Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

fix(category_theory/opposites): make op irreducible#510

Closed
kim-em wants to merge 2 commits intoleanprover-community:masterfrom
leanprover-fork:irreducible-opposites
Closed

fix(category_theory/opposites): make op irreducible#510
kim-em wants to merge 2 commits intoleanprover-community:masterfrom
leanprover-fork:irreducible-opposites

Conversation

@kim-em
Copy link
Copy Markdown
Collaborator

@kim-em kim-em commented Dec 4, 2018

This makes it harder to accidentally (... or intentionally!) move back and forth between a category and its opposite.

Unfortunately, broken proofs were too hard to diagnose, when the wrong (opposite) category was inferred.

This commit also adds constructions in equivalence.lean showing that the functors op_hom : (C ⥤ D)ᵒᵖ ⥤ (Cᵒᵖ ⥤ Dᵒᵖ) and op_inv : (Cᵒᵖ ⥤ Dᵒᵖ) ⥤ (C ⥤ D)ᵒᵖ form an equivalence.

@kim-em kim-em force-pushed the irreducible-opposites branch from adbd17c to 9ce7be9 Compare December 4, 2018 11:29
@kim-em
Copy link
Copy Markdown
Collaborator Author

kim-em commented Dec 5, 2018

I did some renaming per @jcommelin's suggestions, making things slightly less ugly.

@rwbarton
Copy link
Copy Markdown
Collaborator

rwbarton commented Dec 7, 2018

This looks generally clearer. Another op-tion is the Haskell-style

structure op_cat (C : Type u₁) : Type u₁ := op :: (unop : C)

which will make C and its opposite category distinct things in the kernel as well as in the elaborator. I'm not sure whether that is a good thing or a bad thing though.

@rwbarton
Copy link
Copy Markdown
Collaborator

rwbarton commented Dec 8, 2018

The choice might affect the pretty-printer for example--Lean just asked me for a F ≅ F', but I gave it one and surprise, it wanted an isomorphism in the opposite category! It would be nice if it would show op F ≅ op F' then.

Copy link
Copy Markdown
Member

@jcommelin jcommelin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Let's get this merged.

@kim-em kim-em force-pushed the irreducible-opposites branch from fa6d776 to c69f526 Compare December 21, 2018 06:07
@kim-em kim-em force-pushed the irreducible-opposites branch from c69f526 to f4002b9 Compare January 19, 2019 11:23
@jcommelin
Copy link
Copy Markdown
Member

@digama0 Is there anything controversial left in this PR? (Note that the title is now misleading... see the latest commit.)

(op g) ≫ (op f) = op (f ≫ g) := rfl
@[simp] lemma comp_unop {X Y Z : Cᵒᵖ} (f : X ⟶ Y) (g : Y ⟶ Z) :
unop (f ≫ g) = (unop g) ≫ (unop f) := rfl

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of these simp lemmas seems to be backwards, though I'm not sure which one. There are three with op or unop applied to an identity or composition on the left hand side, but presumably there should be an even number of them...

@[simp] lemma op_unop {X Y : C} (f : X ⟶ Y) : f.op.unop = f := rfl
@[simp] lemma unop_op {X Y : Cᵒᵖ} (f : X ⟶ Y) : f.unop.op = f := rfl

attribute [irreducible] op unop
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it can be correct to set these here and then locally mark them as semireducible in other files.

@rwbarton
Copy link
Copy Markdown
Collaborator

I'd like to continue to advocate for using irreducible type synonyms for both the objects and the morphisms of the opposite category. In outline:

  • It's important to consistently use the correct "spelling" (e.g., op X) for objects and morphisms of the opposite category, so as to both eliminate ambiguity in Lean input and output (e.g., goals) and also guide automated reasoning.
  • In principle we could always use the correct spelling even with an ordinary semireducible type synonym, but in practice it's too difficult to always get it right without automated checking.
  • The irreducible type synonym approach enforces correct spelling while introducing almost no additional overhead for the user (see below).
  • Using a structure instead of an irreducible type synonym introduces serious complications, starting already at the definition of the opposite category. (The obvious definition id := λ X, (𝟙 (unop X)).op doesn't type check because the right hand side has the type op (unop X) ⟶ op (unop X) not X ⟶ X.)
  • In a language like Coq that supports definitional eta for records, these complications would not arise. Lean does not support definitional eta for records but we can simulate the case of a one-field record using the irreducible type synonym method and (if even necessary?) consider the support in other languages as justification for the use of this method.

Concretely, I suggest 89379bc, which is basically a cleaned-up implementation of the original version of this PR. Of note:

  • Most of the changes are to insert op or unop as needed in the statements of definitions and lemmas.
  • Few proofs are affected, and only in simple ways.
  • A number of proofs can be deleted because tidy now has the correct information to produce them automatically. In particular, the lemmas op_id_app and op_comp_app were required for category_theory.cocones, but tidy now succeeds without them.

I was originally intending to also prepare a version which uses a structure in place of the irreducible type synonym, but in view of the complications which arose already with the category instance for the opposite category I decided not to finish it.

@digama0
Copy link
Copy Markdown
Member

digama0 commented Jan 25, 2019

Okay, go ahead. Get this PR working or make a replacement and I'll merge it.

@jcommelin
Copy link
Copy Markdown
Member

@rwbarton Thanks a lot for this thorough review of the options! I'm glad we're converging towards a solution.

@kim-em
Copy link
Copy Markdown
Collaborator Author

kim-em commented Jan 25, 2019 via email

@rwbarton
Copy link
Copy Markdown
Collaborator

New PR at #627. It contains only the minimum changes to opposite and not the handful of other improvements in this PR.

@rwbarton
Copy link
Copy Markdown
Collaborator

@semorrison, would you like me to make new PRs for the parts of this not covered by #627 and #633?

@kim-em
Copy link
Copy Markdown
Collaborator Author

kim-em commented Jan 29, 2019 via email

@kim-em
Copy link
Copy Markdown
Collaborator Author

kim-em commented Feb 2, 2019

I'm closing this; everything has been divided up into smaller PRs.

@kim-em kim-em closed this Feb 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants