I want to try puzzle 103 *again*, but I want to make an algorithm.

Let's define a helper function,

\$\texttt{CategoryToPreorder}( \mathrm{Obj}( \mathcal{C}\_1), \mathrm{Obj}(\mathcal{C}\_2), \mathrm{Obj}(\mathcal{C}\_{\leq}), \mathrm{Mor}(\mathcal{C}\_{\leq}) ) \overset{\mathrm{def}}{=} \$

\$\texttt{case } [ \exists x \mid x \in \mathrm{Obj}(\mathcal{C}\_1) ] \land [ \exists y \mid y \in \mathrm{Obj}(\mathcal{C}\_2) ] \land [ \exists f \mid f \in \mathcal{C}(x,y) ] \\\\ \texttt{ CategoryToPreorder}( \mathrm{Obj}(\mathcal{C}\_1), \mathrm{Obj}(\mathcal{C}\_2) \setminus \lbrace y \rbrace, \mathrm{Obj}(\mathcal{C}\_\leq) \cup \lbrace x \rbrace \cup \lbrace y \rbrace, \mathrm{Mor}(\mathcal{C}\_\leq) \cup \lbrace x \leq y \rbrace) \$

\$\texttt{case } [\exists x \mid x \in \mathrm{Obj}(\mathcal{C}\_1)] \land [\exists y \mid y \in \mathrm{Obj}(\mathcal{C}\_2)] \land \neg[\exists f \mid f \in \mathcal{C}(x,y)] \\\\ \texttt{ CategoryToPreorder}( \mathrm{Obj}(\mathcal{C}\_1), \mathrm{Obj}(\mathcal{C}\_2) \setminus \lbrace y \rbrace, \mathrm{Obj}(\mathcal{C}\_\leq), \mathrm{Mor}(\mathcal{C}\_\leq)) \$

\$\texttt{case } [\exists x \mid x \in \mathrm{Obj}(\mathcal{C}\_1)] \land [\mathrm{Obj}(\mathcal{C}\_2) = \varnothing] \\\\ \texttt{ CategoryToPreorder}( \mathrm{Obj}(\mathcal{C}\_1) \setminus \lbrace x \rbrace, \mathrm{Obj}(\mathcal{C}), \mathrm{Obj}(\mathcal{C}\_\leq), \mathrm{Mor}(\mathcal{C}\_\leq)) \$

\$\texttt{case } [\mathrm{Obj}(\mathcal{C}\_1) = \varnothing] \\\\ \texttt{ output} \langle \mathrm{Obj}(\mathcal{C}\_\leq), \mathrm{Mor}(\mathcal{C}\_\leq) \rangle ; \\\\ \texttt{ Done!} \$

The idea here is that we iterate over the object set of \$$\mathrm{C}\$$, removing elements as we go along to avoid double counting, and adding any elements to \$$\mathrm{C}_\leq\$$ as we iterate.

Now we define our change-of-base proper,

\$\mathrm{Preorderfy}(\mathcal{C}) \overset{\mathrm{def}}{=} \\\\ \texttt{CategoryToPreorder}(\mathrm{Obj}(\mathcal{C}),\mathrm{Obj}(\mathcal{C}), \varnothing, \lbrace \varnothing \leq \varnothing \rbrace). \$

Edit: If anyone can pinpoint where the \$$\LaTeX\$$ failed, that would be wonderful.

Edit edit: Well it ain't pretty, but there it is.

Edit\$$^3\$$: Hmm, I think my helper function needs an extra dummy variable...