?

Average Error: 15.5 → 0.4
Time: 1.1min
Precision: binary64
Cost: 972

?

\[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]
\[\begin{array}{l} t_0 := \frac{y \cdot \left(2 \cdot x\right)}{x - y}\\ \mathbf{if}\;y \leq -20000:\\ \;\;\;\;\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 10^{-103}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;x \ne 0:\\ \;\;\;\;\frac{y \cdot 2}{\frac{x - y}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array}\\ \mathbf{elif}\;y \ne 0:\\ \;\;\;\;\frac{x + x}{\frac{x}{y} - 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(y + y\right) \cdot x}{x - y}\\ \end{array} \]
(FPCore (x y) :precision binary64 (/ (* (* x 2.0) y) (- x y)))
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ (* y (* 2.0 x)) (- x y))))
   (if (<= y -20000.0)
     (if (!= y 0.0) (/ x (/ (- x y) (* y 2.0))) t_0)
     (if (<= y 1e-103)
       (if (!= x 0.0) (/ (* y 2.0) (/ (- x y) x)) t_0)
       (if (!= y 0.0)
         (/ (+ x x) (- (/ x y) 1.0))
         (/ (* (+ y y) x) (- x y)))))))
double code(double x, double y) {
	return ((x * 2.0) * y) / (x - y);
}
double code(double x, double y) {
	double t_0 = (y * (2.0 * x)) / (x - y);
	double tmp_1;
	if (y <= -20000.0) {
		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 <= 1e-103) {
		double tmp_3;
		if (x != 0.0) {
			tmp_3 = (y * 2.0) / ((x - y) / x);
		} else {
			tmp_3 = t_0;
		}
		tmp_1 = tmp_3;
	} else if (y != 0.0) {
		tmp_1 = (x + x) / ((x / y) - 1.0);
	} else {
		tmp_1 = ((y + y) * x) / (x - y);
	}
	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 = (y * (2.0d0 * x)) / (x - y)
    if (y <= (-20000.0d0)) 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 <= 1d-103) then
        if (x /= 0.0d0) then
            tmp_3 = (y * 2.0d0) / ((x - y) / x)
        else
            tmp_3 = t_0
        end if
        tmp_1 = tmp_3
    else if (y /= 0.0d0) then
        tmp_1 = (x + x) / ((x / y) - 1.0d0)
    else
        tmp_1 = ((y + y) * x) / (x - y)
    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 = (y * (2.0 * x)) / (x - y);
	double tmp_1;
	if (y <= -20000.0) {
		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 <= 1e-103) {
		double tmp_3;
		if (x != 0.0) {
			tmp_3 = (y * 2.0) / ((x - y) / x);
		} else {
			tmp_3 = t_0;
		}
		tmp_1 = tmp_3;
	} else if (y != 0.0) {
		tmp_1 = (x + x) / ((x / y) - 1.0);
	} else {
		tmp_1 = ((y + y) * x) / (x - y);
	}
	return tmp_1;
}
def code(x, y):
	return ((x * 2.0) * y) / (x - y)
def code(x, y):
	t_0 = (y * (2.0 * x)) / (x - y)
	tmp_1 = 0
	if y <= -20000.0:
		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 <= 1e-103:
		tmp_3 = 0
		if x != 0.0:
			tmp_3 = (y * 2.0) / ((x - y) / x)
		else:
			tmp_3 = t_0
		tmp_1 = tmp_3
	elif y != 0.0:
		tmp_1 = (x + x) / ((x / y) - 1.0)
	else:
		tmp_1 = ((y + y) * x) / (x - y)
	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(y * Float64(2.0 * x)) / Float64(x - y))
	tmp_1 = 0.0
	if (y <= -20000.0)
		tmp_2 = 0.0
		if (y != 0.0)
			tmp_2 = Float64(x / Float64(Float64(x - y) / Float64(y * 2.0)));
		else
			tmp_2 = t_0;
		end
		tmp_1 = tmp_2;
	elseif (y <= 1e-103)
		tmp_3 = 0.0
		if (x != 0.0)
			tmp_3 = Float64(Float64(y * 2.0) / Float64(Float64(x - y) / x));
		else
			tmp_3 = t_0;
		end
		tmp_1 = tmp_3;
	elseif (y != 0.0)
		tmp_1 = Float64(Float64(x + x) / Float64(Float64(x / y) - 1.0));
	else
		tmp_1 = Float64(Float64(Float64(y + y) * x) / Float64(x - y));
	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 = (y * (2.0 * x)) / (x - y);
	tmp_2 = 0.0;
	if (y <= -20000.0)
		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 <= 1e-103)
		tmp_4 = 0.0;
		if (x ~= 0.0)
			tmp_4 = (y * 2.0) / ((x - y) / x);
		else
			tmp_4 = t_0;
		end
		tmp_2 = tmp_4;
	elseif (y ~= 0.0)
		tmp_2 = (x + x) / ((x / y) - 1.0);
	else
		tmp_2 = ((y + y) * x) / (x - y);
	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[(y * N[(2.0 * x), $MachinePrecision]), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -20000.0], If[Unequal[y, 0.0], N[(x / N[(N[(x - y), $MachinePrecision] / N[(y * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0], If[LessEqual[y, 1e-103], If[Unequal[x, 0.0], N[(N[(y * 2.0), $MachinePrecision] / N[(N[(x - y), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], t$95$0], If[Unequal[y, 0.0], N[(N[(x + x), $MachinePrecision] / N[(N[(x / y), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(y + y), $MachinePrecision] * x), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]]]]]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
t_0 := \frac{y \cdot \left(2 \cdot x\right)}{x - y}\\
\mathbf{if}\;y \leq -20000:\\
\;\;\;\;\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 10^{-103}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;x \ne 0:\\
\;\;\;\;\frac{y \cdot 2}{\frac{x - y}{x}}\\

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


\end{array}\\

\mathbf{elif}\;y \ne 0:\\
\;\;\;\;\frac{x + x}{\frac{x}{y} - 1}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(y + y\right) \cdot x}{x - y}\\


\end{array}

Error?

Target

Original15.5
Target0.3
Herbie0.4
\[\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 < -2e4

    1. Initial program 17.1

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

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

    if -2e4 < y < 9.99999999999999958e-104

    1. Initial program 16.1

      \[\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}\;x \ne 0:\\ \;\;\;\;\frac{y \cdot 2}{\frac{x - y}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot \left(2 \cdot x\right)}{x - y}\\ } \end{array}} \]

    if 9.99999999999999958e-104 < y

    1. Initial program 13.5

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

      \[\leadsto \color{blue}{\frac{1}{x - y} \cdot \left(y \cdot \left(2 \cdot x\right)\right)} \]
    3. Applied egg-rr1.1

      \[\leadsto \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;y \ne 0:\\ \;\;\;\;\frac{x + x}{\frac{x - y}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(y + y\right) \cdot x}{x - y}\\ } \end{array}} \]
    4. Taylor expanded in x around 0 1.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;y \ne 0:\\ \;\;\;\;\frac{x + x}{\color{blue}{\frac{x}{y} - 1}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(y + y\right) \cdot x}{x - y}\\ \end{array} \]
  3. Recombined 3 regimes into one program.

Alternatives

Alternative 1
Error0.5
Cost972
\[\begin{array}{l} t_0 := \frac{y \cdot 2}{x - y} \cdot x\\ \mathbf{if}\;y \leq -50000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 7 \cdot 10^{+112}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;x \ne 0:\\ \;\;\;\;\frac{y \cdot 2}{\frac{x - y}{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot \left(2 \cdot x\right)}{x - y}\\ \end{array}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.4
Cost972
\[\begin{array}{l} t_0 := \frac{y \cdot \left(2 \cdot x\right)}{x - y}\\ t_1 := \begin{array}{l} \mathbf{if}\;y \ne 0:\\ \;\;\;\;\frac{x}{\frac{x - y}{y \cdot 2}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array}\\ \mathbf{if}\;y \leq -12000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 10^{-103}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;x \ne 0:\\ \;\;\;\;\frac{y \cdot 2}{\frac{x - y}{x}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error3.9
Cost840
\[\begin{array}{l} \mathbf{if}\;y \leq -5.4 \cdot 10^{+174}:\\ \;\;\;\;x \cdot -2\\ \mathbf{elif}\;y \leq 2.75 \cdot 10^{+132}:\\ \;\;\;\;\left(\frac{2}{x - y} \cdot x\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot -2\\ \end{array} \]
Alternative 4
Error3.8
Cost840
\[\begin{array}{l} \mathbf{if}\;y \leq -6.6 \cdot 10^{+179}:\\ \;\;\;\;x \cdot -2\\ \mathbf{elif}\;y \leq 1.55 \cdot 10^{+130}:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot -2\\ \end{array} \]
Alternative 5
Error0.1
Cost840
\[\begin{array}{l} t_0 := \frac{2 \cdot x}{x - y} \cdot y\\ \mathbf{if}\;x \leq -20000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 5 \cdot 10^{-17}:\\ \;\;\;\;\frac{y \cdot 2}{x - y} \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error16.6
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -3.15 \cdot 10^{-63}:\\ \;\;\;\;2 \cdot y\\ \mathbf{elif}\;x \leq 8 \cdot 10^{-13}:\\ \;\;\;\;x \cdot -2\\ \mathbf{else}:\\ \;\;\;\;2 \cdot y\\ \end{array} \]
Alternative 7
Error31.8
Cost192
\[2 \cdot y \]

Error

Reproduce?

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