本文整理汇总了Python中sympy.printing.python.python函数的典型用法代码示例。如果您正苦于以下问题:Python python函数的具体用法?Python python怎么用?Python python使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了python函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_python_functions
def test_python_functions():
# Simple
assert python((2*x + exp(x))) in "x = Symbol('x')\ne = 2*x + exp(x)"
assert python(sqrt(2)) == 'e = 2**(Half(1, 2))'
assert python(sqrt(2+pi)) == 'e = (2 + pi)**(Half(1, 2))'
assert python(abs(x)) == "x = Symbol('x')\ne = abs(x)"
assert python(abs(x/(x**2+1))) in ["x = Symbol('x')\ne = abs(x/(1 + x**2))",
"x = Symbol('x')\ne = abs(x/(x**2 + 1))"]
# Univariate/Multivariate functions
f = Function('f')
assert python(f(x)) == "x = Symbol('x')\nf = Function('f')\ne = f(x)"
assert python(f(x, y)) == "x = Symbol('x')\ny = Symbol('y')\nf = Function('f')\ne = f(x, y)"
assert python(f(x/(y+1), y)) in [
"x = Symbol('x')\ny = Symbol('y')\nf = Function('f')\ne = f(x/(1 + y), y)",
"x = Symbol('x')\ny = Symbol('y')\nf = Function('f')\ne = f(x/(y + 1), y)"]
# Nesting of square roots
assert python(sqrt((sqrt(x+1))+1)) in [
"x = Symbol('x')\ne = (1 + (1 + x)**(Half(1, 2)))**(Half(1, 2))",
"x = Symbol('x')\ne = ((x + 1)**(Half(1, 2)) + 1)**(Half(1, 2))"]
# Function powers
assert python(sin(x)**2) == "x = Symbol('x')\ne = sin(x)**2"
# Conjugates
a, b = map(Symbol, 'ab')
开发者ID:Sumith1896,项目名称:sympy-polys,代码行数:26,代码来源:test_python.py
示例2: test_python_keyword_symbol_name_escaping
def test_python_keyword_symbol_name_escaping():
# Check for escaping of keywords
assert python(5*Symbol("lambda")) == "lambda_ = Symbol('lambda')\ne = 5*lambda_"
assert (python(5*Symbol("lambda") + 7*Symbol("lambda_")) ==
"lambda__ = Symbol('lambda')\nlambda_ = Symbol('lambda_')\ne = 7*lambda_ + 5*lambda__")
assert (python(5*Symbol("for") + Function("for_")(8)) ==
"for__ = Symbol('for')\nfor_ = Function('for_')\ne = 5*for__ + for_(8)")
开发者ID:flacjacket,项目名称:sympy,代码行数:7,代码来源:test_python.py
示例3: test_python_relational
def test_python_relational():
assert python(Eq(x, y)) == "x = Symbol('x')\ny = Symbol('y')\ne = x == y"
assert python(Le(x, y)) == "x = Symbol('x')\ny = Symbol('y')\ne = x <= y"
assert python(Gt(x, y)) == "y = Symbol('y')\nx = Symbol('x')\ne = y < x"
assert python(Ne(x/(y+1), y**2)) in [
"x = Symbol('x')\ny = Symbol('y')\ne = x/(1 + y) != y**2",
"x = Symbol('x')\ny = Symbol('y')\ne = x/(y + 1) != y**2"]
开发者ID:Sumith1896,项目名称:sympy-polys,代码行数:7,代码来源:test_python.py
示例4: test_python_derivatives
def test_python_derivatives():
# Simple
f_1 = Derivative(log(x), x, evaluate=False)
assert python(f_1) == "x = Symbol('x')\ne = D(log(x), x)"
f_2 = Derivative(log(x), x, evaluate=False) + x
assert python(f_2) == "x = Symbol('x')\ne = x + D(log(x), x)"
# Multiple symbols
f_3 = Derivative(log(x) + x**2, x, y, evaluate=False)
#assert python(f_3) ==
f_4 = Derivative(2*x*y, y, x, evaluate=False) + x**2
assert python(f_4) in [
"x = Symbol('x')\ny = Symbol('y')\ne = x**2 + D(2*x*y, y, x)",
"x = Symbol('x')\ny = Symbol('y')\ne = D(2*x*y, y, x) + x**2"]
开发者ID:Sumith1896,项目名称:sympy-polys,代码行数:16,代码来源:test_python.py
示例5: test_python_relational
def test_python_relational():
assert python(Eq(x, y)) == "e = Eq(x, y)"
assert python(Ge(x, y)) == "x = Symbol('x')\ny = Symbol('y')\ne = x >= y"
assert python(Le(x, y)) == "x = Symbol('x')\ny = Symbol('y')\ne = x <= y"
assert python(Gt(x, y)) == "x = Symbol('x')\ny = Symbol('y')\ne = x > y"
assert python(Lt(x, y)) == "x = Symbol('x')\ny = Symbol('y')\ne = x < y"
assert python(Ne(x / (y + 1), y ** 2)) in ["e = Ne(x/(1 + y), y**2)", "e = Ne(x/(y + 1), y**2)"]
开发者ID:guanlongtianzi,项目名称:sympy,代码行数:7,代码来源:test_python.py
示例6: test_python_integrals
def test_python_integrals():
# Simple
f_1 = Integral(log(x), x)
assert python(f_1) == "x = Symbol('x')\ne = Integral(log(x), x)"
f_2 = Integral(x**2, x)
assert python(f_2) == "x = Symbol('x')\ne = Integral(x**2, x)"
# Double nesting of pow
f_3 = Integral(x**(2**x), x)
assert python(f_3) == "x = Symbol('x')\ne = Integral(x**(2**x), x)"
# Definite integrals
f_4 = Integral(x**2, (x,1,2))
assert python(f_4) == "x = Symbol('x')\ne = Integral(x**2, (x, 1, 2))"
f_5 = Integral(x**2, (x,Rational(1,2),10))
assert python(f_5) == "x = Symbol('x')\ne = Integral(x**2, (x, Half(1, 2), 10))"
# Nested integrals
f_6 = Integral(x**2*y**2, x,y)
assert python(f_6) == "x = Symbol('x')\ny = Symbol('y')\ne = Integral(x**2*y**2, x, y)"
开发者ID:Sumith1896,项目名称:sympy-polys,代码行数:22,代码来源:test_python.py
示例7: f
# print f(x).diff(x, x) + f(x)
# print dsolve(f(x).diff(x, x) + f(x), f(x))
from sympy import *
x = Symbol('x')
print (1/cos(x)).series(x, 0, 10)
print f(x).diff(x, x) + f(x)
from sympy import Integral, preview
from sympy.abc import x
preview(Integral(x**2, x))
from sympy.printing.python import python
from sympy import Integral
from sympy.abc import x
print python(x**2)
print python(1/x)
print python(Integral(x**2, x))
#----------------------------------------------
def fib(n): # write Fibonacci series up to n
a, b = 0, 1
while b < n:
print b; a, b = b, a+b;
# Now call the function we just defined:
fib(200)
#----------------------------------------------
import numpy as np
import matplotlib.pyplot as plt
开发者ID:albert4git,项目名称:aTest,代码行数:30,代码来源:scip1.py
示例8: test_python_limits
def test_python_limits():
assert python(limit(x, x, oo)) == 'e = oo'
assert python(limit(x**2, x, 0)) == 'e = 0'
开发者ID:Sumith1896,项目名称:sympy-polys,代码行数:3,代码来源:test_python.py
示例9: test_python_basic
def test_python_basic():
# Simple numbers/symbols
assert python(-Rational(1)/2) == "e = Rational(-1, 2)"
assert python(-Rational(13)/22) == "e = Rational(-13, 22)"
assert python(oo) == "e = oo"
# Powers
assert python((x**2)) == "x = Symbol(\'x\')\ne = x**2"
assert python(1/x) == "x = Symbol('x')\ne = 1/x"
assert python(y*x**-2) == "y = Symbol('y')\nx = Symbol('x')\ne = y/x**2"
assert python(x**Rational(-5, 2)) == "x = Symbol('x')\ne = x**(Rational(-5, 2))"
# Sums of terms
assert python((x**2 + x + 1)) in [
"x = Symbol('x')\ne = 1 + x + x**2",
"x = Symbol('x')\ne = x + x**2 + 1",
"x = Symbol('x')\ne = x**2 + x + 1",]
assert python(1-x) in [
"x = Symbol('x')\ne = 1 - x",
"x = Symbol('x')\ne = -x + 1"]
assert python(1-2*x) in [
"x = Symbol('x')\ne = 1 - 2*x",
"x = Symbol('x')\ne = -2*x + 1"]
assert python(1-Rational(3,2)*y/x) in [
"y = Symbol('y')\nx = Symbol('x')\ne = 1 - 3/2*y/x",
"y = Symbol('y')\nx = Symbol('x')\ne = -3/2*y/x + 1",
"y = Symbol('y')\nx = Symbol('x')\ne = 1 - 3*y/(2*x)"]
# Multiplication
assert python(x/y) == "x = Symbol('x')\ny = Symbol('y')\ne = x/y"
assert python(-x/y) == "x = Symbol('x')\ny = Symbol('y')\ne = -x/y"
assert python((x+2)/y) in [
"y = Symbol('y')\nx = Symbol('x')\ne = 1/y*(2 + x)",
"y = Symbol('y')\nx = Symbol('x')\ne = 1/y*(x + 2)",
"x = Symbol('x')\ny = Symbol('y')\ne = 1/y*(2 + x)",
"x = Symbol('x')\ny = Symbol('y')\ne = (2 + x)/y"]
assert python((1+x)*y) in [
"y = Symbol('y')\nx = Symbol('x')\ne = y*(1 + x)",
"y = Symbol('y')\nx = Symbol('x')\ne = y*(x + 1)",]
# Check for proper placement of negative sign
assert python(-5*x/(x+10)) == "x = Symbol('x')\ne = -5*x/(10 + x)"
assert python(1 - Rational(3,2)*(x+1)) in [
"x = Symbol('x')\ne = Rational(-1, 2) + Rational(-3, 2)*x",
"x = Symbol('x')\ne = Rational(-1, 2) - 3*x/2",
"x = Symbol('x')\ne = Rational(-1, 2) - 3*x/2"
]
开发者ID:Sumith1896,项目名称:sympy-polys,代码行数:47,代码来源:test_python.py
示例10: test_python_functions
def test_python_functions():
# Simple
assert python((2*x + exp(x))) in "x = Symbol('x')\ne = 2*x + exp(x)"
assert python(sqrt(2)) == 'e = sqrt(2)'
assert python(2**Rational(1, 3)) == 'e = 2**Rational(1, 3)'
assert python(sqrt(2 + pi)) == 'e = sqrt(2 + pi)'
assert python((2 + pi)**Rational(1, 3)) == 'e = (2 + pi)**Rational(1, 3)'
assert python(2**Rational(1, 4)) == 'e = 2**Rational(1, 4)'
assert python(Abs(x)) == "x = Symbol('x')\ne = Abs(x)"
assert python(Abs(x/(x**2+1))) in ["x = Symbol('x')\ne = Abs(x/(1 + x**2))",
"x = Symbol('x')\ne = Abs(x/(x**2 + 1))"]
# Univariate/Multivariate functions
f = Function('f')
assert python(f(x)) == "x = Symbol('x')\nf = Function('f')\ne = f(x)"
assert python(f(x, y)) == "x = Symbol('x')\ny = Symbol('y')\nf = Function('f')\ne = f(x, y)"
assert python(f(x/(y+1), y)) in [
"x = Symbol('x')\ny = Symbol('y')\nf = Function('f')\ne = f(x/(1 + y), y)",
"x = Symbol('x')\ny = Symbol('y')\nf = Function('f')\ne = f(x/(y + 1), y)"]
# Nesting of square roots
assert python(sqrt((sqrt(x+1))+1)) in [
"x = Symbol('x')\ne = sqrt(1 + sqrt(1 + x))",
"x = Symbol('x')\ne = sqrt(sqrt(x + 1) + 1)"]
# Nesting of powers
assert python((((x+1)**Rational(1, 3))+1)**Rational(1, 3)) in [
"x = Symbol('x')\ne = (1 + (1 + x)**Rational(1, 3))**Rational(1, 3)",
"x = Symbol('x')\ne = ((x + 1)**Rational(1, 3) + 1)**Rational(1, 3)"]
# Function powers
assert python(sin(x)**2) == "x = Symbol('x')\ne = sin(x)**2"
开发者ID:flacjacket,项目名称:sympy,代码行数:32,代码来源:test_python.py
示例11: test_python_keyword_function_name_escaping
def test_python_keyword_function_name_escaping():
assert python(5*Function("for")(8)) == "for_ = Function('for')\ne = 5*for_(8)"
开发者ID:flacjacket,项目名称:sympy,代码行数:2,代码来源:test_python.py
示例12: test_settings
def test_settings():
raises(TypeError, lambda: python(x, method="garbage"))
开发者ID:flacjacket,项目名称:sympy,代码行数:2,代码来源:test_python.py
示例13: test_python_functions_conjugates
def test_python_functions_conjugates():
a, b = map(Symbol, 'ab')
assert python( conjugate(a+b*I) ) == '_ _\na - I*b'
assert python( conjugate(exp(a+b*I)) ) == ' _ _\n a - I*b\ne '
开发者ID:flacjacket,项目名称:sympy,代码行数:4,代码来源:test_python.py
示例14: test_python_matrix
def test_python_matrix():
p = python(Matrix([[x**2+1, 1], [y, x+y]]))
s = "x = Symbol('x')\ny = Symbol('y')\ne = MutableDenseMatrix([[x**2 + 1, 1], [y, x + y]])"
assert p == s
开发者ID:artcompiler,项目名称:artcompiler.github.com,代码行数:4,代码来源:test_python.py
示例15: test_python_limits
def test_python_limits():
assert python(limit(x, x, oo)) == "e = oo"
assert python(limit(x ** 2, x, 0)) == "e = 0"
开发者ID:guanlongtianzi,项目名称:sympy,代码行数:3,代码来源:test_python.py
示例16: test_python_functions_conjugates
def test_python_functions_conjugates():
a, b = map(Symbol, "ab")
assert python(conjugate(a + b * I)) == "_ _\na - I*b"
assert python(conjugate(exp(a + b * I))) == " _ _\n a - I*b\ne "
开发者ID:guanlongtianzi,项目名称:sympy,代码行数:4,代码来源:test_python.py
注:本文中的sympy.printing.python.python函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论