pylogic.expressions package

Submodules

pylogic.expressions.abs module

class pylogic.expressions.abs.Abs(*args, **kwargs)[source]

Bases: Expr

A nonnegative real number representing the size of some object.

evaluate(**kwargs) Abs | Constant[source]

Evaluate the expression. Keyword arguments are used for passing additional information to the evaluation function.

to_sympy() Basic[source]

Convert the expression to a sympy object.

update_properties() None[source]

Update the properties of the expression. Properties include is_real, is_rational, is_integer, is_natural, is_zero, is_nonpositive, is_nonnegative, is_even.

pylogic.expressions.expr module

class pylogic.expressions.expr.Add(*args, **kwargs)[source]

Bases: Expr

evaluate(**kwargs) Add[source]

Evaluate the expression. Keyword arguments are used for passing additional information to the evaluation function.

to_sympy() Add[source]

Convert the expression to a sympy object.

update_properties() None[source]

Update the properties of the expression. Properties include is_real, is_rational, is_integer, is_natural, is_zero, is_nonpositive, is_nonnegative, is_even.

class pylogic.expressions.expr.BinaryExpression(*args, **kwargs)[source]

Bases: CustomExpr[U]

class pylogic.expressions.expr.CustomExpr(*args, **kwargs)[source]

Bases: Expr, Generic[U]

U is the return type after evaluating the expression, unless it is not fully evaluated.

evaluate(**kwargs) Self | U[source]

Calls the evaluation function with the arguments.

update_properties() None[source]

Update the properties of the expression. Properties include is_real, is_rational, is_integer, is_natural, is_zero, is_nonpositive, is_nonnegative, is_even.

class pylogic.expressions.expr.Expr(*args, **kwargs)[source]

Bases: ABC

property atoms: set[Class | Set | Symbol]
copy() Self[source]

Create a copy of this expression.

deepcopy() Self[source]
doit() Basic[source]
equals(other: Term, **kwargs) Equals[source]
eval_same(other: Any) bool[source]

Check if two expressions evaluate to the same value.

abstractmethod evaluate(**kwargs) Expr[source]

Evaluate the expression. Keyword arguments are used for passing additional information to the evaluation function.

is_atomic = False
property is_even: bool | None
property is_finite: bool | None
is_in(other: Set | Variable, **kwargs) IsContainedIn[source]
property is_integer: bool | None
property is_list: bool | None
property is_natural: bool | None
property is_negative: bool | None
property is_nonnegative: bool | None
property is_nonpositive: bool | None
property is_nonzero: bool | None
is_not_in(other: Set | Variable, **kwargs) Not[IsContainedIn][source]
property is_odd: bool | None
property is_positive: bool | None
property is_rational: bool | None
property is_real: bool | None
property is_sequence: bool | None
property is_set: bool | None
property is_zero: bool | None
kwargs = [('knowledge_base', 'knowledge_base')]
mutable_attrs_to_copy = ['independent_dependencies', '_is_real', '_is_rational', '_is_integer', '_is_natural', '_is_zero', '_is_nonpositive', '_is_nonnegative', '_is_positive', '_is_negative', '_is_even', '_is_sequence', '_is_set', '_is_list', '_is_finite', 'args', 'variables', 'independent_dependencies', 'constants', 'sets', 'class_ns', 'sets_contained_in']
replace(replace_dict: dict, equal_check: Callable | None = None, positions: list[list[int]] | None = None) Self[source]

For replacing subexpressions in an expression. equal_check is a function that checks if two objects are equal in order to replace.

property symbols: set[Any]
to_sympy() Basic[source]

Convert the expression to a sympy object.

unify(other: Self) Any | Literal[True] | None[source]

Algorithm to unify two expressions. If unification succeeds, a dictionary of values to instantiate variables to is returned. The dictionary never instantiates a variable y to variable y. It may instantiate a variable y to variable x or a variable y to a symbol or value y. If no instantiations need to be made (eg propositions are equal), return True. Otherwise (unification fails), return None.

abstractmethod update_properties() None[source]

Update the properties of the expression. Properties include is_real, is_rational, is_integer, is_natural, is_zero, is_nonpositive, is_nonnegative, is_even.

class pylogic.expressions.expr.Mul(*args, **kwargs)[source]

Bases: Expr

evaluate(**kwargs) Mul[source]

Evaluate the expression. Keyword arguments are used for passing additional information to the evaluation function.

to_sympy() Mul[source]

Convert the expression to a sympy object.

update_properties() None[source]

Update the properties of the expression. Properties include is_real, is_rational, is_integer, is_natural, is_zero, is_nonpositive, is_nonnegative, is_even.

class pylogic.expressions.expr.Pow(*args, **kwargs)[source]

Bases: Expr

evaluate(**kwargs) Pow[source]

Evaluate the expression. Keyword arguments are used for passing additional information to the evaluation function.

to_sympy() Pow[source]

Convert the expression to a sympy object.

update_properties() None[source]

Update the properties of the expression. Properties include is_real, is_rational, is_integer, is_natural, is_zero, is_nonpositive, is_nonnegative, is_even.

pylogic.expressions.expr.add(*args: Any | Expr) Add[source]
pylogic.expressions.expr.cbrt(expr: Any | Expr) Pow[source]
pylogic.expressions.expr.distance(a, b, eval_func: Callable[[U, U], Term | None] | None = None) Abs | CustomExpr[source]

General distance function.

Returns an expression representing the ‘distance’ between two terms.

When evaluated, it returns the absolute value of the difference for real numbers, or the result of the evaluation function for other types.

pylogic.expressions.expr.div(a: Any | Expr, b: Any | Expr) Mul[source]
pylogic.expressions.expr.max(*args)[source]
pylogic.expressions.expr.mul(*args: Any | Expr) Mul[source]
pylogic.expressions.expr.replace(expr: Any, replace_dict: dict, equal_check: Callable | None = None, positions: list[list[int]] | None = None) Any[source]

For replacing subexpressions in an expression. equal_check is a function that checks if two objects are equal in order to replace.

pylogic.expressions.expr.sqrt(expr: Any | Expr) Pow[source]
pylogic.expressions.expr.sub(a: Any | Expr, b: Any | Expr) Add[source]
pylogic.expressions.expr.to_sympy(expr: int) Integer[source]
pylogic.expressions.expr.to_sympy(expr: float) Float
pylogic.expressions.expr.to_sympy(expr: Fraction) Rational
pylogic.expressions.expr.to_sympy(expr: Expr) Basic
pylogic.expressions.expr.to_sympy(expr: Any) Symbol
pylogic.expressions.expr.to_sympy(expr: Set) Set

pylogic.expressions.function module

class pylogic.expressions.function.CalledFunction(*args, **kwargs)[source]

Bases: Expr

evaluate(**kwargs) Any[source]

Evaluate the expression. Keyword arguments are used for passing additional information to the evaluation function.

to_sympy() Basic[source]

Convert the expression to a sympy object.

update_properties() None[source]

Update the properties of the expression. Properties include is_real, is_rational, is_integer, is_natural, is_zero, is_nonpositive, is_nonnegative, is_even.

class pylogic.expressions.function.Function(*args, **kwargs)[source]

Bases: Expr

the function’s args include the domain and codomain.

define(parameters: tuple[Variable, ...], definition: Expr) None[source]
evaluate(**kwargs) Self[source]

Evaluate the expression. Keyword arguments are used for passing additional information to the evaluation function.

to_sympy() UndefinedFunction[source]

Convert the expression to a sympy object.

update_properties() None[source]

Update the properties of the expression. Properties include is_real, is_rational, is_integer, is_natural, is_zero, is_nonpositive, is_nonnegative, is_even.

class pylogic.expressions.function.SelfFunc(*args: Any)[source]

Bases: Expr

evaluate(**kwargs) Self[source]

Evaluate the expression. Keyword arguments are used for passing additional information to the evaluation function.

to_sympy() UndefinedFunction[source]

Convert the expression to a sympy object.

update_properties() None[source]

Update the properties of the expression. Properties include is_real, is_rational, is_integer, is_natural, is_zero, is_nonpositive, is_nonnegative, is_even.

pylogic.expressions.function.contains_self(expr: Expr) bool[source]

Check if an expression contains a SelfFunc.

pylogic.expressions.function.replace_self_func(expr: SelfFunc, func: Callable[[SelfFunc], T]) T[source]
pylogic.expressions.function.replace_self_func(expr: E, func: Callable[[SelfFunc], T]) E

Replace all SelfFuncs in an expression with a Term.

pylogic.expressions.function.self

alias of SelfFunc

pylogic.expressions.gcd module

class pylogic.expressions.gcd.Gcd(*args, **kwargs)[source]

Bases: Expr

The greatest common divisor of two or more integers.

evaluate(**kwargs) Any[source]

Evaluate the expression. Keyword arguments are used for passing additional information to the evaluation function.

update_properties() None[source]

Update the properties of the expression. Properties include is_real, is_rational, is_integer, is_natural, is_zero, is_nonpositive, is_nonnegative, is_even.

pylogic.expressions.limit module

class pylogic.expressions.limit.Limit(*args, **kwargs)[source]

Bases: Expr

evaluate(**kwargs) Limit | Constant[source]

Evaluate the expression. Keyword arguments are used for passing additional information to the evaluation function.

classmethod make_epsilon_N_definition(limit: Term, sequence: Sequence | Variable, **kwargs) ForallInSet[source]
update_properties() None[source]

Update the properties of the expression. Properties include is_real, is_rational, is_integer, is_natural, is_zero, is_nonpositive, is_nonnegative, is_even.

pylogic.expressions.max module

class pylogic.expressions.max.Max(*args, **kwargs)[source]

Bases: Expr

evaluate(**kwargs) Max | Any[source]

Evaluate the expression. Keyword arguments are used for passing additional information to the evaluation function.

update_properties() None[source]

Update the properties of the expression. Properties include is_real, is_rational, is_integer, is_natural, is_zero, is_nonpositive, is_nonnegative, is_even.

class pylogic.expressions.max.MaxElement(*args, **kwargs)[source]

Bases: Expr

evaluate(**kwargs) MaxElement | Any[source]

Evaluate the expression. Keyword arguments are used for passing additional information to the evaluation function.

update_properties() None[source]

Update the properties of the expression. Properties include is_real, is_rational, is_integer, is_natural, is_zero, is_nonpositive, is_nonnegative, is_even.

pylogic.expressions.min module

class pylogic.expressions.min.MinElement(*args, **kwargs)[source]

Bases: Expr

evaluate(**kwargs) MinElement | Any[source]

Evaluate the expression. Keyword arguments are used for passing additional information to the evaluation function.

update_properties() None[source]

Update the properties of the expression. Properties include is_real, is_rational, is_integer, is_natural, is_zero, is_nonpositive, is_nonnegative, is_even.

pylogic.expressions.mod module

class pylogic.expressions.mod.Mod(*args, **kwargs)[source]

Bases: Expr

The smallest natural number that remains when an integer is divided by another integer.

evaluate(**kwargs) Any[source]

Evaluate the expression. Keyword arguments are used for passing additional information to the evaluation function.

to_sympy() Basic[source]

Convert the expression to a sympy object.

update_properties() None[source]

Update the properties of the expression. Properties include is_real, is_rational, is_integer, is_natural, is_zero, is_nonpositive, is_nonnegative, is_even.

pylogic.expressions.piecewise module

class pylogic.expressions.piecewise.OtherwiseBranch(then: Any)[source]

Bases: Expr

evaluate(**kwargs) Any[source]

Evaluate the expression. Keyword arguments are used for passing additional information to the evaluation function.

to_sympy() ExprCondPair[source]

Convert the expression to a sympy object.

update_properties() None[source]

Update the properties of the expression. Properties include is_real, is_rational, is_integer, is_natural, is_zero, is_nonpositive, is_nonnegative, is_even.

pylogic.expressions.piecewise.Piecewise

alias of PiecewiseExpr

class pylogic.expressions.piecewise.PiecewiseBranch(*args, **kwargs)[source]

Bases: Expr, Generic[P]

Represents one branch of a piecewise function. Technicially, this should not be used in isolation, but only as part of a PiecewiseExpr.

evaluate(**kwargs) Any[source]

Evaluate the expression. Keyword arguments are used for passing additional information to the evaluation function.

to_sympy() Basic[source]

Convert the expression to a sympy object.

update_properties() None[source]

Update the properties of the expression. Properties include is_real, is_rational, is_integer, is_natural, is_zero, is_nonpositive, is_nonnegative, is_even.

class pylogic.expressions.piecewise.PiecewiseExpr(*args, **kwargs)[source]

Bases: Expr, Generic[Unpack[Ps]]

evaluate(knowledge_base: set[Proposition] | None = None, **kwargs) Term[source]

For now, we assume the knowledge base contains only proven propositions.

to_sympy() Basic[source]

Convert the expression to a sympy object.

update_properties() None[source]

Update the properties of the expression. Properties include is_real, is_rational, is_integer, is_natural, is_zero, is_nonpositive, is_nonnegative, is_even.

pylogic.expressions.piecewise.otherwise(then: Any) OtherwiseBranch[source]

pylogic.expressions.prod module

class pylogic.expressions.prod.Prod(*args, **kwargs)[source]

Bases: _Aggregate

Represents a product of a sequence of non-set terms. For products of sets, see pylogic.structures.set_.CartesProduct

to_sympy() Product | Mul[source]

Convert the expression to a sympy object.

update_properties() None[source]

Update the properties of the expression. Properties include is_real, is_rational, is_integer, is_natural, is_zero, is_nonpositive, is_nonnegative, is_even.

pylogic.expressions.sequence_term module

class pylogic.expressions.sequence_term.SequenceTerm(*args, **kwargs)[source]

Bases: Expr, Generic[T]

contains(term: Term, **kwargs) IsContainedIn[source]

For sequences of sets.

evaluate(**kwargs) SequenceTerm | T[source]

Evaluate the expression. Keyword arguments are used for passing additional information to the evaluation function.

predicate(term: Term) IsContainedIn[source]

For sequences of sets.

update_properties() None[source]

Update the properties of the expression. Properties include is_real, is_rational, is_integer, is_natural, is_zero, is_nonpositive, is_nonnegative, is_even.

pylogic.expressions.sum module

class pylogic.expressions.sum.Sum(*args, **kwargs)[source]

Bases: _Aggregate

Represents a sum of a sequence of non-set terms. For unions of sets, see pylogic.structures.set_.Union

to_sympy() Sum | Add[source]

Convert the expression to a sympy object.

update_properties() None[source]

Update the properties of the expression. Properties include is_real, is_rational, is_integer, is_natural, is_zero, is_nonpositive, is_nonnegative, is_even.

Module contents