#include "mterm.hh"
#include "signals.hh"
#include "ppsig.hh"
#include "xtended.hh"
#include <assert.h>
Go to the source code of this file.
Typedefs | |
typedef map< Tree, int > | MP |
Functions | |
static bool | isSigPow (Tree sig, Tree &x, int &n) |
match x^p with p:int | |
static Tree | sigPow (Tree x, int p) |
produce x^p with p:int | |
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 362 of file mterm.cpp.
References sigPow().
Referenced by combineMulDiv().
00363 { 00364 assert(f); 00365 assert(q>0); 00366 if (q>1) { 00367 return sigPow(f, q); 00368 } else { 00369 return f; 00370 } 00371 }
Combine R and A doing R = R*A or R = A.
Definition at line 385 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 394 of file mterm.cpp.
References buildPowTerm(), and combineMulLeft().
Referenced by mterm::normalizedTree().
00395 { 00396 #ifdef TRACE 00397 cerr << "combineMulDiv (" << M << "/" << D << "*" << ppsig(f)<< "**" << q << endl; 00398 #endif 00399 if (f) { 00400 if (q > 0) { 00401 combineMulLeft(M, buildPowTerm(f,q)); 00402 } else if (q < 0) { 00403 combineMulLeft(D, buildPowTerm(f,-q)); 00404 } 00405 } 00406 }
Combine R and A doing R = R*A or R = A.
Definition at line 376 of file mterm.cpp.
References sigMul().
Referenced by combineMulDiv(), and mterm::normalizedTree().
00377 { 00378 if (R && A) R = sigMul(R,A); 00379 else if (A) R = A; 00380 }
static int common | ( | int | a, | |
int | b | |||
) | [static] |
return the "common quantity" of two numbers
Definition at line 284 of file mterm.cpp.
Referenced by gcd().
00285 { 00286 if (a > 0 & b > 0) { 00287 return min(a,b); 00288 } else if (a < 0 & b < 0) { 00289 return max(a,b); 00290 } else { 00291 return 0; 00292 } 00293 }
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 325 of file mterm.cpp.
Referenced by mterm::hasDivisor().
return a mterm that is the greatest common divisor of two mterms
Definition at line 299 of file mterm.cpp.
References common(), mterm::fCoef, mterm::fFactors, and tree().
Referenced by aterm::greatestDivisor().
00300 { 00301 //cerr << "GCD of " << m1 << " and " << m2 << endl; 00302 00303 Tree c = (m1.fCoef == m2.fCoef) ? m1.fCoef : tree(1); // common coefficient (real gcd not needed) 00304 mterm R(c); 00305 for (MP::const_iterator p1 = m1.fFactors.begin(); p1 != m1.fFactors.end(); p1++) { 00306 Tree t = p1->first; 00307 MP::const_iterator p2 = m2.fFactors.find(t); 00308 if (p2 != m2.fFactors.end()) { 00309 int v1 = p1->second; 00310 int v2 = p2->second; 00311 int c = common(v1,v2); 00312 if (c != 0) { 00313 R.fFactors[t] = c; 00314 } 00315 } 00316 } 00317 //cerr << "GCD of " << m1 << " and " << m2 << " is : " << R << endl; 00318 return R; 00319 }
match x^p with p:int
Definition at line 77 of file mterm.cpp.
References CTree::branch(), getUserData(), gPowPrim, and isSigInt().
Referenced by mterm::operator*=(), and mterm::operator/=().
00078 { 00079 //cerr << "isSigPow("<< *sig << ')' << endl; 00080 xtended* p = (xtended*) getUserData(sig); 00081 if (p == gPowPrim) { 00082 if (isSigInt(sig->branch(1), &n)) { 00083 x = sig->branch(0); 00084 //cerr << "factor of isSigPow " << *x << endl; 00085 return true; 00086 } 00087 } 00088 return false; 00089 }
produce x^p with p:int
Definition at line 94 of file mterm.cpp.
References gPowPrim, sigInt(), xtended::symbol(), and tree().
Referenced by buildPowTerm().