コード例 #1
0
def test_FunctionWrapper():
    import sympy
    sympy.var("n, m, theta, phi")
    r = sympy.Ynm(n, m, theta, phi)
    s = Integer(2) * r
    assert isinstance(s, Mul)
    assert isinstance(s.args[1]._sympy_(), sympy.Ynm)
コード例 #2
0
def test_FunctionWrapper():
    import sympy
    n, m, theta, phi = sympy.symbols("n, m, theta, phi")
    r = sympy.Ynm(n, m, theta, phi)
    s = Integer(2) * r
    assert isinstance(s, Mul)
    assert isinstance(s.args[1]._sympy_(), sympy.Ynm)

    x = symbols("x")
    e = x + sympy.loggamma(x)
    assert str(e) == "x + loggamma(x)"
    assert isinstance(e, Add)
    assert e + sympy.loggamma(x) == x + 2 * sympy.loggamma(x)

    f = e.subs({x: 10})
    assert f == 10 + log(362880)

    f = e.subs({x: 2})
    assert f == 2

    f = e.subs({x: 100})
    v = f.n(53, real=True)
    assert abs(float(v) - 459.13420537) < 1e-7

    f = e.diff(x)
    assert f == 1 + sympy.polygamma(0, x)
コード例 #3
0
 def _get_cartfn(l, m):
     """Return the reference result in Cartesian coordinates with SymPy."""
     # Take the complex spherical harmonics from SymPy and write in terms
     # of simple trigoniometric functions.
     ref = sp.Ynm(l, abs(m), theta, phi)
     ref = ref.expand(func=True)
     ref = ref.subs(sp.exp(sp.I * phi), sp.cos(phi) + sp.I * sp.sin(phi))
     # Take the definition of real functions from Wikipedia, not from
     # SymPy. The latter has an incompatible sign for the sin-like
     # functions.
     if m > 0:
         ref = sp.re(ref) * sp.sqrt(2)
     elif m < 0:
         ref = sp.im(ref) * sp.sqrt(2)
     # Undo the Condon-Shortley phase
     ref *= (-sp.Integer(1))**abs(m)
     # Convert to regular solid harmonics
     ref = (sp.sqrt(4 * sp.pi / (2 * l + 1)) * ref * r**l).expand()
     # From spherical to Cartesian coordinates
     ref = ref.subs(sp.cos(phi), x / (r * sp.sin(theta)))
     ref = ref.subs(sp.sin(phi), y / (r * sp.sin(theta)))
     ref = ref.subs(sp.cos(theta), z / r)
     ref = ref.subs(sp.sin(theta), sp.sqrt(x * x + y * y) / r)
     ref = ref.subs(r, sp.sqrt(r2)).expand()
     return sp.simplify(ref).expand()
コード例 #4
0
def test_FunctionWrapper():
    import sympy
    n, m, theta, phi = sympy.symbols("n, m, theta, phi")
    r = sympy.Ynm(n, m, theta, phi)
    s = Integer(2) * r
    assert isinstance(s, Mul)
    assert isinstance(s.args[1]._sympy_(), sympy.Ynm)

    x = symbols("x")
    e = x + sympy.Mod(x, 2)
    assert str(e) == "x + Mod(x, 2)"
    assert isinstance(e, Add)
    assert e + sympy.Mod(x, 2) == x + 2 * sympy.Mod(x, 2)

    f = e.subs({x: 10})
    assert f == 10

    f = e.subs({x: 2})
    assert f == 2

    f = e.subs({x: 100})
    v = f.n(53, real=True)
    assert abs(float(v) - 100.00000000) < 1e-7