Changeset 8e89a3 in git
- Timestamp:
- Nov 29, 2021, 2:48:20 PM (2 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- eccae75d9df69c8235bdc90b5a36a2161eb0654d
- Parents:
- b9ded9215c1f31f52c684d1560787b9c150d904e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
factory/cf_chinese.cc
rb9ded9 r8e89a3 202 202 CanonicalForm Farey ( const CanonicalForm & f, const CanonicalForm & q ) 203 203 { 204 205 206 207 208 209 204 int is_rat=isOn(SW_RATIONAL); 205 Off(SW_RATIONAL); 206 Variable x = f.mvar(); 207 CanonicalForm result = 0; 208 CanonicalForm c; 209 CFIterator i; 210 210 #ifdef HAVE_FLINT 211 212 213 214 215 216 217 211 fmpz_t FLINTq; 212 fmpz_init(FLINTq); 213 convertCF2initFmpz(FLINTq,q); 214 fmpz_t FLINTc; 215 fmpz_init(FLINTc); 216 fmpq_t FLINTres; 217 fmpq_init(FLINTres); 218 218 #elif defined(HAVE_NTL) 219 220 221 219 ZZ NTLq= convertFacCF2NTLZZ (q); 220 ZZ bound; 221 SqrRoot (bound, NTLq/2); 222 222 #else 223 factoryError("NTL/FLINT missing:Farey"); 224 #endif 225 for ( i = f; i.hasTerms(); i++ ) 223 factoryError("NTL/FLINT missing:Farey"); 224 #endif 225 for ( i = f; i.hasTerms(); i++ ) 226 { 227 c = i.coeff(); 228 if ( c.inCoeffDomain()) 226 229 { 227 c = i.coeff(); 228 if ( c.inCoeffDomain()) 230 #ifdef HAVE_FLINT 231 if (c.inZ()) 232 { 233 convertCF2initFmpz(FLINTc,c); 234 fmpq_reconstruct_fmpz(FLINTres,FLINTc,FLINTq); 235 result += power (x, i.exp())*(convertFmpq2CF(FLINTres)); 236 } 237 #elif defined(HAVE_NTL) 238 if (c.inZ()) 239 { 240 ZZ NTLc= convertFacCF2NTLZZ (c); 241 bool lessZero= (sign (NTLc) == -1); 242 if (lessZero) 243 NTL::negate (NTLc, NTLc); 244 ZZ NTLnum, NTLden; 245 if (ReconstructRational (NTLnum, NTLden, NTLc, NTLq, bound, bound)) 229 246 { 247 if (lessZero) 248 NTL::negate (NTLnum, NTLnum); 249 CanonicalForm num= convertNTLZZX2CF (to_ZZX (NTLnum), Variable (1)); 250 CanonicalForm den= convertNTLZZX2CF (to_ZZX (NTLden), Variable (1)); 251 On (SW_RATIONAL); 252 result += power (x, i.exp())*(num/den); 253 Off (SW_RATIONAL); 254 } 255 } 256 #else 257 if (c.inZ()) 258 result += power (x, i.exp()) * Farey_n(c,q); 259 #endif 260 else 261 result += power( x, i.exp() ) * Farey(c,q); 262 } 263 else 264 result += power( x, i.exp() ) * Farey(c,q); 265 } 266 if (is_rat) On(SW_RATIONAL); 230 267 #ifdef HAVE_FLINT 231 if (c.inZ()) 232 { 233 convertCF2initFmpz(FLINTc,c); 234 fmpq_reconstruct_fmpz(FLINTres,FLINTc,FLINTq); 235 result += power (x, i.exp())*(convertFmpq2CF(FLINTres)); 236 } 237 #elif defined(HAVE_NTL) 238 if (c.inZ()) 239 { 240 ZZ NTLc= convertFacCF2NTLZZ (c); 241 bool lessZero= (sign (NTLc) == -1); 242 if (lessZero) 243 NTL::negate (NTLc, NTLc); 244 ZZ NTLnum, NTLden; 245 if (ReconstructRational (NTLnum, NTLden, NTLc, NTLq, bound, bound)) 246 { 247 if (lessZero) 248 NTL::negate (NTLnum, NTLnum); 249 CanonicalForm num= convertNTLZZX2CF (to_ZZX (NTLnum), Variable (1)); 250 CanonicalForm den= convertNTLZZX2CF (to_ZZX (NTLden), Variable (1)); 251 On (SW_RATIONAL); 252 result += power (x, i.exp())*(num/den); 253 Off (SW_RATIONAL); 254 } 255 } 256 #else 257 if (c.inZ()) 258 result += power (x, i.exp()) * Farey_n(c,q); 259 #endif 260 else 261 result += power( x, i.exp() ) * Farey(c,q); 262 } 263 else 264 result += power( x, i.exp() ) * Farey(c,q); 265 } 266 if (is_rat) On(SW_RATIONAL); 267 #ifdef HAVE_FLINT 268 fmpq_clear(FLINTres); 269 fmpz_clear(FLINTc); 270 fmpz_clear(FLINTq); 271 #endif 272 return result; 268 fmpq_clear(FLINTres); 269 fmpz_clear(FLINTc); 270 fmpz_clear(FLINTq); 271 #endif 272 return result; 273 273 } 274 274
Note: See TracChangeset
for help on using the changeset viewer.