Average Error: 19.9 → 0.0
Time: 21.5s
Precision: 64
Internal Precision: 128
\[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
\[\frac{\left(x - y\right) \cdot \frac{y + x}{\sqrt{x^2 + y^2}^*}}{\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

Original19.9
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 19.9

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

    \[\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-sqrt19.9

    \[\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.0

    \[\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.0

    \[\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. Final simplification0.0

    \[\leadsto \frac{\left(x - y\right) \cdot \frac{y + x}{\sqrt{x^2 + y^2}^*}}{\sqrt{x^2 + y^2}^*}\]

Reproduce

herbie shell --seed 2019010 +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: 21.1s)Debug log

sample61.0ms

Algorithm
intervals

simplify407.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
406.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

localize19.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
Rules
associate-/l/
add-exp-log
add-cbrt-cube
add-cube-cbrt
*-un-lft-identity
frac-times
add-sqr-sqrt
flip--
flip-+
flip3--
times-frac
flip3-+
associate-/r*
add-log-exp
log1p-expm1-u
associate-*r/
associate-*l/
div-exp
cbrt-undiv
pow1
expm1-log1p-u
associate-/l*
div-inv
fma-udef
cbrt-unprod
prod-exp
frac-2neg
clear-num
Counts
2 → 41
Calls
2 calls:
Slowest
12.0ms
(/ (* (- x y) (+ y x)) (fma x x (* y y)))
0.0ms
(fma x x (* y y))

series84.0ms

Counts
2 → 6
Calls
2 calls:
Slowest
53.0ms
(/ (* (- x y) (+ y x)) (fma x x (* y y)))
31.0ms
(fma x x (* y y))

simplify3.0s

Counts
28 → 47
Calls
28 calls:
Slowest
450.0ms
(* (- (* x x) (* y y)) (+ (pow y 3) (pow x 3)))
300.0ms
(* (- (* x x) (* y y)) (- (* y y) (* x x)))
293.0ms
(* (- (* x x) (* y y)) (+ y x))
281.0ms
(* (- x y) (+ (pow y 3) (pow x 3)))
269.0ms
(* (- (pow x 3) (pow y 3)) (+ y x))

prune435.0ms

Pruning

3 alts after pruning (3 fresh and 0 done)

Merged error: 0.0b

localize24.0ms

Local error

Found 3 expressions with local error:

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

rewrite31.0ms

Algorithm
rewrite-expression-head
Rules
36×times-frac
33×add-cube-cbrt
33×*-un-lft-identity
33×add-sqr-sqrt
19×add-exp-log
19×add-cbrt-cube
13×associate-*l*
13×associate-*r*
associate-/l*
div-exp
associate-/r*
cbrt-undiv
pow1
associate-/l/
div-inv
cbrt-unprod
prod-exp
add-log-exp
log1p-expm1-u
expm1-log1p-u
frac-2neg
clear-num
flip--
flip-+
*-commutative
associate-*r/
associate-*l/
pow-prod-down
div-sub
flip3--
flip3-+
frac-times
Counts
3 → 111
Calls
3 calls:
Slowest
16.0ms
(* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))
7.0ms
(/ (+ x y) (hypot x y))
6.0ms
(/ (- x y) (hypot x y))

series189.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
78.0ms
(* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))
58.0ms
(/ (- x y) (hypot x y))
53.0ms
(/ (+ x y) (hypot x y))

simplify3.2s

Counts
102 → 120
Calls
102 calls:
Slowest
367.0ms
(+ (- (log (- x y)) (log (hypot x y))) (- (log (+ x y)) (log (hypot x y))))
342.0ms
(* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))
309.0ms
(/ (* (* (+ x y) (+ x y)) (+ x y)) (* (* (hypot x y) (hypot x y)) (hypot x y)))
300.0ms
(* (/ (* (* (- x y) (- x y)) (- x y)) (* (* (hypot x y) (hypot x y)) (hypot x y))) (/ (* (* (+ x y) (+ x y)) (+ x y)) (* (* (hypot x y) (hypot x y)) (hypot x y))))
281.0ms
(+ (- (log (- x y)) (log (hypot x y))) (log (/ (+ x y) (hypot x y))))

prune1.1s

Pruning

3 alts after pruning (3 fresh and 0 done)

Merged error: 0b

localize11.0ms

Local error

Found 3 expressions with local error:

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

rewrite21.0ms

Algorithm
rewrite-expression-head
Rules
21×add-cube-cbrt
21×times-frac
21×*-un-lft-identity
21×add-sqr-sqrt
19×add-exp-log
19×add-cbrt-cube
13×associate-*r*
associate-/l/
div-exp
associate-/r*
cbrt-undiv
pow1
associate-/l*
flip--
cbrt-unprod
prod-exp
associate-*l/
flip3--
frac-times
add-log-exp
div-inv
log1p-expm1-u
associate-*l*
expm1-log1p-u
associate-*r/
frac-2neg
clear-num
flip-+
*-commutative
pow-prod-down
flip3-+
Counts
3 → 97
Calls
3 calls:
Slowest
9.0ms
(/ (* (- x y) (/ (+ x y) (hypot x y))) (hypot x y))
6.0ms
(/ (+ x y) (hypot x y))
5.0ms
(* (- x y) (/ (+ x y) (hypot x y)))

series173.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
60.0ms
(* (- x y) (/ (+ x y) (hypot x y)))
57.0ms
(/ (+ x y) (hypot x y))
55.0ms
(/ (* (- x y) (/ (+ x y) (hypot x y))) (hypot x y))

simplify3.9s

Counts
84 → 106
Calls
84 calls:
Slowest
337.0ms
(/ (* (* (+ x y) (+ x y)) (+ x y)) (* (* (hypot x y) (hypot x y)) (hypot x y)))
315.0ms
(* (- (pow x 3) (pow y 3)) (+ x y))
306.0ms
(* (- (pow x 3) (pow y 3)) (+ x y))
269.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)))
248.0ms
(* (- (pow x 3) (pow y 3)) (/ (+ x y) (hypot x y)))

prune975.0ms

Pruning

3 alts after pruning (2 fresh and 1 done)

Merged error: 0b

localize13.0ms

Local error

Found 3 expressions with local error:

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

rewrite41.0ms

Algorithm
rewrite-expression-head
Rules
21×add-cube-cbrt
21×times-frac
21×*-un-lft-identity
21×add-sqr-sqrt
19×add-exp-log
19×add-cbrt-cube
13×associate-*l*
associate-/l/
div-exp
associate-/r*
cbrt-undiv
pow1
associate-/l*
flip-+
cbrt-unprod
associate-*r/
prod-exp
flip3-+
frac-times
add-log-exp
div-inv
log1p-expm1-u
associate-*r*
expm1-log1p-u
associate-*l/
frac-2neg
clear-num
flip--
*-commutative
pow-prod-down
div-sub
flip3--
distribute-lft-in
distribute-rgt-in
Counts
3 → 100
Calls
3 calls:
Slowest
17.0ms
(/ (* (/ (- x y) (hypot x y)) (+ x y)) (hypot x y))
13.0ms
(* (/ (- x y) (hypot x y)) (+ x y))
9.0ms
(/ (- x y) (hypot x y))

series224.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
76.0ms
(* (/ (- x y) (hypot x y)) (+ x y))
74.0ms
(/ (- x y) (hypot x y))
74.0ms
(/ (* (/ (- x y) (hypot x y)) (+ x y)) (hypot x y))

simplify4.4s

Counts
87 → 109
Calls
87 calls:
Slowest
385.0ms
(* (/ (- x y) (hypot x y)) (+ x y))
318.0ms
(/ (* (/ (* (* (- x y) (- x y)) (- x y)) (* (* (hypot x y) (hypot x y)) (hypot x y))) (* (* (+ x y) (+ x y)) (+ x y))) (* (* (hypot x y) (hypot x y)) (hypot x y)))
306.0ms
(/ (* (* (* (/ (- x y) (hypot x y)) (/ (- x y) (hypot x y))) (/ (- x y) (hypot x y))) (* (* (+ x y) (+ x y)) (+ x y))) (* (* (hypot x y) (hypot x y)) (hypot x y)))
289.0ms
(* (hypot x y) (+ (* x x) (- (* y y) (* x y))))
279.0ms
(* (- x y) (+ (pow x 3) (pow y 3)))

prune848.0ms

Pruning

3 alts after pruning (1 fresh and 2 done)

Merged error: 0b

regimes97.0ms

Accuracy

0% (0.0b remaining)

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

bsearch2.0ms

end0.0ms

sample1.8s

Algorithm
intervals