Ignore:
Timestamp:
Feb 15, 2021, 6:01:06 PM (3 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', '17f1d200f27c5bd38f5dfc6e8a0879242279d1d8')
Children:
7b5b095ed2434be9e1783ac23414e01c2a75fec4
Parents:
e6f77c64ad84a4393b83a375b4207c80fe495718
Message:
add: p_Content_n
File:
1 edited

Legend:

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

    re6f77c6 r02d009  
    23372337}
    23382338
     2339void p_Content_n(poly ph, number &c,const ring r)
     2340{
     2341  if (ph==NULL)
     2342  {
     2343    c=n_Init(1,r->cf);
     2344    return;
     2345  }
     2346  const coeffs cf=r->cf;
     2347  if (pNext(ph)==NULL)
     2348  {
     2349    c=pGetCoeff(ph);
     2350    p_SetCoeff0(ph,n_Init(1,cf),r);
     2351  }
     2352  if ((cf->cfSubringGcd==ndGcd)
     2353  || (cf->cfGcd==ndGcd)) /* trivial gcd*/
     2354  {
     2355    c=n_Init(1,r->cf);
     2356    return;
     2357  }
     2358  number h;
     2359  if ((rField_is_Q(r))
     2360  || (rField_is_Q_a(r))
     2361  || (rField_is_Zp_a)(r)
     2362  || (rField_is_Z(r))
     2363  )
     2364  {
     2365    h=p_InitContent(ph,r); /* first guess of a gcd of all coeffs */
     2366  }
     2367  else
     2368  {
     2369    h=n_Copy(pGetCoeff(ph),cf);
     2370  }
     2371  poly p;
     2372  if(n_IsOne(h,cf))
     2373  {
     2374    goto content_finish;
     2375  }
     2376  p=ph;
     2377  // take the SubringGcd of all coeffs
     2378  while (p!=NULL)
     2379  {
     2380    n_Normalize(pGetCoeff(p),cf);
     2381    number d=n_SubringGcd(h,pGetCoeff(p),cf);
     2382    n_Delete(&h,cf);
     2383    h = d;
     2384    if(n_IsOne(h,cf))
     2385    {
     2386      goto content_finish;
     2387    }
     2388    pIter(p);
     2389  }
     2390  // if found<>1, divide by it
     2391  p = ph;
     2392  while (p!=NULL)
     2393  {
     2394    number d = n_ExactDiv(pGetCoeff(p),h,cf);
     2395    p_SetCoeff(p,d,r);
     2396    pIter(p);
     2397  }
     2398content_finish:
     2399  c=h;
     2400  // and last: check leading sign:
     2401  if(!n_GreaterZero(pGetCoeff(ph),r->cf))
     2402  {
     2403    c = n_InpNeg(c,r->cf);
     2404    ph = p_Neg(ph,r);
     2405  }
     2406}
     2407
    23392408#define CLEARENUMERATORS 1
    23402409
Note: See TracChangeset for help on using the changeset viewer.