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

Percentage Accurate: 97.7% → 98.9%
Time: 7.5s
Alternatives: 11
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 11 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.7% 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 96.8%

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

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

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

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

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

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

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

Alternative 2: 98.9% accurate, 0.1× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\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-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} \]
    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 x around 0 25.0%

      \[\leadsto \color{blue}{a \cdot b + t \cdot z} \]
    4. Step-by-step derivation
      1. fma-def62.5%

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

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

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

Alternative 3: 98.9% accurate, 0.1× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, b, z \cdot t\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 x around 0 25.0%

      \[\leadsto \color{blue}{a \cdot b + t \cdot z} \]
    4. Step-by-step derivation
      1. fma-def62.5%

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

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

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

Alternative 4: 98.5% accurate, 0.1× speedup?

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, \mathsf{fma}\left(a, b, z \cdot t\right)\right)} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. fma-udef97.6%

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

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

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

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

Alternative 5: 53.9% accurate, 0.4× speedup?

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

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

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

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

\mathbf{elif}\;a \cdot b \leq 0.0037:\\
\;\;\;\;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.8999999999999999e58 or 0.0037000000000000002 < (*.f64 a b)

    1. Initial program 95.7%

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

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

    if -1.8999999999999999e58 < (*.f64 a b) < -7.1999999999999998e-53 or -1.25e-268 < (*.f64 a b) < 0.0037000000000000002

    1. Initial program 98.2%

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

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

    if -7.1999999999999998e-53 < (*.f64 a b) < -1.25e-268

    1. Initial program 96.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -1.9 \cdot 10^{+58}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -7.2 \cdot 10^{-53}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq -1.25 \cdot 10^{-268}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 0.0037:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 98.6% accurate, 0.4× speedup?

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

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

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


\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 50.2%

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

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

Alternative 7: 80.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -1.95 \cdot 10^{+145} \lor \neg \left(x \cdot y \leq 1.35 \cdot 10^{+66}\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.95e+145) (not (<= (* x y) 1.35e+66)))
   (* 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.95e+145) || !((x * y) <= 1.35e+66)) {
		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.95d+145)) .or. (.not. ((x * y) <= 1.35d+66))) 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.95e+145) || !((x * y) <= 1.35e+66)) {
		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.95e+145) or not ((x * y) <= 1.35e+66):
		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.95e+145) || !(Float64(x * y) <= 1.35e+66))
		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.95e+145) || ~(((x * y) <= 1.35e+66)))
		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.95e+145], N[Not[LessEqual[N[(x * y), $MachinePrecision], 1.35e+66]], $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.95 \cdot 10^{+145} \lor \neg \left(x \cdot y \leq 1.35 \cdot 10^{+66}\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.9499999999999999e145 or 1.35e66 < (*.f64 x y)

    1. Initial program 93.3%

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

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

    if -1.9499999999999999e145 < (*.f64 x y) < 1.35e66

    1. Initial program 98.3%

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

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

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

Alternative 8: 85.2% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+63} \lor \neg \left(x \cdot y \leq 10^{+52}\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 y) -1e+63) (not (<= (* x y) 1e+52)))
   (+ (* 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 * y) <= -1e+63) || !((x * y) <= 1e+52)) {
		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 * y) <= (-1d+63)) .or. (.not. ((x * y) <= 1d+52))) 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 * y) <= -1e+63) || !((x * y) <= 1e+52)) {
		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 * y) <= -1e+63) or not ((x * y) <= 1e+52):
		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 ((Float64(x * y) <= -1e+63) || !(Float64(x * y) <= 1e+52))
		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 * y) <= -1e+63) || ~(((x * y) <= 1e+52)))
		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[N[(x * y), $MachinePrecision], -1e+63], N[Not[LessEqual[N[(x * y), $MachinePrecision], 1e+52]], $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 \cdot y \leq -1 \cdot 10^{+63} \lor \neg \left(x \cdot y \leq 10^{+52}\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 (*.f64 x y) < -1.00000000000000006e63 or 9.9999999999999999e51 < (*.f64 x y)

    1. Initial program 94.6%

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

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

    if -1.00000000000000006e63 < (*.f64 x y) < 9.9999999999999999e51

    1. Initial program 98.1%

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

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

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

Alternative 9: 84.4% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -5 \cdot 10^{-20}:\\
\;\;\;\;a \cdot b + x \cdot y\\

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

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


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

    1. Initial program 93.7%

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

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

    if -4.9999999999999999e-20 < (*.f64 a b) < 9.5000000000000003e-18

    1. Initial program 97.5%

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

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

    if 9.5000000000000003e-18 < (*.f64 a b)

    1. Initial program 98.5%

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

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

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

Alternative 10: 54.0% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -3.6 \cdot 10^{-19} \lor \neg \left(a \cdot b \leq 1.3 \cdot 10^{+50}\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.6000000000000001e-19 or 1.3000000000000001e50 < (*.f64 a b)

    1. Initial program 95.9%

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

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

    if -3.6000000000000001e-19 < (*.f64 a b) < 1.3000000000000001e50

    1. Initial program 97.7%

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

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

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

Alternative 11: 36.2% 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 96.8%

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

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

    \[\leadsto a \cdot b \]
  5. Add Preprocessing

Reproduce

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