本文整理汇总了Python中sympy.abc.f函数的典型用法代码示例。如果您正苦于以下问题:Python f函数的具体用法?Python f怎么用?Python f使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了f函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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))
示例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
示例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)
示例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
示例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
示例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
示例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)
示例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)
示例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))
示例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
示例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
示例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))
示例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
示例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
示例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