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

Percentage Accurate: 97.7% → 98.8%
Time: 6.2s
Alternatives: 8
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 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.7% accurate, 1.0× speedup?

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

\\
\left(x \cdot y + z \cdot t\right) + a \cdot b
\end{array}

Alternative 1: 98.8% 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.2%

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

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

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

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

\[\begin{array}{l} \\ \begin{array}{l} t_1 := x \cdot y + a \cdot b\\ t_2 := z \cdot t + a \cdot b\\ \mathbf{if}\;a \cdot b \leq -3.2 \cdot 10^{+187}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;a \cdot b \leq -3.5 \cdot 10^{+71}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;a \cdot b \leq -54000000:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;a \cdot b \leq 2.7 \cdot 10^{-83}:\\ \;\;\;\;z \cdot t + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (+ (* x y) (* a b))) (t_2 (+ (* z t) (* a b))))
   (if (<= (* a b) -3.2e+187)
     t_2
     (if (<= (* a b) -3.5e+71)
       t_1
       (if (<= (* a b) -54000000.0)
         t_2
         (if (<= (* a b) 2.7e-83) (+ (* z t) (* x y)) t_1))))))
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (x * y) + (a * b);
	double t_2 = (z * t) + (a * b);
	double tmp;
	if ((a * b) <= -3.2e+187) {
		tmp = t_2;
	} else if ((a * b) <= -3.5e+71) {
		tmp = t_1;
	} else if ((a * b) <= -54000000.0) {
		tmp = t_2;
	} else if ((a * b) <= 2.7e-83) {
		tmp = (z * t) + (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) :: t_2
    real(8) :: tmp
    t_1 = (x * y) + (a * b)
    t_2 = (z * t) + (a * b)
    if ((a * b) <= (-3.2d+187)) then
        tmp = t_2
    else if ((a * b) <= (-3.5d+71)) then
        tmp = t_1
    else if ((a * b) <= (-54000000.0d0)) then
        tmp = t_2
    else if ((a * b) <= 2.7d-83) then
        tmp = (z * t) + (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 = (x * y) + (a * b);
	double t_2 = (z * t) + (a * b);
	double tmp;
	if ((a * b) <= -3.2e+187) {
		tmp = t_2;
	} else if ((a * b) <= -3.5e+71) {
		tmp = t_1;
	} else if ((a * b) <= -54000000.0) {
		tmp = t_2;
	} else if ((a * b) <= 2.7e-83) {
		tmp = (z * t) + (x * y);
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	t_1 = (x * y) + (a * b)
	t_2 = (z * t) + (a * b)
	tmp = 0
	if (a * b) <= -3.2e+187:
		tmp = t_2
	elif (a * b) <= -3.5e+71:
		tmp = t_1
	elif (a * b) <= -54000000.0:
		tmp = t_2
	elif (a * b) <= 2.7e-83:
		tmp = (z * t) + (x * y)
	else:
		tmp = t_1
	return tmp
function code(x, y, z, t, a, b)
	t_1 = Float64(Float64(x * y) + Float64(a * b))
	t_2 = Float64(Float64(z * t) + Float64(a * b))
	tmp = 0.0
	if (Float64(a * b) <= -3.2e+187)
		tmp = t_2;
	elseif (Float64(a * b) <= -3.5e+71)
		tmp = t_1;
	elseif (Float64(a * b) <= -54000000.0)
		tmp = t_2;
	elseif (Float64(a * b) <= 2.7e-83)
		tmp = Float64(Float64(z * t) + Float64(x * y));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	t_1 = (x * y) + (a * b);
	t_2 = (z * t) + (a * b);
	tmp = 0.0;
	if ((a * b) <= -3.2e+187)
		tmp = t_2;
	elseif ((a * b) <= -3.5e+71)
		tmp = t_1;
	elseif ((a * b) <= -54000000.0)
		tmp = t_2;
	elseif ((a * b) <= 2.7e-83)
		tmp = (z * t) + (x * y);
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(x * y), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(z * t), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(a * b), $MachinePrecision], -3.2e+187], t$95$2, If[LessEqual[N[(a * b), $MachinePrecision], -3.5e+71], t$95$1, If[LessEqual[N[(a * b), $MachinePrecision], -54000000.0], t$95$2, If[LessEqual[N[(a * b), $MachinePrecision], 2.7e-83], N[(N[(z * t), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := x \cdot y + a \cdot b\\
t_2 := z \cdot t + a \cdot b\\
\mathbf{if}\;a \cdot b \leq -3.2 \cdot 10^{+187}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;a \cdot b \leq -3.5 \cdot 10^{+71}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;a \cdot b \leq -54000000:\\
\;\;\;\;t\_2\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 a b) < -3.19999999999999993e187 or -3.4999999999999999e71 < (*.f64 a b) < -5.4e7

    1. Initial program 100.0%

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, \mathsf{fma}\left(a, b, z \cdot t\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 96.2%

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

    if -3.19999999999999993e187 < (*.f64 a b) < -3.4999999999999999e71 or 2.69999999999999991e-83 < (*.f64 a b)

    1. Initial program 98.0%

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

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

    if -5.4e7 < (*.f64 a b) < 2.69999999999999991e-83

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -3.2 \cdot 10^{+187}:\\ \;\;\;\;z \cdot t + a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -3.5 \cdot 10^{+71}:\\ \;\;\;\;x \cdot y + a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -54000000:\\ \;\;\;\;z \cdot t + a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 2.7 \cdot 10^{-83}:\\ \;\;\;\;z \cdot t + x \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot y + a \cdot b\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 53.9% accurate, 0.5× speedup?

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

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

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

\mathbf{elif}\;a \cdot b \leq 3700000:\\
\;\;\;\;x \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 a b) < -6.99999999999999974e69 or 3.7e6 < (*.f64 a b)

    1. Initial program 98.2%

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, \mathsf{fma}\left(a, b, z \cdot t\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in a around inf 70.8%

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

    if -6.99999999999999974e69 < (*.f64 a b) < -4.30000000000000026e-179

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

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

      \[\leadsto \color{blue}{z \cdot \left(t + \frac{x \cdot y}{z}\right)} \]
    5. Taylor expanded in t around inf 58.0%

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

    if -4.30000000000000026e-179 < (*.f64 a b) < 3.7e6

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

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

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

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

Alternative 4: 84.5% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -21000 \lor \neg \left(a \cdot b \leq 25000000000\right):\\
\;\;\;\;z \cdot t + a \cdot b\\

\mathbf{else}:\\
\;\;\;\;z \cdot t + x \cdot y\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 a b) < -21000 or 2.5e10 < (*.f64 a b)

    1. Initial program 98.4%

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, \mathsf{fma}\left(a, b, z \cdot t\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 83.8%

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

    if -21000 < (*.f64 a b) < 2.5e10

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

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

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

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

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

Alternative 5: 81.1% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -4.6 \cdot 10^{+127} \lor \neg \left(x \cdot y \leq 1.65 \cdot 10^{+160}\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot t + a \cdot b\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (if (or (<= (* x y) -4.6e+127) (not (<= (* x y) 1.65e+160)))
   (* x y)
   (+ (* z t) (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if (((x * y) <= -4.6e+127) || !((x * y) <= 1.65e+160)) {
		tmp = x * y;
	} else {
		tmp = (z * t) + (a * b);
	}
	return tmp;
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if (((x * y) <= (-4.6d+127)) .or. (.not. ((x * y) <= 1.65d+160))) then
        tmp = x * y
    else
        tmp = (z * t) + (a * b)
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if (((x * y) <= -4.6e+127) || !((x * y) <= 1.65e+160)) {
		tmp = x * y;
	} else {
		tmp = (z * t) + (a * b);
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if ((x * y) <= -4.6e+127) or not ((x * y) <= 1.65e+160):
		tmp = x * y
	else:
		tmp = (z * t) + (a * b)
	return tmp
function code(x, y, z, t, a, b)
	tmp = 0.0
	if ((Float64(x * y) <= -4.6e+127) || !(Float64(x * y) <= 1.65e+160))
		tmp = Float64(x * y);
	else
		tmp = Float64(Float64(z * t) + Float64(a * b));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	tmp = 0.0;
	if (((x * y) <= -4.6e+127) || ~(((x * y) <= 1.65e+160)))
		tmp = x * y;
	else
		tmp = (z * t) + (a * b);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -4.6e+127], N[Not[LessEqual[N[(x * y), $MachinePrecision], 1.65e+160]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(N[(z * t), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -4.6 \cdot 10^{+127} \lor \neg \left(x \cdot y \leq 1.65 \cdot 10^{+160}\right):\\
\;\;\;\;x \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x y) < -4.6000000000000003e127 or 1.6499999999999999e160 < (*.f64 x y)

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

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

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

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

    if -4.6000000000000003e127 < (*.f64 x y) < 1.6499999999999999e160

    1. Initial program 98.9%

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, \mathsf{fma}\left(a, b, z \cdot t\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around 0 82.6%

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

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

Alternative 6: 53.7% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -9.4 \cdot 10^{-7} \lor \neg \left(a \cdot b \leq 38000000\right):\\
\;\;\;\;a \cdot b\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 a b) < -9.4e-7 or 3.8e7 < (*.f64 a b)

    1. Initial program 98.4%

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, \mathsf{fma}\left(a, b, z \cdot t\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in a around inf 65.2%

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

    if -9.4e-7 < (*.f64 a b) < 3.8e7

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -9.4 \cdot 10^{-7} \lor \neg \left(a \cdot b \leq 38000000\right):\\ \;\;\;\;a \cdot b\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 97.7% accurate, 1.0× speedup?

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

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

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

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

Alternative 8: 36.2% accurate, 3.7× speedup?

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

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

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

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

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

      \[\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. Taylor expanded in a around inf 36.3%

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

Reproduce

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