Skip to content
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

Swapping the argument order in equational reasoning #998

Closed
maxsnew opened this issue Mar 24, 2023 · 5 comments
Closed

Swapping the argument order in equational reasoning #998

maxsnew opened this issue Mar 24, 2023 · 5 comments

Comments

@maxsnew
Copy link
Collaborator

maxsnew commented Mar 24, 2023

In porting a category solver from the 1lab (https://github.com/maxsnew/multi-poly-cats/tree/main/Cubical/Tactics/CategorySolver), I ran into an issue: the solvers can't work in equational reasoning proofs because they never have the right hand side of the goal inferred. For example this proof:

  ex : ∀ {A B C}(f : 𝓒 [ A , B ])(g : 𝓒 [ B , C ])(h : 𝓒 [ A , C ])
    → (f ⋆ (id ⋆ g)) ≡ h
    → f ⋆ g ≡ h ⋆ id
  ex f g h p =
    f ⋆ g ≡⟨ solveCat! 𝓒 ⟩
    (f ⋆ (id ⋆ g)) ≡⟨ p ⟩
    h ≡⟨ solveCat! 𝓒 ⟩
    h ⋆ id ∎

Doesn't succeed with the current definition of equational reasoning, in each case the call to solveCat! fails because the rhs is an unsolved metavariable.

Reed Mullanix showed me that the issue can be solved by redefining the equational-reasoning syntax to swap the order the arguments are passed:

≡⟨⟩-syntax : ∀ {ℓ} {A : Type ℓ} (x : A) {y z} → y ≡ z → x ≡ y → x ≡ z
≡⟨⟩-syntax x q p = p ∙ q

infixr 2 ≡⟨⟩-syntax

syntax ≡⟨⟩-syntax x q p = x ≡⟨ p ⟩ q

Agda's type checker works from left to right but the equational reasoning macro is right-nested, so swapping the arguments like this gives better type inference and can even lead to performance improvements. With this change the equational reasoning proof above works.

This change has already been done in the agda-stdlib three years ago (agda/agda-stdlib#1045) and is used in the 1lab as well. It seems quite critical for allowing the use of solvers in practice.

@felixwellen
Copy link
Collaborator

felixwellen commented Mar 24, 2023

Wow - this is great! I ran into this problem once, but didn't know it has an easy fix like this. Does it have drawbacks? Does the use of syntax mess up goals?

@MatthewDaggitt
Copy link

The issues the stdlib has had with it: i) very verbose to rename the syntax, ii) much more non-obvious what to do when trying to import explicitly using using.

@maxsnew
Copy link
Collaborator Author

maxsnew commented Mar 24, 2023

What do you mean by it being verbose? Don't we just need to change a couple of definitions to be macros?

@felixwellen
Copy link
Collaborator

Maybe we can just try how good or bad it is?
@maxsnew: Can you make a PR (with possibly failing CI) that replaces equational reasoning with what you think we should do?

felixwellen added a commit to felixwellen/cubical that referenced this issue Mar 27, 2023
maxsnew pushed a commit to maxsnew/cubical that referenced this issue Mar 27, 2023
felixwellen added a commit that referenced this issue Mar 29, 2023
* swap the argument order in equational reasoning

* [#998]: Remove unused code, fix imports

---------

Co-authored-by: Felix Cherubini <felix.cherubini@posteo.de>
@maxsnew
Copy link
Collaborator Author

maxsnew commented Mar 30, 2023

solved by #999

@maxsnew maxsnew closed this as completed Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants