Counting binary operators over finite sets - Admitting an identity

Table of Contents

Introduction

So we’ve counted general binary operators and the commutative operators. We’ve also employed a model (tables) to help make sense of our results and hopefully help us with new ones.

Given some binary operator \(f:S\times{S}\rightarrow{S}\), an identity element is some \(e\in{S}\) which, when applied with some other element, just returns that element.

There can exist 2 kinds of identity in the most general case:

  1. Left identity: \(e_1\in{S}:\forall{x\in{S}}:f(e_1,x)=x\)
  2. Right identity: \(e_2\in{S}:\forall{x\in{S}}:f(x,e_2)=x\)

If the element counts as both a left and right identity, call it a complete identity.

In \(S=\mathbb{Z}\) with the operator \(+\), 0 is an identity element: if you add 0 to anything, it doesn’t change the value. There only happens to be one identity (0) and it is both a left and right identity. This is trivial to prove, so we leave it to the reader1.

The problem: count all binary operators that may admit any identity element, whether that be a left or a right or both.

Complete identities as left and right identities

Let the set of all operators with:

  • a left identity be called L
  • a right identity be called R
  • a complete identity be called C

Question: \(C=L\cap{R}\)?

Lemma 1: left and right identities are equivalent

  • Say I have a left identity a and a right identity b on the same operator
  • By definition:
    1. \(\forall{x\in{S}}:f(a,x)=x\)
    2. \(\forall{x\in{S}}:f(x,b)=x\)
  • By specialising 1 (x=b): \(f(a,b)=b\)
  • By specialising 2 (x=a): \(f(a,b)=a\)
  • Since f is a function, f(a,b) is a constant
  • Therefore \(a=b\)

Corollary 2: left and right identity implies a complete identity

By lemma 1, any left and any right identity over the same operator are equivalent. Since they’re equivalent, either identity is both a left and a right one. By definition, therefore, they are a complete identity

Corollary 3: complete identity implies a left identity and a right identity

Obviously, if \(a\in{S}\) is a complete identity we can classify a as a left identity and a right identity.

Multiple identities preclude other identities

So a left and right identity will make a complete identity, and there can only be one complete identity.

What if I had two left identities? Or two right identities? I argue having multiple of one removes the possibility of the other, therefore removing the possibility of a complete identity.

Two left identities preclude a right identity

Arguing by contradiction

  • Say I have two distinct left identities \(a,b\in{S}\) and a right identity \(c\in{S}\)
  • By left identity, \(f(a,c)=f(b,c)=c\)
  • By right identity, \(f(a,c)=a\) and \(f(b,c)=b\)
  • Therefore \(a=b\), but that contradicts the distinctness of a and b

Two right identities preclude a left identity

Basically the exact same as the previous argument, exercise for the reader2.

Multiple of either type of identity preclude complete identities

Derive from needing a left and right identity to make a complete identity, and that having two of one type of identity precludes having any of the other type of identity.

Identities in tables

Now we have some useful tools to pattern match certain situations, let’s use tables to visualise some stuff.

In terms of a table, the left identity is a row that is completely fixed; all values are just the same as the column.

Table 1: 0 as a left identity
0 1 2
0 0 1 2
1 . . .
2 . . .

Similarly, the right identity is a column that is completely fixed; all values are the same as the row.

Table 2: 0 as a right identity
0 1 2
0 0 . .
1 1 . .
2 2 . .

You can see from this that in the case of a complete identity the column and row will be completely fixed.

Table 3: 0 as a complete identity
0 1 2
0 0 1 2
1 1 . .
2 2 . .

Constructor algorithms a.k.a being a chad first

For this post I’m going to make the constructors first, in comparison to post 2 where I make the constructors after counting up.

Constructor for operators with a complete identity

This one is a bit trite, mostly cos the reasoning is so simple. The problem of generating operators with complete identities is the same as generating tables that have a fixed row and column. How should we design an algorithm for this?

The reasoning

Pick some element \(a\in{S}\). Let’s make it the complete identity. In procedural steps, that would mean:

  • \(\forall{x\in{S}}:\) set \(f(x,a)=x\)
  • \(\forall{x\in{S}}:\) set \(f(a,x)=x\)

Note that set has a different meaning now. There will be two ways of picking a value for some symbol now:

  • “fix \(f(x,y)\) from S” which means \(f(x,y)\) is any value from the set S
  • “set \(f(x,y)=C\)” means \(f(x,y)\) has the exact value C

That aside, these procedural steps certainly make a a complete identity. To make expressing this easier, we can specify a numbering on S such that \(1\leftrightarrow{a}\) i.e. the complete identity and 1 are synonymous. This can be done without loss of generality; any numbering you pick that doesn’t have \(1\leftrightarrow{a}\) can just be permuted to this one, and any numbering I give that has \(1\leftrightarrow{a}\) can be permuted to one that you pick.

To complete the algorithm, let’s just fix the rest of the values of the table. Something like \(\forall{x,y\in{S},x,y>1}:\) fix f(x,y) from S. Notice that this is basically the same as \(\forall{x,y\in{S\backslash{\{a\}}}}:\) fix f(x,y) from S, so the numbering isn’t really necessary for the core argument.

I’m not going to prove the formal semantics of this algorithm, those being:

  • All cells are filled by this procedure
  • To construct an operator with some complete identity, all the cells directly set or fixed by this procedure are sufficient and necessary
  • The number of ways this algorithm can setup an operator is, therefore, the same as the number of operators that admit a complete identity

These should be simple enough to prove at a glance, but we’ll leave it as an exercise for the reader.

The algorithm

  1. \(\forall{x\in{S}}:\) set \(f(x,1)=x\)
  2. \(\forall{x\in{S}}:\) set \(f(1,x)=x\)
  3. \(\forall{x,y\in{S},x,y>1}:\) fix f(x,y) from S

Constructor for commutative operators with a complete identity

This will be the first time we’re combining constraints together. The conditions of an operator being commutative and an operator having a complete identity are independent; one doesn’t affect the likelihood of the other.

Therefore we can go from either direction: think about commutative operators then filter for those with a complete identity, or think about operators with a complete identity and filter out for those that are commutative. I’ll go for the former because the space of commutative operators is easy for me to visualise as a table.

We’ve made a simple table condition for a complete element: a row and column that are completely fixed to certain values. If we look at the constructor we made back in part 2, we can just fit the constructor I made earlier into this. This should be really easy to perform analysis on, using the proofs we made in part 2’s constructor.

A little refresher

Here’s the algorithm we used in part 2.

  1. \(\forall{x\in{S}}:\) set \(f(x, x)\)
  2. For x from 1 to |S|
    1. \(\forall{y\in{S}, y>x}:\) set \(f(x, y)\)

It uses an arbitrary numbering on S and we proved some stuff on it. The most important thing is that this procedure generates a commutative binary operator in the least steps, by only setting the cells necessary and using the commutative restraint to fill the rest.

How do we refactor this algorithm to also admit a complete identity? If we use the numbering that I proposed when making the constructor for complete identities and apply that constructor, then apply this part 2 algorithm to the smaller subtable, I think we should be in the money!

New Magic Constructor

Remember, I’m using the terminology we defined in the earlier section on defining the complete identity construction.

  1. \(\forall{x\in{S}}:\) set \(f(x,1)=x\)
  2. \(\forall{x\in{S\backslash\{1\}}}:\) fix \(f(x, x)\) from S
  3. For x from 2 to |S|
    1. \(\forall{y\in{S}, y>x}:\) fix \(f(x, y)\) from S

Certainly, step 2 and 3 are the same as the original algorithm’s step 1 and 2. They work on a subset of the original set S, so the proofs for all the properties in post 2 apply only to this subset. We’re going to abuse that heavily here to prove the same semantics about this new algorithm.

1) All cells are fixed by the algorithm

In Post 2 we prove that for the table it works on, the commutative operator fixes all the cells. In our case, that’s the cells \(\{f(x,y):x,y\in{S}\land{x,y>1}\}\) i.e. the table that is all but the 1st row and column.

Obviously, the cells \(\{f(1,x):x\in{S}\}\) and \(\{f(x,1):x\in{S}\}\) are fixed:

  • The cells \(\{f(x,1):x\in{S}\}\) are set by step 1
  • By the commutative constraint \(\{f(1,x):x\in{S}\}\) are all fixed to the corresponding values \(f(x,1)\)

So the first row and column are dealt with in the new steps, and the remaining cells are filled by the old algorithm.

2) Number of cells directly set is necessary and sufficient

Certainly it is sufficient by the previous argument.

Is it necessary? We’ll try to prove a contradiction: that the operator cannot be well defined if we don’t directly set a certain cell.

  • Say some \(f(x,y)\) isn’t directly set, but the operator is still well defined
  • If x=1 or y=1
    • In step 1 we set the row \(f(x,1)\) and, by the commutative constraint, the column \(f(1,x)\)
    • Step 2 and 3 only concern themselves with the subtable \([2,n]\times{[2,n]}\) so they will never set anything on row or column 1.
    • Therefore, if the algorithm skips directly setting this cell the operator is not well defined; we cannot use any constraints to define it.
  • Otherwise, it must be a cell filled in step 2 and 3. The proof in post 2 can be applied on the subtable \([2,n]\times{[2,n]}\) (equivalently, on the set \(S\backslash\{a\}\)) to prove all cells set here are necessary

Counting up and gathering up the results

I think we have the logic necessary to start counting up.

Number of left identities

A left identity fixes a row in a table. That means we have \(n(n-1)\) cells left to choose values for. Since there are still n choices per cell, \(n^{n(n-1)}\) choices.

Number of right identities

Using the same argument as for left identities, \(n^{n(n-1)}\).

Number of complete identities

Both a row and a column are fixed. That means \(2n-1\) cells are fixed (2n for both the row and column, minus 1 for over counting). Therefore \(n^2 - 2n + 1\) cells are free to choose values for. n choices per cell means \(n^{n^2-2n+1}\) possibilities.

Number of possible operators with some identity

Same as asking \(|L\cup{R}|\). By inclusion-exclusion principle, \(|L\cup{R}|=|L|+|R|-|L\cap{R}|\)

\(|L|+|R|=2n^{n^2-n}\) and \(|L\cap{R}|=n^{n^2-2n+1}\).

Therefore \(|L\cup{R}|=2n^{n^2-n}-n^{n^2-2n+1}\).

We can simplify by simplifying \(L\cap{R}\): \(n^2-2n+1=(n-1)^2\) so we can factor that exponent in \(L\cap{R}\): \[n^{(n-1)^2}=(n^{n-1})^{n-1}=(\frac{n^n}{n})^{n-1}=\frac{n^{n(n-1)}}{n^{n-1}}\]

Then we can factor it out of \(|L\cup{R}|\): \[2n^{n^2-n}-n^{n^2-2n+1}=2n^{n(n-1)}-\frac{n^{n(n-1)}}{n^{n-1}}=n^{n(n-1)}(2-\frac{1}{n^{n-1}})\]

Therefore \(|L\cup{R}|=n^{n(n-1)}(2-\frac{1}{n^{n-1}})\)

Number of commutative operators with complete identity

Let’s use the constructor we made for this.

The number of cells fixed represent our free variables: the cells set in step 1 must be set to those values and cannot be changed.

The size of \(S\backslash\{1\}\) is \(|S|-1=n-1\). The number of cells set directly in step 2 and 3, by theorem 4 from post 2, is \(\sum_{i=1}^{n-1}{i}\).

Since each of these cells can be any of the n values from \([n]\leftrightarrow{S}\), we have \(n^{\frac{(n-1)n}{2}}\) possible options for a commutative operator that also admits a complete identity. The exponent comes from the sum we derived in the previous paragraph.

Some tissue paper tests to see if we got it right

Let’s do some concrete tests, just to see if we got it right. For n=2 we should only have 2 possible operators that can be both commutative and have a complete identity.

Let S={a,b} and let a be the identity.

Table 4: Size 2 commutative operator that admits a complete identity
a b
a a b
b b x

There is only one free variable to fix, x. There are two options from S and no constraints on what to pick, so we could make two possible operators!

For n=3, we get 27. Let S={a,b,c} and a the identity.

Table 5: Size 3 commutative operator that admits a complete identity
a b c
a a b c
b b x y
c c z w

x,y,z,w are free to pick… kinda. The commutative constraint means \(y=z\) so we actually only can fix 3 variables (if we fix y, we fix z). 3 options to pick from S, 3 variables to fix so \(3^3=27\) operators!

So this definitely satisfies these paper tissue tests, and I think the reasoning is sound. \(\square\)

Probabilities and analysis

The left member of the product \(n^{n(n-1)}\) is exactly the number of operators that admit either a left/right identity. The right member will be really close to 2 for large n i.e. \(\lim_{n\rightarrow\infty}{2-\frac{1}{n^{n-1}}}=2\)

This leads me to suggest that, like commutative operators in comparison to all binary operators, having some complete identity is exceedingly rare in comparison to having any identity; the “amount” of complete identities in \(|L\cup{R}|\) is a fraction of the overall amount (the fraction being \(\frac{1}{n^{n-1}}\)).

Probability of some identity given a binary operator

This is simply the ratio \(\frac{|L\cup{R}|}{n^{n^2}}\).

\[\frac{n^{n(n-1)}(2-n^{1-n})}{n^{n^2}}=\frac{n^{n^2}n^{-n}(2-n^{1-n})}{n^{n^2}}=\frac{2-n^{1-n}}{n^n}\]

Table 6: Chance of a binary operator having some identity element
n %
1 100
3 6.996
5 0.064
10 2e-08
20 1.91-24

In comparison to commutative operators, an operator admitting some identity is actually quite likely. Of course, it’s still exceedingly rare for large n. Nevertheless, it shows that the constraint of having an identity element is actually looser than being commutative, which makes sense.

Probability of a complete identity in a binary operator

We want to find \(\frac{|L\cap{R}|}{n^{n^2}}\). I suspect this will be a very hard scaling expression, though I think it’ll still be more likely than commutativity.

\[\frac{n^{(n-1)^2}}{n^{n^2}}=\frac{n^{(n-1)^2}}{n^{(n-1)^2}n^{2n-1}}=\frac{1}{n^{2n-1}}=n^{1-2n}\]

Table 7: Chance of a binary operator having a complete identity element
n %
1 100
3 0.412
5 5.12e-05
10 1e-19
20 1.82e-49

Wow, so up to 5 the chances of having a complete identity element is slightly worse than getting a commutative operator. Past that the chances are much better for a complete identity element. That makes sense as \(2n\) is slower than \(n^2/2\) in terms of growth. Also the chances of getting a complete identity is exponentially worse than getting some identity, which makes complete sense.

Probability that an operator with some identity has complete identity

That is \(\frac{|C|}{|L\cup{R}|}\).

\[\frac{n^{(n-1)^2}}{n^{n(n-1)}(2-n^{1-n})}=\frac{n^{(n-1)^2}}{n^{n-1}n^{(n-1)^2}(2-n^{1-n})}=\] \[\frac{1}{n^{n-1}(2-n^{1-n})}=n^{1-n}{(\frac{2n^{n-1}-1}{n^{n-1}})}^{-1}=n^{1-n}\frac{n^{n-1}}{2n^{n-1}-1}=\frac{1}{2n^{n-1}-1}\]

n %
1 100
3 5.88
5 0.08
10 5e-08
20 9.5e-24

So given an identity the chances of having a complete identity are on the same order of magnitude as the chances of having an identity in any operator at all. This makes complete sense: if we have an identity and we’re checking if we have a complete one, that is the same as asking if we have the other type of identity i.e. if I have a left identity and I’m asking if it’s a complete identity, I need a right identity. This is why the chances of having a complete identity in any binary operator are so low: it’s almost a squaring of the probability!

Probability of an operator being commutative and having complete identity

That is \(\frac{n^{\frac{n(n-1)}{2}}}{n^{n^2}}\).

\[\frac{n^{\frac{n(n-1)}{2}}}{n^{n^2}}=n^{\frac{n^2-n}{2}}n^{-n^2}=n^{-\frac{n^2+n}{2}}=n^{-\frac{n(n+1)}{2}}\]

n %
1 100.0
3 0.137
5 3.28e-09
10 1e-53
20 6.08e-272

Just from this sample graph alone, along with the fact that we can assert the number of these objects is lower than general commutative operators, we can definitely say these are rare operators. Though later on the difference in orders of magnitude lessens (purely due to how tiny these probabilities get), this operator is still several orders of magnitude less likely to occur than the previous rarest object: the commutative operator.

Conclusion

So identities are quite simple objects in binary operators. Constructing an algorithm for generating them, as a result, was pretty simple. The product we get at the end is quite clean, all things considered. I’m a bit disappointed by the expression for the number of operators with some identity; it was not as clean an expression as the previous posts but, on the other hand, the natural suspicion of “complete identities are quite rare” coming from the factored constant leading to the expressions which proved that complete identities were kinda rare was cool to see.

The probability analysis is an idea that I applied retroactively into post 2 (I promise to not retcon any more articles from here on out), but I’m quite happy to have done that: it’s so cool to see the sheer scale of the numbers you’re working with from such small inputs, as well as the ridiculous chances of getting something that is starting to resemble some form of algebra. It is currently 04:01:28 and I am very tired. Typesetting the mathematics for this article was a real test of the \(\LaTeX\) skills I picked up during my dissertation. I’m quite proud of some of the work I’ve done here, though some of the equations look so squashed even in the larger \(\LaTeX\) environments I used.

Most of my blog is a constant WIP, but after this one I think I’m going to spend more time leaving my posts in the workshop before deploying them just to polish them up a bit more. All in all, this was very fun to make. Next post will be about counting associative operators, so look out for that.

Updates

2024-06-08::01:54:08 - I made a few changes in structure and wording, as well as the simplification of fractions in the probability section for clarity.

2024-06-12::21:03:31 - Changed up a few equations to look prettier, reworded conclusion.


  1. I finally did it to someone else. I feel like I’ve passed some rite of passage in mathematical writing. ↩︎

  2. I DID IT AGAIN!!! ↩︎


This post is part of the series "Counting Binary Operators".

Other posts:

  1. Counting binary operators over finite sets - General case
  2. Counting binary operators over finite sets - Commutative operators
  3. Counting binary operators over finite sets - Admitting an identity
  4. Counting binary operators over finite sets - Associative operators