?

Average Accuracy: 68.1% → 100.0%
Time: 8.8s
Precision: binary64
Cost: 13632

?

\[\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} \]
\[\frac{\frac{x - y}{\mathsf{hypot}\left(y, x\right)}}{\frac{\mathsf{hypot}\left(y, x\right)}{x + y}} \]
(FPCore (x y) :precision binary64 (/ (* (- x y) (+ x y)) (+ (* x x) (* y y))))
(FPCore (x y)
 :precision binary64
 (/ (/ (- x y) (hypot y x)) (/ (hypot y x) (+ x y))))
double code(double x, double y) {
	return ((x - y) * (x + y)) / ((x * x) + (y * y));
}
double code(double x, double y) {
	return ((x - y) / hypot(y, x)) / (hypot(y, x) / (x + y));
}
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 ((x - y) / Math.hypot(y, x)) / (Math.hypot(y, x) / (x + y));
}
def code(x, y):
	return ((x - y) * (x + y)) / ((x * x) + (y * y))
def code(x, y):
	return ((x - y) / math.hypot(y, x)) / (math.hypot(y, x) / (x + y))
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(Float64(Float64(x - y) / hypot(y, x)) / Float64(hypot(y, x) / Float64(x + y)))
end
function tmp = code(x, y)
	tmp = ((x - y) * (x + y)) / ((x * x) + (y * y));
end
function tmp = code(x, y)
	tmp = ((x - y) / hypot(y, x)) / (hypot(y, x) / (x + y));
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[(N[(N[(x - y), $MachinePrecision] / N[Sqrt[y ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[y ^ 2 + x ^ 2], $MachinePrecision] / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}
\frac{\frac{x - y}{\mathsf{hypot}\left(y, x\right)}}{\frac{\mathsf{hypot}\left(y, x\right)}{x + y}}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original68.1%
Target99.9%
Herbie100.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 68.1%

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

    \[\leadsto \color{blue}{\left(x - y\right) \cdot \frac{x + y}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
    Proof

    [Start]68.1

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

    associate-*r/ [<=]67.6

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

    +-commutative [=>]67.6

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

    fma-def [=>]67.6

    \[ \left(x - y\right) \cdot \frac{x + y}{\color{blue}{\mathsf{fma}\left(y, y, x \cdot x\right)}} \]
  3. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\frac{\frac{x - y}{\mathsf{hypot}\left(y, x\right)}}{\frac{\mathsf{hypot}\left(y, x\right)}{x + y}}} \]
  4. Final simplification100.0%

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

Alternatives

Alternative 1
Accuracy92.5%
Cost1357
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \cdot 10^{+154}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -1.55 \cdot 10^{-162} \lor \neg \left(y \leq 6.6 \cdot 10^{-193}\right):\\ \;\;\;\;\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{y \cdot -2}{x} \cdot \frac{y}{x}\\ \end{array} \]
Alternative 2
Accuracy82.6%
Cost969
\[\begin{array}{l} \mathbf{if}\;y \leq -2.4 \cdot 10^{-135} \lor \neg \left(y \leq 6.6 \cdot 10^{-106}\right):\\ \;\;\;\;-1 + \frac{x}{y} \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{y \cdot -2}{x} \cdot \frac{y}{x}\\ \end{array} \]
Alternative 3
Accuracy82.7%
Cost968
\[\begin{array}{l} \mathbf{if}\;y \leq -3.2 \cdot 10^{-136}:\\ \;\;\;\;-1 + 2 \cdot \frac{\frac{x}{y}}{\frac{y}{x}}\\ \mathbf{elif}\;y \leq 1.3 \cdot 10^{-105}:\\ \;\;\;\;1 + \frac{y \cdot -2}{x} \cdot \frac{y}{x}\\ \mathbf{else}:\\ \;\;\;\;-1 + \frac{x}{y} \cdot \frac{x}{y}\\ \end{array} \]
Alternative 4
Accuracy82.6%
Cost841
\[\begin{array}{l} \mathbf{if}\;y \leq -1.75 \cdot 10^{-181} \lor \neg \left(y \leq 9.2 \cdot 10^{-115}\right):\\ \;\;\;\;-1 + \frac{x}{y} \cdot \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 5
Accuracy81.8%
Cost328
\[\begin{array}{l} \mathbf{if}\;y \leq -2.4 \cdot 10^{-181}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 1.25 \cdot 10^{-105}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 6
Accuracy67.0%
Cost64
\[-1 \]

Error

Reproduce?

herbie shell --seed 2023129 
(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))))