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 | #if ( __FLINT_RELEASE >= 20503) |
---|
44 | #include <flint/fmpq_mpoly.h> |
---|
45 | #endif |
---|
46 | #endif |
---|
47 | |
---|
48 | EXTERN_VAR flint_rand_t FLINTrandom; |
---|
49 | |
---|
50 | #ifdef __cplusplus |
---|
51 | } |
---|
52 | #endif |
---|
53 | |
---|
54 | #include "factory/cf_gmp.h" |
---|
55 | |
---|
56 | /// conversion of a factory integer to fmpz_t |
---|
57 | void |
---|
58 | convertCF2Fmpz (fmpz_t result, ///< [in,out] an fmpz_t |
---|
59 | const CanonicalForm& f ///< [in] a CanonicalForm wrapping an |
---|
60 | ///< integer |
---|
61 | ); |
---|
62 | |
---|
63 | /// conversion of a factory univariate polynomial over Z to a fmpz_poly_t |
---|
64 | void |
---|
65 | convertFacCF2Fmpz_poly_t (fmpz_poly_t result, ///< [in,out] an fmpz_poly_t |
---|
66 | const CanonicalForm& f ///< [in] univariate poly over |
---|
67 | ///< Z |
---|
68 | ); |
---|
69 | |
---|
70 | /// conversion of a FLINT integer to CanonicalForm |
---|
71 | CanonicalForm |
---|
72 | convertFmpz2CF (const fmpz_t coefficient ///< [in] a FLINT integer |
---|
73 | ); |
---|
74 | |
---|
75 | /// conversion of a FLINT poly over Z to CanonicalForm |
---|
76 | CanonicalForm |
---|
77 | convertFmpz_poly_t2FacCF (const fmpz_poly_t poly, ///< [in] an fmpz_poly_t |
---|
78 | const Variable& x ///< [in] variable the result should |
---|
79 | ///< have |
---|
80 | ); |
---|
81 | |
---|
82 | /// conversion of a factory univariate polynomials over Z/p (for word size p) |
---|
83 | /// to nmod_poly_t |
---|
84 | void |
---|
85 | convertFacCF2nmod_poly_t (nmod_poly_t result, ///< [in, out] a nmod_poly_t |
---|
86 | const CanonicalForm& f ///< [in] univariate poly over |
---|
87 | ///< Z/p |
---|
88 | ); |
---|
89 | |
---|
90 | /// conversion of a FLINT poly over Z/p to CanonicalForm |
---|
91 | CanonicalForm |
---|
92 | convertnmod_poly_t2FacCF (const nmod_poly_t poly, ///< [in] a nmod_poly_t |
---|
93 | const Variable& x ///< [in] variable the result should |
---|
94 | ///< have |
---|
95 | ); |
---|
96 | |
---|
97 | /// conversion of a factory rationals to fmpq_t |
---|
98 | void |
---|
99 | convertCF2Fmpq (fmpq_t result, ///< [in,out] an fmpq_t |
---|
100 | const CanonicalForm& f ///< [in] a CanonicalForm wrapping a |
---|
101 | ///< rational |
---|
102 | ); |
---|
103 | |
---|
104 | /// conversion of a FLINT rational to CanonicalForm |
---|
105 | CanonicalForm convertFmpq2CF (const fmpq_t q); |
---|
106 | |
---|
107 | /// conversion of a factory univariate polynomials over Q to fmpq_poly_t |
---|
108 | void |
---|
109 | convertFacCF2Fmpq_poly_t (fmpq_poly_t result, ///< [in,out] an fmpq_poly_t |
---|
110 | const CanonicalForm& f ///< [in] univariate poly over |
---|
111 | ///< Q |
---|
112 | ); |
---|
113 | |
---|
114 | /// conversion of a FLINT poly over Q to CanonicalForm |
---|
115 | CanonicalForm |
---|
116 | convertFmpq_poly_t2FacCF (const fmpq_poly_t p, ///< [in] an fmpq_poly_t |
---|
117 | const Variable& x ///< [in] variable the result should |
---|
118 | ///< have |
---|
119 | ); |
---|
120 | |
---|
121 | /// conversion of a FLINT factorization over Z/p (for word size p) to a |
---|
122 | /// CFFList |
---|
123 | CFFList |
---|
124 | convertFLINTnmod_poly_factor2FacCFFList ( |
---|
125 | const nmod_poly_factor_t fac, ///< [in] a nmod_poly_factor_t |
---|
126 | const mp_limb_t leadingCoeff, ///< [in] leading coefficient |
---|
127 | const Variable& x ///< [in] variable the result should |
---|
128 | ///< have |
---|
129 | ); |
---|
130 | |
---|
131 | /// conversion of a FLINT factorization over Z to a CFFList |
---|
132 | CFFList |
---|
133 | convertFLINTfmpz_poly_factor2FacCFFList ( |
---|
134 | const fmpz_poly_factor_t fac, ///< [in] a fmpz_poly_factor_t |
---|
135 | const Variable& x ///< [in] variable the result should |
---|
136 | ///< have |
---|
137 | ); |
---|
138 | |
---|
139 | /// conversion of a factory univariate poly over Z to a FLINT poly over |
---|
140 | /// Z/p (for non word size p) |
---|
141 | void |
---|
142 | convertFacCF2Fmpz_mod_poly_t ( |
---|
143 | fmpz_mod_poly_t result, ///< [in,out] fmpz_mod_poly_t |
---|
144 | const CanonicalForm& f, ///< [in] univariate poly over |
---|
145 | ///< Z |
---|
146 | const fmpz_t p ///< [in] some integer p |
---|
147 | ); |
---|
148 | |
---|
149 | /// conversion of a FLINT poly over Z/p (for non word size p) to a CanonicalForm |
---|
150 | /// over Z |
---|
151 | CanonicalForm |
---|
152 | convertFmpz_mod_poly_t2FacCF ( |
---|
153 | const fmpz_mod_poly_t poly, ///< [in] fmpz_mod_poly_t |
---|
154 | const Variable& x, ///< [in] variable the result |
---|
155 | ///< should have |
---|
156 | const modpk& b ///< [in] coeff bound to map |
---|
157 | ///< coeffs in (-p/2,p/2) |
---|
158 | ); |
---|
159 | |
---|
160 | #if __FLINT_RELEASE >= 20400 |
---|
161 | /// conversion of a FLINT element of F_q to a CanonicalForm with alg. variable |
---|
162 | /// alpha |
---|
163 | CanonicalForm |
---|
164 | convertFq_nmod_t2FacCF (const fq_nmod_t poly, ///< [in] fq_nmod_t |
---|
165 | const Variable& alpha, ///< [in] algebraic variable |
---|
166 | const fq_nmod_ctx_t ctx ///<[in] context |
---|
167 | ); |
---|
168 | |
---|
169 | /// conversion of a FLINT element of F_q with non-word size p to a CanonicalForm |
---|
170 | /// with alg. variable alpha |
---|
171 | CanonicalForm |
---|
172 | convertFq_t2FacCF (const fq_t poly, ///< [in] fq_t |
---|
173 | const Variable& alpha ///< [in] algebraic variable |
---|
174 | ); |
---|
175 | |
---|
176 | /// conversion of a factory element of F_q to a FLINT fq_nmod_t, does not do any |
---|
177 | /// memory allocation for poly |
---|
178 | void |
---|
179 | convertFacCF2Fq_nmod_t (fq_nmod_t result, ///< [in,out] fq_nmod_t |
---|
180 | const CanonicalForm& f, ///< [in] element of Fq |
---|
181 | const fq_nmod_ctx_t ctx ///< [in] Fq context |
---|
182 | ); |
---|
183 | |
---|
184 | /// conversion of a factory element of F_q (for non-word size p) to a FLINT fq_t |
---|
185 | void |
---|
186 | convertFacCF2Fq_t (fq_t result, ///< [in,out] fq_t |
---|
187 | const CanonicalForm& f, ///< [in] element of Fq |
---|
188 | const fq_ctx_t ctx ///< [in] Fq context |
---|
189 | ); |
---|
190 | |
---|
191 | /// conversion of a factory univariate poly over F_q (for non-word size p) to a |
---|
192 | /// FLINT fq_poly_t |
---|
193 | void |
---|
194 | convertFacCF2Fq_poly_t (fq_poly_t result, ///< [in,out] fq_poly_t |
---|
195 | const CanonicalForm& f,///< [in] univariate poly over Fq |
---|
196 | const fq_ctx_t ctx ///< [in] Fq context |
---|
197 | ); |
---|
198 | |
---|
199 | /// conversion of a factory univariate poly over F_q to a FLINT fq_nmod_poly_t |
---|
200 | void |
---|
201 | convertFacCF2Fq_nmod_poly_t (fq_nmod_poly_t result, ///< [in,out] fq_nmod_poly_t |
---|
202 | const CanonicalForm& f,///< [in] univariate poly |
---|
203 | ///< over Fq |
---|
204 | const fq_nmod_ctx_t ctx///< [in] Fq context |
---|
205 | ); |
---|
206 | |
---|
207 | /// conversion of a FLINT poly over Fq (for non-word size p) to a CanonicalForm |
---|
208 | /// with alg. variable alpha and polynomial variable x |
---|
209 | CanonicalForm |
---|
210 | convertFq_poly_t2FacCF (const fq_poly_t p, ///< [in] fq_poly_t |
---|
211 | const Variable& x, ///< [in] polynomial variable |
---|
212 | const Variable& alpha, ///< [in] algebraic variable |
---|
213 | const fq_ctx_t ctx ///< [in] Fq context |
---|
214 | ); |
---|
215 | |
---|
216 | /// conversion of a FLINT poly over Fq to a CanonicalForm with alg. variable |
---|
217 | /// alpha and polynomial variable x |
---|
218 | CanonicalForm |
---|
219 | convertFq_nmod_poly_t2FacCF (const fq_nmod_poly_t p, ///< [in] fq_nmod_poly_t |
---|
220 | const Variable& x, ///< [in] polynomial var. |
---|
221 | const Variable& alpha, ///< [in] algebraic var. |
---|
222 | const fq_nmod_ctx_t ctx ///< [in] Fq context |
---|
223 | ); |
---|
224 | #endif |
---|
225 | |
---|
226 | /// conversion of a factory matrix over Z to a fmpz_mat_t |
---|
227 | void convertFacCFMatrix2Fmpz_mat_t (fmpz_mat_t M, ///<[in,out] fmpz_mat_t |
---|
228 | const CFMatrix &m ///<[in] matrix over Z |
---|
229 | ); |
---|
230 | |
---|
231 | /// conversion of a FLINT matrix over Z to a factory matrix |
---|
232 | CFMatrix* convertFmpz_mat_t2FacCFMatrix(const fmpz_mat_t m ///<[in] fmpz_mat_t |
---|
233 | ); |
---|
234 | |
---|
235 | /// conversion of a factory matrix over Z/p to a nmod_mat_t |
---|
236 | void convertFacCFMatrix2nmod_mat_t (nmod_mat_t M, ///<[in,out] nmod_mat_t |
---|
237 | const CFMatrix &m ///<[in] matrix over Z/p |
---|
238 | ); |
---|
239 | |
---|
240 | /// conversion of a FLINT matrix over Z/p to a factory matrix |
---|
241 | CFMatrix* convertNmod_mat_t2FacCFMatrix(const nmod_mat_t m ///<[in] nmod_mat_t |
---|
242 | ); |
---|
243 | |
---|
244 | #if __FLINT_RELEASE >= 20400 |
---|
245 | /// conversion of a FLINT matrix over F_q to a factory matrix |
---|
246 | CFMatrix* |
---|
247 | convertFq_nmod_mat_t2FacCFMatrix(const fq_nmod_mat_t m, ///< [in] fq_nmod_mat_t |
---|
248 | const fq_nmod_ctx_t& fq_con, ///< [in] Fq context |
---|
249 | const Variable& alpha ///< [in] algebraic variable |
---|
250 | ); |
---|
251 | |
---|
252 | /// conversion of a factory matrix over F_q to a fq_nmod_mat_t |
---|
253 | void |
---|
254 | convertFacCFMatrix2Fq_nmod_mat_t (fq_nmod_mat_t M, ///< [in, out] fq_nmod_mat_t |
---|
255 | const fq_nmod_ctx_t fq_con, ///< [in] Fq context |
---|
256 | const CFMatrix &m ///< [in] matrix over Fq |
---|
257 | ); |
---|
258 | |
---|
259 | /// conversion of a FLINT factorization over Fq (for word size p) to a |
---|
260 | /// CFFList |
---|
261 | CFFList |
---|
262 | convertFLINTFq_nmod_poly_factor2FacCFFList (const fq_nmod_poly_factor_t fac, ///< [in] fq_nmod_poly_factor_t |
---|
263 | const Variable& x, ///< [in] polynomial variable |
---|
264 | const Variable& alpha, ///< [in] algebraic variable |
---|
265 | const fq_nmod_ctx_t fq_con ///< [in] Fq context |
---|
266 | ); |
---|
267 | #endif |
---|
268 | |
---|
269 | |
---|
270 | #if __FLINT_RELEASE >= 20503 |
---|
271 | CanonicalForm mulFlintMP_Zp(const CanonicalForm& F,int lF, const CanonicalForm& Gi, int lG, int m); |
---|
272 | CanonicalForm mulFlintMP_QQ(const CanonicalForm& F,int lF, const CanonicalForm& Gi, int lG, int m); |
---|
273 | CanonicalForm gcdFlintMP_Zp(const CanonicalForm& F, const CanonicalForm& G); |
---|
274 | CanonicalForm gcdFlintMP_QQ(const CanonicalForm& F, const CanonicalForm& G); |
---|
275 | void convFactoryPFlintMP ( const CanonicalForm & f, nmod_mpoly_t res, nmod_mpoly_ctx_t ctx, int N ); |
---|
276 | void convFactoryPFlintMP ( const CanonicalForm & f, fmpq_mpoly_t res, fmpq_mpoly_ctx_t ctx, int N ); |
---|
277 | CanonicalForm convFlintMPFactoryP(nmod_mpoly_t f, nmod_mpoly_ctx_t ctx, int N); |
---|
278 | CanonicalForm convFlintMPFactoryP(fmpq_mpoly_t f, fmpq_mpoly_ctx_t ctx, int N); |
---|
279 | #endif |
---|
280 | #endif |
---|
281 | #endif |
---|