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

Original19.8
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.8

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

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

    \[\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-frac19.8

    \[\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. Simplified19.8

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

    \[\leadsto \color{blue}{\log \left(e^{\frac{x - y}{\sqrt{x^2 + y^2}^*}}\right)} \cdot \frac{x + y}{\sqrt{x^2 + y^2}^*}\]
  10. Final simplification0.0

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

Reproduce

herbie shell --seed 2019022 +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

sample60.0ms

Algorithm
intervals
Results
35.0ms256×body80valid
12.0ms256×pre80true

simplify381.0ms

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

prune15.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 19.0b

localize26.0ms

Local error

Found 2 expressions with local error:

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

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

series87.0ms

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

simplify2.8s

Counts
28 → 47
Calls
28 calls:
Slowest
429.0ms
(* (- (* x x) (* y y)) (+ (pow y 3) (pow x 3)))
283.0ms
(* (- x y) (+ (pow y 3) (pow x 3)))
275.0ms
(* (- (* x x) (* y y)) (+ y x))
251.0ms
(/ (* (* (* (- x y) (- x y)) (- x y)) (* (* (+ y x) (+ y x)) (+ y x))) (* (* (fma x x (* y y)) (fma x x (* y y))) (fma x x (* y y))))
246.0ms
(* (- (* x x) (* y y)) (- (* y y) (* x x)))

prune388.0ms

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0.0b

localize14.0ms

Local error

Found 4 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)))
0.0b
(hypot x y)

rewrite14.0ms

Algorithm
rewrite-expression-head
Rules
36×times-frac
34×add-cube-cbrt
34×*-un-lft-identity
34×add-sqr-sqrt
20×add-exp-log
20×add-cbrt-cube
13×associate-*l*
13×associate-*r*
associate-/l*
div-exp
associate-/r*
cbrt-undiv
pow1
associate-/l/
add-log-exp
div-inv
log1p-expm1-u
cbrt-unprod
prod-exp
expm1-log1p-u
frac-2neg
clear-num
flip--
flip-+
*-commutative
associate-*r/
associate-*l/
pow-prod-down
div-sub
flip3--
flip3-+
hypot-udef
frac-times
Counts
4 → 121
Calls
4 calls:
Slowest
7.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))
0.0ms
(hypot x y)

series209.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
69.0ms
(/ (+ x y) (hypot x y))
68.0ms
(* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))
48.0ms
(/ (- x y) (hypot x y))
23.0ms
(hypot x y)

simplify2.5s

Counts
105 → 133
Calls
105 calls:
Slowest
322.0ms
(* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))
263.0ms
(/ (* (* (+ x y) (+ x y)) (+ x y)) (* (* (hypot x y) (hypot x y)) (hypot x y)))
220.0ms
(+ (- (log (- x y)) (log (hypot x y))) (- (log (+ x y)) (log (hypot x y))))
179.0ms
(+ (- (log (- x y)) (log (hypot x y))) (log (/ (+ x y) (hypot x y))))
175.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))))

prune1.0s

Pruning

5 alts after pruning (5 fresh and 0 done)

Merged error: 0b

localize13.0ms

Local error

Found 4 expressions with local error:

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

rewrite31.0ms

Algorithm
rewrite-expression-head
Rules
45×times-frac
43×add-cube-cbrt
43×*-un-lft-identity
43×add-sqr-sqrt
28×log-pow
26×exp-prod
17×associate-*l*
13×add-exp-log
13×associate-*r*
13×add-cbrt-cube
pow1
associate-/l*
associate-/r*
div-inv
associate-/l/
add-log-exp
log1p-expm1-u
expm1-log1p-u
div-exp
log-prod
cbrt-undiv
cbrt-unprod
prod-exp
div-sub
frac-2neg
clear-num
flip--
flip-+
*-commutative
associate-*r/
pow-prod-down
rem-log-exp
exp-diff
flip3--
flip3-+
log-div
Counts
4 → 137
Calls
4 calls:
Slowest
11.0ms
(* (log (exp (/ (- x y) (hypot x y)))) (/ (+ x y) (hypot x y)))
9.0ms
(log (exp (/ (- x y) (hypot x y))))
4.0ms
(/ (- x y) (hypot x y))
4.0ms
(/ (+ x y) (hypot x y))

series189.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
52.0ms
(/ (- x y) (hypot x y))
47.0ms
(/ (+ x y) (hypot x y))
46.0ms
(* (log (exp (/ (- x y) (hypot x y)))) (/ (+ x y) (hypot x y)))
44.0ms
(log (exp (/ (- x y) (hypot x y))))

simplify1.5s

Counts
119 → 149
Calls
119 calls:
Slowest
192.0ms
(/ (* (* (+ x y) (+ x y)) (+ x y)) (* (* (hypot x y) (hypot x y)) (hypot x y)))
167.0ms
(* (log (exp (/ (- x y) (hypot x y)))) (/ (+ x y) (hypot x y)))
138.0ms
(* (* (* (log (exp (/ (- x y) (hypot x y)))) (log (exp (/ (- x y) (hypot x y))))) (log (exp (/ (- x y) (hypot x y))))) (/ (* (* (+ x y) (+ x y)) (+ x y)) (* (* (hypot x y) (hypot x y)) (hypot x y))))
123.0ms
(+ (log (log (exp (/ (- x y) (hypot x y))))) (- (log (+ x y)) (log (hypot x y))))
107.0ms
(/ (* (* (- x y) (- x y)) (- x y)) (* (* (hypot x y) (hypot x y)) (hypot x y)))

prune1.2s

Pruning

5 alts after pruning (4 fresh and 1 done)

Merged error: 0b

localize20.0ms

Local error

Found 4 expressions with local error:

0.0b
(* (cbrt (* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))) (cbrt (* (/ (- 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
(/ (- x y) (hypot x y))

rewrite22.0ms

Algorithm
rewrite-expression-head
Rules
30×add-cube-cbrt
30×*-un-lft-identity
30×add-sqr-sqrt
27×times-frac
24×cbrt-div
17×frac-times
12×add-exp-log
11×associate-*r/
11×associate-*l/
10×add-cbrt-cube
associate-/l*
associate-/r*
pow1
associate-/l/
add-log-exp
log1p-expm1-u
associate-*l*
associate-*r*
pow1/3
expm1-log1p-u
flip--
div-inv
div-exp
div-sub
flip3--
frac-2neg
clear-num
cbrt-undiv
pow-prod-up
pow-prod-down
cbrt-prod
cbrt-unprod
*-commutative
prod-exp
pow-plus
pow2
Counts
4 → 137
Calls
4 calls:
Slowest
11.0ms
(* (cbrt (* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))) (cbrt (* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))))
4.0ms
(/ (- x y) (hypot x y))
2.0ms
(/ (- x y) (hypot x y))
2.0ms
(/ (- x y) (hypot x y))

series359.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
208.0ms
(* (cbrt (* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))) (cbrt (* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))))
60.0ms
(/ (- x y) (hypot x y))
50.0ms
(/ (- x y) (hypot x y))
42.0ms
(/ (- x y) (hypot x y))

simplify7.4s

Counts
136 → 149
Calls
136 calls:
Slowest
676.0ms
(* (cbrt (* (/ (- x y) (hypot x y)) (+ x y))) (cbrt (* (- x y) (/ (+ x y) (hypot x y)))))
365.0ms
(* (* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y))) (* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y))))
364.0ms
(* (* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y))) (* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y))))
352.0ms
(cbrt (cbrt (* (/ (- x y) (hypot x y)) (/ (+ x y) (hypot x y)))))
342.0ms
(* (cbrt (* (/ (- x y) (hypot x y)) (+ x y))) (cbrt (* (/ (- x y) (hypot x y)) (+ x y))))

prune1.5s

Pruning

5 alts after pruning (3 fresh and 2 done)

Merged error: 0b

regimes78.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.2s

Algorithm
intervals
Results
845.0ms8000×body80valid
277.0ms8000×pre80true