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

Percentage Accurate: 97.8% → 98.5%
Time: 4.5s
Alternatives: 9
Speedup: 0.5×

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.8% 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.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := a \cdot b + \left(z \cdot t + x \cdot y\right)\\ \mathbf{if}\;t_1 \leq \infty:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot t\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (+ (* a b) (+ (* z t) (* x y)))))
   (if (<= t_1 INFINITY) t_1 (* z t))))
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (a * b) + ((z * t) + (x * y));
	double tmp;
	if (t_1 <= ((double) INFINITY)) {
		tmp = t_1;
	} else {
		tmp = z * t;
	}
	return tmp;
}
public static double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (a * b) + ((z * t) + (x * y));
	double tmp;
	if (t_1 <= Double.POSITIVE_INFINITY) {
		tmp = t_1;
	} else {
		tmp = z * t;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	t_1 = (a * b) + ((z * t) + (x * y))
	tmp = 0
	if t_1 <= math.inf:
		tmp = t_1
	else:
		tmp = z * t
	return tmp
function code(x, y, z, t, a, b)
	t_1 = Float64(Float64(a * b) + Float64(Float64(z * t) + Float64(x * y)))
	tmp = 0.0
	if (t_1 <= Inf)
		tmp = t_1;
	else
		tmp = Float64(z * t);
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	t_1 = (a * b) + ((z * t) + (x * y));
	tmp = 0.0;
	if (t_1 <= Inf)
		tmp = t_1;
	else
		tmp = z * t;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(a * b), $MachinePrecision] + N[(N[(z * t), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, Infinity], t$95$1, N[(z * t), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := a \cdot b + \left(z \cdot t + x \cdot y\right)\\
\mathbf{if}\;t_1 \leq \infty:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;z \cdot t\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (+.f64 (*.f64 x y) (*.f64 z t)) (*.f64 a b)) < +inf.0

    1. Initial program 99.9%

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

    if +inf.0 < (+.f64 (+.f64 (*.f64 x y) (*.f64 z t)) (*.f64 a b))

    1. Initial program 0.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b + \left(z \cdot t + x \cdot y\right) \leq \infty:\\ \;\;\;\;a \cdot b + \left(z \cdot t + x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot t\\ \end{array} \]

Alternative 2: 99.0% 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 98.0%

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

      \[\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.4%

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

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

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

Alternative 3: 98.2% 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 98.0%

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

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

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

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

Alternative 4: 69.9% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -9.6 \cdot 10^{+157}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -1 \cdot 10^{+112} \lor \neg \left(x \leq -2.8 \cdot 10^{+69}\right) \land x \leq 0.033:\\ \;\;\;\;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 (<= x -9.6e+157)
   (* x y)
   (if (or (<= x -1e+112) (and (not (<= x -2.8e+69)) (<= x 0.033)))
     (+ (* a b) (* z t))
     (* x y))))
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if (x <= -9.6e+157) {
		tmp = x * y;
	} else if ((x <= -1e+112) || (!(x <= -2.8e+69) && (x <= 0.033))) {
		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 (x <= (-9.6d+157)) then
        tmp = x * y
    else if ((x <= (-1d+112)) .or. (.not. (x <= (-2.8d+69))) .and. (x <= 0.033d0)) 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 (x <= -9.6e+157) {
		tmp = x * y;
	} else if ((x <= -1e+112) || (!(x <= -2.8e+69) && (x <= 0.033))) {
		tmp = (a * b) + (z * t);
	} else {
		tmp = x * y;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if x <= -9.6e+157:
		tmp = x * y
	elif (x <= -1e+112) or (not (x <= -2.8e+69) and (x <= 0.033)):
		tmp = (a * b) + (z * t)
	else:
		tmp = x * y
	return tmp
function code(x, y, z, t, a, b)
	tmp = 0.0
	if (x <= -9.6e+157)
		tmp = Float64(x * y);
	elseif ((x <= -1e+112) || (!(x <= -2.8e+69) && (x <= 0.033)))
		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 (x <= -9.6e+157)
		tmp = x * y;
	elseif ((x <= -1e+112) || (~((x <= -2.8e+69)) && (x <= 0.033)))
		tmp = (a * b) + (z * t);
	else
		tmp = x * y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[x, -9.6e+157], N[(x * y), $MachinePrecision], If[Or[LessEqual[x, -1e+112], And[N[Not[LessEqual[x, -2.8e+69]], $MachinePrecision], LessEqual[x, 0.033]]], N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;x \leq -1 \cdot 10^{+112} \lor \neg \left(x \leq -2.8 \cdot 10^{+69}\right) \land x \leq 0.033:\\
\;\;\;\;a \cdot b + z \cdot t\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -9.5999999999999998e157 or -9.9999999999999993e111 < x < -2.79999999999999982e69 or 0.033000000000000002 < x

    1. Initial program 97.1%

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

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

    if -9.5999999999999998e157 < x < -9.9999999999999993e111 or -2.79999999999999982e69 < x < 0.033000000000000002

    1. Initial program 98.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -9.6 \cdot 10^{+157}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq -1 \cdot 10^{+112} \lor \neg \left(x \leq -2.8 \cdot 10^{+69}\right) \land x \leq 0.033:\\ \;\;\;\;a \cdot b + z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]

Alternative 5: 84.9% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+47} \lor \neg \left(z \cdot t \leq 6 \cdot 10^{+46}\right):\\
\;\;\;\;z \cdot t + x \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 z t) < -5.00000000000000022e47 or 6.00000000000000047e46 < (*.f64 z t)

    1. Initial program 96.3%

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

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

    if -5.00000000000000022e47 < (*.f64 z t) < 6.00000000000000047e46

    1. Initial program 99.2%

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

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

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

Alternative 6: 47.2% accurate, 1.0× speedup?

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

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

\mathbf{elif}\;y \leq 3.4 \lor \neg \left(y \leq 2.5 \cdot 10^{+113}\right) \land y \leq 3.9 \cdot 10^{+148}:\\
\;\;\;\;z \cdot t\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -2.4e-88 or 3.39999999999999991 < y < 2.5e113 or 3.90000000000000002e148 < y

    1. Initial program 98.4%

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

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

    if -2.4e-88 < y < 3.39999999999999991 or 2.5e113 < y < 3.90000000000000002e148

    1. Initial program 97.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.4 \cdot 10^{-88}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 3.4 \lor \neg \left(y \leq 2.5 \cdot 10^{+113}\right) \land y \leq 3.9 \cdot 10^{+148}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]

Alternative 7: 77.4% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.6 \cdot 10^{+28} \lor \neg \left(x \leq 3 \cdot 10^{-132}\right):\\
\;\;\;\;a \cdot b + x \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -5.6000000000000003e28 or 3e-132 < x

    1. Initial program 96.6%

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

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

    if -5.6000000000000003e28 < x < 3e-132

    1. Initial program 100.0%

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

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

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

Alternative 8: 55.1% accurate, 1.0× speedup?

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

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

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

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


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

    1. Initial program 95.0%

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

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

    if -3.3e52 < (*.f64 a b) < 8.5e43

    1. Initial program 99.9%

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

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

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

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

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

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

    \[\leadsto a \cdot b \]

Reproduce

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