Average Error: 20.2 → 6.0
Time: 22.3s
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.3266524044529779 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -6.45209558740925 \cdot 10^{-161}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\\ \mathbf{elif}\;y \le 1.8045349817621806 \cdot 10^{-222}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 2.0891795127861158 \cdot 10^{-165}:\\ \;\;\;\;-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.2
Target0.1
Herbie6.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. Split input into 3 regimes
  2. if y < -1.3266524044529779e+154 or 1.8045349817621806e-222 < y < 2.0891795127861158e-165

    1. Initial program 55.1

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

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

    if -1.3266524044529779e+154 < y < -6.45209558740925e-161 or 2.0891795127861158e-165 < y

    1. Initial program 0.4

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

    if -6.45209558740925e-161 < y < 1.8045349817621806e-222

    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 associate-/l*28.9

      \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{x + y}}}\]
    4. Taylor expanded around inf 13.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3266524044529779 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -6.45209558740925 \cdot 10^{-161}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\\ \mathbf{elif}\;y \le 1.8045349817621806 \cdot 10^{-222}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 2.0891795127861158 \cdot 10^{-165}:\\ \;\;\;\;-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 2018362 
(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: 19.8s)Debug log

start38.0ms

Algorithm
intervals

setup195.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 20.5b

localize18.0ms

Local error

Found 1 expressions with local error:

20.5b
(/ (* (- x y) (+ x y)) (+ (* x x) (* y y)))

rewrite9.0ms

Algorithm
rewrite-expression-head
Counts
1 → 31
Calls

1 calls. Slowest were:

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

series43.0ms

Counts
1 → 3
Calls

1 calls. Slowest were:

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

simplify2.9s

Counts
27 → 34
Calls

27 calls. Slowest were:

479.0ms
(* (- (* x x) (* y y)) (+ x y))
351.0ms
(* (- (pow x 3) (pow y 3)) (+ (pow x 3) (pow y 3)))
300.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))))

prune267.0ms

Pruning

5 alts after pruning (4 fresh and 1 done)

Merged error: 0.9b

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:

prune6.0ms

Pruning

5 alts after pruning (3 fresh and 2 done)

Merged error: 0.9b

localize5.0ms

Local error

Found 2 expressions with local error:

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

rewrite18.0ms

Algorithm
rewrite-expression-head
Counts
2 → 112
Calls

2 calls. Slowest were:

11.0ms
(/ (+ (* x x) (* y y)) (+ x y))
6.0ms
(/ (- x y) (/ (+ (* x x) (* y y)) (+ x y)))

series76.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

44.0ms
(/ (+ (* x x) (* y y)) (+ x y))
33.0ms
(/ (- x y) (/ (+ (* x x) (* y y)) (+ x y)))

simplify7.3s

Counts
150 → 118
Calls

150 calls. Slowest were:

537.0ms
(/ (* (* (- x y) (- x y)) (- x y)) (* (* (/ (+ (* x x) (* y y)) (+ x y)) (/ (+ (* x x) (* y y)) (+ x y))) (/ (+ (* x x) (* y y)) (+ x y))))
399.0ms
(/ (* (cbrt (- x y)) (cbrt (- x y))) (/ (* (cbrt (+ (* x x) (* y y))) (cbrt (+ (* x x) (* y y)))) (* (cbrt (+ x y)) (cbrt (+ x y)))))
374.0ms
(/ (sqrt (- x y)) (/ (+ (* x x) (* y y)) (- (* x x) (* y y))))

prune935.0ms

Pruning

4 alts after pruning (2 fresh and 2 done)

Merged error: 0.9b

localize6.0ms

Local error

Found 3 expressions with local error:

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

rewrite29.0ms

Algorithm
rewrite-expression-head
Counts
3 → 178
Calls

3 calls. Slowest were:

11.0ms
(/ (/ (+ (* x x) (* y y)) (+ x y)) (- x y))
9.0ms
(/ (+ (* x x) (* y y)) (+ x y))
4.0ms
(/ 1 (/ (/ (+ (* x x) (* y y)) (+ x y)) (- x y)))

series156.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

56.0ms
(/ 1 (/ (/ (+ (* x x) (* y y)) (+ x y)) (- x y)))
55.0ms
(/ (/ (+ (* x x) (* y y)) (+ x y)) (- x y))
45.0ms
(/ (+ (* x x) (* y y)) (+ x y))

simplify5.6s

Counts
205 → 187
Calls

205 calls. Slowest were:

366.0ms
(/ (* (* (/ (+ (* x x) (* y y)) (+ x y)) (/ (+ (* x x) (* y y)) (+ x y))) (/ (+ (* x x) (* y y)) (+ x y))) (* (* (- x y) (- x y)) (- x y)))
259.0ms
(/ (/ (* (cbrt (+ (* x x) (* y y))) (cbrt (+ (* x x) (* y y)))) (* (cbrt (+ x y)) (cbrt (+ x y)))) (* (cbrt (- x y)) (cbrt (- x y))))
202.0ms
(/ (/ (+ (* x x) (* y y)) (- (* x x) (* y y))) (sqrt (- x y)))

prune1.9s

Pruning

4 alts after pruning (1 fresh and 3 done)

Merged error: 0.9b

regimes139.0ms

Accuracy

73.6% (5.5b remaining)

Error of 6.0b against oracle of 0.5b and baseline of 21.3b

bsearch149.0ms