Average Error: 53.1 → 10.4
Time: 2.1m
Precision: 64
Internal Precision: 2432
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \le -0.07666359635680058:\\ \;\;\;\;100 \cdot \frac{\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}}{\frac{i}{n}}\\ \mathbf{if}\;i \le 1.1209319314423736 \cdot 10^{-07}:\\ \;\;\;\;\left(50 \cdot i + 100\right) \cdot n\\ \mathbf{if}\;i \le 6.24960210020365 \cdot 10^{+172}:\\ \;\;\;\;100 \cdot \frac{\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}}{\frac{i}{n}}\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \frac{e^{\frac{\log n - \log i}{n}} - 1}{\frac{i}{n}}\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Target

Original53.1
Target51.1
Herbie10.4
\[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 < -0.07666359635680058 or 1.1209319314423736e-07 < i < 6.24960210020365e+172

    1. Initial program 29.6

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Using strategy rm
    3. Applied add-cube-cbrt29.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}}}{\frac{i}{n}}\]

    if -0.07666359635680058 < i < 1.1209319314423736e-07

    1. Initial program 61.8

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

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

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

      \[\leadsto \color{blue}{100 \cdot n + 50 \cdot \left(n \cdot i\right)}\]
    5. Applied simplify0.0

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

    if 6.24960210020365e+172 < i

    1. Initial program 62.4

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

      \[\leadsto 100 \cdot \frac{\color{blue}{e^{\frac{\log n - \log i}{n}} - 1}}{\frac{i}{n}}\]
  3. Recombined 3 regimes into one program.
  4. Removed slow pow expressions.

Runtime

Time bar (total: 2.1m)Debug log

herbie shell --seed '#(1567391828 2030694642 2833800258 828025724 3004380912 3532991858)' +o setup:early-exit +o reduce:binary-search
(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))))