Average Error: 20.1 → 5.5
Time: 13.8s
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.3665520024672976 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -5.309205025385931 \cdot 10^{-161}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\\ \mathbf{elif}\;y \le 2.9020243613441586 \cdot 10^{-202}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 2.5202678793515666 \cdot 10^{-174}:\\ \;\;\;\;-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.1
Target0.0
Herbie5.5
\[\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.3665520024672976e+154 or 2.9020243613441586e-202 < y < 2.5202678793515666e-174

    1. Initial program 58.1

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

      \[\leadsto \frac{\left(x - y\right) \cdot \left(y + x\right)}{x \cdot x + y \cdot y}\]
    3. Using strategy rm
    4. Applied associate-/l*56.8

      \[\leadsto \color{blue}{\frac{x - y}{\frac{x \cdot x + y \cdot y}{y + x}}}\]
    5. Taylor expanded around 0 6.1

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

    if -1.3665520024672976e+154 < y < -5.309205025385931e-161 or 2.5202678793515666e-174 < y

    1. Initial program 0.8

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

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

    if -5.309205025385931e-161 < y < 2.9020243613441586e-202

    1. Initial program 29.5

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

      \[\leadsto \frac{\left(x - y\right) \cdot \left(y + x\right)}{x \cdot x + y \cdot y}\]
    3. Using strategy rm
    4. Applied associate-/l*30.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.3665520024672976 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -5.309205025385931 \cdot 10^{-161}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(y + x\right)}{y \cdot y + x \cdot x}\\ \mathbf{elif}\;y \le 2.9020243613441586 \cdot 10^{-202}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 2.5202678793515666 \cdot 10^{-174}:\\ \;\;\;\;-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 2018360 
(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: 11.1s)Debug log

start73.0ms

Algorithm
intervals

setup246.0ms

Pruning

1 alts after pruning (1 fresh and 0 done)

Merged error: 19.5b

localize23.0ms

Local error

Found 1 expressions with local error:

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

rewrite9.0ms

Algorithm
rewrite-expression-head
Counts
1 → 31
Calls

1 calls. Slowest were:

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

series32.0ms

Counts
1 → 3
Calls

1 calls. Slowest were:

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

simplify2.7s

Counts
27 → 34
Calls

27 calls. Slowest were:

406.0ms
(+ (* (* x x) (* x x)) (- (* (* y y) (* y y)) (* (* x x) (* y y))))
350.0ms
(* (- (pow x 3) (pow y 3)) (+ (pow y 3) (pow x 3)))
288.0ms
(* (- (* x x) (* y y)) (+ (pow y 3) (pow x 3)))

prune343.0ms

Pruning

4 alts after pruning (3 fresh and 1 done)

Merged error: 0.2b

localize6.0ms

Local error

Found 2 expressions with local error:

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

rewrite16.0ms

Algorithm
rewrite-expression-head
Counts
2 → 112
Calls

2 calls. Slowest were:

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

series70.0ms

Counts
2 → 6
Calls

2 calls. Slowest were:

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

simplify6.1s

Counts
150 → 118
Calls

150 calls. Slowest were:

478.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))))
375.0ms
(/ (* (cbrt (- x y)) (cbrt (- x y))) (/ (* (cbrt (+ (* x x) (* y y))) (cbrt (+ (* x x) (* y y)))) (* (cbrt (+ y x)) (cbrt (+ y x)))))
290.0ms
(/ (* (cbrt (- x y)) (cbrt (- x y))) (/ (+ (* x x) (* y y)) (+ (pow y 3) (pow x 3))))

prune1.2s

Pruning

4 alts after pruning (2 fresh and 2 done)

Merged error: 0.2b

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:

prune4.0ms

Pruning

4 alts after pruning (1 fresh and 3 done)

Merged error: 0.2b

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.2b

regimes165.0ms

Accuracy

74% (5.1b remaining)

Error of 5.5b against oracle of 0.4b and baseline of 20.1b

bsearch208.0ms