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

Percentage Accurate: 97.9% → 99.1%
Time: 7.9s
Alternatives: 10
Speedup: 1.0×

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 10 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.1% accurate, 0.1× speedup?

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

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

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

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

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

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

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

Alternative 2: 98.4% accurate, 0.1× speedup?

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

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

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

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

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

Alternative 3: 53.5% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot b \leq -8.6 \cdot 10^{+129}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -1.45 \cdot 10^{+87}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq -6.8 \cdot 10^{+45}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -7.8 \cdot 10^{-108}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq -3.4 \cdot 10^{-183}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 112000000000:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (if (<= (* a b) -8.6e+129)
   (* a b)
   (if (<= (* a b) -1.45e+87)
     (* x y)
     (if (<= (* a b) -6.8e+45)
       (* a b)
       (if (<= (* a b) -7.8e-108)
         (* z t)
         (if (<= (* a b) -3.4e-183)
           (* x y)
           (if (<= (* a b) 112000000000.0) (* z t) (* a b))))))))
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if ((a * b) <= -8.6e+129) {
		tmp = a * b;
	} else if ((a * b) <= -1.45e+87) {
		tmp = x * y;
	} else if ((a * b) <= -6.8e+45) {
		tmp = a * b;
	} else if ((a * b) <= -7.8e-108) {
		tmp = z * t;
	} else if ((a * b) <= -3.4e-183) {
		tmp = x * y;
	} else if ((a * b) <= 112000000000.0) {
		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) <= (-8.6d+129)) then
        tmp = a * b
    else if ((a * b) <= (-1.45d+87)) then
        tmp = x * y
    else if ((a * b) <= (-6.8d+45)) then
        tmp = a * b
    else if ((a * b) <= (-7.8d-108)) then
        tmp = z * t
    else if ((a * b) <= (-3.4d-183)) then
        tmp = x * y
    else if ((a * b) <= 112000000000.0d0) 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) <= -8.6e+129) {
		tmp = a * b;
	} else if ((a * b) <= -1.45e+87) {
		tmp = x * y;
	} else if ((a * b) <= -6.8e+45) {
		tmp = a * b;
	} else if ((a * b) <= -7.8e-108) {
		tmp = z * t;
	} else if ((a * b) <= -3.4e-183) {
		tmp = x * y;
	} else if ((a * b) <= 112000000000.0) {
		tmp = z * t;
	} else {
		tmp = a * b;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if (a * b) <= -8.6e+129:
		tmp = a * b
	elif (a * b) <= -1.45e+87:
		tmp = x * y
	elif (a * b) <= -6.8e+45:
		tmp = a * b
	elif (a * b) <= -7.8e-108:
		tmp = z * t
	elif (a * b) <= -3.4e-183:
		tmp = x * y
	elif (a * b) <= 112000000000.0:
		tmp = z * t
	else:
		tmp = a * b
	return tmp
function code(x, y, z, t, a, b)
	tmp = 0.0
	if (Float64(a * b) <= -8.6e+129)
		tmp = Float64(a * b);
	elseif (Float64(a * b) <= -1.45e+87)
		tmp = Float64(x * y);
	elseif (Float64(a * b) <= -6.8e+45)
		tmp = Float64(a * b);
	elseif (Float64(a * b) <= -7.8e-108)
		tmp = Float64(z * t);
	elseif (Float64(a * b) <= -3.4e-183)
		tmp = Float64(x * y);
	elseif (Float64(a * b) <= 112000000000.0)
		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) <= -8.6e+129)
		tmp = a * b;
	elseif ((a * b) <= -1.45e+87)
		tmp = x * y;
	elseif ((a * b) <= -6.8e+45)
		tmp = a * b;
	elseif ((a * b) <= -7.8e-108)
		tmp = z * t;
	elseif ((a * b) <= -3.4e-183)
		tmp = x * y;
	elseif ((a * b) <= 112000000000.0)
		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], -8.6e+129], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -1.45e+87], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -6.8e+45], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -7.8e-108], N[(z * t), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -3.4e-183], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 112000000000.0], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;a \cdot b \leq -6.8 \cdot 10^{+45}:\\
\;\;\;\;a \cdot b\\

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

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

\mathbf{elif}\;a \cdot b \leq 112000000000:\\
\;\;\;\;z \cdot t\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 a b) < -8.60000000000000042e129 or -1.4499999999999999e87 < (*.f64 a b) < -6.8e45 or 1.12e11 < (*.f64 a b)

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

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

    if -8.60000000000000042e129 < (*.f64 a b) < -1.4499999999999999e87 or -7.79999999999999989e-108 < (*.f64 a b) < -3.40000000000000014e-183

    1. Initial program 100.0%

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

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

    if -6.8e45 < (*.f64 a b) < -7.79999999999999989e-108 or -3.40000000000000014e-183 < (*.f64 a b) < 1.12e11

    1. Initial program 99.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -8.6 \cdot 10^{+129}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -1.45 \cdot 10^{+87}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq -6.8 \cdot 10^{+45}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -7.8 \cdot 10^{-108}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq -3.4 \cdot 10^{-183}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 112000000000:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 79.0% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -7.5 \cdot 10^{+287} \lor \neg \left(x \cdot y \leq -5.8 \cdot 10^{+140} \lor \neg \left(x \cdot y \leq -1.55 \cdot 10^{+122}\right) \land x \cdot y \leq 1.2 \cdot 10^{+219}\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) -7.5e+287)
         (not
          (or (<= (* x y) -5.8e+140)
              (and (not (<= (* x y) -1.55e+122)) (<= (* x y) 1.2e+219)))))
   (* 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) <= -7.5e+287) || !(((x * y) <= -5.8e+140) || (!((x * y) <= -1.55e+122) && ((x * y) <= 1.2e+219)))) {
		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) <= (-7.5d+287)) .or. (.not. ((x * y) <= (-5.8d+140)) .or. (.not. ((x * y) <= (-1.55d+122))) .and. ((x * y) <= 1.2d+219))) 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) <= -7.5e+287) || !(((x * y) <= -5.8e+140) || (!((x * y) <= -1.55e+122) && ((x * y) <= 1.2e+219)))) {
		tmp = x * y;
	} else {
		tmp = (a * b) + (z * t);
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if ((x * y) <= -7.5e+287) or not (((x * y) <= -5.8e+140) or (not ((x * y) <= -1.55e+122) and ((x * y) <= 1.2e+219))):
		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) <= -7.5e+287) || !((Float64(x * y) <= -5.8e+140) || (!(Float64(x * y) <= -1.55e+122) && (Float64(x * y) <= 1.2e+219))))
		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) <= -7.5e+287) || ~((((x * y) <= -5.8e+140) || (~(((x * y) <= -1.55e+122)) && ((x * y) <= 1.2e+219)))))
		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], -7.5e+287], N[Not[Or[LessEqual[N[(x * y), $MachinePrecision], -5.8e+140], And[N[Not[LessEqual[N[(x * y), $MachinePrecision], -1.55e+122]], $MachinePrecision], LessEqual[N[(x * y), $MachinePrecision], 1.2e+219]]]], $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 -7.5 \cdot 10^{+287} \lor \neg \left(x \cdot y \leq -5.8 \cdot 10^{+140} \lor \neg \left(x \cdot y \leq -1.55 \cdot 10^{+122}\right) \land x \cdot y \leq 1.2 \cdot 10^{+219}\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) < -7.4999999999999994e287 or -5.7999999999999998e140 < (*.f64 x y) < -1.54999999999999999e122 or 1.2e219 < (*.f64 x y)

    1. Initial program 90.7%

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

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

    if -7.4999999999999994e287 < (*.f64 x y) < -5.7999999999999998e140 or -1.54999999999999999e122 < (*.f64 x y) < 1.2e219

    1. Initial program 99.5%

      \[\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} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification85.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -7.5 \cdot 10^{+287} \lor \neg \left(x \cdot y \leq -5.8 \cdot 10^{+140} \lor \neg \left(x \cdot y \leq -1.55 \cdot 10^{+122}\right) \land x \cdot y \leq 1.2 \cdot 10^{+219}\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 85.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot b \leq -1 \cdot 10^{+56}:\\ \;\;\;\;b \cdot \left(a + x \cdot \frac{y}{b}\right)\\ \mathbf{elif}\;a \cdot b \leq 2 \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) -1e+56)
   (* b (+ a (* x (/ y b))))
   (if (<= (* a b) 2e+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) <= -1e+56) {
		tmp = b * (a + (x * (y / b)));
	} else if ((a * b) <= 2e+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) <= (-1d+56)) then
        tmp = b * (a + (x * (y / b)))
    else if ((a * b) <= 2d+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) <= -1e+56) {
		tmp = b * (a + (x * (y / b)));
	} else if ((a * b) <= 2e+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) <= -1e+56:
		tmp = b * (a + (x * (y / b)))
	elif (a * b) <= 2e+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) <= -1e+56)
		tmp = Float64(b * Float64(a + Float64(x * Float64(y / b))));
	elseif (Float64(a * b) <= 2e+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) <= -1e+56)
		tmp = b * (a + (x * (y / b)));
	elseif ((a * b) <= 2e+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], -1e+56], N[(b * N[(a + N[(x * N[(y / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2e+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 -1 \cdot 10^{+56}:\\
\;\;\;\;b \cdot \left(a + x \cdot \frac{y}{b}\right)\\

\mathbf{elif}\;a \cdot b \leq 2 \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) < -1.00000000000000009e56

    1. Initial program 94.8%

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

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

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

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

      \[\leadsto \color{blue}{b \cdot \left(a + x \cdot \frac{y}{b}\right)} \]

    if -1.00000000000000009e56 < (*.f64 a b) < 2e18

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

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

    if 2e18 < (*.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 92.5%

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

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

Alternative 6: 85.3% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot b \leq -5.8 \cdot 10^{+51}:\\ \;\;\;\;a \cdot b + x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 2.1 \cdot 10^{+19}:\\ \;\;\;\;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) -5.8e+51)
   (+ (* a b) (* x y))
   (if (<= (* a b) 2.1e+19) (+ (* 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) <= -5.8e+51) {
		tmp = (a * b) + (x * y);
	} else if ((a * b) <= 2.1e+19) {
		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) <= (-5.8d+51)) then
        tmp = (a * b) + (x * y)
    else if ((a * b) <= 2.1d+19) 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) <= -5.8e+51) {
		tmp = (a * b) + (x * y);
	} else if ((a * b) <= 2.1e+19) {
		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) <= -5.8e+51:
		tmp = (a * b) + (x * y)
	elif (a * b) <= 2.1e+19:
		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) <= -5.8e+51)
		tmp = Float64(Float64(a * b) + Float64(x * y));
	elseif (Float64(a * b) <= 2.1e+19)
		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) <= -5.8e+51)
		tmp = (a * b) + (x * y);
	elseif ((a * b) <= 2.1e+19)
		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], -5.8e+51], N[(N[(a * b), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2.1e+19], 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.8 \cdot 10^{+51}:\\
\;\;\;\;a \cdot b + x \cdot y\\

\mathbf{elif}\;a \cdot b \leq 2.1 \cdot 10^{+19}:\\
\;\;\;\;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) < -5.7999999999999997e51

    1. Initial program 94.8%

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

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

    if -5.7999999999999997e51 < (*.f64 a b) < 2.1e19

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

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

    if 2.1e19 < (*.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 92.5%

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

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

Alternative 7: 82.4% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -1650000:\\
\;\;\;\;a \cdot b + x \cdot y\\

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

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


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

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

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

    if -1.65e6 < (*.f64 x y) < 1.14999999999999998e220

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

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

    if 1.14999999999999998e220 < (*.f64 x y)

    1. Initial program 81.8%

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

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

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

Alternative 8: 54.3% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -6.8 \cdot 10^{+51} \lor \neg \left(a \cdot b \leq 74000000000\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) < -6.79999999999999969e51 or 7.4e10 < (*.f64 a b)

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

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

    if -6.79999999999999969e51 < (*.f64 a b) < 7.4e10

    1. Initial program 99.2%

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

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

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

Alternative 9: 97.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ a \cdot b + \left(x \cdot y + z \cdot t\right) \end{array} \]
(FPCore (x y z t a b) :precision binary64 (+ (* a b) (+ (* x y) (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
	return (a * b) + ((x * y) + (z * t));
}
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) + ((x * y) + (z * t))
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	return (a * b) + ((x * y) + (z * t));
}
def code(x, y, z, t, a, b):
	return (a * b) + ((x * y) + (z * t))
function code(x, y, z, t, a, b)
	return Float64(Float64(a * b) + Float64(Float64(x * y) + Float64(z * t)))
end
function tmp = code(x, y, z, t, a, b)
	tmp = (a * b) + ((x * y) + (z * t));
end
code[x_, y_, z_, t_, a_, b_] := N[(N[(a * b), $MachinePrecision] + N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

    \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
  2. Add Preprocessing
  3. Final simplification98.0%

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

Alternative 10: 34.7% accurate, 3.7× speedup?

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

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

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

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

Reproduce

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