Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, B

Percentage Accurate: 99.8% → 99.8%
Time: 7.6s
Alternatives: 6
Speedup: 1.0×

Specification

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

\\
x \cdot \sin y + z \cdot \cos y
\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 6 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: 99.8% accurate, 1.0× speedup?

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

\\
x \cdot \sin y + z \cdot \cos y
\end{array}

Alternative 1: 99.8% accurate, 1.0× speedup?

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

\\
\mathsf{fma}\left(\sin y, x, z \cdot \cos y\right)
\end{array}
Derivation
  1. Initial program 99.8%

    \[x \cdot \sin y + z \cdot \cos y \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-+.f64N/A

      \[\leadsto \color{blue}{x \cdot \sin y + z \cdot \cos y} \]
    2. lift-*.f64N/A

      \[\leadsto \color{blue}{x \cdot \sin y} + z \cdot \cos y \]
    3. *-commutativeN/A

      \[\leadsto \color{blue}{\sin y \cdot x} + z \cdot \cos y \]
    4. lower-fma.f6499.8

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sin y, x, z \cdot \cos y\right)} \]
    5. lift-*.f64N/A

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

      \[\leadsto \mathsf{fma}\left(\sin y, x, \color{blue}{\cos y \cdot z}\right) \]
    7. lower-*.f6499.8

      \[\leadsto \mathsf{fma}\left(\sin y, x, \color{blue}{\cos y \cdot z}\right) \]
  4. Applied rewrites99.8%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\sin y, x, \cos y \cdot z\right)} \]
  5. Final simplification99.8%

    \[\leadsto \mathsf{fma}\left(\sin y, x, z \cdot \cos y\right) \]
  6. Add Preprocessing

Alternative 2: 73.7% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := z \cdot \cos y\\ \mathbf{if}\;z \leq -0.024:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq -2.35 \cdot 10^{-108}:\\ \;\;\;\;\mathsf{fma}\left(y, x, z\right)\\ \mathbf{elif}\;z \leq 1.2 \cdot 10^{-39}:\\ \;\;\;\;\sin y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* z (cos y))))
   (if (<= z -0.024)
     t_0
     (if (<= z -2.35e-108)
       (fma y x z)
       (if (<= z 1.2e-39) (* (sin y) x) t_0)))))
double code(double x, double y, double z) {
	double t_0 = z * cos(y);
	double tmp;
	if (z <= -0.024) {
		tmp = t_0;
	} else if (z <= -2.35e-108) {
		tmp = fma(y, x, z);
	} else if (z <= 1.2e-39) {
		tmp = sin(y) * x;
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(x, y, z)
	t_0 = Float64(z * cos(y))
	tmp = 0.0
	if (z <= -0.024)
		tmp = t_0;
	elseif (z <= -2.35e-108)
		tmp = fma(y, x, z);
	elseif (z <= 1.2e-39)
		tmp = Float64(sin(y) * x);
	else
		tmp = t_0;
	end
	return tmp
end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -0.024], t$95$0, If[LessEqual[z, -2.35e-108], N[(y * x + z), $MachinePrecision], If[LessEqual[z, 1.2e-39], N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -0.024:\\
\;\;\;\;t\_0\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -0.024 or 1.20000000000000008e-39 < z

    1. Initial program 99.8%

      \[x \cdot \sin y + z \cdot \cos y \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

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

        \[\leadsto \color{blue}{\cos y \cdot z} \]
      2. lower-*.f64N/A

        \[\leadsto \color{blue}{\cos y \cdot z} \]
      3. lower-cos.f6493.0

        \[\leadsto \color{blue}{\cos y} \cdot z \]
    5. Applied rewrites93.0%

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

    if -0.024 < z < -2.35000000000000006e-108

    1. Initial program 99.8%

      \[x \cdot \sin y + z \cdot \cos y \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

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

        \[\leadsto \color{blue}{x \cdot y + z} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{y \cdot x} + z \]
      3. lower-fma.f6491.1

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

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

    if -2.35000000000000006e-108 < z < 1.20000000000000008e-39

    1. Initial program 99.8%

      \[x \cdot \sin y + z \cdot \cos y \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{x \cdot \sin y + z \cdot \cos y} \]
      2. lift-*.f64N/A

        \[\leadsto \color{blue}{x \cdot \sin y} + z \cdot \cos y \]
      3. *-commutativeN/A

        \[\leadsto \color{blue}{\sin y \cdot x} + z \cdot \cos y \]
      4. lower-fma.f6499.8

        \[\leadsto \color{blue}{\mathsf{fma}\left(\sin y, x, z \cdot \cos y\right)} \]
      5. lift-*.f64N/A

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

        \[\leadsto \mathsf{fma}\left(\sin y, x, \color{blue}{\cos y \cdot z}\right) \]
      7. lower-*.f6499.8

        \[\leadsto \mathsf{fma}\left(\sin y, x, \color{blue}{\cos y \cdot z}\right) \]
    4. Applied rewrites99.8%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(z, \frac{\cos y}{x}, \sin y\right)} \cdot x \]
      6. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(z, \color{blue}{\frac{\cos y}{x}}, \sin y\right) \cdot x \]
      7. lower-cos.f64N/A

        \[\leadsto \mathsf{fma}\left(z, \frac{\color{blue}{\cos y}}{x}, \sin y\right) \cdot x \]
      8. lower-sin.f6499.7

        \[\leadsto \mathsf{fma}\left(z, \frac{\cos y}{x}, \color{blue}{\sin y}\right) \cdot x \]
    7. Applied rewrites99.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(z, \frac{\cos y}{x}, \sin y\right) \cdot x} \]
    8. Taylor expanded in x around inf

      \[\leadsto \sin y \cdot x \]
    9. Step-by-step derivation
      1. Applied rewrites76.4%

        \[\leadsto \sin y \cdot x \]
    10. Recombined 3 regimes into one program.
    11. Final simplification86.0%

      \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -0.024:\\ \;\;\;\;z \cdot \cos y\\ \mathbf{elif}\;z \leq -2.35 \cdot 10^{-108}:\\ \;\;\;\;\mathsf{fma}\left(y, x, z\right)\\ \mathbf{elif}\;z \leq 1.2 \cdot 10^{-39}:\\ \;\;\;\;\sin y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z \cdot \cos y\\ \end{array} \]
    12. Add Preprocessing

    Alternative 3: 84.8% accurate, 1.7× speedup?

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

      1. Initial program 99.8%

        \[x \cdot \sin y + z \cdot \cos y \]
      2. Add Preprocessing
      3. Taylor expanded in x around 0

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

          \[\leadsto \color{blue}{\cos y \cdot z} \]
        2. lower-*.f64N/A

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

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

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

      if -5.6e53 < z < 7.7999999999999999e-19

      1. Initial program 99.8%

        \[x \cdot \sin y + z \cdot \cos y \]
      2. Add Preprocessing
      3. Taylor expanded in y around 0

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

          \[\leadsto x \cdot \sin y + z \cdot \color{blue}{1} \]
        2. Step-by-step derivation
          1. lift-+.f64N/A

            \[\leadsto \color{blue}{x \cdot \sin y + z \cdot 1} \]
          2. +-commutativeN/A

            \[\leadsto \color{blue}{z \cdot 1 + x \cdot \sin y} \]
          3. lift-*.f64N/A

            \[\leadsto \color{blue}{z \cdot 1} + x \cdot \sin y \]
          4. *-commutativeN/A

            \[\leadsto \color{blue}{1 \cdot z} + x \cdot \sin y \]
          5. lift-*.f64N/A

            \[\leadsto 1 \cdot z + \color{blue}{x \cdot \sin y} \]
          6. *-commutativeN/A

            \[\leadsto 1 \cdot z + \color{blue}{\sin y \cdot x} \]
          7. lift-*.f64N/A

            \[\leadsto 1 \cdot z + \color{blue}{\sin y \cdot x} \]
          8. lower-fma.f6491.7

            \[\leadsto \color{blue}{\mathsf{fma}\left(1, z, \sin y \cdot x\right)} \]
          9. lift-*.f64N/A

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

            \[\leadsto \mathsf{fma}\left(1, z, \color{blue}{x \cdot \sin y}\right) \]
          11. lift-*.f6491.7

            \[\leadsto \mathsf{fma}\left(1, z, \color{blue}{x \cdot \sin y}\right) \]
        3. Applied rewrites91.7%

          \[\leadsto \color{blue}{\mathsf{fma}\left(1, z, x \cdot \sin y\right)} \]
      5. Recombined 2 regimes into one program.
      6. Final simplification92.9%

        \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -5.6 \cdot 10^{+53}:\\ \;\;\;\;z \cdot \cos y\\ \mathbf{elif}\;z \leq 7.8 \cdot 10^{-19}:\\ \;\;\;\;\mathsf{fma}\left(1, z, x \cdot \sin y\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \cos y\\ \end{array} \]
      7. Add Preprocessing

      Alternative 4: 73.8% accurate, 1.8× speedup?

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

        1. Initial program 99.6%

          \[x \cdot \sin y + z \cdot \cos y \]
        2. Add Preprocessing
        3. Taylor expanded in x around 0

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

            \[\leadsto \color{blue}{\cos y \cdot z} \]
          2. lower-*.f64N/A

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

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

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

        if -0.024 < y < 480

        1. Initial program 100.0%

          \[x \cdot \sin y + z \cdot \cos y \]
        2. Add Preprocessing
        3. Taylor expanded in y around 0

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

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

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

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

            \[\leadsto \mathsf{fma}\left(\color{blue}{y \cdot \left(\frac{-1}{2} \cdot z + \frac{-1}{6} \cdot \left(x \cdot y\right)\right) + x}, y, z\right) \]
          5. *-commutativeN/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{\left(\frac{-1}{2} \cdot z + \frac{-1}{6} \cdot \left(x \cdot y\right)\right) \cdot y} + x, y, z\right) \]
          6. lower-fma.f64N/A

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

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

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

            \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{-1}{6}, \color{blue}{y \cdot x}, \frac{-1}{2} \cdot z\right), y, x\right), y, z\right) \]
          10. lower-*.f64N/A

            \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{-1}{6}, \color{blue}{y \cdot x}, \frac{-1}{2} \cdot z\right), y, x\right), y, z\right) \]
          11. lower-*.f6499.3

            \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, y \cdot x, \color{blue}{-0.5 \cdot z}\right), y, x\right), y, z\right) \]
        5. Applied rewrites99.3%

          \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, y \cdot x, -0.5 \cdot z\right), y, x\right), y, z\right)} \]
      3. Recombined 2 regimes into one program.
      4. Final simplification75.3%

        \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -0.024:\\ \;\;\;\;z \cdot \cos y\\ \mathbf{elif}\;y \leq 480:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, x \cdot y, -0.5 \cdot z\right), y, x\right), y, z\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \cos y\\ \end{array} \]
      5. Add Preprocessing

      Alternative 5: 51.4% accurate, 30.6× speedup?

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

        \[x \cdot \sin y + z \cdot \cos y \]
      2. Add Preprocessing
      3. Taylor expanded in y around 0

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

          \[\leadsto \color{blue}{x \cdot y + z} \]
        2. *-commutativeN/A

          \[\leadsto \color{blue}{y \cdot x} + z \]
        3. lower-fma.f6453.3

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

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

      Alternative 6: 16.6% accurate, 35.7× speedup?

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

        \[x \cdot \sin y + z \cdot \cos y \]
      2. Add Preprocessing
      3. Taylor expanded in y around 0

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

          \[\leadsto \color{blue}{x \cdot y + z} \]
        2. *-commutativeN/A

          \[\leadsto \color{blue}{y \cdot x} + z \]
        3. lower-fma.f6453.3

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

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

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

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

        Reproduce

        ?
        herbie shell --seed 2024296 
        (FPCore (x y z)
          :name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, B"
          :precision binary64
          (+ (* x (sin y)) (* z (cos y))))