當前位置: 首頁>>代碼示例>>Python>>正文


Python sympy.oo方法代碼示例

本文整理匯總了Python中sympy.oo方法的典型用法代碼示例。如果您正苦於以下問題:Python sympy.oo方法的具體用法?Python sympy.oo怎麽用?Python sympy.oo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sympy的用法示例。


在下文中一共展示了sympy.oo方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_constants

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import oo [as 別名]
def test_constants():
    assert sympify(sympy.E) == E
    assert sympy.E == E._sympy_()

    assert sympify(sympy.pi) == pi
    assert sympy.pi == pi._sympy_()

    assert sympify(sympy.GoldenRatio) == GoldenRatio
    assert sympy.GoldenRatio == GoldenRatio._sympy_()

    assert sympify(sympy.Catalan) == Catalan
    assert sympy.Catalan == Catalan._sympy_()

    assert sympify(sympy.EulerGamma) == EulerGamma
    assert sympy.EulerGamma == EulerGamma._sympy_()

    assert sympify(sympy.oo) == oo
    assert sympy.oo == oo._sympy_()

    assert sympify(sympy.zoo) == zoo
    assert sympy.zoo == zoo._sympy_()

    assert sympify(sympy.nan) == nan
    assert sympy.nan == nan._sympy_() 
開發者ID:symengine,項目名稱:symengine.py,代碼行數:26,代碼來源:test_sympy_conv.py

示例2: test_integrate

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import oo [as 別名]
def test_integrate():
    moments = quadpy.tools.integrate(lambda x: [x ** k for k in range(5)], -1, +1)
    assert (moments == [2, 0, sympy.S(2) / 3, 0, sympy.S(2) / 5]).all()

    moments = quadpy.tools.integrate(
        lambda x: orthopy.line_segment.tree_legendre(x, 4, "monic", symbolic=True),
        -1,
        +1,
    )
    assert (moments == [2, 0, 0, 0, 0]).all()

    # Example from Gautschi's "How to and how not to" article
    moments = quadpy.tools.integrate(
        lambda x: [x ** k * sympy.exp(-(x ** 3) / 3) for k in range(5)], 0, sympy.oo
    )
    S = numpy.vectorize(sympy.S)
    gamma = numpy.vectorize(sympy.gamma)
    n = numpy.arange(5)
    reference = 3 ** (S(n - 2) / 3) * gamma(S(n + 1) / 3)
    assert numpy.all([sympy.simplify(m - r) == 0 for m, r in zip(moments, reference)]) 
開發者ID:nschloe,項目名稱:quadpy,代碼行數:22,代碼來源:test_tools.py

示例3: test_gaussian

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import oo [as 別名]
def test_gaussian():
    """
    Make sure that symfit.distributions.Gaussians produces the expected
    sympy expression.
    """
    x0 = Parameter()
    sig = Parameter(positive=True)
    x = Variable()

    new = sympy.exp(-(x - x0)**2/(2*sig**2))/sympy.sqrt((2*sympy.pi*sig**2))
    assert isinstance(new, sympy.Expr)
    g = Gaussian(x, x0, sig)
    assert issubclass(g.__class__, sympy.Expr)
    assert new == g

    # A pdf should always integrate to 1 on its domain
    assert sympy.integrate(g, (x, -sympy.oo, sympy.oo)) == 1 
開發者ID:tBuLi,項目名稱:symfit,代碼行數:19,代碼來源:test_distributions.py

示例4: test_exp

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import oo [as 別名]
def test_exp():
    """
    Make sure that symfit.distributions.Exp produces the expected
    sympy expression.
    """
    l = Parameter(positive=True)
    x = Variable()

    new = l * sympy.exp(- l * x)
    assert isinstance(new, sympy.Expr)
    e = Exp(x, l)
    assert issubclass(e.__class__, sympy.Expr)
    assert new == e

    # A pdf should always integrate to 1 on its domain
    assert sympy.integrate(e, (x, 0, sympy.oo)) == 1 
開發者ID:tBuLi,項目名稱:symfit,代碼行數:18,代碼來源:test_distributions.py

示例5: default_args

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import oo [as 別名]
def default_args(self):
        return (oo,) 
開發者ID:sympsi,項目名稱:sympsi,代碼行數:4,代碼來源:operator.py

示例6: _represent_default_basis

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import oo [as 別名]
def _represent_default_basis(self, **options):
        if not self.N or self.N == oo:
            raise NotImplementedError('Cannot represent infinite dimensional' +
                                      ' identity operator as a matrix')

        format = options.get('format', 'sympy')
        if format != 'sympy':
            raise NotImplementedError('Representation in format ' +
                                      '%s not implemented.' % format)

        return eye(self.N) 
開發者ID:sympsi,項目名稱:sympsi,代碼行數:13,代碼來源:operator.py

示例7: eval

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import oo [as 別名]
def eval(cls, dimension):
        if len(dimension.atoms()) == 1:
            if not (dimension.is_Integer and dimension > 0 or dimension is oo
            or dimension.is_Symbol):
                raise TypeError('The dimension of a ComplexSpace can only'
                                'be a positive integer, oo, or a Symbol: %r'
                                % dimension)
        else:
            for dim in dimension.atoms():
                if not (dim.is_Integer or dim is oo or dim.is_Symbol):
                    raise TypeError('The dimension of a ComplexSpace can only'
                                    ' contain integers, oo, or a Symbol: %r'
                                    % dim) 
開發者ID:sympsi,項目名稱:sympsi,代碼行數:15,代碼來源:hilbert.py

示例8: dimension

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import oo [as 別名]
def dimension(self):
        arg_list = [arg.dimension for arg in self.args]
        if oo in arg_list:
            return oo
        else:
            return reduce(lambda x, y: x*y, arg_list) 
開發者ID:sympsi,項目名稱:sympsi,代碼行數:8,代碼來源:hilbert.py

示例9: test_L2

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import oo [as 別名]
def test_L2():
    b1 = L2(Interval(-oo, 1))
    assert isinstance(b1, L2)
    assert b1.dimension == oo
    assert b1.interval == Interval(-oo, 1)

    x = Symbol('x', real=True)
    y = Symbol('y', real=True)
    b2 = L2(Interval(x, y))
    assert b2.dimension == oo
    assert b2.interval == Interval(x, y)
    assert b2.subs(x, -1) == L2(Interval(-1, y)) 
開發者ID:sympsi,項目名稱:sympsi,代碼行數:14,代碼來源:test_hilbert.py

示例10: test_fock_space

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import oo [as 別名]
def test_fock_space():
    f1 = FockSpace()
    f2 = FockSpace()
    assert isinstance(f1, FockSpace)
    assert f1.dimension == oo
    assert f1 == f2 
開發者ID:sympsi,項目名稱:sympsi,代碼行數:8,代碼來源:test_hilbert.py

示例11: test_direct_sum

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import oo [as 別名]
def test_direct_sum():
    n = Symbol('n')
    hs1 = ComplexSpace(2)
    hs2 = ComplexSpace(n)

    h = hs1 + hs2
    assert isinstance(h, DirectSumHilbertSpace)
    assert h.dimension == 2 + n
    assert h.spaces == (hs1, hs2)

    f = FockSpace()
    h = hs1 + f + hs2
    assert h.dimension == oo
    assert h.spaces == (hs1, f, hs2) 
開發者ID:sympsi,項目名稱:sympsi,代碼行數:16,代碼來源:test_hilbert.py

示例12: test_stieltjes

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import oo [as 別名]
def test_stieltjes():
    alpha0, beta0 = quadpy.tools.stieltjes(lambda t: 1, -1, +1, 5)
    _, _, alpha1, beta1 = orthopy.line_segment.recurrence_coefficients.legendre(
        5, "monic", symbolic=True
    )
    assert (alpha0 == alpha1).all()
    assert (beta0 == beta1).all()


# def test_expt3():
#     '''Full example from Gautschi's "How to and how not to" article.
#     '''
#     # moments = quadpy.tools.integrate(
#     #         lambda x: sympy.exp(-x**3/3),
#     #         0, sympy.oo,
#     #         31
#     #         )
#     # print(moments)
#     # alpha, beta = quadpy.tools.chebyshev(moments)
#
#     alpha, beta = quadpy.tools.stieltjes(
#             lambda x: sympy.exp(-x**3/3),
#             0, sympy.oo,
#             5
#             )
#     print(alpha)
#     print(beta) 
開發者ID:nschloe,項目名稱:quadpy,代碼行數:29,代碼來源:test_tools.py

示例13: convert_atom

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import oo [as 別名]
def convert_atom(atom):
    if atom.LETTER():
        subscriptName = ''
        if atom.subexpr():
            subscript = None
            if atom.subexpr().expr():           # subscript is expr
                subscript = convert_expr(atom.subexpr().expr())
            else:                               # subscript is atom
                subscript = convert_atom(atom.subexpr().atom())
            subscriptName = '_{' + StrPrinter().doprint(subscript) + '}'
        return sympy.Symbol(atom.LETTER().getText() + subscriptName)
    elif atom.SYMBOL():
        s = atom.SYMBOL().getText()[1:]
        if s == "infty":
            return sympy.oo
        else:
            if atom.subexpr():
                subscript = None
                if atom.subexpr().expr():           # subscript is expr
                    subscript = convert_expr(atom.subexpr().expr())
                else:                               # subscript is atom
                    subscript = convert_atom(atom.subexpr().atom())
                subscriptName = StrPrinter().doprint(subscript)
                s += '_{' + subscriptName + '}'
            return sympy.Symbol(s)
    elif atom.NUMBER():
        s = atom.NUMBER().getText().replace(",", "")
        return sympy.Number(s)
    elif atom.DIFFERENTIAL():
        var = get_differential_var(atom.DIFFERENTIAL())
        return sympy.Symbol('d' + var.name)
    elif atom.mathit():
        text = rule2text(atom.mathit().mathit_text())
        return sympy.Symbol(text) 
開發者ID:augustt198,項目名稱:latex2sympy,代碼行數:36,代碼來源:process_latex.py

示例14: test_requires_partial

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import oo [as 別名]
def test_requires_partial():
    x, y, z, t, nu = symbols('x y z t nu')
    n = symbols('n', integer=True)

    f = x * y
    assert requires_partial(Derivative(f, x)) is True
    assert requires_partial(Derivative(f, y)) is True

    ## integrating out one of the variables
    assert requires_partial(Derivative(Integral(exp(-x * y), (x, 0, oo)), y, evaluate=False)) is False

    ## bessel function with smooth parameter
    f = besselj(nu, x)
    assert requires_partial(Derivative(f, x)) is True
    assert requires_partial(Derivative(f, nu)) is True

    ## bessel function with integer parameter
    f = besselj(n, x)
    assert requires_partial(Derivative(f, x)) is False
    # this is not really valid (differentiating with respect to an integer)
    # but there's no reason to use the partial derivative symbol there. make
    # sure we don't throw an exception here, though
    assert requires_partial(Derivative(f, n)) is False

    ## bell polynomial
    f = bell(n, x)
    assert requires_partial(Derivative(f, x)) is False
    # again, invalid
    assert requires_partial(Derivative(f, n)) is False

    ## legendre polynomial
    f = legendre(0, x)
    assert requires_partial(Derivative(f, x)) is False

    f = legendre(n, x)
    assert requires_partial(Derivative(f, x)) is False
    # again, invalid
    assert requires_partial(Derivative(f, n)) is False

    f = x ** n
    assert requires_partial(Derivative(f, x)) is False

    assert requires_partial(Derivative(Integral((x*y) ** n * exp(-x * y), (x, 0, oo)), y, evaluate=False)) is False

    # parametric equation
    f = (exp(t), cos(t))
    g = sum(f)
    assert requires_partial(Derivative(g, t)) is False

    # function of unspecified variables
    f = symbols('f', cls=Function)
    assert requires_partial(Derivative(f, x)) is False
    assert requires_partial(Derivative(f, x, y)) is True 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:55,代碼來源:test_conventions.py

示例15: sympy_expr_abs_distance_key

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import oo [as 別名]
def sympy_expr_abs_distance_key(e):
    """
    Transform expression into tuple for sorting and comparison.

    e.g., sympy_expr_abs_distance_key(N**2 + 23) -> ((2, 0.0), (1, 0.0), (0, 23.0))

    Multiple variables are treated equal (N*M == N**2).
    """
    # Integers
    if type(e) is int or e.is_Integer:
        return ((0, abs(e)),)

    # Infinity
    if abs(e) is sympy.oo:
        return ((sympy.oo, sympy.oo),)

    # Expressions, replace all free_symbols with one
    first_s = None
    for i, s in enumerate(e.free_symbols):
        # Skip and remember first symbol
        if i == 0:
            first_s = s
            continue
        e = e.subs(s, first_s)
    e = e.expand()

    key = []
    # split into terms
    terms, gens = e.as_terms()
    assert gens == [first_s] or first_s is None and gens == [], \
        "Expression was split into unusable terms: {}, expected.".format(gens, first_s)
    # extract exponent and coefficient
    for term, (coeff, cpart, ncpart) in terms:
        coeff_real, coeff_imag = coeff
        assert coeff_imag == 0, "Not supporting imaginary coefficients."
        # Sort order: exponent (cpart), factor
        key.append(cpart + (coeff_real,))
    key[0] = (key[0][0], key[0][1])
    # build key
    key.sort(reverse=True)
    # add missing exponent, coefficient tuples
    i = 0
    for exponent in reversed(range(key[0][0]+1)):
        if len(key) > i and key[i][0] == exponent:
            i += 1
            continue
        else:
            key[i:i] = [(exponent, 0.0)]
            i += 1
    key = tuple(key)
    return key 
開發者ID:RRZE-HPC,項目名稱:kerncraft,代碼行數:53,代碼來源:cacheprediction.py


注:本文中的sympy.oo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。