?

Average Accuracy: 67.5% → 99.9%
Time: 16.4s
Precision: binary64
Cost: 14144

?

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

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original67.5%
Target99.9%
Herbie99.9%
\[\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 67.5%

    \[\frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y} \]
  2. Applied egg-rr99.9%

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

    [Start]67.5

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

    add-sqr-sqrt [=>]67.5

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

    times-frac [=>]67.3

    \[ \color{blue}{\frac{x - y}{\sqrt{x \cdot x + y \cdot y}} \cdot \frac{x + y}{\sqrt{x \cdot x + y \cdot y}}} \]

    hypot-def [=>]67.4

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

    hypot-def [=>]99.9

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

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

    [Start]99.9

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

    associate-*r/ [=>]100.0

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

    associate-/l* [=>]100.0

    \[ \color{blue}{\frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}}} \]
  4. Applied egg-rr66.7%

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

    [Start]100.0

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

    flip-+ [=>]67.2

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

    associate-/r/ [=>]67.0

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

    sub-neg [=>]67.0

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

    distribute-lft-in [=>]66.7

    \[ \frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\color{blue}{\frac{\mathsf{hypot}\left(x, y\right)}{x \cdot x - y \cdot y} \cdot x + \frac{\mathsf{hypot}\left(x, y\right)}{x \cdot x - y \cdot y} \cdot \left(-y\right)}} \]
  5. Simplified99.9%

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

    [Start]66.7

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

    distribute-lft-out [=>]67.0

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

    sub-neg [<=]67.0

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

    *-commutative [<=]67.0

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

    associate-*r/ [=>]67.5

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

    associate-/l* [=>]67.2

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

    difference-of-squares [=>]67.2

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

    associate-*r/ [<=]99.9

    \[ \frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\frac{x - y}{\color{blue}{\left(x + y\right) \cdot \frac{x - y}{\mathsf{hypot}\left(x, y\right)}}}} \]
  6. Final simplification99.9%

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

Alternatives

Alternative 1
Accuracy99.9%
Cost13632
\[\frac{x - y}{\mathsf{hypot}\left(x, y\right)} \cdot \frac{x + y}{\mathsf{hypot}\left(x, y\right)} \]
Alternative 2
Accuracy100.0%
Cost13632
\[\frac{\frac{x - y}{\mathsf{hypot}\left(x, y\right)}}{\frac{\mathsf{hypot}\left(x, y\right)}{x + y}} \]
Alternative 3
Accuracy93.0%
Cost2116
\[\begin{array}{l} t_0 := \frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ t_1 := \frac{x}{y} \cdot \frac{x}{y}\\ \mathbf{if}\;t_0 \leq 2:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1 + \left(t_1 + -1\right)\\ \end{array} \]
Alternative 4
Accuracy92.5%
Cost1988
\[\begin{array}{l} t_0 := \frac{\left(x - y\right) \cdot \left(x + y\right)}{x \cdot x + y \cdot y}\\ \mathbf{if}\;t_0 \leq 2:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 5
Accuracy82.5%
Cost1232
\[\begin{array}{l} \mathbf{if}\;y \leq -4.7 \cdot 10^{-108}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -7.6 \cdot 10^{-170}:\\ \;\;\;\;1 - \frac{y}{x} \cdot \frac{y}{x}\\ \mathbf{elif}\;y \leq -3.1 \cdot 10^{-196}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 10^{-169}:\\ \;\;\;\;1 + \frac{\frac{y}{\frac{x}{y}}}{x} \cdot -2\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 6
Accuracy82.3%
Cost1105
\[\begin{array}{l} \mathbf{if}\;y \leq -8.2 \cdot 10^{-106}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -1.35 \cdot 10^{-169} \lor \neg \left(y \leq -3.1 \cdot 10^{-196}\right) \land y \leq 1.3 \cdot 10^{-169}:\\ \;\;\;\;1 - \frac{y}{x} \cdot \frac{y}{x}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 7
Accuracy81.8%
Cost848
\[\begin{array}{l} \mathbf{if}\;y \leq -4.3 \cdot 10^{-108}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -8 \cdot 10^{-170}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq -7.5 \cdot 10^{-197}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 1.22 \cdot 10^{-169}:\\ \;\;\;\;\frac{x - y}{x}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 8
Accuracy81.8%
Cost592
\[\begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{-107}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -7.6 \cdot 10^{-170}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq -1.3 \cdot 10^{-196}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 6.5 \cdot 10^{-170}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 9
Accuracy66.4%
Cost64
\[-1 \]

Error

Reproduce?

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