Average Error: 32.0 → 13.9
Time: 2.7s
Precision: binary64
Cost: 2768
\[\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 := 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^{-309}:\\ \;\;\;\;1\\ \mathbf{elif}\;t_0 \leq 1.6 \cdot 10^{+190}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 3.25 \cdot 10^{+240}:\\ \;\;\;\;1\\ \mathbf{elif}\;t_0 \leq 2.9 \cdot 10^{+273}:\\ \;\;\;\;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 (* y 4.0)))
        (t_1 (/ (+ (* x x) (* y (* y -4.0))) (+ t_0 (* x x)))))
   (if (<= t_0 1e-309)
     1.0
     (if (<= t_0 1.6e+190)
       t_1
       (if (<= t_0 3.25e+240) 1.0 (if (<= t_0 2.9e+273) 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 * (y * 4.0);
	double t_1 = ((x * x) + (y * (y * -4.0))) / (t_0 + (x * x));
	double tmp;
	if (t_0 <= 1e-309) {
		tmp = 1.0;
	} else if (t_0 <= 1.6e+190) {
		tmp = t_1;
	} else if (t_0 <= 3.25e+240) {
		tmp = 1.0;
	} else if (t_0 <= 2.9e+273) {
		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 * (y * 4.0d0)
    t_1 = ((x * x) + (y * (y * (-4.0d0)))) / (t_0 + (x * x))
    if (t_0 <= 1d-309) then
        tmp = 1.0d0
    else if (t_0 <= 1.6d+190) then
        tmp = t_1
    else if (t_0 <= 3.25d+240) then
        tmp = 1.0d0
    else if (t_0 <= 2.9d+273) 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 * (y * 4.0);
	double t_1 = ((x * x) + (y * (y * -4.0))) / (t_0 + (x * x));
	double tmp;
	if (t_0 <= 1e-309) {
		tmp = 1.0;
	} else if (t_0 <= 1.6e+190) {
		tmp = t_1;
	} else if (t_0 <= 3.25e+240) {
		tmp = 1.0;
	} else if (t_0 <= 2.9e+273) {
		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 * (y * 4.0)
	t_1 = ((x * x) + (y * (y * -4.0))) / (t_0 + (x * x))
	tmp = 0
	if t_0 <= 1e-309:
		tmp = 1.0
	elif t_0 <= 1.6e+190:
		tmp = t_1
	elif t_0 <= 3.25e+240:
		tmp = 1.0
	elif t_0 <= 2.9e+273:
		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(y * Float64(y * 4.0))
	t_1 = Float64(Float64(Float64(x * x) + Float64(y * Float64(y * -4.0))) / Float64(t_0 + Float64(x * x)))
	tmp = 0.0
	if (t_0 <= 1e-309)
		tmp = 1.0;
	elseif (t_0 <= 1.6e+190)
		tmp = t_1;
	elseif (t_0 <= 3.25e+240)
		tmp = 1.0;
	elseif (t_0 <= 2.9e+273)
		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 * (y * 4.0);
	t_1 = ((x * x) + (y * (y * -4.0))) / (t_0 + (x * x));
	tmp = 0.0;
	if (t_0 <= 1e-309)
		tmp = 1.0;
	elseif (t_0 <= 1.6e+190)
		tmp = t_1;
	elseif (t_0 <= 3.25e+240)
		tmp = 1.0;
	elseif (t_0 <= 2.9e+273)
		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[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(x * x), $MachinePrecision] + N[(y * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1e-309], 1.0, If[LessEqual[t$95$0, 1.6e+190], t$95$1, If[LessEqual[t$95$0, 3.25e+240], 1.0, If[LessEqual[t$95$0, 2.9e+273], 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 := 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^{-309}:\\
\;\;\;\;1\\

\mathbf{elif}\;t_0 \leq 1.6 \cdot 10^{+190}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq 3.25 \cdot 10^{+240}:\\
\;\;\;\;1\\

\mathbf{elif}\;t_0 \leq 2.9 \cdot 10^{+273}:\\
\;\;\;\;t_1\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original32.0
Target31.6
Herbie13.9
\[\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 (*.f64 (*.f64 y 4) y) < 1.000000000000002e-309 or 1.6e190 < (*.f64 (*.f64 y 4) y) < 3.25000000000000009e240

    1. Initial program 28.0

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

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

    if 1.000000000000002e-309 < (*.f64 (*.f64 y 4) y) < 1.6e190 or 3.25000000000000009e240 < (*.f64 (*.f64 y 4) y) < 2.8999999999999998e273

    1. Initial program 17.2

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

    if 2.8999999999999998e273 < (*.f64 (*.f64 y 4) y)

    1. Initial program 59.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 9.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot \left(y \cdot 4\right) \leq 10^{-309}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 1.6 \cdot 10^{+190}:\\ \;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{y \cdot \left(y \cdot 4\right) + x \cdot x}\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 3.25 \cdot 10^{+240}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 2.9 \cdot 10^{+273}:\\ \;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{y \cdot \left(y \cdot 4\right) + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]

Alternatives

Alternative 1
Error17.0
Cost328
\[\begin{array}{l} \mathbf{if}\;y \leq -1.42 \cdot 10^{-78}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 50000000:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 2
Error32.4
Cost64
\[-1 \]

Error

Reproduce

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