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

Percentage Accurate: 97.7% → 97.7%
Time: 1.4s
Alternatives: 7
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 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.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: 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}
Derivation
  1. Initial program 96.5%

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

Alternative 2: 52.4% accurate, 0.4× speedup?

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

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

\mathbf{elif}\;x \cdot y \leq -4.9 \cdot 10^{+62}:\\
\;\;\;\;z \cdot t\\

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 x y) < -1.2999999999999999e198 or 7.60000000000000033e118 < (*.f64 x y)

    1. Initial program 89.6%

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

      \[\leadsto \color{blue}{a \cdot b + \left(t \cdot z + x \cdot y\right)} \]
    4. Applied rewrites85.4%

      \[\leadsto \color{blue}{x \cdot y + z \cdot t} \]
    5. Taylor expanded in x around 0

      \[\leadsto t \cdot \color{blue}{z} \]
    6. Applied rewrites77.8%

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

    if -1.2999999999999999e198 < (*.f64 x y) < -4.8999999999999997e62 or -2.60000000000000017e-208 < (*.f64 x y) < 7.5999999999999998e-158

    1. Initial program 98.8%

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

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

      \[\leadsto \color{blue}{x \cdot y + z \cdot t} \]
    5. Taylor expanded in x around 0

      \[\leadsto t \cdot z + \color{blue}{x \cdot y} \]
    6. Applied rewrites59.0%

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

    if -4.8999999999999997e62 < (*.f64 x y) < -2.60000000000000017e-208 or 7.5999999999999998e-158 < (*.f64 x y) < 7.60000000000000033e118

    1. Initial program 99.0%

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

      \[\leadsto \color{blue}{a \cdot b + \left(t \cdot z + x \cdot y\right)} \]
    4. Applied rewrites44.2%

      \[\leadsto \color{blue}{x \cdot y + z \cdot t} \]
    5. Taylor expanded in x around inf

      \[\leadsto x \cdot \color{blue}{\left(y + \frac{t \cdot z}{x}\right)} \]
    6. Applied rewrites58.5%

      \[\leadsto a \cdot \color{blue}{b} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 3: 85.4% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
t_1 := x \cdot y + z \cdot t\\
\mathbf{if}\;x \cdot y \leq -8 \cdot 10^{+78}:\\
\;\;\;\;t\_1\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x y) < -8.00000000000000007e78 or 4.3000000000000001e114 < (*.f64 x y)

    1. Initial program 90.6%

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

      \[\leadsto \color{blue}{a \cdot b + \left(t \cdot z + x \cdot y\right)} \]
    4. Applied rewrites87.4%

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

    if -8.00000000000000007e78 < (*.f64 x y) < 4.3000000000000001e114

    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 \color{blue}{\left(t \cdot z + x \cdot y\right)} + a \cdot b \]
    4. Applied rewrites88.9%

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

Alternative 4: 84.3% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
t_1 := x \cdot y + z \cdot t\\
\mathbf{if}\;z \cdot t \leq -300000000000:\\
\;\;\;\;t\_1\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 z t) < -3e11 or 6.1999999999999995e138 < (*.f64 z t)

    1. Initial program 93.0%

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

      \[\leadsto \color{blue}{a \cdot b + \left(t \cdot z + x \cdot y\right)} \]
    4. Applied rewrites82.5%

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

    if -3e11 < (*.f64 z t) < 6.1999999999999995e138

    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 0

      \[\leadsto \color{blue}{t \cdot z} + a \cdot b \]
    4. Applied rewrites86.2%

      \[\leadsto \color{blue}{x \cdot y} + a \cdot b \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 79.4% accurate, 0.6× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 a b) < -5.4999999999999998e256 or 4.7999999999999998e142 < (*.f64 a b)

    1. Initial program 90.9%

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

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

      \[\leadsto \color{blue}{x \cdot y + z \cdot t} \]
    5. Taylor expanded in x around inf

      \[\leadsto x \cdot \color{blue}{\left(y + \frac{t \cdot z}{x}\right)} \]
    6. Applied rewrites84.2%

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

    if -5.4999999999999998e256 < (*.f64 a b) < 4.7999999999999998e142

    1. Initial program 98.4%

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

      \[\leadsto \color{blue}{a \cdot b + \left(t \cdot z + x \cdot y\right)} \]
    4. Applied rewrites77.2%

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

Alternative 6: 53.7% accurate, 0.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x y) < -2.04999999999999996e63 or 7.60000000000000033e118 < (*.f64 x y)

    1. Initial program 90.8%

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

      \[\leadsto \color{blue}{a \cdot b + \left(t \cdot z + x \cdot y\right)} \]
    4. Applied rewrites87.7%

      \[\leadsto \color{blue}{x \cdot y + z \cdot t} \]
    5. Taylor expanded in x around 0

      \[\leadsto t \cdot \color{blue}{z} \]
    6. Applied rewrites68.4%

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

    if -2.04999999999999996e63 < (*.f64 x y) < 7.60000000000000033e118

    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 \color{blue}{a \cdot b + \left(t \cdot z + x \cdot y\right)} \]
    4. Applied rewrites50.8%

      \[\leadsto \color{blue}{x \cdot y + z \cdot t} \]
    5. Taylor expanded in x around inf

      \[\leadsto x \cdot \color{blue}{\left(y + \frac{t \cdot z}{x}\right)} \]
    6. Applied rewrites53.2%

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

Alternative 7: 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 96.5%

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

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

    \[\leadsto \color{blue}{x \cdot y + z \cdot t} \]
  5. Taylor expanded in x around inf

    \[\leadsto x \cdot \color{blue}{\left(y + \frac{t \cdot z}{x}\right)} \]
  6. Applied rewrites39.0%

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

Reproduce

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