Average Error: 19.9 → 0.0
Time: 13.2s
Precision: binary64
Cost: 20096
\[\left(0 < x \land x < 1\right) \land y < 1\]
\[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
\[{\left(\frac{\mathsf{hypot}\left(x, y\right)}{\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \left(x + y\right)}\right)}^{-1} \]
(FPCore (x y) :precision binary64 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))
(FPCore (x y)
 :precision binary64
 (pow (/ (hypot x y) (* (/ (- x y) (hypot x y)) (+ x y))) -1.0))
double code(double x, double y) {
	return ((x - y) * (x + y)) / ((x * x) + (y * y));
}
double code(double x, double y) {
	return pow((hypot(x, y) / (((x - y) / hypot(x, y)) * (x + y))), -1.0);
}
public static double code(double x, double y) {
	return ((x - y) * (x + y)) / ((x * x) + (y * y));
}
public static double code(double x, double y) {
	return Math.pow((Math.hypot(x, y) / (((x - y) / Math.hypot(x, y)) * (x + y))), -1.0);
}
def code(x, y):
	return ((x - y) * (x + y)) / ((x * x) + (y * y))
def code(x, y):
	return math.pow((math.hypot(x, y) / (((x - y) / math.hypot(x, y)) * (x + y))), -1.0)
function code(x, y)
	return Float64(Float64(Float64(x - y) * Float64(x + y)) / Float64(Float64(x * x) + Float64(y * y)))
end
function code(x, y)
	return Float64(hypot(x, y) / Float64(Float64(Float64(x - y) / hypot(x, y)) * Float64(x + y))) ^ -1.0
end
function tmp = code(x, y)
	tmp = ((x - y) * (x + y)) / ((x * x) + (y * y));
end
function tmp = code(x, y)
	tmp = (hypot(x, y) / (((x - y) / hypot(x, y)) * (x + y))) ^ -1.0;
end
code[x_, y_] := N[(N[(N[(x - y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := N[Power[N[(N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision] / N[(N[(N[(x - y), $MachinePrecision] / N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
{\left(\frac{\mathsf{hypot}\left(x, y\right)}{\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \left(x + y\right)}\right)}^{-1}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original19.9
Target0.0
Herbie0.0
\[\begin{array}{l} \mathbf{if}\;0.5 < \left|\frac{x}{y}\right| \land \left|\frac{x}{y}\right| < 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. Initial program 19.9

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

    \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(x, x, y \cdot y\right)}} \]
    Proof
    (*.f64 (-.f64 x y) (/.f64 (+.f64 x y) (fma.f64 x x (*.f64 y y)))): 0 points increase in error, 0 points decrease in error
    (*.f64 (-.f64 x y) (/.f64 (+.f64 x y) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x x) (*.f64 y y))))): 0 points increase in error, 0 points decrease in error
    (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 (-.f64 x y) (+.f64 x y)) (+.f64 (*.f64 x x) (*.f64 y y)))): 53 points increase in error, 45 points decrease in error
  3. Applied egg-rr0.2

    \[\leadsto \left(x - y\right) \cdot \color{blue}{\left(\frac{1}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)}\right)} \]
  4. Applied egg-rr0.0

    \[\leadsto \color{blue}{\frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}} \]
  5. Applied egg-rr0.0

    \[\leadsto \color{blue}{{\left(\frac{\mathsf{hypot}\left(x, y\right)}{\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \left(x + y\right)}\right)}^{-1}} \]
  6. Final simplification0.0

    \[\leadsto {\left(\frac{\mathsf{hypot}\left(x, y\right)}{\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \left(x + y\right)}\right)}^{-1} \]

Alternatives

Alternative 1
Error0.0
Cost13632
\[\frac{x + y}{\mathsf{hypot}\left(x, y\right) \cdot \frac{\mathsf{hypot}\left(x, y\right)}{x - y}} \]
Alternative 2
Error4.8
Cost7372
\[\begin{array}{l} t_0 := \left(x - y\right) \cdot \left(x + y\right)\\ \mathbf{if}\;y \leq -0.006349111880085442:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -5.632794257281874 \cdot 10^{-161}:\\ \;\;\;\;\frac{t_0}{\frac{x \cdot x}{x - y} \cdot \frac{x \cdot x}{x + y} - \frac{y \cdot y}{x - y} \cdot \frac{y \cdot y}{x + y}}\\ \mathbf{elif}\;y \leq 3.817406963700337 \cdot 10^{-184}:\\ \;\;\;\;\mathsf{fma}\left(-2, \frac{y}{x} \cdot \frac{y}{x}, 1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{x \cdot x + y \cdot y}\\ \end{array} \]
Alternative 3
Error4.8
Cost2760
\[\begin{array}{l} t_0 := \left(x - y\right) \cdot \left(x + y\right)\\ \mathbf{if}\;y \leq -0.006349111880085442:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -5.632794257281874 \cdot 10^{-161}:\\ \;\;\;\;\frac{t_0}{\frac{x \cdot x}{x - y} \cdot \frac{x \cdot x}{x + y} - \frac{y \cdot y}{x - y} \cdot \frac{y \cdot y}{x + y}}\\ \mathbf{elif}\;y \leq 3.817406963700337 \cdot 10^{-184}:\\ \;\;\;\;\left(1 + \frac{y}{x} \cdot \left(-1 - \frac{y}{x}\right)\right) + \frac{y}{x} \cdot \left(1 - \frac{y}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{x \cdot x + y \cdot y}\\ \end{array} \]
Alternative 4
Error4.8
Cost1740
\[\begin{array}{l} t_0 := \frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{if}\;y \leq -1.1588890312746165 \cdot 10^{+155}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -5.632794257281874 \cdot 10^{-161}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 3.817406963700337 \cdot 10^{-184}:\\ \;\;\;\;\left(1 + \frac{y}{x} \cdot \left(-1 - \frac{y}{x}\right)\right) + \frac{y}{x} \cdot \left(1 - \frac{y}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error4.9
Cost1356
\[\begin{array}{l} t_0 := \frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{if}\;y \leq -1.1588890312746165 \cdot 10^{+155}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -5.632794257281874 \cdot 10^{-161}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.1743190104364287 \cdot 10^{-189}:\\ \;\;\;\;1 + y \cdot \frac{-2}{\frac{x}{\frac{y}{x}}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error11.2
Cost968
\[\begin{array}{l} t_0 := -1 + \frac{\frac{2}{y}}{\frac{\frac{y}{x}}{x}}\\ \mathbf{if}\;y \leq -5.632794257281874 \cdot 10^{-161}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 4.18747732620905 \cdot 10^{-105}:\\ \;\;\;\;1 - \frac{y}{x \cdot \frac{x}{y}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error11.2
Cost968
\[\begin{array}{l} \mathbf{if}\;y \leq -5.632794257281874 \cdot 10^{-161}:\\ \;\;\;\;-1 + \frac{\frac{2}{y}}{\frac{\frac{y}{x}}{x}}\\ \mathbf{elif}\;y \leq 4.18747732620905 \cdot 10^{-105}:\\ \;\;\;\;1 - \frac{y}{x \cdot \frac{x}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{y \cdot y}\\ \end{array} \]
Alternative 8
Error11.1
Cost968
\[\begin{array}{l} \mathbf{if}\;y \leq -5.632794257281874 \cdot 10^{-161}:\\ \;\;\;\;-1 + \frac{\frac{2}{y}}{\frac{\frac{y}{x}}{x}}\\ \mathbf{elif}\;y \leq 4.18747732620905 \cdot 10^{-105}:\\ \;\;\;\;1 + y \cdot \frac{-2}{\frac{x}{\frac{y}{x}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{y \cdot y}\\ \end{array} \]
Alternative 9
Error11.5
Cost840
\[\begin{array}{l} \mathbf{if}\;y \leq -5.632794257281874 \cdot 10^{-161}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 4.18747732620905 \cdot 10^{-105}:\\ \;\;\;\;1 - \frac{y}{x \cdot \frac{x}{y}}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 10
Error11.7
Cost328
\[\begin{array}{l} \mathbf{if}\;y \leq -5.632794257281874 \cdot 10^{-161}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 4.18747732620905 \cdot 10^{-105}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 11
Error21.6
Cost64
\[-1 \]

Error

Reproduce

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

  :herbie-target
  (if (and (< 0.5 (fabs (/ x y))) (< (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))))