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

Percentage Accurate: 99.8% → 99.8%
Time: 11.9s
Alternatives: 10
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 10 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.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 75.0% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := z \cdot \cos y\\ \mathbf{if}\;y \leq -4 \cdot 10^{+231}:\\ \;\;\;\;\frac{1}{\frac{\frac{1}{\cos y}}{z}}\\ \mathbf{elif}\;y \leq -7.2 \cdot 10^{+24}:\\ \;\;\;\;\sin y \cdot x\\ \mathbf{elif}\;y \leq 0.0105:\\ \;\;\;\;t\_0 + y \cdot \mathsf{fma}\left(x \cdot \left(y \cdot y\right), \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, -0.0001984126984126984, 0.008333333333333333\right), -0.16666666666666666\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* z (cos y))))
   (if (<= y -4e+231)
     (/ 1.0 (/ (/ 1.0 (cos y)) z))
     (if (<= y -7.2e+24)
       (* (sin y) x)
       (if (<= y 0.0105)
         (+
          t_0
          (*
           y
           (fma
            (* x (* y y))
            (fma
             y
             (* y (fma (* y y) -0.0001984126984126984 0.008333333333333333))
             -0.16666666666666666)
            x)))
         t_0)))))
double code(double x, double y, double z) {
	double t_0 = z * cos(y);
	double tmp;
	if (y <= -4e+231) {
		tmp = 1.0 / ((1.0 / cos(y)) / z);
	} else if (y <= -7.2e+24) {
		tmp = sin(y) * x;
	} else if (y <= 0.0105) {
		tmp = t_0 + (y * fma((x * (y * y)), fma(y, (y * fma((y * y), -0.0001984126984126984, 0.008333333333333333)), -0.16666666666666666), x));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(x, y, z)
	t_0 = Float64(z * cos(y))
	tmp = 0.0
	if (y <= -4e+231)
		tmp = Float64(1.0 / Float64(Float64(1.0 / cos(y)) / z));
	elseif (y <= -7.2e+24)
		tmp = Float64(sin(y) * x);
	elseif (y <= 0.0105)
		tmp = Float64(t_0 + Float64(y * fma(Float64(x * Float64(y * y)), fma(y, Float64(y * fma(Float64(y * y), -0.0001984126984126984, 0.008333333333333333)), -0.16666666666666666), x)));
	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, -4e+231], N[(1.0 / N[(N[(1.0 / N[Cos[y], $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, -7.2e+24], N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision], If[LessEqual[y, 0.0105], N[(t$95$0 + N[(y * N[(N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision] * N[(y * N[(y * N[(N[(y * y), $MachinePrecision] * -0.0001984126984126984 + 0.008333333333333333), $MachinePrecision]), $MachinePrecision] + -0.16666666666666666), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;y \leq -4 \cdot 10^{+231}:\\
\;\;\;\;\frac{1}{\frac{\frac{1}{\cos y}}{z}}\\

\mathbf{elif}\;y \leq -7.2 \cdot 10^{+24}:\\
\;\;\;\;\sin y \cdot x\\

\mathbf{elif}\;y \leq 0.0105:\\
\;\;\;\;t\_0 + y \cdot \mathsf{fma}\left(x \cdot \left(y \cdot y\right), \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, -0.0001984126984126984, 0.008333333333333333\right), -0.16666666666666666\right), x\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < -4.0000000000000002e231

    1. Initial program 99.4%

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

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

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

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

        \[\leadsto x \cdot \sin y + \color{blue}{z \cdot \cos y} \]
      5. 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}} \]
      6. clear-numN/A

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

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

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{\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}}}} \]
      9. flip-+N/A

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

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

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

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

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

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{z \cdot \cos y} + x \cdot \sin y}} \]
    4. Applied rewrites99.2%

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

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{z \cdot \cos y}}} \]
    6. Step-by-step derivation
      1. lower-/.f64N/A

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

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

        \[\leadsto \frac{1}{\frac{1}{z \cdot \color{blue}{\cos y}}} \]
    7. Applied rewrites67.2%

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{z \cdot \cos y}}} \]
    8. Step-by-step derivation
      1. lift-cos.f64N/A

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

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{z \cdot \cos y}}} \]
      3. unpow1N/A

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{{\left(z \cdot \cos y\right)}^{1}}}} \]
      4. pow-flipN/A

        \[\leadsto \frac{1}{\color{blue}{{\left(z \cdot \cos y\right)}^{\left(\mathsf{neg}\left(1\right)\right)}}} \]
      5. metadata-evalN/A

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

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

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

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{\cos y \cdot z}}} \]
      9. associate-/r*N/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{1}{\cos y}}{z}}} \]
      10. lower-/.f64N/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{1}{\cos y}}{z}}} \]
      11. lower-/.f6467.6

        \[\leadsto \frac{1}{\frac{\color{blue}{\frac{1}{\cos y}}}{z}} \]
    9. Applied rewrites67.6%

      \[\leadsto \frac{1}{\color{blue}{\frac{\frac{1}{\cos y}}{z}}} \]

    if -4.0000000000000002e231 < y < -7.19999999999999966e24

    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.f6468.0

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

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

    if -7.19999999999999966e24 < y < 0.0105000000000000007

    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 + {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)} + z \cdot \cos y \]
    4. Applied rewrites99.2%

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

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

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

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

      \[\leadsto \color{blue}{z \cdot \cos y} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification80.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4 \cdot 10^{+231}:\\ \;\;\;\;\frac{1}{\frac{\frac{1}{\cos y}}{z}}\\ \mathbf{elif}\;y \leq -7.2 \cdot 10^{+24}:\\ \;\;\;\;\sin y \cdot x\\ \mathbf{elif}\;y \leq 0.0105:\\ \;\;\;\;z \cdot \cos y + y \cdot \mathsf{fma}\left(x \cdot \left(y \cdot y\right), \mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(y \cdot y, -0.0001984126984126984, 0.008333333333333333\right), -0.16666666666666666\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \cos y\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 75.5% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
t_0 := \sin y \cdot x\\
\mathbf{if}\;y \leq -4 \cdot 10^{+231}:\\
\;\;\;\;\frac{1}{\frac{\frac{1}{\cos y}}{z}}\\

\mathbf{elif}\;y \leq -4.8 \cdot 10^{+19}:\\
\;\;\;\;t\_0\\

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

\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < -4.0000000000000002e231

    1. Initial program 99.4%

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

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

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

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

        \[\leadsto x \cdot \sin y + \color{blue}{z \cdot \cos y} \]
      5. 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}} \]
      6. clear-numN/A

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

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

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{\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}}}} \]
      9. flip-+N/A

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

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

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

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

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

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{z \cdot \cos y} + x \cdot \sin y}} \]
    4. Applied rewrites99.2%

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

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{z \cdot \cos y}}} \]
    6. Step-by-step derivation
      1. lower-/.f64N/A

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

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

        \[\leadsto \frac{1}{\frac{1}{z \cdot \color{blue}{\cos y}}} \]
    7. Applied rewrites67.2%

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{z \cdot \cos y}}} \]
    8. Step-by-step derivation
      1. lift-cos.f64N/A

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

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{z \cdot \cos y}}} \]
      3. unpow1N/A

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{{\left(z \cdot \cos y\right)}^{1}}}} \]
      4. pow-flipN/A

        \[\leadsto \frac{1}{\color{blue}{{\left(z \cdot \cos y\right)}^{\left(\mathsf{neg}\left(1\right)\right)}}} \]
      5. metadata-evalN/A

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

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

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

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{\cos y \cdot z}}} \]
      9. associate-/r*N/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{1}{\cos y}}{z}}} \]
      10. lower-/.f64N/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{1}{\cos y}}{z}}} \]
      11. lower-/.f6467.6

        \[\leadsto \frac{1}{\frac{\color{blue}{\frac{1}{\cos y}}}{z}} \]
    9. Applied rewrites67.6%

      \[\leadsto \frac{1}{\color{blue}{\frac{\frac{1}{\cos y}}{z}}} \]

    if -4.0000000000000002e231 < y < -4.8e19

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

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

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

    if -4.8e19 < y < 17.5

    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 + {y}^{2} \cdot \left(\frac{-1}{720} \cdot \left({y}^{2} \cdot z\right) + \frac{1}{24} \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 + {y}^{2} \cdot \left(\frac{-1}{720} \cdot \left({y}^{2} \cdot z\right) + \frac{1}{24} \cdot z\right)\right) + z\right)} \]
    5. Applied rewrites97.1%

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

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

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

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

      \[\leadsto \color{blue}{z \cdot \cos y} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification79.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4 \cdot 10^{+231}:\\ \;\;\;\;\frac{1}{\frac{\frac{1}{\cos y}}{z}}\\ \mathbf{elif}\;y \leq -4.8 \cdot 10^{+19}:\\ \;\;\;\;\sin y \cdot x\\ \mathbf{elif}\;y \leq 17.5:\\ \;\;\;\;\sin y \cdot x + \mathsf{fma}\left(z \cdot \left(y \cdot y\right), \mathsf{fma}\left(y \cdot y, \mathsf{fma}\left(y, y \cdot -0.001388888888888889, 0.041666666666666664\right), -0.5\right), z\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \cos y\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 75.3% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -4 \cdot 10^{+231}:\\ \;\;\;\;\frac{1}{\frac{\frac{1}{\cos y}}{z}}\\ \mathbf{elif}\;y \leq -0.016:\\ \;\;\;\;\sin y \cdot x\\ \mathbf{elif}\;y \leq 0.0102:\\ \;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(z, -0.5, -0.16666666666666666 \cdot \left(y \cdot x\right)\right), x\right), z\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \cos y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -4e+231)
   (/ 1.0 (/ (/ 1.0 (cos y)) z))
   (if (<= y -0.016)
     (* (sin y) x)
     (if (<= y 0.0102)
       (fma y (fma y (fma z -0.5 (* -0.16666666666666666 (* y x))) x) z)
       (* z (cos y))))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -4e+231) {
		tmp = 1.0 / ((1.0 / cos(y)) / z);
	} else if (y <= -0.016) {
		tmp = sin(y) * x;
	} else if (y <= 0.0102) {
		tmp = fma(y, fma(y, fma(z, -0.5, (-0.16666666666666666 * (y * x))), x), z);
	} else {
		tmp = z * cos(y);
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if (y <= -4e+231)
		tmp = Float64(1.0 / Float64(Float64(1.0 / cos(y)) / z));
	elseif (y <= -0.016)
		tmp = Float64(sin(y) * x);
	elseif (y <= 0.0102)
		tmp = fma(y, fma(y, fma(z, -0.5, Float64(-0.16666666666666666 * Float64(y * x))), x), z);
	else
		tmp = Float64(z * cos(y));
	end
	return tmp
end
code[x_, y_, z_] := If[LessEqual[y, -4e+231], N[(1.0 / N[(N[(1.0 / N[Cos[y], $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, -0.016], N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision], If[LessEqual[y, 0.0102], N[(y * N[(y * N[(z * -0.5 + N[(-0.16666666666666666 * N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{+231}:\\
\;\;\;\;\frac{1}{\frac{\frac{1}{\cos y}}{z}}\\

\mathbf{elif}\;y \leq -0.016:\\
\;\;\;\;\sin y \cdot x\\

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

\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if y < -4.0000000000000002e231

    1. Initial program 99.4%

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

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

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

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

        \[\leadsto x \cdot \sin y + \color{blue}{z \cdot \cos y} \]
      5. 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}} \]
      6. clear-numN/A

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

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

        \[\leadsto \frac{1}{\color{blue}{\frac{1}{\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}}}} \]
      9. flip-+N/A

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

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

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

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

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

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{z \cdot \cos y} + x \cdot \sin y}} \]
    4. Applied rewrites99.2%

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

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{z \cdot \cos y}}} \]
    6. Step-by-step derivation
      1. lower-/.f64N/A

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

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

        \[\leadsto \frac{1}{\frac{1}{z \cdot \color{blue}{\cos y}}} \]
    7. Applied rewrites67.2%

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{z \cdot \cos y}}} \]
    8. Step-by-step derivation
      1. lift-cos.f64N/A

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

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{z \cdot \cos y}}} \]
      3. unpow1N/A

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{{\left(z \cdot \cos y\right)}^{1}}}} \]
      4. pow-flipN/A

        \[\leadsto \frac{1}{\color{blue}{{\left(z \cdot \cos y\right)}^{\left(\mathsf{neg}\left(1\right)\right)}}} \]
      5. metadata-evalN/A

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

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

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

        \[\leadsto \frac{1}{\frac{1}{\color{blue}{\cos y \cdot z}}} \]
      9. associate-/r*N/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{1}{\cos y}}{z}}} \]
      10. lower-/.f64N/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{1}{\cos y}}{z}}} \]
      11. lower-/.f6467.6

        \[\leadsto \frac{1}{\frac{\color{blue}{\frac{1}{\cos y}}}{z}} \]
    9. Applied rewrites67.6%

      \[\leadsto \frac{1}{\color{blue}{\frac{\frac{1}{\cos y}}{z}}} \]

    if -4.0000000000000002e231 < y < -0.016

    1. Initial program 99.5%

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

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

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

    if -0.016 < y < 0.010200000000000001

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4 \cdot 10^{+231}:\\ \;\;\;\;\frac{1}{\frac{\frac{1}{\cos y}}{z}}\\ \mathbf{elif}\;y \leq -0.016:\\ \;\;\;\;\sin y \cdot x\\ \mathbf{elif}\;y \leq 0.0102:\\ \;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(z, -0.5, -0.16666666666666666 \cdot \left(y \cdot x\right)\right), x\right), z\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \cos y\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 75.3% accurate, 1.7× speedup?

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

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

\mathbf{elif}\;y \leq -0.016:\\
\;\;\;\;\sin y \cdot x\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -3.8000000000000001e231 or 0.010200000000000001 < 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. lower-*.f64N/A

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

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

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

    if -3.8000000000000001e231 < y < -0.016

    1. Initial program 99.5%

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

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

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

    if -0.016 < y < 0.010200000000000001

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 74.2% accurate, 1.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < -0.016 or 1.85e6 < 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.f6451.3

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

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

    if -0.016 < y < 1.85e6

    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}{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. lower-fma.f64N/A

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 39.7% accurate, 17.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -7.2 \cdot 10^{+113}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \end{array} \]
(FPCore (x y z) :precision binary64 (if (<= x -7.2e+113) (* y x) z))
double code(double x, double y, double z) {
	double tmp;
	if (x <= -7.2e+113) {
		tmp = y * x;
	} 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 (x <= (-7.2d+113)) then
        tmp = y * x
    else
        tmp = z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= -7.2e+113) {
		tmp = y * x;
	} else {
		tmp = z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= -7.2e+113:
		tmp = y * x
	else:
		tmp = z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= -7.2e+113)
		tmp = Float64(y * x);
	else
		tmp = z;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= -7.2e+113)
		tmp = y * x;
	else
		tmp = z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, -7.2e+113], N[(y * x), $MachinePrecision], z]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{+113}:\\
\;\;\;\;y \cdot x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -7.19999999999999984e113

    1. Initial program 99.7%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{x \cdot y} \]
    8. Applied rewrites30.7%

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

    if -7.19999999999999984e113 < x

    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.f6471.5

        \[\leadsto z \cdot \color{blue}{\cos y} \]
    5. Applied rewrites71.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. Applied rewrites45.1%

        \[\leadsto z \cdot \color{blue}{1} \]
      2. Step-by-step derivation
        1. *-rgt-identity45.1

          \[\leadsto \color{blue}{z} \]
      3. Applied rewrites45.1%

        \[\leadsto \color{blue}{z} \]
    8. Recombined 2 regimes into one program.
    9. Final simplification42.5%

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

    Alternative 9: 52.0% 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.7%

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

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

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

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

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

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

    Alternative 10: 38.5% accurate, 214.0× speedup?

    \[\begin{array}{l} \\ z \end{array} \]
    (FPCore (x y z) :precision binary64 z)
    double code(double x, double y, double z) {
    	return z;
    }
    
    real(8) function code(x, y, z)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        real(8), intent (in) :: z
        code = z
    end function
    
    public static double code(double x, double y, double z) {
    	return z;
    }
    
    def code(x, y, z):
    	return z
    
    function code(x, y, z)
    	return z
    end
    
    function tmp = code(x, y, z)
    	tmp = z;
    end
    
    code[x_, y_, z_] := z
    
    \begin{array}{l}
    
    \\
    z
    \end{array}
    
    Derivation
    1. Initial program 99.7%

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

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

      \[\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. Applied rewrites40.1%

        \[\leadsto z \cdot \color{blue}{1} \]
      2. Step-by-step derivation
        1. *-rgt-identity40.1

          \[\leadsto \color{blue}{z} \]
      3. Applied rewrites40.1%

        \[\leadsto \color{blue}{z} \]
      4. Add Preprocessing

      Reproduce

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