Studies of Boolean functions

This class for Boolean functions (BF) is the biggest part of this software.
It contains some unfinished and experimental features.

This project is related to many pages in Studies of Boolean functions.

There are two main goals, both not yet reached:

from discretehelpers.boolf import Boolf


a = Boolf('0101')
b = Boolf('0011')

assert a == Boolf('01')
assert b == Boolf('01', [1])

assert a & b == Boolf('0001')  # AND
assert a | b == Boolf('0111')  # OR
assert a ^ b == Boolf('0110')  # XOR

assert ~a == Boolf('10')  # NOT
assert ~(a&b) == Boolf('1110')

periodic truth tables edit

Within this project Boolean functions are used without specifying the arity.
Their arity is implicitly infinite, and their truth tables are implicitly periodic.   (But the term truth table is usually used for finite ones.)
They are repeating binary fractions (just like repeating decimals) with values between 0 and 1.   (This may be the only occurence of big-endian binary in this project.)

The truth tables 0001 and 0001 0001 denote the same thing, namely the Boolean function  .
The corresponding fraction is  . (That can be expanded to  , corresponding to the longer truth table.)

The letters from the beginning of the alphabet are not meaningless variable names, but denote specific atoms.

valency ≤ adicity ≤ arity edit

Valency is the number of arguments actually used.
Adicity follows from the biggest atom, and corresponds to the required length of the truth table.
For a dense BF valency and adicity are equal. E.g. Boolf('0001') ( ) has valency and adicity 2.
But Boolf('0000 0011') ( ) has valency 2 and adicity 3.
The term arity is only used for arguments of methods, e.g. to calculate the consul.

boolf = Boolf('0000 0011')
assert boolf == Boolf('0001', [1, 2])

assert boolf.valency == 2
assert boolf.adicity == 3

assert boolf.consul(3) == 1  # arity 3
assert boolf.consul(4) == 0  # arity 4