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

Percentage Accurate: 99.8% → 99.8%
Time: 10.0s
Alternatives: 8
Speedup: 1.0×

Specification

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

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

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

Alternative 1: 99.8% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.8% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 76.9% accurate, 1.6× speedup?

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

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

\mathbf{elif}\;z \leq 7.5 \cdot 10^{+128}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\sin y}{z}, x, 1\right) \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -3.5000000000000002e-17 or 7.50000000000000076e128 < z

    1. Initial program 99.7%

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

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

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

        \[\leadsto \color{blue}{\cos y \cdot z} \]
      3. lower-cos.f6489.0

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

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

    if -3.5000000000000002e-17 < z < 7.50000000000000076e128

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{\sin y}{z}, x, 1\right) \cdot z \]
    10. Recombined 2 regimes into one program.
    11. Final simplification81.5%

      \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -3.5 \cdot 10^{-17}:\\ \;\;\;\;z \cdot \cos y\\ \mathbf{elif}\;z \leq 7.5 \cdot 10^{+128}:\\ \;\;\;\;\mathsf{fma}\left(\frac{\sin y}{z}, x, 1\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;z \cdot \cos y\\ \end{array} \]
    12. Add Preprocessing

    Alternative 4: 74.4% accurate, 1.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -12500000:\\ \;\;\;\;z \cdot \cos y\\ \mathbf{elif}\;y \leq 10.5:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, x \cdot y, -0.5 \cdot z\right), y, x\right), y, z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sin y\\ \end{array} \end{array} \]
    (FPCore (x y z)
     :precision binary64
     (if (<= y -12500000.0)
       (* z (cos y))
       (if (<= y 10.5)
         (fma (fma (fma -0.16666666666666666 (* x y) (* -0.5 z)) y x) y z)
         (* x (sin y)))))
    double code(double x, double y, double z) {
    	double tmp;
    	if (y <= -12500000.0) {
    		tmp = z * cos(y);
    	} else if (y <= 10.5) {
    		tmp = fma(fma(fma(-0.16666666666666666, (x * y), (-0.5 * z)), y, x), y, z);
    	} else {
    		tmp = x * sin(y);
    	}
    	return tmp;
    }
    
    function code(x, y, z)
    	tmp = 0.0
    	if (y <= -12500000.0)
    		tmp = Float64(z * cos(y));
    	elseif (y <= 10.5)
    		tmp = fma(fma(fma(-0.16666666666666666, Float64(x * y), Float64(-0.5 * z)), y, x), y, z);
    	else
    		tmp = Float64(x * sin(y));
    	end
    	return tmp
    end
    
    code[x_, y_, z_] := If[LessEqual[y, -12500000.0], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 10.5], N[(N[(N[(-0.16666666666666666 * N[(x * y), $MachinePrecision] + N[(-0.5 * z), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision] * y + z), $MachinePrecision], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;y \leq -12500000:\\
    \;\;\;\;z \cdot \cos y\\
    
    \mathbf{elif}\;y \leq 10.5:\\
    \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, x \cdot y, -0.5 \cdot z\right), y, x\right), y, z\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;x \cdot \sin y\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if y < -1.25e7

      1. Initial program 99.5%

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

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

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

          \[\leadsto \color{blue}{\cos y \cdot z} \]
        3. lower-cos.f6466.2

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

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

      if -1.25e7 < y < 10.5

      1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if 10.5 < y

      1. Initial program 99.7%

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

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

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

          \[\leadsto \color{blue}{\sin y \cdot x} \]
        3. lower-sin.f6459.0

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

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

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

    Alternative 5: 73.9% accurate, 1.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := z \cdot \cos y\\ \mathbf{if}\;y \leq -12500000:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 9.2 \cdot 10^{-7}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, x \cdot y, -0.5 \cdot z\right), y, x\right), y, z\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
    (FPCore (x y z)
     :precision binary64
     (let* ((t_0 (* z (cos y))))
       (if (<= y -12500000.0)
         t_0
         (if (<= y 9.2e-7)
           (fma (fma (fma -0.16666666666666666 (* x y) (* -0.5 z)) y x) y z)
           t_0))))
    double code(double x, double y, double z) {
    	double t_0 = z * cos(y);
    	double tmp;
    	if (y <= -12500000.0) {
    		tmp = t_0;
    	} else if (y <= 9.2e-7) {
    		tmp = fma(fma(fma(-0.16666666666666666, (x * y), (-0.5 * z)), y, x), y, z);
    	} else {
    		tmp = t_0;
    	}
    	return tmp;
    }
    
    function code(x, y, z)
    	t_0 = Float64(z * cos(y))
    	tmp = 0.0
    	if (y <= -12500000.0)
    		tmp = t_0;
    	elseif (y <= 9.2e-7)
    		tmp = fma(fma(fma(-0.16666666666666666, Float64(x * y), Float64(-0.5 * z)), y, x), y, z);
    	else
    		tmp = t_0;
    	end
    	return tmp
    end
    
    code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -12500000.0], t$95$0, If[LessEqual[y, 9.2e-7], N[(N[(N[(-0.16666666666666666 * N[(x * y), $MachinePrecision] + N[(-0.5 * z), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision] * y + z), $MachinePrecision], t$95$0]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := z \cdot \cos y\\
    \mathbf{if}\;y \leq -12500000:\\
    \;\;\;\;t\_0\\
    
    \mathbf{elif}\;y \leq 9.2 \cdot 10^{-7}:\\
    \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, x \cdot y, -0.5 \cdot z\right), y, x\right), y, z\right)\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_0\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if y < -1.25e7 or 9.1999999999999998e-7 < y

      1. Initial program 99.6%

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

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

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

          \[\leadsto \color{blue}{\cos y \cdot z} \]
        3. lower-cos.f6454.6

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

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

      if -1.25e7 < y < 9.1999999999999998e-7

      1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -12500000:\\ \;\;\;\;z \cdot \cos y\\ \mathbf{elif}\;y \leq 9.2 \cdot 10^{-7}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, x \cdot y, -0.5 \cdot z\right), y, x\right), y, z\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \cos y\\ \end{array} \]
    5. Add Preprocessing

    Alternative 6: 41.8% accurate, 11.9× speedup?

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

      1. Initial program 99.7%

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

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

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

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

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

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

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

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

        if -1.34999999999999991e183 < x < 9.60000000000000004e120

        1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto 1 \cdot z \]
        9. Step-by-step derivation
          1. Applied rewrites46.1%

            \[\leadsto 1 \cdot z \]
        10. Recombined 2 regimes into one program.
        11. Final simplification44.6%

          \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.35 \cdot 10^{+183}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 9.6 \cdot 10^{+120}:\\ \;\;\;\;1 \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
        12. Add Preprocessing

        Alternative 7: 52.2% accurate, 30.6× speedup?

        \[\begin{array}{l} \\ \mathsf{fma}\left(y, x, z\right) \end{array} \]
        (FPCore (x y z) :precision binary64 (fma y x z))
        double code(double x, double y, double z) {
        	return fma(y, x, z);
        }
        
        function code(x, y, z)
        	return fma(y, x, z)
        end
        
        code[x_, y_, z_] := N[(y * x + z), $MachinePrecision]
        
        \begin{array}{l}
        
        \\
        \mathsf{fma}\left(y, x, z\right)
        \end{array}
        
        Derivation
        1. Initial program 99.8%

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

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

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

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

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

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

        Alternative 8: 16.8% accurate, 35.7× speedup?

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

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

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

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

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

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

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

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

            \[\leadsto y \cdot \color{blue}{x} \]
          2. Final simplification16.3%

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

          Reproduce

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