JuliaAlgebra / MultivariatePolynomials.jl

Multivariate polynomials interface
https://juliaalgebra.github.io/MultivariatePolynomials.jl/stable/
Other
135 stars 27 forks source link

Extract monomial ordering #189

Closed sumiya11 closed 2 years ago

sumiya11 commented 2 years ago

Hi! I think it would be nice to have a function for extracting the monomial ordering. So that, for example,

ordering(::AbstractPolynomialLike) = :deglex

I'm developing a package for Groebner bases computations and want to support MultivariatePolynomials.AbstractPolynomial as an input type. To be coherent with AbstractAlgebra, I assume and hardcode the ordering for AbstractPolynomial which does not seem good

blegat commented 2 years ago

Hi! At the moment, both DynamicPolynomials and TypedPolynomials use the graded lex order so it's safe to assume it. We could add an interface to get the ordering. We need to choose between

struct GradedLex <: Ordering end
struct GradedReverseLex <: Ordering end
ordering(...) = :graded_lex
ordering(...) = :graded_reverse_lex

or

struct GradedLex <: Ordering end
struct GradedReverseLex <: Ordering end
ordering(...) = GradedLex()
ordering(...) = GradedReverseLex()

or

@enum Ordering GRADED_LEX GRADED_REVERSE_LEX
ordering(...) = GRADED_LEX
ordering(...) = GRADED_REVERSE_LEX

I don't really like the first one because when you have typos and write an incorrect ordering, you don't see it and it might lead to subtle bugs. The disadvantage of the 3rd one is that MultivariatePolynomials has to limit the set of possible ordering and it cannot be extended by other packages. The 2nd one allows other packages to add subtypes of Ordering and allows to use the ordering directly in multiple dispatch to dispatch to a function handling this ordering.

blegat commented 2 years ago

Closed by https://github.com/JuliaAlgebra/MultivariatePolynomials.jl/pull/190