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

Percentage Accurate: 97.8% → 99.0%
Time: 3.3s
Alternatives: 7
Speedup: 0.5×

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);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z, t, a, b)
use fmin_fmax_functions
    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);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z, t, a, b)
use fmin_fmax_functions
    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, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(x \cdot y + z \cdot t\right) + a \cdot b \leq \infty:\\ \;\;\;\;\mathsf{fma}\left(y, x, \mathsf{fma}\left(b, a, t \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, x, b \cdot a\right)\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (if (<= (+ (+ (* x y) (* z t)) (* a b)) INFINITY)
   (fma y x (fma b a (* t z)))
   (fma y x (* b a))))
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if ((((x * y) + (z * t)) + (a * b)) <= ((double) INFINITY)) {
		tmp = fma(y, x, fma(b, a, (t * z)));
	} else {
		tmp = fma(y, x, (b * a));
	}
	return tmp;
}
function code(x, y, z, t, a, b)
	tmp = 0.0
	if (Float64(Float64(Float64(x * y) + Float64(z * t)) + Float64(a * b)) <= Inf)
		tmp = fma(y, x, fma(b, a, Float64(t * z)));
	else
		tmp = fma(y, x, Float64(b * a));
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision], Infinity], N[(y * x + N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * x + N[(b * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left(x \cdot y + z \cdot t\right) + a \cdot b \leq \infty:\\
\;\;\;\;\mathsf{fma}\left(y, x, \mathsf{fma}\left(b, a, t \cdot z\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (+.f64 (*.f64 x y) (*.f64 z t)) (*.f64 a b)) < +inf.0

    1. Initial program 100.0%

      \[\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. associate-+l+N/A

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

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

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

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

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

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

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

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

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

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

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

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

    if +inf.0 < (+.f64 (+.f64 (*.f64 x y) (*.f64 z t)) (*.f64 a b))

    1. Initial program 0.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. Applied rewrites77.8%

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

    Alternative 2: 85.0% accurate, 0.6× speedup?

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

      1. Initial program 95.3%

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

        \[\leadsto \color{blue}{t \cdot z + x \cdot y} \]
      4. Step-by-step derivation
        1. Applied rewrites87.7%

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

        if -2e86 < (*.f64 x y) < 1.99999999999999999e-73

        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. Applied rewrites91.0%

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

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

        Alternative 3: 81.4% accurate, 0.6× speedup?

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

            \[\leadsto \color{blue}{x \cdot y} \]
          4. Step-by-step derivation
            1. Applied rewrites83.4%

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

            if -2.0000000000000001e97 < (*.f64 x y) < 1e153

            1. Initial program 98.2%

              \[\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. Applied rewrites83.5%

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

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

            Alternative 4: 81.5% accurate, 0.6× speedup?

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

                \[\leadsto \color{blue}{x \cdot y} \]
              4. Step-by-step derivation
                1. Applied rewrites83.4%

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

                if -2.0000000000000001e97 < (*.f64 x y) < 1e153

                1. Initial program 98.2%

                  \[\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. Applied rewrites83.5%

                    \[\leadsto \color{blue}{\mathsf{fma}\left(t, z, b \cdot a\right)} \]
                  2. Step-by-step derivation
                    1. Applied rewrites81.8%

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

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

                  Alternative 5: 52.4% accurate, 0.8× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -2 \cdot 10^{+86} \lor \neg \left(x \cdot y \leq 2 \cdot 10^{-73}\right):\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;b \cdot a\\ \end{array} \end{array} \]
                  (FPCore (x y z t a b)
                   :precision binary64
                   (if (or (<= (* x y) -2e+86) (not (<= (* x y) 2e-73))) (* y x) (* b a)))
                  double code(double x, double y, double z, double t, double a, double b) {
                  	double tmp;
                  	if (((x * y) <= -2e+86) || !((x * y) <= 2e-73)) {
                  		tmp = y * x;
                  	} else {
                  		tmp = b * a;
                  	}
                  	return tmp;
                  }
                  
                  module fmin_fmax_functions
                      implicit none
                      private
                      public fmax
                      public fmin
                  
                      interface fmax
                          module procedure fmax88
                          module procedure fmax44
                          module procedure fmax84
                          module procedure fmax48
                      end interface
                      interface fmin
                          module procedure fmin88
                          module procedure fmin44
                          module procedure fmin84
                          module procedure fmin48
                      end interface
                  contains
                      real(8) function fmax88(x, y) result (res)
                          real(8), intent (in) :: x
                          real(8), intent (in) :: y
                          res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                      end function
                      real(4) function fmax44(x, y) result (res)
                          real(4), intent (in) :: x
                          real(4), intent (in) :: y
                          res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                      end function
                      real(8) function fmax84(x, y) result(res)
                          real(8), intent (in) :: x
                          real(4), intent (in) :: y
                          res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                      end function
                      real(8) function fmax48(x, y) result(res)
                          real(4), intent (in) :: x
                          real(8), intent (in) :: y
                          res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                      end function
                      real(8) function fmin88(x, y) result (res)
                          real(8), intent (in) :: x
                          real(8), intent (in) :: y
                          res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                      end function
                      real(4) function fmin44(x, y) result (res)
                          real(4), intent (in) :: x
                          real(4), intent (in) :: y
                          res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                      end function
                      real(8) function fmin84(x, y) result(res)
                          real(8), intent (in) :: x
                          real(4), intent (in) :: y
                          res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                      end function
                      real(8) function fmin48(x, y) result(res)
                          real(4), intent (in) :: x
                          real(8), intent (in) :: y
                          res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                      end function
                  end module
                  
                  real(8) function code(x, y, z, t, a, b)
                  use fmin_fmax_functions
                      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) <= (-2d+86)) .or. (.not. ((x * y) <= 2d-73))) then
                          tmp = y * x
                      else
                          tmp = b * a
                      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) <= -2e+86) || !((x * y) <= 2e-73)) {
                  		tmp = y * x;
                  	} else {
                  		tmp = b * a;
                  	}
                  	return tmp;
                  }
                  
                  def code(x, y, z, t, a, b):
                  	tmp = 0
                  	if ((x * y) <= -2e+86) or not ((x * y) <= 2e-73):
                  		tmp = y * x
                  	else:
                  		tmp = b * a
                  	return tmp
                  
                  function code(x, y, z, t, a, b)
                  	tmp = 0.0
                  	if ((Float64(x * y) <= -2e+86) || !(Float64(x * y) <= 2e-73))
                  		tmp = Float64(y * x);
                  	else
                  		tmp = Float64(b * a);
                  	end
                  	return tmp
                  end
                  
                  function tmp_2 = code(x, y, z, t, a, b)
                  	tmp = 0.0;
                  	if (((x * y) <= -2e+86) || ~(((x * y) <= 2e-73)))
                  		tmp = y * x;
                  	else
                  		tmp = b * a;
                  	end
                  	tmp_2 = tmp;
                  end
                  
                  code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -2e+86], N[Not[LessEqual[N[(x * y), $MachinePrecision], 2e-73]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(b * a), $MachinePrecision]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  \mathbf{if}\;x \cdot y \leq -2 \cdot 10^{+86} \lor \neg \left(x \cdot y \leq 2 \cdot 10^{-73}\right):\\
                  \;\;\;\;y \cdot x\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;b \cdot a\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 2 regimes
                  2. if (*.f64 x y) < -2e86 or 1.99999999999999999e-73 < (*.f64 x y)

                    1. Initial program 95.3%

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

                      \[\leadsto \color{blue}{x \cdot y} \]
                    4. Step-by-step derivation
                      1. Applied rewrites68.6%

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

                      if -2e86 < (*.f64 x y) < 1.99999999999999999e-73

                      1. Initial program 97.6%

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

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

                          \[\leadsto \color{blue}{b \cdot a} \]
                      5. Recombined 2 regimes into one program.
                      6. Final simplification64.4%

                        \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -2 \cdot 10^{+86} \lor \neg \left(x \cdot y \leq 2 \cdot 10^{-73}\right):\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;b \cdot a\\ \end{array} \]
                      7. Add Preprocessing

                      Alternative 6: 52.1% accurate, 0.8× speedup?

                      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot b \leq -2 \cdot 10^{+101} \lor \neg \left(a \cdot b \leq 2 \cdot 10^{-108}\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) -2e+101) (not (<= (* a b) 2e-108))) (* b a) (* t z)))
                      double code(double x, double y, double z, double t, double a, double b) {
                      	double tmp;
                      	if (((a * b) <= -2e+101) || !((a * b) <= 2e-108)) {
                      		tmp = b * a;
                      	} else {
                      		tmp = t * z;
                      	}
                      	return tmp;
                      }
                      
                      module fmin_fmax_functions
                          implicit none
                          private
                          public fmax
                          public fmin
                      
                          interface fmax
                              module procedure fmax88
                              module procedure fmax44
                              module procedure fmax84
                              module procedure fmax48
                          end interface
                          interface fmin
                              module procedure fmin88
                              module procedure fmin44
                              module procedure fmin84
                              module procedure fmin48
                          end interface
                      contains
                          real(8) function fmax88(x, y) result (res)
                              real(8), intent (in) :: x
                              real(8), intent (in) :: y
                              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                          end function
                          real(4) function fmax44(x, y) result (res)
                              real(4), intent (in) :: x
                              real(4), intent (in) :: y
                              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                          end function
                          real(8) function fmax84(x, y) result(res)
                              real(8), intent (in) :: x
                              real(4), intent (in) :: y
                              res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                          end function
                          real(8) function fmax48(x, y) result(res)
                              real(4), intent (in) :: x
                              real(8), intent (in) :: y
                              res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                          end function
                          real(8) function fmin88(x, y) result (res)
                              real(8), intent (in) :: x
                              real(8), intent (in) :: y
                              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                          end function
                          real(4) function fmin44(x, y) result (res)
                              real(4), intent (in) :: x
                              real(4), intent (in) :: y
                              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                          end function
                          real(8) function fmin84(x, y) result(res)
                              real(8), intent (in) :: x
                              real(4), intent (in) :: y
                              res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                          end function
                          real(8) function fmin48(x, y) result(res)
                              real(4), intent (in) :: x
                              real(8), intent (in) :: y
                              res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                          end function
                      end module
                      
                      real(8) function code(x, y, z, t, a, b)
                      use fmin_fmax_functions
                          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+101)) .or. (.not. ((a * b) <= 2d-108))) 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) <= -2e+101) || !((a * b) <= 2e-108)) {
                      		tmp = b * a;
                      	} else {
                      		tmp = t * z;
                      	}
                      	return tmp;
                      }
                      
                      def code(x, y, z, t, a, b):
                      	tmp = 0
                      	if ((a * b) <= -2e+101) or not ((a * b) <= 2e-108):
                      		tmp = b * a
                      	else:
                      		tmp = t * z
                      	return tmp
                      
                      function code(x, y, z, t, a, b)
                      	tmp = 0.0
                      	if ((Float64(a * b) <= -2e+101) || !(Float64(a * b) <= 2e-108))
                      		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) <= -2e+101) || ~(((a * b) <= 2e-108)))
                      		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], -2e+101], N[Not[LessEqual[N[(a * b), $MachinePrecision], 2e-108]], $MachinePrecision]], N[(b * a), $MachinePrecision], N[(t * z), $MachinePrecision]]
                      
                      \begin{array}{l}
                      
                      \\
                      \begin{array}{l}
                      \mathbf{if}\;a \cdot b \leq -2 \cdot 10^{+101} \lor \neg \left(a \cdot b \leq 2 \cdot 10^{-108}\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) < -2e101 or 2.00000000000000008e-108 < (*.f64 a b)

                        1. Initial program 94.8%

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

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

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

                          if -2e101 < (*.f64 a b) < 2.00000000000000008e-108

                          1. Initial program 97.8%

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

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

                              \[\leadsto \color{blue}{t \cdot z} \]
                          5. Recombined 2 regimes into one program.
                          6. Final simplification52.2%

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

                          Alternative 7: 35.0% 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;
                          }
                          
                          module fmin_fmax_functions
                              implicit none
                              private
                              public fmax
                              public fmin
                          
                              interface fmax
                                  module procedure fmax88
                                  module procedure fmax44
                                  module procedure fmax84
                                  module procedure fmax48
                              end interface
                              interface fmin
                                  module procedure fmin88
                                  module procedure fmin44
                                  module procedure fmin84
                                  module procedure fmin48
                              end interface
                          contains
                              real(8) function fmax88(x, y) result (res)
                                  real(8), intent (in) :: x
                                  real(8), intent (in) :: y
                                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                              end function
                              real(4) function fmax44(x, y) result (res)
                                  real(4), intent (in) :: x
                                  real(4), intent (in) :: y
                                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                              end function
                              real(8) function fmax84(x, y) result(res)
                                  real(8), intent (in) :: x
                                  real(4), intent (in) :: y
                                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                              end function
                              real(8) function fmax48(x, y) result(res)
                                  real(4), intent (in) :: x
                                  real(8), intent (in) :: y
                                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                              end function
                              real(8) function fmin88(x, y) result (res)
                                  real(8), intent (in) :: x
                                  real(8), intent (in) :: y
                                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                              end function
                              real(4) function fmin44(x, y) result (res)
                                  real(4), intent (in) :: x
                                  real(4), intent (in) :: y
                                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                              end function
                              real(8) function fmin84(x, y) result(res)
                                  real(8), intent (in) :: x
                                  real(4), intent (in) :: y
                                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                              end function
                              real(8) function fmin48(x, y) result(res)
                                  real(4), intent (in) :: x
                                  real(8), intent (in) :: y
                                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                              end function
                          end module
                          
                          real(8) function code(x, y, z, t, a, b)
                          use fmin_fmax_functions
                              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 96.5%

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

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

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

                            Reproduce

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