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

Percentage Accurate: 99.8% → 99.8%
Time: 5.1s
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} \\ 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}
Derivation
  1. Initial program 99.8%

    \[x \cdot \cos y - z \cdot \sin y \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 2: 86.1% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -7.8 \cdot 10^{-143} \lor \neg \left(z \leq 1.52 \cdot 10^{-99}\right):\\ \;\;\;\;x \cdot 1 - z \cdot \sin y\\ \mathbf{else}:\\ \;\;\;\;\cos y \cdot x\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -7.8e-143) (not (<= z 1.52e-99)))
   (- (* x 1.0) (* z (sin y)))
   (* (cos y) x)))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -7.8e-143) || !(z <= 1.52e-99)) {
		tmp = (x * 1.0) - (z * sin(y));
	} else {
		tmp = cos(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 <= (-7.8d-143)) .or. (.not. (z <= 1.52d-99))) then
        tmp = (x * 1.0d0) - (z * sin(y))
    else
        tmp = cos(y) * x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z <= -7.8e-143) || !(z <= 1.52e-99)) {
		tmp = (x * 1.0) - (z * Math.sin(y));
	} else {
		tmp = Math.cos(y) * x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -7.8e-143) or not (z <= 1.52e-99):
		tmp = (x * 1.0) - (z * math.sin(y))
	else:
		tmp = math.cos(y) * x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -7.8e-143) || !(z <= 1.52e-99))
		tmp = Float64(Float64(x * 1.0) - Float64(z * sin(y)));
	else
		tmp = Float64(cos(y) * x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z <= -7.8e-143) || ~((z <= 1.52e-99)))
		tmp = (x * 1.0) - (z * sin(y));
	else
		tmp = cos(y) * x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, -7.8e-143], N[Not[LessEqual[z, 1.52e-99]], $MachinePrecision]], N[(N[(x * 1.0), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.8 \cdot 10^{-143} \lor \neg \left(z \leq 1.52 \cdot 10^{-99}\right):\\
\;\;\;\;x \cdot 1 - z \cdot \sin y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -7.80000000000000007e-143 or 1.51999999999999999e-99 < z

    1. Initial program 99.8%

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

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

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

      if -7.80000000000000007e-143 < z < 1.51999999999999999e-99

      1. Initial program 99.8%

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

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

          \[\leadsto \color{blue}{x \cdot \cos y + x \cdot \left(-1 \cdot \frac{z \cdot \sin y}{x}\right)} \]
        2. remove-double-negN/A

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

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

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

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

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

          \[\leadsto \left(\mathsf{neg}\left(\left(-1 \cdot \cos y\right) \cdot x\right)\right) + \color{blue}{\left(\mathsf{neg}\left(\frac{z \cdot \sin y}{x}\right)\right)} \cdot x \]
        8. distribute-lft-neg-outN/A

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

          \[\leadsto \color{blue}{\mathsf{neg}\left(\left(\left(-1 \cdot \cos y\right) \cdot x + \frac{z \cdot \sin y}{x} \cdot x\right)\right)} \]
        10. distribute-rgt-inN/A

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

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

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

          \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \cos y + \frac{z \cdot \sin y}{x}\right)\right)\right) \cdot x} \]
      5. Applied rewrites99.8%

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

        \[\leadsto \cos y \cdot x \]
      7. Step-by-step derivation
        1. Applied rewrites94.8%

          \[\leadsto \cos y \cdot x \]
      8. Recombined 2 regimes into one program.
      9. Final simplification88.5%

        \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -7.8 \cdot 10^{-143} \lor \neg \left(z \leq 1.52 \cdot 10^{-99}\right):\\ \;\;\;\;x \cdot 1 - z \cdot \sin y\\ \mathbf{else}:\\ \;\;\;\;\cos y \cdot x\\ \end{array} \]
      10. Add Preprocessing

      Alternative 3: 73.8% accurate, 1.7× speedup?

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

        1. Initial program 99.7%

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

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

            \[\leadsto \color{blue}{x \cdot \cos y + x \cdot \left(-1 \cdot \frac{z \cdot \sin y}{x}\right)} \]
          2. remove-double-negN/A

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

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

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

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

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

            \[\leadsto \left(\mathsf{neg}\left(\left(-1 \cdot \cos y\right) \cdot x\right)\right) + \color{blue}{\left(\mathsf{neg}\left(\frac{z \cdot \sin y}{x}\right)\right)} \cdot x \]
          8. distribute-lft-neg-outN/A

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

            \[\leadsto \color{blue}{\mathsf{neg}\left(\left(\left(-1 \cdot \cos y\right) \cdot x + \frac{z \cdot \sin y}{x} \cdot x\right)\right)} \]
          10. distribute-rgt-inN/A

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

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

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

            \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \cos y + \frac{z \cdot \sin y}{x}\right)\right)\right) \cdot x} \]
        5. Applied rewrites92.0%

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

          \[\leadsto \cos y \cdot x \]
        7. Step-by-step derivation
          1. Applied rewrites64.5%

            \[\leadsto \cos y \cdot x \]

          if -1.64999999999999996e171 < y < -0.839999999999999969

          1. Initial program 99.6%

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

            \[\leadsto \color{blue}{-1 \cdot \left(z \cdot \sin y\right)} \]
          4. Step-by-step derivation
            1. mul-1-negN/A

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

              \[\leadsto \color{blue}{\left(\mathsf{neg}\left(z\right)\right) \cdot \sin y} \]
            3. lower-*.f64N/A

              \[\leadsto \color{blue}{\left(\mathsf{neg}\left(z\right)\right) \cdot \sin y} \]
            4. lower-neg.f64N/A

              \[\leadsto \color{blue}{\left(-z\right)} \cdot \sin y \]
            5. lower-sin.f6460.6

              \[\leadsto \left(-z\right) \cdot \color{blue}{\sin y} \]
          5. Applied rewrites60.6%

            \[\leadsto \color{blue}{\left(-z\right) \cdot \sin y} \]

          if -0.839999999999999969 < y < 7.99999999999999956e-20

          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(\frac{-1}{2} \cdot \left(x \cdot y\right) - z\right)} \]
          4. Step-by-step derivation
            1. +-commutativeN/A

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

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

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

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

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

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

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

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

            \[\leadsto \color{blue}{\mathsf{fma}\left(\left(y \cdot x\right) \cdot -0.5 - z, y, x\right)} \]
        8. Recombined 3 regimes into one program.
        9. Add Preprocessing

        Alternative 4: 73.8% accurate, 1.8× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -2.75 \cdot 10^{-5} \lor \neg \left(y \leq 8 \cdot 10^{-20}\right):\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-z, y, x\right)\\ \end{array} \end{array} \]
        (FPCore (x y z)
         :precision binary64
         (if (or (<= y -2.75e-5) (not (<= y 8e-20))) (* (cos y) x) (fma (- z) y x)))
        double code(double x, double y, double z) {
        	double tmp;
        	if ((y <= -2.75e-5) || !(y <= 8e-20)) {
        		tmp = cos(y) * x;
        	} else {
        		tmp = fma(-z, y, x);
        	}
        	return tmp;
        }
        
        function code(x, y, z)
        	tmp = 0.0
        	if ((y <= -2.75e-5) || !(y <= 8e-20))
        		tmp = Float64(cos(y) * x);
        	else
        		tmp = fma(Float64(-z), y, x);
        	end
        	return tmp
        end
        
        code[x_, y_, z_] := If[Or[LessEqual[y, -2.75e-5], N[Not[LessEqual[y, 8e-20]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[((-z) * y + x), $MachinePrecision]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;y \leq -2.75 \cdot 10^{-5} \lor \neg \left(y \leq 8 \cdot 10^{-20}\right):\\
        \;\;\;\;\cos y \cdot x\\
        
        \mathbf{else}:\\
        \;\;\;\;\mathsf{fma}\left(-z, y, x\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if y < -2.7500000000000001e-5 or 7.99999999999999956e-20 < y

          1. Initial program 99.7%

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

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

              \[\leadsto \color{blue}{x \cdot \cos y + x \cdot \left(-1 \cdot \frac{z \cdot \sin y}{x}\right)} \]
            2. remove-double-negN/A

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

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

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

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

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

              \[\leadsto \left(\mathsf{neg}\left(\left(-1 \cdot \cos y\right) \cdot x\right)\right) + \color{blue}{\left(\mathsf{neg}\left(\frac{z \cdot \sin y}{x}\right)\right)} \cdot x \]
            8. distribute-lft-neg-outN/A

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

              \[\leadsto \color{blue}{\mathsf{neg}\left(\left(\left(-1 \cdot \cos y\right) \cdot x + \frac{z \cdot \sin y}{x} \cdot x\right)\right)} \]
            10. distribute-rgt-inN/A

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

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

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

              \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\left(-1 \cdot \cos y + \frac{z \cdot \sin y}{x}\right)\right)\right) \cdot x} \]
          5. Applied rewrites89.4%

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

            \[\leadsto \cos y \cdot x \]
          7. Step-by-step derivation
            1. Applied rewrites57.3%

              \[\leadsto \cos y \cdot x \]

            if -2.7500000000000001e-5 < y < 7.99999999999999956e-20

            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 + -1 \cdot \left(y \cdot z\right)} \]
            4. Step-by-step derivation
              1. +-commutativeN/A

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

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

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

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

                \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(z\right), y, x\right)} \]
              6. lower-neg.f64100.0

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

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

            \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -2.75 \cdot 10^{-5} \lor \neg \left(y \leq 8 \cdot 10^{-20}\right):\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-z, y, x\right)\\ \end{array} \]
          10. Add Preprocessing

          Alternative 5: 52.1% accurate, 23.8× 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(Float64(-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 + -1 \cdot \left(y \cdot z\right)} \]
          4. Step-by-step derivation
            1. +-commutativeN/A

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

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

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

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

              \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(z\right), y, x\right)} \]
            6. lower-neg.f6454.0

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

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

          Alternative 6: 16.8% accurate, 26.8× speedup?

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

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

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

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

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

              \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{neg}\left(z\right), y, x\right)} \]
            6. lower-neg.f6454.0

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

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

            \[\leadsto -1 \cdot \color{blue}{\left(y \cdot z\right)} \]
          7. Step-by-step derivation
            1. Applied rewrites17.4%

              \[\leadsto \left(-y\right) \cdot \color{blue}{z} \]
            2. Add Preprocessing

            Reproduce

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