Average Error: 47.2 → 17.2
Time: 2.4m
Precision: 64
Internal Precision: 3136
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \cdot \frac{1}{2} + 1 \le 0.9999999999999787:\\ \;\;\;\;100 \cdot \frac{\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}}{\frac{i}{n}}\\ \mathbf{if}\;i \cdot \frac{1}{2} + 1 \le 5.156473555252393 \cdot 10^{+23}:\\ \;\;\;\;\left(\left(\sqrt[3]{1 + \frac{1}{2} \cdot i} \cdot 100\right) \cdot \sqrt[3]{1 + \frac{1}{2} \cdot i}\right) \cdot \left(\sqrt[3]{1 + \frac{1}{2} \cdot i} \cdot n\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{i \cdot \frac{1}{2} + 1}{\log \left(e^{\frac{\frac{1}{n}}{100}}\right)}\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original47.2
Target46.8
Herbie17.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

  1. Split input into 3 regimes
  2. if (+ (* i 1/2) 1) < 0.9999999999999787

    1. Initial program 29.6

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

      \[\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}}}{\frac{i}{n}}\]

    if 0.9999999999999787 < (+ (* i 1/2) 1) < 5.156473555252393e+23

    1. Initial program 57.5

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Taylor expanded around 0 57.3

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

      \[\leadsto \color{blue}{\frac{i \cdot \frac{1}{2} + 1}{\frac{\frac{i}{n}}{100 \cdot i}}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity25.8

      \[\leadsto \frac{i \cdot \frac{1}{2} + 1}{\frac{\color{blue}{1 \cdot \frac{i}{n}}}{100 \cdot i}}\]
    6. Applied times-frac25.9

      \[\leadsto \frac{i \cdot \frac{1}{2} + 1}{\color{blue}{\frac{1}{100} \cdot \frac{\frac{i}{n}}{i}}}\]
    7. Applied add-cube-cbrt25.9

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{i \cdot \frac{1}{2} + 1} \cdot \sqrt[3]{i \cdot \frac{1}{2} + 1}\right) \cdot \sqrt[3]{i \cdot \frac{1}{2} + 1}}}{\frac{1}{100} \cdot \frac{\frac{i}{n}}{i}}\]
    8. Applied times-frac25.8

      \[\leadsto \color{blue}{\frac{\sqrt[3]{i \cdot \frac{1}{2} + 1} \cdot \sqrt[3]{i \cdot \frac{1}{2} + 1}}{\frac{1}{100}} \cdot \frac{\sqrt[3]{i \cdot \frac{1}{2} + 1}}{\frac{\frac{i}{n}}{i}}}\]
    9. Applied simplify25.8

      \[\leadsto \color{blue}{\left(\left(\sqrt[3]{1 + \frac{1}{2} \cdot i} \cdot 100\right) \cdot \sqrt[3]{1 + \frac{1}{2} \cdot i}\right)} \cdot \frac{\sqrt[3]{i \cdot \frac{1}{2} + 1}}{\frac{\frac{i}{n}}{i}}\]
    10. Applied simplify9.5

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

    if 5.156473555252393e+23 < (+ (* i 1/2) 1)

    1. Initial program 30.5

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Taylor expanded around 0 57.4

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

      \[\leadsto \color{blue}{\frac{i \cdot \frac{1}{2} + 1}{\frac{\frac{i}{n}}{100 \cdot i}}}\]
    4. Using strategy rm
    5. Applied add-log-exp31.6

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

      \[\leadsto \frac{i \cdot \frac{1}{2} + 1}{\log \color{blue}{\left(e^{\frac{\frac{1}{n}}{100}}\right)}}\]
  3. Recombined 3 regimes into one program.

Runtime

Time bar (total: 2.4m)Debug logProfile

herbie shell --seed 2018170 
(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))))