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

Percentage Accurate: 97.8% → 98.8%
Time: 5.3s
Alternatives: 9
Speedup: 1.2×

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

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

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

    \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-+.f64N/A

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(z, t, \color{blue}{b \cdot a} + x \cdot y\right) \]
    10. lower-fma.f6498.8

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

      \[\leadsto \mathsf{fma}\left(z, t, \mathsf{fma}\left(b, a, \color{blue}{x \cdot y}\right)\right) \]
    12. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(z, t, \mathsf{fma}\left(b, a, \color{blue}{y \cdot x}\right)\right) \]
    13. lower-*.f6498.8

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

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

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

Alternative 2: 54.2% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;t \cdot z \leq -8.2 \cdot 10^{+27}:\\ \;\;\;\;t \cdot z\\ \mathbf{elif}\;t \cdot z \leq 1.4 \cdot 10^{-229}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;t \cdot z \leq 4.4 \cdot 10^{-70}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;t \cdot z \leq 7.6 \cdot 10^{+34}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;t \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (if (<= (* t z) -8.2e+27)
   (* t z)
   (if (<= (* t z) 1.4e-229)
     (* x y)
     (if (<= (* t z) 4.4e-70)
       (* a b)
       (if (<= (* t z) 7.6e+34) (* x y) (* t z))))))
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if ((t * z) <= -8.2e+27) {
		tmp = t * z;
	} else if ((t * z) <= 1.4e-229) {
		tmp = x * y;
	} else if ((t * z) <= 4.4e-70) {
		tmp = a * b;
	} else if ((t * z) <= 7.6e+34) {
		tmp = x * y;
	} else {
		tmp = t * z;
	}
	return tmp;
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if ((t * z) <= (-8.2d+27)) then
        tmp = t * z
    else if ((t * z) <= 1.4d-229) then
        tmp = x * y
    else if ((t * z) <= 4.4d-70) then
        tmp = a * b
    else if ((t * z) <= 7.6d+34) then
        tmp = x * y
    else
        tmp = t * z
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if ((t * z) <= -8.2e+27) {
		tmp = t * z;
	} else if ((t * z) <= 1.4e-229) {
		tmp = x * y;
	} else if ((t * z) <= 4.4e-70) {
		tmp = a * b;
	} else if ((t * z) <= 7.6e+34) {
		tmp = x * y;
	} else {
		tmp = t * z;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if (t * z) <= -8.2e+27:
		tmp = t * z
	elif (t * z) <= 1.4e-229:
		tmp = x * y
	elif (t * z) <= 4.4e-70:
		tmp = a * b
	elif (t * z) <= 7.6e+34:
		tmp = x * y
	else:
		tmp = t * z
	return tmp
function code(x, y, z, t, a, b)
	tmp = 0.0
	if (Float64(t * z) <= -8.2e+27)
		tmp = Float64(t * z);
	elseif (Float64(t * z) <= 1.4e-229)
		tmp = Float64(x * y);
	elseif (Float64(t * z) <= 4.4e-70)
		tmp = Float64(a * b);
	elseif (Float64(t * z) <= 7.6e+34)
		tmp = Float64(x * y);
	else
		tmp = Float64(t * z);
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a, b)
	tmp = 0.0;
	if ((t * z) <= -8.2e+27)
		tmp = t * z;
	elseif ((t * z) <= 1.4e-229)
		tmp = x * y;
	elseif ((t * z) <= 4.4e-70)
		tmp = a * b;
	elseif ((t * z) <= 7.6e+34)
		tmp = x * y;
	else
		tmp = t * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(t * z), $MachinePrecision], -8.2e+27], N[(t * z), $MachinePrecision], If[LessEqual[N[(t * z), $MachinePrecision], 1.4e-229], N[(x * y), $MachinePrecision], If[LessEqual[N[(t * z), $MachinePrecision], 4.4e-70], N[(a * b), $MachinePrecision], If[LessEqual[N[(t * z), $MachinePrecision], 7.6e+34], N[(x * y), $MachinePrecision], N[(t * z), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;t \cdot z \leq -8.2 \cdot 10^{+27}:\\
\;\;\;\;t \cdot z\\

\mathbf{elif}\;t \cdot z \leq 1.4 \cdot 10^{-229}:\\
\;\;\;\;x \cdot y\\

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

\mathbf{elif}\;t \cdot z \leq 7.6 \cdot 10^{+34}:\\
\;\;\;\;x \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 z t) < -8.2000000000000005e27 or 7.6000000000000003e34 < (*.f64 z t)

    1. Initial program 97.4%

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

      \[\leadsto \color{blue}{t \cdot z} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{z \cdot t} \]
      2. lower-*.f6470.5

        \[\leadsto \color{blue}{z \cdot t} \]
    5. Applied rewrites70.5%

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

    if -8.2000000000000005e27 < (*.f64 z t) < 1.39999999999999995e-229 or 4.3999999999999998e-70 < (*.f64 z t) < 7.6000000000000003e34

    1. Initial program 100.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}{x \cdot y} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{y \cdot x} \]
      2. lower-*.f6458.5

        \[\leadsto \color{blue}{y \cdot x} \]
    5. Applied rewrites58.5%

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

    if 1.39999999999999995e-229 < (*.f64 z t) < 4.3999999999999998e-70

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{a \cdot b} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{b \cdot a} \]
      2. lower-*.f6468.7

        \[\leadsto \color{blue}{b \cdot a} \]
    5. Applied rewrites68.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \cdot z \leq -8.2 \cdot 10^{+27}:\\ \;\;\;\;t \cdot z\\ \mathbf{elif}\;t \cdot z \leq 1.4 \cdot 10^{-229}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;t \cdot z \leq 4.4 \cdot 10^{-70}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;t \cdot z \leq 7.6 \cdot 10^{+34}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;t \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 84.1% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{fma}\left(z, t, x \cdot y\right)\\ \mathbf{if}\;x \cdot y \leq -1 \cdot 10^{-85}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \cdot y \leq 50000:\\ \;\;\;\;\mathsf{fma}\left(z, t, a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (fma z t (* x y))))
   (if (<= (* x y) -1e-85)
     t_1
     (if (<= (* x y) 50000.0) (fma z t (* a b)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = fma(z, t, (x * y));
	double tmp;
	if ((x * y) <= -1e-85) {
		tmp = t_1;
	} else if ((x * y) <= 50000.0) {
		tmp = fma(z, t, (a * b));
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z, t, a, b)
	t_1 = fma(z, t, Float64(x * y))
	tmp = 0.0
	if (Float64(x * y) <= -1e-85)
		tmp = t_1;
	elseif (Float64(x * y) <= 50000.0)
		tmp = fma(z, t, Float64(a * b));
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(z * t + N[(x * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -1e-85], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 50000.0], N[(z * t + N[(a * b), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(z, t, x \cdot y\right)\\
\mathbf{if}\;x \cdot y \leq -1 \cdot 10^{-85}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;x \cdot y \leq 50000:\\
\;\;\;\;\mathsf{fma}\left(z, t, a \cdot b\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x y) < -9.9999999999999998e-86 or 5e4 < (*.f64 x y)

    1. Initial program 97.9%

      \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(z, t, \color{blue}{b \cdot a} + x \cdot y\right) \]
      10. lower-fma.f6497.9

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

        \[\leadsto \mathsf{fma}\left(z, t, \mathsf{fma}\left(b, a, \color{blue}{x \cdot y}\right)\right) \]
      12. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(z, t, \mathsf{fma}\left(b, a, \color{blue}{y \cdot x}\right)\right) \]
      13. lower-*.f6497.9

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, t, \mathsf{fma}\left(b, a, y \cdot x\right)\right)} \]
    5. Taylor expanded in b around 0

      \[\leadsto \mathsf{fma}\left(z, t, \color{blue}{x \cdot y}\right) \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(z, t, \color{blue}{y \cdot x}\right) \]
      2. lower-*.f6487.2

        \[\leadsto \mathsf{fma}\left(z, t, \color{blue}{y \cdot x}\right) \]
    7. Applied rewrites87.2%

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

    if -9.9999999999999998e-86 < (*.f64 x y) < 5e4

    1. Initial program 100.0%

      \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(z, t, \color{blue}{b \cdot a} + x \cdot y\right) \]
      10. lower-fma.f64100.0

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

        \[\leadsto \mathsf{fma}\left(z, t, \mathsf{fma}\left(b, a, \color{blue}{x \cdot y}\right)\right) \]
      12. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(z, t, \mathsf{fma}\left(b, a, \color{blue}{y \cdot x}\right)\right) \]
      13. lower-*.f64100.0

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

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

      \[\leadsto \mathsf{fma}\left(z, t, \color{blue}{a \cdot b}\right) \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(z, t, \color{blue}{b \cdot a}\right) \]
      2. lower-*.f6495.4

        \[\leadsto \mathsf{fma}\left(z, t, \color{blue}{b \cdot a}\right) \]
    7. Applied rewrites95.4%

      \[\leadsto \mathsf{fma}\left(z, t, \color{blue}{b \cdot a}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification90.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -1 \cdot 10^{-85}:\\ \;\;\;\;\mathsf{fma}\left(z, t, x \cdot y\right)\\ \mathbf{elif}\;x \cdot y \leq 50000:\\ \;\;\;\;\mathsf{fma}\left(z, t, a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, t, x \cdot y\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 84.3% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{fma}\left(y, x, t \cdot z\right)\\ \mathbf{if}\;x \cdot y \leq -1 \cdot 10^{-85}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \cdot y \leq 50000:\\ \;\;\;\;\mathsf{fma}\left(z, t, a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (fma y x (* t z))))
   (if (<= (* x y) -1e-85)
     t_1
     (if (<= (* x y) 50000.0) (fma z t (* a b)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = fma(y, x, (t * z));
	double tmp;
	if ((x * y) <= -1e-85) {
		tmp = t_1;
	} else if ((x * y) <= 50000.0) {
		tmp = fma(z, t, (a * b));
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z, t, a, b)
	t_1 = fma(y, x, Float64(t * z))
	tmp = 0.0
	if (Float64(x * y) <= -1e-85)
		tmp = t_1;
	elseif (Float64(x * y) <= 50000.0)
		tmp = fma(z, t, Float64(a * b));
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(y * x + N[(t * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -1e-85], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 50000.0], N[(z * t + N[(a * b), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(y, x, t \cdot z\right)\\
\mathbf{if}\;x \cdot y \leq -1 \cdot 10^{-85}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;x \cdot y \leq 50000:\\
\;\;\;\;\mathsf{fma}\left(z, t, a \cdot b\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x y) < -9.9999999999999998e-86 or 5e4 < (*.f64 x y)

    1. Initial program 97.9%

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

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

        \[\leadsto \color{blue}{x \cdot y + t \cdot z} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{y \cdot x} + t \cdot z \]
      3. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, t \cdot z\right)} \]
      4. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{z \cdot t}\right) \]
      5. lower-*.f6487.2

        \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{z \cdot t}\right) \]
    5. Applied rewrites87.2%

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

    if -9.9999999999999998e-86 < (*.f64 x y) < 5e4

    1. Initial program 100.0%

      \[\left(x \cdot y + z \cdot t\right) + a \cdot b \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(z, t, \color{blue}{b \cdot a} + x \cdot y\right) \]
      10. lower-fma.f64100.0

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

        \[\leadsto \mathsf{fma}\left(z, t, \mathsf{fma}\left(b, a, \color{blue}{x \cdot y}\right)\right) \]
      12. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(z, t, \mathsf{fma}\left(b, a, \color{blue}{y \cdot x}\right)\right) \]
      13. lower-*.f64100.0

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

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

      \[\leadsto \mathsf{fma}\left(z, t, \color{blue}{a \cdot b}\right) \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(z, t, \color{blue}{b \cdot a}\right) \]
      2. lower-*.f6495.4

        \[\leadsto \mathsf{fma}\left(z, t, \color{blue}{b \cdot a}\right) \]
    7. Applied rewrites95.4%

      \[\leadsto \mathsf{fma}\left(z, t, \color{blue}{b \cdot a}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification90.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -1 \cdot 10^{-85}:\\ \;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\ \mathbf{elif}\;x \cdot y \leq 50000:\\ \;\;\;\;\mathsf{fma}\left(z, t, a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 84.4% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{fma}\left(y, x, t \cdot z\right)\\ \mathbf{if}\;x \cdot y \leq -1 \cdot 10^{-85}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \cdot y \leq 50000:\\ \;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (fma y x (* t z))))
   (if (<= (* x y) -1e-85)
     t_1
     (if (<= (* x y) 50000.0) (fma b a (* t z)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = fma(y, x, (t * z));
	double tmp;
	if ((x * y) <= -1e-85) {
		tmp = t_1;
	} else if ((x * y) <= 50000.0) {
		tmp = fma(b, a, (t * z));
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z, t, a, b)
	t_1 = fma(y, x, Float64(t * z))
	tmp = 0.0
	if (Float64(x * y) <= -1e-85)
		tmp = t_1;
	elseif (Float64(x * y) <= 50000.0)
		tmp = fma(b, a, Float64(t * z));
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(y * x + N[(t * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x * y), $MachinePrecision], -1e-85], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 50000.0], N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(y, x, t \cdot z\right)\\
\mathbf{if}\;x \cdot y \leq -1 \cdot 10^{-85}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;x \cdot y \leq 50000:\\
\;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x y) < -9.9999999999999998e-86 or 5e4 < (*.f64 x y)

    1. Initial program 97.9%

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

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

        \[\leadsto \color{blue}{x \cdot y + t \cdot z} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{y \cdot x} + t \cdot z \]
      3. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, t \cdot z\right)} \]
      4. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{z \cdot t}\right) \]
      5. lower-*.f6487.2

        \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{z \cdot t}\right) \]
    5. Applied rewrites87.2%

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

    if -9.9999999999999998e-86 < (*.f64 x y) < 5e4

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{a \cdot b + t \cdot z} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{b \cdot a} + t \cdot z \]
      2. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, t \cdot z\right)} \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{z \cdot t}\right) \]
      4. lower-*.f6495.4

        \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{z \cdot t}\right) \]
    5. Applied rewrites95.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, z \cdot t\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification90.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -1 \cdot 10^{-85}:\\ \;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\ \mathbf{elif}\;x \cdot y \leq 50000:\\ \;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, x, t \cdot z\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 86.2% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{fma}\left(b, a, t \cdot z\right)\\ \mathbf{if}\;t \cdot z \leq -3.6 \cdot 10^{+26}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t \cdot z \leq 1.5 \cdot 10^{+37}:\\ \;\;\;\;\mathsf{fma}\left(b, a, x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (fma b a (* t z))))
   (if (<= (* t z) -3.6e+26)
     t_1
     (if (<= (* t z) 1.5e+37) (fma b a (* x y)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = fma(b, a, (t * z));
	double tmp;
	if ((t * z) <= -3.6e+26) {
		tmp = t_1;
	} else if ((t * z) <= 1.5e+37) {
		tmp = fma(b, a, (x * y));
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z, t, a, b)
	t_1 = fma(b, a, Float64(t * z))
	tmp = 0.0
	if (Float64(t * z) <= -3.6e+26)
		tmp = t_1;
	elseif (Float64(t * z) <= 1.5e+37)
		tmp = fma(b, a, Float64(x * y));
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(b * a + N[(t * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t * z), $MachinePrecision], -3.6e+26], t$95$1, If[LessEqual[N[(t * z), $MachinePrecision], 1.5e+37], N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(b, a, t \cdot z\right)\\
\mathbf{if}\;t \cdot z \leq -3.6 \cdot 10^{+26}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t \cdot z \leq 1.5 \cdot 10^{+37}:\\
\;\;\;\;\mathsf{fma}\left(b, a, x \cdot y\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 z t) < -3.60000000000000024e26 or 1.50000000000000011e37 < (*.f64 z t)

    1. Initial program 97.3%

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

      \[\leadsto \color{blue}{a \cdot b + t \cdot z} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{b \cdot a} + t \cdot z \]
      2. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, t \cdot z\right)} \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{z \cdot t}\right) \]
      4. lower-*.f6483.2

        \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{z \cdot t}\right) \]
    5. Applied rewrites83.2%

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

    if -3.60000000000000024e26 < (*.f64 z t) < 1.50000000000000011e37

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{a \cdot b + x \cdot y} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{b \cdot a} + x \cdot y \]
      2. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, x \cdot y\right)} \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{y \cdot x}\right) \]
      4. lower-*.f6489.4

        \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{y \cdot x}\right) \]
    5. Applied rewrites89.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, y \cdot x\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification86.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \cdot z \leq -3.6 \cdot 10^{+26}:\\ \;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\ \mathbf{elif}\;t \cdot z \leq 1.5 \cdot 10^{+37}:\\ \;\;\;\;\mathsf{fma}\left(b, a, x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(b, a, t \cdot z\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 81.4% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;t \cdot z \leq -1.4 \cdot 10^{+116}:\\ \;\;\;\;t \cdot z\\ \mathbf{elif}\;t \cdot z \leq 1.4 \cdot 10^{+163}:\\ \;\;\;\;\mathsf{fma}\left(b, a, x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (if (<= (* t z) -1.4e+116)
   (* t z)
   (if (<= (* t z) 1.4e+163) (fma b a (* x y)) (* t z))))
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if ((t * z) <= -1.4e+116) {
		tmp = t * z;
	} else if ((t * z) <= 1.4e+163) {
		tmp = fma(b, a, (x * y));
	} else {
		tmp = t * z;
	}
	return tmp;
}
function code(x, y, z, t, a, b)
	tmp = 0.0
	if (Float64(t * z) <= -1.4e+116)
		tmp = Float64(t * z);
	elseif (Float64(t * z) <= 1.4e+163)
		tmp = fma(b, a, Float64(x * y));
	else
		tmp = Float64(t * z);
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[N[(t * z), $MachinePrecision], -1.4e+116], N[(t * z), $MachinePrecision], If[LessEqual[N[(t * z), $MachinePrecision], 1.4e+163], N[(b * a + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(t * z), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;t \cdot z \leq -1.4 \cdot 10^{+116}:\\
\;\;\;\;t \cdot z\\

\mathbf{elif}\;t \cdot z \leq 1.4 \cdot 10^{+163}:\\
\;\;\;\;\mathsf{fma}\left(b, a, x \cdot y\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 z t) < -1.40000000000000002e116 or 1.40000000000000007e163 < (*.f64 z t)

    1. Initial program 96.2%

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

      \[\leadsto \color{blue}{t \cdot z} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{z \cdot t} \]
      2. lower-*.f6484.5

        \[\leadsto \color{blue}{z \cdot t} \]
    5. Applied rewrites84.5%

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

    if -1.40000000000000002e116 < (*.f64 z t) < 1.40000000000000007e163

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{a \cdot b + x \cdot y} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{b \cdot a} + x \cdot y \]
      2. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, x \cdot y\right)} \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{y \cdot x}\right) \]
      4. lower-*.f6483.9

        \[\leadsto \mathsf{fma}\left(b, a, \color{blue}{y \cdot x}\right) \]
    5. Applied rewrites83.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(b, a, y \cdot x\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification84.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \cdot z \leq -1.4 \cdot 10^{+116}:\\ \;\;\;\;t \cdot z\\ \mathbf{elif}\;t \cdot z \leq 1.4 \cdot 10^{+163}:\\ \;\;\;\;\mathsf{fma}\left(b, a, x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 52.5% accurate, 0.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x y) < -9.9999999999999998e-86 or 5e4 < (*.f64 x y)

    1. Initial program 97.9%

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

      \[\leadsto \color{blue}{x \cdot y} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{y \cdot x} \]
      2. lower-*.f6461.5

        \[\leadsto \color{blue}{y \cdot x} \]
    5. Applied rewrites61.5%

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

    if -9.9999999999999998e-86 < (*.f64 x y) < 5e4

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{a \cdot b} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \color{blue}{b \cdot a} \]
      2. lower-*.f6447.1

        \[\leadsto \color{blue}{b \cdot a} \]
    5. Applied rewrites47.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -1 \cdot 10^{-85}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \cdot y \leq 50000:\\ \;\;\;\;a \cdot b\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 36.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 b around inf

    \[\leadsto \color{blue}{a \cdot b} \]
  4. Step-by-step derivation
    1. *-commutativeN/A

      \[\leadsto \color{blue}{b \cdot a} \]
    2. lower-*.f6430.1

      \[\leadsto \color{blue}{b \cdot a} \]
  5. Applied rewrites30.1%

    \[\leadsto \color{blue}{b \cdot a} \]
  6. Final simplification30.1%

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

Reproduce

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