Average Error: 20.0 → 5.2
Time: 15.4s
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.3362591618789198 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.2206913091651824 \cdot 10^{-159} \lor \neg \left(y \le 1.0395458390998354 \cdot 10^{-187}\right):\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;1\\ \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.1
Herbie5.2
\[\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.3362591618789198e+154

    1. Initial program 63.6

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Initial simplification63.6

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

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

    if -1.3362591618789198e+154 < y < -1.2206913091651824e-159 or 1.0395458390998354e-187 < y

    1. Initial program 1.5

      \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\]
    2. Initial simplification1.5

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

    if -1.2206913091651824e-159 < y < 1.0395458390998354e-187

    1. Initial program 30.2

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3362591618789198 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.2206913091651824 \cdot 10^{-159} \lor \neg \left(y \le 1.0395458390998354 \cdot 10^{-187}\right):\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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

start67.0ms

Algorithm
intervals

setup283.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 23.9b

localize23.0ms

Local error

Found 2 expressions with local error:

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

rewrite16.0ms

Algorithm
rewrite-expression-head
Counts
2 → 42
Calls

2 calls. Slowest were:

10.0ms
(/ (* (- x y) (+ y x)) (+ (* x x) (* y y)))
5.0ms
(+ (* x x) (* y y))

series80.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

55.0ms
(/ (* (- x y) (+ y x)) (+ (* x x) (* y y)))
25.0ms
(+ (* x x) (* y y))

simplify2.9s

Counts
31 → 48
Calls

31 calls. Slowest were:

618.0ms
(* (- (* x x) (* y y)) (+ y x))
324.0ms
(* (- (* x x) (* y y)) (+ (pow y 3) (pow x 3)))
292.0ms
(/ (* (* (* (- x y) (+ y x)) (* (- x y) (+ y x))) (* (- x y) (+ y x))) (* (* (+ (* x x) (* y y)) (+ (* x x) (* y y))) (+ (* x x) (* y y))))

prune449.0ms

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 0.8b

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:

prune5.0ms

Pruning

4 alts after pruning (2 fresh and 2 done)

Merged error: 0.8b

localize13.0ms

Local error

Found 3 expressions with local error:

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

rewrite37.0ms

Algorithm
rewrite-expression-head
Counts
3 → 123
Calls

3 calls. Slowest were:

18.0ms
(/ (+ (* x x) (* y y)) (+ y x))
11.0ms
(/ (- x y) (/ (+ (* x x) (* y y)) (+ y x)))
4.0ms
(+ (* x x) (* y y))

series127.0ms

Counts
3 → 9
Calls

3 calls. Slowest were:

60.0ms
(/ (- x y) (/ (+ (* x x) (* y y)) (+ y x)))
50.0ms
(/ (+ (* x x) (* y y)) (+ y x))
17.0ms
(+ (* x x) (* y y))

simplify6.9s

Counts
154 → 132
Calls

154 calls. Slowest were:

576.0ms
(/ (* (* (- x y) (- x y)) (- x y)) (* (* (/ (+ (* x x) (* y y)) (+ y x)) (/ (+ (* x x) (* y y)) (+ y x))) (/ (+ (* x x) (* y y)) (+ y x))))
361.0ms
(/ (* (cbrt (- x y)) (cbrt (- x y))) (/ 1 (* (cbrt (+ y x)) (cbrt (+ y x)))))
344.0ms
(/ (* (cbrt (- x y)) (cbrt (- x y))) (/ (+ (* x x) (* y y)) (+ (pow y 3) (pow x 3))))

prune1.3s

Pruning

4 alts after pruning (1 fresh and 3 done)

Merged error: 0.8b

localize1.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:

prune1.0ms

Pruning

4 alts after pruning (0 fresh and 4 done)

Merged error: 0.8b

regimes87.0ms

Accuracy

78% (4.6b remaining)

Error of 5.2b against oracle of 0.6b and baseline of 21.7b

bsearch163.0ms