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

Percentage Accurate: 97.9% → 99.3%
Time: 7.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: 99.3% 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}:\\ \;\;\;\;y \cdot \left(x + a \cdot \frac{b}{y}\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 (* y (+ x (* a (/ b y)))))))
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 = y * (x + (a * (b / y)));
	}
	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 = y * (x + (a * (b / y)));
	}
	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 = y * (x + (a * (b / y)))
	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(y * Float64(x + Float64(a * Float64(b / y))));
	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 = y * (x + (a * (b / y)));
	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[(y * N[(x + N[(a * N[(b / y), $MachinePrecision]), $MachinePrecision]), $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}:\\
\;\;\;\;y \cdot \left(x + a \cdot \frac{b}{y}\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 0 44.4%

      \[\leadsto \color{blue}{a \cdot b + x \cdot y} \]
    4. Taylor expanded in y around inf 77.8%

      \[\leadsto \color{blue}{y \cdot \left(x + \frac{a \cdot b}{y}\right)} \]
    5. Step-by-step derivation
      1. associate-*r/100.0%

        \[\leadsto y \cdot \left(x + \color{blue}{a \cdot \frac{b}{y}}\right) \]
    6. Simplified100.0%

      \[\leadsto \color{blue}{y \cdot \left(x + a \cdot \frac{b}{y}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification100.0%

    \[\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}:\\ \;\;\;\;y \cdot \left(x + a \cdot \frac{b}{y}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 99.0% accurate, 0.1× speedup?

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

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

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

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

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

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

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

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

Alternative 3: 77.6% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -3.3 \cdot 10^{+290} \lor \neg \left(x \cdot y \leq -3 \cdot 10^{+53}\right) \land \left(x \cdot y \leq -39000000 \lor \neg \left(x \cdot y \leq 7 \cdot 10^{+207}\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) -3.3e+290)
         (and (not (<= (* x y) -3e+53))
              (or (<= (* x y) -39000000.0) (not (<= (* x y) 7e+207)))))
   (* x y)
   (+ (* a b) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if (((x * y) <= -3.3e+290) || (!((x * y) <= -3e+53) && (((x * y) <= -39000000.0) || !((x * y) <= 7e+207)))) {
		tmp = x * y;
	} else {
		tmp = (a * b) + (z * t);
	}
	return tmp;
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if (((x * y) <= (-3.3d+290)) .or. (.not. ((x * y) <= (-3d+53))) .and. ((x * y) <= (-39000000.0d0)) .or. (.not. ((x * y) <= 7d+207))) then
        tmp = x * y
    else
        tmp = (a * b) + (z * t)
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if (((x * y) <= -3.3e+290) || (!((x * y) <= -3e+53) && (((x * y) <= -39000000.0) || !((x * y) <= 7e+207)))) {
		tmp = x * y;
	} else {
		tmp = (a * b) + (z * t);
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if ((x * y) <= -3.3e+290) or (not ((x * y) <= -3e+53) and (((x * y) <= -39000000.0) or not ((x * y) <= 7e+207))):
		tmp = x * y
	else:
		tmp = (a * b) + (z * t)
	return tmp
function code(x, y, z, t, a, b)
	tmp = 0.0
	if ((Float64(x * y) <= -3.3e+290) || (!(Float64(x * y) <= -3e+53) && ((Float64(x * y) <= -39000000.0) || !(Float64(x * y) <= 7e+207))))
		tmp = Float64(x * y);
	else
		tmp = Float64(Float64(a * b) + Float64(z * t));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	tmp = 0.0;
	if (((x * y) <= -3.3e+290) || (~(((x * y) <= -3e+53)) && (((x * y) <= -39000000.0) || ~(((x * y) <= 7e+207)))))
		tmp = x * y;
	else
		tmp = (a * b) + (z * t);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -3.3e+290], And[N[Not[LessEqual[N[(x * y), $MachinePrecision], -3e+53]], $MachinePrecision], Or[LessEqual[N[(x * y), $MachinePrecision], -39000000.0], N[Not[LessEqual[N[(x * y), $MachinePrecision], 7e+207]], $MachinePrecision]]]], N[(x * y), $MachinePrecision], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -3.3 \cdot 10^{+290} \lor \neg \left(x \cdot y \leq -3 \cdot 10^{+53}\right) \land \left(x \cdot y \leq -39000000 \lor \neg \left(x \cdot y \leq 7 \cdot 10^{+207}\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) < -3.2999999999999999e290 or -2.99999999999999998e53 < (*.f64 x y) < -3.9e7 or 7.00000000000000056e207 < (*.f64 x y)

    1. Initial program 88.7%

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

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

    if -3.2999999999999999e290 < (*.f64 x y) < -2.99999999999999998e53 or -3.9e7 < (*.f64 x y) < 7.00000000000000056e207

    1. Initial program 98.9%

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

      \[\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 -3.3 \cdot 10^{+290} \lor \neg \left(x \cdot y \leq -3 \cdot 10^{+53}\right) \land \left(x \cdot y \leq -39000000 \lor \neg \left(x \cdot y \leq 7 \cdot 10^{+207}\right)\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 84.0% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -8.2 \cdot 10^{-13} \lor \neg \left(x \cdot y \leq 5.8 \cdot 10^{+61}\right) \land \left(x \cdot y \leq 2.4 \cdot 10^{+104} \lor \neg \left(x \cdot y \leq 4 \cdot 10^{+170}\right)\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) -8.2e-13)
         (and (not (<= (* x y) 5.8e+61))
              (or (<= (* x y) 2.4e+104) (not (<= (* x y) 4e+170)))))
   (+ (* 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) <= -8.2e-13) || (!((x * y) <= 5.8e+61) && (((x * y) <= 2.4e+104) || !((x * y) <= 4e+170)))) {
		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) <= (-8.2d-13)) .or. (.not. ((x * y) <= 5.8d+61)) .and. ((x * y) <= 2.4d+104) .or. (.not. ((x * y) <= 4d+170))) 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) <= -8.2e-13) || (!((x * y) <= 5.8e+61) && (((x * y) <= 2.4e+104) || !((x * y) <= 4e+170)))) {
		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) <= -8.2e-13) or (not ((x * y) <= 5.8e+61) and (((x * y) <= 2.4e+104) or not ((x * y) <= 4e+170))):
		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) <= -8.2e-13) || (!(Float64(x * y) <= 5.8e+61) && ((Float64(x * y) <= 2.4e+104) || !(Float64(x * y) <= 4e+170))))
		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) <= -8.2e-13) || (~(((x * y) <= 5.8e+61)) && (((x * y) <= 2.4e+104) || ~(((x * y) <= 4e+170)))))
		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], -8.2e-13], And[N[Not[LessEqual[N[(x * y), $MachinePrecision], 5.8e+61]], $MachinePrecision], Or[LessEqual[N[(x * y), $MachinePrecision], 2.4e+104], N[Not[LessEqual[N[(x * y), $MachinePrecision], 4e+170]], $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 -8.2 \cdot 10^{-13} \lor \neg \left(x \cdot y \leq 5.8 \cdot 10^{+61}\right) \land \left(x \cdot y \leq 2.4 \cdot 10^{+104} \lor \neg \left(x \cdot y \leq 4 \cdot 10^{+170}\right)\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) < -8.2000000000000004e-13 or 5.8000000000000001e61 < (*.f64 x y) < 2.4e104 or 4.00000000000000014e170 < (*.f64 x y)

    1. Initial program 93.1%

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

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

    if -8.2000000000000004e-13 < (*.f64 x y) < 5.8000000000000001e61 or 2.4e104 < (*.f64 x y) < 4.00000000000000014e170

    1. Initial program 99.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -8.2 \cdot 10^{-13} \lor \neg \left(x \cdot y \leq 5.8 \cdot 10^{+61}\right) \land \left(x \cdot y \leq 2.4 \cdot 10^{+104} \lor \neg \left(x \cdot y \leq 4 \cdot 10^{+170}\right)\right):\\ \;\;\;\;a \cdot b + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 53.0% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot b \leq -2 \cdot 10^{+237} \lor \neg \left(a \cdot b \leq -2.9 \cdot 10^{+227}\right) \land \left(a \cdot b \leq -5.8 \cdot 10^{-28} \lor \neg \left(a \cdot b \leq 4.4 \cdot 10^{+22}\right)\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) -2e+237)
         (and (not (<= (* a b) -2.9e+227))
              (or (<= (* a b) -5.8e-28) (not (<= (* a b) 4.4e+22)))))
   (* a b)
   (* z t)))
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if (((a * b) <= -2e+237) || (!((a * b) <= -2.9e+227) && (((a * b) <= -5.8e-28) || !((a * b) <= 4.4e+22)))) {
		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) <= (-2d+237)) .or. (.not. ((a * b) <= (-2.9d+227))) .and. ((a * b) <= (-5.8d-28)) .or. (.not. ((a * b) <= 4.4d+22))) 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) <= -2e+237) || (!((a * b) <= -2.9e+227) && (((a * b) <= -5.8e-28) || !((a * b) <= 4.4e+22)))) {
		tmp = a * b;
	} else {
		tmp = z * t;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if ((a * b) <= -2e+237) or (not ((a * b) <= -2.9e+227) and (((a * b) <= -5.8e-28) or not ((a * b) <= 4.4e+22))):
		tmp = a * b
	else:
		tmp = z * t
	return tmp
function code(x, y, z, t, a, b)
	tmp = 0.0
	if ((Float64(a * b) <= -2e+237) || (!(Float64(a * b) <= -2.9e+227) && ((Float64(a * b) <= -5.8e-28) || !(Float64(a * b) <= 4.4e+22))))
		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) <= -2e+237) || (~(((a * b) <= -2.9e+227)) && (((a * b) <= -5.8e-28) || ~(((a * b) <= 4.4e+22)))))
		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], -2e+237], And[N[Not[LessEqual[N[(a * b), $MachinePrecision], -2.9e+227]], $MachinePrecision], Or[LessEqual[N[(a * b), $MachinePrecision], -5.8e-28], N[Not[LessEqual[N[(a * b), $MachinePrecision], 4.4e+22]], $MachinePrecision]]]], N[(a * b), $MachinePrecision], N[(z * t), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -2 \cdot 10^{+237} \lor \neg \left(a \cdot b \leq -2.9 \cdot 10^{+227}\right) \land \left(a \cdot b \leq -5.8 \cdot 10^{-28} \lor \neg \left(a \cdot b \leq 4.4 \cdot 10^{+22}\right)\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) < -1.99999999999999988e237 or -2.8999999999999998e227 < (*.f64 a b) < -5.80000000000000026e-28 or 4.4e22 < (*.f64 a b)

    1. Initial program 92.8%

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

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

    if -1.99999999999999988e237 < (*.f64 a b) < -2.8999999999999998e227 or -5.80000000000000026e-28 < (*.f64 a b) < 4.4e22

    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 52.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -2 \cdot 10^{+237} \lor \neg \left(a \cdot b \leq -2.9 \cdot 10^{+227}\right) \land \left(a \cdot b \leq -5.8 \cdot 10^{-28} \lor \neg \left(a \cdot b \leq 4.4 \cdot 10^{+22}\right)\right):\\ \;\;\;\;a \cdot b\\ \mathbf{else}:\\ \;\;\;\;z \cdot t\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 52.1% accurate, 0.4× speedup?

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

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

\mathbf{elif}\;x \cdot y \leq -2.35 \cdot 10^{+57}:\\
\;\;\;\;a \cdot b\\

\mathbf{elif}\;x \cdot y \leq -4.1 \cdot 10^{-8} \lor \neg \left(x \cdot y \leq 1.6 \cdot 10^{+171}\right):\\
\;\;\;\;x \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 x y) < -3.70000000000000001e169 or -2.3500000000000001e57 < (*.f64 x y) < -4.10000000000000032e-8 or 1.60000000000000006e171 < (*.f64 x y)

    1. Initial program 90.1%

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

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

    if -3.70000000000000001e169 < (*.f64 x y) < -2.3500000000000001e57

    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 inf 46.2%

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

    if -4.10000000000000032e-8 < (*.f64 x y) < 1.60000000000000006e171

    1. Initial program 99.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -3.7 \cdot 10^{+169}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \cdot y \leq -2.35 \cdot 10^{+57}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;x \cdot y \leq -4.1 \cdot 10^{-8} \lor \neg \left(x \cdot y \leq 1.6 \cdot 10^{+171}\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot t\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 84.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := a \cdot b + z \cdot t\\ \mathbf{if}\;a \cdot b \leq -3.5 \cdot 10^{-26}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{+22}:\\ \;\;\;\;x \cdot y + z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 10^{+131}:\\ \;\;\;\;a \cdot b + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (+ (* a b) (* z t))))
   (if (<= (* a b) -3.5e-26)
     t_1
     (if (<= (* a b) 2e+22)
       (+ (* x y) (* z t))
       (if (<= (* a b) 1e+131) (+ (* a b) (* x y)) t_1)))))
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (a * b) + (z * t);
	double tmp;
	if ((a * b) <= -3.5e-26) {
		tmp = t_1;
	} else if ((a * b) <= 2e+22) {
		tmp = (x * y) + (z * t);
	} else if ((a * b) <= 1e+131) {
		tmp = (a * b) + (x * y);
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: t_1
    real(8) :: tmp
    t_1 = (a * b) + (z * t)
    if ((a * b) <= (-3.5d-26)) then
        tmp = t_1
    else if ((a * b) <= 2d+22) then
        tmp = (x * y) + (z * t)
    else if ((a * b) <= 1d+131) then
        tmp = (a * b) + (x * y)
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (a * b) + (z * t);
	double tmp;
	if ((a * b) <= -3.5e-26) {
		tmp = t_1;
	} else if ((a * b) <= 2e+22) {
		tmp = (x * y) + (z * t);
	} else if ((a * b) <= 1e+131) {
		tmp = (a * b) + (x * y);
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	t_1 = (a * b) + (z * t)
	tmp = 0
	if (a * b) <= -3.5e-26:
		tmp = t_1
	elif (a * b) <= 2e+22:
		tmp = (x * y) + (z * t)
	elif (a * b) <= 1e+131:
		tmp = (a * b) + (x * y)
	else:
		tmp = t_1
	return tmp
function code(x, y, z, t, a, b)
	t_1 = Float64(Float64(a * b) + Float64(z * t))
	tmp = 0.0
	if (Float64(a * b) <= -3.5e-26)
		tmp = t_1;
	elseif (Float64(a * b) <= 2e+22)
		tmp = Float64(Float64(x * y) + Float64(z * t));
	elseif (Float64(a * b) <= 1e+131)
		tmp = Float64(Float64(a * b) + Float64(x * y));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	t_1 = (a * b) + (z * t);
	tmp = 0.0;
	if ((a * b) <= -3.5e-26)
		tmp = t_1;
	elseif ((a * b) <= 2e+22)
		tmp = (x * y) + (z * t);
	elseif ((a * b) <= 1e+131)
		tmp = (a * b) + (x * y);
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(a * b), $MachinePrecision], -3.5e-26], t$95$1, If[LessEqual[N[(a * b), $MachinePrecision], 2e+22], N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1e+131], N[(N[(a * b), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}

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

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

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

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 a b) < -3.49999999999999985e-26 or 9.9999999999999991e130 < (*.f64 a b)

    1. Initial program 91.2%

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

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

    if -3.49999999999999985e-26 < (*.f64 a b) < 2e22

    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 93.6%

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

    if 2e22 < (*.f64 a b) < 9.9999999999999991e130

    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 0 81.2%

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

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

Alternative 8: 35.4% accurate, 3.7× speedup?

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

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

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

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

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

Reproduce

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