FAUST compiler  0.9.9.6b8
Typedefs | Functions
mterm.cpp File Reference
#include "mterm.hh"
#include "signals.hh"
#include "ppsig.hh"
#include "xtended.hh"
#include <assert.h>
Include dependency graph for mterm.cpp:

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 More...
 
static Tree sigPow (Tree x, int p)
 produce x^p with p:int More...
 
static int common (int a, int b)
 return the "common quantity" of two numbers More...
 
mterm gcd (const mterm &m1, const mterm &m2)
 return a mterm that is the greatest common divisor of two mterms More...
 
static bool contains (int a, int b)
 We say that a "contains" b if a/b > 0. More...
 
static Tree buildPowTerm (Tree f, int q)
 produce the canonical tree correspoding to a mterm More...
 
static void combineMulLeft (Tree &R, Tree A)
 Combine R and A doing R = R*A or R = A. More...
 
static void combineDivLeft (Tree &R, Tree A)
 Combine R and A doing R = R*A or R = A. More...
 
static void combineMulDiv (Tree &M, Tree &D, Tree f, int q)
 Do M = M * f**q or D = D * f**-q. More...
 

Typedef Documentation

typedef map<Tree,int> MP

Definition at line 12 of file mterm.cpp.

Function Documentation

static Tree buildPowTerm ( Tree  f,
int  q 
)
static

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().

363 {
364  assert(f);
365  assert(q>0);
366  if (q>1) {
367  return sigPow(f, q);
368  } else {
369  return f;
370  }
371 }
static Tree sigPow(Tree x, int p)
produce x^p with p:int
Definition: mterm.cpp:94

Here is the call graph for this function:

Here is the caller graph for this function:

static void combineDivLeft ( Tree R,
Tree  A 
)
static

Combine R and A doing R = R*A or R = A.

Definition at line 386 of file mterm.cpp.

References sigDiv(), and tree().

Referenced by mterm::normalizedTree().

387 {
388  if (R && A) R = sigDiv(R,A);
389  else if (A) R = sigDiv(tree(1.0f),A);
390  else exit(1);
391 }
Tree tree(const Node &n)
Definition: tree.hh:186
Tree sigDiv(Tree x, Tree y)
Definition: signals.hh:155

Here is the call graph for this function:

Here is the caller graph for this function:

static void combineMulDiv ( Tree M,
Tree D,
Tree  f,
int  q 
)
static

Do M = M * f**q or D = D * f**-q.

Definition at line 396 of file mterm.cpp.

References buildPowTerm(), and combineMulLeft().

Referenced by mterm::normalizedTree().

397 {
398  #ifdef TRACE
399  cerr << "combineMulDiv (" << M << "/" << D << "*" << ppsig(f)<< "**" << q << endl;
400  #endif
401  if (f) {
402  assert(q != 0);
403  if (q > 0) {
404  combineMulLeft(M, buildPowTerm(f,q));
405  } else if (q < 0) {
406  combineMulLeft(D, buildPowTerm(f,-q));
407  }
408  }
409 }
static void combineMulLeft(Tree &R, Tree A)
Combine R and A doing R = R*A or R = A.
Definition: mterm.cpp:376
static Tree buildPowTerm(Tree f, int q)
produce the canonical tree correspoding to a mterm
Definition: mterm.cpp:362
Definition: ppsig.hh:48

Here is the call graph for this function:

Here is the caller graph for this function:

static void combineMulLeft ( Tree R,
Tree  A 
)
static

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().

377 {
378  if (R && A) R = sigMul(R,A);
379  else if (A) R = A;
380  else exit(1);
381 }
Tree sigMul(Tree x, Tree y)
Definition: signals.hh:154

Here is the call graph for this function:

Here is the caller graph for this function:

static int common ( int  a,
int  b 
)
static

return the "common quantity" of two numbers

Definition at line 284 of file mterm.cpp.

References max(), and min().

Referenced by gcd().

285 {
286  if (a > 0 & b > 0) {
287  return min(a,b);
288  } else if (a < 0 & b < 0) {
289  return max(a,b);
290  } else {
291  return 0;
292  }
293 }
double max(double x, double y)
Definition: interval.hh:60
double min(double x, double y)
Definition: interval.hh:59

Here is the call graph for this function:

Here is the caller graph for this function:

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().

326 {
327  return (b == 0) || (a/b > 0);
328 }

Here is the caller graph for this function:

mterm gcd ( const mterm m1,
const mterm m2 
)

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().

300 {
301  //cerr << "GCD of " << m1 << " and " << m2 << endl;
302 
303  Tree c = (m1.fCoef == m2.fCoef) ? m1.fCoef : tree(1); // common coefficient (real gcd not needed)
304  mterm R(c);
305  for (MP::const_iterator p1 = m1.fFactors.begin(); p1 != m1.fFactors.end(); p1++) {
306  Tree t = p1->first;
307  MP::const_iterator p2 = m2.fFactors.find(t);
308  if (p2 != m2.fFactors.end()) {
309  int v1 = p1->second;
310  int v2 = p2->second;
311  int c = common(v1,v2);
312  if (c != 0) {
313  R.fFactors[t] = c;
314  }
315  }
316  }
317  //cerr << "GCD of " << m1 << " and " << m2 << " is : " << R << endl;
318  return R;
319 }
Tree fCoef
constant part of the term (usually 1 or -1)
Definition: mterm.hh:24
static int common(int a, int b)
return the "common quantity" of two numbers
Definition: mterm.cpp:284
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
map< Tree, int > fFactors
non constant terms and their power
Definition: mterm.hh:25
Implements a multiplicative term, a term of type k*x^n*y^m*...
Definition: mterm.hh:21
Tree tree(const Node &n)
Definition: tree.hh:186

Here is the call graph for this function:

Here is the caller graph for this function:

static bool isSigPow ( Tree  sig,
Tree x,
int &  n 
)
static

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/=().

78 {
79  //cerr << "isSigPow("<< *sig << ')' << endl;
80  xtended* p = (xtended*) getUserData(sig);
81  if (p == gPowPrim) {
82  if (isSigInt(sig->branch(1), &n)) {
83  x = sig->branch(0);
84  //cerr << "factor of isSigPow " << *x << endl;
85  return true;
86  }
87  }
88  return false;
89 }
bool isSigInt(Tree t, int *i)
Definition: signals.cpp:41
void * getUserData(Symbol *sym)
Returns user data.
Definition: symbol.hh:100
xtended * gPowPrim
Definition: powprim.cpp:77
Tree branch(int i) const
return the ith branch (subtree) of a tree
Definition: tree.hh:145

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree sigPow ( Tree  x,
int  p 
)
static

produce x^p with p:int

Definition at line 94 of file mterm.cpp.

References gPowPrim, sigInt(), xtended::symbol(), and tree().

Referenced by buildPowTerm().

95 {
96  return tree(gPowPrim->symbol(), x, sigInt(p));
97 }
Sym symbol()
Definition: xtended.hh:24
Tree tree(const Node &n)
Definition: tree.hh:186
xtended * gPowPrim
Definition: powprim.cpp:77
Tree sigInt(int i)
Signals.
Definition: signals.cpp:40

Here is the call graph for this function:

Here is the caller graph for this function: