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

Percentage Accurate: 97.6% → 98.7%
Time: 7.9s
Alternatives: 7
Speedup: 0.4×

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 7 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.6% 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.7% accurate, 0.4× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + \frac{a \cdot b}{y}\right)\\


\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 100.0%

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

    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. Add Preprocessing
    3. Taylor expanded in y around inf

      \[\leadsto \color{blue}{y \cdot \left(x + \left(\frac{a \cdot b}{y} + \frac{t \cdot z}{y}\right)\right)} \]
    4. Step-by-step derivation
      1. associate-+r+N/A

        \[\leadsto y \cdot \left(\left(x + \frac{a \cdot b}{y}\right) + \color{blue}{\frac{t \cdot z}{y}}\right) \]
      2. +-commutativeN/A

        \[\leadsto y \cdot \left(\frac{t \cdot z}{y} + \color{blue}{\left(x + \frac{a \cdot b}{y}\right)}\right) \]
      3. distribute-lft-inN/A

        \[\leadsto y \cdot \frac{t \cdot z}{y} + \color{blue}{y \cdot \left(x + \frac{a \cdot b}{y}\right)} \]
      4. *-commutativeN/A

        \[\leadsto \frac{t \cdot z}{y} \cdot y + \color{blue}{y} \cdot \left(x + \frac{a \cdot b}{y}\right) \]
      5. associate-*l/N/A

        \[\leadsto \frac{\left(t \cdot z\right) \cdot y}{y} + \color{blue}{y} \cdot \left(x + \frac{a \cdot b}{y}\right) \]
      6. associate-/l*N/A

        \[\leadsto \left(t \cdot z\right) \cdot \frac{y}{y} + \color{blue}{y} \cdot \left(x + \frac{a \cdot b}{y}\right) \]
      7. *-inversesN/A

        \[\leadsto \left(t \cdot z\right) \cdot 1 + y \cdot \left(x + \frac{a \cdot b}{y}\right) \]
      8. *-rgt-identityN/A

        \[\leadsto t \cdot z + \color{blue}{y} \cdot \left(x + \frac{a \cdot b}{y}\right) \]
      9. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\left(t \cdot z\right), \color{blue}{\left(y \cdot \left(x + \frac{a \cdot b}{y}\right)\right)}\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(t, z\right), \left(\color{blue}{y} \cdot \left(x + \frac{a \cdot b}{y}\right)\right)\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(t, z\right), \mathsf{*.f64}\left(y, \color{blue}{\left(x + \frac{a \cdot b}{y}\right)}\right)\right) \]
      12. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(t, z\right), \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(x, \color{blue}{\left(\frac{a \cdot b}{y}\right)}\right)\right)\right) \]
      13. /-lowering-/.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(t, z\right), \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(x, \mathsf{/.f64}\left(\left(a \cdot b\right), \color{blue}{y}\right)\right)\right)\right) \]
      14. *-lowering-*.f6433.3%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(t, z\right), \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(x, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, b\right), y\right)\right)\right)\right) \]
    5. Simplified33.3%

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

      \[\leadsto \color{blue}{y \cdot \left(x + \frac{a \cdot b}{y}\right)} \]
    7. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(y, \color{blue}{\left(x + \frac{a \cdot b}{y}\right)}\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(x, \color{blue}{\left(\frac{a \cdot b}{y}\right)}\right)\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(x, \mathsf{/.f64}\left(\left(a \cdot b\right), \color{blue}{y}\right)\right)\right) \]
      4. *-lowering-*.f6466.7%

        \[\leadsto \mathsf{*.f64}\left(y, \mathsf{+.f64}\left(x, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, b\right), y\right)\right)\right) \]
    8. Simplified66.7%

      \[\leadsto \color{blue}{y \cdot \left(x + \frac{a \cdot b}{y}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.2%

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

Alternative 2: 84.7% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := a \cdot b + z \cdot t\\ t_2 := x \cdot y + a \cdot b\\ \mathbf{if}\;a \cdot b \leq -2 \cdot 10^{+193}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;a \cdot b \leq -5 \cdot 10^{+79}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{-19}:\\ \;\;\;\;x \cdot y + z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 10^{+117}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (+ (* a b) (* z t))) (t_2 (+ (* x y) (* a b))))
   (if (<= (* a b) -2e+193)
     t_2
     (if (<= (* a b) -5e+79)
       t_1
       (if (<= (* a b) 2e-19)
         (+ (* x y) (* z t))
         (if (<= (* a b) 1e+117) t_1 t_2))))))
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (a * b) + (z * t);
	double t_2 = (x * y) + (a * b);
	double tmp;
	if ((a * b) <= -2e+193) {
		tmp = t_2;
	} else if ((a * b) <= -5e+79) {
		tmp = t_1;
	} else if ((a * b) <= 2e-19) {
		tmp = (x * y) + (z * t);
	} else if ((a * b) <= 1e+117) {
		tmp = t_1;
	} else {
		tmp = t_2;
	}
	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) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_1 = (a * b) + (z * t)
    t_2 = (x * y) + (a * b)
    if ((a * b) <= (-2d+193)) then
        tmp = t_2
    else if ((a * b) <= (-5d+79)) then
        tmp = t_1
    else if ((a * b) <= 2d-19) then
        tmp = (x * y) + (z * t)
    else if ((a * b) <= 1d+117) then
        tmp = t_1
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (a * b) + (z * t);
	double t_2 = (x * y) + (a * b);
	double tmp;
	if ((a * b) <= -2e+193) {
		tmp = t_2;
	} else if ((a * b) <= -5e+79) {
		tmp = t_1;
	} else if ((a * b) <= 2e-19) {
		tmp = (x * y) + (z * t);
	} else if ((a * b) <= 1e+117) {
		tmp = t_1;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	t_1 = (a * b) + (z * t)
	t_2 = (x * y) + (a * b)
	tmp = 0
	if (a * b) <= -2e+193:
		tmp = t_2
	elif (a * b) <= -5e+79:
		tmp = t_1
	elif (a * b) <= 2e-19:
		tmp = (x * y) + (z * t)
	elif (a * b) <= 1e+117:
		tmp = t_1
	else:
		tmp = t_2
	return tmp
function code(x, y, z, t, a, b)
	t_1 = Float64(Float64(a * b) + Float64(z * t))
	t_2 = Float64(Float64(x * y) + Float64(a * b))
	tmp = 0.0
	if (Float64(a * b) <= -2e+193)
		tmp = t_2;
	elseif (Float64(a * b) <= -5e+79)
		tmp = t_1;
	elseif (Float64(a * b) <= 2e-19)
		tmp = Float64(Float64(x * y) + Float64(z * t));
	elseif (Float64(a * b) <= 1e+117)
		tmp = t_1;
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	t_1 = (a * b) + (z * t);
	t_2 = (x * y) + (a * b);
	tmp = 0.0;
	if ((a * b) <= -2e+193)
		tmp = t_2;
	elseif ((a * b) <= -5e+79)
		tmp = t_1;
	elseif ((a * b) <= 2e-19)
		tmp = (x * y) + (z * t);
	elseif ((a * b) <= 1e+117)
		tmp = t_1;
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * y), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(a * b), $MachinePrecision], -2e+193], t$95$2, If[LessEqual[N[(a * b), $MachinePrecision], -5e+79], t$95$1, If[LessEqual[N[(a * b), $MachinePrecision], 2e-19], N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 1e+117], t$95$1, t$95$2]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := a \cdot b + z \cdot t\\
t_2 := x \cdot y + a \cdot b\\
\mathbf{if}\;a \cdot b \leq -2 \cdot 10^{+193}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;a \cdot b \leq -5 \cdot 10^{+79}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{-19}:\\
\;\;\;\;x \cdot y + z \cdot t\\

\mathbf{elif}\;a \cdot b \leq 10^{+117}:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;t\_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 a b) < -2.00000000000000013e193 or 1.00000000000000005e117 < (*.f64 a b)

    1. Initial program 94.0%

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

      \[\leadsto \mathsf{+.f64}\left(\color{blue}{\left(x \cdot y\right)}, \mathsf{*.f64}\left(a, b\right)\right) \]
    4. Step-by-step derivation
      1. *-lowering-*.f6494.0%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\color{blue}{a}, b\right)\right) \]
    5. Simplified94.0%

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

    if -2.00000000000000013e193 < (*.f64 a b) < -5e79 or 2e-19 < (*.f64 a b) < 1.00000000000000005e117

    1. Initial program 99.9%

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

      \[\leadsto \mathsf{+.f64}\left(\color{blue}{\left(t \cdot z\right)}, \mathsf{*.f64}\left(a, b\right)\right) \]
    4. Step-by-step derivation
      1. *-lowering-*.f6487.0%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(t, z\right), \mathsf{*.f64}\left(\color{blue}{a}, b\right)\right) \]
    5. Simplified87.0%

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

    if -5e79 < (*.f64 a b) < 2e-19

    1. Initial program 99.2%

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

      \[\leadsto \color{blue}{t \cdot z + x \cdot y} \]
    4. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\left(t \cdot z\right), \color{blue}{\left(x \cdot y\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(t, z\right), \left(\color{blue}{x} \cdot y\right)\right) \]
      3. *-lowering-*.f6489.4%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(t, z\right), \mathsf{*.f64}\left(x, \color{blue}{y}\right)\right) \]
    5. Simplified89.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -2 \cdot 10^{+193}:\\ \;\;\;\;x \cdot y + a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -5 \cdot 10^{+79}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 2 \cdot 10^{-19}:\\ \;\;\;\;x \cdot y + z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 10^{+117}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot y + a \cdot b\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 52.8% accurate, 0.5× speedup?

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

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

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

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

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


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

    1. Initial program 95.2%

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

      \[\leadsto \color{blue}{a \cdot b} \]
    4. Step-by-step derivation
      1. *-lowering-*.f6474.4%

        \[\leadsto \mathsf{*.f64}\left(a, \color{blue}{b}\right) \]
    5. Simplified74.4%

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

    if -4.80000000000000004e181 < (*.f64 a b) < -6.5999999999999997e-285

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{t \cdot z} \]
    4. Step-by-step derivation
      1. *-lowering-*.f6446.2%

        \[\leadsto \mathsf{*.f64}\left(t, \color{blue}{z}\right) \]
    5. Simplified46.2%

      \[\leadsto \color{blue}{t \cdot z} \]

    if -6.5999999999999997e-285 < (*.f64 a b) < 0.0018500000000000001

    1. Initial program 98.7%

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

      \[\leadsto \color{blue}{x \cdot y} \]
    4. Step-by-step derivation
      1. *-lowering-*.f6458.7%

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{y}\right) \]
    5. Simplified58.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -4.8 \cdot 10^{+181}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq -6.6 \cdot 10^{-285}:\\ \;\;\;\;z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 0.00185:\\ \;\;\;\;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} t_1 := a \cdot b + z \cdot t\\ \mathbf{if}\;a \cdot b \leq -4.8 \cdot 10^{+79}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;a \cdot b \leq 1.75 \cdot 10^{-13}:\\ \;\;\;\;x \cdot y + z \cdot t\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (+ (* a b) (* z t))))
   (if (<= (* a b) -4.8e+79)
     t_1
     (if (<= (* a b) 1.75e-13) (+ (* x y) (* z t)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (a * b) + (z * t);
	double tmp;
	if ((a * b) <= -4.8e+79) {
		tmp = t_1;
	} else if ((a * b) <= 1.75e-13) {
		tmp = (x * y) + (z * t);
	} else {
		tmp = t_1;
	}
	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) :: t_1
    real(8) :: tmp
    t_1 = (a * b) + (z * t)
    if ((a * b) <= (-4.8d+79)) then
        tmp = t_1
    else if ((a * b) <= 1.75d-13) then
        tmp = (x * y) + (z * t)
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (a * b) + (z * t);
	double tmp;
	if ((a * b) <= -4.8e+79) {
		tmp = t_1;
	} else if ((a * b) <= 1.75e-13) {
		tmp = (x * y) + (z * t);
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	t_1 = (a * b) + (z * t)
	tmp = 0
	if (a * b) <= -4.8e+79:
		tmp = t_1
	elif (a * b) <= 1.75e-13:
		tmp = (x * y) + (z * t)
	else:
		tmp = t_1
	return tmp
function code(x, y, z, t, a, b)
	t_1 = Float64(Float64(a * b) + Float64(z * t))
	tmp = 0.0
	if (Float64(a * b) <= -4.8e+79)
		tmp = t_1;
	elseif (Float64(a * b) <= 1.75e-13)
		tmp = Float64(Float64(x * y) + Float64(z * t));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	t_1 = (a * b) + (z * t);
	tmp = 0.0;
	if ((a * b) <= -4.8e+79)
		tmp = t_1;
	elseif ((a * b) <= 1.75e-13)
		tmp = (x * y) + (z * t);
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(a * b), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(a * b), $MachinePrecision], -4.8e+79], t$95$1, If[LessEqual[N[(a * b), $MachinePrecision], 1.75e-13], N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := a \cdot b + z \cdot t\\
\mathbf{if}\;a \cdot b \leq -4.8 \cdot 10^{+79}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;a \cdot b \leq 1.75 \cdot 10^{-13}:\\
\;\;\;\;x \cdot y + z \cdot t\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 a b) < -4.79999999999999971e79 or 1.7500000000000001e-13 < (*.f64 a b)

    1. Initial program 95.9%

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

      \[\leadsto \mathsf{+.f64}\left(\color{blue}{\left(t \cdot z\right)}, \mathsf{*.f64}\left(a, b\right)\right) \]
    4. Step-by-step derivation
      1. *-lowering-*.f6483.1%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(t, z\right), \mathsf{*.f64}\left(\color{blue}{a}, b\right)\right) \]
    5. Simplified83.1%

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

    if -4.79999999999999971e79 < (*.f64 a b) < 1.7500000000000001e-13

    1. Initial program 99.2%

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

      \[\leadsto \color{blue}{t \cdot z + x \cdot y} \]
    4. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\left(t \cdot z\right), \color{blue}{\left(x \cdot y\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(t, z\right), \left(\color{blue}{x} \cdot y\right)\right) \]
      3. *-lowering-*.f6489.4%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(t, z\right), \mathsf{*.f64}\left(x, \color{blue}{y}\right)\right) \]
    5. Simplified89.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -4.8 \cdot 10^{+79}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \mathbf{elif}\;a \cdot b \leq 1.75 \cdot 10^{-13}:\\ \;\;\;\;x \cdot y + z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 79.9% accurate, 0.5× speedup?

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

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

\mathbf{elif}\;x \cdot y \leq 8.6 \cdot 10^{+68}:\\
\;\;\;\;a \cdot b + z \cdot t\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x y) < -2.5999999999999999e164 or 8.6000000000000002e68 < (*.f64 x y)

    1. Initial program 94.6%

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

      \[\leadsto \color{blue}{x \cdot y} \]
    4. Step-by-step derivation
      1. *-lowering-*.f6474.6%

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{y}\right) \]
    5. Simplified74.6%

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

    if -2.5999999999999999e164 < (*.f64 x y) < 8.6000000000000002e68

    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

      \[\leadsto \mathsf{+.f64}\left(\color{blue}{\left(t \cdot z\right)}, \mathsf{*.f64}\left(a, b\right)\right) \]
    4. Step-by-step derivation
      1. *-lowering-*.f6485.6%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(t, z\right), \mathsf{*.f64}\left(\color{blue}{a}, b\right)\right) \]
    5. Simplified85.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -2.6 \cdot 10^{+164}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \cdot y \leq 8.6 \cdot 10^{+68}:\\ \;\;\;\;a \cdot b + z \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 52.2% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;a \cdot b \leq 20:\\
\;\;\;\;z \cdot t\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 a b) < -4.80000000000000004e181 or 20 < (*.f64 a b)

    1. Initial program 95.2%

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

      \[\leadsto \color{blue}{a \cdot b} \]
    4. Step-by-step derivation
      1. *-lowering-*.f6475.0%

        \[\leadsto \mathsf{*.f64}\left(a, \color{blue}{b}\right) \]
    5. Simplified75.0%

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

    if -4.80000000000000004e181 < (*.f64 a b) < 20

    1. Initial program 99.3%

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

      \[\leadsto \color{blue}{t \cdot z} \]
    4. Step-by-step derivation
      1. *-lowering-*.f6443.2%

        \[\leadsto \mathsf{*.f64}\left(t, \color{blue}{z}\right) \]
    5. Simplified43.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -4.8 \cdot 10^{+181}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 20:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 35.8% accurate, 3.7× speedup?

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

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

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

    \[\leadsto \color{blue}{a \cdot b} \]
  4. Step-by-step derivation
    1. *-lowering-*.f6439.4%

      \[\leadsto \mathsf{*.f64}\left(a, \color{blue}{b}\right) \]
  5. Simplified39.4%

    \[\leadsto \color{blue}{a \cdot b} \]
  6. Add Preprocessing

Reproduce

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