Average Error: 31.7 → 13.4
Time: 2.7s
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 := \frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{if}\;y \leq -2.5050968686813432 \cdot 10^{+75}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -3.4679379870731976 \cdot 10^{-62}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 5.492403835733428 \cdot 10^{-173}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 4.5516736627057783 \cdot 10^{+101}:\\ \;\;\;\;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 (/ (+ (* x x) (* y (* y -4.0))) (+ (* x x) (* y (* y 4.0))))))
   (if (<= y -2.5050968686813432e+75)
     -1.0
     (if (<= y -3.4679379870731976e-62)
       t_0
       (if (<= y 5.492403835733428e-173)
         1.0
         (if (<= y 4.5516736627057783e+101) 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 = ((x * x) + (y * (y * -4.0))) / ((x * x) + (y * (y * 4.0)));
	double tmp;
	if (y <= -2.5050968686813432e+75) {
		tmp = -1.0;
	} else if (y <= -3.4679379870731976e-62) {
		tmp = t_0;
	} else if (y <= 5.492403835733428e-173) {
		tmp = 1.0;
	} else if (y <= 4.5516736627057783e+101) {
		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) :: tmp
    t_0 = ((x * x) + (y * (y * (-4.0d0)))) / ((x * x) + (y * (y * 4.0d0)))
    if (y <= (-2.5050968686813432d+75)) then
        tmp = -1.0d0
    else if (y <= (-3.4679379870731976d-62)) then
        tmp = t_0
    else if (y <= 5.492403835733428d-173) then
        tmp = 1.0d0
    else if (y <= 4.5516736627057783d+101) 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 = ((x * x) + (y * (y * -4.0))) / ((x * x) + (y * (y * 4.0)));
	double tmp;
	if (y <= -2.5050968686813432e+75) {
		tmp = -1.0;
	} else if (y <= -3.4679379870731976e-62) {
		tmp = t_0;
	} else if (y <= 5.492403835733428e-173) {
		tmp = 1.0;
	} else if (y <= 4.5516736627057783e+101) {
		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 = ((x * x) + (y * (y * -4.0))) / ((x * x) + (y * (y * 4.0)))
	tmp = 0
	if y <= -2.5050968686813432e+75:
		tmp = -1.0
	elif y <= -3.4679379870731976e-62:
		tmp = t_0
	elif y <= 5.492403835733428e-173:
		tmp = 1.0
	elif y <= 4.5516736627057783e+101:
		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(Float64(Float64(x * x) + Float64(y * Float64(y * -4.0))) / Float64(Float64(x * x) + Float64(y * Float64(y * 4.0))))
	tmp = 0.0
	if (y <= -2.5050968686813432e+75)
		tmp = -1.0;
	elseif (y <= -3.4679379870731976e-62)
		tmp = t_0;
	elseif (y <= 5.492403835733428e-173)
		tmp = 1.0;
	elseif (y <= 4.5516736627057783e+101)
		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 = ((x * x) + (y * (y * -4.0))) / ((x * x) + (y * (y * 4.0)));
	tmp = 0.0;
	if (y <= -2.5050968686813432e+75)
		tmp = -1.0;
	elseif (y <= -3.4679379870731976e-62)
		tmp = t_0;
	elseif (y <= 5.492403835733428e-173)
		tmp = 1.0;
	elseif (y <= 4.5516736627057783e+101)
		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[(N[(N[(x * x), $MachinePrecision] + N[(y * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.5050968686813432e+75], -1.0, If[LessEqual[y, -3.4679379870731976e-62], t$95$0, If[LessEqual[y, 5.492403835733428e-173], 1.0, If[LessEqual[y, 4.5516736627057783e+101], 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 := \frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\
\mathbf{if}\;y \leq -2.5050968686813432 \cdot 10^{+75}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \leq -3.4679379870731976 \cdot 10^{-62}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 5.492403835733428 \cdot 10^{-173}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq 4.5516736627057783 \cdot 10^{+101}:\\
\;\;\;\;t_0\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original31.7
Target31.4
Herbie13.4
\[\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 < -2.5050968686813432e75 or 4.55167366270577833e101 < y

    1. Initial program 50.7

      \[\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 11.7

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

    if -2.5050968686813432e75 < y < -3.4679379870731976e-62 or 5.49240383573342834e-173 < y < 4.55167366270577833e101

    1. Initial program 16.9

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

    if -3.4679379870731976e-62 < y < 5.49240383573342834e-173

    1. Initial program 26.1

      \[\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 11.4

      \[\leadsto \color{blue}{1} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification13.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.5050968686813432 \cdot 10^{+75}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -3.4679379870731976 \cdot 10^{-62}:\\ \;\;\;\;\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 5.492403835733428 \cdot 10^{-173}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 4.5516736627057783 \cdot 10^{+101}:\\ \;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]

Alternatives

Alternative 1
Error16.7
Cost592
\[\begin{array}{l} \mathbf{if}\;y \leq -4912416.627133531:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 4.730849519192564 \cdot 10^{-89}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 1.616598462713126 \cdot 10^{-62}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 1.2644690275844588 \cdot 10^{-13}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 2
Error31.8
Cost64
\[-1 \]

Error

Reproduce

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