
(FPCore (ux uy maxCos) :precision binary32 (let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))) (* (sin (* (* 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\\
\sin \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)))) (* (sin (* (* 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\\
\sin \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)
uy\_s = (copysign.f32 #s(literal 1 binary32) uy)
(FPCore (uy_s ux uy_m maxCos)
:precision binary32
(let* ((t_0 (sqrt (PI))))
(*
uy_s
(if (<= maxCos 7.99999974612418e-20)
(*
(sqrt
(*
(* ux ux)
(- (/ (fma -2.0 maxCos 2.0) ux) (pow (- maxCos 1.0) 2.0))))
(sin (* (* (* t_0 2.0) uy_m) t_0)))
(*
(sqrt
(*
(* maxCos maxCos)
(-
(/
(+
(* (* (- ux 1.0) ux) 2.0)
(/ (* (* (- (/ 2.0 ux) 1.0) ux) ux) maxCos))
maxCos)
(* ux ux))))
(sin (* (* 2.0 uy_m) (PI))))))))\begin{array}{l}
uy\_m = \left|uy\right|
\\
uy\_s = \mathsf{copysign}\left(1, uy\right)
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
uy\_s \cdot \begin{array}{l}
\mathbf{if}\;maxCos \leq 7.99999974612418 \cdot 10^{-20}:\\
\;\;\;\;\sqrt{\left(ux \cdot ux\right) \cdot \left(\frac{\mathsf{fma}\left(-2, maxCos, 2\right)}{ux} - {\left(maxCos - 1\right)}^{2}\right)} \cdot \sin \left(\left(\left(t\_0 \cdot 2\right) \cdot uy\_m\right) \cdot t\_0\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(maxCos \cdot maxCos\right) \cdot \left(\frac{\left(\left(ux - 1\right) \cdot ux\right) \cdot 2 + \frac{\left(\left(\frac{2}{ux} - 1\right) \cdot ux\right) \cdot ux}{maxCos}}{maxCos} - ux \cdot ux\right)} \cdot \sin \left(\left(2 \cdot uy\_m\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
\end{array}
if maxCos < 7.99999975e-20Initial program 54.9%
lift-*.f32N/A
lift-PI.f32N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
lower-*.f32N/A
lower-*.f32N/A
lift-PI.f32N/A
lower-sqrt.f32N/A
lift-PI.f32N/A
lower-sqrt.f3254.9
Applied rewrites54.9%
Taylor expanded in ux around inf
Applied rewrites12.8%
if 7.99999975e-20 < maxCos Initial program 57.9%
Taylor expanded in maxCos around -inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites55.8%
Taylor expanded in ux around inf
Applied rewrites98.0%
Final simplification54.5%
uy\_m = (fabs.f32 uy)
uy\_s = (copysign.f32 #s(literal 1 binary32) uy)
(FPCore (uy_s ux uy_m maxCos)
:precision binary32
(let* ((t_0 (- (* ux maxCos) (- ux 1.0))))
(*
uy_s
(if (<= t_0 0.9998199939727783)
(*
(sqrt (- 1.0 (* (- 1.0 (- ux (* ux maxCos))) t_0)))
(sin (* (* 2.0 uy_m) (PI))))
(*
(sqrt (* (+ (* -2.0 maxCos) 2.0) ux))
(sin (* (+ uy_m uy_m) (PI))))))))\begin{array}{l}
uy\_m = \left|uy\right|
\\
uy\_s = \mathsf{copysign}\left(1, uy\right)
\\
\begin{array}{l}
t_0 := ux \cdot maxCos - \left(ux - 1\right)\\
uy\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq 0.9998199939727783:\\
\;\;\;\;\sqrt{1 - \left(1 - \left(ux - ux \cdot maxCos\right)\right) \cdot t\_0} \cdot \sin \left(\left(2 \cdot uy\_m\right) \cdot \mathsf{PI}\left(\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(-2 \cdot maxCos + 2\right) \cdot ux} \cdot \sin \left(\left(uy\_m + uy\_m\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
\end{array}
if (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) < 0.999819994Initial program 90.5%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lower--.f3290.6
lift-*.f32N/A
*-commutativeN/A
lower-*.f3290.6
Applied rewrites90.6%
if 0.999819994 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 35.1%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f3234.4
Applied rewrites34.4%
Applied rewrites92.6%
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lift-*.f32N/A
count-2N/A
lift-*.f32N/A
lift-*.f32N/A
distribute-lft-outN/A
lower-*.f32N/A
lower-+.f3292.6
Applied rewrites92.6%
Final simplification91.8%
uy\_m = (fabs.f32 uy)
uy\_s = (copysign.f32 #s(literal 1 binary32) uy)
(FPCore (uy_s ux uy_m maxCos)
:precision binary32
(let* ((t_0 (- (- ux 1.0) (* ux maxCos))))
(*
uy_s
(if (<= (- (* ux maxCos) (- ux 1.0)) 0.9998199939727783)
(* (sqrt (- 1.0 (* t_0 t_0))) (sin (* (* 2.0 uy_m) (PI))))
(*
(sqrt (* (+ (* -2.0 maxCos) 2.0) ux))
(sin (* (+ uy_m uy_m) (PI))))))))\begin{array}{l}
uy\_m = \left|uy\right|
\\
uy\_s = \mathsf{copysign}\left(1, uy\right)
\\
\begin{array}{l}
t_0 := \left(ux - 1\right) - ux \cdot maxCos\\
uy\_s \cdot \begin{array}{l}
\mathbf{if}\;ux \cdot maxCos - \left(ux - 1\right) \leq 0.9998199939727783:\\
\;\;\;\;\sqrt{1 - t\_0 \cdot t\_0} \cdot \sin \left(\left(2 \cdot uy\_m\right) \cdot \mathsf{PI}\left(\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(-2 \cdot maxCos + 2\right) \cdot ux} \cdot \sin \left(\left(uy\_m + uy\_m\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
\end{array}
if (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) < 0.999819994Initial program 90.5%
if 0.999819994 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 35.1%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f3234.4
Applied rewrites34.4%
Applied rewrites92.6%
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lift-*.f32N/A
count-2N/A
lift-*.f32N/A
lift-*.f32N/A
distribute-lft-outN/A
lower-*.f32N/A
lower-+.f3292.6
Applied rewrites92.6%
Final simplification91.8%
uy\_m = (fabs.f32 uy)
uy\_s = (copysign.f32 #s(literal 1 binary32) uy)
(FPCore (uy_s ux uy_m maxCos)
:precision binary32
(*
uy_s
(if (<= (- (* ux maxCos) (- ux 1.0)) 0.9998199939727783)
(*
(sqrt (- 1.0 (* (- 1.0 ux) (- 1.0 (- ux (* ux maxCos))))))
(sin (* (* 2.0 uy_m) (PI))))
(* (sqrt (* (+ (* -2.0 maxCos) 2.0) ux)) (sin (* (+ uy_m uy_m) (PI)))))))\begin{array}{l}
uy\_m = \left|uy\right|
\\
uy\_s = \mathsf{copysign}\left(1, uy\right)
\\
uy\_s \cdot \begin{array}{l}
\mathbf{if}\;ux \cdot maxCos - \left(ux - 1\right) \leq 0.9998199939727783:\\
\;\;\;\;\sqrt{1 - \left(1 - ux\right) \cdot \left(1 - \left(ux - ux \cdot maxCos\right)\right)} \cdot \sin \left(\left(2 \cdot uy\_m\right) \cdot \mathsf{PI}\left(\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(-2 \cdot maxCos + 2\right) \cdot ux} \cdot \sin \left(\left(uy\_m + uy\_m\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) < 0.999819994Initial program 90.5%
Taylor expanded in maxCos around 0
lower--.f3286.8
Applied rewrites86.8%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lower--.f3286.9
lift-*.f32N/A
*-commutativeN/A
lower-*.f3286.9
Applied rewrites86.9%
if 0.999819994 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 35.1%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f3234.4
Applied rewrites34.4%
Applied rewrites92.6%
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lift-*.f32N/A
count-2N/A
lift-*.f32N/A
lift-*.f32N/A
distribute-lft-outN/A
lower-*.f32N/A
lower-+.f3292.6
Applied rewrites92.6%
Final simplification90.4%
uy\_m = (fabs.f32 uy)
uy\_s = (copysign.f32 #s(literal 1 binary32) uy)
(FPCore (uy_s ux uy_m maxCos)
:precision binary32
(let* ((t_0 (- (* ux maxCos) (- ux 1.0))))
(*
uy_s
(if (<= t_0 0.9998199939727783)
(* (sqrt (- 1.0 (* (- 1.0 ux) t_0))) (sin (* (* 2.0 uy_m) (PI))))
(*
(sqrt (* (+ (* -2.0 maxCos) 2.0) ux))
(sin (* (+ uy_m uy_m) (PI))))))))\begin{array}{l}
uy\_m = \left|uy\right|
\\
uy\_s = \mathsf{copysign}\left(1, uy\right)
\\
\begin{array}{l}
t_0 := ux \cdot maxCos - \left(ux - 1\right)\\
uy\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq 0.9998199939727783:\\
\;\;\;\;\sqrt{1 - \left(1 - ux\right) \cdot t\_0} \cdot \sin \left(\left(2 \cdot uy\_m\right) \cdot \mathsf{PI}\left(\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(-2 \cdot maxCos + 2\right) \cdot ux} \cdot \sin \left(\left(uy\_m + uy\_m\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
\end{array}
if (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) < 0.999819994Initial program 90.5%
Taylor expanded in maxCos around 0
lower--.f3286.8
Applied rewrites86.8%
if 0.999819994 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 35.1%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f3234.4
Applied rewrites34.4%
Applied rewrites92.6%
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lift-*.f32N/A
count-2N/A
lift-*.f32N/A
lift-*.f32N/A
distribute-lft-outN/A
lower-*.f32N/A
lower-+.f3292.6
Applied rewrites92.6%
Final simplification90.4%
uy\_m = (fabs.f32 uy)
uy\_s = (copysign.f32 #s(literal 1 binary32) uy)
(FPCore (uy_s ux uy_m maxCos)
:precision binary32
(*
uy_s
(if (<= (- (* ux maxCos) (- ux 1.0)) 0.9998199939727783)
(* (sqrt (- 1.0 (* (- 1.0 ux) (- 1.0 ux)))) (sin (* (* 2.0 uy_m) (PI))))
(* (sqrt (* (+ (* -2.0 maxCos) 2.0) ux)) (sin (* (+ uy_m uy_m) (PI)))))))\begin{array}{l}
uy\_m = \left|uy\right|
\\
uy\_s = \mathsf{copysign}\left(1, uy\right)
\\
uy\_s \cdot \begin{array}{l}
\mathbf{if}\;ux \cdot maxCos - \left(ux - 1\right) \leq 0.9998199939727783:\\
\;\;\;\;\sqrt{1 - \left(1 - ux\right) \cdot \left(1 - ux\right)} \cdot \sin \left(\left(2 \cdot uy\_m\right) \cdot \mathsf{PI}\left(\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(-2 \cdot maxCos + 2\right) \cdot ux} \cdot \sin \left(\left(uy\_m + uy\_m\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) < 0.999819994Initial program 90.5%
Taylor expanded in maxCos around 0
lower--.f3286.8
Applied rewrites86.8%
Taylor expanded in maxCos around 0
lower--.f3286.4
Applied rewrites86.4%
if 0.999819994 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 35.1%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f3234.4
Applied rewrites34.4%
Applied rewrites92.6%
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lift-*.f32N/A
count-2N/A
lift-*.f32N/A
lift-*.f32N/A
distribute-lft-outN/A
lower-*.f32N/A
lower-+.f3292.6
Applied rewrites92.6%
Final simplification90.2%
uy\_m = (fabs.f32 uy)
uy\_s = (copysign.f32 #s(literal 1 binary32) uy)
(FPCore (uy_s ux uy_m maxCos)
:precision binary32
(let* ((t_0 (- (* ux maxCos) (- ux 1.0))))
(*
uy_s
(if (<= t_0 0.9998059868812561)
(*
(sqrt (- 1.0 (* (* (- (+ (/ 1.0 ux) maxCos) 1.0) ux) t_0)))
(* (* (PI) 2.0) uy_m))
(*
(sqrt (* (+ (* -2.0 maxCos) 2.0) ux))
(sin (* (+ uy_m uy_m) (PI))))))))\begin{array}{l}
uy\_m = \left|uy\right|
\\
uy\_s = \mathsf{copysign}\left(1, uy\right)
\\
\begin{array}{l}
t_0 := ux \cdot maxCos - \left(ux - 1\right)\\
uy\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq 0.9998059868812561:\\
\;\;\;\;\sqrt{1 - \left(\left(\left(\frac{1}{ux} + maxCos\right) - 1\right) \cdot ux\right) \cdot t\_0} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\_m\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(-2 \cdot maxCos + 2\right) \cdot ux} \cdot \sin \left(\left(uy\_m + uy\_m\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
\end{array}
if (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) < 0.999805987Initial program 90.8%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower-/.f3290.6
Applied rewrites90.6%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3275.3
Applied rewrites75.3%
if 0.999805987 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 35.6%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f3234.1
Applied rewrites34.1%
Applied rewrites92.3%
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lift-*.f32N/A
count-2N/A
lift-*.f32N/A
lift-*.f32N/A
distribute-lft-outN/A
lower-*.f32N/A
lower-+.f3292.3
Applied rewrites92.3%
Final simplification85.9%
uy\_m = (fabs.f32 uy)
uy\_s = (copysign.f32 #s(literal 1 binary32) uy)
(FPCore (uy_s ux uy_m maxCos)
:precision binary32
(let* ((t_0 (- (* ux maxCos) (- ux 1.0))))
(*
uy_s
(if (<= t_0 0.9998059868812561)
(*
(sqrt (- 1.0 (* (* (- (+ (/ 1.0 ux) maxCos) 1.0) ux) t_0)))
(* (* (PI) 2.0) uy_m))
(* (sqrt (* 2.0 ux)) (sin (* (* 2.0 uy_m) (PI))))))))\begin{array}{l}
uy\_m = \left|uy\right|
\\
uy\_s = \mathsf{copysign}\left(1, uy\right)
\\
\begin{array}{l}
t_0 := ux \cdot maxCos - \left(ux - 1\right)\\
uy\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq 0.9998059868812561:\\
\;\;\;\;\sqrt{1 - \left(\left(\left(\frac{1}{ux} + maxCos\right) - 1\right) \cdot ux\right) \cdot t\_0} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\_m\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{2 \cdot ux} \cdot \sin \left(\left(2 \cdot uy\_m\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
\end{array}
if (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) < 0.999805987Initial program 90.8%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower-/.f3290.6
Applied rewrites90.6%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3275.3
Applied rewrites75.3%
if 0.999805987 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 35.6%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f3234.1
Applied rewrites34.1%
Taylor expanded in maxCos around 0
Applied rewrites88.2%
Final simplification83.3%
uy\_m = (fabs.f32 uy)
uy\_s = (copysign.f32 #s(literal 1 binary32) uy)
(FPCore (uy_s ux uy_m maxCos)
:precision binary32
(let* ((t_0 (* (* (PI) 2.0) uy_m)) (t_1 (- (* ux maxCos) (- ux 1.0))))
(*
uy_s
(if (<= t_1 0.9999169707298279)
(* (sqrt (- 1.0 (* (* (- (+ (/ 1.0 ux) maxCos) 1.0) ux) t_1))) t_0)
(* t_0 (sqrt (* (+ (* -2.0 maxCos) 2.0) ux)))))))\begin{array}{l}
uy\_m = \left|uy\right|
\\
uy\_s = \mathsf{copysign}\left(1, uy\right)
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\_m\\
t_1 := ux \cdot maxCos - \left(ux - 1\right)\\
uy\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_1 \leq 0.9999169707298279:\\
\;\;\;\;\sqrt{1 - \left(\left(\left(\frac{1}{ux} + maxCos\right) - 1\right) \cdot ux\right) \cdot t\_1} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sqrt{\left(-2 \cdot maxCos + 2\right) \cdot ux}\\
\end{array}
\end{array}
\end{array}
if (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) < 0.999916971Initial program 89.4%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower-/.f3289.2
Applied rewrites89.2%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3274.7
Applied rewrites74.7%
if 0.999916971 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 33.7%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3232.5
Applied rewrites32.5%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3275.4
Applied rewrites75.4%
Applied rewrites78.8%
Final simplification77.1%
uy\_m = (fabs.f32 uy)
uy\_s = (copysign.f32 #s(literal 1 binary32) uy)
(FPCore (uy_s ux uy_m maxCos)
:precision binary32
(let* ((t_0 (* (* (PI) 2.0) uy_m)) (t_1 (- (* ux maxCos) (- ux 1.0))))
(*
uy_s
(if (<= t_1 0.9998199939727783)
(* t_0 (sqrt (- 1.0 (* (- 1.0 ux) t_1))))
(* t_0 (sqrt (* (+ (* -2.0 maxCos) 2.0) ux)))))))\begin{array}{l}
uy\_m = \left|uy\right|
\\
uy\_s = \mathsf{copysign}\left(1, uy\right)
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\_m\\
t_1 := ux \cdot maxCos - \left(ux - 1\right)\\
uy\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_1 \leq 0.9998199939727783:\\
\;\;\;\;t\_0 \cdot \sqrt{1 - \left(1 - ux\right) \cdot t\_1}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sqrt{\left(-2 \cdot maxCos + 2\right) \cdot ux}\\
\end{array}
\end{array}
\end{array}
if (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) < 0.999819994Initial program 90.5%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3275.1
Applied rewrites75.1%
Taylor expanded in maxCos around 0
lower--.f3272.7
Applied rewrites72.7%
if 0.999819994 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 35.1%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3233.8
Applied rewrites33.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.9%
Applied rewrites78.4%
Final simplification76.2%
uy\_m = (fabs.f32 uy)
uy\_s = (copysign.f32 #s(literal 1 binary32) uy)
(FPCore (uy_s ux uy_m maxCos)
:precision binary32
(let* ((t_0 (* (* (PI) 2.0) uy_m)))
(*
uy_s
(if (<= ux 0.00018000000272877514)
(* t_0 (sqrt (* (+ (* -2.0 maxCos) 2.0) ux)))
(*
t_0
(sqrt
(-
1.0
(* (- 1.0 (- ux (* ux maxCos))) (- (* ux maxCos) (- ux 1.0))))))))))\begin{array}{l}
uy\_m = \left|uy\right|
\\
uy\_s = \mathsf{copysign}\left(1, uy\right)
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\_m\\
uy\_s \cdot \begin{array}{l}
\mathbf{if}\;ux \leq 0.00018000000272877514:\\
\;\;\;\;t\_0 \cdot \sqrt{\left(-2 \cdot maxCos + 2\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sqrt{1 - \left(1 - \left(ux - ux \cdot maxCos\right)\right) \cdot \left(ux \cdot maxCos - \left(ux - 1\right)\right)}\\
\end{array}
\end{array}
\end{array}
if ux < 1.80000003e-4Initial program 35.1%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3233.8
Applied rewrites33.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.9%
Applied rewrites78.4%
if 1.80000003e-4 < ux Initial program 90.5%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3275.1
Applied rewrites75.1%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lower--.f3275.1
lift-*.f32N/A
*-commutativeN/A
lower-*.f3275.1
Applied rewrites75.1%
Final simplification77.1%
uy\_m = (fabs.f32 uy)
uy\_s = (copysign.f32 #s(literal 1 binary32) uy)
(FPCore (uy_s ux uy_m maxCos)
:precision binary32
(let* ((t_0 (* (* (PI) 2.0) uy_m)) (t_1 (- (- ux 1.0) (* ux maxCos))))
(*
uy_s
(if (<= ux 0.00018000000272877514)
(* t_0 (sqrt (* (+ (* -2.0 maxCos) 2.0) ux)))
(* t_0 (sqrt (- 1.0 (* t_1 t_1))))))))\begin{array}{l}
uy\_m = \left|uy\right|
\\
uy\_s = \mathsf{copysign}\left(1, uy\right)
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\_m\\
t_1 := \left(ux - 1\right) - ux \cdot maxCos\\
uy\_s \cdot \begin{array}{l}
\mathbf{if}\;ux \leq 0.00018000000272877514:\\
\;\;\;\;t\_0 \cdot \sqrt{\left(-2 \cdot maxCos + 2\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sqrt{1 - t\_1 \cdot t\_1}\\
\end{array}
\end{array}
\end{array}
if ux < 1.80000003e-4Initial program 35.1%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3233.8
Applied rewrites33.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.9%
Applied rewrites78.4%
if 1.80000003e-4 < ux Initial program 90.5%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3275.1
Applied rewrites75.1%
Final simplification77.1%
uy\_m = (fabs.f32 uy)
uy\_s = (copysign.f32 #s(literal 1 binary32) uy)
(FPCore (uy_s ux uy_m maxCos)
:precision binary32
(let* ((t_0 (* (* (PI) 2.0) uy_m)))
(*
uy_s
(if (<= (- (* ux maxCos) (- ux 1.0)) 0.9998199939727783)
(* (sqrt (- 1.0 (* (- ux 1.0) (- ux 1.0)))) t_0)
(* t_0 (sqrt (* (+ (* -2.0 maxCos) 2.0) ux)))))))\begin{array}{l}
uy\_m = \left|uy\right|
\\
uy\_s = \mathsf{copysign}\left(1, uy\right)
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\_m\\
uy\_s \cdot \begin{array}{l}
\mathbf{if}\;ux \cdot maxCos - \left(ux - 1\right) \leq 0.9998199939727783:\\
\;\;\;\;\sqrt{1 - \left(ux - 1\right) \cdot \left(ux - 1\right)} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sqrt{\left(-2 \cdot maxCos + 2\right) \cdot ux}\\
\end{array}
\end{array}
\end{array}
if (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) < 0.999819994Initial program 90.5%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3275.1
Applied rewrites75.1%
Taylor expanded in ux around 0
Applied rewrites6.9%
Taylor expanded in maxCos around -inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites41.8%
Taylor expanded in maxCos around 0
Applied rewrites72.4%
if 0.999819994 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 35.1%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3233.8
Applied rewrites33.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.9%
Applied rewrites78.4%
Final simplification76.1%
uy\_m = (fabs.f32 uy) uy\_s = (copysign.f32 #s(literal 1 binary32) uy) (FPCore (uy_s ux uy_m maxCos) :precision binary32 (* uy_s (* (* (* (PI) 2.0) uy_m) (sqrt (* (+ (* -2.0 maxCos) 2.0) ux)))))
\begin{array}{l}
uy\_m = \left|uy\right|
\\
uy\_s = \mathsf{copysign}\left(1, uy\right)
\\
uy\_s \cdot \left(\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\_m\right) \cdot \sqrt{\left(-2 \cdot maxCos + 2\right) \cdot ux}\right)
\end{array}
Initial program 56.3%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3249.6
Applied rewrites49.6%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3264.6
Applied rewrites64.6%
Applied rewrites66.9%
uy\_m = (fabs.f32 uy) uy\_s = (copysign.f32 #s(literal 1 binary32) uy) (FPCore (uy_s ux uy_m maxCos) :precision binary32 (* uy_s (* (sqrt (* 2.0 ux)) (* (+ uy_m uy_m) (PI)))))
\begin{array}{l}
uy\_m = \left|uy\right|
\\
uy\_s = \mathsf{copysign}\left(1, uy\right)
\\
uy\_s \cdot \left(\sqrt{2 \cdot ux} \cdot \left(\left(uy\_m + uy\_m\right) \cdot \mathsf{PI}\left(\right)\right)\right)
\end{array}
Initial program 56.3%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3249.6
Applied rewrites49.6%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3264.6
Applied rewrites64.6%
Taylor expanded in maxCos around 0
Applied rewrites64.6%
Applied rewrites64.6%
Final simplification64.6%
herbie shell --seed 2024250
(FPCore (ux uy maxCos)
:name "UniformSampleCone, y"
: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)))
(* (sin (* (* uy 2.0) (PI))) (sqrt (- 1.0 (* (+ (- 1.0 ux) (* ux maxCos)) (+ (- 1.0 ux) (* ux maxCos)))))))