Main:bigenough2 from A

Percentage Accurate: 100.0% → 100.0%
Time: 4.9s
Alternatives: 7
Speedup: 1.0×

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 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: 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.0× speedup?

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

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

    \[x + y \cdot \left(z + x\right) \]
  2. Add Preprocessing
  3. Final simplification100.0%

    \[\leadsto x + y \cdot \left(x + z\right) \]
  4. Add Preprocessing

Alternative 2: 60.9% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -9.5 \cdot 10^{+135}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq -7 \cdot 10^{+42}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq -5.8 \cdot 10^{-85}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{-58}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2020000:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -9.5e+135)
   (* y z)
   (if (<= y -7e+42)
     (* x y)
     (if (<= y -5.8e-85)
       (* y z)
       (if (<= y 1.5e-58) x (if (<= y 2020000.0) (* y z) (* x y)))))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -9.5e+135) {
		tmp = y * z;
	} else if (y <= -7e+42) {
		tmp = x * y;
	} else if (y <= -5.8e-85) {
		tmp = y * z;
	} else if (y <= 1.5e-58) {
		tmp = x;
	} else if (y <= 2020000.0) {
		tmp = y * z;
	} else {
		tmp = x * y;
	}
	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 (y <= (-9.5d+135)) then
        tmp = y * z
    else if (y <= (-7d+42)) then
        tmp = x * y
    else if (y <= (-5.8d-85)) then
        tmp = y * z
    else if (y <= 1.5d-58) then
        tmp = x
    else if (y <= 2020000.0d0) then
        tmp = y * z
    else
        tmp = x * y
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -9.5e+135) {
		tmp = y * z;
	} else if (y <= -7e+42) {
		tmp = x * y;
	} else if (y <= -5.8e-85) {
		tmp = y * z;
	} else if (y <= 1.5e-58) {
		tmp = x;
	} else if (y <= 2020000.0) {
		tmp = y * z;
	} else {
		tmp = x * y;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -9.5e+135:
		tmp = y * z
	elif y <= -7e+42:
		tmp = x * y
	elif y <= -5.8e-85:
		tmp = y * z
	elif y <= 1.5e-58:
		tmp = x
	elif y <= 2020000.0:
		tmp = y * z
	else:
		tmp = x * y
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -9.5e+135)
		tmp = Float64(y * z);
	elseif (y <= -7e+42)
		tmp = Float64(x * y);
	elseif (y <= -5.8e-85)
		tmp = Float64(y * z);
	elseif (y <= 1.5e-58)
		tmp = x;
	elseif (y <= 2020000.0)
		tmp = Float64(y * z);
	else
		tmp = Float64(x * y);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -9.5e+135)
		tmp = y * z;
	elseif (y <= -7e+42)
		tmp = x * y;
	elseif (y <= -5.8e-85)
		tmp = y * z;
	elseif (y <= 1.5e-58)
		tmp = x;
	elseif (y <= 2020000.0)
		tmp = y * z;
	else
		tmp = x * y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -9.5e+135], N[(y * z), $MachinePrecision], If[LessEqual[y, -7e+42], N[(x * y), $MachinePrecision], If[LessEqual[y, -5.8e-85], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.5e-58], x, If[LessEqual[y, 2020000.0], N[(y * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.5 \cdot 10^{+135}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;y \leq -7 \cdot 10^{+42}:\\
\;\;\;\;x \cdot y\\

\mathbf{elif}\;y \leq -5.8 \cdot 10^{-85}:\\
\;\;\;\;y \cdot z\\

\mathbf{elif}\;y \leq 1.5 \cdot 10^{-58}:\\
\;\;\;\;x\\

\mathbf{elif}\;y \leq 2020000:\\
\;\;\;\;y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -9.50000000000000036e135 or -7.00000000000000047e42 < y < -5.8000000000000004e-85 or 1.50000000000000004e-58 < y < 2.02e6

    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. *-lowering-*.f6474.0

        \[\leadsto \color{blue}{y \cdot z} \]
    5. Simplified74.0%

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

    if -9.50000000000000036e135 < y < -7.00000000000000047e42 or 2.02e6 < y

    1. Initial program 100.0%

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

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

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

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

        \[\leadsto y \cdot \color{blue}{\left(z + x\right)} \]
    5. Simplified100.0%

      \[\leadsto \color{blue}{y \cdot \left(z + x\right)} \]
    6. Taylor expanded in z around 0

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

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

      if -5.8000000000000004e-85 < y < 1.50000000000000004e-58

      1. Initial program 100.0%

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

        \[\leadsto \color{blue}{x} \]
      4. Step-by-step derivation
        1. Simplified76.1%

          \[\leadsto \color{blue}{x} \]
      5. Recombined 3 regimes into one program.
      6. Final simplification72.8%

        \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -9.5 \cdot 10^{+135}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq -7 \cdot 10^{+42}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq -5.8 \cdot 10^{-85}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;y \leq 1.5 \cdot 10^{-58}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 2020000:\\ \;\;\;\;y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
      7. Add Preprocessing

      Alternative 3: 98.6% accurate, 0.6× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := y \cdot \left(x + z\right)\\ \mathbf{if}\;y \leq -76000:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 8.6 \cdot 10^{-10}:\\ \;\;\;\;\mathsf{fma}\left(z, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
      (FPCore (x y z)
       :precision binary64
       (let* ((t_0 (* y (+ x z))))
         (if (<= y -76000.0) t_0 (if (<= y 8.6e-10) (fma z y x) t_0))))
      double code(double x, double y, double z) {
      	double t_0 = y * (x + z);
      	double tmp;
      	if (y <= -76000.0) {
      		tmp = t_0;
      	} else if (y <= 8.6e-10) {
      		tmp = fma(z, y, x);
      	} else {
      		tmp = t_0;
      	}
      	return tmp;
      }
      
      function code(x, y, z)
      	t_0 = Float64(y * Float64(x + z))
      	tmp = 0.0
      	if (y <= -76000.0)
      		tmp = t_0;
      	elseif (y <= 8.6e-10)
      		tmp = fma(z, y, x);
      	else
      		tmp = t_0;
      	end
      	return tmp
      end
      
      code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -76000.0], t$95$0, If[LessEqual[y, 8.6e-10], N[(z * y + x), $MachinePrecision], t$95$0]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := y \cdot \left(x + z\right)\\
      \mathbf{if}\;y \leq -76000:\\
      \;\;\;\;t\_0\\
      
      \mathbf{elif}\;y \leq 8.6 \cdot 10^{-10}:\\
      \;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;t\_0\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if y < -76000 or 8.60000000000000029e-10 < y

        1. Initial program 100.0%

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

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

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

            \[\leadsto y \cdot \color{blue}{\left(z + x\right)} \]
          3. +-lowering-+.f6498.6

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

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

        if -76000 < y < 8.60000000000000029e-10

        1. Initial program 100.0%

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

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

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

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

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

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

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

          \[\leadsto \mathsf{fma}\left(z, y, \color{blue}{x}\right) \]
        6. Step-by-step derivation
          1. Simplified99.6%

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

          \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -76000:\\ \;\;\;\;y \cdot \left(x + z\right)\\ \mathbf{elif}\;y \leq 8.6 \cdot 10^{-10}:\\ \;\;\;\;\mathsf{fma}\left(z, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x + z\right)\\ \end{array} \]
        9. Add Preprocessing

        Alternative 4: 85.7% accurate, 0.6× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.9 \cdot 10^{+149}:\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \mathbf{elif}\;x \leq 5.5 \cdot 10^{+36}:\\ \;\;\;\;\mathsf{fma}\left(z, y, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \end{array} \end{array} \]
        (FPCore (x y z)
         :precision binary64
         (if (<= x -1.9e+149) (fma y x x) (if (<= x 5.5e+36) (fma z y x) (fma y x x))))
        double code(double x, double y, double z) {
        	double tmp;
        	if (x <= -1.9e+149) {
        		tmp = fma(y, x, x);
        	} else if (x <= 5.5e+36) {
        		tmp = fma(z, y, x);
        	} else {
        		tmp = fma(y, x, x);
        	}
        	return tmp;
        }
        
        function code(x, y, z)
        	tmp = 0.0
        	if (x <= -1.9e+149)
        		tmp = fma(y, x, x);
        	elseif (x <= 5.5e+36)
        		tmp = fma(z, y, x);
        	else
        		tmp = fma(y, x, x);
        	end
        	return tmp
        end
        
        code[x_, y_, z_] := If[LessEqual[x, -1.9e+149], N[(y * x + x), $MachinePrecision], If[LessEqual[x, 5.5e+36], N[(z * y + x), $MachinePrecision], N[(y * x + x), $MachinePrecision]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;x \leq -1.9 \cdot 10^{+149}:\\
        \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
        
        \mathbf{elif}\;x \leq 5.5 \cdot 10^{+36}:\\
        \;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if x < -1.9e149 or 5.5000000000000002e36 < x

          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. accelerator-lowering-fma.f6493.6

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

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

          if -1.9e149 < x < 5.5000000000000002e36

          1. Initial program 100.0%

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

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

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

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

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

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

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

            \[\leadsto \mathsf{fma}\left(z, y, \color{blue}{x}\right) \]
          6. Step-by-step derivation
            1. Simplified90.5%

              \[\leadsto \mathsf{fma}\left(z, y, \color{blue}{x}\right) \]
          7. Recombined 2 regimes into one program.
          8. Add Preprocessing

          Alternative 5: 74.3% accurate, 0.6× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -3.8 \cdot 10^{+156}:\\ \;\;\;\;y \cdot z\\ \mathbf{elif}\;z \leq 1.6 \cdot 10^{+123}:\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \end{array} \end{array} \]
          (FPCore (x y z)
           :precision binary64
           (if (<= z -3.8e+156) (* y z) (if (<= z 1.6e+123) (fma y x x) (* y z))))
          double code(double x, double y, double z) {
          	double tmp;
          	if (z <= -3.8e+156) {
          		tmp = y * z;
          	} else if (z <= 1.6e+123) {
          		tmp = fma(y, x, x);
          	} else {
          		tmp = y * z;
          	}
          	return tmp;
          }
          
          function code(x, y, z)
          	tmp = 0.0
          	if (z <= -3.8e+156)
          		tmp = Float64(y * z);
          	elseif (z <= 1.6e+123)
          		tmp = fma(y, x, x);
          	else
          		tmp = Float64(y * z);
          	end
          	return tmp
          end
          
          code[x_, y_, z_] := If[LessEqual[z, -3.8e+156], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.6e+123], N[(y * x + x), $MachinePrecision], N[(y * z), $MachinePrecision]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;z \leq -3.8 \cdot 10^{+156}:\\
          \;\;\;\;y \cdot z\\
          
          \mathbf{elif}\;z \leq 1.6 \cdot 10^{+123}:\\
          \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
          
          \mathbf{else}:\\
          \;\;\;\;y \cdot z\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if z < -3.80000000000000024e156 or 1.60000000000000002e123 < z

            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. *-lowering-*.f6477.8

                \[\leadsto \color{blue}{y \cdot z} \]
            5. Simplified77.8%

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

            if -3.80000000000000024e156 < z < 1.60000000000000002e123

            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. accelerator-lowering-fma.f6478.1

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

              \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, x\right)} \]
          3. Recombined 2 regimes into one program.
          4. Add Preprocessing

          Alternative 6: 61.0% accurate, 0.7× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
          (FPCore (x y z)
           :precision binary64
           (if (<= y -1.0) (* x y) (if (<= y 1.0) x (* x y))))
          double code(double x, double y, double z) {
          	double tmp;
          	if (y <= -1.0) {
          		tmp = x * y;
          	} else if (y <= 1.0) {
          		tmp = x;
          	} else {
          		tmp = x * y;
          	}
          	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 (y <= (-1.0d0)) then
                  tmp = x * y
              else if (y <= 1.0d0) then
                  tmp = x
              else
                  tmp = x * y
              end if
              code = tmp
          end function
          
          public static double code(double x, double y, double z) {
          	double tmp;
          	if (y <= -1.0) {
          		tmp = x * y;
          	} else if (y <= 1.0) {
          		tmp = x;
          	} else {
          		tmp = x * y;
          	}
          	return tmp;
          }
          
          def code(x, y, z):
          	tmp = 0
          	if y <= -1.0:
          		tmp = x * y
          	elif y <= 1.0:
          		tmp = x
          	else:
          		tmp = x * y
          	return tmp
          
          function code(x, y, z)
          	tmp = 0.0
          	if (y <= -1.0)
          		tmp = Float64(x * y);
          	elseif (y <= 1.0)
          		tmp = x;
          	else
          		tmp = Float64(x * y);
          	end
          	return tmp
          end
          
          function tmp_2 = code(x, y, z)
          	tmp = 0.0;
          	if (y <= -1.0)
          		tmp = x * y;
          	elseif (y <= 1.0)
          		tmp = x;
          	else
          		tmp = x * y;
          	end
          	tmp_2 = tmp;
          end
          
          code[x_, y_, z_] := If[LessEqual[y, -1.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.0], x, N[(x * y), $MachinePrecision]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;y \leq -1:\\
          \;\;\;\;x \cdot y\\
          
          \mathbf{elif}\;y \leq 1:\\
          \;\;\;\;x\\
          
          \mathbf{else}:\\
          \;\;\;\;x \cdot y\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if y < -1 or 1 < y

            1. Initial program 100.0%

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

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

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

                \[\leadsto y \cdot \color{blue}{\left(z + x\right)} \]
              3. +-lowering-+.f6498.5

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

              \[\leadsto \color{blue}{y \cdot \left(z + x\right)} \]
            6. Taylor expanded in z around 0

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

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

              if -1 < y < 1

              1. Initial program 100.0%

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

                \[\leadsto \color{blue}{x} \]
              4. Step-by-step derivation
                1. Simplified66.7%

                  \[\leadsto \color{blue}{x} \]
              5. Recombined 2 regimes into one program.
              6. Final simplification62.4%

                \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;y \leq 1:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
              7. Add Preprocessing

              Alternative 7: 36.9% accurate, 12.0× speedup?

              \[\begin{array}{l} \\ x \end{array} \]
              (FPCore (x y z) :precision binary64 x)
              double code(double x, double y, double z) {
              	return 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
              end function
              
              public static double code(double x, double y, double z) {
              	return x;
              }
              
              def code(x, y, z):
              	return x
              
              function code(x, y, z)
              	return x
              end
              
              function tmp = code(x, y, z)
              	tmp = x;
              end
              
              code[x_, y_, z_] := x
              
              \begin{array}{l}
              
              \\
              x
              \end{array}
              
              Derivation
              1. Initial program 100.0%

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

                \[\leadsto \color{blue}{x} \]
              4. Step-by-step derivation
                1. Simplified36.3%

                  \[\leadsto \color{blue}{x} \]
                2. Add Preprocessing

                Reproduce

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