source: git/libpolys/polys/nc/nc.h @ 3ec6bba

spielwiese
Last change on this file since 3ec6bba was c6c3f1, checked in by Oleksandr Motsak <motsak@…>, 13 years ago
ADD: export nc_CheckSubalgebra
  • Property mode set to 100644
File size: 11.1 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
23
24enum nc_type
25{
26  nc_error = -1, // Something's gone wrong!
27  nc_general = 0, /* yx=q xy+... */
28  nc_skew, /*1*/ /* yx=q xy */
29  nc_comm, /*2*/ /* yx= xy */
30  nc_lie,  /*3*/ /* yx=xy+... */
31  nc_undef, /*4*/  /* for internal reasons */
32
33  nc_exterior /*5*/ // Exterior Algebra(SCA): yx= -xy & (!:) x^2 = 0
34};
35
36
37// //////////////////////////////////////////////////////
38
39// Macros used to access upper triangle matrices C,D... (which are actually ideals) // afaik
40#define UPMATELEM(i,j,nVar) ( (nVar * ((i)-1) - ((i) * ((i)-1))/2 + (j)-1)-(i) )
41
42/// complete destructor
43void nc_rKill(ring r);
44
45
46BOOLEAN nc_CheckSubalgebra(poly PolyVar, ring r);
47
48// NC pProcs:
49typedef poly (*mm_Mult_p_Proc_Ptr)(const poly m, poly p, const ring r);
50typedef poly (*mm_Mult_pp_Proc_Ptr)(const poly m, const poly p, const ring r);
51
52
53
54typedef ideal (*GB_Proc_Ptr)(const ideal F, const ideal Q, const intvec *w, const intvec *hilb, kStrategy strat, const ring r);
55
56typedef poly (*SPoly_Proc_Ptr)(const poly p1, const poly p2, const ring r);
57typedef poly (*SPolyReduce_Proc_Ptr)(const poly p1, poly p2, const ring r);
58
59typedef void (*bucket_Proc_Ptr)(kBucket_pt b, poly p, number *c);
60
61struct nc_pProcs
62{
63public:
64  mm_Mult_p_Proc_Ptr                    mm_Mult_p;
65  mm_Mult_pp_Proc_Ptr                   mm_Mult_pp;
66
67  bucket_Proc_Ptr                       BucketPolyRed;
68  bucket_Proc_Ptr                       BucketPolyRed_Z;
69
70  SPoly_Proc_Ptr                        SPoly;
71  SPolyReduce_Proc_Ptr                  ReduceSPoly;
72
73  GB_Proc_Ptr                           GB;
74//                                         GlobalGB, // BBA
75//                                         LocalGB;  // MORA
76};
77
78class CGlobalMultiplier;
79class CFormulaPowerMultiplier;
80
81struct nc_struct
82{
83  nc_type type;
84  //ring basering; // the ring C,D,.. live in (commutative ring with this NC structure!)
85
86  // initial data: square matrices rVar() x rVar()
87  // logically: upper triangular!!!
88  // TODO: eliminate this waste of memory!!!!
89  matrix C; 
90  matrix D;
91
92  // computed data:
93  matrix *MT; // size 0.. (rVar()*rVar()-1)/2
94  matrix COM;
95  int *MTsize; // size 0.. (rVar()*rVar()-1)/2
96
97  // IsSkewConstant indicates whethere coeffs C_ij are all equal,
98  // effective together with nc_type=nc_skew
99  int IsSkewConstant;
100
101  private:
102    // internal data for different implementations
103    // if dynamic => must be deallocated in destructor (nc_rKill!)
104    union
105    {
106      struct
107      {
108        // treat variables from iAltVarsStart till iAltVarsEnd as alternating vars.
109        // these variables should have odd degree, though that will not be checked
110        // iAltVarsStart, iAltVarsEnd are only used together with nc_type=nc_exterior
111        // 1 <= iAltVarsStart <= iAltVarsEnd <= r->N
112        unsigned int iFirstAltVar, iLastAltVar; // = 0 by default
113
114        // for factors of super-commutative algebras we need
115        // the part of general quotient ideal modulo squares!   
116        ideal idSCAQuotient; // = NULL by default. // must be deleted in Kill!
117      } sca;
118    } data;
119
120  public:
121   
122    inline nc_type& ncRingType() { return (type); };
123    inline nc_type ncRingType() const { return (type); };
124
125    inline unsigned int& FirstAltVar() 
126        { assume(ncRingType() == nc_exterior); return (data.sca.iFirstAltVar); };
127    inline unsigned int& LastAltVar () 
128        { assume(ncRingType() == nc_exterior); return (data.sca.iLastAltVar ); };
129
130    inline unsigned int FirstAltVar() const 
131        { assume(ncRingType() == nc_exterior); return (data.sca.iFirstAltVar); };
132    inline unsigned int LastAltVar () const 
133        { assume(ncRingType() == nc_exterior); return (data.sca.iLastAltVar ); };
134
135    inline ideal& SCAQuotient() 
136        { assume(ncRingType() == nc_exterior); return (data.sca.idSCAQuotient); };
137  private:
138
139    CGlobalMultiplier* m_Multiplier;
140    CFormulaPowerMultiplier* m_PowerMultiplier;
141
142  public:
143 
144    inline CGlobalMultiplier* GetGlobalMultiplier() const
145        { return (m_Multiplier); };
146
147    inline CGlobalMultiplier*& GetGlobalMultiplier()
148        { return (m_Multiplier); };
149
150
151    inline CFormulaPowerMultiplier* GetFormulaPowerMultiplier() const
152        { return (m_PowerMultiplier); };
153
154    inline CFormulaPowerMultiplier*& GetFormulaPowerMultiplier()
155        { return (m_PowerMultiplier); };
156   
157  public:
158    nc_pProcs p_Procs; // NC procedures.
159
160};
161
162
163
164
165// //////////////////////////////////////////////////////////////////////// //
166// NC inlines
167
168static inline nc_struct*& GetNC(ring r)
169{
170  return r->GetNC();
171}
172
173static inline nc_type& ncRingType(nc_struct* p)
174{
175  assume(p!=NULL);
176  return (p->ncRingType());
177}
178
179static inline nc_type ncRingType(ring r) // Get
180{
181  if(rIsPluralRing(r))
182    return (ncRingType(r->GetNC()));
183  else
184    return (nc_error);
185}
186
187static inline void ncRingType(ring r, nc_type t) // Set
188{
189  assume((r != NULL) && (r->GetNC() != NULL));
190  ncRingType(r->GetNC()) = t;
191}
192
193static inline void ncRingType(nc_struct* p, nc_type t) // Set
194{
195  assume(p!=NULL);
196  ncRingType(p) = t;
197}
198
199
200
201
202// //////////////////////////////////////////////////////////////////////// //
203// we must always have this test!?
204static inline bool rIsSCA(const ring r)
205{
206#ifdef HAVE_PLURAL
207  return rIsPluralRing(r) && (ncRingType(r) == nc_exterior);
208#else
209  return false;
210#endif
211}
212
213// //////////////////////////////////////////////////////////////////////// //
214// NC inlines
215
216
217/// general NC-multiplication with destruction
218poly _nc_p_Mult_q(poly p, poly q, const ring r);
219
220/// general NC-multiplication without destruction
221poly _nc_pp_Mult_qq(const poly p, const poly q, const ring r);
222
223
224
225/// for p_Minus_mm_Mult_qq in pInline2.h
226poly nc_p_Minus_mm_Mult_qq(poly p, const poly m, const poly q, int &lp,
227                                    const int, const poly, const ring r);
228
229// // for p_Plus_mm_Mult_qq in pInline2.h
230// returns p + m*q destroys p, const: q, m
231poly nc_p_Plus_mm_Mult_qq(poly p, const poly m, const poly q, int &lp,
232                              const int, const ring r);
233
234
235
236
237// returns m*p, does neither destroy p nor m
238static inline poly nc_mm_Mult_pp(const poly m, const poly p, const ring r)
239{
240  assume(rIsPluralRing(r));
241  assume(r->GetNC()->p_Procs.mm_Mult_pp!=NULL);
242  return r->GetNC()->p_Procs.mm_Mult_pp(m, p, r);
243//  return pp_Mult_mm( p, m, r);
244}
245
246
247// returns m*p, does destroy p, preserves m
248static inline poly nc_mm_Mult_p(const poly m, poly p, const ring r)
249{
250  assume(rIsPluralRing(r));
251  assume(r->GetNC()->p_Procs.mm_Mult_p!=NULL);
252  return r->GetNC()->p_Procs.mm_Mult_p(m, p, r);
253//   return p_Mult_mm( p, m, r);
254}
255
256static inline poly nc_CreateSpoly(const poly p1, const poly p2, const ring r)
257{
258  assume(rIsPluralRing(r));
259  assume(r->GetNC()->p_Procs.SPoly!=NULL);
260  return r->GetNC()->p_Procs.SPoly(p1, p2, r);
261}
262
263// ?
264poly nc_CreateShortSpoly(poly p1, poly p2, const ring r);
265
266/* brackets: p will be destroyed... */
267poly nc_p_Bracket_qq(poly p, const poly q);
268
269
270static inline poly nc_ReduceSpoly(const poly p1, poly p2, const ring r)
271{
272  assume(rIsPluralRing(r));
273  assume(r->GetNC()->p_Procs.ReduceSPoly!=NULL);
274#ifdef PDEBUG
275//  assume(p_LmDivisibleBy(p1, p2, r));
276#endif
277  return r->GetNC()->p_Procs.ReduceSPoly(p1, p2, r);
278}
279
280void nc_PolyPolyRed(poly &b, poly p, number *c, const ring r);
281
282/*
283static inline void nc_PolyReduce(poly &b, const poly p, number *c, const ring r) // nc_PolyPolyRed
284{
285  assume(rIsPluralRing(r));
286//  assume(r->GetNC()->p_Procs.PolyReduce!=NULL);
287//  r->GetNC()->p_Procs.PolyReduce(b, p, c, r);
288}
289*/
290
291static inline void nc_kBucketPolyRed(kBucket_pt b, poly p, number *c)
292{
293  const ring r = b->bucket_ring;
294  assume(rIsPluralRing(r));
295
296//   return gnc_kBucketPolyRedNew(b, p, c);
297
298  assume(r->GetNC()->p_Procs.BucketPolyRed!=NULL);
299  return r->GetNC()->p_Procs.BucketPolyRed(b, p, c);
300}
301
302static inline void nc_BucketPolyRed_Z(kBucket_pt b, poly p, number *c)
303{
304  const ring r = b->bucket_ring;
305  assume(rIsPluralRing(r));
306
307//   return gnc_kBucketPolyRed_ZNew(b, p, c);
308
309  assume(r->GetNC()->p_Procs.BucketPolyRed_Z!=NULL);
310  return r->GetNC()->p_Procs.BucketPolyRed_Z(b, p, c);
311
312}
313
314static inline ideal nc_GB(const ideal F, const ideal Q, const intvec *w, const intvec *hilb, kStrategy strat, const ring r)
315{
316  assume(rIsPluralRing(r));
317
318  assume(r->GetNC()->p_Procs.GB!=NULL);
319  return r->GetNC()->p_Procs.GB(F, Q, w, hilb, strat, r);
320}
321
322
323
324/* subst: */
325poly nc_pSubst(poly p, int n, poly e, const ring r);
326
327// set pProcs table for rGR and global variable p_Procs
328// this should be used by p_ProcsSet in p_Procs_Set.h
329void nc_p_ProcsSet(ring rGR, p_Procs_s* p_Procs);
330
331
332// the part, related to the interface
333// Changes r, Assumes that all other input belongs to curr
334BOOLEAN nc_CallPlural(matrix cc, matrix dd, poly cn, poly dn, ring r,
335                      bool bSetupQuotient, //< false
336                      bool bCopyInput, //< true
337                      bool bBeQuiet, //< false
338                      ring curr,
339                      bool dummy_ring = false 
340                      /* allow to create a nc-ring with 1 variable*/);
341
342
343BOOLEAN nc_rComplete(const ring src, ring dest, bool bSetupQuotient = true); // in ring.cc
344
345// this function should be used inside QRing definition!
346// we go from rG into factor ring rGR with factor ideal rGR->qideal.
347bool nc_SetupQuotient(ring rGR, const ring rG = NULL, bool bCopy = false); // rG == NULL means that there is no base G-algebra
348
349
350bool nc_rCopy(ring res, const ring r, bool bSetupQuotient);
351
352poly pOppose(ring Rop_src, poly p, const ring Rop_dst);
353ideal idOppose(ring Rop_src, ideal I, const ring Rop_dst);
354
355
356
357// returns the LCM of the head terms of a and b with the given component
358// NOTE: coeff will be created but remains undefined(zero?)
359poly p_Lcm(const poly a, const poly b, const long lCompM, const ring r);
360
361// returns the LCM of the head terms of a and b with component = max comp. of a & b
362// NOTE: coeff will be created but remains undefined(zero?)
363poly p_Lcm(const poly a, const poly b, const ring r);
364
365
366
367
368
369// const int GRMASK = 1 << 1;
370const int SCAMASK = 1; // For backward compatibility
371const int TESTSYZSCAMASK = 0x0100 | SCAMASK; //
372
373// NCExtensions Mask Property
374int& getNCExtensions();
375int  setNCExtensions(int iMask);
376
377// Test
378bool ncExtensions(int iMask); //  = 0x0FFFF
379
380
381
382#ifdef PLURAL_INTERNAL_DECLARATIONS
383
384#include <polys/matpol.h>
385
386// read only access to NC matrices C/D:
387// get C_{i,j}, 1 <= row = i < j = col <= N
388static inline poly GetC( const ring r, int i, int j ) 
389{
390  assume(r!= NULL && rIsPluralRing(r));
391  const matrix C = GetNC(r)->C;
392  assume(C != NULL);
393  const int ncols = C->ncols;
394  assume( (i > 0) && (i < j) && (j <= ncols) );
395  return ( C->m[ncols * ((i)-1) + (j)-1] );
396}
397
398// get D_{i,j}, 1 <= row = i < j = col <= N
399static inline poly GetD( const ring r, int i, int j ) 
400{
401  assume(r!= NULL && rIsPluralRing(r));
402  const matrix D = GetNC(r)->D;
403  assume(D != NULL);
404  const int ncols = D->ncols;
405  assume( (i > 0) && (i < j) && (j <= ncols) );
406  return ( D->m[ncols * ((i)-1) + (j)-1] );
407}
408
409#endif /* PLURAL_INTERNAL_DECLARATIONS */
410
411#endif /* HAVE_PLURAL */
412
413#endif /* POLYS_NC_H */
Note: See TracBrowser for help on using the repository browser.