Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3

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

\\
\mathsf{fma}\left(\cos y, x, z \cdot \sin 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. lift-*.f64N/A

      \[\leadsto \color{blue}{x \cdot \cos y} + z \cdot \sin y \]
    3. *-commutativeN/A

      \[\leadsto \color{blue}{\cos y \cdot x} + z \cdot \sin y \]
    4. lower-fma.f6499.8

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

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

Alternative 2: 75.0% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
t_0 := \cos y \cdot x\\
\mathbf{if}\;y \leq -0.68:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;y \leq 3.5 \cdot 10^{+62}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -0.680000000000000049 or 0.92000000000000004 < y < 3.49999999999999984e62

    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.f6463.4

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

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

    if -0.680000000000000049 < y < 0.92000000000000004

    1. Initial program 100.0%

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

      \[\leadsto x \cdot \cos y + \color{blue}{y \cdot \left(z + {y}^{2} \cdot \left(\frac{-1}{6} \cdot z + \frac{1}{120} \cdot \left({y}^{2} \cdot z\right)\right)\right)} \]
    4. Step-by-step derivation
      1. distribute-rgt-inN/A

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

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

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

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

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

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

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

        \[\leadsto x \cdot \cos y + \left(z \cdot y + \color{blue}{z \cdot \left(\left(\frac{1}{120} \cdot {y}^{2} + \frac{-1}{6}\right) \cdot \left(y \cdot {y}^{2}\right)\right)}\right) \]
      9. distribute-lft-outN/A

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

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

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

        \[\leadsto x \cdot \cos y + z \cdot \color{blue}{\mathsf{fma}\left(\frac{1}{120} \cdot {y}^{2} + \frac{-1}{6}, y \cdot {y}^{2}, y\right)} \]
    5. Applied rewrites99.6%

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

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

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

        \[\leadsto x \cdot \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)} + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \frac{1}{120}, \frac{-1}{6}\right), y \cdot \left(y \cdot y\right), y\right) \]
      3. unpow2N/A

        \[\leadsto x \cdot \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) + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \frac{1}{120}, \frac{-1}{6}\right), y \cdot \left(y \cdot y\right), y\right) \]
      4. lower-*.f64N/A

        \[\leadsto x \cdot \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) + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \frac{1}{120}, \frac{-1}{6}\right), y \cdot \left(y \cdot y\right), y\right) \]
      5. sub-negN/A

        \[\leadsto x \cdot \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) + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \frac{1}{120}, \frac{-1}{6}\right), y \cdot \left(y \cdot y\right), y\right) \]
      6. metadata-evalN/A

        \[\leadsto x \cdot \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) + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \frac{1}{120}, \frac{-1}{6}\right), y \cdot \left(y \cdot y\right), y\right) \]
      7. lower-fma.f64N/A

        \[\leadsto x \cdot \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) + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \frac{1}{120}, \frac{-1}{6}\right), y \cdot \left(y \cdot y\right), y\right) \]
      8. unpow2N/A

        \[\leadsto x \cdot \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) + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \frac{1}{120}, \frac{-1}{6}\right), y \cdot \left(y \cdot y\right), y\right) \]
      9. lower-*.f64N/A

        \[\leadsto x \cdot \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) + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \frac{1}{120}, \frac{-1}{6}\right), y \cdot \left(y \cdot y\right), y\right) \]
      10. +-commutativeN/A

        \[\leadsto x \cdot \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) + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \frac{1}{120}, \frac{-1}{6}\right), y \cdot \left(y \cdot y\right), y\right) \]
      11. *-commutativeN/A

        \[\leadsto x \cdot \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) + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \frac{1}{120}, \frac{-1}{6}\right), y \cdot \left(y \cdot y\right), y\right) \]
      12. lower-fma.f64N/A

        \[\leadsto x \cdot \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) + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \frac{1}{120}, \frac{-1}{6}\right), y \cdot \left(y \cdot y\right), y\right) \]
      13. unpow2N/A

        \[\leadsto x \cdot \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) + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \frac{1}{120}, \frac{-1}{6}\right), y \cdot \left(y \cdot y\right), y\right) \]
      14. lower-*.f6499.6

        \[\leadsto x \cdot \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) + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot 0.008333333333333333, -0.16666666666666666\right), y \cdot \left(y \cdot y\right), y\right) \]
    8. Applied rewrites99.6%

      \[\leadsto x \cdot \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)} + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot 0.008333333333333333, -0.16666666666666666\right), y \cdot \left(y \cdot y\right), y\right) \]
    9. Step-by-step derivation
      1. lift-+.f64N/A

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

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

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

        \[\leadsto \color{blue}{\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, z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot 0.008333333333333333, -0.16666666666666666\right), y \cdot \left(y \cdot y\right), y\right)\right)} \]
    10. Applied rewrites99.6%

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

    if 3.49999999999999984e62 < 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}{z \cdot \sin y} \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{z \cdot \sin y} \]
      2. lower-sin.f6472.9

        \[\leadsto z \cdot \color{blue}{\sin y} \]
    5. Applied rewrites72.9%

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

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

Alternative 3: 85.0% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -9.2 \cdot 10^{-59}:\\ \;\;\;\;\mathsf{fma}\left(1, x, z \cdot \sin y\right)\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{-178}:\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\sin y, z, x \cdot 1\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -9.2e-59)
   (fma 1.0 x (* z (sin y)))
   (if (<= z 2.7e-178) (* (cos y) x) (fma (sin y) z (* x 1.0)))))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -9.2e-59) {
		tmp = fma(1.0, x, (z * sin(y)));
	} else if (z <= 2.7e-178) {
		tmp = cos(y) * x;
	} else {
		tmp = fma(sin(y), z, (x * 1.0));
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (z <= -9.2e-59)
		tmp = fma(1.0, x, Float64(z * sin(y)));
	elseif (z <= 2.7e-178)
		tmp = Float64(cos(y) * x);
	else
		tmp = fma(sin(y), z, Float64(x * 1.0));
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[z, -9.2e-59], N[(1.0 * x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.7e-178], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * z + N[(x * 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.2 \cdot 10^{-59}:\\
\;\;\;\;\mathsf{fma}\left(1, x, z \cdot \sin y\right)\\

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, z, x \cdot 1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < -9.19999999999999918e-59

    1. Initial program 99.9%

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

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

        \[\leadsto \color{blue}{x \cdot \cos y} + z \cdot \sin y \]
      3. *-commutativeN/A

        \[\leadsto \color{blue}{\cos y \cdot x} + z \cdot \sin y \]
      4. lower-fma.f6499.9

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

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

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{1}, x, z \cdot \sin y\right) \]

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

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

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

      if 2.70000000000000009e-178 < z

      1. Initial program 99.7%

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

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

          \[\leadsto \color{blue}{x \cdot \cos y} + z \cdot \sin y \]
        3. *-commutativeN/A

          \[\leadsto \color{blue}{\cos y \cdot x} + z \cdot \sin y \]
        4. lower-fma.f6499.7

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

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

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

          \[\leadsto \color{blue}{z \cdot \sin y + \cos y \cdot x} \]
        3. *-commutativeN/A

          \[\leadsto z \cdot \sin y + \color{blue}{x \cdot \cos y} \]
        4. lift-*.f64N/A

          \[\leadsto z \cdot \sin y + \color{blue}{x \cdot \cos y} \]
        5. lift-*.f64N/A

          \[\leadsto \color{blue}{z \cdot \sin y} + x \cdot \cos y \]
        6. *-commutativeN/A

          \[\leadsto \color{blue}{\sin y \cdot z} + x \cdot \cos y \]
        7. lower-fma.f6499.7

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\sin y, z, \color{blue}{1} \cdot x\right) \]
      8. Step-by-step derivation
        1. Applied rewrites86.5%

          \[\leadsto \mathsf{fma}\left(\sin y, z, \color{blue}{1} \cdot x\right) \]
      9. Recombined 3 regimes into one program.
      10. Final simplification87.3%

        \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -9.2 \cdot 10^{-59}:\\ \;\;\;\;\mathsf{fma}\left(1, x, z \cdot \sin y\right)\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{-178}:\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\sin y, z, x \cdot 1\right)\\ \end{array} \]
      11. Add Preprocessing

      Alternative 4: 85.0% accurate, 1.7× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(1, x, z \cdot \sin y\right)\\ \mathbf{if}\;z \leq -9.2 \cdot 10^{-59}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{-178}:\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
      (FPCore (x y z)
       :precision binary64
       (let* ((t_0 (fma 1.0 x (* z (sin y)))))
         (if (<= z -9.2e-59) t_0 (if (<= z 2.7e-178) (* (cos y) x) t_0))))
      double code(double x, double y, double z) {
      	double t_0 = fma(1.0, x, (z * sin(y)));
      	double tmp;
      	if (z <= -9.2e-59) {
      		tmp = t_0;
      	} else if (z <= 2.7e-178) {
      		tmp = cos(y) * x;
      	} else {
      		tmp = t_0;
      	}
      	return tmp;
      }
      
      function code(x, y, z)
      	t_0 = fma(1.0, x, Float64(z * sin(y)))
      	tmp = 0.0
      	if (z <= -9.2e-59)
      		tmp = t_0;
      	elseif (z <= 2.7e-178)
      		tmp = Float64(cos(y) * x);
      	else
      		tmp = t_0;
      	end
      	return tmp
      end
      
      code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 * x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -9.2e-59], t$95$0, If[LessEqual[z, 2.7e-178], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], t$95$0]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := \mathsf{fma}\left(1, x, z \cdot \sin y\right)\\
      \mathbf{if}\;z \leq -9.2 \cdot 10^{-59}:\\
      \;\;\;\;t\_0\\
      
      \mathbf{elif}\;z \leq 2.7 \cdot 10^{-178}:\\
      \;\;\;\;\cos y \cdot x\\
      
      \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. Step-by-step derivation
          1. lift-+.f64N/A

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

            \[\leadsto \color{blue}{x \cdot \cos y} + z \cdot \sin y \]
          3. *-commutativeN/A

            \[\leadsto \color{blue}{\cos y \cdot x} + z \cdot \sin y \]
          4. lower-fma.f6499.8

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

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

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

            \[\leadsto \mathsf{fma}\left(\color{blue}{1}, x, z \cdot \sin y\right) \]

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

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

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

          \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -9.2 \cdot 10^{-59}:\\ \;\;\;\;\mathsf{fma}\left(1, x, z \cdot \sin y\right)\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{-178}:\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, x, z \cdot \sin y\right)\\ \end{array} \]
        9. Add Preprocessing

        Alternative 5: 74.7% accurate, 1.8× speedup?

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

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

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

          if -0.680000000000000049 < y < 0.92000000000000004

          1. Initial program 100.0%

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

            \[\leadsto x \cdot \cos y + \color{blue}{y \cdot \left(z + {y}^{2} \cdot \left(\frac{-1}{6} \cdot z + \frac{1}{120} \cdot \left({y}^{2} \cdot z\right)\right)\right)} \]
          4. Step-by-step derivation
            1. distribute-rgt-inN/A

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

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

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

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

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

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

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

              \[\leadsto x \cdot \cos y + \left(z \cdot y + \color{blue}{z \cdot \left(\left(\frac{1}{120} \cdot {y}^{2} + \frac{-1}{6}\right) \cdot \left(y \cdot {y}^{2}\right)\right)}\right) \]
            9. distribute-lft-outN/A

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

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

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

              \[\leadsto x \cdot \cos y + z \cdot \color{blue}{\mathsf{fma}\left(\frac{1}{120} \cdot {y}^{2} + \frac{-1}{6}, y \cdot {y}^{2}, y\right)} \]
          5. Applied rewrites99.6%

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

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

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

              \[\leadsto x \cdot \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)} + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \frac{1}{120}, \frac{-1}{6}\right), y \cdot \left(y \cdot y\right), y\right) \]
            3. unpow2N/A

              \[\leadsto x \cdot \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) + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \frac{1}{120}, \frac{-1}{6}\right), y \cdot \left(y \cdot y\right), y\right) \]
            4. lower-*.f64N/A

              \[\leadsto x \cdot \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) + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \frac{1}{120}, \frac{-1}{6}\right), y \cdot \left(y \cdot y\right), y\right) \]
            5. sub-negN/A

              \[\leadsto x \cdot \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) + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \frac{1}{120}, \frac{-1}{6}\right), y \cdot \left(y \cdot y\right), y\right) \]
            6. metadata-evalN/A

              \[\leadsto x \cdot \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) + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \frac{1}{120}, \frac{-1}{6}\right), y \cdot \left(y \cdot y\right), y\right) \]
            7. lower-fma.f64N/A

              \[\leadsto x \cdot \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) + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \frac{1}{120}, \frac{-1}{6}\right), y \cdot \left(y \cdot y\right), y\right) \]
            8. unpow2N/A

              \[\leadsto x \cdot \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) + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \frac{1}{120}, \frac{-1}{6}\right), y \cdot \left(y \cdot y\right), y\right) \]
            9. lower-*.f64N/A

              \[\leadsto x \cdot \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) + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \frac{1}{120}, \frac{-1}{6}\right), y \cdot \left(y \cdot y\right), y\right) \]
            10. +-commutativeN/A

              \[\leadsto x \cdot \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) + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \frac{1}{120}, \frac{-1}{6}\right), y \cdot \left(y \cdot y\right), y\right) \]
            11. *-commutativeN/A

              \[\leadsto x \cdot \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) + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \frac{1}{120}, \frac{-1}{6}\right), y \cdot \left(y \cdot y\right), y\right) \]
            12. lower-fma.f64N/A

              \[\leadsto x \cdot \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) + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \frac{1}{120}, \frac{-1}{6}\right), y \cdot \left(y \cdot y\right), y\right) \]
            13. unpow2N/A

              \[\leadsto x \cdot \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) + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot \frac{1}{120}, \frac{-1}{6}\right), y \cdot \left(y \cdot y\right), y\right) \]
            14. lower-*.f6499.6

              \[\leadsto x \cdot \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) + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot 0.008333333333333333, -0.16666666666666666\right), y \cdot \left(y \cdot y\right), y\right) \]
          8. Applied rewrites99.6%

            \[\leadsto x \cdot \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)} + z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot 0.008333333333333333, -0.16666666666666666\right), y \cdot \left(y \cdot y\right), y\right) \]
          9. Step-by-step derivation
            1. lift-+.f64N/A

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

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

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

              \[\leadsto \color{blue}{\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, z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y, y \cdot 0.008333333333333333, -0.16666666666666666\right), y \cdot \left(y \cdot y\right), y\right)\right)} \]
          10. Applied rewrites99.6%

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

          \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -0.68:\\ \;\;\;\;\cos y \cdot x\\ \mathbf{elif}\;y \leq 0.92:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right), x, z \cdot \mathsf{fma}\left(\mathsf{fma}\left(y \cdot y, 0.008333333333333333, -0.16666666666666666\right), y \cdot \left(y \cdot y\right), y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos y \cdot x\\ \end{array} \]
        5. Add Preprocessing

        Alternative 6: 39.7% accurate, 17.8× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq 6.5 \cdot 10^{+114}:\\ \;\;\;\;x \cdot 1\\ \mathbf{else}:\\ \;\;\;\;y \cdot z\\ \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 * 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 z\\
        
        
        \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. lift-*.f64N/A

              \[\leadsto \color{blue}{x \cdot \cos y} + z \cdot \sin y \]
            3. *-commutativeN/A

              \[\leadsto \color{blue}{\cos y \cdot x} + z \cdot \sin y \]
            4. lower-fma.f6499.8

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

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

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

              \[\leadsto \color{blue}{x \cdot \cos y} + z \cdot \sin y \]
            3. lift-*.f64N/A

              \[\leadsto \color{blue}{x \cdot \cos y} + z \cdot \sin y \]
            4. 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}} \]
            5. 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)}}} \]
            6. 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)}}} \]
            7. 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}}}} \]
            8. flip-+N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\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 + y \cdot z} \]
            4. Step-by-step derivation
              1. +-commutativeN/A

                \[\leadsto \color{blue}{y \cdot z + x} \]
              2. *-commutativeN/A

                \[\leadsto \color{blue}{z \cdot y} + x \]
              3. lower-fma.f6449.9

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

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

              \[\leadsto y \cdot \color{blue}{z} \]
            7. Step-by-step derivation
              1. Applied rewrites34.5%

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

            Alternative 7: 51.9% accurate, 30.6× 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(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 + y \cdot z} \]
            4. Step-by-step derivation
              1. +-commutativeN/A

                \[\leadsto \color{blue}{y \cdot z + x} \]
              2. *-commutativeN/A

                \[\leadsto \color{blue}{z \cdot y} + x \]
              3. lower-fma.f6452.0

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

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

            Alternative 8: 16.8% accurate, 35.7× speedup?

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

                \[\leadsto \color{blue}{y \cdot z + x} \]
              2. *-commutativeN/A

                \[\leadsto \color{blue}{z \cdot y} + x \]
              3. lower-fma.f6452.0

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

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

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

                \[\leadsto y \cdot \color{blue}{z} \]
              2. Add Preprocessing

              Reproduce

              ?
              herbie shell --seed 2024220 
              (FPCore (x y z)
                :name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
                :precision binary64
                (+ (* x (cos y)) (* z (sin y))))