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

Percentage Accurate: 99.8% → 99.8%
Time: 9.1s
Alternatives: 11
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 11 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), Float64(-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. sub-negN/A

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(\sin y, -z, \color{blue}{\cos y \cdot x}\right) \]
    11. 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: 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 3: 84.2% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{+155}:\\ \;\;\;\;\left(\left(\frac{\cos y}{z} - \frac{y}{x}\right) \cdot z\right) \cdot x\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{+44}:\\ \;\;\;\;\mathsf{fma}\left(\sin y, -z, 1 \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \cos y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x -2e+155)
   (* (* (- (/ (cos y) z) (/ y x)) z) x)
   (if (<= x 1.65e+44) (fma (sin y) (- z) (* 1.0 x)) (* x (cos y)))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -2e+155) {
		tmp = (((cos(y) / z) - (y / x)) * z) * x;
	} else if (x <= 1.65e+44) {
		tmp = fma(sin(y), -z, (1.0 * x));
	} else {
		tmp = x * cos(y);
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (x <= -2e+155)
		tmp = Float64(Float64(Float64(Float64(cos(y) / z) - Float64(y / x)) * z) * x);
	elseif (x <= 1.65e+44)
		tmp = fma(sin(y), Float64(-z), Float64(1.0 * x));
	else
		tmp = Float64(x * cos(y));
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[x, -2e+155], N[(N[(N[(N[(N[Cos[y], $MachinePrecision] / z), $MachinePrecision] - N[(y / x), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[x, 1.65e+44], N[(N[Sin[y], $MachinePrecision] * (-z) + N[(1.0 * x), $MachinePrecision]), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{+155}:\\
\;\;\;\;\left(\left(\frac{\cos y}{z} - \frac{y}{x}\right) \cdot z\right) \cdot x\\

\mathbf{elif}\;x \leq 1.65 \cdot 10^{+44}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, -z, 1 \cdot x\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -2.00000000000000001e155

    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. sub-negN/A

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

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(z \cdot \sin y\right)\right) + x \cdot \cos y} \]
      4. flip-+N/A

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\frac{\left(-z\right) \cdot \sin y - \cos y \cdot x}{{\left(\sin y \cdot z\right)}^{2} - {\left(\cos y \cdot x\right)}^{2}}}} \]
    5. Taylor expanded in x around inf

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(z \cdot \left(-1 \cdot \frac{\sin y}{x} + \frac{\cos y}{z}\right)\right) \cdot x \]
    9. Step-by-step derivation
      1. Applied rewrites99.6%

        \[\leadsto \left(\left(\frac{\cos y}{z} - \frac{\sin y}{x}\right) \cdot z\right) \cdot x \]
      2. Taylor expanded in y around 0

        \[\leadsto \left(\left(\frac{\cos y}{z} - \frac{y}{x}\right) \cdot z\right) \cdot x \]
      3. Step-by-step derivation
        1. Applied rewrites88.0%

          \[\leadsto \left(\left(\frac{\cos y}{z} - \frac{y}{x}\right) \cdot z\right) \cdot x \]

        if -2.00000000000000001e155 < x < 1.65000000000000007e44

        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. sub-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

          if 1.65000000000000007e44 < x

          1. Initial program 99.7%

            \[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.f6485.9

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

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

          \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{+155}:\\ \;\;\;\;\left(\left(\frac{\cos y}{z} - \frac{y}{x}\right) \cdot z\right) \cdot x\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{+44}:\\ \;\;\;\;\mathsf{fma}\left(\sin y, -z, 1 \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \cos y\\ \end{array} \]
        9. Add Preprocessing

        Alternative 4: 85.6% accurate, 1.7× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \cos y\\ \mathbf{if}\;x \leq -1.22 \cdot 10^{+156}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{+44}:\\ \;\;\;\;\mathsf{fma}\left(\sin y, -z, 1 \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
        (FPCore (x y z)
         :precision binary64
         (let* ((t_0 (* x (cos y))))
           (if (<= x -1.22e+156)
             t_0
             (if (<= x 1.65e+44) (fma (sin y) (- z) (* 1.0 x)) t_0))))
        double code(double x, double y, double z) {
        	double t_0 = x * cos(y);
        	double tmp;
        	if (x <= -1.22e+156) {
        		tmp = t_0;
        	} else if (x <= 1.65e+44) {
        		tmp = fma(sin(y), -z, (1.0 * x));
        	} else {
        		tmp = t_0;
        	}
        	return tmp;
        }
        
        function code(x, y, z)
        	t_0 = Float64(x * cos(y))
        	tmp = 0.0
        	if (x <= -1.22e+156)
        		tmp = t_0;
        	elseif (x <= 1.65e+44)
        		tmp = fma(sin(y), Float64(-z), Float64(1.0 * 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[x, -1.22e+156], t$95$0, If[LessEqual[x, 1.65e+44], N[(N[Sin[y], $MachinePrecision] * (-z) + N[(1.0 * x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        t_0 := x \cdot \cos y\\
        \mathbf{if}\;x \leq -1.22 \cdot 10^{+156}:\\
        \;\;\;\;t\_0\\
        
        \mathbf{elif}\;x \leq 1.65 \cdot 10^{+44}:\\
        \;\;\;\;\mathsf{fma}\left(\sin y, -z, 1 \cdot x\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;t\_0\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if x < -1.21999999999999991e156 or 1.65000000000000007e44 < x

          1. Initial program 99.7%

            \[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.f6485.9

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

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

          if -1.21999999999999991e156 < x < 1.65000000000000007e44

          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. sub-negN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

          Alternative 5: 85.6% accurate, 1.7× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \cos y\\ \mathbf{if}\;x \leq -1.22 \cdot 10^{+156}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{+44}:\\ \;\;\;\;1 \cdot x - z \cdot \sin y\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
          (FPCore (x y z)
           :precision binary64
           (let* ((t_0 (* x (cos y))))
             (if (<= x -1.22e+156)
               t_0
               (if (<= x 1.65e+44) (- (* 1.0 x) (* z (sin y))) t_0))))
          double code(double x, double y, double z) {
          	double t_0 = x * cos(y);
          	double tmp;
          	if (x <= -1.22e+156) {
          		tmp = t_0;
          	} else if (x <= 1.65e+44) {
          		tmp = (1.0 * x) - (z * sin(y));
          	} else {
          		tmp = t_0;
          	}
          	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) :: t_0
              real(8) :: tmp
              t_0 = x * cos(y)
              if (x <= (-1.22d+156)) then
                  tmp = t_0
              else if (x <= 1.65d+44) then
                  tmp = (1.0d0 * x) - (z * sin(y))
              else
                  tmp = t_0
              end if
              code = tmp
          end function
          
          public static double code(double x, double y, double z) {
          	double t_0 = x * Math.cos(y);
          	double tmp;
          	if (x <= -1.22e+156) {
          		tmp = t_0;
          	} else if (x <= 1.65e+44) {
          		tmp = (1.0 * x) - (z * Math.sin(y));
          	} else {
          		tmp = t_0;
          	}
          	return tmp;
          }
          
          def code(x, y, z):
          	t_0 = x * math.cos(y)
          	tmp = 0
          	if x <= -1.22e+156:
          		tmp = t_0
          	elif x <= 1.65e+44:
          		tmp = (1.0 * x) - (z * math.sin(y))
          	else:
          		tmp = t_0
          	return tmp
          
          function code(x, y, z)
          	t_0 = Float64(x * cos(y))
          	tmp = 0.0
          	if (x <= -1.22e+156)
          		tmp = t_0;
          	elseif (x <= 1.65e+44)
          		tmp = Float64(Float64(1.0 * x) - Float64(z * sin(y)));
          	else
          		tmp = t_0;
          	end
          	return tmp
          end
          
          function tmp_2 = code(x, y, z)
          	t_0 = x * cos(y);
          	tmp = 0.0;
          	if (x <= -1.22e+156)
          		tmp = t_0;
          	elseif (x <= 1.65e+44)
          		tmp = (1.0 * x) - (z * sin(y));
          	else
          		tmp = t_0;
          	end
          	tmp_2 = tmp;
          end
          
          code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.22e+156], t$95$0, If[LessEqual[x, 1.65e+44], N[(N[(1.0 * x), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          t_0 := x \cdot \cos y\\
          \mathbf{if}\;x \leq -1.22 \cdot 10^{+156}:\\
          \;\;\;\;t\_0\\
          
          \mathbf{elif}\;x \leq 1.65 \cdot 10^{+44}:\\
          \;\;\;\;1 \cdot x - z \cdot \sin y\\
          
          \mathbf{else}:\\
          \;\;\;\;t\_0\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if x < -1.21999999999999991e156 or 1.65000000000000007e44 < x

            1. Initial program 99.7%

              \[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.f6485.9

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

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

            if -1.21999999999999991e156 < x < 1.65000000000000007e44

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

                \[\leadsto x \cdot \color{blue}{1} - z \cdot \sin y \]
            5. Recombined 2 regimes into one program.
            6. Final simplification87.1%

              \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.22 \cdot 10^{+156}:\\ \;\;\;\;x \cdot \cos y\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{+44}:\\ \;\;\;\;1 \cdot x - z \cdot \sin y\\ \mathbf{else}:\\ \;\;\;\;x \cdot \cos y\\ \end{array} \]
            7. Add Preprocessing

            Alternative 6: 75.2% accurate, 1.8× speedup?

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

              1. Initial program 99.7%

                \[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.f6455.1

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

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

              if -45000 < y < 0.0074000000000000003

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

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

                \[\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)} \]

              if 0.0074000000000000003 < y

              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}{-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.f6451.6

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

                \[\leadsto \color{blue}{\left(-z\right) \cdot \sin y} \]
            3. Recombined 3 regimes into one program.
            4. Final simplification79.5%

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

            Alternative 7: 75.3% accurate, 1.8× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \cos y\\ \mathbf{if}\;y \leq -45000:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 0.042:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, z \cdot y, -0.5 \cdot x\right) \cdot y - z, 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 -45000.0)
                 t_0
                 (if (<= y 0.042)
                   (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 <= -45000.0) {
            		tmp = t_0;
            	} else if (y <= 0.042) {
            		tmp = 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 <= -45000.0)
            		tmp = t_0;
            	elseif (y <= 0.042)
            		tmp = fma(Float64(Float64(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, -45000.0], t$95$0, If[LessEqual[y, 0.042], N[(N[(N[(N[(0.16666666666666666 * N[(z * y), $MachinePrecision] + N[(-0.5 * x), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision] * y + x), $MachinePrecision], t$95$0]]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            t_0 := x \cdot \cos y\\
            \mathbf{if}\;y \leq -45000:\\
            \;\;\;\;t\_0\\
            
            \mathbf{elif}\;y \leq 0.042:\\
            \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, z \cdot y, -0.5 \cdot x\right) \cdot y - z, y, x\right)\\
            
            \mathbf{else}:\\
            \;\;\;\;t\_0\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if y < -45000 or 0.0420000000000000026 < 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.f6451.3

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

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

              if -45000 < y < 0.0420000000000000026

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

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

                \[\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)} \]
            3. Recombined 2 regimes into one program.
            4. Final simplification78.7%

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

            Alternative 8: 41.7% accurate, 10.7× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(-y\right) \cdot z\\ \mathbf{if}\;z \leq -1 \cdot 10^{+129}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq 1.6 \cdot 10^{+257}:\\ \;\;\;\;1 \cdot x\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
            (FPCore (x y z)
             :precision binary64
             (let* ((t_0 (* (- y) z)))
               (if (<= z -1e+129) t_0 (if (<= z 1.6e+257) (* 1.0 x) t_0))))
            double code(double x, double y, double z) {
            	double t_0 = -y * z;
            	double tmp;
            	if (z <= -1e+129) {
            		tmp = t_0;
            	} else if (z <= 1.6e+257) {
            		tmp = 1.0 * x;
            	} else {
            		tmp = t_0;
            	}
            	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) :: t_0
                real(8) :: tmp
                t_0 = -y * z
                if (z <= (-1d+129)) then
                    tmp = t_0
                else if (z <= 1.6d+257) then
                    tmp = 1.0d0 * x
                else
                    tmp = t_0
                end if
                code = tmp
            end function
            
            public static double code(double x, double y, double z) {
            	double t_0 = -y * z;
            	double tmp;
            	if (z <= -1e+129) {
            		tmp = t_0;
            	} else if (z <= 1.6e+257) {
            		tmp = 1.0 * x;
            	} else {
            		tmp = t_0;
            	}
            	return tmp;
            }
            
            def code(x, y, z):
            	t_0 = -y * z
            	tmp = 0
            	if z <= -1e+129:
            		tmp = t_0
            	elif z <= 1.6e+257:
            		tmp = 1.0 * x
            	else:
            		tmp = t_0
            	return tmp
            
            function code(x, y, z)
            	t_0 = Float64(Float64(-y) * z)
            	tmp = 0.0
            	if (z <= -1e+129)
            		tmp = t_0;
            	elseif (z <= 1.6e+257)
            		tmp = Float64(1.0 * x);
            	else
            		tmp = t_0;
            	end
            	return tmp
            end
            
            function tmp_2 = code(x, y, z)
            	t_0 = -y * z;
            	tmp = 0.0;
            	if (z <= -1e+129)
            		tmp = t_0;
            	elseif (z <= 1.6e+257)
            		tmp = 1.0 * x;
            	else
            		tmp = t_0;
            	end
            	tmp_2 = tmp;
            end
            
            code[x_, y_, z_] := Block[{t$95$0 = N[((-y) * z), $MachinePrecision]}, If[LessEqual[z, -1e+129], t$95$0, If[LessEqual[z, 1.6e+257], N[(1.0 * x), $MachinePrecision], t$95$0]]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            t_0 := \left(-y\right) \cdot z\\
            \mathbf{if}\;z \leq -1 \cdot 10^{+129}:\\
            \;\;\;\;t\_0\\
            
            \mathbf{elif}\;z \leq 1.6 \cdot 10^{+257}:\\
            \;\;\;\;1 \cdot x\\
            
            \mathbf{else}:\\
            \;\;\;\;t\_0\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if z < -1e129 or 1.6e257 < z

              1. Initial program 99.7%

                \[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. mul-1-negN/A

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

                  \[\leadsto \color{blue}{x - y \cdot z} \]
                3. lower--.f64N/A

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

                  \[\leadsto x - \color{blue}{z \cdot y} \]
                5. lower-*.f6452.1

                  \[\leadsto x - \color{blue}{z \cdot y} \]
              5. Applied rewrites52.1%

                \[\leadsto \color{blue}{x - z \cdot y} \]
              6. Taylor expanded in z around inf

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

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

                if -1e129 < z < 1.6e257

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

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

                  \[\leadsto \color{blue}{\cos y \cdot x} \]
                6. Taylor expanded in y around 0

                  \[\leadsto 1 \cdot x \]
                7. Step-by-step derivation
                  1. Applied rewrites50.1%

                    \[\leadsto 1 \cdot x \]
                8. Recombined 2 regimes into one program.
                9. Add Preprocessing

                Alternative 9: 52.8% 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. mul-1-negN/A

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

                    \[\leadsto \color{blue}{x - y \cdot z} \]
                  3. lower--.f64N/A

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

                    \[\leadsto x - \color{blue}{z \cdot y} \]
                  5. lower-*.f6458.6

                    \[\leadsto x - \color{blue}{z \cdot y} \]
                5. Applied rewrites58.6%

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

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

                  Alternative 10: 52.8% accurate, 23.8× speedup?

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

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

                      \[\leadsto \color{blue}{x - y \cdot z} \]
                    3. lower--.f64N/A

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

                      \[\leadsto x - \color{blue}{z \cdot y} \]
                    5. lower-*.f6458.6

                      \[\leadsto x - \color{blue}{z \cdot y} \]
                  5. Applied rewrites58.6%

                    \[\leadsto \color{blue}{x - z \cdot y} \]
                  6. Add Preprocessing

                  Alternative 11: 38.9% accurate, 35.7× speedup?

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

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

                    \[\leadsto \color{blue}{\cos y \cdot x} \]
                  6. Taylor expanded in y around 0

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

                      \[\leadsto 1 \cdot x \]
                    2. Add Preprocessing

                    Reproduce

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