Average Error: 29.0 → 0.1
Time: 1.8m
Precision: 64
Internal Precision: 128
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -15536.005790753223 \lor \neg \left(x \le 9720.782418787607\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}:\\ \;\;\;\;(\left(\frac{x}{(x \cdot \left(x \cdot x\right) + 1)_*}\right) \cdot \left(\left(1 - x\right) + x \cdot x\right) + \left(-\log \left(e^{\frac{1 + x}{x - 1}}\right)\right))_*\\ \end{array}\]

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -15536.005790753223 or 9720.782418787607 < x

    1. Initial program 59.1

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
    2. Using strategy rm
    3. Applied add-log-exp59.1

      \[\leadsto \frac{x}{x + 1} - \color{blue}{\log \left(e^{\frac{x + 1}{x - 1}}\right)}\]
    4. Taylor expanded around -inf 0.3

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

      \[\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 -15536.005790753223 < x < 9720.782418787607

    1. Initial program 0.1

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
    2. Using strategy rm
    3. Applied add-log-exp0.1

      \[\leadsto \frac{x}{x + 1} - \color{blue}{\log \left(e^{\frac{x + 1}{x - 1}}\right)}\]
    4. Using strategy rm
    5. Applied flip3-+0.1

      \[\leadsto \frac{x}{\color{blue}{\frac{{x}^{3} + {1}^{3}}{x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)}}} - \log \left(e^{\frac{x + 1}{x - 1}}\right)\]
    6. Applied associate-/r/0.1

      \[\leadsto \color{blue}{\frac{x}{{x}^{3} + {1}^{3}} \cdot \left(x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)\right)} - \log \left(e^{\frac{x + 1}{x - 1}}\right)\]
    7. Applied fma-neg0.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -15536.005790753223 \lor \neg \left(x \le 9720.782418787607\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}:\\ \;\;\;\;(\left(\frac{x}{(x \cdot \left(x \cdot x\right) + 1)_*}\right) \cdot \left(\left(1 - x\right) + x \cdot x\right) + \left(-\log \left(e^{\frac{1 + x}{x - 1}}\right)\right))_*\\ \end{array}\]

Reproduce

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

Details

Time bar (total: 1.8m)Debug log

sample46.0ms

Algorithm
intervals
Results
15.0ms51×body1280valid
9.0ms134×body80valid
7.0ms31×body640valid
5.0ms26×body320valid
2.0ms14×body160valid

simplify28.0ms

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

prune4.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 28.8b

localize13.0ms

Local error

Found 3 expressions with local error:

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

rewrite33.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
21.0ms
(- (/ x (+ x 1)) (/ (+ x 1) (- x 1)))
5.0ms
(/ (+ x 1) (- x 1))
1.0ms
(/ x (+ x 1))

series64.0ms

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

simplify41.0s

Counts
235 → 173
Calls
235 calls:
Slowest
885.0ms
(fma (/ x (- (* x x) (* 1 1))) (- x 1) (- (* (/ 1 (- x 1)) (+ x 1))))
734.0ms
(fma (/ x (- (* x x) (* 1 1))) (- x 1) (- (* (sqrt (/ (+ x 1) (- x 1))) (sqrt (/ (+ x 1) (- x 1))))))
734.0ms
(fma x (/ 1 (+ x 1)) (- (* (+ x 1) (/ (+ x 1) (- (* x x) (* 1 1))))))
734.0ms
(fma (/ x (- (* x x) (* 1 1))) (- x 1) (- (* (cbrt (/ (+ x 1) (- x 1))) (* (cbrt (/ (+ x 1) (- x 1))) (cbrt (/ (+ x 1) (- x 1)))))))
710.0ms
(fma (sqrt (/ x (+ x 1))) (sqrt (/ x (+ x 1))) (- (* (+ x 1) (/ (+ x 1) (- (* x x) (* 1 1))))))

prune1.7s

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0.0b

localize18.0ms

Local error

Found 4 expressions with local error:

4.1b
(- (/ x (+ x 1)) (log (exp (/ (+ x 1) (- x 1)))))
0.0b
(log (exp (/ (+ x 1) (- x 1))))
0.0b
(/ (+ x 1) (- x 1))
0.0b
(exp (/ (+ x 1) (- x 1)))

rewrite57.0ms

Algorithm
rewrite-expression-head
Rules
120×exp-prod
114×prod-diff
113×log-pow
99×*-un-lft-identity
98×add-sqr-sqrt
96×add-cube-cbrt
81×times-frac
58×associate-/r/
29×div-inv
21×flip-+
21×flip3-+
12×pow1
10×flip--
10×flip3--
add-log-exp
add-exp-log
fma-neg
add-cbrt-cube
log-prod
log1p-expm1-u
expm1-log1p-u
associate--r+
associate-/l*
associate-/r*
associate-/l/
distribute-lft-out--
rem-exp-log
difference-of-squares
rem-log-exp
div-exp
diff-log
frac-2neg
sub-neg
clear-num
cbrt-undiv
Counts
4 → 227
Calls
4 calls:
Slowest
28.0ms
(- (/ x (+ x 1)) (log (exp (/ (+ x 1) (- x 1)))))
8.0ms
(log (exp (/ (+ x 1) (- x 1))))
6.0ms
(exp (/ (+ x 1) (- x 1)))
6.0ms
(/ (+ x 1) (- x 1))

series119.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
55.0ms
(- (/ x (+ x 1)) (log (exp (/ (+ x 1) (- x 1)))))
33.0ms
(exp (/ (+ x 1) (- x 1)))
16.0ms
(log (exp (/ (+ x 1) (- x 1))))
15.0ms
(/ (+ x 1) (- x 1))

simplify52.8s

Counts
316 → 239
Calls
316 calls:
Slowest
1.0s
(fma (- (log (exp (+ x 1)))) (/ 1 (- x 1)) (* (log (exp (+ x 1))) (/ 1 (- x 1))))
983.0ms
(fma (- (log (exp (+ x 1)))) (/ 1 (- x 1)) (* (log (exp (+ x 1))) (/ 1 (- x 1))))
952.0ms
(fma (- (log (exp (+ x 1)))) (/ 1 (- x 1)) (* (log (exp (+ x 1))) (/ 1 (- x 1))))
919.0ms
(fma (- (log (exp (+ x 1)))) (/ 1 (- x 1)) (* (log (exp (+ x 1))) (/ 1 (- x 1))))
909.0ms
(fma (- (log (exp (+ x 1)))) (/ 1 (- x 1)) (* (log (exp (+ x 1))) (/ 1 (- x 1))))

prune1.8s

Pruning

3 alts after pruning (3 fresh and 0 done)

Merged error: 0.0b

localize33.0ms

Local error

Found 3 expressions with local error:

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

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

series70.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
41.0ms
(fma (/ -1 (+ -1 x)) (+ 1 x) (/ x (+ 1 x)))
17.0ms
(/ x (+ 1 x))
11.0ms
(/ -1 (+ -1 x))

simplify1.4s

Counts
19 → 53
Calls
19 calls:
Slowest
533.0ms
(- (+ (* 3 (/ 1 (pow x 3))) (+ (/ 1 (pow x 2)) (* 3 (/ 1 x)))))
489.0ms
(- (+ (* 3 (/ 1 (pow x 3))) (+ (/ 1 (pow x 2)) (* 3 (/ 1 x)))))
75.0ms
(- (+ x (pow x 3)) (pow x 2))
60.0ms
(- (+ (/ 1 (pow x 3)) (+ (/ 1 (pow x 2)) (/ 1 x))))
46.0ms
(+ (* -1 -1) (- (* x x) (* -1 x)))

prune459.0ms

Pruning

3 alts after pruning (2 fresh and 1 done)

Merged error: 0.0b

localize40.0ms

Local error

Found 4 expressions with local error:

29.5b
(fma (/ x (fma x (* x x) 1)) (+ (* x x) (- (* 1 1) (* x 1))) (- (log (exp (/ (+ x 1) (- x 1))))))
3.6b
(/ x (fma x (* x x) 1))
0.1b
(fma x (* x x) 1)
0.0b
(log (exp (/ (+ x 1) (- x 1))))

rewrite11.0ms

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

series514.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
370.0ms
(log (exp (/ (+ x 1) (- x 1))))
70.0ms
(fma (/ x (fma x (* x x) 1)) (+ (* x x) (- (* 1 1) (* x 1))) (- (log (exp (/ (+ x 1) (- x 1))))))
39.0ms
(fma x (* x x) 1)
34.0ms
(/ x (fma x (* x x) 1))

simplify2.1s

Counts
34 → 76
Calls
34 calls:
Slowest
577.0ms
(- (+ (* 3 (/ 1 (pow x 3))) (+ (/ 1 (pow x 2)) (* 3 (/ 1 x)))))
549.0ms
(- (+ (* 3 (/ 1 (pow x 3))) (+ (/ 1 (pow x 2)) (* 3 (/ 1 x)))))
518.0ms
(- (+ (* 2 x) (+ (* 2 (pow x 2)) 1)))
98.0ms
(+ (* 2 (/ 1 (pow x 2))) (+ (* 2 (/ 1 x)) 1))
73.0ms
(+ (* 2 (/ 1 (pow x 2))) (+ (* 2 (/ 1 x)) 1))

prune896.0ms

Pruning

4 alts after pruning (2 fresh and 2 done)

Merged error: 0.0b

regimes72.0ms

Accuracy

100% (0.0b remaining)

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

bsearch147.0ms

end0.0ms

sample2.0s

Algorithm
intervals
Results
786.0ms1718×body1280valid
444.0ms4131×body80valid
441.0ms1151×body640valid
151.0ms658×body320valid
54.0ms342×body160valid