
(FPCore (ux uy maxCos) :precision binary32 (let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))) (* (sin (* (* uy 2.0) (PI))) (sqrt (- 1.0 (* t_0 t_0))))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{1 - t\_0 \cdot t\_0}
\end{array}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (ux uy maxCos) :precision binary32 (let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))) (* (sin (* (* uy 2.0) (PI))) (sqrt (- 1.0 (* t_0 t_0))))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{1 - t\_0 \cdot t\_0}
\end{array}
\end{array}
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* (- (- 2.0 (* (pow (- maxCos 1.0) 2.0) ux)) (* maxCos 2.0)) ux)) (sin (* (PI) (* 2.0 uy)))))
\begin{array}{l}
\\
\sqrt{\left(\left(2 - {\left(maxCos - 1\right)}^{2} \cdot ux\right) - maxCos \cdot 2\right) \cdot ux} \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)
\end{array}
Initial program 55.9%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower-/.f3256.8
Applied rewrites56.8%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-pow.f32N/A
lower--.f32N/A
lower-*.f3298.3
Applied rewrites98.3%
Final simplification98.3%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* (- (- 2.0 (* (fma -2.0 ux 2.0) maxCos)) ux) ux)) (sin (* (PI) (* 2.0 uy)))))
\begin{array}{l}
\\
\sqrt{\left(\left(2 - \mathsf{fma}\left(-2, ux, 2\right) \cdot maxCos\right) - ux\right) \cdot ux} \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)
\end{array}
Initial program 55.9%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower-/.f3256.8
Applied rewrites56.8%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-pow.f32N/A
lower--.f32N/A
lower-*.f3298.3
Applied rewrites98.3%
Taylor expanded in maxCos around 0
Applied rewrites85.9%
Final simplification87.8%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= maxCos 1.500000053056283e-6)
(* (sin (* (* (PI) uy) 2.0)) (sqrt (+ (* (- 1.0 ux) ux) ux)))
(*
(sqrt
(*
(- (- 2.0 (* (* (- maxCos 1.0) (- maxCos 1.0)) ux)) (* maxCos 2.0))
ux))
(* (* (PI) 2.0) uy))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 1.500000053056283 \cdot 10^{-6}:\\
\;\;\;\;\sin \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right) \cdot \sqrt{\left(1 - ux\right) \cdot ux + ux}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\left(2 - \left(\left(maxCos - 1\right) \cdot \left(maxCos - 1\right)\right) \cdot ux\right) - maxCos \cdot 2\right) \cdot ux} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right)\\
\end{array}
\end{array}
if maxCos < 1.50000005e-6Initial program 56.3%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3248.4
Applied rewrites48.4%
lift-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift--.f32N/A
associate-+r-N/A
lift-*.f32N/A
*-commutativeN/A
lift-fma.f32N/A
sub-negN/A
distribute-lft-inN/A
lower-+.f32N/A
lower-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
Applied rewrites46.7%
Taylor expanded in maxCos around 0
*-commutativeN/A
lower-*.f32N/A
lower-sqrt.f32N/A
associate-*r*N/A
mul-1-negN/A
cancel-sign-subN/A
lower-+.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
lower-sin.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3298.2
Applied rewrites98.2%
if 1.50000005e-6 < maxCos Initial program 52.9%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3250.6
Applied rewrites50.6%
lift-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift--.f32N/A
associate-+r-N/A
lift-*.f32N/A
*-commutativeN/A
lift-fma.f32N/A
sub-negN/A
distribute-lft-inN/A
lower-+.f32N/A
lower-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
Applied rewrites37.1%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
distribute-rgt-outN/A
lower-*.f32N/A
lower--.f32N/A
lower-+.f32N/A
lower-*.f3290.7
Applied rewrites90.7%
Final simplification97.2%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= maxCos 1.500000053056283e-6)
(* (sqrt (* (- 2.0 ux) ux)) (sin (* (PI) (* 2.0 uy))))
(*
(sqrt
(*
(- (- 2.0 (* (* (- maxCos 1.0) (- maxCos 1.0)) ux)) (* maxCos 2.0))
ux))
(* (* (PI) 2.0) uy))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 1.500000053056283 \cdot 10^{-6}:\\
\;\;\;\;\sqrt{\left(2 - ux\right) \cdot ux} \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\left(2 - \left(\left(maxCos - 1\right) \cdot \left(maxCos - 1\right)\right) \cdot ux\right) - maxCos \cdot 2\right) \cdot ux} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right)\\
\end{array}
\end{array}
if maxCos < 1.50000005e-6Initial program 56.3%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower-/.f3257.2
Applied rewrites57.2%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-pow.f32N/A
lower--.f32N/A
lower-*.f3298.2
Applied rewrites98.2%
Taylor expanded in maxCos around 0
Applied rewrites98.1%
if 1.50000005e-6 < maxCos Initial program 52.9%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3250.6
Applied rewrites50.6%
lift-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift--.f32N/A
associate-+r-N/A
lift-*.f32N/A
*-commutativeN/A
lift-fma.f32N/A
sub-negN/A
distribute-lft-inN/A
lower-+.f32N/A
lower-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
Applied rewrites39.7%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
distribute-rgt-outN/A
lower-*.f32N/A
lower--.f32N/A
lower-+.f32N/A
lower-*.f3290.7
Applied rewrites90.7%
Final simplification97.2%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* (- (- 2.0 (* (* (- maxCos 1.0) (- maxCos 1.0)) ux)) (* maxCos 2.0)) ux)) (* (* (PI) 2.0) uy)))
\begin{array}{l}
\\
\sqrt{\left(\left(2 - \left(\left(maxCos - 1\right) \cdot \left(maxCos - 1\right)\right) \cdot ux\right) - maxCos \cdot 2\right) \cdot ux} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right)
\end{array}
Initial program 55.9%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3248.7
Applied rewrites48.7%
lift-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift--.f32N/A
associate-+r-N/A
lift-*.f32N/A
*-commutativeN/A
lift-fma.f32N/A
sub-negN/A
distribute-lft-inN/A
lower-+.f32N/A
lower-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
Applied rewrites46.3%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
distribute-rgt-outN/A
lower-*.f32N/A
lower--.f32N/A
lower-+.f32N/A
lower-*.f3281.3
Applied rewrites81.3%
Final simplification81.3%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (+ (* (- 1.0 ux) ux) ux)) (* (* (PI) 2.0) uy)))
\begin{array}{l}
\\
\sqrt{\left(1 - ux\right) \cdot ux + ux} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right)
\end{array}
Initial program 55.9%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3248.7
Applied rewrites48.7%
lift-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift--.f32N/A
associate-+r-N/A
lift-*.f32N/A
*-commutativeN/A
lift-fma.f32N/A
sub-negN/A
distribute-lft-inN/A
lower-+.f32N/A
lower-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
Applied rewrites46.4%
Taylor expanded in maxCos around 0
associate-*r*N/A
mul-1-negN/A
cancel-sign-subN/A
lower-+.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f3277.2
Applied rewrites77.2%
Final simplification77.2%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* (fma -2.0 maxCos 2.0) ux)) (* (+ uy uy) (PI))))
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot \left(\left(uy + uy\right) \cdot \mathsf{PI}\left(\right)\right)
\end{array}
Initial program 55.9%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3248.7
Applied rewrites48.7%
Taylor expanded in maxCos around 0
lower--.f3247.5
Applied rewrites47.5%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
lower-fma.f3264.6
Applied rewrites64.5%
Applied rewrites64.0%
Final simplification64.6%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (- 1.0 (* ux ux))) (* (* (PI) 2.0) uy)))
\begin{array}{l}
\\
\sqrt{1 - ux \cdot ux} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right)
\end{array}
Initial program 55.9%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3248.7
Applied rewrites48.7%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
flip--N/A
lower-/.f32N/A
metadata-evalN/A
lower--.f32N/A
pow2N/A
lower-pow.f32N/A
lower--.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
lower-+.f32N/A
lower--.f3248.7
lift-*.f32N/A
*-commutativeN/A
lift-*.f3248.7
Applied rewrites48.7%
Taylor expanded in maxCos around 0
lower-/.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f32N/A
lower--.f32N/A
lower-+.f3247.4
Applied rewrites47.4%
Taylor expanded in ux around inf
Applied rewrites19.6%
Final simplification19.6%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (- 1.0 1.0)) (* (* (PI) 2.0) uy)))
\begin{array}{l}
\\
\sqrt{1 - 1} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right)
\end{array}
Initial program 55.9%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3248.7
Applied rewrites48.7%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
flip--N/A
lower-/.f32N/A
metadata-evalN/A
lower--.f32N/A
pow2N/A
lower-pow.f32N/A
lower--.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
lower-+.f32N/A
lower--.f3248.7
lift-*.f32N/A
*-commutativeN/A
lift-*.f3248.7
Applied rewrites48.7%
Taylor expanded in maxCos around 0
lower-/.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f32N/A
lower--.f32N/A
lower-+.f3247.4
Applied rewrites47.4%
Taylor expanded in ux around 0
Applied rewrites7.1%
Final simplification7.1%
herbie shell --seed 2024304
(FPCore (ux uy maxCos)
:name "UniformSampleCone, y"
:precision binary32
:pre (and (and (and (<= 2.328306437e-10 ux) (<= ux 1.0)) (and (<= 2.328306437e-10 uy) (<= uy 1.0))) (and (<= 0.0 maxCos) (<= maxCos 1.0)))
(* (sin (* (* uy 2.0) (PI))) (sqrt (- 1.0 (* (+ (- 1.0 ux) (* ux maxCos)) (+ (- 1.0 ux) (* ux maxCos)))))))