Average Error: 10.1 → 0.1
Time: 32.9s
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 -1.0146621172518915:\\ \;\;\;\;\frac{\frac{2}{x}}{x \cdot x} + \left(\frac{2}{{x}^{7}} + \frac{2}{{x}^{5}}\right)\\ \mathbf{elif}\;x \le 101.22050069893446:\\ \;\;\;\;\frac{1}{x - 1} + \left(\frac{\frac{1}{\sqrt{1 + x}}}{\sqrt{1 + x}} - \frac{2}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{2}{x}}{x}}{x} + \left(\frac{2}{{x}^{7}} + \frac{2}{{x}^{5}}\right)\\ \end{array}\]

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

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

    1. Initial program 19.7

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

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

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

      \[\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.3

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

    if -1.0146621172518915 < x < 101.22050069893446

    1. Initial program 0.0

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

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

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

    if 101.22050069893446 < x

    1. Initial program 20.4

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

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

      \[\leadsto \left(\color{blue}{\frac{\frac{1}{\sqrt{x + 1}}}{\sqrt{x + 1}}} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    5. 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)}\]
    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}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.1

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

Reproduce

herbie shell --seed 1042149663 
(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: 31.8s)Debug log

sample140.0ms

Algorithm
intervals
Results
256×(pre true 80)
130×(body real 80)
60×(body real 640)
32×(body real 320)
24×(body real 1280)
10×(body real 160)

simplify72.0ms

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

prune10.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 9.9b

localize63.0ms

Local error

Found 4 expressions with local error:

2.4b
(+ (- (/ 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))

rewrite63.0ms

Algorithm
rewrite-expression-head
Rules
20×*-un-lft-identity
11×add-log-exp
div-inv
add-sqr-sqrt
distribute-lft-out--
distribute-lft-out
add-cube-cbrt
add-exp-log
associate-/r*
pow1
associate-/r/
add-cbrt-cube
flip--
frac-add
flip3--
inv-pow
pow-flip
flip-+
frac-sub
diff-log
flip3-+
frac-2neg
sub-neg
sum-log
clear-num
associate-+l+
rec-exp
difference-of-squares
associate-+l-
+-commutative
Counts
4 → 76
Calls
4 calls:
Slowest
47.0ms
(+ (- (/ 1 (+ x 1)) (/ 2 x)) (/ 1 (- x 1)))
11.0ms
(- (/ 1 (+ x 1)) (/ 2 x))
2.0ms
(/ 1 (- x 1))
2.0ms
(/ 1 (+ x 1))

series491.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
381.0ms
(/ 1 (+ x 1))
73.0ms
(+ (- (/ 1 (+ x 1)) (/ 2 x)) (/ 1 (- x 1)))
24.0ms
(- (/ 1 (+ x 1)) (/ 2 x))
13.0ms
(/ 1 (- x 1))

simplify4.9s

Counts
48 → 88
Calls
48 calls:
Slowest
622.0ms
(* (+ (/ 1 (+ x 1)) (/ 2 x)) (- x 1))
577.0ms
(- (+ (* 2 x) (+ (* 2 (pow x 3)) (* 2 (/ 1 x)))))
481.0ms
(+ (* (- (* 1 x) (* (+ x 1) 2)) (- x 1)) (* (* (+ x 1) x) 1))
385.0ms
(* (* (+ x 1) x) (- x 1))
363.0ms
(* (+ (* (/ 1 (+ x 1)) (/ 1 (+ x 1))) (+ (* (/ 2 x) (/ 2 x)) (* (/ 1 (+ x 1)) (/ 2 x)))) (- x 1))

prune1.1s

Pruning

3 alts after pruning (3 fresh and 0 done)

Merged error: 0.1b

localize35.0ms

Local error

Found 4 expressions with local error:

8.2b
(+ (- (/ (/ 1 (sqrt (+ x 1))) (sqrt (+ x 1))) (/ 2 x)) (/ 1 (- x 1)))
0.1b
(/ (/ 1 (sqrt (+ x 1))) (sqrt (+ x 1)))
0.1b
(/ 1 (sqrt (+ x 1)))
0.0b
(- (/ (/ 1 (sqrt (+ x 1))) (sqrt (+ x 1))) (/ 2 x))

rewrite174.0ms

Algorithm
rewrite-expression-head
Rules
38×times-frac
37×*-un-lft-identity
36×add-sqr-sqrt
27×add-cube-cbrt
25×sqrt-prod
18×associate-/r/
18×sqrt-div
12×div-inv
12×associate-/r*
11×add-log-exp
10×flip-+
10×flip3-+
add-exp-log
pow1
associate-/l*
add-cbrt-cube
difference-of-squares
distribute-lft-out
pow-flip
pow-div
distribute-lft-out--
frac-add
pow1/2
inv-pow
flip--
frac-sub
div-exp
diff-log
flip3--
frac-2neg
sub-neg
sum-log
clear-num
associate-+l+
rec-exp
associate-/l/
associate-+l-
+-commutative
cbrt-undiv
Counts
4 → 129
Calls
4 calls:
Slowest
125.0ms
(+ (- (/ (/ 1 (sqrt (+ x 1))) (sqrt (+ x 1))) (/ 2 x)) (/ 1 (- x 1)))
32.0ms
(- (/ (/ 1 (sqrt (+ x 1))) (sqrt (+ x 1))) (/ 2 x))
10.0ms
(/ (/ 1 (sqrt (+ x 1))) (sqrt (+ x 1)))
3.0ms
(/ 1 (sqrt (+ x 1)))

series136.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
76.0ms
(+ (- (/ (/ 1 (sqrt (+ x 1))) (sqrt (+ x 1))) (/ 2 x)) (/ 1 (- x 1)))
25.0ms
(/ 1 (sqrt (+ x 1)))
22.0ms
(- (/ (/ 1 (sqrt (+ x 1))) (sqrt (+ x 1))) (/ 2 x))
13.0ms
(/ (/ 1 (sqrt (+ x 1))) (sqrt (+ x 1)))

simplify6.9s

Counts
142 → 141
Calls
142 calls:
Slowest
646.0ms
(* (+ (/ (/ 1 (sqrt (+ x 1))) (sqrt (+ x 1))) (/ 2 x)) (- x 1))
575.0ms
(- (+ (* 2 x) (+ (* 2 (pow x 3)) (* 2 (/ 1 x)))))
543.0ms
(/ (* (* (/ 1 (sqrt (+ x 1))) (/ 1 (sqrt (+ x 1)))) (/ 1 (sqrt (+ x 1)))) (* (* (sqrt (+ x 1)) (sqrt (+ x 1))) (sqrt (+ x 1))))
516.0ms
(+ (* (- (* (/ 1 (sqrt (+ x 1))) x) (* (sqrt (+ x 1)) 2)) (- x 1)) (* (* (sqrt (+ x 1)) x) 1))
432.0ms
(+ (* (- (* (/ (/ 1 (sqrt (+ x 1))) (sqrt (+ x 1))) (/ (/ 1 (sqrt (+ x 1))) (sqrt (+ x 1)))) (* (/ 2 x) (/ 2 x))) (- x 1)) (* (+ (/ (/ 1 (sqrt (+ x 1))) (sqrt (+ x 1))) (/ 2 x)) 1))

prune2.1s

Pruning

3 alts after pruning (2 fresh and 1 done)

Merged error: 0.1b

localize43.0ms

Local error

Found 4 expressions with local error:

15.5b
(/ (+ (+ (* x -2) -2) x) (* (+ x 1) x))
1.7b
(+ (/ (+ (+ (* x -2) -2) x) (* (+ x 1) x)) (/ 1 (- x 1)))
0.0b
(* (+ x 1) x)
0.0b
(+ (+ (* x -2) -2) x)

rewrite155.0ms

Algorithm
rewrite-expression-head
Rules
10×*-un-lft-identity
add-cube-cbrt
add-sqr-sqrt
add-log-exp
add-exp-log
add-cbrt-cube
flip-+
flip3-+
associate-*l/
pow1
associate-/l*
associate-*l*
times-frac
associate-/l/
distribute-lft-out
div-inv
associate-/r/
+-commutative
*-commutative
frac-add
div-exp
frac-2neg
sum-log
associate-/r*
clear-num
associate-+l+
cbrt-undiv
Counts
4 → 61
Calls
4 calls:
Slowest
88.0ms
(+ (/ (+ (+ (* x -2) -2) x) (* (+ x 1) x)) (/ 1 (- x 1)))
44.0ms
(/ (+ (+ (* x -2) -2) x) (* (+ x 1) x))
15.0ms
(+ (+ (* x -2) -2) x)
5.0ms
(* (+ x 1) x)

series183.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
92.0ms
(+ (/ (+ (+ (* x -2) -2) x) (* (+ x 1) x)) (/ 1 (- x 1)))
37.0ms
(* (+ x 1) x)
32.0ms
(/ (+ (+ (* x -2) -2) x) (* (+ x 1) x))
22.0ms
(+ (+ (* x -2) -2) x)

simplify4.7s

Counts
36 → 73
Calls
36 calls:
Slowest
602.0ms
(+ (pow (+ (* x -2) -2) 3) (pow x 3))
579.0ms
(- (+ (* 2 x) (+ (* 2 (pow x 3)) (* 2 (/ 1 x)))))
564.0ms
(- (* (+ (* x -2) -2) (+ (* x -2) -2)) (* x x))
383.0ms
(* (* (+ x 1) x) (- x 1))
380.0ms
(/ (* (* (+ (+ (* x -2) -2) x) (+ (+ (* x -2) -2) x)) (+ (+ (* x -2) -2) x)) (* (* (* (+ x 1) x) (* (+ x 1) x)) (* (+ x 1) x)))

prune901.0ms

Pruning

3 alts after pruning (1 fresh and 2 done)

Merged error: 0.1b

localize61.0ms

Local error

Found 4 expressions with local error:

0.3b
(/ 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))) (/ (/ 2 x) (* x x)))

rewrite61.0ms

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

series176.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
52.0ms
(+ (+ (/ 2 (pow x 7)) (/ 2 (pow x 5))) (/ (/ 2 x) (* x x)))
48.0ms
(/ 2 (pow x 7))
46.0ms
(/ 2 (pow x 5))
31.0ms
(/ (/ 2 x) (* x x))

simplify3.2s

Counts
41 → 78
Calls
41 calls:
Slowest
759.0ms
(/ (* (* (/ 2 x) (/ 2 x)) (/ 2 x)) (* (* (* x x) (* x x)) (* x x)))
455.0ms
(+ (* (+ (* 2 (pow x 5)) (* (pow x 7) 2)) (* x x)) (* (* (pow x 7) (pow x 5)) (/ 2 x)))
355.0ms
(+ (* (+ (pow (/ 2 (pow x 7)) 3) (pow (/ 2 (pow x 5)) 3)) (* x x)) (* (+ (* (/ 2 (pow x 7)) (/ 2 (pow x 7))) (- (* (/ 2 (pow x 5)) (/ 2 (pow x 5))) (* (/ 2 (pow x 7)) (/ 2 (pow x 5))))) (/ 2 x)))
289.0ms
(+ (* (- (* (/ 2 (pow x 7)) (/ 2 (pow x 7))) (* (/ 2 (pow x 5)) (/ 2 (pow x 5)))) (* x x)) (* (- (/ 2 (pow x 7)) (/ 2 (pow x 5))) (/ 2 x)))
222.0ms
(+ (* 2 (/ 1 (pow x 7))) (+ (* 2 (/ 1 (pow x 3))) (* 2 (/ 1 (pow x 5)))))

prune1.2s

Pruning

6 alts after pruning (3 fresh and 3 done)

Merged error: 0b

regimes90.0ms

Accuracy

99.6% (0.1b remaining)

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

bsearch278.0ms

end0.0ms

sample4.4s

Algorithm
intervals
Results
8004×(pre true 80)
4107×(body real 80)
1933×(body real 640)
909×(body real 320)
575×(body real 1280)
480×(body real 160)