Average Error: 15.4 → 0.2
Time: 11.8s
Precision: binary64
Cost: 972
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]
\[\begin{array}{l} t_0 := \frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \mathbf{if}\;y \leq -1.6 \cdot 10^{+43}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;y \ne 0:\\ \;\;\;\;\frac{x}{\frac{x - y}{y}} \cdot 2\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array}\\ \mathbf{elif}\;y \leq 3 \cdot 10^{-30}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;x \ne 0:\\ \;\;\;\;\frac{2 \cdot y}{\frac{x - y}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot y}{x - y} \cdot x\\ \end{array} \]
(FPCore (x y) :precision binary64 (/ (* (* x 2.0) y) (- x y)))
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ (* (* x 2.0) y) (- x y))))
   (if (<= y -1.6e+43)
     (if (!= y 0.0) (* (/ x (/ (- x y) y)) 2.0) t_0)
     (if (<= y 3e-30)
       (if (!= x 0.0) (/ (* 2.0 y) (/ (- x y) x)) t_0)
       (* (/ (* 2.0 y) (- x y)) x)))))
double code(double x, double y) {
	return ((x * 2.0) * y) / (x - y);
}
double code(double x, double y) {
	double t_0 = ((x * 2.0) * y) / (x - y);
	double tmp_1;
	if (y <= -1.6e+43) {
		double tmp_2;
		if (y != 0.0) {
			tmp_2 = (x / ((x - y) / y)) * 2.0;
		} else {
			tmp_2 = t_0;
		}
		tmp_1 = tmp_2;
	} else if (y <= 3e-30) {
		double tmp_3;
		if (x != 0.0) {
			tmp_3 = (2.0 * y) / ((x - y) / x);
		} else {
			tmp_3 = t_0;
		}
		tmp_1 = tmp_3;
	} else {
		tmp_1 = ((2.0 * y) / (x - y)) * x;
	}
	return tmp_1;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = ((x * 2.0d0) * y) / (x - 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
    real(8) :: tmp_1
    real(8) :: tmp_2
    real(8) :: tmp_3
    t_0 = ((x * 2.0d0) * y) / (x - y)
    if (y <= (-1.6d+43)) then
        if (y /= 0.0d0) then
            tmp_2 = (x / ((x - y) / y)) * 2.0d0
        else
            tmp_2 = t_0
        end if
        tmp_1 = tmp_2
    else if (y <= 3d-30) then
        if (x /= 0.0d0) then
            tmp_3 = (2.0d0 * y) / ((x - y) / x)
        else
            tmp_3 = t_0
        end if
        tmp_1 = tmp_3
    else
        tmp_1 = ((2.0d0 * y) / (x - y)) * x
    end if
    code = tmp_1
end function
public static double code(double x, double y) {
	return ((x * 2.0) * y) / (x - y);
}
public static double code(double x, double y) {
	double t_0 = ((x * 2.0) * y) / (x - y);
	double tmp_1;
	if (y <= -1.6e+43) {
		double tmp_2;
		if (y != 0.0) {
			tmp_2 = (x / ((x - y) / y)) * 2.0;
		} else {
			tmp_2 = t_0;
		}
		tmp_1 = tmp_2;
	} else if (y <= 3e-30) {
		double tmp_3;
		if (x != 0.0) {
			tmp_3 = (2.0 * y) / ((x - y) / x);
		} else {
			tmp_3 = t_0;
		}
		tmp_1 = tmp_3;
	} else {
		tmp_1 = ((2.0 * y) / (x - y)) * x;
	}
	return tmp_1;
}
def code(x, y):
	return ((x * 2.0) * y) / (x - y)
def code(x, y):
	t_0 = ((x * 2.0) * y) / (x - y)
	tmp_1 = 0
	if y <= -1.6e+43:
		tmp_2 = 0
		if y != 0.0:
			tmp_2 = (x / ((x - y) / y)) * 2.0
		else:
			tmp_2 = t_0
		tmp_1 = tmp_2
	elif y <= 3e-30:
		tmp_3 = 0
		if x != 0.0:
			tmp_3 = (2.0 * y) / ((x - y) / x)
		else:
			tmp_3 = t_0
		tmp_1 = tmp_3
	else:
		tmp_1 = ((2.0 * y) / (x - y)) * x
	return tmp_1
function code(x, y)
	return Float64(Float64(Float64(x * 2.0) * y) / Float64(x - y))
end
function code(x, y)
	t_0 = Float64(Float64(Float64(x * 2.0) * y) / Float64(x - y))
	tmp_1 = 0.0
	if (y <= -1.6e+43)
		tmp_2 = 0.0
		if (y != 0.0)
			tmp_2 = Float64(Float64(x / Float64(Float64(x - y) / y)) * 2.0);
		else
			tmp_2 = t_0;
		end
		tmp_1 = tmp_2;
	elseif (y <= 3e-30)
		tmp_3 = 0.0
		if (x != 0.0)
			tmp_3 = Float64(Float64(2.0 * y) / Float64(Float64(x - y) / x));
		else
			tmp_3 = t_0;
		end
		tmp_1 = tmp_3;
	else
		tmp_1 = Float64(Float64(Float64(2.0 * y) / Float64(x - y)) * x);
	end
	return tmp_1
end
function tmp = code(x, y)
	tmp = ((x * 2.0) * y) / (x - y);
end
function tmp_5 = code(x, y)
	t_0 = ((x * 2.0) * y) / (x - y);
	tmp_2 = 0.0;
	if (y <= -1.6e+43)
		tmp_3 = 0.0;
		if (y ~= 0.0)
			tmp_3 = (x / ((x - y) / y)) * 2.0;
		else
			tmp_3 = t_0;
		end
		tmp_2 = tmp_3;
	elseif (y <= 3e-30)
		tmp_4 = 0.0;
		if (x ~= 0.0)
			tmp_4 = (2.0 * y) / ((x - y) / x);
		else
			tmp_4 = t_0;
		end
		tmp_2 = tmp_4;
	else
		tmp_2 = ((2.0 * y) / (x - y)) * x;
	end
	tmp_5 = tmp_2;
end
code[x_, y_] := N[(N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.6e+43], If[Unequal[y, 0.0], N[(N[(x / N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision], t$95$0], If[LessEqual[y, 3e-30], If[Unequal[x, 0.0], N[(N[(2.0 * y), $MachinePrecision] / N[(N[(x - y), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], t$95$0], N[(N[(N[(2.0 * y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]]]]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
t_0 := \frac{\left(x \cdot 2\right) \cdot y}{x - y}\\
\mathbf{if}\;y \leq -1.6 \cdot 10^{+43}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;y \ne 0:\\
\;\;\;\;\frac{x}{\frac{x - y}{y}} \cdot 2\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}\\

\mathbf{elif}\;y \leq 3 \cdot 10^{-30}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;x \ne 0:\\
\;\;\;\;\frac{2 \cdot y}{\frac{x - y}{x}}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}\\

\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot y}{x - y} \cdot x\\


\end{array}

Error

Target

Original15.4
Target0.3
Herbie0.2
\[\begin{array}{l} \mathbf{if}\;x < -1.7210442634149447 \cdot 10^{+81}:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \mathbf{elif}\;x < 83645045635564430:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if y < -1.60000000000000007e43

    1. Initial program 18.4

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]
    2. Applied egg-rr0.0

      \[\leadsto \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;y \ne 0:\\ \;\;\;\;\frac{x}{\frac{x - y}{y}} \cdot 2\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ } \end{array}} \]

    if -1.60000000000000007e43 < y < 2.9999999999999999e-30

    1. Initial program 14.4

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]
    2. Applied egg-rr0.3

      \[\leadsto \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;x \ne 0:\\ \;\;\;\;\frac{2 \cdot y}{\frac{x - y}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ } \end{array}} \]

    if 2.9999999999999999e-30 < y

    1. Initial program 14.9

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]
    2. Applied egg-rr0.2

      \[\leadsto \color{blue}{\frac{2 \cdot y}{x - y} \cdot x} \]
  3. Recombined 3 regimes into one program.

Alternatives

Alternative 1
Error0.6
Cost3152
\[\begin{array}{l} t_0 := \frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ t_1 := \frac{2 \cdot y}{x - y} \cdot x\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;\left(\frac{2}{x - y} \cdot y\right) \cdot x\\ \mathbf{elif}\;t_0 \leq -4 \cdot 10^{-307}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{-302}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{-30}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error0.2
Cost972
\[\begin{array}{l} \mathbf{if}\;y \leq -7 \cdot 10^{+42}:\\ \;\;\;\;\left(\frac{2}{x - y} \cdot y\right) \cdot x\\ \mathbf{elif}\;y \leq 8 \cdot 10^{-30}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;x \ne 0:\\ \;\;\;\;\frac{2 \cdot y}{\frac{x - y}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \end{array}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot y}{x - y} \cdot x\\ \end{array} \]
Alternative 3
Error0.2
Cost968
\[\begin{array}{l} \mathbf{if}\;y \leq -5.5 \cdot 10^{-47}:\\ \;\;\;\;\left(\frac{2}{x - y} \cdot y\right) \cdot x\\ \mathbf{elif}\;y \leq 5 \cdot 10^{-30}:\\ \;\;\;\;\left(\frac{-1}{y - x} \cdot x\right) \cdot \left(2 \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot y}{x - y} \cdot x\\ \end{array} \]
Alternative 4
Error4.2
Cost840
\[\begin{array}{l} t_0 := \left(\frac{2}{x - y} \cdot y\right) \cdot x\\ \mathbf{if}\;y \leq -4.9 \cdot 10^{-169}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.32 \cdot 10^{-101}:\\ \;\;\;\;2 \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error4.2
Cost840
\[\begin{array}{l} \mathbf{if}\;y \leq -2.7 \cdot 10^{-169}:\\ \;\;\;\;\left(\frac{2}{x - y} \cdot y\right) \cdot x\\ \mathbf{elif}\;y \leq 3 \cdot 10^{-101}:\\ \;\;\;\;2 \cdot y\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot y}{x - y} \cdot x\\ \end{array} \]
Alternative 6
Error15.7
Cost456
\[\begin{array}{l} \mathbf{if}\;y \leq -1.65 \cdot 10^{-9}:\\ \;\;\;\;x \cdot -2\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{+25}:\\ \;\;\;\;2 \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot -2\\ \end{array} \]
Alternative 7
Error31.5
Cost192
\[2 \cdot y \]

Error

Reproduce

herbie shell --seed 2023010 
(FPCore (x y)
  :name "Linear.Projection:perspective from linear-1.19.1.3, B"
  :precision binary64

  :herbie-target
  (if (< x -1.7210442634149447e+81) (* (/ (* 2.0 x) (- x y)) y) (if (< x 83645045635564430.0) (/ (* x 2.0) (/ (- x y) y)) (* (/ (* 2.0 x) (- x y)) y)))

  (/ (* (* x 2.0) y) (- x y)))