Average Error: 31.8 → 0.1
Time: 16.5s
Precision: binary64
Cost: 27200
\[\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 + y\right)\\ {\left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2} + \frac{\left(y + y\right) \cdot \left(\frac{y}{t_0} \cdot -2\right)}{t_0} \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 y))))
   (+
    (pow (/ x (hypot x (* y 2.0))) 2.0)
    (/ (* (+ y y) (* (/ y t_0) -2.0)) t_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 + y));
	return pow((x / hypot(x, (y * 2.0))), 2.0) + (((y + y) * ((y / t_0) * -2.0)) / t_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 + y));
	return Math.pow((x / Math.hypot(x, (y * 2.0))), 2.0) + (((y + y) * ((y / t_0) * -2.0)) / t_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 + y))
	return math.pow((x / math.hypot(x, (y * 2.0))), 2.0) + (((y + y) * ((y / t_0) * -2.0)) / t_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 + y))
	return Float64((Float64(x / hypot(x, Float64(y * 2.0))) ^ 2.0) + Float64(Float64(Float64(y + y) * Float64(Float64(y / t_0) * -2.0)) / t_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 + y));
	tmp = ((x / hypot(x, (y * 2.0))) ^ 2.0) + (((y + y) * ((y / t_0) * -2.0)) / t_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 + y), $MachinePrecision] ^ 2], $MachinePrecision]}, N[(N[Power[N[(x / N[Sqrt[x ^ 2 + N[(y * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(N[(y + y), $MachinePrecision] * N[(N[(y / t$95$0), $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision] / t$95$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 + y\right)\\
{\left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2} + \frac{\left(y + y\right) \cdot \left(\frac{y}{t_0} \cdot -2\right)}{t_0}
\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original31.8
Target31.5
Herbie0.1
\[\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 31.8

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

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

    \[\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}} \]
  4. Applied egg-rr0.1

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

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

Alternatives

Alternative 1
Error0.1
Cost26688
\[\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} \]
Alternative 2
Error12.7
Cost21068
\[\begin{array}{l} t_0 := \mathsf{hypot}\left(x, y \cdot 2\right)\\ t_1 := {\left(\frac{x}{t_0}\right)}^{2}\\ t_2 := t_1 - \mathsf{fma}\left(\frac{x}{y} \cdot \frac{x}{y}, -0.25, 1\right)\\ t_3 := x \cdot x + y \cdot \left(y \cdot -4\right)\\ \mathbf{if}\;x \cdot x \leq 0:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \cdot x \leq 10^{-101}:\\ \;\;\;\;\frac{t_3}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \cdot x \leq 10^{-7}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+291}:\\ \;\;\;\;\frac{t_3}{{t_0}^{2}}\\ \mathbf{else}:\\ \;\;\;\;t_1 + \left(\frac{y}{x} \cdot \frac{y}{x}\right) \cdot -4\\ \end{array} \]
Alternative 3
Error12.7
Cost14928
\[\begin{array}{l} t_0 := x \cdot x + y \cdot \left(y \cdot -4\right)\\ t_1 := \mathsf{hypot}\left(x, y \cdot 2\right)\\ \mathbf{if}\;x \cdot x \leq 0:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{\frac{y}{x}}, \frac{0.5}{y}, -1\right)\\ \mathbf{elif}\;x \cdot x \leq 10^{-101}:\\ \;\;\;\;\frac{t_0}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \cdot x \leq 10^{-7}:\\ \;\;\;\;-1 + x \cdot \left(\frac{x}{y} \cdot \frac{0.5}{y}\right)\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+291}:\\ \;\;\;\;\frac{t_0}{{t_1}^{2}}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{x}{t_1}\right)}^{2} + \left(\frac{y}{x} \cdot \frac{y}{x}\right) \cdot -4\\ \end{array} \]
Alternative 4
Error12.7
Cost14800
\[\begin{array}{l} t_0 := x \cdot x + y \cdot \left(y \cdot -4\right)\\ \mathbf{if}\;x \cdot x \leq 0:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{\frac{y}{x}}, \frac{0.5}{y}, -1\right)\\ \mathbf{elif}\;x \cdot x \leq 10^{-101}:\\ \;\;\;\;\frac{t_0}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \cdot x \leq 10^{-7}:\\ \;\;\;\;-1 + x \cdot \left(\frac{x}{y} \cdot \frac{0.5}{y}\right)\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+291}:\\ \;\;\;\;\frac{t_0}{{\left(\mathsf{hypot}\left(x, y \cdot 2\right)\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;1 + y \cdot \left(-8 \cdot \frac{\frac{y}{x}}{x}\right)\\ \end{array} \]
Alternative 5
Error12.7
Cost7236
\[\begin{array}{l} t_0 := \frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{if}\;x \cdot x \leq 0:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{\frac{y}{x}}, \frac{0.5}{y}, -1\right)\\ \mathbf{elif}\;x \cdot x \leq 10^{-101}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \cdot x \leq 10^{-7}:\\ \;\;\;\;-1 + x \cdot \left(\frac{x}{y} \cdot \frac{0.5}{y}\right)\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+291}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;1 + y \cdot \left(-8 \cdot \frac{\frac{y}{x}}{x}\right)\\ \end{array} \]
Alternative 6
Error12.8
Cost2256
\[\begin{array}{l} t_0 := \frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ t_1 := -1 + x \cdot \left(\frac{x}{y} \cdot \frac{0.5}{y}\right)\\ \mathbf{if}\;x \cdot x \leq 0:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 10^{-101}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \cdot x \leq 10^{-7}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+291}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;1 + y \cdot \left(-8 \cdot \frac{\frac{y}{x}}{x}\right)\\ \end{array} \]
Alternative 7
Error16.3
Cost1496
\[\begin{array}{l} t_0 := 1 + y \cdot \left(-8 \cdot \frac{\frac{y}{x}}{x}\right)\\ \mathbf{if}\;y \leq -6.101664348091817 \cdot 10^{+62}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -2.389624658687178 \cdot 10^{+36}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq -2.417153638885234:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 7.1456437241885864 \cdot 10^{-130}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 6.40699827568335 \cdot 10^{-104}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 674288824.1166409:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 8
Error16.1
Cost1496
\[\begin{array}{l} t_0 := -1 + x \cdot \left(\frac{x}{y} \cdot \frac{0.5}{y}\right)\\ t_1 := 1 + y \cdot \left(-8 \cdot \frac{\frac{y}{x}}{x}\right)\\ \mathbf{if}\;y \leq -6.101664348091817 \cdot 10^{+62}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -2.389624658687178 \cdot 10^{+36}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq -2.417153638885234:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 7.1456437241885864 \cdot 10^{-130}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 6.40699827568335 \cdot 10^{-104}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 674288824.1166409:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error17.3
Cost856
\[\begin{array}{l} \mathbf{if}\;y \leq -6.101664348091817 \cdot 10^{+62}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -2.389624658687178 \cdot 10^{+36}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq -1148218555260301800:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 1.4804286115285545 \cdot 10^{-156}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 6.40699827568335 \cdot 10^{-104}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 674288824.1166409:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 10
Error31.6
Cost64
\[1 \]

Error

Reproduce

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