Average Error: 47.2 → 17.0
Time: 4.2m
Precision: 64
Internal Precision: 3392
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
↓
\[\begin{array}{l}
\mathbf{if}\;i \le -2066439.759770858:\\
\;\;\;\;100 \cdot \frac{\log \left(e^{{\left(1 + \frac{i}{n}\right)}^{n} - 1}\right)}{\frac{i}{n}}\\
\mathbf{if}\;i \le 85799642328309.52:\\
\;\;\;\;100 \cdot \frac{\frac{\frac{1}{2} \cdot {i}^{2} + \left(\frac{1}{6} \cdot {i}^{3} + i\right)}{i}}{\frac{1}{n}}\\
\mathbf{else}:\\
\;\;\;\;100 \cdot \frac{\log \left(e^{{\left(1 + \frac{i}{n}\right)}^{n} - 1}\right)}{\frac{i}{n}}\\
\end{array}\]
Target
| Original | 47.2 |
|---|
| Target | 46.7 |
|---|
| Herbie | 17.0 |
|---|
\[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 2 regimes
if i < -2066439.759770858 or 85799642328309.52 < i
Initial program 28.7
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
- Using strategy
rm Applied add-log-exp28.8
\[\leadsto 100 \cdot \frac{\color{blue}{\log \left(e^{{\left(1 + \frac{i}{n}\right)}^{n} - 1}\right)}}{\frac{i}{n}}\]
if -2066439.759770858 < i < 85799642328309.52
Initial program 57.4
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
Taylor expanded around 0 26.0
\[\leadsto 100 \cdot \frac{\color{blue}{\frac{1}{2} \cdot {i}^{2} + \left(\frac{1}{6} \cdot {i}^{3} + i\right)}}{\frac{i}{n}}\]
- Using strategy
rm Applied div-inv26.0
\[\leadsto 100 \cdot \frac{\frac{1}{2} \cdot {i}^{2} + \left(\frac{1}{6} \cdot {i}^{3} + i\right)}{\color{blue}{i \cdot \frac{1}{n}}}\]
Applied associate-/r*10.5
\[\leadsto 100 \cdot \color{blue}{\frac{\frac{\frac{1}{2} \cdot {i}^{2} + \left(\frac{1}{6} \cdot {i}^{3} + i\right)}{i}}{\frac{1}{n}}}\]
- Recombined 2 regimes into one program.
Runtime
herbie shell --seed '#(1071373924 2949776965 1885069702 3247780810 90874544 2263903749)'
(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))))