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

Percentage Accurate: 97.9% → 99.1%
Time: 7.8s
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.9% accurate, 1.0× speedup?

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

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

Alternative 1: 99.1% accurate, 0.1× speedup?

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

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

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

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

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

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

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

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

Alternative 2: 98.3% accurate, 0.1× speedup?

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

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

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

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

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

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

Alternative 3: 53.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot b \leq -1.55 \cdot 10^{-20}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 2.6 \cdot 10^{-261}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 5.6 \cdot 10^{-159}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 14500000000000:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (if (<= (* a b) -1.55e-20)
   (* a b)
   (if (<= (* a b) 2.6e-261)
     (* x y)
     (if (<= (* a b) 5.6e-159)
       (* z t)
       (if (<= (* a b) 14500000000000.0) (* x y) (* a b))))))
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if ((a * b) <= -1.55e-20) {
		tmp = a * b;
	} else if ((a * b) <= 2.6e-261) {
		tmp = x * y;
	} else if ((a * b) <= 5.6e-159) {
		tmp = z * t;
	} else if ((a * b) <= 14500000000000.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) <= (-1.55d-20)) then
        tmp = a * b
    else if ((a * b) <= 2.6d-261) then
        tmp = x * y
    else if ((a * b) <= 5.6d-159) then
        tmp = z * t
    else if ((a * b) <= 14500000000000.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) <= -1.55e-20) {
		tmp = a * b;
	} else if ((a * b) <= 2.6e-261) {
		tmp = x * y;
	} else if ((a * b) <= 5.6e-159) {
		tmp = z * t;
	} else if ((a * b) <= 14500000000000.0) {
		tmp = x * y;
	} else {
		tmp = a * b;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if (a * b) <= -1.55e-20:
		tmp = a * b
	elif (a * b) <= 2.6e-261:
		tmp = x * y
	elif (a * b) <= 5.6e-159:
		tmp = z * t
	elif (a * b) <= 14500000000000.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) <= -1.55e-20)
		tmp = Float64(a * b);
	elseif (Float64(a * b) <= 2.6e-261)
		tmp = Float64(x * y);
	elseif (Float64(a * b) <= 5.6e-159)
		tmp = Float64(z * t);
	elseif (Float64(a * b) <= 14500000000000.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) <= -1.55e-20)
		tmp = a * b;
	elseif ((a * b) <= 2.6e-261)
		tmp = x * y;
	elseif ((a * b) <= 5.6e-159)
		tmp = z * t;
	elseif ((a * b) <= 14500000000000.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], -1.55e-20], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 2.6e-261], N[(x * y), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 5.6e-159], N[(z * t), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 14500000000000.0], N[(x * y), $MachinePrecision], N[(a * b), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1.55 \cdot 10^{-20}:\\
\;\;\;\;a \cdot b\\

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 a b) < -1.55e-20 or 1.45e13 < (*.f64 a b)

    1. Initial program 98.3%

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

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

    if -1.55e-20 < (*.f64 a b) < 2.6000000000000001e-261 or 5.6000000000000004e-159 < (*.f64 a b) < 1.45e13

    1. Initial program 99.1%

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

      \[\leadsto \color{blue}{x \cdot y} + a \cdot b \]
    4. Taylor expanded in y around inf 64.1%

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

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

      \[\leadsto \color{blue}{y \cdot \left(x + a \cdot \frac{b}{y}\right)} \]
    7. Taylor expanded in x around inf 59.7%

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

    if 2.6000000000000001e-261 < (*.f64 a b) < 5.6000000000000004e-159

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{t \cdot z} + a \cdot b \]
    4. Taylor expanded in z around inf 69.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -1.55 \cdot 10^{-20}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 2.6 \cdot 10^{-261}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq 5.6 \cdot 10^{-159}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 14500000000000:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 84.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot b \leq -2 \cdot 10^{-9} \lor \neg \left(a \cdot b \leq 5000000000000\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) -2e-9) (not (<= (* a b) 5000000000000.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) <= -2e-9) || !((a * b) <= 5000000000000.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) <= (-2d-9)) .or. (.not. ((a * b) <= 5000000000000.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) <= -2e-9) || !((a * b) <= 5000000000000.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) <= -2e-9) or not ((a * b) <= 5000000000000.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) <= -2e-9) || !(Float64(a * b) <= 5000000000000.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) <= -2e-9) || ~(((a * b) <= 5000000000000.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], -2e-9], N[Not[LessEqual[N[(a * b), $MachinePrecision], 5000000000000.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 -2 \cdot 10^{-9} \lor \neg \left(a \cdot b \leq 5000000000000\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) < -2.00000000000000012e-9 or 5e12 < (*.f64 a b)

    1. Initial program 98.3%

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

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

    if -2.00000000000000012e-9 < (*.f64 a b) < 5e12

    1. Initial program 99.2%

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

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

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

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

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

Alternative 5: 53.0% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -1.55 \cdot 10^{-20} \lor \neg \left(a \cdot b \leq 14500000000000\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) < -1.55e-20 or 1.45e13 < (*.f64 a b)

    1. Initial program 98.3%

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

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

    if -1.55e-20 < (*.f64 a b) < 1.45e13

    1. Initial program 99.2%

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

      \[\leadsto \color{blue}{x \cdot y} + a \cdot b \]
    4. Taylor expanded in y around inf 59.7%

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

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

      \[\leadsto \color{blue}{y \cdot \left(x + a \cdot \frac{b}{y}\right)} \]
    7. Taylor expanded in x around inf 55.9%

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

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

Alternative 6: 72.3% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{+62} \lor \neg \left(y \leq 1.9 \cdot 10^{+131}\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 y < -1.40000000000000007e62 or 1.9000000000000002e131 < y

    1. Initial program 97.7%

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

      \[\leadsto \color{blue}{x \cdot y} + a \cdot b \]
    4. Taylor expanded in y around inf 81.5%

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

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

      \[\leadsto \color{blue}{y \cdot \left(x + a \cdot \frac{b}{y}\right)} \]
    7. Taylor expanded in x around inf 60.9%

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

    if -1.40000000000000007e62 < y < 1.9000000000000002e131

    1. Initial program 99.4%

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

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

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

Alternative 7: 97.9% 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 98.8%

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

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

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

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

    \[\leadsto \color{blue}{a \cdot b} \]
  4. Final simplification34.6%

    \[\leadsto a \cdot b \]
  5. Add Preprocessing

Reproduce

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