当前位置: 首页>>代码示例>>Python>>正文


Python sympy.ask函数代码示例

本文整理汇总了Python中sympy.ask函数的典型用法代码示例。如果您正苦于以下问题:Python ask函数的具体用法?Python ask怎么用?Python ask使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ask函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_triangular

def test_triangular():
    assert ask(Q.upper_triangular(X+Z.T+Identity(2)), Q.upper_triangular(X) &
            Q.lower_triangular(Z)) is True
    assert ask(Q.upper_triangular(X*Z.T), Q.upper_triangular(X) &
            Q.lower_triangular(Z)) is True
    assert ask(Q.lower_triangular(Identity(3))) is True
    assert ask(Q.lower_triangular(ZeroMatrix(3, 3))) is True
开发者ID:archipleago-creature,项目名称:sympy,代码行数:7,代码来源:test_matrices.py

示例2: test_assumptions

def test_assumptions():
    n = Symbol('n')
    A = MatrixSymbol('A', 1, n)
    P = PermutationMatrix(A)
    assert ask(Q.integer_elements(P))
    assert ask(Q.real_elements(P))
    assert ask(Q.complex_elements(P))
开发者ID:mrocklin,项目名称:computations,代码行数:7,代码来源:test_permutation.py

示例3: test_non_trivial_implies

def test_non_trivial_implies():
    X = MatrixSymbol('X', 3, 3)
    Y = MatrixSymbol('Y', 3, 3)
    assert ask(Q.lower_triangular(X+Y), Q.lower_triangular(X) &
               Q.lower_triangular(Y))
    assert ask(Q.triangular(X), Q.lower_triangular(X))
    assert ask(Q.triangular(X+Y), Q.lower_triangular(X) &
               Q.lower_triangular(Y))
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:8,代码来源:test_matrices.py

示例4: _eval_determinant

 def _eval_determinant(self):
     if self.blockshape == (2, 2):
         [[A, B],
          [C, D]] = self.blocks.tolist()
         if ask(Q.invertible(A)):
             return det(A)*det(D - C*A.I*B)
         elif ask(Q.invertible(D)):
             return det(D)*det(A - B*D.I*C)
     return Determinant(self)
开发者ID:JiraiyaGerotora,项目名称:sympy,代码行数:9,代码来源:blockmatrix.py

示例5: test_orthogonal

def test_orthogonal():
    assert ask(Q.orthogonal(X), Q.orthogonal(X))
    assert ask(Q.orthogonal(X.T), Q.orthogonal(X)) is True
    assert ask(Q.orthogonal(X.I), Q.orthogonal(X)) is True
    assert ask(Q.orthogonal(Y)) is False
    assert ask(Q.orthogonal(X)) is None
    assert ask(Q.orthogonal(X*Z*X), Q.orthogonal(X) & Q.orthogonal(Z)) is True
    assert ask(Q.orthogonal(Identity(3))) is True
    assert ask(Q.orthogonal(ZeroMatrix(3, 3))) is False
    assert ask(Q.invertible(X), Q.orthogonal(X))
    assert not ask(Q.orthogonal(X+Z), Q.orthogonal(X) & Q.orthogonal(Z))
开发者ID:archipleago-creature,项目名称:sympy,代码行数:11,代码来源:test_matrices.py

示例6: test_invertible

def test_invertible():
    assert ask(Q.invertible(X), Q.invertible(X))
    assert ask(Q.invertible(Y)) is False
    assert ask(Q.invertible(X*Y), Q.invertible(X)) is False
    assert ask(Q.invertible(X*Z), Q.invertible(X)) is None
    assert ask(Q.invertible(X*Z), Q.invertible(X) & Q.invertible(Z)) is True
    assert ask(Q.invertible(X.T)) is None
    assert ask(Q.invertible(X.T), Q.invertible(X)) is True
    assert ask(Q.invertible(X.I)) is True
    assert ask(Q.invertible(Identity(3))) is True
    assert ask(Q.invertible(ZeroMatrix(3, 3))) is False
开发者ID:archipleago-creature,项目名称:sympy,代码行数:11,代码来源:test_matrices.py

示例7: _test_orthogonal_unitary

def _test_orthogonal_unitary(predicate):
    assert ask(predicate(X), predicate(X))
    assert ask(predicate(X.T), predicate(X)) is True
    assert ask(predicate(X.I), predicate(X)) is True
    assert ask(predicate(Y)) is False
    assert ask(predicate(X)) is None
    assert ask(predicate(X*Z*X), predicate(X) & predicate(Z)) is True
    assert ask(predicate(Identity(3))) is True
    assert ask(predicate(ZeroMatrix(3, 3))) is False
    assert ask(Q.invertible(X), predicate(X))
    assert not ask(predicate(X + Z), predicate(X) & predicate(Z))
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:11,代码来源:test_matrices.py

示例8: test_fullrank

def test_fullrank():
    assert ask(Q.fullrank(X), Q.fullrank(X))
    assert ask(Q.fullrank(X**2), Q.fullrank(X))
    assert ask(Q.fullrank(X.T), Q.fullrank(X)) is True
    assert ask(Q.fullrank(X)) is None
    assert ask(Q.fullrank(Y)) is None
    assert ask(Q.fullrank(X*Z), Q.fullrank(X) & Q.fullrank(Z)) is True
    assert ask(Q.fullrank(Identity(3))) is True
    assert ask(Q.fullrank(ZeroMatrix(3, 3))) is False
    assert ask(Q.invertible(X), ~Q.fullrank(X)) == False
开发者ID:asmeurer,项目名称:sympy,代码行数:10,代码来源:test_matrices.py

示例9: test_symmetric

def test_symmetric():
    assert ask(Q.symmetric(X), Q.symmetric(X))
    assert ask(Q.symmetric(X*Z), Q.symmetric(X)) is None
    assert ask(Q.symmetric(X*Z), Q.symmetric(X) & Q.symmetric(Z)) is True
    assert ask(Q.symmetric(X+Z), Q.symmetric(X) & Q.symmetric(Z)) is True
    assert ask(Q.symmetric(Y)) is False
    assert ask(Q.symmetric(Y*Y.T)) is True
    assert ask(Q.symmetric(Y.T*X*Y)) is None
    assert ask(Q.symmetric(Y.T*X*Y), Q.symmetric(X)) is True
    assert ask(Q.symmetric(X*X*X*X*X*X*X*X*X*X), Q.symmetric(X)) is True
开发者ID:archipleago-creature,项目名称:sympy,代码行数:10,代码来源:test_matrices.py

示例10: dtype_of

def dtype_of(expr, *assumptions):
    if hasattr(expr, 'fortran_type'):
        return expr.fortran_type()

    with assuming(*assumptions):
        if ask(Q.integer(expr) | Q.integer_elements(expr)) or expr.is_integer:
            result = 'integer'
        elif ask(Q.real(expr) | Q.real_elements(expr)) or expr.is_real:
            result = 'real(kind=8)'
        elif ask(Q.complex(expr) | Q.complex_elements(expr)) or expr.is_complex:
            result = 'complex(kind=8)'
        else:
            raise TypeError('Could not infer type of %s'%str(expr))
    return result
开发者ID:mrocklin,项目名称:computations,代码行数:14,代码来源:core.py

示例11: test_MatrixSlice

def test_MatrixSlice():
    X = MatrixSymbol('X', 4, 4)
    B = MatrixSlice(X, (1, 3), (1, 3))
    C = MatrixSlice(X, (0, 3), (1, 3))
    assert ask(Q.symmetric(B), Q.symmetric(X))
    assert ask(Q.invertible(B), Q.invertible(X))
    assert ask(Q.diagonal(B), Q.diagonal(X))
    assert ask(Q.orthogonal(B), Q.orthogonal(X))
    assert ask(Q.upper_triangular(B), Q.upper_triangular(X))

    assert not ask(Q.symmetric(C), Q.symmetric(X))
    assert not ask(Q.invertible(C), Q.invertible(X))
    assert not ask(Q.diagonal(C), Q.diagonal(X))
    assert not ask(Q.orthogonal(C), Q.orthogonal(X))
    assert not ask(Q.upper_triangular(C), Q.upper_triangular(X))
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:15,代码来源:test_matrices.py

示例12: doit

 def doit(self, expand=False):
     if ask(Q.singular(self)):
         return S.Zero
     try:
         return self.arg._eval_determinant()
     except (AttributeError, NotImplementedError):
         return self
开发者ID:Acebulf,项目名称:sympy,代码行数:7,代码来源:determinant.py

示例13: isolate

def isolate(alg, eps=None, fast=False):
    """Give a rational isolating interval for an algebraic number. """
    alg = sympify(alg)

    if alg.is_Rational:
        return (alg, alg)
    elif not ask(Q.real(alg)):
        raise NotImplementedError(
            "complex algebraic numbers are not supported")

    func = lambdify((), alg, modules="mpmath", printer=IntervalPrinter())

    poly = minpoly(alg, polys=True)
    intervals = poly.intervals(sqf=True)

    dps, done = mp.dps, False

    try:
        while not done:
            alg = func()

            for a, b in intervals:
                if a <= alg.a and alg.b <= b:
                    done = True
                    break
            else:
                mp.dps *= 2
    finally:
        mp.dps = dps

    if eps is not None:
        a, b = poly.refine_root(a, b, eps=eps, fast=fast)

    return (a, b)
开发者ID:thilinarmtb,项目名称:sympy,代码行数:34,代码来源:numberfields.py

示例14: arctan_rule

def arctan_rule(integral):
    integrand, symbol = integral
    base, exp = integrand.as_base_exp()

    if sympy.simplify(exp + 1) == 0:
        a = sympy.Wild('a', exclude=[symbol])
        b = sympy.Wild('b', exclude=[symbol])
        match = base.match(a + b*symbol**2)
        if match:
            a, b = match[a], match[b]
            if ((isinstance(a, sympy.Number) and a < 0) or (isinstance(b, sympy.Number) and b < 0)):
                return
            if (sympy.ask(sympy.Q.negative(a) | sympy.Q.negative(b) | sympy.Q.is_true(a <= 0) | sympy.Q.is_true(b <= 0))):
                return
            #   /    dx       1  /   dx             1   /     dx                |                     |    1     1         /   du
            #  | --------- = -- | -------------- = --  | -------------------- = | sqrt(b/a)x = u      | =  -- ----------  | -------
            # /  a + bx^2    a /   1  + (b/a)x^2   a  /   1 + (sqrt(b/a)x)^2    | dx = du / sqrt(b/a) |    a   sqrt(b/a) /  1 + u^2
            if a == 1 and b == 1:
                return ArctanRule(integrand, symbol)
            if a == b:
                    constant = 1 / a
                    integrand_ = 1 / (1 + symbol**2)
                    substep = ArctanRule(integrand_, symbol)
                    return ConstantTimesRule(constant, integrand_, substep, integrand, symbol)
            u_var = new_symbol_(symbol)
            u_func = sympy.sqrt(sympy.sympify(b) / a) * symbol
            integrand_ = 1 / (1 + u_func**2)
            constant = 1 / sympy.sqrt(sympy.sympify(b) / a)
            substituted = 1 / (1 + u_var**2)
            substep = ArctanRule(substituted, u_var)
            substep = ConstantTimesRule(constant, substituted, substep, constant*substituted, u_var)
            substep = URule(u_var, u_func, constant, substep, constant*substituted, integrand_, symbol)
            return ConstantTimesRule(1/a, integrand_, substep, integrand, symbol)
开发者ID:hrashk,项目名称:sympy,代码行数:33,代码来源:manualintegrate.py

示例15: substitution_rule

def substitution_rule(integral):
    integrand, symbol = integral

    u_var = sympy.Dummy("u")
    substitutions = find_substitutions(integrand, symbol, u_var)
    if substitutions:
        ways = []
        for u_func, c, substituted in substitutions:
            subrule = integral_steps(substituted, u_var)
            if contains_dont_know(subrule):
                continue

            if sympy.simplify(c - 1) != 0:
                _, denom = c.as_numer_denom()
                subrule = ConstantTimesRule(c, substituted, subrule, substituted, symbol)

                if denom.free_symbols:
                    piecewise = []
                    could_be_zero = []

                    if isinstance(denom, sympy.Mul):
                        could_be_zero = denom.args
                    else:
                        could_be_zero.append(denom)

                    for expr in could_be_zero:
                        if not sympy.ask(~sympy.Q.zero(expr)):
                            substep = integral_steps(integrand.subs(expr, 0), symbol)

                            if substep:
                                piecewise.append((
                                    substep,
                                    sympy.Eq(expr, 0)
                                ))
                    piecewise.append((subrule, True))
                    subrule = PiecewiseRule(piecewise, substituted, symbol)

            ways.append(URule(u_var, u_func, c,
                              subrule,
                              integrand, symbol))

        if len(ways) > 1:
            return AlternativeRule(ways, integrand, symbol)
        elif ways:
            return ways[0]

    elif integrand.has(sympy.exp):
        u_func = sympy.exp(symbol)
        c = 1
        substituted = integrand / u_func.diff(symbol)
        substituted = substituted.subs(u_func, u_var)

        if symbol not in substituted.free_symbols:
            return URule(u_var, u_func, c,
                         integral_steps(substituted, u_var),
                         integrand, symbol)
开发者ID:Tkizzy,项目名称:PythonistaAppTemplate,代码行数:56,代码来源:manualintegrate.py


注:本文中的sympy.ask函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。