
(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 11 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
(let* ((t_0 (sin (* (* (PI) 2.0) u2))))
(if (<= u1 0.00019999999494757503)
(* (pow (* u1 u1) 0.25) t_0)
(* t_0 (sqrt (- (log (- 1.0 u1))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)\\
\mathbf{if}\;u1 \leq 0.00019999999494757503:\\
\;\;\;\;{\left(u1 \cdot u1\right)}^{0.25} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sqrt{-\log \left(1 - u1\right)}\\
\end{array}
\end{array}
if u1 < 1.99999995e-4Initial program 37.0%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3292.6
Applied rewrites92.6%
lift-sqrt.f32N/A
pow1/2N/A
metadata-evalN/A
pow-sqrN/A
pow-prod-downN/A
lower-pow.f32N/A
lower-*.f3292.6
Applied rewrites92.6%
Taylor expanded in u1 around 0
unpow2N/A
lower-*.f3292.6
Applied rewrites92.6%
if 1.99999995e-4 < u1 Initial program 90.0%
Final simplification91.5%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (sin (* (* (PI) 2.0) u2))))
(if (<= (- 1.0 u1) 0.9959999918937683)
(* t_0 (sqrt (- (log (- 1.0 u1)))))
(if (<= (- 1.0 u1) 0.9999998211860657)
(*
(sqrt
(-
(* (/ (- 1.0 (* 0.25 (* u1 u1))) (- 1.0 (* -0.5 u1))) u1)
(log1p (* (- u1) u1))))
t_0)
(* (sqrt (/ -1.0 (/ 1.0 (log1p (- u1))))) t_0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)\\
\mathbf{if}\;1 - u1 \leq 0.9959999918937683:\\
\;\;\;\;t\_0 \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{elif}\;1 - u1 \leq 0.9999998211860657:\\
\;\;\;\;\sqrt{\frac{1 - 0.25 \cdot \left(u1 \cdot u1\right)}{1 - -0.5 \cdot u1} \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{-1}{\frac{1}{\mathsf{log1p}\left(-u1\right)}}} \cdot t\_0\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.995999992Initial program 95.0%
if 0.995999992 < (-.f32 #s(literal 1 binary32) u1) < 0.999999821Initial program 65.5%
Applied rewrites34.3%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3219.4
Applied rewrites13.7%
Applied rewrites58.5%
if 0.999999821 < (-.f32 #s(literal 1 binary32) u1) Initial program 15.3%
Applied rewrites44.8%
lift--.f32N/A
lift-log1p.f32N/A
lift-log1p.f32N/A
diff-logN/A
lift-*.f32N/A
lift-neg.f32N/A
cancel-sign-sub-invN/A
metadata-evalN/A
flip-+N/A
lift--.f32N/A
associate-/l/N/A
log-divN/A
metadata-evalN/A
cancel-sign-sub-invN/A
lift-neg.f32N/A
lift-*.f32N/A
lift-log1p.f32N/A
Applied rewrites11.0%
Applied rewrites48.4%
Final simplification62.7%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (sin (* (* (PI) 2.0) u2))))
(if (<= (- 1.0 u1) 0.9959999918937683)
(* t_0 (sqrt (- (log (- 1.0 u1)))))
(if (<= (- 1.0 u1) 0.9999998211860657)
(*
(sqrt (- (* (* (- (/ 1.0 u1) 0.5) u1) u1) (log1p (* (- u1) u1))))
t_0)
(* (sqrt (/ -1.0 (/ 1.0 (log1p (- u1))))) t_0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)\\
\mathbf{if}\;1 - u1 \leq 0.9959999918937683:\\
\;\;\;\;t\_0 \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{elif}\;1 - u1 \leq 0.9999998211860657:\\
\;\;\;\;\sqrt{\left(\left(\frac{1}{u1} - 0.5\right) \cdot u1\right) \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{-1}{\frac{1}{\mathsf{log1p}\left(-u1\right)}}} \cdot t\_0\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.995999992Initial program 95.0%
if 0.995999992 < (-.f32 #s(literal 1 binary32) u1) < 0.999999821Initial program 65.5%
Applied rewrites35.9%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3212.1
Applied rewrites16.0%
Taylor expanded in u1 around inf
Applied rewrites53.9%
if 0.999999821 < (-.f32 #s(literal 1 binary32) u1) Initial program 15.3%
Applied rewrites43.5%
lift--.f32N/A
lift-log1p.f32N/A
lift-log1p.f32N/A
diff-logN/A
lift-*.f32N/A
lift-neg.f32N/A
cancel-sign-sub-invN/A
metadata-evalN/A
flip-+N/A
lift--.f32N/A
associate-/l/N/A
log-divN/A
metadata-evalN/A
cancel-sign-sub-invN/A
lift-neg.f32N/A
lift-*.f32N/A
lift-log1p.f32N/A
Applied rewrites10.9%
Applied rewrites49.5%
Final simplification63.3%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (sin (* (* (PI) 2.0) u2))))
(if (<= (- 1.0 u1) 0.9959999918937683)
(* t_0 (sqrt (- (log (- 1.0 u1)))))
(if (<= (- 1.0 u1) 0.9999998211860657)
(* (sqrt (- (* (+ (* -0.5 u1) 1.0) u1) (log1p (* (- u1) u1)))) t_0)
(* (sqrt (/ -1.0 (/ 1.0 (log1p (- u1))))) t_0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)\\
\mathbf{if}\;1 - u1 \leq 0.9959999918937683:\\
\;\;\;\;t\_0 \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{elif}\;1 - u1 \leq 0.9999998211860657:\\
\;\;\;\;\sqrt{\left(-0.5 \cdot u1 + 1\right) \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{-1}{\frac{1}{\mathsf{log1p}\left(-u1\right)}}} \cdot t\_0\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.995999992Initial program 95.0%
if 0.995999992 < (-.f32 #s(literal 1 binary32) u1) < 0.999999821Initial program 65.5%
Applied rewrites35.1%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3218.0
Applied rewrites14.2%
Applied rewrites56.2%
if 0.999999821 < (-.f32 #s(literal 1 binary32) u1) Initial program 15.3%
Applied rewrites46.5%
lift--.f32N/A
lift-log1p.f32N/A
lift-log1p.f32N/A
diff-logN/A
lift-*.f32N/A
lift-neg.f32N/A
cancel-sign-sub-invN/A
metadata-evalN/A
flip-+N/A
lift--.f32N/A
associate-/l/N/A
log-divN/A
metadata-evalN/A
cancel-sign-sub-invN/A
lift-neg.f32N/A
lift-*.f32N/A
lift-log1p.f32N/A
Applied rewrites10.7%
Applied rewrites50.8%
Final simplification65.1%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (sin (* (* (PI) 2.0) u2))))
(if (<= u1 5.000000058430487e-8)
(* (pow (* u1 u1) 0.25) t_0)
(if (<= u1 0.004000000189989805)
(* (sqrt (- (* (+ (* -0.5 u1) 1.0) u1) (log1p (* (- u1) u1)))) t_0)
(* t_0 (sqrt (- (log (- 1.0 u1)))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)\\
\mathbf{if}\;u1 \leq 5.000000058430487 \cdot 10^{-8}:\\
\;\;\;\;{\left(u1 \cdot u1\right)}^{0.25} \cdot t\_0\\
\mathbf{elif}\;u1 \leq 0.004000000189989805:\\
\;\;\;\;\sqrt{\left(-0.5 \cdot u1 + 1\right) \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sqrt{-\log \left(1 - u1\right)}\\
\end{array}
\end{array}
if u1 < 5.00000006e-8Initial program 9.2%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3298.7
Applied rewrites98.7%
lift-sqrt.f32N/A
pow1/2N/A
metadata-evalN/A
pow-sqrN/A
pow-prod-downN/A
lower-pow.f32N/A
lower-*.f3298.8
Applied rewrites98.8%
Taylor expanded in u1 around 0
unpow2N/A
lower-*.f3298.8
Applied rewrites98.8%
if 5.00000006e-8 < u1 < 0.00400000019Initial program 62.3%
Applied rewrites37.2%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3217.5
Applied rewrites16.2%
Applied rewrites51.1%
if 0.00400000019 < u1 Initial program 95.0%
Final simplification65.2%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* (* (PI) 2.0) u2)))
(if (<= (- 1.0 u1) 0.9998000264167786)
(* t_0 (sqrt (- (log (- 1.0 u1)))))
(* (pow (* u1 u1) 0.25) (sin t_0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\\
\mathbf{if}\;1 - u1 \leq 0.9998000264167786:\\
\;\;\;\;t\_0 \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;{\left(u1 \cdot u1\right)}^{0.25} \cdot \sin t\_0\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.999800026Initial program 90.0%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3276.4
Applied rewrites76.4%
if 0.999800026 < (-.f32 #s(literal 1 binary32) u1) Initial program 37.0%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3292.6
Applied rewrites92.6%
lift-sqrt.f32N/A
pow1/2N/A
metadata-evalN/A
pow-sqrN/A
pow-prod-downN/A
lower-pow.f32N/A
lower-*.f3292.6
Applied rewrites92.6%
Taylor expanded in u1 around 0
unpow2N/A
lower-*.f3292.6
Applied rewrites92.6%
Final simplification85.8%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* (* (PI) 2.0) u2)))
(if (<= (- 1.0 u1) 0.9998000264167786)
(* t_0 (sqrt (- (log (- 1.0 u1)))))
(* (sqrt u1) (sin t_0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\\
\mathbf{if}\;1 - u1 \leq 0.9998000264167786:\\
\;\;\;\;t\_0 \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{u1} \cdot \sin t\_0\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.999800026Initial program 90.0%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3276.4
Applied rewrites76.4%
if 0.999800026 < (-.f32 #s(literal 1 binary32) u1) Initial program 37.0%
Applied rewrites18.5%
Taylor expanded in u1 around 0
lower-sqrt.f3292.6
Applied rewrites92.6%
Final simplification85.8%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt u1) (sin (* (* (PI) 2.0) u2))))
\begin{array}{l}
\\
\sqrt{u1} \cdot \sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)
\end{array}
Initial program 59.3%
Applied rewrites15.5%
Taylor expanded in u1 around 0
lower-sqrt.f3275.3
Applied rewrites75.3%
Final simplification75.3%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (* (* u2 (PI)) 2.0) (pow (* u1 u1) 0.25)))
\begin{array}{l}
\\
\left(\left(u2 \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right) \cdot {\left(u1 \cdot u1\right)}^{0.25}
\end{array}
Initial program 59.3%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3275.3
Applied rewrites75.3%
lift-sqrt.f32N/A
pow1/2N/A
metadata-evalN/A
pow-sqrN/A
pow-prod-downN/A
lower-pow.f32N/A
lower-*.f3275.4
Applied rewrites75.4%
Taylor expanded in u1 around 0
unpow2N/A
lower-*.f3275.4
Applied rewrites75.4%
Taylor expanded in u2 around 0
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3265.2
Applied rewrites65.2%
Final simplification65.2%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (- (- u1))) (* (* (PI) 2.0) u2)))
\begin{array}{l}
\\
\sqrt{-\left(-u1\right)} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)
\end{array}
Initial program 59.3%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3275.3
Applied rewrites75.3%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3265.2
Applied rewrites65.2%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (- (sqrt u1)) (* (* (PI) 2.0) u2)))
\begin{array}{l}
\\
\left(-\sqrt{u1}\right) \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)
\end{array}
Initial program 59.3%
Taylor expanded in u1 around 0
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
mul-1-negN/A
lower-neg.f32N/A
lower-sqrt.f324.0
Applied rewrites4.0%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f324.7
Applied rewrites4.7%
herbie shell --seed 2024271
(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))))