?

Average Error: 31.9 → 12.4
Time: 2.9s
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 := \left(y \cdot 4\right) \cdot y\\ t_1 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\ \mathbf{if}\;y \leq -2.6 \cdot 10^{+120}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -4.1 \cdot 10^{-97}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.02 \cdot 10^{-143}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 2.7 \cdot 10^{+132}:\\ \;\;\;\;t_1\\ \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 (* (* y 4.0) y)) (t_1 (/ (- (* x x) t_0) (+ (* x x) t_0))))
   (if (<= y -2.6e+120)
     -1.0
     (if (<= y -4.1e-97)
       t_1
       (if (<= y 1.02e-143) 1.0 (if (<= y 2.7e+132) t_1 -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 = (y * 4.0) * y;
	double t_1 = ((x * x) - t_0) / ((x * x) + t_0);
	double tmp;
	if (y <= -2.6e+120) {
		tmp = -1.0;
	} else if (y <= -4.1e-97) {
		tmp = t_1;
	} else if (y <= 1.02e-143) {
		tmp = 1.0;
	} else if (y <= 2.7e+132) {
		tmp = t_1;
	} 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) :: tmp
    t_0 = (y * 4.0d0) * y
    t_1 = ((x * x) - t_0) / ((x * x) + t_0)
    if (y <= (-2.6d+120)) then
        tmp = -1.0d0
    else if (y <= (-4.1d-97)) then
        tmp = t_1
    else if (y <= 1.02d-143) then
        tmp = 1.0d0
    else if (y <= 2.7d+132) then
        tmp = t_1
    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 = (y * 4.0) * y;
	double t_1 = ((x * x) - t_0) / ((x * x) + t_0);
	double tmp;
	if (y <= -2.6e+120) {
		tmp = -1.0;
	} else if (y <= -4.1e-97) {
		tmp = t_1;
	} else if (y <= 1.02e-143) {
		tmp = 1.0;
	} else if (y <= 2.7e+132) {
		tmp = t_1;
	} 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 = (y * 4.0) * y
	t_1 = ((x * x) - t_0) / ((x * x) + t_0)
	tmp = 0
	if y <= -2.6e+120:
		tmp = -1.0
	elif y <= -4.1e-97:
		tmp = t_1
	elif y <= 1.02e-143:
		tmp = 1.0
	elif y <= 2.7e+132:
		tmp = t_1
	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(y * 4.0) * y)
	t_1 = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0))
	tmp = 0.0
	if (y <= -2.6e+120)
		tmp = -1.0;
	elseif (y <= -4.1e-97)
		tmp = t_1;
	elseif (y <= 1.02e-143)
		tmp = 1.0;
	elseif (y <= 2.7e+132)
		tmp = t_1;
	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 = (y * 4.0) * y;
	t_1 = ((x * x) - t_0) / ((x * x) + t_0);
	tmp = 0.0;
	if (y <= -2.6e+120)
		tmp = -1.0;
	elseif (y <= -4.1e-97)
		tmp = t_1;
	elseif (y <= 1.02e-143)
		tmp = 1.0;
	elseif (y <= 2.7e+132)
		tmp = t_1;
	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[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.6e+120], -1.0, If[LessEqual[y, -4.1e-97], t$95$1, If[LessEqual[y, 1.02e-143], 1.0, If[LessEqual[y, 2.7e+132], t$95$1, -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 := \left(y \cdot 4\right) \cdot y\\
t_1 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\
\mathbf{if}\;y \leq -2.6 \cdot 10^{+120}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \leq -4.1 \cdot 10^{-97}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;y \leq 1.02 \cdot 10^{-143}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq 2.7 \cdot 10^{+132}:\\
\;\;\;\;t_1\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original31.9
Target31.6
Herbie12.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.5999999999999999e120 or 2.7e132 < y

    1. Initial program 57.5

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

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

    if -2.5999999999999999e120 < y < -4.09999999999999993e-97 or 1.02e-143 < y < 2.7e132

    1. Initial program 16.1

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

    if -4.09999999999999993e-97 < y < 1.02e-143

    1. Initial program 28.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 10.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.6 \cdot 10^{+120}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -4.1 \cdot 10^{-97}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;y \leq 1.02 \cdot 10^{-143}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 2.7 \cdot 10^{+132}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]

Alternatives

Alternative 1
Error16.1
Cost328
\[\begin{array}{l} \mathbf{if}\;y \leq -2.95 \cdot 10^{-64}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 1.35 \cdot 10^{-31}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 2
Error31.5
Cost64
\[-1 \]

Error

Reproduce?

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