Did I find the right examples for you? yes no

All Samples(10)  |  Call(10)  |  Derive(0)  |  Import(0)
Substitutes old for new in an expression after sympifying args.

`args` is either:
  - two arguments, e.g. foo.subs(old, new)
  - one iterable argument, e.g. foo.subs(iterable). The iterable may be
     o an iterable container with (old, new) pairs. In this case the
       replacements are processed in the order given with successive
       patterns possibly affecting replacements already made.
     o a dict or set whose key/value items correspond to old/new pairs.
       In this case the old/new pairs will be sorted by op count and in(more...)

src/s/y/sympy-0.7.5/sympy/matrices/tests/test_immutable.py   sympy(Download)
def test_subs():
    A = ImmutableMatrix([[1, 2], [3, 4]])
    B = ImmutableMatrix([[1, 2], [x, 4]])
    C = ImmutableMatrix([[-x, x*y], [-(x + y), y**2]])
    assert B.subs(x, 3) == A
    assert (x*B).subs(x, 3) == 3*A
    assert (x*eye(2) + B).subs(x, 3) == 3*eye(2) + A
    assert C.subs([[x, -1], [y, -2]]) == A
    assert C.subs([(x, -1), (y, -2)]) == A
    assert C.subs({x: -1, y: -2}) == A
    assert C.subs([(x, -1), (y, -2)]) == A
    assert C.subs({x: -1, y: -2}) == A
    assert C.subs({x: y - 1, y: x - 1}, simultaneous=True) == \
        ImmutableMatrix([[1 - y, (x - 1)*(y - 1)], [2 - x - y, (x - 1)**2]])
 

src/s/y/sympy-HEAD/sympy/matrices/tests/test_immutable.py   sympy(Download)
def test_subs():
    A = ImmutableMatrix([[1, 2], [3, 4]])
    B = ImmutableMatrix([[1, 2], [x, 4]])
    C = ImmutableMatrix([[-x, x*y], [-(x + y), y**2]])
    assert B.subs(x, 3) == A
    assert (x*B).subs(x, 3) == 3*A
    assert (x*eye(2) + B).subs(x, 3) == 3*eye(2) + A
    assert C.subs([[x, -1], [y, -2]]) == A
    assert C.subs([(x, -1), (y, -2)]) == A
    assert C.subs({x: -1, y: -2}) == A
    assert C.subs([(x, -1), (y, -2)]) == A
    assert C.subs({x: -1, y: -2}) == A
    assert C.subs({x: y - 1, y: x - 1}, simultaneous=True) == \
        ImmutableMatrix([[1 - y, (x - 1)*(y - 1)], [2 - x - y, (x - 1)**2]])