Average Error: 6.7 → 0.7
Time: 8.0s
Precision: binary64
\[[y, t] = \mathsf{sort}([y, t]) \\]
\[\left(x \cdot y - z \cdot y\right) \cdot t \]
\[\begin{array}{l} t_1 := x \cdot y - y \cdot z\\ t_2 := \mathsf{fma}\left(t \cdot \left(x - z\right), y, y \cdot \mathsf{fma}\left(t, -z, z \cdot t\right)\right)\\ \mathbf{if}\;t_1 \leq -3.9027479416013315 \cdot 10^{+279}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq -1.0453025525917239 \cdot 10^{-153}:\\ \;\;\;\;t_1 \cdot t\\ \mathbf{elif}\;t_1 \leq 5.261353732592366 \cdot 10^{-129}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 1.902271020531652 \cdot 10^{+174}:\\ \;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \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 (fma (* t (- x z)) y (* y (fma t (- z) (* z t))))))
   (if (<= t_1 -3.9027479416013315e+279)
     t_2
     (if (<= t_1 -1.0453025525917239e-153)
       (* t_1 t)
       (if (<= t_1 5.261353732592366e-129)
         t_2
         (if (<= t_1 1.902271020531652e+174) (* t (* y (- x z))) t_2))))))
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 = fma((t * (x - z)), y, (y * fma(t, -z, (z * t))));
	double tmp;
	if (t_1 <= -3.9027479416013315e+279) {
		tmp = t_2;
	} else if (t_1 <= -1.0453025525917239e-153) {
		tmp = t_1 * t;
	} else if (t_1 <= 5.261353732592366e-129) {
		tmp = t_2;
	} else if (t_1 <= 1.902271020531652e+174) {
		tmp = t * (y * (x - z));
	} else {
		tmp = t_2;
	}
	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 = fma(Float64(t * Float64(x - z)), y, Float64(y * fma(t, Float64(-z), Float64(z * t))))
	tmp = 0.0
	if (t_1 <= -3.9027479416013315e+279)
		tmp = t_2;
	elseif (t_1 <= -1.0453025525917239e-153)
		tmp = Float64(t_1 * t);
	elseif (t_1 <= 5.261353732592366e-129)
		tmp = t_2;
	elseif (t_1 <= 1.902271020531652e+174)
		tmp = Float64(t * Float64(y * Float64(x - z)));
	else
		tmp = t_2;
	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[(N[(t * N[(x - z), $MachinePrecision]), $MachinePrecision] * y + N[(y * N[(t * (-z) + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -3.9027479416013315e+279], t$95$2, If[LessEqual[t$95$1, -1.0453025525917239e-153], N[(t$95$1 * t), $MachinePrecision], If[LessEqual[t$95$1, 5.261353732592366e-129], t$95$2, If[LessEqual[t$95$1, 1.902271020531652e+174], N[(t * N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$2]]]]]]
\left(x \cdot y - z \cdot y\right) \cdot t
\begin{array}{l}
t_1 := x \cdot y - y \cdot z\\
t_2 := \mathsf{fma}\left(t \cdot \left(x - z\right), y, y \cdot \mathsf{fma}\left(t, -z, z \cdot t\right)\right)\\
\mathbf{if}\;t_1 \leq -3.9027479416013315 \cdot 10^{+279}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq -1.0453025525917239 \cdot 10^{-153}:\\
\;\;\;\;t_1 \cdot t\\

\mathbf{elif}\;t_1 \leq 5.261353732592366 \cdot 10^{-129}:\\
\;\;\;\;t_2\\

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

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original6.7
Target3.3
Herbie0.7
\[\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)) < -3.902747941601331e279 or -1.0453025525917239e-153 < (-.f64 (*.f64 x y) (*.f64 z y)) < 5.26135373259236625e-129 or 1.9022710205316519e174 < (-.f64 (*.f64 x y) (*.f64 z y))

    1. Initial program 17.2

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

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

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

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

    if -3.902747941601331e279 < (-.f64 (*.f64 x y) (*.f64 z y)) < -1.0453025525917239e-153

    1. Initial program 0.2

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

    if 5.26135373259236625e-129 < (-.f64 (*.f64 x y) (*.f64 z y)) < 1.9022710205316519e174

    1. Initial program 0.3

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(t \cdot \left(x - z\right), y, \mathsf{fma}\left(t, -z, t \cdot z\right) \cdot y\right)} \]
    5. Taylor expanded in t around 0 0.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y - y \cdot z \leq -3.9027479416013315 \cdot 10^{+279}:\\ \;\;\;\;\mathsf{fma}\left(t \cdot \left(x - z\right), y, y \cdot \mathsf{fma}\left(t, -z, z \cdot t\right)\right)\\ \mathbf{elif}\;x \cdot y - y \cdot z \leq -1.0453025525917239 \cdot 10^{-153}:\\ \;\;\;\;\left(x \cdot y - y \cdot z\right) \cdot t\\ \mathbf{elif}\;x \cdot y - y \cdot z \leq 5.261353732592366 \cdot 10^{-129}:\\ \;\;\;\;\mathsf{fma}\left(t \cdot \left(x - z\right), y, y \cdot \mathsf{fma}\left(t, -z, z \cdot t\right)\right)\\ \mathbf{elif}\;x \cdot y - y \cdot z \leq 1.902271020531652 \cdot 10^{+174}:\\ \;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t \cdot \left(x - z\right), y, y \cdot \mathsf{fma}\left(t, -z, z \cdot t\right)\right)\\ \end{array} \]

Reproduce

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