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

Percentage Accurate: 97.5% → 98.3%
Time: 3.7s
Alternatives: 9
Speedup: 0.5×

Specification

?
\[\begin{array}{l} \\ \left(x \cdot y + z \cdot t\right) + a \cdot b \end{array} \]
(FPCore (x y z t a b) :precision binary64 (+ (+ (* x y) (* z t)) (* a b)))
double code(double x, double y, double z, double t, double a, double b) {
	return ((x * y) + (z * t)) + (a * b);
}
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.3% accurate, 0.1× speedup?

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

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

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


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

    1. Initial program 100.0%

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

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

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

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

    1. Initial program 0.0%

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

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

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

Alternative 2: 98.8% accurate, 0.1× speedup?

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

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

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

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

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

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

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

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

Alternative 3: 54.5% accurate, 0.4× speedup?

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

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

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

\mathbf{elif}\;a \cdot b \leq -1.22 \cdot 10^{+30}:\\
\;\;\;\;a \cdot b\\

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

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

\mathbf{elif}\;a \cdot b \leq 1.26 \cdot 10^{+129}:\\
\;\;\;\;x \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 a b) < -1.3999999999999999e145 or -2.2999999999999999e86 < (*.f64 a b) < -1.22e30 or 1.26e129 < (*.f64 a b)

    1. Initial program 94.8%

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

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

    if -1.3999999999999999e145 < (*.f64 a b) < -2.2999999999999999e86 or -9.10000000000000032e-237 < (*.f64 a b) < 4.70000000000000003e-133

    1. Initial program 97.6%

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

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

    if -1.22e30 < (*.f64 a b) < -9.10000000000000032e-237 or 4.70000000000000003e-133 < (*.f64 a b) < 1.26e129

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -1.4 \cdot 10^{+145}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -2.3 \cdot 10^{+86}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq -1.22 \cdot 10^{+30}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -9.1 \cdot 10^{-237}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 4.7 \cdot 10^{-133}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 1.26 \cdot 10^{+129}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]

Alternative 4: 98.3% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := a \cdot b + \left(z \cdot t + x \cdot y\right)\\ \mathbf{if}\;t_1 \leq \infty:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (+ (* a b) (+ (* z t) (* x y)))))
   (if (<= t_1 INFINITY) t_1 (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (a * b) + ((z * t) + (x * y));
	double tmp;
	if (t_1 <= ((double) INFINITY)) {
		tmp = t_1;
	} else {
		tmp = a * b;
	}
	return tmp;
}
public static double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (a * b) + ((z * t) + (x * y));
	double tmp;
	if (t_1 <= Double.POSITIVE_INFINITY) {
		tmp = t_1;
	} else {
		tmp = a * b;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	t_1 = (a * b) + ((z * t) + (x * y))
	tmp = 0
	if t_1 <= math.inf:
		tmp = t_1
	else:
		tmp = a * b
	return tmp
function code(x, y, z, t, a, b)
	t_1 = Float64(Float64(a * b) + Float64(Float64(z * t) + Float64(x * y)))
	tmp = 0.0
	if (t_1 <= Inf)
		tmp = t_1;
	else
		tmp = Float64(a * b);
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	t_1 = (a * b) + ((z * t) + (x * y));
	tmp = 0.0;
	if (t_1 <= Inf)
		tmp = t_1;
	else
		tmp = a * b;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(a * b), $MachinePrecision] + N[(N[(z * t), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, Infinity], t$95$1, N[(a * b), $MachinePrecision]]]
\begin{array}{l}

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

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


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

    1. Initial program 100.0%

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

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

    1. Initial program 0.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b + \left(z \cdot t + x \cdot y\right) \leq \infty:\\ \;\;\;\;a \cdot b + \left(z \cdot t + x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]

Alternative 5: 84.8% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
t_1 := a \cdot b + z \cdot t\\
\mathbf{if}\;a \cdot b \leq -2.7 \cdot 10^{+31}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;a \cdot b \leq 3.7 \cdot 10^{-22}:\\
\;\;\;\;z \cdot t + x \cdot y\\

\mathbf{elif}\;a \cdot b \leq 5.2 \cdot 10^{+211}:\\
\;\;\;\;a \cdot b + x \cdot y\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 a b) < -2.69999999999999986e31 or 5.1999999999999997e211 < (*.f64 a b)

    1. Initial program 94.3%

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

      \[\leadsto \color{blue}{a \cdot b + t \cdot z} \]

    if -2.69999999999999986e31 < (*.f64 a b) < 3.7e-22

    1. Initial program 99.3%

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

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

    if 3.7e-22 < (*.f64 a b) < 5.1999999999999997e211

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -2.7 \cdot 10^{+31}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 3.7 \cdot 10^{-22}:\\ \;\;\;\;z \cdot t + x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 5.2 \cdot 10^{+211}:\\ \;\;\;\;a \cdot b + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \end{array} \]

Alternative 6: 77.1% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -4 \cdot 10^{+115} \lor \neg \left(z \leq 1.16 \cdot 10^{-173}\right):\\
\;\;\;\;a \cdot b + z \cdot t\\

\mathbf{else}:\\
\;\;\;\;a \cdot b + x \cdot y\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -4.0000000000000001e115 or 1.16000000000000004e-173 < z

    1. Initial program 97.2%

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

      \[\leadsto \color{blue}{a \cdot b + t \cdot z} \]

    if -4.0000000000000001e115 < z < 1.16000000000000004e-173

    1. Initial program 98.2%

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

      \[\leadsto \color{blue}{a \cdot b + y \cdot x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification77.3%

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

Alternative 7: 54.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot b \leq -1.9 \cdot 10^{+144}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 1.08 \cdot 10^{-10}:\\ \;\;\;\;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.9e+144)
   (* a b)
   (if (<= (* a b) 1.08e-10) (* z t) (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if ((a * b) <= -1.9e+144) {
		tmp = a * b;
	} else if ((a * b) <= 1.08e-10) {
		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.9d+144)) then
        tmp = a * b
    else if ((a * b) <= 1.08d-10) 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.9e+144) {
		tmp = a * b;
	} else if ((a * b) <= 1.08e-10) {
		tmp = z * t;
	} else {
		tmp = a * b;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if (a * b) <= -1.9e+144:
		tmp = a * b
	elif (a * b) <= 1.08e-10:
		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.9e+144)
		tmp = Float64(a * b);
	elseif (Float64(a * b) <= 1.08e-10)
		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.9e+144)
		tmp = a * b;
	elseif ((a * b) <= 1.08e-10)
		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.9e+144], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1.08e-10], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;a \cdot b \leq 1.08 \cdot 10^{-10}:\\
\;\;\;\;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.90000000000000013e144 or 1.08000000000000002e-10 < (*.f64 a b)

    1. Initial program 95.7%

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

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

    if -1.90000000000000013e144 < (*.f64 a b) < 1.08000000000000002e-10

    1. Initial program 98.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -1.9 \cdot 10^{+144}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 1.08 \cdot 10^{-10}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]

Alternative 8: 71.2% accurate, 1.0× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.00000000000000002e198 or 2.4e37 < x

    1. Initial program 94.9%

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

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

    if -1.00000000000000002e198 < x < 2.4e37

    1. Initial program 98.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{+198}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 2.4 \cdot 10^{+37}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]

Alternative 9: 36.4% 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 97.6%

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

    \[\leadsto \color{blue}{a \cdot b} \]
  3. Final simplification33.4%

    \[\leadsto a \cdot b \]

Reproduce

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