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

    1. Initial program 59.0

      \[\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.00014066850350312815 < 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.00014066850350312815:\\ \;\;\;\;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 2019022 
(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: 25.9s)Debug log

sample117.0ms

Algorithm
intervals
Results
71.0ms80×body1280valid
22.0ms47×body640valid
6.0ms24×body320valid
5.0ms93×body80valid
3.0ms76×body80nan
2.0ms12×body160valid

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: 38.2b

localize17.0ms

Local error

Found 1 expressions with local error:

4.4b
(log (+ 1 x))

rewrite2.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
2.0ms
(log (+ 1 x))

series38.0ms

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

simplify590.0ms

Counts
9 → 17
Calls
9 calls:
Slowest
324.0ms
(- (+ (/ 1 x) (log -1)) (+ (log (/ -1 x)) (* 1/2 (/ 1 (pow x 2)))))
124.0ms
(- (/ 1 x) (+ (log (/ 1 x)) (* 1/2 (/ 1 (pow x 2)))))
113.0ms
(- (+ x (* 1/3 (pow x 3))) (* 1/2 (pow x 2)))
8.0ms
(log (- (* 1 1) (* x x)))
6.0ms
(log (+ (pow 1 3) (pow x 3)))

prune100.0ms

Pruning

2 alts after pruning (1 fresh and 1 done)

Merged error: 0.0b

localize21.0ms

Local error

Found 4 expressions with local error:

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

rewrite23.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*
flip--
*-commutative
associate-*l/
flip3--
flip-+
cbrt-unprod
prod-exp
pow-prod-down
associate-*r*
flip3-+
sub-neg
+-commutative
Counts
4 → 46
Calls
4 calls:
Slowest
11.0ms
(* (- (* x 1/3) 1/2) (* x x))
7.0ms
(+ (* (- (* x 1/3) 1/2) (* x x)) x)
3.0ms
(- (* x 1/3) 1/2)
0.0ms
(* x 1/3)

series86.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
38.0ms
(* (- (* x 1/3) 1/2) (* x x))
25.0ms
(- (* x 1/3) 1/2)
16.0ms
(+ (* (- (* x 1/3) 1/2) (* x x)) x)
7.0ms
(* x 1/3)

simplify1.7s

Counts
19 → 58
Calls
19 calls:
Slowest
401.0ms
(* (- (* (* x 1/3) (* x 1/3)) (* 1/2 1/2)) (* x x))
371.0ms
(* (- (pow (* x 1/3) 3) (pow 1/2 3)) (* x x))
363.0ms
(* (* (* (- (* x 1/3) 1/2) (- (* x 1/3) 1/2)) (- (* x 1/3) 1/2)) (* (* (* x x) (* x x)) (* x x)))
108.0ms
(- (+ x (* 1/3 (pow x 3))) (* 1/2 (pow x 2)))
102.0ms
(- (+ x (* 1/3 (pow x 3))) (* 1/2 (pow x 2)))

prune336.0ms

Pruning

3 alts after pruning (1 fresh and 2 done)

Merged error: 0.0b

localize15.0ms

Local error

Found 4 expressions with local error:

12.6b
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
12.6b
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
12.6b
(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)))

rewrite49.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
37.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))

series291.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
81.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
76.0ms
(* (cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x)) (cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x)))
71.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
62.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))

simplify12.1s

Counts
59 → 87
Calls
59 calls:
Slowest
906.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))))
841.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))))
583.0ms
(cbrt (+ (pow (* (- (* x 1/3) 1/2) (* x x)) 3) (pow x 3)))
555.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))))
515.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)))

prune685.0ms

Pruning

4 alts after pruning (2 fresh and 2 done)

Merged error: 0.0b

localize21.0ms

Local error

Found 4 expressions with local error:

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

rewrite20.0ms

Algorithm
rewrite-expression-head
Rules
12×cbrt-prod
add-cube-cbrt
*-un-lft-identity
cbrt-div
add-sqr-sqrt
add-log-exp
flip-+
add-exp-log
pow1/3
add-cbrt-cube
flip3-+
pow1
Counts
4 → 52
Calls
4 calls:
Slowest
7.0ms
(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))
4.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))

series261.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
71.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
67.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
63.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))
59.0ms
(cbrt (+ (* (- (* x 1/3) 1/2) (* x x)) x))

simplify5.8s

Counts
32 → 64
Calls
32 calls:
Slowest
793.0ms
(cbrt (+ (pow (* (- (* x 1/3) 1/2) (* x x)) 3) (pow x 3)))
573.0ms
(cbrt (+ (pow (* (- (* x 1/3) 1/2) (* x x)) 3) (pow x 3)))
483.0ms
(cbrt (+ (pow (* (- (* x 1/3) 1/2) (* x x)) 3) (pow x 3)))
459.0ms
(cbrt (+ (pow (* (- (* x 1/3) 1/2) (* x x)) 3) (pow x 3)))
374.0ms
(cbrt (- (* (* (- (* x 1/3) 1/2) (* x x)) (* (- (* x 1/3) 1/2) (* x x))) (* x x)))

prune644.0ms

Pruning

4 alts after pruning (1 fresh and 3 done)

Merged error: 0.0b

regimes110.0ms

Accuracy

99.4% (0.1b remaining)

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

bsearch33.0ms

end0.0ms

sample3.0s

Algorithm
intervals
Results
1.6s2239×body1280valid
685.0ms1677×body640valid
206.0ms879×body320valid
135.0ms2826×body80valid
118.0ms2590×body80nan
46.0ms379×body160valid