Average Error: 47.7 → 13.8
Time: 39.8s
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 \le 2.8661021442212233 \cdot 10^{+49}:\\ \;\;\;\;\frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^* \cdot 100}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 2.3281031367793534 \cdot 10^{+188} \lor \neg \left(i \le 1.4760076298463418 \cdot 10^{+283}\right):\\ \;\;\;\;100 \cdot 0\\ \mathbf{else}:\\ \;\;\;\;(\left(n \cdot \frac{100}{i}\right) \cdot \left({\left(\frac{i}{n} + 1\right)}^{n}\right) + \left(\frac{-100}{\frac{i}{n}}\right))_*\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Target

Original47.7
Target46.8
Herbie13.8
\[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 < 2.8661021442212233e+49

    1. Initial program 49.6

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

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

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

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

      \[\leadsto 100 \cdot \frac{(e^{\color{blue}{n \cdot \log_* (1 + \frac{i}{n})}} - 1)^*}{\frac{i}{n}}\]
    7. Using strategy rm
    8. Applied associate-*r/11.6

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

    if 2.8661021442212233e+49 < i < 2.3281031367793534e+188 or 1.4760076298463418e+283 < i

    1. Initial program 33.0

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

      \[\leadsto 100 \cdot \color{blue}{0}\]

    if 2.3281031367793534e+188 < i < 1.4760076298463418e+283

    1. Initial program 32.4

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Initial simplification33.0

      \[\leadsto (\left(n \cdot \frac{100}{i}\right) \cdot \left({\left(1 + \frac{i}{n}\right)}^{n}\right) + \left(\frac{-100}{\frac{i}{n}}\right))_*\]
  3. Recombined 3 regimes into one program.
  4. Final simplification13.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \le 2.8661021442212233 \cdot 10^{+49}:\\ \;\;\;\;\frac{(e^{\log_* (1 + \frac{i}{n}) \cdot n} - 1)^* \cdot 100}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 2.3281031367793534 \cdot 10^{+188} \lor \neg \left(i \le 1.4760076298463418 \cdot 10^{+283}\right):\\ \;\;\;\;100 \cdot 0\\ \mathbf{else}:\\ \;\;\;\;(\left(n \cdot \frac{100}{i}\right) \cdot \left({\left(\frac{i}{n} + 1\right)}^{n}\right) + \left(\frac{-100}{\frac{i}{n}}\right))_*\\ \end{array}\]

Runtime

Time bar (total: 39.8s)Debug logProfile

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