
(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
(*
(sin (* (* uy 2.0) (PI)))
(sqrt
(*
(-
(* ux (fma -1.0 (pow (- maxCos 1.0) 2.0) (* 2.0 (/ 1.0 ux))))
(* maxCos 2.0))
ux))))\begin{array}{l}
\\
\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(ux \cdot \mathsf{fma}\left(-1, {\left(maxCos - 1\right)}^{2}, 2 \cdot \frac{1}{ux}\right) - maxCos \cdot 2\right) \cdot ux}
\end{array}
Initial program 54.2%
Taylor expanded in ux around 0
Applied rewrites98.2%
Taylor expanded in ux around inf
Applied rewrites98.2%
(FPCore (ux uy maxCos)
:precision binary32
(*
(sin (* (* uy 2.0) (PI)))
(sqrt
(*
(*
(-
(fma (/ maxCos ux) -2.0 (fma (fma -1.0 maxCos 2.0) 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{\left(\left(\mathsf{fma}\left(\frac{maxCos}{ux}, -2, \mathsf{fma}\left(\mathsf{fma}\left(-1, maxCos, 2\right), maxCos, \frac{2}{ux}\right)\right) - 1\right) \cdot ux\right) \cdot ux}
\end{array}
Initial program 54.2%
Taylor expanded in ux around 0
Applied rewrites98.2%
Taylor expanded in ux around inf
Applied rewrites98.2%
Taylor expanded in maxCos around 0
Applied rewrites98.2%
Taylor expanded in ux around inf
Applied rewrites98.2%
(FPCore (ux uy maxCos) :precision binary32 (* (sin (* (* uy 2.0) (PI))) (sqrt (* (+ (fma maxCos (- (* (- ux) (- maxCos 2.0)) 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(\mathsf{fma}\left(maxCos, \left(-ux\right) \cdot \left(maxCos - 2\right) - 2, -ux\right) + 2\right) \cdot ux}
\end{array}
Initial program 54.2%
Taylor expanded in ux around 0
Applied rewrites98.2%
Taylor expanded in ux around inf
Applied rewrites98.2%
Taylor expanded in maxCos around 0
Applied rewrites98.2%
Taylor expanded in ux around -inf
Applied rewrites98.2%
(FPCore (ux uy maxCos) :precision binary32 (* (sin (* (* uy 2.0) (PI))) (sqrt (* (+ (fma maxCos (- (* 2.0 ux) 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(\mathsf{fma}\left(maxCos, 2 \cdot ux - 2, -ux\right) + 2\right) \cdot ux}
\end{array}
Initial program 54.2%
Taylor expanded in ux around 0
Applied rewrites98.2%
Taylor expanded in ux around inf
Applied rewrites98.2%
Taylor expanded in maxCos around 0
Applied rewrites97.5%
(FPCore (ux uy maxCos) :precision binary32 (* (sin (* (* uy 2.0) (PI))) (sqrt (* (- (fma (- (* ux 2.0) 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{\left(\mathsf{fma}\left(ux \cdot 2 - 2, maxCos, 2\right) - ux\right) \cdot ux}
\end{array}
Initial program 54.2%
Taylor expanded in ux around 0
Applied rewrites98.2%
Taylor expanded in ux around inf
Applied rewrites98.2%
Taylor expanded in maxCos around 0
Applied rewrites98.2%
Taylor expanded in maxCos around 0
Applied rewrites97.5%
(FPCore (ux uy maxCos) :precision binary32 (* (sin (* (* uy 2.0) (PI))) (sqrt (* (+ (fma maxCos -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(\mathsf{fma}\left(maxCos, -2, -ux\right) + 2\right) \cdot ux}
\end{array}
Initial program 54.2%
Taylor expanded in ux around 0
Applied rewrites98.2%
Taylor expanded in ux around inf
Applied rewrites98.2%
Taylor expanded in maxCos around 0
Applied rewrites98.2%
Taylor expanded in ux around 0
Applied rewrites96.9%
(FPCore (ux uy maxCos) :precision binary32 (if (<= uy 0.0024999999441206455) (* (* 2.0 (* uy (PI))) (sqrt (* (- 2.0 ux) ux))) (* (sin (* (* uy 2.0) (PI))) (sqrt (* 2.0 ux)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \leq 0.0024999999441206455:\\
\;\;\;\;\left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sqrt{\left(2 - ux\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{2 \cdot ux}\\
\end{array}
\end{array}
if uy < 0.00249999994Initial program 54.7%
Taylor expanded in ux around 0
Applied rewrites98.5%
Taylor expanded in maxCos around 0
Applied rewrites93.4%
Taylor expanded in uy around 0
Applied rewrites91.1%
if 0.00249999994 < uy Initial program 53.0%
Taylor expanded in ux around 0
Applied rewrites97.5%
Taylor expanded in maxCos around 0
Applied rewrites91.7%
Taylor expanded in ux around 0
Applied rewrites75.1%
Final simplification86.1%
(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.2%
Taylor expanded in ux around 0
Applied rewrites98.2%
Taylor expanded in ux around inf
Applied rewrites98.2%
Taylor expanded in maxCos around 0
Applied rewrites98.2%
Taylor expanded in maxCos around 0
Applied rewrites92.9%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (* 2.0 (* uy (PI)))))
(if (<= maxCos 7.99999974612418e-20)
(* t_0 (sqrt (* (- 2.0 ux) ux)))
(*
t_0
(sqrt
(*
(-
(*
(* maxCos maxCos)
(fma
-1.0
ux
(fma
-1.0
(/ ux (* maxCos maxCos))
(fma 2.0 (/ ux maxCos) (/ 2.0 (* maxCos maxCos))))))
(* maxCos 2.0))
ux))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := 2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\\
\mathbf{if}\;maxCos \leq 7.99999974612418 \cdot 10^{-20}:\\
\;\;\;\;t\_0 \cdot \sqrt{\left(2 - ux\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sqrt{\left(\left(maxCos \cdot maxCos\right) \cdot \mathsf{fma}\left(-1, ux, \mathsf{fma}\left(-1, \frac{ux}{maxCos \cdot maxCos}, \mathsf{fma}\left(2, \frac{ux}{maxCos}, \frac{2}{maxCos \cdot maxCos}\right)\right)\right) - maxCos \cdot 2\right) \cdot ux}\\
\end{array}
\end{array}
if maxCos < 7.99999975e-20Initial program 55.8%
Taylor expanded in ux around 0
Applied rewrites98.6%
Taylor expanded in maxCos around 0
Applied rewrites98.6%
Taylor expanded in uy around 0
Applied rewrites81.8%
if 7.99999975e-20 < maxCos Initial program 52.8%
Taylor expanded in ux around 0
Applied rewrites97.9%
Taylor expanded in maxCos around inf
Applied rewrites98.0%
Taylor expanded in uy around 0
Applied rewrites76.8%
Final simplification79.1%
(FPCore (ux uy maxCos) :precision binary32 (* (* 2.0 (* uy (PI))) (sqrt (* (- 2.0 ux) ux))))
\begin{array}{l}
\\
\left(2 \cdot \left(uy \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \sqrt{\left(2 - ux\right) \cdot ux}
\end{array}
Initial program 54.2%
Taylor expanded in ux around 0
Applied rewrites98.2%
Taylor expanded in maxCos around 0
Applied rewrites92.9%
Taylor expanded in uy around 0
Applied rewrites75.8%
Final simplification75.8%
(FPCore (ux uy maxCos) :precision binary32 (* (* (PI) (+ uy uy)) (sqrt (- 1.0 1.0))))
\begin{array}{l}
\\
\left(\mathsf{PI}\left(\right) \cdot \left(uy + uy\right)\right) \cdot \sqrt{1 - 1}
\end{array}
Initial program 54.2%
Taylor expanded in uy around 0
Applied rewrites46.9%
Taylor expanded in ux around 0
Applied rewrites7.1%
Applied rewrites7.1%
herbie shell --seed 2025026
(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)))))))