
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (- (log (- 1.0 u1)))) (sin (* (* 2.0 (PI)) u2))))
\begin{array}{l}
\\
\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (- (log (- 1.0 u1)))) (sin (* (* 2.0 (PI)) u2))))
\begin{array}{l}
\\
\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (- 1.0 u1) 0.9965999722480774) (* (sqrt (- (log (- 1.0 u1)))) (sin (* (PI) (+ u2 u2)))) (* (sqrt (* (+ (* 0.5 u1) 1.0) u1)) (sin (* u2 (+ (PI) (PI)))))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - u1 \leq 0.9965999722480774:\\
\;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \left(u2 + u2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(0.5 \cdot u1 + 1\right) \cdot u1} \cdot \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right)\right)\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.996599972Initial program 94.4%
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
lift-PI.f32N/A
add-cube-cbrtN/A
associate-*l*N/A
associate-*l*N/A
lower-*.f32N/A
pow2N/A
lower-pow.f32N/A
lift-PI.f32N/A
lower-cbrt.f32N/A
lower-*.f32N/A
lower-*.f32N/A
lift-PI.f32N/A
lower-cbrt.f3294.1
Applied rewrites94.1%
lift-*.f32N/A
lift-*.f32N/A
associate-*r*N/A
lift-*.f32N/A
associate-*r*N/A
lift-pow.f32N/A
unpow2N/A
pow3N/A
lift-cbrt.f32N/A
rem-cube-cbrtN/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
count-2N/A
lift-*.f32N/A
lift-*.f32N/A
distribute-rgt-outN/A
lower-*.f32N/A
lower-+.f3294.4
Applied rewrites94.4%
if 0.996599972 < (-.f32 #s(literal 1 binary32) u1) Initial program 41.1%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3289.5
Applied rewrites89.5%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3241.9
Applied rewrites43.9%
Applied rewrites98.2%
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
associate-*l*N/A
count-2N/A
distribute-rgt-inN/A
distribute-lft-outN/A
lower-*.f32N/A
lower-+.f3298.2
Applied rewrites98.2%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (* (+ (* 0.5 u1) 1.0) u1)) (sin (* u2 (+ (PI) (PI))))))
\begin{array}{l}
\\
\sqrt{\left(0.5 \cdot u1 + 1\right) \cdot u1} \cdot \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right)\right)
\end{array}
Initial program 54.2%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3278.6
Applied rewrites78.6%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3237.2
Applied rewrites37.3%
Applied rewrites88.8%
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
associate-*l*N/A
count-2N/A
distribute-rgt-inN/A
distribute-lft-outN/A
lower-*.f32N/A
lower-+.f3288.8
Applied rewrites88.8%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sin (* (* (PI) 2.0) u2)) (sqrt u1)))
\begin{array}{l}
\\
\sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right) \cdot \sqrt{u1}
\end{array}
Initial program 54.2%
Applied rewrites36.7%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-sin.f32N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-sqrt.f3278.6
Applied rewrites78.6%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (* (* (sqrt u1) (PI)) 2.0) u2))
\begin{array}{l}
\\
\left(\left(\sqrt{u1} \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right) \cdot u2
\end{array}
Initial program 54.2%
Applied rewrites37.9%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-sin.f32N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-sqrt.f3278.6
Applied rewrites78.6%
Taylor expanded in u2 around 0
Applied rewrites68.0%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (* u2 (sqrt u1)) (* (PI) 2.0)))
\begin{array}{l}
\\
\left(u2 \cdot \sqrt{u1}\right) \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)
\end{array}
Initial program 54.2%
Applied rewrites38.1%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-sin.f32N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-sqrt.f3278.6
Applied rewrites78.6%
Taylor expanded in u2 around 0
Applied rewrites68.0%
Applied rewrites67.9%
herbie shell --seed 2024302
(FPCore (cosTheta_i u1 u2)
:name "Beckmann Sample, near normal, slope_y"
:precision binary32
:pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0)) (and (<= 2.328306437e-10 u1) (<= u1 1.0))) (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
(* (sqrt (- (log (- 1.0 u1)))) (sin (* (* 2.0 (PI)) u2))))