# Groupoid

In mathematics, especially in category theory and homotopy theory, a groupoid (less often Brandt groupoid or virtual group) generalises the notion of group in several equivalent ways. A groupoid can be seen as a:
* Group with a partial function replacing the binary operation;
* Category in which every morphism is invertible. A category of this sort can be viewed as augmented with a unary operation on the morphisms, called inverse by analogy with group theory. A groupoid where there is only one object is a usual group.
In the presence of dependent typing, a category in general can be viewed as a typed monoid, and similarly, a groupoid can be viewed as simply a typed group. The morphisms take one from one object to another, and form a dependent family of types, thus morphisms might be typed ⁠$g:A\rightarrow B$⁠, ⁠$h:B\rightarrow C$⁠, say. Composition is then a total function: ⁠$\circ :(B\rightarrow C)\rightarrow (A\rightarrow B)\rightarrow (A\rightarrow C)$⁠, so that ⁠$h\circ g:A\rightarrow C$⁠.
Special cases include:
* Setoids: sets that come with an equivalence relation,
* G-sets: sets equipped with an action of a group ⁠$G$⁠.
Groupoids are often used to reason about geometrical objects such as manifolds. Heinrich Brandt (1927) introduced groupoids implicitly via Brandt semigroups.

## Definitions
### Algebraic

A groupoid can be viewed as an algebraic structure consisting of a set with a binary partial function. Precisely, it is a non-empty set $G$ with a unary operation ⁠$^{-1}:G\to G$⁠, and a partial function ⁠$*:G\times G\rightharpoonup G$⁠. Here $*$ is not a binary operation because it is not necessarily defined for all pairs of elements of ⁠$G$⁠. The precise conditions under which $*$ is defined are not articulated here and vary by situation.
The operations $\ast$ and $^{−1}$ have the following axiomatic properties: For all ⁠$a$⁠, ⁠$b$⁠, and $c$ in ⁠$G$⁠,
* Associativity: If $a*b$ and $b*c$ are defined, then $(a*b)*c$ and $a*(b*c)$ are defined and are equal. Conversely, if one of $(a*b)*c$ or $a*(b*c)$ is defined, then they are both defined (and they are equal to each other), and $a*b$ and $b*c$ are also defined.
* Inverse: $a^{-1}*a$ and $a*{a^{-1}}$ are always defined.
* Identity: If $a*b$ is defined, then ⁠$a*b*{b^{-1}}=a$⁠, and ⁠${a^{-1}}*a*b=b$⁠. (The previous two axioms already show that these expressions are defined and unambiguous.)
Two easy and convenient properties follow from these axioms:
* ⁠$(a^{-1})^{-1}=a$⁠,
* If $a*b$ is defined, then ⁠$(a*b)^{-1}=b^{-1}*a^{-1}$⁠.

### Category-theoretic

A groupoid is a small category in which every morphism is an isomorphism, i.e., invertible. More explicitly, a groupoid $G$ is a set $G_{0}$ of objects with
* for each pair of objects x and y, a (possibly empty) set G(x,y) of morphisms (or arrows) from x to y; we write f : x → y to indicate that f is an element of G(x,y);
* for every object x, a designated element $\mathrm {id} _{x}$ of G(x, x);
* for each triple of objects x, y, and z, a function ⁠$\mathrm {comp} _{x,y,z}:G(y,z)\times G(x,y)\rightarrow G(x,z):(g,f)\mapsto gf$⁠;
* for each pair of objects x, y, a function $\mathrm {inv} :G(x,y)\rightarrow G(y,x):f\mapsto f^{-1}$ satisfying, for any f : x → y, g : y → z, and h : z → w:
** ⁠$f\ \mathrm {id} _{x}=f$⁠ and ⁠$\mathrm {id} _{y}\ f=f$⁠;
** ⁠$(hg)f=h(gf)$⁠;
** $ff^{-1}=\mathrm {id} _{y}$ and ⁠$f^{-1}f=\mathrm {id} _{x}$⁠.
If f is an element of G(x,y), then x is called the source of f, written s(f), and y is called the target of f, written t(f).
A groupoid G is sometimes denoted as ⁠$G_{1}\rightrightarrows G_{0}$⁠, where $G_{1}$ is the set of all morphisms, and the two arrows $G_{1}\to G_{0}$ represent the source and the target.
More generally, one can consider a groupoid object in an arbitrary category admitting finite fiber products.

### Comparing the definitions

The algebraic and category-theoretic definitions are equivalent, as we now show. Given a groupoid in the category-theoretic sense, let G be the disjoint union of all of the sets G(x,y) (i.e. the sets of morphisms from x to y). Then $\mathrm {comp}$ and $\mathrm {inv}$ become partial operations on G, and $\mathrm {inv}$ will in fact be defined everywhere. We define ∗ to be $\mathrm {comp}$ and $^{−1}$ to be ⁠$\mathrm {inv}$⁠, which gives a groupoid in the algebraic sense. Explicit reference to G$_0$ (and hence to ⁠$\mathrm {id}$⁠) can be dropped.
Conversely, given a groupoid G in the algebraic sense, define an equivalence relation $\sim$ on its elements by $a\sim b$ iff a ∗ a$^{−1}$ = b ∗ b$^{−1}$. Let G$_0$ be the set of equivalence classes of ⁠$\sim$⁠, i.e. ⁠$G_{0}:=G/\!\!\sim$⁠. Denote a ∗ a$^{−1}$ by $1_{x}$ if $a\in G$ with ⁠$x\in G_{0}$⁠.
Now define $G(x,y)$ as the set of all elements f such that $1_{x}*f*1_{y}$ exists. Given $f\in G(x,y)$ and ⁠$g\in G(y,z)$⁠, their composite is defined as ⁠$gf:=f*g\in G(x,z)$⁠. To see that this is well defined, observe that since $(1_{x}*f)*1_{y}$ and $1_{y}*(g*1_{z})$ exist, so does ⁠$(1_{x}*f*1_{y})*(g*1_{z})=f*g$⁠. The identity morphism on x is then ⁠$1_{x}$⁠, and the category-theoretic inverse of f is f$^{−1}$.
Sets in the definitions above may be replaced with classes, as is generally the case in category theory.

### Vertex groups and orbits

Given a groupoid G, the vertex groups or isotropy groups or object groups in G are the subsets of the form G(x,x), where x is any object of G. It follows easily from the axioms above that these are indeed groups, as every pair of elements is composable and inverses are in the same vertex group.
The orbit of a groupoid G at a point $x\in X$ is given by the set $s(t^{-1}(x))\subseteq X$ containing every point that can be joined to x by a morphism in G. If two points $x$ and $y$ are in the same orbits, their vertex groups $G(x)$ and $G(y)$ are isomorphic: if $f$ is any morphism from $x$ to ⁠$y$⁠, then the isomorphism is given by the mapping ⁠$g\to fgf^{-1}$⁠.
Orbits form a partition of the set X, and a groupoid is called transitive if it has only one orbit (equivalently, if it is connected as a category). In that case, all the vertex groups are isomorphic (on the other hand, this is not a sufficient condition for transitivity; see the section below for counterexamples).

### Subgroupoids and morphisms

A subgroupoid of $G\rightrightarrows X$ is a subcategory $H\rightrightarrows Y$ that is itself a groupoid. It is called wide or full if it is wide or full as a subcategory, i.e., respectively, if $X=Y$ or $G(x,y)=H(x,y)$ for every ⁠$x,y\in Y$⁠.
A groupoid morphism is simply a functor between two (category-theoretic) groupoids.
Particular kinds of morphisms of groupoids are of interest. A morphism $p:E\to B$ of groupoids is called a fibration if for each object $x$ of $E$ and each morphism $b$ of $B$ starting at $p(x)$ there is a morphism $e$ of $E$ starting at $x$ such that ⁠$p(e)=b$⁠. A fibration is called a covering morphism or covering of groupoids if further such an $e$ is unique. The covering morphisms of groupoids are especially useful because they can be used to model covering maps of spaces.
It is also true that the category of covering morphisms of a given groupoid $B$ is equivalent to the category of actions of the groupoid $B$ on sets.

## Examples
### Topology

Given a topological space ⁠$X$⁠, let $G_{0}$ be the set ⁠$X$⁠. The morphisms from the point $p$ to the point $q$ are equivalence classes of continuous paths from $p$ to ⁠$q$⁠, with two paths being equivalent if they are homotopic. Two such morphisms are composed by first following the first path, then the second; the homotopy equivalence guarantees that this composition is associative. This groupoid is called the fundamental groupoid of ⁠$X$⁠, denoted $\pi _{1}(X)$ (or sometimes, ⁠$\Pi _{1}(X)$⁠). The usual fundamental group $\pi _{1}(X,x)$ is then the vertex group for the point ⁠$x$⁠.
The orbits of the fundamental groupoid $\pi _{1}(X)$ are the path-connected components of ⁠$X$⁠. Accordingly, the fundamental groupoid of a path-connected space is transitive, and we recover the known fact that the fundamental groups at any base point are isomorphic. Moreover, in this case, the fundamental groupoid and the fundamental groups are equivalent as categories (see the section below for the general theory).
An important extension of this idea is to consider the fundamental groupoid $\pi _{1}(X,A)$ where $A\subset X$ is a chosen set of "base points". Here $\pi _{1}(X,A)$ is a (full) subgroupoid of ⁠$\pi _{1}(X)$⁠, where one considers only paths whose endpoints belong to ⁠$A$⁠. The set $A$ may be chosen according to the geometry of the situation at hand.

### Equivalence relation

If $X$ is a setoid, i.e. a set with an equivalence relation ⁠$\sim$⁠, then a groupoid "representing" this equivalence relation can be formed as follows:
* The objects of the groupoid are the elements of ⁠$X$⁠;
* For any two elements $x$ and $y$ in ⁠$X$⁠, there is a single morphism from $x$ to $y$ (denote by ⁠$(y,x)$⁠) if and only if ⁠$x\sim y$⁠;
* The composition of $(z,y)$ and $(y,x)$ is ⁠$(z,x)$⁠.
The vertex groups of this groupoid are always trivial; moreover, this groupoid is in general not transitive and its orbits are precisely the equivalence classes. There are two extreme examples:
* If every element of $X$ is in relation with every other element of ⁠$X$⁠, we obtain the pair groupoid of ⁠$X$⁠, which has the entire $X\times X$ as set of arrows, and which is transitive.
* If every element of $X$ is only in relation with itself, one obtains the unit groupoid, which has $X$ as set of arrows, ⁠$s=t=\mathrm {id} _{X}$⁠, and which is completely intransitive (every singleton $\{x\}$ is an orbit).

#### Examples

* If $f:X_{0}\to Y$ is a smooth surjective submersion of smooth manifolds, then $X_{0}\times _{Y}X_{0}\subset X_{0}\times X_{0}$ is an equivalence relation since $Y$ has a topology isomorphic to the quotient topology of $X_{0}$ under the surjective map of topological spaces. If we write, $X_{1}=X_{0}\times _{Y}X_{0}$ then we get a groupoid $X_{1}\rightrightarrows X_{0},$ which is sometimes called the banal groupoid of a surjective submersion of smooth manifolds.
* If we relax the reflexivity requirement and consider partial equivalence relations, then it becomes possible to consider semidecidable notions of equivalence on computable realisers for sets. This allows groupoids to be used as a computable approximation to set theory, called PER models. Considered as a category, PER models are a cartesian closed category with natural numbers object and subobject classifier, giving rise to the effective topos introduced by Martin Hyland.

### Čech groupoid

A Čech groupoid$^{p.5}$ is a special kind of groupoid associated to an equivalence relation given by an open cover ${\mathcal {U}}=\{U_{i}\}_{i\in I}$ of some manifold ⁠$X$⁠. Its objects are given by the disjoint union ${\mathcal {G}}_{0}=\coprod U_{i},$ and its arrows are the intersections ${\mathcal {G}}_{1}=\coprod U_{ij}.$
The source and target maps are then given by the induced maps
   ${\begin{aligned}s=\phi _{j}:U_{ij}\to U_{j}\\t=\phi _{i}:U_{ij}\to U_{i}\end{aligned}}$
and the inclusion map
   $\varepsilon :U_{i}\to U_{ii}$
giving the structure of a groupoid. In fact, this can be further extended by setting
   ${\mathcal {G}}_{n}={\mathcal {G}}_{1}\times _{{\mathcal {G}}_{0}}\cdots \times _{{\mathcal {G}}_{0}}{\mathcal {G}}_{1}$
as the $n$-iterated fiber product where the ${\mathcal {G}}_{n}$ represents $n$-tuples of composable arrows. The structure map of the fiber product is implicitly the target map, since
   ${\begin{matrix}U_{ijk}&\to &U_{ij}\\\downarrow &&\downarrow \\U_{ik}&\to &U_{i}\end{matrix}}$
is a cartesian diagram where the maps to $U_{i}$ are the target maps. This construction can be seen as a model for some ∞-groupoids. Also, another artifact of this construction is k-cocycles
   $[\sigma ]\in {\check {H}}^{k}({\mathcal {U}},{\underline {A}})$
for some constant sheaf of abelian groups can be represented as a function
   $\sigma :\coprod U_{i_{1}\cdots i_{k}}\to A$
giving an explicit representation of cohomology classes.

### Group action

If the group $G$ acts on the set ⁠$X$⁠, then we can form the action groupoid (or transformation groupoid) representing this group action as follows:
* The objects are the elements of ⁠$X$⁠;
* For any two elements $x$ and $y$ in ⁠$X$⁠, the morphisms from $x$ to $y$ correspond to the elements $g$ of $G$ such that ⁠$gx=y$⁠;
* Composition of morphisms interprets the binary operation of ⁠$G$⁠.
More explicitly, the action groupoid is a small category with $\mathrm {ob} (C)=X$ and $\mathrm {hom} (C)=G\times X$ and with source and target maps $s(g,x)=x$ and ⁠$t(g,x)=gx$⁠. It is often denoted $G\ltimes X$ (or $X\rtimes G$ for a right action). Multiplication (or composition) in the groupoid is then ⁠$(h,y)(g,x)=(hg,x)$⁠, which is defined provided ⁠$y=gx$⁠.
For $x$ in ⁠$X$⁠, the vertex group consists of those $(g,x)$ with ⁠$gx=x$⁠, which is just the isotropy subgroup at $x$ for the given action (which is why vertex groups are also called isotropy groups). Similarly, the orbits of the action groupoid are the orbit of the group action, and the groupoid is transitive if and only if the group action is transitive.
Another way to describe $G$-sets is the functor category ⁠$[\mathrm {Gr} ,\mathrm {Set} ]$⁠, where $\mathrm {Gr}$ is the groupoid (category) with one element and isomorphic to the group ⁠$G$⁠. Indeed, every functor $F$ of this category defines a set $X=F(\mathrm {Gr} )$ and for every $g$ in $G$ (i.e. for every morphism in ⁠$\mathrm {Gr}$⁠) induces a bijection $F_{g}$ : ⁠$X\to X$⁠. The categorical structure of the functor $F$ assures us that $F$ defines a $G$-action on the set ⁠$G$⁠. The (unique) representable functor $F:\mathrm {Gr} \to \mathrm {Set}$ is the Cayley representation of ⁠$G$⁠. In fact, this functor is isomorphic to $\mathrm {Hom} (\mathrm {Gr} ,-)$ and so sends $\mathrm {ob} (\mathrm {Gr} )$ to the set $\mathrm {Hom} (\mathrm {Gr} ,\mathrm {Gr} )$ which is by definition the "set" $G$ and the morphism $g$ of $\mathrm {Gr}$ (i.e. the element $g$ of ⁠$G$⁠) to the permutation $F_{g}$ of the set ⁠$G$⁠. We deduce from the Yoneda embedding that the group $G$ is isomorphic to the group ⁠$\{F_{g}\mid g\in G\}$⁠, a subgroup of the group of permutations of ⁠$G$⁠.

#### Finite set

Consider the group action of $\mathbb {Z} /2$ on the finite set $X=\{-2,-1,0,1,2\}$ where 1 acts by taking each number to its negative, so $-2\mapsto 2$ and ⁠$1\mapsto -1$⁠. The quotient groupoid $[X/G]$ is the set of equivalence classes from this group action ⁠$\{[0],[1],[2]\}$⁠, and $[0]$ has a group action of $\mathbb {Z} /2$ on it.

#### Quotient variety

Any finite group $G$ that maps to $GL(n)$ gives a group action on the affine space $\mathbb {A} ^{n}$ (since this is the group of automorphisms). Then, a quotient groupoid can be of the form ⁠$[\mathbb {A} ^{n}/G]$⁠, which has one point with stabilizer $G$ at the origin. Examples like these form the basis for the theory of orbifolds. Another commonly studied family of orbifolds are weighted projective spaces $\mathbb {P} (n_{1},\ldots ,n_{k})$ and subspaces of them, such as Calabi–Yau orbifolds.

### Fiber product of groupoids

Given a diagram of groupoids with groupoid morphisms
    ${\begin{aligned}&&X\\&&\downarrow \\Y&\rightarrow &Z\end{aligned}}$
where $f:X\to Z$ and ⁠$g:Y\to Z$⁠, we can form the groupoid $X\times _{Z}Y$ whose objects are triples ⁠$(x,\phi ,y)$⁠, where ⁠$x\in {\text{Ob}}(X)$⁠, ⁠$y\in {\text{Ob}}(Y)$⁠, and $\phi :f(x)\to g(y)$ in ⁠$Z$⁠. Morphisms can be defined as a pair of morphisms $(\alpha ,\beta )$ where $\alpha :x\to x'$ and $\beta :y\to y'$ such that for triples ⁠$(x,\phi ,y),(x',\phi ',y')$⁠, there is a commutative diagram in $Z$ of ⁠$f(\alpha ):f(x)\to f(x')$⁠, $g(\beta ):g(y)\to g(y')$ and the ⁠$\phi ,\phi '$⁠.

### Homological algebra

A two term complex
    $C_{1}~{\overset {d}{\rightarrow }}~C_{0}$
of objects in a concrete Abelian category can be used to form a groupoid. It has as objects the set $C_{0}$ and as arrows the set ⁠$C_{1}\oplus C_{0}$⁠; the source morphism is just the projection onto $C_{0}$ while the target morphism is the addition of projection onto $C_{1}$ composed with $d$ and projection onto ⁠$C_{0}$⁠. That is, given ⁠$c_{1}+c_{0}\in C_{1}\oplus C_{0}$⁠, we have
    $t(c_{1}+c_{0})=d(c_{1})+c_{0}.$
Of course, if the abelian category is the category of coherent sheaves on a scheme, then this construction can be used to form a presheaf of groupoids.

### Puzzles

While puzzles such as the Rubik's Cube can be modeled using group theory (see Rubik's Cube group), certain puzzles are better modeled as groupoids.
The transformations of the fifteen puzzle form a groupoid (not a group, as not all moves can be composed). This groupoid acts on configurations.

### Mathieu groupoid

The Mathieu groupoid is a groupoid introduced by John Horton Conway acting on 13 points such that the elements fixing a point form a copy of the Mathieu group M$_{12}$.

## Relation to groups

If a groupoid has only one object, then the set of its morphisms forms a group. Using the algebraic definition, such a groupoid is literally just a group. Many concepts of group theory generalize to groupoids, with the notion of functor replacing that of group homomorphism.
Every transitive/connected groupoid - that is, as explained above, one in which any two objects are connected by at least one morphism - is isomorphic to an action groupoid (as defined above) ⁠$(G,X)$⁠. By transitivity, there will only be one orbit under the action.
Note that the isomorphism just mentioned is not unique, and there is no natural choice. Choosing such an isomorphism for a transitive groupoid essentially amounts to picking one object ⁠$x_{0}$⁠, a group isomorphism $h$ from $G(x_{0})$ to ⁠$G$⁠, and for each $x$ other than ⁠$x_{0}$⁠, a morphism in $G$ from $x_{0}$ to ⁠$x$⁠.
If a groupoid is not transitive, then it is isomorphic to a disjoint union of groupoids of the above type, also called its connected components (possibly with different groups $G$ and sets $X$ for each connected component).
In category-theoretic terms, each connected component of a groupoid is equivalent (but not isomorphic) to a groupoid with a single object, that is, a single group. Thus any groupoid is equivalent to a multiset of unrelated groups. In other words, for equivalence instead of isomorphism, one does not need to specify the sets ⁠$X$⁠, but only the groups ⁠$G$⁠. For example,
* The fundamental groupoid of $X$ is equivalent to the collection of the fundamental groups of each path-connected component of ⁠$X$⁠, but an isomorphism requires specifying the set of points in each component;
* The set $X$ with the equivalence relation $\sim$ is equivalent (as a groupoid) to one copy of the trivial group for each equivalence class, but an isomorphism requires specifying what each equivalence class is;
* The set $X$ equipped with an action of the group $G$ is equivalent (as a groupoid) to one copy of $G$ for each orbit of the action, but an isomorphism requires specifying what set each orbit is.
The collapse of a groupoid into a mere collection of groups loses some information, even from a category-theoretic point of view, because it is not natural. Thus when groupoids arise in terms of other structures, as in the above examples, it can be helpful to maintain the entire groupoid. Otherwise, one must choose a way to view each $G(x)$ in terms of a single group, and this choice can be arbitrary. In the example from topology, one would have to make a coherent choice of paths (or equivalence classes of paths) from each point $p$ to each point $q$ in the same path-connected component.
As a more illuminating example, the classification of groupoids with one endomorphism does not reduce to purely group theoretic considerations. This is analogous to the fact that the classification of vector spaces with one endomorphism is nontrivial.
Morphisms of groupoids come in more kinds than those of groups: we have, for example, fibrations, covering morphisms, universal morphisms, and quotient morphisms. Thus a subgroup $H$ of a group $G$ yields an action of $G$ on the set of cosets of $H$ in $G$ and hence a covering morphism $p$ from, say, $K$ to ⁠$G$⁠, where $K$ is a groupoid with vertex groups isomorphic to ⁠$H$⁠. In this way, presentations of the group $G$ can be "lifted" to presentations of the groupoid ⁠$K$⁠, and this is a useful way of obtaining information about presentations of the subgroup ⁠$H$⁠. For further information, see the books by Higgins and by Brown in the References.

## Category of groupoids

The category whose objects are groupoids and whose morphisms are groupoid morphisms is called the groupoid category, or the category of groupoids, and is denoted by Grpd.
The category Grpd is, like the category of small categories, Cartesian closed: for any groupoids $H,K$ we can construct a groupoid $\operatorname {GPD} (H,K)$ whose objects are the morphisms $H\to K$ and whose arrows are the natural equivalences of morphisms. Thus if $H,K$ are just groups, then such arrows are the conjugacies of morphisms. The main result is that for any groupoids $G,H,K$ there is a natural bijection
    $\operatorname {Grpd} (G\times H,K)\cong \operatorname {Grpd} (G,\operatorname {GPD} (H,K)).$
This result is of interest even if all the groupoids $G,H,K$ are just groups.
Another important property of Grpd is that it is both complete and cocomplete.

### Relation to Cat

The inclusion $i:\mathbf {Grpd} \to \mathbf {Cat}$ has both a left and a right adjoint:
    $\hom _{\mathbf {Grpd} }(C[C^{-1}],G)\cong \hom _{\mathbf {Cat} }(C,i(G))$
    $\hom _{\mathbf {Cat} }(i(G),C)\cong \hom _{\mathbf {Grpd} }(G,\mathrm {Core} (C))$
Here, $C[C^{-1}]$ denotes the localization of a category that inverts every morphism, and $\mathrm {Core} (C)$ denotes the subcategory of all isomorphisms.

### Relation to sSet

The nerve functor $N:\mathbf {Grpd} \to \mathbf {sSet}$ embeds Grpd as a full subcategory of the category of simplicial sets. The nerve of a groupoid is always a Kan complex.
The nerve has a left adjoint
    $\hom _{\mathbf {Grpd} }(\pi _{1}(X),G)\cong \hom _{\mathbf {sSet} }(X,N(G))$
Here, $\pi _{1}(X)$ denotes the fundamental groupoid of the simplicial set ⁠$X$⁠.

### Groupoids in Grpd

There is an additional structure which can be derived from groupoids internal to the category of groupoids, double-groupoids. Because Grpd is a 2-category, these objects form a 2-category instead of a 1-category since there is extra structure. Essentially, these are groupoids ${\mathcal {G}}_{1},{\mathcal {G}}_{0}$ with functors
   $s,t:{\mathcal {G}}_{1}\to {\mathcal {G}}_{0}$
and an embedding given by an identity functor
   $i:{\mathcal {G}}_{0}\to {\mathcal {G}}_{1}$
One way to think about these 2-groupoids is they contain objects, morphisms, and squares which can compose together vertically and horizontally. For example, given squares
   ${\begin{matrix}\bullet &\to &\bullet \\\downarrow &&\downarrow \\\bullet &\xrightarrow {a} &\bullet \end{matrix}}$ and ${\begin{matrix}\bullet &\xrightarrow {a} &\bullet \\\downarrow &&\downarrow \\\bullet &\to &\bullet \end{matrix}}$
with $a$ the same morphism, they can be vertically conjoined giving a diagram
   ${\begin{matrix}\bullet &\to &\bullet \\\downarrow &&\downarrow \\\bullet &\xrightarrow {a} &\bullet \\\downarrow &&\downarrow \\\bullet &\to &\bullet \end{matrix}}$
which can be converted into another square by composing the vertical arrows. There is a similar composition law for horizontal attachments of squares.

## Groupoids with geometric structures

When studying geometrical objects, the arising groupoids often carry a topology, turning them into topological groupoids, or even some differentiable structure, turning them into Lie groupoids. These last objects can be also studied in terms of their associated Lie algebroids, in analogy to the relation between Lie groups and Lie algebras.
Groupoids arising from geometry often possess further structures which interact with the groupoid multiplication. For instance, in Poisson geometry one has the notion of a symplectic groupoid, which is a Lie groupoid endowed with a compatible symplectic form. Similarly, one can have groupoids with a compatible Riemannian metric, or complex structure, etc.