Average Error: 7.4 → 1.4
Time: 4.6s
Precision: binary64
\[ \begin{array}{c}[y, t] = \mathsf{sort}([y, t])\\ \end{array} \]
\[\left(x \cdot y - z \cdot y\right) \cdot t \]
\[\begin{array}{l} t_1 := x \cdot y - y \cdot z\\ t_2 := t_1 \cdot t\\ t_3 := y \cdot \left(x \cdot t\right) - y \cdot \left(z \cdot t\right)\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_1 \leq -2 \cdot 10^{-89}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 10^{-150}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_1 \leq 10^{+88}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, y \cdot t, z \cdot \left(y \cdot \left(-t\right)\right)\right)\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (* (- (* x y) (* z y)) t))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (- (* x y) (* y z)))
        (t_2 (* t_1 t))
        (t_3 (- (* y (* x t)) (* y (* z t)))))
   (if (<= t_1 (- INFINITY))
     t_3
     (if (<= t_1 -2e-89)
       t_2
       (if (<= t_1 1e-150)
         t_3
         (if (<= t_1 1e+88) t_2 (fma x (* y t) (* z (* y (- t))))))))))
double code(double x, double y, double z, double t) {
	return ((x * y) - (z * y)) * t;
}
double code(double x, double y, double z, double t) {
	double t_1 = (x * y) - (y * z);
	double t_2 = t_1 * t;
	double t_3 = (y * (x * t)) - (y * (z * t));
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = t_3;
	} else if (t_1 <= -2e-89) {
		tmp = t_2;
	} else if (t_1 <= 1e-150) {
		tmp = t_3;
	} else if (t_1 <= 1e+88) {
		tmp = t_2;
	} else {
		tmp = fma(x, (y * t), (z * (y * -t)));
	}
	return tmp;
}
function code(x, y, z, t)
	return Float64(Float64(Float64(x * y) - Float64(z * y)) * t)
end
function code(x, y, z, t)
	t_1 = Float64(Float64(x * y) - Float64(y * z))
	t_2 = Float64(t_1 * t)
	t_3 = Float64(Float64(y * Float64(x * t)) - Float64(y * Float64(z * t)))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = t_3;
	elseif (t_1 <= -2e-89)
		tmp = t_2;
	elseif (t_1 <= 1e-150)
		tmp = t_3;
	elseif (t_1 <= 1e+88)
		tmp = t_2;
	else
		tmp = fma(x, Float64(y * t), Float64(z * Float64(y * Float64(-t))));
	end
	return tmp
end
code[x_, y_, z_, t_] := N[(N[(N[(x * y), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x * y), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * t), $MachinePrecision]}, Block[{t$95$3 = N[(N[(y * N[(x * t), $MachinePrecision]), $MachinePrecision] - N[(y * N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], t$95$3, If[LessEqual[t$95$1, -2e-89], t$95$2, If[LessEqual[t$95$1, 1e-150], t$95$3, If[LessEqual[t$95$1, 1e+88], t$95$2, N[(x * N[(y * t), $MachinePrecision] + N[(z * N[(y * (-t)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\left(x \cdot y - z \cdot y\right) \cdot t
\begin{array}{l}
t_1 := x \cdot y - y \cdot z\\
t_2 := t_1 \cdot t\\
t_3 := y \cdot \left(x \cdot t\right) - y \cdot \left(z \cdot t\right)\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;t_3\\

\mathbf{elif}\;t_1 \leq -2 \cdot 10^{-89}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq 10^{-150}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;t_1 \leq 10^{+88}:\\
\;\;\;\;t_2\\

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


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original7.4
Target3.3
Herbie1.4
\[\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} \]

Derivation

  1. Split input into 3 regimes
  2. if (-.f64 (*.f64 x y) (*.f64 z y)) < -inf.0 or -2.00000000000000008e-89 < (-.f64 (*.f64 x y) (*.f64 z y)) < 1.00000000000000001e-150

    1. Initial program 14.3

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Simplified2.2

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

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

    if -inf.0 < (-.f64 (*.f64 x y) (*.f64 z y)) < -2.00000000000000008e-89 or 1.00000000000000001e-150 < (-.f64 (*.f64 x y) (*.f64 z y)) < 9.99999999999999959e87

    1. Initial program 0.3

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

    if 9.99999999999999959e87 < (-.f64 (*.f64 x y) (*.f64 z y))

    1. Initial program 16.6

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Simplified3.7

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, y \cdot t, \left(-y \cdot t\right) \cdot z\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y - y \cdot z \leq -\infty:\\ \;\;\;\;y \cdot \left(x \cdot t\right) - y \cdot \left(z \cdot t\right)\\ \mathbf{elif}\;x \cdot y - y \cdot z \leq -2 \cdot 10^{-89}:\\ \;\;\;\;\left(x \cdot y - y \cdot z\right) \cdot t\\ \mathbf{elif}\;x \cdot y - y \cdot z \leq 10^{-150}:\\ \;\;\;\;y \cdot \left(x \cdot t\right) - y \cdot \left(z \cdot t\right)\\ \mathbf{elif}\;x \cdot y - y \cdot z \leq 10^{+88}:\\ \;\;\;\;\left(x \cdot y - y \cdot z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, y \cdot t, z \cdot \left(y \cdot \left(-t\right)\right)\right)\\ \end{array} \]

Reproduce

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