Average Error: 19.9 → 5.1
Time: 15.2s
Precision: 64
Internal Precision: 128
\[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -1.3646408840354792 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -7.692497260825509 \cdot 10^{-162}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(y + x\right)}}\\ \mathbf{elif}\;y \le 1.867899514340098 \cdot 10^{-177}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{y + x}{\sqrt{x \cdot x + y \cdot y}}\\ \end{array}\]

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
Herbie5.1
\[\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. Split input into 4 regimes
  2. if y < -1.3646408840354792e+154

    1. Initial program 63.6

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Taylor expanded around 0 0

      \[\leadsto \color{blue}{-1}\]

    if -1.3646408840354792e+154 < y < -7.692497260825509e-162

    1. Initial program 0.0

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied clear-num0.0

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(x + y\right)}}}\]

    if -7.692497260825509e-162 < y < 1.867899514340098e-177

    1. Initial program 30.4

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Taylor expanded around inf 15.3

      \[\leadsto \color{blue}{1}\]

    if 1.867899514340098e-177 < y

    1. Initial program 2.7

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt2.7

      \[\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-frac3.3

      \[\leadsto \color{blue}{\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification5.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3646408840354792 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -7.692497260825509 \cdot 10^{-162}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot y}{\left(x - y\right) \cdot \left(y + x\right)}}\\ \mathbf{elif}\;y \le 1.867899514340098 \cdot 10^{-177}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{y + x}{\sqrt{x \cdot x + y \cdot y}}\\ \end{array}\]

Reproduce

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

sample60.0ms

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

simplify265.0ms

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

prune6.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 20.3b

localize24.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*
associate-/r/
associate-*r/
associate-*l/
div-exp
cbrt-undiv
pow1
associate-/l*
div-inv
cbrt-unprod
prod-exp
frac-2neg
sum-log
clear-num
+-commutative
Counts
2 → 42
Calls
2 calls:
Slowest
17.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
4.0ms
(+ (* x x) (* y y))

series81.0ms

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

simplify2.7s

Counts
31 → 48
Calls
31 calls:
Slowest
375.0ms
(* (- (pow x 3) (pow y 3)) (+ (pow x 3) (pow y 3)))
332.0ms
(* (- (* x x) (* y y)) (+ x y))
234.0ms
(* (- (* x x) (* y y)) (+ (pow x 3) (pow y 3)))
206.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))))
201.0ms
(- (log (* (- x y) (+ x y))) (log (+ (* x x) (* y y))))

prune416.0ms

Pruning

4 alts after pruning (4 fresh and 0 done)

Merged error: 0b

localize1.0ms

Local error

Found 0 expressions with local error:

rewrite0.0ms

Algorithm
rewrite-expression-head
Rules
Counts
0 → 0
Calls
0 calls:
Slowest

series0.0ms

Counts
0 → 0
Calls
0 calls:
Slowest

simplify0.0ms

Counts
0 → 0
Calls
0 calls:
Slowest

prune13.0ms

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 0b

localize15.0ms

Local error

Found 4 expressions with local error:

19.3b
(sqrt (+ (* x x) (* y y)))
19.3b
(sqrt (+ (* x x) (* y y)))
0.0b
(/ (+ x y) (sqrt (+ (* x x) (* y y))))
0.0b
(* (/ (- x y) (sqrt (+ (* x x) (* y y)))) (/ (+ x y) (sqrt (+ (* x x) (* y y)))))

rewrite23.0ms

Algorithm
rewrite-expression-head
Rules
54×times-frac
49×add-sqr-sqrt
47×add-cube-cbrt
47×*-un-lft-identity
36×sqrt-prod
24×associate-*l*
24×associate-*r*
18×add-exp-log
18×add-cbrt-cube
10×sqrt-div
flip-+
associate-/r/
flip3-+
associate-/r*
pow1
div-exp
cbrt-undiv
add-log-exp
cbrt-unprod
prod-exp
associate-/l*
div-inv
associate-/l/
pow1/2
rem-sqrt-square
*-commutative
associate-*r/
associate-*l/
pow-prod-down
frac-2neg
clear-num
frac-times
Counts
4 → 139
Calls
4 calls:
Slowest
12.0ms
(* (/ (- x y) (sqrt (+ (* x x) (* y y)))) (/ (+ x y) (sqrt (+ (* x x) (* y y)))))
5.0ms
(/ (+ x y) (sqrt (+ (* x x) (* y y))))
2.0ms
(sqrt (+ (* x x) (* y y)))
2.0ms
(sqrt (+ (* x x) (* y y)))

series167.0ms

Counts
4 → 12
Calls
4 calls:
Slowest
56.0ms
(* (/ (- x y) (sqrt (+ (* x x) (* y y)))) (/ (+ x y) (sqrt (+ (* x x) (* y y)))))
43.0ms
(/ (+ x y) (sqrt (+ (* x x) (* y y))))
37.0ms
(sqrt (+ (* x x) (* y y)))
30.0ms
(sqrt (+ (* x x) (* y y)))

simplify4.2s

Counts
134 → 151
Calls
134 calls:
Slowest
370.0ms
(+ (- (log (- x y)) (log (sqrt (+ (* x x) (* y y))))) (- (log (+ x y)) (log (sqrt (+ (* x x) (* y y))))))
292.0ms
(+ (- (log (- x y)) (log (sqrt (+ (* x x) (* y y))))) (log (/ (+ x y) (sqrt (+ (* x x) (* y y))))))
268.0ms
(* (/ (- x y) (sqrt (+ (* x x) (* y y)))) (/ (+ x y) (sqrt (+ (* x x) (* y y)))))
252.0ms
(/ (* (* (+ x y) (+ x y)) (+ x y)) (* (* (sqrt (+ (* x x) (* y y))) (sqrt (+ (* x x) (* y y)))) (sqrt (+ (* x x) (* y y)))))
245.0ms
(* (/ (* (* (- x y) (- x y)) (- x y)) (* (* (sqrt (+ (* x x) (* y y))) (sqrt (+ (* x x) (* y y)))) (sqrt (+ (* x x) (* y y))))) (/ (* (* (+ x y) (+ x y)) (+ x y)) (* (* (sqrt (+ (* x x) (* y y))) (sqrt (+ (* x x) (* y y)))) (sqrt (+ (* x x) (* y y))))))

prune1.9s

Pruning

4 alts after pruning (2 fresh and 2 done)

Merged error: 0b

localize7.0ms

Local error

Found 3 expressions with local error:

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

rewrite19.0ms

Algorithm
rewrite-expression-head
Rules
17×associate-/r/
16×associate-/r*
14×add-exp-log
flip-+
add-cbrt-cube
flip3-+
frac-times
add-cube-cbrt
*-un-lft-identity
add-sqr-sqrt
flip--
flip3--
times-frac
add-log-exp
associate-*r/
associate-*l/
div-exp
pow1
associate-/l*
div-inv
rec-exp
associate-/l/
prod-exp
frac-2neg
clear-num
cbrt-undiv
inv-pow
pow-flip
cbrt-unprod
sum-log
+-commutative
Counts
3 → 73
Calls
3 calls:
Slowest
12.0ms
(/ (+ (* x x) (* y y)) (* (- x y) (+ x y)))
4.0ms
(/ 1 (/ (+ (* x x) (* y y)) (* (- x y) (+ x y))))
2.0ms
(+ (* x x) (* y y))

series102.0ms

Counts
3 → 9
Calls
3 calls:
Slowest
42.0ms
(/ (+ (* x x) (* y y)) (* (- x y) (+ x y)))
38.0ms
(/ 1 (/ (+ (* x x) (* y y)) (* (- x y) (+ x y))))
21.0ms
(+ (* x x) (* y y))

simplify2.4s

Counts
50 → 82
Calls
50 calls:
Slowest
291.0ms
(/ (* (* (+ (* x x) (* y y)) (+ (* x x) (* y y))) (+ (* x x) (* y y))) (* (* (* (- x y) (+ x y)) (* (- x y) (+ x y))) (* (- x y) (+ x y))))
256.0ms
(/ (* (* (+ (* x x) (* y y)) (+ (* x x) (* y y))) (+ (* x x) (* y y))) (* (* (* (- x y) (- x y)) (- x y)) (* (* (+ x y) (+ x y)) (+ x y))))
157.0ms
(/ 1 (* (- x y) (+ x y)))
148.0ms
(sqrt (/ (+ (* x x) (* y y)) (* (- x y) (+ x y))))
146.0ms
(* (+ x y) (+ (* x x) (- (* y y) (* x y))))

prune731.0ms

Pruning

4 alts after pruning (1 fresh and 3 done)

Merged error: 0b

regimes90.0ms

Accuracy

77.3% (4.7b remaining)

Error of 5.1b against oracle of 0.4b and baseline of 21.3b

bsearch150.0ms

end0.0ms

sample1.3s

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