Average Error: 42.0 → 21.9
Time: 33.6s
Precision: 64
Internal Precision: 128
\[100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\]
\[\begin{array}{l} \mathbf{if}\;n \le -6.946497033310484 \cdot 10^{+191}:\\ \;\;\;\;n \cdot 100 + \left(i \cdot n\right) \cdot \left(50 + i \cdot \frac{50}{3}\right)\\ \mathbf{elif}\;n \le -4.056551695566858 \cdot 10^{+130}:\\ \;\;\;\;100 \cdot \frac{\frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{i}}{\frac{1}{n}}\\ \mathbf{elif}\;n \le -4.0276202651907404 \cdot 10^{-09} \lor \neg \left(n \le 9.658195263911622 \cdot 10^{-134}\right):\\ \;\;\;\;n \cdot 100 + \left(i \cdot n\right) \cdot \left(50 + i \cdot \frac{50}{3}\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \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
Herbie21.9
\[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 n < -6.946497033310484e+191 or -4.056551695566858e+130 < n < -4.0276202651907404e-09 or 9.658195263911622e-134 < n

    1. Initial program 51.9

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

      \[\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 22.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. Simplified21.9

      \[\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. Taylor expanded around 0 22.1

      \[\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)}\]
    7. Simplified21.9

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

    if -6.946497033310484e+191 < n < -4.056551695566858e+130

    1. Initial program 42.7

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

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

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

    if -4.0276202651907404e-09 < n < 9.658195263911622e-134

    1. Initial program 24.7

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

      \[\leadsto \color{blue}{0}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification21.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \le -6.946497033310484 \cdot 10^{+191}:\\ \;\;\;\;n \cdot 100 + \left(i \cdot n\right) \cdot \left(50 + i \cdot \frac{50}{3}\right)\\ \mathbf{elif}\;n \le -4.056551695566858 \cdot 10^{+130}:\\ \;\;\;\;100 \cdot \frac{\frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{i}}{\frac{1}{n}}\\ \mathbf{elif}\;n \le -4.0276202651907404 \cdot 10^{-09} \lor \neg \left(n \le 9.658195263911622 \cdot 10^{-134}\right):\\ \;\;\;\;n \cdot 100 + \left(i \cdot n\right) \cdot \left(50 + i \cdot \frac{50}{3}\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]

Reproduce

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

start451.0ms

Algorithm
intervals

setup357.0ms

Pruning

2 alts after pruning (2 fresh and 0 done)

Merged error: 40.0b

localize36.0ms

Local error

Found 4 expressions with local error:

10.2b
(/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))
9.2b
(pow (+ 1 (/ i n)) n)
1.2b
(- (pow (+ 1 (/ i n)) n) 1)
0.1b
(* 100 (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n)))

rewrite78.0ms

Algorithm
rewrite-expression-head
Counts
4 → 105
Calls

4 calls. Slowest were:

39.0ms
(/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))
17.0ms
(* 100 (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n)))
16.0ms
(- (pow (+ 1 (/ i n)) n) 1)

series758.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

249.0ms
(/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))
241.0ms
(* 100 (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n)))
158.0ms
(pow (+ 1 (/ i n)) n)
111.0ms
(- (pow (+ 1 (/ i n)) n) 1)

simplify3.9s

Counts
97 → 117
Calls

97 calls. Slowest were:

347.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)))
337.0ms
(/ (* (- (exp (* (- (log (/ 1 n)) (log (/ 1 i))) n)) 1) n) i)
295.0ms
(* 100 (/ (* n (- (exp (* n (- (log (/ -1 n)) (log (/ -1 i))))) 1)) i))

prune1.6s

Pruning

9 alts after pruning (9 fresh and 0 done)

Merged error: 18.1b

localize23.0ms

Local error

Found 4 expressions with local error:

11.9b
(- (/ (pow (+ 1 (/ i n)) n) (/ i n)) (/ 1 (/ i n)))
9.2b
(pow (+ 1 (/ i n)) n)
0.6b
(/ 1 (/ i n))
0.6b
(/ (pow (+ 1 (/ i n)) n) (/ i n))

rewrite22.0ms

Algorithm
rewrite-expression-head
Counts
4 → 103
Calls

4 calls. Slowest were:

14.0ms
(- (/ (pow (+ 1 (/ i n)) n) (/ i n)) (/ 1 (/ i n)))
5.0ms
(/ (pow (+ 1 (/ i n)) n) (/ i n))
1.0ms
(pow (+ 1 (/ i n)) n)

series555.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

231.0ms
(- (/ (pow (+ 1 (/ i n)) n) (/ i n)) (/ 1 (/ i n)))
191.0ms
(/ (pow (+ 1 (/ i n)) n) (/ i n))
122.0ms
(pow (+ 1 (/ i n)) n)
11.0ms
(/ 1 (/ i n))

simplify2.9s

Counts
103 → 115
Calls

103 calls. Slowest were:

402.0ms
(/ (* (- (exp (* (- (log (/ 1 n)) (log (/ 1 i))) n)) 1) n) i)
285.0ms
(/ (* (exp (* (- (log (/ 1 n)) (log (/ 1 i))) n)) n) i)
279.0ms
(/ (* (* (pow (+ 1 (/ i n)) n) (pow (+ 1 (/ i n)) n)) (pow (+ 1 (/ i n)) n)) (* (* (/ i n) (/ i n)) (/ i n)))

prune1.5s

Pruning

14 alts after pruning (14 fresh and 0 done)

Merged error: 8.1b

localize23.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)))

rewrite16.0ms

Algorithm
rewrite-expression-head
Counts
4 → 54
Calls

4 calls. Slowest were:

10.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))))

series116.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

35.0ms
(* (* i n) (+ (* 1/6 i) 1/2))
33.0ms
(* 100 (+ n (* (* i n) (+ (* 1/6 i) 1/2))))
32.0ms
(+ n (* (* i n) (+ (* 1/6 i) 1/2)))
16.0ms
(* 1/6 i)

simplify3.1s

Counts
31 → 66
Calls

31 calls. Slowest were:

375.0ms
(- n (* (* i n) (+ (* 1/6 i) 1/2)))
345.0ms
(* 100 (* (* i n) (+ (* 1/6 i) 1/2)))
292.0ms
(* (* (* i n) (+ (* 1/6 i) 1/2)) 100)

prune890.0ms

Pruning

19 alts after pruning (19 fresh and 0 done)

Merged error: 8.1b

localize16.0ms

Local error

Found 3 expressions with local error:

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

rewrite8.0ms

Algorithm
rewrite-expression-head
Counts
3 → 40
Calls

3 calls. Slowest were:

4.0ms
(+ (* (* i n) (+ 50 (* 50/3 i))) (* 100 n))
3.0ms
(* (* i n) (+ 50 (* 50/3 i)))
0.0ms
(* 50/3 i)

series80.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

35.0ms
(+ (* (* i n) (+ 50 (* 50/3 i))) (* 100 n))
34.0ms
(* (* i n) (+ 50 (* 50/3 i)))
11.0ms
(* 50/3 i)

simplify1.2s

Counts
22 → 49
Calls

22 calls. Slowest were:

191.0ms
(* (exp (* (* i n) (+ 50 (* 50/3 i)))) (exp (* 100 n)))
161.0ms
(* (* (* (* i n) (* i n)) (* i n)) (* (* (+ 50 (* 50/3 i)) (+ 50 (* 50/3 i))) (+ 50 (* 50/3 i))))
137.0ms
(+ (* 50/3 (* (pow i 2) n)) (+ (* 100 n) (* 50 (* i n))))

prune409.0ms

Pruning

19 alts after pruning (18 fresh and 1 done)

Merged error: 8.1b

regimes376.0ms

Accuracy

46.2% (13.6b remaining)

Error of 21.9b against oracle of 8.3b and baseline of 33.6b

bsearch808.0ms