Changeset 56c5ce7 in git


Ignore:
Timestamp:
Oct 16, 2007, 5:49:49 PM (17 years ago)
Author:
Hans Schönemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
765143c771865be37b60999074fbbe5d4df511e3
Parents:
f48c17b84a3f24065be82667d6289cbceb45dc53
Message:
SAGE: remove alg content in myfitting


git-svn-id: file:///usr/local/Singular/svn/trunk@10339 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfac/charset/csutil.cc

    rf48c17 r56c5ce7  
    22////////////////////////////////////////////////////////////
    33// emacs edit mode for this file is -*- C++ -*-
    4 static char * rcsid = "$Id: csutil.cc,v 1.14 2007-05-15 14:46:48 Singular Exp $";
     4static char * rcsid = "$Id: csutil.cc,v 1.15 2007-10-16 15:49:49 Singular Exp $";
    55/////////////////////////////////////////////////////////////
    66// FACTORY - Includes
     
    2424  Variable vf = f.mvar(), vg = g.mvar();
    2525
    26   if ( f.inCoeffDomain() ) {
     26  if ( f.inCoeffDomain() )
     27  {
    2728    if ( g.inCoeffDomain() ) ind= 1;
    2829    return true;//( vg > vf );
     
    3031  else if ( g.inCoeffDomain() ) return false;
    3132  else if ( vf < vg ) return true;
    32   else if ( vf == vg ) {
     33  else if ( vf == vg )
     34  {
    3335    df = degree( f ); dg = degree( g );
    3436    if ( df < dg ) return true;
     
    4749  if ( ! i.hasItem() )        return f;
    4850  f = i.getItem(); ++i;
    49   while ( i.hasItem() ) {
     51  while ( i.hasItem() )
     52  {
    5053    //CERR << "comparing " << f << "  and " << i.getItem()
    5154    // << " == " << lowerRank( i.getItem(), f, ind ) << "\n";
    52     if ( lowerRank( i.getItem(), f, ind ) ) {
    53       if ( ind ){
     55    if ( lowerRank( i.getItem(), f, ind ) )
     56    {
     57      if ( ind )
     58      {
    5459        CFList Itemlist= get_Terms(i.getItem());
    5560        CFList Flist= get_Terms(f);
     
    6166        ind=0;
    6267      }
    63       else{
     68      else
     69      {
    6470        f = i.getItem();
    6571      }
     
    105111
    106112CanonicalForm
    107 Prem ( const CanonicalForm &f, const CanonicalForm &g ){
     113Prem ( const CanonicalForm &f, const CanonicalForm &g )
     114{
    108115  CanonicalForm ff, gg, l, test, lu, lv, t, retvalue;
    109116  int df, dg;
     
    112119
    113120  if ( (vf = f.mvar()) < (vg = g.mvar()) ) return f;
    114   else {
    115     if ( vf == vg ) {
     121  else
     122  {
     123    if ( vf == vg )
     124    {
    116125      ff = f; gg = g;
    117126      reord = false;
    118127      v = vg;
    119128    }
    120     else {
     129    else
     130    {
    121131      v = Variable(level(f.mvar()) + 1);
    122132      ff = swapvar(f,vg,v);
     
    128138    if (dg <= df) {l=LC(gg); gg = gg -LC(gg)*power(v,dg);}
    129139    else { l = 1; }
    130     while ( ( dg <= df  ) && ( ff != ff.genZero()) ){
     140    while ( ( dg <= df  ) && ( ff != ff.genZero()) )
     141    {
    131142      // CERR << "Start gcd..." << "\n";
    132143      test = gcd(l,LC(ff));
     
    139150      df = degree( ff, v );
    140151    }
    141     if ( reord ) {
    142      retvalue= swapvar( ff, vg, v );
    143     }
    144     else {
    145      retvalue= ff;
     152    if ( reord )
     153    {
     154      retvalue= swapvar( ff, vg, v );
     155    }
     156    else
     157    {
     158      retvalue= ff;
    146159    }
    147160    return retvalue;
     
    150163
    151164static CanonicalForm
    152 Sprem ( const CanonicalForm &f, const CanonicalForm &g, CanonicalForm & m, CanonicalForm & q ){
     165Sprem ( const CanonicalForm &f, const CanonicalForm &g, CanonicalForm & m, CanonicalForm & q )
     166{
    153167  CanonicalForm ff, gg, l, test, retvalue;
    154168  int df, dg,n;
     
    156170  Variable vf, vg, v;
    157171
    158   if ( (vf = f.mvar()) < (vg = g.mvar()) ) {
     172  if ( (vf = f.mvar()) < (vg = g.mvar()) )
     173  {
    159174    m=CanonicalForm(0); q=CanonicalForm(0);
    160175    return f;
    161176  }
    162   else {
    163     if ( vf == vg ) {
     177  else
     178  {
     179    if ( vf == vg )
     180    {
    164181      ff = f; gg = g;
    165182      reord = false;
    166183      v = vg; // == x
    167184    }
    168     else {
     185    else
     186    {
    169187      v = Variable(level(f.mvar()) + 1);
    170188      ff = swapvar(f,vg,v); // == r
     
    177195    else { l = 1; }
    178196    n= 0;
    179     while ( ( dg <= df  ) && ( ff != ff.genZero()) ){
     197    while ( ( dg <= df  ) && ( ff != ff.genZero()) )
     198    {
    180199      test= power(v,df-dg) * gg * LC(ff);
    181200      if ( df == 0 ){ff= ff.genZero();}
     
    185204      n++;
    186205    }
    187     if ( reord ) {
    188      retvalue= swapvar( ff, vg, v );
    189     }
    190     else {
    191      retvalue= ff;
     206    if ( reord )
     207    {
     208      retvalue= swapvar( ff, vg, v );
     209    }
     210    else
     211    {
     212      retvalue= ff;
    192213    }
    193214    m= power(l,n);
    194215    if ( fdivides(g,m*f-retvalue) )
    195216      q= (m*f-retvalue)/g;
    196     else {
     217    else
    197218      q= CanonicalForm(0);
    198     }
    199219    return retvalue;
    200220  }
     
    210230  if (f.inCoeffDomain())
    211231  {
    212     bool b=false;         
    213     if (!isOn(SW_RATIONAL)) { b=true;On(SW_RATIONAL); }
     232    bool b=!isOn(SW_RATIONAL);
     233    On(SW_RATIONAL);
    214234    q=ff/f;
    215235    if (b) Off(SW_RATIONAL);
    216   } 
     236  }
    217237  else
    218238    r= Sprem(ff,f,m,q); //result in q, ignore r,m
     
    224244}
    225245
     246// This function allows as to be empty; in that case, it is equivalent
     247// to the previous version (treating no variables as algebraic).
    226248static CanonicalForm
    227 myfitting( const CanonicalForm &f )
     249myfitting( const CanonicalForm &f, const CFList &as )
    228250{
    229251 CanonicalForm rem=f;
     
    241263//      CERR << "temp/lc(temp)= " << temp/lc(temp) << "\n";
    242264//      CERR << "num(rem/lc(rem))= " << num(rem/lc(rem)) << "\n";
     265
     266     // If as is of length 1, and its polynomial is level 1, then
     267     // we treat the first variable as algebraic and invert the leading
     268     // coefficient where this variable is part of the coefficient domain.
     269
     270     if (as.length() == 1 && level(as.getFirst()) == 1)
     271     {
     272       CanonicalForm lcoeff = temp;
     273       while (level(lcoeff) > 1)
     274       {
     275         lcoeff = LC(lcoeff);
     276       }
     277       // out_cf("myfitting: lcoeff = ", lcoeff, "\n");
     278
     279       CanonicalForm p = as.getFirst();
     280       // out_cf("myfitting: p = ", p, "\n");
     281
     282       CanonicalForm unused, inverse;
     283
     284       extgcd(lcoeff, p, inverse, unused);
     285       // out_cf("myfitting: inverse = ", inverse, "\n");
     286
     287       // This may leave temp with non-integral coefficients,
     288       // which will be cleaned up below.
     289       temp = temp * inverse;
     290       // out_cf("myfitting: temp = ", temp, "\n");
     291     }
     292
    243293     temp= bCommonDen(temp/lc(temp))*(temp/lc(temp));
    244294     Off(SW_RATIONAL);
     
    252302
    253303CanonicalForm
    254 Prem( const CanonicalForm &f, const CFList &L ){
     304Prem( const CanonicalForm &f, const CFList &L )
     305{
    255306  CanonicalForm rem = f;
    256307  CFListIterator i = L;
    257   for ( i.lastItem(); i.hasItem(); i-- ){
    258 //CERR << "   PREM: Prem(" << rem << "," ;
     308  for ( i.lastItem(); i.hasItem(); i-- )
     309  {
     310    //CERR << "   PREM: Prem(" << rem << "," ;
    259311    rem = Prem( rem, i.getItem() );
    260 //CERR << "   PREM: Prem(" << rem << "," << i.getItem() << ")  = " << rem << "\n";
    261   }
    262   return myfitting(rem);
     312    //CERR << "   PREM: Prem(" << rem << "," << i.getItem() << ")  = " << rem << "\n";
     313  }
     314  return myfitting(rem, CFList());
     315}
     316
     317CanonicalForm
     318Prem( const CanonicalForm &f, const CFList &L, const CFList &as )
     319{
     320  CanonicalForm rem = f;
     321  CFListIterator i = L;
     322  for ( i.lastItem(); i.hasItem(); i-- )
     323  {
     324    //CERR << "   PREM: Prem(" << rem << "," ;
     325    rem = Prem( rem, i.getItem() );
     326    //CERR << "   PREM: Prem(" << rem << "," << i.getItem() << ")  = " << rem << "\n";
     327  }
     328  return myfitting(rem, as);
    263329}
    264330
    265331CFList
    266 Prem( const CFList &AS, const CFList &L ){
     332Prem( const CFList &AS, const CFList &L )
     333{
    267334  CFList Output;
    268335
     
    322389
    323390  for ( CFIterator j=init; j.hasTerms(); j++ )
    324     if (!(j.coeff().isOne()) ) count += 1;
     391    if (!(j.coeff().isOne()) ) count++;
    325392  //  if ( init != 1 ){
    326393  //  CERR << "nopower: f is " << init << "\n";
     
    368435// Remember.FS2 contains all factors removed before
    369436void
    370 removefactor( CanonicalForm & r , PremForm & Remembern){
     437removefactor( CanonicalForm & r , PremForm & Remembern)
     438{
    371439  int test;
    372440  CanonicalForm a,b,testelem;
     
    438506      elem = j.getItem().factor();
    439507      if ( getNumVars(elem) > 0 )
    440         qs= Union(qs, CFList(myfitting(elem)));
     508        qs= Union(qs, CFList(myfitting(elem, CFList())));
    441509    }
    442510  }
     
    455523    leadcoeff = LC(f,lvar(f));
    456524    //    if ( leadcoeff != 0 )
    457     return myfitting(leadcoeff); //num(leadcoeff/lc(leadcoeff));
     525    return myfitting(leadcoeff, CFList()); //num(leadcoeff/lc(leadcoeff));
    458526    //    else return leadcoeff;
    459527  }
     
    481549// with certain repeated factors cancelled
    482550CFList
    483 initalset1(const CFList & Cset){
     551initalset1(const CFList & Cset)
     552{
    484553  CFList temp;
    485554  CFList initals;
    486555  CanonicalForm init;
    487556
    488   for ( CFListIterator i = Cset ; i.hasItem(); i++ ){
     557  for ( CFListIterator i = Cset ; i.hasItem(); i++ )
     558  {
    489559    initals= nopower( inital(i.getItem()) );
    490560    //    init= inital(i.getItem());
    491     for ( CFListIterator j = initals; j.hasItem(); j++){
     561    for ( CFListIterator j = initals; j.hasItem(); j++)
     562    {
    492563      init = j.getItem();
    493564      if ( cls(init) > 0 )
     
    502573// with certain repeated factors cancelled
    503574CFList
    504 initalset2(const CFList & Cset, const CanonicalForm & reducible){
     575initalset2(const CFList & Cset, const CanonicalForm & reducible)
     576{
    505577  CFList temp;
    506578  CFList initals;
     
    508580  int clsred = cls(reducible);
    509581
    510   for ( CFListIterator i = Cset ; i.hasItem(); i++ ){
     582  for ( CFListIterator i = Cset ; i.hasItem(); i++ )
     583  {
    511584    init = i.getItem();
    512     if ( cls(init) < clsred ){
     585    if ( cls(init) < clsred )
     586    {
    513587      initals= nopower( inital(init) );
    514588      //    init= inital(i.getItem());
    515       for ( CFListIterator j = initals; j.hasItem(); j++){
     589      for ( CFListIterator j = initals; j.hasItem(); j++)
     590      {
    516591        init = j.getItem();
    517592        if ( cls(init) > 0 )
     
    550625// examine the irreducibility of as for IrrCharSeries
    551626int
    552 irreducible( const CFList & AS){
     627irreducible( const CFList & AS)
     628{
    553629// AS is given by AS = { A1, A2, .. Ar }, d_i = degree(Ai)
    554630
    555631  DEBOUTMSG(CERR, rcsid);
    556632// 1) we test: if d_i > 1, d_j =1 for all j<>i, then AS is irreducible.
    557   bool deg1=1;
    558   for ( CFListIterator i = AS ; i.hasItem(); i++ ){
    559     if ( degree(i.getItem()) > 1 ){
     633  bool deg1=true;
     634  for ( CFListIterator i = AS ; i.hasItem(); i++ )
     635  {
     636    if ( degree(i.getItem()) > 1 )
     637    {
    560638      if ( deg1 ) deg1=0;
    561639      else return 0; // found 2nd poly with deg > 1
     
    568646// select an item from PS for irras
    569647CFList
    570 select( const ListCFList & PS){
    571 
     648select( const ListCFList & PS)
     649{
    572650  return PS.getFirst();
    573651}
     
    575653// divide list ppi in elems having length <= and > length
    576654void
    577 select( const ListCFList & ppi, int length, ListCFList & ppi1, ListCFList & ppi2){
     655select( const ListCFList & ppi, int length, ListCFList & ppi1, ListCFList & ppi2)
     656{
    578657  CFList elem;
    579   for ( ListCFListIterator i=ppi ; i.hasItem(); i++ ){
     658  for ( ListCFListIterator i=ppi ; i.hasItem(); i++ )
     659  {
    580660    elem = i.getItem();
    581661    if ( ! elem.isEmpty() )
     
    591671// is f in F ?
    592672static bool
    593 member( const CanonicalForm &f, const CFList &F){
    594 
     673member( const CanonicalForm &f, const CFList &F)
     674{
    595675  for ( CFListIterator i=F; i.hasItem(); i++ )
    596676    if ( i.getItem() == f ) return 1;
     
    600680// are list A and B the same?
    601681bool
    602 same( const CFList &A, const CFList &B ){
     682same( const CFList &A, const CFList &B )
     683{
    603684  CFListIterator i;
    604685
     
    613694// is List cs contained in List of lists pi?
    614695bool
    615 member( const CFList & cs, const ListCFList & pi ){
     696member( const CFList & cs, const ListCFList & pi )
     697{
    616698  ListCFListIterator i;
    617699  CFList elem;
    618700
    619   for ( i=pi; i.hasItem(); i++){
     701  for ( i=pi; i.hasItem(); i++)
     702  {
    620703    elem = i.getItem();
    621704    if ( same(cs,elem) ) return 1;
     
    626709// is PS a subset of Cset ?
    627710bool
    628 subset( const CFList &PS, const CFList &Cset ){
    629 
     711subset( const CFList &PS, const CFList &Cset )
     712{
    630713  //  CERR << "subset: called with: " << PS << "   " << Cset << "\n";
    631714  for ( CFListIterator i=PS; i.hasItem(); i++ )
    632     if ( ! member(i.getItem(), Cset) ) {
     715    if ( ! member(i.getItem(), Cset) )
     716    {
    633717      //      CERR << "subset: " << i.getItem() << "  is not a member of " << Cset << "\n";
    634718      return 0;
     
    639723// Union of two List of Lists
    640724ListCFList
    641 MyUnion( const ListCFList & a, const ListCFList &b ){
     725MyUnion( const ListCFList & a, const ListCFList &b )
     726{
    642727  ListCFList output;
    643728  ListCFListIterator i;
    644729  CFList elem;
    645730
    646   for ( i = a ; i.hasItem(); i++ ){
     731  for ( i = a ; i.hasItem(); i++ )
     732  {
    647733    elem=i.getItem();
    648     // if ( ! member(elem,output) ){
    649     if ( (! elem.isEmpty()) && ( ! member(elem,output)) ){
     734    if ( (! elem.isEmpty()) && ( ! member(elem,output)) )
     735    {
    650736      output.append(elem);
    651737    }
    652738  }
    653739
    654   for ( i = b ; i.hasItem(); i++ ){
     740  for ( i = b ; i.hasItem(); i++ )
     741  {
    655742    elem=i.getItem();
    656     // if ( ! member(elem,output) ){
    657     if ( (! elem.isEmpty()) && ( ! member(elem,output)) ){
     743    if ( (! elem.isEmpty()) && ( ! member(elem,output)) )
     744    {
    658745      output.append(elem);
    659746    }
     
    664751//if list b is member of the list of lists remove b and return the rest
    665752ListCFList
    666 MyDifference( const ListCFList & a, const CFList &b){
     753MyDifference( const ListCFList & a, const CFList &b)
     754{
    667755  ListCFList output;
    668756  ListCFListIterator i;
    669757  CFList elem;
    670758
    671   for ( i = a ; i.hasItem(); i++ ){
     759  for ( i = a ; i.hasItem(); i++ )
     760  {
    672761    elem=i.getItem();
    673     if ( (! elem.isEmpty()) && ( ! same(elem,b)) ){
     762    if ( (! elem.isEmpty()) && ( ! same(elem,b)) )
     763    {
    674764      output.append(elem);
    675765    }
     
    680770// remove all elements of b from list of lists a and return the rest
    681771ListCFList
    682 Minus( const ListCFList & a, const ListCFList & b){
     772Minus( const ListCFList & a, const ListCFList & b)
     773{
    683774  ListCFList output=a;
    684775
     
    800891  //g/=c_gcd;
    801892  if (!c_gcd.isOne())
    802   {       
     893  {
    803894    f=divide(f,c_gcd,as);
    804895    g=divide(g,c_gcd,as);
     
    825916          if (f_gcd.inBaseDomain()) break;
    826917          i++;
    827         } 
    828         //out_cf("g=0 -> f:",f,"\n");
    829         //out_cf("f_gcd:",f_gcd,"\n");
    830         //out_cf("c_gcd:",c_gcd,"\n");
    831         //f/=f_gcd; 
    832         f=divide(f,f_gcd,as);
    833         //out_cf("f/f_gcd:",f,"\n");
    834         f*=c_gcd;
    835         //out_cf("f*c_gcd:",f,"\n");
     918        }
     919        //out_cf("g=0 -> f:",f,"\n");
     920        //out_cf("f_gcd:",f_gcd,"\n");
     921        //out_cf("c_gcd:",c_gcd,"\n");
     922        //f/=f_gcd;
     923        f=divide(f,f_gcd,as);
     924        //out_cf("f/f_gcd:",f,"\n");
     925        f*=c_gcd;
     926        //out_cf("f*c_gcd:",f,"\n");
    836927        CanonicalForm r_lc=alg_lc(f);
    837         //out_cf("r_lc:",r_lc,"\n");
    838         //f/=r_lc;
    839         f=divide(f,r_lc,as);
    840         //out_cf(" -> gcd:",f,"\n");
     928        //out_cf("r_lc:",r_lc,"\n");
     929        //f/=r_lc;
     930        f=divide(f,r_lc,as);
     931        //out_cf(" -> gcd:",f,"\n");
    841932        return f;
    842933      }
    843       else { //printf("c\n"); 
    844         return c_gcd;}
    845     } 
    846     else if (g.level()==f.level()) r=Prem(f,gg);
     934      else { //printf("c\n");
     935        return c_gcd;}
     936    }
     937    else if (g.level()==f.level()) r=Prem(f,gg,as);
    847938    else
    848939    {
     
    897988/*
    898989$Log: not supported by cvs2svn $
     990Revision 1.14  2007/05/15 14:46:48  Singular
     991*hannes: factorize in Zp(a)[x...]
     992
    899993Revision 1.13  2006/06/19 13:37:47  Singular
    900994*hannes: more CS renamed
Note: See TracChangeset for help on using the changeset viewer.