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

Percentage Accurate: 99.8% → 99.8%
Time: 9.7s
Alternatives: 6
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 6 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.8% accurate, 1.0× speedup?

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

\\
x \cdot \cos y - z \cdot \sin y
\end{array}

Alternative 1: 99.8% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.8% accurate, 1.0× speedup?

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

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

    \[x \cdot \cos y - z \cdot \sin y \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 3: 85.3% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;x \leq -1.7 \cdot 10^{+67}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;x \leq 1.1 \cdot 10^{-38}:\\
\;\;\;\;x - z \cdot \sin y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.7000000000000001e67 or 1.10000000000000004e-38 < 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 + 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-*.f6450.3

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

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

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

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

        \[\leadsto \color{blue}{x \cdot \cos y} \]
      3. 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.f6487.9

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

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

      if -1.7000000000000001e67 < x < 1.10000000000000004e-38

      1. Initial program 99.8%

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

          \[\leadsto x \cdot \color{blue}{\cos y} - z \cdot \sin y \]
        2. sin-+PI/2-revN/A

          \[\leadsto x \cdot \color{blue}{\sin \left(y + \frac{\mathsf{PI}\left(\right)}{2}\right)} - z \cdot \sin y \]
        3. div-invN/A

          \[\leadsto x \cdot \sin \left(y + \color{blue}{\mathsf{PI}\left(\right) \cdot \frac{1}{2}}\right) - z \cdot \sin y \]
        4. cancel-sign-sub-invN/A

          \[\leadsto x \cdot \sin \color{blue}{\left(y - \left(\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)\right) \cdot \frac{1}{2}\right)} - z \cdot \sin y \]
        5. sin-diffN/A

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

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

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

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

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

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

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

          \[\leadsto x \cdot \left(\sin y \cdot \cos \left(\left(-\color{blue}{\mathsf{PI}\left(\right)}\right) \cdot \frac{1}{2}\right) - \cos y \cdot \sin \left(\left(\mathsf{neg}\left(\mathsf{PI}\left(\right)\right)\right) \cdot \frac{1}{2}\right)\right) - z \cdot \sin y \]
        13. metadata-evalN/A

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

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

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

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

        \[\leadsto x \cdot \color{blue}{\left(\sin y \cdot \cos \left(\left(-\mathsf{PI}\left(\right)\right) \cdot 0.5\right) - \cos y \cdot \sin \left(\left(-\mathsf{PI}\left(\right)\right) \cdot 0.5\right)\right)} - z \cdot \sin y \]
      5. Taylor expanded in y around 0

        \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \sin \left(\frac{-1}{2} \cdot \mathsf{PI}\left(\right)\right)\right)} - z \cdot \sin y \]
      6. Step-by-step derivation
        1. mul-1-negN/A

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

          \[\leadsto \color{blue}{x \cdot \left(\mathsf{neg}\left(\sin \left(\frac{-1}{2} \cdot \mathsf{PI}\left(\right)\right)\right)\right)} - z \cdot \sin y \]
        3. sin-neg-revN/A

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

          \[\leadsto x \cdot \sin \left(\mathsf{neg}\left(\color{blue}{\mathsf{PI}\left(\right) \cdot \frac{-1}{2}}\right)\right) - z \cdot \sin y \]
        5. distribute-rgt-neg-inN/A

          \[\leadsto x \cdot \sin \color{blue}{\left(\mathsf{PI}\left(\right) \cdot \left(\mathsf{neg}\left(\frac{-1}{2}\right)\right)\right)} - z \cdot \sin y \]
        6. metadata-evalN/A

          \[\leadsto x \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \color{blue}{\frac{1}{2}}\right) - z \cdot \sin y \]
        7. metadata-evalN/A

          \[\leadsto x \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \color{blue}{\frac{1}{2}}\right) - z \cdot \sin y \]
        8. associate-/l*N/A

          \[\leadsto x \cdot \sin \color{blue}{\left(\frac{\mathsf{PI}\left(\right) \cdot 1}{2}\right)} - z \cdot \sin y \]
        9. *-rgt-identity-revN/A

          \[\leadsto x \cdot \sin \left(\frac{\color{blue}{\mathsf{PI}\left(\right)}}{2}\right) - z \cdot \sin y \]
        10. sin-PI/2N/A

          \[\leadsto x \cdot \color{blue}{1} - z \cdot \sin y \]
        11. *-rgt-identity86.4

          \[\leadsto \color{blue}{x} - z \cdot \sin y \]
      7. Applied rewrites86.4%

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.7 \cdot 10^{+67}:\\ \;\;\;\;x \cdot \cos y\\ \mathbf{elif}\;x \leq 1.1 \cdot 10^{-38}:\\ \;\;\;\;x - z \cdot \sin y\\ \mathbf{else}:\\ \;\;\;\;x \cdot \cos y\\ \end{array} \]
    10. Add Preprocessing

    Alternative 4: 75.1% accurate, 1.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \cos y\\ \mathbf{if}\;y \leq -0.07:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 0.135:\\ \;\;\;\;\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.07)
         t_0
         (if (<= y 0.135)
           (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.07) {
    		tmp = t_0;
    	} else if (y <= 0.135) {
    		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.07)
    		tmp = t_0;
    	elseif (y <= 0.135)
    		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.07], t$95$0, If[LessEqual[y, 0.135], 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.07:\\
    \;\;\;\;t\_0\\
    
    \mathbf{elif}\;y \leq 0.135:\\
    \;\;\;\;\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.070000000000000007 or 0.13500000000000001 < y

      1. Initial program 99.6%

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

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

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

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

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

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

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

        if -0.070000000000000007 < y < 0.13500000000000001

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

        \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -0.07:\\ \;\;\;\;x \cdot \cos y\\ \mathbf{elif}\;y \leq 0.135:\\ \;\;\;\;\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} \]
      10. Add Preprocessing

      Alternative 5: 52.6% 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-*.f6454.1

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

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

      Alternative 6: 17.1% accurate, 26.8× speedup?

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

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

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

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

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

        Reproduce

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