[d81b79] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
| 4 | /*************************************************************** |
---|
| 5 | * File: ncSAMult.cc |
---|
| 6 | * Purpose: implementation of multiplication in simple NC subalgebras |
---|
| 7 | * Author: motsak |
---|
[fea494] | 8 | * Created: |
---|
[d81b79] | 9 | *******************************************************************/ |
---|
| 10 | |
---|
[a7fbdd] | 11 | #define MYTEST 0 |
---|
[d81b79] | 12 | |
---|
| 13 | #if MYTEST |
---|
| 14 | #define OM_CHECK 4 |
---|
| 15 | #define OM_TRACK 5 |
---|
[a7fbdd] | 16 | // these settings must be before "mod2.h" in order to work!!! |
---|
[d81b79] | 17 | #endif |
---|
| 18 | |
---|
[03cecc2] | 19 | |
---|
[9f7665] | 20 | |
---|
| 21 | |
---|
| 22 | |
---|
[aadd638] | 23 | #include "misc/auxiliary.h" |
---|
[03cecc2] | 24 | |
---|
[6e05dc] | 25 | #ifdef HAVE_PLURAL |
---|
| 26 | |
---|
[1377c9] | 27 | |
---|
[7fe9e13] | 28 | #ifndef SING_NDEBUG |
---|
[1f5565d] | 29 | #define OUTPUT MYTEST |
---|
[a7fbdd] | 30 | #else |
---|
| 31 | #define OUTPUT 0 |
---|
[03cecc2] | 32 | #endif |
---|
| 33 | |
---|
[1377c9] | 34 | # define PLURAL_INTERNAL_DECLARATIONS |
---|
| 35 | #include "nc/nc.h" |
---|
| 36 | #include "nc/sca.h" |
---|
| 37 | |
---|
[aadd638] | 38 | #include "misc/options.h" |
---|
| 39 | #include "coeffs/numbers.h" |
---|
[1377c9] | 40 | |
---|
| 41 | |
---|
| 42 | #include "monomials/ring.h" |
---|
| 43 | #include "monomials/p_polys.h" |
---|
[d81b79] | 44 | |
---|
[1377c9] | 45 | #include "nc/ncSAMult.h" // for CMultiplier etc classes |
---|
| 46 | // #include "nc/sca.h" // for SCA |
---|
[d81b79] | 47 | |
---|
| 48 | |
---|
[1377c9] | 49 | namespace |
---|
[58f1ff5] | 50 | { |
---|
[d81b79] | 51 | |
---|
| 52 | // poly functions defined in p_Procs: ; |
---|
[abe5c8] | 53 | static poly ggnc_pp_Mult_mm(const poly p, const poly m, const ring r) |
---|
[1495df4] | 54 | { |
---|
[63774ec] | 55 | if( (p == NULL) || (m == NULL) ) |
---|
| 56 | return NULL; |
---|
| 57 | |
---|
[f78891] | 58 | assume( (p != NULL) && (m != NULL) && (r != NULL) ); |
---|
| 59 | |
---|
[fea494] | 60 | #if OUTPUT |
---|
[a647914] | 61 | PrintS("VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ggnc_pp_Mult_mm(p, m) VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV "); |
---|
[1495df4] | 62 | PrintLn(); |
---|
[fea494] | 63 | PrintS("p: "); p_Write(p, r); |
---|
| 64 | PrintS("m: "); p_Write(m, r); |
---|
[1495df4] | 65 | #endif |
---|
[f2a4f3f] | 66 | poly pResult; |
---|
[fea494] | 67 | |
---|
[f2a4f3f] | 68 | if (p_IsConstant(m, r)) |
---|
[3d1222a] | 69 | pResult = __pp_Mult_nn(p, p_GetCoeff(m,r),r); |
---|
[f2a4f3f] | 70 | else |
---|
[fea494] | 71 | { |
---|
[f2a4f3f] | 72 | CGlobalMultiplier* const pMultiplier = r->GetNC()->GetGlobalMultiplier(); |
---|
| 73 | assume( pMultiplier != NULL ); |
---|
| 74 | |
---|
| 75 | poly pMonom = pMultiplier->LM(m, r); |
---|
| 76 | pResult = pMultiplier->MultiplyPE(p, pMonom); |
---|
| 77 | p_Delete(&pMonom, r); |
---|
| 78 | p_Test(pResult, r); |
---|
[3d1222a] | 79 | pResult = __p_Mult_nn(pResult, p_GetCoeff(m, r), r); |
---|
[f2a4f3f] | 80 | } |
---|
[f78891] | 81 | |
---|
[fea494] | 82 | #if OUTPUT |
---|
[f78891] | 83 | p_Test(pResult, r); |
---|
| 84 | |
---|
[a647914] | 85 | PrintS("ggnc_pp_Mult_mm(p, m) => "); p_Write(pResult, r); |
---|
[fea494] | 86 | PrintS("p: "); p_Write(p, r); |
---|
| 87 | PrintS("m: "); p_Write(m, r); |
---|
[a610ee] | 88 | PrintS("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "); |
---|
[f78891] | 89 | PrintLn(); |
---|
| 90 | #endif |
---|
| 91 | |
---|
| 92 | return pResult; |
---|
| 93 | |
---|
[1495df4] | 94 | } |
---|
| 95 | |
---|
[a647914] | 96 | static poly ggnc_p_Mult_mm(poly p, const poly m, const ring r) |
---|
[1495df4] | 97 | { |
---|
[63774ec] | 98 | if( (p == NULL) || (m == NULL) ) |
---|
| 99 | { |
---|
| 100 | p_Delete(&p, r); |
---|
| 101 | return NULL; |
---|
| 102 | } |
---|
| 103 | |
---|
[f78891] | 104 | assume( (p != NULL) && (m != NULL) && (r != NULL) ); |
---|
| 105 | |
---|
[fea494] | 106 | #if OUTPUT |
---|
[a647914] | 107 | PrintS("VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ggnc_p_Mult_mm(p, m) VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV "); |
---|
[1495df4] | 108 | PrintLn(); |
---|
[f78891] | 109 | PrintS("p: "); |
---|
[fea494] | 110 | p_Write(p, r); |
---|
[f78891] | 111 | PrintS("m: "); |
---|
[fea494] | 112 | p_Write(m, r); |
---|
[1495df4] | 113 | #endif |
---|
[f78891] | 114 | |
---|
[f2a4f3f] | 115 | poly pResult; |
---|
| 116 | |
---|
| 117 | if (p_IsConstant(m, r)) |
---|
[3d1222a] | 118 | pResult = __p_Mult_nn(p, p_GetCoeff(m,r),r); |
---|
[f2a4f3f] | 119 | else |
---|
[fea494] | 120 | { |
---|
[f2a4f3f] | 121 | CGlobalMultiplier* const pMultiplier = r->GetNC()->GetGlobalMultiplier(); |
---|
| 122 | assume( pMultiplier != NULL ); |
---|
| 123 | |
---|
| 124 | poly pMonom = pMultiplier->LM(m, r); |
---|
| 125 | pResult = pMultiplier->MultiplyPEDestroy(p, pMonom); |
---|
| 126 | p_Delete(&pMonom, r); |
---|
| 127 | p_Test(pResult, r); |
---|
[3d1222a] | 128 | pResult = __p_Mult_nn(pResult, p_GetCoeff(m, r), r); |
---|
[f2a4f3f] | 129 | } |
---|
[f78891] | 130 | |
---|
[fea494] | 131 | #if OUTPUT |
---|
[f2a4f3f] | 132 | p_Test(pResult, r); |
---|
| 133 | |
---|
[fea494] | 134 | PrintS("ggnc_p_Mult_mm(p, m) => "); p_Write(pResult, r); |
---|
| 135 | // PrintS("p: "); p_Write(p, r); |
---|
| 136 | PrintS("m: "); p_Write(m, r); |
---|
[a610ee] | 137 | PrintS("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "); |
---|
[f78891] | 138 | PrintLn(); |
---|
| 139 | #endif |
---|
[fea494] | 140 | |
---|
[f78891] | 141 | return pResult; |
---|
[1495df4] | 142 | |
---|
| 143 | } |
---|
| 144 | |
---|
[a9277b] | 145 | /* m*p */ |
---|
| 146 | static poly ggnc_p_mm_Mult(poly p, const poly m, const ring r) |
---|
[1495df4] | 147 | { |
---|
[63774ec] | 148 | if( (p == NULL) || (m == NULL) ) |
---|
| 149 | { |
---|
| 150 | p_Delete(&p, r); |
---|
| 151 | return NULL; |
---|
| 152 | } |
---|
| 153 | |
---|
[f78891] | 154 | assume( (p != NULL) && (m != NULL) && (r != NULL) ); |
---|
| 155 | |
---|
| 156 | p_Test(m, r); |
---|
| 157 | p_Test(p, r); |
---|
| 158 | |
---|
[fea494] | 159 | #if OUTPUT |
---|
[a9277b] | 160 | PrintS("VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ggnc_p_mm_Mult(p,m) VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV "); |
---|
[1495df4] | 161 | PrintLn(); |
---|
[fea494] | 162 | PrintS("m: "); p_Write(m, r); |
---|
| 163 | PrintS("p: "); p_Write(p, r); |
---|
[1495df4] | 164 | #endif |
---|
[f78891] | 165 | |
---|
[f2a4f3f] | 166 | poly pResult; |
---|
| 167 | |
---|
| 168 | if (p_IsConstant(m, r)) |
---|
[3d1222a] | 169 | pResult = __p_Mult_nn(p, p_GetCoeff(m,r),r); |
---|
[f2a4f3f] | 170 | else |
---|
[fea494] | 171 | { |
---|
[f2a4f3f] | 172 | CGlobalMultiplier* const pMultiplier = r->GetNC()->GetGlobalMultiplier(); |
---|
| 173 | assume( pMultiplier != NULL ); |
---|
| 174 | |
---|
| 175 | poly pMonom = pMultiplier->LM(m, r); |
---|
| 176 | pResult = pMultiplier->MultiplyEPDestroy(pMonom, p); |
---|
| 177 | p_Delete(&pMonom, r); |
---|
| 178 | p_Test(pResult, r); |
---|
[3d1222a] | 179 | pResult = __p_Mult_nn(pResult, p_GetCoeff(m, r), r); |
---|
[f2a4f3f] | 180 | } |
---|
[fea494] | 181 | |
---|
| 182 | #if OUTPUT |
---|
[f2a4f3f] | 183 | p_Test(pResult, r); |
---|
| 184 | |
---|
[a9277b] | 185 | PrintS("ggnc_p_mm_Mult(p,m) => "); p_Write(pResult, r); |
---|
[fea494] | 186 | // PrintS("p: "); p_Write(p, r); |
---|
| 187 | PrintS("m: "); p_Write(m, r); |
---|
[a610ee] | 188 | PrintS("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "); |
---|
[f78891] | 189 | PrintLn(); |
---|
| 190 | #endif |
---|
[fea494] | 191 | |
---|
[f78891] | 192 | return pResult; |
---|
[1495df4] | 193 | } |
---|
| 194 | |
---|
[a647914] | 195 | static poly ggnc_mm_Mult_pp(const poly m, const poly p, const ring r) |
---|
[1495df4] | 196 | { |
---|
[63774ec] | 197 | if( (p == NULL) || (m == NULL) ) |
---|
| 198 | { |
---|
| 199 | return NULL; |
---|
| 200 | } |
---|
| 201 | |
---|
[f78891] | 202 | assume( (p != NULL) && (m != NULL) && (r != NULL) ); |
---|
| 203 | |
---|
| 204 | p_Test(m, r); |
---|
| 205 | p_Test(p, r); |
---|
[fea494] | 206 | |
---|
| 207 | #if OUTPUT |
---|
[a647914] | 208 | PrintS("VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ggnc_mm_Mult_pp(m, p) VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV "); |
---|
[1495df4] | 209 | PrintLn(); |
---|
[fea494] | 210 | PrintS("m: "); p_Write(m, r); |
---|
| 211 | PrintS("p: "); p_Write(p, r); |
---|
[1495df4] | 212 | #endif |
---|
[fea494] | 213 | |
---|
[f2a4f3f] | 214 | poly pResult; |
---|
| 215 | |
---|
| 216 | if (p_IsConstant(m, r)) |
---|
[3d1222a] | 217 | pResult = __pp_Mult_nn(p, p_GetCoeff(m,r),r); |
---|
[f2a4f3f] | 218 | else |
---|
[fea494] | 219 | { |
---|
[f2a4f3f] | 220 | CGlobalMultiplier* const pMultiplier = r->GetNC()->GetGlobalMultiplier(); |
---|
| 221 | assume( pMultiplier != NULL ); |
---|
| 222 | |
---|
| 223 | poly pMonom = pMultiplier->LM(m, r); |
---|
| 224 | pResult = pMultiplier->MultiplyEP(pMonom, p); |
---|
| 225 | p_Delete(&pMonom, r); |
---|
| 226 | p_Test(pResult, r); |
---|
[3d1222a] | 227 | pResult = __p_Mult_nn(pResult, p_GetCoeff(m, r), r); |
---|
[f2a4f3f] | 228 | } |
---|
[1495df4] | 229 | |
---|
[fea494] | 230 | #if OUTPUT |
---|
[f78891] | 231 | p_Test(pResult, r); |
---|
| 232 | |
---|
[fea494] | 233 | PrintS("ggnc_mm_Mult_pp(m, p) => "); p_Write(pResult, r); |
---|
| 234 | PrintS("p: "); p_Write(p, r); |
---|
| 235 | PrintS("m: "); p_Write(m, r); |
---|
[a610ee] | 236 | PrintS("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "); |
---|
[f78891] | 237 | PrintLn(); |
---|
| 238 | #endif |
---|
[fea494] | 239 | |
---|
[f78891] | 240 | return pResult; |
---|
[1495df4] | 241 | } |
---|
| 242 | |
---|
[ef7b98] | 243 | static void ggnc_p_ProcsSet(ring rGR, p_Procs_s* p_Procs) |
---|
[1495df4] | 244 | { |
---|
[fea494] | 245 | #if OUTPUT |
---|
[a647914] | 246 | PrintS("|ggnc_p_ProcsSet()"); |
---|
[1495df4] | 247 | PrintLn(); |
---|
| 248 | #endif |
---|
| 249 | |
---|
[1f5565d] | 250 | assume( p_Procs != NULL ); |
---|
[fea494] | 251 | |
---|
[1495df4] | 252 | // "commutative" |
---|
[a647914] | 253 | p_Procs->p_Mult_mm = rGR->p_Procs->p_Mult_mm = ggnc_p_Mult_mm; |
---|
| 254 | p_Procs->pp_Mult_mm = rGR->p_Procs->pp_Mult_mm = ggnc_pp_Mult_mm; |
---|
[1495df4] | 255 | |
---|
| 256 | p_Procs->p_Minus_mm_Mult_qq = rGR->p_Procs->p_Minus_mm_Mult_qq = NULL; |
---|
| 257 | |
---|
| 258 | // non-commutaitve multiplication by monomial from the left |
---|
[a9277b] | 259 | rGR->p_Procs->p_mm_Mult = ggnc_p_mm_Mult; |
---|
[a647914] | 260 | rGR->GetNC()->p_Procs.mm_Mult_pp = ggnc_mm_Mult_pp; |
---|
[1495df4] | 261 | |
---|
| 262 | } |
---|
| 263 | |
---|
[a60e0b] | 264 | } |
---|
[58f1ff5] | 265 | |
---|
[1f5565d] | 266 | BOOLEAN ncInitSpecialPairMultiplication(ring r) |
---|
[1495df4] | 267 | { |
---|
[fea494] | 268 | #if OUTPUT |
---|
[a610ee] | 269 | PrintS("ncInitSpecialPairMultiplication(ring), ring: \n"); |
---|
[1f5565d] | 270 | rWrite(r, TRUE); |
---|
[1495df4] | 271 | PrintLn(); |
---|
| 272 | #endif |
---|
[fea494] | 273 | |
---|
[32a76d] | 274 | if(!rIsPluralRing(r))// ; // :((( |
---|
[1f5565d] | 275 | return TRUE; |
---|
[fea494] | 276 | |
---|
[1f5565d] | 277 | if(rIsSCA(r)) |
---|
| 278 | return TRUE; |
---|
[1495df4] | 279 | |
---|
[b902246] | 280 | if( r->GetNC()->GetGlobalMultiplier() != NULL ) |
---|
| 281 | { |
---|
| 282 | WarnS("Already defined!"); |
---|
[1f5565d] | 283 | return TRUE; |
---|
[b902246] | 284 | } |
---|
| 285 | |
---|
[1495df4] | 286 | r->GetNC()->GetGlobalMultiplier() = new CGlobalMultiplier(r); |
---|
| 287 | |
---|
[1f5565d] | 288 | ggnc_p_ProcsSet(r, r->p_Procs); |
---|
| 289 | return FALSE; // ok! |
---|
[1495df4] | 290 | } |
---|
| 291 | |
---|
| 292 | |
---|
[b902246] | 293 | CGlobalMultiplier::CGlobalMultiplier(ring r): |
---|
| 294 | CMultiplier<poly>(r), m_RingFormulaMultiplier(GetFormulaPowerMultiplier(r)) |
---|
[1495df4] | 295 | { |
---|
[fea494] | 296 | #if OUTPUT |
---|
[a610ee] | 297 | PrintS("CGlobalMultiplier::CGlobalMultiplier(ring)!"); |
---|
[1495df4] | 298 | PrintLn(); |
---|
| 299 | #endif |
---|
| 300 | |
---|
[ef7b98] | 301 | // m_cache = new CGlobalCacheHash(r); |
---|
[1495df4] | 302 | m_powers = new CPowerMultiplier(r); |
---|
| 303 | } |
---|
| 304 | |
---|
| 305 | |
---|
| 306 | CGlobalMultiplier::~CGlobalMultiplier() |
---|
| 307 | { |
---|
[fea494] | 308 | #if OUTPUT |
---|
[a610ee] | 309 | PrintS("CGlobalMultiplier::~CGlobalMultiplier()!"); |
---|
[1495df4] | 310 | PrintLn(); |
---|
| 311 | #endif |
---|
| 312 | |
---|
[ef7b98] | 313 | // delete m_cache; |
---|
[1495df4] | 314 | delete m_powers; |
---|
[b902246] | 315 | |
---|
| 316 | // we cannot delete m_RingFormulaMultiplier as it belongs to the ring! |
---|
[1495df4] | 317 | } |
---|
| 318 | |
---|
| 319 | |
---|
| 320 | |
---|
| 321 | // Exponent * Exponent |
---|
| 322 | // TODO: handle components!!! |
---|
[f78891] | 323 | poly CGlobalMultiplier::MultiplyEE(const CGlobalMultiplier::CExponent expLeft, const CGlobalMultiplier::CExponent expRight) |
---|
[1495df4] | 324 | { |
---|
[f78891] | 325 | |
---|
| 326 | const ring r = GetBasering(); |
---|
| 327 | |
---|
[fea494] | 328 | #if OUTPUT |
---|
[a610ee] | 329 | PrintS("CGlobalMultiplier::MultiplyEE(expLeft, expRight)!"); |
---|
[1495df4] | 330 | PrintLn(); |
---|
[fea494] | 331 | PrintS("expL: "); p_Write(expLeft, GetBasering()); |
---|
| 332 | PrintS("expR: "); p_Write(expRight, GetBasering()); |
---|
[1495df4] | 333 | #endif |
---|
| 334 | |
---|
[ef7b98] | 335 | // CCacheHash<poly>::CCacheItem* pLookup; |
---|
[fea494] | 336 | // |
---|
[ef7b98] | 337 | // int b = m_cache->LookupEE(expLeft, expRight, pLookup); |
---|
| 338 | // // TODO!!! |
---|
| 339 | // |
---|
| 340 | // // up to now: |
---|
| 341 | // assume( b == -1 ); |
---|
[1495df4] | 342 | |
---|
| 343 | // TODO: use PowerMultiplier!!!! |
---|
[f78891] | 344 | |
---|
| 345 | poly product = NULL; |
---|
| 346 | |
---|
| 347 | const int N = NVars(); |
---|
| 348 | int j = N; |
---|
| 349 | int i = 1; |
---|
| 350 | |
---|
| 351 | int ej = p_GetExp(expLeft, j, r); |
---|
| 352 | int ei = p_GetExp(expRight, i, r); |
---|
| 353 | |
---|
| 354 | while( (i < j) && !((ej != 0) && (ei != 0)) ) |
---|
| 355 | { |
---|
| 356 | if( ei == 0 ) |
---|
| 357 | ei = p_GetExp(expRight, ++i, r); |
---|
[fea494] | 358 | |
---|
[f78891] | 359 | if( ej == 0 ) |
---|
| 360 | ej = p_GetExp(expLeft, --j, r); |
---|
| 361 | } |
---|
| 362 | |
---|
[fea494] | 363 | |
---|
| 364 | #if OUTPUT |
---|
[a610ee] | 365 | PrintS("<CGlobalMultiplier::MultiplyEE>"); |
---|
[f78891] | 366 | PrintLn(); |
---|
[fea494] | 367 | Print("i: %d, j: %d", i, j); |
---|
[f78891] | 368 | PrintLn(); |
---|
[fea494] | 369 | Print("ei: %d, ej: %d", ei, ej); |
---|
[f78891] | 370 | PrintLn(); |
---|
| 371 | #endif |
---|
| 372 | |
---|
| 373 | |
---|
| 374 | // | expLeft | * | expRight | |
---|
| 375 | // |<<<< ej 0..0| , |0..0 ei >>>>| |
---|
| 376 | // |<<<< j <<<N| , |1>>> i >>>>| |
---|
| 377 | |
---|
| 378 | if( i >= j ) // BUG here!!!??? |
---|
| 379 | { |
---|
| 380 | // either i == j or i = j + 1 => commutative multiple! |
---|
| 381 | // TODO: it can be done more efficiently! () |
---|
| 382 | product = p_Head(expRight, r); |
---|
| 383 | |
---|
| 384 | // | expLeft | * | expRight | |
---|
| 385 | // |<<<< ej 0....0| , |0..00 ei >>>>| |
---|
| 386 | // |<<<< j i <<<N| , |1>>>j i >>>>| |
---|
| 387 | |
---|
[03cecc2] | 388 | if(i > j) |
---|
| 389 | { |
---|
| 390 | --i; |
---|
| 391 | ei = 0; |
---|
| 392 | } |
---|
[fea494] | 393 | |
---|
[f78891] | 394 | if( i == j ) |
---|
| 395 | { |
---|
| 396 | if( ej != 0 ) |
---|
| 397 | p_SetExp(product, i, ei + ej, r); |
---|
[03cecc2] | 398 | } |
---|
| 399 | |
---|
| 400 | --i; |
---|
[f78891] | 401 | |
---|
[03cecc2] | 402 | for(; i > 0; --i) |
---|
[f78891] | 403 | { |
---|
| 404 | const int e = p_GetExp(expLeft, i, r); |
---|
| 405 | |
---|
| 406 | if( e > 0 ) |
---|
| 407 | p_SetExp(product, i, e, r); |
---|
| 408 | } |
---|
| 409 | |
---|
[fea494] | 410 | p_Setm(product, r); |
---|
[f78891] | 411 | |
---|
| 412 | } else |
---|
| 413 | { // i < j, ei != 0, ej != 0 |
---|
[b902246] | 414 | |
---|
| 415 | Enum_ncSAType PairType = _ncSA_notImplemented; |
---|
| 416 | |
---|
| 417 | if( m_RingFormulaMultiplier != NULL ) |
---|
| 418 | PairType = m_RingFormulaMultiplier->GetPair(i, j); |
---|
| 419 | |
---|
| 420 | |
---|
| 421 | if( PairType == _ncSA_notImplemented ) |
---|
| 422 | product = m_powers->MultiplyEE( CPower(j, ej), CPower(i, ei) ); |
---|
[a647914] | 423 | // return ggnc_uu_Mult_ww_vert(i, a, j, b, r); |
---|
[b902246] | 424 | else |
---|
| 425 | // return m_RingFormulaMultiplier->Multiply(j, i, b, a); |
---|
| 426 | product = CFormulaPowerMultiplier::Multiply( PairType, i, j, ei, ej, GetBasering()); |
---|
[f78891] | 427 | |
---|
[fea494] | 428 | |
---|
| 429 | #if OUTPUT |
---|
[a610ee] | 430 | PrintS("<CGlobalMultiplier::MultiplyEE> ==> "); |
---|
[f78891] | 431 | PrintLn(); |
---|
[fea494] | 432 | Print("i: %d, j: %d", i, j); |
---|
[f78891] | 433 | PrintLn(); |
---|
[fea494] | 434 | Print("ei: %d, ej: %d", ei, ej); |
---|
[f78891] | 435 | PrintLn(); |
---|
[fea494] | 436 | PrintS("<product>: "); p_Write(product, GetBasering()); |
---|
[f78891] | 437 | #endif |
---|
[fea494] | 438 | |
---|
[f78891] | 439 | |
---|
| 440 | // TODO: Choose some multiplication strategy!!! |
---|
[fea494] | 441 | |
---|
[f78891] | 442 | while( (product != NULL) && !((i == NVars()) && (j == 1)) ) |
---|
| 443 | { |
---|
| 444 | |
---|
| 445 | // make some choice here!: |
---|
| 446 | |
---|
| 447 | if( i < NVars() ) |
---|
| 448 | { |
---|
| 449 | ei = p_GetExp(expRight, ++i, r); |
---|
[fea494] | 450 | |
---|
[f78891] | 451 | while( (ei == 0) && (i < NVars()) ) |
---|
| 452 | ei = p_GetExp(expRight, ++i, r); |
---|
| 453 | |
---|
| 454 | if( ei != 0 ) |
---|
| 455 | product = m_powers->MultiplyPEDestroy(product, CPower(i, ei)); |
---|
[fea494] | 456 | } |
---|
[f78891] | 457 | |
---|
| 458 | if( j > 1 ) |
---|
| 459 | { |
---|
| 460 | ej = p_GetExp(expLeft, --j, r); |
---|
| 461 | |
---|
| 462 | while( (ej == 0) && (1 < j) ) |
---|
| 463 | ej = p_GetExp(expLeft, --j, r); |
---|
| 464 | |
---|
| 465 | if( ej != 0 ) |
---|
| 466 | product = m_powers->MultiplyEPDestroy(CPower(j, ej), product); |
---|
| 467 | } |
---|
| 468 | |
---|
| 469 | |
---|
[fea494] | 470 | #if OUTPUT |
---|
[a610ee] | 471 | PrintS("<CGlobalMultiplier::MultiplyEE> ==> "); |
---|
[f78891] | 472 | PrintLn(); |
---|
[fea494] | 473 | Print("i: %d, j: %d", i, j); |
---|
[f78891] | 474 | PrintLn(); |
---|
[fea494] | 475 | Print("ei: %d, ej: %d", ei, ej); |
---|
[f78891] | 476 | PrintLn(); |
---|
[fea494] | 477 | PrintS("<product>: "); p_Write(product, GetBasering()); |
---|
[f78891] | 478 | #endif |
---|
[fea494] | 479 | |
---|
[f78891] | 480 | } |
---|
| 481 | |
---|
| 482 | } |
---|
| 483 | |
---|
[fea494] | 484 | // // TODO! |
---|
[ef7b98] | 485 | // |
---|
| 486 | // m_cache->StoreEE( expLeft, expRight, product); |
---|
| 487 | // // up to now: |
---|
[fea494] | 488 | return product; |
---|
[1495df4] | 489 | } |
---|
| 490 | |
---|
| 491 | // Monom * Exponent |
---|
[f78891] | 492 | poly CGlobalMultiplier::MultiplyME(const poly pMonom, const CGlobalMultiplier::CExponent expRight) |
---|
[1495df4] | 493 | { |
---|
[fea494] | 494 | #if OUTPUT |
---|
| 495 | PrintS("CGlobalMultiplier::MultiplyME(monom, expR)!"); |
---|
[f78891] | 496 | PrintLn(); |
---|
[fea494] | 497 | PrintS("Monom: "); p_Write(pMonom, GetBasering()); |
---|
| 498 | PrintS("expR: "); p_Write(expRight, GetBasering()); |
---|
[f78891] | 499 | #endif |
---|
| 500 | |
---|
[1495df4] | 501 | return MultiplyEE(pMonom, expRight); |
---|
| 502 | } |
---|
| 503 | |
---|
| 504 | // Exponent * Monom |
---|
[f78891] | 505 | poly CGlobalMultiplier::MultiplyEM(const CGlobalMultiplier::CExponent expLeft, const poly pMonom) |
---|
[1495df4] | 506 | { |
---|
[fea494] | 507 | #if OUTPUT |
---|
| 508 | PrintS("CGlobalMultiplier::MultiplyEM(expL, monom)!"); |
---|
[f78891] | 509 | PrintLn(); |
---|
[fea494] | 510 | PrintS("expL: "); p_Write(expLeft, GetBasering()); |
---|
| 511 | PrintS("Monom: "); p_Write(pMonom, GetBasering()); |
---|
[f78891] | 512 | #endif |
---|
| 513 | |
---|
[1495df4] | 514 | return MultiplyEE(expLeft, pMonom); |
---|
| 515 | } |
---|
| 516 | |
---|
| 517 | |
---|
[03cecc2] | 518 | |
---|
| 519 | |
---|
| 520 | |
---|
[6807f0] | 521 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
[f78891] | 522 | CCommutativeSpecialPairMultiplier::CCommutativeSpecialPairMultiplier(ring r, int i, int j): |
---|
| 523 | CSpecialPairMultiplier(r, i, j) |
---|
| 524 | { |
---|
[fea494] | 525 | #if OUTPUT |
---|
[f78891] | 526 | Print("CCommutativeSpecialPairMultiplier::CCommutativeSpecialPairMultiplier(ring, i: %d, j: %d)!", i, j); |
---|
| 527 | PrintLn(); |
---|
| 528 | #endif |
---|
[a60e0b] | 529 | } |
---|
[1495df4] | 530 | |
---|
| 531 | |
---|
[f78891] | 532 | CCommutativeSpecialPairMultiplier::~CCommutativeSpecialPairMultiplier() |
---|
[1495df4] | 533 | { |
---|
[fea494] | 534 | #if OUTPUT |
---|
[a610ee] | 535 | PrintS("CCommutativeSpecialPairMultiplier::~CCommutativeSpecialPairMultiplier()"); |
---|
[f78891] | 536 | PrintLn(); |
---|
| 537 | #endif |
---|
[1495df4] | 538 | } |
---|
| 539 | |
---|
[f78891] | 540 | // Exponent * Exponent |
---|
| 541 | poly CCommutativeSpecialPairMultiplier::MultiplyEE(const int expLeft, const int expRight) |
---|
[1495df4] | 542 | { |
---|
[fea494] | 543 | #if OUTPUT |
---|
| 544 | Print("CCommutativeSpecialPairMultiplier::MultiplyEE(var(%d)^{%d}, var(%d)^{%d})!", GetJ(), expLeft, GetI(), expRight); |
---|
[f78891] | 545 | PrintLn(); |
---|
| 546 | #endif |
---|
| 547 | |
---|
| 548 | const ring r = GetBasering(); |
---|
[1495df4] | 549 | |
---|
[a7fbdd] | 550 | return CFormulaPowerMultiplier::ncSA_1xy0x0y0(GetI(), GetJ(), expRight, expLeft, r); |
---|
[f78891] | 551 | } |
---|
[1495df4] | 552 | |
---|
[6807f0] | 553 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 554 | CAntiCommutativeSpecialPairMultiplier::CAntiCommutativeSpecialPairMultiplier(ring r, int i, int j): |
---|
[2bf04b] | 555 | CSpecialPairMultiplier(r, i, j) |
---|
[6807f0] | 556 | { |
---|
[fea494] | 557 | #if OUTPUT |
---|
[2bf04b] | 558 | Print("CAntiCommutativeSpecialPairMultiplier::CAntiCommutativeSpecialPairMultiplier(ring, i: %d, j: %d)!", i, j); |
---|
| 559 | PrintLn(); |
---|
[6807f0] | 560 | #endif |
---|
[a60e0b] | 561 | } |
---|
[6807f0] | 562 | |
---|
| 563 | |
---|
| 564 | CAntiCommutativeSpecialPairMultiplier::~CAntiCommutativeSpecialPairMultiplier() |
---|
| 565 | { |
---|
[fea494] | 566 | #if OUTPUT |
---|
[2bf04b] | 567 | PrintS("CAntiCommutativeSpecialPairMultiplier::~CAntiCommutativeSpecialPairMultiplier()"); |
---|
| 568 | PrintLn(); |
---|
[6807f0] | 569 | #endif |
---|
| 570 | } |
---|
| 571 | |
---|
| 572 | // Exponent * Exponent |
---|
| 573 | poly CAntiCommutativeSpecialPairMultiplier::MultiplyEE(const int expLeft, const int expRight) |
---|
| 574 | { |
---|
[fea494] | 575 | #if OUTPUT |
---|
[2bf04b] | 576 | Print("CAntiCommutativeSpecialPairMultiplier::MultiplyEE(var(%d)^{%d}, var(%d)^{%d})!", GetJ(), expLeft, GetI(), expRight); |
---|
| 577 | PrintLn(); |
---|
[6807f0] | 578 | #endif |
---|
| 579 | |
---|
[2bf04b] | 580 | const ring r = GetBasering(); |
---|
[6807f0] | 581 | |
---|
[2bf04b] | 582 | return CFormulaPowerMultiplier::ncSA_Mxy0x0y0(GetI(), GetJ(), expRight, expLeft, r); |
---|
[6807f0] | 583 | } |
---|
| 584 | |
---|
| 585 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 586 | CQuasiCommutativeSpecialPairMultiplier::CQuasiCommutativeSpecialPairMultiplier(ring r, int i, int j, number q): |
---|
[2bf04b] | 587 | CSpecialPairMultiplier(r, i, j), m_q(q) |
---|
[6807f0] | 588 | { |
---|
[fea494] | 589 | #if OUTPUT |
---|
[2bf04b] | 590 | Print("CQuasiCommutativeSpecialPairMultiplier::CQuasiCommutativeSpecialPairMultiplier(ring, i: %d, j: %d, q)!", i, j); |
---|
| 591 | PrintLn(); |
---|
| 592 | PrintS("Parameter q: "); |
---|
| 593 | n_Write(q, r); |
---|
[6807f0] | 594 | #endif |
---|
[a60e0b] | 595 | } |
---|
[6807f0] | 596 | |
---|
| 597 | |
---|
| 598 | CQuasiCommutativeSpecialPairMultiplier::~CQuasiCommutativeSpecialPairMultiplier() |
---|
| 599 | { |
---|
[fea494] | 600 | #if OUTPUT |
---|
[2bf04b] | 601 | PrintS("CQuasiCommutativeSpecialPairMultiplier::~CQuasiCommutativeSpecialPairMultiplier()"); |
---|
| 602 | PrintLn(); |
---|
[6807f0] | 603 | #endif |
---|
| 604 | } |
---|
| 605 | |
---|
| 606 | // Exponent * Exponent |
---|
| 607 | poly CQuasiCommutativeSpecialPairMultiplier::MultiplyEE(const int expLeft, const int expRight) |
---|
| 608 | { |
---|
[fea494] | 609 | #if OUTPUT |
---|
[2bf04b] | 610 | Print("CQuasiCommutativeSpecialPairMultiplier::MultiplyEE(var(%d)^{%d}, var(%d)^{%d})!", GetJ(), expLeft, GetI(), expRight); |
---|
| 611 | PrintLn(); |
---|
[6807f0] | 612 | #endif |
---|
| 613 | |
---|
[2bf04b] | 614 | const ring r = GetBasering(); |
---|
[6807f0] | 615 | |
---|
[2bf04b] | 616 | return CFormulaPowerMultiplier::ncSA_Qxy0x0y0(GetI(), GetJ(), expRight, expLeft, m_q, r); |
---|
[6807f0] | 617 | } |
---|
| 618 | |
---|
| 619 | |
---|
[03cecc2] | 620 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 621 | CWeylSpecialPairMultiplier::CWeylSpecialPairMultiplier(ring r, int i, int j, number g): |
---|
| 622 | CSpecialPairMultiplier(r, i, j), m_g(g) |
---|
| 623 | { |
---|
[fea494] | 624 | #if OUTPUT |
---|
[03cecc2] | 625 | Print("CWeylSpecialPairMultiplier::CWeylSpecialPairMultiplier(ring, i: %d, j: %d, g)!", i, j); |
---|
| 626 | PrintLn(); |
---|
| 627 | PrintS("Parameter g: "); |
---|
| 628 | n_Write(g, r); |
---|
| 629 | #endif |
---|
[a60e0b] | 630 | } |
---|
[03cecc2] | 631 | |
---|
| 632 | |
---|
| 633 | CWeylSpecialPairMultiplier::~CWeylSpecialPairMultiplier() |
---|
| 634 | { |
---|
[fea494] | 635 | #if OUTPUT |
---|
[a610ee] | 636 | PrintS("CWeylSpecialPairMultiplier::~CWeylSpecialPairMultiplier()"); |
---|
[03cecc2] | 637 | PrintLn(); |
---|
| 638 | #endif |
---|
| 639 | } |
---|
| 640 | |
---|
| 641 | // Exponent * Exponent |
---|
| 642 | poly CWeylSpecialPairMultiplier::MultiplyEE(const int expLeft, const int expRight) |
---|
| 643 | { |
---|
[fea494] | 644 | #if OUTPUT |
---|
| 645 | Print("CWeylSpecialPairMultiplier::MultiplyEE(var(%d)^{%d}, var(%d)^{%d})!", GetJ(), expLeft, GetI(), expRight); |
---|
[03cecc2] | 646 | PrintLn(); |
---|
| 647 | #endif |
---|
| 648 | // Char == 0, otherwise - problem! |
---|
| 649 | |
---|
[fea494] | 650 | |
---|
[03cecc2] | 651 | const ring r = GetBasering(); |
---|
| 652 | |
---|
[a7fbdd] | 653 | assume( expLeft*expRight > 0 ); |
---|
[03cecc2] | 654 | |
---|
[a7fbdd] | 655 | return CFormulaPowerMultiplier::ncSA_1xy0x0yG(GetI(), GetJ(), expRight, expLeft, m_g, r); |
---|
[03cecc2] | 656 | } |
---|
| 657 | |
---|
[1f5565d] | 658 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 659 | CHWeylSpecialPairMultiplier::CHWeylSpecialPairMultiplier(ring r, int i, int j, int k): |
---|
| 660 | CSpecialPairMultiplier(r, i, j), m_k(k) |
---|
| 661 | { |
---|
[fea494] | 662 | #if OUTPUT |
---|
[1f5565d] | 663 | Print("CHWeylSpecialPairMultiplier::CHWeylSpecialPairMultiplier(ring, i: %d, j: %d, k: %d)!", i, j, k); |
---|
| 664 | PrintLn(); |
---|
| 665 | #endif |
---|
| 666 | } |
---|
| 667 | |
---|
| 668 | |
---|
| 669 | CHWeylSpecialPairMultiplier::~CHWeylSpecialPairMultiplier() |
---|
| 670 | { |
---|
[fea494] | 671 | #if OUTPUT |
---|
[1f5565d] | 672 | PrintS("CHWeylSpecialPairMultiplier::~CHWeylSpecialPairMultiplier()"); |
---|
| 673 | PrintLn(); |
---|
| 674 | #endif |
---|
| 675 | } |
---|
| 676 | |
---|
| 677 | // Exponent * Exponent |
---|
| 678 | poly CHWeylSpecialPairMultiplier::MultiplyEE(const int expLeft, const int expRight) |
---|
| 679 | { |
---|
[fea494] | 680 | #if OUTPUT |
---|
| 681 | Print("CHWeylSpecialPairMultiplier::MultiplyEE(var(%d)^{%d}, var(%d)^{%d})!", GetJ(), expLeft, GetI(), expRight); |
---|
[1f5565d] | 682 | PrintLn(); |
---|
| 683 | #endif |
---|
| 684 | // Char == 0, otherwise - problem! |
---|
| 685 | |
---|
| 686 | |
---|
| 687 | const ring r = GetBasering(); |
---|
| 688 | |
---|
| 689 | assume( expLeft*expRight > 0 ); |
---|
| 690 | |
---|
| 691 | return CFormulaPowerMultiplier::ncSA_1xy0x0yT2(GetI(), GetJ(), expRight, expLeft, m_k, r); |
---|
| 692 | } |
---|
| 693 | |
---|
[03cecc2] | 694 | |
---|
| 695 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 696 | CShiftSpecialPairMultiplier::CShiftSpecialPairMultiplier(ring r, int i, int j, int s, number c): |
---|
| 697 | CSpecialPairMultiplier(r, i, j), m_shiftCoef(c), m_shiftVar(s) |
---|
| 698 | { |
---|
[fea494] | 699 | #if OUTPUT |
---|
[03cecc2] | 700 | Print("CShiftSpecialPairMultiplier::CShiftSpecialPairMultiplier(ring, i: %d, j: %d, s: %d, c)!", i, j, s); |
---|
| 701 | PrintLn(); |
---|
| 702 | PrintS("Parameter c: "); n_Write(c, r); |
---|
| 703 | #endif |
---|
[a60e0b] | 704 | } |
---|
[03cecc2] | 705 | |
---|
| 706 | |
---|
| 707 | CShiftSpecialPairMultiplier::~CShiftSpecialPairMultiplier() |
---|
| 708 | { |
---|
[fea494] | 709 | #if OUTPUT |
---|
[a610ee] | 710 | PrintS("CShiftSpecialPairMultiplier::~CShiftSpecialPairMultiplier()"); |
---|
[03cecc2] | 711 | PrintLn(); |
---|
| 712 | #endif |
---|
| 713 | } |
---|
| 714 | |
---|
| 715 | // Exponent * Exponent |
---|
| 716 | poly CShiftSpecialPairMultiplier::MultiplyEE(const int expLeft, const int expRight) |
---|
| 717 | { |
---|
[fea494] | 718 | #if OUTPUT |
---|
| 719 | Print("CShiftSpecialPairMultiplier::MultiplyEE(var(%d)^{%d}, var(%d)^{%d})!", GetJ(), expLeft, GetI(), expRight); |
---|
[03cecc2] | 720 | PrintLn(); |
---|
| 721 | #endif |
---|
| 722 | // Char == 0, otherwise - problem! |
---|
| 723 | |
---|
| 724 | assume( expLeft*expRight > 0 ); |
---|
| 725 | |
---|
| 726 | const ring r = GetBasering(); |
---|
| 727 | |
---|
[a7fbdd] | 728 | if( m_shiftVar != GetI() ) // YX = XY + b*Y? |
---|
| 729 | return CFormulaPowerMultiplier::ncSA_1xy0xBy0(GetI(), GetJ(), expRight, expLeft, m_shiftCoef, r); // case: (1, 0, beta, 0, 0) |
---|
| 730 | else |
---|
| 731 | return CFormulaPowerMultiplier::ncSA_1xyAx0y0(GetI(), GetJ(), expRight, expLeft, m_shiftCoef, r); // case: (1, alpha, 0, 0) |
---|
[03cecc2] | 732 | |
---|
[a7fbdd] | 733 | } |
---|
[03cecc2] | 734 | |
---|
| 735 | |
---|
| 736 | |
---|
[a7fbdd] | 737 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 738 | CExternalSpecialPairMultiplier::CExternalSpecialPairMultiplier(ring r, int i, int j, Enum_ncSAType type): |
---|
| 739 | CSpecialPairMultiplier(r, i, j), m_ncSAtype(type) |
---|
| 740 | { |
---|
[fea494] | 741 | #if OUTPUT |
---|
[a7fbdd] | 742 | Print("CExternalSpecialPairMultiplier::CExternalSpecialPairMultiplier(ring, i: %d, j: %d, type: %d, c)!", i, j, (int)type); |
---|
| 743 | PrintLn(); |
---|
| 744 | #endif |
---|
[a60e0b] | 745 | } |
---|
[03cecc2] | 746 | |
---|
| 747 | |
---|
[a7fbdd] | 748 | CExternalSpecialPairMultiplier::~CExternalSpecialPairMultiplier() |
---|
| 749 | { |
---|
[fea494] | 750 | #if OUTPUT |
---|
[a610ee] | 751 | PrintS("CExternalSpecialPairMultiplier::~CExternalSpecialPairMultiplier()"); |
---|
[a7fbdd] | 752 | PrintLn(); |
---|
| 753 | #endif |
---|
| 754 | } |
---|
[03cecc2] | 755 | |
---|
[a7fbdd] | 756 | // Exponent * Exponent |
---|
| 757 | poly CExternalSpecialPairMultiplier::MultiplyEE(const int expLeft, const int expRight) |
---|
| 758 | { |
---|
[fea494] | 759 | #if OUTPUT |
---|
| 760 | Print("CExternalSpecialPairMultiplier::MultiplyEE(var(%d)^{%d}, var(%d)^{%d})!", GetJ(), expLeft, GetI(), expRight); |
---|
[a7fbdd] | 761 | PrintLn(); |
---|
| 762 | #endif |
---|
| 763 | // Char == 0, otherwise - problem! |
---|
[03cecc2] | 764 | |
---|
[a7fbdd] | 765 | assume( expLeft*expRight > 0 ); |
---|
[03cecc2] | 766 | |
---|
[a7fbdd] | 767 | const ring r = GetBasering(); |
---|
[03cecc2] | 768 | |
---|
[fea494] | 769 | return CFormulaPowerMultiplier::Multiply(m_ncSAtype, GetI(), GetJ(), expRight, expLeft, r); |
---|
[03cecc2] | 770 | |
---|
| 771 | } |
---|
| 772 | |
---|
| 773 | |
---|
| 774 | |
---|
[6807f0] | 775 | /////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 776 | |
---|
[1495df4] | 777 | // factory method! |
---|
| 778 | CSpecialPairMultiplier* AnalyzePair(const ring r, int i, int j) |
---|
| 779 | { |
---|
[fea494] | 780 | #if OUTPUT |
---|
[1495df4] | 781 | Print("AnalyzePair(ring, i: %d, j: %d)!", i, j); |
---|
| 782 | PrintLn(); |
---|
| 783 | #endif |
---|
| 784 | |
---|
[a7fbdd] | 785 | Enum_ncSAType type = CFormulaPowerMultiplier::AnalyzePair(r, i, j); |
---|
[1495df4] | 786 | |
---|
[a7fbdd] | 787 | if( type == _ncSA_notImplemented ) return NULL; |
---|
[1495df4] | 788 | |
---|
| 789 | |
---|
[a7fbdd] | 790 | // last possibility: |
---|
| 791 | return new CExternalSpecialPairMultiplier(r, i, j, type); // For tests! |
---|
[1495df4] | 792 | |
---|
[fea494] | 793 | |
---|
[a7fbdd] | 794 | if( type == _ncSA_1xy0x0y0 ) |
---|
| 795 | return new CCommutativeSpecialPairMultiplier(r, i, j); |
---|
[6807f0] | 796 | |
---|
[a7fbdd] | 797 | if( type == _ncSA_Mxy0x0y0 ) |
---|
| 798 | return new CAntiCommutativeSpecialPairMultiplier(r, i, j); |
---|
[6807f0] | 799 | |
---|
[a7fbdd] | 800 | if( type == _ncSA_Qxy0x0y0 ) |
---|
[03cecc2] | 801 | { |
---|
[a7fbdd] | 802 | const number q = p_GetCoeff(GetC(r, i, j), r); |
---|
| 803 | return new CQuasiCommutativeSpecialPairMultiplier(r, i, j, q); |
---|
| 804 | } |
---|
[fea494] | 805 | |
---|
[a7fbdd] | 806 | const poly d = GetD(r, i, j); |
---|
[fea494] | 807 | |
---|
[a7fbdd] | 808 | assume( d != NULL ); |
---|
| 809 | assume( pNext(d) == NULL ); |
---|
[03cecc2] | 810 | |
---|
[a7fbdd] | 811 | const number g = p_GetCoeff(d, r); |
---|
[03cecc2] | 812 | |
---|
[a7fbdd] | 813 | if( type == _ncSA_1xy0x0yG ) // Weyl |
---|
[fea494] | 814 | return new CWeylSpecialPairMultiplier(r, i, j, g); |
---|
[6807f0] | 815 | |
---|
[a7fbdd] | 816 | if( type == _ncSA_1xyAx0y0 ) // Shift 1 |
---|
| 817 | return new CShiftSpecialPairMultiplier(r, i, j, i, g); |
---|
[6807f0] | 818 | |
---|
[a7fbdd] | 819 | if( type == _ncSA_1xy0xBy0 ) // Shift 2 |
---|
| 820 | return new CShiftSpecialPairMultiplier(r, i, j, j, g); |
---|
[1495df4] | 821 | |
---|
[1f5565d] | 822 | if( type == _ncSA_1xy0x0yT2 ) // simple homogenized Weyl algebra |
---|
| 823 | return new CHWeylSpecialPairMultiplier(r, i, j, p_IsPurePower(d, r)); |
---|
| 824 | |
---|
[1495df4] | 825 | } |
---|
| 826 | |
---|
| 827 | |
---|
| 828 | |
---|
| 829 | |
---|
| 830 | |
---|
| 831 | |
---|
| 832 | CPowerMultiplier::CPowerMultiplier(ring r): CMultiplier<CPower>(r) |
---|
| 833 | { |
---|
[fea494] | 834 | #if OUTPUT |
---|
[a610ee] | 835 | PrintS("CPowerMultiplier::CPowerMultiplier(ring)!"); |
---|
[1495df4] | 836 | PrintLn(); |
---|
| 837 | #endif |
---|
| 838 | |
---|
| 839 | m_specialpairs = (CSpecialPairMultiplier**)omAlloc0( ((NVars() * (NVars()-1)) / 2) * sizeof(CSpecialPairMultiplier*) ); |
---|
| 840 | |
---|
| 841 | for( int i = 1; i < NVars(); i++ ) |
---|
| 842 | for( int j = i + 1; j <= NVars(); j++ ) |
---|
| 843 | GetPair(i, j) = AnalyzePair(GetBasering(), i, j); // factory method! |
---|
| 844 | } |
---|
| 845 | |
---|
| 846 | |
---|
| 847 | CPowerMultiplier::~CPowerMultiplier() |
---|
| 848 | { |
---|
[fea494] | 849 | #if OUTPUT |
---|
[a610ee] | 850 | PrintS("CPowerMultiplier::~CPowerMultiplier()!"); |
---|
[1495df4] | 851 | PrintLn(); |
---|
| 852 | #endif |
---|
| 853 | |
---|
| 854 | omFreeSize((ADDRESS)m_specialpairs, ((NVars() * (NVars()-1)) / 2) * sizeof(CSpecialPairMultiplier*) ); |
---|
| 855 | } |
---|
| 856 | |
---|
| 857 | |
---|
| 858 | // Monom * Exponent |
---|
| 859 | // pMonom may NOT be of the form: var(j)^{n}! |
---|
| 860 | poly CPowerMultiplier::MultiplyME(const poly pMonom, const CExponent expRight) |
---|
| 861 | { |
---|
| 862 | const int j = expRight.Var; |
---|
| 863 | const int n = expRight.Power; |
---|
[f78891] | 864 | |
---|
| 865 | const ring r = GetBasering(); |
---|
[fea494] | 866 | |
---|
| 867 | #if OUTPUT |
---|
[f78891] | 868 | Print("CPowerMultiplier::MultiplyME(monom * var(%d)^{%d})!", j, n); |
---|
[1495df4] | 869 | PrintLn(); |
---|
[fea494] | 870 | PrintS("Monom: "); p_Write(pMonom, r); |
---|
[1495df4] | 871 | #endif |
---|
| 872 | |
---|
| 873 | assume( (j > 0) && (j <= NVars())); |
---|
| 874 | |
---|
| 875 | if( n == 0 ) |
---|
[f78891] | 876 | return p_Head(pMonom, r); // Copy?!? |
---|
[fea494] | 877 | |
---|
[1495df4] | 878 | |
---|
| 879 | int v = NVars(); |
---|
[f78891] | 880 | int e = p_GetExp(pMonom, v, r); |
---|
[1495df4] | 881 | |
---|
| 882 | while((v > j) && (e == 0)) |
---|
[f78891] | 883 | e = p_GetExp(pMonom, --v, r); |
---|
[1495df4] | 884 | |
---|
| 885 | // TODO: review this! |
---|
[cc4cc80] | 886 | if( v == j ) |
---|
[1495df4] | 887 | { |
---|
[fea494] | 888 | poly p = p_Head(pMonom, r); |
---|
[f78891] | 889 | p_SetExp(p, v, e + n, r); |
---|
[fea494] | 890 | p_Setm(p, r); |
---|
[f78891] | 891 | |
---|
[1495df4] | 892 | return p; |
---|
| 893 | } |
---|
[f78891] | 894 | |
---|
| 895 | assume( v > j ); |
---|
| 896 | assume( e > 0 ); |
---|
[fea494] | 897 | |
---|
[1495df4] | 898 | // And now the General Case: v > j! |
---|
| 899 | |
---|
| 900 | poly p = MultiplyEE( CPower(v, e), expRight ); // Easy way! |
---|
| 901 | |
---|
| 902 | --v; |
---|
[fea494] | 903 | |
---|
[1495df4] | 904 | while(v > 0) |
---|
| 905 | { |
---|
| 906 | e = p_GetExp(pMonom, v, GetBasering()); |
---|
[fea494] | 907 | |
---|
[1495df4] | 908 | if( e > 0 ) |
---|
| 909 | p = MultiplyEPDestroy(CPower(v, e), p); |
---|
| 910 | |
---|
| 911 | --v; |
---|
| 912 | } |
---|
| 913 | |
---|
[fea494] | 914 | #if OUTPUT |
---|
[a610ee] | 915 | PrintS("CPowerMultiplier::MultiplyME() ===> "); |
---|
[fea494] | 916 | p_Write(p, GetBasering()); |
---|
[f78891] | 917 | #endif |
---|
[fea494] | 918 | |
---|
[1495df4] | 919 | return p; |
---|
| 920 | } |
---|
| 921 | |
---|
| 922 | // Exponent * Monom |
---|
| 923 | // pMonom may NOT be of the form: var(i)^{m}! |
---|
| 924 | poly CPowerMultiplier::MultiplyEM(const CExponent expLeft, const poly pMonom) |
---|
| 925 | { |
---|
[f78891] | 926 | const ring r = GetBasering(); |
---|
| 927 | |
---|
[1495df4] | 928 | // TODO: as above! (difference due to Left/Right semmantics!) |
---|
| 929 | const int j = expLeft.Var; |
---|
| 930 | const int n = expLeft.Power; |
---|
| 931 | |
---|
[fea494] | 932 | #if OUTPUT |
---|
[1495df4] | 933 | Print("CPowerMultiplier::MultiplyEM(var(%d)^{%d} * monom)!", j, n); |
---|
| 934 | PrintLn(); |
---|
[fea494] | 935 | PrintS("Monom: "); p_Write(pMonom, r); |
---|
[1495df4] | 936 | #endif |
---|
| 937 | |
---|
| 938 | assume( (j > 0) && (j <= NVars())); |
---|
| 939 | |
---|
| 940 | if( n == 0 ) |
---|
[f78891] | 941 | return p_Head(pMonom, r); // Copy?!? |
---|
[1495df4] | 942 | |
---|
| 943 | |
---|
| 944 | int v = 1; // NVars(); |
---|
[f78891] | 945 | int e = p_GetExp(pMonom, v, r); |
---|
[1495df4] | 946 | |
---|
| 947 | while((v < j) && (e == 0)) |
---|
[f78891] | 948 | e = p_GetExp(pMonom, ++v, r); |
---|
[1495df4] | 949 | |
---|
[fea494] | 950 | if( v == j ) |
---|
[1495df4] | 951 | { |
---|
[fea494] | 952 | poly p = p_Head(pMonom, r); |
---|
[f78891] | 953 | p_SetExp(p, j, e + n, r); |
---|
[fea494] | 954 | p_Setm(p, r); |
---|
[f78891] | 955 | |
---|
[1495df4] | 956 | return p; |
---|
| 957 | } |
---|
| 958 | |
---|
[f78891] | 959 | assume( v < j ); |
---|
| 960 | assume( e > 0 ); |
---|
| 961 | |
---|
[fea494] | 962 | |
---|
[1495df4] | 963 | // And now the General Case: v > j! |
---|
| 964 | |
---|
| 965 | poly p = MultiplyEE( expLeft, CPower(v, e) ); // Easy way! |
---|
| 966 | |
---|
| 967 | ++v; |
---|
[f78891] | 968 | |
---|
[1495df4] | 969 | while(v <= NVars()) |
---|
| 970 | { |
---|
[f78891] | 971 | e = p_GetExp(pMonom, v, r); |
---|
[fea494] | 972 | |
---|
[1495df4] | 973 | if( e > 0 ) |
---|
| 974 | p = MultiplyPEDestroy(p, CPower(v, e)); |
---|
[fea494] | 975 | |
---|
[1495df4] | 976 | ++v; |
---|
| 977 | } |
---|
[f78891] | 978 | |
---|
[fea494] | 979 | #if OUTPUT |
---|
[a610ee] | 980 | PrintS("CPowerMultiplier::MultiplyEM() ===> "); |
---|
[fea494] | 981 | p_Write(p, r); |
---|
[f78891] | 982 | #endif |
---|
| 983 | |
---|
| 984 | return p; |
---|
[fea494] | 985 | |
---|
[1495df4] | 986 | } |
---|
| 987 | |
---|
| 988 | |
---|
| 989 | // Exponent * Exponent |
---|
| 990 | // Computes: var(j)^{expLeft} * var(i)^{expRight} |
---|
| 991 | poly CPowerMultiplier::MultiplyEE(const CExponent expLeft, const CExponent expRight) |
---|
| 992 | { |
---|
[fea494] | 993 | #if OUTPUT |
---|
[a610ee] | 994 | PrintS("CPowerMultiplier::MultiplyEE)!"); |
---|
[1495df4] | 995 | PrintLn(); |
---|
| 996 | #endif |
---|
| 997 | |
---|
| 998 | const int i = expRight.Var, j = expLeft.Var; |
---|
| 999 | const int ei = expRight.Power, ej = expLeft.Power; |
---|
| 1000 | |
---|
[fea494] | 1001 | #if OUTPUT |
---|
[1495df4] | 1002 | Print("Input: var(%d)^{%d} * var(%d)^{%d}", j, ej, i, ei); |
---|
| 1003 | PrintLn(); |
---|
| 1004 | #endif |
---|
| 1005 | |
---|
[f78891] | 1006 | assume(1 <= i); |
---|
| 1007 | assume(j <= NVars()); |
---|
| 1008 | assume(1 <= j); |
---|
| 1009 | assume(i <= NVars()); |
---|
| 1010 | assume(ei > 0); |
---|
| 1011 | assume(ej > 0); |
---|
[fea494] | 1012 | |
---|
[1495df4] | 1013 | if( i >= j ) |
---|
| 1014 | { |
---|
[f78891] | 1015 | const ring r = GetBasering(); |
---|
| 1016 | |
---|
[b902246] | 1017 | poly product = p_One(r); |
---|
[f78891] | 1018 | p_SetExp(product, j, ej, r); |
---|
| 1019 | p_SetExp(product, i, ei, r); |
---|
| 1020 | p_Setm(product, r); |
---|
| 1021 | |
---|
| 1022 | return product; |
---|
| 1023 | |
---|
[1495df4] | 1024 | } else |
---|
| 1025 | { |
---|
| 1026 | assume(i < j); |
---|
| 1027 | |
---|
| 1028 | // No Cache Lookup!? :( |
---|
| 1029 | |
---|
| 1030 | CSpecialPairMultiplier* pSpecialMultiplier = GetPair(i, j); |
---|
| 1031 | |
---|
| 1032 | // Special case? |
---|
| 1033 | if( pSpecialMultiplier != NULL ) |
---|
| 1034 | { |
---|
| 1035 | assume( pSpecialMultiplier->GetI() == i ); |
---|
| 1036 | assume( pSpecialMultiplier->GetJ() == j ); |
---|
| 1037 | assume( pSpecialMultiplier->GetBasering() == GetBasering() ); |
---|
| 1038 | |
---|
[f78891] | 1039 | return pSpecialMultiplier->MultiplyEE(ej, ei); |
---|
[1495df4] | 1040 | } else |
---|
| 1041 | { |
---|
| 1042 | // Perform general NC Multiplication: |
---|
| 1043 | // TODO |
---|
[fea494] | 1044 | |
---|
[58f1ff5] | 1045 | WerrorS("Sorry the general case is not implemented this way yet!!!"); |
---|
| 1046 | assume(0); |
---|
[1495df4] | 1047 | |
---|
[d2f720] | 1048 | // poly product = NULL; |
---|
[1495df4] | 1049 | } |
---|
| 1050 | } |
---|
[fea494] | 1051 | |
---|
| 1052 | return NULL; |
---|
[1495df4] | 1053 | } |
---|
| 1054 | |
---|
| 1055 | |
---|
| 1056 | |
---|
| 1057 | |
---|
| 1058 | |
---|
| 1059 | |
---|
| 1060 | CSpecialPairMultiplier::CSpecialPairMultiplier(ring r, int i, int j): |
---|
| 1061 | CMultiplier<int>(r), m_i(i), m_j(j) |
---|
| 1062 | { |
---|
[fea494] | 1063 | #if OUTPUT |
---|
[f78891] | 1064 | Print("CSpecialPairMultiplier::CSpecialPairMultiplier(ring, i: %d, j: %d)!", i, j); |
---|
| 1065 | PrintLn(); |
---|
| 1066 | #endif |
---|
[fea494] | 1067 | |
---|
[1495df4] | 1068 | assume(i < j); |
---|
| 1069 | assume(i > 0); |
---|
| 1070 | assume(j <= NVars()); |
---|
| 1071 | } |
---|
| 1072 | |
---|
| 1073 | |
---|
[f78891] | 1074 | CSpecialPairMultiplier::~CSpecialPairMultiplier() |
---|
| 1075 | { |
---|
[fea494] | 1076 | #if OUTPUT |
---|
[a610ee] | 1077 | PrintS("CSpecialPairMultiplier::~CSpecialPairMultiplier()!"); |
---|
[f78891] | 1078 | PrintLn(); |
---|
| 1079 | #endif |
---|
| 1080 | } |
---|
| 1081 | |
---|
| 1082 | |
---|
| 1083 | |
---|
[1495df4] | 1084 | // Monom * Exponent |
---|
| 1085 | poly CSpecialPairMultiplier::MultiplyME(const poly pMonom, const CExponent expRight) |
---|
| 1086 | { |
---|
[fea494] | 1087 | #if OUTPUT |
---|
| 1088 | Print("CSpecialPairMultiplier::MultiplyME(monom, var(%d)^{%d})!", GetI(), expRight); |
---|
[f78891] | 1089 | PrintLn(); |
---|
| 1090 | PrintS("Monom: "); p_Write(pMonom, GetBasering()); |
---|
| 1091 | #endif |
---|
[fea494] | 1092 | |
---|
[1495df4] | 1093 | return MultiplyEE(p_GetExp(pMonom, GetJ(), GetBasering()), expRight); |
---|
| 1094 | } |
---|
| 1095 | |
---|
| 1096 | // Exponent * Monom |
---|
| 1097 | poly CSpecialPairMultiplier::MultiplyEM(const CExponent expLeft, const poly pMonom) |
---|
| 1098 | { |
---|
[fea494] | 1099 | #if OUTPUT |
---|
| 1100 | Print("CSpecialPairMultiplier::MultiplyEM(var(%d)^{%d}, monom)!", GetJ(), expLeft); |
---|
[f78891] | 1101 | PrintLn(); |
---|
| 1102 | PrintS("Monom: "); p_Write(pMonom, GetBasering()); |
---|
| 1103 | #endif |
---|
| 1104 | |
---|
[1495df4] | 1105 | return MultiplyEE(expLeft, p_GetExp(pMonom, GetI(), GetBasering())); |
---|
| 1106 | } |
---|
[35564a5] | 1107 | |
---|
| 1108 | template class CMultiplier<CPower>; |
---|
| 1109 | template class CMultiplier<int>; |
---|
| 1110 | template class CMultiplier<spolyrec*>; |
---|
| 1111 | |
---|
| 1112 | |
---|
[6e05dc] | 1113 | #endif |
---|