Changeset a30a39a in git


Ignore:
Timestamp:
Dec 2, 2010, 4:53:23 PM (12 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a657104b677b4c461d018cbf3204d72d34ad66a9')
Children:
852d4b70bcea05af98462b8e106e5659ea831e1b
Parents:
014b65b05f3dcc53c2482f7290e78a289930ae54
git-author:
Hans Schoenemann <hannes@mathematik.uni-kl.de>2010-12-02 16:53:23+01:00
git-committer:
Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 11:57:46+01:00
Message:
code cleanup: pGetMaxPower, pDivByMonom, pCancelPolyByMonom
Location:
libpolys/polys
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libpolys/polys/monomials/p_polys.cc

    r014b65 ra30a39a  
    24642464}
    24652465
    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 static 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 static 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 
    25772466/*2
    25782467*tests if p is homogeneous with respect to the actual weigths
  • libpolys/polys/monomials/p_polys.h

    r014b65 ra30a39a  
    310310// homogenizes p by multiplying certain powers of the varnum-th variable
    311311poly      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);
     312
    315313BOOLEAN   p_IsHomogeneous (poly p, const ring r);
    316314
  • libpolys/polys/polys.h

    r014b65 ra30a39a  
    291291// #define   pDehomogen(p1,p2,n) p_Dehomgen(p1,p2,n,currRing)
    292292// #define   pIsHomogen(p)       p_IsHomggen(p,currRing)
     293#define   pIsHomogen(p)       p_IsHomogen(p,currRing)
    293294
    294295/*BOOLEAN   pVectorHasUnitM(poly p, int * k);*/
Note: See TracChangeset for help on using the changeset viewer.