本文整理汇总了Python中sympy.abc.f函数的典型用法代码示例。如果您正苦于以下问题:Python f函数的具体用法?Python f怎么用?Python f使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了f函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_f_expand_complex
def test_f_expand_complex():
x = Symbol("x", real=True)
assert f(x).expand(complex=True) == I * im(f(x)) + re(f(x))
assert exp(x).expand(complex=True) == exp(x)
assert exp(I * x).expand(complex=True) == cos(x) + I * sin(x)
assert exp(z).expand(complex=True) == cos(im(z)) * exp(re(z)) + I * sin(im(z)) * exp(re(z))
开发者ID:scopatz,项目名称:sympy,代码行数:7,代码来源:test_function.py
示例2: test_Lambda
def test_Lambda():
e = Lambda(x, x**2)
assert e(4) == 16
assert e(x) == x**2
assert e(y) == y**2
assert Lambda((), 42)() == 42
assert Lambda((), 42) == Lambda((), 42)
assert Lambda((), 42) != Lambda((), 43)
assert Lambda((), f(x))() == f(x)
assert Lambda((), 42).nargs == FiniteSet(0)
assert Lambda(x, x**2) == Lambda(x, x**2)
assert Lambda(x, x**2) == Lambda(y, y**2)
assert Lambda(x, x**2) != Lambda(y, y**2 + 1)
assert Lambda((x, y), x**y) == Lambda((y, x), y**x)
assert Lambda((x, y), x**y) != Lambda((x, y), y**x)
assert Lambda((x, y), x**y)(x, y) == x**y
assert Lambda((x, y), x**y)(3, 3) == 3**3
assert Lambda((x, y), x**y)(x, 3) == x**3
assert Lambda((x, y), x**y)(3, y) == 3**y
assert Lambda(x, f(x))(x) == f(x)
assert Lambda(x, x**2)(e(x)) == x**4
assert e(e(x)) == x**4
assert Lambda((x, y), x + y).nargs == FiniteSet(2)
p = x, y, z, t
assert Lambda(p, t*(x + y + z))(*p) == t * (x + y + z)
assert Lambda(x, 2*x) + Lambda(y, 2*y) == 2*Lambda(x, 2*x)
assert Lambda(x, 2*x) not in [ Lambda(x, x) ]
raises(TypeError, lambda: Lambda(1, x))
assert Lambda(x, 1)(1) is S.One
开发者ID:aprasanna,项目名称:sympy,代码行数:35,代码来源:test_function.py
示例3: test_derivative_subs_bug
def test_derivative_subs_bug():
e = diff(g(x), x)
assert e.subs(g(x), f(x)) != e
assert e.subs(g(x), f(x)) == Derivative(f(x), x)
assert e.subs(g(x), -f(x)) == Derivative(-f(x), x)
assert e.subs(x, y) == Derivative(g(y), y)
开发者ID:normalhuman,项目名称:sympy,代码行数:7,代码来源:test_function.py
示例4: test_is_commutative
def test_is_commutative():
from sympy.physics.secondquant import NO, F, Fd
m = Symbol('m', commutative=False)
for f in (Sum, Product, Integral):
assert f(z, (z, 1, 1)).is_commutative is True
assert f(z*y, (z, 1, 6)).is_commutative is True
assert f(m*x, (x, 1, 2)).is_commutative is False
assert f(NO(Fd(x)*F(y))*z, (z, 1, 2)).is_commutative is False
开发者ID:JoenyBui,项目名称:sympy,代码行数:9,代码来源:test_sums_products.py
示例5: test_function_complex
def test_function_complex():
x = Symbol('x', complex=True)
assert f(x).is_commutative is True
assert sin(x).is_commutative is True
assert exp(x).is_commutative is True
assert log(x).is_commutative is True
assert f(x).is_complex is True
assert sin(x).is_complex is True
assert exp(x).is_complex is True
assert log(x).is_complex is True
开发者ID:normalhuman,项目名称:sympy,代码行数:10,代码来源:test_function.py
示例6: test_function_non_commutative
def test_function_non_commutative():
x = Symbol('x', commutative=False)
assert f(x).is_commutative is False
assert sin(x).is_commutative is False
assert exp(x).is_commutative is False
assert log(x).is_commutative is False
assert f(x).is_complex is False
assert sin(x).is_complex is False
assert exp(x).is_complex is False
assert log(x).is_complex is False
开发者ID:normalhuman,项目名称:sympy,代码行数:10,代码来源:test_function.py
示例7: test_unhandled
def test_unhandled():
class MyExpr(Expr):
def _eval_derivative(self, s):
if not s.name.startswith('xi'):
return self
else:
return None
expr = MyExpr(x, y, z)
assert diff(expr, x, y, f(x), z) == Derivative(expr, f(x), z)
assert diff(expr, f(x), x) == Derivative(expr, f(x), x)
开发者ID:normalhuman,项目名称:sympy,代码行数:11,代码来源:test_function.py
示例8: test_simplify_expr
def test_simplify_expr():
x, y, z, k, n, m, w, f, s, A = symbols("x,y,z,k,n,m,w,f,s,A")
assert all(simplify(tmp) == tmp for tmp in [I, E, oo, x, -x, -oo, -E, -I])
e = 1 / x + 1 / y
assert e != (x + y) / (x * y)
assert simplify(e) == (x + y) / (x * y)
e = A ** 2 * s ** 4 / (4 * pi * k * m ** 3)
assert simplify(e) == e
e = (4 + 4 * x - 2 * (2 + 2 * x)) / (2 + 2 * x)
assert simplify(e) == 0
e = (-4 * x * y ** 2 - 2 * y ** 3 - 2 * x ** 2 * y) / (x + y) ** 2
assert simplify(e) == -2 * y
e = -x - y - (x + y) ** (-1) * y ** 2 + (x + y) ** (-1) * x ** 2
assert simplify(e) == -2 * y
e = (x + x * y) / x
assert simplify(e) == 1 + y
e = (f(x) + y * f(x)) / f(x)
assert simplify(e) == 1 + y
e = (2 * (1 / n - cos(n * pi) / n)) / pi
assert simplify(e) == (-cos(pi * n) + 1) / (pi * n) * 2
e = integrate(1 / (x ** 3 + 1), x).diff(x)
assert simplify(e) == 1 / (x ** 3 + 1)
e = integrate(x / (x ** 2 + 3 * x + 1), x).diff(x)
assert simplify(e) == x / (x ** 2 + 3 * x + 1)
A = Matrix([[2 * k - m * w ** 2, -k], [-k, k - m * w ** 2]]).inv()
assert simplify((A * Matrix([0, f]))[1]) == -f * (2 * k - m * w ** 2) / (
k ** 2 - (k - m * w ** 2) * (2 * k - m * w ** 2)
)
f = -x + y / (z + t) + z * x / (z + t) + z * a / (z + t) + t * x / (z + t)
assert simplify(f) == (y + a * z) / (z + t)
A, B = symbols("A,B", commutative=False)
assert simplify(A * B - B * A) == A * B - B * A
assert simplify(A / (1 + y / x)) == x * A / (x + y)
assert simplify(A * (1 / x + 1 / y)) == A / x + A / y # (x + y)*A/(x*y)
assert simplify(log(2) + log(3)) == log(6)
assert simplify(log(2 * x) - log(2)) == log(x)
assert simplify(hyper([], [], x)) == exp(x)
开发者ID:pabloferz,项目名称:sympy,代码行数:54,代码来源:test_simplify.py
示例9: test_issue_12005
def test_issue_12005():
e1 = Subs(Derivative(f(x), x), (x,), (x,))
assert e1.diff(x) == Derivative(f(x), x, x)
e2 = Subs(Derivative(f(x), x), (x,), (x**2 + 1,))
assert e2.diff(x) == 2*x*Subs(Derivative(f(x), x, x), (x,), (x**2 + 1,))
e3 = Subs(Derivative(f(x) + y**2 - y, y), (y,), (y**2,))
assert e3.diff(y) == 4*y
e4 = Subs(Derivative(f(x + y), y), (y,), (x**2))
assert e4.diff(y) == S.Zero
e5 = Subs(Derivative(f(x), x), (y, z), (y, z))
assert e5.diff(x) == Derivative(f(x), x, x)
assert f(g(x)).diff(g(x), g(x)) == Derivative(f(g(x)), g(x), g(x))
开发者ID:normalhuman,项目名称:sympy,代码行数:12,代码来源:test_function.py
示例10: test_issue_7068
def test_issue_7068():
from sympy.abc import a, b, f
y1 = Dummy('y')
y2 = Dummy('y')
func1 = f(a + y1 * b)
func2 = f(a + y2 * b)
func1_y = func1.diff(y1)
func2_y = func2.diff(y2)
assert func1_y != func2_y
z1 = Subs(f(a), a, y1)
z2 = Subs(f(a), a, y2)
assert z1 != z2
开发者ID:normalhuman,项目名称:sympy,代码行数:12,代码来源:test_function.py
示例11: test_func_deriv
def test_func_deriv():
assert f(x).diff(x) == Derivative(f(x), x)
# issue 4534
assert f(x, y).diff(x, y) - f(x, y).diff(y, x) == 0
assert Derivative(f(x, y), x, y).args[1:] == ((x, 1), (y, 1))
assert Derivative(f(x, y), y, x).args[1:] == ((y, 1), (x, 1))
assert (Derivative(f(x, y), x, y) - Derivative(f(x, y), y, x)).doit() == 0
开发者ID:normalhuman,项目名称:sympy,代码行数:7,代码来源:test_function.py
示例12: test_Sum_doit
def test_Sum_doit():
assert Sum(n*Integral(a**2), (n, 0, 2)).doit() == a**3
assert Sum(n*Integral(a**2), (n, 0, 2)).doit(deep=False) == \
3*Integral(a**2)
assert summation(n*Integral(a**2), (n, 0, 2)) == 3*Integral(a**2)
# test nested sum evaluation
s = Sum( Sum( Sum(2,(z,1,n+1)), (y,x+1,n)), (x,1,n))
assert 0 == (s.doit() - n*(n+1)*(n-1)).factor()
assert Sum(Sum(KroneckerDelta(m, n), (m, 1, 3)), (n, 1, 3)).doit() == 3
assert Sum(Sum(KroneckerDelta(k, m), (m, 1, 3)), (n, 1, 3)).doit() == \
3*Piecewise((1, And(S(1) <= k, k <= 3)), (0, True))
assert Sum(f(n)*Sum(KroneckerDelta(m, n), (m, 0, oo)), (n, 1, 3)).doit() == \
f(1) + f(2) + f(3)
assert Sum(f(n)*Sum(KroneckerDelta(m, n), (m, 0, oo)), (n, 1, oo)).doit() == \
Sum(Piecewise((f(n), n >= 0), (0, True)), (n, 1, oo))
l = Symbol('l', integer=True, positive=True)
assert Sum(f(l)*Sum(KroneckerDelta(m, l), (m, 0, oo)), (l, 1, oo)).doit() == \
Sum(f(l), (l, 1, oo))
# issue 2597
nmax = symbols('N', integer=True, positive=True)
pw = Piecewise((1, And(S(1) <= n, n <= nmax)), (0, True))
assert Sum(pw, (n, 1, nmax)).doit() == Sum(pw, (n, 1, nmax))
开发者ID:JoenyBui,项目名称:sympy,代码行数:25,代码来源:test_sums_products.py
示例13: test_function_assumptions
def test_function_assumptions():
x = Symbol('x')
f = Function('f')
f_real = Function('f', real=True)
assert f != f_real
assert f(x) != f_real(x)
assert f(x).is_real is None
assert f_real(x).is_real is True
# Can also do it this way, but it won't be equal to f_real because of the
# way UndefinedFunction.__new__ works.
f_real2 = Function('f', is_real=True)
assert f_real2(x).is_real is True
开发者ID:normalhuman,项目名称:sympy,代码行数:15,代码来源:test_function.py
示例14: test_klein_gordon_lagrangian
def test_klein_gordon_lagrangian():
m = Symbol("m")
phi = f(x, t)
L = -(diff(phi, t) ** 2 - diff(phi, x) ** 2 - m ** 2 * phi ** 2) / 2
eqna = Eq(diff(L, phi) - diff(L, diff(phi, x), x) - diff(L, diff(phi, t), t), 0)
eqnb = Eq(diff(phi, t, t) - diff(phi, x, x) + m ** 2 * phi, 0)
assert eqna == eqnb
开发者ID:scopatz,项目名称:sympy,代码行数:8,代码来源:test_function.py
示例15: test_collect_D_0
def test_collect_D_0():
D = Derivative
f = Function('f')
x, a, b = symbols('x,a,b')
fxx = D(f(x), x, x)
# collect does not distinguish nested derivatives, so it returns
# -- (a + b)*D(D(f, x), x)
assert collect(a*fxx + b*fxx, fxx) == (a + b)*fxx
开发者ID:Lenqth,项目名称:sympy,代码行数:9,代码来源:test_radsimp.py
示例16: test_collect_3
def test_collect_3():
"""Collect with respect to a product"""
a, b, c = symbols('a,b,c')
f = Function('f')
x, y, z, n = symbols('x,y,z,n')
assert collect(-x/8 + x*y, -x) == x*(y - S(1)/8)
assert collect( 1 + x*(y**2), x*y ) == 1 + x*(y**2)
assert collect( x*y + a*x*y, x*y) == x*y*(1 + a)
assert collect( 1 + x*y + a*x*y, x*y) == 1 + x*y*(1 + a)
assert collect(a*x*f(x) + b*(x*f(x)), x*f(x)) == x*(a + b)*f(x)
assert collect(a*x*log(x) + b*(x*log(x)), x*log(x)) == x*(a + b)*log(x)
assert collect(a*x**2*log(x)**2 + b*(x*log(x))**2, x*log(x)) == \
x**2*log(x)**2*(a + b)
# with respect to a product of three symbols
assert collect(y*x*z + a*x*y*z, x*y*z) == (1 + a)*x*y*z
开发者ID:Lenqth,项目名称:sympy,代码行数:19,代码来源:test_radsimp.py
示例17: test_Sum_doit
def test_Sum_doit():
assert Sum(n * Integral(a ** 2), (n, 0, 2)).doit() == a ** 3
assert Sum(n * Integral(a ** 2), (n, 0, 2)).doit(deep=False) == 3 * Integral(a ** 2)
assert summation(n * Integral(a ** 2), (n, 0, 2)) == 3 * Integral(a ** 2)
# test nested sum evaluation
s = Sum(Sum(Sum(2, (z, 1, n + 1)), (y, x + 1, n)), (x, 1, n))
assert 0 == (s.doit() - n * (n + 1) * (n - 1)).factor()
assert Sum(KroneckerDelta(m, n), (m, -oo, oo)).doit() == Piecewise((1, And(-oo < n, n < oo)), (0, True))
assert Sum(x * KroneckerDelta(m, n), (m, -oo, oo)).doit() == Piecewise((x, And(-oo < n, n < oo)), (0, True))
assert Sum(Sum(KroneckerDelta(m, n), (m, 1, 3)), (n, 1, 3)).doit() == 3
assert Sum(Sum(KroneckerDelta(k, m), (m, 1, 3)), (n, 1, 3)).doit() == 3 * Piecewise(
(1, And(S(1) <= k, k <= 3)), (0, True)
)
assert Sum(f(n) * Sum(KroneckerDelta(m, n), (m, 0, oo)), (n, 1, 3)).doit() == f(1) + f(2) + f(3)
assert Sum(f(n) * Sum(KroneckerDelta(m, n), (m, 0, oo)), (n, 1, oo)).doit() == Sum(
Piecewise((f(n), And(Le(0, n), n < oo)), (0, True)), (n, 1, oo)
)
l = Symbol("l", integer=True, positive=True)
assert Sum(f(l) * Sum(KroneckerDelta(m, l), (m, 0, oo)), (l, 1, oo)).doit() == Sum(f(l), (l, 1, oo))
# issue 2597
nmax = symbols("N", integer=True, positive=True)
pw = Piecewise((1, And(S(1) <= n, n <= nmax)), (0, True))
assert Sum(pw, (n, 1, nmax)).doit() == Sum(pw, (n, 1, nmax))
q, s = symbols("q, s")
assert summation(1 / n ** (2 * s), (n, 1, oo)) == Piecewise(
(zeta(2 * s), 2 * s > 1), (Sum(n ** (-2 * s), (n, 1, oo)), True)
)
assert summation(1 / (n + 1) ** s, (n, 0, oo)) == Piecewise(
(zeta(s), s > 1), (Sum((n + 1) ** (-s), (n, 0, oo)), True)
)
assert summation(1 / (n + q) ** s, (n, 0, oo)) == Piecewise(
(zeta(s, q), And(q > 0, s > 1)), (Sum((n + q) ** (-s), (n, 0, oo)), True)
)
assert summation(1 / (n + q) ** s, (n, q, oo)) == Piecewise(
(zeta(s, 2 * q), And(2 * q > 0, s > 1)), (Sum((n + q) ** (-s), (n, q, oo)), True)
)
assert summation(1 / n ** 2, (n, 1, oo)) == zeta(2)
assert summation(1 / n ** s, (n, 0, oo)) == Sum(n ** (-s), (n, 0, oo))
开发者ID:ashutoshsaboo,项目名称:sympy,代码行数:42,代码来源:test_sums_products.py
示例18: test_nargs
def test_nargs():
f = Function('f')
assert f.nargs == S.Naturals0
assert f(1).nargs == S.Naturals0
assert Function('f', nargs=2)(1, 2).nargs == FiniteSet(2)
assert sin.nargs == FiniteSet(1)
assert sin(2).nargs == FiniteSet(1)
assert log.nargs == FiniteSet(1, 2)
assert log(2).nargs == FiniteSet(1, 2)
assert Function('f', nargs=2).nargs == FiniteSet(2)
assert Function('f', nargs=0).nargs == FiniteSet(0)
开发者ID:mayukuse24,项目名称:sympy,代码行数:11,代码来源:test_function.py
示例19: test_sho_lagrangian
def test_sho_lagrangian():
m = Symbol('m')
k = Symbol('k')
x = f(t)
L = m*diff(x, t)**2/2 - k*x**2/2
eqna = Eq(diff(L, x), diff(L, diff(x, t), t))
eqnb = Eq(-k*x, m*diff(x, t, t))
assert eqna == eqnb
assert diff(L, x, t) == diff(L, t, x)
assert diff(L, diff(x, t), t) == m*diff(x, t, 2)
assert diff(L, t, diff(x, t)) == -k*x + m*diff(x, t, 2)
开发者ID:normalhuman,项目名称:sympy,代码行数:13,代码来源:test_function.py
示例20: test_issue_7231
def test_issue_7231():
from sympy.abc import a
ans1 = f(x).series(x, a)
_xi_1 = ans1.atoms(Dummy).pop()
res = (f(a) + (-a + x)*Subs(Derivative(f(_xi_1), _xi_1), (_xi_1,), (a,)) +
(-a + x)**2*Subs(Derivative(f(_xi_1), _xi_1, _xi_1), (_xi_1,), (a,))/2 +
(-a + x)**3*Subs(Derivative(f(_xi_1), _xi_1, _xi_1, _xi_1),
(_xi_1,), (a,))/6 +
(-a + x)**4*Subs(Derivative(f(_xi_1), _xi_1, _xi_1, _xi_1, _xi_1),
(_xi_1,), (a,))/24 +
(-a + x)**5*Subs(Derivative(f(_xi_1), _xi_1, _xi_1, _xi_1, _xi_1, _xi_1),
(_xi_1,), (a,))/120 + O((-a + x)**6, (x, a)))
assert res == ans1
ans2 = f(x).series(x, a)
assert res == ans2
开发者ID:normalhuman,项目名称:sympy,代码行数:15,代码来源:test_function.py
注:本文中的sympy.abc.f函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论