Linear.Projection:perspective from linear-1.19.1.3, B

Percentage Accurate: 77.0% → 99.2%
Time: 5.7s
Alternatives: 5
Speedup: 0.5×

Specification

?
\[\begin{array}{l} \\ \frac{\left(x \cdot 2\right) \cdot y}{x - y} \end{array} \]
(FPCore (x y) :precision binary64 (/ (* (* x 2.0) y) (- x y)))
double code(double x, double y) {
	return ((x * 2.0) * y) / (x - y);
}
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
public static double code(double x, double y) {
	return ((x * 2.0) * y) / (x - y);
}
def code(x, y):
	return ((x * 2.0) * y) / (x - y)
function code(x, y)
	return Float64(Float64(Float64(x * 2.0) * y) / Float64(x - y))
end
function tmp = code(x, y)
	tmp = ((x * 2.0) * y) / (x - y);
end
code[x_, y_] := N[(N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 5 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 77.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\left(x \cdot 2\right) \cdot y}{x - y} \end{array} \]
(FPCore (x y) :precision binary64 (/ (* (* x 2.0) y) (- x y)))
double code(double x, double y) {
	return ((x * 2.0) * y) / (x - y);
}
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
public static double code(double x, double y) {
	return ((x * 2.0) * y) / (x - y);
}
def code(x, y):
	return ((x * 2.0) * y) / (x - y)
function code(x, y)
	return Float64(Float64(Float64(x * 2.0) * y) / Float64(x - y))
end
function tmp = code(x, y)
	tmp = ((x * 2.0) * y) / (x - y);
end
code[x_, y_] := N[(N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\end{array}

Alternative 1: 99.2% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 2 \cdot \frac{x}{\frac{x}{y} + -1}\\ t_1 := \frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ t_2 := \frac{x \cdot \left(2 \cdot y\right)}{x - y}\\ \mathbf{if}\;t\_1 \leq -1 \cdot 10^{-45}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;t\_1 \leq -5 \cdot 10^{-305}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_1 \leq 0:\\ \;\;\;\;x \cdot \left(2 \cdot \frac{y}{x - y}\right)\\ \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+75}:\\ \;\;\;\;t\_2\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (* 2.0 (/ x (+ (/ x y) -1.0))))
        (t_1 (/ (* (* x 2.0) y) (- x y)))
        (t_2 (/ (* x (* 2.0 y)) (- x y))))
   (if (<= t_1 -1e-45)
     t_0
     (if (<= t_1 -5e-305)
       t_2
       (if (<= t_1 0.0)
         (* x (* 2.0 (/ y (- x y))))
         (if (<= t_1 2e+75) t_2 t_0))))))
double code(double x, double y) {
	double t_0 = 2.0 * (x / ((x / y) + -1.0));
	double t_1 = ((x * 2.0) * y) / (x - y);
	double t_2 = (x * (2.0 * y)) / (x - y);
	double tmp;
	if (t_1 <= -1e-45) {
		tmp = t_0;
	} else if (t_1 <= -5e-305) {
		tmp = t_2;
	} else if (t_1 <= 0.0) {
		tmp = x * (2.0 * (y / (x - y)));
	} else if (t_1 <= 2e+75) {
		tmp = t_2;
	} else {
		tmp = t_0;
	}
	return tmp;
}
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) :: tmp
    t_0 = 2.0d0 * (x / ((x / y) + (-1.0d0)))
    t_1 = ((x * 2.0d0) * y) / (x - y)
    t_2 = (x * (2.0d0 * y)) / (x - y)
    if (t_1 <= (-1d-45)) then
        tmp = t_0
    else if (t_1 <= (-5d-305)) then
        tmp = t_2
    else if (t_1 <= 0.0d0) then
        tmp = x * (2.0d0 * (y / (x - y)))
    else if (t_1 <= 2d+75) then
        tmp = t_2
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = 2.0 * (x / ((x / y) + -1.0));
	double t_1 = ((x * 2.0) * y) / (x - y);
	double t_2 = (x * (2.0 * y)) / (x - y);
	double tmp;
	if (t_1 <= -1e-45) {
		tmp = t_0;
	} else if (t_1 <= -5e-305) {
		tmp = t_2;
	} else if (t_1 <= 0.0) {
		tmp = x * (2.0 * (y / (x - y)));
	} else if (t_1 <= 2e+75) {
		tmp = t_2;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y):
	t_0 = 2.0 * (x / ((x / y) + -1.0))
	t_1 = ((x * 2.0) * y) / (x - y)
	t_2 = (x * (2.0 * y)) / (x - y)
	tmp = 0
	if t_1 <= -1e-45:
		tmp = t_0
	elif t_1 <= -5e-305:
		tmp = t_2
	elif t_1 <= 0.0:
		tmp = x * (2.0 * (y / (x - y)))
	elif t_1 <= 2e+75:
		tmp = t_2
	else:
		tmp = t_0
	return tmp
function code(x, y)
	t_0 = Float64(2.0 * Float64(x / Float64(Float64(x / y) + -1.0)))
	t_1 = Float64(Float64(Float64(x * 2.0) * y) / Float64(x - y))
	t_2 = Float64(Float64(x * Float64(2.0 * y)) / Float64(x - y))
	tmp = 0.0
	if (t_1 <= -1e-45)
		tmp = t_0;
	elseif (t_1 <= -5e-305)
		tmp = t_2;
	elseif (t_1 <= 0.0)
		tmp = Float64(x * Float64(2.0 * Float64(y / Float64(x - y))));
	elseif (t_1 <= 2e+75)
		tmp = t_2;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = 2.0 * (x / ((x / y) + -1.0));
	t_1 = ((x * 2.0) * y) / (x - y);
	t_2 = (x * (2.0 * y)) / (x - y);
	tmp = 0.0;
	if (t_1 <= -1e-45)
		tmp = t_0;
	elseif (t_1 <= -5e-305)
		tmp = t_2;
	elseif (t_1 <= 0.0)
		tmp = x * (2.0 * (y / (x - y)));
	elseif (t_1 <= 2e+75)
		tmp = t_2;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(2.0 * N[(x / N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * N[(2.0 * y), $MachinePrecision]), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e-45], t$95$0, If[LessEqual[t$95$1, -5e-305], t$95$2, If[LessEqual[t$95$1, 0.0], N[(x * N[(2.0 * N[(y / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e+75], t$95$2, t$95$0]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 2 \cdot \frac{x}{\frac{x}{y} + -1}\\
t_1 := \frac{\left(x \cdot 2\right) \cdot y}{x - y}\\
t_2 := \frac{x \cdot \left(2 \cdot y\right)}{x - y}\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{-45}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;t\_1 \leq -5 \cdot 10^{-305}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_1 \leq 0:\\
\;\;\;\;x \cdot \left(2 \cdot \frac{y}{x - y}\right)\\

\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+75}:\\
\;\;\;\;t\_2\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 (*.f64 (*.f64 x #s(literal 2 binary64)) y) (-.f64 x y)) < -9.99999999999999984e-46 or 1.99999999999999985e75 < (/.f64 (*.f64 (*.f64 x #s(literal 2 binary64)) y) (-.f64 x y))

    1. Initial program 48.8%

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]
    2. Step-by-step derivation
      1. associate-/l*98.6%

        \[\leadsto \color{blue}{\left(x \cdot 2\right) \cdot \frac{y}{x - y}} \]
      2. associate-*l*98.7%

        \[\leadsto \color{blue}{x \cdot \left(2 \cdot \frac{y}{x - y}\right)} \]
    3. Simplified98.7%

      \[\leadsto \color{blue}{x \cdot \left(2 \cdot \frac{y}{x - y}\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. associate-*r/98.7%

        \[\leadsto x \cdot \color{blue}{\frac{2 \cdot y}{x - y}} \]
      2. associate-/l*50.0%

        \[\leadsto \color{blue}{\frac{x \cdot \left(2 \cdot y\right)}{x - y}} \]
      3. add-log-exp12.8%

        \[\leadsto \color{blue}{\log \left(e^{\frac{x \cdot \left(2 \cdot y\right)}{x - y}}\right)} \]
      4. *-un-lft-identity12.8%

        \[\leadsto \log \color{blue}{\left(1 \cdot e^{\frac{x \cdot \left(2 \cdot y\right)}{x - y}}\right)} \]
      5. log-prod12.8%

        \[\leadsto \color{blue}{\log 1 + \log \left(e^{\frac{x \cdot \left(2 \cdot y\right)}{x - y}}\right)} \]
      6. metadata-eval12.8%

        \[\leadsto \color{blue}{0} + \log \left(e^{\frac{x \cdot \left(2 \cdot y\right)}{x - y}}\right) \]
      7. add-log-exp50.0%

        \[\leadsto 0 + \color{blue}{\frac{x \cdot \left(2 \cdot y\right)}{x - y}} \]
      8. associate-/l*98.7%

        \[\leadsto 0 + \color{blue}{x \cdot \frac{2 \cdot y}{x - y}} \]
      9. associate-*r/98.7%

        \[\leadsto 0 + x \cdot \color{blue}{\left(2 \cdot \frac{y}{x - y}\right)} \]
    6. Applied egg-rr98.7%

      \[\leadsto \color{blue}{0 + x \cdot \left(2 \cdot \frac{y}{x - y}\right)} \]
    7. Step-by-step derivation
      1. +-lft-identity98.7%

        \[\leadsto \color{blue}{x \cdot \left(2 \cdot \frac{y}{x - y}\right)} \]
      2. associate-*r*98.6%

        \[\leadsto \color{blue}{\left(x \cdot 2\right) \cdot \frac{y}{x - y}} \]
      3. associate-*r/48.8%

        \[\leadsto \color{blue}{\frac{\left(x \cdot 2\right) \cdot y}{x - y}} \]
      4. associate-*l/97.4%

        \[\leadsto \color{blue}{\frac{x \cdot 2}{x - y} \cdot y} \]
      5. associate-/r/98.7%

        \[\leadsto \color{blue}{\frac{x \cdot 2}{\frac{x - y}{y}}} \]
      6. *-commutative98.7%

        \[\leadsto \frac{\color{blue}{2 \cdot x}}{\frac{x - y}{y}} \]
      7. associate-/l*98.7%

        \[\leadsto \color{blue}{2 \cdot \frac{x}{\frac{x - y}{y}}} \]
      8. div-sub98.8%

        \[\leadsto 2 \cdot \frac{x}{\color{blue}{\frac{x}{y} - \frac{y}{y}}} \]
      9. sub-neg98.8%

        \[\leadsto 2 \cdot \frac{x}{\color{blue}{\frac{x}{y} + \left(-\frac{y}{y}\right)}} \]
      10. *-inverses98.8%

        \[\leadsto 2 \cdot \frac{x}{\frac{x}{y} + \left(-\color{blue}{1}\right)} \]
      11. metadata-eval98.8%

        \[\leadsto 2 \cdot \frac{x}{\frac{x}{y} + \color{blue}{-1}} \]
    8. Simplified98.8%

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

    if -9.99999999999999984e-46 < (/.f64 (*.f64 (*.f64 x #s(literal 2 binary64)) y) (-.f64 x y)) < -4.99999999999999985e-305 or 0.0 < (/.f64 (*.f64 (*.f64 x #s(literal 2 binary64)) y) (-.f64 x y)) < 1.99999999999999985e75

    1. Initial program 99.3%

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]
    2. Step-by-step derivation
      1. associate-*l*99.3%

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

      \[\leadsto \color{blue}{\frac{x \cdot \left(2 \cdot y\right)}{x - y}} \]
    4. Add Preprocessing

    if -4.99999999999999985e-305 < (/.f64 (*.f64 (*.f64 x #s(literal 2 binary64)) y) (-.f64 x y)) < 0.0

    1. Initial program 8.2%

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]
    2. Step-by-step derivation
      1. associate-/l*99.8%

        \[\leadsto \color{blue}{\left(x \cdot 2\right) \cdot \frac{y}{x - y}} \]
      2. associate-*l*99.8%

        \[\leadsto \color{blue}{x \cdot \left(2 \cdot \frac{y}{x - y}\right)} \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{x \cdot \left(2 \cdot \frac{y}{x - y}\right)} \]
    4. Add Preprocessing
  3. Recombined 3 regimes into one program.
  4. Final simplification99.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \leq -1 \cdot 10^{-45}:\\ \;\;\;\;2 \cdot \frac{x}{\frac{x}{y} + -1}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \leq -5 \cdot 10^{-305}:\\ \;\;\;\;\frac{x \cdot \left(2 \cdot y\right)}{x - y}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \leq 0:\\ \;\;\;\;x \cdot \left(2 \cdot \frac{y}{x - y}\right)\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \leq 2 \cdot 10^{+75}:\\ \;\;\;\;\frac{x \cdot \left(2 \cdot y\right)}{x - y}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{x}{\frac{x}{y} + -1}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 93.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -6.5 \cdot 10^{-163} \lor \neg \left(y \leq 2.06 \cdot 10^{-140}\right):\\ \;\;\;\;2 \cdot \frac{x}{\frac{x}{y} + -1}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot y\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (or (<= y -6.5e-163) (not (<= y 2.06e-140)))
   (* 2.0 (/ x (+ (/ x y) -1.0)))
   (* 2.0 y)))
double code(double x, double y) {
	double tmp;
	if ((y <= -6.5e-163) || !(y <= 2.06e-140)) {
		tmp = 2.0 * (x / ((x / y) + -1.0));
	} else {
		tmp = 2.0 * y;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if ((y <= (-6.5d-163)) .or. (.not. (y <= 2.06d-140))) then
        tmp = 2.0d0 * (x / ((x / y) + (-1.0d0)))
    else
        tmp = 2.0d0 * y
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((y <= -6.5e-163) || !(y <= 2.06e-140)) {
		tmp = 2.0 * (x / ((x / y) + -1.0));
	} else {
		tmp = 2.0 * y;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (y <= -6.5e-163) or not (y <= 2.06e-140):
		tmp = 2.0 * (x / ((x / y) + -1.0))
	else:
		tmp = 2.0 * y
	return tmp
function code(x, y)
	tmp = 0.0
	if ((y <= -6.5e-163) || !(y <= 2.06e-140))
		tmp = Float64(2.0 * Float64(x / Float64(Float64(x / y) + -1.0)));
	else
		tmp = Float64(2.0 * y);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((y <= -6.5e-163) || ~((y <= 2.06e-140)))
		tmp = 2.0 * (x / ((x / y) + -1.0));
	else
		tmp = 2.0 * y;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[Or[LessEqual[y, -6.5e-163], N[Not[LessEqual[y, 2.06e-140]], $MachinePrecision]], N[(2.0 * N[(x / N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 * y), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{-163} \lor \neg \left(y \leq 2.06 \cdot 10^{-140}\right):\\
\;\;\;\;2 \cdot \frac{x}{\frac{x}{y} + -1}\\

\mathbf{else}:\\
\;\;\;\;2 \cdot y\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -6.4999999999999999e-163 or 2.06e-140 < y

    1. Initial program 76.1%

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]
    2. Step-by-step derivation
      1. associate-/l*98.3%

        \[\leadsto \color{blue}{\left(x \cdot 2\right) \cdot \frac{y}{x - y}} \]
      2. associate-*l*98.3%

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

      \[\leadsto \color{blue}{x \cdot \left(2 \cdot \frac{y}{x - y}\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. associate-*r/98.3%

        \[\leadsto x \cdot \color{blue}{\frac{2 \cdot y}{x - y}} \]
      2. associate-/l*76.1%

        \[\leadsto \color{blue}{\frac{x \cdot \left(2 \cdot y\right)}{x - y}} \]
      3. add-log-exp8.4%

        \[\leadsto \color{blue}{\log \left(e^{\frac{x \cdot \left(2 \cdot y\right)}{x - y}}\right)} \]
      4. *-un-lft-identity8.4%

        \[\leadsto \log \color{blue}{\left(1 \cdot e^{\frac{x \cdot \left(2 \cdot y\right)}{x - y}}\right)} \]
      5. log-prod8.4%

        \[\leadsto \color{blue}{\log 1 + \log \left(e^{\frac{x \cdot \left(2 \cdot y\right)}{x - y}}\right)} \]
      6. metadata-eval8.4%

        \[\leadsto \color{blue}{0} + \log \left(e^{\frac{x \cdot \left(2 \cdot y\right)}{x - y}}\right) \]
      7. add-log-exp76.1%

        \[\leadsto 0 + \color{blue}{\frac{x \cdot \left(2 \cdot y\right)}{x - y}} \]
      8. associate-/l*98.3%

        \[\leadsto 0 + \color{blue}{x \cdot \frac{2 \cdot y}{x - y}} \]
      9. associate-*r/98.3%

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

      \[\leadsto \color{blue}{0 + x \cdot \left(2 \cdot \frac{y}{x - y}\right)} \]
    7. Step-by-step derivation
      1. +-lft-identity98.3%

        \[\leadsto \color{blue}{x \cdot \left(2 \cdot \frac{y}{x - y}\right)} \]
      2. associate-*r*98.3%

        \[\leadsto \color{blue}{\left(x \cdot 2\right) \cdot \frac{y}{x - y}} \]
      3. associate-*r/76.1%

        \[\leadsto \color{blue}{\frac{\left(x \cdot 2\right) \cdot y}{x - y}} \]
      4. associate-*l/86.1%

        \[\leadsto \color{blue}{\frac{x \cdot 2}{x - y} \cdot y} \]
      5. associate-/r/98.0%

        \[\leadsto \color{blue}{\frac{x \cdot 2}{\frac{x - y}{y}}} \]
      6. *-commutative98.0%

        \[\leadsto \frac{\color{blue}{2 \cdot x}}{\frac{x - y}{y}} \]
      7. associate-/l*98.0%

        \[\leadsto \color{blue}{2 \cdot \frac{x}{\frac{x - y}{y}}} \]
      8. div-sub98.0%

        \[\leadsto 2 \cdot \frac{x}{\color{blue}{\frac{x}{y} - \frac{y}{y}}} \]
      9. sub-neg98.0%

        \[\leadsto 2 \cdot \frac{x}{\color{blue}{\frac{x}{y} + \left(-\frac{y}{y}\right)}} \]
      10. *-inverses98.0%

        \[\leadsto 2 \cdot \frac{x}{\frac{x}{y} + \left(-\color{blue}{1}\right)} \]
      11. metadata-eval98.0%

        \[\leadsto 2 \cdot \frac{x}{\frac{x}{y} + \color{blue}{-1}} \]
    8. Simplified98.0%

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

    if -6.4999999999999999e-163 < y < 2.06e-140

    1. Initial program 69.7%

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]
    2. Step-by-step derivation
      1. associate-/l*62.5%

        \[\leadsto \color{blue}{\left(x \cdot 2\right) \cdot \frac{y}{x - y}} \]
      2. associate-*l*62.6%

        \[\leadsto \color{blue}{x \cdot \left(2 \cdot \frac{y}{x - y}\right)} \]
    3. Simplified62.6%

      \[\leadsto \color{blue}{x \cdot \left(2 \cdot \frac{y}{x - y}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 87.8%

      \[\leadsto \color{blue}{2 \cdot y} \]
    6. Step-by-step derivation
      1. *-commutative87.8%

        \[\leadsto \color{blue}{y \cdot 2} \]
    7. Simplified87.8%

      \[\leadsto \color{blue}{y \cdot 2} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification95.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -6.5 \cdot 10^{-163} \lor \neg \left(y \leq 2.06 \cdot 10^{-140}\right):\\ \;\;\;\;2 \cdot \frac{x}{\frac{x}{y} + -1}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot y\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 93.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.05 \cdot 10^{-162}:\\ \;\;\;\;2 \cdot \frac{x}{\frac{x}{y} + -1}\\ \mathbf{elif}\;y \leq 2.1 \cdot 10^{-145}:\\ \;\;\;\;2 \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(2 \cdot \frac{y}{x - y}\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= y -1.05e-162)
   (* 2.0 (/ x (+ (/ x y) -1.0)))
   (if (<= y 2.1e-145) (* 2.0 y) (* x (* 2.0 (/ y (- x y)))))))
double code(double x, double y) {
	double tmp;
	if (y <= -1.05e-162) {
		tmp = 2.0 * (x / ((x / y) + -1.0));
	} else if (y <= 2.1e-145) {
		tmp = 2.0 * y;
	} else {
		tmp = x * (2.0 * (y / (x - y)));
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (y <= (-1.05d-162)) then
        tmp = 2.0d0 * (x / ((x / y) + (-1.0d0)))
    else if (y <= 2.1d-145) then
        tmp = 2.0d0 * y
    else
        tmp = x * (2.0d0 * (y / (x - y)))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (y <= -1.05e-162) {
		tmp = 2.0 * (x / ((x / y) + -1.0));
	} else if (y <= 2.1e-145) {
		tmp = 2.0 * y;
	} else {
		tmp = x * (2.0 * (y / (x - y)));
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if y <= -1.05e-162:
		tmp = 2.0 * (x / ((x / y) + -1.0))
	elif y <= 2.1e-145:
		tmp = 2.0 * y
	else:
		tmp = x * (2.0 * (y / (x - y)))
	return tmp
function code(x, y)
	tmp = 0.0
	if (y <= -1.05e-162)
		tmp = Float64(2.0 * Float64(x / Float64(Float64(x / y) + -1.0)));
	elseif (y <= 2.1e-145)
		tmp = Float64(2.0 * y);
	else
		tmp = Float64(x * Float64(2.0 * Float64(y / Float64(x - y))));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (y <= -1.05e-162)
		tmp = 2.0 * (x / ((x / y) + -1.0));
	elseif (y <= 2.1e-145)
		tmp = 2.0 * y;
	else
		tmp = x * (2.0 * (y / (x - y)));
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[y, -1.05e-162], N[(2.0 * N[(x / N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.1e-145], N[(2.0 * y), $MachinePrecision], N[(x * N[(2.0 * N[(y / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.05 \cdot 10^{-162}:\\
\;\;\;\;2 \cdot \frac{x}{\frac{x}{y} + -1}\\

\mathbf{elif}\;y \leq 2.1 \cdot 10^{-145}:\\
\;\;\;\;2 \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.05e-162

    1. Initial program 78.6%

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]
    2. Step-by-step derivation
      1. associate-/l*98.9%

        \[\leadsto \color{blue}{\left(x \cdot 2\right) \cdot \frac{y}{x - y}} \]
      2. associate-*l*98.9%

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

      \[\leadsto \color{blue}{x \cdot \left(2 \cdot \frac{y}{x - y}\right)} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. associate-*r/98.9%

        \[\leadsto x \cdot \color{blue}{\frac{2 \cdot y}{x - y}} \]
      2. associate-/l*78.6%

        \[\leadsto \color{blue}{\frac{x \cdot \left(2 \cdot y\right)}{x - y}} \]
      3. add-log-exp11.3%

        \[\leadsto \color{blue}{\log \left(e^{\frac{x \cdot \left(2 \cdot y\right)}{x - y}}\right)} \]
      4. *-un-lft-identity11.3%

        \[\leadsto \log \color{blue}{\left(1 \cdot e^{\frac{x \cdot \left(2 \cdot y\right)}{x - y}}\right)} \]
      5. log-prod11.3%

        \[\leadsto \color{blue}{\log 1 + \log \left(e^{\frac{x \cdot \left(2 \cdot y\right)}{x - y}}\right)} \]
      6. metadata-eval11.3%

        \[\leadsto \color{blue}{0} + \log \left(e^{\frac{x \cdot \left(2 \cdot y\right)}{x - y}}\right) \]
      7. add-log-exp78.6%

        \[\leadsto 0 + \color{blue}{\frac{x \cdot \left(2 \cdot y\right)}{x - y}} \]
      8. associate-/l*98.9%

        \[\leadsto 0 + \color{blue}{x \cdot \frac{2 \cdot y}{x - y}} \]
      9. associate-*r/98.9%

        \[\leadsto 0 + x \cdot \color{blue}{\left(2 \cdot \frac{y}{x - y}\right)} \]
    6. Applied egg-rr98.9%

      \[\leadsto \color{blue}{0 + x \cdot \left(2 \cdot \frac{y}{x - y}\right)} \]
    7. Step-by-step derivation
      1. +-lft-identity98.9%

        \[\leadsto \color{blue}{x \cdot \left(2 \cdot \frac{y}{x - y}\right)} \]
      2. associate-*r*98.9%

        \[\leadsto \color{blue}{\left(x \cdot 2\right) \cdot \frac{y}{x - y}} \]
      3. associate-*r/78.6%

        \[\leadsto \color{blue}{\frac{\left(x \cdot 2\right) \cdot y}{x - y}} \]
      4. associate-*l/87.6%

        \[\leadsto \color{blue}{\frac{x \cdot 2}{x - y} \cdot y} \]
      5. associate-/r/99.0%

        \[\leadsto \color{blue}{\frac{x \cdot 2}{\frac{x - y}{y}}} \]
      6. *-commutative99.0%

        \[\leadsto \frac{\color{blue}{2 \cdot x}}{\frac{x - y}{y}} \]
      7. associate-/l*99.0%

        \[\leadsto \color{blue}{2 \cdot \frac{x}{\frac{x - y}{y}}} \]
      8. div-sub99.1%

        \[\leadsto 2 \cdot \frac{x}{\color{blue}{\frac{x}{y} - \frac{y}{y}}} \]
      9. sub-neg99.1%

        \[\leadsto 2 \cdot \frac{x}{\color{blue}{\frac{x}{y} + \left(-\frac{y}{y}\right)}} \]
      10. *-inverses99.1%

        \[\leadsto 2 \cdot \frac{x}{\frac{x}{y} + \left(-\color{blue}{1}\right)} \]
      11. metadata-eval99.1%

        \[\leadsto 2 \cdot \frac{x}{\frac{x}{y} + \color{blue}{-1}} \]
    8. Simplified99.1%

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

    if -1.05e-162 < y < 2.09999999999999991e-145

    1. Initial program 69.7%

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]
    2. Step-by-step derivation
      1. associate-/l*62.5%

        \[\leadsto \color{blue}{\left(x \cdot 2\right) \cdot \frac{y}{x - y}} \]
      2. associate-*l*62.6%

        \[\leadsto \color{blue}{x \cdot \left(2 \cdot \frac{y}{x - y}\right)} \]
    3. Simplified62.6%

      \[\leadsto \color{blue}{x \cdot \left(2 \cdot \frac{y}{x - y}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 87.8%

      \[\leadsto \color{blue}{2 \cdot y} \]
    6. Step-by-step derivation
      1. *-commutative87.8%

        \[\leadsto \color{blue}{y \cdot 2} \]
    7. Simplified87.8%

      \[\leadsto \color{blue}{y \cdot 2} \]

    if 2.09999999999999991e-145 < y

    1. Initial program 73.3%

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]
    2. Step-by-step derivation
      1. associate-/l*97.7%

        \[\leadsto \color{blue}{\left(x \cdot 2\right) \cdot \frac{y}{x - y}} \]
      2. associate-*l*97.7%

        \[\leadsto \color{blue}{x \cdot \left(2 \cdot \frac{y}{x - y}\right)} \]
    3. Simplified97.7%

      \[\leadsto \color{blue}{x \cdot \left(2 \cdot \frac{y}{x - y}\right)} \]
    4. Add Preprocessing
  3. Recombined 3 regimes into one program.
  4. Final simplification95.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.05 \cdot 10^{-162}:\\ \;\;\;\;2 \cdot \frac{x}{\frac{x}{y} + -1}\\ \mathbf{elif}\;y \leq 2.1 \cdot 10^{-145}:\\ \;\;\;\;2 \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(2 \cdot \frac{y}{x - y}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 72.3% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.56 \cdot 10^{-12} \lor \neg \left(x \leq 3.9 \cdot 10^{+133}\right):\\ \;\;\;\;2 \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot -2\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (or (<= x -1.56e-12) (not (<= x 3.9e+133))) (* 2.0 y) (* x -2.0)))
double code(double x, double y) {
	double tmp;
	if ((x <= -1.56e-12) || !(x <= 3.9e+133)) {
		tmp = 2.0 * y;
	} else {
		tmp = x * -2.0;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if ((x <= (-1.56d-12)) .or. (.not. (x <= 3.9d+133))) then
        tmp = 2.0d0 * y
    else
        tmp = x * (-2.0d0)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((x <= -1.56e-12) || !(x <= 3.9e+133)) {
		tmp = 2.0 * y;
	} else {
		tmp = x * -2.0;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (x <= -1.56e-12) or not (x <= 3.9e+133):
		tmp = 2.0 * y
	else:
		tmp = x * -2.0
	return tmp
function code(x, y)
	tmp = 0.0
	if ((x <= -1.56e-12) || !(x <= 3.9e+133))
		tmp = Float64(2.0 * y);
	else
		tmp = Float64(x * -2.0);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((x <= -1.56e-12) || ~((x <= 3.9e+133)))
		tmp = 2.0 * y;
	else
		tmp = x * -2.0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[Or[LessEqual[x, -1.56e-12], N[Not[LessEqual[x, 3.9e+133]], $MachinePrecision]], N[(2.0 * y), $MachinePrecision], N[(x * -2.0), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.56 \cdot 10^{-12} \lor \neg \left(x \leq 3.9 \cdot 10^{+133}\right):\\
\;\;\;\;2 \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.56000000000000002e-12 or 3.90000000000000014e133 < x

    1. Initial program 68.6%

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]
    2. Step-by-step derivation
      1. associate-/l*76.7%

        \[\leadsto \color{blue}{\left(x \cdot 2\right) \cdot \frac{y}{x - y}} \]
      2. associate-*l*76.8%

        \[\leadsto \color{blue}{x \cdot \left(2 \cdot \frac{y}{x - y}\right)} \]
    3. Simplified76.8%

      \[\leadsto \color{blue}{x \cdot \left(2 \cdot \frac{y}{x - y}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 77.6%

      \[\leadsto \color{blue}{2 \cdot y} \]
    6. Step-by-step derivation
      1. *-commutative77.6%

        \[\leadsto \color{blue}{y \cdot 2} \]
    7. Simplified77.6%

      \[\leadsto \color{blue}{y \cdot 2} \]

    if -1.56000000000000002e-12 < x < 3.90000000000000014e133

    1. Initial program 78.9%

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]
    2. Step-by-step derivation
      1. associate-/l*99.3%

        \[\leadsto \color{blue}{\left(x \cdot 2\right) \cdot \frac{y}{x - y}} \]
      2. associate-*l*99.3%

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

      \[\leadsto \color{blue}{x \cdot \left(2 \cdot \frac{y}{x - y}\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 74.8%

      \[\leadsto \color{blue}{-2 \cdot x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification76.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.56 \cdot 10^{-12} \lor \neg \left(x \leq 3.9 \cdot 10^{+133}\right):\\ \;\;\;\;2 \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot -2\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 50.0% accurate, 3.0× speedup?

\[\begin{array}{l} \\ x \cdot -2 \end{array} \]
(FPCore (x y) :precision binary64 (* x -2.0))
double code(double x, double y) {
	return x * -2.0;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = x * (-2.0d0)
end function
public static double code(double x, double y) {
	return x * -2.0;
}
def code(x, y):
	return x * -2.0
function code(x, y)
	return Float64(x * -2.0)
end
function tmp = code(x, y)
	tmp = x * -2.0;
end
code[x_, y_] := N[(x * -2.0), $MachinePrecision]
\begin{array}{l}

\\
x \cdot -2
\end{array}
Derivation
  1. Initial program 74.6%

    \[\frac{\left(x \cdot 2\right) \cdot y}{x - y} \]
  2. Step-by-step derivation
    1. associate-/l*89.9%

      \[\leadsto \color{blue}{\left(x \cdot 2\right) \cdot \frac{y}{x - y}} \]
    2. associate-*l*90.0%

      \[\leadsto \color{blue}{x \cdot \left(2 \cdot \frac{y}{x - y}\right)} \]
  3. Simplified90.0%

    \[\leadsto \color{blue}{x \cdot \left(2 \cdot \frac{y}{x - y}\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in x around 0 52.9%

    \[\leadsto \color{blue}{-2 \cdot x} \]
  6. Final simplification52.9%

    \[\leadsto x \cdot -2 \]
  7. Add Preprocessing

Developer target: 99.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{2 \cdot x}{x - y} \cdot y\\ \mathbf{if}\;x < -1.7210442634149447 \cdot 10^{+81}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x < 83645045635564430:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (* (/ (* 2.0 x) (- x y)) y)))
   (if (< x -1.7210442634149447e+81)
     t_0
     (if (< x 83645045635564430.0) (/ (* x 2.0) (/ (- x y) y)) t_0))))
double code(double x, double y) {
	double t_0 = ((2.0 * x) / (x - y)) * y;
	double tmp;
	if (x < -1.7210442634149447e+81) {
		tmp = t_0;
	} else if (x < 83645045635564430.0) {
		tmp = (x * 2.0) / ((x - y) / y);
	} else {
		tmp = t_0;
	}
	return tmp;
}
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 = ((2.0d0 * x) / (x - y)) * y
    if (x < (-1.7210442634149447d+81)) then
        tmp = t_0
    else if (x < 83645045635564430.0d0) then
        tmp = (x * 2.0d0) / ((x - y) / y)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = ((2.0 * x) / (x - y)) * y;
	double tmp;
	if (x < -1.7210442634149447e+81) {
		tmp = t_0;
	} else if (x < 83645045635564430.0) {
		tmp = (x * 2.0) / ((x - y) / y);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y):
	t_0 = ((2.0 * x) / (x - y)) * y
	tmp = 0
	if x < -1.7210442634149447e+81:
		tmp = t_0
	elif x < 83645045635564430.0:
		tmp = (x * 2.0) / ((x - y) / y)
	else:
		tmp = t_0
	return tmp
function code(x, y)
	t_0 = Float64(Float64(Float64(2.0 * x) / Float64(x - y)) * y)
	tmp = 0.0
	if (x < -1.7210442634149447e+81)
		tmp = t_0;
	elseif (x < 83645045635564430.0)
		tmp = Float64(Float64(x * 2.0) / Float64(Float64(x - y) / y));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = ((2.0 * x) / (x - y)) * y;
	tmp = 0.0;
	if (x < -1.7210442634149447e+81)
		tmp = t_0;
	elseif (x < 83645045635564430.0)
		tmp = (x * 2.0) / ((x - y) / y);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(2.0 * x), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]}, If[Less[x, -1.7210442634149447e+81], t$95$0, If[Less[x, 83645045635564430.0], N[(N[(x * 2.0), $MachinePrecision] / N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{2 \cdot x}{x - y} \cdot y\\
\mathbf{if}\;x < -1.7210442634149447 \cdot 10^{+81}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x < 83645045635564430:\\
\;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}

Reproduce

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

  :alt
  (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)))