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