Beispiel #1
0
inline
subMonomial::subMonomial(const Monomial & theMonomial,int st,int len) :
    _mono(theMonomial), _start(1), _length(0),
    start_iterator(theMonomial.begin()) {
   start(st);
   length(len);
};
Beispiel #2
0
void NCASink::put(const Monomial& x) {
  int len = x.numberOfFactors();
  if(len==0) {
    d_ofs << '1';
  } else if(len==1) {
    put(*x.begin());
  } else {
    MonomialIterator w = x.begin();
    put(*w);
    --len;++w;
    while(len) {
      d_ofs << " ** ";
      put(*w);
      --len;++w;
    };
  };
};
Beispiel #3
0
Monomial Wreath::grabAtLevel(int aLevel,const Monomial & first) const {
  Monomial result;
  MonomialIterator w = first.begin();
  const int sz = first.numberOfFactors();
  for(int i=1;i<=sz;++i,++w) {
    const Variable & v = *w;
    if(level(v)==aLevel) result *= v;
  };
  return result;
};
Beispiel #4
0
void MatcherMonomial::constructMatch( const Monomial & mona,int a,
       const Monomial & monb,int b, const subMonomial & aINode,
       const subMonomial & bINode, MATCHING_TYPES type,
       Match & match ) const {
  match.firstGBData = a;
  match.secondGBData = b;

  const int bStartm1 = bINode.start()-1;
  MonomialIterator iter = monb.begin();
  int i=1;
  for(;i<=bStartm1;++i,++iter) {
    match.left1() *= (* iter);
  }
  const int bNumFactor = monb.numberOfFactors();
  int temp2 = bINode.start()+bINode.length();
  if(temp2<=bNumFactor) {
    MonomialIterator iter2 = monb.begin();
    int jj = temp2-1;
    while(jj) { ++iter2;--jj;};
    for(int j=temp2;j<=bNumFactor;++j,++iter2) {
      match.right1() *= (* iter2);
    }
  }
  if(type==SUBSET_MATCH) {
    match.subsetMatch = false;
    match.overlapMatch = true;  
  } else if(type==OVERLAP_MATCH) {
    match.subsetMatch = false;
    match.overlapMatch = true;
    const int aStartm1 = aINode.start()-1;
    MonomialIterator iter3 = mona.begin(); 
    for(i=1;i<=aStartm1;++i,++iter3) {   
       match.left2() *= (* iter3);
    }   
    MonomialIterator iter4 = mona.begin(); 
    const int temp4 = aINode.start()+aINode.length();
    int jj = temp4-1;
    while(jj) { ++iter4;--jj;};
    for(int j=temp4;j<=mona.numberOfFactors();++j,++iter4) {   
       match.right2() *= (* iter4);
    }   
  }
};
Beispiel #5
0
bool MatcherMonomial::matchExists(const Monomial & mona,
                             const Monomial & monb) {
  setInternalMatch();
  bool result = matchExistsNoRecord(mona,monb);
  if(result && k > 0) {
    const int beginNum = k-1;
    MonomialIterator iter = monb.begin();
    for(int i = 1; i <= beginNum; ++i,++iter) {
      _theMatch->left1() *= (*iter);
    }
    const int numberFactors = monb.numberOfFactors();
    const int temp2 = k + mona.numberOfFactors();
    if(temp2<=numberFactors) {
      MonomialIterator iter2 = monb.begin();
      int jj = temp2-1;
      while(jj) {++iter2;--jj;};
      for(int j=temp2;j<=numberFactors;++j,++iter2) {
        _theMatch->right1() *= (*iter2);
      }
    }
  }
  return result;
};
Beispiel #6
0
void removePowers(const Monomial & m,Monomial & result) {
  if(m.numberOfFactors()!=0) {
    Variable v;
    result.setToOne();
    MonomialIterator w = m.begin(), e = m.end();
    while(w!=e) {
      if(v!=*w) {
        v = *w;
        result *= v;
      };
      ++w;
    };
  };
};
Beispiel #7
0
 void MmaSink::put(const Monomial& x) {
#ifdef DEBUG_MMASINK
   GBStream << "sink:monomial " << this << ' ' << x << '\n';
#endif
  int len = x.numberOfFactors();
  if(len==0) {
    MLPutInteger(d_mlink,1);
    ++d_count;
  } else if(len==1) {
    put(*x.begin());
  } else {
    MLPutFunction(d_mlink,"NonCommutativeMultiply",len);
    ++d_count;
    d_count -= len;
    MonomialIterator w = x.begin();
    while(len) {
      put(*w);
      --len;++w;
    };
  };
#ifdef DEBUG_MMASINK
  checkforerror();
#endif
};
Beispiel #8
0
bool MatcherMonomial::matchExistsNoRecord(const Monomial & mona,
                                     const Monomial & monb) {
  k = 0; // mutable class variable
  bool result = mona==monb;
  if(!result) {
    int leni = mona.numberOfFactors();
    int lenj = monb.numberOfFactors();
    if(leni<lenj) {
      subMonomial INodei(mona,1,0);
      subMonomial INodej(monb,1,0);

      const int spread = lenj - leni + 1;

      INodei.length(leni);
      INodej.length(leni);
#ifdef NEWCODE
      if(spread>0) {
        Variable v = * mona.begin();
#endif
        for(int tempk = 1; tempk <= spread && !result; ++tempk) {
          if(tempk!=1) {
            INodej.incrementStart();
          }
#ifdef NEWCODE
          tempk = INodej.findVariableForward(spread-tempk+1,v);
          if(tempk==-1) {
            tempk = spread+1;
          } else
#endif
          {
            result = INodei==INodej;
            if(result) k = tempk;
          }
        }
#ifdef NEWCODE
      } else {
        k = 1; // deal with matching against 1
      }
#endif
    }
  }
  return result;
};