Average Error: 47.1 → 10.9
Time: 1.1m
Precision: 64
Internal Precision: 3136
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;100 \cdot \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 \left(\sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1} \cdot n\right)\right) \le 2.785101380500176 \cdot 10^{-187}:\\ \;\;\;\;\frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^*}{\frac{i}{n}} \cdot 100\\ \mathbf{elif}\;100 \cdot \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 \left(\sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1} \cdot n\right)\right) \le 47667349.975142784:\\ \;\;\;\;100 \cdot \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 \left(\sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1} \cdot n\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0 \cdot 100\\ \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.1
Target46.8
Herbie10.9
\[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 (* 100 (* (/ (* (cbrt (- (pow (+ 1 (/ i n)) n) 1)) (cbrt (- (pow (+ 1 (/ i n)) n) 1))) i) (* n (cbrt (- (pow (+ (/ i n) 1) n) 1))))) < 2.785101380500176e-187

    1. Initial program 48.5

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

      \[\leadsto 100 \cdot \frac{{\color{blue}{\left(e^{\log \left(1 + \frac{i}{n}\right)}\right)}}^{n} - 1}{\frac{i}{n}}\]
    4. Applied pow-exp48.8

      \[\leadsto 100 \cdot \frac{\color{blue}{e^{\log \left(1 + \frac{i}{n}\right) \cdot n}} - 1}{\frac{i}{n}}\]
    5. Applied expm1-def42.7

      \[\leadsto 100 \cdot \frac{\color{blue}{(e^{\log \left(1 + \frac{i}{n}\right) \cdot n} - 1)^*}}{\frac{i}{n}}\]
    6. Simplified11.8

      \[\leadsto 100 \cdot \frac{(e^{\color{blue}{n \cdot \log_* (1 + \frac{i}{n})}} - 1)^*}{\frac{i}{n}}\]

    if 2.785101380500176e-187 < (* 100 (* (/ (* (cbrt (- (pow (+ 1 (/ i n)) n) 1)) (cbrt (- (pow (+ 1 (/ i n)) n) 1))) i) (* n (cbrt (- (pow (+ (/ i n) 1) n) 1))))) < 47667349.975142784

    1. Initial program 1.5

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

      \[\leadsto 100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\color{blue}{i \cdot \frac{1}{n}}}\]
    4. Applied add-cube-cbrt1.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}}}{i \cdot \frac{1}{n}}\]
    5. Applied times-frac1.5

      \[\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)}\]
    6. Simplified1.5

      \[\leadsto 100 \cdot \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 \color{blue}{\left(n \cdot \sqrt[3]{{\left(\frac{i}{n} + 1\right)}^{n} - 1}\right)}\right)\]

    if 47667349.975142784 < (* 100 (* (/ (* (cbrt (- (pow (+ 1 (/ i n)) n) 1)) (cbrt (- (pow (+ 1 (/ i n)) n) 1))) i) (* n (cbrt (- (pow (+ (/ i n) 1) n) 1)))))

    1. Initial program 59.5

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

      \[\leadsto 100 \cdot \color{blue}{0}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification10.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;100 \cdot \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 \left(\sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1} \cdot n\right)\right) \le 2.785101380500176 \cdot 10^{-187}:\\ \;\;\;\;\frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^*}{\frac{i}{n}} \cdot 100\\ \mathbf{elif}\;100 \cdot \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 \left(\sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1} \cdot n\right)\right) \le 47667349.975142784:\\ \;\;\;\;100 \cdot \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 \left(\sqrt[3]{{\left(1 + \frac{i}{n}\right)}^{n} - 1} \cdot n\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0 \cdot 100\\ \end{array}\]

Runtime

Time bar (total: 1.1m)Debug logProfile

herbie shell --seed 2018217 +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))))