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

ALL_LOGICS

The names of all built-in logics defined in this module.

ALL_LOGICS_TUPLE

ALL_LOGICS as a tuple with a canonical ordering.

ALL_METHODS

Equivalent to RECOMMEDED_METHODS | REQUIRED_ATTRS | MIXIN_METHODS | EXTENSION_METHODS.

EXTENSION_METHODS

The method names logic classes may have for specialized use cases, including possibly niche fuzzy and modal logic operators.

FAKE_PROTOCOLS

The names of the 'protocols' defined in the protocols submodule, which support instance and subclass testing.

FAKE_PROTOCOLS_TUPLE

FAKE_PROTOCOLS as a tuple with a canonical ordering.

FORBIDDEN

Method/property names logic classes are forbidden from implementing.

MIXIN_METHODS

The method names of methods that will be provided automatically to logic base classes.

RECOMMENDED_METHODS

The method names logic classes are recommended to have if suitable, corresponding to less common logical operations.

REQUIRED_ATTRS

The method names all logic classes must have.

Classes

B4

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.

BI3

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

Boolean or Aristotelian logic, where the law of the excluded middle holds.

G3

Alias 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.

G_aleph_0

Gödel's infinite-valued logic, with rational numbers between 0 and 1 as truth values.

G_inf

Gödel's infinite-valued logic, with real numbers between 0 and 1 as truth values.

K3

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.

L3

Jan Łukasiewicz's three-valued logic; the truth values for 0, 1/2, 1 are called F, U and T respectively.

LP

Priest's 'logic of paradox' (P_3), provisionally named LP because P_3 refers to ternary Post logic here.

L_aleph_0

Łukasiewicz's infinite-valued logic, with rational numbers between 0 and 1 as truth values.

L_inf

Łukasiewicz's infinite-valued logic, with real numbers between 0 and 1 as truth values.

NP

A t-norm logic with the nilpotent minimum norm as the implication operator.

NP_aleph_0

A t-norm logic with the nilpotent minimum norm as the implication operator and rational truth values only.

P3

Ternary Post logic, with a cyclic implementation of the negation operator.

RM3

The R-mingle 3 logic, whose significance lies in its material implication implementation. The axiom of weakening does not hold.

SmT

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'.

Unit

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.

Π_aleph_0

Product logic, with rational numbers between 0 and 1 as truth values. Pass in what Fraction takes to the constructor.

Functions

convert(→ L)

Convert a logic member member to a member of another logic class cls.

decimal_logic_from_implication(...)

Version of logic_from_implication specific to decimals.

decimal_t_norm_logic(→ type[protocols.TNormLogic])

Version of t_norm_logic specific to decimals.

gödel_logic(…)

Returns a Gödel logic class with name clsname and truth values of names name_1 (0), name_2 (1/(k-1)), ..., name_(k-1) ((k-2)/(k-1)), name_k (1).

is_builtin_logic(...)

Return whether typ is a built-in logic class.

is_builtin_logic_member(...)

Return whether obj is a member of a built-in logic class.

is_logic(...)

Return whether typ is a logic class.

is_logic_member(...)

Return whether obj is a logic member.

logic_from_implication(…)

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.

post_logic(…)

Returns a Post logic class with name clsname and truth values of names name_1 (0), name_2 (1/(k-1)), ..., name_(k-1) ((k-2)/(k-1)), name_k (1).

rational_logic_from_implication(...)

Version of logic_from_implication specific to fractions.

rational_t_norm_logic(→ type[protocols.RationalTNormLogic])

Version of t_norm_logic specific to fractions.

t_norm_logic(…)

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.

łukasiewicz_logic(…)

Returns a Łukasiewicz logic class with name clsname and truth values of names name_1 (0), name_2 (1/(k-1)), ..., name_(k-1) ((k-2)/(k-1)), name_k (1).

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.

__and__(other: Self, /) Self[source]
__invert__() Self[source]
__or__(other: Self, /) Self[source]
consensus(other: Self, /) Self[source]
gullibility(other: Self, /) Self[source]
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.

__and__(other: Self, /) Self[source]
__invert__() Self[source]
__or__(other: Self, /) Self[source]
consensus(other: Self, /) Self[source]
gullibility(other: Self, /) Self[source]
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 bool to satisfy the interface.

__and__(other: Self, /) Self[source]
__invert__() Self[source]
__or__(other: Self, /) Self[source]
box() Self
diamond() Self
F: ClassVar[Self]
T: ClassVar[Self]
class mvlogics.G3

Bases: protocols.GödelLogic

Alias 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.RationalLogicBase

Gödel’s infinite-valued logic, with rational numbers between 0 and 1 as truth values.

class mvlogics.G_inf

Bases: protocols.DecimalLogicBase

Gö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.ŁukasiewiczLogic

Jan Ł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.TNormLogic

A t-norm logic with the nilpotent minimum norm as the implication operator.

class mvlogics.NP_aleph_0

Bases: protocols.RationalTNormLogic

A t-norm logic with the nilpotent minimum norm as the implication operator and rational truth values only.

class mvlogics.P3

Bases: protocols.PostLogic

Ternary 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.

__and__(other: Self, /) Self[source]
__invert__() Self[source]
__or__(other: Self, /) Self[source]
B: ClassVar[Self]
F: ClassVar[Self]
T: ClassVar[Self]
class mvlogics.SmT

Bases: protocols.GödelLogic

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’.

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
__bool__() NoReturn[source]
__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.DecimalLogicBase

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.

class mvlogics.Π_aleph_0

Bases: protocols.RationalLogicBase

Product 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 member to a member of another logic class cls.

mvlogics.decimal_logic_from_implication(impliesf: _collections_abc.Callable[[decimal.Decimal, decimal.Decimal], decimal.Decimal]) type[protocols.DecimalLogicBase]

Version of logic_from_implication specific 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_logic specific 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 clsname and truth values of names name_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 typ is a built-in logic class.

mvlogics.is_builtin_logic_member(obj: object) TypeGuard[protocols.LogicBase[Any] | Unit][source]

Return whether obj is a member of a built-in logic class.

mvlogics.is_logic(typ: type) TypeGuard[type[protocols.MemberlessLogicBase[Any]]][source]

Return whether typ is a logic class.

mvlogics.is_logic_member(obj: object) TypeGuard[protocols.MemberlessLogicBase[Any]][source]

Return whether obj is 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 clsname and truth values of names name_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_implication specific 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_logic specific 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 clsname and truth values of names name_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_LOGICS as 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 protocols submodule, which support instance and subclass testing.

mvlogics.FAKE_PROTOCOLS_TUPLE: tuple[str, Ellipsis]

FAKE_PROTOCOLS as 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.