[mathicgb] 211/393: Removed unused code from PolyRing.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Fri Apr 3 15:59:03 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch upstream
in repository mathicgb.

commit f3b33fad423120130d3db9959afb51721986e4b7
Author: Bjarke Hammersholt Roune <bjarkehr.code at gmail.com>
Date:   Fri Mar 29 14:58:47 2013 +0100

    Removed unused code from PolyRing.
---
 src/mathicgb/PolyRing.cpp | 311 ----------------------------------------------
 src/mathicgb/PolyRing.hpp | 228 +--------------------------------
 src/mathicgb/io-util.cpp  |  19 ---
 3 files changed, 4 insertions(+), 554 deletions(-)

diff --git a/src/mathicgb/PolyRing.cpp b/src/mathicgb/PolyRing.cpp
index 7b366f6..8ab828e 100755
--- a/src/mathicgb/PolyRing.cpp
+++ b/src/mathicgb/PolyRing.cpp
@@ -344,317 +344,6 @@ void PolyRing::printRingFrobbyM2Format(std::ostream& out) const {
   out << "];\n";
 }
 
-
-
-///////////////////////////////////////
-// (Old) Monomial Routines ////////////
-///////////////////////////////////////
-
-#ifndef NEWMONOMIALS
-bool PolyRing::monomialIsLeastCommonMultiple(
-  const_monomial a,
-  const_monomial b,
-  const_monomial l) const
-{
-  return monomialIsLeastCommonMultipleNoWeights(a, b, l) && weightsCorrect(l);
-}
-
-bool PolyRing::weightsCorrect(const_monomial a) const
-{
-  ++a;
-  auto wts = &mWeights[0];
-  for (int i=0; i < mNumWeights; ++i) {
-    exponent result = 0;
-    for (size_t j=0; j < mNumVars; ++j)
-      result += *wts++ * a[j];
-    if (a[mNumVars + i] != result)
-      return false;
-  }
-  return true;
-}
-
-bool PolyRing::monomialIsLeastCommonMultipleNoWeights(
-  const_monomial a,
-  const_monomial b,
-  const_monomial l) const
-{
-  if (*l != 0)
-    return false;
-  for (size_t i = 1; i <= mNumVars; ++i)
-    if (l[i] != std::max(a[i], b[i]))
-      return false;
-  return true;
-}
-
-int PolyRing::monomialCompare(const_monomial sig, const_monomial m2, const_monomial sig2) const
-  // returns LT, EQ, or GT, depending on sig ? (m2 * sig2).
-{
-  for (size_t i = mTopIndex; i != static_cast<size_t>(-1); --i)
-    {
-      auto cmp = sig[i] - m2[i] - sig2[i];
-      if (cmp < 0) return GT;
-      if (cmp > 0) return LT;
-    }
-  return EQ;
-}
-
-bool PolyRing::monomialEQ(const_monomial a, const_monomial b) const
-{
-  for (size_t i = 0; i <= mNumVars; ++i)
-    if (a[i] != b[i]) return false;
-  return true;
-}
-
-void PolyRing::monomialSetIdentity(monomial& result) const {
-  for (size_t i = 0; i <= mTopIndex; ++i)
-    result[i] = 0;
-  result[mHashIndex] = 0;
-}
-
-void PolyRing::monomialEi(size_t i, monomial &result) const
-{
-  for (size_t j=mTopIndex; j != static_cast<size_t>(-1); --j) result[j] = 0;
-  *result = static_cast<exponent>(i); // todo: handle overflow or change representation
-  result[mHashIndex] = static_cast<exponent>(i); // todo: handle overflow or change representation
-}
-
-void PolyRing::monomialMult(const_monomial a, const_monomial b, monomial &result) const
-{
-  for (size_t i = mHashIndex; i != static_cast<size_t>(-1); --i)
-    result[i] = a[i] + b[i];
-}
-void PolyRing::monomialMultTo(monomial a, const_monomial b) const
-{
-  // a *= b
-  for (size_t i = mHashIndex; i != static_cast<size_t>(-1); --i)
-    a[i] += b[i];
-}
-
-
-void PolyRing::monomialCopy(const_monomial a, monomial &result) const
-{
-  for (size_t i = mHashIndex; i != static_cast<size_t>(-1); --i)
-    result[i] = a[i];
-}
-
-void PolyRing::monomialQuotientAndMult(const_monomial a,
-                                       const_monomial b,
-                                       const_monomial c,
-                                       monomial result) const
-{
-  // result is set to (a:b) * c.  It is not assumed that b divides a.
-  for (size_t i = 0; i <= mNumVars; ++i)
-    {
-      result[i] = c[i];
-      auto cmp = a[i] - b[i];
-      if (cmp > 0) result[i] += cmp;
-    }
-  setWeightsAndHash(result);
-}
-
-void PolyRing::setWeightsAndHash(monomial a) const
-{
-  setWeightsOnly(a);
-  auto hash = *a;
-  a++;
-  for (size_t i = 0; i < mNumVars; ++i)
-    hash += a[i] * mHashVals[i];
-  a[mHashIndex - 1] = hash; // index-1 as we did ++a above
-}
-
-void PolyRing::monomialFindSignatures(const_monomial v1,
-                                      const_monomial v2,
-                                      const_monomial u1,
-                                      const_monomial u2,
-                                      monomial t1,
-                                      monomial t2) const
-{
-  // t1 := (v2:v1) u1
-  // t2 := (v1:v2) u2
-  // set components:
-  *t1 = *u1;
-  *t2 = *u2;
-
-  for (size_t i = 1; i <= mNumVars; ++i)
-    {
-      exponent a = v1[i];
-      exponent b = v2[i];
-      exponent min = std::min(a, b);
-      t1[i] = b - min + u1[i];
-      t2[i] = a - min + u2[i];
-    }
-  setWeightsOnly(t1);
-  setWeightsOnly(t2);
-}
-
-void PolyRing::monomialFindSignature(const_monomial v1,
-                                     const_monomial v2,
-                                     const_monomial u1,
-                                     monomial t1) const
-{
-  // t1 := (v2:v1) u1
-  *t1 = *u1;
-  if (mTotalDegreeGradedOnly) {
-    MATHICGB_ASSERT(mNumWeights == 1);
-    exponent weight = 0;
-    for (size_t i = 1; i <= mNumVars; ++i) {
-      MATHICGB_ASSERT(mWeights[i - 1] == -1);
-      if (v1[i] < v2[i])
-        weight -= t1[i] = u1[i] + v2[i] - v1[i];
-      else
-        weight -= t1[i] = u1[i];
-    }
-#ifdef DEBUG
-    setWeightsOnly(t1);
-    MATHICGB_ASSERT(t1[mNumVars + 1] == weight);
-#endif
-    t1[mNumVars + 1] = weight;
-  } else {
-    for (size_t i = 1; i <= mNumVars; ++i) {
-        if (v1[i] < v2[i])
-          t1[i] = u1[i] + v2[i] - v1[i];
-        else
-          t1[i] = u1[i];
-    }
-    setWeightsOnly(t1);
-  }
-}
-
-size_t PolyRing::monomialSizeOfSupport(const_monomial m) const {
-  size_t support = 0;
-  for (size_t i = 1; i <= mNumVars; ++i)
-    if (m[i] != 0)
-      ++support;
-  return support;
-}
-
-void PolyRing::monomialGreatestCommonDivisor(const_monomial a, const_monomial b, monomial g) const {
-  *g = 0;
-  for (size_t i = 1; i <= mNumVars; ++i)
-    g[i] = std::min(a[i], b[i]);
-  setWeightsOnly(g);
-}
-
-void PolyRing::monomialRead(std::istream &I, monomial &result) const
-{
-  // format is as stated in PolyRing.h
-  int len;
-  I >> *result; // component
-  I >> len; // nterms of monomial
-  for (size_t i=1; i<=mNumVars; i++)
-    result[i] = 0;
-  for (int i=len; i>0; --i)
-    {
-      int v;
-      exponent e;
-      I >> v;
-      I >> e;
-      result[v+1] = e;
-    }
-  setWeightsAndHash(result);
-}
-void PolyRing::monomialWrite(std::ostream &o, const_monomial monom) const
-{
-  int len = 0;
-  for (size_t i=1; i<=mNumVars; i++)
-    if (monom[i] != 0) len++;
-  o << *monom << " " << len; // the component
-  monom++;
-  for (size_t i = mNumVars - 1; i != static_cast<size_t>(-1); --i)
-    if (monom[i] != 0)
-      o << " " << i << " " << monom[i];
-}
-
-// The following two read/write monomials in the form:
-//  letter number letter number ... letter number < number >
-// allowed letters: a-zA-Z
-// also allowed instead of letter: [ number ], [0] refers to first var, etc.
-// What about errors??
-void PolyRing::monomialParse(std::istream &i, monomial &result) const
-{
-  // first initialize result:
-  for (size_t j=0; j<mMaxMonomialSize; j++) result[j] = 0;
-
-  exponent e;
-  int v, x;
-  // now look at the next char
-  for (;;)
-    {
-      char next = i.peek();
-      if (isalpha(next))
-        {
-          // determine variable
-          v = next - 'a';
-          if (v > 25 || v < 0)
-            v = next - 'A' + 26;
-          if (v < 0 || v > 51)
-            std::cerr << "variable out of range" << std::endl;
-          i.get(); // move past the letter
-          next = i.peek();
-          e = 1;
-          if (isdigit(next))
-            {
-              i >> e;
-            }
-          result[v+1] = e;
-        }
-      else if (next == '<')
-        {
-          // get component
-          i.get();
-          i >> x;
-          *result = x; // place component
-          if (i.peek() == '>') i.get();
-        }
-      else
-        {
-          break; // We assume that we are at the end of the monomial
-        }
-    }
-  setWeightsAndHash(result);
-}
-
-void PolyRing::monomialDisplay(std::ostream &o, const_monomial a, bool print_comp, bool print_one) const
-{
-  // We display a monomial in the form that can be used with monomialParse
-  // print_one: only is consulted in print_comp is false.
-
-  bool printed_any = false;
-  for (size_t i=0; i<mNumVars; i++)
-    if (a[i+1] > 0)
-      {
-        printed_any = true;
-        if (i <= 25)
-          o << static_cast<unsigned char>('a' + i);
-        else
-          o << static_cast<unsigned char>('A' + (i - 26));
-        if (a[i+1] >= 2)
-          o << a[i+1];
-      }
-  if (print_comp)
-    o << '<' << *a << '>';
-  else if (!printed_any && print_one)
-    o << "1";
-}
-
-void PolyRing::printMonomialFrobbyM2Format(std::ostream& out, const_monomial m) const {
-  out << "  ";
-  bool isOne = true;
-  for (size_t i = 0; i < mNumVars; ++i) {
-    auto e = m[i + 1];
-    if (e == 0)
-      continue;
-    if (!isOne)
-      out << '*';
-    else
-      isOne = false;
-    out << 'x' << (i + 1) << '^' << e;
-  }
-  if (isOne)
-    out << '1';
-}
-#endif
-
 PolyRing *PolyRing::read(std::istream &i)
 {
   int64 characInt;
diff --git a/src/mathicgb/PolyRing.hpp b/src/mathicgb/PolyRing.hpp
index 6d65d0f..a09d0ee 100755
--- a/src/mathicgb/PolyRing.hpp
+++ b/src/mathicgb/PolyRing.hpp
@@ -3,8 +3,6 @@
 #ifndef _polyRing_h_
 #define _polyRing_h_
 
-#define NEWMONOMIALS 1
-
 #include <assert.h>
 #include <string>
 #include <vector>
@@ -190,13 +188,8 @@ inline const Monomial& ConstMonomial::castAwayConst() const
   return reinterpret_cast<const Monomial&>(*this);
 }
 
-#ifdef NEWMONOMIALS
-  typedef Monomial monomial;
-  typedef ConstMonomial const_monomial;
-#else
-  typedef exponent *monomial; // a power product in the ring
-  typedef const exponent * const_monomial;
-#endif
+typedef Monomial monomial;
+typedef ConstMonomial const_monomial;
 
 struct const_term {
   const_coefficient coeff;
@@ -287,18 +280,8 @@ public:
   // Only call this method for monomials returned by allocMonomial().
   void freeMonomial(Monomial m) const {mMonomialPool.free(m.unsafeGetRepresentation());}
 
-#ifdef NEWMONOMIALS
-  // Free monomials allocated here by calling freeMonomial().
-  monomial allocMonomial() const { return allocMonomial(mMonomialPool); }
-#else
-  // Free monomials allocated here by calling freeMonomial().
-  monomial allocMonomial() const {
-    return static_cast<monomial>(mMonomialPool.alloc());
-  }
-
-  // Only call this method for monomials returned by allocMonomial().
-  void freeMonomial(monomial m) const {mMonomialPool.free(m);}
-#endif
+// Free monomials allocated here by calling freeMonomial().
+monomial allocMonomial() const { return allocMonomial(mMonomialPool); }
 
 
 
@@ -532,88 +515,6 @@ public:
   ///////////////////////////////////////////
   ///////////////////////////////////////////
 
-#ifndef NEWMONOMIALS
-  int monomialCompare(const_monomial a, const_monomial b) const; // returns LT, EQ or GT
-  int monomialCompare(const_monomial sig, const_monomial m2, const_monomial sig2) const;
-  // returns LT, EQ, or GT, depending on sig ? (m2 * sig2).
-  bool monomialLT(const_monomial a, const_monomial b) const {
-    for (size_t i = mTopIndex; i != static_cast<size_t>(-1); --i)
-      {
-        auto cmp = a[i] - b[i];
-        if (cmp == 0) continue;
-        if (cmp < 0) return false;
-        return true;
-      }
-    return false;
-  }
-  bool monomialEQ(const_monomial a, const_monomial b) const;
-
-  size_t monomialSize(const_monomial) const { return mMaxMonomialSize; }
-  int monomialGetComponent(const_monomial a) const { return *a; }
-  void monomialChangeComponent(monomial a, int x) const {
-    a[mHashIndex] -= *a;
-    a[mHashIndex] += x;
-    *a = x;
-  }
-
-  void monomialSetIdentity(monomial& result) const;
-  void monomialEi(size_t i, monomial &result) const;
-  void monomialMult(const_monomial a, const_monomial b, monomial &result) const;
-  bool monomialDivide(const_monomial a, const_monomial b, monomial &result) const;
-  // returns truue if b divides a, in this case, result is set to b//a.
-  void monomialDivideToNegative(const_monomial a, const_monomial b, monomial result) const;
-  // sets result to a/b, even if that produces negative exponents.
-
-  bool monomialIsDivisibleBy(const_monomial a, const_monomial b) const;
-  // returns true if b divides a.  Components are ignored.
-
-  void monomialMultTo(monomial a, const_monomial b) const; // a *= b
-  void monomialCopy(const_monomial a, monomial &result) const;
-  void monomialQuotientAndMult(const_monomial a, const_monomial b, const_monomial c, monomial result) const;
-  // result is set to (a//b) * c
-
-  inline bool monomialRelativelyPrime(const_monomial a, const_monomial b) const;
-  void monomialFindSignatures(const_monomial v1,
-                              const_monomial v2,
-                              const_monomial u1,
-                              const_monomial u2,
-                              monomial t1,
-                              monomial t2) const;  // answer into the already allocated t1,t2
-  // t1 := (v2:v1) u1
-  // t2 := (v1:v2) u2
-  void monomialFindSignature(const_monomial v1,
-                              const_monomial v2,
-                              const_monomial u1,
-                              monomial t1) const; // answer into the already allocated t1
-
-  size_t monomialSizeOfSupport(const_monomial m) const;
-
-  void monomialGreatestCommonDivisor(const_monomial a, const_monomial b, monomial g) const;
-  inline void monomialLeastCommonMultiple(const_monomial a, const_monomial b, monomial l) const;
-  inline void monomialLeastCommonMultipleNoWeights(const_monomial a, const_monomial b, monomial l) const;
-  bool monomialIsLeastCommonMultiple(const_monomial a, const_monomial b, const_monomial l) const;
-  bool monomialIsLeastCommonMultipleNoWeights(const_monomial a, const_monomial b, const_monomial l) const;
-
-  // Returns true if there is a variable var such that hasLarger raises var to
-  // a strictly greater exponent than both smaller1 and smaller2 does.
-  inline bool monomialHasStrictlyLargerExponent(
-    const_monomial hasLarger,
-    const_monomial smaller1,
-    const_monomial smaller2) const;
-
-  void monomialRead(std::istream &i, monomial &result) const;
-  void monomialWrite(std::ostream &o, const_monomial a) const;
-
-  void monomialParse(std::istream &i, monomial &result) const;
-  void monomialDisplay(std::ostream&o, const_monomial a, bool print_comp=true, bool print_one=true) const;
-
-  void printMonomialFrobbyM2Format(std::ostream& out, const_monomial m) const;
-
-  void setWeightsAndHash(monomial a) const;
-  inline void setWeightsOnly(monomial a) const;
-  bool weightsCorrect(const_monomial a) const;
-#endif
-
   struct coefficientStats {
     size_t n_addmult;
     size_t n_add;
@@ -936,127 +837,6 @@ inline bool PolyRing::monomialHasStrictlyLargerExponent(
 // Old Monomial Routines ///////////////////////
 ////////////////////////////////////////////////
 
-#ifndef NEWMONOMIALS
-inline bool PolyRing::monomialIsDivisibleBy(const_monomial a, const_monomial b) const
-{
-  // returns truue if b divides a, in this case, result is set to b//a.
-  //  for (int i = mNumVars; i >= 1; --i)
-  //    {
-  //      int c = a[i] - b[i];
-  //      if (c < 0) return false;
-  //    }
-  for (size_t i = 1; i<= mNumVars; i++)
-    if (a[i] < b[i])
-      return false;
-
-  return true;
-}
-
-inline void PolyRing::monomialDivideToNegative(const_monomial a, const_monomial b, monomial result) const {
-  for (size_t i = 0; i <= this->mTopIndex; ++i)
-    result[i] = a[i] - b[i];
-}
-
-inline bool PolyRing::monomialDivide(const_monomial a, const_monomial b, monomial &result) const
-{
-  //// returns true if b divides a, in this case, result is set to b//a.
-  //  for (int i = mNumVars; i >= 1; --i)
-  //    {
-  //      int c = a[i] - b[i];
-  //      if (c >= 0)
-  //    result[i] = c;
-  //      else
-  //    return false;
-  //    }
-  //// at this point we have divisibility, so need to fill in the rest of the monomial
-  //  *result = *a - *b;  // component
-  //  for (int i=mHashIndex; i>mNumVars; --i)
-  //    result[i] = a[i] - b[i];
-  //  return true;
-
-  size_t i;
-  for (i = 1; i <= mNumVars; i++)
-    {
-      auto c = a[i] - b[i];
-      if (c >= 0)
-        result[i] = c;
-      else
-        return false;
-    }
-  // at this point we have divisibility, so need to fill in the rest of the monomial
-  *result = *a - *b;  // component
-  for ( ; i<=mHashIndex; i++)
-    result[i] = a[i] - b[i];
-  return true;
-}
-
-inline int PolyRing::monomialCompare(const_monomial a, const_monomial b) const
-// returns LT, EQ or GT
-{
-  for (size_t i = mTopIndex; i != static_cast<size_t>(-1); --i)
-    {
-      //      if (a[i] == b[i]) continue;
-      //      if (a[i] < b[i]) return GT;
-      //      return LT;
-      //      if (a[i] > b[i]) return LT;
-            auto cmp = a[i] - b[i];
-            if (cmp < 0) return GT;
-            if (cmp > 0) return LT;
-    }
-  return EQ;
-}
-
-inline void PolyRing::monomialLeastCommonMultiple(
-  const_monomial a,
-  const_monomial b,
-  monomial l) const
-{
-  monomialLeastCommonMultipleNoWeights(a, b, l);
-  setWeightsAndHash(l);
-}
-
-inline void PolyRing::monomialLeastCommonMultipleNoWeights(
-  const_monomial a,
-  const_monomial b,
-  monomial l) const
-{
-  *l = 0;
-  for (size_t i = 1; i <= mNumVars; ++i)
-    l[i] = std::max(a[i], b[i]);
-}
-
-inline bool PolyRing::monomialHasStrictlyLargerExponent(
-  const_monomial hasLarger,
-  const_monomial smaller1,
-  const_monomial smaller2) const {
-  for (size_t i = 1; i <= mNumVars; ++i)
-    if (hasLarger[i] > smaller1[i] && hasLarger[i] > smaller2[i])
-      return true;
-  return false;
-}
-
-inline void PolyRing::setWeightsOnly(monomial a) const
-{
-  a++;
-  auto wts = mWeights.data();
-  for (size i = 0; i < mNumWeights; ++i) {
-    exponent result = 0;
-    for (size_t j=0; j<mNumVars; ++j)
-      result += *wts++ * a[j];
-    a[mNumVars+i] = result;
-  }
-}
-
-inline bool PolyRing::monomialRelativelyPrime(const_monomial a, const_monomial b) const
-{
-  for (size_t i = 1; i <= mNumVars; ++i)
-    if (a[i] > 0 && b[i] > 0)
-      return false;
-  return true;
-}
-
-#endif
-
 inline bool PolyRing::monomialIsLeastCommonMultiple(
   ConstMonomial a,
   ConstMonomial b,
diff --git a/src/mathicgb/io-util.cpp b/src/mathicgb/io-util.cpp
index 4ee3b4c..1e30596 100755
--- a/src/mathicgb/io-util.cpp
+++ b/src/mathicgb/io-util.cpp
@@ -60,25 +60,6 @@ std::string monomialToString(const PolyRing *R, const Monomial& mon)
   return o.str();
 }
 
-///////// Which of the following do we need/use? /////////////
-#ifndef NEWMONOMIALS
-monomial monomialFromString(const PolyRing *R, std::string mon)
-{
-  // This is poor code, to only be used for testing!
-  monomial result = new int[R->maxMonomialSize()];
-  std::stringstream ifil(mon);
-  R->monomialRead(ifil, result);
-  return result;
-}
-
-std::string monomialToString(const PolyRing *R, const_monomial mon)
-{
-  std::ostringstream o;
-  R->monomialWrite(o,mon);
-  return o.str();
-}
-#endif
-
 monomial monomialParseFromString(const PolyRing *R, std::string mon)
 {
   // This is poor code, to only be used for testing!

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mathicgb.git



More information about the debian-science-commits mailing list