
(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 (cbrt (PI))) (t_1 (sqrt (PI))))
(if (<= u1 0.03400000184774399)
(*
(*
(sqrt
(-
(*
(- (* (- (* (- (* -0.25 u1) 0.3333333333333333) u1) 0.5) u1) 1.0)
u1)))
(* (sin (* u2 (PI))) 2.0))
(cos (* (* u2 t_1) t_1)))
(*
(sqrt (- (log (- 1.0 u1))))
(sin (* (pow t_0 2.0) (* (* t_0 u2) 2.0)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\mathsf{PI}\left(\right)}\\
t_1 := \sqrt{\mathsf{PI}\left(\right)}\\
\mathbf{if}\;u1 \leq 0.03400000184774399:\\
\;\;\;\;\left(\sqrt{-\left(\left(\left(-0.25 \cdot u1 - 0.3333333333333333\right) \cdot u1 - 0.5\right) \cdot u1 - 1\right) \cdot u1} \cdot \left(\sin \left(u2 \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right)\right) \cdot \cos \left(\left(u2 \cdot t\_1\right) \cdot t\_1\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left({t\_0}^{2} \cdot \left(\left(t\_0 \cdot u2\right) \cdot 2\right)\right)\\
\end{array}
\end{array}
if u1 < 0.0340000018Initial program 53.5%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
metadata-evalN/A
distribute-lft-neg-inN/A
lower--.f32N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f3298.5
Applied rewrites98.5%
lift-*.f32N/A
lift-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
lift-*.f32N/A
sin-2N/A
lift-sin.f32N/A
lift-cos.f32N/A
associate-*r*N/A
*-commutativeN/A
Applied rewrites98.5%
lift-*.f32N/A
lift-PI.f32N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f32N/A
lift-PI.f32N/A
lower-sqrt.f32N/A
lift-PI.f32N/A
lower-sqrt.f3298.5
Applied rewrites98.5%
if 0.0340000018 < u1 Initial program 96.8%
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.f3297.3
Applied rewrites97.3%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* u2 (PI))) (t_1 (sin t_0)) (t_2 (sqrt (PI))))
(if (<= u1 0.03999999910593033)
(*
(*
(sqrt
(-
(*
(- (* (- (* (- (* -0.25 u1) 0.3333333333333333) u1) 0.5) u1) 1.0)
u1)))
(* t_1 2.0))
(cos (* (* u2 t_2) t_2)))
(* (sqrt (- (log (- 1.0 u1)))) (* (* (cos t_0) t_1) 2.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := u2 \cdot \mathsf{PI}\left(\right)\\
t_1 := \sin t\_0\\
t_2 := \sqrt{\mathsf{PI}\left(\right)}\\
\mathbf{if}\;u1 \leq 0.03999999910593033:\\
\;\;\;\;\left(\sqrt{-\left(\left(\left(-0.25 \cdot u1 - 0.3333333333333333\right) \cdot u1 - 0.5\right) \cdot u1 - 1\right) \cdot u1} \cdot \left(t\_1 \cdot 2\right)\right) \cdot \cos \left(\left(u2 \cdot t\_2\right) \cdot t\_2\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot \left(\left(\cos t\_0 \cdot t\_1\right) \cdot 2\right)\\
\end{array}
\end{array}
if u1 < 0.0399999991Initial program 54.1%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
metadata-evalN/A
distribute-lft-neg-inN/A
lower--.f32N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f3298.4
Applied rewrites98.4%
lift-*.f32N/A
lift-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
lift-*.f32N/A
sin-2N/A
lift-sin.f32N/A
lift-cos.f32N/A
associate-*r*N/A
*-commutativeN/A
Applied rewrites98.5%
lift-*.f32N/A
lift-PI.f32N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f32N/A
lift-PI.f32N/A
lower-sqrt.f32N/A
lift-PI.f32N/A
lower-sqrt.f3298.5
Applied rewrites98.5%
if 0.0399999991 < u1 Initial program 97.1%
lift-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
sin-2N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-sin.f32N/A
*-commutativeN/A
lower-*.f3297.2
Applied rewrites97.2%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (sqrt (PI))))
(if (<= u1 0.03999999910593033)
(*
(*
(sqrt
(-
(*
(- (* (- (* (- (* -0.25 u1) 0.3333333333333333) u1) 0.5) u1) 1.0)
u1)))
(* (sin (* u2 (PI))) 2.0))
(cos (* (* u2 t_0) t_0)))
(* (sqrt (- (log (- 1.0 u1)))) (sin (* (* 2.0 (PI)) u2))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
\mathbf{if}\;u1 \leq 0.03999999910593033:\\
\;\;\;\;\left(\sqrt{-\left(\left(\left(-0.25 \cdot u1 - 0.3333333333333333\right) \cdot u1 - 0.5\right) \cdot u1 - 1\right) \cdot u1} \cdot \left(\sin \left(u2 \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right)\right) \cdot \cos \left(\left(u2 \cdot t\_0\right) \cdot t\_0\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\end{array}
\end{array}
if u1 < 0.0399999991Initial program 54.1%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
metadata-evalN/A
distribute-lft-neg-inN/A
lower--.f32N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f3298.4
Applied rewrites98.4%
lift-*.f32N/A
lift-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
lift-*.f32N/A
sin-2N/A
lift-sin.f32N/A
lift-cos.f32N/A
associate-*r*N/A
*-commutativeN/A
Applied rewrites98.5%
lift-*.f32N/A
lift-PI.f32N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f32N/A
lift-PI.f32N/A
lower-sqrt.f32N/A
lift-PI.f32N/A
lower-sqrt.f3298.5
Applied rewrites98.5%
if 0.0399999991 < u1 Initial program 97.1%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* u2 (PI))))
(if (<= u1 0.03999999910593033)
(*
(*
(sqrt
(-
(*
(- (* (- (* (- (* -0.25 u1) 0.3333333333333333) u1) 0.5) u1) 1.0)
u1)))
(* (sin t_0) 2.0))
(cos t_0))
(* (sqrt (- (log (- 1.0 u1)))) (sin (* (* 2.0 (PI)) u2))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := u2 \cdot \mathsf{PI}\left(\right)\\
\mathbf{if}\;u1 \leq 0.03999999910593033:\\
\;\;\;\;\left(\sqrt{-\left(\left(\left(-0.25 \cdot u1 - 0.3333333333333333\right) \cdot u1 - 0.5\right) \cdot u1 - 1\right) \cdot u1} \cdot \left(\sin t\_0 \cdot 2\right)\right) \cdot \cos t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\end{array}
\end{array}
if u1 < 0.0399999991Initial program 54.1%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
metadata-evalN/A
distribute-lft-neg-inN/A
lower--.f32N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f3298.4
Applied rewrites98.4%
lift-*.f32N/A
lift-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
lift-*.f32N/A
sin-2N/A
lift-sin.f32N/A
lift-cos.f32N/A
associate-*r*N/A
*-commutativeN/A
Applied rewrites98.5%
if 0.0399999991 < u1 Initial program 97.1%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (log (- 1.0 u1))))
(if (<= t_0 -0.007600000128149986)
(* (* (sqrt (- t_0)) (* (PI) 2.0)) u2)
(* (sqrt (- (* (- (* -0.5 u1) 1.0) u1))) (sin (* (* 2.0 (PI)) u2))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log \left(1 - u1\right)\\
\mathbf{if}\;t\_0 \leq -0.007600000128149986:\\
\;\;\;\;\left(\sqrt{-t\_0} \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right) \cdot u2\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-\left(-0.5 \cdot u1 - 1\right) \cdot u1} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\end{array}
\end{array}
if (log.f32 (-.f32 #s(literal 1 binary32) u1)) < -0.00760000013Initial program 94.7%
lift-neg.f32N/A
lift-log.f32N/A
neg-logN/A
lower-log.f32N/A
lower-/.f3293.3
Applied rewrites93.3%
Taylor expanded in u2 around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
associate-*l*N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f32N/A
Applied rewrites7.9%
Taylor expanded in u2 around 0
Applied rewrites79.5%
if -0.00760000013 < (log.f32 (-.f32 #s(literal 1 binary32) u1)) Initial program 48.4%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
metadata-evalN/A
distribute-lft-neg-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower--.f32N/A
distribute-lft-neg-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f3296.9
Applied rewrites96.9%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (sin (* (* 2.0 (PI)) u2))))
(if (<= u1 0.03999999910593033)
(*
(sqrt
(-
(*
(- (* (- (* (- (* -0.25 u1) 0.3333333333333333) u1) 0.5) u1) 1.0)
u1)))
t_0)
(* (sqrt (- (log (- 1.0 u1)))) t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\mathbf{if}\;u1 \leq 0.03999999910593033:\\
\;\;\;\;\sqrt{-\left(\left(\left(-0.25 \cdot u1 - 0.3333333333333333\right) \cdot u1 - 0.5\right) \cdot u1 - 1\right) \cdot u1} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot t\_0\\
\end{array}
\end{array}
if u1 < 0.0399999991Initial program 54.1%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
metadata-evalN/A
distribute-lft-neg-inN/A
lower--.f32N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f3298.4
Applied rewrites98.4%
if 0.0399999991 < u1 Initial program 97.1%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(*
(sqrt
(-
(* (- (* (- (* (- (* -0.25 u1) 0.3333333333333333) u1) 0.5) u1) 1.0) u1)))
(sin (* (* 2.0 (PI)) u2))))\begin{array}{l}
\\
\sqrt{-\left(\left(\left(-0.25 \cdot u1 - 0.3333333333333333\right) \cdot u1 - 0.5\right) \cdot u1 - 1\right) \cdot u1} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
Initial program 59.3%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
metadata-evalN/A
distribute-lft-neg-inN/A
lower--.f32N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f3294.7
Applied rewrites94.7%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (- (* (- (* (- (* -0.3333333333333333 u1) 0.5) u1) 1.0) u1))) (sin (* (* 2.0 (PI)) u2))))
\begin{array}{l}
\\
\sqrt{-\left(\left(-0.3333333333333333 \cdot u1 - 0.5\right) \cdot u1 - 1\right) \cdot u1} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
Initial program 59.3%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
metadata-evalN/A
distribute-lft-neg-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower--.f32N/A
distribute-lft-neg-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f3292.6
Applied rewrites92.6%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<= u2 0.001500000013038516)
(*
(sqrt
(-
(*
(- (* (- (* (- (* -0.25 u1) 0.3333333333333333) u1) 0.5) u1) 1.0)
u1)))
(* (* (PI) u2) 2.0))
(* (sqrt u1) (sin (* (* 2.0 (PI)) u2)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u2 \leq 0.001500000013038516:\\
\;\;\;\;\sqrt{-\left(\left(\left(-0.25 \cdot u1 - 0.3333333333333333\right) \cdot u1 - 0.5\right) \cdot u1 - 1\right) \cdot u1} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot u2\right) \cdot 2\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{u1} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\end{array}
\end{array}
if u2 < 0.00150000001Initial program 59.0%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
metadata-evalN/A
distribute-lft-neg-inN/A
lower--.f32N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f3295.2
Applied rewrites95.2%
lift-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
lift-*.f32N/A
sin-2N/A
lift-sin.f32N/A
lift-cos.f32N/A
associate-*r*N/A
*-commutativeN/A
lift-cos.f32N/A
sin-+PI/2-revN/A
sin-sumN/A
distribute-rgt-inN/A
Applied rewrites95.0%
Taylor expanded in u2 around 0
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3294.0
Applied rewrites94.0%
if 0.00150000001 < u2 Initial program 59.8%
lift-neg.f32N/A
lift-log.f32N/A
neg-logN/A
lower-log.f32N/A
lower-/.f3257.7
Applied rewrites57.7%
Taylor expanded in u1 around 0
lower-sqrt.f3275.3
Applied rewrites75.3%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(*
(sqrt
(-
(* (- (* (- (* (- (* -0.25 u1) 0.3333333333333333) u1) 0.5) u1) 1.0) u1)))
(* (* (PI) u2) 2.0)))\begin{array}{l}
\\
\sqrt{-\left(\left(\left(-0.25 \cdot u1 - 0.3333333333333333\right) \cdot u1 - 0.5\right) \cdot u1 - 1\right) \cdot u1} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot u2\right) \cdot 2\right)
\end{array}
Initial program 59.3%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
metadata-evalN/A
distribute-lft-neg-inN/A
lower--.f32N/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f3294.7
Applied rewrites94.7%
lift-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
lift-*.f32N/A
sin-2N/A
lift-sin.f32N/A
lift-cos.f32N/A
associate-*r*N/A
*-commutativeN/A
lift-cos.f32N/A
sin-+PI/2-revN/A
sin-sumN/A
distribute-rgt-inN/A
Applied rewrites71.4%
Taylor expanded in u2 around 0
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3278.8
Applied rewrites78.8%
(FPCore (cosTheta_i u1 u2) :precision binary32 0.0)
float code(float cosTheta_i, float u1, float u2) {
return 0.0f;
}
real(4) function code(costheta_i, u1, u2)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
code = 0.0e0
end function
function code(cosTheta_i, u1, u2) return Float32(0.0) end
function tmp = code(cosTheta_i, u1, u2) tmp = single(0.0); end
\begin{array}{l}
\\
0
\end{array}
Initial program 59.3%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3275.9
Applied rewrites75.9%
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
count-2-revN/A
flip-+N/A
lift-PI.f32N/A
lift-PI.f32N/A
lift-PI.f32N/A
lift-PI.f32N/A
+-inversesN/A
+-inversesN/A
associate-*r/N/A
Applied rewrites19.1%
lift-sin.f32N/A
lift-*.f32N/A
*-commutativeN/A
count-2-revN/A
lift-PI.f32N/A
sin-+PIN/A
lift-PI.f32N/A
sin-PIN/A
metadata-eval7.1
Applied rewrites7.1%
Taylor expanded in u1 around 0
Applied rewrites7.1%
herbie shell --seed 2024339
(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))))