Average Error: 47.4 → 17.6
Time: 3.3m
Precision: 64
Internal Precision: 3456
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \le -9.496970096237412 \cdot 10^{+24}:\\ \;\;\;\;\frac{100 \cdot \left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right)}{\frac{i}{n}}\\ \mathbf{if}\;i \le 0.9728556327625646:\\ \;\;\;\;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}:\\ \;\;\;\;\frac{100 \cdot \left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right)}{\frac{i}{n}}\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Target

Original47.4
Target46.8
Herbie17.6
\[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 < -9.496970096237412e+24 or 0.9728556327625646 < i

    1. Initial program 29.0

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Using strategy rm
    3. Applied associate-*r/29.0

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

    if -9.496970096237412e+24 < i < 0.9728556327625646

    1. Initial program 56.9

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

      \[\leadsto 100 \cdot \frac{\color{blue}{\frac{1}{2} \cdot {i}^{2} + \left(\frac{1}{6} \cdot {i}^{3} + i\right)}}{\frac{i}{n}}\]
    3. Using strategy rm
    4. Applied associate-/r/11.7

      \[\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)}\]
    5. Applied simplify11.7

      \[\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)\]
  3. Recombined 2 regimes into one program.
  4. Removed slow pow expressions.

Runtime

Time bar (total: 3.3m)Debug logProfile

herbie shell --seed '#(1063282112 2455465480 4141627379 3773598652 1647277307 776739644)' 
(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))))