'Convert a Groebner basis from one ordering to another.
The FGLM algorithm converts reduced Groebner bases of zero-dimensional
ideals from one ordering to another. This method is often used when it
is infeasible to compute a Groebner basis with respect to a particular
ordering directly.
Examples
>>> from sympy.abc import x, y
>>> from sympy import groebner
>>> F = [x**2 - 3*y - x + 1, y**2 - 2*x + y - 1]
>>> G = groebner(F, x, y, order=\'grlex\')
>>> list(G.fglm(\'lex\'))
[2*x - y**2 - y + 1, y**4 + 2*y**3 - 3*y**2 - 16*y + 7]
>>> list(groebner(F, x, y, order=\'lex\'))
[2*x - y**2 - y + 1, y**4 + 2*y**3 - 3*y**2 - 16*y + 7]
References
J.C. Faugere, P. Gianni, D. Lazard, T. Mora (1994). Efficient
Computation of Zero-dimensional Groebner Bases by Change of
Ordering'

def fglm(self, order):

    opt = self._options
    src_order = opt.order
    dst_order = monomial_key(order)
    if (src_order == dst_order):
        return self
    if (not self.is_zero_dimensional):
        raise NotImplementedError("can't    convert    Groebner    bases    of    ideals    with    positive    dimension")
    polys = list(self._basis)
    domain = opt.domain
    opt = opt.clone(dict(domain=domain.get_field(), order=dst_order))
    from sympy.polys.rings import xring
    (_ring, _) = xring(opt.gens, opt.domain, src_order)
    for (i, poly) in enumerate(polys):
        poly = poly.set_domain(opt.domain).rep.to_dict()
        polys[i] = _ring.from_dict(poly)
    G = matrix_fglm(polys, _ring, dst_order)
    G = [Poly._from_dict(dict(g), opt) for g in G]
    if (not domain.is_Field):
        G = [g.clear_denoms(convert=True)[1] for g in G]
        opt.domain = domain
    return self._new(G, opt)
