784{
785 try
786 {
789 if (P == nullptr)
790 {
791 ERROR(
"expected a polynomial ring");
792 return nullptr;
793 }
794 if (nthreads < 0)
795 {
796 ERROR(
"mgb: expected a non-negative number of threads");
797 return nullptr;
798 }
800 {
801 ERROR(
"characteristic is too large for mathic gb computation");
802 return nullptr;
803 }
805 {
807 "characteristic for mathic gb computation must be a prime "
808 "number");
809 return nullptr;
810 }
812 {
813 ERROR(
"coefficients for mathic gb computation must be a prime field");
814 return nullptr;
815 }
819 mgb::GroebnerConfiguration configuration(
820 charac, nvars, inputMatrix->
n_rows());
821
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);
831
832
833 std::vector<int> mat;
834 bool base_is_revlex = true;
835 int component_direction = 1;
836 int component_is_before_row = -1;
838 mat,
839 base_is_revlex,
840 component_direction,
841 component_is_before_row))
842 {
844 "monomial ordering is not appropriate for Groebner basis "
845 "computation");
846 return nullptr;
847 }
848 if (!configuration.setMonomialOrder(
849 (base_is_revlex
850 ?
851
852 mgb::GroebnerConfiguration::BaseOrder::
853 RevLexDescendingBaseOrder
854 : mgb::GroebnerConfiguration::BaseOrder::
855 LexDescendingBaseOrder),
856 mat))
857 {
859 }
860
861 if (component_is_before_row >= 0)
862 configuration.setComponentBefore(component_is_before_row);
863 configuration.setComponentsAscending(component_direction == 1);
864
865#if 0
866
867 printf("Setting monomial order:");
868 for (size_t i=0; i<mat.size(); i++) printf("%d ", mat[i]);
869 printf("\n");
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;
873#endif
874
875 mgb::GroebnerInputIdealStream input(configuration);
876
877 std::ostringstream computedStr;
878 mgb::IdealStreamLog<> computed(
879 computedStr, charac, nvars, inputMatrix->
n_rows());
880 mgb::IdealStreamChecker<decltype(computed)> checkedOut(computed);
881
884
885 mgb::computeGroebnerBasis(input, matStream);
887 {
888 ERROR(
"computation was interrupted");
889 return nullptr;
890 }
892
893
894
896 } catch (const std::runtime_error& e)
897 {
899 return nullptr;
900 }
901}
bool wasInterrupted() const
mathicgb (mgb) callback that polls the engine's interrupt flag during a long-running GB computation.
const Ring * get_ring() const
const FreeModule * rows() const
Streaming consumer that builds an engine Matrix from the mathicgb-style stream callbacks (idealBegin ...
const MonomialOrdering * getMonomialOrdering() const
Concrete PolyRingFlat subclass implementing ordinary commutative polynomial rings K[x_1,...
const Ring * getCoefficientRing() const
virtual const Monoid * getMonoid() const
virtual const PolyRing * cast_to_PolyRing() const
long characteristic() const
virtual bool isFinitePrimeField() const
bool monomialOrderingToMatrix(const struct MonomialOrdering &mo, std::vector< int > &mat, bool &base_is_revlex, int &component_direction, int &component_is_before_row)
VALGRIND_MAKE_MEM_DEFINED & result(result)
void matrixToStream(const Matrix *M, T &stream)
const mpreal log(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())