
(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 12 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 (fma (cbrt (* (PI) (PI))) (* (cbrt (PI)) uy) (* (PI) uy))) (sqrt (* (fma -2.0 maxCos (- 2.0 (* (pow (- maxCos 1.0) 2.0) ux))) ux))))
\begin{array}{l}
\\
\sin \left(\mathsf{fma}\left(\sqrt[3]{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)}, \sqrt[3]{\mathsf{PI}\left(\right)} \cdot uy, \mathsf{PI}\left(\right) \cdot uy\right)\right) \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2 - {\left(maxCos - 1\right)}^{2} \cdot ux\right) \cdot ux}
\end{array}
Initial program 58.9%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
lower-fma.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--.f3298.2
Applied rewrites98.2%
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
count-2-revN/A
distribute-lft-inN/A
lift-PI.f32N/A
add-cube-cbrtN/A
associate-*l*N/A
lift-*.f32N/A
lower-fma.f32N/A
pow2N/A
lower-pow.f32N/A
lift-PI.f32N/A
lower-cbrt.f32N/A
lower-*.f32N/A
lift-PI.f32N/A
lower-cbrt.f3298.3
Applied rewrites98.3%
lift-pow.f32N/A
unpow2N/A
lift-cbrt.f32N/A
lift-cbrt.f32N/A
cbrt-unprodN/A
lift-PI.f32N/A
lift-PI.f32N/A
lower-cbrt.f32N/A
lift-PI.f32N/A
lift-PI.f32N/A
lower-*.f3298.3
Applied rewrites98.3%
Final simplification98.3%
(FPCore (ux uy maxCos) :precision binary32 (* (sin (* (* uy 2.0) (PI))) (sqrt (* (- 2.0 (fma (pow (- maxCos 1.0) 2.0) ux (* 2.0 maxCos))) ux))))
\begin{array}{l}
\\
\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(2 - \mathsf{fma}\left({\left(maxCos - 1\right)}^{2}, ux, 2 \cdot maxCos\right)\right) \cdot ux}
\end{array}
Initial program 58.9%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
lower-fma.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--.f3298.2
Applied rewrites98.2%
Taylor expanded in ux around 0
Applied rewrites98.2%
Final simplification98.2%
(FPCore (ux uy maxCos)
:precision binary32
(*
(sin (* (* uy 2.0) (PI)))
(sqrt
(fma
(- (fma (fma -2.0 ux 2.0) ux (* (* maxCos ux) ux)))
maxCos
(* (- 2.0 ux) ux)))))\begin{array}{l}
\\
\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\mathsf{fma}\left(-\mathsf{fma}\left(\mathsf{fma}\left(-2, ux, 2\right), ux, \left(maxCos \cdot ux\right) \cdot ux\right), maxCos, \left(2 - ux\right) \cdot ux\right)}
\end{array}
Initial program 58.9%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
lower-fma.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--.f3298.2
Applied rewrites98.2%
Taylor expanded in maxCos around 0
Applied rewrites98.1%
Final simplification98.1%
(FPCore (ux uy maxCos) :precision binary32 (* (sin (* (* uy 2.0) (PI))) (sqrt (- (* (- 2.0 ux) ux) (* (* maxCos (fma -2.0 ux 2.0)) ux)))))
\begin{array}{l}
\\
\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(2 - ux\right) \cdot ux - \left(maxCos \cdot \mathsf{fma}\left(-2, ux, 2\right)\right) \cdot ux}
\end{array}
Initial program 58.9%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
lower-fma.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--.f3298.2
Applied rewrites98.2%
Taylor expanded in maxCos around 0
Applied rewrites97.1%
Final simplification97.1%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (sin (* (* uy 2.0) (PI)))))
(if (<= maxCos 1.9999999494757503e-5)
(* t_0 (sqrt (* (- 2.0 ux) ux)))
(* t_0 (sqrt (* (fma -2.0 maxCos 2.0) ux))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right)\\
\mathbf{if}\;maxCos \leq 1.9999999494757503 \cdot 10^{-5}:\\
\;\;\;\;t\_0 \cdot \sqrt{\left(2 - ux\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}\\
\end{array}
\end{array}
if maxCos < 1.99999995e-5Initial program 59.2%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
lower-fma.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--.f3298.2
Applied rewrites98.2%
Taylor expanded in maxCos around 0
Applied rewrites97.7%
if 1.99999995e-5 < maxCos Initial program 56.5%
Taylor expanded in ux around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3278.7
Applied rewrites78.7%
Final simplification95.2%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= maxCos 9.999999747378752e-5)
(* (sin (* (* uy 2.0) (PI))) (sqrt (* (- 2.0 ux) ux)))
(*
(* (* (PI) 2.0) uy)
(sqrt
(*
(-
(*
(* ux ux)
(+
(/ (- (/ 2.0 ux) 1.0) (* maxCos maxCos))
(/ (- 2.0 (/ 2.0 ux)) maxCos)))
(* ux ux))
(* maxCos maxCos))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(2 - ux\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{\left(\left(ux \cdot ux\right) \cdot \left(\frac{\frac{2}{ux} - 1}{maxCos \cdot maxCos} + \frac{2 - \frac{2}{ux}}{maxCos}\right) - ux \cdot ux\right) \cdot \left(maxCos \cdot maxCos\right)}\\
\end{array}
\end{array}
if maxCos < 9.99999975e-5Initial program 58.7%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
fp-cancel-sub-sign-invN/A
metadata-evalN/A
+-commutativeN/A
lower-fma.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--.f3298.2
Applied rewrites98.2%
Taylor expanded in maxCos around 0
Applied rewrites96.9%
if 9.99999975e-5 < maxCos Initial program 60.5%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3254.4
Applied rewrites54.4%
Taylor expanded in ux around inf
*-commutativeN/A
Applied rewrites78.3%
Taylor expanded in maxCos around inf
Applied rewrites78.6%
Final simplification95.1%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (* (* (PI) 2.0) uy)) (t_1 (+ (- 1.0 ux) (* ux maxCos))))
(if (<= (sqrt (- 1.0 (* t_1 t_1))) 0.023000000044703484)
(* t_0 (sqrt (* (fma -2.0 maxCos 2.0) ux)))
(* t_0 (sqrt (- 1.0 (* t_1 (- 1.0 ux))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\\
t_1 := \left(1 - ux\right) + ux \cdot maxCos\\
\mathbf{if}\;\sqrt{1 - t\_1 \cdot t\_1} \leq 0.023000000044703484:\\
\;\;\;\;t\_0 \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sqrt{1 - t\_1 \cdot \left(1 - ux\right)}\\
\end{array}
\end{array}
if (sqrt.f32 (-.f32 #s(literal 1 binary32) (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))))) < 0.023Initial program 38.3%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3236.3
Applied rewrites36.3%
Taylor expanded in ux around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3279.4
Applied rewrites79.4%
if 0.023 < (sqrt.f32 (-.f32 #s(literal 1 binary32) (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))))) Initial program 89.0%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3274.6
Applied rewrites74.6%
Taylor expanded in maxCos around 0
lower--.f3271.5
Applied rewrites71.5%
Final simplification76.2%
(FPCore (ux uy maxCos)
:precision binary32
(*
(* (* (PI) 2.0) uy)
(sqrt
(-
(* (- (/ (- 2.0 maxCos) ux) (- 1.0 maxCos)) (* ux ux))
(* (* (fma maxCos ux (- 1.0 ux)) maxCos) ux)))))\begin{array}{l}
\\
\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{\left(\frac{2 - maxCos}{ux} - \left(1 - maxCos\right)\right) \cdot \left(ux \cdot ux\right) - \left(\mathsf{fma}\left(maxCos, ux, 1 - ux\right) \cdot maxCos\right) \cdot ux}
\end{array}
Initial program 58.9%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3251.9
Applied rewrites51.9%
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
lift--.f32N/A
lift-*.f32N/A
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
lift--.f32N/A
lift-*.f32N/A
distribute-rgt-inN/A
associate--r+N/A
lower--.f32N/A
Applied rewrites50.5%
Taylor expanded in ux around -inf
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
div-addN/A
lower--.f32N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-/.f32N/A
lower--.f32N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f32N/A
unpow2N/A
lower-*.f3282.2
Applied rewrites82.2%
(FPCore (ux uy maxCos) :precision binary32 (* (* (* (PI) 2.0) uy) (sqrt (* (- 2.0 (fma (* ux (- maxCos 1.0)) (+ -1.0 maxCos) (* 2.0 maxCos))) ux))))
\begin{array}{l}
\\
\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{\left(2 - \mathsf{fma}\left(ux \cdot \left(maxCos - 1\right), -1 + maxCos, 2 \cdot maxCos\right)\right) \cdot ux}
\end{array}
Initial program 58.9%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3251.9
Applied rewrites51.9%
lift-*.f32N/A
lift-+.f32N/A
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
lift--.f32N/A
lift-*.f32N/A
lift--.f32N/A
lift-*.f32N/A
lift-+.f32N/A
lift--.f32N/A
lift-*.f32N/A
distribute-lft-inN/A
Applied rewrites51.2%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
Applied rewrites82.2%
(FPCore (ux uy maxCos) :precision binary32 (* (* (* (PI) 2.0) uy) (sqrt (* (* (- (/ 2.0 ux) 1.0) ux) ux))))
\begin{array}{l}
\\
\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{\left(\left(\frac{2}{ux} - 1\right) \cdot ux\right) \cdot ux}
\end{array}
Initial program 58.9%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3251.9
Applied rewrites51.9%
Taylor expanded in ux around inf
*-commutativeN/A
Applied rewrites82.2%
Taylor expanded in maxCos around 0
Applied rewrites78.0%
Final simplification78.0%
(FPCore (ux uy maxCos) :precision binary32 (* (* (* (PI) 2.0) uy) (sqrt (* (fma -2.0 maxCos 2.0) ux))))
\begin{array}{l}
\\
\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}
\end{array}
Initial program 58.9%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3251.9
Applied rewrites51.9%
Taylor expanded in ux around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3266.8
Applied rewrites66.8%
Final simplification66.8%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (- 1.0 1.0)) (* 2.0 (PI))))
\begin{array}{l}
\\
\sqrt{1 - 1} \cdot \left(2 \cdot \mathsf{PI}\left(\right)\right)
\end{array}
Initial program 58.9%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3251.9
Applied rewrites51.9%
Taylor expanded in ux around 0
Applied rewrites7.1%
Applied rewrites7.1%
lift-*.f32N/A
*-commutativeN/A
lower-*.f327.1
Applied rewrites7.1%
herbie shell --seed 2024359
(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)))))))