Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ProductOrder's in core #1332

Open
skirpichev opened this issue Jun 12, 2023 · 0 comments
Open

Support ProductOrder's in core #1332

skirpichev opened this issue Jun 12, 2023 · 0 comments
Labels
bug an unexpected problem or unintended behavior core polys printing
Milestone

Comments

@skirpichev
Copy link
Collaborator

Right now Expr.as_ordered_terms() raises an exception:

In [1]: from diofant.polys.orderings import build_product_order, lex

In [2]: O = build_product_order(((lex, z), (lex, x, y)), [x, y, z])

In [3]: F = [x**2 + y + z - 1, x + y**2 + z - 1, x + y + z**2 - 1]

In [4]: groebner(F, x, y, z, order=O)
Out[4]: ---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
File ~/venv/dev3.11/lib/python3.11/site-packages/IPython/core/formatters.py:706, in PlainTextFormatter.__call__(self, obj)
    699 stream = StringIO()
    700 printer = pretty.RepresentationPrinter(stream, self.verbose,
    701     self.max_width, self.newline,
    702     max_seq_length=self.max_seq_length,
    703     singleton_pprinters=self.singleton_printers,
    704     type_pprinters=self.type_printers,
    705     deferred_pprinters=self.deferred_printers)
--> 706 printer.pretty(obj)
    707 printer.flush()
    708 return stream.getvalue()

File ~/venv/dev3.11/lib/python3.11/site-packages/IPython/lib/pretty.py:407, in RepresentationPrinter.pretty(self, obj)
    405     meth = cls._repr_pretty_
    406     if callable(meth):
--> 407         return meth(obj, self, cycle)
    408 if cls is not object \
    409         and callable(cls.__dict__.get('__repr__')):
    410     return _repr_pprint(obj, self, cycle)

File ~/src/diofant/diofant/core/basic.py:164, in Basic._repr_pretty_(self, p, cycle)
    162 def _repr_pretty_(self, p, cycle):
    163     from ..printing import pretty
--> 164     p.text(pretty(self))

File ~/src/diofant/diofant/printing/pretty/pretty.py:1591, in pretty(expr, **settings)
   1588 uflag = pretty_use_unicode(use_unicode)
   1590 try:
-> 1591     return pp.doprint(expr)
   1592 finally:
   1593     pretty_use_unicode(uflag)

File ~/src/diofant/diofant/printing/pretty/pretty.py:47, in PrettyPrinter.doprint(self, expr)
     46 def doprint(self, expr):
---> 47     return self._print(expr).render(**self._settings)

File ~/src/diofant/diofant/printing/printer.py:211, in Printer._print(self, expr, *args, **kwargs)
    208         if cls.__class__.__name__ == 'UndefinedFunction':
    209             # XXX a hack for sympy/sympy#6853
    210             continue
--> 211         return getattr(self, printmethod)(expr, *args, **kwargs)
    213 # Unknown object, fall back to the emptyPrinter.
    214 return self.emptyPrinter(expr)

File ~/src/diofant/diofant/printing/pretty/pretty.py:1506, in PrettyPrinter._print_GroebnerBasis(self, basis)
   1505 def _print_GroebnerBasis(self, basis):
-> 1506     exprs = [self._print_Add(arg, order=basis.order)
   1507              for arg in basis.exprs]
   1508     exprs = prettyForm(*self.join(', ', exprs).parens(left='[', right=']'))
   1510     gens = [self._print(gen) for gen in basis.gens]

File ~/src/diofant/diofant/printing/pretty/pretty.py:1506, in <listcomp>(.0)
   1505 def _print_GroebnerBasis(self, basis):
-> 1506     exprs = [self._print_Add(arg, order=basis.order)
   1507              for arg in basis.exprs]
   1508     exprs = prettyForm(*self.join(', ', exprs).parens(left='[', right=']'))
   1510     gens = [self._print(gen) for gen in basis.gens]

File ~/src/diofant/diofant/printing/pretty/pretty.py:1073, in PrettyPrinter._print_Add(self, expr, order)
   1071     terms = list(expr.args)
   1072 else:
-> 1073     terms = expr.as_ordered_terms(order=order or self.order)
   1074 pforms, indices = [], []
   1076 def pretty_negative(pform, index):

File ~/src/diofant/diofant/core/expr.py:793, in Expr.as_ordered_terms(self, order, data)
    790 terms, gens = self.as_terms()
    792 if not any(term.is_Order for term, _ in terms):
--> 793     ordered = sorted(terms, key=key, reverse=reverse)
    794 else:
    795     _terms, _order = [], []

File ~/src/diofant/diofant/core/expr.py:767, in Expr._parse_order.<locals>.key(term)
    764 def key(term):
    765     _, ((re, im), monom, ncpart) = term
--> 767     monom = neg(monom_key(monom))
    768     ncpart = tuple(e.sort_key(order=order) for e in ncpart)
    769     coeff = ((bool(im), im), (re, im))

File ~/src/diofant/diofant/polys/orderings.py:109, in ProductOrder.__call__(self, monomial)
    108 def __call__(self, monomial):
--> 109     return tuple(O(lamda(monomial)) for (O, lamda) in self.args)

File ~/src/diofant/diofant/polys/orderings.py:109, in <genexpr>(.0)
    108 def __call__(self, monomial):
--> 109     return tuple(O(lamda(monomial)) for (O, lamda) in self.args)

File ~/src/diofant/diofant/polys/orderings.py:246, in _ItemGetter.__call__(self, m)
    245 def __call__(self, m):
--> 246     return tuple(m[idx] for idx in self.seq)

File ~/src/diofant/diofant/polys/orderings.py:246, in <genexpr>(.0)
    245 def __call__(self, m):
--> 246     return tuple(m[idx] for idx in self.seq)

IndexError: tuple index out of range
@skirpichev skirpichev added bug an unexpected problem or unintended behavior core printing polys labels Jun 12, 2023
@skirpichev skirpichev added this to the 0.15 milestone Jun 12, 2023
skirpichev added a commit to skirpichev/diofant that referenced this issue Oct 2, 2023
skirpichev added a commit to skirpichev/diofant that referenced this issue Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior core polys printing
Development

No branches or pull requests

1 participant