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

Percentage Accurate: 97.9% → 98.5%
Time: 6.5s
Alternatives: 8
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 8 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.9% 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.5% 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}:\\ \;\;\;\;x \cdot y\\ \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 (* x y))))
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 = x * y;
	}
	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 = x * y;
	}
	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 = x * y
	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(x * y);
	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 = x * y;
	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[(x * y), $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}:\\
\;\;\;\;x \cdot y\\


\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 inf 56.3%

      \[\leadsto \color{blue}{x \cdot y} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 99.0% 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 96.5%

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

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

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

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

    \[\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: 55.0% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot b \leq -1.45 \cdot 10^{+119}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -4.05 \cdot 10^{-109}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 2.9 \cdot 10^{-304}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 3.4 \cdot 10^{-63}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 10^{+52}:\\ \;\;\;\;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.45e+119)
   (* a b)
   (if (<= (* a b) -4.05e-109)
     (* x y)
     (if (<= (* a b) 2.9e-304)
       (* z t)
       (if (<= (* a b) 3.4e-63)
         (* x y)
         (if (<= (* a b) 1e+52) (* z t) (* a b)))))))
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if ((a * b) <= -1.45e+119) {
		tmp = a * b;
	} else if ((a * b) <= -4.05e-109) {
		tmp = x * y;
	} else if ((a * b) <= 2.9e-304) {
		tmp = z * t;
	} else if ((a * b) <= 3.4e-63) {
		tmp = x * y;
	} else if ((a * b) <= 1e+52) {
		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.45d+119)) then
        tmp = a * b
    else if ((a * b) <= (-4.05d-109)) then
        tmp = x * y
    else if ((a * b) <= 2.9d-304) then
        tmp = z * t
    else if ((a * b) <= 3.4d-63) then
        tmp = x * y
    else if ((a * b) <= 1d+52) 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.45e+119) {
		tmp = a * b;
	} else if ((a * b) <= -4.05e-109) {
		tmp = x * y;
	} else if ((a * b) <= 2.9e-304) {
		tmp = z * t;
	} else if ((a * b) <= 3.4e-63) {
		tmp = x * y;
	} else if ((a * b) <= 1e+52) {
		tmp = z * t;
	} else {
		tmp = a * b;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if (a * b) <= -1.45e+119:
		tmp = a * b
	elif (a * b) <= -4.05e-109:
		tmp = x * y
	elif (a * b) <= 2.9e-304:
		tmp = z * t
	elif (a * b) <= 3.4e-63:
		tmp = x * y
	elif (a * b) <= 1e+52:
		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.45e+119)
		tmp = Float64(a * b);
	elseif (Float64(a * b) <= -4.05e-109)
		tmp = Float64(x * y);
	elseif (Float64(a * b) <= 2.9e-304)
		tmp = Float64(z * t);
	elseif (Float64(a * b) <= 3.4e-63)
		tmp = Float64(x * y);
	elseif (Float64(a * b) <= 1e+52)
		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.45e+119)
		tmp = a * b;
	elseif ((a * b) <= -4.05e-109)
		tmp = x * y;
	elseif ((a * b) <= 2.9e-304)
		tmp = z * t;
	elseif ((a * b) <= 3.4e-63)
		tmp = x * y;
	elseif ((a * b) <= 1e+52)
		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.45e+119], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -4.05e-109], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2.9e-304], N[(z * t), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 3.4e-63], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1e+52], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]]]]
\begin{array}{l}

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 a b) < -1.45000000000000004e119 or 9.9999999999999999e51 < (*.f64 a b)

    1. Initial program 94.7%

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

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

    if -1.45000000000000004e119 < (*.f64 a b) < -4.0500000000000001e-109 or 2.9e-304 < (*.f64 a b) < 3.39999999999999998e-63

    1. Initial program 97.4%

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

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

    if -4.0500000000000001e-109 < (*.f64 a b) < 2.9e-304 or 3.39999999999999998e-63 < (*.f64 a b) < 9.9999999999999999e51

    1. Initial program 97.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -1.45 \cdot 10^{+119}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -4.05 \cdot 10^{-109}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 2.9 \cdot 10^{-304}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 3.4 \cdot 10^{-63}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 10^{+52}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 83.4% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -4.5 \cdot 10^{+144} \lor \neg \left(x \cdot y \leq -6 \cdot 10^{+58}\right) \land \left(x \cdot y \leq -2.3 \cdot 10^{-29} \lor \neg \left(x \cdot y \leq 3.15 \cdot 10^{+130}\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) -4.5e+144)
         (and (not (<= (* x y) -6e+58))
              (or (<= (* x y) -2.3e-29) (not (<= (* x y) 3.15e+130)))))
   (+ (* 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) <= -4.5e+144) || (!((x * y) <= -6e+58) && (((x * y) <= -2.3e-29) || !((x * y) <= 3.15e+130)))) {
		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) <= (-4.5d+144)) .or. (.not. ((x * y) <= (-6d+58))) .and. ((x * y) <= (-2.3d-29)) .or. (.not. ((x * y) <= 3.15d+130))) 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) <= -4.5e+144) || (!((x * y) <= -6e+58) && (((x * y) <= -2.3e-29) || !((x * y) <= 3.15e+130)))) {
		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) <= -4.5e+144) or (not ((x * y) <= -6e+58) and (((x * y) <= -2.3e-29) or not ((x * y) <= 3.15e+130))):
		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) <= -4.5e+144) || (!(Float64(x * y) <= -6e+58) && ((Float64(x * y) <= -2.3e-29) || !(Float64(x * y) <= 3.15e+130))))
		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) <= -4.5e+144) || (~(((x * y) <= -6e+58)) && (((x * y) <= -2.3e-29) || ~(((x * y) <= 3.15e+130)))))
		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], -4.5e+144], And[N[Not[LessEqual[N[(x * y), $MachinePrecision], -6e+58]], $MachinePrecision], Or[LessEqual[N[(x * y), $MachinePrecision], -2.3e-29], N[Not[LessEqual[N[(x * y), $MachinePrecision], 3.15e+130]], $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 -4.5 \cdot 10^{+144} \lor \neg \left(x \cdot y \leq -6 \cdot 10^{+58}\right) \land \left(x \cdot y \leq -2.3 \cdot 10^{-29} \lor \neg \left(x \cdot y \leq 3.15 \cdot 10^{+130}\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) < -4.49999999999999967e144 or -6.0000000000000005e58 < (*.f64 x y) < -2.29999999999999991e-29 or 3.15e130 < (*.f64 x y)

    1. Initial program 91.7%

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

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

    if -4.49999999999999967e144 < (*.f64 x y) < -6.0000000000000005e58 or -2.29999999999999991e-29 < (*.f64 x y) < 3.15e130

    1. Initial program 99.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -4.5 \cdot 10^{+144} \lor \neg \left(x \cdot y \leq -6 \cdot 10^{+58}\right) \land \left(x \cdot y \leq -2.3 \cdot 10^{-29} \lor \neg \left(x \cdot y \leq 3.15 \cdot 10^{+130}\right)\right):\\ \;\;\;\;x \cdot y + a \cdot b\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 79.3% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -1.4 \cdot 10^{+145} \lor \neg \left(x \cdot y \leq -8.5 \cdot 10^{+56}\right) \land \left(x \cdot y \leq -3.65 \cdot 10^{+18} \lor \neg \left(x \cdot y \leq 6.3 \cdot 10^{+153}\right)\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.4e+145)
         (and (not (<= (* x y) -8.5e+56))
              (or (<= (* x y) -3.65e+18) (not (<= (* x y) 6.3e+153)))))
   (* 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.4e+145) || (!((x * y) <= -8.5e+56) && (((x * y) <= -3.65e+18) || !((x * y) <= 6.3e+153)))) {
		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.4d+145)) .or. (.not. ((x * y) <= (-8.5d+56))) .and. ((x * y) <= (-3.65d+18)) .or. (.not. ((x * y) <= 6.3d+153))) 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.4e+145) || (!((x * y) <= -8.5e+56) && (((x * y) <= -3.65e+18) || !((x * y) <= 6.3e+153)))) {
		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.4e+145) or (not ((x * y) <= -8.5e+56) and (((x * y) <= -3.65e+18) or not ((x * y) <= 6.3e+153))):
		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.4e+145) || (!(Float64(x * y) <= -8.5e+56) && ((Float64(x * y) <= -3.65e+18) || !(Float64(x * y) <= 6.3e+153))))
		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.4e+145) || (~(((x * y) <= -8.5e+56)) && (((x * y) <= -3.65e+18) || ~(((x * y) <= 6.3e+153)))))
		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.4e+145], And[N[Not[LessEqual[N[(x * y), $MachinePrecision], -8.5e+56]], $MachinePrecision], Or[LessEqual[N[(x * y), $MachinePrecision], -3.65e+18], N[Not[LessEqual[N[(x * y), $MachinePrecision], 6.3e+153]], $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.4 \cdot 10^{+145} \lor \neg \left(x \cdot y \leq -8.5 \cdot 10^{+56}\right) \land \left(x \cdot y \leq -3.65 \cdot 10^{+18} \lor \neg \left(x \cdot y \leq 6.3 \cdot 10^{+153}\right)\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.3999999999999999e145 or -8.4999999999999998e56 < (*.f64 x y) < -3.65e18 or 6.3000000000000001e153 < (*.f64 x y)

    1. Initial program 90.2%

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

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

    if -1.3999999999999999e145 < (*.f64 x y) < -8.4999999999999998e56 or -3.65e18 < (*.f64 x y) < 6.3000000000000001e153

    1. Initial program 99.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -1.4 \cdot 10^{+145} \lor \neg \left(x \cdot y \leq -8.5 \cdot 10^{+56}\right) \land \left(x \cdot y \leq -3.65 \cdot 10^{+18} \lor \neg \left(x \cdot y \leq 6.3 \cdot 10^{+153}\right)\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 83.8% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -2.05 \cdot 10^{-41}:\\ \;\;\;\;x \cdot y + z \cdot t\\ \mathbf{elif}\;x \cdot y \leq 5.1 \cdot 10^{-8} \lor \neg \left(x \cdot y \leq 1.75 \cdot 10^{+51}\right) \land x \cdot y \leq 1.72 \cdot 10^{+131}:\\ \;\;\;\;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) -2.05e-41)
   (+ (* x y) (* z t))
   (if (or (<= (* x y) 5.1e-8)
           (and (not (<= (* x y) 1.75e+51)) (<= (* x y) 1.72e+131)))
     (+ (* 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) <= -2.05e-41) {
		tmp = (x * y) + (z * t);
	} else if (((x * y) <= 5.1e-8) || (!((x * y) <= 1.75e+51) && ((x * y) <= 1.72e+131))) {
		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) <= (-2.05d-41)) then
        tmp = (x * y) + (z * t)
    else if (((x * y) <= 5.1d-8) .or. (.not. ((x * y) <= 1.75d+51)) .and. ((x * y) <= 1.72d+131)) 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) <= -2.05e-41) {
		tmp = (x * y) + (z * t);
	} else if (((x * y) <= 5.1e-8) || (!((x * y) <= 1.75e+51) && ((x * y) <= 1.72e+131))) {
		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) <= -2.05e-41:
		tmp = (x * y) + (z * t)
	elif ((x * y) <= 5.1e-8) or (not ((x * y) <= 1.75e+51) and ((x * y) <= 1.72e+131)):
		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) <= -2.05e-41)
		tmp = Float64(Float64(x * y) + Float64(z * t));
	elseif ((Float64(x * y) <= 5.1e-8) || (!(Float64(x * y) <= 1.75e+51) && (Float64(x * y) <= 1.72e+131)))
		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) <= -2.05e-41)
		tmp = (x * y) + (z * t);
	elseif (((x * y) <= 5.1e-8) || (~(((x * y) <= 1.75e+51)) && ((x * y) <= 1.72e+131)))
		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], -2.05e-41], N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[N[(x * y), $MachinePrecision], 5.1e-8], And[N[Not[LessEqual[N[(x * y), $MachinePrecision], 1.75e+51]], $MachinePrecision], LessEqual[N[(x * y), $MachinePrecision], 1.72e+131]]], 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 -2.05 \cdot 10^{-41}:\\
\;\;\;\;x \cdot y + z \cdot t\\

\mathbf{elif}\;x \cdot y \leq 5.1 \cdot 10^{-8} \lor \neg \left(x \cdot y \leq 1.75 \cdot 10^{+51}\right) \land x \cdot y \leq 1.72 \cdot 10^{+131}:\\
\;\;\;\;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) < -2.05000000000000007e-41

    1. Initial program 94.8%

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

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

    if -2.05000000000000007e-41 < (*.f64 x y) < 5.10000000000000001e-8 or 1.75e51 < (*.f64 x y) < 1.71999999999999994e131

    1. Initial program 99.2%

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

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

    if 5.10000000000000001e-8 < (*.f64 x y) < 1.75e51 or 1.71999999999999994e131 < (*.f64 x y)

    1. Initial program 91.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -2.05 \cdot 10^{-41}:\\ \;\;\;\;x \cdot y + z \cdot t\\ \mathbf{elif}\;x \cdot y \leq 5.1 \cdot 10^{-8} \lor \neg \left(x \cdot y \leq 1.75 \cdot 10^{+51}\right) \land x \cdot y \leq 1.72 \cdot 10^{+131}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot y + a \cdot b\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 48.9% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;t \leq -9 \cdot 10^{-13} \lor \neg \left(t \leq 1.25 \cdot 10^{+49}\right):\\
\;\;\;\;z \cdot t\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if t < -9e-13 or 1.2500000000000001e49 < t

    1. Initial program 93.5%

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

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

    if -9e-13 < t < 1.2500000000000001e49

    1. Initial program 99.2%

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

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

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

Alternative 8: 34.9% 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.5%

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

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

Reproduce

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