Linear.V3:$cdot from linear-1.19.1.3, B

Percentage Accurate: 97.8% → 98.9%
Time: 5.5s
Alternatives: 7
Speedup: 1.2×

Specification

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

\\
\left(x \cdot y + z \cdot t\right) + a \cdot b
\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 7 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: 97.8% accurate, 1.0× speedup?

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

\\
\left(x \cdot y + z \cdot t\right) + a \cdot b
\end{array}

Alternative 1: 98.9% accurate, 1.2× speedup?

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

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

    \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \color{blue}{\left(x \cdot y + z \cdot t\right) + a \cdot b} \]
    2. lift-+.f64N/A

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

      \[\leadsto \color{blue}{\left(z \cdot t + x \cdot y\right)} + a \cdot b \]
    4. associate-+l+N/A

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 54.3% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+58}:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{-159}:\\ \;\;\;\;t \cdot z\\ \mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+97}:\\ \;\;\;\;b \cdot a\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (if (<= (* x y) -5e+58)
   (* y x)
   (if (<= (* x y) 5e-159) (* t z) (if (<= (* x y) 5e+97) (* b a) (* y x)))))
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if ((x * y) <= -5e+58) {
		tmp = y * x;
	} else if ((x * y) <= 5e-159) {
		tmp = t * z;
	} else if ((x * y) <= 5e+97) {
		tmp = b * a;
	} else {
		tmp = y * x;
	}
	return tmp;
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if ((x * y) <= (-5d+58)) then
        tmp = y * x
    else if ((x * y) <= 5d-159) then
        tmp = t * z
    else if ((x * y) <= 5d+97) then
        tmp = b * a
    else
        tmp = y * x
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if ((x * y) <= -5e+58) {
		tmp = y * x;
	} else if ((x * y) <= 5e-159) {
		tmp = t * z;
	} else if ((x * y) <= 5e+97) {
		tmp = b * a;
	} else {
		tmp = y * x;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if (x * y) <= -5e+58:
		tmp = y * x
	elif (x * y) <= 5e-159:
		tmp = t * z
	elif (x * y) <= 5e+97:
		tmp = b * a
	else:
		tmp = y * x
	return tmp
function code(x, y, z, t, a, b)
	tmp = 0.0
	if (Float64(x * y) <= -5e+58)
		tmp = Float64(y * x);
	elseif (Float64(x * y) <= 5e-159)
		tmp = Float64(t * z);
	elseif (Float64(x * y) <= 5e+97)
		tmp = Float64(b * a);
	else
		tmp = Float64(y * x);
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	tmp = 0.0;
	if ((x * y) <= -5e+58)
		tmp = y * x;
	elseif ((x * y) <= 5e-159)
		tmp = t * z;
	elseif ((x * y) <= 5e+97)
		tmp = b * a;
	else
		tmp = y * x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -5e+58], N[(y * x), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 5e-159], N[(t * z), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 5e+97], N[(b * a), $MachinePrecision], N[(y * x), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+58}:\\
\;\;\;\;y \cdot x\\

\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{-159}:\\
\;\;\;\;t \cdot z\\

\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+97}:\\
\;\;\;\;b \cdot a\\

\mathbf{else}:\\
\;\;\;\;y \cdot x\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 x y) < -4.99999999999999986e58 or 4.99999999999999999e97 < (*.f64 x y)

    1. Initial program 94.5%

      \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{a \cdot b + t \cdot z} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{b \cdot a} + t \cdot z \]
      2. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, t \cdot z\right)} \]
      3. lower-*.f6432.4

        \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{t \cdot z}\right) \]
    5. Applied rewrites32.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, t \cdot z\right)} \]
    6. Taylor expanded in a around 0

      \[\leadsto \color{blue}{t \cdot z + x \cdot y} \]
    7. Step-by-step derivation
      1. lower-fma.f64N/A

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(t, z, y \cdot x\right)} \]
    9. Taylor expanded in x around 0

      \[\leadsto t \cdot \color{blue}{z} \]
    10. Step-by-step derivation
      1. Applied rewrites22.0%

        \[\leadsto t \cdot \color{blue}{z} \]
      2. Taylor expanded in x around inf

        \[\leadsto \color{blue}{x \cdot y} \]
      3. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{y \cdot x} \]
        2. lower-*.f6469.4

          \[\leadsto \color{blue}{y \cdot x} \]
      4. Applied rewrites69.4%

        \[\leadsto \color{blue}{y \cdot x} \]

      if -4.99999999999999986e58 < (*.f64 x y) < 5.00000000000000032e-159

      1. Initial program 98.9%

        \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
      2. Add Preprocessing
      3. Taylor expanded in x around 0

        \[\leadsto \color{blue}{a \cdot b + t \cdot z} \]
      4. Step-by-step derivation
        1. *-commutativeN/A

          \[\leadsto \color{blue}{b \cdot a} + t \cdot z \]
        2. lower-fma.f64N/A

          \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, t \cdot z\right)} \]
        3. lower-*.f6496.0

          \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{t \cdot z}\right) \]
      5. Applied rewrites96.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, t \cdot z\right)} \]
      6. Taylor expanded in a around 0

        \[\leadsto \color{blue}{t \cdot z + x \cdot y} \]
      7. Step-by-step derivation
        1. lower-fma.f64N/A

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(t, z, y \cdot x\right)} \]
      9. Taylor expanded in x around 0

        \[\leadsto t \cdot \color{blue}{z} \]
      10. Step-by-step derivation
        1. Applied rewrites61.3%

          \[\leadsto t \cdot \color{blue}{z} \]

        if 5.00000000000000032e-159 < (*.f64 x y) < 4.99999999999999999e97

        1. Initial program 100.0%

          \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
        2. Add Preprocessing
        3. Taylor expanded in z around 0

          \[\leadsto \color{blue}{a \cdot b + x \cdot y} \]
        4. Step-by-step derivation
          1. *-commutativeN/A

            \[\leadsto \color{blue}{b \cdot a} + x \cdot y \]
          2. lower-fma.f64N/A

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

            \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{y \cdot x}\right) \]
          4. lower-*.f6475.4

            \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{y \cdot x}\right) \]
        5. Applied rewrites75.4%

          \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, y \cdot x\right)} \]
        6. Taylor expanded in x around 0

          \[\leadsto a \cdot \color{blue}{b} \]
        7. Step-by-step derivation
          1. Applied rewrites50.0%

            \[\leadsto b \cdot \color{blue}{a} \]
        8. Recombined 3 regimes into one program.
        9. Add Preprocessing

        Alternative 3: 84.9% accurate, 0.6× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+58} \lor \neg \left(x \cdot y \leq 5 \cdot 10^{-17}\right):\\ \;\;\;\;\mathsf{fma}\left(b, a, y \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\ \end{array} \end{array} \]
        (FPCore (x y z t a b)
         :precision binary64
         (if (or (<= (* x y) -5e+58) (not (<= (* x y) 5e-17)))
           (fma b a (* y x))
           (fma b a (* t z))))
        double code(double x, double y, double z, double t, double a, double b) {
        	double tmp;
        	if (((x * y) <= -5e+58) || !((x * y) <= 5e-17)) {
        		tmp = fma(b, a, (y * x));
        	} else {
        		tmp = fma(b, a, (t * z));
        	}
        	return tmp;
        }
        
        function code(x, y, z, t, a, b)
        	tmp = 0.0
        	if ((Float64(x * y) <= -5e+58) || !(Float64(x * y) <= 5e-17))
        		tmp = fma(b, a, Float64(y * x));
        	else
        		tmp = fma(b, a, Float64(t * z));
        	end
        	return tmp
        end
        
        code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -5e+58], N[Not[LessEqual[N[(x * y), $MachinePrecision], 5e-17]], $MachinePrecision]], N[(b * a + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+58} \lor \neg \left(x \cdot y \leq 5 \cdot 10^{-17}\right):\\
        \;\;\;\;\mathsf{fma}\left(b, a, y \cdot x\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if (*.f64 x y) < -4.99999999999999986e58 or 4.9999999999999999e-17 < (*.f64 x y)

          1. Initial program 95.8%

            \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
          2. Add Preprocessing
          3. Taylor expanded in z around 0

            \[\leadsto \color{blue}{a \cdot b + x \cdot y} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \color{blue}{b \cdot a} + x \cdot y \]
            2. lower-fma.f64N/A

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

              \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{y \cdot x}\right) \]
            4. lower-*.f6478.5

              \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{y \cdot x}\right) \]
          5. Applied rewrites78.5%

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

          if -4.99999999999999986e58 < (*.f64 x y) < 4.9999999999999999e-17

          1. Initial program 99.1%

            \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
          2. Add Preprocessing
          3. Taylor expanded in x around 0

            \[\leadsto \color{blue}{a \cdot b + t \cdot z} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \color{blue}{b \cdot a} + t \cdot z \]
            2. lower-fma.f64N/A

              \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, t \cdot z\right)} \]
            3. lower-*.f6495.3

              \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{t \cdot z}\right) \]
          5. Applied rewrites95.3%

            \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, t \cdot z\right)} \]
        3. Recombined 2 regimes into one program.
        4. Final simplification85.9%

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

        Alternative 4: 80.4% accurate, 0.6× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+86} \lor \neg \left(x \cdot y \leq 10^{+165}\right):\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\ \end{array} \end{array} \]
        (FPCore (x y z t a b)
         :precision binary64
         (if (or (<= (* x y) -5e+86) (not (<= (* x y) 1e+165)))
           (* y x)
           (fma b a (* t z))))
        double code(double x, double y, double z, double t, double a, double b) {
        	double tmp;
        	if (((x * y) <= -5e+86) || !((x * y) <= 1e+165)) {
        		tmp = y * x;
        	} else {
        		tmp = fma(b, a, (t * z));
        	}
        	return tmp;
        }
        
        function code(x, y, z, t, a, b)
        	tmp = 0.0
        	if ((Float64(x * y) <= -5e+86) || !(Float64(x * y) <= 1e+165))
        		tmp = Float64(y * x);
        	else
        		tmp = fma(b, a, Float64(t * z));
        	end
        	return tmp
        end
        
        code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -5e+86], N[Not[LessEqual[N[(x * y), $MachinePrecision], 1e+165]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+86} \lor \neg \left(x \cdot y \leq 10^{+165}\right):\\
        \;\;\;\;y \cdot x\\
        
        \mathbf{else}:\\
        \;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if (*.f64 x y) < -4.9999999999999998e86 or 9.99999999999999899e164 < (*.f64 x y)

          1. Initial program 93.4%

            \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
          2. Add Preprocessing
          3. Taylor expanded in x around 0

            \[\leadsto \color{blue}{a \cdot b + t \cdot z} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \color{blue}{b \cdot a} + t \cdot z \]
            2. lower-fma.f64N/A

              \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, t \cdot z\right)} \]
            3. lower-*.f6428.2

              \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{t \cdot z}\right) \]
          5. Applied rewrites28.2%

            \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, t \cdot z\right)} \]
          6. Taylor expanded in a around 0

            \[\leadsto \color{blue}{t \cdot z + x \cdot y} \]
          7. Step-by-step derivation
            1. lower-fma.f64N/A

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

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

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

            \[\leadsto \color{blue}{\mathsf{fma}\left(t, z, y \cdot x\right)} \]
          9. Taylor expanded in x around 0

            \[\leadsto t \cdot \color{blue}{z} \]
          10. Step-by-step derivation
            1. Applied rewrites19.5%

              \[\leadsto t \cdot \color{blue}{z} \]
            2. Taylor expanded in x around inf

              \[\leadsto \color{blue}{x \cdot y} \]
            3. Step-by-step derivation
              1. *-commutativeN/A

                \[\leadsto \color{blue}{y \cdot x} \]
              2. lower-*.f6474.7

                \[\leadsto \color{blue}{y \cdot x} \]
            4. Applied rewrites74.7%

              \[\leadsto \color{blue}{y \cdot x} \]

            if -4.9999999999999998e86 < (*.f64 x y) < 9.99999999999999899e164

            1. Initial program 99.4%

              \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
            2. Add Preprocessing
            3. Taylor expanded in x around 0

              \[\leadsto \color{blue}{a \cdot b + t \cdot z} \]
            4. Step-by-step derivation
              1. *-commutativeN/A

                \[\leadsto \color{blue}{b \cdot a} + t \cdot z \]
              2. lower-fma.f64N/A

                \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, t \cdot z\right)} \]
              3. lower-*.f6484.4

                \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{t \cdot z}\right) \]
            5. Applied rewrites84.4%

              \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, t \cdot z\right)} \]
          11. Recombined 2 regimes into one program.
          12. Final simplification81.0%

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

          Alternative 5: 85.1% accurate, 0.6× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot b \leq -4 \cdot 10^{+69}:\\ \;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\ \mathbf{elif}\;a \cdot b \leq 10^{+125}:\\ \;\;\;\;\mathsf{fma}\left(t, z, y \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(b, a, y \cdot x\right)\\ \end{array} \end{array} \]
          (FPCore (x y z t a b)
           :precision binary64
           (if (<= (* a b) -4e+69)
             (fma b a (* t z))
             (if (<= (* a b) 1e+125) (fma t z (* y x)) (fma b a (* y x)))))
          double code(double x, double y, double z, double t, double a, double b) {
          	double tmp;
          	if ((a * b) <= -4e+69) {
          		tmp = fma(b, a, (t * z));
          	} else if ((a * b) <= 1e+125) {
          		tmp = fma(t, z, (y * x));
          	} else {
          		tmp = fma(b, a, (y * x));
          	}
          	return tmp;
          }
          
          function code(x, y, z, t, a, b)
          	tmp = 0.0
          	if (Float64(a * b) <= -4e+69)
          		tmp = fma(b, a, Float64(t * z));
          	elseif (Float64(a * b) <= 1e+125)
          		tmp = fma(t, z, Float64(y * x));
          	else
          		tmp = fma(b, a, Float64(y * x));
          	end
          	return tmp
          end
          
          code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(a * b), $MachinePrecision], -4e+69], N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1e+125], N[(t * z + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(b * a + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;a \cdot b \leq -4 \cdot 10^{+69}:\\
          \;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
          
          \mathbf{elif}\;a \cdot b \leq 10^{+125}:\\
          \;\;\;\;\mathsf{fma}\left(t, z, y \cdot x\right)\\
          
          \mathbf{else}:\\
          \;\;\;\;\mathsf{fma}\left(b, a, y \cdot x\right)\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 3 regimes
          2. if (*.f64 a b) < -4.0000000000000003e69

            1. Initial program 95.6%

              \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
            2. Add Preprocessing
            3. Taylor expanded in x around 0

              \[\leadsto \color{blue}{a \cdot b + t \cdot z} \]
            4. Step-by-step derivation
              1. *-commutativeN/A

                \[\leadsto \color{blue}{b \cdot a} + t \cdot z \]
              2. lower-fma.f64N/A

                \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, t \cdot z\right)} \]
              3. lower-*.f6490.5

                \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{t \cdot z}\right) \]
            5. Applied rewrites90.5%

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

            if -4.0000000000000003e69 < (*.f64 a b) < 9.9999999999999992e124

            1. Initial program 99.4%

              \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
            2. Add Preprocessing
            3. Taylor expanded in x around 0

              \[\leadsto \color{blue}{a \cdot b + t \cdot z} \]
            4. Step-by-step derivation
              1. *-commutativeN/A

                \[\leadsto \color{blue}{b \cdot a} + t \cdot z \]
              2. lower-fma.f64N/A

                \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, t \cdot z\right)} \]
              3. lower-*.f6452.9

                \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{t \cdot z}\right) \]
            5. Applied rewrites52.9%

              \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, t \cdot z\right)} \]
            6. Taylor expanded in a around 0

              \[\leadsto \color{blue}{t \cdot z + x \cdot y} \]
            7. Step-by-step derivation
              1. lower-fma.f64N/A

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

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

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

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

            if 9.9999999999999992e124 < (*.f64 a b)

            1. Initial program 90.0%

              \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
            2. Add Preprocessing
            3. Taylor expanded in z around 0

              \[\leadsto \color{blue}{a \cdot b + x \cdot y} \]
            4. Step-by-step derivation
              1. *-commutativeN/A

                \[\leadsto \color{blue}{b \cdot a} + x \cdot y \]
              2. lower-fma.f64N/A

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

                \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{y \cdot x}\right) \]
              4. lower-*.f6485.2

                \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{y \cdot x}\right) \]
            5. Applied rewrites85.2%

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

          Alternative 6: 53.2% accurate, 0.8× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot b \leq -5 \cdot 10^{+116} \lor \neg \left(a \cdot b \leq 10^{+125}\right):\\ \;\;\;\;b \cdot a\\ \mathbf{else}:\\ \;\;\;\;t \cdot z\\ \end{array} \end{array} \]
          (FPCore (x y z t a b)
           :precision binary64
           (if (or (<= (* a b) -5e+116) (not (<= (* a b) 1e+125))) (* b a) (* t z)))
          double code(double x, double y, double z, double t, double a, double b) {
          	double tmp;
          	if (((a * b) <= -5e+116) || !((a * b) <= 1e+125)) {
          		tmp = b * a;
          	} else {
          		tmp = t * z;
          	}
          	return tmp;
          }
          
          real(8) function code(x, y, z, t, a, b)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              real(8), intent (in) :: z
              real(8), intent (in) :: t
              real(8), intent (in) :: a
              real(8), intent (in) :: b
              real(8) :: tmp
              if (((a * b) <= (-5d+116)) .or. (.not. ((a * b) <= 1d+125))) then
                  tmp = b * a
              else
                  tmp = t * z
              end if
              code = tmp
          end function
          
          public static double code(double x, double y, double z, double t, double a, double b) {
          	double tmp;
          	if (((a * b) <= -5e+116) || !((a * b) <= 1e+125)) {
          		tmp = b * a;
          	} else {
          		tmp = t * z;
          	}
          	return tmp;
          }
          
          def code(x, y, z, t, a, b):
          	tmp = 0
          	if ((a * b) <= -5e+116) or not ((a * b) <= 1e+125):
          		tmp = b * a
          	else:
          		tmp = t * z
          	return tmp
          
          function code(x, y, z, t, a, b)
          	tmp = 0.0
          	if ((Float64(a * b) <= -5e+116) || !(Float64(a * b) <= 1e+125))
          		tmp = Float64(b * a);
          	else
          		tmp = Float64(t * z);
          	end
          	return tmp
          end
          
          function tmp_2 = code(x, y, z, t, a, b)
          	tmp = 0.0;
          	if (((a * b) <= -5e+116) || ~(((a * b) <= 1e+125)))
          		tmp = b * a;
          	else
          		tmp = t * z;
          	end
          	tmp_2 = tmp;
          end
          
          code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(a * b), $MachinePrecision], -5e+116], N[Not[LessEqual[N[(a * b), $MachinePrecision], 1e+125]], $MachinePrecision]], N[(b * a), $MachinePrecision], N[(t * z), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;a \cdot b \leq -5 \cdot 10^{+116} \lor \neg \left(a \cdot b \leq 10^{+125}\right):\\
          \;\;\;\;b \cdot a\\
          
          \mathbf{else}:\\
          \;\;\;\;t \cdot z\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if (*.f64 a b) < -5.00000000000000025e116 or 9.9999999999999992e124 < (*.f64 a b)

            1. Initial program 92.4%

              \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
            2. Add Preprocessing
            3. Taylor expanded in z around 0

              \[\leadsto \color{blue}{a \cdot b + x \cdot y} \]
            4. Step-by-step derivation
              1. *-commutativeN/A

                \[\leadsto \color{blue}{b \cdot a} + x \cdot y \]
              2. lower-fma.f64N/A

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

                \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{y \cdot x}\right) \]
              4. lower-*.f6487.1

                \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{y \cdot x}\right) \]
            5. Applied rewrites87.1%

              \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, y \cdot x\right)} \]
            6. Taylor expanded in x around 0

              \[\leadsto a \cdot \color{blue}{b} \]
            7. Step-by-step derivation
              1. Applied rewrites77.8%

                \[\leadsto b \cdot \color{blue}{a} \]

              if -5.00000000000000025e116 < (*.f64 a b) < 9.9999999999999992e124

              1. Initial program 99.4%

                \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
              2. Add Preprocessing
              3. Taylor expanded in x around 0

                \[\leadsto \color{blue}{a \cdot b + t \cdot z} \]
              4. Step-by-step derivation
                1. *-commutativeN/A

                  \[\leadsto \color{blue}{b \cdot a} + t \cdot z \]
                2. lower-fma.f64N/A

                  \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, t \cdot z\right)} \]
                3. lower-*.f6454.3

                  \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{t \cdot z}\right) \]
              5. Applied rewrites54.3%

                \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, t \cdot z\right)} \]
              6. Taylor expanded in a around 0

                \[\leadsto \color{blue}{t \cdot z + x \cdot y} \]
              7. Step-by-step derivation
                1. lower-fma.f64N/A

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

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

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

                \[\leadsto \color{blue}{\mathsf{fma}\left(t, z, y \cdot x\right)} \]
              9. Taylor expanded in x around 0

                \[\leadsto t \cdot \color{blue}{z} \]
              10. Step-by-step derivation
                1. Applied rewrites47.8%

                  \[\leadsto t \cdot \color{blue}{z} \]
              11. Recombined 2 regimes into one program.
              12. Final simplification57.2%

                \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -5 \cdot 10^{+116} \lor \neg \left(a \cdot b \leq 10^{+125}\right):\\ \;\;\;\;b \cdot a\\ \mathbf{else}:\\ \;\;\;\;t \cdot z\\ \end{array} \]
              13. Add Preprocessing

              Alternative 7: 35.3% accurate, 3.7× speedup?

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

                \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
              2. Add Preprocessing
              3. Taylor expanded in z around 0

                \[\leadsto \color{blue}{a \cdot b + x \cdot y} \]
              4. Step-by-step derivation
                1. *-commutativeN/A

                  \[\leadsto \color{blue}{b \cdot a} + x \cdot y \]
                2. lower-fma.f64N/A

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

                  \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{y \cdot x}\right) \]
                4. lower-*.f6464.5

                  \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{y \cdot x}\right) \]
              5. Applied rewrites64.5%

                \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, y \cdot x\right)} \]
              6. Taylor expanded in x around 0

                \[\leadsto a \cdot \color{blue}{b} \]
              7. Step-by-step derivation
                1. Applied rewrites30.4%

                  \[\leadsto b \cdot \color{blue}{a} \]
                2. Add Preprocessing

                Reproduce

                ?
                herbie shell --seed 2024322 
                (FPCore (x y z t a b)
                  :name "Linear.V3:$cdot from linear-1.19.1.3, B"
                  :precision binary64
                  (+ (+ (* x y) (* z t)) (* a b)))