Average Error: 9.7 → 0.5
Time: 26.1s
Precision: 64
Internal Precision: 128
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.9876686633063027:\\ \;\;\;\;\frac{2}{{x}^{5}} + \left(\frac{2}{\left(x \cdot x\right) \cdot x} + \frac{2}{{x}^{7}}\right)\\ \mathbf{elif}\;x \le 0.9941898984045208:\\ \;\;\;\;(\left(-2 - x\right) \cdot x + \left(\frac{-2}{x}\right))_*\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{\frac{\frac{2}{x}}{x}}{x} + \frac{2}{{x}^{7}}\right) + \frac{2}{{x}^{5}}\\ \end{array}\]

Error

Bits error versus x

Target

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

Derivation

  1. Split input into 3 regimes
  2. if x < -0.9876686633063027

    1. Initial program 19.4

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    2. Taylor expanded around inf 0.6

      \[\leadsto \color{blue}{2 \cdot \frac{1}{{x}^{7}} + \left(2 \cdot \frac{1}{{x}^{3}} + 2 \cdot \frac{1}{{x}^{5}}\right)}\]
    3. Simplified0.4

      \[\leadsto \color{blue}{\left(\frac{\frac{2}{x}}{x \cdot x} + \frac{2}{{x}^{7}}\right) + \frac{2}{{x}^{5}}}\]
    4. Using strategy rm
    5. Applied associate-/l/0.6

      \[\leadsto \left(\color{blue}{\frac{2}{\left(x \cdot x\right) \cdot x}} + \frac{2}{{x}^{7}}\right) + \frac{2}{{x}^{5}}\]

    if -0.9876686633063027 < x < 0.9941898984045208

    1. Initial program 0.0

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    2. Taylor expanded around 0 0.4

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

      \[\leadsto \color{blue}{\left(\frac{-2}{x} + \left(1 - x\right)\right)} + \frac{1}{x - 1}\]
    4. Taylor expanded around 0 0.4

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

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

    if 0.9941898984045208 < x

    1. Initial program 20.0

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    2. Taylor expanded around inf 0.8

      \[\leadsto \color{blue}{2 \cdot \frac{1}{{x}^{7}} + \left(2 \cdot \frac{1}{{x}^{3}} + 2 \cdot \frac{1}{{x}^{5}}\right)}\]
    3. Simplified0.3

      \[\leadsto \color{blue}{\left(\frac{\frac{2}{x}}{x \cdot x} + \frac{2}{{x}^{7}}\right) + \frac{2}{{x}^{5}}}\]
    4. Using strategy rm
    5. Applied associate-/r*0.3

      \[\leadsto \left(\color{blue}{\frac{\frac{\frac{2}{x}}{x}}{x}} + \frac{2}{{x}^{7}}\right) + \frac{2}{{x}^{5}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.9876686633063027:\\ \;\;\;\;\frac{2}{{x}^{5}} + \left(\frac{2}{\left(x \cdot x\right) \cdot x} + \frac{2}{{x}^{7}}\right)\\ \mathbf{elif}\;x \le 0.9941898984045208:\\ \;\;\;\;(\left(-2 - x\right) \cdot x + \left(\frac{-2}{x}\right))_*\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{\frac{\frac{2}{x}}{x}}{x} + \frac{2}{{x}^{7}}\right) + \frac{2}{{x}^{5}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019010 +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: 25.2s)Debug log

sample81.0ms

Algorithm
intervals

simplify74.0ms

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

prune5.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 10.0b

localize18.0ms

Local error

Found 4 expressions with local error:

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

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

series73.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
50.0ms
(+ (- (/ 1 (+ x 1)) (/ 2 x)) (/ 1 (- x 1)))
11.0ms
(- (/ 1 (+ x 1)) (/ 2 x))
6.0ms
(/ 1 (- x 1))
6.0ms
(/ 1 (+ x 1))

simplify10.6s

Counts
127 → 156
Calls
127 calls:
Slowest
646.0ms
(+ (* (- (* 1 x) (* (+ x 1) 2)) (- x 1)) (* (* (+ x 1) x) 1))
626.0ms
(- (+ (* 2 x) (+ (* 2 (pow x 3)) (* 2 (/ 1 x)))))
530.0ms
(fma (/ 1 (+ (pow x 3) (pow 1 3))) (+ (* x x) (- (* 1 1) (* x 1))) (- (* (sqrt (/ 2 x)) (sqrt (/ 2 x)))))
492.0ms
(* (+ (/ 1 (+ x 1)) (/ 2 x)) (- x 1))
462.0ms
(fma (/ 1 (+ (pow x 3) (pow 1 3))) (+ (* x x) (- (* 1 1) (* x 1))) (- (* (/ 2 x) 1)))

prune1.2s

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0.0b

localize21.0ms

Local error

Found 3 expressions with local error:

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

rewrite46.0ms

Algorithm
rewrite-expression-head
Rules
18×*-un-lft-identity
10×add-log-exp
distribute-lft-out
frac-add
fma-def
add-cube-cbrt
add-sqr-sqrt
div-inv
add-exp-log
sum-log
pow1
flip--
log1p-expm1-u
flip-+
add-cbrt-cube
flip3--
flip3-+
associate-/r*
expm1-log1p-u
associate-/r/
associate-+r-
associate-+r+
+-commutative
inv-pow
pow-flip
associate-+l-
frac-2neg
sub-neg
clear-num
associate-+l+
rec-exp
Counts
3 → 71
Calls
3 calls:
Slowest
35.0ms
(+ (+ (/ -2 x) (- 1 x)) (/ 1 (- x 1)))
7.0ms
(+ (/ -2 x) (- 1 x))
2.0ms
(/ 1 (- x 1))

series32.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
15.0ms
(+ (+ (/ -2 x) (- 1 x)) (/ 1 (- x 1)))
10.0ms
(/ 1 (- x 1))
7.0ms
(+ (/ -2 x) (- 1 x))

simplify5.4s

Counts
43 → 80
Calls
43 calls:
Slowest
839.0ms
(* (- (/ -2 x) (- 1 x)) (- x 1))
480.0ms
(+ (* (+ (* -2 (+ (* 1 1) (+ (* x x) (* 1 x)))) (* x (- (pow 1 3) (pow x 3)))) (- x 1)) (* (* x (+ (* 1 1) (+ (* x x) (* 1 x)))) 1))
444.0ms
(* (* x (+ 1 x)) (- x 1))
364.0ms
(- (+ (* 2 x) (+ (pow x 2) (* 2 (/ 1 x)))))
346.0ms
(* (* x (+ (* 1 1) (+ (* x x) (* 1 x)))) (- x 1))

prune612.0ms

Pruning

3 alts after pruning (3 fresh and 0 done)

Merged error: 0.0b

localize12.0ms

Local error

Found 0 expressions with local error:

rewrite0.0ms

Algorithm
rewrite-expression-head
Rules
Counts
0 → 0
Calls
0 calls:
Slowest

series0.0ms

Counts
0 → 0
Calls
0 calls:
Slowest

simplify0.0ms

Counts
0 → 0
Calls
0 calls:
Slowest

prune15.0ms

Pruning

3 alts after pruning (2 fresh and 1 done)

Merged error: 0.0b

localize44.0ms

Local error

Found 4 expressions with local error:

0.1b
(/ (/ 2 x) (* x x))
0.1b
(/ 2 (pow x 7))
0.0b
(/ 2 (pow x 5))
0.0b
(+ (+ (/ (/ 2 x) (* x x)) (/ 2 (pow x 7))) (/ 2 (pow x 5)))

rewrite65.0ms

Algorithm
rewrite-expression-head
Rules
16×*-un-lft-identity
add-log-exp
add-cube-cbrt
add-sqr-sqrt
associate-/r*
add-exp-log
add-cbrt-cube
div-inv
associate-/l*
distribute-lft-out
log1p-expm1-u
frac-add
times-frac
fma-def
pow1
expm1-log1p-u
frac-2neg
sum-log
clear-num
flip-+
flip3-+
associate-/l/
div-exp
associate-+l+
+-commutative
cbrt-undiv
Counts
4 → 78
Calls
4 calls:
Slowest
57.0ms
(+ (+ (/ (/ 2 x) (* x x)) (/ 2 (pow x 7))) (/ 2 (pow x 5)))
6.0ms
(/ (/ 2 x) (* x x))
1.0ms
(/ 2 (pow x 7))
1.0ms
(/ 2 (pow x 5))

series115.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
40.0ms
(+ (+ (/ (/ 2 x) (* x x)) (/ 2 (pow x 7))) (/ 2 (pow x 5)))
28.0ms
(/ 2 (pow x 7))
25.0ms
(/ 2 (pow x 5))
22.0ms
(/ (/ 2 x) (* x x))

simplify3.2s

Counts
43 → 90
Calls
43 calls:
Slowest
556.0ms
(* (+ (* (/ (/ 2 x) (* x x)) (/ (/ 2 x) (* x x))) (- (* (/ 2 (pow x 7)) (/ 2 (pow x 7))) (* (/ (/ 2 x) (* x x)) (/ 2 (pow x 7))))) (pow x 5))
539.0ms
(/ (* (* (/ 2 x) (/ 2 x)) (/ 2 x)) (* (* (* x x) (* x x)) (* x x)))
374.0ms
(+ (* 2 (/ 1 (pow x 7))) (+ (* 2 (/ 1 (pow x 3))) (* 2 (/ 1 (pow x 5)))))
347.0ms
(+ (* 2 (/ 1 (pow x 7))) (+ (* 2 (/ 1 (pow x 3))) (* 2 (/ 1 (pow x 5)))))
323.0ms
(+ (* 2 (/ 1 (pow x 7))) (+ (* 2 (/ 1 (pow x 3))) (* 2 (/ 1 (pow x 5)))))

prune938.0ms

Pruning

6 alts after pruning (5 fresh and 1 done)

Merged error: 0.0b

regimes58.0ms

Accuracy

98.7% (0.4b remaining)

Error of 0.5b against oracle of 0.0b and baseline of 31.0b

bsearch178.0ms

end0.0ms

sample2.3s

Algorithm
intervals