Average Error: 14.9 → 0.0
Time: 16.1s
Precision: 64
Internal Precision: 128
\[\frac{x}{x \cdot x + 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.3803995254788722 \cdot 10^{+154} \lor \neg \left(x \le 521.0581431275527\right):\\ \;\;\;\;\left(\frac{1}{x} + \frac{1}{{x}^{5}}\right) - \frac{1}{{x}^{3}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{\sqrt{(x \cdot x + 1)_*}}}{\sqrt{(x \cdot x + 1)_*}}\\ \end{array}\]

Error

Bits error versus x

Target

Original14.9
Target0.1
Herbie0.0
\[\frac{1}{x + \frac{1}{x}}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -1.3803995254788722e+154 or 521.0581431275527 < x

    1. Initial program 39.6

      \[\frac{x}{x \cdot x + 1}\]
    2. Simplified39.6

      \[\leadsto \color{blue}{\frac{x}{(x \cdot x + 1)_*}}\]
    3. Taylor expanded around inf 0.0

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

    if -1.3803995254788722e+154 < x < 521.0581431275527

    1. Initial program 0.1

      \[\frac{x}{x \cdot x + 1}\]
    2. Simplified0.1

      \[\leadsto \color{blue}{\frac{x}{(x \cdot x + 1)_*}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt0.1

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

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

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

Reproduce

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

  :herbie-target
  (/ 1 (+ x (/ 1 x)))

  (/ x (+ (* x x) 1)))

Details

Time bar (total: 15.6s)Debug log

sample15.0ms

Algorithm
intervals
Results
10.0ms256×body80valid

simplify3.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
3.0ms
(/ x (+ (* x x) 1))

prune6.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 13.7b

localize6.0ms

Local error

Found 1 expressions with local error:

13.7b
(/ x (fma x x 1))

rewrite1.0ms

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

series26.0ms

Counts
1 → 3
Calls
1 calls:
Slowest
26.0ms
(/ x (fma x x 1))

simplify91.0ms

Counts
6 → 18
Calls
6 calls:
Slowest
38.0ms
(- (+ (/ 1 (pow x 5)) (/ 1 x)) (/ 1 (pow x 3)))
28.0ms
(- (+ (/ 1 (pow x 5)) (/ 1 x)) (/ 1 (pow x 3)))
20.0ms
(- (+ x (pow x 5)) (pow x 3))
2.0ms
(cbrt (fma x x 1))
2.0ms
(sqrt (fma x x 1))

prune115.0ms

Pruning

3 alts after pruning (3 fresh and 0 done)

Merged error: 0b

localize17.0ms

Local error

Found 4 expressions with local error:

13.6b
(sqrt (fma x x 1))
13.6b
(sqrt (fma x x 1))
0.0b
(/ x (sqrt (fma x x 1)))
0.0b
(/ (/ x (sqrt (fma x x 1))) (sqrt (fma x x 1)))

rewrite13.0ms

Algorithm
rewrite-expression-head
Rules
27×add-sqr-sqrt
25×add-cube-cbrt
25×*-un-lft-identity
24×sqrt-prod
24×times-frac
12×associate-/r*
div-inv
add-exp-log
add-cbrt-cube
add-log-exp
associate-/l*
log1p-expm1-u
pow1
expm1-log1p-u
pow1/2
frac-2neg
clear-num
rem-sqrt-square
associate-/l/
div-exp
cbrt-undiv
Counts
4 → 95
Calls
4 calls:
Slowest
7.0ms
(/ (/ x (sqrt (fma x x 1))) (sqrt (fma x x 1)))
2.0ms
(sqrt (fma x x 1))
1.0ms
(sqrt (fma x x 1))
1.0ms
(/ x (sqrt (fma x x 1)))

series94.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
31.0ms
(/ x (sqrt (fma x x 1)))
23.0ms
(/ (/ x (sqrt (fma x x 1))) (sqrt (fma x x 1)))
20.0ms
(sqrt (fma x x 1))
20.0ms
(sqrt (fma x x 1))

simplify2.0s

Counts
84 → 107
Calls
84 calls:
Slowest
197.0ms
(/ (* (* (/ x (sqrt (fma x x 1))) (/ x (sqrt (fma x x 1)))) (/ x (sqrt (fma x x 1)))) (* (* (sqrt (fma x x 1)) (sqrt (fma x x 1))) (sqrt (fma x x 1))))
172.0ms
(- (+ x (* 1/2 (/ 1 x))) (* 1/8 (/ 1 (pow x 3))))
171.0ms
(- (* 1/8 (/ 1 (pow x 3))) (+ x (* 1/2 (/ 1 x))))
159.0ms
(- (+ x (* 1/2 (/ 1 x))) (* 1/8 (/ 1 (pow x 3))))
150.0ms
(- (* 1/8 (/ 1 (pow x 3))) (+ x (* 1/2 (/ 1 x))))

prune928.0ms

Pruning

3 alts after pruning (2 fresh and 1 done)

Merged error: 0b

localize12.0ms

Local error

Found 2 expressions with local error:

16.4b
(- (+ x (pow x 5)) (pow x 3))
0.0b
(+ x (pow x 5))

rewrite15.0ms

Algorithm
rewrite-expression-head
Rules
15×prod-diff
13×*-un-lft-identity
13×add-sqr-sqrt
11×add-cube-cbrt
add-log-exp
unpow3
fma-neg
cube-mult
log1p-expm1-u
add-exp-log
add-cbrt-cube
pow1
expm1-log1p-u
difference-of-squares
distribute-lft-out--
flip--
flip-+
associate--l+
diff-log
flip3--
flip3-+
sub-neg
+-commutative
Counts
2 → 47
Calls
2 calls:
Slowest
12.0ms
(- (+ x (pow x 5)) (pow x 3))
2.0ms
(+ x (pow x 5))

series71.0ms

Counts
2 → 6
Calls
2 calls:
Slowest
40.0ms
(+ x (pow x 5))
30.0ms
(- (+ x (pow x 5)) (pow x 3))

simplify2.4s

Counts
42 → 53
Calls
42 calls:
Slowest
270.0ms
(fma (- (cbrt (pow x 3))) (* (cbrt (pow x 3)) (cbrt (pow x 3))) (* (cbrt (pow x 3)) (* (cbrt (pow x 3)) (cbrt (pow x 3)))))
249.0ms
(fma (- (cbrt (pow x 3))) (* (cbrt (pow x 3)) (cbrt (pow x 3))) (* (cbrt (pow x 3)) (* (cbrt (pow x 3)) (cbrt (pow x 3)))))
203.0ms
(fma (- (cbrt (pow x 3))) (* (cbrt (pow x 3)) (cbrt (pow x 3))) (* (cbrt (pow x 3)) (* (cbrt (pow x 3)) (cbrt (pow x 3)))))
199.0ms
(fma (sqrt (+ x (pow x 5))) (sqrt (+ x (pow x 5))) (- (* (cbrt (pow x 3)) (* (cbrt (pow x 3)) (cbrt (pow x 3))))))
166.0ms
(fma 1 (+ x (pow x 5)) (- (* (cbrt (pow x 3)) (* (cbrt (pow x 3)) (cbrt (pow x 3))))))

prune404.0ms

Pruning

3 alts after pruning (1 fresh and 2 done)

Merged error: 0b

localize13.0ms

Local error

Found 4 expressions with local error:

21.4b
(- (+ (/ 1 (pow x 5)) (/ 1 x)) (/ 1 (pow x 3)))
0.3b
(/ 1 (pow x 5))
0.2b
(/ 1 (pow x 3))
0.0b
(+ (/ 1 (pow x 5)) (/ 1 x))

rewrite46.0ms

Algorithm
rewrite-expression-head
Rules
58×*-un-lft-identity
47×div-inv
32×distribute-lft-out
28×prod-diff
21×add-sqr-sqrt
19×add-cube-cbrt
11×add-log-exp
10×distribute-lft-out--
associate-/r*
fma-neg
add-exp-log
log1p-expm1-u
add-cbrt-cube
fma-def
rec-exp
pow1
expm1-log1p-u
frac-sub
inv-pow
pow-flip
flip-+
frac-add
diff-log
flip3-+
frac-2neg
sum-log
clear-num
pow-to-exp
difference-of-squares
flip--
associate--l+
unpow3
flip3--
sub-neg
+-commutative
cube-mult
Counts
4 → 127
Calls
4 calls:
Slowest
37.0ms
(- (+ (/ 1 (pow x 5)) (/ 1 x)) (/ 1 (pow x 3)))
5.0ms
(+ (/ 1 (pow x 5)) (/ 1 x))
1.0ms
(/ 1 (pow x 5))
1.0ms
(/ 1 (pow x 3))

series89.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
38.0ms
(+ (/ 1 (pow x 5)) (/ 1 x))
21.0ms
(/ 1 (pow x 5))
17.0ms
(- (+ (/ 1 (pow x 5)) (/ 1 x)) (/ 1 (pow x 3)))
13.0ms
(/ 1 (pow x 3))

simplify7.3s

Counts
109 → 139
Calls
109 calls:
Slowest
428.0ms
(* (- (/ 1 (pow x 5)) (/ 1 x)) (pow x 3))
260.0ms
(- (* (+ (pow (/ 1 (pow x 5)) 3) (pow (/ 1 x) 3)) (pow x 3)) (* (+ (* (/ 1 (pow x 5)) (/ 1 (pow x 5))) (- (* (/ 1 x) (/ 1 x)) (* (/ 1 (pow x 5)) (/ 1 x)))) 1))
246.0ms
(- (* (- (* (/ 1 (pow x 5)) (/ 1 (pow x 5))) (* (/ 1 x) (/ 1 x))) (pow x 3)) (* (- (/ 1 (pow x 5)) (/ 1 x)) 1))
215.0ms
(fma 1 (+ (/ 1 (pow x 5)) (/ 1 x)) (- (* (/ 1 (pow x 3)) 1)))
202.0ms
(- (* (+ (* 1 x) (* (pow x 5) 1)) (pow x 3)) (* (* (pow x 5) x) 1))

prune1.2s

Pruning

3 alts after pruning (0 fresh and 3 done)

Merged error: 0b

regimes41.0ms

Accuracy

99.9% (0.0b remaining)

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

bsearch83.0ms

end0.0ms

sample667.0ms

Algorithm
intervals
Results
573.0ms8000×body80valid