Average Error: 47.1 → 17.2
Time: 2.8m
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 -7.795465067186963 \cdot 10^{-14}:\\
\;\;\;\;100 \cdot \frac{\frac{{\left(1 + \frac{i}{n}\right)}^{n} \cdot {\left(1 + \frac{i}{n}\right)}^{n} - 1}{{\left(1 + \frac{i}{n}\right)}^{n} + 1}}{\frac{i}{n}}\\
\mathbf{if}\;i \le 9.685143337392256:\\
\;\;\;\;100 \cdot \left(\frac{\left(\frac{1}{6} \cdot i + \frac{1}{2}\right) \cdot \left(i \cdot i\right) + i}{i} \cdot n\right)\\
\mathbf{else}:\\
\;\;\;\;\left(100 \cdot \frac{\sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1} \cdot \sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1}}{i}\right) \cdot \frac{\sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1}}{\frac{1}{n}}\\
\end{array}\]
Target
| Original | 47.1 |
|---|
| Target | 46.9 |
|---|
| Herbie | 17.2 |
|---|
\[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 3 regimes
if i < -7.795465067186963e-14
Initial program 28.3
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
- Using strategy
rm Applied flip--28.3
\[\leadsto 100 \cdot \frac{\color{blue}{\frac{{\left(1 + \frac{i}{n}\right)}^{n} \cdot {\left(1 + \frac{i}{n}\right)}^{n} - 1 \cdot 1}{{\left(1 + \frac{i}{n}\right)}^{n} + 1}}}{\frac{i}{n}}\]
Applied simplify28.3
\[\leadsto 100 \cdot \frac{\frac{\color{blue}{{\left(1 + \frac{i}{n}\right)}^{n} \cdot {\left(1 + \frac{i}{n}\right)}^{n} - 1}}{{\left(1 + \frac{i}{n}\right)}^{n} + 1}}{\frac{i}{n}}\]
if -7.795465067186963e-14 < i < 9.685143337392256
Initial program 57.6
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
Taylor expanded around 0 25.8
\[\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 associate-/r/9.6
\[\leadsto 100 \cdot \color{blue}{\left(\frac{\frac{1}{2} \cdot {i}^{2} + \left(\frac{1}{6} \cdot {i}^{3} + i\right)}{i} \cdot n\right)}\]
Applied simplify9.6
\[\leadsto 100 \cdot \left(\color{blue}{\frac{\left(\frac{1}{6} \cdot i + \frac{1}{2}\right) \cdot \left(i \cdot i\right) + i}{i}} \cdot n\right)\]
if 9.685143337392256 < i
Initial program 32.1
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
- Using strategy
rm Applied div-inv32.2
\[\leadsto 100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\color{blue}{i \cdot \frac{1}{n}}}\]
Applied add-cube-cbrt32.2
\[\leadsto 100 \cdot \frac{\color{blue}{\left(\sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1} \cdot \sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1}\right) \cdot \sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1}}}{i \cdot \frac{1}{n}}\]
Applied times-frac32.2
\[\leadsto 100 \cdot \color{blue}{\left(\frac{\sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1} \cdot \sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1}}{i} \cdot \frac{\sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1}}{\frac{1}{n}}\right)}\]
Applied associate-*r*32.2
\[\leadsto \color{blue}{\left(100 \cdot \frac{\sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1} \cdot \sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1}}{i}\right) \cdot \frac{\sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1}}{\frac{1}{n}}}\]
- Recombined 3 regimes into one program.
- Removed slow
pow expressions.
Runtime
herbie shell --seed '#(1063154770 1824007522 645063331 41291047 494775821 1237684644)'
(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))))