# logic Module¶

## Module Description¶

Provides common logic operators as functions.

The functions come in two forms: objective and boolean. Objective functions work in a manner similar to the and and or operators, built in to Python, in that return one of the original objects provided as an operand. Boolean functions return boolean values rather than the original objects. The names of objective functions start with o_.

The names of all functions in the module end with f, because some of the names would otherwise conflict with Python keywords. The f can be understood to mean function or functional version as opposed to an inline operator.

None of the functions in this module perform true short-circuit evaluation like the Python and and or operators do. This is because any expressions given as arguments to a function are evaluated before the function is called.

The documentation below and the Examples section provide more details.

## Boolean Functions¶

utilia.functional.logic.andf(*posargs)

If no arguments are supplied, returns True. Else, returns the result of calling the all built-in function on the sequence of arguments.

Below is a truth table for this function with two arguments:

$$p$$ $$q$$ $$p \wedge q$$
False False False
False True False
True False False
True True True
Parameters: posargs (objects of any type) – Arbitrary number of positional arguments. boolean
utilia.functional.logic.nandf(*posargs)

If no arguments are supplied, returns False. Else, returns the negated result of calling the all built-in function on the sequence of arguments.

Below is a truth table for this function with two arguments:

$$p$$ $$q$$ $$p \uparrow q$$
False False True
False True True
True False True
True True False
Parameters: posargs (objects of any type) – Arbitrary number of positional arguments. boolean
utilia.functional.logic.orf(*posargs)

If no arguments are supplied, returns False. Else, returns the result of calling the any built-in function on the sequence of arguments.

Below is a truth table for this function with two arguments:

$$p$$ $$q$$ $$p \vee q$$
False False False
False True True
True False True
True True True
Parameters: posargs (objects of any type) – Arbitrary number of positional arguments. boolean
utilia.functional.logic.norf(*posargs)

If no arguments are supplied, returns True. Else, returns the negated result of calling the any built-in function on the sequence of arguments.

Below is a truth table for this function with two arguments:

$$p$$ $$q$$ $$p \downarrow q$$
False False True
False True False
True False False
True True False
Parameters: posargs (objects of any type) – Arbitrary number of positional arguments. boolean
utilia.functional.logic.xorf(*posargs)

Converts sequence of arguments to booleans. If no arguments are supplied, raises an exception. Else, returns the result of reducing the sequence of arguments with a logical xor function.

Below is a truth table for this function with two arguments:

$$p$$ $$q$$ $$p \veebar q$$
False False False
False True True
True False True
True True False
Parameters: posargs (objects of any type) – Arbitrary number of positional arguments. boolean TypeError, if a required argument is missing.
utilia.functional.logic.xnorf(*posargs)

Converts sequence of arguments to booleans. If no arguments are supplied, raises an exception. Else, returns the result of reducing the sequence of arguments with a logical xnor function.

Below is a truth table for this function with two arguments:

$$p$$ $$q$$ $$p \Leftrightarrow q$$
False False True
False True False
True False False
True True True
Parameters: posargs (objects of any type) – Arbitrary number of positional arguments. boolean TypeError, if a required argument is missing.
utilia.functional.logic.impliesf(*posargs)

Converts sequence of arguments to booleans. If no arguments are supplied, raises an exception. Else, returns the result of reducing the sequence of arguments with a logical implies function.

Below is a truth table for this function with two arguments:

$$p$$ $$q$$ $$p \Rightarrow q$$
False False True
False True True
True False False
True True True
Parameters: posargs (objects of any type) – Arbitrary number of positional arguments. boolean TypeError, if a required argument is missing.
utilia.functional.logic.nimpliesf(*posargs)

Converts sequence of arguments to booleans. If no arguments are supplied, raises an exception. Else, returns the negated result of reducing the sequence of arguments with a logical implies function.

Below is a truth table for this function with two arguments:

$$p$$ $$q$$ $$p \nRightarrow q$$
False False False
False True False
True False True
True True False
Parameters: posargs (objects of any type) – Arbitrary number of positional arguments. boolean TypeError, if a required argument is missing.
utilia.functional.logic.cimpliesf(*posargs)

Converts sequence of arguments to booleans. If no arguments are supplied, raises an exception. Else, returns the result of reducing the sequence of arguments with a logical converse implies function.

Below is a truth table for this function with two arguments:

$$p$$ $$q$$ $$p \Leftarrow q$$
False False True
False True False
True False True
True True True
Parameters: posargs (objects of any type) – Arbitrary number of positional arguments. boolean TypeError, if a required argument is missing.
utilia.functional.logic.cnimpliesf(*posargs)

Converts sequence of arguments to booleans. If no arguments are supplied, raises an exception. Else, returns the negated result of reducing the sequence of arguments with a logical converse implies function.

Below is a truth table for this function with two arguments:

$$p$$ $$q$$ $$p \nLeftarrow q$$
False False False
False True True
True False False
True True False
Parameters: posargs (objects of any type) – Arbitrary number of positional arguments. boolean TypeError, if a required argument is missing.

## Objective Functions¶

utilia.functional.logic.o_andf(*posargs)

If no arguments are supplied, returns True. Else, returns the result of reducing the sequence of arguments with the logical and operator.

Below is a truth-like table for this function with two arguments:

$$p$$ $$q$$ $$p \wedge q$$
zeroish zeroish $$p$$
zeroish non-zeroish $$p$$
non-zeroish zeroish $$q$$
non-zeroish non-zeroish $$q$$
Parameters: posargs (objects of any type) – Arbitrary number of positional arguments. object of any type
utilia.functional.logic.o_orf(*posargs)

If no arguments are supplied, returns False. Else, returns the result of reducing the sequence of arguments with the logical or operator.

Below is a truth-like table for this function with two arguments:

$$p$$ $$q$$ $$p \vee q$$
zeroish zeroish $$q$$
zeroish non-zeroish $$q$$
non-zeroish zeroish $$p$$
non-zeroish non-zeroish $$p$$
Parameters: posargs (objects of any type) – Arbitrary number of positional arguments. object of any type

Todo

Create examples.