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

Percentage Accurate: 99.8% → 99.8%
Time: 6.9s
Alternatives: 7
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 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: 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: 85.8% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -6 \cdot 10^{-46} \lor \neg \left(z \leq 2.25 \cdot 10^{-68}\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 -6e-46) (not (<= z 2.25e-68)))
   (- (* x 1.0) (* z (sin y)))
   (* (cos y) x)))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -6e-46) || !(z <= 2.25e-68)) {
		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 <= (-6d-46)) .or. (.not. (z <= 2.25d-68))) 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 <= -6e-46) || !(z <= 2.25e-68)) {
		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 <= -6e-46) or not (z <= 2.25e-68):
		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 <= -6e-46) || !(z <= 2.25e-68))
		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 <= -6e-46) || ~((z <= 2.25e-68)))
		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, -6e-46], N[Not[LessEqual[z, 2.25e-68]], $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 -6 \cdot 10^{-46} \lor \neg \left(z \leq 2.25 \cdot 10^{-68}\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 < -5.99999999999999975e-46 or 2.25e-68 < 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 rewrites90.0%

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

      if -5.99999999999999975e-46 < z < 2.25e-68

      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.7%

        \[\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 rewrites89.5%

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

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

      Alternative 3: 74.1% accurate, 1.8× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -4.7 \cdot 10^{+160} \lor \neg \left(z \leq 7.2 \cdot 10^{+87}\right):\\ \;\;\;\;\left(-z\right) \cdot \sin y\\ \mathbf{else}:\\ \;\;\;\;\cos y \cdot x\\ \end{array} \end{array} \]
      (FPCore (x y z)
       :precision binary64
       (if (or (<= z -4.7e+160) (not (<= z 7.2e+87)))
         (* (- z) (sin y))
         (* (cos y) x)))
      double code(double x, double y, double z) {
      	double tmp;
      	if ((z <= -4.7e+160) || !(z <= 7.2e+87)) {
      		tmp = -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 <= (-4.7d+160)) .or. (.not. (z <= 7.2d+87))) then
              tmp = -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 <= -4.7e+160) || !(z <= 7.2e+87)) {
      		tmp = -z * Math.sin(y);
      	} else {
      		tmp = Math.cos(y) * x;
      	}
      	return tmp;
      }
      
      def code(x, y, z):
      	tmp = 0
      	if (z <= -4.7e+160) or not (z <= 7.2e+87):
      		tmp = -z * math.sin(y)
      	else:
      		tmp = math.cos(y) * x
      	return tmp
      
      function code(x, y, z)
      	tmp = 0.0
      	if ((z <= -4.7e+160) || !(z <= 7.2e+87))
      		tmp = Float64(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 <= -4.7e+160) || ~((z <= 7.2e+87)))
      		tmp = -z * sin(y);
      	else
      		tmp = cos(y) * x;
      	end
      	tmp_2 = tmp;
      end
      
      code[x_, y_, z_] := If[Or[LessEqual[z, -4.7e+160], N[Not[LessEqual[z, 7.2e+87]], $MachinePrecision]], N[((-z) * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;z \leq -4.7 \cdot 10^{+160} \lor \neg \left(z \leq 7.2 \cdot 10^{+87}\right):\\
      \;\;\;\;\left(-z\right) \cdot \sin y\\
      
      \mathbf{else}:\\
      \;\;\;\;\cos y \cdot x\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if z < -4.6999999999999997e160 or 7.19999999999999988e87 < z

        1. Initial program 99.8%

          \[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.f6476.8

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

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

        if -4.6999999999999997e160 < z < 7.19999999999999988e87

        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.1%

          \[\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 rewrites80.6%

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

          \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -4.7 \cdot 10^{+160} \lor \neg \left(z \leq 7.2 \cdot 10^{+87}\right):\\ \;\;\;\;\left(-z\right) \cdot \sin y\\ \mathbf{else}:\\ \;\;\;\;\cos y \cdot x\\ \end{array} \]
        10. Add Preprocessing

        Alternative 4: 75.3% accurate, 1.8× speedup?

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

          1. Initial program 99.6%

            \[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 rewrites87.6%

            \[\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 rewrites51.8%

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

            if -0.0420000000000000026 < y < 1.29999999999999999e-7

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

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

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

                \[\leadsto \color{blue}{\mathsf{fma}\left(y \cdot \left(\frac{-1}{2} \cdot x + \frac{1}{6} \cdot \left(y \cdot z\right)\right) - z, y, x\right)} \]
              4. lower--.f64N/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-*.f64N/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) \]
              7. +-commutativeN/A

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

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

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

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

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

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

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

          Alternative 5: 40.6% accurate, 15.3× speedup?

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

            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.f6449.7

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

              \[\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 rewrites44.8%

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

              if -4.9999999999999995e164 < 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 \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.f6451.8

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

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

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

                  \[\leadsto x \cdot \color{blue}{{\left(\sqrt{-1}\right)}^{2}} \]
                3. Step-by-step derivation
                  1. Applied rewrites4.8%

                    \[\leadsto -x \]
                  2. Step-by-step derivation
                    1. Applied rewrites43.5%

                      \[\leadsto \color{blue}{x} \]
                  3. Recombined 2 regimes into one program.
                  4. Add Preprocessing

                  Alternative 6: 52.6% 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.f6451.6

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

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

                  Alternative 7: 38.6% accurate, 214.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 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.f6451.6

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

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

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

                      \[\leadsto x \cdot \color{blue}{{\left(\sqrt{-1}\right)}^{2}} \]
                    3. Step-by-step derivation
                      1. Applied rewrites4.5%

                        \[\leadsto -x \]
                      2. Step-by-step derivation
                        1. Applied rewrites39.8%

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

                        Reproduce

                        ?
                        herbie shell --seed 2024320 
                        (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))))