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

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

\\
\mathsf{fma}\left(\cos y, z, \sin y \cdot x\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. Add Preprocessing

Alternative 2: 85.6% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.6 \cdot 10^{+101} \lor \neg \left(z \leq 4.8 \cdot 10^{+79}\right):\\
\;\;\;\;\cos y \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -8.6000000000000002e101 or 4.79999999999999971e79 < z

    1. Initial program 99.8%

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

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

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

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

    if -8.6000000000000002e101 < z < 4.79999999999999971e79

    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. Taylor expanded in y around 0

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

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

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

    Alternative 3: 74.1% accurate, 1.8× speedup?

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

      1. Initial program 99.8%

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

        \[\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.f6479.1

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

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

      if -9.20000000000000012e-132 < z < 1.3499999999999999e-35

      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. unpow1N/A

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

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

          \[\leadsto \color{blue}{\sqrt{{\left(x \cdot \sin y\right)}^{2}}} + z \cdot \cos y \]
        5. pow2N/A

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

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

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

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

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

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

          \[\leadsto \mathsf{fma}\left(\sqrt{\color{blue}{\sin y \cdot x}}, \sqrt{x \cdot \sin y}, z \cdot \cos y\right) \]
        12. lower-sqrt.f6459.2

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(\sin y \cdot {\left(\sqrt{-1}\right)}^{2}\right)\right)} \]
      6. Step-by-step derivation
        1. mul-1-negN/A

          \[\leadsto \color{blue}{\mathsf{neg}\left(x \cdot \left(\sin y \cdot {\left(\sqrt{-1}\right)}^{2}\right)\right)} \]
        2. *-commutativeN/A

          \[\leadsto \mathsf{neg}\left(\color{blue}{\left(\sin y \cdot {\left(\sqrt{-1}\right)}^{2}\right) \cdot x}\right) \]
        3. *-commutativeN/A

          \[\leadsto \mathsf{neg}\left(\color{blue}{\left({\left(\sqrt{-1}\right)}^{2} \cdot \sin y\right)} \cdot x\right) \]
        4. unpow2N/A

          \[\leadsto \mathsf{neg}\left(\left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot \sin y\right) \cdot x\right) \]
        5. rem-square-sqrtN/A

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

          \[\leadsto \mathsf{neg}\left(\color{blue}{\left(\sin y \cdot -1\right)} \cdot x\right) \]
        7. associate-*l*N/A

          \[\leadsto \mathsf{neg}\left(\color{blue}{\sin y \cdot \left(-1 \cdot x\right)}\right) \]
        8. distribute-rgt-neg-inN/A

          \[\leadsto \color{blue}{\sin y \cdot \left(\mathsf{neg}\left(-1 \cdot x\right)\right)} \]
        9. distribute-lft-neg-inN/A

          \[\leadsto \sin y \cdot \color{blue}{\left(\left(\mathsf{neg}\left(-1\right)\right) \cdot x\right)} \]
        10. metadata-evalN/A

          \[\leadsto \sin y \cdot \left(\color{blue}{1} \cdot x\right) \]
        11. *-lft-identityN/A

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

          \[\leadsto \color{blue}{\sin y \cdot x} \]
        13. lower-sin.f6476.4

          \[\leadsto \color{blue}{\sin y} \cdot x \]
      7. Applied rewrites76.4%

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -9.2 \cdot 10^{-132} \lor \neg \left(z \leq 1.35 \cdot 10^{-35}\right):\\ \;\;\;\;\cos y \cdot z\\ \mathbf{else}:\\ \;\;\;\;\sin y \cdot x\\ \end{array} \]
    5. Add Preprocessing

    Alternative 4: 74.2% accurate, 1.8× speedup?

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

      1. Initial program 99.6%

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

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

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

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

      if -0.00365000000000000003 < y < 8.00000000000000029e-10

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

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

        \[\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 -0.00365 \lor \neg \left(y \leq 8 \cdot 10^{-10}\right):\\ \;\;\;\;\cos y \cdot z\\ \mathbf{else}:\\ \;\;\;\;\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)\\ \end{array} \]
    5. Add Preprocessing

    Alternative 5: 51.6% 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.f6453.4

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

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

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

    Alternative 6: 17.0% 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.f6453.4

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

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

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

        \[\leadsto x \cdot \color{blue}{y} \]
      2. Final simplification19.5%

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

      Reproduce

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