Exemplo n.º 1
0
M2_arrayint rawMonomialOrderingToMatrix(const struct MonomialOrdering* mo)
{
  bool base;
  std::vector<int> mat;
  M2_arrayint result = 0;
  int component_is_before_row = 0;
  int component_direction = 0;
  if (monomialOrderingToMatrix(
          *mo, mat, base, component_direction, component_is_before_row))
    {
      int top = static_cast<int>(mat.size());
      result = M2_makearrayint(top + 3);
      for (int i = 0; i < top; i++) result->array[i] = mat[i];
      result->array[top] = (base ? 1 : 0);
      result->array[top + 1] = component_direction;
      result->array[top + 2] = component_is_before_row;
    }
  return result;
}
Exemplo n.º 2
0
const Matrix * rawMGB(const Matrix *inputMatrix, 
                      int reducer,
                      int spairGroupSize, // a value of 0 means let the algorithm choose
                      int nthreads,
                      M2_string logging)
{
  const Ring *R = inputMatrix->get_ring();
  const PolyRing *P = R->cast_to_PolyRing();
  if (P == 0) 
    {
      ERROR("expected a polynomial ring");
      return 0;
    }
  if (nthreads < 0)
    {
      ERROR("mgb: expected a non-negative number of threads");
      return 0;
    }
  int charac = P->charac();
  int nvars = P->n_vars();
#if defined(HAVE_MATHICGB)
  mgb::GroebnerConfiguration configuration(charac, nvars);

  const auto reducerType = reducer == 0 ?
    mgb::GroebnerConfiguration::ClassicReducer :
    mgb::GroebnerConfiguration::MatrixReducer;
  configuration.setReducer(reducerType);
  configuration.setMaxSPairGroupSize(spairGroupSize);
  configuration.setMaxThreadCount(nthreads);
  std::string log(logging->array, logging->len);
  configuration.setLogging(log.c_str());


  std::vector<int> mat;
  bool base_is_revlex = true;
  // Now set the monomial ordering info
  if (!monomialOrderingToMatrix(* P->getMonoid()->getMonomialOrdering(), mat, base_is_revlex))
    {
      ERROR("monomial ordering is not appropriate for Groebner basis computation");
      return 0;
    }
  configuration.setMonomialOrder((base_is_revlex ? 
                                    mgb::GroebnerConfiguration::BaseOrder::ReverseLexicographicBaseOrder 
                                  : mgb::GroebnerConfiguration::BaseOrder::LexicographicBaseOrder),
                                 mat);

#if 0
  // Debug information
  printf("Setting monomial order:");
  for (size_t i=0; i<mat.size(); i++) printf("%d ", mat[i]);
  printf("\n");
  printf("  Base=%d\n", base_is_revlex);
#endif

  mgb::GroebnerInputIdealStream input(configuration);

  std::ostringstream computedStr;
  mgb::IdealStreamLog<> computed(computedStr, charac, nvars);
  mgb::IdealStreamChecker<decltype(computed)> checkedOut(computed);

  matrixToStream(inputMatrix, input); 
  MatrixStream matStream(P);
  //  mgb::computeGroebnerBasis(input, checked);
  mgb::computeGroebnerBasis(input, matStream);
  const Matrix* result = matStream.value();
  //  rawDisplayMatrixStream(result);
  return result;
#endif
  return inputMatrix;
}