Average Error: 7.2 → 0.3
Time: 9.4s
Precision: binary64
Cost: 15760
\[ \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 -\infty:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_2 \leq -1 \cdot 10^{-178}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 10^{-218}:\\ \;\;\;\;y \cdot \left(\left(x - z\right) \cdot t\right)\\ \mathbf{elif}\;t_2 \leq 10^{+219}:\\ \;\;\;\;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 (- INFINITY))
     t_3
     (if (<= t_2 -1e-178)
       t_1
       (if (<= t_2 1e-218)
         (* y (* (- x z) t))
         (if (<= t_2 1e+219) 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 <= -((double) INFINITY)) {
		tmp = t_3;
	} else if (t_2 <= -1e-178) {
		tmp = t_1;
	} else if (t_2 <= 1e-218) {
		tmp = y * ((x - z) * t);
	} else if (t_2 <= 1e+219) {
		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 <= Float64(-Inf))
		tmp = t_3;
	elseif (t_2 <= -1e-178)
		tmp = t_1;
	elseif (t_2 <= 1e-218)
		tmp = Float64(y * Float64(Float64(x - z) * t));
	elseif (t_2 <= 1e+219)
		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, (-Infinity)], t$95$3, If[LessEqual[t$95$2, -1e-178], t$95$1, If[LessEqual[t$95$2, 1e-218], N[(y * N[(N[(x - z), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 1e+219], 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 -\infty:\\
\;\;\;\;t_3\\

\mathbf{elif}\;t_2 \leq -1 \cdot 10^{-178}:\\
\;\;\;\;t_1\\

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

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

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


\end{array}

Error

Target

Original7.2
Target3.6
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)) < -inf.0 or 9.99999999999999965e218 < (-.f64 (*.f64 x y) (*.f64 z y))

    1. Initial program 42.5

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

      \[\leadsto \color{blue}{y \cdot \left(t \cdot \left(x - z\right)\right)} \]
      Proof
      (*.f64 y (*.f64 t (-.f64 x z))): 0 points increase in error, 0 points decrease in error
      (*.f64 y (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 x z) t))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 y (-.f64 x z)) t)): 70 points increase in error, 63 points decrease in error
      (*.f64 (Rewrite<= distribute-rgt-out--_binary64 (-.f64 (*.f64 x y) (*.f64 z y))) t): 2 points increase in error, 1 points decrease in error
    3. Applied egg-rr31.8

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

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

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

      \[\leadsto \color{blue}{\left(x - z\right) \cdot \left(y \cdot t\right)} \]
      Proof
      (*.f64 (-.f64 x z) (*.f64 y t)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 (*.f64 y t) (-.f64 x z))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*r*_binary64 (*.f64 y (*.f64 t (-.f64 x z)))): 66 points increase in error, 65 points decrease in error

    if -inf.0 < (-.f64 (*.f64 x y) (*.f64 z y)) < -9.9999999999999995e-179 or 1e-218 < (-.f64 (*.f64 x y) (*.f64 z y)) < 9.99999999999999965e218

    1. Initial program 0.3

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

      \[\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 -9.9999999999999995e-179 < (-.f64 (*.f64 x y) (*.f64 z y)) < 1e-218

    1. Initial program 9.2

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

      \[\leadsto \color{blue}{y \cdot \left(t \cdot \left(x - z\right)\right)} \]
      Proof
      (*.f64 y (*.f64 t (-.f64 x z))): 0 points increase in error, 0 points decrease in error
      (*.f64 y (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 x z) t))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 y (-.f64 x z)) t)): 70 points increase in error, 63 points decrease in error
      (*.f64 (Rewrite<= distribute-rgt-out--_binary64 (-.f64 (*.f64 x y) (*.f64 z y))) t): 2 points increase in error, 1 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y - y \cdot z \leq -\infty:\\ \;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\ \mathbf{elif}\;x \cdot y - y \cdot z \leq -1 \cdot 10^{-178}:\\ \;\;\;\;\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 10^{-218}:\\ \;\;\;\;y \cdot \left(\left(x - z\right) \cdot t\right)\\ \mathbf{elif}\;x \cdot y - y \cdot z \leq 10^{+219}:\\ \;\;\;\;\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} \]

Alternatives

Alternative 1
Error0.7
Cost2640
\[\begin{array}{l} t_1 := x \cdot y - y \cdot z\\ t_2 := y \cdot \left(\left(x - z\right) \cdot t\right)\\ \mathbf{if}\;t_1 \leq -4 \cdot 10^{+210}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq -5 \cdot 10^{-155}:\\ \;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\ \mathbf{elif}\;t_1 \leq 10^{-218}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+185}:\\ \;\;\;\;t_1 \cdot t\\ \mathbf{else}:\\ \;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\ \end{array} \]
Alternative 2
Error19.9
Cost912
\[\begin{array}{l} t_1 := y \cdot \left(z \cdot \left(-t\right)\right)\\ \mathbf{if}\;x \leq -1070770.2605367599:\\ \;\;\;\;y \cdot \left(x \cdot t\right)\\ \mathbf{elif}\;x \leq 3.445538999220402 \cdot 10^{-128}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.97930192731501 \cdot 10^{-92}:\\ \;\;\;\;\left(x \cdot y\right) \cdot t\\ \mathbf{elif}\;x \leq 1.3592837751672966 \cdot 10^{-7}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(y \cdot t\right)\\ \end{array} \]
Alternative 3
Error19.9
Cost912
\[\begin{array}{l} t_1 := t \cdot \left(z \cdot \left(-y\right)\right)\\ \mathbf{if}\;x \leq -63396.88368210693:\\ \;\;\;\;y \cdot \left(x \cdot t\right)\\ \mathbf{elif}\;x \leq 3.445538999220402 \cdot 10^{-128}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.97930192731501 \cdot 10^{-92}:\\ \;\;\;\;\left(x \cdot y\right) \cdot t\\ \mathbf{elif}\;x \leq 1.3592837751672966 \cdot 10^{-7}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(y \cdot t\right)\\ \end{array} \]
Alternative 4
Error2.6
Cost580
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \cdot 10^{+36}:\\ \;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\ \end{array} \]
Alternative 5
Error29.3
Cost452
\[\begin{array}{l} \mathbf{if}\;y \leq -1.5 \cdot 10^{+36}:\\ \;\;\;\;x \cdot \left(y \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot y\right) \cdot t\\ \end{array} \]
Alternative 6
Error29.7
Cost452
\[\begin{array}{l} \mathbf{if}\;t \leq 10^{+70}:\\ \;\;\;\;y \cdot \left(x \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot y\right) \cdot t\\ \end{array} \]
Alternative 7
Error6.9
Cost448
\[\left(x - z\right) \cdot \left(y \cdot t\right) \]
Alternative 8
Error31.6
Cost320
\[\left(x \cdot y\right) \cdot t \]

Error

Reproduce

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