
(FPCore (xi yi zi ux uy maxCos)
:precision binary32
(let* ((t_0 (* (* (- 1.0 ux) maxCos) ux))
(t_1 (sqrt (- 1.0 (* t_0 t_0))))
(t_2 (* (* uy 2.0) (PI))))
(+ (+ (* (* (cos t_2) t_1) xi) (* (* (sin t_2) t_1) yi)) (* t_0 zi))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\\
t_1 := \sqrt{1 - t\_0 \cdot t\_0}\\
t_2 := \left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\\
\left(\left(\cos t\_2 \cdot t\_1\right) \cdot xi + \left(\sin t\_2 \cdot t\_1\right) \cdot yi\right) + t\_0 \cdot zi
\end{array}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 17 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (xi yi zi ux uy maxCos)
:precision binary32
(let* ((t_0 (* (* (- 1.0 ux) maxCos) ux))
(t_1 (sqrt (- 1.0 (* t_0 t_0))))
(t_2 (* (* uy 2.0) (PI))))
(+ (+ (* (* (cos t_2) t_1) xi) (* (* (sin t_2) t_1) yi)) (* t_0 zi))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\\
t_1 := \sqrt{1 - t\_0 \cdot t\_0}\\
t_2 := \left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\\
\left(\left(\cos t\_2 \cdot t\_1\right) \cdot xi + \left(\sin t\_2 \cdot t\_1\right) \cdot yi\right) + t\_0 \cdot zi
\end{array}
\end{array}
(FPCore (xi yi zi ux uy maxCos)
:precision binary32
(let* ((t_0 (asin (* (* maxCos (- 1.0 ux)) ux)))
(t_1 (* (* (- 1.0 ux) maxCos) ux)))
(+
(+
(*
(/
(+
(sin (- (fma (- uy) (* (PI) 2.0) (/ (PI) 2.0)) t_0))
(sin (+ (* (fma (/ (PI) uy) 0.5 (* -2.0 (PI))) uy) t_0)))
2.0)
xi)
(* (* (sin (* (* uy 2.0) (PI))) (sqrt (- 1.0 (* t_1 t_1)))) yi))
(* t_1 zi))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin^{-1} \left(\left(maxCos \cdot \left(1 - ux\right)\right) \cdot ux\right)\\
t_1 := \left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\\
\left(\frac{\sin \left(\mathsf{fma}\left(-uy, \mathsf{PI}\left(\right) \cdot 2, \frac{\mathsf{PI}\left(\right)}{2}\right) - t\_0\right) + \sin \left(\mathsf{fma}\left(\frac{\mathsf{PI}\left(\right)}{uy}, 0.5, -2 \cdot \mathsf{PI}\left(\right)\right) \cdot uy + t\_0\right)}{2} \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{1 - t\_1 \cdot t\_1}\right) \cdot yi\right) + t\_1 \cdot zi
\end{array}
\end{array}
Initial program 98.9%
lift-*.f32N/A
lift-cos.f32N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lift-sqrt.f32N/A
lift--.f32N/A
lift-*.f32N/A
cos-asin-revN/A
sin-cos-multN/A
lower-/.f32N/A
Applied rewrites99.0%
Taylor expanded in uy around inf
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower-/.f32N/A
lower-PI.f32N/A
lower-*.f32N/A
lower-PI.f3299.0
Applied rewrites99.0%
(FPCore (xi yi zi ux uy maxCos)
:precision binary32
(+
(+
(*
(/
(+
(sin (fma (* -2.0 uy) (PI) (acos (* (* (- 1.0 ux) ux) maxCos))))
(sin
(+
(* (fma (/ (PI) uy) 0.5 (* -2.0 (PI))) uy)
(asin (* (* maxCos (- 1.0 ux)) ux)))))
2.0)
xi)
(*
(*
(sin (* (* uy 2.0) (PI)))
(sqrt (- 1.0 (* (* ux ux) (* maxCos maxCos)))))
yi))
(* (* (* (- 1.0 ux) maxCos) ux) zi)))\begin{array}{l}
\\
\left(\frac{\sin \left(\mathsf{fma}\left(-2 \cdot uy, \mathsf{PI}\left(\right), \cos^{-1} \left(\left(\left(1 - ux\right) \cdot ux\right) \cdot maxCos\right)\right)\right) + \sin \left(\mathsf{fma}\left(\frac{\mathsf{PI}\left(\right)}{uy}, 0.5, -2 \cdot \mathsf{PI}\left(\right)\right) \cdot uy + \sin^{-1} \left(\left(maxCos \cdot \left(1 - ux\right)\right) \cdot ux\right)\right)}{2} \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{1 - \left(ux \cdot ux\right) \cdot \left(maxCos \cdot maxCos\right)}\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi
\end{array}
Initial program 98.9%
lift-*.f32N/A
lift-cos.f32N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lift-sqrt.f32N/A
lift--.f32N/A
lift-*.f32N/A
cos-asin-revN/A
sin-cos-multN/A
lower-/.f32N/A
Applied rewrites99.0%
Taylor expanded in uy around inf
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower-/.f32N/A
lower-PI.f32N/A
lower-*.f32N/A
lower-PI.f3299.0
Applied rewrites99.0%
lift--.f32N/A
lift-fma.f32N/A
associate--l+N/A
lift-*.f32N/A
associate-*r*N/A
lift-neg.f32N/A
distribute-lft-neg-outN/A
*-commutativeN/A
lift-*.f32N/A
distribute-lft-neg-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
metadata-evalN/A
lift-*.f32N/A
*-commutativeN/A
associate-*r*N/A
Applied rewrites99.0%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f3299.0
Applied rewrites99.0%
(FPCore (xi yi zi ux uy maxCos)
:precision binary32
(let* ((t_0 (cbrt (PI)))
(t_1 (* (* (- 1.0 ux) maxCos) ux))
(t_2 (sqrt (- 1.0 (* t_1 t_1)))))
(+
(+
(* (* (cos (* (* (* 2.0 uy) (pow t_0 2.0)) t_0)) t_2) xi)
(* (* (sin (* (* uy 2.0) (PI))) t_2) yi))
(* t_1 zi))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\mathsf{PI}\left(\right)}\\
t_1 := \left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\\
t_2 := \sqrt{1 - t\_1 \cdot t\_1}\\
\left(\left(\cos \left(\left(\left(2 \cdot uy\right) \cdot {t\_0}^{2}\right) \cdot t\_0\right) \cdot t\_2\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot t\_2\right) \cdot yi\right) + t\_1 \cdot zi
\end{array}
\end{array}
Initial program 98.9%
lift-*.f32N/A
lift-PI.f32N/A
add-cube-cbrtN/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
pow2N/A
lower-pow.f32N/A
lift-PI.f32N/A
lower-cbrt.f32N/A
lift-PI.f32N/A
lower-cbrt.f3298.9
Applied rewrites98.9%
(FPCore (xi yi zi ux uy maxCos)
:precision binary32
(let* ((t_0 (* (* (- 1.0 ux) maxCos) ux)))
(+
(+
(* (* (cos (* (* uy 2.0) (PI))) (sqrt (- 1.0 (* t_0 t_0)))) xi)
(* (sin (* (* (PI) uy) 2.0)) yi))
(* t_0 zi))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\\
\left(\left(\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{1 - t\_0 \cdot t\_0}\right) \cdot xi + \sin \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right) \cdot yi\right) + t\_0 \cdot zi
\end{array}
\end{array}
Initial program 98.9%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
lower-sin.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3298.9
Applied rewrites98.9%
(FPCore (xi yi zi ux uy maxCos)
:precision binary32
(let* ((t_0 (* (PI) uy)))
(+
(fma (cos (* -2.0 t_0)) xi (* (sin (* t_0 2.0)) yi))
(* (* (* (- 1.0 ux) maxCos) ux) zi))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot uy\\
\mathsf{fma}\left(\cos \left(-2 \cdot t\_0\right), xi, \sin \left(t\_0 \cdot 2\right) \cdot yi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi
\end{array}
\end{array}
Initial program 98.9%
Taylor expanded in ux around 0
*-commutativeN/A
lower-fma.f32N/A
cos-neg-revN/A
lower-cos.f32N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-sin.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3298.8
Applied rewrites98.8%
(FPCore (xi yi zi ux uy maxCos)
:precision binary32
(let* ((t_0 (* (PI) uy)))
(fma
(cos (* -2.0 t_0))
xi
(fma (sin (* t_0 2.0)) yi (* (* (* (- 1.0 ux) zi) ux) maxCos)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot uy\\
\mathsf{fma}\left(\cos \left(-2 \cdot t\_0\right), xi, \mathsf{fma}\left(\sin \left(t\_0 \cdot 2\right), yi, \left(\left(\left(1 - ux\right) \cdot zi\right) \cdot ux\right) \cdot maxCos\right)\right)
\end{array}
\end{array}
Initial program 98.9%
Taylor expanded in maxCos around 0
+-commutativeN/A
associate-+l+N/A
*-commutativeN/A
lower-fma.f32N/A
cos-neg-revN/A
lower-cos.f32N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f32N/A
*-commutativeN/A
Applied rewrites98.8%
(FPCore (xi yi zi ux uy maxCos)
:precision binary32
(let* ((t_0 (* (PI) uy)))
(fma
(cos (* -2.0 t_0))
xi
(fma (sin (* t_0 2.0)) yi (* (* zi ux) maxCos)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot uy\\
\mathsf{fma}\left(\cos \left(-2 \cdot t\_0\right), xi, \mathsf{fma}\left(\sin \left(t\_0 \cdot 2\right), yi, \left(zi \cdot ux\right) \cdot maxCos\right)\right)
\end{array}
\end{array}
Initial program 98.9%
Taylor expanded in ux around 0
+-commutativeN/A
associate-+l+N/A
*-commutativeN/A
lower-fma.f32N/A
cos-neg-revN/A
lower-cos.f32N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f32N/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites96.0%
(FPCore (xi yi zi ux uy maxCos)
:precision binary32
(let* ((t_0 (* (PI) uy)) (t_1 (* t_0 2.0)))
(if (<= uy 0.01600000075995922)
(*
(fma
1.0
(/ (fma (cos (* -2.0 t_0)) xi (* (* (* (PI) yi) uy) 2.0)) zi)
(* (* (- 1.0 ux) ux) maxCos))
zi)
(fma (cos t_1) xi (* (sin t_1) yi)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot uy\\
t_1 := t\_0 \cdot 2\\
\mathbf{if}\;uy \leq 0.01600000075995922:\\
\;\;\;\;\mathsf{fma}\left(1, \frac{\mathsf{fma}\left(\cos \left(-2 \cdot t\_0\right), xi, \left(\left(\mathsf{PI}\left(\right) \cdot yi\right) \cdot uy\right) \cdot 2\right)}{zi}, \left(\left(1 - ux\right) \cdot ux\right) \cdot maxCos\right) \cdot zi\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\cos t\_1, xi, \sin t\_1 \cdot yi\right)\\
\end{array}
\end{array}
if uy < 0.0160000008Initial program 99.2%
Taylor expanded in zi around inf
Applied rewrites98.8%
Taylor expanded in uy around 0
Applied rewrites97.0%
Taylor expanded in ux around 0
Applied rewrites97.0%
if 0.0160000008 < uy Initial program 97.5%
Taylor expanded in uy around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites22.6%
Taylor expanded in ux around 0
*-commutativeN/A
lower-fma.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-sin.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3291.9
Applied rewrites91.9%
(FPCore (xi yi zi ux uy maxCos)
:precision binary32
(let* ((t_0 (* 2.0 (* uy (PI)))))
(if (<= uy 0.01600000075995922)
(*
(fma
1.0
(/ (fma (cos (* -2.0 (* (PI) uy))) xi (* (* (* (PI) yi) uy) 2.0)) zi)
(* (* (- 1.0 ux) ux) maxCos))
zi)
(fma yi (sin t_0) (* xi (cos t_0))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := 2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\\
\mathbf{if}\;uy \leq 0.01600000075995922:\\
\;\;\;\;\mathsf{fma}\left(1, \frac{\mathsf{fma}\left(\cos \left(-2 \cdot \left(\mathsf{PI}\left(\right) \cdot uy\right)\right), xi, \left(\left(\mathsf{PI}\left(\right) \cdot yi\right) \cdot uy\right) \cdot 2\right)}{zi}, \left(\left(1 - ux\right) \cdot ux\right) \cdot maxCos\right) \cdot zi\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(yi, \sin t\_0, xi \cdot \cos t\_0\right)\\
\end{array}
\end{array}
if uy < 0.0160000008Initial program 99.2%
Taylor expanded in zi around inf
Applied rewrites98.8%
Taylor expanded in uy around 0
Applied rewrites97.0%
Taylor expanded in ux around 0
Applied rewrites97.0%
if 0.0160000008 < uy Initial program 97.5%
Taylor expanded in uy around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites22.6%
Taylor expanded in ux around 0
Applied rewrites20.7%
Taylor expanded in ux around 0
+-commutativeN/A
lower-fma.f32N/A
lower-sin.f32N/A
lower-*.f32N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-*.f32N/A
lower-cos.f32N/A
lower-*.f32N/A
lower-*.f32N/A
lower-PI.f3291.8
Applied rewrites91.8%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (* (fma 1.0 (/ (fma (cos (* -2.0 (* (PI) uy))) xi (* (* (* (PI) yi) uy) 2.0)) zi) (* (* (- 1.0 ux) ux) maxCos)) zi))
\begin{array}{l}
\\
\mathsf{fma}\left(1, \frac{\mathsf{fma}\left(\cos \left(-2 \cdot \left(\mathsf{PI}\left(\right) \cdot uy\right)\right), xi, \left(\left(\mathsf{PI}\left(\right) \cdot yi\right) \cdot uy\right) \cdot 2\right)}{zi}, \left(\left(1 - ux\right) \cdot ux\right) \cdot maxCos\right) \cdot zi
\end{array}
Initial program 98.9%
Taylor expanded in zi around inf
Applied rewrites98.5%
Taylor expanded in uy around 0
Applied rewrites91.1%
Taylor expanded in ux around 0
Applied rewrites91.1%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (* (fma (* maxCos ux) (- 1.0 ux) (/ (fma (* 2.0 (- (* yi (PI)) (* (* (* (PI) (PI)) xi) uy))) uy xi) zi)) zi))
\begin{array}{l}
\\
\mathsf{fma}\left(maxCos \cdot ux, 1 - ux, \frac{\mathsf{fma}\left(2 \cdot \left(yi \cdot \mathsf{PI}\left(\right) - \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot xi\right) \cdot uy\right), uy, xi\right)}{zi}\right) \cdot zi
\end{array}
Initial program 98.9%
Taylor expanded in zi around inf
Applied rewrites98.5%
Taylor expanded in uy around 0
Applied rewrites85.9%
Taylor expanded in ux around 0
Applied rewrites85.9%
Applied rewrites86.4%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (+ (fma 2.0 (* uy (* yi (PI))) xi) (* (* (* (- 1.0 ux) maxCos) ux) zi)))
\begin{array}{l}
\\
\mathsf{fma}\left(2, uy \cdot \left(yi \cdot \mathsf{PI}\left(\right)\right), xi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi
\end{array}
Initial program 98.9%
Taylor expanded in uy around 0
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f32N/A
Applied rewrites82.8%
Taylor expanded in ux around 0
Applied rewrites82.8%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (fma 1.0 xi (* (* (* (- 1.0 ux) zi) ux) maxCos)))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
return fmaf(1.0f, xi, ((((1.0f - ux) * zi) * ux) * maxCos));
}
function code(xi, yi, zi, ux, uy, maxCos) return fma(Float32(1.0), xi, Float32(Float32(Float32(Float32(Float32(1.0) - ux) * zi) * ux) * maxCos)) end
\begin{array}{l}
\\
\mathsf{fma}\left(1, xi, \left(\left(\left(1 - ux\right) \cdot zi\right) \cdot ux\right) \cdot maxCos\right)
\end{array}
Initial program 98.9%
Taylor expanded in uy around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites51.8%
Taylor expanded in ux around 0
Applied rewrites51.8%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (fma (* ux maxCos) (* (- 1.0 ux) zi) xi))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
return fmaf((ux * maxCos), ((1.0f - ux) * zi), xi);
}
function code(xi, yi, zi, ux, uy, maxCos) return fma(Float32(ux * maxCos), Float32(Float32(Float32(1.0) - ux) * zi), xi) end
\begin{array}{l}
\\
\mathsf{fma}\left(ux \cdot maxCos, \left(1 - ux\right) \cdot zi, xi\right)
\end{array}
Initial program 98.9%
Taylor expanded in uy around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites51.8%
Taylor expanded in maxCos around 0
Applied rewrites51.8%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (fma (* ux maxCos) zi xi))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
return fmaf((ux * maxCos), zi, xi);
}
function code(xi, yi, zi, ux, uy, maxCos) return fma(Float32(ux * maxCos), zi, xi) end
\begin{array}{l}
\\
\mathsf{fma}\left(ux \cdot maxCos, zi, xi\right)
\end{array}
Initial program 98.9%
Taylor expanded in uy around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites51.8%
Taylor expanded in ux around 0
Applied rewrites49.6%
Applied rewrites49.6%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (* (* maxCos ux) zi))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
return (maxCos * ux) * zi;
}
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(4) function code(xi, yi, zi, ux, uy, maxcos)
use fmin_fmax_functions
real(4), intent (in) :: xi
real(4), intent (in) :: yi
real(4), intent (in) :: zi
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = (maxcos * ux) * zi
end function
function code(xi, yi, zi, ux, uy, maxCos) return Float32(Float32(maxCos * ux) * zi) end
function tmp = code(xi, yi, zi, ux, uy, maxCos) tmp = (maxCos * ux) * zi; end
\begin{array}{l}
\\
\left(maxCos \cdot ux\right) \cdot zi
\end{array}
Initial program 98.9%
Taylor expanded in uy around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites51.8%
Taylor expanded in ux around 0
Applied rewrites49.6%
Taylor expanded in xi around 0
Applied rewrites12.0%
Applied rewrites12.1%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (* maxCos (* ux zi)))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
return maxCos * (ux * zi);
}
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(4) function code(xi, yi, zi, ux, uy, maxcos)
use fmin_fmax_functions
real(4), intent (in) :: xi
real(4), intent (in) :: yi
real(4), intent (in) :: zi
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = maxcos * (ux * zi)
end function
function code(xi, yi, zi, ux, uy, maxCos) return Float32(maxCos * Float32(ux * zi)) end
function tmp = code(xi, yi, zi, ux, uy, maxCos) tmp = maxCos * (ux * zi); end
\begin{array}{l}
\\
maxCos \cdot \left(ux \cdot zi\right)
\end{array}
Initial program 98.9%
Taylor expanded in uy around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
Applied rewrites51.8%
Taylor expanded in ux around 0
Applied rewrites49.6%
Taylor expanded in xi around 0
Applied rewrites12.0%
herbie shell --seed 2025006
(FPCore (xi yi zi ux uy maxCos)
:name "UniformSampleCone 2"
:precision binary32
:pre (and (and (and (and (and (and (<= -10000.0 xi) (<= xi 10000.0)) (and (<= -10000.0 yi) (<= yi 10000.0))) (and (<= -10000.0 zi) (<= zi 10000.0))) (and (<= 2.328306437e-10 ux) (<= ux 1.0))) (and (<= 2.328306437e-10 uy) (<= uy 1.0))) (and (<= 0.0 maxCos) (<= maxCos 1.0)))
(+ (+ (* (* (cos (* (* uy 2.0) (PI))) (sqrt (- 1.0 (* (* (* (- 1.0 ux) maxCos) ux) (* (* (- 1.0 ux) maxCos) ux))))) xi) (* (* (sin (* (* uy 2.0) (PI))) (sqrt (- 1.0 (* (* (* (- 1.0 ux) maxCos) ux) (* (* (- 1.0 ux) maxCos) ux))))) yi)) (* (* (* (- 1.0 ux) maxCos) ux) zi)))