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

Percentage Accurate: 99.8% → 99.8%
Time: 3.3s
Alternatives: 7
Speedup: 1.0×

Specification

?
\[x \cdot \cos y + z \cdot \sin y \]
(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]
x \cdot \cos y + z \cdot \sin y

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 7 alternatives:

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

Initial Program: 99.8% accurate, 1.0× speedup?

\[x \cdot \cos y + z \cdot \sin y \]
(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]
x \cdot \cos y + z \cdot \sin y

Alternative 1: 99.8% accurate, 1.0× speedup?

\[\mathsf{fma}\left(\sin y, z, \cos y \cdot x\right) \]
(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]
\mathsf{fma}\left(\sin y, z, \cos y \cdot x\right)
Derivation
  1. Initial program 99.8%

    \[x \cdot \cos y + z \cdot \sin y \]
  2. 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.8%

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

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

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

Alternative 2: 99.8% accurate, 1.0× speedup?

\[\mathsf{fma}\left(\cos y, x, \sin y \cdot z\right) \]
(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]
\mathsf{fma}\left(\cos y, x, \sin y \cdot z\right)
Derivation
  1. Initial program 99.8%

    \[x \cdot \cos y + z \cdot \sin y \]
  2. 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.8%

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

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

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

Alternative 3: 81.9% accurate, 1.5× speedup?

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

\mathbf{elif}\;z \leq 4.6 \cdot 10^{-181}:\\
\;\;\;\;\mathsf{fma}\left(\cos y, x, y \cdot z\right)\\

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


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -0.025999999999999999 or 4.5999999999999998e-181 < z

    1. Initial program 99.8%

      \[x \cdot \cos y + z \cdot \sin y \]
    2. 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.8%

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{1}, x, \sin y \cdot z\right) \]

      if -0.025999999999999999 < z < 4.5999999999999998e-181

      1. Initial program 99.8%

        \[x \cdot \cos y + z \cdot \sin y \]
      2. 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.8%

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

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

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

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

          \[\leadsto \mathsf{fma}\left(\cos y, x, \color{blue}{y} \cdot z\right) \]
      6. Recombined 2 regimes into one program.
      7. Add Preprocessing

      Alternative 4: 77.0% accurate, 1.8× speedup?

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

        \[x \cdot \cos y + z \cdot \sin y \]
      2. 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.8%

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

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

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

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

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

        Alternative 5: 74.3% accurate, 1.7× speedup?

        \[\begin{array}{l} t_0 := z \cdot \sin y\\ \mathbf{if}\;y \leq -4.2 \cdot 10^{+15}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y \leq 15:\\ \;\;\;\;x + y \cdot \left(z + y \cdot \left(-0.16666666666666666 \cdot \left(y \cdot z\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \]
        (FPCore (x y z)
         :precision binary64
         (let* ((t_0 (* z (sin y))))
           (if (<= y -4.2e+15)
             t_0
             (if (<= y 15.0)
               (+ x (* y (+ z (* y (* -0.16666666666666666 (* y z))))))
               t_0))))
        double code(double x, double y, double z) {
        	double t_0 = z * sin(y);
        	double tmp;
        	if (y <= -4.2e+15) {
        		tmp = t_0;
        	} else if (y <= 15.0) {
        		tmp = x + (y * (z + (y * (-0.16666666666666666 * (y * z)))));
        	} else {
        		tmp = t_0;
        	}
        	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) :: t_0
            real(8) :: tmp
            t_0 = z * sin(y)
            if (y <= (-4.2d+15)) then
                tmp = t_0
            else if (y <= 15.0d0) then
                tmp = x + (y * (z + (y * ((-0.16666666666666666d0) * (y * z)))))
            else
                tmp = t_0
            end if
            code = tmp
        end function
        
        public static double code(double x, double y, double z) {
        	double t_0 = z * Math.sin(y);
        	double tmp;
        	if (y <= -4.2e+15) {
        		tmp = t_0;
        	} else if (y <= 15.0) {
        		tmp = x + (y * (z + (y * (-0.16666666666666666 * (y * z)))));
        	} else {
        		tmp = t_0;
        	}
        	return tmp;
        }
        
        def code(x, y, z):
        	t_0 = z * math.sin(y)
        	tmp = 0
        	if y <= -4.2e+15:
        		tmp = t_0
        	elif y <= 15.0:
        		tmp = x + (y * (z + (y * (-0.16666666666666666 * (y * z)))))
        	else:
        		tmp = t_0
        	return tmp
        
        function code(x, y, z)
        	t_0 = Float64(z * sin(y))
        	tmp = 0.0
        	if (y <= -4.2e+15)
        		tmp = t_0;
        	elseif (y <= 15.0)
        		tmp = Float64(x + Float64(y * Float64(z + Float64(y * Float64(-0.16666666666666666 * Float64(y * z))))));
        	else
        		tmp = t_0;
        	end
        	return tmp
        end
        
        function tmp_2 = code(x, y, z)
        	t_0 = z * sin(y);
        	tmp = 0.0;
        	if (y <= -4.2e+15)
        		tmp = t_0;
        	elseif (y <= 15.0)
        		tmp = x + (y * (z + (y * (-0.16666666666666666 * (y * z)))));
        	else
        		tmp = t_0;
        	end
        	tmp_2 = tmp;
        end
        
        code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4.2e+15], t$95$0, If[LessEqual[y, 15.0], N[(x + N[(y * N[(z + N[(y * N[(-0.16666666666666666 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
        
        \begin{array}{l}
        t_0 := z \cdot \sin y\\
        \mathbf{if}\;y \leq -4.2 \cdot 10^{+15}:\\
        \;\;\;\;t\_0\\
        
        \mathbf{elif}\;y \leq 15:\\
        \;\;\;\;x + y \cdot \left(z + y \cdot \left(-0.16666666666666666 \cdot \left(y \cdot z\right)\right)\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;t\_0\\
        
        
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if y < -4.2e15 or 15 < y

          1. Initial program 99.8%

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

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

              \[\leadsto z \cdot \color{blue}{\sin y} \]
            2. lower-sin.f6440.5%

              \[\leadsto z \cdot \sin y \]
          4. Applied rewrites40.5%

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

          if -4.2e15 < y < 15

          1. Initial program 99.8%

            \[x \cdot \cos y + z \cdot \sin y \]
          2. 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.8%

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

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

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

            \[\leadsto \color{blue}{x + y \cdot \left(z + y \cdot \left(\frac{-1}{2} \cdot x + \frac{-1}{6} \cdot \left(y \cdot z\right)\right)\right)} \]
          5. Step-by-step derivation
            1. lower-+.f64N/A

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

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

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

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

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

              \[\leadsto x + y \cdot \left(z + y \cdot \mathsf{fma}\left(\frac{-1}{2}, x, \frac{-1}{6} \cdot \left(y \cdot z\right)\right)\right) \]
            7. lower-*.f6451.4%

              \[\leadsto x + y \cdot \left(z + y \cdot \mathsf{fma}\left(-0.5, x, -0.16666666666666666 \cdot \left(y \cdot z\right)\right)\right) \]
          6. Applied rewrites51.4%

            \[\leadsto \color{blue}{x + y \cdot \left(z + y \cdot \mathsf{fma}\left(-0.5, x, -0.16666666666666666 \cdot \left(y \cdot z\right)\right)\right)} \]
          7. Taylor expanded in x around 0

            \[\leadsto x + y \cdot \left(z + y \cdot \left(\frac{-1}{6} \cdot \color{blue}{\left(y \cdot z\right)}\right)\right) \]
          8. Step-by-step derivation
            1. lower-*.f64N/A

              \[\leadsto x + y \cdot \left(z + y \cdot \left(\frac{-1}{6} \cdot \left(y \cdot \color{blue}{z}\right)\right)\right) \]
            2. lower-*.f6451.6%

              \[\leadsto x + y \cdot \left(z + y \cdot \left(-0.16666666666666666 \cdot \left(y \cdot z\right)\right)\right) \]
          9. Applied rewrites51.6%

            \[\leadsto x + y \cdot \left(z + y \cdot \left(-0.16666666666666666 \cdot \color{blue}{\left(y \cdot z\right)}\right)\right) \]
        3. Recombined 2 regimes into one program.
        4. Add Preprocessing

        Alternative 6: 52.5% accurate, 12.8× speedup?

        \[\mathsf{fma}\left(z, y, x\right) \]
        (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]
        
        \mathsf{fma}\left(z, y, x\right)
        
        Derivation
        1. Initial program 99.8%

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

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

            \[\leadsto x + \color{blue}{y \cdot z} \]
          2. lower-*.f6452.5%

            \[\leadsto x + y \cdot \color{blue}{z} \]
        4. Applied rewrites52.5%

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

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

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

            \[\leadsto y \cdot z + x \]
          4. *-commutativeN/A

            \[\leadsto z \cdot y + x \]
          5. lower-fma.f6452.5%

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

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

        Alternative 7: 16.9% accurate, 19.2× speedup?

        \[z \cdot y \]
        (FPCore (x y z) :precision binary64 (* z y))
        double code(double x, double y, double z) {
        	return z * 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 = z * y
        end function
        
        public static double code(double x, double y, double z) {
        	return z * y;
        }
        
        def code(x, y, z):
        	return z * y
        
        function code(x, y, z)
        	return Float64(z * y)
        end
        
        function tmp = code(x, y, z)
        	tmp = z * y;
        end
        
        code[x_, y_, z_] := N[(z * y), $MachinePrecision]
        
        z \cdot y
        
        Derivation
        1. Initial program 99.8%

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

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

            \[\leadsto z \cdot \color{blue}{\sin y} \]
          2. lower-sin.f6440.5%

            \[\leadsto z \cdot \sin y \]
        4. Applied rewrites40.5%

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

          \[\leadsto z \cdot y \]
        6. Step-by-step derivation
          1. Applied rewrites16.9%

            \[\leadsto z \cdot y \]
          2. Add Preprocessing

          Reproduce

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