Macaulay2 Engine
Loading...
Searching...
No Matches
BasicPolyList.hpp
Go to the documentation of this file.
1
35
36// BasicPolyList is a vector of polynomials (with components)
37// which we can easily translate to and from other polynomial and matrix types.
38// This class really doesn't require any ring.
39// Current restriction: the coefficients must be an integral type. TODO: allow infinite precision integers too.
40// TODO: how should we handle coefficients which are: GF(p^n), QQ, fraction fields? or even polynomials?
41#pragma once
42
43#include "exceptions.hpp"
44
45#include <stdexcept>
46#include <string>
47#include <vector>
48#include <iostream>
49
50#include "BasicPoly.hpp"
51#include "PolynomialStream.hpp"
52
53class FreeModule;
54class Matrix;
55
56using BasicPolyList = std::vector<BasicPoly>;
57
58long bytesUsed(const BasicPolyList& F);
59
76{
77public:
78 using Coefficient = mpz_class;
79 using VarIndex = int32_t; // TODO: these must match BasicPoly above.
80 using Exponent = int32_t;
81 using Component = int32_t;
82 using ModulusType = int32_t;
83private:
85
86 // We store these, as we need to be able to respond to what they are,
87 // but we don't use them here at all.
91
92 // State during the construction
96
97public:
98 // modulus, varCount, comCount can be set to 0, they are not used in this class.
99 BasicPolyListStreamCollector(); // Set the three variables all to 0.
102
104 {
105 return mValue;
106 }
107
108 // Fields required for the general stream interface (see mathicgb::mathicgb.h)
109
110 ModulusType modulus() const { return mModulus; }
111 VarIndex varCount() const { return mVarCount; }
112 Component comCount() const { return mComCount; }
113
114 void idealBegin(size_t polyCount);
115 void appendPolynomialBegin(size_t termCount);
116 void appendTermBegin(Component com);
117 void appendExponent(VarIndex index, Exponent exponent);
118 void appendTermDone(const Coefficient& coefficient);
120 void idealDone();
121};
122
123//template<newf4::PolynomialStream S>
124template<typename S>
125void toStream(const BasicPolyList& Fs, S &str)
126{
127 str.idealBegin(Fs.size());
128 for (auto& F : Fs)
129 {
130 str.appendPolynomialBegin(F.mCoefficients.size());
131 int monomStart = 0;
132 for (auto i=0; i<F.mCoefficients.size(); ++i)
133 {
134 auto monomEnd = monomStart + F.mMonomials[monomStart];
135 if (F.mComponents.empty())
136 str.appendTermBegin(0);
137 else
138 str.appendTermBegin(F.mComponents[i]);
139 for (auto j=monomStart+1; j<monomEnd; j += 2)
140 str.appendExponent(F.mMonomials[j], F.mMonomials[j+1]);
141 str.appendTermDone(F.mCoefficients[i]);
142 monomStart = monomEnd;
143 }
144 str.appendPolynomialDone();
145 }
146 str.idealDone();
147}
148
149const Matrix* toMatrix(const FreeModule *target, const BasicPolyList& Fs);
150
151// The following can certainly throw an error. You need to check that!
152auto basicPolyListFromString(std::vector<std::string> varNames, std::string polyPerLine) -> BasicPolyList;
153auto basicPolyListFromFile(std::vector<std::string> varNames, std::string fileName) -> BasicPolyList;
154
155// Local Variables:
156// indent-tabs-mode: nil
157// End:
Minimal, portable polynomial value type used where heavier engine types would be overkill.
std::vector< BasicPoly > BasicPolyList
auto basicPolyListFromString(std::vector< std::string > varNames, std::string polyPerLine) -> BasicPolyList
auto basicPolyListFromFile(std::vector< std::string > varNames, std::string fileName) -> BasicPolyList
long bytesUsed(const BasicPolyList &F)
const Matrix * toMatrix(const FreeModule *target, const BasicPolyList &Fs)
void toStream(const BasicPolyList &Fs, S &str)
Type aliases and the (currently disabled) C++20 concept that streaming polynomial consumers implement...
void appendTermDone(const Coefficient &coefficient)
void idealBegin(size_t polyCount)
void appendExponent(VarIndex index, Exponent exponent)
void appendPolynomialBegin(size_t termCount)
BasicPolyListStreamCollector(Coefficient modulus, VarIndex varCount, Component comCount)
void appendTermBegin(Component com)
Engine-side free module R^n over a Ring.
Definition freemod.hpp:66
namespace exc — internal C++ exception types and the TRY / CATCH macro pair.
int * exponent
Definition exptable.h:34
#define Matrix
Definition factory.cpp:14