Average Error: 46.9 → 11.3
Time: 57.4s
Precision: 64
Internal Precision: 2944
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
↓
\[\begin{array}{l}
\mathbf{if}\;i \le -1.1380411540023518 \cdot 10^{-08}:\\
\;\;\;\;100 \cdot \frac{e^{n \cdot \log_* (1 + \frac{i}{n})} - 1}{\frac{i}{n}}\\
\mathbf{if}\;i \le 1.4594955125845637 \cdot 10^{-22}:\\
\;\;\;\;(\left(\left(i \cdot i\right) \cdot n\right) \cdot \frac{50}{3} + \left(n \cdot (i \cdot 50 + 100)_*\right))_*\\
\mathbf{if}\;i \le 2.1020695442444676 \cdot 10^{+101}:\\
\;\;\;\;100 \cdot \frac{(e^{\log \left(1 + \frac{i}{n}\right) \cdot n} - 1)^*}{\frac{i}{n}}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}\]
Target
| Original | 46.9 |
|---|
| Target | 46.9 |
|---|
| Herbie | 11.3 |
|---|
\[100 \cdot \frac{e^{n \cdot \begin{array}{l}
\mathbf{if}\;1 + \frac{i}{n} = 1:\\
\;\;\;\;\frac{i}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{i}{n} \cdot \log \left(1 + \frac{i}{n}\right)}{\left(\frac{i}{n} + 1\right) - 1}\\
\end{array}} - 1}{\frac{i}{n}}\]
Derivation
- Split input into 4 regimes
if i < -1.1380411540023518e-08
Initial program 28.3
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
- Using strategy
rm Applied add-exp-log28.3
\[\leadsto 100 \cdot \frac{{\color{blue}{\left(e^{\log \left(1 + \frac{i}{n}\right)}\right)}}^{n} - 1}{\frac{i}{n}}\]
Applied pow-exp28.3
\[\leadsto 100 \cdot \frac{\color{blue}{e^{\log \left(1 + \frac{i}{n}\right) \cdot n}} - 1}{\frac{i}{n}}\]
Applied simplify6.7
\[\leadsto 100 \cdot \frac{e^{\color{blue}{n \cdot \log_* (1 + \frac{i}{n})}} - 1}{\frac{i}{n}}\]
if -1.1380411540023518e-08 < i < 1.4594955125845637e-22
Initial program 57.4
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
Taylor expanded around 0 25.7
\[\leadsto 100 \cdot \frac{\color{blue}{\frac{1}{2} \cdot {i}^{2} + \left(\frac{1}{6} \cdot {i}^{3} + i\right)}}{\frac{i}{n}}\]
Applied simplify26.0
\[\leadsto \color{blue}{\frac{(\left(i \cdot i\right) \cdot \left((i \cdot \frac{1}{6} + \frac{1}{2})_*\right) + i)_*}{\frac{\frac{i}{100}}{n}}}\]
Taylor expanded around 0 8.9
\[\leadsto \color{blue}{100 \cdot n + \left(\frac{50}{3} \cdot \left(n \cdot {i}^{2}\right) + 50 \cdot \left(n \cdot i\right)\right)}\]
Applied simplify8.9
\[\leadsto \color{blue}{(\left(\left(i \cdot i\right) \cdot n\right) \cdot \frac{50}{3} + \left(n \cdot (i \cdot 50 + 100)_*\right))_*}\]
if 1.4594955125845637e-22 < i < 2.1020695442444676e+101
Initial program 37.7
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
- Using strategy
rm Applied add-exp-log41.5
\[\leadsto 100 \cdot \frac{{\color{blue}{\left(e^{\log \left(1 + \frac{i}{n}\right)}\right)}}^{n} - 1}{\frac{i}{n}}\]
Applied pow-exp41.5
\[\leadsto 100 \cdot \frac{\color{blue}{e^{\log \left(1 + \frac{i}{n}\right) \cdot n}} - 1}{\frac{i}{n}}\]
Applied expm1-def26.0
\[\leadsto 100 \cdot \frac{\color{blue}{(e^{\log \left(1 + \frac{i}{n}\right) \cdot n} - 1)^*}}{\frac{i}{n}}\]
if 2.1020695442444676e+101 < i
Initial program 31.0
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
Taylor expanded around 0 28.9
\[\leadsto 100 \cdot \color{blue}{0}\]
Applied simplify28.9
\[\leadsto \color{blue}{0}\]
- Recombined 4 regimes into one program.
Runtime
herbie shell --seed '#(1064173506 2580572819 2847706409 4129882574 1125180799 1845288547)' +o rules:numerics
(FPCore (i n)
:name "Compound Interest"
:herbie-target
(* 100 (/ (- (exp (* n (if (== (+ 1 (/ i n)) 1) (/ i n) (/ (* (/ i n) (log (+ 1 (/ i n)))) (- (+ (/ i n) 1) 1))))) 1) (/ i n)))
(* 100 (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))))