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

Percentage Accurate: 98.0% → 99.0%
Time: 5.3s
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: 98.0% 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: 99.0% 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 96.1%

    \[\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.5% accurate, 0.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -2 \cdot 10^{+73}:\\
\;\;\;\;a \cdot b\\

\mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{-165}:\\
\;\;\;\;t \cdot z\\

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

\mathbf{elif}\;a \cdot b \leq 10^{+103}:\\
\;\;\;\;t \cdot z\\

\mathbf{else}:\\
\;\;\;\;a \cdot b\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 a b) < -1.99999999999999997e73 or 1e103 < (*.f64 a b)

    1. Initial program 93.3%

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

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

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

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

      if -1.99999999999999997e73 < (*.f64 a b) < 2e-165 or 5.00000000000000011e-47 < (*.f64 a b) < 1e103

      1. Initial program 97.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-*.f6461.3

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

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

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

        if 2e-165 < (*.f64 a b) < 5.00000000000000011e-47

        1. Initial program 99.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-*.f6443.6

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

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

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

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

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

            \[\leadsto \color{blue}{y \cdot x} \]
        11. Recombined 3 regimes into one program.
        12. Final simplification62.1%

          \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -2 \cdot 10^{+73}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{-165}:\\ \;\;\;\;t \cdot z\\ \mathbf{elif}\;a \cdot b \leq 5 \cdot 10^{-47}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 10^{+103}:\\ \;\;\;\;t \cdot z\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
        13. Add Preprocessing

        Alternative 3: 84.9% accurate, 0.6× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{fma}\left(b, a, x \cdot y\right)\\ \mathbf{if}\;a \cdot b \leq -2 \cdot 10^{+73}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;a \cdot b \leq 10^{+103}:\\ \;\;\;\;\mathsf{fma}\left(t, z, x \cdot y\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 (<= (* a b) -2e+73)
             t_1
             (if (<= (* a b) 1e+103) (fma t z (* x y)) 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 ((a * b) <= -2e+73) {
        		tmp = t_1;
        	} else if ((a * b) <= 1e+103) {
        		tmp = fma(t, z, (x * y));
        	} 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(a * b) <= -2e+73)
        		tmp = t_1;
        	elseif (Float64(a * b) <= 1e+103)
        		tmp = fma(t, z, Float64(x * y));
        	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[(a * b), $MachinePrecision], -2e+73], t$95$1, If[LessEqual[N[(a * b), $MachinePrecision], 1e+103], N[(t * z + N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$1]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        t_1 := \mathsf{fma}\left(b, a, x \cdot y\right)\\
        \mathbf{if}\;a \cdot b \leq -2 \cdot 10^{+73}:\\
        \;\;\;\;t\_1\\
        
        \mathbf{elif}\;a \cdot b \leq 10^{+103}:\\
        \;\;\;\;\mathsf{fma}\left(t, z, x \cdot y\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;t\_1\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if (*.f64 a b) < -1.99999999999999997e73 or 1e103 < (*.f64 a b)

          1. Initial program 93.3%

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

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

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

          if -1.99999999999999997e73 < (*.f64 a b) < 1e103

          1. Initial program 98.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-*.f6458.0

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

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

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

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

        Alternative 4: 85.3% 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 -2 \cdot 10^{+34}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \cdot y \leq 10^{+119}:\\ \;\;\;\;\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) -2e+34)
             t_1
             (if (<= (* x y) 1e+119) (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) <= -2e+34) {
        		tmp = t_1;
        	} else if ((x * y) <= 1e+119) {
        		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) <= -2e+34)
        		tmp = t_1;
        	elseif (Float64(x * y) <= 1e+119)
        		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], -2e+34], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 1e+119], 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 -2 \cdot 10^{+34}:\\
        \;\;\;\;t\_1\\
        
        \mathbf{elif}\;x \cdot y \leq 10^{+119}:\\
        \;\;\;\;\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) < -1.99999999999999989e34 or 9.99999999999999944e118 < (*.f64 x y)

          1. Initial program 94.3%

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

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

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

          if -1.99999999999999989e34 < (*.f64 x y) < 9.99999999999999944e118

          1. Initial program 97.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-*.f6488.2

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

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

          \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -2 \cdot 10^{+34}:\\ \;\;\;\;\mathsf{fma}\left(b, a, x \cdot y\right)\\ \mathbf{elif}\;x \cdot y \leq 10^{+119}:\\ \;\;\;\;\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: 81.0% accurate, 0.6× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+86}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \cdot y \leq 10^{+158}:\\ \;\;\;\;\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) -5e+86)
           (* x y)
           (if (<= (* x y) 1e+158) (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) <= -5e+86) {
        		tmp = x * y;
        	} else if ((x * y) <= 1e+158) {
        		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) <= -5e+86)
        		tmp = Float64(x * y);
        	elseif (Float64(x * y) <= 1e+158)
        		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], -5e+86], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 1e+158], N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+86}:\\
        \;\;\;\;x \cdot y\\
        
        \mathbf{elif}\;x \cdot y \leq 10^{+158}:\\
        \;\;\;\;\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) < -4.9999999999999998e86 or 9.99999999999999953e157 < (*.f64 x y)

          1. Initial program 93.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-*.f6431.0

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

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

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

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

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

            if -4.9999999999999998e86 < (*.f64 x y) < 9.99999999999999953e157

            1. Initial program 97.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-*.f6485.0

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

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

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

          Alternative 6: 54.6% accurate, 0.8× speedup?

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

            1. Initial program 93.3%

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

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

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

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

              if -1.99999999999999997e73 < (*.f64 a b) < 1e103

              1. Initial program 98.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-*.f6458.0

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

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

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

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

              Alternative 7: 36.3% 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 96.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-*.f6468.5

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

                  \[\leadsto b \cdot \color{blue}{a} \]
                2. Final simplification37.3%

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

                Reproduce

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