Average Error: 39.2 → 0.2
Time: 29.2s
Precision: 64
Internal Precision: 128
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le 0.00011556263466977106:\\ \;\;\;\;x + \left(x \cdot x\right) \cdot \left(\frac{1}{3} \cdot x - \frac{1}{2}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + 1\right)\\ \end{array}\]

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original39.2
Target0.2
Herbie0.2
\[\begin{array}{l} \mathbf{if}\;1 + x = 1:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \log \left(1 + x\right)}{\left(1 + x\right) - 1}\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if x < 0.00011556263466977106

    1. Initial program 58.9

      \[\log \left(1 + x\right)\]
    2. Taylor expanded around 0 0.3

      \[\leadsto \color{blue}{\left(x + \frac{1}{3} \cdot {x}^{3}\right) - \frac{1}{2} \cdot {x}^{2}}\]
    3. Simplified0.2

      \[\leadsto \color{blue}{\left(x \cdot \frac{1}{3} - \frac{1}{2}\right) \cdot \left(x \cdot x\right) + x}\]

    if 0.00011556263466977106 < x

    1. Initial program 0.1

      \[\log \left(1 + x\right)\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le 0.00011556263466977106:\\ \;\;\;\;x + \left(x \cdot x\right) \cdot \left(\frac{1}{3} \cdot x - \frac{1}{2}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + 1\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2018362 
(FPCore (x)
  :name "ln(1 + x)"

  :herbie-target
  (if (== (+ 1 x) 1) x (/ (* x (log (+ 1 x))) (- (+ 1 x) 1)))

  (log (+ 1 x)))

Details

Time bar (total: 24.9s)Debug log

start82.0ms

Algorithm
intervals

setup22.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 42.6b

localize14.0ms

Local error

Found 1 expressions with local error:

5.3b
(log (+ 1 x))

rewrite2.0ms

Algorithm
rewrite-expression-head
Counts
1 → 14
Calls

1 calls. Slowest were:

2.0ms
(log (+ 1 x))

series38.0ms

Counts
1 → 3
Calls

1 calls. Slowest were:

38.0ms
(log (+ 1 x))

simplify670.0ms

Counts
9 → 17
Calls

9 calls. Slowest were:

377.0ms
(- (+ (/ 1 x) (log -1)) (+ (log (/ -1 x)) (* 1/2 (/ 1 (pow x 2)))))
172.0ms
(- (/ 1 x) (+ (log (/ 1 x)) (* 1/2 (/ 1 (pow x 2)))))
92.0ms
(- (+ x (* 1/3 (pow x 3))) (* 1/2 (pow x 2)))

prune121.0ms

Pruning

3 alts after pruning (2 fresh and 1 done)

Merged error: 0.1b

localize15.0ms

Local error

Found 4 expressions with local error:

0.3b
(* x 1/3)
0.0b
(* (- (* x 1/3) 1/2) (* x x))
0.0b
(- (* x 1/3) 1/2)
0.0b
(+ (* (- (* x 1/3) 1/2) (* x x)) x)

rewrite20.0ms

Algorithm
rewrite-expression-head
Counts
4 → 46
Calls

4 calls. Slowest were:

10.0ms
(+ (* (- (* x 1/3) 1/2) (* x x)) x)
6.0ms
(* (- (* x 1/3) 1/2) (* x x))
2.0ms
(- (* x 1/3) 1/2)

series85.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

43.0ms
(* (- (* x 1/3) 1/2) (* x x))
17.0ms
(- (* x 1/3) 1/2)
14.0ms
(+ (* (- (* x 1/3) 1/2) (* x x)) x)
11.0ms
(* x 1/3)

simplify1.8s

Counts
19 → 58
Calls

19 calls. Slowest were:

503.0ms
(* (- (* (* x 1/3) (* x 1/3)) (* 1/2 1/2)) (* x x))
415.0ms
(* (* (* (- (* x 1/3) 1/2) (- (* x 1/3) 1/2)) (- (* x 1/3) 1/2)) (* (* (* x x) (* x x)) (* x x)))
376.0ms
(* (- (pow (* x 1/3) 3) (pow 1/2 3)) (* x x))

prune483.0ms

Pruning

4 alts after pruning (2 fresh and 2 done)

Merged error: 0.1b

localize11.0ms

Local error

Found 4 expressions with local error:

11.4b
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
11.4b
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
11.4b
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
0.5b
(* (cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x)) (cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x)))

rewrite64.0ms

Algorithm
rewrite-expression-head
Counts
4 → 75
Calls

4 calls. Slowest were:

49.0ms
(* (cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x)) (cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x)))
5.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
4.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))

series247.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

76.0ms
(* (cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x)) (cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x)))
59.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
58.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
53.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))

simplify14.3s

Counts
59 → 87
Calls

59 calls. Slowest were:

1.1s
(* (cbrt (- (* (* (- (* x 1/3) 1/2) (* x x)) (* (- (* x 1/3) 1/2) (* x x))) (* x x))) (cbrt (+ (pow (* (- (* x 1/3) 1/2) (* x x)) 3) (pow x 3))))
958.0ms
(* (cbrt (+ (pow (* (- (* x 1/3) 1/2) (* x x)) 3) (pow x 3))) (cbrt (- (* (* (- (* x 1/3) 1/2) (* x x)) (* (- (* x 1/3) 1/2) (* x x))) (* x x))))
753.0ms
(* (cbrt (- (* (* (- (* x 1/3) 1/2) (* x x)) (* (- (* x 1/3) 1/2) (* x x))) (* x x))) (cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x)))

prune1.1s

Pruning

4 alts after pruning (2 fresh and 2 done)

Merged error: 0.1b

localize58.0ms

Local error

Found 4 expressions with local error:

30.1b
(cbrt (pow x 4))
16.8b
(cbrt (pow x 7))
11.4b
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
11.4b
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))

rewrite13.0ms

Algorithm
rewrite-expression-head
Counts
4 → 48
Calls

4 calls. Slowest were:

6.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
4.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
1.0ms
(cbrt (pow x 4))

series708.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

303.0ms
(cbrt (pow x 7))
269.0ms
(cbrt (pow x 4))
80.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
56.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))

simplify3.1s

Counts
28 → 60
Calls

28 calls. Slowest were:

585.0ms
(cbrt (+ (pow (* (- (* x 1/3) 1/2) (* x x)) 3) (pow x 3)))
509.0ms
(cbrt (+ (pow (* (- (* x 1/3) 1/2) (* x x)) 3) (pow x 3)))
414.0ms
(cbrt (- (* (* (- (* x 1/3) 1/2) (* x x)) (* (- (* x 1/3) 1/2) (* x x))) (* x x)))

prune1.7s

Pruning

4 alts after pruning (2 fresh and 2 done)

Merged error: 0.1b

regimes190.0ms

Accuracy

99.3% (0.1b remaining)

Error of 0.2b against oracle of 0.1b and baseline of 20.6b

bsearch48.0ms