Average Error: 38.7 → 0.2
Time: 27.4s
Precision: 64
Internal Precision: 128
\[\log \left(1 + x\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le 0.00013149958412846043:\\ \;\;\;\;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

Original38.7
Target0.3
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.00013149958412846043

    1. Initial program 58.8

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

      \[\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.00013149958412846043 < 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.00013149958412846043:\\ \;\;\;\;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 2019016 
(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: 26.8s)Debug log

sample145.0ms

Algorithm
intervals
Results
385×(pre true 80)
128×(body nan 80)
81×(body real 80)
75×(body real 1280)
54×(body real 640)
32×(body real 320)
15×(body real 160)

simplify2.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
2.0ms
(log (+ 1 x))

prune4.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 41.5b

localize6.0ms

Local error

Found 1 expressions with local error:

4.9b
(log (+ 1 x))

rewrite1.0ms

Algorithm
rewrite-expression-head
Rules
log-prod
add-cube-cbrt
add-exp-log
*-un-lft-identity
log-div
pow1
add-sqr-sqrt
add-log-exp
flip-+
log-pow
rem-log-exp
add-cbrt-cube
flip3-+
Counts
1 → 14
Calls
1 calls:
Slowest
1.0ms
(log (+ 1 x))

series34.0ms

Counts
1 → 3
Calls
1 calls:
Slowest
34.0ms
(log (+ 1 x))

simplify608.0ms

Counts
9 → 17
Calls
9 calls:
Slowest
279.0ms
(- (+ (/ 1 x) (log -1)) (+ (log (/ -1 x)) (* 1/2 (/ 1 (pow x 2)))))
158.0ms
(- (/ 1 x) (+ (log (/ 1 x)) (* 1/2 (/ 1 (pow x 2)))))
154.0ms
(- (+ x (* 1/3 (pow x 3))) (* 1/2 (pow x 2)))
5.0ms
(log (- (* 1 1) (* x x)))
4.0ms
(log (+ (pow 1 3) (pow x 3)))

prune115.0ms

Pruning

3 alts after pruning (2 fresh and 1 done)

Merged error: 0.1b

localize17.0ms

Local error

Found 3 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) (* x x)) x)

rewrite12.0ms

Algorithm
rewrite-expression-head
Rules
add-exp-log
add-cbrt-cube
pow1
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
add-log-exp
associate-*l*
*-commutative
associate-*l/
flip--
flip-+
cbrt-unprod
prod-exp
pow-prod-down
associate-*r*
flip3--
flip3-+
+-commutative
Counts
3 → 35
Calls
3 calls:
Slowest
6.0ms
(* (- (* x 1/3) 1/2) (* x x))
6.0ms
(+ (* (- (* x 1/3) 1/2) (* x x)) x)
0.0ms
(* x 1/3)

series58.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
30.0ms
(* (- (* x 1/3) 1/2) (* x x))
21.0ms
(+ (* (- (* x 1/3) 1/2) (* x x)) x)
7.0ms
(* x 1/3)

simplify1.9s

Counts
16 → 44
Calls
16 calls:
Slowest
522.0ms
(* (- (* (* x 1/3) (* x 1/3)) (* 1/2 1/2)) (* x x))
444.0ms
(* (* (* (- (* x 1/3) 1/2) (- (* x 1/3) 1/2)) (- (* x 1/3) 1/2)) (* (* (* x x) (* x x)) (* x x)))
327.0ms
(* (- (pow (* x 1/3) 3) (pow 1/2 3)) (* x x))
145.0ms
(- (+ x (* 1/3 (pow x 3))) (* 1/2 (pow x 2)))
108.0ms
(- (+ x (* 1/3 (pow x 3))) (* 1/2 (pow x 2)))

prune377.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:

12.9b
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
12.9b
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
12.9b
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
0.4b
(* (cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x)) (cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x)))

rewrite58.0ms

Algorithm
rewrite-expression-head
Rules
18×cbrt-div
15×cbrt-prod
11×add-cube-cbrt
11×*-un-lft-identity
11×add-sqr-sqrt
flip-+
flip3-+
pow1
pow1/3
add-exp-log
associate-*l*
associate-*r*
add-log-exp
add-cbrt-cube
frac-times
pow-prod-up
associate-*r/
associate-*l/
pow-prod-down
cbrt-unprod
*-commutative
prod-exp
pow-plus
pow2
Counts
4 → 75
Calls
4 calls:
Slowest
43.0ms
(* (cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x)) (cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x)))
4.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
4.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
4.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))

series313.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
87.0ms
(* (cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x)) (cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x)))
80.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
80.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
66.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))

simplify13.6s

Counts
59 → 87
Calls
59 calls:
Slowest
946.0ms
(* (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))))
900.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))))
839.0ms
(* (cbrt (+ (* (* (- (* x 1/3) 1/2) (* x x)) (* (- (* x 1/3) 1/2) (* x x))) (- (* x x) (* (* (- (* x 1/3) 1/2) (* x x)) x)))) (cbrt (+ (* (* (- (* x 1/3) 1/2) (* x x)) (* (- (* x 1/3) 1/2) (* x x))) (- (* x x) (* (* (- (* x 1/3) 1/2) (* x x)) x)))))
666.0ms
(* (cbrt (+ (pow (* (- (* x 1/3) 1/2) (* x x)) 3) (pow x 3))) (cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x)))
620.0ms
(* (cbrt (+ (pow (* (- (* x 1/3) 1/2) (* x x)) 3) (pow x 3))) (cbrt (+ (pow (* (- (* x 1/3) 1/2) (* x x)) 3) (pow x 3))))

prune776.0ms

Pruning

5 alts after pruning (3 fresh and 2 done)

Merged error: 0.1b

localize50.0ms

Local error

Found 4 expressions with local error:

29.9b
(cbrt (pow x 4))
18.0b
(cbrt (pow x 7))
12.9b
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
12.9b
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))

rewrite19.0ms

Algorithm
rewrite-expression-head
Rules
12×cbrt-prod
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
add-log-exp
add-exp-log
pow1/3
add-cbrt-cube
cbrt-div
pow1
flip-+
flip3-+
Counts
4 → 48
Calls
4 calls:
Slowest
8.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
8.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
1.0ms
(cbrt (pow x 4))
1.0ms
(cbrt (pow x 7))

series775.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
332.0ms
(cbrt (pow x 7))
316.0ms
(cbrt (pow x 4))
67.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
59.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))

simplify2.9s

Counts
28 → 60
Calls
28 calls:
Slowest
510.0ms
(cbrt (+ (pow (* (- (* x 1/3) 1/2) (* x x)) 3) (pow x 3)))
457.0ms
(cbrt (+ (pow (* (- (* x 1/3) 1/2) (* x x)) 3) (pow x 3)))
313.0ms
(cbrt (- (* (* (- (* x 1/3) 1/2) (* x x)) (* (- (* x 1/3) 1/2) (* x x))) (* x x)))
292.0ms
(cbrt (- (* (* (- (* x 1/3) 1/2) (* x x)) (* (- (* x 1/3) 1/2) (* x x))) (* x x)))
225.0ms
(- (+ (* 3/4 (/ (exp (* 1/3 (- (log 1/3) (* 3 (log (/ 1 x)))))) (pow x 2))) (exp (* 1/3 (- (log 1/3) (* 3 (log (/ 1 x))))))) (* 1/2 (/ (exp (* 1/3 (- (log 1/3) (* 3 (log (/ 1 x)))))) x)))

prune1.1s

Pruning

5 alts after pruning (3 fresh and 2 done)

Merged error: 0.1b

regimes163.0ms

Accuracy

99.4% (0.1b remaining)

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

bsearch23.0ms

end0.0ms

sample3.8s

Algorithm
intervals
Results
10752×(pre true 80)
2849×(body real 80)
2752×(body nan 80)
2248×(body real 1280)
1693×(body real 640)
793×(body real 320)
417×(body real 160)