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

Percentage Accurate: 97.5% → 98.8%
Time: 2.3s
Alternatives: 8
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);
}
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}

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 8 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);
}
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: 98.8% accurate, 1.2× speedup?

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

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

    \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
  2. 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. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 86.4% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -200000000000:\\
\;\;\;\;\mathsf{fma}\left(y, x, a \cdot b\right)\\

\mathbf{elif}\;a \cdot b \leq 10^{+33}:\\
\;\;\;\;\mathsf{fma}\left(t, z, y \cdot x\right)\\

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


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

    1. Initial program 95.3%

      \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
    2. 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. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{a \cdot b}\right) \]
    5. Step-by-step derivation
      1. lower-*.f6481.0

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

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

    if -2e11 < (*.f64 a b) < 9.9999999999999995e32

    1. Initial program 99.1%

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

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

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

        \[\leadsto \mathsf{fma}\left(t, z, y \cdot x\right) \]
      3. lower-*.f6490.4

        \[\leadsto \mathsf{fma}\left(t, z, y \cdot x\right) \]
    4. Applied rewrites90.4%

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

    if 9.9999999999999995e32 < (*.f64 a b)

    1. Initial program 96.1%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(b, a, t \cdot z\right) \]
    4. Applied rewrites82.8%

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

Alternative 3: 86.3% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -200000000000:\\
\;\;\;\;\mathsf{fma}\left(b, a, y \cdot x\right)\\

\mathbf{elif}\;a \cdot b \leq 10^{+33}:\\
\;\;\;\;\mathsf{fma}\left(t, z, y \cdot x\right)\\

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


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

    1. Initial program 95.3%

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(b, a, y \cdot x\right) \]
    4. Applied rewrites80.6%

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

    if -2e11 < (*.f64 a b) < 9.9999999999999995e32

    1. Initial program 99.1%

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

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

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

        \[\leadsto \mathsf{fma}\left(t, z, y \cdot x\right) \]
      3. lower-*.f6490.4

        \[\leadsto \mathsf{fma}\left(t, z, y \cdot x\right) \]
    4. Applied rewrites90.4%

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

    if 9.9999999999999995e32 < (*.f64 a b)

    1. Initial program 96.1%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(b, a, t \cdot z\right) \]
    4. Applied rewrites82.8%

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

Alternative 4: 84.5% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{fma}\left(b, a, t \cdot z\right)\\ \mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+131}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+139}:\\ \;\;\;\;\mathsf{fma}\left(b, a, y \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (fma b a (* t z))))
   (if (<= (* z t) -5e+131)
     t_1
     (if (<= (* z t) 5e+139) (fma b a (* y x)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = fma(b, a, (t * z));
	double tmp;
	if ((z * t) <= -5e+131) {
		tmp = t_1;
	} else if ((z * t) <= 5e+139) {
		tmp = fma(b, a, (y * x));
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z, t, a, b)
	t_1 = fma(b, a, Float64(t * z))
	tmp = 0.0
	if (Float64(z * t) <= -5e+131)
		tmp = t_1;
	elseif (Float64(z * t) <= 5e+139)
		tmp = fma(b, a, Float64(y * x));
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * t), $MachinePrecision], -5e+131], t$95$1, If[LessEqual[N[(z * t), $MachinePrecision], 5e+139], N[(b * a + N[(y * x), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(b, a, t \cdot z\right)\\
\mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+131}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+139}:\\
\;\;\;\;\mathsf{fma}\left(b, a, y \cdot x\right)\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 z t) < -4.99999999999999995e131 or 5.0000000000000003e139 < (*.f64 z t)

    1. Initial program 93.9%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(b, a, t \cdot z\right) \]
    4. Applied rewrites86.3%

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

    if -4.99999999999999995e131 < (*.f64 z t) < 5.0000000000000003e139

    1. Initial program 99.1%

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(b, a, y \cdot x\right) \]
    4. Applied rewrites83.7%

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

Alternative 5: 81.5% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+179}:\\
\;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x y) < -1.0000000000000001e172 or 5e179 < (*.f64 x y)

    1. Initial program 93.1%

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

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

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

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

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

    if -1.0000000000000001e172 < (*.f64 x y) < 5e179

    1. Initial program 99.0%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(b, a, t \cdot z\right) \]
    4. Applied rewrites82.6%

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

Alternative 6: 52.2% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+131}:\\
\;\;\;\;t \cdot z\\

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

\mathbf{else}:\\
\;\;\;\;t \cdot z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 z t) < -4.99999999999999995e131 or 4.9999999999999999e146 < (*.f64 z t)

    1. Initial program 93.9%

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

      \[\leadsto \color{blue}{t \cdot z} \]
    3. Step-by-step derivation
      1. lower-*.f6475.3

        \[\leadsto t \cdot \color{blue}{z} \]
    4. Applied rewrites75.3%

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

    if -4.99999999999999995e131 < (*.f64 z t) < 4.9999999999999999e146

    1. Initial program 99.1%

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

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

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

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

      \[\leadsto \color{blue}{y \cdot x} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 7: 54.5% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -2 \cdot 10^{+141}:\\
\;\;\;\;t \cdot z\\

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

\mathbf{else}:\\
\;\;\;\;t \cdot z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 z t) < -2.00000000000000003e141 or 4.9999999999999999e146 < (*.f64 z t)

    1. Initial program 93.8%

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

      \[\leadsto \color{blue}{t \cdot z} \]
    3. Step-by-step derivation
      1. lower-*.f6475.9

        \[\leadsto t \cdot \color{blue}{z} \]
    4. Applied rewrites75.9%

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

    if -2.00000000000000003e141 < (*.f64 z t) < 4.9999999999999999e146

    1. Initial program 99.1%

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

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

        \[\leadsto b \cdot \color{blue}{a} \]
      2. lower-*.f6445.4

        \[\leadsto b \cdot \color{blue}{a} \]
    4. Applied rewrites45.4%

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

Alternative 8: 36.8% 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 97.5%

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

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

      \[\leadsto b \cdot \color{blue}{a} \]
    2. lower-*.f6436.8

      \[\leadsto b \cdot \color{blue}{a} \]
  4. Applied rewrites36.8%

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

Reproduce

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