Average Error: 7.1 → 0.3
Time: 4.2s
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 := \mathsf{fma}\left(y \cdot \left(x - z\right), t, t \cdot \mathsf{fma}\left(y, -z, y \cdot z\right)\right)\\ t_2 := x \cdot y - y \cdot z\\ t_3 := \left(x - z\right) \cdot \left(y \cdot t\right)\\ \mathbf{if}\;t_2 \leq -8.275773723220835 \cdot 10^{+193}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_2 \leq -3.7358845021563734 \cdot 10^{-228}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;y \cdot \left(x \cdot t - z \cdot t\right)\\ \mathbf{elif}\;t_2 \leq 7.874539937961861 \cdot 10^{+262}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (* (- (* x y) (* z y)) t))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (fma (* y (- x z)) t (* t (fma y (- z) (* y z)))))
        (t_2 (- (* x y) (* y z)))
        (t_3 (* (- x z) (* y t))))
   (if (<= t_2 -8.275773723220835e+193)
     t_3
     (if (<= t_2 -3.7358845021563734e-228)
       t_1
       (if (<= t_2 0.0)
         (* y (- (* x t) (* z t)))
         (if (<= t_2 7.874539937961861e+262) t_1 t_3))))))
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 = fma((y * (x - z)), t, (t * fma(y, -z, (y * z))));
	double t_2 = (x * y) - (y * z);
	double t_3 = (x - z) * (y * t);
	double tmp;
	if (t_2 <= -8.275773723220835e+193) {
		tmp = t_3;
	} else if (t_2 <= -3.7358845021563734e-228) {
		tmp = t_1;
	} else if (t_2 <= 0.0) {
		tmp = y * ((x * t) - (z * t));
	} else if (t_2 <= 7.874539937961861e+262) {
		tmp = t_1;
	} else {
		tmp = t_3;
	}
	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 = fma(Float64(y * Float64(x - z)), t, Float64(t * fma(y, Float64(-z), Float64(y * z))))
	t_2 = Float64(Float64(x * y) - Float64(y * z))
	t_3 = Float64(Float64(x - z) * Float64(y * t))
	tmp = 0.0
	if (t_2 <= -8.275773723220835e+193)
		tmp = t_3;
	elseif (t_2 <= -3.7358845021563734e-228)
		tmp = t_1;
	elseif (t_2 <= 0.0)
		tmp = Float64(y * Float64(Float64(x * t) - Float64(z * t)));
	elseif (t_2 <= 7.874539937961861e+262)
		tmp = t_1;
	else
		tmp = t_3;
	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[(y * N[(x - z), $MachinePrecision]), $MachinePrecision] * t + N[(t * N[(y * (-z) + N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * y), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(x - z), $MachinePrecision] * N[(y * t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -8.275773723220835e+193], t$95$3, If[LessEqual[t$95$2, -3.7358845021563734e-228], t$95$1, If[LessEqual[t$95$2, 0.0], N[(y * N[(N[(x * t), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 7.874539937961861e+262], t$95$1, t$95$3]]]]]]]
\left(x \cdot y - z \cdot y\right) \cdot t
\begin{array}{l}
t_1 := \mathsf{fma}\left(y \cdot \left(x - z\right), t, t \cdot \mathsf{fma}\left(y, -z, y \cdot z\right)\right)\\
t_2 := x \cdot y - y \cdot z\\
t_3 := \left(x - z\right) \cdot \left(y \cdot t\right)\\
\mathbf{if}\;t_2 \leq -8.275773723220835 \cdot 10^{+193}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;t_2 \leq -3.7358845021563734 \cdot 10^{-228}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_2 \leq 0:\\
\;\;\;\;y \cdot \left(x \cdot t - z \cdot t\right)\\

\mathbf{elif}\;t_2 \leq 7.874539937961861 \cdot 10^{+262}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_3\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original7.1
Target3.5
Herbie0.3
\[\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)) < -8.27577372322083497e193 or 7.8745399379618613e262 < (-.f64 (*.f64 x y) (*.f64 z y))

    1. Initial program 33.3

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Taylor expanded in y around inf 0.9

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

    if -8.27577372322083497e193 < (-.f64 (*.f64 x y) (*.f64 z y)) < -3.7358845021563734e-228 or 0.0 < (-.f64 (*.f64 x y) (*.f64 z y)) < 7.8745399379618613e262

    1. Initial program 0.3

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Applied egg-rr0.2

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

    if -3.7358845021563734e-228 < (-.f64 (*.f64 x y) (*.f64 z y)) < 0.0

    1. Initial program 15.4

      \[\left(x \cdot y - z \cdot y\right) \cdot t \]
    2. Taylor expanded in y around inf 0.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y - y \cdot z \leq -8.275773723220835 \cdot 10^{+193}:\\ \;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\ \mathbf{elif}\;x \cdot y - y \cdot z \leq -3.7358845021563734 \cdot 10^{-228}:\\ \;\;\;\;\mathsf{fma}\left(y \cdot \left(x - z\right), t, t \cdot \mathsf{fma}\left(y, -z, y \cdot z\right)\right)\\ \mathbf{elif}\;x \cdot y - y \cdot z \leq 0:\\ \;\;\;\;y \cdot \left(x \cdot t - z \cdot t\right)\\ \mathbf{elif}\;x \cdot y - y \cdot z \leq 7.874539937961861 \cdot 10^{+262}:\\ \;\;\;\;\mathsf{fma}\left(y \cdot \left(x - z\right), t, t \cdot \mathsf{fma}\left(y, -z, y \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\ \end{array} \]

Reproduce

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