
(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 (* (* uy 2.0) (PI))) (sqrt (* (- (- 2.0 (+ (* ux (pow (- maxCos 1.0) 2.0)) maxCos)) maxCos) ux))))
\begin{array}{l}
\\
\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(\left(2 - \left(ux \cdot {\left(maxCos - 1\right)}^{2} + maxCos\right)\right) - maxCos\right) \cdot ux}
\end{array}
Initial program 54.9%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower-/.f3256.3
Applied rewrites56.3%
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-*.f3298.6
Applied rewrites98.6%
Applied rewrites98.6%
Applied rewrites98.6%
Final simplification98.6%
(FPCore (ux uy maxCos) :precision binary32 (* (sin (* (* uy 2.0) (PI))) (sqrt (* (- (- (- 2.0 (* ux (pow (- maxCos 1.0) 2.0))) maxCos) maxCos) ux))))
\begin{array}{l}
\\
\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\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 54.9%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower-/.f3256.3
Applied rewrites56.3%
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-*.f3298.6
Applied rewrites98.6%
Applied rewrites98.6%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (sin (* (* uy 2.0) (PI)))))
(if (<= maxCos 4.200000069953802e-11)
(* t_0 (sqrt (* (- 2.0 ux) ux)))
(*
t_0
(sqrt
(*
(-
(*
(-
(- (/ 2.0 (* maxCos maxCos)) ux)
(+ (/ (/ ux maxCos) maxCos) (/ (fma -2.0 ux 1.0) maxCos)))
(* maxCos maxCos))
maxCos)
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 4.200000069953802 \cdot 10^{-11}:\\
\;\;\;\;t\_0 \cdot \sqrt{\left(2 - ux\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sqrt{\left(\left(\left(\frac{2}{maxCos \cdot maxCos} - ux\right) - \left(\frac{\frac{ux}{maxCos}}{maxCos} + \frac{\mathsf{fma}\left(-2, ux, 1\right)}{maxCos}\right)\right) \cdot \left(maxCos \cdot maxCos\right) - maxCos\right) \cdot ux}\\
\end{array}
\end{array}
if maxCos < 4.20000007e-11Initial program 55.9%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower-/.f3257.4
Applied rewrites57.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-*.f3298.6
Applied rewrites98.6%
Taylor expanded in maxCos around 0
Applied rewrites98.6%
if 4.20000007e-11 < maxCos Initial program 52.1%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower-/.f3253.3
Applied rewrites53.3%
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-*.f3298.5
Applied rewrites98.5%
Applied rewrites98.6%
Taylor expanded in maxCos around inf
Applied rewrites71.6%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (sin (* (* uy 2.0) (PI)))))
(if (<= maxCos 3.9999998989515007e-5)
(* t_0 (sqrt (* (- 2.0 ux) ux)))
(* t_0 (sqrt (* (- (- 2.0 maxCos) maxCos) 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 3.9999998989515007 \cdot 10^{-5}:\\
\;\;\;\;t\_0 \cdot \sqrt{\left(2 - ux\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sqrt{\left(\left(2 - maxCos\right) - maxCos\right) \cdot ux}\\
\end{array}
\end{array}
if maxCos < 3.9999999e-5Initial program 55.6%
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
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-*.f3298.6
Applied rewrites98.6%
Taylor expanded in maxCos around 0
Applied rewrites98.1%
if 3.9999999e-5 < maxCos Initial program 49.2%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower-/.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-*.f3298.3
Applied rewrites98.3%
Applied rewrites98.5%
Taylor expanded in ux around 0
Applied rewrites82.4%
(FPCore (ux uy maxCos) :precision binary32 (* (sin (* (* uy 2.0) (PI))) (sqrt (* (- (- 2.0 ux) maxCos) ux))))
\begin{array}{l}
\\
\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(\left(2 - ux\right) - maxCos\right) \cdot ux}
\end{array}
Initial program 54.9%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower-/.f3256.3
Applied rewrites56.3%
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-*.f3298.6
Applied rewrites98.6%
Applied rewrites98.6%
Taylor expanded in maxCos around 0
Applied rewrites93.4%
(FPCore (ux uy maxCos) :precision binary32 (* (sin (* (* uy 2.0) (PI))) (sqrt (* (- 2.0 ux) 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}
\end{array}
Initial program 54.9%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower-/.f3256.3
Applied rewrites56.3%
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-*.f3298.6
Applied rewrites98.6%
Taylor expanded in maxCos around 0
Applied rewrites93.0%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos))) (t_1 (* (* (PI) 2.0) uy)))
(if (<= (* t_0 t_0) 0.999779999256134)
(* t_1 (sqrt (- 1.0 (* (- 1.0 (- ux (* maxCos ux))) t_0))))
(* t_1 (sqrt (* (- 2.0 (* maxCos 2.0)) ux))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
t_1 := \left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\\
\mathbf{if}\;t\_0 \cdot t\_0 \leq 0.999779999256134:\\
\;\;\;\;t\_1 \cdot \sqrt{1 - \left(1 - \left(ux - maxCos \cdot ux\right)\right) \cdot t\_0}\\
\mathbf{else}:\\
\;\;\;\;t\_1 \cdot \sqrt{\left(2 - maxCos \cdot 2\right) \cdot ux}\\
\end{array}
\end{array}
if (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) < 0.999779999Initial program 88.6%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3274.5
Applied rewrites74.5%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lower--.f3274.6
lift-*.f32N/A
*-commutativeN/A
lower-*.f3274.6
Applied rewrites74.6%
if 0.999779999 < (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) Initial program 31.9%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3229.2
Applied rewrites29.2%
Taylor expanded in maxCos around 0
lower--.f3229.2
Applied rewrites29.2%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
lower-fma.f3274.2
Applied rewrites73.9%
Applied rewrites78.3%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))
(t_1 (* t_0 t_0))
(t_2 (* (* (PI) 2.0) uy)))
(if (<= t_1 0.999779999256134)
(* t_2 (sqrt (- 1.0 t_1)))
(* t_2 (sqrt (* (- 2.0 (* maxCos 2.0)) ux))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
t_1 := t\_0 \cdot t\_0\\
t_2 := \left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\\
\mathbf{if}\;t\_1 \leq 0.999779999256134:\\
\;\;\;\;t\_2 \cdot \sqrt{1 - t\_1}\\
\mathbf{else}:\\
\;\;\;\;t\_2 \cdot \sqrt{\left(2 - maxCos \cdot 2\right) \cdot ux}\\
\end{array}
\end{array}
if (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) < 0.999779999Initial program 88.6%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3274.5
Applied rewrites74.5%
if 0.999779999 < (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) Initial program 31.9%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3229.2
Applied rewrites29.2%
Taylor expanded in maxCos around 0
lower--.f3229.2
Applied rewrites29.2%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
lower-fma.f3274.2
Applied rewrites73.9%
Applied rewrites78.3%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos))) (t_1 (* (* (PI) 2.0) uy)))
(if (<= (* t_0 t_0) 0.9990000128746033)
(* t_1 (sqrt (- 1.0 (* t_0 (- 1.0 ux)))))
(* t_1 (sqrt (* (- 2.0 (* maxCos 2.0)) ux))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
t_1 := \left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\\
\mathbf{if}\;t\_0 \cdot t\_0 \leq 0.9990000128746033:\\
\;\;\;\;t\_1 \cdot \sqrt{1 - t\_0 \cdot \left(1 - ux\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_1 \cdot \sqrt{\left(2 - maxCos \cdot 2\right) \cdot ux}\\
\end{array}
\end{array}
if (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) < 0.999000013Initial program 90.3%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3275.3
Applied rewrites75.3%
Taylor expanded in maxCos around 0
lower--.f3273.4
Applied rewrites73.4%
if 0.999000013 < (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) Initial program 34.7%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3231.8
Applied rewrites31.8%
Taylor expanded in maxCos around 0
lower--.f3231.4
Applied rewrites31.4%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
lower-fma.f3273.1
Applied rewrites72.8%
Applied rewrites77.3%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos))) (t_1 (* (* (PI) 2.0) uy)))
(if (<= (* t_0 t_0) 0.9990000128746033)
(* t_1 (sqrt (- 1.0 (* (- 1.0 ux) (- 1.0 ux)))))
(* t_1 (sqrt (* (- 2.0 (* maxCos 2.0)) ux))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
t_1 := \left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\\
\mathbf{if}\;t\_0 \cdot t\_0 \leq 0.9990000128746033:\\
\;\;\;\;t\_1 \cdot \sqrt{1 - \left(1 - ux\right) \cdot \left(1 - ux\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_1 \cdot \sqrt{\left(2 - maxCos \cdot 2\right) \cdot ux}\\
\end{array}
\end{array}
if (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) < 0.999000013Initial program 90.3%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3275.3
Applied rewrites75.3%
Taylor expanded in maxCos around 0
lower--.f3273.4
Applied rewrites73.4%
Taylor expanded in maxCos around 0
lower--.f3273.3
Applied rewrites73.3%
if 0.999000013 < (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) Initial program 34.7%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3231.8
Applied rewrites31.8%
Taylor expanded in maxCos around 0
lower--.f3231.4
Applied rewrites31.4%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
lower-fma.f3273.1
Applied rewrites72.8%
Applied rewrites77.3%
(FPCore (ux uy maxCos) :precision binary32 (* (* (* (PI) 2.0) uy) (sqrt (* (- 2.0 (* maxCos 2.0)) ux))))
\begin{array}{l}
\\
\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{\left(2 - maxCos \cdot 2\right) \cdot ux}
\end{array}
Initial program 54.9%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3247.6
Applied rewrites47.6%
Taylor expanded in maxCos around 0
lower--.f3246.7
Applied rewrites46.7%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
lower-fma.f3263.1
Applied rewrites56.2%
Applied rewrites65.9%
(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 54.9%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3247.6
Applied rewrites47.6%
Taylor expanded in maxCos around 0
lower--.f3246.7
Applied rewrites46.7%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
lower-fma.f3263.1
Applied rewrites55.9%
Taylor expanded in maxCos around 0
Applied rewrites63.1%
herbie shell --seed 2024347
(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)))))))