Changeset a8e8b9 in git for factory/algext.cc


Ignore:
Timestamp:
May 31, 2011, 5:29:48 PM (13 years ago)
Author:
Martin Lee <martinlee84@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
d80a1affe5140fcac28532ccf3a3ad97b41ee6ee
Parents:
7d1c995f987c51bad98f33e83e328a16ded060ec
Message:
added division with remainder


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

Legend:

Unmodified
Added
Removed
  • factory/algext.cc

    r7d1c995 ra8e8b9  
    3434    if(f.degree() < M.degree())
    3535      return f;
    36     CanonicalForm tmp = f;
    37     do
    38       tmp -= lc(tmp)*M*power(M.mvar(),tmp.degree()-M.degree());
    39     while(tmp.degree() >= M.degree());
     36    CanonicalForm tmp = mod (f, M);
    4037    return tmp;
    4138  }
     
    6966}
    7067
     68void tryDivrem (const CanonicalForm& F, const CanonicalForm& G, CanonicalForm& Q,
     69                CanonicalForm& R, CanonicalForm& inv, const CanonicalForm& mipo,
     70                bool& fail)
     71{
     72  if (F.inCoeffDomain())
     73  {
     74    Q= 0;
     75    R= F;
     76    return;
     77  }
     78
     79  CanonicalForm A, B;
     80  Variable x= F.mvar();
     81  A= F;
     82  B= G;
     83  int degA= degree (A, x);
     84  int degB= degree (B, x);
     85
     86  if (degA < degB)
     87  {
     88    R= A;
     89    Q= 0;
     90    return;
     91  }
     92
     93  tryInvert (Lc (B), mipo, inv, fail);
     94  if (fail)
     95    return;
     96
     97  R= A;
     98  Q= 0;
     99  CanonicalForm Qi;
     100  for (int i= degA -degB; i >= 0; i--)
     101  {
     102    if (degree (R, x) == i + degB)
     103    {
     104      Qi= Lc (R)*inv*power (x, i);
     105      Qi= reduce (Qi, mipo);
     106      R -= Qi*B;
     107      R= reduce (R, mipo);
     108      Q += Qi;
     109    }
     110  }
     111}
     112
    71113void tryEuclid( const CanonicalForm & A, const CanonicalForm & B, const CanonicalForm & M, CanonicalForm & result, bool & fail )
    72114{
     
    107149  }
    108150  Variable x = P.mvar();
    109   CanonicalForm rem;
     151  CanonicalForm rem, Q;
    110152  // here: degree(P) >= degree(result)
    111153  while(true)
    112154  {
    113     tryInvert( Lc(result), M, inv, fail );
    114     if(fail)
    115       return;
    116     // here: Lc(result) is invertible modulo M
    117     rem = reduce( P - Lc(P)*inv*result*power( x, P.degree(x)-result.degree(x) ), M );
     155    tryDivrem (P, result, Q, rem, inv, M, fail);
     156    if (fail)
     157      return;
    118158    if( rem.isZero() )
    119159    {
Note: See TracChangeset for help on using the changeset viewer.