-
Notifications
You must be signed in to change notification settings - Fork 460
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
Wishlist for congruence lemmas #988
Comments
leodemoura
added a commit
that referenced
this issue
Feb 3, 2022
leodemoura
added a commit
that referenced
this issue
Feb 3, 2022
TODO: congruence lemma must be automatically generated. see #988
@gebner Thanks! The current TODO list is:
@[congr] theorem decide_congr (p q : Prop) (h : p = q) [s₁ : Decidable p] [s₂ : Decidable q] : decide p = decide q := by
subst h
have : s₁ = s₂ := Subsingleton.elim s₁ s₂
subst this
rfl
|
@gebner Do you have an example that needs |
leodemoura
added a commit
that referenced
this issue
Feb 3, 2022
…ments on the lhs must be free variables see #988
Here you go: def Submodule (α : Type u) [OfNat α 0] := { s : Set α // s.mem 0 }
instance [OfNat α 0] : CoeSort (Submodule α) (Type u) where coe s := s.1
instance [OfNat α 0] (p : Submodule α) : Inhabited p where default := ⟨0, p.2⟩
example (p : Nat → Submodule Nat) :
Pi.single (f := (p ·)) (x - x) ⟨0, (p ..).2⟩ = Pi.single 0 ⟨0, (p ..).2⟩ := by
simp only [Nat.sub_self] -- should work |
leodemoura
added a commit
that referenced
this issue
Feb 3, 2022
leodemoura
added a commit
that referenced
this issue
Feb 5, 2022
TODO: proof is still missing see #988
leodemoura
added a commit
that referenced
this issue
Feb 5, 2022
leodemoura
added a commit
that referenced
this issue
Feb 8, 2022
TODO: cache auto generated congr theorems, and `removeUnnecessaryCasts` see #988
leodemoura
added a commit
that referenced
this issue
Feb 8, 2022
leodemoura
added a commit
that referenced
this issue
Feb 8, 2022
@gebner The new test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As discussed yesterday, let me summarize the important changes related to congruence lemmas in Lean 3 as well as some features that we wanted to add but would have required larger refactorings.
The first two items are about automatically generated congruence lemmas for simp. The other two are about user congruence lemmas marked with
@[congr]
. Automatically generated congruence lemmas for congruence closure haven't really changed (these are also used for thecongr
andconvert
tactics).Rewriting under subsingleton arguments
If
f : α → β
, then the congruence lemma should be∀ x y, x = y → f x = f y
even ifα
is subsingleton.The rationale is that we want to rewrite e.g. zero-length vectors (see corresponding PR leanprover-community/lean#134):
Dependent subsingleton instances
This is about functions like the following, where
Decidable
/Fintype
are classes that are also subsingletons but not inProp
:The congruence lemma for
decide
should be∀ p q, p = q → [Decidable p] → [Decidable q] → decide p = decide q
.Rationale: generating the instance for
Decidable q
as‹p = q› ▸ ‹Decidable p›
introduces a diamond, since‹p = q› ▸ ‹Decidable p›
and‹Decidable q›
are typically not defeq. One consequence of using▸
instead of synthesizing the instance is that simp cannot solve the following example (becausedecide p = decide p
would not be true by reflexivity):Relevant PR: leanprover-community/lean#665 Note: we had to disable the subsingleton check completely in Lean 3 because of massive performance issues with TC synthesis. Now it only checks if the type is of the form
∀ ..., decidable ...
.Partially applied user congruence lemmas
This is an actual wishlist item and not implemented in Lean 3 either yet. But it fits the theme, so let me mention it here.
User congruence lemmas should also work if they only match a prefix of the application. That is, a congruence lemma
Array.get as i = Array.get bs j
should also apply to a subtermArray.get xs j y
.Type-specific congruence lemmas
Another actual wishlist item, it would be useful to lift the restriction that all function arguments on the lhs must be free variables. With polymorphic functions, you often want to declare a more specific congruence lemma for some types (e.g. if some arguments become subtypes---see congruence lemma for the
Fin
argument ofArray.get
above.)Requested on Zulip: https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/simp.20simp/near/263872040
The text was updated successfully, but these errors were encountered: