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

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

Specification

?
\[\begin{array}{l} \\ x \cdot \sin y + z \cdot \cos y \end{array} \]
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
	return (x * sin(y)) + (z * cos(y));
}
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 * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
	return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z):
	return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z)
	return Float64(Float64(x * sin(y)) + Float64(z * cos(y)))
end
function tmp = code(x, y, z)
	tmp = (x * sin(y)) + (z * cos(y));
end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.8% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 85.8% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1.15 \cdot 10^{+118} \lor \neg \left(z \leq 2.2 \cdot 10^{+88}\right):\\ \;\;\;\;\cos y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sin y + z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -1.15e+118) (not (<= z 2.2e+88)))
   (* (cos y) z)
   (+ (* x (sin y)) z)))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -1.15e+118) || !(z <= 2.2e+88)) {
		tmp = cos(y) * z;
	} else {
		tmp = (x * sin(y)) + z;
	}
	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 <= (-1.15d+118)) .or. (.not. (z <= 2.2d+88))) then
        tmp = cos(y) * z
    else
        tmp = (x * sin(y)) + z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z <= -1.15e+118) || !(z <= 2.2e+88)) {
		tmp = Math.cos(y) * z;
	} else {
		tmp = (x * Math.sin(y)) + z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -1.15e+118) or not (z <= 2.2e+88):
		tmp = math.cos(y) * z
	else:
		tmp = (x * math.sin(y)) + z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -1.15e+118) || !(z <= 2.2e+88))
		tmp = Float64(cos(y) * z);
	else
		tmp = Float64(Float64(x * sin(y)) + z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z <= -1.15e+118) || ~((z <= 2.2e+88)))
		tmp = cos(y) * z;
	else
		tmp = (x * sin(y)) + z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.15e+118], N[Not[LessEqual[z, 2.2e+88]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.15 \cdot 10^{+118} \lor \neg \left(z \leq 2.2 \cdot 10^{+88}\right):\\
\;\;\;\;\cos y \cdot z\\

\mathbf{else}:\\
\;\;\;\;x \cdot \sin y + z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -1.15000000000000008e118 or 2.20000000000000009e88 < z

    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. Applied rewrites90.3%

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

      if -1.15000000000000008e118 < z < 2.20000000000000009e88

      1. Initial program 99.8%

        \[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}{z} \]
      4. Step-by-step derivation
        1. Applied rewrites87.1%

          \[\leadsto x \cdot \sin y + \color{blue}{z} \]
      5. Recombined 2 regimes into one program.
      6. Final simplification88.2%

        \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.15 \cdot 10^{+118} \lor \neg \left(z \leq 2.2 \cdot 10^{+88}\right):\\ \;\;\;\;\cos y \cdot z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sin y + z\\ \end{array} \]
      7. Add Preprocessing

      Alternative 3: 85.8% accurate, 1.8× speedup?

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

        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. Applied rewrites90.3%

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

          if -1.15000000000000008e118 < z < 2.20000000000000009e88

          1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

          Alternative 4: 74.9% accurate, 1.8× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -0.02 \lor \neg \left(y \leq 0.007\right):\\ \;\;\;\;\sin y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(z \cdot y, -0.5, x\right), y, z\right)\\ \end{array} \end{array} \]
          (FPCore (x y z)
           :precision binary64
           (if (or (<= y -0.02) (not (<= y 0.007)))
             (* (sin y) x)
             (fma (fma (* z y) -0.5 x) y z)))
          double code(double x, double y, double z) {
          	double tmp;
          	if ((y <= -0.02) || !(y <= 0.007)) {
          		tmp = sin(y) * x;
          	} else {
          		tmp = fma(fma((z * y), -0.5, x), y, z);
          	}
          	return tmp;
          }
          
          function code(x, y, z)
          	tmp = 0.0
          	if ((y <= -0.02) || !(y <= 0.007))
          		tmp = Float64(sin(y) * x);
          	else
          		tmp = fma(fma(Float64(z * y), -0.5, x), y, z);
          	end
          	return tmp
          end
          
          code[x_, y_, z_] := If[Or[LessEqual[y, -0.02], N[Not[LessEqual[y, 0.007]], $MachinePrecision]], N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision], N[(N[(N[(z * y), $MachinePrecision] * -0.5 + x), $MachinePrecision] * y + z), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;y \leq -0.02 \lor \neg \left(y \leq 0.007\right):\\
          \;\;\;\;\sin y \cdot x\\
          
          \mathbf{else}:\\
          \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(z \cdot y, -0.5, x\right), y, z\right)\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if y < -0.0200000000000000004 or 0.00700000000000000015 < 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. Applied rewrites54.8%

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

              if -0.0200000000000000004 < y < 0.00700000000000000015

              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 + \frac{-1}{2} \cdot \left(y \cdot z\right)\right)} \]
              4. Step-by-step derivation
                1. Applied rewrites100.0%

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

                \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -0.02 \lor \neg \left(y \leq 0.007\right):\\ \;\;\;\;\sin y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(z \cdot y, -0.5, x\right), y, z\right)\\ \end{array} \]
              7. Add Preprocessing

              Alternative 5: 75.2% accurate, 1.8× speedup?

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

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

                  if -17.5 < y < 4.20000000000000018

                  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. Applied rewrites98.1%

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

                    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -17.5 \lor \neg \left(y \leq 4.2\right):\\ \;\;\;\;\cos y \cdot z\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, y \cdot x, -0.5 \cdot z\right), y, x\right), y, z\right)\\ \end{array} \]
                  7. Add Preprocessing

                  Alternative 6: 40.5% accurate, 11.9× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -4.5 \cdot 10^{-11} \lor \neg \left(z \leq 3.3 \cdot 10^{-166}\right):\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \end{array} \]
                  (FPCore (x y z)
                   :precision binary64
                   (if (or (<= z -4.5e-11) (not (<= z 3.3e-166))) z (* y x)))
                  double code(double x, double y, double z) {
                  	double tmp;
                  	if ((z <= -4.5e-11) || !(z <= 3.3e-166)) {
                  		tmp = z;
                  	} else {
                  		tmp = y * 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 <= (-4.5d-11)) .or. (.not. (z <= 3.3d-166))) then
                          tmp = z
                      else
                          tmp = y * x
                      end if
                      code = tmp
                  end function
                  
                  public static double code(double x, double y, double z) {
                  	double tmp;
                  	if ((z <= -4.5e-11) || !(z <= 3.3e-166)) {
                  		tmp = z;
                  	} else {
                  		tmp = y * x;
                  	}
                  	return tmp;
                  }
                  
                  def code(x, y, z):
                  	tmp = 0
                  	if (z <= -4.5e-11) or not (z <= 3.3e-166):
                  		tmp = z
                  	else:
                  		tmp = y * x
                  	return tmp
                  
                  function code(x, y, z)
                  	tmp = 0.0
                  	if ((z <= -4.5e-11) || !(z <= 3.3e-166))
                  		tmp = z;
                  	else
                  		tmp = Float64(y * x);
                  	end
                  	return tmp
                  end
                  
                  function tmp_2 = code(x, y, z)
                  	tmp = 0.0;
                  	if ((z <= -4.5e-11) || ~((z <= 3.3e-166)))
                  		tmp = z;
                  	else
                  		tmp = y * x;
                  	end
                  	tmp_2 = tmp;
                  end
                  
                  code[x_, y_, z_] := If[Or[LessEqual[z, -4.5e-11], N[Not[LessEqual[z, 3.3e-166]], $MachinePrecision]], z, N[(y * x), $MachinePrecision]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  \mathbf{if}\;z \leq -4.5 \cdot 10^{-11} \lor \neg \left(z \leq 3.3 \cdot 10^{-166}\right):\\
                  \;\;\;\;z\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;y \cdot x\\
                  
                  
                  \end{array}
                  \end{array}
                  
                  Derivation
                  1. Split input into 2 regimes
                  2. if z < -4.5e-11 or 3.30000000000000018e-166 < z

                    1. Initial program 99.8%

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

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

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

                      if -4.5e-11 < z < 3.30000000000000018e-166

                      1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                            \[\leadsto y \cdot \color{blue}{x} \]
                        4. Recombined 2 regimes into one program.
                        5. Final simplification41.4%

                          \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -4.5 \cdot 10^{-11} \lor \neg \left(z \leq 3.3 \cdot 10^{-166}\right):\\ \;\;\;\;z\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \]
                        6. Add Preprocessing

                        Alternative 7: 52.6% accurate, 30.6× speedup?

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

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

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

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

                          Alternative 8: 39.0% 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;
                          }
                          
                          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 = 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.8%

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

                            \[\leadsto \color{blue}{z} \]
                          4. Step-by-step derivation
                            1. Applied rewrites36.4%

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

                            Reproduce

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