?

Average Accuracy: 51.4% → 79.0%
Time: 8.8s
Precision: binary64
Cost: 3544

?

\[\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 - t_0}{t_0 + x \cdot x}\\ \mathbf{if}\;t_0 \leq 2 \cdot 10^{-165}:\\ \;\;\;\;1 + \frac{\frac{y}{\frac{x}{y}} \cdot -4}{x}\\ \mathbf{elif}\;t_0 \leq 10^{-112}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{-63}:\\ \;\;\;\;1\\ \mathbf{elif}\;t_0 \leq 10^{+31}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+82}:\\ \;\;\;\;1 + -4 \cdot \frac{y \cdot y}{x \cdot x}\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+153}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{y}}{\frac{y}{x}} \cdot 0.5 + -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) t_0) (+ t_0 (* x x)))))
   (if (<= t_0 2e-165)
     (+ 1.0 (/ (* (/ y (/ x y)) -4.0) x))
     (if (<= t_0 1e-112)
       t_1
       (if (<= t_0 2e-63)
         1.0
         (if (<= t_0 1e+31)
           t_1
           (if (<= t_0 2e+82)
             (+ 1.0 (* -4.0 (/ (* y y) (* x x))))
             (if (<= t_0 2e+153)
               t_1
               (+ (* (/ (/ x y) (/ y x)) 0.5) -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) - t_0) / (t_0 + (x * x));
	double tmp;
	if (t_0 <= 2e-165) {
		tmp = 1.0 + (((y / (x / y)) * -4.0) / x);
	} else if (t_0 <= 1e-112) {
		tmp = t_1;
	} else if (t_0 <= 2e-63) {
		tmp = 1.0;
	} else if (t_0 <= 1e+31) {
		tmp = t_1;
	} else if (t_0 <= 2e+82) {
		tmp = 1.0 + (-4.0 * ((y * y) / (x * x)));
	} else if (t_0 <= 2e+153) {
		tmp = t_1;
	} else {
		tmp = (((x / y) / (y / x)) * 0.5) + -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) - t_0) / (t_0 + (x * x))
    if (t_0 <= 2d-165) then
        tmp = 1.0d0 + (((y / (x / y)) * (-4.0d0)) / x)
    else if (t_0 <= 1d-112) then
        tmp = t_1
    else if (t_0 <= 2d-63) then
        tmp = 1.0d0
    else if (t_0 <= 1d+31) then
        tmp = t_1
    else if (t_0 <= 2d+82) then
        tmp = 1.0d0 + ((-4.0d0) * ((y * y) / (x * x)))
    else if (t_0 <= 2d+153) then
        tmp = t_1
    else
        tmp = (((x / y) / (y / x)) * 0.5d0) + (-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) - t_0) / (t_0 + (x * x));
	double tmp;
	if (t_0 <= 2e-165) {
		tmp = 1.0 + (((y / (x / y)) * -4.0) / x);
	} else if (t_0 <= 1e-112) {
		tmp = t_1;
	} else if (t_0 <= 2e-63) {
		tmp = 1.0;
	} else if (t_0 <= 1e+31) {
		tmp = t_1;
	} else if (t_0 <= 2e+82) {
		tmp = 1.0 + (-4.0 * ((y * y) / (x * x)));
	} else if (t_0 <= 2e+153) {
		tmp = t_1;
	} else {
		tmp = (((x / y) / (y / x)) * 0.5) + -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) - t_0) / (t_0 + (x * x))
	tmp = 0
	if t_0 <= 2e-165:
		tmp = 1.0 + (((y / (x / y)) * -4.0) / x)
	elif t_0 <= 1e-112:
		tmp = t_1
	elif t_0 <= 2e-63:
		tmp = 1.0
	elif t_0 <= 1e+31:
		tmp = t_1
	elif t_0 <= 2e+82:
		tmp = 1.0 + (-4.0 * ((y * y) / (x * x)))
	elif t_0 <= 2e+153:
		tmp = t_1
	else:
		tmp = (((x / y) / (y / x)) * 0.5) + -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) - t_0) / Float64(t_0 + Float64(x * x)))
	tmp = 0.0
	if (t_0 <= 2e-165)
		tmp = Float64(1.0 + Float64(Float64(Float64(y / Float64(x / y)) * -4.0) / x));
	elseif (t_0 <= 1e-112)
		tmp = t_1;
	elseif (t_0 <= 2e-63)
		tmp = 1.0;
	elseif (t_0 <= 1e+31)
		tmp = t_1;
	elseif (t_0 <= 2e+82)
		tmp = Float64(1.0 + Float64(-4.0 * Float64(Float64(y * y) / Float64(x * x))));
	elseif (t_0 <= 2e+153)
		tmp = t_1;
	else
		tmp = Float64(Float64(Float64(Float64(x / y) / Float64(y / x)) * 0.5) + -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) - t_0) / (t_0 + (x * x));
	tmp = 0.0;
	if (t_0 <= 2e-165)
		tmp = 1.0 + (((y / (x / y)) * -4.0) / x);
	elseif (t_0 <= 1e-112)
		tmp = t_1;
	elseif (t_0 <= 2e-63)
		tmp = 1.0;
	elseif (t_0 <= 1e+31)
		tmp = t_1;
	elseif (t_0 <= 2e+82)
		tmp = 1.0 + (-4.0 * ((y * y) / (x * x)));
	elseif (t_0 <= 2e+153)
		tmp = t_1;
	else
		tmp = (((x / y) / (y / x)) * 0.5) + -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] - t$95$0), $MachinePrecision] / N[(t$95$0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2e-165], N[(1.0 + N[(N[(N[(y / N[(x / y), $MachinePrecision]), $MachinePrecision] * -4.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e-112], t$95$1, If[LessEqual[t$95$0, 2e-63], 1.0, If[LessEqual[t$95$0, 1e+31], t$95$1, If[LessEqual[t$95$0, 2e+82], N[(1.0 + N[(-4.0 * N[(N[(y * y), $MachinePrecision] / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e+153], t$95$1, N[(N[(N[(N[(x / y), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision] + -1.0), $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 := y \cdot \left(y \cdot 4\right)\\
t_1 := \frac{x \cdot x - t_0}{t_0 + x \cdot x}\\
\mathbf{if}\;t_0 \leq 2 \cdot 10^{-165}:\\
\;\;\;\;1 + \frac{\frac{y}{\frac{x}{y}} \cdot -4}{x}\\

\mathbf{elif}\;t_0 \leq 10^{-112}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq 2 \cdot 10^{-63}:\\
\;\;\;\;1\\

\mathbf{elif}\;t_0 \leq 10^{+31}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+82}:\\
\;\;\;\;1 + -4 \cdot \frac{y \cdot y}{x \cdot x}\\

\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+153}:\\
\;\;\;\;t_1\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original51.4%
Target51.9%
Herbie79.0%
\[\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 (*.f64 (*.f64 y 4) y) < 2e-165

    1. Initial program 59.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 inf 49.5%

      \[\leadsto \frac{\color{blue}{{x}^{2}}}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    3. Simplified49.5%

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

      [Start]49.5

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

      unpow2 [=>]49.5

      \[ \frac{\color{blue}{x \cdot x}}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    4. Taylor expanded in x around inf 75.2%

      \[\leadsto \color{blue}{1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}}} \]
    5. Simplified75.2%

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

      [Start]75.2

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

      unpow2 [=>]75.2

      \[ 1 + -4 \cdot \frac{\color{blue}{y \cdot y}}{{x}^{2}} \]

      unpow2 [=>]75.2

      \[ 1 + -4 \cdot \frac{y \cdot y}{\color{blue}{x \cdot x}} \]
    6. Applied egg-rr82.9%

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

      [Start]75.2

      \[ 1 + -4 \cdot \frac{y \cdot y}{x \cdot x} \]

      *-commutative [=>]75.2

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

      associate-/r* [=>]82.5

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

      associate-*l/ [=>]82.5

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

      associate-/l* [=>]82.9

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

    if 2e-165 < (*.f64 (*.f64 y 4) y) < 9.9999999999999995e-113 or 2.00000000000000013e-63 < (*.f64 (*.f64 y 4) y) < 9.9999999999999996e30 or 1.9999999999999999e82 < (*.f64 (*.f64 y 4) y) < 2e153

    1. Initial program 76.5%

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

    if 9.9999999999999995e-113 < (*.f64 (*.f64 y 4) y) < 2.00000000000000013e-63

    1. Initial program 77.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 53.5%

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

    if 9.9999999999999996e30 < (*.f64 (*.f64 y 4) y) < 1.9999999999999999e82

    1. Initial program 75.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 16.3%

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

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

      [Start]16.3

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

      unpow2 [=>]16.3

      \[ \frac{\color{blue}{x \cdot x}}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
    4. Taylor expanded in x around inf 41.1%

      \[\leadsto \color{blue}{1 + -4 \cdot \frac{{y}^{2}}{{x}^{2}}} \]
    5. Simplified41.1%

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

      [Start]41.1

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

      unpow2 [=>]41.1

      \[ 1 + -4 \cdot \frac{\color{blue}{y \cdot y}}{{x}^{2}} \]

      unpow2 [=>]41.1

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

    if 2e153 < (*.f64 (*.f64 y 4) y)

    1. Initial program 26.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 0 73.8%

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

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

      [Start]73.8

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

      fma-neg [=>]73.8

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

      unpow2 [=>]73.8

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

      unpow2 [=>]73.8

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

      times-frac [=>]83.1

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

      metadata-eval [=>]83.1

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

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

      [Start]83.1

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

      fma-udef [=>]83.1

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

      *-commutative [=>]83.1

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

      pow2 [=>]83.1

      \[ \color{blue}{{\left(\frac{x}{y}\right)}^{2}} \cdot 0.5 + -1 \]
    5. Applied egg-rr83.1%

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

      [Start]83.1

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

      unpow2 [=>]83.1

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

      clear-num [=>]83.1

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

      un-div-inv [=>]83.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot \left(y \cdot 4\right) \leq 2 \cdot 10^{-165}:\\ \;\;\;\;1 + \frac{\frac{y}{\frac{x}{y}} \cdot -4}{x}\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 10^{-112}:\\ \;\;\;\;\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 2 \cdot 10^{-63}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 10^{+31}:\\ \;\;\;\;\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 2 \cdot 10^{+82}:\\ \;\;\;\;1 + -4 \cdot \frac{y \cdot y}{x \cdot x}\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \leq 2 \cdot 10^{+153}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{y \cdot \left(y \cdot 4\right) + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{y}}{\frac{y}{x}} \cdot 0.5 + -1\\ \end{array} \]

Alternatives

Alternative 1
Accuracy75.7%
Cost969
\[\begin{array}{l} \mathbf{if}\;y \leq -9 \cdot 10^{-8} \lor \neg \left(y \leq 10^{+68}\right):\\ \;\;\;\;\frac{\frac{x}{y}}{\frac{y}{x}} \cdot 0.5 + -1\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{\frac{y}{\frac{x}{y}} \cdot -4}{x}\\ \end{array} \]
Alternative 2
Accuracy75.3%
Cost968
\[\begin{array}{l} \mathbf{if}\;y \leq -5.7 \cdot 10^{-8}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 4.4 \cdot 10^{+67}:\\ \;\;\;\;1 + \frac{\frac{y}{\frac{x}{y}} \cdot -4}{x}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 3
Accuracy75.1%
Cost328
\[\begin{array}{l} \mathbf{if}\;y \leq -5 \cdot 10^{-24}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq 10^{+68}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Alternative 4
Accuracy50.7%
Cost64
\[-1 \]

Error

Reproduce?

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