
(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 13 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}
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (* uy 2.0) 0.004000000189989805)
(*
(* (* (PI) 2.0) uy)
(sqrt
(*
(/ (- (- 2.0 (* (pow (- maxCos 1.0) 2.0) ux)) (* 2.0 maxCos)) ux)
(* ux ux))))
(* (sin (* (* uy 2.0) (PI))) (sqrt (* ux (* 2.0 (- 1.0 maxCos)))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \cdot 2 \leq 0.004000000189989805:\\
\;\;\;\;\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{\frac{\left(2 - {\left(maxCos - 1\right)}^{2} \cdot ux\right) - 2 \cdot maxCos}{ux} \cdot \left(ux \cdot ux\right)}\\
\mathbf{else}:\\
\;\;\;\;\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{ux \cdot \left(2 \cdot \left(1 - maxCos\right)\right)}\\
\end{array}
\end{array}
if (*.f32 uy #s(literal 2 binary32)) < 0.00400000019Initial program 60.3%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3259.7
Applied rewrites59.7%
lift-*.f32N/A
lift-+.f32N/A
distribute-lft-inN/A
+-commutativeN/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
*-commutativeN/A
lower-*.f3257.1
Applied rewrites55.2%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites88.9%
Taylor expanded in ux around 0
Applied rewrites96.6%
if 0.00400000019 < (*.f32 uy #s(literal 2 binary32)) Initial program 57.0%
lift-*.f32N/A
sqr-abs-revN/A
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
fabs-subN/A
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
fabs-subN/A
sqr-absN/A
lower-*.f32N/A
lower--.f32N/A
lower--.f32N/A
lift-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
lower--.f3257.2
lift-*.f32N/A
*-commutativeN/A
lower-*.f3257.2
Applied rewrites57.2%
Taylor expanded in ux around 0
count-2-revN/A
distribute-lft-outN/A
count-2-revN/A
metadata-evalN/A
lower-*.f32N/A
metadata-evalN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower-*.f32N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f3277.2
Applied rewrites77.2%
Final simplification91.4%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (* (/ maxCos ux) 2.0))
(t_1 (* (+ -1.0 maxCos) (- maxCos 1.0)))
(t_2 (- t_0 t_1)))
(if (<= maxCos 9.999999747378752e-6)
(*
(sin (* (* (PI) uy) 2.0))
(sqrt
(*
(-
(/ 2.0 ux)
(fma (/ maxCos ux) 2.0 (* (- maxCos 1.0) (- maxCos 1.0))))
(* ux ux))))
(*
(* (* (PI) 2.0) uy)
(sqrt
(*
(/ (- (* 2.0 t_2) (* ux (- (pow t_0 2.0) (pow t_1 2.0)))) (* ux t_2))
(* ux ux)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{maxCos}{ux} \cdot 2\\
t_1 := \left(-1 + maxCos\right) \cdot \left(maxCos - 1\right)\\
t_2 := t\_0 - t\_1\\
\mathbf{if}\;maxCos \leq 9.999999747378752 \cdot 10^{-6}:\\
\;\;\;\;\sin \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right) \cdot \sqrt{\left(\frac{2}{ux} - \mathsf{fma}\left(\frac{maxCos}{ux}, 2, \left(maxCos - 1\right) \cdot \left(maxCos - 1\right)\right)\right) \cdot \left(ux \cdot ux\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{\frac{2 \cdot t\_2 - ux \cdot \left({t\_0}^{2} - {t\_1}^{2}\right)}{ux \cdot t\_2} \cdot \left(ux \cdot ux\right)}\\
\end{array}
\end{array}
if maxCos < 9.99999975e-6Initial program 58.7%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3251.8
Applied rewrites51.8%
lift-*.f32N/A
lift-+.f32N/A
distribute-lft-inN/A
+-commutativeN/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
*-commutativeN/A
lower-*.f3251.8
Applied rewrites51.7%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites81.1%
Taylor expanded in uy around inf
lower-sin.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3274.5
Applied rewrites74.6%
if 9.99999975e-6 < maxCos Initial program 63.8%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3257.8
Applied rewrites57.8%
lift-*.f32N/A
lift-+.f32N/A
distribute-lft-inN/A
+-commutativeN/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
*-commutativeN/A
lower-*.f3244.2
Applied rewrites42.7%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites50.6%
Applied rewrites87.1%
Final simplification60.6%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= maxCos 9.999999747378752e-6)
(*
(sin (* (* (PI) uy) 2.0))
(sqrt
(*
(- (/ 2.0 ux) (fma (/ maxCos ux) 2.0 (* (- maxCos 1.0) (- maxCos 1.0))))
(* ux ux))))
(*
(* (* (PI) 2.0) uy)
(sqrt
(*
(/ (- (- 2.0 (* (pow (- maxCos 1.0) 2.0) ux)) (* 2.0 maxCos)) ux)
(* ux ux))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 9.999999747378752 \cdot 10^{-6}:\\
\;\;\;\;\sin \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right) \cdot \sqrt{\left(\frac{2}{ux} - \mathsf{fma}\left(\frac{maxCos}{ux}, 2, \left(maxCos - 1\right) \cdot \left(maxCos - 1\right)\right)\right) \cdot \left(ux \cdot ux\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{\frac{\left(2 - {\left(maxCos - 1\right)}^{2} \cdot ux\right) - 2 \cdot maxCos}{ux} \cdot \left(ux \cdot ux\right)}\\
\end{array}
\end{array}
if maxCos < 9.99999975e-6Initial program 58.7%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3251.8
Applied rewrites51.8%
lift-*.f32N/A
lift-+.f32N/A
distribute-lft-inN/A
+-commutativeN/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
*-commutativeN/A
lower-*.f3251.8
Applied rewrites49.8%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites81.1%
Taylor expanded in uy around inf
lower-sin.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3274.6
Applied rewrites74.5%
if 9.99999975e-6 < maxCos Initial program 63.8%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3257.8
Applied rewrites57.8%
lift-*.f32N/A
lift-+.f32N/A
distribute-lft-inN/A
+-commutativeN/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
*-commutativeN/A
lower-*.f3244.2
Applied rewrites34.5%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites50.6%
Taylor expanded in ux around 0
Applied rewrites87.0%
Final simplification61.4%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (* uy 2.0) 0.004000000189989805)
(*
(* (* (PI) 2.0) uy)
(sqrt (* (- (- 2.0 (* (pow (- maxCos 1.0) 2.0) ux)) (* 2.0 maxCos)) ux)))
(* (sin (* (* uy 2.0) (PI))) (sqrt (* ux (* 2.0 (- 1.0 maxCos)))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \cdot 2 \leq 0.004000000189989805:\\
\;\;\;\;\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{\left(\left(2 - {\left(maxCos - 1\right)}^{2} \cdot ux\right) - 2 \cdot maxCos\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{ux \cdot \left(2 \cdot \left(1 - maxCos\right)\right)}\\
\end{array}
\end{array}
if (*.f32 uy #s(literal 2 binary32)) < 0.00400000019Initial program 60.3%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3259.7
Applied rewrites59.7%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lower--.f3259.8
lift-*.f32N/A
*-commutativeN/A
lower-*.f3259.8
Applied rewrites59.8%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
associate-*r*N/A
mul-1-negN/A
fp-cancel-sub-signN/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-pow.f32N/A
lower--.f32N/A
lower-*.f3296.5
Applied rewrites96.5%
if 0.00400000019 < (*.f32 uy #s(literal 2 binary32)) Initial program 57.0%
lift-*.f32N/A
sqr-abs-revN/A
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
fabs-subN/A
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
fabs-subN/A
sqr-absN/A
lower-*.f32N/A
lower--.f32N/A
lower--.f32N/A
lift-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
lower--.f3257.2
lift-*.f32N/A
*-commutativeN/A
lower-*.f3257.2
Applied rewrites57.2%
Taylor expanded in ux around 0
count-2-revN/A
distribute-lft-outN/A
count-2-revN/A
metadata-evalN/A
lower-*.f32N/A
metadata-evalN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower-*.f32N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f3277.2
Applied rewrites77.2%
Final simplification91.4%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (* uy 2.0) 0.004000000189989805)
(*
(sqrt
(*
(* ux ux)
(- (/ (- 2.0 (* maxCos 2.0)) ux) (* (+ -1.0 maxCos) (- maxCos 1.0)))))
(* (* (PI) 2.0) uy))
(* (sin (* (* uy 2.0) (PI))) (sqrt (* ux (* 2.0 (- 1.0 maxCos)))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \cdot 2 \leq 0.004000000189989805:\\
\;\;\;\;\sqrt{\left(ux \cdot ux\right) \cdot \left(\frac{2 - maxCos \cdot 2}{ux} - \left(-1 + maxCos\right) \cdot \left(maxCos - 1\right)\right)} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right)\\
\mathbf{else}:\\
\;\;\;\;\sin \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{ux \cdot \left(2 \cdot \left(1 - maxCos\right)\right)}\\
\end{array}
\end{array}
if (*.f32 uy #s(literal 2 binary32)) < 0.00400000019Initial program 60.3%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3259.7
Applied rewrites59.7%
lift-*.f32N/A
lift-+.f32N/A
distribute-lft-inN/A
+-commutativeN/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
*-commutativeN/A
lower-*.f3257.1
Applied rewrites55.8%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites88.9%
lift-*.f32N/A
*-commutativeN/A
lower-*.f3289.0
Applied rewrites96.4%
if 0.00400000019 < (*.f32 uy #s(literal 2 binary32)) Initial program 57.0%
lift-*.f32N/A
sqr-abs-revN/A
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
fabs-subN/A
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
fabs-subN/A
sqr-absN/A
lower-*.f32N/A
lower--.f32N/A
lower--.f32N/A
lift-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
lower--.f3257.2
lift-*.f32N/A
*-commutativeN/A
lower-*.f3257.2
Applied rewrites57.2%
Taylor expanded in ux around 0
count-2-revN/A
distribute-lft-outN/A
count-2-revN/A
metadata-evalN/A
lower-*.f32N/A
metadata-evalN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower-*.f32N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f3277.2
Applied rewrites77.2%
Final simplification91.3%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (* uy 2.0) 0.004000000189989805)
(*
(sqrt
(*
(* ux ux)
(- (/ (- 2.0 (* maxCos 2.0)) ux) (* (+ -1.0 maxCos) (- maxCos 1.0)))))
(* (* (PI) 2.0) uy))
(* (sin (* (* (PI) uy) 2.0)) (sqrt (* (fma -2.0 maxCos 2.0) ux)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \cdot 2 \leq 0.004000000189989805:\\
\;\;\;\;\sqrt{\left(ux \cdot ux\right) \cdot \left(\frac{2 - maxCos \cdot 2}{ux} - \left(-1 + maxCos\right) \cdot \left(maxCos - 1\right)\right)} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right)\\
\mathbf{else}:\\
\;\;\;\;\sin \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right) \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}\\
\end{array}
\end{array}
if (*.f32 uy #s(literal 2 binary32)) < 0.00400000019Initial program 60.3%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3259.7
Applied rewrites59.7%
lift-*.f32N/A
lift-+.f32N/A
distribute-lft-inN/A
+-commutativeN/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
*-commutativeN/A
lower-*.f3257.1
Applied rewrites53.1%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites88.9%
lift-*.f32N/A
*-commutativeN/A
lower-*.f3289.0
Applied rewrites96.4%
if 0.00400000019 < (*.f32 uy #s(literal 2 binary32)) Initial program 57.0%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower-/.f3258.4
Applied rewrites58.4%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
lower-sin.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-sqrt.f32N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3210.7
Applied rewrites9.6%
(FPCore (ux uy maxCos)
:precision binary32
(*
(sqrt
(*
(* ux ux)
(- (/ (- 2.0 (* maxCos 2.0)) ux) (* (+ -1.0 maxCos) (- maxCos 1.0)))))
(* (* (PI) 2.0) uy)))\begin{array}{l}
\\
\sqrt{\left(ux \cdot ux\right) \cdot \left(\frac{2 - maxCos \cdot 2}{ux} - \left(-1 + maxCos\right) \cdot \left(maxCos - 1\right)\right)} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right)
\end{array}
Initial program 59.4%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3252.7
Applied rewrites52.7%
lift-*.f32N/A
lift-+.f32N/A
distribute-lft-inN/A
+-commutativeN/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
*-commutativeN/A
lower-*.f3250.6
Applied rewrites49.0%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites76.6%
lift-*.f32N/A
*-commutativeN/A
lower-*.f3276.6
Applied rewrites82.3%
(FPCore (ux uy maxCos)
:precision binary32
(*
(* (* (PI) 2.0) uy)
(sqrt
(*
(* (- (/ (- 2.0 (* maxCos 2.0)) ux) (* (+ -1.0 maxCos) (- maxCos 1.0))) ux)
ux))))\begin{array}{l}
\\
\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{\left(\left(\frac{2 - maxCos \cdot 2}{ux} - \left(-1 + maxCos\right) \cdot \left(maxCos - 1\right)\right) \cdot ux\right) \cdot ux}
\end{array}
Initial program 59.4%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3252.7
Applied rewrites52.7%
lift-*.f32N/A
lift-+.f32N/A
distribute-lft-inN/A
+-commutativeN/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
*-commutativeN/A
lower-*.f3250.6
Applied rewrites50.4%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites76.6%
Applied rewrites82.3%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos))))
(if (<= t_0 0.9995999932289124)
(* (* (* (PI) 2.0) uy) (sqrt (- 1.0 (* t_0 (- 1.0 ux)))))
(* (* (* (* (sqrt 2.0) (PI)) uy) 2.0) (sqrt (* (- 1.0 maxCos) ux))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
\mathbf{if}\;t\_0 \leq 0.9995999932289124:\\
\;\;\;\;\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{1 - t\_0 \cdot \left(1 - ux\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\sqrt{2} \cdot \mathsf{PI}\left(\right)\right) \cdot uy\right) \cdot 2\right) \cdot \sqrt{\left(1 - maxCos\right) \cdot ux}\\
\end{array}
\end{array}
if (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) < 0.999599993Initial program 90.3%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3278.2
Applied rewrites78.2%
Taylor expanded in maxCos around 0
lower--.f3273.9
Applied rewrites73.9%
if 0.999599993 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 43.0%
lift-*.f32N/A
sqr-abs-revN/A
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
fabs-subN/A
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
fabs-subN/A
sqr-absN/A
lower-*.f32N/A
lower--.f32N/A
lower--.f32N/A
lift-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
lower--.f3243.1
lift-*.f32N/A
*-commutativeN/A
lower-*.f3243.1
Applied rewrites43.1%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-sqrt.f32N/A
lower-sin.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-sqrt.f32N/A
*-commutativeN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower-*.f32N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f3289.9
Applied rewrites89.9%
Taylor expanded in uy around 0
Applied rewrites76.0%
Final simplification75.3%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos))) (t_1 (* (* (PI) 2.0) uy)))
(if (<= t_0 0.9999099969863892)
(* t_1 (sqrt (- 1.0 (* t_0 (- 1.0 ux)))))
(* t_1 (sqrt (* (fma -2.0 maxCos 2.0) ux))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
t_1 := \left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\\
\mathbf{if}\;t\_0 \leq 0.9999099969863892:\\
\;\;\;\;t\_1 \cdot \sqrt{1 - t\_0 \cdot \left(1 - ux\right)}\\
\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.999909997Initial program 87.1%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3274.2
Applied rewrites74.2%
Taylor expanded in maxCos around 0
lower--.f3270.1
Applied rewrites70.1%
if 0.999909997 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 38.2%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3236.2
Applied rewrites36.2%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lower--.f3236.2
lift-*.f32N/A
*-commutativeN/A
lower-*.f3236.2
Applied rewrites36.2%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
lower-fma.f3274.0
Applied rewrites73.6%
Final simplification72.3%
(FPCore (ux uy maxCos) :precision binary32 (if (<= (+ (- 1.0 ux) (* ux maxCos)) 0.9999099969863892) (* (* (+ (PI) (PI)) uy) (sqrt (- 1.0 (* (- 1.0 ux) (- 1.0 ux))))) (* (* (* (PI) 2.0) uy) (sqrt (* (fma -2.0 maxCos 2.0) ux)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(1 - ux\right) + ux \cdot maxCos \leq 0.9999099969863892:\\
\;\;\;\;\left(\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right) \cdot uy\right) \cdot \sqrt{1 - \left(1 - ux\right) \cdot \left(1 - ux\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \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.999909997Initial program 87.1%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3274.2
Applied rewrites74.2%
Taylor expanded in maxCos around 0
lower--.f3270.1
Applied rewrites70.1%
Taylor expanded in maxCos around 0
lower--.f3269.6
Applied rewrites69.6%
Applied rewrites69.6%
if 0.999909997 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 38.2%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3236.2
Applied rewrites36.2%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lower--.f3236.2
lift-*.f32N/A
*-commutativeN/A
lower-*.f3236.2
Applied rewrites36.2%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
lower-fma.f3274.0
Applied rewrites73.6%
Final simplification72.1%
(FPCore (ux uy maxCos) :precision binary32 (* (* (* (PI) 2.0) uy) (sqrt (* (- (/ 2.0 ux) 1.0) (* ux ux)))))
\begin{array}{l}
\\
\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{\left(\frac{2}{ux} - 1\right) \cdot \left(ux \cdot ux\right)}
\end{array}
Initial program 59.4%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3252.7
Applied rewrites52.7%
lift-*.f32N/A
lift-+.f32N/A
distribute-lft-inN/A
+-commutativeN/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
*-commutativeN/A
lower-*.f3250.6
Applied rewrites48.5%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites76.6%
Taylor expanded in maxCos around 0
Applied rewrites76.7%
(FPCore (ux uy maxCos) :precision binary32 (* (* (* (PI) 2.0) uy) (sqrt (* (fma -2.0 maxCos 2.0) ux))))
\begin{array}{l}
\\
\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot uy\right) \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}
\end{array}
Initial program 59.4%
Taylor expanded in uy around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3252.7
Applied rewrites52.7%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lower--.f3252.8
lift-*.f32N/A
*-commutativeN/A
lower-*.f3252.8
Applied rewrites52.8%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
+-commutativeN/A
lower-fma.f3262.7
Applied rewrites62.7%
Final simplification62.7%
herbie shell --seed 2024326
(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)))))))