本文整理汇总了Python中sympy.Symbol类的典型用法代码示例。如果您正苦于以下问题:Python Symbol类的具体用法?Python Symbol怎么用?Python Symbol使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Symbol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_dim
def get_dim(self, dim):
"""
Find a specific dimension which is part of the system.
dim can be a string or a dimension object. If no dimension is found,
then return None.
"""
#TODO: if the argument is a list, return a list of all matching dims
found_dim = None
#TODO: use copy instead of direct assignment for found_dim?
if isinstance(dim, string_types):
dim = Symbol(dim)
if dim.is_Symbol:
for d in self._dims:
if dim in (d.name, d.symbol):
found_dim = d
break
elif isinstance(dim, Dimension):
for i, idim in enumerate(self._dims):
if dim.get_dimensional_dependencies() == idim.get_dimensional_dependencies():
return idim
return found_dim
示例2: test_as_coeff_factors
def test_as_coeff_factors():
x = Symbol("x")
assert x.as_coeff_factors() == (0, (x,))
assert (-1 + x).as_coeff_factors() == (-1, (x,))
assert (2 + x).as_coeff_factors() == (2, (x,))
assert (1 + x).as_coeff_factors() == (1, (x,))
示例3: test_diff
def test_diff():
x = Symbol('x')
assert Rational(1, 3).diff(x) is S.Zero
assert I.diff(x) is S.Zero
assert pi.diff(x) is S.Zero
assert x.diff(x, 0) == x
assert (x**2).diff(x, 2, x) == 0
raises(ValueError, 'x.diff(1, x)')
a = Symbol("a")
b = Symbol("b")
c = Symbol("c")
p = Rational(5)
e = a*b + b**p
assert e.diff(a) == b
assert e.diff(b) == a + 5*b**4
assert e.diff(b).diff(a) == Rational(1)
e = a*(b + c)
assert e.diff(a) == b + c
assert e.diff(b) == a
assert e.diff(b).diff(a) == Rational(1)
e = c**p
assert e.diff(c, 6) == Rational(0)
assert e.diff(c, 5) == Rational(120)
e = c**Rational(2)
assert e.diff(c) == 2*c
e = a*b*c
assert e.diff(c) == a*b
示例4: test_K
def test_K():
assert K(0) == pi / 2
assert K(S(1) / 2) == 8 * pi ** (S(3) / 2) / gamma(-S(1) / 4) ** 2
assert K(1) == zoo
assert K(-1) == gamma(S(1) / 4) ** 2 / (4 * sqrt(2 * pi))
assert K(oo) == 0
assert K(-oo) == 0
assert K(I * oo) == 0
assert K(-I * oo) == 0
assert K(zoo) == 0
assert K(z).diff(z) == (E(z) - (1 - z) * K(z)) / (2 * z * (1 - z))
assert td(K(z), z)
zi = Symbol("z", real=False)
assert K(zi).conjugate() == K(zi.conjugate())
zr = Symbol("z", real=True, negative=True)
assert K(zr).conjugate() == K(zr)
assert K(z).rewrite(hyper) == (pi / 2) * hyper((S.Half, S.Half), (S.One,), z)
assert tn(K(z), (pi / 2) * hyper((S.Half, S.Half), (S.One,), z))
assert K(z).rewrite(meijerg) == meijerg(((S.Half, S.Half), []), ((S.Zero,), (S.Zero,)), -z) / 2
assert tn(K(z), meijerg(((S.Half, S.Half), []), ((S.Zero,), (S.Zero,)), -z) / 2)
assert K(z).series(
z
) == pi / 2 + pi * z / 8 + 9 * pi * z ** 2 / 128 + 25 * pi * z ** 3 / 512 + 1225 * pi * z ** 4 / 32768 + 3969 * pi * z ** 5 / 131072 + O(
z ** 6
)
示例5: test_Dummy_from_Symbol
def test_Dummy_from_Symbol():
# should not get the full dictionary of assumptions
n = Symbol('n', integer=True)
d = n.as_dummy()
s1 = "Dummy('n', dummy_index=%s, integer=True)" % str(d.dummy_index)
s2 = "Dummy('n', integer=True, dummy_index=%s)" % str(d.dummy_index)
assert srepr(d) in (s1, s2)
示例6: test_E
def test_E():
assert E(z, 0) == z
assert E(0, m) == 0
assert E(i*pi/2, m) == i*E(m)
assert E(z, oo) == zoo
assert E(z, -oo) == zoo
assert E(0) == pi/2
assert E(1) == 1
assert E(oo) == I*oo
assert E(-oo) == oo
assert E(zoo) == zoo
assert E(-z, m) == -E(z, m)
assert E(z, m).diff(z) == sqrt(1 - m*sin(z)**2)
assert E(z, m).diff(m) == (E(z, m) - F(z, m))/(2*m)
assert E(z).diff(z) == (E(z) - K(z))/(2*z)
r = randcplx()
assert td(E(r, m), m)
assert td(E(z, r), z)
assert td(E(z), z)
mi = Symbol('m', real=False)
assert E(z, mi).conjugate() == E(z.conjugate(), mi.conjugate())
mr = Symbol('m', real=True, negative=True)
assert E(z, mr).conjugate() == E(z.conjugate(), mr)
assert E(z).rewrite(hyper) == (pi/2)*hyper((-S.Half, S.Half), (S.One,), z)
assert tn(E(z), (pi/2)*hyper((-S.Half, S.Half), (S.One,), z))
assert E(z).rewrite(meijerg) == \
-meijerg(((S.Half, S(3)/2), []), ((S.Zero,), (S.Zero,)), -z)/4
assert tn(E(z), -meijerg(((S.Half, S(3)/2), []), ((S.Zero,), (S.Zero,)), -z)/4)
示例7: __init__
def __init__(self, data, step_size=1.0):
"""A continuous scalar data source from a discrete time series.
Time series data points are linearly interpolated in order to generate
values for points not present in the time series. The time series is
wrapped in order to generate an infinite sequence.
:param data: iterable of scalar values
:param step_size: number of LB iterations corresponding to one unit in
the time series (i.e. time distance between two neighboring points).
"""
Symbol.__init__("unused")
if type(data) is list or type(data) is tuple:
data = np.float64(data)
# Copy here is necessary so that the caller doesn't accidentally change
# the underlying array later. Also, we need the array to be C-contiguous
# (for __hash__ below), which might not be the case if it's a view.
self._data = data.copy()
self._step_size = step_size
# To be set later by the geometry encoder class. This is necessary due
# to how the printing system in Sympy works (see _ccode below).
self._offset = None
示例8: test_K
def test_K():
assert K(0) == pi/2
assert K(S(1)/2) == 8*pi**(S(3)/2)/gamma(-S(1)/4)**2
assert K(1) == zoo
assert K(-1) == gamma(S(1)/4)**2/(4*sqrt(2*pi))
assert K(oo) == 0
assert K(-oo) == 0
assert K(I*oo) == 0
assert K(-I*oo) == 0
assert K(zoo) == 0
assert K(z).diff(z) == (E(z) - (1 - z)*K(z))/(2*z*(1 - z))
assert td(K(z), z)
zi = Symbol('z', real=False)
assert K(zi).conjugate() == K(zi.conjugate())
zr = Symbol('z', real=True, negative=True)
assert K(zr).conjugate() == K(zr)
assert K(z).rewrite(hyper) == \
(pi/2)*hyper((S.Half, S.Half), (S.One,), z)
assert tn(K(z), (pi/2)*hyper((S.Half, S.Half), (S.One,), z))
assert K(z).rewrite(meijerg) == \
meijerg(((S.Half, S.Half), []), ((S.Zero,), (S.Zero,)), -z)/2
assert tn(K(z), meijerg(((S.Half, S.Half), []), ((S.Zero,), (S.Zero,)), -z)/2)
示例9: GeneralizedCoordinate
def GeneralizedCoordinate(s, constant=False):
gc = Symbol(s)(Symbol("t"))
gc.is_gc = True
if constant == True:
gc.fdiff = lambda argindex: 0
gc.__repr__ = lambda self: PyDyStrPrinter().doprint(self)
gc.__str__ = lambda self: PyDyStrPrinter().doprint(self)
return gc
示例10: test_atoms
def test_atoms():
x = Symbol('x')
y = Symbol('y')
assert list((1+x).atoms()) == [1,x]
assert list(x.atoms()) == [x]
assert list((1+2*cos(x)).atoms(type=Symbol)) == [x]
assert list((2*(x**(y**x))).atoms()) == [2,x,y]
assert list(Rational(1,2).atoms()) == [Rational(1,2)]
assert list(Rational(1,2).atoms(type=type(oo))) == []
示例11: test_as_dummy
def test_as_dummy():
x = Symbol('x')
x1 = x.as_dummy()
assert x1 != x
assert x1 != x.as_dummy()
x = Symbol('x', commutative=False)
x1 = x.as_dummy()
assert x1 != x
assert x1.is_commutative is False
示例12: test_as_dummy_nondummy
def test_as_dummy_nondummy():
x = Symbol('x')
x1 = x.as_dummy()
assert x1 != x
assert x1 != x.as_dummy()
# assert x == x1.as_nondummy()
x = Symbol('x', commutative = False)
x1 = x.as_dummy()
assert x1 != x
assert x1.is_commutative == False
示例13: __init__
def __init__(self, val):
if not Expr.initialized:
Expr.initialized = True
Expr.init()
if isinstance(val, int) or isinstance(val, long):
self.expr = Integer(val)
elif isinstance(val, basestring):
self.expr = Symbol(val)
elif isinstance(val, bool) or isinstance(val, BooleanAtom):
self.expr = S.One if val else S.Zero
else:
assert isinstance(val, SymPyExpr) or isinstance(val, BooleanFunction) \
or (val == S.Infinity) or (val == -S.Infinity)
self.expr = val
示例14: test_as_coeff_add
def test_as_coeff_add():
x = Symbol("x")
y = Symbol("y")
assert S(2).as_coeff_add() == (2, ())
assert S(3.0).as_coeff_add() == (0, (S(3.0),))
assert S(-3.0).as_coeff_add() == (0, (S(-3.0),))
assert x.as_coeff_add() == (0, (x,))
assert (-1 + x).as_coeff_add() == (-1, (x,))
assert (2 + x).as_coeff_add() == (2, (x,))
assert (1 + x).as_coeff_add() == (1, (x,))
assert (x + y).as_coeff_add(y) == (x, (y,))
assert (3 * x).as_coeff_add(y) == (3 * x, ())
# don't do expansion
e = (x + y) ** 2
assert e.as_coeff_add(y) == (0, (e,))
示例15: __new__
def __new__(cls, name, dim=None):
obj = Symbol.__new__(cls, name)
obj.dim = dim
obj._fields = None
obj._field_names = None
obj._constant_fields = None
return obj