feat: new variable command
Resolves #2452. For theorems, section variables are now conditionally included when elaborating the theorem body and sending the result to the kernel based on their use in the header; elaboration of the header is unchanged. Definitions as well are unchanged for now because it looks like adapting them will take more follow-up work: changing their behavior broke more than 30 tests while changing theorems' behavior broke one.
Specifically, section variables are included if they
- are directly referenced by the theorem header,
- are included via the new
includecommand in the current section, - are directly referenced by any variable included by these rules, OR
- are instance-implicit variables that reference any variable included by these rules.
For porting, a new option deprecated.oldSectionVars is included to locally switch back to the old behavior.
TODO: testing, docs, possibly more conveniences
are instance-implicit variables that reference any variable included by these rules.
Should this be "are instance-implicit variables and all referenced variables are included by these rules."? For example, if I have
variable {R : Type*} [CommRing R] {M : Type*} [AddCommGroup M] [Module R M]
If only one of R/M is referenced, Module R M should not be included.
(I would also love it if include supports binder updates)
are instance-implicit variables that reference any variable included by these rules.
Should this be "are instance-implicit variables and all referenced variables are included by these rules."? For example, if I have
Makes sense to me, updated.
(I would also love it if include supports binder updates)
Would include {v} be equivalent to variable {v} include v? I'm not sure yet what to think about such overloading of semantics
Yes, those would be equivalent.
In Mathlib we are striving towards using variable {v} and include v only using in (i.e. variable {v} or include v is banned, you should solely use variable {v} in and include v in).
If we follow that rule, then the ability to write include {v} means that we don't need variable {v} anymore in Mathlib, since all its uses can be replaced by include.
Yes, those would be equivalent.
In Mathlib we are striving towards using
variable {v}andinclude vonly usingin(i.e.variable {v}orinclude vis banned, you should solely usevariable {v} inandinclude v in). If we follow that rule, then the ability to writeinclude {v}means that we don't needvariable {v}anymore in Mathlib, since all its uses can be replaced byinclude.
@fpvandoorn, I've finally started looking at Mathlib under this PR (the lean-pr-testing-4814 branch). (It is going to be epic! :-)
I've already encountered a few places where is seems rather inconvenient for only using include ... in, rather than bounded by a section. Please see https://github.com/leanprover-community/mathlib4/commit/c3ec6bedfaddc035e24f86a44099089854a7d13c for the first two examples I encountered.
Mathlib CI status (docs):
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-07-29 00:04:50) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-07-29 00:21:53) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-07-29 00:31:07) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-07-29 00:56:45) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-07-29 02:21:32) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build this PR didn't complete normally. (2024-07-29 05:57:56) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-07-29 06:05:06) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-07-29 06:15:19) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build this PR didn't complete normally. (2024-07-30 10:19:25) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-07-30 10:37:08) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-07-30 10:59:38) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-07-30 12:12:17) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-07-30 17:09:43) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-07-30 18:21:30) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-07-30 19:29:34) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-07-30 19:46:03) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build against this PR was cancelled. (2024-07-31 00:21:34) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-07-31 00:26:47) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build against this PR was cancelled. (2024-07-31 00:54:05) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-07-31 01:01:23) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-07-31 02:00:29) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build against this PR was cancelled. (2024-07-31 03:15:41) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-07-31 03:22:36) View Log
- ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the
nightly-with-mathlibbranch. Trygit rebase afe0b5a01326a99fb18049d29d7f62a5ffc83c15 --onto 69f86d6478a944865969abebc45f9417b212a5fc. (2024-07-31 04:33:26) - 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-07-31 14:00:19) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build this PR didn't complete normally. (2024-07-31 23:05:32) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build this PR didn't complete normally. (2024-07-31 23:06:17) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build this PR didn't complete normally. (2024-07-31 23:10:24) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build this PR didn't complete normally. (2024-08-01 01:51:37) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build against this PR was cancelled. (2024-08-01 02:08:07) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-01 02:16:36) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build this PR didn't complete normally. (2024-08-01 06:10:05) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-01 06:18:22) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build this PR didn't complete normally. (2024-08-01 07:02:30) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build this PR didn't complete normally. (2024-08-01 09:12:04) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-01 09:20:22) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-01 14:02:31) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-01 15:01:57) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-02 00:19:36) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-02 01:04:37) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-02 03:11:59) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-02 03:20:48) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-02 04:09:26) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-02 04:42:01) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-02 05:36:15) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-02 05:50:37) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-02 06:38:16) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-02 07:27:44) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-02 11:51:19) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-02 12:01:36) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build against this PR was cancelled. (2024-08-05 04:18:07) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-05 04:27:34) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build against this PR was cancelled. (2024-08-05 06:32:49) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-05 06:43:40) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-05 07:43:28) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-05 08:49:17) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build against this PR was cancelled. (2024-08-05 12:35:43) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-05 12:44:41) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-06 05:16:44) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build against this PR was cancelled. (2024-08-06 06:12:22) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-06 06:17:09) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-06 06:51:27) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-06 09:57:39) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build this PR didn't complete normally. (2024-08-06 11:48:23) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-06 11:51:01) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-06 12:12:46) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-06 15:26:32) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-06 15:40:40) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-06 16:28:09) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-06 17:46:56) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-06 20:56:42) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-06 23:32:13) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build against this PR was cancelled. (2024-08-06 23:58:55) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-07 00:01:47) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-07 00:22:54) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-07 00:25:09) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-07 00:41:36) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build against this PR was cancelled. (2024-08-07 01:08:37) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-07 01:31:29) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build against this PR was cancelled. (2024-08-07 01:56:21) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build against this PR was cancelled. (2024-08-07 02:00:46) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build against this PR was cancelled. (2024-08-07 02:13:56) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build this PR didn't complete normally. (2024-08-07 02:14:44) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build against this PR was cancelled. (2024-08-07 02:23:11) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build against this PR was cancelled. (2024-08-07 02:35:59) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build against this PR was cancelled. (2024-08-07 02:41:30) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build against this PR was cancelled. (2024-08-07 02:45:41) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build against this PR was cancelled. (2024-08-07 02:59:57) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build against this PR was cancelled. (2024-08-07 03:03:17) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-07 03:12:10) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-07 04:53:24) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-07 05:33:09) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-07 06:26:56) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-07 09:29:27) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build this PR didn't complete normally. (2024-08-08 01:50:32) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build against this PR was cancelled. (2024-08-08 01:50:58) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build this PR didn't complete normally. (2024-08-08 02:15:58) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build against this PR was cancelled. (2024-08-08 02:16:47) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build against this PR was cancelled. (2024-08-08 02:21:12) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-08 02:46:46) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-08 03:56:17) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-08 04:29:35) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build this PR didn't complete normally. (2024-08-08 06:11:56) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-08 06:15:28) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-08 07:25:00) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-08 07:29:17) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-08 07:43:53) View Log
- 💥 Mathlib branch lean-pr-testing-4814 build failed against this PR. (2024-08-08 07:52:40) View Log
- ❌ Mathlib branch lean-pr-testing-4814 built against this PR, but linting failed. (2024-08-08 09:25:43) View Log
- ❌ Mathlib branch lean-pr-testing-4814 built against this PR, but linting failed. (2024-08-08 09:51:40) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build against this PR was cancelled. (2024-08-08 10:26:53) View Log
- ❌ Mathlib branch lean-pr-testing-4814 built against this PR, but linting failed. (2024-08-08 10:39:08) View Log
- ❌ Mathlib branch lean-pr-testing-4814 built against this PR, but linting failed. (2024-08-08 13:18:33) View Log
- ❌ Mathlib branch lean-pr-testing-4814 built against this PR, but testing failed. (2024-08-08 23:52:28) View Log
- 🟡 Mathlib branch lean-pr-testing-4814 build against this PR was cancelled. (2024-08-09 00:36:18) View Log
- ❌ Mathlib branch lean-pr-testing-4814 built against this PR, but testing failed. (2024-08-09 01:33:26) View Log
- ❌ Mathlib branch lean-pr-testing-4814 built against this PR, but testing failed. (2024-08-09 04:32:55) View Log
- ❌ Mathlib branch lean-pr-testing-4814 built against this PR, but testing failed. (2024-08-09 04:46:38) View Log
- ❌ Mathlib branch lean-pr-testing-4814 built against this PR, but testing failed. (2024-08-10 12:37:05) View Log
Re: looking at Mathlib on this PR. So far there are two classes of problems: typeclasses hypothesis being included which should not be (for which the new linter is really helpful), and variables with need an include.
Fixing the first class of problems requires either adding sections to bound variable [...] scopes, using variable ... in, or reordering results.
I propose that for anyone working on the Mathlib branch for this PR, we try to backport all the changes of the first form.
A reasonable workflow seems to be:
- As you make changes on
lean-pr-testing-4814, any changes that useinclude(i.e. which will not work on master), you immediately stage. - But any changes for excluding typeclasses hypotheses you leave unstage.
- At suitable intervals, make a commit of the stages changes on
lean-pr-testing-4814 - Then stash the remaining changes, make a new branch off master, make a PR from it, and then ~~merge that branch~~ cherry-pick that commit back to
lean-pr-testing-4814. (See first example of such a PR at https://github.com/leanprover-community/mathlib4/pull/15245.)
(We have have following a similar workflow for the byAsSorry branch, c.f. zulip discusssion.)
This is going to be a massive adaptation exercise to get this working, and I will need help to get it done.
are instance-implicit variables that reference any variable included by these rules.
Should this be "are instance-implicit variables and all referenced variables are included by these rules."? For example, if I have
Makes sense to me, updated.
@Kha, I think this change may have not worked as intended. In Mathlib on lean-pr-testing-4814 I am seeing:
section Trans
variable [IsTrans N r] (m n : M) {a b c d : N}
-- Lemmas with 3 elements.
theorem act_rel_of_rel_of_act_rel (ab : r a b) (rl : r (μ m b) c) : r (μ m a) c :=
_root_.trans (act_rel_act_of_rel m ab) rl
theorem rel_act_of_rel_of_rel_act (ab : r a b) (rr : r c (μ m a)) : r c (μ m b) :=
_root_.trans rr (act_rel_act_of_rel _ ab)
end Trans
failing with failed to synthesize IsTrans N r, despite both the arguments of IsTrans being mentioned in the theorem statement.
(I have no idea why in Mathlib the first argument of IsTrans is explicit rather than implicit -- I'll investigate that too...)
Let me know if you'd like a minimization of this.
@Kha, another bug, where typeclass arguments that are included transitively can be included with multiplicity, apparently!
Again on lean-pr-testing-4814, in Mathlib.Order.Monotone, we see:
variable (α) [Preorder α] [Nonempty α] [NoMinOrder α] [NoMaxOrder α]
/-- If `α` is a nonempty preorder with no minimal or maximal elements, then there exists a strictly
monotone function `f : ℤ → α`. -/
theorem exists_strictMono : ∃ f : ℤ → α, StrictMono f := by
inhabit α
rcases Nat.exists_strictMono' (default : α) with ⟨f, hf, hf₀⟩
rcases Nat.exists_strictAnti' (default : α) with ⟨g, hg, hg₀⟩
refine ⟨fun n ↦ Int.casesOn n f fun n ↦ g (n + 1), strictMono_int_of_lt_succ ?_⟩
rintro (n | _ | n)
· exact hf n.lt_succ_self
· show g 1 < f 0
rw [hf₀, ← hg₀]
exact hg Nat.zero_lt_one
· exact hg (Nat.lt_succ_self _)
resulting in the signature
Int.exists_strictMono.{u} (α : Type u) [Preorder α] [Preorder α] [Nonempty α] [NoMinOrder α] [NoMaxOrder α] :
∃ f, StrictMono f
where apparently [Preorder α] has been added twice, once because [NoMinOrder α] needs it and again because [NoMaxOrder α] needs it.
Again, please let me know if you'd like an minimisation.
And another problem, @Kha! We have places in Mathlib where people have add implicit arguments that could otherwise be automatically included instance arguments, on the principle that it is faster/better to find these by unification from later arguments that to redo typeclass search.
Here's an example from Mathlib in Mathlib.Algebra.GroupWithZero:
@[simp]
lemma coe_copy {_ : MulZeroOneClass α} {_ : MulZeroOneClass β} (f : α →*₀ β) (f' : α → β) (h) :
(f.copy f' h) = f' := rfl
lemma copy_eq {_ : MulZeroOneClass α} {_ : MulZeroOneClass β} (f : α →*₀ β) (f' : α → β) (h) :
f.copy f' h = f := DFunLike.ext' h
It's perfectly okay on master to just omit these, and instead we get corresponding instance arguments included.
However on lean-pr-testing-4814, we get warning, because the signature becomes:
MonoidWithZeroHom.coe_copy.{u_2, u_3} {α : Type u_2} {β : Type u_3} [MulZeroOneClass α] [MulZeroOneClass β] :
∀ {x : MulZeroOneClass α} {x_1 : MulZeroOneClass β} (f : α →*₀ β) (f' : α → β) (h : f' = ⇑f), ⇑(f.copy f' h) = f'
I'm uncertain the best way to proceed here. Probably we ought to make the variable inclusion mechanism robust to this, and decline to include instance arguments if there are already there as implicit arguments. In this particular case it's fine to just remove them, but I don't think that is always going to be true.
Again, let me know if you want a minimization.
And more. :-)
We may need to pull in typeclass arguments because they mention the type of an included argument, not just the argument itself.
For example in Mathlib we have in Mathlib.Algebra.Ring.Divisibility.Basic:
variable [Semigroup α] [Semigroup β] {F : Type*} [EquivLike F α β] [MulEquivClass F α β] (f : F)
theorem map_dvd_iff {a b} : f a ∣ f b ↔ a ∣ b :=
let f := MulEquivClass.toMulEquiv f
⟨fun h ↦ by rw [← f.left_inv a, ← f.left_inv b]; exact map_dvd f.symm h, map_dvd f⟩
theorem MulEquiv.decompositionMonoid [DecompositionMonoid β] : DecompositionMonoid α where
primal a b c h := by
rw [← map_dvd_iff f, map_mul] at h
obtain ⟨a₁, a₂, h⟩ := DecompositionMonoid.primal _ h
refine ⟨symm f a₁, symm f a₂, ?_⟩
simp_rw [← map_dvd_iff f, ← map_mul, eq_symm_apply]
iterate 2 erw [(f : α ≃* β).apply_symm_apply]
exact h
Here include f on MulEquiv.decompositionMonoid (or just writing it as an explicit argument) doesn't suffice to pull in [MulEquivClass F α β].
Making matters worse, if we just change the theorem statement to
theorem MulEquiv.decompositionMonoid
[MulEquivClass F α β] (f : F) [DecompositionMonoid β] : DecompositionMonoid α where
then we get the incorrect warning:
included section variable '[MulEquivClass F α β]' is not used in 'MulEquiv.decompositionMonoid', consider excluding it
I can work around this by just not making it a section variable at all and instead including it directly in both theorems here.
(As above with minimization. :-)
Yes, those would be equivalent. In Mathlib we are striving towards using
variable {v}andinclude vonly usingin(i.e.variable {v}orinclude vis banned, you should solely usevariable {v} inandinclude v in). If we follow that rule, then the ability to writeinclude {v}means that we don't needvariable {v}anymore in Mathlib, since all its uses can be replaced byinclude.@fpvandoorn, I've finally started looking at Mathlib under this PR (the
lean-pr-testing-4814branch). (It is going to be epic! :-)I've already encountered a few places where is seems rather inconvenient for only using
include ... in, rather than bounded by a section. Please see leanprover-community/mathlib4@c3ec6be for the first two examples I encountered.
We should probably not strive to do this immediately. Another thing we can consider is to have (in the long-term) no explicit variables, instead repeating those in each theorem statement. That should also reduce the number of includes.
But given your example we maybe want to allow having a global include directly after the corresponding variable statement. Then whenever that variable is visible it will have the include statement.
@Kha, another bug, where typeclass arguments that are included transitively can be included with multiplicity, apparently!
Again on
lean-pr-testing-4814, inMathlib.Order.Monotone, we see:variable (α) [Preorder α] [Nonempty α] [NoMinOrder α] [NoMaxOrder α] /-- If `α` is a nonempty preorder with no minimal or maximal elements, then there exists a strictly monotone function `f : ℤ → α`. -/ theorem exists_strictMono : ∃ f : ℤ → α, StrictMono f := by inhabit α rcases Nat.exists_strictMono' (default : α) with ⟨f, hf, hf₀⟩ rcases Nat.exists_strictAnti' (default : α) with ⟨g, hg, hg₀⟩ refine ⟨fun n ↦ Int.casesOn n f fun n ↦ g (n + 1), strictMono_int_of_lt_succ ?_⟩ rintro (n | _ | n) · exact hf n.lt_succ_self · show g 1 < f 0 rw [hf₀, ← hg₀] exact hg Nat.zero_lt_one · exact hg (Nat.lt_succ_self _)resulting in the signature
Int.exists_strictMono.{u} (α : Type u) [Preorder α] [Preorder α] [Nonempty α] [NoMinOrder α] [NoMaxOrder α] : ∃ f, StrictMono fwhere apparently
[Preorder α]has been added twice, once because[NoMinOrder α]needs it and again because[NoMaxOrder α]needs it.Again, please let me know if you'd like an minimisation.
This looks correct in that there is already a [Preorder \a] in context. But also #2789 comes in and prevents us from removing the duplicate assumption unless broken into two lines.
variable (α)
variable [Nonempty α] [NoMinOrder α] [NoMaxOrder α]
Probably we ought to make the variable inclusion mechanism robust to this, and decline to include instance arguments if there are already there as implicit arguments.
I'm a bit wary of comparing parameter types by equality (which one?). I assume one alternative would be to name the instances and use binder updates instead?
failing with
failed to synthesize IsTrans N r, despite both the arguments ofIsTransbeing mentioned in the theorem statement.
Fixed
Here
include fonMulEquiv.decompositionMonoid(or just writing it as an explicit argument) doesn't suffice to pull in[MulEquivClass F α β].
Fixed
I am rebasing on nightly-with-mathlib (regenerating update-stage0 commits), in order to keep the Mathlib adaptation branch viable.
Sigh, the merge conflict with master occurs after nightly-with-mathlib. I will see if Mathlib's nightly-testing is compatible with master, and if so rebase this onto master.
Edit: nope! We'll need to wait until the next nightly release and try again then.