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 
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:
68 
71 
74 
75  void* GB; ///< From "gb_hack.h"
76 // GlobalGB, // BBA
77 // LocalGB; // MORA
78 };
79 
80 class CGlobalMultiplier;
82 
83 struct nc_struct
84 {
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!!!!
93 
94  // computed data:
95  matrix *MT; // size 0.. (rVar()*rVar()-1)/2
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
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  short 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 short& FirstAltVar()
128  { assume(ncRingType() == nc_exterior); return (data.sca.iFirstAltVar); };
129  inline short& LastAltVar ()
130  { assume(ncRingType() == nc_exterior); return (data.sca.iLastAltVar ); };
131 
132  inline short FirstAltVar() const
133  { assume(ncRingType() == nc_exterior); return (data.sca.iFirstAltVar); };
134  inline short 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 
143 
144  public:
145 
147  { return (m_Multiplier); };
148 
150  { return (m_Multiplier); };
151 
152 
154  { return (m_PowerMultiplier); };
155 
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 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 GENERICMASK = 0x000; // gnc... must do its dirty job first!
355 const int SCAMASK = 0x001;
356 
357 #if 0
358 static const bool bNoPluralMultiplication = false; // use only formula shortcuts in my OOP Multiplier
359 // the following make sense only if bNoPluralMultiplication is false:
360 static const bool bNoFormula = true; // don't use any formula shortcuts
361 static 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 
369 const int NOPLURALMASK= 0x002; // bNoPluralMultiplication
370 const int NOFORMULAMASK=0x004; // bNoFormula
371 const int NOCACHEMASK = 0x008; // bNoCache
372 
373 const int TESTSYZSCAMASK = 0x0100 | SCAMASK;
374 
375 
376 
377 // NCExtensions Mask Property
378 int& getNCExtensions();
379 int setNCExtensions(int iMask);
380 
381 // Test
382 bool 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
390 void 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
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 */
poly pOppose(ring Rop_src, poly p, const ring Rop_dst)
opposes a vector p from Rop to currRing (dst!)
Definition: old.gring.cc:3426
CGlobalMultiplier * m_Multiplier
Definition: nc.h:138
mm_Mult_p_Proc_Ptr mm_Mult_p
Definition: nc.h:66
poly nc_p_Bracket_qq(poly p, const poly q, const ring r)
returns [p,q], destroys p
Definition: old.gring.cc:2307
#define D(A)
Definition: gentable.cc:123
mm_Mult_pp_Proc_Ptr mm_Mult_pp
Definition: nc.h:67
poly _nc_pp_Mult_qq(const poly p, const poly q, const ring r)
general NC-multiplication without destruction
Definition: old.gring.cc:312
static void nc_kBucketPolyRed(kBucket_pt b, poly p, number *c)
Definition: nc.h:292
const poly a
Definition: syzextra.cc:212
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:3399
void nc_PolyPolyRed(poly &b, poly p, number *c, const ring r)
Definition: old.gring.cc:2294
nc_type type
Definition: nc.h:85
int ncols
Definition: matpol.h:22
poly p_Lcm(const poly a, const poly b, const long lCompM, const ring r)
Definition: old.gring.cc:159
nc_type ncRingType() const
Definition: nc.h:125
return P p
Definition: myNF.cc:203
struct p_Procs_s p_Procs_s
Definition: ring.h:29
static nc_struct *& GetNC(ring r)
Definition: nc.h:170
int & getNCExtensions()
Definition: old.gring.cc:87
void(* bucket_Proc_Ptr)(kBucket_pt b, poly p, number *c)
Definition: nc.h:61
bucket_Proc_Ptr BucketPolyRed
Definition: nc.h:69
bool nc_SetupQuotient(ring rGR, const ring rG=NULL, bool bCopy=false)
Definition: old.gring.cc:3487
short & FirstAltVar()
Definition: nc.h:127
int setNCExtensions(int iMask)
Definition: old.gring.cc:92
matrix COM
Definition: nc.h:96
void nc_rKill(ring r)
complete destructor
Definition: old.gring.cc:2539
CFormulaPowerMultiplier *& GetFormulaPowerMultiplier()
Definition: nc.h:156
SPolyReduce_Proc_Ptr ReduceSPoly
Definition: nc.h:73
short & LastAltVar()
Definition: nc.h:129
void nc_p_ProcsSet(ring rGR, p_Procs_s *p_Procs)
Definition: old.gring.cc:3263
poly nc_CreateShortSpoly(poly p1, poly p2, const ring r)
Definition: old.gring.cc:1938
int * MTsize
Definition: nc.h:97
Definition: nc.h:83
nc_type
Definition: nc.h:20
short FirstAltVar() const
Definition: nc.h:132
Definition: nc.h:25
ideal idOppose(ring Rop_src, ideal I, const ring Rop_dst)
opposes a module I from Rop to currRing(dst)
Definition: old.gring.cc:3465
Definition: nc.h:22
ideal & SCAQuotient()
Definition: nc.h:137
bucket_Proc_Ptr BucketPolyRed_Z
Definition: nc.h:70
short LastAltVar() const
Definition: nc.h:134
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:226
poly res
Definition: myNF.cc:322
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:208
static poly nc_mm_Mult_p(const poly m, poly p, const ring r)
Definition: nc.h:250
poly * m
Definition: matpol.h:19
const ring r
Definition: syzextra.cc:208
nc_pProcs p_Procs
Definition: nc.h:157
Definition: nc.h:63
matrix nc_PrintMat(int a, int b, ring r, int metric)
returns matrix with the info on noncomm multiplication
Definition: old.gring.cc:2458
int j
Definition: myNF.cc:70
ring bucket_ring
Definition: kbuckets.h:191
#define assume(x)
Definition: mod2.h:394
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition: ring.h:404
poly _nc_p_Mult_q(poly p, poly q, const ring r)
general NC-multiplication with destruction
Definition: old.gring.cc:273
Definition: nc.h:27
bool ncExtensions(int iMask)
Definition: old.gring.cc:99
poly(* SPolyReduce_Proc_Ptr)(const poly p1, poly p2, const ring r)
Definition: nc.h:59
CGlobalMultiplier * GetGlobalMultiplier() const
Definition: nc.h:146
nc_type & ncRingType()
Definition: nc.h:124
static poly nc_ReduceSpoly(const poly p1, poly p2, const ring r)
Definition: nc.h:271
BOOLEAN nc_rComplete(const ring src, ring dest, bool bSetupQuotient=true)
Definition: ring.cc:5492
int m
Definition: cfEzgcd.cc:119
poly(* mm_Mult_p_Proc_Ptr)(const poly m, poly p, const ring r)
Definition: nc.h:53
int i
Definition: cfEzgcd.cc:123
const int GENERICMASK
Definition: nc.h:354
Definition: nc.h:24
matrix * MT
Definition: nc.h:95
const int NOCACHEMASK
Definition: nc.h:371
poly(* SPoly_Proc_Ptr)(const poly p1, const poly p2, const ring r)
Definition: nc.h:58
ip_smatrix * matrix
Definition: nc.h:13
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:2746
bool nc_rCopy(ring res, const ring r, bool bSetupQuotient)
Definition: old.gring.cc:3087
Definition: nc.h:29
const int TESTSYZSCAMASK
Definition: nc.h:373
#define NULL
Definition: omList.c:10
Definition: nc.h:23
matrix D
Definition: nc.h:92
int int ncols
Definition: cf_linsys.cc:32
SPoly_Proc_Ptr SPoly
Definition: nc.h:72
const int SCAMASK
Definition: nc.h:355
static bool rIsSCA(const ring r)
Definition: nc.h:206
void * GB
From "gb_hack.h".
Definition: nc.h:75
const int NOPLURALMASK
Definition: nc.h:369
CFormulaPowerMultiplier * GetFormulaPowerMultiplier() const
Definition: nc.h:153
static nc_type & ncRingType(nc_struct *p)
Definition: nc.h:175
matrix C
Definition: nc.h:91
static poly GetC(const ring r, int i, int j)
Definition: nc.h:397
static poly nc_mm_Mult_pp(const poly m, const poly p, const ring r)
Definition: nc.h:240
static poly nc_CreateSpoly(const poly p1, const poly p2, const ring r)
Definition: nc.h:258
END_NAMESPACE const void * p2
Definition: syzextra.cc:202
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:3287
CFormulaPowerMultiplier * m_PowerMultiplier
Definition: nc.h:142
int IsSkewConstant
Definition: nc.h:101
polyrec * poly
Definition: hilb.h:10
BOOLEAN nc_CheckSubalgebra(poly PolyVar, ring r)
Definition: old.gring.cc:2632
const int NOFORMULAMASK
Definition: nc.h:370
poly(* mm_Mult_pp_Proc_Ptr)(const poly m, const poly p, const ring r)
Definition: nc.h:54
int BOOLEAN
Definition: auxiliary.h:85
const poly b
Definition: syzextra.cc:213
CGlobalMultiplier *& GetGlobalMultiplier()
Definition: nc.h:149
static void nc_BucketPolyRed_Z(kBucket_pt b, poly p, number *c)
Definition: nc.h:303
Definition: nc.h:26
static poly GetD(const ring r, int i, int j)
Definition: nc.h:408