FAUST compiler  0.9.9.6b8
Public Member Functions | Private Attributes | List of all members
aterm Class Reference

Implements a additive term, a set of mterms added together m1 + m2 + m3 + ... More...

#include <aterm.hh>

Public Member Functions

 aterm ()
 create an empty aterm (equivalent to 0) More...
 
 aterm (Tree t)
 create a aterm from an additive exp More...
 
const atermoperator+= (Tree t)
 add in place an additive expression tree More...
 
const atermoperator-= (Tree t)
 add in place an additive expression tree More...
 
const atermoperator+= (const mterm &m)
 add in place an mterm More...
 
const atermoperator-= (const mterm &m)
 add in place an mterm More...
 
Tree normalizedTree () const
 return the corresponding normalized expression tree More...
 
ostream & print (ostream &dst) const
 print a aterm m1 + m2 + m3 +... More...
 
mterm greatestDivisor () const
 return the greatest divisor of any two mterms More...
 
aterm factorize (const mterm &d)
 reorganize the aterm by factorizing d More...
 

Private Attributes

map< Tree, mtermfSig2MTerms
 mapping between signatures and corresponding mterms More...
 

Detailed Description

Implements a additive term, a set of mterms added together m1 + m2 + m3 + ...

Definition at line 23 of file aterm.hh.

Constructor & Destructor Documentation

aterm::aterm ( )

create an empty aterm (equivalent to 0)

Definition at line 11 of file aterm.cpp.

12 {}
aterm::aterm ( Tree  t)

create a aterm from an additive exp

create a aterm from a tree expression

Definition at line 18 of file aterm.cpp.

19 {
20  #ifdef TRACE
21  cerr << "aterm::aterm (" << ppsig(t)<< ")" << endl;
22  #endif
23  *this += t;
24  #ifdef TRACE
25  cerr << "aterm::aterm (" << ppsig(t)<< ") : -> " << *this << endl;
26  #endif
27 }
Definition: ppsig.hh:48

Member Function Documentation

aterm aterm::factorize ( const mterm d)

reorganize the aterm by factorizing d

Definition at line 241 of file aterm.cpp.

References mterm::hasDivisor(), normalizedTree(), mterm::normalizedTree(), and sigMul().

Referenced by normalizeAddTerm().

242 {
243  //cerr << "factorize : " << *this << " with " << d << endl;
244  aterm A;
245  aterm Q;
246 
247  // separate the multiple of m from the others
248  for (SM::const_iterator p1 = fSig2MTerms.begin(); p1 != fSig2MTerms.end(); p1++) {
249  mterm t = p1->second;
250  if (t.hasDivisor(d)) {
251  mterm q = t/d;
252  //cerr << "q = " << q << endl;
253  Q += q;
254  //cerr << "step Q = " << Q << endl;
255  } else {
256  A += t;
257  //cerr << "step A = " << A << endl;
258  }
259  }
260 
261  // combines the two parts
262  //cerr << "d.normalizedTree() " << ppsig(d.normalizedTree()) << endl;
263  //cerr << "Q.normalizedTree() " << ppsig(Q.normalizedTree()) << endl;
264  //Tree tt = sigMul(d.normalizedTree(), Q.normalizedTree());
265  //cerr << "tt " << *tt << endl;
266 
267  //Tree ttt = sigAdd(
268  A += sigMul(d.normalizedTree(), Q.normalizedTree());
269  //cerr << "Final A = " << A << endl;
270  //cerr << "Final Tree " << *(A.normalizedTree()) << endl;
271  return A;
272 }
Implements a multiplicative term, a term of type k*x^n*y^m*...
Definition: mterm.hh:21
map< Tree, mterm > fSig2MTerms
mapping between signatures and corresponding mterms
Definition: aterm.hh:26
Tree normalizedTree(bool sign=false, bool neg=false) const
return the normalized tree of the mterm
Definition: mterm.cpp:427
Tree normalizedTree() const
return the corresponding normalized expression tree
Definition: aterm.cpp:59
Tree sigMul(Tree x, Tree y)
Definition: signals.hh:154
Implements a additive term, a set of mterms added together m1 + m2 + m3 + ...
Definition: aterm.hh:23
bool hasDivisor(const mterm &n) const
return true if this can be divided by n
Definition: mterm.cpp:337

Here is the call graph for this function:

Here is the caller graph for this function:

mterm aterm::greatestDivisor ( ) const

return the greatest divisor of any two mterms

Definition at line 218 of file aterm.cpp.

References mterm::complexity(), and gcd().

Referenced by normalizeAddTerm().

219 {
220  int maxComplexity = 0;
221  mterm maxGCD(1);
222 
223  for (SM::const_iterator p1 = fSig2MTerms.begin(); p1 != fSig2MTerms.end(); p1++) {
224  for (SM::const_iterator p2 = p1; p2 != fSig2MTerms.end(); p2++) {
225  if (p2 != p1) {
226  mterm g = gcd(p1->second,p2->second);
227  if (g.complexity()>maxComplexity) {
228  maxComplexity = g.complexity();
229  maxGCD = g;
230  }
231  }
232  }
233  }
234  //cerr << "greatestDivisor of " << *this << " is " << maxGCD << endl;
235  return maxGCD;
236 }
mterm gcd(const mterm &m1, const mterm &m2)
return a mterm that is the greatest common divisor of two mterms
Definition: mterm.cpp:299
Implements a multiplicative term, a term of type k*x^n*y^m*...
Definition: mterm.hh:21
map< Tree, mterm > fSig2MTerms
mapping between signatures and corresponding mterms
Definition: aterm.hh:26
int complexity() const
return an evaluation of the complexity
Definition: mterm.cpp:65

Here is the call graph for this function:

Here is the caller graph for this function:

Tree aterm::normalizedTree ( ) const

return the corresponding normalized expression tree

Definition at line 59 of file aterm.cpp.

References getSigOrder(), mterm::isNegative(), isZero(), mterm::normalizedTree(), sigSub(), simplifyingAdd(), and tree().

Referenced by factorize(), and normalizeAddTerm().

60 {
61  // store positive and negative tems by order and sign
62  // positive terms are stored in P[]
63  // negative terms are inverted (made positive) and stored in N[]
64  Tree P[4], N[4];
65 
66  // prepare
67  for (int order = 0; order < 4; order++) P[order] = N[order] = tree(0);
68 
69  // sum by order and sign
70  for (SM::const_iterator p = fSig2MTerms.begin(); p != fSig2MTerms.end(); p++) {
71  const mterm& m = p->second;
72  if (m.isNegative()) {
73  Tree t = m.normalizedTree(false, true);
74  int order = getSigOrder(t);
75  N[order] = simplifyingAdd(N[order],t);
76  } else {
77  Tree t = m.normalizedTree();
78  int order = getSigOrder(t);
79  P[order] = simplifyingAdd(P[order],t);
80  }
81  }
82 
83  // combine sums
84  Tree SUM = tree(0);
85  for (int order = 0; order < 4; order++) {
86  if (!isZero(P[order])) {
87  SUM = simplifyingAdd(SUM,P[order]);
88  }
89  if (!isZero(N[order])) { // we have to substract
90  if (isZero(SUM) && (order < 3)) {
91  // we postpone substraction
92  N[order+1] = simplifyingAdd(N[order], N[order+1]);
93  } else {
94  SUM = sigSub(SUM, N[order]);
95  }
96  }
97  }
98 
99  assert(SUM);
100  return SUM;
101 }
bool isZero(Tree a)
Definition: signals.hh:188
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
static Tree simplifyingAdd(Tree t1, Tree t2)
Add two terms trying to simplify the result.
Definition: aterm.cpp:33
int getSigOrder(Tree sig)
retrieve the order annotation (between 0 and 3) of a signal.
Implements a multiplicative term, a term of type k*x^n*y^m*...
Definition: mterm.hh:21
Tree sigSub(Tree x, Tree y)
Definition: signals.hh:153
map< Tree, mterm > fSig2MTerms
mapping between signatures and corresponding mterms
Definition: aterm.hh:26
Tree normalizedTree(bool sign=false, bool neg=false) const
return the normalized tree of the mterm
Definition: mterm.cpp:427
Tree tree(const Node &n)
Definition: tree.hh:186
bool isNegative() const
true if mterm has a negative coefficient
Definition: mterm.cpp:40

Here is the call graph for this function:

Here is the caller graph for this function:

const aterm & aterm::operator+= ( Tree  t)

add in place an additive expression tree

Add in place an additive expression tree Go down t recursively looking for additions and substractions.

Definition at line 127 of file aterm.cpp.

References isSigBinOp(), kAdd, and kSub.

128 {
129  int op;
130  Tree x,y;
131 
132  assert(t!=0);
133 
134  if (isSigBinOp(t, &op, x, y) && (op == kAdd)) {
135  *this += x;
136  *this += y;
137 
138  } else if (isSigBinOp(t, &op, x, y) && (op == kSub)) {
139  *this += x;
140  *this -= y;
141 
142  } else {
143  mterm m(t);
144  *this += m;
145  }
146  return *this;
147 }
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Implements a multiplicative term, a term of type k*x^n*y^m*...
Definition: mterm.hh:21
Definition: binop.hh:56
bool isSigBinOp(Tree s, int *op, Tree &x, Tree &y)
Definition: signals.cpp:126
Definition: binop.hh:56

Here is the call graph for this function:

const aterm & aterm::operator+= ( const mterm m)

add in place an mterm

Add in place an mterm.

Definition at line 180 of file aterm.cpp.

References mterm::signatureTree().

181 {
182  #ifdef TRACE
183  cerr << *this << " aterm::+= " << m << endl;
184  #endif
185  Tree sig = m.signatureTree();
186  #ifdef TRACE
187  cerr << "signature " << *sig << endl;
188  #endif
189  SM::const_iterator p = fSig2MTerms.find(sig);
190  if (p == fSig2MTerms.end()) {
191  // its a new mterm
192  fSig2MTerms.insert(make_pair(sig,m));
193  } else {
194  fSig2MTerms[sig] += m;
195  }
196  return *this;
197 }
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree signatureTree() const
return a signature (a normalized tree)
Definition: mterm.cpp:416
map< Tree, mterm > fSig2MTerms
mapping between signatures and corresponding mterms
Definition: aterm.hh:26

Here is the call graph for this function:

const aterm & aterm::operator-= ( Tree  t)

add in place an additive expression tree

Substract in place an additive expression tree Go down t recursively looking for additions and substractions.

Definition at line 154 of file aterm.cpp.

References isSigBinOp(), kAdd, and kSub.

155 {
156  int op;
157  Tree x,y;
158 
159  assert(t!=0);
160 
161  if (isSigBinOp(t, &op, x, y) && (op == kAdd)) {
162  *this -= x;
163  *this -= y;
164 
165  } else if (isSigBinOp(t, &op, x, y) && (op == kSub)) {
166  *this -= x;
167  *this += y;
168 
169  } else {
170  mterm m(t);
171  *this -= m;
172  }
173  return *this;
174 }
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Implements a multiplicative term, a term of type k*x^n*y^m*...
Definition: mterm.hh:21
Definition: binop.hh:56
bool isSigBinOp(Tree s, int *op, Tree &x, Tree &y)
Definition: signals.cpp:126
Definition: binop.hh:56

Here is the call graph for this function:

const aterm & aterm::operator-= ( const mterm m)

add in place an mterm

Substract in place an mterm.

Definition at line 203 of file aterm.cpp.

References mterm::signatureTree().

204 {
205  //cerr << *this << " aterm::-= " << m << endl;
206  Tree sig = m.signatureTree();
207  //cerr << "signature " << *sig << endl;
208  SM::const_iterator p = fSig2MTerms.find(sig);
209  if (p == fSig2MTerms.end()) {
210  // its a new mterm
211  fSig2MTerms.insert(make_pair(sig,m*mterm(-1)));
212  } else {
213  fSig2MTerms[sig] -= m;
214  }
215  return *this;
216 }
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree signatureTree() const
return a signature (a normalized tree)
Definition: mterm.cpp:416
Implements a multiplicative term, a term of type k*x^n*y^m*...
Definition: mterm.hh:21
map< Tree, mterm > fSig2MTerms
mapping between signatures and corresponding mterms
Definition: aterm.hh:26

Here is the call graph for this function:

ostream & aterm::print ( ostream &  dst) const

print a aterm m1 + m2 + m3 +...

print an aterm in a human readable format

Definition at line 107 of file aterm.cpp.

Referenced by operator<<().

108 {
109  if (fSig2MTerms.empty()) {
110  dst << "AZERO";
111  } else {
112  const char* sep = "";
113  for (SM::const_iterator p = fSig2MTerms.begin(); p != fSig2MTerms.end(); p++) {
114  dst << sep << p->second;
115  sep = " + ";
116  }
117  }
118 
119  return dst;
120 }
map< Tree, mterm > fSig2MTerms
mapping between signatures and corresponding mterms
Definition: aterm.hh:26

Here is the caller graph for this function:

Member Data Documentation

map<Tree,mterm> aterm::fSig2MTerms
private

mapping between signatures and corresponding mterms

Definition at line 26 of file aterm.hh.


The documentation for this class was generated from the following files: