Description
What I'm going to write here is something between a feature request and a research proposal.
One of the great advantages of cubical type theory is that the path type behaves somewhat like a function type, making results like funExt, refl, sym, cong and flipSquare trivial to implement and giving them nice computational behaviour.
However, when as a user of Agda cubical you dare to make use of this function-like nature of paths and actually abstract over an interval variable, then the endpoint constraints move from the type to Agda's constraint system and become rather difficult to keep track of. This is a theoretical issue, not one of Agda. Indeed, we could keep constraints in the judgement (as I think Agda actually does as long as possible) but there is no way to infer constraints e.g. for the following subterms:
Γ |- f : A -> B [ φ -> ? ]
Γ |- a : A [ φ -> ? ]
------------------
Γ |- f a : B [ φ -> b ]
I think that instead of having libraries full of operations like the ones listed above that involve trivial manipulations of interval variables while not really helping us out with the constraints, we should instead leave interval variable manipulations to the user and have libraries that help out with the constraints. This is possible if we view the path type not as a primitive type but as built up of two parts:
- Functions
(i : I) -> A iranging over the interval. I think these should be Kan, if not by the usual proof for Π-types, then at least by swappingiwith the dimensions of the Kan operation, which is possible since box inclusions are closed under products withI. - Extension types, not in the sense of Riehl and Shulman (what they call extension types is a generalization of path types) but in the sense of §6.2.2 of my phd thesis (I do not claim to have invented these).
I'll quickly state the rules here:
Γ |- A type
Γ |- φ : Prop
Γ, φ |- a : A
-----------------
Γ |- Ext A [φ -> a] type
Γ |- a : A
Γ |- φ : Prop
-----------------
Γ |- cut φ a : Ext A [φ -> a]
Γ |- e : Ext A [φ -> a]
-----------------------
Γ |- paste φ e : A
paste φ (cut φ a) = a
cut φ (paste φ e) = e
paste \top e = a -- (the index from the type)
I guess these are Kan by design of the Kan operations.
Now if we define PathP (λ i -> A i) a0 a1 as (i : I) -> Ext (A i) [i = i0 -> a0 | i = i1 -> a1], then it is sufficient to support library operations for working with extension types. For example (omitting implicit arguments), we could have
xCong : (f : (x : A) -> B x) -> (ex : Ext A [φ -> a]) -> Ext (B (paste ex)) [φ -> f a]
so that xCong f ? infers the hole's constraints at least if f is injective and keeps them in the type.
Instead of function extensionality and its inverse, we would have
xFunExt : ((x : A) -> Ext (B x) [φ -> b x]) -> Ext ((x : A) -> B x) [φ -> λ x -> b x]
xFunExtI : ((x : I) -> Ext (B x) [φ -> b x]) -> Ext ((x : I) -> B x) [φ -> λ x -> b x]
xFunExt- : Ext ((x : A) -> B x) [φ -> λ x -> b x] -> ((x : A) -> Ext (B x) [φ -> b x])
xFunExtI- : Ext ((x : I) -> B x) [φ -> λ x -> b x] -> ((x : I) -> Ext (B x) [φ -> b x])
(which should be implementable).
If there is also an (implementable) merging and unmerging operation
xMerge : Ext (Ext A [φ -> a]) [ψ -> eb] -> Ext A [φ -> a | ψ -> paste eb]
xUnmerge : Ext A [φ -> a | ψ -> paste eb] -> Ext (Ext A [φ -> a]) [ψ -> eb]
then, when in need of a square, we could simply do
square i = xFunExtI λ j -> xUnmerge ?
and we get a hole with a clear constraint of the form i = 0 /\ i = 1 /\ j = 0 /\ j = 1.
As a first step towards evaluating this proposal, the Agda developers could consider adding experimental pragmas to be used in combination with --cubical that:
- allow level-preserving interval quantification,
- allow extension types.
Then we can have an experimental library that builds path types from these two (which should be easily proven isomorphic to the primitive path types) and provides operations to work with extension types.
Activity
anuyts commentedon May 2, 2022
Well we can probably only allow Kan operations in the extension type if φ is constant in the dimension of composition/transport. This could be a problem.
jonsterling commentedon Aug 2, 2022
You may be interested in checking out what we did in cooltt, which is similar to your proposal i think.
Saizan commentedon Aug 3, 2022
@anuyts your
ExtisSubfromAgda.Builtin.Cubical.Suband indeed it's not Kan in general.anuyts commentedon Aug 4, 2022
@jonsterling Do you merely mean that cooltt also has
Sub/Exttypes, or also that you've used combinators as I described?jonsterling commentedon Aug 4, 2022
What I mean is that in addition to supporting the
Sub/Ext(pre)types, bothcoolttandredttkeep the boundary constraint in the judgment as long as possible; it's true that there are cases where one loses the boundary however. Your combinators are interesting and could be implemented there... But I would like to think about whether we can take some lesson from your combinators and integrate it into elaboration directly.anuyts commentedon Aug 4, 2022
Well I guess we could have a typing rule
Then when we give a hole
{!f ?!}of typeB [ φ -> ∂b ], I guess this could∂fto bef∂aand equatef ∂a = ∂b. Then iffis judgementally an injective operation and∂b = f a', we do get a subgoalA [ φ -> a' ]as desired.This is a type-theoretic formulation; I'm not sure (due to not being a seasoned proof assistant developer) if you mean something substantially different when regarding it as part of elaboration, but I guess the effect would be extremely close to what @plt-amy is proposing in #5997.
anuyts commentedon Aug 4, 2022
This was fun!
I had success in a few places, but problems in most, and I do not understand all of them.
On
isProp→collapseBool, I seem to have run into an Agda bug, where reloading after giving changes the Agda state.jespercockx commentedon Aug 23, 2022
I do not think the issue tracker is the best place to discuss novel research ideas. If you have a concrete proposal of what should be implemented, feel free to reopen this or create a new issue/PR!
anuyts commentedon Aug 23, 2022
Well it turned out that the proposed type was already there and is called
Sub, so I think indeed this issue is completed.