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

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

\\
\cos y \cdot x - \sin y \cdot z
\end{array}
Derivation
  1. Initial program 99.8%

    \[x \cdot \cos y - z \cdot \sin y \]
  2. Add Preprocessing
  3. Final simplification99.8%

    \[\leadsto \cos y \cdot x - \sin y \cdot z \]
  4. Add Preprocessing

Alternative 2: 76.0% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos y \cdot x\\ t_1 := \left(-z\right) \cdot \sin y\\ \mathbf{if}\;y \leq -4 \cdot 10^{+105}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq -4.1 \cdot 10^{+39}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq -0.027:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 1.6:\\ \;\;\;\;\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 2 \cdot 10^{+167}:\\ \;\;\;\;{\left({t\_0}^{-1}\right)}^{-1}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* (cos y) x)) (t_1 (* (- z) (sin y))))
   (if (<= y -4e+105)
     t_0
     (if (<= y -4.1e+39)
       t_1
       (if (<= y -0.027)
         t_0
         (if (<= y 1.6)
           (fma (- (* (fma 0.16666666666666666 (* z y) (* -0.5 x)) y) z) y x)
           (if (<= y 2e+167) (pow (pow t_0 -1.0) -1.0) t_1)))))))
double code(double x, double y, double z) {
	double t_0 = cos(y) * x;
	double t_1 = -z * sin(y);
	double tmp;
	if (y <= -4e+105) {
		tmp = t_0;
	} else if (y <= -4.1e+39) {
		tmp = t_1;
	} else if (y <= -0.027) {
		tmp = t_0;
	} else if (y <= 1.6) {
		tmp = fma(((fma(0.16666666666666666, (z * y), (-0.5 * x)) * y) - z), y, x);
	} else if (y <= 2e+167) {
		tmp = pow(pow(t_0, -1.0), -1.0);
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z)
	t_0 = Float64(cos(y) * x)
	t_1 = Float64(Float64(-z) * sin(y))
	tmp = 0.0
	if (y <= -4e+105)
		tmp = t_0;
	elseif (y <= -4.1e+39)
		tmp = t_1;
	elseif (y <= -0.027)
		tmp = t_0;
	elseif (y <= 1.6)
		tmp = fma(Float64(Float64(fma(0.16666666666666666, Float64(z * y), Float64(-0.5 * x)) * y) - z), y, x);
	elseif (y <= 2e+167)
		tmp = (t_0 ^ -1.0) ^ -1.0;
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]}, Block[{t$95$1 = N[((-z) * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4e+105], t$95$0, If[LessEqual[y, -4.1e+39], t$95$1, If[LessEqual[y, -0.027], t$95$0, If[LessEqual[y, 1.6], 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, 2e+167], N[Power[N[Power[t$95$0, -1.0], $MachinePrecision], -1.0], $MachinePrecision], t$95$1]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;y \leq -4.1 \cdot 10^{+39}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y \leq -0.027:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 1.6:\\
\;\;\;\;\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 2 \cdot 10^{+167}:\\
\;\;\;\;{\left({t\_0}^{-1}\right)}^{-1}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < -3.9999999999999998e105 or -4.10000000000000004e39 < y < -0.0269999999999999997

    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.f6471.6

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

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

    if -3.9999999999999998e105 < y < -4.10000000000000004e39 or 2.0000000000000001e167 < y

    1. Initial program 99.6%

      \[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.f6471.7

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

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

    if -0.0269999999999999997 < y < 1.6000000000000001

    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-*.f6498.8

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

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

    if 1.6000000000000001 < y < 2.0000000000000001e167

    1. Initial program 99.6%

      \[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. flip--N/A

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

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

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

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

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{x \cdot \cos y - z \cdot \sin y}}} \]
      7. lift--.f64N/A

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{x \cdot \cos y - z \cdot \sin y}}} \]
      8. inv-powN/A

        \[\leadsto \frac{1}{\color{blue}{{\left(x \cdot \cos y - z \cdot \sin y\right)}^{-1}}} \]
      9. lower-pow.f6499.5

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{x \cdot \cos y}}} \]
    6. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{x \cdot \cos y}}} \]
      2. *-commutativeN/A

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

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{\cos y \cdot x}}} \]
      4. lower-cos.f6464.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4 \cdot 10^{+105}:\\ \;\;\;\;\cos y \cdot x\\ \mathbf{elif}\;y \leq -4.1 \cdot 10^{+39}:\\ \;\;\;\;\left(-z\right) \cdot \sin y\\ \mathbf{elif}\;y \leq -0.027:\\ \;\;\;\;\cos y \cdot x\\ \mathbf{elif}\;y \leq 1.6:\\ \;\;\;\;\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 2 \cdot 10^{+167}:\\ \;\;\;\;{\left({\left(\cos y \cdot x\right)}^{-1}\right)}^{-1}\\ \mathbf{else}:\\ \;\;\;\;\left(-z\right) \cdot \sin y\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 76.0% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos y \cdot x\\ t_1 := \left(-z\right) \cdot \sin y\\ \mathbf{if}\;y \leq -4 \cdot 10^{+105}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq -4.1 \cdot 10^{+39}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq -0.027:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 1.6:\\ \;\;\;\;\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 2 \cdot 10^{+167}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* (cos y) x)) (t_1 (* (- z) (sin y))))
   (if (<= y -4e+105)
     t_0
     (if (<= y -4.1e+39)
       t_1
       (if (<= y -0.027)
         t_0
         (if (<= y 1.6)
           (fma (- (* (fma 0.16666666666666666 (* z y) (* -0.5 x)) y) z) y x)
           (if (<= y 2e+167) t_0 t_1)))))))
double code(double x, double y, double z) {
	double t_0 = cos(y) * x;
	double t_1 = -z * sin(y);
	double tmp;
	if (y <= -4e+105) {
		tmp = t_0;
	} else if (y <= -4.1e+39) {
		tmp = t_1;
	} else if (y <= -0.027) {
		tmp = t_0;
	} else if (y <= 1.6) {
		tmp = fma(((fma(0.16666666666666666, (z * y), (-0.5 * x)) * y) - z), y, x);
	} else if (y <= 2e+167) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z)
	t_0 = Float64(cos(y) * x)
	t_1 = Float64(Float64(-z) * sin(y))
	tmp = 0.0
	if (y <= -4e+105)
		tmp = t_0;
	elseif (y <= -4.1e+39)
		tmp = t_1;
	elseif (y <= -0.027)
		tmp = t_0;
	elseif (y <= 1.6)
		tmp = fma(Float64(Float64(fma(0.16666666666666666, Float64(z * y), Float64(-0.5 * x)) * y) - z), y, x);
	elseif (y <= 2e+167)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]}, Block[{t$95$1 = N[((-z) * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4e+105], t$95$0, If[LessEqual[y, -4.1e+39], t$95$1, If[LessEqual[y, -0.027], t$95$0, If[LessEqual[y, 1.6], 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, 2e+167], t$95$0, t$95$1]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;y \leq -4.1 \cdot 10^{+39}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y \leq -0.027:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 1.6:\\
\;\;\;\;\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 2 \cdot 10^{+167}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -3.9999999999999998e105 or -4.10000000000000004e39 < y < -0.0269999999999999997 or 1.6000000000000001 < y < 2.0000000000000001e167

    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.f6468.8

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

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

    if -3.9999999999999998e105 < y < -4.10000000000000004e39 or 2.0000000000000001e167 < y

    1. Initial program 99.6%

      \[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.f6471.7

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

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

    if -0.0269999999999999997 < y < 1.6000000000000001

    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-*.f6498.8

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

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

Alternative 4: 75.0% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -0.027 \lor \neg \left(y \leq 1.6\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.027) (not (<= y 1.6)))
   (* (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.027) || !(y <= 1.6)) {
		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.027) || !(y <= 1.6))
		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.027], N[Not[LessEqual[y, 1.6]], $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.027 \lor \neg \left(y \leq 1.6\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.0269999999999999997 or 1.6000000000000001 < y

    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 -0.0269999999999999997 < y < 1.6000000000000001

    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-*.f6498.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -0.027 \lor \neg \left(y \leq 1.6\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 5: 41.7% accurate, 10.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.6 \cdot 10^{+77} \lor \neg \left(z \leq 2.3 \cdot 10^{+116}\right):\\
\;\;\;\;\left(-z\right) \cdot y\\

\mathbf{else}:\\
\;\;\;\;1 \cdot x\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -2.6000000000000002e77 or 2.29999999999999995e116 < 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. 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-*.f6451.5

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

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

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

      if -2.6000000000000002e77 < z < 2.29999999999999995e116

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

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

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

          \[\leadsto 1 \cdot x \]
      8. Recombined 2 regimes into one program.
      9. Final simplification41.1%

        \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.6 \cdot 10^{+77} \lor \neg \left(z \leq 2.3 \cdot 10^{+116}\right):\\ \;\;\;\;\left(-z\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x\\ \end{array} \]
      10. Add Preprocessing

      Alternative 6: 52.3% 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-*.f6451.2

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

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

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

        Alternative 7: 52.3% 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-*.f6451.2

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

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

        Alternative 8: 38.6% 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.f6461.9

            \[\leadsto \color{blue}{\cos y} \cdot x \]
        5. Applied rewrites61.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 rewrites37.3%

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

          Reproduce

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