
(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 15 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 (* (sqrt (* (* ux ux) (- (/ (+ (* -2.0 maxCos) 2.0) ux) (pow (- maxCos 1.0) 2.0)))) (cos (* (PI) (* 2.0 uy)))))
\begin{array}{l}
\\
\sqrt{\left(ux \cdot ux\right) \cdot \left(\frac{-2 \cdot maxCos + 2}{ux} - {\left(maxCos - 1\right)}^{2}\right)} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)
\end{array}
Initial program 55.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
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 rewrites68.2%
Applied rewrites98.7%
Final simplification98.7%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (- (+ -1.0 ux) (* maxCos ux))))
(if (<=
(* (sqrt (- 1.0 (* t_0 t_0))) (cos (* (PI) (* 2.0 uy))))
0.004999999888241291)
(*
(cos (* (* (PI) uy) 2.0))
(sqrt (* (- (- 1.0 (- maxCos 1.0)) maxCos) ux)))
(sqrt
(*
(- (/ (fma -2.0 maxCos 2.0) ux) (pow (- maxCos 1.0) 2.0))
(* ux ux))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-1 + ux\right) - maxCos \cdot ux\\
\mathbf{if}\;\sqrt{1 - t\_0 \cdot t\_0} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right) \leq 0.004999999888241291:\\
\;\;\;\;\cos \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right) \cdot \sqrt{\left(\left(1 - \left(maxCos - 1\right)\right) - maxCos\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\frac{\mathsf{fma}\left(-2, maxCos, 2\right)}{ux} - {\left(maxCos - 1\right)}^{2}\right) \cdot \left(ux \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.00499999989Initial program 30.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.f3223.1
Applied rewrites22.9%
lift--.f32N/A
sub-negN/A
+-commutativeN/A
lift-*.f32N/A
distribute-rgt-neg-inN/A
lower-fma.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
lower-neg.f3215.3
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f3215.3
Applied rewrites15.2%
Taylor expanded in ux around 0
lower-*.f32N/A
lower-sqrt.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower--.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3294.2
Applied rewrites94.2%
if 0.00499999989 < (*.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 83.2%
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-*.f3277.7
Applied rewrites77.7%
Applied rewrites99.0%
Taylor expanded in uy around 0
lower-sqrt.f32N/A
lower--.f32N/A
lower-pow.f32N/A
lower--.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f3272.5
Applied rewrites64.7%
Taylor expanded in ux around inf
Applied rewrites82.8%
Final simplification88.8%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (- (+ -1.0 ux) (* maxCos ux))))
(if (<=
(* (sqrt (- 1.0 (* t_0 t_0))) (cos (* (PI) (* 2.0 uy))))
0.020999999716877937)
(*
(cos (* (* (PI) uy) 2.0))
(sqrt (* (- (- 1.0 (- maxCos 1.0)) maxCos) ux)))
(*
(sqrt
(+ (* (+ (- ux (* maxCos ux)) -1.0) (- (* maxCos ux) (+ -1.0 ux))) 1.0))
(fma (* (* uy uy) -2.0) (* (PI) (PI)) 1.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-1 + ux\right) - maxCos \cdot ux\\
\mathbf{if}\;\sqrt{1 - t\_0 \cdot t\_0} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right) \leq 0.020999999716877937:\\
\;\;\;\;\cos \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right) \cdot \sqrt{\left(\left(1 - \left(maxCos - 1\right)\right) - maxCos\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\left(ux - maxCos \cdot ux\right) + -1\right) \cdot \left(maxCos \cdot ux - \left(-1 + ux\right)\right) + 1} \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 (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.0209999997Initial program 38.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.f3230.6
Applied rewrites30.6%
lift--.f32N/A
sub-negN/A
+-commutativeN/A
lift-*.f32N/A
distribute-rgt-neg-inN/A
lower-fma.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
lower-neg.f3216.1
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f3216.1
Applied rewrites16.0%
Taylor expanded in ux around 0
lower-*.f32N/A
lower-sqrt.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower--.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3290.7
Applied rewrites90.7%
if 0.0209999997 < (*.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 88.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.f3280.9
Applied rewrites80.5%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lower--.f3280.9
lift-*.f32N/A
*-commutativeN/A
lower-*.f3280.9
Applied rewrites80.5%
Final simplification87.3%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (- (+ -1.0 ux) (* maxCos ux))))
(if (<=
(* (sqrt (- 1.0 (* t_0 t_0))) (cos (* (PI) (* 2.0 uy))))
0.020999999716877937)
(* (sqrt (* (fma -2.0 maxCos 2.0) ux)) (cos (* (* (PI) uy) 2.0)))
(*
(sqrt
(+ (* (+ (- ux (* maxCos ux)) -1.0) (- (* maxCos ux) (+ -1.0 ux))) 1.0))
(fma (* (* uy uy) -2.0) (* (PI) (PI)) 1.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-1 + ux\right) - maxCos \cdot ux\\
\mathbf{if}\;\sqrt{1 - t\_0 \cdot t\_0} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right) \leq 0.020999999716877937:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux} \cdot \cos \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\left(ux - maxCos \cdot ux\right) + -1\right) \cdot \left(maxCos \cdot ux - \left(-1 + ux\right)\right) + 1} \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 (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.0209999997Initial program 38.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.f3230.6
Applied rewrites30.3%
Taylor expanded in ux around 0
cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3266.1
Applied rewrites65.6%
Taylor expanded in uy around inf
Applied rewrites6.1%
Taylor expanded in uy around inf
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3259.6
Applied rewrites59.6%
if 0.0209999997 < (*.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 88.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.f3280.9
Applied rewrites80.9%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lower--.f3280.9
lift-*.f32N/A
*-commutativeN/A
lower-*.f3280.9
Applied rewrites80.5%
Final simplification67.2%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (cos (* (PI) (* 2.0 uy)))))
(if (<= maxCos 2.499999990010493e-12)
(*
(sqrt (* (- (fma -2.0 maxCos 2.0) (* (pow (- maxCos 1.0) 2.0) ux)) ux))
t_0)
(*
(sqrt
(*
(* maxCos maxCos)
(*
(-
(/ (/ (- (/ 2.0 ux) 1.0) maxCos) maxCos)
(- 1.0 (/ (- 2.0 (/ 2.0 ux)) maxCos)))
(* ux ux))))
t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
\mathbf{if}\;maxCos \leq 2.499999990010493 \cdot 10^{-12}:\\
\;\;\;\;\sqrt{\left(\mathsf{fma}\left(-2, maxCos, 2\right) - {\left(maxCos - 1\right)}^{2} \cdot ux\right) \cdot ux} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(maxCos \cdot maxCos\right) \cdot \left(\left(\frac{\frac{\frac{2}{ux} - 1}{maxCos}}{maxCos} - \left(1 - \frac{2 - \frac{2}{ux}}{maxCos}\right)\right) \cdot \left(ux \cdot ux\right)\right)} \cdot t\_0\\
\end{array}
\end{array}
if maxCos < 2.49999999e-12Initial program 56.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-*.f3273.8
Applied rewrites73.8%
Taylor expanded in ux around 0
Applied rewrites74.1%
if 2.49999999e-12 < maxCos Initial program 54.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-*.f3254.6
Applied rewrites54.6%
Applied rewrites98.4%
Taylor expanded in maxCos around inf
Applied rewrites98.2%
Final simplification98.8%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (cos (* (PI) (* 2.0 uy)))) (t_1 (- (/ 2.0 ux) 1.0)))
(if (<= maxCos 6.000000052353016e-9)
(* (sqrt (* t_1 (* ux ux))) t_0)
(*
(sqrt
(*
(* maxCos maxCos)
(*
(- (/ (/ t_1 maxCos) maxCos) (- 1.0 (/ (- 2.0 (/ 2.0 ux)) maxCos)))
(* ux ux))))
t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
t_1 := \frac{2}{ux} - 1\\
\mathbf{if}\;maxCos \leq 6.000000052353016 \cdot 10^{-9}:\\
\;\;\;\;\sqrt{t\_1 \cdot \left(ux \cdot ux\right)} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(maxCos \cdot maxCos\right) \cdot \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 t\_0\\
\end{array}
\end{array}
if maxCos < 6.00000005e-9Initial program 56.4%
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-*.f3273.5
Applied rewrites73.5%
Taylor expanded in maxCos around 0
Applied rewrites98.8%
if 6.00000005e-9 < maxCos Initial program 52.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
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-*.f3245.6
Applied rewrites45.6%
Applied rewrites98.0%
Taylor expanded in maxCos around inf
Applied rewrites97.8%
Final simplification98.6%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (- (+ -1.0 ux) (* maxCos ux))))
(if (<= (- 1.0 (* t_0 t_0)) 0.00019999999494757503)
(*
(cos (* (* (PI) uy) 2.0))
(sqrt (* (- (- 1.0 (- maxCos 1.0)) maxCos) ux)))
(*
(sqrt (- 1.0 (* (- 1.0 ux) (- (* maxCos ux) (+ -1.0 ux)))))
(cos (* (PI) (* 2.0 uy)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-1 + ux\right) - maxCos \cdot ux\\
\mathbf{if}\;1 - t\_0 \cdot t\_0 \leq 0.00019999999494757503:\\
\;\;\;\;\cos \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right) \cdot \sqrt{\left(\left(1 - \left(maxCos - 1\right)\right) - maxCos\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(1 - ux\right) \cdot \left(maxCos \cdot ux - \left(-1 + ux\right)\right)} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\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)))) < 1.99999995e-4Initial program 34.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.f3230.3
Applied rewrites29.9%
lift--.f32N/A
sub-negN/A
+-commutativeN/A
lift-*.f32N/A
distribute-rgt-neg-inN/A
lower-fma.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
lower-neg.f3216.4
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f3216.4
Applied rewrites16.3%
Taylor expanded in ux around 0
lower-*.f32N/A
lower-sqrt.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower--.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3293.3
Applied rewrites93.3%
if 1.99999995e-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 87.4%
Taylor expanded in maxCos around 0
lower--.f3282.8
Applied rewrites82.8%
Final simplification89.0%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= maxCos 2.499999936844688e-5)
(* (sqrt (* (- (/ 2.0 ux) 1.0) (* ux ux))) (cos (* (PI) (* 2.0 uy))))
(*
(cos (* (* (PI) uy) 2.0))
(sqrt (* (- (- 1.0 (- maxCos 1.0)) maxCos) ux)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 2.499999936844688 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{\left(\frac{2}{ux} - 1\right) \cdot \left(ux \cdot ux\right)} \cdot \cos \left(\mathsf{PI}\left(\right) \cdot \left(2 \cdot uy\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\cos \left(\left(\mathsf{PI}\left(\right) \cdot uy\right) \cdot 2\right) \cdot \sqrt{\left(\left(1 - \left(maxCos - 1\right)\right) - maxCos\right) \cdot ux}\\
\end{array}
\end{array}
if maxCos < 2.49999994e-5Initial program 57.2%
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-*.f3273.7
Applied rewrites74.0%
Taylor expanded in maxCos around 0
Applied rewrites98.4%
if 2.49999994e-5 < maxCos Initial program 47.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.f3238.2
Applied rewrites37.3%
lift--.f32N/A
sub-negN/A
+-commutativeN/A
lift-*.f32N/A
distribute-rgt-neg-inN/A
lower-fma.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
lower-neg.f3217.8
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f3217.8
Applied rewrites17.5%
Taylor expanded in ux around 0
lower-*.f32N/A
lower-sqrt.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower--.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3280.2
Applied rewrites80.2%
Final simplification95.6%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (fma (* (* uy uy) -2.0) (* (PI) (PI)) 1.0)))
(if (<= ux 9.999999747378752e-5)
(* (sqrt (* (- (- 1.0 (- maxCos 1.0)) maxCos) ux)) t_0)
(*
(sqrt
(+ (* (+ (- ux (* maxCos ux)) -1.0) (- (* maxCos ux) (+ -1.0 ux))) 1.0))
t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\left(uy \cdot uy\right) \cdot -2, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)\\
\mathbf{if}\;ux \leq 9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{\left(\left(1 - \left(maxCos - 1\right)\right) - maxCos\right) \cdot ux} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\left(ux - maxCos \cdot ux\right) + -1\right) \cdot \left(maxCos \cdot ux - \left(-1 + ux\right)\right) + 1} \cdot t\_0\\
\end{array}
\end{array}
if ux < 9.99999975e-5Initial program 34.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.f3230.3
Applied rewrites29.9%
lift--.f32N/A
sub-negN/A
+-commutativeN/A
lift-*.f32N/A
distribute-rgt-neg-inN/A
lower-fma.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
lower-neg.f3216.4
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f3216.4
Applied rewrites16.3%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower--.f3273.1
Applied rewrites73.1%
if 9.99999975e-5 < ux Initial program 87.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.f3274.1
Applied rewrites73.8%
lift-+.f32N/A
lift--.f32N/A
associate-+l-N/A
lower--.f32N/A
lower--.f3274.1
lift-*.f32N/A
*-commutativeN/A
lower-*.f3274.1
Applied rewrites74.1%
Final simplification73.5%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (- (+ -1.0 ux) (* maxCos ux)))
(t_1 (fma (* (* uy uy) -2.0) (* (PI) (PI)) 1.0)))
(if (<= ux 9.999999747378752e-5)
(* (sqrt (* (- (- 1.0 (- maxCos 1.0)) maxCos) ux)) t_1)
(* t_1 (sqrt (- 1.0 (* t_0 t_0)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-1 + ux\right) - maxCos \cdot ux\\
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}\;ux \leq 9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{\left(\left(1 - \left(maxCos - 1\right)\right) - maxCos\right) \cdot ux} \cdot t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_1 \cdot \sqrt{1 - t\_0 \cdot t\_0}\\
\end{array}
\end{array}
if ux < 9.99999975e-5Initial program 34.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.f3230.3
Applied rewrites29.9%
lift--.f32N/A
sub-negN/A
+-commutativeN/A
lift-*.f32N/A
distribute-rgt-neg-inN/A
lower-fma.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
lower-neg.f3216.4
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f3216.4
Applied rewrites16.3%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower--.f3273.1
Applied rewrites72.6%
if 9.99999975e-5 < ux Initial program 87.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.f3274.1
Applied rewrites73.8%
Final simplification73.5%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- ux (* maxCos ux)) -1.0)))
(if (<= ux 9.999999747378752e-5)
(*
(sqrt (* (- (- 1.0 (- maxCos 1.0)) maxCos) ux))
(fma (* (* uy uy) -2.0) (* (PI) (PI)) 1.0))
(sqrt (- 1.0 (* t_0 t_0))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(ux - maxCos \cdot ux\right) + -1\\
\mathbf{if}\;ux \leq 9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{\left(\left(1 - \left(maxCos - 1\right)\right) - maxCos\right) \cdot ux} \cdot \mathsf{fma}\left(\left(uy \cdot uy\right) \cdot -2, \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - t\_0 \cdot t\_0}\\
\end{array}
\end{array}
if ux < 9.99999975e-5Initial program 34.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.f3230.3
Applied rewrites29.9%
lift--.f32N/A
sub-negN/A
+-commutativeN/A
lift-*.f32N/A
distribute-rgt-neg-inN/A
lower-fma.f32N/A
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
lower-neg.f3216.4
lift-+.f32N/A
lift-*.f32N/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f3216.4
Applied rewrites16.3%
Taylor expanded in ux around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
mul-1-negN/A
unsub-negN/A
lower--.f32N/A
lower--.f3273.1
Applied rewrites73.1%
if 9.99999975e-5 < ux Initial program 87.4%
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-*.f3272.0
Applied rewrites72.0%
Applied rewrites98.7%
Taylor expanded in uy around 0
lower-sqrt.f32N/A
lower--.f32N/A
lower-pow.f32N/A
lower--.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f3270.7
Applied rewrites61.0%
Applied rewrites74.1%
Final simplification73.5%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (- (fma ux maxCos 1.0) ux)))
(if (<= (- (* maxCos ux) (+ -1.0 ux)) 0.9998999834060669)
(sqrt (- 1.0 (* t_0 t_0)))
(sqrt (* (fma -2.0 maxCos 2.0) ux)))))
float code(float ux, float uy, float maxCos) {
float t_0 = fmaf(ux, maxCos, 1.0f) - ux;
float tmp;
if (((maxCos * ux) - (-1.0f + ux)) <= 0.9998999834060669f) {
tmp = sqrtf((1.0f - (t_0 * t_0)));
} else {
tmp = sqrtf((fmaf(-2.0f, maxCos, 2.0f) * ux));
}
return tmp;
}
function code(ux, uy, maxCos) t_0 = Float32(fma(ux, maxCos, Float32(1.0)) - ux) tmp = Float32(0.0) if (Float32(Float32(maxCos * ux) - Float32(Float32(-1.0) + ux)) <= Float32(0.9998999834060669)) tmp = sqrt(Float32(Float32(1.0) - Float32(t_0 * t_0))); else tmp = sqrt(Float32(fma(Float32(-2.0), maxCos, Float32(2.0)) * ux)); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(ux, maxCos, 1\right) - ux\\
\mathbf{if}\;maxCos \cdot ux - \left(-1 + ux\right) \leq 0.9998999834060669:\\
\;\;\;\;\sqrt{1 - t\_0 \cdot t\_0}\\
\mathbf{else}:\\
\;\;\;\;\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.999899983Initial program 87.4%
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-*.f3272.0
Applied rewrites72.0%
Applied rewrites98.7%
Taylor expanded in uy around 0
lower-sqrt.f32N/A
lower--.f32N/A
lower-pow.f32N/A
lower--.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f3270.7
Applied rewrites66.7%
Applied rewrites59.2%
if 0.999899983 < (+.f32 (-.f32 #s(literal 1 binary32) ux) (*.f32 ux maxCos)) Initial program 34.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-*.f3264.9
Applied rewrites64.9%
Applied rewrites98.6%
Taylor expanded in uy around 0
lower-sqrt.f32N/A
lower--.f32N/A
lower-pow.f32N/A
lower--.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f3229.9
Applied rewrites29.9%
Taylor expanded in ux around 0
Applied rewrites68.8%
Final simplification69.9%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- ux (* maxCos ux)) -1.0)))
(if (<= ux 9.999999747378752e-5)
(sqrt (* (fma -2.0 maxCos 2.0) ux))
(sqrt (- 1.0 (* t_0 t_0))))))
float code(float ux, float uy, float maxCos) {
float t_0 = (ux - (maxCos * ux)) + -1.0f;
float tmp;
if (ux <= 9.999999747378752e-5f) {
tmp = sqrtf((fmaf(-2.0f, maxCos, 2.0f) * ux));
} else {
tmp = sqrtf((1.0f - (t_0 * t_0)));
}
return tmp;
}
function code(ux, uy, maxCos) t_0 = Float32(Float32(ux - Float32(maxCos * ux)) + Float32(-1.0)) tmp = Float32(0.0) if (ux <= Float32(9.999999747378752e-5)) tmp = sqrt(Float32(fma(Float32(-2.0), maxCos, Float32(2.0)) * ux)); else tmp = sqrt(Float32(Float32(1.0) - Float32(t_0 * t_0))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(ux - maxCos \cdot ux\right) + -1\\
\mathbf{if}\;ux \leq 9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - t\_0 \cdot t\_0}\\
\end{array}
\end{array}
if ux < 9.99999975e-5Initial program 34.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-*.f3264.9
Applied rewrites64.9%
Applied rewrites98.6%
Taylor expanded in uy around 0
lower-sqrt.f32N/A
lower--.f32N/A
lower-pow.f32N/A
lower--.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f3229.9
Applied rewrites29.3%
Taylor expanded in ux around 0
Applied rewrites68.8%
if 9.99999975e-5 < ux Initial program 87.4%
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-*.f3272.0
Applied rewrites72.0%
Applied rewrites98.7%
Taylor expanded in uy around 0
lower-sqrt.f32N/A
lower--.f32N/A
lower-pow.f32N/A
lower--.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f3270.7
Applied rewrites70.7%
Applied rewrites74.1%
Final simplification71.2%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* (fma -2.0 maxCos 2.0) ux)))
float code(float ux, float uy, float maxCos) {
return sqrtf((fmaf(-2.0f, maxCos, 2.0f) * ux));
}
function code(ux, uy, maxCos) return sqrt(Float32(fma(Float32(-2.0), maxCos, Float32(2.0)) * ux)) end
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(-2, maxCos, 2\right) \cdot ux}
\end{array}
Initial program 55.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
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 rewrites68.2%
Applied rewrites98.7%
Taylor expanded in uy around 0
lower-sqrt.f32N/A
lower--.f32N/A
lower-pow.f32N/A
lower--.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f3246.4
Applied rewrites44.7%
Taylor expanded in ux around 0
Applied rewrites61.0%
(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 55.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
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 rewrites68.0%
Applied rewrites98.7%
Taylor expanded in uy around 0
lower-sqrt.f32N/A
lower--.f32N/A
lower-pow.f32N/A
lower--.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f3246.4
Applied rewrites46.4%
Taylor expanded in ux around 0
Applied rewrites6.6%
herbie shell --seed 2024331
(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)))))))