Average Error: 7.1 → 1.4
Time: 9.4s
Precision: binary64
Cost: 14728
\[ \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\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+218}:\\ \;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+277}:\\ \;\;\;\;\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} \]
(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))))
   (if (<= t_1 -2e+218)
     (* (- x z) (* y t))
     (if (<= t_1 5e+277)
       (fma (* y (- x z)) t (* t (fma y (- z) (* y z))))
       (* 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 = (x * y) - (y * z);
	double tmp;
	if (t_1 <= -2e+218) {
		tmp = (x - z) * (y * t);
	} else if (t_1 <= 5e+277) {
		tmp = fma((y * (x - z)), t, (t * fma(y, -z, (y * z))));
	} 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 = Float64(Float64(x * y) - Float64(y * z))
	tmp = 0.0
	if (t_1 <= -2e+218)
		tmp = Float64(Float64(x - z) * Float64(y * t));
	elseif (t_1 <= 5e+277)
		tmp = fma(Float64(y * Float64(x - z)), t, Float64(t * fma(y, Float64(-z), Float64(y * z))));
	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[(x * y), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+218], N[(N[(x - z), $MachinePrecision] * N[(y * t), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e+277], N[(N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision] * t + N[(t * N[(y * (-z) + N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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 := x \cdot y - y \cdot z\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+218}:\\
\;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\

\mathbf{elif}\;t_1 \leq 5 \cdot 10^{+277}:\\
\;\;\;\;\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}

Error

Target

Original7.1
Target3.6
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)) < -2.00000000000000017e218

    1. Initial program 29.4

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

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

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

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

      \[\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)))): 55 points increase in error, 69 points decrease in error

    if -2.00000000000000017e218 < (-.f64 (*.f64 x y) (*.f64 z y)) < 4.99999999999999982e277

    1. Initial program 1.6

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

      \[\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 4.99999999999999982e277 < (-.f64 (*.f64 x y) (*.f64 z y))

    1. Initial program 48.3

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

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

      \[\leadsto y \cdot \color{blue}{\left(x \cdot t + \left(-z\right) \cdot t\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 -2 \cdot 10^{+218}:\\ \;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\ \mathbf{elif}\;x \cdot y - y \cdot z \leq 5 \cdot 10^{+277}:\\ \;\;\;\;\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
Error1.7
Cost1736
\[\begin{array}{l} t_1 := x \cdot y - y \cdot z\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+218}:\\ \;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\ \mathbf{elif}\;t_1 \leq 10^{+162}:\\ \;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\frac{1}{x - z}}{y \cdot t}}\\ \end{array} \]
Alternative 2
Error1.5
Cost1480
\[\begin{array}{l} t_1 := x \cdot y - y \cdot z\\ t_2 := \left(x - z\right) \cdot \left(y \cdot t\right)\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+218}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 10^{+248}:\\ \;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error19.5
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -33268983442043268:\\ \;\;\;\;y \cdot \left(x \cdot t\right)\\ \mathbf{elif}\;x \leq 2.019052354148519 \cdot 10^{-40}:\\ \;\;\;\;\left(z \cdot t\right) \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{t}{\frac{\frac{1}{y}}{x}}\\ \end{array} \]
Alternative 4
Error7.5
Cost712
\[\begin{array}{l} t_1 := \left(x - z\right) \cdot \left(y \cdot t\right)\\ \mathbf{if}\;x \leq -7.21651413342849 \cdot 10^{-207}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.0374068095533603 \cdot 10^{-235}:\\ \;\;\;\;t \cdot \left(z \cdot \left(-y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error19.6
Cost648
\[\begin{array}{l} \mathbf{if}\;x \leq -33268983442043268:\\ \;\;\;\;y \cdot \left(x \cdot t\right)\\ \mathbf{elif}\;x \leq 2.019052354148519 \cdot 10^{-40}:\\ \;\;\;\;\left(z \cdot t\right) \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot y\right) \cdot t\\ \end{array} \]
Alternative 6
Error30.0
Cost452
\[\begin{array}{l} \mathbf{if}\;t \leq 1.028861000513625 \cdot 10^{-83}:\\ \;\;\;\;y \cdot \left(x \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot y\right) \cdot t\\ \end{array} \]
Alternative 7
Error30.1
Cost452
\[\begin{array}{l} \mathbf{if}\;t \leq 4 \cdot 10^{+73}:\\ \;\;\;\;y \cdot \left(x \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(y \cdot t\right)\\ \end{array} \]
Alternative 8
Error32.0
Cost320
\[\left(x \cdot y\right) \cdot t \]

Error

Reproduce

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