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

Percentage Accurate: 97.5% → 98.9%
Time: 5.2s
Alternatives: 9
Speedup: 1.0×

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 9 alternatives:

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

Initial Program: 97.5% accurate, 1.0× speedup?

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

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

Alternative 1: 98.9% accurate, 0.1× speedup?

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

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

    \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
  2. Step-by-step derivation
    1. associate-+l+98.8%

      \[\leadsto \color{blue}{x \cdot y + \left(z \cdot t + a \cdot b\right)} \]
    2. fma-def99.6%

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

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

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

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

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

Alternative 2: 98.0% accurate, 0.1× speedup?

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

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

    \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
  2. Step-by-step derivation
    1. fma-def99.2%

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

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

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

Alternative 3: 53.8% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -6 \cdot 10^{+39}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \cdot y \leq -8.5 \cdot 10^{-50}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;x \cdot y \leq -6 \cdot 10^{-299}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;x \cdot y \leq 4 \cdot 10^{-140}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;x \cdot y \leq 680:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;x \cdot y \leq 7.4 \cdot 10^{+22}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;x \cdot y \leq 1.85 \cdot 10^{+77} \lor \neg \left(x \cdot y \leq 2.2 \cdot 10^{+142}\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (if (<= (* x y) -6e+39)
   (* x y)
   (if (<= (* x y) -8.5e-50)
     (* z t)
     (if (<= (* x y) -6e-299)
       (* a b)
       (if (<= (* x y) 4e-140)
         (* z t)
         (if (<= (* x y) 680.0)
           (* a b)
           (if (<= (* x y) 7.4e+22)
             (* z t)
             (if (or (<= (* x y) 1.85e+77) (not (<= (* x y) 2.2e+142)))
               (* x y)
               (* a b)))))))))
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if ((x * y) <= -6e+39) {
		tmp = x * y;
	} else if ((x * y) <= -8.5e-50) {
		tmp = z * t;
	} else if ((x * y) <= -6e-299) {
		tmp = a * b;
	} else if ((x * y) <= 4e-140) {
		tmp = z * t;
	} else if ((x * y) <= 680.0) {
		tmp = a * b;
	} else if ((x * y) <= 7.4e+22) {
		tmp = z * t;
	} else if (((x * y) <= 1.85e+77) || !((x * y) <= 2.2e+142)) {
		tmp = x * y;
	} 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 ((x * y) <= (-6d+39)) then
        tmp = x * y
    else if ((x * y) <= (-8.5d-50)) then
        tmp = z * t
    else if ((x * y) <= (-6d-299)) then
        tmp = a * b
    else if ((x * y) <= 4d-140) then
        tmp = z * t
    else if ((x * y) <= 680.0d0) then
        tmp = a * b
    else if ((x * y) <= 7.4d+22) then
        tmp = z * t
    else if (((x * y) <= 1.85d+77) .or. (.not. ((x * y) <= 2.2d+142))) then
        tmp = x * y
    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 ((x * y) <= -6e+39) {
		tmp = x * y;
	} else if ((x * y) <= -8.5e-50) {
		tmp = z * t;
	} else if ((x * y) <= -6e-299) {
		tmp = a * b;
	} else if ((x * y) <= 4e-140) {
		tmp = z * t;
	} else if ((x * y) <= 680.0) {
		tmp = a * b;
	} else if ((x * y) <= 7.4e+22) {
		tmp = z * t;
	} else if (((x * y) <= 1.85e+77) || !((x * y) <= 2.2e+142)) {
		tmp = x * y;
	} else {
		tmp = a * b;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if (x * y) <= -6e+39:
		tmp = x * y
	elif (x * y) <= -8.5e-50:
		tmp = z * t
	elif (x * y) <= -6e-299:
		tmp = a * b
	elif (x * y) <= 4e-140:
		tmp = z * t
	elif (x * y) <= 680.0:
		tmp = a * b
	elif (x * y) <= 7.4e+22:
		tmp = z * t
	elif ((x * y) <= 1.85e+77) or not ((x * y) <= 2.2e+142):
		tmp = x * y
	else:
		tmp = a * b
	return tmp
function code(x, y, z, t, a, b)
	tmp = 0.0
	if (Float64(x * y) <= -6e+39)
		tmp = Float64(x * y);
	elseif (Float64(x * y) <= -8.5e-50)
		tmp = Float64(z * t);
	elseif (Float64(x * y) <= -6e-299)
		tmp = Float64(a * b);
	elseif (Float64(x * y) <= 4e-140)
		tmp = Float64(z * t);
	elseif (Float64(x * y) <= 680.0)
		tmp = Float64(a * b);
	elseif (Float64(x * y) <= 7.4e+22)
		tmp = Float64(z * t);
	elseif ((Float64(x * y) <= 1.85e+77) || !(Float64(x * y) <= 2.2e+142))
		tmp = Float64(x * y);
	else
		tmp = Float64(a * b);
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	tmp = 0.0;
	if ((x * y) <= -6e+39)
		tmp = x * y;
	elseif ((x * y) <= -8.5e-50)
		tmp = z * t;
	elseif ((x * y) <= -6e-299)
		tmp = a * b;
	elseif ((x * y) <= 4e-140)
		tmp = z * t;
	elseif ((x * y) <= 680.0)
		tmp = a * b;
	elseif ((x * y) <= 7.4e+22)
		tmp = z * t;
	elseif (((x * y) <= 1.85e+77) || ~(((x * y) <= 2.2e+142)))
		tmp = x * y;
	else
		tmp = a * b;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(x * y), $MachinePrecision], -6e+39], N[(x * y), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], -8.5e-50], N[(z * t), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], -6e-299], N[(a * b), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 4e-140], N[(z * t), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 680.0], N[(a * b), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 7.4e+22], N[(z * t), $MachinePrecision], If[Or[LessEqual[N[(x * y), $MachinePrecision], 1.85e+77], N[Not[LessEqual[N[(x * y), $MachinePrecision], 2.2e+142]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(a * b), $MachinePrecision]]]]]]]]
\begin{array}{l}

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

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

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

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

\mathbf{elif}\;x \cdot y \leq 680:\\
\;\;\;\;a \cdot b\\

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

\mathbf{elif}\;x \cdot y \leq 1.85 \cdot 10^{+77} \lor \neg \left(x \cdot y \leq 2.2 \cdot 10^{+142}\right):\\
\;\;\;\;x \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 x y) < -5.9999999999999999e39 or 7.3999999999999996e22 < (*.f64 x y) < 1.84999999999999997e77 or 2.19999999999999987e142 < (*.f64 x y)

    1. Initial program 98.2%

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

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

    if -5.9999999999999999e39 < (*.f64 x y) < -8.50000000000000012e-50 or -5.99999999999999969e-299 < (*.f64 x y) < 3.9999999999999999e-140 or 680 < (*.f64 x y) < 7.3999999999999996e22

    1. Initial program 100.0%

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

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

    if -8.50000000000000012e-50 < (*.f64 x y) < -5.99999999999999969e-299 or 3.9999999999999999e-140 < (*.f64 x y) < 680 or 1.84999999999999997e77 < (*.f64 x y) < 2.19999999999999987e142

    1. Initial program 98.3%

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

      \[\leadsto \color{blue}{a \cdot b} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification66.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -6 \cdot 10^{+39}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \cdot y \leq -8.5 \cdot 10^{-50}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;x \cdot y \leq -6 \cdot 10^{-299}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;x \cdot y \leq 4 \cdot 10^{-140}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;x \cdot y \leq 680:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;x \cdot y \leq 7.4 \cdot 10^{+22}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;x \cdot y \leq 1.85 \cdot 10^{+77} \lor \neg \left(x \cdot y \leq 2.2 \cdot 10^{+142}\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]

Alternative 4: 83.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := x \cdot y + z \cdot t\\ t_2 := a \cdot b + x \cdot y\\ \mathbf{if}\;a \cdot b \leq -3 \cdot 10^{+74}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \cdot b \leq 2.9 \cdot 10^{-19}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \cdot b \leq 1.8 \cdot 10^{+57}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{+159}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (+ (* x y) (* z t))) (t_2 (+ (* a b) (* x y))))
   (if (<= (* a b) -3e+74)
     t_2
     (if (<= (* a b) 2.9e-19)
       t_1
       (if (<= (* a b) 1.8e+57)
         t_2
         (if (<= (* a b) 2e+159) t_1 (+ (* a b) (* z t))))))))
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (x * y) + (z * t);
	double t_2 = (a * b) + (x * y);
	double tmp;
	if ((a * b) <= -3e+74) {
		tmp = t_2;
	} else if ((a * b) <= 2.9e-19) {
		tmp = t_1;
	} else if ((a * b) <= 1.8e+57) {
		tmp = t_2;
	} else if ((a * b) <= 2e+159) {
		tmp = t_1;
	} else {
		tmp = (a * b) + (z * t);
	}
	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) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_1 = (x * y) + (z * t)
    t_2 = (a * b) + (x * y)
    if ((a * b) <= (-3d+74)) then
        tmp = t_2
    else if ((a * b) <= 2.9d-19) then
        tmp = t_1
    else if ((a * b) <= 1.8d+57) then
        tmp = t_2
    else if ((a * b) <= 2d+159) then
        tmp = t_1
    else
        tmp = (a * b) + (z * t)
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (x * y) + (z * t);
	double t_2 = (a * b) + (x * y);
	double tmp;
	if ((a * b) <= -3e+74) {
		tmp = t_2;
	} else if ((a * b) <= 2.9e-19) {
		tmp = t_1;
	} else if ((a * b) <= 1.8e+57) {
		tmp = t_2;
	} else if ((a * b) <= 2e+159) {
		tmp = t_1;
	} else {
		tmp = (a * b) + (z * t);
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	t_1 = (x * y) + (z * t)
	t_2 = (a * b) + (x * y)
	tmp = 0
	if (a * b) <= -3e+74:
		tmp = t_2
	elif (a * b) <= 2.9e-19:
		tmp = t_1
	elif (a * b) <= 1.8e+57:
		tmp = t_2
	elif (a * b) <= 2e+159:
		tmp = t_1
	else:
		tmp = (a * b) + (z * t)
	return tmp
function code(x, y, z, t, a, b)
	t_1 = Float64(Float64(x * y) + Float64(z * t))
	t_2 = Float64(Float64(a * b) + Float64(x * y))
	tmp = 0.0
	if (Float64(a * b) <= -3e+74)
		tmp = t_2;
	elseif (Float64(a * b) <= 2.9e-19)
		tmp = t_1;
	elseif (Float64(a * b) <= 1.8e+57)
		tmp = t_2;
	elseif (Float64(a * b) <= 2e+159)
		tmp = t_1;
	else
		tmp = Float64(Float64(a * b) + Float64(z * t));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	t_1 = (x * y) + (z * t);
	t_2 = (a * b) + (x * y);
	tmp = 0.0;
	if ((a * b) <= -3e+74)
		tmp = t_2;
	elseif ((a * b) <= 2.9e-19)
		tmp = t_1;
	elseif ((a * b) <= 1.8e+57)
		tmp = t_2;
	elseif ((a * b) <= 2e+159)
		tmp = t_1;
	else
		tmp = (a * b) + (z * t);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(a * b), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(a * b), $MachinePrecision], -3e+74], t$95$2, If[LessEqual[N[(a * b), $MachinePrecision], 2.9e-19], t$95$1, If[LessEqual[N[(a * b), $MachinePrecision], 1.8e+57], t$95$2, If[LessEqual[N[(a * b), $MachinePrecision], 2e+159], t$95$1, N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := x \cdot y + z \cdot t\\
t_2 := a \cdot b + x \cdot y\\
\mathbf{if}\;a \cdot b \leq -3 \cdot 10^{+74}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;a \cdot b \leq 2.9 \cdot 10^{-19}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;a \cdot b \leq 1.8 \cdot 10^{+57}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{+159}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 a b) < -3e74 or 2.9e-19 < (*.f64 a b) < 1.8000000000000001e57

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{a \cdot b + x \cdot y} \]

    if -3e74 < (*.f64 a b) < 2.9e-19 or 1.8000000000000001e57 < (*.f64 a b) < 1.9999999999999999e159

    1. Initial program 99.3%

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

      \[\leadsto \color{blue}{t \cdot z + x \cdot y} \]

    if 1.9999999999999999e159 < (*.f64 a b)

    1. Initial program 94.6%

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

      \[\leadsto \color{blue}{a \cdot b + t \cdot z} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification89.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -3 \cdot 10^{+74}:\\ \;\;\;\;a \cdot b + x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 2.9 \cdot 10^{-19}:\\ \;\;\;\;x \cdot y + z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 1.8 \cdot 10^{+57}:\\ \;\;\;\;a \cdot b + x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{+159}:\\ \;\;\;\;x \cdot y + z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \end{array} \]

Alternative 5: 52.0% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot b \leq -4.4 \cdot 10^{+67} \lor \neg \left(a \cdot b \leq 2.9 \cdot 10^{-19} \lor \neg \left(a \cdot b \leq 2.95 \cdot 10^{+57}\right) \land a \cdot b \leq 4.5 \cdot 10^{+219}\right):\\ \;\;\;\;a \cdot b\\ \mathbf{else}:\\ \;\;\;\;z \cdot t\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (if (or (<= (* a b) -4.4e+67)
         (not
          (or (<= (* a b) 2.9e-19)
              (and (not (<= (* a b) 2.95e+57)) (<= (* a b) 4.5e+219)))))
   (* a b)
   (* z t)))
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if (((a * b) <= -4.4e+67) || !(((a * b) <= 2.9e-19) || (!((a * b) <= 2.95e+57) && ((a * b) <= 4.5e+219)))) {
		tmp = a * b;
	} else {
		tmp = z * t;
	}
	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) <= (-4.4d+67)) .or. (.not. ((a * b) <= 2.9d-19) .or. (.not. ((a * b) <= 2.95d+57)) .and. ((a * b) <= 4.5d+219))) then
        tmp = a * b
    else
        tmp = z * t
    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) <= -4.4e+67) || !(((a * b) <= 2.9e-19) || (!((a * b) <= 2.95e+57) && ((a * b) <= 4.5e+219)))) {
		tmp = a * b;
	} else {
		tmp = z * t;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if ((a * b) <= -4.4e+67) or not (((a * b) <= 2.9e-19) or (not ((a * b) <= 2.95e+57) and ((a * b) <= 4.5e+219))):
		tmp = a * b
	else:
		tmp = z * t
	return tmp
function code(x, y, z, t, a, b)
	tmp = 0.0
	if ((Float64(a * b) <= -4.4e+67) || !((Float64(a * b) <= 2.9e-19) || (!(Float64(a * b) <= 2.95e+57) && (Float64(a * b) <= 4.5e+219))))
		tmp = Float64(a * b);
	else
		tmp = Float64(z * t);
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	tmp = 0.0;
	if (((a * b) <= -4.4e+67) || ~((((a * b) <= 2.9e-19) || (~(((a * b) <= 2.95e+57)) && ((a * b) <= 4.5e+219)))))
		tmp = a * b;
	else
		tmp = z * t;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(a * b), $MachinePrecision], -4.4e+67], N[Not[Or[LessEqual[N[(a * b), $MachinePrecision], 2.9e-19], And[N[Not[LessEqual[N[(a * b), $MachinePrecision], 2.95e+57]], $MachinePrecision], LessEqual[N[(a * b), $MachinePrecision], 4.5e+219]]]], $MachinePrecision]], N[(a * b), $MachinePrecision], N[(z * t), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -4.4 \cdot 10^{+67} \lor \neg \left(a \cdot b \leq 2.9 \cdot 10^{-19} \lor \neg \left(a \cdot b \leq 2.95 \cdot 10^{+57}\right) \land a \cdot b \leq 4.5 \cdot 10^{+219}\right):\\
\;\;\;\;a \cdot b\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 a b) < -4.4e67 or 2.9e-19 < (*.f64 a b) < 2.95000000000000006e57 or 4.50000000000000023e219 < (*.f64 a b)

    1. Initial program 97.8%

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

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

    if -4.4e67 < (*.f64 a b) < 2.9e-19 or 2.95000000000000006e57 < (*.f64 a b) < 4.50000000000000023e219

    1. Initial program 99.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -4.4 \cdot 10^{+67} \lor \neg \left(a \cdot b \leq 2.9 \cdot 10^{-19} \lor \neg \left(a \cdot b \leq 2.95 \cdot 10^{+57}\right) \land a \cdot b \leq 4.5 \cdot 10^{+219}\right):\\ \;\;\;\;a \cdot b\\ \mathbf{else}:\\ \;\;\;\;z \cdot t\\ \end{array} \]

Alternative 6: 79.9% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -3.4 \cdot 10^{+221} \lor \neg \left(x \cdot y \leq 3.35 \cdot 10^{+146}\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (if (or (<= (* x y) -3.4e+221) (not (<= (* x y) 3.35e+146)))
   (* x y)
   (+ (* a b) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if (((x * y) <= -3.4e+221) || !((x * y) <= 3.35e+146)) {
		tmp = x * y;
	} else {
		tmp = (a * b) + (z * t);
	}
	return tmp;
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if (((x * y) <= (-3.4d+221)) .or. (.not. ((x * y) <= 3.35d+146))) then
        tmp = x * y
    else
        tmp = (a * b) + (z * t)
    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) <= -3.4e+221) || !((x * y) <= 3.35e+146)) {
		tmp = x * y;
	} else {
		tmp = (a * b) + (z * t);
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if ((x * y) <= -3.4e+221) or not ((x * y) <= 3.35e+146):
		tmp = x * y
	else:
		tmp = (a * b) + (z * t)
	return tmp
function code(x, y, z, t, a, b)
	tmp = 0.0
	if ((Float64(x * y) <= -3.4e+221) || !(Float64(x * y) <= 3.35e+146))
		tmp = Float64(x * y);
	else
		tmp = Float64(Float64(a * b) + Float64(z * t));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	tmp = 0.0;
	if (((x * y) <= -3.4e+221) || ~(((x * y) <= 3.35e+146)))
		tmp = x * y;
	else
		tmp = (a * b) + (z * t);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -3.4e+221], N[Not[LessEqual[N[(x * y), $MachinePrecision], 3.35e+146]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -3.4 \cdot 10^{+221} \lor \neg \left(x \cdot y \leq 3.35 \cdot 10^{+146}\right):\\
\;\;\;\;x \cdot y\\

\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x y) < -3.3999999999999998e221 or 3.35000000000000003e146 < (*.f64 x y)

    1. Initial program 96.9%

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

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

    if -3.3999999999999998e221 < (*.f64 x y) < 3.35000000000000003e146

    1. Initial program 99.4%

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

      \[\leadsto \color{blue}{a \cdot b + t \cdot z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification84.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -3.4 \cdot 10^{+221} \lor \neg \left(x \cdot y \leq 3.35 \cdot 10^{+146}\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \end{array} \]

Alternative 7: 78.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.35 \cdot 10^{+91} \lor \neg \left(x \leq 2.4 \cdot 10^{-71}\right):\\ \;\;\;\;a \cdot b + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (if (or (<= x -1.35e+91) (not (<= x 2.4e-71)))
   (+ (* a b) (* x y))
   (+ (* a b) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if ((x <= -1.35e+91) || !(x <= 2.4e-71)) {
		tmp = (a * b) + (x * y);
	} else {
		tmp = (a * b) + (z * t);
	}
	return tmp;
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if ((x <= (-1.35d+91)) .or. (.not. (x <= 2.4d-71))) then
        tmp = (a * b) + (x * y)
    else
        tmp = (a * b) + (z * t)
    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 <= -1.35e+91) || !(x <= 2.4e-71)) {
		tmp = (a * b) + (x * y);
	} else {
		tmp = (a * b) + (z * t);
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if (x <= -1.35e+91) or not (x <= 2.4e-71):
		tmp = (a * b) + (x * y)
	else:
		tmp = (a * b) + (z * t)
	return tmp
function code(x, y, z, t, a, b)
	tmp = 0.0
	if ((x <= -1.35e+91) || !(x <= 2.4e-71))
		tmp = Float64(Float64(a * b) + Float64(x * y));
	else
		tmp = Float64(Float64(a * b) + Float64(z * t));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	tmp = 0.0;
	if ((x <= -1.35e+91) || ~((x <= 2.4e-71)))
		tmp = (a * b) + (x * y);
	else
		tmp = (a * b) + (z * t);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[x, -1.35e+91], N[Not[LessEqual[x, 2.4e-71]], $MachinePrecision]], N[(N[(a * b), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.35 \cdot 10^{+91} \lor \neg \left(x \leq 2.4 \cdot 10^{-71}\right):\\
\;\;\;\;a \cdot b + x \cdot y\\

\mathbf{else}:\\
\;\;\;\;a \cdot b + z \cdot t\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.35e91 or 2.4e-71 < x

    1. Initial program 98.5%

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

      \[\leadsto \color{blue}{a \cdot b + x \cdot y} \]

    if -1.35e91 < x < 2.4e-71

    1. Initial program 99.2%

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

      \[\leadsto \color{blue}{a \cdot b + t \cdot z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification79.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.35 \cdot 10^{+91} \lor \neg \left(x \leq 2.4 \cdot 10^{-71}\right):\\ \;\;\;\;a \cdot b + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \end{array} \]

Alternative 8: 97.5% accurate, 1.0× speedup?

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

\\
a \cdot b + \left(x \cdot y + z \cdot t\right)
\end{array}
Derivation
  1. Initial program 98.8%

    \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
  2. Final simplification98.8%

    \[\leadsto a \cdot b + \left(x \cdot y + z \cdot t\right) \]

Alternative 9: 36.3% accurate, 3.7× speedup?

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

\\
a \cdot b
\end{array}
Derivation
  1. Initial program 98.8%

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

    \[\leadsto \color{blue}{a \cdot b} \]
  3. Final simplification34.5%

    \[\leadsto a \cdot b \]

Reproduce

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