- Timestamp:
- Nov 10, 2010, 2:37:03 PM (13 years ago)
- Branches:
- (u'spielwiese', '5b153614cbc72bfa198d75b1e9e33dab2645d9fe')
- Children:
- 7a452a7797022a5eead0baf7b8b21bb39014afaa
- Parents:
- fbf8a60b7b930de2742fc70ec47fc8300a70db5c
- git-author:
- Hans Schoenemann <hannes@mathematik.uni-kl.de>2010-11-10 14:37:03+01:00
- git-committer:
- Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 11:55:37+01:00
- Location:
- polys
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
polys/monomials/p_polys.cc
rfbf8a6 r4e8ef90 2414 2414 } 2415 2415 2416 /*2 2417 *make p homogeneous by multiplying the monomials by powers of x_varnum 2418 *assume: deg(var(varnum))==1 2419 */ 2420 poly p_Homogen (poly p, int varnum, const ring r) 2421 { 2422 pFDegProc deg; 2423 if (pLexOrder && (r->order[0]==ringorder_lp)) 2424 deg=p_Totaldegree; 2425 else 2426 deg=pFDeg; 2427 2428 poly q=NULL, qn; 2429 int o,ii; 2430 sBucket_pt bp; 2431 2432 if (p!=NULL) 2433 { 2434 if ((varnum < 1) || (varnum > rVar(r))) 2435 { 2436 return NULL; 2437 } 2438 o=deg(p,r); 2439 q=pNext(p); 2440 while (q != NULL) 2441 { 2442 ii=deg(q,r); 2443 if (ii>o) o=ii; 2444 pIter(q); 2445 } 2446 q = p_Copy(p,r); 2447 bp = sBucketCreate(r); 2448 while (q != NULL) 2449 { 2450 ii = o-deg(q,r); 2451 if (ii!=0) 2452 { 2453 p_AddExp(q,varnum, (long)ii,r); 2454 p_Setm(q,r); 2455 } 2456 qn = pNext(q); 2457 pNext(q) = NULL; 2458 sBucket_Add_p(bp, q, 1); 2459 q = qn; 2460 } 2461 sBucketDestroyAdd(bp, &q, &ii); 2462 } 2463 return q; 2464 } 2465 2466 /*4 2467 *Returns the exponent of the maximal power of the leading monomial of 2468 *p2 in that of p1 2469 */ 2470 static int p_GetMaxPower (poly p1,poly p2, const ring r) 2471 { 2472 int i,k,res = MAX_INT; /*a very large integer*/ 2473 2474 if (p1 == NULL) return 0; 2475 for (i=rVar(r); i>0; i--) 2476 { 2477 if ( pGetExp(p2,i) != 0) 2478 { 2479 k = p_GetExp(p1,i,r) / p_GetExp(p2,i,r); 2480 if (k < res) res = k; 2481 } 2482 } 2483 return res; 2484 } 2485 2486 /*2 2487 *returns the leading monomial of p1 divided by the maximal power of that 2488 *of p2 2489 */ 2490 poly p_DivByMonom (poly p1,poly p2, const ring r) 2491 { 2492 int k, i; 2493 2494 if (p1 == NULL) return NULL; 2495 k = p_GetMaxPower(p1,p2,r); 2496 if (k == 0) 2497 return p_Head(p1,r); 2498 else 2499 { 2500 number n; 2501 poly p = pInit(r); 2502 2503 p->next = NULL; 2504 for (i=rVar(r);i>0; i--) 2505 { 2506 p_SetExp(p,i, p_GetExp(p1,i,r)-k* p_GetExp(p2,i,r),r); 2507 } 2508 n_Power(p2->coef,k,&n,r->cf); 2509 pSetCoeff0(p,n_Div(p1->coef,n,r->cf)); 2510 n_Delete(&n,r->cf); 2511 p_Setm(p,r); 2512 return p; 2513 } 2514 } 2515 2516 /*2 2517 *Returns as i-th entry of P the coefficient of the (i-1) power of 2518 *the leading monomial of p2 in p1 2519 */ 2520 void p_CancelPolyByMonom (poly p1,poly p2,polyset * P,int * SizeOfSet, const ring r) 2521 { 2522 int maxPow; 2523 poly p,qp,Coeff; 2524 2525 if (*P == NULL) 2526 { 2527 *P = (polyset) omAlloc0(5*sizeof(poly)); 2528 *SizeOfSet = 5; 2529 } 2530 p = p_Copy(p1,r); 2531 while (p != NULL) 2532 { 2533 qp = pNext(p); 2534 pNext(p) = NULL; 2535 maxPow = p_GetMaxPower(p,p2,r); 2536 Coeff = p_DivByMonom(p,p2,r); 2537 if (maxPow > *SizeOfSet) 2538 { 2539 pEnlargeSet(P,*SizeOfSet,maxPow+1-*SizeOfSet); 2540 *SizeOfSet = maxPow+1; 2541 } 2542 (*P)[maxPow] = p_Add_q((*P)[maxPow],Coeff,r); 2543 p_Delete(&p,r); 2544 p = qp; 2545 } 2546 } 2547 /*2 2548 *replaces the maximal powers of the leading monomial of p2 in p1 by 2549 *the same powers of n, utility for dehomogenization 2550 */ 2551 poly p_Dehomogen (poly p1,poly p2,number n, const ring r) 2552 { 2553 polyset P; 2554 int SizeOfSet=5; 2555 int i; 2556 poly p; 2557 number nn; 2558 2559 P = (polyset)omAlloc0(5*sizeof(poly)); 2560 p_CancelPolyByMonom(p1,p2,&P,&SizeOfSet,r); 2561 p = P[0]; 2562 for (i=1; i<SizeOfSet; i++) 2563 { 2564 if (P[i] != NULL) 2565 { 2566 nPower(n,i,&nn); 2567 pMult_nn(P[i],nn); 2568 p = pAdd(p,P[i]); 2569 //P[i] =NULL; // for safety, may be removed later 2570 nDelete(&nn); 2571 } 2572 } 2573 omFreeSize((ADDRESS)P,SizeOfSet*sizeof(poly)); 2574 return p; 2575 } 2576 2577 /*2 2578 *tests if p is homogeneous with respect to the actual weigths 2579 */ 2580 BOOLEAN p_IsHomogeneous (poly p, const ring r) 2581 { 2582 poly qp=p; 2583 int o; 2584 2585 if ((p == NULL) || (pNext(p) == NULL)) return TRUE; 2586 pFDegProc d; 2587 if (pLexOrder && (r->order[0]==ringorder_lp)) 2588 d=p_Totaldegree; 2589 else 2590 d=pFDeg; 2591 o = d(p,currRing); 2592 do 2593 { 2594 if (d(qp,r) != o) return FALSE; 2595 pIter(qp); 2596 } 2597 while (qp != NULL); 2598 return TRUE; 2599 } 2600 2416 2601 /*************************************************************** 2417 2602 * -
polys/monomials/p_polys.h
rfbf8a6 r4e8ef90 308 308 int pSize( poly p, const ring r ); 309 309 310 // homogenizes p by multiplying certain powers of the varnum-th variable 311 poly p_Homogen (poly p, int varnum, const ring r); 312 // replaces the maximal powers of the leading monomial of p2 in p1 by 313 // the same powers of n, utility for dehomogenization 314 poly p_Dehomogen (poly p1,poly p2,number n, const ring r); 315 BOOLEAN p_IsHomogeneous (poly p, const ring r); 316 317 310 318 static inline void p_Setm(poly p, const ring r); 311 319 p_SetmProc p_GetSetmProc(ring r); -
polys/polys.h
rfbf8a6 r4e8ef90 308 308 309 309 // homogenizes p by multiplying certain powers of the varnum-th variable 310 poly pHomogen (poly p, int varnum); 310 #define pHomogen(p,varnum) p_Homogen(p,varnum,currRing) 311 311 312 312 BOOLEAN pIsHomogeneous (poly p); 313 // // replaces the maximal powers of the leading monomial of p2 in p1 by 314 // // the same powers of n, utility for dehomogenization 315 // #define pDehomogen(p1,p2,n) p_Dehomgen(p1,p2,n,currRing) 316 // #define pIsHomogen(p) p_IsHomggen(p,currRing) 313 317 314 318 poly pPermPoly (poly p, int * perm,const ring OldRing, nMapFunc nMap,
Note: See TracChangeset
for help on using the changeset viewer.