maths/boolean

This module contains code to do boolean logic on integers. Boolean logic here is the special case of arithmetic circuit logic with p = 2.

Functions

and_(x: Int, y: Int) -> Int

Performs a logical AND operation on two integer values. Expects both inputs as binary (0 or 1) and returns 1 if both are 1, otherwise returns 0.

boolean.and_(1, 1)

or_(x: Int, y: Int) -> Int

Performs a logical OR operation on two integer values. Expects both inputs as binary (0 or 1) and returns 1 if at least one input is 1, otherwise returns 0.

boolean.or_(0, 1)

not_(x: Int) -> Int

Performs a logical NOT operation on an integer value. Expects the input as binary (0 or 1) and returns the inverse (1 becomes 0, 0 becomes 1).

boolean.not_(1)

xor_(x: Int, y: Int) -> Int

Performs a logical XOR operation on two integer values. Expects both inputs as binary (0 or 1) and returns 1 if the inputs are different, otherwise returns 0.

boolean.xor_(0, 1)

nand_(x: Int, y: Int) -> Int

Performs a logical NAND operation on two integer values. Returns 1 if at least one input is 0, otherwise returns 0.

boolean.nand_(1, 1)

nor_(x: Int, y: Int) -> Int

Performs a logical NOR operation on two integer values. Returns 1 if both inputs are 0, otherwise returns 0.

boolean.nor_(0, 0)

xnor_(x: Int, y: Int) -> Int

Performs a logical XNOR operation on two integer values. Returns 1 if the inputs are the same, otherwise returns 0.

boolean.xnor_(1, 1)

imply_(x: Int, y: Int) -> Int

Performs a logical implication operation on two integer values. Returns 1 if the first input is false or both inputs are true, otherwise returns 0.

boolean.imply_(1, 0)
Search Document