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

Percentage Accurate: 97.6% → 98.9%
Time: 6.6s
Alternatives: 7
Speedup: 1.2×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 7 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 97.6% accurate, 1.0× speedup?

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

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

Alternative 1: 98.9% accurate, 1.2× speedup?

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

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

    \[\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. lift-*.f64N/A

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

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

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

Alternative 2: 86.1% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1 \cdot 10^{+25}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\

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

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


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

    1. Initial program 98.4%

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

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

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

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

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

    if -1.00000000000000009e25 < (*.f64 a b) < 9.99999999999999914e28

    1. Initial program 99.3%

      \[\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. lift-*.f64N/A

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

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

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

      \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{t \cdot z}\right) \]
    6. Step-by-step derivation
      1. lower-*.f6492.5

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

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

    if 9.99999999999999914e28 < (*.f64 a b)

    1. Initial program 96.4%

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

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

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

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

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

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

Alternative 3: 86.1% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1 \cdot 10^{+25}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\right)\\

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

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


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

    1. Initial program 98.4%

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

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

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

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

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

    if -1.00000000000000009e25 < (*.f64 a b) < 9.99999999999999914e28

    1. Initial program 99.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. lower-fma.f64N/A

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

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

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

    if 9.99999999999999914e28 < (*.f64 a b)

    1. Initial program 96.4%

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

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

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

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

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

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

Alternative 4: 85.5% accurate, 0.6× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 z t) < -9.99999999999999946e33 or 1e110 < (*.f64 z t)

    1. Initial program 97.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. lower-fma.f64N/A

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

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

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

    if -9.99999999999999946e33 < (*.f64 z t) < 1e110

    1. Initial program 98.7%

      \[\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. lower-fma.f64N/A

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

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

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

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

Alternative 5: 79.2% accurate, 0.6× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x y) < -6.29999999999999961e109 or 5.8000000000000003e76 < (*.f64 x y)

    1. Initial program 96.2%

      \[\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. lower-*.f6474.9

        \[\leadsto \color{blue}{x \cdot y} \]
    5. Applied rewrites74.9%

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

    if -6.29999999999999961e109 < (*.f64 x y) < 5.8000000000000003e76

    1. Initial program 99.4%

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

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

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

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

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

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

Alternative 6: 54.8% accurate, 0.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 a b) < -1.55000000000000007e59 or 2.9999999999999999e29 < (*.f64 a b)

    1. Initial program 97.2%

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

        \[\leadsto \color{blue}{a \cdot b} \]
    5. Applied rewrites68.2%

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

    if -1.55000000000000007e59 < (*.f64 a b) < 2.9999999999999999e29

    1. Initial program 99.3%

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

        \[\leadsto \color{blue}{t \cdot z} \]
    5. Applied rewrites50.2%

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

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

Alternative 7: 35.1% 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 98.4%

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

      \[\leadsto \color{blue}{a \cdot b} \]
  5. Applied rewrites34.8%

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

Reproduce

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