Average Error: 42.0 → 19.8
Time: 31.3s
Precision: 64
Internal Precision: 128
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;i \le -7.421910630204065 \cdot 10^{-14}:\\ \;\;\;\;100 \cdot \frac{{\left(\frac{i}{n}\right)}^{n} + -1}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 2.7609046075630226 \cdot 10^{-08}:\\ \;\;\;\;100 \cdot n + \left(\frac{50}{3} \cdot i + 50\right) \cdot \left(n \cdot i\right)\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \left(n \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{i}\right)\\ \end{array}\]

Error

Bits error versus i

Bits error versus n

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original42.0
Target41.8
Herbie19.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 < -7.421910630204065e-14

    1. Initial program 28.7

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

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

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

    if -7.421910630204065e-14 < i < 2.7609046075630226e-08

    1. Initial program 49.6

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

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

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

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

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

    if 2.7609046075630226e-08 < i

    1. Initial program 31.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \le -7.421910630204065 \cdot 10^{-14}:\\ \;\;\;\;100 \cdot \frac{{\left(\frac{i}{n}\right)}^{n} + -1}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 2.7609046075630226 \cdot 10^{-08}:\\ \;\;\;\;100 \cdot n + \left(\frac{50}{3} \cdot i + 50\right) \cdot \left(n \cdot i\right)\\ \mathbf{else}:\\ \;\;\;\;100 \cdot \left(n \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{i}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019010 
(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))))

Details

Time bar (total: 29.9s)Debug log

sample298.0ms

Algorithm
intervals

simplify194.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
194.0ms
(* 100 (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n)))

prune5.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 43.7b

localize17.0ms

Local error

Found 4 expressions with local error:

11.6b
(/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))
6.5b
(pow (+ 1 (/ i n)) n)
1.3b
(- (pow (+ 1 (/ i n)) n) 1)
0.1b
(* 100 (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n)))

rewrite41.0ms

Algorithm
rewrite-expression-head
Rules
46×add-sqr-sqrt
40×times-frac
26×add-cube-cbrt
26×*-un-lft-identity
25×associate-*r*
20×difference-of-sqr-1
13×div-inv
13×unpow-prod-down
add-exp-log
add-cbrt-cube
associate-/l*
pow1
add-log-exp
associate-/r*
associate-/l/
flip--
associate-/r/
flip3--
*-commutative
associate-*r/
pow-exp
div-exp
div-sub
frac-2neg
pow-pow
sub-neg
clear-num
cbrt-undiv
pow-to-exp
Counts
4 → 105
Calls
4 calls:
Slowest
17.0ms
(/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))
12.0ms
(* 100 (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n)))
8.0ms
(- (pow (+ 1 (/ i n)) n) 1)
1.0ms
(pow (+ 1 (/ i n)) n)

series577.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
185.0ms
(* 100 (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n)))
152.0ms
(/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))
142.0ms
(- (pow (+ 1 (/ i n)) n) 1)
98.0ms
(pow (+ 1 (/ i n)) n)

simplify3.1s

Counts
97 → 117
Calls
97 calls:
Slowest
324.0ms
(/ (* (* (- (pow (+ 1 (/ i n)) n) 1) (- (pow (+ 1 (/ i n)) n) 1)) (- (pow (+ 1 (/ i n)) n) 1)) (* (* (/ i n) (/ i n)) (/ i n)))
303.0ms
(/ (* (- (exp (* (- (log (/ 1 n)) (log (/ 1 i))) n)) 1) n) i)
240.0ms
(* 100 (/ (* n (- (exp (* n (- (log (/ -1 n)) (log (/ -1 i))))) 1)) i))
212.0ms
(* 100 (/ (* (- (exp (* (- (log (/ 1 n)) (log (/ 1 i))) n)) 1) n) i))
171.0ms
(- (exp (* (- (log (/ 1 n)) (log (/ 1 i))) n)) 1)

prune1.1s

Pruning

10 alts after pruning (10 fresh and 0 done)

Merged error: 19.2b

localize32.0ms

Local error

Found 4 expressions with local error:

19.3b
(/ (+ i (* (* i i) (+ (* 1/6 i) 1/2))) (/ i n))
0.4b
(* 1/6 i)
0.0b
(* 100 (/ (+ i (* (* i i) (+ (* 1/6 i) 1/2))) (/ i n)))
0.0b
(* (* i i) (+ (* 1/6 i) 1/2))

rewrite31.0ms

Algorithm
rewrite-expression-head
Rules
24×times-frac
22×add-cube-cbrt
22×*-un-lft-identity
22×add-sqr-sqrt
20×associate-*r*
div-inv
add-exp-log
add-cbrt-cube
pow1
add-log-exp
associate-/r*
associate-/l*
*-commutative
associate-*r/
associate-/l/
flip-+
associate-/r/
flip3-+
cbrt-unprod
prod-exp
pow-prod-down
associate-*l*
div-exp
distribute-lft-in
frac-2neg
clear-num
cbrt-undiv
distribute-rgt-in
Counts
4 → 87
Calls
4 calls:
Slowest
17.0ms
(/ (+ i (* (* i i) (+ (* 1/6 i) 1/2))) (/ i n))
9.0ms
(* (* i i) (+ (* 1/6 i) 1/2))
3.0ms
(* 100 (/ (+ i (* (* i i) (+ (* 1/6 i) 1/2))) (/ i n)))
0.0ms
(* 1/6 i)

series143.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
54.0ms
(/ (+ i (* (* i i) (+ (* 1/6 i) 1/2))) (/ i n))
44.0ms
(* 100 (/ (+ i (* (* i i) (+ (* 1/6 i) 1/2))) (/ i n)))
34.0ms
(* (* i i) (+ (* 1/6 i) 1/2))
11.0ms
(* 1/6 i)

simplify7.0s

Counts
73 → 99
Calls
73 calls:
Slowest
543.0ms
(/ (sqrt (+ i (* (* i i) (+ (* 1/6 i) 1/2)))) (* (cbrt (/ i n)) (cbrt (/ i n))))
322.0ms
(sqrt (/ (+ i (* (* i i) (+ (* 1/6 i) 1/2))) (/ i n)))
277.0ms
(cbrt (/ (+ i (* (* i i) (+ (* 1/6 i) 1/2))) (/ i n)))
241.0ms
(/ (+ i (* (* i i) (+ (* 1/6 i) 1/2))) (/ i n))
232.0ms
(/ (+ i (* (* i i) (+ (* 1/6 i) 1/2))) (/ i n))

prune1.0s

Pruning

19 alts after pruning (19 fresh and 0 done)

Merged error: 7.8b

localize32.0ms

Local error

Found 2 expressions with local error:

0.5b
(* 50/3 i)
0.3b
(* (* i n) (+ 50 (* 50/3 i)))

rewrite8.0ms

Algorithm
rewrite-expression-head
Rules
add-exp-log
add-cbrt-cube
pow1
add-cube-cbrt
associate-*r*
*-un-lft-identity
add-sqr-sqrt
add-log-exp
*-commutative
associate-*r/
flip-+
cbrt-unprod
prod-exp
pow-prod-down
associate-*l*
flip3-+
distribute-lft-in
distribute-rgt-in
Counts
2 → 27
Calls
2 calls:
Slowest
7.0ms
(* (* i n) (+ 50 (* 50/3 i)))
0.0ms
(* 50/3 i)

series54.0ms

Counts
2 → 6
Calls
2 calls:
Slowest
36.0ms
(* (* i n) (+ 50 (* 50/3 i)))
18.0ms
(* 50/3 i)

simplify714.0ms

Counts
16 → 33
Calls
16 calls:
Slowest
179.0ms
(* (* (* (* i n) (* i n)) (* i n)) (* (* (+ 50 (* 50/3 i)) (+ 50 (* 50/3 i))) (+ 50 (* 50/3 i))))
155.0ms
(+ (* 50 50) (- (* (* 50/3 i) (* 50/3 i)) (* 50 (* 50/3 i))))
78.0ms
(* (* i n) (+ 50 (* 50/3 i)))
76.0ms
(+ (* 50/3 (* (pow i 2) n)) (* 50 (* i n)))
71.0ms
(+ (* 50/3 (* (pow i 2) n)) (* 50 (* i n)))

prune322.0ms

Pruning

19 alts after pruning (18 fresh and 1 done)

Merged error: 7.8b

localize30.0ms

Local error

Found 4 expressions with local error:

14.1b
(cbrt (+ i (* (+ (* i 1/6) 1/2) (* i i))))
14.1b
(cbrt (+ i (* (* i i) (+ (* 1/6 i) 1/2))))
14.1b
(cbrt (+ i (* (* i i) (+ (* 1/6 i) 1/2))))
9.8b
(/ (* (cbrt (+ i (* (* i i) (+ (* 1/6 i) 1/2)))) (cbrt (+ i (* (* i i) (+ (* 1/6 i) 1/2))))) i)

rewrite10.0ms

Algorithm
rewrite-expression-head
Rules
18×cbrt-div
flip-+
flip3-+
cbrt-prod
associate-/l/
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
add-log-exp
add-exp-log
add-cbrt-cube
pow1
frac-times
pow1/3
associate-*r/
associate-*l/
associate-/l*
div-inv
frac-2neg
clear-num
Counts
4 → 58
Calls
4 calls:
Slowest
7.0ms
(/ (* (cbrt (+ i (* (* i i) (+ (* 1/6 i) 1/2)))) (cbrt (+ i (* (* i i) (+ (* 1/6 i) 1/2))))) i)
1.0ms
(cbrt (+ i (* (+ (* i 1/6) 1/2) (* i i))))
1.0ms
(cbrt (+ i (* (* i i) (+ (* 1/6 i) 1/2))))
1.0ms
(cbrt (+ i (* (* i i) (+ (* 1/6 i) 1/2))))

series248.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
94.0ms
(/ (* (cbrt (+ i (* (* i i) (+ (* 1/6 i) 1/2)))) (cbrt (+ i (* (* i i) (+ (* 1/6 i) 1/2))))) i)
53.0ms
(cbrt (+ i (* (* i i) (+ (* 1/6 i) 1/2))))
51.0ms
(cbrt (+ i (* (+ (* i 1/6) 1/2) (* i i))))
51.0ms
(cbrt (+ i (* (* i i) (+ (* 1/6 i) 1/2))))

simplify5.7s

Counts
36 → 70
Calls
36 calls:
Slowest
617.0ms
(+ (exp (* 1/3 (- (log -1/6) (* 3 (log (/ -1 i)))))) (+ (/ (exp (* 1/3 (- (log -1/6) (* 3 (log (/ -1 i)))))) i) (/ (exp (* 1/3 (- (log -1/6) (* 3 (log (/ -1 i)))))) (pow i 2))))
501.0ms
(+ (exp (* 1/3 (- (log -1/6) (* 3 (log (/ -1 i)))))) (+ (/ (exp (* 1/3 (- (log -1/6) (* 3 (log (/ -1 i)))))) i) (/ (exp (* 1/3 (- (log -1/6) (* 3 (log (/ -1 i)))))) (pow i 2))))
499.0ms
(+ (exp (* 1/3 (- (log -1/6) (* 3 (log (/ -1 i)))))) (+ (/ (exp (* 1/3 (- (log -1/6) (* 3 (log (/ -1 i)))))) i) (/ (exp (* 1/3 (- (log -1/6) (* 3 (log (/ -1 i)))))) (pow i 2))))
456.0ms
(cbrt (+ (pow i 3) (pow (* (+ (* i 1/6) 1/2) (* i i)) 3)))
445.0ms
(+ (/ (exp (* 1/3 (- (log 1/6) (* 3 (log (/ 1 i)))))) i) (+ (/ (exp (* 1/3 (- (log 1/6) (* 3 (log (/ 1 i)))))) (pow i 2)) (exp (* 1/3 (- (log 1/6) (* 3 (log (/ 1 i))))))))

prune740.0ms

Pruning

23 alts after pruning (22 fresh and 1 done)

Merged error: 7.8b

regimes525.0ms

Accuracy

56% (11.0b remaining)

Error of 19.8b against oracle of 8.8b and baseline of 33.7b

bsearch262.0ms

end0.0ms

sample7.6s

Algorithm
intervals