Skip to content

Commit a904cfd

Browse files
committed
chore: backports for leanprover/lean4#4814 (part 1) (#15245)
The new variables inclusion mechanism leanprover/lean4#4814 is going to require many changes to Mathlib. Some of these changes are to make sure typeclass hypotheses are not unnecessarily included. This is achieved either by using `section` to bound `variable [...]`, using `variable ... in`, or reordering theorems. (I think you can see all three being using here.) Other changes require adding `include ...` to include variables that the new mechanism won't automatically include. These changes can't be backported to master, and instead are accumulating on the `lean-pr-testing-4814` branch.
1 parent 67f52fe commit a904cfd

File tree

7 files changed

+32
-18
lines changed

7 files changed

+32
-18
lines changed

Mathlib/Control/Lawful.lean

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,10 @@ variable {α β ε : Type u} {m : Type u → Type v} (x : ExceptT ε m α)
5555
theorem run_mk (x : m (Except ε α)) : ExceptT.run (ExceptT.mk x) = x :=
5656
rfl
5757

58-
variable [Monad m]
59-
6058
attribute [simp] run_bind
6159

6260
@[simp]
63-
theorem run_monadLift {n} [MonadLiftT n m] (x : n α) :
61+
theorem run_monadLift {n} [Monad m] [MonadLiftT n m] (x : n α) :
6462
(monadLift x : ExceptT ε m α).run = Except.ok <$> (monadLift x : m α) :=
6563
rfl
6664

@@ -115,6 +113,7 @@ variable {α β : Type u} {m : Type u → Type v} (x : OptionT m α)
115113
theorem run_mk (x : m (Option α)) : OptionT.run (OptionT.mk x) = x :=
116114
rfl
117115

116+
section Monad
118117
variable [Monad m]
119118

120119
@[simp]
@@ -142,6 +141,8 @@ theorem run_monadLift {n} [MonadLiftT n m] (x : n α) :
142141
(monadLift x : OptionT m α).run = (monadLift x : m α) >>= fun a => pure (some a) :=
143142
rfl
144143

144+
end Monad
145+
145146
@[simp]
146147
theorem run_monadMap {n} [MonadFunctorT n m] (f : ∀ {α}, n α → n α) :
147148
(monadMap (@f) x : OptionT m α).run = monadMap (@f) x.run :=

Mathlib/Control/Traversable/Basic.lean

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ end ApplicativeTransformation
7979

8080
namespace ApplicativeTransformation
8181

82-
variable (F : Type u → Type v) [Applicative F] [LawfulApplicative F]
83-
variable (G : Type u → Type w) [Applicative G] [LawfulApplicative G]
82+
variable (F : Type u → Type v) [Applicative F]
83+
variable (G : Type u → Type w) [Applicative G]
8484

8585
instance : CoeFun (ApplicativeTransformation F G) fun _ => ∀ {α}, F α → G α :=
8686
fun η ↦ η.app _⟩
@@ -133,6 +133,8 @@ theorem preserves_pure {α} : ∀ x : α, η (pure x) = pure x :=
133133
theorem preserves_seq {α β : Type u} : ∀ (x : F (α → β)) (y : F α), η (x <*> y) = η x <*> η y :=
134134
η.preserves_seq'
135135

136+
variable [LawfulApplicative F] [LawfulApplicative G]
137+
136138
@[functor_norm]
137139
theorem preserves_map {α β} (x : α → β) (y : F α) : η (x <$> y) = x <$> η y := by
138140
rw [← pure_seq, η.preserves_seq, preserves_pure, pure_seq]
@@ -154,7 +156,7 @@ instance : Inhabited (ApplicativeTransformation F F) :=
154156

155157
universe s t
156158

157-
variable {H : Type u → Type s} [Applicative H] [LawfulApplicative H]
159+
variable {H : Type u → Type s} [Applicative H]
158160

159161
/-- The composition of applicative transformations. -/
160162
def comp (η' : ApplicativeTransformation G H) (η : ApplicativeTransformation F G) :

Mathlib/Init/Algebra/Classes.lean

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -333,22 +333,22 @@ local infixl:50 " ≺ " => r
333333
def Equiv (a b : α) : Prop :=
334334
¬a ≺ b ∧ ¬b ≺ a
335335

336-
variable [IsStrictWeakOrder α r]
337-
338336
local infixl:50 " ≈ " => @Equiv _ r
339337

340-
theorem erefl (a : α) : a ≈ a :=
341-
⟨irrefl a, irrefl a⟩
342-
343338
theorem esymm {a b : α} : a ≈ b → b ≈ a := fun ⟨h₁, h₂⟩ => ⟨h₂, h₁⟩
344339

345-
theorem etrans {a b c : α} : a ≈ b → b ≈ c → a ≈ c :=
346-
incomp_trans
347-
348340
theorem not_lt_of_equiv {a b : α} : a ≈ b → ¬a ≺ b := fun h => h.1
349341

350342
theorem not_lt_of_equiv' {a b : α} : a ≈ b → ¬b ≺ a := fun h => h.2
351343

344+
variable [IsStrictWeakOrder α r]
345+
346+
theorem erefl (a : α) : a ≈ a :=
347+
⟨irrefl a, irrefl a⟩
348+
349+
theorem etrans {a b c : α} : a ≈ b → b ≈ c → a ≈ c :=
350+
incomp_trans
351+
352352
instance isEquiv : IsEquiv α (@Equiv _ r) where
353353
refl := erefl
354354
trans _ _ _ := etrans

Mathlib/Logic/Basic.lean

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,9 @@ either branch to `a`. -/
951951
theorem ite_apply (f g : ∀ a, σ a) (a : α) : (ite P f g) a = ite P (f a) (g a) :=
952952
dite_apply P (fun _ ↦ f) (fun _ ↦ g) a
953953

954+
section
955+
variable [Decidable Q]
956+
954957
theorem ite_and : ite (P ∧ Q) a b = ite P (ite Q a b) b := by
955958
by_cases hp : P <;> by_cases hq : Q <;> simp [hp, hq]
956959

@@ -966,6 +969,8 @@ theorem ite_ite_comm (h : P → ¬Q) :
966969
if Q then b else if P then a else c :=
967970
dite_dite_comm P Q h
968971

972+
end
973+
969974
variable {P Q}
970975

971976
theorem ite_prop_iff_or : (if P then Q else R) ↔ (P ∧ Q ∨ ¬ P ∧ R) := by

Mathlib/Logic/Function/Basic.lean

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ end SurjInv
454454

455455
section Update
456456

457-
variable {α : Sort u} {β : α → Sort v} {α' : Sort w} [DecidableEq α] [DecidableEq α']
457+
variable {α : Sort u} {β : α → Sort v} {α' : Sort w} [DecidableEq α]
458458
{f g : (a : α) → β a} {a : α} {b : β a}
459459

460460

@@ -523,6 +523,8 @@ theorem update_comp_eq_of_forall_ne' {α'} (g : ∀ a, β a) {f : α' → α} {i
523523
(h : ∀ x, f x ≠ i) : (fun j ↦ (update g i a) (f j)) = fun j ↦ g (f j) :=
524524
funext fun _ ↦ update_noteq (h _) _ _
525525

526+
variable [DecidableEq α']
527+
526528
/-- Non-dependent version of `Function.update_comp_eq_of_forall_ne'` -/
527529
theorem update_comp_eq_of_forall_ne {α β : Sort*} (g : α' → β) {f : α → α'} {i : α'} (a : β)
528530
(h : ∀ x, f x ≠ i) : update g i a ∘ f = g ∘ f :=

Mathlib/Order/Defs.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def ltByCases (x y : α) {P : Sort*} (h₁ : x < y → P) (h₂ : x = y → P) (
346346
if h : x < y then h₁ h
347347
else if h' : y < x then h₃ h' else h₂ (le_antisymm (le_of_not_gt h') (le_of_not_gt h))
348348

349-
theorem le_imp_le_of_lt_imp_lt {β} [Preorder α] [LinearOrder β] {a b : α} {c d : β}
349+
theorem le_imp_le_of_lt_imp_lt {α β} [Preorder α] [LinearOrder β] {a b : α} {c d : β}
350350
(H : d < c → b < a) (h : a ≤ b) : c ≤ d :=
351351
le_of_not_lt fun h' => not_le_of_gt (H h') h
352352

Mathlib/Tactic/PushNeg.lean

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace Mathlib.Tactic.PushNeg
2222

2323
open Lean Meta Elab.Tactic Parser.Tactic
2424

25-
variable (p q : Prop) {α : Sort*} (s : α → Prop)
25+
variable (p q : Prop) {α : Sort*} {β : Type*} (s : α → Prop)
2626

2727
theorem not_not_eq : (¬ ¬ p) = p := propext not_not
2828
theorem not_and_eq : (¬ (p ∧ q)) = (p → ¬ q) := propext not_and
@@ -35,12 +35,16 @@ theorem not_ne_eq (x y : α) : (¬ (x ≠ y)) = (x = y) := ne_eq x y ▸ not_not
3535
theorem not_iff : (¬ (p ↔ q)) = ((p ∧ ¬ q) ∨ (¬ p ∧ q)) := propext <|
3636
_root_.not_iff.trans <| iff_iff_and_or_not_and_not.trans <| by rw [not_not, or_comm]
3737

38-
variable {β : Type*} [LinearOrder β]
38+
section LinearOrder
39+
variable [LinearOrder β]
40+
3941
theorem not_le_eq (a b : β) : (¬ (a ≤ b)) = (b < a) := propext not_le
4042
theorem not_lt_eq (a b : β) : (¬ (a < b)) = (b ≤ a) := propext not_lt
4143
theorem not_ge_eq (a b : β) : (¬ (a ≥ b)) = (a < b) := propext not_le
4244
theorem not_gt_eq (a b : β) : (¬ (a > b)) = (a ≤ b) := propext not_lt
4345

46+
end LinearOrder
47+
4448
theorem not_nonempty_eq (s : Set β) : (¬ s.Nonempty) = (s = ∅) := by
4549
have A : ∀ (x : β), ¬(x ∈ (∅ : Set β)) := fun x ↦ id
4650
simp only [Set.Nonempty, not_exists, eq_iff_iff]

0 commit comments

Comments
 (0)