Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3

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

Specification

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

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

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

Alternative 1: 99.8% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 85.8% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\sin y, z, 1 \cdot x\right)\\
\mathbf{if}\;z \leq -2.4 \cdot 10^{-45}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;z \leq 1.35 \cdot 10^{-42}:\\
\;\;\;\;x \cdot \cos y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -2.3999999999999999e-45 or 1.35e-42 < z

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

      if -2.3999999999999999e-45 < z < 1.35e-42

      1. Initial program 99.8%

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

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

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

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

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

        \[\leadsto \color{blue}{\cos y \cdot x} \]
    7. Recombined 2 regimes into one program.
    8. Final simplification89.1%

      \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.4 \cdot 10^{-45}:\\ \;\;\;\;\mathsf{fma}\left(\sin y, z, 1 \cdot x\right)\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{-42}:\\ \;\;\;\;x \cdot \cos y\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\sin y, z, 1 \cdot x\right)\\ \end{array} \]
    9. Add Preprocessing

    Alternative 3: 74.6% accurate, 1.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -0.065:\\ \;\;\;\;z \cdot \sin y\\ \mathbf{elif}\;y \leq 25500:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, z \cdot y, -0.5 \cdot x\right), y, z\right), y, x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \cos y\\ \end{array} \end{array} \]
    (FPCore (x y z)
     :precision binary64
     (if (<= y -0.065)
       (* z (sin y))
       (if (<= y 25500.0)
         (fma (fma (fma -0.16666666666666666 (* z y) (* -0.5 x)) y z) y x)
         (* x (cos y)))))
    double code(double x, double y, double z) {
    	double tmp;
    	if (y <= -0.065) {
    		tmp = z * sin(y);
    	} else if (y <= 25500.0) {
    		tmp = fma(fma(fma(-0.16666666666666666, (z * y), (-0.5 * x)), y, z), y, x);
    	} else {
    		tmp = x * cos(y);
    	}
    	return tmp;
    }
    
    function code(x, y, z)
    	tmp = 0.0
    	if (y <= -0.065)
    		tmp = Float64(z * sin(y));
    	elseif (y <= 25500.0)
    		tmp = fma(fma(fma(-0.16666666666666666, Float64(z * y), Float64(-0.5 * x)), y, z), y, x);
    	else
    		tmp = Float64(x * cos(y));
    	end
    	return tmp
    end
    
    code[x_, y_, z_] := If[LessEqual[y, -0.065], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 25500.0], N[(N[(N[(-0.16666666666666666 * N[(z * y), $MachinePrecision] + N[(-0.5 * x), $MachinePrecision]), $MachinePrecision] * y + z), $MachinePrecision] * y + x), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;y \leq -0.065:\\
    \;\;\;\;z \cdot \sin y\\
    
    \mathbf{elif}\;y \leq 25500:\\
    \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, z \cdot y, -0.5 \cdot x\right), y, z\right), y, x\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;x \cdot \cos y\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if y < -0.065000000000000002

      1. Initial program 99.5%

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

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

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

          \[\leadsto \color{blue}{\sin y \cdot z} \]
        3. lower-sin.f6464.5

          \[\leadsto \color{blue}{\sin y} \cdot z \]
      5. Applied rewrites64.5%

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

      if -0.065000000000000002 < y < 25500

      1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if 25500 < y

      1. Initial program 99.6%

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

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

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

          \[\leadsto \color{blue}{\cos y \cdot x} \]
        3. lower-cos.f6460.8

          \[\leadsto \color{blue}{\cos y} \cdot x \]
      5. Applied rewrites60.8%

        \[\leadsto \color{blue}{\cos y \cdot x} \]
    3. Recombined 3 regimes into one program.
    4. Final simplification80.3%

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

    Alternative 4: 75.6% accurate, 1.8× speedup?

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

      1. Initial program 99.5%

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

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

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

          \[\leadsto \color{blue}{\cos y \cdot x} \]
        3. lower-cos.f6447.7

          \[\leadsto \color{blue}{\cos y} \cdot x \]
      5. Applied rewrites47.7%

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

      if -0.023 < y < 25500

      1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    Alternative 5: 52.3% accurate, 30.6× speedup?

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

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

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

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

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

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

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

    Alternative 6: 17.4% accurate, 35.7× speedup?

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

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

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

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

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

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

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

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

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

      Reproduce

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