?

Average Error: 49.06% → 0.05%
Time: 13.8s
Precision: binary64
Cost: 26688

?

\[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
\[\begin{array}{l} t_0 := \mathsf{hypot}\left(x, y \cdot 2\right)\\ {\left(\frac{x}{t_0}\right)}^{2} - {\left(\frac{y \cdot 2}{t_0}\right)}^{2} \end{array} \]
(FPCore (x y)
 :precision binary64
 (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (hypot x (* y 2.0))))
   (- (pow (/ x t_0) 2.0) (pow (/ (* y 2.0) t_0) 2.0))))
double code(double x, double y) {
	return ((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y));
}
double code(double x, double y) {
	double t_0 = hypot(x, (y * 2.0));
	return pow((x / t_0), 2.0) - pow(((y * 2.0) / t_0), 2.0);
}
public static double code(double x, double y) {
	return ((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y));
}
public static double code(double x, double y) {
	double t_0 = Math.hypot(x, (y * 2.0));
	return Math.pow((x / t_0), 2.0) - Math.pow(((y * 2.0) / t_0), 2.0);
}
def code(x, y):
	return ((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y))
def code(x, y):
	t_0 = math.hypot(x, (y * 2.0))
	return math.pow((x / t_0), 2.0) - math.pow(((y * 2.0) / t_0), 2.0)
function code(x, y)
	return Float64(Float64(Float64(x * x) - Float64(Float64(y * 4.0) * y)) / Float64(Float64(x * x) + Float64(Float64(y * 4.0) * y)))
end
function code(x, y)
	t_0 = hypot(x, Float64(y * 2.0))
	return Float64((Float64(x / t_0) ^ 2.0) - (Float64(Float64(y * 2.0) / t_0) ^ 2.0))
end
function tmp = code(x, y)
	tmp = ((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y));
end
function tmp = code(x, y)
	t_0 = hypot(x, (y * 2.0));
	tmp = ((x / t_0) ^ 2.0) - (((y * 2.0) / t_0) ^ 2.0);
end
code[x_, y_] := N[(N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := Block[{t$95$0 = N[Sqrt[x ^ 2 + N[(y * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]}, N[(N[Power[N[(x / t$95$0), $MachinePrecision], 2.0], $MachinePrecision] - N[Power[N[(N[(y * 2.0), $MachinePrecision] / t$95$0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\begin{array}{l}
t_0 := \mathsf{hypot}\left(x, y \cdot 2\right)\\
{\left(\frac{x}{t_0}\right)}^{2} - {\left(\frac{y \cdot 2}{t_0}\right)}^{2}
\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original49.06%
Target48.6%
Herbie0.05%
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} < 0.9743233849626781:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot y\right) \cdot 4} - \frac{\left(y \cdot y\right) \cdot 4}{x \cdot x + \left(y \cdot y\right) \cdot 4}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{x}{\sqrt{x \cdot x + \left(y \cdot y\right) \cdot 4}}\right)}^{2} - \frac{\left(y \cdot y\right) \cdot 4}{x \cdot x + \left(y \cdot y\right) \cdot 4}\\ \end{array} \]

Derivation?

  1. Initial program 49.06

    \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
  2. Applied egg-rr48.7

    \[\leadsto \color{blue}{\frac{x \cdot x}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} + \left(-\frac{y \cdot 4}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} \cdot y\right)} \]
  3. Simplified48.63

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

    [Start]48.7

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

    sub-neg [<=]48.7

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

    associate-/l* [=>]48.06

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

    associate-*l/ [=>]48.63

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

    *-commutative [<=]48.63

    \[ \frac{x}{\frac{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}{x}} - \frac{\color{blue}{y \cdot \left(y \cdot 4\right)}}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} \]
  4. Applied egg-rr48.71

    \[\leadsto \frac{x}{\color{blue}{\frac{1}{x} \cdot \left(y \cdot \left(y \cdot 4\right)\right) + \frac{1}{x} \cdot \left(x \cdot x\right)}} - \frac{y \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)} \]
  5. Simplified48.71

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

    [Start]48.71

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

    distribute-lft-out [=>]48.71

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

    +-commutative [<=]48.71

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

    associate-*r* [=>]48.71

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

    \[\leadsto \color{blue}{{\left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2} + \left(-{\left(\frac{y \cdot 2}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2}\right)} \]
  7. Simplified0.05

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

    [Start]0.05

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

    unsub-neg [=>]0.05

    \[ \color{blue}{{\left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2} - {\left(\frac{y \cdot 2}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2}} \]
  8. Final simplification0.05

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

Alternatives

Alternative 1
Error19.97%
Cost8528
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ t_1 := \frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{t_0 + x \cdot x}\\ \mathbf{if}\;t_0 \leq 10^{-225}:\\ \;\;\;\;\mathsf{fma}\left(-8, \frac{y}{x} \cdot \frac{y}{x}, 1\right)\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{-163}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{-107}:\\ \;\;\;\;1 + \left(\frac{y \cdot -4}{\frac{x}{\frac{y}{x}}} - \frac{y}{x \cdot \frac{x \cdot 0.25}{y}}\right)\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+219}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{y} \cdot \frac{x}{y}, 0.5, -1\right)\\ \end{array} \]
Alternative 2
Error8.58%
Cost8528
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ t_1 := \mathsf{fma}\left(\frac{x}{y} \cdot \frac{x}{y}, 0.5, -1\right)\\ t_2 := \frac{x}{x + \frac{t_0}{x}} + \frac{y \cdot \left(y \cdot -4\right)}{\mathsf{fma}\left(x, x, t_0\right)}\\ \mathbf{if}\;y \leq -6.8 \cdot 10^{+153}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -6.8 \cdot 10^{-127}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 6 \cdot 10^{-163}:\\ \;\;\;\;1 + \left(\frac{y \cdot -4}{\frac{x}{\frac{y}{x}}} - \frac{y}{x \cdot \frac{x \cdot 0.25}{y}}\right)\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{+89}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error20.32%
Cost7364
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ t_1 := \frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{t_0 + x \cdot x}\\ \mathbf{if}\;t_0 \leq 10^{-225}:\\ \;\;\;\;\mathsf{fma}\left(-8, \frac{y}{x} \cdot \frac{y}{x}, 1\right)\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{-163}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{-107}:\\ \;\;\;\;1 + \left(\frac{y \cdot -4}{\frac{x}{\frac{y}{x}}} - \frac{y}{x \cdot \frac{x \cdot 0.25}{y}}\right)\\ \mathbf{elif}\;t_0 \leq 4 \cdot 10^{+221}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 4
Error20.47%
Cost2768
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ t_1 := \frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{t_0 + x \cdot x}\\ \mathbf{if}\;t_0 \leq 10^{-225}:\\ \;\;\;\;1 + \frac{y}{x} \cdot \frac{y \cdot -4}{x}\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{-163}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{-107}:\\ \;\;\;\;1\\ \mathbf{elif}\;t_0 \leq 4 \cdot 10^{+221}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 5
Error20.4%
Cost2768
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ t_1 := 1 + \left(\frac{y \cdot -4}{\frac{x}{\frac{y}{x}}} - \frac{y}{x \cdot \frac{x \cdot 0.25}{y}}\right)\\ t_2 := \frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{t_0 + x \cdot x}\\ \mathbf{if}\;t_0 \leq 10^{-225}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{-163}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{-107}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 4 \cdot 10^{+221}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 6
Error25.87%
Cost1869
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;t_0 \leq 10^{-101} \lor \neg \left(t_0 \leq 4 \cdot 10^{-61}\right) \land t_0 \leq 1:\\ \;\;\;\;1 + \frac{y}{x} \cdot \frac{y \cdot -4}{x}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 7
Error25.85%
Cost1868
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ t_1 := 1 + \frac{y}{x} \cdot \frac{y \cdot -4}{x}\\ \mathbf{if}\;t_0 \leq 10^{-101}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 4 \cdot 10^{-61}:\\ \;\;\;\;\frac{y \cdot \left(y \cdot -4\right)}{t_0 + x \cdot x}\\ \mathbf{elif}\;t_0 \leq 1:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 8
Error26.08%
Cost328
\[\begin{array}{l} \mathbf{if}\;y \leq -4.6 \cdot 10^{-51}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 10^{-8}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 9
Error50.38%
Cost64
\[-1 \]

Error

Reproduce?

herbie shell --seed 2023088 
(FPCore (x y)
  :name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))) 0.9743233849626781) (- (/ (* x x) (+ (* x x) (* (* y y) 4.0))) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))) (- (pow (/ x (sqrt (+ (* x x) (* (* y y) 4.0)))) 2.0) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))))

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