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

    1. Initial program 58.8

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

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

    if 0.0001147652914481212 < 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.0001147652914481212:\\ \;\;\;\;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 2019007 
(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: 10.9s)Debug log

sample99.0ms

Algorithm
intervals

simplify3.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

3.0ms
(log (+ 1 x))

prune7.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 35.2b

localize13.0ms

Local error

Found 1 expressions with local error:

5.8b
(log (+ 1 x))

rewrite2.0ms

Algorithm
rewrite-expression-head
Counts
1 → 14
Calls

1 calls. Slowest were:

2.0ms
(log (+ 1 x))

series39.0ms

Counts
1 → 3
Calls

1 calls. Slowest were:

39.0ms
(log (+ 1 x))

simplify563.0ms

Counts
9 → 17
Calls

9 calls. Slowest were:

308.0ms
(- (+ (/ 1 x) (log -1)) (+ (log (/ -1 x)) (* 1/2 (/ 1 (pow x 2)))))
132.0ms
(- (/ 1 x) (+ (log (/ 1 x)) (* 1/2 (/ 1 (pow x 2)))))
93.0ms
(- (+ x (* 1/3 (pow x 3))) (* 1/2 (pow x 2)))

prune187.0ms

Pruning

5 alts after pruning (4 fresh and 1 done)

Merged error: 0.1b

localize17.0ms

Local error

Found 3 expressions with local error:

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

rewrite11.0ms

Algorithm
rewrite-expression-head
Counts
3 → 35
Calls

3 calls. Slowest were:

5.0ms
(* (- (* x 1/3) 1/2) (* x x))
5.0ms
(+ (* (- (* x 1/3) 1/2) (* x x)) x)
0.0ms
(* x 1/3)

series68.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

44.0ms
(* (- (* x 1/3) 1/2) (* x x))
17.0ms
(+ (* (- (* x 1/3) 1/2) (* x x)) x)
7.0ms
(* x 1/3)

simplify1.9s

Counts
16 → 44
Calls

16 calls. Slowest were:

505.0ms
(* (- (* (* x 1/3) (* x 1/3)) (* 1/2 1/2)) (* x x))
414.0ms
(* (- (pow (* x 1/3) 3) (pow 1/2 3)) (* x x))
410.0ms
(* (* (* (- (* x 1/3) 1/2) (- (* x 1/3) 1/2)) (- (* x 1/3) 1/2)) (* (* (* x x) (* x x)) (* x x)))

prune336.0ms

Pruning

5 alts after pruning (3 fresh and 2 done)

Merged error: 0.1b

localize17.0ms

Local error

Found 4 expressions with local error:

5.9b
(log (sqrt (+ 1 x)))
5.9b
(log (sqrt (+ 1 x)))
0.0b
(sqrt (+ 1 x))
0.0b
(sqrt (+ 1 x))

rewrite8.0ms

Algorithm
rewrite-expression-head
Counts
4 → 64
Calls

4 calls. Slowest were:

2.0ms
(log (sqrt (+ 1 x)))
2.0ms
(log (sqrt (+ 1 x)))
1.0ms
(sqrt (+ 1 x))

series109.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

41.0ms
(log (sqrt (+ 1 x)))
35.0ms
(log (sqrt (+ 1 x)))
17.0ms
(sqrt (+ 1 x))
16.0ms
(sqrt (+ 1 x))

simplify524.0ms

Counts
42 → 76
Calls

42 calls. Slowest were:

145.0ms
(- (+ (* 1/2 x) (* 1/6 (pow x 3))) (* 1/4 (pow x 2)))
114.0ms
(- (+ (* 1/2 x) (* 1/6 (pow x 3))) (* 1/4 (pow x 2)))
71.0ms
(- (+ (* 1/2 x) 1) (* 1/8 (pow x 2)))

prune693.0ms

Pruning

6 alts after pruning (4 fresh and 2 done)

Merged error: 0.1b

localize17.0ms

Local error

Found 4 expressions with local error:

5.9b
(log (sqrt (+ 1 x)))
5.7b
(log (cbrt (sqrt (+ 1 x))))
5.6b
(log (* (cbrt (sqrt (+ 1 x))) (cbrt (sqrt (+ 1 x)))))
0.3b
(cbrt (sqrt (+ 1 x)))

rewrite18.0ms

Algorithm
rewrite-expression-head
Counts
4 → 80
Calls

4 calls. Slowest were:

12.0ms
(log (* (cbrt (sqrt (+ 1 x))) (cbrt (sqrt (+ 1 x)))))
1.0ms
(log (cbrt (sqrt (+ 1 x))))
1.0ms
(cbrt (sqrt (+ 1 x)))

series212.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

62.0ms
(log (* (cbrt (sqrt (+ 1 x))) (cbrt (sqrt (+ 1 x)))))
60.0ms
(log (cbrt (sqrt (+ 1 x))))
50.0ms
(log (sqrt (+ 1 x)))
39.0ms
(cbrt (sqrt (+ 1 x)))

simplify1.6s

Counts
55 → 92
Calls

55 calls. Slowest were:

260.0ms
(- (+ (* 1/6 (/ 1 x)) (* 1/6 (log -1))) (+ (* 1/6 (log (/ -1 x))) (* 1/12 (/ 1 (pow x 2)))))
248.0ms
(- (+ (exp (* 1/6 (- (log -1) (log (/ -1 x))))) (* 1/6 (/ (exp (* 1/6 (- (log -1) (log (/ -1 x))))) x))) (* 5/72 (/ (exp (* 1/6 (- (log -1) (log (/ -1 x))))) (pow x 2))))
173.0ms
(- (+ (* 1/3 (/ 1 x)) (* 1/3 (log -1))) (+ (* 1/3 (log (/ -1 x))) (* 1/6 (/ 1 (pow x 2)))))

prune1.1s

Pruning

5 alts after pruning (3 fresh and 2 done)

Merged error: 0.1b

regimes165.0ms

Accuracy

99.3% (0.2b remaining)

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

bsearch44.0ms

end0.0ms

sample3.2s

Algorithm
intervals