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

Percentage Accurate: 98.0% → 99.1%
Time: 6.8s
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: 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.1% accurate, 0.1× speedup?

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

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

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

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

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

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

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

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

Alternative 2: 98.4% accurate, 0.1× speedup?

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

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

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

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

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

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

Alternative 3: 98.3% accurate, 0.1× speedup?

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

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

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

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

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

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

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

Alternative 4: 54.5% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot b \leq -7.6 \cdot 10^{+85}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -2.9 \cdot 10^{-196}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 1.2 \cdot 10^{-287}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 2.25 \cdot 10^{-206}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 1.9 \cdot 10^{-138}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 2.5 \cdot 10^{-116}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 1.16 \cdot 10^{+85}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (if (<= (* a b) -7.6e+85)
   (* a b)
   (if (<= (* a b) -2.9e-196)
     (* x y)
     (if (<= (* a b) 1.2e-287)
       (* z t)
       (if (<= (* a b) 2.25e-206)
         (* x y)
         (if (<= (* a b) 1.9e-138)
           (* z t)
           (if (<= (* a b) 2.5e-116)
             (* x y)
             (if (<= (* a b) 1.16e+85) (* z t) (* a b)))))))))
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if ((a * b) <= -7.6e+85) {
		tmp = a * b;
	} else if ((a * b) <= -2.9e-196) {
		tmp = x * y;
	} else if ((a * b) <= 1.2e-287) {
		tmp = z * t;
	} else if ((a * b) <= 2.25e-206) {
		tmp = x * y;
	} else if ((a * b) <= 1.9e-138) {
		tmp = z * t;
	} else if ((a * b) <= 2.5e-116) {
		tmp = x * y;
	} else if ((a * b) <= 1.16e+85) {
		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) <= (-7.6d+85)) then
        tmp = a * b
    else if ((a * b) <= (-2.9d-196)) then
        tmp = x * y
    else if ((a * b) <= 1.2d-287) then
        tmp = z * t
    else if ((a * b) <= 2.25d-206) then
        tmp = x * y
    else if ((a * b) <= 1.9d-138) then
        tmp = z * t
    else if ((a * b) <= 2.5d-116) then
        tmp = x * y
    else if ((a * b) <= 1.16d+85) 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) <= -7.6e+85) {
		tmp = a * b;
	} else if ((a * b) <= -2.9e-196) {
		tmp = x * y;
	} else if ((a * b) <= 1.2e-287) {
		tmp = z * t;
	} else if ((a * b) <= 2.25e-206) {
		tmp = x * y;
	} else if ((a * b) <= 1.9e-138) {
		tmp = z * t;
	} else if ((a * b) <= 2.5e-116) {
		tmp = x * y;
	} else if ((a * b) <= 1.16e+85) {
		tmp = z * t;
	} else {
		tmp = a * b;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if (a * b) <= -7.6e+85:
		tmp = a * b
	elif (a * b) <= -2.9e-196:
		tmp = x * y
	elif (a * b) <= 1.2e-287:
		tmp = z * t
	elif (a * b) <= 2.25e-206:
		tmp = x * y
	elif (a * b) <= 1.9e-138:
		tmp = z * t
	elif (a * b) <= 2.5e-116:
		tmp = x * y
	elif (a * b) <= 1.16e+85:
		tmp = z * t
	else:
		tmp = a * b
	return tmp
function code(x, y, z, t, a, b)
	tmp = 0.0
	if (Float64(a * b) <= -7.6e+85)
		tmp = Float64(a * b);
	elseif (Float64(a * b) <= -2.9e-196)
		tmp = Float64(x * y);
	elseif (Float64(a * b) <= 1.2e-287)
		tmp = Float64(z * t);
	elseif (Float64(a * b) <= 2.25e-206)
		tmp = Float64(x * y);
	elseif (Float64(a * b) <= 1.9e-138)
		tmp = Float64(z * t);
	elseif (Float64(a * b) <= 2.5e-116)
		tmp = Float64(x * y);
	elseif (Float64(a * b) <= 1.16e+85)
		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) <= -7.6e+85)
		tmp = a * b;
	elseif ((a * b) <= -2.9e-196)
		tmp = x * y;
	elseif ((a * b) <= 1.2e-287)
		tmp = z * t;
	elseif ((a * b) <= 2.25e-206)
		tmp = x * y;
	elseif ((a * b) <= 1.9e-138)
		tmp = z * t;
	elseif ((a * b) <= 2.5e-116)
		tmp = x * y;
	elseif ((a * b) <= 1.16e+85)
		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], -7.6e+85], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -2.9e-196], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1.2e-287], N[(z * t), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2.25e-206], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1.9e-138], N[(z * t), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2.5e-116], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1.16e+85], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]]]]]]
\begin{array}{l}

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

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

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 a b) < -7.59999999999999984e85 or 1.15999999999999995e85 < (*.f64 a b)

    1. Initial program 96.7%

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

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

    if -7.59999999999999984e85 < (*.f64 a b) < -2.89999999999999987e-196 or 1.2e-287 < (*.f64 a b) < 2.2499999999999999e-206 or 1.9000000000000001e-138 < (*.f64 a b) < 2.5000000000000001e-116

    1. Initial program 98.4%

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

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

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

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

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

    if -2.89999999999999987e-196 < (*.f64 a b) < 1.2e-287 or 2.2499999999999999e-206 < (*.f64 a b) < 1.9000000000000001e-138 or 2.5000000000000001e-116 < (*.f64 a b) < 1.15999999999999995e85

    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}{\left(z \cdot t + x \cdot y\right)} + a \cdot b \]
      2. fma-def99.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -7.6 \cdot 10^{+85}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -2.9 \cdot 10^{-196}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 1.2 \cdot 10^{-287}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 2.25 \cdot 10^{-206}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 1.9 \cdot 10^{-138}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 2.5 \cdot 10^{-116}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 1.16 \cdot 10^{+85}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]

Alternative 5: 78.9% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -1.4 \cdot 10^{+81} \lor \neg \left(x \cdot y \leq 1.4 \cdot 10^{+264}\right):\\
\;\;\;\;x \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x y) < -1.39999999999999997e81 or 1.39999999999999999e264 < (*.f64 x y)

    1. Initial program 90.5%

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

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

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

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

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

    if -1.39999999999999997e81 < (*.f64 x y) < 1.39999999999999999e264

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -1.4 \cdot 10^{+81} \lor \neg \left(x \cdot y \leq 1.4 \cdot 10^{+264}\right):\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \end{array} \]

Alternative 6: 85.7% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1.4 \cdot 10^{+86} \lor \neg \left(a \cdot b \leq 9.4 \cdot 10^{+58}\right):\\
\;\;\;\;a \cdot b + z \cdot t\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 a b) < -1.40000000000000002e86 or 9.39999999999999944e58 < (*.f64 a b)

    1. Initial program 95.8%

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

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

    if -1.40000000000000002e86 < (*.f64 a b) < 9.39999999999999944e58

    1. Initial program 98.7%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -1.4 \cdot 10^{+86} \lor \neg \left(a \cdot b \leq 9.4 \cdot 10^{+58}\right):\\ \;\;\;\;a \cdot b + z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot y + z \cdot t\\ \end{array} \]

Alternative 7: 86.2% accurate, 0.7× speedup?

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

\mathbf{elif}\;a \cdot b \leq 1.5 \cdot 10^{+58}:\\
\;\;\;\;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) < -6.4000000000000004

    1. Initial program 96.1%

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

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

    if -6.4000000000000004 < (*.f64 a b) < 1.5000000000000001e58

    1. Initial program 98.6%

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

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

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

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

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

    if 1.5000000000000001e58 < (*.f64 a b)

    1. Initial program 96.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -6.4:\\ \;\;\;\;a \cdot b + x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 1.5 \cdot 10^{+58}:\\ \;\;\;\;x \cdot y + z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \end{array} \]

Alternative 8: 54.3% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -11 \lor \neg \left(a \cdot b \leq 1.05 \cdot 10^{+87}\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) < -11 or 1.05e87 < (*.f64 a b)

    1. Initial program 97.1%

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

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

    if -11 < (*.f64 a b) < 1.05e87

    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}{\left(z \cdot t + x \cdot y\right)} + a \cdot b \]
      2. fma-def99.3%

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

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

      \[\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 -11 \lor \neg \left(a \cdot b \leq 1.05 \cdot 10^{+87}\right):\\ \;\;\;\;a \cdot b\\ \mathbf{else}:\\ \;\;\;\;z \cdot t\\ \end{array} \]

Alternative 9: 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 97.6%

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

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

Alternative 10: 34.9% accurate, 3.7× speedup?

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

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

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

    \[\leadsto \color{blue}{a \cdot b} \]
  3. Final simplification39.3%

    \[\leadsto a \cdot b \]

Reproduce

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