Skip to content

Commit

Permalink
Merge 123f276 into a829ca3
Browse files Browse the repository at this point in the history
  • Loading branch information
skirpichev committed May 16, 2015
2 parents a829ca3 + 123f276 commit b598777
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
14 changes: 10 additions & 4 deletions sympy/sets/sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1336,12 +1336,12 @@ def flatten(arg):
if len(args) == 0:
raise TypeError("Intersection expected at least one argument")

args = list(ordered(args, Set._infimum_key))

# Reduce sets using known rules
if evaluate:
return Intersection.reduce(args)

args = list(ordered(args, Set._infimum_key))

return Basic.__new__(cls, *args)

@property
Expand Down Expand Up @@ -1393,8 +1393,14 @@ def reduce(args):
# all other sets in the intersection
for s in args:
if s.is_FiniteSet:
return s.func(*[x for x in s
if all(other.contains(x) == True for other in args)])
args = [a for a in args if a != s]
res = s.func(*[x for x in s
if all(other.contains(x) == True for other in args)])
unk = [x for x in s
if any(other.contains(x) not in (True, False) for other in args)]
if unk:
res += Intersection(*([s.func(*unk)] + args), evaluate=False)
return res

# If any of the sets are unions, return a Union of Intersections
for s in args:
Expand Down
10 changes: 9 additions & 1 deletion sympy/sets/tests/test_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,15 @@ def test_intersect():
assert Union(Interval(0, 1), Interval(2, 3)).intersect(S.EmptySet) == \
S.EmptySet
assert Union(Interval(0, 5), FiniteSet('ham')).intersect(FiniteSet(2, 3, 4, 5, 6)) == \
FiniteSet(2, 3, 4, 5)
Union(FiniteSet(2, 3, 4, 5),
Intersection(FiniteSet(6), Union(Interval(0, 5),
FiniteSet('ham'))))

# issue 8217
assert Intersection(FiniteSet(x), FiniteSet(y)) == \
Intersection(FiniteSet(x), FiniteSet(y), evaluate=False)
assert FiniteSet(x).intersect(S.Reals) == \
Intersection(S.Reals, FiniteSet(x), evaluate=False)

# tests for the intersection alias
assert Interval(0, 5).intersection(FiniteSet(1, 3)) == FiniteSet(1, 3)
Expand Down

0 comments on commit b598777

Please sign in to comment.