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

Percentage Accurate: 97.7% → 98.1%
Time: 4.1s
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: 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.1% accurate, 0.1× speedup?

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

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

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

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

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

Alternative 2: 98.2% accurate, 0.1× speedup?

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

\\
\mathsf{fma}\left(a, b, x \cdot y\right) + z \cdot t
\end{array}
Derivation
  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-def98.4%

      \[\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. Step-by-step derivation
    1. fma-udef98.8%

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

      \[\leadsto x \cdot y + \color{blue}{\left(z \cdot t + a \cdot b\right)} \]
    3. associate-+l+98.4%

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

      \[\leadsto \color{blue}{a \cdot b + \left(x \cdot y + z \cdot t\right)} \]
    5. associate-+r+98.4%

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

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

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

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

Alternative 3: 53.3% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot b \leq -2.3 \cdot 10^{+112}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -6.8 \cdot 10^{-165}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq -2 \cdot 10^{-314}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 2.7 \cdot 10^{-192}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 3 \cdot 10^{+132}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (if (<= (* a b) -2.3e+112)
   (* a b)
   (if (<= (* a b) -6.8e-165)
     (* x y)
     (if (<= (* a b) -2e-314)
       (* z t)
       (if (<= (* a b) 2.7e-192)
         (* x y)
         (if (<= (* a b) 3e+132) (* z t) (* a b)))))))
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if ((a * b) <= -2.3e+112) {
		tmp = a * b;
	} else if ((a * b) <= -6.8e-165) {
		tmp = x * y;
	} else if ((a * b) <= -2e-314) {
		tmp = z * t;
	} else if ((a * b) <= 2.7e-192) {
		tmp = x * y;
	} else if ((a * b) <= 3e+132) {
		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) <= (-2.3d+112)) then
        tmp = a * b
    else if ((a * b) <= (-6.8d-165)) then
        tmp = x * y
    else if ((a * b) <= (-2d-314)) then
        tmp = z * t
    else if ((a * b) <= 2.7d-192) then
        tmp = x * y
    else if ((a * b) <= 3d+132) 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) <= -2.3e+112) {
		tmp = a * b;
	} else if ((a * b) <= -6.8e-165) {
		tmp = x * y;
	} else if ((a * b) <= -2e-314) {
		tmp = z * t;
	} else if ((a * b) <= 2.7e-192) {
		tmp = x * y;
	} else if ((a * b) <= 3e+132) {
		tmp = z * t;
	} else {
		tmp = a * b;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if (a * b) <= -2.3e+112:
		tmp = a * b
	elif (a * b) <= -6.8e-165:
		tmp = x * y
	elif (a * b) <= -2e-314:
		tmp = z * t
	elif (a * b) <= 2.7e-192:
		tmp = x * y
	elif (a * b) <= 3e+132:
		tmp = z * t
	else:
		tmp = a * b
	return tmp
function code(x, y, z, t, a, b)
	tmp = 0.0
	if (Float64(a * b) <= -2.3e+112)
		tmp = Float64(a * b);
	elseif (Float64(a * b) <= -6.8e-165)
		tmp = Float64(x * y);
	elseif (Float64(a * b) <= -2e-314)
		tmp = Float64(z * t);
	elseif (Float64(a * b) <= 2.7e-192)
		tmp = Float64(x * y);
	elseif (Float64(a * b) <= 3e+132)
		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) <= -2.3e+112)
		tmp = a * b;
	elseif ((a * b) <= -6.8e-165)
		tmp = x * y;
	elseif ((a * b) <= -2e-314)
		tmp = z * t;
	elseif ((a * b) <= 2.7e-192)
		tmp = x * y;
	elseif ((a * b) <= 3e+132)
		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], -2.3e+112], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -6.8e-165], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], -2e-314], N[(z * t), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2.7e-192], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 3e+132], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]]]]
\begin{array}{l}

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 a b) < -2.3e112 or 2.9999999999999998e132 < (*.f64 a b)

    1. Initial program 97.7%

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

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

    if -2.3e112 < (*.f64 a b) < -6.8e-165 or -1.9999999999e-314 < (*.f64 a b) < 2.69999999999999991e-192

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

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

    if -6.8e-165 < (*.f64 a b) < -1.9999999999e-314 or 2.69999999999999991e-192 < (*.f64 a b) < 2.9999999999999998e132

    1. Initial program 100.0%

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

        \[\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 z around inf 61.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -2.3 \cdot 10^{+112}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -6.8 \cdot 10^{-165}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq -2 \cdot 10^{-314}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 2.7 \cdot 10^{-192}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 3 \cdot 10^{+132}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]

Alternative 4: 84.5% accurate, 0.7× speedup?

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

\mathbf{elif}\;a \cdot b \leq 3.6 \cdot 10^{-15}:\\
\;\;\;\;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) < -4.1999999999999999e50

    1. Initial program 98.0%

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

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

    if -4.1999999999999999e50 < (*.f64 a b) < 3.6000000000000001e-15

    1. Initial program 99.2%

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

        \[\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 93.9%

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

    if 3.6000000000000001e-15 < (*.f64 a b)

    1. Initial program 97.2%

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

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

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

Alternative 5: 79.2% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;t \leq -6.5 \cdot 10^{-40} \lor \neg \left(t \leq 1.25 \cdot 10^{+66}\right):\\
\;\;\;\;a \cdot b + z \cdot t\\

\mathbf{else}:\\
\;\;\;\;a \cdot b + x \cdot y\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if t < -6.4999999999999999e-40 or 1.24999999999999998e66 < t

    1. Initial program 96.6%

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

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

    if -6.4999999999999999e-40 < t < 1.24999999999999998e66

    1. Initial program 100.0%

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

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

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

Alternative 6: 53.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot b \leq -1.15 \cdot 10^{+52}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 3.6 \cdot 10^{+132}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (if (<= (* a b) -1.15e+52)
   (* a b)
   (if (<= (* a b) 3.6e+132) (* z t) (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if ((a * b) <= -1.15e+52) {
		tmp = a * b;
	} else if ((a * b) <= 3.6e+132) {
		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) <= (-1.15d+52)) then
        tmp = a * b
    else if ((a * b) <= 3.6d+132) 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) <= -1.15e+52) {
		tmp = a * b;
	} else if ((a * b) <= 3.6e+132) {
		tmp = z * t;
	} else {
		tmp = a * b;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if (a * b) <= -1.15e+52:
		tmp = a * b
	elif (a * b) <= 3.6e+132:
		tmp = z * t
	else:
		tmp = a * b
	return tmp
function code(x, y, z, t, a, b)
	tmp = 0.0
	if (Float64(a * b) <= -1.15e+52)
		tmp = Float64(a * b);
	elseif (Float64(a * b) <= 3.6e+132)
		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) <= -1.15e+52)
		tmp = a * b;
	elseif ((a * b) <= 3.6e+132)
		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], -1.15e+52], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 3.6e+132], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]
\begin{array}{l}

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 a b) < -1.15e52 or 3.60000000000000016e132 < (*.f64 a b)

    1. Initial program 96.9%

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

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

    if -1.15e52 < (*.f64 a b) < 3.60000000000000016e132

    1. Initial program 99.4%

      \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
    2. Step-by-step derivation
      1. +-commutative99.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 z around inf 49.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -1.15 \cdot 10^{+52}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 3.6 \cdot 10^{+132}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]

Alternative 7: 69.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -8 \cdot 10^{-47}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 3.5 \cdot 10^{+187}:\\ \;\;\;\;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 (<= y -8e-47) (* x y) (if (<= y 3.5e+187) (+ (* a b) (* z t)) (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if (y <= -8e-47) {
		tmp = x * y;
	} else if (y <= 3.5e+187) {
		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 (y <= (-8d-47)) then
        tmp = x * y
    else if (y <= 3.5d+187) 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 (y <= -8e-47) {
		tmp = x * y;
	} else if (y <= 3.5e+187) {
		tmp = (a * b) + (z * t);
	} else {
		tmp = x * y;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if y <= -8e-47:
		tmp = x * y
	elif y <= 3.5e+187:
		tmp = (a * b) + (z * t)
	else:
		tmp = x * y
	return tmp
function code(x, y, z, t, a, b)
	tmp = 0.0
	if (y <= -8e-47)
		tmp = Float64(x * y);
	elseif (y <= 3.5e+187)
		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 (y <= -8e-47)
		tmp = x * y;
	elseif (y <= 3.5e+187)
		tmp = (a * b) + (z * t);
	else
		tmp = x * y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[y, -8e-47], N[(x * y), $MachinePrecision], If[LessEqual[y, 3.5e+187], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{-47}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;y \leq 3.5 \cdot 10^{+187}:\\
\;\;\;\;a \cdot b + z \cdot t\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -7.9999999999999998e-47 or 3.4999999999999998e187 < y

    1. Initial program 96.0%

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

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

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

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

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

    if -7.9999999999999998e-47 < y < 3.4999999999999998e187

    1. Initial program 100.0%

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

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

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

Alternative 8: 97.7% 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.4%

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

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

Alternative 9: 35.6% 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.4%

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

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

    \[\leadsto a \cdot b \]

Reproduce

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