Skip to content

Commit

Permalink
Merge pull request sympy#9671 from aktech/complex-fs
Browse files Browse the repository at this point in the history
Simplify ComplexPlane({x}*{y}) to FiniteSet(x + I*y)
  • Loading branch information
hargup committed Jul 22, 2015
2 parents 49df06b + cc13a7b commit 9e6a4da
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
20 changes: 19 additions & 1 deletion sympy/sets/fancysets.py
Expand Up @@ -634,17 +634,35 @@ def __new__(cls, sets, polar=False):

# Rectangular Form
if polar is False:
obj = ImageSet.__new__(cls, Lambda((x, y), x + I*y), sets)

if all(_a.is_FiniteSet for _a in sets.args) and (len(sets.args) == 2):

# ** ProductSet of FiniteSets in the Complex Plane. **
# For Cases like ComplexPlane({2, 4}*{3}), It
# would return {2 + 3*I, 4 + 3*I}
complex_num = []
for x in sets.args[0]:
for y in sets.args[1]:
complex_num.append(x + I*y)
obj = FiniteSet(*complex_num)

else:
obj = ImageSet.__new__(cls, Lambda((x, y), x + I*y), sets)

# Polar Form
elif polar is True:
new_sets = []

# sets is Union of ProductSets
if not sets.is_ProductSet:
for k in sets.args:
new_sets.append(k)

# sets is ProductSets
else:
new_sets.append(sets)

# Normalize input theta
for k, v in enumerate(new_sets):
from sympy.sets import ProductSet
new_sets[k] = ProductSet(v.args[0],
Expand Down
10 changes: 10 additions & 0 deletions sympy/sets/tests/test_fancysets.py
Expand Up @@ -413,3 +413,13 @@ def test_normalize_theta_set():

# ValueError for non-real sets
raises(ValueError, lambda: normalize_theta_set(S.Complexes))


def test_ComplexPlane_FiniteSet():
x, y, z, a, b, c = symbols('x y z a b c')

# Issue #9669
assert ComplexPlane(FiniteSet(a, b, c)*FiniteSet(x, y, z)) == \
FiniteSet(a + I*x, a + I*y, a + I*z, b + I*x, b + I*y,
b + I*z, c + I*x, c + I*y, c + I*z)
assert ComplexPlane(FiniteSet(2)*FiniteSet(3)) == FiniteSet(2 + 3*I)

0 comments on commit 9e6a4da

Please sign in to comment.