Average Error: 47.0 → 10.0
Time: 2.0m
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 -1.2293824047274391 \cdot 10^{-10}:\\ \;\;\;\;100 \cdot \frac{e^{n \cdot \log_* (1 + \frac{i}{n})} - 1}{\frac{i}{n}}\\ \mathbf{if}\;i \le 2.292576075217319 \cdot 10^{-18}:\\ \;\;\;\;(\left(\left(i \cdot i\right) \cdot n\right) \cdot \frac{50}{3} + \left(n \cdot (i \cdot 50 + 100)_*\right))_*\\ \mathbf{else}:\\ \;\;\;\;\frac{100 \cdot n}{i} \cdot (e^{\left(\log i - \log n\right) \cdot n} - 1)^*\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Target

Original47.0
Target47.1
Herbie10.0
\[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.2293824047274391e-10

    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 add-exp-log27.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-exp27.8

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

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

    if -1.2293824047274391e-10 < i < 2.292576075217319e-18

    1. Initial program 58.1

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

      \[\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. Applied simplify25.5

      \[\leadsto \color{blue}{\frac{(\left(i \cdot i\right) \cdot \left((i \cdot \frac{1}{6} + \frac{1}{2})_*\right) + i)_*}{\frac{\frac{i}{100}}{n}}}\]
    4. Taylor expanded around 0 8.4

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

      \[\leadsto \color{blue}{(\left(\left(i \cdot i\right) \cdot n\right) \cdot \frac{50}{3} + \left(n \cdot (i \cdot 50 + 100)_*\right))_*}\]

    if 2.292576075217319e-18 < i

    1. Initial program 33.1

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

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;i \le -1.2293824047274391 \cdot 10^{-10}:\\ \;\;\;\;100 \cdot \frac{e^{n \cdot \log_* (1 + \frac{i}{n})} - 1}{\frac{i}{n}}\\ \mathbf{if}\;i \le 2.292576075217319 \cdot 10^{-18}:\\ \;\;\;\;(\left(\left(i \cdot i\right) \cdot n\right) \cdot \frac{50}{3} + \left(n \cdot (i \cdot 50 + 100)_*\right))_*\\ \mathbf{else}:\\ \;\;\;\;\frac{100 \cdot n}{i} \cdot (e^{\left(\log i - \log n\right) \cdot n} - 1)^*\\ \end{array}}\]

Runtime

Time bar (total: 2.0m)Debug logProfile

herbie shell --seed '#(1064300848 3212030778 2049303162 3567222883 2277747821 1384278011)' +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))))