
(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 15 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}
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (cos (* (PI) (* 2.0 uy)))) (t_1 (- (/ 2.0 ux) 1.0)))
(if (<= maxCos 1.000000013351432e-10)
(* (sqrt (* (* t_1 ux) ux)) t_0)
(*
(sqrt
(*
(* maxCos maxCos)
(-
(* (/ (- 2.0 (- (/ 2.0 ux) (/ t_1 maxCos))) maxCos) (* ux ux))
(* ux ux))))
t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
t_1 := \frac{2}{ux} - 1\\
\mathbf{if}\;maxCos \leq 1.000000013351432 \cdot 10^{-10}:\\
\;\;\;\;\sqrt{\left(t\_1 \cdot ux\right) \cdot ux} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(maxCos \cdot maxCos\right) \cdot \left(\frac{2 - \left(\frac{2}{ux} - \frac{t\_1}{maxCos}\right)}{maxCos} \cdot \left(ux \cdot ux\right) - ux \cdot ux\right)} \cdot t\_0\\
\end{array}
\end{array}
if maxCos < 1.00000001e-10Initial program 60.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-*.f3272.8
Applied rewrites72.8%
Taylor expanded in maxCos around 0
Applied rewrites99.0%
if 1.00000001e-10 < maxCos Initial program 60.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-*.f3256.6
Applied rewrites56.6%
Taylor expanded in maxCos around inf
Applied rewrites98.4%
Taylor expanded in maxCos around inf
Applied rewrites98.7%
Final simplification99.0%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (* maxCos ux) (- 1.0 ux))) (t_1 (cos (* (PI) (* 2.0 uy)))))
(if (<= (* (sqrt (- 1.0 (* t_0 t_0))) t_1) 0.039000000804662704)
(* (sqrt (* (fma -2.0 maxCos 2.0) ux)) t_1)
(*
(sqrt (- 1.0 (* (* (- (+ (/ 1.0 ux) maxCos) 1.0) ux) t_0)))
(fma (* (* uy uy) -2.0) (* (PI) (PI)) 1.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := maxCos \cdot ux + \left(1 - ux\right)\\
t_1 := \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
\mathbf{if}\;\sqrt{1 - t\_0 \cdot t\_0} \cdot t\_1 \leq 0.039000000804662704:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot t\_1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(\left(\left(\frac{1}{ux} + maxCos\right) - 1\right) \cdot ux\right) \cdot t\_0} \cdot \mathsf{fma}\left(\left(uy \cdot uy\right) \cdot -2, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\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.0390000008Initial program 41.9%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3259.7
Applied rewrites59.7%
if 0.0390000008 < (*.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 92.2%
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.f3283.8
Applied rewrites83.8%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
lower--.f3283.8
Applied rewrites83.8%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower-/.f3284.3
Applied rewrites83.8%
Final simplification68.5%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* (* ux ux) (- (/ (+ (* -2.0 maxCos) 2.0) ux) (pow (- maxCos 1.0) 2.0)))) (cos (* (PI) (* 2.0 uy)))))
\begin{array}{l}
\\
\sqrt{\left(ux \cdot ux\right) \cdot \left(\frac{-2 \cdot maxCos + 2}{ux} - {\left(maxCos - 1\right)}^{2}\right)} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)
\end{array}
Initial program 60.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-*.f3269.3
Applied rewrites69.3%
Applied rewrites98.8%
Final simplification98.8%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (cos (* (PI) (* 2.0 uy)))) (t_1 (- (/ 2.0 ux) 1.0)))
(if (<= maxCos 5.499999899960528e-10)
(* (sqrt (* (* t_1 ux) ux)) t_0)
(*
(sqrt
(*
(-
(/ (* (* (- (+ (/ t_1 maxCos) 2.0) (/ 2.0 ux)) ux) ux) maxCos)
(* ux ux))
(* maxCos maxCos)))
t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
t_1 := \frac{2}{ux} - 1\\
\mathbf{if}\;maxCos \leq 5.499999899960528 \cdot 10^{-10}:\\
\;\;\;\;\sqrt{\left(t\_1 \cdot ux\right) \cdot ux} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\frac{\left(\left(\left(\frac{t\_1}{maxCos} + 2\right) - \frac{2}{ux}\right) \cdot ux\right) \cdot ux}{maxCos} - ux \cdot ux\right) \cdot \left(maxCos \cdot maxCos\right)} \cdot t\_0\\
\end{array}
\end{array}
if maxCos < 5.4999999e-10Initial program 60.2%
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-*.f3272.2
Applied rewrites72.7%
Taylor expanded in maxCos around 0
Applied rewrites99.1%
if 5.4999999e-10 < maxCos Initial program 59.2%
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-*.f3256.1
Applied rewrites56.1%
Taylor expanded in maxCos around inf
Applied rewrites98.3%
Taylor expanded in maxCos around inf
Applied rewrites98.4%
Applied rewrites98.5%
Final simplification98.9%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (cos (* (PI) (* 2.0 uy)))) (t_1 (- (/ 2.0 ux) 1.0)))
(if (<= maxCos 4.000000053405728e-10)
(* (sqrt (* (* t_1 ux) ux)) t_0)
(*
(sqrt
(*
(*
(-
(* (/ (* ux ux) maxCos) (- (+ (/ t_1 maxCos) 2.0) (/ 2.0 ux)))
(* ux ux))
maxCos)
maxCos))
t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
t_1 := \frac{2}{ux} - 1\\
\mathbf{if}\;maxCos \leq 4.000000053405728 \cdot 10^{-10}:\\
\;\;\;\;\sqrt{\left(t\_1 \cdot ux\right) \cdot ux} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\left(\frac{ux \cdot ux}{maxCos} \cdot \left(\left(\frac{t\_1}{maxCos} + 2\right) - \frac{2}{ux}\right) - ux \cdot ux\right) \cdot maxCos\right) \cdot maxCos} \cdot t\_0\\
\end{array}
\end{array}
if maxCos < 4.00000005e-10Initial program 60.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-*.f3272.6
Applied rewrites72.5%
Taylor expanded in maxCos around 0
Applied rewrites99.1%
if 4.00000005e-10 < maxCos Initial program 60.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-*.f3256.9
Applied rewrites56.9%
Taylor expanded in maxCos around inf
Applied rewrites98.3%
Taylor expanded in maxCos around inf
Applied rewrites98.4%
Applied rewrites98.5%
Final simplification98.9%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (cos (* (PI) (* 2.0 uy)))) (t_1 (+ (* maxCos ux) (- 1.0 ux))))
(if (<= (- 1.0 (* t_1 t_1)) 0.0002500000118743628)
(* (sqrt (* (fma -2.0 maxCos 2.0) ux)) t_0)
(* (sqrt (- 1.0 (* (- 1.0 ux) t_1))) t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
t_1 := maxCos \cdot ux + \left(1 - ux\right)\\
\mathbf{if}\;1 - t\_1 \cdot t\_1 \leq 0.0002500000118743628:\\
\;\;\;\;\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)))) < 2.50000012e-4Initial program 35.6%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3265.7
Applied rewrites65.0%
if 2.50000012e-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 89.0%
Taylor expanded in maxCos around 0
lower--.f3285.8
Applied rewrites85.8%
Final simplification88.0%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (cos (* (PI) (* 2.0 uy)))))
(if (<= (+ (* maxCos ux) (- 1.0 ux)) 0.9998499751091003)
(* (sqrt (- 1.0 (* (- (fma ux maxCos 1.0) ux) (- 1.0 ux)))) t_0)
(* (sqrt (* (fma -2.0 maxCos 2.0) ux)) t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
\mathbf{if}\;maxCos \cdot ux + \left(1 - ux\right) \leq 0.9998499751091003:\\
\;\;\;\;\sqrt{1 - \left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux\right) \cdot \left(1 - ux\right)} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot t\_0\\
\end{array}
\end{array}
if (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) < 0.999849975Initial program 89.1%
lift-+.f32N/A
lift--.f32N/A
sub-negN/A
+-commutativeN/A
associate-+l+N/A
lower-+.f32N/A
lower-neg.f32N/A
lower-+.f3289.1
lift-*.f32N/A
*-commutativeN/A
lower-*.f3289.1
Applied rewrites89.1%
Taylor expanded in maxCos around 0
lower--.f3286.1
Applied rewrites86.1%
lift-*.f32N/A
*-commutativeN/A
lower-*.f3286.1
Applied rewrites67.3%
if 0.999849975 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 35.9%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3264.9
Applied rewrites64.9%
Final simplification73.0%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* (* (- (/ 2.0 ux) 1.0) ux) ux)) (cos (* (PI) (* 2.0 uy)))))
\begin{array}{l}
\\
\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\right)\right)
\end{array}
Initial program 60.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-*.f3269.3
Applied rewrites69.3%
Taylor expanded in maxCos around 0
Applied rewrites94.6%
Final simplification94.6%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (fma (* (* uy uy) -2.0) (* (PI) (PI)) 1.0)))
(if (<= ux 5.999999848427251e-5)
(* t_0 (sqrt (* (fma -2.0 maxCos 2.0) ux)))
(*
(sqrt
(-
1.0
(* (* (- (+ (/ 1.0 ux) maxCos) 1.0) ux) (+ (* maxCos ux) (- 1.0 ux)))))
t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\left(uy \cdot uy\right) \cdot -2, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)\\
\mathbf{if}\;ux \leq 5.999999848427251 \cdot 10^{-5}:\\
\;\;\;\;t\_0 \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(\left(\left(\frac{1}{ux} + maxCos\right) - 1\right) \cdot ux\right) \cdot \left(maxCos \cdot ux + \left(1 - ux\right)\right)} \cdot t\_0\\
\end{array}
\end{array}
if ux < 5.99999985e-5Initial program 34.0%
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.f3231.6
Applied rewrites31.3%
Taylor expanded in ux around 0
Applied rewrites21.6%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3256.9
Applied rewrites74.1%
if 5.99999985e-5 < ux Initial program 88.1%
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.f3274.0
Applied rewrites74.0%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
lower--.f3274.0
Applied rewrites74.0%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower-/.f3274.6
Applied rewrites74.6%
Final simplification72.2%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (* maxCos ux) (- 1.0 ux)))
(t_1 (fma (* (* uy uy) -2.0) (* (PI) (PI)) 1.0)))
(if (<= t_0 0.9998800158500671)
(* t_1 (sqrt (- 1.0 (* (- 1.0 ux) t_0))))
(* t_1 (sqrt (* (fma -2.0 maxCos 2.0) ux))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := maxCos \cdot ux + \left(1 - ux\right)\\
t_1 := \mathsf{fma}\left(\left(uy \cdot uy\right) \cdot -2, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)\\
\mathbf{if}\;t\_0 \leq 0.9998800158500671:\\
\;\;\;\;t\_1 \cdot \sqrt{1 - \left(1 - ux\right) \cdot t\_0}\\
\mathbf{else}:\\
\;\;\;\;t\_1 \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}\\
\end{array}
\end{array}
if (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) < 0.999880016Initial program 89.0%
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.f3275.0
Applied rewrites75.0%
Taylor expanded in maxCos around 0
lower--.f3270.3
Applied rewrites73.1%
if 0.999880016 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 35.6%
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.f3230.3
Applied rewrites32.3%
Taylor expanded in ux around 0
Applied rewrites22.0%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3273.7
Applied rewrites73.1%
Final simplification73.4%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (fma (* (* uy uy) -2.0) (* (PI) (PI)) 1.0)))
(if (<= ux 5.999999848427251e-5)
(* t_0 (sqrt (* (fma -2.0 maxCos 2.0) ux)))
(*
(sqrt
(- 1.0 (* (- 1.0 (- ux (* maxCos ux))) (+ (* maxCos ux) (- 1.0 ux)))))
t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\left(uy \cdot uy\right) \cdot -2, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)\\
\mathbf{if}\;ux \leq 5.999999848427251 \cdot 10^{-5}:\\
\;\;\;\;t\_0 \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(1 - \left(ux - maxCos \cdot ux\right)\right) \cdot \left(maxCos \cdot ux + \left(1 - ux\right)\right)} \cdot t\_0\\
\end{array}
\end{array}
if ux < 5.99999985e-5Initial program 34.0%
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.f3231.6
Applied rewrites31.3%
Taylor expanded in ux around 0
Applied rewrites21.8%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3254.3
Applied rewrites74.1%
if 5.99999985e-5 < ux Initial program 88.1%
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.f3274.0
Applied rewrites74.0%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
lower--.f3274.0
Applied rewrites74.0%
Final simplification73.1%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (fma (* (* uy uy) -2.0) (* (PI) (PI)) 1.0))
(t_1 (+ (* maxCos ux) (- 1.0 ux))))
(if (<= ux 5.999999848427251e-5)
(* t_0 (sqrt (* (fma -2.0 maxCos 2.0) ux)))
(* t_0 (sqrt (- 1.0 (* t_1 t_1)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\left(uy \cdot uy\right) \cdot -2, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)\\
t_1 := maxCos \cdot ux + \left(1 - ux\right)\\
\mathbf{if}\;ux \leq 5.999999848427251 \cdot 10^{-5}:\\
\;\;\;\;t\_0 \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sqrt{1 - t\_1 \cdot t\_1}\\
\end{array}
\end{array}
if ux < 5.99999985e-5Initial program 34.0%
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.f3231.6
Applied rewrites31.3%
Taylor expanded in ux around 0
Applied rewrites21.8%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3255.4
Applied rewrites74.1%
if 5.99999985e-5 < ux Initial program 88.1%
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.f3274.0
Applied rewrites74.0%
Final simplification72.0%
(FPCore (ux uy maxCos) :precision binary32 (* (fma (* (* uy uy) -2.0) (* (PI) (PI)) 1.0) (sqrt (* (fma -2.0 maxCos 2.0) ux))))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(uy \cdot uy\right) \cdot -2, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right) \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}
\end{array}
Initial program 60.0%
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.f3252.0
Applied rewrites52.0%
Taylor expanded in ux around 0
Applied rewrites25.7%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3260.8
Applied rewrites60.8%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (fma (- 1.0) 1.0 1.0)) (fma (* (* uy uy) -2.0) (* (PI) (PI)) 1.0)))
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(-1, 1, 1\right)} \cdot \mathsf{fma}\left(\left(uy \cdot uy\right) \cdot -2, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)
\end{array}
Initial program 60.0%
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.f3252.0
Applied rewrites52.0%
Taylor expanded in ux around 0
Applied rewrites25.7%
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.2
Applied rewrites20.2%
Final simplification20.2%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (- 1.0 (* 1.0 1.0))) (* (* (* (* (PI) (PI)) -2.0) uy) uy)))
\begin{array}{l}
\\
\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\right) \cdot uy\right)
\end{array}
Initial program 60.0%
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.f3250.9
Applied rewrites52.0%
Taylor expanded in ux around 0
Applied rewrites25.7%
Taylor expanded in ux around 0
Applied rewrites6.6%
Taylor expanded in uy around inf
Applied rewrites6.6%
Final simplification6.6%
herbie shell --seed 2024288
(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)))))))