
(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 12 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 (- (/ 2.0 ux) 1.0)))
(if (<= maxCos 2.6000000306073074e-15)
(* (sqrt (* (* t_0 ux) ux)) (cos (* (+ (PI) (PI)) uy)))
(*
(sqrt
(*
(* maxCos maxCos)
(-
(*
(+ (/ (- 2.0 (/ 2.0 ux)) maxCos) (/ (/ t_0 maxCos) maxCos))
(* ux ux))
(* ux ux))))
(cos (* (* 2.0 uy) (PI)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2}{ux} - 1\\
\mathbf{if}\;maxCos \leq 2.6000000306073074 \cdot 10^{-15}:\\
\;\;\;\;\sqrt{\left(t\_0 \cdot ux\right) \cdot ux} \cdot \cos \left(\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right) \cdot uy\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(maxCos \cdot maxCos\right) \cdot \left(\left(\frac{2 - \frac{2}{ux}}{maxCos} + \frac{\frac{t\_0}{maxCos}}{maxCos}\right) \cdot \left(ux \cdot ux\right) - ux \cdot ux\right)} \cdot \cos \left(\left(2 \cdot uy\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if maxCos < 2.60000003e-15Initial program 61.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.3
Applied rewrites71.3%
Applied rewrites98.6%
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
count-2N/A
distribute-lft-inN/A
distribute-rgt-outN/A
lower-*.f32N/A
lower-+.f3298.6
Applied rewrites98.6%
Taylor expanded in maxCos around 0
Applied rewrites98.6%
if 2.60000003e-15 < maxCos Initial program 58.3%
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-*.f3260.7
Applied rewrites60.7%
Applied rewrites98.8%
Taylor expanded in maxCos around inf
Applied rewrites98.9%
Final simplification98.7%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (- (- ux 1.0) (* maxCos ux))))
(if (<=
(* (sqrt (- 1.0 (* t_0 t_0))) (cos (* (* 2.0 uy) (PI))))
0.019999999552965164)
(* (sqrt (* (fma -2.0 maxCos 2.0) ux)) (cos (* (+ (PI) (PI)) uy)))
(*
(sqrt
(-
1.0
(* (* (- (+ (/ 1.0 ux) maxCos) 1.0) ux) (- (* maxCos ux) (- ux 1.0)))))
(fma (* (* (* -2.0 uy) (PI)) uy) (PI) 1.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(ux - 1\right) - maxCos \cdot ux\\
\mathbf{if}\;\sqrt{1 - t\_0 \cdot t\_0} \cdot \cos \left(\left(2 \cdot uy\right) \cdot \mathsf{PI}\left(\right)\right) \leq 0.019999999552965164:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot \cos \left(\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right) \cdot uy\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(\left(\left(\frac{1}{ux} + maxCos\right) - 1\right) \cdot ux\right) \cdot \left(maxCos \cdot ux - \left(ux - 1\right)\right)} \cdot \mathsf{fma}\left(\left(\left(-2 \cdot uy\right) \cdot \mathsf{PI}\left(\right)\right) \cdot uy, \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.0199999996Initial program 40.9%
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-*.f3264.2
Applied rewrites63.5%
Applied rewrites98.3%
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
count-2N/A
distribute-lft-inN/A
distribute-rgt-outN/A
lower-*.f32N/A
lower-+.f3298.3
Applied rewrites98.3%
Taylor expanded in ux around 0
Applied rewrites61.4%
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.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.f3278.6
Applied rewrites77.9%
Applied rewrites77.9%
Applied rewrites77.9%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower-/.f3279.0
Applied rewrites78.3%
Final simplification68.6%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* (* ux ux) (- (/ (+ 2.0 (* -2.0 maxCos)) ux) (pow (- maxCos 1.0) 2.0)))) (cos (* (+ (PI) (PI)) uy))))
\begin{array}{l}
\\
\sqrt{\left(ux \cdot ux\right) \cdot \left(\frac{2 + -2 \cdot maxCos}{ux} - {\left(maxCos - 1\right)}^{2}\right)} \cdot \cos \left(\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right) \cdot uy\right)
\end{array}
Initial program 60.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-*.f3268.3
Applied rewrites67.9%
Applied rewrites98.6%
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
count-2N/A
distribute-lft-inN/A
distribute-rgt-outN/A
lower-*.f32N/A
lower-+.f3298.6
Applied rewrites98.6%
Final simplification98.6%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (cos (* (+ (PI) (PI)) uy))) (t_1 (- (/ 2.0 ux) 1.0)))
(if (<= maxCos 2.6000000306073074e-15)
(* (sqrt (* (* t_1 ux) ux)) t_0)
(*
(sqrt
(*
(*
(- (/ (/ t_1 maxCos) maxCos) (- 1.0 (/ (- 2.0 (/ 2.0 ux)) maxCos)))
(* ux ux))
(* maxCos maxCos)))
t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right) \cdot uy\right)\\
t_1 := \frac{2}{ux} - 1\\
\mathbf{if}\;maxCos \leq 2.6000000306073074 \cdot 10^{-15}:\\
\;\;\;\;\sqrt{\left(t\_1 \cdot ux\right) \cdot ux} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\left(\frac{\frac{t\_1}{maxCos}}{maxCos} - \left(1 - \frac{2 - \frac{2}{ux}}{maxCos}\right)\right) \cdot \left(ux \cdot ux\right)\right) \cdot \left(maxCos \cdot maxCos\right)} \cdot t\_0\\
\end{array}
\end{array}
if maxCos < 2.60000003e-15Initial program 61.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.3
Applied rewrites71.3%
Applied rewrites98.6%
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
count-2N/A
distribute-lft-inN/A
distribute-rgt-outN/A
lower-*.f32N/A
lower-+.f3298.6
Applied rewrites98.6%
Taylor expanded in maxCos around 0
Applied rewrites98.6%
if 2.60000003e-15 < maxCos Initial program 58.3%
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-*.f3260.7
Applied rewrites60.7%
Applied rewrites98.8%
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
count-2N/A
distribute-lft-inN/A
distribute-rgt-outN/A
lower-*.f32N/A
lower-+.f3298.8
Applied rewrites98.8%
Taylor expanded in maxCos around inf
Applied rewrites98.8%
Final simplification98.7%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (- (- ux 1.0) (* maxCos ux))))
(if (<= (- 1.0 (* t_0 t_0)) 0.00039999998989515007)
(* (sqrt (* (fma -2.0 maxCos 2.0) ux)) (cos (* (+ (PI) (PI)) uy)))
(* (sqrt (- 1.0 (* (- ux 1.0) (- ux 1.0)))) (cos (* (* 2.0 uy) (PI)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(ux - 1\right) - maxCos \cdot ux\\
\mathbf{if}\;1 - t\_0 \cdot t\_0 \leq 0.00039999998989515007:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot \cos \left(\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right) \cdot uy\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(ux - 1\right) \cdot \left(ux - 1\right)} \cdot \cos \left(\left(2 \cdot uy\right) \cdot \mathsf{PI}\left(\right)\right)\\
\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.9999999e-4Initial program 37.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-*.f3267.8
Applied rewrites67.8%
Applied rewrites98.6%
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
count-2N/A
distribute-lft-inN/A
distribute-rgt-outN/A
lower-*.f32N/A
lower-+.f3298.6
Applied rewrites98.6%
Taylor expanded in ux around 0
Applied rewrites65.1%
if 3.9999999e-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.8%
Taylor expanded in maxCos around -inf
*-commutativeN/A
lower-*.f32N/A
Applied rewrites35.2%
Taylor expanded in maxCos around 0
Applied rewrites85.6%
Final simplification74.5%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* (* (- (/ 2.0 ux) 1.0) ux) ux)) (cos (* (+ (PI) (PI)) uy))))
\begin{array}{l}
\\
\sqrt{\left(\left(\frac{2}{ux} - 1\right) \cdot ux\right) \cdot ux} \cdot \cos \left(\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right) \cdot uy\right)
\end{array}
Initial program 60.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-*.f3267.9
Applied rewrites67.9%
Applied rewrites98.6%
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
count-2N/A
distribute-lft-inN/A
distribute-rgt-outN/A
lower-*.f32N/A
lower-+.f3298.6
Applied rewrites98.6%
Taylor expanded in maxCos around 0
Applied rewrites92.3%
Final simplification92.3%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (- (- ux 1.0) (* maxCos ux))))
(if (<= (- 1.0 (* t_0 t_0)) 0.00013000000035390258)
(*
(sqrt (* (fma -2.0 maxCos 2.0) ux))
(fma uy (* (* (* -2.0 (PI)) (PI)) uy) 1.0))
(*
(sqrt
(-
1.0
(* (* (- (+ (/ 1.0 ux) maxCos) 1.0) ux) (- (* maxCos ux) (- ux 1.0)))))
(fma (* (* (* -2.0 uy) (PI)) uy) (PI) 1.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(ux - 1\right) - maxCos \cdot ux\\
\mathbf{if}\;1 - t\_0 \cdot t\_0 \leq 0.00013000000035390258:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot \mathsf{fma}\left(uy, \left(\left(-2 \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right)\right) \cdot uy, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(\left(\left(\frac{1}{ux} + maxCos\right) - 1\right) \cdot ux\right) \cdot \left(maxCos \cdot ux - \left(ux - 1\right)\right)} \cdot \mathsf{fma}\left(\left(\left(-2 \cdot uy\right) \cdot \mathsf{PI}\left(\right)\right) \cdot uy, \mathsf{PI}\left(\right), 1\right)\\
\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)))) < 1.3e-4Initial program 34.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.f3231.2
Applied rewrites30.9%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3272.1
Applied rewrites71.6%
Applied rewrites71.6%
if 1.3e-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.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.f3270.6
Applied rewrites70.0%
Applied rewrites70.0%
Applied rewrites70.0%
Taylor expanded in ux around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower-/.f3270.8
Applied rewrites70.2%
Final simplification71.5%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (- (- ux 1.0) (* maxCos ux))))
(if (<= (- 1.0 (* t_0 t_0)) 0.00013000000035390258)
(*
(sqrt (* (fma -2.0 maxCos 2.0) ux))
(fma uy (* (* (* -2.0 (PI)) (PI)) uy) 1.0))
(*
(sqrt
(- 1.0 (* (- 1.0 (- ux (* maxCos ux))) (- (* maxCos ux) (- ux 1.0)))))
(fma (* (* uy uy) -2.0) (* (PI) (PI)) 1.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(ux - 1\right) - maxCos \cdot ux\\
\mathbf{if}\;1 - t\_0 \cdot t\_0 \leq 0.00013000000035390258:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot \mathsf{fma}\left(uy, \left(\left(-2 \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right)\right) \cdot uy, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(1 - \left(ux - maxCos \cdot ux\right)\right) \cdot \left(maxCos \cdot ux - \left(ux - 1\right)\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}
\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)))) < 1.3e-4Initial program 34.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.f3231.2
Applied rewrites30.9%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3272.1
Applied rewrites71.6%
Applied rewrites71.6%
if 1.3e-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.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.f3270.6
Applied rewrites70.0%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lower--.f3270.7
lift-*.f32N/A
*-commutativeN/A
lift-*.f3270.7
Applied rewrites70.1%
Final simplification71.5%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (- (- ux 1.0) (* maxCos ux))) (t_1 (- 1.0 (* t_0 t_0))))
(if (<= t_1 0.00013000000035390258)
(*
(sqrt (* (fma -2.0 maxCos 2.0) ux))
(fma uy (* (* (* -2.0 (PI)) (PI)) uy) 1.0))
(* (fma (* (* (* -2.0 uy) (PI)) uy) (PI) 1.0) (sqrt t_1)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(ux - 1\right) - maxCos \cdot ux\\
t_1 := 1 - t\_0 \cdot t\_0\\
\mathbf{if}\;t\_1 \leq 0.00013000000035390258:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot \mathsf{fma}\left(uy, \left(\left(-2 \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right)\right) \cdot uy, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(-2 \cdot uy\right) \cdot \mathsf{PI}\left(\right)\right) \cdot uy, \mathsf{PI}\left(\right), 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)))) < 1.3e-4Initial program 34.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.f3231.2
Applied rewrites30.9%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3272.1
Applied rewrites72.1%
Applied rewrites71.6%
if 1.3e-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.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.f3270.6
Applied rewrites70.0%
Applied rewrites70.0%
Applied rewrites70.0%
Final simplification71.4%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (- (- ux 1.0) (* maxCos ux))))
(if (<= (- 1.0 (* t_0 t_0)) 0.00013000000035390258)
(*
(sqrt (* (fma -2.0 maxCos 2.0) ux))
(fma uy (* (* (* -2.0 (PI)) (PI)) uy) 1.0))
(*
(sqrt (- 1.0 (* (- 1.0 ux) (- (* maxCos ux) (- ux 1.0)))))
(fma (* (* (* -2.0 uy) (PI)) uy) (PI) 1.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(ux - 1\right) - maxCos \cdot ux\\
\mathbf{if}\;1 - t\_0 \cdot t\_0 \leq 0.00013000000035390258:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot \mathsf{fma}\left(uy, \left(\left(-2 \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right)\right) \cdot uy, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(1 - ux\right) \cdot \left(maxCos \cdot ux - \left(ux - 1\right)\right)} \cdot \mathsf{fma}\left(\left(\left(-2 \cdot uy\right) \cdot \mathsf{PI}\left(\right)\right) \cdot uy, \mathsf{PI}\left(\right), 1\right)\\
\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)))) < 1.3e-4Initial program 34.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.f3231.2
Applied rewrites31.2%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3272.1
Applied rewrites71.6%
Applied rewrites71.6%
if 1.3e-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.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.f3270.6
Applied rewrites70.0%
Applied rewrites70.0%
Applied rewrites70.0%
Taylor expanded in maxCos around 0
lower--.f3268.6
Applied rewrites68.0%
Final simplification70.5%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* (fma -2.0 maxCos 2.0) ux)) (fma uy (* (* (* -2.0 (PI)) (PI)) uy) 1.0)))
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot \mathsf{fma}\left(uy, \left(\left(-2 \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right)\right) \cdot uy, 1\right)
\end{array}
Initial program 60.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.f3249.9
Applied rewrites49.7%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3259.9
Applied rewrites59.7%
Applied rewrites59.7%
Final simplification59.9%
(FPCore (ux uy maxCos) :precision binary32 (* (* (* (* (* -2.0 uy) (PI)) uy) (PI)) (sqrt (* (fma -2.0 maxCos 2.0) ux))))
\begin{array}{l}
\\
\left(\left(\left(\left(-2 \cdot uy\right) \cdot \mathsf{PI}\left(\right)\right) \cdot uy\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}
\end{array}
Initial program 60.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.f3249.9
Applied rewrites49.7%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3259.9
Applied rewrites59.9%
Taylor expanded in uy around inf
Applied rewrites5.3%
Applied rewrites5.3%
Final simplification5.3%
herbie shell --seed 2024285
(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)))))))