Ejemplo n.º 1
0
 RingElem monic(ConstRefRingElem f)
 {
   const PolyRing Rx = owner(f);
   RingElem ans(Rx);
   Rx->myMonic(raw(ans), raw(f));
   return ans;
 }
Ejemplo n.º 2
0
void ReducerPackDedup<Q>::MultipleWithPos::addCurrentCoefficient(
  const PolyRing& ring,
  Coefficient& coeff
) {
  Coefficient tmp;
  ring.coefficientMult(multiple.coef, pos.coef(), tmp);
  ring.coefficientAddTo(coeff, tmp);
}
Ejemplo n.º 3
0
 RingElem IndetPower(const PolyRing& P, long var, long exp)  // error if exp < 0
 {
   P->myCheckIndetIndex(var, "IndetPower(P, var, exp)");
   if (exp < 0) CoCoA_ERROR(ERR::NegExp, "IndetPower(P, var, exp)");
   RingElem ans(P, 1);
   P->myIndetPower(raw(ans), var, exp);
   return ans;
 }
Ejemplo n.º 4
0
void TournamentReducer::MultipleWithPos::destroy(const PolyRing& ring) {
  ring.freeMonomial(current);
  ring.freeMonomial(const_cast<ConstMonomial&>(multiple.monom).castAwayConst());

  // Call the destructor to destruct the iterators into std::vector.
  // In debug mode MSVC puts those in a linked list and the destructor
  // has to be called since it takes an iterator off the list. We had
  // memory corruption problems before doing this.
  this->~MultipleWithPos();
}
Ejemplo n.º 5
0
void ReducerPack<Q>::MultipleWithPos::destroy(const PolyRing& ring) {
  ring.monoid().freeRaw(*current);
  ring.monoid().freeRaw(*multiple.mono);

  // Call the destructor to destruct the iterators into std::vector.
  // In debug mode MSVC puts those in a linked list and the destructor
  // has to be called since it takes an iterator off the list. There were
  // memory corruption problems in debug mode before doing this on MSVC.
  this->~MultipleWithPos();
}
Ejemplo n.º 6
0
 RingElem deriv(ConstRefRingElem f, ConstRefRingElem x)
 {
   if (owner(x) != owner(f)) CoCoA_ERROR(ERR::MixedRings, "deriv(f, x)");
   if (IsFractionField(owner(f))) return DerivFrF(f,x);
   // From here on we are in the "polynomial" case.
   if (!IsIndet(x)) CoCoA_ERROR(ERR::NotIndet, "deriv(f,x)");
   const PolyRing Rx = owner(f);
   RingElem ans(Rx);
   Rx->myDeriv(raw(ans), raw(f), raw(x));
   return ans;
 }
Ejemplo n.º 7
0
void program()
{
  // This test is for testing printing functions
  GlobalManager CoCoAFoundations;


  PolyRing R = NewPolyRing(RingQQ(), symbols("a","b")); // QQ[a,b]
  ring K = NewFractionField(R); // QQ(a,b)
  PolyRing Kxy = NewPolyRing(K, symbols("x", "y"));
  RingHom f = CanonicalHom(R,K);
  RingHom g = CanonicalHom(K,Kxy);
  RingHom h = g(f);
  RingElem a = RingElem(R, symbol("a"));
  RingElem b = RingElem(R, symbol("b"));
  RingElem Inv_a = 1/f(a);
  RingElem x = RingElem(Kxy, symbol("x"));
  RingElem Inv_a_x = g(Inv_a)*x;
  
  //  std::cout << 2*a/3-1 << std::endl;
  //  std::cout << 2*h(a)*x-1 << std::endl;
  
  { ostringstream s;  s << a/2;          TEST_ASSERT(s.str() == "(1/2)*a"); }
  { ostringstream s;  s << -a/3;         TEST_ASSERT(s.str() == "(-1/3)*a"); }
  { ostringstream s;  s << -x/3;         TEST_ASSERT(s.str() == "(-1/3)*x"); }
  { ostringstream s;  s << h(-a)*x*x + h(1-a)*x + h(1-a);
    TEST_ASSERT(s.str() == "-a*x^2 +(-a +1)*x -a +1"); }
  { ostringstream s;  s << x - h(a*b);   TEST_ASSERT(s.str() == "x -a*b"); }
  { ostringstream s;  s << -x;           TEST_ASSERT(s.str() == "-x"); }
  { ostringstream s;  s << -x+1;         TEST_ASSERT(s.str() == "-x +1"); }
  { ostringstream s;  s << x-1;          TEST_ASSERT(s.str() == "x -1"); }
  { ostringstream s;  s << x- h(a);      TEST_ASSERT(s.str() == "x -a"); }
  { ostringstream s;  s << 1/f(a);       TEST_ASSERT(s.str() == "1/a"); }
  { ostringstream s;  s << 1/h(a);       TEST_ASSERT(s.str() == "1/a"); }
  { ostringstream s;  s << g(1/f(a))*x;  TEST_ASSERT(s.str() == "(1/a)*x"); }
  { ostringstream s;  s << h(a)*x;       TEST_ASSERT(s.str() == "a*x"); }
  { ostringstream s;  s << x/(-1);       TEST_ASSERT(s.str() == "-x"); }
  { ostringstream s;  s << x-one(Kxy)/2; TEST_ASSERT(s.str() == "x -1/2"); }
  { ostringstream s;  s << x-h(a/2);     TEST_ASSERT(s.str() == "x -a/2"); }
  { ostringstream s;  s << x-h(a)/2;     TEST_ASSERT(s.str() == "x -a/2"); }
  { ostringstream s;  s << x-h(a+1)/2;   TEST_ASSERT(s.str() == "x +(-a -1)/2"); }
  { R->myOutputSelfLong(std::cout); }
  { std::cout << std::endl; }
  { NewPolyRing(R, SymbolRange("x",1,3))->myOutputSelfLong(std::cout); }
  { std::cout << std::endl; }
  { NewPolyRing(NewFractionField(R), SymbolRange("x",1,3))->myOutputSelfLong(std::cout); }
  { std::cout << std::endl; }
  { NewPolyRing(NewQuotientRing(R,ideal(ReadExpr(R,"a^2-2"))), SymbolRange("x",1,3))->myOutputSelfLong(std::cout); }
  { std::cout << std::endl; }
  
  //  std::cout << x-h(a)/2 << std::endl;

}
Ejemplo n.º 8
0
 RingHom EvalHom(const PolyRing& Rx, const BigRat& q)     // Maps f in R[x] into f(q) in R
 {
   if (NumIndets(Rx) != 1) CoCoA_ERROR(ERR::BadArg, "EvalHom(Rx,N)");
   const ring& R = CoeffRing(Rx);
   const vector<RingElem> IndetImage(1, RingElem(R,q));
   return Rx->myHomCtor(R, IdentityHom(R), IndetImage);
 }
Ejemplo n.º 9
0
 RingHom EvalHom(const PolyRing& Rx, ConstRefRingElem r)  // Maps f in R[x] into f(r) in R
 {
   if (NumIndets(Rx) != 1) CoCoA_ERROR(ERR::BadArg, "EvalHom(Rx,r)");
   const ring& R = CoeffRing(Rx);
   if (owner(r) != R) CoCoA_ERROR(ERR::MixedRings, "EvalHom(Rx,r");
   const vector<RingElem> IndetImage(1, r);
   return Rx->myHomCtor(R, IdentityHom(R), IndetImage);
 }
Ejemplo n.º 10
0
void ReducerPackDedup<Q>::MultipleWithPos::destroy(const PolyRing& ring) {
  MultipleWithPos* entry = this;
  do {
    ring.monoid().freeRaw(*entry->current);
    ring.monoid().freeRaw(*entry->multiple.mono);
    MultipleWithPos* next = entry->chain;
    MATHICGB_ASSERT(next != 0);

    // Call the destructor to destruct the iterators into std::vector.
    // In debug mode MSVC puts those in a linked list and the destructor
    // has to be called since it takes an iterator off the list. There were
    // memory corruption problems in debug mode on MSVC before doing this.
    entry->~MultipleWithPos();

    entry = next;
  } while (entry != this);
}
Ejemplo n.º 11
0
MATHICGB_NAMESPACE_BEGIN

SigPolyBasis::SigPolyBasis(
  const PolyRing& R0,
  int monoLookupType,
  int monTableType,
  bool preferSparseReducers
):
  mMonoLookupFactory
    (MonoLookup::makeFactory(R0.monoid(), monoLookupType)),
  mRatioSorted(RatioOrder(mSigLeadRatio, R0.monoid())),
  mMinimalMonoLookup(mMonoLookupFactory->make(preferSparseReducers, true)),
  mBasis(R0, mMonoLookupFactory->make(preferSparseReducers, true)),
  mPreferSparseReducers(preferSparseReducers)
{
  mTmp = mBasis.ring().allocMonomial();
  const_cast<MonoLookup&>(mBasis.monoLookup()).setSigBasis(*this);
  mMinimalMonoLookup->setSigBasis(*this);
}
Ejemplo n.º 12
0
  RingElem ClearDenom(ConstRefRingElem f)
  {
    if (!IsPolyRing(owner(f)))
      CoCoA_ERROR(ERR::NotElemPolyRing, "ClearDenom(f)");
    const PolyRing Qx = owner(f);
    const ring Q = CoeffRing(Qx);
    if (!IsFractionField(Q))
      CoCoA_ERROR(ERR::NotTrueGCDDomain, "CoeffRing inside ClearDenom(f)");
    const ring R = BaseRing(Q);
    if (!IsTrueGCDDomain(R))
      CoCoA_ERROR(ERR::NotTrueGCDDomain, "BaseRing of CoeffRing inside ClearDenom(f)");
//     if (IsField(R))  // see documentation (Bugs section)
//       CoCoA_ERROR(ERR::NotTrueGCDDomain, "content(f)");
    if (IsZero(f)) return zero(Qx);

    RingElem ans(Qx);
    Qx->myClearDenom(raw(ans), raw(f));
    return ans;
  }
Ejemplo n.º 13
0
  RingHom EvalHom(const PolyRing& Rx, const std::vector<RingElem>& IndetImages)
  {
    const char* const FnName = "EvalHom(Rx,IndetImages)";
    const ring& R = CoeffRing(Rx);
    if (NumIndets(Rx) != len(IndetImages))
      CoCoA_ERROR(ERR::BadPolyRingHomImages, FnName);
    for (long i=0; i < NumIndets(Rx); ++i)
      if (owner(IndetImages[i]) != R)
        CoCoA_ERROR(ERR::BadPolyRingHomImages, FnName);

    return Rx->myHomCtor(R, IdentityHom(R), IndetImages);
  }
Ejemplo n.º 14
0
  RingElem content(ConstRefRingElem f)
  {
    if (!IsPolyRing(owner(f)))
      CoCoA_ERROR(ERR::NotElemPolyRing, "content(f)");
    const PolyRing Rx = owner(f);
    const ring R = CoeffRing(Rx);

    if (IsFractionFieldOfGCDDomain(R))
    {
      if (IsZero(f)) return zero(R);
      RingElem ans(R);
      Rx->myContentFrF(raw(ans), raw(f));
      return ans;
    }
    if (IsTrueGCDDomain(R))
    {
      if (IsZero(f)) return zero(R);
      RingElem ans(R);
      Rx->myContent(raw(ans), raw(f));
      return ans;
    }
    CoCoA_ERROR(ERR::NotTrueGCDDomain, "content(f)");
    return zero(R); // never reached, just to keep compiler quiet
  }
Ejemplo n.º 15
0
  // Rx is the domain, S is the codomain
  RingHom PolyRingHom(const PolyRing& Rx, const ring& S, RingHom CoeffHom, const std::vector<RingElem>& IndetImages)
  {
    const char* const FnName = "PolyRingHom(Rx,S,CoeffHom,IndetImages)";
    if (domain(CoeffHom) != CoeffRing(Rx))
      CoCoA_ERROR(ERR::MixedCoeffRings, FnName);
    if (IsPolyRing(S) && codomain(CoeffHom) == CoeffRing(S))
      CoeffHom = CoeffEmbeddingHom(S)(CoeffHom);
    if (codomain(CoeffHom) != S)
      CoCoA_ERROR(ERR::BadCodomain, FnName);
    if (NumIndets(Rx) != len(IndetImages))
      CoCoA_ERROR(ERR::BadPolyRingHomImages, FnName);
    for (long i=0; i < NumIndets(Rx); ++i)
      if (owner(IndetImages[i]) != S)
        CoCoA_ERROR(ERR::BadPolyRingHomImages, FnName);

    return Rx->myHomCtor(S, CoeffHom, IndetImages);
  }
Ejemplo n.º 16
0
  RingHom PolyAlgebraHom(const PolyRing& Rx, const ring& Ry, const std::vector<RingElem>& IndetImages)
  {
    const char* const FnName = "PolyAlgebraHom(Rx,Ry,IndetImages)";
    // Check that IndetImages are sensible...
    if (NumIndets(Rx) != len(IndetImages))
      CoCoA_ERROR(ERR::BadPolyRingHomImages, FnName);
    for (long i=0; i < NumIndets(Rx); ++i)
      if (owner(IndetImages[i]) != Ry)
        CoCoA_ERROR(ERR::BadPolyRingHomImages, FnName);
//     // Special case: codomain is coeff ring.
//     if (Ry == CoeffRing(Rx))
//       return Rx->myHomCtor(Ry, IdentityHom(Ry), IndetImages);
//     // General case: codomain must be a poly ring with same coeffs
//     if (!IsPolyRing(Ry))
//       CoCoA_ERROR(ERR::BadCodomain, FnName);
//     if (CoeffRing(Rx) != CoeffRing(Ry))
//       CoCoA_ERROR(ERR::MixedCoeffRings, FnName);
//    return Rx->myHomCtor(Ry, CoeffEmbeddingHom(Ry), IndetImages);
    return Rx->myHomCtor(Ry, CanonicalHom(CoeffRing(Rx),Ry), IndetImages);
  }
Ejemplo n.º 17
0
void ilio(Mat &M, PolyElement &f, MatDom &MD, PolyRing &R) {
	IliopoulosDom sfi(R);
	
	size_t n = M.coldim();
	Mat A(MD.field(), n, n);
	MD.copy(A, M);
	
	FactorVector l;
	l.resize(n);
	
	Timer timer;
	timer.start();
	sfi.smithForm(l, A, f);
	timer.stop();
	cout << "Iliopolous Time: " << timer << endl;
	
	if (VERBOSE) {
		for (size_t i = 0; i < l.size(); i++) {
			R.write(cout, l[i]) << endl;
		}
		cout << endl;
	}
}
Ejemplo n.º 18
0
void TournamentReducer::MultipleWithPos::currentCoefficient
(const PolyRing& ring, coefficient& coeff) {
  ring.coefficientMult(multiple.coeff, pos.getCoefficient(), coeff);
}
Ejemplo n.º 19
0
void TournamentReducer::MultipleWithPos::computeCurrent(const PolyRing& ring) {
  ring.monomialMult(multiple.monom, pos.getMonomial(), current);  
}
Ejemplo n.º 20
0
void ReducerPack<Q>::MultipleWithPos::currentCoefficient
(const PolyRing& ring, coefficient& coeff) {
  ring.coefficientMult(multiple.coef, pos.coef(), coeff);
}
void L::initNiederreiter
(GeneratorMatrixGen<typename A::type> &gm, A a, int d,
 const typename PolynomialRing<A>::type &irred)
{
    typedef typename A::type T;
    typedef PolynomialRing<A> PolyRing;
    typedef typename PolyRing::type Poly;

    const int degree = irred.degree ();

    const int vSize
        = std::max (gm.getM() + degree - 1,   // these elements are copied to gm
                    (gm.getPrec() + degree + 1));  // used in the loop

    Array<T> v (vSize);
    PolyRing poly (a);

    // cout << "Using " << irred << " for d=" << d << endl;

    Poly newPoly = poly.one();

    int u = 0;

    for (int j = 0; j < gm.getPrec(); j++)
    {
        // cout << "  j=" << j << endl;
        // Do we need a new v?

        if (u == 0)
        {
            Poly oldPoly = newPoly;
            int oldDegree = oldPoly.degree ();

            // calculate polyK+1 from polyK

            poly.mulBy (newPoly, irred);
            int newDegree = newPoly.degree ();
            // cout << "    newPolynomial: " << newPoly << endl;

            // kj can be set to any value between 0 <= kj < newDegree

            const int kj = oldDegree   // proposed by BFN
                           // newDegree - 1    // standard, bad???
                           // 0
                           // (newDegree > 3) ? 3 : oldDegree
                           ;

            std::fill (&v[0], &v[kj], T());  // Set leading v's to 0

            v[kj] = a.one();                     // the next one is 1

            if (kj < oldDegree)
            {
                T term = oldPoly [kj];

                for (int r = kj + 1; r < oldDegree; ++r)
                {
                    v [r] = a.one (); // 1 is arbitrary. Could be 0, too

                    a.addTo (term, a.mul (oldPoly [r], v [r]));
                }

                // set v[] not equal to -term

                v [oldDegree] = a.sub (a.one(), term);

                for (int r = oldDegree + 1; r < newDegree; ++r) v [r] = a.one(); //or 0
            }
            else
            {
                for (int r = kj + 1; r < newDegree; ++r) v [r] = a.one(); // or 0..
            }

            // All other elements are calculated by a recursion parameterized
            // by polyK

            for (int r = 0; r < vSize - newDegree; ++r)
            {
                T term = T();

                for (int i = 0; i < newDegree; ++i)
                {
                    a.addTo (term, a.mul (newPoly [i], v [r+i]));
                }
                v [newDegree + r] = a.neg (term);
            }
        }

        // Set data in ci

        for (int r = 0; r < gm.getM(); ++r)  gm.setd (d,r,j, v[r+u]);

        if (++u == degree) u = 0;
    }
}
Ejemplo n.º 22
0
 RingElem deriv(ConstRefRingElem f, long x) // here x is the index of the variable
 {
   const PolyRing Rx = owner(f);
   Rx->myCheckIndetIndex(x, "deriv(f, x)");
   return deriv(f, indet(Rx, x));
 }
Ejemplo n.º 23
0
void ReducerPack<Q>::MultipleWithPos::computeCurrent(const PolyRing& ring) {
  ring.monoid().multiply(*multiple.mono, pos.mono(), *current);  
}
Ejemplo n.º 24
0
void generateM(
	Mat &M,
	MatDom &MD,
	PolyRing &R,
	PolyElement &f,
	PolyElement &g,
	size_t n,
	size_t e
) {
	integer max;
	R.convert(max, f);
	max *= 10;
	
	Mat L(R, n, n);
	for (size_t i = 0; i < n; i++) {
		for (size_t j = 0; j < i; j++) {
			PolyElement e;
			R.init(e, rand() % max);
			R.modin(e, f);
			L.setEntry(i, j, e);
		}
	}
	for (size_t i = 0; i < n; i++) {
		L.setEntry(i, i, R.one);
	}
	
	Mat T(R, n, n);
	for (size_t i = 0; i < n; i++) {
		for (size_t j = i+1; j < n; j++) {
			PolyElement e;
			R.init(e, rand() % max);
			R.modin(e, f);
			T.setEntry(i, j, e);
		}
	}
	for (size_t i = 0; i < n; i++) {
		T.setEntry(i, i, R.one);
	}
	
	Mat D(R, n, n);
	for (size_t i = 0; i < n; i++) {
		size_t ei = rand() % e;
		PolyElement di;
		R.assign(di, R.one);
		
		for (size_t j = 0; j < ei; j++) {
			R.mulin(di, g);
		}
		
		D.setEntry(i, i, di);
		if (VERBOSE > 1) {
			R.write(cout << i << ", " << i << ": ", di) << endl;
		}
	}
	
	MD.mul(M, L, D);
	MD.mulin(M, T);
	
	if (VERBOSE > 1) {
		cout << endl;
		for (size_t i = 0; i < n; i++) {
			for (size_t j = 0; j < n; j++) {
				PolyElement e;
				M.getEntry(e, i, j);
				R.write(cout << i << ", " << j << ": ", e) << endl;
			}
		}
	}
}
Ejemplo n.º 25
0
inline bool heapCompareFcn::operator()(heap_term &a, heap_term &b)
{
  PolyHeap::stats_static_n_compares++;
  return R->monomialLT(a.actual, b.actual);
}
Ejemplo n.º 26
0
 RingHom CoeffEmbeddingHom(const PolyRing& Rx)
 {
   return Rx->myCoeffEmbeddingHomCtor();
 }