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

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

\\
\mathsf{fma}\left(x, \sin y, 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. Taylor expanded in x around 0

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

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

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

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

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

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

Alternative 2: 74.4% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \sin y\\ t_1 := z \cdot \cos y\\ \mathbf{if}\;y \leq -8.5 \cdot 10^{+216}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq -3.7 \cdot 10^{+25}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;y \leq 4.5 \cdot 10^{+31}:\\ \;\;\;\;t\_0 + \mathsf{fma}\left(y \cdot y, z \cdot \mathsf{fma}\left(y \cdot y, 0.041666666666666664, -0.5\right), z\right)\\ \mathbf{elif}\;y \leq 1.02 \cdot 10^{+194}:\\ \;\;\;\;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 -8.5e+216)
     t_0
     (if (<= y -3.7e+25)
       t_1
       (if (<= y 4.5e+31)
         (+ t_0 (fma (* y y) (* z (fma (* y y) 0.041666666666666664 -0.5)) z))
         (if (<= y 1.02e+194) 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 <= -8.5e+216) {
		tmp = t_0;
	} else if (y <= -3.7e+25) {
		tmp = t_1;
	} else if (y <= 4.5e+31) {
		tmp = t_0 + fma((y * y), (z * fma((y * y), 0.041666666666666664, -0.5)), z);
	} else if (y <= 1.02e+194) {
		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 <= -8.5e+216)
		tmp = t_0;
	elseif (y <= -3.7e+25)
		tmp = t_1;
	elseif (y <= 4.5e+31)
		tmp = Float64(t_0 + fma(Float64(y * y), Float64(z * fma(Float64(y * y), 0.041666666666666664, -0.5)), z));
	elseif (y <= 1.02e+194)
		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, -8.5e+216], t$95$0, If[LessEqual[y, -3.7e+25], t$95$1, If[LessEqual[y, 4.5e+31], N[(t$95$0 + N[(N[(y * y), $MachinePrecision] * N[(z * N[(N[(y * y), $MachinePrecision] * 0.041666666666666664 + -0.5), $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.02e+194], 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 -8.5 \cdot 10^{+216}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq -3.7 \cdot 10^{+25}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;y \leq 4.5 \cdot 10^{+31}:\\
\;\;\;\;t\_0 + \mathsf{fma}\left(y \cdot y, z \cdot \mathsf{fma}\left(y \cdot y, 0.041666666666666664, -0.5\right), z\right)\\

\mathbf{elif}\;y \leq 1.02 \cdot 10^{+194}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -8.4999999999999997e216 or 1.02e194 < y

    1. Initial program 99.6%

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

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

        \[\leadsto \color{blue}{x \cdot \sin y} \]
      2. lower-sin.f6467.5

        \[\leadsto x \cdot \color{blue}{\sin y} \]
    5. Simplified67.5%

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

    if -8.4999999999999997e216 < y < -3.6999999999999999e25 or 4.4999999999999996e31 < y < 1.02e194

    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. lower-*.f64N/A

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

        \[\leadsto z \cdot \color{blue}{\cos y} \]
    5. Simplified59.3%

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

    if -3.6999999999999999e25 < y < 4.4999999999999996e31

    1. Initial program 99.9%

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

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

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

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

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

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

        \[\leadsto x \cdot \sin y + \mathsf{fma}\left(y \cdot y, \frac{-1}{2} \cdot z + \color{blue}{\left(\frac{1}{24} \cdot {y}^{2}\right) \cdot z}, z\right) \]
      6. distribute-rgt-outN/A

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

        \[\leadsto x \cdot \sin y + \mathsf{fma}\left(y \cdot y, z \cdot \color{blue}{\left(\frac{1}{24} \cdot {y}^{2} + \frac{-1}{2}\right)}, z\right) \]
      8. metadata-evalN/A

        \[\leadsto x \cdot \sin y + \mathsf{fma}\left(y \cdot y, z \cdot \left(\frac{1}{24} \cdot {y}^{2} + \color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}\right), z\right) \]
      9. sub-negN/A

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

        \[\leadsto x \cdot \sin y + \mathsf{fma}\left(y \cdot y, \color{blue}{z \cdot \left(\frac{1}{24} \cdot {y}^{2} - \frac{1}{2}\right)}, z\right) \]
      11. sub-negN/A

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

        \[\leadsto x \cdot \sin y + \mathsf{fma}\left(y \cdot y, z \cdot \left(\color{blue}{{y}^{2} \cdot \frac{1}{24}} + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right), z\right) \]
      13. metadata-evalN/A

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

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

        \[\leadsto x \cdot \sin y + \mathsf{fma}\left(y \cdot y, z \cdot \mathsf{fma}\left(\color{blue}{y \cdot y}, \frac{1}{24}, \frac{-1}{2}\right), z\right) \]
      16. lower-*.f6496.9

        \[\leadsto x \cdot \sin y + \mathsf{fma}\left(y \cdot y, z \cdot \mathsf{fma}\left(\color{blue}{y \cdot y}, 0.041666666666666664, -0.5\right), z\right) \]
    5. Simplified96.9%

      \[\leadsto x \cdot \sin y + \color{blue}{\mathsf{fma}\left(y \cdot y, z \cdot \mathsf{fma}\left(y \cdot y, 0.041666666666666664, -0.5\right), z\right)} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 3: 75.5% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;y \leq -3.9:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 12500000000000:\\
\;\;\;\;z \cdot \cos y + x \cdot \mathsf{fma}\left(y \cdot y, y \cdot -0.16666666666666666, y\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -3.89999999999999991 or 1.25e13 < y

    1. Initial program 99.7%

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

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

        \[\leadsto \color{blue}{x \cdot \sin y} \]
      2. lower-sin.f6453.7

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

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

    if -3.89999999999999991 < y < 1.25e13

    1. Initial program 99.9%

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

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

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

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

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

        \[\leadsto \left(y \cdot x + \color{blue}{\left(\left(y \cdot \frac{-1}{6}\right) \cdot {y}^{2}\right) \cdot x}\right) + z \cdot \cos y \]
      5. distribute-rgt-outN/A

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

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

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

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

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

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

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

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

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

        \[\leadsto x \cdot \mathsf{fma}\left(y \cdot y, \color{blue}{y \cdot -0.16666666666666666}, y\right) + z \cdot \cos y \]
    5. Simplified99.1%

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

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

Alternative 4: 75.1% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;y \leq -1.1:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 1.92:\\
\;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right), y \cdot \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, x \cdot \mathsf{fma}\left(-0.0001984126984126984, y \cdot y, 0.008333333333333333\right), x \cdot -0.16666666666666666\right), x\right)\right)\\

\mathbf{elif}\;y \leq 1.02 \cdot 10^{+194}:\\
\;\;\;\;z \cdot \cos y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.1000000000000001 or 1.02e194 < y

    1. Initial program 99.7%

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

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

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

        \[\leadsto x \cdot \color{blue}{\sin y} \]
    5. Simplified57.4%

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

    if -1.1000000000000001 < y < 1.9199999999999999

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(z, \color{blue}{1 + {y}^{2} \cdot \left({y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) - \frac{1}{2}\right)}, x \cdot \sin y\right) \]
    10. Step-by-step derivation
      1. +-commutativeN/A

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

        \[\leadsto \mathsf{fma}\left(z, \color{blue}{\left(y \cdot y\right)} \cdot \left({y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) - \frac{1}{2}\right) + 1, x \cdot \sin y\right) \]
      3. associate-*l*N/A

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

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

        \[\leadsto \mathsf{fma}\left(z, \mathsf{fma}\left(y, \color{blue}{y \cdot \left({y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) - \frac{1}{2}\right)}, 1\right), x \cdot \sin y\right) \]
      6. sub-negN/A

        \[\leadsto \mathsf{fma}\left(z, \mathsf{fma}\left(y, y \cdot \color{blue}{\left({y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)}, 1\right), x \cdot \sin y\right) \]
      7. metadata-evalN/A

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

        \[\leadsto \mathsf{fma}\left(z, \mathsf{fma}\left(y, y \cdot \color{blue}{\mathsf{fma}\left({y}^{2}, \frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}, \frac{-1}{2}\right)}, 1\right), x \cdot \sin y\right) \]
      9. unpow2N/A

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(z, \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(\color{blue}{y \cdot y}, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right), x \cdot \sin y\right) \]
    11. Simplified99.8%

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

      \[\leadsto \mathsf{fma}\left(z, \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \frac{-1}{720}, \frac{1}{24}\right), \frac{-1}{2}\right), 1\right), \color{blue}{y \cdot \left(x + {y}^{2} \cdot \left(\frac{-1}{6} \cdot x + {y}^{2} \cdot \left(\frac{-1}{5040} \cdot \left(x \cdot {y}^{2}\right) + \frac{1}{120} \cdot x\right)\right)\right)}\right) \]
    13. Step-by-step derivation
      1. lower-*.f64N/A

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

        \[\leadsto \mathsf{fma}\left(z, \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \frac{-1}{720}, \frac{1}{24}\right), \frac{-1}{2}\right), 1\right), y \cdot \color{blue}{\left({y}^{2} \cdot \left(\frac{-1}{6} \cdot x + {y}^{2} \cdot \left(\frac{-1}{5040} \cdot \left(x \cdot {y}^{2}\right) + \frac{1}{120} \cdot x\right)\right) + x\right)}\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{fma}\left(z, \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \frac{-1}{720}, \frac{1}{24}\right), \frac{-1}{2}\right), 1\right), y \cdot \left(\color{blue}{\left(y \cdot y\right)} \cdot \left(\frac{-1}{6} \cdot x + {y}^{2} \cdot \left(\frac{-1}{5040} \cdot \left(x \cdot {y}^{2}\right) + \frac{1}{120} \cdot x\right)\right) + x\right)\right) \]
      4. associate-*l*N/A

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

        \[\leadsto \mathsf{fma}\left(z, \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \frac{-1}{720}, \frac{1}{24}\right), \frac{-1}{2}\right), 1\right), y \cdot \color{blue}{\mathsf{fma}\left(y, y \cdot \left(\frac{-1}{6} \cdot x + {y}^{2} \cdot \left(\frac{-1}{5040} \cdot \left(x \cdot {y}^{2}\right) + \frac{1}{120} \cdot x\right)\right), x\right)}\right) \]
    14. Simplified99.3%

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

    if 1.9199999999999999 < y < 1.02e194

    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. lower-*.f64N/A

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

        \[\leadsto z \cdot \color{blue}{\cos y} \]
    5. Simplified56.3%

      \[\leadsto \color{blue}{z \cdot \cos y} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 5: 75.4% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := x \cdot \sin y\\ \mathbf{if}\;y \leq -1.1:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 0.65:\\ \;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right), y \cdot \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, x \cdot \mathsf{fma}\left(-0.0001984126984126984, y \cdot y, 0.008333333333333333\right), x \cdot -0.16666666666666666\right), x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* x (sin y))))
   (if (<= y -1.1)
     t_0
     (if (<= y 0.65)
       (fma
        z
        (fma
         y
         (*
          y
          (fma
           (* y y)
           (fma (* y y) -0.001388888888888889 0.041666666666666664)
           -0.5))
         1.0)
        (*
         y
         (fma
          y
          (*
           y
           (fma
            (* y y)
            (* x (fma -0.0001984126984126984 (* y y) 0.008333333333333333))
            (* x -0.16666666666666666)))
          x)))
       t_0))))
double code(double x, double y, double z) {
	double t_0 = x * sin(y);
	double tmp;
	if (y <= -1.1) {
		tmp = t_0;
	} else if (y <= 0.65) {
		tmp = fma(z, fma(y, (y * fma((y * y), fma((y * y), -0.001388888888888889, 0.041666666666666664), -0.5)), 1.0), (y * fma(y, (y * fma((y * y), (x * fma(-0.0001984126984126984, (y * y), 0.008333333333333333)), (x * -0.16666666666666666))), x)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(x, y, z)
	t_0 = Float64(x * sin(y))
	tmp = 0.0
	if (y <= -1.1)
		tmp = t_0;
	elseif (y <= 0.65)
		tmp = fma(z, fma(y, Float64(y * fma(Float64(y * y), fma(Float64(y * y), -0.001388888888888889, 0.041666666666666664), -0.5)), 1.0), Float64(y * fma(y, Float64(y * fma(Float64(y * y), Float64(x * fma(-0.0001984126984126984, Float64(y * y), 0.008333333333333333)), Float64(x * -0.16666666666666666))), x)));
	else
		tmp = t_0;
	end
	return tmp
end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.1], t$95$0, If[LessEqual[y, 0.65], N[(z * N[(y * N[(y * N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] * -0.001388888888888889 + 0.041666666666666664), $MachinePrecision] + -0.5), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] + N[(y * N[(y * N[(y * N[(N[(y * y), $MachinePrecision] * N[(x * N[(-0.0001984126984126984 * N[(y * y), $MachinePrecision] + 0.008333333333333333), $MachinePrecision]), $MachinePrecision] + N[(x * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;y \leq -1.1:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;y \leq 0.65:\\
\;\;\;\;\mathsf{fma}\left(z, \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right), y \cdot \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, x \cdot \mathsf{fma}\left(-0.0001984126984126984, y \cdot y, 0.008333333333333333\right), x \cdot -0.16666666666666666\right), x\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -1.1000000000000001 or 0.650000000000000022 < y

    1. Initial program 99.7%

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

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

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

        \[\leadsto x \cdot \color{blue}{\sin y} \]
    5. Simplified53.3%

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

    if -1.1000000000000001 < y < 0.650000000000000022

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(z, \color{blue}{1 + {y}^{2} \cdot \left({y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) - \frac{1}{2}\right)}, x \cdot \sin y\right) \]
    10. Step-by-step derivation
      1. +-commutativeN/A

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

        \[\leadsto \mathsf{fma}\left(z, \color{blue}{\left(y \cdot y\right)} \cdot \left({y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) - \frac{1}{2}\right) + 1, x \cdot \sin y\right) \]
      3. associate-*l*N/A

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

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

        \[\leadsto \mathsf{fma}\left(z, \mathsf{fma}\left(y, \color{blue}{y \cdot \left({y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) - \frac{1}{2}\right)}, 1\right), x \cdot \sin y\right) \]
      6. sub-negN/A

        \[\leadsto \mathsf{fma}\left(z, \mathsf{fma}\left(y, y \cdot \color{blue}{\left({y}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}\right) + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)}, 1\right), x \cdot \sin y\right) \]
      7. metadata-evalN/A

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

        \[\leadsto \mathsf{fma}\left(z, \mathsf{fma}\left(y, y \cdot \color{blue}{\mathsf{fma}\left({y}^{2}, \frac{1}{24} + \frac{-1}{720} \cdot {y}^{2}, \frac{-1}{2}\right)}, 1\right), x \cdot \sin y\right) \]
      9. unpow2N/A

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(z, \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(\color{blue}{y \cdot y}, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right), x \cdot \sin y\right) \]
    11. Simplified99.8%

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

      \[\leadsto \mathsf{fma}\left(z, \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \frac{-1}{720}, \frac{1}{24}\right), \frac{-1}{2}\right), 1\right), \color{blue}{y \cdot \left(x + {y}^{2} \cdot \left(\frac{-1}{6} \cdot x + {y}^{2} \cdot \left(\frac{-1}{5040} \cdot \left(x \cdot {y}^{2}\right) + \frac{1}{120} \cdot x\right)\right)\right)}\right) \]
    13. Step-by-step derivation
      1. lower-*.f64N/A

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

        \[\leadsto \mathsf{fma}\left(z, \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \frac{-1}{720}, \frac{1}{24}\right), \frac{-1}{2}\right), 1\right), y \cdot \color{blue}{\left({y}^{2} \cdot \left(\frac{-1}{6} \cdot x + {y}^{2} \cdot \left(\frac{-1}{5040} \cdot \left(x \cdot {y}^{2}\right) + \frac{1}{120} \cdot x\right)\right) + x\right)}\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{fma}\left(z, \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \frac{-1}{720}, \frac{1}{24}\right), \frac{-1}{2}\right), 1\right), y \cdot \left(\color{blue}{\left(y \cdot y\right)} \cdot \left(\frac{-1}{6} \cdot x + {y}^{2} \cdot \left(\frac{-1}{5040} \cdot \left(x \cdot {y}^{2}\right) + \frac{1}{120} \cdot x\right)\right) + x\right)\right) \]
      4. associate-*l*N/A

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

        \[\leadsto \mathsf{fma}\left(z, \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, \frac{-1}{720}, \frac{1}{24}\right), \frac{-1}{2}\right), 1\right), y \cdot \color{blue}{\mathsf{fma}\left(y, y \cdot \left(\frac{-1}{6} \cdot x + {y}^{2} \cdot \left(\frac{-1}{5040} \cdot \left(x \cdot {y}^{2}\right) + \frac{1}{120} \cdot x\right)\right), x\right)}\right) \]
    14. Simplified99.8%

      \[\leadsto \mathsf{fma}\left(z, \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y \cdot y, -0.001388888888888889, 0.041666666666666664\right), -0.5\right), 1\right), \color{blue}{y \cdot \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, x \cdot \mathsf{fma}\left(-0.0001984126984126984, y \cdot y, 0.008333333333333333\right), x \cdot -0.16666666666666666\right), x\right)}\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 40.3% accurate, 11.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1.7 \cdot 10^{-113}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq -1.05 \cdot 10^{-299}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= z -1.7e-113) z (if (<= z -1.05e-299) (* x y) z)))
double code(double x, double y, double z) {
	double tmp;
	if (z <= -1.7e-113) {
		tmp = z;
	} else if (z <= -1.05e-299) {
		tmp = x * y;
	} else {
		tmp = z;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (z <= (-1.7d-113)) then
        tmp = z
    else if (z <= (-1.05d-299)) then
        tmp = x * y
    else
        tmp = z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (z <= -1.7e-113) {
		tmp = z;
	} else if (z <= -1.05e-299) {
		tmp = x * y;
	} else {
		tmp = z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if z <= -1.7e-113:
		tmp = z
	elif z <= -1.05e-299:
		tmp = x * y
	else:
		tmp = z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (z <= -1.7e-113)
		tmp = z;
	elseif (z <= -1.05e-299)
		tmp = Float64(x * y);
	else
		tmp = z;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (z <= -1.7e-113)
		tmp = z;
	elseif (z <= -1.05e-299)
		tmp = x * y;
	else
		tmp = z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[z, -1.7e-113], z, If[LessEqual[z, -1.05e-299], N[(x * y), $MachinePrecision], z]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{-113}:\\
\;\;\;\;z\\

\mathbf{elif}\;z \leq -1.05 \cdot 10^{-299}:\\
\;\;\;\;x \cdot y\\

\mathbf{else}:\\
\;\;\;\;z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.7000000000000001e-113 or -1.05000000000000005e-299 < 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. lower-*.f64N/A

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

        \[\leadsto z \cdot \color{blue}{\cos y} \]
    5. Simplified67.5%

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

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

        \[\leadsto z \cdot \color{blue}{1} \]

      if -1.7000000000000001e-113 < z < -1.05000000000000005e-299

      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. lower-fma.f6457.8

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

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

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

          \[\leadsto \color{blue}{y \cdot x} \]
        2. lower-*.f6448.9

          \[\leadsto \color{blue}{y \cdot x} \]
      8. Simplified48.9%

        \[\leadsto \color{blue}{y \cdot x} \]
    8. Recombined 2 regimes into one program.
    9. Final simplification45.7%

      \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.7 \cdot 10^{-113}:\\ \;\;\;\;z\\ \mathbf{elif}\;z \leq -1.05 \cdot 10^{-299}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
    10. Add Preprocessing

    Alternative 7: 52.2% accurate, 30.6× speedup?

    \[\begin{array}{l} \\ \mathsf{fma}\left(x, y, z\right) \end{array} \]
    (FPCore (x y z) :precision binary64 (fma x y z))
    double code(double x, double y, double z) {
    	return fma(x, y, z);
    }
    
    function code(x, y, z)
    	return fma(x, y, z)
    end
    
    code[x_, y_, z_] := N[(x * y + z), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \mathsf{fma}\left(x, y, 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. lower-fma.f6454.8

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

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

    Alternative 8: 16.3% 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. lower-fma.f6454.8

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

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

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

        \[\leadsto \color{blue}{y \cdot x} \]
      2. lower-*.f6417.0

        \[\leadsto \color{blue}{y \cdot x} \]
    8. Simplified17.0%

      \[\leadsto \color{blue}{y \cdot x} \]
    9. Final simplification17.0%

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

    Reproduce

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