Changeset a8e8b9 in git
- Timestamp:
- May 31, 2011, 5:29:48 PM (12 years ago)
- Branches:
- (u'spielwiese', '91fdef05f09f54b8d58d92a472e9c4a43aa4656f')
- Children:
- d80a1affe5140fcac28532ccf3a3ad97b41ee6ee
- Parents:
- 7d1c995f987c51bad98f33e83e328a16ded060ec
- Location:
- factory
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/algext.cc
r7d1c995 ra8e8b9 34 34 if(f.degree() < M.degree()) 35 35 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); 40 37 return tmp; 41 38 } … … 69 66 } 70 67 68 void 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 71 113 void tryEuclid( const CanonicalForm & A, const CanonicalForm & B, const CanonicalForm & M, CanonicalForm & result, bool & fail ) 72 114 { … … 107 149 } 108 150 Variable x = P.mvar(); 109 CanonicalForm rem ;151 CanonicalForm rem, Q; 110 152 // here: degree(P) >= degree(result) 111 153 while(true) 112 154 { 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; 118 158 if( rem.isZero() ) 119 159 { -
factory/algext.h
r7d1c995 ra8e8b9 8 8 9 9 CanonicalForm QGCD( const CanonicalForm &, const CanonicalForm & ); 10 void tryDivrem (const CanonicalForm&, const CanonicalForm&, CanonicalForm&, 11 CanonicalForm&, CanonicalForm&, const CanonicalForm&, 12 bool&); 10 13 void tryEuclid( const CanonicalForm &, const CanonicalForm &, const CanonicalForm &, CanonicalForm &, bool & ); 11 14 void tryInvert( const CanonicalForm &, const CanonicalForm &, CanonicalForm &, bool & );
Note: See TracChangeset
for help on using the changeset viewer.