
(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 14 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 (* (* uy 2.0) (PI))))
(+
(+
(*
(*
(cos t_1)
(sqrt (/ 1.0 (/ 1.0 (- 1.0 (pow (* (* maxCos (- 1.0 ux)) ux) 2.0))))))
xi)
(* (* (sin t_1) (sqrt (- 1.0 (* t_0 t_0)))) yi))
(* t_0 zi))))\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)\\
\left(\left(\cos t\_1 \cdot \sqrt{\frac{1}{\frac{1}{1 - {\left(\left(maxCos \cdot \left(1 - ux\right)\right) \cdot ux\right)}^{2}}}}\right) \cdot xi + \left(\sin t\_1 \cdot \sqrt{1 - t\_0 \cdot t\_0}\right) \cdot yi\right) + t\_0 \cdot zi
\end{array}
\end{array}
Initial program 99.1%
lift--.f32N/A
flip--N/A
clear-numN/A
lower-/.f32N/A
clear-numN/A
flip--N/A
lift--.f32N/A
Applied rewrites99.2%
(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)))
(+
(+
(* (cos (* (* (PI) uy) 2.0)) xi)
(* (* (sin (* (* uy 2.0) (PI))) (sqrt (- 1.0 (* t_0 t_0)))) yi))
(* t_0 zi))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\\
\left(\cos \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right) \cdot xi + \left(\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{1 - t\_0 \cdot t\_0}\right) \cdot yi\right) + t\_0 \cdot zi
\end{array}
\end{array}
Initial program 99.1%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3299.0
Applied rewrites99.0%
(FPCore (xi yi zi ux uy maxCos)
:precision binary32
(let* ((t_0 (* (* (PI) 2.0) uy)))
(+
(+ (* yi (sin t_0)) (* xi (cos t_0)))
(* (* (* (- 1.0 ux) maxCos) ux) zi))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\\
\left(yi \cdot \sin t\_0 + xi \cdot \cos t\_0\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi
\end{array}
\end{array}
Initial program 99.1%
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.f3231.6
Applied rewrites31.3%
Applied rewrites98.7%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (let* ((t_0 (* (* (PI) 2.0) uy))) (+ (+ (* yi (sin t_0)) (* xi (cos t_0))) (* (* maxCos ux) zi))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\\
\left(yi \cdot \sin t\_0 + xi \cdot \cos t\_0\right) + \left(maxCos \cdot ux\right) \cdot zi
\end{array}
\end{array}
Initial program 99.1%
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.f3231.3
Applied rewrites31.3%
Applied rewrites98.7%
Taylor expanded in ux around 0
lower-*.f3296.5
Applied rewrites96.5%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (+ (+ (* (* (* (PI) yi) uy) 2.0) (* xi (cos (* (* (PI) 2.0) uy)))) (* (* (* (- 1.0 ux) maxCos) ux) zi)))
\begin{array}{l}
\\
\left(\left(\left(\mathsf{PI}\left(\right) \cdot yi\right) \cdot uy\right) \cdot 2 + xi \cdot \cos \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right)\right) + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi
\end{array}
Initial program 99.1%
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.f3231.3
Applied rewrites31.3%
Applied rewrites98.7%
Taylor expanded in uy around 0
Applied rewrites92.9%
(FPCore (xi yi zi ux uy maxCos)
:precision binary32
(let* ((t_0 (* (* (PI) uy) 2.0)) (t_1 (* (* (* (- 1.0 ux) maxCos) ux) zi)))
(if (or (<= xi -9.999999998199587e-24) (not (<= xi 1.4999999523982838e-22)))
(+ (* (cos t_0) xi) t_1)
(+ (* (sin t_0) yi) t_1))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\\
t_1 := \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi\\
\mathbf{if}\;xi \leq -9.999999998199587 \cdot 10^{-24} \lor \neg \left(xi \leq 1.4999999523982838 \cdot 10^{-22}\right):\\
\;\;\;\;\cos t\_0 \cdot xi + t\_1\\
\mathbf{else}:\\
\;\;\;\;\sin t\_0 \cdot yi + t\_1\\
\end{array}
\end{array}
if xi < -1e-23 or 1.5e-22 < xi Initial program 99.4%
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.f3216.1
Applied rewrites16.1%
Taylor expanded in xi around inf
Applied rewrites81.9%
if -1e-23 < xi < 1.5e-22Initial program 98.7%
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.f3254.5
Applied rewrites55.4%
Taylor expanded in xi around 0
Applied rewrites72.3%
Final simplification78.1%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (+ (* (cos (* (* (PI) uy) 2.0)) xi) (* (* (* (- 1.0 ux) maxCos) ux) zi)))
\begin{array}{l}
\\
\cos \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right) \cdot xi + \left(\left(\left(1 - ux\right) \cdot maxCos\right) \cdot ux\right) \cdot zi
\end{array}
Initial program 99.1%
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.f3231.3
Applied rewrites31.3%
Taylor expanded in xi around inf
Applied rewrites62.9%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (+ (fma (fma (* (* (* (PI) (PI)) xi) uy) -2.0 (* (* (PI) yi) 2.0)) uy xi) (* (* (* (- 1.0 ux) maxCos) ux) zi)))
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot xi\right) \cdot uy, -2, \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
\end{array}
Initial program 99.1%
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.f3231.3
Applied rewrites31.3%
Applied rewrites98.7%
Taylor expanded in uy around 0
Applied rewrites58.2%
Final simplification58.2%
(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 99.1%
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.f3231.3
Applied rewrites31.3%
Applied rewrites98.7%
Taylor expanded in uy around 0
Applied rewrites58.2%
Final simplification58.2%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (* (* (* ux ux) zi) (- (/ maxCos ux) maxCos)))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
return ((ux * ux) * zi) * ((maxCos / ux) - maxCos);
}
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 = ((ux * ux) * zi) * ((maxcos / ux) - maxcos)
end function
function code(xi, yi, zi, ux, uy, maxCos) return Float32(Float32(Float32(ux * ux) * zi) * Float32(Float32(maxCos / ux) - maxCos)) end
function tmp = code(xi, yi, zi, ux, uy, maxCos) tmp = ((ux * ux) * zi) * ((maxCos / ux) - maxCos); end
\begin{array}{l}
\\
\left(\left(ux \cdot ux\right) \cdot zi\right) \cdot \left(\frac{maxCos}{ux} - maxCos\right)
\end{array}
Initial program 99.1%
Taylor expanded in zi around inf
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f3213.1
Applied rewrites13.1%
Taylor expanded in ux around inf
Applied rewrites13.1%
Taylor expanded in zi around 0
Applied rewrites13.1%
Final simplification13.1%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (* (* (* (- 1.0 ux) zi) ux) maxCos))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
return (((1.0f - ux) * zi) * ux) * maxCos;
}
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) * zi) * ux) * maxcos
end function
function code(xi, yi, zi, ux, uy, maxCos) return Float32(Float32(Float32(Float32(Float32(1.0) - ux) * zi) * ux) * maxCos) end
function tmp = code(xi, yi, zi, ux, uy, maxCos) tmp = (((single(1.0) - ux) * zi) * ux) * maxCos; end
\begin{array}{l}
\\
\left(\left(\left(1 - ux\right) \cdot zi\right) \cdot ux\right) \cdot maxCos
\end{array}
Initial program 99.1%
Taylor expanded in zi around inf
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f3213.1
Applied rewrites13.1%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (* (* maxCos (* zi (- 1.0 ux))) ux))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
return (maxCos * (zi * (1.0f - ux))) * 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 = (maxcos * (zi * (1.0e0 - ux))) * ux
end function
function code(xi, yi, zi, ux, uy, maxCos) return Float32(Float32(maxCos * Float32(zi * Float32(Float32(1.0) - ux))) * ux) end
function tmp = code(xi, yi, zi, ux, uy, maxCos) tmp = (maxCos * (zi * (single(1.0) - ux))) * ux; end
\begin{array}{l}
\\
\left(maxCos \cdot \left(zi \cdot \left(1 - ux\right)\right)\right) \cdot ux
\end{array}
Initial program 99.1%
Taylor expanded in zi around inf
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f3213.1
Applied rewrites13.1%
Applied rewrites13.1%
(FPCore (xi yi zi ux uy maxCos) :precision binary32 (* (* zi ux) maxCos))
float code(float xi, float yi, float zi, float ux, float uy, float maxCos) {
return (zi * ux) * maxCos;
}
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 = (zi * ux) * maxcos
end function
function code(xi, yi, zi, ux, uy, maxCos) return Float32(Float32(zi * ux) * maxCos) end
function tmp = code(xi, yi, zi, ux, uy, maxCos) tmp = (zi * ux) * maxCos; end
\begin{array}{l}
\\
\left(zi \cdot ux\right) \cdot maxCos
\end{array}
Initial program 99.1%
Taylor expanded in zi around inf
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f3213.1
Applied rewrites13.1%
Taylor expanded in ux around 0
Applied rewrites11.8%
herbie shell --seed 2024313
(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)))