Average Error: 28.9 → 0.0
Time: 1.8m
Precision: 64
Internal Precision: 128
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.1484138251760253 \cdot 10^{+33} \lor \neg \left(x \le 4921536.861747979\right):\\ \;\;\;\;\frac{\frac{-1}{x}}{x} \cdot \left(1 + \frac{3}{x}\right) - \frac{3}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{(-3 \cdot x + -1)_*}{\left(1 + x\right) \cdot \left(x - 1\right)}\\ \end{array}\]

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if x < -2.1484138251760253e+33 or 4921536.861747979 < x

    1. Initial program 60.1

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

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

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

      \[\leadsto \frac{\color{blue}{-\left(3 \cdot x + 1\right)}}{\left(x + 1\right) \cdot \left(x - 1\right)}\]
    6. Simplified32.8

      \[\leadsto \frac{\color{blue}{(-3 \cdot x + -1)_*}}{\left(x + 1\right) \cdot \left(x - 1\right)}\]
    7. Using strategy rm
    8. Applied flip3-+45.8

      \[\leadsto \frac{(-3 \cdot x + -1)_*}{\color{blue}{\frac{{x}^{3} + {1}^{3}}{x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)}} \cdot \left(x - 1\right)}\]
    9. Applied associate-*l/50.9

      \[\leadsto \frac{(-3 \cdot x + -1)_*}{\color{blue}{\frac{\left({x}^{3} + {1}^{3}\right) \cdot \left(x - 1\right)}{x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)}}}\]
    10. Applied associate-/r/50.9

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

      \[\leadsto \frac{(-3 \cdot x + -1)_*}{\left({x}^{3} + {1}^{3}\right) \cdot \left(x - 1\right)} \cdot \color{blue}{(x \cdot x + \left(1 - x\right))_*}\]
    12. 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)}\]
    13. Simplified0.0

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

    if -2.1484138251760253e+33 < x < 4921536.861747979

    1. Initial program 2.2

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

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

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

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

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

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

Reproduce

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

Details

Time bar (total: 1.7m)Debug log

start140.0ms

Algorithm
intervals

setup45.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 27.0b

localize58.0ms

Local error

Found 3 expressions with local error:

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

rewrite27.0ms

Algorithm
rewrite-expression-head
Counts
3 → 164
Calls

3 calls. Slowest were:

15.0ms
(- (/ x (+ x 1)) (/ (+ x 1) (- x 1)))
6.0ms
(/ (+ x 1) (- x 1))
1.0ms
(/ x (+ x 1))

series64.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

35.0ms
(- (/ x (+ x 1)) (/ (+ x 1) (- x 1)))
16.0ms
(/ x (+ x 1))
13.0ms
(/ (+ x 1) (- x 1))

simplify56.1s

Counts
235 → 173
Calls

235 calls. Slowest were:

1.2s
(fma (- (+ x 1)) (/ (+ x 1) (- (* x x) (* 1 1))) (* (+ x 1) (/ (+ x 1) (- (* x x) (* 1 1)))))
1.2s
(fma (- (+ x 1)) (/ (+ x 1) (- (* x x) (* 1 1))) (* (+ x 1) (/ (+ x 1) (- (* x x) (* 1 1)))))
1.2s
(fma (- (+ x 1)) (/ (+ x 1) (- (* x x) (* 1 1))) (* (+ x 1) (/ (+ x 1) (- (* x x) (* 1 1)))))

prune1.5s

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0.0b

localize27.0ms

Local error

Found 4 expressions with local error:

14.5b
(/ (fma x (- x (+ x 2)) (- -1 x)) (* (+ x 1) (- x 1)))
1.0b
(- x (+ x 2))
0.0b
(* (+ x 1) (- x 1))
0.0b
(fma x (- x (+ x 2)) (- -1 x))

rewrite21.0ms

Algorithm
rewrite-expression-head
Counts
4 → 86
Calls

4 calls. Slowest were:

11.0ms
(/ (fma x (- x (+ x 2)) (- -1 x)) (* (+ x 1) (- x 1)))
8.0ms
(* (+ x 1) (- x 1))
1.0ms
(- x (+ x 2))

series102.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

34.0ms
(fma x (- x (+ x 2)) (- -1 x))
33.0ms
(/ (fma x (- x (+ x 2)) (- -1 x)) (* (+ x 1) (- x 1)))
31.0ms
(* (+ x 1) (- x 1))
4.0ms
(- x (+ x 2))

simplify12.2s

Counts
57 → 98
Calls

57 calls. Slowest were:

2.3s
(* (+ (* x x) (- (* 1 1) (* x 1))) (+ x 1))
2.3s
(* (+ (* x x) (- (* 1 1) (* x 1))) (+ x 1))
1.2s
(* (* (* (+ x 1) (+ x 1)) (+ x 1)) (* (* (- x 1) (- x 1)) (- x 1)))

prune1.3s

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0b

localize14.0ms

Local error

Found 3 expressions with local error:

14.6b
(/ (fma -3 x -1) (* (+ x 1) (- x 1)))
0.1b
(fma -3 x -1)
0.0b
(* (+ x 1) (- x 1))

rewrite19.0ms

Algorithm
rewrite-expression-head
Counts
3 → 72
Calls

3 calls. Slowest were:

10.0ms
(/ (fma -3 x -1) (* (+ x 1) (- x 1)))
7.0ms
(* (+ x 1) (- x 1))
0.0ms
(fma -3 x -1)

series86.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

36.0ms
(/ (fma -3 x -1) (* (+ x 1) (- x 1)))
29.0ms
(* (+ x 1) (- x 1))
20.0ms
(fma -3 x -1)

simplify10.9s

Counts
54 → 81
Calls

54 calls. Slowest were:

2.5s
(* (+ (* x x) (- (* 1 1) (* x 1))) (+ x 1))
2.2s
(* (+ (* x x) (- (* 1 1) (* x 1))) (+ x 1))
1.2s
(* (* (* (+ x 1) (+ x 1)) (+ x 1)) (* (* (- x 1) (- x 1)) (- x 1)))

prune909.0ms

Pruning

3 alts after pruning (2 fresh and 1 done)

Merged error: 0b

localize48.0ms

Local error

Found 4 expressions with local error:

19.9b
(* (/ (fma -3 x -1) (* (+ (pow x 3) (pow 1 3)) (- x 1))) (fma x x (- 1 x)))
2.2b
(/ (fma -3 x -1) (* (+ (pow x 3) (pow 1 3)) (- x 1)))
0.1b
(fma -3 x -1)
0.0b
(* (+ (pow x 3) (pow 1 3)) (- x 1))

rewrite53.0ms

Algorithm
rewrite-expression-head
Counts
4 → 113
Calls

4 calls. Slowest were:

36.0ms
(* (/ (fma -3 x -1) (* (+ (pow x 3) (pow 1 3)) (- x 1))) (fma x x (- 1 x)))
8.0ms
(* (+ (pow x 3) (pow 1 3)) (- x 1))
7.0ms
(/ (fma -3 x -1) (* (+ (pow x 3) (pow 1 3)) (- x 1)))

series127.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

41.0ms
(* (/ (fma -3 x -1) (* (+ (pow x 3) (pow 1 3)) (- x 1))) (fma x x (- 1 x)))
33.0ms
(/ (fma -3 x -1) (* (+ (pow x 3) (pow 1 3)) (- x 1)))
27.0ms
(* (+ (pow x 3) (pow 1 3)) (- x 1))
26.0ms
(fma -3 x -1)

simplify16.0s

Counts
85 → 125
Calls

85 calls. Slowest were:

859.0ms
(* (+ (pow (pow x 3) 3) (pow (pow 1 3) 3)) (- (* x x) (* 1 1)))
804.0ms
(/ (fma -3 x -1) (* (+ (pow (pow x 3) 3) (pow (pow 1 3) 3)) (- (* x x) (* 1 1))))
773.0ms
(/ (fma -3 x -1) (* (- (* (pow x 3) (pow x 3)) (* (pow 1 3) (pow 1 3))) (- x 1)))

prune2.1s

Pruning

3 alts after pruning (1 fresh and 2 done)

Merged error: 0b

regimes38.0ms

Accuracy

99.9% (0.0b remaining)

Error of 0.0b against oracle of 0.0b and baseline of 15.1b

bsearch200.0ms