Average Error: 50.9 → 10.4
Time: 27.7s
Precision: 64
Internal precision: 2432
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \le -0.058764479831025576:\\ \;\;\;\;100 \cdot \frac{\frac{{\left({\left(1 + \frac{i}{n}\right)}^{n}\right)}^3 - 1}{\left({\left(1 + \frac{i}{n}\right)}^{n} + 1\right) + {\left({\left(1 + \frac{i}{n}\right)}^{n}\right)}^2}}{\frac{i}{n}}\\ \mathbf{if}\;i \le 4.370354623930509 \cdot 10^{-12}:\\ \;\;\;\;n \cdot \left(\left(100 + 50 \cdot i\right) + e^{\log \left(\frac{50}{3} \cdot {i}^2\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \left(\frac{{\left(1 + \frac{i}{n}\right)}^{n}}{\frac{i}{n}} - \frac{n}{i}\right)\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Target

Original50.9
Comparison50.4
Herbie10.4
\[ 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

  1. Split input into 3 regimes.
  2. if i < -0.058764479831025576

    1. Initial program 27.7

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Using strategy rm
    3. Applied flip3-- 27.7

      \[\leadsto 100 \cdot \frac{\color{blue}{\frac{{\left({\left(1 + \frac{i}{n}\right)}^{n}\right)}^{3} - {1}^{3}}{{\left({\left(1 + \frac{i}{n}\right)}^{n}\right)}^2 + \left({1}^2 + {\left(1 + \frac{i}{n}\right)}^{n} \cdot 1\right)}}}{\frac{i}{n}}\]
    4. Applied simplify 27.7

      \[\leadsto 100 \cdot \frac{\frac{\color{blue}{{\left({\left(1 + \frac{i}{n}\right)}^{n}\right)}^3 - 1}}{{\left({\left(1 + \frac{i}{n}\right)}^{n}\right)}^2 + \left({1}^2 + {\left(1 + \frac{i}{n}\right)}^{n} \cdot 1\right)}}{\frac{i}{n}}\]
    5. Applied simplify 27.7

      \[\leadsto 100 \cdot \frac{\frac{{\left({\left(1 + \frac{i}{n}\right)}^{n}\right)}^3 - 1}{\color{blue}{\left({\left(1 + \frac{i}{n}\right)}^{n} + 1\right) + {\left({\left(1 + \frac{i}{n}\right)}^{n}\right)}^2}}}{\frac{i}{n}}\]

    if -0.058764479831025576 < i < 4.370354623930509e-12

    1. Initial program 61.7

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Applied taylor 14.5

      \[\leadsto 100 \cdot \frac{\frac{1}{6} \cdot {i}^{3} + \left(i + \frac{1}{2} \cdot {i}^2\right)}{\frac{i}{n}}\]
    3. Taylor expanded around 0 14.5

      \[\leadsto 100 \cdot \frac{\color{blue}{\frac{1}{6} \cdot {i}^{3} + \left(i + \frac{1}{2} \cdot {i}^2\right)}}{\frac{i}{n}}\]
    4. Applied taylor 0.0

      \[\leadsto 100 \cdot n + \left(\frac{50}{3} \cdot \left(n \cdot {i}^2\right) + 50 \cdot \left(n \cdot i\right)\right)\]
    5. Taylor expanded around 0 0.0

      \[\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)}\]
    6. Applied simplify 0.0

      \[\leadsto \color{blue}{n \cdot \left(\left(100 + 50 \cdot i\right) + \frac{50}{3} \cdot \left(i \cdot i\right)\right)}\]
    7. Using strategy rm
    8. Applied add-exp-log 0.0

      \[\leadsto n \cdot \left(\left(100 + 50 \cdot i\right) + \color{blue}{e^{\log \left(\frac{50}{3} \cdot \left(i \cdot i\right)\right)}}\right)\]
    9. Applied simplify 0.0

      \[\leadsto n \cdot \left(\left(100 + 50 \cdot i\right) + e^{\color{blue}{\log \left(\frac{50}{3} \cdot {i}^2\right)}}\right)\]

    if 4.370354623930509e-12 < i

    1. Initial program 32.8

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Using strategy rm
    3. Applied div-sub 32.8

      \[\leadsto 100 \cdot \color{blue}{\left(\frac{{\left(1 + \frac{i}{n}\right)}^{n}}{\frac{i}{n}} - \frac{1}{\frac{i}{n}}\right)}\]
    4. Applied simplify 35.7

      \[\leadsto 100 \cdot \left(\frac{{\left(1 + \frac{i}{n}\right)}^{n}}{\frac{i}{n}} - \color{blue}{\frac{n}{i}}\right)\]
  3. Recombined 3 regimes into one program.
  4. Removed slow pow expressions

Runtime

Time bar (total: 27.7s) Debug logProfile

Please include this information when filing a bug report:

herbie shell --seed '#(1064524629 4159152179 2999149171 575749698 4006532819 692958815)'
(FPCore (i n)
  :name "Compound Interest"

  :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))))