
(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 11 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 (+ (* (- 1.0 ux) ux) ux)) (sin (* (PI) (* 2.0 uy)))))
\begin{array}{l}
\\
\sqrt{\left(1 - ux\right) \cdot ux + ux} \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)
\end{array}
Initial program 56.4%
lift-*.f32N/A
lift-+.f32N/A
lift--.f32N/A
sub-negN/A
associate-+l+N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-+.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
neg-mul-1N/A
lift-*.f32N/A
*-commutativeN/A
distribute-rgt-outN/A
lower-*.f32N/A
Applied rewrites19.5%
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--.f3294.3
Applied rewrites94.3%
Final simplification94.3%
(FPCore (ux uy maxCos)
:precision binary32
(*
(sqrt
(-
(- ux (* maxCos ux))
(* (- maxCos 1.0) (* (fma maxCos ux (- 1.0 ux)) ux))))
(sin (* (PI) (* 2.0 uy)))))\begin{array}{l}
\\
\sqrt{\left(ux - maxCos \cdot ux\right) - \left(maxCos - 1\right) \cdot \left(\mathsf{fma}\left(maxCos, ux, 1 - ux\right) \cdot ux\right)} \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)
\end{array}
Initial program 56.4%
lift-*.f32N/A
lift-+.f32N/A
lift--.f32N/A
sub-negN/A
associate-+l+N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-+.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
neg-mul-1N/A
lift-*.f32N/A
*-commutativeN/A
distribute-rgt-outN/A
lower-*.f32N/A
Applied rewrites18.9%
lift--.f32N/A
lift-+.f32N/A
associate--r+N/A
lower--.f32N/A
lift-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lift-*.f32N/A
lift--.f32N/A
associate-+l-N/A
associate--r-N/A
metadata-evalN/A
lower-+.f32N/A
lower--.f3249.5
lift-*.f32N/A
*-commutativeN/A
lower-*.f3249.9
lift-*.f32N/A
lift-*.f32N/A
associate-*r*N/A
lift-+.f32N/A
Applied rewrites50.5%
Final simplification50.4%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (+ (* (- 1.0 ux) ux) (- ux (* (fma (- (- 1.0 ux) ux) ux ux) maxCos)))) (sin (* (PI) (* 2.0 uy)))))
\begin{array}{l}
\\
\sqrt{\left(1 - ux\right) \cdot ux + \left(ux - \mathsf{fma}\left(\left(1 - ux\right) - ux, ux, ux\right) \cdot maxCos\right)} \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)
\end{array}
Initial program 56.4%
lift-*.f32N/A
lift-+.f32N/A
lift--.f32N/A
sub-negN/A
associate-+l+N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-+.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
neg-mul-1N/A
lift-*.f32N/A
*-commutativeN/A
distribute-rgt-outN/A
lower-*.f32N/A
Applied rewrites19.2%
Taylor expanded in maxCos around 0
lower--.f32N/A
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f3256.3
Applied rewrites56.3%
Taylor expanded in maxCos around 0
associate-*r*N/A
mul-1-negN/A
cancel-sign-subN/A
lower-+.f32N/A
Applied rewrites82.4%
Final simplification84.1%
(FPCore (ux uy maxCos) :precision binary32 (if (<= (* 2.0 uy) 0.00559999980032444) (* (* (* (PI) 2.0) uy) (sqrt (+ (* (- 1.0 ux) ux) ux))) (* (sqrt (* ux 2.0)) (sin (* (PI) (* 2.0 uy))))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;2 \cdot uy \leq 0.00559999980032444:\\
\;\;\;\;\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{\left(1 - ux\right) \cdot ux + ux}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{ux \cdot 2} \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
\end{array}
\end{array}
if (*.f32 uy #s(literal 2 binary32)) < 0.0055999998Initial program 57.5%
lift-*.f32N/A
lift-+.f32N/A
lift--.f32N/A
sub-negN/A
associate-+l+N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-+.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
neg-mul-1N/A
lift-*.f32N/A
*-commutativeN/A
distribute-rgt-outN/A
lower-*.f32N/A
Applied rewrites25.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--.f3294.3
Applied rewrites94.3%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3292.2
Applied rewrites92.2%
if 0.0055999998 < (*.f32 uy #s(literal 2 binary32)) Initial program 53.5%
lift-*.f32N/A
lift-+.f32N/A
lift--.f32N/A
sub-negN/A
associate-+l+N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-+.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
neg-mul-1N/A
lift-*.f32N/A
*-commutativeN/A
distribute-rgt-outN/A
lower-*.f32N/A
Applied rewrites11.0%
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--.f3294.3
Applied rewrites94.3%
Taylor expanded in ux around 0
Applied rewrites75.9%
Final simplification87.7%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* (+ (- 1.0 ux) 1.0) ux)) (sin (* (PI) (* 2.0 uy)))))
\begin{array}{l}
\\
\sqrt{\left(\left(1 - ux\right) + 1\right) \cdot ux} \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)
\end{array}
Initial program 56.4%
lift-*.f32N/A
lift-+.f32N/A
lift--.f32N/A
sub-negN/A
associate-+l+N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-+.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
neg-mul-1N/A
lift-*.f32N/A
*-commutativeN/A
distribute-rgt-outN/A
lower-*.f32N/A
Applied rewrites20.0%
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--.f3294.3
Applied rewrites94.3%
Applied rewrites94.3%
Final simplification94.3%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* (- 2.0 ux) ux)) (sin (* (PI) (* 2.0 uy)))))
\begin{array}{l}
\\
\sqrt{\left(2 - ux\right) \cdot ux} \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)
\end{array}
Initial program 56.4%
lift-*.f32N/A
lift-+.f32N/A
lift--.f32N/A
sub-negN/A
associate-+l+N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-+.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
neg-mul-1N/A
lift-*.f32N/A
*-commutativeN/A
distribute-rgt-outN/A
lower-*.f32N/A
Applied rewrites19.5%
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--.f3294.3
Applied rewrites94.3%
Taylor expanded in ux around 0
Applied rewrites94.2%
Final simplification94.2%
(FPCore (ux uy maxCos) :precision binary32 (* (* (* (PI) 2.0) uy) (sqrt (+ (* (- 1.0 ux) ux) ux))))
\begin{array}{l}
\\
\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{\left(1 - ux\right) \cdot ux + ux}
\end{array}
Initial program 56.4%
lift-*.f32N/A
lift-+.f32N/A
lift--.f32N/A
sub-negN/A
associate-+l+N/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-+.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
neg-mul-1N/A
lift-*.f32N/A
*-commutativeN/A
distribute-rgt-outN/A
lower-*.f32N/A
Applied rewrites19.2%
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--.f3294.3
Applied rewrites94.3%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3279.4
Applied rewrites79.4%
Final simplification79.4%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* (fma -2.0 maxCos 2.0) ux)) (* (* (PI) 2.0) uy)))
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right)
\end{array}
Initial program 56.4%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3250.7
Applied rewrites50.7%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3263.4
Applied rewrites64.1%
Final simplification64.3%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (fma -1.0 1.0 1.0)) (fma uy (PI) (* (PI) uy))))
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(-1, 1, 1\right)} \cdot \mathsf{fma}\left(uy, \mathsf{PI}\left(\right), \mathsf{PI}\left(\right) \cdot uy\right)
\end{array}
Initial program 56.4%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3250.7
Applied rewrites50.7%
Taylor expanded in ux around 0
Applied rewrites7.1%
lift--.f32N/A
sub-negN/A
+-commutativeN/A
neg-mul-1N/A
lower-fma.f3220.2
Applied rewrites20.5%
Applied rewrites21.1%
Final simplification20.3%
(FPCore (ux uy maxCos) :precision binary32 (* (* (+ uy uy) (PI)) (sqrt (fma -1.0 1.0 1.0))))
\begin{array}{l}
\\
\left(\left(uy + uy\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\mathsf{fma}\left(-1, 1, 1\right)}
\end{array}
Initial program 56.4%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3250.7
Applied rewrites50.7%
Taylor expanded in ux around 0
Applied rewrites7.1%
lift--.f32N/A
sub-negN/A
+-commutativeN/A
neg-mul-1N/A
lower-fma.f3220.6
Applied rewrites20.5%
Applied rewrites20.5%
Final simplification20.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 56.4%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3250.7
Applied rewrites50.7%
Taylor expanded in ux around 0
Applied rewrites7.1%
Final simplification7.1%
herbie shell --seed 2024276
(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)))))))