Average Error: 9.9 → 0.1
Time: 28.5s
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 -109.43620591770889 \lor \neg \left(x \le 108.90688060677309\right):\\ \;\;\;\;\frac{\frac{\frac{2}{x}}{x}}{x} + \left(\frac{2}{{x}^{7}} + \frac{2}{{x}^{5}}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{1}{1 + x} - \frac{-1}{-1 + x}\right) + \frac{-2}{x}\\ \end{array}\]

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 2 regimes
  2. if x < -109.43620591770889 or 108.90688060677309 < x

    1. Initial program 19.7

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

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

      \[\leadsto \left(\color{blue}{\frac{1}{x \cdot x - 1 \cdot 1} \cdot \left(x - 1\right)} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    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{2}{{x}^{7}} + \frac{2}{{x}^{5}}\right) + \frac{\frac{2}{x}}{x \cdot x}}\]
    7. Using strategy rm
    8. Applied associate-/r*0.1

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

    if -109.43620591770889 < x < 108.90688060677309

    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}{\color{blue}{\frac{x \cdot x - 1 \cdot 1}{x - 1}}} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    4. Applied associate-/r/0.0

      \[\leadsto \left(\color{blue}{\frac{1}{x \cdot x - 1 \cdot 1} \cdot \left(x - 1\right)} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity0.0

      \[\leadsto \left(\frac{1}{x \cdot x - 1 \cdot 1} \cdot \left(x - 1\right) - \frac{2}{x}\right) + \color{blue}{1 \cdot \frac{1}{x - 1}}\]
    7. Applied *-un-lft-identity0.0

      \[\leadsto \color{blue}{1 \cdot \left(\frac{1}{x \cdot x - 1 \cdot 1} \cdot \left(x - 1\right) - \frac{2}{x}\right)} + 1 \cdot \frac{1}{x - 1}\]
    8. Applied distribute-lft-out0.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -109.43620591770889 \lor \neg \left(x \le 108.90688060677309\right):\\ \;\;\;\;\frac{\frac{\frac{2}{x}}{x}}{x} + \left(\frac{2}{{x}^{7}} + \frac{2}{{x}^{5}}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{1}{1 + x} - \frac{-1}{-1 + x}\right) + \frac{-2}{x}\\ \end{array}\]

Reproduce

herbie shell --seed 2019008 
(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.5s)Debug log

sample51.0ms

Algorithm
intervals

simplify42.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune4.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 9.2b

localize28.0ms

Local error

Found 4 expressions with local error:

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

rewrite27.0ms

Algorithm
rewrite-expression-head
Counts
4 → 76
Calls

4 calls. Slowest were:

20.0ms
(+ (- (/ 1 (+ x 1)) (/ 2 x)) (/ 1 (- x 1)))
5.0ms
(- (/ 1 (+ x 1)) (/ 2 x))
1.0ms
(/ 1 (- x 1))

series97.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

60.0ms
(+ (- (/ 1 (+ x 1)) (/ 2 x)) (/ 1 (- x 1)))
16.0ms
(- (/ 1 (+ x 1)) (/ 2 x))
11.0ms
(/ 1 (+ x 1))
10.0ms
(/ 1 (- x 1))

simplify3.5s

Counts
48 → 88
Calls

48 calls. Slowest were:

488.0ms
(* (+ (/ 1 (+ x 1)) (/ 2 x)) (- x 1))
436.0ms
(- (+ (* 2 x) (+ (* 2 (pow x 3)) (* 2 (/ 1 x)))))
303.0ms
(+ (* (- (* 1 x) (* (+ x 1) 2)) (- x 1)) (* (* (+ x 1) x) 1))

prune717.0ms

Pruning

3 alts after pruning (3 fresh and 0 done)

Merged error: 0.0b

localize32.0ms

Local error

Found 4 expressions with local error:

13.7b
(* (/ 1 (- (* x x) (* 1 1))) (- x 1))
6.3b
(+ (- (* (/ 1 (- (* x x) (* 1 1))) (- x 1)) (/ 2 x)) (/ 1 (- x 1)))
0.1b
(/ 1 (- (* x x) (* 1 1)))
0.0b
(/ 1 (- x 1))

rewrite43.0ms

Algorithm
rewrite-expression-head
Counts
4 → 95
Calls

4 calls. Slowest were:

31.0ms
(+ (- (* (/ 1 (- (* x x) (* 1 1))) (- x 1)) (/ 2 x)) (/ 1 (- x 1)))
5.0ms
(* (/ 1 (- (* x x) (* 1 1))) (- x 1))
4.0ms
(/ 1 (- (* x x) (* 1 1)))

series158.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

104.0ms
(+ (- (* (/ 1 (- (* x x) (* 1 1))) (- x 1)) (/ 2 x)) (/ 1 (- x 1)))
21.0ms
(* (/ 1 (- (* x x) (* 1 1))) (- x 1))
21.0ms
(/ 1 (- (* x x) (* 1 1)))
11.0ms
(/ 1 (- x 1))

simplify12.4s

Counts
72 → 107
Calls

72 calls. Slowest were:

1.1s
(* (* (* (- (* x x) (* 1 1)) (+ (* x x) (+ (* 1 1) (* x 1)))) x) (- x 1))
805.0ms
(* (/ 1 (- (* x x) (* 1 1))) (- x 1))
743.0ms
(+ (* (- (* (* (/ 1 (- (* x x) (* 1 1))) (- (pow x 3) (pow 1 3))) x) (* (+ (* x x) (+ (* 1 1) (* x 1))) 2)) (- x 1)) (* (* (+ (* x x) (+ (* 1 1) (* x 1))) x) 1))

prune962.0ms

Pruning

2 alts after pruning (2 fresh and 0 done)

Merged error: 0.0b

localize27.0ms

Local error

Found 4 expressions with local error:

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

rewrite54.0ms

Algorithm
rewrite-expression-head
Counts
4 → 70
Calls

4 calls. Slowest were:

44.0ms
(+ (- (/ 1 (+ x 1)) (/ -1 (+ x -1))) (/ -2 x))
8.0ms
(- (/ 1 (+ x 1)) (/ -1 (+ x -1)))
1.0ms
(/ 1 (+ x 1))

series98.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

58.0ms
(+ (- (/ 1 (+ x 1)) (/ -1 (+ x -1))) (/ -2 x))
22.0ms
(- (/ 1 (+ x 1)) (/ -1 (+ x -1)))
12.0ms
(/ -1 (+ x -1))
6.0ms
(/ 1 (+ x 1))

simplify4.2s

Counts
44 → 82
Calls

44 calls. Slowest were:

784.0ms
(- (+ (* 2 x) (+ (* 2 (pow x 3)) (* 2 (pow x 5)))))
474.0ms
(- (+ (* 2 x) (+ (* 2 (pow x 3)) (* 2 (/ 1 x)))))
374.0ms
(* (* (+ x 1) (+ x -1)) x)

prune626.0ms

Pruning

2 alts after pruning (1 fresh and 1 done)

Merged error: 0.0b

localize32.0ms

Local error

Found 4 expressions with local error:

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

rewrite17.0ms

Algorithm
rewrite-expression-head
Counts
4 → 62
Calls

4 calls. Slowest were:

9.0ms
(+ (/ 2 (pow x 7)) (/ 2 (pow x 5)))
5.0ms
(/ (/ 2 x) (* x x))
1.0ms
(/ 2 (pow x 5))

series176.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

74.0ms
(+ (/ 2 (pow x 7)) (/ 2 (pow x 5)))
40.0ms
(/ 2 (pow x 7))
31.0ms
(/ 2 (pow x 5))
30.0ms
(/ (/ 2 x) (* x x))

simplify783.0ms

Counts
35 → 74
Calls

35 calls. Slowest were:

535.0ms
(/ (* (* (/ 2 x) (/ 2 x)) (/ 2 x)) (* (* (* x x) (* x x)) (* x x)))
45.0ms
(- (log (/ 2 x)) (log (* x x)))
39.0ms
(+ (* 2 (/ 1 (pow x 7))) (* 2 (/ 1 (pow x 5))))

prune680.0ms

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 0.0b

regimes58.0ms

Accuracy

99.7% (0.0b remaining)

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

bsearch182.0ms

end0.0ms

sample2.5s

Algorithm
intervals