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