source: git/libpolys/polys/nc/nc.h @ e63576

spielwiese
Last change on this file since e63576 was e63576, checked in by Oleksandr Motsak <motsak@…>, 13 years ago
FIX: started moving GB-related non-commutative routines to kernel/
  • Property mode set to 100644
File size: 11.2 KB
Line 
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
16class ip_smatrix;
17typedef ip_smatrix *       matrix;
18
19class skStrategy;
20typedef skStrategy * kStrategy;
21
22
23matrix nc_PrintMat(int a, int b, ring r, int metric);
24
25
26enum 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// Macros used to access upper triangle matrices C,D... (which are actually ideals) // afaik
42#define UPMATELEM(i,j,nVar) ( (nVar * ((i)-1) - ((i) * ((i)-1))/2 + (j)-1)-(i) )
43
44/// complete destructor
45void nc_rKill(ring r);
46
47
48BOOLEAN nc_CheckSubalgebra(poly PolyVar, ring r);
49
50// NC pProcs:
51typedef poly (*mm_Mult_p_Proc_Ptr)(const poly m, poly p, const ring r);
52typedef poly (*mm_Mult_pp_Proc_Ptr)(const poly m, const poly p, const ring r);
53
54
55
56typedef ideal (*GB_Proc_Ptr)(const ideal F, const ideal Q, const intvec *w, const intvec *hilb, kStrategy strat, const ring r);
57
58typedef poly (*SPoly_Proc_Ptr)(const poly p1, const poly p2, const ring r);
59typedef poly (*SPolyReduce_Proc_Ptr)(const poly p1, poly p2, const ring r);
60
61typedef void (*bucket_Proc_Ptr)(kBucket_pt b, poly p, number *c);
62
63struct nc_pProcs
64{
65public:
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  GB_Proc_Ptr                           GB;
76//                                         GlobalGB, // BBA
77//                                         LocalGB;  // MORA
78};
79
80class CGlobalMultiplier;
81class CFormulaPowerMultiplier;
82
83struct 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
170static inline nc_struct*& GetNC(ring r)
171{
172  return r->GetNC();
173}
174
175static inline nc_type& ncRingType(nc_struct* p)
176{
177  assume(p!=NULL);
178  return (p->ncRingType());
179}
180
181static 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
189static inline void ncRingType(ring r, nc_type t) // Set
190{
191  assume((r != NULL) && (r->GetNC() != NULL));
192  ncRingType(r->GetNC()) = t;
193}
194
195static 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!?
206static 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
220poly _nc_p_Mult_q(poly p, poly q, const ring r);
221
222/// general NC-multiplication without destruction
223poly _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
228poly 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
233poly 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
240static 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
250static 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
258static 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// ?
266poly nc_CreateShortSpoly(poly p1, poly p2, const ring r);
267
268/* brackets: p will be destroyed... */
269poly nc_p_Bracket_qq(poly p, const poly q);
270
271
272static inline poly nc_ReduceSpoly(const poly p1, poly p2, const ring r)
273{
274  assume(rIsPluralRing(r));
275  assume(r->GetNC()->p_Procs.ReduceSPoly!=NULL);
276#ifdef PDEBUG
277//  assume(p_LmDivisibleBy(p1, p2, r));
278#endif
279  return r->GetNC()->p_Procs.ReduceSPoly(p1, p2, r);
280}
281
282void nc_PolyPolyRed(poly &b, poly p, number *c, const ring r);
283
284/*
285static inline void nc_PolyReduce(poly &b, const poly p, number *c, const ring r) // nc_PolyPolyRed
286{
287  assume(rIsPluralRing(r));
288//  assume(r->GetNC()->p_Procs.PolyReduce!=NULL);
289//  r->GetNC()->p_Procs.PolyReduce(b, p, c, r);
290}
291*/
292
293static inline void nc_kBucketPolyRed(kBucket_pt b, poly p, number *c)
294{
295  const ring r = b->bucket_ring;
296  assume(rIsPluralRing(r));
297
298//   return gnc_kBucketPolyRedNew(b, p, c);
299
300  assume(r->GetNC()->p_Procs.BucketPolyRed!=NULL);
301  return r->GetNC()->p_Procs.BucketPolyRed(b, p, c);
302}
303
304static inline void nc_BucketPolyRed_Z(kBucket_pt b, poly p, number *c)
305{
306  const ring r = b->bucket_ring;
307  assume(rIsPluralRing(r));
308
309//   return gnc_kBucketPolyRed_ZNew(b, p, c);
310
311  assume(r->GetNC()->p_Procs.BucketPolyRed_Z!=NULL);
312  return r->GetNC()->p_Procs.BucketPolyRed_Z(b, p, c);
313
314}
315
316static inline ideal nc_GB(const ideal F, const ideal Q, const intvec *w, const intvec *hilb, kStrategy strat, const ring r)
317{
318  assume(rIsPluralRing(r));
319
320  assume(r->GetNC()->p_Procs.GB!=NULL);
321  return r->GetNC()->p_Procs.GB(F, Q, w, hilb, strat, r);
322}
323
324
325
326/* subst: */
327poly nc_pSubst(poly p, int n, poly e, const ring r);
328
329// set pProcs table for rGR and global variable p_Procs
330// this should be used by p_ProcsSet in p_Procs_Set.h
331void nc_p_ProcsSet(ring rGR, p_Procs_s* p_Procs);
332
333
334// the part, related to the interface
335// Changes r, Assumes that all other input belongs to curr
336BOOLEAN nc_CallPlural(matrix cc, matrix dd, poly cn, poly dn, ring r,
337                      bool bSetupQuotient, //< false
338                      bool bCopyInput, //< true
339                      bool bBeQuiet, //< false
340                      ring curr,
341                      bool dummy_ring = false 
342                      /* allow to create a nc-ring with 1 variable*/);
343
344
345BOOLEAN nc_rComplete(const ring src, ring dest, bool bSetupQuotient = true); // in ring.cc
346
347// this function should be used inside QRing definition!
348// we go from rG into factor ring rGR with factor ideal rGR->qideal.
349bool nc_SetupQuotient(ring rGR, const ring rG = NULL, bool bCopy = false); // rG == NULL means that there is no base G-algebra
350
351
352bool nc_rCopy(ring res, const ring r, bool bSetupQuotient);
353
354poly pOppose(ring Rop_src, poly p, const ring Rop_dst);
355ideal idOppose(ring Rop_src, ideal I, const ring Rop_dst);
356
357
358
359// returns the LCM of the head terms of a and b with the given component
360// NOTE: coeff will be created but remains undefined(zero?)
361poly p_Lcm(const poly a, const poly b, const long lCompM, const ring r);
362
363// returns the LCM of the head terms of a and b with component = max comp. of a & b
364// NOTE: coeff will be created but remains undefined(zero?)
365poly p_Lcm(const poly a, const poly b, const ring r);
366
367
368
369
370
371// const int GRMASK = 1 << 1;
372const int SCAMASK = 1; // For backward compatibility
373const int TESTSYZSCAMASK = 0x0100 | SCAMASK; //
374
375// NCExtensions Mask Property
376int& getNCExtensions();
377int  setNCExtensions(int iMask);
378
379// Test
380bool ncExtensions(int iMask); //  = 0x0FFFF
381
382
383
384#ifdef PLURAL_INTERNAL_DECLARATIONS
385
386#include <polys/matpol.h>
387
388// read only access to NC matrices C/D:
389// get C_{i,j}, 1 <= row = i < j = col <= N
390static inline poly GetC( const ring r, int i, int j ) 
391{
392  assume(r!= NULL && rIsPluralRing(r));
393  const matrix C = GetNC(r)->C;
394  assume(C != NULL);
395  const int ncols = C->ncols;
396  assume( (i > 0) && (i < j) && (j <= ncols) );
397  return ( C->m[ncols * ((i)-1) + (j)-1] );
398}
399
400// get D_{i,j}, 1 <= row = i < j = col <= N
401static inline poly GetD( const ring r, int i, int j ) 
402{
403  assume(r!= NULL && rIsPluralRing(r));
404  const matrix D = GetNC(r)->D;
405  assume(D != NULL);
406  const int ncols = D->ncols;
407  assume( (i > 0) && (i < j) && (j <= ncols) );
408  return ( D->m[ncols * ((i)-1) + (j)-1] );
409}
410
411#endif /* PLURAL_INTERNAL_DECLARATIONS */
412
413#endif /* HAVE_PLURAL */
414
415#endif /* POLYS_NC_H */
Note: See TracBrowser for help on using the repository browser.