Average Error: 9.8 → 0.1
Time: 27.8s
Precision: 64
Internal Precision: 128
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
\[\frac{\frac{2}{(x \cdot x + x)_*}}{x + -1}\]

Error

Bits error versus x

Target

Original9.8
Target0.3
Herbie0.1
\[\frac{2}{x \cdot \left(x \cdot x - 1\right)}\]

Derivation

  1. Initial program 9.8

    \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
  2. Using strategy rm
  3. Applied frac-sub26.2

    \[\leadsto \color{blue}{\frac{1 \cdot x - \left(x + 1\right) \cdot 2}{\left(x + 1\right) \cdot x}} + \frac{1}{x - 1}\]
  4. Applied frac-add25.4

    \[\leadsto \color{blue}{\frac{\left(1 \cdot x - \left(x + 1\right) \cdot 2\right) \cdot \left(x - 1\right) + \left(\left(x + 1\right) \cdot x\right) \cdot 1}{\left(\left(x + 1\right) \cdot x\right) \cdot \left(x - 1\right)}}\]
  5. Simplified25.9

    \[\leadsto \frac{\color{blue}{(\left(x + (-2 \cdot x + -2)_*\right) \cdot \left(x + -1\right) + \left((x \cdot x + x)_*\right))_*}}{\left(\left(x + 1\right) \cdot x\right) \cdot \left(x - 1\right)}\]
  6. Simplified25.9

    \[\leadsto \frac{(\left(x + (-2 \cdot x + -2)_*\right) \cdot \left(x + -1\right) + \left((x \cdot x + x)_*\right))_*}{\color{blue}{(x \cdot x + x)_* \cdot \left(-1 + x\right)}}\]
  7. Taylor expanded around inf 0.3

    \[\leadsto \frac{\color{blue}{2}}{(x \cdot x + x)_* \cdot \left(-1 + x\right)}\]
  8. Using strategy rm
  9. Applied associate-/r*0.1

    \[\leadsto \color{blue}{\frac{\frac{2}{(x \cdot x + x)_*}}{-1 + x}}\]
  10. Final simplification0.1

    \[\leadsto \frac{\frac{2}{(x \cdot x + x)_*}}{x + -1}\]

Reproduce

herbie shell --seed 2019016 +o rules:numerics
(FPCore (x)
  :name "3frac (problem 3.3.3)"

  :herbie-target
  (/ 2 (* x (- (* x x) 1)))

  (+ (- (/ 1 (+ x 1)) (/ 2 x)) (/ 1 (- x 1))))

Details

Time bar (total: 27.3s)Debug log

sample100.0ms

Algorithm
intervals
Results
256×(pre true 80)
130×(body real 80)
49×(body real 640)
28×(body real 320)
27×(body real 160)
22×(body real 1280)

simplify65.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
64.0ms
(+ (- (/ 1 (+ x 1)) (/ 2 x)) (/ 1 (- x 1)))

prune8.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 10.0b

localize38.0ms

Local error

Found 4 expressions with local error:

3.0b
(+ (- (/ 1 (+ x 1)) (/ 2 x)) (/ 1 (- x 1)))
0.0b
(- (/ 1 (+ x 1)) (/ 2 x))
0.0b
(/ 1 (- x 1))
0.0b
(/ 1 (+ x 1))

rewrite76.0ms

Algorithm
rewrite-expression-head
Rules
48×prod-diff
45×*-un-lft-identity
32×add-sqr-sqrt
30×div-inv
28×add-cube-cbrt
26×associate-+l+
22×associate-/r/
11×add-log-exp
11×flip-+
11×flip3-+
distribute-lft-out--
distribute-lft-out
add-exp-log
fma-neg
fma-def
associate-/r*
pow1
log1p-expm1-u
add-cbrt-cube
expm1-log1p-u
flip--
frac-add
flip3--
difference-of-squares
inv-pow
pow-flip
frac-sub
diff-log
frac-2neg
sub-neg
sum-log
clear-num
rec-exp
associate-+l-
+-commutative
Counts
4 → 144
Calls
4 calls:
Slowest
57.0ms
(+ (- (/ 1 (+ x 1)) (/ 2 x)) (/ 1 (- x 1)))
12.0ms
(- (/ 1 (+ x 1)) (/ 2 x))
2.0ms
(/ 1 (+ x 1))
2.0ms
(/ 1 (- x 1))

series103.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
61.0ms
(+ (- (/ 1 (+ x 1)) (/ 2 x)) (/ 1 (- x 1)))
18.0ms
(- (/ 1 (+ x 1)) (/ 2 x))
13.0ms
(/ 1 (+ x 1))
11.0ms
(/ 1 (- x 1))

simplify11.2s

Counts
127 → 156
Calls
127 calls:
Slowest
797.0ms
(+ (* (- (* 1 x) (* (+ x 1) 2)) (- x 1)) (* (* (+ x 1) x) 1))
636.0ms
(- (+ (* 2 x) (+ (* 2 (pow x 3)) (* 2 (/ 1 x)))))
520.0ms
(* (+ (/ 1 (+ x 1)) (/ 2 x)) (- x 1))
506.0ms
(fma (/ 1 (+ (pow x 3) (pow 1 3))) (+ (* x x) (- (* 1 1) (* x 1))) (- (* (sqrt (/ 2 x)) (sqrt (/ 2 x)))))
488.0ms
(fma (/ 1 (+ (pow x 3) (pow 1 3))) (+ (* x x) (- (* 1 1) (* x 1))) (- (* (/ 2 x) 1)))

prune1.4s

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0.0b

localize37.0ms

Local error

Found 4 expressions with local error:

30.9b
(fma (+ x (fma -2 x -2)) (+ x -1) (fma x x x))
0.1b
(* (fma x x x) (+ -1 x))
0.0b
(+ x (fma -2 x -2))
0.0b
(/ (fma (+ x (fma -2 x -2)) (+ x -1) (fma x x x)) (* (fma x x x) (+ -1 x)))

rewrite22.0ms

Algorithm
rewrite-expression-head
Rules
11×add-exp-log
11×add-cbrt-cube
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
pow1
add-log-exp
log1p-expm1-u
associate-*r/
expm1-log1p-u
associate-/l*
flip-+
associate-*l*
associate-*r*
times-frac
flip3-+
fma-udef
cbrt-unprod
associate-/r/
prod-exp
div-exp
cbrt-undiv
div-inv
*-commutative
pow-prod-down
distribute-lft-in
frac-2neg
associate-/r*
clear-num
associate-+r+
+-commutative
distribute-rgt-in
Counts
4 → 71
Calls
4 calls:
Slowest
11.0ms
(/ (fma (+ x (fma -2 x -2)) (+ x -1) (fma x x x)) (* (fma x x x) (+ -1 x)))
8.0ms
(* (fma x x x) (+ -1 x))
2.0ms
(+ x (fma -2 x -2))
0.0ms
(fma (+ x (fma -2 x -2)) (+ x -1) (fma x x x))

series325.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
124.0ms
(/ (fma (+ x (fma -2 x -2)) (+ x -1) (fma x x x)) (* (fma x x x) (+ -1 x)))
121.0ms
(fma (+ x (fma -2 x -2)) (+ x -1) (fma x x x))
55.0ms
(* (fma x x x) (+ -1 x))
24.0ms
(+ x (fma -2 x -2))

simplify4.0s

Counts
39 → 83
Calls
39 calls:
Slowest
598.0ms
(- (+ (* 2 x) (+ (* 2 (pow x 3)) (* 2 (/ 1 x)))))
498.0ms
(/ (* (cbrt (fma (+ x (fma -2 x -2)) (+ x -1) (fma x x x))) (cbrt (fma (+ x (fma -2 x -2)) (+ x -1) (fma x x x)))) (fma x x x))
373.0ms
(+ (* 2 (/ 1 (pow x 7))) (+ (* 2 (/ 1 (pow x 3))) (* 2 (/ 1 (pow x 5)))))
319.0ms
(/ (* (* (fma (+ x (fma -2 x -2)) (+ x -1) (fma x x x)) (fma (+ x (fma -2 x -2)) (+ x -1) (fma x x x))) (fma (+ x (fma -2 x -2)) (+ x -1) (fma x x x))) (* (* (* (fma x x x) (fma x x x)) (fma x x x)) (* (* (+ -1 x) (+ -1 x)) (+ -1 x))))
318.0ms
(+ (* 2 (/ 1 (pow x 7))) (+ (* 2 (/ 1 (pow x 3))) (* 2 (/ 1 (pow x 5)))))

prune789.0ms

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0.0b

localize3.0ms

Local error

Found 2 expressions with local error:

0.9b
(/ 2 (* (fma x x x) (+ -1 x)))
0.1b
(* (fma x x x) (+ -1 x))

rewrite5.0ms

Algorithm
rewrite-expression-head
Rules
add-cube-cbrt
add-exp-log
associate-*r/
add-cbrt-cube
*-un-lft-identity
pow1
add-sqr-sqrt
associate-*l*
associate-*r*
add-log-exp
log1p-expm1-u
flip-+
associate-/r/
flip3-+
expm1-log1p-u
div-inv
cbrt-unprod
*-commutative
prod-exp
pow-prod-down
distribute-lft-in
frac-2neg
associate-/r*
clear-num
distribute-rgt-in
Counts
2 → 38
Calls
2 calls:
Slowest
4.0ms
(* (fma x x x) (+ -1 x))
1.0ms
(/ 2 (* (fma x x x) (+ -1 x)))

series92.0ms

Counts
2 → 6
Calls
2 calls:
Slowest
56.0ms
(* (fma x x x) (+ -1 x))
36.0ms
(/ 2 (* (fma x x x) (+ -1 x)))

simplify1.6s

Counts
21 → 44
Calls
21 calls:
Slowest
540.0ms
(- (+ (* 2 x) (+ (* 2 (pow x 3)) (* 2 (/ 1 x)))))
320.0ms
(+ (* 2 (/ 1 (pow x 7))) (+ (* 2 (/ 1 (pow x 3))) (* 2 (/ 1 (pow x 5)))))
263.0ms
(+ (* 2 (/ 1 (pow x 7))) (+ (* 2 (/ 1 (pow x 3))) (* 2 (/ 1 (pow x 5)))))
168.0ms
(* (* (* (fma x x x) (fma x x x)) (fma x x x)) (* (* (+ -1 x) (+ -1 x)) (+ -1 x)))
73.0ms
(* (fma x x x) (+ -1 x))

prune386.0ms

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0b

localize11.0ms

Local error

Found 2 expressions with local error:

0.1b
(/ 2 (fma x x x))
0.0b
(/ (/ 2 (fma x x x)) (+ -1 x))

rewrite9.0ms

Algorithm
rewrite-expression-head
Rules
12×add-cube-cbrt
12×times-frac
12×*-un-lft-identity
12×add-sqr-sqrt
div-inv
associate-/r*
associate-/l*
add-exp-log
add-cbrt-cube
add-log-exp
log1p-expm1-u
associate-/r/
frac-2neg
clear-num
pow1
expm1-log1p-u
associate-/l/
flip-+
div-exp
flip3-+
cbrt-undiv
Counts
2 → 51
Calls
2 calls:
Slowest
7.0ms
(/ (/ 2 (fma x x x)) (+ -1 x))
1.0ms
(/ 2 (fma x x x))

series42.0ms

Counts
2 → 6
Calls
2 calls:
Slowest
28.0ms
(/ (/ 2 (fma x x x)) (+ -1 x))
13.0ms
(/ 2 (fma x x x))

simplify4.0s

Counts
42 → 57
Calls
42 calls:
Slowest
759.0ms
(- (+ (* 2 (/ 1 (pow x 4))) (* 2 (/ 1 (pow x 2)))) (* 2 (/ 1 (pow x 3))))
759.0ms
(- (+ (* 2 (/ 1 (pow x 4))) (* 2 (/ 1 (pow x 2)))) (* 2 (/ 1 (pow x 3))))
535.0ms
(- (+ (* 2 x) (+ (* 2 (pow x 3)) (* 2 (/ 1 x)))))
313.0ms
(+ (* 2 (/ 1 (pow x 7))) (+ (* 2 (/ 1 (pow x 3))) (* 2 (/ 1 (pow x 5)))))
253.0ms
(+ (* 2 (/ 1 (pow x 7))) (+ (* 2 (/ 1 (pow x 3))) (* 2 (/ 1 (pow x 5)))))

prune422.0ms

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 0b

regimes22.0ms

Accuracy

0% (0.1b remaining)

Error of 0.1b against oracle of 0.0b and baseline of 0.1b

bsearch1.0ms

end0.0ms

sample2.6s

Algorithm
intervals
Results
8004×(pre true 80)
4141×(body real 80)
1874×(body real 640)
914×(body real 320)
544×(body real 1280)
531×(body real 160)