Esempio n. 1
0
def test_issue_6976():
    x, y = symbols('x y')
    assert (sqrt(x)**3 + sqrt(x) + x + x**2).subs(sqrt(x), y) == \
        y**4 + y**3 + y**2 + y
    assert (x**4 + x**3 + x**2 + x + sqrt(x)).subs(x**2, y) == \
        sqrt(x) + x**3 + x + y**2 + y
    assert x.subs(x**3, y) == x
    assert x.subs(x**(S(1) / 3), y) == y**3

    # More substitutions are possible with nonnegative symbols
    x, y = symbols('x y', nonnegative=True)
    assert (x**4 + x**3 + x**2 + x + sqrt(x)).subs(x**2, y) == \
        y**(1/4) + y**(3/2) + sqrt(y) + y**2 + y
    assert x.subs(x**3, y) == y**(1 / 3)
Esempio n. 2
0
def test_issue_6976():
    x, y = symbols('x y')
    assert (sqrt(x)**3 + sqrt(x) + x + x**2).subs(sqrt(x), y) == \
        y**4 + y**3 + y**2 + y
    assert (x**4 + x**3 + x**2 + x + sqrt(x)).subs(x**2, y) == \
        sqrt(x) + x**3 + x + y**2 + y
    assert x.subs(x**3, y) == x
    assert x.subs(x**(S(1)/3), y) == y**3

    # More substitutions are possible with nonnegative symbols
    x, y = symbols('x y', nonnegative=True)
    assert (x**4 + x**3 + x**2 + x + sqrt(x)).subs(x**2, y) == \
        y**(S(1)/4) + y**(S(3)/2) + sqrt(y) + y**2 + y
    assert x.subs(x**3, y) == y**(S(1)/3)
Esempio n. 3
0
def test_issue_6976():
    x, y = symbols("x y")
    assert (sqrt(x)**3 + sqrt(x) + x + x**2).subs(sqrt(x),
                                                  y) == y**4 + y**3 + y**2 + y
    assert (x**4 + x**3 + x**2 + x + sqrt(x)).subs(
        x**2, y) == sqrt(x) + x**3 + x + y**2 + y
    assert x.subs(x**3, y) == x
    assert x.subs(x**Rational(1, 3), y) == y**3

    # More substitutions are possible with nonnegative symbols
    x, y = symbols("x y", nonnegative=True)
    assert (x**4 + x**3 + x**2 + x + sqrt(x)).subs(
        x**2, y) == y**Rational(1, 4) + y**Rational(3, 2) + sqrt(y) + y**2 + y
    assert x.subs(x**3, y) == y**Rational(1, 3)
Esempio n. 4
0
def test_issue_8886():
    from sympy.physics.mechanics import ReferenceFrame as R
    # if something can't be sympified we assume that it
    # doesn't play well with SymPy and disallow the
    # substitution
    v = R('A').x
    assert x.subs(x, v) == x
    assert v.subs(v, x) == v
    assert v.__eq__(x) is False
Esempio n. 5
0
def test_issue_8886():
    from sympy.physics.mechanics import ReferenceFrame as R
    # if something can't be sympified we assume that it
    # doesn't play well with SymPy and disallow the
    # substitution
    v = R('A').x
    assert x.subs(x, v) == x
    assert v.subs(v, x) == v
    assert v.__eq__(x) is False
Esempio n. 6
0
def test_dict_set():
    a, b, c = map(Wild, 'abc')

    f = 3 * cos(4 * x)
    r = f.match(a * cos(b * x))
    assert r == {a: 3, b: 4}
    e = a / b * sin(b * x)
    assert e.subs(r) == r[a] / r[b] * sin(r[b] * x)
    assert e.subs(r) == 3 * sin(4 * x) / 4
    s = set(r.items())
    assert e.subs(s) == r[a] / r[b] * sin(r[b] * x)
    assert e.subs(s) == 3 * sin(4 * x) / 4

    assert e.subs(r) == r[a] / r[b] * sin(r[b] * x)
    assert e.subs(r) == 3 * sin(4 * x) / 4
    assert x.subs(Dict((x, 1))) == 1
Esempio n. 7
0
def test_dict_set():
    a, b, c = map(Wild, 'abc')

    f = 3*cos(4*x)
    r = f.match(a*cos(b*x))
    assert r == {a: 3, b: 4}
    e = a/b*sin(b*x)
    assert e.subs(r) == r[a]/r[b]*sin(r[b]*x)
    assert e.subs(r) == 3*sin(4*x) / 4
    s = set(r.items())
    assert e.subs(s) == r[a]/r[b]*sin(r[b]*x)
    assert e.subs(s) == 3*sin(4*x) / 4

    assert e.subs(r) == r[a]/r[b]*sin(r[b]*x)
    assert e.subs(r) == 3*sin(4*x) / 4
    assert x.subs(Dict((x, 1))) == 1
Esempio n. 8
0
def test_subs_iter():
    assert x.subs(reversed([[x, y]])) == y
    it = iter([[x, y]])
    assert x.subs(it) == y
    assert x.subs(Tuple((x, y))) == y
Esempio n. 9
0
def test_subs_iter():
    assert x.subs(reversed([[x, y]])) == y
    it = iter([[x, y]])
    assert x.subs(it) == y
    assert x.subs(Tuple((x, y))) == y
Esempio n. 10
0
 def f(v):
     v = map(int, list(v)) if isinstance(v, str) else v
     v = x.subs(zip(sy.symbols(f'x:{n}'), v))
     return tuple(v)