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

Percentage Accurate: 97.5% → 98.8%
Time: 3.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.5% 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.8% accurate, 1.2× speedup?

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

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

    \[\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.f6499.2

      \[\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-*.f6499.2

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

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

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

Alternative 2: 54.2% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+122}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \cdot y \leq -5 \cdot 10^{-110}:\\ \;\;\;\;t \cdot z\\ \mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+100}:\\ \;\;\;\;a \cdot b\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (if (<= (* x y) -1e+122)
   (* x y)
   (if (<= (* x y) -5e-110) (* t z) (if (<= (* x y) 5e+100) (* a b) (* x y)))))
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if ((x * y) <= -1e+122) {
		tmp = x * y;
	} else if ((x * y) <= -5e-110) {
		tmp = t * z;
	} else if ((x * y) <= 5e+100) {
		tmp = a * b;
	} else {
		tmp = x * y;
	}
	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) <= (-1d+122)) then
        tmp = x * y
    else if ((x * y) <= (-5d-110)) then
        tmp = t * z
    else if ((x * y) <= 5d+100) then
        tmp = a * b
    else
        tmp = x * y
    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) <= -1e+122) {
		tmp = x * y;
	} else if ((x * y) <= -5e-110) {
		tmp = t * z;
	} else if ((x * y) <= 5e+100) {
		tmp = a * b;
	} else {
		tmp = x * y;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if (x * y) <= -1e+122:
		tmp = x * y
	elif (x * y) <= -5e-110:
		tmp = t * z
	elif (x * y) <= 5e+100:
		tmp = a * b
	else:
		tmp = x * y
	return tmp
function code(x, y, z, t, a, b)
	tmp = 0.0
	if (Float64(x * y) <= -1e+122)
		tmp = Float64(x * y);
	elseif (Float64(x * y) <= -5e-110)
		tmp = Float64(t * z);
	elseif (Float64(x * y) <= 5e+100)
		tmp = Float64(a * b);
	else
		tmp = Float64(x * y);
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	tmp = 0.0;
	if ((x * y) <= -1e+122)
		tmp = x * y;
	elseif ((x * y) <= -5e-110)
		tmp = t * z;
	elseif ((x * y) <= 5e+100)
		tmp = a * b;
	else
		tmp = x * y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -1e+122], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], -5e-110], N[(t * z), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 5e+100], N[(a * b), $MachinePrecision], N[(x * y), $MachinePrecision]]]]
\begin{array}{l}

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 x y) < -1.00000000000000001e122 or 4.9999999999999999e100 < (*.f64 x y)

    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-*.f6428.6

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

      \[\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-*.f6485.6

        \[\leadsto \mathsf{fma}\left(t, z, \color{blue}{y \cdot x}\right) \]
    8. Applied rewrites85.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 rewrites13.1%

        \[\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-*.f6475.6

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

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

      if -1.00000000000000001e122 < (*.f64 x y) < -5e-110

      1. Initial program 96.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-*.f6464.0

          \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{t \cdot z}\right) \]
      5. Applied rewrites64.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-*.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 rewrites53.9%

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

        if -5e-110 < (*.f64 x y) < 4.9999999999999999e100

        1. Initial program 99.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-*.f6456.5

            \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{y \cdot x}\right) \]
        5. Applied rewrites56.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 rewrites51.2%

            \[\leadsto b \cdot \color{blue}{a} \]
        8. Recombined 3 regimes into one program.
        9. Final simplification60.1%

          \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+122}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \cdot y \leq -5 \cdot 10^{-110}:\\ \;\;\;\;t \cdot z\\ \mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+100}:\\ \;\;\;\;a \cdot b\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
        10. Add Preprocessing

        Alternative 3: 85.7% accurate, 0.6× speedup?

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

          1. Initial program 97.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-*.f6438.4

              \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{t \cdot z}\right) \]
          5. Applied rewrites38.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-*.f6487.8

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

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

          if -5.00000000000000028e-33 < (*.f64 x y) < 2.0000000000000002e50

          1. Initial program 100.0%

            \[\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.6

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

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

          if 2.0000000000000002e50 < (*.f64 x y)

          1. Initial program 92.1%

            \[\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-*.f6484.6

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

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

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

        Alternative 4: 85.2% accurate, 0.6× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{fma}\left(b, a, x \cdot y\right)\\ \mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+124}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+50}:\\ \;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
        (FPCore (x y z t a b)
         :precision binary64
         (let* ((t_1 (fma b a (* x y))))
           (if (<= (* x y) -1e+124)
             t_1
             (if (<= (* x y) 2e+50) (fma b a (* t z)) t_1))))
        double code(double x, double y, double z, double t, double a, double b) {
        	double t_1 = fma(b, a, (x * y));
        	double tmp;
        	if ((x * y) <= -1e+124) {
        		tmp = t_1;
        	} else if ((x * y) <= 2e+50) {
        		tmp = fma(b, a, (t * z));
        	} else {
        		tmp = t_1;
        	}
        	return tmp;
        }
        
        function code(x, y, z, t, a, b)
        	t_1 = fma(b, a, Float64(x * y))
        	tmp = 0.0
        	if (Float64(x * y) <= -1e+124)
        		tmp = t_1;
        	elseif (Float64(x * y) <= 2e+50)
        		tmp = fma(b, a, Float64(t * z));
        	else
        		tmp = t_1;
        	end
        	return tmp
        end
        
        code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -1e+124], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 2e+50], N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision], t$95$1]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        t_1 := \mathsf{fma}\left(b, a, x \cdot y\right)\\
        \mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+124}:\\
        \;\;\;\;t\_1\\
        
        \mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+50}:\\
        \;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;t\_1\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if (*.f64 x y) < -9.99999999999999948e123 or 2.0000000000000002e50 < (*.f64 x y)

          1. Initial program 94.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-*.f6487.6

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

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

          if -9.99999999999999948e123 < (*.f64 x y) < 2.0000000000000002e50

          1. Initial program 99.3%

            \[\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-*.f6489.8

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

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

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

        Alternative 5: 80.9% accurate, 0.6× speedup?

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

          1. Initial program 94.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-*.f6423.7

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

            \[\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.7

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

            \[\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 rewrites12.1%

              \[\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-*.f6480.8

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

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

            if -9.99999999999999948e123 < (*.f64 x y) < 2.00000000000000001e160

            1. Initial program 98.8%

              \[\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-*.f6486.7

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

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

            \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+124}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{+160}:\\ \;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
          13. Add Preprocessing

          Alternative 6: 53.2% accurate, 0.8× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;t \cdot z \leq -2 \cdot 10^{-59}:\\ \;\;\;\;t \cdot z\\ \mathbf{elif}\;t \cdot z \leq 0.5:\\ \;\;\;\;a \cdot b\\ \mathbf{else}:\\ \;\;\;\;t \cdot z\\ \end{array} \end{array} \]
          (FPCore (x y z t a b)
           :precision binary64
           (if (<= (* t z) -2e-59) (* t z) (if (<= (* t z) 0.5) (* a b) (* t z))))
          double code(double x, double y, double z, double t, double a, double b) {
          	double tmp;
          	if ((t * z) <= -2e-59) {
          		tmp = t * z;
          	} else if ((t * z) <= 0.5) {
          		tmp = a * b;
          	} 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 ((t * z) <= (-2d-59)) then
                  tmp = t * z
              else if ((t * z) <= 0.5d0) then
                  tmp = a * b
              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 ((t * z) <= -2e-59) {
          		tmp = t * z;
          	} else if ((t * z) <= 0.5) {
          		tmp = a * b;
          	} else {
          		tmp = t * z;
          	}
          	return tmp;
          }
          
          def code(x, y, z, t, a, b):
          	tmp = 0
          	if (t * z) <= -2e-59:
          		tmp = t * z
          	elif (t * z) <= 0.5:
          		tmp = a * b
          	else:
          		tmp = t * z
          	return tmp
          
          function code(x, y, z, t, a, b)
          	tmp = 0.0
          	if (Float64(t * z) <= -2e-59)
          		tmp = Float64(t * z);
          	elseif (Float64(t * z) <= 0.5)
          		tmp = Float64(a * b);
          	else
          		tmp = Float64(t * z);
          	end
          	return tmp
          end
          
          function tmp_2 = code(x, y, z, t, a, b)
          	tmp = 0.0;
          	if ((t * z) <= -2e-59)
          		tmp = t * z;
          	elseif ((t * z) <= 0.5)
          		tmp = a * b;
          	else
          		tmp = t * z;
          	end
          	tmp_2 = tmp;
          end
          
          code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(t * z), $MachinePrecision], -2e-59], N[(t * z), $MachinePrecision], If[LessEqual[N[(t * z), $MachinePrecision], 0.5], N[(a * b), $MachinePrecision], N[(t * z), $MachinePrecision]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;t \cdot z \leq -2 \cdot 10^{-59}:\\
          \;\;\;\;t \cdot z\\
          
          \mathbf{elif}\;t \cdot z \leq 0.5:\\
          \;\;\;\;a \cdot b\\
          
          \mathbf{else}:\\
          \;\;\;\;t \cdot z\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if (*.f64 z t) < -2.0000000000000001e-59 or 0.5 < (*.f64 z t)

            1. Initial program 95.7%

              \[\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-*.f6475.1

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

              \[\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-*.f6482.1

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

              \[\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 rewrites57.3%

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

              if -2.0000000000000001e-59 < (*.f64 z t) < 0.5

              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-*.f6493.3

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

                \[\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 rewrites51.2%

                  \[\leadsto b \cdot \color{blue}{a} \]
              8. Recombined 2 regimes into one program.
              9. Final simplification54.6%

                \[\leadsto \begin{array}{l} \mathbf{if}\;t \cdot z \leq -2 \cdot 10^{-59}:\\ \;\;\;\;t \cdot z\\ \mathbf{elif}\;t \cdot z \leq 0.5:\\ \;\;\;\;a \cdot b\\ \mathbf{else}:\\ \;\;\;\;t \cdot z\\ \end{array} \]
              10. Add Preprocessing

              Alternative 7: 36.2% accurate, 3.7× speedup?

              \[\begin{array}{l} \\ a \cdot b \end{array} \]
              (FPCore (x y z t a b) :precision binary64 (* a b))
              double code(double x, double y, double z, double t, double a, double b) {
              	return 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 = a * b
              end function
              
              public static double code(double x, double y, double z, double t, double a, double b) {
              	return a * b;
              }
              
              def code(x, y, z, t, a, b):
              	return a * b
              
              function code(x, y, z, t, a, b)
              	return Float64(a * b)
              end
              
              function tmp = code(x, y, z, t, a, b)
              	tmp = a * b;
              end
              
              code[x_, y_, z_, t_, a_, b_] := N[(a * b), $MachinePrecision]
              
              \begin{array}{l}
              
              \\
              a \cdot b
              \end{array}
              
              Derivation
              1. Initial program 97.6%

                \[\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-*.f6466.7

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

                \[\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 rewrites34.8%

                  \[\leadsto b \cdot \color{blue}{a} \]
                2. Final simplification34.8%

                  \[\leadsto a \cdot b \]
                3. Add Preprocessing

                Reproduce

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