def test_subs_CondSet(): s = FiniteSet(z, y) c = ConditionSet(x, x < 2, s) # you can only replace sym with a symbol that is not in # the free symbols assert c.subs(x, 1) == c assert c.subs(x, y) == c assert c.subs(x, w) == ConditionSet(w, w < 2, s) assert ConditionSet(x, x < y, s ).subs(y, w) == ConditionSet(x, x < w, s.subs(y, w)) # to eventually be removed c = ConditionSet((x, y), {x + 1, x + y}, S.Reals) assert c.subs(x, z) == c
def test_subs_CondSet(): s = FiniteSet(z, y) c = ConditionSet(x, x < 2, s) # you can only replace sym with a symbol that is not in # the free symbols assert c.subs(x, 1) == c assert c.subs(x, y) == ConditionSet(y, y < 2, s) # double subs needed to change dummy if the base set # also contains the dummy orig = ConditionSet(y, y < 2, s) base = orig.subs(y, w) and_dummy = base.subs(y, w) assert base == ConditionSet(y, y < 2, {w, z}) assert and_dummy == ConditionSet(w, w < 2, {w, z}) assert c.subs(x, w) == ConditionSet(w, w < 2, s) assert ConditionSet(x, x < y, s).subs(y, w) == ConditionSet(x, x < w, s.subs(y, w)) # if the user uses assumptions that cause the condition # to evaluate, that can't be helped from SymPy's end n = Symbol('n', negative=True) assert ConditionSet(n, 0 < n, S.Integers) is S.EmptySet p = Symbol('p', positive=True) assert ConditionSet(n, n < y, S.Integers).subs(n, x) == ConditionSet( x, x < y, S.Integers) nc = Symbol('nc', commutative=False) raises(ValueError, lambda: ConditionSet(x, x < p, S.Integers).subs(x, nc)) raises(ValueError, lambda: ConditionSet(x, x < p, S.Integers).subs(x, n)) raises(ValueError, lambda: ConditionSet(x + 1, x < 1, S.Integers)) raises(ValueError, lambda: ConditionSet(x + 1, x < 1, s)) assert ConditionSet(n, n < x, Interval(0, oo)).subs(x, p) == Interval(0, oo) assert ConditionSet(n, n < x, Interval(-oo, 0)).subs(x, p) == Interval(-oo, 0) assert ConditionSet(f(x), f(x) < 1, {w, z}).subs(f(x), y) == ConditionSet(y, y < 1, {w, z}) # issue 17341 k = Symbol('k') img1 = ImageSet(Lambda(k, 2 * k * pi + asin(y)), S.Integers) img2 = ImageSet(Lambda(k, 2 * k * pi + asin(S.One / 3)), S.Integers) assert ConditionSet(x, Contains(y, Interval(-1, 1)), img1).subs(y, S.One / 3).dummy_eq(img2)
def test_subs_CondSet(): s = FiniteSet(z, y) c = ConditionSet(x, x < 2, s) # you can only replace sym with a symbol that is not in # the free symbols assert c.subs(x, 1) == c assert c.subs(x, y) == ConditionSet(y, y < 2, s) # double subs needed to change dummy if the base set # also contains the dummy orig = ConditionSet(y, y < 2, s) base = orig.subs(y, w) and_dummy = base.subs(y, w) assert base == ConditionSet(y, y < 2, {w, z}) assert and_dummy == ConditionSet(w, w < 2, {w, z}) assert c.subs(x, w) == ConditionSet(w, w < 2, s) assert ConditionSet(x, x < y, s ).subs(y, w) == ConditionSet(x, x < w, s.subs(y, w)) # if the user uses assumptions that cause the condition # to evaluate, that can't be helped from SymPy's end n = Symbol('n', negative=True) assert ConditionSet(n, 0 < n, S.Integers) is S.EmptySet p = Symbol('p', positive=True) assert ConditionSet(n, n < y, S.Integers ).subs(n, x) == ConditionSet(x, x < y, S.Integers) nc = Symbol('nc', commutative=False) raises(ValueError, lambda: ConditionSet( x, x < p, S.Integers).subs(x, nc)) raises(ValueError, lambda: ConditionSet( x, x < p, S.Integers).subs(x, n)) raises(ValueError, lambda: ConditionSet( x + 1, x < 1, S.Integers)) raises(ValueError, lambda: ConditionSet( x + 1, x < 1, s)) assert ConditionSet( n, n < x, Interval(0, oo)).subs(x, p) == Interval(0, oo) assert ConditionSet( n, n < x, Interval(-oo, 0)).subs(x, p) == S.EmptySet assert ConditionSet(f(x), f(x) < 1, {w, z} ).subs(f(x), y) == ConditionSet(y, y < 1, {w, z})
def test_subs_CondSet(): s = FiniteSet(z, y) c = ConditionSet(x, x < 2, s) assert c.subs(x, y) == c assert c.subs(z, y) == ConditionSet(x, x < 2, FiniteSet(y)) assert c.xreplace({x: y}) == ConditionSet(y, y < 2, s) assert ConditionSet(x, x < y, s ).subs(y, w) == ConditionSet(x, x < w, s.subs(y, w)) # if the user uses assumptions that cause the condition # to evaluate, that can't be helped from SymPy's end n = Symbol('n', negative=True) assert ConditionSet(n, 0 < n, S.Integers) is S.EmptySet p = Symbol('p', positive=True) assert ConditionSet(n, n < y, S.Integers ).subs(n, x) == ConditionSet(n, n < y, S.Integers) raises(ValueError, lambda: ConditionSet( x + 1, x < 1, S.Integers)) assert ConditionSet( p, n < x, Interval(-5, 5)).subs(x, p) == Interval(-5, 5), ConditionSet( p, n < x, Interval(-5, 5)).subs(x, p) assert ConditionSet( n, n < x, Interval(-oo, 0)).subs(x, p ) == Interval(-oo, 0) assert ConditionSet(f(x), f(x) < 1, {w, z} ).subs(f(x), y) == ConditionSet(f(x), f(x) < 1, {w, z}) # issue 17341 k = Symbol('k') img1 = ImageSet(Lambda(k, 2*k*pi + asin(y)), S.Integers) img2 = ImageSet(Lambda(k, 2*k*pi + asin(S.One/3)), S.Integers) assert ConditionSet(x, Contains( y, Interval(-1,1)), img1).subs(y, S.One/3).dummy_eq(img2) assert (0, 1) in ConditionSet((x, y), x + y < 3, S.Integers**2) raises(TypeError, lambda: ConditionSet(n, n < -10, Interval(0, 10)))