Average Error: 20.6 → 5.2
Time: 2.0s
Precision: binary64
\[\]
\[\]
\[\]
double code(double x, double y) {
	return ((double) (((double) (((double) (x - y)) * ((double) (x + y)))) / ((double) (((double) (x * x)) + ((double) (y * y))))));
}
double code(double x, double y) {
	double VAR;
	if ((y <= -1.353645889848894e+154)) {
		VAR = -1.0;
	} else {
		double VAR_1;
		if (((y <= -1.57795570958839e-162) || !(y <= 2.9392210219802266e-187))) {
			VAR_1 = ((double) (1.0 / ((double) (((double) (((double) (x * x)) + ((double) (y * y)))) / ((double) (((double) (x * x)) - ((double) (y * y))))))));
		} else {
			VAR_1 = 1.0;
		}
		VAR = VAR_1;
	}
	return VAR;
}

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.6
Target0.1
Herbie5.2
\[\]

Derivation

  1. Split input into 3 regimes
  2. if y < -1.353645889848894e154

    1. Initial program 64.0

      \[\]
    2. Taylor expanded around 0 0

      \[\leadsto \]

    if -1.353645889848894e154 < y < -1.57795570958839e-162 or 2.9392210219802266e-187 < y

    1. Initial program 1.5

      \[\]
    2. Using strategy rm
    3. Applied clear-num1.5

      \[\leadsto \]
    4. Simplified1.5

      \[\leadsto \]

    if -1.57795570958839e-162 < y < 2.9392210219802266e-187

    1. Initial program 30.3

      \[\]
    2. Taylor expanded around inf 14.9

      \[\leadsto \]
  3. Recombined 3 regimes into one program.
  4. Final simplification5.2

    \[\leadsto \]

Reproduce

herbie shell --seed 2020190 
(FPCore (x y)
  :name "Kahan p9 Example"
  :precision binary64
  :pre (and (< 0.0 x 1.0) (< y 1.0))

  :herbie-target
  (if (< 0.5 (fabs (/ x y)) 2.0) (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))) (- 1.0 (/ 2.0 (+ 1.0 (* (/ x y) (/ x y))))))

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