My question is long on background and motivation, and almost but not quite answered over at the nLab. I'll write up a bunch before asking my question (feel free to skip to the end or look at the title), so that (i) those who know more than me can see exactly what I do and do not understand (ii) those that know less than me might learn something (iii) to clarify my own thoughts.


Background
----------


Let $\mathcal S$ be a reasonably nice category: for example, I want it to at least have either all finite limits, or I want it to have a [good theory of submersions](https://mathoverflow.net/questions/45219/what-abstract-nonsense-is-necessary-to-say-the-word-submersion); and I need some extra conditions (see comments), that I haven't fully thought through, but they should be satisfied in various "geometrical" categories like (your favorite convenient category of) Topological Spaces or Manifolds. A **span in $\mathcal S$** is a diagram $X \leftarrow M \rightarrow Y$, and if I can, I will require that the right map be a submersion. There is a two-category $\operatorname{Span}(\mathcal S)$ constructed in the usual way: 1-morphisms are spans, and 2-morphisms are maps of spans that cover the identity morphisms on the bases.


A **category object in $\mathcal S$** is a span $X = \{X\_0 \leftarrow X\_1 \rightarrow X\_0\}$ and 2-morphisms $$ \{ X\_0 \leftarrow X\_0 \rightarrow X\_0 \} \overset i \to \{X\_0 \leftarrow X\_1 \rightarrow X\_0\}$$ $$ \{X\_0 \leftarrow (X\_1 \underset{X\_0}\times X\_1) \rightarrow X\_0\} \overset m \to \{X\_0 \leftarrow X\_1 \rightarrow X\_0\}$$ in $\operatorname{Span}(\mathcal S)$ making $X$ into an algebra object. (The domain of $m$ is the 1-composition of $X$ with itself in $\operatorname{Span}(\mathcal S)$, and the domain of $i$ is the 1-identity span on $X\_0$.) Writing $\circ$ for the 1-composition in $\operatorname{Span}(\mathcal S)$, the requirement is that the various maps $X\circ X \circ X \to X$ formed from $m,i$ all agree.


A **functor in $\mathcal S$** $\{X\_1 \rightrightarrows X\_0\} \to \{Y\_1 \rightrightarrows Y\_0\}$ is a pair of maps $X\_1 \to Y\_1$ and $X\_0 \to Y\_0$ making some diagrams commute. But there tend not to be enough functors when $\mathcal S$ does not satisfy the axiom of choice. For example, if $\mathcal S$ is the category of manifolds, then certain categories (the groupoids, which I will define in a moment) are supposed to present stacks, but the functor that associates to each manifold $M$ the groupoid of functors $\{M \rightrightarrows M\} \to \{X\_1 \rightrightarrows X\_0\}$ into some groupoid $X$ does not satisfy the right descent axioms.


Instead, the usual thing to do is to define the notion of "right-principal bibundles". Let $X = \{X\_1 \rightrightarrows X\_0\}$ and $Y = \{Y\_1 \rightrightarrows Y\_0\}$ be categories. An **$X,Y$-bibundle** is a span $B = \{X\_0 \leftarrow B\_1 \rightarrow Y\_0\}$ and 2-morphisms $X \circ B \to B$ and $B \circ Y \to B$, such that all the various 2-morphisms $X \circ X \circ B \circ Y \circ Y \to B$ agree (as above, $\circ$ is the 1-composition in $\operatorname{Span}(\mathcal S)$). The "tensor product over $Y$" gives a "composition" of bibundles which is associative up to a canonical associator that satisfies a pentagon.


Given a span $B = \{X\_0 \leftarrow B\_1 \rightarrow Y\_0\}$, there is another span
$$ X\_0 \leftarrow (B\_1 \underset{X\_0 \times Y\_0}\times B\_1) \rightarrow Y\_0 $$
and a "diagonal" map from $B$ to this other span. Let $B$ be an $X,Y$-bibundle. Using the diagonal map, one can build a map
$$ B\_1 \underset{Y\_0}\times Y\_1 \to B\_1 \underset{X\_0}\times B\_1$$
which is actually a map of objects over $X\_0 \times Y\_0 \times Y\_0$. On (generalized) elements, this map is $(b,y) \mapsto (b,by)$. The bibundle $B$ is **right-principal** if this map is an isomorphism. A category $X$ is a **groupoid** if it is right-principal as an $X,X$-bibundle. If $X,Y$ are groupoids, a functor $f: X \to Y$ determines an $X,Y$-bibundle where the middle object is $X\_0 \underset {Y\_0} \times Y\_1$, and it is right-principal.


Then the point is that the 2-category whose objects are groupoids in $\mathcal S$ and whose one-morphisms are right-principal bibundles embeds as a full sub-2-category into the category of "stacks", which I will not define. For a precise version of this story, see for example [C. Blohmann, Stacky Lie groups, 2007](http://arxiv.org/abs/math/0702399).


Question
--------


Any functor of categories in $\mathcal S$ determines a bibundle, but if the categories are not groupoids, then the bibundle is not (usually) right-principal; for example, the identity bibundle is not. I do want the bibundles of groupoids to be "morphisms" of categories, so I don't want to just take functors. On the other hand, as observed in [Op. cit.](http://arxiv.org/abs/math/0702399), if we don't demand some sort of "right-principality" condition, then the 2-category which allows all bibundles as 1-morphisms has neither products nor a terminal object. Hence my question is:



> 
> What is the correct notion of "bibundle" for (internal) categories that generalizes "right-principal bibundle of groupoids"?
> 
> 
> 


The answer to my question is almost "[anafunctor](http://ncatlab.org/nlab/show/anafunctor)". An anafunctor seems to have a bit more structure than a bibundle, since it is an object not in $\operatorname{Span}(\mathcal S)$ but in $\operatorname{Span}(\text{categories in }\mathcal S)$. (Conversely, at least when $\mathcal S$ is the category of sets, bibundles wihout any conditions are the same as [profunctors](http://ncatlab.org/nlab/show/profunctor).) If I understood better how to go between anafunctors and bibundles, I would probably be happy.



What condition on a "bibundle between categories" generalizes "right-principal bibundle between groupoids"?
Hi Theo. This is something I have been working on lately. In Makkai's original paper on anafunctors he defines a condition on an anafunctor which makes it *saturated*. His motivations are logical, in that he wants the 'image' of a point in the domain category (pullback and pushdown along the span) to be closed under isomorphism. This is satisfied for his examples of (co)limit anafunctors, or an anafunctor arising from a universal property. In the case that he talks about saturated anafunctors between groupoids, this is the same as a right principal bibundle (in Set). When we replace groupoids by categories, then he defines a saturated anafunctor to be an anafunctor such that the underlying span between the cores is saturated. Thus the 'cover' (in Makkai's case, a surjection of sets) is a right principal bibundle for the underlying groupoids.


This is done so that the canonical 2-functor $Cat \to Cat\_{sat.ana}$, where we do *not* assume choice, sends fully faithful, essentially surjective functors to equivalences in the bicategory $Cat\_{ana}$. Actually I'm fudging here, because Makkai defines $Cat\_{sat.ana}$ as a an anabicategory - a category weakly enriched over $Cat\_{ana}$.


Note also that Street at one point defines in his Oberwolfach descent notes a definition of a 'torsor for a category' which is just the same as Makkai's definition. He correctly notes that there are non-invertible maps between such 'torsors', unlike the group(oid) case.


So to cut a long story short, it is possible to define a saturated anafunctor for internal groupoids and hence categories. (email me if you would like some notes on this)


But! This is not the same as a torsor for an internal category, as one could extract or otherwise from various places, e.g. Moerdijk's or Johnstone. See [this answer](https://mathoverflow.net/questions/36156/internal-version-of-a-flat-functor/36182#36182). The two definitions are aiming at very different things. For example, a saturated anafunctor with codomain a topological monoid (as a one-object category) is trivial, but a torsor for the same is not. In general internal saturated anafunctors are about inverting weak equivalences between internal categories (fully faithful and essentially 'surjective': i.e. some map admitting local sections) but internal torsors are about characterising maps between topoi and classifying topoi and stuff (you can tell I know less about the latter).


