#include "mterm.hh"
#include "signals.hh"
#include "ppsig.hh"
#include <assert.h>
Go to the source code of this file.
Typedefs | |
typedef map< Tree, int > | MP |
Functions | |
static int | common (int a, int b) |
return the "common quantity" of two numbers | |
mterm | gcd (const mterm &m1, const mterm &m2) |
return a mterm that is the greatest common divisor of two mterms | |
static bool | contains (int a, int b) |
We say that a "contains" b if a/b > 0. | |
static Tree | buildPowTerm (Tree f, int q) |
produce the canonical tree correspoding to a mterm | |
static void | combineMulLeft (Tree &R, Tree A) |
Combine R and A doing R = R*A or R = A. | |
static void | combineDivLeft (Tree &R, Tree A) |
Combine R and A doing R = R*A or R = A. | |
static void | combineMulDiv (Tree &M, Tree &D, Tree f, int q) |
Do M = M * f**q or D = D * f**-q. |
produce the canonical tree correspoding to a mterm
Build a power term of type f**q -> (((f.f).f)..f) with q>0
Definition at line 330 of file mterm.cpp.
References sigMul().
Referenced by combineMulDiv().
00331 { 00332 assert(f); 00333 assert(q>0); 00334 Tree r = f; 00335 for (int c=2; c<=q; c++) { r = sigMul(r,f); } 00336 assert(r); 00337 return r; 00338 }
Combine R and A doing R = R*A or R = A.
Definition at line 352 of file mterm.cpp.
References sigDiv(), and tree().
Referenced by mterm::normalizedTree().
Do M = M * f**q or D = D * f**-q.
Definition at line 361 of file mterm.cpp.
References buildPowTerm(), and combineMulLeft().
Referenced by mterm::normalizedTree().
00362 { 00363 #ifdef TRACE 00364 cerr << "combineMulDiv (" << M << "/" << D << "*" << ppsig(f)<< "**" << q << endl; 00365 #endif 00366 if (f) { 00367 if (q > 0) { 00368 combineMulLeft(M, buildPowTerm(f,q)); 00369 } else if (q < 0) { 00370 combineMulLeft(D, buildPowTerm(f,-q)); 00371 } 00372 } 00373 }
Combine R and A doing R = R*A or R = A.
Definition at line 343 of file mterm.cpp.
References sigMul().
Referenced by combineMulDiv(), and mterm::normalizedTree().
00344 { 00345 if (R && A) R = sigMul(R,A); 00346 else if (A) R = A; 00347 }
static int common | ( | int | a, | |
int | b | |||
) | [static] |
return the "common quantity" of two numbers
Definition at line 252 of file mterm.cpp.
Referenced by gcd().
00253 { 00254 if (a > 0 & b > 0) { 00255 return min(a,b); 00256 } else if (a < 0 & b < 0) { 00257 return max(a,b); 00258 } else { 00259 return 0; 00260 } 00261 }
static bool contains | ( | int | a, | |
int | b | |||
) | [static] |
We say that a "contains" b if a/b > 0.
For example 3 contains 2 and -4 contains -2, but 3 doesn't contains -2 and -3 doesn't contains 1
Definition at line 293 of file mterm.cpp.
Referenced by mterm::hasDivisor().
return a mterm that is the greatest common divisor of two mterms
Definition at line 267 of file mterm.cpp.
References common(), mterm::fCoef, mterm::fFactors, and tree().
Referenced by aterm::greatestDivisor().
00268 { 00269 //cerr << "GCD of " << m1 << " and " << m2 << endl; 00270 00271 Tree c = (m1.fCoef == m2.fCoef) ? m1.fCoef : tree(1); // common coefficient (real gcd not needed) 00272 mterm R(c); 00273 for (MP::const_iterator p1 = m1.fFactors.begin(); p1 != m1.fFactors.end(); p1++) { 00274 Tree t = p1->first; 00275 MP::const_iterator p2 = m2.fFactors.find(t); 00276 if (p2 != m2.fFactors.end()) { 00277 int v1 = p1->second; 00278 int v2 = p2->second; 00279 int c = common(v1,v2); 00280 if (c != 0) { 00281 R.fFactors[t] = c; 00282 } 00283 } 00284 } 00285 //cerr << "GCD of " << m1 << " and " << m2 << " is : " << R << endl; 00286 return R; 00287 }