Average Error: 42.5 → 18.4
Time: 31.0s
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 -1164558.298979503:\\ \;\;\;\;\left({\left(\frac{i}{n}\right)}^{n} + -1\right) \cdot \frac{100}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 5.683451278453723 \cdot 10^{-38}:\\ \;\;\;\;100 \cdot n + \left(\frac{50}{3} \cdot i + 50\right) \cdot \left(n \cdot i\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(\left(\left(\log i \cdot \log i + \log n \cdot \log n\right) \cdot \left(\left(n \cdot n\right) \cdot \left(\frac{1}{2} \cdot n\right)\right) + \left(\left(\log i \cdot {n}^{4}\right) \cdot \frac{1}{6}\right) \cdot \left(\log n \cdot \log n\right)\right) + \left(\left({\left(\log i\right)}^{3} \cdot \left(\frac{1}{6} \cdot {n}^{4}\right) + \log i \cdot \left(n \cdot n\right)\right) + \left(\frac{1}{3} \cdot {n}^{4}\right) \cdot \left(\left(\log n \cdot \log n\right) \cdot \log i\right)\right)\right) - \left(\left(\left(\log i \cdot \log i\right) \cdot \left(\left(\frac{1}{6} \cdot {n}^{4}\right) \cdot \log n\right) + \left(\left({n}^{4} \cdot \log n\right) \cdot \frac{1}{3}\right) \cdot \left(\log i \cdot \log i\right)\right) + \left(\left(\log n \cdot \left(n \cdot n\right) + {\left(\log n\right)}^{3} \cdot \left(\frac{1}{6} \cdot {n}^{4}\right)\right) + \left(\left(n \cdot n\right) \cdot \left(\frac{1}{2} \cdot n\right)\right) \cdot \left(\log n \cdot \log i + \log n \cdot \log i\right)\right)\right)\right) \cdot \left(100 \cdot \frac{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.5
Target42.3
Herbie18.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 < -1164558.298979503

    1. Initial program 26.3

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

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

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

    if -1164558.298979503 < i < 5.683451278453723e-38

    1. Initial program 50.0

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

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

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

      \[\leadsto 100 \cdot \color{blue}{\left(\frac{1}{i} \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{1}{n}}\right)}\]
    6. Applied associate-*r*50.4

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

      \[\leadsto \left(100 \cdot \frac{1}{i}\right) \cdot \color{blue}{\left(n \cdot {\left(\frac{i}{n} + 1\right)}^{n} - n\right)}\]
    8. Taylor expanded around -inf 49.8

      \[\leadsto \left(100 \cdot \frac{1}{i}\right) \cdot \color{blue}{\left(-1 \cdot \left(\left(1 - e^{i}\right) \cdot n\right)\right)}\]
    9. Simplified49.8

      \[\leadsto \left(100 \cdot \frac{1}{i}\right) \cdot \color{blue}{\left(e^{i} \cdot n - n\right)}\]
    10. Taylor expanded around 0 16.7

      \[\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)}\]
    11. Simplified16.7

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

    if 5.683451278453723e-38 < i

    1. Initial program 36.7

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

      \[\leadsto 100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\color{blue}{i \cdot \frac{1}{n}}}\]
    4. Applied *-un-lft-identity36.7

      \[\leadsto 100 \cdot \frac{\color{blue}{1 \cdot \left({\left(1 + \frac{i}{n}\right)}^{n} - 1\right)}}{i \cdot \frac{1}{n}}\]
    5. Applied times-frac36.7

      \[\leadsto 100 \cdot \color{blue}{\left(\frac{1}{i} \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{1}{n}}\right)}\]
    6. Applied associate-*r*36.7

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

      \[\leadsto \left(100 \cdot \frac{1}{i}\right) \cdot \color{blue}{\left(n \cdot {\left(\frac{i}{n} + 1\right)}^{n} - n\right)}\]
    8. Taylor expanded around 0 25.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \le -1164558.298979503:\\ \;\;\;\;\left({\left(\frac{i}{n}\right)}^{n} + -1\right) \cdot \frac{100}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 5.683451278453723 \cdot 10^{-38}:\\ \;\;\;\;100 \cdot n + \left(\frac{50}{3} \cdot i + 50\right) \cdot \left(n \cdot i\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(\left(\left(\log i \cdot \log i + \log n \cdot \log n\right) \cdot \left(\left(n \cdot n\right) \cdot \left(\frac{1}{2} \cdot n\right)\right) + \left(\left(\log i \cdot {n}^{4}\right) \cdot \frac{1}{6}\right) \cdot \left(\log n \cdot \log n\right)\right) + \left(\left({\left(\log i\right)}^{3} \cdot \left(\frac{1}{6} \cdot {n}^{4}\right) + \log i \cdot \left(n \cdot n\right)\right) + \left(\frac{1}{3} \cdot {n}^{4}\right) \cdot \left(\left(\log n \cdot \log n\right) \cdot \log i\right)\right)\right) - \left(\left(\left(\log i \cdot \log i\right) \cdot \left(\left(\frac{1}{6} \cdot {n}^{4}\right) \cdot \log n\right) + \left(\left({n}^{4} \cdot \log n\right) \cdot \frac{1}{3}\right) \cdot \left(\log i \cdot \log i\right)\right) + \left(\left(\log n \cdot \left(n \cdot n\right) + {\left(\log n\right)}^{3} \cdot \left(\frac{1}{6} \cdot {n}^{4}\right)\right) + \left(\left(n \cdot n\right) \cdot \left(\frac{1}{2} \cdot n\right)\right) \cdot \left(\log n \cdot \log i + \log n \cdot \log i\right)\right)\right)\right) \cdot \left(100 \cdot \frac{1}{i}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019022 
(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: 30.4s)Debug log

sample275.0ms

Algorithm
intervals
Results
106.0ms36×body2560valid
89.0ms73×body1280valid
33.0ms40×body640valid
14.0ms119×body80valid
9.0ms87×body80nan
7.0ms18×body320valid
3.0ms12×body160valid

simplify182.0ms

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

prune5.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 41.5b

localize25.0ms

Local error

Found 4 expressions with local error:

12.2b
(/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))
9.3b
(pow (+ 1 (/ i n)) n)
1.6b
(- (pow (+ 1 (/ i n)) n) 1)
0.1b
(* 100 (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n)))

rewrite51.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
24.0ms
(/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))
12.0ms
(* 100 (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n)))
11.0ms
(- (pow (+ 1 (/ i n)) n) 1)
2.0ms
(pow (+ 1 (/ i n)) n)

series616.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
193.0ms
(/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))
179.0ms
(* 100 (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n)))
126.0ms
(- (pow (+ 1 (/ i n)) n) 1)
117.0ms
(pow (+ 1 (/ i n)) n)

simplify2.8s

Counts
97 → 117
Calls
97 calls:
Slowest
257.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)))
240.0ms
(* 100 (/ (* n (- (exp (* n (- (log (/ -1 n)) (log (/ -1 i))))) 1)) i))
229.0ms
(/ (* (- (exp (* (- (log (/ 1 n)) (log (/ 1 i))) n)) 1) n) i)
216.0ms
(* 100 (/ (* (- (exp (* (- (log (/ 1 n)) (log (/ 1 i))) n)) 1) n) i))
170.0ms
(- (exp (* (- (log (/ 1 n)) (log (/ 1 i))) n)) 1)

prune941.0ms

Pruning

7 alts after pruning (7 fresh and 0 done)

Merged error: 19.1b

localize14.0ms

Local error

Found 4 expressions with local error:

12.2b
(/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))
12.2b
(/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))
12.2b
(/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))
9.3b
(pow (+ 1 (/ i n)) n)

rewrite353.0ms

Algorithm
rewrite-expression-head
Rules
68×add-sqr-sqrt
60×times-frac
38×add-cube-cbrt
38×*-un-lft-identity
30×difference-of-sqr-1
21×div-inv
18×unpow-prod-down
15×associate-/l*
12×associate-/r*
11×add-exp-log
10×add-cbrt-cube
associate-/l/
pow1
add-log-exp
flip--
associate-/r/
div-exp
div-sub
flip3--
frac-2neg
clear-num
cbrt-undiv
pow-exp
pow-pow
pow-to-exp
Counts
4 → 148
Calls
4 calls:
Slowest
302.0ms
(/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))
24.0ms
(/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))
23.0ms
(/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))
2.0ms
(pow (+ 1 (/ i n)) n)

series616.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
197.0ms
(/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))
172.0ms
(/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))
148.0ms
(/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))
98.0ms
(pow (+ 1 (/ i n)) n)

simplify4.1s

Counts
176 → 160
Calls
176 calls:
Slowest
284.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)))
277.0ms
(/ (* (- (exp (* (- (log (/ 1 n)) (log (/ 1 i))) n)) 1) n) i)
276.0ms
(/ (* (- (exp (* (- (log (/ 1 n)) (log (/ 1 i))) n)) 1) n) i)
267.0ms
(/ (* (- (exp (* (- (log (/ 1 n)) (log (/ 1 i))) n)) 1) n) i)
255.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)))

prune1.9s

Pruning

7 alts after pruning (6 fresh and 1 done)

Merged error: 19.1b

localize30.0ms

Local error

Found 4 expressions with local error:

9.3b
(pow (+ (/ i n) 1) n)
1.6b
(- (* n (pow (+ (/ i n) 1) n)) n)
1.0b
(* (* 100 (/ 1 i)) (- (* n (pow (+ (/ i n) 1) n)) n))
0.2b
(* 100 (/ 1 i))

rewrite36.0ms

Algorithm
rewrite-expression-head
Rules
add-cube-cbrt
add-exp-log
associate-*r*
*-un-lft-identity
pow1
add-sqr-sqrt
associate-*r/
add-cbrt-cube
add-log-exp
flip--
un-div-inv
flip3--
frac-times
unpow-prod-down
sub-neg
*-commutative
associate-*l/
distribute-lft-in
distribute-rgt-in
div-inv
cbrt-unprod
prod-exp
pow-exp
pow-prod-down
associate-*l*
pow-pow
pow-to-exp
Counts
4 → 65
Calls
4 calls:
Slowest
22.0ms
(* (* 100 (/ 1 i)) (- (* n (pow (+ (/ i n) 1) n)) n))
7.0ms
(- (* n (pow (+ (/ i n) 1) n)) n)
5.0ms
(pow (+ (/ i n) 1) n)
1.0ms
(* 100 (/ 1 i))

series438.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
191.0ms
(- (* n (pow (+ (/ i n) 1) n)) n)
123.0ms
(* (* 100 (/ 1 i)) (- (* n (pow (+ (/ i n) 1) n)) n))
116.0ms
(pow (+ (/ i n) 1) n)
8.0ms
(* 100 (/ 1 i))

simplify4.2s

Counts
43 → 77
Calls
43 calls:
Slowest
420.0ms
(* 100 (- (* (* n (pow (+ (/ i n) 1) n)) (* n (pow (+ (/ i n) 1) n))) (* n n)))
334.0ms
(* (* 100 1) (- (* (* n (pow (+ (/ i n) 1) n)) (* n (pow (+ (/ i n) 1) n))) (* n n)))
323.0ms
(* 100 (- (pow (* n (pow (+ (/ i n) 1) n)) 3) (pow n 3)))
321.0ms
(* i (+ (* (* n (pow (+ (/ i n) 1) n)) (* n (pow (+ (/ i n) 1) n))) (+ (* n n) (* (* n (pow (+ (/ i n) 1) n)) n))))
293.0ms
(* i (+ (* (* n (pow (+ (/ i n) 1) n)) (* n (pow (+ (/ i n) 1) n))) (+ (* n n) (* (* n (pow (+ (/ i n) 1) n)) n))))

prune635.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 15.4b

localize15.0ms

Local error

Found 4 expressions with local error:

2.3b
(- (* (exp i) n) n)
1.3b
(* (* 100 (/ 1 i)) (- (* (exp i) n) n))
0.2b
(* 100 (/ 1 i))
0.0b
(* (exp i) n)

rewrite29.0ms

Algorithm
rewrite-expression-head
Rules
add-cube-cbrt
associate-*r*
*-un-lft-identity
add-sqr-sqrt
add-exp-log
associate-*r/
add-cbrt-cube
pow1
add-log-exp
flip--
un-div-inv
associate-*l*
flip3--
frac-times
*-commutative
sub-neg
associate-*l/
distribute-lft-in
distribute-rgt-in
div-inv
cbrt-unprod
prod-exp
pow-prod-down
Counts
4 → 63
Calls
4 calls:
Slowest
19.0ms
(* (* 100 (/ 1 i)) (- (* (exp i) n) n))
6.0ms
(- (* (exp i) n) n)
2.0ms
(* (exp i) n)
1.0ms
(* 100 (/ 1 i))

series119.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
39.0ms
(* (exp i) n)
37.0ms
(- (* (exp i) n) n)
35.0ms
(* (* 100 (/ 1 i)) (- (* (exp i) n) n))
8.0ms
(* 100 (/ 1 i))

simplify4.4s

Counts
40 → 75
Calls
40 calls:
Slowest
467.0ms
(+ (* 1/2 (* (pow i 2) n)) (+ (* 1/6 (* (pow i 3) n)) (* i n)))
407.0ms
(* (* 100 1) (- (* (* (exp i) n) (* (exp i) n)) (* n n)))
365.0ms
(* 100 (- (* (* (exp i) n) (* (exp i) n)) (* n n)))
357.0ms
(* i (+ (* (* (exp i) n) (* (exp i) n)) (+ (* n n) (* (* (exp i) n) n))))
296.0ms
(* i (+ (* (* (exp i) n) (* (exp i) n)) (+ (* n n) (* (* (exp i) n) n))))

prune573.0ms

Pruning

8 alts after pruning (8 fresh and 0 done)

Merged error: 3.7b

regimes170.0ms

Accuracy

50.3% (14.4b remaining)

Error of 18.4b against oracle of 3.9b and baseline of 32.9b

bsearch476.0ms

end0.0ms

sample7.3s

Algorithm
intervals
Results
2.8s2459×body1280valid
2.2s987×body2560valid
884.0ms1636×body640valid
644.0ms3073×body80valid
296.0ms828×body320valid
163.0ms2182×body80nan
86.0ms453×body160valid
7.0msbody5120valid