Average Error: 20.0 → 5.4
Time: 27.1s
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.3396022331219297 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.0705598109984798 \cdot 10^{-175}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\\ \mathbf{elif}\;y \le -2.4722449832826208 \cdot 10^{-216}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 1.7274153437829284 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\\ \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

Original20.0
Target0.0
Herbie5.4
\[\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 3 regimes
  2. if y < -1.3396022331219297e+154 or -1.0705598109984798e-175 < y < -2.4722449832826208e-216

    1. Initial program 56.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-sqrt56.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 associate-/r*56.9

      \[\leadsto \color{blue}{\frac{\frac{\left(x - y\right) \cdot \left(x + y\right)}{\sqrt{x \cdot x + y \cdot y}}}{\sqrt{x \cdot x + y \cdot y}}}\]
    5. Taylor expanded around 0 8.1

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

    if -1.3396022331219297e+154 < y < -1.0705598109984798e-175 or 1.7274153437829284e-162 < y

    1. Initial program 0.7

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]

    if -2.4722449832826208e-216 < y < 1.7274153437829284e-162

    1. Initial program 28.4

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

      \[\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 associate-/r*28.4

      \[\leadsto \color{blue}{\frac{\frac{\left(x - y\right) \cdot \left(x + y\right)}{\sqrt{x \cdot x + y \cdot y}}}{\sqrt{x \cdot x + y \cdot y}}}\]
    5. Taylor expanded around -inf 12.7

      \[\leadsto \color{blue}{1}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification5.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3396022331219297 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.0705598109984798 \cdot 10^{-175}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\\ \mathbf{elif}\;y \le -2.4722449832826208 \cdot 10^{-216}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 1.7274153437829284 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\\ \end{array}\]

Reproduce

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

sample58.0ms

Algorithm
intervals

simplify255.0ms

Counts
1 → 1
Calls

1 calls. Slowest were:

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

prune5.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 21.3b

localize18.0ms

Local error

Found 2 expressions with local error:

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

rewrite13.0ms

Algorithm
rewrite-expression-head
Counts
2 → 42
Calls

2 calls. Slowest were:

8.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
4.0ms
(+ (* x x) (* y y))

series83.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

53.0ms
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))
30.0ms
(+ (* x x) (* y y))

simplify2.6s

Counts
31 → 48
Calls

31 calls. Slowest were:

401.0ms
(* (- (* x x) (* y y)) (+ x y))
316.0ms
(* (- (pow x 3) (pow y 3)) (+ (pow x 3) (pow y 3)))
253.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))))

prune421.0ms

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 0.6b

localize18.0ms

Local error

Found 4 expressions with local error:

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

rewrite29.0ms

Algorithm
rewrite-expression-head
Counts
4 → 174
Calls

4 calls. Slowest were:

12.0ms
(/ (/ (* (- x y) (+ x y)) (sqrt (+ (* x x) (* y y)))) (sqrt (+ (* x x) (* y y))))
11.0ms
(/ (* (- x y) (+ x y)) (sqrt (+ (* x x) (* y y))))
2.0ms
(sqrt (+ (* x x) (* y y)))

series165.0ms

Counts
4 → 12
Calls

4 calls. Slowest were:

54.0ms
(/ (/ (* (- x y) (+ x y)) (sqrt (+ (* x x) (* y y)))) (sqrt (+ (* x x) (* y y))))
46.0ms
(/ (* (- x y) (+ x y)) (sqrt (+ (* x x) (* y y))))
34.0ms
(sqrt (+ (* x x) (* y y)))
32.0ms
(sqrt (+ (* x x) (* y y)))

simplify18.8s

Counts
227 → 186
Calls

227 calls. Slowest were:

411.0ms
(* (- (* x x) (* y y)) (+ x y))
358.0ms
(/ (* (- x y) (+ x y)) (sqrt (- (* (* x x) (* x x)) (* (* y y) (* y y)))))
353.0ms
(* (- (pow x 3) (pow y 3)) (+ (pow x 3) (pow y 3)))

prune2.2s

Pruning

4 alts after pruning (2 fresh and 2 done)

Merged error: 0.6b

localize0.0ms

Local error

Found 0 expressions with local error:

rewrite0.0ms

Algorithm
rewrite-expression-head
Counts
0 → 0
Calls

0 calls. Slowest were:

series0.0ms

Counts
0 → 0
Calls

0 calls. Slowest were:

simplify0.0ms

Counts
0 → 0
Calls

0 calls. Slowest were:

prune2.0ms

Pruning

4 alts after pruning (1 fresh and 3 done)

Merged error: 0.6b

localize0.0ms

Local error

Found 0 expressions with local error:

rewrite0.0ms

Algorithm
rewrite-expression-head
Counts
0 → 0
Calls

0 calls. Slowest were:

series0.0ms

Counts
0 → 0
Calls

0 calls. Slowest were:

simplify0.0ms

Counts
0 → 0
Calls

0 calls. Slowest were:

prune0.0ms

Pruning

4 alts after pruning (0 fresh and 4 done)

Merged error: 0.6b

regimes144.0ms

Accuracy

74.8% (4.9b remaining)

Error of 5.4b against oracle of 0.4b and baseline of 20.0b

bsearch156.0ms

end0.0ms

sample1.5s

Algorithm
intervals