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