Skip to content

Commit d99b0d9

Browse files
xgenereuxMaría Inés de Frutos Fernández
authored andcommitted
feat(Algebra/Adjoin): CoeDep instances for Algebra.adjoin on singletons (leanprover-community#36439)
It is a common occurrence that I need to consider an element `x` or some polynomial evaluated in `x`, `p.eval x` as an element of `Algebra.adjoin R {x}`. This makes it so that we can write - `(x : adjoin R {x})` instead of `⟨x, self_mem_adjoin_singleton A x⟩` - `(p.eval x : adjoin R {x})` instead of `⟨p.aeval x, aeval_mem_adjoin_singleton A x⟩` This is particularly useful when we need to write the type anyways, so that we need not to write `(⟨p.aeval x, aeval_mem_adjoin_singleton A x⟩ : adjoin R {x})` anymore. Co-authored-by: María Inés de Frutos Fernández <[mariaines.dff@gmail.com](mailto:mariaines.dff@gmail.com)> Co-authored-by: Xavier Genereux <xaviergenereux@hotmail.com>
1 parent 0ec5998 commit d99b0d9

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

Mathlib/Algebra/Algebra/Subalgebra/Lattice.lean

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,34 @@ theorem subset_adjoin : s ⊆ adjoin R s :=
517517
@[aesop 80% (rule_sets := [SetLike])]
518518
theorem mem_adjoin_of_mem {s : Set A} {x : A} (hx : x ∈ s) : x ∈ adjoin R s := subset_adjoin hx
519519

520+
/-
521+
The following set-up allows one to write `xₖ : R[x₁, ..., xₙ]` instead of
522+
`(⟨xₖ, "membership proof"⟩ : R[x₁, ..., xₙ])`.
523+
524+
The idea is to recurse through the list of `x₁, ..., xₙ` until we find the appropriate `xₖ`.
525+
By design, it only triggers if the set is of the form `insert x₁ (insert x₂ (...(s)))` or
526+
`{x₁, ..., xₙ}`.
527+
-/
528+
529+
variable {α : Type*}
530+
531+
/-- Supporting class for coercions `xₖ : R[x₁, ..., xₙ]`. -/
532+
class CoeAdjoinAux (x : α) (s : Set α) : Prop where mem : x ∈ s
533+
534+
scoped instance (x : α) : CoeAdjoinAux x {x} := ⟨Set.mem_singleton x⟩
535+
536+
scoped instance (x : α) (s : Set α) : CoeAdjoinAux x (insert x s) := ⟨Set.mem_insert x s⟩
537+
538+
scoped instance (x y : α) (s : Set α) [CoeAdjoinAux x s] : CoeAdjoinAux x (insert y s) :=
539+
⟨Set.mem_insert_of_mem y CoeAdjoinAux.mem⟩
540+
541+
/-- Enables notation `xₖ : R[x₁, ..., xₙ]` instead of
542+
`(⟨xₖ, "membership proof"⟩ : R[x₁, ..., xₙ])`. -/
543+
scoped instance {A B : Type*} [CommSemiring A] [Semiring B] [Algebra A B]
544+
(s : Set B) (x : B) [CoeAdjoinAux x s] :
545+
CoeDep B x (adjoin A s) where
546+
coe := ⟨x, mem_adjoin_of_mem CoeAdjoinAux.mem⟩
547+
520548
theorem adjoin_le {S : Subalgebra R A} (H : s ⊆ S) : adjoin R s ≤ S :=
521549
Algebra.gc.l_le H
522550

Mathlib/RingTheory/Adjoin/Polynomial/Basic.lean

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ theorem adjoin_singleton_eq_range_aeval (x : A) :
5757
theorem _root_.Polynomial.aeval_mem_adjoin_singleton : aeval x p ∈ adjoin R {x} := by
5858
simp [adjoin_singleton_eq_range_aeval]
5959

60+
instance {A B : Type*} [CommSemiring A] [Semiring B] [Algebra A B] (x : B) (p : Polynomial A) :
61+
CoeDep B (p.aeval x) (Algebra.adjoin A {x}) where
62+
coe := ⟨p.aeval x, aeval_mem_adjoin_singleton A x⟩
63+
6064
theorem adjoin_mem_exists_aeval {a : A} (h : a ∈ R[x]) :
6165
∃ p : R[X], aeval x p = a := by
6266
rw [Algebra.adjoin_singleton_eq_range_aeval] at h
@@ -74,9 +78,7 @@ Proving a fact about `a : adjoin R {x}` is the same as proving it for
7478
`aeval x p` where `p`is an arbitrary polynomial. -/
7579
@[elab_as_elim]
7680
theorem adjoin_singleton_induction {M : (adjoin R {x}) → Prop}
77-
(a : adjoin R {x}) (f : ∀ (p : Polynomial R),
78-
M (⟨aeval x p, aeval_mem_adjoin_singleton R x⟩ : adjoin R {x})) :
79-
M a := by
81+
(a : adjoin R {x}) (f : ∀ (p : Polynomial R), M (aeval x p : adjoin R {x})) : M a := by
8082
obtain ⟨p, hp⟩ := Algebra.adjoin_eq_exists_aeval _ x a
8183
grind
8284

0 commit comments

Comments
 (0)