
(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 23 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 (fma (- 1.0 ux) (* (* zi ux) maxCos) (fma (sin (* (fma -2.0 uy 0.5) (PI))) xi (* (sin (* (* (PI) 2.0) uy)) yi))))
\begin{array}{l}
\\
\mathsf{fma}\left(1 - ux, \left(zi \cdot ux\right) \cdot maxCos, \mathsf{fma}\left(\sin \left(\mathsf{fma}\left(-2, uy, 0.5\right) \cdot \mathsf{PI}\left(\right)\right), xi, \sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot yi\right)\right)
\end{array}
Initial program 98.9%
Taylor expanded in ux around 0
Applied rewrites98.8%
Applied rewrites99.0%
Taylor expanded in uy around 0
Applied rewrites99.0%
lift-+.f32N/A
+-commutativeN/A
Applied rewrites99.0%
(FPCore (xi yi zi ux uy maxCos)
:precision binary32
(if (<= uy 0.00800000037997961)
(+
(fma
(fma
(fma
(* (* (pow (PI) 3.0) yi) uy)
-1.3333333333333333
(* (* (* (PI) (PI)) xi) -2.0))
uy
(* (* (PI) yi) 2.0))
uy
xi)
(* (* (* (- 1.0 ux) maxCos) ux) zi))
(+
(fma (sin (* (PI) (fma -2.0 uy 0.5))) xi (* (sin (* (PI) (* 2.0 uy))) yi))
(* (* maxCos ux) zi))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \leq 0.00800000037997961:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\left({\mathsf{PI}\left(\right)}^{3} \cdot yi\right) \cdot uy, -1.3333333333333333, \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot xi\right) \cdot -2\right), uy, \left(\mathsf{PI}\left(\right) \cdot yi\right) \cdot 2\right), uy, xi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(-2, uy, 0.5\right)\right), xi, \sin \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right) \cdot yi\right) + \left(maxCos \cdot ux\right) \cdot zi\\
\end{array}
\end{array}
if uy < 0.00800000038Initial program 99.2%
Taylor expanded in ux around 0
Applied rewrites99.1%
Taylor expanded in uy around 0
Applied rewrites99.2%
if 0.00800000038 < uy Initial program 97.5%
Taylor expanded in ux around 0
Applied rewrites97.6%
Applied rewrites98.4%
Taylor expanded in uy around 0
Applied rewrites98.3%
Taylor expanded in ux around 0
Applied rewrites93.4%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (fma (- 1.0 ux) (* (* zi ux) maxCos) (fma (cos (* (* (PI) uy) -2.0)) xi (* (sin (* (* 2.0 uy) (PI))) yi))))
\begin{array}{l}
\\
\mathsf{fma}\left(1 - ux, \left(zi \cdot ux\right) \cdot maxCos, \mathsf{fma}\left(\cos \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot -2\right), xi, \sin \left(\left(2 \cdot uy\right) \cdot \mathsf{PI}\left(\right)\right) \cdot yi\right)\right)
\end{array}
Initial program 98.9%
Taylor expanded in ux around 0
Applied rewrites98.8%
lift-+.f32N/A
+-commutativeN/A
Applied rewrites98.8%
Applied rewrites98.9%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (fma (cos (* -2.0 (* (PI) uy))) xi (fma (sin (* (PI) (* 2.0 uy))) yi (* (* (* (- 1.0 ux) zi) ux) maxCos))))
\begin{array}{l}
\\
\mathsf{fma}\left(\cos \left(-2 \cdot \left(\mathsf{PI}\left(\right) \cdot uy\right)\right), xi, \mathsf{fma}\left(\sin \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right), yi, \left(\left(\left(1 - ux\right) \cdot zi\right) \cdot ux\right) \cdot maxCos\right)\right)
\end{array}
Initial program 98.9%
Taylor expanded in maxCos around 0
Applied rewrites98.8%
(FPCore (xi yi zi ux uy maxCos)
:precision binary32
(if (<= uy 0.007499999832361937)
(+
(fma
(fma
(fma
(* (* (pow (PI) 3.0) yi) uy)
-1.3333333333333333
(* (* (* (PI) (PI)) xi) -2.0))
uy
(* (* (PI) yi) 2.0))
uy
xi)
(* (* (* (- 1.0 ux) maxCos) ux) zi))
(fma
(cos (* -2.0 (* (PI) uy)))
xi
(fma (sin (* (PI) (* 2.0 uy))) yi (* (* zi ux) maxCos)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \leq 0.007499999832361937:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\left({\mathsf{PI}\left(\right)}^{3} \cdot yi\right) \cdot uy, -1.3333333333333333, \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot xi\right) \cdot -2\right), uy, \left(\mathsf{PI}\left(\right) \cdot yi\right) \cdot 2\right), uy, xi\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\cos \left(-2 \cdot \left(\mathsf{PI}\left(\right) \cdot uy\right)\right), xi, \mathsf{fma}\left(\sin \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right), yi, \left(zi \cdot ux\right) \cdot maxCos\right)\right)\\
\end{array}
\end{array}
if uy < 0.00749999983Initial program 99.2%
Taylor expanded in ux around 0
Applied rewrites99.1%
Taylor expanded in uy around 0
Applied rewrites99.2%
if 0.00749999983 < uy Initial program 97.5%
Taylor expanded in ux around 0
Applied rewrites92.8%
(FPCore (xi yi zi ux uy maxCos)
:precision binary32
(if (<= uy 0.05000000074505806)
(fma
(- 1.0 ux)
(* (* zi ux) maxCos)
(fma
(sin (* (* (PI) 2.0) uy))
yi
(* (fma (* -2.0 (* uy uy)) (* (PI) (PI)) 1.0) xi)))
(fma (cos (* -2.0 (* (PI) uy))) xi (* (sin (* (PI) (* 2.0 uy))) yi))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \leq 0.05000000074505806:\\
\;\;\;\;\mathsf{fma}\left(1 - ux, \left(zi \cdot ux\right) \cdot maxCos, \mathsf{fma}\left(\sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right), yi, \mathsf{fma}\left(-2 \cdot \left(uy \cdot uy\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right) \cdot xi\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\cos \left(-2 \cdot \left(\mathsf{PI}\left(\right) \cdot uy\right)\right), xi, \sin \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right) \cdot yi\right)\\
\end{array}
\end{array}
if uy < 0.0500000007Initial program 99.2%
Taylor expanded in ux around 0
Applied rewrites99.1%
lift-+.f32N/A
+-commutativeN/A
Applied rewrites99.1%
Taylor expanded in uy around 0
Applied rewrites98.5%
if 0.0500000007 < uy Initial program 97.0%
Taylor expanded in ux around 0
Applied rewrites88.5%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (+ (fma (fma (* -2.0 (* uy uy)) (* (PI) (PI)) 1.0) xi (* (sin (* (PI) (* 2.0 uy))) yi)) (* (* (* (- 1.0 ux) maxCos) ux) zi)))
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(-2 \cdot \left(uy \cdot uy\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right), xi, \sin \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\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%
Taylor expanded in ux around 0
Applied rewrites98.8%
Taylor expanded in uy around 0
Applied rewrites94.1%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (fma (- 1.0 ux) (* (* zi ux) maxCos) (fma (sin (* (* (PI) 2.0) uy)) yi (* (fma (* -2.0 (* uy uy)) (* (PI) (PI)) 1.0) xi))))
\begin{array}{l}
\\
\mathsf{fma}\left(1 - ux, \left(zi \cdot ux\right) \cdot maxCos, \mathsf{fma}\left(\sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right), yi, \mathsf{fma}\left(-2 \cdot \left(uy \cdot uy\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right) \cdot xi\right)\right)
\end{array}
Initial program 98.9%
Taylor expanded in ux around 0
Applied rewrites98.8%
lift-+.f32N/A
+-commutativeN/A
Applied rewrites98.8%
Taylor expanded in uy around 0
Applied rewrites94.1%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (+ (fma (sin (* (PI) (fma -2.0 uy 0.5))) xi (* (* (* yi (PI)) uy) 2.0)) (* (* (* (- 1.0 ux) maxCos) ux) zi)))
\begin{array}{l}
\\
\mathsf{fma}\left(\sin \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(-2, uy, 0.5\right)\right), xi, \left(\left(yi \cdot \mathsf{PI}\left(\right)\right) \cdot uy\right) \cdot 2\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi
\end{array}
Initial program 98.9%
Taylor expanded in ux around 0
Applied rewrites98.8%
Applied rewrites99.0%
Taylor expanded in uy around 0
Applied rewrites99.0%
Taylor expanded in uy around 0
Applied rewrites91.3%
Final simplification91.3%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (+ (fma (cos (* -2.0 (* (PI) uy))) xi (* (* (* (PI) yi) uy) 2.0)) (* (* (* (- 1.0 ux) maxCos) ux) zi)))
\begin{array}{l}
\\
\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) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi
\end{array}
Initial program 98.9%
Taylor expanded in ux around 0
Applied rewrites98.8%
Taylor expanded in uy around 0
Applied rewrites91.2%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (fma (- 1.0 ux) (* (* zi ux) maxCos) (fma (sin (* (* (PI) 2.0) uy)) yi (* 1.0 xi))))
\begin{array}{l}
\\
\mathsf{fma}\left(1 - ux, \left(zi \cdot ux\right) \cdot maxCos, \mathsf{fma}\left(\sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right), yi, 1 \cdot xi\right)\right)
\end{array}
Initial program 98.9%
Taylor expanded in ux around 0
Applied rewrites98.8%
lift-+.f32N/A
+-commutativeN/A
Applied rewrites98.8%
Taylor expanded in uy around 0
Applied rewrites90.2%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (fma (- 1.0 ux) (* (* zi ux) maxCos) (fma 1.0 xi (* (sin (* (* (PI) 2.0) uy)) yi))))
\begin{array}{l}
\\
\mathsf{fma}\left(1 - ux, \left(zi \cdot ux\right) \cdot maxCos, \mathsf{fma}\left(1, xi, \sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot yi\right)\right)
\end{array}
Initial program 98.9%
Taylor expanded in ux around 0
Applied rewrites98.8%
lift-+.f32N/A
+-commutativeN/A
Applied rewrites98.8%
Taylor expanded in uy around 0
Applied rewrites90.2%
Applied rewrites90.2%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (fma (- 1.0 ux) (* (* zi ux) maxCos) (fma (fma (* -2.0 (* (* (PI) (PI)) xi)) uy (* (* yi 2.0) (PI))) uy xi)))
\begin{array}{l}
\\
\mathsf{fma}\left(1 - ux, \left(zi \cdot ux\right) \cdot maxCos, \mathsf{fma}\left(\mathsf{fma}\left(-2 \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot xi\right), uy, \left(yi \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right), uy, xi\right)\right)
\end{array}
Initial program 98.9%
Taylor expanded in ux around 0
Applied rewrites98.8%
Taylor expanded in uy around 0
Applied rewrites88.1%
lift-+.f32N/A
+-commutativeN/A
Applied rewrites88.1%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (+ (fma (* -2.0 (- (* (* (* (PI) (PI)) xi) uy) (* yi (PI)))) uy xi) (* (* (* (- 1.0 ux) maxCos) ux) zi)))
\begin{array}{l}
\\
\mathsf{fma}\left(-2 \cdot \left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot xi\right) \cdot uy - yi \cdot \mathsf{PI}\left(\right)\right), uy, 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 ux around 0
Applied rewrites98.8%
Taylor expanded in uy around 0
Applied rewrites88.1%
Taylor expanded in uy around 0
Applied rewrites88.1%
(FPCore (xi yi zi ux uy maxCos)
:precision binary32
(let* ((t_0 (* (* (* (- 1.0 ux) maxCos) ux) zi)))
(if (or (<= yi -1.4999999940062958e-12) (not (<= yi 3.99999992980668e-13)))
(+ (* (* (* yi (PI)) uy) 2.0) t_0)
(+ xi t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi\\
\mathbf{if}\;yi \leq -1.4999999940062958 \cdot 10^{-12} \lor \neg \left(yi \leq 3.99999992980668 \cdot 10^{-13}\right):\\
\;\;\;\;\left(\left(yi \cdot \mathsf{PI}\left(\right)\right) \cdot uy\right) \cdot 2 + t\_0\\
\mathbf{else}:\\
\;\;\;\;xi + t\_0\\
\end{array}
\end{array}
if yi < -1.49999999e-12 or 3.99999993e-13 < yi Initial program 98.7%
Taylor expanded in ux around 0
Applied rewrites98.3%
Taylor expanded in uy around 0
Applied rewrites87.8%
Taylor expanded in xi around inf
Applied rewrites24.2%
Taylor expanded in xi around 0
Applied rewrites66.6%
if -1.49999999e-12 < yi < 3.99999993e-13Initial program 99.0%
Taylor expanded in ux around 0
Applied rewrites99.1%
Taylor expanded in uy around 0
Applied rewrites68.8%
Final simplification67.9%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (+ (fma (* (* (PI) yi) uy) 2.0 xi) (* (* (* (- 1.0 ux) maxCos) ux) zi)))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(\mathsf{PI}\left(\right) \cdot yi\right) \cdot uy, 2, 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 ux around 0
Applied rewrites98.8%
Taylor expanded in uy around 0
Applied rewrites85.0%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (+ (fma (* (* yi (PI)) 2.0) uy xi) (* (* (* (- 1.0 ux) maxCos) ux) zi)))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(yi \cdot \mathsf{PI}\left(\right)\right) \cdot 2, uy, 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 ux around 0
Applied rewrites98.8%
Taylor expanded in uy around 0
Applied rewrites88.1%
Taylor expanded in xi around 0
Applied rewrites85.0%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (+ xi (* (* (* (- 1.0 ux) maxCos) ux) zi)))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
return xi + ((((1.0f - ux) * 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 = xi + ((((1.0e0 - ux) * maxcos) * ux) * zi)
end function
function code(xi, yi, zi, ux, uy, maxCos) return Float32(xi + Float32(Float32(Float32(Float32(Float32(1.0) - ux) * maxCos) * ux) * zi)) end
function tmp = code(xi, yi, zi, ux, uy, maxCos) tmp = xi + ((((single(1.0) - ux) * maxCos) * ux) * zi); end
\begin{array}{l}
\\
xi + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi
\end{array}
Initial program 98.9%
Taylor expanded in ux around 0
Applied rewrites98.8%
Taylor expanded in uy around 0
Applied rewrites51.2%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (* (* maxCos (- (* zi ux) zi)) (- ux)))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
return (maxCos * ((zi * ux) - zi)) * -ux;
}
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 * ((zi * ux) - zi)) * -ux
end function
function code(xi, yi, zi, ux, uy, maxCos) return Float32(Float32(maxCos * Float32(Float32(zi * ux) - zi)) * Float32(-ux)) end
function tmp = code(xi, yi, zi, ux, uy, maxCos) tmp = (maxCos * ((zi * ux) - zi)) * -ux; end
\begin{array}{l}
\\
\left(maxCos \cdot \left(zi \cdot ux - zi\right)\right) \cdot \left(-ux\right)
\end{array}
Initial program 98.9%
Taylor expanded in zi around inf
Applied rewrites15.6%
Taylor expanded in ux around 0
Applied rewrites13.8%
Taylor expanded in ux around 0
Applied rewrites15.6%
Final simplification15.6%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (* (* (fma (- ux) zi zi) ux) maxCos))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
return (fmaf(-ux, zi, zi) * ux) * maxCos;
}
function code(xi, yi, zi, ux, uy, maxCos) return Float32(Float32(fma(Float32(-ux), zi, zi) * ux) * maxCos) end
\begin{array}{l}
\\
\left(\mathsf{fma}\left(-ux, zi, zi\right) \cdot ux\right) \cdot maxCos
\end{array}
Initial program 98.9%
Taylor expanded in zi around inf
Applied rewrites15.6%
Taylor expanded in ux around 0
Applied rewrites15.6%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (* (* zi ux) (* maxCos (- 1.0 ux))))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
return (zi * ux) * (maxCos * (1.0f - ux));
}
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 = (zi * ux) * (maxcos * (1.0e0 - ux))
end function
function code(xi, yi, zi, ux, uy, maxCos) return Float32(Float32(zi * ux) * Float32(maxCos * Float32(Float32(1.0) - ux))) end
function tmp = code(xi, yi, zi, ux, uy, maxCos) tmp = (zi * ux) * (maxCos * (single(1.0) - ux)); end
\begin{array}{l}
\\
\left(zi \cdot ux\right) \cdot \left(maxCos \cdot \left(1 - ux\right)\right)
\end{array}
Initial program 98.9%
Taylor expanded in zi around inf
Applied rewrites15.6%
Applied rewrites15.6%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (* (* maxCos zi) ux))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
return (maxCos * zi) * ux;
}
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 * zi) * ux
end function
function code(xi, yi, zi, ux, uy, maxCos) return Float32(Float32(maxCos * zi) * ux) end
function tmp = code(xi, yi, zi, ux, uy, maxCos) tmp = (maxCos * zi) * ux; end
\begin{array}{l}
\\
\left(maxCos \cdot zi\right) \cdot ux
\end{array}
Initial program 98.9%
Taylor expanded in zi around inf
Applied rewrites15.6%
Taylor expanded in ux around 0
Applied rewrites13.8%
Applied rewrites13.8%
(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 zi around inf
Applied rewrites15.6%
Taylor expanded in ux around 0
Applied rewrites13.8%
Applied rewrites13.8%
herbie shell --seed 2025020
(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)))