source: git/libpolys/polys/nc/nc.h @ 85bcd6

spielwiese
Last change on this file since 85bcd6 was 232bbd5, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
switchable NC-extensions add/chg: two more non-commutative (special multiplication) extensions and general Plural caching can be switched on&off now
  • Property mode set to 100644
File size: 11.7 KB
Line 
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
13class ip_smatrix;
14typedef ip_smatrix *       matrix;
15
16
17matrix nc_PrintMat(int a, int b, ring r, int metric);
18
19
20enum 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
39BOOLEAN 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
47void nc_rKill(ring r);
48
49
50BOOLEAN nc_CheckSubalgebra(poly PolyVar, ring r);
51
52// NC pProcs:
53typedef poly (*mm_Mult_p_Proc_Ptr)(const poly m, poly p, const ring r);
54typedef poly (*mm_Mult_pp_Proc_Ptr)(const poly m, const poly p, const ring r);
55
56
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  void*                                 GB; ///< From "gb_hack.h"
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, const ring r);
270
271static 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
281void nc_PolyPolyRed(poly &b, poly p, number *c, const ring r);
282
283/*
284static 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
292static 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
303static 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: */
316poly 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
320BOOLEAN 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.
331bool nc_SetupQuotient(ring rGR, const ring rG = NULL, bool bCopy = false); // rG == NULL means that there is no base G-algebra
332
333BOOLEAN nc_rComplete(const ring src, ring dest, bool bSetupQuotient = true); // in ring.cc
334
335bool nc_rCopy(ring res, const ring r, bool bSetupQuotient);
336
337poly pOppose(ring Rop_src, poly p, const ring Rop_dst);
338ideal 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?)
344poly 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?)
348poly p_Lcm(const poly a, const poly b, const ring r);
349
350
351
352
353
354const int GENERICMASK = 0x000; // gnc... must do its dirty job first!
355const int SCAMASK     = 0x001; 
356
357#if 0
358static const bool bNoPluralMultiplication = false;  // use only formula shortcuts in my OOP Multiplier
359// the following make sense only if bNoPluralMultiplication is false:
360static const bool bNoFormula = true;  // don't use any formula shortcuts
361static const bool bNoCache   = false; // only formula whenever possible, only make sanse if bNoFormula is false!
362#endif
363
364// false, true, false == old "good" Plural
365// false, false ==>> Plural + Cache + Direct Formula - not much
366// false, false, true ==>> Plural Mult + Direct Formula (no ~cache)
367// true, *, *  == new OOP multiplication!
368
369const int NOPLURALMASK= 0x002; // bNoPluralMultiplication
370const int NOFORMULAMASK=0x004; // bNoFormula
371const int NOCACHEMASK = 0x008; // bNoCache
372
373const int TESTSYZSCAMASK = 0x0100 | SCAMASK;
374
375
376
377// NCExtensions Mask Property
378int& getNCExtensions();
379int  setNCExtensions(int iMask);
380
381// Test
382bool ncExtensions(int iMask); //  = 0x0FFFF
383
384
385
386#ifdef PLURAL_INTERNAL_DECLARATIONS
387
388// set pProcs table for rGR and global variable p_Procs
389// this should be used by p_ProcsSet in p_Procs_Set.h
390void nc_p_ProcsSet(ring rGR, p_Procs_s* p_Procs);
391
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
397static 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
408static 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 */
Note: See TracBrowser for help on using the repository browser.