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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 85.7% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.4 \cdot 10^{+93} \lor \neg \left(x \leq 6.3 \cdot 10^{-24}\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 -1.4e+93) (not (<= x 6.3e-24)))
   (* (cos y) x)
   (fma (sin y) z (* 1.0 x))))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -1.4e+93) || !(x <= 6.3e-24)) {
		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 <= -1.4e+93) || !(x <= 6.3e-24))
		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, -1.4e+93], N[Not[LessEqual[x, 6.3e-24]], $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 -1.4 \cdot 10^{+93} \lor \neg \left(x \leq 6.3 \cdot 10^{-24}\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 < -1.39999999999999994e93 or 6.29999999999999979e-24 < 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. flip-+N/A

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

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

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

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

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

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{x \cdot \cos y + z \cdot \sin y}}} \]
      8. inv-powN/A

        \[\leadsto \frac{1}{\color{blue}{{\left(x \cdot \cos y + z \cdot \sin y\right)}^{-1}}} \]
      9. lower-pow.f6499.5

        \[\leadsto \frac{1}{\color{blue}{{\left(x \cdot \cos y + z \cdot \sin y\right)}^{-1}}} \]
    4. Applied rewrites99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto x \cdot \color{blue}{\cos y} \]
    11. Step-by-step derivation
      1. Applied rewrites89.8%

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

      if -1.39999999999999994e93 < x < 6.29999999999999979e-24

      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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.4 \cdot 10^{+93} \lor \neg \left(x \leq 6.3 \cdot 10^{-24}\right):\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\sin y, z, 1 \cdot x\right)\\ \end{array} \]
      9. Add Preprocessing

      Alternative 3: 73.7% accurate, 1.8× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -7.5 \cdot 10^{-63} \lor \neg \left(x \leq 2.8 \cdot 10^{-47}\right):\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\sin y \cdot z\\ \end{array} \end{array} \]
      (FPCore (x y z)
       :precision binary64
       (if (or (<= x -7.5e-63) (not (<= x 2.8e-47))) (* (cos y) x) (* (sin y) z)))
      double code(double x, double y, double z) {
      	double tmp;
      	if ((x <= -7.5e-63) || !(x <= 2.8e-47)) {
      		tmp = cos(y) * x;
      	} else {
      		tmp = sin(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 ((x <= (-7.5d-63)) .or. (.not. (x <= 2.8d-47))) then
              tmp = cos(y) * x
          else
              tmp = sin(y) * z
          end if
          code = tmp
      end function
      
      public static double code(double x, double y, double z) {
      	double tmp;
      	if ((x <= -7.5e-63) || !(x <= 2.8e-47)) {
      		tmp = Math.cos(y) * x;
      	} else {
      		tmp = Math.sin(y) * z;
      	}
      	return tmp;
      }
      
      def code(x, y, z):
      	tmp = 0
      	if (x <= -7.5e-63) or not (x <= 2.8e-47):
      		tmp = math.cos(y) * x
      	else:
      		tmp = math.sin(y) * z
      	return tmp
      
      function code(x, y, z)
      	tmp = 0.0
      	if ((x <= -7.5e-63) || !(x <= 2.8e-47))
      		tmp = Float64(cos(y) * x);
      	else
      		tmp = Float64(sin(y) * z);
      	end
      	return tmp
      end
      
      function tmp_2 = code(x, y, z)
      	tmp = 0.0;
      	if ((x <= -7.5e-63) || ~((x <= 2.8e-47)))
      		tmp = cos(y) * x;
      	else
      		tmp = sin(y) * z;
      	end
      	tmp_2 = tmp;
      end
      
      code[x_, y_, z_] := If[Or[LessEqual[x, -7.5e-63], N[Not[LessEqual[x, 2.8e-47]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;x \leq -7.5 \cdot 10^{-63} \lor \neg \left(x \leq 2.8 \cdot 10^{-47}\right):\\
      \;\;\;\;\cos y \cdot x\\
      
      \mathbf{else}:\\
      \;\;\;\;\sin y \cdot z\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if x < -7.5000000000000003e-63 or 2.79999999999999993e-47 < 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. flip-+N/A

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

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

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

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

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

            \[\leadsto \frac{1}{\frac{1}{\color{blue}{x \cdot \cos y + z \cdot \sin y}}} \]
          8. inv-powN/A

            \[\leadsto \frac{1}{\color{blue}{{\left(x \cdot \cos y + z \cdot \sin y\right)}^{-1}}} \]
          9. lower-pow.f6499.6

            \[\leadsto \frac{1}{\color{blue}{{\left(x \cdot \cos y + z \cdot \sin y\right)}^{-1}}} \]
        4. Applied rewrites99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto x \cdot \color{blue}{\cos y} \]
        11. Step-by-step derivation
          1. Applied rewrites84.9%

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

          if -7.5000000000000003e-63 < x < 2.79999999999999993e-47

          1. Initial program 99.8%

            \[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.f6476.6

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

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

          \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -7.5 \cdot 10^{-63} \lor \neg \left(x \leq 2.8 \cdot 10^{-47}\right):\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\sin y \cdot z\\ \end{array} \]
        14. Add Preprocessing

        Alternative 4: 75.6% accurate, 1.8× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -0.0046 \lor \neg \left(y \leq 0.102\right):\\ \;\;\;\;\sin y \cdot z\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(y \cdot x, -0.5, z\right), y, x\right)\\ \end{array} \end{array} \]
        (FPCore (x y z)
         :precision binary64
         (if (or (<= y -0.0046) (not (<= y 0.102)))
           (* (sin y) z)
           (fma (fma (* y x) -0.5 z) y x)))
        double code(double x, double y, double z) {
        	double tmp;
        	if ((y <= -0.0046) || !(y <= 0.102)) {
        		tmp = sin(y) * z;
        	} else {
        		tmp = fma(fma((y * x), -0.5, z), y, x);
        	}
        	return tmp;
        }
        
        function code(x, y, z)
        	tmp = 0.0
        	if ((y <= -0.0046) || !(y <= 0.102))
        		tmp = Float64(sin(y) * z);
        	else
        		tmp = fma(fma(Float64(y * x), -0.5, z), y, x);
        	end
        	return tmp
        end
        
        code[x_, y_, z_] := If[Or[LessEqual[y, -0.0046], N[Not[LessEqual[y, 0.102]], $MachinePrecision]], N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision], N[(N[(N[(y * x), $MachinePrecision] * -0.5 + z), $MachinePrecision] * y + x), $MachinePrecision]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;y \leq -0.0046 \lor \neg \left(y \leq 0.102\right):\\
        \;\;\;\;\sin y \cdot z\\
        
        \mathbf{else}:\\
        \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(y \cdot x, -0.5, z\right), y, x\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if y < -0.0045999999999999999 or 0.101999999999999993 < 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. *-commutativeN/A

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

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

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

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

          if -0.0045999999999999999 < y < 0.101999999999999993

          1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(y \cdot x, -0.5, z\right), y, x\right)} \]
        3. Recombined 2 regimes into one program.
        4. Final simplification73.5%

          \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -0.0046 \lor \neg \left(y \leq 0.102\right):\\ \;\;\;\;\sin y \cdot z\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(y \cdot x, -0.5, z\right), y, x\right)\\ \end{array} \]
        5. Add Preprocessing

        Alternative 5: 41.9% accurate, 11.9× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -6.6 \cdot 10^{-71} \lor \neg \left(x \leq 5.4 \cdot 10^{-124}\right):\\ \;\;\;\;1 \cdot x\\ \mathbf{else}:\\ \;\;\;\;z \cdot y\\ \end{array} \end{array} \]
        (FPCore (x y z)
         :precision binary64
         (if (or (<= x -6.6e-71) (not (<= x 5.4e-124))) (* 1.0 x) (* z y)))
        double code(double x, double y, double z) {
        	double tmp;
        	if ((x <= -6.6e-71) || !(x <= 5.4e-124)) {
        		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 <= (-6.6d-71)) .or. (.not. (x <= 5.4d-124))) 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 <= -6.6e-71) || !(x <= 5.4e-124)) {
        		tmp = 1.0 * x;
        	} else {
        		tmp = z * y;
        	}
        	return tmp;
        }
        
        def code(x, y, z):
        	tmp = 0
        	if (x <= -6.6e-71) or not (x <= 5.4e-124):
        		tmp = 1.0 * x
        	else:
        		tmp = z * y
        	return tmp
        
        function code(x, y, z)
        	tmp = 0.0
        	if ((x <= -6.6e-71) || !(x <= 5.4e-124))
        		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 <= -6.6e-71) || ~((x <= 5.4e-124)))
        		tmp = 1.0 * x;
        	else
        		tmp = z * y;
        	end
        	tmp_2 = tmp;
        end
        
        code[x_, y_, z_] := If[Or[LessEqual[x, -6.6e-71], N[Not[LessEqual[x, 5.4e-124]], $MachinePrecision]], N[(1.0 * x), $MachinePrecision], N[(z * y), $MachinePrecision]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;x \leq -6.6 \cdot 10^{-71} \lor \neg \left(x \leq 5.4 \cdot 10^{-124}\right):\\
        \;\;\;\;1 \cdot x\\
        
        \mathbf{else}:\\
        \;\;\;\;z \cdot y\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if x < -6.6000000000000003e-71 or 5.40000000000000035e-124 < x

          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. +-commutativeN/A

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

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

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

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

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

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

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

            \[\leadsto \color{blue}{\mathsf{fma}\left(\sin y, z, \cos y \cdot x\right)} \]
          5. 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-*.f6450.8

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

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

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

                \[\leadsto 1 \cdot x \]

              if -6.6000000000000003e-71 < x < 5.40000000000000035e-124

              1. Initial program 99.9%

                \[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.f6447.7

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

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

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

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

              Alternative 6: 54.1% 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.f6450.7

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

                \[\leadsto \color{blue}{\mathsf{fma}\left(z, y, x\right)} \]
              6. Final simplification50.7%

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

              Alternative 7: 17.3% 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.f6450.7

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

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

                  \[\leadsto z \cdot \color{blue}{y} \]
                2. Final simplification18.2%

                  \[\leadsto z \cdot y \]
                3. Add Preprocessing

                Reproduce

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