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} \\ \mathsf{fma}\left(\cos y, x, \sin y \cdot \left(-z\right)\right) \end{array} \]
(FPCore (x y z) :precision binary64 (fma (cos y) x (* (sin y) (- z))))
double code(double x, double y, double z) {
	return fma(cos(y), x, (sin(y) * -z));
}
function code(x, y, z)
	return fma(cos(y), x, Float64(sin(y) * Float64(-z)))
end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * x + N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(\cos y, x, \sin y \cdot \left(-z\right)\right)
\end{array}
Derivation
  1. Initial program 99.8%

    \[x \cdot \cos y - z \cdot \sin y \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift--.f64N/A

      \[\leadsto \color{blue}{x \cdot \cos y - z \cdot \sin y} \]
    2. sub-negN/A

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(\cos y, x, \left(-z\right) \cdot \sin y\right)} \]
  5. Final simplification99.8%

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

Alternative 2: 99.8% accurate, 1.0× speedup?

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

\\
x \cdot \cos y - \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 x \cdot \cos y - \sin y \cdot z \]
  4. Add Preprocessing

Alternative 3: 74.1% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sin y \cdot \left(-z\right)\\ \mathbf{if}\;y \leq -12500000:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 9.2 \cdot 10^{-7}:\\ \;\;\;\;x - z \cdot y\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{+19}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;x \cdot \cos y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* (sin y) (- z))))
   (if (<= y -12500000.0)
     t_0
     (if (<= y 9.2e-7) (- x (* z y)) (if (<= y 1.15e+19) t_0 (* x (cos y)))))))
double code(double x, double y, double z) {
	double t_0 = sin(y) * -z;
	double tmp;
	if (y <= -12500000.0) {
		tmp = t_0;
	} else if (y <= 9.2e-7) {
		tmp = x - (z * y);
	} else if (y <= 1.15e+19) {
		tmp = t_0;
	} else {
		tmp = x * cos(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) :: t_0
    real(8) :: tmp
    t_0 = sin(y) * -z
    if (y <= (-12500000.0d0)) then
        tmp = t_0
    else if (y <= 9.2d-7) then
        tmp = x - (z * y)
    else if (y <= 1.15d+19) then
        tmp = t_0
    else
        tmp = x * cos(y)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = Math.sin(y) * -z;
	double tmp;
	if (y <= -12500000.0) {
		tmp = t_0;
	} else if (y <= 9.2e-7) {
		tmp = x - (z * y);
	} else if (y <= 1.15e+19) {
		tmp = t_0;
	} else {
		tmp = x * Math.cos(y);
	}
	return tmp;
}
def code(x, y, z):
	t_0 = math.sin(y) * -z
	tmp = 0
	if y <= -12500000.0:
		tmp = t_0
	elif y <= 9.2e-7:
		tmp = x - (z * y)
	elif y <= 1.15e+19:
		tmp = t_0
	else:
		tmp = x * math.cos(y)
	return tmp
function code(x, y, z)
	t_0 = Float64(sin(y) * Float64(-z))
	tmp = 0.0
	if (y <= -12500000.0)
		tmp = t_0;
	elseif (y <= 9.2e-7)
		tmp = Float64(x - Float64(z * y));
	elseif (y <= 1.15e+19)
		tmp = t_0;
	else
		tmp = Float64(x * cos(y));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = sin(y) * -z;
	tmp = 0.0;
	if (y <= -12500000.0)
		tmp = t_0;
	elseif (y <= 9.2e-7)
		tmp = x - (z * y);
	elseif (y <= 1.15e+19)
		tmp = t_0;
	else
		tmp = x * cos(y);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision]}, If[LessEqual[y, -12500000.0], t$95$0, If[LessEqual[y, 9.2e-7], N[(x - N[(z * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.15e+19], t$95$0, N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sin y \cdot \left(-z\right)\\
\mathbf{if}\;y \leq -12500000:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 9.2 \cdot 10^{-7}:\\
\;\;\;\;x - z \cdot y\\

\mathbf{elif}\;y \leq 1.15 \cdot 10^{+19}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.25e7 or 9.1999999999999998e-7 < y < 1.15e19

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

    if -1.25e7 < y < 9.1999999999999998e-7

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x + -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-*.f6498.7

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

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

    if 1.15e19 < y

    1. Initial program 99.6%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -12500000:\\ \;\;\;\;\sin y \cdot \left(-z\right)\\ \mathbf{elif}\;y \leq 9.2 \cdot 10^{-7}:\\ \;\;\;\;x - z \cdot y\\ \mathbf{elif}\;y \leq 1.15 \cdot 10^{+19}:\\ \;\;\;\;\sin y \cdot \left(-z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \cos y\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 85.8% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 \cdot x - \sin y \cdot z\\ \mathbf{if}\;z \leq -2.4 \cdot 10^{-45}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{-42}:\\ \;\;\;\;x \cdot \cos y\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (- (* 1.0 x) (* (sin y) z))))
   (if (<= z -2.4e-45) t_0 (if (<= z 1.35e-42) (* x (cos y)) t_0))))
double code(double x, double y, double z) {
	double t_0 = (1.0 * x) - (sin(y) * z);
	double tmp;
	if (z <= -2.4e-45) {
		tmp = t_0;
	} else if (z <= 1.35e-42) {
		tmp = x * cos(y);
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (1.0d0 * x) - (sin(y) * z)
    if (z <= (-2.4d-45)) then
        tmp = t_0
    else if (z <= 1.35d-42) then
        tmp = x * cos(y)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = (1.0 * x) - (Math.sin(y) * z);
	double tmp;
	if (z <= -2.4e-45) {
		tmp = t_0;
	} else if (z <= 1.35e-42) {
		tmp = x * Math.cos(y);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = (1.0 * x) - (math.sin(y) * z)
	tmp = 0
	if z <= -2.4e-45:
		tmp = t_0
	elif z <= 1.35e-42:
		tmp = x * math.cos(y)
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(1.0 * x) - Float64(sin(y) * z))
	tmp = 0.0
	if (z <= -2.4e-45)
		tmp = t_0;
	elseif (z <= 1.35e-42)
		tmp = Float64(x * cos(y));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = (1.0 * x) - (sin(y) * z);
	tmp = 0.0;
	if (z <= -2.4e-45)
		tmp = t_0;
	elseif (z <= 1.35e-42)
		tmp = x * cos(y);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 * x), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.4e-45], t$95$0, If[LessEqual[z, 1.35e-42], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 1 \cdot x - \sin y \cdot z\\
\mathbf{if}\;z \leq -2.4 \cdot 10^{-45}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;z \leq 1.35 \cdot 10^{-42}:\\
\;\;\;\;x \cdot \cos y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -2.3999999999999999e-45 or 1.35e-42 < z

    1. Initial program 99.8%

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

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

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

      if -2.3999999999999999e-45 < z < 1.35e-42

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

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

        \[\leadsto \color{blue}{\cos y \cdot x} \]
    5. Recombined 2 regimes into one program.
    6. Final simplification89.2%

      \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.4 \cdot 10^{-45}:\\ \;\;\;\;1 \cdot x - \sin y \cdot z\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{-42}:\\ \;\;\;\;x \cdot \cos y\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x - \sin y \cdot z\\ \end{array} \]
    7. Add Preprocessing

    Alternative 5: 75.0% accurate, 1.8× speedup?

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

      1. Initial program 99.5%

        \[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.f6448.2

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

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

      if -0.214999999999999997 < y < 5.5e18

      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-*.f6496.5

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

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

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

    Alternative 6: 42.0% accurate, 10.7× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.18 \cdot 10^{-153}:\\ \;\;\;\;1 \cdot x\\ \mathbf{elif}\;x \leq 8.2 \cdot 10^{-228}:\\ \;\;\;\;\left(-z\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;1 \cdot x\\ \end{array} \end{array} \]
    (FPCore (x y z)
     :precision binary64
     (if (<= x -1.18e-153) (* 1.0 x) (if (<= x 8.2e-228) (* (- z) y) (* 1.0 x))))
    double code(double x, double y, double z) {
    	double tmp;
    	if (x <= -1.18e-153) {
    		tmp = 1.0 * x;
    	} else if (x <= 8.2e-228) {
    		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 (x <= (-1.18d-153)) then
            tmp = 1.0d0 * x
        else if (x <= 8.2d-228) 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 (x <= -1.18e-153) {
    		tmp = 1.0 * x;
    	} else if (x <= 8.2e-228) {
    		tmp = -z * y;
    	} else {
    		tmp = 1.0 * x;
    	}
    	return tmp;
    }
    
    def code(x, y, z):
    	tmp = 0
    	if x <= -1.18e-153:
    		tmp = 1.0 * x
    	elif x <= 8.2e-228:
    		tmp = -z * y
    	else:
    		tmp = 1.0 * x
    	return tmp
    
    function code(x, y, z)
    	tmp = 0.0
    	if (x <= -1.18e-153)
    		tmp = Float64(1.0 * x);
    	elseif (x <= 8.2e-228)
    		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 (x <= -1.18e-153)
    		tmp = 1.0 * x;
    	elseif (x <= 8.2e-228)
    		tmp = -z * y;
    	else
    		tmp = 1.0 * x;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_, y_, z_] := If[LessEqual[x, -1.18e-153], N[(1.0 * x), $MachinePrecision], If[LessEqual[x, 8.2e-228], N[((-z) * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;x \leq -1.18 \cdot 10^{-153}:\\
    \;\;\;\;1 \cdot x\\
    
    \mathbf{elif}\;x \leq 8.2 \cdot 10^{-228}:\\
    \;\;\;\;\left(-z\right) \cdot y\\
    
    \mathbf{else}:\\
    \;\;\;\;1 \cdot x\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < -1.1800000000000001e-153 or 8.19999999999999995e-228 < x

      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. Taylor expanded in x around inf

        \[\leadsto x \cdot \color{blue}{\left(1 + -1 \cdot \frac{y \cdot z}{x}\right)} \]
      7. Step-by-step derivation
        1. Applied rewrites51.2%

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

          \[\leadsto 1 \cdot x \]
        3. Step-by-step derivation
          1. Applied rewrites46.4%

            \[\leadsto 1 \cdot x \]

          if -1.1800000000000001e-153 < x < 8.19999999999999995e-228

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

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

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

              \[\leadsto \left(-z\right) \cdot \color{blue}{y} \]
          8. Recombined 2 regimes into one program.
          9. Add Preprocessing

          Alternative 7: 52.4% 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.3

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

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

          Alternative 8: 38.5% 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 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.3

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

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

            \[\leadsto x \cdot \color{blue}{\left(1 + -1 \cdot \frac{y \cdot z}{x}\right)} \]
          7. Step-by-step derivation
            1. Applied rewrites50.2%

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

              \[\leadsto 1 \cdot x \]
            3. Step-by-step derivation
              1. Applied rewrites40.0%

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

              Reproduce

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