?

Average Error: 31.9 → 13.6
Time: 31.1s
Precision: binary64
Cost: 4552

?

\[\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 := \left(y \cdot 4\right) \cdot y\\ t_2 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\ t_3 := 4 \cdot \left(y \cdot y\right)\\ \mathbf{if}\;y \leq -3.25 \cdot 10^{+153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -2.4 \cdot 10^{-19}:\\ \;\;\;\;\frac{1}{t_2} \cdot \left(\left(0 - \left(-1 - t_2 \cdot t_2\right)\right) - 1\right)\\ \mathbf{elif}\;y \leq -6.6 \cdot 10^{-49}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq -1.9 \cdot 10^{-107}:\\ \;\;\;\;\frac{x \cdot x - t_1}{x \cdot x + t_1}\\ \mathbf{elif}\;y \leq 9.5 \cdot 10^{-95}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 2.45 \cdot 10^{+86}:\\ \;\;\;\;\left(\frac{x \cdot x - t_3}{x \cdot x + t_3} + 1\right) + -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 (* (* y 4.0) y))
        (t_2 (/ (- (* x x) t_0) (+ (* x x) t_0)))
        (t_3 (* 4.0 (* y y))))
   (if (<= y -3.25e+153)
     -1.0
     (if (<= y -2.4e-19)
       (* (/ 1.0 t_2) (- (- 0.0 (- -1.0 (* t_2 t_2))) 1.0))
       (if (<= y -6.6e-49)
         1.0
         (if (<= y -1.9e-107)
           (/ (- (* x x) t_1) (+ (* x x) t_1))
           (if (<= y 9.5e-95)
             1.0
             (if (<= y 2.45e+86)
               (+ (+ (/ (- (* x x) t_3) (+ (* x x) t_3)) 1.0) -1.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 = y * (y * 4.0);
	double t_1 = (y * 4.0) * y;
	double t_2 = ((x * x) - t_0) / ((x * x) + t_0);
	double t_3 = 4.0 * (y * y);
	double tmp;
	if (y <= -3.25e+153) {
		tmp = -1.0;
	} else if (y <= -2.4e-19) {
		tmp = (1.0 / t_2) * ((0.0 - (-1.0 - (t_2 * t_2))) - 1.0);
	} else if (y <= -6.6e-49) {
		tmp = 1.0;
	} else if (y <= -1.9e-107) {
		tmp = ((x * x) - t_1) / ((x * x) + t_1);
	} else if (y <= 9.5e-95) {
		tmp = 1.0;
	} else if (y <= 2.45e+86) {
		tmp = ((((x * x) - t_3) / ((x * x) + t_3)) + 1.0) + -1.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) :: t_3
    real(8) :: tmp
    t_0 = y * (y * 4.0d0)
    t_1 = (y * 4.0d0) * y
    t_2 = ((x * x) - t_0) / ((x * x) + t_0)
    t_3 = 4.0d0 * (y * y)
    if (y <= (-3.25d+153)) then
        tmp = -1.0d0
    else if (y <= (-2.4d-19)) then
        tmp = (1.0d0 / t_2) * ((0.0d0 - ((-1.0d0) - (t_2 * t_2))) - 1.0d0)
    else if (y <= (-6.6d-49)) then
        tmp = 1.0d0
    else if (y <= (-1.9d-107)) then
        tmp = ((x * x) - t_1) / ((x * x) + t_1)
    else if (y <= 9.5d-95) then
        tmp = 1.0d0
    else if (y <= 2.45d+86) then
        tmp = ((((x * x) - t_3) / ((x * x) + t_3)) + 1.0d0) + (-1.0d0)
    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 = (y * 4.0) * y;
	double t_2 = ((x * x) - t_0) / ((x * x) + t_0);
	double t_3 = 4.0 * (y * y);
	double tmp;
	if (y <= -3.25e+153) {
		tmp = -1.0;
	} else if (y <= -2.4e-19) {
		tmp = (1.0 / t_2) * ((0.0 - (-1.0 - (t_2 * t_2))) - 1.0);
	} else if (y <= -6.6e-49) {
		tmp = 1.0;
	} else if (y <= -1.9e-107) {
		tmp = ((x * x) - t_1) / ((x * x) + t_1);
	} else if (y <= 9.5e-95) {
		tmp = 1.0;
	} else if (y <= 2.45e+86) {
		tmp = ((((x * x) - t_3) / ((x * x) + t_3)) + 1.0) + -1.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 = y * (y * 4.0)
	t_1 = (y * 4.0) * y
	t_2 = ((x * x) - t_0) / ((x * x) + t_0)
	t_3 = 4.0 * (y * y)
	tmp = 0
	if y <= -3.25e+153:
		tmp = -1.0
	elif y <= -2.4e-19:
		tmp = (1.0 / t_2) * ((0.0 - (-1.0 - (t_2 * t_2))) - 1.0)
	elif y <= -6.6e-49:
		tmp = 1.0
	elif y <= -1.9e-107:
		tmp = ((x * x) - t_1) / ((x * x) + t_1)
	elif y <= 9.5e-95:
		tmp = 1.0
	elif y <= 2.45e+86:
		tmp = ((((x * x) - t_3) / ((x * x) + t_3)) + 1.0) + -1.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(y * Float64(y * 4.0))
	t_1 = Float64(Float64(y * 4.0) * y)
	t_2 = Float64(Float64(Float64(x * x) - t_0) / Float64(Float64(x * x) + t_0))
	t_3 = Float64(4.0 * Float64(y * y))
	tmp = 0.0
	if (y <= -3.25e+153)
		tmp = -1.0;
	elseif (y <= -2.4e-19)
		tmp = Float64(Float64(1.0 / t_2) * Float64(Float64(0.0 - Float64(-1.0 - Float64(t_2 * t_2))) - 1.0));
	elseif (y <= -6.6e-49)
		tmp = 1.0;
	elseif (y <= -1.9e-107)
		tmp = Float64(Float64(Float64(x * x) - t_1) / Float64(Float64(x * x) + t_1));
	elseif (y <= 9.5e-95)
		tmp = 1.0;
	elseif (y <= 2.45e+86)
		tmp = Float64(Float64(Float64(Float64(Float64(x * x) - t_3) / Float64(Float64(x * x) + t_3)) + 1.0) + -1.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 = y * (y * 4.0);
	t_1 = (y * 4.0) * y;
	t_2 = ((x * x) - t_0) / ((x * x) + t_0);
	t_3 = 4.0 * (y * y);
	tmp = 0.0;
	if (y <= -3.25e+153)
		tmp = -1.0;
	elseif (y <= -2.4e-19)
		tmp = (1.0 / t_2) * ((0.0 - (-1.0 - (t_2 * t_2))) - 1.0);
	elseif (y <= -6.6e-49)
		tmp = 1.0;
	elseif (y <= -1.9e-107)
		tmp = ((x * x) - t_1) / ((x * x) + t_1);
	elseif (y <= 9.5e-95)
		tmp = 1.0;
	elseif (y <= 2.45e+86)
		tmp = ((((x * x) - t_3) / ((x * x) + t_3)) + 1.0) + -1.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[(y * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(x * x), $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(4.0 * N[(y * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -3.25e+153], -1.0, If[LessEqual[y, -2.4e-19], N[(N[(1.0 / t$95$2), $MachinePrecision] * N[(N[(0.0 - N[(-1.0 - N[(t$95$2 * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, -6.6e-49], 1.0, If[LessEqual[y, -1.9e-107], N[(N[(N[(x * x), $MachinePrecision] - t$95$1), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 9.5e-95], 1.0, If[LessEqual[y, 2.45e+86], N[(N[(N[(N[(N[(x * x), $MachinePrecision] - t$95$3), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + t$95$3), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] + -1.0), $MachinePrecision], -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 := \left(y \cdot 4\right) \cdot y\\
t_2 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\
t_3 := 4 \cdot \left(y \cdot y\right)\\
\mathbf{if}\;y \leq -3.25 \cdot 10^{+153}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \leq -2.4 \cdot 10^{-19}:\\
\;\;\;\;\frac{1}{t_2} \cdot \left(\left(0 - \left(-1 - t_2 \cdot t_2\right)\right) - 1\right)\\

\mathbf{elif}\;y \leq -6.6 \cdot 10^{-49}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq -1.9 \cdot 10^{-107}:\\
\;\;\;\;\frac{x \cdot x - t_1}{x \cdot x + t_1}\\

\mathbf{elif}\;y \leq 9.5 \cdot 10^{-95}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq 2.45 \cdot 10^{+86}:\\
\;\;\;\;\left(\frac{x \cdot x - t_3}{x \cdot x + t_3} + 1\right) + -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.5
Herbie13.6
\[\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 5 regimes
  2. if y < -3.24999999999999986e153 or 2.45e86 < y

    1. Initial program 54.6

      \[\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.0

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

    if -3.24999999999999986e153 < y < -2.40000000000000023e-19

    1. Initial program 17.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-rr17.8

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}} \cdot \left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)} \cdot \frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\right)} \]
    3. Applied egg-rr17.8

      \[\leadsto \frac{1}{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}} \cdot \color{blue}{\left(\left(0 - \left(-1 - \frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)} \cdot \frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\right)\right) - 1\right)} \]

    if -2.40000000000000023e-19 < y < -6.6e-49 or -1.9000000000000001e-107 < y < 9.49999999999999998e-95

    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 12.6

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

    if -6.6e-49 < y < -1.9000000000000001e-107

    1. Initial program 17.1

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

    if 9.49999999999999998e-95 < y < 2.45e86

    1. Initial program 16.6

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

      \[\leadsto \color{blue}{\left(0 - \left(-1 - \frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\right)\right) - 1} \]
    3. Applied egg-rr16.6

      \[\leadsto \color{blue}{\left(\frac{x \cdot x - 4 \cdot \left(y \cdot y\right)}{x \cdot x + 4 \cdot \left(y \cdot y\right)} + 1\right) + -1} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification13.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3.25 \cdot 10^{+153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -2.4 \cdot 10^{-19}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}} \cdot \left(\left(0 - \left(-1 - \frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)} \cdot \frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\right)\right) - 1\right)\\ \mathbf{elif}\;y \leq -6.6 \cdot 10^{-49}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq -1.9 \cdot 10^{-107}:\\ \;\;\;\;\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 9.5 \cdot 10^{-95}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 2.45 \cdot 10^{+86}:\\ \;\;\;\;\left(\frac{x \cdot x - 4 \cdot \left(y \cdot y\right)}{x \cdot x + 4 \cdot \left(y \cdot y\right)} + 1\right) + -1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]

Alternatives

Alternative 1
Error13.6
Cost2264
\[\begin{array}{l} t_0 := 4 \cdot \left(y \cdot y\right)\\ t_1 := \frac{x \cdot x - t_0}{x \cdot x + t_0}\\ t_2 := \left(y \cdot 4\right) \cdot y\\ \mathbf{if}\;y \leq -2.05 \cdot 10^{+153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -3.1 \cdot 10^{-19}:\\ \;\;\;\;\left(-1 + t_1\right) + 1\\ \mathbf{elif}\;y \leq -1.25 \cdot 10^{-50}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq -3.4 \cdot 10^{-106}:\\ \;\;\;\;\frac{x \cdot x - t_2}{x \cdot x + t_2}\\ \mathbf{elif}\;y \leq 1.1 \cdot 10^{-94}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 1.65 \cdot 10^{+86}:\\ \;\;\;\;\left(t_1 + 1\right) + -1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 2
Error13.5
Cost2008
\[\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.35 \cdot 10^{+153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -7.5 \cdot 10^{-19}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -2.4 \cdot 10^{-44}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq -1.9 \cdot 10^{-107}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.6 \cdot 10^{-94}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 3.35 \cdot 10^{+86}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 3
Error13.6
Cost2008
\[\begin{array}{l} t_0 := 4 \cdot \left(y \cdot y\right)\\ t_1 := \left(y \cdot 4\right) \cdot y\\ t_2 := \frac{x \cdot x - t_1}{x \cdot x + t_1}\\ \mathbf{if}\;y \leq -3.25 \cdot 10^{+153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -2.15 \cdot 10^{-18}:\\ \;\;\;\;\left(-1 + \frac{x \cdot x - t_0}{x \cdot x + t_0}\right) + 1\\ \mathbf{elif}\;y \leq -6.2 \cdot 10^{-44}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq -1.75 \cdot 10^{-107}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 1.65 \cdot 10^{-94}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 2.25 \cdot 10^{+86}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 4
Error17.2
Cost592
\[\begin{array}{l} \mathbf{if}\;y \leq -44000000000000:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -1.15 \cdot 10^{-58}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq -2.9 \cdot 10^{-105}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 5 \cdot 10^{+55}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 5
Error32.6
Cost64
\[-1 \]

Error

Reproduce?

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