User:Macrakis/ANF

In Boolean algebra, the algebraic normal form (ANF), ring sum normal form (RSNF or RNF), Zhegalkin normal form, or Reed–Muller form expresses a logical formula as the exclusive or (XOR) of zero or more terms each of which is the logical conjunction (AND) of zero or more variables.

Since the identity for XOR is False, a zero-length formula denotes, and is written as, False. Since the identity for AND is True, an zero-length term denotes, and is written as, True.

In typical computer science notation, an example is:
 * a ⊕ b ⊕ ab ⊕ abc.

In standard propositional logic symbols, that is:
 * $$ a \veebar b \veebar \left(a \wedge b\right) \veebar \left(a \wedge b \wedge c\right) $$

The negation of that is:
 * True ⊕ a ⊕ b ⊕ ab ⊕ abc

Formulas written in ANF are also known as Zhegalkin polynomials (полиномы Жегалкина) and Positive Polarity (or Parity) Reed–Muller expressions (PPRM).

Common uses
ANF is a normal form, which means that two equivalent formulas will convert to the same ANF, easily showing whether two formulas are equivalent for automated theorem proving. Unlike other normal forms, it can be represented as a simple list of lists of variable names. Conjunctive and disjunctive normal forms also require recording whether each variable is negated or not. Negation normal form is unsuitable for that purpose, since it doesn't use equality as its equivalence relation: a &or; ¬a isn't reduced to the same thing as 1, even though they're equal.

Putting a formula into ANF also makes it easy to identify linear functions (used, for example, in linear feedback shift registers): a linear function is one that is a sum of single literals. Properties of nonlinear feedback shift registers can also be deduced from certain properties of the feedback function in ANF.

Performing operations within algebraic normal form
There are straightforward ways to perform the standard boolean operations on ANF inputs in order to get ANF results.

XOR (logical exclusive disjunction) is performed directly:
 * 1 ⊕ 1 ⊕ x ⊕ x ⊕ y
 * y
 * 1 ⊕ 1 ⊕ x ⊕ x ⊕ y
 * y

NOT (logical negation) is XORing 1:
 * 1 ⊕ 1 ⊕ x ⊕ y
 * x ⊕ y
 * 1 ⊕ 1 ⊕ x ⊕ y
 * x ⊕ y

AND (logical conjunction) is distributed algebraically
 * (1 ⊕ x ⊕ y) ⊕ (x ⊕ x ⊕ xy)
 * 1 ⊕ x ⊕ x ⊕ x ⊕ y ⊕ xy
 * 1 ⊕ x ⊕ y ⊕ xy
 * 1 ⊕ x ⊕ x ⊕ x ⊕ y ⊕ xy
 * 1 ⊕ x ⊕ y ⊕ xy

OR (logical disjunction) uses either 1 ⊕ (1 ⊕ a)(1 ⊕ b) (easier when both operands have purely true terms) or a ⊕ b ⊕ ab (easier otherwise):
 * 1 ⊕ (1 ⊕ )(1 ⊕ )
 * 1 ⊕ x(x ⊕ y)
 * 1 ⊕ x ⊕ xy
 * 1 ⊕ x ⊕ xy

Converting to algebraic normal form
Each variable in a formula is already in pure ANF, so you only need to perform the formula's boolean operations as shown above to get the entire formula into ANF. For example:
 * x + (y &middot; ¬z)
 * x + (y(1 ⊕ z))
 * x + (y ⊕ yz)
 * x ⊕ (y ⊕ yz) ⊕ x(y ⊕ yz)
 * x ⊕ y ⊕ xy ⊕ yz ⊕ xyz

Formal representation
ANF is sometimes described in an equivalent way:
 * {| cellpadding="4"


 * $$f(x_1, x_2, \ldots, x_n) = \!$$
 * $$a_0 \oplus \!$$
 * $$a_1x_1 \oplus a_2x_2 \oplus \cdots \oplus a_nx_n \oplus \!$$
 * $$a_{1,2}x_1x_2 \oplus \cdots \oplus a_{n-1,n}x_{n-1}x_n \oplus \!$$
 * $$\cdots \oplus \!$$
 * $$a_{1,2,\ldots,n}x_1x_2\ldots x_n \!$$
 * }
 * where $$a_0, a_1, \ldots, a_{1,2,\ldots,n} \in \{0,1\}^*$$ fully describes $$f$$.
 * $$a_{1,2}x_1x_2 \oplus \cdots \oplus a_{n-1,n}x_{n-1}x_n \oplus \!$$
 * $$\cdots \oplus \!$$
 * $$a_{1,2,\ldots,n}x_1x_2\ldots x_n \!$$
 * }
 * where $$a_0, a_1, \ldots, a_{1,2,\ldots,n} \in \{0,1\}^*$$ fully describes $$f$$.
 * $$a_{1,2,\ldots,n}x_1x_2\ldots x_n \!$$
 * }
 * where $$a_0, a_1, \ldots, a_{1,2,\ldots,n} \in \{0,1\}^*$$ fully describes $$f$$.
 * where $$a_0, a_1, \ldots, a_{1,2,\ldots,n} \in \{0,1\}^*$$ fully describes $$f$$.

Recursively deriving multiargument Boolean functions
There are only four functions with one argument:
 * $$f(x)=0$$
 * $$f(x)=1$$
 * $$f(x)=x$$
 * $$f(x)=1 \oplus x$$

To represent a function with multiple arguments one can use the following equality:
 * $$f(x_1,x_2,\ldots,x_n) = g(x_2,\ldots,x_n) \oplus x_1 h(x_2,\ldots,x_n)$$, where
 * $$g(x_2,\ldots,x_n) = f(0,x_2,\ldots,x_n)$$
 * $$h(x_2,\ldots,x_n) = f(0,x_2,\ldots,x_n) \oplus f(1,x_2,\ldots,x_n)$$

Indeed,
 * if $$x_1=0$$ then $$x_1 h = 0$$ and so $$f(0,\ldots) = f(0,\ldots)$$
 * if $$x_1=1$$ then $$x_1 h = h$$ and so $$f(1,\ldots) = f(0,\ldots) \oplus f(0,\ldots) \oplus f(1,\ldots)$$

Since both $$g$$ and $$h$$ have fewer arguments than $$f$$ it follows that using this process recursively we will finish with functions with one variable. For example, let us construct ANF of $$f(x,y)= x \lor y$$ (logical or):
 * $$f(x,y) = f(0,y) \oplus x(f(0,y) \oplus f(1,y))$$
 * since $$f(0,y)=0 \lor y = y$$ and $$f(1,y)=1 \lor y = 1$$
 * it follows that $$f(x,y) = y \oplus x (y \oplus 1)$$
 * by distribution, we get the final ANF: $$f(x,y) = y \oplus x y \oplus x = x \oplus y \oplus x y$$