mvlogics¶
Implementations of various logics, not necessarily with two truth values.
A logic is a propositional calculus, with an example being the familiar logical calculus of Aristotle’s, where the only truth values are
T (True, verum) and F (False, falsum) and the law of the excluded middle (that is, p | ~p for all propositions p) holds.
Logics do not support subclassing, same as the built-in type bool.
Members of all classes in this module but Unit are lazily generated to avoid significant memory overhead.
Submodules¶
Attributes¶
The names of all built-in logics defined in this module. |
|
|
|
Equivalent to |
|
The method names logic classes may have for specialized use cases, including possibly niche fuzzy and modal logic operators. |
|
The names of the 'protocols' defined in the |
|
|
|
Method/property names logic classes are forbidden from implementing. |
|
The method names of methods that will be provided automatically to logic base classes. |
|
The method names logic classes are recommended to have if suitable, corresponding to less common logical operations. |
|
The method names all logic classes must have. |
Classes¶
Belnap's logic B_4, a combination of K_3 and P_3, such that the overdetermined I is called B for 'both', and the underdetermined N for 'neither' The truth tables are derived accordingly. |
|
Dmitry Bochvar's internal three-value logic, also known as Kleene's weak three-value logic. The indeterminate truth value is contagious in the sense that it propagates as the result of any operation that involves it. |
|
Boolean or Aristotelian logic, where the law of the excluded middle holds. |
|
Alias to |
|
Gödel's infinite-valued logic, with rational numbers between 0 and 1 as truth values. |
|
Gödel's infinite-valued logic, with real numbers between 0 and 1 as truth values. |
|
Kleene's strong logic of indeterminancy K_3, in which besides the truth values T and F, a new 'indeterminate' truth value I is introduced. |
|
Jan Łukasiewicz's three-valued logic; the truth values for 0, 1/2, 1 are called F, U and T respectively. |
|
Priest's 'logic of paradox' (P_3), provisionally named LP because P_3 refers to ternary Post logic here. |
|
Łukasiewicz's infinite-valued logic, with rational numbers between 0 and 1 as truth values. |
|
Łukasiewicz's infinite-valued logic, with real numbers between 0 and 1 as truth values. |
|
A t-norm logic with the nilpotent minimum norm as the implication operator. |
|
A t-norm logic with the nilpotent minimum norm as the implication operator and rational truth values only. |
|
Ternary Post logic, with a cyclic implementation of the negation operator. |
|
The R-mingle 3 logic, whose significance lies in its material implication implementation. The axiom of weakening does not hold. |
|
Smetanov logic, also known as the logic of here and there and Gödel G3 logic. Introduced by Arend Heyting in 1930 to study intuitionistic logic, it is a three-valued intermediate logic where the intermediate value can be understood as 'not false'. |
|
An implementation of a single-valued logic. May be useful as a base case in various recursive operations. |
|
Product logic, with truth values between 0 and 1. For precision, please pass in a string (e.g. '3.14159' instead of 3.14159) to the constructor; however, passing an int, float or decimal.Decimal instance is also acceptable. |
|
Product logic, with rational numbers between 0 and 1 as truth values. Pass in what Fraction takes to the constructor. |
Functions¶
|
Convert a logic member |
Version of |
|
|
Version of |
|
Returns a Gödel logic class with name |
|
Return whether |
Return whether |
|
|
Return whether |
|
Return whether |
A decorator factory whose products return t-norm logic classes given the strong conjunction operator, given whether the members should be constrained to rational numbers. |
|
|
Returns a Post logic class with name |
Version of |
|
|
Version of |
|
A decorator factory whose products return t-norm logic classes given the strong conjunction operator, given whether the members should be constrained to rational numbers. |
Returns a Łukasiewicz logic class with name |
Package Contents¶
- class mvlogics.B4[source]¶
Bases:
protocols.StrictLogicBase[int]Belnap’s logic B_4, a combination of K_3 and P_3, such that the overdetermined I is called B for ‘both’, and the underdetermined N for ‘neither’ The truth tables are derived accordingly.
- B: ClassVar[Self]¶
- F: ClassVar[Self]¶
- N: ClassVar[Self]¶
- T: ClassVar[Self]¶
- class mvlogics.BI3[source]¶
Bases:
protocols.StrictLogicBase[int]Dmitry Bochvar’s internal three-value logic, also known as Kleene’s weak three-value logic. The indeterminate truth value is contagious in the sense that it propagates as the result of any operation that involves it.
- F: ClassVar[Self]¶
- I: ClassVar[Self]¶
- T: ClassVar[Self]¶
- class mvlogics.Boolean[source]¶
Bases:
protocols.LogicBase[bool]Boolean or Aristotelian logic, where the law of the excluded middle holds. Simply wraps the built-in class
boolto satisfy the interface.- box() Self¶
- diamond() Self¶
- F: ClassVar[Self]¶
- T: ClassVar[Self]¶
- class mvlogics.G3¶
Bases:
protocols.GödelLogicAlias to
SmT. A three-valued logic of Gödel’s, also known as Smetanov logic and the logic of here and there. Belongs to a larger family of ‘Gödel’ logics G_k with truth values 0, 1/(k-1), 2/(k-1), …, (k-2)/(k-1), 1, with 1 designated as a ‘true’ truth value.- F: ClassVar[Self]¶
- NF: ClassVar[Self]¶
- T: ClassVar[Self]¶
- class mvlogics.G_aleph_0¶
Bases:
protocols.RationalLogicBaseGödel’s infinite-valued logic, with rational numbers between 0 and 1 as truth values.
- class mvlogics.G_inf¶
Bases:
protocols.DecimalLogicBaseGödel’s infinite-valued logic, with real numbers between 0 and 1 as truth values.
- class mvlogics.K3¶
Bases:
protocols.StrictLogicBase[int]Kleene’s strong logic of indeterminancy K_3, in which besides the truth values T and F, a new ‘indeterminate’ truth value I is introduced. T is the only designated truth value.
- __and__(other: Self, /) Self¶
- __invert__() Self¶
- __or__(other: Self, /) Self¶
- consensus(other: Self, /) Self¶
- gullibility(other: Self, /) Self¶
- F: ClassVar[Self]¶
- I: ClassVar[Self]¶
- T: ClassVar[Self]¶
- class mvlogics.L3¶
Bases:
protocols.ŁukasiewiczLogicJan Łukasiewicz’s three-valued logic; the truth values for 0, 1/2, 1 are called F, U and T respectively.
- F: ClassVar[Self]¶
- T: ClassVar[Self]¶
- U: ClassVar[Self]¶
- class mvlogics.LP¶
Bases:
protocols.StrictLogicBase[int]Priest’s ‘logic of paradox’ (P_3), provisionally named LP because P_3 refers to ternary Post logic here. The truth tables are equivalent to those of Kleene’s, except I is also designated as a truth value. The gullibility operation is thus not as well-defined as in K_3, and in the case that one operand is T and the other F, the arbitrary convention to return F is chosen.
- __and__(other: Self, /) Self¶
- __invert__() Self¶
- __or__(other: Self, /) Self¶
- consensus(other: Self, /) Self¶
- gullibility(other: Self, /) Self¶
- F: ClassVar[Self]¶
- I: ClassVar[Self]¶
- T: ClassVar[Self]¶
- class mvlogics.L_aleph_0¶
Bases:
protocols.RationalLogicBaseŁukasiewicz’s infinite-valued logic, with rational numbers between 0 and 1 as truth values.
- box() Self¶
- diamond() Self¶
- doubtful() Self¶
- strong_conjunction(other: Self, /) Self¶
- strong_disjunction(other: Self, /) Self¶
- class mvlogics.L_inf¶
Bases:
protocols.DecimalLogicBaseŁukasiewicz’s infinite-valued logic, with real numbers between 0 and 1 as truth values.
- box() Self¶
- diamond() Self¶
- doubtful() Self¶
- strong_conjunction(other: Self, /) Self¶
- strong_disjunction(other: Self, /) Self¶
- class mvlogics.NP¶
Bases:
protocols.TNormLogicA t-norm logic with the nilpotent minimum norm as the implication operator.
- class mvlogics.NP_aleph_0¶
Bases:
protocols.RationalTNormLogicA t-norm logic with the nilpotent minimum norm as the implication operator and rational truth values only.
- class mvlogics.P3¶
Bases:
protocols.PostLogicTernary Post logic, with a cyclic implementation of the negation operator.
- F: ClassVar[Self]¶
- T: ClassVar[Self]¶
- U: ClassVar[Self]¶
- class mvlogics.RM3[source]¶
Bases:
protocols.LogicBase[int]The R-mingle 3 logic, whose significance lies in its material implication implementation. The axiom of weakening does not hold.
- B: ClassVar[Self]¶
- F: ClassVar[Self]¶
- T: ClassVar[Self]¶
- class mvlogics.SmT¶
Bases:
protocols.GödelLogicSmetanov logic, also known as the logic of here and there and Gödel G3 logic. Introduced by Arend Heyting in 1930 to study intuitionistic logic, it is a three-valued intermediate logic where the intermediate value can be understood as ‘not false’.
- F: ClassVar[Self]¶
- NF: ClassVar[Self]¶
- T: ClassVar[Self]¶
- class mvlogics.Unit[source]¶
Bases:
protocols.MemberlessLogicBase[int]An implementation of a single-valued logic. May be useful as a base case in various recursive operations.
- __and__(other: Self, /) Self¶
- __invert__() Self¶
- __or__(other: Self, /) Self¶
- box() Self¶
- consensus(other: Self, /) Self¶
- diamond() Self¶
- gullibility(other: Self, /) Self¶
- T: ClassVar[Self]¶
- class mvlogics.Π¶
Bases:
protocols.DecimalLogicBaseProduct logic, with truth values between 0 and 1. For precision, please pass in a string (e.g. ‘3.14159’ instead of 3.14159) to the constructor; however, passing an int, float or decimal.Decimal instance is also acceptable.
- class mvlogics.Π_aleph_0¶
Bases:
protocols.RationalLogicBaseProduct logic, with rational numbers between 0 and 1 as truth values. Pass in what Fraction takes to the constructor.
- mvlogics.convert[L: protocols.MemberlessLogicBase[Any]](member: protocols.MemberlessLogicBase[Any], cls: type[L]) L[source]¶
Convert a logic member
memberto a member of another logic classcls.
- mvlogics.decimal_logic_from_implication(impliesf: _collections_abc.Callable[[decimal.Decimal, decimal.Decimal], decimal.Decimal]) type[protocols.DecimalLogicBase]¶
Version of
logic_from_implicationspecific to decimals.
- mvlogics.decimal_t_norm_logic(strong_conjunctionf: _collections_abc.Callable[[decimal.Decimal, decimal.Decimal], decimal.Decimal]) type[protocols.TNormLogic]¶
Version of
t_norm_logicspecific to decimals.
- mvlogics.gödel_logic(name_1: str, name_2: str, /, *names: str, clsname: str | None = ...) type[protocols.GödelLogic][source]¶
- mvlogics.gödel_logic(*, k: int, prefix: str = ..., clsname: str | None = ...) type[protocols.GödelLogic]
Returns a Gödel logic class with name
clsnameand truth values of namesname_1(0),name_2(1/(k-1)), …,name_(k-1)((k-2)/(k-1)),name_k(1).
- mvlogics.is_builtin_logic(typ: type) TypeGuard[type[protocols.LogicBase[Any] | Unit]][source]¶
Return whether
typis a built-in logic class.
- mvlogics.is_builtin_logic_member(obj: object) TypeGuard[protocols.LogicBase[Any] | Unit][source]¶
Return whether
objis a member of a built-in logic class.
- mvlogics.is_logic(typ: type) TypeGuard[type[protocols.MemberlessLogicBase[Any]]][source]¶
Return whether
typis a logic class.
- mvlogics.is_logic_member(obj: object) TypeGuard[protocols.MemberlessLogicBase[Any]][source]¶
Return whether
objis a logic member.
- mvlogics.logic_from_implication(*, name: str, rational: Literal[False] = ..., **additional: Any) _collections_abc.Callable[[_collections_abc.Callable[[decimal.Decimal, decimal.Decimal], decimal.Decimal]], type[protocols.DecimalLogicBase]][source]¶
- mvlogics.logic_from_implication(*, name: str, rational: Literal[True], **additional: Any) _collections_abc.Callable[[_collections_abc.Callable[[fractions.Fraction, fractions.Fraction], fractions.Fraction]], type[protocols.RationalLogicBase]]
- mvlogics.logic_from_implication(*, rational: Literal[False] = ..., **additional: Any) _collections_abc.Callable[[_collections_abc.Callable[[decimal.Decimal, decimal.Decimal], decimal.Decimal]], type[protocols.DecimalLogicBase]]
- mvlogics.logic_from_implication(*, rational: Literal[True], **additional: Any) _collections_abc.Callable[[_collections_abc.Callable[[fractions.Fraction, fractions.Fraction], fractions.Fraction]], type[protocols.RationalLogicBase]]
A decorator factory whose products return t-norm logic classes given the strong conjunction operator, given whether the members should be constrained to rational numbers.
- mvlogics.post_logic(name_1: str, name_2: str, /, *names: str, clsname: str | None = ...) type[protocols.PostLogic][source]¶
- mvlogics.post_logic(*, k: int, prefix: str = ..., clsname: str | None = ...) type[protocols.PostLogic]
Returns a Post logic class with name
clsnameand truth values of namesname_1(0),name_2(1/(k-1)), …,name_(k-1)((k-2)/(k-1)),name_k(1).
- mvlogics.rational_logic_from_implication(impliesf: _collections_abc.Callable[[fractions.Fraction, fractions.Fraction], fractions.Fraction]) type[protocols.RationalLogicBase]¶
Version of
logic_from_implicationspecific to fractions.
- mvlogics.rational_t_norm_logic(strong_conjunctionf: _collections_abc.Callable[[fractions.Fraction, fractions.Fraction], fractions.Fraction]) type[protocols.RationalTNormLogic]¶
Version of
t_norm_logicspecific to fractions.
- mvlogics.t_norm_logic(*, name: str, rational: Literal[False] = ..., **additional: Any) _collections_abc.Callable[[_collections_abc.Callable[[decimal.Decimal, decimal.Decimal], decimal.Decimal]], type[protocols.TNormLogic]][source]¶
- mvlogics.t_norm_logic(*, name: str, rational: Literal[True], **additional: Any) _collections_abc.Callable[[_collections_abc.Callable[[fractions.Fraction, fractions.Fraction], fractions.Fraction]], type[protocols.RationalTNormLogic]]
- mvlogics.t_norm_logic(*, rational: Literal[False] = ..., **additional: Any) _collections_abc.Callable[[_collections_abc.Callable[[decimal.Decimal, decimal.Decimal], decimal.Decimal]], type[protocols.TNormLogic]]
- mvlogics.t_norm_logic(*, rational: Literal[True], **additional: Any) _collections_abc.Callable[[_collections_abc.Callable[[fractions.Fraction, fractions.Fraction], fractions.Fraction]], type[protocols.RationalTNormLogic]]
A decorator factory whose products return t-norm logic classes given the strong conjunction operator, given whether the members should be constrained to rational numbers.
- mvlogics.łukasiewicz_logic(name_1: str, name_2: str, /, *names: str, clsname: str | None = ...) type[protocols.ŁukasiewiczLogic][source]¶
- mvlogics.łukasiewicz_logic(*, k: int, prefix: str = ..., clsname: str | None = ...) type[protocols.ŁukasiewiczLogic]
Returns a Łukasiewicz logic class with name
clsnameand truth values of namesname_1(0),name_2(1/(k-1)), …,name_(k-1)((k-2)/(k-1)),name_k(1).
- mvlogics.ALL_LOGICS: frozenset[str]¶
The names of all built-in logics defined in this module.
- mvlogics.ALL_LOGICS_TUPLE: tuple[str, Ellipsis]¶
ALL_LOGICSas a tuple with a canonical ordering.
- mvlogics.ALL_METHODS: frozenset[str]¶
Equivalent to
RECOMMEDED_METHODS | REQUIRED_ATTRS | MIXIN_METHODS | EXTENSION_METHODS.
- mvlogics.EXTENSION_METHODS: frozenset[str]¶
The method names logic classes may have for specialized use cases, including possibly niche fuzzy and modal logic operators.
- mvlogics.FAKE_PROTOCOLS: frozenset[str]¶
The names of the ‘protocols’ defined in the
protocolssubmodule, which support instance and subclass testing.
- mvlogics.FAKE_PROTOCOLS_TUPLE: tuple[str, Ellipsis]¶
FAKE_PROTOCOLSas a tuple with a canonical ordering.
- mvlogics.FORBIDDEN: frozenset[str]¶
Method/property names logic classes are forbidden from implementing.
- mvlogics.MIXIN_METHODS: frozenset[str]¶
The method names of methods that will be provided automatically to logic base classes.
- mvlogics.RECOMMENDED_METHODS: frozenset[str]¶
The method names logic classes are recommended to have if suitable, corresponding to less common logical operations.
- mvlogics.REQUIRED_ATTRS: frozenset[str]¶
The method names all logic classes must have.