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

Percentage Accurate: 97.7% → 98.8%
Time: 6.4s
Alternatives: 7
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 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: 98.8% accurate, 1.2× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 54.0% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \cdot b \leq -15200:\\
\;\;\;\;a \cdot b\\

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

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

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


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

    1. Initial program 95.4%

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

      \[\leadsto \color{blue}{a \cdot b} \]
    4. Step-by-step derivation
      1. lower-*.f6470.6

        \[\leadsto \color{blue}{a \cdot b} \]
    5. Simplified70.6%

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

    if -15200 < (*.f64 a b) < 4e-289

    1. Initial program 97.6%

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

      \[\leadsto \color{blue}{x \cdot y} \]
    4. Step-by-step derivation
      1. lower-*.f6459.5

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

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

    if 4e-289 < (*.f64 a b) < 1.0000000000000001e69

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{t \cdot z} \]
    4. Step-by-step derivation
      1. lower-*.f6450.0

        \[\leadsto \color{blue}{t \cdot z} \]
    5. Simplified50.0%

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

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

Alternative 3: 86.0% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{fma}\left(a, b, z \cdot t\right)\\ \mathbf{if}\;z \cdot t \leq -4 \cdot 10^{+111}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;z \cdot t \leq 2 \cdot 10^{+29}:\\ \;\;\;\;\mathsf{fma}\left(y, x, 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 a b (* z t))))
   (if (<= (* z t) -4e+111)
     t_1
     (if (<= (* z t) 2e+29) (fma y x (* a b)) t_1))))
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = fma(a, b, (z * t));
	double tmp;
	if ((z * t) <= -4e+111) {
		tmp = t_1;
	} else if ((z * t) <= 2e+29) {
		tmp = fma(y, x, (a * b));
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z, t, a, b)
	t_1 = fma(a, b, Float64(z * t))
	tmp = 0.0
	if (Float64(z * t) <= -4e+111)
		tmp = t_1;
	elseif (Float64(z * t) <= 2e+29)
		tmp = fma(y, x, Float64(a * b));
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(a * b + N[(z * t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * t), $MachinePrecision], -4e+111], t$95$1, If[LessEqual[N[(z * t), $MachinePrecision], 2e+29], N[(y * x + N[(a * b), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 z t) < -3.99999999999999983e111 or 1.99999999999999983e29 < (*.f64 z t)

    1. Initial program 95.9%

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

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

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

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

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

    if -3.99999999999999983e111 < (*.f64 z t) < 1.99999999999999983e29

    1. Initial program 98.1%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{a \cdot b}\right) \]
    6. Step-by-step derivation
      1. lower-*.f6491.0

        \[\leadsto \mathsf{fma}\left(y, x, \color{blue}{a \cdot b}\right) \]
    7. Simplified91.0%

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

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

Alternative 4: 85.9% accurate, 0.6× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 z t) < -3.99999999999999983e111 or 1.99999999999999983e29 < (*.f64 z t)

    1. Initial program 95.9%

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

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

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

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

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

    if -3.99999999999999983e111 < (*.f64 z t) < 1.99999999999999983e29

    1. Initial program 98.1%

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

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

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

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

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

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

Alternative 5: 80.7% accurate, 0.6× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x y) < -7.40000000000000024e110 or 2.90000000000000005e115 < (*.f64 x y)

    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 inf

      \[\leadsto \color{blue}{x \cdot y} \]
    4. Step-by-step derivation
      1. lower-*.f6477.3

        \[\leadsto \color{blue}{x \cdot y} \]
    5. Simplified77.3%

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

    if -7.40000000000000024e110 < (*.f64 x y) < 2.90000000000000005e115

    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 + t \cdot z} \]
    4. Step-by-step derivation
      1. lower-fma.f64N/A

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

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

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

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

Alternative 6: 54.1% accurate, 0.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 a b) < -7.0000000000000003e39 or 1.0000000000000001e69 < (*.f64 a b)

    1. Initial program 95.0%

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

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

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

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

    if -7.0000000000000003e39 < (*.f64 a b) < 1.0000000000000001e69

    1. Initial program 98.7%

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

      \[\leadsto \color{blue}{t \cdot z} \]
    4. Step-by-step derivation
      1. lower-*.f6445.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot b \leq -7 \cdot 10^{+39}:\\ \;\;\;\;a \cdot b\\ \mathbf{elif}\;a \cdot b \leq 10^{+69}:\\ \;\;\;\;z \cdot t\\ \mathbf{else}:\\ \;\;\;\;a \cdot b\\ \end{array} \]
  5. 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 97.3%

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

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

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

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

Reproduce

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