-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Monoidal Category Tactic #279
base: master
Are you sure you want to change the base?
Conversation
This is very cool! I'd love to help out but I'm super busy this and next week. What I can offer in the meantime is some observations:
Update: forget about 2. I realize now the |
Yeah, I roughly see where I need to use the associators and unitors. The reason I am using this degenerate version is that during reflection, I plan on splitting the morphisms into the ones that just do coherence things, and non trivial ones. If we included the non trivial ones in our subcategory, then the key theorem As for I originally tried working with synthetic equality actually, but it didn't seem to be buying me a whole lot. Perhaps it could help with versions of the problematic Adding a syntax for normal forms is a great idea, I hadn't considered it! The whole proof is sort of a bizzare version of a coherence theorem anyways, so it makes sense that an explicit version of a stricit moniodal category could be useful. Will give this a go :) WRT to naming, good point. I suppose just writing unitors/associators is clearer. |
I managed to make some progress by using an explicit representation of normal forms. It allowed me to solve the case for the tensor product Hope this is helpful. |
@sstucki This is great! I think we might have ourselves a solver pretty soon :). WRT commiting to the branch, this is the most annoying thing about git IMO. I'll grab those commits off your branch and integrate them into mine. Moving forward, you should probably have your branch track mine so that the histories are the same (makes merges easier) |
Looks like using explicit equalities might be the right move after all. This lemma would be waaaaaay easier if we could pattern match on equality proofs.
Maybe it's worth defining Free Monoidal Categores in a separate PR. That seems useful enough in it's own right! The same could be said for the strict variants as well. |
Can't you use the fact that In fact, there's a lemma in IsoEquiv that proves what you want: agda-categories/src/Categories/Morphism/IsoEquiv.agda Lines 22 to 23 in 5e4de42
|
Good idea, I'll do that! |
Ok, more progress. |
Because of the stated reason, using the category tactic here seems reasonable. |
Actually, a lot of the code in this module is independently useful. It's a weak version of the coherence theorem for (discrete) monoidal categories. It just so happens that this proof is constructive so we can use it as an algorithm to "solve" equations in such categories. I think there's a point exposing that part of the module and making it independent of tactics code. If the issue is just the "gnarly reassociation" for the associator case, then we can either prove it by hand (shouldn't be all that bad) or use the category tactic to generate a proof and substitute it in. Apparently the command for this is |
The proofs are finally done! Now all that remains is writing the reflection code, and figuring out what needs to get factored out. @sstucki After checking through the relevant sections of CWM, I think this is actually the proof that Maclane has. Specifically, that coherence theorem states that "every diagram built out of unitors, associators, and multiplication commutes"[1], which is exactly what this proves. References[1] Categories for the Working Mathematician VII.2 |
unit′ : Word | ||
_′ : (X : Obj) → Word | ||
|
||
reify : Word → Obj |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be tempted to call this [[_]]W. But this is just a weak suggestion.
ρ⁻¹′ : Expr A (A ⊗₀′ unit′) | ||
|
||
-- Embed a morphism in 'Expr' back into '𝒞' without normalizing. | ||
[_↓] : Expr A B → (reify A) ⇒ (reify B) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And then here [[_\d]] (or maybe put the downarrow outside?). Again, weak suggestion.
|
||
infix 4 _≈↓_ | ||
|
||
-- TODO: is this sufficient or should we define an equality directly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My feeling is that using the semantic equality here is downright clever, and should stay.
invert ρ⁻¹′ = ρ′ | ||
|
||
-- Witness the isomorphism between 'f' and 'invert f'. | ||
invert-isoˡ : ∀ (f : Expr A B) → [ invert f ↓] ∘ [ f ↓] ≈ id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps make the next two proofs private, and export just invert-iso
?
{ isoˡ = invert-isoˡ f | ||
; isoʳ = invert-isoʳ f | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment to the effect that "the normal form for a (free) Monoid is a list"?
NfWord = List Obj | ||
|
||
data NfExpr : NfWord → NfWord → Set o where | ||
idⁿ : ∀ {N} → NfExpr N N |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be tempted, to avoid subst-juggling, to try
idⁿ : ∀ {N M} → N == M → NfExpr N M
There's also some alternate way that @sstucki wrote to do this, but I can't recall where it is...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JacquesCarette I think you're thinking of hid
which itself uses subst-juggling, so not sure it's helpful here.
But I was thinking: the use of subst in this module could maybe be avoided if the normal forms of the unitors and associators were defined by recursion on the domains following the same structure as the unit/associativity laws for lists themselves. That might also simplify the proofs of the corresponding "monoidality" laws which are proven by recursion and need helper lemmas to deal with the subst stuff. Anyway, just an idea, I don't know whether it would actually work out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, hid
. If all subst
-juggling can be isolated to one place, that counts as a win.
Ok, I've done some more thinking on this, and I have a idea for how we can normalize non-discrete things. If we update our data Expr : Word → Word → Set (o ⊔ ℓ) where
id′ : Expr A A
_∘′_ : Expr B C → Expr A B → Expr A C
_⊗₁′_ : Expr A C → Expr B D → Expr (A ⊗₀′ B) (C ⊗₀′ D)
α′ : Expr ((A ⊗₀′ B) ⊗₀′ C) (A ⊗₀′ (B ⊗₀′ C))
α⁻¹′ : Expr (A ⊗₀′ (B ⊗₀′ C)) ((A ⊗₀′ B) ⊗₀′ C)
ƛ′ : Expr (unit′ ⊗₀′ A) A
ƛ⁻¹′ : Expr A (unit′ ⊗₀′ A)
ρ′ : Expr (A ⊗₀′ unit′) A
ρ⁻¹′ : Expr A (A ⊗₀′ unit′)
[_↑] : X ⇒ Y → Expr (X ′) (Y ′) and our normal forms to something like: data NfExpr : NfWord → NfWord → Set (o ⊔ ℓ) where
emptyⁿ : NfExpr [] []
consⁿ : ∀ {X Y} {N M} → X ⇒ Y → NfExpr N M → NfExpr (X ∷ N) (Y ∷ M) Then things seem to work out. Most of the proofs seem to fall out pretty naturally by induction, though I haven't reworked the monster that is One annoying thing is that we lose out on |
Everything else in [_↑] : X ⇒ Y → Expr (X ′) (Y ′) as well? You should make the lift be on an iso too. You really do want that for |
This is definitely a big step forward, but it doesn't go all the way. The issue is that the domain and codomain of In any case, the tactic would already be enormously helpful even in the form you propose, because one could solve string diagrams "layer by layer" with a few manual proofs to merge and split these layers, when necessary. |
Actual string diagrams that contain arrows other than the monoidal maps (unit, assoc, etc.) need not be invertible. So there's no reason to think you'd only be embedding isos, is there? |
We can still represent those morphisms with this encoding actually!
The trick here is that we are "quoting" the objects EDIT: |
The |
I don't understand how the composition can type check when different parts of the domain and codomain are quoted. EDIT: Oh, I see. My example was imprecisely formulated. I meant for the domain of |
Yeah, that example worked out fine by coincidence. You run into trouble when you want to start composing onto associators/unitors. You were definitely right when you stated that the domain/codomain of the quoted morphisms ought to be reified words. |
Yea, what I had in mind was
|
Ok, I have a possible solution: During reflection, we insert quoting/unquoting morphisms when needed:
These can read-back into |
I think the fundamental problem is certain diagrams just cannot be 'linearized' into a single list of morphisms. They need some form of tiling with multiple levels. Here's another version of the example I gave above with an explicit associator:
I cannot see how you'd turn that into a single layer. But maybe there's a way to turn it into a multi-layer normal form somehow. |
Would there be something to learn from @gelisam 's premonoidal solver? |
The monoidal version of the problem is harder than the premonoidal version, so it is I who has the most to learn from this conversation :) In particular, while I do have a definition for a free premonoidal category in that repo, I have not yet made a solver out of it. What distinguishes a premonoidal category from a monoidal category is that the law
is required to hold in a monoidal category but not in a premonoidal category (in fact there is no When looking for a definition for a free X, e.g. the free monoidal category, I start from a representation for the AST and I apply all the laws to reduce all the degrees of freedom. Above, we can see that the
The canonical representation for the premonoidal case is much easier: the representation on the left is already canonical. It's just a list of atoms, each shifted so that it only affects a sublist of the strings at that height of the string diagram. |
Taking a closer look at this branch, it looks to me like you don't support atoms at all, only the structural bits such as the associators, unit-introduction, and unit elimination? That explains why your only normal form is the identity! Well, that certainly makes the problem a lot simpler. And yet, from what I can see in the rest of this thread, it has already been quite a challenge! I guess I was wrong to think that the main challenge when writing this kind of solver was to figure out what the canonical representations look like, and that the rest (converting to and from the canonical representation, proving that an expression is equal to its canonical representation, writing a macro reflecting the type into an expression) would be routine. |
Where is your definition of a Free Monoidal Category? I'd be curious to see how yours compares to my tetris pile approach. I don't see it in this nor any recent PR. |
Indeed, atoms are not part of the implementation in the PR, hence the discussion starting after this comment by @TOTBWF (who claims he has a version with limited support for atoms somewhere 😉).
The challenge was really to implement the laws and to show that (embeddings of) the normal forms are equal to the original morphisms. The main difficulty there, as far as I can tell, stems from the coherence laws for the associators and unitors. As far as I can tell, this is somewhat orthogonal to the question of defining (good) normal forms. But @TOTBWF did all the work, so I might be wrong 😄.
In this PR, we only support a degenerate form of monoidal category (the discrete ones) which are lacking atoms, as you point out. The free discrete monoidal category is just the one built out of |
I've done a lot of stewing on this over the past 2 weeks, and I keep running into walls whenever I try to add non-structural morphisms. I think that this approach of trying to boil everything down to identity morphisms then reading them back is just not the right approach to handling atomic morphisms, and we may need to take a radically different approach if we want to support those. That's not to say the existing code isn't useful (it is a proof of a coherence theorem after all, and that is somewhat exciting), but I can't see any obvious way of bolting on non-structure morphisms that doesn't cause everything to come falling down. Perhaps instead of trying to do the strictification and solving at the same time, we could adopt a sort of "phased" approach, where we pluck out all of the structure morphisms, resolve them to a canonical form, then try to solve the remaining morphisms in this strict context. |
So is this completely stalled then? |
I've been pretty busy as of late (started a new job and moved countries) so I haven't had the time to think about this too hard 🙁. Hopefully I'll have some time to devote to this soon! |
Those are rather good reasons for not having time! Hope it all went smoothly. |
What's the current thinking on this? It looks as if coherence doesn't get us a solver for equalities in the usual sense, because coherence only talks about the free monoidal category on a set of objects, rather than on any data that could contain morphisms. I wonder how much we can get out of coherence. I suppose the most obvious thing is that, if we had a coherence tactic, we would never have to name a coherence principle during a proof. I think there genuinely are at least some cases where we naturally have two cliques of structural morphisms, and we know they're equal because of coherence. Something else we should be able to get is a tactic for composition up to structurality. For example, if we have For a lot of other things we do in monoidal categories, maybe the tool we need is a solver for morphisms involving various functors and natural transformations. Incorporating functors into a solver is traditionally hard to do because of size issues, but this should not be a problem when most of the functors derive from ⊗, as these are all level-preserving. I don't remember seeing a solver for natural transformations, but it seems at least plausible that one should be possible to make. |
So this might end up being new research, rather than something that can "just be done". Or at least, that's my current impression. I don't personally have any cycles I could devote to this right now (and not for some months), but if it's still open when my time frees up [and it will - sabbatical next year!], I'll dive in. |
I take it that this is still stalled (and there was no progress on something similar over in 1lab?) |
We're currently discussing this in the Monoidal Café discord. We found a flaw in my Tetris pile idea from earlier in this thread: it doesn't support scalars (morphisms from unit to unit), which commute with each other but not with identity morphisms. Word on the street is that @pigworker has found a complicated normal form for monoidal categories he calls "staircases", but it's not ready to be published yet. |
I can't find the Monoidal Café discord - could I get an invite? |
I was summoned here by @gelisam. Here is an invite to the Monoidal Cafe, feel welcome to join! |
Patch Description
This PR implements the start of a monoidal category solver, based roughly off of the ideas found in [1].
Specifically, we compute a normal form for each of the objects via
reassoc
, and then show that any composition of coherence morphisms is actually just the identity morphism between the normalized objects.Notes
I'm almost over the finish line on this one, just have to show that normalization preserves equality for associators, and prove a couple of rather stubborn lemmas. Of note is
strict-⊗
, which is not being well behaved. The proof ought to follow by some simple rewrites likestrict-∘
, but Agda does not seem happy about that.References