
(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 7 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 (* (sin (* (* (PI) uy) 2.0)) (sqrt (* (- (- 2.0 (* (pow (- maxCos 1.0) 2.0) ux)) (* 2.0 maxCos)) ux))))
\begin{array}{l}
\\
\sin \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right) \cdot \sqrt{\left(\left(2 - {\left(maxCos - 1\right)}^{2} \cdot ux\right) - 2 \cdot maxCos\right) \cdot ux}
\end{array}
Initial program 57.1%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3249.4
Applied rewrites49.4%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
associate-*r*N/A
mul-1-negN/A
fp-cancel-sub-signN/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-pow.f32N/A
lower--.f32N/A
lower-*.f3279.9
Applied rewrites79.9%
Taylor expanded in uy around inf
count-2-revN/A
distribute-lft-inN/A
count-2-revN/A
lower-sin.f32N/A
count-2-revN/A
distribute-lft-inN/A
count-2-revN/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3298.4
Applied rewrites98.4%
(FPCore (ux uy maxCos) :precision binary32 (* (sin (* (* (PI) uy) 2.0)) (sqrt (* (- (- (- 2.0 (* ux (pow (- maxCos 1.0) 2.0))) maxCos) maxCos) ux))))
\begin{array}{l}
\\
\sin \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right) \cdot \sqrt{\left(\left(\left(2 - ux \cdot {\left(maxCos - 1\right)}^{2}\right) - maxCos\right) - maxCos\right) \cdot ux}
\end{array}
Initial program 57.1%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3249.4
Applied rewrites49.4%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
associate-*r*N/A
mul-1-negN/A
fp-cancel-sub-signN/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-pow.f32N/A
lower--.f32N/A
lower-*.f3279.9
Applied rewrites79.9%
Taylor expanded in uy around inf
count-2-revN/A
distribute-lft-inN/A
count-2-revN/A
lower-sin.f32N/A
count-2-revN/A
distribute-lft-inN/A
count-2-revN/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3298.4
Applied rewrites98.4%
Applied rewrites98.3%
(FPCore (ux uy maxCos) :precision binary32 (* (sin (* (* (PI) uy) 2.0)) (sqrt (* (- 2.0 ux) ux))))
\begin{array}{l}
\\
\sin \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right) \cdot \sqrt{\left(2 - ux\right) \cdot ux}
\end{array}
Initial program 57.1%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3249.4
Applied rewrites49.4%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
associate-*r*N/A
mul-1-negN/A
fp-cancel-sub-signN/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-pow.f32N/A
lower--.f32N/A
lower-*.f3279.9
Applied rewrites79.9%
Taylor expanded in uy around inf
count-2-revN/A
distribute-lft-inN/A
count-2-revN/A
lower-sin.f32N/A
count-2-revN/A
distribute-lft-inN/A
count-2-revN/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3298.4
Applied rewrites98.4%
Taylor expanded in maxCos around 0
Applied rewrites93.4%
(FPCore (ux uy maxCos)
:precision binary32
(*
(* (* (PI) 2.0) uy)
(sqrt
(*
(- (- 2.0 (* (* (- maxCos 1.0) (+ -1.0 maxCos)) ux)) (* 2.0 maxCos))
ux))))\begin{array}{l}
\\
\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{\left(\left(2 - \left(\left(maxCos - 1\right) \cdot \left(-1 + maxCos\right)\right) \cdot ux\right) - 2 \cdot maxCos\right) \cdot ux}
\end{array}
Initial program 57.1%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3249.4
Applied rewrites49.4%
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
lower-fma.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-fma.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f3220.1
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-fma.f3220.1
Applied rewrites20.2%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
Applied rewrites79.9%
Final simplification79.9%
(FPCore (ux uy maxCos) :precision binary32 (* (* (* (PI) 2.0) uy) (sqrt (* (- 2.0 ux) ux))))
\begin{array}{l}
\\
\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{\left(2 - ux\right) \cdot ux}
\end{array}
Initial program 57.1%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3249.4
Applied rewrites49.4%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
associate-*r*N/A
mul-1-negN/A
fp-cancel-sub-signN/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-pow.f32N/A
lower--.f32N/A
lower-*.f3279.9
Applied rewrites79.9%
Taylor expanded in maxCos around 0
Applied rewrites76.8%
(FPCore (ux uy maxCos) :precision binary32 (* (* (* (PI) 2.0) uy) (sqrt (* 2.0 ux))))
\begin{array}{l}
\\
\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{2 \cdot ux}
\end{array}
Initial program 57.1%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3249.4
Applied rewrites49.4%
Taylor expanded in ux around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3262.9
Applied rewrites60.4%
Taylor expanded in maxCos around 0
Applied rewrites62.9%
(FPCore (ux uy maxCos) :precision binary32 (* (* (+ (PI) (PI)) uy) (sqrt (- 1.0 1.0))))
\begin{array}{l}
\\
\left(\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right) \cdot uy\right) \cdot \sqrt{1 - 1}
\end{array}
Initial program 57.1%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3249.4
Applied rewrites49.4%
*-lft-identityN/A
lift-*.f32N/A
lift-+.f32N/A
distribute-rgt-inN/A
distribute-lft-inN/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-fma.f32N/A
lower-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
Applied rewrites19.8%
Taylor expanded in ux around 0
Applied rewrites7.1%
Applied rewrites7.1%
herbie shell --seed 2024332
(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)))))))