@@ -66,6 +66,84 @@ void nf_elem_randtest(nf_elem_t a, flint_rand_t state,
6666 }
6767}
6868
69+ void nf_elem_randtest_bounded (nf_elem_t a , flint_rand_t state ,
70+ mp_bitcnt_t bits , const nf_t nf )
71+ {
72+ if (nf -> flag & NF_LINEAR )
73+ {
74+ fmpz_randtest (LNF_ELEM_NUMREF (a ), state , bits );
75+
76+ if (n_randint (state , 2 ))
77+ {
78+ fmpz_randtest_not_zero (LNF_ELEM_DENREF (a ), state , bits );
79+ fmpz_abs (LNF_ELEM_DENREF (a ), LNF_ELEM_DENREF (a ));
80+
81+ _fmpq_canonicalise (LNF_ELEM_NUMREF (a ), LNF_ELEM_DENREF (a ));
82+ } else
83+ fmpz_one (LNF_ELEM_DENREF (a ));
84+ } else if (nf -> flag & NF_QUADRATIC )
85+ {
86+ fmpz_randtest (QNF_ELEM_NUMREF (a ), state , bits );
87+ fmpz_randtest (QNF_ELEM_NUMREF (a ) + 1 , state , bits );
88+
89+ if (n_randint (state , 2 ))
90+ {
91+ fmpz_t d ;
92+
93+ fmpz_randtest_not_zero (QNF_ELEM_DENREF (a ), state , bits );
94+ fmpz_abs (QNF_ELEM_DENREF (a ), QNF_ELEM_DENREF (a ));
95+
96+ fmpz_init (d );
97+ fmpz_gcd (d , QNF_ELEM_NUMREF (a ), QNF_ELEM_NUMREF (a ) + 1 );
98+ if (!fmpz_is_one (d ))
99+ {
100+ fmpz_gcd (d , d , QNF_ELEM_DENREF (a ));
101+
102+ if (!fmpz_is_one (d ))
103+ {
104+ _fmpz_vec_scalar_divexact_fmpz (QNF_ELEM_NUMREF (a ), QNF_ELEM_NUMREF (a ), 2 , d );
105+ fmpz_divexact (QNF_ELEM_DENREF (a ), QNF_ELEM_DENREF (a ), d );
106+ }
107+ }
108+ } else
109+ fmpz_one (QNF_ELEM_DENREF (a ));
110+ }
111+ else
112+ {
113+ slong i , lenf = nf -> pol -> length ;
114+ fmpz_t d ;
115+
116+ for (i = 0 ; i < lenf - 1 ; i ++ )
117+ fmpz_randtest (NF_ELEM_NUMREF (a ) + i , state , bits );
118+
119+ if (n_randint (state , 2 )) {
120+ fmpz_init (d );
121+
122+ fmpz_randtest_not_zero (NF_ELEM_DENREF (a ), state , bits );
123+ fmpz_abs (NF_ELEM_DENREF (a ), NF_ELEM_DENREF (a ));
124+
125+ _fmpz_vec_content (d , NF_ELEM_NUMREF (a ), lenf - 1 );
126+
127+ if (!fmpz_is_one (d ))
128+ {
129+ fmpz_gcd (d , d , NF_ELEM_DENREF (a ));
130+
131+ if (!fmpz_is_one (d ))
132+ {
133+ _fmpz_vec_scalar_divexact_fmpz (NF_ELEM_NUMREF (a ), NF_ELEM_NUMREF (a ), lenf - 1 , d );
134+ fmpz_divexact (NF_ELEM_DENREF (a ), NF_ELEM_DENREF (a ), d );
135+ }
136+ }
137+
138+ fmpz_clear (d );
139+ } else
140+ fmpz_one (NF_ELEM_DENREF (a ));
141+
142+ _fmpq_poly_set_length (NF_ELEM (a ), lenf - 1 );
143+ _fmpq_poly_normalise (NF_ELEM (a ));
144+ }
145+ }
146+
69147void nf_elem_randtest_not_zero (nf_elem_t a , flint_rand_t state ,
70148 mp_bitcnt_t bits , const nf_t nf )
71149{
0 commit comments