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

Percentage Accurate: 97.7% → 98.9%
Time: 3.7s
Alternatives: 8
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 97.7% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

    \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
  2. Step-by-step derivation
    1. fma-def99.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. Final simplification99.2%

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

Alternative 3: 50.1% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot b \leq -8 \cdot 10^{-133}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 4 \cdot 10^{-22} \lor \neg \left(a \cdot b \leq 1.9 \cdot 10^{+69}\right) \land a \cdot b \leq 8.8 \cdot 10^{+175}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (if (<= (* a b) -8e-133)
   (* a b)
   (if (or (<= (* a b) 4e-22)
           (and (not (<= (* a b) 1.9e+69)) (<= (* a b) 8.8e+175)))
     (* z t)
     (* a b))))
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if ((a * b) <= -8e-133) {
		tmp = a * b;
	} else if (((a * b) <= 4e-22) || (!((a * b) <= 1.9e+69) && ((a * b) <= 8.8e+175))) {
		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) <= (-8d-133)) then
        tmp = a * b
    else if (((a * b) <= 4d-22) .or. (.not. ((a * b) <= 1.9d+69)) .and. ((a * b) <= 8.8d+175)) 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) <= -8e-133) {
		tmp = a * b;
	} else if (((a * b) <= 4e-22) || (!((a * b) <= 1.9e+69) && ((a * b) <= 8.8e+175))) {
		tmp = z * t;
	} else {
		tmp = a * b;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if (a * b) <= -8e-133:
		tmp = a * b
	elif ((a * b) <= 4e-22) or (not ((a * b) <= 1.9e+69) and ((a * b) <= 8.8e+175)):
		tmp = z * t
	else:
		tmp = a * b
	return tmp
function code(x, y, z, t, a, b)
	tmp = 0.0
	if (Float64(a * b) <= -8e-133)
		tmp = Float64(a * b);
	elseif ((Float64(a * b) <= 4e-22) || (!(Float64(a * b) <= 1.9e+69) && (Float64(a * b) <= 8.8e+175)))
		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) <= -8e-133)
		tmp = a * b;
	elseif (((a * b) <= 4e-22) || (~(((a * b) <= 1.9e+69)) && ((a * b) <= 8.8e+175)))
		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], -8e-133], N[(a * b), $MachinePrecision], If[Or[LessEqual[N[(a * b), $MachinePrecision], 4e-22], And[N[Not[LessEqual[N[(a * b), $MachinePrecision], 1.9e+69]], $MachinePrecision], LessEqual[N[(a * b), $MachinePrecision], 8.8e+175]]], N[(z * t), $MachinePrecision], N[(a * b), $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;a \cdot b \leq 4 \cdot 10^{-22} \lor \neg \left(a \cdot b \leq 1.9 \cdot 10^{+69}\right) \land a \cdot b \leq 8.8 \cdot 10^{+175}:\\
\;\;\;\;z \cdot t\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 a b) < -8.0000000000000005e-133 or 4.0000000000000002e-22 < (*.f64 a b) < 1.90000000000000014e69 or 8.7999999999999997e175 < (*.f64 a b)

    1. Initial program 97.9%

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

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

    if -8.0000000000000005e-133 < (*.f64 a b) < 4.0000000000000002e-22 or 1.90000000000000014e69 < (*.f64 a b) < 8.7999999999999997e175

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -8 \cdot 10^{-133}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 4 \cdot 10^{-22} \lor \neg \left(a \cdot b \leq 1.9 \cdot 10^{+69}\right) \land a \cdot b \leq 8.8 \cdot 10^{+175}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]

Alternative 4: 52.5% accurate, 0.6× speedup?

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

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

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

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

\mathbf{elif}\;a \cdot b \leq 8.8 \cdot 10^{+175}:\\
\;\;\;\;x \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 a b) < -5.39999999999999992e38 or 8.7999999999999997e175 < (*.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 78.8%

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

    if -5.39999999999999992e38 < (*.f64 a b) < -1.1500000000000001e-196 or -9.999999985e-316 < (*.f64 a b) < 8.7999999999999997e175

    1. Initial program 100.0%

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

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

    if -1.1500000000000001e-196 < (*.f64 a b) < -9.999999985e-316

    1. Initial program 100.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -5.4 \cdot 10^{+38}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -1.15 \cdot 10^{-196}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;a \cdot b \leq -1 \cdot 10^{-315}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 8.8 \cdot 10^{+175}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]

Alternative 5: 69.8% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.4 \cdot 10^{-34} \lor \neg \left(y \leq 1.05 \cdot 10^{+176}\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 y < -6.40000000000000005e-34 or 1.05e176 < y

    1. Initial program 97.1%

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

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

    if -6.40000000000000005e-34 < y < 1.05e176

    1. Initial program 100.0%

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

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

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

Alternative 6: 79.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -660000 \lor \neg \left(x \leq 1.95 \cdot 10^{-62}\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 -660000.0) (not (<= x 1.95e-62)))
   (+ (* 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 <= -660000.0) || !(x <= 1.95e-62)) {
		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 <= (-660000.0d0)) .or. (.not. (x <= 1.95d-62))) 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 <= -660000.0) || !(x <= 1.95e-62)) {
		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 <= -660000.0) or not (x <= 1.95e-62):
		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 <= -660000.0) || !(x <= 1.95e-62))
		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 <= -660000.0) || ~((x <= 1.95e-62)))
		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, -660000.0], N[Not[LessEqual[x, 1.95e-62]], $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 -660000 \lor \neg \left(x \leq 1.95 \cdot 10^{-62}\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 < -6.6e5 or 1.9500000000000002e-62 < x

    1. Initial program 97.8%

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

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

    if -6.6e5 < x < 1.9500000000000002e-62

    1. Initial program 100.0%

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

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

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

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

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

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

Alternative 8: 35.3% 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. Taylor expanded in a around inf 38.5%

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

    \[\leadsto a \cdot b \]

Reproduce

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