1 Introduction

Let X be an arbitrary nonempty set. We use the symbol \(X_n\) if X contains \(n\ge 1\) elements, in which case we assume without loss of generality that \(X_n=\{1,\ldots ,n\}\).

In this paper we investigate the class of binary operations \(F:X^2\rightarrow X\) that are associative and quasitrivial, where quasitriviality means that F always outputs one of its input values. In the algebraic language, the pair (XF) is then called a quasitrivial semigroup (for general background, see, e.g., [10, 12, 15] and for a recent reference, see [1]). We also investigate certain subclasses of quasitrivial semigroups by adding properties such as commutativity, order-preservation, and the existence of neutral elements. The case where the semigroups are defined on finite sets (i.e., \(X=X_n\) for any integer \(n\ge 1\)) is of particular interest as it enables us to address and solve various enumeration issues. We remark that most of our results rely on a simple known theorem (Theorem 2.1) that provides a descriptive characterization of the class of quasitrivial semigroups.

After presenting some definitions and preliminary results (including Theorem 2.1) in Sect. 2, we provide in Sect. 3 different characterizations of the class of quasitrivial and commutative (i.e., Abelian) semigroups on both arbitrary sets and finite sets (Theorem 3.3). In the latter case we illustrate some of our results by showing the contour plots of the operations. When X is endowed with a total ordering we also characterize the subclass of quasitrivial, commutative, and order-preserving semigroups (Theorem 3.7) by means of the single-peakedness property, which is a generalization to arbitrary totally ordered sets of a notion introduced 70 years ago in social choice theory. In Sect. 4 we introduce the “weak single-peakedness” property (Definition 4.3) as a further generalization of single-peakedness to arbitrary weakly ordered sets to characterize the class of quasitrivial and order-preserving semigroups (Theorem 4.5). In the special case where the semigroups are defined on finite sets, the class of quasitrivial semigroups is also finite. This raises the problem of computing the size of this class as well as the sizes of all subclasses discussed in this paper. We tackle this problem in Sect. 4 where we arrive at some known integer sequences as well as new ones. The number of quasitrivial semigroups on \(X_n\) for any integer \(n\ge 1\) (Theorem 4.1) gives rise to a sequence that was previously unknown in the Sloane’s On-Line Encyclopedia of Integer Sequences (OEIS, see [19]). All the (old and new) sequences that we consider are given in explicit forms (i.e., closed-form expressions) and/or through their generating functions or exponential generating functions (Theorem 4.1 and Propositions 4.2, 4.8, 4.9, 4.11, and 4.12). In Sect. 5 we further investigate the single-peakedness and weak single-peakedness properties and provide a graphical characterization of weakly single-peaked weak orderings (Theorem 5.6). We also observe that the weakly single-peaked weak orderings on finite sets are precisely the so-called single-plateaued weak orderings introduced in social choice theory.

2 Preliminaries

Recall that a binary relation R on X is said to be

  • total if \(\forall x,y\): xRy or yRx;

  • transitive if \(\forall x,y,z\): xRy and yRz implies xRz;

  • antisymmetric if \(\forall x,y\): xRy and yRx implies \(x=y\).

Note that any total binary relation R on X is reflexive, i.e., xRx for all \(x\in X\).

Recall also that a total ordering on X is a binary relation \(\le \) on X that is total, transitive, and antisymmetric. More generally, a weak ordering on X is a binary relation \(\lesssim \) on X that is total and transitive. We denote the symmetric and asymmetric parts of \(\lesssim \) by \(\sim \) and <, respectively. Thus, \(x\sim y\) means that \(x\lesssim y\) and \(y\lesssim x\). Also, \(x<y\) means that \(x\lesssim y\) and \(\lnot (y\lesssim x)\). Recall also that \(\sim \) is an equivalence relation on X and that < induces a total ordering on the quotient set \({X/\sim }\). Thus, defining a weak ordering on X amounts to defining an ordered partition of X. For any \(a\in X\), we use the notation \([a]_{\sim }\) to denote the equivalence class of a, i.e., \([a]_{\sim }=\{x\in X: x\sim a\}\).

For any total ordering \(\le \) on X, the pair \((X,\le )\) is called a totally ordered set or a chain. Similarly, for any weak ordering \(\lesssim \) on X, the pair \((X,\lesssim )\) is called a weakly ordered set. For any integer \(n\ge 1\), we assume without loss of generality that the pair \((X_n,\le _n)\) represents the set \(X_n=\{1,\ldots ,n\}\) endowed with the total ordering relation \(\le _n\) defined by \(1<_n\cdots <_nn\).

If \((X,\lesssim )\) is a weakly ordered set, an element \(a\in X\) is said to be maximal (resp. minimal) for  \(\lesssim \) if \(x\lesssim a\) (resp. \(a\lesssim x\)) for all \(x\in X\). We denote the set of maximal (resp. minimal) elements of X for \(\lesssim \) by \(\max _{\lesssim }X\) (resp. \(\min _{\lesssim }X\)). Note that this set need not be nonempty (consider, e.g., the set of nonnegative integers endowed with the usual total ordering \(\le \)).

An operation \(F:X^2\rightarrow X\) is said to be

  • associative if \(F(F(x,y),z)=F(x,F(y,z))\) for all \(x,y,z\in X\);

  • idempotent if \(F(x,x)=x\) for all \(x\in X\);

  • quasitrivial (or conservative) if \(F(x,y)\in \{x,y\}\) for all \(x,y\in X\);

  • commutative if \(F(x,y)=F(y,x)\) for all \(x,y\in X\);

  • \(\le \)-preserving for some total ordering \(\le \) on X if for any \(x,y,x',y'\in X\) such that \(x\le x'\) and \(y\le y'\), we have \(F(x,y)\le F(x',y')\).

Given a weak ordering \(\lesssim \) on X, the maximum (resp. minimum) operation on X for \(\lesssim \) is the commutative binary operation \(\max _{\lesssim }\) (resp. \(\min _{\lesssim }\)) defined on \(X^2{\setminus }\{(x,y)\in X^2: x\sim y,~x\ne y\}\) by \(\max _{\lesssim }(x,y)=y\) (resp. \(\min _{\lesssim }(x,y)=x\)) whenever \(x\lesssim y\). We observe that if \(\lesssim \) reduces to a total ordering, then the operation \(\max _{\lesssim }\) (resp. \(\min _{\lesssim }\)) is defined everywhere on \(X^2\).

Also, the projection operations\(\pi _1:X^2\rightarrow X\) and \(\pi _2:X^2\rightarrow X\) (also called left- and right-semigroups) are respectively defined by \(\pi _1(x,y)=x\) and \(\pi _2(x,y)=y\) for all \(x,y\in X\).

An element \(e\in X\) is said to be a neutral element of \(F:X^2\rightarrow X\) if \(F(x,e)=F(e,x)=x\) for all \(x\in X\). An element \(a\in X\) is said to be an annihilator element of \(F:X^2\rightarrow X\) if \(F(x,a)=F(a,x)=a\) for all \(x\in X\).

For any integer \(n\ge 1\), any \(F:X_n^2\rightarrow X_n\), and any \(z\in X_n\), the F-degree of z, denoted \(\deg _F(z)\), is the number of points \((x,y)\in X_n^2{\setminus }\{(z,z)\}\) such that \(F(x,y)=F(z,z)\). Also, the degree sequence of F, denoted \(\deg _F\), is the nondecreasing n-element sequence of the numbers \(\deg _F(x)\), \(x\in X_n\).

We now state the key theorem on which most of our results rely. It provides a descriptive characterization of the class of associative and quasitrivial operations on X. As observed by Ackerman [1, Section 1.2], this result is a simple consequence of two papers on idempotent semigroups, namely Kimura [13] and McLean [18]. It was also independently presented by various authors (see, e.g., Kepka [12, Corollary 1.6] and Länger [15, Theorem 1]). For the sake of completeness we provide a direct elementary proof.

Theorem 2.1

\(F:X^2\rightarrow X\) is associative and quasitrivial if and only if there exists a weak ordering \(\precsim \) on X such that

$$\begin{aligned} F|_{A\times B} ~=~ {\left\{ \begin{array}{ll} \max \nolimits _{\precsim }|_{A\times B}, &{} \text {if}~A\ne B,\\ \pi _1|_{A\times B}~~\text {or}~~\pi _2|_{A\times B}, &{} \text {if}~A=B, \end{array}\right. } \quad \forall A,B\in {X/\sim }. \end{aligned}$$
(1)

Proof

(Sufficiency):

Trivial.

(Necessity):

We observe that the binary relation \(\precsim \) defined on X by

$$\begin{aligned} x\precsim y \quad \Leftrightarrow \quad F(x,y)=y~\text {or}~F(y,x)=y,\quad x,y\in X, \end{aligned}$$
(2)

is a weak ordering on X. Indeed, this relation is clearly total. Let us show that it is transitive. Let \(x,y,z\in X\) be pairwise distinct and such that \(x\precsim y\) and \(y\precsim z\). Let us assume for instance that \(F(x,y)=y\) and \(F(z,y)=z\) (the other three cases can be dealt with similarly). Then we have \(F(x,z)=z\) and hence \(x\precsim z\). Indeed, otherwise we would have \(x=F(x,z)=F(x,F(z,y))=F(F(x,z),y)=F(x,y)=y\), a contradiction.

Let us now show that Eq. (1) holds. It is easy to see that for any \(x,y\in X\) such that \(x\prec y\), we have \(F|_{\{x,y\}^2}=\textstyle {\max _{\precsim }|_{\{x,y\}^2}}\). Similarly, for any distinct \(x,y\in X\) such that \(x\sim y\) we have \(F|_{\{x,y\}^2}=\pi _1|_{\{x,y\}^2}\) or \(F|_{\{x,y\}^2}=\pi _2|_{\{x,y\}^2}\). Finally, let us show that for any pairwise distinct \(x,y,z\in X\) such that \(x\sim y\sim z\), we cannot have both \(F|_{\{x,y\}^2}=\pi _1|_{\{x,y\}^2}\) and \(F|_{\{x,z\}^2}=\pi _2|_{\{x,z\}^2}\). Indeed, otherwise

  • if \(F(y,z)=y\), then \(z=F(x,z)=F(F(x,y),z)=F(x,F(y,z))=F(x,y)=x\),

  • if \(F(y,z)=z\), then \(y=F(y,x)=F(y,F(z,x))=F(F(y,z),x)=F(z,x)=x\).

We reach a contradiction in each of these cases. \(\square \)

It is not difficult to see that the weak ordering \(\precsim \) mentioned in Theorem 2.1 is uniquely determined from F and can be defined by condition (2). If \(X=X_n\) for some integer \(n\ge 1\), then \(\precsim \) can be as well defined as follows: \(x\precsim y\) if and only if \(\deg _F(x)\le \deg _F(y)\).Footnote 1 This latter equivalence can be easily derived (see Corollary 2.3) from the following proposition.

Proposition 2.2

If \(F:X_n^2\rightarrow X_n\) is of the form (1) for some weak ordering \(\precsim \) on \(X_n\), then for any \(x\in X_n\), we have

$$\begin{aligned} \deg _F(x)= & {} 2\times |\{z\in X_n: z\prec x\}|+|\{z\in X_n: z\sim x,~z\ne x\}|\\= & {} |\{z\in X_n: z\prec x\}|+|\{z\in X_n: z\precsim x\}|-1. \end{aligned}$$

Proof

Let \(x\in X_n\). By quasitriviality, only points of the form (xz) or (zx), with \(z\in X_n\), may have the same value as (xx).

  • If \(z\prec x\), then \(F(x,z)=F(z,x)=x=F(x,x)\).

  • If \(x\prec z\), then \(F(x,z)=F(z,x)=z\ne F(x,x)\).

  • If \(z\sim x\) and \(z\ne x\), then either \(F(x,z)=\pi _1(x,z)\) or \(F(x,z)=\pi _2(x,z)\). In the first case, we have \(F(x,z)=x=F(x,x)\ne z=F(z,x)\). The other case is similar.

This completes the proof of Proposition 2.2. \(\square \)

Corollary 2.3

If \(F:X_n^2\rightarrow X_n\) is of the form (1) for some weak ordering \(\precsim \) on \(X_n\), then for any \(x,y\in X_n\), we have

$$\begin{aligned} x\precsim y\quad \Leftrightarrow \quad \deg _F(x)\le \deg _F(y). \end{aligned}$$

Proof

Let \(x,y\in X_n\) such that \(x\precsim y\). We clearly have

$$\begin{aligned} |\{z\in X_n: z\prec x\}|~\le ~|\{z\in X_n: z\prec y\}| \end{aligned}$$

and

$$\begin{aligned} |\{z\in X_n: z\precsim x\}|~\le ~|\{z\in X_n: z\precsim y\}|. \end{aligned}$$

By Proposition 2.2, we then immediately have \(\deg _F(x)\le \deg _F(y)\). The (contrapositive of the) reverse implication can be proved similarly. \(\square \)

From the properties of the maximum operation in (1), we can observe the following fact.

Fact 2.4

If \(F:X^2\rightarrow X\) is of the form (1) for some weak ordering \(\precsim \) on X, then F has a neutral element \(e\in X\) (resp. an annihilator element \(a\in X\)) if and only if the weakly ordered set \((X,\precsim )\) has a unique minimal element denoted by \(x^{\bot }\) (resp. a unique maximal element denoted by \(x^{\top }\)). In this case we have \(e = x^{\bot }\) (resp. \(a=x^{\top }\)).

Remark 1

If \(F:X^2\rightarrow X\) is of the form (1) for some weak ordering \(\precsim \) on X, then, by replacing \(\precsim \) with its inverse relation \({\precsim ^{-1}}\) (defined by \({a\precsim ^{-1}}b\Leftrightarrow b\precsim a\)), we see that F is again of the form (1), except that the maximum operation is changed to the minimum operation. Thus, choosing the maximum or the minimum operation is just a matter of convention.

The following lemma can be obtained by following the first few steps of the proof of [6, Theorem 3], which was stated in the special case where X is an arbitrary closed real interval. For the sake of self-containedness we provide a short proof.

Lemma 2.5

(see [6, Theorem 3]) If \(F:X^2\rightarrow X\) is associative, idempotent, \(\le \)-preserving for some total ordering \(\le \) on X, and has a neutral element, then F is quasitrivial.

Proof

Let e denote the neutral element of F. By idempotency and \(\le \)-preservation we clearly have \(\min _{\le }(x,y)\le F(x,y)\le \max _{\le }(x,y)\) for all \(x,y\in X\). If \(x,y\le e\), then by \(\le \)-preservation we obtain \(F(x,y)\le \min _{\le }(F(x,e),F(e,y))=\min _{\le }(x,y)\). Thus \(F(x,y)=\min _{\le }(x,y)\) whenever \(x,y\le e\). We show dually that \(F(x,y)=\max _{\le }(x,y)\) whenever \(x,y\ge e\). Assume now that \(x<e<y\) (the case \(y<e<x\) can be dealt with dually). If \(F(x,y)\le e\), then \(F(x,y)=F(F(x,x),y)=F(x,F(x,y))=\min _{\le }(x,F(x,y))=x\). We prove similarly that \(F(x,y)=y\) whenever \(F(x,y)\ge e\). It follows that F is quasitrivial. \(\square \)

When \(X_n\) is endowed with \(\le _n\), the operations \(F:X_n^2\rightarrow X_n\) can be visualized through their contour plots, where we connect points in \(X_n^2\) having the same F-values by edges or paths. For instance, the operation \(F:X_6^2\rightarrow X_6\) whose contour plot is shown in Fig. 1 is associative, quasitrivial, commutative, and \(\le _6\)-preserving.

Fig. 1
figure 1

An associative and quasitrivial operation on \(X_6\) (contour plot)

Two points (xy) and (uv) of \(X_n^2\) are said to be F-connected if they have the same F-value, i.e., if \(F(x,y)=F(u,v)\). Using this definition, we can state the following four graphical tests (see [5]), where \(F:X_n^2\rightarrow X_n\) denotes an arbitrary operation and \(\Delta _{X_n}\) denotes the set \(\{(x,x): x\in X_n\}\).

  • F is quasitrivial if and only if it is idempotent and every point \((x,y)\in X_n^2{\setminus }\Delta _{X_n}\) is F-connected to either (xx) or (yy).

  • If F is quasitrivial, then \(e\in X_n\) is a neutral element of F if and only if the point (ee) is not F-connected to another point, i.e., if and only if \(\deg _F(e)=0\).

  • If F is quasitrivial, then \(a\in X_n\) is an annihilator element of F if and only if the point (aa) is F-connected to exactly \(2n-2\) points, i.e., if and only if \(\deg _F(a)=2n-2\).

  • If F is quasitrivial, then it is associative if and only if for every rectangle in \(X_n^2\) that has only one vertex on \(\Delta _{X_n}\), at least two of the remaining three vertices are F-connected.

3 Quasitrivial and commutative semigroups

In this section we provide characterizations of the class of associative, quasitrivial, and commutative operations \(F:X^2\rightarrow X\), or equivalently, the class of quasitrivial and commutative semigroups on X. We also characterize the subclass of those operations that are order-preserving with respect to some total ordering on X.

The first characterization is given in the following theorem, which immediately follows from Theorem 2.1. We observe that Ackerman (see [1, Corollary 4.10]) generalized this result to n-ary semigroups for any integer \(n\ge 2\).

Theorem 3.1

\(F:X^2\rightarrow X\) is associative, quasitrivial, and commutative if and only if there exists a total ordering \(\preceq \) on X such that \(F=\max _{\preceq }\).

Theorem 3.3 below provides alternative characterizations of the class of associative, quasitrivial, and commutative operations. We first consider the following auxiliary lemma.

Lemma 3.2

If \(F:X^2\rightarrow X\) is quasitrivial, commutative, \(\le \)-preserving for some total ordering \(\le \) on X, then F is associative.

Proof

This result was established in the special case where X is the real unit interval [0, 1] in [17, Proposition 2]. The proof therein is purely algebraic and hence it applies to any nonempty totally ordered set. \(\square \)

Theorem 3.3

Let \(F:X^2\rightarrow X\) be an operation. The following assertions are equivalent.

  1. (i)

    F is associative, quasitrivial, and commutative.

  2. (ii)

    \(F=\max _{\preceq }\) for some total ordering \(\preceq \) on X.

  3. (iii)

    F is quasitrivial, commutative, and \(\le \)-preserving for some total ordering \(\le \) on X.

If \(X=X_n\) for some integer \(n\ge 1\), then any of the assertions (i)–(iii) above is equivalent to any of the following ones.

  1. (iv)

    F is quasitrivial and satisfies \(\deg _F=(0,2,4,\ldots ,2n-2)\).

  2. (v)

    F is associative, idempotent, commutative, \(\le \)-preserving for some total ordering \(\le \) on X, and has a neutral element.

Moreover, there are exactly n! operations \(F:X_n^2\rightarrow X_n\) satisfying any of the assertions (i)–(v). Furthermore, the total ordering \(\preceq \) considered in assertion (ii) is uniquely defined as follows: \(x\preceq y\) if and only if \(\deg _F(x)\le \deg _F(y)\). In particular, each of these operations has the (unique) neutral element \(e=\min _{\preceq }X_n\) and the (unique) annihilator element \(a=\max _{\preceq }X_n\).

Proof

The equivalence (i) \(\Leftrightarrow \) (ii) \(\Leftrightarrow \) (iii) follows from Theorem 3.1 and Lemma 3.2. We have (ii) \(\Rightarrow \) (v) by Fact 2.4 and (v) \(\Rightarrow \) (iii) by Lemma 2.5. Also, it is clear that (ii) \(\Rightarrow \) (iv).

Let us now show by induction on n that (iv) \(\Rightarrow \) (ii). The result clearly holds for \(n=1\). Suppose that it holds for some \(n\ge 1\) and let us show that it still holds for \(n+1\). Assume that \(F:X_{n+1}^2\rightarrow X_{n+1}\) is quasitrivial and that \(\deg _F=(0,2,\ldots ,2n)\). Let \(\preceq \) be the unique total ordering on \(X_{n+1}\) defined by \(x\preceq y\) if and only if \(\deg _F(x)\le \deg _F(y)\) and let \(z=\max _{\preceq }X_{n+1}\). Clearly, the operation \(F'=F|_{(X_{n+1}{\setminus }\{z\})^2}\) is quasitrivial and such that \(\deg _{F'}=(0,2,\ldots ,2n-2)\). By induction hypothesis we have \(F'=\max _{\preceq '}\), where \(\preceq '\) is the restriction of \(\preceq \) to \((X_{n+1}{\setminus }\{z\})^2\). Since \(\deg _F(z)=2n\) we necessarily have \(F=\max _{\preceq }\).

To complete the proof of the theorem, we observe that there are exactly n! total orderings on \(X_n\) and hence exactly n! operations \(F:X_n^2\rightarrow X_n\) satisfying assertion (ii). The rest of the statement is immediate. \(\square \)

Remark 2

The existence of a neutral element in assertion (v) of Theorem 3.3 cannot be replaced with the existence of an annihilator element. Indeed, the operation \(F:X_3^2\rightarrow X_3\) whose contour plot is depicted in Fig. 2 is associative, idempotent, commutative, \(\le _3\)-preserving, and has the annihilator element \(a=2\). However it is not quasitrivial.

Fig. 2
figure 2

An associative operation on \(X_3\) that is not quasitrivial

We now consider the subclass of associative, quasitrivial, and commutative operations \(F:X^2\rightarrow X\) that are \(\le \)-preserving for some fixed total ordering \(\le \) on X. To this extent we recall the single-peakedness property for arbitrary totally ordered sets. This notion was first introduced for finite totally ordered sets (i.e., finite chains) in social choice theory by Black [3, 4].

Definition 3.4

(see [7, Definition 3.8]) Let \(\le \) and \(\preceq \) be total orderings on X. We say that \(\preceq \) is single-peaked for \(\le \) if for any \(a,b,c\in X\) such that \(a<b<c\), we have \(b\prec a\) or \(b\prec c\).

Example 3.5

There are four total orderings \(\preceq \) on \(X_3\) that are single-peaked for \(\le _3\), namely \(1\prec 2\prec 3\), \(2\prec 1\prec 3\), \(2\prec 3\prec 1\), and \(3\prec 2\prec 1\).

For arbitrary total orderings \(\le \) and \(\preceq \) on X, the operation \(F=\max _{\preceq }\) need not be \(\le \)-preserving. The following proposition characterizes those total orderings \(\preceq \) on X for which \(F=\max _{\preceq }\) is \(\le \)-preserving.

Proposition 3.6

(see [7, Proposition 3.9]) Let \(\le \) be a total ordering on X and let \(F:X^2\rightarrow X\) be given by \(F=\max _{\preceq }\) for some total ordering \(\preceq \) on X. Then F is \(\le \)-preserving if and only if \(\preceq \) is single-peaked for \(\le \).

The following theorem is an immediate consequence of Lemma 3.2, Theorem 3.3, Proposition 3.6 and the known fact (see also Sect. 5) that there are exactly \(2^{n-1}\) total orderings on \(X_n\) that are single-peaked for \(\le _n\).

Theorem 3.7

Let \(F:X^2\rightarrow X\) be an operation and let \(\le \) be a total ordering on X. The following assertions are equivalent.

  1. (i)

    F is quasitrivial, commutative, and \(\le \)-preserving.

  2. (ii)

    \(F=\max _{\preceq }\) for some total ordering \(\preceq \) on X that is single-peaked for \(\le \).

If \((X,\le )=(X_n,\le _n)\) for some integer \(n\ge 1\), then any of the assertions (i)–(ii) above is equivalent to any of the following ones.

  1. (iii)

    F is quasitrivial, \(\le \)-preserving, and satisfies \(\deg _F=(0,2,4,\ldots ,2n-2)\).

  2. (iv)

    F is associative, idempotent, commutative, \(\le \)-preserving, and has a neutral element.

Moreover, there are exactly \(2^{n-1}\) operations \(F:X_n^2\rightarrow X_n\) satisfying any of the assertions (i)–(iv). Furthermore, the total ordering \(\preceq \) considered in assertion (ii) is uniquely defined as follows: \(x\preceq y\) if and only if \(\deg _F(x)\le \deg _F(y)\). In particular, each of these operations has the (unique) neutral element \(e=\min _{\preceq }X_n\) and the (unique) annihilator element \(a=\max _{\preceq }X_n\).

Example 3.8

In Fig. 3 we present the \(3!=6\) associative, quasitrivial, and commutative operations on \(X_3\). Only the first \(2^{3-1}=4\) operations are \(\le _3\)-preserving. All these operations have neutral and annihilator elements.

Fig. 3
figure 3

The six associative, quasitrivial, and commutative operations on \(X_3\)

Remark 3

  1. (a)

    To better illustrate Theorem 3.7 when X is finite, consider the operation \(F:X_6^2\rightarrow X_6\) whose contour plot is shown in Fig. 4 (left). This operation is clearly quasitrivial, \(\le _6\)-preserving, and is such that \(\deg _F=(0,2,\ldots ,10)\). By Theorem 3.7 we then have \(F=\max _{\preceq }\), where \(\preceq \) is the total ordering on \(X_6\) obtained by sorting the numbers \(\deg _F(x)\), \(x\in X_6\), in increasing order, that is, \(4\prec 3\prec 5\prec 2\prec 1\prec 6\); see Fig. 4 (right). This total ordering is single-peaked for \(\le _6\) (see also Example 5.2).

  2. (b)

    The equivalence between assertions (i) and (ii) of Theorem 3.7 was established in [7, Theorem 3.13]. When X is finite, the equivalence among assertions (i), (ii), and (iv) of Theorem 3.7 was established in [5, Theorems 12 and 17].

Fig. 4
figure 4

An operation \(F:X_6^2\rightarrow X_6\) defined by \(F=\max _{\preceq }\), where \(\preceq \) is single-peaked for \(\le _6\)

4 Enumerations of arbitrary quasitrivial semigroups

This section is devoted to the arbitrary associative and quasitrivial operations that need not be commutative. Recall that a characterization of this class of operations is given in Theorem 2.1. However, to our knowledge a generalization of Theorem 3.3 to noncommutative operations is not known and hence remains an open problem. On this issue we make the following two observations.

  • An associative and quasitrivial operation \(F:X^2\rightarrow X\) need not have a neutral element, even if X is finite. For instance, the projection operations \(\pi _1\) and \(\pi _2\) have no neutral element.

  • An associative and quasitrivial operation \(F:X^2\rightarrow X\) need not be \(\le \)-preserving for some total ordering \(\le \) on X, even if X is finite. To illustrate, consider \(F:X_4^2\rightarrow X_4\) whose contour plot is depicted in Fig. 5. This operation is associative and quasitrivial. However, it can be shown that it is not \(\le \)-preserving for any of the 24 total orderings \(\le \) on \(X_4\).

Fig. 5
figure 5

An operation that is not \(\le \)-preserving for any total ordering \(\le \)

In the rest of this section we consider the problem of enumerating quasitrivial semigroups on finite sets. For instance, for any integer \(n\ge 1\), we provide in Theorem 4.1 the exact number of associative and quasitrivial operations \(F:X_n^2\rightarrow X_n\). We posted the corresponding sequence in Sloane’s On-Line Encyclopedia of Integer Sequences (OEIS, see [19]) as sequence A292932.

In this section we often consider either the (ordinary) generating function (GF) or the exponential generating function (EGF) of a given integer sequence \((s_n)_{n\ge 0}\). Recall that, when these functions exist, they are respectively defined by the power series

$$\begin{aligned} S(z) ~=~ \sum _{n\ge 0}s_n{\,}z^n\quad \text {and}\quad \hat{S}(z) ~=~ \sum _{n\ge 0}s_n{\,}\frac{z^n}{n!}{\,}. \end{aligned}$$

Recall also that for any integers \(0\le k\le n\), the Stirling number of the second kind\(\left\{ \begin{array}{c} n\\ k\\ \end{array}\right\} \) is defined by

$$\begin{aligned} \left\{ \begin{array}{c} n\\ k\\ \end{array}\right\} ~=~ \frac{1}{k!}{\,}\sum _{i=0}^k(-1)^{k-i}{k\atopwithdelims ()i}{\,}i^{n}. \end{aligned}$$

For any integer \(n\ge 0\), let p(n) denote the number of weak orderings on \(X_n\), or equivalently, the number of ordered partitions of \(X_n\). Setting \(p(0)=1\), the number p(n) is explicitly given by

$$\begin{aligned} p(n) ~=~ \sum _{k=0}^n{\left\{ \begin{array}{c} n\\ k\\ \end{array}\right\} }{\,}k!{\,},\quad n\ge 0. \end{aligned}$$

Actually, the corresponding sequence \((p(n))_{n\ge 0}\) consists of the ordered Bell numbers (Sloane’s A000670) and satisfies the following recurrence equation

$$\begin{aligned} p(n+1) ~=~ \sum _{k=0}^n{n+1\atopwithdelims ()k}{\,}p(k){\,},\quad n\ge 0, \end{aligned}$$

with \(p(0)=1\). Moreover, its EGF is given by \(\hat{P}(z) = 1/(2-e^z)\).

For any integer \(n\ge 1\), we denote by q(n) the number of associative and quasitrivial operations \(F:X_n^2\rightarrow X_n\) (i.e., the number of quasitrivial semigroups on an n-element set). As a convention, we set \(q(0)=1\). Also, for any integer \(n\ge 0\), we denote by

  • \(q_e(n)\) the number of associative and quasitrivial operations \(F:X_n^2\rightarrow X_n\) that have neutral elements,

  • \(q_a(n)\) the number of associative and quasitrivial operations \(F:X_n^2\rightarrow X_n\) that have annihilator elements,

  • \(q_{ea}(n)\) the number of associative and quasitrivial operations \(F:X_n^2\rightarrow X_n\) that have distinct neutral and annihilator elements.

As a convention, we set \(q_e(0)=q_a(0)=q_{ea}(0)=0\). Theorem 4.1 and Proposition 4.2 below provide explicit formulas for these sequences. The first few values of these sequences are shown in Table 1.

Theorem 4.1

For any integer \(n\ge 0\), we have the closed-form expression

$$\begin{aligned} q(n) ~=~ \sum _{i=0}^n 2^i{\,}\sum _{k=0}^{n-i}(-1)^k{\,}{n\atopwithdelims ()k}{\left\{ \begin{array}{c} n-k\\ i\\ \end{array}\right\} }{\,}(i+k)!{\,},\quad n\ge 0. \end{aligned}$$
(3)

Moreover, the sequence \((q(n))_{n\ge 0}\) satisfies the recurrence equation

$$\begin{aligned} q(n+1) ~=~ (n+1){\,}q(n)+2\sum _{k=0}^{n-1}{n+1\atopwithdelims ()k}{\,}q(k){\,},\quad n\ge 0, \end{aligned}$$

with \(q(0)=1\). Furthermore, its EGF is given by \(\hat{Q}(z)=1/(z+3-2e^z)\).

Table 1 First few values of q(n), \(q_e(n)\), \(q_a(n)\), and \(q_{ea}(n)\)

Proof

Using Theorem 2.1 we can easily see that

$$\begin{aligned} q(n) ~=~ \sum _{k=1}^n ~\sum _{\begin{array}{c} \textstyle {n_1,\ldots ,n_k\ge 1}\\ n_1+\cdots +n_k=n \end{array}} {n\atopwithdelims ()n_1,\ldots ,n_k}\prod _{\begin{array}{c} \textstyle {i=1}\\ n_i\ge 2 \end{array}}^k 2{\,},\quad n\ge 1. \end{aligned}$$
(4)

Indeed, to compute q(n) we need to consider all the ordered partitions of \(X_n\) and count twice each equivalence class containing at least two elements (because two possible projections are to be considered for each such class). In Eq. (4), k represents the number of equivalence classes and \(n_i\) represents the cardinality of the ith class.

For any integer \(k\ge 1\), define the sequence \((s_n^k)_{n\ge 0}\) as

$$\begin{aligned} s_n^k ~=~ \sum _{\begin{array}{c} \textstyle {n_1,\ldots ,n_k\ge 0}\\ n_1+\cdots +n_k=n \end{array}}{n\atopwithdelims ()n_1,\ldots ,n_k}\prod _{i=1}^k \min \{n_i,2\}. \end{aligned}$$
(5)

Thus defined, the sequence \((s_n^k)_{n\ge 0}\) is the k-fold binomial convolution of the sequence \((\min \{n,2\})_{n\ge 0}\) (for background on convolutions see, e.g., [16, Section 7.2.1]). Since the EGF of the latter sequence is clearly the function \(z\mapsto 2e^z-z-2\), it follows that the EGF of the sequence \((s_n^k)_{n\ge 0}\) is the function \(z\mapsto (2e^z-z-2)^k\), which means that

$$\begin{aligned} s_n^k ~=~ D_z^n (2e^z-z-2)^k|_{z=0}{\,}, \end{aligned}$$
(6)

where \(D_z\) denotes the usual differential operator.

Using (4)–(6), for any integer \(n\ge 1\), we then obtain

$$\begin{aligned} q(n) ~=~ \sum _{k=1}^n s_n^k ~=~ D_z^n{\,}\frac{1-(2e^z-z-2)^{n+1}}{z+3-2e^z}\Big |_{z=0} ~=~ D_z^n{\,}\frac{1}{z+3-2e^z}\Big |_{z=0}. \end{aligned}$$

Since \(q(0)=1\) by definition, we thus see that the EGF of the sequence \((q(n))_{n\ge 0}\) is given by \(\hat{Q}(z)=(z+3-2e^z)^{-1}\).

Now, by taking the \((n+1)\)st derivative at \(z=0\) of both sides of the identity

$$\begin{aligned} (z+3-2{\,}e^z){\, }\hat{Q}(z)~=~1 \end{aligned}$$

(using the general Leibniz rule) we immediately derive the claimed recurrence equation for the sequence \((q(n))_{n\ge 0}\).

Let us now establish Eq. (3). It is enough to show that the EGF of the sequence \((\tilde{q}(n))_{n\ge 0}\) defined by \(\tilde{q}(0)=1\) and

$$\begin{aligned} \tilde{q}(n) ~=~ \sum _{i=0}^n 2^i{\,}\sum _{k=0}^{n-i}(-1)^k{\,}{n\atopwithdelims ()k}{\left\{ \begin{array}{c} n-k\\ i\\ \end{array}\right\} }{\,}(i+k)!{\,},\quad n\ge 1, \end{aligned}$$

is exactly \(\hat{Q}(z)\).

For any integer \(i\ge 0\), consider the sequences \((f_n^i)_{n\ge 0}\) and \((g_n^i)_{n\ge 0}\) defined by \(f_n^i=(-1)^n(n+i)!\) and \(g_n^i={\left\{ \begin{array}{c} n\\ i\\ \end{array}\right\} }\). Define also the sequence \((h_n^i)_{n\ge 0}\) by the binomial convolution of \((f_n^i)_{n\ge 0}\) and \((g_n^i)_{n\ge 0}\), that is,

$$\begin{aligned} h_n^i ~=~ \sum _{k=0}^n{n\atopwithdelims ()k}(-1)^k(i+k)!{\left\{ \begin{array}{c} n-k\\ i\\ \end{array}\right\} }. \end{aligned}$$

Observing that \({\left\{ \begin{array}{c} n-k\\ i\\ \end{array}\right\} }=0\) if \(n-k<i\) we see that

$$\begin{aligned} \tilde{q}(n) ~=~ \sum _{i=0}^n 2^ih_n^i{\,},\quad n\ge 0. \end{aligned}$$
(7)

Let \(\hat{F}_i(z)\), \(\hat{G}_i(z)\), and \(\hat{H}_i(z)\) be the EGFs of the sequences \((f_n^i)_{n\ge 0}\), \((g_n^i)_{n\ge 0}\), and \((h_n^i)_{n\ge 0}\), respectively. It is known (see, e.g., [9, p. 335, p. 351]) that \(\hat{F}_i(z)=i!(z+1)^{-i-1}\) and \(\hat{G}_i(z)=(e^z-1)^i/i!\). We then have

$$\begin{aligned} \hat{H}_i(z) ~=~ \hat{F}_i(z)\hat{G}_i(z) ~=~ \frac{(e^z-1)^i}{(z+1)^{i+1}}{\,}. \end{aligned}$$

Since \(h_n^i=D_z^n \hat{H}_i(z)|_{z=0}\), using (7) we obtain

$$\begin{aligned} \tilde{q}(n) ~=~ D_z^n{\,}\frac{1-\big (2\frac{e^z-1}{z+1}\big )^{n+1}}{z+3-2e^z}\Big |_{z=0} ~=~ D_z^n{\,}\frac{1}{z+3-2e^z}\Big |_{z=0} ~=~ (D_z^n{\,}\hat{Q})(0). \end{aligned}$$

This means that the EGF of \((\tilde{q}(n))_{n\ge 0}\) is given by \(\hat{Q}(z)\). This completes the proof. \(\square \)

Remark 4

  1. (a)

    It is clear that the radius r of convergence of the series \(\hat{Q}(z)\) is less than or equal to the closest singularity (\(\approx 0.583\)) to the origin of the real function \(x\mapsto 1/(x+3-2e^x)\). We conjecture that r is given by the classical ratio test and corresponds exactly to that singularity. In mathematical terms, this amounts to proving (or disproving) that

    $$\begin{aligned} \frac{q(n+1)}{(n+1){\,}q(n)} ~\rightarrow ~\frac{1}{r} ~\approx ~ 1.715\quad \text {as}~n\rightarrow \infty , \end{aligned}$$

    where \(r\approx 0.583\) is the unique positive zero of the real function \(x\mapsto x+3-2e^x\).

  2. (b)

    In the proof of Theorem 4.1 we have established Eq. (3) by first searching for the explicit form of \(\hat{Q}(z)\) from the definition of the sequence \((q(n))_{n\ge 0}\). In the appendix we provide an alternative proof of (3) that does not make use of \(\hat{Q}(z)\).

Proposition 4.2

For any integer \(n\ge 0\), we have \(q_e(n)=q_a(n)=n{\,}q(n-1)\) and \(q_{ea}(n)=n(n-1){\,}q(n-2)\).

Proof

Let us first show how we can construct an arbitrary associative and quasitrivial operation \(F:X_n^2\rightarrow X_n\) having a neutral element. There are n ways to choose the neutral element e in \(X_n\). Then we observe that the restriction of F to \((X_n{\setminus }\{e\})^2\) is still an associative and quasitrivial operation, so we have \(q(n-1)\) possible choices to construct this restriction. This shows that \(q_e(n)=n{\,}q(n-1)\). Using the same reasoning, we also obtain \(q_a(n)=n{\,}q(n-1)\) and \(q_{ea}(n)=n(n-1){\,}q(n-2)\). \(\square \)

We now consider the subclass of associative and quasitrivial operations \(F:X_n^2\rightarrow X_n\) that are \(\le _n\)-preserving. To this extent, we introduce a generalization of single-peakedness to weak orderings, that we call weak single-peakedness. This leads to a generalization of Proposition 3.6 to arbitrary quasitrivial semigroups (see Proposition 4.4). We will further elaborate on this concept in Sect. 5.

Definition 4.3

Let \(\le \) be a total ordering on X and let \(\precsim \) be a weak ordering on X. We say that \(\precsim \) is weakly single-peaked for \(\le \) if for any \(a,b,c\in X\) such that \(a<b<c\), we have \(b\prec a\) or \(b\prec c\) or \(a\sim b\sim c\).

Proposition 4.4

Let \(\le \) be a total ordering on X and let \(\precsim \) be a weak ordering on X. Suppose that \(F:X^2\rightarrow X\) is of the form (1). Then F is \(\le \)-preserving if and only if \(\precsim \) is weakly single-peaked for \(\le \).

Proof

(Necessity) We proceed by contradiction. Suppose that there exist \(a,b,c\in X\) satisfying \(a<b<c\) such that \(a\precsim b\) and \(c\precsim b\) and \(\lnot (a\sim b\sim c)\). Suppose that \(a\prec b\) and \(c\sim b\). The other two cases can be dealt with similarly.

  • If \(F|_{[b]_{\sim }^2}=\pi _1|_{[b]_{\sim }^2}\), then by \(\le \)-preservation of F we have \( b=F(a,b)\le F(a,c)\le F(b,c)=b. \)

  • If \(F|_{[b]_{\sim }^2}=\pi _2|_{[b]_{\sim }^2}\), then by \(\le \)-preservation of F we have \( b=F(b,a)\le F(c,a)\le F(c,b)=b. \)

In the first (resp. second) case we obtain \(F(a,c)=b\) (resp. \(F(c,a)=b\)), which contradicts quasitriviality.

(Sufficiency) We proceed by contradiction. Suppose that \(\precsim \) is weakly single-peaked for \(\le \) and that F is not \(\le \)-preserving. Then, for instance there exist \(x,y,z\in X\) such that

$$\begin{aligned} y<z\quad \text {and}\quad F(x,y)>F(x,z). \end{aligned}$$
(8)

Using (8) it is easy to see by contradiction that we necessarily have

$$\begin{aligned} (x\precsim y~\text {or}~x\precsim z)\quad \text {and}\quad (y\precsim x~\text {or}~ z\precsim x). \end{aligned}$$

We then have only the following three mutually exclusive cases to consider.

  • If \(y\prec x\prec z\) or \(y\sim x\prec z\) or \(y\prec x\sim z\), then by (8) we obtain \(y<z<x\), which violates weak single-peakedness.

  • If \(z\prec x\prec y\) or \(z\sim x\prec y\) or \(z\prec x\sim y\), then by (8) we obtain \(x<y<z\), which violates weak single-peakedness.

  • If \(x\sim y\sim z\), then we must have \(F|_{[x]_{\sim }^2}=\pi _1|_{[x]_{\sim }^2}\) or \(F|_{[x]_{\sim }^2}=\pi _2|_{[x]_{\sim }^2}\), which immediately violates (8).

This completes the proof of Proposition 4.4. \(\square \)

From Proposition 4.4 we immediately derive the following characterization of the class of associative, quasitrivial, and order-preserving operations \(F:X^2\rightarrow X\), thus generalizing to the noncommutative case the equivalence between assertions (i) and (ii) of Theorem 3.7. We observe that, when \(X=X_n\) for some integer \(n\ge 1\), an alternative characterisation of this class has been recently presented in [14].

Theorem 4.5

Let \(\le \) be a total ordering on X. An \(F:X^2\rightarrow X\) is associative, quasitrivial, and \(\le \)-preserving if and only if it is of the form (1) for some weak ordering \(\precsim \) on X that is weakly single-peaked for \(\le \).

We now consider the problem of enumerating associative and quasitrivial operations \(F:X_n^2\rightarrow X_n\) that are \(\le _n\)-preserving. We will make use of the following two auxiliary lemmas.

Lemma 4.6

Let \(\le \) be a total ordering on X and let \(\precsim \) be a weak ordering on X. If \(\precsim \) is weakly single-peaked for \(\le \), then there are no pairwise distinct \(a,b,c,d\in X\) such that \(a\prec b\sim c\sim d\).

Proof

We proceed by contradiction. Suppose that there exist pairwise distinct \(a,b,c,d\in X\) such that \(a\prec b\sim c\sim d\). Assume without loss of generality that \(b<c<d\). If \(b<a<c\), then the set \(\{a,c,d\}\) violates weak single-peakedness of \(\precsim \). In the three other cases the set \(\{a,b,c\}\) violates weak single-peakedness of \(\precsim \). \(\square \)

Lemma 4.7

Let \(\le \) be a total ordering on X and let \(\precsim \) be a weak ordering on X that is weakly single-peaked for \(\le \). Assume that both \(\min _{\le }X\) and \(\max _{\le }X\) are nonempty and let \(a=\min _{\le }X\) and \(b=\max _{\le }X\). If \(\max _{\precsim }X\ne X\), then \(\max _{\precsim }X\subseteq \{a,b\}\).

Proof

By Lemma 4.6 the set \(\max _{\precsim }X\) contains at most two elements. Now suppose that there exists \(x\in (\max _{\precsim }X){\setminus }\{a,b\}\). Then the set \(\{a,x,b\}\) violates weak single-peakedness of \(\precsim \). \(\square \)

Assume that \(X_n\) is endowed with \(\le _n\). For any integer \(n\ge 0\), we denote by u(n) the number of weak orderings \(\precsim \) on \(X_n\) that are weakly single-peaked for \(\le _n\). Also, we denote by

  • \(u_e(n)\) the number of weak orderings \(\precsim \) on \(X_n\) that are weakly single-peaked for \(\le _n\) and for which \(X_n\) has exactly one minimal element for \(\precsim \),

  • \(u_a(n)\) the number of weak orderings \(\precsim \) on \(X_n\) that are weakly single-peaked for \(\le _n\) and for which \(X_n\) has exactly one maximal element for \(\precsim \),

  • \(u_{ea}(n)\) the number of weak orderings \(\precsim \) on \(X_n\) that are weakly single-peaked for \(\le _n\) and for which \(X_n\) has exactly one minimal element and exactly one maximal element for \(\precsim \), the two elements being distinct.

As a convention, we set \(u(0)=u_e(0)=u_a(0)=u_{ea}(0)=0\). Propositions 4.8 and 4.9 below provide explicit formulas for these sequences. The first few values of these sequences are shown in Table 2.Footnote 2 It turns out that the sequence \((u_e(n))_{n\ge 0}\) consists of the so-called Pell numbers (Sloane’s A000129).

Table 2 First few values of u(n), \(u_e(n)\), \(u_a(n)\), and \(u_{ea}(n)\)

Proposition 4.8

The sequence \((u(n))_{n\ge 0}\) satisfies the second order linear recurrence equation

$$\begin{aligned} u(n+2)-2{\,}u(n+1)-u(n) ~=~ 1{\,},\quad n\ge 0, \end{aligned}$$

with \(u(0)=0\) and \(u(1)=1\), and we have

$$\begin{aligned} 2{\,}u(n)+1= & {} \textstyle {\frac{1}{2}(1+\sqrt{2})^{n+1}+\frac{1}{2}(1-\sqrt{2})^{n+1}}\\= & {} \textstyle {\sum _{k\ge 0}{n+1\atopwithdelims ()2k}{\,}2^k}{\,},\quad n\ge 0. \end{aligned}$$

Moreover, its GF is given by \(U(z)=z/(z^3+z^2-3z+1)\).

Proof

We clearly have \(u(0)=0\) and \(u(1)=1\). So let us assume that \(n\ge 2\). If \(\precsim \) is a weak ordering on \(X_n\) that is weakly single-peaked for \(\le _n\), then by Lemma 4.7 either \(\max _{\precsim }X_n=X_n\), or \(\max _{\precsim }X_n=\{1\}\), or \(\max _{\precsim }X_n=\{n\}\), or \(\max _{\precsim }X_n=\{1,n\}\). In the three latter cases it is clear that the restriction of \(\precsim \) to \(X_n{\setminus }\max _{\precsim }X_n\) is weakly single-peaked for the restriction of \(\le _n\) to \(X_n{\setminus }\max _{\precsim }X_n\). It follows that the number u(n) of weakly single-peaked weak orderings on \(X_n\) for \(\le _n\) satisfies the following second order linear equation

$$\begin{aligned} u(n) ~=~ 1 + u(n-1)+u(n-1)+u(n-2),\quad n\ge 2. \end{aligned}$$

The claimed expressions of u(n) and GF of \((u(n))_{n\ge 0}\) follow straightforwardly. \(\square \)

Proposition 4.9

The sequence \((u_e(n))_{n\ge 0}\) satisfies the second order linear recurrence equation

$$\begin{aligned} u_e(n+2)-2{\,}u_e(n+1)-u_e(n) ~=~ 0{\,},\quad n\ge 0, \end{aligned}$$

with \(u_e(0)=0\) and \(u_e(1)=1\), and we have

$$\begin{aligned} u_e(n)= & {} \textstyle {\frac{\sqrt{2}}{4}(1+\sqrt{2})^n-\frac{\sqrt{2}}{4}(1-\sqrt{2})^n}\\= & {} \textstyle {\sum _{k\ge 0}{n\atopwithdelims ()2k+1}{\,}2^k}{\,},\quad n\ge 0. \end{aligned}$$

Moreover, its GF is given by \(U_e(z)=-z/(z^2+2z-1)\). Furthermore, for any integer \(n\ge 1\), we have \(u_a(n)=2u(n-1)\), \(u_{ea}(n)=2u_e(n-1)\), and \(u_a(0)=u_{ea}(0)=0\).

Proof

The formula describing the sequence \((u_e(n))_{n\ge 0}\) is obtained by following the same steps as in the proof of Proposition 4.8, except that in this case we always have \(\max _{\precsim }X_n\ne X_n\). As for the sequence \((u_a(n))_{n\ge 0}\) we note that \(\max _{\precsim }X_n\) must be either \(\{1\}\) or \(\{n\}\) and that the restriction of \(\precsim \) to \(X_n{\setminus }\max _{\precsim }X_n\) is weakly single-peaked for the restriction of \(\le _n\) to \(X_n{\setminus }\max _{\precsim }X_n\). We proceed similarly for the sequence \((u_{ea}(n))_{n\ge 0}\).

\(\square \)

Example 4.10

The \(u(3)=8\) weak orderings on \(X_3\) that are weakly single-peaked for \(\le _3\) are: \(1\prec 2\prec 3\), \(2\prec 1\prec 3\), \(2\prec 3\prec 1\), \(3\prec 2\prec 1\), \(2\prec 1\sim 3\), \(1\sim 2\prec 3\), \(2\sim 3\prec 1\), and \(1\sim 2\sim 3\). \(u_e(3)=5\) of those have exactly one minimal element and \(u_a(3)=6\) of those have exactly one maximal element. \(u_{ea}(3)=4\) of those have exactly one minimal element and exactly one maximal element. These four weak orderings correspond to the \(2^{3-1}=4\) total orderings on \(X_3\) that are single-peaked for \(\le _3\).

Assume again that \(X_n\) is endowed with \(\le _n\). For any integer \(n\ge 0\), we denote by v(n) the number of associative, quasitrivial, and \(\le _n\)-preserving operations \(F:X_n^2\rightarrow X_n\). Also, we denote by

  • \(v_e(n)\) the number of associative, quasitrivial, and \(\le _n\)-preserving operations \(F:X_n^2\rightarrow X_n\) that have neutral elements,

  • \(v_a(n)\) the number of associative, quasitrivial, and \(\le _n\)-preserving operations \(F:X_n^2\rightarrow X_n\) that have annihilator elements,

  • \(v_{ea}(n)\) the number of associative, quasitrivial, and \(\le _n\)-preserving operations \(F:X_n^2\rightarrow X_n\) that have distinct neutral and annihilator elements.

As a convention, we set \(v(0)=v_e(0)=v_a(0)=v_{ea}(0)=0\). Propositions 4.11 and 4.12 below provide explicit formulas for these sequences. The first few values of these sequences are shown in Table 3.

Table 3 First few values of v(n), \(v_e(n)\), \(v_a(n)\), and \(v_{ea}(n)\)

Proposition 4.11

The sequence \((v(n))_{n\ge 0}\) satisfies the second order linear recurrence equation

$$\begin{aligned} v(n+2)-2{\,}v(n+1)-2{\,}v(n) ~=~ 2{\,},\quad n\ge 0, \end{aligned}$$

with \(v(0)=0\) and \(v(1)=1\), and we have

$$\begin{aligned} 3{\,}v(n)+2= & {} \textstyle {\frac{2+\sqrt{3}}{2}(1+\sqrt{3})^n+\frac{2-\sqrt{3}}{2}(1-\sqrt{3})^n}\\= & {} \textstyle {\sum _{k\ge 0}3^k(2{n\atopwithdelims ()2k}+3{n\atopwithdelims ()2k+1})}{\,},\quad n\ge 0. \end{aligned}$$

Moreover, its GF is given by \(V(z)=z(z+1)/(2z^3-3z+1)\).

Proof

We clearly have \(v(0)=0\) and \(v(1)=1\). So let us assume that \(n\ge 2\). If \(F:X_n^2\rightarrow X_n\) is an associative, quasitrivial, and \(\le _n\)-preserving operation, then by Theorem 4.5 it is of the form (1) for some weak ordering \(\precsim \) on \(X_n\) that is weakly single-peaked for \(\le _n\). By Lemma 4.7, either \(\max _{\precsim }X_n=X_n\) or \(\max _{\precsim }X_n=\{1\}\) or \(\max _{\precsim }X_n=\{n\}\) or \(\max _{\precsim }X_n=\{1,n\}\). In the first case we have to consider the two projections \(F=\pi _1\) and \(F=\pi _2\). In the three latter cases it is clear that the restriction of F to \((X_n{\setminus }\max _{\precsim }X_n)^2\) is associative, quasitrivial, and \(\le '_n\)-preserving, where \(\le '_n\) is the restriction of \(\le _n\) to \(X_n{\setminus }\max _{\precsim }X_n\). Also, in the latter case we have to consider the two projections \(F|_{\{1,n\}^2}=\pi _1|_{\{1,n\}^2}\) and \(F|_{\{1,n\}^2}=\pi _2|_{\{1,n\}^2}\). It follows that the number v(n) of associative, quasitrivial, and \(\le _n\)-preserving operations \(F:X_n^2\rightarrow X_n\) satisfies the following second order linear equation

$$\begin{aligned} v(n) ~=~ 2 + v(n-1)+v(n-1)+2v(n-2),\quad n\ge 2. \end{aligned}$$

The claimed expressions of v(n) and GF of \((v(n))_{n\ge 0}\) follow straightforwardly. \(\square \)

Proposition 4.12

The sequence \((v_e(n))_{n\ge 0}\) satisfies the second order linear recurrence equation

$$\begin{aligned} v_e(n+2)-2{\,}v_e(n+1)-2v_e(n) ~=~ 0{\,},\quad n\ge 0, \end{aligned}$$

with \(v_e(0)=0\) and \(v_e(1)=1\), and we have

$$\begin{aligned} \textstyle {v_e(n) ~=~ \frac{\sqrt{3}}{6}(1+\sqrt{3})^n-\frac{\sqrt{3}}{6}(1-\sqrt{3})^n ~=~ \sum _{k\ge 0}{n\atopwithdelims ()2k+1}{\,}3^k{\,},\quad n\ge 0.} \end{aligned}$$

Moreover, its GF is given by \(V_e(z)=-z/(2z^2+2z-1)\). Furthermore, for any integer \(n\ge 1\), we have \(v_a(n)=2v(n-1)\), \(v_{ea}(n)=2v_e(n-1)\), and \(v_a(0)=v_{ea}(0)=0\).

Proof

The formula describing the sequence \((v_e(n))_{n\ge 0}\) is obtained by following the same steps as in the proof of Proposition 4.11, except that in this case we always have \(\max _{\precsim }X_n\ne X_n\). As for the sequence \((v_a(n))_{n\ge 0}\) we note that \(\max _{\precsim }X_n\) must be either \(\{1\}\) or \(\{n\}\) and that the restriction of F to \((X_n{\setminus }\max _{\precsim }X_n)^2\) is associative, quasitrivial, and \(\le '_n\)-preserving, where \(\le '_n\) is the restriction of \(\le _n\) to \(X_n{\setminus }\max _{\precsim }X_n\). We proceed similarly for the sequence \((v_{ea}(n))_{n\ge 0}\). \(\square \)

Example 4.13

We show in Fig. 6 the \(q(3)=20\) associative and quasitrivial operations on \(X_3\). Among these operations, \(q_e(3)=12\) have neutral elements and \(v(3)=12\) are \(\le _3\)-preserving.

Fig. 6
figure 6

The 20 associative and quasitrivial operations on \(X_3\)

Remark 5

We observe that the explicit expressions of v(n) and \(v_e(n)\) as stated in Propositions 4.11 and 4.12 were recently and independently obtained in [14] by means of a totally different approach.

5 Single-peakedness and weak single-peakedness

In this section we further analyze the single-peakedness and weak single-peakedness properties. In particular, we show how these properties can be easily checked graphically.

Define the strict convex hull of \(x,y\in X\) for a total ordering \(\le \) on X by \(\mathrm {conv}_{\le }(x,y)=\{z\in X:x<z<y\}\), if \(x<y\), and \(\mathrm {conv}_{\le }(x,y)=\{z\in X:y<z<x\}\), if \(y<x\). Using this concept we can rewrite the definitions of single-peakedness and weak single-peakedness in a more symmetric way.

Accordingly, a total ordering \(\preceq \) on X is single-peaked for a (reference) total ordering \(\le \) on X if and only if for any \(a,b,c\in X\) such that \(b\in \mathrm {conv}_{\le }(a,c)\), we have \(b\prec a\) or \(b\prec c\) (see Definition 3.4). In other words, the condition says that from among three pairwise distinct elements of X, the centrist one for \(\le \) is never ranked last by \(\preceq \).

A noteworthy characterization of single-peakedness is that for any total orderings \(\le \) and \(\preceq \) on X, the operation \(F=\max _{\preceq }\) is \(\le \)-preserving if and only if \(\preceq \) is single-peaked for \(\le \) (cf. Proposition 3.6).

Remark 6

It is natural to define the dual version of single-peakedness by saying that from among three pairwise distinct elements of X, the centrist one for \(\le \) is never ranked first by \(\preceq \). By doing so, it is clear that \(\preceq \) is single-peaked for \(\le \) if and only if the inverse ordering \({\preceq ^{-1}}\) (defined by \({a\preceq ^{-1}}b\Leftrightarrow b\preceq a\)) is dual single-peaked for \(\le \). For instance, we could replace \(\max _{\preceq }\) with \(\min _{\preceq }\) and “single-peaked” with “dual single-peaked” in Proposition 3.6. Thus, considering the single-peakedness property or its dual version is simply a matter of convention.

The following proposition provides an alternative characterization of single-peakedness. Recall first that, for any total ordering \(\le \) on X, a subset C of X is said to be convex for  \(\le \) if for any \(a,b,c\in X\) such that \(b\in \mathrm {conv}_{\le }(a,c)\), we have that \(a,c\in C\) implies \(b\in C\).

Proposition 5.1

(see [7, Proposition 3.10]) Let \(\le \) and \(\preceq \) be total orderings on X. Then \(\preceq \) is single-peaked for \(\le \) if and only if for every \(t\in X\) the set \(\{x\in X: x\preceq t\}\) is convex for \(\le \).

The single-peakedness property of a total ordering \(\preceq \) on X for some total ordering \(\le \) can often be easily checked (especially if X is finite) by plotting a function, say \(f_{\preceq }\), in a rectangular coordinate system in the following way. Represent the reference totally ordered set \((X,\le )\) on the horizontal axis and the reversed version of the totally ordered set \((X,\preceq )\), that is \((X,{\preceq ^{-1}})\), on the vertical axis. The function \(f_{\preceq }\) is defined by its graph \(\{(x,x):x\in X\}\).Footnote 3 We then see that the total ordering \(\preceq \) is single-peaked for \(\le \) if and only if the graph of \(f_{\preceq }\) is “V-free” in the sense that we cannot find three points (ii), (jj), (kk) in V-shape. Equivalently, \(f_{\preceq }\) has only one local maximum.

Example 5.2

Figure 7 gives the functions \(f_{\preceq }\) and \(f_{\preceq '}\) corresponding to the total orderings \(4\prec 3\prec 5\prec 2\prec 1\prec 6\) (from Remark 3(a)) and \(6\prec ' 5\prec ' 2\prec ' 1\prec ' 3\prec ' 4\), respectively, on \(X_6\). We see that \(\preceq \) is single-peaked for \(\le _6\) since \(f_{\preceq }\) has only one local maximum while \(\preceq '\) is not single-peaked for \(\le _6\) since \(f_{\preceq '}\) has two local maxima (also, the points (1, 1), (3, 3), (5, 5) for instance are in V-shape).

Fig. 7
figure 7

\(\preceq \) is single-peaked (left) while \(\preceq '\) is not (right)

It is known (see, e.g., [2]) that there are exactly \(2^{n-1}\) single-peaked total orderings on \(X_n\) for \(\le _n\). The proof is a simplified version of that of Proposition 4.8 (just observe that either \(\max _{\preceq }X_n=\{1\}\) or \(\max _{\preceq }X_n=\{n\}\)).

Let us now focus on weak single-peakedness. Recall (cf. Definition 4.3) that a weak ordering \(\precsim \) on X is weakly single-peaked for a reference total ordering \(\le \) on X if for any \(a,b,c\in X\) such that \(b\in \mathrm {conv}_{\le }(a,c)\), we have \(b\prec a\) or \(b\prec c\) or \(a\sim b\sim c\).

In Proposition 4.4 we saw that for any total ordering \(\le \) and weak ordering \(\precsim \) on X, any operation \(F:X^2\rightarrow X\) of the form (1) is \(\le \)-preserving if and only if \(\precsim \) is weakly single-peaked for \(\le \). This characterization justifies the definition of weak single-peakedness and shows in particular that the condition \(a\sim b\sim c\) is necessary in the definition. It is also noteworthy that the following equivalence holds

$$\begin{aligned} b\prec a~\text {or}~b\prec c~ \text {or}~a\sim b\sim c\quad \Leftrightarrow \quad {\left\{ \begin{array}{ll} a\prec b~\Rightarrow ~ b\prec c,\\ c\prec b~\Rightarrow ~ b\prec a. \end{array}\right. } \end{aligned}$$

We also have the following alternative characterization of weak single-peakedness. We omit the proof for it is straightforward (by contradiction).

Proposition 5.3

Let \(\le \) be a total ordering on X and let \(\precsim \) be a weak ordering on X. Then \(\precsim \) is weakly single-peaked for \(\le \) if and only if the following conditions hold.

  1. (a)

    For any \(a,b,c\in X\) such that \(b\in \mathrm {conv}_{\le }(a,c)\), we have \(b\precsim a\) or \(b\precsim c\).

  2. (b)

    For any \(a,b,c\in X\) such that \(a\ne c\) and \(b\prec a\sim c\), we have \(b\in \mathrm {conv}_{\le }(a,c)\).

Weak single-peakedness of a weak ordering \(\precsim \) on X for some total ordering \(\le \) can often be visualized and checked by plotting a function \(f_{\precsim }\) in a rectangular coordinate system. Represent the reference totally ordered set \((X,\le )\) on the horizontal axis and the reversed version of the weakly ordered set \((X,\precsim )\) on the vertical axis.Footnote 4 Here again the function \(f_{\preceq }\) is defined by its graph \(\{(x,x):x\in X\}\). Condition (a) of Proposition 5.3 says that the graph of \(f_{\precsim }\) is V-free, i.e., we cannot find three points (ii), (jj), (kk) in V-shape. Condition (b) is a little less immediate to interpret graphically. However, Proposition 5.5 below shows how conditions (a) and (b) together can be easily interpreted.

Definition 5.4

Let \(\le \) be a total ordering on X and let \(\precsim \) be a weak ordering on X. We say that a subset P of X of size \(|P|\ge 2\) is a plateau for \((\le ,\precsim )\) if P is convex for \(\le \) and if there exists \(x\in X\) such that \(P\subseteq [x]_{\sim }\).

Proposition 5.5

Let \(\le \) be a total ordering on X and let \(\precsim \) be a weak ordering on X. Consider the assertions (a) and (b) of Proposition 5.3 as well as the following one.

(b’):

If \(P\subseteq X\), \(|P|\ge 2\), is a plateau for \((\le ,\precsim )\), then it is \(\precsim \)-minimal in the sense that for every \(a\in X\) satisfying \(a\precsim P\) there exists \(z\in P\) such that \(z\sim a\).

Then we have ((a) and (b’)) \(\Rightarrow \) (b) and (b) \(\Rightarrow \) (b’).

Proof

Let us prove that ((a) and (b’)) implies (b). Let \(a,b,c\in X\) such that \(a\ne c\) and \(b\prec a\sim c\) and suppose that \(b\notin \mathrm {conv}_{\le }(a,c)\). Assume without loss of generality that \(b<a\). If \(\mathrm {conv}_{\le }(a,c)\) is a plateau for \((\le ,\precsim )\), then it cannot be \(\precsim \)-minimal, which contradicts (b’). Hence \(\mathrm {conv}_{\le }(a,c)\) is not a plateau for \((\le ,\precsim )\), which means that there exists \(z\in \mathrm {conv}_{\le }(a,c)\) such that \(\lnot (z\sim a)\). By (a) we then have \(z\prec a\). But then the set \(\{a,b,z\}\) violates condition (a) since the points (bb), (aa), (zz) are in V-shape.

Let us now prove that (b) implies (b’). Let \(P\subseteq X\), \(|P|\ge 2\), be a plateau for \((\le ,\precsim )\) and let \(a,c\in P\), \(a\ne c\). Suppose that P is not \(\precsim \)-minimal, i.e., there exists \(b\in X\) such that \(b\prec a\sim c\). By (b), we have \(b\in \mathrm {conv}_{\le }(a,c)\), which contradicts the fact that P is a plateau for \((\le ,\precsim )\). \(\square \)

From Proposition 5.5 it follows that conditions (a) and (b) hold if and only if conditions (a) and (b’) hold. As discussed above, condition (a) says that the graph of \(f_{\precsim }\) is V-free. Now, condition (b’) simply says that the graph of \(f_{\precsim }\) is both reversed L-free and L-free, which means that the two patterns shown in Fig. 8 (reversed L-shape and L-shape), where each horizontal part is a plateau P, are forbidden.

Fig. 8
figure 8

The two patterns excluded by condition (b’)

Summing up, we have proved the following result.

Theorem 5.6

Let \(\le \) be a total ordering on X and let \(\precsim \) be a weak ordering on X. Then \(\precsim \) is weakly single-peaked for \(\le \) if and only if conditions (a) and (b’) of Propositions 5.3 and 5.5 hold (i.e., the graph of \(f_{\precsim }\) is V-free, L-free, and reversed L-free).

Example 5.7

Let us consider the operation \(F:X_4^2\rightarrow X_4\) shown in Fig. 9 (left). Using the tests given at the end of Sect. 2 for instance, we can see that this operation is associative and quasitrivial. It is also \(\le _4\)-preserving and such that \(\deg _F=(0,3,3,6)\). Thus, F is of the form (1), where \(\precsim \) is the weak ordering on \(X_4\) obtained by ranking the numbers \(\deg _F(x)\), \(x\in X_4\), in nondecreasing order, that is, \(2\prec 1\sim 3\prec 4\); see Fig. 9 (center). By Proposition 4.4 this weak ordering \(\precsim \) is weakly single-peaked for \(\le _4\). By Theorem 5.6 the graph of \(f_{\precsim }\) is V-free, L-free, and reversed L-free; see Fig. 9 (right).

Fig. 9
figure 9

Example 5.7

Example 5.8

Let us consider the operation \(F:X_4^2\rightarrow X_4\) shown in Fig. 10 (left). Just as in Example 5.7, we can see that this operation is of the form (1), where \(\precsim \) is the weak ordering on \(X_4\) defined by \(1\prec 4\prec 2\sim 3\); see Fig. 10 (center). Since F is not \(\le _4\)-preserving, by Proposition 4.4 the weak ordering \(\precsim \) is not weakly single-peaked for \(\le _4\). Here the graph of \(f_{\precsim }\) is neither V-free, nor L-free, nor reversed L-free. It has the plateau \(P=\{2,3\}\), which is not \(\precsim \)-minimal; see Fig. 10 (right).

Fig. 10
figure 10

Example 5.8

Remark 7

For any integer \(n\ge 1\), the weak orderings \(\precsim \) on \(X=X_n\) that satisfy conditions (a) and (b’) of Propositions 5.3 and 5.5 are known in social choice theory as being single-plateaued for \(\le _n\) (see, e.g., [8, Definition 4 and Lemma 17]).Footnote 5 Thus, by Theorem 5.6 the weak orderings \(\precsim \) on \(X_n\) that are weakly single-peaked for \(\le _n\) are also single-plateaued for \(\le _n\) and vice versa. Since the graphical representations of these weak orderings need not include plateaus, we will keep our terminology and say that they are weakly single-peaked for \(\le _n\).

We can now extend Proposition 5.1 to weak orderings.

Proposition 5.9

Let \(\le \) be a total ordering on X and let \(\precsim \) be a weak ordering on X. Then condition (a) of Proposition 5.3 holds if and only if for every \(t\in X\) the set \(\{x\in X: x\precsim t\}\) is convex for \(\le \).

Proof

(Necessity) Let \(t\in X\) and let \(a,b,c\in X\) such that \(a,c\in \{x\in X: x\precsim t\}\) and \(b\in \mathrm {conv}_{\le }(a,c)\). By condition (a), we have \(b\in \{x\in X: x\precsim t\}\).

(Sufficiency) For the sake of a contradiction, suppose that there exist \(a,b,c\in X\) such that \(b\in \mathrm {conv}_{\le }(a,c)\) and \(\max _{\precsim }(a,c)\prec b\). Set \(t_0=c\) if \(a\prec c\), and \(t_0=a\), otherwise. We then have \(a,c\in \{x\in X: x\precsim t_0\}\). By convexity for \(\le \) we also have \(b\in \{x\in X: x\precsim t_0\}\). Therefore we have \(\max _{\precsim }(a,c)\prec b\precsim t_0\), which contradicts the definition of \(t_0\).\(\square \)

Remark 8

The dual version of weak single-peakedness can be defined exactly as we did for single-peakedness (see Remark 6): just replace the condition \(b\prec a\) or \(b\prec c\) or \(a\sim b\sim c\) by \(a\prec b\) or \(c\prec b\) or \(a\sim b\sim c\). Here again, considering the weak single-peakedness property or its dual version is simply a matter of convention.

6 Conclusion

This paper is rooted in a known characterization of associative and quasitrivial binary operations on an arbitrary set X, which essentially states that each of these operations can be thought of as a maximum with respect to a weak ordering (Theorem 2.1). We established different characterizations of the subclass of associative, quasitrivial, and commutative operations (Theorem 3.3) and different characterizations of the subclass of associative, quasitrivial, commutative, and \(\le \)-preserving operations when X is endowed with a total ordering \(\le \) (Theorem 3.7). When commutativity is no longer assumed, finding generalizations of these characterizations remains an interesting open question (see below).

When X is an n-element set we also enumerated

  • all associative and quasitrivial operations with or without neutral and/or annihilator elements (Theorem 4.1 and Proposition 4.2), thus solving an enumeration problem posed in [5],

  • all associative, quasitrivial, and \(\le \)-preserving operations (when X is endowed with a total ordering \(\le \)) with or without neutral and/or annihilator elements (Propositions 4.11 and 4.12).

In order to characterize those that are \(\le \)-preserving, we made use of single-peakedness. We proposed a generalization of this concept by introducing weak single-peakedness (Definition 4.3 and Theorem 4.5) and we provided a graphical characterization of the latter (Theorem 5.6). When X is an n-element set, we also enumerated all weak orderings on X that are weakly single-peaked for the reference ordering on X (Propositions 4.8 and 4.9). We posted in the Sloane’s OEIS [19] all the new sequences that arose from our results.

In view of these results, some questions emerge naturally and we now list a few below.

  • Generalize Theorems 3.3 and 3.7 by removing commutativity in assertion (i).

  • Analyze the asymptotic behavior of the sequence \((q(n))_{n\ge 0}\) (see Remark 4(a)).

  • The integer sequences A000129, A002605, A048739, and A163271 were previously introduced in the OEIS to solve enumeration problems not related to weak single-peakedness and quasitrivial semigroups. It would be interesting to establish one-to-one correspondences between those problems and ours.

  • Find the number of operations \(F:X_n^2\rightarrow X_n\) that are associative, quasitrivial, and \(\le \)-preserving for some total ordering \(\le \) on X. The values for \(1\le n\le 4\) are 1, 4, 20, 130. For instance the operation on \(X_4\) represented in Fig. 5 is associative and quasitrivial. However, there is no total ordering \(\le \) on \(X_4\) for which this operation is \(\le \)-preserving.