1 | #ifndef POLYS_NC_H |
---|
2 | #define POLYS_NC_H |
---|
3 | |
---|
4 | |
---|
5 | #ifdef HAVE_PLURAL |
---|
6 | |
---|
7 | |
---|
8 | |
---|
9 | // TODO: the following is a part of ring.h... would be nice to have a |
---|
10 | // clear public NC interface defined here! |
---|
11 | |
---|
12 | #include <polys/monomials/ring.h> |
---|
13 | #include <polys/kbuckets.h> |
---|
14 | |
---|
15 | |
---|
16 | class ip_smatrix; |
---|
17 | typedef ip_smatrix * matrix; |
---|
18 | |
---|
19 | class skStrategy; |
---|
20 | typedef skStrategy * kStrategy; |
---|
21 | |
---|
22 | |
---|
23 | matrix nc_PrintMat(int a, int b, ring r, int metric); |
---|
24 | |
---|
25 | |
---|
26 | enum nc_type |
---|
27 | { |
---|
28 | nc_error = -1, // Something's gone wrong! |
---|
29 | nc_general = 0, /* yx=q xy+... */ |
---|
30 | nc_skew, /*1*/ /* yx=q xy */ |
---|
31 | nc_comm, /*2*/ /* yx= xy */ |
---|
32 | nc_lie, /*3*/ /* yx=xy+... */ |
---|
33 | nc_undef, /*4*/ /* for internal reasons */ |
---|
34 | |
---|
35 | nc_exterior /*5*/ // Exterior Algebra(SCA): yx= -xy & (!:) x^2 = 0 |
---|
36 | }; |
---|
37 | |
---|
38 | |
---|
39 | // ////////////////////////////////////////////////////// |
---|
40 | |
---|
41 | |
---|
42 | /// checks whether rings rBase and rCandidate |
---|
43 | /// could be opposite to each other |
---|
44 | /// returns TRUE if it is so |
---|
45 | BOOLEAN rIsLikeOpposite(ring rBase, ring rCandidate); |
---|
46 | |
---|
47 | |
---|
48 | |
---|
49 | // Macros used to access upper triangle matrices C,D... (which are actually ideals) // afaik |
---|
50 | #define UPMATELEM(i,j,nVar) ( (nVar * ((i)-1) - ((i) * ((i)-1))/2 + (j)-1)-(i) ) |
---|
51 | |
---|
52 | /// complete destructor |
---|
53 | void nc_rKill(ring r); |
---|
54 | |
---|
55 | |
---|
56 | BOOLEAN nc_CheckSubalgebra(poly PolyVar, ring r); |
---|
57 | |
---|
58 | // NC pProcs: |
---|
59 | typedef poly (*mm_Mult_p_Proc_Ptr)(const poly m, poly p, const ring r); |
---|
60 | typedef poly (*mm_Mult_pp_Proc_Ptr)(const poly m, const poly p, const ring r); |
---|
61 | |
---|
62 | |
---|
63 | |
---|
64 | typedef ideal (*GB_Proc_Ptr)(const ideal F, const ideal Q, const intvec *w, const intvec *hilb, kStrategy strat, const ring r); |
---|
65 | |
---|
66 | typedef poly (*SPoly_Proc_Ptr)(const poly p1, const poly p2, const ring r); |
---|
67 | typedef poly (*SPolyReduce_Proc_Ptr)(const poly p1, poly p2, const ring r); |
---|
68 | |
---|
69 | typedef void (*bucket_Proc_Ptr)(kBucket_pt b, poly p, number *c); |
---|
70 | |
---|
71 | struct nc_pProcs |
---|
72 | { |
---|
73 | public: |
---|
74 | mm_Mult_p_Proc_Ptr mm_Mult_p; |
---|
75 | mm_Mult_pp_Proc_Ptr mm_Mult_pp; |
---|
76 | |
---|
77 | bucket_Proc_Ptr BucketPolyRed; |
---|
78 | bucket_Proc_Ptr BucketPolyRed_Z; |
---|
79 | |
---|
80 | SPoly_Proc_Ptr SPoly; |
---|
81 | SPolyReduce_Proc_Ptr ReduceSPoly; |
---|
82 | |
---|
83 | GB_Proc_Ptr GB; |
---|
84 | // GlobalGB, // BBA |
---|
85 | // LocalGB; // MORA |
---|
86 | }; |
---|
87 | |
---|
88 | class CGlobalMultiplier; |
---|
89 | class CFormulaPowerMultiplier; |
---|
90 | |
---|
91 | struct nc_struct |
---|
92 | { |
---|
93 | nc_type type; |
---|
94 | //ring basering; // the ring C,D,.. live in (commutative ring with this NC structure!) |
---|
95 | |
---|
96 | // initial data: square matrices rVar() x rVar() |
---|
97 | // logically: upper triangular!!! |
---|
98 | // TODO: eliminate this waste of memory!!!! |
---|
99 | matrix C; |
---|
100 | matrix D; |
---|
101 | |
---|
102 | // computed data: |
---|
103 | matrix *MT; // size 0.. (rVar()*rVar()-1)/2 |
---|
104 | matrix COM; |
---|
105 | int *MTsize; // size 0.. (rVar()*rVar()-1)/2 |
---|
106 | |
---|
107 | // IsSkewConstant indicates whethere coeffs C_ij are all equal, |
---|
108 | // effective together with nc_type=nc_skew |
---|
109 | int IsSkewConstant; |
---|
110 | |
---|
111 | private: |
---|
112 | // internal data for different implementations |
---|
113 | // if dynamic => must be deallocated in destructor (nc_rKill!) |
---|
114 | union |
---|
115 | { |
---|
116 | struct |
---|
117 | { |
---|
118 | // treat variables from iAltVarsStart till iAltVarsEnd as alternating vars. |
---|
119 | // these variables should have odd degree, though that will not be checked |
---|
120 | // iAltVarsStart, iAltVarsEnd are only used together with nc_type=nc_exterior |
---|
121 | // 1 <= iAltVarsStart <= iAltVarsEnd <= r->N |
---|
122 | unsigned int iFirstAltVar, iLastAltVar; // = 0 by default |
---|
123 | |
---|
124 | // for factors of super-commutative algebras we need |
---|
125 | // the part of general quotient ideal modulo squares! |
---|
126 | ideal idSCAQuotient; // = NULL by default. // must be deleted in Kill! |
---|
127 | } sca; |
---|
128 | } data; |
---|
129 | |
---|
130 | public: |
---|
131 | |
---|
132 | inline nc_type& ncRingType() { return (type); }; |
---|
133 | inline nc_type ncRingType() const { return (type); }; |
---|
134 | |
---|
135 | inline unsigned int& FirstAltVar() |
---|
136 | { assume(ncRingType() == nc_exterior); return (data.sca.iFirstAltVar); }; |
---|
137 | inline unsigned int& LastAltVar () |
---|
138 | { assume(ncRingType() == nc_exterior); return (data.sca.iLastAltVar ); }; |
---|
139 | |
---|
140 | inline unsigned int FirstAltVar() const |
---|
141 | { assume(ncRingType() == nc_exterior); return (data.sca.iFirstAltVar); }; |
---|
142 | inline unsigned int LastAltVar () const |
---|
143 | { assume(ncRingType() == nc_exterior); return (data.sca.iLastAltVar ); }; |
---|
144 | |
---|
145 | inline ideal& SCAQuotient() |
---|
146 | { assume(ncRingType() == nc_exterior); return (data.sca.idSCAQuotient); }; |
---|
147 | private: |
---|
148 | |
---|
149 | CGlobalMultiplier* m_Multiplier; |
---|
150 | CFormulaPowerMultiplier* m_PowerMultiplier; |
---|
151 | |
---|
152 | public: |
---|
153 | |
---|
154 | inline CGlobalMultiplier* GetGlobalMultiplier() const |
---|
155 | { return (m_Multiplier); }; |
---|
156 | |
---|
157 | inline CGlobalMultiplier*& GetGlobalMultiplier() |
---|
158 | { return (m_Multiplier); }; |
---|
159 | |
---|
160 | |
---|
161 | inline CFormulaPowerMultiplier* GetFormulaPowerMultiplier() const |
---|
162 | { return (m_PowerMultiplier); }; |
---|
163 | |
---|
164 | inline CFormulaPowerMultiplier*& GetFormulaPowerMultiplier() |
---|
165 | { return (m_PowerMultiplier); }; |
---|
166 | |
---|
167 | public: |
---|
168 | nc_pProcs p_Procs; // NC procedures. |
---|
169 | |
---|
170 | }; |
---|
171 | |
---|
172 | |
---|
173 | |
---|
174 | |
---|
175 | // //////////////////////////////////////////////////////////////////////// // |
---|
176 | // NC inlines |
---|
177 | |
---|
178 | static inline nc_struct*& GetNC(ring r) |
---|
179 | { |
---|
180 | return r->GetNC(); |
---|
181 | } |
---|
182 | |
---|
183 | static inline nc_type& ncRingType(nc_struct* p) |
---|
184 | { |
---|
185 | assume(p!=NULL); |
---|
186 | return (p->ncRingType()); |
---|
187 | } |
---|
188 | |
---|
189 | static inline nc_type ncRingType(ring r) // Get |
---|
190 | { |
---|
191 | if(rIsPluralRing(r)) |
---|
192 | return (ncRingType(r->GetNC())); |
---|
193 | else |
---|
194 | return (nc_error); |
---|
195 | } |
---|
196 | |
---|
197 | static inline void ncRingType(ring r, nc_type t) // Set |
---|
198 | { |
---|
199 | assume((r != NULL) && (r->GetNC() != NULL)); |
---|
200 | ncRingType(r->GetNC()) = t; |
---|
201 | } |
---|
202 | |
---|
203 | static inline void ncRingType(nc_struct* p, nc_type t) // Set |
---|
204 | { |
---|
205 | assume(p!=NULL); |
---|
206 | ncRingType(p) = t; |
---|
207 | } |
---|
208 | |
---|
209 | |
---|
210 | |
---|
211 | |
---|
212 | // //////////////////////////////////////////////////////////////////////// // |
---|
213 | // we must always have this test!? |
---|
214 | static inline bool rIsSCA(const ring r) |
---|
215 | { |
---|
216 | #ifdef HAVE_PLURAL |
---|
217 | return rIsPluralRing(r) && (ncRingType(r) == nc_exterior); |
---|
218 | #else |
---|
219 | return false; |
---|
220 | #endif |
---|
221 | } |
---|
222 | |
---|
223 | // //////////////////////////////////////////////////////////////////////// // |
---|
224 | // NC inlines |
---|
225 | |
---|
226 | |
---|
227 | /// general NC-multiplication with destruction |
---|
228 | poly _nc_p_Mult_q(poly p, poly q, const ring r); |
---|
229 | |
---|
230 | /// general NC-multiplication without destruction |
---|
231 | poly _nc_pp_Mult_qq(const poly p, const poly q, const ring r); |
---|
232 | |
---|
233 | |
---|
234 | |
---|
235 | /// for p_Minus_mm_Mult_qq in pInline2.h |
---|
236 | poly nc_p_Minus_mm_Mult_qq(poly p, const poly m, const poly q, int &lp, |
---|
237 | const int, const poly, const ring r); |
---|
238 | |
---|
239 | // // for p_Plus_mm_Mult_qq in pInline2.h |
---|
240 | // returns p + m*q destroys p, const: q, m |
---|
241 | poly nc_p_Plus_mm_Mult_qq(poly p, const poly m, const poly q, int &lp, |
---|
242 | const int, const ring r); |
---|
243 | |
---|
244 | |
---|
245 | |
---|
246 | |
---|
247 | // returns m*p, does neither destroy p nor m |
---|
248 | static inline poly nc_mm_Mult_pp(const poly m, const poly p, const ring r) |
---|
249 | { |
---|
250 | assume(rIsPluralRing(r)); |
---|
251 | assume(r->GetNC()->p_Procs.mm_Mult_pp!=NULL); |
---|
252 | return r->GetNC()->p_Procs.mm_Mult_pp(m, p, r); |
---|
253 | // return pp_Mult_mm( p, m, r); |
---|
254 | } |
---|
255 | |
---|
256 | |
---|
257 | // returns m*p, does destroy p, preserves m |
---|
258 | static inline poly nc_mm_Mult_p(const poly m, poly p, const ring r) |
---|
259 | { |
---|
260 | assume(rIsPluralRing(r)); |
---|
261 | assume(r->GetNC()->p_Procs.mm_Mult_p!=NULL); |
---|
262 | return r->GetNC()->p_Procs.mm_Mult_p(m, p, r); |
---|
263 | // return p_Mult_mm( p, m, r); |
---|
264 | } |
---|
265 | |
---|
266 | static inline poly nc_CreateSpoly(const poly p1, const poly p2, const ring r) |
---|
267 | { |
---|
268 | assume(rIsPluralRing(r)); |
---|
269 | assume(r->GetNC()->p_Procs.SPoly!=NULL); |
---|
270 | return r->GetNC()->p_Procs.SPoly(p1, p2, r); |
---|
271 | } |
---|
272 | |
---|
273 | // ? |
---|
274 | poly nc_CreateShortSpoly(poly p1, poly p2, const ring r); |
---|
275 | |
---|
276 | /* brackets: p will be destroyed... */ |
---|
277 | poly nc_p_Bracket_qq(poly p, const poly q, const ring r); |
---|
278 | |
---|
279 | static inline poly nc_ReduceSpoly(const poly p1, poly p2, const ring r) |
---|
280 | { |
---|
281 | assume(rIsPluralRing(r)); |
---|
282 | assume(r->GetNC()->p_Procs.ReduceSPoly!=NULL); |
---|
283 | #ifdef PDEBUG |
---|
284 | // assume(p_LmDivisibleBy(p1, p2, r)); |
---|
285 | #endif |
---|
286 | return r->GetNC()->p_Procs.ReduceSPoly(p1, p2, r); |
---|
287 | } |
---|
288 | |
---|
289 | void nc_PolyPolyRed(poly &b, poly p, number *c, const ring r); |
---|
290 | |
---|
291 | /* |
---|
292 | static inline void nc_PolyReduce(poly &b, const poly p, number *c, const ring r) // nc_PolyPolyRed |
---|
293 | { |
---|
294 | assume(rIsPluralRing(r)); |
---|
295 | // assume(r->GetNC()->p_Procs.PolyReduce!=NULL); |
---|
296 | // r->GetNC()->p_Procs.PolyReduce(b, p, c, r); |
---|
297 | } |
---|
298 | */ |
---|
299 | |
---|
300 | static inline void nc_kBucketPolyRed(kBucket_pt b, poly p, number *c) |
---|
301 | { |
---|
302 | const ring r = b->bucket_ring; |
---|
303 | assume(rIsPluralRing(r)); |
---|
304 | |
---|
305 | // return gnc_kBucketPolyRedNew(b, p, c); |
---|
306 | |
---|
307 | assume(r->GetNC()->p_Procs.BucketPolyRed!=NULL); |
---|
308 | return r->GetNC()->p_Procs.BucketPolyRed(b, p, c); |
---|
309 | } |
---|
310 | |
---|
311 | static inline void nc_BucketPolyRed_Z(kBucket_pt b, poly p, number *c) |
---|
312 | { |
---|
313 | const ring r = b->bucket_ring; |
---|
314 | assume(rIsPluralRing(r)); |
---|
315 | |
---|
316 | // return gnc_kBucketPolyRed_ZNew(b, p, c); |
---|
317 | |
---|
318 | assume(r->GetNC()->p_Procs.BucketPolyRed_Z!=NULL); |
---|
319 | return r->GetNC()->p_Procs.BucketPolyRed_Z(b, p, c); |
---|
320 | |
---|
321 | } |
---|
322 | |
---|
323 | static inline ideal nc_GB(const ideal F, const ideal Q, const intvec *w, const intvec *hilb, kStrategy strat, const ring r) |
---|
324 | { |
---|
325 | assume(rIsPluralRing(r)); |
---|
326 | |
---|
327 | assume(r->GetNC()->p_Procs.GB!=NULL); |
---|
328 | return r->GetNC()->p_Procs.GB(F, Q, w, hilb, strat, r); |
---|
329 | } |
---|
330 | |
---|
331 | |
---|
332 | |
---|
333 | /* subst: */ |
---|
334 | poly nc_pSubst(poly p, int n, poly e, const ring r); |
---|
335 | |
---|
336 | // set pProcs table for rGR and global variable p_Procs |
---|
337 | // this should be used by p_ProcsSet in p_Procs_Set.h |
---|
338 | void nc_p_ProcsSet(ring rGR, p_Procs_s* p_Procs); |
---|
339 | |
---|
340 | |
---|
341 | // the part, related to the interface |
---|
342 | // Changes r, Assumes that all other input belongs to curr |
---|
343 | BOOLEAN nc_CallPlural(matrix cc, matrix dd, poly cn, poly dn, ring r, |
---|
344 | bool bSetupQuotient, //< false |
---|
345 | bool bCopyInput, //< true |
---|
346 | bool bBeQuiet, //< false |
---|
347 | ring curr, |
---|
348 | bool dummy_ring = false |
---|
349 | /* allow to create a nc-ring with 1 variable*/); |
---|
350 | |
---|
351 | |
---|
352 | BOOLEAN nc_rComplete(const ring src, ring dest, bool bSetupQuotient = true); // in ring.cc |
---|
353 | |
---|
354 | // this function should be used inside QRing definition! |
---|
355 | // we go from rG into factor ring rGR with factor ideal rGR->qideal. |
---|
356 | bool nc_SetupQuotient(ring rGR, const ring rG = NULL, bool bCopy = false); // rG == NULL means that there is no base G-algebra |
---|
357 | |
---|
358 | |
---|
359 | bool nc_rCopy(ring res, const ring r, bool bSetupQuotient); |
---|
360 | |
---|
361 | poly pOppose(ring Rop_src, poly p, const ring Rop_dst); |
---|
362 | ideal idOppose(ring Rop_src, ideal I, const ring Rop_dst); |
---|
363 | |
---|
364 | |
---|
365 | |
---|
366 | // returns the LCM of the head terms of a and b with the given component |
---|
367 | // NOTE: coeff will be created but remains undefined(zero?) |
---|
368 | poly p_Lcm(const poly a, const poly b, const long lCompM, const ring r); |
---|
369 | |
---|
370 | // returns the LCM of the head terms of a and b with component = max comp. of a & b |
---|
371 | // NOTE: coeff will be created but remains undefined(zero?) |
---|
372 | poly p_Lcm(const poly a, const poly b, const ring r); |
---|
373 | |
---|
374 | |
---|
375 | |
---|
376 | |
---|
377 | |
---|
378 | // const int GRMASK = 1 << 1; |
---|
379 | const int SCAMASK = 1; // For backward compatibility |
---|
380 | const int TESTSYZSCAMASK = 0x0100 | SCAMASK; // |
---|
381 | |
---|
382 | // NCExtensions Mask Property |
---|
383 | int& getNCExtensions(); |
---|
384 | int setNCExtensions(int iMask); |
---|
385 | |
---|
386 | // Test |
---|
387 | bool ncExtensions(int iMask); // = 0x0FFFF |
---|
388 | |
---|
389 | |
---|
390 | |
---|
391 | #ifdef PLURAL_INTERNAL_DECLARATIONS |
---|
392 | |
---|
393 | #include <polys/matpol.h> |
---|
394 | |
---|
395 | // read only access to NC matrices C/D: |
---|
396 | // get C_{i,j}, 1 <= row = i < j = col <= N |
---|
397 | static inline poly GetC( const ring r, int i, int j ) |
---|
398 | { |
---|
399 | assume(r!= NULL && rIsPluralRing(r)); |
---|
400 | const matrix C = GetNC(r)->C; |
---|
401 | assume(C != NULL); |
---|
402 | const int ncols = C->ncols; |
---|
403 | assume( (i > 0) && (i < j) && (j <= ncols) ); |
---|
404 | return ( C->m[ncols * ((i)-1) + (j)-1] ); |
---|
405 | } |
---|
406 | |
---|
407 | // get D_{i,j}, 1 <= row = i < j = col <= N |
---|
408 | static inline poly GetD( const ring r, int i, int j ) |
---|
409 | { |
---|
410 | assume(r!= NULL && rIsPluralRing(r)); |
---|
411 | const matrix D = GetNC(r)->D; |
---|
412 | assume(D != NULL); |
---|
413 | const int ncols = D->ncols; |
---|
414 | assume( (i > 0) && (i < j) && (j <= ncols) ); |
---|
415 | return ( D->m[ncols * ((i)-1) + (j)-1] ); |
---|
416 | } |
---|
417 | |
---|
418 | #endif /* PLURAL_INTERNAL_DECLARATIONS */ |
---|
419 | |
---|
420 | #endif /* HAVE_PLURAL */ |
---|
421 | |
---|
422 | #endif /* POLYS_NC_H */ |
---|