Average Error: 52.5 → 10.1
Time: 6.7m
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 -0.0016917120535581073:\\ \;\;\;\;\left(\sqrt[3]{100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}} \cdot \sqrt[3]{100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}}\right) \cdot \sqrt[3]{100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}}\\ \mathbf{if}\;i \le 0.001497256652680892:\\ \;\;\;\;n \cdot \left(\left(\frac{50}{3} \cdot i\right) \cdot i + \left(100 + 50 \cdot i\right)\right)\\ \mathbf{if}\;i \le 3.509098710768375 \cdot 10^{+188}:\\ \;\;\;\;e^{\log \left(100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\right)}\\ \mathbf{if}\;i \le 3.076781514658324 \cdot 10^{+222}:\\ \;\;\;\;\frac{100}{\frac{i}{n}} \cdot \left(\frac{\frac{1}{2}}{i \cdot i} + \left(i + \frac{\frac{\frac{1}{6}}{i}}{i \cdot i}\right)\right)\\ \mathbf{if}\;i \le 3.156165085498486 \cdot 10^{+258}:\\ \;\;\;\;100 \cdot \left(\frac{{\left(1 + \frac{i}{n}\right)}^{n}}{\frac{i}{n}} - \frac{n}{i}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{100}{\frac{i}{n}} \cdot \left(\frac{\frac{1}{2}}{i \cdot i} + \left(i + \frac{\frac{\frac{1}{6}}{i}}{i \cdot i}\right)\right)\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Target

Original52.5
Target51.7
Herbie10.1
\[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 5 regimes
  2. if i < -0.0016917120535581073

    1. Initial program 27.1

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

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

    if -0.0016917120535581073 < i < 0.001497256652680892

    1. Initial program 61.7

      \[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
    2. Taylor expanded around 0 14.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. Taylor expanded around 0 0.0

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

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

    if 0.001497256652680892 < i < 3.509098710768375e+188

    1. Initial program 30.1

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

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

    if 3.509098710768375e+188 < i < 3.076781514658324e+222 or 3.156165085498486e+258 < i

    1. Initial program 61.8

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

      \[\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. Taylor expanded around inf 23.4

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

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

    if 3.076781514658324e+222 < i < 3.156165085498486e+258

    1. Initial program 31.0

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

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

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

Runtime

Time bar (total: 6.7m)Debug logProfile

herbie shell --seed '#(1062930989 876886121 3990119081 3032829768 3060892583 1929069376)' 
(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))))