?

Average Accuracy: 50.1% → 79.6%
Time: 14.7s
Precision: binary64
Cost: 7044

?

\[\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 -3 \cdot 10^{+109}:\\ \;\;\;\;{\left(\frac{x}{y}\right)}^{2} \cdot 0.5 + -1\\ \mathbf{elif}\;y \leq -2 \cdot 10^{-73}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 7.8 \cdot 10^{-47}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 2.2 \cdot 10^{+71}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-1 + \frac{x}{y} \cdot \frac{x}{y \cdot 4}\\ \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 -3e+109)
     (+ (* (pow (/ x y) 2.0) 0.5) -1.0)
     (if (<= y -2e-73)
       t_0
       (if (<= y 7.8e-47)
         1.0
         (if (<= y 2.2e+71) t_0 (+ -1.0 (* (/ x y) (/ x (* y 4.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 <= -3e+109) {
		tmp = (pow((x / y), 2.0) * 0.5) + -1.0;
	} else if (y <= -2e-73) {
		tmp = t_0;
	} else if (y <= 7.8e-47) {
		tmp = 1.0;
	} else if (y <= 2.2e+71) {
		tmp = t_0;
	} else {
		tmp = -1.0 + ((x / y) * (x / (y * 4.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 <= (-3d+109)) then
        tmp = (((x / y) ** 2.0d0) * 0.5d0) + (-1.0d0)
    else if (y <= (-2d-73)) then
        tmp = t_0
    else if (y <= 7.8d-47) then
        tmp = 1.0d0
    else if (y <= 2.2d+71) then
        tmp = t_0
    else
        tmp = (-1.0d0) + ((x / y) * (x / (y * 4.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 <= -3e+109) {
		tmp = (Math.pow((x / y), 2.0) * 0.5) + -1.0;
	} else if (y <= -2e-73) {
		tmp = t_0;
	} else if (y <= 7.8e-47) {
		tmp = 1.0;
	} else if (y <= 2.2e+71) {
		tmp = t_0;
	} else {
		tmp = -1.0 + ((x / y) * (x / (y * 4.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 <= -3e+109:
		tmp = (math.pow((x / y), 2.0) * 0.5) + -1.0
	elif y <= -2e-73:
		tmp = t_0
	elif y <= 7.8e-47:
		tmp = 1.0
	elif y <= 2.2e+71:
		tmp = t_0
	else:
		tmp = -1.0 + ((x / y) * (x / (y * 4.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 <= -3e+109)
		tmp = Float64(Float64((Float64(x / y) ^ 2.0) * 0.5) + -1.0);
	elseif (y <= -2e-73)
		tmp = t_0;
	elseif (y <= 7.8e-47)
		tmp = 1.0;
	elseif (y <= 2.2e+71)
		tmp = t_0;
	else
		tmp = Float64(-1.0 + Float64(Float64(x / y) * Float64(x / Float64(y * 4.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 <= -3e+109)
		tmp = (((x / y) ^ 2.0) * 0.5) + -1.0;
	elseif (y <= -2e-73)
		tmp = t_0;
	elseif (y <= 7.8e-47)
		tmp = 1.0;
	elseif (y <= 2.2e+71)
		tmp = t_0;
	else
		tmp = -1.0 + ((x / y) * (x / (y * 4.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, -3e+109], N[(N[(N[Power[N[(x / y), $MachinePrecision], 2.0], $MachinePrecision] * 0.5), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[y, -2e-73], t$95$0, If[LessEqual[y, 7.8e-47], 1.0, If[LessEqual[y, 2.2e+71], t$95$0, N[(-1.0 + N[(N[(x / y), $MachinePrecision] * N[(x / N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\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 -3 \cdot 10^{+109}:\\
\;\;\;\;{\left(\frac{x}{y}\right)}^{2} \cdot 0.5 + -1\\

\mathbf{elif}\;y \leq -2 \cdot 10^{-73}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 7.8 \cdot 10^{-47}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \leq 2.2 \cdot 10^{+71}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;-1 + \frac{x}{y} \cdot \frac{x}{y \cdot 4}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original50.1%
Target50.5%
Herbie79.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 4 regimes
  2. if y < -3.00000000000000015e109

    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} \]
    2. Simplified16.1%

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot y\right) \cdot -4\right)}{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}} \]
      Proof

      [Start]16.1

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

      fma-neg [=>]16.1

      \[ \frac{\color{blue}{\mathsf{fma}\left(x, x, -\left(y \cdot 4\right) \cdot y\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]

      *-commutative [=>]16.1

      \[ \frac{\mathsf{fma}\left(x, x, -\color{blue}{y \cdot \left(y \cdot 4\right)}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]

      associate-*r* [=>]16.1

      \[ \frac{\mathsf{fma}\left(x, x, -\color{blue}{\left(y \cdot y\right) \cdot 4}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]

      distribute-rgt-neg-in [=>]16.1

      \[ \frac{\mathsf{fma}\left(x, x, \color{blue}{\left(y \cdot y\right) \cdot \left(-4\right)}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]

      metadata-eval [=>]16.1

      \[ \frac{\mathsf{fma}\left(x, x, \left(y \cdot y\right) \cdot \color{blue}{-4}\right)}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]

      fma-def [=>]16.1

      \[ \frac{\mathsf{fma}\left(x, x, \left(y \cdot y\right) \cdot -4\right)}{\color{blue}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}} \]

      *-commutative [=>]16.1

      \[ \frac{\mathsf{fma}\left(x, x, \left(y \cdot y\right) \cdot -4\right)}{\mathsf{fma}\left(x, x, \color{blue}{y \cdot \left(y \cdot 4\right)}\right)} \]
    3. Taylor expanded in x around 0 74.0%

      \[\leadsto \color{blue}{0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1} \]
    4. Simplified84.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right)} \]
      Proof

      [Start]74.0

      \[ 0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1 \]

      fma-neg [=>]74.0

      \[ \color{blue}{\mathsf{fma}\left(0.5, \frac{{x}^{2}}{{y}^{2}}, -1\right)} \]

      unpow2 [=>]74.0

      \[ \mathsf{fma}\left(0.5, \frac{\color{blue}{x \cdot x}}{{y}^{2}}, -1\right) \]

      unpow2 [=>]74.0

      \[ \mathsf{fma}\left(0.5, \frac{x \cdot x}{\color{blue}{y \cdot y}}, -1\right) \]

      times-frac [=>]84.1

      \[ \mathsf{fma}\left(0.5, \color{blue}{\frac{x}{y} \cdot \frac{x}{y}}, -1\right) \]

      metadata-eval [=>]84.1

      \[ \mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, \color{blue}{-1}\right) \]
    5. Applied egg-rr84.1%

      \[\leadsto \color{blue}{{\left(\frac{x}{y}\right)}^{2} \cdot 0.5 + -1} \]
      Proof

      [Start]84.1

      \[ \mathsf{fma}\left(0.5, \frac{x}{y} \cdot \frac{x}{y}, -1\right) \]

      fma-udef [=>]84.1

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

      *-commutative [=>]84.1

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

      pow2 [=>]84.1

      \[ \color{blue}{{\left(\frac{x}{y}\right)}^{2}} \cdot 0.5 + -1 \]

    if -3.00000000000000015e109 < y < -1.99999999999999999e-73 or 7.79999999999999956e-47 < y < 2.19999999999999995e71

    1. Initial program 74.8%

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

    if -1.99999999999999999e-73 < y < 7.79999999999999956e-47

    1. Initial program 61.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 inf 80.0%

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

    if 2.19999999999999995e71 < y

    1. Initial program 24.9%

      \[\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 22.9%

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{4 \cdot {y}^{2}}} \]
    3. Simplified22.9%

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

      [Start]22.9

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

      *-commutative [=>]22.9

      \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{{y}^{2} \cdot 4}} \]

      unpow2 [=>]22.9

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

      associate-*r* [<=]22.9

      \[ \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{y \cdot \left(y \cdot 4\right)}} \]
    4. Applied egg-rr81.0%

      \[\leadsto \color{blue}{\frac{x}{y} \cdot \frac{x}{y \cdot 4} - 1} \]
      Proof

      [Start]22.9

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

      *-commutative [<=]22.9

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

      div-sub [=>]22.9

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

      *-commutative [=>]22.9

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

      times-frac [=>]23.2

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

      *-inverses [=>]81.0

      \[ \frac{x}{y} \cdot \frac{x}{y \cdot 4} - \color{blue}{1} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification79.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -3 \cdot 10^{+109}:\\ \;\;\;\;{\left(\frac{x}{y}\right)}^{2} \cdot 0.5 + -1\\ \mathbf{elif}\;y \leq -2 \cdot 10^{-73}:\\ \;\;\;\;\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 7.8 \cdot 10^{-47}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 2.2 \cdot 10^{+71}:\\ \;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{else}:\\ \;\;\;\;-1 + \frac{x}{y} \cdot \frac{x}{y \cdot 4}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy73.8%
Cost2645
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 4\right)\\ t_1 := -1 + \frac{x}{y} \cdot \frac{x}{y \cdot 4}\\ \mathbf{if}\;t_0 \leq 4 \cdot 10^{-144}:\\ \;\;\;\;1\\ \mathbf{elif}\;t_0 \leq 4 \cdot 10^{-79}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 10^{-21}:\\ \;\;\;\;1\\ \mathbf{elif}\;t_0 \leq 7 \cdot 10^{+130} \lor \neg \left(t_0 \leq 7 \cdot 10^{+156}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{-4 \cdot \left(y \cdot y\right)}{x \cdot x}\\ \end{array} \]
Alternative 2
Accuracy79.6%
Cost1744
\[\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 -3 \cdot 10^{+109}:\\ \;\;\;\;-1 + 0.5 \cdot \frac{\frac{x}{\frac{y}{x}}}{y}\\ \mathbf{elif}\;y \leq -1.3 \cdot 10^{-74}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 7.8 \cdot 10^{-47}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 2.2 \cdot 10^{+71}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-1 + \frac{x}{y} \cdot \frac{x}{y \cdot 4}\\ \end{array} \]
Alternative 3
Accuracy74.0%
Cost1233
\[\begin{array}{l} t_0 := -1 + 0.5 \cdot \frac{\frac{x}{\frac{y}{x}}}{y}\\ \mathbf{if}\;y \leq -2.2 \cdot 10^{+76}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -8.5 \cdot 10^{-31}:\\ \;\;\;\;1 + \frac{-4 \cdot \left(y \cdot y\right)}{x \cdot x}\\ \mathbf{elif}\;y \leq -4.7 \cdot 10^{-71} \lor \neg \left(y \leq 1.15 \cdot 10^{-45}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 4
Accuracy73.6%
Cost968
\[\begin{array}{l} \mathbf{if}\;y \leq -2.4 \cdot 10^{+76}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -6 \cdot 10^{-32}:\\ \;\;\;\;1 + \frac{-4 \cdot \left(y \cdot y\right)}{x \cdot x}\\ \mathbf{elif}\;y \leq -3.4 \cdot 10^{-72}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 1.05 \cdot 10^{-45}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 5
Accuracy73.5%
Cost592
\[\begin{array}{l} \mathbf{if}\;y \leq -3 \cdot 10^{+76}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -5 \cdot 10^{-29}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq -1.3 \cdot 10^{-73}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{-45}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 6
Accuracy50.4%
Cost64
\[-1 \]

Error

Reproduce?

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