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

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

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

Initial Program: 99.8% accurate, 1.0× speedup?

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

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

Alternative 1: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(\cos y, x, \sin y \cdot 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(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. 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)} \]
    5. lift-*.f64N/A

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

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

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

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

Alternative 2: 85.8% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -3.9 \cdot 10^{-25} \lor \neg \left(x \leq 1.15 \cdot 10^{+35}\right):\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\sin y, z, 1 \cdot x\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -3.9e-25) (not (<= x 1.15e+35)))
   (* (cos y) x)
   (fma (sin y) z (* 1.0 x))))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -3.9e-25) || !(x <= 1.15e+35)) {
		tmp = cos(y) * x;
	} else {
		tmp = fma(sin(y), z, (1.0 * x));
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if ((x <= -3.9e-25) || !(x <= 1.15e+35))
		tmp = Float64(cos(y) * x);
	else
		tmp = fma(sin(y), z, Float64(1.0 * x));
	end
	return tmp
end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.9e-25], N[Not[LessEqual[x, 1.15e+35]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * z + N[(1.0 * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.9 \cdot 10^{-25} \lor \neg \left(x \leq 1.15 \cdot 10^{+35}\right):\\
\;\;\;\;\cos y \cdot x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -3.9e-25 or 1.1499999999999999e35 < x

    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 \left(\cos y + \frac{z \cdot \sin y}{x}\right)} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \cos y \cdot x \]
    7. Step-by-step derivation
      1. Applied rewrites88.1%

        \[\leadsto \cos y \cdot x \]

      if -3.9e-25 < x < 1.1499999999999999e35

      1. Initial program 99.8%

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

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

          \[\leadsto x \cdot \color{blue}{1} + z \cdot \sin y \]
        2. Step-by-step derivation
          1. lift-+.f64N/A

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

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

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

            \[\leadsto \color{blue}{\sin y \cdot z} + x \cdot 1 \]
          5. lower-fma.f6490.8

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

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

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

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

          \[\leadsto \color{blue}{\mathsf{fma}\left(\sin y, z, 1 \cdot x\right)} \]
      5. Recombined 2 regimes into one program.
      6. Final simplification89.5%

        \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.9 \cdot 10^{-25} \lor \neg \left(x \leq 1.15 \cdot 10^{+35}\right):\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\sin y, z, 1 \cdot x\right)\\ \end{array} \]
      7. Add Preprocessing

      Alternative 3: 74.6% accurate, 1.7× speedup?

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

        1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \cos y \cdot x \]
        7. Step-by-step derivation
          1. Applied rewrites69.1%

            \[\leadsto \cos y \cdot x \]

          if -9.60000000000000045e234 < y < -1.14999999999999997e-7

          1. Initial program 99.7%

            \[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. *-commutativeN/A

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

              \[\leadsto \color{blue}{\sin y \cdot z} \]
            3. lower-sin.f6465.3

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

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

          if -1.14999999999999997e-7 < y < 8.5e-17

          1. Initial program 100.0%

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

            \[\leadsto \color{blue}{x + y \cdot 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.f64100.0

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

            \[\leadsto \color{blue}{\mathsf{fma}\left(z, y, x\right)} \]
        8. Recombined 3 regimes into one program.
        9. Add Preprocessing

        Alternative 4: 74.9% accurate, 1.8× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -540 \lor \neg \left(y \leq 8.5 \cdot 10^{-17}\right):\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666 \cdot \left(z \cdot y\right), y, z\right), y, x\right)\\ \end{array} \end{array} \]
        (FPCore (x y z)
         :precision binary64
         (if (or (<= y -540.0) (not (<= y 8.5e-17)))
           (* (cos y) x)
           (fma (fma (* -0.16666666666666666 (* z y)) y z) y x)))
        double code(double x, double y, double z) {
        	double tmp;
        	if ((y <= -540.0) || !(y <= 8.5e-17)) {
        		tmp = cos(y) * x;
        	} else {
        		tmp = fma(fma((-0.16666666666666666 * (z * y)), y, z), y, x);
        	}
        	return tmp;
        }
        
        function code(x, y, z)
        	tmp = 0.0
        	if ((y <= -540.0) || !(y <= 8.5e-17))
        		tmp = Float64(cos(y) * x);
        	else
        		tmp = fma(fma(Float64(-0.16666666666666666 * Float64(z * y)), y, z), y, x);
        	end
        	return tmp
        end
        
        code[x_, y_, z_] := If[Or[LessEqual[y, -540.0], N[Not[LessEqual[y, 8.5e-17]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(N[(N[(-0.16666666666666666 * N[(z * y), $MachinePrecision]), $MachinePrecision] * y + z), $MachinePrecision] * y + x), $MachinePrecision]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;y \leq -540 \lor \neg \left(y \leq 8.5 \cdot 10^{-17}\right):\\
        \;\;\;\;\cos y \cdot x\\
        
        \mathbf{else}:\\
        \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666 \cdot \left(z \cdot y\right), y, z\right), y, x\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if y < -540 or 8.5e-17 < y

          1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \cos y \cdot x \]
          7. Step-by-step derivation
            1. Applied rewrites55.0%

              \[\leadsto \cos y \cdot x \]

            if -540 < y < 8.5e-17

            1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{-1}{6}, \color{blue}{z \cdot y}, \frac{-1}{2} \cdot x\right), y, z\right), y, x\right) \]
              11. lower-*.f6499.3

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

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

              \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\frac{-1}{6} \cdot \left(y \cdot z\right), y, z\right), y, x\right) \]
            9. Step-by-step derivation
              1. Applied rewrites99.3%

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

              \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -540 \lor \neg \left(y \leq 8.5 \cdot 10^{-17}\right):\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666 \cdot \left(z \cdot y\right), y, z\right), y, x\right)\\ \end{array} \]
            12. Add Preprocessing

            Alternative 5: 41.3% accurate, 11.9× speedup?

            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -4.8 \cdot 10^{-166} \lor \neg \left(x \leq 2 \cdot 10^{-28}\right):\\ \;\;\;\;1 \cdot x\\ \mathbf{else}:\\ \;\;\;\;z \cdot y\\ \end{array} \end{array} \]
            (FPCore (x y z)
             :precision binary64
             (if (or (<= x -4.8e-166) (not (<= x 2e-28))) (* 1.0 x) (* z y)))
            double code(double x, double y, double z) {
            	double tmp;
            	if ((x <= -4.8e-166) || !(x <= 2e-28)) {
            		tmp = 1.0 * x;
            	} else {
            		tmp = z * y;
            	}
            	return tmp;
            }
            
            real(8) function code(x, y, z)
                real(8), intent (in) :: x
                real(8), intent (in) :: y
                real(8), intent (in) :: z
                real(8) :: tmp
                if ((x <= (-4.8d-166)) .or. (.not. (x <= 2d-28))) then
                    tmp = 1.0d0 * x
                else
                    tmp = z * y
                end if
                code = tmp
            end function
            
            public static double code(double x, double y, double z) {
            	double tmp;
            	if ((x <= -4.8e-166) || !(x <= 2e-28)) {
            		tmp = 1.0 * x;
            	} else {
            		tmp = z * y;
            	}
            	return tmp;
            }
            
            def code(x, y, z):
            	tmp = 0
            	if (x <= -4.8e-166) or not (x <= 2e-28):
            		tmp = 1.0 * x
            	else:
            		tmp = z * y
            	return tmp
            
            function code(x, y, z)
            	tmp = 0.0
            	if ((x <= -4.8e-166) || !(x <= 2e-28))
            		tmp = Float64(1.0 * x);
            	else
            		tmp = Float64(z * y);
            	end
            	return tmp
            end
            
            function tmp_2 = code(x, y, z)
            	tmp = 0.0;
            	if ((x <= -4.8e-166) || ~((x <= 2e-28)))
            		tmp = 1.0 * x;
            	else
            		tmp = z * y;
            	end
            	tmp_2 = tmp;
            end
            
            code[x_, y_, z_] := If[Or[LessEqual[x, -4.8e-166], N[Not[LessEqual[x, 2e-28]], $MachinePrecision]], N[(1.0 * x), $MachinePrecision], N[(z * y), $MachinePrecision]]
            
            \begin{array}{l}
            
            \\
            \begin{array}{l}
            \mathbf{if}\;x \leq -4.8 \cdot 10^{-166} \lor \neg \left(x \leq 2 \cdot 10^{-28}\right):\\
            \;\;\;\;1 \cdot x\\
            
            \mathbf{else}:\\
            \;\;\;\;z \cdot y\\
            
            
            \end{array}
            \end{array}
            
            Derivation
            1. Split input into 2 regimes
            2. if x < -4.7999999999999997e-166 or 1.99999999999999994e-28 < x

              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)} \]
                5. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{-1}{6}, \color{blue}{z \cdot y}, \frac{-1}{2} \cdot x\right), y, z\right), y, x\right) \]
                11. lower-*.f6448.5

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

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

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

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

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

                    \[\leadsto 1 \cdot x \]

                  if -4.7999999999999997e-166 < x < 1.99999999999999994e-28

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

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

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

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

                      \[\leadsto z \cdot \color{blue}{y} \]
                  8. Recombined 2 regimes into one program.
                  9. Final simplification42.5%

                    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4.8 \cdot 10^{-166} \lor \neg \left(x \leq 2 \cdot 10^{-28}\right):\\ \;\;\;\;1 \cdot x\\ \mathbf{else}:\\ \;\;\;\;z \cdot y\\ \end{array} \]
                  10. Add Preprocessing

                  Alternative 6: 52.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.f6451.9

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

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

                  Alternative 7: 16.5% accurate, 35.7× speedup?

                  \[\begin{array}{l} \\ z \cdot y \end{array} \]
                  (FPCore (x y z) :precision binary64 (* z y))
                  double code(double x, double y, double z) {
                  	return z * y;
                  }
                  
                  real(8) function code(x, y, z)
                      real(8), intent (in) :: x
                      real(8), intent (in) :: y
                      real(8), intent (in) :: z
                      code = z * y
                  end function
                  
                  public static double code(double x, double y, double z) {
                  	return z * y;
                  }
                  
                  def code(x, y, z):
                  	return z * y
                  
                  function code(x, y, z)
                  	return Float64(z * y)
                  end
                  
                  function tmp = code(x, y, z)
                  	tmp = z * y;
                  end
                  
                  code[x_, y_, z_] := N[(z * y), $MachinePrecision]
                  
                  \begin{array}{l}
                  
                  \\
                  z \cdot y
                  \end{array}
                  
                  Derivation
                  1. Initial program 99.8%

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

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

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

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

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

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

                    Reproduce

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