Towards a specification of theory refinements [01HU]
- October 3, 2025
- Jon Sterling
In my previous post, I discussed how to deal with coercions between refined theories. While trying to come up with sufficiently expressive rules for forming theory refinements, I realised that this can get very complicated if you do not first fix some prudent simplifying principles.
Shallow refinements might be all you need? [01HV]
- October 3, 2025
- Jon Sterling
One thing that users might expect to be able to do is form deep refinements like in ML modules, where instead of specialising a field of the top-level structure, you specialise a field of a substructure. For example, suppose we had defined rings in the following way:
theory Ring where
car: Set
additive: AbGroup / {car => car}
multiplicative: Monoid / {car => car}
dist/left: // ...
dist/right: // ...Then we might want to consider a ring structure on the integers in which the addition is given by integer addition, which makes us want to be able to write a theory refinement like Ring / {car => Int, additive.join => Int/add} or something. I would like to posit, if I can, that this is unnecessary.
The issue is that in practice, a composite structure like that of rings ought to be flattened anyway. So we would instead really want something like:
theory Ring where
car: Set
include additive: AbGroup / {car => car} renaming
unit => zero
join => add
include multiplicative: Monoid / {car => car}
join => mul
unit => one
// ... dist/left, dist/rightAbove I have introduced a few new construct: theory inclusion (distinct from inheritance) and theory renaming. What this should unravel to is something like the following:
theory Ring where
car: Set
add: car -> car -> car
zero: car
// ... add/assoc, add/zero/left, add/zero/right, add/comm
mul: car -> car -> car
one: car
// ... mul/assoc, mul/one/left, mul/one/right,
// ... dist/left, dist/right
additive: AbGroup / {join => add, unit => zero, ...}
multiplicative: Monoid / {join => mul, unit => one, ...}Because we have named the substructures, the system would not emit any canonical inheritance coercions from Ring to AbGroup or Monoid, as these would not be coherent anyway. The additive and multiplicative components now serve mere “tokens” by which you can access the additive subgroup or the multiplicative monoid all at once, but these are singletons and therefore would not appear in the construction of a given ring.
Coming back to our example, we see that we can obtain the theory of ring structures on integer addition by a shallow refinement Ring / {car => Int, add => Int/add}. I believe that by keeping hierarchies flat in the style of Mathematical Components, we will always be able to obtain the needful refinements shallowly.
Preliminary thoughts on specifying shallow refinements [01HW]
- October 3, 2025
- Jon Sterling
To a first approximation, a refinement of a theory with telescope \Phi is given by a prefix \Phi of \Psi together with an instantiation of \Phi . This is a good first step, but it does not correctly handle the (very common) case where we wish to refine only certain fields that are not necessarly forming a contiguous prefix. In the simplest example, we might want to speak of pairs whose second component is fixed.
These cases arise when one field’s type doesn’t depend on all of the prior fields. One approach to dealing with this would be to replace telescopes by directed acyclic graphs in which the edges represent dependency. I think this can be achieved, but I think it might very complicated, keeping in mind that as one field gets refined, the remainder of the DAG would need to reconfigure itself (in other words, substitution can cause dependencies to disappear).
I have been thinking that a better way to deal with this would be instead to allow a refinement to start in the middle of the telescope, and have it be implicitly abstracted over all the previous fields. Skipping a field just abstracts over that field. Then by construction, the refinement is well-typed but we can still handle the mentioned examples. This is kind of what I did in my Lean prototype of Pterodactyl, but it is difficult to understand my code…
One subtlety of this approach is to figure out appropriate syntactic conditions for these refinements to always correspond to a display map. The naïve version outlined above would allow a refinement by the diagonal, which is probably not what we want.