FAUST compiler  0.9.9.6b8
Public Member Functions | Private Attributes
aterm Class Reference

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

#include <aterm.hh>

List of all members.

Public Member Functions

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

Private Attributes

map< Tree, mtermfSig2MTerms
 mapping between signatures and corresponding mterms

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

create an empty aterm (equivalent to 0)

Definition at line 11 of file aterm.cpp.

{}

create a aterm from an additive exp

create a aterm from a tree expression

Definition at line 18 of file aterm.cpp.

{
    #ifdef TRACE
    cerr << "aterm::aterm (" << ppsig(t)<< ")" << endl;
    #endif
    *this += t;
    #ifdef TRACE
    cerr << "aterm::aterm (" << ppsig(t)<< ") : -> " << *this << endl;
    #endif
}

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

{
    //cerr << "factorize : " << *this << " with " << d << endl;
    aterm A;
    aterm Q;
    
    // separate the multiple of m from the others
    for (SM::const_iterator p1 = fSig2MTerms.begin(); p1 != fSig2MTerms.end(); p1++) {
        mterm t = p1->second;
        if (t.hasDivisor(d)) {
            mterm q = t/d;
            //cerr << "q = " << q << endl;
            Q += q;
            //cerr << "step Q = " << Q << endl;
        } else {
            A += t;
            //cerr << "step A = " << A << endl;
        }
    }
    
    // combines the two parts
    //cerr << "d.normalizedTree() " << ppsig(d.normalizedTree()) << endl;
    //cerr << "Q.normalizedTree() " << ppsig(Q.normalizedTree()) << endl;
    //Tree tt = sigMul(d.normalizedTree(), Q.normalizedTree());
    //cerr << "tt " << *tt << endl;
    
    //Tree ttt = sigAdd(
    A += sigMul(d.normalizedTree(), Q.normalizedTree());
    //cerr << "Final A = " << A << endl;
    //cerr << "Final Tree " << *(A.normalizedTree()) << endl;
    return A;
}

Here is the call graph for this function:

Here is the caller graph for this function:

return the greatest divisor of any two mterms

Definition at line 218 of file aterm.cpp.

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

Referenced by normalizeAddTerm().

{
    int maxComplexity = 0;
    mterm maxGCD(1);
    
    for (SM::const_iterator p1 = fSig2MTerms.begin(); p1 != fSig2MTerms.end(); p1++) {
        for (SM::const_iterator p2 = p1; p2 != fSig2MTerms.end(); p2++) {
            if (p2 != p1) {
                mterm g = gcd(p1->second,p2->second);
                if (g.complexity()>maxComplexity) {
                    maxComplexity = g.complexity();
                    maxGCD = g;
                }
            }
        }
    }
    //cerr << "greatestDivisor of " << *this << " is " << maxGCD << endl;
    return maxGCD;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

{
    // store positive and negative tems by order and sign
    // positive terms are stored in P[]
    // negative terms are inverted (made positive) and stored in N[]
    Tree P[4], N[4];
    
    // prepare
    for (int order = 0; order < 4; order++)     P[order] = N[order] = tree(0);
    
    // sum by order and sign
    for (SM::const_iterator p = fSig2MTerms.begin(); p != fSig2MTerms.end(); p++) {
        const mterm& m = p->second; 
        if (m.isNegative()) {
            Tree t = m.normalizedTree(false, true);
            int order = getSigOrder(t);
            N[order] = simplifyingAdd(N[order],t);
        } else {
            Tree t = m.normalizedTree();
            int order = getSigOrder(t);
            P[order] = simplifyingAdd(P[order],t);
        }
    }
    
    // combine sums
    Tree SUM = tree(0);
    for (int order = 0; order < 4; order++) {
        if (!isZero(P[order]))  {
            SUM = simplifyingAdd(SUM,P[order]);
        }
        if (!isZero(N[order]))  {   // we have to substract
            if (isZero(SUM) && (order < 3)) {
                // we postpone substraction
                N[order+1] = simplifyingAdd(N[order], N[order+1]);
            } else {
                SUM = sigSub(SUM, N[order]);
            }
        }
    }
    
    assert(SUM);
    return SUM;
}

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.

{
    int     op;
    Tree    x,y;

    assert(t!=0);

    if (isSigBinOp(t, &op, x, y) && (op == kAdd)) {
        *this += x;
        *this += y;

    } else if (isSigBinOp(t, &op, x, y) && (op == kSub)) {
        *this += x;
        *this -= y;

    } else {
        mterm m(t);
        *this += m;
    }
    return *this;
}

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

{
    #ifdef TRACE
    cerr << *this << " aterm::+= " << m << endl;
    #endif
    Tree sig = m.signatureTree();
    #ifdef TRACE
    cerr << "signature " << *sig << endl;
    #endif
    SM::const_iterator p = fSig2MTerms.find(sig);
    if (p == fSig2MTerms.end()) {
        // its a new mterm
        fSig2MTerms.insert(make_pair(sig,m));
    } else {
        fSig2MTerms[sig] += m;
    }
    return *this;
}

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.

{
    int     op;
    Tree    x,y;

    assert(t!=0);

    if (isSigBinOp(t, &op, x, y) && (op == kAdd)) {
        *this -= x;
        *this -= y;

    } else if (isSigBinOp(t, &op, x, y) && (op == kSub)) {
        *this -= x;
        *this += y;

    } else {
        mterm m(t);
        *this -= m;
    }
    return *this;
}

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

{
    //cerr << *this << " aterm::-= " << m << endl;
    Tree sig = m.signatureTree();
    //cerr << "signature " << *sig << endl;
    SM::const_iterator p = fSig2MTerms.find(sig);
    if (p == fSig2MTerms.end()) {
        // its a new mterm
        fSig2MTerms.insert(make_pair(sig,m*mterm(-1)));
    } else {
        fSig2MTerms[sig] -= m;
    }
    return *this;
}

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

{
    if (fSig2MTerms.empty()) {
        dst << "AZERO";
    } else {
        const char* sep = "";
        for (SM::const_iterator p = fSig2MTerms.begin(); p != fSig2MTerms.end(); p++) {
            dst << sep << p->second;
            sep = " + ";
        }
    }
 
    return dst;
}

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: