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

cast vs subst in Data.Fin #1610

Closed
conal opened this issue Oct 15, 2021 · 9 comments
Closed

cast vs subst in Data.Fin #1610

conal opened this issue Oct 15, 2021 · 9 comments
Labels

Comments

@conal
Copy link
Contributor

conal commented Oct 15, 2021

I’m working on a collection of proofs for submission to Data.Fin.Properties. I can phrase & prove via cast or via subst Fin. For my own use, I need the subst versions, to fit into a setting more general than Fin. If cast is a better fit for Fin, I’m happy to adapt via an equivalence property cast≗subst : ∀ {m n} (m≡n : m ≡ n) → cast m≡n ≗ subst Fin m≡n (which could also go into Data.Fin.Properties).

Going with cast, I also need some properties of cast corresponding to ones about subst in Relation.Binary.PropositionalEquality.Properties, such as subst-sym-subst (which I’m calling cast-sym-cast for now). I don’t imagine we’d want to replicate all subst properties for cast, though.

Thoughts?

@JacquesCarette
Copy link
Contributor

To me, the biggest advantage of cast over subst is that cast computes regardless of the actual proof of equality, while subst only reduces for refl. Working --without-K and with subst is amazingly tedious.

Side commentary: Using either of them is also misleading; we know that Fin n has an automorphism group of size n!. By singling out the id one as being the only one worth talking about when doing type isomorphism on Fin n hides a lot of the beauty of Id types.

@conal
Copy link
Contributor Author

conal commented Oct 16, 2021

To me, the biggest advantage of cast over subst is that cast computes regardless of the actual proof of equality, while subst only reduces for refl.

Ah, interesting. Thanks for mentioning this difference.

From the definitions of cast and subst, I gather that reducing cast requires evaluating only the Fin argument (as you mentioned), while reducing subst requires evaluating only the equality argument. Do you have any insight to share about how cast’s requirement tends to be less burdensome than subst’s?

@conal
Copy link
Contributor Author

conal commented Oct 16, 2021

For concreteness, here are two of the properties (in their cast form) I intend to submit in a PR (where is Data.Sum). I’ll probably need the analogous properties for products as well.

join-assocˡ :  {m n p} 
  join (m + n) p ∘ ⊎.map₁ (join m n) ∘ ⊎.assocˡ
    ≗ cast (sym (+-assoc m n p)) ∘ join m (n + p) ∘ ⊎.map₂ (join n p)

join-assocʳ :  {m n p} 
  join m (n + p) ∘ ⊎.map₂ (join n p) ∘ ⊎.assocʳ
    ≗ cast (+-assoc m n p) ∘ join (m + n) p ∘ ⊎.map₁ (join m n)

@conal
Copy link
Contributor Author

conal commented Oct 16, 2021

By singling out the id one as being the only one worth talking about when doing type isomorphism on Fin n hides a lot of the beauty of Id types.

Thanks! I’ll meditate on this perspective.

@gallais
Copy link
Member

gallais commented Oct 16, 2021

Do you have any insight to share about how cast’s requirement tends to be less burdensome than subst’s?

Mostly because cast (suc k) = suc (cast k) holds definitionally.
When you're proving something about a function's behaviour and need to use a
coercion to have the types match up on both sides of the propositional equality,
you do want to expose constructors as soon as possible so that you can appeal to cong.

Edit: appeal to cong or have a function applied to this coerced value reduce!

@conal
Copy link
Contributor Author

conal commented Oct 16, 2021

Thanks for the tips, @JacquesCarette & @gallais!

@conal
Copy link
Contributor Author

conal commented Oct 17, 2021

By singling out the id one as being the only one worth talking about when doing type isomorphism on Fin n hides a lot of the beauty of Id types.

Thanks! I’ll meditate on this perspective.

I did, and now I am enlightened. I had indeed gotten focused on the identity automorphism. Seeing equality as such (thanks to your remark) puts the problem I was working on into a wider context that I need anyway. Thanks again, @JacquesCarette!

@JacquesCarette
Copy link
Contributor

Seems to me that all of @conal 's questions have been answered, so that this could be closed?

@conal
Copy link
Contributor Author

conal commented Sep 29, 2022

Thanks again for the answers.

@conal conal closed this as completed Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants