Average Error: 6.9 → 0.4
Time: 10.8s
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\\ \mathbf{if}\;t_2 \leq -2 \cdot 10^{+238}:\\ \;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\ \mathbf{elif}\;t_2 \leq -2 \cdot 10^{-284}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 10^{-317}:\\ \;\;\;\;x \cdot \left(y \cdot t\right) - z \cdot \left(y \cdot t\right)\\ \mathbf{elif}\;t_2 \leq 10^{+169}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x \cdot t - z \cdot t\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 (fma (* y (- x z)) t (* t (fma y (- z) (* y z)))))
        (t_2 (- (* x y) (* y z))))
   (if (<= t_2 -2e+238)
     (* y (* t (- x z)))
     (if (<= t_2 -2e-284)
       t_1
       (if (<= t_2 1e-317)
         (- (* x (* y t)) (* z (* y t)))
         (if (<= t_2 1e+169) t_1 (* y (- (* x t) (* z 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 = fma((y * (x - z)), t, (t * fma(y, -z, (y * z))));
	double t_2 = (x * y) - (y * z);
	double tmp;
	if (t_2 <= -2e+238) {
		tmp = y * (t * (x - z));
	} else if (t_2 <= -2e-284) {
		tmp = t_1;
	} else if (t_2 <= 1e-317) {
		tmp = (x * (y * t)) - (z * (y * t));
	} else if (t_2 <= 1e+169) {
		tmp = t_1;
	} else {
		tmp = y * ((x * t) - (z * 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 = 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))
	tmp = 0.0
	if (t_2 <= -2e+238)
		tmp = Float64(y * Float64(t * Float64(x - z)));
	elseif (t_2 <= -2e-284)
		tmp = t_1;
	elseif (t_2 <= 1e-317)
		tmp = Float64(Float64(x * Float64(y * t)) - Float64(z * Float64(y * t)));
	elseif (t_2 <= 1e+169)
		tmp = t_1;
	else
		tmp = Float64(y * Float64(Float64(x * t) - Float64(z * 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[(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]}, If[LessEqual[t$95$2, -2e+238], N[(y * N[(t * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, -2e-284], t$95$1, If[LessEqual[t$95$2, 1e-317], N[(N[(x * N[(y * t), $MachinePrecision]), $MachinePrecision] - N[(z * N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 1e+169], t$95$1, N[(y * N[(N[(x * t), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\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\\
\mathbf{if}\;t_2 \leq -2 \cdot 10^{+238}:\\
\;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\

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

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

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

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


\end{array}

Error

Target

Original6.9
Target3.5
Herbie0.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 4 regimes
  2. if (-.f64 (*.f64 x y) (*.f64 z y)) < -2.0000000000000001e238

    1. Initial program 37.0

      \[\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)): 65 points increase in error, 45 points decrease in error
      (*.f64 (Rewrite<= distribute-rgt-out--_binary64 (-.f64 (*.f64 x y) (*.f64 z y))) t): 2 points increase in error, 0 points decrease in error

    if -2.0000000000000001e238 < (-.f64 (*.f64 x y) (*.f64 z y)) < -2.00000000000000007e-284 or 1.00000023e-317 < (-.f64 (*.f64 x y) (*.f64 z y)) < 9.99999999999999934e168

    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 -2.00000000000000007e-284 < (-.f64 (*.f64 x y) (*.f64 z y)) < 1.00000023e-317

    1. Initial program 16.5

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

      \[\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)): 65 points increase in error, 45 points decrease in error
      (*.f64 (Rewrite<= distribute-rgt-out--_binary64 (-.f64 (*.f64 x y) (*.f64 z y))) t): 2 points increase in error, 0 points decrease in error
    3. Applied egg-rr0.1

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

    if 9.99999999999999934e168 < (-.f64 (*.f64 x y) (*.f64 z y))

    1. Initial program 24.8

      \[\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)} \]
      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)): 65 points increase in error, 45 points decrease in error
      (*.f64 (Rewrite<= distribute-rgt-out--_binary64 (-.f64 (*.f64 x y) (*.f64 z y))) t): 2 points increase in error, 0 points decrease in error
    3. Applied egg-rr2.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y - y \cdot z \leq -2 \cdot 10^{+238}:\\ \;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\ \mathbf{elif}\;x \cdot y - y \cdot z \leq -2 \cdot 10^{-284}:\\ \;\;\;\;\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^{-317}:\\ \;\;\;\;x \cdot \left(y \cdot t\right) - z \cdot \left(y \cdot t\right)\\ \mathbf{elif}\;x \cdot y - y \cdot z \leq 10^{+169}:\\ \;\;\;\;\mathsf{fma}\left(y \cdot \left(x - z\right), t, t \cdot \mathsf{fma}\left(y, -z, y \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x \cdot t - z \cdot t\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.5
Cost2640
\[\begin{array}{l} t_1 := t \cdot \left(y \cdot \left(x - z\right)\right)\\ t_2 := x \cdot y - y \cdot z\\ t_3 := y \cdot \left(t \cdot \left(x - z\right)\right)\\ \mathbf{if}\;t_2 \leq -2 \cdot 10^{+238}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_2 \leq -5 \cdot 10^{-305}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 10^{-317}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_2 \leq 10^{+169}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x \cdot t - z \cdot t\right)\\ \end{array} \]
Alternative 2
Error0.5
Cost2640
\[\begin{array}{l} t_1 := t \cdot \left(y \cdot \left(x - z\right)\right)\\ t_2 := x \cdot y - y \cdot z\\ \mathbf{if}\;t_2 \leq -2 \cdot 10^{+238}:\\ \;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\ \mathbf{elif}\;t_2 \leq -2 \cdot 10^{-284}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 10^{-317}:\\ \;\;\;\;\left(y \cdot t\right) \cdot \frac{1}{\frac{1}{x - z}}\\ \mathbf{elif}\;t_2 \leq 10^{+169}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x \cdot t - z \cdot t\right)\\ \end{array} \]
Alternative 3
Error0.5
Cost2640
\[\begin{array}{l} t_1 := t \cdot \left(y \cdot \left(x - z\right)\right)\\ t_2 := x \cdot y - y \cdot z\\ \mathbf{if}\;t_2 \leq -2 \cdot 10^{+238}:\\ \;\;\;\;y \cdot \left(t \cdot \left(x - z\right)\right)\\ \mathbf{elif}\;t_2 \leq -2 \cdot 10^{-284}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 10^{-317}:\\ \;\;\;\;x \cdot \left(y \cdot t\right) - z \cdot \left(y \cdot t\right)\\ \mathbf{elif}\;t_2 \leq 10^{+169}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x \cdot t - z \cdot t\right)\\ \end{array} \]
Alternative 4
Error20.7
Cost1308
\[\begin{array}{l} t_1 := x \cdot \left(y \cdot t\right)\\ t_2 := y \cdot \left(x \cdot t\right)\\ t_3 := t \cdot \left(z \cdot \left(-y\right)\right)\\ \mathbf{if}\;x \leq -1.5160411728458046 \cdot 10^{+46}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.6446502769178921 \cdot 10^{-35}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -1.6383415681467727 \cdot 10^{-85}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.4249787263865344 \cdot 10^{-234}:\\ \;\;\;\;\left(z \cdot t\right) \cdot \left(-y\right)\\ \mathbf{elif}\;x \leq 2.1422372796740175 \cdot 10^{-122}:\\ \;\;\;\;z \cdot \left(t \cdot \left(-y\right)\right)\\ \mathbf{elif}\;x \leq 6.84166318247281 \cdot 10^{-85}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.883398283140772 \cdot 10^{-55}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error20.7
Cost1176
\[\begin{array}{l} t_1 := x \cdot \left(y \cdot t\right)\\ t_2 := y \cdot \left(x \cdot t\right)\\ t_3 := \left(z \cdot t\right) \cdot \left(-y\right)\\ \mathbf{if}\;x \leq -1.5160411728458046 \cdot 10^{+46}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.6446502769178921 \cdot 10^{-35}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq -1.6383415681467727 \cdot 10^{-85}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.1422372796740175 \cdot 10^{-122}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;x \leq 6.84166318247281 \cdot 10^{-85}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.883398283140772 \cdot 10^{-55}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error20.9
Cost1176
\[\begin{array}{l} t_1 := y \cdot \left(x \cdot t\right)\\ t_2 := \left(z \cdot t\right) \cdot \left(-y\right)\\ \mathbf{if}\;x \leq -1.5160411728458046 \cdot 10^{+46}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.6446502769178921 \cdot 10^{-35}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -2.948675441101861 \cdot 10^{-108}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.1422372796740175 \cdot 10^{-122}:\\ \;\;\;\;z \cdot \left(t \cdot \left(-y\right)\right)\\ \mathbf{elif}\;x \leq 6.84166318247281 \cdot 10^{-85}:\\ \;\;\;\;x \cdot \left(y \cdot t\right)\\ \mathbf{elif}\;x \leq 4.883398283140772 \cdot 10^{-55}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error7.9
Cost712
\[\begin{array}{l} t_1 := y \cdot \left(x \cdot t\right)\\ \mathbf{if}\;x \leq -1 \cdot 10^{+195}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 10^{+155}:\\ \;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error7.0
Cost712
\[\begin{array}{l} t_1 := y \cdot \left(t \cdot \left(x - z\right)\right)\\ \mathbf{if}\;z \leq 7.773364321466139 \cdot 10^{-296}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 7.428723056914474 \cdot 10^{-84}:\\ \;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error31.4
Cost320
\[y \cdot \left(x \cdot t\right) \]

Error

Reproduce

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