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

Percentage Accurate: 98.2% → 99.4%
Time: 8.0s
Alternatives: 9
Speedup: 0.4×

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: 98.2% 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: 99.4% accurate, 0.1× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;z \cdot \left(t + a \cdot \frac{b}{z}\right)\\


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

    1. Initial program 100.0%

      \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
    2. Step-by-step derivation
      1. fma-define100.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} \]
    4. Add Preprocessing

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

    1. Initial program 0.0%

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

      \[\leadsto \color{blue}{z \cdot \left(t + \frac{x \cdot y}{z}\right)} + a \cdot b \]
    4. Taylor expanded in t around inf 0.0%

      \[\leadsto z \cdot \color{blue}{t} + a \cdot b \]
    5. Taylor expanded in z around inf 40.0%

      \[\leadsto \color{blue}{z \cdot \left(t + \frac{a \cdot b}{z}\right)} \]
    6. Step-by-step derivation
      1. associate-/l*100.0%

        \[\leadsto z \cdot \left(t + \color{blue}{a \cdot \frac{b}{z}}\right) \]
    7. Simplified100.0%

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

Alternative 2: 98.9% accurate, 0.1× speedup?

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

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

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

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

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

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

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

Alternative 3: 54.3% accurate, 0.2× speedup?

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

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

\mathbf{elif}\;x \cdot y \leq -5.5 \cdot 10^{+69}:\\
\;\;\;\;z \cdot t\\

\mathbf{elif}\;x \cdot y \leq -7.5 \cdot 10^{+38}:\\
\;\;\;\;x \cdot y\\

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 x y) < -8.8000000000000008e168 or -5.50000000000000002e69 < (*.f64 x y) < -7.4999999999999999e38 or 1.65e50 < (*.f64 x y)

    1. Initial program 100.0%

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

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

    if -8.8000000000000008e168 < (*.f64 x y) < -5.50000000000000002e69 or -7.4999999999999999e38 < (*.f64 x y) < -4.49999999999999988e-48 or -7.0000000000000003e-177 < (*.f64 x y) < 5.0000000000000002e-220

    1. Initial program 98.9%

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

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

    if -4.49999999999999988e-48 < (*.f64 x y) < -7.0000000000000003e-177 or 5.0000000000000002e-220 < (*.f64 x y) < 1.65e50

    1. Initial program 94.2%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -8.8 \cdot 10^{+168}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \cdot y \leq -5.5 \cdot 10^{+69}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;x \cdot y \leq -7.5 \cdot 10^{+38}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \cdot y \leq -4.5 \cdot 10^{-48}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;x \cdot y \leq -7 \cdot 10^{-177}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{-220}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;x \cdot y \leq 1.65 \cdot 10^{+50}:\\ \;\;\;\;a \cdot b\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 84.9% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -5.9 \cdot 10^{+168} \lor \neg \left(x \cdot y \leq -7.8 \cdot 10^{+62}\right) \land \left(x \cdot y \leq -1.25 \cdot 10^{+44} \lor \neg \left(x \cdot y \leq 2.35 \cdot 10^{+45}\right)\right):\\ \;\;\;\;x \cdot y + a \cdot b\\ \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) -5.9e+168)
         (and (not (<= (* x y) -7.8e+62))
              (or (<= (* x y) -1.25e+44) (not (<= (* x y) 2.35e+45)))))
   (+ (* x y) (* a b))
   (+ (* a b) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if (((x * y) <= -5.9e+168) || (!((x * y) <= -7.8e+62) && (((x * y) <= -1.25e+44) || !((x * y) <= 2.35e+45)))) {
		tmp = (x * y) + (a * b);
	} 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) <= (-5.9d+168)) .or. (.not. ((x * y) <= (-7.8d+62))) .and. ((x * y) <= (-1.25d+44)) .or. (.not. ((x * y) <= 2.35d+45))) then
        tmp = (x * y) + (a * b)
    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) <= -5.9e+168) || (!((x * y) <= -7.8e+62) && (((x * y) <= -1.25e+44) || !((x * y) <= 2.35e+45)))) {
		tmp = (x * y) + (a * b);
	} else {
		tmp = (a * b) + (z * t);
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if ((x * y) <= -5.9e+168) or (not ((x * y) <= -7.8e+62) and (((x * y) <= -1.25e+44) or not ((x * y) <= 2.35e+45))):
		tmp = (x * y) + (a * b)
	else:
		tmp = (a * b) + (z * t)
	return tmp
function code(x, y, z, t, a, b)
	tmp = 0.0
	if ((Float64(x * y) <= -5.9e+168) || (!(Float64(x * y) <= -7.8e+62) && ((Float64(x * y) <= -1.25e+44) || !(Float64(x * y) <= 2.35e+45))))
		tmp = Float64(Float64(x * y) + Float64(a * b));
	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) <= -5.9e+168) || (~(((x * y) <= -7.8e+62)) && (((x * y) <= -1.25e+44) || ~(((x * y) <= 2.35e+45)))))
		tmp = (x * y) + (a * b);
	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], -5.9e+168], And[N[Not[LessEqual[N[(x * y), $MachinePrecision], -7.8e+62]], $MachinePrecision], Or[LessEqual[N[(x * y), $MachinePrecision], -1.25e+44], N[Not[LessEqual[N[(x * y), $MachinePrecision], 2.35e+45]], $MachinePrecision]]]], N[(N[(x * y), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -5.9 \cdot 10^{+168} \lor \neg \left(x \cdot y \leq -7.8 \cdot 10^{+62}\right) \land \left(x \cdot y \leq -1.25 \cdot 10^{+44} \lor \neg \left(x \cdot y \leq 2.35 \cdot 10^{+45}\right)\right):\\
\;\;\;\;x \cdot y + a \cdot b\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x y) < -5.89999999999999986e168 or -7.8e62 < (*.f64 x y) < -1.2499999999999999e44 or 2.35000000000000001e45 < (*.f64 x y)

    1. Initial program 98.9%

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

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

    if -5.89999999999999986e168 < (*.f64 x y) < -7.8e62 or -1.2499999999999999e44 < (*.f64 x y) < 2.35000000000000001e45

    1. Initial program 97.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -5.9 \cdot 10^{+168} \lor \neg \left(x \cdot y \leq -7.8 \cdot 10^{+62}\right) \land \left(x \cdot y \leq -1.25 \cdot 10^{+44} \lor \neg \left(x \cdot y \leq 2.35 \cdot 10^{+45}\right)\right):\\ \;\;\;\;x \cdot y + a \cdot b\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 99.4% accurate, 0.4× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;z \cdot \left(t + a \cdot \frac{b}{z}\right)\\


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

    1. Initial program 100.0%

      \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
    2. Add Preprocessing

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

    1. Initial program 0.0%

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

      \[\leadsto \color{blue}{z \cdot \left(t + \frac{x \cdot y}{z}\right)} + a \cdot b \]
    4. Taylor expanded in t around inf 0.0%

      \[\leadsto z \cdot \color{blue}{t} + a \cdot b \]
    5. Taylor expanded in z around inf 40.0%

      \[\leadsto \color{blue}{z \cdot \left(t + \frac{a \cdot b}{z}\right)} \]
    6. Step-by-step derivation
      1. associate-/l*100.0%

        \[\leadsto z \cdot \left(t + \color{blue}{a \cdot \frac{b}{z}}\right) \]
    7. Simplified100.0%

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

Alternative 6: 80.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -1.65 \cdot 10^{+170} \lor \neg \left(x \cdot y \leq 3 \cdot 10^{+54}\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) -1.65e+170) (not (<= (* x y) 3e+54)))
   (* 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) <= -1.65e+170) || !((x * y) <= 3e+54)) {
		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) <= (-1.65d+170)) .or. (.not. ((x * y) <= 3d+54))) 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) <= -1.65e+170) || !((x * y) <= 3e+54)) {
		tmp = x * y;
	} else {
		tmp = (a * b) + (z * t);
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if ((x * y) <= -1.65e+170) or not ((x * y) <= 3e+54):
		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) <= -1.65e+170) || !(Float64(x * y) <= 3e+54))
		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) <= -1.65e+170) || ~(((x * y) <= 3e+54)))
		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], -1.65e+170], N[Not[LessEqual[N[(x * y), $MachinePrecision], 3e+54]], $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 -1.65 \cdot 10^{+170} \lor \neg \left(x \cdot y \leq 3 \cdot 10^{+54}\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) < -1.65000000000000012e170 or 2.9999999999999999e54 < (*.f64 x y)

    1. Initial program 100.0%

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

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

    if -1.65000000000000012e170 < (*.f64 x y) < 2.9999999999999999e54

    1. Initial program 97.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -1.65 \cdot 10^{+170} \lor \neg \left(x \cdot y \leq 3 \cdot 10^{+54}\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 86.4% accurate, 0.5× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 x y) < -5e15

    1. Initial program 100.0%

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

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

    if -5e15 < (*.f64 x y) < 1.0000000000000001e44

    1. Initial program 97.0%

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

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

    if 1.0000000000000001e44 < (*.f64 x y)

    1. Initial program 98.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+15}:\\ \;\;\;\;x \cdot y + z \cdot t\\ \mathbf{elif}\;x \cdot y \leq 10^{+44}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot y + a \cdot b\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 54.5% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot b \leq -3.8 \cdot 10^{+73} \lor \neg \left(a \cdot b \leq 3.4 \cdot 10^{+54}\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) -3.8e+73) (not (<= (* a b) 3.4e+54))) (* a b) (* z t)))
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if (((a * b) <= -3.8e+73) || !((a * b) <= 3.4e+54)) {
		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) <= (-3.8d+73)) .or. (.not. ((a * b) <= 3.4d+54))) 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) <= -3.8e+73) || !((a * b) <= 3.4e+54)) {
		tmp = a * b;
	} else {
		tmp = z * t;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if ((a * b) <= -3.8e+73) or not ((a * b) <= 3.4e+54):
		tmp = a * b
	else:
		tmp = z * t
	return tmp
function code(x, y, z, t, a, b)
	tmp = 0.0
	if ((Float64(a * b) <= -3.8e+73) || !(Float64(a * b) <= 3.4e+54))
		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) <= -3.8e+73) || ~(((a * b) <= 3.4e+54)))
		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], -3.8e+73], N[Not[LessEqual[N[(a * b), $MachinePrecision], 3.4e+54]], $MachinePrecision]], N[(a * b), $MachinePrecision], N[(z * t), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -3.8 \cdot 10^{+73} \lor \neg \left(a \cdot b \leq 3.4 \cdot 10^{+54}\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) < -3.80000000000000022e73 or 3.4000000000000001e54 < (*.f64 a b)

    1. Initial program 94.9%

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

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

    if -3.80000000000000022e73 < (*.f64 a b) < 3.4000000000000001e54

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -3.8 \cdot 10^{+73} \lor \neg \left(a \cdot b \leq 3.4 \cdot 10^{+54}\right):\\ \;\;\;\;a \cdot b\\ \mathbf{else}:\\ \;\;\;\;z \cdot t\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 35.5% 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.0%

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

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

Reproduce

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