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

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.1
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. Using strategy rm
  3. Applied add-sqr-sqrt19.9

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

    \[\leadsto \color{blue}{\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}}\]
  5. Simplified19.9

    \[\leadsto \color{blue}{\frac{x - y}{\sqrt{x^2 + y^2}^*}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}\]
  6. Simplified0.0

    \[\leadsto \frac{x - y}{\sqrt{x^2 + y^2}^*} \cdot \color{blue}{\frac{y + x}{\sqrt{x^2 + y^2}^*}}\]
  7. Using strategy rm
  8. Applied *-un-lft-identity0.0

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

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

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

Reproduce

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

sample31.0ms

Algorithm
intervals
Results
256×(pre true 80)
256×(body real 80)

simplify293.0ms

Counts
1 → 1
Calls
1 calls:
Slowest
293.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))

prune10.0ms

Pruning

2 alts after pruning (2 fresh and 0 done)

Merged error: 20.3b

localize42.0ms

Local error

Found 2 expressions with local error:

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

rewrite23.0ms

Algorithm
rewrite-expression-head
Rules
associate-/l/
add-exp-log
add-cbrt-cube
flip-+
flip3-+
add-log-exp
add-cube-cbrt
*-un-lft-identity
frac-times
add-sqr-sqrt
flip--
flip3--
times-frac
associate-/r*
log1p-expm1-u
associate-/r/
associate-*r/
associate-*l/
div-exp
cbrt-undiv
pow1
expm1-log1p-u
associate-/l*
div-inv
cbrt-unprod
prod-exp
frac-2neg
fma-def
sum-log
clear-num
+-commutative
Counts
2 → 47
Calls
2 calls:
Slowest
17.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
4.0ms
(+ (* x x) (* y y))

series82.0ms

Counts
2 → 6
Calls
2 calls:
Slowest
56.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
26.0ms
(+ (* x x) (* y y))

simplify3.1s

Counts
31 → 53
Calls
31 calls:
Slowest
371.0ms
(* (- (* x x) (* y y)) (+ (pow x 3) (pow y 3)))
351.0ms
(/ (* (* (* (- x y) (- x y)) (- x y)) (* (* (+ x y) (+ x y)) (+ x y))) (* (* (+ (* x x) (* y y)) (+ (* x x) (* y y))) (+ (* x x) (* y y))))
316.0ms
(* (- (pow x 3) (pow y 3)) (+ x y))
285.0ms
(+ (* (* x x) (* x x)) (- (* (* y y) (* y y)) (* (* x x) (* y y))))
276.0ms
(/ (* (* (* (- x y) (+ x y)) (* (- x y) (+ x y))) (* (- x y) (+ x y))) (* (* (+ (* x x) (* y y)) (+ (* x x) (* y y))) (+ (* x x) (* y y))))

prune490.0ms

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0b

localize26.0ms

Local error

Found 3 expressions with local error:

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

rewrite20.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
9.0ms
(* (/ (- x y) (hypot x y)) (/ (+ y x) (hypot x y)))
7.0ms
(/ (+ y x) (hypot x y))
3.0ms
(/ (- x y) (hypot x y))

series168.0ms

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

simplify3.0s

Counts
102 → 120
Calls
102 calls:
Slowest
294.0ms
(* (/ (- x y) (hypot x y)) (/ (+ y x) (hypot x y)))
280.0ms
(/ (* (* (+ y x) (+ y x)) (+ y x)) (* (* (hypot x y) (hypot x y)) (hypot x y)))
275.0ms
(+ (- (log (- x y)) (log (hypot x y))) (- (log (+ y x)) (log (hypot x y))))
256.0ms
(* (* (* (/ (- x y) (hypot x y)) (/ (- x y) (hypot x y))) (/ (- x y) (hypot x y))) (/ (* (* (+ y x) (+ y x)) (+ y x)) (* (* (hypot x y) (hypot x y)) (hypot x y))))
233.0ms
(+ (- (log (- x y)) (log (hypot x y))) (log (/ (+ y x) (hypot x y))))

prune1.1s

Pruning

2 alts after pruning (2 fresh and 0 done)

Merged error: 0b

localize17.0ms

Local error

Found 4 expressions with local error:

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

rewrite33.0ms

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

series213.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
71.0ms
(/ (hypot x y) (+ y x))
49.0ms
(/ 1 (/ (hypot x y) (+ y x)))
49.0ms
(* (/ (- x y) (hypot x y)) (/ 1 (/ (hypot x y) (+ y x))))
43.0ms
(/ (- x y) (hypot x y))

simplify3.2s

Counts
115 → 148
Calls
115 calls:
Slowest
423.0ms
(+ (- (log (- x y)) (log (hypot x y))) (log (/ 1 (/ (hypot x y) (+ y x)))))
309.0ms
(+ (- (log (- x y)) (log (hypot x y))) (- (- (log (hypot x y)) (log (+ y x)))))
239.0ms
(* (/ (- x y) (hypot x y)) (/ 1 (/ (hypot x y) (+ y x))))
200.0ms
(/ (* (* (hypot x y) (hypot x y)) (hypot x y)) (* (* (+ y x) (+ y x)) (+ y x)))
160.0ms
(+ (log (/ (- x y) (hypot x y))) (log (/ 1 (/ (hypot x y) (+ y x)))))

prune1.5s

Pruning

2 alts after pruning (1 fresh and 1 done)

Merged error: 0b

localize6.0ms

Local error

Found 2 expressions with local error:

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

rewrite10.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
9.0ms
(/ (* (- x y) (+ x y)) (fma y y (* x x)))
0.0ms
(fma y y (* x x))

series79.0ms

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

simplify2.4s

Counts
28 → 47
Calls
28 calls:
Slowest
356.0ms
(* (- (* x x) (* y y)) (+ (pow x 3) (pow y 3)))
240.0ms
(- (log (* (- x y) (+ x y))) (log (fma y y (* x x))))
219.0ms
(* (- x y) (+ (pow x 3) (pow y 3)))
218.0ms
(* (- (pow x 3) (pow y 3)) (+ x y))
211.0ms
(* (- (pow x 3) (pow y 3)) (+ (pow x 3) (pow y 3)))

prune481.0ms

Pruning

2 alts after pruning (0 fresh and 2 done)

Merged error: 0b

regimes58.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.8s

Algorithm
intervals
Results
8000×(pre true 80)
8000×(body real 80)