a*x+b*y+c*z+d

Percentage Accurate: 100.0% → 100.0%
Time: 9.1s
Alternatives: 9
Speedup: 1.3×

Specification

?
\[\left(\left(\left(\left(\left(\left(-1 \leq a \land a \leq 1\right) \land \left(-1000 \leq x \land x \leq 1000\right)\right) \land \left(-1 \leq b \land b \leq 1\right)\right) \land \left(-1000 \leq y \land y \leq 1000\right)\right) \land \left(-1 \leq c \land c \leq 1\right)\right) \land \left(-1000 \leq z \land z \leq 1000\right)\right) \land \left(-1000 \leq d \land d \leq 1000\right)\]
\[\begin{array}{l} \\ \left(\left(a \cdot x + b \cdot y\right) + c \cdot z\right) + d \end{array} \]
(FPCore (a x b y c z d)
 :precision binary64
 (+ (+ (+ (* a x) (* b y)) (* c z)) d))
double code(double a, double x, double b, double y, double c, double z, double d) {
	return (((a * x) + (b * y)) + (c * z)) + d;
}
real(8) function code(a, x, b, y, c, z, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: x
    real(8), intent (in) :: b
    real(8), intent (in) :: y
    real(8), intent (in) :: c
    real(8), intent (in) :: z
    real(8), intent (in) :: d
    code = (((a * x) + (b * y)) + (c * z)) + d
end function
public static double code(double a, double x, double b, double y, double c, double z, double d) {
	return (((a * x) + (b * y)) + (c * z)) + d;
}
def code(a, x, b, y, c, z, d):
	return (((a * x) + (b * y)) + (c * z)) + d
function code(a, x, b, y, c, z, d)
	return Float64(Float64(Float64(Float64(a * x) + Float64(b * y)) + Float64(c * z)) + d)
end
function tmp = code(a, x, b, y, c, z, d)
	tmp = (((a * x) + (b * y)) + (c * z)) + d;
end
code[a_, x_, b_, y_, c_, z_, d_] := N[(N[(N[(N[(a * x), $MachinePrecision] + N[(b * y), $MachinePrecision]), $MachinePrecision] + N[(c * z), $MachinePrecision]), $MachinePrecision] + d), $MachinePrecision]
\begin{array}{l}

\\
\left(\left(a \cdot x + b \cdot y\right) + c \cdot z\right) + d
\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: 100.0% accurate, 1.0× speedup?

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

\\
\left(\left(a \cdot x + b \cdot y\right) + c \cdot z\right) + d
\end{array}

Alternative 1: 100.0% accurate, 1.3× speedup?

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

\\
\mathsf{fma}\left(y, b, \mathsf{fma}\left(x, a, \mathsf{fma}\left(z, c, d\right)\right)\right)
\end{array}
Derivation
  1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(y, b, \color{blue}{x \cdot a} + \left(c \cdot z + d\right)\right) \]
    12. lower-fma.f64N/A

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

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

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

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

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

Alternative 2: 95.7% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot x \leq -2 \cdot 10^{-232} \lor \neg \left(a \cdot x \leq 2 \cdot 10^{-284}\right):\\ \;\;\;\;\mathsf{fma}\left(a, x, \mathsf{fma}\left(c, z, d\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, c, \mathsf{fma}\left(y, b, d\right)\right)\\ \end{array} \end{array} \]
(FPCore (a x b y c z d)
 :precision binary64
 (if (or (<= (* a x) -2e-232) (not (<= (* a x) 2e-284)))
   (fma a x (fma c z d))
   (fma z c (fma y b d))))
double code(double a, double x, double b, double y, double c, double z, double d) {
	double tmp;
	if (((a * x) <= -2e-232) || !((a * x) <= 2e-284)) {
		tmp = fma(a, x, fma(c, z, d));
	} else {
		tmp = fma(z, c, fma(y, b, d));
	}
	return tmp;
}
function code(a, x, b, y, c, z, d)
	tmp = 0.0
	if ((Float64(a * x) <= -2e-232) || !(Float64(a * x) <= 2e-284))
		tmp = fma(a, x, fma(c, z, d));
	else
		tmp = fma(z, c, fma(y, b, d));
	end
	return tmp
end
code[a_, x_, b_, y_, c_, z_, d_] := If[Or[LessEqual[N[(a * x), $MachinePrecision], -2e-232], N[Not[LessEqual[N[(a * x), $MachinePrecision], 2e-284]], $MachinePrecision]], N[(a * x + N[(c * z + d), $MachinePrecision]), $MachinePrecision], N[(z * c + N[(y * b + d), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \cdot x \leq -2 \cdot 10^{-232} \lor \neg \left(a \cdot x \leq 2 \cdot 10^{-284}\right):\\
\;\;\;\;\mathsf{fma}\left(a, x, \mathsf{fma}\left(c, z, d\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, c, \mathsf{fma}\left(y, b, d\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 a x) < -2.00000000000000005e-232 or 2.00000000000000007e-284 < (*.f64 a x)

    1. Initial program 99.9%

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

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

        \[\leadsto \color{blue}{\left(d + a \cdot x\right) + c \cdot z} \]
      2. +-commutativeN/A

        \[\leadsto \color{blue}{c \cdot z + \left(d + a \cdot x\right)} \]
      3. *-commutativeN/A

        \[\leadsto \color{blue}{z \cdot c} + \left(d + a \cdot x\right) \]
      4. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(z, c, d + a \cdot x\right)} \]
      5. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(z, c, \color{blue}{a \cdot x + d}\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(z, c, \color{blue}{x \cdot a} + d\right) \]
      7. lower-fma.f6495.4

        \[\leadsto \mathsf{fma}\left(z, c, \color{blue}{\mathsf{fma}\left(x, a, d\right)}\right) \]
    5. Applied rewrites95.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, c, \mathsf{fma}\left(x, a, d\right)\right)} \]
    6. Step-by-step derivation
      1. Applied rewrites95.4%

        \[\leadsto \color{blue}{\mathsf{fma}\left(a, x, \mathsf{fma}\left(c, z, d\right)\right)} \]

      if -2.00000000000000005e-232 < (*.f64 a x) < 2.00000000000000007e-284

      1. Initial program 100.0%

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

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

          \[\leadsto \color{blue}{\left(d + b \cdot y\right) + c \cdot z} \]
        2. +-commutativeN/A

          \[\leadsto \color{blue}{c \cdot z + \left(d + b \cdot y\right)} \]
        3. *-commutativeN/A

          \[\leadsto \color{blue}{z \cdot c} + \left(d + b \cdot y\right) \]
        4. lower-fma.f64N/A

          \[\leadsto \color{blue}{\mathsf{fma}\left(z, c, d + b \cdot y\right)} \]
        5. +-commutativeN/A

          \[\leadsto \mathsf{fma}\left(z, c, \color{blue}{b \cdot y + d}\right) \]
        6. *-commutativeN/A

          \[\leadsto \mathsf{fma}\left(z, c, \color{blue}{y \cdot b} + d\right) \]
        7. lower-fma.f6498.9

          \[\leadsto \mathsf{fma}\left(z, c, \color{blue}{\mathsf{fma}\left(y, b, d\right)}\right) \]
      5. Applied rewrites98.9%

        \[\leadsto \color{blue}{\mathsf{fma}\left(z, c, \mathsf{fma}\left(y, b, d\right)\right)} \]
    7. Recombined 2 regimes into one program.
    8. Final simplification97.8%

      \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot x \leq -2 \cdot 10^{-232} \lor \neg \left(a \cdot x \leq 2 \cdot 10^{-284}\right):\\ \;\;\;\;\mathsf{fma}\left(a, x, \mathsf{fma}\left(c, z, d\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, c, \mathsf{fma}\left(y, b, d\right)\right)\\ \end{array} \]
    9. Add Preprocessing

    Alternative 3: 96.2% accurate, 0.7× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \cdot z \leq -5 \cdot 10^{-220} \lor \neg \left(c \cdot z \leq 2.5 \cdot 10^{-237}\right):\\ \;\;\;\;\mathsf{fma}\left(a, x, \mathsf{fma}\left(c, z, d\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, b, \mathsf{fma}\left(x, a, d\right)\right)\\ \end{array} \end{array} \]
    (FPCore (a x b y c z d)
     :precision binary64
     (if (or (<= (* c z) -5e-220) (not (<= (* c z) 2.5e-237)))
       (fma a x (fma c z d))
       (fma y b (fma x a d))))
    double code(double a, double x, double b, double y, double c, double z, double d) {
    	double tmp;
    	if (((c * z) <= -5e-220) || !((c * z) <= 2.5e-237)) {
    		tmp = fma(a, x, fma(c, z, d));
    	} else {
    		tmp = fma(y, b, fma(x, a, d));
    	}
    	return tmp;
    }
    
    function code(a, x, b, y, c, z, d)
    	tmp = 0.0
    	if ((Float64(c * z) <= -5e-220) || !(Float64(c * z) <= 2.5e-237))
    		tmp = fma(a, x, fma(c, z, d));
    	else
    		tmp = fma(y, b, fma(x, a, d));
    	end
    	return tmp
    end
    
    code[a_, x_, b_, y_, c_, z_, d_] := If[Or[LessEqual[N[(c * z), $MachinePrecision], -5e-220], N[Not[LessEqual[N[(c * z), $MachinePrecision], 2.5e-237]], $MachinePrecision]], N[(a * x + N[(c * z + d), $MachinePrecision]), $MachinePrecision], N[(y * b + N[(x * a + d), $MachinePrecision]), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;c \cdot z \leq -5 \cdot 10^{-220} \lor \neg \left(c \cdot z \leq 2.5 \cdot 10^{-237}\right):\\
    \;\;\;\;\mathsf{fma}\left(a, x, \mathsf{fma}\left(c, z, d\right)\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;\mathsf{fma}\left(y, b, \mathsf{fma}\left(x, a, d\right)\right)\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (*.f64 c z) < -5.0000000000000002e-220 or 2.5000000000000001e-237 < (*.f64 c z)

      1. Initial program 99.9%

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

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

          \[\leadsto \color{blue}{\left(d + a \cdot x\right) + c \cdot z} \]
        2. +-commutativeN/A

          \[\leadsto \color{blue}{c \cdot z + \left(d + a \cdot x\right)} \]
        3. *-commutativeN/A

          \[\leadsto \color{blue}{z \cdot c} + \left(d + a \cdot x\right) \]
        4. lower-fma.f64N/A

          \[\leadsto \color{blue}{\mathsf{fma}\left(z, c, d + a \cdot x\right)} \]
        5. +-commutativeN/A

          \[\leadsto \mathsf{fma}\left(z, c, \color{blue}{a \cdot x + d}\right) \]
        6. *-commutativeN/A

          \[\leadsto \mathsf{fma}\left(z, c, \color{blue}{x \cdot a} + d\right) \]
        7. lower-fma.f6493.5

          \[\leadsto \mathsf{fma}\left(z, c, \color{blue}{\mathsf{fma}\left(x, a, d\right)}\right) \]
      5. Applied rewrites93.5%

        \[\leadsto \color{blue}{\mathsf{fma}\left(z, c, \mathsf{fma}\left(x, a, d\right)\right)} \]
      6. Step-by-step derivation
        1. Applied rewrites93.5%

          \[\leadsto \color{blue}{\mathsf{fma}\left(a, x, \mathsf{fma}\left(c, z, d\right)\right)} \]

        if -5.0000000000000002e-220 < (*.f64 c z) < 2.5000000000000001e-237

        1. Initial program 100.0%

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

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

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

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

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

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

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

            \[\leadsto \mathsf{fma}\left(y, b, \color{blue}{x \cdot a} + d\right) \]
          7. lower-fma.f6499.5

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

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

        \[\leadsto \begin{array}{l} \mathbf{if}\;c \cdot z \leq -5 \cdot 10^{-220} \lor \neg \left(c \cdot z \leq 2.5 \cdot 10^{-237}\right):\\ \;\;\;\;\mathsf{fma}\left(a, x, \mathsf{fma}\left(c, z, d\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, b, \mathsf{fma}\left(x, a, d\right)\right)\\ \end{array} \]
      9. Add Preprocessing

      Alternative 4: 96.2% accurate, 0.7× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \cdot z \leq -5 \cdot 10^{-220}:\\ \;\;\;\;\mathsf{fma}\left(a, x, \mathsf{fma}\left(c, z, d\right)\right)\\ \mathbf{elif}\;c \cdot z \leq 2.5 \cdot 10^{-237}:\\ \;\;\;\;\mathsf{fma}\left(y, b, \mathsf{fma}\left(x, a, d\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, c, \mathsf{fma}\left(x, a, d\right)\right)\\ \end{array} \end{array} \]
      (FPCore (a x b y c z d)
       :precision binary64
       (if (<= (* c z) -5e-220)
         (fma a x (fma c z d))
         (if (<= (* c z) 2.5e-237) (fma y b (fma x a d)) (fma z c (fma x a d)))))
      double code(double a, double x, double b, double y, double c, double z, double d) {
      	double tmp;
      	if ((c * z) <= -5e-220) {
      		tmp = fma(a, x, fma(c, z, d));
      	} else if ((c * z) <= 2.5e-237) {
      		tmp = fma(y, b, fma(x, a, d));
      	} else {
      		tmp = fma(z, c, fma(x, a, d));
      	}
      	return tmp;
      }
      
      function code(a, x, b, y, c, z, d)
      	tmp = 0.0
      	if (Float64(c * z) <= -5e-220)
      		tmp = fma(a, x, fma(c, z, d));
      	elseif (Float64(c * z) <= 2.5e-237)
      		tmp = fma(y, b, fma(x, a, d));
      	else
      		tmp = fma(z, c, fma(x, a, d));
      	end
      	return tmp
      end
      
      code[a_, x_, b_, y_, c_, z_, d_] := If[LessEqual[N[(c * z), $MachinePrecision], -5e-220], N[(a * x + N[(c * z + d), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(c * z), $MachinePrecision], 2.5e-237], N[(y * b + N[(x * a + d), $MachinePrecision]), $MachinePrecision], N[(z * c + N[(x * a + d), $MachinePrecision]), $MachinePrecision]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;c \cdot z \leq -5 \cdot 10^{-220}:\\
      \;\;\;\;\mathsf{fma}\left(a, x, \mathsf{fma}\left(c, z, d\right)\right)\\
      
      \mathbf{elif}\;c \cdot z \leq 2.5 \cdot 10^{-237}:\\
      \;\;\;\;\mathsf{fma}\left(y, b, \mathsf{fma}\left(x, a, d\right)\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;\mathsf{fma}\left(z, c, \mathsf{fma}\left(x, a, d\right)\right)\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 3 regimes
      2. if (*.f64 c z) < -5.0000000000000002e-220

        1. Initial program 100.0%

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

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

            \[\leadsto \color{blue}{\left(d + a \cdot x\right) + c \cdot z} \]
          2. +-commutativeN/A

            \[\leadsto \color{blue}{c \cdot z + \left(d + a \cdot x\right)} \]
          3. *-commutativeN/A

            \[\leadsto \color{blue}{z \cdot c} + \left(d + a \cdot x\right) \]
          4. lower-fma.f64N/A

            \[\leadsto \color{blue}{\mathsf{fma}\left(z, c, d + a \cdot x\right)} \]
          5. +-commutativeN/A

            \[\leadsto \mathsf{fma}\left(z, c, \color{blue}{a \cdot x + d}\right) \]
          6. *-commutativeN/A

            \[\leadsto \mathsf{fma}\left(z, c, \color{blue}{x \cdot a} + d\right) \]
          7. lower-fma.f6492.9

            \[\leadsto \mathsf{fma}\left(z, c, \color{blue}{\mathsf{fma}\left(x, a, d\right)}\right) \]
        5. Applied rewrites92.9%

          \[\leadsto \color{blue}{\mathsf{fma}\left(z, c, \mathsf{fma}\left(x, a, d\right)\right)} \]
        6. Step-by-step derivation
          1. Applied rewrites92.9%

            \[\leadsto \color{blue}{\mathsf{fma}\left(a, x, \mathsf{fma}\left(c, z, d\right)\right)} \]

          if -5.0000000000000002e-220 < (*.f64 c z) < 2.5000000000000001e-237

          1. Initial program 100.0%

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

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

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

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

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

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

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

              \[\leadsto \mathsf{fma}\left(y, b, \color{blue}{x \cdot a} + d\right) \]
            7. lower-fma.f6499.5

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

            \[\leadsto \color{blue}{\mathsf{fma}\left(y, b, \mathsf{fma}\left(x, a, d\right)\right)} \]

          if 2.5000000000000001e-237 < (*.f64 c z)

          1. Initial program 99.9%

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

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

              \[\leadsto \color{blue}{\left(d + a \cdot x\right) + c \cdot z} \]
            2. +-commutativeN/A

              \[\leadsto \color{blue}{c \cdot z + \left(d + a \cdot x\right)} \]
            3. *-commutativeN/A

              \[\leadsto \color{blue}{z \cdot c} + \left(d + a \cdot x\right) \]
            4. lower-fma.f64N/A

              \[\leadsto \color{blue}{\mathsf{fma}\left(z, c, d + a \cdot x\right)} \]
            5. +-commutativeN/A

              \[\leadsto \mathsf{fma}\left(z, c, \color{blue}{a \cdot x + d}\right) \]
            6. *-commutativeN/A

              \[\leadsto \mathsf{fma}\left(z, c, \color{blue}{x \cdot a} + d\right) \]
            7. lower-fma.f6493.8

              \[\leadsto \mathsf{fma}\left(z, c, \color{blue}{\mathsf{fma}\left(x, a, d\right)}\right) \]
          5. Applied rewrites93.8%

            \[\leadsto \color{blue}{\mathsf{fma}\left(z, c, \mathsf{fma}\left(x, a, d\right)\right)} \]
        7. Recombined 3 regimes into one program.
        8. Final simplification97.7%

          \[\leadsto \begin{array}{l} \mathbf{if}\;c \cdot z \leq -5 \cdot 10^{-220}:\\ \;\;\;\;\mathsf{fma}\left(a, x, \mathsf{fma}\left(c, z, d\right)\right)\\ \mathbf{elif}\;c \cdot z \leq 2.5 \cdot 10^{-237}:\\ \;\;\;\;\mathsf{fma}\left(y, b, \mathsf{fma}\left(x, a, d\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, c, \mathsf{fma}\left(x, a, d\right)\right)\\ \end{array} \]
        9. Add Preprocessing

        Alternative 5: 77.0% accurate, 0.9× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot x \leq -5 \cdot 10^{-119} \lor \neg \left(a \cdot x \leq 5 \cdot 10^{-74}\right):\\ \;\;\;\;a \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(b, y, d\right)\\ \end{array} \end{array} \]
        (FPCore (a x b y c z d)
         :precision binary64
         (if (or (<= (* a x) -5e-119) (not (<= (* a x) 5e-74))) (* a x) (fma b y d)))
        double code(double a, double x, double b, double y, double c, double z, double d) {
        	double tmp;
        	if (((a * x) <= -5e-119) || !((a * x) <= 5e-74)) {
        		tmp = a * x;
        	} else {
        		tmp = fma(b, y, d);
        	}
        	return tmp;
        }
        
        function code(a, x, b, y, c, z, d)
        	tmp = 0.0
        	if ((Float64(a * x) <= -5e-119) || !(Float64(a * x) <= 5e-74))
        		tmp = Float64(a * x);
        	else
        		tmp = fma(b, y, d);
        	end
        	return tmp
        end
        
        code[a_, x_, b_, y_, c_, z_, d_] := If[Or[LessEqual[N[(a * x), $MachinePrecision], -5e-119], N[Not[LessEqual[N[(a * x), $MachinePrecision], 5e-74]], $MachinePrecision]], N[(a * x), $MachinePrecision], N[(b * y + d), $MachinePrecision]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;a \cdot x \leq -5 \cdot 10^{-119} \lor \neg \left(a \cdot x \leq 5 \cdot 10^{-74}\right):\\
        \;\;\;\;a \cdot x\\
        
        \mathbf{else}:\\
        \;\;\;\;\mathsf{fma}\left(b, y, d\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if (*.f64 a x) < -4.99999999999999993e-119 or 4.99999999999999998e-74 < (*.f64 a x)

          1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \mathsf{fma}\left(y, b, \color{blue}{x \cdot a} + \left(c \cdot z + d\right)\right) \]
            12. lower-fma.f64N/A

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

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

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

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

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

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

              \[\leadsto \color{blue}{a \cdot x} \]
          7. Applied rewrites84.4%

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

          if -4.99999999999999993e-119 < (*.f64 a x) < 4.99999999999999998e-74

          1. Initial program 100.0%

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

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

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

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

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

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

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

              \[\leadsto \mathsf{fma}\left(y, b, \color{blue}{x \cdot a} + d\right) \]
            7. lower-fma.f6486.1

              \[\leadsto \mathsf{fma}\left(y, b, \color{blue}{\mathsf{fma}\left(x, a, d\right)}\right) \]
          5. Applied rewrites86.1%

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

            \[\leadsto d + \color{blue}{b \cdot y} \]
          7. Step-by-step derivation
            1. Applied rewrites81.0%

              \[\leadsto \mathsf{fma}\left(b, \color{blue}{y}, d\right) \]
          8. Recombined 2 regimes into one program.
          9. Final simplification81.2%

            \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot x \leq -5 \cdot 10^{-119} \lor \neg \left(a \cdot x \leq 5 \cdot 10^{-74}\right):\\ \;\;\;\;a \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(b, y, d\right)\\ \end{array} \]
          10. Add Preprocessing

          Alternative 6: 23.9% accurate, 0.9× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \cdot z \leq -5 \cdot 10^{-220} \lor \neg \left(c \cdot z \leq 5 \cdot 10^{-237}\right):\\ \;\;\;\;z \cdot c\\ \mathbf{else}:\\ \;\;\;\;b \cdot y\\ \end{array} \end{array} \]
          (FPCore (a x b y c z d)
           :precision binary64
           (if (or (<= (* c z) -5e-220) (not (<= (* c z) 5e-237))) (* z c) (* b y)))
          double code(double a, double x, double b, double y, double c, double z, double d) {
          	double tmp;
          	if (((c * z) <= -5e-220) || !((c * z) <= 5e-237)) {
          		tmp = z * c;
          	} else {
          		tmp = b * y;
          	}
          	return tmp;
          }
          
          real(8) function code(a, x, b, y, c, z, d)
              real(8), intent (in) :: a
              real(8), intent (in) :: x
              real(8), intent (in) :: b
              real(8), intent (in) :: y
              real(8), intent (in) :: c
              real(8), intent (in) :: z
              real(8), intent (in) :: d
              real(8) :: tmp
              if (((c * z) <= (-5d-220)) .or. (.not. ((c * z) <= 5d-237))) then
                  tmp = z * c
              else
                  tmp = b * y
              end if
              code = tmp
          end function
          
          public static double code(double a, double x, double b, double y, double c, double z, double d) {
          	double tmp;
          	if (((c * z) <= -5e-220) || !((c * z) <= 5e-237)) {
          		tmp = z * c;
          	} else {
          		tmp = b * y;
          	}
          	return tmp;
          }
          
          def code(a, x, b, y, c, z, d):
          	tmp = 0
          	if ((c * z) <= -5e-220) or not ((c * z) <= 5e-237):
          		tmp = z * c
          	else:
          		tmp = b * y
          	return tmp
          
          function code(a, x, b, y, c, z, d)
          	tmp = 0.0
          	if ((Float64(c * z) <= -5e-220) || !(Float64(c * z) <= 5e-237))
          		tmp = Float64(z * c);
          	else
          		tmp = Float64(b * y);
          	end
          	return tmp
          end
          
          function tmp_2 = code(a, x, b, y, c, z, d)
          	tmp = 0.0;
          	if (((c * z) <= -5e-220) || ~(((c * z) <= 5e-237)))
          		tmp = z * c;
          	else
          		tmp = b * y;
          	end
          	tmp_2 = tmp;
          end
          
          code[a_, x_, b_, y_, c_, z_, d_] := If[Or[LessEqual[N[(c * z), $MachinePrecision], -5e-220], N[Not[LessEqual[N[(c * z), $MachinePrecision], 5e-237]], $MachinePrecision]], N[(z * c), $MachinePrecision], N[(b * y), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;c \cdot z \leq -5 \cdot 10^{-220} \lor \neg \left(c \cdot z \leq 5 \cdot 10^{-237}\right):\\
          \;\;\;\;z \cdot c\\
          
          \mathbf{else}:\\
          \;\;\;\;b \cdot y\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if (*.f64 c z) < -5.0000000000000002e-220 or 5.0000000000000002e-237 < (*.f64 c z)

            1. Initial program 99.9%

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

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

                \[\leadsto \color{blue}{z \cdot c} \]
              2. lower-*.f6442.0

                \[\leadsto \color{blue}{z \cdot c} \]
            5. Applied rewrites42.0%

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

            if -5.0000000000000002e-220 < (*.f64 c z) < 5.0000000000000002e-237

            1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \mathsf{fma}\left(y, b, \color{blue}{x \cdot a} + \left(c \cdot z + d\right)\right) \]
              12. lower-fma.f64N/A

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

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

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

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

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

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

                \[\leadsto \color{blue}{b \cdot y} \]
            7. Applied rewrites18.4%

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

            \[\leadsto \begin{array}{l} \mathbf{if}\;c \cdot z \leq -5 \cdot 10^{-220} \lor \neg \left(c \cdot z \leq 5 \cdot 10^{-237}\right):\\ \;\;\;\;z \cdot c\\ \mathbf{else}:\\ \;\;\;\;b \cdot y\\ \end{array} \]
          5. Add Preprocessing

          Alternative 7: 23.3% accurate, 0.9× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \cdot x \leq -6 \cdot 10^{-233} \lor \neg \left(a \cdot x \leq 7 \cdot 10^{-271}\right):\\ \;\;\;\;a \cdot x\\ \mathbf{else}:\\ \;\;\;\;b \cdot y\\ \end{array} \end{array} \]
          (FPCore (a x b y c z d)
           :precision binary64
           (if (or (<= (* a x) -6e-233) (not (<= (* a x) 7e-271))) (* a x) (* b y)))
          double code(double a, double x, double b, double y, double c, double z, double d) {
          	double tmp;
          	if (((a * x) <= -6e-233) || !((a * x) <= 7e-271)) {
          		tmp = a * x;
          	} else {
          		tmp = b * y;
          	}
          	return tmp;
          }
          
          real(8) function code(a, x, b, y, c, z, d)
              real(8), intent (in) :: a
              real(8), intent (in) :: x
              real(8), intent (in) :: b
              real(8), intent (in) :: y
              real(8), intent (in) :: c
              real(8), intent (in) :: z
              real(8), intent (in) :: d
              real(8) :: tmp
              if (((a * x) <= (-6d-233)) .or. (.not. ((a * x) <= 7d-271))) then
                  tmp = a * x
              else
                  tmp = b * y
              end if
              code = tmp
          end function
          
          public static double code(double a, double x, double b, double y, double c, double z, double d) {
          	double tmp;
          	if (((a * x) <= -6e-233) || !((a * x) <= 7e-271)) {
          		tmp = a * x;
          	} else {
          		tmp = b * y;
          	}
          	return tmp;
          }
          
          def code(a, x, b, y, c, z, d):
          	tmp = 0
          	if ((a * x) <= -6e-233) or not ((a * x) <= 7e-271):
          		tmp = a * x
          	else:
          		tmp = b * y
          	return tmp
          
          function code(a, x, b, y, c, z, d)
          	tmp = 0.0
          	if ((Float64(a * x) <= -6e-233) || !(Float64(a * x) <= 7e-271))
          		tmp = Float64(a * x);
          	else
          		tmp = Float64(b * y);
          	end
          	return tmp
          end
          
          function tmp_2 = code(a, x, b, y, c, z, d)
          	tmp = 0.0;
          	if (((a * x) <= -6e-233) || ~(((a * x) <= 7e-271)))
          		tmp = a * x;
          	else
          		tmp = b * y;
          	end
          	tmp_2 = tmp;
          end
          
          code[a_, x_, b_, y_, c_, z_, d_] := If[Or[LessEqual[N[(a * x), $MachinePrecision], -6e-233], N[Not[LessEqual[N[(a * x), $MachinePrecision], 7e-271]], $MachinePrecision]], N[(a * x), $MachinePrecision], N[(b * y), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;a \cdot x \leq -6 \cdot 10^{-233} \lor \neg \left(a \cdot x \leq 7 \cdot 10^{-271}\right):\\
          \;\;\;\;a \cdot x\\
          
          \mathbf{else}:\\
          \;\;\;\;b \cdot y\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if (*.f64 a x) < -5.99999999999999997e-233 or 6.9999999999999999e-271 < (*.f64 a x)

            1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \mathsf{fma}\left(y, b, \color{blue}{x \cdot a} + \left(c \cdot z + d\right)\right) \]
              12. lower-fma.f64N/A

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

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

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

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

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

              \[\leadsto \color{blue}{a \cdot x} \]
            6. Step-by-step derivation
              1. lower-*.f6431.2

                \[\leadsto \color{blue}{a \cdot x} \]
            7. Applied rewrites31.2%

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

            if -5.99999999999999997e-233 < (*.f64 a x) < 6.9999999999999999e-271

            1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \mathsf{fma}\left(y, b, \color{blue}{x \cdot a} + \left(c \cdot z + d\right)\right) \]
              12. lower-fma.f64N/A

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

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

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

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

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

              \[\leadsto \color{blue}{b \cdot y} \]
            6. Step-by-step derivation
              1. lower-*.f6418.7

                \[\leadsto \color{blue}{b \cdot y} \]
            7. Applied rewrites18.7%

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

            \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot x \leq -6 \cdot 10^{-233} \lor \neg \left(a \cdot x \leq 7 \cdot 10^{-271}\right):\\ \;\;\;\;a \cdot x\\ \mathbf{else}:\\ \;\;\;\;b \cdot y\\ \end{array} \]
          5. Add Preprocessing

          Alternative 8: 90.3% accurate, 1.0× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -1 \cdot 10^{-54} \lor \neg \left(b \leq 1.5 \cdot 10^{-96}\right):\\ \;\;\;\;\mathsf{fma}\left(b, y, d\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a, x, \mathsf{fma}\left(c, z, d\right)\right)\\ \end{array} \end{array} \]
          (FPCore (a x b y c z d)
           :precision binary64
           (if (or (<= b -1e-54) (not (<= b 1.5e-96)))
             (fma b y d)
             (fma a x (fma c z d))))
          double code(double a, double x, double b, double y, double c, double z, double d) {
          	double tmp;
          	if ((b <= -1e-54) || !(b <= 1.5e-96)) {
          		tmp = fma(b, y, d);
          	} else {
          		tmp = fma(a, x, fma(c, z, d));
          	}
          	return tmp;
          }
          
          function code(a, x, b, y, c, z, d)
          	tmp = 0.0
          	if ((b <= -1e-54) || !(b <= 1.5e-96))
          		tmp = fma(b, y, d);
          	else
          		tmp = fma(a, x, fma(c, z, d));
          	end
          	return tmp
          end
          
          code[a_, x_, b_, y_, c_, z_, d_] := If[Or[LessEqual[b, -1e-54], N[Not[LessEqual[b, 1.5e-96]], $MachinePrecision]], N[(b * y + d), $MachinePrecision], N[(a * x + N[(c * z + d), $MachinePrecision]), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;b \leq -1 \cdot 10^{-54} \lor \neg \left(b \leq 1.5 \cdot 10^{-96}\right):\\
          \;\;\;\;\mathsf{fma}\left(b, y, d\right)\\
          
          \mathbf{else}:\\
          \;\;\;\;\mathsf{fma}\left(a, x, \mathsf{fma}\left(c, z, d\right)\right)\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if b < -1e-54 or 1.5e-96 < b

            1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

              \[\leadsto d + \color{blue}{b \cdot y} \]
            7. Step-by-step derivation
              1. Applied rewrites78.5%

                \[\leadsto \mathsf{fma}\left(b, \color{blue}{y}, d\right) \]

              if -1e-54 < b < 1.5e-96

              1. Initial program 100.0%

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

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

                  \[\leadsto \color{blue}{\left(d + a \cdot x\right) + c \cdot z} \]
                2. +-commutativeN/A

                  \[\leadsto \color{blue}{c \cdot z + \left(d + a \cdot x\right)} \]
                3. *-commutativeN/A

                  \[\leadsto \color{blue}{z \cdot c} + \left(d + a \cdot x\right) \]
                4. lower-fma.f64N/A

                  \[\leadsto \color{blue}{\mathsf{fma}\left(z, c, d + a \cdot x\right)} \]
                5. +-commutativeN/A

                  \[\leadsto \mathsf{fma}\left(z, c, \color{blue}{a \cdot x + d}\right) \]
                6. *-commutativeN/A

                  \[\leadsto \mathsf{fma}\left(z, c, \color{blue}{x \cdot a} + d\right) \]
                7. lower-fma.f6494.3

                  \[\leadsto \mathsf{fma}\left(z, c, \color{blue}{\mathsf{fma}\left(x, a, d\right)}\right) \]
              5. Applied rewrites94.3%

                \[\leadsto \color{blue}{\mathsf{fma}\left(z, c, \mathsf{fma}\left(x, a, d\right)\right)} \]
              6. Step-by-step derivation
                1. Applied rewrites94.3%

                  \[\leadsto \color{blue}{\mathsf{fma}\left(a, x, \mathsf{fma}\left(c, z, d\right)\right)} \]
              7. Recombined 2 regimes into one program.
              8. Final simplification90.5%

                \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1 \cdot 10^{-54} \lor \neg \left(b \leq 1.5 \cdot 10^{-96}\right):\\ \;\;\;\;\mathsf{fma}\left(b, y, d\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(a, x, \mathsf{fma}\left(c, z, d\right)\right)\\ \end{array} \]
              9. Add Preprocessing

              Alternative 9: 15.8% accurate, 4.2× speedup?

              \[\begin{array}{l} \\ a \cdot x \end{array} \]
              (FPCore (a x b y c z d) :precision binary64 (* a x))
              double code(double a, double x, double b, double y, double c, double z, double d) {
              	return a * x;
              }
              
              real(8) function code(a, x, b, y, c, z, d)
                  real(8), intent (in) :: a
                  real(8), intent (in) :: x
                  real(8), intent (in) :: b
                  real(8), intent (in) :: y
                  real(8), intent (in) :: c
                  real(8), intent (in) :: z
                  real(8), intent (in) :: d
                  code = a * x
              end function
              
              public static double code(double a, double x, double b, double y, double c, double z, double d) {
              	return a * x;
              }
              
              def code(a, x, b, y, c, z, d):
              	return a * x
              
              function code(a, x, b, y, c, z, d)
              	return Float64(a * x)
              end
              
              function tmp = code(a, x, b, y, c, z, d)
              	tmp = a * x;
              end
              
              code[a_, x_, b_, y_, c_, z_, d_] := N[(a * x), $MachinePrecision]
              
              \begin{array}{l}
              
              \\
              a \cdot x
              \end{array}
              
              Derivation
              1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto \mathsf{fma}\left(y, b, \color{blue}{x \cdot a} + \left(c \cdot z + d\right)\right) \]
                12. lower-fma.f64N/A

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

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

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

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

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

                \[\leadsto \color{blue}{a \cdot x} \]
              6. Step-by-step derivation
                1. lower-*.f6413.3

                  \[\leadsto \color{blue}{a \cdot x} \]
              7. Applied rewrites13.3%

                \[\leadsto \color{blue}{a \cdot x} \]
              8. Add Preprocessing

              Reproduce

              ?
              herbie shell --seed 1 
              (FPCore (a x b y c z d)
                :name "a*x+b*y+c*z+d"
                :precision binary64
                :pre (and (and (and (and (and (and (and (<= -1.0 a) (<= a 1.0)) (and (<= -1000.0 x) (<= x 1000.0))) (and (<= -1.0 b) (<= b 1.0))) (and (<= -1000.0 y) (<= y 1000.0))) (and (<= -1.0 c) (<= c 1.0))) (and (<= -1000.0 z) (<= z 1000.0))) (and (<= -1000.0 d) (<= d 1000.0)))
                (+ (+ (+ (* a x) (* b y)) (* c z)) d))