1 | /*****************************************************************************\ |
---|
2 | * Computer Algebra System SINGULAR |
---|
3 | \*****************************************************************************/ |
---|
4 | /** @file FLINTconvert.h |
---|
5 | * |
---|
6 | * This file defines functions for conversion to FLINT (www.flintlib.org) |
---|
7 | * and back. |
---|
8 | * |
---|
9 | * @author Martin Lee |
---|
10 | * |
---|
11 | **/ |
---|
12 | /*****************************************************************************/ |
---|
13 | |
---|
14 | #ifndef FLINT_CONVERT_H |
---|
15 | #define FLINT_CONVERT_H |
---|
16 | |
---|
17 | // #include "config.h" |
---|
18 | #include "canonicalform.h" |
---|
19 | #include "fac_util.h" |
---|
20 | |
---|
21 | #ifdef HAVE_FLINT |
---|
22 | #ifdef __cplusplus |
---|
23 | extern "C" |
---|
24 | { |
---|
25 | #endif |
---|
26 | #ifndef __GMP_BITS_PER_MP_LIMB |
---|
27 | #define __GMP_BITS_PER_MP_LIMB GMP_LIMB_BITS |
---|
28 | #endif |
---|
29 | #include <flint/fmpz.h> |
---|
30 | #include <flint/fmpq.h> |
---|
31 | #include <flint/fmpz_poly.h> |
---|
32 | #include <flint/fmpz_mod_poly.h> |
---|
33 | #include <flint/fmpq_poly.h> |
---|
34 | #include <flint/nmod_poly.h> |
---|
35 | #include <flint/nmod_mat.h> |
---|
36 | #include <flint/fmpz_mat.h> |
---|
37 | #if ( __FLINT_RELEASE >= 20400) |
---|
38 | #include <flint/fq.h> |
---|
39 | #include <flint/fq_poly.h> |
---|
40 | #include <flint/fq_nmod.h> |
---|
41 | #include <flint/fq_nmod_poly.h> |
---|
42 | #include <flint/fq_nmod_mat.h> |
---|
43 | #endif |
---|
44 | |
---|
45 | EXTERN_VAR flint_rand_t FLINTrandom; |
---|
46 | |
---|
47 | #ifdef __cplusplus |
---|
48 | } |
---|
49 | #endif |
---|
50 | |
---|
51 | #include "factory/cf_gmp.h" |
---|
52 | |
---|
53 | /// conversion of a factory integer to fmpz_t |
---|
54 | void |
---|
55 | convertCF2Fmpz (fmpz_t result, ///< [in,out] an fmpz_t |
---|
56 | const CanonicalForm& f ///< [in] a CanonicalForm wrapping an |
---|
57 | ///< integer |
---|
58 | ); |
---|
59 | |
---|
60 | /// conversion of a factory univariate polynomial over Z to a fmpz_poly_t |
---|
61 | void |
---|
62 | convertFacCF2Fmpz_poly_t (fmpz_poly_t result, ///< [in,out] an fmpz_poly_t |
---|
63 | const CanonicalForm& f ///< [in] univariate poly over |
---|
64 | ///< Z |
---|
65 | ); |
---|
66 | |
---|
67 | /// conversion of a FLINT integer to CanonicalForm |
---|
68 | CanonicalForm |
---|
69 | convertFmpz2CF (const fmpz_t coefficient ///< [in] a FLINT integer |
---|
70 | ); |
---|
71 | |
---|
72 | /// conversion of a FLINT poly over Z to CanonicalForm |
---|
73 | CanonicalForm |
---|
74 | convertFmpz_poly_t2FacCF (const fmpz_poly_t poly, ///< [in] an fmpz_poly_t |
---|
75 | const Variable& x ///< [in] variable the result should |
---|
76 | ///< have |
---|
77 | ); |
---|
78 | |
---|
79 | /// conversion of a factory univariate polynomials over Z/p (for word size p) |
---|
80 | /// to nmod_poly_t |
---|
81 | void |
---|
82 | convertFacCF2nmod_poly_t (nmod_poly_t result, ///< [in, out] a nmod_poly_t |
---|
83 | const CanonicalForm& f ///< [in] univariate poly over |
---|
84 | ///< Z/p |
---|
85 | ); |
---|
86 | |
---|
87 | /// conversion of a FLINT poly over Z/p to CanonicalForm |
---|
88 | CanonicalForm |
---|
89 | convertnmod_poly_t2FacCF (const nmod_poly_t poly, ///< [in] a nmod_poly_t |
---|
90 | const Variable& x ///< [in] variable the result should |
---|
91 | ///< have |
---|
92 | ); |
---|
93 | |
---|
94 | /// conversion of a factory rationals to fmpq_t |
---|
95 | void |
---|
96 | convertCF2Fmpq (fmpq_t result, ///< [in,out] an fmpq_t |
---|
97 | const CanonicalForm& f ///< [in] a CanonicalForm wrapping a |
---|
98 | ///< rational |
---|
99 | ); |
---|
100 | |
---|
101 | /// conversion of a FLINT rational to CanonicalForm |
---|
102 | CanonicalForm convertFmpq2CF (const fmpq_t q); |
---|
103 | |
---|
104 | /// conversion of a factory univariate polynomials over Q to fmpq_poly_t |
---|
105 | void |
---|
106 | convertFacCF2Fmpq_poly_t (fmpq_poly_t result, ///< [in,out] an fmpq_poly_t |
---|
107 | const CanonicalForm& f ///< [in] univariate poly over |
---|
108 | ///< Q |
---|
109 | ); |
---|
110 | |
---|
111 | /// conversion of a FLINT poly over Q to CanonicalForm |
---|
112 | CanonicalForm |
---|
113 | convertFmpq_poly_t2FacCF (const fmpq_poly_t p, ///< [in] an fmpq_poly_t |
---|
114 | const Variable& x ///< [in] variable the result should |
---|
115 | ///< have |
---|
116 | ); |
---|
117 | |
---|
118 | /// conversion of a FLINT factorization over Z/p (for word size p) to a |
---|
119 | /// CFFList |
---|
120 | CFFList |
---|
121 | convertFLINTnmod_poly_factor2FacCFFList ( |
---|
122 | const nmod_poly_factor_t fac, ///< [in] a nmod_poly_factor_t |
---|
123 | const mp_limb_t leadingCoeff, ///< [in] leading coefficient |
---|
124 | const Variable& x ///< [in] variable the result should |
---|
125 | ///< have |
---|
126 | ); |
---|
127 | |
---|
128 | /// conversion of a FLINT factorization over Z to a CFFList |
---|
129 | CFFList |
---|
130 | convertFLINTfmpz_poly_factor2FacCFFList ( |
---|
131 | const fmpz_poly_factor_t fac, ///< [in] a fmpz_poly_factor_t |
---|
132 | const Variable& x ///< [in] variable the result should |
---|
133 | ///< have |
---|
134 | ); |
---|
135 | |
---|
136 | /// conversion of a factory univariate poly over Z to a FLINT poly over |
---|
137 | /// Z/p (for non word size p) |
---|
138 | void |
---|
139 | convertFacCF2Fmpz_mod_poly_t ( |
---|
140 | fmpz_mod_poly_t result, ///< [in,out] fmpz_mod_poly_t |
---|
141 | const CanonicalForm& f, ///< [in] univariate poly over |
---|
142 | ///< Z |
---|
143 | const fmpz_t p ///< [in] some integer p |
---|
144 | ); |
---|
145 | |
---|
146 | /// conversion of a FLINT poly over Z/p (for non word size p) to a CanonicalForm |
---|
147 | /// over Z |
---|
148 | CanonicalForm |
---|
149 | convertFmpz_mod_poly_t2FacCF ( |
---|
150 | const fmpz_mod_poly_t poly, ///< [in] fmpz_mod_poly_t |
---|
151 | const Variable& x, ///< [in] variable the result |
---|
152 | ///< should have |
---|
153 | const modpk& b ///< [in] coeff bound to map |
---|
154 | ///< coeffs in (-p/2,p/2) |
---|
155 | ); |
---|
156 | |
---|
157 | #if __FLINT_RELEASE >= 20400 |
---|
158 | /// conversion of a FLINT element of F_q to a CanonicalForm with alg. variable |
---|
159 | /// alpha |
---|
160 | CanonicalForm |
---|
161 | convertFq_nmod_t2FacCF (const fq_nmod_t poly, ///< [in] fq_nmod_t |
---|
162 | const Variable& alpha, ///< [in] algebraic variable |
---|
163 | const fq_nmod_ctx_t ctx ///<[in] context |
---|
164 | ); |
---|
165 | |
---|
166 | /// conversion of a FLINT element of F_q with non-word size p to a CanonicalForm |
---|
167 | /// with alg. variable alpha |
---|
168 | CanonicalForm |
---|
169 | convertFq_t2FacCF (const fq_t poly, ///< [in] fq_t |
---|
170 | const Variable& alpha ///< [in] algebraic variable |
---|
171 | ); |
---|
172 | |
---|
173 | /// conversion of a factory element of F_q to a FLINT fq_nmod_t, does not do any |
---|
174 | /// memory allocation for poly |
---|
175 | void |
---|
176 | convertFacCF2Fq_nmod_t (fq_nmod_t result, ///< [in,out] fq_nmod_t |
---|
177 | const CanonicalForm& f, ///< [in] element of Fq |
---|
178 | const fq_nmod_ctx_t ctx ///< [in] Fq context |
---|
179 | ); |
---|
180 | |
---|
181 | /// conversion of a factory element of F_q (for non-word size p) to a FLINT fq_t |
---|
182 | void |
---|
183 | convertFacCF2Fq_t (fq_t result, ///< [in,out] fq_t |
---|
184 | const CanonicalForm& f, ///< [in] element of Fq |
---|
185 | const fq_ctx_t ctx ///< [in] Fq context |
---|
186 | ); |
---|
187 | |
---|
188 | /// conversion of a factory univariate poly over F_q (for non-word size p) to a |
---|
189 | /// FLINT fq_poly_t |
---|
190 | void |
---|
191 | convertFacCF2Fq_poly_t (fq_poly_t result, ///< [in,out] fq_poly_t |
---|
192 | const CanonicalForm& f,///< [in] univariate poly over Fq |
---|
193 | const fq_ctx_t ctx ///< [in] Fq context |
---|
194 | ); |
---|
195 | |
---|
196 | /// conversion of a factory univariate poly over F_q to a FLINT fq_nmod_poly_t |
---|
197 | void |
---|
198 | convertFacCF2Fq_nmod_poly_t (fq_nmod_poly_t result, ///< [in,out] fq_nmod_poly_t |
---|
199 | const CanonicalForm& f,///< [in] univariate poly |
---|
200 | ///< over Fq |
---|
201 | const fq_nmod_ctx_t ctx///< [in] Fq context |
---|
202 | ); |
---|
203 | |
---|
204 | /// conversion of a FLINT poly over Fq (for non-word size p) to a CanonicalForm |
---|
205 | /// with alg. variable alpha and polynomial variable x |
---|
206 | CanonicalForm |
---|
207 | convertFq_poly_t2FacCF (const fq_poly_t p, ///< [in] fq_poly_t |
---|
208 | const Variable& x, ///< [in] polynomial variable |
---|
209 | const Variable& alpha, ///< [in] algebraic variable |
---|
210 | const fq_ctx_t ctx ///< [in] Fq context |
---|
211 | ); |
---|
212 | |
---|
213 | /// conversion of a FLINT poly over Fq to a CanonicalForm with alg. variable |
---|
214 | /// alpha and polynomial variable x |
---|
215 | CanonicalForm |
---|
216 | convertFq_nmod_poly_t2FacCF (const fq_nmod_poly_t p, ///< [in] fq_nmod_poly_t |
---|
217 | const Variable& x, ///< [in] polynomial var. |
---|
218 | const Variable& alpha, ///< [in] algebraic var. |
---|
219 | const fq_nmod_ctx_t ctx ///< [in] Fq context |
---|
220 | ); |
---|
221 | #endif |
---|
222 | |
---|
223 | /// conversion of a factory matrix over Z to a fmpz_mat_t |
---|
224 | void convertFacCFMatrix2Fmpz_mat_t (fmpz_mat_t M, ///<[in,out] fmpz_mat_t |
---|
225 | const CFMatrix &m ///<[in] matrix over Z |
---|
226 | ); |
---|
227 | |
---|
228 | /// conversion of a FLINT matrix over Z to a factory matrix |
---|
229 | CFMatrix* convertFmpz_mat_t2FacCFMatrix(const fmpz_mat_t m ///<[in] fmpz_mat_t |
---|
230 | ); |
---|
231 | |
---|
232 | /// conversion of a factory matrix over Z/p to a nmod_mat_t |
---|
233 | void convertFacCFMatrix2nmod_mat_t (nmod_mat_t M, ///<[in,out] nmod_mat_t |
---|
234 | const CFMatrix &m ///<[in] matrix over Z/p |
---|
235 | ); |
---|
236 | |
---|
237 | /// conversion of a FLINT matrix over Z/p to a factory matrix |
---|
238 | CFMatrix* convertNmod_mat_t2FacCFMatrix(const nmod_mat_t m ///<[in] nmod_mat_t |
---|
239 | ); |
---|
240 | |
---|
241 | #if __FLINT_RELEASE >= 20400 |
---|
242 | /// conversion of a FLINT matrix over F_q to a factory matrix |
---|
243 | CFMatrix* |
---|
244 | convertFq_nmod_mat_t2FacCFMatrix(const fq_nmod_mat_t m, ///< [in] fq_nmod_mat_t |
---|
245 | const fq_nmod_ctx_t& fq_con, ///< [in] Fq context |
---|
246 | const Variable& alpha ///< [in] algebraic variable |
---|
247 | ); |
---|
248 | |
---|
249 | /// conversion of a factory matrix over F_q to a fq_nmod_mat_t |
---|
250 | void |
---|
251 | convertFacCFMatrix2Fq_nmod_mat_t (fq_nmod_mat_t M, ///< [in, out] fq_nmod_mat_t |
---|
252 | const fq_nmod_ctx_t fq_con, ///< [in] Fq context |
---|
253 | const CFMatrix &m ///< [in] matrix over Fq |
---|
254 | ); |
---|
255 | |
---|
256 | /// conversion of a FLINT factorization over Fq (for word size p) to a |
---|
257 | /// CFFList |
---|
258 | CFFList |
---|
259 | convertFLINTFq_nmod_poly_factor2FacCFFList (const fq_nmod_poly_factor_t fac, ///< [in] fq_nmod_poly_factor_t |
---|
260 | const Variable& x, ///< [in] polynomial variable |
---|
261 | const Variable& alpha, ///< [in] algebraic variable |
---|
262 | const fq_nmod_ctx_t fq_con ///< [in] Fq context |
---|
263 | ); |
---|
264 | #endif |
---|
265 | |
---|
266 | |
---|
267 | #if __FLINT_RELEASE >= 20503 |
---|
268 | CanonicalForm mulFlintMP_Zp(const CanonicalForm& F,int lF, const CanonicalForm& Gi, int lG, int m); |
---|
269 | CanonicalForm mulFlintMP_QQ(const CanonicalForm& F,int lF, const CanonicalForm& Gi, int lG, int m); |
---|
270 | CanonicalForm gcdFlintMP_Zp(const CanonicalForm& F, const CanonicalForm& G); |
---|
271 | CanonicalForm gcdFlintMP_QQ(const CanonicalForm& F, const CanonicalForm& G); |
---|
272 | #endif |
---|
273 | #endif |
---|
274 | #endif |
---|