Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is monoid homomorphism exactly?

I've read about monoid homomorphism from Monoid Morphisms, Products, and Coproducts and could not understand 100%.

The author says (emphasis original):

The length function maps from String to Int while preserving the monoid structure. Such a function, that maps from one monoid to another in such a preserving way, is called a monoid homomorphism. In general, for monoids M and N, a homomorphism f: M => N, and all values x:M, y:M, the following equations hold:

f(x |+| y) == (f(x) |+| f(y))  f(mzero[M]) == mzero[N] 

Does he mean that, since the datatypes String and Int are monoids, and the function length maps String => Int preserving the monoid structure (Int is a monoid), it is called monoid homomorphism, right?

like image 657
softshipper Avatar asked May 05 '19 14:05

softshipper


People also ask

What is monoid homomorphism explain with example?

Here are some examples of a monoid: set of integers with operation = addition and identity = zero. set of integers with operation = multiplication and identity = one. set of lists with operation = appending and identity = empty list. set of strings with operation = concatenation and identity = empty string.

What are the types of homomorphism?

There are two main types: group homomorphisms and ring homomorphisms. (Other examples include vector space homomorphisms, which are generally called linear maps, as well as homomorphisms of modules and homomorphisms of algebras.)

What is a monoid explain?

A monoid is a set that is closed under an associative binary operation and has an identity element such that for all , . Note that unlike a group, its elements need not have inverses. It can also be thought of as a semigroup with an identity element. A monoid must contain at least one element.

What is monoid and explain with the help of an example?

In abstract algebra, a branch of mathematics, a monoid is a set equipped with an associative binary operation and an identity element. For example, the nonnegative integers with addition form a monoid, the identity element being 0.


2 Answers

Does he mean, the datatype String and Int are monoid.

No, neither String nor Int are monoids. A monoid is a 3-tuple (S, ⊕, e) where ⊕ is a binary operator ⊕ : S×S → S, such that for all elements a, b, c∈S it holds that (a⊕b)⊕c=a⊕(b⊕c), and e∈S is an "identity element" such that a⊕e=e⊕a=a. String and Int are types, so basically sets of values, but not 3-tuples.

The article says:

Let's take the String concatenation and Int addition as example monoids that have a relationship.

So the author clearly also mentions the binary operators ((++) in case of String, and (+) in case of Int). The identities (empty string in case of String and 0 in case of Int) are left implicit; leaving the identities as an exercise for the reader is common in informal English discourse.

Now given that we have two monoid structures (M, ⊕, em) and (N, ⊗, en), a function f : M → N (like length) is then called a monoid homomorphism [wiki] given it holds that f(m1⊕m2)=f(m1)⊗f(m2) for all elements m1, m2∈M and that mapping also preserves the identity element: f(em)=en.

For example length :: String -> Int is a monoid homomorphism, since we can consider the monoids (String, (++), "") and (Int, (+), 0). It holds that:

  1. length (s1 ++ s2) == length s1 + length s2 (for all Strings s1 and s2); and
  2. length "" == 0.
like image 187
Willem Van Onsem Avatar answered Oct 20 '22 11:10

Willem Van Onsem


Datatype cannot be a monoid on its own. For a monoid, you need a data type T and two more things:

  • an associative binary operation, let's call it |+|, that takes two elements of type T and produces an element of type T
  • an identity element of type T, let's call it i, such that for every element t of type T the following holds: t |+| i = i |+| t = t

Here are some examples of a monoid:

  • set of integers with operation = addition and identity = zero
  • set of integers with operation = multiplication and identity = one
  • set of lists with operation = appending and identity = empty list
  • set of strings with operation = concatenation and identity = empty string

Monoid homomorphism

String concatenation monoid can be transformed into integer addition monoid by applying .length to all its elements. Both those sets form a monoid. By the way, remember that we can't just say "set of integers forms a monoid"; we have to pick an associative operation and a corresponding identity element. If we take e.g. division as operation, we break the first rule (instead of producing an element of type integer, we might produce an element of type float/double).

Method length allows us to go from a monoid (string concatenation) to another monoid (integer addition). If such operation also preserves monoid structure, it is considered to be a monoid homomorphism.

Preserving the structure means:

length(t1 |+| t2) = length(t1) |+| length(t2)  and  length(i) = i' 

where t1 and t2 represent elements of the "source" monoid, i is the identity of the "source" monoid, and i' is the identity of the "destination" monoid. You can try it out yourself and see that length indeed is a structure-preserving operation on a string concatenation monoid, while e.g. indexOf("a") isn't.

Monoid isomorphism

As demonstrated, length maps all strings to their corresponding integers and forms a monoid with addition as operation and zero as identity. But we can't go back - for every string, we can figure out its length, but given a length we can't reconstruct the "original" string. If we could, then the operation of "going forward" combined with the operation of "going back" would form a monoid isomorphism.

Isomorphism means being able to go back and forth without any loss of information. For example, as stated earlier, list forms a monoid under appending as operation and empty list as identity element. We could go from "list under appending" monoid to "vector under appending" monoid and back without any loss of information, which means that operations .toVector and .toList together form an isomorphism. Another example of an isomorphism, which Runar mentioned in his text, is StringList[Char].

like image 37
slouc Avatar answered Oct 20 '22 12:10

slouc