Average Error: 29.4 → 0.2
Time: 2.5m
Precision: 64
Internal Precision: 128
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -16001.301308519196 \lor \neg \left(x \le 1.0187194309816852\right):\\ \;\;\;\;(\left(\frac{-1}{x \cdot x}\right) \cdot \left(\frac{3}{x}\right) + \left(\frac{-1}{x \cdot x} - \frac{3}{x}\right))_*\\ \mathbf{else}:\\ \;\;\;\;e^{\log \left((\left(\frac{-1}{-1 + x}\right) \cdot \left(1 + x\right) + \left(\frac{x}{1 + x}\right))_*\right)}\\ \end{array}\]

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -16001.301308519196 or 1.0187194309816852 < x

    1. Initial program 58.7

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

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

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

    if -16001.301308519196 < x < 1.0187194309816852

    1. Initial program 0.1

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
    2. Using strategy rm
    3. Applied flip--0.1

      \[\leadsto \frac{x}{x + 1} - \frac{x + 1}{\color{blue}{\frac{x \cdot x - 1 \cdot 1}{x + 1}}}\]
    4. Applied associate-/r/0.1

      \[\leadsto \frac{x}{x + 1} - \color{blue}{\frac{x + 1}{x \cdot x - 1 \cdot 1} \cdot \left(x + 1\right)}\]
    5. Applied add-cube-cbrt0.1

      \[\leadsto \color{blue}{\left(\sqrt[3]{\frac{x}{x + 1}} \cdot \sqrt[3]{\frac{x}{x + 1}}\right) \cdot \sqrt[3]{\frac{x}{x + 1}}} - \frac{x + 1}{x \cdot x - 1 \cdot 1} \cdot \left(x + 1\right)\]
    6. Applied prod-diff0.1

      \[\leadsto \color{blue}{(\left(\sqrt[3]{\frac{x}{x + 1}} \cdot \sqrt[3]{\frac{x}{x + 1}}\right) \cdot \left(\sqrt[3]{\frac{x}{x + 1}}\right) + \left(-\left(x + 1\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\right))_* + (\left(-\left(x + 1\right)\right) \cdot \left(\frac{x + 1}{x \cdot x - 1 \cdot 1}\right) + \left(\left(x + 1\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\right))_*}\]
    7. Simplified0.1

      \[\leadsto \color{blue}{(\left(\frac{-1}{-1 + x}\right) \cdot \left(1 + x\right) + \left(\frac{x}{1 + x}\right))_*} + (\left(-\left(x + 1\right)\right) \cdot \left(\frac{x + 1}{x \cdot x - 1 \cdot 1}\right) + \left(\left(x + 1\right) \cdot \frac{x + 1}{x \cdot x - 1 \cdot 1}\right))_*\]
    8. Simplified0.1

      \[\leadsto (\left(\frac{-1}{-1 + x}\right) \cdot \left(1 + x\right) + \left(\frac{x}{1 + x}\right))_* + \color{blue}{0}\]
    9. Using strategy rm
    10. Applied add-exp-log0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -16001.301308519196 \lor \neg \left(x \le 1.0187194309816852\right):\\ \;\;\;\;(\left(\frac{-1}{x \cdot x}\right) \cdot \left(\frac{3}{x}\right) + \left(\frac{-1}{x \cdot x} - \frac{3}{x}\right))_*\\ \mathbf{else}:\\ \;\;\;\;e^{\log \left((\left(\frac{-1}{-1 + x}\right) \cdot \left(1 + x\right) + \left(\frac{x}{1 + x}\right))_*\right)}\\ \end{array}\]

Reproduce

herbie shell --seed 2019016 +o rules:numerics
(FPCore (x)
  :name "Asymptote C"
  (- (/ x (+ x 1)) (/ (+ x 1) (- x 1))))

Details

Time bar (total: 2.4m)Debug log

sample54.0ms

Algorithm
intervals
Results
256×(pre true 80)
131×(body real 80)
56×(body real 1280)
39×(body real 640)
16×(body real 320)
14×(body real 160)

simplify23.0ms

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

prune4.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 29.2b

localize20.0ms

Local error

Found 3 expressions with local error:

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

rewrite30.0ms

Algorithm
rewrite-expression-head
Rules
90×prod-diff
75×add-sqr-sqrt
72×*-un-lft-identity
70×add-cube-cbrt
64×times-frac
48×associate-/r/
24×div-inv
18×flip-+
18×flip3-+
flip--
flip3--
fma-neg
associate-/r*
add-log-exp
add-exp-log
add-cbrt-cube
associate-/l*
log1p-expm1-u
pow1
expm1-log1p-u
associate-/l/
difference-of-squares
frac-2neg
clear-num
distribute-lft-out--
frac-sub
div-exp
diff-log
sub-neg
cbrt-undiv
Counts
3 → 164
Calls
3 calls:
Slowest
16.0ms
(- (/ x (+ x 1)) (/ (+ x 1) (- x 1)))
7.0ms
(/ (+ x 1) (- x 1))
1.0ms
(/ x (+ x 1))

series67.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
43.0ms
(- (/ x (+ x 1)) (/ (+ x 1) (- x 1)))
14.0ms
(/ x (+ x 1))
10.0ms
(/ (+ x 1) (- x 1))

simplify42.5s

Counts
235 → 173
Calls
235 calls:
Slowest
1.1s
(fma (/ x (- (* x x) (* 1 1))) (- x 1) (- (* (/ 1 (- x 1)) (+ x 1))))
826.0ms
(fma x (/ 1 (+ x 1)) (- (* (+ x 1) (/ (+ x 1) (- (* x x) (* 1 1))))))
775.0ms
(fma 1 (/ x (+ x 1)) (- (* (+ x 1) (/ (+ x 1) (- (* x x) (* 1 1))))))
763.0ms
(fma (/ x (- (* x x) (* 1 1))) (- x 1) (- (* (sqrt (/ (+ x 1) (- x 1))) (sqrt (/ (+ x 1) (- x 1))))))
728.0ms
(fma (/ x (- (* x x) (* 1 1))) (- x 1) (- (* (cbrt (/ (+ x 1) (- x 1))) (* (cbrt (/ (+ x 1) (- x 1))) (cbrt (/ (+ x 1) (- x 1)))))))

prune1.3s

Pruning

3 alts after pruning (3 fresh and 0 done)

Merged error: 0.0b

localize6.0ms

Local error

Found 4 expressions with local error:

3.5b
(- (/ x (+ x 1)) (/ (+ x 1) (- x 1)))
3.5b
(- (/ x (+ x 1)) (/ (+ x 1) (- x 1)))
0.0b
(* (sqrt (- (/ x (+ x 1)) (/ (+ x 1) (- x 1)))) (sqrt (- (/ x (+ x 1)) (/ (+ x 1) (- x 1)))))
0.0b
(sqrt (- (/ x (+ x 1)) (/ (+ x 1) (- x 1))))

rewrite74.0ms

Algorithm
rewrite-expression-head
Rules
180×prod-diff
151×add-sqr-sqrt
135×*-un-lft-identity
125×add-cube-cbrt
113×times-frac
88×associate-/r/
44×div-inv
32×flip-+
32×flip3-+
27×sqrt-div
23×flip--
23×flip3--
18×sqrt-prod
12×fma-neg
11×frac-sub
10×difference-of-squares
associate-*l*
associate-*r*
pow1
frac-times
add-log-exp
add-exp-log
add-cbrt-cube
distribute-lft-out--
pow1/2
log1p-expm1-u
expm1-log1p-u
associate-*r/
associate-*l/
pow-prod-up
pow-prod-down
diff-log
sub-neg
cbrt-unprod
*-commutative
prod-exp
sqrt-unprod
pow-plus
rem-square-sqrt
rem-sqrt-square
pow2
Counts
4 → 301
Calls
4 calls:
Slowest
28.0ms
(* (sqrt (- (/ x (+ x 1)) (/ (+ x 1) (- x 1)))) (sqrt (- (/ x (+ x 1)) (/ (+ x 1) (- x 1)))))
17.0ms
(- (/ x (+ x 1)) (/ (+ x 1) (- x 1)))
12.0ms
(sqrt (- (/ x (+ x 1)) (/ (+ x 1) (- x 1))))
9.0ms
(- (/ x (+ x 1)) (/ (+ x 1) (- x 1)))

series161.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
50.0ms
(sqrt (- (/ x (+ x 1)) (/ (+ x 1) (- x 1))))
48.0ms
(- (/ x (+ x 1)) (/ (+ x 1) (- x 1)))
33.0ms
(* (sqrt (- (/ x (+ x 1)) (/ (+ x 1) (- x 1)))) (sqrt (- (/ x (+ x 1)) (/ (+ x 1) (- x 1)))))
30.0ms
(- (/ x (+ x 1)) (/ (+ x 1) (- x 1)))

simplify1.5m

Counts
459 → 313
Calls
459 calls:
Slowest
1.0s
(fma (/ x (- (* x x) (* 1 1))) (- x 1) (- (* (/ 1 (- x 1)) (+ x 1))))
960.0ms
(fma (/ x (- (* x x) (* 1 1))) (- x 1) (- (* (/ 1 (- x 1)) (+ x 1))))
822.0ms
(fma (/ x (- (* x x) (* 1 1))) (- x 1) (- (* (cbrt (/ (+ x 1) (- x 1))) (* (cbrt (/ (+ x 1) (- x 1))) (cbrt (/ (+ x 1) (- x 1)))))))
792.0ms
(fma (- (+ (* x x) (+ (* 1 1) (* x 1)))) (/ (+ x 1) (- (pow x 3) (pow 1 3))) (* (+ (* x x) (+ (* 1 1) (* x 1))) (/ (+ x 1) (- (pow x 3) (pow 1 3)))))
742.0ms
(fma (sqrt (/ x (+ x 1))) (sqrt (/ x (+ x 1))) (- (* (+ x 1) (/ (+ x 1) (- (* x x) (* 1 1))))))

prune2.8s

Pruning

3 alts after pruning (2 fresh and 1 done)

Merged error: 0.0b

localize21.0ms

Local error

Found 3 expressions with local error:

29.7b
(fma (/ -1 (+ -1 x)) (+ 1 x) (/ x (+ 1 x)))
0.0b
(/ -1 (+ -1 x))
0.0b
(/ x (+ 1 x))

rewrite2.0ms

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

series48.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
28.0ms
(fma (/ -1 (+ -1 x)) (+ 1 x) (/ x (+ 1 x)))
10.0ms
(/ x (+ 1 x))
10.0ms
(/ -1 (+ -1 x))

simplify1.4s

Counts
19 → 53
Calls
19 calls:
Slowest
494.0ms
(- (+ (* 3 (/ 1 (pow x 3))) (+ (/ 1 (pow x 2)) (* 3 (/ 1 x)))))
486.0ms
(- (+ (* 3 (/ 1 (pow x 3))) (+ (/ 1 (pow x 2)) (* 3 (/ 1 x)))))
75.0ms
(+ (* 1 1) (- (* x x) (* 1 x)))
66.0ms
(- (+ (/ 1 (pow x 3)) (+ (/ 1 (pow x 2)) (/ 1 x))))
61.0ms
(- (+ x (pow x 3)) (pow x 2))

prune411.0ms

Pruning

3 alts after pruning (2 fresh and 1 done)

Merged error: 0.0b

localize11.0ms

Local error

Found 4 expressions with local error:

29.7b
(fma (/ -1 (+ -1 x)) (+ 1 x) (/ x (+ 1 x)))
3.7b
(log (fma (/ -1 (+ -1 x)) (+ 1 x) (/ x (+ 1 x))))
0.4b
(exp (log (fma (/ -1 (+ -1 x)) (+ 1 x) (/ x (+ 1 x)))))
0.0b
(/ -1 (+ -1 x))

rewrite5.0ms

Algorithm
rewrite-expression-head
Rules
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
log-prod
pow1
add-exp-log
add-log-exp
log1p-expm1-u
add-cbrt-cube
exp-prod
expm1-log1p-u
exp-sum
associate-/r*
log-pow
associate-/r/
rem-exp-log
div-inv
fma-udef
flip-+
rem-log-exp
flip3-+
frac-2neg
clear-num
Counts
4 → 58
Calls
4 calls:
Slowest
2.0ms
(exp (log (fma (/ -1 (+ -1 x)) (+ 1 x) (/ x (+ 1 x)))))
1.0ms
(log (fma (/ -1 (+ -1 x)) (+ 1 x) (/ x (+ 1 x))))
1.0ms
(/ -1 (+ -1 x))
0.0ms
(fma (/ -1 (+ -1 x)) (+ 1 x) (/ x (+ 1 x)))

series155.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
68.0ms
(log (fma (/ -1 (+ -1 x)) (+ 1 x) (/ x (+ 1 x))))
42.0ms
(exp (log (fma (/ -1 (+ -1 x)) (+ 1 x) (/ x (+ 1 x)))))
33.0ms
(fma (/ -1 (+ -1 x)) (+ 1 x) (/ x (+ 1 x)))
11.0ms
(/ -1 (+ -1 x))

simplify4.7s

Counts
29 → 70
Calls
29 calls:
Slowest
961.0ms
(- (+ (* 3 (/ 1 (pow x 3))) (+ (/ 1 (pow x 2)) (* 3 (/ 1 x)))))
564.0ms
(+ (log -3) (+ (log (/ 1 x)) (+ (* 17/18 (/ 1 (pow x 2))) (* 1/3 (/ 1 x)))))
560.0ms
(- (+ (* 3 (/ 1 (pow x 3))) (+ (/ 1 (pow x 2)) (* 3 (/ 1 x)))))
537.0ms
(- (+ (* 3 (/ 1 (pow x 3))) (+ (/ 1 (pow x 2)) (* 3 (/ 1 x)))))
517.0ms
(- (+ (* 3 (/ 1 (pow x 3))) (+ (/ 1 (pow x 2)) (* 3 (/ 1 x)))))

prune784.0ms

Pruning

3 alts after pruning (1 fresh and 2 done)

Merged error: 0.0b

regimes93.0ms

Accuracy

100% (0.0b remaining)

Error of 0.2b against oracle of 0.2b and baseline of 30.0b

bsearch126.0ms

end0.0ms

sample2.3s

Algorithm
intervals
Results
8000×(pre true 80)
4096×(body real 80)
1767×(body real 1280)
1213×(body real 640)
610×(body real 320)
314×(body real 160)