Main:bigenough2 from A

Percentage Accurate: 100.0% → 100.0%
Time: 4.7s
Alternatives: 5
Speedup: 1.2×

Specification

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

\\
x + y \cdot \left(z + x\right)
\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 5 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} \\ x + y \cdot \left(z + x\right) \end{array} \]
(FPCore (x y z) :precision binary64 (+ x (* y (+ z x))))
double code(double x, double y, double z) {
	return x + (y * (z + x));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x + (y * (z + x))
end function
public static double code(double x, double y, double z) {
	return x + (y * (z + x));
}
def code(x, y, z):
	return x + (y * (z + x))
function code(x, y, z)
	return Float64(x + Float64(y * Float64(z + x)))
end
function tmp = code(x, y, z)
	tmp = x + (y * (z + x));
end
code[x_, y_, z_] := N[(x + N[(y * N[(z + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x + y \cdot \left(z + x\right)
\end{array}

Alternative 1: 100.0% accurate, 1.2× speedup?

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(z + x\right) \cdot y} + x \]
    5. lower-fma.f64100.0

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

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

Alternative 2: 82.2% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(z + x\right) \cdot y\\ \mathbf{if}\;y \leq -1.4:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq -3.6 \cdot 10^{-40}:\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \mathbf{elif}\;y \leq -1.85 \cdot 10^{-51}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;y \leq 9 \cdot 10^{-115}:\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \mathbf{elif}\;y \leq 1.02 \cdot 10^{-81}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;y \leq 7.4 \cdot 10^{-56}:\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \mathbf{elif}\;y \leq 1.9 \cdot 10^{+264}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* (+ z x) y)))
   (if (<= y -1.4)
     t_0
     (if (<= y -3.6e-40)
       (fma y x x)
       (if (<= y -1.85e-51)
         (* z y)
         (if (<= y 9e-115)
           (fma y x x)
           (if (<= y 1.02e-81)
             (* z y)
             (if (<= y 7.4e-56)
               (fma y x x)
               (if (<= y 1.9e+264) t_0 (* y x))))))))))
double code(double x, double y, double z) {
	double t_0 = (z + x) * y;
	double tmp;
	if (y <= -1.4) {
		tmp = t_0;
	} else if (y <= -3.6e-40) {
		tmp = fma(y, x, x);
	} else if (y <= -1.85e-51) {
		tmp = z * y;
	} else if (y <= 9e-115) {
		tmp = fma(y, x, x);
	} else if (y <= 1.02e-81) {
		tmp = z * y;
	} else if (y <= 7.4e-56) {
		tmp = fma(y, x, x);
	} else if (y <= 1.9e+264) {
		tmp = t_0;
	} else {
		tmp = y * x;
	}
	return tmp;
}
function code(x, y, z)
	t_0 = Float64(Float64(z + x) * y)
	tmp = 0.0
	if (y <= -1.4)
		tmp = t_0;
	elseif (y <= -3.6e-40)
		tmp = fma(y, x, x);
	elseif (y <= -1.85e-51)
		tmp = Float64(z * y);
	elseif (y <= 9e-115)
		tmp = fma(y, x, x);
	elseif (y <= 1.02e-81)
		tmp = Float64(z * y);
	elseif (y <= 7.4e-56)
		tmp = fma(y, x, x);
	elseif (y <= 1.9e+264)
		tmp = t_0;
	else
		tmp = Float64(y * x);
	end
	return tmp
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(z + x), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -1.4], t$95$0, If[LessEqual[y, -3.6e-40], N[(y * x + x), $MachinePrecision], If[LessEqual[y, -1.85e-51], N[(z * y), $MachinePrecision], If[LessEqual[y, 9e-115], N[(y * x + x), $MachinePrecision], If[LessEqual[y, 1.02e-81], N[(z * y), $MachinePrecision], If[LessEqual[y, 7.4e-56], N[(y * x + x), $MachinePrecision], If[LessEqual[y, 1.9e+264], t$95$0, N[(y * x), $MachinePrecision]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(z + x\right) \cdot y\\
\mathbf{if}\;y \leq -1.4:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq -3.6 \cdot 10^{-40}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\

\mathbf{elif}\;y \leq -1.85 \cdot 10^{-51}:\\
\;\;\;\;z \cdot y\\

\mathbf{elif}\;y \leq 9 \cdot 10^{-115}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\

\mathbf{elif}\;y \leq 1.02 \cdot 10^{-81}:\\
\;\;\;\;z \cdot y\\

\mathbf{elif}\;y \leq 7.4 \cdot 10^{-56}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\

\mathbf{elif}\;y \leq 1.9 \cdot 10^{+264}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < -1.3999999999999999 or 7.4000000000000004e-56 < y < 1.9000000000000001e264

    1. Initial program 100.0%

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

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

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

        \[\leadsto x + y \cdot \color{blue}{\left(z + x\right)} \]
      4. distribute-rgt-inN/A

        \[\leadsto x + \color{blue}{\left(z \cdot y + x \cdot y\right)} \]
      5. associate-+r+N/A

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(y \cdot \left(-1 \cdot x + -1 \cdot z\right)\right)} \]
    6. Step-by-step derivation
      1. distribute-lft-inN/A

        \[\leadsto -1 \cdot \left(y \cdot \color{blue}{\left(-1 \cdot \left(x + z\right)\right)}\right) \]
      2. associate-*r*N/A

        \[\leadsto \color{blue}{\left(-1 \cdot y\right) \cdot \left(-1 \cdot \left(x + z\right)\right)} \]
      3. mul-1-negN/A

        \[\leadsto \left(-1 \cdot y\right) \cdot \color{blue}{\left(\mathsf{neg}\left(\left(x + z\right)\right)\right)} \]
      4. distribute-rgt-neg-outN/A

        \[\leadsto \color{blue}{\mathsf{neg}\left(\left(-1 \cdot y\right) \cdot \left(x + z\right)\right)} \]
      5. distribute-lft-neg-inN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(-1 \cdot y\right)\right) \cdot \left(x + z\right)} \]
      6. mul-1-negN/A

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(y\right)\right)}\right)\right) \cdot \left(x + z\right) \]
      7. remove-double-negN/A

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

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

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

        \[\leadsto \color{blue}{\left(z + x\right)} \cdot y \]
      11. lower-+.f6497.9

        \[\leadsto \color{blue}{\left(z + x\right)} \cdot y \]
    7. Applied rewrites97.9%

      \[\leadsto \color{blue}{\left(z + x\right) \cdot y} \]

    if -1.3999999999999999 < y < -3.6e-40 or -1.84999999999999987e-51 < y < 9.00000000000000046e-115 or 1.01999999999999998e-81 < y < 7.4000000000000004e-56

    1. Initial program 100.0%

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

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

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

        \[\leadsto \color{blue}{\left(y + 1\right)} \cdot x \]
      3. distribute-lft1-inN/A

        \[\leadsto \color{blue}{y \cdot x + x} \]
      4. lower-fma.f6481.1

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

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

    if -3.6e-40 < y < -1.84999999999999987e-51 or 9.00000000000000046e-115 < y < 1.01999999999999998e-81

    1. Initial program 100.0%

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

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

        \[\leadsto \color{blue}{z \cdot y} \]
      2. lower-*.f6475.4

        \[\leadsto \color{blue}{z \cdot y} \]
    5. Applied rewrites75.4%

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

    if 1.9000000000000001e264 < y

    1. Initial program 100.0%

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

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

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

        \[\leadsto \color{blue}{\left(y + 1\right)} \cdot x \]
      3. distribute-lft1-inN/A

        \[\leadsto \color{blue}{y \cdot x + x} \]
      4. lower-fma.f6450.8

        \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, x\right)} \]
    5. Applied rewrites50.8%

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

      \[\leadsto x \cdot \color{blue}{y} \]
    7. Step-by-step derivation
      1. Applied rewrites50.8%

        \[\leadsto y \cdot \color{blue}{x} \]
    8. Recombined 4 regimes into one program.
    9. Final simplification88.0%

      \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.4:\\ \;\;\;\;\left(z + x\right) \cdot y\\ \mathbf{elif}\;y \leq -3.6 \cdot 10^{-40}:\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \mathbf{elif}\;y \leq -1.85 \cdot 10^{-51}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;y \leq 9 \cdot 10^{-115}:\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \mathbf{elif}\;y \leq 1.02 \cdot 10^{-81}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;y \leq 7.4 \cdot 10^{-56}:\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \mathbf{elif}\;y \leq 1.9 \cdot 10^{+264}:\\ \;\;\;\;\left(z + x\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
    10. Add Preprocessing

    Alternative 3: 48.1% accurate, 0.3× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -9.8 \cdot 10^{+72} \lor \neg \left(z \leq -8.6 \cdot 10^{-223} \lor \neg \left(z \leq -1.3 \cdot 10^{-236} \lor \neg \left(z \leq 4.6 \cdot 10^{-186} \lor \neg \left(z \leq 6.4 \cdot 10^{+307}\right)\right)\right)\right):\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \end{array} \]
    (FPCore (x y z)
     :precision binary64
     (if (or (<= z -9.8e+72)
             (not
              (or (<= z -8.6e-223)
                  (not
                   (or (<= z -1.3e-236)
                       (not (or (<= z 4.6e-186) (not (<= z 6.4e+307)))))))))
       (* z y)
       (* y x)))
    double code(double x, double y, double z) {
    	double tmp;
    	if ((z <= -9.8e+72) || !((z <= -8.6e-223) || !((z <= -1.3e-236) || !((z <= 4.6e-186) || !(z <= 6.4e+307))))) {
    		tmp = z * y;
    	} else {
    		tmp = y * x;
    	}
    	return tmp;
    }
    
    real(8) function code(x, y, z)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        real(8), intent (in) :: z
        real(8) :: tmp
        if ((z <= (-9.8d+72)) .or. (.not. (z <= (-8.6d-223)) .or. (.not. (z <= (-1.3d-236)) .or. (.not. (z <= 4.6d-186) .or. (.not. (z <= 6.4d+307)))))) then
            tmp = z * y
        else
            tmp = y * x
        end if
        code = tmp
    end function
    
    public static double code(double x, double y, double z) {
    	double tmp;
    	if ((z <= -9.8e+72) || !((z <= -8.6e-223) || !((z <= -1.3e-236) || !((z <= 4.6e-186) || !(z <= 6.4e+307))))) {
    		tmp = z * y;
    	} else {
    		tmp = y * x;
    	}
    	return tmp;
    }
    
    def code(x, y, z):
    	tmp = 0
    	if (z <= -9.8e+72) or not ((z <= -8.6e-223) or not ((z <= -1.3e-236) or not ((z <= 4.6e-186) or not (z <= 6.4e+307)))):
    		tmp = z * y
    	else:
    		tmp = y * x
    	return tmp
    
    function code(x, y, z)
    	tmp = 0.0
    	if ((z <= -9.8e+72) || !((z <= -8.6e-223) || !((z <= -1.3e-236) || !((z <= 4.6e-186) || !(z <= 6.4e+307)))))
    		tmp = Float64(z * y);
    	else
    		tmp = Float64(y * x);
    	end
    	return tmp
    end
    
    function tmp_2 = code(x, y, z)
    	tmp = 0.0;
    	if ((z <= -9.8e+72) || ~(((z <= -8.6e-223) || ~(((z <= -1.3e-236) || ~(((z <= 4.6e-186) || ~((z <= 6.4e+307)))))))))
    		tmp = z * y;
    	else
    		tmp = y * x;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_, y_, z_] := If[Or[LessEqual[z, -9.8e+72], N[Not[Or[LessEqual[z, -8.6e-223], N[Not[Or[LessEqual[z, -1.3e-236], N[Not[Or[LessEqual[z, 4.6e-186], N[Not[LessEqual[z, 6.4e+307]], $MachinePrecision]]], $MachinePrecision]]], $MachinePrecision]]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(y * x), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;z \leq -9.8 \cdot 10^{+72} \lor \neg \left(z \leq -8.6 \cdot 10^{-223} \lor \neg \left(z \leq -1.3 \cdot 10^{-236} \lor \neg \left(z \leq 4.6 \cdot 10^{-186} \lor \neg \left(z \leq 6.4 \cdot 10^{+307}\right)\right)\right)\right):\\
    \;\;\;\;z \cdot y\\
    
    \mathbf{else}:\\
    \;\;\;\;y \cdot x\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if z < -9.80000000000000012e72 or -8.5999999999999998e-223 < z < -1.3e-236 or 4.6000000000000002e-186 < z < 6.40000000000000011e307

      1. Initial program 100.0%

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

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

          \[\leadsto \color{blue}{z \cdot y} \]
        2. lower-*.f6460.3

          \[\leadsto \color{blue}{z \cdot y} \]
      5. Applied rewrites60.3%

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

      if -9.80000000000000012e72 < z < -8.5999999999999998e-223 or -1.3e-236 < z < 4.6000000000000002e-186 or 6.40000000000000011e307 < z

      1. Initial program 100.0%

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

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

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

          \[\leadsto \color{blue}{\left(y + 1\right)} \cdot x \]
        3. distribute-lft1-inN/A

          \[\leadsto \color{blue}{y \cdot x + x} \]
        4. lower-fma.f6491.6

          \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, x\right)} \]
      5. Applied rewrites91.6%

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

        \[\leadsto x \cdot \color{blue}{y} \]
      7. Step-by-step derivation
        1. Applied rewrites42.4%

          \[\leadsto y \cdot \color{blue}{x} \]
      8. Recombined 2 regimes into one program.
      9. Final simplification53.3%

        \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -9.8 \cdot 10^{+72} \lor \neg \left(z \leq -8.6 \cdot 10^{-223} \lor \neg \left(z \leq -1.3 \cdot 10^{-236} \lor \neg \left(z \leq 4.6 \cdot 10^{-186} \lor \neg \left(z \leq 6.4 \cdot 10^{+307}\right)\right)\right)\right):\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
      10. Add Preprocessing

      Alternative 4: 73.0% accurate, 0.3× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -5.1 \cdot 10^{+82}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;z \leq 3800000:\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \mathbf{elif}\;z \leq 1.1 \cdot 10^{+62}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;z \leq 3.5 \cdot 10^{+103}:\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \mathbf{elif}\;z \leq 7 \cdot 10^{+290}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \end{array} \]
      (FPCore (x y z)
       :precision binary64
       (if (<= z -5.1e+82)
         (* z y)
         (if (<= z 3800000.0)
           (fma y x x)
           (if (<= z 1.1e+62)
             (* z y)
             (if (<= z 3.5e+103) (fma y x x) (if (<= z 7e+290) (* z y) (* y x)))))))
      double code(double x, double y, double z) {
      	double tmp;
      	if (z <= -5.1e+82) {
      		tmp = z * y;
      	} else if (z <= 3800000.0) {
      		tmp = fma(y, x, x);
      	} else if (z <= 1.1e+62) {
      		tmp = z * y;
      	} else if (z <= 3.5e+103) {
      		tmp = fma(y, x, x);
      	} else if (z <= 7e+290) {
      		tmp = z * y;
      	} else {
      		tmp = y * x;
      	}
      	return tmp;
      }
      
      function code(x, y, z)
      	tmp = 0.0
      	if (z <= -5.1e+82)
      		tmp = Float64(z * y);
      	elseif (z <= 3800000.0)
      		tmp = fma(y, x, x);
      	elseif (z <= 1.1e+62)
      		tmp = Float64(z * y);
      	elseif (z <= 3.5e+103)
      		tmp = fma(y, x, x);
      	elseif (z <= 7e+290)
      		tmp = Float64(z * y);
      	else
      		tmp = Float64(y * x);
      	end
      	return tmp
      end
      
      code[x_, y_, z_] := If[LessEqual[z, -5.1e+82], N[(z * y), $MachinePrecision], If[LessEqual[z, 3800000.0], N[(y * x + x), $MachinePrecision], If[LessEqual[z, 1.1e+62], N[(z * y), $MachinePrecision], If[LessEqual[z, 3.5e+103], N[(y * x + x), $MachinePrecision], If[LessEqual[z, 7e+290], N[(z * y), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;z \leq -5.1 \cdot 10^{+82}:\\
      \;\;\;\;z \cdot y\\
      
      \mathbf{elif}\;z \leq 3800000:\\
      \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
      
      \mathbf{elif}\;z \leq 1.1 \cdot 10^{+62}:\\
      \;\;\;\;z \cdot y\\
      
      \mathbf{elif}\;z \leq 3.5 \cdot 10^{+103}:\\
      \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
      
      \mathbf{elif}\;z \leq 7 \cdot 10^{+290}:\\
      \;\;\;\;z \cdot y\\
      
      \mathbf{else}:\\
      \;\;\;\;y \cdot x\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 3 regimes
      2. if z < -5.1000000000000003e82 or 3.8e6 < z < 1.10000000000000007e62 or 3.5e103 < z < 7.00000000000000026e290

        1. Initial program 100.0%

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

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

            \[\leadsto \color{blue}{z \cdot y} \]
          2. lower-*.f6474.2

            \[\leadsto \color{blue}{z \cdot y} \]
        5. Applied rewrites74.2%

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

        if -5.1000000000000003e82 < z < 3.8e6 or 1.10000000000000007e62 < z < 3.5e103

        1. Initial program 100.0%

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

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

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

            \[\leadsto \color{blue}{\left(y + 1\right)} \cdot x \]
          3. distribute-lft1-inN/A

            \[\leadsto \color{blue}{y \cdot x + x} \]
          4. lower-fma.f6485.9

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

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

        if 7.00000000000000026e290 < z

        1. Initial program 100.0%

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

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

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

            \[\leadsto \color{blue}{\left(y + 1\right)} \cdot x \]
          3. distribute-lft1-inN/A

            \[\leadsto \color{blue}{y \cdot x + x} \]
          4. lower-fma.f6425.8

            \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, x\right)} \]
        5. Applied rewrites25.8%

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

          \[\leadsto x \cdot \color{blue}{y} \]
        7. Step-by-step derivation
          1. Applied rewrites1.2%

            \[\leadsto y \cdot \color{blue}{x} \]
        8. Recombined 3 regimes into one program.
        9. Final simplification79.8%

          \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -5.1 \cdot 10^{+82}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;z \leq 3800000:\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \mathbf{elif}\;z \leq 1.1 \cdot 10^{+62}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;z \leq 3.5 \cdot 10^{+103}:\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \mathbf{elif}\;z \leq 7 \cdot 10^{+290}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
        10. Add Preprocessing

        Alternative 5: 27.1% accurate, 2.0× speedup?

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

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

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

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

            \[\leadsto \color{blue}{\left(y + 1\right)} \cdot x \]
          3. distribute-lft1-inN/A

            \[\leadsto \color{blue}{y \cdot x + x} \]
          4. lower-fma.f6462.2

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

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

          \[\leadsto x \cdot \color{blue}{y} \]
        7. Step-by-step derivation
          1. Applied rewrites25.0%

            \[\leadsto y \cdot \color{blue}{x} \]
          2. Final simplification25.0%

            \[\leadsto y \cdot x \]
          3. Add Preprocessing

          Reproduce

          ?
          herbie shell --seed 2024338 
          (FPCore (x y z)
            :name "Main:bigenough2 from A"
            :precision binary64
            (+ x (* y (+ z x))))