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

Percentage Accurate: 97.4% → 97.4%
Time: 1.4s
Alternatives: 7
Speedup: 1.0×

Specification

?
\[\mathsf{TRUE}\left(\right)\]
\[\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.4% 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.4% 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 98.4%

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

Alternative 2: 54.2% accurate, 0.4× speedup?

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 x y) < -5.49999999999999975e53 or 3.30000000000000023e48 < (*.f64 x y)

    1. Initial program 99.1%

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

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

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

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

    if -5.49999999999999975e53 < (*.f64 x y) < -4.79999999999999959e-180 or 1.2000000000000001e-35 < (*.f64 x y) < 3.30000000000000023e48

    1. Initial program 100.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.5%

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

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

    if -4.79999999999999959e-180 < (*.f64 x y) < 1.2000000000000001e-35

    1. Initial program 96.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}{a \cdot b + \left(t \cdot z + x \cdot y\right)} \]
    4. Applied rewrites64.0%

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

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

Alternative 3: 84.3% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := x \cdot y + z \cdot t\\ \mathbf{if}\;z \cdot t \leq -3 \cdot 10^{+62}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;z \cdot t \leq -5.2 \cdot 10^{-32}:\\ \;\;\;\;z \cdot t + a \cdot b\\ \mathbf{elif}\;z \cdot t \leq 1.4 \cdot 10^{+108}:\\ \;\;\;\;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) -3e+62)
     t_1
     (if (<= (* z t) -5.2e-32)
       (+ (* z t) (* a b))
       (if (<= (* z t) 1.4e+108) (+ (* 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) <= -3e+62) {
		tmp = t_1;
	} else if ((z * t) <= -5.2e-32) {
		tmp = (z * t) + (a * b);
	} else if ((z * t) <= 1.4e+108) {
		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) <= (-3d+62)) then
        tmp = t_1
    else if ((z * t) <= (-5.2d-32)) then
        tmp = (z * t) + (a * b)
    else if ((z * t) <= 1.4d+108) 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) <= -3e+62) {
		tmp = t_1;
	} else if ((z * t) <= -5.2e-32) {
		tmp = (z * t) + (a * b);
	} else if ((z * t) <= 1.4e+108) {
		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) <= -3e+62:
		tmp = t_1
	elif (z * t) <= -5.2e-32:
		tmp = (z * t) + (a * b)
	elif (z * t) <= 1.4e+108:
		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) <= -3e+62)
		tmp = t_1;
	elseif (Float64(z * t) <= -5.2e-32)
		tmp = Float64(Float64(z * t) + Float64(a * b));
	elseif (Float64(z * t) <= 1.4e+108)
		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) <= -3e+62)
		tmp = t_1;
	elseif ((z * t) <= -5.2e-32)
		tmp = (z * t) + (a * b);
	elseif ((z * t) <= 1.4e+108)
		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], -3e+62], t$95$1, If[LessEqual[N[(z * t), $MachinePrecision], -5.2e-32], N[(N[(z * t), $MachinePrecision] + N[(a * b), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 1.4e+108], 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 -3 \cdot 10^{+62}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;z \cdot t \leq -5.2 \cdot 10^{-32}:\\
\;\;\;\;z \cdot t + a \cdot b\\

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

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


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

    1. Initial program 97.1%

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

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

    if -3e62 < (*.f64 z t) < -5.1999999999999995e-32

    1. Initial program 94.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 rewrites94.5%

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

    if -5.1999999999999995e-32 < (*.f64 z t) < 1.3999999999999999e108

    1. Initial program 100.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}{t \cdot z} + a \cdot b \]
    4. Applied rewrites90.3%

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

Alternative 4: 84.8% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := x \cdot y + z \cdot t\\ \mathbf{if}\;z \cdot t \leq -8.2 \cdot 10^{+44}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;z \cdot t \leq 1.4 \cdot 10^{+108}:\\ \;\;\;\;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) -8.2e+44)
     t_1
     (if (<= (* z t) 1.4e+108) (+ (* 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) <= -8.2e+44) {
		tmp = t_1;
	} else if ((z * t) <= 1.4e+108) {
		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) <= (-8.2d+44)) then
        tmp = t_1
    else if ((z * t) <= 1.4d+108) 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) <= -8.2e+44) {
		tmp = t_1;
	} else if ((z * t) <= 1.4e+108) {
		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) <= -8.2e+44:
		tmp = t_1
	elif (z * t) <= 1.4e+108:
		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) <= -8.2e+44)
		tmp = t_1;
	elseif (Float64(z * t) <= 1.4e+108)
		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) <= -8.2e+44)
		tmp = t_1;
	elseif ((z * t) <= 1.4e+108)
		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], -8.2e+44], t$95$1, If[LessEqual[N[(z * t), $MachinePrecision], 1.4e+108], 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 -8.2 \cdot 10^{+44}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;z \cdot t \leq 1.4 \cdot 10^{+108}:\\
\;\;\;\;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) < -8.1999999999999993e44 or 1.3999999999999999e108 < (*.f64 z t)

    1. Initial program 96.3%

      \[\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.1999999999999993e44 < (*.f64 z t) < 1.3999999999999999e108

    1. Initial program 100.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}{t \cdot z} + a \cdot b \]
    4. Applied rewrites88.7%

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

Alternative 5: 80.1% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot b \leq -1.9 \cdot 10^{+185}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 6.8 \cdot 10^{+171}:\\ \;\;\;\;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) -1.9e+185)
   (* a b)
   (if (<= (* a b) 6.8e+171) (+ (* 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) <= -1.9e+185) {
		tmp = a * b;
	} else if ((a * b) <= 6.8e+171) {
		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) <= (-1.9d+185)) then
        tmp = a * b
    else if ((a * b) <= 6.8d+171) 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) <= -1.9e+185) {
		tmp = a * b;
	} else if ((a * b) <= 6.8e+171) {
		tmp = (x * y) + (z * t);
	} else {
		tmp = a * b;
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	tmp = 0
	if (a * b) <= -1.9e+185:
		tmp = a * b
	elif (a * b) <= 6.8e+171:
		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) <= -1.9e+185)
		tmp = Float64(a * b);
	elseif (Float64(a * b) <= 6.8e+171)
		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) <= -1.9e+185)
		tmp = a * b;
	elseif ((a * b) <= 6.8e+171)
		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], -1.9e+185], N[(a * b), $MachinePrecision], If[LessEqual[N[(a * b), $MachinePrecision], 6.8e+171], 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 -1.9 \cdot 10^{+185}:\\
\;\;\;\;a \cdot b\\

\mathbf{elif}\;a \cdot b \leq 6.8 \cdot 10^{+171}:\\
\;\;\;\;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) < -1.8999999999999999e185 or 6.8000000000000003e171 < (*.f64 a b)

    1. Initial program 93.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 rewrites23.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 rewrites85.9%

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

    if -1.8999999999999999e185 < (*.f64 a b) < 6.8000000000000003e171

    1. Initial program 100.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 rewrites84.3%

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

Alternative 6: 53.3% accurate, 0.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 a b) < -8.80000000000000002e104 or 1.1499999999999999e-22 < (*.f64 a b)

    1. Initial program 96.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 rewrites41.6%

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

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

    if -8.80000000000000002e104 < (*.f64 a b) < 1.1499999999999999e-22

    1. Initial program 100.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 rewrites90.9%

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

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

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

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

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

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

Reproduce

?
herbie shell --seed 2024321 
(FPCore (x y z t a b)
  :name "Linear.V3:$cdot from linear-1.19.1.3, B"
  :precision binary64
  :pre (TRUE)
  (+ (+ (* x y) (* z t)) (* a b)))