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

Percentage Accurate: 99.8% → 99.8%
Time: 7.6s
Alternatives: 8
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 8 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: 74.2% accurate, 1.6× speedup?

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

\\
\begin{array}{l}
t_0 := \left(-z\right) \cdot \sin y\\
t_1 := \cos y \cdot x\\
\mathbf{if}\;y \leq -4.05 \cdot 10^{+96}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq -0.034:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y \leq 2.5 \cdot 10^{-12}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, z \cdot y, -0.5 \cdot x\right) \cdot y - z, y, x\right)\\

\mathbf{elif}\;y \leq 6 \cdot 10^{+120}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -4.0500000000000001e96 or 6e120 < y

    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.f6462.0

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

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

    if -4.0500000000000001e96 < y < -0.034000000000000002 or 2.49999999999999985e-12 < y < 6e120

    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. lift-*.f64N/A

        \[\leadsto x \cdot \cos y - \color{blue}{z \cdot \sin y} \]
      3. fp-cancel-sub-sign-invN/A

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

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

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

        \[\leadsto \color{blue}{\sqrt{{\left(x \cdot \cos y\right)}^{2}}} + \left(\mathsf{neg}\left(z\right)\right) \cdot \sin y \]
      7. pow2N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(\cos y \cdot {\left(\sqrt{-1}\right)}^{2}\right)\right)} \]
    6. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \color{blue}{\mathsf{neg}\left(x \cdot \left(\cos y \cdot {\left(\sqrt{-1}\right)}^{2}\right)\right)} \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{neg}\left(\color{blue}{\left(\cos y \cdot {\left(\sqrt{-1}\right)}^{2}\right) \cdot x}\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{neg}\left(\color{blue}{\left({\left(\sqrt{-1}\right)}^{2} \cdot \cos y\right)} \cdot x\right) \]
      4. unpow2N/A

        \[\leadsto \mathsf{neg}\left(\left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot \cos y\right) \cdot x\right) \]
      5. rem-square-sqrtN/A

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

        \[\leadsto \mathsf{neg}\left(\color{blue}{\left(\cos y \cdot -1\right)} \cdot x\right) \]
      7. associate-*l*N/A

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

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

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

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

        \[\leadsto \cos y \cdot \color{blue}{\left(\left(\mathsf{neg}\left(-1\right)\right) \cdot x\right)} \]
      12. metadata-evalN/A

        \[\leadsto \cos y \cdot \left(\color{blue}{1} \cdot x\right) \]
      13. *-lft-identityN/A

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

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

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

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

    if -0.034000000000000002 < y < 2.49999999999999985e-12

    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-*.f64100.0

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

      \[\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 3 regimes into one program.
  4. Final simplification82.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4.05 \cdot 10^{+96}:\\ \;\;\;\;\left(-z\right) \cdot \sin y\\ \mathbf{elif}\;y \leq -0.034:\\ \;\;\;\;\cos y \cdot x\\ \mathbf{elif}\;y \leq 2.5 \cdot 10^{-12}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, z \cdot y, -0.5 \cdot x\right) \cdot y - z, y, x\right)\\ \mathbf{elif}\;y \leq 6 \cdot 10^{+120}:\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(-z\right) \cdot \sin y\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 85.2% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.9 \cdot 10^{+56} \lor \neg \left(x \leq 2.2 \cdot 10^{+165}\right):\\
\;\;\;\;\cos y \cdot x\\

\mathbf{else}:\\
\;\;\;\;x \cdot 1 - z \cdot \sin y\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -3.89999999999999994e56 or 2.1999999999999999e165 < x

    1. Initial program 99.9%

      \[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. lift-*.f64N/A

        \[\leadsto x \cdot \cos y - \color{blue}{z \cdot \sin y} \]
      3. fp-cancel-sub-sign-invN/A

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

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

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

        \[\leadsto \color{blue}{\sqrt{{\left(x \cdot \cos y\right)}^{2}}} + \left(\mathsf{neg}\left(z\right)\right) \cdot \sin y \]
      7. pow2N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(\cos y \cdot {\left(\sqrt{-1}\right)}^{2}\right)\right)} \]
    6. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \color{blue}{\mathsf{neg}\left(x \cdot \left(\cos y \cdot {\left(\sqrt{-1}\right)}^{2}\right)\right)} \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{neg}\left(\color{blue}{\left(\cos y \cdot {\left(\sqrt{-1}\right)}^{2}\right) \cdot x}\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{neg}\left(\color{blue}{\left({\left(\sqrt{-1}\right)}^{2} \cdot \cos y\right)} \cdot x\right) \]
      4. unpow2N/A

        \[\leadsto \mathsf{neg}\left(\left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot \cos y\right) \cdot x\right) \]
      5. rem-square-sqrtN/A

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

        \[\leadsto \mathsf{neg}\left(\color{blue}{\left(\cos y \cdot -1\right)} \cdot x\right) \]
      7. associate-*l*N/A

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

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

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

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

        \[\leadsto \cos y \cdot \color{blue}{\left(\left(\mathsf{neg}\left(-1\right)\right) \cdot x\right)} \]
      12. metadata-evalN/A

        \[\leadsto \cos y \cdot \left(\color{blue}{1} \cdot x\right) \]
      13. *-lft-identityN/A

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

        \[\leadsto \color{blue}{\cos y \cdot x} \]
      15. lower-cos.f6491.6

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

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

    if -3.89999999999999994e56 < x < 2.1999999999999999e165

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.9 \cdot 10^{+56} \lor \neg \left(x \leq 2.2 \cdot 10^{+165}\right):\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;x \cdot 1 - z \cdot \sin y\\ \end{array} \]
    7. Add Preprocessing

    Alternative 4: 84.3% accurate, 1.7× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -3.9 \cdot 10^{+56}:\\ \;\;\;\;\cos y \cdot x\\ \mathbf{elif}\;x \leq 1.55 \cdot 10^{+146}:\\ \;\;\;\;x \cdot 1 - z \cdot \sin y\\ \mathbf{else}:\\ \;\;\;\;x \cdot \cos y - z \cdot y\\ \end{array} \end{array} \]
    (FPCore (x y z)
     :precision binary64
     (if (<= x -3.9e+56)
       (* (cos y) x)
       (if (<= x 1.55e+146)
         (- (* x 1.0) (* z (sin y)))
         (- (* x (cos y)) (* z y)))))
    double code(double x, double y, double z) {
    	double tmp;
    	if (x <= -3.9e+56) {
    		tmp = cos(y) * x;
    	} else if (x <= 1.55e+146) {
    		tmp = (x * 1.0) - (z * sin(y));
    	} else {
    		tmp = (x * cos(y)) - (z * y);
    	}
    	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 (x <= (-3.9d+56)) then
            tmp = cos(y) * x
        else if (x <= 1.55d+146) then
            tmp = (x * 1.0d0) - (z * sin(y))
        else
            tmp = (x * cos(y)) - (z * y)
        end if
        code = tmp
    end function
    
    public static double code(double x, double y, double z) {
    	double tmp;
    	if (x <= -3.9e+56) {
    		tmp = Math.cos(y) * x;
    	} else if (x <= 1.55e+146) {
    		tmp = (x * 1.0) - (z * Math.sin(y));
    	} else {
    		tmp = (x * Math.cos(y)) - (z * y);
    	}
    	return tmp;
    }
    
    def code(x, y, z):
    	tmp = 0
    	if x <= -3.9e+56:
    		tmp = math.cos(y) * x
    	elif x <= 1.55e+146:
    		tmp = (x * 1.0) - (z * math.sin(y))
    	else:
    		tmp = (x * math.cos(y)) - (z * y)
    	return tmp
    
    function code(x, y, z)
    	tmp = 0.0
    	if (x <= -3.9e+56)
    		tmp = Float64(cos(y) * x);
    	elseif (x <= 1.55e+146)
    		tmp = Float64(Float64(x * 1.0) - Float64(z * sin(y)));
    	else
    		tmp = Float64(Float64(x * cos(y)) - Float64(z * y));
    	end
    	return tmp
    end
    
    function tmp_2 = code(x, y, z)
    	tmp = 0.0;
    	if (x <= -3.9e+56)
    		tmp = cos(y) * x;
    	elseif (x <= 1.55e+146)
    		tmp = (x * 1.0) - (z * sin(y));
    	else
    		tmp = (x * cos(y)) - (z * y);
    	end
    	tmp_2 = tmp;
    end
    
    code[x_, y_, z_] := If[LessEqual[x, -3.9e+56], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], If[LessEqual[x, 1.55e+146], N[(N[(x * 1.0), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;x \leq -3.9 \cdot 10^{+56}:\\
    \;\;\;\;\cos y \cdot x\\
    
    \mathbf{elif}\;x \leq 1.55 \cdot 10^{+146}:\\
    \;\;\;\;x \cdot 1 - z \cdot \sin y\\
    
    \mathbf{else}:\\
    \;\;\;\;x \cdot \cos y - z \cdot y\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if x < -3.89999999999999994e56

      1. Initial program 99.9%

        \[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. lift-*.f64N/A

          \[\leadsto x \cdot \cos y - \color{blue}{z \cdot \sin y} \]
        3. fp-cancel-sub-sign-invN/A

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

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

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

          \[\leadsto \color{blue}{\sqrt{{\left(x \cdot \cos y\right)}^{2}}} + \left(\mathsf{neg}\left(z\right)\right) \cdot \sin y \]
        7. pow2N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(\cos y \cdot {\left(\sqrt{-1}\right)}^{2}\right)\right)} \]
      6. Step-by-step derivation
        1. mul-1-negN/A

          \[\leadsto \color{blue}{\mathsf{neg}\left(x \cdot \left(\cos y \cdot {\left(\sqrt{-1}\right)}^{2}\right)\right)} \]
        2. *-commutativeN/A

          \[\leadsto \mathsf{neg}\left(\color{blue}{\left(\cos y \cdot {\left(\sqrt{-1}\right)}^{2}\right) \cdot x}\right) \]
        3. *-commutativeN/A

          \[\leadsto \mathsf{neg}\left(\color{blue}{\left({\left(\sqrt{-1}\right)}^{2} \cdot \cos y\right)} \cdot x\right) \]
        4. unpow2N/A

          \[\leadsto \mathsf{neg}\left(\left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot \cos y\right) \cdot x\right) \]
        5. rem-square-sqrtN/A

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

          \[\leadsto \mathsf{neg}\left(\color{blue}{\left(\cos y \cdot -1\right)} \cdot x\right) \]
        7. associate-*l*N/A

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

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

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

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

          \[\leadsto \cos y \cdot \color{blue}{\left(\left(\mathsf{neg}\left(-1\right)\right) \cdot x\right)} \]
        12. metadata-evalN/A

          \[\leadsto \cos y \cdot \left(\color{blue}{1} \cdot x\right) \]
        13. *-lft-identityN/A

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

          \[\leadsto \color{blue}{\cos y \cdot x} \]
        15. lower-cos.f6489.5

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

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

      if -3.89999999999999994e56 < x < 1.5500000000000001e146

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

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

        if 1.5500000000000001e146 < x

        1. Initial program 99.9%

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

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

            \[\leadsto x \cdot \cos y - \color{blue}{z \cdot y} \]
          2. lower-*.f6492.8

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

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

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

      Alternative 5: 74.7% accurate, 1.8× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -0.034 \lor \neg \left(y \leq 2.5 \cdot 10^{-12}\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.034) (not (<= y 2.5e-12)))
         (* (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.034) || !(y <= 2.5e-12)) {
      		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.034) || !(y <= 2.5e-12))
      		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.034], N[Not[LessEqual[y, 2.5e-12]], $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.034 \lor \neg \left(y \leq 2.5 \cdot 10^{-12}\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.034000000000000002 or 2.49999999999999985e-12 < y

        1. Initial program 99.7%

          \[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. lift-*.f64N/A

            \[\leadsto x \cdot \cos y - \color{blue}{z \cdot \sin y} \]
          3. fp-cancel-sub-sign-invN/A

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

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

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

            \[\leadsto \color{blue}{\sqrt{{\left(x \cdot \cos y\right)}^{2}}} + \left(\mathsf{neg}\left(z\right)\right) \cdot \sin y \]
          7. pow2N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(\cos y \cdot {\left(\sqrt{-1}\right)}^{2}\right)\right)} \]
        6. Step-by-step derivation
          1. mul-1-negN/A

            \[\leadsto \color{blue}{\mathsf{neg}\left(x \cdot \left(\cos y \cdot {\left(\sqrt{-1}\right)}^{2}\right)\right)} \]
          2. *-commutativeN/A

            \[\leadsto \mathsf{neg}\left(\color{blue}{\left(\cos y \cdot {\left(\sqrt{-1}\right)}^{2}\right) \cdot x}\right) \]
          3. *-commutativeN/A

            \[\leadsto \mathsf{neg}\left(\color{blue}{\left({\left(\sqrt{-1}\right)}^{2} \cdot \cos y\right)} \cdot x\right) \]
          4. unpow2N/A

            \[\leadsto \mathsf{neg}\left(\left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot \cos y\right) \cdot x\right) \]
          5. rem-square-sqrtN/A

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

            \[\leadsto \mathsf{neg}\left(\color{blue}{\left(\cos y \cdot -1\right)} \cdot x\right) \]
          7. associate-*l*N/A

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

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

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

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

            \[\leadsto \cos y \cdot \color{blue}{\left(\left(\mathsf{neg}\left(-1\right)\right) \cdot x\right)} \]
          12. metadata-evalN/A

            \[\leadsto \cos y \cdot \left(\color{blue}{1} \cdot x\right) \]
          13. *-lft-identityN/A

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

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

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

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

        if -0.034000000000000002 < y < 2.49999999999999985e-12

        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-*.f64100.0

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

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

        \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -0.034 \lor \neg \left(y \leq 2.5 \cdot 10^{-12}\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} \]
      5. Add Preprocessing

      Alternative 6: 41.2% accurate, 10.7× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -2 \cdot 10^{+118} \lor \neg \left(z \leq 3.7 \cdot 10^{+111}\right):\\ \;\;\;\;\left(-y\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
      (FPCore (x y z)
       :precision binary64
       (if (or (<= z -2e+118) (not (<= z 3.7e+111))) (* (- y) z) x))
      double code(double x, double y, double z) {
      	double tmp;
      	if ((z <= -2e+118) || !(z <= 3.7e+111)) {
      		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 <= (-2d+118)) .or. (.not. (z <= 3.7d+111))) 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 <= -2e+118) || !(z <= 3.7e+111)) {
      		tmp = -y * z;
      	} else {
      		tmp = x;
      	}
      	return tmp;
      }
      
      def code(x, y, z):
      	tmp = 0
      	if (z <= -2e+118) or not (z <= 3.7e+111):
      		tmp = -y * z
      	else:
      		tmp = x
      	return tmp
      
      function code(x, y, z)
      	tmp = 0.0
      	if ((z <= -2e+118) || !(z <= 3.7e+111))
      		tmp = Float64(Float64(-y) * z);
      	else
      		tmp = x;
      	end
      	return tmp
      end
      
      function tmp_2 = code(x, y, z)
      	tmp = 0.0;
      	if ((z <= -2e+118) || ~((z <= 3.7e+111)))
      		tmp = -y * z;
      	else
      		tmp = x;
      	end
      	tmp_2 = tmp;
      end
      
      code[x_, y_, z_] := If[Or[LessEqual[z, -2e+118], N[Not[LessEqual[z, 3.7e+111]], $MachinePrecision]], N[((-y) * z), $MachinePrecision], x]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;z \leq -2 \cdot 10^{+118} \lor \neg \left(z \leq 3.7 \cdot 10^{+111}\right):\\
      \;\;\;\;\left(-y\right) \cdot z\\
      
      \mathbf{else}:\\
      \;\;\;\;x\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if z < -1.99999999999999993e118 or 3.7000000000000003e111 < 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.f6450.8

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

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

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

          if -1.99999999999999993e118 < z < 3.7000000000000003e111

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

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

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

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

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

                \[\leadsto x \]
            4. Recombined 2 regimes into one program.
            5. Final simplification46.7%

              \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2 \cdot 10^{+118} \lor \neg \left(z \leq 3.7 \cdot 10^{+111}\right):\\ \;\;\;\;\left(-y\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
            6. Add Preprocessing

            Alternative 7: 51.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. +-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.f6453.9

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

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

            Alternative 8: 39.0% 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.f6453.9

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

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

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

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

                  \[\leadsto x \]
                2. Add Preprocessing

                Reproduce

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