source: git/libpolys/polys/nc/nc.h @ 7a5d05

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