
(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 13 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 (* (* (- (/ (fma -2.0 maxCos 2.0) ux) (pow (- maxCos 1.0) 2.0)) ux) ux))))
\begin{array}{l}
\\
\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(\left(\frac{\mathsf{fma}\left(-2, maxCos, 2\right)}{ux} - {\left(maxCos - 1\right)}^{2}\right) \cdot ux\right) \cdot ux}
\end{array}
Initial program 57.1%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
associate--r+N/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
div-subN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3298.4
Applied rewrites98.4%
Applied rewrites98.4%
(FPCore (ux uy maxCos)
:precision binary32
(*
(sin (* (* uy 2.0) (PI)))
(sqrt
(fma
(- (* (- 2.0 (/ 2.0 ux)) (* ux ux)) (* (* ux ux) maxCos))
maxCos
(* (- (/ 2.0 ux) 1.0) (* ux ux))))))\begin{array}{l}
\\
\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\mathsf{fma}\left(\left(2 - \frac{2}{ux}\right) \cdot \left(ux \cdot ux\right) - \left(ux \cdot ux\right) \cdot maxCos, maxCos, \left(\frac{2}{ux} - 1\right) \cdot \left(ux \cdot ux\right)\right)}
\end{array}
Initial program 57.1%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
associate--r+N/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
div-subN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3298.4
Applied rewrites98.4%
Taylor expanded in maxCos around 0
Applied rewrites98.4%
(FPCore (ux uy maxCos) :precision binary32 (* (sin (* (* uy 2.0) (PI))) (sqrt (* (- (fma (- maxCos 1.0) (fma (- 1.0 maxCos) ux -1.0) 1.0) maxCos) ux))))
\begin{array}{l}
\\
\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(\mathsf{fma}\left(maxCos - 1, \mathsf{fma}\left(1 - maxCos, ux, -1\right), 1\right) - maxCos\right) \cdot ux}
\end{array}
Initial program 57.1%
lift--.f32N/A
lift-*.f32N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
lower-neg.f3257.3
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f3257.3
Applied rewrites57.3%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
Applied rewrites98.4%
Final simplification98.4%
(FPCore (ux uy maxCos) :precision binary32 (* (sin (* (* uy 2.0) (PI))) (sqrt (* (fma (- (* 2.0 ux) 2.0) 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(2 \cdot ux - 2, maxCos, 2 - ux\right) \cdot ux}
\end{array}
Initial program 57.1%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
associate--r+N/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
div-subN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3298.4
Applied rewrites98.4%
Applied rewrites98.4%
Taylor expanded in ux around 0
Applied rewrites98.4%
Taylor expanded in maxCos around 0
Applied rewrites97.9%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= uy 0.00010895000013988465)
(*
(* (* (PI) 2.0) uy)
(sqrt
(-
(* (+ (- (/ (fma -1.0 maxCos 2.0) ux) 1.0) maxCos) (* ux ux))
(* (* (fma maxCos ux (- 1.0 ux)) maxCos) ux))))
(* (sin (* (* uy 2.0) (PI))) (sqrt (* (- 2.0 ux) ux)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \leq 0.00010895000013988465:\\
\;\;\;\;\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{\left(\left(\frac{\mathsf{fma}\left(-1, maxCos, 2\right)}{ux} - 1\right) + maxCos\right) \cdot \left(ux \cdot ux\right) - \left(\mathsf{fma}\left(maxCos, ux, 1 - ux\right) \cdot maxCos\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(2 - ux\right) \cdot ux}\\
\end{array}
\end{array}
if uy < 1.0895e-4Initial program 57.8%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3257.8
Applied rewrites57.8%
Applied rewrites56.2%
Taylor expanded in ux around -inf
*-commutativeN/A
lower-*.f32N/A
associate--r+N/A
lower--.f32N/A
+-commutativeN/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
div-addN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-fma.f32N/A
mul-1-negN/A
lower-neg.f32N/A
unpow2N/A
lower-*.f3298.7
Applied rewrites98.7%
if 1.0895e-4 < uy Initial program 56.0%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
associate--r+N/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
div-subN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3297.9
Applied rewrites97.9%
Applied rewrites98.0%
Taylor expanded in ux around 0
Applied rewrites97.9%
Taylor expanded in maxCos around 0
Applied rewrites93.9%
Final simplification96.8%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (* (* (PI) 2.0) uy))
(t_1 (+ (- 1.0 ux) (* ux maxCos)))
(t_2 (fma maxCos ux (- 1.0 ux))))
(if (<= (sqrt (- 1.0 (* t_1 t_1))) 0.019999999552965164)
(* t_0 (sqrt (* (fma -2.0 maxCos 2.0) ux)))
(* t_0 (sqrt (fma t_2 (- t_2) 1.0))))))\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\\
t_2 := \mathsf{fma}\left(maxCos, ux, 1 - ux\right)\\
\mathbf{if}\;\sqrt{1 - t\_1 \cdot t\_1} \leq 0.019999999552965164:\\
\;\;\;\;t\_0 \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sqrt{\mathsf{fma}\left(t\_2, -t\_2, 1\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.0199999996Initial program 38.0%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3234.7
Applied rewrites34.7%
Applied rewrites32.2%
Taylor expanded in ux around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3277.2
Applied rewrites77.2%
if 0.0199999996 < (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.4%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3279.6
Applied rewrites79.6%
lift--.f32N/A
lift-*.f32N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift--.f32N/A
lift--.f32N/A
lower-fma.f32N/A
lower-neg.f3280.0
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lift--.f32N/A
lift--.f32N/A
lower-fma.f3280.0
Applied rewrites80.0%
Final simplification78.3%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos))))
(if (<= (sqrt (- 1.0 (* t_0 t_0))) 0.019999999552965164)
(* (* (* (PI) 2.0) uy) (sqrt (* (fma -2.0 maxCos 2.0) ux)))
(*
(* (* (PI) uy) 2.0)
(sqrt
(fma (- ux (fma maxCos ux 1.0)) (- (fma maxCos ux 1.0) ux) 1.0))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
\mathbf{if}\;\sqrt{1 - t\_0 \cdot t\_0} \leq 0.019999999552965164:\\
\;\;\;\;\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right) \cdot \sqrt{\mathsf{fma}\left(ux - \mathsf{fma}\left(maxCos, ux, 1\right), \mathsf{fma}\left(maxCos, ux, 1\right) - ux, 1\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.0199999996Initial program 38.0%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3234.7
Applied rewrites34.7%
Applied rewrites32.2%
Taylor expanded in ux around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3277.2
Applied rewrites77.2%
if 0.0199999996 < (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.4%
lift--.f32N/A
lift-*.f32N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f32N/A
lower-neg.f3289.9
lift-+.f32N/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f3289.9
Applied rewrites89.9%
Taylor expanded in uy around 0
associate-*r*N/A
count-2-revN/A
distribute-lft-inN/A
count-2-revN/A
lower-*.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.f32N/A
lower-sqrt.f32N/A
+-commutativeN/A
lower-fma.f32N/A
Applied rewrites79.8%
Final simplification78.2%
(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.9995999932289124)
(* t_1 (sqrt (- 1.0 (* t_0 (- 1.0 ux)))))
(* t_1 (sqrt (* (fma -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.9995999932289124:\\
\;\;\;\;t\_1 \cdot \sqrt{1 - t\_0 \cdot \left(1 - ux\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_1 \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 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.999599993Initial program 89.4%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3279.6
Applied rewrites79.6%
Taylor expanded in maxCos around 0
lower--.f3277.0
Applied rewrites77.0%
if 0.999599993 < (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) Initial program 38.0%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3234.7
Applied rewrites34.7%
Applied rewrites32.2%
Taylor expanded in ux around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3277.2
Applied rewrites77.2%
Final simplification77.2%
(FPCore (ux uy maxCos)
:precision binary32
(*
(* (* (PI) 2.0) uy)
(sqrt
(-
(* (+ (- (/ (fma -1.0 maxCos 2.0) 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(\left(\frac{\mathsf{fma}\left(-1, maxCos, 2\right)}{ux} - 1\right) + maxCos\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 57.1%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3251.4
Applied rewrites51.4%
Applied rewrites49.8%
Taylor expanded in ux around -inf
*-commutativeN/A
lower-*.f32N/A
associate--r+N/A
lower--.f32N/A
+-commutativeN/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
div-addN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-fma.f32N/A
mul-1-negN/A
lower-neg.f32N/A
unpow2N/A
lower-*.f3283.1
Applied rewrites83.1%
Final simplification83.1%
(FPCore (ux uy maxCos)
:precision binary32
(*
(* (* (PI) 2.0) uy)
(sqrt
(-
(* (- (fma (- maxCos 1.0) ux 2.0) maxCos) 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(\mathsf{fma}\left(maxCos - 1, ux, 2\right) - maxCos\right) \cdot ux - \left(\mathsf{fma}\left(maxCos, ux, 1 - ux\right) \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.f3251.4
Applied rewrites51.4%
Applied rewrites49.8%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower--.f3283.1
Applied rewrites83.1%
(FPCore (ux uy maxCos)
:precision binary32
(*
(* (* (PI) 2.0) uy)
(sqrt
(*
(- (fma (- ux) (* (- maxCos 1.0) (+ -1.0 maxCos)) 2.0) (* 2.0 maxCos))
ux))))\begin{array}{l}
\\
\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{\left(\mathsf{fma}\left(-ux, \left(maxCos - 1\right) \cdot \left(-1 + maxCos\right), 2\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.f3251.4
Applied rewrites51.4%
Applied rewrites49.8%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
associate-*r*N/A
mul-1-negN/A
lower-fma.f32N/A
lower-neg.f32N/A
distribute-rgt-outN/A
lower-*.f32N/A
lower--.f32N/A
lower-+.f32N/A
lower-*.f3283.0
Applied rewrites83.0%
Final simplification83.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 57.1%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3251.4
Applied rewrites51.4%
Applied rewrites49.8%
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.7
Applied rewrites66.7%
Final simplification66.7%
(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.f3251.4
Applied rewrites51.4%
Taylor expanded in ux around 0
Applied rewrites7.2%
Applied rewrites7.2%
herbie shell --seed 2024352
(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)))))))