46 o <<
"-- warning: experimental computation over inexact field begun"
48 o <<
"-- results not reliable (one warning given per "
99 int max_reduction_count)
116 max_reduction_count);
127 M2_bool use_max_slanted_degree,
128 int max_slanted_degree,
148 use_max_slanted_degree,
153 parallelizeByDegree);
168 if (
G->get_ring()->get_degree_ring() != h->
get_ring())
170 ERROR(
"expected Hilbert function hint to be in correct degree ring");
173 if (
G !=
nullptr)
return G->set_hilbert_function(h);
174 ERROR(
"computation type unknown or not implemented");
235 int basis_element_limit,
248 return G->set_stop_conditions(always_stop,
278 emit_line(
"computation stopped at degree limit");
281 emit_line(
"computation of GB completed");
284 emit_line(
"computation stopped at pair limit");
301 emit_line(
"computation stopped for some good reason");
304 emit_line(
"incorrect status code encountered");
309 return error() ? nullptr : C;
328 if (
G !=
nullptr)
return G->get_gb();
329 ERROR(
"computation type unknown or not implemented");
348 if (
G !=
nullptr)
return G->get_mingens();
349 ERROR(
"computation type unknown or not implemented");
369 if (
G !=
nullptr)
return G->get_change();
370 ERROR(
"computation type unknown or not implemented");
385 if (
G !=
nullptr)
return G->get_initial(nparts);
386 ERROR(
"computation type unknown or not implemented");
402 if (
G !=
nullptr)
return G->get_parallel_lead_terms(w);
403 ERROR(
"computation type unknown or not implemented");
423 if (
G !=
nullptr)
return G->get_syzygies();
424 ERROR(
"computation type unknown or not implemented");
440 if (
G !=
nullptr)
return G->matrix_remainder(m);
441 ERROR(
"computation type unknown or not implemented");
452 const Matrix **result_remainder,
453 const Matrix **result_quotient)
460 return G->matrix_lift(m, result_remainder, result_quotient);
462 ERROR(
"computation type unknown or not implemented");
476 if (
G !=
nullptr)
return G->contains(m);
477 ERROR(
"computation type unknown or not implemented");
492 if (
G !=
nullptr)
return G->get_matrix(level);
493 ERROR(
"expected resolution computation type");
510 if (
G !=
nullptr)
return G->get_matrix(level, degree);
511 ERROR(
"expected resolution computation type");
533 if (
G !=
nullptr)
return G->get_mutable_matrix(
R, level);
534 ERROR(
"expected fast nonminimal resolution computation type");
553 if (
G !=
nullptr)
return G->get_mutable_matrix(KK, level, degree);
554 ERROR(
"expected fast nonminimal resolution computation type");
569 if (
G !=
nullptr)
return G->get_free(level);
570 ERROR(
"expected resolution computation type");
580 int *complete_up_through_this_degree,
581 int *complete_up_through_this_level)
584 (void) complete_up_through_this_degree;
585 (void) complete_up_through_this_level;
587#warning "IM2_Resolution_status to be written"
589 ERROR(
"not re-implemented yet");
597 int *complete_up_through_this_degree)
602 (void) complete_up_through_this_degree;
604#warning "IM2_Resolution_status to be written"
606 ERROR(
"not re-implemented yet");
623 if (
G !=
nullptr)
return G->get_betti(type);
624 ERROR(
"expected resolution computation type");
643 o <<
"[unprintable gb]";
658 ERROR(
"expected a Groebner basis computation");
673 const RingMap *inclusionAmbient,
674 const RingMap *fullSubstitution,
675 const RingMap *substitutionInclusion,
683 if ((gbReductionIdeal ==
nullptr) || (gbI ==
nullptr))
685 ERROR(
"expected a Groebner basis computation");
688 return sagbi::subduct1(numparts, rawT, rawS, m, inclusionAmbient, fullSubstitution, substitutionInclusion, gbI, gbReductionIdeal);
704 ERROR(
"expected a polynomial ring");
709 ERROR(
"characteristic is too large for mathic gb computation");
715 mgb::GroebnerConfiguration configuration(
717 mgb::GroebnerInputIdealStream input(configuration);
719 std::ostringstream computedStr;
720 mgb::IdealStreamLog<> computed(
721 computedStr, charac,
nvars, inputMatrix->
n_rows());
722 mgb::IdealStreamChecker<
decltype(computed)> checked(computed);
726 std::cout <<
"result: " << std::endl;
727 std::cout << computedStr.str() << std::endl;
757 return StopWithNoOutputAction;
759 return ContinueAction;
770 std::vector<int> &mat,
771 bool &base_is_revlex,
772 int &component_direction,
773 int &component_is_before_row
779 const Matrix *inputMatrix,
791 ERROR(
"expected a polynomial ring");
796 ERROR(
"mgb: expected a non-negative number of threads");
801 ERROR(
"characteristic is too large for mathic gb computation");
807 "characteristic for mathic gb computation must be a prime "
813 ERROR(
"coefficients for mathic gb computation must be a prime field");
819 mgb::GroebnerConfiguration configuration(
820 charac, nvars, inputMatrix->
n_rows());
822 const auto reducerType = reducer == 0
823 ? mgb::GroebnerConfiguration::ClassicReducer
824 : mgb::GroebnerConfiguration::MatrixReducer;
825 configuration.setReducer(reducerType);
826 configuration.setMaxSPairGroupSize(spairGroupSize);
827 configuration.setMaxThreadCount(nthreads);
828 std::string log((
char *)logging->array, logging->len);
829 configuration.setLogging(log.c_str());
830 configuration.setCallback(&callback);
833 std::vector<int> mat;
834 bool base_is_revlex =
true;
835 int component_direction = 1;
836 int component_is_before_row = -1;
841 component_is_before_row))
844 "monomial ordering is not appropriate for Groebner basis "
848 if (!configuration.setMonomialOrder(
852 mgb::GroebnerConfiguration::BaseOrder::
853 RevLexDescendingBaseOrder
854 : mgb::GroebnerConfiguration::BaseOrder::
855 LexDescendingBaseOrder),
861 if (component_is_before_row >= 0)
862 configuration.setComponentBefore(component_is_before_row);
863 configuration.setComponentsAscending(component_direction == 1);
867 printf(
"Setting monomial order:");
868 for (
size_t i=0; i<mat.size(); i++) printf(
"%d ", mat[i]);
870 printf(
" Base=%d\n", base_is_revlex);
871 printf(
" ComponentBefore=%d\n", component_is_before_row);
872 std::cout <<
"componentBefore: " << configuration.componentBefore() << std::endl;
875 mgb::GroebnerInputIdealStream input(configuration);
877 std::ostringstream computedStr;
878 mgb::IdealStreamLog<> computed(
879 computedStr, charac, nvars, inputMatrix->
n_rows());
880 mgb::IdealStreamChecker<
decltype(computed)> checkedOut(computed);
885 mgb::computeGroebnerBasis(input, matStream);
888 ERROR(
"computation was interrupted");
896 }
catch (
const std::runtime_error& e)
913 for (
int i=0; i < input->
n_rows(); i++)
915 for (
int j=0; j < input->
n_cols(); ++j)
926template<
typename PolyL>
932 if (elems.size() != numrows*numcols)
933 ERROR(
"Number of elements in list does not match matrix size.");
935 for (
auto i = 0; i < elems.size(); ++i)
937 int curCol = i % numcols;
938 int curRow = (i - curCol) / numcols;
950 if (A !=
nullptr and input->
n_rows() == 1)
953 bool isF4 = strategy & 16;
954 bool isParallel = strategy & 32;
959 NCF4 G(A->
freeAlgebra(), elems, maxdeg, strategy, (isParallel ? numthreads : 1));
973 ERROR(
"expected a one row matrix over a noncommutative algebra");
982 ERROR(
"expected matrices to be over the same ring");
986 if (A !=
nullptr and reducerMatrix->
n_rows() == 1)
988 auto outRows = toBeReduced->
n_rows();
989 auto outCols = toBeReduced->
n_cols();
993 G.initReductionOnly();
994 auto result =
G.twoSidedReduction(reducees);
997 ERROR(
"expected a matrix over a noncommutative algebra");
1010 ERROR(
"internal error: expected non-null Ring!");
1030 if (not worked)
return nullptr;
1033 ERROR(
"expected a free algebra");
Older Schreyer-style kernel computation, predecessor of schreyer-resolution/.
Free associative algebra k<x_1,...,x_n> over an arbitrary coefficient ring.
PolyList copyPolyVector(const M2FreeAlgebraOrQuotient *A, const PolyList &polys)
Ring-shaped wrapper that exposes a non-commutative FreeAlgebra to the rest of the engine.
NCF4 — non-commutative F4 Gröbner-basis driver building a per-degree Macaulay matrix.
NCGroebner — Buchberger-style two-sided Gröbner basis driver over a FreeAlgebra.
gc_vector< const Poly * > ConstPolyList
Polynomial< CoefficientRingType > Poly
gc_vector< Poly * > PolyList
enum ComputationStatusCode status() const
virtual void text_out(buffer &o) const
virtual ResolutionComputation * cast_to_ResolutionComputation()
virtual GBComputation * cast_to_GBComputation()
virtual void start_computation()=0
virtual int complete_thru_degree() const =0
virtual void show() const
Abstract base for long-running, resumable engine computations (GBComputation, ResolutionComputation,...
ResolutionComputation subclass that drives the F4 resolution engine (SchreyerFrame + F4Res) from the ...
Engine-side free module R^n over a Ring.
static GBComputation * choose_gb(const Matrix *m, M2_bool collect_syz, int n_rows_to_keep, M2_arrayint gb_weights, M2_bool use_max_degree, int max_degree, int algorithm, int strategy, int numThreads, int max_reduction_count=10)
base class for Groebner basis computations.
static GBComputation * create(const Matrix *m, const Matrix *gb, const Matrix *change, const Matrix *syz)
Computes the kernel of a Schreyer-encoded GBMatrix and returns the syzygies in a Schreyer-compatible ...
static GBWalker * create(MarkedGB *G0, long **order1, long **order2)
const FreeAlgebra & freeAlgebra() const
Concrete Ring wrapper around an owned FreeAlgebra (no quotient).
Abstract Ring subclass that lifts either a FreeAlgebra or a FreeAlgebraQuotient into the engine's Rin...
bool wasInterrupted() const
mathicgb (mgb) callback that polls the engine's interrupt flag during a long-running GB computation.
const Ring * get_ring() const
ring_elem elem(int i, int j) const
const FreeModule * rows() const
void compute_column_degrees()
void set_entry(int r, int c, ring_elem a)
Mutable builder used to assemble an immutable Matrix one column (or one term) at a time.
const Matrix * value() const
Streaming consumer that builds an engine Matrix from the mathicgb-style stream callbacks (idealBegin ...
const MonomialOrdering * getMonomialOrdering() const
unsigned int hash() const
Abstract base class for mutable matrices over an arbitrary engine Ring, the in-place counterpart of t...
Non-commutative F4 Groebner-basis driver: builds a per-degree Macaulay matrix from overlaps and reduc...
One-overlap-at-a-time Groebner basis driver for the free associative algebra (the "Naive" companion t...
Concrete PolyRingFlat subclass implementing ordinary commutative polynomial rings K[x_1,...
const Ring * getCoefficientRing() const
virtual const Monoid * getMonoid() const
static ResolutionComputation * choose_res(const Matrix *m, M2_bool resolve_cokernel, int max_level, M2_bool use_max_slanted_degree, int max_slanted_degree, int algorithm, int strategy, int numThreads, M2_bool parallelizeByDegree)
Base class for free resolution computation classes.
virtual FreeModule * make_FreeModule() const
virtual const PolyRing * cast_to_PolyRing() const
virtual unsigned long get_precision() const
long characteristic() const
virtual const M2FreeAlgebra * cast_to_M2FreeAlgebra() const
virtual bool isFinitePrimeField() const
const Ring * get_ring() const
Front-end-visible "ring element" value: an engine ring_elem paired with the Ring* that gives it meani...
Engine-side ring homomorphism: stores, for each source-ring variable, the target-ring element it maps...
static RingElement * hilbertNumerator(const Matrix *M)
static ring_elem subduct(int numslots, const PolyRing *R, ring_elem f, const RingMap *phi, GBComputation *J)
static ring_elem subduct1(int numslots, const PolyRing *T, const PolyRing *S, ring_elem a, const RingMap *inclusionAmbient, const RingMap *fullSubstitution, const RingMap *substitutionInclusion, GBComputation *gbI, GBComputation *gbReductionIdeal)
GBDeclared — a user-asserted Groebner basis the engine accepts without computing.
GBComputation — abstract base of every Groebner-basis algorithm in the engine.
ResolutionComputation — abstract base for every free-resolution algorithm in the engine.
@ COMP_DONE_SUBRING_LIMIT
namespace exc — internal C++ exception types and the TRY / CATCH macro pair.
void gb(IntermediateBasis &F, int n)
GBWalker — generic Groebner-walk strategy that transports a basis between term orders.
const RingElement * IM2_Matrix_Hilbert(const Matrix *M)
Matrix * rawSubduction(int numparts, const Matrix *M, const RingMap *F, Computation *C)
ConstPolyList matrixToPolyList(const M2FreeAlgebraOrQuotient *A, const Matrix *input)
const Matrix * rawGBMinimalGenerators(Computation *C)
unsigned int rawComputationHash(const Computation *C)
const Matrix * polyListToMatrix(const M2FreeAlgebraOrQuotient *A, const PolyL &elems, int numrows, int numcols)
int IM2_GB_contains(Computation *C, const Matrix *m)
const Matrix * rawGBMatrixRemainder(Computation *C, const Matrix *m)
MutableMatrix * rawResolutionGetMatrix2(Computation *C, int level, int degree)
Computation * IM2_res_make(const Matrix *m, M2_bool resolve_cokernel, int max_level, M2_bool use_max_slanted_degree, int max_slanted_degree, int algorithm, int strategy, M2_bool parallelizeByDegree)
Computation * rawStartComputation(Computation *C)
Computation * IM2_GB_set_hilbert_function(Computation *C, const RingElement *h)
const Matrix * rawResolutionGetMatrix(Computation *C, int level)
enum ComputationStatusCode IM2_Resolution_status_level(Computation *C, int level, M2_bool minimize, int *complete_up_through_this_degree)
enum ComputationStatusCode rawStatus1(Computation *C)
int rawStatus2(Computation *C)
void rawShowComputation(const Computation *C)
const Matrix * rawNCGroebnerBasisTwoSided(const Matrix *input, int maxdeg, int strategy)
MutableMatrix * rawResolutionGetMutableMatrix2B(Computation *C, const Ring *KK, int level, int degree)
MutableMatrix * rawResolutionGetMutableMatrixB(Computation *C, const Ring *R, int level)
Computation * IM2_GB_make(const Matrix *m, M2_bool collect_syz, int n_rows_to_keep, M2_arrayint gb_weights, M2_bool use_max_degree, int max_degree, int algorithm, int strategy, int max_reduction_count)
int IM2_Resolution_status(Computation *C, int *complete_up_through_this_degree, int *complete_up_through_this_level)
const Matrix * rawKernelOfGB(const Matrix *M)
const Matrix * rawGBGetLeadTerms(Computation *C, int nparts)
const Matrix * rawGBGetMatrix(Computation *C)
const FreeModule * rawResolutionGetFree(Computation *C, int level)
void test_over_RR_or_CC(const Ring *R)
Computation * rawMarkedGB(const Matrix *leadterms, const Matrix *m, const Matrix *gb, const Matrix *change, const Matrix *syz)
const Matrix * rawGBSyzygies(Computation *C)
Computation * rawGroebnerWalk(const Matrix *gb, const MonomialOrdering *order1)
void rawDisplayMatrixStream(const Matrix *inputMatrix)
const Matrix * rawGBChangeOfBasis(Computation *C)
Computation * IM2_GB_force(const Matrix *m, const Matrix *gb, const Matrix *change, const Matrix *syz)
bool monomialOrderingToMatrix(const struct MonomialOrdering &mo, std::vector< int > &mat, bool &base_is_revlex, int &component_direction, int &component_is_before_row)
M2_arrayintOrNull rawResolutionBetti(Computation *C, int type)
M2_string IM2_GB_to_string(Computation *C)
Matrix * rawSubduction1(int numparts, const Ring *rawT, const Ring *rawS, const Matrix *m, const RingMap *inclusionAmbient, const RingMap *fullSubstitution, const RingMap *substitutionInclusion, Computation *rawGBI, Computation *rawGBReductionIdeal)
bool warning_given_for_gb_or_res_over_RR_or_CC
M2_bool IM2_GB_matrix_lift(Computation *C, const Matrix *m, const Matrix **result_remainder, const Matrix **result_quotient)
Computation * IM2_Computation_set_stop(Computation *G, M2_bool always_stop, M2_arrayint degree_limit, int basis_element_limit, int syzygy_limit, int pair_limit, int codim_limit, int subring_limit, M2_bool just_min_gens, M2_arrayint length_limit)
const Matrix * rawNCBasis(const Matrix *gb2SidedIdeal, M2_arrayint lo_degree, M2_arrayint hi_degree, int limit)
const Matrix * rawMGB(const Matrix *inputMatrix, int reducer, int spairGroupSize, int nthreads, M2_string logging)
const Matrix * rawGBGetParallelLeadTerms(Computation *C, M2_arrayint w)
const Matrix * rawNCReductionTwoSided(const Matrix *toBeReduced, const Matrix *reducerMatrix)
Engine-boundary C API for Gröbner basis, resolution, and Hilbert-series computations.
bool ncBasis(const FreeAlgebra &A, const ConstPolyList &gb, const std::vector< int > &lo_degree, const std::vector< int > &hi_degree, int limit, PolyList &result)
Hilbert-series numerator via the Bigatti-Caboara-Robbiano recursion.
bool system_interrupted()
system_interrupted() — thread-safe polling predicate for Ctrl+C handling.
VALGRIND_MAKE_MEM_DEFINED & result(result)
M2_arrayint M2_arrayintOrNull
ncBasis — non-commutative analogue of basis(d, M) over NCAlgebras/FreeAlgebra.
void matrixToStream(const Matrix *M, T &stream)
MatrixStream — term-by-term streaming construction of a Matrix.
Concrete commutative PolyRing — standard polynomial ring inheriting from PolyRingFlat.
RingElement — tagged (Ring*, ring_elem) pair, the engine's universal element type.
F4ResComputation — top-level Schreyer-frame F4 free-resolution driver.
sagbi — subduction helpers for canonical-subalgebra (SAGBI) bases.
gbvector-side matrix: a target FreeModule plus a list of gbvector* columns living in it.
Front-end-side description of a monomial ordering as a list of mon_part blocks.
Singly linked-list node carrying one term of a polynomial-ring element.
void emit_line(const char *s)
Text-formatting helpers layered on buffer: bignum print, line wrapping, M2_gbTrace-gated emit.
const void * get_Poly() const
std::vector< T > M2_arrayint_to_stdvector(M2_arrayint arr)
Conversion helpers between M2 boundary types and standard C++ containers.