Linear.V3:cross from linear-1.19.1.3

Percentage Accurate: 99.4% → 99.7%
Time: 3.2s
Alternatives: 6
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ x \cdot y - z \cdot t \end{array} \]
(FPCore (x y z t) :precision binary64 (- (* x y) (* z t)))
double code(double x, double y, double z, double t) {
	return (x * y) - (z * t);
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = (x * y) - (z * t)
end function
public static double code(double x, double y, double z, double t) {
	return (x * y) - (z * t);
}
def code(x, y, z, t):
	return (x * y) - (z * t)
function code(x, y, z, t)
	return Float64(Float64(x * y) - Float64(z * t))
end
function tmp = code(x, y, z, t)
	tmp = (x * y) - (z * t);
end
code[x_, y_, z_, t_] := N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot y - z \cdot t
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 6 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x \cdot y - z \cdot t \end{array} \]
(FPCore (x y z t) :precision binary64 (- (* x y) (* z t)))
double code(double x, double y, double z, double t) {
	return (x * y) - (z * t);
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = (x * y) - (z * t)
end function
public static double code(double x, double y, double z, double t) {
	return (x * y) - (z * t);
}
def code(x, y, z, t):
	return (x * y) - (z * t)
function code(x, y, z, t)
	return Float64(Float64(x * y) - Float64(z * t))
end
function tmp = code(x, y, z, t)
	tmp = (x * y) - (z * t);
end
code[x_, y_, z_, t_] := N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot y - z \cdot t
\end{array}

Alternative 1: 99.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(y, x, \left(-t\right) \cdot z\right) \end{array} \]
(FPCore (x y z t) :precision binary64 (fma y x (* (- t) z)))
double code(double x, double y, double z, double t) {
	return fma(y, x, (-t * z));
}
function code(x, y, z, t)
	return fma(y, x, Float64(Float64(-t) * z))
end
code[x_, y_, z_, t_] := N[(y * x + N[((-t) * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(y, x, \left(-t\right) \cdot z\right)
\end{array}
Derivation
  1. Initial program 98.4%

    \[x \cdot y - z \cdot t \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift--.f64N/A

      \[\leadsto \color{blue}{x \cdot y - z \cdot t} \]
    2. sub-negN/A

      \[\leadsto \color{blue}{x \cdot y + \left(\mathsf{neg}\left(z \cdot t\right)\right)} \]
    3. lift-*.f64N/A

      \[\leadsto \color{blue}{x \cdot y} + \left(\mathsf{neg}\left(z \cdot t\right)\right) \]
    4. *-commutativeN/A

      \[\leadsto \color{blue}{y \cdot x} + \left(\mathsf{neg}\left(z \cdot t\right)\right) \]
    5. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, \mathsf{neg}\left(z \cdot t\right)\right)} \]
    6. lift-*.f64N/A

      \[\leadsto \mathsf{fma}\left(y, x, \mathsf{neg}\left(\color{blue}{z \cdot t}\right)\right) \]
    7. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(y, x, \mathsf{neg}\left(\color{blue}{t \cdot z}\right)\right) \]
    8. distribute-lft-neg-inN/A

      \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{\left(\mathsf{neg}\left(t\right)\right) \cdot z}\right) \]
    9. lower-*.f64N/A

      \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{\left(\mathsf{neg}\left(t\right)\right) \cdot z}\right) \]
    10. lower-neg.f6499.2

      \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{\left(-t\right)} \cdot z\right) \]
  4. Applied rewrites99.2%

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

Alternative 2: 74.0% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -2 \cdot 10^{-11} \lor \neg \left(x \cdot y \leq 5 \cdot 10^{-63}\right):\\ \;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-z\right) \cdot t\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (or (<= (* x y) -2e-11) (not (<= (* x y) 5e-63)))
   (fma y x (* t z))
   (* (- z) t)))
double code(double x, double y, double z, double t) {
	double tmp;
	if (((x * y) <= -2e-11) || !((x * y) <= 5e-63)) {
		tmp = fma(y, x, (t * z));
	} else {
		tmp = -z * t;
	}
	return tmp;
}
function code(x, y, z, t)
	tmp = 0.0
	if ((Float64(x * y) <= -2e-11) || !(Float64(x * y) <= 5e-63))
		tmp = fma(y, x, Float64(t * z));
	else
		tmp = Float64(Float64(-z) * t);
	end
	return tmp
end
code[x_, y_, z_, t_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -2e-11], N[Not[LessEqual[N[(x * y), $MachinePrecision], 5e-63]], $MachinePrecision]], N[(y * x + N[(t * z), $MachinePrecision]), $MachinePrecision], N[((-z) * t), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -2 \cdot 10^{-11} \lor \neg \left(x \cdot y \leq 5 \cdot 10^{-63}\right):\\
\;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x y) < -1.99999999999999988e-11 or 5.0000000000000002e-63 < (*.f64 x y)

    1. Initial program 97.1%

      \[x \cdot y - z \cdot t \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto \color{blue}{x \cdot y - z \cdot t} \]
      2. sub-negN/A

        \[\leadsto \color{blue}{x \cdot y + \left(\mathsf{neg}\left(z \cdot t\right)\right)} \]
      3. lift-*.f64N/A

        \[\leadsto \color{blue}{x \cdot y} + \left(\mathsf{neg}\left(z \cdot t\right)\right) \]
      4. *-commutativeN/A

        \[\leadsto \color{blue}{y \cdot x} + \left(\mathsf{neg}\left(z \cdot t\right)\right) \]
      5. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, \mathsf{neg}\left(z \cdot t\right)\right)} \]
      6. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(y, x, \mathsf{neg}\left(\color{blue}{z \cdot t}\right)\right) \]
      7. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(y, x, \mathsf{neg}\left(\color{blue}{t \cdot z}\right)\right) \]
      8. distribute-lft-neg-inN/A

        \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{\left(\mathsf{neg}\left(t\right)\right) \cdot z}\right) \]
      9. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{\left(\mathsf{neg}\left(t\right)\right) \cdot z}\right) \]
      10. lower-neg.f6498.6

        \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{\left(-t\right)} \cdot z\right) \]
    4. Applied rewrites98.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, \left(-t\right) \cdot z\right)} \]
    5. Step-by-step derivation
      1. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{\left(\mathsf{neg}\left(t\right)\right)} \cdot z\right) \]
      2. neg-sub0N/A

        \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{\left(0 - t\right)} \cdot z\right) \]
      3. flip3--N/A

        \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{\frac{{0}^{3} - {t}^{3}}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)}} \cdot z\right) \]
      4. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\color{blue}{0} - {t}^{3}}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      5. sub0-negN/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\color{blue}{\mathsf{neg}\left({t}^{3}\right)}}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      6. sqr-powN/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\mathsf{neg}\left(\color{blue}{{t}^{\left(\frac{3}{2}\right)} \cdot {t}^{\left(\frac{3}{2}\right)}}\right)}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      7. pow-prod-downN/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\mathsf{neg}\left(\color{blue}{{\left(t \cdot t\right)}^{\left(\frac{3}{2}\right)}}\right)}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      8. sqr-negN/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\mathsf{neg}\left({\color{blue}{\left(\left(\mathsf{neg}\left(t\right)\right) \cdot \left(\mathsf{neg}\left(t\right)\right)\right)}}^{\left(\frac{3}{2}\right)}\right)}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      9. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\mathsf{neg}\left({\left(\color{blue}{\left(-t\right)} \cdot \left(\mathsf{neg}\left(t\right)\right)\right)}^{\left(\frac{3}{2}\right)}\right)}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      10. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\mathsf{neg}\left({\left(\left(-t\right) \cdot \color{blue}{\left(-t\right)}\right)}^{\left(\frac{3}{2}\right)}\right)}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      11. pow-prod-downN/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\mathsf{neg}\left(\color{blue}{{\left(-t\right)}^{\left(\frac{3}{2}\right)} \cdot {\left(-t\right)}^{\left(\frac{3}{2}\right)}}\right)}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      12. sqr-powN/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\mathsf{neg}\left(\color{blue}{{\left(-t\right)}^{3}}\right)}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      13. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\mathsf{neg}\left({\color{blue}{\left(\mathsf{neg}\left(t\right)\right)}}^{3}\right)}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      14. cube-negN/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left({t}^{3}\right)\right)}\right)}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      15. sub0-negN/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\mathsf{neg}\left(\color{blue}{\left(0 - {t}^{3}\right)}\right)}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      16. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\mathsf{neg}\left(\left(\color{blue}{{0}^{3}} - {t}^{3}\right)\right)}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      17. distribute-neg-fracN/A

        \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{\left(\mathsf{neg}\left(\frac{{0}^{3} - {t}^{3}}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)}\right)\right)} \cdot z\right) \]
      18. flip3--N/A

        \[\leadsto \mathsf{fma}\left(y, x, \left(\mathsf{neg}\left(\color{blue}{\left(0 - t\right)}\right)\right) \cdot z\right) \]
      19. neg-sub0N/A

        \[\leadsto \mathsf{fma}\left(y, x, \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(t\right)\right)}\right)\right) \cdot z\right) \]
      20. remove-double-neg70.9

        \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{t} \cdot z\right) \]
    6. Applied rewrites70.9%

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

    if -1.99999999999999988e-11 < (*.f64 x y) < 5.0000000000000002e-63

    1. Initial program 100.0%

      \[x \cdot y - z \cdot t \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{-1 \cdot \left(t \cdot z\right)} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto -1 \cdot \color{blue}{\left(z \cdot t\right)} \]
      2. associate-*r*N/A

        \[\leadsto \color{blue}{\left(-1 \cdot z\right) \cdot t} \]
      3. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(-1 \cdot z\right) \cdot t} \]
      4. mul-1-negN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(z\right)\right)} \cdot t \]
      5. lower-neg.f6486.6

        \[\leadsto \color{blue}{\left(-z\right)} \cdot t \]
    5. Applied rewrites86.6%

      \[\leadsto \color{blue}{\left(-z\right) \cdot t} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification78.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -2 \cdot 10^{-11} \lor \neg \left(x \cdot y \leq 5 \cdot 10^{-63}\right):\\ \;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-z\right) \cdot t\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 74.5% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -2 \cdot 10^{-11}:\\ \;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\ \mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{-63}:\\ \;\;\;\;\left(-z\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, t, y \cdot x\right)\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (<= (* x y) -2e-11)
   (fma y x (* t z))
   (if (<= (* x y) 5e-63) (* (- z) t) (fma z t (* y x)))))
double code(double x, double y, double z, double t) {
	double tmp;
	if ((x * y) <= -2e-11) {
		tmp = fma(y, x, (t * z));
	} else if ((x * y) <= 5e-63) {
		tmp = -z * t;
	} else {
		tmp = fma(z, t, (y * x));
	}
	return tmp;
}
function code(x, y, z, t)
	tmp = 0.0
	if (Float64(x * y) <= -2e-11)
		tmp = fma(y, x, Float64(t * z));
	elseif (Float64(x * y) <= 5e-63)
		tmp = Float64(Float64(-z) * t);
	else
		tmp = fma(z, t, Float64(y * x));
	end
	return tmp
end
code[x_, y_, z_, t_] := If[LessEqual[N[(x * y), $MachinePrecision], -2e-11], N[(y * x + N[(t * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 5e-63], N[((-z) * t), $MachinePrecision], N[(z * t + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -2 \cdot 10^{-11}:\\
\;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 x y) < -1.99999999999999988e-11

    1. Initial program 96.4%

      \[x \cdot y - z \cdot t \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto \color{blue}{x \cdot y - z \cdot t} \]
      2. sub-negN/A

        \[\leadsto \color{blue}{x \cdot y + \left(\mathsf{neg}\left(z \cdot t\right)\right)} \]
      3. lift-*.f64N/A

        \[\leadsto \color{blue}{x \cdot y} + \left(\mathsf{neg}\left(z \cdot t\right)\right) \]
      4. *-commutativeN/A

        \[\leadsto \color{blue}{y \cdot x} + \left(\mathsf{neg}\left(z \cdot t\right)\right) \]
      5. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, \mathsf{neg}\left(z \cdot t\right)\right)} \]
      6. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(y, x, \mathsf{neg}\left(\color{blue}{z \cdot t}\right)\right) \]
      7. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(y, x, \mathsf{neg}\left(\color{blue}{t \cdot z}\right)\right) \]
      8. distribute-lft-neg-inN/A

        \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{\left(\mathsf{neg}\left(t\right)\right) \cdot z}\right) \]
      9. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{\left(\mathsf{neg}\left(t\right)\right) \cdot z}\right) \]
      10. lower-neg.f6498.2

        \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{\left(-t\right)} \cdot z\right) \]
    4. Applied rewrites98.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, \left(-t\right) \cdot z\right)} \]
    5. Step-by-step derivation
      1. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{\left(\mathsf{neg}\left(t\right)\right)} \cdot z\right) \]
      2. neg-sub0N/A

        \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{\left(0 - t\right)} \cdot z\right) \]
      3. flip3--N/A

        \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{\frac{{0}^{3} - {t}^{3}}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)}} \cdot z\right) \]
      4. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\color{blue}{0} - {t}^{3}}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      5. sub0-negN/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\color{blue}{\mathsf{neg}\left({t}^{3}\right)}}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      6. sqr-powN/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\mathsf{neg}\left(\color{blue}{{t}^{\left(\frac{3}{2}\right)} \cdot {t}^{\left(\frac{3}{2}\right)}}\right)}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      7. pow-prod-downN/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\mathsf{neg}\left(\color{blue}{{\left(t \cdot t\right)}^{\left(\frac{3}{2}\right)}}\right)}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      8. sqr-negN/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\mathsf{neg}\left({\color{blue}{\left(\left(\mathsf{neg}\left(t\right)\right) \cdot \left(\mathsf{neg}\left(t\right)\right)\right)}}^{\left(\frac{3}{2}\right)}\right)}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      9. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\mathsf{neg}\left({\left(\color{blue}{\left(-t\right)} \cdot \left(\mathsf{neg}\left(t\right)\right)\right)}^{\left(\frac{3}{2}\right)}\right)}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      10. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\mathsf{neg}\left({\left(\left(-t\right) \cdot \color{blue}{\left(-t\right)}\right)}^{\left(\frac{3}{2}\right)}\right)}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      11. pow-prod-downN/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\mathsf{neg}\left(\color{blue}{{\left(-t\right)}^{\left(\frac{3}{2}\right)} \cdot {\left(-t\right)}^{\left(\frac{3}{2}\right)}}\right)}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      12. sqr-powN/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\mathsf{neg}\left(\color{blue}{{\left(-t\right)}^{3}}\right)}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      13. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\mathsf{neg}\left({\color{blue}{\left(\mathsf{neg}\left(t\right)\right)}}^{3}\right)}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      14. cube-negN/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left({t}^{3}\right)\right)}\right)}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      15. sub0-negN/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\mathsf{neg}\left(\color{blue}{\left(0 - {t}^{3}\right)}\right)}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      16. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(y, x, \frac{\mathsf{neg}\left(\left(\color{blue}{{0}^{3}} - {t}^{3}\right)\right)}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)} \cdot z\right) \]
      17. distribute-neg-fracN/A

        \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{\left(\mathsf{neg}\left(\frac{{0}^{3} - {t}^{3}}{0 \cdot 0 + \left(t \cdot t + 0 \cdot t\right)}\right)\right)} \cdot z\right) \]
      18. flip3--N/A

        \[\leadsto \mathsf{fma}\left(y, x, \left(\mathsf{neg}\left(\color{blue}{\left(0 - t\right)}\right)\right) \cdot z\right) \]
      19. neg-sub0N/A

        \[\leadsto \mathsf{fma}\left(y, x, \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(t\right)\right)}\right)\right) \cdot z\right) \]
      20. remove-double-neg72.5

        \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{t} \cdot z\right) \]
    6. Applied rewrites72.5%

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

    if -1.99999999999999988e-11 < (*.f64 x y) < 5.0000000000000002e-63

    1. Initial program 100.0%

      \[x \cdot y - z \cdot t \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{-1 \cdot \left(t \cdot z\right)} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto -1 \cdot \color{blue}{\left(z \cdot t\right)} \]
      2. associate-*r*N/A

        \[\leadsto \color{blue}{\left(-1 \cdot z\right) \cdot t} \]
      3. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(-1 \cdot z\right) \cdot t} \]
      4. mul-1-negN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(z\right)\right)} \cdot t \]
      5. lower-neg.f6486.6

        \[\leadsto \color{blue}{\left(-z\right)} \cdot t \]
    5. Applied rewrites86.6%

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

    if 5.0000000000000002e-63 < (*.f64 x y)

    1. Initial program 97.6%

      \[x \cdot y - z \cdot t \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto \color{blue}{x \cdot y - z \cdot t} \]
      2. sub-negN/A

        \[\leadsto \color{blue}{x \cdot y + \left(\mathsf{neg}\left(z \cdot t\right)\right)} \]
      3. +-commutativeN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(z \cdot t\right)\right) + x \cdot y} \]
      4. lift-*.f64N/A

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{z \cdot t}\right)\right) + x \cdot y \]
      5. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(z\right)\right) \cdot t} + x \cdot y \]
      6. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(z\right), t, x \cdot y\right)} \]
      7. lower-neg.f6498.8

        \[\leadsto \mathsf{fma}\left(\color{blue}{-z}, t, x \cdot y\right) \]
      8. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(-z, t, \color{blue}{x \cdot y}\right) \]
      9. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(-z, t, \color{blue}{y \cdot x}\right) \]
      10. lower-*.f6498.8

        \[\leadsto \mathsf{fma}\left(-z, t, \color{blue}{y \cdot x}\right) \]
    4. Applied rewrites98.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-z, t, y \cdot x\right)} \]
    5. Step-by-step derivation
      1. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{neg}\left(z\right)}, t, y \cdot x\right) \]
      2. neg-sub0N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{0 - z}, t, y \cdot x\right) \]
      3. flip3--N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{{0}^{3} - {z}^{3}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}}, t, y \cdot x\right) \]
      4. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{0} - {z}^{3}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, t, y \cdot x\right) \]
      5. sub0-negN/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\mathsf{neg}\left({z}^{3}\right)}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, t, y \cdot x\right) \]
      6. sqr-powN/A

        \[\leadsto \mathsf{fma}\left(\frac{\mathsf{neg}\left(\color{blue}{{z}^{\left(\frac{3}{2}\right)} \cdot {z}^{\left(\frac{3}{2}\right)}}\right)}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, t, y \cdot x\right) \]
      7. pow-prod-downN/A

        \[\leadsto \mathsf{fma}\left(\frac{\mathsf{neg}\left(\color{blue}{{\left(z \cdot z\right)}^{\left(\frac{3}{2}\right)}}\right)}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, t, y \cdot x\right) \]
      8. sqr-negN/A

        \[\leadsto \mathsf{fma}\left(\frac{\mathsf{neg}\left({\color{blue}{\left(\left(\mathsf{neg}\left(z\right)\right) \cdot \left(\mathsf{neg}\left(z\right)\right)\right)}}^{\left(\frac{3}{2}\right)}\right)}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, t, y \cdot x\right) \]
      9. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\mathsf{neg}\left({\left(\color{blue}{\left(-z\right)} \cdot \left(\mathsf{neg}\left(z\right)\right)\right)}^{\left(\frac{3}{2}\right)}\right)}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, t, y \cdot x\right) \]
      10. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\mathsf{neg}\left({\left(\left(-z\right) \cdot \color{blue}{\left(-z\right)}\right)}^{\left(\frac{3}{2}\right)}\right)}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, t, y \cdot x\right) \]
      11. pow-prod-downN/A

        \[\leadsto \mathsf{fma}\left(\frac{\mathsf{neg}\left(\color{blue}{{\left(-z\right)}^{\left(\frac{3}{2}\right)} \cdot {\left(-z\right)}^{\left(\frac{3}{2}\right)}}\right)}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, t, y \cdot x\right) \]
      12. sqr-powN/A

        \[\leadsto \mathsf{fma}\left(\frac{\mathsf{neg}\left(\color{blue}{{\left(-z\right)}^{3}}\right)}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, t, y \cdot x\right) \]
      13. lift-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\mathsf{neg}\left({\color{blue}{\left(\mathsf{neg}\left(z\right)\right)}}^{3}\right)}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, t, y \cdot x\right) \]
      14. cube-negN/A

        \[\leadsto \mathsf{fma}\left(\frac{\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left({z}^{3}\right)\right)}\right)}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, t, y \cdot x\right) \]
      15. sub0-negN/A

        \[\leadsto \mathsf{fma}\left(\frac{\mathsf{neg}\left(\color{blue}{\left(0 - {z}^{3}\right)}\right)}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, t, y \cdot x\right) \]
      16. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\frac{\mathsf{neg}\left(\left(\color{blue}{{0}^{3}} - {z}^{3}\right)\right)}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}, t, y \cdot x\right) \]
      17. distribute-neg-fracN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{neg}\left(\frac{{0}^{3} - {z}^{3}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}\right)}, t, y \cdot x\right) \]
      18. flip3--N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{neg}\left(\color{blue}{\left(0 - z\right)}\right), t, y \cdot x\right) \]
      19. neg-sub0N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(z\right)\right)}\right), t, y \cdot x\right) \]
      20. remove-double-neg71.0

        \[\leadsto \mathsf{fma}\left(\color{blue}{z}, t, y \cdot x\right) \]
    6. Applied rewrites71.0%

      \[\leadsto \mathsf{fma}\left(\color{blue}{z}, t, y \cdot x\right) \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 4: 99.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x \cdot y - z \cdot t \end{array} \]
(FPCore (x y z t) :precision binary64 (- (* x y) (* z t)))
double code(double x, double y, double z, double t) {
	return (x * y) - (z * t);
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = (x * y) - (z * t)
end function
public static double code(double x, double y, double z, double t) {
	return (x * y) - (z * t);
}
def code(x, y, z, t):
	return (x * y) - (z * t)
function code(x, y, z, t)
	return Float64(Float64(x * y) - Float64(z * t))
end
function tmp = code(x, y, z, t)
	tmp = (x * y) - (z * t);
end
code[x_, y_, z_, t_] := N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot y - z \cdot t
\end{array}
Derivation
  1. Initial program 98.4%

    \[x \cdot y - z \cdot t \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 5: 52.4% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \left(-z\right) \cdot t \end{array} \]
(FPCore (x y z t) :precision binary64 (* (- z) t))
double code(double x, double y, double z, double t) {
	return -z * t;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = -z * t
end function
public static double code(double x, double y, double z, double t) {
	return -z * t;
}
def code(x, y, z, t):
	return -z * t
function code(x, y, z, t)
	return Float64(Float64(-z) * t)
end
function tmp = code(x, y, z, t)
	tmp = -z * t;
end
code[x_, y_, z_, t_] := N[((-z) * t), $MachinePrecision]
\begin{array}{l}

\\
\left(-z\right) \cdot t
\end{array}
Derivation
  1. Initial program 98.4%

    \[x \cdot y - z \cdot t \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto \color{blue}{-1 \cdot \left(t \cdot z\right)} \]
  4. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto -1 \cdot \color{blue}{\left(z \cdot t\right)} \]
    2. associate-*r*N/A

      \[\leadsto \color{blue}{\left(-1 \cdot z\right) \cdot t} \]
    3. lower-*.f64N/A

      \[\leadsto \color{blue}{\left(-1 \cdot z\right) \cdot t} \]
    4. mul-1-negN/A

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(z\right)\right)} \cdot t \]
    5. lower-neg.f6455.5

      \[\leadsto \color{blue}{\left(-z\right)} \cdot t \]
  5. Applied rewrites55.5%

    \[\leadsto \color{blue}{\left(-z\right) \cdot t} \]
  6. Add Preprocessing

Alternative 6: 3.5% accurate, 2.3× speedup?

\[\begin{array}{l} \\ z \cdot t \end{array} \]
(FPCore (x y z t) :precision binary64 (* z t))
double code(double x, double y, double z, double t) {
	return z * t;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = z * t
end function
public static double code(double x, double y, double z, double t) {
	return z * t;
}
def code(x, y, z, t):
	return z * t
function code(x, y, z, t)
	return Float64(z * t)
end
function tmp = code(x, y, z, t)
	tmp = z * t;
end
code[x_, y_, z_, t_] := N[(z * t), $MachinePrecision]
\begin{array}{l}

\\
z \cdot t
\end{array}
Derivation
  1. Initial program 98.4%

    \[x \cdot y - z \cdot t \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0

    \[\leadsto \color{blue}{-1 \cdot \left(t \cdot z\right)} \]
  4. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto -1 \cdot \color{blue}{\left(z \cdot t\right)} \]
    2. associate-*r*N/A

      \[\leadsto \color{blue}{\left(-1 \cdot z\right) \cdot t} \]
    3. lower-*.f64N/A

      \[\leadsto \color{blue}{\left(-1 \cdot z\right) \cdot t} \]
    4. mul-1-negN/A

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(z\right)\right)} \cdot t \]
    5. lower-neg.f6455.5

      \[\leadsto \color{blue}{\left(-z\right)} \cdot t \]
  5. Applied rewrites55.5%

    \[\leadsto \color{blue}{\left(-z\right) \cdot t} \]
  6. Step-by-step derivation
    1. Applied rewrites4.4%

      \[\leadsto z \cdot \color{blue}{t} \]
    2. Add Preprocessing

    Reproduce

    ?
    herbie shell --seed 2024317 
    (FPCore (x y z t)
      :name "Linear.V3:cross from linear-1.19.1.3"
      :precision binary64
      (- (* x y) (* z t)))