Skip to content

Commit

Permalink
Merge pull request #71 from skirpichev/misc
Browse files Browse the repository at this point in the history
Misc fixes

- adopt set/dict literals
- misc fixes in the series module
  • Loading branch information
skirpichev committed May 2, 2015
2 parents 66245d4 + 58b9963 commit 6006a84
Show file tree
Hide file tree
Showing 152 changed files with 1,123 additions and 1,467 deletions.
2 changes: 1 addition & 1 deletion sympy/assumptions/ask.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def single_fact_lookup(known_facts_keys, known_facts_cnf):
# Compute the quick lookup for single facts
mapping = {}
for key in known_facts_keys:
mapping[key] = set([key])
mapping[key] = {key}
for other_key in known_facts_keys:
if other_key != key:
if ask_full_inference(other_key, key, known_facts_cnf):
Expand Down
4 changes: 2 additions & 2 deletions sympy/assumptions/refine.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def refine_Pow(expr, assumptions):

coeff, terms = expr.exp.as_coeff_add()
terms = set(terms)
even_terms = set([])
odd_terms = set([])
even_terms = set()
odd_terms = set()
initial_number_of_terms = len(terms)

for t in terms:
Expand Down
2 changes: 1 addition & 1 deletion sympy/assumptions/tests/test_assumptions_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_equal():
def test_pretty():
assert pretty(Q.positive(x)) == "Q.positive(x)"
assert pretty(
set([Q.positive, Q.integer])) == "set([Q.integer, Q.positive])"
{Q.positive, Q.integer}) == "set([Q.integer, Q.positive])"


def test_extract_facts():
Expand Down
6 changes: 3 additions & 3 deletions sympy/assumptions/tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2035,19 +2035,19 @@ def test_single_fact_lookup():
known_facts = And(Implies(Q.integer, Q.rational),
Implies(Q.rational, Q.real),
Implies(Q.real, Q.complex))
known_facts_keys = set([Q.integer, Q.rational, Q.real, Q.complex])
known_facts_keys = {Q.integer, Q.rational, Q.real, Q.complex}

known_facts_cnf = to_cnf(known_facts)
mapping = single_fact_lookup(known_facts_keys, known_facts_cnf)

assert mapping[Q.rational] == set([Q.real, Q.rational, Q.complex])
assert mapping[Q.rational] == {Q.real, Q.rational, Q.complex}


def test_compute_known_facts():
known_facts = And(Implies(Q.integer, Q.rational),
Implies(Q.rational, Q.real),
Implies(Q.real, Q.complex))
known_facts_keys = set([Q.integer, Q.rational, Q.real, Q.complex])
known_facts_keys = {Q.integer, Q.rational, Q.real, Q.complex}

s = compute_known_facts(known_facts, known_facts_keys)

Expand Down
4 changes: 2 additions & 2 deletions sympy/calculus/tests/test_euler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def test_euler_interface():
raises(TypeError, lambda: euler(D(x(t), t)*y(t), [x(t), y]))
raises(ValueError, lambda: euler(D(x(t), t)*x(y), [x(t), x(y)]))
raises(TypeError, lambda: euler(D(x(t), t)**2, x(0)))
assert euler(D(x(t), t)**2/2, set([x(t)])) == [Eq(-D(x(t), t, t))]
assert euler(D(x(t), t)**2/2, x(t), set([t])) == [Eq(-D(x(t), t, t))]
assert euler(D(x(t), t)**2/2, {x(t)}) == [Eq(-D(x(t), t, t))]
assert euler(D(x(t), t)**2/2, x(t), {t}) == [Eq(-D(x(t), t, t))]


def test_euler_pendulum():
Expand Down
6 changes: 3 additions & 3 deletions sympy/categories/diagram_drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ def _grow_pseudopod(triangles, fringe, grid, skeleton, placed_objects):
def good_triangle(tri):
objs = DiagramGrid._triangle_objects(tri)
return obj in objs and \
placed_objects & (objs - set([obj])) == set()
placed_objects & (objs - {obj}) == set()

tris = [tri for tri in triangles if good_triangle(tri)]
if not tris:
Expand Down Expand Up @@ -1065,7 +1065,7 @@ def _sequential_layout(diagram, merged_morphisms):
grid = _GrowableGrid(1, 1)
grid[0, 0] = root

placed_objects = set([root])
placed_objects = {root}

def place_objects(pt, placed_objects):
"""
Expand Down Expand Up @@ -2023,7 +2023,7 @@ def count_morphisms_undirected(A, B):
two supplied objects.
"""
return len([m for m in morphisms_str_info
if set([m.domain, m.codomain]) == set([A, B])])
if {m.domain, m.codomain} == {A, B}])

def count_morphisms_filtered(dom, cod, curving):
"""
Expand Down
2 changes: 1 addition & 1 deletion sympy/categories/tests/test_drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def test_DiagramGrid():

# Test the five lemma with object grouping, but mixing containers
# to represent groups.
grid = DiagramGrid(d, [(A, B, C, D, E), set([A_, B_, C_, D_, E_])])
grid = DiagramGrid(d, [(A, B, C, D, E), {A_, B_, C_, D_, E_}])

assert grid.width == 6
assert grid.height == 3
Expand Down
8 changes: 4 additions & 4 deletions sympy/combinatorics/perm_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ def generate_dimino(self, af=False):
idn = list(range(self.degree))
order = 0
element_list = [idn]
set_element_list = set([tuple(idn)])
set_element_list = {tuple(idn)}
if af:
yield idn
else:
Expand Down Expand Up @@ -3263,7 +3263,7 @@ def _orbit(degree, generators, alpha, action='tuples'):
elif action == 'tuples':
alpha = tuple(alpha)
orb = [alpha]
used = set([alpha])
used = {alpha}
for b in orb:
for gen in gens:
temp = tuple([gen[x] for x in b])
Expand All @@ -3274,14 +3274,14 @@ def _orbit(degree, generators, alpha, action='tuples'):
elif action == 'sets':
alpha = frozenset(alpha)
orb = [alpha]
used = set([alpha])
used = {alpha}
for b in orb:
for gen in gens:
temp = frozenset([gen[x] for x in b])
if temp not in used:
orb.append(temp)
used.add(temp)
return set([tuple(x) for x in orb])
return {tuple(x) for x in orb}

def _orbits(degree, generators):
"""Compute the orbits of G.
Expand Down
2 changes: 1 addition & 1 deletion sympy/combinatorics/permutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ class Permutation(Basic):
2
>>> q(1) # the easy way
2
>>> dict([(i, q(i)) for i in range(q.size)]) # showing the bijection
>>> {i: q(i) for i in range(q.size)} # showing the bijection
{0: 5, 1: 2, 2: 3, 3: 4, 4: 1, 5: 0}
The full cyclic form (including singletons) can be obtained:
Expand Down
4 changes: 2 additions & 2 deletions sympy/combinatorics/tensor_can.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def double_coset_can_rep(dummies, sym, b_S, sgens, S_transversals, g):
sgensx1 = [_af_new(_) for _ in sgensx]
deltab = _orbit(size, sgensx1, b)
else:
deltab = set([b])
deltab = {b}
# p1 = min(IMAGES) = min(Union D_p*h*deltab for h in TAB)
if all_metrics_with_sym:
md = _min_dummies(dumx, sym, indices)
Expand Down Expand Up @@ -970,7 +970,7 @@ def get_transversals(base, gens):
return []
stabs = _distribute_gens_by_base(base, gens)
orbits, transversals = _orbits_transversals_from_bsgs(base, stabs)
transversals = [dict((x, h._array_form) for x, h in y.items()) for y in
transversals = [{x: h._array_form for x, h in y.items()} for y in
transversals]
return transversals

Expand Down
2 changes: 1 addition & 1 deletion sympy/combinatorics/tests/test_partitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_integer_partition():
next = set()
prev = set()
a = IntegerPartition([i])
ans = set([IntegerPartition(p) for p in partitions(i)])
ans = {IntegerPartition(p) for p in partitions(i)}
n = len(ans)
for j in range(n):
next.add(a)
Expand Down
4 changes: 2 additions & 2 deletions sympy/combinatorics/tests/test_perm_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ def test_orbits():
a = Permutation([2, 0, 1])
b = Permutation([2, 1, 0])
g = PermutationGroup([a, b])
assert g.orbit(0) == set([0, 1, 2])
assert g.orbits() == [set([0, 1, 2])]
assert g.orbit(0) == {0, 1, 2}
assert g.orbits() == [{0, 1, 2}]
assert g.is_transitive() and g.is_transitive(strict=False)
assert g.orbit_transversal(0) == \
[Permutation(
Expand Down
6 changes: 3 additions & 3 deletions sympy/combinatorics/tests/test_permutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_Permutation():

p = Permutation([2, 5, 1, 6, 3, 0, 4])
q = Permutation([[1], [0, 3, 5, 6, 2, 4]])
assert len(set([p, p])) == 1
assert len({p, p}) == 1
r = Permutation([1, 3, 2, 0, 4, 6, 5])
ans = Permutation(_af_rmuln(*[w.array_form for w in (p, q, r)])).array_form
assert rmul(p, q, r).array_form == ans
Expand Down Expand Up @@ -107,7 +107,7 @@ def test_Permutation():
raises(ValueError, lambda: p.commutator(Permutation([])))

assert len(p.atoms()) == 7
assert q.atoms() == set([0, 1, 2, 3, 4, 5, 6])
assert q.atoms() == {0, 1, 2, 3, 4, 5, 6}

assert p.inversion_vector() == [2, 4, 1, 3, 1, 0]
assert q.inversion_vector() == [3, 1, 2, 2, 0, 1]
Expand Down Expand Up @@ -255,7 +255,7 @@ def test_ranking():
a = a.next_lex()
b = b.next_trotterjohnson()
assert a == b is None
assert set([tuple(a) for a in l]) == set([tuple(a) for a in tj])
assert {tuple(a) for a in l} == {tuple(a) for a in tj}

p = Permutation([2, 5, 1, 6, 3, 0, 4])
q = Permutation([[6], [5], [0, 1, 2, 3, 4]])
Expand Down
4 changes: 2 additions & 2 deletions sympy/combinatorics/testutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def _cmp_perm_lists(first, second):
True
"""
return set([tuple(a) for a in first]) == \
set([tuple(a) for a in second])
return {tuple(a) for a in first} == \
{tuple(a) for a in second}


def _naive_list_centralizer(self, other, af=False):
Expand Down
2 changes: 1 addition & 1 deletion sympy/concrete/expr_with_intlimits.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def reorder_limit(expr, x, y):
sympy.concrete.summations.Sum.reverse_order
sympy.concrete.products.Product.reverse_order
"""
var = set([limit[0] for limit in expr.limits])
var = {limit[0] for limit in expr.limits}
limit_x = expr.limits[x]
limit_y = expr.limits[y]

Expand Down
6 changes: 3 additions & 3 deletions sympy/concrete/gosper.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ def gosper_term(f, n):
K = S(C.degree())

if (N != M) or (A.LC() != B.LC()):
D = set([K - max(N, M)])
D = {K - max(N, M)}
elif not N:
D = set([K - N + 1, S(0)])
D = {K - N + 1, S(0)}
else:
D = set([K - N + 1, (B.nth(N - 1) - A.nth(N - 1))/A.LC()])
D = {K - N + 1, (B.nth(N - 1) - A.nth(N - 1))/A.LC()}

for d in set(D):
if not d.is_Integer or d < 0:
Expand Down
2 changes: 1 addition & 1 deletion sympy/concrete/summations.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def findrecur(self, F=Dummy('F'), n=None):

if not n:
try:
n = (self.function.free_symbols - set([k])).pop()
n = (self.function.free_symbols - {k}).pop()
except KeyError:
raise ValueError

Expand Down
24 changes: 12 additions & 12 deletions sympy/concrete/tests/test_sums_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,22 +632,22 @@ def test_is_number():
def test_free_symbols():
for func in [Sum, Product]:
assert func(1, (x, 1, 2)).free_symbols == set()
assert func(0, (x, 1, y)).free_symbols == set([y])
assert func(2, (x, 1, y)).free_symbols == set([y])
assert func(0, (x, 1, y)).free_symbols == {y}
assert func(2, (x, 1, y)).free_symbols == {y}
assert func(x, (x, 1, 2)).free_symbols == set()
assert func(x, (x, 1, y)).free_symbols == set([y])
assert func(x, (y, 1, y)).free_symbols == set([x, y])
assert func(x, (y, 1, 2)).free_symbols == set([x])
assert func(x, (y, 1, 1)).free_symbols == set([x])
assert func(x, (y, 1, z)).free_symbols == set([x, z])
assert func(x, (x, 1, y)).free_symbols == {y}
assert func(x, (y, 1, y)).free_symbols == {x, y}
assert func(x, (y, 1, 2)).free_symbols == {x}
assert func(x, (y, 1, 1)).free_symbols == {x}
assert func(x, (y, 1, z)).free_symbols == {x, z}
assert func(x, (x, 1, y), (y, 1, 2)).free_symbols == set()
assert func(x, (x, 1, y), (y, 1, z)).free_symbols == set([z])
assert func(x, (x, 1, y), (y, 1, y)).free_symbols == set([y])
assert func(x, (y, 1, y), (y, 1, z)).free_symbols == set([x, z])
assert Sum(1, (x, 1, y)).free_symbols == set([y])
assert func(x, (x, 1, y), (y, 1, z)).free_symbols == {z}
assert func(x, (x, 1, y), (y, 1, y)).free_symbols == {y}
assert func(x, (y, 1, y), (y, 1, z)).free_symbols == {x, z}
assert Sum(1, (x, 1, y)).free_symbols == {y}
# free_symbols answers whether the object *as written* has free symbols,
# not whether the evaluated expression has free symbols
assert Product(1, (x, 1, y)).free_symbols == set([y])
assert Product(1, (x, 1, y)).free_symbols == {y}


def test_conjugate_transpose():
Expand Down
3 changes: 0 additions & 3 deletions sympy/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from __future__ import print_function, division

import sys
sys._running_pytest = True

import pytest
from sympy.core.cache import clear_cache
import re
Expand Down
14 changes: 7 additions & 7 deletions sympy/core/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1301,12 +1301,12 @@ def replace(self, query, value, map=False, simultaneous=True, exact=False):
# if ``exact`` is True, only accept match if there are no null
# values amongst those matched.
if exact:
_value = lambda expr, result: (value(**dict([ (
str(key)[:-1], val) for key, val in result.items()]))
_value = lambda expr, result: (value(**{
str(key)[:-1]: val for key, val in result.items()})
if all(val for val in result.values()) else expr)
else:
_value = lambda expr, result: value(**dict([ (
str(key)[:-1], val) for key, val in result.items()]))
_value = lambda expr, result: value(**{
str(key)[:-1]: val for key, val in result.items()})
else:
raise TypeError(
"given an expression, replace() expects "
Expand Down Expand Up @@ -1361,8 +1361,8 @@ def rec_replace(expr):
# restore subexpressions in mapping
for o, n in mask:
r = {o: n}
mapping = dict([(k.xreplace(r), v.xreplace(r))
for k, v in mapping.items()])
mapping = {k.xreplace(r): v.xreplace(r)
for k, v in mapping.items()}
return rv, mapping

def find(self, query, group=False):
Expand Down Expand Up @@ -1696,7 +1696,7 @@ def _atomic(e):
try:
free = e.free_symbols
except AttributeError:
return set([e])
return {e}
atoms = set()
for p in pot:
if p in seen:
Expand Down
2 changes: 1 addition & 1 deletion sympy/core/compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def iterable(i, exclude=(string_types, dict, NotIterable)):
>>> from sympy.utilities.iterables import iterable
>>> from sympy import Tuple
>>> things = [[1], (1,), set([1]), Tuple(1), (j for j in [1, 2]), {1:2}, '1', 1]
>>> things = [[1], (1,), {1}, Tuple(1), (j for j in [1, 2]), {1:2}, '1', 1]
>>> for i in things:
... print('%s %s' % (iterable(i), type(i)))
True <... 'list'>
Expand Down
Loading

0 comments on commit 6006a84

Please sign in to comment.