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

Percentage Accurate: 99.8% → 99.8%
Time: 8.9s
Alternatives: 7
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 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 \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: 75.3% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \sin y\\ t_1 := z \cdot \cos y\\ \mathbf{if}\;y \leq -5.1 \cdot 10^{+193}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq -0.032:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq 0.0055:\\ \;\;\;\;\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{elif}\;y \leq 2.25 \cdot 10^{+117}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 1.8 \cdot 10^{+252}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (sin y))) (t_1 (* z (cos y))))
   (if (<= y -5.1e+193)
     t_0
     (if (<= y -0.032)
       t_1
       (if (<= y 0.0055)
         (fma (fma (fma -0.16666666666666666 (* x y) (* -0.5 z)) y x) y z)
         (if (<= y 2.25e+117) t_0 (if (<= y 1.8e+252) t_1 t_0)))))))
double code(double x, double y, double z) {
	double t_0 = x * sin(y);
	double t_1 = z * cos(y);
	double tmp;
	if (y <= -5.1e+193) {
		tmp = t_0;
	} else if (y <= -0.032) {
		tmp = t_1;
	} else if (y <= 0.0055) {
		tmp = fma(fma(fma(-0.16666666666666666, (x * y), (-0.5 * z)), y, x), y, z);
	} else if (y <= 2.25e+117) {
		tmp = t_0;
	} else if (y <= 1.8e+252) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(x, y, z)
	t_0 = Float64(x * sin(y))
	t_1 = Float64(z * cos(y))
	tmp = 0.0
	if (y <= -5.1e+193)
		tmp = t_0;
	elseif (y <= -0.032)
		tmp = t_1;
	elseif (y <= 0.0055)
		tmp = fma(fma(fma(-0.16666666666666666, Float64(x * y), Float64(-0.5 * z)), y, x), y, z);
	elseif (y <= 2.25e+117)
		tmp = t_0;
	elseif (y <= 1.8e+252)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -5.1e+193], t$95$0, If[LessEqual[y, -0.032], t$95$1, If[LessEqual[y, 0.0055], N[(N[(N[(-0.16666666666666666 * N[(x * y), $MachinePrecision] + N[(-0.5 * z), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision] * y + z), $MachinePrecision], If[LessEqual[y, 2.25e+117], t$95$0, If[LessEqual[y, 1.8e+252], t$95$1, t$95$0]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
t_1 := z \cdot \cos y\\
\mathbf{if}\;y \leq -5.1 \cdot 10^{+193}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq -0.032:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y \leq 0.0055:\\
\;\;\;\;\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{elif}\;y \leq 2.25 \cdot 10^{+117}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 1.8 \cdot 10^{+252}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -5.09999999999999999e193 or 0.0054999999999999997 < y < 2.25e117 or 1.7999999999999999e252 < y

    1. Initial program 99.5%

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

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

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

    if -5.09999999999999999e193 < y < -0.032000000000000001 or 2.25e117 < y < 1.7999999999999999e252

    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.f6466.9

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

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

    if -0.032000000000000001 < y < 0.0054999999999999997

    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 3 regimes into one program.
  4. Final simplification86.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -5.1 \cdot 10^{+193}:\\ \;\;\;\;x \cdot \sin y\\ \mathbf{elif}\;y \leq -0.032:\\ \;\;\;\;z \cdot \cos y\\ \mathbf{elif}\;y \leq 0.0055:\\ \;\;\;\;\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{elif}\;y \leq 2.25 \cdot 10^{+117}:\\ \;\;\;\;x \cdot \sin y\\ \mathbf{elif}\;y \leq 1.8 \cdot 10^{+252}:\\ \;\;\;\;z \cdot \cos y\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sin y\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 85.7% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := z \cdot \cos y\\ \mathbf{if}\;z \leq -7000000000000:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;z \leq 5.1 \cdot 10^{+138}:\\ \;\;\;\;\mathsf{fma}\left(\sin y, x, 1 \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* z (cos y))))
   (if (<= z -7000000000000.0)
     t_0
     (if (<= z 5.1e+138) (fma (sin y) x (* 1.0 z)) t_0))))
double code(double x, double y, double z) {
	double t_0 = z * cos(y);
	double tmp;
	if (z <= -7000000000000.0) {
		tmp = t_0;
	} else if (z <= 5.1e+138) {
		tmp = fma(sin(y), 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 <= -7000000000000.0)
		tmp = t_0;
	elseif (z <= 5.1e+138)
		tmp = fma(sin(y), x, Float64(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, -7000000000000.0], t$95$0, If[LessEqual[z, 5.1e+138], N[(N[Sin[y], $MachinePrecision] * x + N[(1.0 * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -7e12 or 5.0999999999999998e138 < z

    1. Initial program 99.8%

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

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

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

    if -7e12 < z < 5.0999999999999998e138

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

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

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

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

    Alternative 4: 75.2% accurate, 1.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := z \cdot \cos y\\ \mathbf{if}\;y \leq -0.032:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 3.3:\\ \;\;\;\;\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 -0.032)
         t_0
         (if (<= y 3.3)
           (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 <= -0.032) {
    		tmp = t_0;
    	} else if (y <= 3.3) {
    		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 <= -0.032)
    		tmp = t_0;
    	elseif (y <= 3.3)
    		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, -0.032], t$95$0, If[LessEqual[y, 3.3], 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 -0.032:\\
    \;\;\;\;t\_0\\
    
    \mathbf{elif}\;y \leq 3.3:\\
    \;\;\;\;\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 < -0.032000000000000001 or 3.2999999999999998 < 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.f6450.0

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

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

      if -0.032000000000000001 < y < 3.2999999999999998

      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-*.f6499.2

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -0.032:\\ \;\;\;\;z \cdot \cos y\\ \mathbf{elif}\;y \leq 3.3:\\ \;\;\;\;\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 5: 41.2% accurate, 11.9× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -3.8 \cdot 10^{+150}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{+243}:\\ \;\;\;\;1 \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
    (FPCore (x y z)
     :precision binary64
     (if (<= x -3.8e+150) (* x y) (if (<= x 1.65e+243) (* 1.0 z) (* x y))))
    double code(double x, double y, double z) {
    	double tmp;
    	if (x <= -3.8e+150) {
    		tmp = x * y;
    	} else if (x <= 1.65e+243) {
    		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 <= (-3.8d+150)) then
            tmp = x * y
        else if (x <= 1.65d+243) 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 <= -3.8e+150) {
    		tmp = x * y;
    	} else if (x <= 1.65e+243) {
    		tmp = 1.0 * z;
    	} else {
    		tmp = x * y;
    	}
    	return tmp;
    }
    
    def code(x, y, z):
    	tmp = 0
    	if x <= -3.8e+150:
    		tmp = x * y
    	elif x <= 1.65e+243:
    		tmp = 1.0 * z
    	else:
    		tmp = x * y
    	return tmp
    
    function code(x, y, z)
    	tmp = 0.0
    	if (x <= -3.8e+150)
    		tmp = Float64(x * y);
    	elseif (x <= 1.65e+243)
    		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 <= -3.8e+150)
    		tmp = x * y;
    	elseif (x <= 1.65e+243)
    		tmp = 1.0 * z;
    	else
    		tmp = x * y;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_, y_, z_] := If[LessEqual[x, -3.8e+150], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.65e+243], N[(1.0 * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;x \leq -3.8 \cdot 10^{+150}:\\
    \;\;\;\;x \cdot y\\
    
    \mathbf{elif}\;x \leq 1.65 \cdot 10^{+243}:\\
    \;\;\;\;1 \cdot z\\
    
    \mathbf{else}:\\
    \;\;\;\;x \cdot y\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if x < -3.79999999999999989e150 or 1.64999999999999997e243 < x

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

          \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, z\right)} \]
      5. Applied rewrites69.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 rewrites51.4%

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

        if -3.79999999999999989e150 < x < 1.64999999999999997e243

        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. div-subN/A

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

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{z \cdot \cos y} \]
        6. 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.f6470.3

            \[\leadsto \color{blue}{\cos y} \cdot z \]
        7. Applied rewrites70.3%

          \[\leadsto \color{blue}{\cos y \cdot z} \]
        8. Taylor expanded in y around 0

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

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

          \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.8 \cdot 10^{+150}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{+243}:\\ \;\;\;\;1 \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
        12. Add Preprocessing

        Alternative 6: 52.4% 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.f6456.8

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

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

        Alternative 7: 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.f6456.8

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

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

            \[\leadsto y \cdot \color{blue}{x} \]
          2. Final simplification17.7%

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

          Reproduce

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