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 
56   SPoly_Proc_Ptr                        SPoly;
57   SPolyReduce_Proc_Ptr                  ReduceSPoly;
58 
59   void*                                 GB; ///< From "gb_hack.h"
60 //                                         GlobalGB, // BBA
61 //                                         LocalGB;  // MORA
62 };
63 
64 class CGlobalMultiplier;
65 class CFormulaPowerMultiplier;
66 
67 struct nc_struct
68 {
69   nc_type type;
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!!!!
75   matrix C;
76   matrix D;
77 
78   // computed data:
79   matrix *MT; // size 0.. (rVar()*rVar()-1)/2
80   matrix COM;
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
85   int IsSkewConstant;
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 
ncRingTypenc_struct108     inline nc_type& ncRingType() { return (type); };
ncRingTypenc_struct109     inline nc_type ncRingType() const { return (type); };
110 
FirstAltVarnc_struct111     inline short& FirstAltVar()
112         { assume(ncRingType() == nc_exterior); return (data.sca.iFirstAltVar); };
LastAltVarnc_struct113     inline short& LastAltVar ()
114         { assume(ncRingType() == nc_exterior); return (data.sca.iLastAltVar ); };
115 
FirstAltVarnc_struct116     inline short FirstAltVar() const
117         { assume(ncRingType() == nc_exterior); return (data.sca.iFirstAltVar); };
LastAltVarnc_struct118     inline short LastAltVar () const
119         { assume(ncRingType() == nc_exterior); return (data.sca.iLastAltVar ); };
120 
SCAQuotientnc_struct121     inline ideal& SCAQuotient()
122         { assume(ncRingType() == nc_exterior); return (data.sca.idSCAQuotient); };
123   private:
124 
125     CGlobalMultiplier* m_Multiplier;
126     CFormulaPowerMultiplier* m_PowerMultiplier;
127 
128   public:
129 
GetGlobalMultipliernc_struct130     inline CGlobalMultiplier* GetGlobalMultiplier() const
131         { return (m_Multiplier); };
132 
GetGlobalMultipliernc_struct133     inline CGlobalMultiplier*& GetGlobalMultiplier()
134         { return (m_Multiplier); };
135 
136 
GetFormulaPowerMultipliernc_struct137     inline CFormulaPowerMultiplier* GetFormulaPowerMultiplier() const
138         { return (m_PowerMultiplier); };
139 
GetFormulaPowerMultipliernc_struct140     inline CFormulaPowerMultiplier*& GetFormulaPowerMultiplier()
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 
GetNC(ring r)154 static inline nc_struct*& GetNC(ring r)
155 {
156   return r->GetNC();
157 }
158 
ncRingType(nc_struct * p)159 static inline nc_type& ncRingType(nc_struct* p)
160 {
161   assume(p!=NULL);
162   return (p->ncRingType());
163 }
164 
ncRingType(ring r)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 
ncRingType(ring r,nc_type t)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 
ncRingType(nc_struct * p,nc_type t)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!?
rIsSCA(const ring r)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
nc_mm_Mult_pp(const poly m,const poly p,const ring r)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
nc_mm_Mult_p(const poly m,poly p,const ring r)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 
nc_CreateSpoly(const poly p1,const poly p2,const ring r)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 
nc_ReduceSpoly(const poly p1,poly p2,const ring r)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 
nc_kBucketPolyRed_NF(kBucket_pt b,poly p,number * c)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 
nc_kBucketPolyRed_Z(kBucket_pt b,poly p,number * c)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
GetC(const ring r,int i,int j)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
GetD(const ring r,int i,int j)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 */
392