Average Error: 20.5 → 0.0
Time: 54.0s
Precision: 64
Internal Precision: 128
\[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
\[\frac{x - y}{\frac{\sqrt{x^2 + y^2}^*}{\frac{y + x}{\sqrt{x^2 + y^2}^*}}}\]

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original20.5
Target0.0
Herbie0.0
\[\begin{array}{l} \mathbf{if}\;0.5 \lt \left|\frac{x}{y}\right| \lt 2:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{2}{1 + \frac{x}{y} \cdot \frac{x}{y}}\\ \end{array}\]

Derivation

  1. Initial program 20.5

    \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
  2. Simplified20.5

    \[\leadsto \color{blue}{\frac{\left(x - y\right) \cdot \left(y + x\right)}{(x \cdot x + \left(y \cdot y\right))_*}}\]
  3. Using strategy rm
  4. Applied add-sqr-sqrt20.5

    \[\leadsto \frac{\left(x - y\right) \cdot \left(y + x\right)}{\color{blue}{\sqrt{(x \cdot x + \left(y \cdot y\right))_*} \cdot \sqrt{(x \cdot x + \left(y \cdot y\right))_*}}}\]
  5. Applied times-frac20.5

    \[\leadsto \color{blue}{\frac{x - y}{\sqrt{(x \cdot x + \left(y \cdot y\right))_*}} \cdot \frac{y + x}{\sqrt{(x \cdot x + \left(y \cdot y\right))_*}}}\]
  6. Simplified20.4

    \[\leadsto \color{blue}{\frac{x - y}{\sqrt{x^2 + y^2}^*}} \cdot \frac{y + x}{\sqrt{(x \cdot x + \left(y \cdot y\right))_*}}\]
  7. Simplified0.0

    \[\leadsto \frac{x - y}{\sqrt{x^2 + y^2}^*} \cdot \color{blue}{\frac{x + y}{\sqrt{x^2 + y^2}^*}}\]
  8. Using strategy rm
  9. Applied associate-*l/0.0

    \[\leadsto \color{blue}{\frac{\left(x - y\right) \cdot \frac{x + y}{\sqrt{x^2 + y^2}^*}}{\sqrt{x^2 + y^2}^*}}\]
  10. Using strategy rm
  11. Applied associate-/l*0.0

    \[\leadsto \color{blue}{\frac{x - y}{\frac{\sqrt{x^2 + y^2}^*}{\frac{x + y}{\sqrt{x^2 + y^2}^*}}}}\]
  12. Final simplification0.0

    \[\leadsto \frac{x - y}{\frac{\sqrt{x^2 + y^2}^*}{\frac{y + x}{\sqrt{x^2 + y^2}^*}}}\]

Reproduce

herbie shell --seed 2019002 +o rules:numerics
(FPCore (x y)
  :name "Kahan p9 Example"
  :pre (and (< 0 x 1) (< y 1))

  :herbie-target
  (if (< 0.5 (fabs (/ x y)) 2) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1 (/ 2 (+ 1 (* (/ x y) (/ x y))))))

  (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))

Details

Time bar (total: 53.2s)Debug log

sample33.0ms

Algorithm
intervals

simplify409.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

409.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))

prune8.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 19.5b

localize34.0ms

Local error

Found 2 expressions with local error:

19.5b
(/ (* (- x y) (+ y x)) (fma x x (* y y)))
0.0b
(fma x x (* y y))

rewrite13.0ms

Algorithm
rewrite-expression-head
Counts
2 → 41
Calls

2 calls. Slowest were:

12.0ms
(/ (* (- x y) (+ y x)) (fma x x (* y y)))
0.0ms
(fma x x (* y y))

series82.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

54.0ms
(/ (* (- x y) (+ y x)) (fma x x (* y y)))
28.0ms
(fma x x (* y y))

simplify3.3s

Counts
28 → 47
Calls

28 calls. Slowest were:

437.0ms
(* (- (* x x) (* y y)) (+ (pow y 3) (pow x 3)))
401.0ms
(* (- (* x x) (* y y)) (+ y x))
331.0ms
(* (- (pow x 3) (pow y 3)) (+ y x))

prune537.0ms

Pruning

3 alts after pruning (3 fresh and 0 done)

Merged error: 0.0b

localize13.0ms

Local error

Found 4 expressions with local error:

0.0b
(* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))
0.0b
(/ (+ x y) (hypot x y))
0.0b
(/ (- x y) (hypot x y))
0.0b
(hypot x y)

rewrite15.0ms

Algorithm
rewrite-expression-head
Counts
4 → 121
Calls

4 calls. Slowest were:

8.0ms
(* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))
3.0ms
(/ (+ x y) (hypot x y))
3.0ms
(/ (- x y) (hypot x y))

series249.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

74.0ms
(/ (- x y) (hypot x y))
69.0ms
(* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))
65.0ms
(/ (+ x y) (hypot x y))
41.0ms
(hypot x y)

simplify3.3s

Counts
105 → 133
Calls

105 calls. Slowest were:

405.0ms
(+ (- (log (- x y)) (log (hypot x y))) (- (log (+ x y)) (log (hypot x y))))
373.0ms
(* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))
362.0ms
(/ (* (* (+ x y) (+ x y)) (+ x y)) (* (* (hypot x y) (hypot x y)) (hypot x y)))

prune1.3s

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0b

localize6.0ms

Local error

Found 4 expressions with local error:

0.0b
(/ (+ x y) (hypot x y))
0.0b
(/ (* (- x y) (/ (+ x y) (hypot x y))) (hypot x y))
0.0b
(hypot x y)
0.0b
(hypot x y)

rewrite14.0ms

Algorithm
rewrite-expression-head
Counts
4 → 81
Calls

4 calls. Slowest were:

8.0ms
(/ (* (- x y) (/ (+ x y) (hypot x y))) (hypot x y))
3.0ms
(/ (+ x y) (hypot x y))
0.0ms
(hypot x y)

series237.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

79.0ms
(/ (* (- x y) (/ (+ x y) (hypot x y))) (hypot x y))
79.0ms
(/ (+ x y) (hypot x y))
43.0ms
(hypot x y)
36.0ms
(hypot x y)

simplify2.7s

Counts
60 → 93
Calls

60 calls. Slowest were:

392.0ms
(/ (* (* (+ x y) (+ x y)) (+ x y)) (* (* (hypot x y) (hypot x y)) (hypot x y)))
317.0ms
(/ (* (* (* (- x y) (- x y)) (- x y)) (/ (* (* (+ x y) (+ x y)) (+ x y)) (* (* (hypot x y) (hypot x y)) (hypot x y)))) (* (* (hypot x y) (hypot x y)) (hypot x y)))
284.0ms
(* (- (pow x 3) (pow y 3)) (/ (+ x y) (hypot x y)))

prune900.0ms

Pruning

3 alts after pruning (3 fresh and 0 done)

Merged error: 0b

localize6.0ms

Local error

Found 4 expressions with local error:

0.0b
(/ (+ x y) (hypot x y))
0.0b
(/ (hypot x y) (/ (+ x y) (hypot x y)))
0.0b
(/ (- x y) (/ (hypot x y) (/ (+ x y) (hypot x y))))
0.0b
(hypot x y)

rewrite26.0ms

Algorithm
rewrite-expression-head
Counts
4 → 314
Calls

4 calls. Slowest were:

6.0ms
(/ (- x y) (/ (hypot x y) (/ (+ x y) (hypot x y))))
5.0ms
(/ (hypot x y) (/ (+ x y) (hypot x y)))
3.0ms
(/ (+ x y) (hypot x y))

series217.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

70.0ms
(/ (hypot x y) (/ (+ x y) (hypot x y)))
62.0ms
(/ (+ x y) (hypot x y))
56.0ms
(/ (- x y) (/ (hypot x y) (/ (+ x y) (hypot x y))))
30.0ms
(hypot x y)

simplify35.0s

Counts
457 → 326
Calls

457 calls. Slowest were:

686.0ms
(/ (sqrt (- x y)) (/ (* (cbrt (hypot x y)) (cbrt (hypot x y))) (/ 1 (sqrt (hypot x y)))))
682.0ms
(/ (* (cbrt (- x y)) (cbrt (- x y))) (/ (* (cbrt (hypot x y)) (cbrt (hypot x y))) (/ (sqrt (+ x y)) 1)))
628.0ms
(/ (* (cbrt (- x y)) (cbrt (- x y))) (/ (* (cbrt (hypot x y)) (cbrt (hypot x y))) (/ 1 (* (cbrt (hypot x y)) (cbrt (hypot x y))))))

prune3.4s

Pruning

3 alts after pruning (2 fresh and 1 done)

Merged error: 0b

regimes52.0ms

Accuracy

0% (0.0b remaining)

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

bsearch1.0ms

end0.0ms

sample1.3s

Algorithm
intervals