Average Error: 39.7 → 14.9
Time: 12.8s
Precision: 64
$A - B \cdot \left(1 - e^{\frac{-A}{B}}\right)$
$\begin{array}{l} \mathbf{if}\;B \le -1.918295326428170904400234757036795432791 \cdot 10^{185} \lor \neg \left(B \le -9.920334535579159696823631220057170447696 \cdot 10^{62} \lor \neg \left(B \le -11236109519442522112\right) \land B \le 1.224549409822292681696781731715185537412 \cdot 10^{65}\right):\\ \;\;\;\;\frac{1}{2} \cdot \frac{{A}^{2}}{B}\\ \mathbf{else}:\\ \;\;\;\;\left(A - B \cdot 1\right) - \frac{-B}{e^{\frac{A}{B}}}\\ \end{array}$
A - B \cdot \left(1 - e^{\frac{-A}{B}}\right)
\begin{array}{l}
\mathbf{if}\;B \le -1.918295326428170904400234757036795432791 \cdot 10^{185} \lor \neg \left(B \le -9.920334535579159696823631220057170447696 \cdot 10^{62} \lor \neg \left(B \le -11236109519442522112\right) \land B \le 1.224549409822292681696781731715185537412 \cdot 10^{65}\right):\\
\;\;\;\;\frac{1}{2} \cdot \frac{{A}^{2}}{B}\\

\mathbf{else}:\\
\;\;\;\;\left(A - B \cdot 1\right) - \frac{-B}{e^{\frac{A}{B}}}\\

\end{array}
double f(double A, double B) {
double r13571 = A;
double r13572 = B;
double r13573 = 1.0;
double r13574 = -r13571;
double r13575 = r13574 / r13572;
double r13576 = exp(r13575);
double r13577 = r13573 - r13576;
double r13578 = r13572 * r13577;
double r13579 = r13571 - r13578;
return r13579;
}


double f(double A, double B) {
double r13580 = B;
double r13581 = -1.918295326428171e+185;
bool r13582 = r13580 <= r13581;
double r13583 = -9.92033453557916e+62;
bool r13584 = r13580 <= r13583;
double r13585 = -1.1236109519442522e+19;
bool r13586 = r13580 <= r13585;
double r13587 = !r13586;
double r13588 = 1.2245494098222927e+65;
bool r13589 = r13580 <= r13588;
bool r13590 = r13587 && r13589;
bool r13591 = r13584 || r13590;
double r13592 = !r13591;
bool r13593 = r13582 || r13592;
double r13594 = 0.5;
double r13595 = A;
double r13596 = 2.0;
double r13597 = pow(r13595, r13596);
double r13598 = r13597 / r13580;
double r13599 = r13594 * r13598;
double r13600 = 1.0;
double r13601 = r13580 * r13600;
double r13602 = r13595 - r13601;
double r13603 = -r13580;
double r13604 = r13595 / r13580;
double r13605 = exp(r13604);
double r13606 = r13603 / r13605;
double r13607 = r13602 - r13606;
double r13608 = r13593 ? r13599 : r13607;
return r13608;
}



# Try it out

Results

 In Out
Enter valid numbers for all inputs

# Derivation

1. Split input into 2 regimes
2. ## if B < -1.918295326428171e+185 or -9.92033453557916e+62 < B < -1.1236109519442522e+19 or 1.2245494098222927e+65 < B

1. Initial program 53.6

$A - B \cdot \left(1 - e^{\frac{-A}{B}}\right)$
2. Taylor expanded around inf 13.6

$\leadsto \color{blue}{\frac{1}{2} \cdot \frac{{A}^{2}}{B}}$

## if -1.918295326428171e+185 < B < -9.92033453557916e+62 or -1.1236109519442522e+19 < B < 1.2245494098222927e+65

1. Initial program 30.2

$A - B \cdot \left(1 - e^{\frac{-A}{B}}\right)$
2. Using strategy rm
3. Applied sub-neg30.2

$\leadsto A - B \cdot \color{blue}{\left(1 + \left(-e^{\frac{-A}{B}}\right)\right)}$
4. Applied distribute-lft-in30.2

$\leadsto A - \color{blue}{\left(B \cdot 1 + B \cdot \left(-e^{\frac{-A}{B}}\right)\right)}$
5. Applied associate--r+15.8

$\leadsto \color{blue}{\left(A - B \cdot 1\right) - B \cdot \left(-e^{\frac{-A}{B}}\right)}$
6. Using strategy rm
7. Applied distribute-frac-neg15.8

$\leadsto \left(A - B \cdot 1\right) - B \cdot \left(-e^{\color{blue}{-\frac{A}{B}}}\right)$
8. Applied exp-neg15.8

$\leadsto \left(A - B \cdot 1\right) - B \cdot \left(-\color{blue}{\frac{1}{e^{\frac{A}{B}}}}\right)$
9. Applied distribute-neg-frac15.8

$\leadsto \left(A - B \cdot 1\right) - B \cdot \color{blue}{\frac{-1}{e^{\frac{A}{B}}}}$
10. Applied associate-*r/15.8

$\leadsto \left(A - B \cdot 1\right) - \color{blue}{\frac{B \cdot \left(-1\right)}{e^{\frac{A}{B}}}}$
11. Simplified15.8

$\leadsto \left(A - B \cdot 1\right) - \frac{\color{blue}{-B}}{e^{\frac{A}{B}}}$
3. Recombined 2 regimes into one program.
4. Final simplification14.9

$\leadsto \begin{array}{l} \mathbf{if}\;B \le -1.918295326428170904400234757036795432791 \cdot 10^{185} \lor \neg \left(B \le -9.920334535579159696823631220057170447696 \cdot 10^{62} \lor \neg \left(B \le -11236109519442522112\right) \land B \le 1.224549409822292681696781731715185537412 \cdot 10^{65}\right):\\ \;\;\;\;\frac{1}{2} \cdot \frac{{A}^{2}}{B}\\ \mathbf{else}:\\ \;\;\;\;\left(A - B \cdot 1\right) - \frac{-B}{e^{\frac{A}{B}}}\\ \end{array}$

# Reproduce

herbie shell --seed 1
(FPCore (A B)
:name "(A-B*(1-exp(-A/B)))"
:precision binary64
(- A (* B (- 1 (exp (/ (- A) B))))))