?

Average Error: 7.0 → 1.1
Time: 10.0s
Precision: binary64
Cost: 8588

?

\[ \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 := t \cdot \left(y \cdot \left(x - z\right)\right)\\ t_2 := x \cdot y - y \cdot z\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\ \mathbf{elif}\;t_2 \leq -1 \cdot 10^{-102}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 10^{-146}:\\ \;\;\;\;\mathsf{fma}\left(y, x \cdot t, z \cdot \left(y \cdot \left(-t\right)\right)\right)\\ \mathbf{elif}\;t_2 \leq 10^{+164}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(\left(x - z\right) \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 (* t (* y (- x z)))) (t_2 (- (* x y) (* y z))))
   (if (<= t_2 (- INFINITY))
     (* (- x z) (* y t))
     (if (<= t_2 -1e-102)
       t_1
       (if (<= t_2 1e-146)
         (fma y (* x t) (* z (* y (- t))))
         (if (<= t_2 1e+164) t_1 (* y (* (- x 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 = t * (y * (x - z));
	double t_2 = (x * y) - (y * z);
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = (x - z) * (y * t);
	} else if (t_2 <= -1e-102) {
		tmp = t_1;
	} else if (t_2 <= 1e-146) {
		tmp = fma(y, (x * t), (z * (y * -t)));
	} else if (t_2 <= 1e+164) {
		tmp = t_1;
	} else {
		tmp = y * ((x - 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(t * Float64(y * Float64(x - z)))
	t_2 = Float64(Float64(x * y) - Float64(y * z))
	tmp = 0.0
	if (t_2 <= Float64(-Inf))
		tmp = Float64(Float64(x - z) * Float64(y * t));
	elseif (t_2 <= -1e-102)
		tmp = t_1;
	elseif (t_2 <= 1e-146)
		tmp = fma(y, Float64(x * t), Float64(z * Float64(y * Float64(-t))));
	elseif (t_2 <= 1e+164)
		tmp = t_1;
	else
		tmp = Float64(y * Float64(Float64(x - 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[(t * N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * y), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], N[(N[(x - z), $MachinePrecision] * N[(y * t), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, -1e-102], t$95$1, If[LessEqual[t$95$2, 1e-146], N[(y * N[(x * t), $MachinePrecision] + N[(z * N[(y * (-t)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 1e+164], t$95$1, N[(y * N[(N[(x - z), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision]]]]]]]
\left(x \cdot y - z \cdot y\right) \cdot t
\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 -\infty:\\
\;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\

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

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

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

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


\end{array}

Error?

Target

Original7.0
Target3.4
Herbie1.1
\[\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)) < -inf.0

    1. Initial program 64.0

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

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

      [Start]64.0

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

      distribute-rgt-out-- [=>]64.0

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

      associate-*l* [=>]0.3

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

      *-commutative [=>]0.3

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

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

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

      [Start]0.3

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

      mul-1-neg [=>]0.3

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

      associate-*r* [=>]0.3

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

      associate-*r* [=>]0.3

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

      distribute-rgt-neg-out [<=]0.3

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

      distribute-lft-in [<=]0.3

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

      sub-neg [<=]0.3

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

      *-commutative [=>]0.3

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

    if -inf.0 < (-.f64 (*.f64 x y) (*.f64 z y)) < -9.99999999999999933e-103 or 1.00000000000000003e-146 < (-.f64 (*.f64 x y) (*.f64 z y)) < 1e164

    1. Initial program 0.2

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

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

      [Start]0.2

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

      distribute-rgt-out-- [=>]0.2

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

    if -9.99999999999999933e-103 < (-.f64 (*.f64 x y) (*.f64 z y)) < 1.00000000000000003e-146

    1. Initial program 5.4

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

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

      [Start]5.4

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

      distribute-rgt-out-- [=>]5.4

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

      associate-*l* [=>]2.7

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

      *-commutative [=>]2.7

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

      \[\leadsto \color{blue}{y \cdot \left(t \cdot x\right) + -1 \cdot \left(y \cdot \left(t \cdot z\right)\right)} \]
    4. Simplified2.8

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

      [Start]2.7

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

      mul-1-neg [=>]2.7

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

      associate-*r* [=>]3.2

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

      associate-*r* [=>]2.8

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

      distribute-rgt-neg-out [<=]2.8

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

      distribute-lft-in [<=]2.8

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

      sub-neg [<=]2.8

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

      *-commutative [=>]2.8

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

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

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

      [Start]2.7

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

      mul-1-neg [=>]2.7

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

      associate-*r* [=>]2.9

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

      distribute-rgt-neg-out [<=]2.9

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

      *-lft-identity [<=]2.9

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

      *-commutative [<=]2.9

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

      fma-def [=>]2.9

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

      *-commutative [=>]2.9

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

      *-lft-identity [=>]2.9

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

    if 1e164 < (-.f64 (*.f64 x y) (*.f64 z y))

    1. Initial program 24.0

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

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

      [Start]24.0

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

      distribute-rgt-out-- [=>]24.0

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

      associate-*l* [=>]2.3

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

      *-commutative [=>]2.3

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

    \[\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^{-102}:\\ \;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\ \mathbf{elif}\;x \cdot y - y \cdot z \leq 10^{-146}:\\ \;\;\;\;\mathsf{fma}\left(y, x \cdot t, z \cdot \left(y \cdot \left(-t\right)\right)\right)\\ \mathbf{elif}\;x \cdot y - y \cdot z \leq 10^{+164}:\\ \;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(\left(x - z\right) \cdot t\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.6
Cost2512
\[\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 -\infty:\\ \;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\ \mathbf{elif}\;t_2 \leq -5 \cdot 10^{-236}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 10^{-181}:\\ \;\;\;\;y \cdot \frac{t}{\frac{1}{x - z}}\\ \mathbf{elif}\;t_2 \leq 10^{+164}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(\left(x - z\right) \cdot t\right)\\ \end{array} \]
Alternative 2
Error0.6
Cost2512
\[\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 := \left(x - z\right) \cdot t\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\ \mathbf{elif}\;t_2 \leq -5 \cdot 10^{-236}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 10^{-181}:\\ \;\;\;\;\frac{y}{\frac{1}{t_3}}\\ \mathbf{elif}\;t_2 \leq 10^{+164}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot t_3\\ \end{array} \]
Alternative 3
Error20.2
Cost912
\[\begin{array}{l} t_1 := z \cdot \left(y \cdot \left(-t\right)\right)\\ \mathbf{if}\;z \leq -1.95 \cdot 10^{-11}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.8 \cdot 10^{-141}:\\ \;\;\;\;y \cdot \left(x \cdot t\right)\\ \mathbf{elif}\;z \leq 1.3 \cdot 10^{+64}:\\ \;\;\;\;t \cdot \left(x \cdot y\right)\\ \mathbf{elif}\;z \leq 1.6 \cdot 10^{+286}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(z \cdot \left(-t\right)\right)\\ \end{array} \]
Alternative 4
Error19.8
Cost649
\[\begin{array}{l} \mathbf{if}\;z \leq -8.5 \cdot 10^{-12} \lor \neg \left(z \leq 3.9 \cdot 10^{-32}\right):\\ \;\;\;\;y \cdot \left(z \cdot \left(-t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x \cdot t\right)\\ \end{array} \]
Alternative 5
Error2.7
Cost580
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \cdot 10^{+25}:\\ \;\;\;\;y \cdot \left(\left(x - z\right) \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\ \end{array} \]
Alternative 6
Error2.7
Cost580
\[\begin{array}{l} \mathbf{if}\;t \leq 2 \cdot 10^{+50}:\\ \;\;\;\;y \cdot \left(\left(x - z\right) \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x - z\right) \cdot \left(y \cdot t\right)\\ \end{array} \]
Alternative 7
Error29.8
Cost452
\[\begin{array}{l} \mathbf{if}\;t \leq 5 \cdot 10^{+34}:\\ \;\;\;\;y \cdot \left(x \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(y \cdot t\right)\\ \end{array} \]
Alternative 8
Error7.3
Cost448
\[y \cdot \left(\left(x - z\right) \cdot t\right) \]
Alternative 9
Error31.9
Cost320
\[x \cdot \left(y \cdot t\right) \]

Error

Reproduce?

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