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

    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.0001071617979895317 < 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.0001071617979895317:\\ \;\;\;\;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 2019008 
(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: 20.7s)Debug log

sample103.0ms

Algorithm
intervals

simplify2.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

2.0ms
(log (+ 1 x))

prune4.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 42.1b

localize6.0ms

Local error

Found 1 expressions with local error:

3.8b
(log (+ 1 x))

rewrite1.0ms

Algorithm
rewrite-expression-head
Counts
1 → 14
Calls

1 calls. Slowest were:

1.0ms
(log (+ 1 x))

series48.0ms

Counts
1 → 3
Calls

1 calls. Slowest were:

48.0ms
(log (+ 1 x))

simplify612.0ms

Counts
9 → 17
Calls

9 calls. Slowest were:

330.0ms
(- (+ (/ 1 x) (log -1)) (+ (log (/ -1 x)) (* 1/2 (/ 1 (pow x 2)))))
131.0ms
(- (+ x (* 1/3 (pow x 3))) (* 1/2 (pow x 2)))
120.0ms
(- (/ 1 x) (+ (log (/ 1 x)) (* 1/2 (/ 1 (pow x 2)))))

prune170.0ms

Pruning

3 alts after pruning (2 fresh and 1 done)

Merged error: 0.1b

localize15.0ms

Local error

Found 2 expressions with local error:

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

rewrite6.0ms

Algorithm
rewrite-expression-head
Counts
2 → 25
Calls

2 calls. Slowest were:

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

series51.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

43.0ms
(* (- (* x 1/3) 1/2) (* x x))
8.0ms
(* x 1/3)

simplify1.5s

Counts
13 → 31
Calls

13 calls. Slowest were:

463.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))
406.0ms
(* (* (* (- (* x 1/3) 1/2) (- (* x 1/3) 1/2)) (- (* x 1/3) 1/2)) (* (* (* x x) (* x x)) (* x x)))

prune237.0ms

Pruning

3 alts after pruning (1 fresh and 2 done)

Merged error: 0.1b

localize49.0ms

Local error

Found 4 expressions with local error:

13.0b
(log (+ 1 (pow x 3)))
11.8b
(log (+ (* 1 1) (- (* x x) (* 1 x))))
0.3b
(- (log (+ 1 (pow x 3))) (log (+ (* 1 1) (- (* x x) (* 1 x)))))
0.0b
(- (* x x) (* 1 x))

rewrite24.0ms

Algorithm
rewrite-expression-head
Counts
4 → 70
Calls

4 calls. Slowest were:

12.0ms
(- (log (+ 1 (pow x 3))) (log (+ (* 1 1) (- (* x x) (* 1 x)))))
8.0ms
(log (+ (* 1 1) (- (* x x) (* 1 x))))
2.0ms
(log (+ 1 (pow x 3)))

series431.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

306.0ms
(log (+ 1 (pow x 3)))
58.0ms
(- (log (+ 1 (pow x 3))) (log (+ (* 1 1) (- (* x x) (* 1 x)))))
40.0ms
(log (+ (* 1 1) (- (* x x) (* 1 x))))
27.0ms
(- (* x x) (* 1 x))

simplify2.8s

Counts
45 → 82
Calls

45 calls. Slowest were:

559.0ms
(log (+ (pow (* 1 1) 3) (pow (- (* x x) (* 1 x)) 3)))
283.0ms
(- (+ (/ 1 x) (log -1)) (+ (log (/ -1 x)) (* 1/2 (/ 1 (pow x 2)))))
167.0ms
(log (- (* (* 1 1) (* 1 1)) (* (- (* x x) (* 1 x)) (- (* x x) (* 1 x)))))

prune934.0ms

Pruning

3 alts after pruning (1 fresh and 2 done)

Merged error: 0.1b

localize43.0ms

Local error

Found 4 expressions with local error:

13.0b
(log (+ 1 (pow x 3)))
3.8b
(log (- (* 1 1) (- (* x x) (* 1 x))))
2.1b
(log (- 1 (* (- (* x x) x) (- (* x x) x))))
0.0b
(* (- (* x x) x) (- (* x x) x))

rewrite36.0ms

Algorithm
rewrite-expression-head
Counts
4 → 76
Calls

4 calls. Slowest were:

22.0ms
(* (- (* x x) x) (- (* x x) x))
8.0ms
(log (- (* 1 1) (- (* x x) (* 1 x))))
2.0ms
(log (+ 1 (pow x 3)))

series456.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

340.0ms
(log (+ 1 (pow x 3)))
53.0ms
(log (- 1 (* (- (* x x) x) (- (* x x) x))))
49.0ms
(log (- (* 1 1) (- (* x x) (* 1 x))))
14.0ms
(* (- (* x x) x) (- (* x x) x))

simplify8.9s

Counts
59 → 88
Calls

59 calls. Slowest were:

1.5s
(* (+ (* (* x x) (* x x)) (+ (* x x) (* (* x x) x))) (+ (* (* x x) (* x x)) (+ (* x x) (* (* x x) x))))
778.0ms
(* (- (pow (* x x) 3) (pow x 3)) (- (pow (* x x) 3) (pow x 3)))
436.0ms
(* (- (pow (* x x) 3) (pow x 3)) (- (* x x) x))

prune943.0ms

Pruning

4 alts after pruning (1 fresh and 3 done)

Merged error: 0.1b

regimes148.0ms

Accuracy

99.4% (0.1b remaining)

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

bsearch32.0ms

end0.0ms

sample3.2s

Algorithm
intervals