
(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 19 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 (* (pow (- maxCos 1.0) 2.0) ux)) (* 2.0 maxCos)) ux))))
\begin{array}{l}
\\
\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(\left(2 - {\left(maxCos - 1\right)}^{2} \cdot ux\right) - 2 \cdot maxCos\right) \cdot ux}
\end{array}
Initial program 61.0%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lower--.f3261.1
lift-*.f32N/A
*-commutativeN/A
lower-*.f3261.1
Applied rewrites61.1%
Taylor expanded in maxCos around 0
lower--.f3259.2
Applied rewrites59.2%
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-*.f3298.8
Applied rewrites98.8%
Final simplification98.8%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos))) (t_1 (sqrt (- 1.0 (* t_0 t_0)))))
(if (<= (* (cos (* (* uy 2.0) (PI))) t_1) 0.01860000006854534)
(* (cos (* (+ uy uy) (PI))) (sqrt (* (- ux) (- (* 2.0 maxCos) 2.0))))
(* (+ 1.0 (* (* (* (* uy uy) -2.0) (PI)) (PI))) t_1))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
t_1 := \sqrt{1 - t\_0 \cdot t\_0}\\
\mathbf{if}\;\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot t\_1 \leq 0.01860000006854534:\\
\;\;\;\;\cos \left(\left(uy + uy\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(-ux\right) \cdot \left(2 \cdot maxCos - 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\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 t\_1\\
\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.0186000001Initial program 42.8%
lift--.f32N/A
lift-*.f32N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-neg-outN/A
lift-*.f32N/A
*-lft-identityN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f32N/A
Applied rewrites7.5%
Taylor expanded in ux around 0
associate-*r*N/A
lower-*.f32N/A
mul-1-negN/A
lower-neg.f32N/A
lower--.f32N/A
lower-*.f3289.0
Applied rewrites89.0%
lift-*.f32N/A
*-commutativeN/A
count-2-revN/A
lower-+.f3289.0
Applied rewrites89.0%
if 0.0186000001 < (*.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 91.3%
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.f3279.0
Applied rewrites78.0%
Applied rewrites85.1%
Final simplification87.5%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))
(t_1 (fma (* (* uy uy) -2.0) (* (PI) (PI)) 1.0)))
(if (<=
(* (cos (* (* uy 2.0) (PI))) (sqrt (- 1.0 (* t_0 t_0))))
0.01860000006854534)
(* t_1 (sqrt (* (- ux) (- (* 2.0 maxCos) 2.0))))
(* t_1 (sqrt (- 1.0 (* (- 1.0 (- ux (* maxCos ux))) t_0)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
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}\;\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{1 - t\_0 \cdot t\_0} \leq 0.01860000006854534:\\
\;\;\;\;t\_1 \cdot \sqrt{\left(-ux\right) \cdot \left(2 \cdot maxCos - 2\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_1 \cdot \sqrt{1 - \left(1 - \left(ux - maxCos \cdot ux\right)\right) \cdot t\_0}\\
\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.0186000001Initial program 42.8%
lift--.f32N/A
lift-*.f32N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-neg-outN/A
lift-*.f32N/A
*-lft-identityN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f32N/A
Applied rewrites7.4%
Taylor expanded in ux around 0
associate-*r*N/A
lower-*.f32N/A
mul-1-negN/A
lower-neg.f32N/A
lower--.f32N/A
lower-*.f3289.0
Applied rewrites89.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.f3272.9
Applied rewrites72.7%
if 0.0186000001 < (*.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 91.3%
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.f3279.0
Applied rewrites78.0%
lift-+.f32N/A
lift--.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate--r-N/A
lift--.f32N/A
lift--.f3279.0
Applied rewrites78.1%
Final simplification75.2%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))
(t_1 (fma (* (* uy uy) -2.0) (* (PI) (PI)) 1.0))
(t_2 (sqrt (- 1.0 (* t_0 t_0)))))
(if (<= (* (cos (* (* uy 2.0) (PI))) t_2) 0.01860000006854534)
(* t_1 (sqrt (* (- ux) (- (* 2.0 maxCos) 2.0))))
(* t_1 t_2))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
t_1 := \mathsf{fma}\left(\left(uy \cdot uy\right) \cdot -2, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)\\
t_2 := \sqrt{1 - t\_0 \cdot t\_0}\\
\mathbf{if}\;\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot t\_2 \leq 0.01860000006854534:\\
\;\;\;\;t\_1 \cdot \sqrt{\left(-ux\right) \cdot \left(2 \cdot maxCos - 2\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_1 \cdot t\_2\\
\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.0186000001Initial program 42.8%
lift--.f32N/A
lift-*.f32N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-neg-outN/A
lift-*.f32N/A
*-lft-identityN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f32N/A
Applied rewrites7.5%
Taylor expanded in ux around 0
associate-*r*N/A
lower-*.f32N/A
mul-1-negN/A
lower-neg.f32N/A
lower--.f32N/A
lower-*.f3289.0
Applied rewrites89.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.f3272.9
Applied rewrites72.9%
if 0.0186000001 < (*.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 91.3%
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.f3279.0
Applied rewrites78.0%
Final simplification75.2%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))
(t_1 (* (* uy uy) -2.0))
(t_2 (* (PI) (PI)))
(t_3 (sqrt (- 1.0 (* t_0 t_0)))))
(if (<= (* (cos (* (* uy 2.0) (PI))) t_3) 0.0142000000923872)
(* (fma t_1 t_2 1.0) (sqrt (* (- ux) (- (* 2.0 maxCos) 2.0))))
(* (fma t_2 t_1 1.0) t_3))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
t_1 := \left(uy \cdot uy\right) \cdot -2\\
t_2 := \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\\
t_3 := \sqrt{1 - t\_0 \cdot t\_0}\\
\mathbf{if}\;\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot t\_3 \leq 0.0142000000923872:\\
\;\;\;\;\mathsf{fma}\left(t\_1, t\_2, 1\right) \cdot \sqrt{\left(-ux\right) \cdot \left(2 \cdot maxCos - 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t\_2, t\_1, 1\right) \cdot t\_3\\
\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.0142000001Initial program 41.0%
lift--.f32N/A
lift-*.f32N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-neg-outN/A
lift-*.f32N/A
*-lft-identityN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f32N/A
Applied rewrites7.0%
Taylor expanded in ux around 0
associate-*r*N/A
lower-*.f32N/A
mul-1-negN/A
lower-neg.f32N/A
lower--.f32N/A
lower-*.f3290.1
Applied rewrites90.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.f3273.9
Applied rewrites73.5%
if 0.0142000001 < (*.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.3%
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.f3276.8
Applied rewrites76.5%
Applied rewrites76.8%
Final simplification75.1%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))
(t_1 (fma (* (* uy uy) -2.0) (* (PI) (PI)) 1.0)))
(if (<=
(* (cos (* (* uy 2.0) (PI))) (sqrt (- 1.0 (* t_0 t_0))))
0.01860000006854534)
(* t_1 (sqrt (* (- ux) (- (* 2.0 maxCos) 2.0))))
(* t_1 (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{fma}\left(\left(uy \cdot uy\right) \cdot -2, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\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.01860000006854534:\\
\;\;\;\;t\_1 \cdot \sqrt{\left(-ux\right) \cdot \left(2 \cdot maxCos - 2\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_1 \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.0186000001Initial program 42.8%
lift--.f32N/A
lift-*.f32N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-neg-outN/A
lift-*.f32N/A
*-lft-identityN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f32N/A
Applied rewrites7.5%
Taylor expanded in ux around 0
associate-*r*N/A
lower-*.f32N/A
mul-1-negN/A
lower-neg.f32N/A
lower--.f32N/A
lower-*.f3289.0
Applied rewrites89.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.f3272.9
Applied rewrites72.9%
if 0.0186000001 < (*.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 91.3%
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.f3279.0
Applied rewrites78.0%
Taylor expanded in maxCos around 0
lower--.f3277.0
Applied rewrites76.1%
Final simplification74.4%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos))))
(if (<= (sqrt (- 1.0 (* t_0 t_0))) 0.01860000006854534)
(* (cos (* (+ uy uy) (PI))) (sqrt (* (- ux) (- (* 2.0 maxCos) 2.0))))
(* (cos (* (* uy 2.0) (PI))) (sqrt (- 1.0 (* (- 1.0 ux) (- 1.0 ux))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
\mathbf{if}\;\sqrt{1 - t\_0 \cdot t\_0} \leq 0.01860000006854534:\\
\;\;\;\;\cos \left(\left(uy + uy\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(-ux\right) \cdot \left(2 \cdot maxCos - 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{1 - \left(1 - ux\right) \cdot \left(1 - ux\right)}\\
\end{array}
\end{array}
if (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.0186000001Initial program 40.3%
lift--.f32N/A
lift-*.f32N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-neg-outN/A
lift-*.f32N/A
*-lft-identityN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f32N/A
Applied rewrites7.2%
Taylor expanded in ux around 0
associate-*r*N/A
lower-*.f32N/A
mul-1-negN/A
lower-neg.f32N/A
lower--.f32N/A
lower-*.f3290.9
Applied rewrites90.9%
lift-*.f32N/A
*-commutativeN/A
count-2-revN/A
lower-+.f3290.9
Applied rewrites90.9%
if 0.0186000001 < (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 90.6%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lower--.f3290.8
lift-*.f32N/A
*-commutativeN/A
lower-*.f3290.8
Applied rewrites90.8%
Taylor expanded in maxCos around 0
lower--.f3287.3
Applied rewrites87.3%
Taylor expanded in maxCos around 0
lower--.f3286.9
Applied rewrites86.9%
Final simplification89.3%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 0.00017499999376013875)
(* (cos (* (+ uy uy) (PI))) (sqrt (* (- ux) (- (* 2.0 maxCos) 2.0))))
(*
(cos (* (* uy 2.0) (PI)))
(sqrt (- 1.0 (* (- 1.0 (- ux (* maxCos ux))) (- 1.0 ux)))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00017499999376013875:\\
\;\;\;\;\cos \left(\left(uy + uy\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(-ux\right) \cdot \left(2 \cdot maxCos - 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{1 - \left(1 - \left(ux - maxCos \cdot ux\right)\right) \cdot \left(1 - ux\right)}\\
\end{array}
\end{array}
if ux < 1.74999994e-4Initial program 40.3%
lift--.f32N/A
lift-*.f32N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-neg-outN/A
lift-*.f32N/A
*-lft-identityN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f32N/A
Applied rewrites7.1%
Taylor expanded in ux around 0
associate-*r*N/A
lower-*.f32N/A
mul-1-negN/A
lower-neg.f32N/A
lower--.f32N/A
lower-*.f3290.9
Applied rewrites90.9%
lift-*.f32N/A
*-commutativeN/A
count-2-revN/A
lower-+.f3290.9
Applied rewrites90.9%
if 1.74999994e-4 < ux Initial program 90.6%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lower--.f3290.8
lift-*.f32N/A
*-commutativeN/A
lower-*.f3290.8
Applied rewrites90.8%
Taylor expanded in maxCos around 0
lower--.f3287.3
Applied rewrites87.3%
Final simplification89.4%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 0.00017499999376013875)
(* (cos (* (+ uy uy) (PI))) (sqrt (* (- ux) (- (* 2.0 maxCos) 2.0))))
(*
(cos (* (* uy 2.0) (PI)))
(sqrt (- 1.0 (* (+ (- 1.0 ux) (* ux maxCos)) (- 1.0 ux)))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00017499999376013875:\\
\;\;\;\;\cos \left(\left(uy + uy\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{\left(-ux\right) \cdot \left(2 \cdot maxCos - 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(\left(uy \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(1 - ux\right)}\\
\end{array}
\end{array}
if ux < 1.74999994e-4Initial program 40.3%
lift--.f32N/A
lift-*.f32N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-neg-outN/A
lift-*.f32N/A
*-lft-identityN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f32N/A
Applied rewrites7.1%
Taylor expanded in ux around 0
associate-*r*N/A
lower-*.f32N/A
mul-1-negN/A
lower-neg.f32N/A
lower--.f32N/A
lower-*.f3290.9
Applied rewrites90.9%
lift-*.f32N/A
*-commutativeN/A
count-2-revN/A
lower-+.f3290.9
Applied rewrites90.9%
if 1.74999994e-4 < ux Initial program 90.6%
Taylor expanded in maxCos around 0
lower--.f3287.2
Applied rewrites87.2%
Final simplification89.4%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* (+ uy uy) (PI))) (sqrt (* (- (/ 2.0 ux) 1.0) (* ux ux)))))
\begin{array}{l}
\\
\cos \left(\left(uy + uy\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 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
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-*.f3269.9
Applied rewrites69.9%
Applied rewrites98.8%
lift-*.f32N/A
*-commutativeN/A
count-2-revN/A
lower-+.f3298.8
Applied rewrites98.8%
Taylor expanded in maxCos around 0
Applied rewrites93.8%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (* (* uy uy) -2.0)) (t_1 (+ (- 1.0 ux) (* ux maxCos))))
(if (<= ux 2.499999936844688e-5)
(* (fma t_0 (* (PI) (PI)) 1.0) (sqrt (* (- ux) (- (* 2.0 maxCos) 2.0))))
(* (+ 1.0 (* (* t_0 (PI)) (PI))) (sqrt (- 1.0 (* t_1 t_1)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(uy \cdot uy\right) \cdot -2\\
t_1 := \left(1 - ux\right) + ux \cdot maxCos\\
\mathbf{if}\;ux \leq 2.499999936844688 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(t\_0, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right) \cdot \sqrt{\left(-ux\right) \cdot \left(2 \cdot maxCos - 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \left(t\_0 \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{1 - t\_1 \cdot t\_1}\\
\end{array}
\end{array}
if ux < 2.49999994e-5Initial program 33.3%
lift--.f32N/A
lift-*.f32N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-neg-outN/A
lift-*.f32N/A
*-lft-identityN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f32N/A
Applied rewrites6.3%
Taylor expanded in ux around 0
associate-*r*N/A
lower-*.f32N/A
mul-1-negN/A
lower-neg.f32N/A
lower--.f32N/A
lower-*.f3294.6
Applied rewrites94.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.f3279.3
Applied rewrites78.8%
if 2.49999994e-5 < ux Initial program 85.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.f3270.4
Applied rewrites70.2%
Applied rewrites76.9%
Final simplification78.0%
(FPCore (ux uy maxCos) :precision binary32 (* (fma (* (* uy uy) -2.0) (* (PI) (PI)) 1.0) (sqrt (* (- ux) (- (* 2.0 maxCos) 2.0)))))
\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{\left(-ux\right) \cdot \left(2 \cdot maxCos - 2\right)}
\end{array}
Initial program 61.0%
lift--.f32N/A
lift-*.f32N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-lft-neg-outN/A
lift-*.f32N/A
*-lft-identityN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f32N/A
Applied rewrites7.9%
Taylor expanded in ux around 0
associate-*r*N/A
lower-*.f32N/A
mul-1-negN/A
lower-neg.f32N/A
lower--.f32N/A
lower-*.f3274.5
Applied rewrites74.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.f3263.5
Applied rewrites63.4%
Final simplification63.5%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- 1.0 (* (- (* (+ (/ 1.0 ux) maxCos) ux) ux) (fma (- 1.0 maxCos) ux 1.0)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((1.0f - (((((1.0f / ux) + maxCos) * ux) - ux) * fmaf((1.0f - maxCos), ux, 1.0f))));
}
function code(ux, uy, maxCos) return sqrt(Float32(Float32(1.0) - Float32(Float32(Float32(Float32(Float32(Float32(1.0) / ux) + maxCos) * ux) - ux) * fma(Float32(Float32(1.0) - maxCos), ux, Float32(1.0))))) end
\begin{array}{l}
\\
\sqrt{1 - \left(\left(\frac{1}{ux} + maxCos\right) \cdot ux - ux\right) \cdot \mathsf{fma}\left(1 - maxCos, ux, 1\right)}
\end{array}
Initial program 61.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.f3251.7
Applied rewrites51.7%
Applied rewrites25.8%
Taylor expanded in uy around 0
lower-sqrt.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower--.f3226.0
Applied rewrites25.8%
Taylor expanded in ux around inf
Applied rewrites26.6%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- 1.0 (* (- (* (+ (/ 1.0 maxCos) ux) maxCos) ux) (fma (- 1.0 maxCos) ux 1.0)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((1.0f - (((((1.0f / maxCos) + ux) * maxCos) - ux) * fmaf((1.0f - maxCos), ux, 1.0f))));
}
function code(ux, uy, maxCos) return sqrt(Float32(Float32(1.0) - Float32(Float32(Float32(Float32(Float32(Float32(1.0) / maxCos) + ux) * maxCos) - ux) * fma(Float32(Float32(1.0) - maxCos), ux, Float32(1.0))))) end
\begin{array}{l}
\\
\sqrt{1 - \left(\left(\frac{1}{maxCos} + ux\right) \cdot maxCos - ux\right) \cdot \mathsf{fma}\left(1 - maxCos, ux, 1\right)}
\end{array}
Initial program 61.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.f3251.7
Applied rewrites51.6%
Applied rewrites25.8%
Taylor expanded in uy around 0
lower-sqrt.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower--.f3226.0
Applied rewrites26.0%
Taylor expanded in maxCos around inf
Applied rewrites26.4%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- 1.0 (* (- (+ (* ux maxCos) 1.0) ux) (fma (- 1.0 maxCos) ux 1.0)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((1.0f - ((((ux * maxCos) + 1.0f) - ux) * fmaf((1.0f - maxCos), ux, 1.0f))));
}
function code(ux, uy, maxCos) return sqrt(Float32(Float32(1.0) - Float32(Float32(Float32(Float32(ux * maxCos) + Float32(1.0)) - ux) * fma(Float32(Float32(1.0) - maxCos), ux, Float32(1.0))))) end
\begin{array}{l}
\\
\sqrt{1 - \left(\left(ux \cdot maxCos + 1\right) - ux\right) \cdot \mathsf{fma}\left(1 - maxCos, ux, 1\right)}
\end{array}
Initial program 61.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.f3251.7
Applied rewrites51.6%
Applied rewrites25.8%
Taylor expanded in uy around 0
lower-sqrt.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower--.f3226.0
Applied rewrites25.8%
Applied rewrites25.9%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- 1.0 (* (- (fma ux maxCos 1.0) ux) (fma (- 1.0 maxCos) ux 1.0)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((1.0f - ((fmaf(ux, maxCos, 1.0f) - ux) * fmaf((1.0f - maxCos), ux, 1.0f))));
}
function code(ux, uy, maxCos) return sqrt(Float32(Float32(1.0) - Float32(Float32(fma(ux, maxCos, Float32(1.0)) - ux) * fma(Float32(Float32(1.0) - maxCos), ux, Float32(1.0))))) end
\begin{array}{l}
\\
\sqrt{1 - \left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux\right) \cdot \mathsf{fma}\left(1 - maxCos, ux, 1\right)}
\end{array}
Initial program 61.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.f3251.7
Applied rewrites51.6%
Applied rewrites25.8%
Taylor expanded in uy around 0
lower-sqrt.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower--.f3226.0
Applied rewrites26.0%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- 1.0 (* (* (- maxCos) maxCos) (* ux ux)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((1.0f - ((-maxCos * maxCos) * (ux * ux))));
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = sqrt((1.0e0 - ((-maxcos * maxcos) * (ux * ux))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(1.0) - Float32(Float32(Float32(-maxCos) * maxCos) * Float32(ux * ux)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((single(1.0) - ((-maxCos * maxCos) * (ux * ux)))); end
\begin{array}{l}
\\
\sqrt{1 - \left(\left(-maxCos\right) \cdot maxCos\right) \cdot \left(ux \cdot ux\right)}
\end{array}
Initial program 61.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.f3251.7
Applied rewrites51.6%
Applied rewrites25.8%
Taylor expanded in uy around 0
lower-sqrt.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower--.f3226.0
Applied rewrites25.9%
Taylor expanded in maxCos around inf
Applied rewrites20.0%
Final simplification20.0%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- 1.0 (- 1.0 (* ux ux)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((1.0f - (1.0f - (ux * ux))));
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = sqrt((1.0e0 - (1.0e0 - (ux * ux))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(1.0) - Float32(Float32(1.0) - Float32(ux * ux)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((single(1.0) - (single(1.0) - (ux * ux)))); end
\begin{array}{l}
\\
\sqrt{1 - \left(1 - ux \cdot ux\right)}
\end{array}
Initial program 61.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.f3251.7
Applied rewrites51.6%
Applied rewrites25.8%
Taylor expanded in uy around 0
lower-sqrt.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower--.f3226.0
Applied rewrites25.9%
Taylor expanded in maxCos around 0
Applied rewrites13.3%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- 1.0 1.0)))
float code(float ux, float uy, float maxCos) {
return sqrtf((1.0f - 1.0f));
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = sqrt((1.0e0 - 1.0e0))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(1.0) - Float32(1.0))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((single(1.0) - single(1.0))); end
\begin{array}{l}
\\
\sqrt{1 - 1}
\end{array}
Initial program 61.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.f3251.7
Applied rewrites51.6%
Applied rewrites25.9%
Taylor expanded in uy around 0
lower-sqrt.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower--.f3226.0
Applied rewrites25.9%
Taylor expanded in ux around 0
Applied rewrites6.6%
herbie shell --seed 2024337
(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)))))))