8 #include "normalize.hh"
9 #include "sigorderrules.hh"
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
);
28 * Compute the Add-Normal form of a term t.
29 * \param t the term to be normalized
30 * \return the normalized term
32 Tree
normalizeAddTerm(Tree t
)
35 cerr
<< "START normalizeAddTerm : " << ppsig(t
) << endl
;
39 //cerr << "ATERM IS : " << A << endl;
40 mterm D
= A
.greatestDivisor();
41 while (D
.isNotZero() && D
.complexity() > 0) {
42 //cerr << "GREAT DIV : " << D << endl;
44 D
= A
.greatestDivisor();
46 return A
.normalizedTree();
51 * Compute the normal form of a 1-sample delay term s'.
52 * The normalisation rules are :
53 * 0' -> 0 /// INACTIVATE dec07 bug recursion
56 * \param s the term to be delayed by 1 sample
57 * \return the normalized term
59 Tree
normalizeDelay1Term(Tree s
)
61 return normalizeFixedDelayTerm(s
, tree(1));
66 * Compute the normal form of a fixed delay term (s@d).
67 * The normalisation rules are :
73 * Note that the same rules can't be applied to
74 * + et - becaue the value of the first d samples
75 * would be wrong. We could also add delays such that
76 * \param s the term to be delayed
77 * \param d the value of the delay
78 * \return the normalized term
81 Tree
normalizeFixedDelayTerm(Tree s
, Tree d
)
86 if (isZero(d
) && ! isProj(s
, &i
, r
)) {
90 } else if (isZero(s
)) {
94 } else if (isSigMul(s
, x
, y
)) {
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
)));
101 return sigFixDelay(s
,d
);
104 } else if (isSigDiv(s
, x
, y
)) {
106 if (getSigOrder(y
) < 2) {
107 return /*simplify*/(sigDiv(normalizeFixedDelayTerm(x
,d
),y
));
109 return sigFixDelay(s
,d
);
112 } else if (isSigFixDelay(s
, x
, y
)) {
114 // return sigFixDelay(x,tree(tree2int(d)+tree2int(y)));
115 return normalizeFixedDelayTerm(x
,simplify(sigAdd(d
,y
)));
119 return sigFixDelay(s
,d
);