Average Error: 10.0 → 0.2
Time: 1.2m
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.9934881645172994:\\ \;\;\;\;(\left(\frac{2}{x}\right) \cdot \left(\frac{1}{x \cdot x}\right) + \left(\frac{2}{{x}^{7}}\right))_* + \frac{2}{{x}^{5}}\\ \mathbf{elif}\;x \le 129.39195686841717:\\ \;\;\;\;\sqrt{1 + x} \cdot \left(\sqrt{1 + x} \cdot \frac{1}{x \cdot x - 1}\right) + \left(\frac{1}{1 + x} - \frac{2}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{2}{{x}^{7}} + \frac{\frac{2}{x}}{x \cdot x}\right) + \frac{2}{{x}^{5}}\\ \end{array}\]

Error

Bits error versus x

Target

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

Derivation

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

    1. Initial program 20.0

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

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

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

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

      \[\leadsto \color{blue}{\left(\frac{\frac{2}{x}}{x \cdot x} + \frac{2}{{x}^{7}}\right) + \frac{2}{{x}^{5}}}\]
    7. Using strategy rm
    8. Applied div-inv0.4

      \[\leadsto \left(\color{blue}{\frac{2}{x} \cdot \frac{1}{x \cdot x}} + \frac{2}{{x}^{7}}\right) + \frac{2}{{x}^{5}}\]
    9. Applied fma-def0.4

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

    if -0.9934881645172994 < x < 129.39195686841717

    1. Initial program 0.0

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

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

      \[\leadsto \left(\frac{1}{x + 1} - \frac{2}{x}\right) + \color{blue}{\frac{1}{x \cdot x - 1 \cdot 1} \cdot \left(x + 1\right)}\]
    5. Using strategy rm
    6. Applied add-sqr-sqrt0.0

      \[\leadsto \left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x \cdot x - 1 \cdot 1} \cdot \color{blue}{\left(\sqrt{x + 1} \cdot \sqrt{x + 1}\right)}\]
    7. Applied associate-*r*0.0

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

    if 129.39195686841717 < x

    1. Initial program 20.1

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

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

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

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

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

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

Reproduce

herbie shell --seed 2019002 +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: 1.2m)Debug log

sample48.0ms

Algorithm
intervals

simplify32.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune4.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 7.5b

localize33.0ms

Local error

Found 4 expressions with local error:

1.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))

rewrite48.0ms

Algorithm
rewrite-expression-head
Counts
4 → 144
Calls

4 calls. Slowest were:

38.0ms
(+ (- (/ 1 (+ x 1)) (/ 2 x)) (/ 1 (- x 1)))
6.0ms
(- (/ 1 (+ x 1)) (/ 2 x))
1.0ms
(/ 1 (+ x 1))

series87.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

52.0ms
(+ (- (/ 1 (+ x 1)) (/ 2 x)) (/ 1 (- x 1)))
18.0ms
(- (/ 1 (+ x 1)) (/ 2 x))
11.0ms
(/ 1 (+ x 1))
7.0ms
(/ 1 (- x 1))

simplify11.4s

Counts
127 → 156
Calls

127 calls. Slowest were:

845.0ms
(fma (/ 1 (+ (pow x 3) (pow 1 3))) (+ (* x x) (- (* 1 1) (* x 1))) (- (* (sqrt (/ 2 x)) (sqrt (/ 2 x)))))
753.0ms
(+ (* (- (* 1 x) (* (+ x 1) 2)) (- x 1)) (* (* (+ x 1) x) 1))
639.0ms
(- (+ (* 2 x) (+ (* 2 (pow x 3)) (* 2 (/ 1 x)))))

prune1.3s

Pruning

3 alts after pruning (3 fresh and 0 done)

Merged error: 0.1b

localize33.0ms

Local error

Found 4 expressions with local error:

13.0b
(* (/ 1 (- (* x x) (* 1 1))) (+ x 1))
6.2b
(+ (- (/ 1 (+ x 1)) (/ 2 x)) (* (/ 1 (- (* x x) (* 1 1))) (+ x 1)))
0.4b
(/ 1 (- (* x x) (* 1 1)))
0.0b
(- (/ 1 (+ x 1)) (/ 2 x))

rewrite55.0ms

Algorithm
rewrite-expression-head
Counts
4 → 163
Calls

4 calls. Slowest were:

28.0ms
(+ (- (/ 1 (+ x 1)) (/ 2 x)) (* (/ 1 (- (* x x) (* 1 1))) (+ x 1)))
10.0ms
(* (/ 1 (- (* x x) (* 1 1))) (+ x 1))
10.0ms
(- (/ 1 (+ x 1)) (/ 2 x))

series122.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

77.0ms
(+ (- (/ 1 (+ x 1)) (/ 2 x)) (* (/ 1 (- (* x x) (* 1 1))) (+ x 1)))
20.0ms
(* (/ 1 (- (* x x) (* 1 1))) (+ x 1))
14.0ms
(/ 1 (- (* x x) (* 1 1)))
11.0ms
(- (/ 1 (+ x 1)) (/ 2 x))

simplify22.0s

Counts
162 → 175
Calls

162 calls. Slowest were:

1.7s
(* (/ 1 (- (* x x) (* 1 1))) (+ x 1))
822.0ms
(* (* (+ x 1) x) (* (- (* x x) (* 1 1)) (+ (* x x) (- (* 1 1) (* x 1)))))
784.0ms
(+ (* (- (* (/ 1 (+ x 1)) (/ 1 (+ x 1))) (* (/ 2 x) (/ 2 x))) (* (- (* x x) (* 1 1)) (- x 1))) (* (+ (/ 1 (+ x 1)) (/ 2 x)) (* 1 (- (* x x) (* 1 1)))))

prune1.2s

Pruning

2 alts after pruning (2 fresh and 0 done)

Merged error: 0.1b

localize11.0ms

Local error

Found 4 expressions with local error:

5.7b
(+ (- (/ 1 (+ x 1)) (/ 2 x)) (* (* (/ 1 (- (* x x) (* 1 1))) (sqrt (+ x 1))) (sqrt (+ x 1))))
5.1b
(* (* (/ 1 (- (* x x) (* 1 1))) (sqrt (+ x 1))) (sqrt (+ x 1)))
2.2b
(* (/ 1 (- (* x x) (* 1 1))) (sqrt (+ x 1)))
0.4b
(/ 1 (- (* x x) (* 1 1)))

rewrite61.0ms

Algorithm
rewrite-expression-head
Counts
4 → 191
Calls

4 calls. Slowest were:

34.0ms
(+ (- (/ 1 (+ x 1)) (/ 2 x)) (* (* (/ 1 (- (* x x) (* 1 1))) (sqrt (+ x 1))) (sqrt (+ x 1))))
15.0ms
(* (* (/ 1 (- (* x x) (* 1 1))) (sqrt (+ x 1))) (sqrt (+ x 1)))
6.0ms
(* (/ 1 (- (* x x) (* 1 1))) (sqrt (+ x 1)))

series114.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

63.0ms
(+ (- (/ 1 (+ x 1)) (/ 2 x)) (* (* (/ 1 (- (* x x) (* 1 1))) (sqrt (+ x 1))) (sqrt (+ x 1))))
26.0ms
(* (/ 1 (- (* x x) (* 1 1))) (sqrt (+ x 1)))
13.0ms
(/ 1 (- (* x x) (* 1 1)))
12.0ms
(* (* (/ 1 (- (* x x) (* 1 1))) (sqrt (+ x 1))) (sqrt (+ x 1)))

simplify30.4s

Counts
215 → 203
Calls

215 calls. Slowest were:

1.4s
(* (* (* (* (/ 1 (- (* x x) (* 1 1))) (sqrt (+ x 1))) (* (/ 1 (- (* x x) (* 1 1))) (sqrt (+ x 1)))) (* (/ 1 (- (* x x) (* 1 1))) (sqrt (+ x 1)))) (* (* (sqrt (+ x 1)) (sqrt (+ x 1))) (sqrt (+ x 1))))
548.0ms
(+ (* (- (* 1 x) (* (+ x 1) 2)) (* (sqrt (- x 1)) (sqrt (- x 1)))) (* (* (+ x 1) x) (* (* (/ 1 (- (* x x) (* 1 1))) (sqrt (- (* x x) (* 1 1)))) (sqrt (- (* x x) (* 1 1))))))
516.0ms
(* (exp (- (/ 1 (+ x 1)) (/ 2 x))) (exp (* (* (/ 1 (- (* x x) (* 1 1))) (sqrt (+ x 1))) (sqrt (+ x 1)))))

prune1.6s

Pruning

2 alts after pruning (1 fresh and 1 done)

Merged error: 0.1b

localize19.0ms

Local error

Found 4 expressions with local error:

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

rewrite11.0ms

Algorithm
rewrite-expression-head
Counts
4 → 77
Calls

4 calls. Slowest were:

7.0ms
(+ (/ (/ 2 x) (* x x)) (/ 2 (pow x 7)))
3.0ms
(/ (/ 2 x) (* x x))
0.0ms
(/ 2 (pow x 5))

series115.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

59.0ms
(+ (/ (/ 2 x) (* x x)) (/ 2 (pow x 7)))
21.0ms
(/ 2 (pow x 7))
21.0ms
(/ 2 (pow x 5))
14.0ms
(/ (/ 2 x) (* x x))

simplify659.0ms

Counts
41 → 89
Calls

41 calls. Slowest were:

370.0ms
(/ (* (* (/ 2 x) (/ 2 x)) (/ 2 x)) (* (* (* x x) (* x x)) (* x x)))
57.0ms
(+ (* 2 (/ 1 (pow x 7))) (* 2 (/ 1 (pow x 3))))
56.0ms
(+ (* 2 (/ 1 (pow x 7))) (* 2 (/ 1 (pow x 3))))

prune576.0ms

Pruning

6 alts after pruning (4 fresh and 2 done)

Merged error: 0.0b

regimes44.0ms

Accuracy

99.8% (0.0b remaining)

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

bsearch126.0ms

end0.0ms

sample1.8s

Algorithm
intervals