Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3

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

Specification

?
\[\begin{array}{l} \\ x \cdot \cos y + z \cdot \sin y \end{array} \]
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
	return (x * cos(y)) + (z * sin(y));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
	return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z):
	return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z)
	return Float64(Float64(x * cos(y)) + Float64(z * sin(y)))
end
function tmp = code(x, y, z)
	tmp = (x * cos(y)) + (z * sin(y));
end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot \cos y + z \cdot \sin 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 \cos y + z \cdot \sin y \end{array} \]
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
	return (x * cos(y)) + (z * sin(y));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (x * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
	return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z):
	return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z)
	return Float64(Float64(x * cos(y)) + Float64(z * sin(y)))
end
function tmp = code(x, y, z)
	tmp = (x * cos(y)) + (z * sin(y));
end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 99.8% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.8% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 74.8% accurate, 1.6× speedup?

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

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

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

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

\mathbf{elif}\;y \leq 2.05 \cdot 10^{+241}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -4.4e237 or 2.05000000000000007e241 < y

    1. Initial program 99.8%

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

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

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

      if -4.4e237 < y < -0.0420000000000000026 or 0.095000000000000001 < y < 2.05000000000000007e241

      1. Initial program 99.7%

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

        \[\leadsto \color{blue}{z \cdot \sin y} \]
      4. Step-by-step derivation
        1. Applied rewrites61.6%

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

        if -0.0420000000000000026 < y < 0.095000000000000001

        1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \mathsf{fma}\left(\color{blue}{y \cdot \left(1 + {y}^{2} \cdot \left(\frac{1}{120} \cdot {y}^{2} - \frac{1}{6}\right)\right)}, z, x\right) \]
          3. Step-by-step derivation
            1. Applied rewrites99.4%

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

          Alternative 4: 86.1% accurate, 1.8× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.25 \cdot 10^{+84} \lor \neg \left(x \leq 5.4 \cdot 10^{+101}\right):\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\sin y, z, x\right)\\ \end{array} \end{array} \]
          (FPCore (x y z)
           :precision binary64
           (if (or (<= x -1.25e+84) (not (<= x 5.4e+101)))
             (* (cos y) x)
             (fma (sin y) z x)))
          double code(double x, double y, double z) {
          	double tmp;
          	if ((x <= -1.25e+84) || !(x <= 5.4e+101)) {
          		tmp = cos(y) * x;
          	} else {
          		tmp = fma(sin(y), z, x);
          	}
          	return tmp;
          }
          
          function code(x, y, z)
          	tmp = 0.0
          	if ((x <= -1.25e+84) || !(x <= 5.4e+101))
          		tmp = Float64(cos(y) * x);
          	else
          		tmp = fma(sin(y), z, x);
          	end
          	return tmp
          end
          
          code[x_, y_, z_] := If[Or[LessEqual[x, -1.25e+84], N[Not[LessEqual[x, 5.4e+101]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * z + x), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;x \leq -1.25 \cdot 10^{+84} \lor \neg \left(x \leq 5.4 \cdot 10^{+101}\right):\\
          \;\;\;\;\cos y \cdot x\\
          
          \mathbf{else}:\\
          \;\;\;\;\mathsf{fma}\left(\sin y, z, x\right)\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if x < -1.25e84 or 5.40000000000000012e101 < x

            1. Initial program 99.9%

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

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

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

              if -1.25e84 < x < 5.40000000000000012e101

              1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

              Alternative 5: 75.1% accurate, 1.8× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -26000000 \lor \neg \left(y \leq 0.037\right):\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.008333333333333333, y \cdot y, -0.16666666666666666\right), y \cdot y, 1\right) \cdot y, z, x\right)\\ \end{array} \end{array} \]
              (FPCore (x y z)
               :precision binary64
               (if (or (<= y -26000000.0) (not (<= y 0.037)))
                 (* (cos y) x)
                 (fma
                  (*
                   (fma (fma 0.008333333333333333 (* y y) -0.16666666666666666) (* y y) 1.0)
                   y)
                  z
                  x)))
              double code(double x, double y, double z) {
              	double tmp;
              	if ((y <= -26000000.0) || !(y <= 0.037)) {
              		tmp = cos(y) * x;
              	} else {
              		tmp = fma((fma(fma(0.008333333333333333, (y * y), -0.16666666666666666), (y * y), 1.0) * y), z, x);
              	}
              	return tmp;
              }
              
              function code(x, y, z)
              	tmp = 0.0
              	if ((y <= -26000000.0) || !(y <= 0.037))
              		tmp = Float64(cos(y) * x);
              	else
              		tmp = fma(Float64(fma(fma(0.008333333333333333, Float64(y * y), -0.16666666666666666), Float64(y * y), 1.0) * y), z, x);
              	end
              	return tmp
              end
              
              code[x_, y_, z_] := If[Or[LessEqual[y, -26000000.0], N[Not[LessEqual[y, 0.037]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(N[(N[(N[(0.008333333333333333 * N[(y * y), $MachinePrecision] + -0.16666666666666666), $MachinePrecision] * N[(y * y), $MachinePrecision] + 1.0), $MachinePrecision] * y), $MachinePrecision] * z + x), $MachinePrecision]]
              
              \begin{array}{l}
              
              \\
              \begin{array}{l}
              \mathbf{if}\;y \leq -26000000 \lor \neg \left(y \leq 0.037\right):\\
              \;\;\;\;\cos y \cdot x\\
              
              \mathbf{else}:\\
              \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.008333333333333333, y \cdot y, -0.16666666666666666\right), y \cdot y, 1\right) \cdot y, z, x\right)\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if y < -2.6e7 or 0.0369999999999999982 < y

                1. Initial program 99.7%

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

                  \[\leadsto \color{blue}{x \cdot \cos y} \]
                4. Step-by-step derivation
                  1. Applied rewrites46.8%

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

                  if -2.6e7 < y < 0.0369999999999999982

                  1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto \mathsf{fma}\left(\color{blue}{y \cdot \left(1 + {y}^{2} \cdot \left(\frac{1}{120} \cdot {y}^{2} - \frac{1}{6}\right)\right)}, z, x\right) \]
                    3. Step-by-step derivation
                      1. Applied rewrites99.2%

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

                      \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -26000000 \lor \neg \left(y \leq 0.037\right):\\ \;\;\;\;\cos y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.008333333333333333, y \cdot y, -0.16666666666666666\right), y \cdot y, 1\right) \cdot y, z, x\right)\\ \end{array} \]
                    6. Add Preprocessing

                    Alternative 6: 40.7% accurate, 17.8× speedup?

                    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -2.1 \cdot 10^{+204}:\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
                    (FPCore (x y z) :precision binary64 (if (<= z -2.1e+204) (* z y) x))
                    double code(double x, double y, double z) {
                    	double tmp;
                    	if (z <= -2.1e+204) {
                    		tmp = z * y;
                    	} else {
                    		tmp = x;
                    	}
                    	return tmp;
                    }
                    
                    module fmin_fmax_functions
                        implicit none
                        private
                        public fmax
                        public fmin
                    
                        interface fmax
                            module procedure fmax88
                            module procedure fmax44
                            module procedure fmax84
                            module procedure fmax48
                        end interface
                        interface fmin
                            module procedure fmin88
                            module procedure fmin44
                            module procedure fmin84
                            module procedure fmin48
                        end interface
                    contains
                        real(8) function fmax88(x, y) result (res)
                            real(8), intent (in) :: x
                            real(8), intent (in) :: y
                            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                        end function
                        real(4) function fmax44(x, y) result (res)
                            real(4), intent (in) :: x
                            real(4), intent (in) :: y
                            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                        end function
                        real(8) function fmax84(x, y) result(res)
                            real(8), intent (in) :: x
                            real(4), intent (in) :: y
                            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                        end function
                        real(8) function fmax48(x, y) result(res)
                            real(4), intent (in) :: x
                            real(8), intent (in) :: y
                            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                        end function
                        real(8) function fmin88(x, y) result (res)
                            real(8), intent (in) :: x
                            real(8), intent (in) :: y
                            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                        end function
                        real(4) function fmin44(x, y) result (res)
                            real(4), intent (in) :: x
                            real(4), intent (in) :: y
                            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                        end function
                        real(8) function fmin84(x, y) result(res)
                            real(8), intent (in) :: x
                            real(4), intent (in) :: y
                            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                        end function
                        real(8) function fmin48(x, y) result(res)
                            real(4), intent (in) :: x
                            real(8), intent (in) :: y
                            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                        end function
                    end module
                    
                    real(8) function code(x, y, z)
                    use fmin_fmax_functions
                        real(8), intent (in) :: x
                        real(8), intent (in) :: y
                        real(8), intent (in) :: z
                        real(8) :: tmp
                        if (z <= (-2.1d+204)) then
                            tmp = z * y
                        else
                            tmp = x
                        end if
                        code = tmp
                    end function
                    
                    public static double code(double x, double y, double z) {
                    	double tmp;
                    	if (z <= -2.1e+204) {
                    		tmp = z * y;
                    	} else {
                    		tmp = x;
                    	}
                    	return tmp;
                    }
                    
                    def code(x, y, z):
                    	tmp = 0
                    	if z <= -2.1e+204:
                    		tmp = z * y
                    	else:
                    		tmp = x
                    	return tmp
                    
                    function code(x, y, z)
                    	tmp = 0.0
                    	if (z <= -2.1e+204)
                    		tmp = Float64(z * y);
                    	else
                    		tmp = x;
                    	end
                    	return tmp
                    end
                    
                    function tmp_2 = code(x, y, z)
                    	tmp = 0.0;
                    	if (z <= -2.1e+204)
                    		tmp = z * y;
                    	else
                    		tmp = x;
                    	end
                    	tmp_2 = tmp;
                    end
                    
                    code[x_, y_, z_] := If[LessEqual[z, -2.1e+204], N[(z * y), $MachinePrecision], x]
                    
                    \begin{array}{l}
                    
                    \\
                    \begin{array}{l}
                    \mathbf{if}\;z \leq -2.1 \cdot 10^{+204}:\\
                    \;\;\;\;z \cdot y\\
                    
                    \mathbf{else}:\\
                    \;\;\;\;x\\
                    
                    
                    \end{array}
                    \end{array}
                    
                    Derivation
                    1. Split input into 2 regimes
                    2. if z < -2.1e204

                      1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

                        \[\leadsto \color{blue}{x + y \cdot z} \]
                      6. Step-by-step derivation
                        1. Applied rewrites67.8%

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

                          \[\leadsto y \cdot \color{blue}{z} \]
                        3. Step-by-step derivation
                          1. Applied rewrites45.5%

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

                          if -2.1e204 < z

                          1. Initial program 99.9%

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

                            \[\leadsto \color{blue}{x} \]
                          4. Step-by-step derivation
                            1. Applied rewrites44.8%

                              \[\leadsto \color{blue}{x} \]
                          5. Recombined 2 regimes into one program.
                          6. Final simplification44.9%

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

                          Alternative 7: 52.8% accurate, 30.6× speedup?

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

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

                            \[\leadsto \color{blue}{x + y \cdot z} \]
                          4. Step-by-step derivation
                            1. Applied rewrites57.5%

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

                            Alternative 8: 39.3% accurate, 214.0× speedup?

                            \[\begin{array}{l} \\ x \end{array} \]
                            (FPCore (x y z) :precision binary64 x)
                            double code(double x, double y, double z) {
                            	return x;
                            }
                            
                            module fmin_fmax_functions
                                implicit none
                                private
                                public fmax
                                public fmin
                            
                                interface fmax
                                    module procedure fmax88
                                    module procedure fmax44
                                    module procedure fmax84
                                    module procedure fmax48
                                end interface
                                interface fmin
                                    module procedure fmin88
                                    module procedure fmin44
                                    module procedure fmin84
                                    module procedure fmin48
                                end interface
                            contains
                                real(8) function fmax88(x, y) result (res)
                                    real(8), intent (in) :: x
                                    real(8), intent (in) :: y
                                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                end function
                                real(4) function fmax44(x, y) result (res)
                                    real(4), intent (in) :: x
                                    real(4), intent (in) :: y
                                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                end function
                                real(8) function fmax84(x, y) result(res)
                                    real(8), intent (in) :: x
                                    real(4), intent (in) :: y
                                    res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                end function
                                real(8) function fmax48(x, y) result(res)
                                    real(4), intent (in) :: x
                                    real(8), intent (in) :: y
                                    res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                end function
                                real(8) function fmin88(x, y) result (res)
                                    real(8), intent (in) :: x
                                    real(8), intent (in) :: y
                                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                end function
                                real(4) function fmin44(x, y) result (res)
                                    real(4), intent (in) :: x
                                    real(4), intent (in) :: y
                                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                end function
                                real(8) function fmin84(x, y) result(res)
                                    real(8), intent (in) :: x
                                    real(4), intent (in) :: y
                                    res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                end function
                                real(8) function fmin48(x, y) result(res)
                                    real(4), intent (in) :: x
                                    real(8), intent (in) :: y
                                    res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                end function
                            end module
                            
                            real(8) function code(x, y, z)
                            use fmin_fmax_functions
                                real(8), intent (in) :: x
                                real(8), intent (in) :: y
                                real(8), intent (in) :: z
                                code = x
                            end function
                            
                            public static double code(double x, double y, double z) {
                            	return x;
                            }
                            
                            def code(x, y, z):
                            	return x
                            
                            function code(x, y, z)
                            	return x
                            end
                            
                            function tmp = code(x, y, z)
                            	tmp = x;
                            end
                            
                            code[x_, y_, z_] := x
                            
                            \begin{array}{l}
                            
                            \\
                            x
                            \end{array}
                            
                            Derivation
                            1. Initial program 99.9%

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

                              \[\leadsto \color{blue}{x} \]
                            4. Step-by-step derivation
                              1. Applied rewrites42.2%

                                \[\leadsto \color{blue}{x} \]
                              2. Add Preprocessing

                              Reproduce

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