Average Error: 31.8 → 14.2
Time: 4.1s
Precision: binary64
Cost: 1744
\[\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 := 1 + \frac{y \cdot -4}{x} \cdot \frac{y}{x}\\ t_1 := y \cdot \left(y \cdot 4\right)\\ t_2 := \frac{x \cdot x - t_1}{x \cdot x + t_1}\\ \mathbf{if}\;y \leq -3.2 \cdot 10^{+42}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -1.25 \cdot 10^{-75}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 2.45 \cdot 10^{-60}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 8 \cdot 10^{+47}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{+82}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-1\\ \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 (+ 1.0 (* (/ (* y -4.0) x) (/ y x))))
        (t_1 (* y (* y 4.0)))
        (t_2 (/ (- (* x x) t_1) (+ (* x x) t_1))))
   (if (<= y -3.2e+42)
     -1.0
     (if (<= y -1.25e-75)
       t_2
       (if (<= y 2.45e-60)
         t_0
         (if (<= y 8e+47) t_2 (if (<= y 4.5e+82) t_0 -1.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 = 1.0 + (((y * -4.0) / x) * (y / x));
	double t_1 = y * (y * 4.0);
	double t_2 = ((x * x) - t_1) / ((x * x) + t_1);
	double tmp;
	if (y <= -3.2e+42) {
		tmp = -1.0;
	} else if (y <= -1.25e-75) {
		tmp = t_2;
	} else if (y <= 2.45e-60) {
		tmp = t_0;
	} else if (y <= 8e+47) {
		tmp = t_2;
	} else if (y <= 4.5e+82) {
		tmp = t_0;
	} else {
		tmp = -1.0;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = ((x * x) - ((y * 4.0d0) * y)) / ((x * x) + ((y * 4.0d0) * y))
end function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = 1.0d0 + (((y * (-4.0d0)) / x) * (y / x))
    t_1 = y * (y * 4.0d0)
    t_2 = ((x * x) - t_1) / ((x * x) + t_1)
    if (y <= (-3.2d+42)) then
        tmp = -1.0d0
    else if (y <= (-1.25d-75)) then
        tmp = t_2
    else if (y <= 2.45d-60) then
        tmp = t_0
    else if (y <= 8d+47) then
        tmp = t_2
    else if (y <= 4.5d+82) then
        tmp = t_0
    else
        tmp = -1.0d0
    end if
    code = tmp
end function
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 = 1.0 + (((y * -4.0) / x) * (y / x));
	double t_1 = y * (y * 4.0);
	double t_2 = ((x * x) - t_1) / ((x * x) + t_1);
	double tmp;
	if (y <= -3.2e+42) {
		tmp = -1.0;
	} else if (y <= -1.25e-75) {
		tmp = t_2;
	} else if (y <= 2.45e-60) {
		tmp = t_0;
	} else if (y <= 8e+47) {
		tmp = t_2;
	} else if (y <= 4.5e+82) {
		tmp = t_0;
	} else {
		tmp = -1.0;
	}
	return tmp;
}
def code(x, y):
	return ((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y))
def code(x, y):
	t_0 = 1.0 + (((y * -4.0) / x) * (y / x))
	t_1 = y * (y * 4.0)
	t_2 = ((x * x) - t_1) / ((x * x) + t_1)
	tmp = 0
	if y <= -3.2e+42:
		tmp = -1.0
	elif y <= -1.25e-75:
		tmp = t_2
	elif y <= 2.45e-60:
		tmp = t_0
	elif y <= 8e+47:
		tmp = t_2
	elif y <= 4.5e+82:
		tmp = t_0
	else:
		tmp = -1.0
	return tmp
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 = Float64(1.0 + Float64(Float64(Float64(y * -4.0) / x) * Float64(y / x)))
	t_1 = Float64(y * Float64(y * 4.0))
	t_2 = Float64(Float64(Float64(x * x) - t_1) / Float64(Float64(x * x) + t_1))
	tmp = 0.0
	if (y <= -3.2e+42)
		tmp = -1.0;
	elseif (y <= -1.25e-75)
		tmp = t_2;
	elseif (y <= 2.45e-60)
		tmp = t_0;
	elseif (y <= 8e+47)
		tmp = t_2;
	elseif (y <= 4.5e+82)
		tmp = t_0;
	else
		tmp = -1.0;
	end
	return tmp
end
function tmp = code(x, y)
	tmp = ((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y));
end
function tmp_2 = code(x, y)
	t_0 = 1.0 + (((y * -4.0) / x) * (y / x));
	t_1 = y * (y * 4.0);
	t_2 = ((x * x) - t_1) / ((x * x) + t_1);
	tmp = 0.0;
	if (y <= -3.2e+42)
		tmp = -1.0;
	elseif (y <= -1.25e-75)
		tmp = t_2;
	elseif (y <= 2.45e-60)
		tmp = t_0;
	elseif (y <= 8e+47)
		tmp = t_2;
	elseif (y <= 4.5e+82)
		tmp = t_0;
	else
		tmp = -1.0;
	end
	tmp_2 = tmp;
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[(1.0 + N[(N[(N[(y * -4.0), $MachinePrecision] / x), $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(x * x), $MachinePrecision] - t$95$1), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -3.2e+42], -1.0, If[LessEqual[y, -1.25e-75], t$95$2, If[LessEqual[y, 2.45e-60], t$95$0, If[LessEqual[y, 8e+47], t$95$2, If[LessEqual[y, 4.5e+82], t$95$0, -1.0]]]]]]]]
\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 := 1 + \frac{y \cdot -4}{x} \cdot \frac{y}{x}\\
t_1 := y \cdot \left(y \cdot 4\right)\\
t_2 := \frac{x \cdot x - t_1}{x \cdot x + t_1}\\
\mathbf{if}\;y \leq -3.2 \cdot 10^{+42}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \leq -1.25 \cdot 10^{-75}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;y \leq 2.45 \cdot 10^{-60}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 8 \cdot 10^{+47}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;y \leq 4.5 \cdot 10^{+82}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;-1\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original31.8
Target31.6
Herbie14.2
\[\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. Split input into 3 regimes
  2. if y < -3.20000000000000002e42 or 4.4999999999999997e82 < y

    1. Initial program 47.2

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Taylor expanded in x around 0 13.4

      \[\leadsto \color{blue}{-1} \]

    if -3.20000000000000002e42 < y < -1.24999999999999995e-75 or 2.44999999999999994e-60 < y < 8.0000000000000004e47

    1. Initial program 15.4

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

    if -1.24999999999999995e-75 < y < 2.44999999999999994e-60 or 8.0000000000000004e47 < y < 4.4999999999999997e82

    1. Initial program 24.3

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    2. Taylor expanded in x around inf 34.6

      \[\leadsto \frac{\color{blue}{{x}^{2}}}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    3. Simplified34.6

      \[\leadsto \frac{\color{blue}{x \cdot x}}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
      Proof
      (/.f64 (*.f64 x x) (+.f64 (*.f64 x x) (*.f64 (*.f64 y 4) y))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= unpow2_binary64 (pow.f64 x 2)) (+.f64 (*.f64 x x) (*.f64 (*.f64 y 4) y))): 0 points increase in error, 2 points decrease in error
    4. Taylor expanded in x around inf 19.0

      \[\leadsto \color{blue}{1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}}} \]
    5. Simplified19.0

      \[\leadsto \color{blue}{1 + \frac{-4 \cdot \left(y \cdot y\right)}{x \cdot x}} \]
      Proof
      (+.f64 1 (/.f64 (*.f64 -4 (*.f64 y y)) (*.f64 x x))): 0 points increase in error, 0 points decrease in error
      (+.f64 1 (/.f64 (*.f64 -4 (Rewrite<= unpow2_binary64 (pow.f64 y 2))) (*.f64 x x))): 4 points increase in error, 0 points decrease in error
      (+.f64 1 (/.f64 (*.f64 -4 (pow.f64 y 2)) (Rewrite<= unpow2_binary64 (pow.f64 x 2)))): 0 points increase in error, 4 points decrease in error
      (+.f64 1 (Rewrite<= associate-*r/_binary64 (*.f64 -4 (/.f64 (pow.f64 y 2) (pow.f64 x 2))))): 0 points increase in error, 0 points decrease in error
    6. Applied egg-rr14.4

      \[\leadsto 1 + \color{blue}{\frac{-4 \cdot y}{x} \cdot \frac{y}{x}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification14.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.2 \cdot 10^{+42}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -1.25 \cdot 10^{-75}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;y \leq 2.45 \cdot 10^{-60}:\\ \;\;\;\;1 + \frac{y \cdot -4}{x} \cdot \frac{y}{x}\\ \mathbf{elif}\;y \leq 8 \cdot 10^{+47}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{+82}:\\ \;\;\;\;1 + \frac{y \cdot -4}{x} \cdot \frac{y}{x}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]

Alternatives

Alternative 1
Error18.1
Cost2646
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;t_0 \leq 2 \cdot 10^{-154} \lor \neg \left(t_0 \leq 50\right) \land \left(t_0 \leq 10^{+111} \lor \neg \left(t_0 \leq 10^{+130}\right) \land t_0 \leq 10^{+155}\right):\\ \;\;\;\;1 + \frac{y \cdot -4}{x} \cdot \frac{y}{x}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 2
Error17.7
Cost592
\[\begin{array}{l} \mathbf{if}\;y \leq -3.9 \cdot 10^{-70}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 7.8 \cdot 10^{-60}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 18000:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 4.2 \cdot 10^{+82}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 3
Error31.8
Cost64
\[-1 \]

Error

Reproduce

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