
(FPCore (ux uy maxCos) :precision binary32 (let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))) (* (cos (* (* 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\\
\cos \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 14 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (ux uy maxCos) :precision binary32 (let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))) (* (cos (* (* 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\\
\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{1 - t\_0 \cdot t\_0}
\end{array}
\end{array}
uy_m = (fabs.f32 uy)
(FPCore (ux uy_m maxCos)
:precision binary32
(let* ((t_0 (cos (* (PI) (* 2.0 uy_m)))))
(if (<= maxCos 9.999999717180685e-10)
(*
(sqrt (* (- (fma -2.0 maxCos 2.0) (* (pow (- maxCos 1.0) 2.0) ux)) ux))
t_0)
(*
(sqrt
(*
(-
(*
(- -1.0 (/ (- (/ 1.0 maxCos) 2.0) maxCos))
(* (* maxCos ux) maxCos))
(* (- 2.0 (/ 2.0 maxCos)) maxCos))
ux))
t_0))))\begin{array}{l}
uy_m = \left|uy\right|
\\
\begin{array}{l}
t_0 := \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\_m\right)\right)\\
\mathbf{if}\;maxCos \leq 9.999999717180685 \cdot 10^{-10}:\\
\;\;\;\;\sqrt{\left(\mathsf{fma}\left(-2, maxCos, 2\right) - {\left(maxCos - 1\right)}^{2} \cdot ux\right) \cdot ux} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\left(-1 - \frac{\frac{1}{maxCos} - 2}{maxCos}\right) \cdot \left(\left(maxCos \cdot ux\right) \cdot maxCos\right) - \left(2 - \frac{2}{maxCos}\right) \cdot maxCos\right) \cdot ux} \cdot t\_0\\
\end{array}
\end{array}
if maxCos < 9.99999972e-10Initial program 57.1%
lift-+.f32N/A
lift--.f32N/A
flip--N/A
metadata-evalN/A
div-subN/A
associate-+l-N/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower--.f32N/A
lower-/.f32N/A
lower-*.f32N/A
+-commutativeN/A
lower-+.f3257.3
lift-*.f32N/A
*-commutativeN/A
lower-*.f3257.3
Applied rewrites57.3%
Taylor expanded in ux around 0
*-commutativeN/A
associate--l+N/A
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
lower-*.f32N/A
associate-+r+N/A
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
+-commutativeN/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-pow.f32N/A
lower--.f3270.9
Applied rewrites70.9%
if 9.99999972e-10 < maxCos Initial program 49.7%
lift-+.f32N/A
lift--.f32N/A
flip--N/A
metadata-evalN/A
div-subN/A
associate-+l-N/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower--.f32N/A
lower-/.f32N/A
lower-*.f32N/A
+-commutativeN/A
lower-+.f3249.4
lift-*.f32N/A
*-commutativeN/A
lower-*.f3249.4
Applied rewrites49.4%
Taylor expanded in maxCos around -inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites46.9%
Taylor expanded in ux around 0
Applied rewrites98.5%
Final simplification96.2%
uy_m = (fabs.f32 uy)
(FPCore (ux uy_m maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* maxCos ux))) (t_1 (cos (* (PI) (* 2.0 uy_m)))))
(if (<= (* (sqrt (- 1.0 (* t_0 t_0))) t_1) 0.018619999289512634)
(* (sqrt (* (fma -2.0 maxCos 2.0) ux)) t_1)
(*
(sqrt (- 1.0 (* (- 1.0 (- ux (* maxCos ux))) t_0)))
(+ (* (* -2.0 uy_m) (* (* (PI) (PI)) uy_m)) 1.0)))))\begin{array}{l}
uy_m = \left|uy\right|
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + maxCos \cdot ux\\
t_1 := \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\_m\right)\right)\\
\mathbf{if}\;\sqrt{1 - t\_0 \cdot t\_0} \cdot t\_1 \leq 0.018619999289512634:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot t\_1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(1 - \left(ux - maxCos \cdot ux\right)\right) \cdot t\_0} \cdot \left(\left(-2 \cdot uy\_m\right) \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot uy\_m\right) + 1\right)\\
\end{array}
\end{array}
if (*.f32 (cos.f32 (*.f32 (*.f32 uy #s(literal 2 binary32)) (PI.f32))) (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.0186199993Initial program 40.4%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3262.8
Applied rewrites62.7%
if 0.0186199993 < (*.f32 (cos.f32 (*.f32 (*.f32 uy #s(literal 2 binary32)) (PI.f32))) (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.3%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3281.1
Applied rewrites79.9%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
lower--.f3281.2
Applied rewrites81.2%
Applied rewrites86.9%
Final simplification70.6%
uy_m = (fabs.f32 uy)
(FPCore (ux uy_m maxCos)
:precision binary32
(*
(sqrt
(*
(* ux ux)
(-
(/ (/ (- (* (* maxCos maxCos) 4.0) 4.0) (- (* -2.0 maxCos) 2.0)) ux)
(pow (- maxCos 1.0) 2.0))))
(cos (* (PI) (* 2.0 uy_m)))))\begin{array}{l}
uy_m = \left|uy\right|
\\
\sqrt{\left(ux \cdot ux\right) \cdot \left(\frac{\frac{\left(maxCos \cdot maxCos\right) \cdot 4 - 4}{-2 \cdot maxCos - 2}}{ux} - {\left(maxCos - 1\right)}^{2}\right)} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\_m\right)\right)
\end{array}
Initial program 55.7%
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
cancel-sign-sub-invN/A
metadata-evalN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3269.3
Applied rewrites69.3%
Applied rewrites98.7%
Final simplification98.7%
uy_m = (fabs.f32 uy) (FPCore (ux uy_m maxCos) :precision binary32 (* (sqrt (* (- (/ (+ (* -2.0 maxCos) 2.0) ux) (pow (- maxCos 1.0) 2.0)) (* ux ux))) (cos (* (PI) (* 2.0 uy_m)))))
\begin{array}{l}
uy_m = \left|uy\right|
\\
\sqrt{\left(\frac{-2 \cdot maxCos + 2}{ux} - {\left(maxCos - 1\right)}^{2}\right) \cdot \left(ux \cdot ux\right)} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\_m\right)\right)
\end{array}
Initial program 55.7%
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
cancel-sign-sub-invN/A
metadata-evalN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3269.3
Applied rewrites69.3%
Applied rewrites98.7%
Final simplification98.7%
uy_m = (fabs.f32 uy)
(FPCore (ux uy_m maxCos)
:precision binary32
(let* ((t_0 (cos (* (PI) (* 2.0 uy_m)))))
(if (<= maxCos 5.200000158098144e-20)
(* (sqrt (* (* (- (/ 2.0 ux) 1.0) ux) ux)) t_0)
(*
(sqrt
(*
(-
(*
(- -1.0 (/ (- (/ 1.0 maxCos) 2.0) maxCos))
(* (* maxCos ux) maxCos))
(* (- 2.0 (/ 2.0 maxCos)) maxCos))
ux))
t_0))))\begin{array}{l}
uy_m = \left|uy\right|
\\
\begin{array}{l}
t_0 := \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\_m\right)\right)\\
\mathbf{if}\;maxCos \leq 5.200000158098144 \cdot 10^{-20}:\\
\;\;\;\;\sqrt{\left(\left(\frac{2}{ux} - 1\right) \cdot ux\right) \cdot ux} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\left(-1 - \frac{\frac{1}{maxCos} - 2}{maxCos}\right) \cdot \left(\left(maxCos \cdot ux\right) \cdot maxCos\right) - \left(2 - \frac{2}{maxCos}\right) \cdot maxCos\right) \cdot ux} \cdot t\_0\\
\end{array}
\end{array}
if maxCos < 5.20000016e-20Initial 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
cancel-sign-sub-invN/A
metadata-evalN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3271.2
Applied rewrites71.2%
Applied rewrites98.7%
Taylor expanded in maxCos around 0
Applied rewrites98.9%
if 5.20000016e-20 < maxCos Initial program 55.3%
lift-+.f32N/A
lift--.f32N/A
flip--N/A
metadata-evalN/A
div-subN/A
associate-+l-N/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower--.f32N/A
lower-/.f32N/A
lower-*.f32N/A
+-commutativeN/A
lower-+.f3255.7
lift-*.f32N/A
*-commutativeN/A
lower-*.f3255.7
Applied rewrites55.7%
Taylor expanded in maxCos around -inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites54.1%
Taylor expanded in ux around 0
Applied rewrites98.9%
Final simplification98.9%
uy_m = (fabs.f32 uy)
(FPCore (ux uy_m maxCos)
:precision binary32
(let* ((t_0 (cos (* (PI) (* 2.0 uy_m)))) (t_1 (+ (- 1.0 ux) (* maxCos ux))))
(if (<= (- 1.0 (* t_1 t_1)) 0.0003000000142492354)
(* (sqrt (* (fma -2.0 maxCos 2.0) ux)) t_0)
(* (sqrt (- 1.0 (* (- 1.0 ux) t_1))) t_0))))\begin{array}{l}
uy_m = \left|uy\right|
\\
\begin{array}{l}
t_0 := \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\_m\right)\right)\\
t_1 := \left(1 - ux\right) + maxCos \cdot ux\\
\mathbf{if}\;1 - t\_1 \cdot t\_1 \leq 0.0003000000142492354:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(1 - ux\right) \cdot t\_1} \cdot t\_0\\
\end{array}
\end{array}
if (-.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)))) < 3.00000014e-4Initial program 36.4%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3267.1
Applied rewrites67.0%
if 3.00000014e-4 < (-.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 88.3%
Taylor expanded in maxCos around 0
lower--.f3285.5
Applied rewrites85.5%
Final simplification87.2%
uy_m = (fabs.f32 uy)
(FPCore (ux uy_m maxCos)
:precision binary32
(if (<= maxCos 1.500000053056283e-6)
(* (sqrt (* (* (- (/ 2.0 ux) 1.0) ux) ux)) (cos (* (PI) (* 2.0 uy_m))))
(*
(sqrt
(*
(+
(/
(* (- (/ (- 2.0 (/ 2.0 maxCos)) ux) (- 2.0 (/ 1.0 maxCos))) (* ux ux))
maxCos)
(* ux ux))
(* (- maxCos) maxCos)))
(fma (* (* uy_m uy_m) -2.0) (* (PI) (PI)) 1.0))))\begin{array}{l}
uy_m = \left|uy\right|
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 1.500000053056283 \cdot 10^{-6}:\\
\;\;\;\;\sqrt{\left(\left(\frac{2}{ux} - 1\right) \cdot ux\right) \cdot ux} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\_m\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\frac{\left(\frac{2 - \frac{2}{maxCos}}{ux} - \left(2 - \frac{1}{maxCos}\right)\right) \cdot \left(ux \cdot ux\right)}{maxCos} + ux \cdot ux\right) \cdot \left(\left(-maxCos\right) \cdot maxCos\right)} \cdot \mathsf{fma}\left(\left(uy\_m \cdot uy\_m\right) \cdot -2, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)\\
\end{array}
\end{array}
if maxCos < 1.50000005e-6Initial program 56.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
cancel-sign-sub-invN/A
metadata-evalN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3271.2
Applied rewrites71.2%
Applied rewrites98.7%
Taylor expanded in maxCos around 0
Applied rewrites98.7%
if 1.50000005e-6 < maxCos Initial program 52.9%
lift-+.f32N/A
lift--.f32N/A
flip--N/A
metadata-evalN/A
div-subN/A
associate-+l-N/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower--.f32N/A
lower-/.f32N/A
lower-*.f32N/A
+-commutativeN/A
lower-+.f3252.5
lift-*.f32N/A
*-commutativeN/A
lower-*.f3252.5
Applied rewrites52.5%
Taylor expanded in maxCos around -inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites50.2%
Taylor expanded in ux around inf
Applied rewrites98.3%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3288.9
Applied rewrites85.9%
Final simplification97.5%
uy_m = (fabs.f32 uy)
(FPCore (ux uy_m maxCos)
:precision binary32
(let* ((t_0 (fma (* (* uy_m uy_m) -2.0) (* (PI) (PI)) 1.0))
(t_1 (+ (- 1.0 ux) (* maxCos ux))))
(if (<= (- 1.0 (* t_1 t_1)) 0.0003000000142492354)
(* (sqrt (* (fma -2.0 maxCos 2.0) ux)) t_0)
(* (sqrt (- 1.0 (* (- 1.0 (- ux (* maxCos ux))) t_1))) t_0))))\begin{array}{l}
uy_m = \left|uy\right|
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\left(uy\_m \cdot uy\_m\right) \cdot -2, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)\\
t_1 := \left(1 - ux\right) + maxCos \cdot ux\\
\mathbf{if}\;1 - t\_1 \cdot t\_1 \leq 0.0003000000142492354:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(1 - \left(ux - maxCos \cdot ux\right)\right) \cdot t\_1} \cdot t\_0\\
\end{array}
\end{array}
if (-.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)))) < 3.00000014e-4Initial program 36.4%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3232.1
Applied rewrites32.1%
Taylor expanded in ux around 0
Applied rewrites21.5%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3272.4
Applied rewrites72.0%
if 3.00000014e-4 < (-.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 88.3%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3272.1
Applied rewrites72.1%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
lower--.f3272.2
Applied rewrites71.2%
Applied rewrites71.2%
Final simplification72.3%
uy_m = (fabs.f32 uy)
(FPCore (ux uy_m maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* maxCos ux)))
(t_1 (- 1.0 (* t_0 t_0)))
(t_2 (* (PI) (PI))))
(if (<= t_1 0.0003000000142492354)
(*
(sqrt (* (fma -2.0 maxCos 2.0) ux))
(fma (* (* uy_m uy_m) -2.0) t_2 1.0))
(* (fma uy_m (* (* t_2 -2.0) uy_m) 1.0) (sqrt t_1)))))\begin{array}{l}
uy_m = \left|uy\right|
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + maxCos \cdot ux\\
t_1 := 1 - t\_0 \cdot t\_0\\
t_2 := \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\\
\mathbf{if}\;t\_1 \leq 0.0003000000142492354:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot \mathsf{fma}\left(\left(uy\_m \cdot uy\_m\right) \cdot -2, t\_2, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(uy\_m, \left(t\_2 \cdot -2\right) \cdot uy\_m, 1\right) \cdot \sqrt{t\_1}\\
\end{array}
\end{array}
if (-.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)))) < 3.00000014e-4Initial program 36.4%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3232.1
Applied rewrites31.8%
Taylor expanded in ux around 0
Applied rewrites21.5%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3272.4
Applied rewrites72.0%
if 3.00000014e-4 < (-.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 88.3%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3272.1
Applied rewrites71.1%
Applied rewrites71.0%
Final simplification72.3%
uy_m = (fabs.f32 uy)
(FPCore (ux uy_m maxCos)
:precision binary32
(let* ((t_0 (fma (* (* uy_m uy_m) -2.0) (* (PI) (PI)) 1.0))
(t_1 (+ (- 1.0 ux) (* maxCos ux))))
(if (<= (- 1.0 (* t_1 t_1)) 0.0003000000142492354)
(* (sqrt (* (fma -2.0 maxCos 2.0) ux)) t_0)
(* (sqrt (- 1.0 (* (- 1.0 ux) t_1))) t_0))))\begin{array}{l}
uy_m = \left|uy\right|
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\left(uy\_m \cdot uy\_m\right) \cdot -2, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)\\
t_1 := \left(1 - ux\right) + maxCos \cdot ux\\
\mathbf{if}\;1 - t\_1 \cdot t\_1 \leq 0.0003000000142492354:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(1 - ux\right) \cdot t\_1} \cdot t\_0\\
\end{array}
\end{array}
if (-.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)))) < 3.00000014e-4Initial program 36.4%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3232.1
Applied rewrites31.8%
Taylor expanded in ux around 0
Applied rewrites21.5%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3272.4
Applied rewrites72.0%
if 3.00000014e-4 < (-.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 88.3%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3272.1
Applied rewrites71.1%
Taylor expanded in maxCos around 0
lower--.f3269.6
Applied rewrites68.6%
Final simplification71.4%
uy_m = (fabs.f32 uy)
(FPCore (ux uy_m maxCos)
:precision binary32
(let* ((t_0 (* (PI) (PI))))
(if (<= ux 1.8000000636675395e-5)
(*
(sqrt (* (fma -2.0 maxCos 2.0) ux))
(fma (* (* uy_m uy_m) -2.0) t_0 1.0))
(*
(sqrt
(- 1.0 (* (- 1.0 (- ux (* maxCos ux))) (+ (- 1.0 ux) (* maxCos ux)))))
(+ (* (* -2.0 uy_m) (* t_0 uy_m)) 1.0)))))\begin{array}{l}
uy_m = \left|uy\right|
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\\
\mathbf{if}\;ux \leq 1.8000000636675395 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot \mathsf{fma}\left(\left(uy\_m \cdot uy\_m\right) \cdot -2, t\_0, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(1 - \left(ux - maxCos \cdot ux\right)\right) \cdot \left(\left(1 - ux\right) + maxCos \cdot ux\right)} \cdot \left(\left(-2 \cdot uy\_m\right) \cdot \left(t\_0 \cdot uy\_m\right) + 1\right)\\
\end{array}
\end{array}
if ux < 1.80000006e-5Initial program 31.5%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3229.1
Applied rewrites28.7%
Taylor expanded in ux around 0
Applied rewrites20.8%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3275.1
Applied rewrites74.5%
if 1.80000006e-5 < ux Initial program 84.8%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3268.5
Applied rewrites67.7%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
lower--.f3268.6
Applied rewrites67.8%
Applied rewrites75.6%
Final simplification75.3%
uy_m = (fabs.f32 uy) (FPCore (ux uy_m maxCos) :precision binary32 (* (sqrt (* (fma -2.0 maxCos 2.0) ux)) (fma (* (* uy_m uy_m) -2.0) (* (PI) (PI)) 1.0)))
\begin{array}{l}
uy_m = \left|uy\right|
\\
\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot \mathsf{fma}\left(\left(uy\_m \cdot uy\_m\right) \cdot -2, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)
\end{array}
Initial program 55.7%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3246.9
Applied rewrites46.6%
Taylor expanded in ux around 0
Applied rewrites24.4%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3262.6
Applied rewrites62.4%
Final simplification62.6%
uy_m = (fabs.f32 uy) (FPCore (ux uy_m maxCos) :precision binary32 (* (sqrt (fma (- 1.0) 1.0 1.0)) (fma (* (* uy_m uy_m) -2.0) (* (PI) (PI)) 1.0)))
\begin{array}{l}
uy_m = \left|uy\right|
\\
\sqrt{\mathsf{fma}\left(-1, 1, 1\right)} \cdot \mathsf{fma}\left(\left(uy\_m \cdot uy\_m\right) \cdot -2, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)
\end{array}
Initial program 55.7%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3246.9
Applied rewrites46.6%
Taylor expanded in ux around 0
Applied rewrites24.4%
Taylor expanded in ux around 0
Applied rewrites6.6%
lift--.f32N/A
sub-negN/A
+-commutativeN/A
lift-*.f32N/A
distribute-lft-neg-inN/A
lower-fma.f32N/A
lower-neg.f3219.0
Applied rewrites19.0%
Final simplification19.0%
uy_m = (fabs.f32 uy) (FPCore (ux uy_m maxCos) :precision binary32 (* (sqrt (- 1.0 (* 1.0 1.0))) (* (* (* (* (PI) (PI)) -2.0) uy_m) uy_m)))
\begin{array}{l}
uy_m = \left|uy\right|
\\
\sqrt{1 - 1 \cdot 1} \cdot \left(\left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot -2\right) \cdot uy\_m\right) \cdot uy\_m\right)
\end{array}
Initial program 55.7%
Taylor expanded in uy around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3246.9
Applied rewrites46.6%
Taylor expanded in ux around 0
Applied rewrites24.4%
Taylor expanded in ux around 0
Applied rewrites6.6%
Taylor expanded in uy around inf
Applied rewrites6.6%
Final simplification6.6%
herbie shell --seed 2024304
(FPCore (ux uy maxCos)
:name "UniformSampleCone, x"
: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)))
(* (cos (* (* uy 2.0) (PI))) (sqrt (- 1.0 (* (+ (- 1.0 ux) (* ux maxCos)) (+ (- 1.0 ux) (* ux maxCos)))))))