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

Conversation

Projects
None yet
2 participants
@aktech
Copy link
Member

aktech commented Jun 15, 2015

  • Fixes #7486
  • Tests
  • Fix Merge Conflicts
  • Output
In [2]: a, b, c = Interval(2, 3), Interval(4, 7), Interval(1, 9)
In [3]: init_printing()

In [4]: Union(a*b, b*FiniteSet(1,2))
Out[4]: ([4, 7] × {1, 2}) ∪ ([2, 3] × [4, 7])

In [5]: Union(a*b, b*c)
Out[5]: ([2, 3] × [4, 7]) ∪ ([4, 7] × [1, 9])
@aktech

This comment has been minimized.

Copy link
Member Author

aktech commented Jun 15, 2015

@hargup @flacjacket

Not sure, what tests needs to be added, but the following test doesn't works.

diff --git a/sympy/printing/pretty/tests/test_pretty.py b/sympy/printing/pretty/tests/test_pretty.py
index a1c7aa9..445ed3f 100644
--- a/sympy/printing/pretty/tests/test_pretty.py
+++ b/sympy/printing/pretty/tests/test_pretty.py
@@ -5,8 +5,8 @@
     FiniteSet, Function, Ge, Gt, I, Implies, Integral,
     Lambda, Le, Limit, Lt, Matrix, Mul, Nand, Ne, Nor, Not, O, Or,
     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)
+    Segment, Subs, Sum, Symbol, Tuple, Xor, ZZ, conjugate, Interval,
+    Union, groebner, oo, pi, symbols, ilex, grlex, Range, Contains)
 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,
@@ -3099,6 +3099,13 @@ def test_pretty_sets():
     assert upretty(Range(-2, -oo, -1)) == ucode_str


+def test_ProductSet_issue_7486():
+    a, b, c = Interval(2, 3), Interval(4, 7), Interval(1, 9)
+
+    assert pretty(Union(a*b, b*FiniteSet(1, 2))) == u'([2, 3] \xd7 [4, 7]) \u222a ([4, 7] \xd7 [1, 9])'
+    assert pretty(Union(a*b, b*c)) == u'([4, 7] \xd7 {1, 2}) \u222a ([2, 3] \xd7 [4, 7])'
+
+
 def test_pretty_limits():
     expr = Limit(x, x, oo)
     ascii_str = \
@hargup

This comment has been minimized.

Copy link
Member

hargup commented Jun 18, 2015

@aktech you can directly use unicode symbols, encoding them in forms like \xd7 makes the tests completely unreadable. You should look at the function test_pretty_sets in printing/pretty/tests/tests_pretty as an example. Your code looks correct and I tried to write a test for myself and it worked.

diff --git a/sympy/printing/pretty/tests/test_pretty.py b/sympy/printing/pretty/tests/test_pretty
index a1c7aa9..d3162f4 100644
--- a/sympy/printing/pretty/tests/test_pretty.py
+++ b/sympy/printing/pretty/tests/test_pretty.py
@@ -3099,6 +3099,15 @@ def test_pretty_sets():
     assert upretty(Range(-2, -oo, -1)) == ucode_str


+def test_set_paranthesis():
+    from sympy import Interval, Union, FiniteSet
+    x = u'[4, 7] x {1, 2} U [2, 3] x [4, 7]'
+    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_limits():
     expr = Limit(x, x, oo)
     ascii_str = \
@aktech

This comment has been minimized.

Copy link
Member Author

aktech commented Jun 18, 2015

Thanks! It works.

@aktech aktech force-pushed the aktech:prodset-printing branch 2 times, most recently from d044890 to ffc401e Jun 18, 2015

@aktech aktech force-pushed the aktech:prodset-printing branch from ffc401e to af5866e Jun 19, 2015

hargup added a commit that referenced this pull request Jun 19, 2015

Merge pull request #9527 from aktech/prodset-printing
Parenthesize printing of ProductSets

@hargup hargup merged commit 2b6099b into sympy:master Jun 19, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@aktech aktech deleted the aktech:prodset-printing branch Jul 25, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment