Zhegalkin matrix: Difference between revisions

From testwiki
Jump to navigation Jump to search
imported>Watchduck
 
(No difference)

Latest revision as of 00:12, 25 January 2025

Template:Boolf header Template:Zhegalkin stuff The Zhegalkin matrix is an infinite binary matrix.

It is closely related to the infinite integer matrix of Gray code permutation powers (Template:Oeis) and to the algebraic normal form (ANF) of Boolean functions.
(Template:W was the inventor of the ANF. The naming choices made here are new.)

Its colums are the truth tables of all Boolean functions. The column index is the Zhegalkin index of the respective Boolean function.

Its rows are a subset of the Walsh functions, namely the Template:Ws of atoms forming a Template:W (Template:Oeis).

Error creating thumbnail:
The columns of the 8×256 Zhegalkin matrix are the truth tables of the 256 3-ary Boolean functions.
The 8×256 matrix above are the colum indices in little-Template:W binary. On the left are the Sierpiński triangle and the row indices.

Template:Clear Template:Collapsible START This is a 256×256 binary Template:W. Each row is the Template:W XOR of the atoms shown in the 256×8 matrix on the left. File:Walsh Zhegalkin 256.svg Template:Collapsible END


Zhegalkin permutation

sizes of finite Zhegalkin matrices
n 0 1 2 3 4
2n×22n 1×2 2×4 4×16 8×256 16×65536

For arity n the map from ANFs to truth tables gives a finite Zhegalkin matrix of size 2n×22n. (It is the top left corner of the infinite matrix.)

It can be interpreted as a permutation of the integers 0...22n1, which shall be called Zhegalkin permutation Πn.
Keys and values in Πn shall be called Zhegalkin twins — e.g. 7 and 9 are Zhegalkin twins for arity 2.

It is a self-inverse Walsh permutation of degree 2n. The corresponding element of Template:W(2n, 2) is the Template:W Sierpiński triangle.
Π2 is a Walsh permutation of degree 4, and permutes the integers 0 ... 15. The corresponding element of GL(4, 2) is the 4×4 lower Sierpiński triangle.

Template:Zhegalkin matrix/Triangle Pi

In a finite Zhegalkin matrix, the columns with even/odd weight are in the left/right half.   (A truth table has a Zhegalkin twin with odd weight, iff its last digit is true.)
Boolean functions whose Zhegalkin index has even/odd weight shall be called Template:W/Template:W, which shall be called its depravity.

Template:Collapsible START

These integers encode the columns of a bottom left Sierpiński triangle in a square matrix.
These are vectors of Walsh permutations, so T(n,k)=Πn(2k).

0         1
1         3,     2
2        15,    10,    12,     8
3       255,   170,   204,   136,   240,   160,   192,   128
4     65535, 43690, 52428, 34952, 61680, 41120, 49344, 32896, 65280, 43520, 52224, 34816, 61440, 40960, 49152, 32768

Template:Collapsible START

The function arity_and_atom_to_integer creates entries of Template:Oeislink.

def arity_and_atom_to_integer(arity, atom):
    result = 0
    max_place = (1 << arity) - (1 << atom) - 1
    for exponent in range(max_place + 1):
        if not bool(~max_place & max_place - exponent):
            place_value = 1 << exponent
            result += place_value
    return result


def arity_to_vector_of_zhegalkin_permutation(arity):

    degree = 2 ** arity
    atom_integers = [arity_and_atom_to_integer(arity, atom) for atom in range(arity)]

    vector = []

    for i in range(degree):
        entry = 2 ** degree - 1
        for key, val in enumerate(f'{i:b}'):
            if val == '1':
                entry &= atom_integers[key]
        vector.append(entry)

    return vector


assert [arity_to_vector_of_zhegalkin_permutation(3) == [255, 170, 204, 136, 240, 160, 192, 128]]

Template:Collapsible END Template:Collapsible END

fixed points

number of fixed points
n 1 2 3 4 5
22n1 2 4 16 256 65536

The fixed points of Zhegalkin permutations correspond to noble Boolean functions.

Template:Zhegalkin matrix/Triangle Phi

Template:Collapsible START File:Zhegalkin 256; fixed.svg Template:Collapsible END

Python code

Template:Collapsible START

from sympy import binomial


def sierpinski(n):
    return int(sum([(binomial(n, i) % 2) * 2 ** i for i in range(n + 1)]))

def zhegalkin_perm(n, k):
    row_length = 1 << (1 << n)  # 2 ** 2 ** n
    assert k < row_length
    string_length = 1 << n  # 2 ** n
    k_binary = "{0:b}".format(k).zfill(string_length)
    reflected_result = 0
    for i, binary_digit in enumerate(k_binary):
        if binary_digit == '1':
            s = sierpinski(i)
            reflected_result ^= s
    reflected_result_binary = "{0:b}".format(reflected_result).zfill(string_length)
    result_binary = reflected_result_binary[::-1]
    return int(result_binary, 2)

def zhegalkin_fixed(n, k):
    if n == 0:
        assert k < 2
        return k
    else:
        row_length = 1 << (1 << (n-1))  # 2 ** 2 ** (n-1)
        assert k < row_length
    p = zhegalkin_perm(n-1, k)
    p_xor_k = p ^ k
    shifted_k = row_length * k
    return p_xor_k + shifted_k

Template:Collapsible END

Template:Algebraic normal form/python