Average Error: 50.4 → 10.5
Time: 52.3s
Precision: 64
Internal precision: 128
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \le -3.1308280513783317 \cdot 10^{-09}:\\ \;\;\;\;100 \cdot \frac{{\left({\left(1 + \frac{i}{n}\right)}^{n}\right)}^{3} - {1}^{3}}{\frac{i}{n} \cdot \left({\left({\left(\frac{i}{n} + 1\right)}^{n}\right)}^2 + \left(1 + {\left(\frac{i}{n} + 1\right)}^{n}\right)\right)}\\ \mathbf{if}\;i \le 3.203941410402244 \cdot 10^{-15}:\\ \;\;\;\;\left(i \cdot \frac{1}{2} + 1\right) \cdot \left(100 \cdot n\right)\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \frac{{\left({\left(1 + \frac{i}{n}\right)}^{n}\right)}^{3} - {1}^{3}}{\frac{i}{n} \cdot \left({\left({\left(\frac{i}{n} + 1\right)}^{n}\right)}^2 + \left(1 + {\left(\frac{i}{n} + 1\right)}^{n}\right)\right)}\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Target

Original50.4
Comparison50.2
Herbie10.5
\[ 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 2 regimes.
  2. if i < -3.1308280513783317e-09 or 3.203941410402244e-15 < i

    1. Initial program 29.7

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Using strategy rm
    3. Applied flip3-- 29.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 associate-/l/ 29.8

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

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

    if -3.1308280513783317e-09 < i < 3.203941410402244e-15

    1. Initial program 61.7

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

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

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

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

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

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

Runtime

Time bar (total: 52.3s) Debug log

Please include this information when filing a bug report:

herbie --seed '#(2668259955 678661771 1153533617 3222729755 1678190763 2684928584)'
(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))))