<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <contributor>
    <name>Matteo Capucci</name>
    <uri>https://matteocapucci.eu/matteo-capucci/</uri>
  </contributor>
  <updated>2026-03-05</updated>
  <title>https://matteocapucci.eu/feed/</title>
  <id>https://matteocapucci.eu/feed/</id>
  <link rel="alternate" href="https://matteocapucci.eu/feed/" />
  <link rel="self" href="https://matteocapucci.eu/feed/atom.xml" />
  <entry>
    <title>Quanta Article on Applied Category Theory</title>
    <published>2026-03-05T00:00:00Z</published>
    <updated>2026-03-05T00:00:00Z</updated>
    <author>
      <name>Matteo Capucci</name>
      <uri>https://matteocapucci.eu/matteo-capucci/</uri>
    </author>
    <link rel="alternate" type="text/html" href="https://matteocapucci.eu/quanta-article/" />
    <id>https://matteocapucci.eu/quanta-article/</id>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
  Natalie Wolchover wrote a column on <em>Quanta</em> magazine about applied category theory, mainly centering around <a href="https://matteocapucci.eu/john-baez/">John Baez</a> but also interviewing many other people from the community, including yours truly!
</p>
        <p>
  Check it out here:
  <ul><li><a href="https://www.quantamagazine.org/can-the-most-abstract-math-make-the-world-a-better-place-20260304/">Can the most abstract math make the world a better place?</a></li></ul></p>
        <p>
  This is the first time I'm interviewed in my capacity as a mathematician.
  It was really fun to articulate to Natalie what applied category theory is, and what it is good for.
  She got this quote out of me:
  <blockquote>
    When I say we’re underdogs and nobody likes us, it’s not completely true, but it’s a bit true.
  </blockquote>
  which sounds a bit self-aggrandizing, but didn't want to be.
  Applied category theory is a bit niche, sometimes dismissed as needlessly abstract and naive, but mostly respected.
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>How to deploy a Forest to GitHub Pages</title>
    <published>2026-02-17T00:00:00Z</published>
    <updated>2026-02-17T00:00:00Z</updated>
    <author>
      <name>Matteo Capucci</name>
      <uri>https://matteocapucci.eu/matteo-capucci/</uri>
    </author>
    <link rel="alternate" type="text/html" href="https://matteocapucci.eu/how-to-deploy-forester-to-github-pages/" />
    <id>https://matteocapucci.eu/how-to-deploy-forester-to-github-pages/</id>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>So you have grown a beautiful <a href="https://www.forester-notes.org/">Forester</a> forest on your machine. It is structured, it is evergreen, and the mathematical diagrams render perfectly. Naturally, you want to share it with the world via GitHub Pages. Despite it being quite easy in the end, I spent a lovely afternoon untangling 404 errors, mysterious XSLT parsing failures, and OCaml version mismatches. So here is a short guide to share what I learned in the process, for when I will inevitably forget everything.</p>
        <p>The website is deployed by a GitHub Actions workflow that installs a minimal TeX Live (for those sweet diagrams), set up OCaml 5.3+ (required for Forester 5.0), installs forester, builds the forest, and ship it to Pages.</p>
        <p>I used the <code>zauguin/install-texlive</code> action for TeX to keep things lightweight, and the standard <code>ocaml/setup-ocaml</code> with caching enabled. You can see my full workflow file here: <a href="https://github.com/mattecapu/website/blob/master/.github/workflows/forester.yml">.github/workflows/forester.yml</a>.</p>
        <p>Installing the full TeX Live distribution on CI is a massive waste of bandwidth and time. The good thing about <code>zauguin/install-texlive</code> is that you can easily instruct it to pull down a minimal installation.</p>
        <p>The package list was built by grepping around the repo for package names, and <code>scheme-basic</code> takes care of most of the essentials. Also keep in mind a package name in LaTeX is not necessarily the package name <code>tlmgr</code> expects—gotta confess that Gemini was really helpful in figuring out this one.</p>
        <pre>- name: Install TeX Live
        uses: zauguin/install-texlive@v4
        with:
          texlive_version: 2025
          packages: &gt;
            scheme-basic standalone preview dvisvgm amsfonts amsmath
            amscls cclicenses enumitem etoolbox hyperref mathpartir
            ebproof quiver pgf spath3 mathtools microtype stmaryrd
            thmtools tikz-cd tikz-nfold xcolor
</pre>
        <p>The first real pitfall I encountered was that the latest Forester (5.0+) strictly requires OCaml 5.3 or newer. If you just ask for <code>ocaml-compiler: 5.x</code>, you might get 5.2, which causes Opam to quietly fall back to Forester 4.3.1. Suddenly your new features vanish and you are debugging ghost bugs.</p>
        <p>Thus we have to pin the version we need:</p>
        <pre>- name: Setup OCaml
        uses: ocaml/setup-ocaml@v3
        with:
          # Forester 5.0 requires OCaml &gt;= 5.3.0
          ocaml-compiler: 5.3
          dune-cache: true

      - name: Install Forester
        # Pinning the version ensures we get 5.0 or fail if incompatible
        run: opam install forester.5.0
</pre>
        <p>Finally, remember to add this block to give the action permission to deploy.</p>
        <pre>permissions:
  contents: read
  pages: write
  id-token: write
</pre>
        <p>The last hurdle I had to jump was a bit of delicate configuration regarding base URLs. A good piece of debugging advice is that if you end up with a site that loads but throws "XSLT parsing errors" there is a good chance your XSLTs are 404ing, and the culprit is likely how Forester calculates base URLs when deploying to a project subdirectory. Then using browser networking tools you can see which XSL files the browser is trying to load.</p>
        <p>All in all, keep in mind Forester is sensitive to the <code>url</code> setting in <code>forest.toml</code> and its trailing slashes. If you look at my configuration in <a href="https://github.com/mattecapu/website/blob/master/forest.toml">forest.toml</a>, you will see this:</p>
        <pre>[forest]
trees = ["trees"]
assets = ["assets"]
url = "https://mattecapu.github.io/website/"
home = "matteo-capucci/"
</pre>
        <p>It's important the slashes are where they are.</p>
        <p>Because I set the URL to include <code>/website/</code>, Forester infers that the base path is <code>/website/</code>. Consequently, it builds everything into an <em>ulterior subfolder</em> named after that path inside the output directory.
In practice, this means that in the workflow we simply account for that:</p>
        <pre>- name: Upload artifact
  uses: actions/upload-pages-artifact@v3
  with:
    path: 'output/website/'
</pre>
        <p>And that's how you are reading this!</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Convolution, abstractly</title>
    <published>2024-04-02T00:00:00Z</published>
    <updated>2024-04-02T00:00:00Z</updated>
    <author>
      <name>Matteo Capucci</name>
      <uri>https://matteocapucci.eu/matteo-capucci/</uri>
    </author>
    <link rel="alternate" type="text/html" href="https://matteocapucci.eu/convolution-abstractly/" />
    <id>https://matteocapucci.eu/convolution-abstractly/</id>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p><em>This post originally appeared on <a href="https://localcharts.org/18164-convolution-abstractly.html">LocalCharts</a></em>.
</p>
        <p><em>Thanks to <a href="https://matteocapucci.eu/eigil-fjeldgren-rischel/">Eigil Fjeldgren Rischel</a> for catching a mistake in an earlier version of this post (see comment below)</em>.
</p>
        <p>
	Let <code>\cal  K</code> be a monoidal closed 2-category with left Kan extensions and let <code>T:\cal  K \to  \cal  K</code> be a <a href="https://ncatlab.org/nlab/show/lax+monoidal+functor">lax monoidal</a> endofunctor over it. Suppose <code>V</code> and <code>A</code> are <code>T</code>-algebras.
</p>
        <p>
	Often we want to define <strong><code>T</code>-convolution</strong> of ‘functions’ <code>A \to  V</code>, an operation that carries ‘<code>T</code>-terms’ of functions <code>A\to  V</code> into new functions <code>A \to  V</code>. In other words, a <code>T</code>-algebra structure on <code>[A, V]</code>.
</p>
        <p>
	The paradigmatic example here is Day convolution, where <code>\cal  K= \bf  Cat</code>, <code>V = \bf  Set</code> and <code>T</code> is the free monoidal category 2-monad. There, a ‘<code>T</code>-term of functions’ is a tuple of copresheaves <code>A \to  \bf  Set</code> over a monoidal category <code>A</code>. Day convolution gives you a new copresheaf on <code>A</code> from this data.
</p>
        <p>
	Another example is ‘Day convolaction’, which I previously described in <a href="https://matteocapucci.eu/tambara-modules-are-modules/">Tambara modules are modules</a>. In that case we have <code>\cal  K=\bf  Cat</code> and <code>V=\bf  Set</code> again but <code>T</code> is the free <code>\cal  M</code>-actegory 2-monad. Then Day convolaction endows <code>[A,V]</code> with an <code>\cal  M</code>-action. (In fact it endows it with a whole <code>[\cal  M, V]</code>-action, showing the following can be generalized further by replacing monads with graded monads, though, notably, Tambara theory only use the <code>\cal  M</code>-action!).
</p>
        <p>
	The description of <code>T</code>-convolution is really simple. It’s made of three pieces:
	<ol><li><code>T</code> is a lax monoidal functor, thus in particular <a href="https://ncatlab.org/nlab/show/closed+functor">lax closed</a>, meaning there are coherent maps:
			<code>T[A,V] \to  [TA, TV]</code></li>
		<li><code>V</code> is a <code>T</code>-algebra, thus induces a map by post-composition:
			<code>[TA,TV] \to  [TA, V]</code></li>
		<li>
			Finally, <code>\cal  K</code> is closed so the <code>T</code>-algebra structure on <code>A</code> induces a map by left Kan extension:
			<code>[TA,V] \to  [A,V]</code></li></ol></p>
        <p>
	Composing these maps gives you the desired <code>T</code>-algebra structure on <code>[A,V]</code>.
</p>
        <p>
	An observation is: one could replace left Kan extension with any contravariant aggregation operation. This is especially useful when decategorifying the above, in which case one might replace the colimits involved in a Kan extension with e.g. sums in <code>V</code>. See <a href="https://golem.ph.utexas.edu/category/2010/11/integral_transforms_and_pullpu.html">pull-tensor-push</a>.
</p>
        <p>
	Warning: the following is a bit speculative.
</p>
        <p>
	The above should work for <code>{\cal  K}={\bf  Cat}/O</code>, where <code>O</code> is a category of interfaces, and <code>T</code> is the 2-monad associated to a <a href="https://forest.localcharts.org/kda-0003.xml">double operad</a> <code>\cal  W</code> of wiring operations with colours <code>O</code>. Now a <code>T</code>-algebra is a theory of systems indexed by <code>\cal  W</code>. Let <code>V</code> be some other algebra, usually it’s something involving sets indexed by colours.
</p>
        <p>
	Then we can talk about <code>\cal  W</code>-convolution of ‘quantities’ <code>A \to  V</code>: given quantities <code>(q_i:A(o_i) \to  V(o_i))_{o_1, \ldots , o_n}</code> and an operation <code>w:o_1, \ldots , o_n \to  o</code> in <code>\cal  W</code>, we can convolve the first along <code>w</code> to obtain <code>w \ast  (q_1, \ldots , q_n) : A(o)\to  V(o)</code>.
</p>
        <p>
	Note that, crucially, we need <code>\cal  W</code> to be double to be able to perform a Kan extension. In other words, we need to know how systems map into each other to know how to aggregate quantities on them.
</p>
        <p>
	I don’t know yet what I want to do with this operation but I suspect it might be useful to study compositionality of quantities defined over systems, chiefly behaviours.
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>A glimpse of the algebraic theory of linear systems</title>
    <published>2024-03-01T00:00:00Z</published>
    <updated>2024-03-01T00:00:00Z</updated>
    <author>
      <name>Matteo Capucci</name>
      <uri>https://matteocapucci.eu/matteo-capucci/</uri>
    </author>
    <link rel="alternate" type="text/html" href="https://matteocapucci.eu/a-glimpse-of-the-algebraic-theory-of-linear-systems/" />
    <id>https://matteocapucci.eu/a-glimpse-of-the-algebraic-theory-of-linear-systems/</id>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p><em>This post originally appeared on <a href="https://localcharts.org/15799-a-glimpse-of-the-algebraic-theory-of-linear-systems.html">LocalCharts</a></em>.
</p>
        <p>
	I’ve been in Berkeley for the last two weeks, having lots of mathematical fun at <a href="https://topos.site/">Topos</a> in the context of a workshop on <a href="https://topos.site/poly-course/">Poly</a>.
</p>
        <p>
	I focused on its links with categorical systems theory, chatting with lots of people about it. With <a href="https://matteocapucci.eu/sophie-libkind/">Sophie Libkind</a> and <a href="https://matteocapucci.eu/toby-st-clere-smithe/">Toby St Clere Smithe</a> we found a bridge between the theory of <a href="https://arxiv.org/abs/2205.03906">dynamic operads</a> of David Spivak and Brandon Shapiro, the <a href="https://tsmithe.net/p/animating-cats.html">animated categories</a> of Toby, and the cybernetic systems theories of mine. I also managed to make Sophie not scared but actually delighted by categorical systems theory, the way it handles behaviour, and the beauty of it all. Yu-uh!
</p>
        <p>
	But here I’d like to report about some of the amazing things I’ve learned from <a href="https://www.algebra.mathematik.uni-siegen.de/barakat/">Mohamed Barakat</a>. He’s a <em>computational algebraist</em>, i.e. someone who makes computers do algebra for us (yay!), who’s recently been applying the methods of his discipline to the theory of <em>linear</em> systems. It turns out Kalman’s dream of reducing linear systems theory to homological algebra is alive and well, and it’s now broadly developed in <strong>algebraic systems theory</strong>.
</p>
        <p>
	In algebraic systems theory, one starts from an algebra of <em>operators</em> <code>D</code>. These can be differential operators (partial or not!), difference operators, time-shift operators and more (this theory is <em>very</em> general!). One then uses operators from <code>D</code> to write down the equations of a system. For instance we might take <code>D</code> to be the <a href="https://ncatlab.org/nlab/show/Weyl+algebra">Weyl algebra</a> of differential operators on <code><code>\mathbb {R}</code>^3</code> and write equations
</p>
        <code>\begin {cases} 3\partial _t x - u = 0\\ (\partial _t)^2 x = \partial _x^2 x\\ y = x\\ z = u\\ \end {cases}</code>
        <p>
	This is a linear system of 2 equations in the 4 variables <code>x,y,z,u</code> with coefficients in <code>D</code>, which in this (and most) case(s) is <a href="https://en.wikipedia.org/wiki/Ore_algebra">a kind of polynomial algebra</a>. Notice that the variables are all treated equally, but display some attitude: <code>x</code> looks a like a state variable, <code>u</code> like a control one, and <code>y,z</code> like observables.
</p>
        <p>
	We now hit this with lots of interesting homological algebra, i.e. linear algebra on steroids. The starting point is to present our equations as a matrix multiplication:
</p>
        <code>\begin {pmatrix} 3\partial _t &amp; 0 &amp; 0 &amp; -1\\ \partial _t^2 - \partial _x^2 &amp; 0 &amp; 0 &amp; 0\\ -1 &amp; 1 &amp;0 &amp; 0\\ 0 &amp;0 &amp; 1 &amp; -1 \end {pmatrix} \begin {pmatrix} x\\y\\z\\u \end {pmatrix} = 0</code>
        <p>
	Denote by <code>E</code> for the big matrix of operators. We can see it as a morphism of <code>D</code>-modules <code>E : D^4 \to  D^4</code>, whose cokernel represents the equations themselves as a further <code>D</code>-module:
</p>
        <code>D^4 \xrightarrow {E} D^2 \twoheadrightarrow  \operatorname {coker} E</code>
        <p>
	In this way, morphisms from <code>\operatorname {coker} E</code> to any other <code>D</code>-module <code>M</code>, such as <code>{\cal  C}^\infty (<code>\mathbb {R}</code>^n)</code> corresponds to solutions of <code>E</code> in <code>M</code>.
</p>
        <p>
	In fact now one can ‘kick the ladder’ and think of <em>any</em> finitely-presented <code>D</code>-module <code>S</code> as a linear system. Now we can formulate properties of the <em>system</em> <code>S</code> as homological properties of the <em>module</em> <code>S</code> translate to properties of the system described by <code>S</code>.
</p>
        <p>
	As an example, Mohamed showed me the following application, which I hope I’m not going to butcher. One can compute a spectral sequence related to the derived functor <code>\operatorname {Hom}(\operatorname {Hom}(-, D), D)</code> (take the double dual of a resolution of <code>S</code>) and find a presentation of <code>S</code> as a matrix algebra (he called it an equidimensional decomposition):
</p>
        <code>\begin {pmatrix} S_0 &amp; \ast  &amp; \ast  &amp; \ast  &amp; \ast \\ 0 &amp; S_1 &amp; \ast  &amp; \ast  &amp; \ast \\ \vdots  &amp; &amp;\ddots  &amp;&amp; \vdots \\ 0 &amp;&amp; \cdots  &amp;&amp; S_n \end {pmatrix}</code>
        <p>
	where each block <code>S_i</code> represents the ‘<strong>autonomy of degree <code>i</code></strong>’ of <code>S</code>, where the latter roughly means individuation a subsystem of <code>S</code> which is governed by <code>i</code>-many ‘conservation laws’ which prevent control. Algebraically, these are degrees of torsion, since a conservation law is nothing but an operator <code>d \in  D</code> such that <code>ds=0</code> for some element <code>s \in  S</code>.
	 <code>S_0</code> is the part that doesn’t respect any conservation law, but still might not be controllable: there might be other kinds of constraints, or simply couplings, expressed by equations such as <code>ds + d's' = 0</code>, which even though don’t give rise to an autonomous subsystem of <code>S</code>, constrain its controllability. One can in fact compute a further decomposition of <code>S_0</code> into more and more controllable parts.
	 A dual theory concerns observability instead, and allows one to decompose <code>S</code> into various degree of observability!
</p>
        <p>
	Moreover, Mohamed didn’t just <em>tell</em> me about this. He is a <em>computational</em> algebraist after all, so he has the means to actually <em>compute</em> the above homological construction, and indeed he showed me a live demo on Maple on how to <em>solve exactly</em> a complicated PDE in mere seconds by purely homological methods. I’m still astounded!
</p>
        <p>
	If you are as avid of reading more as me, Mohamed suggested to consult his webpage (linked above). Also, <a href="https://arxiv.org/abs/2303.02636">this paper</a> of his student Sebastian Posur paints a better picture than I did above of this wonderful theory.
</p>
        <p>
	Meeting Mohamed what such a great pleasure. He blew my mind with incredible math, and he refreshed me with an uncommon balanced attitude for someone working at the interface of theory and applications, never disowning either side. And he taught me why spectral sequences work!
</p>
        <p>
	I look forward working with him in the future, perhaps extending the algebraic theory of linear systems with compositionality results.
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Induction is induction</title>
    <published>2024-02-23T00:00:00Z</published>
    <updated>2024-02-23T00:00:00Z</updated>
    <author>
      <name>Matteo Capucci</name>
      <uri>https://matteocapucci.eu/matteo-capucci/</uri>
    </author>
    <link rel="alternate" type="text/html" href="https://matteocapucci.eu/induction-is-induction/" />
    <id>https://matteocapucci.eu/induction-is-induction/</id>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
<p><em>This post originally appeared on <a href="https://localcharts.org/15459-induction-is-induction.html">LocalCharts</a></em>.
</p><p><a href="https://matteocapucci.eu/david-corfield/">David Corfield</a> made <a href="https://ncatlab.org/davidcorfield/show/deduction,+induction,+abduction">a very interesting observation</a>: the three types of logical reasoning of Peirce’s, deduction, induction, abduction, correspond to three very elementary operations in category theory: composition, extension and lifting.
</p><p>
	Let’s see what this means.
</p>
    
      

      <figure><img src="https://matteocapucci.eu/0bdd5ffc7c57dbc232f62848db03731a.svg" /></figure>
    
    <ol><li><strong>Deduction</strong>. I observe <code>A \to  B</code> and <code>B \to  C</code>. Then, by <em>modus ponens</em>, I can conclude <code>A \to  C</code>.</li>
	<li><strong>Induction</strong>. I observe <code>A \to  B</code>, and also <code>A \to  C</code>. I conclude <code>B \to  C</code>.</li>
	<li><strong>Abduction</strong>. I observe <code>A \to  C</code> and <code>B \to  C</code>, I conclude <code>A \to  B</code>.</li></ol><p>
	Clearly induction and abduction are not <em>valid</em> reasoning rules! But they are rules reasoners <em>have</em> to use if they want to make new knowledge out of the data they have. For instance, we use induction all the time, both ‘unconsciously’ when we learn facts from the world (‘I said the word mama, mama smiled, therefore the word mama makes mama smile’) and very consciously in science (‘We collected these data samples, and we infer a functional relationship of this kind’).
</p><p>
	In fact you can see how the data for induction is literally the data of an indexed family of pairs <code>(a_i, b_i)_{i \in  I}</code>, and the result of induction is to build a map <code>f:A \to  B</code> such that <code>f(a_i) = b_i</code> for each <code>i \in  I</code>: it’s an interpolation problem!
</p>
    
      

      <figure><img src="https://matteocapucci.eu/21eef3cb600904706bbec1dfabb4a8c2.svg" /></figure>
    
    <p>
	But, again, this isn’t a valid logical rule: there might not be such <code>f</code>, since e.g. there might <code>a_i=a_j</code> with <code>b_i \neq  b_j</code> (so no function can interpolate the points), or even if the points are possible to interpolate, there’s just so many different functions that do so!
</p><p>
	So to give some logical credence to induction, we have to find a way to at least solve the second problem, and thus make induction <em>the more conservative conclusion we can make</em> having observed that <code>I \to  A</code> and <code>I \to  B</code>. In other words, solve the extension problem in a universal way.
</p><p>
	This is the job for a Kan extension!
</p><p>
	This means, first of all, moving from the unspecified 1-category I’ve been working on so far to an unspecified 2-category. Then a (right) Kan extension looks as follows:
</p>
    
      

      <figure><img src="https://matteocapucci.eu/2abb08e7fad19efc93b91facbab4d8ef.svg" /></figure>
    
    <p>
	The dashed arrow and the filling 2-cell are terminal at their job: every other such pair factors uniquely through them:
</p>
    
      

      <figure><img src="https://matteocapucci.eu/d3e50d983b0906f257b8f5fc1ed34e7a.svg" /></figure>
    
    <p>
	So this is the sense in which <code>{\rm  ran}_a b</code> is the ‘least general solution’ to this extension problem: every other solution factors through it. The right Kan extension only contains what’s justified to believe about the implication <code>A \to  B</code>.
</p><p>
	There is also a nice formula for computing <code>{\rm  ran}_a b</code> in <a href="https://ncatlab.org/nlab/show/Kan+extensionPointwiseByWeightedColimits">reasonable cases</a>, if it exists:
	<code>{\rm  ran}_a b(a) = {\large \textstyle \int _{i:I} \int _{p:A(a,a_i)} b_i}</code>
	An interpretation of this formula is that the value of the interpolation of <code>(a_i,b_i)_i</code> at some given point <code>a</code> is the limit over <code>i</code> of all the values <code>b_i</code> which lie over an <code>a_i</code> related to <code>a</code>. In other words, we ‘fill the gaps’ in the data by taking limits.
</p><p>
	Of course this is far from what actual interpolation looks like, a problem which requires spending a bit more time thinking about what are the right generalizations for all these concepts to a ‘quantitative’ setting.
</p><p>
	Still, we can test the proposed definition of ‘induction’ on something else: Peano induction! Is it a special case of induction? I claim it is.
</p><p>
	What is mathematical induction? We are given a predicate <code>\varphi  : <code>\mathbb {N}</code>_0 \to  2</code>, where <code><code>\mathbb {N}</code>_0</code> is the <em>set</em> of natural numbers, which we know satisfy <code>\varphi (k) \to  \varphi (k+1)</code> and <code>\varphi (b)</code> for some <code>b \in  <code>\mathbb {N}</code></code>. We conclude that <code>\forall  n \in  <code>\mathbb {N}</code>,\ (b \leq  n) \to  \varphi (n)</code>.
</p><p>
	So let’s work in <code>\bf  Pos</code>, the 2-category of posets. We have a map <code>i:<code>\mathbb {N}</code>_0 \to  <code>\mathbb {N}</code></code> embedding the <em>set</em> of naturals in the <em>poset</em> of naturals. We have a predicate on <code><code>\mathbb {N}</code>_0</code>. We form its right Kan extension:
</p>
    
      

      <figure><img src="https://matteocapucci.eu/6e24bcf067c305035390d0562bfd681f.svg" /></figure>
    
    <p>
	Such a Kan extension has form
	<code>{\rm  ran}_i \varphi (k) = \forall  {n \in  <code>\mathbb {N}</code>},\ (k \leq  n) \to  \varphi (n)</code>
	which reads as ‘<code>{\rm  ran}_i \varphi (k)</code> is true when <code>\varphi </code> is always true from <code>k</code> onwards’.
</p><p>
	How is this any useful for induction? Well, when <code>\varphi </code> satisfy the induction property then <code>\varphi :<code>\mathbb {N}</code>_0 \to  2</code> actually lifts to <code><code>\mathbb {N}</code> \to  2</code>, since <code>\varphi (k) \to  \varphi (k+1)</code> is a monotonicity property.
	Then by universal property of the Kan extension, there is a (necessarily unique in this context) map <em>into</em> it:
</p>
    
      

      <figure><img src="https://matteocapucci.eu/438f55becd86b2d3cd279764af4e537a.svg" /></figure>
    
    <p>
	This map corresponds to the implication
	<code>\forall  k \in  <code>\mathbb {N}</code>,\ \varphi (k) \to  \forall  {n_0 \in  <code>\mathbb {N}</code>_0}\ (k \leq  n_0) \to  \varphi (n_0)</code>
	which is equivalent to
	<code>\forall  k \in  <code>\mathbb {N}</code>, \forall  n \in  <code>\mathbb {N}</code>, \varphi (k) \land  (k \leq  n) \to  \varphi (n).</code>
	Then given a base case <code>\varphi (b)=\top </code>, we can conclude
	<code>\forall  n \in  <code>\mathbb {N}</code>, (b \leq  n) \to  \varphi (n).</code>
	So induction is a form of... induction after all!
</p><p>
	What I really proved above is that for any poset <code>W</code>, right extension along the inclusion <code>i:W_0 \to  W</code> gives you well-founded induction. Indeed, for general posets we have
	<code>{\rm  ran}_i\varphi (v) = \forall  w \in  W, (v \leq  w) \to  \varphi (w)</code>
	and ‘functoriality’ of <code>\varphi </code> is
	<code>v \leq  w \implies  \varphi (v) \to  \varphi (w)</code>
	Thus the universal map <code>\varphi  \to  {\rm  ran}_i\varphi </code> says that
	<code>\forall  v \in  W<code><![CDATA[\!]]></code>,\ \varphi (v) \to  (\forall  w \in  W, (v \leq  w) \to  \varphi (w))</code>
	which is easily seen to be equivalent to
	<code>\forall  w \in  W<code><![CDATA[\!]]></code>,\ (\forall  v\in  W<code><![CDATA[\!]]></code>, (v \leq  w) \to  \varphi (v)) \to  \varphi (w).</code>
	Of course this extends to categories as well, where you’d get some kind of ‘proof-relevant’ induction. One can give the same definition anywhere you can talk about right Kan extensions and the inclusion <code>W_0 \to  W</code>.
</p>      </div>
    </content>
  </entry>
  <entry>
    <title>Cofree Tambara modules</title>
    <published>2024-02-02T00:00:00Z</published>
    <updated>2024-02-02T00:00:00Z</updated>
    <author>
      <name>Matteo Capucci</name>
      <uri>https://matteocapucci.eu/matteo-capucci/</uri>
    </author>
    <link rel="alternate" type="text/html" href="https://matteocapucci.eu/cofree-tambara-modules/" />
    <id>https://matteocapucci.eu/cofree-tambara-modules/</id>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p><em>This post originally appeared on <a href="https://localcharts.org/14441-cofree-tambara-modules.html">LocalCharts</a></em>.
</p>
        <p>
  In my <a href="https://matteocapucci.eu/tambara-modules-are-modules/">latest post on Tambara modules</a>, I’ve shown you that if <code>\mathcal  C, \mathcal  D</code> are <code>\mathcal  M</code>-actegories then the free Tambara module construction <code>\Psi  : \bf  Prof(\mathcal  C, \mathcal  D) \to  Tamb(\mathcal  C, \mathcal  D)</code> is basically the free <code>\mathcal  M</code>-action construction, where <code>\mathcal  M</code> denotes the hom profunctor on <code>\mathcal  M</code> and ‘action’ means ‘Day convolaction’.
</p>
        <p>
  Recall Day convolaction extends an <code>\mathcal  A</code>-actegory structure on <code>\mathcal  X</code> to an <code>[\mathcal  A^{op}, \bf  Set]</code>-actegory structure on <code>[\mathcal  X^{op}, \bf  Set]</code>. One can use this actegory structure as a way for monoids in <code>[\mathcal  A^{op}, \bf  Set]</code> to act on objects of <code>[\mathcal  X^{op}, \bf  Set]</code>. Above, I’m talking about this instanced for <code>\mathcal  A = \mathcal  M \times  \mathcal  M^{op}</code> and <code>\cal  X = C \times  D^{op}</code>—thus getting an action of <code>\bf  Prof(\cal  M,M)</code> on <code>\bf  Prof(\cal  C,D)</code>—and then looking at actions of the monoid <code>\mathcal  M(-,=): \cal  M \nrightarrow  M</code>.
</p>
        <p>
  It was shown by Pastro and Street, but also by Mario Romàn and others, that <code>\Psi  \dashv  U \dashv  \Theta </code>, where <code>U</code> is the forgetful functor from Tambara modules to profunctors, and <code>\Theta </code> is the functor:
  <code>\Theta  P(C,D) = \int _M P(MC, MD).</code>
  In fact, this functor is the first one usually introduces when starting Pastro-Street theory of Tambara modules, since it’s very easy to see that coalgebras of <code>\Theta  U</code> are strengths.
   Indeed, a strength is a natural family <code>\mathsf {st}_M^{C,D}:P(C,D) \to  P(MC,MD)</code> and these maps are classified by the end above <em>by definition</em>!
</p>
        <p>
  Once we established Tambara modules are actions of <code>\mathcal  M</code>, and that <code>\Psi  \dashv  U</code> is monadic, then <code>\Theta </code> <em>has to be</em> the cofree action construction! I’ve been overlooking this fact since I didn’t know that Day convolaction <em>is always left-closed</em>, meaning acting by <code>P-:\bf  Prof(\cal  C,D) \to  \bf  Prof(\cal  C,D)</code> has parametric right adjoint <code>-/P:\bf  Prof(\cal  C,D) \to  \bf  Prof(\cal  C,D)</code> (this is different from <em>right-closed</em>, where it’s <em>receiving an action</em> which has a right adjoint, see <a href="http://www.tac.mta.ca/tac/volumes/9/n4/n4.pdf">Janelidze-Kelly</a>).
</p>
        <p>
  I’ll give a definition for profunctors straight away, but of course this works for general presheaves:
</p>
        <section>
          <p>
    For <code>P:\cal  M \nrightarrow  M</code> monoidal profunctor and <code>Q:\cal  C \nrightarrow  D</code>, define <code>Q/P:\cal  C \nrightarrow  D</code> as
    <code>Q/P(C,D) = \int _{MM'} \int _{C'D'} \mathcal  C(C', MC) \times  P(M,M') \times  \mathcal  D(M'D, D') \to  Q(C',D').</code>
    Then it’s easy to see that <code>-/\cal  M \cong  \Theta </code>, by using a couple of Yoneda reductions:
    <code>Q/{\cal  M}(C,D) = \int _{MM'} \int _{C'D'} \mathcal  C(C', MC) \times  {\cal  M}(M,M') \times  \mathcal  D(M'D, D') \to  Q(C',D')\\ \cong  \int _{M} \int _{C'D'} \mathcal  C(C', MC) \times  \mathcal  D(MD, D') \to  Q(C',D')\\ \cong  \int _{M} Q(MC,MD) = \Theta  Q(C,D).</code></p>
        </section>
      </div>
    </content>
  </entry>
  <entry>
    <title>Taming argmax</title>
    <published>2024-02-01T00:00:00Z</published>
    <updated>2024-02-01T00:00:00Z</updated>
    <author>
      <name>Matteo Capucci</name>
      <uri>https://matteocapucci.eu/matteo-capucci/</uri>
    </author>
    <link rel="alternate" type="text/html" href="https://matteocapucci.eu/taming-argmax/" />
    <id>https://matteocapucci.eu/taming-argmax/</id>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <em>This post originally appeared on <a href="https://localcharts.org/14394-taming-argmax.html">LocalCharts</a></em>
        </p>
        <p>
          <em>The following has been informed by numerous conversations, among which some with <a href="https://matteocapucci.eu/david-spivak/">David Spivak</a>, Nima Mothamed, <a href="https://matteocapucci.eu/david-jaz-myers/">David Jaz Myers</a>, and <a href="https://matteocapucci.eu/nathaniel-virgo/">Nathaniel Virgo</a>.</em>
        </p>
        <p>
	Argmax is my nemesis. It keeps popping up everywhere in my work and yet escapes a structuralist treatment. It has very bad formal properties and thus it’s hard to justify (which means saying argmax is ‘just’ a blah in a blah). That makes me mad!
</p>
        <p>
	For now, let’s work in <code>\bf  Cat</code>. Consider a functor <code>f:X \to  V</code> therein (typicially, <code>f:X \to  <code>\mathbb {R}</code></code> where <code>X</code> is discrete). An object <code>x^* \in  X</code> is in the argmax iff <code>fx^*</code> is “terminal in the image of <code>f</code>”, i.e. iff for all <code>x \in  X</code>, there exists a (perhaps unique) <code>fx \to  fx^*</code>.
</p>
        <p>
	If one tries to read this as a universal property they are going to get all dizzy. The universal quantification ranges over objects of <code>X</code> but the invoked comparison maps are in <code>V</code>. This is weird.
</p>
        <p>
	One can frame <code>\argmax </code> as follows: consider the map <code>f:X \to  <code>\mathbb {R}</code></code> as a map of sets, and use it to pullback the order structure on <code><code>\mathbb {R}</code></code> onto <code>X</code>. This makes <code>X</code> look like the ‘level sets’ of <code>f</code> since <code>x \leq  x' \iff  fx \leq  fx'</code>, and thus in particular <code>x \cong  x' \iff  fx = fx'</code>. Then <code>\argmax  f</code> is the isomorphism class of terminal objects in <code>X</code>.
</p>
        <p>
	‘Pulling back’ the order structure can be seen in various way. One is as a literal cartesian lift for the forgetful functor <code>U:\bf  Ord \to  Set</code> from orders to sets, which turns out to be a fibration. Indeed, the level sets construction is literally the functor <code>\mathsf {lvl} : {\bf  Set}/ U \to  \bf  Ord</code> defining a cleavage for this fibration. Moreover <code>{\bf  Set}/U</code> has a neat interpretation as ‘sets with utility’, and thus <code>\mathsf {lvl}</code> is a case of very natural and concrete construction (sending a utility function to its induced preference relation) having a decent universal property (being a right adjoint, being a cartesian lift functor, etc.).
</p>
        <p>
	That’s already quite cool! Let’s make this cooler by summoning equipments.
</p>
        <p>
	The operation of taking level sets can also be seen as follows: given a functor <code>f:X \to  V</code>, one factors it as <code>X \to  \mathsf {lvl}f \to  V</code> where the first is a bijective-on-objects functor and the second is a fully-faithful functor (think: bijective-on-morphisms functor). Formally, this factorization comes from the a vertical-cartesian factorization system on <code>\bf  Cat</code> induced by its fibration of objects <code>\rm  Ob: \bf  Cat \to  Set</code>, which in turn is just an extension to categories of the fibration <code>U</code> above.
</p>
        <p>
	One can see this factorization in yet another way, by approaching <a href="https://matteocapucci.eu/categories-are-monads-in-spans/">categories as monads in spans</a>. Recall that functors are tight maps in that equipment, thus in particular squares
  
    
      

      <figure><img src="https://matteocapucci.eu/0e0c27e2c640fa7df69fef046f1a5f31.svg" /></figure>
    
    
	where <code>X_0,V_0</code> are the set of objects of <code>X</code> and <code>V</code> respectively, <code>X_1</code> and <code>V_1</code> the spans of morphisms, and <code>f_0</code> and <code>f_1</code> are similarly the action of <code>f</code> on objects and maps.
</p>
        <p>
	Now by being an equipment, we know this square has to factor along a restriction, thus yielding:
  
    
      

      <figure><img src="https://matteocapucci.eu/a6c429d8a17923a7d72c38dc523ef72e.svg" /></figure>
    
    
	and this is basically the <a href="https://ncatlab.org/nlab/show/bo-ff+factorization+system">bo/ff</a> factorization of <code>f</code> we had above. In fact it’s exactly the same since the 2-cell I labeled <code>\text {cart}</code> is the cartesian lift of the ‘category structure’ on <code>V</code> along the map of objects <code>f_0</code>.
</p>
        <p>
	But we can do something a bit different now. Let’s switch to think about this in the equipment <code>\bf  \mathbb  Cat = \mathbb  Mod(\mathbb  Set)</code> of categories, functors, profunctors and transformations. There, we can restrict the identity profunctor on <code>V = (V_0, V_1)</code> along the entire functor <code>f</code>, yielding:
  
    
      

      <figure><img src="https://matteocapucci.eu/97d7af050bc7172632333be4eb9371b4.svg" /></figure>
    
    
	Now <code>V(f,f)</code> is <em>extra structure on the category <code>X</code></em>: it’s a <a href="https://www.epatters.org/post/algebras-are-promonads/">promonad</a> on it, thus the data of new morphisms on <code>X</code>, namely the ones it would have ‘in <code>V</code>’. This seems useful to talk about properties of elements of <code>X</code> with respect to morphisms between their <code>f</code>-images!
</p>
        <p>
	Besides, here’s a crucial insight: <strong><code>\argmax  f</code> should really be thought as a predicate on <code>X</code></strong>. For instance, consider things like <code>\mathrm {softmax}</code> which assign a ‘maximality score’ to all things in a set: this smells a lot like <em>literally</em> argmax but seen as a ‘generalized predicate’ <code>X \to  [0,1]</code>. And even without resorting to generalization, in a constructive setting <a href="https://github.com/mattecapu/agda-diegetic-games/blob/main/Game.agdaL16">one ends up</a> encoding <code>\argmax  f</code> as the <code>X</code>-indexed type which assign to each <code>x</code> the type of proofs of its argmaximality, in a classic proposition-as-types move.
</p>
        <p>
	So here’s a conjecture (I’m sure duality is gonna bite me): take the following lift in <code>\bf  Prof</code>, the bicategory (you could probably swap if for the equipment above but I just don’t know how would that work):
  
    
      

      <figure><img src="https://matteocapucci.eu/7d823879fcbfe8098a1d934358bf76da.svg" /></figure>
    
    
	By duality, one can compute this as a Kan extension, specifically (I’m stealing this idea from <a href="https://ncatlab.org/nlab/show/Kan+lift">the nLab</a>):
  <code>\argmax  f = \mathsf {Rift}_1V(x^*) = \int _{x:X} (1(x) \to  V(fx,fx^*)) = \int _x V(fx, fx^*)</code>
	where we are considering profunctors <code>1 \nrightarrow  X</code> directly as copresheaves over <code>X</code>.
</p>
        <p>
	It’s not hard to convince oneself that the above formula corresponds to defining:
  <code>x^* \in  \argmax  f \iff  \forall  x\in  X,\ fx \leq  fx^*.</code>
	Clearly, had we setup the above in the <code>2</code>-<code>\bf  \mathbb  Prof</code> (aka <code>\bf  \mathbb  Mod(\mathbb  Rel)</code>), this is exactly what we would have found!
</p>
        <p>
	Moreover, in this fashion, we can also describe constrained optimization problems. Say you have <code>P:X \to  \bf  2 \hookrightarrow  Set</code> describing the predicate which constrains the optimization. This is again a copresheaf <code>1 \nrightarrow  X</code> (in fact a subsingleton), and lifting <code>V(f,f)</code> against it you get:
  <code>(\argmax _P f )(x^*)= \int _x (P(x) \to  V(fx,fx^*)).</code></p>
        <p>
	Notice we can also talk about whether an object <code>x^* \in  X</code> ‘is in <code>\argmax  f</code>’: this categorifies to asking <em>how much</em> it is in <code>\argmax  f</code>, and is answered by <a href="https://matteocapucci.eu/on-elements-in-category-theory/">checking membership</a> categorically, i.e. by mapping from <code>X(x^*,-)</code> in <code>{\bf  Psh}(X)</code>, which by Yoneda simply returns the value of <code>\argmax _P f</code> at <code>x^*</code>.
	When working in <code>\bf  \mathbb  Mod(\mathbb  Rel)</code>, the only possible answers are given by the only possible degrees of ‘being’ in <code>\argmax  f</code>: either <em>not at all</em> (<code>\bot </code>) or <em>completely</em> (<code>\top </code>), whereas in other settings one will get different kinds of answers (e.g. in <code>\bf  \mathbb  Prof</code>, one gets either <code>\varnothing </code> or a set of witnesses that “<code>fx \leq  fx^*</code>”, actually the hom-set <code>fx\to  fx^*</code>).
</p>
        <p>
	Assuming this stuff is right, I can finally say: <strong>argmax is defeated</strong>! ...or is it?
</p>
        <p>
	Let’s check what happens when we compute <code>\argmax  f</code> in the equipment of <code>[0,1]</code>-enriched categories, where <code>([0, 1], \leq , {\cdot }, \multimap )</code> is the base of enrichment, with <code>a \multimap  b =e ^{b\ \dot - a} = \min (e^b/e^a, 1)</code>.
	Given <code>f:X \to  [0,1]</code>, we have
  <code>(\argmax  f)(x^*) = \int _x 1(x) \multimap  (fx \multimap  fx^*) = \dfrac {fx^*}{\int ^x fx}</code>
	Despite the suggestive notation, <code>\int ^x fx</code> is actually the maximum of <code>f</code>. If <code>f=e^{-u}</code>, where <code>e^{-(-)}</code> is base change <code>[0,\infty ] \to  [0,1]</code>, one would expect <code>\argmax  f</code> to be <code>\mathrm {softmax}\ u</code>, but the normalization is somehow wrong.
</p>
        <p>
	So it appears there is a room for another chapter in the battle against <code>\argmax </code>!
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Reflections from factorization systems</title>
    <published>2024-01-04T00:00:00Z</published>
    <updated>2024-01-04T00:00:00Z</updated>
    <author>
      <name>Matteo Capucci</name>
      <uri>https://matteocapucci.eu/matteo-capucci/</uri>
    </author>
    <link rel="alternate" type="text/html" href="https://matteocapucci.eu/reflections-from-factorization-systems/" />
    <id>https://matteocapucci.eu/reflections-from-factorization-systems/</id>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p><em>This post originally appeared on <a href="https://localcharts.org/13111-reflections-from-factorization-systems.html">LocalCharts</a></em>.
</p>
        <p>
  I’m writing this post to deconfuse myself and productively order my notes on this topic, as well as popularizing a topic in category theory that doesn’t get much attention outside the categorical algebra literature (or at least, that’s how it seems from where I’m sitting!).
</p>
        <p>
  Now, let’s start with a definition:
</p>
        <section>
          <p>
    A <strong>factorization system</strong> on a category <code>\cal  X</code> is a pair of subcategories <code>(\cal  L, R)</code> (the <em>left</em> class and the <em>right</em> class) such that
    <ol><li>Both <code>\cal  L</code> and <code>\cal  R</code> contain all isomorphisms,</li>
      <li>
        “<code>\cal  X =\cal  L ;\cal  R</code>”: Every morphism in <code>\cal  X</code> factors as a morphism of <code>\cal  L</code> followed by a morphism in <code>\cal  R</code> and this factorization is unique up to unique isomorphism:
        
    
      

      <figure><img src="https://matteocapucci.eu/4e4ae2083bd8e3e57538f4eb06ae9f21.svg" /></figure></li></ol></p>
        </section>
        <p>
  We denote left morphisms as <code>\twoheadrightarrow </code> and right ones as <code>\rightarrowtail </code>. People often denote the right class as <code>\cal  E</code> and the left class as <code>\cal  M</code>, though epi-mono <em>do not form a factorization system in general</em> (they do in balanced categories, like pretopoi). But having in mind surjections and injections in <code>\bf  Set</code> is a good enough intuition for factorization systems, and in fact the middle object in the factorization of a morphism is usually called the <strong>image</strong>:
  
    
      

      <figure><img src="https://matteocapucci.eu/234c584c430d729211b1be56bc5a5d7b.svg" /></figure>
    
    
  More examples can be found in <a href="https://ncatlab.org/joyalscatlab/published/Factorisation+systems">Joyal’s catlab</a>.
</p>
        <p>
  As often happens in category theory, while we defined the factorization of a morphism as something that just happens to exists, factorization can be given as an actual functor, specifically a section of the composition functor <code>\_;\_ : \cal  C^{\to \to } \to  C^\to </code>. It sends an arrow to its factorization. Conversely, given such a functor one can obtain a factorization system (<code>\cal  L</code> is the subcategory of morphisms whose factorizations look like <code>\to  =</code>, and viceversa for <code>\cal  R</code>). In fact, a section of the identity <code>1:\cal  C \to  C^\to </code>, sending a morphism to its image, <a href="http://www.sciencedirect.com/science/article/pii/002240499390171O">suffices</a>, provided it satisfies the axioms of a (normal) pseudoalgebra for the 2-monad <code>(-)^\to  : \bf  Cat \to  Cat</code>. This is cool! It means factorization systems are an algebraic structure on categories, and makes them easily generalizable to other ambient 2-categories (notice, <code>(-)^\to </code> is a 2-monad on any 2-category with <code>\to </code>-powers!)
</p>
        <p>
  Another cool fact about factorization systems, which justifies writing <code>\cal  X = L;R</code>, is that they literally present <code>\cal  X</code> as a ‘composition’ of two categories when we think of them as <a href="https://matteocapucci.eu/categories-are-monads-in-spans/">monad in spans</a>. This is an old idea of <a href="https://linkinghub.elsevier.com/retrieve/pii/S0022404902001408">Rosebrugh and Wood</a>, and has some caveats.
</p>
        <p>
  I’m starting to accumulate facts that I couldn’t prove without the most important property of factorization systems:
</p>
        <section>
          <p>
    The left and right class are <em>orthogonal</em> (denoted <code>\cal  L \perp  R</code>), meaning every square as below (left side is left, right side is right) has a unique diagonal fill-in:
    
    
      

      <figure><img src="https://matteocapucci.eu/9a2660f954e37729815d49f9c83bc162.svg" /></figure></p>
          <p><strong>Proof</strong>. We factor the top and bottom morphism, and get a unique isomorphism between the respective images. The red composite is the sought diagonal fill-in, and it is unique because each of its component is unique:
    
    
      

      <figure><img src="https://matteocapucci.eu/5e51aa68afddd6959abb2ead2c77dfb9.svg" /></figure></p>
        </section>
        <p>
  This property means that we have simultaneous extensions along left morphisms and lifts along right ones. Note, however, that in general we can’t <em>just</em> extend along a left morphism or <em>just</em> lift along a right one, since we need a full square to invoke orthogonality!
</p>
        <p>
  Orthogonality is so important that factorization systems are often called <a href="https://ncatlab.org/nlab/show/orthogonal+factorization+systems"><em>orthogonal</em> factorization systems</a>. In fact, orthogonality can even replace uniqueness of factorization in the definition: a pair of subcategories that can factor every morphism (possibly non-uniquely) and are orthogonal is automatically a factorization system.
</p>
        <p>
  Orthogonality can be used to prove all the facts I mentioned above. For instance, one can show <code>\cal  L \cap  R</code> is all and only the isomorphisms of <code>\cal  X</code>, a fact we evince by contemplating the following square built for <code>f \in  \cal  L \cap  R</code>:
  
    
      

      <figure><img src="https://matteocapucci.eu/07002dbfd51c7f58a6642f67907485f1.svg" /></figure>
    
    
  This explains why epi-mono is factorization system iff the category is balanced: not all epic and monic morphisms are isos in general!
</p>
        <p>
  It also shows a way to overcome such a limitation. Namely, if one has a class of morphisms <code>\cal  R</code> they really like (say, monomorphisms), they can match it with <code>^\perp \cal  R = \{\ell  \in  \cal  X^\to  \mid  \forall  r \in  R, \ell  \perp  r\}</code> to get a factorization system, with the caveat that they might need to replace <code>\cal  R</code> with <code>\cal  L^\perp </code> after the fact (but then that’s it—I’m describing a closure operation on pairs of classes of morphisms, see <a href="https://matteocapucci.eu/cassidy-1985-reflective/">Reflective subcategories, localizations and factorizationa systems</a>).
  I hope the <code>(-)^\perp </code> and <code>^\perp (-)</code> notations are self-describing: the first means ‘all things that have the diagonal-fill in property on squares where morphisms in the argument appear on the left side’, and dually for the other one.
</p>
        <p>
  So, for instance, (epi, mono) isn’t a factorization system but in a regular category (strong epi, mono) is, where a strong epi is, by definition, something left ortoghonal to all monomorphisms!
</p>
        <p>
  Finally, orthogonality is so cool it can stand by itself. Thus one might have <code>\cal  L = {^\perp  R}</code> and <code>\cal  R = L^\perp </code> without <code>(\cal  L, R)</code> forming a factorization system! This is called a <em>prefactorization system</em>, and it’s a factorization system without the existence part of the factorization.
</p>
        <h2>Reflections</h2>
        <p>
  One of the nicest consequences of having a factorization system is to get a reflective subcategory. I believe this is one of the most beautiful theorems in category theory!
</p>
        <p>
  Let’s start with a category <code>\cal  X</code> with a terminal object <code>1</code> and a factorization system <code>(\cal  L, R)</code>. Then we can define the full subcategory <code>\cal  R/1 \subseteq  X</code> given by those objects whose terminal map <code>!_X:X \rightarrowtail  1</code> is in the right class. These are called <em>fibrant</em>, generalizing a terminology from model categories.
</p>
        <p>
  The archetypal example is subterminal objects, i.e. those objects for which the terminal map is mono, which are thus fibrant for the (strong epi, mono) factorization system.
</p>
        <p>
  What’s interesting is, even though an object isn’t fibrant, we can always factor its terminal map <code>!_X:X \to  1</code> as <code>X \twoheadrightarrow  \mathrm {im} !_X \rightarrowtail  1</code>, thus yielding another object <code>rX := \mathrm {im} !_X</code> which <em>is</em> fibrant. This is called the <em>fibrant replacement</em> of <code>X</code>, again abusing terminology from model categories, or its <em>reflection</em>, foreshadowing the result I’m about to expound.
</p>
        <p>
  It’s easy to see that, by orthogonality, fibrant replacement is functorial, and in fact, left adjoint to the inclusion of fibrant objects:
  
    
      

      <figure><img src="https://matteocapucci.eu/042c2cb802ece1a0e006e6a3669cf052.svg" /></figure>
    
    
  In particular, this adjunction is a <em>reflection</em> meaning the counit is the identity. This can be noticed either by abstract nonsense (the right adjoint is fully faithful) or by concrete nonsense (clearly <code>rX = X</code> if <code>X</code> is already fibrant).
</p>
        <p>
  On other hand, the unit is defined as a byproduct of the factorization we used to construct the fibrant replacement, and thus we define <code>\rho _X : X \twoheadrightarrow  rX</code> to be it. Notice all its components are, by definition, left maps.
</p>
        <p>
  We can then prove that <code>r</code> is left adjoint by proving that <code>\rho  : 1_{\cal  X} \Rightarrow  r</code> is a universal arrow, that is, for every object <code>X:\cal  X</code> and map <code>f:X \to  X'</code> with <code>X'</code> fibrant there is a unique factorization of <code>f</code> through <code>\rho _X</code>:
  
    
      

      <figure><img src="https://matteocapucci.eu/90063a48b2d21becfb14f00bbf2957a1.svg" /></figure>
    
    
  and we can get such a map by invoking ortoghonality for the following square (<code>!_{X'}</code> is right because we assumed <code>X'</code> to be fibrant):
  
    
      

      <figure><img src="https://matteocapucci.eu/0c1d65e65ddf737162600c060c2bd608.svg" /></figure></p>
        <p>
  Done! Isn’t that beautiful?
</p>
        <p>
  In <a href="https://matteocapucci.eu/cassidy-1985-reflective/">Reflective subcategories, localizations and factorizationa systems</a>, a lot of attention is devoted to obtaining a converse to this fact, i.e. obtain a factorization system from a reflective subcategory. In general, this cannot be done (one only gets a <em>pre</em>factorization system), and there is only a Galois connection (which is, amusingly, a reflection again!) between the poset of reflective subcategories of <code>\cal  X</code> and the poset of factorization systems.
</p>
        <p>
  They thus prove two theorems. One characterizes those categories for which the Galois connection is actually an equivalence—these are the ‘<a href="https://ncatlab.org/nlab/show/M-complete+category">finitely well-complete</a>’ ones, which is a condition slightly weaker than finitely complete and well-powered. The other theorem characterizes the <a href="https://ncatlab.org/nlab/show/fixed+point+of+an+adjunction">fixed points</a> of the Galois connection, hence those factorization systems that do arise from a reflective subcategory, and these are the ones for which left left class satisfies the <em>left</em> cancellation property:
  <code>g ; f \in  \cal  L, f \in  \cal  L \implies  g \in  \cal  L.</code>
  (It’s a fact of life that all factorization systems have the left class satisfy the <em>right</em> cancellation property, which is exactly like the above but with <code>g</code> and <code>f</code> swapped.)
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Tambara modules are modules</title>
    <published>2023-12-27T00:00:00Z</published>
    <updated>2023-12-27T00:00:00Z</updated>
    <author>
      <name>Matteo Capucci</name>
      <uri>https://matteocapucci.eu/matteo-capucci/</uri>
    </author>
    <link rel="alternate" type="text/html" href="https://matteocapucci.eu/tambara-modules-are-modules/" />
    <id>https://matteocapucci.eu/tambara-modules-are-modules/</id>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p><em>This post originally appeared on <a href="https://localcharts.org/12745-tambara-modules-are-modules.html">LocalCharts</a></em>.
</p>
        <p>
	There is a story I keep forgetting so I’d like to write it up here to fix it in my brain.
</p>
        <p>
	Tambara modules are profunctors <code>P: \cal  C \nrightarrow  D</code> between <code>\cal  M</code>-actegories <code>\cal  C, \cal  D</code> that are ‘lax equivariant’: they are equipped with a <em>strength</em> (here <code>mc</code> and <code>md</code> denote the action of <code>m</code> on <code>c</code> and <code>d</code> respectively)
	<code>\varsigma _{c,d}^m : P(c,d) \to  P(mc, md), \qquad  m:{\cal  M},\ c: {\cal  C},\ d:{\cal  D};</code>
	which is dinatural in <code>m</code> and natural in <code>c</code>, and satisfies the laws you expect to satisfy relative to the monoidal structure on <code>\cal  M</code>.
</p>
        <p>
	It has been proven that Tambara modules structures correspond to algebra structures on <code>P</code> for a monad <code>\Psi </code> on <code>{\bf  Prof}(\cal  C, D)</code>. This monad is described by Pastro and Street in <a href="https://arxiv.org/abs/0711.1859"><em>Doubles for monoidal categories</em></a>:
	<code>\Psi  P(c,d) = \int ^{m':\cal  M}\int ^{c':\cal  C,d' :D} {\cal  C}(c,m'c') \times  P(c',d') \times  {\cal  D}(m'd',d).</code>
	We can visualize the right hand side in this definition using Mario Roman’s intuition that coends describe diagrams, thus understanding that <code>\Psi </code> freely wraps <code>P</code> in combs with residual in <code>\cal  M</code>.
</p>
        <p>
	Now the fact is, strengths for <code>P</code> corresponds to a (unital and associative) algebra <code>\Psi  P \Rightarrow  P</code>. But where the heck does <code>\Psi </code> come from?
</p>
        <p>
	In Pastro and Street’s paper it comes as a the left adjoint of a far more pedestrian comonad, of which Tambara modules are coalgebras. But there’s also another cute way to see it, which motivates calling Tambara modules ‘modules’. IIRC, this is something <a href="https://matteocapucci.eu/dylan-braithwaite/">Dylan Braithwaite</a> noticed, using something I dreamt up almost as a joke when writing <a href="https://matteocapucci.eu/work-0016/">the big actegories paper</a>.
	We took it further than what I will do here and sent <a href="http://dylanbraithwaite.github.io/ct2023">a poster</a> to this year’s CT conference.
</p>
        <p>
	The thing I dreamt up is a form of Day convolution for co/presheaves over actegories. Day convolution famously extends a monoidal structure on a category to one on its category of co/presheaves. If instead your base category <code>\cal  X</code> is an <code>\cal  M</code>-actegory, then you can make <code>[\cal  X, \bf  Set]</code> a <code>[\cal  M, \bf  Set]</code>-actegory, where <code>[\cal  M, \bf  Set]</code> is equipped with Day convolution. I called this extended action <em><strong>Day convolaction</strong></em>. You can call it ‘the free extension’ of the action, or still ‘Day convolution’.
</p>
        <p>
	Defining it is simple, because at the end of the <em>day</em>, Day convolution is just a left Kan extension, and these can be computed with a coend formula if you’re lucky enough to land in a (very) cocomplete category.
	 Thus we can perform the same trick (which Bartosz Milewski spelled out <a href="https://mathstodon.xyz/@BartoszMilewski/111658326388484708">here</a>) and define the action of a copresheaf <code>M:\cal  M \to  \bf  Set</code> on a copresheaf <code>X:\cal  X \to  \bf  Set</code> as follows:
	<code>MX(x) = \int ^{m' : \cal  M} \int ^{x': \cal  X} M(m') \times  X(x') \times  {\cal  X}(m'x', x).</code>
	This is freely putting together all things in <code>M</code> and <code>X</code> by using all possible ways to map into <code>x</code> from a given <code>m':\cal  M</code> and <code>x':\cal  X</code>.
</p>
        <p>
	As with Day convolution, if we restrict to corepresentables we recover the action we started with (by doing Yoneda reduction twice):
	<code>{\cal  M}(m, -){\cal  X}(x,-) = \int ^{m'}\int ^{x'} {\cal  M}(m, m') \times  {\cal  X}(x, x') \times  {\cal  X}(m'x', -) \cong  {\cal  X}(mx,-).</code>
	Anyway, back to Tambara modules. One nice things about profunctors is that you can pretend they are just copresheaves if you really want, since a profunctor <code>P: \cal  C \nrightarrow  D</code> is indeed a copresheaf on <code>\cal  X:= C^{\rm  op} \times  D</code>.
	Moreover, if <code>\cal  C</code> and <code>\cal  D</code> are both left <code>\cal  M</code>-actegories then <code>\cal  C^{\rm  op} \times  D</code> is a left <code>\cal  M^{\rm  op} \times  M</code>-actegory, in the way you expect (componentwise).
</p>
        <p>
	But then <code>{\bf  Prof}(\cal  C, D) \cong  [C^{\rm  op} \times  D, \bf  Set]</code> receives an action from <code>[\cal  M^{\rm  op} \times  M, \bf  Set] \cong  Prof(\cal  M,M)</code>, by Day convolaction. If <code>M:\cal  M \nrightarrow  M</code> and <code>P:\cal  C \nrightarrow  D</code>, we can unravel the above definition to get the a definition of <code>MP</code>:
	<code>MP(c,d) := \int ^{m',n':\cal  M} \int ^{c':\cal  C, d': D} M(m',n') \times  P(c',d') \times  {\cal  C^{\rm  op} \times  D}((m',n')(c',d'), (c,d))\\ = \int ^{m',n'} \int ^{c',d'} M(m',n') \times  P(c',d') \times  {\cal  C}(c, m'c') \times  {\cal  D}(m'd',d).</code></p>
        <p>
	This starts looking a bit like the definition of <code>\Psi </code>, doesn’t it?
</p>
        <p>
	Except there we don’t have an <code>M</code> around, just a <code>P</code>. If we fix <code>M = {\cal  M}(-,=)</code>, the identity profunctor on <code>\cal  M</code>, we get:
	<code>( {\cal  M}(-,=)P)(c,d) \cong  \int ^{m'} \int ^{c',d'} {\cal  C}(c, m'c') \times  P(c',d') \times  {\cal  D}(m'd',d),</code>
	by Yoneda reduction <code>\int ^{n'} {\cal  M}(m',n') \times  {\cal  D}(n'd',d) \cong  {\cal  D}(m'd',d)</code>. And <em>this</em> is exactly <code>\Psi  P</code>!
</p>
        <p>
	What’s happening here is that whenever <code>M</code> is a monoid in the monoidal category which acts on a category, then <code>M-</code> becomes a monad on the actee–in fact, the ‘free <code>M</code>-module monad’. This is the microcosm principle of actions: the most general habitat to talk about a monoid acting on an object is a monoidal category (where monoids live) acting on a category (where objects live).
</p>
        <p>
	In our case, we’ve chosen a monoid, viz. <code>\cal  M(-,=)</code>, in <code>{\bf  Prof}(M,M)</code> considered with its Day convolution monoidal structure (which, by a classical result of Day, means it’s a <a href="https://arxiv.org/abs/2207.00852">monoidal profunctor</a>), thus we can conclude that <code>\Psi  = \cal  M(-,=)-:{\bf  Prof}(\cal  C, D) \to  {\bf  Prof}(C,D)</code> is a monad, and in fact the ‘free <code>\cal  M(-,=)</code>-module’ monad, thus proving that Tambara modules are nothing but <code>\cal  M(-,=)</code>-modules.
</p>
        <p>
	This is quite fun because it shows also that there’s an extra degree of freedom in the definition of Tambara modules, i.e. what they are a module of. Clearly the identity profunctor on <code>\cal  M</code> is only one of many possible examples of monoidal profunctors. This is the subject of the aforementioned poster Dylan presented at CT23: you can consider arbitrary monoidal profunctors <code>\cal  M \nrightarrow  M</code> instead of the identity one, and actually you can even consider arbitrary monoidal profunctors <code>\cal  M \nrightarrow  N</code> between monoidal categories. These and bimodules thereof organize in a triple category which, speculatively, sits inside the triple category Christian Williams considered in <a href="https://color-logic.io/">his thesis</a>.
</p>
        <p>
	This brings the generalization of Tambara modules from monoidal categories to actegories to a natural level of completion. It also has repercussions on the theory of optics, but that’s maybe for another time!
</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Actions of categories</title>
    <published>2023-12-03T00:00:00Z</published>
    <updated>2023-12-03T00:00:00Z</updated>
    <author>
      <name>Matteo Capucci</name>
      <uri>https://matteocapucci.eu/matteo-capucci/</uri>
    </author>
    <link rel="alternate" type="text/html" href="https://matteocapucci.eu/actions-of-categories/" />
    <id>https://matteocapucci.eu/actions-of-categories/</id>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p><em>This post originally appeared on <a href="https://localcharts.org/11643-actions-of-categories.html">LocalCharts</a></em>.
</p>
        <p>
  In <a href="https://matteocapucci.eu/categories-are-monads-in-spans/">my last post</a> I explained how categories can be seen as algebraic structures in the bicategory of spans, namely as monads. This is already a neat fact in itself, and, as I explained there, allows to see various flavours of categories in the same light.
</p>
        <p>
  Today I want to show you something else that falls out of this cats-are-monads idea, namely that cats can act.
</p>
        <p>
  When you consider a category as a monad in <code>\bf  Span(Set)</code>, then you can ask what is an algebra of said monad. The notion of algebra of a monad is mostly known for when the monad is in <code>\bf  Cat</code>, but it makes sense in every bicategory. The only difference is, these are called modules rather than algebras:
</p>
        <section>
          <p>
    Let <code>\cal  K</code> be a bicategory, and <code>B: \cal  K</code> be an object equipped with an endomorphism <code>T:B \to  B</code>. Then a <strong>left module</strong> [0] of <code>T</code> on a morphism <code>f:A \to  B</code> is a 2-cell <code>\alpha  :Tf \Rightarrow  f</code> (called the <strong>action</strong>):
    
    
      

      <figure><img src="https://matteocapucci.eu/588eca47f5002e34e2e61f53c8181b1a.svg" /></figure></p>
        </section>
        <p>
  It does look like an algebra of a monad in the usual sense, doesn’t it? In fact if <code>\cal  K= \bf  Cat</code> and <code>f:1 \to  B</code> is a functor, which thus picks an object <code>b</code> in <code>B</code>, then <code>\alpha  : Tf \Rightarrow  f</code> corresponds exactly to a familiar map <code>Tb \to  b</code> in <code>B</code> [1].
</p>
        <p>
  When <code>T</code> is a not just an endomorphism, but a monad, then an action of <code>(T, \eta , \mu )</code> is an action of <code>T</code> plus two compatibility axioms:
  
    
      

      <figure><img src="https://matteocapucci.eu/afd198051ace1b22e82e39a021a2327a.svg" /></figure>
    
    
  which are stating that <code>\alpha </code> respects multiplication and unit of the monad, not unlike what algebras of monads in <code>\bf  Cat</code> do.
</p>
        <p>
  Now we are ready to instantiate this definition in <code>\bf  Span(Set)</code>: what is the action of a category <code>\mathcal {X}</code>, given as a monad <code>(X \xleftarrow {s} M \xrightarrow {t} X,\ i,\ {;})</code>?
</p>
        <p>
  Well, it’s a span <code>Y \xleftarrow {f} S \xrightarrow {g} X</code>, together with a map of spans:
  
    
      

      <figure><img src="https://matteocapucci.eu/9a3a125a9803cdae6b567742c18fe5e0.svg" /></figure>
    
    
  which, using the notation <code>s:y \leadsto  x</code> to denote an element <code>s \in  S</code> such that <code>f(s)=y</code> and <code>g(s)=x</code>, and the notation <code>m:x \to  y</code> for morphisms in <code>\cal  X</code> <a href="https://matteocapucci.eu/categories-are-monads-in-spans/">we introduced last time</a>, can be written as:
  <code>\alpha  (y \overset {s}\leadsto  x, x \overset {m}\to  x') : y \leadsto  x'.</code>
  This action is akin to the scalar multiplication of a module over a ring (indeed, both are instances of the general concept of ‘module’), except for the extra checks on which squiggly arrows in <code>S</code> can be multiplied by which morphisms of <code>\cal  X</code>: if they match on their boundary, then it’s fine, and a morphism <code>m</code> acts by ‘extension’ on <code>s</code>. In practice, one can reason very well by just forgetting about these checks and assuming that whenever you write <code>\alpha (s, m) =: sm</code>, <code>s</code> and <code>m</code> are indeed ‘composable’.
</p>
        <p>
  With this notational convention, the laws that make <code>\alpha </code> a module over the <em>monad</em> <code>\cal  X</code> are pretty pedestrian:
  <code>s1 = s, \quad  (sm)n = s(mn)</code>
  where <code>mn := m ; n</code>.
</p>
        <p>
  What is then <code>(Y \xleftarrow {f} S \xrightarrow {g} X, \alpha )</code> in category-land? It is ‘half’ of a profunctor, i.e. a profunctor from the discrete category <code>\Delta  Y</code> to <code>\cal  X</code>. That’s why I’ve been denoting the elements of <code>S</code> as if they were heteromorphisms. We get full profunctors if we consider <strong>bimodules</strong> between two categories, seen as monads in <code>\bf  Span(Set)</code>.
</p>
        <section>
          <p>
    A <strong>bimodule</strong> between monads <code>(S, \eta ', \mu ')</code> on <code>A</code> and <code>(T, \eta , \mu )</code> on <code>B</code> is a 1-cell <code>f:A \to  B</code> together with a left <code>T</code>-action <code>\alpha </code> and a right <code>T</code>-action <code>\beta </code> which commute with each other:
    
    
      

      <figure><img src="https://matteocapucci.eu/d6374601fd15e9c4bb224eb5301d2cf5.svg" /></figure></p>
        </section>
        <p>
  For the case of <code>\bf  Span(Set)</code>, a right action of a monad <code>{\cal  Y} = (Y \xleftarrow {s'} N \xrightarrow {t'} X,\ i', \ {;}')</code> on a span <code>Y \xleftarrow {f} S \xrightarrow {g} X</code> looks exactly like a left action except morphisms of a category act on the left (!):
  <code>\beta  (y' \overset {n}\to  y, y \overset {s}\leadsto  x) : y' \leadsto  x</code>
  and we denote this again as juxtaposition (e.g. the above defines <code>ns</code>).
</p>
        <p>
  Then a bimodule is a span such that
  <code>(ns)m = n(sm) = nsm.</code>
  This makes the data of a bimodule that of a profunctor between the categories <code>\cal  Y</code> and <code>\cal  X</code> corresponding to the monads acting on the left and right. The profunctors <code>S: \cal  Y \nrightarrow  X</code> is defined as <code>S(y,x) = \{y \leadsto  x\}</code>, and its bifunctoriality corresponds precisely to the structure and laws of the bimodule we defined it from!
</p>
        <p>
  This should clarify why some people call profunctors bimodules: because they are!
</p>
        <p>
  I really like this ‘algebraic’ perspective on profunctors, because it allows one to make categories <em>do</em> things on other things. Elements of a profunctor are often considered morphisms too, just straddling categories. But it is useful to consider them to be ‘objects’ in their own right, on which morphisms of two categories can act either covariantly or contravariantly. This distinction between ‘scalar’ morphisms and ‘object’ morphisms, is as useful as the distinction between scalars and vectors in linear algebra, and I hope to make my point clearer in further posts.
</p>
        <h3>Footnotes</h3>
        <ol><li>
    There’s a terminological issue here when talking about ‘left and right modules’, since there’s a problem with that when it comes to denoting composition. Left and right in ‘left/right module’ refers to the traditional, non-diagrammatic composition. Hence when we draw diagrams it looks off. In this post I’ll focus on modules in <code>\bf  Span(Set)</code> where the two notions are basically the same, but in general they are not: in categories, left modules for a monad are algebras in the classical sense, while right modules are free algebras!
  </li>
  <li>
    The fact that everything interesting about the algebras of an endofunctor in <code>\bf  Cat</code> is captured by restricting to those morphisms into <code>A</code> with domain either the walking object <code>1</code> or the walking arrow <code>\downarrow </code> (try it: actions on a functor <code>{\downarrow } \to  A</code> correspond to morphisms of algebras in the usual sense) is due to the fact <code>\bf  Cat</code> is <a href="https://ncatlab.org/nlab/show/accessible+category">accessible</a>, i.e. everything is a colimit of those two objects. In fact what is a category but a (small) bunch of objects together with a (small) bunch of arrows between them? This is a fact akin to ‘sets are bunch of elements’, and why you only need to look at morphisms <code>1 \to  X</code> to know everything about a set <code>X</code>.
  </li></ol>
      </div>
    </content>
  </entry>
  <entry>
    <title>Categories are monads in spans</title>
    <published>2023-11-28T00:00:00Z</published>
    <updated>2023-11-28T00:00:00Z</updated>
    <author>
      <name>Matteo Capucci</name>
      <uri>https://matteocapucci.eu/matteo-capucci/</uri>
    </author>
    <link rel="alternate" type="text/html" href="https://matteocapucci.eu/categories-are-monads-in-spans/" />
    <id>https://matteocapucci.eu/categories-are-monads-in-spans/</id>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
<p><em>This post originally appeared on <a href="https://localcharts.org/11397-categories-are-monads-in-spans.html">LocalCharts</a></em>.
</p><p>
	One fact that gets thrown around a lot in category theory is that <em>categories are monads in spans</em>.
	 I considered this a weird fact for a long time, but then it slowly became an irreplaceable part of the way I think about categories.
</p><p><code>\bf  Span(Set)</code> is a bicategory, i.e. a category whose hom-sets are in fact hom-categories themselves (and whose composition is suitably weakened, but we won’t concern ourselves with that here). This is less scary than it might look. In the case of <code>\bf  Span(Set)</code>, the objects are sets <code>X, Y, \ldots </code>, the morphisms are functions <code>X \xleftarrow {f} S \xrightarrow {g} Y</code> (<code>S</code> being the <em>apex</em>, <code>X, Y</code> being the <em>feet</em> and <code>f,g</code> being the <em>legs</em>), and the morphisms between these are morphisms between the apexes that commute with the legs.
</p>
    
      

      <figure><img src="https://matteocapucci.eu/67b79bb71e670d703a6089ba9c2ccb2f.svg" /></figure>
    
    <p>
	Most importantly, these spans compose by pullback: given two composable spans <code>X \xleftarrow {f} S \xrightarrow {g} Y \xleftarrow {h} R \xrightarrow {k} Z</code>, we get a composite span <code>X \xleftarrow {p_Sf} S \times _Y R \xrightarrow {p_Rg} Z</code>, where <code>S \xleftarrow {p_S} S \times _Y R \xrightarrow {p_R} R</code> is the pullback of <code>h</code> and <code>g</code> over <code>Y</code>:
</p>
    
      

      <figure><img src="https://matteocapucci.eu/7911248c7877324958bbca6888c8a960.svg" /></figure>
    
    <p>
	Evidently, the identity span is the one whose legs are identities <code>X = X = X</code>.
</p><p>
	Now, to get a sense of what a ‘monad in <code>\bf  Span(Set)</code>’ is, and why it is a category, we first have to learn that a monad <em>in</em> a bicategory is nothing but a monoid in one of the endomorphism categories of said bicategory.
	Thus, in our case, we have to realize what a monoid in <code>{\bf  Span(Set)}(X,X)</code> is. First, recall that endomorphisms in a bicategory always form a monoidal category, where the monoidal product is given by composition.
	Thus a monoid in <code>{\bf  Span(Set)}(X,X)</code> is, first of all, a span <code>X \xleftarrow {s} M \xrightarrow {t} X</code> equipped with two morphisms:
	<ol><li>
			A <strong>unit</strong>:
			
    
      

      <figure><img src="https://matteocapucci.eu/4b9c74d8c8a0cb1df39a46174b325654.svg" /></figure></li>
		<li>
			A <strong>composition</strong>:
			
    
      

      <figure><img src="https://matteocapucci.eu/adb042f554e15f4ec0306b001788d09f.svg" /></figure></li></ol></p><p>
	We can reason about these operations using elements, not just because we are in sets, but because we can always do that if we are careful enough, meaning we use generalized elements.
	Also, a good way to reason about spans is to think that the apex is a set of things <em>indexed by</em> the feet. So in our case, chosen two elements <code>x,y \in  X</code>, we get a bunch of elements <code>m \in  M_{x,y} = \{m \mid  s(m) =x, t(m)=y\}</code>. So we see… we get a set of things for every two elements in <code>X</code>… if you squint a bit, you can think we are assigning hom-sets to pairs of objects of a category!
</p><p>
	Thus from now on, I’ll call elements of <code>X</code> ‘objects’ and elements of <code>M</code> ‘morphisms’. Moreover, I’ll denote an <code>m \in  M</code> as <code>m:x \to  y</code> when <code>s(m)=x</code> and <code>t(m)=y</code>. This motivates calling <code>s</code> and <code>t</code> the source and target maps of our wannabe category.
</p><p>
	With this notation, we see that <code>i(x) : x \to  x</code> and that the domain of <code>;</code> is, in fact, the set of composable maps <code>\sum _{y \in  X} \{x \xrightarrow {m} y \xrightarrow {n} z\}</code>. The big diagram defining <code>;</code> then can be summarized as follows:
	<code>(x \xrightarrow {m} y) ; (y \xrightarrow {n} z) = x \xrightarrow {m;n} z.</code>
	Thus, at least at the level of data, we are getting what we expect: a monad in <code>\bf  Span(Set)</code> is a set of objects and a set of morphisms, each with a source and target object, such that every object <code>x \in  X</code> has a distinguished identity morphism <code>i(x):x \to  x</code> and such that consecutive morphisms can be composed.
</p><p>
	It remains to state which properties do <code>i</code> and <code>;</code> respect, namely unitality and associativity.
	 The first means that composing with identity morphisms is a no-op, which in our notation means:
	<code>(x \xrightarrow {i(x)} x) ; (x \xrightarrow {m} y) = x \xrightarrow {m} y = (x \xrightarrow {m} y) ; (y \xrightarrow {i(y)} y)</code>
	and surely this is property of a category too.
	 The second means that composing morphisms is an associative operation, also true for categories:
	<code>((x \xrightarrow {\ell } y) ; (y \xrightarrow {m} z)) ; (y \xrightarrow {n} z) = x \xrightarrow {\ell ;m;n} z = (x \xrightarrow {\ell } y) ; ((y \xrightarrow {m} z) ; (y \xrightarrow {n} z)).</code>
	So the remarkable simplicity of monoids yields a very rich structure, that of a category, when interpreted in the right context (endomorphisms of <code>\bf  Span(Set)</code>). This is one of the tenets of category theory: complexity can be traded off between an object and the context we are defining it in.
</p><p>
	In fact, this very trick is used to define and relate different flavours of categories: just take monads in a suitable bicategory. I won’t delve into details, but I’ll just mention that internal categories and enriched categories can be obtained in this way, by replacing <code>\bf  Span(Set)</code> with, respectively, spans in a finitely complete category <code>\cal  E</code> and <code>\cal  V</code>-valued matrices for a suitably cocomplete monoidal category <code>\cal  V</code> [1]. The paper <a href="https://arxiv.org/abs/0907.2460">A unified framework for generalized multicategories</a> takes this even further, and gives a great breakdown of the kinds of categories one can get by simply taking monads in the right place. Among these: topological spaces, metric spaces, operads!
</p><h2>Footnotes</h2><ol><li><a href="https://matteocapucci.eu/jade-edenstar-master/">Jade Edenstar Master</a> is very passionate about double categories of matrices—check out <a href="https://arxiv.org/abs/2105.12905">her PhD thesis</a> if you want to learn about the magic things you can do with monads in matrices
	</li></ol>      </div>
    </content>
  </entry>
  <entry>
    <title>On elements in category theory</title>
    <published>2023-08-21T00:00:00Z</published>
    <updated>2023-08-21T00:00:00Z</updated>
    <author>
      <name>Matteo Capucci</name>
      <uri>https://matteocapucci.eu/matteo-capucci/</uri>
    </author>
    <link rel="alternate" type="text/html" href="https://matteocapucci.eu/on-elements-in-category-theory/" />
    <id>https://matteocapucci.eu/on-elements-in-category-theory/</id>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
<p>Today I stumbled upon a quote by Lawvere:</p><blockquote>
<p>There has been for a long time the persistent myth that objects in a category are “opaque”, that there are only “indirect” ways of “getting inside” them, that for example the objects of a category of sets are “sets without elements”, and so on. The myth seems to be associated with an inherited belief that the only “direct” way to deal with whole/part relations is to write an unexplained epsilon or horseshoe symbol between A and B and to say that A is then “inside” B, even though in any model of such a discourse A and B are distinct elements on an equal footing. In fact, the theory of categories is the most advanced and refined instrument for getting inside objects, because it does provide explanations (existence of factorizations of inclusion maps) and also makes the sort of distinctions that Volterra and others had noted were necessary for the elements of a space (because the elements are morphisms whose domains are various figure-types that are also objects of the category)</p>
<cite>F. W. Lawvere, <a href="http://www.tac.mta.ca/tac/reprints/articles/5/tr5abs.html">Functorial Semantics of Algebraic Theories and Some Algebraic Problems in the context of Functorial Semantics of Algebraic Theories</a></cite></blockquote><p>Lawvere wrote this 20ish years ago and yet this myth is still not dead! The simplicity and superiority of <a href="https://ncatlab.org/nlab/show/generalized+element">generalized elements</a> (and, more broadly, of <a href="https://ncatlab.org/nlab/show/internal+logic">internal logic</a>) seems to be left aside way too often, especially when teaching category theory: it's such an easy win to leverage set-theoretic intuition to nurture a structuralistic one!</p><p>However, like all good things in life, the element-free/generalized elements dialectic is much more interesting than either of the two sides it insists on.</p>
	<figure>
		<img src="/assets/2023/08/image.png" alt="Like all good things in life, it's a gaussian wojak meme." style="width:600px;max-width: 100%;height:auto" />
		<figcaption>Like all good things in life, it's a gaussian wojak meme.</figcaption>
	</figure>
<p>The first rebuttal to Lawvere, in fact, is that element-freeness is not a 'myth' <em>tout court</em>, since it is true that category theorists strive to avoid working with elements directly, at least as a widespread stylistic choice.</p><p>But there's more to it.</p><p>As I remarked in <a href="https://matteocapucci.eu/no-the-yoneda-lemma-doesnt-solve-the-problem-of-qualia/">one of my last posts</a>, objects of a category are mere labels which are substantiated by morphisms. In particular, it's not at all given that if you label your objects with <a href="https://ncatlab.org/nlab/show/concrete+object">concrete stuff</a>, their set-theoretic elements (call these <em>fool's elements</em>) coincide with their 'actual', i.e. category-theoretic <em><a href="https://ncatlab.org/nlab/show/generalized+element">generalized elements</a></em>.</p><p>That's the true meaning of the categorical wisdom of element-freeness: don't fool yourself, use the <em>right</em> elements. Indeed, the point is precisely than using morphisms to pick out elements is <em>the</em> way to go, as witnessed by the fact it works in all settings uniformly, unlike materialistic notions of elementhood.</p><p>To sum up: category theorists don't work with elements, they work with 'generalized elements' (i.e. morphisms) which are the right notion of elementhood in a structuralist setting. The old adage of working element-free is a cautionary tale for all those settings in which one could fall for a notion of elementhood which is not the right one, but the one falsely suggested by a set-theoretic labeling on objects.</p><p>Category theory doesn't reject the notion of elementhood, but instead fully realizes it.</p>      </div>
    </content>
  </entry>
  <entry>
    <title>No, the Yoneda lemma doesn't solve the problem of qualia.</title>
    <published>2023-07-15T00:00:00Z</published>
    <updated>2023-07-15T00:00:00Z</updated>
    <author>
      <name>Matteo Capucci</name>
      <uri>https://matteocapucci.eu/matteo-capucci/</uri>
    </author>
    <link rel="alternate" type="text/html" href="https://matteocapucci.eu/no-the-yoneda-lemma-doesnt-solve-the-problem-of-qualia/" />
    <id>https://matteocapucci.eu/no-the-yoneda-lemma-doesnt-solve-the-problem-of-qualia/</id>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>Category theory is an extremely insightful subject but its generality, the plethora of structural heuristics it provides, as well as its apparent conceptual simplicity make it very prone to cargo-culting. And the Yoneda lemma, being one of the most prominent theorems in category theory and one a student encounters relatively early, is object of many misunderstandings.</p>
        <p>One place were I've seen this recently was the '<a href="https://amcs-community.org/events/cats4consc-workshop/">Categories for consciousness science</a>' (C4CS) workshop, where some people proposed using category theory, and in particular Yoneda, as a way to settle '<a href="https://uh-ir.tdl.org/handle/10657/3248">the problem of qualia</a>' once for all. Let me stress here already that many talks in the workshop were legit and made interesting points about using categorical tools to approach consciousness science.</p>
        <p>This problem of qualia is often introduced in the following specific form: <strong>how do I know the colours <em>you</em> perceive are the same <em>I</em> perceive?</strong> This is an extremely fascinating questions and, of course, extends to all the subjective conscious experiences, i.e. qualia.</p>
        <p>Unfortunately, the categorical approach proposed to solve this (e.g. by Saigo, Tsuchiya, Maier) is not sound, and despite being happy to see category theory used as a mathematical compass in sciences, I think it's the duty of mathematicians (and scientists in general) to point out mistakes and correct misunderstandings, instead of ignoring them and let bad science (if in good faith!) poison the field.</p>
        <p>Let's consider <a href="https://www.youtube.com/watch?v=4GJ4UQZvCNM">this talk</a> (EDIT: Johannes Kleiner <a href="https://twitter.com/JohannesKleiner/status/1680357509654085632?t=46k7KIHgk_NGdVh_7dJovw&amp;s=19">pointed out</a> this talk isn't from the C4CS workshop, though there was a very similar one by Saigo or Tsuchiya). There, the proposal is to regard colours as the objects of a category. The morphisms of this category are 'relationships' between these colours. [0]</p>
        <p>The speaker then claims that colours' qualia are uniquely determined by the rigidity implied by the unique relationship each has with all the other ones. The Yoneda embedding allows us to conclude this: unique relationships, unique isomorphism class.</p>
        <p>Unfortunately, this line of reasoning is naive, and ultimately wrong.</p>
        <p>A common pitfall for category theory beginners is <strong>holding on to the idea that objects are absolute (as in set theory) and morphisms are an afterthought</strong>. Thus when we see Yoneda we are impressed because it seems we can recover the 'absoluteness' of the objects from the mere data of morphisms. But <strong>this is false</strong>: in a category, objects are mere labels and all the relevant data is in the morphisms. So the statement of the Yoneda embedding theorem is a triviality: since objects are fully constructed from their morphisms, they can be fully probed with morphisms. In other words, once we define a category <code> \mathcal {C} </code> (say, of colours), then applying Yoneda to it <em>can't possibly</em> tell us more about the objects than what we already knew when we assembled <code> \mathcal {C} </code>…</p>
        <p>This issue is fatal for the appeals to Yoneda in the aforementioned talk (or in <a href="https://doi.org/10.1093/nc/niab034">this paper</a>), since they start by assuming a specific category of 'qualia', or other things, and then they claim to be able to uniquely pin down the objects therein using isomorphism classes of representable presheaves over it. But this is circular: everything is determined by the choice of morphisms they make when defining the category at the start, so they can distinguish objects only insofar as they already assumed they could do so. [1]</p>
        <p>Such an <em>object-first</em> attitude, together with a lack of clear definitions for morphisms, leads to a second fallacy that further undermines the ideas proposed at C4CS. The fallacy goes like this: one fixes some objects, then later adds morphisms to make this set (or class) into a category, and then assumes that we this category will reflect the nature of the objects they started with. This is false, again: by choosing morphisms we also choose how objects are determined, i.e. we choose which objects are considered isomorphic. Hence if we start with objects distinguished by some properties not salient to the morphisms we add we end up identifying objects we deemed different at the beginning. In other words, even if we start with a set of objects <code> S </code>, what is relevant to cateory theory is the setoid <code> (S, \cong ) </code> determined by the morphisms we added later, and it may very well be that <code> (S, =) \not \cong  (S, \cong ) </code>.</p>
        <p>A classic example is given by the category of metric spaces and continuous functions thereof <em>versus</em> the category of metric spaces and short maps thereof. The two categories have the same class of objects but have different notions of isomorphism: two metrics inducing the same topology will be considered isomorphic in the first category, but not necessarily in the second (e.g. the <code> p </code>-distances on <code> \mathbb {R}^n </code>). Thus it's misleading to call the objects of the first 'metric spaces' since the choice of metric there is not as relevant as one might think. In particular, looking at all continuous functions out of two metric spaces will not help in the slightest to determine whether they are equipped with 'the same' metric.</p>
        <h2>An interesting idea: presheaves as observations</h2>
        <p>There are some interesting ideas to be saved, however, with some interesting questions.</p>
        <p>The first is that presheaves over a category correspond to 'observables'. This is akin to replacing a physical system with the algebra of observables for it, a maneuver which is ubiquitous in modern mathematical physics. [2]</p>
        <p>Moreover, presheaves have a very rich structure, in particular they admit all limits and colimits of things in the original category (now considered as representables), even if they don't exist therein. In a sense, it tells us that even if some things don't exist in our domain of discourse, we can still 'talk about them', as 'virtual' objects that nonetheless behave very much like 'real' ones. [3]</p>
        <p>Once we adopt this perspective, we realize the interesting thing is not to start with a 'category of things' and look at presheaves over it to learn about the things, but to go the other way around: if the only accessible parts of those things are observations we can make about them, then the true mathematical question is: <strong>how well can we reconstruct a category given its category of presheaves?</strong></p>
        <p>This question breaks down in two:</p>
        <ol><li>Suppose <code> \mathcal {O} </code> is a 'category of observations', when is it the case <code> \mathcal {O} \simeq  \mathbf {Psh}(\mathcal {C}) </code> for some 'category of real things' <code> \mathcal {C} </code>?</li>



<li>If <code> \mathbf {Psh}(\mathcal {C}) \simeq  \mathbf {Psh}(\mathcal {C}') </code>, is it the case <code> \mathcal {C} \simeq  \mathcal {C'} </code>?</li></ol>
        <p>I was very pleased to learn that question (1) was answered <a href="https://doi.org/10.1016/0021-8693(69)90102-1">by Bunge already in 1969</a>, and in much greater generality! In fact she answers this question in the enriched case (Theorem 4.16 there). Another characterization theorem is given by <a href="https://doi.org/10.1016/S0022-4049(96)00115-6">Carboni and Vitale</a> in terms of exact completions. See <a href="https://ncatlab.org/nlab/show/category+of+presheavescharacterization">this section on the nLab</a> for both statements.</p>
        <p>Question (2) has an answer too, this time in the negative. Two categories with the same category of presheaves are called <em><a href="https://link.springer.com/article/10.1007/s10485-011-9247-2">Morita equivalent</a></em>, echoing the terminology from commutative algebra. And like in algebra, in general, Morita equivalence is coarser than isomorphism.</p>
        <p>Two categories are Morita equivalent when they have the same <a href="https://ncatlab.org/nlab/show/Cauchy+complete+category">Cauchy completion</a> since the Cauchy completion <code> \bar {\mathcal {C}} </code> of <code> \mathcal {C} </code> is maximal among the categories Morita equivalent to <code> \mathcal {C} </code>. The completion <code> \bar {\mathcal {C}} </code> is given by the <a href="https://ncatlab.org/nlab/show/Karoubi+envelope">Karoubi envelope</a> of <code> \mathcal {C} </code>, which adds all the missing split idempotents. Doing so can substantially alter a category: for instance, when <code> \mathcal {C} = \mathbf {Op} </code>, the full subcategory of <code> \mathbf {Smooth} </code> spanned by open subsets of <a href="https://ncatlab.org/nlab/show/Cartesian+spaces">Cartesian spaces</a>, then its Karoubi envelope is the whole category of smooth manifolds, as observed by Lawvere.</p>
        <p>The final question hence is: <em>do split idempotents of qualia tell us something about the nature of consciousness?</em></p>
        <h2>Footnotes</h2>
        <p>[0] The elephant in the room of the workshop, and in papers such as <a href="https://doi.org/10.1093/nc/niab034">this one</a>, is that the objects they manipulate mathematically are hopelessly underspecified and vague to the point of uselessness. Mathematical reasoning is garbage in, garbage out: its results are only as universal and unappealable as the assumptions and definitions we start with.</p>
        <p>[1] Sometimes this is subtle because they start with a category (often a metric space or a preorder, really) which is 'objectively determined' by physical properties of the perception. For instance, they arrange colours in the metric space of the <a href="https://en.wikipedia.org/wiki/Gamut">gamut</a> of perceivable colours. Then the error is thinking they can say anything about qualia from this category: whatever they do with presheaves over it is going to reflect the physical aspects they put in the base category instead of the subjective qualities relevant to qualia.</p>
        <p>[2] That's why Saigo and Tsuchiya went to Yoneda, I guess: even if one can't access the 'category of qualia' itself, one seem to be able to observe it by taking measurement which are akin to presheaves. Hence the idea of using Yoneda as a way to tie the second to the first. However, this doesn't quite work: first, it's not obvious that what they deal with are presheaves and not just predicates or even functions (which would be, at best, <em>enriched</em> presheaves, a thing they mention but don't really embrace). Second, reconstructing the category some presheaves are over is not immediate even if we had access to the entirety of the category of presheaves, which we have not, because we can make only a finite amount of measurements.</p>
        <p>[3] Here's an interesting point though: within the category of presheaves, one can distinguish representables by their property of being <a href="https://ncatlab.org/nlab/show/tiny+object">tiny</a>. Thus we can tell if some universal object is real or fake, but only assuming we have enough presheaves around to test for 'tininess'.</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Grrr(othendieck) fibrations</title>
    <published>2023-02-02T00:00:00Z</published>
    <updated>2023-02-02T00:00:00Z</updated>
    <author>
      <name>Matteo Capucci</name>
      <uri>https://matteocapucci.eu/matteo-capucci/</uri>
    </author>
    <link rel="alternate" type="text/html" href="https://matteocapucci.eu/grrrothendieck-fibrations/" />
    <id>https://matteocapucci.eu/grrrothendieck-fibrations/</id>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
<p>Last night I finally wrapped my head around a definition of fibration which has been confusing me for a while. I thought I'd know how it worked until I didn't, only to realize my confusion stemmed from the fact I was looking at <strong>two</strong> subtly different definitions which are nonetheless equivalent. This made me angry enough to write a post.</p><p>A (cloven Grothendieck) fibration, or fibered category, is a functor <code> p: \cal  E \to  C </code> equipped with a structure called a <em><a href="https://www.merriam-webster.com/dictionary/cleavage">cleavage</a></em>, which amounts to say that when we look at the way the fibers of <code> p </code> (which are the categories <code> p^{-1}X </code> for <code> X: \cal  C </code>) are acted upon (or reindexed) by the morphisms of <code> \cal  C </code>, they behave basically as nicely as you can ask.</p><p>In fact, in general, a morphism <code> f:X \to  Y </code> in <code> \cal  C </code> induces a mere profunctor <code> p^{-1}f : p^{-1}X </code>⇸<code> p^{-1}Y </code> between the fibers of its ends. Such a profunctor takes an object <code> X' </code> over <code> X </code> and an object <code> Y' </code> over <code> Y </code> and returns the set of maps <code> f' : X' \to  Y' </code> in <code> \cal  E </code> over <code> f </code>. Here 'over' means 'mapped by <code> p </code> to'. Moreover, when you put together these profunctors, you realize they don't even compose nicely: they organize in a (unitary) lax functor <code> p^{-1} : \cal  C \to  \bf  Prof </code>. This story is told <a href="https://ncatlab.org/nlab/show/displayed+category">here</a>, and with some more detail in the references given there.</p><p>So a fibration is a functor for which reindexing is much better behaved: it is functorial and respects composition up to coherent iso! In other words, taking fibers is now a pseudofunctor <code> p^{-1} : \cal  C \to  \bf  Cat </code>. The structure of a cleavage is thus the data one needs to prove this, which can be more or less effective depending on your taste towards constructiveness.</p><p>Usually one gives a cleavage by proving every morphism <code> f:X \to  Y </code> in <code> \cal  C </code> has a so-called <em>cartesian lift</em> (a name which is very bad until you realize is very good). A lift of <code> f </code> would be a morphism <code> f':X' \to  Y' </code> in <code> \cal  E </code> such that <code> p(f') = f </code>. A cartesian lift is a lift enjoying a universal property, thus making it 'the best lift' according to some criterion.</p><p>When you unpack this universal property, it can be rather unwieldy. It feels like a drunk version of the universal property of a pullback. Here's the relevant diagram:</p>
	<figure>
		<img src="/assets/2023/02/image-7.png" alt="" style="width:346px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
<p>So you start with a morphism <code> f </code> in <code> \cal  C </code> like above, and you fix a <code> Y' : \cal  E </code> to lift to. This is sort of an anchor, think of it as the right leg of a pullback. This is the data in black in the diagram. Now the cartesian lift is the red morphism <code> f_{Y'} : f^*Y' \to  Y' </code>. Here <code> f^*Y' </code> is just notation for 'an object we obtained by reindexing <code> Y' </code> along <code> f </code>'. Its universal property is expressed against the blue data, which consists of another morphism <code> h:Z \to  Y' </code> into <code> Y' </code> and a morphism <code> k: p(Z) \to  X </code> chosen as to factor <code> p(h) </code> through <code> f </code> (hopefully you notice the slightly different shades of blue). Then <code> f_{Y'} </code> is cartesian iff there exists a unique morphism <code> \langle  h, k \rangle  : Z \to  f^*Y' </code> in <code> \cal  E </code> that (1) factors <code> h </code> through <code> f_{Y'} </code> and (2) is over <code> k </code>, i.e. <code> p\langle  h,k \rangle  = k </code>.</p><p>Ugh, what a ride!</p><p>It's not easy to wrap one's head around this universal property the first time one encounters it. In my opinion, it is better given in other ways, and funnily enough, it is <strong>not</strong> the original definition of Grothendieck fibration (given in SGA by, you guessed it, Grothendieck). The original one is given in terms of <em>weak</em> cartesian morphisms (the modern terminology 'cartesian morphism' denotes what Grothendieck called 'strong cartesian morphism'), which satisfy a more intuitive universal property plus the requirement to compose up to coherent isomorphisms. This weaker universal property is then seen, quite straightforwardly actually, to correspond to the fact reindexing can be expressed by representable profunctors, aka functors, while the second requirement makes reindexing pseudofunctorial.</p><p>If you don't fancy reading SGA, I found John Gray gave a detailed, well-written and English exposition of the same material in the first sections of his paper <em><a href="https://link.springer.com/chapter/10.1007/978-3-642-99902-4_2">Fibred and cofibred categories</a></em> (a paper which, regrettably, is freely available on SciHub). This is even more remarkable when you realize Gray's paper is from 1965, just a few years after SGA was published, and the exposition of so many category theory papers from back then hasn't aged that well.</p><p>Apart from the fact Gray did a great job already in explaining Grothendieck's original definition of fibration, I'm not lingering on it mainly because I want to talk about another, slicker way to define fibrations, due to Chevalley.</p><p>As I anticipated these are actually <strong>two</strong> subtly different ways. Their main advantage is to be applicable to define fibrations in any cartesian 2-category <code> \cal  K </code>. But for now, let's stick to <code> \bf  Cat </code>.</p><p>The definition goes like this: <code> p:\cal  E \to  C </code> is a fibration iff you can exhibit the right adjoint dashed in the following commutative diagram:</p>
	<figure>
		<img src="/assets/2023/01/image-10.png" alt="Importantly, this diagram depicts an adjunction in  {\bf  Cat}/\cal  C^\downarrow  ." style="width:249px;max-width: 100%;height:auto" />
		<figcaption>Importantly, this diagram depicts an adjunction in <code> {\bf  Cat}/\cal  C^\downarrow  </code>.</figcaption>
	</figure>
<p>This might look a bit confusing at first, but I promise it's actually very intuitive once we introduce all the characters.</p><p>On the right, <code> C/p </code> is a <a href="https://ncatlab.org/nlab/show/comma+category">comma category</a>, or the slice of <code> C </code> over <code> p </code>. Hence its objects are pairs of an object <code> Y': E </code> and an arrow <code> f:X \to  p(Y') </code> of <code> C </code>, and its morphisms are exactly what you expect (the data here is <code> h </code> and <code> k </code>, and the commutativity of the square is a condition):<br /></p>
	<figure>
		<img src="/assets/2023/02/image.png" alt="" style="width:377px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
<p>The functor <code> u </code> out of <code> C/p </code> forgets about the data of an object in <code> E </code>, and only remembers the arrow.</p><p>On the left, we have <code> p^\downarrow  : \cal  E^\downarrow  \to  C^\downarrow  </code>, the functor <code> p </code> 'on arrows'. It takes an arrow in <code> \cal  E </code> and sends it to an arrow in <code> \cal  C </code>, using <code> p </code>, and does the same for squares.</p><p>Finally, on top we have <em>basically the same functor</em> as <code> p^\downarrow  </code>: it sends an arrow of <code> \cal  E </code> to the pair of its codomain and the arrow of <code> \cal  C </code> obtained by applying <code> p </code> to it:<br /></p>
	<figure>
		<img src="/assets/2023/01/image-12.png" alt="" style="width:285px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
<p>Now, what does a functor <code> \ell  : {\cal  C}/p \to  \cal  E^\downarrow  </code> do? When you think about it, it gives explicit lifts. Indeed, objects of <code> {\cal  C}/p </code> are 'lifting problems': arrows in <code> \cal  C </code> with a specified object of <code> \cal  E </code> over its codomain. Then a lift would send such a thing to an arrow of <code> \cal  E </code>, and since <code> \ell  </code> has to make the triangle over <code> \cal  C^\downarrow  </code> commute, we know that it must send <code> f </code> to a morphism <em>over</em> it, thus a lift!</p>
	<figure>
		<img src="/assets/2023/01/image-13.png" alt="Notice here X' is chosen by l, not data" style="width:252px;max-width: 100%;height:auto" />
		<figcaption>Notice here X' is chosen by l, not data</figcaption>
	</figure>
<p>Asking for <code> \ell  </code> to be right adjoint to what is, in practice, <code> p </code> on morphisms, assures its choice of lifts is cartesian. In fact, we are going to prove it amounts to giving to the lifts the universal property explained above.</p><p>Suppose the adjunction is given by a natural isomorphism <code> {\cal  E}^\downarrow (h_1, \ell (f)) \cong  {\cal  C}/p(p(h_1), f) </code> (pardon the weird name for <code> h_1 </code>, you'll see in a moment why I've chosen that). In one direction, is very simple (<code> {\cal  E}^\downarrow  </code> on the left, <code> {\cal  C}/p </code> on the right):</p>
	<figure>
		<img src="/assets/2023/02/image-5.png" alt="Here V' should be W', ops!" style="width:475px;max-width: 100%;height:auto" />
		<figcaption>Here V' should be W', ops!</figcaption>
	</figure>
<p>In the other direction, we can read the universal property of <code> \ell (f) </code> as cartesian lift of <code> f </code>:</p>
	<figure>
		<img src="/assets/2023/02/image-6.png" alt="" style="width:467px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
<p>The existence and uniqueness of <code> \langle  h_1 ; h_2, k \rangle  </code> (whose name is, so far, just notation) are consequences of stating that the two mappings just exhibited are inverse to each other. Why is this the same <code> \langle  h_1 ; h_2, k \rangle  </code> we've seen in stating the universal property of cartesian lift? Well, if you put <code> h = h_1 ; h_2 </code>, then we are saying that for all morphisms <code> h:Z' \to  Y' </code> and <code> k </code> (such that <code> p(h) = k ; f </code>) there exists a unique <code> \langle  h, k \rangle  </code> that factors <code> h </code> through <code> \ell  f </code>.</p><p>Ta-dah!</p><p>While the counit of this adjunction is boring (since <code> p(\ell (f)) = f </code>), the unit is quite interesting: it takes a map <code> f' </code> in <code> \cal  E^\downarrow  </code> and gives us a square <code> f' \to  \ell (p(f')) </code>, obtained as the mate of the identity of <code> p(f') </code>:</p>
	<figure>
		<img src="/assets/2023/02/image-8.png" alt="" style="width:479px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
<p>Observe that on the left we actually have a triangle, whose 'long side' is <code> f' </code>, and whose short side exhibit a factorization in <code> \ell (p(f)) </code> and <code> \eta _{f'} </code>. By construction, these are, respectively, a cartesian map (i.e. a map obtained by lifting something from <code> \cal  C </code>) and a vertical map (i.e. a map over an identity). So the unit of this adjunction provides the vertical part in the vertical-cartesian factorization system we have on <code> \cal  E </code>! This factorization system is really useful, and you can read more about it <a href="https://arxiv.org/abs/2006.14022">here</a>.</p><p>Now the reason for my confusion is that if you look at classical sources, like the nLab or Street's <em>Fibrations in bicategories</em>, they would tell you <code> p:\cal  E \to  C </code> is a fibration iff you can exhibit the right adjoint dashed in the following commutative diagram:</p>
	<figure>
		<img src="/assets/2023/02/image-9.png" alt="Again, this depicts an adjunction in  {\bf  Cat}/\cal  C " style="width:265px;max-width: 100%;height:auto" />
		<figcaption>Again, this depicts an adjunction in <code> {\bf  Cat}/\cal  C </code></figcaption>
	</figure>
<p>And this diagram looks so similar to the aforementioned one I've never really bothered with it. Only after I end up very confused I realized the two are different definitions! Notice, in fact, that on the left side of the above diagram appears <code> p </code>, not <code> p^\downarrow  </code>!</p><p>So how come two definitions which are so close to each other both give us the same answer?</p><p>The reason is we can recover one from the other by composing the incriminated adjunctions with the mother of all adjunctions, <code> \rm  cod \dashv  id \dashv  dom : \cal  E \to  E^\downarrow  </code>. For instance, one gets the second definition from the first by doing:</p>
	<figure>
		<img src="/assets/2023/02/image-12.png" alt="" style="width:442px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
<p>This is saying that <code> \ell  </code>, in the second definition, maps a morphism <code> f:X \to  p(Y') </code> to the domain of its cartesian lift.</p><p>Dually, we can get the first one from the second:</p>
	<figure>
		<img src="/assets/2023/02/image-11.png" alt="" style="width:440px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
<p>To see how this works, one first has to convince oneself that the second definition I gave you works. The trick is, despite the fact <code> \ell  </code> only gives us the domain of the (alleged) cartesian lift, its action on <em>morphisms</em> can be used to obtain the entire cartesian lift. See <a href="https://ncatlab.org/nlab/show/Street+fibrationIn+terms+of+adjoint+inverses">here</a> for a proof that this is sufficient (in the slightly more general case of Street fibrations).</p><p>This latter definition might feel less intuitive but has the benefit of being a bit simpler to state (no <code> p^\downarrow  </code> involved) and to use in abstract.</p><p>For instance, here's another way to see the fibrations induce a factorization system on their total category <code> \cal  E </code> using this latter definition. For similar reasons as before, the counit of <code> \langle  1, p \rangle  \dashv  \ell  </code> is trivial, which means <code> p </code> is fully faithful. Since <code> \ell  </code> also has a left adjoint, it exhibits <code> {\cal  C}/p </code> as a <a href="https://ncatlab.org/nlab/show/reflective+subcategory">reflective subcategory</a> of <code> \cal  E </code>, and thus <a href="https://ncatlab.org/nlab/show/reflective+factorization+system">induces a factorization system</a> on it. If you look at the way this happens, you quickly realize this is indeed the vertical-cartesian factorization system on <code> \cal  E </code>. Brilliant!</p><p>The true power of this definition, however, is that it exhibits fibrations, as the algebras of a <a href="https://ncatlab.org/nlab/show/lax-idempotent+2-monad">colax idempotent 2-monad</a>. This has many nice consequences, the most immediate being fibrational structure is <a href="http://www.tac.mta.ca/tac/volumes/1997/n9/3-09abs.html">property-like</a>, meaning there's at most one (up to equivalence) way for a given functor to be a fibration.</p><p>That's a great, great piece of category theory which deserves a better exposition than what I can do now before going to lunch, so let's leave for next time! If you're hungry for answers though, the story is <a href="https://ncatlab.org/nlab/show/fibration+in+a+2-category">sketched on the nLab</a> and in full in Street's <em>Fibrations in bicategories</em> (beware, this latter paper is not for the squeamish).</p>      </div>
    </content>
  </entry>
  <entry>
    <title>Mathematicians don't care about foundations</title>
    <published>2022-12-21T00:00:00Z</published>
    <updated>2022-12-21T00:00:00Z</updated>
    <author>
      <name>Matteo Capucci</name>
      <uri>https://matteocapucci.eu/matteo-capucci/</uri>
    </author>
    <link rel="alternate" type="text/html" href="https://matteocapucci.eu/mathematicians-dont-care-about-foundations/" />
    <id>https://matteocapucci.eu/mathematicians-dont-care-about-foundations/</id>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>Many people seem to believe mathematicians work in non-constructive, non-structural, battered foundations because they love their Platonic realm and have a kink for AC and LEM. The reality is most mathematicians don't have a clue about foundations, they don't care, and happily work informally for all their lives.</p>
        <p>Case in point, mathematical foundations are a pretty recent thing (19th century if we are being generous) but their establishment didn't deprecate previous mathematics, which continued to be studied and used just as well. Even during the so-called 'crisis in foundations' at the start of the 20th century most mathematicians didn't blink an eye. Only a few pages of math had to be rewritten, and they were about foundations themselves.</p>
        <p>I'm being intentionally provocative in calling out foundations here so, let me throw a bucket of water on this fire already. Foundations are not useless to study at all! On the contrary, mathematicians are thankful <em>someone</em> figured out foundations for them, so that they just need to know some TL;DR about which logical maneuvers they are allowed to perform and which objects they are allowed to claim the existence of.</p>
        <p>Such 'irrelevance' witnesses a robustness in mathematics, betraying a deeper nature behind it's facade of rigour. Mathematics is irreducibly informal (even foundations), i.e. relying on some unspoken mutual understanding on how to interpret signs, concepts, and norms. The difference among mathematicians is how deep they have to shell such conventions before being satisfied.</p>
        <p>Thus math is not a castle built on a bedrock of unshakeable foundations. Math is rather a collective codification of intuitions squeezed into formal frames in the best way possible. This is why the 'crisis in foundations' didn't really matter for most mathematics: what broke was the frame, not the ideas. This is also why we get new and improved mathematical theories every now and then. Saying 'space' today doesn't evoke the same suggestions it used to do two-hundred years ago.</p>
        <p>In fact formal definitions never fully capture the <em>essence</em> of the ideas they intend to embody, being mere vessels to reason and communicate deeper, intangible intuitions about them. This essence is shaped by the discourse among mathematicians, and the unrelenting murmuration of teaching and learning. This is the true mathematical platonic realm: the socially determined, impalpable world of shared intuitions and understandings, substantiating all the formal language.</p>
        <p>Formality is relevant, don't get me wrong. Mathematicians hold it in great respect, and agree to abide to its rule. I myself recognize the importance of choosing good formal language (meaning definitions and notational devices) to guide our thoughts. After all, boundaries shape creativity. But here I'm making the point that what 'formal enough' means is entirely a social construction, dependent on who, more than what, you are working with.</p>
        <p>If this isn't already liberating (or obvious) enough for you, here's a silver-lining. The carelessness mathematicians have towards foundational matters has the interesting corollary that they don't feel strongly about any of the options on the menu. In particular they are not committed to ZFC as much as some people like to complain.</p>
        <p>Mathematicians point in the direction of ZFC when asked about foundations because this is what they've heard justifies set theory, and that's what they care about. Naive set theory supplies the raw material they've learned to build mathematical concepts with, and ZFC provides quality assurance for it. But that's it: the average mathematician barely knows how ZFC actually limits their set manipulations.</p>
        <p>For people who, like me, are enamoured of structural foundations, and think more mathematicians should be aware of them, this is great news! Potentially, agnostics can be convinced to adopt more expressive foundations if we don't insist this to be a matter of religious faith, but a more convenient justification for their mathematics.</p>
        <p>In fact, I'm sure if at the start of an undergrad mathematical curriculum we provided students with a good 'naive type theory', mathematicians would just grow to use it. They'd still won't care, but they'd happily credit Martin-Löf for giving legitimacy to their mathematics instead of Cantor, Zermelo and Fraenkel.</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Tips on learning how to write proofs</title>
    <published>2022-01-30T00:00:00Z</published>
    <updated>2022-01-30T00:00:00Z</updated>
    <author>
      <name>Matteo Capucci</name>
      <uri>https://matteocapucci.eu/matteo-capucci/</uri>
    </author>
    <link rel="alternate" type="text/html" href="https://matteocapucci.eu/tips-on-learning-how-to-write-proofs/" />
    <id>https://matteocapucci.eu/tips-on-learning-how-to-write-proofs/</id>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>In mathematics, proofs are all the rage. I'm currently TAing a course on theory of computation, which is the most math many students have seen in the last four years, and definitely not high school style mathematics (i.e. 'shut up and calculate'). So I've been asked some tips on how to cope with proof writing and I ended up writing quite a long 'guide', which I like enough to publish here, for the public to ridicule.</p>
        <h3 id="quick-anatomy-of-a-theorem">Quick anatomy of a theorem</h3>
        <p>Theorems are mathematical statements of the form:</p>
        <code>
	A_1, \ldots , A_n \implies  B_1, \ldots , B_m
</code>
        <p><code> A_1, \ldots , A_n </code> are statements we <em>assume</em>, therefore are called assumptions or <em>hypotheses</em>. They are often a mix of summoning mathematical objects ('let <code> G </code> be a graph'), summoning properties ('which is planar') and summoning notation ('and denote by <code> \chi  </code> its genus'). On the other side, we have the <em>conclusions</em> or <em>theses</em>. These are again mathematical statements, and that's what we have to prove. They are usually properties ('<code> \chi  = 0 </code>') or existence claims about the things summoned in the assumptions. The <code> \implies  </code> is often spelled as 'then'.</p>
        <p>Bear in mind that the above is <em>not</em> how theorems are usually written down. Mathematicians speak with words, not symbols (that's <em>mathematics</em>). So you rarely encounter a theorem which is expressed exactly as an implication as above. Often mathematicians prefer to abbreviate them in more succinct statements, and there could be considerable work to be done to unpack them into a clear implication, or to track down what's exactly the setting a theorem is being formulated in. Mathematicians <em>love</em> to disseminate terminology around so that they can say things like 'all blorbs on a smooth zib are 3-sgurz'. Indeed, <a href="https://matteocapucci.wordpress.com/2019/07/27/math-tools-are-ways-of-thinking/">one could say mathematics is all about this</a>.</p>
        <p>Theorems beget proofs: a theorem without a proof is simply a statement, and could be true, false or even neither until a proof is found. If you have a statement but not a proof, you got yourself a <a href="https://en.wikipedia.org/wiki/Conjecture">conjecture</a>, a claim or an <a href="https://en.wikipedia.org/wiki/Riemann_hypothesis">hypothesis</a> if your name is Bernhard Riemann.</p>
        <h3 id="writing-a-proof">Writing a proof</h3>
        <p>It is crucial to realize proofs are nothing but <strong>explanations of why something is true</strong>. We do this all the time in real life, so do not let the formality of the context hold you back. Proofs are mathematicians explaining things to one another. They have some lingo that helps, and they are very exacting on the correctness of the argument (sometimes we do not always do in real life, admittedly). Pause to internalize this and then keep reading.</p>
        <p>It follows from the point above that <strong>the first step in writing a proof is to understand yourself why something is true.</strong> This might seem trivial, but it's definitely the hardest part. Sometimes it takes minutes, sometimes hours, occasionally months or years. But when you do, <a href="https://en.wikipedia.org/wiki/Threshold_knowledge">you crossed the river and can't come back</a>.</p>
        <p>The proof is a shallow manifestation of a deeper phenomenon happening in your brain, which is developing intuition for a new realm. <strong>Mathematics is about concrete manipulations of abstract concept</strong>. You find yourself dealing with a world whose rules are very unfamiliar to your brain at first, like they were when you were a child. Slowly, you learn your way around them. You start to develop that intuition that you develop for the physical world ('if I let this object go, it falls', 'poo smells', 'mom is just behind the door, she didn't stop existing', etc.) [0].</p>
        <p>So before you write anything, be free and aim at intuit. Play with the assumptions, recall facts you know about the objects at hand, break things, experiment, challange the new abstract world around you [1]. At this step, you don't need to be formal. Refrain from be formal, actually. You need to feel the theorem in your guts to move to the second step, and oftentimes rigid formal statements do not sit well with handwavy feelings.</p>
        <p>Bear in mind: proof writing is recursive. Every proof is made of small proofs chained together, and each of those is made of even smaller proofs, and so on. <a href="https://www.masterclass.com/classes/terence-tao-teaches-mathematical-thinking">Think of a proof as a rock wall to climb</a>. You're not gonna jump to the top in one step. Instead, you break down the wall in smaller parts to climb individually. Each of these small parts is, in the end, comprised of single holds that you can actually switch between in one go. So don't feel daunted in front of a big proof: it's actually many small proofs in a trenchcoat.</p>
        <p>Corollary: it really helps to work backwards from the conclusions, since it is equivalent to position yourself closer to the end of the climb. It's not always the definite strategy, but it's a strategy. Seeing what's ahead improves your chances of finding a step, and <a href="https://en.wikipedia.org/wiki/Backward_induction">from there you can proceed backwards again</a>.</p>
        <p>Applying this at least one time is often necessary, in order to unpack what proving the thesis actually amounts to (e.g. 'prove <code> \sqrt  2 </code> is irrational' means 'show there is no pair of integers <code> (a,b) </code> such that <code> \sqrt  2 = a/b </code>'). Most importantly, it has to be absolutely clear what the assumptions are and what the conclusion is asking from you. This often means unpacking some jargon, and surprisingly often means finding out the statement is evident once the unpacking is done.</p>
        <p>When you feel why the theorem you need to prove is true, go ahead and sketch an explanation. It's useful to <a href="https://en.wikipedia.org/wiki/Game_semantics">pretend you're explaining this to a very skeptical friend of yours</a>. They're going to challenge everything you say (it takes time to internalize what can be not challenged, what mathematicians call 'trivial'). Your job is to keep yourself true to your intuition and explain it in detail. Perhaps your imaginary friend will actually poke a hole in your intuition. That's actually the best thing that can happen: often this brings you to realize a deeper truth, and you end up with a deeper understanding of the problem.</p>
        <p>Indeed, it's important to realize <strong>the key to problem solving is continuous back and forth between being wrong and being correct</strong>. The worst thing you can do is freeze and not try anything: you're depriving yourself of useful errors. 'You learn from your mistakes' is a very deep truth.</p>
        <p>Sometimes this means going ahead and sketching to your imaginary skeptical friend a solution you know is wrong and explain to them why you believe so. Making something explicit to yourself ('rubber ducking') is an unreasonably powerful technique. This is because reasoning unravels thoughts in potentiality: as you explain something to yourself, your brain can explore its ramifications. Like in those (old?) games where <a href="https://forums.ageofempires.com/uploads/default/original/3X/e/7/e7793754d7dcbe58976d2ffaab95700ce0a20173.jpeg">the map is hidden until you walk through it</a>, you need to move through the dull parts to glance the interesting one.</p>
        <p>Finally, use 'solved' proofs to test yourself. Sipser's book [we're using this in our 'Theory of computation' course, ndr] is full of proofs, most of them are quite straightforward (one could call them 'constructions'). This is great, it means you can exercise your skills by recreating these proofs.</p>
        <p>You should not read and repeat them, that's useless. You should tackle the task as if it was a theorem you found in the wild and try to prove it yourself. If you get stuck, the solution can give you a hint. Be parsimonious with hints though, or you'll never force your brain to learn. If you are successful and get to the end, you can now compare your proof with Sipser's. It doesn't have to be the same! Many theorems have multiple proofs. It has to be valid, though. Try to understand what Sipser's proof tells you about yours and viceversa.</p>
        <p>Also, this is a crucial step to equip yourself with intuition about the objects the course is about. The ultimate goal of studying a proof is to internalize the intuition conveyed by it. You also learn techniques to deal with specific problems (indeed, in this course most proofs are formulaic, and follow a pattern you can familiarize yourself with in advance by reading the book proofs), e.g. reduction techniques.</p>
        <p>On a minor note, writing proofs means writing in a certain literary style, so reading and imitating 'the masters' is how you learn the correct style of prose [2]. Keep in mind that your goal is to explain why something is true to someone. Providing intuition on why you do something is the main goal. That's what you need to convey. The rest is to be extra-convincing and plug all the holes someone might poke in the argument.</p>
        <h3 id="tl-dr">TL;DR</h3>
        <p>The three most important take-aways to learn how to write proofs/approach proof writing:</p>
        <ol>
          <li>Develop intuition for the material at hand, clarify to yoursel what the proof actually requires (what am I given as hypotheses? What do I actually need to prove?),</li>
          <li>Rubber duck and don't be afraid of being wrong,</li>
          <li>Iterate on your ideas, even the wrong ones, and <a href="https://en.wikipedia.org/wiki/Divide_and_rule">divide your goal in subgoals</a>,</li>
          <li>Learn from the examples.</li>
        </ol>
        <p>To conclude, the best quality a mathematician can have is <strong>perseverance</strong>. That something I noticed when I started my bachelor: finally, I wasn't the only one who was capture by a problem even after class was dismissed. My fellow mathematicians wouldn't abandon a puzzle after the first hurdle. They derived joy from the challenge.</p>
        <p>Perhaps you don't want to be a mathematician, but keep in mind success often comes through insistence! So don't give up!</p>
        <h2 id="footnotes">Footnotes</h2>
        <p>[0] I clearly remember this process when I first learned commutative algebra and (the rudiments of) algebraic geometry. It felt like forcing my brain to restructure itself. Nothing worked out, and I flunked my exams the first time. I was like a 1yo barely able to balance themselves.<br />So I spent more time on it, reviewed the concepts (learned <em>more</em> concepts actually, I took an homological algebra course in the meantime) and finally things started to click. I familiarized myself with rings, modules and their behaviours. I internalized the examples, and learned what to expect from my interactions with them. When I tried my exams a second time, they felt like asking a 6yo to jump, clap their hands and pour a glass a water without spilling it. All things I was familiar with by now. I aced them.</p>
        <p>[1] I believe proof by contradictions are exactly this: challenge the conclusions and try to understand why it breaks down. This so unreasonably powerful that many people do it even when unnecessary, leading to 'fake' proofs by contradiction, <a href="http://math.andrej.com/2010/03/29/proof-of-negation-and-proof-by-contradiction/">proof by negation</a>. So one of my favourite techniques is reason by contradiction and them remove the scaffolding to get a perfectly fine (i.e., constructive) proof by negation.</p>
        <p>[2] Yeah, some 'masters' are really bad at writing. Some aren't. Imitate the proofs you found clear, and strive to keep that clarity.</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Optics in three acts</title>
    <published>2022-01-10T00:00:00Z</published>
    <updated>2022-01-10T00:00:00Z</updated>
    <author>
      <name>Matteo Capucci</name>
      <uri>https://matteocapucci.eu/matteo-capucci/</uri>
    </author>
    <link rel="alternate" type="text/html" href="https://matteocapucci.eu/optics-in-three-acts/" />
    <id>https://matteocapucci.eu/optics-in-three-acts/</id>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
<p>The following is the script of <a href="https://matteocapucci.eu/work-0019/">my latest MSP101 talk</a>. It's supposed to be an overview of optics covering three different ways to construct them and reason about them. Most of it is devoted to the understanding of Tambara theory and the profunctor encoding, for personal reasons: it's the last way of thinking about optics that I've learned, and it took me the most effort to develop an intuition for them.</p><p>In this post I'm assuming basic acquaintance with coend calculus, basically stuff from the first two chapter of '<a href="https://arxiv.org/abs/1501.02503">Co/end calculus</a>'. In preparing the talk, I've heavily drawn from these papers:</p><ol><li>Riley's '<a href="https://arxiv.org/abs/1809.00738">Categories of optics</a>',</li>



<li>Boisseau's '<a href="https://arxiv.org/abs/2002.11480">String diagrams for optics</a>',</li>



<li>Gibbons and coauthors' '<a href="https://arxiv.org/abs/1703.10857">Profunctor optics: modular data accessors</a>',</li>



<li>Pastro &amp;amp; Street's '<a href="https://arxiv.org/abs/0711.1859">Doubles for monoidal categories</a>',</li>



<li>Roman's master thesis, which is an amazing compendium of slow-paced theory of optics, '<a href="https://arxiv.org/abs/2001.08045">Profunctor optics and traversals</a>',</li>



<li>and the multiauthor definitive paper on profunctor optics, '<a href="https://arxiv.org/abs/2001.07488">Profunctor optics: a categorical update</a>'.</li></ol><h2 id="prelude-through-the-looking-glass">Prelude - Through the looking glass</h2><p>First of all, what are optics good for? A very partial answer:</p><ol><li><strong>Modular data accessors</strong><br />Optics were born in functional programming from the need of 'looking inside' data structures. In particular, they provide a modular abstraction for accessing and updating data structures.<br />The classic examples are lenses and prisms. Lenses access and update record types, hence components of tuples of types. Prisms access and update 'corecord' types, hence coproducts of types.<br />There are simpler and more complex optics: adapters, simply transform values without dealing with a 'contextual' data structure. Traversals access values stored in deeply nested data types like lists, trees, heaps, etc.<br />Optics were born out of the need of threading together all these kinds of ways to access data, especially for the purpose of being able to composing different flavors of data accessors together. Data is structured in all sorts of bizarre ways (e.g. 'a tree of pairs of nullables') and you need to be able to interface different accessors if you want to survive.<br />An excellent introduction to optics as modular data accessors is the <a href="https://arxiv.org/abs/1703.10857">almost-eponymous paper by Gibbons, Pickering and Wu</a>.<br /></li>



<li><strong>Cybernetics</strong><br />The second area were optics found a home is categorical cybernetics. This because they provide a useful abstraction for bidirectional processes, which cybernetics is full of.<br />This story basically begins with Jules inventing open games, realising that they amount to indexed families of lenses, and then realising that doesn't work for Bayesian games: optics were needed in that case, and for completely different reasons than in functional programming. Here, optics are needed to deal with the lack of cartesian structure that lenses need so much. As often happens in category theory, this actually turned out to hint at <a href="https://matteocapucci.eu/open-cybernetics-systems-i-feedback-systems-as-optics/">a much more interesting conceptualization of cybernetic systems and their mathematical models</a>.</li></ol><h2 id="act-i-profunctor-representation-or-how-i-stopped-worrying-and-learned-to-love-tambara-modules">Act I - Profunctor representation, or how I stopped worrying and learned to love Tambara modules</h2><h3 id="idea">Idea</h3><p>The original (?) definition of optics is through a clever conceptualization of what it means to be an optic, after all. This idea relates to the other two we are going to explore, and it's surprisingly deep for what has born somewhat as an Haskell hack. In fact, at about the same time profunctor optics were born, Pastro and Street were writing <a href="https://arxiv.org/abs/0711.1859">a paper titled 'Doubles for monoidal categories' </a>which will turn out ot be extremely relevant. In turn, this paper builds on <a href="https://arxiv.org/abs/0711.1859">another work by Tambara</a> published the year before, were he introduces 'Tambara modules' as a tool in representation theory. An amazing plot twist!</p><p>The crown jewel of Tambara theory (at least as far as opticians are concerned) is the profunctor representation theorem, which provides an explicit characterization of optics, the so-called existential encoding. It can be turned into a slogan as follows: <em>optics are what Tambara modules are presheaves over</em>.</p><h3 id="what-s-a-tambara-module">What's a Tambara module</h3><p>Tambara modules are 'just' strong profunctors, but we need some context to unpack this.<br />First, let's fix some data: let <code> \mathcal  C </code>, <code> \mathcal  D </code> be categories receiving an action of a fixed monoidal category <code> (\mathcal  M, i, \odot ) </code>. Lately, we've been referring to a category equipped with a monoidal action from <code> \mathcal  M </code> as 'actegories', but in other parts of the literature they're called '<code> \mathcal  M </code>-modules', generalising the idea that modules in algebra are 'just' actions of monoids in the category of abelian groups.</p><p>In practice, an action of <code> \mathcal  M </code> on <code> \mathcal  C </code> allows you to represent objects and morphisms of <code> \mathcal  M </code> in <code> \mathcal  C </code> (in fact, when some additional structure is around, actions of <code> \mathcal  M </code> on <code> \mathcal  C </code> <em>are</em> mappings of <code> \mathcal  M </code> into <code> \mathcal  C </code>). In symbols, given objects <code> m:\mathcal  M </code> and <code> a:\mathcal  C </code>, one can write <code> m \bullet  a </code> and given <code> \alpha  : m \to  n </code>, there is a natural transformation <code> \alpha  \bullet   - : m \bullet  - \to  n \bullet  - </code>. We are going to deal with pairs of actegories over the same monoidal category <code> \mathcal  M </code>, and we use the same symbol <code> \bullet  </code> to denote all actions.</p><p>On the other hand, profunctors are the categorification of relations between sets, or more suggestively, <strong>they are 'proof relevant' relations between categories</strong>. A profunctor from <code> \mathcal  C </code> to <code> \mathcal  D </code> is then a functor <code> \mathcal  C^\mathrm {op} \times  \mathcal  D \to  \mathbf {Set} </code>, or a presheaf over <code> \mathcal  C^\mathrm {op} \times  \mathcal  D </code>. Everyone who knows the strict basics of category theory knows at least one profunctor: the Hom profunctor, going from <code> \mathcal  C </code> to <code> \mathcal  C </code> (in fact, it's the identity morphisms in the category of categories and profunctors between them).<br />Indeed, another interpretation of profunctors which is going to play a relevant role here is that they provide a way to talk about morphisms from different categories, aka 'heteromorphisms'. In fact to give a profunctor <code> P:\mathcal  C \to  \mathcal  D </code> is to answer the question: 'what's a morphism from <code> a:\mathcal  C </code> to <code> b:\mathcal  D </code> like?' According to <code> P </code> it's an element <code> f:P(a,b) </code>, which we denote by <code> f : a \rightsquigarrow  b </code>. The answer is satisfactory since <code> P </code> has the correct properties you would expect from a hom-like functor, in particular it respects pre-composition with morphisms of <code> \mathcal  C </code> and post-composition with morphisms of <code> \mathcal  D </code>:</p>
    
      

      <figure><img src="https://matteocapucci.eu/dab5183019cf553dc6c612322604ab22.svg" /></figure>
    
    <p>Now, Tambara modules are profunctors that, moreover, respect the actegorical structure of <code> \mathcal  C </code> and <code> \mathcal  D </code>. In fact when that's present there is one more way to extend a morphism (viz. 'vertically'):</p><code> m \phantom {\overset {g}\rightsquigarrow } m \\ \bullet  \ \phantom {\overset {g}\rightsquigarrow }\ \bullet  \\ a \overset {g}\rightsquigarrow  b : P(m \bullet  a, m \bullet  b) </code><p>Functoriality of <code> \bullet  : \mathcal  M \times  \mathcal  C \to  \mathcal  C </code> makes it obvious that a morphism <code> f:a \to  a' </code> of <code> \mathcal  C </code> is carried to a new morphism <code> m \bullet  f : m \bullet  a \to  m \bullet  a' </code>, but for profunctors, one needs to invoke extra structure. Tambara modules are this, and no more.</p><p>Formally, the structure of a <strong>Tambara module</strong> on <code> P: \mathcal  C \to  \mathcal  D </code> is a family of morphisms (called <em>stregnth</em>)</p><code> \mathrm {st} : P(a,b) \to  P(m \bullet  a, m \bullet  b) </code><p>dinatural in <code> m </code> and natural in <code> a </code> and <code> b </code>, which satisfies reasonable coherence conditions. A morphism of Tambara modules is a natural transformation of presheaves which commutes with the strength.</p><p>Each Tambara module is an opinion on the nature of the relation of <code> \mathcal  C </code>, <code> \mathcal  D </code> and <code> \mathcal  M </code>. It proposes ways for a given <code> a: \mathcal  C </code> to map into a given <code> b: \mathcal  D </code>, and a way for these maps to work with additional <em>context</em> <code> m:\mathcal  M </code> around.</p><p>Unsurprisingly, the easiest example of Tambara module is the hom-functor of any <code> \mathcal  M </code>-actegory. An example of this example is the case where <code> \mathcal  C=\mathcal  D=\mathcal  M </code> is cartesian and acting on itself. In this case, a Tambara module is a so-called <strong>cartesian profunctor</strong>, then transformations are given by <code> \mathcal  C(a,b) </code> and the Tambara structure is given by <code> \varphi  \mapsto  1_m \times  \varphi  </code>.</p><p>A less trivial example can be given by non-deterministic maps <code> \mathcal  C(a, Tb) </code> where <code> T </code> is a monoidal monad on <code> \mathcal  C </code>. Given a context <code> m:C </code>, the Tambara structure now lifts <code> \varphi  : a \to  Tb </code> to the morphism <code> m \times  a \to  T(m \times  b) </code> obtained by tensoring <code> \varphi  </code> with the unit of <code> T </code> and postcomposing with <code> T </code>'s monoidal laxator.</p><p>Finally, a fortiori, we'll see 'universally-many' Tambara modules can be obtained by considering the representable presheaves on the relevant category of optics as profunctors <code> \mathcal  C \to  \mathcal  D </code>, in particular that of costates when such a thing makes sense.</p><h3 id="the-pastro-street-adjunction">The Pastro-Street adjunction</h3><p>As with many structures, one might ask how to I equip the stuff I love with that. In the case of Tambara modules, we ask: if I already have a profunctor <code> P </code> of heteromorphisms I like, can I produce a Tambara module from it in a canonical way? And if yes, how?</p><p>The more seasoned category theorists in the audience might already guess there are two answers to this question: one is the 'minimal' one and the other is the 'maximal' one. Let's see how they look like.</p><p>Since the Tambara structure is a certain compatibility between the action of <code> m:\mathcal  M </code> and heteromorphisms <code> a \rightsquigarrow  b </code>, one might just think of weeding out all such morphisms that do not respect such a condition when <code> P </code> is equipped with the 'trivial' strength, that is, the one that looks for a simple embedding of <code> P(a,b) </code> in <code> P(m \bullet  a,m \bullet  b) </code>. In other words, we look for the 'largest subpresheaf' of <code> P </code> which can be equipped with a strength. A little bit of thinking yields the following definition:</p><code> \Theta  P(a,b) = \int _{m: \mathcal  M} P(m \bullet  a, m \bullet  b) </code><p>The only missing idea is realising that <code> \alpha  </code> can be given as <em>wedges</em> (see '<a href="https://arxiv.org/abs/1501.02503">Co/end calculus</a>', Definition 1.1.4) for the profunctors <code> (- \bullet  a, - \bullet  b) : \mathcal  M^\mathrm {op} \times  \mathcal  M \to  \mathbf {Set} </code>, naturally indexed by <code> (a,b):\mathcal  C^\mathrm {op} \times  \mathcal  D </code>.</p><p>It can be proven quite easily that <code> \Theta  </code> is left adjoint to the forgetful functor <code> U:\mathbf {Tamb}(\mathcal  C, \mathcal  D) \to  \mathbf {Prof}(\mathcal  C, \mathcal  D) </code>, as the category theorists already expected.</p><p>But there is also another way to turn a given <code> P </code> into a Tambara module, the 'maximal' way. In fact instead of getting rid from <code> P(a,b) </code> of all those heteromorphisms which don't appear in <code> P(m \bullet  a,m \bullet  b) </code>, we could forcibly add them to the latter. In other words, we look for the smallest Tambara module containing <code> P </code>. This leads us to another construction, right adjoint to <code> U </code>:</p><code> \Psi  P(a,b) = \int ^{m:\mathcal  M} \int ^{x:\mathcal  C,y:\mathcal  D} C(a, m \bullet  x) \times  P(x,y) \times  D(m \bullet  y, b) </code><p>The string of adjoints <code> \Psi  \dashv  U \dashv  \Theta  </code> generates an adjoint pair of a comonad <code> U\Theta  </code> and a monad <code> U\Psi  </code> on <code> \mathbf {Prof}(\mathcal  C,\mathcal  D) </code>, whose coalgebras and algebras, respectively, coincide and are exactly given by Tambara modules.</p><p>(Observation: as we'll see later, Tambara modules are copresheaves over optics. This gives another characterization/construction for <code> \Psi  </code> and <code> \Theta  </code>, namely as those functors <code> \mathbf {Psh}(\mathcal  C \times  \mathcal  D^\mathrm {op}) \to  \mathbf {Psh}({\mathcal  O_{\bullet , \bullet }}^\mathrm {op}) </code> induced by the 'trivial embedding' functor <code> \mathcal  C \times  \mathcal  D^\mathrm {op} \to  {\mathcal  O_{\bullet , \bullet }}^\mathrm {op} </code>, i.e. the one sending a pair of morphisms to a residual-less optic).</p><h3 id="profunctor-encoding-its-explicit-representation">Profunctor encoding &amp;amp; its explicit representation</h3><p>We are now ready to define profunctor optics [1]:</p><code> \mathcal  O_{\bullet , \bullet }((s,t),(a,b)) := \int _{P : \mathbf {Tamb}(\mathcal  C,\mathcal  D)} \mathbf {Set}(P(a,b),\,P(s,t)) </code><p>If Tambara modules give 'morphisms' from <code> \mathcal  C </code> to <code> \mathcal  D </code> which respect the given action, optics are defined as those transformations which 'pullback' these morphisms nicely.</p><p>The profunctor encoding selects the minimal common denominator of the opinions each Tambara module express about maps <code> \mathcal  C </code> into <code> \mathcal  D </code> in order to talk about the morphisms that supposedly respect it.</p><p>A neat side-effect of this definition is that profunctor optics can be composed 'simply by functional composition', under the end. This is one of the main practical advantages of the profunctor encoding. On the other hand, this definition is problematic because of the non-explicit nature of the encoding. Optics are 'carved out' from a very big set, and it's not clear what the result looks like.</p><p>This is when the profunctor representation theorem enters the scene:<br /><code> \int _{P : \mathbf {Tamb}(\mathcal  C, \mathcal  D)} \mathbf {Set}(P(a,b),\,P(s,t)) \cong  \int ^{m:\mathcal  M} \mathcal  C(s,m \bullet  a) \times  \mathcal  D(m \bullet  b, t) </code></p><p>The proof consists entirely of applications of the Yoneda lemma:<br /><code> \int _{P : \mathbf {Tamb}(\mathcal  C,\mathcal  D)} \mathbf {Set}(P(a,b),\,P(s,t)) </code><br /><code> = \int _{P : \mathbf {Tamb}(\mathcal  C,\mathcal  D)} \mathbf {Set}(\mathbf {Prof}(C,D)(y^{(a,b)}, P),\,P(s,t)) </code><br /><code> = \int _{P : \mathbf {Tamb}(\mathcal  C,\mathcal  D)} \mathbf {Set}(\mathbf {Tamb}(\mathcal  C,\mathcal  D)(\Psi  y^{(a,b)}, P),\,P(s,t)) </code><br /><code> = \Psi  y^{(a,b)}(s,t) </code><br /><code> = \int ^{m:\mathcal  M} \int ^{x:\mathcal  C, y:\mathcal  D} \mathcal  C(s, m \bullet  x) \times  y^{(a,b)}(x,y) \times  \mathcal  D(m \bullet  y, t) </code><br /><code> = \int ^{m:\mathcal  M} \mathcal  C(s, m \bullet  a) \times  \mathcal  D(m \bullet  b, t) </code></p><p>A corollary of this theorem is that</p><code> \mathbf {Tamb}(\mathcal  C, \mathcal  D) \simeq  \mathbf {Psh}({\mathcal  O_{\bullet ,\bullet }}^\mathrm {op}) </code><p>In fact:<br /><code> \int _{F : \mathbf {Psh}({\mathcal  O_{\bullet ,\bullet }}^\mathrm {op})} \mathbf {Set}(F(a,b),F(s,t)) </code><br /><code> = \int _{F : \mathbf {Psh}({\mathcal  O_{\bullet ,\bullet }}^\mathrm {op})} \mathbf {Set}(\mathbf {Psh}({\mathcal  O_{\bullet ,\bullet }}^\mathrm {op})(y^{(a,b)}, F),\,F(s,t)) </code><br /><code> = y^{(a,b)}(s,t) </code><br /><code> = \mathcal  O_{\bullet ,\bullet }((a,b)(s,t)) </code></p><p>The interesting thing is that we can talk about such morphisms despite the fact this mythical Tambara module (the initial Tambara module in the twisted arrow category) does not exist in general.</p><h3 id="coda-hybrid-composition">Coda: hybrid composition</h3><p>Just a quick observation: the profunctor encoding of optics makes it very explicit that optics of different flavours can be composed in certain cases. In fact, if we have actions <code> \bullet _{\mathcal  M} </code> and <code> \bullet _{\mathcal  N} </code> of both <code> \mathcal  M </code> and <code> \mathcal  N </code> on <code> \mathcal  C </code> and <code> \mathcal  D </code>, then we can produce an action of <code> \mathcal  M + \mathcal  N </code> on both.</p><p>The latter category is made of formal words made by interleaving objects (and morphisms) of the two summands. Analogously, one can use the two original actions to create a 'coproduct' action.</p><p>Now, evidently, Tambara modules for this action are also Tambara modules for the two original actions, since this action extends both. It turns out that</p><code> \mathbf {Tamb}{(\bullet _{\mathcal  M+\mathcal  N}, \mathcal  C),(\mathcal  D, \bullet _{\mathcal  M+\mathcal  N})} = \mathbf {Tamb}{(\bullet _{\mathcal  N}, \mathcal  C),(\mathcal  D, \bullet _{\mathcal  N})} \times _{\mathbf {Prof}} \mathbf {Tamb}{(\bullet _{\mathcal  M}, \mathcal  C),(\mathcal  D, \bullet _{\mathcal  M})} </code><p>Therefore profunctor optics for <code> \bullet _{\mathcal  M + \mathcal  N} = \bullet _{\mathcal  M} + \bullet _{\mathcal  N} </code> are less 'picky' than those for <code> \mathcal  M </code> and those for <code> \mathcal  N </code>, meaning that taking the end over Tambara modules for the first yields a bigger set than the ones for the latter. All in all, we get embeddings <code> \mathcal  O_{\bullet _{\mathcal  M}, \bullet _{\mathcal  M}} \longrightarrow  \mathcal  O_{\bullet _{\mathcal  M +\mathcal  N}, \bullet _{\mathcal  M+\mathcal  N}} </code><br />In other words, hybrid composition of optics happens by transporting both flavor of optics to a netural common ground and composing there.</p><p>Notice the idea we sketched here is quite more general: if we have a monoidal functor <code> \phi  : \mathcal  M \to  \mathcal  N </code> commuting with given actions on <code> \mathcal  C </code> and <code> \mathcal  D </code>, then we get a morphism <code> \phi ^\bullet  : \mathcal  O_{\bullet _{\mathcal  M}, \bullet _{\mathcal  M}} \longrightarrow  \mathcal  O_{\bullet _{\mathcal  N}, \bullet _{\mathcal  N}} </code>.</p><p>The second important side-effect of profunctor encoding is making this composition trivial enough to be inferred by the Haskell compiler (as far as I understand), by exploiting polymorphism. That said, as you see from the above discussion hybrid composition is not an explicit feature of this encoding but can we defined for different encodings as well, albeit less 'invisibly'.</p><h2 id="act-ii-existential-optics-or-the-case-for-open-diagrams">Act II - Existential optics, or the case for open diagrams</h2><p>After proving the profunctor representation theorem, one is left with a new, explicit, description of optics</p><code> \mathcal  O_{\bullet  , \bullet }((s,t),(a,b)) = \int ^{m:\mathcal  M} C(s,m \bullet  a) \times  D(m \bullet  b, t) </code><p>How to make sense of this? First, let's look at what this definition actually says: it tells us an optic is given by</p><ol><li>a choice of <em>residual</em> <code> m:\mathcal  M </code>,</li>



<li>a map <code> v: s \to  m \bullet  a </code> in <code> \mathcal  C </code>,</li>



<li>a map <code> u: m \bullet  b \to  t </code> in <code> \mathcal  D </code>;</li></ol><p>quotiented by the equivalence relation induced by the coend, which says morphism <code> \alpha  : m \to  m' </code> can <em>slide</em> between <code> v </code> and <code> u </code> without changing the optic.</p><p>I could write down what this equivalence relation is defined to be in symbols, but it's much much better to just draw it out. From now on, let's make a simplification and suppose <code> \mathcal  C = \mathcal  D = \mathcal  M </code> and <code> \bullet  = \odot  </code>.</p><p>In this situation, we can draw all the pieces of an optic as a string diagram in <code> \mathcal  C </code>:</p>
	<figure>
		<img src="/assets/2022/01/broken-comb.jpg" alt="" style="width:714px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
<p>It's almost instictive to join the two wires labelled by <code> m </code>, isn't it? So, is this instinct backed up by the maths? Yes! Indeed, this is exactly what the sliding relation is telling us to do, albeit enigmatically: it's telling us that 'beads' on the <code> m </code> wire can move freely from one side to the other of the diagram. Topologically, this is allowed iff the wires are connected. Moreover, this move embeds the equivalence relation in the notation itself, a major win.</p><p>So we remain with the following picture:</p>
	<figure>
		<img src="/assets/2022/01/whole-comb.jpg" alt="" style="width:683px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
<p>This is called a comb, and as you can see is a kind of wrapper around a morphism <code> a \to  b </code>. Indeed, one can still see the shadow of profunctor encoding: an optic is something that 'wraps' a transformation <code> a \rightsquigarrow  b </code> to yield one <code> s \rightsquigarrow  t </code>.<br />Composition of optics justifies this even further, as this time it's obtained by nesting combs, as suggested by the wrapping/pull back interpretation.</p><p>It's interesting to notice that, in principle, we are not limited to combs with two teeths only, that is, we could have combs wrapping more than one morphism, which represent computations that yield to the environment at some points, asking it to provide bits of it. Then interleaving combs, so that the teeth of one fill the holes of the another, provides a model of interacting computations (and more than two combs can be involved).</p><p>Interleaving is really the most general composition for combs, if we allow for 'incomplete' interleaving and 'degenerate' ones, that is, if we allow for interleaving to still leave some holes unfilled and if we see connecting combs side to side as a degenerate form of interleaving. This is something Jules (and others, like Davidad as far as I know) has been investigating in the last two years, trying to find a working definition of 'operad of combs' with an accompanying coherent diagrammatic language generalising the obvious drawings.</p><h3 id="string-diagrams-for-mixed-optics">String diagrams for mixed optics</h3><p>So, we've seen optics can be decomposed in three parts: a forward part, a backward part, and a residual wire linking them. The names forward/backward come from the observation that combs look a bit lopsides when it comes to see them as arrows. If we straighten them out:</p>
	<figure>
		<img src="/assets/2022/01/teleological-optic.jpg" alt="" style="width:364px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
<p>we can see them as morphism in a more conventional way, and we also realize the need to direct the wires of our diagrams: <code> v </code> and <code> u </code> receive data in opposite directions.</p><p>This way of drawing optics is key if we want to draw string diagrams for mixed optics, i.e. for those optics where <code> \mathcal  C, \mathcal  D </code> and <code> \mathcal  M </code> do not necessarily coincides.</p><p>In fact, as figured out by <a href="https://arxiv.org/abs/2002.11480">Guillaume Boisseau</a>, such diagrams can be conveniently interpreted as being drawin in the bicategory of <code> \mathcal  M </code>-actegories and Tambara modules between them.</p><p>As much as profunctors can be though as 'generalized functors' between categories, so can Tambara modules be thought as 'generalized linear functors' between actegories (as I said above, both are cases of 'categoriefied relations'). This means we can compose a Tambara module <code> \mathcal  C \to  \mathcal  D </code> with one <code> \mathcal  D \to  \mathcal  E </code> and obtain one <code> \mathcal  C \to  \mathcal  E </code>. Morphisms between Tambara modules (i.e., natural transformations commuting with the strenghts) make this a bicategory.</p><p>This is a good point to remember ourselves that string diagrams are defined for all bicategories, not just monoidal categories (i.e. one-object bicategories). The diagrams are so interpreted:</p>
	<figure>
		<img src="/assets/2022/01/tamb.jpg" alt="" style="width:;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
<p>To draw optics in <code> \mathbf {Tamb} </code>, one embeds <code> \mathcal  C, \mathcal  D </code> and <code> \mathcal  M </code> by using their hom-profunctors. The embeddings for <code> \mathcal  C </code> and <code> \mathcal  D </code> are given by:<br /><code> R_a = \mathcal  C(-, {=} \bullet  a) : \mathcal  C^\mathrm {op} \times  \mathcal  M \to  \mathbf {Set}, \quad  L_b = \mathcal  D(- \bullet  b, =) : \mathcal  M^\mathrm {op} \times  \mathcal  D \to  \mathbf {Set} </code><br />whereas <code> \mathcal  M </code> is embedded in both ways<br /><code> R_m = \mathcal  M(-, {=} \bullet  m), \quad  L_m = \mathcal  M(- \bullet  m, =) </code></p><p>Above, <code> R </code> stands for 'right' and <code> L </code> stands for 'left'. This hints at the fact that an object <code> R_a </code> will be drawn as a right-going wire, and an object <code> L_b </code> as a left-going one. You see that we use only one of the two kind of embeddings for <code> \mathcal  C </code> and <code> \mathcal  D </code>, since their objects have only one direction in <code> \mathcal  O </code>, whereas <code> \mathcal  M </code> admits both. This fact is very important since <code> \mathcal  M </code> becomes the only 'communication channel' between the forward and the backward parts. This is corroborated even further by the fact <code> \mathcal  M </code>-labelled wires bend:</p>
	<figure>
		<img src="/assets/2022/01/counit.jpg" alt="Counit for  L_m \overset {\mathbf {Tamb}}\dashv  R_m " style="width:345px;max-width: 100%;height:auto" />
		<figcaption>Counit for <code> L_m \overset {\mathbf {Tamb}}\dashv  R_m </code></figcaption>
	</figure>
<p>This bend is actually a (2-)morphism in <code> \mathbf {Tamb} </code>:</p><code> \varepsilon _m : \mathcal  M(-, {=} \bullet  m) \circ  \mathcal  M(- \bullet  m, =) \to  \mathcal  M(-, =) </code><p>defined by composition under the coend. Technically speaking, it is the counit of the proadjunction <code> L_m \overset {\mathbf {Tamb}}\dashv  R_m </code> (a <em>pro</em>adjunction being an <a href="http://nlab-pages.s3.us-east-2.amazonaws.com/nlab/show/adjunction">adjunction</a> between <em>pro</em>functors):</p><p>Now we can finally draw a mixed optic as an honest-to-goodness string diagram in the bicategory of Tambara modules:</p>
	<figure>
		<img src="/assets/2022/01/optic-in-tamb.jpg" alt="" style="width:483px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
<p>Notice that the embeddings we choose, and the shape of the diagrams we draw, are somewhat arbitrary: <code> \mathcal  C </code> and <code> \mathcal  D </code> also admit embeddings going the opposite way, and <code> L_x </code> is always left adjoint to <code> R_x </code>, no matter where <code> x </code> lives in. So in the bicategory of Tambara modules, we can draw a lot of stuff that 'violates' the contract of optics: only <code> \mathcal  M </code> can interact with both <code> \mathcal  C </code> and <code> \mathcal  D </code> at the same time.</p><p>This is the essence of the usefulness of optics in cybernetics: they explicitly model bidirectional computation (encoding action-reaction dynamics between a system and its environment) and they do so with an explicit 'agent subsystem', whose process theory is given by <code> \mathcal  M </code>, expressed by the residual. They are the ones with counits, which are a form of memory. I've written more about this <a href="https://matteocapucci.eu/open-cybernetics-systems-i-feedback-systems-as-optics/">here</a>.</p><h2 id="act-iii-counits-or-how-to-turn-your-world-upside-down">Act III - Counits, or how to turn your world upside down</h2><p>One might take seriously the idea that optics are what you get if you want objects going in two directions and a mediating family of counits which bends the directions. To seriously tackle this intuition, we have again to restrict ourselves to the case <code> \mathcal  C = \mathcal  D = \mathcal  M </code>.</p><p>In this case, one can indeed prove that optics is the category obtained by 'freely addings counits' to <code> \mathcal  C </code>, a fact expressible in the <a href="https://arxiv.org/abs/1704.02230">theory of teleological categories</a>. This is our third and final characterization of optics.</p><blockquote>
<p><strong>Theorem (Riley)</strong>. Non-mixed optics over a symmetric monoidal category <code> (\mathcal  C, I, \otimes , \sigma ) </code> are the free teleological category on <code> \mathcal  C </code>.</p>
<cite><a href="https://arxiv.org/abs/1809.00738">Categories of Optics, Riley</a></cite></blockquote><p>Indeed, a teleological category is a category equipped with a wide subcategory of dualisable objects and morphisms. In non-mixed optics, this is obtained by freely dualising all the morphisms of <code> \mathcal  C </code>, which is what happens when we add a 'backward part'. To account for residuals, we have the second ingredient of a teleological structure: counits, along which dualisable morphisms can slide to become their own duals. In non-mixed optics, residuals have exactly this function, as we notice when we realized optics as open dirgams: they allow sliding from the forward to the backward part.</p><p>So one proves Riley's theorem by 'surgery' of a non-mixed optic, realizing it can always be factored in three pieces: a part belonging to <code> \mathcal  C </code>, a part belonging to the 'dual' and a counit in-between:</p>
	<figure>
		<img src="/assets/2022/01/factorization.jpg" alt="" style="width:505px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
<h2 id="finale">Finale</h2><p>Hopefully, I managed to show you how optics arise in three different ways:</p><ol><li>as 'equivariant transformations' of data structures,</li>



<li>as open diagrams,</li>



<li>as free categories with counits.</li></ol><p>Each of this shows gives optics a certain attitude and adapts to certain intuitions. Observe as only the first two allow to treat the case of mixed optics, while the other way of getting optics is, for now, limited to the 'non-mixed' case.</p><p>Who knows, perhaps we are going to find a way to extend the last characterization to mixed optics too. It seems possible to define such a thing as a 'mixed teleological category', where counits are constructed from actegorical structure. Reasoning about these bends is also central if we want to understand how to syntactically represent iteration (or agent duality) in categories of optics, since unit-like structures seem to be naturally arising from such a proposition.</p>
	<figure>
		<img src="/assets/2022/01/interacting-feedback-systems.jpg" alt="" style="width:530px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
<p>More on this in the future!</p><h2 id="footnotes">Footnotes</h2><p>[1] At MSP we use a different convention on the 'direction' of optics, namely that an optic from <code> (s,t) </code> to <code> (a,b) </code> has a forward part going from <code> s </code> to <code> a </code>, instead of the other way around. The latter, adopted in papers such as '<a href="https://arxiv.org/abs/2001.07488">Profunctor optics: a categorical update</a>', is more natural when defining optics via the profunctor encoding, but quite unnatural when using optics as models of interaction.</p>      </div>
    </content>
  </entry>
  <entry>
    <title>Open cybernetic systems II: parametrised optics and agency</title>
    <published>2021-06-21T00:00:00Z</published>
    <updated>2021-06-21T00:00:00Z</updated>
    <author>
      <name>Matteo Capucci</name>
      <uri>https://matteocapucci.eu/matteo-capucci/</uri>
    </author>
    <link rel="alternate" type="text/html" href="https://matteocapucci.eu/open-cybernetic-systems-ii-parametrised-optics-and-agency/" />
    <id>https://matteocapucci.eu/open-cybernetic-systems-ii-parametrised-optics-and-agency/</id>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
<p>This post is the second in a series about open cybernetic systems, i.e. the categorical framework for cybernetics we have been developing at MSP and which is underlying the last two papers I coauthored.</p><p>Here's the whole plan of the series:</p><ol><li><a href="https://matteocapucci.eu/open-cybernetics-systems-i-feedback-systems-as-optics/">Open cybernetic systems I: feedback systems as optics</a></li><li><strong>Open cybernetic systems II: parametrised optics and agency</strong></li><li>Open cybernetic systems III: control mechanisms and equilibria (<em>coming soon</em>)</li><li>Bonus: Amazing backward induction (<em>coming soon</em>)</li></ol><h2>Parametrised optics and agency</h2><p>Last time, I described how optics can be a good formalism for feedback systems, i.e. systems whose dynamics happens in two stages (which I dubbed 'do' and 'propagate'), like the undertow on a beach. It often happens, in practice, that a system dynamics is not set in stone: someone can turn a knob and change the dynamics at will:</p><div>
	<figure>
		<img src="/assets/2021/06/table.jpg" alt="" style="width:537px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
</div><p>Ideally, an agent would fully control the dynamics, as a kid does with their toy plane. In practice, they don't, as pilots know: the knobs and switches and levers in the cockpit provide the only ways they can influence the plane. This is often enough to do what they want, but they surely can't specify arbitrary trajectories for their plane. The extent to which an agent can actually control a system is called <a href="https://en.wikipedia.org/wiki/Controllability">controllability</a> by control theorists [0].</p>
	<figure>
		<img src="/assets/2021/05/controllability-1.png" alt="You can add as many knobs as you want, Airbus, and yet the kid will beat you everytime. (credit: left, right)" style="width:;max-width: 100%;height:auto" />
		<figcaption>You can add as many knobs as you want, Airbus, and yet the kid will beat you everytime. (credit: left, right)</figcaption>
	</figure>
<p>The 'someone' who gets to play with knobs is usually an agent of some kind: players in a game, training algorithms in a neural network, or '<a href="https://en.wikipedia.org/wiki/Control_theory">controls</a>' in control theory. Observe that in all these examples, agents not only have a knob to turn but also have some kind of sensor that measures the state of the system and to which they can, ideally, react accordingly (indeed, a plane cockpit is full of knobs <em>and</em> gauges, screens, windows etc.).</p><p>Mathematically, speaking a knob selects a parameter <code> p </code> from a <strong>parameter space</strong> <code> P </code>, and a sensor shows an observation <code> q </code> from an <strong>observation space</strong> <code> Q </code>. In the case of the plane, <code> p </code> is the position of all knobs and levers in the cockpit (and elsewhere, if there are any), while <code> q </code> is the displayed reading of all sensors in the plane (radar, speed, pressure, etc.).</p><p>How do <code> P </code> and <code> Q </code> interact with an optic representing the system being controlled? First of all, <a href="https://matteocapucci.eu/open-cybernetics-systems-i-feedback-systems-as-optics/">recall</a> that an optic <code> (X,S) \rightleftarrows  (Y,R) </code> is given by two morphisms <code> \mathrm {do} : X \to  M \bullet  Y </code> and <code> \mathrm {propagate} : M \bullet  R \to  S </code> in a category <code> \mathbf  C </code>, where <code> M </code> is an object from a monoidal category <code> \mathbf  M </code> called the residual. This object is attached to <code> Y </code> and <code> R </code> using an 'heterogeneous monodial product' <code> \bullet  </code>, commonly know as an <em>action</em> of <code> \mathbf  M </code> on <code> \mathbf  C </code>.</p><p>Back to parameters and observations, we are going to assume they live in the same category <code> \mathbf  M </code> of residuals and we attach parameters to <code> X </code> and observations to <code> S </code> using again <code> \bullet  </code>. Thus we get a <strong>parametrised optic</strong> <code> (X,S) \overset {(P,Q)}{\rightleftarrows } (Y,R) </code> as a pair of morphisms <code> \mathrm {do} : P \bullet  X \to  M \bullet  Y </code> and <code> \mathrm {propagate} : M \bullet  R \to  Q \bullet  S </code>. Intuitively, the system now gets not just the 'environment state' <code> X </code> but also the 'control state' <code> P </code>, and returns not just the 'environment feedback' <code> S </code> but also the 'control feedback' <code> Q </code>. A more enthralling point of view is that state has been <em>decomposed</em> in what we consider going to the control and what we consider going to the environment, and likewise for feedback.</p><p>Visually, parameters and observations live in the same vertical direction we used to represent residuals: [1]</p><div>
	<figure>
		<img src="/assets/2021/06/para-optic.jpg" alt="" style="width:342px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
</div><p>The construction of a 'parametrised version' of a category is called <strong>Para </strong>(the mathematical aspects of which are the topic of a forthcoming paper with <a href="https://matteocapucci.eu/bruno-gavranovic/">Bruno</a> and <a href="https://tsmithe.net/">Toby</a>). It's a very cool construction, and quite general too. It takes a monoidal category <code> \mathbf  M </code> of parameters and an <em><code> \mathbf  M </code>-actegory</em> (meaning a category with an action <code> \bullet  </code> of <code> \mathbf  M </code>) <code> \mathbf  C </code> and produces another <code> \mathbf  M </code>-actegory <code> \mathbf {Para}_\bullet (\mathbf  C) </code> of <code> \mathbf  M </code>-parametrised <code> \mathbf  C </code>-morphisms. Explicitly, this category has the same objects of <code> \mathbf  C </code> and morphisms <code> X \to  Y </code> are given by a choice of <code> P </code> in <code> \mathbf  M </code> and a morphism <code> f : M \bullet  X \to  Y </code> in <code> \mathbf  C </code>. It turns out that if <code> \mathbf  C </code> was itself monoidal and <code> \bullet  </code> interacts nicely with such structure, then <code> \mathbf {Para}_\bullet (\mathbf  C) </code> is again monoidal.</p><p>The instance of the Para construction we propose in the <a href="https://arxiv.org/abs/2105.06332">cybernetics paper</a> (and which I outlined above) hinges upon the following fact: if <code> \mathbf  M </code> is acting on <code> \mathbf  C </code>, then we can get an action <code> \circledast  </code> of <code> \mathbf {Optic}(\mathbf  M) </code> on <code> \mathbf {Optic}_{\bullet }(\mathbf  C) </code> [2]. The resulting category <code> \mathbf {Para}_\circledast (\mathbf {Optic}\bullet (\mathbf  C)) </code> is what I described above, a category whose morphisms are optics with parameters and observations attached.</p><p>The graphical calculus of <a href="https://arxiv.org/abs/1704.02230">teleological categories</a>, that we used for optics, extends naturally to parametrised optics. Vertical wires/boxes represent objects/morphisms in the parametrising category, while horizontal wires/boxes represent objects in the parametrised category. This means I can finally show you how parametrised morphisms compose, directly in the case of interest of parametrised optics:</p>
	<figure>
		<img src="/assets/2021/06/para-optic-seq.jpg" alt="" style="width:;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
<h3>Reparametrisation</h3><p>The most important fact about the Para construction, however, is that the resulting category is actually a <em><a href="https://ncatlab.org/nlab/show/bicategory">bicategory</a></em>, i.e. a category with an additional layer of 'morphisms between morphisms'. Such 2-morphisms are called <em>reparametrisations</em>, so you might already guess what this is all about.</p><p>Formally, given <code> \varphi  : (X,S) \overset {(P,Q)}{\rightleftarrows } (Y,R) </code> and <code> \psi  : (X,S) \overset {(P',Q')}{\rightleftarrows } (Y,R) </code>, a reparametrisation <code> \phi  \Rightarrow  \psi  </code> is an optic <code> \alpha  :(P', Q') \rightleftarrows  (P,Q) </code> in <code> \mathbf  M </code> (hence a morphism in <code> \mathbf {Optic}(\mathbf  M) </code>, the parametrising category) such that <code> \psi  = (\alpha  \circledast  (X,S)) \fatsemi  \varphi  </code>. Usually, we start from <code> \varphi  </code> and <code> \alpha  </code> and <em>obtain</em> <code> \psi  </code> by interpreting the aforementioned equation as an assignment [3].</p><p>Visually, this looks like stacking <code> \alpha  </code> on top of <code> \varphi  </code>:</p><div>
	<figure>
		<img src="/assets/2021/06/repara.jpg" alt="" style="width:604px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
</div><p>This higher structure is crucial as it provides an expressive way to model <em>agency</em> mathematically. That is, if parameters are the way an agent can control and observe a system, reparametrisations (seen as 'optics in parameters-land') are the way agent process and react to the information going to and coming from the system of interest. Indeed, being optics themselves, reparametrisations can be considered 'systems within systems', a point of view I enthusiastically espouse.</p><p>Reparametrisations are also the crucial ingredient to reproduce a distinctive feature of systems with agents, namely non-compositional effects arising from the long-distance correlations the persistent identity of an agent induces in a system. These effects where fundamental in our paper about open games with agency, because this is how imperfect information (and the very concept of 'player') manifests in classical game theory: at different points of the game, the possible decisions a player can make are not independent. For example, <a href="https://en.wikipedia.org/wiki/Game_theoryPerfect_information_and_imperfect_information">players might not be able to distinguish among some of the states of the game</a> (states which might be 'causally' very far), hence they are forced to play the same strategy in distant parts of the game. Hence, by 'reparametrising along a copy', one can reproduce this situation, which otherwise would be impossible.</p>
	<figure>
		<img src="/assets/2021/06/copy.jpg" alt="Reparametrising along a copy forces the same action to be taken at two 'distant' points in the system.This phenomenon is known as 'weight tying' in machine learning." style="width:;max-width: 100%;height:auto" />
		<figcaption>Reparametrising along a copy forces the same action to be taken at two 'distant' points in the system.This phenomenon is known as 'weight tying' in machine learning.</figcaption>
	</figure>
<p>I called these are non-compositional effects because the resulting morphism <code> \Delta ^* (\phi  \fatsemi  \psi ) </code> lies <em>outside</em> the image of the composition map <code> \fatsemi  : \mathbf {Optic}((X,S), (Y, R)) \times  \mathbf {Optic}((Y,R), (Z,T)) \to  \mathbf {Optic}((X,S),(Z,T)) </code>, hence it literally can't be obtained by composition alone.</p><h3>Mereology of agency</h3><p><strong>Agency</strong> is the ability of bring about changes in a system. Oftentimes, this ability is exerted in order to bring about specific states of the system, those that are deemed optimal for whomever embodies agency. Agency is usually exterted through a control, as I described above with the plane example.</p><p>I prefer speaking about agency and not <em>agents</em> since the latter is a much more delicate concept. Agents presuppose agency and further decorate it with identity, but identity comes in a continuous spectrum, not in discrete quantities [4]. Therefore we end up talking about an amorphous blob of agents anyway. Most importantly, agents are not 'blackboxable' while agency is: by definition, I can't look in a black box and discern identity information about agents. In sum, from now on 'agent(s)' will be a shorthand for 'a distinguished part of a system imbued with agency', and does not presuppose anything about their numerosity or identity.</p><p>This whole premise already hints at the fact that <strong><a href="https://twitter.com/bgavran3/status/1404422281212923908">agency isn't an intrinsic property</a></strong> of a system. The mathematical manifestation of this fact is that parametrised optics are, at the end of the day, just optics, though presented in a particular form. We factor state and rewards in an 'environment' and an 'agents' part, although this factorization is somewhat arbitrary: we could put every agent in the environment without any noticeable mathematical difference.</p><p>This reflects an even deeper, if obvious, fact: agents <em>have</em> to place themselves in the environment in order to act on and observe a system. Therefore agents <em>are</em> a distinguished part of a given system, that we (the modelers) decide to treat separately from the rest. This manifests as an additional 'arbitrary' boundary between system, environment, and agents:</p><div>
	<figure>
		<img src="/assets/2021/06/mroloy.jpg" alt="" style="width:294px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
</div><p>As hinted <a href="https://matteocapucci.eu/open-cybernetics-systems-i-feedback-systems-as-optics/">last time</a> we covered environment-system boundaries, these are arbitrarily chosen in designing a model, and can be reabsorbed anytime. When dealing with the environment-system boundary, reabsorption resulted in closing up a system. Adding a second boundary effectively triples the possible reabsorptions we can perform, depending from the point of view we adopt.</p><p>Let's look again at a parametrised optic:</p><div>
	<figure>
		<img src="/assets/2021/06/mereology-of-agency-diag.jpg" alt="" style="width:419px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
</div><p>Where vertical wires (representing agents) meet horizontal boxes (representing the system), an action is used to substantiate agents as actual system-level entities, hence as system parts. As I anticipated above, this can be seen equivalently as decomposing state and feedback into environment and agents parts. Thus, <strong>from the point of view of the system, agents' decisions are part of the state of the environment</strong>. In other words, agents and environment are both external to the system, so the formers can be reabsorbed by the latter, restoring a single environment-system boundary.</p><div>
	<figure>
		<img src="/assets/2021/06/reabs1.jpg" alt="" style="width:458px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
</div><p>Considering the point of view of the environment, we get a similar picture, except now agents are reabsorbed by the system:</p><div>
	<figure>
		<img src="/assets/2021/06/reabs2.jpg" alt="" style="width:421px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
</div><p>Finally, one can consider the point of view of the agents. To them, system and environment are both external, hence they might as well be conflated together:</p><div>
	<figure>
		<img src="/assets/2021/06/reabs3.jpg" alt="" style="width:379px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
</div><p>This is the most interesting of the three reabsorption operations (perhaps because we usually are the agents, so we want to take their side). It shows really clearly how agents dealing with a (partially) closed system are effectively interacting with a black-box. It gets even more interesting when the parametrising category <code> \mathbf  M </code> comes with a triple adjunction <code> L \vdash  - \bullet  I \vdash  R : \mathbf  M \rightleftarrows  \mathbf  C </code>. In this case, the closed system agents interact with (which turns out to be given by a pair of maps <code> P \to  M \bullet  I \to  Q </code>) lifts to a literal costate in <code> \mathbf {Optic}(M) </code> (given by the map <code> L(P) \to  M \to  R(Q) </code>), therefore showing quite literally that such a situation is completely described by the agency dynamics.</p><div>
	<figure>
		<img src="/assets/2021/06/arena-lifting.jpg" alt="" style="width:;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
</div><p>The full mathematical treatment of this situation is not published yet, but we agree it's one of the most intriguing parts of the framework. We refer to the operation that turns a parametrised closed system into a costate in parameters as <strong><em>arena lifting</em></strong>, or <em>transposition</em> (hence the notation). Also, this reunites our treatment with other treatment of open dynamical systems, in which systems where modelled simply as lenses: we can imagine them as being systems of agents whose environment has not been modelled explicitly [5]</p><p>The addition of further mereological distinctions can continue beyond system and agents. Indeed, agents themselves can be subdivided in hierarchies of increasing detail. For instance, we can model the pilot-plane system as a parametrised optic, with the pilot control given by whatever the cockpit allows them to do. But then, we can reason, pilots are actually two, so we might decide to focus on <em>one</em> of the pilots. And we can go on: a pilot acts on the environment through their body, so we can consider the 'system' pilot as a cybernetic system where the pilot brain is in charge of the body which acts in the pilot-copilot duo which act on the plane. And so on, ad libitum. The mathematical reflection of these 'higher systems' is an iterated <code> \mathbf {Para} </code> construction: by letting the parametrising category be itself a parametrised category, we add one new mereological level, and so on. Higher systems we expect to describe are <a href="https://en.wikipedia.org/wiki/Cooperative_game_theory">coalitional games</a> and things like <a href="https://neuro.cs.ut.ee/demystifying-deep-reinforcement-learning/">deep Q-learning</a> (hence <a href="https://mitpress.mit.edu/books/theory-learning-games">learning theory for games</a>).</p><h3>Examples</h3><h4>A game</h4><p>The framework described above works wonderfully to represent games. Indeed, those are feedback systems with a very natural concept of agency in them, players. This crucial part was missing so far in <a href="https://arxiv.org/abs/1603.04641">compositional game theory</a> (<em>open games</em>), and we introduced it in <a href="https://arxiv.org/abs/2105.06763">our latest paper about the subject</a> [6]. In order to stress this, we baptized the new, extended framework as 'open games with agency'.</p><p>The key difference between open games with agency and 'classical' open games is the explicit use of parametrised lenses (let's work with <code> \mathbf  C = \mathbf  M = (\mathbf {Set}, 1 \times ) </code> here). In open games, parameters are called <em>strategies</em> (and we denote them with <code> \Omega _1, \ldots , \Omega _n </code>, where <code> n </code> is the number of players) and observations are limited to real-valued payoffs (so, aggregating everyone's payoff, a vector <code> \mathbb  R^n </code>). The system in which players act is what used to be called the game itself, though <a href="https://github.com/mattecapu/games-with-players/blob/master/main.pdf">we started calling it <em>arena</em></a> to stress the fact it's just part of a game (the horizontal 'system'). Arenas are often built by composing 'decisions', in which players observe the <em>state</em> of the game, and implement the chosen strategy to yield a <em>move</em> (this is the <em>action</em>, usually called <em>play </em>in the open games literature), and where they observe and propagate payoff (this is the <em>propagate</em> part, usually called <em>coplay</em>). In games, payoff propagation is usually quite boring since players don't do anything to it. It doesn't <em>have to</em> be like this, though, and there are situations in which non-trivial propagation is a fundamental part, such as <a href="https://en.wikipedia.org/wiki/Repeated_game">repeated Markov games</a> with <a href="https://en.wikipedia.org/wiki/Folk_theorem_(game_theory)Infinitely-repeated_games_with_discounting">discounting</a>:</p><div>
	<figure>
		<img src="/assets/2021/06/mdp.jpg" alt="The dots '...' mean we can repeat the  \mathcal  G  +  \mathcal  U  unit as many times as we want, potentially infinite [7]. The ground symbol is the discard operation, i.e. the unique morphism  !_A : A \to  1  from a given set  A ." style="width:;max-width: 100%;height:auto" />
		<figcaption>The dots '...' mean we can repeat the <code> \mathcal  G </code> + <code> \mathcal  U </code> unit as many times as we want, potentially infinite [7]. The ground symbol is the discard operation, i.e. the unique morphism <code> !_A : A \to  1 </code> from a given set <code> A </code>.</figcaption>
	</figure>
</div><p>In a <a href="https://en.wikipedia.org/wiki/Markov_strategy">Markov game</a>, the only thing remembered from one round to the next is the 'final state' of the game, that becomes the initial state of the next round. Crucially, players do not observe the game in-between rounds. So <code> \mathcal  G </code> here acts like a kind of state machine, where 'transitions' (moves) are decided by the strategies of each player. After a round is completed, payoffs are distributes among players: <code> \mathcal  U </code> is indeed observing the state of the game to generate a payoff vector (hence <code> \mathcal  G </code> + <code> \mathcal  U </code> behaves like a <a href="https://en.wikipedia.org/wiki/Mealy_machine">Mealy machine</a>).</p><p>In the vertical direction, we handle strategy and rewards distribution. Strategies are copied to be the same in each round, while rewards are computed by summing the payoffs obtained in each round. Moreover, we apply <em>discounting</em>, which means that payoffs from round <code> k </code> are multiplied by <code> \delta ^k </code>, where $latex 0 &amp;lt; \delta  &amp;lt; 1$. Ideally, this models the fact that 'future gains are less and less valuable', which is both a reasonable modelling assumption (people tend to do this) and a useful technical condition (because then you can repeat the game infinitely many times and still have a convergent sum).</p><p>This is how we model the dynamics of a game. In my next blog post, I'll describe how equilibria can be put in the picture.</p><h4>A learner</h4><p><a href="https://en.wikipedia.org/wiki/Generative_adversarial_network">GANs</a> are very interesting examples for this framework since they lie at the intersection of game theory and machine learning. Indeed, they're learners involved in a game: their joint behaviour is governed by game-theoretical laws but their dynamics is interpreted as that of a machine learning model.</p><p>This example is taken from <a href="https://arxiv.org/abs/2105.06332">our paper on categorical cybernetics</a>:</p><div>
	<figure>
		<img src="/assets/2021/06/screenshot-from-2021-06-14-22-50-47.png" alt="" style="width:633px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
</div><p>The system represented by this diagram is composed of two agents interacting a very simple way. The generator, <code> g </code>, is infused with random noise <code> z_i </code> (the <em>latent vector</em>) and produces a <em>fake vector</em> <code> x_i \in  \mathbb  R^x </code>. Here 'vectors' often means 'image', but it could be any kind of data. The discriminator, <code> g </code>, is fed both a <em>true vector</em> <code> d_i </code> (usually coming from a training set) and the fake vector <code> x_i </code> coming from <code> g </code>. The goal of the discriminator is to discern whether its inputs are real or fake.</p><p>The feedback system is given by reverse differentiation, hence the feedback signal is a gradient over the action signal. In particular, in this example there's no explicit loss function: the costates <code> dx </code> simply emit a <code> 1 </code>. The magic happens in the vertical direction: <code> g </code> performs gradient descent on its weights (that's the box <code> gd_\alpha  </code>, where <code> \alpha  </code> is the learning rate), while <code> d </code> performs gradient ascent (<code> ga_\alpha  = gd_{-\alpha } </code>). In this way, <code> g </code> is minimizing the 'fakeness' value <code> d </code> assigns to fake vectors, while <code> d </code> is maximizing the cost assigned to fake images and minimizing the cost assigned to real ones (that's why there's a <code> -dx </code> in the bottom right costate).</p><p>Notice how the two <code> d </code> boxes are tied together by vertical wiring. In particular, the wire <code> \mathbb  R^q </code> which represents the weights of <code> d </code> is copied and fed to both boxes, in order to make them embody <em>the same</em> discriminator both times. This is crucial to get the right training!</p><p>Notice also how, from the perspective of <code> g </code>, what's happening is normal training: everything concerning <code> d </code> is to it just a loss function, and <code> g </code> is learning to minimize that, a task that amounts to generate realistically looking vectors.</p><h4>Network communication</h4><p>Recently <a href="https://twitter.com/andre_videla">André Videla</a> gave a <a href="https://www.youtube.com/watch?v=4xpbYPa1lTc">talk</a> about structuring <a href="https://en.wikipedia.org/wiki/Representational_state_transfer">REST API</a>s as parametrised optics, which has been very exciting since he came up independently with this idea. In this example, agents are computers in a network, which interact through a REST API implementation. REST is a protocol for data exchange on HTTP, which allows clients to fetch and update data on a server. Unsurprisingly, these operations are easily modelled by optics (though it's non-trivial to map such bidirectional data accessors to an actual REST API implementation, kudos to André for figuring this out). Parametrisation becomes necessary to 'populate' the endpoints with actual data from the server, in other words, the vertical direction represents agents' state.</p><h3>Conclusions</h3><p>I hope I managed to convince you how, when combined, the <code> \mathbf {Para} </code> and <code> \mathbf {Optic} </code> constructions are able to model feedback systems with agency. Their mathematics beautifully showcases deep intuitions about the concepts of agency and control of a system. It captures parmetrisation and observations, and accounts for non-compositional effects typical of systems with agency.</p><p>In the next post, I'm going to show you how complex 'control mechanisms' can be described in this framework, thereby allowing us to analyze equilibria of games (and of other systems), to describe training of machine learning models, and equations of motion for Hamiltonian systems.</p><h2>Footnotes</h2><p>[0] Let me say that limited controllability, in many cases, is <em>a feature and not a bug</em>: systems with many degrees of freedom are very hard to govern, thus a limited quantity of control can be a boon. The classic example that comes to mind (and, ultimately, the reason we care about all this) is the way machine learning handles 'learning a function': we <em>parametrise</em> the space of functions and learn a parameter that best fits the true objective function. This is because function spaces are (1) intractably large, since they have infinitely-many degrees of freedom and (2) do not admit easy (or even <em>any</em>) representations of their elements.</p><p>[1] The usual way we draw these diagrams, that is, with vertical wires, can be misleading. Anything we draw above an 'horizontal' box is actually thought as living in the parametrising category, as the later diagrams describing reparametrisation shows. This is unsound, though. What's actually going on is that diagrams in the <em>parametrised</em> category should live on their own plane, while diagrams in the <em>parametrising</em> category should live in the (3D) space surrounding that plane, which we pictured as directed orthogonally to the plane. Actions (<code> \bullet  </code>) describe what happens when wires in the space cross the plane. There's a developing theory behind this calculus, accompanied by several results about the interaction of parametrised and parametrising monoidal categories ('what happens at the interface').</p><p>[2] Actually, in the paper we work in the generality of mixed optics. So the result is quite more general.</p><p>[3] Indeed, this is a reindexing operation: each hom-category in the bicategory of parametrised optics is <a href="https://www2.irb.hr/korisnici/ibakovic/sgc.pdf">2-fibred</a> over the delooping of <code> \mathbf {Optic}_\bullet (\mathbf  C) </code>.</p><p>[4] This idea is expressed, for instance, by <a href="https://en.wikipedia.org/wiki/Integrated_information_theory">Integrated Infromation Theory</a>, which can be regarderd as a 'theory of individuality' as explained in <a href="https://www.quantamagazine.org/what-is-an-individual-biology-seeks-clues-in-information-theory-20200716/">this beautiful Quanta article</a>.</p><p>[5] Let me expand a bit on this. The simplest way an open dynamical system can be modelled is a lens <code> (S,S) \rightleftarrows  (O,I) </code>. Here, <code> S </code> is a 'private' state, <code> O </code> is an output given the environment and <code> I </code> is an input received from the environment. In their book, Myers and Spivak call <code> S \to  O </code> the <em>expose</em> function since it exposes some observable of the internal state and <code> S \times  I \to  S </code> the <em>update</em> function as it updates <code> S </code> once feedback from the environment is received.<br />I interpret the asymmetry between the left and right boundaries of such a lens as witnessing the fact that this simple system really describes a control mechanism for a system, embedded (and lost) in the environment, and whose parameters and observations spaces are given, respectively, by <code> O </code> and <code> I </code>. To put it simply, I believe that such a system should be 'vertical' and not 'horizontal'.</p><p>[6] The problem is subtle and rich and interesting, hence solving it has been very thrilling. Actually (as the name 'open games with agency' testifies) we didn't put players in games, but simply <em>agency</em>. As argued above, this concept is more fluid and flexible, and allows us to treat players without worrying much about their identity. We live this concern to the only person who can look inside black boxes: the user. Also, we expect that such a fluid concept of agency will pay dividends when doing cooperative game theory, in which players can 'merge' in coalitions, which have all the characteristics of monolithic players.</p><p>[7]  Iterated games can be treated coalgebraically. An approach is sketched in <a href="https://arxiv.org/abs/1711.07968">this MSP paper</a>, though the framework used there was still rudimental. However, the same construction (up to adapting the notion of 2-cell used there) can be replayed in the new framework to yield similar results.</p>      </div>
    </content>
  </entry>
  <entry>
    <title>Open cybernetics systems I: feedback systems as optics</title>
    <published>2021-05-26T00:00:00Z</published>
    <updated>2021-05-26T00:00:00Z</updated>
    <author>
      <name>Matteo Capucci</name>
      <uri>https://matteocapucci.eu/matteo-capucci/</uri>
    </author>
    <link rel="alternate" type="text/html" href="https://matteocapucci.eu/open-cybernetics-systems-i-feedback-systems-as-optics/" />
    <id>https://matteocapucci.eu/open-cybernetics-systems-i-feedback-systems-as-optics/</id>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
<p>I coauthored my first two papers! [0] It's work I'm very excited about, and it actually tells a single story which I'd like to put together here, by sketching the bigger picture. Moreover, this is the same story behind my most recent talk, '<a href="https://github.com/mattecapu/games-with-players/blob/master/main.pdf">Games with players'</a>, so there's lots to talk about!</p><p>The papers stand in a theory-applications relationship. '<a href="https://arxiv.org/abs/2105.06332">Towards foundations of categorical cybernetics</a>' lays the theoretical foundations for the second one, '<a href="https://arxiv.org/abs/2105.06763">Translating from extensive form games to open games with agency</a>', though both works stand on their own. I wrote them with a bunch of <a href="http://msp.cis.strath.ac.uk/">MSP</a> people, you can look them up on the arXiv.</p><p>I started blogging about the papers two weeks ago, and the size of what was supposed to me one post spiralled out of hand. There's a lot ideas going around, and eventually I resorted to split the post in three parts plus a spin-off (which is actually an old resurrected draft):</p><ol><li><strong>Open cybernetic systems I: feedback systems as optics</strong></li><li><a href="https://matteocapucci.eu/open-cybernetic-systems-ii-parametrised-optics-and-agency/">Open cybernetic systems II: parametrised optics and agency</a></li><li>Open cybernetic systems III: control mechanisms and equilibria<em> (coming soon)</em></li><li>Bonus: Amazing backward induction<em> (coming soon)</em></li></ol><p>I'm going to introduce all the notions required to understanding our key idea, namely that <strong>parametrised optics</strong> are a good framework for formalising <em>agency</em> in open cybernetic systems. It's been known for a while that 'vanilla' optics do this for open dynamical systems (or <a href="https://www.youtube.com/watch?v=WkZPH3Vb5ug">more</a>), so our contribution is really in the 'parametrised = agency' part. Truth be told, that's also not completely new: notable precedents are '<a href="https://arxiv.org/abs/1711.10455">Backprop as a Functor</a>', in which the Para construction is first sketched and <a href="https://arxiv.org/abs/2103.01931">Bruno Gavranović's recent work</a>. Also, <a href="https://tsmithe.net/">Toby Smithe</a> has been <a href="https://www.youtube.com/watch?v=CoVKGFH6wRQ">playing around with a similar construction for active inference</a>, which is intimately related to the theory of cybernetic systems.</p><p>In these articles I'll assume familiarity with string diagrams (which, I argue, everybody is born with) and some basic categorical concepts, mainly from the world of monoidal categories. Sometimes I'll stray away but those are points for the 'advanced reader', which can be safely skipped by the uninitiated.</p><h2>Feedback systems as optics</h2><p>In categorical systems theory, various kinds of 'bidirectional morphisms with state' (which, we are about to see, is what <em>optics</em> means) have been used to represent dynamical systems. I argue a better word for what've been studying is <strong>feedback systems</strong>, since the kind of dynamics encoded by optics is that of action-reaction: in addition to the unfolding of an action, an optic also models a subsequent 'reaction propagation' step, where some kind of reward/loss/nudge (in a word: <strong>feedback</strong>) is returned to the system.</p><p>Contrast this with <a href="https://en.wikipedia.org/wiki/Dynamical_system">traditional dynamical systems</a>, whose dynamics is encoded by operators acting on a space, a mathematical model representing action but devoid of feedback. Nevertheless, considerable attention is devoled to the study of <strong>observables</strong> of a system, i.e. a (usually scalar) quantity of interest which we monitor during the dynamics. In particular, one is often interested in how these quantities evolve as the system itself evolves, and thus a dynamical system equipped with a distinguished observable turns out to be very similar to a feedback system.</p><p>Another common occurrence is that the evolution of the systems itself is guided by one or more observables. Think of <a href="https://en.wikipedia.org/wiki/Hamiltonian_mechanics">Hamiltonian mechanics</a>, in which a functional <code> h : X \to  \mathbb  R </code>, defined on the space <code> X </code> of phases of a physical system, orchestrates the whole dynamics (together with a symplectic form on <code> X </code>). In these cases 'feedback' is an even more apt terminology.</p><p>The kind of feedback systems me and <a href="http://msp.cis.strath.ac.uk/">my group</a> are most interested in are <strong>games</strong> and <strong>machine learning models</strong>. In both fields, action and feedback are equally important parts of the dynamics. In games, the 'action' part is called play and the 'feedback' part is payoff distribution, often in the form of <em><a href="https://en.wikipedia.org/wiki/Backward_induction">backward induction</a></em>. In machine learning models, they are called the 'forward' and 'backward' pass. The algorithm implementing the backward pass is <em><a href="https://en.wikipedia.org/wiki/Backpropagation">backpropagation</a></em>. I've written about the similarity between backward induction and backpropagation in the last post of this series (<em>coming soon</em>).</p><p>Nevertheless, <a href="https://matteocapucci.wordpress.com/2021/02/14/differential-forms-reverse-derivatives-and-machine-learning/">I've already blogged about</a> how backpropagation is secretely powered by the algebra of <strong>lenses</strong>. These are gadgets which pack bidirectional morphisms: a lens <code> (X,S) \rightleftarrows  (Y,R) </code> is a pair of maps <code> \mathrm {view}: X \to  Y </code> (or just 'forward part') and <code> \mathrm {update} : X \times  R \to  S </code> ('backward part'), which live in some <a href="https://ncatlab.org/nlab/show/cartesian+monoidal+category">category with products</a> <code> \mathbf  C </code>. The terminology surrounding them comes from the functional programming community, where lenses are a rudimental abstraction for accessing and 'mutating' data structures. [1]</p><div>
	<figure>
		<img src="/assets/2021/05/screenshot-from-2021-05-18-17-18-00.png" alt="Fig. 1: A lens" style="width:523px;max-width: 100%;height:auto" />
		<figcaption>Fig. 1: A lens</figcaption>
	</figure>
</div><p>One can see the forward part as bringing about an action and the backward part as propagating a feedback. This is very evident in backpropagation, where the forward part of a lens represents a function being computed and the backward part is a reverse derivative being pulled back in order to propagate the loss gradient. Hence, for us, 'do' and 'propagate' (sometimes abbreviated to <em>prop</em>) are better terms for 'view' and 'update'.</p><p>What's quite important in the definition of lenses is that 'propagate' has a dependency on <code> X </code>, the 'state'. This fact (witnessed by the wire branching before <code> {do} </code> and going down to <code> \mathrm {prop} </code>) is actually enforced by the composition law of lenses:</p><div>
	<figure>
		<img src="/assets/2021/05/lens-seq-comp.jpg" alt="" style="width:543px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
</div><p>In practical terms, this means that the feedback a lens propagates pertains to the computation actually happened, or that a lens, like the North, remembers.</p><p>This is made even more explicit in <strong>optics</strong>, a wide generalization of lenses. The leap in generality amounts to making the memory mechanism more expressive. Lenses remember <em>exactly</em> what they received from the environment in the form of a state, which is copied and preserved for the backward pass. In an optic, state is remembered, transmitted, and read out using a middleman, the <strong>residual</strong>. It is usually denoted by <code> M </code>, and features predominantly in the work we are doing, albeit on the sly [2]. This generalization also allows one to drop the assumption that <code> \mathbf  C </code> is cartesian, and work with an arbitrary category instead. Still, we usually want to assume <code> \mathbf  C </code> is at least monoidal, because it should stand for a category of systems, and monoidal categories allow the two most basic kinds of systems composition, sequential and parallel.</p><p>The memorization-transmission-readout mechanism is implemented through some clever mathematical machinery. First of all, residuals are assumed to live in their own category, the aptly-named and denoted category of residuals <code> \mathbf  M </code>. It is itself monoidal, and <em><a href="https://ncatlab.org/nlab/show/actegory">acts</a></em> on the category our optics are made of (<code> \mathbf  C </code>), meaning that we can multiply a given <code> M : \mathbf  M </code> with a given <code> A : \mathbf  C </code> (pretty much like a scalar multiplication allows you to multiply numbers and vectors, i.e. objects of different sorts) [3]. We denote such a product <code> M \bullet  A </code>.</p><p>A residual is attached to the codomain of the forward part and the domain of the backward part. An optic <code> (X,S) \rightleftarrows  (Y,R) </code> then looks like a pair of maps <code> \mathrm {do} : X \to  M \bullet  Y </code>, <code> \mathrm {propagate} : M \bullet  R \to  S </code>. So the 'do' part computes, from a given state in <code> X </code>, something in <code> Y </code> to give back to the environment and something in <code> M </code> to keep private. Then, given something in <code> M </code> (ideally, the readout of what we memorized in the forward pass) and some feedback in <code> R </code> coming from the environment, we can meaningfully propagate it to the environment. [4]</p><div>
	<figure>
		<img src="/assets/2021/05/optic.jpg" alt="" style="width:409px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
</div><p>Notice that vertical wires now live in a different category than horizontal ones. I draw them blue for this reason. Ideally, these wires are not even drawn on the same plane, they live in the transverse dimension, going in and out of the place (this also the reason why the residual wire takes that long detour). This dimension will be greatly exploited in the next post, when I'll introduce parametrised optics.</p><p>All in all, given a monoidal categories of residuals <code> \mathbf  M </code> acting on a monoidal category <code> \mathbf  C </code>, we get a monoidal category <code> \mathbf {Optic}_\bullet (\mathbf  C) </code> whose objects are pair of objects of <code> \mathbf  C </code> and morphisms are optics between them. Indeed, optics can be composed in sequence and in parallel:</p><div>
	<figure>
		<img src="/assets/2021/05/optic-seq-camp.jpg" alt="" style="width:518px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
</div><div>
	<figure>
		<img src="/assets/2021/05/optic-par-comp.jpg" alt="" style="width:675px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
</div><p>The unit for <code> \mathbf {Optic}(\mathbf  C) </code> is given by the pair <code> (I,I) </code>, an aptly invisible object in the diagrammatic language. This language can be thought of as 'living inside' <code> \mathbf  C </code> diagrammatic language, though this is not completely true as we see from the fact there are wires coming from another category. String diagrams for optics are diagrams for so-called <a href="https://arxiv.org/abs/1704.02230">teleological categories</a>.</p><h3>Context</h3><p>Insofar, I've spoken informally of 'environment', though it's mathematical nature is of utmost importance. For a system, 'environment' is everything that happens outside of its boundaries. More suggestively, <em>everything is environment</em> and to specify a system we cut a piece out. This mereological point of view will be greatly expounded in the next post, where we'll see that also agents arise by cutting a boundary.</p><div>
	<figure>
		<img src="/assets/2021/05/sys-env-informal.jpg" alt="" style="width:276px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
</div><p>For now, we limit ourselves to use this intuition to understand what's a <strong>context</strong> for an optic. A context is something you sorround an open system with to yield a closed system, i.e. something contained and finished in itself, whose dynamic can work without yielding to external parts.</p><p>This means that a closed system is necessarily of type <code> (I,I) \rightleftarrows  (I,I) </code>, a fact that manifests diagrammatically as an absence of wires going in or out:</p><div>
	<figure>
		<img src="/assets/2021/05/closed-sys.jpg" alt="Grey wires are invisible" style="width:363px;max-width: 100%;height:auto" />
		<figcaption>Grey wires are invisible</figcaption>
	</figure>
</div><p>Thus a context has to provide at least (a) an initial state and (b) a continuation, that is, something turning actions into feedbacks. These are respectively morphisms <code> (I,I) \rightleftarrows  (X, S) </code> and <code> (Y,R) \rightleftarrows  (I,I) </code>, also known as <strong>states</strong> and <strong>costates</strong>:</p><div>
	<figure>
		<img src="/assets/2021/05/state-costate1.jpg" alt="" style="width:710px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
</div><p>The graphical depiction of costates makes it very obvious why they can be considered 'continuations': they turn around the information flow, switching from 'action' mode to 'feedback' mode. While a costate amounts to two morphisms <code> Y \to  M \bullet  I </code> and <code> M \bullet  I \to  R </code>, you see how it can be easily converted into a single morphism <code> Y \to  R </code> by composition. If <code> \mathbf  M = \mathbf  C </code> and <code> \bullet  = \otimes  </code>, then the two things are equivalent (that is, any function <code> Y \to  R </code> can be made into a costate), but in general they are not: costates are only those morphisms that can be obtained by squeezing <code> Y </code> through a given residual, since this is the way the two parts of an optic can store and communicate information.</p><div>
	<figure>
		<img src="/assets/2021/05/state-costate2.jpg" alt="Slogan: 'time flows clockwise'.Flow happening in  \mathbf  C  in yellow, flow happening in  \mathbf  M  in orange." style="width:698px;max-width: 100%;height:auto" />
		<figcaption>Slogan: 'time flows clockwise'.Flow happening in <code> \mathbf  C </code> in yellow, flow happening in <code> \mathbf  M </code> in orange.</figcaption>
	</figure>
</div><p>It'd seem a state and a costate pair are enough to account for the environment, but there's still a subtlety. At the moment, the environment 'ceases to exists' as soon as the system dynamics kicks in. That is, there's no way for the environment to store state independently from the system, while when a system is doing its thing, usually <a href="https://en.wikipedia.org/wiki/Object_permanence">the rest of world still</a> <a href="https://www.smbc-comics.com/?id=3307">exists</a> [5]. Hence we are missing something like this:</p><div>
	<figure>
		<img src="/assets/2021/05/sys-env.jpg" alt="Labels are a bit confusing on this one: the red comb is what the totality of 'system's environment amounts to. The grey 'environment' box is the residual dynamics of the environment, namely what happens in the environment while 'system' is doing its thing." style="width:504px;max-width: 100%;height:auto" />
		<figcaption>Labels are a bit confusing on this one: the red comb is what the totality of 'system's environment amounts to. The grey 'environment' box is the residual dynamics of the environment, namely what happens in the environment while 'system' is doing its thing.</figcaption>
	</figure>
</div><p>When we put everything together we realize that the data of a context is given exactly by a <strong><a href="https://arxiv.org/abs/2004.04526v4">comb</a></strong> in the category of optics on <code> \mathbf  C </code>. A comb is a U-shaped diagram, with a hole in the middle. The red piece above is a comb, whose hole is filled by the system.</p><p>This is funny because <a href="https://arxiv.org/abs/1809.00738">optics themselves are combs</a> in <code> \mathbf  C </code>, as illustrated by this beautiful animation made by <a href="https://brunogavranovic.com/">Bruno</a>:</p><div>
	<figure>
		<img src="/assets/2021/05/optic_e28692_comb-2.gif" alt="" style="width:447px;max-width: 100%;height:auto" />
		<figcaption />
	</figure>
</div><p>Hence a compact way to define contexts for a system <code> (X,S) \rightleftarrows  (Y,R) </code>  is as 'states in optics of optics' (!!), i.e. combs in <code> \mathbf {Optic}(\mathbf  C) </code> whose external boundaries are trivial (the unit) and whose internal boundaries are the ones of the system. [6]</p><p>This fits beautiful into the mereological picture of system and environment: a system is a hole in an environment, which 'wraps' the system itself. Putting them together yields an inscrutable closed system. Also, let me stress again how boundaries of a system are a modelling choice. This is quite clear when we consider the composite of two systems: to each of the composee, the other one is part of the environment.</p><h3>Variants &amp;amp; technological horizons</h3><p>I can't abstain from mentioning that, at the moment, two separate generalizations of 'lenses' are present in the literature. One is what I described above, known in the most general form as <strong>mixed optics</strong> or <strong><a href="https://arxiv.org/abs/2001.07488">profunctor optics</a></strong> (these are an equivalent presentation of the same objects). The other one is <strong><a href="https://arxiv.org/abs/1908.02202">F-lenses</a></strong>, which are themselves a generalization of dependent lenses aka <a href="https://www.cs.nott.ac.uk/~psztxa/publ/fossacs03.pdf">containers</a> aka <a href="https://arxiv.org/abs/2005.01894">polynomial functors</a>.</p><p>This latter framework is quite important, especially as used in the work of <a href="https://arxiv.org/abs/2005.05956">Myers</a>, <a href="https://github.com/DavidJaz/DynamicalSystemsBook/tree/master/book">Spivak</a>, <a href="https://www.youtube.com/watch?v=cjti9KdXLY4&amp;t=3s">Libkind</a> and others. Its strength lies in the fact they feature dependent types, which are very expressive and arguably the right way of doing certain things (i.e. <a href="https://www.youtube.com/watch?v=U-W7GT0BUTU">mode-dependent dynamics</a>). It also generalizes further in the direction of <strong><a href="https://arxiv.org/abs/0906.4931">indexed containers</a></strong>, which in turn form the mathematical matter of <a href="https://arxiv.org/abs/0905.4063">Hancock's <strong>interaction structures</strong></a>,  perhaps the most conceptually sharp treatment of feedback systems around.</p><p><strong><em>Dependently-typed mixed optics</em></strong> are thus the holy grail in this area and something me, <a href="https://matteocapucci.eu/bruno-gavranovic/">Bruno</a>, <a href="https://matteocapucci.eu/jules-hedges/">Jules</a> (who <a href="https://julesh.com/2020/06/10/towards-dependent-optics/">blogged about it</a> last year) and <a href="https://matteocapucci.eu/eigil-fjeldgren-rischel/">Eigil</a> have been actively worked on in the last few months. They would allow the flexibility of optics, especially their indifference towards cartesian structure (very uncommon in <a href="https://arxiv.org/abs/1409.5531">resource theories</a>) and at the same type the expressive power of dependent types. I hope we'll soon have good news on this front!</p><p>Finally, there's a pretty important bit that I swept under the rug in this article, which is that usually residuals are not kept explicit in optics. Optics are in fact defined as a quotient, using a coend indexed by residuals. The equivalence relation is generated by 'slidings':</p>
	<figure>
		<img src="/assets/2021/05/slidings.png" alt="From 'Open diagrams via coends', by Mario Román." style="width:;max-width: 100%;height:auto" />
		<figcaption>From 'Open diagrams via coends', by Mario Román.</figcaption>
	</figure>
<p>My impression is that something more should be said about this point. For example, there's merit in keeping the 'hidden dynamics' of a context explicit. On the other hand, equivalence under sliding is a very reasonable condition. A way to resolve this tension is to turn the quotient into a groupoid, i.e. remember slidings as invertible 2-cells between optics. This fits very well with the philosophy behind the construction I'll describe in the next post, Para.</p><h3>Conclusions</h3><p>I hope I managed to conveyed what's my intuition of feedback systems, namely as bidirectional morphisms whose mathematical incarnation is some flavour of optics. Residuals memorize information from the actions executed in the forward pass in order to effectively elaborate feedback in the backward pass. When a system is paired up with a context, it yields a closed system.</p><p>Next time, we are going to see how <em>parametrised</em> optics model agency in feedback systems. This will be a first step toward modelling cybernetic systems themselves, which are feedback systems with agency in a control loop.</p><h3>Further reading</h3><p>A list of further resources on this topic. It's probably gonna grow as things to add come to my mind.</p><ul><li><a href="https://www.brunogavranovic.com/posts/2021-03-03-Towards-Categorical-Foundations-Of-Neural-Networks.html">Towards categorical foundations of learning</a>, blog post by Bruno Gavranović, featuring more nice animations of optics and some insights I didn't cover here.</li><li><a href="https://www.youtube.com/watch?v=8T-Km3taNko">A general definition of open dynamical system</a>, talk by <a href="https://matteocapucci.eu/david-jaz-myers/">David Jaz Myers</a>, featuring a lot of very cool mathematical insights.</li><li><a href="https://arxiv.org/abs/1910.03656">Bayesian open games</a>, paper by Jules Hedges and Jon Bolt, featuring full-blown optics-as-feedback-systems in the wild.</li></ul><h2>Footnotes</h2><p>[0] Yeah, I went from zero to two in one shot, which has resulted in a pretty hectic writing spree.</p><p>[1] Truth be told, 'lenses' in FP are usually limited to what I'd call 'monomorphic lawful lenses'... There's a bunch of conflicting terminology around here. <a href="https://julesh.com/2018/08/16/lenses-for-philosophers/">Here's some</a> historical/etymological background.</p><p>[2] There's a bit of a fight around here: usually residuals are 'quotiented out' (see [4]) and thus become implicit. I make the case residuals should be explicit. More on this in the part about agency.</p><p>[3] To be fair, this happens if <code> M </code> acts 'multiplicatevely', an informal term meaning that <code> M \bullet  A </code> is sort-of a combination of <code> M </code> with <code> A </code>, and <a href="https://arxiv.org/abs/2001.07488">not some other weird thing</a>. These 'other weird things' are actually quite interesting and totally deserved to be considered optics, though the dynamical intution falters a bit there.</p><p>[4] The missing bit of math in this description is a coend, dealing with equivalence of optics. A good reference about optics is <a href="https://arxiv.org/abs/1809.00738">Riley's paper</a>. The full definition of mixed optics can be found <a href="https://arxiv.org/abs/2001.07488">here</a>. You can read more about coends in the <a href="https://arxiv.org/abs/2004.04526v1">Fosco's amazing book on the subject</a>, I won't go down this rabbit hole here.</p><p>[5] A curious fact is that combs do indeed model object permanence only if the resource theory we are using to represent the world is <em>not</em> <a href="https://ncatlab.org/nlab/show/semicartesian+monoidal+category">semicartesian</a>. In fact, in that case the definition of a context would collapse and be equivalent to the sole data of an initial state (see Proposition 2.0.7 <a href="https://arxiv.org/abs/1809.00738">here</a>), thereby trivializing whatever 'hidden dynamics' the world would have. Indeed, if the unit is terminal, there's only one closed system and it is trivial.</p><p>[6] Notice, moreover, that double optics now provide a 'theory of open contexts' for a given system. An open context is one whose domain as a double optic (or external boundary as a comb) is not the unit, so it actually acts as a middleman between a system and its environment, without closing it up. It can be considered a <em>blanket</em>, <a href="https://en.wikipedia.org/wiki/Markov_blanket">borrowing Pearl's terminology</a>.<br />One can make a wonderful use of this to model sequential games with imperfect information. The 'system' we are considering now is a single decision of this game: it receives the state of the game and outputs a move, and its feedback is given by the final payoff of this decision. Open contexts can be used to beautifully manage state in this setting. They filter the incoming state of the game in order to hide information which is not available to the player (but existing nevertheless) at that time, e.g. cards other players have in their hand. Then we use the move chosen by the player, together with the (hidden) state of the game to update the overall state of the game. These 'wrapped decisions' can be then composed in sequence to get the desired game.<br />A setting in which open contexts shine even more is <a href="https://arxiv.org/abs/1910.03656">Bayesian games</a>. In this case, you really see how contexts do not collapse down to state-costate pairs, because Bayesian games make crucial use of non-lenticular optics. I speculate in this setting contexts really amount to Markov blankets.</p>      </div>
    </content>
  </entry>
  <entry>
    <title>Differential forms, reverse derivatives and machine learning</title>
    <published>2021-02-14T00:00:00Z</published>
    <updated>2021-02-14T00:00:00Z</updated>
    <author>
      <name>Matteo Capucci</name>
      <uri>https://matteocapucci.eu/matteo-capucci/</uri>
    </author>
    <link rel="alternate" type="text/html" href="https://matteocapucci.eu/differential-forms-reverse-derivatives-and-machine-learning/" />
    <id>https://matteocapucci.eu/differential-forms-reverse-derivatives-and-machine-learning/</id>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>I was recently trying to convince <a href="https://www.brunogavranovic.com/">Bruno</a> that covectors (in the form of differentials of functions) are the real deal in gradient descent, despite the misleading name and countless pictures showing little arrows pointing downhill.</p>
        <p>The reasons are two:</p>
        <ol>
          <li><strong>Derivatives are </strong>really<strong> differential forms</strong>, not vector fields (huge pedagogical confusion on this point, since derivatives are sold everywhere as 'tangent vectors at a point').</li>
          <li><strong>Reverse derivative</strong> (the star of backpropagation) <strong>is</strong> actually <strong>pullback of differential forms</strong> in disguise.</li>
        </ol>
        <p>I believe the culprit of the confusion is the constant abuse of Euclidean spaces and the conflation of their tangent vectors with their points, or even worse, the habit of identifying tangent fibers on different points. Euclidean spaces are cool but very special as manifolds. Therefore if you want to know the full story of differential geometry you really shouldn't focus on them as an example.</p>
        <p>Add to this the ubiquity of Riemannian and symplectic structures, which allow one to freely identify tangent and cotangent spaces by raising and lowering indices, and you get a recipe for disaster.</p>
        <h2>Derivatives are differential forms</h2>
        <p>Let's look at the first idea: derivatives are differential forms. This is almost tautological in the way things are defined, since the cotangent bundle is defined exactly as the bundle of differentials over a manifold hence <em>of course</em> the differential of a function is a section of this.</p>
        <p>On the other hand, one may understand it in the following way: a smooth function is also a map of smooth manifolds, say <code> f:M \to  \mathbb  R </code>, therefore it induces a map between its tangent bundles <code> Tf : TM \to  T\mathbb  R </code>. But then each fiber of <code> T\mathbb  R </code> can be <em>canonically</em> identified with a single copy of <code> \mathbb  R </code>, so that <code> Tf </code> is a fiberwise linear functional, i.e. a differential form.</p>
        <p>In 1-dimensional Euclidean differential geometry, aka calculus, this is witnessed by the definition
<code>
	df = f' dx
</code>
which students usually think of as a byproduct of
<code>
	\dfrac {df}{dx} = f'
</code>
at which teachers angrily react by screaming <em>yOu cAn'T diViDe bY a diFFeRenTial</em>!</p>
        <p>In general, working in local coordinates one still gets
<code>
	df = \dfrac {\partial  f}{\partial  x_i} dx^i
</code>
which could make one think, <em>well, what's wrong in defining</em>
<code>
	\partial  f = \dfrac {\partial  f}{\partial  x_i} \partial  x_i
</code>
which, by the way, is obviously true: you can simplify <code> \partial  x_i </code> and get an identity (inflicting mortal damage to the teacher left agonizing from the previous paragraph).</p>
        <p>This works <em>locally</em>: indeed, the coordinate patch you choose allows you to pretend you're actually working in some patch of <code> \mathbb  R^n </code>, where it <em>really</em> works. To make it work <em>globally</em>, you need to make sure the identification <code> dx^i \mapsto  \partial  x_i </code> you choose glues along with your coordinate patches, i.e. can be extended to a global bundle isomorphism <code> TM \cong  T^*M </code>.</p>
        <p>This can be made more familiar if we realize that the data of an isomorphism <code> \varphi  : V \to  V^* </code> for a finite dimensional vector space is equivalently expressed as a <a href="https://en.wikipedia.org/wiki/Degenerate_bilinear_form">non-degenerate bilinear form</a> on <code> V </code> (i.e. bilinear maps <code> \langle  -, = \rangle  : V \times  V \to  V </code> which are iso on either slot). This is <a href="https://en.wikipedia.org/wiki/Riesz_representation_theorem">Riesz's theorem</a> in finite dimension, basically, and it's readily proven: given <code> \varphi  </code>, one can define <code> \langle  v, w \rangle  = \varphi (v)(w) </code>, and given <code> \langle  -, = \rangle  </code> one can define <code> \varphi (v) = \langle  -, v \rangle  </code> <em>*mumbles something about Yoneda*</em>.</p>
        <p>Therefore this global correspondence we are looking after is equivalently a smooth choice of such bilinear forms on each tangent space. When these forms are symmetric (i.e. <code> \langle  v, w \rangle  = \langle  w, v\rangle  </code>), the data is called a <a href="https://en.wikipedia.org/wiki/Riemannian_manifold">Riemannian metric</a>. When they're skew-symmetric (<code> \langle  v, w \rangle  = -\langle  w, v\rangle  </code>) it's a <a href="https://en.wikipedia.org/wiki/Symplectic_manifold">symplectic form</a>. Also using (one of) the isomorphisms induced by a bilinear form is called <a href="https://en.wikipedia.org/wiki/Raising_and_lowering_indices">raising or lowering indices</a>, especially in the context of Riemannian geometry, where these two operations are denoted with <code> \sharp  </code> and <code> \flat  </code>, respectively.</p>
        <p>Since Riemannian and symplectic structures are very common in the wild, the distracted pupil, full of hỳbris, might think that <code> \partial  f </code> (which is then called the <em>gradient</em> of <code> f </code>) is as intrinsic as <code> df </code> and thus that vectors triumphed over covectors.</p>
        <p>But they flied too close to the Sun and burned themselves, because <strong>gradients are not intrinsic objects</strong>! They depend on the specific choice of Riemannian or symplectic structure, and these choices can be wildly non unique. Moreover, 'being a gradient' <a href="https://mathoverflow.net/a/301874/50376">is not even invariant under change of metric</a> or symplectic structure!</p>
        <p>In other words, derivatives are not vector fields, but differential forms!</p>
        <h2>Reverse derivative is pullback of forms</h2>
        <p>Machine learning is firmly grounded on backpropagation these days, which is an algorithm that allows to compute 'the gradient' of a loss function in an efficient (compositional) way.</p>
        <p>Let's be more explicit: suppose you have <em>data set</em> <code> (x,y) </code> where <code> x = x_1, \ldots , x_n </code> are <em>examples</em> and <code> y = y_1, \ldots , y_n </code> are their <em>labels</em>. The goal of (most of) machine learning is to create models which can generalize this correspondence to new <code> x' </code> never seen before. The classic example is when <code> x </code> is a set of images, <code> y </code> is a set of labels such as 'cat', 'dog', 'bird', and so on, and I want to build a model which can recognize cats, dogs, birds and so on in images never seen before.</p>
        <p>When I say 'model' I just mean a function from <code> x </code>s to <code> y </code>s. When I say 'build' I mean trying to come up with a nice form for this function (e.g. a neural network) and then <em>training</em> it as we train calculus students: show them a problem, ask them to solve it, and then evaluate their solutions by comparing them with the correct ones we know in advance.</p>
        <p>So we have a function <code> E(x,y') </code> which given the problem set and the tentative solution <code> y' </code>, grades the student with a number, except that usually in machine learning <code> 0 </code> is the highest (suspiciously high, actually) mark. In fact <code> E </code> is called <em>error </em>or <em>loss</em>, and evaluates 'how much wrong' the proposed solution is.</p>
        <p>As in teaching, model training works in rounds: after each assignment, we (hopefully) tell students what they did wrong so that next time they will (hopefully) perform better. Brains have figured out how to update themselves inbetween evaluation round, but machine learning models not yet (emphasis on <em>yet</em>). So the trainer (usually in the form of an automated algorithm) looks at the loss, and tunes the model accordingly.</p>
        <p>This automated algorithm is 99% of the time a form of <em>gradient descent</em>, which works in the following way: to minimize the loss, just go down its gradient until you find a minimum. So, as in a calculus course, gradient descent works under the assumption that <strong>learning means minimizing the loss</strong>, also called <em>training error</em>.</p>
        <p>Now, the problem backpropagation solves is this: if the model is a very complicated function <code> f </code>, computed in many possibly non-linear steps, how do we efficiently compute the gradient of <code> E(x, f(x)) </code>?</p>
        <p>The idea is to 'propagate back' (hence the name) such a gradient by exploiting the chain rule to break down the gradient of the 'big' <code> f </code> (say, a neural networks) into the many gradients of its 'small' constituents (say, layers or neurons of the network).</p>
        <p>Long story short, this can be done by extracting, from a function <code> f : \mathbb  R^m \to  \mathbb  R^n </code>, its <em>reverse derivative</em> <code> Rf : \mathbb  R^m \times  \mathbb  R^n \to  \mathbb  R^m </code>, defined as
<code>
	Rf(x, y) = y^\top  J_f(x) .
</code>
Here <code> J_f </code> is the <a href="https://en.wikipedia.org/wiki/Jacobian_matrix_and_determinant">Jacobian matrix</a> of <code> f </code>, which is the coordinate expression of its derivative.</p>
        <p>Then the reverse derivative of a composite is the composite of the reverse derivatives (if we perform composition right, i.e. <a href="https://www.philipzucker.com/reverse-mode-differentiation-is-kind-of-like-a-lens-ii/">we consider the pair <code>(f, Rf)</code> a lens</a>, more <a href="https://arxiv.org/abs/1910.07065">here</a>).</p>
        <p>Neat!</p>
        <p>But <strong>what's a reverse derivative, for Levi-Civita's sake?</strong> The biggest hint to the truth is given by the way reverse derivatives are sometimes written in the 1-dimensional case:
<code>
	Rg(x, dy) = g'(x) dy .
</code>
Despite being nonsensical with the typing I gave you (which is the usual type they're given, unfortunately), it points us the right direction: first, let's rename <code> \mathbb  R^n </code> and <code> \mathbb  R^m </code> as <code> N </code> and <code> M </code>, to not be tempted to use their Euclidean pudding of structure. Then <code> f </code> has now type <code> M \to  N </code>.</p>
        <p>Then we take the hint above to type <code> Rf </code> as <code> M \times  T^* N \to  T^* M </code>. So now that <code> dy </code> really makes sense. Also it's important to point out <code> M \times  T^*N </code> should really be the pullback of <code> T^* N </code> along <code> f </code> (which, incidentally, <em>is</em> a Cartesian product if done in the right category), since we want our assignment to respect the structure of the cotangent bundle.</p>
        <p>Now, what's pullback of differential forms? A smooth map of manifolds induce a map between their tangent bundles, its <em>differential</em>. Then its fiberwise <a href="https://en.wikipedia.org/wiki/Transpose_of_a_linear_map">dual</a> is the pullback of forms. Concretely, given <code> f:M \to  N </code>, pullback of forms is the map of bundles <code> f^* : T^*N \to  T^*M </code> given on a differential form <code> \alpha  </code> on <code> N </code> by
<code>
	f^* \alpha  = \alpha  \circ  df
</code>
To see this is indeed the reverse derivative, let's go back to the Euclidean case: <code> df </code> is the Jacobian of <code> f </code>, <code> J_f </code>, and if we represent <code> \alpha  </code> in matrix form, it is given on each point by a <strong>row</strong> vector, because dualizing in the Euclidean case corresponds to transposition. Thus if <code> y </code> represents <code> \alpha  </code>, <code> y^\top  </code> is its matrix form.<br />Finally, since composition of linear maps corresponds to multiplication of their associated matrices, we retrieve the initial expression.</p>
        <h2>Epilogue</h2>
        <p>Although in most cases Euclidean spaces are all it's needed, it makes sense to have a differential geometric expression of reverse derivative for two reasons: first, it may help to clarify what's going on, and second, it immediately generalizes to <a href="http://geometricdeeplearning.com/">learning on manifolds</a>, which <a href="https://www.quantamagazine.org/an-idea-from-physics-helps-ai-see-in-higher-dimensions-20200109/">isn't exactly useless</a>.</p>
        <p>Also an interesting corollary of all this story is that, in general, reverse derivatives do not organize in plain lenses, but instead in <a href="https://arxiv.org/abs/1908.02202">generalized lenses in the sense of Spivak</a>. It also helps to see the difference between the horizontal and vertical category of <a href="https://arxiv.org/abs/2005.05956">Myers' differential doctrines</a>, if you know what I'm talking about: horizontal is about mapping systems in other systems, therefore <code> T </code> are used there, while in the vertical category of systems, <code> T^* </code>  is to be used.</p>
        <p>To finish my rant, let me also explain <em>why</em> it makes sense, conceptually, to backpropagate a covector and not a vector.</p>
        <p>First of all, since we've seen in the previous section that derivatives are covectors, which can be turned into vectors (the gradient) by raising indices with a metric or a symplectic form, it should be obvious that the problem of propagating the derivative is actually the problem of propagating a covector.</p>
        <p>Secondly, what is, intuitively, the differential of a function? It's an infinitesimal representation of a function: at a point <code> x </code>, <code> df </code> is the infinitesimal change of <code> f </code> along a given direction vector <code> v \in  T_x M </code>. Apply this to a loss: it gives us an infinitesimal representation of the loss around the current choice of parameters of our model (say, the weight of a neural network), enabling us to 'judge' each proposed change of parameters (a tangent vector). We then use gradients because we want to actually move from our current parameter to a new one, and motions are given by vectors. A Riemannian metric, then, allows us to implement such a change by moving along a geodesic emanating from the parameter we are now (this is <a href="https://www.jair.org/index.php/jair/article/view/12192">gradient descent on Riemannian manifolds</a>). Choose a different metric and the same loss function will select a different direction of descent, because we changed what 'down' means (think: geodesic motion in general relativity).</p>
        <h2>Further work</h2>
        <p>Interestingly, this whole business of losses as differential forms is what Hamiltonian mechanics is based on. That is, while the dynamics of a system are encoded by vector fields, the energy landscape of a system is encoded in a function <code> h </code> which has the same role of a loss function. Dynamics is extracted by means of a symplectic form which implements the changes entailed by <code> h </code> into actual motions. This is explained <a href="https://github.com/mattecapu/hamiltonian-mechanics/blob/master/main.pdf">in Section 3.2 of my notes</a> about the symplectic formulation of Hamiltonian mechanics.</p>
        <p>The similarity is so striking that one could bet that <a href="https://en.wikipedia.org/wiki/Euler%E2%80%93Lagrange_equation">Euler-Lagrange equations </a>may actually be used to express the solution of machine learning problems.</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Why math?</title>
    <published>2020-12-09T00:00:00Z</published>
    <updated>2020-12-09T00:00:00Z</updated>
    <author>
      <name>Matteo Capucci</name>
      <uri>https://matteocapucci.eu/matteo-capucci/</uri>
    </author>
    <link rel="alternate" type="text/html" href="https://matteocapucci.eu/why-math/" />
    <id>https://matteocapucci.eu/why-math/</id>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>Suppose you manage a thrift shop. You buy used, old stuff from people who empty their garages or their lodges and you usually do so for free: people call you, you pop up at their place with your empty van and leave after a long day of moving boxes around with a full van.</p>
        <p>Will you profit from this? Almost certainly yes. You get a lot of free stuff and the probability something valuable is in there is quite high. Moreover, since you get it for free, it doesn't have to be <em>that</em> valuable (we are not talking about gold nuggets), so a good chunk of it will turn into a profit, if small.</p>
        <p>Can you improve your profits? Well, you could if you left out the crap and just cherry-picked the nice, valuable stuff. But what if everything is in dusty, closed boxes and you don't have time to open them all and look inside? Nobody is going to call you if it takes you weeks to go through their stuff. </p>
        <p>Also, you don't know what the valuable stuff actually is: <em>a man's junk is another man's treasure</em>! So you resort to just have a lot of stuff in your shop, and hope that someone someday might find value in what others discarded.</p>
        <p>This is a metaphor for mathematics. A lot of it looks like 'useless crap', and will probably stay that way for a long time, maybe forever. Some of it is clearly useful, though it's often hard to know it in advance since it's usually boxed together with a lot of unassuming, abstract foolishness. Some things are hidden gems: they lurked in the dark corners of mathematics until someone realized they can actually do amazing things. Other things seemed useful for a reason, and then turn out to be useful also in another, completely different context. The problem is, nobody knows which is which.</p>
        <p>In short: you never know when your grandma's cohomology theory will be fashionable again.</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Math is a language, pt. 2</title>
    <published>2020-01-17T00:00:00Z</published>
    <updated>2020-01-17T00:00:00Z</updated>
    <author>
      <name>Matteo Capucci</name>
      <uri>https://matteocapucci.eu/matteo-capucci/</uri>
    </author>
    <link rel="alternate" type="text/html" href="https://matteocapucci.eu/math-is-a-language-pt-2/" />
    <id>https://matteocapucci.eu/math-is-a-language-pt-2/</id>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>In my <a href="https://matteocapucci.eu/math-is-a-language/">previous post,</a> I argued mathematics can be considered as an highly sophisticated, fractal language in which ideas are layered on each other to build very tall mathematical buildings. Rigourous proofs are the strong mortar keeping the tower standing up. All of this was philosphical and suggestive, and stemmed from the evergreen question 'of what use is math?', and I'm still satisfied by that answer.</p>
        <p>On the other hand, I recently come to realize that there's a more technical way in which one could argue 'math is a language'. And if my previous post might have made some people turn their nose because of the handwaving, philosophical remarks, this time we are talking actual mathematics, or at least metamathematics.</p>
        <p>Traditionally, math is thought founded in/on sets. This means that the entities you talk about in math are assumed to be sets. In the most orthodox set theories, everything is really a set, even things we don't usually think of as sets, for instance <em>numbers</em>. This is called <a href="https://ncatlab.org/nlab/show/material+set+theory">material set theory,</a> and I think of it as axiomatizing the 'atoms' of which mathematical matter is made of. Since there's no dialectics going on between atoms and the forms they make, the first are always the same, immutable and do not see the bigger picture.</p>
        <p>Material theories are not bad <em>per sè</em>, though I would argue they are far from the mathematical practice, i.e. we do not think of <em>everything</em> as sets. Some things are sets, sure, but some are just not. Numbers do not make sense as sets. Yeah, maybe counting numbers, right. But real numbers? Whose intuition is grounded on the concept of real numbers as Dedekind cuts? I know of no one.</p>
        <p>This is even more apparent by the fact that (a) most people are basically oblivious of this fact and (b) nevertheless, we really don't care about 'the structure of set' on most of the objects we use. For example, when you describe a map between, say, rings, you may prove it is a well-defined map of rings, but I've never seen anyone checking it is a well-defined set as well. It'd be trivial, of course. Yet nobody even mentions it, which allows us to build a case against a material foundation as natural foundation for mathematics.</p>
        <p>That said, facts (a) and (b) can also be read in favor of materal views. In fact a good foundation 'stays out of the way', so to speak, meaning it doesn't obstruct the study of your object of research with annoying technicalities or bookkeeping. Can this be said, say, of type theory? </p>
        <p>Both this cases, however, have a common point: mathematical practice is usually not concerned with foundations, as long as they are solid enough to not fail us, and as long as they provide the necessary tooling to carry on working on the objects we are interested with. In other words, we could say that most of mathematics is 'foundations invariant', i.e. it doesn't really bother to switch from, say, ZFC to NBG.</p>
        <p>What is preserved, then, in changing foundations? The answer is quite easy once we conceeded ourselves sufficient meditation. <strong>It's language</strong>.</p>
        <p>The point is that <em>soundness and power of tooling are properties of the language we use to describe mathematical theories</em>. Sets have a powerful and (hopefully) sound language, which allows mathematicians to go on undisturbed much of their time. But since they never endorsed sets explicitly, we arrive to the conclusion that if we were to switch to an equivalently powerful foundation nobody will notice.</p>
        <p>This was quite liberatory when I realized it. In fact sets impose quite a strong ontological view on the universe of discourse of mathematics, thus it is liberating to see mathematics is actually independent from them. It is awkward to think mathematics can only be made with sets, that algebra, geometry, analysis and so on are just 'emergent properties' of sets. Why would it be so?</p>
        <p>Instead, it is now clear tht theories are independent and meaningful on their own. Given a sufficiently powerful foundation, a theory can thrive on its own.</p>
        <p>All of this becomes more contentful in light of <strong>topos theory</strong>. A topos is a category whose <a href="https://ncatlab.org/nlab/show/internal+logic">internal language</a> is sufficiently powerful to support many of the theories of everyday mathematical practice. The major drawbacks of a general topos are (1) the lack of nonconstructive principles such as LEM or AC and (2) the lack of infinite sets like the natural numbers. These could startle the reader as too big of an obstacle to ever take seriously the option of moving from sets to other toposes, yet this is nonsense as we cannot be castrated by having more choice than what we have now. If we need infinite objects, we just declare it. If we seriously need LEM/AC, we do it as well.</p>
        <p>I'm not arguing for rebasing all of mathematics on an arbitrary topos, or for structural set theories like ETCS. I'm just noticing a simple fact: we mathematicians talk, and the objects we deal with are made, first of all, by our discourses.</p>
      </div>
    </content>
  </entry>
  <entry>
    <title>Math is a language.</title>
    <published>2019-07-27T00:00:00Z</published>
    <updated>2019-07-27T00:00:00Z</updated>
    <author>
      <name>Matteo Capucci</name>
      <uri>https://matteocapucci.eu/matteo-capucci/</uri>
    </author>
    <link rel="alternate" type="text/html" href="https://matteocapucci.eu/math-is-a-language/" />
    <id>https://matteocapucci.eu/math-is-a-language/</id>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>I always been a lover of 'math for the sake of math' and I found annoying to ask <i>'but what is this useful for?' </i>when learning about a new concept.</p>
        <p>It might seem weird, but to a pure mathematician 'apply' sounds like 'spoil'. Applications are a kind of low rank pursue for a mathematician, something 'easy' and very much unexciting. I happily embarked this line of reasoning very early in my studies, giggling about the superb degree of purity my career was going to have.</p>
        <figure>
          <img src="https://imgs.xkcd.com/comics/purity.png" alt="" />
          <figcaption>Relevant XKCD</figcaption>
        </figure>
        <p>That's also something that the general public, <i>the muggles</i>, seem to get. Mathematics is all about abstraction, and abstraction means getting far from reality. The more abstract we mathematicians soar, the more we enjoy it, refreshing ourselves with pristine, unspoilt Platonic ideas.</p>
        <p>The starting point of this reflection is the existential question of math, that is: <i>is this of any utility whatsoever? </i></p>
        <p>It's actually a causality issue: <strong>if we stopped pursuing very abstract and very theoretical mathematics, will we really miss any practical application?</strong> When is abstract too much?</p>
        <p>I often struggled to find a single example of application for more math than not. And even if the charm of it still has a big effect on me, it started to be not enough. Of course you start to deal with these questions when you get in touch with really whimsical stuff like 'pointless spaces', whose very name hints to something <i>really</i> difficult to apply to anything whatsoever.</p>
        <p>So, why all the fuss?</p>
        <p>I guess the answer lies more in the form than in the substance. A good example to illustrate my point comes from category theory. It was conceived as a good taxonomical tool for algebraic discourse, to formalize <em>general abstract nonsense</em>. Yet, it turns out, categorical concepts pop out everywhere. 'Adjoints are everywhere' said someone. Would you ever see them if no one ever defined what a functor is?</p>
        <p>In the same fashion, a big chunk of mathematics might be justified just by appealing to its form. Topology is useful because topological concepts are indeed ubiquitous in other mathematical tools. Brouwer's fixed point theorem makes a lot of sense when stated about morphism of topological spaces, and when proved using the classical algebraic topology argument. Can you wonder how quirky would it sound if stated without any reference to topology?</p>
        <p>This made-up example is actually what happened with Abel-Ruffini's theorem: Ruffini concocted an unbearably long proof about the unsolvability of quintics (so long, almost no one was brave enough to read it all). Fast forward less than 50 years later, and Abel's proof is neat and short: why? Because it used powerful concepts from the new-born science of abstract algebra, which made much more evident what all the question was about: the structure of the symmetric groups <code> S_n </code>.</p>
        <p><strong>The moral is, a good part of math is simply there to make other chunks look reasonable</strong> [0]. Category theory is the royal example: as put by Freyd, 'the purpose of category theory is to show that what is trivial is trivially trivial'.</p>
        <p>This insight leads us to a much deeper one, that <strong>mathematics is actually a language</strong>. What I mean by <em>language</em> is a set of symbols and rules on how to assemble them to convey meaningful messages.</p>
        <p>Clearly mathematics <em>has</em> a language [1], yet I'm arguing here mathematics <em>is</em> itself a language.</p>
        <p>The main observation is that mathematics is highly hierarchical and fractal-like. Higher mathematics is of course 'made of' lower mathematics (e.g. you need linear algebra to grasp tensor algebra), but at the same time any significantly developed mathematical theory finds itself mirrored in some other, either completely and rigorously so or just partially (e.g. the duality <a href="https://ncatlab.org/nlab/show/duality">between geometry and algebra</a>). Undoubtedly, finding similarities between different areas of mathematics is considered as an highly desirable, elegant and fruitful achievement [2].</p>
        <p><strong>The symbols of mathematics are its own concepts</strong>, which should be intended in a broadly and elastic sense: 'group' is a concept, and so is the subject of topology as a whole. A better word is <em>ideas</em>: groups embody the idea of modeling symmetries algebraically, while topology is the idea of studying a space by defining what is 'near' to a given point [3]. Theories are ideas, too: e.g., Morse theory is the idea that singular points of a manifold must tell something about its topology.</p>
        <p><strong>The rules of the language of mathematics are simply any meaningful way to put together mathematical ideas</strong>. This is too quite blurry, so let's make some examples: singular homology theory is a <em>composed idea</em>, which is made from the idea of probing a (topological) space with maps from simplices and the idea of building an algebraic gadget out of this process. Both ideas can be generalized separately, respectively to get fundamental groups (we study maps from spheres) and homology theory (we study the same algebraic idea applied to different constructions, e.g. <a href="https://en.wikipedia.org/wiki/Cubical_complex">cubes</a>).</p>
        <p>Of course homology theory is also an idea itself. This the power of mathematics as a language: any composed idea can become itself a 'simple' idea upon which we can build more complex ideas, and so on. I believe this explains both why abstraction is so powerful and how mathematicians can work on increasingly advanced topics as easily (or as hardly) as an undergraduate works on linear algebra: both are just surfing the wave of recursive complexity. </p>
        <p>Until this point, I seem to have described not mathematics but a wider generalization of it: <em>thought</em>. We need to ensure our language is tied down to a formal, rigorous system (or ontology), so that a 'successful' idea is one which can be morphed into a provable statement, or at least to a statement we can judge logically. So this distinguishes <a href="https://arxiv.org/abs/1608.03679">the idea of considering the zeroes of Riemann zeta function as eigenvalues of a suitable (self-adjoint) Hamiltonian</a> and actually proving the Riemann Hypothesis.</p>
        <p>This view, moreover, explains my previous claim that some math <em>is just about math</em>, just as some parts of English are just about grammar (like the word 'grammar' itself). It does say something about why it seems so abstract, too: its composition rules produce the fractal structure of the mathematical edifice, thus moving quickly into ever involved concepts and long chains of generalizations. Mathematics has the ability to summon a whole theory by just observing a particular property in an objects: algebraic sets satisfies the properties of a lattice of closed sets? Behold as topology rushes in! Suddenly, you're speaking about compactness and separability in a context which was mostly 'polynomials and ring algebra'.</p>
        <p>To draw a fictional comparison, picture a (spoken) language in which <em>entire debates</em> are condensed in a single word, and then proceed to be used in new debates. Clearly meanings add up and you start to feel dizzy as a ten-words conversation spirals out in a twenty-volumes reference to previous discussions. In some sense we do this in everyday language, but in a lot less meticulous way as in math: nobody (actively) discusses the validity of Euclid's fifth axiom anymore while the same can't be said about communist theories (notice both where 'clarified' around the same time!). In a sense, the rigour imposed upon mathematical ideas makes the whole edifice solid and trustworthy. This is a luxury not even hard sciences have. </p>
        <p>This makes mathematics extremely unwordly, because it is various strata of meaning above 'real stuff', yet phenomenally powerful. Mathematicians routinely handle behemoth ideas by hiding it under an even more gargantuan pile of, let's face it, abstraction. This can be exploited to reflect a similar feature of reality: <strong>things are simple in theory, not so much in practice</strong>.</p>
        <p>This is something that is not extraneous to science, intended as the human endevour of modeling reality with math: by its very definition, scientists never argue to have a perfect model of reality, just a working, 'good enough' one. As science progresses, so do the accuracy of models. And we can only do this by building up on previous models, using smaller and smaller discrepancies from the old ones to guide the introduction of a new one. Naturally, models tend to get less straightforward with each iteration, as to capture a phenomenon more faithfully you'll need to consider more complex interactions, higher order effects, and nitty-gritty details.  <strong>Hence to handle complex situations, we need to be able to work with complex theories</strong>.</p>
        <p>Wrapping up then, yes, we'll miss a lot if we stop pursuing pure math. The feeling of dissatisfaction with more and more abstract math is a symptom of something else: calling applied math sour grapes. Instead of facing the daunting task of modeling complex tasks, we prefer to turn around and pretend applied math is some trivial and inferior endeavour.</p>
        <h3>Notes</h3>
        <p>[0] Another moral is that concepts in mathematics can't be thought, yet alone taught, as independent chunks. They need to be properly motivated (and historical background is great at this), and inserted in their rightful position in the mathematical edifice.</p>
        <p>[1] Math has languages on formal and informal levels. On one hand, every mathematical proposition can be regarded as written down in a formal system of some sort; while on the other hand, mathematicians use a common language made up of naming conventions, common notations, canonical subdivisions of disciplines, and a very distinctive <a href="http://thatsmathematics.com/blog/mathgen/">prosaic style</a><a href="http://thatsmathematics.com/blog/mathgen/" />.</p>
        <p>[2] We could go as far as saying any mathematical progress could be decomposed in a <em>vertical</em> component ('going deeper' into the subject or 'building higher') and an <em>horizontal</em> one, linking the subject to other areas. This picture fits nicely with the informal entity of the 'mathematical edifice'.</p>
        <p>[3] I'm referring here to the <a href="https://en.wikipedia.org/wiki/Topological_spaceDefinition_via_neighbourhoods">definition of a topology using neighbourhoods</a>. Other definitions also embody specific ideas about which aspect of 'being a (topological) space' should be fundamental. The very fact we have strikingly different yet equivalent definitions is highly interesting, and makes topology a useful and strong theory. In the fractal analogy, topology exhibits a lot of self-similarity.</p>
      </div>
    </content>
  </entry>
</feed>
