[cf3743] | 1 | #ifndef POLYS_NC_H |
---|
| 2 | #define POLYS_NC_H |
---|
| 3 | |
---|
[45d2332] | 4 | |
---|
[4f0f42] | 5 | #ifdef HAVE_PLURAL |
---|
| 6 | |
---|
| 7 | |
---|
[cf3743] | 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 | |
---|
[4f0f42] | 12 | #include <polys/monomials/ring.h> |
---|
| 13 | #include <polys/kbuckets.h> |
---|
| 14 | |
---|
[cf3743] | 15 | |
---|
[4f0f42] | 16 | class ip_smatrix; |
---|
| 17 | typedef ip_smatrix * matrix; |
---|
| 18 | |
---|
| 19 | class skStrategy; |
---|
| 20 | typedef skStrategy * kStrategy; |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | enum nc_type |
---|
[cf3743] | 25 | { |
---|
[4f0f42] | 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 | |
---|
[028192] | 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 |
---|
| 43 | void nc_rKill(ring r); |
---|
[45d2332] | 44 | |
---|
| 45 | |
---|
[c6c3f1] | 46 | BOOLEAN nc_CheckSubalgebra(poly PolyVar, ring r); |
---|
| 47 | |
---|
[4f0f42] | 48 | // NC pProcs: |
---|
| 49 | typedef poly (*mm_Mult_p_Proc_Ptr)(const poly m, poly p, const ring r); |
---|
| 50 | typedef poly (*mm_Mult_pp_Proc_Ptr)(const poly m, const poly p, const ring r); |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | typedef ideal (*GB_Proc_Ptr)(const ideal F, const ideal Q, const intvec *w, const intvec *hilb, kStrategy strat, const ring r); |
---|
| 55 | |
---|
| 56 | typedef poly (*SPoly_Proc_Ptr)(const poly p1, const poly p2, const ring r); |
---|
| 57 | typedef poly (*SPolyReduce_Proc_Ptr)(const poly p1, poly p2, const ring r); |
---|
| 58 | |
---|
| 59 | typedef void (*bucket_Proc_Ptr)(kBucket_pt b, poly p, number *c); |
---|
| 60 | |
---|
| 61 | struct nc_pProcs |
---|
| 62 | { |
---|
| 63 | public: |
---|
| 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 | |
---|
[32d07a5] | 78 | class CGlobalMultiplier; |
---|
| 79 | class CFormulaPowerMultiplier; |
---|
| 80 | |
---|
[4f0f42] | 81 | struct 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 | |
---|
[32d07a5] | 139 | CGlobalMultiplier* m_Multiplier; |
---|
[4f0f42] | 140 | CFormulaPowerMultiplier* m_PowerMultiplier; |
---|
| 141 | |
---|
| 142 | public: |
---|
| 143 | |
---|
| 144 | inline CGlobalMultiplier* GetGlobalMultiplier() const |
---|
[32d07a5] | 145 | { return (m_Multiplier); }; |
---|
[4f0f42] | 146 | |
---|
| 147 | inline CGlobalMultiplier*& GetGlobalMultiplier() |
---|
[32d07a5] | 148 | { return (m_Multiplier); }; |
---|
[4f0f42] | 149 | |
---|
| 150 | |
---|
| 151 | inline CFormulaPowerMultiplier* GetFormulaPowerMultiplier() const |
---|
[32d07a5] | 152 | { return (m_PowerMultiplier); }; |
---|
[4f0f42] | 153 | |
---|
| 154 | inline CFormulaPowerMultiplier*& GetFormulaPowerMultiplier() |
---|
[32d07a5] | 155 | { return (m_PowerMultiplier); }; |
---|
[4f0f42] | 156 | |
---|
| 157 | public: |
---|
| 158 | nc_pProcs p_Procs; // NC procedures. |
---|
| 159 | |
---|
| 160 | }; |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | |
---|
| 165 | // //////////////////////////////////////////////////////////////////////// // |
---|
| 166 | // NC inlines |
---|
| 167 | |
---|
[32d07a5] | 168 | static inline nc_struct*& GetNC(ring r) |
---|
[4f0f42] | 169 | { |
---|
| 170 | return r->GetNC(); |
---|
[32d07a5] | 171 | } |
---|
[4f0f42] | 172 | |
---|
[32d07a5] | 173 | static inline nc_type& ncRingType(nc_struct* p) |
---|
[4f0f42] | 174 | { |
---|
| 175 | assume(p!=NULL); |
---|
| 176 | return (p->ncRingType()); |
---|
[32d07a5] | 177 | } |
---|
[4f0f42] | 178 | |
---|
[32d07a5] | 179 | static inline nc_type ncRingType(ring r) // Get |
---|
[4f0f42] | 180 | { |
---|
| 181 | if(rIsPluralRing(r)) |
---|
| 182 | return (ncRingType(r->GetNC())); |
---|
| 183 | else |
---|
| 184 | return (nc_error); |
---|
[32d07a5] | 185 | } |
---|
[4f0f42] | 186 | |
---|
[32d07a5] | 187 | static inline void ncRingType(ring r, nc_type t) // Set |
---|
[4f0f42] | 188 | { |
---|
| 189 | assume((r != NULL) && (r->GetNC() != NULL)); |
---|
| 190 | ncRingType(r->GetNC()) = t; |
---|
[32d07a5] | 191 | } |
---|
| 192 | |
---|
| 193 | static inline void ncRingType(nc_struct* p, nc_type t) // Set |
---|
| 194 | { |
---|
| 195 | assume(p!=NULL); |
---|
| 196 | ncRingType(p) = t; |
---|
| 197 | } |
---|
| 198 | |
---|
[4f0f42] | 199 | |
---|
| 200 | |
---|
[45d2332] | 201 | |
---|
| 202 | // //////////////////////////////////////////////////////////////////////// // |
---|
| 203 | // we must always have this test!? |
---|
[32d07a5] | 204 | static inline bool rIsSCA(const ring r) |
---|
[45d2332] | 205 | { |
---|
| 206 | #ifdef HAVE_PLURAL |
---|
| 207 | return rIsPluralRing(r) && (ncRingType(r) == nc_exterior); |
---|
| 208 | #else |
---|
| 209 | return false; |
---|
| 210 | #endif |
---|
| 211 | } |
---|
| 212 | |
---|
[4f0f42] | 213 | // //////////////////////////////////////////////////////////////////////// // |
---|
| 214 | // NC inlines |
---|
| 215 | |
---|
| 216 | |
---|
| 217 | /// general NC-multiplication with destruction |
---|
| 218 | poly _nc_p_Mult_q(poly p, poly q, const ring r); |
---|
| 219 | |
---|
| 220 | /// general NC-multiplication without destruction |
---|
| 221 | poly _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 |
---|
| 226 | poly 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 |
---|
| 231 | poly 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 |
---|
[32d07a5] | 238 | static inline poly nc_mm_Mult_pp(const poly m, const poly p, const ring r) |
---|
[4f0f42] | 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 |
---|
[32d07a5] | 248 | static inline poly nc_mm_Mult_p(const poly m, poly p, const ring r) |
---|
[4f0f42] | 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 | |
---|
[32d07a5] | 256 | static inline poly nc_CreateSpoly(const poly p1, const poly p2, const ring r) |
---|
[4f0f42] | 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 | |
---|
[eaae7d] | 263 | // ? |
---|
| 264 | poly nc_CreateShortSpoly(poly p1, poly p2, const ring r); |
---|
| 265 | |
---|
| 266 | /* brackets: p will be destroyed... */ |
---|
| 267 | poly nc_p_Bracket_qq(poly p, const poly q); |
---|
| 268 | |
---|
| 269 | |
---|
[32d07a5] | 270 | static inline poly nc_ReduceSpoly(const poly p1, poly p2, const ring r) |
---|
[4f0f42] | 271 | { |
---|
| 272 | assume(rIsPluralRing(r)); |
---|
| 273 | assume(r->GetNC()->p_Procs.ReduceSPoly!=NULL); |
---|
| 274 | #ifdef PDEBUG |
---|
| 275 | // assume(p_LmDivisibleBy(p1, p2, r)); |
---|
[cf3743] | 276 | #endif |
---|
[4f0f42] | 277 | return r->GetNC()->p_Procs.ReduceSPoly(p1, p2, r); |
---|
[cf3743] | 278 | } |
---|
| 279 | |
---|
[9d4b8c] | 280 | void nc_PolyPolyRed(poly &b, poly p, number *c, const ring r); |
---|
| 281 | |
---|
[4f0f42] | 282 | /* |
---|
[32d07a5] | 283 | static inline void nc_PolyReduce(poly &b, const poly p, number *c, const ring r) // nc_PolyPolyRed |
---|
[4f0f42] | 284 | { |
---|
| 285 | assume(rIsPluralRing(r)); |
---|
| 286 | // assume(r->GetNC()->p_Procs.PolyReduce!=NULL); |
---|
| 287 | // r->GetNC()->p_Procs.PolyReduce(b, p, c, r); |
---|
| 288 | } |
---|
[cf3743] | 289 | */ |
---|
[4f0f42] | 290 | |
---|
[32d07a5] | 291 | static inline void nc_kBucketPolyRed(kBucket_pt b, poly p, number *c) |
---|
[4f0f42] | 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 | |
---|
[32d07a5] | 302 | static inline void nc_BucketPolyRed_Z(kBucket_pt b, poly p, number *c) |
---|
[4f0f42] | 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 | |
---|
[32d07a5] | 314 | static inline ideal nc_GB(const ideal F, const ideal Q, const intvec *w, const intvec *hilb, kStrategy strat, const ring r) |
---|
[4f0f42] | 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 | |
---|
[45d2332] | 322 | |
---|
| 323 | |
---|
| 324 | /* subst: */ |
---|
| 325 | poly nc_pSubst(poly p, int n, poly e, const ring r); |
---|
| 326 | |
---|
[32d07a5] | 327 | // set pProcs table for rGR and global variable p_Procs |
---|
| 328 | // this should be used by p_ProcsSet in p_Procs_Set.h |
---|
| 329 | void nc_p_ProcsSet(ring rGR, p_Procs_s* p_Procs); |
---|
[45d2332] | 330 | |
---|
| 331 | |
---|
[028192] | 332 | // the part, related to the interface |
---|
| 333 | // Changes r, Assumes that all other input belongs to curr |
---|
| 334 | BOOLEAN 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 | |
---|
| 343 | BOOLEAN 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. |
---|
| 347 | bool nc_SetupQuotient(ring rGR, const ring rG = NULL, bool bCopy = false); // rG == NULL means that there is no base G-algebra |
---|
| 348 | |
---|
| 349 | |
---|
| 350 | bool nc_rCopy(ring res, const ring r, bool bSetupQuotient); |
---|
| 351 | |
---|
| 352 | poly pOppose(ring Rop_src, poly p, const ring Rop_dst); |
---|
| 353 | ideal idOppose(ring Rop_src, ideal I, const ring Rop_dst); |
---|
| 354 | |
---|
[32d07a5] | 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?) |
---|
| 359 | poly 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?) |
---|
| 363 | poly p_Lcm(const poly a, const poly b, const ring r); |
---|
| 364 | |
---|
| 365 | |
---|
[40d0649] | 366 | |
---|
| 367 | |
---|
| 368 | |
---|
| 369 | // const int GRMASK = 1 << 1; |
---|
| 370 | const int SCAMASK = 1; // For backward compatibility |
---|
| 371 | const int TESTSYZSCAMASK = 0x0100 | SCAMASK; // |
---|
| 372 | |
---|
| 373 | // NCExtensions Mask Property |
---|
| 374 | int& getNCExtensions(); |
---|
| 375 | int setNCExtensions(int iMask); |
---|
| 376 | |
---|
| 377 | // Test |
---|
| 378 | bool ncExtensions(int iMask); // = 0x0FFFF |
---|
| 379 | |
---|
| 380 | |
---|
| 381 | |
---|
[d6a97c3] | 382 | #ifdef PLURAL_INTERNAL_DECLARATIONS |
---|
[40d0649] | 383 | |
---|
[d6a97c3] | 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 |
---|
| 388 | static 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 |
---|
| 399 | static 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 */ |
---|
[40d0649] | 410 | |
---|
[4f0f42] | 411 | #endif /* HAVE_PLURAL */ |
---|
| 412 | |
---|
[cf3743] | 413 | #endif /* POLYS_NC_H */ |
---|