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

Parenthesize printing of ProductSets #9527

Merged
merged 2 commits into from Jun 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion sympy/printing/pretty/pretty.py
Expand Up @@ -1425,7 +1425,8 @@ def _print_ProductSet(self, p):
else:
prod_char = u('\xd7')
return self._print_seq(p.sets, None, None, ' %s ' % prod_char,
parenthesize=lambda set: set.is_Union or set.is_Intersection)
parenthesize=lambda set: set.is_Union or
set.is_Intersection or set.is_ProductSet)

def _print_FiniteSet(self, s):
items = sorted(s.args, key=default_sort_key)
Expand Down
11 changes: 10 additions & 1 deletion sympy/printing/pretty/tests/test_pretty.py
Expand Up @@ -7,7 +7,8 @@
Pow, Product, QQ, RR, Rational, Ray, RootOf, RootSum, S,
Segment, Subs, Sum, Symbol, Tuple, Xor, ZZ, conjugate,
groebner, oo, pi, symbols, ilex, grlex, Range, Contains,
SeqPer, SeqFormula, SeqAdd, SeqMul)
SeqPer, SeqFormula, SeqAdd, SeqMul, Interval, Union)

from sympy.functions import (Abs, Chi, Ci, Ei, KroneckerDelta,
Piecewise, Shi, Si, atan2, binomial, catalan, ceiling, cos,
euler, exp, expint, factorial, factorial2, floor, gamma, hyper, log,
Expand Down Expand Up @@ -3100,6 +3101,14 @@ def test_pretty_sets():
assert upretty(Range(-2, -oo, -1)) == ucode_str


def test_ProductSet_paranthesis():
from sympy import Interval, Union, FiniteSet
ucode_str = u('([4, 7] × {1, 2}) ∪ ([2, 3] × [4, 7])')

a, b, c = Interval(2, 3), Interval(4, 7), Interval(1, 9)
assert upretty(Union(a*b, b*FiniteSet(1, 2))) == ucode_str


def test_pretty_sequences():
s1 = SeqFormula(a**2, (0, oo))
s2 = SeqPer((1, 2))
Expand Down