FAUST compiler  0.9.9.6b8
normalize.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <assert.h>
3 #include "tlib.hh"
4 #include "signals.hh"
5 #include "sigprint.hh"
6 #include "ppsig.hh"
7 #include "simplify.hh"
8 #include "normalize.hh"
9 #include "sigorderrules.hh"
10 #include <map>
11 #include <list>
12 
13 #include "mterm.hh"
14 #include "aterm.hh"
15 
16 #if 0
17 static void countAddTerm (map<Tree,Tree>& M, Tree t, bool invflag);
18 static void incTermCount (map<Tree,int>& M, Tree t, bool invflag);
19 static Tree buildPowTerm (Tree f, int q);
20 static Tree simplifyingReorganizingMul(Tree t1, Tree t2);
21 static Tree reorganizingMul(Tree k, Tree t);
22 static void factorizeAddTerm(map<Tree,Tree>& M);
23 #endif
24 
25 #undef TRACE
26 
33 {
34 #ifdef TRACE
35  cerr << "START normalizeAddTerm : " << ppsig(t) << endl;
36 #endif
37 
38  aterm A(t);
39  //cerr << "ATERM IS : " << A << endl;
40  mterm D = A.greatestDivisor();
41  while (D.isNotZero() && D.complexity() > 0) {
42  //cerr << "GREAT DIV : " << D << endl;
43  A = A.factorize(D);
44  D = A.greatestDivisor();
45  }
46  return A.normalizedTree();
47 }
48 
49 
60 {
61  return normalizeFixedDelayTerm(s, tree(1));
62 }
63 
64 
82 {
83  Tree x, y, r;
84  int i;
85 
86  if (isZero(d) && ! isProj(s, &i, r)) {
87 
88  return s;
89 
90  } else if (isZero(s)) {
91 
92  return s;
93 
94  } else if (isSigMul(s, x, y)) {
95 
96  if (getSigOrder(x) < 2) {
97  return /*simplify*/(sigMul(x,normalizeFixedDelayTerm(y,d)));
98  } else if (getSigOrder(y) < 2) {
99  return /*simplify*/(sigMul(y,normalizeFixedDelayTerm(x,d)));
100  } else {
101  return sigFixDelay(s,d);
102  }
103 
104  } else if (isSigDiv(s, x, y)) {
105 
106  if (getSigOrder(y) < 2) {
107  return /*simplify*/(sigDiv(normalizeFixedDelayTerm(x,d),y));
108  } else {
109  return sigFixDelay(s,d);
110  }
111 
112  } else if (isSigFixDelay(s, x, y)) {
113  // (x@n)@m = x@(n+m)
114 // return sigFixDelay(x,tree(tree2int(d)+tree2int(y)));
115  return normalizeFixedDelayTerm(x,simplify(sigAdd(d,y)));
116 
117  } else {
118 
119  return sigFixDelay(s,d);
120  }
121 }
122 
bool isZero(Tree a)
Definition: signals.hh:188
mterm greatestDivisor() const
return the greatest divisor of any two mterms
Definition: aterm.cpp:218
aterm factorize(const mterm &d)
reorganize the aterm by factorizing d
Definition: aterm.cpp:241
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
bool isSigFixDelay(Tree t, Tree &t0, Tree &t1)
Definition: signals.cpp:62
Tree simplify(Tree sig)
Definition: simplify.cpp:76
Tree normalizeFixedDelayTerm(Tree s, Tree d)
Compute the normal form of a fixed delay term (s).
Definition: normalize.cpp:81
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
static Tree buildPowTerm(Tree f, int q)
produce the canonical tree correspoding to a mterm
Definition: mterm.cpp:362
Definition: ppsig.hh:48
bool isNotZero() const
true if mterm doesn't represent number 0
Definition: mterm.cpp:32
Tree normalizeDelay1Term(Tree s)
Compute the normal form of a 1-sample delay term s'.
Definition: normalize.cpp:59
Tree sigAdd(Tree x, Tree y)
Definition: signals.hh:152
int complexity() const
return an evaluation of the complexity
Definition: mterm.cpp:65
Tree normalizeAddTerm(Tree t)
Compute the Add-Normal form of a term t.
Definition: normalize.cpp:32
Tree normalizedTree() const
return the corresponding normalized expression tree
Definition: aterm.cpp:59
Tree sigFixDelay(Tree t0, Tree t1)
Definition: signals.cpp:61
bool isSigDiv(Tree a, Tree &x, Tree &y)
Definition: signals.cpp:362
Tree tree(const Node &n)
Definition: tree.hh:186
Tree sigMul(Tree x, Tree y)
Definition: signals.hh:154
bool isSigMul(Tree a, Tree &x, Tree &y)
Definition: signals.cpp:350
bool isProj(Tree t, int *i, Tree &rgroup)
Definition: signals.cpp:151
Tree sigDiv(Tree x, Tree y)
Definition: signals.hh:155
Implements a additive term, a set of mterms added together m1 + m2 + m3 + ...
Definition: aterm.hh:23