Linear.Projection:inverseInfinitePerspective from linear-1.19.1.3

Percentage Accurate: 90.8% → 96.9%
Time: 7.7s
Alternatives: 7
Speedup: 1.3×

Specification

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

\\
\left(x \cdot y - z \cdot y\right) \cdot t
\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 7 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: 90.8% accurate, 1.0× speedup?

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

\\
\left(x \cdot y - z \cdot y\right) \cdot t
\end{array}

Alternative 1: 96.9% accurate, 1.0× speedup?

\[\begin{array}{l} [y, t] = \mathsf{sort}([y, t])\\ \\ \begin{array}{l} \mathbf{if}\;t \leq 2.56 \cdot 10^{+54}:\\ \;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x - z\right) \cdot \left(t \cdot y\right)\\ \end{array} \end{array} \]
NOTE: y and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
 :precision binary64
 (if (<= t 2.56e+54) (* y (* t (- x z))) (* (- x z) (* t y))))
assert(y < t);
double code(double x, double y, double z, double t) {
	double tmp;
	if (t <= 2.56e+54) {
		tmp = y * (t * (x - z));
	} else {
		tmp = (x - z) * (t * y);
	}
	return tmp;
}
NOTE: y and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if (t <= 2.56d+54) then
        tmp = y * (t * (x - z))
    else
        tmp = (x - z) * (t * y)
    end if
    code = tmp
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
	double tmp;
	if (t <= 2.56e+54) {
		tmp = y * (t * (x - z));
	} else {
		tmp = (x - z) * (t * y);
	}
	return tmp;
}
[y, t] = sort([y, t])
def code(x, y, z, t):
	tmp = 0
	if t <= 2.56e+54:
		tmp = y * (t * (x - z))
	else:
		tmp = (x - z) * (t * y)
	return tmp
y, t = sort([y, t])
function code(x, y, z, t)
	tmp = 0.0
	if (t <= 2.56e+54)
		tmp = Float64(y * Float64(t * Float64(x - z)));
	else
		tmp = Float64(Float64(x - z) * Float64(t * y));
	end
	return tmp
end
y, t = num2cell(sort([y, t])){:}
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if (t <= 2.56e+54)
		tmp = y * (t * (x - z));
	else
		tmp = (x - z) * (t * y);
	end
	tmp_2 = tmp;
end
NOTE: y and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := If[LessEqual[t, 2.56e+54], N[(y * N[(t * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x - z), $MachinePrecision] * N[(t * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\begin{array}{l}
\mathbf{if}\;t \leq 2.56 \cdot 10^{+54}:\\
\;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\left(x - z\right) \cdot \left(t \cdot y\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if t < 2.56e54

    1. Initial program 87.0%

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Step-by-step derivation
      1. distribute-rgt-out--88.6%

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

        \[\leadsto \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)} \]
    3. Simplified94.5%

      \[\leadsto \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)} \]

    if 2.56e54 < t

    1. Initial program 97.0%

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Step-by-step derivation
      1. distribute-rgt-out--98.7%

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

        \[\leadsto \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)} \]
    3. Simplified81.9%

      \[\leadsto \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)} \]
    4. Step-by-step derivation
      1. *-commutative81.9%

        \[\leadsto y \cdot \color{blue}{\left(t \cdot \left(x - z\right)\right)} \]
      2. flip--70.1%

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

        \[\leadsto y \cdot \color{blue}{\frac{t \cdot \left(x \cdot x - z \cdot z\right)}{x + z}} \]
    5. Applied egg-rr63.5%

      \[\leadsto y \cdot \color{blue}{\frac{t \cdot \left(x \cdot x - z \cdot z\right)}{x + z}} \]
    6. Step-by-step derivation
      1. associate-/l*70.1%

        \[\leadsto y \cdot \color{blue}{\frac{t}{\frac{x + z}{x \cdot x - z \cdot z}}} \]
      2. difference-of-squares75.2%

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

        \[\leadsto y \cdot \frac{t}{\color{blue}{\frac{\frac{x + z}{x + z}}{x - z}}} \]
      4. *-inverses81.9%

        \[\leadsto y \cdot \frac{t}{\frac{\color{blue}{1}}{x - z}} \]
    7. Simplified81.9%

      \[\leadsto y \cdot \color{blue}{\frac{t}{\frac{1}{x - z}}} \]
    8. Step-by-step derivation
      1. *-commutative81.9%

        \[\leadsto \color{blue}{\frac{t}{\frac{1}{x - z}} \cdot y} \]
      2. associate-/r/81.9%

        \[\leadsto \color{blue}{\left(\frac{t}{1} \cdot \left(x - z\right)\right)} \cdot y \]
      3. /-rgt-identity81.9%

        \[\leadsto \left(\color{blue}{t} \cdot \left(x - z\right)\right) \cdot y \]
      4. associate-*r*98.7%

        \[\leadsto \color{blue}{t \cdot \left(\left(x - z\right) \cdot y\right)} \]
      5. flip--75.0%

        \[\leadsto t \cdot \left(\color{blue}{\frac{x \cdot x - z \cdot z}{x + z}} \cdot y\right) \]
      6. associate-/r/54.1%

        \[\leadsto t \cdot \color{blue}{\frac{x \cdot x - z \cdot z}{\frac{x + z}{y}}} \]
      7. clear-num54.1%

        \[\leadsto t \cdot \color{blue}{\frac{1}{\frac{\frac{x + z}{y}}{x \cdot x - z \cdot z}}} \]
      8. un-div-inv54.1%

        \[\leadsto \color{blue}{\frac{t}{\frac{\frac{x + z}{y}}{x \cdot x - z \cdot z}}} \]
      9. clear-num54.1%

        \[\leadsto \frac{t}{\color{blue}{\frac{1}{\frac{x \cdot x - z \cdot z}{\frac{x + z}{y}}}}} \]
      10. associate-/r/75.0%

        \[\leadsto \frac{t}{\frac{1}{\color{blue}{\frac{x \cdot x - z \cdot z}{x + z} \cdot y}}} \]
      11. flip--97.9%

        \[\leadsto \frac{t}{\frac{1}{\color{blue}{\left(x - z\right)} \cdot y}} \]
      12. *-commutative97.9%

        \[\leadsto \frac{t}{\frac{1}{\color{blue}{y \cdot \left(x - z\right)}}} \]
    9. Applied egg-rr97.9%

      \[\leadsto \color{blue}{\frac{t}{\frac{1}{y \cdot \left(x - z\right)}}} \]
    10. Step-by-step derivation
      1. associate-/r/98.7%

        \[\leadsto \color{blue}{\frac{t}{1} \cdot \left(y \cdot \left(x - z\right)\right)} \]
      2. /-rgt-identity98.7%

        \[\leadsto \color{blue}{t} \cdot \left(y \cdot \left(x - z\right)\right) \]
      3. associate-*r*98.2%

        \[\leadsto \color{blue}{\left(t \cdot y\right) \cdot \left(x - z\right)} \]
      4. *-commutative98.2%

        \[\leadsto \color{blue}{\left(y \cdot t\right)} \cdot \left(x - z\right) \]
      5. *-commutative98.2%

        \[\leadsto \color{blue}{\left(x - z\right) \cdot \left(y \cdot t\right)} \]
    11. Applied egg-rr98.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \leq 2.56 \cdot 10^{+54}:\\ \;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x - z\right) \cdot \left(t \cdot y\right)\\ \end{array} \]

Alternative 2: 74.3% accurate, 0.9× speedup?

\[\begin{array}{l} [y, t] = \mathsf{sort}([y, t])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq -1.7 \cdot 10^{-11}:\\ \;\;\;\;t \cdot \left(y \cdot x\right)\\ \mathbf{elif}\;x \leq 1.06 \cdot 10^{+18}:\\ \;\;\;\;\left(-y\right) \cdot \left(t \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(t \cdot x\right)\\ \end{array} \end{array} \]
NOTE: y and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
 :precision binary64
 (if (<= x -1.7e-11)
   (* t (* y x))
   (if (<= x 1.06e+18) (* (- y) (* t z)) (* y (* t x)))))
assert(y < t);
double code(double x, double y, double z, double t) {
	double tmp;
	if (x <= -1.7e-11) {
		tmp = t * (y * x);
	} else if (x <= 1.06e+18) {
		tmp = -y * (t * z);
	} else {
		tmp = y * (t * x);
	}
	return tmp;
}
NOTE: y and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if (x <= (-1.7d-11)) then
        tmp = t * (y * x)
    else if (x <= 1.06d+18) then
        tmp = -y * (t * z)
    else
        tmp = y * (t * x)
    end if
    code = tmp
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
	double tmp;
	if (x <= -1.7e-11) {
		tmp = t * (y * x);
	} else if (x <= 1.06e+18) {
		tmp = -y * (t * z);
	} else {
		tmp = y * (t * x);
	}
	return tmp;
}
[y, t] = sort([y, t])
def code(x, y, z, t):
	tmp = 0
	if x <= -1.7e-11:
		tmp = t * (y * x)
	elif x <= 1.06e+18:
		tmp = -y * (t * z)
	else:
		tmp = y * (t * x)
	return tmp
y, t = sort([y, t])
function code(x, y, z, t)
	tmp = 0.0
	if (x <= -1.7e-11)
		tmp = Float64(t * Float64(y * x));
	elseif (x <= 1.06e+18)
		tmp = Float64(Float64(-y) * Float64(t * z));
	else
		tmp = Float64(y * Float64(t * x));
	end
	return tmp
end
y, t = num2cell(sort([y, t])){:}
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if (x <= -1.7e-11)
		tmp = t * (y * x);
	elseif (x <= 1.06e+18)
		tmp = -y * (t * z);
	else
		tmp = y * (t * x);
	end
	tmp_2 = tmp;
end
NOTE: y and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := If[LessEqual[x, -1.7e-11], N[(t * N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.06e+18], N[((-y) * N[(t * z), $MachinePrecision]), $MachinePrecision], N[(y * N[(t * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.7 \cdot 10^{-11}:\\
\;\;\;\;t \cdot \left(y \cdot x\right)\\

\mathbf{elif}\;x \leq 1.06 \cdot 10^{+18}:\\
\;\;\;\;\left(-y\right) \cdot \left(t \cdot z\right)\\

\mathbf{else}:\\
\;\;\;\;y \cdot \left(t \cdot x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.6999999999999999e-11

    1. Initial program 88.2%

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Step-by-step derivation
      1. distribute-rgt-out--89.6%

        \[\leadsto \color{blue}{\left(y \cdot \left(x - z\right)\right)} \cdot t \]
    3. Simplified89.6%

      \[\leadsto \color{blue}{\left(y \cdot \left(x - z\right)\right) \cdot t} \]
    4. Taylor expanded in x around inf 73.2%

      \[\leadsto \color{blue}{\left(y \cdot x\right)} \cdot t \]

    if -1.6999999999999999e-11 < x < 1.06e18

    1. Initial program 91.3%

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Step-by-step derivation
      1. distribute-rgt-out--91.3%

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

        \[\leadsto \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)} \]
    3. Simplified89.0%

      \[\leadsto \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)} \]
    4. Taylor expanded in x around 0 76.4%

      \[\leadsto \color{blue}{-1 \cdot \left(y \cdot \left(t \cdot z\right)\right)} \]
    5. Step-by-step derivation
      1. associate-*r*76.4%

        \[\leadsto \color{blue}{\left(-1 \cdot y\right) \cdot \left(t \cdot z\right)} \]
      2. neg-mul-176.4%

        \[\leadsto \color{blue}{\left(-y\right)} \cdot \left(t \cdot z\right) \]
    6. Simplified76.4%

      \[\leadsto \color{blue}{\left(-y\right) \cdot \left(t \cdot z\right)} \]

    if 1.06e18 < x

    1. Initial program 86.9%

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Step-by-step derivation
      1. distribute-rgt-out--91.6%

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

        \[\leadsto \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)} \]
    3. Simplified94.3%

      \[\leadsto \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)} \]
    4. Taylor expanded in x around inf 74.8%

      \[\leadsto \color{blue}{y \cdot \left(t \cdot x\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification75.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.7 \cdot 10^{-11}:\\ \;\;\;\;t \cdot \left(y \cdot x\right)\\ \mathbf{elif}\;x \leq 1.06 \cdot 10^{+18}:\\ \;\;\;\;\left(-y\right) \cdot \left(t \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(t \cdot x\right)\\ \end{array} \]

Alternative 3: 74.2% accurate, 0.9× speedup?

\[\begin{array}{l} [y, t] = \mathsf{sort}([y, t])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq -1.6 \cdot 10^{-8}:\\ \;\;\;\;t \cdot \left(y \cdot x\right)\\ \mathbf{elif}\;x \leq 2.9 \cdot 10^{+18}:\\ \;\;\;\;z \cdot \left(t \cdot \left(-y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(t \cdot x\right)\\ \end{array} \end{array} \]
NOTE: y and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
 :precision binary64
 (if (<= x -1.6e-8)
   (* t (* y x))
   (if (<= x 2.9e+18) (* z (* t (- y))) (* y (* t x)))))
assert(y < t);
double code(double x, double y, double z, double t) {
	double tmp;
	if (x <= -1.6e-8) {
		tmp = t * (y * x);
	} else if (x <= 2.9e+18) {
		tmp = z * (t * -y);
	} else {
		tmp = y * (t * x);
	}
	return tmp;
}
NOTE: y and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if (x <= (-1.6d-8)) then
        tmp = t * (y * x)
    else if (x <= 2.9d+18) then
        tmp = z * (t * -y)
    else
        tmp = y * (t * x)
    end if
    code = tmp
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
	double tmp;
	if (x <= -1.6e-8) {
		tmp = t * (y * x);
	} else if (x <= 2.9e+18) {
		tmp = z * (t * -y);
	} else {
		tmp = y * (t * x);
	}
	return tmp;
}
[y, t] = sort([y, t])
def code(x, y, z, t):
	tmp = 0
	if x <= -1.6e-8:
		tmp = t * (y * x)
	elif x <= 2.9e+18:
		tmp = z * (t * -y)
	else:
		tmp = y * (t * x)
	return tmp
y, t = sort([y, t])
function code(x, y, z, t)
	tmp = 0.0
	if (x <= -1.6e-8)
		tmp = Float64(t * Float64(y * x));
	elseif (x <= 2.9e+18)
		tmp = Float64(z * Float64(t * Float64(-y)));
	else
		tmp = Float64(y * Float64(t * x));
	end
	return tmp
end
y, t = num2cell(sort([y, t])){:}
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if (x <= -1.6e-8)
		tmp = t * (y * x);
	elseif (x <= 2.9e+18)
		tmp = z * (t * -y);
	else
		tmp = y * (t * x);
	end
	tmp_2 = tmp;
end
NOTE: y and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := If[LessEqual[x, -1.6e-8], N[(t * N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.9e+18], N[(z * N[(t * (-y)), $MachinePrecision]), $MachinePrecision], N[(y * N[(t * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{-8}:\\
\;\;\;\;t \cdot \left(y \cdot x\right)\\

\mathbf{elif}\;x \leq 2.9 \cdot 10^{+18}:\\
\;\;\;\;z \cdot \left(t \cdot \left(-y\right)\right)\\

\mathbf{else}:\\
\;\;\;\;y \cdot \left(t \cdot x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -1.6000000000000001e-8

    1. Initial program 88.2%

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Step-by-step derivation
      1. distribute-rgt-out--89.6%

        \[\leadsto \color{blue}{\left(y \cdot \left(x - z\right)\right)} \cdot t \]
    3. Simplified89.6%

      \[\leadsto \color{blue}{\left(y \cdot \left(x - z\right)\right) \cdot t} \]
    4. Taylor expanded in x around inf 73.2%

      \[\leadsto \color{blue}{\left(y \cdot x\right)} \cdot t \]

    if -1.6000000000000001e-8 < x < 2.9e18

    1. Initial program 91.3%

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Step-by-step derivation
      1. distribute-rgt-out--91.3%

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

        \[\leadsto \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)} \]
    3. Simplified89.0%

      \[\leadsto \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)} \]
    4. Step-by-step derivation
      1. *-commutative89.0%

        \[\leadsto y \cdot \color{blue}{\left(t \cdot \left(x - z\right)\right)} \]
      2. flip--72.3%

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

        \[\leadsto y \cdot \color{blue}{\frac{t \cdot \left(x \cdot x - z \cdot z\right)}{x + z}} \]
    5. Applied egg-rr69.8%

      \[\leadsto y \cdot \color{blue}{\frac{t \cdot \left(x \cdot x - z \cdot z\right)}{x + z}} \]
    6. Step-by-step derivation
      1. associate-/l*72.3%

        \[\leadsto y \cdot \color{blue}{\frac{t}{\frac{x + z}{x \cdot x - z \cdot z}}} \]
      2. difference-of-squares72.3%

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

        \[\leadsto y \cdot \frac{t}{\color{blue}{\frac{\frac{x + z}{x + z}}{x - z}}} \]
      4. *-inverses89.0%

        \[\leadsto y \cdot \frac{t}{\frac{\color{blue}{1}}{x - z}} \]
    7. Simplified89.0%

      \[\leadsto y \cdot \color{blue}{\frac{t}{\frac{1}{x - z}}} \]
    8. Step-by-step derivation
      1. associate-*r/94.0%

        \[\leadsto \color{blue}{\frac{y \cdot t}{\frac{1}{x - z}}} \]
      2. frac-2neg94.0%

        \[\leadsto \color{blue}{\frac{-y \cdot t}{-\frac{1}{x - z}}} \]
      3. distribute-neg-frac94.0%

        \[\leadsto \frac{-y \cdot t}{\color{blue}{\frac{-1}{x - z}}} \]
      4. metadata-eval94.0%

        \[\leadsto \frac{-y \cdot t}{\frac{\color{blue}{-1}}{x - z}} \]
    9. Applied egg-rr94.0%

      \[\leadsto \color{blue}{\frac{-y \cdot t}{\frac{-1}{x - z}}} \]
    10. Step-by-step derivation
      1. associate-/r/94.1%

        \[\leadsto \color{blue}{\frac{-y \cdot t}{-1} \cdot \left(x - z\right)} \]
      2. distribute-lft-neg-in94.1%

        \[\leadsto \frac{\color{blue}{\left(-y\right) \cdot t}}{-1} \cdot \left(x - z\right) \]
    11. Simplified94.1%

      \[\leadsto \color{blue}{\frac{\left(-y\right) \cdot t}{-1} \cdot \left(x - z\right)} \]
    12. Taylor expanded in x around 0 76.4%

      \[\leadsto \color{blue}{-1 \cdot \left(y \cdot \left(t \cdot z\right)\right)} \]
    13. Step-by-step derivation
      1. mul-1-neg76.4%

        \[\leadsto \color{blue}{-y \cdot \left(t \cdot z\right)} \]
      2. associate-*r*83.1%

        \[\leadsto -\color{blue}{\left(y \cdot t\right) \cdot z} \]
      3. distribute-rgt-neg-in83.1%

        \[\leadsto \color{blue}{\left(y \cdot t\right) \cdot \left(-z\right)} \]
    14. Simplified83.1%

      \[\leadsto \color{blue}{\left(y \cdot t\right) \cdot \left(-z\right)} \]

    if 2.9e18 < x

    1. Initial program 86.9%

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Step-by-step derivation
      1. distribute-rgt-out--91.6%

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

        \[\leadsto \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)} \]
    3. Simplified94.3%

      \[\leadsto \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)} \]
    4. Taylor expanded in x around inf 74.8%

      \[\leadsto \color{blue}{y \cdot \left(t \cdot x\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification78.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.6 \cdot 10^{-8}:\\ \;\;\;\;t \cdot \left(y \cdot x\right)\\ \mathbf{elif}\;x \leq 2.9 \cdot 10^{+18}:\\ \;\;\;\;z \cdot \left(t \cdot \left(-y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(t \cdot x\right)\\ \end{array} \]

Alternative 4: 97.2% accurate, 1.0× speedup?

\[\begin{array}{l} [y, t] = \mathsf{sort}([y, t])\\ \\ \begin{array}{l} \mathbf{if}\;t \leq 4.6 \cdot 10^{-26}:\\ \;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\ \end{array} \end{array} \]
NOTE: y and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
 :precision binary64
 (if (<= t 4.6e-26) (* y (* t (- x z))) (* t (* y (- x z)))))
assert(y < t);
double code(double x, double y, double z, double t) {
	double tmp;
	if (t <= 4.6e-26) {
		tmp = y * (t * (x - z));
	} else {
		tmp = t * (y * (x - z));
	}
	return tmp;
}
NOTE: y and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if (t <= 4.6d-26) then
        tmp = y * (t * (x - z))
    else
        tmp = t * (y * (x - z))
    end if
    code = tmp
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
	double tmp;
	if (t <= 4.6e-26) {
		tmp = y * (t * (x - z));
	} else {
		tmp = t * (y * (x - z));
	}
	return tmp;
}
[y, t] = sort([y, t])
def code(x, y, z, t):
	tmp = 0
	if t <= 4.6e-26:
		tmp = y * (t * (x - z))
	else:
		tmp = t * (y * (x - z))
	return tmp
y, t = sort([y, t])
function code(x, y, z, t)
	tmp = 0.0
	if (t <= 4.6e-26)
		tmp = Float64(y * Float64(t * Float64(x - z)));
	else
		tmp = Float64(t * Float64(y * Float64(x - z)));
	end
	return tmp
end
y, t = num2cell(sort([y, t])){:}
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if (t <= 4.6e-26)
		tmp = y * (t * (x - z));
	else
		tmp = t * (y * (x - z));
	end
	tmp_2 = tmp;
end
NOTE: y and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := If[LessEqual[t, 4.6e-26], N[(y * N[(t * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t * N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\begin{array}{l}
\mathbf{if}\;t \leq 4.6 \cdot 10^{-26}:\\
\;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\

\mathbf{else}:\\
\;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if t < 4.60000000000000018e-26

    1. Initial program 86.7%

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Step-by-step derivation
      1. distribute-rgt-out--87.4%

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

        \[\leadsto \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)} \]
    3. Simplified93.9%

      \[\leadsto \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)} \]

    if 4.60000000000000018e-26 < t

    1. Initial program 95.1%

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Step-by-step derivation
      1. distribute-rgt-out--99.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \leq 4.6 \cdot 10^{-26}:\\ \;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\ \end{array} \]

Alternative 5: 55.9% accurate, 1.3× speedup?

\[\begin{array}{l} [y, t] = \mathsf{sort}([y, t])\\ \\ \begin{array}{l} \mathbf{if}\;y \leq -5 \cdot 10^{+115}:\\ \;\;\;\;y \cdot \left(t \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(y \cdot x\right)\\ \end{array} \end{array} \]
NOTE: y and t should be sorted in increasing order before calling this function.
(FPCore (x y z t)
 :precision binary64
 (if (<= y -5e+115) (* y (* t x)) (* t (* y x))))
assert(y < t);
double code(double x, double y, double z, double t) {
	double tmp;
	if (y <= -5e+115) {
		tmp = y * (t * x);
	} else {
		tmp = t * (y * x);
	}
	return tmp;
}
NOTE: y and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if (y <= (-5d+115)) then
        tmp = y * (t * x)
    else
        tmp = t * (y * x)
    end if
    code = tmp
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
	double tmp;
	if (y <= -5e+115) {
		tmp = y * (t * x);
	} else {
		tmp = t * (y * x);
	}
	return tmp;
}
[y, t] = sort([y, t])
def code(x, y, z, t):
	tmp = 0
	if y <= -5e+115:
		tmp = y * (t * x)
	else:
		tmp = t * (y * x)
	return tmp
y, t = sort([y, t])
function code(x, y, z, t)
	tmp = 0.0
	if (y <= -5e+115)
		tmp = Float64(y * Float64(t * x));
	else
		tmp = Float64(t * Float64(y * x));
	end
	return tmp
end
y, t = num2cell(sort([y, t])){:}
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if (y <= -5e+115)
		tmp = y * (t * x);
	else
		tmp = t * (y * x);
	end
	tmp_2 = tmp;
end
NOTE: y and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := If[LessEqual[y, -5e+115], N[(y * N[(t * x), $MachinePrecision]), $MachinePrecision], N[(t * N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{+115}:\\
\;\;\;\;y \cdot \left(t \cdot x\right)\\

\mathbf{else}:\\
\;\;\;\;t \cdot \left(y \cdot x\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -5.00000000000000008e115

    1. Initial program 72.3%

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Step-by-step derivation
      1. distribute-rgt-out--75.4%

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

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

      \[\leadsto \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)} \]
    4. Taylor expanded in x around inf 53.7%

      \[\leadsto \color{blue}{y \cdot \left(t \cdot x\right)} \]

    if -5.00000000000000008e115 < y

    1. Initial program 92.2%

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Step-by-step derivation
      1. distribute-rgt-out--93.6%

        \[\leadsto \color{blue}{\left(y \cdot \left(x - z\right)\right)} \cdot t \]
    3. Simplified93.6%

      \[\leadsto \color{blue}{\left(y \cdot \left(x - z\right)\right) \cdot t} \]
    4. Taylor expanded in x around inf 54.9%

      \[\leadsto \color{blue}{\left(y \cdot x\right)} \cdot t \]
  3. Recombined 2 regimes into one program.
  4. Final simplification54.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -5 \cdot 10^{+115}:\\ \;\;\;\;y \cdot \left(t \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(y \cdot x\right)\\ \end{array} \]

Alternative 6: 92.2% accurate, 1.3× speedup?

\[\begin{array}{l} [y, t] = \mathsf{sort}([y, t])\\ \\ y \cdot \left(t \cdot \left(x - z\right)\right) \end{array} \]
NOTE: y and t should be sorted in increasing order before calling this function.
(FPCore (x y z t) :precision binary64 (* y (* t (- x z))))
assert(y < t);
double code(double x, double y, double z, double t) {
	return y * (t * (x - z));
}
NOTE: y and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = y * (t * (x - z))
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
	return y * (t * (x - z));
}
[y, t] = sort([y, t])
def code(x, y, z, t):
	return y * (t * (x - z))
y, t = sort([y, t])
function code(x, y, z, t)
	return Float64(y * Float64(t * Float64(x - z)))
end
y, t = num2cell(sort([y, t])){:}
function tmp = code(x, y, z, t)
	tmp = y * (t * (x - z));
end
NOTE: y and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := N[(y * N[(t * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
y \cdot \left(t \cdot \left(x - z\right)\right)
\end{array}
Derivation
  1. Initial program 89.2%

    \[\left(x \cdot y - z \cdot y\right) \cdot t \]
  2. Step-by-step derivation
    1. distribute-rgt-out--90.9%

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

      \[\leadsto \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)} \]
  3. Simplified91.6%

    \[\leadsto \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)} \]
  4. Final simplification91.6%

    \[\leadsto y \cdot \left(t \cdot \left(x - z\right)\right) \]

Alternative 7: 54.2% accurate, 1.8× speedup?

\[\begin{array}{l} [y, t] = \mathsf{sort}([y, t])\\ \\ y \cdot \left(t \cdot x\right) \end{array} \]
NOTE: y and t should be sorted in increasing order before calling this function.
(FPCore (x y z t) :precision binary64 (* y (* t x)))
assert(y < t);
double code(double x, double y, double z, double t) {
	return y * (t * x);
}
NOTE: y and t should be sorted in increasing order before calling this function.
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = y * (t * x)
end function
assert y < t;
public static double code(double x, double y, double z, double t) {
	return y * (t * x);
}
[y, t] = sort([y, t])
def code(x, y, z, t):
	return y * (t * x)
y, t = sort([y, t])
function code(x, y, z, t)
	return Float64(y * Float64(t * x))
end
y, t = num2cell(sort([y, t])){:}
function tmp = code(x, y, z, t)
	tmp = y * (t * x);
end
NOTE: y and t should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_] := N[(y * N[(t * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[y, t] = \mathsf{sort}([y, t])\\
\\
y \cdot \left(t \cdot x\right)
\end{array}
Derivation
  1. Initial program 89.2%

    \[\left(x \cdot y - z \cdot y\right) \cdot t \]
  2. Step-by-step derivation
    1. distribute-rgt-out--90.9%

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

      \[\leadsto \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)} \]
  3. Simplified91.6%

    \[\leadsto \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)} \]
  4. Taylor expanded in x around inf 54.3%

    \[\leadsto \color{blue}{y \cdot \left(t \cdot x\right)} \]
  5. Final simplification54.3%

    \[\leadsto y \cdot \left(t \cdot x\right) \]

Developer target: 96.2% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;t < -9.231879582886777 \cdot 10^{-80}:\\ \;\;\;\;\left(y \cdot t\right) \cdot \left(x - z\right)\\ \mathbf{elif}\;t < 2.543067051564877 \cdot 10^{+83}:\\ \;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot \left(x - z\right)\right) \cdot t\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (< t -9.231879582886777e-80)
   (* (* y t) (- x z))
   (if (< t 2.543067051564877e+83) (* y (* t (- x z))) (* (* y (- x z)) t))))
double code(double x, double y, double z, double t) {
	double tmp;
	if (t < -9.231879582886777e-80) {
		tmp = (y * t) * (x - z);
	} else if (t < 2.543067051564877e+83) {
		tmp = y * (t * (x - z));
	} else {
		tmp = (y * (x - z)) * t;
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if (t < (-9.231879582886777d-80)) then
        tmp = (y * t) * (x - z)
    else if (t < 2.543067051564877d+83) then
        tmp = y * (t * (x - z))
    else
        tmp = (y * (x - z)) * t
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double tmp;
	if (t < -9.231879582886777e-80) {
		tmp = (y * t) * (x - z);
	} else if (t < 2.543067051564877e+83) {
		tmp = y * (t * (x - z));
	} else {
		tmp = (y * (x - z)) * t;
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if t < -9.231879582886777e-80:
		tmp = (y * t) * (x - z)
	elif t < 2.543067051564877e+83:
		tmp = y * (t * (x - z))
	else:
		tmp = (y * (x - z)) * t
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if (t < -9.231879582886777e-80)
		tmp = Float64(Float64(y * t) * Float64(x - z));
	elseif (t < 2.543067051564877e+83)
		tmp = Float64(y * Float64(t * Float64(x - z)));
	else
		tmp = Float64(Float64(y * Float64(x - z)) * t);
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if (t < -9.231879582886777e-80)
		tmp = (y * t) * (x - z);
	elseif (t < 2.543067051564877e+83)
		tmp = y * (t * (x - z));
	else
		tmp = (y * (x - z)) * t;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := If[Less[t, -9.231879582886777e-80], N[(N[(y * t), $MachinePrecision] * N[(x - z), $MachinePrecision]), $MachinePrecision], If[Less[t, 2.543067051564877e+83], N[(y * N[(t * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;t < -9.231879582886777 \cdot 10^{-80}:\\
\;\;\;\;\left(y \cdot t\right) \cdot \left(x - z\right)\\

\mathbf{elif}\;t < 2.543067051564877 \cdot 10^{+83}:\\
\;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\left(y \cdot \left(x - z\right)\right) \cdot t\\


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2023196 
(FPCore (x y z t)
  :name "Linear.Projection:inverseInfinitePerspective from linear-1.19.1.3"
  :precision binary64

  :herbie-target
  (if (< t -9.231879582886777e-80) (* (* y t) (- x z)) (if (< t 2.543067051564877e+83) (* y (* t (- x z))) (* (* y (- x z)) t)))

  (* (- (* x y) (* z y)) t))