Intro to zk Algebra

Intro to zk Algebra

An opinionated basic algebra walkthrough for a zero knowledge beginner

Zero knowledge proofs (zk) , The new kid in town in terms of buzz words and blockchain technologies , this whole buzz word uses some fancy mathematical concepts and principles to prove a statement without revealing any knowledge about the statement ; hence the term zero knowledge .

Any beginner who has tried to delve into this topic would find out why algebra was compulsory in high school (lol) , the topic contains and needs a whole lot of mathematical and algebraic background to grasp correctly its stipulates n . For many , these becomes very hectic and cumbersome very quick .

The major reason for this article (and others to come) is to break this concepts down to the most understandable parts for users consumption , ,it also serves as a public documentation of my roadmap into building zero knowledge systems (yes , i am also somewhat of a beginner).

WIthout further ado, lets dive straight into some topics for beginner algebra needed in zero knowledge developments.

Set theory

This is basically the foundation of linear and abstract algebra , it is also a crucial part of zero knowledge proofs .

Set theory contains a whole lot of theoretical parts which i wont be going into as they arent needed in our goal.

Definition of a set

A set is a well-defined collection of objects. Where the actual power comes from is that these could be anything (virtually anything ) and the rules we learn from set theory apply to them.

What integers, rational numbers, real numbers, complex numbers, matrices, polynomials, polygons, and many other things have in common is that they are all sets.

There can also be a collection that contains nothing , this is called a null/ empty set.

A notable characteristics of sets is the absence of order in the set structure i.e

set A ={1,2,3} and set B = {3,1,2} are equal even though each element isnt in the same position in each set .

Sets are also characterized by its cardinality i.e its size which is the no of elements in the set , from above set A and set B have the same cardinality of 3 represented by /A/ = 3 , /B/=3.
Sets do not contain duplicate items by definition, {a, a, b} is really {a, b}.

Superset and subsets

When we look at numbers, there seems to be a relationship between them. Specifically, all integers are rational (expressed as fraction of two integers) numbers, but not all rational numbers are integers. The relationship between them is that integers are a subset of rational numbers. On the flip side, rational numbers are a superset of integers.

A subset need not be strictly smaller than the set it is a part of. A set is a subset of it self and an empty set is a subset of every set.

The precise definition for the relationship between integers and rational numbers is a proper subset, that is, there exist rational numbers that are not integers.

Ordered pairs

Although sets do not respect order, a different type of algebraic structure can emerge from sets called the ordered pair. For example, (d, b) is an ordered pair while {d, b} is a set.

We programmers typically think of this as a tuple. We say two ordered pairs are equal in the same sense we say two tuples are equal.

Cartesian product

Because sets are well defined therefore we can define a set such that every element from one set is one part of an ordered pair with an element from another set. For example, if A = {1,2,3} and B = {x, y, z} A × B = {(1, x), (1, y), (1, z), (2, x), …, (3, z)} or done as a table:

cartesian product of {1,2,3} and {x,y,z}

The result of a cartesian product is still a set: a set of ordered pairs.

Binary operator

A binary operator is a function from A × A → A. Basically, we take every possible pair from A (the cartesian product of A with itself) and map it to A.

in simpler words we take the cartesian product of a set with itself then map the result to the original set .

Magma, Semigroups, and Monoids, and Groups

Magma

A magma is a set with a closed binary operator.

A magma is a term for a set with a binary operator that maps two element in the set to a result that exists in the set.

A clear example is a set A = {0} under the binary operator addition.

any two element taken from set A above when combined by the operator addition gives a value that exist in the set . i.e 0+0=0

Therefore set A is a Magma .

A simple rust implementation of the magma is shown below:

pub trait  Magma<A : Sized + PartialEq> {
    fn closure(&self, _x: &Self) -> bool {
        true
      }
    fn op(&self, other: &Self, operation : dyn Fn(A,A) -> A) -> Self;
}

Semigroups

Semigroups are magmas with an associative binary operator .

In other words, a semigroup is a set with a binary operator that is closed and associative.

Let our set be the set of all possible non-empty strings from the traditional alphabet a,b,…,y,z. For example, “az”, “programmer”, “zero”, “asdfghjk”, “foo”, and “bar” are all in this set.

Let our binary operator be the concatenation of strings. This is closed, because it produces another string in the set.

Note that if we commute “foo” and “bar”, the output string will not be the same, i.e. “foobar” and “barfoo”. However, that does not matter. Both “foobar” and “barfoo” are members of the set, so the binary operator “concatenate” is closed. Because we have a set with a closed binary operator, the set of all strings under concatenation is a magma.

A simple rust implementation :

pub trait Semigroup<A :PartialEq + Sized> : Magma<A>{
 fn associative() -> bool;
}

Monoid

A monoid is a semigroup with a unique identity element in the set.

For example, addition over integers without zero is a semigroup, but if you include zero, it becomes a monoid.

An identity element means you do a binary operator with the identity element and another element a, you get a. In the example of addition 8 + 0 = 8, where 0 is the identity element. If your binary operator was multiplication, then the identity element would be 1, since multiplying by 1 gives the same number back.

A monoid is also a monad .

pub trait Monad<A: PartialEq+Sized> : Semigroup<A>{
    fn identity(&self) -> A ;
}

Group

A group is a monoid where each element has an inverse in the set .

Using integers with addition, the identity element is zero (because you add zero, you get the same number back), and the inverse of an integer is that integer with the sign flipped (e.g. the inverse of 5 is -5 and the inverse of -7 is 7).

Going back to the domain sensitivity, addition over positive integers is not a group because there can be no inverse elements.

pub trait Group<A: Sized + PartialEq> : Monad<A>{
    fn identity(&self) -> A;
}

Here is an interesting table to drive the point home

table showing how domain affects structure categorization

Note that “inverse” is not meaningful if the set does not have an identity, because the definition of inverse is doing a binary operator of an element with its inverse produces the identity.

That should be all for now , Happy prosperous new year .

See you in the next article.