Changeset c12372 in git for factory/cf_chinese.cc
- Timestamp:
- Jul 24, 1997, 12:39:35 PM (27 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 063ebbbe875cacd2b1e4f25d7006348a5823fc8a
- Parents:
- 960f2ac0a38ea1611c75e0b2fd1764a6c0554fe1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/cf_chinese.cc
r960f2a rc12372 1 1 /* emacs edit mode for this file is -*- C++ -*- */ 2 /* $Id: cf_chinese.cc,v 1. 4 1997-07-19 08:13:16schmidt Exp $ */2 /* $Id: cf_chinese.cc,v 1.5 1997-07-24 10:39:35 schmidt Exp $ */ 3 3 4 4 //{{{ docu … … 14 14 #include "assert.h" 15 15 16 #include "cf_defs.h"17 16 #include "canonicalform.h" 18 17 … … 20 19 //{{{ docu 21 20 // 22 // chineseRemainder - (simple)integer chinese remaindering.21 // chineseRemainder - integer chinese remaindering. 23 22 // 24 // Calculate xnew such that xnew=x1 (mod q1) and xnew=x2 25 // (mod q2) and qnew = q1*q2. q1 and q2 should be integers, 26 // pairwise prime, x1 and x2 should be integers. 23 // Calculate xnew such that xnew=x1 (mod q1) and xnew=x2 (mod q2) 24 // and qnew = q1*q2. q1 and q2 should be positive integers, 25 // pairwise prime, x1 and x2 should be polynomials with integer 26 // coefficients. If x1 and x2 are polynomials with positive 27 // coefficients, the result is guaranteed to have positive 28 // coefficients, too. 27 29 // 28 30 // Note: be sure you are calculating in Z, and not in Q! 29 31 // 30 32 //}}} 31 void chineseRemainder( const CanonicalForm x1, const CanonicalForm q1, const CanonicalForm x2, const CanonicalForm q2, CanonicalForm & xnew, CanonicalForm & qnew ) 33 void 34 chineseRemainder( const CanonicalForm x1, const CanonicalForm q1, const CanonicalForm x2, const CanonicalForm q2, CanonicalForm & xnew, CanonicalForm & qnew ) 32 35 { 33 36 CanonicalForm a1, a2; 34 37 (void)iextgcd( q1, q2, a1, a2 ); 35 38 qnew = q1 * q2; 36 // xnew = mod( q1*a1*x2 + q2*a2*x1, qnew); 37 xnew = ( q1*a1*x2 + q2*a2*x1 ) % qnew; 39 xnew = mod( q1*a1*x2 + q2*a2*x1, qnew ); 38 40 } 39 41 //}}} … … 44 46 // chineseRemainder - integer chinese remaindering. 45 47 // 46 // Calculate xnew such that xnew=x[i] (mod q[i]). q[i] should be 47 // integers, pairwise prime. x[i] should be integers. 48 // Calculate xnew such that xnew=x[i] (mod q[i]) and qnew is the 49 // product of all q[i]. q[i] should be positive integers, 50 // pairwise prime. x[i] should be polynomials with integer 51 // coefficients. If all coefficients of all x[i] are positive 52 // integers, the result is guaranteed to have positive 53 // coefficients, too. 48 54 // 49 55 // Note: be sure you are calculating in Z, and not in Q! 50 56 // 51 57 //}}} 52 void chineseRemainder( const CFArray & x, const CFArray & q, CanonicalForm & xnew, CanonicalForm & qnew ) 58 void 59 chineseRemainder( const CFArray & x, const CFArray & q, CanonicalForm & xnew, CanonicalForm & qnew ) 53 60 { 54 61 ASSERT( x.min() == q.min() && x.size() == q.size(), "incompatible arrays" ); 55 62 CFArray X(x), Q(q); 56 63 int i, j, n = x.size(); 57 // we use a divide-and-conquer algorithm to reduce the number 58 // of remainderings 64 59 65 while ( n != 1 ) { 60 66 i = j = x.min();
Note: See TracChangeset
for help on using the changeset viewer.