
(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}
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* (* uy 2.0) (PI))) (sqrt (* (- (/ (- 2.0 (* 2.0 maxCos)) ux) (pow (- maxCos 1.0) 2.0)) (* ux ux)))))
\begin{array}{l}
\\
\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(\frac{2 - 2 \cdot maxCos}{ux} - {\left(maxCos - 1\right)}^{2}\right) \cdot \left(ux \cdot ux\right)}
\end{array}
Initial program 54.8%
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
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3268.5
Applied rewrites68.8%
Applied rewrites98.8%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos))) (t_1 (cos (* (* uy 2.0) (PI)))))
(if (<= (* t_1 (sqrt (- 1.0 (* t_0 t_0)))) 0.017999999225139618)
(* t_1 (sqrt (* (fma -2.0 maxCos 2.0) ux)))
(*
(+ (* (* (* (PI) (PI)) uy) (* -2.0 uy)) 1.0)
(sqrt (- 1.0 (* t_0 (* (- (+ (/ 1.0 ux) maxCos) 1.0) ux))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
t_1 := \cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right)\\
\mathbf{if}\;t\_1 \cdot \sqrt{1 - t\_0 \cdot t\_0} \leq 0.017999999225139618:\\
\;\;\;\;t\_1 \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot uy\right) \cdot \left(-2 \cdot uy\right) + 1\right) \cdot \sqrt{1 - t\_0 \cdot \left(\left(\left(\frac{1}{ux} + maxCos\right) - 1\right) \cdot ux\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.0179999992Initial program 34.7%
Taylor expanded in ux around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3263.9
Applied rewrites63.3%
if 0.0179999992 < (*.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.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.f3278.0
Applied rewrites77.2%
Applied rewrites84.2%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower-/.f3284.4
Applied rewrites84.4%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* (* uy 2.0) (PI)))
(sqrt
(*
(- (/ (- (- 2.0 maxCos) maxCos) ux) (pow (- maxCos 1.0) 2.0))
(* ux ux)))))\begin{array}{l}
\\
\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(\frac{\left(2 - maxCos\right) - maxCos}{ux} - {\left(maxCos - 1\right)}^{2}\right) \cdot \left(ux \cdot ux\right)}
\end{array}
Initial program 54.8%
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
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3268.5
Applied rewrites68.8%
Applied rewrites98.8%
Applied rewrites98.8%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos))) (t_1 (* (PI) (PI))))
(if (<=
(* (cos (* (* uy 2.0) (PI))) (sqrt (- 1.0 (* t_0 t_0))))
0.019999999552965164)
(* (+ 1.0 (* (* (* t_1 uy) -2.0) uy)) (sqrt (* (fma -2.0 maxCos 2.0) ux)))
(* (fma (* (* uy uy) -2.0) t_1 1.0) (sqrt (- 1.0 (* t_0 (- 1.0 ux))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
t_1 := \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\\
\mathbf{if}\;\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{1 - t\_0 \cdot t\_0} \leq 0.019999999552965164:\\
\;\;\;\;\left(1 + \left(\left(t\_1 \cdot uy\right) \cdot -2\right) \cdot uy\right) \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(uy \cdot uy\right) \cdot -2, t\_1, 1\right) \cdot \sqrt{1 - t\_0 \cdot \left(1 - ux\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.0199999996Initial program 35.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.f3228.5
Applied rewrites28.2%
Taylor expanded in ux around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3269.8
Applied rewrites69.4%
Applied rewrites75.7%
if 0.0199999996 < (*.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.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.f3278.3
Applied rewrites77.5%
Taylor expanded in maxCos around 0
lower--.f3275.9
Applied rewrites75.9%
Final simplification75.8%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (- (/ 2.0 ux) 1.0)) (t_1 (cos (* (* uy 2.0) (PI)))))
(if (<= maxCos 1.199999957179898e-7)
(* t_1 (sqrt (* t_0 (* ux ux))))
(*
t_1
(sqrt
(*
(-
(* (* ux ux) (/ (+ (/ t_0 maxCos) (- 2.0 (/ 2.0 ux))) maxCos))
(* ux ux))
(* maxCos maxCos)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{ux} - 1\\
t_1 := \cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right)\\
\mathbf{if}\;maxCos \leq 1.199999957179898 \cdot 10^{-7}:\\
\;\;\;\;t\_1 \cdot \sqrt{t\_0 \cdot \left(ux \cdot ux\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_1 \cdot \sqrt{\left(\left(ux \cdot ux\right) \cdot \frac{\frac{t\_0}{maxCos} + \left(2 - \frac{2}{ux}\right)}{maxCos} - ux \cdot ux\right) \cdot \left(maxCos \cdot maxCos\right)}\\
\end{array}
\end{array}
if maxCos < 1.19999996e-7Initial program 54.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
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3272.0
Applied rewrites72.0%
Taylor expanded in maxCos around 0
Applied rewrites98.9%
if 1.19999996e-7 < maxCos Initial program 55.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
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3251.1
Applied rewrites51.1%
Applied rewrites98.4%
Taylor expanded in maxCos around inf
Applied rewrites98.1%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (cos (* (* uy 2.0) (PI)))))
(if (<= ux 2.499999936844688e-5)
(* t_0 (sqrt (* (fma -2.0 maxCos 2.0) ux)))
(* t_0 (sqrt (- 1.0 (* (+ (- 1.0 ux) (* ux maxCos)) (- 1.0 ux))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right)\\
\mathbf{if}\;ux \leq 2.499999936844688 \cdot 10^{-5}:\\
\;\;\;\;t\_0 \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(1 - ux\right)}\\
\end{array}
\end{array}
if ux < 2.49999994e-5Initial program 28.3%
Taylor expanded in ux around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3268.5
Applied rewrites68.5%
if 2.49999994e-5 < ux Initial program 86.7%
Taylor expanded in maxCos around 0
lower--.f3283.9
Applied rewrites83.9%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* (* uy 2.0) (PI))) (sqrt (* (- (/ 2.0 ux) 1.0) (* ux ux)))))
\begin{array}{l}
\\
\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(\frac{2}{ux} - 1\right) \cdot \left(ux \cdot ux\right)}
\end{array}
Initial program 54.8%
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
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower--.f32N/A
lower-/.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-pow.f32N/A
lower--.f32N/A
unpow2N/A
lower-*.f3268.5
Applied rewrites68.5%
Taylor expanded in maxCos around 0
Applied rewrites93.2%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (* (* (PI) (PI)) uy)) (t_1 (+ (- 1.0 ux) (* ux maxCos))))
(if (<= (* t_1 t_1) 0.9999449849128723)
(*
(+ (* t_0 (* -2.0 uy)) 1.0)
(sqrt (- 1.0 (* t_1 (* (- (+ (/ 1.0 ux) maxCos) 1.0) ux)))))
(* (+ 1.0 (* (* t_0 -2.0) uy)) (sqrt (* (fma -2.0 maxCos 2.0) ux))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot uy\\
t_1 := \left(1 - ux\right) + ux \cdot maxCos\\
\mathbf{if}\;t\_1 \cdot t\_1 \leq 0.9999449849128723:\\
\;\;\;\;\left(t\_0 \cdot \left(-2 \cdot uy\right) + 1\right) \cdot \sqrt{1 - t\_1 \cdot \left(\left(\left(\frac{1}{ux} + maxCos\right) - 1\right) \cdot ux\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \left(t\_0 \cdot -2\right) \cdot uy\right) \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}\\
\end{array}
\end{array}
if (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) < 0.999944985Initial program 86.9%
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.f3271.2
Applied rewrites70.5%
Applied rewrites77.1%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower-/.f3277.3
Applied rewrites77.3%
if 0.999944985 < (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) Initial program 28.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.f3226.2
Applied rewrites26.2%
Taylor expanded in ux around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3274.1
Applied rewrites74.1%
Applied rewrites73.7%
Final simplification78.7%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos))) (t_1 (* t_0 t_0)))
(if (<= t_1 0.9999449849128723)
(* (+ 1.0 (* (* (* (* uy uy) -2.0) (PI)) (PI))) (sqrt (- 1.0 t_1)))
(*
(+ 1.0 (* (* (* (* (PI) (PI)) uy) -2.0) uy))
(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 := t\_0 \cdot t\_0\\
\mathbf{if}\;t\_1 \leq 0.9999449849128723:\\
\;\;\;\;\left(1 + \left(\left(\left(uy \cdot uy\right) \cdot -2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{1 - t\_1}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot uy\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 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) < 0.999944985Initial program 86.9%
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.f3271.2
Applied rewrites70.5%
Applied rewrites77.1%
if 0.999944985 < (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) Initial program 28.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.f3226.2
Applied rewrites25.9%
Taylor expanded in ux around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3274.1
Applied rewrites73.6%
Applied rewrites66.7%
Final simplification78.6%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (* (* (PI) (PI)) uy))
(t_1 (+ (- 1.0 ux) (* ux maxCos)))
(t_2 (* t_1 t_1)))
(if (<= t_2 0.9999449849128723)
(* (+ (* t_0 (* -2.0 uy)) 1.0) (sqrt (- 1.0 t_2)))
(* (+ 1.0 (* (* t_0 -2.0) uy)) (sqrt (* (fma -2.0 maxCos 2.0) ux))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot uy\\
t_1 := \left(1 - ux\right) + ux \cdot maxCos\\
t_2 := t\_1 \cdot t\_1\\
\mathbf{if}\;t\_2 \leq 0.9999449849128723:\\
\;\;\;\;\left(t\_0 \cdot \left(-2 \cdot uy\right) + 1\right) \cdot \sqrt{1 - t\_2}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \left(t\_0 \cdot -2\right) \cdot uy\right) \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}\\
\end{array}
\end{array}
if (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) < 0.999944985Initial program 86.9%
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.f3271.2
Applied rewrites70.5%
Applied rewrites77.1%
if 0.999944985 < (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) Initial program 28.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.f3226.2
Applied rewrites25.9%
Taylor expanded in ux around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3274.1
Applied rewrites73.6%
Applied rewrites69.7%
Final simplification78.6%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (* (* (PI) (PI)) uy)) (t_1 (+ (- 1.0 ux) (* ux maxCos))))
(if (<= (* t_1 t_1) 0.9999449849128723)
(* (+ (* t_0 (* -2.0 uy)) 1.0) (sqrt (- 1.0 (* t_1 (- 1.0 ux)))))
(* (+ 1.0 (* (* t_0 -2.0) uy)) (sqrt (* (fma -2.0 maxCos 2.0) ux))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot uy\\
t_1 := \left(1 - ux\right) + ux \cdot maxCos\\
\mathbf{if}\;t\_1 \cdot t\_1 \leq 0.9999449849128723:\\
\;\;\;\;\left(t\_0 \cdot \left(-2 \cdot uy\right) + 1\right) \cdot \sqrt{1 - t\_1 \cdot \left(1 - ux\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \left(t\_0 \cdot -2\right) \cdot uy\right) \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}\\
\end{array}
\end{array}
if (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) < 0.999944985Initial program 86.9%
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.f3271.2
Applied rewrites70.5%
Applied rewrites77.1%
Taylor expanded in maxCos around 0
lower--.f3274.6
Applied rewrites74.6%
if 0.999944985 < (*.f32 (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos))) Initial program 28.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.f3226.2
Applied rewrites25.9%
Taylor expanded in ux around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3274.1
Applied rewrites73.6%
Applied rewrites75.1%
Final simplification77.6%
(FPCore (ux uy maxCos) :precision binary32 (* (+ 1.0 (* (* (* (* (PI) (PI)) uy) -2.0) uy)) (sqrt (* (fma -2.0 maxCos 2.0) ux))))
\begin{array}{l}
\\
\left(1 + \left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot uy\right) \cdot -2\right) \cdot uy\right) \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}
\end{array}
Initial program 54.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.f3246.4
Applied rewrites46.1%
Taylor expanded in ux around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3261.9
Applied rewrites61.7%
Applied rewrites66.0%
Final simplification66.2%
(FPCore (ux uy maxCos) :precision binary32 (* (fma -2.0 (* uy (* (* (PI) (PI)) uy)) 1.0) (sqrt (* (fma -2.0 maxCos 2.0) ux))))
\begin{array}{l}
\\
\mathsf{fma}\left(-2, uy \cdot \left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot uy\right), 1\right) \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}
\end{array}
Initial program 54.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.f3246.4
Applied rewrites46.4%
Taylor expanded in ux around 0
metadata-evalN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3261.9
Applied rewrites61.7%
Applied rewrites61.9%
(FPCore (ux uy maxCos) :precision binary32 (* (fma (* (* (* (PI) (PI)) uy) uy) -2.0 1.0) (sqrt (- 1.0 1.0))))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot uy\right) \cdot uy, -2, 1\right) \cdot \sqrt{1 - 1}
\end{array}
Initial program 54.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.f3246.4
Applied rewrites46.1%
Applied rewrites49.5%
Taylor expanded in ux around 0
Applied rewrites6.6%
Applied rewrites6.6%
herbie shell --seed 2024347
(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)))))))