#

用于查询有关假设的sypy对象的模块。

class sympy.assumptions.ask.AssumptionKeys[源代码]#

此类包含所有受支持的键 ask . 它应该通过实例访问 sympy.Q .

sympy.assumptions.ask.ask(proposition, assumptions=True, context={})[源代码]#

Function to evaluate the proposition with assumptions.

参数:

proposition : Boolean

Proposition which will be evaluated to boolean value. If this is not AppliedPredicate, it will be wrapped by Q.is_true.

assumptions : Boolean, optional

Local assumptions to evaluate the proposition.

context : AssumptionsContext, optional

Default assumptions to evaluate the proposition. By default, this is sympy.assumptions.global_assumptions variable.

返回:

True, False, or None

加薪:

TypeError : proposition or assumptions is not valid logical expression.

ValueError : assumptions are inconsistent.

解释

This function evaluates the proposition to True or False if the truth value can be determined. If not, it returns None.

It should be discerned from refine() which, when applied to a proposition, simplifies the argument to symbolic Boolean instead of Python built-in True, False or None.

Syntax

  • 提问(命题)

    Evaluate the proposition in global assumption context.

  • 提问(命题、假设)

    Evaluate the proposition with respect to assumptions in global assumption context.

实例

>>> from sympy import ask, Q, pi
>>> from sympy.abc import x, y
>>> ask(Q.rational(pi))
False
>>> ask(Q.even(x*y), Q.even(x) & Q.integer(y))
True
>>> ask(Q.prime(4*x), Q.integer(x))
False

If the truth value cannot be determined, None will be returned.

>>> print(ask(Q.odd(3*x))) # cannot determine unless we know x
None

ValueError is raised if assumptions are inconsistent.

>>> ask(Q.integer(x), Q.even(x) & Q.odd(x))
Traceback (most recent call last):
  ...
ValueError: inconsistent assumptions Q.even(x) & Q.odd(x)

笔记

假设中的关系还没有实现,所以下面的结果不会有意义。

>>> ask(Q.positive(x), x > 0)

然而,这是一项正在进行的工作。

参见

sympy.assumptions.refine.refine

Simplification using assumptions. Proposition is not reduced to None if the truth value cannot be determined.

sympy.assumptions.ask.register_handler(key, handler)[源代码]#

Register a handler in the ask system. key must be a string and handler a class inheriting from AskHandler.

自 1.8. 版本弃用: Use multipledispatch handler instead. See Predicate.

sympy.assumptions.ask.remove_handler(key, handler)[源代码]#

Removes a handler from the ask system.

自 1.8. 版本弃用: Use multipledispatch handler instead. See Predicate.