Average Error: 42.1 → 21.4
Time: 29.2s
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 -0.0006916119981075335:\\ \;\;\;\;\left({\left(\frac{i}{n}\right)}^{n} + -1\right) \cdot \frac{100}{\frac{i}{n}}\\ \mathbf{elif}\;i \le 3.5996068140721376 \cdot 10^{-62}:\\ \;\;\;\;\left(n \cdot i\right) \cdot \left(\frac{50}{3} \cdot i + 50\right) + 100 \cdot n\\ \mathbf{else}:\\ \;\;\;\;n \cdot \left(100 \cdot \frac{{\left(\frac{i}{n} + 1\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.1
Target41.9
Herbie21.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.0006916119981075335

    1. Initial program 28.5

      \[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. Simplified18.7

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

    if -0.0006916119981075335 < i < 3.5996068140721376e-62

    1. Initial program 49.3

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

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

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

      \[\leadsto 100 \cdot \color{blue}{\left(n + \left(i \cdot n\right) \cdot \left(\frac{1}{6} \cdot i + \frac{1}{2}\right)\right)}\]
    6. Using strategy rm
    7. Applied distribute-rgt-in17.1

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

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

    if 3.5996068140721376e-62 < i

    1. Initial program 37.0

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

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

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

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

Reproduce

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

sample304.0ms

Algorithm
intervals

simplify206.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

206.0ms
(* 100 (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n)))

prune9.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 41.4b

localize17.0ms

Local error

Found 4 expressions with local error:

13.3b
(/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))
7.5b
(pow (+ 1 (/ i n)) n)
1.8b
(- (pow (+ 1 (/ i n)) n) 1)
0.0b
(* 100 (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n)))

rewrite60.0ms

Algorithm
rewrite-expression-head
Counts
4 → 105
Calls

4 calls. Slowest were:

21.0ms
(- (pow (+ 1 (/ i n)) n) 1)
18.0ms
(* 100 (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n)))
17.0ms
(/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))

series878.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

267.0ms
(/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))
258.0ms
(* 100 (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n)))
183.0ms
(- (pow (+ 1 (/ i n)) n) 1)
170.0ms
(pow (+ 1 (/ i n)) n)

simplify3.3s

Counts
97 → 117
Calls

97 calls. Slowest were:

313.0ms
(* 100 (/ (* n (- (exp (* n (- (log (/ -1 n)) (log (/ -1 i))))) 1)) i))
279.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)))
274.0ms
(/ (* (- (exp (* (- (log (/ 1 n)) (log (/ 1 i))) n)) 1) n) i)

prune1.2s

Pruning

11 alts after pruning (11 fresh and 0 done)

Merged error: 18.7b

localize21.0ms

Local error

Found 4 expressions with local error:

16.3b
(- (/ (pow (+ 1 (/ i n)) n) (/ i n)) (/ 1 (/ i n)))
7.5b
(pow (+ 1 (/ i n)) n)
0.8b
(/ (pow (+ 1 (/ i n)) n) (/ i n))
0.8b
(/ 1 (/ i n))

rewrite45.0ms

Algorithm
rewrite-expression-head
Counts
4 → 103
Calls

4 calls. Slowest were:

25.0ms
(- (/ (pow (+ 1 (/ i n)) n) (/ i n)) (/ 1 (/ i n)))
14.0ms
(/ (pow (+ 1 (/ i n)) n) (/ i n))
3.0ms
(pow (+ 1 (/ i n)) n)

series560.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

251.0ms
(- (/ (pow (+ 1 (/ i n)) n) (/ i n)) (/ 1 (/ i n)))
182.0ms
(/ (pow (+ 1 (/ i n)) n) (/ i n))
120.0ms
(pow (+ 1 (/ i n)) n)
8.0ms
(/ 1 (/ i n))

simplify2.6s

Counts
103 → 115
Calls

103 calls. Slowest were:

303.0ms
(/ (* (- (exp (* (- (log (/ 1 n)) (log (/ 1 i))) n)) 1) n) i)
281.0ms
(/ (* (exp (* (- (log (/ 1 n)) (log (/ 1 i))) n)) n) i)
244.0ms
(/ (* (* (pow (+ 1 (/ i n)) n) (pow (+ 1 (/ i n)) n)) (pow (+ 1 (/ i n)) n)) (* (* (/ i n) (/ i n)) (/ i n)))

prune1.3s

Pruning

16 alts after pruning (16 fresh and 0 done)

Merged error: 5.5b

localize19.0ms

Local error

Found 4 expressions with local error:

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

rewrite12.0ms

Algorithm
rewrite-expression-head
Counts
4 → 54
Calls

4 calls. Slowest were:

5.0ms
(* (* i n) (+ (* 1/6 i) 1/2))
3.0ms
(+ n (* (* i n) (+ (* 1/6 i) 1/2)))
2.0ms
(* 100 (+ n (* (* i n) (+ (* 1/6 i) 1/2))))

series147.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

52.0ms
(* 100 (+ n (* (* i n) (+ (* 1/6 i) 1/2))))
48.0ms
(+ n (* (* i n) (+ (* 1/6 i) 1/2)))
35.0ms
(* (* i n) (+ (* 1/6 i) 1/2))
12.0ms
(* 1/6 i)

simplify2.7s

Counts
31 → 66
Calls

31 calls. Slowest were:

321.0ms
(- n (* (* i n) (+ (* 1/6 i) 1/2)))
278.0ms
(* (* (* i n) (+ (* 1/6 i) 1/2)) 100)
248.0ms
(* 100 (* (* i n) (+ (* 1/6 i) 1/2)))

prune617.0ms

Pruning

18 alts after pruning (18 fresh and 0 done)

Merged error: 5.5b

localize28.0ms

Local error

Found 3 expressions with local error:

0.5b
(* i 50/3)
0.2b
(* (+ 50 (* i 50/3)) (* i n))
0.0b
(+ 50 (* i 50/3))

rewrite10.0ms

Algorithm
rewrite-expression-head
Counts
3 → 35
Calls

3 calls. Slowest were:

7.0ms
(* (+ 50 (* i 50/3)) (* i n))
1.0ms
(+ 50 (* i 50/3))
0.0ms
(* i 50/3)

series68.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

31.0ms
(* (+ 50 (* i 50/3)) (* i n))
26.0ms
(+ 50 (* i 50/3))
11.0ms
(* i 50/3)

simplify1.0s

Counts
16 → 44
Calls

16 calls. Slowest were:

383.0ms
(* (+ (pow 50 3) (pow (* i 50/3) 3)) (* i n))
172.0ms
(* (- (* 50 50) (* (* i 50/3) (* i 50/3))) (* i n))
121.0ms
(* (* (* (+ 50 (* i 50/3)) (+ 50 (* i 50/3))) (+ 50 (* i 50/3))) (* (* (* i n) (* i n)) (* i n)))

prune429.0ms

Pruning

18 alts after pruning (17 fresh and 1 done)

Merged error: 5.5b

regimes371.0ms

Accuracy

49.3% (12.9b remaining)

Error of 21.4b against oracle of 8.5b and baseline of 33.9b

bsearch437.0ms

end0.0ms

sample11.1s

Algorithm
intervals