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

Percentage Accurate: 98.0% → 99.0%
Time: 8.7s
Alternatives: 9
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 9 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 98.0% 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.0% accurate, 0.1× speedup?

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, \mathsf{fma}\left(a, b, 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 99.6%

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

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

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

Alternative 3: 51.9% accurate, 0.4× speedup?

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 x y) < -2.65e160 or 1.5200000000000001e162 < (*.f64 x y)

    1. Initial program 98.8%

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

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

    if -2.65e160 < (*.f64 x y) < -2.4000000000000002e50 or 5.8999999999999999e-46 < (*.f64 x y) < 1.5200000000000001e162

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

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

    if -2.4000000000000002e50 < (*.f64 x y) < 5.8999999999999999e-46

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -2.65 \cdot 10^{+160}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \cdot y \leq -2.4 \cdot 10^{+50}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;x \cdot y \leq 5.9 \cdot 10^{-46}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;x \cdot y \leq 1.52 \cdot 10^{+162}:\\ \;\;\;\;a \cdot b\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 83.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -4.6 \cdot 10^{+98} \lor \neg \left(x \cdot y \leq 2.4 \cdot 10^{-55}\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) -4.6e+98) (not (<= (* x y) 2.4e-55)))
   (+ (* 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) <= -4.6e+98) || !((x * y) <= 2.4e-55)) {
		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) <= (-4.6d+98)) .or. (.not. ((x * y) <= 2.4d-55))) 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) <= -4.6e+98) || !((x * y) <= 2.4e-55)) {
		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) <= -4.6e+98) or not ((x * y) <= 2.4e-55):
		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) <= -4.6e+98) || !(Float64(x * y) <= 2.4e-55))
		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) <= -4.6e+98) || ~(((x * y) <= 2.4e-55)))
		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], -4.6e+98], N[Not[LessEqual[N[(x * y), $MachinePrecision], 2.4e-55]], $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 -4.6 \cdot 10^{+98} \lor \neg \left(x \cdot y \leq 2.4 \cdot 10^{-55}\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) < -4.60000000000000026e98 or 2.39999999999999991e-55 < (*.f64 x y)

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

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

    if -4.60000000000000026e98 < (*.f64 x y) < 2.39999999999999991e-55

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

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

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

Alternative 5: 80.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -7.7 \cdot 10^{+164} \lor \neg \left(x \cdot y \leq 2.2 \cdot 10^{+162}\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.7e+164) (not (<= (* x y) 2.2e+162)))
   (* 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.7e+164) || !((x * y) <= 2.2e+162)) {
		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.7d+164)) .or. (.not. ((x * y) <= 2.2d+162))) 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.7e+164) || !((x * y) <= 2.2e+162)) {
		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.7e+164) or not ((x * y) <= 2.2e+162):
		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.7e+164) || !(Float64(x * y) <= 2.2e+162))
		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.7e+164) || ~(((x * y) <= 2.2e+162)))
		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.7e+164], N[Not[LessEqual[N[(x * y), $MachinePrecision], 2.2e+162]], $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.7 \cdot 10^{+164} \lor \neg \left(x \cdot y \leq 2.2 \cdot 10^{+162}\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.7000000000000001e164 or 2.2000000000000002e162 < (*.f64 x y)

    1. Initial program 98.8%

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

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

    if -7.7000000000000001e164 < (*.f64 x y) < 2.2000000000000002e162

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

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

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

Alternative 6: 83.8% accurate, 0.5× speedup?

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

\mathbf{elif}\;a \cdot b \leq 6400000000000:\\
\;\;\;\;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.75000000000000009e162

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

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

    if -1.75000000000000009e162 < (*.f64 a b) < 6.4e12

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

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

    if 6.4e12 < (*.f64 a b)

    1. Initial program 98.4%

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

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

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

Alternative 7: 51.5% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1.4 \cdot 10^{+162} \lor \neg \left(a \cdot b \leq 1.4 \cdot 10^{+202}\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.39999999999999995e162 or 1.40000000000000008e202 < (*.f64 a b)

    1. Initial program 98.2%

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

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

    if -1.39999999999999995e162 < (*.f64 a b) < 1.40000000000000008e202

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

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

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

Alternative 8: 98.0% 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 99.6%

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

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

Alternative 9: 35.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 99.6%

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

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

Reproduce

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