
(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 9 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 (* (* (- 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}
Initial program 99.1%
(FPCore (xi yi zi ux uy maxCos)
:precision binary32
(let* ((t_0 (* (* (- 1.0 ux) maxCos) ux))
(t_1 (* (* uy 2.0) (PI)))
(t_2 (sqrt (- 1.0 (* t_0 t_0)))))
(+ (* (* (cos t_1) t_2) xi) (* (* (sin t_1) t_2) yi))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\\
t_1 := \left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\\
t_2 := \sqrt{1 - t\_0 \cdot t\_0}\\
\left(\cos t\_1 \cdot t\_2\right) \cdot xi + \left(\sin t\_1 \cdot t\_2\right) \cdot yi
\end{array}
\end{array}
Initial program 99.1%
Taylor expanded in xi around 0
Applied rewrites92.5%
(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)))
(t_3 (* (* (sin t_2) t_1) yi)))
(if (<= yi -3.99999992980668e-14)
t_3
(if (<= yi 9.999999960041972e-13)
(+ (* (* (cos t_2) t_1) xi) (* t_0 zi))
t_3))))\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)\\
t_3 := \left(\sin t\_2 \cdot t\_1\right) \cdot yi\\
\mathbf{if}\;yi \leq -3.99999992980668 \cdot 10^{-14}:\\
\;\;\;\;t\_3\\
\mathbf{elif}\;yi \leq 9.999999960041972 \cdot 10^{-13}:\\
\;\;\;\;\left(\cos t\_2 \cdot t\_1\right) \cdot xi + t\_0 \cdot zi\\
\mathbf{else}:\\
\;\;\;\;t\_3\\
\end{array}
\end{array}
if yi < -3.99999993e-14 or 9.99999996e-13 < yi Initial program 99.1%
Taylor expanded in xi around inf
Applied rewrites71.1%
if -3.99999993e-14 < yi < 9.99999996e-13Initial program 99.1%
Taylor expanded in xi around 0
Applied rewrites82.1%
(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)))
(t_3 (* (* (sin t_2) t_1) yi)))
(if (<= yi -3.99999992980668e-14)
t_3
(if (<= yi 9.999999960041972e-13) (* (* (cos t_2) t_1) xi) t_3))))\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)\\
t_3 := \left(\sin t\_2 \cdot t\_1\right) \cdot yi\\
\mathbf{if}\;yi \leq -3.99999992980668 \cdot 10^{-14}:\\
\;\;\;\;t\_3\\
\mathbf{elif}\;yi \leq 9.999999960041972 \cdot 10^{-13}:\\
\;\;\;\;\left(\cos t\_2 \cdot t\_1\right) \cdot xi\\
\mathbf{else}:\\
\;\;\;\;t\_3\\
\end{array}
\end{array}
if yi < -3.99999993e-14 or 9.99999996e-13 < yi Initial program 99.1%
Taylor expanded in xi around inf
Applied rewrites71.1%
if -3.99999993e-14 < yi < 9.99999996e-13Initial program 99.1%
Taylor expanded in xi around 0
Applied rewrites88.8%
Taylor expanded in xi around 0
Applied rewrites72.6%
(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)))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\\
\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
\end{array}
\end{array}
Initial program 99.1%
Taylor expanded in xi around 0
Applied rewrites92.5%
Taylor expanded in xi around 0
Applied rewrites51.7%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (* (* (* (- 1.0 ux) maxCos) ux) zi))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
return (((1.0f - ux) * maxCos) * ux) * zi;
}
real(4) function code(xi, yi, zi, ux, uy, maxcos)
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 = (((1.0e0 - ux) * maxcos) * ux) * zi
end function
function code(xi, yi, zi, ux, uy, maxCos) return Float32(Float32(Float32(Float32(Float32(1.0) - ux) * maxCos) * ux) * zi) end
function tmp = code(xi, yi, zi, ux, uy, maxCos) tmp = (((single(1.0) - ux) * maxCos) * ux) * zi; end
\begin{array}{l}
\\
\left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi
\end{array}
Initial program 99.1%
Taylor expanded in xi around 0
Applied rewrites92.5%
Taylor expanded in yi around inf
Applied rewrites12.4%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (* uy 2.0))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
return uy * 2.0f;
}
real(4) function code(xi, yi, zi, ux, uy, maxcos)
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 = uy * 2.0e0
end function
function code(xi, yi, zi, ux, uy, maxCos) return Float32(uy * Float32(2.0)) end
function tmp = code(xi, yi, zi, ux, uy, maxCos) tmp = uy * single(2.0); end
\begin{array}{l}
\\
uy \cdot 2
\end{array}
Initial program 99.1%
Taylor expanded in xi around 0
Applied rewrites92.5%
Taylor expanded in xi around 0
Applied rewrites51.7%
Taylor expanded in yi around -inf
Applied rewrites9.9%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (- 1.0 ux))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
return 1.0f - ux;
}
real(4) function code(xi, yi, zi, ux, uy, maxcos)
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 = 1.0e0 - ux
end function
function code(xi, yi, zi, ux, uy, maxCos) return Float32(Float32(1.0) - ux) end
function tmp = code(xi, yi, zi, ux, uy, maxCos) tmp = single(1.0) - ux; end
\begin{array}{l}
\\
1 - ux
\end{array}
Initial program 99.1%
Taylor expanded in xi around 0
Applied rewrites92.5%
Taylor expanded in xi around 0
Applied rewrites51.7%
Taylor expanded in xi around inf
Applied rewrites8.8%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (PI))
\begin{array}{l}
\\
\mathsf{PI}\left(\right)
\end{array}
Initial program 99.1%
Taylor expanded in xi around 0
Applied rewrites57.3%
Taylor expanded in ux around 0
Applied rewrites8.7%
herbie shell --seed 2024321
(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)))