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

Percentage Accurate: 99.8% → 99.8%
Time: 14.3s
Alternatives: 10
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 10 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) \]
  4. Applied rewrites99.8%

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

Alternative 2: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\cos y, x, -\sin y \cdot z\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(-Float64(sin(y) * 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 z\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. lower-neg.f6499.8

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

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

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

Alternative 3: 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 4: 74.1% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \cos y\\ \mathbf{if}\;y \leq -1.7 \cdot 10^{+17}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 2900:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(0.16666666666666666, y \cdot y, -1\right)\right)\right)\\ \mathbf{elif}\;y \leq 1.95 \cdot 10^{+42}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;-\sin y \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (cos y))))
   (if (<= y -1.7e+17)
     t_0
     (if (<= y 2900.0)
       (fma
        (fma
         (* y y)
         (fma
          (* y y)
          (fma (* y y) -0.001388888888888889 0.041666666666666664)
          -0.5)
         1.0)
        x
        (* y (* z (fma 0.16666666666666666 (* y y) -1.0))))
       (if (<= y 1.95e+42) t_0 (- (* (sin y) z)))))))
double code(double x, double y, double z) {
	double t_0 = x * cos(y);
	double tmp;
	if (y <= -1.7e+17) {
		tmp = t_0;
	} else if (y <= 2900.0) {
		tmp = fma(fma((y * y), fma((y * y), fma((y * y), -0.001388888888888889, 0.041666666666666664), -0.5), 1.0), x, (y * (z * fma(0.16666666666666666, (y * y), -1.0))));
	} else if (y <= 1.95e+42) {
		tmp = t_0;
	} else {
		tmp = -(sin(y) * z);
	}
	return tmp;
}
function code(x, y, z)
	t_0 = Float64(x * cos(y))
	tmp = 0.0
	if (y <= -1.7e+17)
		tmp = t_0;
	elseif (y <= 2900.0)
		tmp = fma(fma(Float64(y * y), fma(Float64(y * y), fma(Float64(y * y), -0.001388888888888889, 0.041666666666666664), -0.5), 1.0), x, Float64(y * Float64(z * fma(0.16666666666666666, Float64(y * y), -1.0))));
	elseif (y <= 1.95e+42)
		tmp = t_0;
	else
		tmp = Float64(-Float64(sin(y) * z));
	end
	return tmp
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.7e+17], t$95$0, If[LessEqual[y, 2900.0], N[(N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * -0.001388888888888889 + 0.041666666666666664), $MachinePrecision] + -0.5), $MachinePrecision] + 1.0), $MachinePrecision] * x + N[(y * N[(z * N[(0.16666666666666666 * N[(y * y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.95e+42], t$95$0, (-N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision])]]]]
\begin{array}{l}

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

\mathbf{elif}\;y \leq 2900:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(0.16666666666666666, y \cdot y, -1\right)\right)\right)\\

\mathbf{elif}\;y \leq 1.95 \cdot 10^{+42}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.7e17 or 2900 < y < 1.94999999999999985e42

    1. Initial program 99.6%

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

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

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

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

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

    if -1.7e17 < y < 2900

    1. Initial program 99.9%

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

        \[\leadsto \color{blue}{x \cdot \cos y - z \cdot \sin y} \]
      2. 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. lower-neg.f64100.0

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\cos y, x, -z \cdot \sin y\right)} \]
    5. Step-by-step derivation
      1. lift-neg.f64N/A

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

        \[\leadsto \mathsf{fma}\left(\cos y, x, \color{blue}{0 - z \cdot \sin y}\right) \]
      3. flip--N/A

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

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

      \[\leadsto \mathsf{fma}\left(\cos y, x, \color{blue}{y \cdot \left(-1 \cdot z + -1 \cdot \left({y}^{2} \cdot \left(\frac{-1}{3} \cdot z - \frac{-1}{6} \cdot z\right)\right)\right)}\right) \]
    8. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\cos y, x, \color{blue}{y \cdot \left(-1 \cdot z + -1 \cdot \left({y}^{2} \cdot \left(\frac{-1}{3} \cdot z - \frac{-1}{6} \cdot z\right)\right)\right)}\right) \]
      2. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \color{blue}{\left(-1 \cdot \left({y}^{2} \cdot \left(\frac{-1}{3} \cdot z - \frac{-1}{6} \cdot z\right)\right) + -1 \cdot z\right)}\right) \]
      3. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(-1 \cdot \color{blue}{\left(\left(\frac{-1}{3} \cdot z - \frac{-1}{6} \cdot z\right) \cdot {y}^{2}\right)} + -1 \cdot z\right)\right) \]
      4. associate-*r*N/A

        \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(\color{blue}{\left(-1 \cdot \left(\frac{-1}{3} \cdot z - \frac{-1}{6} \cdot z\right)\right) \cdot {y}^{2}} + -1 \cdot z\right)\right) \]
      5. distribute-rgt-out--N/A

        \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(\left(-1 \cdot \color{blue}{\left(z \cdot \left(\frac{-1}{3} - \frac{-1}{6}\right)\right)}\right) \cdot {y}^{2} + -1 \cdot z\right)\right) \]
      6. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(\left(-1 \cdot \left(z \cdot \color{blue}{\frac{-1}{6}}\right)\right) \cdot {y}^{2} + -1 \cdot z\right)\right) \]
      7. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(\left(-1 \cdot \color{blue}{\left(\frac{-1}{6} \cdot z\right)}\right) \cdot {y}^{2} + -1 \cdot z\right)\right) \]
      8. associate-*r*N/A

        \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(\color{blue}{\left(\left(-1 \cdot \frac{-1}{6}\right) \cdot z\right)} \cdot {y}^{2} + -1 \cdot z\right)\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(\left(\color{blue}{\frac{1}{6}} \cdot z\right) \cdot {y}^{2} + -1 \cdot z\right)\right) \]
      10. associate-*r*N/A

        \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(\color{blue}{\frac{1}{6} \cdot \left(z \cdot {y}^{2}\right)} + -1 \cdot z\right)\right) \]
      11. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(\frac{1}{6} \cdot \color{blue}{\left({y}^{2} \cdot z\right)} + -1 \cdot z\right)\right) \]
      12. associate-*r*N/A

        \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(\color{blue}{\left(\frac{1}{6} \cdot {y}^{2}\right) \cdot z} + -1 \cdot z\right)\right) \]
      13. distribute-rgt-outN/A

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

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

        \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(z \cdot \color{blue}{\mathsf{fma}\left(\frac{1}{6}, {y}^{2}, -1\right)}\right)\right) \]
      16. unpow2N/A

        \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, \color{blue}{y \cdot y}, -1\right)\right)\right) \]
      17. lower-*.f6497.7

        \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(z \cdot \mathsf{fma}\left(0.16666666666666666, \color{blue}{y \cdot y}, -1\right)\right)\right) \]
    9. Applied rewrites97.7%

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{1 + {y}^{2} \cdot \left({y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) - \frac{1}{2}\right)}, x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
    11. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{{y}^{2} \cdot \left({y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) - \frac{1}{2}\right) + 1}, x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
      2. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left({y}^{2}, {y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) - \frac{1}{2}, 1\right)}, x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{y \cdot y}, {y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) - \frac{1}{2}, 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
      4. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{y \cdot y}, {y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) - \frac{1}{2}, 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
      5. sub-negN/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \color{blue}{{y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}, 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
      6. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, {y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) + \color{blue}{\frac{-1}{2}}, 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
      7. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \color{blue}{\mathsf{fma}\left({y}^{2}, \frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}, \frac{-1}{2}\right)}, 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
      8. unpow2N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(\color{blue}{y \cdot y}, \frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}, \frac{-1}{2}\right), 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
      9. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(\color{blue}{y \cdot y}, \frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}, \frac{-1}{2}\right), 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
      10. +-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \color{blue}{\frac{-1}{720} \cdot {y}^{2} + \frac{1}{24}}, \frac{-1}{2}\right), 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
      11. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \color{blue}{{y}^{2} \cdot \frac{-1}{720}} + \frac{1}{24}, \frac{-1}{2}\right), 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
      12. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \color{blue}{\mathsf{fma}\left({y}^{2}, \frac{-1}{720}, \frac{1}{24}\right)}, \frac{-1}{2}\right), 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
      13. unpow2N/A

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(\color{blue}{y \cdot y}, \frac{-1}{720}, \frac{1}{24}\right), \frac{-1}{2}\right), 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
      14. lower-*.f6497.8

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(\color{blue}{y \cdot y}, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(0.16666666666666666, y \cdot y, -1\right)\right)\right) \]
    12. Applied rewrites97.8%

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

    if 1.94999999999999985e42 < y

    1. Initial program 99.6%

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

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

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

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

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

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

      \[\leadsto \color{blue}{-z \cdot \sin y} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification83.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.7 \cdot 10^{+17}:\\ \;\;\;\;x \cdot \cos y\\ \mathbf{elif}\;y \leq 2900:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(0.16666666666666666, y \cdot y, -1\right)\right)\right)\\ \mathbf{elif}\;y \leq 1.95 \cdot 10^{+42}:\\ \;\;\;\;x \cdot \cos y\\ \mathbf{else}:\\ \;\;\;\;-\sin y \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 84.9% accurate, 1.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -9.19999999999999918e-59 or 2.70000000000000009e-178 < 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 rewrites85.0%

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

      if -9.19999999999999918e-59 < z < 2.70000000000000009e-178

      1. Initial program 99.8%

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

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

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -9.2 \cdot 10^{-59}:\\ \;\;\;\;x \cdot 1 - \sin y \cdot z\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{-178}:\\ \;\;\;\;x \cdot \cos y\\ \mathbf{else}:\\ \;\;\;\;x \cdot 1 - \sin y \cdot z\\ \end{array} \]
    7. Add Preprocessing

    Alternative 6: 73.9% accurate, 1.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \cos y\\ \mathbf{if}\;y \leq -1.7 \cdot 10^{+17}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 2900:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(0.16666666666666666, y \cdot y, -1\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
    (FPCore (x y z)
     :precision binary64
     (let* ((t_0 (* x (cos y))))
       (if (<= y -1.7e+17)
         t_0
         (if (<= y 2900.0)
           (fma
            (fma
             (* y y)
             (fma
              (* y y)
              (fma (* y y) -0.001388888888888889 0.041666666666666664)
              -0.5)
             1.0)
            x
            (* y (* z (fma 0.16666666666666666 (* y y) -1.0))))
           t_0))))
    double code(double x, double y, double z) {
    	double t_0 = x * cos(y);
    	double tmp;
    	if (y <= -1.7e+17) {
    		tmp = t_0;
    	} else if (y <= 2900.0) {
    		tmp = fma(fma((y * y), fma((y * y), fma((y * y), -0.001388888888888889, 0.041666666666666664), -0.5), 1.0), x, (y * (z * fma(0.16666666666666666, (y * y), -1.0))));
    	} else {
    		tmp = t_0;
    	}
    	return tmp;
    }
    
    function code(x, y, z)
    	t_0 = Float64(x * cos(y))
    	tmp = 0.0
    	if (y <= -1.7e+17)
    		tmp = t_0;
    	elseif (y <= 2900.0)
    		tmp = fma(fma(Float64(y * y), fma(Float64(y * y), fma(Float64(y * y), -0.001388888888888889, 0.041666666666666664), -0.5), 1.0), x, Float64(y * Float64(z * fma(0.16666666666666666, Float64(y * y), -1.0))));
    	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, -1.7e+17], t$95$0, If[LessEqual[y, 2900.0], N[(N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * -0.001388888888888889 + 0.041666666666666664), $MachinePrecision] + -0.5), $MachinePrecision] + 1.0), $MachinePrecision] * x + N[(y * N[(z * N[(0.16666666666666666 * N[(y * y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := x \cdot \cos y\\
    \mathbf{if}\;y \leq -1.7 \cdot 10^{+17}:\\
    \;\;\;\;t\_0\\
    
    \mathbf{elif}\;y \leq 2900:\\
    \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(0.16666666666666666, y \cdot y, -1\right)\right)\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_0\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if y < -1.7e17 or 2900 < y

      1. Initial program 99.6%

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

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

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

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

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

      if -1.7e17 < y < 2900

      1. Initial program 99.9%

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

          \[\leadsto \color{blue}{x \cdot \cos y - z \cdot \sin y} \]
        2. 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. lower-neg.f64100.0

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(\cos y, x, -z \cdot \sin y\right)} \]
      5. Step-by-step derivation
        1. lift-neg.f64N/A

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

          \[\leadsto \mathsf{fma}\left(\cos y, x, \color{blue}{0 - z \cdot \sin y}\right) \]
        3. flip--N/A

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

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

        \[\leadsto \mathsf{fma}\left(\cos y, x, \color{blue}{y \cdot \left(-1 \cdot z + -1 \cdot \left({y}^{2} \cdot \left(\frac{-1}{3} \cdot z - \frac{-1}{6} \cdot z\right)\right)\right)}\right) \]
      8. Step-by-step derivation
        1. lower-*.f64N/A

          \[\leadsto \mathsf{fma}\left(\cos y, x, \color{blue}{y \cdot \left(-1 \cdot z + -1 \cdot \left({y}^{2} \cdot \left(\frac{-1}{3} \cdot z - \frac{-1}{6} \cdot z\right)\right)\right)}\right) \]
        2. +-commutativeN/A

          \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \color{blue}{\left(-1 \cdot \left({y}^{2} \cdot \left(\frac{-1}{3} \cdot z - \frac{-1}{6} \cdot z\right)\right) + -1 \cdot z\right)}\right) \]
        3. *-commutativeN/A

          \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(-1 \cdot \color{blue}{\left(\left(\frac{-1}{3} \cdot z - \frac{-1}{6} \cdot z\right) \cdot {y}^{2}\right)} + -1 \cdot z\right)\right) \]
        4. associate-*r*N/A

          \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(\color{blue}{\left(-1 \cdot \left(\frac{-1}{3} \cdot z - \frac{-1}{6} \cdot z\right)\right) \cdot {y}^{2}} + -1 \cdot z\right)\right) \]
        5. distribute-rgt-out--N/A

          \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(\left(-1 \cdot \color{blue}{\left(z \cdot \left(\frac{-1}{3} - \frac{-1}{6}\right)\right)}\right) \cdot {y}^{2} + -1 \cdot z\right)\right) \]
        6. metadata-evalN/A

          \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(\left(-1 \cdot \left(z \cdot \color{blue}{\frac{-1}{6}}\right)\right) \cdot {y}^{2} + -1 \cdot z\right)\right) \]
        7. *-commutativeN/A

          \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(\left(-1 \cdot \color{blue}{\left(\frac{-1}{6} \cdot z\right)}\right) \cdot {y}^{2} + -1 \cdot z\right)\right) \]
        8. associate-*r*N/A

          \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(\color{blue}{\left(\left(-1 \cdot \frac{-1}{6}\right) \cdot z\right)} \cdot {y}^{2} + -1 \cdot z\right)\right) \]
        9. metadata-evalN/A

          \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(\left(\color{blue}{\frac{1}{6}} \cdot z\right) \cdot {y}^{2} + -1 \cdot z\right)\right) \]
        10. associate-*r*N/A

          \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(\color{blue}{\frac{1}{6} \cdot \left(z \cdot {y}^{2}\right)} + -1 \cdot z\right)\right) \]
        11. *-commutativeN/A

          \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(\frac{1}{6} \cdot \color{blue}{\left({y}^{2} \cdot z\right)} + -1 \cdot z\right)\right) \]
        12. associate-*r*N/A

          \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(\color{blue}{\left(\frac{1}{6} \cdot {y}^{2}\right) \cdot z} + -1 \cdot z\right)\right) \]
        13. distribute-rgt-outN/A

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

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

          \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(z \cdot \color{blue}{\mathsf{fma}\left(\frac{1}{6}, {y}^{2}, -1\right)}\right)\right) \]
        16. unpow2N/A

          \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, \color{blue}{y \cdot y}, -1\right)\right)\right) \]
        17. lower-*.f6497.7

          \[\leadsto \mathsf{fma}\left(\cos y, x, y \cdot \left(z \cdot \mathsf{fma}\left(0.16666666666666666, \color{blue}{y \cdot y}, -1\right)\right)\right) \]
      9. Applied rewrites97.7%

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{1 + {y}^{2} \cdot \left({y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) - \frac{1}{2}\right)}, x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
      11. Step-by-step derivation
        1. +-commutativeN/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{{y}^{2} \cdot \left({y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) - \frac{1}{2}\right) + 1}, x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
        2. lower-fma.f64N/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{fma}\left({y}^{2}, {y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) - \frac{1}{2}, 1\right)}, x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
        3. unpow2N/A

          \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{y \cdot y}, {y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) - \frac{1}{2}, 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
        4. lower-*.f64N/A

          \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{y \cdot y}, {y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) - \frac{1}{2}, 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
        5. sub-negN/A

          \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \color{blue}{{y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}, 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
        6. metadata-evalN/A

          \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, {y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) + \color{blue}{\frac{-1}{2}}, 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
        7. lower-fma.f64N/A

          \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \color{blue}{\mathsf{fma}\left({y}^{2}, \frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}, \frac{-1}{2}\right)}, 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
        8. unpow2N/A

          \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(\color{blue}{y \cdot y}, \frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}, \frac{-1}{2}\right), 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
        9. lower-*.f64N/A

          \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(\color{blue}{y \cdot y}, \frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}, \frac{-1}{2}\right), 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
        10. +-commutativeN/A

          \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \color{blue}{\frac{-1}{720} \cdot {y}^{2} + \frac{1}{24}}, \frac{-1}{2}\right), 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
        11. *-commutativeN/A

          \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \color{blue}{{y}^{2} \cdot \frac{-1}{720}} + \frac{1}{24}, \frac{-1}{2}\right), 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
        12. lower-fma.f64N/A

          \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \color{blue}{\mathsf{fma}\left({y}^{2}, \frac{-1}{720}, \frac{1}{24}\right)}, \frac{-1}{2}\right), 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
        13. unpow2N/A

          \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(\color{blue}{y \cdot y}, \frac{-1}{720}, \frac{1}{24}\right), \frac{-1}{2}\right), 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(\frac{1}{6}, y \cdot y, -1\right)\right)\right) \]
        14. lower-*.f6497.8

          \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(\color{blue}{y \cdot y}, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right), x, y \cdot \left(z \cdot \mathsf{fma}\left(0.16666666666666666, y \cdot y, -1\right)\right)\right) \]
      12. Applied rewrites97.8%

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

    Alternative 7: 39.7% accurate, 15.3× speedup?

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

      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. 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. lower-/.f6499.6

          \[\leadsto \frac{1}{\color{blue}{\frac{1}{x \cdot \cos y - z \cdot \sin y}}} \]
      4. Applied rewrites99.6%

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

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

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

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

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

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

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

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

          \[\leadsto x \cdot \left(\cos y - \frac{\color{blue}{z \cdot \sin y}}{x}\right) \]
        8. lower-sin.f6495.8

          \[\leadsto x \cdot \left(\cos y - \frac{z \cdot \color{blue}{\sin y}}{x}\right) \]
      7. Applied rewrites95.8%

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

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

          \[\leadsto x \cdot 1 \]

        if 6.5000000000000001e114 < 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-*.f6450.2

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

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

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

        Alternative 8: 51.9% 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-*.f6452.1

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

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

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

          Alternative 9: 51.9% accurate, 23.8× speedup?

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

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

            \[\leadsto \color{blue}{x - z \cdot y} \]
          6. Final simplification52.1%

            \[\leadsto x - y \cdot z \]
          7. Add Preprocessing

          Alternative 10: 38.5% accurate, 35.7× speedup?

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

              \[\leadsto \frac{1}{\color{blue}{\frac{1}{x \cdot \cos y - z \cdot \sin y}}} \]
          4. Applied rewrites99.6%

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

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

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

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

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

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

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

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

              \[\leadsto x \cdot \left(\cos y - \frac{\color{blue}{z \cdot \sin y}}{x}\right) \]
            8. lower-sin.f6493.2

              \[\leadsto x \cdot \left(\cos y - \frac{z \cdot \color{blue}{\sin y}}{x}\right) \]
          7. Applied rewrites93.2%

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

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

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

            Reproduce

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