path stringlengths 11 71 | content stringlengths 75 124k |
|---|---|
Data\Stream\Init.lean | /-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Mathlib.Data.Stream.Defs
import Mathlib.Logic.Function.Basic
import Mathlib.Init.Data.List.Basic
import Mathlib.Data.List.Basic
/-!
# Streams a.k.a. infinite lists a.k.a. infinite sequences
Porting note:
This file used to be in the core library. It was moved to `mathlib` and renamed to `init` to avoid
name clashes. -/
open Nat Function Option
namespace Stream'
universe u v w
variable {α : Type u} {β : Type v} {δ : Type w}
instance [Inhabited α] : Inhabited (Stream' α) :=
⟨Stream'.const default⟩
protected theorem eta (s : Stream' α) : (head s::tail s) = s :=
funext fun i => by cases i <;> rfl
@[ext]
protected theorem ext {s₁ s₂ : Stream' α} : (∀ n, get s₁ n = get s₂ n) → s₁ = s₂ :=
fun h => funext h
@[simp]
theorem get_zero_cons (a : α) (s : Stream' α) : get (a::s) 0 = a :=
rfl
@[simp]
theorem head_cons (a : α) (s : Stream' α) : head (a::s) = a :=
rfl
@[simp]
theorem tail_cons (a : α) (s : Stream' α) : tail (a::s) = s :=
rfl
@[simp]
theorem get_drop (n m : ℕ) (s : Stream' α) : get (drop m s) n = get s (n + m) :=
rfl
theorem tail_eq_drop (s : Stream' α) : tail s = drop 1 s :=
rfl
@[simp]
theorem drop_drop (n m : ℕ) (s : Stream' α) : drop n (drop m s) = drop (n + m) s := by
ext; simp [Nat.add_assoc]
@[simp] theorem get_tail {n : ℕ} {s : Stream' α} : s.tail.get n = s.get (n + 1) := rfl
@[simp] theorem tail_drop' {i : ℕ} {s : Stream' α} : tail (drop i s) = s.drop (i+1) := by
ext; simp [Nat.add_comm, Nat.add_assoc, Nat.add_left_comm]
@[simp] theorem drop_tail' {i : ℕ} {s : Stream' α} : drop i (tail s) = s.drop (i+1) := rfl
theorem tail_drop (n : ℕ) (s : Stream' α) : tail (drop n s) = drop n (tail s) := by simp
theorem get_succ (n : ℕ) (s : Stream' α) : get s (succ n) = get (tail s) n :=
rfl
@[simp]
theorem get_succ_cons (n : ℕ) (s : Stream' α) (x : α) : get (x::s) n.succ = get s n :=
rfl
@[simp] theorem drop_zero {s : Stream' α} : s.drop 0 = s := rfl
theorem drop_succ (n : ℕ) (s : Stream' α) : drop (succ n) s = drop n (tail s) :=
rfl
theorem head_drop (a : Stream' α) (n : ℕ) : (a.drop n).head = a.get n := by simp
theorem cons_injective2 : Function.Injective2 (cons : α → Stream' α → Stream' α) := fun x y s t h =>
⟨by rw [← get_zero_cons x s, h, get_zero_cons],
Stream'.ext fun n => by rw [← get_succ_cons n _ x, h, get_succ_cons]⟩
theorem cons_injective_left (s : Stream' α) : Function.Injective fun x => cons x s :=
cons_injective2.left _
theorem cons_injective_right (x : α) : Function.Injective (cons x) :=
cons_injective2.right _
theorem all_def (p : α → Prop) (s : Stream' α) : All p s = ∀ n, p (get s n) :=
rfl
theorem any_def (p : α → Prop) (s : Stream' α) : Any p s = ∃ n, p (get s n) :=
rfl
@[simp]
theorem mem_cons (a : α) (s : Stream' α) : a ∈ a::s :=
Exists.intro 0 rfl
theorem mem_cons_of_mem {a : α} {s : Stream' α} (b : α) : a ∈ s → a ∈ b::s := fun ⟨n, h⟩ =>
Exists.intro (succ n) (by rw [get_succ, tail_cons, h])
theorem eq_or_mem_of_mem_cons {a b : α} {s : Stream' α} : (a ∈ b::s) → a = b ∨ a ∈ s :=
fun ⟨n, h⟩ => by
cases' n with n'
· left
exact h
· right
rw [get_succ, tail_cons] at h
exact ⟨n', h⟩
theorem mem_of_get_eq {n : ℕ} {s : Stream' α} {a : α} : a = get s n → a ∈ s := fun h =>
Exists.intro n h
section Map
variable (f : α → β)
theorem drop_map (n : ℕ) (s : Stream' α) : drop n (map f s) = map f (drop n s) :=
Stream'.ext fun _ => rfl
@[simp]
theorem get_map (n : ℕ) (s : Stream' α) : get (map f s) n = f (get s n) :=
rfl
theorem tail_map (s : Stream' α) : tail (map f s) = map f (tail s) := rfl
@[simp]
theorem head_map (s : Stream' α) : head (map f s) = f (head s) :=
rfl
theorem map_eq (s : Stream' α) : map f s = f (head s)::map f (tail s) := by
rw [← Stream'.eta (map f s), tail_map, head_map]
theorem map_cons (a : α) (s : Stream' α) : map f (a::s) = f a::map f s := by
rw [← Stream'.eta (map f (a::s)), map_eq]; rfl
@[simp]
theorem map_id (s : Stream' α) : map id s = s :=
rfl
@[simp]
theorem map_map (g : β → δ) (f : α → β) (s : Stream' α) : map g (map f s) = map (g ∘ f) s :=
rfl
@[simp]
theorem map_tail (s : Stream' α) : map f (tail s) = tail (map f s) :=
rfl
theorem mem_map {a : α} {s : Stream' α} : a ∈ s → f a ∈ map f s := fun ⟨n, h⟩ =>
Exists.intro n (by rw [get_map, h])
theorem exists_of_mem_map {f} {b : β} {s : Stream' α} : b ∈ map f s → ∃ a, a ∈ s ∧ f a = b :=
fun ⟨n, h⟩ => ⟨get s n, ⟨n, rfl⟩, h.symm⟩
end Map
section Zip
variable (f : α → β → δ)
theorem drop_zip (n : ℕ) (s₁ : Stream' α) (s₂ : Stream' β) :
drop n (zip f s₁ s₂) = zip f (drop n s₁) (drop n s₂) :=
Stream'.ext fun _ => rfl
@[simp]
theorem get_zip (n : ℕ) (s₁ : Stream' α) (s₂ : Stream' β) :
get (zip f s₁ s₂) n = f (get s₁ n) (get s₂ n) :=
rfl
theorem head_zip (s₁ : Stream' α) (s₂ : Stream' β) : head (zip f s₁ s₂) = f (head s₁) (head s₂) :=
rfl
theorem tail_zip (s₁ : Stream' α) (s₂ : Stream' β) :
tail (zip f s₁ s₂) = zip f (tail s₁) (tail s₂) :=
rfl
theorem zip_eq (s₁ : Stream' α) (s₂ : Stream' β) :
zip f s₁ s₂ = f (head s₁) (head s₂)::zip f (tail s₁) (tail s₂) := by
rw [← Stream'.eta (zip f s₁ s₂)]; rfl
@[simp]
theorem get_enum (s : Stream' α) (n : ℕ) : get (enum s) n = (n, s.get n) :=
rfl
theorem enum_eq_zip (s : Stream' α) : enum s = zip Prod.mk nats s :=
rfl
end Zip
@[simp]
theorem mem_const (a : α) : a ∈ const a :=
Exists.intro 0 rfl
theorem const_eq (a : α) : const a = a::const a := by
apply Stream'.ext; intro n
cases n <;> rfl
@[simp]
theorem tail_const (a : α) : tail (const a) = const a :=
suffices tail (a::const a) = const a by rwa [← const_eq] at this
rfl
@[simp]
theorem map_const (f : α → β) (a : α) : map f (const a) = const (f a) :=
rfl
@[simp]
theorem get_const (n : ℕ) (a : α) : get (const a) n = a :=
rfl
@[simp]
theorem drop_const (n : ℕ) (a : α) : drop n (const a) = const a :=
Stream'.ext fun _ => rfl
@[simp]
theorem head_iterate (f : α → α) (a : α) : head (iterate f a) = a :=
rfl
theorem get_succ_iterate' (n : ℕ) (f : α → α) (a : α) :
get (iterate f a) (succ n) = f (get (iterate f a) n) := rfl
theorem tail_iterate (f : α → α) (a : α) : tail (iterate f a) = iterate f (f a) := by
ext n
rw [get_tail]
induction' n with n' ih
· rfl
· rw [get_succ_iterate', ih, get_succ_iterate']
theorem iterate_eq (f : α → α) (a : α) : iterate f a = a::iterate f (f a) := by
rw [← Stream'.eta (iterate f a)]
rw [tail_iterate]; rfl
@[simp]
theorem get_zero_iterate (f : α → α) (a : α) : get (iterate f a) 0 = a :=
rfl
theorem get_succ_iterate (n : ℕ) (f : α → α) (a : α) :
get (iterate f a) (succ n) = get (iterate f (f a)) n := by rw [get_succ, tail_iterate]
section Bisim
variable (R : Stream' α → Stream' α → Prop)
/-- equivalence relation -/
local infixl:50 " ~ " => R
/-- Streams `s₁` and `s₂` are defined to be bisimulations if
their heads are equal and tails are bisimulations. -/
def IsBisimulation :=
∀ ⦃s₁ s₂⦄, s₁ ~ s₂ →
head s₁ = head s₂ ∧ tail s₁ ~ tail s₂
theorem get_of_bisim (bisim : IsBisimulation R) :
∀ {s₁ s₂} (n), s₁ ~ s₂ → get s₁ n = get s₂ n ∧ drop (n + 1) s₁ ~ drop (n + 1) s₂
| _, _, 0, h => bisim h
| _, _, n + 1, h =>
match bisim h with
| ⟨_, trel⟩ => get_of_bisim bisim n trel
-- If two streams are bisimilar, then they are equal
theorem eq_of_bisim (bisim : IsBisimulation R) : ∀ {s₁ s₂}, s₁ ~ s₂ → s₁ = s₂ := fun r =>
Stream'.ext fun n => And.left (get_of_bisim R bisim n r)
end Bisim
theorem bisim_simple (s₁ s₂ : Stream' α) :
head s₁ = head s₂ → s₁ = tail s₁ → s₂ = tail s₂ → s₁ = s₂ := fun hh ht₁ ht₂ =>
eq_of_bisim (fun s₁ s₂ => head s₁ = head s₂ ∧ s₁ = tail s₁ ∧ s₂ = tail s₂)
(fun s₁ s₂ ⟨h₁, h₂, h₃⟩ => by
constructor
· exact h₁
rw [← h₂, ← h₃]
(repeat' constructor) <;> assumption)
(And.intro hh (And.intro ht₁ ht₂))
theorem coinduction {s₁ s₂ : Stream' α} :
head s₁ = head s₂ →
(∀ (β : Type u) (fr : Stream' α → β),
fr s₁ = fr s₂ → fr (tail s₁) = fr (tail s₂)) → s₁ = s₂ :=
fun hh ht =>
eq_of_bisim
(fun s₁ s₂ =>
head s₁ = head s₂ ∧
∀ (β : Type u) (fr : Stream' α → β), fr s₁ = fr s₂ → fr (tail s₁) = fr (tail s₂))
(fun s₁ s₂ h =>
have h₁ : head s₁ = head s₂ := And.left h
have h₂ : head (tail s₁) = head (tail s₂) := And.right h α (@head α) h₁
have h₃ :
∀ (β : Type u) (fr : Stream' α → β),
fr (tail s₁) = fr (tail s₂) → fr (tail (tail s₁)) = fr (tail (tail s₂)) :=
fun β fr => And.right h β fun s => fr (tail s)
And.intro h₁ (And.intro h₂ h₃))
(And.intro hh ht)
@[simp]
theorem iterate_id (a : α) : iterate id a = const a :=
coinduction rfl fun β fr ch => by rw [tail_iterate, tail_const]; exact ch
theorem map_iterate (f : α → α) (a : α) : iterate f (f a) = map f (iterate f a) := by
funext n
induction' n with n' ih
· rfl
· unfold map iterate get
rw [map, get] at ih
rw [iterate]
exact congrArg f ih
section Corec
theorem corec_def (f : α → β) (g : α → α) (a : α) : corec f g a = map f (iterate g a) :=
rfl
theorem corec_eq (f : α → β) (g : α → α) (a : α) : corec f g a = f a::corec f g (g a) := by
rw [corec_def, map_eq, head_iterate, tail_iterate]; rfl
theorem corec_id_id_eq_const (a : α) : corec id id a = const a := by
rw [corec_def, map_id, iterate_id]
theorem corec_id_f_eq_iterate (f : α → α) (a : α) : corec id f a = iterate f a :=
rfl
end Corec
section Corec'
theorem corec'_eq (f : α → β × α) (a : α) : corec' f a = (f a).1::corec' f (f a).2 :=
corec_eq _ _ _
end Corec'
theorem unfolds_eq (g : α → β) (f : α → α) (a : α) : unfolds g f a = g a::unfolds g f (f a) := by
unfold unfolds; rw [corec_eq]
theorem get_unfolds_head_tail : ∀ (n : ℕ) (s : Stream' α),
get (unfolds head tail s) n = get s n := by
intro n; induction' n with n' ih
· intro s
rfl
· intro s
rw [get_succ, get_succ, unfolds_eq, tail_cons, ih]
theorem unfolds_head_eq : ∀ s : Stream' α, unfolds head tail s = s := fun s =>
Stream'.ext fun n => get_unfolds_head_tail n s
theorem interleave_eq (s₁ s₂ : Stream' α) : s₁ ⋈ s₂ = head s₁::head s₂::(tail s₁ ⋈ tail s₂) := by
let t := tail s₁ ⋈ tail s₂
show s₁ ⋈ s₂ = head s₁::head s₂::t
unfold interleave; unfold corecOn; rw [corec_eq]; dsimp; rw [corec_eq]; rfl
theorem tail_interleave (s₁ s₂ : Stream' α) : tail (s₁ ⋈ s₂) = s₂ ⋈ tail s₁ := by
unfold interleave corecOn; rw [corec_eq]; rfl
theorem interleave_tail_tail (s₁ s₂ : Stream' α) : tail s₁ ⋈ tail s₂ = tail (tail (s₁ ⋈ s₂)) := by
rw [interleave_eq s₁ s₂]; rfl
theorem get_interleave_left : ∀ (n : ℕ) (s₁ s₂ : Stream' α),
get (s₁ ⋈ s₂) (2 * n) = get s₁ n
| 0, s₁, s₂ => rfl
| n + 1, s₁, s₂ => by
change get (s₁ ⋈ s₂) (succ (succ (2 * n))) = get s₁ (succ n)
rw [get_succ, get_succ, interleave_eq, tail_cons, tail_cons]
rw [get_interleave_left n (tail s₁) (tail s₂)]
rfl
theorem get_interleave_right : ∀ (n : ℕ) (s₁ s₂ : Stream' α),
get (s₁ ⋈ s₂) (2 * n + 1) = get s₂ n
| 0, s₁, s₂ => rfl
| n + 1, s₁, s₂ => by
change get (s₁ ⋈ s₂) (succ (succ (2 * n + 1))) = get s₂ (succ n)
rw [get_succ, get_succ, interleave_eq, tail_cons, tail_cons,
get_interleave_right n (tail s₁) (tail s₂)]
rfl
theorem mem_interleave_left {a : α} {s₁ : Stream' α} (s₂ : Stream' α) : a ∈ s₁ → a ∈ s₁ ⋈ s₂ :=
fun ⟨n, h⟩ => Exists.intro (2 * n) (by rw [h, get_interleave_left])
theorem mem_interleave_right {a : α} {s₁ : Stream' α} (s₂ : Stream' α) : a ∈ s₂ → a ∈ s₁ ⋈ s₂ :=
fun ⟨n, h⟩ => Exists.intro (2 * n + 1) (by rw [h, get_interleave_right])
theorem odd_eq (s : Stream' α) : odd s = even (tail s) :=
rfl
@[simp]
theorem head_even (s : Stream' α) : head (even s) = head s :=
rfl
theorem tail_even (s : Stream' α) : tail (even s) = even (tail (tail s)) := by
unfold even
rw [corec_eq]
rfl
theorem even_cons_cons (a₁ a₂ : α) (s : Stream' α) : even (a₁::a₂::s) = a₁::even s := by
unfold even
rw [corec_eq]; rfl
theorem even_tail (s : Stream' α) : even (tail s) = odd s :=
rfl
theorem even_interleave (s₁ s₂ : Stream' α) : even (s₁ ⋈ s₂) = s₁ :=
eq_of_bisim (fun s₁' s₁ => ∃ s₂, s₁' = even (s₁ ⋈ s₂))
(fun s₁' s₁ ⟨s₂, h₁⟩ => by
rw [h₁]
constructor
· rfl
· exact ⟨tail s₂, by rw [interleave_eq, even_cons_cons, tail_cons]⟩)
(Exists.intro s₂ rfl)
theorem interleave_even_odd (s₁ : Stream' α) : even s₁ ⋈ odd s₁ = s₁ :=
eq_of_bisim (fun s' s => s' = even s ⋈ odd s)
(fun s' s (h : s' = even s ⋈ odd s) => by
rw [h]; constructor
· rfl
· simp [odd_eq, odd_eq, tail_interleave, tail_even])
rfl
theorem get_even : ∀ (n : ℕ) (s : Stream' α), get (even s) n = get s (2 * n)
| 0, s => rfl
| succ n, s => by
change get (even s) (succ n) = get s (succ (succ (2 * n)))
rw [get_succ, get_succ, tail_even, get_even n]; rfl
theorem get_odd : ∀ (n : ℕ) (s : Stream' α), get (odd s) n = get s (2 * n + 1) := fun n s => by
rw [odd_eq, get_even]; rfl
theorem mem_of_mem_even (a : α) (s : Stream' α) : a ∈ even s → a ∈ s := fun ⟨n, h⟩ =>
Exists.intro (2 * n) (by rw [h, get_even])
theorem mem_of_mem_odd (a : α) (s : Stream' α) : a ∈ odd s → a ∈ s := fun ⟨n, h⟩ =>
Exists.intro (2 * n + 1) (by rw [h, get_odd])
theorem nil_append_stream (s : Stream' α) : appendStream' [] s = s :=
rfl
theorem cons_append_stream (a : α) (l : List α) (s : Stream' α) :
appendStream' (a::l) s = a::appendStream' l s :=
rfl
theorem append_append_stream : ∀ (l₁ l₂ : List α) (s : Stream' α),
l₁ ++ l₂ ++ₛ s = l₁ ++ₛ (l₂ ++ₛ s)
| [], l₂, s => rfl
| List.cons a l₁, l₂, s => by
rw [List.cons_append, cons_append_stream, cons_append_stream, append_append_stream l₁]
theorem map_append_stream (f : α → β) :
∀ (l : List α) (s : Stream' α), map f (l ++ₛ s) = List.map f l ++ₛ map f s
| [], s => rfl
| List.cons a l, s => by
rw [cons_append_stream, List.map_cons, map_cons, cons_append_stream, map_append_stream f l]
theorem drop_append_stream : ∀ (l : List α) (s : Stream' α), drop l.length (l ++ₛ s) = s
| [], s => by rfl
| List.cons a l, s => by
rw [List.length_cons, drop_succ, cons_append_stream, tail_cons, drop_append_stream l s]
theorem append_stream_head_tail (s : Stream' α) : [head s] ++ₛ tail s = s := by
rw [cons_append_stream, nil_append_stream, Stream'.eta]
theorem mem_append_stream_right : ∀ {a : α} (l : List α) {s : Stream' α}, a ∈ s → a ∈ l ++ₛ s
| _, [], _, h => h
| a, List.cons _ l, s, h =>
have ih : a ∈ l ++ₛ s := mem_append_stream_right l h
mem_cons_of_mem _ ih
theorem mem_append_stream_left : ∀ {a : α} {l : List α} (s : Stream' α), a ∈ l → a ∈ l ++ₛ s
| _, [], _, h => absurd h (List.not_mem_nil _)
| a, List.cons b l, s, h =>
Or.elim (List.eq_or_mem_of_mem_cons h) (fun aeqb : a = b => Exists.intro 0 aeqb)
fun ainl : a ∈ l => mem_cons_of_mem b (mem_append_stream_left s ainl)
@[simp]
theorem take_zero (s : Stream' α) : take 0 s = [] :=
rfl
-- This lemma used to be simp, but we removed it from the simp set because:
-- 1) It duplicates the (often large) `s` term, resulting in large tactic states.
-- 2) It conflicts with the very useful `dropLast_take` lemma below (causing nonconfluence).
theorem take_succ (n : ℕ) (s : Stream' α) : take (succ n) s = head s::take n (tail s) :=
rfl
@[simp] theorem take_succ_cons {a : α} (n : ℕ) (s : Stream' α) :
take (n+1) (a::s) = a :: take n s := rfl
theorem take_succ' {s : Stream' α} : ∀ n, s.take (n+1) = s.take n ++ [s.get n]
| 0 => rfl
| n+1 => by rw [take_succ, take_succ' n, ← List.cons_append, ← take_succ, get_tail]
@[simp]
theorem length_take (n : ℕ) (s : Stream' α) : (take n s).length = n := by
induction n generalizing s <;> simp [*, take_succ]
@[simp]
theorem take_take {s : Stream' α} : ∀ {m n}, (s.take n).take m = s.take (min n m)
| 0, n => by rw [Nat.min_zero, List.take_zero, take_zero]
| m, 0 => by rw [Nat.zero_min, take_zero, List.take_nil]
| m+1, n+1 => by rw [take_succ, List.take_cons, Nat.succ_min_succ, take_succ, take_take]
@[simp] theorem concat_take_get {n : ℕ} {s : Stream' α} : s.take n ++ [s.get n] = s.take (n+1) :=
(take_succ' n).symm
theorem get?_take {s : Stream' α} : ∀ {k n}, k < n → (s.take n).get? k = s.get k
| 0, n+1, _ => rfl
| k+1, n+1, h => by rw [take_succ, List.get?, get?_take (Nat.lt_of_succ_lt_succ h), get_succ]
theorem get?_take_succ (n : ℕ) (s : Stream' α) :
List.get? (take (succ n) s) n = some (get s n) :=
get?_take (Nat.lt_succ_self n)
@[simp] theorem dropLast_take {n : ℕ} {xs : Stream' α} :
(Stream'.take n xs).dropLast = Stream'.take (n-1) xs := by
cases n with
| zero => simp
| succ n => rw [take_succ', List.dropLast_concat, Nat.add_one_sub_one]
@[simp]
theorem append_take_drop : ∀ (n : ℕ) (s : Stream' α),
appendStream' (take n s) (drop n s) = s := by
intro n
induction' n with n' ih
· intro s
rfl
· intro s
rw [take_succ, drop_succ, cons_append_stream, ih (tail s), Stream'.eta]
-- Take theorem reduces a proof of equality of infinite streams to an
-- induction over all their finite approximations.
theorem take_theorem (s₁ s₂ : Stream' α) : (∀ n : ℕ, take n s₁ = take n s₂) → s₁ = s₂ := by
intro h; apply Stream'.ext; intro n
induction' n with n _
· have aux := h 1
simp? [take] at aux says
simp only [take, List.cons.injEq, and_true] at aux
exact aux
· have h₁ : some (get s₁ (succ n)) = some (get s₂ (succ n)) := by
rw [← get?_take_succ, ← get?_take_succ, h (succ (succ n))]
injection h₁
protected theorem cycle_g_cons (a : α) (a₁ : α) (l₁ : List α) (a₀ : α) (l₀ : List α) :
Stream'.cycleG (a, a₁::l₁, a₀, l₀) = (a₁, l₁, a₀, l₀) :=
rfl
theorem cycle_eq : ∀ (l : List α) (h : l ≠ []), cycle l h = l ++ₛ cycle l h
| [], h => absurd rfl h
| List.cons a l, _ =>
have gen : ∀ l' a', corec Stream'.cycleF Stream'.cycleG (a', l', a, l) =
(a'::l') ++ₛ corec Stream'.cycleF Stream'.cycleG (a, l, a, l) := by
intro l'
induction' l' with a₁ l₁ ih
· intros
rw [corec_eq]
rfl
· intros
rw [corec_eq, Stream'.cycle_g_cons, ih a₁]
rfl
gen l a
theorem mem_cycle {a : α} {l : List α} : ∀ h : l ≠ [], a ∈ l → a ∈ cycle l h := fun h ainl => by
rw [cycle_eq]; exact mem_append_stream_left _ ainl
@[simp]
theorem cycle_singleton (a : α) : cycle [a] (by simp) = const a :=
coinduction rfl fun β fr ch => by rwa [cycle_eq, const_eq]
theorem tails_eq (s : Stream' α) : tails s = tail s::tails (tail s) := by
unfold tails; rw [corec_eq]; rfl
@[simp]
theorem get_tails : ∀ (n : ℕ) (s : Stream' α), get (tails s) n = drop n (tail s) := by
intro n; induction' n with n' ih
· intros
rfl
· intro s
rw [get_succ, drop_succ, tails_eq, tail_cons, ih]
theorem tails_eq_iterate (s : Stream' α) : tails s = iterate tail (tail s) :=
rfl
theorem inits_core_eq (l : List α) (s : Stream' α) :
initsCore l s = l::initsCore (l ++ [head s]) (tail s) := by
unfold initsCore corecOn
rw [corec_eq]
theorem tail_inits (s : Stream' α) :
tail (inits s) = initsCore [head s, head (tail s)] (tail (tail s)) := by
unfold inits
rw [inits_core_eq]; rfl
theorem inits_tail (s : Stream' α) : inits (tail s) = initsCore [head (tail s)] (tail (tail s)) :=
rfl
theorem cons_get_inits_core :
∀ (a : α) (n : ℕ) (l : List α) (s : Stream' α),
(a::get (initsCore l s) n) = get (initsCore (a::l) s) n := by
intro a n
induction' n with n' ih
· intros
rfl
· intro l s
rw [get_succ, inits_core_eq, tail_cons, ih, inits_core_eq (a::l) s]
rfl
@[simp]
theorem get_inits : ∀ (n : ℕ) (s : Stream' α), get (inits s) n = take (succ n) s := by
intro n; induction' n with n' ih
· intros
rfl
· intros
rw [get_succ, take_succ, ← ih, tail_inits, inits_tail, cons_get_inits_core]
theorem inits_eq (s : Stream' α) :
inits s = [head s]::map (List.cons (head s)) (inits (tail s)) := by
apply Stream'.ext; intro n
cases n
· rfl
· rw [get_inits, get_succ, tail_cons, get_map, get_inits]
rfl
theorem zip_inits_tails (s : Stream' α) : zip appendStream' (inits s) (tails s) = const s := by
apply Stream'.ext; intro n
rw [get_zip, get_inits, get_tails, get_const, take_succ, cons_append_stream, append_take_drop,
Stream'.eta]
theorem identity (s : Stream' α) : pure id ⊛ s = s :=
rfl
theorem composition (g : Stream' (β → δ)) (f : Stream' (α → β)) (s : Stream' α) :
pure comp ⊛ g ⊛ f ⊛ s = g ⊛ (f ⊛ s) :=
rfl
theorem homomorphism (f : α → β) (a : α) : pure f ⊛ pure a = pure (f a) :=
rfl
theorem interchange (fs : Stream' (α → β)) (a : α) :
fs ⊛ pure a = (pure fun f : α → β => f a) ⊛ fs :=
rfl
theorem map_eq_apply (f : α → β) (s : Stream' α) : map f s = pure f ⊛ s :=
rfl
theorem get_nats (n : ℕ) : get nats n = n :=
rfl
theorem nats_eq : nats = cons 0 (map succ nats) := by
apply Stream'.ext; intro n
cases n
· rfl
rw [get_succ]; rfl
end Stream'
|
Data\String\Basic.lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Data.List.Lex
import Mathlib.Data.Char
import Mathlib.Tactic.AdaptationNote
import Mathlib.Algebra.Order.Group.Nat
/-!
# Strings
Supplementary theorems about the `String` type.
-/
namespace String
/-- `<` on string iterators. This coincides with `<` on strings as lists. -/
def ltb (s₁ s₂ : Iterator) : Bool :=
if s₂.hasNext then
if s₁.hasNext then
if s₁.curr = s₂.curr then
ltb s₁.next s₂.next
else s₁.curr < s₂.curr
else true
else false
instance LT' : LT String :=
⟨fun s₁ s₂ ↦ ltb s₁.iter s₂.iter⟩
instance decidableLT : @DecidableRel String (· < ·) := by
simp only [LT']
infer_instance -- short-circuit type class inference
/-- Induction on `String.ltb`. -/
def ltb.inductionOn.{u} {motive : Iterator → Iterator → Sort u} (it₁ it₂ : Iterator)
(ind : ∀ s₁ s₂ i₁ i₂, Iterator.hasNext ⟨s₂, i₂⟩ → Iterator.hasNext ⟨s₁, i₁⟩ →
get s₁ i₁ = get s₂ i₂ → motive (Iterator.next ⟨s₁, i₁⟩) (Iterator.next ⟨s₂, i₂⟩) →
motive ⟨s₁, i₁⟩ ⟨s₂, i₂⟩)
(eq : ∀ s₁ s₂ i₁ i₂, Iterator.hasNext ⟨s₂, i₂⟩ → Iterator.hasNext ⟨s₁, i₁⟩ →
¬ get s₁ i₁ = get s₂ i₂ → motive ⟨s₁, i₁⟩ ⟨s₂, i₂⟩)
(base₁ : ∀ s₁ s₂ i₁ i₂, Iterator.hasNext ⟨s₂, i₂⟩ → ¬ Iterator.hasNext ⟨s₁, i₁⟩ →
motive ⟨s₁, i₁⟩ ⟨s₂, i₂⟩)
(base₂ : ∀ s₁ s₂ i₁ i₂, ¬ Iterator.hasNext ⟨s₂, i₂⟩ → motive ⟨s₁, i₁⟩ ⟨s₂, i₂⟩) :
motive it₁ it₂ :=
if h₂ : it₂.hasNext then
if h₁ : it₁.hasNext then
if heq : it₁.curr = it₂.curr then
ind it₁.s it₂.s it₁.i it₂.i h₂ h₁ heq (inductionOn it₁.next it₂.next ind eq base₁ base₂)
else eq it₁.s it₂.s it₁.i it₂.i h₂ h₁ heq
else base₁ it₁.s it₂.s it₁.i it₂.i h₂ h₁
else base₂ it₁.s it₂.s it₁.i it₂.i h₂
theorem ltb_cons_addChar (c : Char) (cs₁ cs₂ : List Char) (i₁ i₂ : Pos) :
ltb ⟨⟨c :: cs₁⟩, i₁ + c⟩ ⟨⟨c :: cs₂⟩, i₂ + c⟩ = ltb ⟨⟨cs₁⟩, i₁⟩ ⟨⟨cs₂⟩, i₂⟩ := by
apply ltb.inductionOn ⟨⟨cs₁⟩, i₁⟩ ⟨⟨cs₂⟩, i₂⟩ (motive := fun ⟨⟨cs₁⟩, i₁⟩ ⟨⟨cs₂⟩, i₂⟩ ↦
ltb ⟨⟨c :: cs₁⟩, i₁ + c⟩ ⟨⟨c :: cs₂⟩, i₂ + c⟩ =
ltb ⟨⟨cs₁⟩, i₁⟩ ⟨⟨cs₂⟩, i₂⟩) <;> simp only <;>
intro ⟨cs₁⟩ ⟨cs₂⟩ i₁ i₂ <;>
intros <;>
(conv => lhs; unfold ltb) <;> (conv => rhs; unfold ltb) <;>
simp only [Iterator.hasNext_cons_addChar, ite_false, ite_true, *]
· rename_i h₂ h₁ heq ih
simp only [Iterator.next, next, heq, Iterator.curr, get_cons_addChar, ite_true] at ih ⊢
repeat rw [Pos.addChar_right_comm _ c]
exact ih
· rename_i h₂ h₁ hne
simp [Iterator.curr, get_cons_addChar, hne]
@[simp]
theorem lt_iff_toList_lt : ∀ {s₁ s₂ : String}, s₁ < s₂ ↔ s₁.toList < s₂.toList
| ⟨s₁⟩, ⟨s₂⟩ => show ltb ⟨⟨s₁⟩, 0⟩ ⟨⟨s₂⟩, 0⟩ ↔ s₁ < s₂ by
induction s₁ generalizing s₂ <;> cases s₂
· unfold ltb; decide
· rename_i c₂ cs₂; apply iff_of_true
· unfold ltb
#adaptation_note /-- v4.7.0-rc1 exclude reduceMk from simp -/
simp [-reduceMk, Iterator.hasNext, Char.utf8Size_pos]
· apply List.nil_lt_cons
· rename_i c₁ cs₁ ih; apply iff_of_false
· unfold ltb
#adaptation_note /-- v4.7.0-rc1 exclude reduceMk from simp -/
simp [-reduceMk, Iterator.hasNext]
· apply not_lt_of_lt; apply List.nil_lt_cons
· rename_i c₁ cs₁ ih c₂ cs₂; unfold ltb
simp only [Iterator.hasNext, Pos.byteIdx_zero, endPos, utf8ByteSize, utf8ByteSize.go,
add_pos_iff, Char.utf8Size_pos, or_true, decide_eq_true_eq, ↓reduceIte, Iterator.curr, get,
utf8GetAux, Iterator.next, next, Bool.ite_eq_true_distrib]
split_ifs with h
· subst c₂
suffices ltb ⟨⟨c₁ :: cs₁⟩, (0 : Pos) + c₁⟩ ⟨⟨c₁ :: cs₂⟩, (0 : Pos) + c₁⟩ =
ltb ⟨⟨cs₁⟩, 0⟩ ⟨⟨cs₂⟩, 0⟩ by rw [this]; exact (ih cs₂).trans List.Lex.cons_iff.symm
apply ltb_cons_addChar
· refine ⟨List.Lex.rel, fun e ↦ ?_⟩
cases e <;> rename_i h'
· contradiction
· assumption
instance LE : LE String :=
⟨fun s₁ s₂ ↦ ¬s₂ < s₁⟩
instance decidableLE : @DecidableRel String (· ≤ ·) := by
simp only [LE]
infer_instance -- short-circuit type class inference
@[simp]
theorem le_iff_toList_le {s₁ s₂ : String} : s₁ ≤ s₂ ↔ s₁.toList ≤ s₂.toList :=
(not_congr lt_iff_toList_lt).trans not_lt
theorem toList_inj {s₁ s₂ : String} : s₁.toList = s₂.toList ↔ s₁ = s₂ :=
⟨congr_arg mk, congr_arg toList⟩
theorem asString_nil : [].asString = "" :=
rfl
@[deprecated (since := "2024-06-04")] alias nil_asString_eq_empty := asString_nil
@[simp]
theorem toList_empty : "".toList = [] :=
rfl
theorem asString_toList (s : String) : s.toList.asString = s :=
rfl
@[deprecated (since := "2024-06-04")] alias asString_inv_toList := asString_toList
theorem toList_nonempty : ∀ {s : String}, s ≠ "" → s.toList = s.head :: (s.drop 1).toList
| ⟨s⟩, h => by
cases s with
| nil => simp at h
| cons c cs =>
simp only [toList, data_drop, List.drop_succ_cons, List.drop_zero, List.cons.injEq, and_true]
rfl
@[simp]
theorem head_empty : "".data.head! = default :=
rfl
instance : LinearOrder String where
le_refl a := le_iff_toList_le.mpr le_rfl
le_trans a b c := by
simp only [le_iff_toList_le]
apply le_trans
lt_iff_le_not_le a b := by
simp only [lt_iff_toList_lt, le_iff_toList_le, lt_iff_le_not_le]
le_antisymm a b := by
simp only [le_iff_toList_le, ← toList_inj]
apply le_antisymm
le_total a b := by
simp only [le_iff_toList_le]
apply le_total
decidableLE := String.decidableLE
compare_eq_compareOfLessAndEq a b := by
simp only [compare, compareOfLessAndEq, instLT, List.instLT, lt_iff_toList_lt, toList]
split_ifs <;>
simp only [List.lt_iff_lex_lt] at * <;>
contradiction
end String
open String
namespace List
theorem toList_asString (l : List Char) : l.asString.toList = l :=
rfl
@[deprecated (since := "2024-06-04")] alias toList_inv_asString := toList_asString
@[simp]
theorem length_asString (l : List Char) : l.asString.length = l.length :=
rfl
@[simp]
theorem asString_inj {l l' : List Char} : l.asString = l'.asString ↔ l = l' :=
⟨fun h ↦ by rw [← toList_asString l, ← toList_asString l', toList_inj, h],
fun h ↦ h ▸ rfl⟩
theorem asString_eq {l : List Char} {s : String} : l.asString = s ↔ l = s.toList := by
rw [← asString_toList s, asString_inj, asString_toList s]
end List
@[simp]
theorem String.length_data (s : String) : s.data.length = s.length :=
rfl
|
Data\String\Defs.lean | /-
Copyright (c) 2019 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon, Keeley Hoek, Floris van Doorn, Chris Bailey
-/
import Batteries.Data.String.Basic
import Batteries.Tactic.Alias
/-!
# Definitions for `String`
This file defines a bunch of functions for the `String` datatype.
-/
namespace String
/-- Pad `s : String` with repeated occurrences of `c : Char` until it's of length `n`.
If `s` is initially larger than `n`, just return `s`. -/
def leftpad (n : Nat) (c : Char := ' ') (s : String) : String :=
⟨List.leftpad n c s.data⟩
/-- Construct the string consisting of `n` copies of the character `c`. -/
def replicate (n : Nat) (c : Char) : String :=
⟨List.replicate n c⟩
-- TODO bring this definition in line with the above, either by:
-- adding `List.rightpad` to Batteries and changing the definition of `rightpad` here to match
-- or by changing the definition of `leftpad` above to match this
/-- Pad `s : String` with repeated occurrences of `c : Char` on the right until it's of length `n`.
If `s` is initially larger than `n`, just return `s`. -/
def rightpad (n : Nat) (c : Char := ' ') (s : String) : String :=
s ++ String.replicate (n - s.length) c
/-- `s.IsPrefix t` checks if the string `s` is a prefix of the string `t`. -/
def IsPrefix : String → String → Prop
| ⟨d1⟩, ⟨d2⟩ => List.IsPrefix d1 d2
/-- `s.IsSuffix t` checks if the string `s` is a suffix of the string `t`. -/
def IsSuffix : String → String → Prop
| ⟨d1⟩, ⟨d2⟩ => List.IsSuffix d1 d2
/-- `String.mapTokens c f s` tokenizes `s : string` on `c : char`, maps `f` over each token, and
then reassembles the string by intercalating the separator token `c` over the mapped tokens. -/
def mapTokens (c : Char) (f : String → String) : String → String :=
intercalate (singleton c) ∘ List.map f ∘ (·.split (· = c))
@[deprecated (since := "2024-06-04")] alias getRest := dropPrefix?
/-- Produce the head character from the string `s`, if `s` is not empty, otherwise `'A'`. -/
def head (s : String) : Char :=
s.iter.curr
end String
|
Data\String\Lemmas.lean | /-
Copyright (c) 2021 Chris Bailey. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Bailey
-/
import Mathlib.Data.Nat.Notation
import Mathlib.Data.String.Defs
import Mathlib.Tactic.Basic
/-!
# Miscellaneous lemmas about strings
-/
namespace String
lemma congr_append : ∀ (a b : String), a ++ b = String.mk (a.data ++ b.data)
| ⟨_⟩, ⟨_⟩ => rfl
@[simp] lemma length_replicate (n : ℕ) (c : Char) : (replicate n c).length = n := by
simp only [String.length, String.replicate, List.length_replicate]
lemma length_eq_list_length (l : List Char) : (String.mk l).length = l.length := by
simp only [String.length]
/-- The length of the String returned by `String.leftpad n a c` is equal
to the larger of `n` and `s.length` -/
@[simp] lemma leftpad_length (n : ℕ) (c : Char) :
∀ (s : String), (leftpad n c s).length = max n s.length
| ⟨s⟩ => by simp only [leftpad, String.length, List.leftpad_length]
lemma leftpad_prefix (n : ℕ) (c : Char) : ∀ s, IsPrefix (replicate (n - length s) c) (leftpad n c s)
| ⟨l⟩ => by simp only [IsPrefix, replicate, leftpad, String.length, List.leftpad_prefix]
lemma leftpad_suffix (n : ℕ) (c : Char) : ∀ s, IsSuffix s (leftpad n c s)
| ⟨l⟩ => by simp only [IsSuffix, replicate, leftpad, String.length, List.leftpad_suffix]
end String
|
Data\Sum\Basic.lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Yury G. Kudryashov
-/
import Mathlib.Logic.Function.Basic
import Mathlib.Tactic.MkIffOfInductiveProp
import Batteries.Data.Sum.Lemmas
/-!
# Additional lemmas about sum types
Most of the former contents of this file have been moved to Batteries.
-/
universe u v w x
variable {α : Type u} {α' : Type w} {β : Type v} {β' : Type x} {γ δ : Type*}
namespace Sum
theorem exists_sum {γ : α ⊕ β → Sort*} (p : (∀ ab, γ ab) → Prop) :
(∃ fab, p fab) ↔ (∃ fa fb, p (Sum.rec fa fb)) := by
rw [← not_forall_not, forall_sum]
simp
theorem inl_injective : Function.Injective (inl : α → α ⊕ β) := fun _ _ ↦ inl.inj
theorem inr_injective : Function.Injective (inr : β → α ⊕ β) := fun _ _ ↦ inr.inj
theorem sum_rec_congr (P : α ⊕ β → Sort*) (f : ∀ i, P (inl i)) (g : ∀ i, P (inr i))
{x y : α ⊕ β} (h : x = y) :
@Sum.rec _ _ _ f g x = cast (congr_arg P h.symm) (@Sum.rec _ _ _ f g y) := by cases h; rfl
section get
variable {x y : α ⊕ β}
theorem eq_left_iff_getLeft_eq {a : α} : x = inl a ↔ ∃ h, x.getLeft h = a := by
cases x <;> simp
theorem eq_right_iff_getRight_eq {b : β} : x = inr b ↔ ∃ h, x.getRight h = b := by
cases x <;> simp
theorem getLeft_eq_getLeft? (h₁ : x.isLeft) (h₂ : x.getLeft?.isSome) :
x.getLeft h₁ = x.getLeft?.get h₂ := by simp [← getLeft?_eq_some_iff]
theorem getRight_eq_getRight? (h₁ : x.isRight) (h₂ : x.getRight?.isSome) :
x.getRight h₁ = x.getRight?.get h₂ := by simp [← getRight?_eq_some_iff]
@[simp] theorem isSome_getLeft?_iff_isLeft : x.getLeft?.isSome ↔ x.isLeft := by
rw [isLeft_iff, Option.isSome_iff_exists]; simp
@[simp] theorem isSome_getRight?_iff_isRight : x.getRight?.isSome ↔ x.isRight := by
rw [isRight_iff, Option.isSome_iff_exists]; simp
end get
open Function (update update_eq_iff update_comp_eq_of_injective update_comp_eq_of_forall_ne)
@[simp]
theorem update_elim_inl [DecidableEq α] [DecidableEq (α ⊕ β)] {f : α → γ} {g : β → γ} {i : α}
{x : γ} : update (Sum.elim f g) (inl i) x = Sum.elim (update f i x) g :=
update_eq_iff.2 ⟨by simp, by simp (config := { contextual := true })⟩
@[simp]
theorem update_elim_inr [DecidableEq β] [DecidableEq (α ⊕ β)] {f : α → γ} {g : β → γ} {i : β}
{x : γ} : update (Sum.elim f g) (inr i) x = Sum.elim f (update g i x) :=
update_eq_iff.2 ⟨by simp, by simp (config := { contextual := true })⟩
@[simp]
theorem update_inl_comp_inl [DecidableEq α] [DecidableEq (α ⊕ β)] {f : α ⊕ β → γ} {i : α}
{x : γ} : update f (inl i) x ∘ inl = update (f ∘ inl) i x :=
update_comp_eq_of_injective _ inl_injective _ _
@[simp]
theorem update_inl_apply_inl [DecidableEq α] [DecidableEq (α ⊕ β)] {f : α ⊕ β → γ} {i j : α}
{x : γ} : update f (inl i) x (inl j) = update (f ∘ inl) i x j := by
rw [← update_inl_comp_inl, Function.comp_apply]
@[simp]
theorem update_inl_comp_inr [DecidableEq (α ⊕ β)] {f : α ⊕ β → γ} {i : α} {x : γ} :
update f (inl i) x ∘ inr = f ∘ inr :=
(update_comp_eq_of_forall_ne _ _) fun _ ↦ inr_ne_inl
theorem update_inl_apply_inr [DecidableEq (α ⊕ β)] {f : α ⊕ β → γ} {i : α} {j : β} {x : γ} :
update f (inl i) x (inr j) = f (inr j) :=
Function.update_noteq inr_ne_inl _ _
@[simp]
theorem update_inr_comp_inl [DecidableEq (α ⊕ β)] {f : α ⊕ β → γ} {i : β} {x : γ} :
update f (inr i) x ∘ inl = f ∘ inl :=
(update_comp_eq_of_forall_ne _ _) fun _ ↦ inl_ne_inr
theorem update_inr_apply_inl [DecidableEq (α ⊕ β)] {f : α ⊕ β → γ} {i : α} {j : β} {x : γ} :
update f (inr j) x (inl i) = f (inl i) :=
Function.update_noteq inl_ne_inr _ _
@[simp]
theorem update_inr_comp_inr [DecidableEq β] [DecidableEq (α ⊕ β)] {f : α ⊕ β → γ} {i : β}
{x : γ} : update f (inr i) x ∘ inr = update (f ∘ inr) i x :=
update_comp_eq_of_injective _ inr_injective _ _
@[simp]
theorem update_inr_apply_inr [DecidableEq β] [DecidableEq (α ⊕ β)] {f : α ⊕ β → γ} {i j : β}
{x : γ} : update f (inr i) x (inr j) = update (f ∘ inr) i x j := by
rw [← update_inr_comp_inr, Function.comp_apply]
@[simp]
theorem swap_leftInverse : Function.LeftInverse (@swap α β) swap :=
swap_swap
@[simp]
theorem swap_rightInverse : Function.RightInverse (@swap α β) swap :=
swap_swap
mk_iff_of_inductive_prop Sum.LiftRel Sum.liftRel_iff
namespace LiftRel
variable {r : α → γ → Prop} {s : β → δ → Prop} {x : α ⊕ β} {y : γ ⊕ δ}
{a : α} {b : β} {c : γ} {d : δ}
theorem isLeft_congr (h : LiftRel r s x y) : x.isLeft ↔ y.isLeft := by cases h <;> rfl
theorem isRight_congr (h : LiftRel r s x y) : x.isRight ↔ y.isRight := by cases h <;> rfl
theorem isLeft_left (h : LiftRel r s x (inl c)) : x.isLeft := by cases h; rfl
theorem isLeft_right (h : LiftRel r s (inl a) y) : y.isLeft := by cases h; rfl
theorem isRight_left (h : LiftRel r s x (inr d)) : x.isRight := by cases h; rfl
theorem isRight_right (h : LiftRel r s (inr b) y) : y.isRight := by cases h; rfl
theorem exists_of_isLeft_left (h₁ : LiftRel r s x y) (h₂ : x.isLeft) :
∃ a c, r a c ∧ x = inl a ∧ y = inl c := by
rcases isLeft_iff.mp h₂ with ⟨_, rfl⟩
simp only [liftRel_iff, false_and, and_false, exists_false, or_false] at h₁
exact h₁
theorem exists_of_isLeft_right (h₁ : LiftRel r s x y) (h₂ : y.isLeft) :
∃ a c, r a c ∧ x = inl a ∧ y = inl c := exists_of_isLeft_left h₁ ((isLeft_congr h₁).mpr h₂)
theorem exists_of_isRight_left (h₁ : LiftRel r s x y) (h₂ : x.isRight) :
∃ b d, s b d ∧ x = inr b ∧ y = inr d := by
rcases isRight_iff.mp h₂ with ⟨_, rfl⟩
simp only [liftRel_iff, false_and, and_false, exists_false, false_or] at h₁
exact h₁
theorem exists_of_isRight_right (h₁ : LiftRel r s x y) (h₂ : y.isRight) :
∃ b d, s b d ∧ x = inr b ∧ y = inr d :=
exists_of_isRight_left h₁ ((isRight_congr h₁).mpr h₂)
end LiftRel
section Lex
end Lex
end Sum
open Sum
namespace Function
theorem Injective.sum_elim {f : α → γ} {g : β → γ} (hf : Injective f) (hg : Injective g)
(hfg : ∀ a b, f a ≠ g b) : Injective (Sum.elim f g)
| inl _, inl _, h => congr_arg inl <| hf h
| inl _, inr _, h => (hfg _ _ h).elim
| inr _, inl _, h => (hfg _ _ h.symm).elim
| inr _, inr _, h => congr_arg inr <| hg h
theorem Injective.sum_map {f : α → β} {g : α' → β'} (hf : Injective f) (hg : Injective g) :
Injective (Sum.map f g)
| inl _, inl _, h => congr_arg inl <| hf <| inl.inj h
| inr _, inr _, h => congr_arg inr <| hg <| inr.inj h
theorem Surjective.sum_map {f : α → β} {g : α' → β'} (hf : Surjective f) (hg : Surjective g) :
Surjective (Sum.map f g)
| inl y =>
let ⟨x, hx⟩ := hf y
⟨inl x, congr_arg inl hx⟩
| inr y =>
let ⟨x, hx⟩ := hg y
⟨inr x, congr_arg inr hx⟩
theorem Bijective.sum_map {f : α → β} {g : α' → β'} (hf : Bijective f) (hg : Bijective g) :
Bijective (Sum.map f g) :=
⟨hf.injective.sum_map hg.injective, hf.surjective.sum_map hg.surjective⟩
end Function
namespace Sum
open Function
@[simp]
theorem map_injective {f : α → γ} {g : β → δ} :
Injective (Sum.map f g) ↔ Injective f ∧ Injective g :=
⟨fun h =>
⟨fun a₁ a₂ ha => inl_injective <| @h (inl a₁) (inl a₂) (congr_arg inl ha : _), fun b₁ b₂ hb =>
inr_injective <| @h (inr b₁) (inr b₂) (congr_arg inr hb : _)⟩,
fun h => h.1.sum_map h.2⟩
@[simp]
theorem map_surjective {f : α → γ} {g : β → δ} :
Surjective (Sum.map f g) ↔ Surjective f ∧ Surjective g :=
⟨ fun h => ⟨
(fun c => by
obtain ⟨a | b, h⟩ := h (inl c)
· exact ⟨a, inl_injective h⟩
· cases h),
(fun d => by
obtain ⟨a | b, h⟩ := h (inr d)
· cases h
· exact ⟨b, inr_injective h⟩)⟩,
fun h => h.1.sum_map h.2⟩
@[simp]
theorem map_bijective {f : α → γ} {g : β → δ} :
Bijective (Sum.map f g) ↔ Bijective f ∧ Bijective g :=
(map_injective.and map_surjective).trans <| and_and_and_comm
theorem elim_update_left [DecidableEq α] [DecidableEq β] (f : α → γ) (g : β → γ) (i : α) (c : γ) :
Sum.elim (Function.update f i c) g = Function.update (Sum.elim f g) (inl i) c := by
ext x
rcases x with x | x
· by_cases h : x = i
· subst h
simp
· simp [h]
· simp
theorem elim_update_right [DecidableEq α] [DecidableEq β] (f : α → γ) (g : β → γ) (i : β) (c : γ) :
Sum.elim f (Function.update g i c) = Function.update (Sum.elim f g) (inr i) c := by
ext x
rcases x with x | x
· simp
· by_cases h : x = i
· subst h
simp
· simp [h]
end Sum
/-!
### Ternary sum
Abbreviations for the maps from the summands to `α ⊕ β ⊕ γ`. This is useful for pattern-matching.
-/
namespace Sum3
/-- The map from the first summand into a ternary sum. -/
@[match_pattern, simp, reducible]
def in₀ (a : α) : α ⊕ (β ⊕ γ) :=
inl a
/-- The map from the second summand into a ternary sum. -/
@[match_pattern, simp, reducible]
def in₁ (b : β) : α ⊕ (β ⊕ γ) :=
inr <| inl b
/-- The map from the third summand into a ternary sum. -/
@[match_pattern, simp, reducible]
def in₂ (c : γ) : α ⊕ (β ⊕ γ) :=
inr <| inr c
end Sum3
|
Data\Sum\Interval.lean | /-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Finset.Sum
import Mathlib.Data.Sum.Order
import Mathlib.Order.Interval.Finset.Defs
/-!
# Finite intervals in a disjoint union
This file provides the `LocallyFiniteOrder` instance for the disjoint sum and linear sum of two
orders and calculates the cardinality of their finite intervals.
-/
open Function Sum
namespace Finset
variable {α₁ α₂ β₁ β₂ γ₁ γ₂ : Type*}
section SumLift₂
variable (f f₁ g₁ : α₁ → β₁ → Finset γ₁) (g f₂ g₂ : α₂ → β₂ → Finset γ₂)
/-- Lifts maps `α₁ → β₁ → Finset γ₁` and `α₂ → β₂ → Finset γ₂` to a map
`α₁ ⊕ α₂ → β₁ ⊕ β₂ → Finset (γ₁ ⊕ γ₂)`. Could be generalized to `Alternative` functors if we can
make sure to keep computability and universe polymorphism. -/
@[simp]
def sumLift₂ : ∀ (_ : α₁ ⊕ α₂) (_ : β₁ ⊕ β₂), Finset (γ₁ ⊕ γ₂)
| inl a, inl b => (f a b).map Embedding.inl
| inl _, inr _ => ∅
| inr _, inl _ => ∅
| inr a, inr b => (g a b).map Embedding.inr
variable {f f₁ g₁ g f₂ g₂} {a : α₁ ⊕ α₂} {b : β₁ ⊕ β₂} {c : γ₁ ⊕ γ₂}
theorem mem_sumLift₂ :
c ∈ sumLift₂ f g a b ↔
(∃ a₁ b₁ c₁, a = inl a₁ ∧ b = inl b₁ ∧ c = inl c₁ ∧ c₁ ∈ f a₁ b₁) ∨
∃ a₂ b₂ c₂, a = inr a₂ ∧ b = inr b₂ ∧ c = inr c₂ ∧ c₂ ∈ g a₂ b₂ := by
constructor
· cases' a with a a <;> cases' b with b b
· rw [sumLift₂, mem_map]
rintro ⟨c, hc, rfl⟩
exact Or.inl ⟨a, b, c, rfl, rfl, rfl, hc⟩
· refine fun h ↦ (not_mem_empty _ h).elim
· refine fun h ↦ (not_mem_empty _ h).elim
· rw [sumLift₂, mem_map]
rintro ⟨c, hc, rfl⟩
exact Or.inr ⟨a, b, c, rfl, rfl, rfl, hc⟩
· rintro (⟨a, b, c, rfl, rfl, rfl, h⟩ | ⟨a, b, c, rfl, rfl, rfl, h⟩) <;> exact mem_map_of_mem _ h
theorem inl_mem_sumLift₂ {c₁ : γ₁} :
inl c₁ ∈ sumLift₂ f g a b ↔ ∃ a₁ b₁, a = inl a₁ ∧ b = inl b₁ ∧ c₁ ∈ f a₁ b₁ := by
rw [mem_sumLift₂, or_iff_left]
· simp only [inl.injEq, exists_and_left, exists_eq_left']
rintro ⟨_, _, c₂, _, _, h, _⟩
exact inl_ne_inr h
theorem inr_mem_sumLift₂ {c₂ : γ₂} :
inr c₂ ∈ sumLift₂ f g a b ↔ ∃ a₂ b₂, a = inr a₂ ∧ b = inr b₂ ∧ c₂ ∈ g a₂ b₂ := by
rw [mem_sumLift₂, or_iff_right]
· simp only [inr.injEq, exists_and_left, exists_eq_left']
rintro ⟨_, _, c₂, _, _, h, _⟩
exact inr_ne_inl h
theorem sumLift₂_eq_empty :
sumLift₂ f g a b = ∅ ↔
(∀ a₁ b₁, a = inl a₁ → b = inl b₁ → f a₁ b₁ = ∅) ∧
∀ a₂ b₂, a = inr a₂ → b = inr b₂ → g a₂ b₂ = ∅ := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· constructor <;>
· rintro a b rfl rfl
exact map_eq_empty.1 h
cases a <;> cases b
· exact map_eq_empty.2 (h.1 _ _ rfl rfl)
· rfl
· rfl
· exact map_eq_empty.2 (h.2 _ _ rfl rfl)
theorem sumLift₂_nonempty :
(sumLift₂ f g a b).Nonempty ↔
(∃ a₁ b₁, a = inl a₁ ∧ b = inl b₁ ∧ (f a₁ b₁).Nonempty) ∨
∃ a₂ b₂, a = inr a₂ ∧ b = inr b₂ ∧ (g a₂ b₂).Nonempty := by
simp only [nonempty_iff_ne_empty, Ne, sumLift₂_eq_empty, not_and_or, not_forall, exists_prop]
theorem sumLift₂_mono (h₁ : ∀ a b, f₁ a b ⊆ g₁ a b) (h₂ : ∀ a b, f₂ a b ⊆ g₂ a b) :
∀ a b, sumLift₂ f₁ f₂ a b ⊆ sumLift₂ g₁ g₂ a b
| inl _, inl _ => map_subset_map.2 (h₁ _ _)
| inl _, inr _ => Subset.rfl
| inr _, inl _ => Subset.rfl
| inr _, inr _ => map_subset_map.2 (h₂ _ _)
end SumLift₂
section SumLexLift
variable (f₁ f₁' : α₁ → β₁ → Finset γ₁) (f₂ f₂' : α₂ → β₂ → Finset γ₂)
(g₁ g₁' : α₁ → β₂ → Finset γ₁) (g₂ g₂' : α₁ → β₂ → Finset γ₂)
/-- Lifts maps `α₁ → β₁ → Finset γ₁`, `α₂ → β₂ → Finset γ₂`, `α₁ → β₂ → Finset γ₁`,
`α₂ → β₂ → Finset γ₂` to a map `α₁ ⊕ α₂ → β₁ ⊕ β₂ → Finset (γ₁ ⊕ γ₂)`. Could be generalized to
alternative monads if we can make sure to keep computability and universe polymorphism. -/
def sumLexLift : α₁ ⊕ α₂ → β₁ ⊕ β₂ → Finset (γ₁ ⊕ γ₂)
| inl a, inl b => (f₁ a b).map Embedding.inl
| inl a, inr b => (g₁ a b).disjSum (g₂ a b)
| inr _, inl _ => ∅
| inr a, inr b => (f₂ a b).map ⟨_, inr_injective⟩
@[simp]
lemma sumLexLift_inl_inl (a : α₁) (b : β₁) :
sumLexLift f₁ f₂ g₁ g₂ (inl a) (inl b) = (f₁ a b).map Embedding.inl := rfl
@[simp]
lemma sumLexLift_inl_inr (a : α₁) (b : β₂) :
sumLexLift f₁ f₂ g₁ g₂ (inl a) (inr b) = (g₁ a b).disjSum (g₂ a b) := rfl
@[simp]
lemma sumLexLift_inr_inl (a : α₂) (b : β₁) : sumLexLift f₁ f₂ g₁ g₂ (inr a) (inl b) = ∅ := rfl
@[simp]
lemma sumLexLift_inr_inr (a : α₂) (b : β₂) :
sumLexLift f₁ f₂ g₁ g₂ (inr a) (inr b) = (f₂ a b).map ⟨_, inr_injective⟩ := rfl
variable {f₁ g₁ f₂ g₂ f₁' g₁' f₂' g₂'} {a : α₁ ⊕ α₂} {b : β₁ ⊕ β₂} {c : γ₁ ⊕ γ₂}
lemma mem_sumLexLift :
c ∈ sumLexLift f₁ f₂ g₁ g₂ a b ↔
(∃ a₁ b₁ c₁, a = inl a₁ ∧ b = inl b₁ ∧ c = inl c₁ ∧ c₁ ∈ f₁ a₁ b₁) ∨
(∃ a₁ b₂ c₁, a = inl a₁ ∧ b = inr b₂ ∧ c = inl c₁ ∧ c₁ ∈ g₁ a₁ b₂) ∨
(∃ a₁ b₂ c₂, a = inl a₁ ∧ b = inr b₂ ∧ c = inr c₂ ∧ c₂ ∈ g₂ a₁ b₂) ∨
∃ a₂ b₂ c₂, a = inr a₂ ∧ b = inr b₂ ∧ c = inr c₂ ∧ c₂ ∈ f₂ a₂ b₂ := by
constructor
· obtain a | a := a <;> obtain b | b := b
· rw [sumLexLift, mem_map]
rintro ⟨c, hc, rfl⟩
exact Or.inl ⟨a, b, c, rfl, rfl, rfl, hc⟩
· refine fun h ↦ (mem_disjSum.1 h).elim ?_ ?_
· rintro ⟨c, hc, rfl⟩
exact Or.inr (Or.inl ⟨a, b, c, rfl, rfl, rfl, hc⟩)
· rintro ⟨c, hc, rfl⟩
exact Or.inr (Or.inr <| Or.inl ⟨a, b, c, rfl, rfl, rfl, hc⟩)
· exact fun h ↦ (not_mem_empty _ h).elim
· rw [sumLexLift, mem_map]
rintro ⟨c, hc, rfl⟩
exact Or.inr (Or.inr <| Or.inr <| ⟨a, b, c, rfl, rfl, rfl, hc⟩)
· rintro (⟨a, b, c, rfl, rfl, rfl, hc⟩ | ⟨a, b, c, rfl, rfl, rfl, hc⟩ |
⟨a, b, c, rfl, rfl, rfl, hc⟩ | ⟨a, b, c, rfl, rfl, rfl, hc⟩)
· exact mem_map_of_mem _ hc
· exact inl_mem_disjSum.2 hc
· exact inr_mem_disjSum.2 hc
· exact mem_map_of_mem _ hc
lemma inl_mem_sumLexLift {c₁ : γ₁} :
inl c₁ ∈ sumLexLift f₁ f₂ g₁ g₂ a b ↔
(∃ a₁ b₁, a = inl a₁ ∧ b = inl b₁ ∧ c₁ ∈ f₁ a₁ b₁) ∨
∃ a₁ b₂, a = inl a₁ ∧ b = inr b₂ ∧ c₁ ∈ g₁ a₁ b₂ := by
simp [mem_sumLexLift]
lemma inr_mem_sumLexLift {c₂ : γ₂} :
inr c₂ ∈ sumLexLift f₁ f₂ g₁ g₂ a b ↔
(∃ a₁ b₂, a = inl a₁ ∧ b = inr b₂ ∧ c₂ ∈ g₂ a₁ b₂) ∨
∃ a₂ b₂, a = inr a₂ ∧ b = inr b₂ ∧ c₂ ∈ f₂ a₂ b₂ := by
simp [mem_sumLexLift]
lemma sumLexLift_mono (hf₁ : ∀ a b, f₁ a b ⊆ f₁' a b) (hf₂ : ∀ a b, f₂ a b ⊆ f₂' a b)
(hg₁ : ∀ a b, g₁ a b ⊆ g₁' a b) (hg₂ : ∀ a b, g₂ a b ⊆ g₂' a b) (a : α₁ ⊕ α₂)
(b : β₁ ⊕ β₂) : sumLexLift f₁ f₂ g₁ g₂ a b ⊆ sumLexLift f₁' f₂' g₁' g₂' a b := by
cases a <;> cases b
exacts [map_subset_map.2 (hf₁ _ _), disjSum_mono (hg₁ _ _) (hg₂ _ _), Subset.rfl,
map_subset_map.2 (hf₂ _ _)]
lemma sumLexLift_eq_empty :
sumLexLift f₁ f₂ g₁ g₂ a b = ∅ ↔
(∀ a₁ b₁, a = inl a₁ → b = inl b₁ → f₁ a₁ b₁ = ∅) ∧
(∀ a₁ b₂, a = inl a₁ → b = inr b₂ → g₁ a₁ b₂ = ∅ ∧ g₂ a₁ b₂ = ∅) ∧
∀ a₂ b₂, a = inr a₂ → b = inr b₂ → f₂ a₂ b₂ = ∅ := by
refine ⟨fun h ↦ ⟨?_, ?_, ?_⟩, fun h ↦ ?_⟩
any_goals rintro a b rfl rfl; exact map_eq_empty.1 h
· rintro a b rfl rfl; exact disjSum_eq_empty.1 h
cases a <;> cases b
· exact map_eq_empty.2 (h.1 _ _ rfl rfl)
· simp [h.2.1 _ _ rfl rfl]
· rfl
· exact map_eq_empty.2 (h.2.2 _ _ rfl rfl)
lemma sumLexLift_nonempty :
(sumLexLift f₁ f₂ g₁ g₂ a b).Nonempty ↔
(∃ a₁ b₁, a = inl a₁ ∧ b = inl b₁ ∧ (f₁ a₁ b₁).Nonempty) ∨
(∃ a₁ b₂, a = inl a₁ ∧ b = inr b₂ ∧ ((g₁ a₁ b₂).Nonempty ∨ (g₂ a₁ b₂).Nonempty)) ∨
∃ a₂ b₂, a = inr a₂ ∧ b = inr b₂ ∧ (f₂ a₂ b₂).Nonempty := by
-- porting note (#10745): was `simp [nonempty_iff_ne_empty, sumLexLift_eq_empty, not_and_or]`.
-- Could add `-exists_and_left, -not_and, -exists_and_right` but easier to squeeze.
simp only [nonempty_iff_ne_empty, Ne, sumLexLift_eq_empty, not_and_or, exists_prop,
not_forall]
end SumLexLift
end Finset
open Finset Function
namespace Sum
variable {α β : Type*}
/-! ### Disjoint sum of orders -/
section Disjoint
variable [Preorder α] [Preorder β] [LocallyFiniteOrder α] [LocallyFiniteOrder β]
instance instLocallyFiniteOrder : LocallyFiniteOrder (α ⊕ β) where
finsetIcc := sumLift₂ Icc Icc
finsetIco := sumLift₂ Ico Ico
finsetIoc := sumLift₂ Ioc Ioc
finsetIoo := sumLift₂ Ioo Ioo
finset_mem_Icc := by rintro (a | a) (b | b) (x | x) <;> simp
finset_mem_Ico := by rintro (a | a) (b | b) (x | x) <;> simp
finset_mem_Ioc := by rintro (a | a) (b | b) (x | x) <;> simp
finset_mem_Ioo := by rintro (a | a) (b | b) (x | x) <;> simp
variable (a₁ a₂ : α) (b₁ b₂ : β) (a b : α ⊕ β)
theorem Icc_inl_inl : Icc (inl a₁ : α ⊕ β) (inl a₂) = (Icc a₁ a₂).map Embedding.inl :=
rfl
theorem Ico_inl_inl : Ico (inl a₁ : α ⊕ β) (inl a₂) = (Ico a₁ a₂).map Embedding.inl :=
rfl
theorem Ioc_inl_inl : Ioc (inl a₁ : α ⊕ β) (inl a₂) = (Ioc a₁ a₂).map Embedding.inl :=
rfl
theorem Ioo_inl_inl : Ioo (inl a₁ : α ⊕ β) (inl a₂) = (Ioo a₁ a₂).map Embedding.inl :=
rfl
@[simp]
theorem Icc_inl_inr : Icc (inl a₁) (inr b₂) = ∅ :=
rfl
@[simp]
theorem Ico_inl_inr : Ico (inl a₁) (inr b₂) = ∅ :=
rfl
@[simp]
theorem Ioc_inl_inr : Ioc (inl a₁) (inr b₂) = ∅ :=
rfl
@[simp]
theorem Ioo_inl_inr : Ioo (inl a₁) (inr b₂) = ∅ := by
rfl
@[simp]
theorem Icc_inr_inl : Icc (inr b₁) (inl a₂) = ∅ :=
rfl
@[simp]
theorem Ico_inr_inl : Ico (inr b₁) (inl a₂) = ∅ :=
rfl
@[simp]
theorem Ioc_inr_inl : Ioc (inr b₁) (inl a₂) = ∅ :=
rfl
@[simp]
theorem Ioo_inr_inl : Ioo (inr b₁) (inl a₂) = ∅ := by
rfl
theorem Icc_inr_inr : Icc (inr b₁ : α ⊕ β) (inr b₂) = (Icc b₁ b₂).map Embedding.inr :=
rfl
theorem Ico_inr_inr : Ico (inr b₁ : α ⊕ β) (inr b₂) = (Ico b₁ b₂).map Embedding.inr :=
rfl
theorem Ioc_inr_inr : Ioc (inr b₁ : α ⊕ β) (inr b₂) = (Ioc b₁ b₂).map Embedding.inr :=
rfl
theorem Ioo_inr_inr : Ioo (inr b₁ : α ⊕ β) (inr b₂) = (Ioo b₁ b₂).map Embedding.inr :=
rfl
end Disjoint
/-! ### Lexicographical sum of orders -/
namespace Lex
variable [Preorder α] [Preorder β] [OrderTop α] [OrderBot β] [LocallyFiniteOrder α]
[LocallyFiniteOrder β]
/-- Throwaway tactic. -/
local elab "simp_lex" : tactic => do
Lean.Elab.Tactic.evalTactic <| ← `(tactic|
refine toLex.surjective.forall₃.2 ?_;
rintro (a | a) (b | b) (c | c) <;> simp only
[sumLexLift_inl_inl, sumLexLift_inl_inr, sumLexLift_inr_inl, sumLexLift_inr_inr,
inl_le_inl_iff, inl_le_inr, not_inr_le_inl, inr_le_inr_iff, inl_lt_inl_iff, inl_lt_inr,
not_inr_lt_inl, inr_lt_inr_iff, mem_Icc, mem_Ico, mem_Ioc, mem_Ioo, mem_Ici, mem_Ioi,
mem_Iic, mem_Iio, Equiv.coe_toEmbedding, toLex_inj, exists_false, and_false, false_and,
map_empty, not_mem_empty, true_and, inl_mem_disjSum, inr_mem_disjSum, and_true, ofLex_toLex,
mem_map, Embedding.coeFn_mk, exists_prop, exists_eq_right, Embedding.inl_apply,
-- Porting note: added
inl.injEq, inr.injEq]
)
instance locallyFiniteOrder : LocallyFiniteOrder (α ⊕ₗ β) where
finsetIcc a b :=
(sumLexLift Icc Icc (fun a _ => Ici a) (fun _ => Iic) (ofLex a) (ofLex b)).map toLex.toEmbedding
finsetIco a b :=
(sumLexLift Ico Ico (fun a _ => Ici a) (fun _ => Iio) (ofLex a) (ofLex b)).map toLex.toEmbedding
finsetIoc a b :=
(sumLexLift Ioc Ioc (fun a _ => Ioi a) (fun _ => Iic) (ofLex a) (ofLex b)).map toLex.toEmbedding
finsetIoo a b :=
(sumLexLift Ioo Ioo (fun a _ => Ioi a) (fun _ => Iio) (ofLex a) (ofLex b)).map toLex.toEmbedding
finset_mem_Icc := by simp_lex
finset_mem_Ico := by simp_lex
finset_mem_Ioc := by simp_lex
finset_mem_Ioo := by simp_lex
variable (a a₁ a₂ : α) (b b₁ b₂ : β)
lemma Icc_inl_inl :
Icc (inlₗ a₁ : α ⊕ₗ β) (inlₗ a₂) = (Icc a₁ a₂).map (Embedding.inl.trans toLex.toEmbedding) := by
rw [← Finset.map_map]; rfl
lemma Ico_inl_inl :
Ico (inlₗ a₁ : α ⊕ₗ β) (inlₗ a₂) = (Ico a₁ a₂).map (Embedding.inl.trans toLex.toEmbedding) := by
rw [← Finset.map_map]; rfl
lemma Ioc_inl_inl :
Ioc (inlₗ a₁ : α ⊕ₗ β) (inlₗ a₂) = (Ioc a₁ a₂).map (Embedding.inl.trans toLex.toEmbedding) := by
rw [← Finset.map_map]; rfl
lemma Ioo_inl_inl :
Ioo (inlₗ a₁ : α ⊕ₗ β) (inlₗ a₂) = (Ioo a₁ a₂).map (Embedding.inl.trans toLex.toEmbedding) := by
rw [← Finset.map_map]; rfl
@[simp]
lemma Icc_inl_inr : Icc (inlₗ a) (inrₗ b) = ((Ici a).disjSum (Iic b)).map toLex.toEmbedding := rfl
@[simp]
lemma Ico_inl_inr : Ico (inlₗ a) (inrₗ b) = ((Ici a).disjSum (Iio b)).map toLex.toEmbedding := rfl
@[simp]
lemma Ioc_inl_inr : Ioc (inlₗ a) (inrₗ b) = ((Ioi a).disjSum (Iic b)).map toLex.toEmbedding := rfl
@[simp]
lemma Ioo_inl_inr : Ioo (inlₗ a) (inrₗ b) = ((Ioi a).disjSum (Iio b)).map toLex.toEmbedding := rfl
@[simp]
lemma Icc_inr_inl : Icc (inrₗ b) (inlₗ a) = ∅ := rfl
@[simp]
lemma Ico_inr_inl : Ico (inrₗ b) (inlₗ a) = ∅ := rfl
@[simp]
lemma Ioc_inr_inl : Ioc (inrₗ b) (inlₗ a) = ∅ := rfl
@[simp]
lemma Ioo_inr_inl : Ioo (inrₗ b) (inlₗ a) = ∅ := rfl
lemma Icc_inr_inr :
Icc (inrₗ b₁ : α ⊕ₗ β) (inrₗ b₂) = (Icc b₁ b₂).map (Embedding.inr.trans toLex.toEmbedding) := by
rw [← Finset.map_map]; rfl
lemma Ico_inr_inr :
Ico (inrₗ b₁ : α ⊕ₗ β) (inrₗ b₂) = (Ico b₁ b₂).map (Embedding.inr.trans toLex.toEmbedding) := by
rw [← Finset.map_map]; rfl
lemma Ioc_inr_inr :
Ioc (inrₗ b₁ : α ⊕ₗ β) (inrₗ b₂) = (Ioc b₁ b₂).map (Embedding.inr.trans toLex.toEmbedding) := by
rw [← Finset.map_map]; rfl
lemma Ioo_inr_inr :
Ioo (inrₗ b₁ : α ⊕ₗ β) (inrₗ b₂) = (Ioo b₁ b₂).map (Embedding.inr.trans toLex.toEmbedding) := by
rw [← Finset.map_map]; rfl
end Lex
end Sum
|
Data\Sum\Lattice.lean | /-
Copyright (c) 2023 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Data.Sum.Order
import Mathlib.Order.Hom.Lattice
/-!
# Lexicographic sum of lattices
This file proves that we can combine two lattices `α` and `β` into a lattice `α ⊕ₗ β` where
everything in `α` is declared smaller than everything in `β`.
-/
open OrderDual
namespace Sum.Lex
variable {α β : Type*}
section SemilatticeSup
variable [SemilatticeSup α] [SemilatticeSup β]
-- The linter significantly hinders readability here.
set_option linter.unusedVariables false in
instance instSemilatticeSup : SemilatticeSup (α ⊕ₗ β) where
sup x y := match x, y with
| inlₗ a₁, inlₗ a₂ => inl (a₁ ⊔ a₂)
| inlₗ a₁, inrₗ b₂ => inr b₂
| inrₗ b₁, inlₗ a₂ => inr b₁
| inrₗ b₁, inrₗ b₂ => inr (b₁ ⊔ b₂)
le_sup_left x y := match x, y with
| inlₗ a₁, inlₗ a₂ => inl_le_inl_iff.2 le_sup_left
| inlₗ a₁, inrₗ b₂ => inl_le_inr _ _
| inrₗ b₁, inlₗ a₂ => le_rfl
| inrₗ b₁, inrₗ b₂ => inr_le_inr_iff.2 le_sup_left
le_sup_right x y := match x, y with
| inlₗ a₁, inlₗ a₂ => inl_le_inl_iff.2 le_sup_right
| inlₗ a₁, inrₗ b₂ => le_rfl
| inrₗ b₁, inlₗ a₂ => inl_le_inr _ _
| inrₗ b₁, inrₗ b₂ => inr_le_inr_iff.2 le_sup_right
sup_le x y z hxz hyz := match x, y, z, hxz, hyz with
| inlₗ a₁, inlₗ a₂, inlₗ a₃, Lex.inl h₁₃, Lex.inl h₂₃ => inl_le_inl_iff.2 <| sup_le h₁₃ h₂₃
| inlₗ a₁, inlₗ a₂, inrₗ b₃, Lex.sep _ _, Lex.sep _ _ => Lex.sep _ _
| inlₗ a₁, inrₗ b₂, inrₗ b₃, Lex.sep _ _, Lex.inr h₂₃ => inr_le_inr_iff.2 h₂₃
| inrₗ b₁, inlₗ a₂, inrₗ b₃, Lex.inr h₁₃, Lex.sep _ _ => inr_le_inr_iff.2 h₁₃
| inrₗ b₁, inrₗ b₂, inrₗ b₃, Lex.inr h₁₃, Lex.inr h₂₃ => inr_le_inr_iff.2 <| sup_le h₁₃ h₂₃
@[simp] lemma inl_sup (a₁ a₂ : α) : (inlₗ (a₁ ⊔ a₂) : α ⊕ β) = inlₗ a₁ ⊔ inlₗ a₂ := rfl
@[simp] lemma inr_sup (b₁ b₂ : β) : (inrₗ (b₁ ⊔ b₂) : α ⊕ β) = inrₗ b₁ ⊔ inrₗ b₂ := rfl
end SemilatticeSup
section SemilatticeInf
variable [SemilatticeInf α] [SemilatticeInf β]
-- The linter significantly hinders readability here.
set_option linter.unusedVariables false in
instance instSemilatticeInf : SemilatticeInf (α ⊕ₗ β) where
inf x y := match x, y with
| inlₗ a₁, inlₗ a₂ => inl (a₁ ⊓ a₂)
| inlₗ a₁, inrₗ b₂ => inl a₁
| inrₗ b₁, inlₗ a₂ => inl a₂
| inrₗ b₁, inrₗ b₂ => inr (b₁ ⊓ b₂)
inf_le_left x y := match x, y with
| inlₗ a₁, inlₗ a₂ => inl_le_inl_iff.2 inf_le_left
| inlₗ a₁, inrₗ b₂ => le_rfl
| inrₗ b₁, inlₗ a₂ => inl_le_inr _ _
| inrₗ b₁, inrₗ b₂ => inr_le_inr_iff.2 inf_le_left
inf_le_right x y := match x, y with
| inlₗ a₁, inlₗ a₂ => inl_le_inl_iff.2 inf_le_right
| inlₗ a₁, inrₗ b₂ => inl_le_inr _ _
| inrₗ b₁, inlₗ a₂ => le_rfl
| inrₗ b₁, inrₗ b₂ => inr_le_inr_iff.2 inf_le_right
le_inf x y z hzx hzy := match x, y, z, hzx, hzy with
| inlₗ a₁, inlₗ a₂, inlₗ a₃, Lex.inl h₁₃, Lex.inl h₂₃ => inl_le_inl_iff.2 <| le_inf h₁₃ h₂₃
| inlₗ a₁, inlₗ a₂, inrₗ b₃, Lex.inl h₁₃, Lex.sep _ _ => inl_le_inl_iff.2 h₁₃
| inlₗ a₁, inrₗ b₂, inlₗ a₃, Lex.sep _ _, Lex.inl h₂₃ => inl_le_inl_iff.2 h₂₃
| inlₗ a₁, inrₗ b₂, inrₗ b₃, Lex.sep _ _, Lex.sep _ _ => Lex.sep _ _
| inrₗ b₁, inrₗ b₂, inrₗ b₃, Lex.inr h₁₃, Lex.inr h₂₃ => inr_le_inr_iff.2 <| le_inf h₁₃ h₂₃
@[simp] lemma inl_inf (a₁ a₂ : α) : (inlₗ (a₁ ⊓ a₂) : α ⊕ β) = inlₗ a₁ ⊓ inlₗ a₂ := rfl
@[simp] lemma inr_inf (b₁ b₂ : β) : (inrₗ (b₁ ⊓ b₂) : α ⊕ β) = inrₗ b₁ ⊓ inrₗ b₂ := rfl
end SemilatticeInf
section Lattice
variable [Lattice α] [Lattice β]
instance instLattice : Lattice (α ⊕ₗ β) := { instSemilatticeSup, instSemilatticeInf with }
/-- `Sum.Lex.inlₗ` as a lattice homomorphism. -/
def inlLatticeHom : LatticeHom α (α ⊕ₗ β) where
toFun := inlₗ
map_sup' _ _ := rfl
map_inf' _ _ := rfl
/-- `Sum.Lex.inrₗ` as a lattice homomorphism. -/
def inrLatticeHom : LatticeHom β (α ⊕ₗ β) where
toFun := inrₗ
map_sup' _ _ := rfl
map_inf' _ _ := rfl
end Lattice
instance instDistribLattice [DistribLattice α] [DistribLattice β] : DistribLattice (α ⊕ₗ β) where
le_sup_inf := by
simp only [Lex.forall, Sum.forall, inl_le_inl_iff, inr_le_inr_iff, sup_le_iff,
le_sup_left, true_and, inl_le_inr, not_inr_le_inl, le_inf_iff, sup_of_le_right, and_self,
inf_of_le_left, le_refl, implies_true, and_true, inf_of_le_right, sup_of_le_left, ← inl_sup,
← inr_sup, ← inl_inf, ← inr_inf, sup_inf_left, le_rfl]
end Sum.Lex
|
Data\Sum\Order.lean | /-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Order.Hom.Basic
/-!
# Orders on a sum type
This file defines the disjoint sum and the linear (aka lexicographic) sum of two orders and
provides relation instances for `Sum.LiftRel` and `Sum.Lex`.
We declare the disjoint sum of orders as the default set of instances. The linear order goes on a
type synonym.
## Main declarations
* `Sum.LE`, `Sum.LT`: Disjoint sum of orders.
* `Sum.Lex.LE`, `Sum.Lex.LT`: Lexicographic/linear sum of orders.
## Notation
* `α ⊕ₗ β`: The linear sum of `α` and `β`.
-/
variable {α β γ δ : Type*}
namespace Sum
/-! ### Unbundled relation classes -/
section LiftRel
variable (r : α → α → Prop) (s : β → β → Prop)
@[refl]
theorem LiftRel.refl [IsRefl α r] [IsRefl β s] : ∀ x, LiftRel r s x x
| inl a => LiftRel.inl (_root_.refl a)
| inr a => LiftRel.inr (_root_.refl a)
instance [IsRefl α r] [IsRefl β s] : IsRefl (α ⊕ β) (LiftRel r s) :=
⟨LiftRel.refl _ _⟩
instance [IsIrrefl α r] [IsIrrefl β s] : IsIrrefl (α ⊕ β) (LiftRel r s) :=
⟨by rintro _ (⟨h⟩ | ⟨h⟩) <;> exact irrefl _ h⟩
@[trans]
theorem LiftRel.trans [IsTrans α r] [IsTrans β s] :
∀ {a b c}, LiftRel r s a b → LiftRel r s b c → LiftRel r s a c
| _, _, _, LiftRel.inl hab, LiftRel.inl hbc => LiftRel.inl <| _root_.trans hab hbc
| _, _, _, LiftRel.inr hab, LiftRel.inr hbc => LiftRel.inr <| _root_.trans hab hbc
instance [IsTrans α r] [IsTrans β s] : IsTrans (α ⊕ β) (LiftRel r s) :=
⟨fun _ _ _ => LiftRel.trans _ _⟩
instance [IsAntisymm α r] [IsAntisymm β s] : IsAntisymm (α ⊕ β) (LiftRel r s) :=
⟨by rintro _ _ (⟨hab⟩ | ⟨hab⟩) (⟨hba⟩ | ⟨hba⟩) <;> rw [antisymm hab hba]⟩
end LiftRel
section Lex
variable (r : α → α → Prop) (s : β → β → Prop)
instance [IsRefl α r] [IsRefl β s] : IsRefl (α ⊕ β) (Lex r s) :=
⟨by
rintro (a | a)
exacts [Lex.inl (refl _), Lex.inr (refl _)]⟩
instance [IsIrrefl α r] [IsIrrefl β s] : IsIrrefl (α ⊕ β) (Lex r s) :=
⟨by rintro _ (⟨h⟩ | ⟨h⟩) <;> exact irrefl _ h⟩
instance [IsTrans α r] [IsTrans β s] : IsTrans (α ⊕ β) (Lex r s) :=
⟨by
rintro _ _ _ (⟨hab⟩ | ⟨hab⟩) (⟨hbc⟩ | ⟨hbc⟩)
exacts [.inl (_root_.trans hab hbc), .sep _ _, .inr (_root_.trans hab hbc), .sep _ _]⟩
instance [IsAntisymm α r] [IsAntisymm β s] : IsAntisymm (α ⊕ β) (Lex r s) :=
⟨by rintro _ _ (⟨hab⟩ | ⟨hab⟩) (⟨hba⟩ | ⟨hba⟩) <;> rw [antisymm hab hba]⟩
instance [IsTotal α r] [IsTotal β s] : IsTotal (α ⊕ β) (Lex r s) :=
⟨fun a b =>
match a, b with
| inl a, inl b => (total_of r a b).imp Lex.inl Lex.inl
| inl _, inr _ => Or.inl (Lex.sep _ _)
| inr _, inl _ => Or.inr (Lex.sep _ _)
| inr a, inr b => (total_of s a b).imp Lex.inr Lex.inr⟩
instance [IsTrichotomous α r] [IsTrichotomous β s] : IsTrichotomous (α ⊕ β) (Lex r s) :=
⟨fun a b =>
match a, b with
| inl a, inl b => (trichotomous_of r a b).imp3 Lex.inl (congr_arg _) Lex.inl
| inl _, inr _ => Or.inl (Lex.sep _ _)
| inr _, inl _ => Or.inr (Or.inr <| Lex.sep _ _)
| inr a, inr b => (trichotomous_of s a b).imp3 Lex.inr (congr_arg _) Lex.inr⟩
instance [IsWellOrder α r] [IsWellOrder β s] :
IsWellOrder (α ⊕ β) (Sum.Lex r s) where wf := Sum.lex_wf IsWellFounded.wf IsWellFounded.wf
end Lex
/-! ### Disjoint sum of two orders -/
section Disjoint
instance instLESum [LE α] [LE β] : LE (α ⊕ β) :=
⟨LiftRel (· ≤ ·) (· ≤ ·)⟩
instance instLTSum [LT α] [LT β] : LT (α ⊕ β) :=
⟨LiftRel (· < ·) (· < ·)⟩
theorem le_def [LE α] [LE β] {a b : α ⊕ β} : a ≤ b ↔ LiftRel (· ≤ ·) (· ≤ ·) a b :=
Iff.rfl
theorem lt_def [LT α] [LT β] {a b : α ⊕ β} : a < b ↔ LiftRel (· < ·) (· < ·) a b :=
Iff.rfl
@[simp]
theorem inl_le_inl_iff [LE α] [LE β] {a b : α} : (inl a : α ⊕ β) ≤ inl b ↔ a ≤ b :=
liftRel_inl_inl
@[simp]
theorem inr_le_inr_iff [LE α] [LE β] {a b : β} : (inr a : α ⊕ β) ≤ inr b ↔ a ≤ b :=
liftRel_inr_inr
@[simp]
theorem inl_lt_inl_iff [LT α] [LT β] {a b : α} : (inl a : α ⊕ β) < inl b ↔ a < b :=
liftRel_inl_inl
@[simp]
theorem inr_lt_inr_iff [LT α] [LT β] {a b : β} : (inr a : α ⊕ β) < inr b ↔ a < b :=
liftRel_inr_inr
@[simp]
theorem not_inl_le_inr [LE α] [LE β] {a : α} {b : β} : ¬inl b ≤ inr a :=
not_liftRel_inl_inr
@[simp]
theorem not_inl_lt_inr [LT α] [LT β] {a : α} {b : β} : ¬inl b < inr a :=
not_liftRel_inl_inr
@[simp]
theorem not_inr_le_inl [LE α] [LE β] {a : α} {b : β} : ¬inr b ≤ inl a :=
not_liftRel_inr_inl
@[simp]
theorem not_inr_lt_inl [LT α] [LT β] {a : α} {b : β} : ¬inr b < inl a :=
not_liftRel_inr_inl
section Preorder
variable [Preorder α] [Preorder β]
instance instPreorderSum : Preorder (α ⊕ β) :=
{ instLESum, instLTSum with
le_refl := fun x => LiftRel.refl _ _ _,
le_trans := fun _ _ _ => LiftRel.trans _ _,
lt_iff_le_not_le := fun a b => by
refine ⟨fun hab => ⟨hab.mono (fun _ _ => le_of_lt) fun _ _ => le_of_lt, ?_⟩, ?_⟩
· rintro (⟨hba⟩ | ⟨hba⟩)
· exact hba.not_lt (inl_lt_inl_iff.1 hab)
· exact hba.not_lt (inr_lt_inr_iff.1 hab)
· rintro ⟨⟨hab⟩ | ⟨hab⟩, hba⟩
· exact LiftRel.inl (hab.lt_of_not_le fun h => hba <| LiftRel.inl h)
· exact LiftRel.inr (hab.lt_of_not_le fun h => hba <| LiftRel.inr h) }
theorem inl_mono : Monotone (inl : α → α ⊕ β) := fun _ _ => LiftRel.inl
theorem inr_mono : Monotone (inr : β → α ⊕ β) := fun _ _ => LiftRel.inr
theorem inl_strictMono : StrictMono (inl : α → α ⊕ β) := fun _ _ => LiftRel.inl
theorem inr_strictMono : StrictMono (inr : β → α ⊕ β) := fun _ _ => LiftRel.inr
end Preorder
instance [PartialOrder α] [PartialOrder β] : PartialOrder (α ⊕ β) :=
{ instPreorderSum with
le_antisymm := fun _ _ => show LiftRel _ _ _ _ → _ from antisymm }
instance noMinOrder [LT α] [LT β] [NoMinOrder α] [NoMinOrder β] : NoMinOrder (α ⊕ β) :=
⟨fun a =>
match a with
| inl a =>
let ⟨b, h⟩ := exists_lt a
⟨inl b, inl_lt_inl_iff.2 h⟩
| inr a =>
let ⟨b, h⟩ := exists_lt a
⟨inr b, inr_lt_inr_iff.2 h⟩⟩
instance noMaxOrder [LT α] [LT β] [NoMaxOrder α] [NoMaxOrder β] : NoMaxOrder (α ⊕ β) :=
⟨fun a =>
match a with
| inl a =>
let ⟨b, h⟩ := exists_gt a
⟨inl b, inl_lt_inl_iff.2 h⟩
| inr a =>
let ⟨b, h⟩ := exists_gt a
⟨inr b, inr_lt_inr_iff.2 h⟩⟩
@[simp]
theorem noMinOrder_iff [LT α] [LT β] : NoMinOrder (α ⊕ β) ↔ NoMinOrder α ∧ NoMinOrder β :=
⟨fun _ =>
⟨⟨fun a => by
obtain ⟨b | b, h⟩ := exists_lt (inl a : α ⊕ β)
· exact ⟨b, inl_lt_inl_iff.1 h⟩
· exact (not_inr_lt_inl h).elim⟩,
⟨fun a => by
obtain ⟨b | b, h⟩ := exists_lt (inr a : α ⊕ β)
· exact (not_inl_lt_inr h).elim
· exact ⟨b, inr_lt_inr_iff.1 h⟩⟩⟩,
fun h => @Sum.noMinOrder _ _ _ _ h.1 h.2⟩
@[simp]
theorem noMaxOrder_iff [LT α] [LT β] : NoMaxOrder (α ⊕ β) ↔ NoMaxOrder α ∧ NoMaxOrder β :=
⟨fun _ =>
⟨⟨fun a => by
obtain ⟨b | b, h⟩ := exists_gt (inl a : α ⊕ β)
· exact ⟨b, inl_lt_inl_iff.1 h⟩
· exact (not_inl_lt_inr h).elim⟩,
⟨fun a => by
obtain ⟨b | b, h⟩ := exists_gt (inr a : α ⊕ β)
· exact (not_inr_lt_inl h).elim
· exact ⟨b, inr_lt_inr_iff.1 h⟩⟩⟩,
fun h => @Sum.noMaxOrder _ _ _ _ h.1 h.2⟩
instance denselyOrdered [LT α] [LT β] [DenselyOrdered α] [DenselyOrdered β] :
DenselyOrdered (α ⊕ β) :=
⟨fun a b h =>
match a, b, h with
| inl _, inl _, LiftRel.inl h =>
let ⟨c, ha, hb⟩ := exists_between h
⟨toLex (inl c), LiftRel.inl ha, LiftRel.inl hb⟩
| inr _, inr _, LiftRel.inr h =>
let ⟨c, ha, hb⟩ := exists_between h
⟨toLex (inr c), LiftRel.inr ha, LiftRel.inr hb⟩⟩
@[simp]
theorem denselyOrdered_iff [LT α] [LT β] :
DenselyOrdered (α ⊕ β) ↔ DenselyOrdered α ∧ DenselyOrdered β :=
⟨fun _ =>
⟨⟨fun a b h => by
obtain ⟨c | c, ha, hb⟩ := @exists_between (α ⊕ β) _ _ _ _ (inl_lt_inl_iff.2 h)
· exact ⟨c, inl_lt_inl_iff.1 ha, inl_lt_inl_iff.1 hb⟩
· exact (not_inl_lt_inr ha).elim⟩,
⟨fun a b h => by
obtain ⟨c | c, ha, hb⟩ := @exists_between (α ⊕ β) _ _ _ _ (inr_lt_inr_iff.2 h)
· exact (not_inl_lt_inr hb).elim
· exact ⟨c, inr_lt_inr_iff.1 ha, inr_lt_inr_iff.1 hb⟩⟩⟩,
fun h => @Sum.denselyOrdered _ _ _ _ h.1 h.2⟩
@[simp]
theorem swap_le_swap_iff [LE α] [LE β] {a b : α ⊕ β} : a.swap ≤ b.swap ↔ a ≤ b :=
liftRel_swap_iff
@[simp]
theorem swap_lt_swap_iff [LT α] [LT β] {a b : α ⊕ β} : a.swap < b.swap ↔ a < b :=
liftRel_swap_iff
end Disjoint
/-! ### Linear sum of two orders -/
namespace Lex
/-- The linear sum of two orders -/
notation:30 α " ⊕ₗ " β:29 => _root_.Lex (α ⊕ β)
--TODO: Can we make `inlₗ`, `inrₗ` `local notation`?
/-- Lexicographical `Sum.inl`. Only used for pattern matching. -/
@[match_pattern]
abbrev _root_.Sum.inlₗ (x : α) : α ⊕ₗ β :=
toLex (Sum.inl x)
/-- Lexicographical `Sum.inr`. Only used for pattern matching. -/
@[match_pattern]
abbrev _root_.Sum.inrₗ (x : β) : α ⊕ₗ β :=
toLex (Sum.inr x)
/-- The linear/lexicographical `≤` on a sum. -/
protected instance LE [LE α] [LE β] : LE (α ⊕ₗ β) :=
⟨Lex (· ≤ ·) (· ≤ ·)⟩
/-- The linear/lexicographical `<` on a sum. -/
protected instance LT [LT α] [LT β] : LT (α ⊕ₗ β) :=
⟨Lex (· < ·) (· < ·)⟩
@[simp]
theorem toLex_le_toLex [LE α] [LE β] {a b : α ⊕ β} :
toLex a ≤ toLex b ↔ Lex (· ≤ ·) (· ≤ ·) a b :=
Iff.rfl
@[simp]
theorem toLex_lt_toLex [LT α] [LT β] {a b : α ⊕ β} :
toLex a < toLex b ↔ Lex (· < ·) (· < ·) a b :=
Iff.rfl
theorem le_def [LE α] [LE β] {a b : α ⊕ₗ β} : a ≤ b ↔ Lex (· ≤ ·) (· ≤ ·) (ofLex a) (ofLex b) :=
Iff.rfl
theorem lt_def [LT α] [LT β] {a b : α ⊕ₗ β} : a < b ↔ Lex (· < ·) (· < ·) (ofLex a) (ofLex b) :=
Iff.rfl
theorem inl_le_inl_iff [LE α] [LE β] {a b : α} : toLex (inl a : α ⊕ β) ≤ toLex (inl b) ↔ a ≤ b :=
lex_inl_inl
theorem inr_le_inr_iff [LE α] [LE β] {a b : β} : toLex (inr a : α ⊕ β) ≤ toLex (inr b) ↔ a ≤ b :=
lex_inr_inr
theorem inl_lt_inl_iff [LT α] [LT β] {a b : α} : toLex (inl a : α ⊕ β) < toLex (inl b) ↔ a < b :=
lex_inl_inl
theorem inr_lt_inr_iff [LT α] [LT β] {a b : β} : toLex (inr a : α ⊕ₗ β) < toLex (inr b) ↔ a < b :=
lex_inr_inr
theorem inl_le_inr [LE α] [LE β] (a : α) (b : β) : toLex (inl a) ≤ toLex (inr b) :=
Lex.sep _ _
theorem inl_lt_inr [LT α] [LT β] (a : α) (b : β) : toLex (inl a) < toLex (inr b) :=
Lex.sep _ _
theorem not_inr_le_inl [LE α] [LE β] {a : α} {b : β} : ¬toLex (inr b) ≤ toLex (inl a) :=
lex_inr_inl
theorem not_inr_lt_inl [LT α] [LT β] {a : α} {b : β} : ¬toLex (inr b) < toLex (inl a) :=
lex_inr_inl
section Preorder
variable [Preorder α] [Preorder β]
instance preorder : Preorder (α ⊕ₗ β) :=
{ Lex.LE, Lex.LT with
le_refl := refl_of (Lex (· ≤ ·) (· ≤ ·)),
le_trans := fun _ _ _ => trans_of (Lex (· ≤ ·) (· ≤ ·)),
lt_iff_le_not_le := fun a b => by
refine ⟨fun hab => ⟨hab.mono (fun _ _ => le_of_lt) fun _ _ => le_of_lt, ?_⟩, ?_⟩
· rintro (⟨hba⟩ | ⟨hba⟩ | ⟨b, a⟩)
· exact hba.not_lt (inl_lt_inl_iff.1 hab)
· exact hba.not_lt (inr_lt_inr_iff.1 hab)
· exact not_inr_lt_inl hab
· rintro ⟨⟨hab⟩ | ⟨hab⟩ | ⟨a, b⟩, hba⟩
· exact Lex.inl (hab.lt_of_not_le fun h => hba <| Lex.inl h)
· exact Lex.inr (hab.lt_of_not_le fun h => hba <| Lex.inr h)
· exact Lex.sep _ _ }
theorem toLex_mono : Monotone (@toLex (α ⊕ β)) := fun _ _ h => h.lex
theorem toLex_strictMono : StrictMono (@toLex (α ⊕ β)) := fun _ _ h => h.lex
theorem inl_mono : Monotone (toLex ∘ inl : α → α ⊕ₗ β) :=
toLex_mono.comp Sum.inl_mono
theorem inr_mono : Monotone (toLex ∘ inr : β → α ⊕ₗ β) :=
toLex_mono.comp Sum.inr_mono
theorem inl_strictMono : StrictMono (toLex ∘ inl : α → α ⊕ₗ β) :=
toLex_strictMono.comp Sum.inl_strictMono
theorem inr_strictMono : StrictMono (toLex ∘ inr : β → α ⊕ₗ β) :=
toLex_strictMono.comp Sum.inr_strictMono
end Preorder
instance partialOrder [PartialOrder α] [PartialOrder β] : PartialOrder (α ⊕ₗ β) :=
{ Lex.preorder with le_antisymm := fun _ _ => antisymm_of (Lex (· ≤ ·) (· ≤ ·)) }
instance linearOrder [LinearOrder α] [LinearOrder β] : LinearOrder (α ⊕ₗ β) :=
{ Lex.partialOrder with
le_total := total_of (Lex (· ≤ ·) (· ≤ ·)),
decidableLE := instDecidableRelSumLex,
decidableEq := instDecidableEqSum }
/-- The lexicographical bottom of a sum is the bottom of the left component. -/
instance orderBot [LE α] [OrderBot α] [LE β] :
OrderBot (α ⊕ₗ β) where
bot := inl ⊥
bot_le := by
rintro (a | b)
· exact Lex.inl bot_le
· exact Lex.sep _ _
@[simp]
theorem inl_bot [LE α] [OrderBot α] [LE β] : toLex (inl ⊥ : α ⊕ β) = ⊥ :=
rfl
/-- The lexicographical top of a sum is the top of the right component. -/
instance orderTop [LE α] [LE β] [OrderTop β] :
OrderTop (α ⊕ₗ β) where
top := inr ⊤
le_top := by
rintro (a | b)
· exact Lex.sep _ _
· exact Lex.inr le_top
@[simp]
theorem inr_top [LE α] [LE β] [OrderTop β] : toLex (inr ⊤ : α ⊕ β) = ⊤ :=
rfl
instance boundedOrder [LE α] [LE β] [OrderBot α] [OrderTop β] : BoundedOrder (α ⊕ₗ β) :=
{ Lex.orderBot, Lex.orderTop with }
instance noMinOrder [LT α] [LT β] [NoMinOrder α] [NoMinOrder β] : NoMinOrder (α ⊕ₗ β) :=
⟨fun a =>
match a with
| inl a =>
let ⟨b, h⟩ := exists_lt a
⟨toLex (inl b), inl_lt_inl_iff.2 h⟩
| inr a =>
let ⟨b, h⟩ := exists_lt a
⟨toLex (inr b), inr_lt_inr_iff.2 h⟩⟩
instance noMaxOrder [LT α] [LT β] [NoMaxOrder α] [NoMaxOrder β] : NoMaxOrder (α ⊕ₗ β) :=
⟨fun a =>
match a with
| inl a =>
let ⟨b, h⟩ := exists_gt a
⟨toLex (inl b), inl_lt_inl_iff.2 h⟩
| inr a =>
let ⟨b, h⟩ := exists_gt a
⟨toLex (inr b), inr_lt_inr_iff.2 h⟩⟩
instance noMinOrder_of_nonempty [LT α] [LT β] [NoMinOrder α] [Nonempty α] : NoMinOrder (α ⊕ₗ β) :=
⟨fun a =>
match a with
| inl a =>
let ⟨b, h⟩ := exists_lt a
⟨toLex (inl b), inl_lt_inl_iff.2 h⟩
| inr _ => ⟨toLex (inl <| Classical.arbitrary α), inl_lt_inr _ _⟩⟩
instance noMaxOrder_of_nonempty [LT α] [LT β] [NoMaxOrder β] [Nonempty β] : NoMaxOrder (α ⊕ₗ β) :=
⟨fun a =>
match a with
| inl _ => ⟨toLex (inr <| Classical.arbitrary β), inl_lt_inr _ _⟩
| inr a =>
let ⟨b, h⟩ := exists_gt a
⟨toLex (inr b), inr_lt_inr_iff.2 h⟩⟩
instance denselyOrdered_of_noMaxOrder [LT α] [LT β] [DenselyOrdered α] [DenselyOrdered β]
[NoMaxOrder α] : DenselyOrdered (α ⊕ₗ β) :=
⟨fun a b h =>
match a, b, h with
| inl _, inl _, Lex.inl h =>
let ⟨c, ha, hb⟩ := exists_between h
⟨toLex (inl c), inl_lt_inl_iff.2 ha, inl_lt_inl_iff.2 hb⟩
| inl a, inr _, Lex.sep _ _ =>
let ⟨c, h⟩ := exists_gt a
⟨toLex (inl c), inl_lt_inl_iff.2 h, inl_lt_inr _ _⟩
| inr _, inr _, Lex.inr h =>
let ⟨c, ha, hb⟩ := exists_between h
⟨toLex (inr c), inr_lt_inr_iff.2 ha, inr_lt_inr_iff.2 hb⟩⟩
instance denselyOrdered_of_noMinOrder [LT α] [LT β] [DenselyOrdered α] [DenselyOrdered β]
[NoMinOrder β] : DenselyOrdered (α ⊕ₗ β) :=
⟨fun a b h =>
match a, b, h with
| inl _, inl _, Lex.inl h =>
let ⟨c, ha, hb⟩ := exists_between h
⟨toLex (inl c), inl_lt_inl_iff.2 ha, inl_lt_inl_iff.2 hb⟩
| inl _, inr b, Lex.sep _ _ =>
let ⟨c, h⟩ := exists_lt b
⟨toLex (inr c), inl_lt_inr _ _, inr_lt_inr_iff.2 h⟩
| inr _, inr _, Lex.inr h =>
let ⟨c, ha, hb⟩ := exists_between h
⟨toLex (inr c), inr_lt_inr_iff.2 ha, inr_lt_inr_iff.2 hb⟩⟩
end Lex
end Sum
/-! ### Order isomorphisms -/
open OrderDual Sum
namespace OrderIso
variable [LE α] [LE β] [LE γ] (a : α) (b : β) (c : γ)
/-- `Equiv.sumComm` promoted to an order isomorphism. -/
@[simps! apply]
def sumComm (α β : Type*) [LE α] [LE β] : α ⊕ β ≃o β ⊕ α :=
{ Equiv.sumComm α β with map_rel_iff' := swap_le_swap_iff }
@[simp]
theorem sumComm_symm (α β : Type*) [LE α] [LE β] :
(OrderIso.sumComm α β).symm = OrderIso.sumComm β α :=
rfl
/-- `Equiv.sumAssoc` promoted to an order isomorphism. -/
def sumAssoc (α β γ : Type*) [LE α] [LE β] [LE γ] : (α ⊕ β) ⊕ γ ≃o α ⊕ (β ⊕ γ) :=
{ Equiv.sumAssoc α β γ with
map_rel_iff' := fun {a b} => by
rcases a with ((_ | _) | _) <;> rcases b with ((_ | _) | _) <;>
simp [Equiv.sumAssoc] }
@[simp]
theorem sumAssoc_apply_inl_inl : sumAssoc α β γ (inl (inl a)) = inl a :=
rfl
@[simp]
theorem sumAssoc_apply_inl_inr : sumAssoc α β γ (inl (inr b)) = inr (inl b) :=
rfl
@[simp]
theorem sumAssoc_apply_inr : sumAssoc α β γ (inr c) = inr (inr c) :=
rfl
@[simp]
theorem sumAssoc_symm_apply_inl : (sumAssoc α β γ).symm (inl a) = inl (inl a) :=
rfl
@[simp]
theorem sumAssoc_symm_apply_inr_inl : (sumAssoc α β γ).symm (inr (inl b)) = inl (inr b) :=
rfl
@[simp]
theorem sumAssoc_symm_apply_inr_inr : (sumAssoc α β γ).symm (inr (inr c)) = inr c :=
rfl
/-- `orderDual` is distributive over `⊕` up to an order isomorphism. -/
def sumDualDistrib (α β : Type*) [LE α] [LE β] : (α ⊕ β)ᵒᵈ ≃o αᵒᵈ ⊕ βᵒᵈ :=
{ Equiv.refl _ with
map_rel_iff' := by
rintro (a | a) (b | b)
· change inl (toDual a) ≤ inl (toDual b) ↔ toDual (inl a) ≤ toDual (inl b)
simp [toDual_le_toDual, inl_le_inl_iff]
· exact iff_of_false (@not_inl_le_inr (OrderDual β) (OrderDual α) _ _ _ _) not_inr_le_inl
· exact iff_of_false (@not_inr_le_inl (OrderDual α) (OrderDual β) _ _ _ _) not_inl_le_inr
· change inr (toDual a) ≤ inr (toDual b) ↔ toDual (inr a) ≤ toDual (inr b)
simp [toDual_le_toDual, inr_le_inr_iff] }
@[simp]
theorem sumDualDistrib_inl : sumDualDistrib α β (toDual (inl a)) = inl (toDual a) :=
rfl
@[simp]
theorem sumDualDistrib_inr : sumDualDistrib α β (toDual (inr b)) = inr (toDual b) :=
rfl
@[simp]
theorem sumDualDistrib_symm_inl : (sumDualDistrib α β).symm (inl (toDual a)) = toDual (inl a) :=
rfl
@[simp]
theorem sumDualDistrib_symm_inr : (sumDualDistrib α β).symm (inr (toDual b)) = toDual (inr b) :=
rfl
/-- `Equiv.SumAssoc` promoted to an order isomorphism. -/
def sumLexAssoc (α β γ : Type*) [LE α] [LE β] [LE γ] : (α ⊕ₗ β) ⊕ₗ γ ≃o α ⊕ₗ β ⊕ₗ γ :=
{ Equiv.sumAssoc α β γ with
map_rel_iff' := fun {a b} =>
⟨fun h =>
match a, b, h with
| inlₗ (inlₗ _), inlₗ (inlₗ _), Lex.inl h => Lex.inl <| Lex.inl h
| inlₗ (inlₗ _), inlₗ (inrₗ _), Lex.sep _ _ => Lex.inl <| Lex.sep _ _
| inlₗ (inlₗ _), inrₗ _, Lex.sep _ _ => Lex.sep _ _
| inlₗ (inrₗ _), inlₗ (inrₗ _), Lex.inr (Lex.inl h) => Lex.inl <| Lex.inr h
| inlₗ (inrₗ _), inrₗ _, Lex.inr (Lex.sep _ _) => Lex.sep _ _
| inrₗ _, inrₗ _, Lex.inr (Lex.inr h) => Lex.inr h,
fun h =>
match a, b, h with
| inlₗ (inlₗ _), inlₗ (inlₗ _), Lex.inl (Lex.inl h) => Lex.inl h
| inlₗ (inlₗ _), inlₗ (inrₗ _), Lex.inl (Lex.sep _ _) => Lex.sep _ _
| inlₗ (inlₗ _), inrₗ _, Lex.sep _ _ => Lex.sep _ _
| inlₗ (inrₗ _), inlₗ (inrₗ _), Lex.inl (Lex.inr h) => Lex.inr <| Lex.inl h
| inlₗ (inrₗ _), inrₗ _, Lex.sep _ _ => Lex.inr <| Lex.sep _ _
| inrₗ _, inrₗ _, Lex.inr h => Lex.inr <| Lex.inr h⟩ }
@[simp]
theorem sumLexAssoc_apply_inl_inl :
sumLexAssoc α β γ (toLex <| inl <| toLex <| inl a) = toLex (inl a) :=
rfl
@[simp]
theorem sumLexAssoc_apply_inl_inr :
sumLexAssoc α β γ (toLex <| inl <| toLex <| inr b) = toLex (inr <| toLex <| inl b) :=
rfl
@[simp]
theorem sumLexAssoc_apply_inr :
sumLexAssoc α β γ (toLex <| inr c) = toLex (inr <| toLex <| inr c) :=
rfl
@[simp]
theorem sumLexAssoc_symm_apply_inl : (sumLexAssoc α β γ).symm (inl a) = inl (inl a) :=
rfl
@[simp]
theorem sumLexAssoc_symm_apply_inr_inl : (sumLexAssoc α β γ).symm (inr (inl b)) = inl (inr b) :=
rfl
@[simp]
theorem sumLexAssoc_symm_apply_inr_inr : (sumLexAssoc α β γ).symm (inr (inr c)) = inr c :=
rfl
/-- `OrderDual` is antidistributive over `⊕ₗ` up to an order isomorphism. -/
def sumLexDualAntidistrib (α β : Type*) [LE α] [LE β] : (α ⊕ₗ β)ᵒᵈ ≃o βᵒᵈ ⊕ₗ αᵒᵈ :=
{ Equiv.sumComm α β with
map_rel_iff' := fun {a b} => by
rcases a with (a | a) <;> rcases b with (b | b)
· simp
change
toLex (inr <| toDual a) ≤ toLex (inr <| toDual b) ↔
toDual (toLex <| inl a) ≤ toDual (toLex <| inl b)
simp [toDual_le_toDual, Lex.inl_le_inl_iff, Lex.inr_le_inr_iff]
· exact iff_of_false (@Lex.not_inr_le_inl (OrderDual β) (OrderDual α) _ _ _ _)
Lex.not_inr_le_inl
· exact iff_of_true (@Lex.inl_le_inr (OrderDual β) (OrderDual α) _ _ _ _)
(Lex.inl_le_inr _ _)
· change
toLex (inl <| toDual a) ≤ toLex (inl <| toDual b) ↔
toDual (toLex <| inr a) ≤ toDual (toLex <| inr b)
simp [toDual_le_toDual, Lex.inl_le_inl_iff, Lex.inr_le_inr_iff] }
@[simp]
theorem sumLexDualAntidistrib_inl :
sumLexDualAntidistrib α β (toDual (inl a)) = inr (toDual a) :=
rfl
@[simp]
theorem sumLexDualAntidistrib_inr :
sumLexDualAntidistrib α β (toDual (inr b)) = inl (toDual b) :=
rfl
@[simp]
theorem sumLexDualAntidistrib_symm_inl :
(sumLexDualAntidistrib α β).symm (inl (toDual b)) = toDual (inr b) :=
rfl
@[simp]
theorem sumLexDualAntidistrib_symm_inr :
(sumLexDualAntidistrib α β).symm (inr (toDual a)) = toDual (inl a) :=
rfl
end OrderIso
variable [LE α]
namespace WithBot
/-- `WithBot α` is order-isomorphic to `PUnit ⊕ₗ α`, by sending `⊥` to `Unit` and `↑a` to
`a`. -/
def orderIsoPUnitSumLex : WithBot α ≃o PUnit ⊕ₗ α :=
⟨(Equiv.optionEquivSumPUnit α).trans <| (Equiv.sumComm _ _).trans toLex, fun {a b} => by
simp only [Equiv.optionEquivSumPUnit, Option.elim, Equiv.trans_apply, Equiv.coe_fn_mk,
Equiv.sumComm_apply, swap, Lex.toLex_le_toLex, le_refl]
cases' a <;> cases' b
· simp only [elim_inr, lex_inl_inl, bot_le, le_rfl]
· simp only [elim_inr, elim_inl, Lex.sep, bot_le]
· simp only [elim_inl, elim_inr, lex_inr_inl, false_iff]
exact not_coe_le_bot _
· simp only [elim_inl, lex_inr_inr, coe_le_coe]
⟩
@[simp]
theorem orderIsoPUnitSumLex_bot : @orderIsoPUnitSumLex α _ ⊥ = toLex (inl PUnit.unit) :=
rfl
@[simp]
theorem orderIsoPUnitSumLex_toLex (a : α) : orderIsoPUnitSumLex ↑a = toLex (inr a) :=
rfl
@[simp]
theorem orderIsoPUnitSumLex_symm_inl (x : PUnit) :
(@orderIsoPUnitSumLex α _).symm (toLex <| inl x) = ⊥ :=
rfl
@[simp]
theorem orderIsoPUnitSumLex_symm_inr (a : α) : orderIsoPUnitSumLex.symm (toLex <| inr a) = a :=
rfl
end WithBot
namespace WithTop
/-- `WithTop α` is order-isomorphic to `α ⊕ₗ PUnit`, by sending `⊤` to `Unit` and `↑a` to
`a`. -/
def orderIsoSumLexPUnit : WithTop α ≃o α ⊕ₗ PUnit :=
⟨(Equiv.optionEquivSumPUnit α).trans toLex, fun {a b} => by
simp only [Equiv.optionEquivSumPUnit, Option.elim, Equiv.trans_apply, Equiv.coe_fn_mk,
Lex.toLex_le_toLex, le_refl, lex_inr_inr, le_top]
cases' a <;> cases' b
· simp only [lex_inr_inr, le_top]
· simp only [lex_inr_inl, false_iff]
exact not_top_le_coe _
· simp only [Lex.sep, le_top]
· simp only [lex_inl_inl, coe_le_coe]⟩
@[simp]
theorem orderIsoSumLexPUnit_top : @orderIsoSumLexPUnit α _ ⊤ = toLex (inr PUnit.unit) :=
rfl
@[simp]
theorem orderIsoSumLexPUnit_toLex (a : α) : orderIsoSumLexPUnit ↑a = toLex (inl a) :=
rfl
@[simp]
theorem orderIsoSumLexPUnit_symm_inr (x : PUnit) :
(@orderIsoSumLexPUnit α _).symm (toLex <| inr x) = ⊤ :=
rfl
@[simp]
theorem orderIsoSumLexPUnit_symm_inl (a : α) : orderIsoSumLexPUnit.symm (toLex <| inl a) = a :=
rfl
end WithTop
|
Data\Sym\Basic.lean | /-
Copyright (c) 2020 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import Mathlib.Data.Multiset.Basic
import Mathlib.Data.Vector.Basic
import Mathlib.Data.Setoid.Basic
import Mathlib.Tactic.ApplyFun
/-!
# Symmetric powers
This file defines symmetric powers of a type. The nth symmetric power
consists of homogeneous n-tuples modulo permutations by the symmetric
group.
The special case of 2-tuples is called the symmetric square, which is
addressed in more detail in `Data.Sym.Sym2`.
TODO: This was created as supporting material for `Sym2`; it
needs a fleshed-out interface.
## Tags
symmetric powers
-/
assert_not_exists MonoidWithZero
open Mathlib (Vector)
open Function
/-- The nth symmetric power is n-tuples up to permutation. We define it
as a subtype of `Multiset` since these are well developed in the
library. We also give a definition `Sym.sym'` in terms of vectors, and we
show these are equivalent in `Sym.symEquivSym'`.
-/
def Sym (α : Type*) (n : ℕ) :=
{ s : Multiset α // Multiset.card s = n }
-- Porting note (#11445): new definition
/-- The canonical map to `Multiset α` that forgets that `s` has length `n` -/
@[coe] def Sym.toMultiset {α : Type*} {n : ℕ} (s : Sym α n) : Multiset α :=
s.1
instance Sym.hasCoe (α : Type*) (n : ℕ) : CoeOut (Sym α n) (Multiset α) :=
⟨Sym.toMultiset⟩
-- Porting note: instance needed for Data.Finset.Sym
instance {α : Type*} {n : ℕ} [DecidableEq α] : DecidableEq (Sym α n) :=
inferInstanceAs <| DecidableEq <| Subtype _
/-- This is the `List.Perm` setoid lifted to `Vector`.
See note [reducible non-instances].
-/
abbrev Vector.Perm.isSetoid (α : Type*) (n : ℕ) : Setoid (Vector α n) :=
(List.isSetoid α).comap Subtype.val
attribute [local instance] Vector.Perm.isSetoid
namespace Sym
variable {α β : Type*} {n n' m : ℕ} {s : Sym α n} {a b : α}
theorem coe_injective : Injective ((↑) : Sym α n → Multiset α) :=
Subtype.coe_injective
@[simp, norm_cast]
theorem coe_inj {s₁ s₂ : Sym α n} : (s₁ : Multiset α) = s₂ ↔ s₁ = s₂ :=
coe_injective.eq_iff
@[ext] theorem ext {s₁ s₂ : Sym α n} (h : (s₁ : Multiset α) = ↑s₂) : s₁ = s₂ :=
coe_injective h
@[simp]
theorem val_eq_coe (s : Sym α n) : s.1 = ↑s :=
rfl
/-- Construct an element of the `n`th symmetric power from a multiset of cardinality `n`.
-/
@[match_pattern] -- Porting note: removed `@[simps]`, generated bad lemma
abbrev mk (m : Multiset α) (h : Multiset.card m = n) : Sym α n :=
⟨m, h⟩
/-- The unique element in `Sym α 0`. -/
@[match_pattern]
def nil : Sym α 0 :=
⟨0, Multiset.card_zero⟩
@[simp]
theorem coe_nil : ↑(@Sym.nil α) = (0 : Multiset α) :=
rfl
/-- Inserts an element into the term of `Sym α n`, increasing the length by one.
-/
@[match_pattern]
def cons (a : α) (s : Sym α n) : Sym α n.succ :=
⟨a ::ₘ s.1, by rw [Multiset.card_cons, s.2]⟩
@[inherit_doc]
infixr:67 " ::ₛ " => cons
@[simp]
theorem cons_inj_right (a : α) (s s' : Sym α n) : a ::ₛ s = a ::ₛ s' ↔ s = s' :=
Subtype.ext_iff.trans <| (Multiset.cons_inj_right _).trans Subtype.ext_iff.symm
@[simp]
theorem cons_inj_left (a a' : α) (s : Sym α n) : a ::ₛ s = a' ::ₛ s ↔ a = a' :=
Subtype.ext_iff.trans <| Multiset.cons_inj_left _
theorem cons_swap (a b : α) (s : Sym α n) : a ::ₛ b ::ₛ s = b ::ₛ a ::ₛ s :=
Subtype.ext <| Multiset.cons_swap a b s.1
theorem coe_cons (s : Sym α n) (a : α) : (a ::ₛ s : Multiset α) = a ::ₘ s :=
rfl
/-- This is the quotient map that takes a list of n elements as an n-tuple and produces an nth
symmetric power.
-/
def ofVector : Vector α n → Sym α n :=
fun x => ⟨↑x.val, (Multiset.coe_card _).trans x.2⟩
/-- This is the quotient map that takes a list of n elements as an n-tuple and produces an nth
symmetric power.
-/
instance : Coe (Vector α n) (Sym α n) where coe x := ofVector x
@[simp]
theorem ofVector_nil : ↑(Vector.nil : Vector α 0) = (Sym.nil : Sym α 0) :=
rfl
@[simp]
theorem ofVector_cons (a : α) (v : Vector α n) : ↑(Vector.cons a v) = a ::ₛ (↑v : Sym α n) := by
cases v
rfl
@[simp]
theorem card_coe : Multiset.card (s : Multiset α) = n := s.prop
/-- `α ∈ s` means that `a` appears as one of the factors in `s`.
-/
instance : Membership α (Sym α n) :=
⟨fun a s => a ∈ s.1⟩
instance decidableMem [DecidableEq α] (a : α) (s : Sym α n) : Decidable (a ∈ s) :=
s.1.decidableMem _
@[simp, norm_cast] lemma coe_mk (s : Multiset α) (h : Multiset.card s = n) : mk s h = s := rfl
@[simp]
theorem mem_mk (a : α) (s : Multiset α) (h : Multiset.card s = n) : a ∈ mk s h ↔ a ∈ s :=
Iff.rfl
lemma «forall» {p : Sym α n → Prop} :
(∀ s : Sym α n, p s) ↔ ∀ (s : Multiset α) (hs : Multiset.card s = n), p (Sym.mk s hs) := by
simp [Sym]
lemma «exists» {p : Sym α n → Prop} :
(∃ s : Sym α n, p s) ↔ ∃ (s : Multiset α) (hs : Multiset.card s = n), p (Sym.mk s hs) := by
simp [Sym]
@[simp]
theorem not_mem_nil (a : α) : ¬ a ∈ (nil : Sym α 0) :=
Multiset.not_mem_zero a
@[simp]
theorem mem_cons : a ∈ b ::ₛ s ↔ a = b ∨ a ∈ s :=
Multiset.mem_cons
@[simp]
theorem mem_coe : a ∈ (s : Multiset α) ↔ a ∈ s :=
Iff.rfl
theorem mem_cons_of_mem (h : a ∈ s) : a ∈ b ::ₛ s :=
Multiset.mem_cons_of_mem h
--@[simp] Porting note (#10618): simp can prove it
theorem mem_cons_self (a : α) (s : Sym α n) : a ∈ a ::ₛ s :=
Multiset.mem_cons_self a s.1
theorem cons_of_coe_eq (a : α) (v : Vector α n) : a ::ₛ (↑v : Sym α n) = ↑(a ::ᵥ v) :=
Subtype.ext <| by
cases v
rfl
open scoped List in
theorem sound {a b : Vector α n} (h : a.val ~ b.val) : (↑a : Sym α n) = ↑b :=
Subtype.ext <| Quotient.sound h
/-- `erase s a h` is the sym that subtracts 1 from the
multiplicity of `a` if a is present in the sym. -/
def erase [DecidableEq α] (s : Sym α (n + 1)) (a : α) (h : a ∈ s) : Sym α n :=
⟨s.val.erase a, (Multiset.card_erase_of_mem h).trans <| s.property.symm ▸ n.pred_succ⟩
@[simp]
theorem erase_mk [DecidableEq α] (m : Multiset α)
(hc : Multiset.card m = n + 1) (a : α) (h : a ∈ m) :
(mk m hc).erase a h =mk (m.erase a)
(by rw [Multiset.card_erase_of_mem h, hc, Nat.add_one, Nat.pred_succ]) :=
rfl
@[simp]
theorem coe_erase [DecidableEq α] {s : Sym α n.succ} {a : α} (h : a ∈ s) :
(s.erase a h : Multiset α) = Multiset.erase s a :=
rfl
@[simp]
theorem cons_erase [DecidableEq α] {s : Sym α n.succ} {a : α} (h : a ∈ s) : a ::ₛ s.erase a h = s :=
coe_injective <| Multiset.cons_erase h
@[simp]
theorem erase_cons_head [DecidableEq α] (s : Sym α n) (a : α)
(h : a ∈ a ::ₛ s := mem_cons_self a s) : (a ::ₛ s).erase a h = s :=
coe_injective <| Multiset.erase_cons_head a s.1
/-- Another definition of the nth symmetric power, using vectors modulo permutations. (See `Sym`.)
-/
def Sym' (α : Type*) (n : ℕ) :=
Quotient (Vector.Perm.isSetoid α n)
/-- This is `cons` but for the alternative `Sym'` definition.
-/
def cons' {α : Type*} {n : ℕ} : α → Sym' α n → Sym' α (Nat.succ n) := fun a =>
Quotient.map (Vector.cons a) fun ⟨_, _⟩ ⟨_, _⟩ h => List.Perm.cons _ h
@[inherit_doc]
scoped notation a " :: " b => cons' a b
/-- Multisets of cardinality n are equivalent to length-n vectors up to permutations.
-/
def symEquivSym' {α : Type*} {n : ℕ} : Sym α n ≃ Sym' α n :=
Equiv.subtypeQuotientEquivQuotientSubtype _ _ (fun _ => by rfl) fun _ _ => by rfl
theorem cons_equiv_eq_equiv_cons (α : Type*) (n : ℕ) (a : α) (s : Sym α n) :
(a::symEquivSym' s) = symEquivSym' (a ::ₛ s) := by
rcases s with ⟨⟨l⟩, _⟩
rfl
instance instZeroSym : Zero (Sym α 0) :=
⟨⟨0, rfl⟩⟩
@[simp] theorem toMultiset_zero : toMultiset (0 : Sym α 0) = 0 := rfl
instance : EmptyCollection (Sym α 0) :=
⟨0⟩
theorem eq_nil_of_card_zero (s : Sym α 0) : s = nil :=
Subtype.ext <| Multiset.card_eq_zero.1 s.2
instance uniqueZero : Unique (Sym α 0) :=
⟨⟨nil⟩, eq_nil_of_card_zero⟩
/-- `replicate n a` is the sym containing only `a` with multiplicity `n`. -/
def replicate (n : ℕ) (a : α) : Sym α n :=
⟨Multiset.replicate n a, Multiset.card_replicate _ _⟩
theorem replicate_succ {a : α} {n : ℕ} : replicate n.succ a = a ::ₛ replicate n a :=
rfl
theorem coe_replicate : (replicate n a : Multiset α) = Multiset.replicate n a :=
rfl
@[simp]
theorem mem_replicate : b ∈ replicate n a ↔ n ≠ 0 ∧ b = a :=
Multiset.mem_replicate
theorem eq_replicate_iff : s = replicate n a ↔ ∀ b ∈ s, b = a := by
erw [Subtype.ext_iff, Multiset.eq_replicate]
exact and_iff_right s.2
theorem exists_mem (s : Sym α n.succ) : ∃ a, a ∈ s :=
Multiset.card_pos_iff_exists_mem.1 <| s.2.symm ▸ n.succ_pos
theorem exists_cons_of_mem {s : Sym α (n + 1)} {a : α} (h : a ∈ s) : ∃ t, s = a ::ₛ t := by
obtain ⟨m, h⟩ := Multiset.exists_cons_of_mem h
have : Multiset.card m = n := by
apply_fun Multiset.card at h
rw [s.2, Multiset.card_cons, add_left_inj] at h
exact h.symm
use ⟨m, this⟩
apply Subtype.ext
exact h
theorem exists_eq_cons_of_succ (s : Sym α n.succ) : ∃ (a : α) (s' : Sym α n), s = a ::ₛ s' := by
obtain ⟨a, ha⟩ := exists_mem s
classical exact ⟨a, s.erase a ha, (cons_erase ha).symm⟩
theorem eq_replicate {a : α} {n : ℕ} {s : Sym α n} : s = replicate n a ↔ ∀ b ∈ s, b = a :=
Subtype.ext_iff.trans <| Multiset.eq_replicate.trans <| and_iff_right s.prop
theorem eq_replicate_of_subsingleton [Subsingleton α] (a : α) {n : ℕ} (s : Sym α n) :
s = replicate n a :=
eq_replicate.2 fun _ _ => Subsingleton.elim _ _
instance [Subsingleton α] (n : ℕ) : Subsingleton (Sym α n) :=
⟨by
cases n
· simp [eq_iff_true_of_subsingleton]
· intro s s'
obtain ⟨b, -⟩ := exists_mem s
rw [eq_replicate_of_subsingleton b s', eq_replicate_of_subsingleton b s]⟩
instance inhabitedSym [Inhabited α] (n : ℕ) : Inhabited (Sym α n) :=
⟨replicate n default⟩
instance inhabitedSym' [Inhabited α] (n : ℕ) : Inhabited (Sym' α n) :=
⟨Quotient.mk' (Vector.replicate n default)⟩
instance (n : ℕ) [IsEmpty α] : IsEmpty (Sym α n.succ) :=
⟨fun s => by
obtain ⟨a, -⟩ := exists_mem s
exact isEmptyElim a⟩
instance (n : ℕ) [Unique α] : Unique (Sym α n) :=
Unique.mk' _
theorem replicate_right_inj {a b : α} {n : ℕ} (h : n ≠ 0) : replicate n a = replicate n b ↔ a = b :=
Subtype.ext_iff.trans (Multiset.replicate_right_inj h)
theorem replicate_right_injective {n : ℕ} (h : n ≠ 0) :
Function.Injective (replicate n : α → Sym α n) := fun _ _ => (replicate_right_inj h).1
instance (n : ℕ) [Nontrivial α] : Nontrivial (Sym α (n + 1)) :=
(replicate_right_injective n.succ_ne_zero).nontrivial
/-- A function `α → β` induces a function `Sym α n → Sym β n` by applying it to every element of
the underlying `n`-tuple. -/
def map {n : ℕ} (f : α → β) (x : Sym α n) : Sym β n :=
⟨x.val.map f, by simp⟩
@[simp]
theorem mem_map {n : ℕ} {f : α → β} {b : β} {l : Sym α n} :
b ∈ Sym.map f l ↔ ∃ a, a ∈ l ∧ f a = b :=
Multiset.mem_map
/-- Note: `Sym.map_id` is not simp-normal, as simp ends up unfolding `id` with `Sym.map_congr` -/
@[simp]
theorem map_id' {α : Type*} {n : ℕ} (s : Sym α n) : Sym.map (fun x : α => x) s = s := by
ext; simp only [map, Multiset.map_id', ← val_eq_coe]
theorem map_id {α : Type*} {n : ℕ} (s : Sym α n) : Sym.map id s = s := by
ext; simp only [map, id_eq, Multiset.map_id', ← val_eq_coe]
@[simp]
theorem map_map {α β γ : Type*} {n : ℕ} (g : β → γ) (f : α → β) (s : Sym α n) :
Sym.map g (Sym.map f s) = Sym.map (g ∘ f) s :=
Subtype.ext <| by dsimp only [Sym.map]; simp
@[simp]
theorem map_zero (f : α → β) : Sym.map f (0 : Sym α 0) = (0 : Sym β 0) :=
rfl
@[simp]
theorem map_cons {n : ℕ} (f : α → β) (a : α) (s : Sym α n) : (a ::ₛ s).map f = f a ::ₛ s.map f :=
ext <| Multiset.map_cons _ _ _
@[congr]
theorem map_congr {f g : α → β} {s : Sym α n} (h : ∀ x ∈ s, f x = g x) : map f s = map g s :=
Subtype.ext <| Multiset.map_congr rfl h
@[simp]
theorem map_mk {f : α → β} {m : Multiset α} {hc : Multiset.card m = n} :
map f (mk m hc) = mk (m.map f) (by simp [hc]) :=
rfl
@[simp]
theorem coe_map (s : Sym α n) (f : α → β) : ↑(s.map f) = Multiset.map f s :=
rfl
theorem map_injective {f : α → β} (hf : Injective f) (n : ℕ) :
Injective (map f : Sym α n → Sym β n) := fun _ _ h =>
coe_injective <| Multiset.map_injective hf <| coe_inj.2 h
/-- Mapping an equivalence `α ≃ β` using `Sym.map` gives an equivalence between `Sym α n` and
`Sym β n`. -/
@[simps]
def equivCongr (e : α ≃ β) : Sym α n ≃ Sym β n where
toFun := map e
invFun := map e.symm
left_inv x := by rw [map_map, Equiv.symm_comp_self, map_id]
right_inv x := by rw [map_map, Equiv.self_comp_symm, map_id]
/-- "Attach" a proof that `a ∈ s` to each element `a` in `s` to produce
an element of the symmetric power on `{x // x ∈ s}`. -/
def attach (s : Sym α n) : Sym { x // x ∈ s } n :=
⟨s.val.attach, by (conv_rhs => rw [← s.2, ← Multiset.card_attach]); rfl⟩
@[simp]
theorem attach_mk {m : Multiset α} {hc : Multiset.card m = n} :
attach (mk m hc) = mk m.attach (Multiset.card_attach.trans hc) :=
rfl
@[simp]
theorem coe_attach (s : Sym α n) : (s.attach : Multiset { a // a ∈ s }) =
Multiset.attach (s : Multiset α) :=
rfl
theorem attach_map_coe (s : Sym α n) : s.attach.map (↑) = s :=
coe_injective <| Multiset.attach_map_val _
@[simp]
theorem mem_attach (s : Sym α n) (x : { x // x ∈ s }) : x ∈ s.attach :=
Multiset.mem_attach _ _
@[simp]
theorem attach_nil : (nil : Sym α 0).attach = nil :=
rfl
@[simp]
theorem attach_cons (x : α) (s : Sym α n) :
(cons x s).attach =
cons ⟨x, mem_cons_self _ _⟩ (s.attach.map fun x => ⟨x, mem_cons_of_mem x.prop⟩) :=
coe_injective <| Multiset.attach_cons _ _
/-- Change the length of a `Sym` using an equality.
The simp-normal form is for the `cast` to be pushed outward. -/
protected def cast {n m : ℕ} (h : n = m) : Sym α n ≃ Sym α m where
toFun s := ⟨s.val, s.2.trans h⟩
invFun s := ⟨s.val, s.2.trans h.symm⟩
left_inv _ := Subtype.ext rfl
right_inv _ := Subtype.ext rfl
@[simp]
theorem cast_rfl : Sym.cast rfl s = s :=
Subtype.ext rfl
@[simp]
theorem cast_cast {n'' : ℕ} (h : n = n') (h' : n' = n'') :
Sym.cast h' (Sym.cast h s) = Sym.cast (h.trans h') s :=
rfl
@[simp]
theorem coe_cast (h : n = m) : (Sym.cast h s : Multiset α) = s :=
rfl
@[simp]
theorem mem_cast (h : n = m) : a ∈ Sym.cast h s ↔ a ∈ s :=
Iff.rfl
/-- Append a pair of `Sym` terms. -/
def append (s : Sym α n) (s' : Sym α n') : Sym α (n + n') :=
⟨s.1 + s'.1, by rw [map_add, s.2, s'.2]⟩
@[simp]
theorem append_inj_right (s : Sym α n) {t t' : Sym α n'} : s.append t = s.append t' ↔ t = t' :=
Subtype.ext_iff.trans <| (add_right_inj _).trans Subtype.ext_iff.symm
@[simp]
theorem append_inj_left {s s' : Sym α n} (t : Sym α n') : s.append t = s'.append t ↔ s = s' :=
Subtype.ext_iff.trans <| (add_left_inj _).trans Subtype.ext_iff.symm
theorem append_comm (s : Sym α n') (s' : Sym α n') :
s.append s' = Sym.cast (add_comm _ _) (s'.append s) := by
ext
simp [append, add_comm]
@[simp, norm_cast]
theorem coe_append (s : Sym α n) (s' : Sym α n') : (s.append s' : Multiset α) = s + s' :=
rfl
theorem mem_append_iff {s' : Sym α m} : a ∈ s.append s' ↔ a ∈ s ∨ a ∈ s' :=
Multiset.mem_add
/-- `a ↦ {a}` as an equivalence between `α` and `Sym α 1`. -/
@[simps apply]
def oneEquiv : α ≃ Sym α 1 where
toFun a := ⟨{a}, by simp⟩
invFun s := (Equiv.subtypeQuotientEquivQuotientSubtype
(·.length = 1) _ (fun l ↦ Iff.rfl) (fun l l' ↦ by rfl) s).liftOn
(fun l ↦ l.1.head <| List.length_pos.mp <| by simp)
fun ⟨_, _⟩ ⟨_, h⟩ ↦ fun perm ↦ by
obtain ⟨a, rfl⟩ := List.length_eq_one.mp h
exact List.eq_of_mem_singleton (perm.mem_iff.mp <| List.head_mem _)
left_inv a := by rfl
right_inv := by rintro ⟨⟨l⟩, h⟩; obtain ⟨a, rfl⟩ := List.length_eq_one.mp h; rfl
/-- Fill a term `m : Sym α (n - i)` with `i` copies of `a` to obtain a term of `Sym α n`.
This is a convenience wrapper for `m.append (replicate i a)` that adjusts the term using
`Sym.cast`. -/
def fill (a : α) (i : Fin (n + 1)) (m : Sym α (n - i)) : Sym α n :=
Sym.cast (Nat.sub_add_cancel i.is_le) (m.append (replicate i a))
theorem coe_fill {a : α} {i : Fin (n + 1)} {m : Sym α (n - i)} :
(fill a i m : Multiset α) = m + replicate i a :=
rfl
theorem mem_fill_iff {a b : α} {i : Fin (n + 1)} {s : Sym α (n - i)} :
a ∈ Sym.fill b i s ↔ (i : ℕ) ≠ 0 ∧ a = b ∨ a ∈ s := by
rw [fill, mem_cast, mem_append_iff, or_comm, mem_replicate]
open Multiset
/-- Remove every `a` from a given `Sym α n`.
Yields the number of copies `i` and a term of `Sym α (n - i)`. -/
def filterNe [DecidableEq α] (a : α) (m : Sym α n) : Σi : Fin (n + 1), Sym α (n - i) :=
⟨⟨m.1.count a, (count_le_card _ _).trans_lt <| by rw [m.2, Nat.lt_succ_iff]⟩,
m.1.filter (a ≠ ·),
Nat.eq_sub_of_add_eq <|
Eq.trans
(by
rw [← countP_eq_card_filter, add_comm]
simp only [eq_comm, Ne, count]
rw [← card_eq_countP_add_countP _ _])
m.2⟩
theorem sigma_sub_ext {m₁ m₂ : Σi : Fin (n + 1), Sym α (n - i)} (h : (m₁.2 : Multiset α) = m₂.2) :
m₁ = m₂ :=
Sigma.subtype_ext
(Fin.ext <| by
rw [← Nat.sub_sub_self (Nat.le_of_lt_succ m₁.1.is_lt), ← m₁.2.2, val_eq_coe, h,
← val_eq_coe, m₂.2.2, Nat.sub_sub_self (Nat.le_of_lt_succ m₂.1.is_lt)])
h
theorem fill_filterNe [DecidableEq α] (a : α) (m : Sym α n) :
(m.filterNe a).2.fill a (m.filterNe a).1 = m :=
Sym.ext
(by
rw [coe_fill, filterNe, ← val_eq_coe, Subtype.coe_mk, Fin.val_mk]
ext b; dsimp
rw [count_add, count_filter, Sym.coe_replicate, count_replicate]
obtain rfl | h := eq_or_ne a b
· rw [if_pos rfl, if_neg (not_not.2 rfl), zero_add]
· rw [if_pos h, if_neg h, add_zero])
theorem filter_ne_fill [DecidableEq α] (a : α) (m : Σi : Fin (n + 1), Sym α (n - i)) (h : a ∉ m.2) :
(m.2.fill a m.1).filterNe a = m :=
sigma_sub_ext
(by
rw [filterNe, ← val_eq_coe, Subtype.coe_mk, val_eq_coe, coe_fill]
rw [filter_add, filter_eq_self.2, add_right_eq_self, eq_zero_iff_forall_not_mem]
· intro b hb
rw [mem_filter, Sym.mem_coe, mem_replicate] at hb
exact hb.2 hb.1.2.symm
· exact fun a ha ha' => h <| ha'.symm ▸ ha)
theorem count_coe_fill_self_of_not_mem [DecidableEq α] {a : α} {i : Fin (n + 1)} {s : Sym α (n - i)}
(hx : a ∉ s) :
count a (fill a i s : Multiset α) = i := by
simp [coe_fill, coe_replicate, hx]
theorem count_coe_fill_of_ne [DecidableEq α] {a x : α} {i : Fin (n + 1)} {s : Sym α (n - i)}
(hx : x ≠ a) :
count x (fill a i s : Multiset α) = count x s := by
suffices x ∉ Multiset.replicate i a by simp [coe_fill, coe_replicate, this]
simp [Multiset.mem_replicate, hx]
end Sym
section Equiv
/-! ### Combinatorial equivalences -/
variable {α : Type*} {n : ℕ}
open Sym
namespace SymOptionSuccEquiv
/-- Function from the symmetric product over `Option` splitting on whether or not
it contains a `none`. -/
def encode [DecidableEq α] (s : Sym (Option α) n.succ) : Sym (Option α) n ⊕ Sym α n.succ :=
if h : none ∈ s then Sum.inl (s.erase none h)
else
Sum.inr
(s.attach.map fun o =>
o.1.get <| Option.ne_none_iff_isSome.1 <| ne_of_mem_of_not_mem o.2 h)
@[simp]
theorem encode_of_none_mem [DecidableEq α] (s : Sym (Option α) n.succ) (h : none ∈ s) :
encode s = Sum.inl (s.erase none h) :=
dif_pos h
@[simp]
theorem encode_of_not_none_mem [DecidableEq α] (s : Sym (Option α) n.succ) (h : ¬none ∈ s) :
encode s =
Sum.inr
(s.attach.map fun o =>
o.1.get <| Option.ne_none_iff_isSome.1 <| ne_of_mem_of_not_mem o.2 h) :=
dif_neg h
/-- Inverse of `Sym_option_succ_equiv.decode`. -/
-- @[simp] Porting note: not a nice simp lemma, applies too often in Lean4
def decode : Sym (Option α) n ⊕ Sym α n.succ → Sym (Option α) n.succ
| Sum.inl s => none ::ₛ s
| Sum.inr s => s.map Embedding.some
@[simp]
theorem decode_inl (s : Sym (Option α) n) : decode (Sum.inl s) = none ::ₛ s :=
rfl
@[simp]
theorem decode_inr (s : Sym α n.succ) : decode (Sum.inr s) = s.map Embedding.some :=
rfl
@[simp]
theorem decode_encode [DecidableEq α] (s : Sym (Option α) n.succ) : decode (encode s) = s := by
by_cases h : none ∈ s
· simp [h]
· simp only [decode, h, not_false_iff, encode_of_not_none_mem, Embedding.some_apply, map_map,
comp_apply, Option.some_get]
convert s.attach_map_coe
@[simp]
theorem encode_decode [DecidableEq α] (s : Sym (Option α) n ⊕ Sym α n.succ) :
encode (decode s) = s := by
obtain s | s := s
· simp
· unfold SymOptionSuccEquiv.encode
split_ifs with h
· obtain ⟨a, _, ha⟩ := Multiset.mem_map.mp h
exact Option.some_ne_none _ ha
· refine congr_arg Sum.inr ?_
refine map_injective (Option.some_injective _) _ ?_
refine Eq.trans ?_ (.trans (SymOptionSuccEquiv.decode (Sum.inr s)).attach_map_coe ?_) <;> simp
end SymOptionSuccEquiv
/-- The symmetric product over `Option` is a disjoint union over simpler symmetric products. -/
--@[simps]
def symOptionSuccEquiv [DecidableEq α] :
Sym (Option α) n.succ ≃ Sym (Option α) n ⊕ Sym α n.succ where
toFun := SymOptionSuccEquiv.encode
invFun := SymOptionSuccEquiv.decode
left_inv := SymOptionSuccEquiv.decode_encode
right_inv := SymOptionSuccEquiv.encode_decode
end Equiv
|
Data\Sym\Card.lean | /-
Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta, Huỳnh Trần Khanh, Stuart Presnell
-/
import Mathlib.Algebra.BigOperators.Group.Finset
import Mathlib.Data.Finset.Sym
import Mathlib.Data.Fintype.Sum
import Mathlib.Data.Fintype.Prod
/-!
# Stars and bars
In this file, we prove (in `Sym.card_sym_eq_multichoose`) that the function `multichoose n k`
defined in `Data/Nat/Choose/Basic` counts the number of multisets of cardinality `k` over an
alphabet of cardinality `n`. In conjunction with `Nat.multichoose_eq` proved in
`Data/Nat/Choose/Basic`, which shows that `multichoose n k = choose (n + k - 1) k`,
this is central to the "stars and bars" technique in combinatorics, where we switch between
counting multisets of size `k` over an alphabet of size `n` to counting strings of `k` elements
("stars") separated by `n-1` dividers ("bars").
## Informal statement
Many problems in mathematics are of the form of (or can be reduced to) putting `k` indistinguishable
objects into `n` distinguishable boxes; for example, the problem of finding natural numbers
`x1, ..., xn` whose sum is `k`. This is equivalent to forming a multiset of cardinality `k` from
an alphabet of cardinality `n` -- for each box `i ∈ [1, n]` the multiset contains as many copies
of `i` as there are items in the `i`th box.
The "stars and bars" technique arises from another way of presenting the same problem. Instead of
putting `k` items into `n` boxes, we take a row of `k` items (the "stars") and separate them by
inserting `n-1` dividers (the "bars"). For example, the pattern `*|||**|*|` exhibits 4 items
distributed into 6 boxes -- note that any box, including the first and last, may be empty.
Such arrangements of `k` stars and `n-1` bars are in 1-1 correspondence with multisets of size `k`
over an alphabet of size `n`, and are counted by `choose (n + k - 1) k`.
Note that this problem is one component of Gian-Carlo Rota's "Twelvefold Way"
https://en.wikipedia.org/wiki/Twelvefold_way
## Formal statement
Here we generalise the alphabet to an arbitrary fintype `α`, and we use `Sym α k` as the type of
multisets of size `k` over `α`. Thus the statement that these are counted by `multichoose` is:
`Sym.card_sym_eq_multichoose : card (Sym α k) = multichoose (card α) k`
while the "stars and bars" technique gives
`Sym.card_sym_eq_choose : card (Sym α k) = choose (card α + k - 1) k`
## Tags
stars and bars, multichoose
-/
open Finset Fintype Function Sum Nat
variable {α β : Type*}
namespace Sym
section Sym
variable (α) (n : ℕ)
/-- Over `Fin (n + 1)`, the multisets of size `k + 1` containing `0` are equivalent to those of size
`k`, as demonstrated by respectively erasing or appending `0`. -/
protected def e1 {n k : ℕ} : { s : Sym (Fin (n + 1)) (k + 1) // ↑0 ∈ s } ≃ Sym (Fin n.succ) k where
toFun s := s.1.erase 0 s.2
invFun s := ⟨cons 0 s, mem_cons_self 0 s⟩
left_inv s := by simp
right_inv s := by simp
/-- The multisets of size `k` over `Fin n+2` not containing `0`
are equivalent to those of size `k` over `Fin n+1`,
as demonstrated by respectively decrementing or incrementing every element of the multiset.
-/
protected def e2 {n k : ℕ} : { s : Sym (Fin n.succ.succ) k // ↑0 ∉ s } ≃ Sym (Fin n.succ) k where
toFun s := map (Fin.predAbove 0) s.1
invFun s :=
⟨map (Fin.succAbove 0) s,
(mt mem_map.1) (not_exists.2 fun t => not_and.2 fun _ => Fin.succAbove_ne _ t)⟩
left_inv s := by
ext1
simp only [map_map]
refine (Sym.map_congr fun v hv ↦ ?_).trans (map_id' _)
exact Fin.succAbove_predAbove (ne_of_mem_of_not_mem hv s.2)
right_inv s := by
simp only [map_map, comp_apply, ← Fin.castSucc_zero, Fin.predAbove_succAbove, map_id']
-- Porting note: use eqn compiler instead of `pincerRecursion` to make cases more readable
theorem card_sym_fin_eq_multichoose : ∀ n k : ℕ, card (Sym (Fin n) k) = multichoose n k
| n, 0 => by simp
| 0, k + 1 => by rw [multichoose_zero_succ]; exact card_eq_zero
| 1, k + 1 => by simp
| n + 2, k + 1 => by
rw [multichoose_succ_succ, ← card_sym_fin_eq_multichoose (n + 1) (k + 1),
← card_sym_fin_eq_multichoose (n + 2) k, add_comm (Fintype.card _), ← card_sum]
refine Fintype.card_congr (Equiv.symm ?_)
apply (Sym.e1.symm.sumCongr Sym.e2.symm).trans
apply Equiv.sumCompl
/-- For any fintype `α` of cardinality `n`, `card (Sym α k) = multichoose (card α) k`. -/
theorem card_sym_eq_multichoose (α : Type*) (k : ℕ) [Fintype α] [Fintype (Sym α k)] :
card (Sym α k) = multichoose (card α) k := by
rw [← card_sym_fin_eq_multichoose]
-- FIXME: Without the `Fintype` namespace, why does it complain about `Finset.card_congr` being
-- deprecated?
exact Fintype.card_congr (equivCongr (equivFin α))
/-- The *stars and bars* lemma: the cardinality of `Sym α k` is equal to
`Nat.choose (card α + k - 1) k`. -/
theorem card_sym_eq_choose {α : Type*} [Fintype α] (k : ℕ) [Fintype (Sym α k)] :
card (Sym α k) = (card α + k - 1).choose k := by
rw [card_sym_eq_multichoose, Nat.multichoose_eq]
end Sym
end Sym
namespace Sym2
variable [DecidableEq α]
/-- The `diag` of `s : Finset α` is sent on a finset of `Sym2 α` of card `s.card`. -/
theorem card_image_diag (s : Finset α) : (s.diag.image Sym2.mk).card = s.card := by
rw [card_image_of_injOn, diag_card]
rintro ⟨x₀, x₁⟩ hx _ _ h
cases Sym2.eq.1 h
· rfl
· simp only [mem_coe, mem_diag] at hx
rw [hx.2]
theorem two_mul_card_image_offDiag (s : Finset α) :
2 * (s.offDiag.image Sym2.mk).card = s.offDiag.card := by
rw [card_eq_sum_card_image (Sym2.mk : α × α → _), sum_const_nat (Sym2.ind _), mul_comm]
rintro x y hxy
simp_rw [mem_image, mem_offDiag] at hxy
obtain ⟨a, ⟨ha₁, ha₂, ha⟩, h⟩ := hxy
replace h := Sym2.eq.1 h
obtain ⟨hx, hy, hxy⟩ : x ∈ s ∧ y ∈ s ∧ x ≠ y := by
cases h <;> refine ⟨‹_›, ‹_›, ?_⟩ <;> [exact ha; exact ha.symm]
have hxy' : y ≠ x := hxy.symm
have : (s.offDiag.filter fun z => Sym2.mk z = s(x, y)) = ({(x, y), (y, x)} : Finset _) := by
ext ⟨x₁, y₁⟩
rw [mem_filter, mem_insert, mem_singleton, Sym2.eq_iff, Prod.mk.inj_iff, Prod.mk.inj_iff,
and_iff_right_iff_imp]
-- `hxy'` is used in `exact`
rintro (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩) <;> rw [mem_offDiag] <;> exact ⟨‹_›, ‹_›, ‹_›⟩
rw [this, card_insert_of_not_mem, card_singleton]
simp only [not_and, Prod.mk.inj_iff, mem_singleton]
exact fun _ => hxy'
/-- The `offDiag` of `s : Finset α` is sent on a finset of `Sym2 α` of card `s.offDiag.card / 2`.
This is because every element `s(x, y)` of `Sym2 α` not on the diagonal comes from exactly two
pairs: `(x, y)` and `(y, x)`. -/
theorem card_image_offDiag (s : Finset α) :
(s.offDiag.image Sym2.mk).card = s.card.choose 2 := by
rw [Nat.choose_two_right, Nat.mul_sub_left_distrib, mul_one, ← offDiag_card,
Nat.div_eq_of_eq_mul_right Nat.zero_lt_two (two_mul_card_image_offDiag s).symm]
theorem card_subtype_diag [Fintype α] : card { a : Sym2 α // a.IsDiag } = card α := by
convert card_image_diag (univ : Finset α)
rw [← filter_image_mk_isDiag, Fintype.card_of_subtype]
rintro x
rw [mem_filter, univ_product_univ, mem_image]
obtain ⟨a, ha⟩ := Quot.exists_rep x
exact and_iff_right ⟨a, mem_univ _, ha⟩
theorem card_subtype_not_diag [Fintype α] :
card { a : Sym2 α // ¬a.IsDiag } = (card α).choose 2 := by
convert card_image_offDiag (univ : Finset α)
rw [← filter_image_mk_not_isDiag, Fintype.card_of_subtype]
rintro x
rw [mem_filter, univ_product_univ, mem_image]
obtain ⟨a, ha⟩ := Quot.exists_rep x
exact and_iff_right ⟨a, mem_univ _, ha⟩
/-- Type **stars and bars** for the case `n = 2`. -/
protected theorem card {α} [Fintype α] : card (Sym2 α) = Nat.choose (card α + 1) 2 :=
Finset.card_sym2 _
end Sym2
|
Data\Sym\Sym2.lean | /-
Copyright (c) 2020 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import Mathlib.Data.Finset.Prod
import Mathlib.Data.Sym.Basic
import Mathlib.Data.Sym.Sym2.Init
import Mathlib.Data.SetLike.Basic
/-!
# The symmetric square
This file defines the symmetric square, which is `α × α` modulo
swapping. This is also known as the type of unordered pairs.
More generally, the symmetric square is the second symmetric power
(see `Data.Sym.Basic`). The equivalence is `Sym2.equivSym`.
From the point of view that an unordered pair is equivalent to a
multiset of cardinality two (see `Sym2.equivMultiset`), there is a
`Mem` instance `Sym2.Mem`, which is a `Prop`-valued membership
test. Given `h : a ∈ z` for `z : Sym2 α`, then `Mem.other h` is the other
element of the pair, defined using `Classical.choice`. If `α` has
decidable equality, then `h.other'` computably gives the other element.
The universal property of `Sym2` is provided as `Sym2.lift`, which
states that functions from `Sym2 α` are equivalent to symmetric
two-argument functions from `α`.
Recall that an undirected graph (allowing self loops, but no multiple
edges) is equivalent to a symmetric relation on the vertex type `α`.
Given a symmetric relation on `α`, the corresponding edge set is
constructed by `Sym2.fromRel` which is a special case of `Sym2.lift`.
## Notation
The element `Sym2.mk (a, b)` can be written as `s(a, b)` for short.
## Tags
symmetric square, unordered pairs, symmetric powers
-/
assert_not_exists MonoidWithZero
open Mathlib (Vector)
open Finset Function Sym
universe u
variable {α β γ : Type*}
namespace Sym2
/-- This is the relation capturing the notion of pairs equivalent up to permutations. -/
@[aesop (rule_sets := [Sym2]) [safe [constructors, cases], norm]]
inductive Rel (α : Type u) : α × α → α × α → Prop
| refl (x y : α) : Rel _ (x, y) (x, y)
| swap (x y : α) : Rel _ (x, y) (y, x)
attribute [refl] Rel.refl
@[symm]
theorem Rel.symm {x y : α × α} : Rel α x y → Rel α y x := by aesop (rule_sets := [Sym2])
@[trans]
theorem Rel.trans {x y z : α × α} (a : Rel α x y) (b : Rel α y z) : Rel α x z := by
aesop (rule_sets := [Sym2])
theorem Rel.is_equivalence : Equivalence (Rel α) :=
{ refl := fun (x, y) ↦ Rel.refl x y, symm := Rel.symm, trans := Rel.trans }
/-- One can use `attribute [local instance] Sym2.Rel.setoid` to temporarily
make `Quotient` functionality work for `α × α`. -/
def Rel.setoid (α : Type u) : Setoid (α × α) :=
⟨Rel α, Rel.is_equivalence⟩
@[simp]
theorem rel_iff' {p q : α × α} : Rel α p q ↔ p = q ∨ p = q.swap := by
aesop (rule_sets := [Sym2])
theorem rel_iff {x y z w : α} : Rel α (x, y) (z, w) ↔ x = z ∧ y = w ∨ x = w ∧ y = z := by
simp
end Sym2
/-- `Sym2 α` is the symmetric square of `α`, which, in other words, is the
type of unordered pairs.
It is equivalent in a natural way to multisets of cardinality 2 (see
`Sym2.equivMultiset`).
-/
abbrev Sym2 (α : Type u) := Quot (Sym2.Rel α)
/-- Constructor for `Sym2`. This is the quotient map `α × α → Sym2 α`. -/
protected abbrev Sym2.mk {α : Type*} (p : α × α) : Sym2 α := Quot.mk (Sym2.Rel α) p
/-- `s(x, y)` is an unordered pair,
which is to say a pair modulo the action of the symmetric group.
It is equal to `Sym2.mk (x, y)`. -/
notation3 "s(" x ", " y ")" => Sym2.mk (x, y)
namespace Sym2
protected theorem sound {p p' : α × α} (h : Sym2.Rel α p p') : Sym2.mk p = Sym2.mk p' :=
Quot.sound h
protected theorem exact {p p' : α × α} (h : Sym2.mk p = Sym2.mk p') : Sym2.Rel α p p' :=
Quotient.exact (s := Sym2.Rel.setoid α) h
@[simp]
protected theorem eq {p p' : α × α} : Sym2.mk p = Sym2.mk p' ↔ Sym2.Rel α p p' :=
Quotient.eq' (s₁ := Sym2.Rel.setoid α)
@[elab_as_elim, cases_eliminator, induction_eliminator]
protected theorem ind {f : Sym2 α → Prop} (h : ∀ x y, f s(x, y)) : ∀ i, f i :=
Quot.ind <| Prod.rec <| h
@[elab_as_elim]
protected theorem inductionOn {f : Sym2 α → Prop} (i : Sym2 α) (hf : ∀ x y, f s(x, y)) : f i :=
i.ind hf
@[elab_as_elim]
protected theorem inductionOn₂ {f : Sym2 α → Sym2 β → Prop} (i : Sym2 α) (j : Sym2 β)
(hf : ∀ a₁ a₂ b₁ b₂, f s(a₁, a₂) s(b₁, b₂)) : f i j :=
Quot.induction_on₂ i j <| by
intro ⟨a₁, a₂⟩ ⟨b₁, b₂⟩
exact hf _ _ _ _
/-- Dependent recursion principal for `Sym2`. See `Quot.rec`. -/
@[elab_as_elim]
protected def rec {motive : Sym2 α → Sort*}
(f : (p : α × α) → motive (Sym2.mk p))
(h : (p q : α × α) → (h : Sym2.Rel α p q) → Eq.ndrec (f p) (Sym2.sound h) = f q)
(z : Sym2 α) : motive z :=
Quot.rec f h z
/-- Dependent recursion principal for `Sym2` when the target is a `Subsingleton` type.
See `Quot.recOnSubsingleton`. -/
@[elab_as_elim]
protected abbrev recOnSubsingleton {motive : Sym2 α → Sort*}
[(p : α × α) → Subsingleton (motive (Sym2.mk p))]
(z : Sym2 α) (f : (p : α × α) → motive (Sym2.mk p)) : motive z :=
Quot.recOnSubsingleton z f
protected theorem «exists» {α : Sort _} {f : Sym2 α → Prop} :
(∃ x : Sym2 α, f x) ↔ ∃ x y, f s(x, y) :=
(surjective_quot_mk _).exists.trans Prod.exists
protected theorem «forall» {α : Sort _} {f : Sym2 α → Prop} :
(∀ x : Sym2 α, f x) ↔ ∀ x y, f s(x, y) :=
(surjective_quot_mk _).forall.trans Prod.forall
theorem eq_swap {a b : α} : s(a, b) = s(b, a) := Quot.sound (Rel.swap _ _)
@[simp]
theorem mk_prod_swap_eq {p : α × α} : Sym2.mk p.swap = Sym2.mk p := by
cases p
exact eq_swap
theorem congr_right {a b c : α} : s(a, b) = s(a, c) ↔ b = c := by
simp (config := {contextual := true})
theorem congr_left {a b c : α} : s(b, a) = s(c, a) ↔ b = c := by
simp (config := {contextual := true})
theorem eq_iff {x y z w : α} : s(x, y) = s(z, w) ↔ x = z ∧ y = w ∨ x = w ∧ y = z := by
simp
theorem mk_eq_mk_iff {p q : α × α} : Sym2.mk p = Sym2.mk q ↔ p = q ∨ p = q.swap := by
cases p
cases q
simp only [eq_iff, Prod.mk.inj_iff, Prod.swap_prod_mk]
/-- The universal property of `Sym2`; symmetric functions of two arguments are equivalent to
functions from `Sym2`. Note that when `β` is `Prop`, it can sometimes be more convenient to use
`Sym2.fromRel` instead. -/
def lift : { f : α → α → β // ∀ a₁ a₂, f a₁ a₂ = f a₂ a₁ } ≃ (Sym2 α → β) where
toFun f :=
Quot.lift (uncurry ↑f) <| by
rintro _ _ ⟨⟩
exacts [rfl, f.prop _ _]
invFun F := ⟨curry (F ∘ Sym2.mk), fun a₁ a₂ => congr_arg F eq_swap⟩
left_inv f := Subtype.ext rfl
right_inv F := funext <| Sym2.ind fun x y => rfl
@[simp]
theorem lift_mk (f : { f : α → α → β // ∀ a₁ a₂, f a₁ a₂ = f a₂ a₁ }) (a₁ a₂ : α) :
lift f s(a₁, a₂) = (f : α → α → β) a₁ a₂ :=
rfl
@[simp]
theorem coe_lift_symm_apply (F : Sym2 α → β) (a₁ a₂ : α) :
(lift.symm F : α → α → β) a₁ a₂ = F s(a₁, a₂) :=
rfl
/-- A two-argument version of `Sym2.lift`. -/
def lift₂ :
{ f : α → α → β → β → γ //
∀ a₁ a₂ b₁ b₂, f a₁ a₂ b₁ b₂ = f a₂ a₁ b₁ b₂ ∧ f a₁ a₂ b₁ b₂ = f a₁ a₂ b₂ b₁ } ≃
(Sym2 α → Sym2 β → γ) where
toFun f :=
Quotient.lift₂ (s₁ := Sym2.Rel.setoid α) (s₂ := Sym2.Rel.setoid β)
(fun (a : α × α) (b : β × β) => f.1 a.1 a.2 b.1 b.2)
(by
rintro _ _ _ _ ⟨⟩ ⟨⟩
exacts [rfl, (f.2 _ _ _ _).2, (f.2 _ _ _ _).1, (f.2 _ _ _ _).1.trans (f.2 _ _ _ _).2])
invFun F :=
⟨fun a₁ a₂ b₁ b₂ => F s(a₁, a₂) s(b₁, b₂), fun a₁ a₂ b₁ b₂ => by
constructor
exacts [congr_arg₂ F eq_swap rfl, congr_arg₂ F rfl eq_swap]⟩
left_inv f := Subtype.ext rfl
right_inv F := funext₂ fun a b => Sym2.inductionOn₂ a b fun _ _ _ _ => rfl
@[simp]
theorem lift₂_mk
(f :
{ f : α → α → β → β → γ //
∀ a₁ a₂ b₁ b₂, f a₁ a₂ b₁ b₂ = f a₂ a₁ b₁ b₂ ∧ f a₁ a₂ b₁ b₂ = f a₁ a₂ b₂ b₁ })
(a₁ a₂ : α) (b₁ b₂ : β) : lift₂ f s(a₁, a₂) s(b₁, b₂) = (f : α → α → β → β → γ) a₁ a₂ b₁ b₂ :=
rfl
@[simp]
theorem coe_lift₂_symm_apply (F : Sym2 α → Sym2 β → γ) (a₁ a₂ : α) (b₁ b₂ : β) :
(lift₂.symm F : α → α → β → β → γ) a₁ a₂ b₁ b₂ = F s(a₁, a₂) s(b₁, b₂) :=
rfl
/-- The functor `Sym2` is functorial, and this function constructs the induced maps.
-/
def map (f : α → β) : Sym2 α → Sym2 β :=
Quot.map (Prod.map f f)
(by intro _ _ h; cases h <;> constructor)
@[simp]
theorem map_id : map (@id α) = id := by
ext ⟨⟨x, y⟩⟩
rfl
theorem map_comp {g : β → γ} {f : α → β} : Sym2.map (g ∘ f) = Sym2.map g ∘ Sym2.map f := by
ext ⟨⟨x, y⟩⟩
rfl
theorem map_map {g : β → γ} {f : α → β} (x : Sym2 α) : map g (map f x) = map (g ∘ f) x := by
induction x; aesop
@[simp]
theorem map_pair_eq (f : α → β) (x y : α) : map f s(x, y) = s(f x, f y) :=
rfl
theorem map.injective {f : α → β} (hinj : Injective f) : Injective (map f) := by
intro z z'
refine Sym2.inductionOn₂ z z' (fun x y x' y' => ?_)
simp [hinj.eq_iff]
/-- `mk a` as an embedding. This is the symmetric version of `Function.Embedding.sectl`. -/
@[simps]
def mkEmbedding (a : α) : α ↪ Sym2 α where
toFun b := s(a, b)
inj' b₁ b₁ h := by
simp only [Sym2.eq, Sym2.rel_iff', Prod.mk.injEq, true_and, Prod.swap_prod_mk] at h
obtain rfl | ⟨rfl, rfl⟩ := h <;> rfl
/-- `Sym2.map` as an embedding. -/
@[simps]
def _root_.Function.Embedding.sym2Map (f : α ↪ β) : Sym2 α ↪ Sym2 β where
toFun := map f
inj' := map.injective f.injective
section Membership
/-! ### Membership and set coercion -/
/-- This is a predicate that determines whether a given term is a member of a term of the
symmetric square. From this point of view, the symmetric square is the subtype of
cardinality-two multisets on `α`.
-/
protected def Mem (x : α) (z : Sym2 α) : Prop :=
∃ y : α, z = s(x, y)
@[aesop norm (rule_sets := [Sym2])]
theorem mem_iff' {a b c : α} : Sym2.Mem a s(b, c) ↔ a = b ∨ a = c :=
{ mp := by
rintro ⟨_, h⟩
rw [eq_iff] at h
aesop
mpr := by
rintro (rfl | rfl)
· exact ⟨_, rfl⟩
rw [eq_swap]
exact ⟨_, rfl⟩ }
instance : SetLike (Sym2 α) α where
coe z := { x | z.Mem x }
coe_injective' z z' h := by
simp only [Set.ext_iff, Set.mem_setOf_eq] at h
induction' z with x y
induction' z' with x' y'
have hx := h x; have hy := h y; have hx' := h x'; have hy' := h y'
simp only [mem_iff', eq_self_iff_true, or_true_iff, iff_true_iff,
true_or_iff, true_iff_iff] at hx hy hx' hy'
aesop
@[simp]
theorem mem_iff_mem {x : α} {z : Sym2 α} : Sym2.Mem x z ↔ x ∈ z :=
Iff.rfl
theorem mem_iff_exists {x : α} {z : Sym2 α} : x ∈ z ↔ ∃ y : α, z = s(x, y) :=
Iff.rfl
@[ext]
theorem ext {p q : Sym2 α} (h : ∀ x, x ∈ p ↔ x ∈ q) : p = q :=
SetLike.ext h
theorem mem_mk_left (x y : α) : x ∈ s(x, y) :=
⟨y, rfl⟩
theorem mem_mk_right (x y : α) : y ∈ s(x, y) :=
eq_swap.subst <| mem_mk_left y x
@[simp, aesop norm (rule_sets := [Sym2])]
theorem mem_iff {a b c : α} : a ∈ s(b, c) ↔ a = b ∨ a = c :=
mem_iff'
theorem out_fst_mem (e : Sym2 α) : e.out.1 ∈ e :=
⟨e.out.2, by rw [Sym2.mk, e.out_eq]⟩
theorem out_snd_mem (e : Sym2 α) : e.out.2 ∈ e :=
⟨e.out.1, by rw [eq_swap, Sym2.mk, e.out_eq]⟩
theorem ball {p : α → Prop} {a b : α} : (∀ c ∈ s(a, b), p c) ↔ p a ∧ p b := by
refine ⟨fun h => ⟨h _ <| mem_mk_left _ _, h _ <| mem_mk_right _ _⟩, fun h c hc => ?_⟩
obtain rfl | rfl := Sym2.mem_iff.1 hc
· exact h.1
· exact h.2
/-- Given an element of the unordered pair, give the other element using `Classical.choose`.
See also `Mem.other'` for the computable version.
-/
noncomputable def Mem.other {a : α} {z : Sym2 α} (h : a ∈ z) : α :=
Classical.choose h
@[simp]
theorem other_spec {a : α} {z : Sym2 α} (h : a ∈ z) : s(a, Mem.other h) = z := by
erw [← Classical.choose_spec h]
theorem other_mem {a : α} {z : Sym2 α} (h : a ∈ z) : Mem.other h ∈ z := by
convert mem_mk_right a <| Mem.other h
rw [other_spec h]
theorem mem_and_mem_iff {x y : α} {z : Sym2 α} (hne : x ≠ y) : x ∈ z ∧ y ∈ z ↔ z = s(x, y) := by
constructor
· induction' z with x' y'
rw [mem_iff, mem_iff]
aesop
· rintro rfl
simp
theorem eq_of_ne_mem {x y : α} {z z' : Sym2 α} (h : x ≠ y) (h1 : x ∈ z) (h2 : y ∈ z) (h3 : x ∈ z')
(h4 : y ∈ z') : z = z' :=
((mem_and_mem_iff h).mp ⟨h1, h2⟩).trans ((mem_and_mem_iff h).mp ⟨h3, h4⟩).symm
instance Mem.decidable [DecidableEq α] (x : α) (z : Sym2 α) : Decidable (x ∈ z) :=
z.recOnSubsingleton fun ⟨_, _⟩ => decidable_of_iff' _ mem_iff
end Membership
@[simp]
theorem mem_map {f : α → β} {b : β} {z : Sym2 α} : b ∈ Sym2.map f z ↔ ∃ a, a ∈ z ∧ f a = b := by
induction' z with x y
simp only [map_pair_eq, mem_iff, exists_eq_or_imp, exists_eq_left]
aesop
@[congr]
theorem map_congr {f g : α → β} {s : Sym2 α} (h : ∀ x ∈ s, f x = g x) : map f s = map g s := by
ext y
simp only [mem_map]
constructor <;>
· rintro ⟨w, hw, rfl⟩
exact ⟨w, hw, by simp [hw, h]⟩
/-- Note: `Sym2.map_id` will not simplify `Sym2.map id z` due to `Sym2.map_congr`. -/
@[simp]
theorem map_id' : (map fun x : α => x) = id :=
map_id
/-! ### Diagonal -/
variable {e : Sym2 α} {f : α → β}
/-- A type `α` is naturally included in the diagonal of `α × α`, and this function gives the image
of this diagonal in `Sym2 α`.
-/
def diag (x : α) : Sym2 α := s(x, x)
theorem diag_injective : Function.Injective (Sym2.diag : α → Sym2 α) := fun x y h => by
cases Sym2.exact h <;> rfl
/-- A predicate for testing whether an element of `Sym2 α` is on the diagonal.
-/
def IsDiag : Sym2 α → Prop :=
lift ⟨Eq, fun _ _ => propext eq_comm⟩
theorem mk_isDiag_iff {x y : α} : IsDiag s(x, y) ↔ x = y :=
Iff.rfl
@[simp]
theorem isDiag_iff_proj_eq (z : α × α) : IsDiag (Sym2.mk z) ↔ z.1 = z.2 :=
Prod.recOn z fun _ _ => mk_isDiag_iff
protected lemma IsDiag.map : e.IsDiag → (e.map f).IsDiag := Sym2.ind (fun _ _ ↦ congr_arg f) e
lemma isDiag_map (hf : Injective f) : (e.map f).IsDiag ↔ e.IsDiag :=
Sym2.ind (fun _ _ ↦ hf.eq_iff) e
@[simp]
theorem diag_isDiag (a : α) : IsDiag (diag a) :=
Eq.refl a
theorem IsDiag.mem_range_diag {z : Sym2 α} : IsDiag z → z ∈ Set.range (@diag α) := by
induction' z with x y
rintro (rfl : x = y)
exact ⟨_, rfl⟩
theorem isDiag_iff_mem_range_diag (z : Sym2 α) : IsDiag z ↔ z ∈ Set.range (@diag α) :=
⟨IsDiag.mem_range_diag, fun ⟨i, hi⟩ => hi ▸ diag_isDiag i⟩
instance IsDiag.decidablePred (α : Type u) [DecidableEq α] : DecidablePred (@IsDiag α) :=
fun z => z.recOnSubsingleton fun a => decidable_of_iff' _ (isDiag_iff_proj_eq a)
theorem other_ne {a : α} {z : Sym2 α} (hd : ¬IsDiag z) (h : a ∈ z) : Mem.other h ≠ a := by
contrapose! hd
have h' := Sym2.other_spec h
rw [hd] at h'
rw [← h']
simp
section Relations
/-! ### Declarations about symmetric relations -/
variable {r : α → α → Prop}
/-- Symmetric relations define a set on `Sym2 α` by taking all those pairs
of elements that are related.
-/
def fromRel (sym : Symmetric r) : Set (Sym2 α) :=
setOf (lift ⟨r, fun _ _ => propext ⟨(sym ·), (sym ·)⟩⟩)
@[simp]
theorem fromRel_proj_prop {sym : Symmetric r} {z : α × α} : Sym2.mk z ∈ fromRel sym ↔ r z.1 z.2 :=
Iff.rfl
theorem fromRel_prop {sym : Symmetric r} {a b : α} : s(a, b) ∈ fromRel sym ↔ r a b :=
Iff.rfl
theorem fromRel_bot : fromRel (fun (x y : α) z => z : Symmetric ⊥) = ∅ := by
apply Set.eq_empty_of_forall_not_mem fun e => _
apply Sym2.ind
simp [-Set.bot_eq_empty, Prop.bot_eq_false]
theorem fromRel_top : fromRel (fun (x y : α) z => z : Symmetric ⊤) = Set.univ := by
apply Set.eq_univ_of_forall fun e => _
apply Sym2.ind
simp [-Set.top_eq_univ, Prop.top_eq_true]
theorem fromRel_ne : fromRel (fun (x y : α) z => z.symm : Symmetric Ne) = {z | ¬IsDiag z} := by
ext z; exact z.ind (by simp)
theorem fromRel_irreflexive {sym : Symmetric r} :
Irreflexive r ↔ ∀ {z}, z ∈ fromRel sym → ¬IsDiag z :=
{ mp := by intro h; apply Sym2.ind; aesop
mpr := fun h x hr => h (fromRel_prop.mpr hr) rfl }
theorem mem_fromRel_irrefl_other_ne {sym : Symmetric r} (irrefl : Irreflexive r) {a : α}
{z : Sym2 α} (hz : z ∈ fromRel sym) (h : a ∈ z) : Mem.other h ≠ a :=
other_ne (fromRel_irreflexive.mp irrefl hz) h
instance fromRel.decidablePred (sym : Symmetric r) [h : DecidableRel r] :
DecidablePred (· ∈ Sym2.fromRel sym) := fun z => z.recOnSubsingleton fun _ => h _ _
/-- The inverse to `Sym2.fromRel`. Given a set on `Sym2 α`, give a symmetric relation on `α`
(see `Sym2.toRel_symmetric`). -/
def ToRel (s : Set (Sym2 α)) (x y : α) : Prop :=
s(x, y) ∈ s
@[simp]
theorem toRel_prop (s : Set (Sym2 α)) (x y : α) : ToRel s x y ↔ s(x, y) ∈ s :=
Iff.rfl
theorem toRel_symmetric (s : Set (Sym2 α)) : Symmetric (ToRel s) := fun x y => by simp [eq_swap]
theorem toRel_fromRel (sym : Symmetric r) : ToRel (fromRel sym) = r :=
rfl
theorem fromRel_toRel (s : Set (Sym2 α)) : fromRel (toRel_symmetric s) = s :=
Set.ext fun z => Sym2.ind (fun _ _ => Iff.rfl) z
end Relations
section SymEquiv
/-! ### Equivalence to the second symmetric power -/
attribute [local instance] Vector.Perm.isSetoid
private def fromVector : Vector α 2 → α × α
| ⟨[a, b], _⟩ => (a, b)
private theorem perm_card_two_iff {a₁ b₁ a₂ b₂ : α} :
[a₁, b₁].Perm [a₂, b₂] ↔ a₁ = a₂ ∧ b₁ = b₂ ∨ a₁ = b₂ ∧ b₁ = a₂ :=
{ mp := by
simp only [← Multiset.coe_eq_coe, ← Multiset.cons_coe, Multiset.coe_nil, Multiset.cons_zero,
Multiset.cons_eq_cons, Multiset.singleton_inj, ne_eq, Multiset.singleton_eq_cons_iff,
exists_eq_right_right, and_true]
tauto
mpr := fun
| .inl ⟨h₁, h₂⟩ | .inr ⟨h₁, h₂⟩ => by
rw [h₁, h₂]
first | done | apply List.Perm.swap'; rfl }
/-- The symmetric square is equivalent to length-2 vectors up to permutations. -/
def sym2EquivSym' : Equiv (Sym2 α) (Sym' α 2) where
toFun :=
Quot.map (fun x : α × α => ⟨[x.1, x.2], rfl⟩)
(by
rintro _ _ ⟨_⟩
· constructor; apply List.Perm.refl
apply List.Perm.swap'
rfl)
invFun :=
Quot.map fromVector
(by
rintro ⟨x, hx⟩ ⟨y, hy⟩ h
cases' x with _ x; · simp at hx
cases' x with _ x; · simp at hx
cases' x with _ x; swap
· exfalso
simp at hx
cases' y with _ y; · simp at hy
cases' y with _ y; · simp at hy
cases' y with _ y; swap
· exfalso
simp at hy
rcases perm_card_two_iff.mp h with (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩)
· constructor
apply Sym2.Rel.swap)
left_inv := by apply Sym2.ind; aesop (add norm unfold [Sym2.fromVector])
right_inv x := by
refine x.recOnSubsingleton fun x => ?_
cases' x with x hx
cases' x with _ x
· simp at hx
cases' x with _ x
· simp at hx
cases' x with _ x
swap
· exfalso
simp at hx
rfl
/-- The symmetric square is equivalent to the second symmetric power. -/
def equivSym (α : Type*) : Sym2 α ≃ Sym α 2 :=
Equiv.trans sym2EquivSym' symEquivSym'.symm
/-- The symmetric square is equivalent to multisets of cardinality
two. (This is currently a synonym for `equivSym`, but it's provided
in case the definition for `Sym` changes.) -/
def equivMultiset (α : Type*) : Sym2 α ≃ { s : Multiset α // Multiset.card s = 2 } :=
equivSym α
end SymEquiv
section Decidable
/-- Given `[DecidableEq α]` and `[Fintype α]`, the following instance gives `Fintype (Sym2 α)`.
-/
instance instDecidableRel [DecidableEq α] : DecidableRel (Rel α) :=
fun _ _ => decidable_of_iff' _ rel_iff
section
attribute [local instance] Sym2.Rel.setoid
instance instDecidableRel' [DecidableEq α] : DecidableRel (HasEquiv.Equiv (α := α × α)) :=
instDecidableRel
end
instance [DecidableEq α] : DecidableEq (Sym2 α) :=
inferInstanceAs <| DecidableEq (Quotient (Sym2.Rel.setoid α))
/-! ### The other element of an element of the symmetric square -/
/--
A function that gives the other element of a pair given one of the elements. Used in `Mem.other'`.
-/
@[aesop norm unfold (rule_sets := [Sym2])]
private def pairOther [DecidableEq α] (a : α) (z : α × α) : α :=
if a = z.1 then z.2 else z.1
/-- Get the other element of the unordered pair using the decidable equality.
This is the computable version of `Mem.other`. -/
@[aesop norm unfold (rule_sets := [Sym2])]
def Mem.other' [DecidableEq α] {a : α} {z : Sym2 α} (h : a ∈ z) : α :=
Sym2.rec (fun s _ => pairOther a s) (by
clear h z
intro x y h
ext hy
convert_to Sym2.pairOther a x = _
· have : ∀ {c e h}, @Eq.ndrec (Sym2 α) (Sym2.mk x)
(fun x => a ∈ x → α) (fun _ => Sym2.pairOther a x) c e h = Sym2.pairOther a x := by
intro _ e _; subst e; rfl
apply this
· rw [mem_iff] at hy
aesop (add norm unfold [pairOther]))
z h
@[simp]
theorem other_spec' [DecidableEq α] {a : α} {z : Sym2 α} (h : a ∈ z) : s(a, Mem.other' h) = z := by
induction z
have h' := mem_iff.mp h
aesop (add norm unfold [Sym2.rec, Quot.rec]) (rule_sets := [Sym2])
@[simp]
theorem other_eq_other' [DecidableEq α] {a : α} {z : Sym2 α} (h : a ∈ z) :
Mem.other h = Mem.other' h := by rw [← congr_right, other_spec' h, other_spec]
theorem other_mem' [DecidableEq α] {a : α} {z : Sym2 α} (h : a ∈ z) : Mem.other' h ∈ z := by
rw [← other_eq_other']
exact other_mem h
theorem other_invol' [DecidableEq α] {a : α} {z : Sym2 α} (ha : a ∈ z) (hb : Mem.other' ha ∈ z) :
Mem.other' hb = a := by
induction z
aesop (rule_sets := [Sym2]) (add norm unfold [Sym2.rec, Quot.rec])
theorem other_invol {a : α} {z : Sym2 α} (ha : a ∈ z) (hb : Mem.other ha ∈ z) :
Mem.other hb = a := by
classical
rw [other_eq_other'] at hb ⊢
convert other_invol' ha hb using 2
apply other_eq_other'
theorem filter_image_mk_isDiag [DecidableEq α] (s : Finset α) :
((s ×ˢ s).image Sym2.mk).filter IsDiag = s.diag.image Sym2.mk := by
ext z
induction' z
simp only [mem_image, mem_diag, exists_prop, mem_filter, Prod.exists, mem_product]
constructor
· rintro ⟨⟨a, b, ⟨ha, hb⟩, h⟩, hab⟩
rw [← h, Sym2.mk_isDiag_iff] at hab
exact ⟨a, b, ⟨ha, hab⟩, h⟩
· rintro ⟨a, b, ⟨ha, rfl⟩, h⟩
rw [← h]
exact ⟨⟨a, a, ⟨ha, ha⟩, rfl⟩, rfl⟩
theorem filter_image_mk_not_isDiag [DecidableEq α] (s : Finset α) :
(((s ×ˢ s).image Sym2.mk).filter fun a : Sym2 α => ¬a.IsDiag) =
s.offDiag.image Sym2.mk := by
ext z
induction z
simp only [mem_image, mem_offDiag, mem_filter, Prod.exists, mem_product]
constructor
· rintro ⟨⟨a, b, ⟨ha, hb⟩, h⟩, hab⟩
rw [← h, Sym2.mk_isDiag_iff] at hab
exact ⟨a, b, ⟨ha, hb, hab⟩, h⟩
· rintro ⟨a, b, ⟨ha, hb, hab⟩, h⟩
rw [Ne, ← Sym2.mk_isDiag_iff, h] at hab
exact ⟨⟨a, b, ⟨ha, hb⟩, h⟩, hab⟩
end Decidable
instance [Subsingleton α] : Subsingleton (Sym2 α) :=
(equivSym α).injective.subsingleton
instance [Unique α] : Unique (Sym2 α) :=
Unique.mk' _
instance [IsEmpty α] : IsEmpty (Sym2 α) :=
(equivSym α).isEmpty
instance [Nontrivial α] : Nontrivial (Sym2 α) :=
diag_injective.nontrivial
-- TODO: use a sort order if available, https://github.com/leanprover-community/mathlib/issues/18166
unsafe instance [Repr α] : Repr (Sym2 α) where
reprPrec s _ := f!"s({repr s.unquot.1}, {repr s.unquot.2})"
end Sym2
|
Data\Sym\Sym2\Init.lean | /-
Copyright (c) 2023 Jannis Limperg. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jannis Limperg
-/
import Aesop
/-!
# Sym2 Rule Set
This module defines the `Sym2` Aesop rule set. Aesop rule sets only become
visible once the file in which they're declared is imported, so we must put this
declaration into its own file.
-/
declare_aesop_rule_sets [Sym2]
|
Data\Sym\Sym2\Order.lean | /-
Copyright (c) 2024 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Data.Sym.Sym2
import Mathlib.Order.Lattice
/-!
# Sorting the elements of `Sym2`
This files provides `Sym2.sortEquiv`, the forward direction of which is somewhat analogous to
`Multiset.sort`.
-/
namespace Sym2
variable {α}
/-- The supremum of the two elements. -/
def sup [SemilatticeSup α] (x : Sym2 α) : α := Sym2.lift ⟨(· ⊔ ·), sup_comm⟩ x
@[simp] theorem sup_mk [SemilatticeSup α] (a b : α) : s(a, b).sup = a ⊔ b := rfl
/-- The infimum of the two elements. -/
def inf [SemilatticeInf α] (x : Sym2 α) : α := Sym2.lift ⟨(· ⊓ ·), inf_comm⟩ x
@[simp] theorem inf_mk [SemilatticeInf α] (a b : α) : s(a, b).inf = a ⊓ b := rfl
protected theorem inf_le_sup [Lattice α] (s : Sym2 α) : s.inf ≤ s.sup := by
cases s using Sym2.ind; simp [_root_.inf_le_sup]
/-- In a linear order, symmetric squares are canonically identified with ordered pairs. -/
@[simps!]
def sortEquiv [LinearOrder α] : Sym2 α ≃ { p : α × α // p.1 ≤ p.2 } where
toFun s := ⟨(s.inf, s.sup), Sym2.inf_le_sup _⟩
invFun p := Sym2.mk p
left_inv := Sym2.ind fun a b => mk_eq_mk_iff.mpr <| by
cases le_total a b with
| inl h => simp [h]
| inr h => simp [h]
right_inv := Subtype.rec <| Prod.rec fun x y hxy =>
Subtype.ext <| Prod.ext (by simp [hxy]) (by simp [hxy])
end Sym2
|
Data\Tree\Basic.lean | /-
Copyright (c) 2019 mathlib community. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Wojciech Nawrocki
-/
import Batteries.Data.RBMap.Basic
import Mathlib.Data.Nat.Notation
import Mathlib.Tactic.TypeStar
import Mathlib.Util.CompileInductive
/-!
# Binary tree
Provides binary tree storage for values of any type, with O(lg n) retrieval.
See also `Lean.Data.RBTree` for red-black trees - this version allows more operations
to be defined and is better suited for in-kernel computation.
We also specialize for `Tree Unit`, which is a binary tree without any
additional data. We provide the notation `a △ b` for making a `Tree Unit` with children
`a` and `b`.
## TODO
Implement a `Traversable` instance for `Tree`.
## References
<https://leanprover-community.github.io/archive/stream/113488-general/topic/tactic.20question.html>
-/
/-- A binary tree with values stored in non-leaf nodes. -/
inductive Tree.{u} (α : Type u) : Type u
| nil : Tree α
| node : α → Tree α → Tree α → Tree α
deriving DecidableEq, Repr -- Porting note: Removed `has_reflect`, added `Repr`.
namespace Tree
universe u
variable {α : Type u}
-- Porting note: replaced with `deriving Repr` which builds a better instance anyway
instance : Inhabited (Tree α) :=
⟨nil⟩
open Batteries (RBNode)
/-- Makes a `Tree α` out of a red-black tree. -/
def ofRBNode : RBNode α → Tree α
| RBNode.nil => nil
| RBNode.node _color l key r => node key (ofRBNode l) (ofRBNode r)
/-- Apply a function to each value in the tree. This is the `map` function for the `Tree` functor.
-/
def map {β} (f : α → β) : Tree α → Tree β
| nil => nil
| node a l r => node (f a) (map f l) (map f r)
/-- The number of internal nodes (i.e. not including leaves) of a binary tree -/
@[simp]
def numNodes : Tree α → ℕ
| nil => 0
| node _ a b => a.numNodes + b.numNodes + 1
/-- The number of leaves of a binary tree -/
@[simp]
def numLeaves : Tree α → ℕ
| nil => 1
| node _ a b => a.numLeaves + b.numLeaves
/-- The height - length of the longest path from the root - of a binary tree -/
@[simp]
def height : Tree α → ℕ
| nil => 0
| node _ a b => max a.height b.height + 1
theorem numLeaves_eq_numNodes_succ (x : Tree α) : x.numLeaves = x.numNodes + 1 := by
induction x <;> simp [*, Nat.add_comm, Nat.add_assoc, Nat.add_left_comm]
theorem numLeaves_pos (x : Tree α) : 0 < x.numLeaves := by
rw [numLeaves_eq_numNodes_succ]
exact x.numNodes.zero_lt_succ
theorem height_le_numNodes : ∀ x : Tree α, x.height ≤ x.numNodes
| nil => Nat.le_refl _
| node _ a b => Nat.succ_le_succ <|
Nat.max_le.2 ⟨Nat.le_trans a.height_le_numNodes <| a.numNodes.le_add_right _,
Nat.le_trans b.height_le_numNodes <| b.numNodes.le_add_left _⟩
/-- The left child of the tree, or `nil` if the tree is `nil` -/
@[simp]
def left : Tree α → Tree α
| nil => nil
| node _ l _r => l
/-- The right child of the tree, or `nil` if the tree is `nil` -/
@[simp]
def right : Tree α → Tree α
| nil => nil
| node _ _l r => r
/-- A node with `Unit` data -/
scoped infixr:65 " △ " => Tree.node ()
-- Porting note: workaround for leanprover/lean4#2049
compile_inductive% Tree
@[elab_as_elim]
def unitRecOn {motive : Tree Unit → Sort*} (t : Tree Unit) (base : motive nil)
(ind : ∀ x y, motive x → motive y → motive (x △ y)) : motive t :=
-- Porting note: Old proof was `t.recOn base fun u => u.recOn ind` but
-- structure eta makes it unnecessary (https://github.com/leanprover/lean4/issues/777).
t.recOn base fun _u => ind
theorem left_node_right_eq_self : ∀ {x : Tree Unit} (_hx : x ≠ nil), x.left △ x.right = x
| nil, h => by trivial
| node a l r, _ => rfl -- Porting note: `a △ b` no longer works in pattern matching
end Tree
|
Data\Tree\Get.lean | /-
Copyright (c) 2019 mathlib community. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Wojciech Nawrocki
-/
import Mathlib.Data.Num.Basic
import Mathlib.Data.Tree.Basic
/-!
# Binary tree get operation
In this file we define `Tree.indexOf`, `Tree.get`, and `Tree.getOrElse`.
These definitions were moved from the main file to avoid a dependency on `Num`.
## References
<https://leanprover-community.github.io/archive/stream/113488-general/topic/tactic.20question.html#170999997>
-/
namespace Tree
variable {α : Type*}
/-- Finds the index of an element in the tree assuming the tree has been
constructed according to the provided decidable order on its elements.
If it hasn't, the result will be incorrect. If it has, but the element
is not in the tree, returns none. -/
def indexOf (lt : α → α → Prop) [DecidableRel lt] (x : α) : Tree α → Option PosNum
| nil => none
| node a t₁ t₂ =>
match cmpUsing lt x a with
| Ordering.lt => PosNum.bit0 <$> indexOf lt x t₁
| Ordering.eq => some PosNum.one
| Ordering.gt => PosNum.bit1 <$> indexOf lt x t₂
/-- Retrieves an element uniquely determined by a `PosNum` from the tree,
taking the following path to get to the element:
- `bit0` - go to left child
- `bit1` - go to right child
- `PosNum.one` - retrieve from here -/
def get : PosNum → Tree α → Option α
| _, nil => none
| PosNum.one, node a _t₁ _t₂ => some a
| PosNum.bit0 n, node _a t₁ _t₂ => t₁.get n
| PosNum.bit1 n, node _a _t₁ t₂ => t₂.get n
/-- Retrieves an element from the tree, or the provided default value
if the index is invalid. See `Tree.get`. -/
def getOrElse (n : PosNum) (t : Tree α) (v : α) : α :=
(t.get n).getD v
end Tree
|
Data\Vector\Basic.lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Algebra.BigOperators.Group.List
import Mathlib.Data.Vector.Defs
import Mathlib.Data.List.Nodup
import Mathlib.Data.List.OfFn
import Mathlib.Data.List.InsertNth
import Mathlib.Control.Applicative
import Mathlib.Control.Traversable.Basic
/-!
# Additional theorems and definitions about the `Vector` type
This file introduces the infix notation `::ᵥ` for `Vector.cons`.
-/
set_option autoImplicit true
universe u
variable {n : ℕ}
namespace Mathlib
namespace Vector
variable {α : Type*}
@[inherit_doc]
infixr:67 " ::ᵥ " => Vector.cons
attribute [simp] head_cons tail_cons
instance [Inhabited α] : Inhabited (Vector α n) :=
⟨ofFn default⟩
theorem toList_injective : Function.Injective (@toList α n) :=
Subtype.val_injective
/-- Two `v w : Vector α n` are equal iff they are equal at every single index. -/
@[ext]
theorem ext : ∀ {v w : Vector α n} (_ : ∀ m : Fin n, Vector.get v m = Vector.get w m), v = w
| ⟨v, hv⟩, ⟨w, hw⟩, h =>
Subtype.eq (List.ext_get (by rw [hv, hw]) fun m hm _ => h ⟨m, hv ▸ hm⟩)
/-- The empty `Vector` is a `Subsingleton`. -/
instance zero_subsingleton : Subsingleton (Vector α 0) :=
⟨fun _ _ => Vector.ext fun m => Fin.elim0 m⟩
@[simp]
theorem cons_val (a : α) : ∀ v : Vector α n, (a ::ᵥ v).val = a :: v.val
| ⟨_, _⟩ => rfl
theorem eq_cons_iff (a : α) (v : Vector α n.succ) (v' : Vector α n) :
v = a ::ᵥ v' ↔ v.head = a ∧ v.tail = v' :=
⟨fun h => h.symm ▸ ⟨head_cons a v', tail_cons a v'⟩, fun h =>
_root_.trans (cons_head_tail v).symm (by rw [h.1, h.2])⟩
theorem ne_cons_iff (a : α) (v : Vector α n.succ) (v' : Vector α n) :
v ≠ a ::ᵥ v' ↔ v.head ≠ a ∨ v.tail ≠ v' := by rw [Ne, eq_cons_iff a v v', not_and_or]
theorem exists_eq_cons (v : Vector α n.succ) : ∃ (a : α) (as : Vector α n), v = a ::ᵥ as :=
⟨v.head, v.tail, (eq_cons_iff v.head v v.tail).2 ⟨rfl, rfl⟩⟩
@[simp]
theorem toList_ofFn : ∀ {n} (f : Fin n → α), toList (ofFn f) = List.ofFn f
| 0, f => by rw [ofFn, List.ofFn_zero, toList, nil]
| n + 1, f => by rw [ofFn, List.ofFn_succ, toList_cons, toList_ofFn]
@[simp]
theorem mk_toList : ∀ (v : Vector α n) (h), (⟨toList v, h⟩ : Vector α n) = v
| ⟨_, _⟩, _ => rfl
@[simp] theorem length_val (v : Vector α n) : v.val.length = n := v.2
-- Porting note: not used in mathlib and coercions done differently in Lean 4
-- @[simp]
-- theorem length_coe (v : Vector α n) :
-- ((coe : { l : List α // l.length = n } → List α) v).length = n :=
-- v.2
@[simp]
theorem toList_map {β : Type*} (v : Vector α n) (f : α → β) :
(v.map f).toList = v.toList.map f := by cases v; rfl
@[simp]
theorem head_map {β : Type*} (v : Vector α (n + 1)) (f : α → β) : (v.map f).head = f v.head := by
obtain ⟨a, v', h⟩ := Vector.exists_eq_cons v
rw [h, map_cons, head_cons, head_cons]
@[simp]
theorem tail_map {β : Type*} (v : Vector α (n + 1)) (f : α → β) :
(v.map f).tail = v.tail.map f := by
obtain ⟨a, v', h⟩ := Vector.exists_eq_cons v
rw [h, map_cons, tail_cons, tail_cons]
theorem get_eq_get (v : Vector α n) (i : Fin n) :
v.get i = v.toList.get (Fin.cast v.toList_length.symm i) :=
rfl
@[simp]
theorem get_replicate (a : α) (i : Fin n) : (Vector.replicate n a).get i = a := by
apply List.getElem_replicate
@[simp]
theorem get_map {β : Type*} (v : Vector α n) (f : α → β) (i : Fin n) :
(v.map f).get i = f (v.get i) := by
cases v; simp [Vector.map, get_eq_get]
@[simp]
theorem map₂_nil (f : α → β → γ) : Vector.map₂ f nil nil = nil :=
rfl
@[simp]
theorem map₂_cons (hd₁ : α) (tl₁ : Vector α n) (hd₂ : β) (tl₂ : Vector β n) (f : α → β → γ) :
Vector.map₂ f (hd₁ ::ᵥ tl₁) (hd₂ ::ᵥ tl₂) = f hd₁ hd₂ ::ᵥ (Vector.map₂ f tl₁ tl₂) :=
rfl
@[simp]
theorem get_ofFn {n} (f : Fin n → α) (i) : get (ofFn f) i = f i := by
conv_rhs => erw [← List.get_ofFn f ⟨i, by simp⟩]
simp only [get_eq_get]
congr <;> simp [Fin.heq_ext_iff]
@[simp]
theorem ofFn_get (v : Vector α n) : ofFn (get v) = v := by
rcases v with ⟨l, rfl⟩
apply toList_injective
dsimp
simpa only [toList_ofFn] using List.ofFn_get _
/-- The natural equivalence between length-`n` vectors and functions from `Fin n`. -/
def _root_.Equiv.vectorEquivFin (α : Type*) (n : ℕ) : Vector α n ≃ (Fin n → α) :=
⟨Vector.get, Vector.ofFn, Vector.ofFn_get, fun f => funext <| Vector.get_ofFn f⟩
theorem get_tail (x : Vector α n) (i) : x.tail.get i = x.get ⟨i.1 + 1, by omega⟩ := by
cases' i with i ih; dsimp
rcases x with ⟨_ | _, h⟩ <;> try rfl
rw [List.length] at h
rw [← h] at ih
contradiction
@[simp]
theorem get_tail_succ : ∀ (v : Vector α n.succ) (i : Fin n), get (tail v) i = get v i.succ
| ⟨a :: l, e⟩, ⟨i, h⟩ => by simp [get_eq_get]; rfl
@[simp]
theorem tail_val : ∀ v : Vector α n.succ, v.tail.val = v.val.tail
| ⟨_ :: _, _⟩ => rfl
/-- The `tail` of a `nil` vector is `nil`. -/
@[simp]
theorem tail_nil : (@nil α).tail = nil :=
rfl
/-- The `tail` of a vector made up of one element is `nil`. -/
@[simp]
theorem singleton_tail : ∀ (v : Vector α 1), v.tail = Vector.nil
| ⟨[_], _⟩ => rfl
@[simp]
theorem tail_ofFn {n : ℕ} (f : Fin n.succ → α) : tail (ofFn f) = ofFn fun i => f i.succ :=
(ofFn_get _).symm.trans <| by
congr
funext i
rw [get_tail, get_ofFn]
rfl
@[simp]
theorem toList_empty (v : Vector α 0) : v.toList = [] :=
List.length_eq_zero.mp v.2
/-- The list that makes up a `Vector` made up of a single element,
retrieved via `toList`, is equal to the list of that single element. -/
@[simp]
theorem toList_singleton (v : Vector α 1) : v.toList = [v.head] := by
rw [← v.cons_head_tail]
simp only [toList_cons, toList_nil, head_cons, eq_self_iff_true, and_self_iff, singleton_tail]
@[simp]
theorem empty_toList_eq_ff (v : Vector α (n + 1)) : v.toList.isEmpty = false :=
match v with
| ⟨_ :: _, _⟩ => rfl
theorem not_empty_toList (v : Vector α (n + 1)) : ¬v.toList.isEmpty := by
simp only [empty_toList_eq_ff, Bool.coe_sort_false, not_false_iff]
/-- Mapping under `id` does not change a vector. -/
@[simp]
theorem map_id {n : ℕ} (v : Vector α n) : Vector.map id v = v :=
Vector.eq _ _ (by simp only [List.map_id, Vector.toList_map])
theorem nodup_iff_injective_get {v : Vector α n} : v.toList.Nodup ↔ Function.Injective v.get := by
cases' v with l hl
subst hl
exact List.nodup_iff_injective_get
theorem head?_toList : ∀ v : Vector α n.succ, (toList v).head? = some (head v)
| ⟨_ :: _, _⟩ => rfl
/-- Reverse a vector. -/
def reverse (v : Vector α n) : Vector α n :=
⟨v.toList.reverse, by simp⟩
/-- The `List` of a vector after a `reverse`, retrieved by `toList` is equal
to the `List.reverse` after retrieving a vector's `toList`. -/
theorem toList_reverse {v : Vector α n} : v.reverse.toList = v.toList.reverse :=
rfl
@[simp]
theorem reverse_reverse {v : Vector α n} : v.reverse.reverse = v := by
cases v
simp [Vector.reverse]
@[simp]
theorem get_zero : ∀ v : Vector α n.succ, get v 0 = head v
| ⟨_ :: _, _⟩ => rfl
@[simp]
theorem head_ofFn {n : ℕ} (f : Fin n.succ → α) : head (ofFn f) = f 0 := by
rw [← get_zero, get_ofFn]
--@[simp] Porting note (#10618): simp can prove it
theorem get_cons_zero (a : α) (v : Vector α n) : get (a ::ᵥ v) 0 = a := by simp [get_zero]
/-- Accessing the nth element of a vector made up
of one element `x : α` is `x` itself. -/
@[simp]
theorem get_cons_nil : ∀ {ix : Fin 1} (x : α), get (x ::ᵥ nil) ix = x
| ⟨0, _⟩, _ => rfl
@[simp]
theorem get_cons_succ (a : α) (v : Vector α n) (i : Fin n) : get (a ::ᵥ v) i.succ = get v i := by
rw [← get_tail_succ, tail_cons]
/-- The last element of a `Vector`, given that the vector is at least one element. -/
def last (v : Vector α (n + 1)) : α :=
v.get (Fin.last n)
/-- The last element of a `Vector`, given that the vector is at least one element. -/
theorem last_def {v : Vector α (n + 1)} : v.last = v.get (Fin.last n) :=
rfl
/-- The `last` element of a vector is the `head` of the `reverse` vector. -/
theorem reverse_get_zero {v : Vector α (n + 1)} : v.reverse.head = v.last := by
rw [← get_zero, last_def, get_eq_get, get_eq_get]
simp_rw [toList_reverse]
rw [List.get_eq_getElem, List.get_eq_getElem, ← Option.some_inj, Fin.cast, Fin.cast,
← List.getElem?_eq_getElem, ← List.getElem?_eq_getElem, List.getElem?_reverse]
· congr
simp
· simp
section Scan
variable {β : Type*}
variable (f : β → α → β) (b : β)
variable (v : Vector α n)
/-- Construct a `Vector β (n + 1)` from a `Vector α n` by scanning `f : β → α → β`
from the "left", that is, from 0 to `Fin.last n`, using `b : β` as the starting value.
-/
def scanl : Vector β (n + 1) :=
⟨List.scanl f b v.toList, by rw [List.length_scanl, toList_length]⟩
/-- Providing an empty vector to `scanl` gives the starting value `b : β`. -/
@[simp]
theorem scanl_nil : scanl f b nil = b ::ᵥ nil :=
rfl
/-- The recursive step of `scanl` splits a vector `x ::ᵥ v : Vector α (n + 1)`
into the provided starting value `b : β` and the recursed `scanl`
`f b x : β` as the starting value.
This lemma is the `cons` version of `scanl_get`.
-/
@[simp]
theorem scanl_cons (x : α) : scanl f b (x ::ᵥ v) = b ::ᵥ scanl f (f b x) v := by
simp only [scanl, toList_cons, List.scanl]; dsimp
simp only [cons]; rfl
/-- The underlying `List` of a `Vector` after a `scanl` is the `List.scanl`
of the underlying `List` of the original `Vector`.
-/
@[simp]
theorem scanl_val : ∀ {v : Vector α n}, (scanl f b v).val = List.scanl f b v.val
| _ => rfl
/-- The `toList` of a `Vector` after a `scanl` is the `List.scanl`
of the `toList` of the original `Vector`.
-/
@[simp]
theorem toList_scanl : (scanl f b v).toList = List.scanl f b v.toList :=
rfl
/-- The recursive step of `scanl` splits a vector made up of a single element
`x ::ᵥ nil : Vector α 1` into a `Vector` of the provided starting value `b : β`
and the mapped `f b x : β` as the last value.
-/
@[simp]
theorem scanl_singleton (v : Vector α 1) : scanl f b v = b ::ᵥ f b v.head ::ᵥ nil := by
rw [← cons_head_tail v]
simp only [scanl_cons, scanl_nil, head_cons, singleton_tail]
/-- The first element of `scanl` of a vector `v : Vector α n`,
retrieved via `head`, is the starting value `b : β`.
-/
@[simp]
theorem scanl_head : (scanl f b v).head = b := by
cases n
· have : v = nil := by simp only [Nat.zero_eq, eq_iff_true_of_subsingleton]
simp only [this, scanl_nil, head_cons]
· rw [← cons_head_tail v]
simp only [← get_zero, get_eq_get, toList_scanl, toList_cons, List.scanl, Fin.val_zero,
List.get]
/-- For an index `i : Fin n`, the nth element of `scanl` of a
vector `v : Vector α n` at `i.succ`, is equal to the application
function `f : β → α → β` of the `castSucc i` element of
`scanl f b v` and `get v i`.
This lemma is the `get` version of `scanl_cons`.
-/
@[simp]
theorem scanl_get (i : Fin n) :
(scanl f b v).get i.succ = f ((scanl f b v).get (Fin.castSucc i)) (v.get i) := by
cases' n with n
· exact i.elim0
induction' n with n hn generalizing b
· have i0 : i = 0 := Fin.eq_zero _
simp [scanl_singleton, i0, get_zero]; simp [get_eq_get, List.get]
· rw [← cons_head_tail v, scanl_cons, get_cons_succ]
refine Fin.cases ?_ ?_ i
· simp only [get_zero, scanl_head, Fin.castSucc_zero, head_cons]
· intro i'
simp only [hn, Fin.castSucc_fin_succ, get_cons_succ]
end Scan
/-- Monadic analog of `Vector.ofFn`.
Given a monadic function on `Fin n`, return a `Vector α n` inside the monad. -/
def mOfFn {m} [Monad m] {α : Type u} : ∀ {n}, (Fin n → m α) → m (Vector α n)
| 0, _ => pure nil
| _ + 1, f => do
let a ← f 0
let v ← mOfFn fun i => f i.succ
pure (a ::ᵥ v)
theorem mOfFn_pure {m} [Monad m] [LawfulMonad m] {α} :
∀ {n} (f : Fin n → α), (@mOfFn m _ _ _ fun i => pure (f i)) = pure (ofFn f)
| 0, f => rfl
| n + 1, f => by
rw [mOfFn, @mOfFn_pure m _ _ _ n _, ofFn]
simp
/-- Apply a monadic function to each component of a vector,
returning a vector inside the monad. -/
def mmap {m} [Monad m] {α} {β : Type u} (f : α → m β) : ∀ {n}, Vector α n → m (Vector β n)
| 0, _ => pure nil
| _ + 1, xs => do
let h' ← f xs.head
let t' ← mmap f xs.tail
pure (h' ::ᵥ t')
@[simp]
theorem mmap_nil {m} [Monad m] {α β} (f : α → m β) : mmap f nil = pure nil :=
rfl
@[simp]
theorem mmap_cons {m} [Monad m] {α β} (f : α → m β) (a) :
∀ {n} (v : Vector α n),
mmap f (a ::ᵥ v) = do
let h' ← f a
let t' ← mmap f v
pure (h' ::ᵥ t')
| _, ⟨_, rfl⟩ => rfl
/--
Define `C v` by induction on `v : Vector α n`.
This function has two arguments: `nil` handles the base case on `C nil`,
and `cons` defines the inductive step using `∀ x : α, C w → C (x ::ᵥ w)`.
It is used as the default induction principle for the `induction` tactic.
-/
@[elab_as_elim, induction_eliminator]
def inductionOn {C : ∀ {n : ℕ}, Vector α n → Sort*} {n : ℕ} (v : Vector α n)
(nil : C nil) (cons : ∀ {n : ℕ} {x : α} {w : Vector α n}, C w → C (x ::ᵥ w)) : C v := by
-- Porting note: removed `generalizing`: already generalized
induction' n with n ih
· rcases v with ⟨_ | ⟨-, -⟩, - | -⟩
exact nil
· rcases v with ⟨_ | ⟨a, v⟩, v_property⟩
cases v_property
exact cons (ih ⟨v, (add_left_inj 1).mp v_property⟩)
@[simp]
theorem inductionOn_nil {C : ∀ {n : ℕ}, Vector α n → Sort*}
(nil : C nil) (cons : ∀ {n : ℕ} {x : α} {w : Vector α n}, C w → C (x ::ᵥ w)) :
Vector.nil.inductionOn nil cons = nil :=
rfl
@[simp]
theorem inductionOn_cons {C : ∀ {n : ℕ}, Vector α n → Sort*} {n : ℕ} (x : α) (v : Vector α n)
(nil : C nil) (cons : ∀ {n : ℕ} {x : α} {w : Vector α n}, C w → C (x ::ᵥ w)) :
(x ::ᵥ v).inductionOn nil cons = cons (v.inductionOn nil cons : C v) :=
rfl
variable {β γ : Type*}
/-- Define `C v w` by induction on a pair of vectors `v : Vector α n` and `w : Vector β n`. -/
@[elab_as_elim]
def inductionOn₂ {C : ∀ {n}, Vector α n → Vector β n → Sort*}
(v : Vector α n) (w : Vector β n)
(nil : C nil nil) (cons : ∀ {n a b} {x : Vector α n} {y}, C x y → C (a ::ᵥ x) (b ::ᵥ y)) :
C v w := by
-- Porting note: removed `generalizing`: already generalized
induction' n with n ih
· rcases v with ⟨_ | ⟨-, -⟩, - | -⟩
rcases w with ⟨_ | ⟨-, -⟩, - | -⟩
exact nil
· rcases v with ⟨_ | ⟨a, v⟩, v_property⟩
cases v_property
rcases w with ⟨_ | ⟨b, w⟩, w_property⟩
cases w_property
apply @cons n _ _ ⟨v, (add_left_inj 1).mp v_property⟩ ⟨w, (add_left_inj 1).mp w_property⟩
apply ih
/-- Define `C u v w` by induction on a triplet of vectors
`u : Vector α n`, `v : Vector β n`, and `w : Vector γ b`. -/
@[elab_as_elim]
def inductionOn₃ {C : ∀ {n}, Vector α n → Vector β n → Vector γ n → Sort*}
(u : Vector α n) (v : Vector β n) (w : Vector γ n) (nil : C nil nil nil)
(cons : ∀ {n a b c} {x : Vector α n} {y z}, C x y z → C (a ::ᵥ x) (b ::ᵥ y) (c ::ᵥ z)) :
C u v w := by
-- Porting note: removed `generalizing`: already generalized
induction' n with n ih
· rcases u with ⟨_ | ⟨-, -⟩, - | -⟩
rcases v with ⟨_ | ⟨-, -⟩, - | -⟩
rcases w with ⟨_ | ⟨-, -⟩, - | -⟩
exact nil
· rcases u with ⟨_ | ⟨a, u⟩, u_property⟩
cases u_property
rcases v with ⟨_ | ⟨b, v⟩, v_property⟩
cases v_property
rcases w with ⟨_ | ⟨c, w⟩, w_property⟩
cases w_property
apply
@cons n _ _ _ ⟨u, (add_left_inj 1).mp u_property⟩ ⟨v, (add_left_inj 1).mp v_property⟩
⟨w, (add_left_inj 1).mp w_property⟩
apply ih
/-- Define `motive v` by case-analysis on `v : Vector α n`. -/
def casesOn {motive : ∀ {n}, Vector α n → Sort*} (v : Vector α m)
(nil : motive nil)
(cons : ∀ {n}, (hd : α) → (tl : Vector α n) → motive (Vector.cons hd tl)) :
motive v :=
inductionOn (C := motive) v nil @fun _ hd tl _ => cons hd tl
/-- Define `motive v₁ v₂` by case-analysis on `v₁ : Vector α n` and `v₂ : Vector β n`. -/
def casesOn₂ {motive : ∀{n}, Vector α n → Vector β n → Sort*} (v₁ : Vector α m) (v₂ : Vector β m)
(nil : motive nil nil)
(cons : ∀{n}, (x : α) → (y : β) → (xs : Vector α n) → (ys : Vector β n)
→ motive (x ::ᵥ xs) (y ::ᵥ ys)) :
motive v₁ v₂ :=
inductionOn₂ (C := motive) v₁ v₂ nil @fun _ x y xs ys _ => cons x y xs ys
/-- Define `motive v₁ v₂ v₃` by case-analysis on `v₁ : Vector α n`, `v₂ : Vector β n`, and
`v₃ : Vector γ n`. -/
def casesOn₃ {motive : ∀{n}, Vector α n → Vector β n → Vector γ n → Sort*} (v₁ : Vector α m)
(v₂ : Vector β m) (v₃ : Vector γ m) (nil : motive nil nil nil)
(cons : ∀{n}, (x : α) → (y : β) → (z : γ) → (xs : Vector α n) → (ys : Vector β n)
→ (zs : Vector γ n) → motive (x ::ᵥ xs) (y ::ᵥ ys) (z ::ᵥ zs)) :
motive v₁ v₂ v₃ :=
inductionOn₃ (C := motive) v₁ v₂ v₃ nil @fun _ x y z xs ys zs _ => cons x y z xs ys zs
/-- Cast a vector to an array. -/
def toArray : Vector α n → Array α
| ⟨xs, _⟩ => cast (by rfl) xs.toArray
section InsertNth
variable {a : α}
/-- `v.insertNth a i` inserts `a` into the vector `v` at position `i`
(and shifting later components to the right). -/
def insertNth (a : α) (i : Fin (n + 1)) (v : Vector α n) : Vector α (n + 1) :=
⟨v.1.insertNth i a, by
rw [List.length_insertNth, v.2]
rw [v.2, ← Nat.succ_le_succ_iff]
exact i.2⟩
theorem insertNth_val {i : Fin (n + 1)} {v : Vector α n} :
(v.insertNth a i).val = v.val.insertNth i.1 a :=
rfl
@[simp]
theorem eraseIdx_val {i : Fin n} : ∀ {v : Vector α n}, (eraseIdx i v).val = v.val.eraseIdx i
| _ => rfl
@[deprecated (since := "2024-05-04")] alias removeNth_val := eraseIdx_val
theorem eraseIdx_insertNth {v : Vector α n} {i : Fin (n + 1)} :
eraseIdx i (insertNth a i v) = v :=
Subtype.eq <| List.eraseIdx_insertNth i.1 v.1
@[deprecated (since := "2024-05-04")] alias removeNth_insertNth := eraseIdx_insertNth
theorem eraseIdx_insertNth' {v : Vector α (n + 1)} :
∀ {i : Fin (n + 1)} {j : Fin (n + 2)},
eraseIdx (j.succAbove i) (insertNth a j v) = insertNth a (i.predAbove j) (eraseIdx i v)
| ⟨i, hi⟩, ⟨j, hj⟩ => by
dsimp [insertNth, eraseIdx, Fin.succAbove, Fin.predAbove]
rw [Subtype.mk_eq_mk]
simp only [Fin.lt_iff_val_lt_val]
split_ifs with hij
· rcases Nat.exists_eq_succ_of_ne_zero
(Nat.pos_iff_ne_zero.1 (lt_of_le_of_lt (Nat.zero_le _) hij)) with ⟨j, rfl⟩
rw [← List.insertNth_eraseIdx_of_ge]
· simp; rfl
· simpa
· simpa [Nat.lt_succ_iff] using hij
· dsimp
rw [← List.insertNth_eraseIdx_of_le i j _ _ _]
· rfl
· simpa
· simpa [not_lt] using hij
@[deprecated (since := "2024-05-04")] alias removeNth_insertNth' := eraseIdx_insertNth'
theorem insertNth_comm (a b : α) (i j : Fin (n + 1)) (h : i ≤ j) :
∀ v : Vector α n,
(v.insertNth a i).insertNth b j.succ = (v.insertNth b j).insertNth a (Fin.castSucc i)
| ⟨l, hl⟩ => by
refine Subtype.eq ?_
simp only [insertNth_val, Fin.val_succ, Fin.castSucc, Fin.coe_castAdd]
apply List.insertNth_comm
· assumption
· rw [hl]
exact Nat.le_of_succ_le_succ j.2
end InsertNth
-- Porting note: renamed to `set` from `updateNth` to align with `List`
section ModifyNth
/-- `set v n a` replaces the `n`th element of `v` with `a`. -/
def set (v : Vector α n) (i : Fin n) (a : α) : Vector α n :=
⟨v.1.set i.1 a, by simp⟩
@[simp]
theorem toList_set (v : Vector α n) (i : Fin n) (a : α) :
(v.set i a).toList = v.toList.set i a :=
rfl
@[simp]
theorem get_set_same (v : Vector α n) (i : Fin n) (a : α) : (v.set i a).get i = a := by
cases v; cases i; simp [Vector.set, get_eq_get]
theorem get_set_of_ne {v : Vector α n} {i j : Fin n} (h : i ≠ j) (a : α) :
(v.set i a).get j = v.get j := by
cases v; cases i; cases j
simp only [get_eq_get, toList_set, toList_mk, Fin.cast_mk, List.get_eq_getElem]
rw [List.getElem_set_of_ne]
· simpa using h
theorem get_set_eq_if {v : Vector α n} {i j : Fin n} (a : α) :
(v.set i a).get j = if i = j then a else v.get j := by
split_ifs <;> (try simp [*]); rwa [get_set_of_ne]
@[to_additive]
theorem prod_set [Monoid α] (v : Vector α n) (i : Fin n) (a : α) :
(v.set i a).toList.prod = (v.take i).toList.prod * a * (v.drop (i + 1)).toList.prod := by
refine (List.prod_set v.toList i a).trans ?_
simp_all
@[to_additive]
theorem prod_set' [CommGroup α] (v : Vector α n) (i : Fin n) (a : α) :
(v.set i a).toList.prod = v.toList.prod * (v.get i)⁻¹ * a := by
refine (List.prod_set' v.toList i a).trans ?_
simp [get_eq_get, mul_assoc]
end ModifyNth
end Vector
namespace Vector
section Traverse
variable {F G : Type u → Type u}
variable [Applicative F] [Applicative G]
open Applicative Functor
open List (cons)
open Nat
private def traverseAux {α β : Type u} (f : α → F β) : ∀ x : List α, F (Vector β x.length)
| [] => pure Vector.nil
| x :: xs => Vector.cons <$> f x <*> traverseAux f xs
/-- Apply an applicative function to each component of a vector. -/
protected def traverse {α β : Type u} (f : α → F β) : Vector α n → F (Vector β n)
| ⟨v, Hv⟩ => cast (by rw [Hv]) <| traverseAux f v
section
variable {α β : Type u}
@[simp]
protected theorem traverse_def (f : α → F β) (x : α) :
∀ xs : Vector α n, (x ::ᵥ xs).traverse f = cons <$> f x <*> xs.traverse f := by
rintro ⟨xs, rfl⟩; rfl
protected theorem id_traverse : ∀ x : Vector α n, x.traverse (pure : _ → Id _) = x := by
rintro ⟨x, rfl⟩; dsimp [Vector.traverse, cast]
induction' x with x xs IH; · rfl
simp! [IH]; rfl
end
open Function
variable [LawfulApplicative G]
variable {α β γ : Type u}
-- We need to turn off the linter here as
-- the `LawfulTraversable` instance below expects a particular signature.
@[nolint unusedArguments]
protected theorem comp_traverse (f : β → F γ) (g : α → G β) (x : Vector α n) :
Vector.traverse (Comp.mk ∘ Functor.map f ∘ g) x =
Comp.mk (Vector.traverse f <$> Vector.traverse g x) := by
induction' x with n x xs ih
· simp! [cast, *, functor_norm]
rfl
· rw [Vector.traverse_def, ih]
simp [functor_norm, (· ∘ ·)]
protected theorem traverse_eq_map_id {α β} (f : α → β) :
∀ x : Vector α n, x.traverse ((pure : _ → Id _) ∘ f) = (pure : _ → Id _) (map f x) := by
rintro ⟨x, rfl⟩; simp!; induction x <;> simp! [*, functor_norm] <;> rfl
variable [LawfulApplicative F] (η : ApplicativeTransformation F G)
protected theorem naturality {α β : Type u} (f : α → F β) (x : Vector α n) :
η (x.traverse f) = x.traverse (@η _ ∘ f) := by
induction' x with n x xs ih
· simp! [functor_norm, cast, η.preserves_pure]
· rw [Vector.traverse_def, Vector.traverse_def, ← ih, η.preserves_seq, η.preserves_map]
rfl
end Traverse
instance : Traversable.{u} (flip Vector n) where
traverse := @Vector.traverse n
map {α β} := @Vector.map.{u, u} α β n
instance : LawfulTraversable.{u} (flip Vector n) where
id_traverse := @Vector.id_traverse n
comp_traverse := Vector.comp_traverse
traverse_eq_map_id := @Vector.traverse_eq_map_id n
naturality := Vector.naturality
id_map := by intro _ x; cases x; simp! [(· <$> ·)]
comp_map := by intro _ _ _ _ _ x; cases x; simp! [(· <$> ·)]
map_const := rfl
-- Porting note: not porting meta instances
-- unsafe instance reflect [reflected_univ.{u}] {α : Type u} [has_reflect α]
-- [reflected _ α] {n : ℕ} : has_reflect (Vector α n) := fun v =>
-- @Vector.inductionOn α (fun n => reflected _) n v
-- ((by
-- trace
-- "./././Mathport/Syntax/Translate/Tactic/Builtin.lean:76:14:
-- unsupported tactic `reflect_name #[]" :
-- reflected _ @Vector.nil.{u}).subst
-- q(α))
-- fun n x xs ih =>
-- (by
-- trace
-- "./././Mathport/Syntax/Translate/Tactic/Builtin.lean:76:14:
-- unsupported tactic `reflect_name #[]" :
-- reflected _ @Vector.cons.{u}).subst₄
-- q(α) q(n) q(x) ih
section Simp
variable (xs : Vector α n)
@[simp]
theorem replicate_succ (val : α) :
replicate (n+1) val = val ::ᵥ (replicate n val) :=
rfl
section Append
variable (ys : Vector α m)
@[simp] lemma get_append_cons_zero : get (append (x ::ᵥ xs) ys) ⟨0, by omega⟩ = x := rfl
@[simp]
theorem get_append_cons_succ {i : Fin (n + m)} {h} :
get (append (x ::ᵥ xs) ys) ⟨i+1, h⟩ = get (append xs ys) i :=
rfl
@[simp]
theorem append_nil : append xs nil = xs := by
cases xs; simp [append]
end Append
variable (ys : Vector β n)
@[simp]
theorem get_map₂ (v₁ : Vector α n) (v₂ : Vector β n) (f : α → β → γ) (i : Fin n) :
get (map₂ f v₁ v₂) i = f (get v₁ i) (get v₂ i) := by
clear * - v₁ v₂
induction v₁, v₂ using inductionOn₂ with
| nil =>
exact Fin.elim0 i
| cons ih =>
rw [map₂_cons]
cases i using Fin.cases
· simp only [get_zero, head_cons]
· simp only [get_cons_succ, ih]
@[simp]
theorem mapAccumr_cons :
mapAccumr f (x ::ᵥ xs) s
= let r := mapAccumr f xs s
let q := f x r.1
(q.1, q.2 ::ᵥ r.2) :=
rfl
@[simp]
theorem mapAccumr₂_cons :
mapAccumr₂ f (x ::ᵥ xs) (y ::ᵥ ys) s
= let r := mapAccumr₂ f xs ys s
let q := f x y r.1
(q.1, q.2 ::ᵥ r.2) :=
rfl
end Simp
end Vector
end Mathlib
|
Data\Vector\Defs.lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Mathlib.Init.Data.List.Lemmas
import Mathlib.Tactic.Common
/-!
The type `Vector` represents lists with fixed length.
-/
namespace Mathlib
assert_not_exists Monoid
universe u v w
/-- `Vector α n` is the type of lists of length `n` with elements of type `α`. -/
def Vector (α : Type u) (n : ℕ) :=
{ l : List α // l.length = n }
namespace Vector
variable {α : Type u} {β : Type v} {φ : Type w}
variable {n : ℕ}
instance [DecidableEq α] : DecidableEq (Vector α n) :=
inferInstanceAs (DecidableEq {l : List α // l.length = n})
/-- The empty vector with elements of type `α` -/
@[match_pattern]
def nil : Vector α 0 :=
⟨[], rfl⟩
/-- If `a : α` and `l : Vector α n`, then `cons a l`, is the vector of length `n + 1`
whose first element is a and with l as the rest of the list. -/
@[match_pattern]
def cons : α → Vector α n → Vector α (Nat.succ n)
| a, ⟨v, h⟩ => ⟨a :: v, congrArg Nat.succ h⟩
/-- The length of a vector. -/
@[reducible, nolint unusedArguments]
def length (_ : Vector α n) : ℕ :=
n
open Nat
/-- The first element of a vector with length at least `1`. -/
def head : Vector α (Nat.succ n) → α
| ⟨a :: _, _⟩ => a
/-- The head of a vector obtained by prepending is the element prepended. -/
theorem head_cons (a : α) : ∀ v : Vector α n, head (cons a v) = a
| ⟨_, _⟩ => rfl
/-- The tail of a vector, with an empty vector having empty tail. -/
def tail : Vector α n → Vector α (n - 1)
| ⟨[], h⟩ => ⟨[], congrArg pred h⟩
| ⟨_ :: v, h⟩ => ⟨v, congrArg pred h⟩
/-- The tail of a vector obtained by prepending is the vector prepended. to -/
theorem tail_cons (a : α) : ∀ v : Vector α n, tail (cons a v) = v
| ⟨_, _⟩ => rfl
/-- Prepending the head of a vector to its tail gives the vector. -/
@[simp]
theorem cons_head_tail : ∀ v : Vector α (succ n), cons (head v) (tail v) = v
| ⟨[], h⟩ => by contradiction
| ⟨a :: v, h⟩ => rfl
/-- The list obtained from a vector. -/
def toList (v : Vector α n) : List α :=
v.1
/-- nth element of a vector, indexed by a `Fin` type. -/
def get (l : Vector α n) (i : Fin n) : α :=
l.1.get <| i.cast l.2.symm
/-- Appending a vector to another. -/
def append {n m : Nat} : Vector α n → Vector α m → Vector α (n + m)
| ⟨l₁, h₁⟩, ⟨l₂, h₂⟩ => ⟨l₁ ++ l₂, by simp [*]⟩
/-- Elimination rule for `Vector`. -/
@[elab_as_elim]
def elim {α} {C : ∀ {n}, Vector α n → Sort u}
(H : ∀ l : List α, C ⟨l, rfl⟩) {n : ℕ} : ∀ v : Vector α n, C v
| ⟨l, h⟩ =>
match n, h with
| _, rfl => H l
/-- Map a vector under a function. -/
def map (f : α → β) : Vector α n → Vector β n
| ⟨l, h⟩ => ⟨List.map f l, by simp [*]⟩
/-- A `nil` vector maps to a `nil` vector. -/
@[simp]
theorem map_nil (f : α → β) : map f nil = nil :=
rfl
/-- `map` is natural with respect to `cons`. -/
@[simp]
theorem map_cons (f : α → β) (a : α) : ∀ v : Vector α n, map f (cons a v) = cons (f a) (map f v)
| ⟨_, _⟩ => rfl
/-- Mapping two vectors under a curried function of two variables. -/
def map₂ (f : α → β → φ) : Vector α n → Vector β n → Vector φ n
| ⟨x, _⟩, ⟨y, _⟩ => ⟨List.zipWith f x y, by simp [*]⟩
/-- Vector obtained by repeating an element. -/
def replicate (n : ℕ) (a : α) : Vector α n :=
⟨List.replicate n a, List.length_replicate n a⟩
/-- Drop `i` elements from a vector of length `n`; we can have `i > n`. -/
def drop (i : ℕ) : Vector α n → Vector α (n - i)
| ⟨l, p⟩ => ⟨List.drop i l, by simp [*]⟩
/-- Take `i` elements from a vector of length `n`; we can have `i > n`. -/
def take (i : ℕ) : Vector α n → Vector α (min i n)
| ⟨l, p⟩ => ⟨List.take i l, by simp [*]⟩
/-- Remove the element at position `i` from a vector of length `n`. -/
def eraseIdx (i : Fin n) : Vector α n → Vector α (n - 1)
| ⟨l, p⟩ => ⟨List.eraseIdx l i.1, by rw [l.length_eraseIdx] <;> rw [p]; exact i.2⟩
@[deprecated (since := "2024-05-04")] alias removeNth := eraseIdx
/-- Vector of length `n` from a function on `Fin n`. -/
def ofFn : ∀ {n}, (Fin n → α) → Vector α n
| 0, _ => nil
| _ + 1, f => cons (f 0) (ofFn fun i ↦ f i.succ)
/-- Create a vector from another with a provably equal length. -/
protected def congr {n m : ℕ} (h : n = m) : Vector α n → Vector α m
| ⟨x, p⟩ => ⟨x, h ▸ p⟩
section Accum
open Prod
variable {σ : Type}
/-- Runs a function over a vector returning the intermediate results and a
final result.
-/
def mapAccumr (f : α → σ → σ × β) : Vector α n → σ → σ × Vector β n
| ⟨x, px⟩, c =>
let res := List.mapAccumr f x c
⟨res.1, res.2, by simp [*, res]⟩
/-- Runs a function over a pair of vectors returning the intermediate results and a
final result.
-/
def mapAccumr₂ {α β σ φ : Type} (f : α → β → σ → σ × φ) :
Vector α n → Vector β n → σ → σ × Vector φ n
| ⟨x, px⟩, ⟨y, py⟩, c =>
let res := List.mapAccumr₂ f x y c
⟨res.1, res.2, by simp [*, res]⟩
end Accum
/-! ### Shift Primitives-/
section Shift
/-- `shiftLeftFill v i` is the vector obtained by left-shifting `v` `i` times and padding with the
`fill` argument. If `v.length < i` then this will return `replicate n fill`. -/
def shiftLeftFill (v : Vector α n) (i : ℕ) (fill : α) : Vector α n :=
Vector.congr (by simp) <|
append (drop i v) (replicate (min n i) fill)
/-- `shiftRightFill v i` is the vector obtained by right-shifting `v` `i` times and padding with the
`fill` argument. If `v.length < i` then this will return `replicate n fill`. -/
def shiftRightFill (v : Vector α n) (i : ℕ) (fill : α) : Vector α n :=
Vector.congr (by omega) <| append (replicate (min n i) fill) (take (n - i) v)
end Shift
/-! ### Basic Theorems -/
/-- Vector is determined by the underlying list. -/
protected theorem eq {n : ℕ} : ∀ a1 a2 : Vector α n, toList a1 = toList a2 → a1 = a2
| ⟨_, _⟩, ⟨_, _⟩, rfl => rfl
/-- A vector of length `0` is a `nil` vector. -/
protected theorem eq_nil (v : Vector α 0) : v = nil :=
v.eq nil (List.eq_nil_of_length_eq_zero v.2)
/-- Vector of length from a list `v`
with witness that `v` has length `n` maps to `v` under `toList`. -/
@[simp]
theorem toList_mk (v : List α) (P : List.length v = n) : toList (Subtype.mk v P) = v :=
rfl
/-- A nil vector maps to a nil list. -/
@[simp]
theorem toList_nil : toList nil = @List.nil α :=
rfl
/-- The length of the list to which a vector of length `n` maps is `n`. -/
@[simp]
theorem toList_length (v : Vector α n) : (toList v).length = n :=
v.2
/-- `toList` of `cons` of a vector and an element is
the `cons` of the list obtained by `toList` and the element -/
@[simp]
theorem toList_cons (a : α) (v : Vector α n) : toList (cons a v) = a :: toList v := by
cases v; rfl
/-- Appending of vectors corresponds under `toList` to appending of lists. -/
@[simp]
theorem toList_append {n m : ℕ} (v : Vector α n) (w : Vector α m) :
toList (append v w) = toList v ++ toList w := by
cases v
cases w
rfl
/-- `drop` of vectors corresponds under `toList` to `drop` of lists. -/
@[simp]
theorem toList_drop {n m : ℕ} (v : Vector α m) : toList (drop n v) = List.drop n (toList v) := by
cases v
rfl
/-- `take` of vectors corresponds under `toList` to `take` of lists. -/
@[simp]
theorem toList_take {n m : ℕ} (v : Vector α m) : toList (take n v) = List.take n (toList v) := by
cases v
rfl
instance : GetElem (Vector α n) Nat α fun _ i => i < n where
getElem := fun x i h => get x ⟨i, h⟩
end Vector
end Mathlib
|
Data\Vector\MapLemmas.lean | /-
Copyright (c) 2023 Alex Keizer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex Keizer
-/
import Mathlib.Data.Vector.Basic
import Mathlib.Data.Vector.Snoc
/-!
This file establishes a set of normalization lemmas for `map`/`mapAccumr` operations on vectors
-/
set_option autoImplicit true
namespace Mathlib
namespace Vector
/-!
## Fold nested `mapAccumr`s into one
-/
section Fold
section Unary
variable (xs : Vector α n) (f₁ : β → σ₁ → σ₁ × γ) (f₂ : α → σ₂ → σ₂ × β)
@[simp]
theorem mapAccumr_mapAccumr :
mapAccumr f₁ (mapAccumr f₂ xs s₂).snd s₁
= let m := (mapAccumr (fun x s =>
let r₂ := f₂ x s.snd
let r₁ := f₁ r₂.snd s.fst
((r₁.fst, r₂.fst), r₁.snd)
) xs (s₁, s₂))
(m.fst.fst, m.snd) := by
induction xs using Vector.revInductionOn generalizing s₁ s₂ <;> simp_all
@[simp]
theorem mapAccumr_map (f₂ : α → β) :
(mapAccumr f₁ (map f₂ xs) s) = (mapAccumr (fun x s => f₁ (f₂ x) s) xs s) := by
induction xs using Vector.revInductionOn generalizing s <;> simp_all
@[simp]
theorem map_mapAccumr (f₁ : β → γ) :
(map f₁ (mapAccumr f₂ xs s).snd) = (mapAccumr (fun x s =>
let r := (f₂ x s); (r.fst, f₁ r.snd)
) xs s).snd := by
induction xs using Vector.revInductionOn generalizing s <;> simp_all
@[simp]
theorem map_map (f₁ : β → γ) (f₂ : α → β) :
map f₁ (map f₂ xs) = map (fun x => f₁ <| f₂ x) xs := by
induction xs <;> simp_all
end Unary
section Binary
variable (xs : Vector α n) (ys : Vector β n)
@[simp]
theorem mapAccumr₂_mapAccumr_left (f₁ : γ → β → σ₁ → σ₁ × ζ) (f₂ : α → σ₂ → σ₂ × γ) :
(mapAccumr₂ f₁ (mapAccumr f₂ xs s₂).snd ys s₁)
= let m := (mapAccumr₂ (fun x y s =>
let r₂ := f₂ x s.snd
let r₁ := f₁ r₂.snd y s.fst
((r₁.fst, r₂.fst), r₁.snd)
) xs ys (s₁, s₂))
(m.fst.fst, m.snd) := by
induction xs, ys using Vector.revInductionOn₂ generalizing s₁ s₂ <;> simp_all
@[simp]
theorem map₂_map_left (f₁ : γ → β → ζ) (f₂ : α → γ) :
map₂ f₁ (map f₂ xs) ys = map₂ (fun x y => f₁ (f₂ x) y) xs ys := by
induction xs, ys using Vector.revInductionOn₂ <;> simp_all
@[simp]
theorem mapAccumr₂_mapAccumr_right (f₁ : α → γ → σ₁ → σ₁ × ζ) (f₂ : β → σ₂ → σ₂ × γ) :
(mapAccumr₂ f₁ xs (mapAccumr f₂ ys s₂).snd s₁)
= let m := (mapAccumr₂ (fun x y s =>
let r₂ := f₂ y s.snd
let r₁ := f₁ x r₂.snd s.fst
((r₁.fst, r₂.fst), r₁.snd)
) xs ys (s₁, s₂))
(m.fst.fst, m.snd) := by
induction xs, ys using Vector.revInductionOn₂ generalizing s₁ s₂ <;> simp_all
@[simp]
theorem map₂_map_right (f₁ : α → γ → ζ) (f₂ : β → γ) :
map₂ f₁ xs (map f₂ ys) = map₂ (fun x y => f₁ x (f₂ y)) xs ys := by
induction xs, ys using Vector.revInductionOn₂ <;> simp_all
@[simp]
theorem mapAccumr_mapAccumr₂ (f₁ : γ → σ₁ → σ₁ × ζ) (f₂ : α → β → σ₂ → σ₂ × γ) :
(mapAccumr f₁ (mapAccumr₂ f₂ xs ys s₂).snd s₁)
= let m := mapAccumr₂ (fun x y s =>
let r₂ := f₂ x y s.snd
let r₁ := f₁ r₂.snd s.fst
((r₁.fst, r₂.fst), r₁.snd)
) xs ys (s₁, s₂)
(m.fst.fst, m.snd) := by
induction xs, ys using Vector.revInductionOn₂ generalizing s₁ s₂ <;> simp_all
@[simp]
theorem map_map₂ (f₁ : γ → ζ) (f₂ : α → β → γ) :
map f₁ (map₂ f₂ xs ys) = map₂ (fun x y => f₁ <| f₂ x y) xs ys := by
induction xs, ys using Vector.revInductionOn₂ <;> simp_all
@[simp]
theorem mapAccumr₂_mapAccumr₂_left_left (f₁ : γ → α → σ₁ → σ₁ × φ) (f₂ : α → β → σ₂ → σ₂ × γ) :
(mapAccumr₂ f₁ (mapAccumr₂ f₂ xs ys s₂).snd xs s₁)
= let m := mapAccumr₂ (fun x y (s₁, s₂) =>
let r₂ := f₂ x y s₂
let r₁ := f₁ r₂.snd x s₁
((r₁.fst, r₂.fst), r₁.snd)
)
xs ys (s₁, s₂)
(m.fst.fst, m.snd) := by
induction xs, ys using Vector.revInductionOn₂ generalizing s₁ s₂ <;> simp_all
@[simp]
theorem mapAccumr₂_mapAccumr₂_left_right
(f₁ : γ → β → σ₁ → σ₁ × φ) (f₂ : α → β → σ₂ → σ₂ × γ) :
(mapAccumr₂ f₁ (mapAccumr₂ f₂ xs ys s₂).snd ys s₁)
= let m := mapAccumr₂ (fun x y (s₁, s₂) =>
let r₂ := f₂ x y s₂
let r₁ := f₁ r₂.snd y s₁
((r₁.fst, r₂.fst), r₁.snd)
)
xs ys (s₁, s₂)
(m.fst.fst, m.snd) := by
induction xs, ys using Vector.revInductionOn₂ generalizing s₁ s₂ <;> simp_all
@[simp]
theorem mapAccumr₂_mapAccumr₂_right_left (f₁ : α → γ → σ₁ → σ₁ × φ) (f₂ : α → β → σ₂ → σ₂ × γ) :
(mapAccumr₂ f₁ xs (mapAccumr₂ f₂ xs ys s₂).snd s₁)
= let m := mapAccumr₂ (fun x y (s₁, s₂) =>
let r₂ := f₂ x y s₂
let r₁ := f₁ x r₂.snd s₁
((r₁.fst, r₂.fst), r₁.snd)
)
xs ys (s₁, s₂)
(m.fst.fst, m.snd) := by
induction xs, ys using Vector.revInductionOn₂ generalizing s₁ s₂ <;> simp_all
@[simp]
theorem mapAccumr₂_mapAccumr₂_right_right (f₁ : β → γ → σ₁ → σ₁ × φ) (f₂ : α → β → σ₂ → σ₂ × γ) :
(mapAccumr₂ f₁ ys (mapAccumr₂ f₂ xs ys s₂).snd s₁)
= let m := mapAccumr₂ (fun x y (s₁, s₂) =>
let r₂ := f₂ x y s₂
let r₁ := f₁ y r₂.snd s₁
((r₁.fst, r₂.fst), r₁.snd)
)
xs ys (s₁, s₂)
(m.fst.fst, m.snd) := by
induction xs, ys using Vector.revInductionOn₂ generalizing s₁ s₂ <;> simp_all
end Binary
end Fold
/-!
## Bisimulations
We can prove two applications of `mapAccumr` equal by providing a bisimulation relation that relates
the initial states.
That is, by providing a relation `R : σ₁ → σ₁ → Prop` such that `R s₁ s₂` implies that `R` also
relates any pair of states reachable by applying `f₁` to `s₁` and `f₂` to `s₂`, with any possible
input values.
-/
section Bisim
variable {xs : Vector α n}
theorem mapAccumr_bisim {f₁ : α → σ₁ → σ₁ × β} {f₂ : α → σ₂ → σ₂ × β} {s₁ : σ₁} {s₂ : σ₂}
(R : σ₁ → σ₂ → Prop) (h₀ : R s₁ s₂)
(hR : ∀ {s q} a, R s q → R (f₁ a s).1 (f₂ a q).1 ∧ (f₁ a s).2 = (f₂ a q).2) :
R (mapAccumr f₁ xs s₁).fst (mapAccumr f₂ xs s₂).fst
∧ (mapAccumr f₁ xs s₁).snd = (mapAccumr f₂ xs s₂).snd := by
induction xs using Vector.revInductionOn generalizing s₁ s₂
next => exact ⟨h₀, rfl⟩
next xs x ih =>
rcases (hR x h₀) with ⟨hR, _⟩
simp only [mapAccumr_snoc, ih hR, true_and]
congr 1
theorem mapAccumr_bisim_tail {f₁ : α → σ₁ → σ₁ × β} {f₂ : α → σ₂ → σ₂ × β} {s₁ : σ₁} {s₂ : σ₂}
(h : ∃ R : σ₁ → σ₂ → Prop, R s₁ s₂ ∧
∀ {s q} a, R s q → R (f₁ a s).1 (f₂ a q).1 ∧ (f₁ a s).2 = (f₂ a q).2) :
(mapAccumr f₁ xs s₁).snd = (mapAccumr f₂ xs s₂).snd := by
rcases h with ⟨R, h₀, hR⟩
exact (mapAccumr_bisim R h₀ hR).2
theorem mapAccumr₂_bisim {ys : Vector β n} {f₁ : α → β → σ₁ → σ₁ × γ}
{f₂ : α → β → σ₂ → σ₂ × γ} {s₁ : σ₁} {s₂ : σ₂}
(R : σ₁ → σ₂ → Prop) (h₀ : R s₁ s₂)
(hR : ∀ {s q} a b, R s q → R (f₁ a b s).1 (f₂ a b q).1 ∧ (f₁ a b s).2 = (f₂ a b q).2) :
R (mapAccumr₂ f₁ xs ys s₁).1 (mapAccumr₂ f₂ xs ys s₂).1
∧ (mapAccumr₂ f₁ xs ys s₁).2 = (mapAccumr₂ f₂ xs ys s₂).2 := by
induction xs, ys using Vector.revInductionOn₂ generalizing s₁ s₂
next => exact ⟨h₀, rfl⟩
next xs ys x y ih =>
rcases (hR x y h₀) with ⟨hR, _⟩
simp only [mapAccumr₂_snoc, ih hR, true_and]
congr 1
theorem mapAccumr₂_bisim_tail {ys : Vector β n} {f₁ : α → β → σ₁ → σ₁ × γ}
{f₂ : α → β → σ₂ → σ₂ × γ} {s₁ : σ₁} {s₂ : σ₂}
(h : ∃ R : σ₁ → σ₂ → Prop, R s₁ s₂ ∧
∀ {s q} a b, R s q → R (f₁ a b s).1 (f₂ a b q).1 ∧ (f₁ a b s).2 = (f₂ a b q).2) :
(mapAccumr₂ f₁ xs ys s₁).2 = (mapAccumr₂ f₂ xs ys s₂).2 := by
rcases h with ⟨R, h₀, hR⟩
exact (mapAccumr₂_bisim R h₀ hR).2
end Bisim
/-!
## Redundant state optimization
The following section are collection of rewrites to simplify, or even get rid, redundant
accumulation state
-/
section RedundantState
variable {xs : Vector α n} {ys : Vector β n}
protected theorem map_eq_mapAccumr :
map f xs = (mapAccumr (fun x (_ : Unit) ↦ ((), f x)) xs ()).snd := by
clear ys
induction xs using Vector.revInductionOn <;> simp_all
/--
If there is a set of states that is closed under `f`, and such that `f` produces that same output
for all states in this set, then the state is not actually needed.
Hence, then we can rewrite `mapAccumr` into just `map`
-/
theorem mapAccumr_eq_map {f : α → σ → σ × β} {s₀ : σ} (S : Set σ) (h₀ : s₀ ∈ S)
(closure : ∀ a s, s ∈ S → (f a s).1 ∈ S)
(out : ∀ a s s', s ∈ S → s' ∈ S → (f a s).2 = (f a s').2) :
(mapAccumr f xs s₀).snd = map (f · s₀ |>.snd) xs := by
rw [Vector.map_eq_mapAccumr]
apply mapAccumr_bisim_tail
use fun s _ => s ∈ S, h₀
exact @fun s _q a h => ⟨closure a s h, out a s s₀ h h₀⟩
protected theorem map₂_eq_mapAccumr₂ :
map₂ f xs ys = (mapAccumr₂ (fun x y (_ : Unit) ↦ ((), f x y)) xs ys ()).snd := by
induction xs, ys using Vector.revInductionOn₂ <;> simp_all
/--
If there is a set of states that is closed under `f`, and such that `f` produces that same output
for all states in this set, then the state is not actually needed.
Hence, then we can rewrite `mapAccumr₂` into just `map₂`
-/
theorem mapAccumr₂_eq_map₂ {f : α → β → σ → σ × γ} {s₀ : σ} (S : Set σ) (h₀ : s₀ ∈ S)
(closure : ∀ a b s, s ∈ S → (f a b s).1 ∈ S)
(out : ∀ a b s s', s ∈ S → s' ∈ S → (f a b s).2 = (f a b s').2) :
(mapAccumr₂ f xs ys s₀).snd = map₂ (f · · s₀ |>.snd) xs ys := by
rw [Vector.map₂_eq_mapAccumr₂]
apply mapAccumr₂_bisim_tail
use fun s _ => s ∈ S, h₀
exact @fun s _q a b h => ⟨closure a b s h, out a b s s₀ h h₀⟩
/--
If an accumulation function `f`, given an initial state `s`, produces `s` as its output state
for all possible input bits, then the state is redundant and can be optimized out
-/
@[simp]
theorem mapAccumr_eq_map_of_constant_state (f : α → σ → σ × β) (s : σ) (h : ∀ a, (f a s).fst = s) :
mapAccumr f xs s = (s, (map (fun x => (f x s).snd) xs)) := by
clear ys
induction xs using revInductionOn <;> simp_all
/--
If an accumulation function `f`, given an initial state `s`, produces `s` as its output state
for all possible input bits, then the state is redundant and can be optimized out
-/
@[simp]
theorem mapAccumr₂_eq_map₂_of_constant_state (f : α → β → σ → σ × γ) (s : σ)
(h : ∀ a b, (f a b s).fst = s) :
mapAccumr₂ f xs ys s = (s, (map₂ (fun x y => (f x y s).snd) xs ys)) := by
induction xs, ys using revInductionOn₂ <;> simp_all
/--
If an accumulation function `f`, produces the same output bits regardless of accumulation state,
then the state is redundant and can be optimized out
-/
@[simp]
theorem mapAccumr_eq_map_of_unused_state (f : α → σ → σ × β) (s : σ)
(h : ∀ a s s', (f a s).snd = (f a s').snd) :
(mapAccumr f xs s).snd = (map (fun x => (f x s).snd) xs) :=
mapAccumr_eq_map (fun _ => true) rfl (fun _ _ _ => rfl) (fun a s s' _ _ => h a s s')
/--
If an accumulation function `f`, produces the same output bits regardless of accumulation state,
then the state is redundant and can be optimized out
-/
@[simp]
theorem mapAccumr₂_eq_map₂_of_unused_state (f : α → β → σ → σ × γ) (s : σ)
(h : ∀ a b s s', (f a b s).snd = (f a b s').snd) :
(mapAccumr₂ f xs ys s).snd = (map₂ (fun x y => (f x y s).snd) xs ys) :=
mapAccumr₂_eq_map₂ (fun _ => true) rfl (fun _ _ _ _ => rfl) (fun a b s s' _ _ => h a b s s')
/-- If `f` takes a pair of states, but always returns the same value for both elements of the
pair, then we can simplify to just a single element of state
-/
@[simp]
theorem mapAccumr_redundant_pair (f : α → (σ × σ) → (σ × σ) × β)
(h : ∀ x s, (f x (s, s)).fst.fst = (f x (s, s)).fst.snd) :
(mapAccumr f xs (s, s)).snd = (mapAccumr (fun x (s : σ) =>
(f x (s, s) |>.fst.fst, f x (s, s) |>.snd)
) xs s).snd :=
mapAccumr_bisim_tail <| by
use fun (s₁, s₂) s => s₂ = s ∧ s₁ = s
simp_all
/-- If `f` takes a pair of states, but always returns the same value for both elements of the
pair, then we can simplify to just a single element of state
-/
@[simp]
theorem mapAccumr₂_redundant_pair (f : α → β → (σ × σ) → (σ × σ) × γ)
(h : ∀ x y s, let s' := (f x y (s, s)).fst; s'.fst = s'.snd) :
(mapAccumr₂ f xs ys (s, s)).snd = (mapAccumr₂ (fun x y (s : σ) =>
(f x y (s, s) |>.fst.fst, f x y (s, s) |>.snd)
) xs ys s).snd :=
mapAccumr₂_bisim_tail <| by
use fun (s₁, s₂) s => s₂ = s ∧ s₁ = s
simp_all
end RedundantState
/-!
## Unused input optimizations
-/
section UnusedInput
variable {xs : Vector α n} {ys : Vector β n}
/--
If `f` returns the same output and next state for every value of it's first argument, then
`xs : Vector` is ignored, and we can rewrite `mapAccumr₂` into `map`
-/
@[simp]
theorem mapAccumr₂_unused_input_left [Inhabited α] (f : α → β → σ → σ × γ)
(h : ∀ a b s, f default b s = f a b s) :
mapAccumr₂ f xs ys s = mapAccumr (fun b s => f default b s) ys s := by
induction xs, ys using Vector.revInductionOn₂ generalizing s with
| nil => rfl
| snoc xs ys x y ih => simp [h x y s, ih]
/--
If `f` returns the same output and next state for every value of it's second argument, then
`ys : Vector` is ignored, and we can rewrite `mapAccumr₂` into `map`
-/
@[simp]
theorem mapAccumr₂_unused_input_right [Inhabited β] (f : α → β → σ → σ × γ)
(h : ∀ a b s, f a default s = f a b s) :
mapAccumr₂ f xs ys s = mapAccumr (fun a s => f a default s) xs s := by
induction xs, ys using Vector.revInductionOn₂ generalizing s with
| nil => rfl
| snoc xs ys x y ih => simp [h x y s, ih]
end UnusedInput
/-!
## Commutativity
-/
section Comm
variable (xs ys : Vector α n)
theorem map₂_comm (f : α → α → β) (comm : ∀ a₁ a₂, f a₁ a₂ = f a₂ a₁) :
map₂ f xs ys = map₂ f ys xs := by
induction xs, ys using Vector.inductionOn₂ <;> simp_all
theorem mapAccumr₂_comm (f : α → α → σ → σ × γ) (comm : ∀ a₁ a₂ s, f a₁ a₂ s = f a₂ a₁ s) :
mapAccumr₂ f xs ys s = mapAccumr₂ f ys xs s := by
induction xs, ys using Vector.inductionOn₂ generalizing s <;> simp_all
end Comm
/-!
## Argument Flipping
-/
section Flip
variable (xs : Vector α n) (ys : Vector β n)
theorem map₂_flip (f : α → β → γ) :
map₂ f xs ys = map₂ (flip f) ys xs := by
induction xs, ys using Vector.inductionOn₂ <;> simp_all[flip]
theorem mapAccumr₂_flip (f : α → β → σ → σ × γ) :
mapAccumr₂ f xs ys s = mapAccumr₂ (flip f) ys xs s := by
induction xs, ys using Vector.inductionOn₂ <;> simp_all[flip]
end Flip
end Vector
end Mathlib
|
Data\Vector\Mem.lean | /-
Copyright (c) 2022 Devon Tuma. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Devon Tuma
-/
import Mathlib.Data.Vector.Basic
/-!
# Theorems about membership of elements in vectors
This file contains theorems for membership in a `v.toList` for a vector `v`.
Having the length available in the type allows some of the lemmas to be
simpler and more general than the original version for lists.
In particular we can avoid some assumptions about types being `Inhabited`,
and make more general statements about `head` and `tail`.
-/
namespace Mathlib
namespace Vector
variable {α β : Type*} {n : ℕ} (a a' : α)
@[simp]
theorem get_mem (i : Fin n) (v : Vector α n) : v.get i ∈ v.toList := by
rw [get_eq_get]
exact List.get_mem _ _ _
theorem mem_iff_get (v : Vector α n) : a ∈ v.toList ↔ ∃ i, v.get i = a := by
simp only [List.mem_iff_get, Fin.exists_iff, Vector.get_eq_get]
exact
⟨fun ⟨i, hi, h⟩ => ⟨i, by rwa [toList_length] at hi, h⟩, fun ⟨i, hi, h⟩ =>
⟨i, by rwa [toList_length], h⟩⟩
theorem not_mem_nil : a ∉ (Vector.nil : Vector α 0).toList := by
unfold Vector.nil
dsimp
simp
theorem not_mem_zero (v : Vector α 0) : a ∉ v.toList :=
(Vector.eq_nil v).symm ▸ not_mem_nil a
theorem mem_cons_iff (v : Vector α n) : a' ∈ (a ::ᵥ v).toList ↔ a' = a ∨ a' ∈ v.toList := by
rw [Vector.toList_cons, List.mem_cons]
theorem mem_succ_iff (v : Vector α (n + 1)) : a ∈ v.toList ↔ a = v.head ∨ a ∈ v.tail.toList := by
obtain ⟨a', v', h⟩ := exists_eq_cons v
simp_rw [h, Vector.mem_cons_iff, Vector.head_cons, Vector.tail_cons]
theorem mem_cons_self (v : Vector α n) : a ∈ (a ::ᵥ v).toList :=
(Vector.mem_iff_get a (a ::ᵥ v)).2 ⟨0, Vector.get_cons_zero a v⟩
@[simp]
theorem head_mem (v : Vector α (n + 1)) : v.head ∈ v.toList :=
(Vector.mem_iff_get v.head v).2 ⟨0, Vector.get_zero v⟩
theorem mem_cons_of_mem (v : Vector α n) (ha' : a' ∈ v.toList) : a' ∈ (a ::ᵥ v).toList :=
(Vector.mem_cons_iff a a' v).2 (Or.inr ha')
theorem mem_of_mem_tail (v : Vector α n) (ha : a ∈ v.tail.toList) : a ∈ v.toList := by
induction' n with n _
· exact False.elim (Vector.not_mem_zero a v.tail ha)
· exact (mem_succ_iff a v).2 (Or.inr ha)
theorem mem_map_iff (b : β) (v : Vector α n) (f : α → β) :
b ∈ (v.map f).toList ↔ ∃ a : α, a ∈ v.toList ∧ f a = b := by
rw [Vector.toList_map, List.mem_map]
theorem not_mem_map_zero (b : β) (v : Vector α 0) (f : α → β) : b ∉ (v.map f).toList := by
simpa only [Vector.eq_nil v, Vector.map_nil, Vector.toList_nil] using List.not_mem_nil b
theorem mem_map_succ_iff (b : β) (v : Vector α (n + 1)) (f : α → β) :
b ∈ (v.map f).toList ↔ f v.head = b ∨ ∃ a : α, a ∈ v.tail.toList ∧ f a = b := by
rw [mem_succ_iff, head_map, tail_map, mem_map_iff, @eq_comm _ b]
end Vector
end Mathlib
|
Data\Vector\Snoc.lean | /-
Copyright (c) 2023 Alex Keizer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex Keizer
-/
import Mathlib.Data.Vector.Basic
/-!
This file establishes a `snoc : Vector α n → α → Vector α (n+1)` operation, that appends a single
element to the back of a vector.
It provides a collection of lemmas that show how different `Vector` operations reduce when their
argument is `snoc xs x`.
Also, an alternative, reverse, induction principle is added, that breaks down a vector into
`snoc xs x` for its inductive case. Effectively doing induction from right-to-left
-/
set_option autoImplicit true
namespace Mathlib
namespace Vector
/-- Append a single element to the end of a vector -/
def snoc : Vector α n → α → Vector α (n+1) :=
fun xs x => append xs (x ::ᵥ Vector.nil)
/-!
## Simplification lemmas
-/
section Simp
variable (xs : Vector α n)
@[simp]
theorem snoc_cons : (x ::ᵥ xs).snoc y = x ::ᵥ (xs.snoc y) :=
rfl
@[simp]
theorem snoc_nil : (nil.snoc x) = x ::ᵥ nil :=
rfl
@[simp]
theorem reverse_cons : reverse (x ::ᵥ xs) = (reverse xs).snoc x := by
cases xs
simp only [reverse, cons, toList_mk, List.reverse_cons, snoc]
congr
@[simp]
theorem reverse_snoc : reverse (xs.snoc x) = x ::ᵥ (reverse xs) := by
cases xs
simp only [reverse, snoc, cons, toList_mk]
congr
simp [toList, Vector.append, Append.append]
theorem replicate_succ_to_snoc (val : α) :
replicate (n+1) val = (replicate n val).snoc val := by
clear xs
induction n with
| zero => rfl
| succ n ih =>
rw [replicate_succ]
conv => rhs; rw [replicate_succ]
rw [snoc_cons, ih]
end Simp
/-!
## Reverse induction principle
-/
section Induction
/-- Define `C v` by *reverse* induction on `v : Vector α n`.
That is, break the vector down starting from the right-most element, using `snoc`
This function has two arguments: `nil` handles the base case on `C nil`,
and `snoc` defines the inductive step using `∀ x : α, C xs → C (xs.snoc x)`.
This can be used as `induction v using Vector.revInductionOn`. -/
@[elab_as_elim]
def revInductionOn {C : ∀ {n : ℕ}, Vector α n → Sort*} {n : ℕ} (v : Vector α n)
(nil : C nil)
(snoc : ∀ {n : ℕ} (xs : Vector α n) (x : α), C xs → C (xs.snoc x)) :
C v :=
cast (by simp) <| inductionOn
(C := fun v => C v.reverse)
v.reverse
nil
(@fun n x xs (r : C xs.reverse) => cast (by simp) <| snoc xs.reverse x r)
/-- Define `C v w` by *reverse* induction on a pair of vectors `v : Vector α n` and
`w : Vector β n`. -/
@[elab_as_elim]
def revInductionOn₂ {C : ∀ {n : ℕ}, Vector α n → Vector β n → Sort*} {n : ℕ}
(v : Vector α n) (w : Vector β n)
(nil : C nil nil)
(snoc : ∀ {n : ℕ} (xs : Vector α n) (ys : Vector β n) (x : α) (y : β),
C xs ys → C (xs.snoc x) (ys.snoc y)) :
C v w :=
cast (by simp) <| inductionOn₂
(C := fun v w => C v.reverse w.reverse)
v.reverse
w.reverse
nil
(@fun n x y xs ys (r : C xs.reverse ys.reverse) =>
cast (by simp) <| snoc xs.reverse ys.reverse x y r)
/-- Define `C v` by *reverse* case analysis, i.e. by handling the cases `nil` and `xs.snoc x`
separately -/
@[elab_as_elim]
def revCasesOn {C : ∀ {n : ℕ}, Vector α n → Sort*} {n : ℕ} (v : Vector α n)
(nil : C nil)
(snoc : ∀ {n : ℕ} (xs : Vector α n) (x : α), C (xs.snoc x)) :
C v :=
revInductionOn v nil fun xs x _ => snoc xs x
end Induction
/-!
## More simplification lemmas
-/
section Simp
variable (xs : Vector α n)
@[simp]
theorem map_snoc : map f (xs.snoc x) = (map f xs).snoc (f x) := by
induction xs <;> simp_all
@[simp]
theorem mapAccumr_nil : mapAccumr f Vector.nil s = (s, Vector.nil) :=
rfl
@[simp]
theorem mapAccumr_snoc :
mapAccumr f (xs.snoc x) s
= let q := f x s
let r := mapAccumr f xs q.1
(r.1, r.2.snoc q.2) := by
induction xs
· rfl
· simp [*]
variable (ys : Vector β n)
@[simp]
theorem map₂_snoc : map₂ f (xs.snoc x) (ys.snoc y) = (map₂ f xs ys).snoc (f x y) := by
induction xs, ys using Vector.inductionOn₂ <;> simp_all
@[simp]
theorem mapAccumr₂_nil : mapAccumr₂ f Vector.nil Vector.nil s = (s, Vector.nil) :=
rfl
@[simp]
theorem mapAccumr₂_snoc (f : α → β → σ → σ × φ) (x : α) (y : β) :
mapAccumr₂ f (xs.snoc x) (ys.snoc y) c
= let q := f x y c
let r := mapAccumr₂ f xs ys q.1
(r.1, r.2.snoc q.2) := by
induction xs, ys using Vector.inductionOn₂ <;> simp_all
end Simp
end Vector
end Mathlib
|
Data\Vector\Zip.lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Data.Vector.Basic
/-!
# The `zipWith` operation on vectors.
-/
namespace Mathlib
namespace Vector
section ZipWith
variable {α β γ : Type*} {n : ℕ} (f : α → β → γ)
/-- Apply the function `f : α → β → γ` to each corresponding pair of elements from two vectors. -/
def zipWith : Vector α n → Vector β n → Vector γ n := fun x y => ⟨List.zipWith f x.1 y.1, by simp⟩
@[simp]
theorem zipWith_toList (x : Vector α n) (y : Vector β n) :
(Vector.zipWith f x y).toList = List.zipWith f x.toList y.toList :=
rfl
@[simp]
theorem zipWith_get (x : Vector α n) (y : Vector β n) (i) :
(Vector.zipWith f x y).get i = f (x.get i) (y.get i) := by
dsimp only [Vector.zipWith, Vector.get]
simp
@[simp]
theorem zipWith_tail (x : Vector α n) (y : Vector β n) :
(Vector.zipWith f x y).tail = Vector.zipWith f x.tail y.tail := by
ext
simp [get_tail]
@[to_additive]
theorem prod_mul_prod_eq_prod_zipWith [CommMonoid α] (x y : Vector α n) :
x.toList.prod * y.toList.prod = (Vector.zipWith (· * ·) x y).toList.prod :=
List.prod_mul_prod_eq_prod_zipWith_of_length_eq x.toList y.toList
((toList_length x).trans (toList_length y).symm)
end ZipWith
end Vector
end Mathlib
|
Data\W\Basic.lean | /-
Copyright (c) 2019 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
-/
import Mathlib.Logic.Equiv.List
/-!
# W types
Given `α : Type` and `β : α → Type`, the W type determined by this data, `WType β`, is the
inductively defined type of trees where the nodes are labeled by elements of `α` and the children of
a node labeled `a` are indexed by elements of `β a`.
This file is currently a stub, awaiting a full development of the theory. Currently, the main result
is that if `α` is an encodable fintype and `β a` is encodable for every `a : α`, then `WType β` is
encodable. This can be used to show the encodability of other inductive types, such as those that
are commonly used to formalize syntax, e.g. terms and expressions in a given language. The strategy
is illustrated in the example found in the file `prop_encodable` in the `archive/examples` folder of
mathlib.
## Implementation details
While the name `WType` is somewhat verbose, it is preferable to putting a single character
identifier `W` in the root namespace.
-/
-- For "W_type"
/--
Given `β : α → Type*`, `WType β` is the type of finitely branching trees where nodes are labeled by
elements of `α` and the children of a node labeled `a` are indexed by elements of `β a`.
-/
inductive WType {α : Type*} (β : α → Type*)
| mk (a : α) (f : β a → WType β) : WType β
instance : Inhabited (WType fun _ : Unit => Empty) :=
⟨WType.mk Unit.unit Empty.elim⟩
namespace WType
variable {α : Type*} {β : α → Type*}
/-- The canonical map to the corresponding sigma type, returning the label of a node as an
element `a` of `α`, and the children of the node as a function `β a → WType β`. -/
def toSigma : WType β → Σa : α, β a → WType β
| ⟨a, f⟩ => ⟨a, f⟩
/-- The canonical map from the sigma type into a `WType`. Given a node `a : α`, and
its children as a function `β a → WType β`, return the corresponding tree. -/
def ofSigma : (Σa : α, β a → WType β) → WType β
| ⟨a, f⟩ => WType.mk a f
@[simp]
theorem ofSigma_toSigma : ∀ w : WType β, ofSigma (toSigma w) = w
| ⟨_, _⟩ => rfl
@[simp]
theorem toSigma_ofSigma : ∀ s : Σa : α, β a → WType β, toSigma (ofSigma s) = s
| ⟨_, _⟩ => rfl
variable (β)
/-- The canonical bijection with the sigma type, showing that `WType` is a fixed point of
the polynomial functor `X ↦ Σ a : α, β a → X`. -/
@[simps]
def equivSigma : WType β ≃ Σa : α, β a → WType β where
toFun := toSigma
invFun := ofSigma
left_inv := ofSigma_toSigma
right_inv := toSigma_ofSigma
variable {β}
-- Porting note: Universes have a different order than mathlib3 definition
/-- The canonical map from `WType β` into any type `γ` given a map `(Σ a : α, β a → γ) → γ`. -/
def elim (γ : Type*) (fγ : (Σa : α, β a → γ) → γ) : WType β → γ
| ⟨a, f⟩ => fγ ⟨a, fun b => elim γ fγ (f b)⟩
theorem elim_injective (γ : Type*) (fγ : (Σa : α, β a → γ) → γ)
(fγ_injective : Function.Injective fγ) : Function.Injective (elim γ fγ)
| ⟨a₁, f₁⟩, ⟨a₂, f₂⟩, h => by
obtain ⟨rfl, h⟩ := Sigma.mk.inj_iff.mp (fγ_injective h)
congr with x
exact elim_injective γ fγ fγ_injective (congr_fun (eq_of_heq h) x : _)
instance [hα : IsEmpty α] : IsEmpty (WType β) :=
⟨fun w => WType.recOn w (IsEmpty.elim hα)⟩
theorem infinite_of_nonempty_of_isEmpty (a b : α) [ha : Nonempty (β a)] [he : IsEmpty (β b)] :
Infinite (WType β) :=
⟨by
intro hf
have hba : b ≠ a := fun h => ha.elim (IsEmpty.elim' (show IsEmpty (β a) from h ▸ he))
refine
not_injective_infinite_finite
(fun n : ℕ =>
show WType β from Nat.recOn n ⟨b, IsEmpty.elim' he⟩ fun _ ih => ⟨a, fun _ => ih⟩)
?_
intro n m h
induction' n with n ih generalizing m
· cases' m with m <;> simp_all
· cases' m with m
· simp_all
· refine congr_arg Nat.succ (ih ?_)
simp_all [Function.funext_iff]⟩
variable [∀ a : α, Fintype (β a)]
/-- The depth of a finitely branching tree. -/
def depth : WType β → ℕ
| ⟨_, f⟩ => (Finset.sup Finset.univ fun n => depth (f n)) + 1
theorem depth_pos (t : WType β) : 0 < t.depth := by
cases t
apply Nat.succ_pos
theorem depth_lt_depth_mk (a : α) (f : β a → WType β) (i : β a) : depth (f i) < depth ⟨a, f⟩ :=
Nat.lt_succ_of_le (Finset.le_sup (f := (depth <| f ·)) (Finset.mem_univ i))
/-
Show that W types are encodable when `α` is an encodable fintype and for every `a : α`, `β a` is
encodable.
We define an auxiliary type `WType' β n` of trees of depth at most `n`, and then we show by
induction on `n` that these are all encodable. These auxiliary constructions are not interesting in
and of themselves, so we mark them as `private`.
-/
private abbrev WType' {α : Type*} (β : α → Type*) [∀ a : α, Fintype (β a)]
[∀ a : α, Encodable (β a)] (n : ℕ) :=
{ t : WType β // t.depth ≤ n }
variable [∀ a : α, Encodable (β a)]
private def encodable_zero : Encodable (WType' β 0) :=
let f : WType' β 0 → Empty := fun ⟨x, h⟩ => False.elim <| not_lt_of_ge h (WType.depth_pos _)
let finv : Empty → WType' β 0 := by
intro x
cases x
have : ∀ x, finv (f x) = x := fun ⟨x, h⟩ => False.elim <| not_lt_of_ge h (WType.depth_pos _)
Encodable.ofLeftInverse f finv this
private def f (n : ℕ) : WType' β (n + 1) → Σa : α, β a → WType' β n
| ⟨t, h⟩ => by
cases' t with a f
have h₀ : ∀ i : β a, WType.depth (f i) ≤ n := fun i =>
Nat.le_of_lt_succ (lt_of_lt_of_le (WType.depth_lt_depth_mk a f i) h)
exact ⟨a, fun i : β a => ⟨f i, h₀ i⟩⟩
private def finv (n : ℕ) : (Σa : α, β a → WType' β n) → WType' β (n + 1)
| ⟨a, f⟩ =>
let f' := fun i : β a => (f i).val
have : WType.depth ⟨a, f'⟩ ≤ n + 1 := Nat.add_le_add_right (Finset.sup_le fun b _ => (f b).2) 1
⟨⟨a, f'⟩, this⟩
variable [Encodable α]
private def encodable_succ (n : Nat) (h : Encodable (WType' β n)) : Encodable (WType' β (n + 1)) :=
Encodable.ofLeftInverse (f n) (finv n)
(by
rintro ⟨⟨_, _⟩, _⟩
rfl)
/-- `WType` is encodable when `α` is an encodable fintype and for every `a : α`, `β a` is
encodable. -/
instance : Encodable (WType β) := by
haveI h' : ∀ n, Encodable (WType' β n) := fun n => Nat.rec encodable_zero encodable_succ n
let f : WType β → Σn, WType' β n := fun t => ⟨t.depth, ⟨t, le_rfl⟩⟩
let finv : (Σn, WType' β n) → WType β := fun p => p.2.1
have : ∀ t, finv (f t) = t := fun t => rfl
exact Encodable.ofLeftInverse f finv this
end WType
|
Data\W\Cardinal.lean | /-
Copyright (c) 2021 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Data.W.Basic
import Mathlib.SetTheory.Cardinal.Ordinal
/-!
# Cardinality of W-types
This file proves some theorems about the cardinality of W-types. The main result is
`cardinal_mk_le_max_aleph0_of_finite` which says that if for any `a : α`,
`β a` is finite, then the cardinality of `WType β` is at most the maximum of the
cardinality of `α` and `ℵ₀`.
This can be used to prove theorems about the cardinality of algebraic constructions such as
polynomials. There is a surjection from a `WType` to `MvPolynomial` for example, and
this surjection can be used to put an upper bound on the cardinality of `MvPolynomial`.
## Tags
W, W type, cardinal, first order
-/
universe u v
variable {α : Type u} {β : α → Type v}
noncomputable section
namespace WType
open Cardinal
theorem cardinal_mk_eq_sum' : #(WType β) = sum (fun a : α => #(WType β) ^ lift.{u} #(β a)) :=
(mk_congr <| equivSigma β).trans <| by
simp_rw [mk_sigma, mk_arrow]; rw [lift_id'.{v, u}, lift_umax.{v, u}]
/-- `#(WType β)` is the least cardinal `κ` such that `sum (fun a : α ↦ κ ^ #(β a)) ≤ κ` -/
theorem cardinal_mk_le_of_le' {κ : Cardinal.{max u v}}
(hκ : (sum fun a : α => κ ^ lift.{u} #(β a)) ≤ κ) :
#(WType β) ≤ κ := by
induction' κ using Cardinal.inductionOn with γ
simp_rw [← lift_umax.{v, u}] at hκ
nth_rewrite 1 [← lift_id'.{v, u} #γ] at hκ
simp_rw [← mk_arrow, ← mk_sigma, le_def] at hκ
cases' hκ with hκ
exact Cardinal.mk_le_of_injective (elim_injective _ hκ.1 hκ.2)
/-- If, for any `a : α`, `β a` is finite, then the cardinality of `WType β`
is at most the maximum of the cardinality of `α` and `ℵ₀` -/
theorem cardinal_mk_le_max_aleph0_of_finite' [∀ a, Finite (β a)] :
#(WType β) ≤ max (lift.{v} #α) ℵ₀ :=
(isEmpty_or_nonempty α).elim
(by
intro h
rw [Cardinal.mk_eq_zero (WType β)]
exact zero_le _)
fun hn =>
let m := max (lift.{v} #α) ℵ₀
cardinal_mk_le_of_le' <|
calc
(Cardinal.sum fun a => m ^ lift.{u} #(β a)) ≤ lift.{v} #α * ⨆ a, m ^ lift.{u} #(β a) :=
Cardinal.sum_le_iSup_lift _
_ ≤ m * ⨆ a, m ^ lift.{u} #(β a) := mul_le_mul' (le_max_left _ _) le_rfl
_ = m :=
mul_eq_left (le_max_right _ _)
(ciSup_le' fun i => pow_le (le_max_right _ _) (lt_aleph0_of_finite _)) <|
pos_iff_ne_zero.1 <|
Order.succ_le_iff.1
(by
rw [succ_zero]
obtain ⟨a⟩ : Nonempty α := hn
refine le_trans ?_ (le_ciSup (bddAbove_range.{_, v} _) a)
rw [← power_zero]
exact
power_le_power_left
(pos_iff_ne_zero.1 (aleph0_pos.trans_le (le_max_right _ _))) (zero_le _))
variable {β : α → Type u}
theorem cardinal_mk_eq_sum : #(WType β) = sum (fun a : α => #(WType β) ^ #(β a)) :=
cardinal_mk_eq_sum'.trans <| by simp_rw [lift_id]
/-- `#(WType β)` is the least cardinal `κ` such that `sum (fun a : α ↦ κ ^ #(β a)) ≤ κ` -/
theorem cardinal_mk_le_of_le {κ : Cardinal.{u}} (hκ : (sum fun a : α => κ ^ #(β a)) ≤ κ) :
#(WType β) ≤ κ := cardinal_mk_le_of_le' <| by simp_rw [lift_id]; exact hκ
/-- If, for any `a : α`, `β a` is finite, then the cardinality of `WType β`
is at most the maximum of the cardinality of `α` and `ℵ₀` -/
theorem cardinal_mk_le_max_aleph0_of_finite [∀ a, Finite (β a)] : #(WType β) ≤ max #α ℵ₀ :=
cardinal_mk_le_max_aleph0_of_finite'.trans_eq <| by rw [lift_id]
end WType
|
Data\W\Constructions.lean | /-
Copyright (c) 2015 Joseph Hua. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Hua
-/
import Mathlib.Data.W.Basic
/-!
# Examples of W-types
We take the view of W types as inductive types.
Given `α : Type` and `β : α → Type`, the W type determined by this data, `WType β`, is the
inductively with constructors from `α` and arities of each constructor `a : α` given by `β a`.
This file contains `Nat` and `List` as examples of W types.
## Main results
* `WType.equivNat`: the construction of the naturals as a W-type is equivalent to `Nat`
* `WType.equivList`: the construction of lists on a type `γ` as a W-type is equivalent to `List γ`
-/
universe u v
namespace WType
-- For "W_type"
section Nat
/-- The constructors for the naturals -/
inductive Natα : Type
| zero : Natα
| succ : Natα
instance : Inhabited Natα :=
⟨Natα.zero⟩
/-- The arity of the constructors for the naturals, `zero` takes no arguments, `succ` takes one -/
def Natβ : Natα → Type
| Natα.zero => Empty
| Natα.succ => Unit
instance : Inhabited (Natβ Natα.succ) :=
⟨()⟩
/-- The isomorphism from the naturals to its corresponding `WType` -/
@[simp]
def ofNat : ℕ → WType Natβ
| Nat.zero => ⟨Natα.zero, Empty.elim⟩
| Nat.succ n => ⟨Natα.succ, fun _ ↦ ofNat n⟩
/-- The isomorphism from the `WType` of the naturals to the naturals -/
@[simp]
def toNat : WType Natβ → ℕ
| WType.mk Natα.zero _ => 0
| WType.mk Natα.succ f => (f ()).toNat.succ
theorem leftInverse_nat : Function.LeftInverse ofNat toNat
| WType.mk Natα.zero f => by
rw [toNat, ofNat]
congr
ext x
cases x
| WType.mk Natα.succ f => by
simp only [toNat, ofNat, leftInverse_nat (f ()), mk.injEq, heq_eq_eq, true_and]
rfl
theorem rightInverse_nat : Function.RightInverse ofNat toNat
| Nat.zero => rfl
| Nat.succ n => by rw [ofNat, toNat, rightInverse_nat n]
/-- The naturals are equivalent to their associated `WType` -/
def equivNat : WType Natβ ≃ ℕ where
toFun := toNat
invFun := ofNat
left_inv := leftInverse_nat
right_inv := rightInverse_nat
open Sum PUnit
/-- `WType.Natα` is equivalent to `PUnit ⊕ PUnit`.
This is useful when considering the associated polynomial endofunctor.
-/
@[simps]
def NatαEquivPUnitSumPUnit : Natα ≃ PUnit.{u + 1} ⊕ PUnit where
toFun c :=
match c with
| Natα.zero => inl unit
| Natα.succ => inr unit
invFun b :=
match b with
| inl _ => Natα.zero
| inr _ => Natα.succ
left_inv c :=
match c with
| Natα.zero => rfl
| Natα.succ => rfl
right_inv b :=
match b with
| inl _ => rfl
| inr _ => rfl
end Nat
section List
variable (γ : Type u)
/-- The constructors for lists.
There is "one constructor `cons x` for each `x : γ`",
since we view `List γ` as
```
| nil : List γ
| cons x₀ : List γ → List γ
| cons x₁ : List γ → List γ
| ⋮ γ many times
```
-/
inductive Listα : Type u
| nil : Listα
| cons : γ → Listα
instance : Inhabited (Listα γ) :=
⟨Listα.nil⟩
/-- The arities of each constructor for lists, `nil` takes no arguments, `cons hd` takes one -/
def Listβ : Listα γ → Type u
| Listα.nil => PEmpty
| Listα.cons _ => PUnit
instance (hd : γ) : Inhabited (Listβ γ (Listα.cons hd)) :=
⟨PUnit.unit⟩
/-- The isomorphism from lists to the `WType` construction of lists -/
@[simp]
def ofList : List γ → WType (Listβ γ)
| List.nil => ⟨Listα.nil, PEmpty.elim⟩
| List.cons hd tl => ⟨Listα.cons hd, fun _ ↦ ofList tl⟩
/-- The isomorphism from the `WType` construction of lists to lists -/
@[simp]
def toList : WType (Listβ γ) → List γ
| WType.mk Listα.nil _ => []
| WType.mk (Listα.cons hd) f => hd :: (f PUnit.unit).toList
theorem leftInverse_list : Function.LeftInverse (ofList γ) (toList _)
| WType.mk Listα.nil f => by
simp only [toList, ofList, mk.injEq, heq_eq_eq, true_and]
ext x
cases x
| WType.mk (Listα.cons x) f => by
simp only [ofList, leftInverse_list (f PUnit.unit), mk.injEq, heq_eq_eq, true_and]
rfl
theorem rightInverse_list : Function.RightInverse (ofList γ) (toList _)
| List.nil => rfl
| List.cons hd tl => by simp only [toList, rightInverse_list tl]
/-- Lists are equivalent to their associated `WType` -/
def equivList : WType (Listβ γ) ≃ List γ where
toFun := toList _
invFun := ofList _
left_inv := leftInverse_list _
right_inv := rightInverse_list _
/-- `WType.Listα` is equivalent to `γ` with an extra point.
This is useful when considering the associated polynomial endofunctor
-/
def ListαEquivPUnitSum : Listα γ ≃ PUnit.{v + 1} ⊕ γ where
toFun c :=
match c with
| Listα.nil => Sum.inl PUnit.unit
| Listα.cons x => Sum.inr x
invFun := Sum.elim (fun _ ↦ Listα.nil) Listα.cons
left_inv c :=
match c with
| Listα.nil => rfl
| Listα.cons _ => rfl
right_inv x :=
match x with
| Sum.inl PUnit.unit => rfl
| Sum.inr _ => rfl
end List
end WType
|
Data\ZMod\Algebra.lean | /-
Copyright (c) 2021 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Data.ZMod.Basic
import Mathlib.Algebra.Algebra.Defs
/-!
# The `ZMod n`-algebra structure on rings whose characteristic divides `n`
-/
namespace ZMod
variable (R : Type*) [Ring R]
instance (p : ℕ) : Subsingleton (Algebra (ZMod p) R) :=
⟨fun _ _ => Algebra.algebra_ext _ _ <| RingHom.congr_fun <| Subsingleton.elim _ _⟩
section
variable {n : ℕ} (m : ℕ) [CharP R m]
/-- The `ZMod n`-algebra structure on rings whose characteristic `m` divides `n`.
See note [reducible non-instances]. -/
abbrev algebra' (h : m ∣ n) : Algebra (ZMod n) R :=
{ ZMod.castHom h R with
smul := fun a r => cast a * r
commutes' := fun a r =>
show (cast a * r : R) = r * cast a by
rcases ZMod.intCast_surjective a with ⟨k, rfl⟩
show ZMod.castHom h R k * r = r * ZMod.castHom h R k
rw [map_intCast, Int.cast_comm]
smul_def' := fun a r => rfl }
end
/-- The `ZMod p`-algebra structure on a ring of characteristic `p`. This is not an
instance since it creates a diamond with `Algebra.id`.
See note [reducible non-instances]. -/
abbrev algebra (p : ℕ) [CharP R p] : Algebra (ZMod p) R :=
algebra' R p dvd_rfl
end ZMod
|
Data\ZMod\Basic.lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Algebra.Ring.Prod
import Mathlib.GroupTheory.OrderOfElement
import Mathlib.Tactic.FinCases
import Mathlib.Tactic.Linarith
/-!
# Integers mod `n`
Definition of the integers mod n, and the field structure on the integers mod p.
## Definitions
* `ZMod n`, which is for integers modulo a nat `n : ℕ`
* `val a` is defined as a natural number:
- for `a : ZMod 0` it is the absolute value of `a`
- for `a : ZMod n` with `0 < n` it is the least natural number in the equivalence class
* `valMinAbs` returns the integer closest to zero in the equivalence class.
* A coercion `cast` is defined from `ZMod n` into any ring.
This is a ring hom if the ring has characteristic dividing `n`
-/
assert_not_exists Submodule
open Function
namespace ZMod
instance charZero : CharZero (ZMod 0) := inferInstanceAs (CharZero ℤ)
/-- `val a` is a natural number defined as:
- for `a : ZMod 0` it is the absolute value of `a`
- for `a : ZMod n` with `0 < n` it is the least natural number in the equivalence class
See `ZMod.valMinAbs` for a variant that takes values in the integers.
-/
def val : ∀ {n : ℕ}, ZMod n → ℕ
| 0 => Int.natAbs
| n + 1 => ((↑) : Fin (n + 1) → ℕ)
theorem val_lt {n : ℕ} [NeZero n] (a : ZMod n) : a.val < n := by
cases n
· cases NeZero.ne 0 rfl
exact Fin.is_lt a
theorem val_le {n : ℕ} [NeZero n] (a : ZMod n) : a.val ≤ n :=
a.val_lt.le
@[simp]
theorem val_zero : ∀ {n}, (0 : ZMod n).val = 0
| 0 => rfl
| _ + 1 => rfl
@[simp]
theorem val_one' : (1 : ZMod 0).val = 1 :=
rfl
@[simp]
theorem val_neg' {n : ZMod 0} : (-n).val = n.val :=
Int.natAbs_neg n
@[simp]
theorem val_mul' {m n : ZMod 0} : (m * n).val = m.val * n.val :=
Int.natAbs_mul m n
@[simp]
theorem val_natCast {n : ℕ} (a : ℕ) : (a : ZMod n).val = a % n := by
cases n
· rw [Nat.mod_zero]
exact Int.natAbs_ofNat a
· apply Fin.val_natCast
@[deprecated (since := "2024-04-17")]
alias val_nat_cast := val_natCast
theorem val_unit' {n : ZMod 0} : IsUnit n ↔ n.val = 1 := by
simp only [val]
rw [Int.isUnit_iff, Int.natAbs_eq_iff, Nat.cast_one]
lemma eq_one_of_isUnit_natCast {n : ℕ} (h : IsUnit (n : ZMod 0)) : n = 1 := by
rw [← Nat.mod_zero n, ← val_natCast, val_unit'.mp h]
theorem val_natCast_of_lt {n a : ℕ} (h : a < n) : (a : ZMod n).val = a := by
rwa [val_natCast, Nat.mod_eq_of_lt]
@[deprecated (since := "2024-04-17")]
alias val_nat_cast_of_lt := val_natCast_of_lt
instance charP (n : ℕ) : CharP (ZMod n) n where
cast_eq_zero_iff' := by
intro k
cases' n with n
· simp [zero_dvd_iff, Int.natCast_eq_zero, Nat.zero_eq]
· exact Fin.natCast_eq_zero
@[simp]
theorem addOrderOf_one (n : ℕ) : addOrderOf (1 : ZMod n) = n :=
CharP.eq _ (CharP.addOrderOf_one _) (ZMod.charP n)
/-- This lemma works in the case in which `ZMod n` is not infinite, i.e. `n ≠ 0`. The version
where `a ≠ 0` is `addOrderOf_coe'`. -/
@[simp]
theorem addOrderOf_coe (a : ℕ) {n : ℕ} (n0 : n ≠ 0) : addOrderOf (a : ZMod n) = n / n.gcd a := by
cases' a with a
· simp only [Nat.zero_eq, Nat.cast_zero, addOrderOf_zero, Nat.gcd_zero_right,
Nat.pos_of_ne_zero n0, Nat.div_self]
rw [← Nat.smul_one_eq_cast, addOrderOf_nsmul' _ a.succ_ne_zero, ZMod.addOrderOf_one]
/-- This lemma works in the case in which `a ≠ 0`. The version where
`ZMod n` is not infinite, i.e. `n ≠ 0`, is `addOrderOf_coe`. -/
@[simp]
theorem addOrderOf_coe' {a : ℕ} (n : ℕ) (a0 : a ≠ 0) : addOrderOf (a : ZMod n) = n / n.gcd a := by
rw [← Nat.smul_one_eq_cast, addOrderOf_nsmul' _ a0, ZMod.addOrderOf_one]
/-- We have that `ringChar (ZMod n) = n`. -/
theorem ringChar_zmod_n (n : ℕ) : ringChar (ZMod n) = n := by
rw [ringChar.eq_iff]
exact ZMod.charP n
-- @[simp] -- Porting note (#10618): simp can prove this
theorem natCast_self (n : ℕ) : (n : ZMod n) = 0 :=
CharP.cast_eq_zero (ZMod n) n
@[deprecated (since := "2024-04-17")]
alias nat_cast_self := natCast_self
@[simp]
theorem natCast_self' (n : ℕ) : (n + 1 : ZMod (n + 1)) = 0 := by
rw [← Nat.cast_add_one, natCast_self (n + 1)]
@[deprecated (since := "2024-04-17")]
alias nat_cast_self' := natCast_self'
section UniversalProperty
variable {n : ℕ} {R : Type*}
section
variable [AddGroupWithOne R]
/-- Cast an integer modulo `n` to another semiring.
This function is a morphism if the characteristic of `R` divides `n`.
See `ZMod.castHom` for a bundled version. -/
def cast : ∀ {n : ℕ}, ZMod n → R
| 0 => Int.cast
| _ + 1 => fun i => i.val
@[simp]
theorem cast_zero : (cast (0 : ZMod n) : R) = 0 := by
delta ZMod.cast
cases n
· exact Int.cast_zero
· simp
theorem cast_eq_val [NeZero n] (a : ZMod n) : (cast a : R) = a.val := by
cases n
· cases NeZero.ne 0 rfl
rfl
variable {S : Type*} [AddGroupWithOne S]
@[simp]
theorem _root_.Prod.fst_zmod_cast (a : ZMod n) : (cast a : R × S).fst = cast a := by
cases n
· rfl
· simp [ZMod.cast]
@[simp]
theorem _root_.Prod.snd_zmod_cast (a : ZMod n) : (cast a : R × S).snd = cast a := by
cases n
· rfl
· simp [ZMod.cast]
end
/-- So-named because the coercion is `Nat.cast` into `ZMod`. For `Nat.cast` into an arbitrary ring,
see `ZMod.natCast_val`. -/
theorem natCast_zmod_val {n : ℕ} [NeZero n] (a : ZMod n) : (a.val : ZMod n) = a := by
cases n
· cases NeZero.ne 0 rfl
· apply Fin.cast_val_eq_self
@[deprecated (since := "2024-04-17")]
alias nat_cast_zmod_val := natCast_zmod_val
theorem natCast_rightInverse [NeZero n] : Function.RightInverse val ((↑) : ℕ → ZMod n) :=
natCast_zmod_val
@[deprecated (since := "2024-04-17")]
alias nat_cast_rightInverse := natCast_rightInverse
theorem natCast_zmod_surjective [NeZero n] : Function.Surjective ((↑) : ℕ → ZMod n) :=
natCast_rightInverse.surjective
@[deprecated (since := "2024-04-17")]
alias nat_cast_zmod_surjective := natCast_zmod_surjective
/-- So-named because the outer coercion is `Int.cast` into `ZMod`. For `Int.cast` into an arbitrary
ring, see `ZMod.intCast_cast`. -/
@[norm_cast]
theorem intCast_zmod_cast (a : ZMod n) : ((cast a : ℤ) : ZMod n) = a := by
cases n
· simp [ZMod.cast, ZMod]
· dsimp [ZMod.cast, ZMod]
erw [Int.cast_natCast, Fin.cast_val_eq_self]
@[deprecated (since := "2024-04-17")]
alias int_cast_zmod_cast := intCast_zmod_cast
theorem intCast_rightInverse : Function.RightInverse (cast : ZMod n → ℤ) ((↑) : ℤ → ZMod n) :=
intCast_zmod_cast
@[deprecated (since := "2024-04-17")]
alias int_cast_rightInverse := intCast_rightInverse
theorem intCast_surjective : Function.Surjective ((↑) : ℤ → ZMod n) :=
intCast_rightInverse.surjective
@[deprecated (since := "2024-04-17")]
alias int_cast_surjective := intCast_surjective
theorem cast_id : ∀ (n) (i : ZMod n), (ZMod.cast i : ZMod n) = i
| 0, _ => Int.cast_id
| _ + 1, i => natCast_zmod_val i
@[simp]
theorem cast_id' : (ZMod.cast : ZMod n → ZMod n) = id :=
funext (cast_id n)
variable (R) [Ring R]
/-- The coercions are respectively `Nat.cast` and `ZMod.cast`. -/
@[simp]
theorem natCast_comp_val [NeZero n] : ((↑) : ℕ → R) ∘ (val : ZMod n → ℕ) = cast := by
cases n
· cases NeZero.ne 0 rfl
rfl
@[deprecated (since := "2024-04-17")]
alias nat_cast_comp_val := natCast_comp_val
/-- The coercions are respectively `Int.cast`, `ZMod.cast`, and `ZMod.cast`. -/
@[simp]
theorem intCast_comp_cast : ((↑) : ℤ → R) ∘ (cast : ZMod n → ℤ) = cast := by
cases n
· exact congr_arg (Int.cast ∘ ·) ZMod.cast_id'
· ext
simp [ZMod, ZMod.cast]
@[deprecated (since := "2024-04-17")]
alias int_cast_comp_cast := intCast_comp_cast
variable {R}
@[simp]
theorem natCast_val [NeZero n] (i : ZMod n) : (i.val : R) = cast i :=
congr_fun (natCast_comp_val R) i
@[deprecated (since := "2024-04-17")]
alias nat_cast_val := natCast_val
@[simp]
theorem intCast_cast (i : ZMod n) : ((cast i : ℤ) : R) = cast i :=
congr_fun (intCast_comp_cast R) i
@[deprecated (since := "2024-04-17")]
alias int_cast_cast := intCast_cast
theorem cast_add_eq_ite {n : ℕ} (a b : ZMod n) :
(cast (a + b) : ℤ) =
if (n : ℤ) ≤ cast a + cast b then (cast a + cast b - n : ℤ) else cast a + cast b := by
cases' n with n
· simp; rfl
change Fin (n + 1) at a b
change ((((a + b) : Fin (n + 1)) : ℕ) : ℤ) = if ((n + 1 : ℕ) : ℤ) ≤ (a : ℕ) + b then _ else _
simp only [Fin.val_add_eq_ite, Int.ofNat_succ, Int.ofNat_le]
norm_cast
split_ifs with h
· rw [Nat.cast_sub h]
congr
· rfl
section CharDvd
/-! If the characteristic of `R` divides `n`, then `cast` is a homomorphism. -/
variable {m : ℕ} [CharP R m]
@[simp]
theorem cast_one (h : m ∣ n) : (cast (1 : ZMod n) : R) = 1 := by
cases' n with n
· exact Int.cast_one
show ((1 % (n + 1) : ℕ) : R) = 1
cases n
· rw [Nat.dvd_one] at h
subst m
subsingleton [CharP.CharOne.subsingleton]
rw [Nat.mod_eq_of_lt]
· exact Nat.cast_one
exact Nat.lt_of_sub_eq_succ rfl
theorem cast_add (h : m ∣ n) (a b : ZMod n) : (cast (a + b : ZMod n) : R) = cast a + cast b := by
cases n
· apply Int.cast_add
symm
dsimp [ZMod, ZMod.cast]
erw [← Nat.cast_add, ← sub_eq_zero, ← Nat.cast_sub (Nat.mod_le _ _),
@CharP.cast_eq_zero_iff R _ m]
exact h.trans (Nat.dvd_sub_mod _)
theorem cast_mul (h : m ∣ n) (a b : ZMod n) : (cast (a * b : ZMod n) : R) = cast a * cast b := by
cases n
· apply Int.cast_mul
symm
dsimp [ZMod, ZMod.cast]
erw [← Nat.cast_mul, ← sub_eq_zero, ← Nat.cast_sub (Nat.mod_le _ _),
@CharP.cast_eq_zero_iff R _ m]
exact h.trans (Nat.dvd_sub_mod _)
/-- The canonical ring homomorphism from `ZMod n` to a ring of characteristic dividing `n`.
See also `ZMod.lift` for a generalized version working in `AddGroup`s.
-/
def castHom (h : m ∣ n) (R : Type*) [Ring R] [CharP R m] : ZMod n →+* R where
toFun := cast
map_zero' := cast_zero
map_one' := cast_one h
map_add' := cast_add h
map_mul' := cast_mul h
@[simp]
theorem castHom_apply {h : m ∣ n} (i : ZMod n) : castHom h R i = cast i :=
rfl
@[simp]
theorem cast_sub (h : m ∣ n) (a b : ZMod n) : (cast (a - b : ZMod n) : R) = cast a - cast b :=
(castHom h R).map_sub a b
@[simp]
theorem cast_neg (h : m ∣ n) (a : ZMod n) : (cast (-a : ZMod n) : R) = -(cast a) :=
(castHom h R).map_neg a
@[simp]
theorem cast_pow (h : m ∣ n) (a : ZMod n) (k : ℕ) : (cast (a ^ k : ZMod n) : R) = (cast a) ^ k :=
(castHom h R).map_pow a k
@[simp, norm_cast]
theorem cast_natCast (h : m ∣ n) (k : ℕ) : (cast (k : ZMod n) : R) = k :=
map_natCast (castHom h R) k
@[deprecated (since := "2024-04-17")]
alias cast_nat_cast := cast_natCast
@[simp, norm_cast]
theorem cast_intCast (h : m ∣ n) (k : ℤ) : (cast (k : ZMod n) : R) = k :=
map_intCast (castHom h R) k
@[deprecated (since := "2024-04-17")]
alias cast_int_cast := cast_intCast
end CharDvd
section CharEq
/-! Some specialised simp lemmas which apply when `R` has characteristic `n`. -/
variable [CharP R n]
@[simp]
theorem cast_one' : (cast (1 : ZMod n) : R) = 1 :=
cast_one dvd_rfl
@[simp]
theorem cast_add' (a b : ZMod n) : (cast (a + b : ZMod n) : R) = cast a + cast b :=
cast_add dvd_rfl a b
@[simp]
theorem cast_mul' (a b : ZMod n) : (cast (a * b : ZMod n) : R) = cast a * cast b :=
cast_mul dvd_rfl a b
@[simp]
theorem cast_sub' (a b : ZMod n) : (cast (a - b : ZMod n) : R) = cast a - cast b :=
cast_sub dvd_rfl a b
@[simp]
theorem cast_pow' (a : ZMod n) (k : ℕ) : (cast (a ^ k : ZMod n) : R) = (cast a : R) ^ k :=
cast_pow dvd_rfl a k
@[simp, norm_cast]
theorem cast_natCast' (k : ℕ) : (cast (k : ZMod n) : R) = k :=
cast_natCast dvd_rfl k
@[deprecated (since := "2024-04-17")]
alias cast_nat_cast' := cast_natCast'
@[simp, norm_cast]
theorem cast_intCast' (k : ℤ) : (cast (k : ZMod n) : R) = k :=
cast_intCast dvd_rfl k
@[deprecated (since := "2024-04-17")]
alias cast_int_cast' := cast_intCast'
variable (R)
theorem castHom_injective : Function.Injective (ZMod.castHom (dvd_refl n) R) := by
rw [injective_iff_map_eq_zero]
intro x
obtain ⟨k, rfl⟩ := ZMod.intCast_surjective x
rw [map_intCast, CharP.intCast_eq_zero_iff R n, CharP.intCast_eq_zero_iff (ZMod n) n]
exact id
theorem castHom_bijective [Fintype R] (h : Fintype.card R = n) :
Function.Bijective (ZMod.castHom (dvd_refl n) R) := by
haveI : NeZero n :=
⟨by
intro hn
rw [hn] at h
exact (Fintype.card_eq_zero_iff.mp h).elim' 0⟩
rw [Fintype.bijective_iff_injective_and_card, ZMod.card, h, eq_self_iff_true, and_true_iff]
apply ZMod.castHom_injective
/-- The unique ring isomorphism between `ZMod n` and a ring `R`
of characteristic `n` and cardinality `n`. -/
noncomputable def ringEquiv [Fintype R] (h : Fintype.card R = n) : ZMod n ≃+* R :=
RingEquiv.ofBijective _ (ZMod.castHom_bijective R h)
/-- The unique ring isomorphism between `ZMod p` and a ring `R` of cardinality a prime `p`.
If you need any property of this isomorphism, first of all use `ringEquivOfPrime_eq_ringEquiv`
below (after `have : CharP R p := ...`) and deduce it by the results about `ZMod.ringEquiv`. -/
noncomputable def ringEquivOfPrime [Fintype R] {p : ℕ} (hp : p.Prime) (hR : Fintype.card R = p) :
ZMod p ≃+* R :=
have : Nontrivial R := Fintype.one_lt_card_iff_nontrivial.1 (hR ▸ hp.one_lt)
-- The following line exists as `charP_of_card_eq_prime` in `Mathlib.Algebra.CharP.CharAndCard`.
have : CharP R p := (CharP.charP_iff_prime_eq_zero hp).2 (hR ▸ Nat.cast_card_eq_zero R)
ZMod.ringEquiv R hR
@[simp]
lemma ringEquivOfPrime_eq_ringEquiv [Fintype R] {p : ℕ} [CharP R p] (hp : p.Prime)
(hR : Fintype.card R = p) : ringEquivOfPrime R hp hR = ringEquiv R hR := rfl
/-- The identity between `ZMod m` and `ZMod n` when `m = n`, as a ring isomorphism. -/
def ringEquivCongr {m n : ℕ} (h : m = n) : ZMod m ≃+* ZMod n := by
cases' m with m <;> cases' n with n
· exact RingEquiv.refl _
· exfalso
exact n.succ_ne_zero h.symm
· exfalso
exact m.succ_ne_zero h
· exact
{ finCongr h with
map_mul' := fun a b => by
dsimp [ZMod]
ext
rw [Fin.coe_cast, Fin.coe_mul, Fin.coe_mul, Fin.coe_cast, Fin.coe_cast, ← h]
map_add' := fun a b => by
dsimp [ZMod]
ext
rw [Fin.coe_cast, Fin.val_add, Fin.val_add, Fin.coe_cast, Fin.coe_cast, ← h] }
@[simp] lemma ringEquivCongr_refl (a : ℕ) : ringEquivCongr (rfl : a = a) = .refl _ := by
cases a <;> rfl
lemma ringEquivCongr_refl_apply {a : ℕ} (x : ZMod a) : ringEquivCongr rfl x = x := by
rw [ringEquivCongr_refl]
rfl
lemma ringEquivCongr_symm {a b : ℕ} (hab : a = b) :
(ringEquivCongr hab).symm = ringEquivCongr hab.symm := by
subst hab
cases a <;> rfl
lemma ringEquivCongr_trans {a b c : ℕ} (hab : a = b) (hbc : b = c) :
(ringEquivCongr hab).trans (ringEquivCongr hbc) = ringEquivCongr (hab.trans hbc) := by
subst hab hbc
cases a <;> rfl
lemma ringEquivCongr_ringEquivCongr_apply {a b c : ℕ} (hab : a = b) (hbc : b = c) (x : ZMod a) :
ringEquivCongr hbc (ringEquivCongr hab x) = ringEquivCongr (hab.trans hbc) x := by
rw [← ringEquivCongr_trans hab hbc]
rfl
lemma ringEquivCongr_val {a b : ℕ} (h : a = b) (x : ZMod a) :
ZMod.val ((ZMod.ringEquivCongr h) x) = ZMod.val x := by
subst h
cases a <;> rfl
lemma ringEquivCongr_intCast {a b : ℕ} (h : a = b) (z : ℤ) :
ZMod.ringEquivCongr h z = z := by
subst h
cases a <;> rfl
@[deprecated (since := "2024-05-25")] alias int_coe_ringEquivCongr := ringEquivCongr_intCast
end CharEq
end UniversalProperty
variable {m n : ℕ}
@[simp]
theorem val_eq_zero : ∀ {n : ℕ} (a : ZMod n), a.val = 0 ↔ a = 0
| 0, a => Int.natAbs_eq_zero
| n + 1, a => by
rw [Fin.ext_iff]
exact Iff.rfl
theorem intCast_eq_intCast_iff (a b : ℤ) (c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a ≡ b [ZMOD c] :=
CharP.intCast_eq_intCast (ZMod c) c
@[deprecated (since := "2024-04-17")]
alias int_cast_eq_int_cast_iff := intCast_eq_intCast_iff
theorem intCast_eq_intCast_iff' (a b : ℤ) (c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a % c = b % c :=
ZMod.intCast_eq_intCast_iff a b c
@[deprecated (since := "2024-04-17")]
alias int_cast_eq_int_cast_iff' := intCast_eq_intCast_iff'
theorem val_intCast {n : ℕ} (a : ℤ) [NeZero n] : ↑(a : ZMod n).val = a % n := by
have hle : (0 : ℤ) ≤ ↑(a : ZMod n).val := Int.natCast_nonneg _
have hlt : ↑(a : ZMod n).val < (n : ℤ) := Int.ofNat_lt.mpr (ZMod.val_lt a)
refine (Int.emod_eq_of_lt hle hlt).symm.trans ?_
rw [← ZMod.intCast_eq_intCast_iff', Int.cast_natCast, ZMod.natCast_val, ZMod.cast_id]
@[deprecated (since := "2024-04-17")]
alias val_int_cast := val_intCast
theorem natCast_eq_natCast_iff (a b c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a ≡ b [MOD c] := by
simpa [Int.natCast_modEq_iff] using ZMod.intCast_eq_intCast_iff a b c
@[deprecated (since := "2024-04-17")]
alias nat_cast_eq_nat_cast_iff := natCast_eq_natCast_iff
theorem natCast_eq_natCast_iff' (a b c : ℕ) : (a : ZMod c) = (b : ZMod c) ↔ a % c = b % c :=
ZMod.natCast_eq_natCast_iff a b c
@[deprecated (since := "2024-04-17")]
alias nat_cast_eq_nat_cast_iff' := natCast_eq_natCast_iff'
theorem intCast_zmod_eq_zero_iff_dvd (a : ℤ) (b : ℕ) : (a : ZMod b) = 0 ↔ (b : ℤ) ∣ a := by
rw [← Int.cast_zero, ZMod.intCast_eq_intCast_iff, Int.modEq_zero_iff_dvd]
@[deprecated (since := "2024-04-17")]
alias int_cast_zmod_eq_zero_iff_dvd := intCast_zmod_eq_zero_iff_dvd
theorem intCast_eq_intCast_iff_dvd_sub (a b : ℤ) (c : ℕ) : (a : ZMod c) = ↑b ↔ ↑c ∣ b - a := by
rw [ZMod.intCast_eq_intCast_iff, Int.modEq_iff_dvd]
@[deprecated (since := "2024-04-17")]
alias int_cast_eq_int_cast_iff_dvd_sub := intCast_eq_intCast_iff_dvd_sub
theorem natCast_zmod_eq_zero_iff_dvd (a b : ℕ) : (a : ZMod b) = 0 ↔ b ∣ a := by
rw [← Nat.cast_zero, ZMod.natCast_eq_natCast_iff, Nat.modEq_zero_iff_dvd]
@[deprecated (since := "2024-04-17")]
alias nat_cast_zmod_eq_zero_iff_dvd := natCast_zmod_eq_zero_iff_dvd
theorem coe_intCast (a : ℤ) : cast (a : ZMod n) = a % n := by
cases n
· rw [Int.ofNat_zero, Int.emod_zero, Int.cast_id]; rfl
· rw [← val_intCast, val]; rfl
@[deprecated (since := "2024-04-17")]
alias coe_int_cast := coe_intCast
lemma intCast_cast_add (x y : ZMod n) : (cast (x + y) : ℤ) = (cast x + cast y) % n := by
rw [← ZMod.coe_intCast, Int.cast_add, ZMod.intCast_zmod_cast, ZMod.intCast_zmod_cast]
lemma intCast_cast_mul (x y : ZMod n) : (cast (x * y) : ℤ) = cast x * cast y % n := by
rw [← ZMod.coe_intCast, Int.cast_mul, ZMod.intCast_zmod_cast, ZMod.intCast_zmod_cast]
lemma intCast_cast_sub (x y : ZMod n) : (cast (x - y) : ℤ) = (cast x - cast y) % n := by
rw [← ZMod.coe_intCast, Int.cast_sub, ZMod.intCast_zmod_cast, ZMod.intCast_zmod_cast]
lemma intCast_cast_neg (x : ZMod n) : (cast (-x) : ℤ) = -cast x % n := by
rw [← ZMod.coe_intCast, Int.cast_neg, ZMod.intCast_zmod_cast]
@[simp]
theorem val_neg_one (n : ℕ) : (-1 : ZMod n.succ).val = n := by
dsimp [val, Fin.coe_neg]
cases n
· simp [Nat.mod_one]
· dsimp [ZMod, ZMod.cast]
rw [Fin.coe_neg_one]
/-- `-1 : ZMod n` lifts to `n - 1 : R`. This avoids the characteristic assumption in `cast_neg`. -/
theorem cast_neg_one {R : Type*} [Ring R] (n : ℕ) : cast (-1 : ZMod n) = (n - 1 : R) := by
cases' n with n
· dsimp [ZMod, ZMod.cast]; simp
· rw [← natCast_val, val_neg_one, Nat.cast_succ, add_sub_cancel_right]
theorem cast_sub_one {R : Type*} [Ring R] {n : ℕ} (k : ZMod n) :
(cast (k - 1 : ZMod n) : R) = (if k = 0 then (n : R) else cast k) - 1 := by
split_ifs with hk
· rw [hk, zero_sub, ZMod.cast_neg_one]
· cases n
· dsimp [ZMod, ZMod.cast]
rw [Int.cast_sub, Int.cast_one]
· dsimp [ZMod, ZMod.cast, ZMod.val]
rw [Fin.coe_sub_one, if_neg]
· rw [Nat.cast_sub, Nat.cast_one]
rwa [Fin.ext_iff, Fin.val_zero, ← Ne, ← Nat.one_le_iff_ne_zero] at hk
· exact hk
theorem natCast_eq_iff (p : ℕ) (n : ℕ) (z : ZMod p) [NeZero p] :
↑n = z ↔ ∃ k, n = z.val + p * k := by
constructor
· rintro rfl
refine ⟨n / p, ?_⟩
rw [val_natCast, Nat.mod_add_div]
· rintro ⟨k, rfl⟩
rw [Nat.cast_add, natCast_zmod_val, Nat.cast_mul, natCast_self, zero_mul,
add_zero]
theorem intCast_eq_iff (p : ℕ) (n : ℤ) (z : ZMod p) [NeZero p] :
↑n = z ↔ ∃ k, n = z.val + p * k := by
constructor
· rintro rfl
refine ⟨n / p, ?_⟩
rw [val_intCast, Int.emod_add_ediv]
· rintro ⟨k, rfl⟩
rw [Int.cast_add, Int.cast_mul, Int.cast_natCast, Int.cast_natCast, natCast_val,
ZMod.natCast_self, zero_mul, add_zero, cast_id]
@[deprecated (since := "2024-05-25")] alias nat_coe_zmod_eq_iff := natCast_eq_iff
@[deprecated (since := "2024-05-25")] alias int_coe_zmod_eq_iff := intCast_eq_iff
@[push_cast, simp]
theorem intCast_mod (a : ℤ) (b : ℕ) : ((a % b : ℤ) : ZMod b) = (a : ZMod b) := by
rw [ZMod.intCast_eq_intCast_iff]
apply Int.mod_modEq
@[deprecated (since := "2024-04-17")]
alias int_cast_mod := intCast_mod
theorem ker_intCastAddHom (n : ℕ) :
(Int.castAddHom (ZMod n)).ker = AddSubgroup.zmultiples (n : ℤ) := by
ext
rw [Int.mem_zmultiples_iff, AddMonoidHom.mem_ker, Int.coe_castAddHom,
intCast_zmod_eq_zero_iff_dvd]
@[deprecated (since := "2024-04-17")]
alias ker_int_castAddHom := ker_intCastAddHom
theorem cast_injective_of_le {m n : ℕ} [nzm : NeZero m] (h : m ≤ n) :
Function.Injective (@cast (ZMod n) _ m) := by
cases m with
| zero => cases nzm; simp_all
| succ m =>
rintro ⟨x, hx⟩ ⟨y, hy⟩ f
simp only [cast, val, natCast_eq_natCast_iff',
Nat.mod_eq_of_lt (hx.trans_le h), Nat.mod_eq_of_lt (hy.trans_le h)] at f
apply Fin.ext
exact f
theorem cast_zmod_eq_zero_iff_of_le {m n : ℕ} [NeZero m] (h : m ≤ n) (a : ZMod m) :
(cast a : ZMod n) = 0 ↔ a = 0 := by
rw [← ZMod.cast_zero (n := m)]
exact Injective.eq_iff' (cast_injective_of_le h) rfl
-- Porting note: commented
-- unseal Int.NonNeg
@[simp]
theorem natCast_toNat (p : ℕ) : ∀ {z : ℤ} (_h : 0 ≤ z), (z.toNat : ZMod p) = z
| (n : ℕ), _h => by simp only [Int.cast_natCast, Int.toNat_natCast]
| Int.negSucc n, h => by simp at h
@[deprecated (since := "2024-04-17")]
alias nat_cast_toNat := natCast_toNat
theorem val_injective (n : ℕ) [NeZero n] : Function.Injective (val : ZMod n → ℕ) := by
cases n
· cases NeZero.ne 0 rfl
intro a b h
dsimp [ZMod]
ext
exact h
theorem val_one_eq_one_mod (n : ℕ) : (1 : ZMod n).val = 1 % n := by
rw [← Nat.cast_one, val_natCast]
theorem val_one (n : ℕ) [Fact (1 < n)] : (1 : ZMod n).val = 1 := by
rw [val_one_eq_one_mod]
exact Nat.mod_eq_of_lt Fact.out
lemma val_one'' : ∀ {n}, n ≠ 1 → (1 : ZMod n).val = 1
| 0, _ => rfl
| 1, hn => by cases hn rfl
| n + 2, _ =>
haveI : Fact (1 < n + 2) := ⟨by simp⟩
ZMod.val_one _
theorem val_add {n : ℕ} [NeZero n] (a b : ZMod n) : (a + b).val = (a.val + b.val) % n := by
cases n
· cases NeZero.ne 0 rfl
· apply Fin.val_add
theorem val_add_of_lt {n : ℕ} {a b : ZMod n} (h : a.val + b.val < n) :
(a + b).val = a.val + b.val := by
have : NeZero n := by constructor; rintro rfl; simp at h
rw [ZMod.val_add, Nat.mod_eq_of_lt h]
theorem val_add_val_of_le {n : ℕ} [NeZero n] {a b : ZMod n} (h : n ≤ a.val + b.val) :
a.val + b.val = (a + b).val + n := by
rw [val_add, Nat.add_mod_add_of_le_add_mod, Nat.mod_eq_of_lt (val_lt _),
Nat.mod_eq_of_lt (val_lt _)]
rwa [Nat.mod_eq_of_lt (val_lt _), Nat.mod_eq_of_lt (val_lt _)]
theorem val_add_of_le {n : ℕ} [NeZero n] {a b : ZMod n} (h : n ≤ a.val + b.val) :
(a + b).val = a.val + b.val - n := by
rw [val_add_val_of_le h]
exact eq_tsub_of_add_eq rfl
theorem val_add_le {n : ℕ} (a b : ZMod n) : (a + b).val ≤ a.val + b.val := by
cases n
· simp [ZMod.val]; apply Int.natAbs_add_le
· simp [ZMod.val_add]; apply Nat.mod_le
theorem val_mul {n : ℕ} (a b : ZMod n) : (a * b).val = a.val * b.val % n := by
cases n
· rw [Nat.mod_zero]
apply Int.natAbs_mul
· apply Fin.val_mul
theorem val_mul_le {n : ℕ} (a b : ZMod n) : (a * b).val ≤ a.val * b.val := by
rw [val_mul]
apply Nat.mod_le
theorem val_mul_of_lt {n : ℕ} {a b : ZMod n} (h : a.val * b.val < n) :
(a * b).val = a.val * b.val := by
rw [val_mul]
apply Nat.mod_eq_of_lt h
instance nontrivial (n : ℕ) [Fact (1 < n)] : Nontrivial (ZMod n) :=
⟨⟨0, 1, fun h =>
zero_ne_one <|
calc
0 = (0 : ZMod n).val := by rw [val_zero]
_ = (1 : ZMod n).val := congr_arg ZMod.val h
_ = 1 := val_one n
⟩⟩
instance nontrivial' : Nontrivial (ZMod 0) := by
delta ZMod; infer_instance
/-- The inversion on `ZMod n`.
It is setup in such a way that `a * a⁻¹` is equal to `gcd a.val n`.
In particular, if `a` is coprime to `n`, and hence a unit, `a * a⁻¹ = 1`. -/
def inv : ∀ n : ℕ, ZMod n → ZMod n
| 0, i => Int.sign i
| n + 1, i => Nat.gcdA i.val (n + 1)
instance (n : ℕ) : Inv (ZMod n) :=
⟨inv n⟩
@[nolint unusedHavesSuffices]
theorem inv_zero : ∀ n : ℕ, (0 : ZMod n)⁻¹ = 0
| 0 => Int.sign_zero
| n + 1 =>
show (Nat.gcdA _ (n + 1) : ZMod (n + 1)) = 0 by
rw [val_zero]
unfold Nat.gcdA Nat.xgcd Nat.xgcdAux
rfl
theorem mul_inv_eq_gcd {n : ℕ} (a : ZMod n) : a * a⁻¹ = Nat.gcd a.val n := by
cases' n with n
· dsimp [ZMod] at a ⊢
calc
_ = a * Int.sign a := rfl
_ = a.natAbs := by rw [Int.mul_sign]
_ = a.natAbs.gcd 0 := by rw [Nat.gcd_zero_right]
· calc
a * a⁻¹ = a * a⁻¹ + n.succ * Nat.gcdB (val a) n.succ := by
rw [natCast_self, zero_mul, add_zero]
_ = ↑(↑a.val * Nat.gcdA (val a) n.succ + n.succ * Nat.gcdB (val a) n.succ) := by
push_cast
rw [natCast_zmod_val]
rfl
_ = Nat.gcd a.val n.succ := by rw [← Nat.gcd_eq_gcd_ab a.val n.succ]; rfl
@[simp] protected lemma inv_one (n : ℕ) : (1⁻¹ : ZMod n) = 1 := by
obtain rfl | hn := eq_or_ne n 1
· exact Subsingleton.elim _ _
· simpa [ZMod.val_one'' hn] using mul_inv_eq_gcd (1 : ZMod n)
@[simp]
theorem natCast_mod (a : ℕ) (n : ℕ) : ((a % n : ℕ) : ZMod n) = a := by
conv =>
rhs
rw [← Nat.mod_add_div a n]
simp
@[deprecated (since := "2024-04-17")]
alias nat_cast_mod := natCast_mod
theorem eq_iff_modEq_nat (n : ℕ) {a b : ℕ} : (a : ZMod n) = b ↔ a ≡ b [MOD n] := by
cases n
· simp [Nat.ModEq, Int.natCast_inj, Nat.mod_zero]
· rw [Fin.ext_iff, Nat.ModEq, ← val_natCast, ← val_natCast]
exact Iff.rfl
theorem coe_mul_inv_eq_one {n : ℕ} (x : ℕ) (h : Nat.Coprime x n) :
((x : ZMod n) * (x : ZMod n)⁻¹) = 1 := by
rw [Nat.Coprime, Nat.gcd_comm, Nat.gcd_rec] at h
rw [mul_inv_eq_gcd, val_natCast, h, Nat.cast_one]
lemma mul_val_inv (hmn : m.Coprime n) : (m * (m⁻¹ : ZMod n).val : ZMod n) = 1 := by
obtain rfl | hn := eq_or_ne n 0
· simp [m.coprime_zero_right.1 hmn]
haveI : NeZero n := ⟨hn⟩
rw [ZMod.natCast_zmod_val, ZMod.coe_mul_inv_eq_one _ hmn]
lemma val_inv_mul (hmn : m.Coprime n) : ((m⁻¹ : ZMod n).val * m : ZMod n) = 1 := by
rw [mul_comm, mul_val_inv hmn]
/-- `unitOfCoprime` makes an element of `(ZMod n)ˣ` given
a natural number `x` and a proof that `x` is coprime to `n` -/
def unitOfCoprime {n : ℕ} (x : ℕ) (h : Nat.Coprime x n) : (ZMod n)ˣ :=
⟨x, x⁻¹, coe_mul_inv_eq_one x h, by rw [mul_comm, coe_mul_inv_eq_one x h]⟩
@[simp]
theorem coe_unitOfCoprime {n : ℕ} (x : ℕ) (h : Nat.Coprime x n) :
(unitOfCoprime x h : ZMod n) = x :=
rfl
theorem val_coe_unit_coprime {n : ℕ} (u : (ZMod n)ˣ) : Nat.Coprime (u : ZMod n).val n := by
cases' n with n
· rcases Int.units_eq_one_or u with (rfl | rfl) <;> simp
apply Nat.coprime_of_mul_modEq_one ((u⁻¹ : Units (ZMod (n + 1))) : ZMod (n + 1)).val
have := Units.ext_iff.1 (mul_right_inv u)
rw [Units.val_one] at this
rw [← eq_iff_modEq_nat, Nat.cast_one, ← this]; clear this
rw [← natCast_zmod_val ((u * u⁻¹ : Units (ZMod (n + 1))) : ZMod (n + 1))]
rw [Units.val_mul, val_mul, natCast_mod]
lemma isUnit_iff_coprime (m n : ℕ) : IsUnit (m : ZMod n) ↔ m.Coprime n := by
refine ⟨fun H ↦ ?_, fun H ↦ (unitOfCoprime m H).isUnit⟩
have H' := val_coe_unit_coprime H.unit
rw [IsUnit.unit_spec, val_natCast m, Nat.coprime_iff_gcd_eq_one] at H'
rw [Nat.coprime_iff_gcd_eq_one, Nat.gcd_comm, ← H']
exact Nat.gcd_rec n m
lemma isUnit_prime_iff_not_dvd {n p : ℕ} (hp : p.Prime) : IsUnit (p : ZMod n) ↔ ¬p ∣ n := by
rw [isUnit_iff_coprime, Nat.Prime.coprime_iff_not_dvd hp]
lemma isUnit_prime_of_not_dvd {n p : ℕ} (hp : p.Prime) (h : ¬ p ∣ n) : IsUnit (p : ZMod n) :=
(isUnit_prime_iff_not_dvd hp).mpr h
@[simp]
theorem inv_coe_unit {n : ℕ} (u : (ZMod n)ˣ) : (u : ZMod n)⁻¹ = (u⁻¹ : (ZMod n)ˣ) := by
have := congr_arg ((↑) : ℕ → ZMod n) (val_coe_unit_coprime u)
rw [← mul_inv_eq_gcd, Nat.cast_one] at this
let u' : (ZMod n)ˣ := ⟨u, (u : ZMod n)⁻¹, this, by rwa [mul_comm]⟩
have h : u = u' := by
apply Units.ext
rfl
rw [h]
rfl
theorem mul_inv_of_unit {n : ℕ} (a : ZMod n) (h : IsUnit a) : a * a⁻¹ = 1 := by
rcases h with ⟨u, rfl⟩
rw [inv_coe_unit, u.mul_inv]
theorem inv_mul_of_unit {n : ℕ} (a : ZMod n) (h : IsUnit a) : a⁻¹ * a = 1 := by
rw [mul_comm, mul_inv_of_unit a h]
-- TODO: If we changed `⁻¹` so that `ZMod n` is always a `DivisionMonoid`,
-- then we could use the general lemma `inv_eq_of_mul_eq_one`
protected theorem inv_eq_of_mul_eq_one (n : ℕ) (a b : ZMod n) (h : a * b = 1) : a⁻¹ = b :=
left_inv_eq_right_inv (inv_mul_of_unit a ⟨⟨a, b, h, mul_comm a b ▸ h⟩, rfl⟩) h
-- TODO: this equivalence is true for `ZMod 0 = ℤ`, but needs to use different functions.
/-- Equivalence between the units of `ZMod n` and
the subtype of terms `x : ZMod n` for which `x.val` is coprime to `n` -/
def unitsEquivCoprime {n : ℕ} [NeZero n] : (ZMod n)ˣ ≃ { x : ZMod n // Nat.Coprime x.val n } where
toFun x := ⟨x, val_coe_unit_coprime x⟩
invFun x := unitOfCoprime x.1.val x.2
left_inv := fun ⟨_, _, _, _⟩ => Units.ext (natCast_zmod_val _)
right_inv := fun ⟨_, _⟩ => by simp
/-- The **Chinese remainder theorem**. For a pair of coprime natural numbers, `m` and `n`,
the rings `ZMod (m * n)` and `ZMod m × ZMod n` are isomorphic.
See `Ideal.quotientInfRingEquivPiQuotient` for the Chinese remainder theorem for ideals in any
ring.
-/
def chineseRemainder {m n : ℕ} (h : m.Coprime n) : ZMod (m * n) ≃+* ZMod m × ZMod n :=
let to_fun : ZMod (m * n) → ZMod m × ZMod n :=
ZMod.castHom (show m.lcm n ∣ m * n by simp [Nat.lcm_dvd_iff]) (ZMod m × ZMod n)
let inv_fun : ZMod m × ZMod n → ZMod (m * n) := fun x =>
if m * n = 0 then
if m = 1 then cast (RingHom.snd _ (ZMod n) x) else cast (RingHom.fst (ZMod m) _ x)
else Nat.chineseRemainder h x.1.val x.2.val
have inv : Function.LeftInverse inv_fun to_fun ∧ Function.RightInverse inv_fun to_fun :=
if hmn0 : m * n = 0 then by
rcases h.eq_of_mul_eq_zero hmn0 with (⟨rfl, rfl⟩ | ⟨rfl, rfl⟩)
· constructor
· intro x; rfl
· rintro ⟨x, y⟩
fin_cases y
simp [to_fun, inv_fun, castHom, Prod.ext_iff, eq_iff_true_of_subsingleton]
· constructor
· intro x; rfl
· rintro ⟨x, y⟩
fin_cases x
simp [to_fun, inv_fun, castHom, Prod.ext_iff, eq_iff_true_of_subsingleton]
else by
haveI : NeZero (m * n) := ⟨hmn0⟩
haveI : NeZero m := ⟨left_ne_zero_of_mul hmn0⟩
haveI : NeZero n := ⟨right_ne_zero_of_mul hmn0⟩
have left_inv : Function.LeftInverse inv_fun to_fun := by
intro x
dsimp only [to_fun, inv_fun, ZMod.castHom_apply]
conv_rhs => rw [← ZMod.natCast_zmod_val x]
rw [if_neg hmn0, ZMod.eq_iff_modEq_nat, ← Nat.modEq_and_modEq_iff_modEq_mul h,
Prod.fst_zmod_cast, Prod.snd_zmod_cast]
refine
⟨(Nat.chineseRemainder h (cast x : ZMod m).val (cast x : ZMod n).val).2.left.trans ?_,
(Nat.chineseRemainder h (cast x : ZMod m).val (cast x : ZMod n).val).2.right.trans ?_⟩
· rw [← ZMod.eq_iff_modEq_nat, ZMod.natCast_zmod_val, ZMod.natCast_val]
· rw [← ZMod.eq_iff_modEq_nat, ZMod.natCast_zmod_val, ZMod.natCast_val]
exact ⟨left_inv, left_inv.rightInverse_of_card_le (by simp)⟩
{ toFun := to_fun,
invFun := inv_fun,
map_mul' := RingHom.map_mul _
map_add' := RingHom.map_add _
left_inv := inv.1
right_inv := inv.2 }
lemma subsingleton_iff {n : ℕ} : Subsingleton (ZMod n) ↔ n = 1 := by
constructor
· obtain (_ | _ | n) := n
· simpa [ZMod] using not_subsingleton _
· simp [ZMod]
· simpa [ZMod] using not_subsingleton _
· rintro rfl
infer_instance
lemma nontrivial_iff {n : ℕ} : Nontrivial (ZMod n) ↔ n ≠ 1 := by
rw [← not_subsingleton_iff_nontrivial, subsingleton_iff]
-- todo: this can be made a `Unique` instance.
instance subsingleton_units : Subsingleton (ZMod 2)ˣ :=
⟨by decide⟩
@[simp]
theorem add_self_eq_zero_iff_eq_zero {n : ℕ} (hn : Odd n) {a : ZMod n} :
a + a = 0 ↔ a = 0 := by
rw [Nat.odd_iff, ← Nat.two_dvd_ne_zero, ← Nat.prime_two.coprime_iff_not_dvd] at hn
rw [← mul_two, ← @Nat.cast_two (ZMod n), ← ZMod.coe_unitOfCoprime 2 hn, Units.mul_left_eq_zero]
theorem ne_neg_self {n : ℕ} (hn : Odd n) {a : ZMod n} (ha : a ≠ 0) : a ≠ -a := by
rwa [Ne, eq_neg_iff_add_eq_zero, add_self_eq_zero_iff_eq_zero hn]
theorem neg_one_ne_one {n : ℕ} [Fact (2 < n)] : (-1 : ZMod n) ≠ 1 :=
CharP.neg_one_ne_one (ZMod n) n
theorem neg_eq_self_mod_two (a : ZMod 2) : -a = a := by
fin_cases a <;> apply Fin.ext <;> simp [Fin.coe_neg, Int.natMod]; rfl
@[simp]
theorem natAbs_mod_two (a : ℤ) : (a.natAbs : ZMod 2) = a := by
cases a
· simp only [Int.natAbs_ofNat, Int.cast_natCast, Int.ofNat_eq_coe]
· simp only [neg_eq_self_mod_two, Nat.cast_succ, Int.natAbs, Int.cast_negSucc]
theorem val_ne_zero {n : ℕ} (a : ZMod n) : a.val ≠ 0 ↔ a ≠ 0 :=
(val_eq_zero a).not
theorem neg_eq_self_iff {n : ℕ} (a : ZMod n) : -a = a ↔ a = 0 ∨ 2 * a.val = n := by
rw [neg_eq_iff_add_eq_zero, ← two_mul]
cases n
· erw [@mul_eq_zero ℤ, @mul_eq_zero ℕ, val_eq_zero]
exact
⟨fun h => h.elim (by simp) Or.inl, fun h =>
Or.inr (h.elim id fun h => h.elim (by simp) id)⟩
conv_lhs =>
rw [← a.natCast_zmod_val, ← Nat.cast_two, ← Nat.cast_mul, natCast_zmod_eq_zero_iff_dvd]
constructor
· rintro ⟨m, he⟩
cases' m with m
· erw [mul_zero, mul_eq_zero] at he
rcases he with (⟨⟨⟩⟩ | he)
exact Or.inl (a.val_eq_zero.1 he)
cases m
· right
rwa [show 0 + 1 = 1 from rfl, mul_one] at he
refine (a.val_lt.not_le <| Nat.le_of_mul_le_mul_left ?_ zero_lt_two).elim
rw [he, mul_comm]
apply Nat.mul_le_mul_left
erw [Nat.succ_le_succ_iff, Nat.succ_le_succ_iff]; simp
· rintro (rfl | h)
· rw [val_zero, mul_zero]
apply dvd_zero
· rw [h]
theorem val_cast_of_lt {n : ℕ} {a : ℕ} (h : a < n) : (a : ZMod n).val = a := by
rw [val_natCast, Nat.mod_eq_of_lt h]
theorem neg_val' {n : ℕ} [NeZero n] (a : ZMod n) : (-a).val = (n - a.val) % n :=
calc
(-a).val = val (-a) % n := by rw [Nat.mod_eq_of_lt (-a).val_lt]
_ = (n - val a) % n :=
Nat.ModEq.add_right_cancel' (val a)
(by
rw [Nat.ModEq, ← val_add, add_left_neg, tsub_add_cancel_of_le a.val_le, Nat.mod_self,
val_zero])
theorem neg_val {n : ℕ} [NeZero n] (a : ZMod n) : (-a).val = if a = 0 then 0 else n - a.val := by
rw [neg_val']
by_cases h : a = 0; · rw [if_pos h, h, val_zero, tsub_zero, Nat.mod_self]
rw [if_neg h]
apply Nat.mod_eq_of_lt
apply Nat.sub_lt (NeZero.pos n)
contrapose! h
rwa [Nat.le_zero, val_eq_zero] at h
theorem val_neg_of_ne_zero {n : ℕ} [nz : NeZero n] (a : ZMod n) [na : NeZero a] :
(- a).val = n - a.val := by simp_all [neg_val a, na.out]
theorem val_sub {n : ℕ} [NeZero n] {a b : ZMod n} (h : b.val ≤ a.val) :
(a - b).val = a.val - b.val := by
by_cases hb : b = 0
· cases hb; simp
· have : NeZero b := ⟨hb⟩
rw [sub_eq_add_neg, val_add, val_neg_of_ne_zero, ← Nat.add_sub_assoc (le_of_lt (val_lt _)),
add_comm, Nat.add_sub_assoc h, Nat.add_mod_left]
apply Nat.mod_eq_of_lt (tsub_lt_of_lt (val_lt _))
theorem val_cast_eq_val_of_lt {m n : ℕ} [nzm : NeZero m] {a : ZMod m}
(h : a.val < n) : (a.cast : ZMod n).val = a.val := by
have nzn : NeZero n := by constructor; rintro rfl; simp at h
cases m with
| zero => cases nzm; simp_all
| succ m =>
cases n with
| zero => cases nzn; simp_all
| succ n => exact Fin.val_cast_of_lt h
theorem cast_cast_zmod_of_le {m n : ℕ} [hm : NeZero m] (h : m ≤ n) (a : ZMod m) :
(cast (cast a : ZMod n) : ZMod m) = a := by
have : NeZero n := ⟨((Nat.zero_lt_of_ne_zero hm.out).trans_le h).ne'⟩
rw [cast_eq_val, val_cast_eq_val_of_lt (a.val_lt.trans_le h), natCast_zmod_val]
/-- `valMinAbs x` returns the integer in the same equivalence class as `x` that is closest to `0`,
The result will be in the interval `(-n/2, n/2]`. -/
def valMinAbs : ∀ {n : ℕ}, ZMod n → ℤ
| 0, x => x
| n@(_ + 1), x => if x.val ≤ n / 2 then x.val else (x.val : ℤ) - n
@[simp]
theorem valMinAbs_def_zero (x : ZMod 0) : valMinAbs x = x :=
rfl
theorem valMinAbs_def_pos {n : ℕ} [NeZero n] (x : ZMod n) :
valMinAbs x = if x.val ≤ n / 2 then (x.val : ℤ) else x.val - n := by
cases n
· cases NeZero.ne 0 rfl
· rfl
@[simp, norm_cast]
theorem coe_valMinAbs : ∀ {n : ℕ} (x : ZMod n), (x.valMinAbs : ZMod n) = x
| 0, x => Int.cast_id
| k@(n + 1), x => by
rw [valMinAbs_def_pos]
split_ifs
· rw [Int.cast_natCast, natCast_zmod_val]
· rw [Int.cast_sub, Int.cast_natCast, natCast_zmod_val, Int.cast_natCast, natCast_self,
sub_zero]
theorem injective_valMinAbs {n : ℕ} : (valMinAbs : ZMod n → ℤ).Injective :=
Function.injective_iff_hasLeftInverse.2 ⟨_, coe_valMinAbs⟩
theorem _root_.Nat.le_div_two_iff_mul_two_le {n m : ℕ} : m ≤ n / 2 ↔ (m : ℤ) * 2 ≤ n := by
rw [Nat.le_div_iff_mul_le zero_lt_two, ← Int.ofNat_le, Int.ofNat_mul, Nat.cast_two]
theorem valMinAbs_nonneg_iff {n : ℕ} [NeZero n] (x : ZMod n) : 0 ≤ x.valMinAbs ↔ x.val ≤ n / 2 := by
rw [valMinAbs_def_pos]; split_ifs with h
· exact iff_of_true (Nat.cast_nonneg _) h
· exact iff_of_false (sub_lt_zero.2 <| Int.ofNat_lt.2 x.val_lt).not_le h
theorem valMinAbs_mul_two_eq_iff {n : ℕ} (a : ZMod n) : a.valMinAbs * 2 = n ↔ 2 * a.val = n := by
cases' n with n
· simp
by_cases h : a.val ≤ n.succ / 2
· dsimp [valMinAbs]
rw [if_pos h, ← Int.natCast_inj, Nat.cast_mul, Nat.cast_two, mul_comm]
apply iff_of_false _ (mt _ h)
· intro he
rw [← a.valMinAbs_nonneg_iff, ← mul_nonneg_iff_left_nonneg_of_pos, he] at h
exacts [h (Nat.cast_nonneg _), zero_lt_two]
· rw [mul_comm]
exact fun h => (Nat.le_div_iff_mul_le zero_lt_two).2 h.le
theorem valMinAbs_mem_Ioc {n : ℕ} [NeZero n] (x : ZMod n) :
x.valMinAbs * 2 ∈ Set.Ioc (-n : ℤ) n := by
simp_rw [valMinAbs_def_pos, Nat.le_div_two_iff_mul_two_le]; split_ifs with h
· refine ⟨(neg_lt_zero.2 <| mod_cast NeZero.pos n).trans_le (mul_nonneg ?_ ?_), h⟩
exacts [Nat.cast_nonneg _, zero_le_two]
· refine ⟨?_, le_trans (mul_nonpos_of_nonpos_of_nonneg ?_ zero_le_two) <| Nat.cast_nonneg _⟩
· linarith only [h]
· rw [sub_nonpos, Int.ofNat_le]
exact x.val_lt.le
theorem valMinAbs_spec {n : ℕ} [NeZero n] (x : ZMod n) (y : ℤ) :
x.valMinAbs = y ↔ x = y ∧ y * 2 ∈ Set.Ioc (-n : ℤ) n :=
⟨by
rintro rfl
exact ⟨x.coe_valMinAbs.symm, x.valMinAbs_mem_Ioc⟩, fun h =>
by
rw [← sub_eq_zero]
apply @Int.eq_zero_of_abs_lt_dvd n
· rw [← intCast_zmod_eq_zero_iff_dvd, Int.cast_sub, coe_valMinAbs, h.1, sub_self]
rw [← mul_lt_mul_right (@zero_lt_two ℤ _ _ _ _ _)]
nth_rw 1 [← abs_eq_self.2 (@zero_le_two ℤ _ _ _ _)]
rw [← abs_mul, sub_mul, abs_lt]
constructor <;> linarith only [x.valMinAbs_mem_Ioc.1, x.valMinAbs_mem_Ioc.2, h.2.1, h.2.2]⟩
theorem natAbs_valMinAbs_le {n : ℕ} [NeZero n] (x : ZMod n) : x.valMinAbs.natAbs ≤ n / 2 := by
rw [Nat.le_div_two_iff_mul_two_le]
cases' x.valMinAbs.natAbs_eq with h h
· rw [← h]
exact x.valMinAbs_mem_Ioc.2
· rw [← neg_le_neg_iff, ← neg_mul, ← h]
exact x.valMinAbs_mem_Ioc.1.le
@[simp]
theorem valMinAbs_zero : ∀ n, (0 : ZMod n).valMinAbs = 0
| 0 => by simp only [valMinAbs_def_zero]
| n + 1 => by simp only [valMinAbs_def_pos, if_true, Int.ofNat_zero, zero_le, val_zero]
@[simp]
theorem valMinAbs_eq_zero {n : ℕ} (x : ZMod n) : x.valMinAbs = 0 ↔ x = 0 := by
cases' n with n
· simp
rw [← valMinAbs_zero n.succ]
apply injective_valMinAbs.eq_iff
theorem natCast_natAbs_valMinAbs {n : ℕ} [NeZero n] (a : ZMod n) :
(a.valMinAbs.natAbs : ZMod n) = if a.val ≤ (n : ℕ) / 2 then a else -a := by
have : (a.val : ℤ) - n ≤ 0 := by
erw [sub_nonpos, Int.ofNat_le]
exact a.val_le
rw [valMinAbs_def_pos]
split_ifs
· rw [Int.natAbs_ofNat, natCast_zmod_val]
· rw [← Int.cast_natCast, Int.ofNat_natAbs_of_nonpos this, Int.cast_neg, Int.cast_sub,
Int.cast_natCast, Int.cast_natCast, natCast_self, sub_zero, natCast_zmod_val]
@[deprecated (since := "2024-04-17")]
alias nat_cast_natAbs_valMinAbs := natCast_natAbs_valMinAbs
theorem valMinAbs_neg_of_ne_half {n : ℕ} {a : ZMod n} (ha : 2 * a.val ≠ n) :
(-a).valMinAbs = -a.valMinAbs := by
cases' eq_zero_or_neZero n with h h
· subst h
rfl
refine (valMinAbs_spec _ _).2 ⟨?_, ?_, ?_⟩
· rw [Int.cast_neg, coe_valMinAbs]
· rw [neg_mul, neg_lt_neg_iff]
exact a.valMinAbs_mem_Ioc.2.lt_of_ne (mt a.valMinAbs_mul_two_eq_iff.1 ha)
· linarith only [a.valMinAbs_mem_Ioc.1]
@[simp]
theorem natAbs_valMinAbs_neg {n : ℕ} (a : ZMod n) : (-a).valMinAbs.natAbs = a.valMinAbs.natAbs := by
by_cases h2a : 2 * a.val = n
· rw [a.neg_eq_self_iff.2 (Or.inr h2a)]
· rw [valMinAbs_neg_of_ne_half h2a, Int.natAbs_neg]
theorem val_eq_ite_valMinAbs {n : ℕ} [NeZero n] (a : ZMod n) :
(a.val : ℤ) = a.valMinAbs + if a.val ≤ n / 2 then 0 else n := by
rw [valMinAbs_def_pos]
split_ifs <;> simp [add_zero, sub_add_cancel]
theorem prime_ne_zero (p q : ℕ) [hp : Fact p.Prime] [hq : Fact q.Prime] (hpq : p ≠ q) :
(q : ZMod p) ≠ 0 := by
rwa [← Nat.cast_zero, Ne, eq_iff_modEq_nat, Nat.modEq_zero_iff_dvd, ←
hp.1.coprime_iff_not_dvd, Nat.coprime_primes hp.1 hq.1]
variable {n a : ℕ}
theorem valMinAbs_natAbs_eq_min {n : ℕ} [hpos : NeZero n] (a : ZMod n) :
a.valMinAbs.natAbs = min a.val (n - a.val) := by
rw [valMinAbs_def_pos]
split_ifs with h
· rw [Int.natAbs_ofNat]
symm
apply
min_eq_left (le_trans h (le_trans (Nat.half_le_of_sub_le_half _) (Nat.sub_le_sub_left h n)))
rw [Nat.sub_sub_self (Nat.div_le_self _ _)]
· rw [← Int.natAbs_neg, neg_sub, ← Nat.cast_sub a.val_le]
symm
apply
min_eq_right
(le_trans (le_trans (Nat.sub_le_sub_left (lt_of_not_ge h) n) (Nat.le_half_of_half_lt_sub _))
(le_of_not_ge h))
rw [Nat.sub_sub_self (Nat.div_lt_self (lt_of_le_of_ne' (Nat.zero_le _) hpos.1) one_lt_two)]
apply Nat.lt_succ_self
theorem valMinAbs_natCast_of_le_half (ha : a ≤ n / 2) : (a : ZMod n).valMinAbs = a := by
cases n
· simp
· simp [valMinAbs_def_pos, val_natCast, Nat.mod_eq_of_lt (ha.trans_lt <| Nat.div_lt_self' _ 0),
ha]
theorem valMinAbs_natCast_of_half_lt (ha : n / 2 < a) (ha' : a < n) :
(a : ZMod n).valMinAbs = a - n := by
cases n
· cases not_lt_bot ha'
· simp [valMinAbs_def_pos, val_natCast, Nat.mod_eq_of_lt ha', ha.not_le]
-- Porting note: There was an extraneous `nat_` in the mathlib3 name
@[simp]
theorem valMinAbs_natCast_eq_self [NeZero n] : (a : ZMod n).valMinAbs = a ↔ a ≤ n / 2 := by
refine ⟨fun ha => ?_, valMinAbs_natCast_of_le_half⟩
rw [← Int.natAbs_ofNat a, ← ha]
exact natAbs_valMinAbs_le a
theorem natAbs_min_of_le_div_two (n : ℕ) (x y : ℤ) (he : (x : ZMod n) = y) (hl : x.natAbs ≤ n / 2) :
x.natAbs ≤ y.natAbs := by
rw [intCast_eq_intCast_iff_dvd_sub] at he
obtain ⟨m, he⟩ := he
rw [sub_eq_iff_eq_add] at he
subst he
obtain rfl | hm := eq_or_ne m 0
· rw [mul_zero, zero_add]
apply hl.trans
rw [← add_le_add_iff_right x.natAbs]
refine le_trans (le_trans ((add_le_add_iff_left _).2 hl) ?_) (Int.natAbs_sub_le _ _)
rw [add_sub_cancel_right, Int.natAbs_mul, Int.natAbs_ofNat]
refine le_trans ?_ (Nat.le_mul_of_pos_right _ <| Int.natAbs_pos.2 hm)
rw [← mul_two]; apply Nat.div_mul_le_self
theorem natAbs_valMinAbs_add_le {n : ℕ} (a b : ZMod n) :
(a + b).valMinAbs.natAbs ≤ (a.valMinAbs + b.valMinAbs).natAbs := by
cases' n with n
· rfl
apply natAbs_min_of_le_div_two n.succ
· simp_rw [Int.cast_add, coe_valMinAbs]
· apply natAbs_valMinAbs_le
variable (p : ℕ) [Fact p.Prime]
private theorem mul_inv_cancel_aux (a : ZMod p) (h : a ≠ 0) : a * a⁻¹ = 1 := by
obtain ⟨k, rfl⟩ := natCast_zmod_surjective a
apply coe_mul_inv_eq_one
apply Nat.Coprime.symm
rwa [Nat.Prime.coprime_iff_not_dvd Fact.out, ← CharP.cast_eq_zero_iff (ZMod p)]
/-- Field structure on `ZMod p` if `p` is prime. -/
instance instField : Field (ZMod p) where
mul_inv_cancel := mul_inv_cancel_aux p
inv_zero := inv_zero p
nnqsmul := _
nnqsmul_def := fun q a => rfl
qsmul := _
qsmul_def := fun a x => rfl
/-- `ZMod p` is an integral domain when `p` is prime. -/
instance (p : ℕ) [hp : Fact p.Prime] : IsDomain (ZMod p) := by
-- We need `cases p` here in order to resolve which `CommRing` instance is being used.
cases p
· exact (Nat.not_prime_zero hp.out).elim
exact @Field.isDomain (ZMod _) (inferInstanceAs (Field (ZMod _)))
end ZMod
theorem RingHom.ext_zmod {n : ℕ} {R : Type*} [Semiring R] (f g : ZMod n →+* R) : f = g := by
ext a
obtain ⟨k, rfl⟩ := ZMod.intCast_surjective a
let φ : ℤ →+* R := f.comp (Int.castRingHom (ZMod n))
let ψ : ℤ →+* R := g.comp (Int.castRingHom (ZMod n))
show φ k = ψ k
rw [φ.ext_int ψ]
namespace ZMod
variable {n : ℕ} {R : Type*}
instance subsingleton_ringHom [Semiring R] : Subsingleton (ZMod n →+* R) :=
⟨RingHom.ext_zmod⟩
instance subsingleton_ringEquiv [Semiring R] : Subsingleton (ZMod n ≃+* R) :=
⟨fun f g => by
rw [RingEquiv.coe_ringHom_inj_iff]
apply RingHom.ext_zmod _ _⟩
@[simp]
theorem ringHom_map_cast [Ring R] (f : R →+* ZMod n) (k : ZMod n) : f (cast k) = k := by
cases n
· dsimp [ZMod, ZMod.cast] at f k ⊢; simp
· dsimp [ZMod, ZMod.cast] at f k ⊢
erw [map_natCast, Fin.cast_val_eq_self]
/-- Any ring homomorphism into `ZMod n` has a right inverse. -/
theorem ringHom_rightInverse [Ring R] (f : R →+* ZMod n) :
Function.RightInverse (cast : ZMod n → R) f :=
ringHom_map_cast f
/-- Any ring homomorphism into `ZMod n` is surjective. -/
theorem ringHom_surjective [Ring R] (f : R →+* ZMod n) : Function.Surjective f :=
(ringHom_rightInverse f).surjective
@[simp]
lemma castHom_self : ZMod.castHom dvd_rfl (ZMod n) = RingHom.id (ZMod n) :=
Subsingleton.elim _ _
@[simp]
lemma castHom_comp {m d : ℕ} (hm : n ∣ m) (hd : m ∣ d) :
(castHom hm (ZMod n)).comp (castHom hd (ZMod m)) = castHom (dvd_trans hm hd) (ZMod n) :=
RingHom.ext_zmod _ _
section lift
variable (n) {A : Type*} [AddGroup A]
/-- The map from `ZMod n` induced by `f : ℤ →+ A` that maps `n` to `0`. -/
--@[simps] -- Porting note: removed, simplified LHS of `lift_coe` to something worse.
def lift : { f : ℤ →+ A // f n = 0 } ≃ (ZMod n →+ A) :=
(Equiv.subtypeEquivRight <| by
intro f
rw [ker_intCastAddHom]
constructor
· rintro hf _ ⟨x, rfl⟩
simp only [f.map_zsmul, zsmul_zero, f.mem_ker, hf]
· intro h
exact h (AddSubgroup.mem_zmultiples _)).trans <|
(Int.castAddHom (ZMod n)).liftOfRightInverse cast intCast_zmod_cast
variable (f : { f : ℤ →+ A // f n = 0 })
@[simp]
theorem lift_coe (x : ℤ) : lift n f (x : ZMod n) = f.val x :=
AddMonoidHom.liftOfRightInverse_comp_apply _ _ (fun _ => intCast_zmod_cast _) _ _
theorem lift_castAddHom (x : ℤ) : lift n f (Int.castAddHom (ZMod n) x) = f.1 x :=
AddMonoidHom.liftOfRightInverse_comp_apply _ _ (fun _ => intCast_zmod_cast _) _ _
@[simp]
theorem lift_comp_coe : ZMod.lift n f ∘ ((↑) : ℤ → _) = f :=
funext <| lift_coe _ _
@[simp]
theorem lift_comp_castAddHom : (ZMod.lift n f).comp (Int.castAddHom (ZMod n)) = f :=
AddMonoidHom.ext <| lift_castAddHom _ _
lemma lift_injective {f : {f : ℤ →+ A // f n = 0}} :
Injective (lift n f) ↔ ∀ m, f.1 m = 0 → (m : ZMod n) = 0 := by
simp only [← AddMonoidHom.ker_eq_bot_iff, eq_bot_iff, SetLike.le_def,
ZMod.intCast_surjective.forall, ZMod.lift_coe, AddMonoidHom.mem_ker, AddSubgroup.mem_bot]
end lift
end ZMod
section AddGroup
variable {α : Type*} [AddGroup α] {n : ℕ}
@[simp]
lemma nsmul_zmod_val_inv_nsmul (hn : (Nat.card α).Coprime n) (a : α) :
n • (n⁻¹ : ZMod (Nat.card α)).val • a = a := by
rw [← mul_nsmul', ← mod_natCard_nsmul, ← ZMod.val_natCast, Nat.cast_mul,
ZMod.mul_val_inv hn.symm, ZMod.val_one_eq_one_mod, mod_natCard_nsmul, one_nsmul]
@[simp]
lemma zmod_val_inv_nsmul_nsmul (hn : (Nat.card α).Coprime n) (a : α) :
(n⁻¹ : ZMod (Nat.card α)).val • n • a = a := by
rw [nsmul_left_comm, nsmul_zmod_val_inv_nsmul hn]
end AddGroup
section Group
variable {α : Type*} [Group α] {n : ℕ}
-- TODO: Without the `existing`, `to_additive` chokes on `Inv (ZMod n)`.
@[to_additive (attr := simp) existing nsmul_zmod_val_inv_nsmul]
lemma pow_zmod_val_inv_pow (hn : (Nat.card α).Coprime n) (a : α) :
(a ^ (n⁻¹ : ZMod (Nat.card α)).val) ^ n = a := by
rw [← pow_mul', ← pow_mod_natCard, ← ZMod.val_natCast, Nat.cast_mul, ZMod.mul_val_inv hn.symm,
ZMod.val_one_eq_one_mod, pow_mod_natCard, pow_one]
@[to_additive (attr := simp) existing zmod_val_inv_nsmul_nsmul]
lemma pow_pow_zmod_val_inv (hn : (Nat.card α).Coprime n) (a : α) :
(a ^ n) ^ (n⁻¹ : ZMod (Nat.card α)).val = a := by rw [pow_right_comm, pow_zmod_val_inv_pow hn]
end Group
/-- The range of `(m * · + k)` on natural numbers is the set of elements `≥ k` in the
residue class of `k` mod `m`. -/
lemma Nat.range_mul_add (m k : ℕ) :
Set.range (fun n : ℕ ↦ m * n + k) = {n : ℕ | (n : ZMod m) = k ∧ k ≤ n} := by
ext n
simp only [Set.mem_range, Set.mem_setOf_eq]
conv => enter [1, 1, y]; rw [add_comm, eq_comm]
refine ⟨fun ⟨a, ha⟩ ↦ ⟨?_, le_iff_exists_add.mpr ⟨_, ha⟩⟩, fun ⟨H₁, H₂⟩ ↦ ?_⟩
· simpa using congr_arg ((↑) : ℕ → ZMod m) ha
· obtain ⟨a, ha⟩ := le_iff_exists_add.mp H₂
simp only [ha, Nat.cast_add, add_right_eq_self, ZMod.natCast_zmod_eq_zero_iff_dvd] at H₁
obtain ⟨b, rfl⟩ := H₁
exact ⟨b, ha⟩
|
Data\ZMod\Coprime.lean | /-
Copyright (c) 2022 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Stoll
-/
import Mathlib.Data.ZMod.Basic
import Mathlib.RingTheory.Int.Basic
import Mathlib.RingTheory.PrincipalIdealDomain
/-!
# Coprimality and vanishing
We show that for prime `p`, the image of an integer `a` in `ZMod p` vanishes if and only if
`a` and `p` are not coprime.
-/
namespace ZMod
/-- If `p` is a prime and `a` is an integer, then `a : ZMod p` is zero if and only if
`gcd a p ≠ 1`. -/
theorem eq_zero_iff_gcd_ne_one {a : ℤ} {p : ℕ} [pp : Fact p.Prime] :
(a : ZMod p) = 0 ↔ a.gcd p ≠ 1 := by
rw [Ne, Int.gcd_comm, Int.gcd_eq_one_iff_coprime,
(Nat.prime_iff_prime_int.1 pp.1).coprime_iff_not_dvd, Classical.not_not,
intCast_zmod_eq_zero_iff_dvd]
/-- If an integer `a` and a prime `p` satisfy `gcd a p = 1`, then `a : ZMod p` is nonzero. -/
theorem ne_zero_of_gcd_eq_one {a : ℤ} {p : ℕ} (pp : p.Prime) (h : a.gcd p = 1) : (a : ZMod p) ≠ 0 :=
mt (@eq_zero_iff_gcd_ne_one a p ⟨pp⟩).mp (Classical.not_not.mpr h)
/-- If an integer `a` and a prime `p` satisfy `gcd a p ≠ 1`, then `a : ZMod p` is zero. -/
theorem eq_zero_of_gcd_ne_one {a : ℤ} {p : ℕ} (pp : p.Prime) (h : a.gcd p ≠ 1) : (a : ZMod p) = 0 :=
(@eq_zero_iff_gcd_ne_one a p ⟨pp⟩).mpr h
end ZMod
|
Data\ZMod\Defs.lean | /-
Copyright (c) 2022 Eric Rodriguez. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Rodriguez
-/
import Mathlib.Algebra.Group.Fin.Basic
import Mathlib.Algebra.NeZero
import Mathlib.Data.Nat.ModEq
import Mathlib.Data.Fintype.Card
/-!
# Definition of `ZMod n` + basic results.
This file provides the basic details of `ZMod n`, including its commutative ring structure.
## Implementation details
This used to be inlined into `Data.ZMod.Basic`. This file imports `CharP.Basic`, which is an
issue; all `CharP` instances create an `Algebra (ZMod p) R` instance; however, this instance may
not be definitionally equal to other `Algebra` instances (for example, `GaloisField` also has an
`Algebra` instance as it is defined as a `SplittingField`). The way to fix this is to use the
forgetful inheritance pattern, and make `CharP` carry the data of what the `smul` should be (so
for example, the `smul` on the `GaloisField` `CharP` instance should be equal to the `smul` from
its `SplittingField` structure); there is only one possible `ZMod p` algebra for any `p`, so this
is not an issue mathematically. For this to be possible, however, we need `CharP.Basic` to be
able to import some part of `ZMod`.
-/
namespace Fin
/-!
## Ring structure on `Fin n`
We define a commutative ring structure on `Fin n`.
Afterwards, when we define `ZMod n` in terms of `Fin n`, we use these definitions
to register the ring structure on `ZMod n` as type class instance.
-/
open Nat.ModEq Int
/-- Multiplicative commutative semigroup structure on `Fin n`. -/
instance instCommSemigroup (n : ℕ) : CommSemigroup (Fin n) :=
{ inferInstanceAs (Mul (Fin n)) with
mul_assoc := fun ⟨a, ha⟩ ⟨b, hb⟩ ⟨c, hc⟩ =>
Fin.eq_of_val_eq <|
calc
a * b % n * c ≡ a * b * c [MOD n] := (Nat.mod_modEq _ _).mul_right _
_ ≡ a * (b * c) [MOD n] := by rw [mul_assoc]
_ ≡ a * (b * c % n) [MOD n] := (Nat.mod_modEq _ _).symm.mul_left _
mul_comm := Fin.mul_comm }
private theorem left_distrib_aux (n : ℕ) : ∀ a b c : Fin n, a * (b + c) = a * b + a * c :=
fun ⟨a, ha⟩ ⟨b, hb⟩ ⟨c, hc⟩ =>
Fin.eq_of_val_eq <|
calc
a * ((b + c) % n) ≡ a * (b + c) [MOD n] := (Nat.mod_modEq _ _).mul_left _
_ ≡ a * b + a * c [MOD n] := by rw [mul_add]
_ ≡ a * b % n + a * c % n [MOD n] := (Nat.mod_modEq _ _).symm.add (Nat.mod_modEq _ _).symm
/-- Commutative ring structure on `Fin n`. -/
instance instDistrib (n : ℕ) : Distrib (Fin n) :=
{ Fin.addCommSemigroup n, Fin.instCommSemigroup n with
left_distrib := left_distrib_aux n
right_distrib := fun a b c => by
rw [mul_comm, left_distrib_aux, mul_comm _ b, mul_comm] }
/-- Commutative ring structure on `Fin n`. -/
instance instCommRing (n : ℕ) [NeZero n] : CommRing (Fin n) :=
{ Fin.instAddMonoidWithOne n, Fin.addCommGroup n, Fin.instCommSemigroup n, Fin.instDistrib n with
one_mul := Fin.one_mul'
mul_one := Fin.mul_one',
-- Porting note: new, see
-- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/ring.20vs.20Ring/near/322876462
zero_mul := Fin.zero_mul'
mul_zero := Fin.mul_zero' }
/-- Note this is more general than `Fin.instCommRing` as it applies (vacuously) to `Fin 0` too. -/
instance instHasDistribNeg (n : ℕ) : HasDistribNeg (Fin n) :=
{ toInvolutiveNeg := Fin.instInvolutiveNeg n
mul_neg := Nat.casesOn n finZeroElim fun _i => mul_neg
neg_mul := Nat.casesOn n finZeroElim fun _i => neg_mul }
end Fin
/-- The integers modulo `n : ℕ`. -/
def ZMod : ℕ → Type
| 0 => ℤ
| n + 1 => Fin (n + 1)
instance ZMod.decidableEq : ∀ n : ℕ, DecidableEq (ZMod n)
| 0 => inferInstanceAs (DecidableEq ℤ)
| n + 1 => inferInstanceAs (DecidableEq (Fin (n + 1)))
instance ZMod.repr : ∀ n : ℕ, Repr (ZMod n)
| 0 => by dsimp [ZMod]; infer_instance
| n + 1 => by dsimp [ZMod]; infer_instance
namespace ZMod
instance instUnique : Unique (ZMod 1) := Fin.uniqueFinOne
instance fintype : ∀ (n : ℕ) [NeZero n], Fintype (ZMod n)
| 0, h => (h.ne rfl).elim
| n + 1, _ => Fin.fintype (n + 1)
instance infinite : Infinite (ZMod 0) :=
Int.infinite
@[simp]
theorem card (n : ℕ) [Fintype (ZMod n)] : Fintype.card (ZMod n) = n := by
cases n with
| zero => exact (not_finite (ZMod 0)).elim
| succ n => convert Fintype.card_fin (n + 1) using 2
/- We define each field by cases, to ensure that the eta-expanded `ZMod.commRing` is defeq to the
original, this helps avoid diamonds with instances coming from classes extending `CommRing` such as
field. -/
instance commRing (n : ℕ) : CommRing (ZMod n) where
add := Nat.casesOn n (@Add.add Int _) fun n => @Add.add (Fin n.succ) _
add_assoc := Nat.casesOn n (@add_assoc Int _) fun n => @add_assoc (Fin n.succ) _
zero := Nat.casesOn n (0 : Int) fun n => (0 : Fin n.succ)
zero_add := Nat.casesOn n (@zero_add Int _) fun n => @zero_add (Fin n.succ) _
add_zero := Nat.casesOn n (@add_zero Int _) fun n => @add_zero (Fin n.succ) _
neg := Nat.casesOn n (@Neg.neg Int _) fun n => @Neg.neg (Fin n.succ) _
sub := Nat.casesOn n (@Sub.sub Int _) fun n => @Sub.sub (Fin n.succ) _
sub_eq_add_neg := Nat.casesOn n (@sub_eq_add_neg Int _) fun n => @sub_eq_add_neg (Fin n.succ) _
zsmul := Nat.casesOn n
(inferInstanceAs (CommRing ℤ)).zsmul fun n => (inferInstanceAs (CommRing (Fin n.succ))).zsmul
zsmul_zero' := Nat.casesOn n
(inferInstanceAs (CommRing ℤ)).zsmul_zero'
fun n => (inferInstanceAs (CommRing (Fin n.succ))).zsmul_zero'
zsmul_succ' := Nat.casesOn n
(inferInstanceAs (CommRing ℤ)).zsmul_succ'
fun n => (inferInstanceAs (CommRing (Fin n.succ))).zsmul_succ'
zsmul_neg' := Nat.casesOn n
(inferInstanceAs (CommRing ℤ)).zsmul_neg'
fun n => (inferInstanceAs (CommRing (Fin n.succ))).zsmul_neg'
nsmul := Nat.casesOn n
(inferInstanceAs (CommRing ℤ)).nsmul fun n => (inferInstanceAs (CommRing (Fin n.succ))).nsmul
nsmul_zero := Nat.casesOn n
(inferInstanceAs (CommRing ℤ)).nsmul_zero
fun n => (inferInstanceAs (CommRing (Fin n.succ))).nsmul_zero
nsmul_succ := Nat.casesOn n
(inferInstanceAs (CommRing ℤ)).nsmul_succ
fun n => (inferInstanceAs (CommRing (Fin n.succ))).nsmul_succ
-- Porting note: `match` didn't work here
add_left_neg := Nat.casesOn n (@add_left_neg Int _) fun n => @add_left_neg (Fin n.succ) _
add_comm := Nat.casesOn n (@add_comm Int _) fun n => @add_comm (Fin n.succ) _
mul := Nat.casesOn n (@Mul.mul Int _) fun n => @Mul.mul (Fin n.succ) _
mul_assoc := Nat.casesOn n (@mul_assoc Int _) fun n => @mul_assoc (Fin n.succ) _
one := Nat.casesOn n (1 : Int) fun n => (1 : Fin n.succ)
one_mul := Nat.casesOn n (@one_mul Int _) fun n => @one_mul (Fin n.succ) _
mul_one := Nat.casesOn n (@mul_one Int _) fun n => @mul_one (Fin n.succ) _
natCast := Nat.casesOn n ((↑) : ℕ → ℤ) fun n => ((↑) : ℕ → Fin n.succ)
natCast_zero := Nat.casesOn n (@Nat.cast_zero Int _) fun n => @Nat.cast_zero (Fin n.succ) _
natCast_succ := Nat.casesOn n (@Nat.cast_succ Int _) fun n => @Nat.cast_succ (Fin n.succ) _
intCast := Nat.casesOn n ((↑) : ℤ → ℤ) fun n => ((↑) : ℤ → Fin n.succ)
intCast_ofNat := Nat.casesOn n (@Int.cast_natCast Int _) fun n => @Int.cast_natCast (Fin n.succ) _
intCast_negSucc :=
Nat.casesOn n (@Int.cast_negSucc Int _) fun n => @Int.cast_negSucc (Fin n.succ) _
left_distrib := Nat.casesOn n (@left_distrib Int _ _ _) fun n => @left_distrib (Fin n.succ) _ _ _
right_distrib :=
Nat.casesOn n (@right_distrib Int _ _ _) fun n => @right_distrib (Fin n.succ) _ _ _
mul_comm := Nat.casesOn n (@mul_comm Int _) fun n => @mul_comm (Fin n.succ) _
-- Porting note: new, see
-- https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/ring.20vs.20Ring/near/322876462
zero_mul := Nat.casesOn n (@zero_mul Int _) fun n => @zero_mul (Fin n.succ) _
mul_zero := Nat.casesOn n (@mul_zero Int _) fun n => @mul_zero (Fin n.succ) _
npow := Nat.casesOn n
(inferInstanceAs (CommRing ℤ)).npow fun n => (inferInstanceAs (CommRing (Fin n.succ))).npow
npow_zero := Nat.casesOn n
(inferInstanceAs (CommRing ℤ)).npow_zero
fun n => (inferInstanceAs (CommRing (Fin n.succ))).npow_zero
npow_succ := Nat.casesOn n
(inferInstanceAs (CommRing ℤ)).npow_succ
fun n => (inferInstanceAs (CommRing (Fin n.succ))).npow_succ
instance inhabited (n : ℕ) : Inhabited (ZMod n) :=
⟨0⟩
end ZMod
|
Data\ZMod\Factorial.lean | /-
Copyright (c) 2023 Moritz Firsching. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Firsching
-/
import Mathlib.Algebra.BigOperators.Intervals
import Mathlib.Data.Nat.Factorial.BigOperators
import Mathlib.Data.ZMod.Basic
/-!
# Facts about factorials in ZMod
We collect facts about factorials in context of modular arithmetic.
## Main statements
* `ZMod.cast_descFactorial`: For natural numbers `n` and `p`, where `n` is less than or equal to `p`
the descending factorial of `(p - 1)` taken `n` times modulo `p` equals `(-1) ^ n * n!`.
## See also
For the prime case and involving `factorial` rather than `descFactorial`, see Wilson's theorem:
* Nat.prime_iff_fac_equiv_neg_one
-/
open Finset Nat
namespace ZMod
theorem cast_descFactorial {n p : ℕ} (h : n ≤ p) :
(descFactorial (p - 1) n : ZMod p) = (-1) ^ n * n ! := by
rw [descFactorial_eq_prod_range, ← prod_range_add_one_eq_factorial]
simp only [cast_prod]
nth_rw 2 [← card_range n]
rw [pow_card_mul_prod]
refine prod_congr rfl ?_
intro x hx
rw [← tsub_add_eq_tsub_tsub_swap,
Nat.cast_sub <| Nat.le_trans (Nat.add_one_le_iff.mpr (List.mem_range.mp hx)) h,
CharP.cast_eq_zero, zero_sub, cast_succ, neg_add_rev, mul_add, neg_mul, one_mul,
mul_one, add_comm]
end ZMod
|
Data\ZMod\IntUnitsPower.lean | /-
Copyright (c) 2023 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Algebra.GroupWithZero.Divisibility
import Mathlib.Data.Int.Order.Units
import Mathlib.Data.ZMod.Basic
/-!
# The power operator on `ℤˣ` by `ZMod 2`, `ℕ`, and `ℤ`
See also the related `negOnePow`.
## TODO
* Generalize this to `Pow G (Zmod n)` where `orderOf g = n`.
## Implementation notes
In future, we could consider a `LawfulPower M R` typeclass; but we can save ourselves a lot of work
by using `Module R (Additive M)` in its place, especially since this already has instances for
`R = ℕ` and `R = ℤ`.
-/
instance : SMul (ZMod 2) (Additive ℤˣ) where
smul z au := .ofMul <| Additive.toMul au ^ z.val
lemma ZMod.smul_units_def (z : ZMod 2) (au : Additive ℤˣ) :
z • au = z.val • au := rfl
lemma ZMod.natCast_smul_units (n : ℕ) (au : Additive ℤˣ) : (n : ZMod 2) • au = n • au :=
(Int.units_pow_eq_pow_mod_two au n).symm
/-- This is an indirect way of saying that `ℤˣ` has a power operation by `ZMod 2`. -/
instance : Module (ZMod 2) (Additive ℤˣ) where
smul z au := .ofMul <| Additive.toMul au ^ z.val
one_smul au := Additive.toMul.injective <| pow_one _
mul_smul z₁ z₂ au := Additive.toMul.injective <| by
dsimp only [ZMod.smul_units_def, toMul_nsmul]
rw [← pow_mul, ZMod.val_mul, ← Int.units_pow_eq_pow_mod_two, mul_comm]
smul_zero z := Additive.toMul.injective <| one_pow _
smul_add z au₁ au₂ := Additive.toMul.injective <| mul_pow _ _ _
add_smul z₁ z₂ au := Additive.toMul.injective <| by
dsimp only [ZMod.smul_units_def, toMul_nsmul, toMul_add]
rw [← pow_add, ZMod.val_add, ← Int.units_pow_eq_pow_mod_two]
zero_smul au := Additive.toMul.injective <| pow_zero (Additive.toMul au)
section CommSemiring
variable {R : Type*} [CommSemiring R] [Module R (Additive ℤˣ)]
/-- There is a canonical power operation on `ℤˣ` by `R` if `Additive ℤˣ` is an `R`-module.
In lemma names, this operations is called `uzpow` to match `zpow`.
Notably this is satisfied by `R ∈ {ℕ, ℤ, ZMod 2}`. -/
instance Int.instUnitsPow : Pow ℤˣ R where
pow u r := Additive.toMul (r • Additive.ofMul u)
-- The above instances form no typeclass diamonds with the standard power operators
-- but we will need `reducible_and_instances` which currently fails #10906
example : Int.instUnitsPow = Monoid.toNatPow := rfl
example : Int.instUnitsPow = DivInvMonoid.Pow := rfl
@[simp] lemma ofMul_uzpow (u : ℤˣ) (r : R) : Additive.ofMul (u ^ r) = r • Additive.ofMul u := rfl
@[simp] lemma toMul_uzpow (u : Additive ℤˣ) (r : R) :
Additive.toMul (r • u) = Additive.toMul u ^ r := rfl
@[norm_cast] lemma uzpow_natCast (u : ℤˣ) (n : ℕ) : u ^ (n : R) = u ^ n := by
change Additive.toMul ((n : R) • Additive.ofMul u) = _
rw [Nat.cast_smul_eq_nsmul, toMul_nsmul, toMul_ofMul]
-- See note [no_index around OfNat.ofNat]
lemma uzpow_coe_nat (s : ℤˣ) (n : ℕ) [n.AtLeastTwo] :
s ^ (no_index (OfNat.ofNat n : R)) = s ^ (no_index (OfNat.ofNat n : ℕ)) :=
uzpow_natCast _ _
@[simp] lemma one_uzpow (x : R) : (1 : ℤˣ) ^ x = 1 :=
Additive.ofMul.injective <| smul_zero _
lemma mul_uzpow (s₁ s₂ : ℤˣ) (x : R) : (s₁ * s₂) ^ x = s₁ ^ x * s₂ ^ x :=
Additive.ofMul.injective <| smul_add x (Additive.ofMul s₁) (Additive.ofMul s₂)
@[simp] lemma uzpow_zero (s : ℤˣ) : (s ^ (0 : R) : ℤˣ) = (1 : ℤˣ) :=
Additive.ofMul.injective <| zero_smul R (Additive.ofMul s)
@[simp] lemma uzpow_one (s : ℤˣ) : (s ^ (1 : R) : ℤˣ) = s :=
Additive.ofMul.injective <| one_smul R (Additive.ofMul s)
lemma uzpow_mul (s : ℤˣ) (x y : R) : s ^ (x * y) = (s ^ x) ^ y :=
Additive.ofMul.injective <| mul_comm x y ▸ mul_smul y x (Additive.ofMul s)
lemma uzpow_add (s : ℤˣ) (x y : R) : s ^ (x + y) = s ^ x * s ^ y :=
Additive.ofMul.injective <| add_smul x y (Additive.ofMul s)
end CommSemiring
section CommRing
variable {R : Type*} [CommRing R] [Module R (Additive ℤˣ)]
lemma uzpow_sub (s : ℤˣ) (x y : R) : s ^ (x - y) = s ^ x / s ^ y :=
Additive.ofMul.injective <| sub_smul x y (Additive.ofMul s)
lemma uzpow_neg (s : ℤˣ) (x : R) : s ^ (-x) = (s ^ x)⁻¹ :=
Additive.ofMul.injective <| neg_smul x (Additive.ofMul s)
@[norm_cast] lemma uzpow_intCast (u : ℤˣ) (z : ℤ) : u ^ (z : R) = u ^ z := by
change Additive.toMul ((z : R) • Additive.ofMul u) = _
rw [Int.cast_smul_eq_zsmul, toMul_zsmul, toMul_ofMul]
end CommRing
|
Data\ZMod\Module.lean | /-
Copyright (c) 2023 Lawrence Wu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Lawrence Wu
-/
import Mathlib.Algebra.Module.Submodule.Lattice
import Mathlib.Data.ZMod.Basic
import Mathlib.Order.OmegaCompletePartialOrder
/-!
# The `ZMod n`-module structure on Abelian groups whose elements have order dividing `n`
-/
variable {n : ℕ} {M M₁ : Type*}
/-- The `ZMod n`-module structure on commutative monoids whose elements have order dividing `n ≠ 0`.
Also implies a group structure via `Module.addCommMonoidToAddCommGroup`.
See note [reducible non-instances]. -/
abbrev AddCommMonoid.zmodModule [NeZero n] [AddCommMonoid M] (h : ∀ (x : M), n • x = 0) :
Module (ZMod n) M := by
have h_mod (c : ℕ) (x : M) : (c % n) • x = c • x := by
suffices (c % n + c / n * n) • x = c • x by rwa [add_nsmul, mul_nsmul, h, add_zero] at this
rw [Nat.mod_add_div']
have := NeZero.ne n
match n with
| n + 1 => exact {
smul := fun (c : Fin _) x ↦ c.val • x
smul_zero := fun _ ↦ nsmul_zero _
zero_smul := fun _ ↦ zero_nsmul _
smul_add := fun _ _ _ ↦ nsmul_add _ _ _
one_smul := fun _ ↦ (h_mod _ _).trans <| one_nsmul _
add_smul := fun _ _ _ ↦ (h_mod _ _).trans <| add_nsmul _ _ _
mul_smul := fun _ _ _ ↦ (h_mod _ _).trans <| mul_nsmul' _ _ _
}
/-- The `ZMod n`-module structure on Abelian groups whose elements have order dividing `n`.
See note [reducible non-instances]. -/
abbrev AddCommGroup.zmodModule {G : Type*} [AddCommGroup G] (h : ∀ (x : G), n • x = 0) :
Module (ZMod n) G :=
match n with
| 0 => AddCommGroup.toIntModule G
| _ + 1 => AddCommMonoid.zmodModule h
variable {F S : Type*} [AddCommGroup M] [AddCommGroup M₁] [FunLike F M M₁]
[AddMonoidHomClass F M M₁] [Module (ZMod n) M] [Module (ZMod n) M₁] [SetLike S M]
[AddSubgroupClass S M] {x : M} {K : S}
namespace ZMod
theorem map_smul (f : F) (c : ZMod n) (x : M) : f (c • x) = c • f x := by
rw [← ZMod.intCast_zmod_cast c]
exact map_intCast_smul f _ _ (cast c) x
theorem smul_mem (hx : x ∈ K) (c : ZMod n) : c • x ∈ K := by
rw [← ZMod.intCast_zmod_cast c, Int.cast_smul_eq_zsmul]
exact zsmul_mem hx (cast c)
end ZMod
variable (n)
namespace AddMonoidHom
/-- Reinterpret an additive homomorphism as a `ℤ/nℤ`-linear map.
See also:
`AddMonoidHom.toIntLinearMap`, `AddMonoidHom.toNatLinearMap`, `AddMonoidHom.toRatLinearMap` -/
def toZModLinearMap (f : M →+ M₁) : M →ₗ[ZMod n] M₁ := { f with map_smul' := ZMod.map_smul f }
theorem toZModLinearMap_injective : Function.Injective <| toZModLinearMap n (M := M) (M₁ := M₁) :=
fun _ _ h ↦ ext fun x ↦ congr($h x)
@[simp]
theorem coe_toZModLinearMap (f : M →+ M₁) : ⇑(f.toZModLinearMap n) = f := rfl
end AddMonoidHom
namespace AddSubgroup
/-- Reinterpret an additive subgroup of a `ℤ/nℤ`-module as a `ℤ/nℤ`-submodule.
See also: `AddSubgroup.toIntSubmodule`, `AddSubmonoid.toNatSubmodule`. -/
def toZModSubmodule : AddSubgroup M ≃o Submodule (ZMod n) M where
toFun S := { S with smul_mem' := fun c _ h ↦ ZMod.smul_mem (K := S) h c }
invFun := Submodule.toAddSubgroup
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' := Iff.rfl
@[simp]
theorem toZModSubmodule_symm :
⇑((toZModSubmodule n).symm : _ ≃o AddSubgroup M) = Submodule.toAddSubgroup :=
rfl
@[simp]
theorem coe_toZModSubmodule (S : AddSubgroup M) : (toZModSubmodule n S : Set M) = S :=
rfl
@[simp]
theorem toZModSubmodule_toAddSubgroup (S : AddSubgroup M) :
(toZModSubmodule n S).toAddSubgroup = S :=
rfl
@[simp]
theorem _root_.Submodule.toAddSubgroup_toZModSubmodule (S : Submodule (ZMod n) M) :
toZModSubmodule n S.toAddSubgroup = S :=
rfl
end AddSubgroup
|
Data\ZMod\Parity.lean | /-
Copyright (c) 2020 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Data.ZMod.Basic
/-!
# Relating parity to natural numbers mod 2
This module provides lemmas relating `ZMod 2` to `Even` and `Odd`.
## Tags
parity, zmod, even, odd
-/
namespace ZMod
theorem eq_zero_iff_even {n : ℕ} : (n : ZMod 2) = 0 ↔ Even n :=
(CharP.cast_eq_zero_iff (ZMod 2) 2 n).trans even_iff_two_dvd.symm
theorem eq_one_iff_odd {n : ℕ} : (n : ZMod 2) = 1 ↔ Odd n := by
rw [← @Nat.cast_one (ZMod 2), ZMod.eq_iff_modEq_nat, Nat.odd_iff, Nat.ModEq]
theorem ne_zero_iff_odd {n : ℕ} : (n : ZMod 2) ≠ 0 ↔ Odd n := by
constructor <;>
· contrapose
simp [eq_zero_iff_even]
end ZMod
|
Data\ZMod\Quotient.lean | /-
Copyright (c) 2021 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.Algebra.Group.Equiv.TypeTags
import Mathlib.Data.ZMod.Basic
import Mathlib.GroupTheory.GroupAction.Quotient
import Mathlib.RingTheory.Ideal.QuotientOperations
import Mathlib.RingTheory.Int.Basic
import Mathlib.RingTheory.ZMod
/-!
# `ZMod n` and quotient groups / rings
This file relates `ZMod n` to the quotient group
`ℤ / AddSubgroup.zmultiples (n : ℤ)` and to the quotient ring
`ℤ ⧸ Ideal.span {(n : ℤ)}`.
## Main definitions
- `ZMod.quotientZMultiplesNatEquivZMod` and `ZMod.quotientZMultiplesEquivZMod`:
`ZMod n` is the group quotient of `ℤ` by `n ℤ := AddSubgroup.zmultiples (n)`,
(where `n : ℕ` and `n : ℤ` respectively)
- `ZMod.quotient_span_nat_equiv_zmod` and `ZMod.quotientSpanEquivZMod `:
`ZMod n` is the ring quotient of `ℤ` by `n ℤ : Ideal.span {n}`
(where `n : ℕ` and `n : ℤ` respectively)
- `ZMod.lift n f` is the map from `ZMod n` induced by `f : ℤ →+ A` that maps `n` to `0`.
## Tags
zmod, quotient group, quotient ring, ideal quotient
-/
open QuotientAddGroup Set ZMod
variable (n : ℕ) {A R : Type*} [AddGroup A] [Ring R]
namespace Int
/-- `ℤ` modulo multiples of `n : ℕ` is `ZMod n`. -/
def quotientZMultiplesNatEquivZMod : ℤ ⧸ AddSubgroup.zmultiples (n : ℤ) ≃+ ZMod n :=
(quotientAddEquivOfEq (ZMod.ker_intCastAddHom _)).symm.trans <|
quotientKerEquivOfRightInverse (Int.castAddHom (ZMod n)) cast intCast_zmod_cast
/-- `ℤ` modulo multiples of `a : ℤ` is `ZMod a.natAbs`. -/
def quotientZMultiplesEquivZMod (a : ℤ) : ℤ ⧸ AddSubgroup.zmultiples a ≃+ ZMod a.natAbs :=
(quotientAddEquivOfEq (zmultiples_natAbs a)).symm.trans (quotientZMultiplesNatEquivZMod a.natAbs)
/-- `ℤ` modulo the ideal generated by `n : ℕ` is `ZMod n`. -/
def quotientSpanNatEquivZMod : ℤ ⧸ Ideal.span {(n : ℤ)} ≃+* ZMod n :=
(Ideal.quotEquivOfEq (ZMod.ker_intCastRingHom _)).symm.trans <|
RingHom.quotientKerEquivOfRightInverse <|
show Function.RightInverse ZMod.cast (Int.castRingHom (ZMod n)) from intCast_zmod_cast
/-- `ℤ` modulo the ideal generated by `a : ℤ` is `ZMod a.natAbs`. -/
def quotientSpanEquivZMod (a : ℤ) : ℤ ⧸ Ideal.span ({a} : Set ℤ) ≃+* ZMod a.natAbs :=
(Ideal.quotEquivOfEq (span_natAbs a)).symm.trans (quotientSpanNatEquivZMod a.natAbs)
end Int
noncomputable section ChineseRemainder
open Ideal
/-- The **Chinese remainder theorem**, elementary version for `ZMod`. See also
`Mathlib.Data.ZMod.Basic` for versions involving only two numbers. -/
def ZMod.prodEquivPi {ι : Type*} [Fintype ι] (a : ι → ℕ)
(coprime : Pairwise fun i j => Nat.Coprime (a i) (a j)) : ZMod (∏ i, a i) ≃+* Π i, ZMod (a i) :=
have : Pairwise fun i j => IsCoprime (span {(a i : ℤ)}) (span {(a j : ℤ)}) :=
fun _i _j h ↦ (isCoprime_span_singleton_iff _ _).mpr ((coprime h).cast (R := ℤ))
Int.quotientSpanNatEquivZMod _ |>.symm.trans <|
quotEquivOfEq (iInf_span_singleton_natCast (R := ℤ) coprime) |>.symm.trans <|
quotientInfRingEquivPiQuotient _ this |>.trans <|
RingEquiv.piCongrRight fun i ↦ Int.quotientSpanNatEquivZMod (a i)
end ChineseRemainder
namespace AddAction
open AddSubgroup AddMonoidHom AddEquiv Function
variable {α β : Type*} [AddGroup α] (a : α) [AddAction α β] (b : β)
/-- The quotient `(ℤ ∙ a) ⧸ (stabilizer b)` is cyclic of order `minimalPeriod (a +ᵥ ·) b`. -/
noncomputable def zmultiplesQuotientStabilizerEquiv :
zmultiples a ⧸ stabilizer (zmultiples a) b ≃+ ZMod (minimalPeriod (a +ᵥ ·) b) :=
(ofBijective
(map _ (stabilizer (zmultiples a) b) (zmultiplesHom (zmultiples a) ⟨a, mem_zmultiples a⟩)
(by
rw [zmultiples_le, mem_comap, mem_stabilizer_iff, zmultiplesHom_apply, natCast_zsmul]
simp_rw [← vadd_iterate]
exact isPeriodicPt_minimalPeriod (a +ᵥ ·) b))
⟨by
rw [← ker_eq_bot_iff, eq_bot_iff]
refine fun q => induction_on q fun n hn => ?_
rw [mem_bot, eq_zero_iff, Int.mem_zmultiples_iff, ←
zsmul_vadd_eq_iff_minimalPeriod_dvd]
exact (eq_zero_iff _).mp hn, fun q =>
induction_on q fun ⟨_, n, rfl⟩ => ⟨n, rfl⟩⟩).symm.trans
(Int.quotientZMultiplesNatEquivZMod (minimalPeriod (a +ᵥ ·) b))
theorem zmultiplesQuotientStabilizerEquiv_symm_apply (n : ZMod (minimalPeriod (a +ᵥ ·) b)) :
(zmultiplesQuotientStabilizerEquiv a b).symm n =
(cast n : ℤ) • (⟨a, mem_zmultiples a⟩ : zmultiples a) :=
rfl
end AddAction
namespace MulAction
open AddAction Subgroup AddSubgroup Function
variable {α β : Type*} [Group α] (a : α) [MulAction α β] (b : β)
/-- The quotient `(a ^ ℤ) ⧸ (stabilizer b)` is cyclic of order `minimalPeriod ((•) a) b`. -/
noncomputable def zpowersQuotientStabilizerEquiv :
zpowers a ⧸ stabilizer (zpowers a) b ≃* Multiplicative (ZMod (minimalPeriod (a • ·) b)) :=
letI f := zmultiplesQuotientStabilizerEquiv (Additive.ofMul a) b
AddEquiv.toMultiplicative f
theorem zpowersQuotientStabilizerEquiv_symm_apply (n : ZMod (minimalPeriod (a • ·) b)) :
(zpowersQuotientStabilizerEquiv a b).symm n = (⟨a, mem_zpowers a⟩ : zpowers a) ^ (cast n : ℤ) :=
rfl
/-- The orbit `(a ^ ℤ) • b` is a cycle of order `minimalPeriod ((•) a) b`. -/
noncomputable def orbitZPowersEquiv : orbit (zpowers a) b ≃ ZMod (minimalPeriod (a • ·) b) :=
(orbitEquivQuotientStabilizer _ b).trans (zpowersQuotientStabilizerEquiv a b).toEquiv
/-- The orbit `(ℤ • a) +ᵥ b` is a cycle of order `minimalPeriod (a +ᵥ ·) b`. -/
noncomputable def _root_.AddAction.orbitZMultiplesEquiv {α β : Type*} [AddGroup α] (a : α)
[AddAction α β] (b : β) :
AddAction.orbit (zmultiples a) b ≃ ZMod (minimalPeriod (a +ᵥ ·) b) :=
(AddAction.orbitEquivQuotientStabilizer (zmultiples a) b).trans
(zmultiplesQuotientStabilizerEquiv a b).toEquiv
attribute [to_additive existing] orbitZPowersEquiv
@[to_additive]
theorem orbitZPowersEquiv_symm_apply (k : ZMod (minimalPeriod (a • ·) b)) :
(orbitZPowersEquiv a b).symm k =
(⟨a, mem_zpowers a⟩ : zpowers a) ^ (cast k : ℤ) • ⟨b, mem_orbit_self b⟩ :=
rfl
@[deprecated (since := "2024-02-21")]
alias _root_.AddAction.orbit_zmultiples_equiv_symm_apply := orbitZMultiplesEquiv_symm_apply
theorem orbitZPowersEquiv_symm_apply' (k : ℤ) :
(orbitZPowersEquiv a b).symm k =
(⟨a, mem_zpowers a⟩ : zpowers a) ^ k • ⟨b, mem_orbit_self b⟩ := by
rw [orbitZPowersEquiv_symm_apply, ZMod.coe_intCast]
exact Subtype.ext (zpow_smul_mod_minimalPeriod _ _ k)
theorem _root_.AddAction.orbitZMultiplesEquiv_symm_apply' {α β : Type*} [AddGroup α] (a : α)
[AddAction α β] (b : β) (k : ℤ) :
(AddAction.orbitZMultiplesEquiv a b).symm k =
k • (⟨a, mem_zmultiples a⟩ : zmultiples a) +ᵥ ⟨b, AddAction.mem_orbit_self b⟩ := by
rw [AddAction.orbitZMultiplesEquiv_symm_apply, ZMod.coe_intCast]
-- Porting note: times out without `a b` explicit
exact Subtype.ext (zsmul_vadd_mod_minimalPeriod a b k)
attribute [to_additive existing]
orbitZPowersEquiv_symm_apply'
@[to_additive]
theorem minimalPeriod_eq_card [Fintype (orbit (zpowers a) b)] :
minimalPeriod (a • ·) b = Fintype.card (orbit (zpowers a) b) := by
-- Porting note: added `(_)` to find `Fintype` by unification
rw [← Fintype.ofEquiv_card (orbitZPowersEquiv a b), @ZMod.card _ (_)]
@[to_additive]
instance minimalPeriod_pos [Finite <| orbit (zpowers a) b] :
NeZero <| minimalPeriod (a • ·) b :=
⟨by
cases nonempty_fintype (orbit (zpowers a) b)
haveI : Nonempty (orbit (zpowers a) b) := (orbit_nonempty b).to_subtype
rw [minimalPeriod_eq_card]
exact Fintype.card_ne_zero⟩
end MulAction
section Group
open Subgroup
variable {α : Type*} [Group α] (a : α)
/-- See also `Fintype.card_zpowers`. -/
@[to_additive (attr := simp) "See also `Fintype.card_zmultiples`."]
theorem Nat.card_zpowers : Nat.card (zpowers a) = orderOf a := by
have := Nat.card_congr (MulAction.orbitZPowersEquiv a (1 : α))
rwa [Nat.card_zmod, orbit_subgroup_one_eq_self] at this
variable {a}
@[to_additive (attr := simp)]
lemma finite_zpowers : (zpowers a : Set α).Finite ↔ IsOfFinOrder a := by
simp only [← orderOf_pos_iff, ← Nat.card_zpowers, Nat.card_pos_iff, ← SetLike.coe_sort_coe,
nonempty_coe_sort, Nat.card_pos_iff, Set.finite_coe_iff, Subgroup.coe_nonempty, true_and]
@[to_additive (attr := simp)]
lemma infinite_zpowers : (zpowers a : Set α).Infinite ↔ ¬IsOfFinOrder a := finite_zpowers.not
@[to_additive]
protected alias ⟨_, IsOfFinOrder.finite_zpowers⟩ := finite_zpowers
end Group
|
Data\ZMod\Units.lean | /-
Copyright (c) 2023 Moritz Firsching. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Firsching, Ashvni Narayanan, Michael Stoll
-/
import Mathlib.Algebra.BigOperators.Associated
import Mathlib.Data.ZMod.Basic
import Mathlib.Data.Nat.PrimeFin
import Mathlib.RingTheory.Coprime.Lemmas
/-!
# Lemmas about units in `ZMod`.
-/
namespace ZMod
variable {n m : ℕ}
/-- `unitsMap` is a group homomorphism that maps units of `ZMod m` to units of `ZMod n` when `n`
divides `m`. -/
def unitsMap (hm : n ∣ m) : (ZMod m)ˣ →* (ZMod n)ˣ := Units.map (castHom hm (ZMod n))
lemma unitsMap_def (hm : n ∣ m) : unitsMap hm = Units.map (castHom hm (ZMod n)) := rfl
lemma unitsMap_comp {d : ℕ} (hm : n ∣ m) (hd : m ∣ d) :
(unitsMap hm).comp (unitsMap hd) = unitsMap (dvd_trans hm hd) := by
simp only [unitsMap_def]
rw [← Units.map_comp]
exact congr_arg Units.map <| congr_arg RingHom.toMonoidHom <| castHom_comp hm hd
@[simp]
lemma unitsMap_self (n : ℕ) : unitsMap (dvd_refl n) = MonoidHom.id _ := by
simp [unitsMap, castHom_self]
lemma IsUnit_cast_of_dvd (hm : n ∣ m) (a : Units (ZMod m)) : IsUnit (cast (a : ZMod m) : ZMod n) :=
Units.isUnit (unitsMap hm a)
theorem unitsMap_surjective [hm : NeZero m] (h : n ∣ m) :
Function.Surjective (unitsMap h) := by
suffices ∀ x : ℕ, x.Coprime n → ∃ k : ℕ, (x + k * n).Coprime m by
intro x
have ⟨k, hk⟩ := this x.val.val (val_coe_unit_coprime x)
refine ⟨unitOfCoprime _ hk, Units.ext ?_⟩
have : NeZero n := ⟨fun hn ↦ hm.out (eq_zero_of_zero_dvd (hn ▸ h))⟩
simp [unitsMap_def]
intro x hx
let ps := m.primeFactors.filter (fun p ↦ ¬p ∣ x)
use ps.prod id
apply Nat.coprime_of_dvd
intro p pp hp hpn
by_cases hpx : p ∣ x
· have h := Nat.dvd_sub' hp hpx
rw [add_comm, Nat.add_sub_cancel] at h
rcases pp.dvd_mul.mp h with h | h
· have ⟨q, hq, hq'⟩ := (pp.prime.dvd_finset_prod_iff id).mp h
rw [Finset.mem_filter, Nat.mem_primeFactors,
← (Nat.prime_dvd_prime_iff_eq pp hq.1.1).mp hq'] at hq
exact hq.2 hpx
· exact Nat.Prime.not_coprime_iff_dvd.mpr ⟨p, pp, hpx, h⟩ hx
· have pps : p ∈ ps := Finset.mem_filter.mpr ⟨Nat.mem_primeFactors.mpr ⟨pp, hpn, hm.out⟩, hpx⟩
have h := Nat.dvd_sub' hp ((Finset.dvd_prod_of_mem id pps).mul_right n)
rw [Nat.add_sub_cancel] at h
contradiction
-- This needs `Nat.primeFactors`, so cannot go into `Mathlib.Data.ZMod.Basic`.
open Nat in
lemma not_isUnit_of_mem_primeFactors {n p : ℕ} (h : p ∈ n.primeFactors) :
¬ IsUnit (p : ZMod n) := by
rw [isUnit_iff_coprime]
exact (Prime.dvd_iff_not_coprime <| prime_of_mem_primeFactors h).mp <| dvd_of_mem_primeFactors h
/-- Any element of `ZMod N` has the form `u * d` where `u` is a unit and `d` is a divisor of `N`. -/
lemma eq_unit_mul_divisor {N : ℕ} (a : ZMod N) :
∃ d : ℕ, d ∣ N ∧ ∃ (u : ZMod N), IsUnit u ∧ a = u * d := by
rcases eq_or_ne N 0 with rfl | hN
-- Silly special case : N = 0. Of no mathematical interest, but true, so let's prove it.
· change ℤ at a
rcases eq_or_ne a 0 with rfl | ha
· refine ⟨0, dvd_zero _, 1, isUnit_one, by rw [Nat.cast_zero, mul_zero]⟩
refine ⟨a.natAbs, dvd_zero _, Int.sign a, ?_, (Int.sign_mul_natAbs a).symm⟩
rcases lt_or_gt_of_ne ha with h | h
· simp only [Int.sign_eq_neg_one_of_neg h, IsUnit.neg_iff, isUnit_one]
· simp only [Int.sign_eq_one_of_pos h, isUnit_one]
-- now the interesting case
have : NeZero N := ⟨hN⟩
-- Define `d` as the GCD of a lift of `a` and `N`.
let d := a.val.gcd N
have hd : d ≠ 0 := Nat.gcd_ne_zero_right hN
obtain ⟨a₀, (ha₀ : _ = d * _)⟩ := a.val.gcd_dvd_left N
obtain ⟨N₀, (hN₀ : _ = d * _)⟩ := a.val.gcd_dvd_right N
refine ⟨d, ⟨N₀, hN₀⟩, ?_⟩
-- Show `a` is a unit mod `N / d`.
have hu₀ : IsUnit (a₀ : ZMod N₀) := by
refine (isUnit_iff_coprime _ _).mpr (Nat.isCoprime_iff_coprime.mp ?_)
obtain ⟨p, q, hpq⟩ : ∃ (p q : ℤ), d = a.val * p + N * q := ⟨_, _, Nat.gcd_eq_gcd_ab _ _⟩
rw [ha₀, hN₀, Nat.cast_mul, Nat.cast_mul, mul_assoc, mul_assoc, ← mul_add, eq_comm,
mul_comm _ p, mul_comm _ q] at hpq
exact ⟨p, q, Int.eq_one_of_mul_eq_self_right (Nat.cast_ne_zero.mpr hd) hpq⟩
-- Lift it arbitrarily to a unit mod `N`.
obtain ⟨u, hu⟩ := (ZMod.unitsMap_surjective (⟨d, mul_comm d N₀ ▸ hN₀⟩ : N₀ ∣ N)) hu₀.unit
rw [unitsMap_def, ← Units.eq_iff, Units.coe_map, IsUnit.unit_spec, MonoidHom.coe_coe] at hu
refine ⟨u.val, u.isUnit, ?_⟩
rw [← ZMod.natCast_zmod_val a, ← ZMod.natCast_zmod_val u.1, ha₀, ← Nat.cast_mul,
ZMod.natCast_eq_natCast_iff, mul_comm _ d, Nat.ModEq]
simp only [hN₀, Nat.mul_mod_mul_left, Nat.mul_right_inj hd]
rw [← Nat.ModEq, ← ZMod.natCast_eq_natCast_iff, ← hu, natCast_val, castHom_apply]
end ZMod
|
Deprecated\Group.lean | /-
Copyright (c) 2019 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Algebra.Group.Equiv.Basic
import Mathlib.Algebra.Group.TypeTags
import Mathlib.Algebra.Group.Units.Hom
import Mathlib.Algebra.Ring.Hom.Defs
/-!
# Unbundled monoid and group homomorphisms
This file is deprecated, and is no longer imported by anything in mathlib other than other
deprecated files, and test files. You should not need to import it.
This file defines predicates for unbundled monoid and group homomorphisms. Instead of using
this file, please use `MonoidHom`, defined in `Algebra.Hom.Group`, with notation `→*`, for
morphisms between monoids or groups. For example use `φ : G →* H` to represent a group
homomorphism between multiplicative groups, and `ψ : A →+ B` to represent a group homomorphism
between additive groups.
## Main Definitions
`IsMonoidHom` (deprecated), `IsGroupHom` (deprecated)
## Tags
IsGroupHom, IsMonoidHom
-/
universe u v
variable {α : Type u} {β : Type v}
/-- Predicate for maps which preserve an addition. -/
structure IsAddHom {α β : Type*} [Add α] [Add β] (f : α → β) : Prop where
/-- The proposition that `f` preserves addition. -/
map_add : ∀ x y, f (x + y) = f x + f y
/-- Predicate for maps which preserve a multiplication. -/
@[to_additive]
structure IsMulHom {α β : Type*} [Mul α] [Mul β] (f : α → β) : Prop where
/-- The proposition that `f` preserves multiplication. -/
map_mul : ∀ x y, f (x * y) = f x * f y
namespace IsMulHom
variable [Mul α] [Mul β] {γ : Type*} [Mul γ]
/-- The identity map preserves multiplication. -/
@[to_additive "The identity map preserves addition"]
theorem id : IsMulHom (id : α → α) :=
{ map_mul := fun _ _ => rfl }
/-- The composition of maps which preserve multiplication, also preserves multiplication. -/
@[to_additive "The composition of addition preserving maps also preserves addition"]
theorem comp {f : α → β} {g : β → γ} (hf : IsMulHom f) (hg : IsMulHom g) : IsMulHom (g ∘ f) :=
{ map_mul := fun x y => by simp only [Function.comp, hf.map_mul, hg.map_mul] }
/-- A product of maps which preserve multiplication,
preserves multiplication when the target is commutative. -/
@[to_additive
"A sum of maps which preserves addition, preserves addition when the target
is commutative."]
theorem mul {α β} [Semigroup α] [CommSemigroup β] {f g : α → β} (hf : IsMulHom f)
(hg : IsMulHom g) : IsMulHom fun a => f a * g a :=
{ map_mul := fun a b => by
simp only [hf.map_mul, hg.map_mul, mul_comm, mul_assoc, mul_left_comm] }
/-- The inverse of a map which preserves multiplication,
preserves multiplication when the target is commutative. -/
@[to_additive
"The negation of a map which preserves addition, preserves addition when
the target is commutative."]
theorem inv {α β} [Mul α] [CommGroup β] {f : α → β} (hf : IsMulHom f) : IsMulHom fun a => (f a)⁻¹ :=
{ map_mul := fun a b => (hf.map_mul a b).symm ▸ mul_inv _ _ }
end IsMulHom
/-- Predicate for additive monoid homomorphisms
(deprecated -- use the bundled `MonoidHom` version). -/
structure IsAddMonoidHom [AddZeroClass α] [AddZeroClass β] (f : α → β) extends IsAddHom f :
Prop where
/-- The proposition that `f` preserves the additive identity. -/
map_zero : f 0 = 0
/-- Predicate for monoid homomorphisms (deprecated -- use the bundled `MonoidHom` version). -/
@[to_additive]
structure IsMonoidHom [MulOneClass α] [MulOneClass β] (f : α → β) extends IsMulHom f : Prop where
/-- The proposition that `f` preserves the multiplicative identity. -/
map_one : f 1 = 1
namespace MonoidHom
variable {M : Type*} {N : Type*} {mM : MulOneClass M} {mN : MulOneClass N}
/-- Interpret a map `f : M → N` as a homomorphism `M →* N`. -/
@[to_additive "Interpret a map `f : M → N` as a homomorphism `M →+ N`."]
def of {f : M → N} (h : IsMonoidHom f) : M →* N where
toFun := f
map_one' := h.2
map_mul' := h.1.1
@[to_additive (attr := simp)]
theorem coe_of {f : M → N} (hf : IsMonoidHom f) : ⇑(MonoidHom.of hf) = f :=
rfl
@[to_additive]
theorem isMonoidHom_coe (f : M →* N) : IsMonoidHom (f : M → N) :=
{ map_mul := f.map_mul
map_one := f.map_one }
end MonoidHom
namespace MulEquiv
variable {M : Type*} {N : Type*} [MulOneClass M] [MulOneClass N]
/-- A multiplicative isomorphism preserves multiplication (deprecated). -/
@[to_additive "An additive isomorphism preserves addition (deprecated)."]
theorem isMulHom (h : M ≃* N) : IsMulHom h :=
⟨h.map_mul⟩
/-- A multiplicative bijection between two monoids is a monoid hom
(deprecated -- use `MulEquiv.toMonoidHom`). -/
@[to_additive
"An additive bijection between two additive monoids is an additive
monoid hom (deprecated). "]
theorem isMonoidHom (h : M ≃* N) : IsMonoidHom h :=
{ map_mul := h.map_mul
map_one := h.map_one }
end MulEquiv
namespace IsMonoidHom
variable [MulOneClass α] [MulOneClass β] {f : α → β} (hf : IsMonoidHom f)
/-- A monoid homomorphism preserves multiplication. -/
@[to_additive "An additive monoid homomorphism preserves addition."]
theorem map_mul' (x y) : f (x * y) = f x * f y :=
hf.map_mul x y
/-- The inverse of a map which preserves multiplication,
preserves multiplication when the target is commutative. -/
@[to_additive
"The negation of a map which preserves addition, preserves addition
when the target is commutative."]
theorem inv {α β} [MulOneClass α] [CommGroup β] {f : α → β} (hf : IsMonoidHom f) :
IsMonoidHom fun a => (f a)⁻¹ :=
{ map_one := hf.map_one.symm ▸ inv_one
map_mul := fun a b => (hf.map_mul a b).symm ▸ mul_inv _ _ }
end IsMonoidHom
/-- A map to a group preserving multiplication is a monoid homomorphism. -/
@[to_additive "A map to an additive group preserving addition is an additive monoid
homomorphism."]
theorem IsMulHom.to_isMonoidHom [MulOneClass α] [Group β] {f : α → β} (hf : IsMulHom f) :
IsMonoidHom f :=
{ map_one := (mul_right_eq_self (a := f 1)).1 <| by rw [← hf.map_mul, one_mul]
map_mul := hf.map_mul }
namespace IsMonoidHom
variable [MulOneClass α] [MulOneClass β] {f : α → β}
/-- The identity map is a monoid homomorphism. -/
@[to_additive "The identity map is an additive monoid homomorphism."]
theorem id : IsMonoidHom (@id α) :=
{ map_one := rfl
map_mul := fun _ _ => rfl }
/-- The composite of two monoid homomorphisms is a monoid homomorphism. -/
@[to_additive
"The composite of two additive monoid homomorphisms is an additive monoid
homomorphism."]
theorem comp (hf : IsMonoidHom f) {γ} [MulOneClass γ] {g : β → γ} (hg : IsMonoidHom g) :
IsMonoidHom (g ∘ f) :=
{ IsMulHom.comp hf.toIsMulHom hg.toIsMulHom with
map_one := show g _ = 1 by rw [hf.map_one, hg.map_one] }
end IsMonoidHom
namespace IsAddMonoidHom
/-- Left multiplication in a ring is an additive monoid morphism. -/
theorem isAddMonoidHom_mul_left {γ : Type*} [NonUnitalNonAssocSemiring γ] (x : γ) :
IsAddMonoidHom fun y : γ => x * y :=
{ map_zero := mul_zero x
map_add := fun y z => mul_add x y z }
/-- Right multiplication in a ring is an additive monoid morphism. -/
theorem isAddMonoidHom_mul_right {γ : Type*} [NonUnitalNonAssocSemiring γ] (x : γ) :
IsAddMonoidHom fun y : γ => y * x :=
{ map_zero := zero_mul x
map_add := fun y z => add_mul y z x }
end IsAddMonoidHom
/-- Predicate for additive group homomorphism (deprecated -- use bundled `MonoidHom`). -/
structure IsAddGroupHom [AddGroup α] [AddGroup β] (f : α → β) extends IsAddHom f : Prop
/-- Predicate for group homomorphisms (deprecated -- use bundled `MonoidHom`). -/
@[to_additive]
structure IsGroupHom [Group α] [Group β] (f : α → β) extends IsMulHom f : Prop
@[to_additive]
theorem MonoidHom.isGroupHom {G H : Type*} {_ : Group G} {_ : Group H} (f : G →* H) :
IsGroupHom (f : G → H) :=
{ map_mul := f.map_mul }
@[to_additive]
theorem MulEquiv.isGroupHom {G H : Type*} {_ : Group G} {_ : Group H} (h : G ≃* H) :
IsGroupHom h :=
{ map_mul := h.map_mul }
/-- Construct `IsGroupHom` from its only hypothesis. -/
@[to_additive "Construct `IsAddGroupHom` from its only hypothesis."]
theorem IsGroupHom.mk' [Group α] [Group β] {f : α → β} (hf : ∀ x y, f (x * y) = f x * f y) :
IsGroupHom f :=
{ map_mul := hf }
namespace IsGroupHom
variable [Group α] [Group β] {f : α → β} (hf : IsGroupHom f)
open IsMulHom (map_mul)
theorem map_mul' : ∀ x y, f (x * y) = f x * f y :=
hf.toIsMulHom.map_mul
/-- A group homomorphism is a monoid homomorphism. -/
@[to_additive "An additive group homomorphism is an additive monoid homomorphism."]
theorem to_isMonoidHom : IsMonoidHom f :=
hf.toIsMulHom.to_isMonoidHom
/-- A group homomorphism sends 1 to 1. -/
@[to_additive "An additive group homomorphism sends 0 to 0."]
theorem map_one : f 1 = 1 :=
hf.to_isMonoidHom.map_one
/-- A group homomorphism sends inverses to inverses. -/
@[to_additive "An additive group homomorphism sends negations to negations."]
theorem map_inv (hf : IsGroupHom f) (a : α) : f a⁻¹ = (f a)⁻¹ :=
eq_inv_of_mul_eq_one_left <| by rw [← hf.map_mul, inv_mul_self, hf.map_one]
@[to_additive]
theorem map_div (hf : IsGroupHom f) (a b : α) : f (a / b) = f a / f b := by
simp_rw [div_eq_mul_inv, hf.map_mul, hf.map_inv]
/-- The identity is a group homomorphism. -/
@[to_additive "The identity is an additive group homomorphism."]
theorem id : IsGroupHom (@id α) :=
{ map_mul := fun _ _ => rfl }
/-- The composition of two group homomorphisms is a group homomorphism. -/
@[to_additive
"The composition of two additive group homomorphisms is an additive
group homomorphism."]
theorem comp (hf : IsGroupHom f) {γ} [Group γ] {g : β → γ} (hg : IsGroupHom g) :
IsGroupHom (g ∘ f) :=
{ IsMulHom.comp hf.toIsMulHom hg.toIsMulHom with }
/-- A group homomorphism is injective iff its kernel is trivial. -/
@[to_additive "An additive group homomorphism is injective if its kernel is trivial."]
theorem injective_iff {f : α → β} (hf : IsGroupHom f) :
Function.Injective f ↔ ∀ a, f a = 1 → a = 1 :=
⟨fun h _ => by rw [← hf.map_one]; exact @h _ _, fun h x y hxy =>
eq_of_div_eq_one <| h _ <| by rwa [hf.map_div, div_eq_one]⟩
/-- The product of group homomorphisms is a group homomorphism if the target is commutative. -/
@[to_additive
"The sum of two additive group homomorphisms is an additive group homomorphism
if the target is commutative."]
theorem mul {α β} [Group α] [CommGroup β] {f g : α → β} (hf : IsGroupHom f) (hg : IsGroupHom g) :
IsGroupHom fun a => f a * g a :=
{ map_mul := (hf.toIsMulHom.mul hg.toIsMulHom).map_mul }
/-- The inverse of a group homomorphism is a group homomorphism if the target is commutative. -/
@[to_additive
"The negation of an additive group homomorphism is an additive group homomorphism
if the target is commutative."]
theorem inv {α β} [Group α] [CommGroup β] {f : α → β} (hf : IsGroupHom f) :
IsGroupHom fun a => (f a)⁻¹ :=
{ map_mul := hf.toIsMulHom.inv.map_mul }
end IsGroupHom
namespace RingHom
/-!
These instances look redundant, because `Deprecated.Ring` provides `IsRingHom` for a `→+*`.
Nevertheless these are harmless, and helpful for stripping out dependencies on `Deprecated.Ring`.
-/
variable {R : Type*} {S : Type*}
section
variable [NonAssocSemiring R] [NonAssocSemiring S]
theorem to_isMonoidHom (f : R →+* S) : IsMonoidHom f :=
{ map_one := f.map_one
map_mul := f.map_mul }
theorem to_isAddMonoidHom (f : R →+* S) : IsAddMonoidHom f :=
{ map_zero := f.map_zero
map_add := f.map_add }
end
section
variable [Ring R] [Ring S]
theorem to_isAddGroupHom (f : R →+* S) : IsAddGroupHom f :=
{ map_add := f.map_add }
end
end RingHom
/-- Inversion is a group homomorphism if the group is commutative. -/
@[to_additive
"Negation is an `AddGroup` homomorphism if the `AddGroup` is commutative."]
theorem Inv.isGroupHom [CommGroup α] : IsGroupHom (Inv.inv : α → α) :=
{ map_mul := mul_inv }
/-- The difference of two additive group homomorphisms is an additive group
homomorphism if the target is commutative. -/
theorem IsAddGroupHom.sub {α β} [AddGroup α] [AddCommGroup β] {f g : α → β} (hf : IsAddGroupHom f)
(hg : IsAddGroupHom g) : IsAddGroupHom fun a => f a - g a := by
simpa only [sub_eq_add_neg] using hf.add hg.neg
namespace Units
variable {M : Type*} {N : Type*} [Monoid M] [Monoid N]
/-- The group homomorphism on units induced by a multiplicative morphism. -/
abbrev map' {f : M → N} (hf : IsMonoidHom f) : Mˣ →* Nˣ :=
map (MonoidHom.of hf)
@[simp]
theorem coe_map' {f : M → N} (hf : IsMonoidHom f) (x : Mˣ) : ↑((map' hf : Mˣ → Nˣ) x) = f x :=
rfl
theorem coe_isMonoidHom : IsMonoidHom (↑· : Mˣ → M) :=
(coeHom M).isMonoidHom_coe
end Units
namespace IsUnit
variable {M : Type*} {N : Type*} [Monoid M] [Monoid N] {x : M}
theorem map' {f : M → N} (hf : IsMonoidHom f) {x : M} (h : IsUnit x) : IsUnit (f x) :=
h.map (MonoidHom.of hf)
end IsUnit
theorem Additive.isAddHom [Mul α] [Mul β] {f : α → β} (hf : IsMulHom f) :
@IsAddHom (Additive α) (Additive β) _ _ f :=
{ map_add := hf.map_mul }
theorem Multiplicative.isMulHom [Add α] [Add β] {f : α → β} (hf : IsAddHom f) :
@IsMulHom (Multiplicative α) (Multiplicative β) _ _ f :=
{ map_mul := hf.map_add }
-- defeq abuse
theorem Additive.isAddMonoidHom [MulOneClass α] [MulOneClass β] {f : α → β}
(hf : IsMonoidHom f) : @IsAddMonoidHom (Additive α) (Additive β) _ _ f :=
{ Additive.isAddHom hf.toIsMulHom with map_zero := hf.map_one }
theorem Multiplicative.isMonoidHom [AddZeroClass α] [AddZeroClass β] {f : α → β}
(hf : IsAddMonoidHom f) : @IsMonoidHom (Multiplicative α) (Multiplicative β) _ _ f :=
{ Multiplicative.isMulHom hf.toIsAddHom with map_one := hf.map_zero }
theorem Additive.isAddGroupHom [Group α] [Group β] {f : α → β} (hf : IsGroupHom f) :
@IsAddGroupHom (Additive α) (Additive β) _ _ f :=
{ map_add := hf.toIsMulHom.map_mul }
theorem Multiplicative.isGroupHom [AddGroup α] [AddGroup β] {f : α → β} (hf : IsAddGroupHom f) :
@IsGroupHom (Multiplicative α) (Multiplicative β) _ _ f :=
{ map_mul := hf.toIsAddHom.map_add }
|
Deprecated\Ring.lean | /-
Copyright (c) 2020 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Deprecated.Group
/-!
# Unbundled semiring and ring homomorphisms (deprecated)
This file is deprecated, and is no longer imported by anything in mathlib other than other
deprecated files, and test files. You should not need to import it.
This file defines predicates for unbundled semiring and ring homomorphisms. Instead of using
this file, please use `RingHom`, defined in `Algebra.Hom.Ring`, with notation `→+*`, for
morphisms between semirings or rings. For example use `φ : A →+* B` to represent a
ring homomorphism.
## Main Definitions
`IsSemiringHom` (deprecated), `IsRingHom` (deprecated)
## Tags
IsSemiringHom, IsRingHom
-/
universe u v w
variable {α : Type u}
/-- Predicate for semiring homomorphisms (deprecated -- use the bundled `RingHom` version). -/
structure IsSemiringHom {α : Type u} {β : Type v} [Semiring α] [Semiring β] (f : α → β) : Prop where
/-- The proposition that `f` preserves the additive identity. -/
map_zero : f 0 = 0
/-- The proposition that `f` preserves the multiplicative identity. -/
map_one : f 1 = 1
/-- The proposition that `f` preserves addition. -/
map_add : ∀ x y, f (x + y) = f x + f y
/-- The proposition that `f` preserves multiplication. -/
map_mul : ∀ x y, f (x * y) = f x * f y
namespace IsSemiringHom
variable {β : Type v} [Semiring α] [Semiring β]
variable {f : α → β} (hf : IsSemiringHom f) {x y : α}
/-- The identity map is a semiring homomorphism. -/
theorem id : IsSemiringHom (@id α) := by constructor <;> intros <;> rfl
/-- The composition of two semiring homomorphisms is a semiring homomorphism. -/
theorem comp (hf : IsSemiringHom f) {γ} [Semiring γ] {g : β → γ} (hg : IsSemiringHom g) :
IsSemiringHom (g ∘ f) :=
{ map_zero := by simpa [map_zero hf] using map_zero hg
map_one := by simpa [map_one hf] using map_one hg
map_add := fun {x y} => by simp [map_add hf, map_add hg]
map_mul := fun {x y} => by simp [map_mul hf, map_mul hg] }
/-- A semiring homomorphism is an additive monoid homomorphism. -/
theorem to_isAddMonoidHom (hf : IsSemiringHom f) : IsAddMonoidHom f :=
{ ‹IsSemiringHom f› with map_add := by apply @‹IsSemiringHom f›.map_add }
/-- A semiring homomorphism is a monoid homomorphism. -/
theorem to_isMonoidHom (hf : IsSemiringHom f) : IsMonoidHom f :=
{ ‹IsSemiringHom f› with }
end IsSemiringHom
/-- Predicate for ring homomorphisms (deprecated -- use the bundled `RingHom` version). -/
structure IsRingHom {α : Type u} {β : Type v} [Ring α] [Ring β] (f : α → β) : Prop where
/-- The proposition that `f` preserves the multiplicative identity. -/
map_one : f 1 = 1
/-- The proposition that `f` preserves multiplication. -/
map_mul : ∀ x y, f (x * y) = f x * f y
/-- The proposition that `f` preserves addition. -/
map_add : ∀ x y, f (x + y) = f x + f y
namespace IsRingHom
variable {β : Type v} [Ring α] [Ring β]
/-- A map of rings that is a semiring homomorphism is also a ring homomorphism. -/
theorem of_semiring {f : α → β} (H : IsSemiringHom f) : IsRingHom f :=
{ H with }
variable {f : α → β} (hf : IsRingHom f) {x y : α}
/-- Ring homomorphisms map zero to zero. -/
theorem map_zero (hf : IsRingHom f) : f 0 = 0 :=
calc
f 0 = f (0 + 0) - f 0 := by rw [hf.map_add]; simp
_ = 0 := by simp
/-- Ring homomorphisms preserve additive inverses. -/
theorem map_neg (hf : IsRingHom f) : f (-x) = -f x :=
calc
f (-x) = f (-x + x) - f x := by rw [hf.map_add]; simp
_ = -f x := by simp [hf.map_zero]
/-- Ring homomorphisms preserve subtraction. -/
theorem map_sub (hf : IsRingHom f) : f (x - y) = f x - f y := by
simp [sub_eq_add_neg, hf.map_add, hf.map_neg]
/-- The identity map is a ring homomorphism. -/
theorem id : IsRingHom (@id α) := by constructor <;> intros <;> rfl
-- see Note [no instance on morphisms]
/-- The composition of two ring homomorphisms is a ring homomorphism. -/
theorem comp (hf : IsRingHom f) {γ} [Ring γ] {g : β → γ} (hg : IsRingHom g) : IsRingHom (g ∘ f) :=
{ map_add := fun x y => by simp only [Function.comp_apply, map_add hf, map_add hg]
map_mul := fun x y => by simp only [Function.comp_apply, map_mul hf, map_mul hg]
map_one := by simp only [Function.comp_apply, map_one hf, map_one hg] }
/-- A ring homomorphism is also a semiring homomorphism. -/
theorem to_isSemiringHom (hf : IsRingHom f) : IsSemiringHom f :=
{ ‹IsRingHom f› with map_zero := map_zero hf }
theorem to_isAddGroupHom (hf : IsRingHom f) : IsAddGroupHom f :=
{ map_add := hf.map_add }
end IsRingHom
variable {β : Type v} {γ : Type w} {rα : Semiring α} {rβ : Semiring β}
namespace RingHom
section
/-- Interpret `f : α → β` with `IsSemiringHom f` as a ring homomorphism. -/
def of {f : α → β} (hf : IsSemiringHom f) : α →+* β :=
{ MonoidHom.of hf.to_isMonoidHom, AddMonoidHom.of hf.to_isAddMonoidHom with toFun := f }
@[simp]
theorem coe_of {f : α → β} (hf : IsSemiringHom f) : ⇑(of hf) = f :=
rfl
theorem to_isSemiringHom (f : α →+* β) : IsSemiringHom f :=
{ map_zero := f.map_zero
map_one := f.map_one
map_add := f.map_add
map_mul := f.map_mul }
end
theorem to_isRingHom {α γ} [Ring α] [Ring γ] (g : α →+* γ) : IsRingHom g :=
IsRingHom.of_semiring g.to_isSemiringHom
end RingHom
|
Deprecated\Subfield.lean | /-
Copyright (c) 2018 Andreas Swerdlow. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andreas Swerdlow
-/
import Mathlib.Algebra.Field.Basic
import Mathlib.Deprecated.Subring
/-!
# Unbundled subfields (deprecated)
This file is deprecated, and is no longer imported by anything in mathlib other than other
deprecated files, and test files. You should not need to import it.
This file defines predicates for unbundled subfields. Instead of using this file, please use
`Subfield`, defined in `FieldTheory.Subfield`, for subfields of fields.
## Main definitions
`IsSubfield (S : Set F) : Prop` : the predicate that `S` is the underlying set of a subfield
of the field `F`. The bundled variant `Subfield F` should be used in preference to this.
## Tags
IsSubfield, subfield
-/
variable {F : Type*} [Field F] (S : Set F)
/-- `IsSubfield (S : Set F)` is the predicate saying that a given subset of a field is
the set underlying a subfield. This structure is deprecated; use the bundled variant
`Subfield F` to model subfields of a field. -/
structure IsSubfield extends IsSubring S : Prop where
inv_mem : ∀ {x : F}, x ∈ S → x⁻¹ ∈ S
theorem IsSubfield.div_mem {S : Set F} (hS : IsSubfield S) {x y : F} (hx : x ∈ S) (hy : y ∈ S) :
x / y ∈ S := by
rw [div_eq_mul_inv]
exact hS.toIsSubring.toIsSubmonoid.mul_mem hx (hS.inv_mem hy)
theorem IsSubfield.pow_mem {a : F} {n : ℤ} {s : Set F} (hs : IsSubfield s) (h : a ∈ s) :
a ^ n ∈ s := by
cases' n with n n
· suffices a ^ (n : ℤ) ∈ s by exact this
rw [zpow_natCast]
exact hs.toIsSubring.toIsSubmonoid.pow_mem h
· rw [zpow_negSucc]
exact hs.inv_mem (hs.toIsSubring.toIsSubmonoid.pow_mem h)
theorem Univ.isSubfield : IsSubfield (@Set.univ F) :=
{ Univ.isSubmonoid, IsAddSubgroup.univ_addSubgroup with
inv_mem := fun _ ↦ trivial }
theorem Preimage.isSubfield {K : Type*} [Field K] (f : F →+* K) {s : Set K} (hs : IsSubfield s) :
IsSubfield (f ⁻¹' s) :=
{ f.isSubring_preimage hs.toIsSubring with
inv_mem := fun {a} (ha : f a ∈ s) ↦ show f a⁻¹ ∈ s by
rw [map_inv₀]
exact hs.inv_mem ha }
theorem Image.isSubfield {K : Type*} [Field K] (f : F →+* K) {s : Set F} (hs : IsSubfield s) :
IsSubfield (f '' s) :=
{ f.isSubring_image hs.toIsSubring with
inv_mem := fun ⟨x, xmem, ha⟩ ↦ ⟨x⁻¹, hs.inv_mem xmem, ha ▸ map_inv₀ f x⟩ }
theorem Range.isSubfield {K : Type*} [Field K] (f : F →+* K) : IsSubfield (Set.range f) := by
rw [← Set.image_univ]
apply Image.isSubfield _ Univ.isSubfield
namespace Field
/-- `Field.closure s` is the minimal subfield that includes `s`. -/
def closure : Set F :=
{ x | ∃ y ∈ Ring.closure S, ∃ z ∈ Ring.closure S, y / z = x }
variable {S}
theorem ring_closure_subset : Ring.closure S ⊆ closure S :=
fun x hx ↦ ⟨x, hx, 1, Ring.closure.isSubring.toIsSubmonoid.one_mem, div_one x⟩
theorem closure.isSubmonoid : IsSubmonoid (closure S) :=
{ mul_mem := by
rintro _ _ ⟨p, hp, q, hq, hq0, rfl⟩ ⟨r, hr, s, hs, hs0, rfl⟩
exact ⟨p * r, IsSubmonoid.mul_mem Ring.closure.isSubring.toIsSubmonoid hp hr, q * s,
IsSubmonoid.mul_mem Ring.closure.isSubring.toIsSubmonoid hq hs,
(div_mul_div_comm _ _ _ _).symm⟩
one_mem := ring_closure_subset <| IsSubmonoid.one_mem Ring.closure.isSubring.toIsSubmonoid }
theorem closure.isSubfield : IsSubfield (closure S) :=
{ closure.isSubmonoid with
add_mem := by
intro a b ha hb
rcases id ha with ⟨p, hp, q, hq, rfl⟩
rcases id hb with ⟨r, hr, s, hs, rfl⟩
by_cases hq0 : q = 0
· rwa [hq0, div_zero, zero_add]
by_cases hs0 : s = 0
· rwa [hs0, div_zero, add_zero]
exact ⟨p * s + q * r,
IsAddSubmonoid.add_mem Ring.closure.isSubring.toIsAddSubgroup.toIsAddSubmonoid
(Ring.closure.isSubring.toIsSubmonoid.mul_mem hp hs)
(Ring.closure.isSubring.toIsSubmonoid.mul_mem hq hr),
q * s, Ring.closure.isSubring.toIsSubmonoid.mul_mem hq hs, (div_add_div p r hq0 hs0).symm⟩
zero_mem := ring_closure_subset Ring.closure.isSubring.toIsAddSubgroup.toIsAddSubmonoid.zero_mem
neg_mem := by
rintro _ ⟨p, hp, q, hq, rfl⟩
exact ⟨-p, Ring.closure.isSubring.toIsAddSubgroup.neg_mem hp, q, hq, neg_div q p⟩
inv_mem := by
rintro _ ⟨p, hp, q, hq, rfl⟩
exact ⟨q, hq, p, hp, (inv_div _ _).symm⟩ }
theorem mem_closure {a : F} (ha : a ∈ S) : a ∈ closure S :=
ring_closure_subset <| Ring.mem_closure ha
theorem subset_closure : S ⊆ closure S :=
fun _ ↦ mem_closure
theorem closure_subset {T : Set F} (hT : IsSubfield T) (H : S ⊆ T) : closure S ⊆ T := by
rintro _ ⟨p, hp, q, hq, hq0, rfl⟩
exact hT.div_mem (Ring.closure_subset hT.toIsSubring H hp)
(Ring.closure_subset hT.toIsSubring H hq)
theorem closure_subset_iff {s t : Set F} (ht : IsSubfield t) : closure s ⊆ t ↔ s ⊆ t :=
⟨Set.Subset.trans subset_closure, closure_subset ht⟩
theorem closure_mono {s t : Set F} (H : s ⊆ t) : closure s ⊆ closure t :=
closure_subset closure.isSubfield <| Set.Subset.trans H subset_closure
end Field
theorem isSubfield_iUnion_of_directed {ι : Type*} [Nonempty ι] {s : ι → Set F}
(hs : ∀ i, IsSubfield (s i)) (directed : ∀ i j, ∃ k, s i ⊆ s k ∧ s j ⊆ s k) :
IsSubfield (⋃ i, s i) :=
{ inv_mem := fun hx ↦
let ⟨i, hi⟩ := Set.mem_iUnion.1 hx
Set.mem_iUnion.2 ⟨i, (hs i).inv_mem hi⟩
toIsSubring := isSubring_iUnion_of_directed (fun i ↦ (hs i).toIsSubring) directed }
theorem IsSubfield.inter {S₁ S₂ : Set F} (hS₁ : IsSubfield S₁) (hS₂ : IsSubfield S₂) :
IsSubfield (S₁ ∩ S₂) :=
{ IsSubring.inter hS₁.toIsSubring hS₂.toIsSubring with
inv_mem := fun hx ↦ ⟨hS₁.inv_mem hx.1, hS₂.inv_mem hx.2⟩ }
theorem IsSubfield.iInter {ι : Sort*} {S : ι → Set F} (h : ∀ y : ι, IsSubfield (S y)) :
IsSubfield (Set.iInter S) :=
{ IsSubring.iInter fun y ↦ (h y).toIsSubring with
inv_mem := fun hx ↦ Set.mem_iInter.2 fun y ↦ (h y).inv_mem <| Set.mem_iInter.1 hx y }
|
Deprecated\Subgroup.lean | /-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mitchell Rowett, Scott Morrison, Johan Commelin, Mario Carneiro,
Michael Howes
-/
import Mathlib.Algebra.Group.Subgroup.Basic
import Mathlib.Deprecated.Submonoid
/-!
# Unbundled subgroups (deprecated)
This file is deprecated, and is no longer imported by anything in mathlib other than other
deprecated files, and test files. You should not need to import it.
This file defines unbundled multiplicative and additive subgroups. Instead of using this file,
please use `Subgroup G` and `AddSubgroup A`, defined in `Mathlib.Algebra.Group.Subgroup.Basic`.
## Main definitions
`IsAddSubgroup (S : Set A)` : the predicate that `S` is the underlying subset of an additive
subgroup of `A`. The bundled variant `AddSubgroup A` should be used in preference to this.
`IsSubgroup (S : Set G)` : the predicate that `S` is the underlying subset of a subgroup
of `G`. The bundled variant `Subgroup G` should be used in preference to this.
## Tags
subgroup, subgroups, IsSubgroup
-/
open Set Function
variable {G : Type*} {H : Type*} {A : Type*} {a a₁ a₂ b c : G}
section Group
variable [Group G] [AddGroup A]
/-- `s` is an additive subgroup: a set containing 0 and closed under addition and negation. -/
structure IsAddSubgroup (s : Set A) extends IsAddSubmonoid s : Prop where
/-- The proposition that `s` is closed under negation. -/
neg_mem {a} : a ∈ s → -a ∈ s
/-- `s` is a subgroup: a set containing 1 and closed under multiplication and inverse. -/
@[to_additive]
structure IsSubgroup (s : Set G) extends IsSubmonoid s : Prop where
/-- The proposition that `s` is closed under inverse. -/
inv_mem {a} : a ∈ s → a⁻¹ ∈ s
@[to_additive]
theorem IsSubgroup.div_mem {s : Set G} (hs : IsSubgroup s) {x y : G} (hx : x ∈ s) (hy : y ∈ s) :
x / y ∈ s := by simpa only [div_eq_mul_inv] using hs.mul_mem hx (hs.inv_mem hy)
theorem Additive.isAddSubgroup {s : Set G} (hs : IsSubgroup s) : @IsAddSubgroup (Additive G) _ s :=
@IsAddSubgroup.mk (Additive G) _ _ (Additive.isAddSubmonoid hs.toIsSubmonoid) hs.inv_mem
theorem Additive.isAddSubgroup_iff {s : Set G} : @IsAddSubgroup (Additive G) _ s ↔ IsSubgroup s :=
⟨by rintro ⟨⟨h₁, h₂⟩, h₃⟩; exact @IsSubgroup.mk G _ _ ⟨h₁, @h₂⟩ @h₃, fun h =>
Additive.isAddSubgroup h⟩
theorem Multiplicative.isSubgroup {s : Set A} (hs : IsAddSubgroup s) :
@IsSubgroup (Multiplicative A) _ s :=
@IsSubgroup.mk (Multiplicative A) _ _ (Multiplicative.isSubmonoid hs.toIsAddSubmonoid) hs.neg_mem
theorem Multiplicative.isSubgroup_iff {s : Set A} :
@IsSubgroup (Multiplicative A) _ s ↔ IsAddSubgroup s :=
⟨by rintro ⟨⟨h₁, h₂⟩, h₃⟩; exact @IsAddSubgroup.mk A _ _ ⟨h₁, @h₂⟩ @h₃, fun h =>
Multiplicative.isSubgroup h⟩
@[to_additive of_add_neg]
theorem IsSubgroup.of_div (s : Set G) (one_mem : (1 : G) ∈ s)
(div_mem : ∀ {a b : G}, a ∈ s → b ∈ s → a * b⁻¹ ∈ s) : IsSubgroup s :=
have inv_mem : ∀ a, a ∈ s → a⁻¹ ∈ s := fun a ha => by
have : 1 * a⁻¹ ∈ s := div_mem one_mem ha
convert this using 1
rw [one_mul]
{ inv_mem := inv_mem _
mul_mem := fun {a b} ha hb => by
have : a * b⁻¹⁻¹ ∈ s := div_mem ha (inv_mem b hb)
convert this
rw [inv_inv]
one_mem }
theorem IsAddSubgroup.of_sub (s : Set A) (zero_mem : (0 : A) ∈ s)
(sub_mem : ∀ {a b : A}, a ∈ s → b ∈ s → a - b ∈ s) : IsAddSubgroup s :=
IsAddSubgroup.of_add_neg s zero_mem fun {x y} hx hy => by
simpa only [sub_eq_add_neg] using sub_mem hx hy
@[to_additive]
theorem IsSubgroup.inter {s₁ s₂ : Set G} (hs₁ : IsSubgroup s₁) (hs₂ : IsSubgroup s₂) :
IsSubgroup (s₁ ∩ s₂) :=
{ IsSubmonoid.inter hs₁.toIsSubmonoid hs₂.toIsSubmonoid with
inv_mem := fun hx => ⟨hs₁.inv_mem hx.1, hs₂.inv_mem hx.2⟩ }
@[to_additive]
theorem IsSubgroup.iInter {ι : Sort*} {s : ι → Set G} (hs : ∀ y : ι, IsSubgroup (s y)) :
IsSubgroup (Set.iInter s) :=
{ IsSubmonoid.iInter fun y => (hs y).toIsSubmonoid with
inv_mem := fun h =>
Set.mem_iInter.2 fun y => IsSubgroup.inv_mem (hs _) (Set.mem_iInter.1 h y) }
@[to_additive]
theorem isSubgroup_iUnion_of_directed {ι : Type*} [Nonempty ι] {s : ι → Set G}
(hs : ∀ i, IsSubgroup (s i)) (directed : ∀ i j, ∃ k, s i ⊆ s k ∧ s j ⊆ s k) :
IsSubgroup (⋃ i, s i) :=
{ inv_mem := fun ha =>
let ⟨i, hi⟩ := Set.mem_iUnion.1 ha
Set.mem_iUnion.2 ⟨i, (hs i).inv_mem hi⟩
toIsSubmonoid := isSubmonoid_iUnion_of_directed (fun i => (hs i).toIsSubmonoid) directed }
end Group
namespace IsSubgroup
open IsSubmonoid
variable [Group G] {s : Set G} (hs : IsSubgroup s)
@[to_additive]
theorem inv_mem_iff : a⁻¹ ∈ s ↔ a ∈ s :=
⟨fun h => by simpa using hs.inv_mem h, inv_mem hs⟩
@[to_additive]
theorem mul_mem_cancel_right (h : a ∈ s) : b * a ∈ s ↔ b ∈ s :=
⟨fun hba => by simpa using hs.mul_mem hba (hs.inv_mem h), fun hb => hs.mul_mem hb h⟩
@[to_additive]
theorem mul_mem_cancel_left (h : a ∈ s) : a * b ∈ s ↔ b ∈ s :=
⟨fun hab => by simpa using hs.mul_mem (hs.inv_mem h) hab, hs.mul_mem h⟩
end IsSubgroup
/-- `IsNormalAddSubgroup (s : Set A)` expresses the fact that `s` is a normal additive subgroup
of the additive group `A`. Important: the preferred way to say this in Lean is via bundled
subgroups `S : AddSubgroup A` and `hs : S.normal`, and not via this structure. -/
structure IsNormalAddSubgroup [AddGroup A] (s : Set A) extends IsAddSubgroup s : Prop where
/-- The proposition that `s` is closed under (additive) conjugation. -/
normal : ∀ n ∈ s, ∀ g : A, g + n + -g ∈ s
/-- `IsNormalSubgroup (s : Set G)` expresses the fact that `s` is a normal subgroup
of the group `G`. Important: the preferred way to say this in Lean is via bundled
subgroups `S : Subgroup G` and not via this structure. -/
@[to_additive]
structure IsNormalSubgroup [Group G] (s : Set G) extends IsSubgroup s : Prop where
/-- The proposition that `s` is closed under conjugation. -/
normal : ∀ n ∈ s, ∀ g : G, g * n * g⁻¹ ∈ s
@[to_additive]
theorem isNormalSubgroup_of_commGroup [CommGroup G] {s : Set G} (hs : IsSubgroup s) :
IsNormalSubgroup s :=
{ hs with normal := fun n hn g => by rwa [mul_right_comm, mul_right_inv, one_mul] }
theorem Additive.isNormalAddSubgroup [Group G] {s : Set G} (hs : IsNormalSubgroup s) :
@IsNormalAddSubgroup (Additive G) _ s :=
@IsNormalAddSubgroup.mk (Additive G) _ _ (Additive.isAddSubgroup hs.toIsSubgroup)
(@IsNormalSubgroup.normal _ ‹Group (Additive G)› _ hs)
-- Porting note: Lean needs help synthesising
theorem Additive.isNormalAddSubgroup_iff [Group G] {s : Set G} :
@IsNormalAddSubgroup (Additive G) _ s ↔ IsNormalSubgroup s :=
⟨by rintro ⟨h₁, h₂⟩; exact @IsNormalSubgroup.mk G _ _ (Additive.isAddSubgroup_iff.1 h₁) @h₂,
fun h => Additive.isNormalAddSubgroup h⟩
theorem Multiplicative.isNormalSubgroup [AddGroup A] {s : Set A} (hs : IsNormalAddSubgroup s) :
@IsNormalSubgroup (Multiplicative A) _ s :=
@IsNormalSubgroup.mk (Multiplicative A) _ _ (Multiplicative.isSubgroup hs.toIsAddSubgroup)
(@IsNormalAddSubgroup.normal _ ‹AddGroup (Multiplicative A)› _ hs)
theorem Multiplicative.isNormalSubgroup_iff [AddGroup A] {s : Set A} :
@IsNormalSubgroup (Multiplicative A) _ s ↔ IsNormalAddSubgroup s :=
⟨by
rintro ⟨h₁, h₂⟩
exact @IsNormalAddSubgroup.mk A _ _ (Multiplicative.isSubgroup_iff.1 h₁) @h₂,
fun h => Multiplicative.isNormalSubgroup h⟩
namespace IsSubgroup
variable [Group G]
-- Normal subgroup properties
@[to_additive]
theorem mem_norm_comm {s : Set G} (hs : IsNormalSubgroup s) {a b : G} (hab : a * b ∈ s) :
b * a ∈ s := by
simpa using (hs.normal (a * b) hab a⁻¹)
@[to_additive]
theorem mem_norm_comm_iff {s : Set G} (hs : IsNormalSubgroup s) {a b : G} : a * b ∈ s ↔ b * a ∈ s :=
⟨mem_norm_comm hs, mem_norm_comm hs⟩
/-- The trivial subgroup -/
@[to_additive "the trivial additive subgroup"]
def trivial (G : Type*) [Group G] : Set G :=
{1}
@[to_additive (attr := simp)]
theorem mem_trivial {g : G} : g ∈ trivial G ↔ g = 1 :=
mem_singleton_iff
@[to_additive]
theorem trivial_normal : IsNormalSubgroup (trivial G) := by refine ⟨⟨⟨?_, ?_⟩, ?_⟩, ?_⟩ <;> simp
@[to_additive]
theorem eq_trivial_iff {s : Set G} (hs : IsSubgroup s) : s = trivial G ↔ ∀ x ∈ s, x = (1 : G) := by
simp only [Set.ext_iff, IsSubgroup.mem_trivial]
exact ⟨fun h x => (h x).1, fun h x => ⟨h x, fun hx => hx.symm ▸ hs.toIsSubmonoid.one_mem⟩⟩
@[to_additive]
theorem univ_subgroup : IsNormalSubgroup (@univ G) := by refine ⟨⟨⟨?_, ?_⟩, ?_⟩, ?_⟩ <;> simp
/-- The underlying set of the center of a group. -/
@[to_additive addCenter "The underlying set of the center of an additive group."]
def center (G : Type*) [Group G] : Set G :=
{ z | ∀ g, g * z = z * g }
@[to_additive mem_add_center]
theorem mem_center {a : G} : a ∈ center G ↔ ∀ g, g * a = a * g :=
Iff.rfl
@[to_additive add_center_normal]
theorem center_normal : IsNormalSubgroup (center G) :=
{ one_mem := by simp [center]
mul_mem := fun ha hb g => by
rw [← mul_assoc, mem_center.2 ha g, mul_assoc, mem_center.2 hb g, ← mul_assoc]
inv_mem := fun {a} ha g =>
calc
g * a⁻¹ = a⁻¹ * (g * a) * a⁻¹ := by simp [ha g]
_ = a⁻¹ * g := by rw [← mul_assoc, mul_assoc]; simp
normal := fun n ha g h =>
calc
h * (g * n * g⁻¹) = h * n := by simp [ha g, mul_assoc]
_ = g * g⁻¹ * n * h := by rw [ha h]; simp
_ = g * n * g⁻¹ * h := by rw [mul_assoc g, ha g⁻¹, ← mul_assoc]
}
/-- The underlying set of the normalizer of a subset `S : Set G` of a group `G`. That is,
the elements `g : G` such that `g * S * g⁻¹ = S`. -/
@[to_additive addNormalizer
"The underlying set of the normalizer of a subset `S : Set A` of an
additive group `A`. That is, the elements `a : A` such that `a + S - a = S`."]
def normalizer (s : Set G) : Set G :=
{ g : G | ∀ n, n ∈ s ↔ g * n * g⁻¹ ∈ s }
@[to_additive]
theorem normalizer_isSubgroup (s : Set G) : IsSubgroup (normalizer s) :=
{ one_mem := by simp [normalizer]
mul_mem := fun {a b}
(ha : ∀ n, n ∈ s ↔ a * n * a⁻¹ ∈ s) (hb : ∀ n, n ∈ s ↔ b * n * b⁻¹ ∈ s) n =>
by rw [mul_inv_rev, ← mul_assoc, mul_assoc a, mul_assoc a, ← ha, ← hb]
inv_mem := fun {a} (ha : ∀ n, n ∈ s ↔ a * n * a⁻¹ ∈ s) n => by
rw [ha (a⁻¹ * n * a⁻¹⁻¹)]; simp [mul_assoc] }
@[to_additive subset_add_normalizer]
theorem subset_normalizer {s : Set G} (hs : IsSubgroup s) : s ⊆ normalizer s := fun g hg n => by
rw [IsSubgroup.mul_mem_cancel_right hs ((IsSubgroup.inv_mem_iff hs).2 hg),
IsSubgroup.mul_mem_cancel_left hs hg]
end IsSubgroup
-- Homomorphism subgroups
namespace IsGroupHom
open IsSubmonoid IsSubgroup
/-- `ker f : Set G` is the underlying subset of the kernel of a map `G → H`. -/
@[to_additive "`ker f : Set A` is the underlying subset of the kernel of a map `A → B`"]
def ker [Group H] (f : G → H) : Set G :=
preimage f (trivial H)
@[to_additive]
theorem mem_ker [Group H] (f : G → H) {x : G} : x ∈ ker f ↔ f x = 1 :=
mem_trivial
variable [Group G] [Group H]
@[to_additive]
theorem one_ker_inv {f : G → H} (hf : IsGroupHom f) {a b : G} (h : f (a * b⁻¹) = 1) :
f a = f b := by
rw [hf.map_mul, hf.map_inv] at h
rw [← inv_inv (f b), eq_inv_of_mul_eq_one_left h]
@[to_additive]
theorem one_ker_inv' {f : G → H} (hf : IsGroupHom f) {a b : G} (h : f (a⁻¹ * b) = 1) :
f a = f b := by
rw [hf.map_mul, hf.map_inv] at h
apply inv_injective
rw [eq_inv_of_mul_eq_one_left h]
@[to_additive]
theorem inv_ker_one {f : G → H} (hf : IsGroupHom f) {a b : G} (h : f a = f b) :
f (a * b⁻¹) = 1 := by
have : f a * (f b)⁻¹ = 1 := by rw [h, mul_right_inv]
rwa [← hf.map_inv, ← hf.map_mul] at this
@[to_additive]
theorem inv_ker_one' {f : G → H} (hf : IsGroupHom f) {a b : G} (h : f a = f b) :
f (a⁻¹ * b) = 1 := by
have : (f a)⁻¹ * f b = 1 := by rw [h, mul_left_inv]
rwa [← hf.map_inv, ← hf.map_mul] at this
@[to_additive]
theorem one_iff_ker_inv {f : G → H} (hf : IsGroupHom f) (a b : G) : f a = f b ↔ f (a * b⁻¹) = 1 :=
⟨hf.inv_ker_one, hf.one_ker_inv⟩
@[to_additive]
theorem one_iff_ker_inv' {f : G → H} (hf : IsGroupHom f) (a b : G) : f a = f b ↔ f (a⁻¹ * b) = 1 :=
⟨hf.inv_ker_one', hf.one_ker_inv'⟩
@[to_additive]
theorem inv_iff_ker {f : G → H} (hf : IsGroupHom f) (a b : G) : f a = f b ↔ a * b⁻¹ ∈ ker f := by
rw [mem_ker]; exact one_iff_ker_inv hf _ _
@[to_additive]
theorem inv_iff_ker' {f : G → H} (hf : IsGroupHom f) (a b : G) : f a = f b ↔ a⁻¹ * b ∈ ker f := by
rw [mem_ker]; exact one_iff_ker_inv' hf _ _
@[to_additive]
theorem image_subgroup {f : G → H} (hf : IsGroupHom f) {s : Set G} (hs : IsSubgroup s) :
IsSubgroup (f '' s) :=
{ mul_mem := fun {a₁ a₂} ⟨b₁, hb₁, eq₁⟩ ⟨b₂, hb₂, eq₂⟩ =>
⟨b₁ * b₂, hs.mul_mem hb₁ hb₂, by simp [eq₁, eq₂, hf.map_mul]⟩
one_mem := ⟨1, hs.toIsSubmonoid.one_mem, hf.map_one⟩
inv_mem := fun {a} ⟨b, hb, Eq⟩ =>
⟨b⁻¹, hs.inv_mem hb, by
rw [hf.map_inv]
simp [*]⟩ }
@[to_additive]
theorem range_subgroup {f : G → H} (hf : IsGroupHom f) : IsSubgroup (Set.range f) :=
@Set.image_univ _ _ f ▸ hf.image_subgroup univ_subgroup.toIsSubgroup
attribute [local simp] IsSubmonoid.one_mem IsSubgroup.inv_mem
IsSubmonoid.mul_mem IsNormalSubgroup.normal
@[to_additive]
theorem preimage {f : G → H} (hf : IsGroupHom f) {s : Set H} (hs : IsSubgroup s) :
IsSubgroup (f ⁻¹' s) where
one_mem := by simp [hf.map_one, hs.one_mem]
mul_mem := by simp_all [hf.map_mul, hs.mul_mem]
inv_mem := by simp_all [hf.map_inv]
@[to_additive]
theorem preimage_normal {f : G → H} (hf : IsGroupHom f) {s : Set H} (hs : IsNormalSubgroup s) :
IsNormalSubgroup (f ⁻¹' s) :=
{ one_mem := by simp [hf.map_one, hs.toIsSubgroup.one_mem]
mul_mem := by simp (config := { contextual := true }) [hf.map_mul, hs.toIsSubgroup.mul_mem]
inv_mem := by simp (config := { contextual := true }) [hf.map_inv, hs.toIsSubgroup.inv_mem]
normal := by simp (config := { contextual := true }) [hs.normal, hf.map_mul, hf.map_inv] }
@[to_additive]
theorem isNormalSubgroup_ker {f : G → H} (hf : IsGroupHom f) : IsNormalSubgroup (ker f) :=
hf.preimage_normal trivial_normal
@[to_additive]
theorem injective_of_trivial_ker {f : G → H} (hf : IsGroupHom f) (h : ker f = trivial G) :
Function.Injective f := by
intro a₁ a₂ hfa
simp [Set.ext_iff, ker, IsSubgroup.trivial] at h
have ha : a₁ * a₂⁻¹ = 1 := by rw [← h]; exact hf.inv_ker_one hfa
rw [eq_inv_of_mul_eq_one_left ha, inv_inv a₂]
@[to_additive]
theorem trivial_ker_of_injective {f : G → H} (hf : IsGroupHom f) (h : Function.Injective f) :
ker f = trivial G :=
Set.ext fun x =>
Iff.intro
(fun hx => by
suffices f x = f 1 by simpa using h this
simp [hf.map_one]; rwa [mem_ker] at hx)
(by simp (config := { contextual := true }) [mem_ker, hf.map_one])
@[to_additive]
theorem injective_iff_trivial_ker {f : G → H} (hf : IsGroupHom f) :
Function.Injective f ↔ ker f = trivial G :=
⟨hf.trivial_ker_of_injective, hf.injective_of_trivial_ker⟩
@[to_additive]
theorem trivial_ker_iff_eq_one {f : G → H} (hf : IsGroupHom f) :
ker f = trivial G ↔ ∀ x, f x = 1 → x = 1 := by
rw [Set.ext_iff]
simpa [ker] using ⟨fun h x hx => (h x).1 hx, fun h x => ⟨h x, fun hx => by rw [hx, hf.map_one]⟩⟩
end IsGroupHom
namespace AddGroup
variable [AddGroup A]
/-- If `A` is an additive group and `s : Set A`, then `InClosure s : Set A` is the underlying
subset of the subgroup generated by `s`. -/
inductive InClosure (s : Set A) : A → Prop
| basic {a : A} : a ∈ s → InClosure s a
| zero : InClosure s 0
| neg {a : A} : InClosure s a → InClosure s (-a)
| add {a b : A} : InClosure s a → InClosure s b → InClosure s (a + b)
end AddGroup
namespace Group
open IsSubmonoid IsSubgroup
variable [Group G] {s : Set G}
/-- If `G` is a group and `s : Set G`, then `InClosure s : Set G` is the underlying
subset of the subgroup generated by `s`. -/
@[to_additive]
inductive InClosure (s : Set G) : G → Prop
| basic {a : G} : a ∈ s → InClosure s a
| one : InClosure s 1
| inv {a : G} : InClosure s a → InClosure s a⁻¹
| mul {a b : G} : InClosure s a → InClosure s b → InClosure s (a * b)
/-- `Group.closure s` is the subgroup generated by `s`, i.e. the smallest subgroup containing `s`.
-/
@[to_additive
"`AddGroup.closure s` is the additive subgroup generated by `s`, i.e., the
smallest additive subgroup containing `s`."]
def closure (s : Set G) : Set G :=
{ a | InClosure s a }
@[to_additive]
theorem mem_closure {a : G} : a ∈ s → a ∈ closure s :=
InClosure.basic
@[to_additive]
theorem closure.isSubgroup (s : Set G) : IsSubgroup (closure s) :=
{ one_mem := InClosure.one
mul_mem := InClosure.mul
inv_mem := InClosure.inv }
@[to_additive]
theorem subset_closure {s : Set G} : s ⊆ closure s := fun _ => mem_closure
@[to_additive]
theorem closure_subset {s t : Set G} (ht : IsSubgroup t) (h : s ⊆ t) : closure s ⊆ t := fun a ha =>
by induction ha <;> simp [h _, *, ht.one_mem, ht.mul_mem, IsSubgroup.inv_mem_iff]
@[to_additive]
theorem closure_subset_iff {s t : Set G} (ht : IsSubgroup t) : closure s ⊆ t ↔ s ⊆ t :=
⟨fun h _ ha => h (mem_closure ha), fun h _ ha => closure_subset ht h ha⟩
@[to_additive]
theorem closure_mono {s t : Set G} (h : s ⊆ t) : closure s ⊆ closure t :=
closure_subset (closure.isSubgroup _) <| Set.Subset.trans h subset_closure
@[to_additive (attr := simp)]
theorem closure_subgroup {s : Set G} (hs : IsSubgroup s) : closure s = s :=
Set.Subset.antisymm (closure_subset hs <| Set.Subset.refl s) subset_closure
@[to_additive]
theorem exists_list_of_mem_closure {s : Set G} {a : G} (h : a ∈ closure s) :
∃ l : List G, (∀ x ∈ l, x ∈ s ∨ x⁻¹ ∈ s) ∧ l.prod = a :=
InClosure.recOn h (fun {x} hxs => ⟨[x], List.forall_mem_singleton.2 <| Or.inl hxs, one_mul _⟩)
⟨[], List.forall_mem_nil _, rfl⟩
(fun {x} _ ⟨L, HL1, HL2⟩ =>
⟨L.reverse.map Inv.inv, fun x hx =>
let ⟨y, hy1, hy2⟩ := List.exists_of_mem_map hx
hy2 ▸ Or.imp id (by rw [inv_inv]; exact id) (HL1 _ <| List.mem_reverse.1 hy1).symm,
HL2 ▸
List.recOn L inv_one.symm fun hd tl ih => by
rw [List.reverse_cons, List.map_append, List.prod_append, ih, List.map_singleton,
List.prod_cons, List.prod_nil, mul_one, List.prod_cons, mul_inv_rev]⟩)
fun {x y} _ _ ⟨L1, HL1, HL2⟩ ⟨L2, HL3, HL4⟩ =>
⟨L1 ++ L2, List.forall_mem_append.2 ⟨HL1, HL3⟩, by rw [List.prod_append, HL2, HL4]⟩
@[to_additive]
theorem image_closure [Group H] {f : G → H} (hf : IsGroupHom f) (s : Set G) :
f '' closure s = closure (f '' s) :=
le_antisymm
(by
rintro _ ⟨x, hx, rfl⟩
exact InClosure.recOn hx
(by intros _ ha; exact subset_closure (mem_image_of_mem f ha))
(by
rw [hf.map_one]
apply IsSubmonoid.one_mem (closure.isSubgroup _).toIsSubmonoid)
(by
intros _ _
rw [hf.map_inv]
apply IsSubgroup.inv_mem (closure.isSubgroup _))
(by
intros _ _ _ _ ha hb
rw [hf.map_mul]
exact (closure.isSubgroup (f '' s)).toIsSubmonoid.mul_mem ha hb))
(closure_subset (hf.image_subgroup <| closure.isSubgroup _) <|
Set.image_subset _ subset_closure)
@[to_additive]
theorem mclosure_subset {s : Set G} : Monoid.Closure s ⊆ closure s :=
Monoid.closure_subset (closure.isSubgroup _).toIsSubmonoid <| subset_closure
@[to_additive]
theorem mclosure_inv_subset {s : Set G} : Monoid.Closure (Inv.inv ⁻¹' s) ⊆ closure s :=
Monoid.closure_subset (closure.isSubgroup _).toIsSubmonoid fun x hx =>
inv_inv x ▸ ((closure.isSubgroup _).inv_mem <| subset_closure hx)
@[to_additive]
theorem closure_eq_mclosure {s : Set G} : closure s = Monoid.Closure (s ∪ Inv.inv ⁻¹' s) :=
Set.Subset.antisymm
(@closure_subset _ _ _ (Monoid.Closure (s ∪ Inv.inv ⁻¹' s))
{ one_mem := (Monoid.closure.isSubmonoid _).one_mem
mul_mem := (Monoid.closure.isSubmonoid _).mul_mem
inv_mem := fun hx =>
Monoid.InClosure.recOn hx
(fun {x} hx =>
Or.casesOn hx
(fun hx =>
Monoid.subset_closure <| Or.inr <| show x⁻¹⁻¹ ∈ s from (inv_inv x).symm ▸ hx)
fun hx => Monoid.subset_closure <| Or.inl hx)
((@inv_one G _).symm ▸ IsSubmonoid.one_mem (Monoid.closure.isSubmonoid _))
fun {x y} _ _ ihx ihy =>
(mul_inv_rev x y).symm ▸ IsSubmonoid.mul_mem (Monoid.closure.isSubmonoid _) ihy ihx }
(Set.Subset.trans Set.subset_union_left Monoid.subset_closure))
(Monoid.closure_subset (closure.isSubgroup _).toIsSubmonoid <|
Set.union_subset subset_closure fun x hx =>
inv_inv x ▸ (IsSubgroup.inv_mem (closure.isSubgroup _) <| subset_closure hx))
@[to_additive]
theorem mem_closure_union_iff {G : Type*} [CommGroup G] {s t : Set G} {x : G} :
x ∈ closure (s ∪ t) ↔ ∃ y ∈ closure s, ∃ z ∈ closure t, y * z = x := by
simp only [closure_eq_mclosure, Monoid.mem_closure_union_iff, exists_prop, preimage_union]
constructor
· rintro ⟨_, ⟨ys, hys, yt, hyt, rfl⟩, _, ⟨zs, hzs, zt, hzt, rfl⟩, rfl⟩
refine ⟨_, ⟨_, hys, _, hzs, rfl⟩, _, ⟨_, hyt, _, hzt, rfl⟩, ?_⟩
rw [mul_assoc, mul_assoc, mul_left_comm zs]
· rintro ⟨_, ⟨ys, hys, zs, hzs, rfl⟩, _, ⟨yt, hyt, zt, hzt, rfl⟩, rfl⟩
refine ⟨_, ⟨ys, hys, yt, hyt, rfl⟩, _, ⟨zs, hzs, zt, hzt, rfl⟩, ?_⟩
rw [mul_assoc, mul_assoc, mul_left_comm yt]
end Group
namespace IsSubgroup
variable [Group G]
@[to_additive]
theorem trivial_eq_closure : trivial G = Group.closure ∅ :=
Subset.antisymm (by simp [Set.subset_def, (Group.closure.isSubgroup _).one_mem])
(Group.closure_subset trivial_normal.toIsSubgroup <| by simp)
end IsSubgroup
/- The normal closure of a set s is the subgroup closure of all the conjugates of
elements of s. It is the smallest normal subgroup containing s. -/
namespace Group
variable {s : Set G} [Group G]
theorem conjugatesOf_subset {t : Set G} (ht : IsNormalSubgroup t) {a : G} (h : a ∈ t) :
conjugatesOf a ⊆ t := fun x hc => by
obtain ⟨c, w⟩ := isConj_iff.1 hc
have H := IsNormalSubgroup.normal ht a h c
rwa [← w]
theorem conjugatesOfSet_subset' {s t : Set G} (ht : IsNormalSubgroup t) (h : s ⊆ t) :
conjugatesOfSet s ⊆ t :=
Set.iUnion₂_subset fun _ H => conjugatesOf_subset ht (h H)
/-- The normal closure of a set s is the subgroup closure of all the conjugates of
elements of s. It is the smallest normal subgroup containing s. -/
def normalClosure (s : Set G) : Set G :=
closure (conjugatesOfSet s)
theorem conjugatesOfSet_subset_normalClosure : conjugatesOfSet s ⊆ normalClosure s :=
subset_closure
theorem subset_normalClosure : s ⊆ normalClosure s :=
Set.Subset.trans subset_conjugatesOfSet conjugatesOfSet_subset_normalClosure
/-- The normal closure of a set is a subgroup. -/
theorem normalClosure.isSubgroup (s : Set G) : IsSubgroup (normalClosure s) :=
closure.isSubgroup (conjugatesOfSet s)
/-- The normal closure of s is a normal subgroup. -/
theorem normalClosure.is_normal : IsNormalSubgroup (normalClosure s) :=
{ normalClosure.isSubgroup _ with
normal := fun n h g => by
induction' h with x hx x hx ihx x y hx hy ihx ihy
· exact conjugatesOfSet_subset_normalClosure (conj_mem_conjugatesOfSet hx)
· simpa using (normalClosure.isSubgroup s).one_mem
· rw [← conj_inv]
exact (normalClosure.isSubgroup _).inv_mem ihx
· rw [← conj_mul]
exact (normalClosure.isSubgroup _).toIsSubmonoid.mul_mem ihx ihy }
/-- The normal closure of s is the smallest normal subgroup containing s. -/
theorem normalClosure_subset {s t : Set G} (ht : IsNormalSubgroup t) (h : s ⊆ t) :
normalClosure s ⊆ t := fun a w => by
induction' w with x hx x _ ihx x y _ _ ihx ihy
· exact conjugatesOfSet_subset' ht h <| hx
· exact ht.toIsSubgroup.toIsSubmonoid.one_mem
· exact ht.toIsSubgroup.inv_mem ihx
· exact ht.toIsSubgroup.toIsSubmonoid.mul_mem ihx ihy
theorem normalClosure_subset_iff {s t : Set G} (ht : IsNormalSubgroup t) :
s ⊆ t ↔ normalClosure s ⊆ t :=
⟨normalClosure_subset ht, Set.Subset.trans subset_normalClosure⟩
theorem normalClosure_mono {s t : Set G} : s ⊆ t → normalClosure s ⊆ normalClosure t := fun h =>
normalClosure_subset normalClosure.is_normal (Set.Subset.trans h subset_normalClosure)
end Group
/-- Create a bundled subgroup from a set `s` and `[IsSubgroup s]`. -/
@[to_additive "Create a bundled additive subgroup from a set `s` and `[IsAddSubgroup s]`."]
def Subgroup.of [Group G] {s : Set G} (h : IsSubgroup s) : Subgroup G where
carrier := s
one_mem' := h.1.1
mul_mem' := h.1.2
inv_mem' := h.2
@[to_additive]
theorem Subgroup.isSubgroup [Group G] (K : Subgroup G) : IsSubgroup (K : Set G) :=
{ one_mem := K.one_mem'
mul_mem := K.mul_mem'
inv_mem := K.inv_mem' }
-- this will never fire if it's an instance
@[to_additive]
theorem Subgroup.of_normal [Group G] (s : Set G) (h : IsSubgroup s) (n : IsNormalSubgroup s) :
Subgroup.Normal (Subgroup.of h) :=
{ conj_mem := n.normal }
|
Deprecated\Submonoid.lean | /-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Kenny Lau, Johan Commelin, Mario Carneiro, Kevin Buzzard
-/
import Mathlib.Algebra.BigOperators.Group.Finset
import Mathlib.Algebra.Group.Submonoid.Basic
import Mathlib.Deprecated.Group
/-!
# Unbundled submonoids (deprecated)
This file is deprecated, and is no longer imported by anything in mathlib other than other
deprecated files, and test files. You should not need to import it.
This file defines unbundled multiplicative and additive submonoids. Instead of using this file,
please use `Submonoid G` and `AddSubmonoid A`, defined in `GroupTheory.Submonoid.Basic`.
## Main definitions
`IsAddSubmonoid (S : Set M)` : the predicate that `S` is the underlying subset of an additive
submonoid of `M`. The bundled variant `AddSubmonoid M` should be used in preference to this.
`IsSubmonoid (S : Set M)` : the predicate that `S` is the underlying subset of a submonoid
of `M`. The bundled variant `Submonoid M` should be used in preference to this.
## Tags
Submonoid, Submonoids, IsSubmonoid
-/
variable {M : Type*} [Monoid M] {s : Set M}
variable {A : Type*} [AddMonoid A] {t : Set A}
/-- `s` is an additive submonoid: a set containing 0 and closed under addition.
Note that this structure is deprecated, and the bundled variant `AddSubmonoid A` should be
preferred. -/
structure IsAddSubmonoid (s : Set A) : Prop where
/-- The proposition that s contains 0. -/
zero_mem : (0 : A) ∈ s
/-- The proposition that s is closed under addition. -/
add_mem {a b} : a ∈ s → b ∈ s → a + b ∈ s
/-- `s` is a submonoid: a set containing 1 and closed under multiplication.
Note that this structure is deprecated, and the bundled variant `Submonoid M` should be
preferred. -/
@[to_additive]
structure IsSubmonoid (s : Set M) : Prop where
/-- The proposition that s contains 1. -/
one_mem : (1 : M) ∈ s
/-- The proposition that s is closed under multiplication. -/
mul_mem {a b} : a ∈ s → b ∈ s → a * b ∈ s
theorem Additive.isAddSubmonoid {s : Set M} :
IsSubmonoid s → @IsAddSubmonoid (Additive M) _ s
| ⟨h₁, h₂⟩ => ⟨h₁, @h₂⟩
theorem Additive.isAddSubmonoid_iff {s : Set M} :
@IsAddSubmonoid (Additive M) _ s ↔ IsSubmonoid s :=
⟨fun ⟨h₁, h₂⟩ => ⟨h₁, @h₂⟩, Additive.isAddSubmonoid⟩
theorem Multiplicative.isSubmonoid {s : Set A} :
IsAddSubmonoid s → @IsSubmonoid (Multiplicative A) _ s
| ⟨h₁, h₂⟩ => ⟨h₁, @h₂⟩
theorem Multiplicative.isSubmonoid_iff {s : Set A} :
@IsSubmonoid (Multiplicative A) _ s ↔ IsAddSubmonoid s :=
⟨fun ⟨h₁, h₂⟩ => ⟨h₁, @h₂⟩, Multiplicative.isSubmonoid⟩
/-- The intersection of two submonoids of a monoid `M` is a submonoid of `M`. -/
@[to_additive
"The intersection of two `AddSubmonoid`s of an `AddMonoid` `M` is an `AddSubmonoid` of M."]
theorem IsSubmonoid.inter {s₁ s₂ : Set M} (is₁ : IsSubmonoid s₁) (is₂ : IsSubmonoid s₂) :
IsSubmonoid (s₁ ∩ s₂) :=
{ one_mem := ⟨is₁.one_mem, is₂.one_mem⟩
mul_mem := @fun _ _ hx hy => ⟨is₁.mul_mem hx.1 hy.1, is₂.mul_mem hx.2 hy.2⟩ }
/-- The intersection of an indexed set of submonoids of a monoid `M` is a submonoid of `M`. -/
@[to_additive
"The intersection of an indexed set of `AddSubmonoid`s of an `AddMonoid` `M` is
an `AddSubmonoid` of `M`."]
theorem IsSubmonoid.iInter {ι : Sort*} {s : ι → Set M} (h : ∀ y : ι, IsSubmonoid (s y)) :
IsSubmonoid (Set.iInter s) :=
{ one_mem := Set.mem_iInter.2 fun y => (h y).one_mem
mul_mem := fun h₁ h₂ =>
Set.mem_iInter.2 fun y => (h y).mul_mem (Set.mem_iInter.1 h₁ y) (Set.mem_iInter.1 h₂ y) }
/-- The union of an indexed, directed, nonempty set of submonoids of a monoid `M` is a submonoid
of `M`. -/
@[to_additive
"The union of an indexed, directed, nonempty set of `AddSubmonoid`s of an `AddMonoid` `M`
is an `AddSubmonoid` of `M`. "]
theorem isSubmonoid_iUnion_of_directed {ι : Type*} [hι : Nonempty ι] {s : ι → Set M}
(hs : ∀ i, IsSubmonoid (s i)) (Directed : ∀ i j, ∃ k, s i ⊆ s k ∧ s j ⊆ s k) :
IsSubmonoid (⋃ i, s i) :=
{ one_mem :=
let ⟨i⟩ := hι
Set.mem_iUnion.2 ⟨i, (hs i).one_mem⟩
mul_mem := fun ha hb =>
let ⟨i, hi⟩ := Set.mem_iUnion.1 ha
let ⟨j, hj⟩ := Set.mem_iUnion.1 hb
let ⟨k, hk⟩ := Directed i j
Set.mem_iUnion.2 ⟨k, (hs k).mul_mem (hk.1 hi) (hk.2 hj)⟩ }
section powers
/-- The set of natural number powers `1, x, x², ...` of an element `x` of a monoid. -/
@[to_additive
"The set of natural number multiples `0, x, 2x, ...` of an element `x` of an `AddMonoid`."]
def powers (x : M) : Set M :=
{ y | ∃ n : ℕ, x ^ n = y }
/-- 1 is in the set of natural number powers of an element of a monoid. -/
@[to_additive "0 is in the set of natural number multiples of an element of an `AddMonoid`."]
theorem powers.one_mem {x : M} : (1 : M) ∈ powers x :=
⟨0, pow_zero _⟩
/-- An element of a monoid is in the set of that element's natural number powers. -/
@[to_additive
"An element of an `AddMonoid` is in the set of that element's natural number multiples."]
theorem powers.self_mem {x : M} : x ∈ powers x :=
⟨1, pow_one _⟩
/-- The set of natural number powers of an element of a monoid is closed under multiplication. -/
@[to_additive
"The set of natural number multiples of an element of an `AddMonoid` is closed under
addition."]
theorem powers.mul_mem {x y z : M} : y ∈ powers x → z ∈ powers x → y * z ∈ powers x :=
fun ⟨n₁, h₁⟩ ⟨n₂, h₂⟩ => ⟨n₁ + n₂, by simp only [pow_add, *]⟩
/-- The set of natural number powers of an element of a monoid `M` is a submonoid of `M`. -/
@[to_additive
"The set of natural number multiples of an element of an `AddMonoid` `M` is
an `AddSubmonoid` of `M`."]
theorem powers.isSubmonoid (x : M) : IsSubmonoid (powers x) :=
{ one_mem := powers.one_mem
mul_mem := powers.mul_mem }
/-- A monoid is a submonoid of itself. -/
@[to_additive "An `AddMonoid` is an `AddSubmonoid` of itself."]
theorem Univ.isSubmonoid : IsSubmonoid (@Set.univ M) := by constructor <;> simp
/-- The preimage of a submonoid under a monoid hom is a submonoid of the domain. -/
@[to_additive
"The preimage of an `AddSubmonoid` under an `AddMonoid` hom is
an `AddSubmonoid` of the domain."]
theorem IsSubmonoid.preimage {N : Type*} [Monoid N] {f : M → N} (hf : IsMonoidHom f) {s : Set N}
(hs : IsSubmonoid s) : IsSubmonoid (f ⁻¹' s) :=
{ one_mem := show f 1 ∈ s by (rw [IsMonoidHom.map_one hf]; exact hs.one_mem)
mul_mem := fun {a b} (ha : f a ∈ s) (hb : f b ∈ s) =>
show f (a * b) ∈ s by (rw [IsMonoidHom.map_mul' hf]; exact hs.mul_mem ha hb) }
/-- The image of a submonoid under a monoid hom is a submonoid of the codomain. -/
@[to_additive
"The image of an `AddSubmonoid` under an `AddMonoid` hom is an `AddSubmonoid` of the
codomain."]
theorem IsSubmonoid.image {γ : Type*} [Monoid γ] {f : M → γ} (hf : IsMonoidHom f) {s : Set M}
(hs : IsSubmonoid s) : IsSubmonoid (f '' s) :=
{ one_mem := ⟨1, hs.one_mem, hf.map_one⟩
mul_mem := @fun a b ⟨x, hx⟩ ⟨y, hy⟩ =>
⟨x * y, hs.mul_mem hx.1 hy.1, by rw [hf.map_mul, hx.2, hy.2]⟩ }
/-- The image of a monoid hom is a submonoid of the codomain. -/
@[to_additive "The image of an `AddMonoid` hom is an `AddSubmonoid` of the codomain."]
theorem Range.isSubmonoid {γ : Type*} [Monoid γ] {f : M → γ} (hf : IsMonoidHom f) :
IsSubmonoid (Set.range f) := by
rw [← Set.image_univ]
exact Univ.isSubmonoid.image hf
/-- Submonoids are closed under natural powers. -/
@[to_additive
"An `AddSubmonoid` is closed under multiplication by naturals."]
theorem IsSubmonoid.pow_mem {a : M} (hs : IsSubmonoid s) (h : a ∈ s) : ∀ {n : ℕ}, a ^ n ∈ s
| 0 => by
rw [pow_zero]
exact hs.one_mem
| n + 1 => by
rw [pow_succ]
exact hs.mul_mem (IsSubmonoid.pow_mem hs h) h
/-- The set of natural number powers of an element of a `Submonoid` is a subset of the
`Submonoid`. -/
@[to_additive
"The set of natural number multiples of an element of an `AddSubmonoid` is a subset of
the `AddSubmonoid`."]
theorem IsSubmonoid.powers_subset {a : M} (hs : IsSubmonoid s) (h : a ∈ s) : powers a ⊆ s :=
fun _ ⟨_, hx⟩ => hx ▸ hs.pow_mem h
@[deprecated (since := "2024-02-21")] alias IsSubmonoid.power_subset := IsSubmonoid.powers_subset
end powers
namespace IsSubmonoid
/-- The product of a list of elements of a submonoid is an element of the submonoid. -/
@[to_additive
"The sum of a list of elements of an `AddSubmonoid` is an element of the `AddSubmonoid`."]
theorem list_prod_mem (hs : IsSubmonoid s) : ∀ {l : List M}, (∀ x ∈ l, x ∈ s) → l.prod ∈ s
| [], _ => hs.one_mem
| a :: l, h =>
suffices a * l.prod ∈ s by simpa
have : a ∈ s ∧ ∀ x ∈ l, x ∈ s := by simpa using h
hs.mul_mem this.1 (list_prod_mem hs this.2)
/-- The product of a multiset of elements of a submonoid of a `CommMonoid` is an element of
the submonoid. -/
@[to_additive
"The sum of a multiset of elements of an `AddSubmonoid` of an `AddCommMonoid`
is an element of the `AddSubmonoid`. "]
theorem multiset_prod_mem {M} [CommMonoid M] {s : Set M} (hs : IsSubmonoid s) (m : Multiset M) :
(∀ a ∈ m, a ∈ s) → m.prod ∈ s := by
refine Quotient.inductionOn m fun l hl => ?_
rw [Multiset.quot_mk_to_coe, Multiset.prod_coe]
exact list_prod_mem hs hl
/-- The product of elements of a submonoid of a `CommMonoid` indexed by a `Finset` is an element
of the submonoid. -/
@[to_additive
"The sum of elements of an `AddSubmonoid` of an `AddCommMonoid` indexed by
a `Finset` is an element of the `AddSubmonoid`."]
theorem finset_prod_mem {M A} [CommMonoid M] {s : Set M} (hs : IsSubmonoid s) (f : A → M) :
∀ t : Finset A, (∀ b ∈ t, f b ∈ s) → (∏ b ∈ t, f b) ∈ s
| ⟨m, hm⟩, _ => multiset_prod_mem hs _ (by simpa)
end IsSubmonoid
namespace AddMonoid
/-- The inductively defined membership predicate for the submonoid generated by a subset of a
monoid. -/
inductive InClosure (s : Set A) : A → Prop
| basic {a : A} : a ∈ s → InClosure _ a
| zero : InClosure _ 0
| add {a b : A} : InClosure _ a → InClosure _ b → InClosure _ (a + b)
end AddMonoid
namespace Monoid
/-- The inductively defined membership predicate for the `Submonoid` generated by a subset of an
monoid. -/
@[to_additive]
inductive InClosure (s : Set M) : M → Prop
| basic {a : M} : a ∈ s → InClosure _ a
| one : InClosure _ 1
| mul {a b : M} : InClosure _ a → InClosure _ b → InClosure _ (a * b)
/-- The inductively defined submonoid generated by a subset of a monoid. -/
@[to_additive
"The inductively defined `AddSubmonoid` generated by a subset of an `AddMonoid`."]
def Closure (s : Set M) : Set M :=
{ a | InClosure s a }
@[to_additive]
theorem closure.isSubmonoid (s : Set M) : IsSubmonoid (Closure s) :=
{ one_mem := InClosure.one
mul_mem := InClosure.mul }
/-- A subset of a monoid is contained in the submonoid it generates. -/
@[to_additive
"A subset of an `AddMonoid` is contained in the `AddSubmonoid` it generates."]
theorem subset_closure {s : Set M} : s ⊆ Closure s := fun _ => InClosure.basic
/-- The submonoid generated by a set is contained in any submonoid that contains the set. -/
@[to_additive
"The `AddSubmonoid` generated by a set is contained in any `AddSubmonoid` that
contains the set."]
theorem closure_subset {s t : Set M} (ht : IsSubmonoid t) (h : s ⊆ t) : Closure s ⊆ t := fun a ha =>
by induction ha <;> simp [h _, *, IsSubmonoid.one_mem, IsSubmonoid.mul_mem]
/-- Given subsets `t` and `s` of a monoid `M`, if `s ⊆ t`, the submonoid of `M` generated by `s` is
contained in the submonoid generated by `t`. -/
@[to_additive
"Given subsets `t` and `s` of an `AddMonoid M`, if `s ⊆ t`, the `AddSubmonoid`
of `M` generated by `s` is contained in the `AddSubmonoid` generated by `t`."]
theorem closure_mono {s t : Set M} (h : s ⊆ t) : Closure s ⊆ Closure t :=
closure_subset (closure.isSubmonoid t) <| Set.Subset.trans h subset_closure
/-- The submonoid generated by an element of a monoid equals the set of natural number powers of
the element. -/
@[to_additive
"The `AddSubmonoid` generated by an element of an `AddMonoid` equals the set of
natural number multiples of the element."]
theorem closure_singleton {x : M} : Closure ({x} : Set M) = powers x :=
Set.eq_of_subset_of_subset
(closure_subset (powers.isSubmonoid x) <| Set.singleton_subset_iff.2 <| powers.self_mem) <|
IsSubmonoid.powers_subset (closure.isSubmonoid _) <|
Set.singleton_subset_iff.1 <| subset_closure
/-- The image under a monoid hom of the submonoid generated by a set equals the submonoid generated
by the image of the set under the monoid hom. -/
@[to_additive
"The image under an `AddMonoid` hom of the `AddSubmonoid` generated by a set equals
the `AddSubmonoid` generated by the image of the set under the `AddMonoid` hom."]
theorem image_closure {A : Type*} [Monoid A] {f : M → A} (hf : IsMonoidHom f) (s : Set M) :
f '' Closure s = Closure (f '' s) :=
le_antisymm
(by
rintro _ ⟨x, hx, rfl⟩
induction' hx with z hz
· solve_by_elim [subset_closure, Set.mem_image_of_mem]
· rw [hf.map_one]
apply IsSubmonoid.one_mem (closure.isSubmonoid (f '' s))
· rw [hf.map_mul]
solve_by_elim [(closure.isSubmonoid _).mul_mem] )
(closure_subset (IsSubmonoid.image hf (closure.isSubmonoid _)) <|
Set.image_subset _ subset_closure)
/-- Given an element `a` of the submonoid of a monoid `M` generated by a set `s`, there exists
a list of elements of `s` whose product is `a`. -/
@[to_additive
"Given an element `a` of the `AddSubmonoid` of an `AddMonoid M` generated by
a set `s`, there exists a list of elements of `s` whose sum is `a`."]
theorem exists_list_of_mem_closure {s : Set M} {a : M} (h : a ∈ Closure s) :
∃ l : List M, (∀ x ∈ l, x ∈ s) ∧ l.prod = a := by
induction h with
| @basic a ha => exists [a]; simp [ha]
| one => exists []; simp
| mul _ _ ha hb =>
rcases ha with ⟨la, ha, eqa⟩
rcases hb with ⟨lb, hb, eqb⟩
exists la ++ lb
simp only [List.mem_append, or_imp, List.prod_append, eqa.symm, eqb.symm, and_true]
exact fun a => ⟨ha a, hb a⟩
/-- Given sets `s, t` of a commutative monoid `M`, `x ∈ M` is in the submonoid of `M` generated by
`s ∪ t` iff there exists an element of the submonoid generated by `s` and an element of the
submonoid generated by `t` whose product is `x`. -/
@[to_additive
"Given sets `s, t` of a commutative `AddMonoid M`, `x ∈ M` is in the `AddSubmonoid`
of `M` generated by `s ∪ t` iff there exists an element of the `AddSubmonoid` generated by `s`
and an element of the `AddSubmonoid` generated by `t` whose sum is `x`."]
theorem mem_closure_union_iff {M : Type*} [CommMonoid M] {s t : Set M} {x : M} :
x ∈ Closure (s ∪ t) ↔ ∃ y ∈ Closure s, ∃ z ∈ Closure t, y * z = x :=
⟨fun hx =>
let ⟨L, HL1, HL2⟩ := exists_list_of_mem_closure hx
HL2 ▸
List.recOn L
(fun _ =>
⟨1, (closure.isSubmonoid _).one_mem, 1, (closure.isSubmonoid _).one_mem, mul_one _⟩)
(fun hd tl ih HL1 =>
let ⟨y, hy, z, hz, hyzx⟩ := ih (List.forall_mem_of_forall_mem_cons HL1)
Or.casesOn (HL1 hd <| List.mem_cons_self _ _)
(fun hs =>
⟨hd * y, (closure.isSubmonoid _).mul_mem (subset_closure hs) hy, z, hz, by
rw [mul_assoc, List.prod_cons, ← hyzx]⟩)
fun ht =>
⟨y, hy, z * hd, (closure.isSubmonoid _).mul_mem hz (subset_closure ht), by
rw [← mul_assoc, List.prod_cons, ← hyzx, mul_comm hd]⟩)
HL1,
fun ⟨y, hy, z, hz, hyzx⟩ =>
hyzx ▸
(closure.isSubmonoid _).mul_mem (closure_mono Set.subset_union_left hy)
(closure_mono Set.subset_union_right hz)⟩
end Monoid
/-- Create a bundled submonoid from a set `s` and `[IsSubmonoid s]`. -/
@[to_additive "Create a bundled additive submonoid from a set `s` and `[IsAddSubmonoid s]`."]
def Submonoid.of {s : Set M} (h : IsSubmonoid s) : Submonoid M :=
⟨⟨s, @fun _ _ => h.2⟩, h.1⟩
@[to_additive]
theorem Submonoid.isSubmonoid (S : Submonoid M) : IsSubmonoid (S : Set M) := by
exact ⟨S.2, S.1.2⟩
|
Deprecated\Subring.lean | /-
Copyright (c) 2018 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Deprecated.Subgroup
import Mathlib.Deprecated.Group
import Mathlib.Algebra.Ring.Subring.Basic
/-!
# Unbundled subrings (deprecated)
This file is deprecated, and is no longer imported by anything in mathlib other than other
deprecated files, and test files. You should not need to import it.
This file defines predicates for unbundled subrings. Instead of using this file, please use
`Subring`, defined in `Mathlib.Algebra.Ring.Subring.Basic`, for subrings of rings.
## Main definitions
`IsSubring (S : Set R) : Prop` : the predicate that `S` is the underlying set of a subring
of the ring `R`. The bundled variant `Subring R` should be used in preference to this.
## Tags
IsSubring
-/
universe u v
open Group
variable {R : Type u} [Ring R]
/-- `S` is a subring: a set containing 1 and closed under multiplication, addition and additive
inverse. -/
structure IsSubring (S : Set R) extends IsAddSubgroup S, IsSubmonoid S : Prop
/-- Construct a `Subring` from a set satisfying `IsSubring`. -/
def IsSubring.subring {S : Set R} (hs : IsSubring S) : Subring R where
carrier := S
one_mem' := hs.one_mem
mul_mem' := hs.mul_mem
zero_mem' := hs.zero_mem
add_mem' := hs.add_mem
neg_mem' := hs.neg_mem
namespace RingHom
theorem isSubring_preimage {R : Type u} {S : Type v} [Ring R] [Ring S] (f : R →+* S) {s : Set S}
(hs : IsSubring s) : IsSubring (f ⁻¹' s) :=
{ IsAddGroupHom.preimage f.to_isAddGroupHom hs.toIsAddSubgroup,
IsSubmonoid.preimage f.to_isMonoidHom hs.toIsSubmonoid with }
theorem isSubring_image {R : Type u} {S : Type v} [Ring R] [Ring S] (f : R →+* S) {s : Set R}
(hs : IsSubring s) : IsSubring (f '' s) :=
{ IsAddGroupHom.image_addSubgroup f.to_isAddGroupHom hs.toIsAddSubgroup,
IsSubmonoid.image f.to_isMonoidHom hs.toIsSubmonoid with }
theorem isSubring_set_range {R : Type u} {S : Type v} [Ring R] [Ring S] (f : R →+* S) :
IsSubring (Set.range f) :=
{ IsAddGroupHom.range_addSubgroup f.to_isAddGroupHom, Range.isSubmonoid f.to_isMonoidHom with }
end RingHom
variable {cR : Type u} [CommRing cR]
theorem IsSubring.inter {S₁ S₂ : Set R} (hS₁ : IsSubring S₁) (hS₂ : IsSubring S₂) :
IsSubring (S₁ ∩ S₂) :=
{ IsAddSubgroup.inter hS₁.toIsAddSubgroup hS₂.toIsAddSubgroup,
IsSubmonoid.inter hS₁.toIsSubmonoid hS₂.toIsSubmonoid with }
theorem IsSubring.iInter {ι : Sort*} {S : ι → Set R} (h : ∀ y : ι, IsSubring (S y)) :
IsSubring (Set.iInter S) :=
{ IsAddSubgroup.iInter fun i ↦ (h i).toIsAddSubgroup,
IsSubmonoid.iInter fun i ↦ (h i).toIsSubmonoid with }
theorem isSubring_iUnion_of_directed {ι : Type*} [Nonempty ι] {s : ι → Set R}
(h : ∀ i, IsSubring (s i)) (directed : ∀ i j, ∃ k, s i ⊆ s k ∧ s j ⊆ s k) :
IsSubring (⋃ i, s i) :=
{ toIsAddSubgroup := isAddSubgroup_iUnion_of_directed (fun i ↦ (h i).toIsAddSubgroup) directed
toIsSubmonoid := isSubmonoid_iUnion_of_directed (fun i ↦ (h i).toIsSubmonoid) directed }
namespace Ring
/-- The smallest subring containing a given subset of a ring, considered as a set. This function
is deprecated; use `Subring.closure`. -/
def closure (s : Set R) :=
AddGroup.closure (Monoid.Closure s)
variable {s : Set R}
-- attribute [local reducible] closure -- Porting note: not available in Lean4
theorem exists_list_of_mem_closure {a : R} (h : a ∈ closure s) :
∃ L : List (List R), (∀ l ∈ L, ∀ x ∈ l, x ∈ s ∨ x = (-1 : R)) ∧ (L.map List.prod).sum = a :=
AddGroup.InClosure.recOn h
fun {x} hx ↦ match x, Monoid.exists_list_of_mem_closure hx with
| _, ⟨L, h1, rfl⟩ => ⟨[L], List.forall_mem_singleton.2 fun r hr ↦ Or.inl (h1 r hr), zero_add _⟩
⟨[], List.forall_mem_nil _, rfl⟩
fun {b} _ ih ↦ match b, ih with
| _, ⟨L1, h1, rfl⟩ =>
⟨L1.map (List.cons (-1)),
fun L2 h2 ↦ match L2, List.mem_map.1 h2 with
| _, ⟨L3, h3, rfl⟩ => List.forall_mem_cons.2 ⟨Or.inr rfl, h1 L3 h3⟩, by
simp only [List.map_map, (· ∘ ·), List.prod_cons, neg_one_mul]
refine List.recOn L1 neg_zero.symm fun hd tl ih ↦ ?_
rw [List.map_cons, List.sum_cons, ih, List.map_cons, List.sum_cons, neg_add]⟩
fun {r1 r2} _ _ ih1 ih2 ↦ match r1, r2, ih1, ih2 with
| _, _, ⟨L1, h1, rfl⟩, ⟨L2, h2, rfl⟩ =>
⟨L1 ++ L2, List.forall_mem_append.2 ⟨h1, h2⟩, by rw [List.map_append, List.sum_append]⟩
@[elab_as_elim]
protected theorem InClosure.recOn {C : R → Prop} {x : R} (hx : x ∈ closure s) (h1 : C 1)
(hneg1 : C (-1)) (hs : ∀ z ∈ s, ∀ n, C n → C (z * n)) (ha : ∀ {x y}, C x → C y → C (x + y)) :
C x := by
have h0 : C 0 := add_neg_self (1 : R) ▸ ha h1 hneg1
rcases exists_list_of_mem_closure hx with ⟨L, HL, rfl⟩
clear hx
induction' L with hd tl ih
· exact h0
rw [List.forall_mem_cons] at HL
suffices C (List.prod hd) by
rw [List.map_cons, List.sum_cons]
exact ha this (ih HL.2)
replace HL := HL.1
clear ih tl
-- Porting note: Expanded `rsuffices`
suffices ∃ L, (∀ x ∈ L, x ∈ s) ∧ (List.prod hd = List.prod L ∨ List.prod hd = -List.prod L) by
rcases this with ⟨L, HL', HP | HP⟩ <;> rw [HP] <;> clear HP HL
· induction' L with hd tl ih
· exact h1
rw [List.forall_mem_cons] at HL'
rw [List.prod_cons]
exact hs _ HL'.1 _ (ih HL'.2)
· induction' L with hd tl ih
· exact hneg1
rw [List.prod_cons, neg_mul_eq_mul_neg]
rw [List.forall_mem_cons] at HL'
exact hs _ HL'.1 _ (ih HL'.2)
induction' hd with hd tl ih
· exact ⟨[], List.forall_mem_nil _, Or.inl rfl⟩
rw [List.forall_mem_cons] at HL
rcases ih HL.2 with ⟨L, HL', HP | HP⟩ <;> cases' HL.1 with hhd hhd
· exact
⟨hd::L, List.forall_mem_cons.2 ⟨hhd, HL'⟩,
Or.inl <| by rw [List.prod_cons, List.prod_cons, HP]⟩
· exact ⟨L, HL', Or.inr <| by rw [List.prod_cons, hhd, neg_one_mul, HP]⟩
· exact
⟨hd::L, List.forall_mem_cons.2 ⟨hhd, HL'⟩,
Or.inr <| by rw [List.prod_cons, List.prod_cons, HP, neg_mul_eq_mul_neg]⟩
· exact ⟨L, HL', Or.inl <| by rw [List.prod_cons, hhd, HP, neg_one_mul, neg_neg]⟩
theorem closure.isSubring : IsSubring (closure s) :=
{ AddGroup.closure.isAddSubgroup _ with
one_mem := AddGroup.mem_closure <| IsSubmonoid.one_mem <| Monoid.closure.isSubmonoid _
mul_mem := fun {a _} ha hb ↦ AddGroup.InClosure.recOn hb
(fun {c} hc ↦ AddGroup.InClosure.recOn ha
(fun hd ↦ AddGroup.subset_closure ((Monoid.closure.isSubmonoid _).mul_mem hd hc))
((zero_mul c).symm ▸ (AddGroup.closure.isAddSubgroup _).zero_mem)
(fun {d} _ hdc ↦ neg_mul_eq_neg_mul d c ▸ (AddGroup.closure.isAddSubgroup _).neg_mem hdc)
fun {d e} _ _ hdc hec ↦
(add_mul d e c).symm ▸ (AddGroup.closure.isAddSubgroup _).add_mem hdc hec)
((mul_zero a).symm ▸ (AddGroup.closure.isAddSubgroup _).zero_mem)
(fun {c} _ hac ↦ neg_mul_eq_mul_neg a c ▸ (AddGroup.closure.isAddSubgroup _).neg_mem hac)
fun {c d} _ _ hac had ↦
(mul_add a c d).symm ▸ (AddGroup.closure.isAddSubgroup _).add_mem hac had }
theorem mem_closure {a : R} : a ∈ s → a ∈ closure s :=
AddGroup.mem_closure ∘ @Monoid.subset_closure _ _ _ _
theorem subset_closure : s ⊆ closure s :=
fun _ ↦ mem_closure
theorem closure_subset {t : Set R} (ht : IsSubring t) : s ⊆ t → closure s ⊆ t :=
AddGroup.closure_subset ht.toIsAddSubgroup ∘ Monoid.closure_subset ht.toIsSubmonoid
theorem closure_subset_iff {s t : Set R} (ht : IsSubring t) : closure s ⊆ t ↔ s ⊆ t :=
(AddGroup.closure_subset_iff ht.toIsAddSubgroup).trans
⟨Set.Subset.trans Monoid.subset_closure, Monoid.closure_subset ht.toIsSubmonoid⟩
theorem closure_mono {s t : Set R} (H : s ⊆ t) : closure s ⊆ closure t :=
closure_subset closure.isSubring <| Set.Subset.trans H subset_closure
theorem image_closure {S : Type*} [Ring S] (f : R →+* S) (s : Set R) :
f '' closure s = closure (f '' s) := by
refine le_antisymm ?_ (closure_subset (RingHom.isSubring_image _ closure.isSubring) <|
Set.image_subset _ subset_closure)
rintro _ ⟨x, hx, rfl⟩
apply AddGroup.InClosure.recOn (motive := fun {x} _ ↦ f x ∈ closure (f '' s)) hx _ <;> intros
· rw [f.map_zero]
apply closure.isSubring.zero_mem
· rw [f.map_neg]
apply closure.isSubring.neg_mem
assumption
· rw [f.map_add]
apply closure.isSubring.add_mem
assumption'
· apply AddGroup.mem_closure
rw [← Monoid.image_closure f.to_isMonoidHom]
apply Set.mem_image_of_mem
assumption
end Ring
|
Dynamics\Flow.lean | /-
Copyright (c) 2020 Jean Lo. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jean Lo
-/
import Mathlib.Topology.Algebra.Group.Basic
import Mathlib.Logic.Function.Iterate
/-!
# Flows and invariant sets
This file defines a flow on a topological space `α` by a topological
monoid `τ` as a continuous monoid-action of `τ` on `α`. Anticipating the
cases where `τ` is one of `ℕ`, `ℤ`, `ℝ⁺`, or `ℝ`, we use additive
notation for the monoids, though the definition does not require
commutativity.
A subset `s` of `α` is invariant under a family of maps `ϕₜ : α → α`
if `ϕₜ s ⊆ s` for all `t`. In many cases `ϕ` will be a flow on
`α`. For the cases where `ϕ` is a flow by an ordered (additive,
commutative) monoid, we additionally define forward invariance, where
`t` ranges over those elements which are nonnegative.
Additionally, we define such constructions as the restriction of a
flow onto an invariant subset, and the time-reversal of a flow by a
group.
-/
open Set Function Filter
/-!
### Invariant sets
-/
section Invariant
variable {τ : Type*} {α : Type*}
/-- A set `s ⊆ α` is invariant under `ϕ : τ → α → α` if
`ϕ t s ⊆ s` for all `t` in `τ`. -/
def IsInvariant (ϕ : τ → α → α) (s : Set α) : Prop :=
∀ t, MapsTo (ϕ t) s s
variable (ϕ : τ → α → α) (s : Set α)
theorem isInvariant_iff_image : IsInvariant ϕ s ↔ ∀ t, ϕ t '' s ⊆ s := by
simp_rw [IsInvariant, mapsTo']
/-- A set `s ⊆ α` is forward-invariant under `ϕ : τ → α → α` if
`ϕ t s ⊆ s` for all `t ≥ 0`. -/
def IsFwInvariant [Preorder τ] [Zero τ] (ϕ : τ → α → α) (s : Set α) : Prop :=
∀ ⦃t⦄, 0 ≤ t → MapsTo (ϕ t) s s
theorem IsInvariant.isFwInvariant [Preorder τ] [Zero τ] {ϕ : τ → α → α} {s : Set α}
(h : IsInvariant ϕ s) : IsFwInvariant ϕ s := fun t _ht => h t
/-- If `τ` is a `CanonicallyOrderedAddCommMonoid` (e.g., `ℕ` or `ℝ≥0`), then the notions
`IsFwInvariant` and `IsInvariant` are equivalent. -/
theorem IsFwInvariant.isInvariant [CanonicallyOrderedAddCommMonoid τ] {ϕ : τ → α → α} {s : Set α}
(h : IsFwInvariant ϕ s) : IsInvariant ϕ s := fun t => h (zero_le t)
/-- If `τ` is a `CanonicallyOrderedAddCommMonoid` (e.g., `ℕ` or `ℝ≥0`), then the notions
`IsFwInvariant` and `IsInvariant` are equivalent. -/
theorem isFwInvariant_iff_isInvariant [CanonicallyOrderedAddCommMonoid τ] {ϕ : τ → α → α}
{s : Set α} :
IsFwInvariant ϕ s ↔ IsInvariant ϕ s :=
⟨IsFwInvariant.isInvariant, IsInvariant.isFwInvariant⟩
end Invariant
/-!
### Flows
-/
/-- A flow on a topological space `α` by an additive topological
monoid `τ` is a continuous monoid action of `τ` on `α`. -/
structure Flow (τ : Type*) [TopologicalSpace τ] [AddMonoid τ] [ContinuousAdd τ] (α : Type*)
[TopologicalSpace α] where
/-- The map `τ → α → α` underlying a flow of `τ` on `α`. -/
toFun : τ → α → α
cont' : Continuous (uncurry toFun)
map_add' : ∀ t₁ t₂ x, toFun (t₁ + t₂) x = toFun t₁ (toFun t₂ x)
map_zero' : ∀ x, toFun 0 x = x
namespace Flow
variable {τ : Type*} [AddMonoid τ] [TopologicalSpace τ] [ContinuousAdd τ]
{α : Type*} [TopologicalSpace α] (ϕ : Flow τ α)
instance : Inhabited (Flow τ α) :=
⟨{ toFun := fun _ x => x
cont' := continuous_snd
map_add' := fun _ _ _ => rfl
map_zero' := fun _ => rfl }⟩
instance : CoeFun (Flow τ α) fun _ => τ → α → α := ⟨Flow.toFun⟩
@[ext]
theorem ext : ∀ {ϕ₁ ϕ₂ : Flow τ α}, (∀ t x, ϕ₁ t x = ϕ₂ t x) → ϕ₁ = ϕ₂
| ⟨f₁, _, _, _⟩, ⟨f₂, _, _, _⟩, h => by
congr
funext
exact h _ _
@[continuity, fun_prop]
protected theorem continuous {β : Type*} [TopologicalSpace β] {t : β → τ} (ht : Continuous t)
{f : β → α} (hf : Continuous f) : Continuous fun x => ϕ (t x) (f x) :=
ϕ.cont'.comp (ht.prod_mk hf)
alias _root_.Continuous.flow := Flow.continuous
theorem map_add (t₁ t₂ : τ) (x : α) : ϕ (t₁ + t₂) x = ϕ t₁ (ϕ t₂ x) := ϕ.map_add' _ _ _
@[simp]
theorem map_zero : ϕ 0 = id := funext ϕ.map_zero'
theorem map_zero_apply (x : α) : ϕ 0 x = x := ϕ.map_zero' x
/-- Iterations of a continuous function from a topological space `α`
to itself defines a semiflow by `ℕ` on `α`. -/
def fromIter {g : α → α} (h : Continuous g) : Flow ℕ α where
toFun n x := g^[n] x
cont' := continuous_prod_of_discrete_left.mpr (Continuous.iterate h)
map_add' := iterate_add_apply _
map_zero' _x := rfl
/-- Restriction of a flow onto an invariant set. -/
def restrict {s : Set α} (h : IsInvariant ϕ s) : Flow τ (↥s) where
toFun t := (h t).restrict _ _ _
cont' := (ϕ.continuous continuous_fst continuous_subtype_val.snd').subtype_mk _
map_add' _ _ _ := Subtype.ext (map_add _ _ _ _)
map_zero' _ := Subtype.ext (map_zero_apply _ _)
end Flow
namespace Flow
variable {τ : Type*} [AddCommGroup τ] [TopologicalSpace τ] [TopologicalAddGroup τ]
{α : Type*} [TopologicalSpace α] (ϕ : Flow τ α)
theorem isInvariant_iff_image_eq (s : Set α) : IsInvariant ϕ s ↔ ∀ t, ϕ t '' s = s :=
(isInvariant_iff_image _ _).trans
(Iff.intro
(fun h t => Subset.antisymm (h t) fun _ hx => ⟨_, h (-t) ⟨_, hx, rfl⟩, by simp [← map_add]⟩)
fun h t => by rw [h t])
/-- The time-reversal of a flow `ϕ` by a (commutative, additive) group
is defined `ϕ.reverse t x = ϕ (-t) x`. -/
def reverse : Flow τ α where
toFun t := ϕ (-t)
cont' := ϕ.continuous continuous_fst.neg continuous_snd
map_add' _ _ _ := by dsimp; rw [neg_add, map_add]
map_zero' _ := by dsimp; rw [neg_zero, map_zero_apply]
-- Porting note: add @continuity to Flow.toFun so that these works:
-- Porting note: Homeomorphism.continuous_toFun : Continuous toFun := by continuity
-- Porting note: Homeomorphism.continuous_invFun : Continuous invFun := by continuity
@[continuity]
theorem continuous_toFun (t : τ) : Continuous (ϕ.toFun t) := by
rw [← curry_uncurry ϕ.toFun]
apply continuous_curry
exact ϕ.cont'
/-- The map `ϕ t` as a homeomorphism. -/
def toHomeomorph (t : τ) : (α ≃ₜ α) where
toFun := ϕ t
invFun := ϕ (-t)
left_inv x := by rw [← map_add, neg_add_self, map_zero_apply]
right_inv x := by rw [← map_add, add_neg_self, map_zero_apply]
theorem image_eq_preimage (t : τ) (s : Set α) : ϕ t '' s = ϕ (-t) ⁻¹' s :=
(ϕ.toHomeomorph t).toEquiv.image_eq_preimage s
end Flow
|
Dynamics\Minimal.lean | /-
Copyright (c) 2021 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import Mathlib.GroupTheory.GroupAction.Basic
import Mathlib.Topology.Algebra.ConstMulAction
/-!
# Minimal action of a group
In this file we define an action of a monoid `M` on a topological space `α` to be *minimal* if the
`M`-orbit of every point `x : α` is dense. We also provide an additive version of this definition
and prove some basic facts about minimal actions.
## TODO
* Define a minimal set of an action.
## Tags
group action, minimal
-/
open Pointwise
/-- An action of an additive monoid `M` on a topological space is called *minimal* if the `M`-orbit
of every point `x : α` is dense. -/
class AddAction.IsMinimal (M α : Type*) [AddMonoid M] [TopologicalSpace α] [AddAction M α] :
Prop where
dense_orbit : ∀ x : α, Dense (AddAction.orbit M x)
/-- An action of a monoid `M` on a topological space is called *minimal* if the `M`-orbit of every
point `x : α` is dense. -/
@[to_additive]
class MulAction.IsMinimal (M α : Type*) [Monoid M] [TopologicalSpace α] [MulAction M α] :
Prop where
dense_orbit : ∀ x : α, Dense (MulAction.orbit M x)
open MulAction Set
variable (M G : Type*) {α : Type*} [Monoid M] [Group G] [TopologicalSpace α] [MulAction M α]
[MulAction G α]
@[to_additive]
theorem MulAction.dense_orbit [IsMinimal M α] (x : α) : Dense (orbit M x) :=
MulAction.IsMinimal.dense_orbit x
@[to_additive]
theorem denseRange_smul [IsMinimal M α] (x : α) : DenseRange fun c : M ↦ c • x :=
MulAction.dense_orbit M x
@[to_additive]
instance (priority := 100) MulAction.isMinimal_of_pretransitive [IsPretransitive M α] :
IsMinimal M α :=
⟨fun x ↦ (surjective_smul M x).denseRange⟩
@[to_additive]
theorem IsOpen.exists_smul_mem [IsMinimal M α] (x : α) {U : Set α} (hUo : IsOpen U)
(hne : U.Nonempty) : ∃ c : M, c • x ∈ U :=
(denseRange_smul M x).exists_mem_open hUo hne
@[to_additive]
theorem IsOpen.iUnion_preimage_smul [IsMinimal M α] {U : Set α} (hUo : IsOpen U)
(hne : U.Nonempty) : ⋃ c : M, (c • ·) ⁻¹' U = univ :=
iUnion_eq_univ_iff.2 fun x ↦ hUo.exists_smul_mem M x hne
@[to_additive]
theorem IsOpen.iUnion_smul [IsMinimal G α] {U : Set α} (hUo : IsOpen U) (hne : U.Nonempty) :
⋃ g : G, g • U = univ :=
iUnion_eq_univ_iff.2 fun x ↦
let ⟨g, hg⟩ := hUo.exists_smul_mem G x hne
⟨g⁻¹, _, hg, inv_smul_smul _ _⟩
@[to_additive]
theorem IsCompact.exists_finite_cover_smul [IsMinimal G α] [ContinuousConstSMul G α]
{K U : Set α} (hK : IsCompact K) (hUo : IsOpen U) (hne : U.Nonempty) :
∃ I : Finset G, K ⊆ ⋃ g ∈ I, g • U :=
(hK.elim_finite_subcover (fun g ↦ g • U) fun _ ↦ hUo.smul _) <| calc
K ⊆ univ := subset_univ K
_ = ⋃ g : G, g • U := (hUo.iUnion_smul G hne).symm
@[to_additive]
theorem dense_of_nonempty_smul_invariant [IsMinimal M α] {s : Set α} (hne : s.Nonempty)
(hsmul : ∀ c : M, c • s ⊆ s) : Dense s :=
let ⟨x, hx⟩ := hne
(MulAction.dense_orbit M x).mono (range_subset_iff.2 fun c ↦ hsmul c ⟨x, hx, rfl⟩)
@[to_additive]
theorem eq_empty_or_univ_of_smul_invariant_closed [IsMinimal M α] {s : Set α} (hs : IsClosed s)
(hsmul : ∀ c : M, c • s ⊆ s) : s = ∅ ∨ s = univ :=
s.eq_empty_or_nonempty.imp_right fun hne ↦
hs.closure_eq ▸ (dense_of_nonempty_smul_invariant M hne hsmul).closure_eq
@[to_additive]
theorem isMinimal_iff_closed_smul_invariant [ContinuousConstSMul M α] :
IsMinimal M α ↔ ∀ s : Set α, IsClosed s → (∀ c : M, c • s ⊆ s) → s = ∅ ∨ s = univ := by
constructor
· intro _ _
exact eq_empty_or_univ_of_smul_invariant_closed M
refine fun H ↦ ⟨fun _ ↦ dense_iff_closure_eq.2 <| (H _ ?_ ?_).resolve_left ?_⟩
exacts [isClosed_closure, fun _ ↦ smul_closure_orbit_subset _ _,
(orbit_nonempty _).closure.ne_empty]
|
Dynamics\Newton.lean | /-
Copyright (c) 2024 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Antoine Chambert-Loir, Oliver Nash
-/
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Identities
import Mathlib.RingTheory.Nilpotent.Lemmas
import Mathlib.RingTheory.Polynomial.Nilpotent
import Mathlib.RingTheory.Polynomial.Tower
/-!
# Newton-Raphson method
Given a single-variable polynomial `P` with derivative `P'`, Newton's method concerns iteration of
the rational map: `x ↦ x - P(x) / P'(x)`.
Over a field it can serve as a root-finding algorithm. It is also useful tool in certain proofs
such as Hensel's lemma and Jordan-Chevalley decomposition.
## Main definitions / results:
* `Polynomial.newtonMap`: the map `x ↦ x - P(x) / P'(x)`, where `P'` is the derivative of the
polynomial `P`.
* `Polynomial.isFixedPt_newtonMap_of_isUnit_iff`: `x` is a fixed point for Newton iteration iff
it is a root of `P` (provided `P'(x)` is a unit).
* `Polynomial.exists_unique_nilpotent_sub_and_aeval_eq_zero`: if `x` is almost a root of `P` in the
sense that `P(x)` is nilpotent (and `P'(x)` is a unit) then we may write `x` as a sum
`x = n + r` where `n` is nilpotent and `r` is a root of `P`. This can be used to prove the
Jordan-Chevalley decomposition of linear endomorphims.
-/
open Set Function
noncomputable section
namespace Polynomial
variable {R S : Type*} [CommRing R] [CommRing S] [Algebra R S] (P : R[X]) {x : S}
/-- Given a single-variable polynomial `P` with derivative `P'`, this is the map:
`x ↦ x - P(x) / P'(x)`. When `P'(x)` is not a unit we use a junk-value pattern and send `x ↦ x`. -/
def newtonMap (x : S) : S :=
x - (Ring.inverse <| aeval x (derivative P)) * aeval x P
theorem newtonMap_apply :
P.newtonMap x = x - (Ring.inverse <| aeval x (derivative P)) * (aeval x P) :=
rfl
variable {P}
theorem newtonMap_apply_of_isUnit (h : IsUnit <| aeval x (derivative P)) :
P.newtonMap x = x - h.unit⁻¹ * aeval x P := by
simp [newtonMap_apply, Ring.inverse, h]
theorem newtonMap_apply_of_not_isUnit (h : ¬ (IsUnit <| aeval x (derivative P))) :
P.newtonMap x = x := by
simp [newtonMap_apply, Ring.inverse, h]
theorem isNilpotent_iterate_newtonMap_sub_of_isNilpotent (h : IsNilpotent <| aeval x P) (n : ℕ) :
IsNilpotent <| P.newtonMap^[n] x - x := by
induction n with
| zero => simp
| succ n ih =>
rw [iterate_succ', comp_apply, newtonMap_apply, sub_right_comm]
refine (Commute.all _ _).isNilpotent_sub ih <| (Commute.all _ _).isNilpotent_mul_right ?_
simpa using Commute.isNilpotent_add (Commute.all _ _)
(isNilpotent_aeval_sub_of_isNilpotent_sub P ih) h
theorem isFixedPt_newtonMap_of_aeval_eq_zero (h : aeval x P = 0) :
IsFixedPt P.newtonMap x := by
rw [IsFixedPt, newtonMap_apply, h, mul_zero, sub_zero]
theorem isFixedPt_newtonMap_of_isUnit_iff (h : IsUnit <| aeval x (derivative P)) :
IsFixedPt P.newtonMap x ↔ aeval x P = 0 := by
rw [IsFixedPt, newtonMap_apply, sub_eq_self, Ring.inverse_mul_eq_iff_eq_mul _ _ _ h, mul_zero]
/-- This is really an auxiliary result, en route to
`Polynomial.exists_unique_nilpotent_sub_and_aeval_eq_zero`. -/
theorem aeval_pow_two_pow_dvd_aeval_iterate_newtonMap
(h : IsNilpotent (aeval x P)) (h' : IsUnit (aeval x <| derivative P)) (n : ℕ) :
(aeval x P) ^ (2 ^ n) ∣ aeval (P.newtonMap^[n] x) P := by
induction n with
| zero => simp
| succ n ih =>
have ⟨d, hd⟩ := binomExpansion (P.map (algebraMap R S)) (P.newtonMap^[n] x)
(-Ring.inverse (aeval (P.newtonMap^[n] x) <| derivative P) * aeval (P.newtonMap^[n] x) P)
rw [eval_map_algebraMap, eval_map_algebraMap] at hd
rw [iterate_succ', comp_apply, newtonMap_apply, sub_eq_add_neg, neg_mul_eq_neg_mul, hd]
refine dvd_add ?_ (dvd_mul_of_dvd_right ?_ _)
· convert dvd_zero _
have : IsUnit (aeval (P.newtonMap^[n] x) <| derivative P) :=
isUnit_aeval_of_isUnit_aeval_of_isNilpotent_sub h' <|
isNilpotent_iterate_newtonMap_sub_of_isNilpotent h n
rw [derivative_map, eval_map_algebraMap, ← mul_assoc, mul_neg, Ring.mul_inverse_cancel _ this,
neg_mul, one_mul, add_right_neg]
· rw [neg_mul, even_two.neg_pow, mul_pow, pow_succ, pow_mul]
exact dvd_mul_of_dvd_right (pow_dvd_pow_of_dvd ih 2) _
/-- If `x` is almost a root of `P` in the sense that `P(x)` is nilpotent (and `P'(x)` is a
unit) then we may write `x` as a sum `x = n + r` where `n` is nilpotent and `r` is a root of `P`.
Moreover, `n` and `r` are unique.
This can be used to prove the Jordan-Chevalley decomposition of linear endomorphims. -/
theorem exists_unique_nilpotent_sub_and_aeval_eq_zero
(h : IsNilpotent (aeval x P)) (h' : IsUnit (aeval x <| derivative P)) :
∃! r, IsNilpotent (x - r) ∧ aeval r P = 0 := by
simp_rw [(neg_sub _ x).symm, isNilpotent_neg_iff]
refine exists_unique_of_exists_of_unique ?_ fun r₁ r₂ ⟨hr₁, hr₁'⟩ ⟨hr₂, hr₂'⟩ ↦ ?_
· -- Existence
obtain ⟨n, hn⟩ := id h
refine ⟨P.newtonMap^[n] x, isNilpotent_iterate_newtonMap_sub_of_isNilpotent h n, ?_⟩
rw [← zero_dvd_iff, ← pow_eq_zero_of_le n.lt_two_pow.le hn]
exact aeval_pow_two_pow_dvd_aeval_iterate_newtonMap h h' n
· -- Uniqueness
have ⟨u, hu⟩ := binomExpansion (P.map (algebraMap R S)) r₁ (r₂ - r₁)
suffices IsUnit (aeval r₁ (derivative P) + u * (r₂ - r₁)) by
rwa [derivative_map, eval_map_algebraMap, eval_map_algebraMap, eval_map_algebraMap,
add_sub_cancel, hr₂', hr₁', zero_add, pow_two, ← mul_assoc, ← add_mul, eq_comm,
this.mul_right_eq_zero, sub_eq_zero, eq_comm] at hu
have : IsUnit (aeval r₁ (derivative P)) :=
isUnit_aeval_of_isUnit_aeval_of_isNilpotent_sub h' hr₁
rw [← sub_sub_sub_cancel_right r₂ r₁ x]
refine IsNilpotent.isUnit_add_left_of_commute ?_ this (Commute.all _ _)
exact (Commute.all _ _).isNilpotent_mul_right <| (Commute.all _ _).isNilpotent_sub hr₂ hr₁
end Polynomial
|
Dynamics\OmegaLimit.lean | /-
Copyright (c) 2020 Jean Lo. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jean Lo
-/
import Mathlib.Dynamics.Flow
import Mathlib.Tactic.Monotonicity
/-!
# ω-limits
For a function `ϕ : τ → α → β` where `β` is a topological space, we
define the ω-limit under `ϕ` of a set `s` in `α` with respect to
filter `f` on `τ`: an element `y : β` is in the ω-limit of `s` if the
forward images of `s` intersect arbitrarily small neighbourhoods of
`y` frequently "in the direction of `f`".
In practice `ϕ` is often a continuous monoid-act, but the definition
requires only that `ϕ` has a coercion to the appropriate function
type. In the case where `τ` is `ℕ` or `ℝ` and `f` is `atTop`, we
recover the usual definition of the ω-limit set as the set of all `y`
such that there exist sequences `(tₙ)`, `(xₙ)` such that `ϕ tₙ xₙ ⟶ y`
as `n ⟶ ∞`.
## Notations
The `omegaLimit` locale provides the localised notation `ω` for
`omegaLimit`, as well as `ω⁺` and `ω⁻` for `omegaLimit atTop` and
`omegaLimit atBot` respectively for when the acting monoid is
endowed with an order.
-/
open Set Function Filter Topology
/-!
### Definition and notation
-/
section omegaLimit
variable {τ : Type*} {α : Type*} {β : Type*} {ι : Type*}
/-- The ω-limit of a set `s` under `ϕ` with respect to a filter `f` is `⋂ u ∈ f, cl (ϕ u s)`. -/
def omegaLimit [TopologicalSpace β] (f : Filter τ) (ϕ : τ → α → β) (s : Set α) : Set β :=
⋂ u ∈ f, closure (image2 ϕ u s)
@[inherit_doc]
scoped[omegaLimit] notation "ω" => omegaLimit
/-- The ω-limit w.r.t. `Filter.atTop`. -/
scoped[omegaLimit] notation "ω⁺" => omegaLimit Filter.atTop
/-- The ω-limit w.r.t. `Filter.atBot`. -/
scoped[omegaLimit] notation "ω⁻" => omegaLimit Filter.atBot
variable [TopologicalSpace β]
variable (f : Filter τ) (ϕ : τ → α → β) (s s₁ s₂ : Set α)
/-!
### Elementary properties
-/
open omegaLimit
theorem omegaLimit_def : ω f ϕ s = ⋂ u ∈ f, closure (image2 ϕ u s) := rfl
theorem omegaLimit_subset_of_tendsto {m : τ → τ} {f₁ f₂ : Filter τ} (hf : Tendsto m f₁ f₂) :
ω f₁ (fun t x ↦ ϕ (m t) x) s ⊆ ω f₂ ϕ s := by
refine iInter₂_mono' fun u hu ↦ ⟨m ⁻¹' u, tendsto_def.mp hf _ hu, ?_⟩
rw [← image2_image_left]
exact closure_mono (image2_subset (image_preimage_subset _ _) Subset.rfl)
theorem omegaLimit_mono_left {f₁ f₂ : Filter τ} (hf : f₁ ≤ f₂) : ω f₁ ϕ s ⊆ ω f₂ ϕ s :=
omegaLimit_subset_of_tendsto ϕ s (tendsto_id'.2 hf)
theorem omegaLimit_mono_right {s₁ s₂ : Set α} (hs : s₁ ⊆ s₂) : ω f ϕ s₁ ⊆ ω f ϕ s₂ :=
iInter₂_mono fun _u _hu ↦ closure_mono (image2_subset Subset.rfl hs)
theorem isClosed_omegaLimit : IsClosed (ω f ϕ s) :=
isClosed_iInter fun _u ↦ isClosed_iInter fun _hu ↦ isClosed_closure
theorem mapsTo_omegaLimit' {α' β' : Type*} [TopologicalSpace β'] {f : Filter τ} {ϕ : τ → α → β}
{ϕ' : τ → α' → β'} {ga : α → α'} {s' : Set α'} (hs : MapsTo ga s s') {gb : β → β'}
(hg : ∀ᶠ t in f, EqOn (gb ∘ ϕ t) (ϕ' t ∘ ga) s) (hgc : Continuous gb) :
MapsTo gb (ω f ϕ s) (ω f ϕ' s') := by
simp only [omegaLimit_def, mem_iInter, MapsTo]
intro y hy u hu
refine map_mem_closure hgc (hy _ (inter_mem hu hg)) (forall_image2_iff.2 fun t ht x hx ↦ ?_)
calc
gb (ϕ t x) = ϕ' t (ga x) := ht.2 hx
_ ∈ image2 ϕ' u s' := mem_image2_of_mem ht.1 (hs hx)
theorem mapsTo_omegaLimit {α' β' : Type*} [TopologicalSpace β'] {f : Filter τ} {ϕ : τ → α → β}
{ϕ' : τ → α' → β'} {ga : α → α'} {s' : Set α'} (hs : MapsTo ga s s') {gb : β → β'}
(hg : ∀ t x, gb (ϕ t x) = ϕ' t (ga x)) (hgc : Continuous gb) :
MapsTo gb (ω f ϕ s) (ω f ϕ' s') :=
mapsTo_omegaLimit' _ hs (eventually_of_forall fun t x _hx ↦ hg t x) hgc
theorem omegaLimit_image_eq {α' : Type*} (ϕ : τ → α' → β) (f : Filter τ) (g : α → α') :
ω f ϕ (g '' s) = ω f (fun t x ↦ ϕ t (g x)) s := by simp only [omegaLimit, image2_image_right]
theorem omegaLimit_preimage_subset {α' : Type*} (ϕ : τ → α' → β) (s : Set α') (f : Filter τ)
(g : α → α') : ω f (fun t x ↦ ϕ t (g x)) (g ⁻¹' s) ⊆ ω f ϕ s :=
mapsTo_omegaLimit _ (mapsTo_preimage _ _) (fun _t _x ↦ rfl) continuous_id
/-!
### Equivalent definitions of the omega limit
The next few lemmas are various versions of the property
characterising ω-limits:
-/
/-- An element `y` is in the ω-limit set of `s` w.r.t. `f` if the
preimages of an arbitrary neighbourhood of `y` frequently
(w.r.t. `f`) intersects of `s`. -/
theorem mem_omegaLimit_iff_frequently (y : β) :
y ∈ ω f ϕ s ↔ ∀ n ∈ 𝓝 y, ∃ᶠ t in f, (s ∩ ϕ t ⁻¹' n).Nonempty := by
simp_rw [frequently_iff, omegaLimit_def, mem_iInter, mem_closure_iff_nhds]
constructor
· intro h _ hn _ hu
rcases h _ hu _ hn with ⟨_, _, _, ht, _, hx, rfl⟩
exact ⟨_, ht, _, hx, by rwa [mem_preimage]⟩
· intro h _ hu _ hn
rcases h _ hn hu with ⟨_, ht, _, hx, hϕtx⟩
exact ⟨_, hϕtx, _, ht, _, hx, rfl⟩
/-- An element `y` is in the ω-limit set of `s` w.r.t. `f` if the
forward images of `s` frequently (w.r.t. `f`) intersect arbitrary
neighbourhoods of `y`. -/
theorem mem_omegaLimit_iff_frequently₂ (y : β) :
y ∈ ω f ϕ s ↔ ∀ n ∈ 𝓝 y, ∃ᶠ t in f, (ϕ t '' s ∩ n).Nonempty := by
simp_rw [mem_omegaLimit_iff_frequently, image_inter_nonempty_iff]
/-- An element `y` is in the ω-limit of `x` w.r.t. `f` if the forward
images of `x` frequently (w.r.t. `f`) falls within an arbitrary
neighbourhood of `y`. -/
theorem mem_omegaLimit_singleton_iff_map_cluster_point (x : α) (y : β) :
y ∈ ω f ϕ {x} ↔ MapClusterPt y f fun t ↦ ϕ t x := by
simp_rw [mem_omegaLimit_iff_frequently, mapClusterPt_iff, singleton_inter_nonempty, mem_preimage]
/-!
### Set operations and omega limits
-/
theorem omegaLimit_inter : ω f ϕ (s₁ ∩ s₂) ⊆ ω f ϕ s₁ ∩ ω f ϕ s₂ :=
subset_inter (omegaLimit_mono_right _ _ inter_subset_left)
(omegaLimit_mono_right _ _ inter_subset_right)
theorem omegaLimit_iInter (p : ι → Set α) : ω f ϕ (⋂ i, p i) ⊆ ⋂ i, ω f ϕ (p i) :=
subset_iInter fun _i ↦ omegaLimit_mono_right _ _ (iInter_subset _ _)
theorem omegaLimit_union : ω f ϕ (s₁ ∪ s₂) = ω f ϕ s₁ ∪ ω f ϕ s₂ := by
ext y; constructor
· simp only [mem_union, mem_omegaLimit_iff_frequently, union_inter_distrib_right, union_nonempty,
frequently_or_distrib]
contrapose!
simp only [not_frequently, not_nonempty_iff_eq_empty, ← subset_empty_iff]
rintro ⟨⟨n₁, hn₁, h₁⟩, ⟨n₂, hn₂, h₂⟩⟩
refine ⟨n₁ ∩ n₂, inter_mem hn₁ hn₂, h₁.mono fun t ↦ ?_, h₂.mono fun t ↦ ?_⟩
exacts [Subset.trans <| inter_subset_inter_right _ <| preimage_mono inter_subset_left,
Subset.trans <| inter_subset_inter_right _ <| preimage_mono inter_subset_right]
· rintro (hy | hy)
exacts [omegaLimit_mono_right _ _ subset_union_left hy,
omegaLimit_mono_right _ _ subset_union_right hy]
theorem omegaLimit_iUnion (p : ι → Set α) : ⋃ i, ω f ϕ (p i) ⊆ ω f ϕ (⋃ i, p i) := by
rw [iUnion_subset_iff]
exact fun i ↦ omegaLimit_mono_right _ _ (subset_iUnion _ _)
/-!
Different expressions for omega limits, useful for rewrites. In
particular, one may restrict the intersection to sets in `f` which are
subsets of some set `v` also in `f`.
-/
theorem omegaLimit_eq_iInter : ω f ϕ s = ⋂ u : ↥f.sets, closure (image2 ϕ u s) :=
biInter_eq_iInter _ _
theorem omegaLimit_eq_biInter_inter {v : Set τ} (hv : v ∈ f) :
ω f ϕ s = ⋂ u ∈ f, closure (image2 ϕ (u ∩ v) s) :=
Subset.antisymm (iInter₂_mono' fun u hu ↦ ⟨u ∩ v, inter_mem hu hv, Subset.rfl⟩)
(iInter₂_mono fun _u _hu ↦ closure_mono <| image2_subset inter_subset_left Subset.rfl)
theorem omegaLimit_eq_iInter_inter {v : Set τ} (hv : v ∈ f) :
ω f ϕ s = ⋂ u : ↥f.sets, closure (image2 ϕ (u ∩ v) s) := by
rw [omegaLimit_eq_biInter_inter _ _ _ hv]
apply biInter_eq_iInter
theorem omegaLimit_subset_closure_fw_image {u : Set τ} (hu : u ∈ f) :
ω f ϕ s ⊆ closure (image2 ϕ u s) := by
rw [omegaLimit_eq_iInter]
intro _ hx
rw [mem_iInter] at hx
exact hx ⟨u, hu⟩
/-!
### ω-limits and compactness
-/
/-- A set is eventually carried into any open neighbourhood of its ω-limit:
if `c` is a compact set such that `closure {ϕ t x | t ∈ v, x ∈ s} ⊆ c` for some `v ∈ f`
and `n` is an open neighbourhood of `ω f ϕ s`, then for some `u ∈ f` we have
`closure {ϕ t x | t ∈ u, x ∈ s} ⊆ n`. -/
theorem eventually_closure_subset_of_isCompact_absorbing_of_isOpen_of_omegaLimit_subset' {c : Set β}
(hc₁ : IsCompact c) (hc₂ : ∃ v ∈ f, closure (image2 ϕ v s) ⊆ c) {n : Set β} (hn₁ : IsOpen n)
(hn₂ : ω f ϕ s ⊆ n) : ∃ u ∈ f, closure (image2 ϕ u s) ⊆ n := by
rcases hc₂ with ⟨v, hv₁, hv₂⟩
let k := closure (image2 ϕ v s)
have hk : IsCompact (k \ n) :=
(hc₁.of_isClosed_subset isClosed_closure hv₂).diff hn₁
let j u := (closure (image2 ϕ (u ∩ v) s))ᶜ
have hj₁ : ∀ u ∈ f, IsOpen (j u) := fun _ _ ↦ isOpen_compl_iff.mpr isClosed_closure
have hj₂ : k \ n ⊆ ⋃ u ∈ f, j u := by
have : ⋃ u ∈ f, j u = ⋃ u : (↥f.sets), j u := biUnion_eq_iUnion _ _
rw [this, diff_subset_comm, diff_iUnion]
rw [omegaLimit_eq_iInter_inter _ _ _ hv₁] at hn₂
simp_rw [j, diff_compl]
rw [← inter_iInter]
exact Subset.trans inter_subset_right hn₂
rcases hk.elim_finite_subcover_image hj₁ hj₂ with ⟨g, hg₁ : ∀ u ∈ g, u ∈ f, hg₂, hg₃⟩
let w := (⋂ u ∈ g, u) ∩ v
have hw₂ : w ∈ f := by simpa [w, *]
have hw₃ : k \ n ⊆ (closure (image2 ϕ w s))ᶜ := by
apply Subset.trans hg₃
simp only [j, iUnion_subset_iff, compl_subset_compl]
intros u hu
mono
refine iInter_subset_of_subset u (iInter_subset_of_subset hu ?_)
all_goals exact Subset.rfl
have hw₄ : kᶜ ⊆ (closure (image2 ϕ w s))ᶜ := by
simp only [compl_subset_compl]
exact closure_mono (image2_subset inter_subset_right Subset.rfl)
have hnc : nᶜ ⊆ k \ n ∪ kᶜ := by rw [union_comm, ← inter_subset, diff_eq, inter_comm]
have hw : closure (image2 ϕ w s) ⊆ n :=
compl_subset_compl.mp (Subset.trans hnc (union_subset hw₃ hw₄))
exact ⟨_, hw₂, hw⟩
/-- A set is eventually carried into any open neighbourhood of its ω-limit:
if `c` is a compact set such that `closure {ϕ t x | t ∈ v, x ∈ s} ⊆ c` for some `v ∈ f`
and `n` is an open neighbourhood of `ω f ϕ s`, then for some `u ∈ f` we have
`closure {ϕ t x | t ∈ u, x ∈ s} ⊆ n`. -/
theorem eventually_closure_subset_of_isCompact_absorbing_of_isOpen_of_omegaLimit_subset [T2Space β]
{c : Set β} (hc₁ : IsCompact c) (hc₂ : ∀ᶠ t in f, MapsTo (ϕ t) s c) {n : Set β} (hn₁ : IsOpen n)
(hn₂ : ω f ϕ s ⊆ n) : ∃ u ∈ f, closure (image2 ϕ u s) ⊆ n :=
eventually_closure_subset_of_isCompact_absorbing_of_isOpen_of_omegaLimit_subset' f ϕ _ hc₁
⟨_, hc₂, closure_minimal (image2_subset_iff.2 fun _t ↦ id) hc₁.isClosed⟩ hn₁ hn₂
theorem eventually_mapsTo_of_isCompact_absorbing_of_isOpen_of_omegaLimit_subset [T2Space β]
{c : Set β} (hc₁ : IsCompact c) (hc₂ : ∀ᶠ t in f, MapsTo (ϕ t) s c) {n : Set β} (hn₁ : IsOpen n)
(hn₂ : ω f ϕ s ⊆ n) : ∀ᶠ t in f, MapsTo (ϕ t) s n := by
rcases eventually_closure_subset_of_isCompact_absorbing_of_isOpen_of_omegaLimit_subset f ϕ s hc₁
hc₂ hn₁ hn₂ with
⟨u, hu_mem, hu⟩
refine mem_of_superset hu_mem fun t ht x hx ↦ ?_
exact hu (subset_closure <| mem_image2_of_mem ht hx)
theorem eventually_closure_subset_of_isOpen_of_omegaLimit_subset [CompactSpace β] {v : Set β}
(hv₁ : IsOpen v) (hv₂ : ω f ϕ s ⊆ v) : ∃ u ∈ f, closure (image2 ϕ u s) ⊆ v :=
eventually_closure_subset_of_isCompact_absorbing_of_isOpen_of_omegaLimit_subset' _ _ _
isCompact_univ ⟨univ, univ_mem, subset_univ _⟩ hv₁ hv₂
theorem eventually_mapsTo_of_isOpen_of_omegaLimit_subset [CompactSpace β] {v : Set β}
(hv₁ : IsOpen v) (hv₂ : ω f ϕ s ⊆ v) : ∀ᶠ t in f, MapsTo (ϕ t) s v := by
rcases eventually_closure_subset_of_isOpen_of_omegaLimit_subset f ϕ s hv₁ hv₂ with ⟨u, hu_mem, hu⟩
refine mem_of_superset hu_mem fun t ht x hx ↦ ?_
exact hu (subset_closure <| mem_image2_of_mem ht hx)
/-- The ω-limit of a nonempty set w.r.t. a nontrivial filter is nonempty. -/
theorem nonempty_omegaLimit_of_isCompact_absorbing [NeBot f] {c : Set β} (hc₁ : IsCompact c)
(hc₂ : ∃ v ∈ f, closure (image2 ϕ v s) ⊆ c) (hs : s.Nonempty) : (ω f ϕ s).Nonempty := by
rcases hc₂ with ⟨v, hv₁, hv₂⟩
rw [omegaLimit_eq_iInter_inter _ _ _ hv₁]
apply IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed
· rintro ⟨u₁, hu₁⟩ ⟨u₂, hu₂⟩
use ⟨u₁ ∩ u₂, inter_mem hu₁ hu₂⟩
constructor
all_goals exact closure_mono (image2_subset (inter_subset_inter_left _ (by simp)) Subset.rfl)
· intro u
have hn : (image2 ϕ (u ∩ v) s).Nonempty :=
Nonempty.image2 (Filter.nonempty_of_mem (inter_mem u.prop hv₁)) hs
exact hn.mono subset_closure
· intro
apply hc₁.of_isClosed_subset isClosed_closure
calc
_ ⊆ closure (image2 ϕ v s) := closure_mono (image2_subset inter_subset_right Subset.rfl)
_ ⊆ c := hv₂
· exact fun _ ↦ isClosed_closure
theorem nonempty_omegaLimit [CompactSpace β] [NeBot f] (hs : s.Nonempty) : (ω f ϕ s).Nonempty :=
nonempty_omegaLimit_of_isCompact_absorbing _ _ _ isCompact_univ ⟨univ, univ_mem, subset_univ _⟩ hs
end omegaLimit
/-!
### ω-limits of flows by a monoid
-/
namespace Flow
variable {τ : Type*} [TopologicalSpace τ] [AddMonoid τ] [ContinuousAdd τ] {α : Type*}
[TopologicalSpace α] (f : Filter τ) (ϕ : Flow τ α) (s : Set α)
open omegaLimit
theorem isInvariant_omegaLimit (hf : ∀ t, Tendsto (t + ·) f f) : IsInvariant ϕ (ω f ϕ s) := by
refine fun t ↦ MapsTo.mono_right ?_ (omegaLimit_subset_of_tendsto ϕ s (hf t))
exact
mapsTo_omegaLimit _ (mapsTo_id _) (fun t' x ↦ (ϕ.map_add _ _ _).symm)
(continuous_const.flow ϕ continuous_id)
theorem omegaLimit_image_subset (t : τ) (ht : Tendsto (· + t) f f) :
ω f ϕ (ϕ t '' s) ⊆ ω f ϕ s := by
simp only [omegaLimit_image_eq, ← map_add]
exact omegaLimit_subset_of_tendsto ϕ s ht
end Flow
/-!
### ω-limits of flows by a group
-/
namespace Flow
variable {τ : Type*} [TopologicalSpace τ] [AddCommGroup τ] [TopologicalAddGroup τ] {α : Type*}
[TopologicalSpace α] (f : Filter τ) (ϕ : Flow τ α) (s : Set α)
open omegaLimit
/-- the ω-limit of a forward image of `s` is the same as the ω-limit of `s`. -/
@[simp]
theorem omegaLimit_image_eq (hf : ∀ t, Tendsto (· + t) f f) (t : τ) : ω f ϕ (ϕ t '' s) = ω f ϕ s :=
Subset.antisymm (omegaLimit_image_subset _ _ _ _ (hf t)) <|
calc
ω f ϕ s = ω f ϕ (ϕ (-t) '' (ϕ t '' s)) := by simp [image_image, ← map_add]
_ ⊆ ω f ϕ (ϕ t '' s) := omegaLimit_image_subset _ _ _ _ (hf _)
theorem omegaLimit_omegaLimit (hf : ∀ t, Tendsto (t + ·) f f) : ω f ϕ (ω f ϕ s) ⊆ ω f ϕ s := by
simp only [subset_def, mem_omegaLimit_iff_frequently₂, frequently_iff]
intro _ h
rintro n hn u hu
rcases mem_nhds_iff.mp hn with ⟨o, ho₁, ho₂, ho₃⟩
rcases h o (IsOpen.mem_nhds ho₂ ho₃) hu with ⟨t, _ht₁, ht₂⟩
have l₁ : (ω f ϕ s ∩ o).Nonempty :=
ht₂.mono
(inter_subset_inter_left _
((isInvariant_iff_image _ _).mp (isInvariant_omegaLimit _ _ _ hf) _))
have l₂ : (closure (image2 ϕ u s) ∩ o).Nonempty :=
l₁.mono fun b hb ↦ ⟨omegaLimit_subset_closure_fw_image _ _ _ hu hb.1, hb.2⟩
have l₃ : (o ∩ image2 ϕ u s).Nonempty := by
rcases l₂ with ⟨b, hb₁, hb₂⟩
exact mem_closure_iff_nhds.mp hb₁ o (IsOpen.mem_nhds ho₂ hb₂)
rcases l₃ with ⟨ϕra, ho, ⟨_, hr, _, ha, hϕra⟩⟩
exact ⟨_, hr, ϕra, ⟨_, ha, hϕra⟩, ho₁ ho⟩
end Flow
|
Dynamics\PeriodicPts.lean | /-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import Mathlib.Algebra.GroupPower.IterateHom
import Mathlib.Algebra.Ring.Divisibility.Basic
import Mathlib.Data.List.Cycle
import Mathlib.Data.Nat.Prime.Basic
import Mathlib.Data.PNat.Basic
import Mathlib.Dynamics.FixedPoints.Basic
/-!
# Periodic points
A point `x : α` is a periodic point of `f : α → α` of period `n` if `f^[n] x = x`.
## Main definitions
* `IsPeriodicPt f n x` : `x` is a periodic point of `f` of period `n`, i.e. `f^[n] x = x`.
We do not require `n > 0` in the definition.
* `ptsOfPeriod f n` : the set `{x | IsPeriodicPt f n x}`. Note that `n` is not required to
be the minimal period of `x`.
* `periodicPts f` : the set of all periodic points of `f`.
* `minimalPeriod f x` : the minimal period of a point `x` under an endomorphism `f` or zero
if `x` is not a periodic point of `f`.
* `orbit f x`: the cycle `[x, f x, f (f x), ...]` for a periodic point.
* `MulAction.period g x` : the minimal period of a point `x` under the multiplicative action of `g`;
an equivalent `AddAction.period g x` is defined for additive actions.
## Main statements
We provide “dot syntax”-style operations on terms of the form `h : IsPeriodicPt f n x` including
arithmetic operations on `n` and `h.map (hg : SemiconjBy g f f')`. We also prove that `f`
is bijective on each set `ptsOfPeriod f n` and on `periodicPts f`. Finally, we prove that `x`
is a periodic point of `f` of period `n` if and only if `minimalPeriod f x | n`.
## References
* https://en.wikipedia.org/wiki/Periodic_point
-/
open Set
namespace Function
open Function (Commute)
variable {α : Type*} {β : Type*} {f fa : α → α} {fb : β → β} {x y : α} {m n : ℕ}
/-- A point `x` is a periodic point of `f : α → α` of period `n` if `f^[n] x = x`.
Note that we do not require `0 < n` in this definition. Many theorems about periodic points
need this assumption. -/
def IsPeriodicPt (f : α → α) (n : ℕ) (x : α) :=
IsFixedPt f^[n] x
/-- A fixed point of `f` is a periodic point of `f` of any prescribed period. -/
theorem IsFixedPt.isPeriodicPt (hf : IsFixedPt f x) (n : ℕ) : IsPeriodicPt f n x :=
hf.iterate n
/-- For the identity map, all points are periodic. -/
theorem is_periodic_id (n : ℕ) (x : α) : IsPeriodicPt id n x :=
(isFixedPt_id x).isPeriodicPt n
/-- Any point is a periodic point of period `0`. -/
theorem isPeriodicPt_zero (f : α → α) (x : α) : IsPeriodicPt f 0 x :=
isFixedPt_id x
namespace IsPeriodicPt
instance [DecidableEq α] {f : α → α} {n : ℕ} {x : α} : Decidable (IsPeriodicPt f n x) :=
IsFixedPt.decidable
protected theorem isFixedPt (hf : IsPeriodicPt f n x) : IsFixedPt f^[n] x :=
hf
protected theorem map (hx : IsPeriodicPt fa n x) {g : α → β} (hg : Semiconj g fa fb) :
IsPeriodicPt fb n (g x) :=
IsFixedPt.map hx (hg.iterate_right n)
theorem apply_iterate (hx : IsPeriodicPt f n x) (m : ℕ) : IsPeriodicPt f n (f^[m] x) :=
hx.map <| Commute.iterate_self f m
protected theorem apply (hx : IsPeriodicPt f n x) : IsPeriodicPt f n (f x) :=
hx.apply_iterate 1
protected theorem add (hn : IsPeriodicPt f n x) (hm : IsPeriodicPt f m x) :
IsPeriodicPt f (n + m) x := by
rw [IsPeriodicPt, iterate_add]
exact hn.comp hm
theorem left_of_add (hn : IsPeriodicPt f (n + m) x) (hm : IsPeriodicPt f m x) :
IsPeriodicPt f n x := by
rw [IsPeriodicPt, iterate_add] at hn
exact hn.left_of_comp hm
theorem right_of_add (hn : IsPeriodicPt f (n + m) x) (hm : IsPeriodicPt f n x) :
IsPeriodicPt f m x := by
rw [add_comm] at hn
exact hn.left_of_add hm
protected theorem sub (hm : IsPeriodicPt f m x) (hn : IsPeriodicPt f n x) :
IsPeriodicPt f (m - n) x := by
rcases le_total n m with h | h
· refine left_of_add ?_ hn
rwa [tsub_add_cancel_of_le h]
· rw [tsub_eq_zero_iff_le.mpr h]
apply isPeriodicPt_zero
protected theorem mul_const (hm : IsPeriodicPt f m x) (n : ℕ) : IsPeriodicPt f (m * n) x := by
simp only [IsPeriodicPt, iterate_mul, hm.isFixedPt.iterate n]
protected theorem const_mul (hm : IsPeriodicPt f m x) (n : ℕ) : IsPeriodicPt f (n * m) x := by
simp only [mul_comm n, hm.mul_const n]
theorem trans_dvd (hm : IsPeriodicPt f m x) {n : ℕ} (hn : m ∣ n) : IsPeriodicPt f n x :=
let ⟨k, hk⟩ := hn
hk.symm ▸ hm.mul_const k
protected theorem iterate (hf : IsPeriodicPt f n x) (m : ℕ) : IsPeriodicPt f^[m] n x := by
rw [IsPeriodicPt, ← iterate_mul, mul_comm, iterate_mul]
exact hf.isFixedPt.iterate m
theorem comp {g : α → α} (hco : Commute f g) (hf : IsPeriodicPt f n x) (hg : IsPeriodicPt g n x) :
IsPeriodicPt (f ∘ g) n x := by
rw [IsPeriodicPt, hco.comp_iterate]
exact IsFixedPt.comp hf hg
theorem comp_lcm {g : α → α} (hco : Commute f g) (hf : IsPeriodicPt f m x)
(hg : IsPeriodicPt g n x) : IsPeriodicPt (f ∘ g) (Nat.lcm m n) x :=
(hf.trans_dvd <| Nat.dvd_lcm_left _ _).comp hco (hg.trans_dvd <| Nat.dvd_lcm_right _ _)
theorem left_of_comp {g : α → α} (hco : Commute f g) (hfg : IsPeriodicPt (f ∘ g) n x)
(hg : IsPeriodicPt g n x) : IsPeriodicPt f n x := by
rw [IsPeriodicPt, hco.comp_iterate] at hfg
exact hfg.left_of_comp hg
theorem iterate_mod_apply (h : IsPeriodicPt f n x) (m : ℕ) : f^[m % n] x = f^[m] x := by
conv_rhs => rw [← Nat.mod_add_div m n, iterate_add_apply, (h.mul_const _).eq]
protected theorem mod (hm : IsPeriodicPt f m x) (hn : IsPeriodicPt f n x) :
IsPeriodicPt f (m % n) x :=
(hn.iterate_mod_apply m).trans hm
protected theorem gcd (hm : IsPeriodicPt f m x) (hn : IsPeriodicPt f n x) :
IsPeriodicPt f (m.gcd n) x := by
revert hm hn
refine Nat.gcd.induction m n (fun n _ hn => ?_) fun m n _ ih hm hn => ?_
· rwa [Nat.gcd_zero_left]
· rw [Nat.gcd_rec]
exact ih (hn.mod hm) hm
/-- If `f` sends two periodic points `x` and `y` of the same positive period to the same point,
then `x = y`. For a similar statement about points of different periods see `eq_of_apply_eq`. -/
theorem eq_of_apply_eq_same (hx : IsPeriodicPt f n x) (hy : IsPeriodicPt f n y) (hn : 0 < n)
(h : f x = f y) : x = y := by
rw [← hx.eq, ← hy.eq, ← iterate_pred_comp_of_pos f hn, comp_apply, comp_apply, h]
/-- If `f` sends two periodic points `x` and `y` of positive periods to the same point,
then `x = y`. -/
theorem eq_of_apply_eq (hx : IsPeriodicPt f m x) (hy : IsPeriodicPt f n y) (hm : 0 < m) (hn : 0 < n)
(h : f x = f y) : x = y :=
(hx.mul_const n).eq_of_apply_eq_same (hy.const_mul m) (mul_pos hm hn) h
end IsPeriodicPt
/-- The set of periodic points of a given (possibly non-minimal) period. -/
def ptsOfPeriod (f : α → α) (n : ℕ) : Set α :=
{ x : α | IsPeriodicPt f n x }
@[simp]
theorem mem_ptsOfPeriod : x ∈ ptsOfPeriod f n ↔ IsPeriodicPt f n x :=
Iff.rfl
theorem Semiconj.mapsTo_ptsOfPeriod {g : α → β} (h : Semiconj g fa fb) (n : ℕ) :
MapsTo g (ptsOfPeriod fa n) (ptsOfPeriod fb n) :=
(h.iterate_right n).mapsTo_fixedPoints
theorem bijOn_ptsOfPeriod (f : α → α) {n : ℕ} (hn : 0 < n) :
BijOn f (ptsOfPeriod f n) (ptsOfPeriod f n) :=
⟨(Commute.refl f).mapsTo_ptsOfPeriod n, fun x hx y hy hxy => hx.eq_of_apply_eq_same hy hn hxy,
fun x hx =>
⟨f^[n.pred] x, hx.apply_iterate _, by
rw [← comp_apply (f := f), comp_iterate_pred_of_pos f hn, hx.eq]⟩⟩
theorem directed_ptsOfPeriod_pNat (f : α → α) : Directed (· ⊆ ·) fun n : ℕ+ => ptsOfPeriod f n :=
fun m n => ⟨m * n, fun _ hx => hx.mul_const n, fun _ hx => hx.const_mul m⟩
/-- The set of periodic points of a map `f : α → α`. -/
def periodicPts (f : α → α) : Set α :=
{ x : α | ∃ n > 0, IsPeriodicPt f n x }
theorem mk_mem_periodicPts (hn : 0 < n) (hx : IsPeriodicPt f n x) : x ∈ periodicPts f :=
⟨n, hn, hx⟩
theorem mem_periodicPts : x ∈ periodicPts f ↔ ∃ n > 0, IsPeriodicPt f n x :=
Iff.rfl
theorem isPeriodicPt_of_mem_periodicPts_of_isPeriodicPt_iterate (hx : x ∈ periodicPts f)
(hm : IsPeriodicPt f m (f^[n] x)) : IsPeriodicPt f m x := by
rcases hx with ⟨r, hr, hr'⟩
suffices n ≤ (n / r + 1) * r by
-- Porting note: convert used to unfold IsPeriodicPt
change _ = _
convert (hm.apply_iterate ((n / r + 1) * r - n)).eq <;>
rw [← iterate_add_apply, Nat.sub_add_cancel this, iterate_mul, (hr'.iterate _).eq]
rw [add_mul, one_mul]
exact (Nat.lt_div_mul_add hr).le
variable (f)
theorem bUnion_ptsOfPeriod : ⋃ n > 0, ptsOfPeriod f n = periodicPts f :=
Set.ext fun x => by simp [mem_periodicPts]
theorem iUnion_pNat_ptsOfPeriod : ⋃ n : ℕ+, ptsOfPeriod f n = periodicPts f :=
iSup_subtype.trans <| bUnion_ptsOfPeriod f
theorem bijOn_periodicPts : BijOn f (periodicPts f) (periodicPts f) :=
iUnion_pNat_ptsOfPeriod f ▸
bijOn_iUnion_of_directed (directed_ptsOfPeriod_pNat f) fun i => bijOn_ptsOfPeriod f i.pos
variable {f}
theorem Semiconj.mapsTo_periodicPts {g : α → β} (h : Semiconj g fa fb) :
MapsTo g (periodicPts fa) (periodicPts fb) := fun _ ⟨n, hn, hx⟩ => ⟨n, hn, hx.map h⟩
open scoped Classical
noncomputable section
/-- Minimal period of a point `x` under an endomorphism `f`. If `x` is not a periodic point of `f`,
then `minimalPeriod f x = 0`. -/
def minimalPeriod (f : α → α) (x : α) :=
if h : x ∈ periodicPts f then Nat.find h else 0
theorem isPeriodicPt_minimalPeriod (f : α → α) (x : α) : IsPeriodicPt f (minimalPeriod f x) x := by
delta minimalPeriod
split_ifs with hx
· exact (Nat.find_spec hx).2
· exact isPeriodicPt_zero f x
@[simp]
theorem iterate_minimalPeriod : f^[minimalPeriod f x] x = x :=
isPeriodicPt_minimalPeriod f x
@[simp]
theorem iterate_add_minimalPeriod_eq : f^[n + minimalPeriod f x] x = f^[n] x := by
rw [iterate_add_apply]
congr
exact isPeriodicPt_minimalPeriod f x
@[simp]
theorem iterate_mod_minimalPeriod_eq : f^[n % minimalPeriod f x] x = f^[n] x :=
(isPeriodicPt_minimalPeriod f x).iterate_mod_apply n
theorem minimalPeriod_pos_of_mem_periodicPts (hx : x ∈ periodicPts f) : 0 < minimalPeriod f x := by
simp only [minimalPeriod, dif_pos hx, (Nat.find_spec hx).1.lt]
theorem minimalPeriod_eq_zero_of_nmem_periodicPts (hx : x ∉ periodicPts f) :
minimalPeriod f x = 0 := by simp only [minimalPeriod, dif_neg hx]
theorem IsPeriodicPt.minimalPeriod_pos (hn : 0 < n) (hx : IsPeriodicPt f n x) :
0 < minimalPeriod f x :=
minimalPeriod_pos_of_mem_periodicPts <| mk_mem_periodicPts hn hx
theorem minimalPeriod_pos_iff_mem_periodicPts : 0 < minimalPeriod f x ↔ x ∈ periodicPts f :=
⟨not_imp_not.1 fun h => by simp only [minimalPeriod, dif_neg h, lt_irrefl 0, not_false_iff],
minimalPeriod_pos_of_mem_periodicPts⟩
theorem minimalPeriod_eq_zero_iff_nmem_periodicPts : minimalPeriod f x = 0 ↔ x ∉ periodicPts f := by
rw [← minimalPeriod_pos_iff_mem_periodicPts, not_lt, nonpos_iff_eq_zero]
theorem IsPeriodicPt.minimalPeriod_le (hn : 0 < n) (hx : IsPeriodicPt f n x) :
minimalPeriod f x ≤ n := by
rw [minimalPeriod, dif_pos (mk_mem_periodicPts hn hx)]
exact Nat.find_min' (mk_mem_periodicPts hn hx) ⟨hn, hx⟩
theorem minimalPeriod_apply_iterate (hx : x ∈ periodicPts f) (n : ℕ) :
minimalPeriod f (f^[n] x) = minimalPeriod f x := by
apply
(IsPeriodicPt.minimalPeriod_le (minimalPeriod_pos_of_mem_periodicPts hx) _).antisymm
((isPeriodicPt_of_mem_periodicPts_of_isPeriodicPt_iterate hx
(isPeriodicPt_minimalPeriod f _)).minimalPeriod_le
(minimalPeriod_pos_of_mem_periodicPts _))
· exact (isPeriodicPt_minimalPeriod f x).apply_iterate n
· rcases hx with ⟨m, hm, hx⟩
exact ⟨m, hm, hx.apply_iterate n⟩
theorem minimalPeriod_apply (hx : x ∈ periodicPts f) : minimalPeriod f (f x) = minimalPeriod f x :=
minimalPeriod_apply_iterate hx 1
theorem le_of_lt_minimalPeriod_of_iterate_eq {m n : ℕ} (hm : m < minimalPeriod f x)
(hmn : f^[m] x = f^[n] x) : m ≤ n := by
by_contra! hmn'
rw [← Nat.add_sub_of_le hmn'.le, add_comm, iterate_add_apply] at hmn
exact
((IsPeriodicPt.minimalPeriod_le (tsub_pos_of_lt hmn')
(isPeriodicPt_of_mem_periodicPts_of_isPeriodicPt_iterate
(minimalPeriod_pos_iff_mem_periodicPts.1 ((zero_le m).trans_lt hm)) hmn)).trans
(Nat.sub_le m n)).not_lt
hm
theorem iterate_injOn_Iio_minimalPeriod : (Iio <| minimalPeriod f x).InjOn (f^[·] x) :=
fun _m hm _n hn hmn ↦ (le_of_lt_minimalPeriod_of_iterate_eq hm hmn).antisymm
(le_of_lt_minimalPeriod_of_iterate_eq hn hmn.symm)
theorem iterate_eq_iterate_iff_of_lt_minimalPeriod {m n : ℕ} (hm : m < minimalPeriod f x)
(hn : n < minimalPeriod f x) : f^[m] x = f^[n] x ↔ m = n :=
iterate_injOn_Iio_minimalPeriod.eq_iff hm hn
@[simp] theorem minimalPeriod_id : minimalPeriod id x = 1 :=
((is_periodic_id _ _).minimalPeriod_le Nat.one_pos).antisymm
(Nat.succ_le_of_lt ((is_periodic_id _ _).minimalPeriod_pos Nat.one_pos))
theorem minimalPeriod_eq_one_iff_isFixedPt : minimalPeriod f x = 1 ↔ IsFixedPt f x := by
refine ⟨fun h => ?_, fun h => ?_⟩
· rw [← iterate_one f]
refine Function.IsPeriodicPt.isFixedPt ?_
rw [← h]
exact isPeriodicPt_minimalPeriod f x
· exact
((h.isPeriodicPt 1).minimalPeriod_le Nat.one_pos).antisymm
(Nat.succ_le_of_lt ((h.isPeriodicPt 1).minimalPeriod_pos Nat.one_pos))
theorem IsPeriodicPt.eq_zero_of_lt_minimalPeriod (hx : IsPeriodicPt f n x)
(hn : n < minimalPeriod f x) : n = 0 :=
Eq.symm <|
(eq_or_lt_of_le <| n.zero_le).resolve_right fun hn0 => not_lt.2 (hx.minimalPeriod_le hn0) hn
theorem not_isPeriodicPt_of_pos_of_lt_minimalPeriod :
∀ {n : ℕ} (_ : n ≠ 0) (_ : n < minimalPeriod f x), ¬IsPeriodicPt f n x
| 0, n0, _ => (n0 rfl).elim
| _ + 1, _, hn => fun hp => Nat.succ_ne_zero _ (hp.eq_zero_of_lt_minimalPeriod hn)
theorem IsPeriodicPt.minimalPeriod_dvd (hx : IsPeriodicPt f n x) : minimalPeriod f x ∣ n :=
(eq_or_lt_of_le <| n.zero_le).elim (fun hn0 => hn0 ▸ dvd_zero _) fun hn0 =>
-- Porting note: `Nat.dvd_iff_mod_eq_zero` gained explicit arguments
(Nat.dvd_iff_mod_eq_zero _ _).2 <|
(hx.mod <| isPeriodicPt_minimalPeriod f x).eq_zero_of_lt_minimalPeriod <|
Nat.mod_lt _ <| hx.minimalPeriod_pos hn0
theorem isPeriodicPt_iff_minimalPeriod_dvd : IsPeriodicPt f n x ↔ minimalPeriod f x ∣ n :=
⟨IsPeriodicPt.minimalPeriod_dvd, fun h => (isPeriodicPt_minimalPeriod f x).trans_dvd h⟩
open Nat
theorem minimalPeriod_eq_minimalPeriod_iff {g : β → β} {y : β} :
minimalPeriod f x = minimalPeriod g y ↔ ∀ n, IsPeriodicPt f n x ↔ IsPeriodicPt g n y := by
simp_rw [isPeriodicPt_iff_minimalPeriod_dvd, dvd_right_iff_eq]
theorem minimalPeriod_eq_prime {p : ℕ} [hp : Fact p.Prime] (hper : IsPeriodicPt f p x)
(hfix : ¬IsFixedPt f x) : minimalPeriod f x = p :=
(hp.out.eq_one_or_self_of_dvd _ hper.minimalPeriod_dvd).resolve_left
(mt minimalPeriod_eq_one_iff_isFixedPt.1 hfix)
theorem minimalPeriod_eq_prime_pow {p k : ℕ} [hp : Fact p.Prime] (hk : ¬IsPeriodicPt f (p ^ k) x)
(hk1 : IsPeriodicPt f (p ^ (k + 1)) x) : minimalPeriod f x = p ^ (k + 1) := by
apply Nat.eq_prime_pow_of_dvd_least_prime_pow hp.out <;>
rwa [← isPeriodicPt_iff_minimalPeriod_dvd]
theorem Commute.minimalPeriod_of_comp_dvd_lcm {g : α → α} (h : Commute f g) :
minimalPeriod (f ∘ g) x ∣ Nat.lcm (minimalPeriod f x) (minimalPeriod g x) := by
rw [← isPeriodicPt_iff_minimalPeriod_dvd]
exact (isPeriodicPt_minimalPeriod f x).comp_lcm h (isPeriodicPt_minimalPeriod g x)
theorem Commute.minimalPeriod_of_comp_dvd_mul {g : α → α} (h : Commute f g) :
minimalPeriod (f ∘ g) x ∣ minimalPeriod f x * minimalPeriod g x :=
dvd_trans h.minimalPeriod_of_comp_dvd_lcm (lcm_dvd_mul _ _)
theorem Commute.minimalPeriod_of_comp_eq_mul_of_coprime {g : α → α} (h : Commute f g)
(hco : Coprime (minimalPeriod f x) (minimalPeriod g x)) :
minimalPeriod (f ∘ g) x = minimalPeriod f x * minimalPeriod g x := by
apply h.minimalPeriod_of_comp_dvd_mul.antisymm
suffices
∀ {f g : α → α},
Commute f g →
Coprime (minimalPeriod f x) (minimalPeriod g x) →
minimalPeriod f x ∣ minimalPeriod (f ∘ g) x from
hco.mul_dvd_of_dvd_of_dvd (this h hco) (h.comp_eq.symm ▸ this h.symm hco.symm)
intro f g h hco
refine hco.dvd_of_dvd_mul_left (IsPeriodicPt.left_of_comp h ?_ ?_).minimalPeriod_dvd
· exact (isPeriodicPt_minimalPeriod _ _).const_mul _
· exact (isPeriodicPt_minimalPeriod _ _).mul_const _
private theorem minimalPeriod_iterate_eq_div_gcd_aux (h : 0 < gcd (minimalPeriod f x) n) :
minimalPeriod f^[n] x = minimalPeriod f x / Nat.gcd (minimalPeriod f x) n := by
apply Nat.dvd_antisymm
· apply IsPeriodicPt.minimalPeriod_dvd
rw [IsPeriodicPt, IsFixedPt, ← iterate_mul, ← Nat.mul_div_assoc _ (gcd_dvd_left _ _),
mul_comm, Nat.mul_div_assoc _ (gcd_dvd_right _ _), mul_comm, iterate_mul]
exact (isPeriodicPt_minimalPeriod f x).iterate _
· apply Coprime.dvd_of_dvd_mul_right (coprime_div_gcd_div_gcd h)
apply Nat.dvd_of_mul_dvd_mul_right h
rw [Nat.div_mul_cancel (gcd_dvd_left _ _), mul_assoc, Nat.div_mul_cancel (gcd_dvd_right _ _),
mul_comm]
apply IsPeriodicPt.minimalPeriod_dvd
rw [IsPeriodicPt, IsFixedPt, iterate_mul]
exact isPeriodicPt_minimalPeriod _ _
theorem minimalPeriod_iterate_eq_div_gcd (h : n ≠ 0) :
minimalPeriod f^[n] x = minimalPeriod f x / Nat.gcd (minimalPeriod f x) n :=
minimalPeriod_iterate_eq_div_gcd_aux <| gcd_pos_of_pos_right _ (Nat.pos_of_ne_zero h)
theorem minimalPeriod_iterate_eq_div_gcd' (h : x ∈ periodicPts f) :
minimalPeriod f^[n] x = minimalPeriod f x / Nat.gcd (minimalPeriod f x) n :=
minimalPeriod_iterate_eq_div_gcd_aux <|
gcd_pos_of_pos_left n (minimalPeriod_pos_iff_mem_periodicPts.mpr h)
/-- The orbit of a periodic point `x` of `f` is the cycle `[x, f x, f (f x), ...]`. Its length is
the minimal period of `x`.
If `x` is not a periodic point, then this is the empty (aka nil) cycle. -/
def periodicOrbit (f : α → α) (x : α) : Cycle α :=
(List.range (minimalPeriod f x)).map fun n => f^[n] x
/-- The definition of a periodic orbit, in terms of `List.map`. -/
theorem periodicOrbit_def (f : α → α) (x : α) :
periodicOrbit f x = (List.range (minimalPeriod f x)).map fun n => f^[n] x :=
rfl
/-- The definition of a periodic orbit, in terms of `Cycle.map`. -/
theorem periodicOrbit_eq_cycle_map (f : α → α) (x : α) :
periodicOrbit f x = (List.range (minimalPeriod f x) : Cycle ℕ).map fun n => f^[n] x :=
rfl
@[simp]
theorem periodicOrbit_length : (periodicOrbit f x).length = minimalPeriod f x := by
rw [periodicOrbit, Cycle.length_coe, List.length_map, List.length_range]
@[simp]
theorem periodicOrbit_eq_nil_iff_not_periodic_pt :
periodicOrbit f x = Cycle.nil ↔ x ∉ periodicPts f := by
simp only [periodicOrbit.eq_1, Cycle.coe_eq_nil, List.map_eq_nil, List.range_eq_nil]
exact minimalPeriod_eq_zero_iff_nmem_periodicPts
theorem periodicOrbit_eq_nil_of_not_periodic_pt (h : x ∉ periodicPts f) :
periodicOrbit f x = Cycle.nil :=
periodicOrbit_eq_nil_iff_not_periodic_pt.2 h
@[simp]
theorem mem_periodicOrbit_iff (hx : x ∈ periodicPts f) :
y ∈ periodicOrbit f x ↔ ∃ n, f^[n] x = y := by
simp only [periodicOrbit, Cycle.mem_coe_iff, List.mem_map, List.mem_range]
use fun ⟨a, _, ha'⟩ => ⟨a, ha'⟩
rintro ⟨n, rfl⟩
use n % minimalPeriod f x, mod_lt _ (minimalPeriod_pos_of_mem_periodicPts hx)
rw [iterate_mod_minimalPeriod_eq]
@[simp]
theorem iterate_mem_periodicOrbit (hx : x ∈ periodicPts f) (n : ℕ) :
f^[n] x ∈ periodicOrbit f x :=
(mem_periodicOrbit_iff hx).2 ⟨n, rfl⟩
@[simp]
theorem self_mem_periodicOrbit (hx : x ∈ periodicPts f) : x ∈ periodicOrbit f x :=
iterate_mem_periodicOrbit hx 0
theorem nodup_periodicOrbit : (periodicOrbit f x).Nodup := by
rw [periodicOrbit, Cycle.nodup_coe_iff, List.nodup_map_iff_inj_on (List.nodup_range _)]
intro m hm n hn hmn
rw [List.mem_range] at hm hn
rwa [iterate_eq_iterate_iff_of_lt_minimalPeriod hm hn] at hmn
theorem periodicOrbit_apply_iterate_eq (hx : x ∈ periodicPts f) (n : ℕ) :
periodicOrbit f (f^[n] x) = periodicOrbit f x :=
Eq.symm <| Cycle.coe_eq_coe.2 <| .intro n <|
List.ext_get (by simp [minimalPeriod_apply_iterate hx]) fun m _ _ ↦ by
simp [List.getElem_rotate, iterate_add_apply]
theorem periodicOrbit_apply_eq (hx : x ∈ periodicPts f) :
periodicOrbit f (f x) = periodicOrbit f x :=
periodicOrbit_apply_iterate_eq hx 1
theorem periodicOrbit_chain (r : α → α → Prop) {f : α → α} {x : α} :
(periodicOrbit f x).Chain r ↔ ∀ n < minimalPeriod f x, r (f^[n] x) (f^[n + 1] x) := by
by_cases hx : x ∈ periodicPts f
· have hx' := minimalPeriod_pos_of_mem_periodicPts hx
have hM := Nat.sub_add_cancel (succ_le_iff.2 hx')
rw [periodicOrbit, ← Cycle.map_coe, Cycle.chain_map, ← hM, Cycle.chain_range_succ]
refine ⟨?_, fun H => ⟨?_, fun m hm => H _ (hm.trans (Nat.lt_succ_self _))⟩⟩
· rintro ⟨hr, H⟩ n hn
cases' eq_or_lt_of_le (Nat.lt_succ_iff.1 hn) with hM' hM'
· rwa [hM', hM, iterate_minimalPeriod]
· exact H _ hM'
· rw [iterate_zero_apply]
nth_rw 3 [← @iterate_minimalPeriod α f x]
nth_rw 2 [← hM]
exact H _ (Nat.lt_succ_self _)
· rw [periodicOrbit_eq_nil_of_not_periodic_pt hx, minimalPeriod_eq_zero_of_nmem_periodicPts hx]
simp
theorem periodicOrbit_chain' (r : α → α → Prop) {f : α → α} {x : α} (hx : x ∈ periodicPts f) :
(periodicOrbit f x).Chain r ↔ ∀ n, r (f^[n] x) (f^[n + 1] x) := by
rw [periodicOrbit_chain r]
refine ⟨fun H n => ?_, fun H n _ => H n⟩
rw [iterate_succ_apply, ← iterate_mod_minimalPeriod_eq, ← iterate_mod_minimalPeriod_eq (n := n),
← iterate_succ_apply, minimalPeriod_apply hx]
exact H _ (mod_lt _ (minimalPeriod_pos_of_mem_periodicPts hx))
end -- noncomputable
end Function
namespace Function
variable {α β : Type*} {f : α → α} {g : β → β} {x : α × β} {a : α} {b : β} {m n : ℕ}
@[simp]
theorem isFixedPt_prod_map (x : α × β) :
IsFixedPt (Prod.map f g) x ↔ IsFixedPt f x.1 ∧ IsFixedPt g x.2 :=
Prod.ext_iff
@[simp]
theorem isPeriodicPt_prod_map (x : α × β) :
IsPeriodicPt (Prod.map f g) n x ↔ IsPeriodicPt f n x.1 ∧ IsPeriodicPt g n x.2 := by
simp [IsPeriodicPt]
theorem minimalPeriod_prod_map (f : α → α) (g : β → β) (x : α × β) :
minimalPeriod (Prod.map f g) x = (minimalPeriod f x.1).lcm (minimalPeriod g x.2) :=
eq_of_forall_dvd <| by cases x; simp [← isPeriodicPt_iff_minimalPeriod_dvd, Nat.lcm_dvd_iff]
theorem minimalPeriod_fst_dvd : minimalPeriod f x.1 ∣ minimalPeriod (Prod.map f g) x := by
rw [minimalPeriod_prod_map]; exact Nat.dvd_lcm_left _ _
theorem minimalPeriod_snd_dvd : minimalPeriod g x.2 ∣ minimalPeriod (Prod.map f g) x := by
rw [minimalPeriod_prod_map]; exact Nat.dvd_lcm_right _ _
end Function
namespace MulAction
open Function
universe u v
variable {α : Type v}
variable {G : Type u} [Group G] [MulAction G α]
variable {M : Type u} [Monoid M] [MulAction M α]
/--
The period of a multiplicative action of `g` on `a` is the smallest positive `n` such that
`g ^ n • a = a`, or `0` if such an `n` does not exist.
-/
@[to_additive "The period of an additive action of `g` on `a` is the smallest positive `n`
such that `(n • g) +ᵥ a = a`, or `0` if such an `n` does not exist."]
noncomputable def period (m : M) (a : α) : ℕ := minimalPeriod (fun x => m • x) a
/-- `MulAction.period m a` is definitionally equal to `Function.minimalPeriod (m • ·) a`. -/
@[to_additive "`AddAction.period m a` is definitionally equal to
`Function.minimalPeriod (m +ᵥ ·) a`"]
theorem period_eq_minimalPeriod {m : M} {a : α} :
MulAction.period m a = minimalPeriod (fun x => m • x) a := rfl
/-- `m ^ (period m a)` fixes `a`. -/
@[to_additive (attr := simp) "`(period m a) • m` fixes `a`."]
theorem pow_period_smul (m : M) (a : α) : m ^ (period m a) • a = a := by
rw [period_eq_minimalPeriod, ← smul_iterate_apply, iterate_minimalPeriod]
@[to_additive]
lemma isPeriodicPt_smul_iff {m : M} {a : α} {n : ℕ} :
IsPeriodicPt (m • ·) n a ↔ m ^ n • a = a := by
rw [← smul_iterate_apply, IsPeriodicPt, IsFixedPt]
/-! ### Multiples of `MulAction.period`
It is easy to convince oneself that if `g ^ n • a = a` (resp. `(n • g) +ᵥ a = a`),
then `n` must be a multiple of `period g a`.
This also holds for negative powers/multiples.
-/
@[to_additive]
theorem pow_smul_eq_iff_period_dvd {n : ℕ} {m : M} {a : α} :
m ^ n • a = a ↔ period m a ∣ n := by
rw [period_eq_minimalPeriod, ← isPeriodicPt_iff_minimalPeriod_dvd, isPeriodicPt_smul_iff]
@[to_additive]
theorem zpow_smul_eq_iff_period_dvd {j : ℤ} {g : G} {a : α} :
g ^ j • a = a ↔ (period g a : ℤ) ∣ j := by
rcases j with n | n
· rw [Int.ofNat_eq_coe, zpow_natCast, Int.natCast_dvd_natCast, pow_smul_eq_iff_period_dvd]
· rw [Int.negSucc_coe, zpow_neg, zpow_natCast, inv_smul_eq_iff, eq_comm, dvd_neg,
Int.natCast_dvd_natCast, pow_smul_eq_iff_period_dvd]
@[to_additive (attr := simp)]
theorem pow_mod_period_smul (n : ℕ) {m : M} {a : α} :
m ^ (n % period m a) • a = m ^ n • a := by
conv_rhs => rw [← Nat.mod_add_div n (period m a), pow_add, mul_smul,
pow_smul_eq_iff_period_dvd.mpr (dvd_mul_right _ _)]
@[to_additive (attr := simp)]
theorem zpow_mod_period_smul (j : ℤ) {g : G} {a : α} :
g ^ (j % (period g a : ℤ)) • a = g ^ j • a := by
conv_rhs => rw [← Int.emod_add_ediv j (period g a), zpow_add, mul_smul,
zpow_smul_eq_iff_period_dvd.mpr (dvd_mul_right _ _)]
@[to_additive (attr := simp)]
theorem pow_add_period_smul (n : ℕ) (m : M) (a : α) :
m ^ (n + period m a) • a = m ^ n • a := by
rw [← pow_mod_period_smul, Nat.add_mod_right, pow_mod_period_smul]
@[to_additive (attr := simp)]
theorem pow_period_add_smul (n : ℕ) (m : M) (a : α) :
m ^ (period m a + n) • a = m ^ n • a := by
rw [← pow_mod_period_smul, Nat.add_mod_left, pow_mod_period_smul]
@[to_additive (attr := simp)]
theorem zpow_add_period_smul (i : ℤ) (g : G) (a : α) :
g ^ (i + period g a) • a = g ^ i • a := by
rw [← zpow_mod_period_smul, Int.add_emod_self, zpow_mod_period_smul]
@[to_additive (attr := simp)]
theorem zpow_period_add_smul (i : ℤ) (g : G) (a : α) :
g ^ (period g a + i) • a = g ^ i • a := by
rw [← zpow_mod_period_smul, Int.add_emod_self_left, zpow_mod_period_smul]
variable {a : G} {b : α}
@[to_additive]
theorem pow_smul_eq_iff_minimalPeriod_dvd {n : ℕ} :
a ^ n • b = b ↔ minimalPeriod (a • ·) b ∣ n := by
rw [← period_eq_minimalPeriod, pow_smul_eq_iff_period_dvd]
@[to_additive]
theorem zpow_smul_eq_iff_minimalPeriod_dvd {n : ℤ} :
a ^ n • b = b ↔ (minimalPeriod (a • ·) b : ℤ) ∣ n := by
rw [← period_eq_minimalPeriod, zpow_smul_eq_iff_period_dvd]
variable (a b)
@[to_additive (attr := simp)]
theorem pow_smul_mod_minimalPeriod (n : ℕ) :
a ^ (n % minimalPeriod (a • ·) b) • b = a ^ n • b := by
rw [← period_eq_minimalPeriod, pow_mod_period_smul]
@[to_additive (attr := simp)]
theorem zpow_smul_mod_minimalPeriod (n : ℤ) :
a ^ (n % (minimalPeriod (a • ·) b : ℤ)) • b = a ^ n • b := by
rw [← period_eq_minimalPeriod, zpow_mod_period_smul]
end MulAction
|
Dynamics\BirkhoffSum\Average.lean | /-
Copyright (c) 2023 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Dynamics.BirkhoffSum.Basic
import Mathlib.Algebra.Module.Basic
/-!
# Birkhoff average
In this file we define `birkhoffAverage f g n x` to be
$$
\frac{1}{n}\sum_{k=0}^{n-1}g(f^{[k]}(x)),
$$
where `f : α → α` is a self-map on some type `α`,
`g : α → M` is a function from `α` to a module over a division semiring `R`,
and `R` is used to formalize division by `n` as `(n : R)⁻¹ • _`.
While we need an auxiliary division semiring `R` to define `birkhoffAverage`,
the definition does not depend on the choice of `R`,
see `birkhoffAverage_congr_ring`.
-/
open Finset
section birkhoffAverage
variable (R : Type*) {α M : Type*} [DivisionSemiring R] [AddCommMonoid M] [Module R M]
/-- The average value of `g` on the first `n` points of the orbit of `x` under `f`,
i.e. the Birkhoff sum `∑ k ∈ Finset.range n, g (f^[k] x)` divided by `n`.
This average appears in many ergodic theorems
which say that `(birkhoffAverage R f g · x)`
converges to the "space average" `⨍ x, g x ∂μ` as `n → ∞`.
We use an auxiliary `[DivisionSemiring R]` to define division by `n`.
However, the definition does not depend on the choice of `R`,
see `birkhoffAverage_congr_ring`. -/
def birkhoffAverage (f : α → α) (g : α → M) (n : ℕ) (x : α) : M := (n : R)⁻¹ • birkhoffSum f g n x
theorem birkhoffAverage_zero (f : α → α) (g : α → M) (x : α) :
birkhoffAverage R f g 0 x = 0 := by simp [birkhoffAverage]
@[simp] theorem birkhoffAverage_zero' (f : α → α) (g : α → M) : birkhoffAverage R f g 0 = 0 :=
funext <| birkhoffAverage_zero _ _ _
theorem birkhoffAverage_one (f : α → α) (g : α → M) (x : α) :
birkhoffAverage R f g 1 x = g x := by simp [birkhoffAverage]
@[simp]
theorem birkhoffAverage_one' (f : α → α) (g : α → M) : birkhoffAverage R f g 1 = g :=
funext <| birkhoffAverage_one R f g
theorem map_birkhoffAverage (S : Type*) {F N : Type*}
[DivisionSemiring S] [AddCommMonoid N] [Module S N] [FunLike F M N]
[AddMonoidHomClass F M N] (g' : F) (f : α → α) (g : α → M) (n : ℕ) (x : α) :
g' (birkhoffAverage R f g n x) = birkhoffAverage S f (g' ∘ g) n x := by
simp only [birkhoffAverage, map_inv_natCast_smul g' R S, map_birkhoffSum]
theorem birkhoffAverage_congr_ring (S : Type*) [DivisionSemiring S] [Module S M]
(f : α → α) (g : α → M) (n : ℕ) (x : α) :
birkhoffAverage R f g n x = birkhoffAverage S f g n x :=
map_birkhoffAverage R S (AddMonoidHom.id M) f g n x
theorem birkhoffAverage_congr_ring' (S : Type*) [DivisionSemiring S] [Module S M] :
birkhoffAverage (α := α) (M := M) R = birkhoffAverage S := by
ext; apply birkhoffAverage_congr_ring
theorem Function.IsFixedPt.birkhoffAverage_eq [CharZero R] {f : α → α} {x : α} (h : IsFixedPt f x)
(g : α → M) {n : ℕ} (hn : n ≠ 0) : birkhoffAverage R f g n x = g x := by
rw [birkhoffAverage, h.birkhoffSum_eq, ← Nat.cast_smul_eq_nsmul R, inv_smul_smul₀]
rwa [Nat.cast_ne_zero]
end birkhoffAverage
/-- Birkhoff average is "almost invariant" under `f`:
the difference between `birkhoffAverage R f g n (f x)` and `birkhoffAverage R f g n x`
is equal to `(n : R)⁻¹ • (g (f^[n] x) - g x)`. -/
theorem birkhoffAverage_apply_sub_birkhoffAverage {α M : Type*} (R : Type*) [DivisionRing R]
[AddCommGroup M] [Module R M] (f : α → α) (g : α → M) (n : ℕ) (x : α) :
birkhoffAverage R f g n (f x) - birkhoffAverage R f g n x =
(n : R)⁻¹ • (g (f^[n] x) - g x) := by
simp only [birkhoffAverage, birkhoffSum_apply_sub_birkhoffSum, ← smul_sub]
|
Dynamics\BirkhoffSum\Basic.lean | /-
Copyright (c) 2023 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Algebra.BigOperators.Group.Finset
import Mathlib.Dynamics.FixedPoints.Basic
/-!
# Birkhoff sums
In this file we define `birkhoffSum f g n x` to be the sum `∑ k ∈ Finset.range n, g (f^[k] x)`.
This sum (more precisely, the corresponding average `n⁻¹ • birkhoffSum f g n x`)
appears in various ergodic theorems
saying that these averages converge to the "space average" `⨍ x, g x ∂μ` in some sense.
See also `birkhoffAverage` defined in `Dynamics/BirkhoffSum/Average`.
-/
open Finset Function
section AddCommMonoid
variable {α M : Type*} [AddCommMonoid M]
/-- The sum of values of `g` on the first `n` points of the orbit of `x` under `f`. -/
def birkhoffSum (f : α → α) (g : α → M) (n : ℕ) (x : α) : M := ∑ k ∈ range n, g (f^[k] x)
theorem birkhoffSum_zero (f : α → α) (g : α → M) (x : α) : birkhoffSum f g 0 x = 0 :=
sum_range_zero _
@[simp]
theorem birkhoffSum_zero' (f : α → α) (g : α → M) : birkhoffSum f g 0 = 0 :=
funext <| birkhoffSum_zero _ _
theorem birkhoffSum_one (f : α → α) (g : α → M) (x : α) : birkhoffSum f g 1 x = g x :=
sum_range_one _
@[simp]
theorem birkhoffSum_one' (f : α → α) (g : α → M) : birkhoffSum f g 1 = g :=
funext <| birkhoffSum_one f g
theorem birkhoffSum_succ (f : α → α) (g : α → M) (n : ℕ) (x : α) :
birkhoffSum f g (n + 1) x = birkhoffSum f g n x + g (f^[n] x) :=
sum_range_succ _ _
theorem birkhoffSum_succ' (f : α → α) (g : α → M) (n : ℕ) (x : α) :
birkhoffSum f g (n + 1) x = g x + birkhoffSum f g n (f x) :=
(sum_range_succ' _ _).trans (add_comm _ _)
theorem birkhoffSum_add (f : α → α) (g : α → M) (m n : ℕ) (x : α) :
birkhoffSum f g (m + n) x = birkhoffSum f g m x + birkhoffSum f g n (f^[m] x) := by
simp_rw [birkhoffSum, sum_range_add, add_comm m, iterate_add_apply]
theorem Function.IsFixedPt.birkhoffSum_eq {f : α → α} {x : α} (h : IsFixedPt f x) (g : α → M)
(n : ℕ) : birkhoffSum f g n x = n • g x := by
simp [birkhoffSum, (h.iterate _).eq]
theorem map_birkhoffSum {F N : Type*} [AddCommMonoid N] [FunLike F M N] [AddMonoidHomClass F M N]
(g' : F) (f : α → α) (g : α → M) (n : ℕ) (x : α) :
g' (birkhoffSum f g n x) = birkhoffSum f (g' ∘ g) n x :=
map_sum g' _ _
end AddCommMonoid
section AddCommGroup
variable {α G : Type*} [AddCommGroup G]
/-- Birkhoff sum is "almost invariant" under `f`:
the difference between `birkhoffSum f g n (f x)` and `birkhoffSum f g n x`
is equal to `g (f^[n] x) - g x`. -/
theorem birkhoffSum_apply_sub_birkhoffSum (f : α → α) (g : α → G) (n : ℕ) (x : α) :
birkhoffSum f g n (f x) - birkhoffSum f g n x = g (f^[n] x) - g x := by
rw [← sub_eq_iff_eq_add.2 (birkhoffSum_succ f g n x),
← sub_eq_iff_eq_add.2 (birkhoffSum_succ' f g n x),
← sub_add, ← sub_add, sub_add_comm]
end AddCommGroup
|
Dynamics\BirkhoffSum\NormedSpace.lean | /-
Copyright (c) 2023 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.RCLike.Basic
import Mathlib.Dynamics.BirkhoffSum.Average
/-!
# Birkhoff average in a normed space
In this file we prove some lemmas about the Birkhoff average (`birkhoffAverage`)
of a function which takes values in a normed space over `ℝ` or `ℂ`.
At the time of writing, all lemmas in this file
are motivated by the proof of the von Neumann Mean Ergodic Theorem,
see `LinearIsometry.tendsto_birkhoffAverage_orthogonalProjection`.
-/
open Function Set Filter
open scoped Topology ENNReal Uniformity
section
variable {α E : Type*}
/-- The Birkhoff averages of a function `g` over the orbit of a fixed point `x` of `f`
tend to `g x` as `N → ∞`. In fact, they are equal to `g x` for all `N ≠ 0`,
see `Function.IsFixedPt.birkhoffAverage_eq`.
TODO: add a version for a periodic orbit. -/
theorem Function.IsFixedPt.tendsto_birkhoffAverage
(R : Type*) [DivisionSemiring R] [CharZero R]
[AddCommMonoid E] [TopologicalSpace E] [Module R E]
{f : α → α} {x : α} (h : f.IsFixedPt x) (g : α → E) :
Tendsto (birkhoffAverage R f g · x) atTop (𝓝 (g x)) :=
tendsto_const_nhds.congr' <| (eventually_ne_atTop 0).mono fun _n hn ↦
(h.birkhoffAverage_eq R g hn).symm
variable [NormedAddCommGroup E]
theorem dist_birkhoffSum_apply_birkhoffSum (f : α → α) (g : α → E) (n : ℕ) (x : α) :
dist (birkhoffSum f g n (f x)) (birkhoffSum f g n x) = dist (g (f^[n] x)) (g x) := by
simp only [dist_eq_norm, birkhoffSum_apply_sub_birkhoffSum]
theorem dist_birkhoffSum_birkhoffSum_le (f : α → α) (g : α → E) (n : ℕ) (x y : α) :
dist (birkhoffSum f g n x) (birkhoffSum f g n y) ≤
∑ k ∈ Finset.range n, dist (g (f^[k] x)) (g (f^[k] y)) :=
dist_sum_sum_le _ _ _
variable (𝕜 : Type*) [RCLike 𝕜] [Module 𝕜 E] [BoundedSMul 𝕜 E]
theorem dist_birkhoffAverage_birkhoffAverage (f : α → α) (g : α → E) (n : ℕ) (x y : α) :
dist (birkhoffAverage 𝕜 f g n x) (birkhoffAverage 𝕜 f g n y) =
dist (birkhoffSum f g n x) (birkhoffSum f g n y) / n := by
simp [birkhoffAverage, dist_smul₀, div_eq_inv_mul]
theorem dist_birkhoffAverage_birkhoffAverage_le (f : α → α) (g : α → E) (n : ℕ) (x y : α) :
dist (birkhoffAverage 𝕜 f g n x) (birkhoffAverage 𝕜 f g n y) ≤
(∑ k ∈ Finset.range n, dist (g (f^[k] x)) (g (f^[k] y))) / n :=
(dist_birkhoffAverage_birkhoffAverage _ _ _ _ _ _).trans_le <| by
gcongr; apply dist_birkhoffSum_birkhoffSum_le
theorem dist_birkhoffAverage_apply_birkhoffAverage (f : α → α) (g : α → E) (n : ℕ) (x : α) :
dist (birkhoffAverage 𝕜 f g n (f x)) (birkhoffAverage 𝕜 f g n x) =
dist (g (f^[n] x)) (g x) / n := by
simp [dist_birkhoffAverage_birkhoffAverage, dist_birkhoffSum_apply_birkhoffSum]
/-- If a function `g` is bounded along the positive orbit of `x` under `f`,
then the difference between Birkhoff averages of `g`
along the orbit of `f x` and along the orbit of `x`
tends to zero.
See also `tendsto_birkhoffAverage_apply_sub_birkhoffAverage'`. -/
theorem tendsto_birkhoffAverage_apply_sub_birkhoffAverage {f : α → α} {g : α → E} {x : α}
(h : Bornology.IsBounded (range (g <| f^[·] x))) :
Tendsto (fun n ↦ birkhoffAverage 𝕜 f g n (f x) - birkhoffAverage 𝕜 f g n x) atTop (𝓝 0) := by
rcases Metric.isBounded_range_iff.1 h with ⟨C, hC⟩
have : Tendsto (fun n : ℕ ↦ C / n) atTop (𝓝 0) :=
tendsto_const_nhds.div_atTop tendsto_natCast_atTop_atTop
refine squeeze_zero_norm (fun n ↦ ?_) this
rw [← dist_eq_norm, dist_birkhoffAverage_apply_birkhoffAverage]
gcongr
exact hC n 0
/-- If a function `g` is bounded,
then the difference between Birkhoff averages of `g`
along the orbit of `f x` and along the orbit of `x`
tends to zero.
See also `tendsto_birkhoffAverage_apply_sub_birkhoffAverage`. -/
theorem tendsto_birkhoffAverage_apply_sub_birkhoffAverage' {g : α → E}
(h : Bornology.IsBounded (range g)) (f : α → α) (x : α) :
Tendsto (fun n ↦ birkhoffAverage 𝕜 f g n (f x) - birkhoffAverage 𝕜 f g n x) atTop (𝓝 0) :=
tendsto_birkhoffAverage_apply_sub_birkhoffAverage _ <| h.subset <| range_comp_subset_range _ _
end
variable (𝕜 : Type*) {X E : Type*}
[PseudoEMetricSpace X] [RCLike 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E]
{f : X → X} {g : X → E} {l : X → E}
/-- If `f` is a non-strictly contracting map (i.e., it is Lipschitz with constant `1`)
and `g` is a uniformly continuous, then the Birkhoff averages of `g` along orbits of `f`
is a uniformly equicontinuous family of functions. -/
theorem uniformEquicontinuous_birkhoffAverage (hf : LipschitzWith 1 f) (hg : UniformContinuous g) :
UniformEquicontinuous (birkhoffAverage 𝕜 f g) := by
refine Metric.uniformity_basis_dist_le.uniformEquicontinuous_iff_right.2 fun ε hε ↦ ?_
rcases (uniformity_basis_edist_le.uniformContinuous_iff Metric.uniformity_basis_dist_le).1 hg ε hε
with ⟨δ, hδ₀, hδε⟩
refine mem_uniformity_edist.2 ⟨δ, hδ₀, fun {x y} h n ↦ ?_⟩
calc
dist (birkhoffAverage 𝕜 f g n x) (birkhoffAverage 𝕜 f g n y)
≤ (∑ k ∈ Finset.range n, dist (g (f^[k] x)) (g (f^[k] y))) / n :=
dist_birkhoffAverage_birkhoffAverage_le ..
_ ≤ (∑ _k ∈ Finset.range n, ε) / n := by
gcongr
refine hδε _ _ ?_
simpa using (hf.iterate _).edist_le_mul_of_le h.le
_ = n * ε / n := by simp
_ ≤ ε := by
rcases eq_or_ne n 0 with hn | hn <;> field_simp [hn, hε.le, mul_div_cancel_left₀]
/-- If `f : X → X` is a non-strictly contracting map (i.e., it is Lipschitz with constant `1`),
`g : X → E` is a uniformly continuous, and `l : X → E` is a continuous function,
then the set of points `x`
such that the Birkhoff average of `g` along the orbit of `x` tends to `l x`
is a closed set. -/
theorem isClosed_setOf_tendsto_birkhoffAverage
(hf : LipschitzWith 1 f) (hg : UniformContinuous g) (hl : Continuous l) :
IsClosed {x | Tendsto (birkhoffAverage 𝕜 f g · x) atTop (𝓝 (l x))} :=
(uniformEquicontinuous_birkhoffAverage 𝕜 hf hg).equicontinuous.isClosed_setOf_tendsto hl
|
Dynamics\Circle\RotationNumber\TranslationNumber.lean | /-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import Mathlib.Algebra.GroupPower.IterateHom
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Order.Iterate
import Mathlib.Order.SemiconjSup
import Mathlib.Topology.Order.MonotoneContinuity
/-!
# Translation number of a monotone real map that commutes with `x ↦ x + 1`
Let `f : ℝ → ℝ` be a monotone map such that `f (x + 1) = f x + 1` for all `x`. Then the limit
$$
\tau(f)=\lim_{n\to\infty}{f^n(x)-x}{n}
$$
exists and does not depend on `x`. This number is called the *translation number* of `f`.
Different authors use different notation for this number: `τ`, `ρ`, `rot`, etc
In this file we define a structure `CircleDeg1Lift` for bundled maps with these properties, define
translation number of `f : CircleDeg1Lift`, prove some estimates relating `f^n(x)-x` to `τ(f)`. In
case of a continuous map `f` we also prove that `f` admits a point `x` such that `f^n(x)=x+m` if and
only if `τ(f)=m/n`.
Maps of this type naturally appear as lifts of orientation preserving circle homeomorphisms. More
precisely, let `f` be an orientation preserving homeomorphism of the circle $S^1=ℝ/ℤ$, and
consider a real number `a` such that
`⟦a⟧ = f 0`, where `⟦⟧` means the natural projection `ℝ → ℝ/ℤ`. Then there exists a unique
continuous function `F : ℝ → ℝ` such that `F 0 = a` and `⟦F x⟧ = f ⟦x⟧` for all `x` (this fact is
not formalized yet). This function is strictly monotone, continuous, and satisfies
`F (x + 1) = F x + 1`. The number `⟦τ F⟧ : ℝ / ℤ` is called the *rotation number* of `f`.
It does not depend on the choice of `a`.
## Main definitions
* `CircleDeg1Lift`: a monotone map `f : ℝ → ℝ` such that `f (x + 1) = f x + 1` for all `x`;
the type `CircleDeg1Lift` is equipped with `Lattice` and `Monoid` structures; the
multiplication is given by composition: `(f * g) x = f (g x)`.
* `CircleDeg1Lift.translationNumber`: translation number of `f : CircleDeg1Lift`.
## Main statements
We prove the following properties of `CircleDeg1Lift.translationNumber`.
* `CircleDeg1Lift.translationNumber_eq_of_dist_bounded`: if the distance between `(f^n) 0`
and `(g^n) 0` is bounded from above uniformly in `n : ℕ`, then `f` and `g` have equal
translation numbers.
* `CircleDeg1Lift.translationNumber_eq_of_semiconjBy`: if two `CircleDeg1Lift` maps `f`, `g`
are semiconjugate by a `CircleDeg1Lift` map, then `τ f = τ g`.
* `CircleDeg1Lift.translationNumber_units_inv`: if `f` is an invertible `CircleDeg1Lift` map
(equivalently, `f` is a lift of an orientation-preserving circle homeomorphism), then
the translation number of `f⁻¹` is the negative of the translation number of `f`.
* `CircleDeg1Lift.translationNumber_mul_of_commute`: if `f` and `g` commute, then
`τ (f * g) = τ f + τ g`.
* `CircleDeg1Lift.translationNumber_eq_rat_iff`: the translation number of `f` is equal to
a rational number `m / n` if and only if `(f^n) x = x + m` for some `x`.
* `CircleDeg1Lift.semiconj_of_bijective_of_translationNumber_eq`: if `f` and `g` are two
bijective `CircleDeg1Lift` maps and their translation numbers are equal, then these
maps are semiconjugate to each other.
* `CircleDeg1Lift.semiconj_of_group_action_of_forall_translationNumber_eq`: let `f₁` and `f₂` be
two actions of a group `G` on the circle by degree 1 maps (formally, `f₁` and `f₂` are two
homomorphisms from `G →* CircleDeg1Lift`). If the translation numbers of `f₁ g` and `f₂ g` are
equal to each other for all `g : G`, then these two actions are semiconjugate by some
`F : CircleDeg1Lift`. This is a version of Proposition 5.4 from [Étienne Ghys, Groupes
d'homeomorphismes du cercle et cohomologie bornee][ghys87:groupes].
## Notation
We use a local notation `τ` for the translation number of `f : CircleDeg1Lift`.
## Implementation notes
We define the translation number of `f : CircleDeg1Lift` to be the limit of the sequence
`(f ^ (2 ^ n)) 0 / (2 ^ n)`, then prove that `((f ^ n) x - x) / n` tends to this number for any `x`.
This way it is much easier to prove that the limit exists and basic properties of the limit.
We define translation number for a wider class of maps `f : ℝ → ℝ` instead of lifts of orientation
preserving circle homeomorphisms for two reasons:
* non-strictly monotone circle self-maps with discontinuities naturally appear as Poincaré maps
for some flows on the two-torus (e.g., one can take a constant flow and glue in a few Cherry
cells);
* definition and some basic properties still work for this class.
## References
* [Étienne Ghys, Groupes d'homeomorphismes du cercle et cohomologie bornee][ghys87:groupes]
## TODO
Here are some short-term goals.
* Introduce a structure or a typeclass for lifts of circle homeomorphisms. We use
`Units CircleDeg1Lift` for now, but it's better to have a dedicated type (or a typeclass?).
* Prove that the `SemiconjBy` relation on circle homeomorphisms is an equivalence relation.
* Introduce `ConditionallyCompleteLattice` structure, use it in the proof of
`CircleDeg1Lift.semiconj_of_group_action_of_forall_translationNumber_eq`.
* Prove that the orbits of the irrational rotation are dense in the circle. Deduce that a
homeomorphism with an irrational rotation is semiconjugate to the corresponding irrational
translation by a continuous `CircleDeg1Lift`.
## Tags
circle homeomorphism, rotation number
-/
open Filter Set Int Topology
open Function hiding Commute
/-!
### Definition and monoid structure
-/
/-- A lift of a monotone degree one map `S¹ → S¹`. -/
structure CircleDeg1Lift extends ℝ →o ℝ : Type where
map_add_one' : ∀ x, toFun (x + 1) = toFun x + 1
namespace CircleDeg1Lift
instance : FunLike CircleDeg1Lift ℝ ℝ where
coe f := f.toFun
coe_injective' | ⟨⟨_, _⟩, _⟩, ⟨⟨_, _⟩, _⟩, rfl => rfl
instance : OrderHomClass CircleDeg1Lift ℝ ℝ where
map_rel f _ _ h := f.monotone' h
@[simp] theorem coe_mk (f h) : ⇑(mk f h) = f := rfl
variable (f g : CircleDeg1Lift)
@[simp] theorem coe_toOrderHom : ⇑f.toOrderHom = f := rfl
protected theorem monotone : Monotone f := f.monotone'
@[mono] theorem mono {x y} (h : x ≤ y) : f x ≤ f y := f.monotone h
theorem strictMono_iff_injective : StrictMono f ↔ Injective f :=
f.monotone.strictMono_iff_injective
@[simp]
theorem map_add_one : ∀ x, f (x + 1) = f x + 1 :=
f.map_add_one'
@[simp]
theorem map_one_add (x : ℝ) : f (1 + x) = 1 + f x := by rw [add_comm, map_add_one, add_comm 1]
@[ext]
theorem ext ⦃f g : CircleDeg1Lift⦄ (h : ∀ x, f x = g x) : f = g :=
DFunLike.ext f g h
instance : Monoid CircleDeg1Lift where
mul f g :=
{ toOrderHom := f.1.comp g.1
map_add_one' := fun x => by simp [map_add_one] }
one := ⟨.id, fun _ => rfl⟩
mul_one f := rfl
one_mul f := rfl
mul_assoc f₁ f₂ f₃ := DFunLike.coe_injective rfl
instance : Inhabited CircleDeg1Lift := ⟨1⟩
@[simp]
theorem coe_mul : ⇑(f * g) = f ∘ g :=
rfl
theorem mul_apply (x) : (f * g) x = f (g x) :=
rfl
@[simp]
theorem coe_one : ⇑(1 : CircleDeg1Lift) = id :=
rfl
instance unitsHasCoeToFun : CoeFun CircleDeg1Liftˣ fun _ => ℝ → ℝ :=
⟨fun f => ⇑(f : CircleDeg1Lift)⟩
@[simp]
theorem units_inv_apply_apply (f : CircleDeg1Liftˣ) (x : ℝ) :
(f⁻¹ : CircleDeg1Liftˣ) (f x) = x := by simp only [← mul_apply, f.inv_mul, coe_one, id]
@[simp]
theorem units_apply_inv_apply (f : CircleDeg1Liftˣ) (x : ℝ) :
f ((f⁻¹ : CircleDeg1Liftˣ) x) = x := by simp only [← mul_apply, f.mul_inv, coe_one, id]
/-- If a lift of a circle map is bijective, then it is an order automorphism of the line. -/
def toOrderIso : CircleDeg1Liftˣ →* ℝ ≃o ℝ where
toFun f :=
{ toFun := f
invFun := ⇑f⁻¹
left_inv := units_inv_apply_apply f
right_inv := units_apply_inv_apply f
map_rel_iff' := ⟨fun h => by simpa using mono (↑f⁻¹) h, mono f⟩ }
map_one' := rfl
map_mul' f g := rfl
@[simp]
theorem coe_toOrderIso (f : CircleDeg1Liftˣ) : ⇑(toOrderIso f) = f :=
rfl
@[simp]
theorem coe_toOrderIso_symm (f : CircleDeg1Liftˣ) :
⇑(toOrderIso f).symm = (f⁻¹ : CircleDeg1Liftˣ) :=
rfl
@[simp]
theorem coe_toOrderIso_inv (f : CircleDeg1Liftˣ) : ⇑(toOrderIso f)⁻¹ = (f⁻¹ : CircleDeg1Liftˣ) :=
rfl
theorem isUnit_iff_bijective {f : CircleDeg1Lift} : IsUnit f ↔ Bijective f :=
⟨fun ⟨u, h⟩ => h ▸ (toOrderIso u).bijective, fun h =>
Units.isUnit
{ val := f
inv :=
{ toFun := (Equiv.ofBijective f h).symm
monotone' := fun x y hxy =>
(f.strictMono_iff_injective.2 h.1).le_iff_le.1
(by simp only [Equiv.ofBijective_apply_symm_apply f h, hxy])
map_add_one' := fun x =>
h.1 <| by simp only [Equiv.ofBijective_apply_symm_apply f, f.map_add_one] }
val_inv := ext <| Equiv.ofBijective_apply_symm_apply f h
inv_val := ext <| Equiv.ofBijective_symm_apply_apply f h }⟩
theorem coe_pow : ∀ n : ℕ, ⇑(f ^ n) = f^[n]
| 0 => rfl
| n + 1 => by
ext x
simp [coe_pow n, pow_succ]
theorem semiconjBy_iff_semiconj {f g₁ g₂ : CircleDeg1Lift} :
SemiconjBy f g₁ g₂ ↔ Semiconj f g₁ g₂ :=
CircleDeg1Lift.ext_iff
theorem commute_iff_commute {f g : CircleDeg1Lift} : Commute f g ↔ Function.Commute f g :=
CircleDeg1Lift.ext_iff
/-!
### Translate by a constant
-/
/-- The map `y ↦ x + y` as a `CircleDeg1Lift`. More precisely, we define a homomorphism from
`Multiplicative ℝ` to `CircleDeg1Liftˣ`, so the translation by `x` is
`translation (Multiplicative.ofAdd x)`. -/
def translate : Multiplicative ℝ →* CircleDeg1Liftˣ := MonoidHom.toHomUnits <|
{ toFun := fun x =>
⟨⟨fun y => Multiplicative.toAdd x + y, fun _ _ h => add_le_add_left h _⟩, fun _ =>
(add_assoc _ _ _).symm⟩
map_one' := ext <| zero_add
map_mul' := fun _ _ => ext <| add_assoc _ _ }
@[simp]
theorem translate_apply (x y : ℝ) : translate (Multiplicative.ofAdd x) y = x + y :=
rfl
@[simp]
theorem translate_inv_apply (x y : ℝ) : (translate <| Multiplicative.ofAdd x)⁻¹ y = -x + y :=
rfl
@[simp]
theorem translate_zpow (x : ℝ) (n : ℤ) :
translate (Multiplicative.ofAdd x) ^ n = translate (Multiplicative.ofAdd <| ↑n * x) := by
simp only [← zsmul_eq_mul, ofAdd_zsmul, MonoidHom.map_zpow]
@[simp]
theorem translate_pow (x : ℝ) (n : ℕ) :
translate (Multiplicative.ofAdd x) ^ n = translate (Multiplicative.ofAdd <| ↑n * x) :=
translate_zpow x n
@[simp]
theorem translate_iterate (x : ℝ) (n : ℕ) :
(translate (Multiplicative.ofAdd x))^[n] = translate (Multiplicative.ofAdd <| ↑n * x) := by
rw [← coe_pow, ← Units.val_pow_eq_pow_val, translate_pow]
/-!
### Commutativity with integer translations
In this section we prove that `f` commutes with translations by an integer number.
First we formulate these statements (for a natural or an integer number,
addition on the left or on the right, addition or subtraction) using `Function.Commute`,
then reformulate as `simp` lemmas `map_int_add` etc.
-/
theorem commute_nat_add (n : ℕ) : Function.Commute f (n + ·) := by
simpa only [nsmul_one, add_left_iterate] using Function.Commute.iterate_right f.map_one_add n
theorem commute_add_nat (n : ℕ) : Function.Commute f (· + n) := by
simp only [add_comm _ (n : ℝ), f.commute_nat_add n]
theorem commute_sub_nat (n : ℕ) : Function.Commute f (· - n) := by
simpa only [sub_eq_add_neg] using
(f.commute_add_nat n).inverses_right (Equiv.addRight _).right_inv (Equiv.addRight _).left_inv
theorem commute_add_int : ∀ n : ℤ, Function.Commute f (· + n)
| (n : ℕ) => f.commute_add_nat n
| -[n+1] => by simpa [sub_eq_add_neg] using f.commute_sub_nat (n + 1)
theorem commute_int_add (n : ℤ) : Function.Commute f (n + ·) := by
simpa only [add_comm _ (n : ℝ)] using f.commute_add_int n
theorem commute_sub_int (n : ℤ) : Function.Commute f (· - n) := by
simpa only [sub_eq_add_neg] using
(f.commute_add_int n).inverses_right (Equiv.addRight _).right_inv (Equiv.addRight _).left_inv
@[simp]
theorem map_int_add (m : ℤ) (x : ℝ) : f (m + x) = m + f x :=
f.commute_int_add m x
@[simp]
theorem map_add_int (x : ℝ) (m : ℤ) : f (x + m) = f x + m :=
f.commute_add_int m x
@[simp]
theorem map_sub_int (x : ℝ) (n : ℤ) : f (x - n) = f x - n :=
f.commute_sub_int n x
@[simp]
theorem map_add_nat (x : ℝ) (n : ℕ) : f (x + n) = f x + n :=
f.map_add_int x n
@[simp]
theorem map_nat_add (n : ℕ) (x : ℝ) : f (n + x) = n + f x :=
f.map_int_add n x
@[simp]
theorem map_sub_nat (x : ℝ) (n : ℕ) : f (x - n) = f x - n :=
f.map_sub_int x n
theorem map_int_of_map_zero (n : ℤ) : f n = f 0 + n := by rw [← f.map_add_int, zero_add]
@[simp]
theorem map_fract_sub_fract_eq (x : ℝ) : f (fract x) - fract x = f x - x := by
rw [Int.fract, f.map_sub_int, sub_sub_sub_cancel_right]
/-!
### Pointwise order on circle maps
-/
/-- Monotone circle maps form a lattice with respect to the pointwise order -/
noncomputable instance : Lattice CircleDeg1Lift where
sup f g :=
{ toFun := fun x => max (f x) (g x)
monotone' := fun x y h => max_le_max (f.mono h) (g.mono h)
-- TODO: generalize to `Monotone.max`
map_add_one' := fun x => by simp [max_add_add_right] }
le f g := ∀ x, f x ≤ g x
le_refl f x := le_refl (f x)
le_trans f₁ f₂ f₃ h₁₂ h₂₃ x := le_trans (h₁₂ x) (h₂₃ x)
le_antisymm f₁ f₂ h₁₂ h₂₁ := ext fun x => le_antisymm (h₁₂ x) (h₂₁ x)
le_sup_left f g x := le_max_left (f x) (g x)
le_sup_right f g x := le_max_right (f x) (g x)
sup_le f₁ f₂ f₃ h₁ h₂ x := max_le (h₁ x) (h₂ x)
inf f g :=
{ toFun := fun x => min (f x) (g x)
monotone' := fun x y h => min_le_min (f.mono h) (g.mono h)
map_add_one' := fun x => by simp [min_add_add_right] }
inf_le_left f g x := min_le_left (f x) (g x)
inf_le_right f g x := min_le_right (f x) (g x)
le_inf f₁ f₂ f₃ h₂ h₃ x := le_min (h₂ x) (h₃ x)
@[simp]
theorem sup_apply (x : ℝ) : (f ⊔ g) x = max (f x) (g x) :=
rfl
@[simp]
theorem inf_apply (x : ℝ) : (f ⊓ g) x = min (f x) (g x) :=
rfl
theorem iterate_monotone (n : ℕ) : Monotone fun f : CircleDeg1Lift => f^[n] := fun f _ h =>
f.monotone.iterate_le_of_le h _
theorem iterate_mono {f g : CircleDeg1Lift} (h : f ≤ g) (n : ℕ) : f^[n] ≤ g^[n] :=
iterate_monotone n h
theorem pow_mono {f g : CircleDeg1Lift} (h : f ≤ g) (n : ℕ) : f ^ n ≤ g ^ n := fun x => by
simp only [coe_pow, iterate_mono h n x]
theorem pow_monotone (n : ℕ) : Monotone fun f : CircleDeg1Lift => f ^ n := fun _ _ h => pow_mono h n
/-!
### Estimates on `(f * g) 0`
We prove the estimates `f 0 + ⌊g 0⌋ ≤ f (g 0) ≤ f 0 + ⌈g 0⌉` and some corollaries with added/removed
floors and ceils.
We also prove that for two semiconjugate maps `g₁`, `g₂`, the distance between `g₁ 0` and `g₂ 0`
is less than two.
-/
theorem map_le_of_map_zero (x : ℝ) : f x ≤ f 0 + ⌈x⌉ :=
calc
f x ≤ f ⌈x⌉ := f.monotone <| le_ceil _
_ = f 0 + ⌈x⌉ := f.map_int_of_map_zero _
theorem map_map_zero_le : f (g 0) ≤ f 0 + ⌈g 0⌉ :=
f.map_le_of_map_zero (g 0)
theorem floor_map_map_zero_le : ⌊f (g 0)⌋ ≤ ⌊f 0⌋ + ⌈g 0⌉ :=
calc
⌊f (g 0)⌋ ≤ ⌊f 0 + ⌈g 0⌉⌋ := floor_mono <| f.map_map_zero_le g
_ = ⌊f 0⌋ + ⌈g 0⌉ := floor_add_int _ _
theorem ceil_map_map_zero_le : ⌈f (g 0)⌉ ≤ ⌈f 0⌉ + ⌈g 0⌉ :=
calc
⌈f (g 0)⌉ ≤ ⌈f 0 + ⌈g 0⌉⌉ := ceil_mono <| f.map_map_zero_le g
_ = ⌈f 0⌉ + ⌈g 0⌉ := ceil_add_int _ _
theorem map_map_zero_lt : f (g 0) < f 0 + g 0 + 1 :=
calc
f (g 0) ≤ f 0 + ⌈g 0⌉ := f.map_map_zero_le g
_ < f 0 + (g 0 + 1) := add_lt_add_left (ceil_lt_add_one _) _
_ = f 0 + g 0 + 1 := (add_assoc _ _ _).symm
theorem le_map_of_map_zero (x : ℝ) : f 0 + ⌊x⌋ ≤ f x :=
calc
f 0 + ⌊x⌋ = f ⌊x⌋ := (f.map_int_of_map_zero _).symm
_ ≤ f x := f.monotone <| floor_le _
theorem le_map_map_zero : f 0 + ⌊g 0⌋ ≤ f (g 0) :=
f.le_map_of_map_zero (g 0)
theorem le_floor_map_map_zero : ⌊f 0⌋ + ⌊g 0⌋ ≤ ⌊f (g 0)⌋ :=
calc
⌊f 0⌋ + ⌊g 0⌋ = ⌊f 0 + ⌊g 0⌋⌋ := (floor_add_int _ _).symm
_ ≤ ⌊f (g 0)⌋ := floor_mono <| f.le_map_map_zero g
theorem le_ceil_map_map_zero : ⌈f 0⌉ + ⌊g 0⌋ ≤ ⌈(f * g) 0⌉ :=
calc
⌈f 0⌉ + ⌊g 0⌋ = ⌈f 0 + ⌊g 0⌋⌉ := (ceil_add_int _ _).symm
_ ≤ ⌈f (g 0)⌉ := ceil_mono <| f.le_map_map_zero g
theorem lt_map_map_zero : f 0 + g 0 - 1 < f (g 0) :=
calc
f 0 + g 0 - 1 = f 0 + (g 0 - 1) := add_sub_assoc _ _ _
_ < f 0 + ⌊g 0⌋ := add_lt_add_left (sub_one_lt_floor _) _
_ ≤ f (g 0) := f.le_map_map_zero g
theorem dist_map_map_zero_lt : dist (f 0 + g 0) (f (g 0)) < 1 := by
rw [dist_comm, Real.dist_eq, abs_lt, lt_sub_iff_add_lt', sub_lt_iff_lt_add', ← sub_eq_add_neg]
exact ⟨f.lt_map_map_zero g, f.map_map_zero_lt g⟩
theorem dist_map_zero_lt_of_semiconj {f g₁ g₂ : CircleDeg1Lift} (h : Function.Semiconj f g₁ g₂) :
dist (g₁ 0) (g₂ 0) < 2 :=
calc
dist (g₁ 0) (g₂ 0) ≤ dist (g₁ 0) (f (g₁ 0) - f 0) + dist _ (g₂ 0) := dist_triangle _ _ _
_ = dist (f 0 + g₁ 0) (f (g₁ 0)) + dist (g₂ 0 + f 0) (g₂ (f 0)) := by
simp only [h.eq, Real.dist_eq, sub_sub, add_comm (f 0), sub_sub_eq_add_sub,
abs_sub_comm (g₂ (f 0))]
_ < 1 + 1 := add_lt_add (f.dist_map_map_zero_lt g₁) (g₂.dist_map_map_zero_lt f)
_ = 2 := one_add_one_eq_two
theorem dist_map_zero_lt_of_semiconjBy {f g₁ g₂ : CircleDeg1Lift} (h : SemiconjBy f g₁ g₂) :
dist (g₁ 0) (g₂ 0) < 2 :=
dist_map_zero_lt_of_semiconj <| semiconjBy_iff_semiconj.1 h
/-!
### Limits at infinities and continuity
-/
protected theorem tendsto_atBot : Tendsto f atBot atBot :=
tendsto_atBot_mono f.map_le_of_map_zero <| tendsto_atBot_add_const_left _ _ <|
(tendsto_atBot_mono fun x => (ceil_lt_add_one x).le) <|
tendsto_atBot_add_const_right _ _ tendsto_id
protected theorem tendsto_atTop : Tendsto f atTop atTop :=
tendsto_atTop_mono f.le_map_of_map_zero <| tendsto_atTop_add_const_left _ _ <|
(tendsto_atTop_mono fun x => (sub_one_lt_floor x).le) <| by
simpa [sub_eq_add_neg] using tendsto_atTop_add_const_right _ _ tendsto_id
theorem continuous_iff_surjective : Continuous f ↔ Function.Surjective f :=
⟨fun h => h.surjective f.tendsto_atTop f.tendsto_atBot, f.monotone.continuous_of_surjective⟩
/-!
### Estimates on `(f^n) x`
If we know that `f x` is `≤`/`<`/`≥`/`>`/`=` to `x + m`, then we have a similar estimate on
`f^[n] x` and `x + n * m`.
For `≤`, `≥`, and `=` we formulate both `of` (implication) and `iff` versions because implications
work for `n = 0`. For `<` and `>` we formulate only `iff` versions.
-/
theorem iterate_le_of_map_le_add_int {x : ℝ} {m : ℤ} (h : f x ≤ x + m) (n : ℕ) :
f^[n] x ≤ x + n * m := by
simpa only [nsmul_eq_mul, add_right_iterate] using
(f.commute_add_int m).iterate_le_of_map_le f.monotone (monotone_id.add_const (m : ℝ)) h n
theorem le_iterate_of_add_int_le_map {x : ℝ} {m : ℤ} (h : x + m ≤ f x) (n : ℕ) :
x + n * m ≤ f^[n] x := by
simpa only [nsmul_eq_mul, add_right_iterate] using
(f.commute_add_int m).symm.iterate_le_of_map_le (monotone_id.add_const (m : ℝ)) f.monotone h n
theorem iterate_eq_of_map_eq_add_int {x : ℝ} {m : ℤ} (h : f x = x + m) (n : ℕ) :
f^[n] x = x + n * m := by
simpa only [nsmul_eq_mul, add_right_iterate] using (f.commute_add_int m).iterate_eq_of_map_eq n h
theorem iterate_pos_le_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) :
f^[n] x ≤ x + n * m ↔ f x ≤ x + m := by
simpa only [nsmul_eq_mul, add_right_iterate] using
(f.commute_add_int m).iterate_pos_le_iff_map_le f.monotone (strictMono_id.add_const (m : ℝ)) hn
theorem iterate_pos_lt_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) :
f^[n] x < x + n * m ↔ f x < x + m := by
simpa only [nsmul_eq_mul, add_right_iterate] using
(f.commute_add_int m).iterate_pos_lt_iff_map_lt f.monotone (strictMono_id.add_const (m : ℝ)) hn
theorem iterate_pos_eq_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) :
f^[n] x = x + n * m ↔ f x = x + m := by
simpa only [nsmul_eq_mul, add_right_iterate] using
(f.commute_add_int m).iterate_pos_eq_iff_map_eq f.monotone (strictMono_id.add_const (m : ℝ)) hn
theorem le_iterate_pos_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) :
x + n * m ≤ f^[n] x ↔ x + m ≤ f x := by
simpa only [not_lt] using not_congr (f.iterate_pos_lt_iff hn)
theorem lt_iterate_pos_iff {x : ℝ} {m : ℤ} {n : ℕ} (hn : 0 < n) :
x + n * m < f^[n] x ↔ x + m < f x := by
simpa only [not_le] using not_congr (f.iterate_pos_le_iff hn)
theorem mul_floor_map_zero_le_floor_iterate_zero (n : ℕ) : ↑n * ⌊f 0⌋ ≤ ⌊f^[n] 0⌋ := by
rw [le_floor, Int.cast_mul, Int.cast_natCast, ← zero_add ((n : ℝ) * _)]
apply le_iterate_of_add_int_le_map
simp [floor_le]
/-!
### Definition of translation number
-/
noncomputable section
/-- An auxiliary sequence used to define the translation number. -/
def transnumAuxSeq (n : ℕ) : ℝ :=
(f ^ (2 ^ n : ℕ)) 0 / 2 ^ n
/-- The translation number of a `CircleDeg1Lift`, $τ(f)=\lim_{n→∞}\frac{f^n(x)-x}{n}$. We use
an auxiliary sequence `\frac{f^{2^n}(0)}{2^n}` to define `τ(f)` because some proofs are simpler
this way. -/
def translationNumber : ℝ :=
limUnder atTop f.transnumAuxSeq
end
-- TODO: choose two different symbols for `CircleDeg1Lift.translationNumber` and the future
-- `circle_mono_homeo.rotation_number`, then make them `localized notation`s
local notation "τ" => translationNumber
theorem transnumAuxSeq_def : f.transnumAuxSeq = fun n : ℕ => (f ^ (2 ^ n : ℕ)) 0 / 2 ^ n :=
rfl
theorem translationNumber_eq_of_tendsto_aux {τ' : ℝ} (h : Tendsto f.transnumAuxSeq atTop (𝓝 τ')) :
τ f = τ' :=
h.limUnder_eq
theorem translationNumber_eq_of_tendsto₀ {τ' : ℝ}
(h : Tendsto (fun n : ℕ => f^[n] 0 / n) atTop (𝓝 τ')) : τ f = τ' :=
f.translationNumber_eq_of_tendsto_aux <| by
simpa [(· ∘ ·), transnumAuxSeq_def, coe_pow] using
h.comp (Nat.tendsto_pow_atTop_atTop_of_one_lt one_lt_two)
theorem translationNumber_eq_of_tendsto₀' {τ' : ℝ}
(h : Tendsto (fun n : ℕ => f^[n + 1] 0 / (n + 1)) atTop (𝓝 τ')) : τ f = τ' :=
f.translationNumber_eq_of_tendsto₀ <| (tendsto_add_atTop_iff_nat 1).1 (mod_cast h)
theorem transnumAuxSeq_zero : f.transnumAuxSeq 0 = f 0 := by simp [transnumAuxSeq]
theorem transnumAuxSeq_dist_lt (n : ℕ) :
dist (f.transnumAuxSeq n) (f.transnumAuxSeq (n + 1)) < 1 / 2 / 2 ^ n := by
have : 0 < (2 ^ (n + 1) : ℝ) := pow_pos zero_lt_two _
rw [div_div, ← pow_succ', ← abs_of_pos this]
replace := abs_pos.2 (ne_of_gt this)
convert (div_lt_div_right this).2 ((f ^ 2 ^ n).dist_map_map_zero_lt (f ^ 2 ^ n)) using 1
simp_rw [transnumAuxSeq, Real.dist_eq]
rw [← abs_div, sub_div, pow_succ, pow_succ', ← two_mul, mul_div_mul_left _ _ (two_ne_zero' ℝ),
pow_mul, sq, mul_apply]
theorem tendsto_translationNumber_aux : Tendsto f.transnumAuxSeq atTop (𝓝 <| τ f) :=
(cauchySeq_of_le_geometric_two 1 fun n => le_of_lt <| f.transnumAuxSeq_dist_lt n).tendsto_limUnder
theorem dist_map_zero_translationNumber_le : dist (f 0) (τ f) ≤ 1 :=
f.transnumAuxSeq_zero ▸
dist_le_of_le_geometric_two_of_tendsto₀ 1 (fun n => le_of_lt <| f.transnumAuxSeq_dist_lt n)
f.tendsto_translationNumber_aux
theorem tendsto_translationNumber_of_dist_bounded_aux (x : ℕ → ℝ) (C : ℝ)
(H : ∀ n : ℕ, dist ((f ^ n) 0) (x n) ≤ C) :
Tendsto (fun n : ℕ => x (2 ^ n) / 2 ^ n) atTop (𝓝 <| τ f) := by
apply f.tendsto_translationNumber_aux.congr_dist (squeeze_zero (fun _ => dist_nonneg) _ _)
· exact fun n => C / 2 ^ n
· intro n
have : 0 < (2 ^ n : ℝ) := pow_pos zero_lt_two _
convert (div_le_div_right this).2 (H (2 ^ n)) using 1
rw [transnumAuxSeq, Real.dist_eq, ← sub_div, abs_div, abs_of_pos this, Real.dist_eq]
· exact mul_zero C ▸ tendsto_const_nhds.mul <| tendsto_inv_atTop_zero.comp <|
tendsto_pow_atTop_atTop_of_one_lt one_lt_two
theorem translationNumber_eq_of_dist_bounded {f g : CircleDeg1Lift} (C : ℝ)
(H : ∀ n : ℕ, dist ((f ^ n) 0) ((g ^ n) 0) ≤ C) : τ f = τ g :=
Eq.symm <| g.translationNumber_eq_of_tendsto_aux <|
f.tendsto_translationNumber_of_dist_bounded_aux _ C H
@[simp]
theorem translationNumber_one : τ 1 = 0 :=
translationNumber_eq_of_tendsto₀ _ <| by simp [tendsto_const_nhds]
theorem translationNumber_eq_of_semiconjBy {f g₁ g₂ : CircleDeg1Lift} (H : SemiconjBy f g₁ g₂) :
τ g₁ = τ g₂ :=
translationNumber_eq_of_dist_bounded 2 fun n =>
le_of_lt <| dist_map_zero_lt_of_semiconjBy <| H.pow_right n
theorem translationNumber_eq_of_semiconj {f g₁ g₂ : CircleDeg1Lift}
(H : Function.Semiconj f g₁ g₂) : τ g₁ = τ g₂ :=
translationNumber_eq_of_semiconjBy <| semiconjBy_iff_semiconj.2 H
theorem translationNumber_mul_of_commute {f g : CircleDeg1Lift} (h : Commute f g) :
τ (f * g) = τ f + τ g := by
refine tendsto_nhds_unique ?_
(f.tendsto_translationNumber_aux.add g.tendsto_translationNumber_aux)
simp only [transnumAuxSeq, ← add_div]
refine (f * g).tendsto_translationNumber_of_dist_bounded_aux
(fun n ↦ (f ^ n) 0 + (g ^ n) 0) 1 fun n ↦ ?_
rw [h.mul_pow, dist_comm]
exact le_of_lt ((f ^ n).dist_map_map_zero_lt (g ^ n))
@[simp]
theorem translationNumber_units_inv (f : CircleDeg1Liftˣ) : τ ↑f⁻¹ = -τ f :=
eq_neg_iff_add_eq_zero.2 <| by
simp [← translationNumber_mul_of_commute (Commute.refl _).units_inv_left]
@[simp]
theorem translationNumber_pow : ∀ n : ℕ, τ (f ^ n) = n * τ f
| 0 => by simp
| n + 1 => by
rw [pow_succ, translationNumber_mul_of_commute (Commute.pow_self f n),
translationNumber_pow n, Nat.cast_add_one, add_mul, one_mul]
@[simp]
theorem translationNumber_zpow (f : CircleDeg1Liftˣ) : ∀ n : ℤ, τ (f ^ n : Units _) = n * τ f
| (n : ℕ) => by simp [translationNumber_pow f n]
| -[n+1] => by simp; ring
@[simp]
theorem translationNumber_conj_eq (f : CircleDeg1Liftˣ) (g : CircleDeg1Lift) :
τ (↑f * g * ↑f⁻¹) = τ g :=
(translationNumber_eq_of_semiconjBy (f.mk_semiconjBy g)).symm
@[simp]
theorem translationNumber_conj_eq' (f : CircleDeg1Liftˣ) (g : CircleDeg1Lift) :
τ (↑f⁻¹ * g * f) = τ g :=
translationNumber_conj_eq f⁻¹ g
theorem dist_pow_map_zero_mul_translationNumber_le (n : ℕ) :
dist ((f ^ n) 0) (n * f.translationNumber) ≤ 1 :=
f.translationNumber_pow n ▸ (f ^ n).dist_map_zero_translationNumber_le
theorem tendsto_translation_number₀' :
Tendsto (fun n : ℕ => (f ^ (n + 1) : CircleDeg1Lift) 0 / ((n : ℝ) + 1)) atTop (𝓝 <| τ f) := by
refine
tendsto_iff_dist_tendsto_zero.2 <|
squeeze_zero (fun _ => dist_nonneg) (fun n => ?_)
((tendsto_const_div_atTop_nhds_zero_nat 1).comp (tendsto_add_atTop_nat 1))
dsimp
have : (0 : ℝ) < n + 1 := n.cast_add_one_pos
rw [Real.dist_eq, div_sub' _ _ _ (ne_of_gt this), abs_div, ← Real.dist_eq, abs_of_pos this,
Nat.cast_add_one, div_le_div_right this, ← Nat.cast_add_one]
apply dist_pow_map_zero_mul_translationNumber_le
theorem tendsto_translation_number₀ : Tendsto (fun n : ℕ => (f ^ n) 0 / n) atTop (𝓝 <| τ f) :=
(tendsto_add_atTop_iff_nat 1).1 (mod_cast f.tendsto_translation_number₀')
/-- For any `x : ℝ` the sequence $\frac{f^n(x)-x}{n}$ tends to the translation number of `f`.
In particular, this limit does not depend on `x`. -/
theorem tendsto_translationNumber (x : ℝ) :
Tendsto (fun n : ℕ => ((f ^ n) x - x) / n) atTop (𝓝 <| τ f) := by
rw [← translationNumber_conj_eq' (translate <| Multiplicative.ofAdd x)]
refine (tendsto_translation_number₀ _).congr fun n ↦ ?_
simp [sub_eq_neg_add, Units.conj_pow']
theorem tendsto_translation_number' (x : ℝ) :
Tendsto (fun n : ℕ => ((f ^ (n + 1) : CircleDeg1Lift) x - x) / (n + 1)) atTop (𝓝 <| τ f) :=
mod_cast (tendsto_add_atTop_iff_nat 1).2 (f.tendsto_translationNumber x)
theorem translationNumber_mono : Monotone τ := fun f g h =>
le_of_tendsto_of_tendsto' f.tendsto_translation_number₀ g.tendsto_translation_number₀ fun n => by
gcongr; exact pow_mono h _ _
theorem translationNumber_translate (x : ℝ) : τ (translate <| Multiplicative.ofAdd x) = x :=
translationNumber_eq_of_tendsto₀' _ <| by
simp only [translate_iterate, translate_apply, add_zero, Nat.cast_succ,
mul_div_cancel_left₀ (M₀ := ℝ) _ (Nat.cast_add_one_ne_zero _), tendsto_const_nhds]
theorem translationNumber_le_of_le_add {z : ℝ} (hz : ∀ x, f x ≤ x + z) : τ f ≤ z :=
translationNumber_translate z ▸ translationNumber_mono fun x => (hz x).trans_eq (add_comm _ _)
theorem le_translationNumber_of_add_le {z : ℝ} (hz : ∀ x, x + z ≤ f x) : z ≤ τ f :=
translationNumber_translate z ▸ translationNumber_mono fun x => (add_comm _ _).trans_le (hz x)
theorem translationNumber_le_of_le_add_int {x : ℝ} {m : ℤ} (h : f x ≤ x + m) : τ f ≤ m :=
le_of_tendsto' (f.tendsto_translation_number' x) fun n =>
(div_le_iff' (n.cast_add_one_pos : (0 : ℝ) < _)).mpr <| sub_le_iff_le_add'.2 <|
(coe_pow f (n + 1)).symm ▸ @Nat.cast_add_one ℝ _ n ▸ f.iterate_le_of_map_le_add_int h (n + 1)
theorem translationNumber_le_of_le_add_nat {x : ℝ} {m : ℕ} (h : f x ≤ x + m) : τ f ≤ m :=
@translationNumber_le_of_le_add_int f x m h
theorem le_translationNumber_of_add_int_le {x : ℝ} {m : ℤ} (h : x + m ≤ f x) : ↑m ≤ τ f :=
ge_of_tendsto' (f.tendsto_translation_number' x) fun n =>
(le_div_iff (n.cast_add_one_pos : (0 : ℝ) < _)).mpr <| le_sub_iff_add_le'.2 <| by
simp only [coe_pow, mul_comm (m : ℝ), ← Nat.cast_add_one, f.le_iterate_of_add_int_le_map h]
theorem le_translationNumber_of_add_nat_le {x : ℝ} {m : ℕ} (h : x + m ≤ f x) : ↑m ≤ τ f :=
@le_translationNumber_of_add_int_le f x m h
/-- If `f x - x` is an integer number `m` for some point `x`, then `τ f = m`.
On the circle this means that a map with a fixed point has rotation number zero. -/
theorem translationNumber_of_eq_add_int {x : ℝ} {m : ℤ} (h : f x = x + m) : τ f = m :=
le_antisymm (translationNumber_le_of_le_add_int f <| le_of_eq h)
(le_translationNumber_of_add_int_le f <| le_of_eq h.symm)
theorem floor_sub_le_translationNumber (x : ℝ) : ↑⌊f x - x⌋ ≤ τ f :=
le_translationNumber_of_add_int_le f <| le_sub_iff_add_le'.1 (floor_le <| f x - x)
theorem translationNumber_le_ceil_sub (x : ℝ) : τ f ≤ ⌈f x - x⌉ :=
translationNumber_le_of_le_add_int f <| sub_le_iff_le_add'.1 (le_ceil <| f x - x)
theorem map_lt_of_translationNumber_lt_int {n : ℤ} (h : τ f < n) (x : ℝ) : f x < x + n :=
not_le.1 <| mt f.le_translationNumber_of_add_int_le <| not_le.2 h
theorem map_lt_of_translationNumber_lt_nat {n : ℕ} (h : τ f < n) (x : ℝ) : f x < x + n :=
@map_lt_of_translationNumber_lt_int f n h x
theorem map_lt_add_floor_translationNumber_add_one (x : ℝ) : f x < x + ⌊τ f⌋ + 1 := by
rw [add_assoc]
norm_cast
refine map_lt_of_translationNumber_lt_int _ ?_ _
push_cast
exact lt_floor_add_one _
theorem map_lt_add_translationNumber_add_one (x : ℝ) : f x < x + τ f + 1 :=
calc
f x < x + ⌊τ f⌋ + 1 := f.map_lt_add_floor_translationNumber_add_one x
_ ≤ x + τ f + 1 := by gcongr; apply floor_le
theorem lt_map_of_int_lt_translationNumber {n : ℤ} (h : ↑n < τ f) (x : ℝ) : x + n < f x :=
not_le.1 <| mt f.translationNumber_le_of_le_add_int <| not_le.2 h
theorem lt_map_of_nat_lt_translationNumber {n : ℕ} (h : ↑n < τ f) (x : ℝ) : x + n < f x :=
@lt_map_of_int_lt_translationNumber f n h x
/-- If `f^n x - x`, `n > 0`, is an integer number `m` for some point `x`, then
`τ f = m / n`. On the circle this means that a map with a periodic orbit has
a rational rotation number. -/
theorem translationNumber_of_map_pow_eq_add_int {x : ℝ} {n : ℕ} {m : ℤ} (h : (f ^ n) x = x + m)
(hn : 0 < n) : τ f = m / n := by
have := (f ^ n).translationNumber_of_eq_add_int h
rwa [translationNumber_pow, mul_comm, ← eq_div_iff] at this
exact Nat.cast_ne_zero.2 (ne_of_gt hn)
/-- If a predicate depends only on `f x - x` and holds for all `0 ≤ x ≤ 1`,
then it holds for all `x`. -/
theorem forall_map_sub_of_Icc (P : ℝ → Prop) (h : ∀ x ∈ Icc (0 : ℝ) 1, P (f x - x)) (x : ℝ) :
P (f x - x) :=
f.map_fract_sub_fract_eq x ▸ h _ ⟨fract_nonneg _, le_of_lt (fract_lt_one _)⟩
theorem translationNumber_lt_of_forall_lt_add (hf : Continuous f) {z : ℝ} (hz : ∀ x, f x < x + z) :
τ f < z := by
obtain ⟨x, -, hx⟩ : ∃ x ∈ Icc (0 : ℝ) 1, ∀ y ∈ Icc (0 : ℝ) 1, f y - y ≤ f x - x :=
isCompact_Icc.exists_isMaxOn (nonempty_Icc.2 zero_le_one)
(hf.sub continuous_id).continuousOn
refine lt_of_le_of_lt ?_ (sub_lt_iff_lt_add'.2 <| hz x)
apply translationNumber_le_of_le_add
simp only [← sub_le_iff_le_add']
exact f.forall_map_sub_of_Icc (fun a => a ≤ f x - x) hx
theorem lt_translationNumber_of_forall_add_lt (hf : Continuous f) {z : ℝ} (hz : ∀ x, x + z < f x) :
z < τ f := by
obtain ⟨x, -, hx⟩ : ∃ x ∈ Icc (0 : ℝ) 1, ∀ y ∈ Icc (0 : ℝ) 1, f x - x ≤ f y - y :=
isCompact_Icc.exists_isMinOn (nonempty_Icc.2 zero_le_one) (hf.sub continuous_id).continuousOn
refine lt_of_lt_of_le (lt_sub_iff_add_lt'.2 <| hz x) ?_
apply le_translationNumber_of_add_le
simp only [← le_sub_iff_add_le']
exact f.forall_map_sub_of_Icc _ hx
/-- If `f` is a continuous monotone map `ℝ → ℝ`, `f (x + 1) = f x + 1`, then there exists `x`
such that `f x = x + τ f`. -/
theorem exists_eq_add_translationNumber (hf : Continuous f) : ∃ x, f x = x + τ f := by
obtain ⟨a, ha⟩ : ∃ x, f x ≤ x + τ f := by
by_contra! H
exact lt_irrefl _ (f.lt_translationNumber_of_forall_add_lt hf H)
obtain ⟨b, hb⟩ : ∃ x, x + τ f ≤ f x := by
by_contra! H
exact lt_irrefl _ (f.translationNumber_lt_of_forall_lt_add hf H)
exact intermediate_value_univ₂ hf (continuous_id.add continuous_const) ha hb
theorem translationNumber_eq_int_iff (hf : Continuous f) {m : ℤ} :
τ f = m ↔ ∃ x : ℝ, f x = x + m := by
constructor
· intro h
simp only [← h]
exact f.exists_eq_add_translationNumber hf
· rintro ⟨x, hx⟩
exact f.translationNumber_of_eq_add_int hx
theorem continuous_pow (hf : Continuous f) (n : ℕ) : Continuous (f ^ n : CircleDeg1Lift) := by
rw [coe_pow]
exact hf.iterate n
theorem translationNumber_eq_rat_iff (hf : Continuous f) {m : ℤ} {n : ℕ} (hn : 0 < n) :
τ f = m / n ↔ ∃ x, (f ^ n) x = x + m := by
rw [eq_div_iff, mul_comm, ← translationNumber_pow] <;> [skip; exact ne_of_gt (Nat.cast_pos.2 hn)]
exact (f ^ n).translationNumber_eq_int_iff (f.continuous_pow hf n)
/-- Consider two actions `f₁ f₂ : G →* CircleDeg1Lift` of a group on the real line by lifts of
orientation preserving circle homeomorphisms. Suppose that for each `g : G` the homeomorphisms
`f₁ g` and `f₂ g` have equal rotation numbers. Then there exists `F : CircleDeg1Lift` such that
`F * f₁ g = f₂ g * F` for all `g : G`.
This is a version of Proposition 5.4 from [Étienne Ghys, Groupes d'homeomorphismes du cercle et
cohomologie bornee][ghys87:groupes]. -/
theorem semiconj_of_group_action_of_forall_translationNumber_eq {G : Type*} [Group G]
(f₁ f₂ : G →* CircleDeg1Lift) (h : ∀ g, τ (f₁ g) = τ (f₂ g)) :
∃ F : CircleDeg1Lift, ∀ g, Semiconj F (f₁ g) (f₂ g) := by
-- Equality of translation number guarantees that for each `x`
-- the set `{f₂ g⁻¹ (f₁ g x) | g : G}` is bounded above.
have : ∀ x, BddAbove (range fun g => f₂ g⁻¹ (f₁ g x)) := by
refine fun x => ⟨x + 2, ?_⟩
rintro _ ⟨g, rfl⟩
have : τ (f₂ g⁻¹) = -τ (f₂ g) := by
rw [← MonoidHom.coe_toHomUnits, MonoidHom.map_inv, translationNumber_units_inv,
MonoidHom.coe_toHomUnits]
calc
f₂ g⁻¹ (f₁ g x) ≤ f₂ g⁻¹ (x + τ (f₁ g) + 1) :=
mono _ (map_lt_add_translationNumber_add_one _ _).le
_ = f₂ g⁻¹ (x + τ (f₂ g)) + 1 := by rw [h, map_add_one]
_ ≤ x + τ (f₂ g) + τ (f₂ g⁻¹) + 1 + 1 :=
add_le_add_right (map_lt_add_translationNumber_add_one _ _).le _
_ = x + 2 := by simp [this, add_assoc, one_add_one_eq_two]
-- We have a theorem about actions by `OrderIso`, so we introduce auxiliary maps
-- to `ℝ ≃o ℝ`.
set F₁ := toOrderIso.comp f₁.toHomUnits
set F₂ := toOrderIso.comp f₂.toHomUnits
have hF₁ : ∀ g, ⇑(F₁ g) = f₁ g := fun _ => rfl
have hF₂ : ∀ g, ⇑(F₂ g) = f₂ g := fun _ => rfl
-- Now we apply `csSup_div_semiconj` and go back to `f₁` and `f₂`.
refine ⟨⟨⟨_, fun x y hxy => ?_⟩, fun x => ?_⟩, csSup_div_semiconj F₂ F₁ fun x => ?_⟩ <;>
simp only [hF₁, hF₂, ← map_inv, coe_mk]
· exact ciSup_mono (this y) fun g => mono _ (mono _ hxy)
· simp only [map_add_one]
exact (Monotone.map_ciSup_of_continuousAt (continuousAt_id.add continuousAt_const)
(monotone_id.add_const (1 : ℝ)) (this x)).symm
· exact this x
/-- If two lifts of circle homeomorphisms have the same translation number, then they are
semiconjugate by a `CircleDeg1Lift`. This version uses arguments `f₁ f₂ : CircleDeg1Liftˣ`
to assume that `f₁` and `f₂` are homeomorphisms. -/
theorem units_semiconj_of_translationNumber_eq {f₁ f₂ : CircleDeg1Liftˣ} (h : τ f₁ = τ f₂) :
∃ F : CircleDeg1Lift, Semiconj F f₁ f₂ :=
have : ∀ n : Multiplicative ℤ,
τ ((Units.coeHom _).comp (zpowersHom _ f₁) n) =
τ ((Units.coeHom _).comp (zpowersHom _ f₂) n) := fun n ↦ by
simp [h]
(semiconj_of_group_action_of_forall_translationNumber_eq _ _ this).imp fun F hF => by
simpa using hF (Multiplicative.ofAdd 1)
/-- If two lifts of circle homeomorphisms have the same translation number, then they are
semiconjugate by a `CircleDeg1Lift`. This version uses assumptions `IsUnit f₁` and `IsUnit f₂`
to assume that `f₁` and `f₂` are homeomorphisms. -/
theorem semiconj_of_isUnit_of_translationNumber_eq {f₁ f₂ : CircleDeg1Lift} (h₁ : IsUnit f₁)
(h₂ : IsUnit f₂) (h : τ f₁ = τ f₂) : ∃ F : CircleDeg1Lift, Semiconj F f₁ f₂ := by
rcases h₁, h₂ with ⟨⟨f₁, rfl⟩, ⟨f₂, rfl⟩⟩
exact units_semiconj_of_translationNumber_eq h
/-- If two lifts of circle homeomorphisms have the same translation number, then they are
semiconjugate by a `CircleDeg1Lift`. This version uses assumptions `bijective f₁` and
`bijective f₂` to assume that `f₁` and `f₂` are homeomorphisms. -/
theorem semiconj_of_bijective_of_translationNumber_eq {f₁ f₂ : CircleDeg1Lift} (h₁ : Bijective f₁)
(h₂ : Bijective f₂) (h : τ f₁ = τ f₂) : ∃ F : CircleDeg1Lift, Semiconj F f₁ f₂ :=
semiconj_of_isUnit_of_translationNumber_eq (isUnit_iff_bijective.2 h₁) (isUnit_iff_bijective.2 h₂)
h
end CircleDeg1Lift
|
Dynamics\Ergodic\AddCircle.lean | /-
Copyright (c) 2022 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Data.Set.Pointwise.Iterate
import Mathlib.Dynamics.Ergodic.Ergodic
import Mathlib.MeasureTheory.Covering.DensityTheorem
import Mathlib.MeasureTheory.Group.AddCircle
import Mathlib.MeasureTheory.Measure.Haar.Unique
/-!
# Ergodic maps of the additive circle
This file contains proofs of ergodicity for maps of the additive circle.
## Main definitions:
* `AddCircle.ergodic_zsmul`: given `n : ℤ` such that `1 < |n|`, the self map `y ↦ n • y` on
the additive circle is ergodic (wrt the Haar measure).
* `AddCircle.ergodic_nsmul`: given `n : ℕ` such that `1 < n`, the self map `y ↦ n • y` on
the additive circle is ergodic (wrt the Haar measure).
* `AddCircle.ergodic_zsmul_add`: given `n : ℤ` such that `1 < |n|` and `x : AddCircle T`, the
self map `y ↦ n • y + x` on the additive circle is ergodic (wrt the Haar measure).
* `AddCircle.ergodic_nsmul_add`: given `n : ℕ` such that `1 < n` and `x : AddCircle T`, the
self map `y ↦ n • y + x` on the additive circle is ergodic (wrt the Haar measure).
-/
open Set Function MeasureTheory MeasureTheory.Measure Filter Metric
open scoped MeasureTheory NNReal ENNReal Topology Pointwise
namespace AddCircle
variable {T : ℝ} [hT : Fact (0 < T)]
/-- If a null-measurable subset of the circle is almost invariant under rotation by a family of
rational angles with denominators tending to infinity, then it must be almost empty or almost full.
-/
theorem ae_empty_or_univ_of_forall_vadd_ae_eq_self {s : Set <| AddCircle T}
(hs : NullMeasurableSet s volume) {ι : Type*} {l : Filter ι} [l.NeBot] {u : ι → AddCircle T}
(hu₁ : ∀ i, (u i +ᵥ s : Set _) =ᵐ[volume] s) (hu₂ : Tendsto (addOrderOf ∘ u) l atTop) :
s =ᵐ[volume] (∅ : Set <| AddCircle T) ∨ s =ᵐ[volume] univ := by
/- Sketch of proof:
Assume `T = 1` for simplicity and let `μ` be the Haar measure. We may assume `s` has positive
measure since otherwise there is nothing to prove. In this case, by Lebesgue's density theorem,
there exists a point `d` of positive density. Let `Iⱼ` be the sequence of closed balls about `d`
of diameter `1 / nⱼ` where `nⱼ` is the additive order of `uⱼ`. Since `d` has positive density we
must have `μ (s ∩ Iⱼ) / μ Iⱼ → 1` along `l`. However since `s` is invariant under the action of
`uⱼ` and since `Iⱼ` is a fundamental domain for this action, we must have
`μ (s ∩ Iⱼ) = nⱼ * μ s = (μ Iⱼ) * μ s`. We thus have `μ s → 1` and thus `μ s = 1`. -/
set μ := (volume : Measure <| AddCircle T)
set n : ι → ℕ := addOrderOf ∘ u
have hT₀ : 0 < T := hT.out
have hT₁ : ENNReal.ofReal T ≠ 0 := by simpa
rw [ae_eq_empty, ae_eq_univ_iff_measure_eq hs, AddCircle.measure_univ]
rcases eq_or_ne (μ s) 0 with h | h; · exact Or.inl h
right
obtain ⟨d, -, hd⟩ : ∃ d, d ∈ s ∧ ∀ {ι'} {l : Filter ι'} (w : ι' → AddCircle T) (δ : ι' → ℝ),
Tendsto δ l (𝓝[>] 0) → (∀ᶠ j in l, d ∈ closedBall (w j) (1 * δ j)) →
Tendsto (fun j => μ (s ∩ closedBall (w j) (δ j)) / μ (closedBall (w j) (δ j))) l (𝓝 1) :=
exists_mem_of_measure_ne_zero_of_ae h
(IsUnifLocDoublingMeasure.ae_tendsto_measure_inter_div μ s 1)
let I : ι → Set (AddCircle T) := fun j => closedBall d (T / (2 * ↑(n j)))
replace hd : Tendsto (fun j => μ (s ∩ I j) / μ (I j)) l (𝓝 1) := by
let δ : ι → ℝ := fun j => T / (2 * ↑(n j))
have hδ₀ : ∀ᶠ j in l, 0 < δ j :=
(hu₂.eventually_gt_atTop 0).mono fun j hj => div_pos hT₀ <| by positivity
have hδ₁ : Tendsto δ l (𝓝[>] 0) := by
refine tendsto_nhdsWithin_iff.mpr ⟨?_, hδ₀⟩
replace hu₂ : Tendsto (fun j => T⁻¹ * 2 * n j) l atTop :=
(tendsto_natCast_atTop_iff.mpr hu₂).const_mul_atTop (by positivity : 0 < T⁻¹ * 2)
convert hu₂.inv_tendsto_atTop
ext j
simp only [δ, Pi.inv_apply, mul_inv_rev, inv_inv, div_eq_inv_mul, ← mul_assoc]
have hw : ∀ᶠ j in l, d ∈ closedBall d (1 * δ j) := hδ₀.mono fun j hj => by
simp only [comp_apply, one_mul, mem_closedBall, dist_self]
apply hj.le
exact hd _ δ hδ₁ hw
suffices ∀ᶠ j in l, μ (s ∩ I j) / μ (I j) = μ s / ENNReal.ofReal T by
replace hd := hd.congr' this
rwa [tendsto_const_nhds_iff, ENNReal.div_eq_one_iff hT₁ ENNReal.ofReal_ne_top] at hd
refine (hu₂.eventually_gt_atTop 0).mono fun j hj => ?_
have : addOrderOf (u j) = n j := rfl
have huj : IsOfFinAddOrder (u j) := addOrderOf_pos_iff.mp hj
have huj' : 1 ≤ (↑(n j) : ℝ) := by norm_cast
have hI₀ : μ (I j) ≠ 0 := (measure_closedBall_pos _ d <| by positivity).ne.symm
have hI₁ : μ (I j) ≠ ⊤ := measure_ne_top _ _
have hI₂ : μ (I j) * ↑(n j) = ENNReal.ofReal T := by
rw [volume_closedBall, mul_div, mul_div_mul_left T _ two_ne_zero,
min_eq_right (div_le_self hT₀.le huj'), mul_comm, ← nsmul_eq_mul, ← ENNReal.ofReal_nsmul,
nsmul_eq_mul, mul_div_cancel₀]
exact Nat.cast_ne_zero.mpr hj.ne'
rw [ENNReal.div_eq_div_iff hT₁ ENNReal.ofReal_ne_top hI₀ hI₁,
volume_of_add_preimage_eq s _ (u j) d huj (hu₁ j) closedBall_ae_eq_ball, nsmul_eq_mul, ←
mul_assoc, this, hI₂]
theorem ergodic_zsmul {n : ℤ} (hn : 1 < |n|) : Ergodic fun y : AddCircle T => n • y :=
{ measurePreserving_zsmul volume (abs_pos.mp <| lt_trans zero_lt_one hn) with
ae_empty_or_univ := fun s hs hs' => by
let u : ℕ → AddCircle T := fun j => ↑((↑1 : ℝ) / ↑(n.natAbs ^ j) * T)
replace hn : 1 < n.natAbs := by rwa [Int.abs_eq_natAbs, Nat.one_lt_cast] at hn
have hu₀ : ∀ j, addOrderOf (u j) = n.natAbs ^ j := fun j => by
convert addOrderOf_div_of_gcd_eq_one (p := T) (m := 1)
(pow_pos (pos_of_gt hn) j) (gcd_one_left _)
norm_cast
have hnu : ∀ j, n ^ j • u j = 0 := fun j => by
rw [← addOrderOf_dvd_iff_zsmul_eq_zero, hu₀, Int.natCast_pow, Int.natCast_natAbs, ← abs_pow,
abs_dvd]
have hu₁ : ∀ j, (u j +ᵥ s : Set _) =ᵐ[volume] s := fun j => by
rw [vadd_eq_self_of_preimage_zsmul_eq_self hs' (hnu j)]
have hu₂ : Tendsto (fun j => addOrderOf <| u j) atTop atTop := by
simp_rw [hu₀]; exact Nat.tendsto_pow_atTop_atTop_of_one_lt hn
exact ae_empty_or_univ_of_forall_vadd_ae_eq_self hs.nullMeasurableSet hu₁ hu₂ }
theorem ergodic_nsmul {n : ℕ} (hn : 1 < n) : Ergodic fun y : AddCircle T => n • y :=
ergodic_zsmul (by simp [hn] : 1 < |(n : ℤ)|)
theorem ergodic_zsmul_add (x : AddCircle T) {n : ℤ} (h : 1 < |n|) : Ergodic fun y => n • y + x := by
set f : AddCircle T → AddCircle T := fun y => n • y + x
let e : AddCircle T ≃ᵐ AddCircle T := MeasurableEquiv.addLeft (DivisibleBy.div x <| n - 1)
have he : MeasurePreserving e volume volume :=
measurePreserving_add_left volume (DivisibleBy.div x <| n - 1)
suffices e ∘ f ∘ e.symm = fun y => n • y by
rw [← he.ergodic_conjugate_iff, this]; exact ergodic_zsmul h
replace h : n - 1 ≠ 0 := by
rw [← abs_one] at h; rw [sub_ne_zero]; exact ne_of_apply_ne _ (ne_of_gt h)
have hnx : n • DivisibleBy.div x (n - 1) = x + DivisibleBy.div x (n - 1) := by
conv_rhs => congr; rw [← DivisibleBy.div_cancel x h]
rw [sub_smul, one_smul, sub_add_cancel]
ext y
simp only [f, e, hnx, MeasurableEquiv.coe_addLeft, MeasurableEquiv.symm_addLeft, comp_apply,
smul_add, zsmul_neg', neg_smul, neg_add_rev]
abel
theorem ergodic_nsmul_add (x : AddCircle T) {n : ℕ} (h : 1 < n) : Ergodic fun y => n • y + x :=
ergodic_zsmul_add x (by simp [h] : 1 < |(n : ℤ)|)
end AddCircle
|
Dynamics\Ergodic\Conservative.lean | /-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.MeasureTheory.Constructions.BorelSpace.Basic
import Mathlib.Dynamics.Ergodic.MeasurePreserving
import Mathlib.Combinatorics.Pigeonhole
/-!
# Conservative systems
In this file we define `f : α → α` to be a *conservative* system w.r.t a measure `μ` if `f` is
non-singular (`MeasureTheory.QuasiMeasurePreserving`) and for every measurable set `s` of
positive measure at least one point `x ∈ s` returns back to `s` after some number of iterations of
`f`. There are several properties that look like they are stronger than this one but actually follow
from it:
* `MeasureTheory.Conservative.frequently_measure_inter_ne_zero`,
`MeasureTheory.Conservative.exists_gt_measure_inter_ne_zero`: if `μ s ≠ 0`, then for infinitely
many `n`, the measure of `s ∩ f^[n] ⁻¹' s` is positive.
* `MeasureTheory.Conservative.measure_mem_forall_ge_image_not_mem_eq_zero`,
`MeasureTheory.Conservative.ae_mem_imp_frequently_image_mem`: a.e. every point of `s` visits `s`
infinitely many times (Poincaré recurrence theorem).
We also prove the topological Poincaré recurrence theorem
`MeasureTheory.Conservative.ae_frequently_mem_of_mem_nhds`. Let `f : α → α` be a conservative
dynamical system on a topological space with second countable topology and measurable open
sets. Then almost every point `x : α` is recurrent: it visits every neighborhood `s ∈ 𝓝 x`
infinitely many times.
## Tags
conservative dynamical system, Poincare recurrence theorem
-/
noncomputable section
open Set Filter MeasureTheory Finset Function TopologicalSpace Topology
variable {ι : Type*} {α : Type*} [MeasurableSpace α] {f : α → α} {s : Set α} {μ : Measure α}
namespace MeasureTheory
open Measure
/-- We say that a non-singular (`MeasureTheory.QuasiMeasurePreserving`) self-map is
*conservative* if for any measurable set `s` of positive measure there exists `x ∈ s` such that `x`
returns back to `s` under some iteration of `f`. -/
structure Conservative (f : α → α) (μ : Measure α) extends QuasiMeasurePreserving f μ μ : Prop where
/-- If `f` is a conservative self-map and `s` is a measurable set of nonzero measure,
then there exists a point `x ∈ s` that returns to `s` under a non-zero iteration of `f`. -/
exists_mem_iterate_mem' : ∀ ⦃s⦄, MeasurableSet s → μ s ≠ 0 → ∃ x ∈ s, ∃ m ≠ 0, f^[m] x ∈ s
/-- A self-map preserving a finite measure is conservative. -/
protected theorem MeasurePreserving.conservative [IsFiniteMeasure μ] (h : MeasurePreserving f μ μ) :
Conservative f μ :=
⟨h.quasiMeasurePreserving, fun _ hsm h0 => h.exists_mem_iterate_mem hsm.nullMeasurableSet h0⟩
namespace Conservative
/-- The identity map is conservative w.r.t. any measure. -/
protected theorem id (μ : Measure α) : Conservative id μ :=
{ toQuasiMeasurePreserving := QuasiMeasurePreserving.id μ
exists_mem_iterate_mem' := fun _ _ h0 => by
simpa [exists_ne] using nonempty_of_measure_ne_zero h0 }
/-- If `f` is a conservative self-map and `s` is a null measurable set of nonzero measure,
then there exists a point `x ∈ s` that returns to `s` under a non-zero iteration of `f`. -/
theorem exists_mem_iterate_mem (hf : Conservative f μ)
(hsm : NullMeasurableSet s μ) (hs₀ : μ s ≠ 0) :
∃ x ∈ s, ∃ m ≠ 0, f^[m] x ∈ s := by
rcases hsm.exists_measurable_subset_ae_eq with ⟨t, hsub, htm, hts⟩
rcases hf.exists_mem_iterate_mem' htm (by rwa [measure_congr hts]) with ⟨x, hxt, m, hm₀, hmt⟩
exact ⟨x, hsub hxt, m, hm₀, hsub hmt⟩
/-- If `f` is a conservative map and `s` is a measurable set of nonzero measure, then
for infinitely many values of `m` a positive measure of points `x ∈ s` returns back to `s`
after `m` iterations of `f`. -/
theorem frequently_measure_inter_ne_zero (hf : Conservative f μ) (hs : NullMeasurableSet s μ)
(h0 : μ s ≠ 0) : ∃ᶠ m in atTop, μ (s ∩ f^[m] ⁻¹' s) ≠ 0 := by
set t : ℕ → Set α := fun n ↦ s ∩ f^[n] ⁻¹' s
-- Assume that `μ (t n) ≠ 0`, where `t n = s ∩ f^[n] ⁻¹' s`, only for finitely many `n`.
by_contra H
-- Let `N` be the maximal `n` such that `μ (t n) ≠ 0`.
obtain ⟨N, hN, hmax⟩ : ∃ N, μ (t N) ≠ 0 ∧ ∀ n > N, μ (t n) = 0 := by
rw [Nat.frequently_atTop_iff_infinite, not_infinite] at H
convert exists_max_image _ (·) H ⟨0, by simpa⟩ using 4
rw [gt_iff_lt, ← not_le, not_imp_comm, mem_setOf]
have htm {n : ℕ} : NullMeasurableSet (t n) μ :=
hs.inter <| hs.preimage <| hf.toQuasiMeasurePreserving.iterate n
-- Then all `t n`, `n > N`, are null sets, hence `T = t N \ ⋃ n > N, t n` has positive measure.
set T := t N \ ⋃ n > N, t n with hT
have hμT : μ T ≠ 0 := by
rwa [hT, measure_diff_null]
exact (measure_biUnion_null_iff {n | N < n}.to_countable).2 hmax
have hTm : NullMeasurableSet T μ := htm.diff <| .biUnion {n | N < n}.to_countable fun _ _ ↦ htm
-- Take `x ∈ T` and `m ≠ 0` such that `f^[m] x ∈ T`.
rcases hf.exists_mem_iterate_mem hTm hμT with ⟨x, hxt, m, hm₀, hmt⟩
-- Then `N + m > N`, `x ∈ s`, and `f^[N + m] x = f^[N] (f^[m] x) ∈ s`.
-- This contradicts `x ∈ T ⊆ (⋃ n > N, t n)ᶜ`.
refine hxt.2 <| mem_iUnion₂.2 ⟨N + m, ?_, hxt.1.1, ?_⟩
· simpa [pos_iff_ne_zero]
· simpa only [iterate_add] using hmt.1.2
/-- If `f` is a conservative map and `s` is a measurable set of nonzero measure, then
for an arbitrarily large `m` a positive measure of points `x ∈ s` returns back to `s`
after `m` iterations of `f`. -/
theorem exists_gt_measure_inter_ne_zero (hf : Conservative f μ) (hs : NullMeasurableSet s μ)
(h0 : μ s ≠ 0) (N : ℕ) : ∃ m > N, μ (s ∩ f^[m] ⁻¹' s) ≠ 0 :=
let ⟨m, hm, hmN⟩ :=
((hf.frequently_measure_inter_ne_zero hs h0).and_eventually (eventually_gt_atTop N)).exists
⟨m, hmN, hm⟩
/-- Poincaré recurrence theorem: given a conservative map `f` and a measurable set `s`, the set
of points `x ∈ s` such that `x` does not return to `s` after `≥ n` iterations has measure zero. -/
theorem measure_mem_forall_ge_image_not_mem_eq_zero (hf : Conservative f μ)
(hs : NullMeasurableSet s μ) (n : ℕ) :
μ ({ x ∈ s | ∀ m ≥ n, f^[m] x ∉ s }) = 0 := by
by_contra H
have : NullMeasurableSet (s ∩ { x | ∀ m ≥ n, f^[m] x ∉ s }) μ := by
simp only [setOf_forall, ← compl_setOf]
exact hs.inter <| .biInter (to_countable _) fun m _ ↦
(hs.preimage <| hf.toQuasiMeasurePreserving.iterate m).compl
rcases (hf.exists_gt_measure_inter_ne_zero this H) n with ⟨m, hmn, hm⟩
rcases nonempty_of_measure_ne_zero hm with ⟨x, ⟨_, hxn⟩, hxm, -⟩
exact hxn m hmn.lt.le hxm
/-- Poincaré recurrence theorem: given a conservative map `f` and a measurable set `s`,
almost every point `x ∈ s` returns back to `s` infinitely many times. -/
theorem ae_mem_imp_frequently_image_mem (hf : Conservative f μ) (hs : NullMeasurableSet s μ) :
∀ᵐ x ∂μ, x ∈ s → ∃ᶠ n in atTop, f^[n] x ∈ s := by
simp only [frequently_atTop, @forall_swap (_ ∈ s), ae_all_iff]
intro n
filter_upwards [measure_zero_iff_ae_nmem.1 (hf.measure_mem_forall_ge_image_not_mem_eq_zero hs n)]
simp
theorem inter_frequently_image_mem_ae_eq (hf : Conservative f μ) (hs : NullMeasurableSet s μ) :
(s ∩ { x | ∃ᶠ n in atTop, f^[n] x ∈ s } : Set α) =ᵐ[μ] s :=
inter_eventuallyEq_left.2 <| hf.ae_mem_imp_frequently_image_mem hs
theorem measure_inter_frequently_image_mem_eq (hf : Conservative f μ) (hs : NullMeasurableSet s μ) :
μ (s ∩ { x | ∃ᶠ n in atTop, f^[n] x ∈ s }) = μ s :=
measure_congr (hf.inter_frequently_image_mem_ae_eq hs)
/-- Poincaré recurrence theorem: if `f` is a conservative dynamical system and `s` is a measurable
set, then for `μ`-a.e. `x`, if the orbit of `x` visits `s` at least once, then it visits `s`
infinitely many times. -/
theorem ae_forall_image_mem_imp_frequently_image_mem (hf : Conservative f μ)
(hs : NullMeasurableSet s μ) : ∀ᵐ x ∂μ, ∀ k, f^[k] x ∈ s → ∃ᶠ n in atTop, f^[n] x ∈ s := by
refine ae_all_iff.2 fun k => ?_
refine (hf.ae_mem_imp_frequently_image_mem
(hs.preimage <| hf.toQuasiMeasurePreserving.iterate k)).mono fun x hx hk => ?_
rw [← map_add_atTop_eq_nat k, frequently_map]
refine (hx hk).mono fun n hn => ?_
rwa [add_comm, iterate_add_apply]
/-- If `f` is a conservative self-map and `s` is a measurable set of positive measure, then
`ae μ`-frequently we have `x ∈ s` and `s` returns to `s` under infinitely many iterations of `f`. -/
theorem frequently_ae_mem_and_frequently_image_mem (hf : Conservative f μ)
(hs : NullMeasurableSet s μ) (h0 : μ s ≠ 0) : ∃ᵐ x ∂μ, x ∈ s ∧ ∃ᶠ n in atTop, f^[n] x ∈ s :=
((frequently_ae_mem_iff.2 h0).and_eventually (hf.ae_mem_imp_frequently_image_mem hs)).mono
fun _ hx => ⟨hx.1, hx.2 hx.1⟩
/-- Poincaré recurrence theorem. Let `f : α → α` be a conservative dynamical system on a topological
space with second countable topology and measurable open sets. Then almost every point `x : α`
is recurrent: it visits every neighborhood `s ∈ 𝓝 x` infinitely many times. -/
theorem ae_frequently_mem_of_mem_nhds [TopologicalSpace α] [SecondCountableTopology α]
[OpensMeasurableSpace α] {f : α → α} {μ : Measure α} (h : Conservative f μ) :
∀ᵐ x ∂μ, ∀ s ∈ 𝓝 x, ∃ᶠ n in atTop, f^[n] x ∈ s := by
have : ∀ s ∈ countableBasis α, ∀ᵐ x ∂μ, x ∈ s → ∃ᶠ n in atTop, f^[n] x ∈ s := fun s hs =>
h.ae_mem_imp_frequently_image_mem (isOpen_of_mem_countableBasis hs).nullMeasurableSet
refine ((ae_ball_iff <| countable_countableBasis α).2 this).mono fun x hx s hs => ?_
rcases (isBasis_countableBasis α).mem_nhds_iff.1 hs with ⟨o, hoS, hxo, hos⟩
exact (hx o hoS hxo).mono fun n hn => hos hn
/-- Iteration of a conservative system is a conservative system. -/
protected theorem iterate (hf : Conservative f μ) (n : ℕ) : Conservative f^[n] μ := by
-- Discharge the trivial case `n = 0`
cases' n with n
· exact Conservative.id μ
refine ⟨hf.1.iterate _, fun s hs hs0 => ?_⟩
rcases (hf.frequently_ae_mem_and_frequently_image_mem hs.nullMeasurableSet hs0).exists
with ⟨x, _, hx⟩
/- We take a point `x ∈ s` such that `f^[k] x ∈ s` for infinitely many values of `k`,
then we choose two of these values `k < l` such that `k ≡ l [MOD (n + 1)]`.
Then `f^[k] x ∈ s` and `f^[n + 1]^[(l - k) / (n + 1)] (f^[k] x) = f^[l] x ∈ s`. -/
rw [Nat.frequently_atTop_iff_infinite] at hx
rcases Nat.exists_lt_modEq_of_infinite hx n.succ_pos with ⟨k, hk, l, hl, hkl, hn⟩
set m := (l - k) / (n + 1)
have : (n + 1) * m = l - k := by
apply Nat.mul_div_cancel'
exact (Nat.modEq_iff_dvd' hkl.le).1 hn
refine ⟨f^[k] x, hk, m, ?_, ?_⟩
· intro hm
rw [hm, mul_zero, eq_comm, tsub_eq_zero_iff_le] at this
exact this.not_lt hkl
· rwa [← iterate_mul, this, ← iterate_add_apply, tsub_add_cancel_of_le]
exact hkl.le
end Conservative
end MeasureTheory
|
Dynamics\Ergodic\Ergodic.lean | /-
Copyright (c) 2022 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Dynamics.Ergodic.MeasurePreserving
/-!
# Ergodic maps and measures
Let `f : α → α` be measure preserving with respect to a measure `μ`. We say `f` is ergodic with
respect to `μ` (or `μ` is ergodic with respect to `f`) if the only measurable sets `s` such that
`f⁻¹' s = s` are either almost empty or full.
In this file we define ergodic maps / measures together with quasi-ergodic maps / measures and
provide some basic API. Quasi-ergodicity is a weaker condition than ergodicity for which the measure
preserving condition is relaxed to quasi measure preserving.
# Main definitions:
* `PreErgodic`: the ergodicity condition without the measure preserving condition. This exists
to share code between the `Ergodic` and `QuasiErgodic` definitions.
* `Ergodic`: the definition of ergodic maps / measures.
* `QuasiErgodic`: the definition of quasi ergodic maps / measures.
* `Ergodic.quasiErgodic`: an ergodic map / measure is quasi ergodic.
* `QuasiErgodic.ae_empty_or_univ'`: when the map is quasi measure preserving, one may relax the
strict invariance condition to almost invariance in the ergodicity condition.
-/
open Set Function Filter MeasureTheory MeasureTheory.Measure
open ENNReal
variable {α : Type*} {m : MeasurableSpace α} (f : α → α) {s : Set α}
/-- A map `f : α → α` is said to be pre-ergodic with respect to a measure `μ` if any measurable
strictly invariant set is either almost empty or full. -/
structure PreErgodic (μ : Measure α := by volume_tac) : Prop where
ae_empty_or_univ : ∀ ⦃s⦄, MeasurableSet s → f ⁻¹' s = s → s =ᵐ[μ] (∅ : Set α) ∨ s =ᵐ[μ] univ
/-- A map `f : α → α` is said to be ergodic with respect to a measure `μ` if it is measure
preserving and pre-ergodic. -/
-- porting note (#5171): removed @[nolint has_nonempty_instance]
structure Ergodic (μ : Measure α := by volume_tac) extends
MeasurePreserving f μ μ, PreErgodic f μ : Prop
/-- A map `f : α → α` is said to be quasi ergodic with respect to a measure `μ` if it is quasi
measure preserving and pre-ergodic. -/
-- porting note (#5171): removed @[nolint has_nonempty_instance]
structure QuasiErgodic (μ : Measure α := by volume_tac) extends
QuasiMeasurePreserving f μ μ, PreErgodic f μ : Prop
variable {f} {μ : Measure α}
namespace PreErgodic
theorem measure_self_or_compl_eq_zero (hf : PreErgodic f μ) (hs : MeasurableSet s)
(hs' : f ⁻¹' s = s) : μ s = 0 ∨ μ sᶜ = 0 := by
simpa using hf.ae_empty_or_univ hs hs'
theorem ae_mem_or_ae_nmem (hf : PreErgodic f μ) (hsm : MeasurableSet s) (hs : f ⁻¹' s = s) :
(∀ᵐ x ∂μ, x ∈ s) ∨ ∀ᵐ x ∂μ, x ∉ s :=
(hf.ae_empty_or_univ hsm hs).symm.imp eventuallyEq_univ.1 eventuallyEq_empty.1
/-- On a probability space, the (pre)ergodicity condition is a zero one law. -/
theorem prob_eq_zero_or_one [IsProbabilityMeasure μ] (hf : PreErgodic f μ) (hs : MeasurableSet s)
(hs' : f ⁻¹' s = s) : μ s = 0 ∨ μ s = 1 := by
simpa [hs] using hf.measure_self_or_compl_eq_zero hs hs'
theorem of_iterate (n : ℕ) (hf : PreErgodic f^[n] μ) : PreErgodic f μ :=
⟨fun _ hs hs' => hf.ae_empty_or_univ hs <| IsFixedPt.preimage_iterate hs' n⟩
end PreErgodic
namespace MeasureTheory.MeasurePreserving
variable {β : Type*} {m' : MeasurableSpace β} {μ' : Measure β} {s' : Set β} {g : α → β}
theorem preErgodic_of_preErgodic_conjugate (hg : MeasurePreserving g μ μ') (hf : PreErgodic f μ)
{f' : β → β} (h_comm : g ∘ f = f' ∘ g) : PreErgodic f' μ' :=
⟨by
intro s hs₀ hs₁
replace hs₁ : f ⁻¹' (g ⁻¹' s) = g ⁻¹' s := by rw [← preimage_comp, h_comm, preimage_comp, hs₁]
cases' hf.ae_empty_or_univ (hg.measurable hs₀) hs₁ with hs₂ hs₂ <;> [left; right]
· simpa only [ae_eq_empty, hg.measure_preimage hs₀.nullMeasurableSet] using hs₂
· simpa only [ae_eq_univ, ← preimage_compl,
hg.measure_preimage hs₀.compl.nullMeasurableSet] using hs₂⟩
theorem preErgodic_conjugate_iff {e : α ≃ᵐ β} (h : MeasurePreserving e μ μ') :
PreErgodic (e ∘ f ∘ e.symm) μ' ↔ PreErgodic f μ := by
refine ⟨fun hf => preErgodic_of_preErgodic_conjugate (h.symm e) hf ?_,
fun hf => preErgodic_of_preErgodic_conjugate h hf ?_⟩
· change (e.symm ∘ e) ∘ f ∘ e.symm = f ∘ e.symm
rw [MeasurableEquiv.symm_comp_self, id_comp]
· change e ∘ f = e ∘ f ∘ e.symm ∘ e
rw [MeasurableEquiv.symm_comp_self, comp_id]
theorem ergodic_conjugate_iff {e : α ≃ᵐ β} (h : MeasurePreserving e μ μ') :
Ergodic (e ∘ f ∘ e.symm) μ' ↔ Ergodic f μ := by
have : MeasurePreserving (e ∘ f ∘ e.symm) μ' μ' ↔ MeasurePreserving f μ μ := by
rw [h.comp_left_iff, (MeasurePreserving.symm e h).comp_right_iff]
replace h : PreErgodic (e ∘ f ∘ e.symm) μ' ↔ PreErgodic f μ := h.preErgodic_conjugate_iff
exact ⟨fun hf => { this.mp hf.toMeasurePreserving, h.mp hf.toPreErgodic with },
fun hf => { this.mpr hf.toMeasurePreserving, h.mpr hf.toPreErgodic with }⟩
end MeasureTheory.MeasurePreserving
namespace QuasiErgodic
/-- For a quasi ergodic map, sets that are almost invariant (rather than strictly invariant) are
still either almost empty or full. -/
theorem ae_empty_or_univ' (hf : QuasiErgodic f μ) (hs : MeasurableSet s) (hs' : f ⁻¹' s =ᵐ[μ] s) :
s =ᵐ[μ] (∅ : Set α) ∨ s =ᵐ[μ] univ := by
obtain ⟨t, h₀, h₁, h₂⟩ := hf.toQuasiMeasurePreserving.exists_preimage_eq_of_preimage_ae hs hs'
rcases hf.ae_empty_or_univ h₀ h₂ with (h₃ | h₃) <;> [left; right] <;> exact ae_eq_trans h₁.symm h₃
/-- For a quasi ergodic map, sets that are almost invariant (rather than strictly invariant) are
still either almost empty or full. -/
theorem ae_empty_or_univ₀ (hf : QuasiErgodic f μ) (hsm : NullMeasurableSet s μ)
(hs : f ⁻¹' s =ᵐ[μ] s) : s =ᵐ[μ] (∅ : Set α) ∨ s =ᵐ[μ] univ :=
let ⟨t, htm, hst⟩ := hsm
have : f ⁻¹' t =ᵐ[μ] t := (hf.preimage_ae_eq hst.symm).trans <| hs.trans hst
(hf.ae_empty_or_univ' htm this).imp hst.trans hst.trans
/-- For a quasi ergodic map, sets that are almost invariant (rather than strictly invariant) are
still either almost empty or full. -/
theorem ae_mem_or_ae_nmem₀ (hf : QuasiErgodic f μ) (hsm : NullMeasurableSet s μ)
(hs : f ⁻¹' s =ᵐ[μ] s) :
(∀ᵐ x ∂μ, x ∈ s) ∨ ∀ᵐ x ∂μ, x ∉ s :=
(hf.ae_empty_or_univ₀ hsm hs).symm.imp (by simp [mem_ae_iff]) (by simp [ae_iff])
end QuasiErgodic
namespace Ergodic
/-- An ergodic map is quasi ergodic. -/
theorem quasiErgodic (hf : Ergodic f μ) : QuasiErgodic f μ :=
{ hf.toPreErgodic, hf.toMeasurePreserving.quasiMeasurePreserving with }
/-- See also `Ergodic.ae_empty_or_univ_of_preimage_ae_le`. -/
theorem ae_empty_or_univ_of_preimage_ae_le' (hf : Ergodic f μ) (hs : MeasurableSet s)
(hs' : f ⁻¹' s ≤ᵐ[μ] s) (h_fin : μ s ≠ ∞) : s =ᵐ[μ] (∅ : Set α) ∨ s =ᵐ[μ] univ := by
refine hf.quasiErgodic.ae_empty_or_univ' hs ?_
refine ae_eq_of_ae_subset_of_measure_ge hs'
(hf.measure_preimage hs.nullMeasurableSet).symm.le ?_ h_fin
exact measurableSet_preimage hf.measurable hs
/-- See also `Ergodic.ae_empty_or_univ_of_ae_le_preimage`. -/
theorem ae_empty_or_univ_of_ae_le_preimage' (hf : Ergodic f μ) (hs : MeasurableSet s)
(hs' : s ≤ᵐ[μ] f ⁻¹' s) (h_fin : μ s ≠ ∞) : s =ᵐ[μ] (∅ : Set α) ∨ s =ᵐ[μ] univ := by
replace h_fin : μ (f ⁻¹' s) ≠ ∞ := by rwa [hf.measure_preimage hs.nullMeasurableSet]
refine hf.quasiErgodic.ae_empty_or_univ' hs ?_
exact (ae_eq_of_ae_subset_of_measure_ge hs'
(hf.measure_preimage hs.nullMeasurableSet).le hs h_fin).symm
/-- See also `Ergodic.ae_empty_or_univ_of_image_ae_le`. -/
theorem ae_empty_or_univ_of_image_ae_le' (hf : Ergodic f μ) (hs : MeasurableSet s)
(hs' : f '' s ≤ᵐ[μ] s) (h_fin : μ s ≠ ∞) : s =ᵐ[μ] (∅ : Set α) ∨ s =ᵐ[μ] univ := by
replace hs' : s ≤ᵐ[μ] f ⁻¹' s :=
(HasSubset.Subset.eventuallyLE (subset_preimage_image f s)).trans
(hf.quasiMeasurePreserving.preimage_mono_ae hs')
exact ae_empty_or_univ_of_ae_le_preimage' hf hs hs' h_fin
section IsFiniteMeasure
variable [IsFiniteMeasure μ]
theorem ae_empty_or_univ_of_preimage_ae_le (hf : Ergodic f μ) (hs : MeasurableSet s)
(hs' : f ⁻¹' s ≤ᵐ[μ] s) : s =ᵐ[μ] (∅ : Set α) ∨ s =ᵐ[μ] univ :=
ae_empty_or_univ_of_preimage_ae_le' hf hs hs' <| measure_ne_top μ s
theorem ae_empty_or_univ_of_ae_le_preimage (hf : Ergodic f μ) (hs : MeasurableSet s)
(hs' : s ≤ᵐ[μ] f ⁻¹' s) : s =ᵐ[μ] (∅ : Set α) ∨ s =ᵐ[μ] univ :=
ae_empty_or_univ_of_ae_le_preimage' hf hs hs' <| measure_ne_top μ s
theorem ae_empty_or_univ_of_image_ae_le (hf : Ergodic f μ) (hs : MeasurableSet s)
(hs' : f '' s ≤ᵐ[μ] s) : s =ᵐ[μ] (∅ : Set α) ∨ s =ᵐ[μ] univ :=
ae_empty_or_univ_of_image_ae_le' hf hs hs' <| measure_ne_top μ s
end IsFiniteMeasure
end Ergodic
|
Dynamics\Ergodic\Function.lean | /-
Copyright (c) 2023 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Dynamics.Ergodic.Ergodic
import Mathlib.MeasureTheory.Function.AEEqFun
/-!
# Functions invariant under (quasi)ergodic map
In this file we prove that an a.e. strongly measurable function `g : α → X`
that is a.e. invariant under a (quasi)ergodic map is a.e. equal to a constant.
We prove several versions of this statement with slightly different measurability assumptions.
We also formulate a version for `MeasureTheory.AEEqFun` functions
with all a.e. equalities replaced with equalities in the quotient space.
-/
open Function Set Filter MeasureTheory Topology TopologicalSpace
variable {α X : Type*} [MeasurableSpace α] {μ : MeasureTheory.Measure α}
/-- Let `f : α → α` be a (quasi)ergodic map. Let `g : α → X` is a null-measurable function
from `α` to a nonempty space with a countable family of measurable sets
separating points of a set `s` such that `f x ∈ s` for a.e. `x`.
If `g` that is a.e.-invariant under `f`, then `g` is a.e. constant. -/
theorem QuasiErgodic.ae_eq_const_of_ae_eq_comp_of_ae_range₀ [Nonempty X] [MeasurableSpace X]
{s : Set X} [MeasurableSpace.CountablySeparated s] {f : α → α} {g : α → X}
(h : QuasiErgodic f μ) (hs : ∀ᵐ x ∂μ, g x ∈ s) (hgm : NullMeasurable g μ)
(hg_eq : g ∘ f =ᵐ[μ] g) :
∃ c, g =ᵐ[μ] const α c := by
refine exists_eventuallyEq_const_of_eventually_mem_of_forall_separating MeasurableSet hs ?_
refine fun U hU ↦ h.ae_mem_or_ae_nmem₀ (s := g ⁻¹' U) (hgm hU) ?_b
refine (hg_eq.mono fun x hx ↦ ?_).set_eq
rw [← preimage_comp, mem_preimage, mem_preimage, hx]
section CountableSeparatingOnUniv
variable [Nonempty X] [MeasurableSpace X] [MeasurableSpace.CountablySeparated X]
{f : α → α} {g : α → X}
/-- Let `f : α → α` be a (pre)ergodic map.
Let `g : α → X` be a measurable function from `α` to a nonempty measurable space
with a countable family of measurable sets separating the points of `X`.
If `g` is invariant under `f`, then `g` is a.e. constant. -/
theorem PreErgodic.ae_eq_const_of_ae_eq_comp (h : PreErgodic f μ) (hgm : Measurable g)
(hg_eq : g ∘ f = g) : ∃ c, g =ᵐ[μ] const α c :=
exists_eventuallyEq_const_of_forall_separating MeasurableSet fun U hU ↦
h.ae_mem_or_ae_nmem (s := g ⁻¹' U) (hgm hU) <| by rw [← preimage_comp, hg_eq]
/-- Let `f : α → α` be a quasi ergodic map.
Let `g : α → X` be a null-measurable function from `α` to a nonempty measurable space
with a countable family of measurable sets separating the points of `X`.
If `g` is a.e.-invariant under `f`, then `g` is a.e. constant. -/
theorem QuasiErgodic.ae_eq_const_of_ae_eq_comp₀ (h : QuasiErgodic f μ) (hgm : NullMeasurable g μ)
(hg_eq : g ∘ f =ᵐ[μ] g) : ∃ c, g =ᵐ[μ] const α c :=
h.ae_eq_const_of_ae_eq_comp_of_ae_range₀ (s := univ) univ_mem hgm hg_eq
/-- Let `f : α → α` be an ergodic map.
Let `g : α → X` be a null-measurable function from `α` to a nonempty measurable space
with a countable family of measurable sets separating the points of `X`.
If `g` is a.e.-invariant under `f`, then `g` is a.e. constant. -/
theorem Ergodic.ae_eq_const_of_ae_eq_comp₀ (h : Ergodic f μ) (hgm : NullMeasurable g μ)
(hg_eq : g ∘ f =ᵐ[μ] g) : ∃ c, g =ᵐ[μ] const α c :=
h.quasiErgodic.ae_eq_const_of_ae_eq_comp₀ hgm hg_eq
end CountableSeparatingOnUniv
variable [TopologicalSpace X] [MetrizableSpace X] [Nonempty X] {f : α → α}
namespace QuasiErgodic
/-- Let `f : α → α` be a quasi ergodic map.
Let `g : α → X` be an a.e. strongly measurable function
from `α` to a nonempty metrizable topological space.
If `g` is a.e.-invariant under `f`, then `g` is a.e. constant. -/
theorem ae_eq_const_of_ae_eq_comp_ae {g : α → X} (h : QuasiErgodic f μ)
(hgm : AEStronglyMeasurable g μ) (hg_eq : g ∘ f =ᵐ[μ] g) : ∃ c, g =ᵐ[μ] const α c := by
borelize X
rcases hgm.isSeparable_ae_range with ⟨t, ht, hgt⟩
haveI := ht.secondCountableTopology
exact h.ae_eq_const_of_ae_eq_comp_of_ae_range₀ hgt hgm.aemeasurable.nullMeasurable hg_eq
theorem eq_const_of_compQuasiMeasurePreserving_eq (h : QuasiErgodic f μ) {g : α →ₘ[μ] X}
(hg_eq : g.compQuasiMeasurePreserving f h.1 = g) : ∃ c, g = .const α c :=
have : g ∘ f =ᵐ[μ] g := (g.coeFn_compQuasiMeasurePreserving h.1).symm.trans
(hg_eq.symm ▸ .refl _ _)
let ⟨c, hc⟩ := h.ae_eq_const_of_ae_eq_comp_ae g.aestronglyMeasurable this
⟨c, AEEqFun.ext <| hc.trans (AEEqFun.coeFn_const _ _).symm⟩
end QuasiErgodic
namespace Ergodic
/-- Let `f : α → α` be an ergodic map.
Let `g : α → X` be an a.e. strongly measurable function
from `α` to a nonempty metrizable topological space.
If `g` is a.e.-invariant under `f`, then `g` is a.e. constant. -/
theorem ae_eq_const_of_ae_eq_comp_ae {g : α → X} (h : Ergodic f μ) (hgm : AEStronglyMeasurable g μ)
(hg_eq : g ∘ f =ᵐ[μ] g) : ∃ c, g =ᵐ[μ] const α c :=
h.quasiErgodic.ae_eq_const_of_ae_eq_comp_ae hgm hg_eq
theorem eq_const_of_compMeasurePreserving_eq (h : Ergodic f μ) {g : α →ₘ[μ] X}
(hg_eq : g.compMeasurePreserving f h.1 = g) : ∃ c, g = .const α c :=
h.quasiErgodic.eq_const_of_compQuasiMeasurePreserving_eq hg_eq
end Ergodic
|
Dynamics\Ergodic\MeasurePreserving.lean | /-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.MeasureTheory.Measure.AEMeasurable
/-!
# Measure preserving maps
We say that `f : α → β` is a measure preserving map w.r.t. measures `μ : Measure α` and
`ν : Measure β` if `f` is measurable and `map f μ = ν`. In this file we define the predicate
`MeasureTheory.MeasurePreserving` and prove its basic properties.
We use the term "measure preserving" because in many applications `α = β` and `μ = ν`.
## References
Partially based on
[this](https://www.isa-afp.org/browser_info/current/AFP/Ergodic_Theory/Measure_Preserving_Transformations.html)
Isabelle formalization.
## Tags
measure preserving map, measure
-/
variable {α β γ δ : Type*} [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ]
[MeasurableSpace δ]
namespace MeasureTheory
open Measure Function Set
variable {μa : Measure α} {μb : Measure β} {μc : Measure γ} {μd : Measure δ}
/-- `f` is a measure preserving map w.r.t. measures `μa` and `μb` if `f` is measurable
and `map f μa = μb`. -/
structure MeasurePreserving (f : α → β)
(μa : Measure α := by volume_tac) (μb : Measure β := by volume_tac) : Prop where
protected measurable : Measurable f
protected map_eq : map f μa = μb
protected theorem _root_.Measurable.measurePreserving
{f : α → β} (h : Measurable f) (μa : Measure α) : MeasurePreserving f μa (map f μa) :=
⟨h, rfl⟩
namespace MeasurePreserving
protected theorem id (μ : Measure α) : MeasurePreserving id μ μ :=
⟨measurable_id, map_id⟩
protected theorem aemeasurable {f : α → β} (hf : MeasurePreserving f μa μb) : AEMeasurable f μa :=
hf.1.aemeasurable
@[nontriviality]
theorem of_isEmpty [IsEmpty β] (f : α → β) (μa : Measure α) (μb : Measure β) :
MeasurePreserving f μa μb :=
⟨measurable_of_subsingleton_codomain _, Subsingleton.elim _ _⟩
theorem symm (e : α ≃ᵐ β) {μa : Measure α} {μb : Measure β} (h : MeasurePreserving e μa μb) :
MeasurePreserving e.symm μb μa :=
⟨e.symm.measurable, by
rw [← h.map_eq, map_map e.symm.measurable e.measurable, e.symm_comp_self, map_id]⟩
theorem restrict_preimage {f : α → β} (hf : MeasurePreserving f μa μb) {s : Set β}
(hs : MeasurableSet s) : MeasurePreserving f (μa.restrict (f ⁻¹' s)) (μb.restrict s) :=
⟨hf.measurable, by rw [← hf.map_eq, restrict_map hf.measurable hs]⟩
theorem restrict_preimage_emb {f : α → β} (hf : MeasurePreserving f μa μb)
(h₂ : MeasurableEmbedding f) (s : Set β) :
MeasurePreserving f (μa.restrict (f ⁻¹' s)) (μb.restrict s) :=
⟨hf.measurable, by rw [← hf.map_eq, h₂.restrict_map]⟩
theorem restrict_image_emb {f : α → β} (hf : MeasurePreserving f μa μb) (h₂ : MeasurableEmbedding f)
(s : Set α) : MeasurePreserving f (μa.restrict s) (μb.restrict (f '' s)) := by
simpa only [Set.preimage_image_eq _ h₂.injective] using hf.restrict_preimage_emb h₂ (f '' s)
theorem aemeasurable_comp_iff {f : α → β} (hf : MeasurePreserving f μa μb)
(h₂ : MeasurableEmbedding f) {g : β → γ} : AEMeasurable (g ∘ f) μa ↔ AEMeasurable g μb := by
rw [← hf.map_eq, h₂.aemeasurable_map_iff]
protected theorem quasiMeasurePreserving {f : α → β} (hf : MeasurePreserving f μa μb) :
QuasiMeasurePreserving f μa μb :=
⟨hf.1, hf.2.absolutelyContinuous⟩
protected theorem comp {g : β → γ} {f : α → β} (hg : MeasurePreserving g μb μc)
(hf : MeasurePreserving f μa μb) : MeasurePreserving (g ∘ f) μa μc :=
⟨hg.1.comp hf.1, by rw [← map_map hg.1 hf.1, hf.2, hg.2]⟩
/-- An alias of `MeasureTheory.MeasurePreserving.comp` with a convenient defeq and argument order
for `MeasurableEquiv` -/
protected theorem trans {e : α ≃ᵐ β} {e' : β ≃ᵐ γ}
{μa : Measure α} {μb : Measure β} {μc : Measure γ}
(h : MeasurePreserving e μa μb) (h' : MeasurePreserving e' μb μc) :
MeasurePreserving (e.trans e') μa μc :=
h'.comp h
protected theorem comp_left_iff {g : α → β} {e : β ≃ᵐ γ} (h : MeasurePreserving e μb μc) :
MeasurePreserving (e ∘ g) μa μc ↔ MeasurePreserving g μa μb := by
refine ⟨fun hg => ?_, fun hg => h.comp hg⟩
convert (MeasurePreserving.symm e h).comp hg
simp [← Function.comp.assoc e.symm e g]
protected theorem comp_right_iff {g : α → β} {e : γ ≃ᵐ α} (h : MeasurePreserving e μc μa) :
MeasurePreserving (g ∘ e) μc μb ↔ MeasurePreserving g μa μb := by
refine ⟨fun hg => ?_, fun hg => hg.comp h⟩
convert hg.comp (MeasurePreserving.symm e h)
simp [Function.comp.assoc g e e.symm]
protected theorem sigmaFinite {f : α → β} (hf : MeasurePreserving f μa μb) [SigmaFinite μb] :
SigmaFinite μa :=
SigmaFinite.of_map μa hf.aemeasurable (by rwa [hf.map_eq])
theorem measure_preimage {f : α → β} (hf : MeasurePreserving f μa μb) {s : Set β}
(hs : NullMeasurableSet s μb) : μa (f ⁻¹' s) = μb s := by
rw [← hf.map_eq] at hs ⊢
rw [map_apply₀ hf.1.aemeasurable hs]
theorem measure_preimage_emb {f : α → β} (hf : MeasurePreserving f μa μb)
(hfe : MeasurableEmbedding f) (s : Set β) : μa (f ⁻¹' s) = μb s := by
rw [← hf.map_eq, hfe.map_apply]
theorem measure_preimage_equiv {f : α ≃ᵐ β} (hf : MeasurePreserving f μa μb) (s : Set β) :
μa (f ⁻¹' s) = μb s :=
measure_preimage_emb hf f.measurableEmbedding s
protected theorem iterate {f : α → α} (hf : MeasurePreserving f μa μa) :
∀ n, MeasurePreserving f^[n] μa μa
| 0 => MeasurePreserving.id μa
| n + 1 => (MeasurePreserving.iterate hf n).comp hf
variable {μ : Measure α} {f : α → α} {s : Set α}
open scoped symmDiff in
lemma measure_symmDiff_preimage_iterate_le
(hf : MeasurePreserving f μ μ) (hs : NullMeasurableSet s μ) (n : ℕ) :
μ (s ∆ (f^[n] ⁻¹' s)) ≤ n • μ (s ∆ (f ⁻¹' s)) := by
induction' n with n ih; · simp
simp only [add_smul, one_smul, ← n.add_one]
refine le_trans (measure_symmDiff_le s (f^[n] ⁻¹' s) (f^[n+1] ⁻¹' s)) (add_le_add ih ?_)
replace hs : NullMeasurableSet (s ∆ (f ⁻¹' s)) μ :=
hs.symmDiff <| hs.preimage hf.quasiMeasurePreserving
rw [iterate_succ', preimage_comp, ← preimage_symmDiff, (hf.iterate n).measure_preimage hs]
/-- If `μ univ < n * μ s` and `f` is a map preserving measure `μ`,
then for some `x ∈ s` and `0 < m < n`, `f^[m] x ∈ s`. -/
theorem exists_mem_iterate_mem_of_volume_lt_mul_volume (hf : MeasurePreserving f μ μ)
(hs : NullMeasurableSet s μ) {n : ℕ} (hvol : μ (Set.univ : Set α) < n * μ s) :
∃ x ∈ s, ∃ m ∈ Set.Ioo 0 n, f^[m] x ∈ s := by
have A : ∀ m, NullMeasurableSet (f^[m] ⁻¹' s) μ := fun m ↦
hs.preimage (hf.iterate m).quasiMeasurePreserving
have B : ∀ m, μ (f^[m] ⁻¹' s) = μ s := fun m ↦ (hf.iterate m).measure_preimage hs
have : μ (univ : Set α) < ∑ m ∈ Finset.range n, μ (f^[m] ⁻¹' s) := by simpa [B]
obtain ⟨i, hi, j, hj, hij, x, hxi : f^[i] x ∈ s, hxj : f^[j] x ∈ s⟩ :
∃ i < n, ∃ j < n, i ≠ j ∧ (f^[i] ⁻¹' s ∩ f^[j] ⁻¹' s).Nonempty := by
simpa using exists_nonempty_inter_of_measure_univ_lt_sum_measure μ (fun m _ ↦ A m) this
wlog hlt : i < j generalizing i j
· exact this j hj i hi hij.symm hxj hxi (hij.lt_or_lt.resolve_left hlt)
refine ⟨f^[i] x, hxi, j - i, ⟨tsub_pos_of_lt hlt, lt_of_le_of_lt (j.sub_le i) hj⟩, ?_⟩
rwa [← iterate_add_apply, tsub_add_cancel_of_le hlt.le]
/-- A self-map preserving a finite measure is conservative: if `μ s ≠ 0`, then at least one point
`x ∈ s` comes back to `s` under iterations of `f`. Actually, a.e. point of `s` comes back to `s`
infinitely many times, see `MeasureTheory.MeasurePreserving.conservative` and theorems about
`MeasureTheory.Conservative`. -/
theorem exists_mem_iterate_mem [IsFiniteMeasure μ] (hf : MeasurePreserving f μ μ)
(hs : NullMeasurableSet s μ) (hs' : μ s ≠ 0) : ∃ x ∈ s, ∃ m ≠ 0, f^[m] x ∈ s := by
rcases ENNReal.exists_nat_mul_gt hs' (measure_ne_top μ (Set.univ : Set α)) with ⟨N, hN⟩
rcases hf.exists_mem_iterate_mem_of_volume_lt_mul_volume hs hN with ⟨x, hx, m, hm, hmx⟩
exact ⟨x, hx, m, hm.1.ne', hmx⟩
end MeasurePreserving
namespace MeasurableEquiv
theorem measurePreserving_symm (μ : Measure α) (e : α ≃ᵐ β) :
MeasurePreserving e.symm (map e μ) μ :=
(e.measurable.measurePreserving μ).symm _
end MeasurableEquiv
end MeasureTheory
|
Dynamics\FixedPoints\Basic.lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Data.Set.Function
import Mathlib.Logic.Function.Iterate
import Mathlib.GroupTheory.Perm.Basic
/-!
# Fixed points of a self-map
In this file we define
* the predicate `IsFixedPt f x := f x = x`;
* the set `fixedPoints f` of fixed points of a self-map `f`.
We also prove some simple lemmas about `IsFixedPt` and `∘`, `iterate`, and `Semiconj`.
## Tags
fixed point
-/
open Equiv
universe u v
variable {α : Type u} {β : Type v} {f fa g : α → α} {x y : α} {fb : β → β} {m n k : ℕ} {e : Perm α}
namespace Function
open Function (Commute)
/-- Every point is a fixed point of `id`. -/
theorem isFixedPt_id (x : α) : IsFixedPt id x :=
(rfl : _)
namespace IsFixedPt
instance decidable [h : DecidableEq α] {f : α → α} {x : α} : Decidable (IsFixedPt f x) :=
h (f x) x
/-- If `x` is a fixed point of `f`, then `f x = x`. This is useful, e.g., for `rw` or `simp`. -/
protected theorem eq (hf : IsFixedPt f x) : f x = x :=
hf
/-- If `x` is a fixed point of `f` and `g`, then it is a fixed point of `f ∘ g`. -/
protected theorem comp (hf : IsFixedPt f x) (hg : IsFixedPt g x) : IsFixedPt (f ∘ g) x :=
calc
f (g x) = f x := congr_arg f hg
_ = x := hf
/-- If `x` is a fixed point of `f`, then it is a fixed point of `f^[n]`. -/
protected theorem iterate (hf : IsFixedPt f x) (n : ℕ) : IsFixedPt f^[n] x :=
iterate_fixed hf n
/-- If `x` is a fixed point of `f ∘ g` and `g`, then it is a fixed point of `f`. -/
theorem left_of_comp (hfg : IsFixedPt (f ∘ g) x) (hg : IsFixedPt g x) : IsFixedPt f x :=
calc
f x = f (g x) := congr_arg f hg.symm
_ = x := hfg
/-- If `x` is a fixed point of `f` and `g` is a left inverse of `f`, then `x` is a fixed
point of `g`. -/
theorem to_leftInverse (hf : IsFixedPt f x) (h : LeftInverse g f) : IsFixedPt g x :=
calc
g x = g (f x) := congr_arg g hf.symm
_ = x := h x
/-- If `g` (semi)conjugates `fa` to `fb`, then it sends fixed points of `fa` to fixed points
of `fb`. -/
protected theorem map {x : α} (hx : IsFixedPt fa x) {g : α → β} (h : Semiconj g fa fb) :
IsFixedPt fb (g x) :=
calc
fb (g x) = g (fa x) := (h.eq x).symm
_ = g x := congr_arg g hx
protected theorem apply {x : α} (hx : IsFixedPt f x) : IsFixedPt f (f x) := by convert hx
theorem preimage_iterate {s : Set α} (h : IsFixedPt (Set.preimage f) s) (n : ℕ) :
IsFixedPt (Set.preimage f^[n]) s := by
rw [Set.preimage_iterate_eq]
exact h.iterate n
lemma image_iterate {s : Set α} (h : IsFixedPt (Set.image f) s) (n : ℕ) :
IsFixedPt (Set.image f^[n]) s :=
Set.image_iterate_eq ▸ h.iterate n
protected theorem equiv_symm (h : IsFixedPt e x) : IsFixedPt e.symm x :=
h.to_leftInverse e.leftInverse_symm
protected theorem perm_inv (h : IsFixedPt e x) : IsFixedPt (⇑e⁻¹) x :=
h.equiv_symm
protected theorem perm_pow (h : IsFixedPt e x) (n : ℕ) : IsFixedPt (⇑(e ^ n)) x := h.iterate _
protected theorem perm_zpow (h : IsFixedPt e x) : ∀ n : ℤ, IsFixedPt (⇑(e ^ n)) x
| Int.ofNat _ => h.perm_pow _
| Int.negSucc n => (h.perm_pow <| n + 1).perm_inv
end IsFixedPt
@[simp]
theorem Injective.isFixedPt_apply_iff (hf : Injective f) {x : α} :
IsFixedPt f (f x) ↔ IsFixedPt f x :=
⟨fun h => hf h.eq, IsFixedPt.apply⟩
/-- The set of fixed points of a map `f : α → α`. -/
def fixedPoints (f : α → α) : Set α :=
{ x : α | IsFixedPt f x }
instance fixedPoints.decidable [DecidableEq α] (f : α → α) (x : α) :
Decidable (x ∈ fixedPoints f) :=
IsFixedPt.decidable
@[simp]
theorem mem_fixedPoints : x ∈ fixedPoints f ↔ IsFixedPt f x :=
Iff.rfl
theorem mem_fixedPoints_iff {α : Type*} {f : α → α} {x : α} : x ∈ fixedPoints f ↔ f x = x := by
rfl
@[simp]
theorem fixedPoints_id : fixedPoints (@id α) = Set.univ :=
Set.ext fun _ => by simpa using isFixedPt_id _
theorem fixedPoints_subset_range : fixedPoints f ⊆ Set.range f := fun x hx => ⟨x, hx⟩
/-- If `g` semiconjugates `fa` to `fb`, then it sends fixed points of `fa` to fixed points
of `fb`. -/
theorem Semiconj.mapsTo_fixedPoints {g : α → β} (h : Semiconj g fa fb) :
Set.MapsTo g (fixedPoints fa) (fixedPoints fb) := fun _ hx => hx.map h
/-- Any two maps `f : α → β` and `g : β → α` are inverse of each other on the sets of fixed points
of `f ∘ g` and `g ∘ f`, respectively. -/
theorem invOn_fixedPoints_comp (f : α → β) (g : β → α) :
Set.InvOn f g (fixedPoints <| f ∘ g) (fixedPoints <| g ∘ f) :=
⟨fun _ => id, fun _ => id⟩
/-- Any map `f` sends fixed points of `g ∘ f` to fixed points of `f ∘ g`. -/
theorem mapsTo_fixedPoints_comp (f : α → β) (g : β → α) :
Set.MapsTo f (fixedPoints <| g ∘ f) (fixedPoints <| f ∘ g) := fun _ hx => hx.map fun _ => rfl
/-- Given two maps `f : α → β` and `g : β → α`, `g` is a bijective map between the fixed points
of `f ∘ g` and the fixed points of `g ∘ f`. The inverse map is `f`, see `invOn_fixedPoints_comp`. -/
theorem bijOn_fixedPoints_comp (f : α → β) (g : β → α) :
Set.BijOn g (fixedPoints <| f ∘ g) (fixedPoints <| g ∘ f) :=
(invOn_fixedPoints_comp f g).bijOn (mapsTo_fixedPoints_comp g f) (mapsTo_fixedPoints_comp f g)
/-- If self-maps `f` and `g` commute, then they are inverse of each other on the set of fixed points
of `f ∘ g`. This is a particular case of `Function.invOn_fixedPoints_comp`. -/
theorem Commute.invOn_fixedPoints_comp (h : Commute f g) :
Set.InvOn f g (fixedPoints <| f ∘ g) (fixedPoints <| f ∘ g) := by
simpa only [h.comp_eq] using Function.invOn_fixedPoints_comp f g
/-- If self-maps `f` and `g` commute, then `f` is bijective on the set of fixed points of `f ∘ g`.
This is a particular case of `Function.bijOn_fixedPoints_comp`. -/
theorem Commute.left_bijOn_fixedPoints_comp (h : Commute f g) :
Set.BijOn f (fixedPoints <| f ∘ g) (fixedPoints <| f ∘ g) := by
simpa only [h.comp_eq] using bijOn_fixedPoints_comp g f
/-- If self-maps `f` and `g` commute, then `g` is bijective on the set of fixed points of `f ∘ g`.
This is a particular case of `Function.bijOn_fixedPoints_comp`. -/
theorem Commute.right_bijOn_fixedPoints_comp (h : Commute f g) :
Set.BijOn g (fixedPoints <| f ∘ g) (fixedPoints <| f ∘ g) := by
simpa only [h.comp_eq] using bijOn_fixedPoints_comp f g
end Function
|
Dynamics\FixedPoints\Topology.lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Johannes Hölzl
-/
import Mathlib.Dynamics.FixedPoints.Basic
import Mathlib.Topology.Separation
/-!
# Topological properties of fixed points
Currently this file contains two lemmas:
- `isFixedPt_of_tendsto_iterate`: if `f^n(x) → y` and `f` is continuous at `y`, then `f y = y`;
- `isClosed_fixedPoints`: the set of fixed points of a continuous map is a closed set.
## TODO
fixed points, iterates
-/
variable {α : Type*} [TopologicalSpace α] [T2Space α] {f : α → α}
open Function Filter
open Topology
/-- If the iterates `f^[n] x` converge to `y` and `f` is continuous at `y`,
then `y` is a fixed point for `f`. -/
theorem isFixedPt_of_tendsto_iterate {x y : α} (hy : Tendsto (fun n => f^[n] x) atTop (𝓝 y))
(hf : ContinuousAt f y) : IsFixedPt f y := by
refine tendsto_nhds_unique ((tendsto_add_atTop_iff_nat 1).1 ?_) hy
simp only [iterate_succ' f]
exact hf.tendsto.comp hy
/-- The set of fixed points of a continuous map is a closed set. -/
theorem isClosed_fixedPoints (hf : Continuous f) : IsClosed (fixedPoints f) :=
isClosed_eq hf continuous_id
|
FieldTheory\AbelRuffini.lean | /-
Copyright (c) 2020 Thomas Browning and Patrick Lutz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning, Patrick Lutz
-/
import Mathlib.GroupTheory.Solvable
import Mathlib.FieldTheory.PolynomialGaloisGroup
import Mathlib.RingTheory.RootsOfUnity.Basic
/-!
# The Abel-Ruffini Theorem
This file proves one direction of the Abel-Ruffini theorem, namely that if an element is solvable
by radicals, then its minimal polynomial has solvable Galois group.
## Main definitions
* `solvableByRad F E` : the intermediate field of solvable-by-radicals elements
## Main results
* the Abel-Ruffini Theorem `solvableByRad.isSolvable'` : An irreducible polynomial with a root
that is solvable by radicals has a solvable Galois group.
-/
noncomputable section
open Polynomial IntermediateField
section AbelRuffini
variable {F : Type*} [Field F] {E : Type*} [Field E] [Algebra F E]
theorem gal_zero_isSolvable : IsSolvable (0 : F[X]).Gal := by infer_instance
theorem gal_one_isSolvable : IsSolvable (1 : F[X]).Gal := by infer_instance
theorem gal_C_isSolvable (x : F) : IsSolvable (C x).Gal := by infer_instance
theorem gal_X_isSolvable : IsSolvable (X : F[X]).Gal := by infer_instance
theorem gal_X_sub_C_isSolvable (x : F) : IsSolvable (X - C x).Gal := by infer_instance
theorem gal_X_pow_isSolvable (n : ℕ) : IsSolvable (X ^ n : F[X]).Gal := by infer_instance
theorem gal_mul_isSolvable {p q : F[X]} (_ : IsSolvable p.Gal) (_ : IsSolvable q.Gal) :
IsSolvable (p * q).Gal :=
solvable_of_solvable_injective (Gal.restrictProd_injective p q)
theorem gal_prod_isSolvable {s : Multiset F[X]} (hs : ∀ p ∈ s, IsSolvable (Gal p)) :
IsSolvable s.prod.Gal := by
apply Multiset.induction_on' s
· exact gal_one_isSolvable
· intro p t hps _ ht
rw [Multiset.insert_eq_cons, Multiset.prod_cons]
exact gal_mul_isSolvable (hs p hps) ht
theorem gal_isSolvable_of_splits {p q : F[X]}
(_ : Fact (p.Splits (algebraMap F q.SplittingField))) (hq : IsSolvable q.Gal) :
IsSolvable p.Gal :=
haveI : IsSolvable (q.SplittingField ≃ₐ[F] q.SplittingField) := hq
solvable_of_surjective (AlgEquiv.restrictNormalHom_surjective q.SplittingField)
theorem gal_isSolvable_tower (p q : F[X]) (hpq : p.Splits (algebraMap F q.SplittingField))
(hp : IsSolvable p.Gal) (hq : IsSolvable (q.map (algebraMap F p.SplittingField)).Gal) :
IsSolvable q.Gal := by
let K := p.SplittingField
let L := q.SplittingField
haveI : Fact (p.Splits (algebraMap F L)) := ⟨hpq⟩
let ϕ : (L ≃ₐ[K] L) ≃* (q.map (algebraMap F K)).Gal :=
(IsSplittingField.algEquiv L (q.map (algebraMap F K))).autCongr
have ϕ_inj : Function.Injective ϕ.toMonoidHom := ϕ.injective
haveI : IsSolvable (K ≃ₐ[F] K) := hp
haveI : IsSolvable (L ≃ₐ[K] L) := solvable_of_solvable_injective ϕ_inj
exact isSolvable_of_isScalarTower F p.SplittingField q.SplittingField
section GalXPowSubC
theorem gal_X_pow_sub_one_isSolvable (n : ℕ) : IsSolvable (X ^ n - 1 : F[X]).Gal := by
by_cases hn : n = 0
· rw [hn, pow_zero, sub_self]
exact gal_zero_isSolvable
have hn' : 0 < n := pos_iff_ne_zero.mpr hn
have hn'' : (X ^ n - 1 : F[X]) ≠ 0 := X_pow_sub_C_ne_zero hn' 1
apply isSolvable_of_comm
intro σ τ
ext a ha
simp only [mem_rootSet_of_ne hn'', map_sub, aeval_X_pow, aeval_one, sub_eq_zero] at ha
have key : ∀ σ : (X ^ n - 1 : F[X]).Gal, ∃ m : ℕ, σ a = a ^ m := by
intro σ
lift n to ℕ+ using hn'
exact map_rootsOfUnity_eq_pow_self σ.toAlgHom (rootsOfUnity.mkOfPowEq a ha)
obtain ⟨c, hc⟩ := key σ
obtain ⟨d, hd⟩ := key τ
rw [σ.mul_apply, τ.mul_apply, hc, map_pow, hd, map_pow, hc, ← pow_mul, pow_mul']
theorem gal_X_pow_sub_C_isSolvable_aux (n : ℕ) (a : F)
(h : (X ^ n - 1 : F[X]).Splits (RingHom.id F)) : IsSolvable (X ^ n - C a).Gal := by
by_cases ha : a = 0
· rw [ha, C_0, sub_zero]
exact gal_X_pow_isSolvable n
have ha' : algebraMap F (X ^ n - C a).SplittingField a ≠ 0 :=
mt ((injective_iff_map_eq_zero _).mp (RingHom.injective _) a) ha
by_cases hn : n = 0
· rw [hn, pow_zero, ← C_1, ← C_sub]
exact gal_C_isSolvable (1 - a)
have hn' : 0 < n := pos_iff_ne_zero.mpr hn
have hn'' : X ^ n - C a ≠ 0 := X_pow_sub_C_ne_zero hn' a
have hn''' : (X ^ n - 1 : F[X]) ≠ 0 := X_pow_sub_C_ne_zero hn' 1
have mem_range : ∀ {c : (X ^ n - C a).SplittingField},
(c ^ n = 1 → (∃ d, algebraMap F (X ^ n - C a).SplittingField d = c)) := fun {c} hc =>
RingHom.mem_range.mp (minpoly.mem_range_of_degree_eq_one F c (h.def.resolve_left hn'''
(minpoly.irreducible ((SplittingField.instNormal (X ^ n - C a)).isIntegral c))
(minpoly.dvd F c (by rwa [map_id, map_sub, sub_eq_zero, aeval_X_pow, aeval_one]))))
apply isSolvable_of_comm
intro σ τ
ext b hb
rw [mem_rootSet_of_ne hn'', map_sub, aeval_X_pow, aeval_C, sub_eq_zero] at hb
have hb' : b ≠ 0 := by
intro hb'
rw [hb', zero_pow hn] at hb
exact ha' hb.symm
have key : ∀ σ : (X ^ n - C a).Gal, ∃ c, σ b = b * algebraMap F _ c := by
intro σ
have key : (σ b / b) ^ n = 1 := by rw [div_pow, ← map_pow, hb, σ.commutes, div_self ha']
obtain ⟨c, hc⟩ := mem_range key
use c
rw [hc, mul_div_cancel₀ (σ b) hb']
obtain ⟨c, hc⟩ := key σ
obtain ⟨d, hd⟩ := key τ
rw [σ.mul_apply, τ.mul_apply, hc, map_mul, τ.commutes, hd, map_mul, σ.commutes, hc,
mul_assoc, mul_assoc, mul_right_inj' hb', mul_comm]
theorem splits_X_pow_sub_one_of_X_pow_sub_C {F : Type*} [Field F] {E : Type*} [Field E]
(i : F →+* E) (n : ℕ) {a : F} (ha : a ≠ 0) (h : (X ^ n - C a).Splits i) :
(X ^ n - 1 : F[X]).Splits i := by
have ha' : i a ≠ 0 := mt ((injective_iff_map_eq_zero i).mp i.injective a) ha
by_cases hn : n = 0
· rw [hn, pow_zero, sub_self]
exact splits_zero i
have hn' : 0 < n := pos_iff_ne_zero.mpr hn
have hn'' : (X ^ n - C a).degree ≠ 0 :=
ne_of_eq_of_ne (degree_X_pow_sub_C hn' a) (mt WithBot.coe_eq_coe.mp hn)
obtain ⟨b, hb⟩ := exists_root_of_splits i h hn''
rw [eval₂_sub, eval₂_X_pow, eval₂_C, sub_eq_zero] at hb
have hb' : b ≠ 0 := by
intro hb'
rw [hb', zero_pow hn] at hb
exact ha' hb.symm
let s := ((X ^ n - C a).map i).roots
have hs : _ = _ * (s.map _).prod := eq_prod_roots_of_splits h
rw [leadingCoeff_X_pow_sub_C hn', RingHom.map_one, C_1, one_mul] at hs
have hs' : Multiset.card s = n := (natDegree_eq_card_roots h).symm.trans natDegree_X_pow_sub_C
apply @splits_of_exists_multiset F E _ _ i (X ^ n - 1) (s.map fun c : E => c / b)
rw [leadingCoeff_X_pow_sub_one hn', RingHom.map_one, C_1, one_mul, Multiset.map_map]
have C_mul_C : C (i a⁻¹) * C (i a) = 1 := by
rw [← C_mul, ← i.map_mul, inv_mul_cancel ha, i.map_one, C_1]
have key1 : (X ^ n - 1 : F[X]).map i = C (i a⁻¹) * ((X ^ n - C a).map i).comp (C b * X) := by
rw [Polynomial.map_sub, Polynomial.map_sub, Polynomial.map_pow, map_X, map_C,
Polynomial.map_one, sub_comp, pow_comp, X_comp, C_comp, mul_pow, ← C_pow, hb, mul_sub, ←
mul_assoc, C_mul_C, one_mul]
have key2 : ((fun q : E[X] => q.comp (C b * X)) ∘ fun c : E => X - C c) = fun c : E =>
C b * (X - C (c / b)) := by
ext1 c
dsimp only [Function.comp_apply]
rw [sub_comp, X_comp, C_comp, mul_sub, ← C_mul, mul_div_cancel₀ c hb']
rw [key1, hs, multiset_prod_comp, Multiset.map_map, key2, Multiset.prod_map_mul,
-- Porting note: needed for `Multiset.map_const` to work
show (fun (_ : E) => C b) = Function.const E (C b) by rfl,
Multiset.map_const, Multiset.prod_replicate, hs', ← C_pow, hb, ← mul_assoc, C_mul_C, one_mul]
rfl
theorem gal_X_pow_sub_C_isSolvable (n : ℕ) (x : F) : IsSolvable (X ^ n - C x).Gal := by
by_cases hx : x = 0
· rw [hx, C_0, sub_zero]
exact gal_X_pow_isSolvable n
apply gal_isSolvable_tower (X ^ n - 1) (X ^ n - C x)
· exact splits_X_pow_sub_one_of_X_pow_sub_C _ n hx (SplittingField.splits _)
· exact gal_X_pow_sub_one_isSolvable n
· rw [Polynomial.map_sub, Polynomial.map_pow, map_X, map_C]
apply gal_X_pow_sub_C_isSolvable_aux
have key := SplittingField.splits (X ^ n - 1 : F[X])
rwa [← splits_id_iff_splits, Polynomial.map_sub, Polynomial.map_pow, map_X,
Polynomial.map_one] at key
end GalXPowSubC
variable (F)
/-- Inductive definition of solvable by radicals -/
inductive IsSolvableByRad : E → Prop
| base (α : F) : IsSolvableByRad (algebraMap F E α)
| add (α β : E) : IsSolvableByRad α → IsSolvableByRad β → IsSolvableByRad (α + β)
| neg (α : E) : IsSolvableByRad α → IsSolvableByRad (-α)
| mul (α β : E) : IsSolvableByRad α → IsSolvableByRad β → IsSolvableByRad (α * β)
| inv (α : E) : IsSolvableByRad α → IsSolvableByRad α⁻¹
| rad (α : E) (n : ℕ) (hn : n ≠ 0) : IsSolvableByRad (α ^ n) → IsSolvableByRad α
variable (E)
/-- The intermediate field of solvable-by-radicals elements -/
def solvableByRad : IntermediateField F E where
carrier := IsSolvableByRad F
zero_mem' := by
change IsSolvableByRad F 0
convert IsSolvableByRad.base (E := E) (0 : F); rw [RingHom.map_zero]
add_mem' := by apply IsSolvableByRad.add
one_mem' := by
change IsSolvableByRad F 1
convert IsSolvableByRad.base (E := E) (1 : F); rw [RingHom.map_one]
mul_mem' := by apply IsSolvableByRad.mul
inv_mem' := IsSolvableByRad.inv
algebraMap_mem' := IsSolvableByRad.base
namespace solvableByRad
variable {F} {E} {α : E}
theorem induction (P : solvableByRad F E → Prop)
(base : ∀ α : F, P (algebraMap F (solvableByRad F E) α))
(add : ∀ α β : solvableByRad F E, P α → P β → P (α + β))
(neg : ∀ α : solvableByRad F E, P α → P (-α))
(mul : ∀ α β : solvableByRad F E, P α → P β → P (α * β))
(inv : ∀ α : solvableByRad F E, P α → P α⁻¹)
(rad : ∀ α : solvableByRad F E, ∀ n : ℕ, n ≠ 0 → P (α ^ n) → P α) (α : solvableByRad F E) :
P α := by
revert α
suffices ∀ α : E, IsSolvableByRad F α → ∃ β : solvableByRad F E, ↑β = α ∧ P β by
intro α
obtain ⟨α₀, hα₀, Pα⟩ := this α (Subtype.mem α)
convert Pα
exact Subtype.ext hα₀.symm
apply IsSolvableByRad.rec
· exact fun α => ⟨algebraMap F (solvableByRad F E) α, rfl, base α⟩
· intro α β _ _ Pα Pβ
obtain ⟨⟨α₀, hα₀, Pα⟩, β₀, hβ₀, Pβ⟩ := Pα, Pβ
exact ⟨α₀ + β₀, by rw [← hα₀, ← hβ₀]; rfl, add α₀ β₀ Pα Pβ⟩
· intro α _ Pα
obtain ⟨α₀, hα₀, Pα⟩ := Pα
exact ⟨-α₀, by rw [← hα₀]; rfl, neg α₀ Pα⟩
· intro α β _ _ Pα Pβ
obtain ⟨⟨α₀, hα₀, Pα⟩, β₀, hβ₀, Pβ⟩ := Pα, Pβ
exact ⟨α₀ * β₀, by rw [← hα₀, ← hβ₀]; rfl, mul α₀ β₀ Pα Pβ⟩
· intro α _ Pα
obtain ⟨α₀, hα₀, Pα⟩ := Pα
exact ⟨α₀⁻¹, by rw [← hα₀]; rfl, inv α₀ Pα⟩
· intro α n hn hα Pα
obtain ⟨α₀, hα₀, Pα⟩ := Pα
refine ⟨⟨α, IsSolvableByRad.rad α n hn hα⟩, rfl, rad _ n hn ?_⟩
convert Pα
exact Subtype.ext (Eq.trans ((solvableByRad F E).coe_pow _ n) hα₀.symm)
theorem isIntegral (α : solvableByRad F E) : IsIntegral F α := by
revert α
apply solvableByRad.induction
· exact fun _ => isIntegral_algebraMap
· exact fun _ _ => IsIntegral.add
· exact fun _ => IsIntegral.neg
· exact fun _ _ => IsIntegral.mul
· intro α hα
exact Subalgebra.inv_mem_of_algebraic (integralClosure F (solvableByRad F E))
(show IsAlgebraic F ↑(⟨α, hα⟩ : integralClosure F (solvableByRad F E)) from hα.isAlgebraic)
· intro α n hn hα
obtain ⟨p, h1, h2⟩ := hα.isAlgebraic
refine IsAlgebraic.isIntegral ⟨p.comp (X ^ n),
⟨fun h => h1 (leadingCoeff_eq_zero.mp ?_), by rw [aeval_comp, aeval_X_pow, h2]⟩⟩
rwa [← leadingCoeff_eq_zero, leadingCoeff_comp, leadingCoeff_X_pow, one_pow, mul_one] at h
rwa [natDegree_X_pow]
/-- The statement to be proved inductively -/
def P (α : solvableByRad F E) : Prop :=
IsSolvable (minpoly F α).Gal
/-- An auxiliary induction lemma, which is generalized by `solvableByRad.isSolvable`. -/
theorem induction3 {α : solvableByRad F E} {n : ℕ} (hn : n ≠ 0) (hα : P (α ^ n)) : P α := by
let p := minpoly F (α ^ n)
have hp : p.comp (X ^ n) ≠ 0 := by
intro h
cases' comp_eq_zero_iff.mp h with h' h'
· exact minpoly.ne_zero (isIntegral (α ^ n)) h'
· exact hn (by rw [← @natDegree_C F, ← h'.2, natDegree_X_pow])
apply gal_isSolvable_of_splits
· exact ⟨splits_of_splits_of_dvd _ hp (SplittingField.splits (p.comp (X ^ n)))
(minpoly.dvd F α (by rw [aeval_comp, aeval_X_pow, minpoly.aeval]))⟩
· refine gal_isSolvable_tower p (p.comp (X ^ n)) ?_ hα ?_
· exact Gal.splits_in_splittingField_of_comp _ _ (by rwa [natDegree_X_pow])
· obtain ⟨s, hs⟩ := (splits_iff_exists_multiset _).1 (SplittingField.splits p)
rw [map_comp, Polynomial.map_pow, map_X, hs, mul_comp, C_comp]
apply gal_mul_isSolvable (gal_C_isSolvable _)
rw [multiset_prod_comp]
apply gal_prod_isSolvable
intro q hq
rw [Multiset.mem_map] at hq
obtain ⟨q, hq, rfl⟩ := hq
rw [Multiset.mem_map] at hq
obtain ⟨q, _, rfl⟩ := hq
rw [sub_comp, X_comp, C_comp]
exact gal_X_pow_sub_C_isSolvable n q
/-- An auxiliary induction lemma, which is generalized by `solvableByRad.isSolvable`. -/
theorem induction2 {α β γ : solvableByRad F E} (hγ : γ ∈ F⟮α, β⟯) (hα : P α) (hβ : P β) : P γ := by
let p := minpoly F α
let q := minpoly F β
have hpq := Polynomial.splits_of_splits_mul _
(mul_ne_zero (minpoly.ne_zero (isIntegral α)) (minpoly.ne_zero (isIntegral β)))
(SplittingField.splits (p * q))
let f : ↥F⟮α, β⟯ →ₐ[F] (p * q).SplittingField :=
Classical.choice <| nonempty_algHom_adjoin_of_splits <| by
intro x hx
simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at hx
cases hx with rw [hx]
| inl hx => exact ⟨isIntegral α, hpq.1⟩
| inr hx => exact ⟨isIntegral β, hpq.2⟩
have key : minpoly F γ = minpoly F (f ⟨γ, hγ⟩) := by
refine minpoly.eq_of_irreducible_of_monic
(minpoly.irreducible (isIntegral γ)) ?_ (minpoly.monic (isIntegral γ))
suffices aeval (⟨γ, hγ⟩ : F⟮α, β⟯) (minpoly F γ) = 0 by
rw [aeval_algHom_apply, this, map_zero]
apply (algebraMap (↥F⟮α, β⟯) (solvableByRad F E)).injective
simp only [map_zero, _root_.map_eq_zero]
-- Porting note: end of the proof was `exact minpoly.aeval F γ`.
apply Subtype.val_injective
-- This used to be `simp`, but we need `erw` and `simp` after leanprover/lean4#2644
erw [Polynomial.aeval_subalgebra_coe (minpoly F γ)]
simp
rw [P, key]
refine gal_isSolvable_of_splits ⟨Normal.splits ?_ (f ⟨γ, hγ⟩)⟩ (gal_mul_isSolvable hα hβ)
apply SplittingField.instNormal
/-- An auxiliary induction lemma, which is generalized by `solvableByRad.isSolvable`. -/
theorem induction1 {α β : solvableByRad F E} (hβ : β ∈ F⟮α⟯) (hα : P α) : P β :=
induction2 (adjoin.mono F _ _ (ge_of_eq (Set.pair_eq_singleton α)) hβ) hα hα
theorem isSolvable (α : solvableByRad F E) : IsSolvable (minpoly F α).Gal := by
revert α
apply solvableByRad.induction
· exact fun α => by rw [minpoly.eq_X_sub_C (solvableByRad F E)]; exact gal_X_sub_C_isSolvable α
· exact fun α β => induction2 (add_mem (subset_adjoin F _ (Set.mem_insert α _))
(subset_adjoin F _ (Set.mem_insert_of_mem α (Set.mem_singleton β))))
· exact fun α => induction1 (neg_mem (mem_adjoin_simple_self F α))
· exact fun α β => induction2 (mul_mem (subset_adjoin F _ (Set.mem_insert α _))
(subset_adjoin F _ (Set.mem_insert_of_mem α (Set.mem_singleton β))))
· exact fun α => induction1 (inv_mem (mem_adjoin_simple_self F α))
· exact fun α n => induction3
/-- **Abel-Ruffini Theorem** (one direction): An irreducible polynomial with an
`IsSolvableByRad` root has solvable Galois group -/
theorem isSolvable' {α : E} {q : F[X]} (q_irred : Irreducible q) (q_aeval : aeval α q = 0)
(hα : IsSolvableByRad F α) : IsSolvable q.Gal := by
have : _root_.IsSolvable (q * C q.leadingCoeff⁻¹).Gal := by
rw [minpoly.eq_of_irreducible q_irred q_aeval, ←
show minpoly F (⟨α, hα⟩ : solvableByRad F E) = minpoly F α from
(minpoly.algebraMap_eq (RingHom.injective _) _).symm]
exact isSolvable ⟨α, hα⟩
refine solvable_of_surjective (Gal.restrictDvd_surjective ⟨C q.leadingCoeff⁻¹, rfl⟩ ?_)
rw [mul_ne_zero_iff, Ne, Ne, C_eq_zero, inv_eq_zero]
exact ⟨q_irred.ne_zero, leadingCoeff_ne_zero.mpr q_irred.ne_zero⟩
end solvableByRad
end AbelRuffini
|
FieldTheory\AbsoluteGaloisGroup.lean | /-
Copyright (c) 2023 María Inés de Frutos-Fernández. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: María Inés de Frutos-Fernández
-/
import Mathlib.FieldTheory.KrullTopology
import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure
import Mathlib.Topology.Algebra.Group.TopologicalAbelianization
/-!
# The topological abelianization of the absolute Galois group.
We define the absolute Galois group of a field `K` and its topological abelianization.
## Main definitions
- `Field.absoluteGaloisGroup` : The Galois group of the field extension `K^al/K`, where `K^al` is an
algebraic closure of `K`.
- `Field.absoluteGaloisGroupAbelianization` : The topological abelianization of
`Field.absoluteGaloisGroup K`, that is, the quotient of `Field.absoluteGaloisGroup K` by the
topological closure of its commutator subgroup.
## Main results
- `Field.absoluteGaloisGroup.commutator_closure_isNormal` : the topological closure of the
commutator of `absoluteGaloisGroup` is a normal subgroup.
## Tags
field, algebraic closure, galois group, abelianization
-/
namespace Field
variable (K : Type*) [Field K]
/-! ### The absolute Galois group -/
/-- The absolute Galois group of `K`, defined as the Galois group of the field extension `K^al/K`,
where `K^al` is an algebraic closure of `K`. -/
def absoluteGaloisGroup := AlgebraicClosure K ≃ₐ[K] AlgebraicClosure K
local notation "G_K" => absoluteGaloisGroup
noncomputable instance : Group (G_K K) := AlgEquiv.aut
/-- `absoluteGaloisGroup` is a topological space with the Krull topology. -/
noncomputable instance : TopologicalSpace (G_K K) := krullTopology K (AlgebraicClosure K)
/-! ### The topological abelianization of the absolute Galois group -/
instance absoluteGaloisGroup.commutator_closure_isNormal :
(commutator (G_K K)).topologicalClosure.Normal :=
Subgroup.is_normal_topologicalClosure (commutator (G_K K))
/-- The topological abelianization of `absoluteGaloisGroup`, that is, the quotient of
`absoluteGaloisGroup` by the topological closure of its commutator subgroup. -/
abbrev absoluteGaloisGroupAbelianization := TopologicalAbelianization (G_K K)
local notation "G_K_ab" => absoluteGaloisGroupAbelianization
end Field
|
FieldTheory\Adjoin.lean | /-
Copyright (c) 2020 Thomas Browning, Patrick Lutz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning, Patrick Lutz
-/
import Mathlib.Algebra.Algebra.Subalgebra.Directed
import Mathlib.FieldTheory.IntermediateField
import Mathlib.FieldTheory.Separable
import Mathlib.FieldTheory.SplittingField.IsSplittingField
import Mathlib.RingTheory.TensorProduct.Basic
/-!
# Adjoining Elements to Fields
In this file we introduce the notion of adjoining elements to fields.
This isn't quite the same as adjoining elements to rings.
For example, `Algebra.adjoin K {x}` might not include `x⁻¹`.
## Main results
- `adjoin_adjoin_left`: adjoining S and then T is the same as adjoining `S ∪ T`.
- `bot_eq_top_of_rank_adjoin_eq_one`: if `F⟮x⟯` has dimension `1` over `F` for every `x`
in `E` then `F = E`
## Notation
- `F⟮α⟯`: adjoin a single element `α` to `F` (in scope `IntermediateField`).
-/
open FiniteDimensional Polynomial
namespace IntermediateField
section AdjoinDef
variable (F : Type*) [Field F] {E : Type*} [Field E] [Algebra F E] (S : Set E)
-- Porting note: not adding `neg_mem'` causes an error.
/-- `adjoin F S` extends a field `F` by adjoining a set `S ⊆ E`. -/
def adjoin : IntermediateField F E :=
{ Subfield.closure (Set.range (algebraMap F E) ∪ S) with
algebraMap_mem' := fun x => Subfield.subset_closure (Or.inl (Set.mem_range_self x)) }
variable {S}
theorem mem_adjoin_iff (x : E) :
x ∈ adjoin F S ↔ ∃ r s : MvPolynomial S F,
x = MvPolynomial.aeval Subtype.val r / MvPolynomial.aeval Subtype.val s := by
simp only [adjoin, mem_mk, Subring.mem_toSubsemiring, Subfield.mem_toSubring,
Subfield.mem_closure_iff, ← Algebra.adjoin_eq_ring_closure, Subalgebra.mem_toSubring,
Algebra.adjoin_eq_range, AlgHom.mem_range, exists_exists_eq_and]
tauto
theorem mem_adjoin_simple_iff {α : E} (x : E) :
x ∈ adjoin F {α} ↔ ∃ r s : F[X], x = aeval α r / aeval α s := by
simp only [adjoin, mem_mk, Subring.mem_toSubsemiring, Subfield.mem_toSubring,
Subfield.mem_closure_iff, ← Algebra.adjoin_eq_ring_closure, Subalgebra.mem_toSubring,
Algebra.adjoin_singleton_eq_range_aeval, AlgHom.mem_range, exists_exists_eq_and]
tauto
end AdjoinDef
section Lattice
variable {F : Type*} [Field F] {E : Type*} [Field E] [Algebra F E]
@[simp]
theorem adjoin_le_iff {S : Set E} {T : IntermediateField F E} : adjoin F S ≤ T ↔ S ≤ T :=
⟨fun H => le_trans (le_trans Set.subset_union_right Subfield.subset_closure) H, fun H =>
(@Subfield.closure_le E _ (Set.range (algebraMap F E) ∪ S) T.toSubfield).mpr
(Set.union_subset (IntermediateField.set_range_subset T) H)⟩
theorem gc : GaloisConnection (adjoin F : Set E → IntermediateField F E)
(fun (x : IntermediateField F E) => (x : Set E)) := fun _ _ =>
adjoin_le_iff
/-- Galois insertion between `adjoin` and `coe`. -/
def gi : GaloisInsertion (adjoin F : Set E → IntermediateField F E)
(fun (x : IntermediateField F E) => (x : Set E)) where
choice s hs := (adjoin F s).copy s <| le_antisymm (gc.le_u_l s) hs
gc := IntermediateField.gc
le_l_u S := (IntermediateField.gc (S : Set E) (adjoin F S)).1 <| le_rfl
choice_eq _ _ := copy_eq _ _ _
instance : CompleteLattice (IntermediateField F E) where
__ := GaloisInsertion.liftCompleteLattice IntermediateField.gi
bot :=
{ toSubalgebra := ⊥
inv_mem' := by rintro x ⟨r, rfl⟩; exact ⟨r⁻¹, map_inv₀ _ _⟩ }
bot_le x := (bot_le : ⊥ ≤ x.toSubalgebra)
instance : Inhabited (IntermediateField F E) :=
⟨⊤⟩
instance : Unique (IntermediateField F F) :=
{ inferInstanceAs (Inhabited (IntermediateField F F)) with
uniq := fun _ ↦ toSubalgebra_injective <| Subsingleton.elim _ _ }
theorem coe_bot : ↑(⊥ : IntermediateField F E) = Set.range (algebraMap F E) := rfl
theorem mem_bot {x : E} : x ∈ (⊥ : IntermediateField F E) ↔ x ∈ Set.range (algebraMap F E) :=
Iff.rfl
@[simp]
theorem bot_toSubalgebra : (⊥ : IntermediateField F E).toSubalgebra = ⊥ := rfl
@[simp]
theorem coe_top : ↑(⊤ : IntermediateField F E) = (Set.univ : Set E) :=
rfl
@[simp]
theorem mem_top {x : E} : x ∈ (⊤ : IntermediateField F E) :=
trivial
@[simp]
theorem top_toSubalgebra : (⊤ : IntermediateField F E).toSubalgebra = ⊤ :=
rfl
@[simp]
theorem top_toSubfield : (⊤ : IntermediateField F E).toSubfield = ⊤ :=
rfl
@[simp, norm_cast]
theorem coe_inf (S T : IntermediateField F E) : (↑(S ⊓ T) : Set E) = (S : Set E) ∩ T :=
rfl
@[simp]
theorem mem_inf {S T : IntermediateField F E} {x : E} : x ∈ S ⊓ T ↔ x ∈ S ∧ x ∈ T :=
Iff.rfl
@[simp]
theorem inf_toSubalgebra (S T : IntermediateField F E) :
(S ⊓ T).toSubalgebra = S.toSubalgebra ⊓ T.toSubalgebra :=
rfl
@[simp]
theorem inf_toSubfield (S T : IntermediateField F E) :
(S ⊓ T).toSubfield = S.toSubfield ⊓ T.toSubfield :=
rfl
@[simp, norm_cast]
theorem coe_sInf (S : Set (IntermediateField F E)) : (↑(sInf S) : Set E) =
sInf ((fun (x : IntermediateField F E) => (x : Set E)) '' S) :=
rfl
@[simp]
theorem sInf_toSubalgebra (S : Set (IntermediateField F E)) :
(sInf S).toSubalgebra = sInf (toSubalgebra '' S) :=
SetLike.coe_injective <| by simp [Set.sUnion_image]
@[simp]
theorem sInf_toSubfield (S : Set (IntermediateField F E)) :
(sInf S).toSubfield = sInf (toSubfield '' S) :=
SetLike.coe_injective <| by simp [Set.sUnion_image]
@[simp, norm_cast]
theorem coe_iInf {ι : Sort*} (S : ι → IntermediateField F E) : (↑(iInf S) : Set E) = ⋂ i, S i := by
simp [iInf]
@[simp]
theorem iInf_toSubalgebra {ι : Sort*} (S : ι → IntermediateField F E) :
(iInf S).toSubalgebra = ⨅ i, (S i).toSubalgebra :=
SetLike.coe_injective <| by simp [iInf]
@[simp]
theorem iInf_toSubfield {ι : Sort*} (S : ι → IntermediateField F E) :
(iInf S).toSubfield = ⨅ i, (S i).toSubfield :=
SetLike.coe_injective <| by simp [iInf]
/-- Construct an algebra isomorphism from an equality of intermediate fields -/
@[simps! apply]
def equivOfEq {S T : IntermediateField F E} (h : S = T) : S ≃ₐ[F] T :=
Subalgebra.equivOfEq _ _ (congr_arg toSubalgebra h)
@[simp]
theorem equivOfEq_symm {S T : IntermediateField F E} (h : S = T) :
(equivOfEq h).symm = equivOfEq h.symm :=
rfl
@[simp]
theorem equivOfEq_rfl (S : IntermediateField F E) : equivOfEq (rfl : S = S) = AlgEquiv.refl := by
ext; rfl
@[simp]
theorem equivOfEq_trans {S T U : IntermediateField F E} (hST : S = T) (hTU : T = U) :
(equivOfEq hST).trans (equivOfEq hTU) = equivOfEq (hST.trans hTU) :=
rfl
variable (F E)
/-- The bottom intermediate_field is isomorphic to the field. -/
noncomputable def botEquiv : (⊥ : IntermediateField F E) ≃ₐ[F] F :=
(Subalgebra.equivOfEq _ _ bot_toSubalgebra).trans (Algebra.botEquiv F E)
variable {F E}
-- Porting note: this was tagged `simp`.
theorem botEquiv_def (x : F) : botEquiv F E (algebraMap F (⊥ : IntermediateField F E) x) = x := by
simp
@[simp]
theorem botEquiv_symm (x : F) : (botEquiv F E).symm x = algebraMap F _ x :=
rfl
noncomputable instance algebraOverBot : Algebra (⊥ : IntermediateField F E) F :=
(IntermediateField.botEquiv F E).toAlgHom.toRingHom.toAlgebra
theorem coe_algebraMap_over_bot :
(algebraMap (⊥ : IntermediateField F E) F : (⊥ : IntermediateField F E) → F) =
IntermediateField.botEquiv F E :=
rfl
instance isScalarTower_over_bot : IsScalarTower (⊥ : IntermediateField F E) F E :=
IsScalarTower.of_algebraMap_eq
(by
intro x
obtain ⟨y, rfl⟩ := (botEquiv F E).symm.surjective x
rw [coe_algebraMap_over_bot, (botEquiv F E).apply_symm_apply, botEquiv_symm,
IsScalarTower.algebraMap_apply F (⊥ : IntermediateField F E) E])
/-- The top `IntermediateField` is isomorphic to the field.
This is the intermediate field version of `Subalgebra.topEquiv`. -/
@[simps!]
def topEquiv : (⊤ : IntermediateField F E) ≃ₐ[F] E :=
(Subalgebra.equivOfEq _ _ top_toSubalgebra).trans Subalgebra.topEquiv
-- Porting note: this theorem is now generated by the `@[simps!]` above.
@[simp]
theorem restrictScalars_bot_eq_self (K : IntermediateField F E) :
(⊥ : IntermediateField K E).restrictScalars _ = K :=
SetLike.coe_injective Subtype.range_coe
@[simp]
theorem restrictScalars_top {K : Type*} [Field K] [Algebra K E] [Algebra K F]
[IsScalarTower K F E] : (⊤ : IntermediateField F E).restrictScalars K = ⊤ :=
rfl
variable {K : Type*} [Field K] [Algebra F K]
@[simp]
theorem map_bot (f : E →ₐ[F] K) :
IntermediateField.map f ⊥ = ⊥ :=
toSubalgebra_injective <| Algebra.map_bot _
theorem map_sup (s t : IntermediateField F E) (f : E →ₐ[F] K) : (s ⊔ t).map f = s.map f ⊔ t.map f :=
(gc_map_comap f).l_sup
theorem map_iSup {ι : Sort*} (f : E →ₐ[F] K) (s : ι → IntermediateField F E) :
(iSup s).map f = ⨆ i, (s i).map f :=
(gc_map_comap f).l_iSup
theorem _root_.AlgHom.fieldRange_eq_map (f : E →ₐ[F] K) :
f.fieldRange = IntermediateField.map f ⊤ :=
SetLike.ext' Set.image_univ.symm
theorem _root_.AlgHom.map_fieldRange {L : Type*} [Field L] [Algebra F L]
(f : E →ₐ[F] K) (g : K →ₐ[F] L) : f.fieldRange.map g = (g.comp f).fieldRange :=
SetLike.ext' (Set.range_comp g f).symm
theorem _root_.AlgHom.fieldRange_eq_top {f : E →ₐ[F] K} :
f.fieldRange = ⊤ ↔ Function.Surjective f :=
SetLike.ext'_iff.trans Set.range_iff_surjective
@[simp]
theorem _root_.AlgEquiv.fieldRange_eq_top (f : E ≃ₐ[F] K) :
(f : E →ₐ[F] K).fieldRange = ⊤ :=
AlgHom.fieldRange_eq_top.mpr f.surjective
end Lattice
section equivMap
variable {F : Type*} [Field F] {E : Type*} [Field E] [Algebra F E]
{K : Type*} [Field K] [Algebra F K] (L : IntermediateField F E) (f : E →ₐ[F] K)
theorem fieldRange_comp_val : (f.comp L.val).fieldRange = L.map f := toSubalgebra_injective <| by
rw [toSubalgebra_map, AlgHom.fieldRange_toSubalgebra, AlgHom.range_comp, range_val]
/-- An intermediate field is isomorphic to its image under an `AlgHom`
(which is automatically injective) -/
noncomputable def equivMap : L ≃ₐ[F] L.map f :=
(AlgEquiv.ofInjective _ (f.comp L.val).injective).trans (equivOfEq (fieldRange_comp_val L f))
@[simp]
theorem coe_equivMap_apply (x : L) : ↑(equivMap L f x) = f x := rfl
end equivMap
section AdjoinDef
variable (F : Type*) [Field F] {E : Type*} [Field E] [Algebra F E] (S : Set E)
theorem adjoin_eq_range_algebraMap_adjoin :
(adjoin F S : Set E) = Set.range (algebraMap (adjoin F S) E) :=
Subtype.range_coe.symm
theorem adjoin.algebraMap_mem (x : F) : algebraMap F E x ∈ adjoin F S :=
IntermediateField.algebraMap_mem (adjoin F S) x
theorem adjoin.range_algebraMap_subset : Set.range (algebraMap F E) ⊆ adjoin F S := by
intro x hx
cases' hx with f hf
rw [← hf]
exact adjoin.algebraMap_mem F S f
instance adjoin.fieldCoe : CoeTC F (adjoin F S) where
coe x := ⟨algebraMap F E x, adjoin.algebraMap_mem F S x⟩
theorem subset_adjoin : S ⊆ adjoin F S := fun _ hx => Subfield.subset_closure (Or.inr hx)
instance adjoin.setCoe : CoeTC S (adjoin F S) where coe x := ⟨x, subset_adjoin F S (Subtype.mem x)⟩
@[mono]
theorem adjoin.mono (T : Set E) (h : S ⊆ T) : adjoin F S ≤ adjoin F T :=
GaloisConnection.monotone_l gc h
theorem adjoin_contains_field_as_subfield (F : Subfield E) : (F : Set E) ⊆ adjoin F S := fun x hx =>
adjoin.algebraMap_mem F S ⟨x, hx⟩
theorem subset_adjoin_of_subset_left {F : Subfield E} {T : Set E} (HT : T ⊆ F) : T ⊆ adjoin F S :=
fun x hx => (adjoin F S).algebraMap_mem ⟨x, HT hx⟩
theorem subset_adjoin_of_subset_right {T : Set E} (H : T ⊆ S) : T ⊆ adjoin F S := fun _ hx =>
subset_adjoin F S (H hx)
@[simp]
theorem adjoin_empty (F E : Type*) [Field F] [Field E] [Algebra F E] : adjoin F (∅ : Set E) = ⊥ :=
eq_bot_iff.mpr (adjoin_le_iff.mpr (Set.empty_subset _))
@[simp]
theorem adjoin_univ (F E : Type*) [Field F] [Field E] [Algebra F E] :
adjoin F (Set.univ : Set E) = ⊤ :=
eq_top_iff.mpr <| subset_adjoin _ _
/-- If `K` is a field with `F ⊆ K` and `S ⊆ K` then `adjoin F S ≤ K`. -/
theorem adjoin_le_subfield {K : Subfield E} (HF : Set.range (algebraMap F E) ⊆ K) (HS : S ⊆ K) :
(adjoin F S).toSubfield ≤ K := by
apply Subfield.closure_le.mpr
rw [Set.union_subset_iff]
exact ⟨HF, HS⟩
theorem adjoin_subset_adjoin_iff {F' : Type*} [Field F'] [Algebra F' E] {S S' : Set E} :
(adjoin F S : Set E) ⊆ adjoin F' S' ↔
Set.range (algebraMap F E) ⊆ adjoin F' S' ∧ S ⊆ adjoin F' S' :=
⟨fun h => ⟨(adjoin.range_algebraMap_subset _ _).trans h,
(subset_adjoin _ _).trans h⟩, fun ⟨hF, hS⟩ =>
(Subfield.closure_le (t := (adjoin F' S').toSubfield)).mpr (Set.union_subset hF hS)⟩
/-- `F[S][T] = F[S ∪ T]` -/
theorem adjoin_adjoin_left (T : Set E) :
(adjoin (adjoin F S) T).restrictScalars _ = adjoin F (S ∪ T) := by
rw [SetLike.ext'_iff]
change (↑(adjoin (adjoin F S) T) : Set E) = _
apply Set.eq_of_subset_of_subset <;> rw [adjoin_subset_adjoin_iff] <;> constructor
· rintro _ ⟨⟨x, hx⟩, rfl⟩; exact adjoin.mono _ _ _ Set.subset_union_left hx
· exact subset_adjoin_of_subset_right _ _ Set.subset_union_right
-- Porting note: orginal proof times out
· rintro x ⟨f, rfl⟩
refine Subfield.subset_closure ?_
left
exact ⟨f, rfl⟩
-- Porting note: orginal proof times out
· refine Set.union_subset (fun x hx => Subfield.subset_closure ?_)
(fun x hx => Subfield.subset_closure ?_)
· left
refine ⟨⟨x, Subfield.subset_closure ?_⟩, rfl⟩
right
exact hx
· right
exact hx
@[simp]
theorem adjoin_insert_adjoin (x : E) :
adjoin F (insert x (adjoin F S : Set E)) = adjoin F (insert x S) :=
le_antisymm
(adjoin_le_iff.mpr
(Set.insert_subset_iff.mpr
⟨subset_adjoin _ _ (Set.mem_insert _ _),
adjoin_le_iff.mpr (subset_adjoin_of_subset_right _ _ (Set.subset_insert _ _))⟩))
(adjoin.mono _ _ _ (Set.insert_subset_insert (subset_adjoin _ _)))
/-- `F[S][T] = F[T][S]` -/
theorem adjoin_adjoin_comm (T : Set E) :
(adjoin (adjoin F S) T).restrictScalars F = (adjoin (adjoin F T) S).restrictScalars F := by
rw [adjoin_adjoin_left, adjoin_adjoin_left, Set.union_comm]
theorem adjoin_map {E' : Type*} [Field E'] [Algebra F E'] (f : E →ₐ[F] E') :
(adjoin F S).map f = adjoin F (f '' S) := by
ext x
show
x ∈ (Subfield.closure (Set.range (algebraMap F E) ∪ S)).map (f : E →+* E') ↔
x ∈ Subfield.closure (Set.range (algebraMap F E') ∪ f '' S)
rw [RingHom.map_field_closure, Set.image_union, ← Set.range_comp, ← RingHom.coe_comp,
f.comp_algebraMap]
rfl
@[simp]
theorem lift_adjoin (K : IntermediateField F E) (S : Set K) :
lift (adjoin F S) = adjoin F (Subtype.val '' S) :=
adjoin_map _ _ _
theorem lift_adjoin_simple (K : IntermediateField F E) (α : K) :
lift (adjoin F {α}) = adjoin F {α.1} := by
simp only [lift_adjoin, Set.image_singleton]
@[simp]
theorem lift_bot (K : IntermediateField F E) :
lift (F := K) ⊥ = ⊥ := map_bot _
@[simp]
theorem lift_top (K : IntermediateField F E) :
lift (F := K) ⊤ = K := by rw [lift, ← AlgHom.fieldRange_eq_map, fieldRange_val]
@[simp]
theorem adjoin_self (K : IntermediateField F E) :
adjoin F K = K := le_antisymm (adjoin_le_iff.2 fun _ ↦ id) (subset_adjoin F _)
theorem restrictScalars_adjoin (K : IntermediateField F E) (S : Set E) :
restrictScalars F (adjoin K S) = adjoin F (K ∪ S) := by
rw [← adjoin_self _ K, adjoin_adjoin_left, adjoin_self _ K]
variable {F} in
theorem extendScalars_adjoin {K : IntermediateField F E} {S : Set E} (h : K ≤ adjoin F S) :
extendScalars h = adjoin K S := restrictScalars_injective F <| by
rw [extendScalars_restrictScalars, restrictScalars_adjoin]
exact le_antisymm (adjoin.mono F S _ Set.subset_union_right) <| adjoin_le_iff.2 <|
Set.union_subset h (subset_adjoin F S)
variable {F} in
/-- If `E / L / F` and `E / L' / F` are two field extension towers, `L ≃ₐ[F] L'` is an isomorphism
compatible with `E / L` and `E / L'`, then for any subset `S` of `E`, `L(S)` and `L'(S)` are
equal as intermediate fields of `E / F`. -/
theorem restrictScalars_adjoin_of_algEquiv
{L L' : Type*} [Field L] [Field L']
[Algebra F L] [Algebra L E] [Algebra F L'] [Algebra L' E]
[IsScalarTower F L E] [IsScalarTower F L' E] (i : L ≃ₐ[F] L')
(hi : algebraMap L E = (algebraMap L' E) ∘ i) (S : Set E) :
(adjoin L S).restrictScalars F = (adjoin L' S).restrictScalars F := by
apply_fun toSubfield using (fun K K' h ↦ by
ext x; change x ∈ K.toSubfield ↔ x ∈ K'.toSubfield; rw [h])
change Subfield.closure _ = Subfield.closure _
congr
ext x
exact ⟨fun ⟨y, h⟩ ↦ ⟨i y, by rw [← h, hi]; rfl⟩,
fun ⟨y, h⟩ ↦ ⟨i.symm y, by rw [← h, hi, Function.comp_apply, AlgEquiv.apply_symm_apply]⟩⟩
theorem algebra_adjoin_le_adjoin : Algebra.adjoin F S ≤ (adjoin F S).toSubalgebra :=
Algebra.adjoin_le (subset_adjoin _ _)
theorem adjoin_eq_algebra_adjoin (inv_mem : ∀ x ∈ Algebra.adjoin F S, x⁻¹ ∈ Algebra.adjoin F S) :
(adjoin F S).toSubalgebra = Algebra.adjoin F S :=
le_antisymm
(show adjoin F S ≤
{ Algebra.adjoin F S with
inv_mem' := inv_mem }
from adjoin_le_iff.mpr Algebra.subset_adjoin)
(algebra_adjoin_le_adjoin _ _)
theorem eq_adjoin_of_eq_algebra_adjoin (K : IntermediateField F E)
(h : K.toSubalgebra = Algebra.adjoin F S) : K = adjoin F S := by
apply toSubalgebra_injective
rw [h]
refine (adjoin_eq_algebra_adjoin F _ ?_).symm
intro x
convert K.inv_mem (x := x) <;> rw [← h] <;> rfl
theorem adjoin_eq_top_of_algebra (hS : Algebra.adjoin F S = ⊤) : adjoin F S = ⊤ :=
top_le_iff.mp (hS.symm.trans_le <| algebra_adjoin_le_adjoin F S)
@[elab_as_elim]
theorem adjoin_induction {s : Set E} {p : E → Prop} {x} (h : x ∈ adjoin F s) (mem : ∀ x ∈ s, p x)
(algebraMap : ∀ x, p (algebraMap F E x)) (add : ∀ x y, p x → p y → p (x + y))
(neg : ∀ x, p x → p (-x)) (inv : ∀ x, p x → p x⁻¹) (mul : ∀ x y, p x → p y → p (x * y)) :
p x :=
Subfield.closure_induction h
(fun x hx => Or.casesOn hx (fun ⟨x, hx⟩ => hx ▸ algebraMap x) (mem x))
((_root_.algebraMap F E).map_one ▸ algebraMap 1) add neg inv mul
/- Porting note (kmill): this notation is replacing the typeclass-based one I had previously
written, and it gives true `{x₁, x₂, ..., xₙ}` sets in the `adjoin` term. -/
open Lean in
/-- Supporting function for the `F⟮x₁,x₂,...,xₙ⟯` adjunction notation. -/
private partial def mkInsertTerm {m : Type → Type} [Monad m] [MonadQuotation m]
(xs : TSyntaxArray `term) : m Term := run 0 where
run (i : Nat) : m Term := do
if i + 1 == xs.size then
``(singleton $(xs[i]!))
else if i < xs.size then
``(insert $(xs[i]!) $(← run (i + 1)))
else
``(EmptyCollection.emptyCollection)
/-- If `x₁ x₂ ... xₙ : E` then `F⟮x₁,x₂,...,xₙ⟯` is the `IntermediateField F E`
generated by these elements. -/
scoped macro:max K:term "⟮" xs:term,* "⟯" : term => do ``(adjoin $K $(← mkInsertTerm xs.getElems))
open Lean PrettyPrinter.Delaborator SubExpr in
@[delab app.IntermediateField.adjoin]
partial def delabAdjoinNotation : Delab := whenPPOption getPPNotation do
let e ← getExpr
guard <| e.isAppOfArity ``adjoin 6
let F ← withNaryArg 0 delab
let xs ← withNaryArg 5 delabInsertArray
`($F⟮$(xs.toArray),*⟯)
where
delabInsertArray : DelabM (List Term) := do
let e ← getExpr
if e.isAppOfArity ``EmptyCollection.emptyCollection 2 then
return []
else if e.isAppOfArity ``singleton 4 then
let x ← withNaryArg 3 delab
return [x]
else if e.isAppOfArity ``insert 5 then
let x ← withNaryArg 3 delab
let xs ← withNaryArg 4 delabInsertArray
return x :: xs
else failure
section AdjoinSimple
variable (α : E)
-- Porting note: in all the theorems below, mathport translated `F⟮α⟯` into `F⟮⟯`.
theorem mem_adjoin_simple_self : α ∈ F⟮α⟯ :=
subset_adjoin F {α} (Set.mem_singleton α)
/-- generator of `F⟮α⟯` -/
def AdjoinSimple.gen : F⟮α⟯ :=
⟨α, mem_adjoin_simple_self F α⟩
@[simp]
theorem AdjoinSimple.coe_gen : (AdjoinSimple.gen F α : E) = α :=
rfl
theorem AdjoinSimple.algebraMap_gen : algebraMap F⟮α⟯ E (AdjoinSimple.gen F α) = α :=
rfl
@[simp]
theorem AdjoinSimple.isIntegral_gen : IsIntegral F (AdjoinSimple.gen F α) ↔ IsIntegral F α := by
conv_rhs => rw [← AdjoinSimple.algebraMap_gen F α]
rw [isIntegral_algebraMap_iff (algebraMap F⟮α⟯ E).injective]
theorem adjoin_simple_adjoin_simple (β : E) : F⟮α⟯⟮β⟯.restrictScalars F = F⟮α, β⟯ :=
adjoin_adjoin_left _ _ _
theorem adjoin_simple_comm (β : E) : F⟮α⟯⟮β⟯.restrictScalars F = F⟮β⟯⟮α⟯.restrictScalars F :=
adjoin_adjoin_comm _ _ _
variable {F} {α}
theorem adjoin_algebraic_toSubalgebra {S : Set E} (hS : ∀ x ∈ S, IsAlgebraic F x) :
(IntermediateField.adjoin F S).toSubalgebra = Algebra.adjoin F S := by
simp only [isAlgebraic_iff_isIntegral] at hS
have : Algebra.IsIntegral F (Algebra.adjoin F S) := by
rwa [← le_integralClosure_iff_isIntegral, Algebra.adjoin_le_iff]
have : IsField (Algebra.adjoin F S) := isField_of_isIntegral_of_isField' (Field.toIsField F)
rw [← ((Algebra.adjoin F S).toIntermediateField' this).eq_adjoin_of_eq_algebra_adjoin F S] <;> rfl
theorem adjoin_simple_toSubalgebra_of_integral (hα : IsIntegral F α) :
F⟮α⟯.toSubalgebra = Algebra.adjoin F {α} := by
apply adjoin_algebraic_toSubalgebra
rintro x (rfl : x = α)
rwa [isAlgebraic_iff_isIntegral]
/-- Characterize `IsSplittingField` with `IntermediateField.adjoin` instead of `Algebra.adjoin`. -/
theorem _root_.isSplittingField_iff_intermediateField {p : F[X]} :
p.IsSplittingField F E ↔ p.Splits (algebraMap F E) ∧ adjoin F (p.rootSet E) = ⊤ := by
rw [← toSubalgebra_injective.eq_iff,
adjoin_algebraic_toSubalgebra fun _ ↦ isAlgebraic_of_mem_rootSet]
exact ⟨fun ⟨spl, adj⟩ ↦ ⟨spl, adj⟩, fun ⟨spl, adj⟩ ↦ ⟨spl, adj⟩⟩
-- Note: p.Splits (algebraMap F E) also works
theorem isSplittingField_iff {p : F[X]} {K : IntermediateField F E} :
p.IsSplittingField F K ↔ p.Splits (algebraMap F K) ∧ K = adjoin F (p.rootSet E) := by
suffices _ → (Algebra.adjoin F (p.rootSet K) = ⊤ ↔ K = adjoin F (p.rootSet E)) by
exact ⟨fun h ↦ ⟨h.1, (this h.1).mp h.2⟩, fun h ↦ ⟨h.1, (this h.1).mpr h.2⟩⟩
rw [← toSubalgebra_injective.eq_iff,
adjoin_algebraic_toSubalgebra fun x ↦ isAlgebraic_of_mem_rootSet]
refine fun hp ↦ (adjoin_rootSet_eq_range hp K.val).symm.trans ?_
rw [← K.range_val, eq_comm]
theorem adjoin_rootSet_isSplittingField {p : F[X]} (hp : p.Splits (algebraMap F E)) :
p.IsSplittingField F (adjoin F (p.rootSet E)) :=
isSplittingField_iff.mpr ⟨splits_of_splits hp fun _ hx ↦ subset_adjoin F (p.rootSet E) hx, rfl⟩
section Supremum
variable {K L : Type*} [Field K] [Field L] [Algebra K L] (E1 E2 : IntermediateField K L)
theorem le_sup_toSubalgebra : E1.toSubalgebra ⊔ E2.toSubalgebra ≤ (E1 ⊔ E2).toSubalgebra :=
sup_le (show E1 ≤ E1 ⊔ E2 from le_sup_left) (show E2 ≤ E1 ⊔ E2 from le_sup_right)
theorem sup_toSubalgebra_of_isAlgebraic_right [Algebra.IsAlgebraic K E2] :
(E1 ⊔ E2).toSubalgebra = E1.toSubalgebra ⊔ E2.toSubalgebra := by
have : (adjoin E1 (E2 : Set L)).toSubalgebra = _ := adjoin_algebraic_toSubalgebra fun x h ↦
IsAlgebraic.tower_top E1 (isAlgebraic_iff.1
(Algebra.IsAlgebraic.isAlgebraic (⟨x, h⟩ : E2)))
apply_fun Subalgebra.restrictScalars K at this
erw [← restrictScalars_toSubalgebra, restrictScalars_adjoin,
Algebra.restrictScalars_adjoin] at this
exact this
theorem sup_toSubalgebra_of_isAlgebraic_left [Algebra.IsAlgebraic K E1] :
(E1 ⊔ E2).toSubalgebra = E1.toSubalgebra ⊔ E2.toSubalgebra := by
have := sup_toSubalgebra_of_isAlgebraic_right E2 E1
rwa [sup_comm (a := E1), sup_comm (a := E1.toSubalgebra)]
/-- The compositum of two intermediate fields is equal to the compositum of them
as subalgebras, if one of them is algebraic over the base field. -/
theorem sup_toSubalgebra_of_isAlgebraic
(halg : Algebra.IsAlgebraic K E1 ∨ Algebra.IsAlgebraic K E2) :
(E1 ⊔ E2).toSubalgebra = E1.toSubalgebra ⊔ E2.toSubalgebra :=
halg.elim (fun _ ↦ sup_toSubalgebra_of_isAlgebraic_left E1 E2)
(fun _ ↦ sup_toSubalgebra_of_isAlgebraic_right E1 E2)
theorem sup_toSubalgebra_of_left [FiniteDimensional K E1] :
(E1 ⊔ E2).toSubalgebra = E1.toSubalgebra ⊔ E2.toSubalgebra :=
sup_toSubalgebra_of_isAlgebraic_left E1 E2
@[deprecated (since := "2024-01-19")] alias sup_toSubalgebra := sup_toSubalgebra_of_left
theorem sup_toSubalgebra_of_right [FiniteDimensional K E2] :
(E1 ⊔ E2).toSubalgebra = E1.toSubalgebra ⊔ E2.toSubalgebra :=
sup_toSubalgebra_of_isAlgebraic_right E1 E2
instance finiteDimensional_sup [FiniteDimensional K E1] [FiniteDimensional K E2] :
FiniteDimensional K (E1 ⊔ E2 : IntermediateField K L) := by
let g := Algebra.TensorProduct.productMap E1.val E2.val
suffices g.range = (E1 ⊔ E2).toSubalgebra by
have h : FiniteDimensional K (Subalgebra.toSubmodule g.range) :=
g.toLinearMap.finiteDimensional_range
rwa [this] at h
rw [Algebra.TensorProduct.productMap_range, E1.range_val, E2.range_val, sup_toSubalgebra_of_left]
variable {ι : Type*} {t : ι → IntermediateField K L}
theorem coe_iSup_of_directed [Nonempty ι] (dir : Directed (· ≤ ·) t) :
↑(iSup t) = ⋃ i, (t i : Set L) :=
let M : IntermediateField K L :=
{ __ := Subalgebra.copy _ _ (Subalgebra.coe_iSup_of_directed dir).symm
inv_mem' := fun _ hx ↦ have ⟨i, hi⟩ := Set.mem_iUnion.mp hx
Set.mem_iUnion.mpr ⟨i, (t i).inv_mem hi⟩ }
have : iSup t = M := le_antisymm
(iSup_le fun i ↦ le_iSup (fun i ↦ (t i : Set L)) i) (Set.iUnion_subset fun _ ↦ le_iSup t _)
this.symm ▸ rfl
theorem toSubalgebra_iSup_of_directed (dir : Directed (· ≤ ·) t) :
(iSup t).toSubalgebra = ⨆ i, (t i).toSubalgebra := by
cases isEmpty_or_nonempty ι
· simp_rw [iSup_of_empty, bot_toSubalgebra]
· exact SetLike.ext' ((coe_iSup_of_directed dir).trans (Subalgebra.coe_iSup_of_directed dir).symm)
instance finiteDimensional_iSup_of_finite [h : Finite ι] [∀ i, FiniteDimensional K (t i)] :
FiniteDimensional K (⨆ i, t i : IntermediateField K L) := by
rw [← iSup_univ]
let P : Set ι → Prop := fun s => FiniteDimensional K (⨆ i ∈ s, t i : IntermediateField K L)
change P Set.univ
apply Set.Finite.induction_on
all_goals dsimp only [P]
· exact Set.finite_univ
· rw [iSup_emptyset]
exact (botEquiv K L).symm.toLinearEquiv.finiteDimensional
· intro _ s _ _ hs
rw [iSup_insert]
exact IntermediateField.finiteDimensional_sup _ _
instance finiteDimensional_iSup_of_finset
/- Porting note: changed `h` from `∀ i ∈ s, FiniteDimensional K (t i)` because this caused an
error. See `finiteDimensional_iSup_of_finset'` for a stronger version, that was the one
used in mathlib3. -/
{s : Finset ι} [∀ i, FiniteDimensional K (t i)] :
FiniteDimensional K (⨆ i ∈ s, t i : IntermediateField K L) :=
iSup_subtype'' s t ▸ IntermediateField.finiteDimensional_iSup_of_finite
theorem finiteDimensional_iSup_of_finset'
/- Porting note: this was the mathlib3 version. Using `[h : ...]`, as in mathlib3, causes the
error "invalid parametric local instance". -/
{s : Finset ι} (h : ∀ i ∈ s, FiniteDimensional K (t i)) :
FiniteDimensional K (⨆ i ∈ s, t i : IntermediateField K L) :=
have := Subtype.forall'.mp h
iSup_subtype'' s t ▸ IntermediateField.finiteDimensional_iSup_of_finite
/-- A compositum of splitting fields is a splitting field -/
theorem isSplittingField_iSup {p : ι → K[X]}
{s : Finset ι} (h0 : ∏ i ∈ s, p i ≠ 0) (h : ∀ i ∈ s, (p i).IsSplittingField K (t i)) :
(∏ i ∈ s, p i).IsSplittingField K (⨆ i ∈ s, t i : IntermediateField K L) := by
let F : IntermediateField K L := ⨆ i ∈ s, t i
have hF : ∀ i ∈ s, t i ≤ F := fun i hi ↦ le_iSup_of_le i (le_iSup (fun _ ↦ t i) hi)
simp only [isSplittingField_iff] at h ⊢
refine
⟨splits_prod (algebraMap K F) fun i hi ↦
splits_comp_of_splits (algebraMap K (t i)) (inclusion (hF i hi)).toRingHom
(h i hi).1,
?_⟩
simp only [rootSet_prod p s h0, ← Set.iSup_eq_iUnion, (@gc K _ L _ _).l_iSup₂]
exact iSup_congr fun i ↦ iSup_congr fun hi ↦ (h i hi).2
end Supremum
section Tower
variable (E)
variable {K : Type*} [Field K] [Algebra F K] [Algebra E K] [IsScalarTower F E K]
/-- If `K / E / F` is a field extension tower, `L` is an intermediate field of `K / F`, such that
either `E / F` or `L / F` is algebraic, then `E(L) = E[L]`. -/
theorem adjoin_toSubalgebra_of_isAlgebraic (L : IntermediateField F K)
(halg : Algebra.IsAlgebraic F E ∨ Algebra.IsAlgebraic F L) :
(adjoin E (L : Set K)).toSubalgebra = Algebra.adjoin E (L : Set K) := by
let i := IsScalarTower.toAlgHom F E K
let E' := i.fieldRange
let i' : E ≃ₐ[F] E' := AlgEquiv.ofInjectiveField i
have hi : algebraMap E K = (algebraMap E' K) ∘ i' := by ext x; rfl
apply_fun _ using Subalgebra.restrictScalars_injective F
erw [← restrictScalars_toSubalgebra, restrictScalars_adjoin_of_algEquiv i' hi,
Algebra.restrictScalars_adjoin_of_algEquiv i' hi, restrictScalars_adjoin,
Algebra.restrictScalars_adjoin]
exact E'.sup_toSubalgebra_of_isAlgebraic L (halg.imp
(fun (_ : Algebra.IsAlgebraic F E) ↦ i'.isAlgebraic) id)
theorem adjoin_toSubalgebra_of_isAlgebraic_left (L : IntermediateField F K)
[halg : Algebra.IsAlgebraic F E] :
(adjoin E (L : Set K)).toSubalgebra = Algebra.adjoin E (L : Set K) :=
adjoin_toSubalgebra_of_isAlgebraic E L (Or.inl halg)
theorem adjoin_toSubalgebra_of_isAlgebraic_right (L : IntermediateField F K)
[halg : Algebra.IsAlgebraic F L] :
(adjoin E (L : Set K)).toSubalgebra = Algebra.adjoin E (L : Set K) :=
adjoin_toSubalgebra_of_isAlgebraic E L (Or.inr halg)
/-- If `K / E / F` is a field extension tower, `L` is an intermediate field of `K / F`, such that
either `E / F` or `L / F` is algebraic, then `[E(L) : E] ≤ [L : F]`. A corollary of
`Subalgebra.adjoin_rank_le` since in this case `E(L) = E[L]`. -/
theorem adjoin_rank_le_of_isAlgebraic (L : IntermediateField F K)
(halg : Algebra.IsAlgebraic F E ∨ Algebra.IsAlgebraic F L) :
Module.rank E (adjoin E (L : Set K)) ≤ Module.rank F L := by
have h : (adjoin E (L.toSubalgebra : Set K)).toSubalgebra =
Algebra.adjoin E (L.toSubalgebra : Set K) :=
L.adjoin_toSubalgebra_of_isAlgebraic E halg
have := L.toSubalgebra.adjoin_rank_le E
rwa [(Subalgebra.equivOfEq _ _ h).symm.toLinearEquiv.rank_eq] at this
theorem adjoin_rank_le_of_isAlgebraic_left (L : IntermediateField F K)
[halg : Algebra.IsAlgebraic F E] :
Module.rank E (adjoin E (L : Set K)) ≤ Module.rank F L :=
adjoin_rank_le_of_isAlgebraic E L (Or.inl halg)
theorem adjoin_rank_le_of_isAlgebraic_right (L : IntermediateField F K)
[halg : Algebra.IsAlgebraic F L] :
Module.rank E (adjoin E (L : Set K)) ≤ Module.rank F L :=
adjoin_rank_le_of_isAlgebraic E L (Or.inr halg)
end Tower
open Set CompleteLattice
/- Porting note: this was tagged `simp`, but the LHS can be simplified now that the notation
has been improved. -/
theorem adjoin_simple_le_iff {K : IntermediateField F E} : F⟮α⟯ ≤ K ↔ α ∈ K := by simp
theorem biSup_adjoin_simple : ⨆ x ∈ S, F⟮x⟯ = adjoin F S := by
rw [← iSup_subtype'', ← gc.l_iSup, iSup_subtype'']; congr; exact S.biUnion_of_singleton
/-- Adjoining a single element is compact in the lattice of intermediate fields. -/
theorem adjoin_simple_isCompactElement (x : E) : IsCompactElement F⟮x⟯ := by
simp_rw [isCompactElement_iff_le_of_directed_sSup_le,
adjoin_simple_le_iff, sSup_eq_iSup', ← exists_prop]
intro s hne hs hx
have := hne.to_subtype
rwa [← SetLike.mem_coe, coe_iSup_of_directed hs.directed_val, mem_iUnion, Subtype.exists] at hx
-- Porting note: original proof times out.
/-- Adjoining a finite subset is compact in the lattice of intermediate fields. -/
theorem adjoin_finset_isCompactElement (S : Finset E) :
IsCompactElement (adjoin F S : IntermediateField F E) := by
rw [← biSup_adjoin_simple]
simp_rw [Finset.mem_coe, ← Finset.sup_eq_iSup]
exact isCompactElement_finsetSup S fun x _ => adjoin_simple_isCompactElement x
/-- Adjoining a finite subset is compact in the lattice of intermediate fields. -/
theorem adjoin_finite_isCompactElement {S : Set E} (h : S.Finite) : IsCompactElement (adjoin F S) :=
Finite.coe_toFinset h ▸ adjoin_finset_isCompactElement h.toFinset
/-- The lattice of intermediate fields is compactly generated. -/
instance : IsCompactlyGenerated (IntermediateField F E) :=
⟨fun s =>
⟨(fun x => F⟮x⟯) '' s,
⟨by rintro t ⟨x, _, rfl⟩; exact adjoin_simple_isCompactElement x,
sSup_image.trans <| (biSup_adjoin_simple _).trans <|
le_antisymm (adjoin_le_iff.mpr le_rfl) <| subset_adjoin F (s : Set E)⟩⟩⟩
theorem exists_finset_of_mem_iSup {ι : Type*} {f : ι → IntermediateField F E} {x : E}
(hx : x ∈ ⨆ i, f i) : ∃ s : Finset ι, x ∈ ⨆ i ∈ s, f i := by
have := (adjoin_simple_isCompactElement x).exists_finset_of_le_iSup (IntermediateField F E) f
simp only [adjoin_simple_le_iff] at this
exact this hx
theorem exists_finset_of_mem_supr' {ι : Type*} {f : ι → IntermediateField F E} {x : E}
(hx : x ∈ ⨆ i, f i) : ∃ s : Finset (Σ i, f i), x ∈ ⨆ i ∈ s, F⟮(i.2 : E)⟯ := by
-- Porting note: writing `fun i x h => ...` does not work.
refine exists_finset_of_mem_iSup (SetLike.le_def.mp (iSup_le fun i ↦ ?_) hx)
exact fun x h ↦ SetLike.le_def.mp (le_iSup_of_le ⟨i, x, h⟩ (by simp)) (mem_adjoin_simple_self F x)
theorem exists_finset_of_mem_supr'' {ι : Type*} {f : ι → IntermediateField F E}
(h : ∀ i, Algebra.IsAlgebraic F (f i)) {x : E} (hx : x ∈ ⨆ i, f i) :
∃ s : Finset (Σ i, f i), x ∈ ⨆ i ∈ s, adjoin F ((minpoly F (i.2 : _)).rootSet E) := by
-- Porting note: writing `fun i x1 hx1 => ...` does not work.
refine exists_finset_of_mem_iSup (SetLike.le_def.mp (iSup_le (fun i => ?_)) hx)
intro x1 hx1
refine SetLike.le_def.mp (le_iSup_of_le ⟨i, x1, hx1⟩ ?_)
(subset_adjoin F (rootSet (minpoly F x1) E) ?_)
· rw [IntermediateField.minpoly_eq, Subtype.coe_mk]
· rw [mem_rootSet_of_ne, minpoly.aeval]
exact minpoly.ne_zero (isIntegral_iff.mp (Algebra.IsIntegral.isIntegral (⟨x1, hx1⟩ : f i)))
theorem exists_finset_of_mem_adjoin {S : Set E} {x : E} (hx : x ∈ adjoin F S) :
∃ T : Finset E, (T : Set E) ⊆ S ∧ x ∈ adjoin F (T : Set E) := by
simp_rw [← biSup_adjoin_simple S, ← iSup_subtype''] at hx
obtain ⟨s, hx'⟩ := exists_finset_of_mem_iSup hx
classical
refine ⟨s.image Subtype.val, by simp, SetLike.le_def.mp ?_ hx'⟩
simp_rw [Finset.coe_image, iSup_le_iff, adjoin_le_iff]
rintro _ h _ rfl
exact subset_adjoin F _ ⟨_, h, rfl⟩
end AdjoinSimple
end AdjoinDef
section AdjoinIntermediateFieldLattice
variable {F : Type*} [Field F] {E : Type*} [Field E] [Algebra F E] {α : E} {S : Set E}
@[simp]
theorem adjoin_eq_bot_iff : adjoin F S = ⊥ ↔ S ⊆ (⊥ : IntermediateField F E) := by
rw [eq_bot_iff, adjoin_le_iff]; rfl
/- Porting note: this was tagged `simp`. -/
theorem adjoin_simple_eq_bot_iff : F⟮α⟯ = ⊥ ↔ α ∈ (⊥ : IntermediateField F E) := by
simp
@[simp]
theorem adjoin_zero : F⟮(0 : E)⟯ = ⊥ :=
adjoin_simple_eq_bot_iff.mpr (zero_mem ⊥)
@[simp]
theorem adjoin_one : F⟮(1 : E)⟯ = ⊥ :=
adjoin_simple_eq_bot_iff.mpr (one_mem ⊥)
@[simp]
theorem adjoin_intCast (n : ℤ) : F⟮(n : E)⟯ = ⊥ := by
exact adjoin_simple_eq_bot_iff.mpr (intCast_mem ⊥ n)
@[simp]
theorem adjoin_natCast (n : ℕ) : F⟮(n : E)⟯ = ⊥ :=
adjoin_simple_eq_bot_iff.mpr (natCast_mem ⊥ n)
@[deprecated (since := "2024-04-05")] alias adjoin_int := adjoin_intCast
@[deprecated (since := "2024-04-05")] alias adjoin_nat := adjoin_natCast
section AdjoinRank
open FiniteDimensional Module
variable {K L : IntermediateField F E}
@[simp]
theorem rank_eq_one_iff : Module.rank F K = 1 ↔ K = ⊥ := by
rw [← toSubalgebra_eq_iff, ← rank_eq_rank_subalgebra, Subalgebra.rank_eq_one_iff,
bot_toSubalgebra]
@[simp]
theorem finrank_eq_one_iff : finrank F K = 1 ↔ K = ⊥ := by
rw [← toSubalgebra_eq_iff, ← finrank_eq_finrank_subalgebra, Subalgebra.finrank_eq_one_iff,
bot_toSubalgebra]
@[simp] protected
theorem rank_bot : Module.rank F (⊥ : IntermediateField F E) = 1 := by rw [rank_eq_one_iff]
@[simp] protected
theorem finrank_bot : finrank F (⊥ : IntermediateField F E) = 1 := by rw [finrank_eq_one_iff]
@[simp] theorem rank_bot' : Module.rank (⊥ : IntermediateField F E) E = Module.rank F E := by
rw [← rank_mul_rank F (⊥ : IntermediateField F E) E, IntermediateField.rank_bot, one_mul]
@[simp] theorem finrank_bot' : finrank (⊥ : IntermediateField F E) E = finrank F E :=
congr(Cardinal.toNat $(rank_bot'))
@[simp] protected theorem rank_top : Module.rank (⊤ : IntermediateField F E) E = 1 :=
Subalgebra.bot_eq_top_iff_rank_eq_one.mp <| top_le_iff.mp fun x _ ↦ ⟨⟨x, trivial⟩, rfl⟩
@[simp] protected theorem finrank_top : finrank (⊤ : IntermediateField F E) E = 1 :=
rank_eq_one_iff_finrank_eq_one.mp IntermediateField.rank_top
@[simp] theorem rank_top' : Module.rank F (⊤ : IntermediateField F E) = Module.rank F E :=
rank_top F E
@[simp] theorem finrank_top' : finrank F (⊤ : IntermediateField F E) = finrank F E :=
finrank_top F E
theorem rank_adjoin_eq_one_iff : Module.rank F (adjoin F S) = 1 ↔ S ⊆ (⊥ : IntermediateField F E) :=
Iff.trans rank_eq_one_iff adjoin_eq_bot_iff
theorem rank_adjoin_simple_eq_one_iff :
Module.rank F F⟮α⟯ = 1 ↔ α ∈ (⊥ : IntermediateField F E) := by
rw [rank_adjoin_eq_one_iff]; exact Set.singleton_subset_iff
theorem finrank_adjoin_eq_one_iff : finrank F (adjoin F S) = 1 ↔ S ⊆ (⊥ : IntermediateField F E) :=
Iff.trans finrank_eq_one_iff adjoin_eq_bot_iff
theorem finrank_adjoin_simple_eq_one_iff :
finrank F F⟮α⟯ = 1 ↔ α ∈ (⊥ : IntermediateField F E) := by
rw [finrank_adjoin_eq_one_iff]; exact Set.singleton_subset_iff
/-- If `F⟮x⟯` has dimension `1` over `F` for every `x ∈ E` then `F = E`. -/
theorem bot_eq_top_of_rank_adjoin_eq_one (h : ∀ x : E, Module.rank F F⟮x⟯ = 1) :
(⊥ : IntermediateField F E) = ⊤ := by
ext y
rw [iff_true_right IntermediateField.mem_top]
exact rank_adjoin_simple_eq_one_iff.mp (h y)
theorem bot_eq_top_of_finrank_adjoin_eq_one (h : ∀ x : E, finrank F F⟮x⟯ = 1) :
(⊥ : IntermediateField F E) = ⊤ := by
ext y
rw [iff_true_right IntermediateField.mem_top]
exact finrank_adjoin_simple_eq_one_iff.mp (h y)
theorem subsingleton_of_rank_adjoin_eq_one (h : ∀ x : E, Module.rank F F⟮x⟯ = 1) :
Subsingleton (IntermediateField F E) :=
subsingleton_of_bot_eq_top (bot_eq_top_of_rank_adjoin_eq_one h)
theorem subsingleton_of_finrank_adjoin_eq_one (h : ∀ x : E, finrank F F⟮x⟯ = 1) :
Subsingleton (IntermediateField F E) :=
subsingleton_of_bot_eq_top (bot_eq_top_of_finrank_adjoin_eq_one h)
/-- If `F⟮x⟯` has dimension `≤1` over `F` for every `x ∈ E` then `F = E`. -/
theorem bot_eq_top_of_finrank_adjoin_le_one [FiniteDimensional F E]
(h : ∀ x : E, finrank F F⟮x⟯ ≤ 1) : (⊥ : IntermediateField F E) = ⊤ := by
apply bot_eq_top_of_finrank_adjoin_eq_one
exact fun x => by linarith [h x, show 0 < finrank F F⟮x⟯ from finrank_pos]
theorem subsingleton_of_finrank_adjoin_le_one [FiniteDimensional F E]
(h : ∀ x : E, finrank F F⟮x⟯ ≤ 1) : Subsingleton (IntermediateField F E) :=
subsingleton_of_bot_eq_top (bot_eq_top_of_finrank_adjoin_le_one h)
end AdjoinRank
end AdjoinIntermediateFieldLattice
section AdjoinIntegralElement
universe u
variable (F : Type*) [Field F] {E : Type*} [Field E] [Algebra F E] {α : E}
variable {K : Type u} [Field K] [Algebra F K]
theorem minpoly_gen (α : E) :
minpoly F (AdjoinSimple.gen F α) = minpoly F α := by
rw [← minpoly.algebraMap_eq (algebraMap F⟮α⟯ E).injective, AdjoinSimple.algebraMap_gen]
theorem aeval_gen_minpoly (α : E) : aeval (AdjoinSimple.gen F α) (minpoly F α) = 0 := by
ext
convert minpoly.aeval F α
conv in aeval α => rw [← AdjoinSimple.algebraMap_gen F α]
exact (aeval_algebraMap_apply E (AdjoinSimple.gen F α) _).symm
-- Porting note: original proof used `Exists.cases_on`.
/-- algebra isomorphism between `AdjoinRoot` and `F⟮α⟯` -/
noncomputable def adjoinRootEquivAdjoin (h : IsIntegral F α) :
AdjoinRoot (minpoly F α) ≃ₐ[F] F⟮α⟯ :=
AlgEquiv.ofBijective
(AdjoinRoot.liftHom (minpoly F α) (AdjoinSimple.gen F α) (aeval_gen_minpoly F α))
(by
set f := AdjoinRoot.lift _ _ (aeval_gen_minpoly F α : _)
haveI := Fact.mk (minpoly.irreducible h)
constructor
· exact RingHom.injective f
· suffices F⟮α⟯.toSubfield ≤ RingHom.fieldRange (F⟮α⟯.toSubfield.subtype.comp f) by
intro x
obtain ⟨y, hy⟩ := this (Subtype.mem x)
exact ⟨y, Subtype.ext hy⟩
refine Subfield.closure_le.mpr (Set.union_subset (fun x hx => ?_) ?_)
· obtain ⟨y, hy⟩ := hx
refine ⟨y, ?_⟩
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [RingHom.comp_apply, AdjoinRoot.lift_of (aeval_gen_minpoly F α)]
exact hy
· refine Set.singleton_subset_iff.mpr ⟨AdjoinRoot.root (minpoly F α), ?_⟩
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [RingHom.comp_apply, AdjoinRoot.lift_root (aeval_gen_minpoly F α)]
rfl)
theorem adjoinRootEquivAdjoin_apply_root (h : IsIntegral F α) :
adjoinRootEquivAdjoin F h (AdjoinRoot.root (minpoly F α)) = AdjoinSimple.gen F α :=
AdjoinRoot.lift_root (aeval_gen_minpoly F α)
theorem adjoin_root_eq_top (p : K[X]) [Fact (Irreducible p)] : K⟮AdjoinRoot.root p⟯ = ⊤ :=
(eq_adjoin_of_eq_algebra_adjoin K _ ⊤ (AdjoinRoot.adjoinRoot_eq_top (f := p)).symm).symm
section PowerBasis
variable {L : Type*} [Field L] [Algebra K L]
/-- The elements `1, x, ..., x ^ (d - 1)` form a basis for `K⟮x⟯`,
where `d` is the degree of the minimal polynomial of `x`. -/
noncomputable def powerBasisAux {x : L} (hx : IsIntegral K x) :
Basis (Fin (minpoly K x).natDegree) K K⟮x⟯ :=
(AdjoinRoot.powerBasis (minpoly.ne_zero hx)).basis.map (adjoinRootEquivAdjoin K hx).toLinearEquiv
/-- The power basis `1, x, ..., x ^ (d - 1)` for `K⟮x⟯`,
where `d` is the degree of the minimal polynomial of `x`. -/
@[simps]
noncomputable def adjoin.powerBasis {x : L} (hx : IsIntegral K x) : PowerBasis K K⟮x⟯ where
gen := AdjoinSimple.gen K x
dim := (minpoly K x).natDegree
basis := powerBasisAux hx
basis_eq_pow i := by
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [powerBasisAux, Basis.map_apply, PowerBasis.basis_eq_pow, AlgEquiv.toLinearEquiv_apply,
map_pow, AdjoinRoot.powerBasis_gen, adjoinRootEquivAdjoin_apply_root]
theorem adjoin.finiteDimensional {x : L} (hx : IsIntegral K x) : FiniteDimensional K K⟮x⟯ :=
(adjoin.powerBasis hx).finite
theorem isAlgebraic_adjoin_simple {x : L} (hx : IsIntegral K x) : Algebra.IsAlgebraic K K⟮x⟯ :=
have := adjoin.finiteDimensional hx; Algebra.IsAlgebraic.of_finite K K⟮x⟯
theorem adjoin.finrank {x : L} (hx : IsIntegral K x) :
FiniteDimensional.finrank K K⟮x⟯ = (minpoly K x).natDegree := by
rw [PowerBasis.finrank (adjoin.powerBasis hx : _)]
rfl
/-- If `K / E / F` is a field extension tower, `S ⊂ K` is such that `F(S) = K`,
then `E(S) = K`. -/
theorem adjoin_eq_top_of_adjoin_eq_top [Algebra E K] [IsScalarTower F E K]
{S : Set K} (hprim : adjoin F S = ⊤) : adjoin E S = ⊤ :=
restrictScalars_injective F <| by
rw [restrictScalars_top, ← top_le_iff, ← hprim, adjoin_le_iff,
coe_restrictScalars, ← adjoin_le_iff]
/-- If `E / F` is a finite extension such that `E = F(α)`, then for any intermediate field `K`, the
`F` adjoin the coefficients of `minpoly K α` is equal to `K` itself. -/
theorem adjoin_minpoly_coeff_of_exists_primitive_element
[FiniteDimensional F E] (hprim : adjoin F {α} = ⊤) (K : IntermediateField F E) :
adjoin F ((minpoly K α).map (algebraMap K E)).coeffs = K := by
set g := (minpoly K α).map (algebraMap K E)
set K' : IntermediateField F E := adjoin F g.coeffs
have hsub : K' ≤ K := by
refine adjoin_le_iff.mpr fun x ↦ ?_
rw [Finset.mem_coe, mem_coeffs_iff]
rintro ⟨n, -, rfl⟩
rw [coeff_map]
apply Subtype.mem
have dvd_g : minpoly K' α ∣ g.toSubring K'.toSubring (subset_adjoin F _) := by
apply minpoly.dvd
erw [aeval_def, eval₂_eq_eval_map, g.map_toSubring K'.toSubring, eval_map, ← aeval_def]
exact minpoly.aeval K α
have finrank_eq : ∀ K : IntermediateField F E, finrank K E = natDegree (minpoly K α) := by
intro K
have := adjoin.finrank (.of_finite K α)
erw [adjoin_eq_top_of_adjoin_eq_top F hprim, finrank_top K E] at this
exact this
refine eq_of_le_of_finrank_le' hsub ?_
simp_rw [finrank_eq]
convert natDegree_le_of_dvd dvd_g
((g.monic_toSubring _ _).mpr <| (minpoly.monic <| .of_finite K α).map _).ne_zero using 1
rw [natDegree_toSubring, natDegree_map]
variable {F} in
/-- If `E / F` is an infinite algebraic extension, then there exists an intermediate field
`L / F` with arbitrarily large finite extension degree. -/
theorem exists_lt_finrank_of_infinite_dimensional
[Algebra.IsAlgebraic F E] (hnfd : ¬ FiniteDimensional F E) (n : ℕ) :
∃ L : IntermediateField F E, FiniteDimensional F L ∧ n < finrank F L := by
induction' n with n ih
· exact ⟨⊥, Subalgebra.finite_bot, finrank_pos⟩
obtain ⟨L, fin, hn⟩ := ih
obtain ⟨x, hx⟩ : ∃ x : E, x ∉ L := by
contrapose! hnfd
rw [show L = ⊤ from eq_top_iff.2 fun x _ ↦ hnfd x] at fin
exact topEquiv.toLinearEquiv.finiteDimensional
let L' := L ⊔ F⟮x⟯
haveI := adjoin.finiteDimensional (Algebra.IsIntegral.isIntegral (R := F) x)
refine ⟨L', inferInstance, by_contra fun h ↦ ?_⟩
have h1 : L = L' := eq_of_le_of_finrank_le le_sup_left ((not_lt.1 h).trans hn)
have h2 : F⟮x⟯ ≤ L' := le_sup_right
exact hx <| (h1.symm ▸ h2) <| mem_adjoin_simple_self F x
theorem _root_.minpoly.natDegree_le (x : L) [FiniteDimensional K L] :
(minpoly K x).natDegree ≤ finrank K L :=
le_of_eq_of_le (IntermediateField.adjoin.finrank (.of_finite _ _)).symm
K⟮x⟯.toSubmodule.finrank_le
theorem _root_.minpoly.degree_le (x : L) [FiniteDimensional K L] :
(minpoly K x).degree ≤ finrank K L :=
degree_le_of_natDegree_le (minpoly.natDegree_le x)
-- TODO: generalize to `Sort`
/-- A compositum of algebraic extensions is algebraic -/
theorem isAlgebraic_iSup {ι : Type*} {t : ι → IntermediateField K L}
(h : ∀ i, Algebra.IsAlgebraic K (t i)) :
Algebra.IsAlgebraic K (⨆ i, t i : IntermediateField K L) := by
constructor
rintro ⟨x, hx⟩
obtain ⟨s, hx⟩ := exists_finset_of_mem_supr' hx
rw [isAlgebraic_iff, Subtype.coe_mk, ← Subtype.coe_mk (p := (· ∈ _)) x hx, ← isAlgebraic_iff]
haveI : ∀ i : Σ i, t i, FiniteDimensional K K⟮(i.2 : L)⟯ := fun ⟨i, x⟩ ↦
adjoin.finiteDimensional (isIntegral_iff.1 (Algebra.IsIntegral.isIntegral x))
apply IsAlgebraic.of_finite
theorem isAlgebraic_adjoin {S : Set L} (hS : ∀ x ∈ S, IsIntegral K x) :
Algebra.IsAlgebraic K (adjoin K S) := by
rw [← biSup_adjoin_simple, ← iSup_subtype'']
exact isAlgebraic_iSup fun x ↦ isAlgebraic_adjoin_simple (hS x x.2)
/-- If `L / K` is a field extension, `S` is a finite subset of `L`, such that every element of `S`
is integral (= algebraic) over `K`, then `K(S) / K` is a finite extension.
A direct corollary of `finiteDimensional_iSup_of_finite`. -/
theorem finiteDimensional_adjoin {S : Set L} [Finite S] (hS : ∀ x ∈ S, IsIntegral K x) :
FiniteDimensional K (adjoin K S) := by
rw [← biSup_adjoin_simple, ← iSup_subtype'']
haveI (x : S) := adjoin.finiteDimensional (hS x.1 x.2)
exact finiteDimensional_iSup_of_finite
end PowerBasis
/-- Algebra homomorphism `F⟮α⟯ →ₐ[F] K` are in bijection with the set of roots
of `minpoly α` in `K`. -/
noncomputable def algHomAdjoinIntegralEquiv (h : IsIntegral F α) :
(F⟮α⟯ →ₐ[F] K) ≃ { x // x ∈ (minpoly F α).aroots K } :=
(adjoin.powerBasis h).liftEquiv'.trans
((Equiv.refl _).subtypeEquiv fun x => by
rw [adjoin.powerBasis_gen, minpoly_gen, Equiv.refl_apply])
lemma algHomAdjoinIntegralEquiv_symm_apply_gen (h : IsIntegral F α)
(x : { x // x ∈ (minpoly F α).aroots K }) :
(algHomAdjoinIntegralEquiv F h).symm x (AdjoinSimple.gen F α) = x :=
(adjoin.powerBasis h).lift_gen x.val <| by
rw [adjoin.powerBasis_gen, minpoly_gen]; exact (mem_aroots.mp x.2).2
/-- Fintype of algebra homomorphism `F⟮α⟯ →ₐ[F] K` -/
noncomputable def fintypeOfAlgHomAdjoinIntegral (h : IsIntegral F α) : Fintype (F⟮α⟯ →ₐ[F] K) :=
PowerBasis.AlgHom.fintype (adjoin.powerBasis h)
theorem card_algHom_adjoin_integral (h : IsIntegral F α) (h_sep : IsSeparable F α)
(h_splits : (minpoly F α).Splits (algebraMap F K)) :
@Fintype.card (F⟮α⟯ →ₐ[F] K) (fintypeOfAlgHomAdjoinIntegral F h) = (minpoly F α).natDegree := by
rw [AlgHom.card_of_powerBasis] <;>
simp only [IsSeparable, adjoin.powerBasis_dim, adjoin.powerBasis_gen, minpoly_gen, h_splits]
exact h_sep
-- Apparently `K⟮root f⟯ →+* K⟮root f⟯` is expensive to unify during instance synthesis.
open FiniteDimensional AdjoinRoot in
/-- Let `f, g` be monic polynomials over `K`. If `f` is irreducible, and `g(x) - α` is irreducible
in `K⟮α⟯` with `α` a root of `f`, then `f(g(x))` is irreducible. -/
theorem _root_.Polynomial.irreducible_comp {f g : K[X]} (hfm : f.Monic) (hgm : g.Monic)
(hf : Irreducible f)
(hg : ∀ (E : Type u) [Field E] [Algebra K E] (x : E) (hx : minpoly K x = f),
Irreducible (g.map (algebraMap _ _) - C (AdjoinSimple.gen K x))) :
Irreducible (f.comp g) := by
have hf' : natDegree f ≠ 0 :=
fun e ↦ not_irreducible_C (f.coeff 0) (eq_C_of_natDegree_eq_zero e ▸ hf)
have hg' : natDegree g ≠ 0 := by
have := Fact.mk hf
intro e
apply not_irreducible_C ((g.map (algebraMap _ _)).coeff 0 - AdjoinSimple.gen K (root f))
-- Needed to specialize `map_sub` to avoid a timeout #8386
rw [RingHom.map_sub, coeff_map, ← map_C, ← eq_C_of_natDegree_eq_zero e]
apply hg (AdjoinRoot f)
rw [AdjoinRoot.minpoly_root hf.ne_zero, hfm, inv_one, map_one, mul_one]
have H₁ : f.comp g ≠ 0 := fun h ↦ by simpa [hf', hg', natDegree_comp] using congr_arg natDegree h
have H₂ : ¬ IsUnit (f.comp g) := fun h ↦
by simpa [hf', hg', natDegree_comp] using natDegree_eq_zero_of_isUnit h
have ⟨p, hp₁, hp₂⟩ := WfDvdMonoid.exists_irreducible_factor H₂ H₁
suffices natDegree p = natDegree f * natDegree g from (associated_of_dvd_of_natDegree_le hp₂ H₁
(this.trans natDegree_comp.symm).ge).irreducible hp₁
have := Fact.mk hp₁
let Kx := AdjoinRoot p
letI := (AdjoinRoot.powerBasis hp₁.ne_zero).finite
have key₁ : f = minpoly K (aeval (root p) g) := by
refine minpoly.eq_of_irreducible_of_monic hf ?_ hfm
rw [← aeval_comp]
exact aeval_eq_zero_of_dvd_aeval_eq_zero hp₂ (AdjoinRoot.eval₂_root p)
have key₁' : finrank K K⟮aeval (root p) g⟯ = natDegree f := by
rw [adjoin.finrank, ← key₁]
exact IsIntegral.of_finite _ _
have key₂ : g.map (algebraMap _ _) - C (AdjoinSimple.gen K (aeval (root p) g)) =
minpoly K⟮aeval (root p) g⟯ (root p) :=
minpoly.eq_of_irreducible_of_monic (hg _ _ key₁.symm) (by simp [AdjoinSimple.gen])
(Monic.sub_of_left (hgm.map _) (degree_lt_degree (by simpa [Nat.pos_iff_ne_zero] using hg')))
have key₂' : finrank K⟮aeval (root p) g⟯ Kx = natDegree g := by
trans natDegree (minpoly K⟮aeval (root p) g⟯ (root p))
· have : K⟮aeval (root p) g⟯⟮root p⟯ = ⊤ := by
apply restrictScalars_injective K
rw [restrictScalars_top, adjoin_adjoin_left, Set.union_comm, ← adjoin_adjoin_left,
adjoin_root_eq_top p, restrictScalars_adjoin]
simp
rw [← finrank_top', ← this, adjoin.finrank]
exact IsIntegral.of_finite _ _
· simp [← key₂]
have := FiniteDimensional.finrank_mul_finrank K K⟮aeval (root p) g⟯ Kx
rwa [key₁', key₂', (AdjoinRoot.powerBasis hp₁.ne_zero).finrank, powerBasis_dim, eq_comm] at this
end AdjoinIntegralElement
section Induction
variable {F : Type*} [Field F] {E : Type*} [Field E] [Algebra F E]
/-- An intermediate field `S` is finitely generated if there exists `t : Finset E` such that
`IntermediateField.adjoin F t = S`. -/
def FG (S : IntermediateField F E) : Prop :=
∃ t : Finset E, adjoin F ↑t = S
theorem fg_adjoin_finset (t : Finset E) : (adjoin F (↑t : Set E)).FG :=
⟨t, rfl⟩
theorem fg_def {S : IntermediateField F E} : S.FG ↔ ∃ t : Set E, Set.Finite t ∧ adjoin F t = S :=
Iff.symm Set.exists_finite_iff_finset
theorem fg_bot : (⊥ : IntermediateField F E).FG :=
-- Porting note: was `⟨∅, adjoin_empty F E⟩`
⟨∅, by simp only [Finset.coe_empty, adjoin_empty]⟩
theorem fG_of_fG_toSubalgebra (S : IntermediateField F E) (h : S.toSubalgebra.FG) : S.FG := by
cases' h with t ht
exact ⟨t, (eq_adjoin_of_eq_algebra_adjoin _ _ _ ht.symm).symm⟩
theorem fg_of_noetherian (S : IntermediateField F E) [IsNoetherian F E] : S.FG :=
S.fG_of_fG_toSubalgebra S.toSubalgebra.fg_of_noetherian
theorem induction_on_adjoin_finset (S : Finset E) (P : IntermediateField F E → Prop) (base : P ⊥)
(ih : ∀ (K : IntermediateField F E), ∀ x ∈ S, P K → P (K⟮x⟯.restrictScalars F)) :
P (adjoin F S) := by
classical
refine Finset.induction_on' S ?_ (fun ha _ _ h => ?_)
· simp [base]
· rw [Finset.coe_insert, Set.insert_eq, Set.union_comm, ← adjoin_adjoin_left]
exact ih (adjoin F _) _ ha h
theorem induction_on_adjoin_fg (P : IntermediateField F E → Prop) (base : P ⊥)
(ih : ∀ (K : IntermediateField F E) (x : E), P K → P (K⟮x⟯.restrictScalars F))
(K : IntermediateField F E) (hK : K.FG) : P K := by
obtain ⟨S, rfl⟩ := hK
exact induction_on_adjoin_finset S P base fun K x _ hK => ih K x hK
theorem induction_on_adjoin [FiniteDimensional F E] (P : IntermediateField F E → Prop)
(base : P ⊥) (ih : ∀ (K : IntermediateField F E) (x : E), P K → P (K⟮x⟯.restrictScalars F))
(K : IntermediateField F E) : P K :=
letI : IsNoetherian F E := IsNoetherian.iff_fg.2 inferInstance
induction_on_adjoin_fg P base ih K K.fg_of_noetherian
end Induction
end IntermediateField
section Minpoly
open AlgEquiv
variable {K L : Type _} [Field K] [Field L] [Algebra K L]
namespace AdjoinRoot
/-- The canonical algebraic homomorphism from `AdjoinRoot p` to `AdjoinRoot q`, where
the polynomial `q : K[X]` divides `p`. -/
noncomputable def algHomOfDvd {p q : K[X]} (hpq : q ∣ p) :
AdjoinRoot p →ₐ[K] AdjoinRoot q :=
(liftHom p (root q) (by simp only [aeval_eq, mk_eq_zero, hpq]))
theorem coe_algHomOfDvd {p q : K[X]} (hpq : q ∣ p) :
(algHomOfDvd hpq).toFun = liftHom p (root q) (by simp only [aeval_eq, mk_eq_zero, hpq]) :=
rfl
/-- `algHomOfDvd` sends `AdjoinRoot.root p` to `AdjoinRoot.root q`. -/
theorem algHomOfDvd_apply_root {p q : K[X]} (hpq : q ∣ p) :
algHomOfDvd hpq (root p) = root q := by
rw [algHomOfDvd, liftHom_root]
/-- The canonical algebraic equivalence between `AdjoinRoot p` and `AdjoinRoot q`, where
the two polynomials `p q : K[X]` are equal. -/
noncomputable def algEquivOfEq {p q : K[X]} (hp : p ≠ 0) (h_eq : p = q) :
AdjoinRoot p ≃ₐ[K] AdjoinRoot q :=
ofAlgHom (algHomOfDvd (dvd_of_eq h_eq.symm)) (algHomOfDvd (dvd_of_eq h_eq))
(PowerBasis.algHom_ext (powerBasis (h_eq ▸ hp))
(by rw [algHomOfDvd, powerBasis_gen (h_eq ▸ hp), AlgHom.coe_comp, Function.comp_apply,
algHomOfDvd, liftHom_root, liftHom_root, AlgHom.coe_id, id_eq]))
(PowerBasis.algHom_ext (powerBasis hp)
(by rw [algHomOfDvd, powerBasis_gen hp, AlgHom.coe_comp, Function.comp_apply, algHomOfDvd,
liftHom_root, liftHom_root, AlgHom.coe_id, id_eq]))
theorem coe_algEquivOfEq {p q : K[X]} (hp : p ≠ 0) (h_eq : p = q) :
(algEquivOfEq hp h_eq).toFun = liftHom p (root q) (by rw [h_eq, aeval_eq, mk_self]) :=
rfl
theorem algEquivOfEq_toAlgHom {p q : K[X]} (hp : p ≠ 0) (h_eq : p = q) :
(algEquivOfEq hp h_eq).toAlgHom = liftHom p (root q) (by rw [h_eq, aeval_eq, mk_self]) :=
rfl
/-- `algEquivOfEq` sends `AdjoinRoot.root p` to `AdjoinRoot.root q`. -/
theorem algEquivOfEq_apply_root {p q : K[X]} (hp : p ≠ 0) (h_eq : p = q) :
algEquivOfEq hp h_eq (root p) = root q := by
rw [← coe_algHom, algEquivOfEq_toAlgHom, liftHom_root]
/-- The canonical algebraic equivalence between `AdjoinRoot p` and `AdjoinRoot q`,
where the two polynomials `p q : K[X]` are associated.-/
noncomputable def algEquivOfAssociated {p q : K[X]} (hp : p ≠ 0) (hpq : Associated p q) :
AdjoinRoot p ≃ₐ[K] AdjoinRoot q :=
ofAlgHom (liftHom p (root q) (by simp only [aeval_eq, mk_eq_zero, hpq.symm.dvd] ))
(liftHom q (root p) (by simp only [aeval_eq, mk_eq_zero, hpq.dvd]))
( PowerBasis.algHom_ext (powerBasis (hpq.ne_zero_iff.mp hp))
(by rw [powerBasis_gen (hpq.ne_zero_iff.mp hp), AlgHom.coe_comp, Function.comp_apply,
liftHom_root, liftHom_root, AlgHom.coe_id, id_eq]))
(PowerBasis.algHom_ext (powerBasis hp)
(by rw [powerBasis_gen hp, AlgHom.coe_comp, Function.comp_apply, liftHom_root, liftHom_root,
AlgHom.coe_id, id_eq]))
theorem coe_algEquivOfAssociated {p q : K[X]} (hp : p ≠ 0) (hpq : Associated p q) :
(algEquivOfAssociated hp hpq).toFun =
liftHom p (root q) (by simp only [aeval_eq, mk_eq_zero, hpq.symm.dvd]) :=
rfl
theorem algEquivOfAssociated_toAlgHom {p q : K[X]} (hp : p ≠ 0) (hpq : Associated p q) :
(algEquivOfAssociated hp hpq).toAlgHom =
liftHom p (root q) (by simp only [aeval_eq, mk_eq_zero, hpq.symm.dvd]) :=
rfl
/-- `algEquivOfAssociated` sends `AdjoinRoot.root p` to `AdjoinRoot.root q`. -/
theorem algEquivOfAssociated_apply_root {p q : K[X]} (hp : p ≠ 0) (hpq : Associated p q) :
algEquivOfAssociated hp hpq (root p) = root q := by
rw [← coe_algHom, algEquivOfAssociated_toAlgHom, liftHom_root]
end AdjoinRoot
namespace minpoly
open IntermediateField
/-- If `y : L` is a root of `minpoly K x`, then `minpoly K y = minpoly K x`. -/
theorem eq_of_root {x y : L} (hx : IsAlgebraic K x)
(h_ev : (Polynomial.aeval y) (minpoly K x) = 0) : minpoly K y = minpoly K x := by
have hy : IsAlgebraic K y := ⟨minpoly K x, ne_zero hx.isIntegral, h_ev⟩
exact Polynomial.eq_of_monic_of_associated (monic hy.isIntegral) (monic hx.isIntegral)
(Irreducible.associated_of_dvd (irreducible hy.isIntegral)
(irreducible hx.isIntegral) (dvd K y h_ev))
/-- The canonical `algEquiv` between `K⟮x⟯`and `K⟮y⟯`, sending `x` to `y`, where `x` and `y` have
the same minimal polynomial over `K`. -/
noncomputable def algEquiv {x y : L} (hx : IsAlgebraic K x)
(h_mp : minpoly K x = minpoly K y) : K⟮x⟯ ≃ₐ[K] K⟮y⟯ := by
have hy : IsAlgebraic K y := ⟨minpoly K x, ne_zero hx.isIntegral, (h_mp ▸ aeval _ _)⟩
exact AlgEquiv.trans (adjoinRootEquivAdjoin K hx.isIntegral).symm
(AlgEquiv.trans (AdjoinRoot.algEquivOfEq (ne_zero hx.isIntegral) h_mp)
(adjoinRootEquivAdjoin K hy.isIntegral))
/-- `minpoly.algEquiv` sends the generator of `K⟮x⟯` to the generator of `K⟮y⟯`. -/
theorem algEquiv_apply {x y : L} (hx : IsAlgebraic K x) (h_mp : minpoly K x = minpoly K y) :
algEquiv hx h_mp (AdjoinSimple.gen K x) = AdjoinSimple.gen K y := by
have hy : IsAlgebraic K y := ⟨minpoly K x, ne_zero hx.isIntegral, (h_mp ▸ aeval _ _)⟩
rw [algEquiv, trans_apply, ← adjoinRootEquivAdjoin_apply_root K hx.isIntegral,
symm_apply_apply, trans_apply, AdjoinRoot.algEquivOfEq_apply_root,
adjoinRootEquivAdjoin_apply_root K hy.isIntegral]
end minpoly
end Minpoly
namespace PowerBasis
variable {K L : Type*} [Field K] [Field L] [Algebra K L]
open IntermediateField
/-- `pb.equivAdjoinSimple` is the equivalence between `K⟮pb.gen⟯` and `L` itself. -/
noncomputable def equivAdjoinSimple (pb : PowerBasis K L) : K⟮pb.gen⟯ ≃ₐ[K] L :=
(adjoin.powerBasis pb.isIntegral_gen).equivOfMinpoly pb <| by
rw [adjoin.powerBasis_gen, minpoly_gen]
@[simp]
theorem equivAdjoinSimple_aeval (pb : PowerBasis K L) (f : K[X]) :
pb.equivAdjoinSimple (aeval (AdjoinSimple.gen K pb.gen) f) = aeval pb.gen f :=
equivOfMinpoly_aeval _ pb _ f
@[simp]
theorem equivAdjoinSimple_gen (pb : PowerBasis K L) :
pb.equivAdjoinSimple (AdjoinSimple.gen K pb.gen) = pb.gen :=
equivOfMinpoly_gen _ pb _
@[simp]
theorem equivAdjoinSimple_symm_aeval (pb : PowerBasis K L) (f : K[X]) :
pb.equivAdjoinSimple.symm (aeval pb.gen f) = aeval (AdjoinSimple.gen K pb.gen) f := by
rw [equivAdjoinSimple, equivOfMinpoly_symm, equivOfMinpoly_aeval, adjoin.powerBasis_gen]
@[simp]
theorem equivAdjoinSimple_symm_gen (pb : PowerBasis K L) :
pb.equivAdjoinSimple.symm pb.gen = AdjoinSimple.gen K pb.gen := by
rw [equivAdjoinSimple, equivOfMinpoly_symm, equivOfMinpoly_gen, adjoin.powerBasis_gen]
end PowerBasis
namespace IntermediateField
variable {K L L' : Type*} [Field K] [Field L] [Field L'] [Algebra K L] [Algebra K L']
theorem map_comap_eq (f : L →ₐ[K] L') (S : IntermediateField K L') :
(S.comap f).map f = S ⊓ f.fieldRange :=
SetLike.coe_injective Set.image_preimage_eq_inter_range
theorem map_comap_eq_self {f : L →ₐ[K] L'} {S : IntermediateField K L'} (h : S ≤ f.fieldRange) :
(S.comap f).map f = S := by
simpa only [inf_of_le_left h] using map_comap_eq f S
theorem map_comap_eq_self_of_surjective {f : L →ₐ[K] L'} (hf : Function.Surjective f)
(S : IntermediateField K L') : (S.comap f).map f = S :=
SetLike.coe_injective (Set.image_preimage_eq _ hf)
theorem comap_map (f : L →ₐ[K] L') (S : IntermediateField K L) : (S.map f).comap f = S :=
SetLike.coe_injective (Set.preimage_image_eq _ f.injective)
end IntermediateField
|
FieldTheory\AxGrothendieck.lean | /-
Copyright (c) 2023 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Algebra.MvPolynomial.Basic
import Mathlib.Data.Fintype.Card
import Mathlib.RingTheory.Algebraic
/-!
# Ax-Grothendieck for algebraic extensions of `ZMod p`
This file proves that if `R` is an algebraic extension of a finite field,
then any injective polynomial map `R^n → R^n` is also surjective.
This proof is required for the true Ax-Grothendieck theorem, which proves the same result
for any algebraically closed field of characteristic zero.
## TODO
The proof of the theorem for characteristic zero is not in mathlib, but it is at
https://github.com/Jlh18/ModelTheoryInLean8
-/
noncomputable section
open MvPolynomial Finset Function
/-- Any injective polynomial map over an algebraic extension of a finite field is surjective. -/
theorem ax_grothendieck_of_locally_finite {ι K R : Type*} [Field K] [Finite K] [CommRing R]
[Finite ι] [Algebra K R] [Algebra.IsAlgebraic K R] (ps : ι → MvPolynomial ι R)
(hinj : Injective fun v i => MvPolynomial.eval v (ps i)) :
Surjective fun v i => MvPolynomial.eval v (ps i) := by
classical
intro v
cases nonempty_fintype ι
/- `s` is the set of all coefficients of the polynomial, as well as all of
the coordinates of `v`, the point I am trying to find the preimage of. -/
let s : Finset R :=
(Finset.biUnion (univ : Finset ι) fun i => (ps i).support.image fun x => coeff x (ps i)) ∪
(univ : Finset ι).image v
have hv : ∀ i, v i ∈ Algebra.adjoin K (s : Set R) := fun j =>
Algebra.subset_adjoin (mem_union_right _ (mem_image.2 ⟨j, mem_univ _, rfl⟩))
have hs₁ : ∀ (i : ι) (k : ι →₀ ℕ),
k ∈ (ps i).support → coeff k (ps i) ∈ Algebra.adjoin K (s : Set R) :=
fun i k hk => Algebra.subset_adjoin
(mem_union_left _ (mem_biUnion.2 ⟨i, mem_univ _, mem_image_of_mem _ hk⟩))
letI := isNoetherian_adjoin_finset s fun x _ => Algebra.IsIntegral.isIntegral (R := K) x
letI := Module.IsNoetherian.finite K (Algebra.adjoin K (s : Set R))
letI : Finite (Algebra.adjoin K (s : Set R)) :=
FiniteDimensional.finite_of_finite K (Algebra.adjoin K (s : Set R))
-- The restriction of the polynomial map, `ps`, to the subalgebra generated by `s`
let res : (ι → Algebra.adjoin K (s : Set R)) → ι → Algebra.adjoin K (s : Set R) := fun x i =>
⟨eval (fun j : ι => (x j : R)) (ps i), eval_mem (hs₁ _) fun i => (x i).2⟩
have hres_inj : Injective res := by
intro x y hxy
ext i
simp only [Subtype.ext_iff, funext_iff] at hxy
exact congr_fun (hinj (funext hxy)) i
have hres_surj : Surjective res := Finite.injective_iff_surjective.1 hres_inj
cases' hres_surj fun i => ⟨v i, hv i⟩ with w hw
use fun i => w i
simpa only [Subtype.ext_iff, funext_iff] using hw
|
FieldTheory\Cardinality.lean | /-
Copyright (c) 2022 Eric Rodriguez. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Rodriguez
-/
import Mathlib.Algebra.Field.ULift
import Mathlib.Algebra.MvPolynomial.Cardinal
import Mathlib.Data.Nat.Factorization.PrimePow
import Mathlib.Data.Rat.Denumerable
import Mathlib.FieldTheory.Finite.GaloisField
import Mathlib.Logic.Equiv.TransferInstance
import Mathlib.RingTheory.Localization.Cardinality
import Mathlib.SetTheory.Cardinal.Divisibility
/-!
# Cardinality of Fields
In this file we show all the possible cardinalities of fields. All infinite cardinals can harbour
a field structure, and so can all types with prime power cardinalities, and this is sharp.
## Main statements
* `Fintype.nonempty_field_iff`: A `Fintype` can be given a field structure iff its cardinality is a
prime power.
* `Infinite.nonempty_field` : Any infinite type can be endowed a field structure.
* `Field.nonempty_iff` : There is a field structure on type iff its cardinality is a prime power.
-/
local notation "‖" x "‖" => Fintype.card x
open scoped Cardinal nonZeroDivisors
universe u
/-- A finite field has prime power cardinality. -/
theorem Fintype.isPrimePow_card_of_field {α} [Fintype α] [Field α] : IsPrimePow ‖α‖ := by
-- TODO: `Algebra` version of `CharP.exists`, of type `∀ p, Algebra (ZMod p) α`
cases' CharP.exists α with p _
haveI hp := Fact.mk (CharP.char_is_prime α p)
letI : Algebra (ZMod p) α := ZMod.algebra _ _
let b := IsNoetherian.finsetBasis (ZMod p) α
rw [Module.card_fintype b, ZMod.card, isPrimePow_pow_iff]
· exact hp.1.isPrimePow
rw [← FiniteDimensional.finrank_eq_card_basis b]
exact FiniteDimensional.finrank_pos.ne'
/-- A `Fintype` can be given a field structure iff its cardinality is a prime power. -/
theorem Fintype.nonempty_field_iff {α} [Fintype α] : Nonempty (Field α) ↔ IsPrimePow ‖α‖ := by
refine ⟨fun ⟨h⟩ => Fintype.isPrimePow_card_of_field, ?_⟩
rintro ⟨p, n, hp, hn, hα⟩
haveI := Fact.mk hp.nat_prime
exact ⟨(Fintype.equivOfCardEq ((GaloisField.card p n hn.ne').trans hα)).symm.field⟩
theorem Fintype.not_isField_of_card_not_prime_pow {α} [Fintype α] [Ring α] :
¬IsPrimePow ‖α‖ → ¬IsField α :=
mt fun h => Fintype.nonempty_field_iff.mp ⟨h.toField⟩
/-- Any infinite type can be endowed a field structure. -/
theorem Infinite.nonempty_field {α : Type u} [Infinite α] : Nonempty (Field α) := by
letI K := FractionRing (MvPolynomial α <| ULift.{u} ℚ)
suffices #α = #K by
obtain ⟨e⟩ := Cardinal.eq.1 this
exact ⟨e.field⟩
rw [← IsLocalization.card K (MvPolynomial α <| ULift.{u} ℚ)⁰ le_rfl]
apply le_antisymm
· refine
⟨⟨fun a => MvPolynomial.monomial (Finsupp.single a 1) (1 : ULift.{u} ℚ), fun x y h => ?_⟩⟩
simpa [MvPolynomial.monomial_eq_monomial_iff, Finsupp.single_eq_single_iff] using h
· simp
/-- There is a field structure on type if and only if its cardinality is a prime power. -/
theorem Field.nonempty_iff {α : Type u} : Nonempty (Field α) ↔ IsPrimePow #α := by
rw [Cardinal.isPrimePow_iff]
cases' fintypeOrInfinite α with h h
· simpa only [Cardinal.mk_fintype, Nat.cast_inj, exists_eq_left',
(Cardinal.nat_lt_aleph0 _).not_le, false_or_iff] using Fintype.nonempty_field_iff
· simpa only [← Cardinal.infinite_iff, h, true_or_iff, iff_true_iff] using Infinite.nonempty_field
|
FieldTheory\ChevalleyWarning.lean | /-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.FieldTheory.Finite.Basic
/-!
# The Chevalley–Warning theorem
This file contains a proof of the Chevalley–Warning theorem.
Throughout most of this file, `K` denotes a finite field
and `q` is notation for the cardinality of `K`.
## Main results
1. Let `f` be a multivariate polynomial in finitely many variables (`X s`, `s : σ`)
such that the total degree of `f` is less than `(q-1)` times the cardinality of `σ`.
Then the evaluation of `f` on all points of `σ → K` (aka `K^σ`) sums to `0`.
(`sum_eval_eq_zero`)
2. The Chevalley–Warning theorem (`char_dvd_card_solutions_of_sum_lt`).
Let `f i` be a finite family of multivariate polynomials
in finitely many variables (`X s`, `s : σ`) such that
the sum of the total degrees of the `f i` is less than the cardinality of `σ`.
Then the number of common solutions of the `f i`
is divisible by the characteristic of `K`.
## Notation
- `K` is a finite field
- `q` is notation for the cardinality of `K`
- `σ` is the indexing type for the variables of a multivariate polynomial ring over `K`
-/
universe u v
section FiniteField
open MvPolynomial
open Function hiding eval
open Finset FiniteField
variable {K σ ι : Type*} [Fintype K] [Field K] [Fintype σ] [DecidableEq σ]
local notation "q" => Fintype.card K
theorem MvPolynomial.sum_eval_eq_zero (f : MvPolynomial σ K)
(h : f.totalDegree < (q - 1) * Fintype.card σ) : ∑ x, eval x f = 0 := by
haveI : DecidableEq K := Classical.decEq K
calc
∑ x, eval x f = ∑ x : σ → K, ∑ d ∈ f.support, f.coeff d * ∏ i, x i ^ d i := by
simp only [eval_eq']
_ = ∑ d ∈ f.support, ∑ x : σ → K, f.coeff d * ∏ i, x i ^ d i := sum_comm
_ = 0 := sum_eq_zero ?_
intro d hd
obtain ⟨i, hi⟩ : ∃ i, d i < q - 1 := f.exists_degree_lt (q - 1) h hd
calc
(∑ x : σ → K, f.coeff d * ∏ i, x i ^ d i) = f.coeff d * ∑ x : σ → K, ∏ i, x i ^ d i :=
(mul_sum ..).symm
_ = 0 := (mul_eq_zero.mpr ∘ Or.inr) ?_
calc
(∑ x : σ → K, ∏ i, x i ^ d i) =
∑ x₀ : { j // j ≠ i } → K, ∑ x : { x : σ → K // x ∘ (↑) = x₀ }, ∏ j, (x : σ → K) j ^ d j :=
(Fintype.sum_fiberwise _ _).symm
_ = 0 := Fintype.sum_eq_zero _ ?_
intro x₀
let e : K ≃ { x // x ∘ ((↑) : _ → σ) = x₀ } := (Equiv.subtypeEquivCodomain _).symm
calc
(∑ x : { x : σ → K // x ∘ (↑) = x₀ }, ∏ j, (x : σ → K) j ^ d j) =
∑ a : K, ∏ j : σ, (e a : σ → K) j ^ d j := (e.sum_comp _).symm
_ = ∑ a : K, (∏ j, x₀ j ^ d j) * a ^ d i := Fintype.sum_congr _ _ ?_
_ = (∏ j, x₀ j ^ d j) * ∑ a : K, a ^ d i := by rw [mul_sum]
_ = 0 := by rw [sum_pow_lt_card_sub_one K _ hi, mul_zero]
intro a
let e' : { j // j = i } ⊕ { j // j ≠ i } ≃ σ := Equiv.sumCompl _
letI : Unique { j // j = i } :=
{ default := ⟨i, rfl⟩
uniq := fun ⟨j, h⟩ => Subtype.val_injective h }
calc
(∏ j : σ, (e a : σ → K) j ^ d j) =
(e a : σ → K) i ^ d i * ∏ j : { j // j ≠ i }, (e a : σ → K) j ^ d j := by
rw [← e'.prod_comp, Fintype.prod_sum_type, univ_unique, prod_singleton]; rfl
_ = a ^ d i * ∏ j : { j // j ≠ i }, (e a : σ → K) j ^ d j := by
rw [Equiv.subtypeEquivCodomain_symm_apply_eq]
_ = a ^ d i * ∏ j, x₀ j ^ d j := congr_arg _ (Fintype.prod_congr _ _ ?_)
-- see below
_ = (∏ j, x₀ j ^ d j) * a ^ d i := mul_comm _ _
-- the remaining step of the calculation above
rintro ⟨j, hj⟩
show (e a : σ → K) j ^ d j = x₀ ⟨j, hj⟩ ^ d j
rw [Equiv.subtypeEquivCodomain_symm_apply_ne]
variable [DecidableEq K] (p : ℕ) [CharP K p]
/-- The **Chevalley–Warning theorem**, finitary version.
Let `(f i)` be a finite family of multivariate polynomials
in finitely many variables (`X s`, `s : σ`) over a finite field of characteristic `p`.
Assume that the sum of the total degrees of the `f i` is less than the cardinality of `σ`.
Then the number of common solutions of the `f i` is divisible by `p`. -/
theorem char_dvd_card_solutions_of_sum_lt {s : Finset ι} {f : ι → MvPolynomial σ K}
(h : (∑ i ∈ s, (f i).totalDegree) < Fintype.card σ) :
p ∣ Fintype.card { x : σ → K // ∀ i ∈ s, eval x (f i) = 0 } := by
have hq : 0 < q - 1 := by rw [← Fintype.card_units, Fintype.card_pos_iff]; exact ⟨1⟩
let S : Finset (σ → K) := { x ∈ univ | ∀ i ∈ s, eval x (f i) = 0 }.toFinset
have hS : ∀ x : σ → K, x ∈ S ↔ ∀ i : ι, i ∈ s → eval x (f i) = 0 := by
intro x
simp only [S, Set.toFinset_setOf, mem_univ, true_and, mem_filter]
/- The polynomial `F = ∏ i ∈ s, (1 - (f i)^(q - 1))` has the nice property
that it takes the value `1` on elements of `{x : σ → K // ∀ i ∈ s, (f i).eval x = 0}`
while it is `0` outside that locus.
Hence the sum of its values is equal to the cardinality of
`{x : σ → K // ∀ i ∈ s, (f i).eval x = 0}` modulo `p`. -/
let F : MvPolynomial σ K := ∏ i ∈ s, (1 - f i ^ (q - 1))
have hF : ∀ x, eval x F = if x ∈ S then 1 else 0 := by
intro x
calc
eval x F = ∏ i ∈ s, eval x (1 - f i ^ (q - 1)) := eval_prod s _ x
_ = if x ∈ S then 1 else 0 := ?_
simp only [(eval x).map_sub, (eval x).map_pow, (eval x).map_one]
split_ifs with hx
· apply Finset.prod_eq_one
intro i hi
rw [hS] at hx
rw [hx i hi, zero_pow hq.ne', sub_zero]
· obtain ⟨i, hi, hx⟩ : ∃ i ∈ s, eval x (f i) ≠ 0 := by
simpa [hS, not_forall, Classical.not_imp] using hx
apply Finset.prod_eq_zero hi
rw [pow_card_sub_one_eq_one (eval x (f i)) hx, sub_self]
-- In particular, we can now show:
have key : ∑ x, eval x F = Fintype.card { x : σ → K // ∀ i ∈ s, eval x (f i) = 0 } := by
rw [Fintype.card_of_subtype S hS, card_eq_sum_ones, Nat.cast_sum, Nat.cast_one, ←
Fintype.sum_extend_by_zero S, sum_congr rfl fun x _ => hF x]
-- With these preparations under our belt, we will approach the main goal.
show p ∣ Fintype.card { x // ∀ i : ι, i ∈ s → eval x (f i) = 0 }
rw [← CharP.cast_eq_zero_iff K, ← key]
show (∑ x, eval x F) = 0
-- We are now ready to apply the main machine, proven before.
apply F.sum_eval_eq_zero
-- It remains to verify the crucial assumption of this machine
show F.totalDegree < (q - 1) * Fintype.card σ
calc
F.totalDegree ≤ ∑ i ∈ s, (1 - f i ^ (q - 1)).totalDegree := totalDegree_finset_prod s _
_ ≤ ∑ i ∈ s, (q - 1) * (f i).totalDegree := sum_le_sum fun i _ => ?_
-- see ↓
_ = (q - 1) * ∑ i ∈ s, (f i).totalDegree := (mul_sum ..).symm
_ < (q - 1) * Fintype.card σ := by rwa [mul_lt_mul_left hq]
-- Now we prove the remaining step from the preceding calculation
show (1 - f i ^ (q - 1)).totalDegree ≤ (q - 1) * (f i).totalDegree
calc
(1 - f i ^ (q - 1)).totalDegree ≤
max (1 : MvPolynomial σ K).totalDegree (f i ^ (q - 1)).totalDegree := totalDegree_sub _ _
_ ≤ (f i ^ (q - 1)).totalDegree := by simp
_ ≤ (q - 1) * (f i).totalDegree := totalDegree_pow _ _
/-- The **Chevalley–Warning theorem**, `Fintype` version.
Let `(f i)` be a finite family of multivariate polynomials
in finitely many variables (`X s`, `s : σ`) over a finite field of characteristic `p`.
Assume that the sum of the total degrees of the `f i` is less than the cardinality of `σ`.
Then the number of common solutions of the `f i` is divisible by `p`. -/
theorem char_dvd_card_solutions_of_fintype_sum_lt [Fintype ι] {f : ι → MvPolynomial σ K}
(h : (∑ i, (f i).totalDegree) < Fintype.card σ) :
p ∣ Fintype.card { x : σ → K // ∀ i, eval x (f i) = 0 } := by
simpa using char_dvd_card_solutions_of_sum_lt p h
/-- The **Chevalley–Warning theorem**, unary version.
Let `f` be a multivariate polynomial in finitely many variables (`X s`, `s : σ`)
over a finite field of characteristic `p`.
Assume that the total degree of `f` is less than the cardinality of `σ`.
Then the number of solutions of `f` is divisible by `p`.
See `char_dvd_card_solutions_of_sum_lt` for a version that takes a family of polynomials `f i`. -/
theorem char_dvd_card_solutions {f : MvPolynomial σ K} (h : f.totalDegree < Fintype.card σ) :
p ∣ Fintype.card { x : σ → K // eval x f = 0 } := by
let F : Unit → MvPolynomial σ K := fun _ => f
have : (∑ i : Unit, (F i).totalDegree) < Fintype.card σ := h
-- Porting note: was
-- `simpa only [F, Fintype.univ_punit, forall_eq, mem_singleton] using`
-- ` char_dvd_card_solutions_of_sum_lt p this`
convert char_dvd_card_solutions_of_sum_lt p this
aesop
/-- The **Chevalley–Warning theorem**, binary version.
Let `f₁`, `f₂` be two multivariate polynomials in finitely many variables (`X s`, `s : σ`) over a
finite field of characteristic `p`.
Assume that the sum of the total degrees of `f₁` and `f₂` is less than the cardinality of `σ`.
Then the number of common solutions of the `f₁` and `f₂` is divisible by `p`. -/
theorem char_dvd_card_solutions_of_add_lt {f₁ f₂ : MvPolynomial σ K}
(h : f₁.totalDegree + f₂.totalDegree < Fintype.card σ) :
p ∣ Fintype.card { x : σ → K // eval x f₁ = 0 ∧ eval x f₂ = 0 } := by
let F : Bool → MvPolynomial σ K := fun b => cond b f₂ f₁
have : (∑ b : Bool, (F b).totalDegree) < Fintype.card σ := (add_comm _ _).trans_lt h
simpa only [Bool.forall_bool] using char_dvd_card_solutions_of_fintype_sum_lt p this
end FiniteField
|
FieldTheory\Extension.lean | /-
Copyright (c) 2020 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning
-/
import Mathlib.FieldTheory.Adjoin
/-!
# Extension of field embeddings
`IntermediateField.exists_algHom_of_adjoin_splits'` is the main result: if E/L/F is a tower of
field extensions, K is another extension of F, and `f` is an embedding of L/F into K/F, such
that the minimal polynomials of a set of generators of E/L splits in K (via `f`), then `f`
extends to an embedding of E/F into K/F.
-/
open Polynomial
namespace IntermediateField
variable (F E K : Type*) [Field F] [Field E] [Field K] [Algebra F E] [Algebra F K] {S : Set E}
/-- Lifts `L → K` of `F → K` -/
structure Lifts where
/-- The domain of a lift. -/
carrier : IntermediateField F E
/-- The lifted RingHom, expressed as an AlgHom. -/
emb : carrier →ₐ[F] K
variable {F E K}
instance : PartialOrder (Lifts F E K) where
le L₁ L₂ := ∃ h : L₁.carrier ≤ L₂.carrier, ∀ x, L₂.emb (inclusion h x) = L₁.emb x
le_refl L := ⟨le_rfl, by simp⟩
le_trans L₁ L₂ L₃ := by
rintro ⟨h₁₂, h₁₂'⟩ ⟨h₂₃, h₂₃'⟩
refine ⟨h₁₂.trans h₂₃, fun _ ↦ ?_⟩
rw [← inclusion_inclusion h₁₂ h₂₃, h₂₃', h₁₂']
le_antisymm := by
rintro ⟨L₁, e₁⟩ ⟨L₂, e₂⟩ ⟨h₁₂, h₁₂'⟩ ⟨h₂₁, h₂₁'⟩
obtain rfl : L₁ = L₂ := h₁₂.antisymm h₂₁
congr
exact AlgHom.ext h₂₁'
noncomputable instance : OrderBot (Lifts F E K) where
bot := ⟨⊥, (Algebra.ofId F K).comp (botEquiv F E)⟩
bot_le L := ⟨bot_le, fun x ↦ by
obtain ⟨x, rfl⟩ := (botEquiv F E).symm.surjective x
simp_rw [AlgHom.comp_apply, AlgHom.coe_coe, AlgEquiv.apply_symm_apply]
exact L.emb.commutes x⟩
noncomputable instance : Inhabited (Lifts F E K) :=
⟨⊥⟩
/-- A chain of lifts has an upper bound. -/
theorem Lifts.exists_upper_bound (c : Set (Lifts F E K)) (hc : IsChain (· ≤ ·) c) :
∃ ub, ∀ a ∈ c, a ≤ ub := by
let t (i : ↑(insert ⊥ c)) := i.val.carrier
let t' (i) := (t i).toSubalgebra
have hc := hc.insert fun _ _ _ ↦ .inl bot_le
have dir : Directed (· ≤ ·) t := hc.directedOn.directed_val.mono_comp _ fun _ _ h ↦ h.1
refine ⟨⟨iSup t, (Subalgebra.iSupLift t' dir (fun i ↦ i.val.emb) (fun i j h ↦ ?_) _ rfl).comp
(Subalgebra.equivOfEq _ _ <| toSubalgebra_iSup_of_directed dir)⟩,
fun L hL ↦ have hL := Set.mem_insert_of_mem ⊥ hL; ⟨le_iSup t ⟨L, hL⟩, fun x ↦ ?_⟩⟩
· refine AlgHom.ext fun x ↦ (hc.total i.2 j.2).elim (fun hij ↦ (hij.snd x).symm) fun hji ↦ ?_
erw [AlgHom.comp_apply, ← hji.snd (Subalgebra.inclusion h x),
inclusion_inclusion, inclusion_self, AlgHom.id_apply x]
· dsimp only [AlgHom.comp_apply]
exact Subalgebra.iSupLift_inclusion (K := t') (i := ⟨L, hL⟩) x (le_iSup t' ⟨L, hL⟩)
/-- Given a lift `x` and an integral element `s : E` over `x.carrier` whose conjugates over
`x.carrier` are all in `K`, we can extend the lift to a lift whose carrier contains `s`. -/
theorem Lifts.exists_lift_of_splits' (x : Lifts F E K) {s : E} (h1 : IsIntegral x.carrier s)
(h2 : (minpoly x.carrier s).Splits x.emb.toRingHom) : ∃ y, x ≤ y ∧ s ∈ y.carrier :=
have I2 := (minpoly.degree_pos h1).ne'
letI : Algebra x.carrier K := x.emb.toRingHom.toAlgebra
let carrier := x.carrier⟮s⟯.restrictScalars F
letI : Algebra x.carrier carrier := x.carrier⟮s⟯.toSubalgebra.algebra
let φ : carrier →ₐ[x.carrier] K := ((algHomAdjoinIntegralEquiv x.carrier h1).symm
⟨rootOfSplits x.emb.toRingHom h2 I2, by
rw [mem_aroots, and_iff_right (minpoly.ne_zero h1)]
exact map_rootOfSplits x.emb.toRingHom h2 I2⟩)
⟨⟨carrier, (@algHomEquivSigma F x.carrier carrier K _ _ _ _ _ _ _ _
(IsScalarTower.of_algebraMap_eq fun _ ↦ rfl)).symm ⟨x.emb, φ⟩⟩,
⟨fun z hz ↦ algebraMap_mem x.carrier⟮s⟯ ⟨z, hz⟩, φ.commutes⟩,
mem_adjoin_simple_self x.carrier s⟩
/-- Given an integral element `s : E` over `F` whose `F`-conjugates are all in `K`,
any lift can be extended to one whose carrier contains `s`. -/
theorem Lifts.exists_lift_of_splits (x : Lifts F E K) {s : E} (h1 : IsIntegral F s)
(h2 : (minpoly F s).Splits (algebraMap F K)) : ∃ y, x ≤ y ∧ s ∈ y.carrier :=
Lifts.exists_lift_of_splits' x h1.tower_top <| h1.minpoly_splits_tower_top' <| by
rwa [← x.emb.comp_algebraMap] at h2
section
private theorem exists_algHom_adjoin_of_splits'' {L : IntermediateField F E}
(f : L →ₐ[F] K) (hK : ∀ s ∈ S, IsIntegral L s ∧ (minpoly L s).Splits f.toRingHom) :
∃ φ : adjoin L S →ₐ[F] K, φ.comp (IsScalarTower.toAlgHom F L _) = f := by
obtain ⟨φ, hfφ, hφ⟩ := zorn_nonempty_Ici₀ _
(fun c _ hc _ _ ↦ Lifts.exists_upper_bound c hc) ⟨L, f⟩ le_rfl
refine ⟨φ.emb.comp (inclusion <| (le_extendScalars_iff hfφ.1 <| adjoin L S).mp <|
adjoin_le_iff.mpr fun s h ↦ ?_), AlgHom.ext hfφ.2⟩
letI := (inclusion hfφ.1).toAlgebra
letI : SMul L φ.carrier := Algebra.toSMul
have : IsScalarTower L φ.carrier E := ⟨(smul_assoc · (· : E))⟩
have := φ.exists_lift_of_splits' (hK s h).1.tower_top ((hK s h).1.minpoly_splits_tower_top' ?_)
· obtain ⟨y, h1, h2⟩ := this; exact (hφ y h1).1 h2
· convert (hK s h).2; ext; apply hfφ.2
variable {L : Type*} [Field L] [Algebra F L] [Algebra L E] [IsScalarTower F L E]
(f : L →ₐ[F] K) (hK : ∀ s ∈ S, IsIntegral L s ∧ (minpoly L s).Splits f.toRingHom)
theorem exists_algHom_adjoin_of_splits' :
∃ φ : adjoin L S →ₐ[F] K, φ.comp (IsScalarTower.toAlgHom F L _) = f := by
let L' := (IsScalarTower.toAlgHom F L E).fieldRange
let f' : L' →ₐ[F] K := f.comp (AlgEquiv.ofInjectiveField _).symm.toAlgHom
have := exists_algHom_adjoin_of_splits'' f' (S := S) fun s hs ↦ ?_
· obtain ⟨φ, hφ⟩ := this; refine ⟨φ.comp <|
inclusion (?_ : (adjoin L S).restrictScalars F ≤ (adjoin L' S).restrictScalars F), ?_⟩
· simp_rw [← SetLike.coe_subset_coe, coe_restrictScalars, adjoin_subset_adjoin_iff]
exact ⟨subset_adjoin_of_subset_left S (F := L'.toSubfield) le_rfl, subset_adjoin _ _⟩
· ext x
rw [AlgHom.comp_assoc]
exact congr($hφ _).trans (congr_arg f <| AlgEquiv.symm_apply_apply _ _)
letI : Algebra L L' := (AlgEquiv.ofInjectiveField _).toRingEquiv.toRingHom.toAlgebra
have : IsScalarTower L L' E := IsScalarTower.of_algebraMap_eq' rfl
refine ⟨(hK s hs).1.tower_top, (hK s hs).1.minpoly_splits_tower_top' ?_⟩
convert (hK s hs).2; ext; exact congr_arg f (AlgEquiv.symm_apply_apply _ _)
theorem exists_algHom_of_adjoin_splits' (hS : adjoin L S = ⊤) :
∃ φ : E →ₐ[F] K, φ.comp (IsScalarTower.toAlgHom F L E) = f :=
have ⟨φ, hφ⟩ := exists_algHom_adjoin_of_splits' f hK
⟨φ.comp (((equivOfEq hS).trans topEquiv).symm.toAlgHom.restrictScalars F), hφ⟩
theorem exists_algHom_of_splits' (hK : ∀ s : E, IsIntegral L s ∧ (minpoly L s).Splits f.toRingHom) :
∃ φ : E →ₐ[F] K, φ.comp (IsScalarTower.toAlgHom F L E) = f :=
exists_algHom_of_adjoin_splits' f (fun x _ ↦ hK x) (adjoin_univ L E)
end
variable (hK : ∀ s ∈ S, IsIntegral F s ∧ (minpoly F s).Splits (algebraMap F K))
(hK' : ∀ s : E, IsIntegral F s ∧ (minpoly F s).Splits (algebraMap F K))
{L : IntermediateField F E} (f : L →ₐ[F] K) (hL : L ≤ adjoin F S)
-- The following uses the hypothesis `hK`.
theorem exists_algHom_adjoin_of_splits : ∃ φ : adjoin F S →ₐ[F] K, φ.comp (inclusion hL) = f := by
obtain ⟨φ, hfφ, hφ⟩ := zorn_nonempty_Ici₀ _
(fun c _ hc _ _ ↦ Lifts.exists_upper_bound c hc) ⟨L, f⟩ le_rfl
refine ⟨φ.emb.comp (inclusion <| adjoin_le_iff.mpr fun s hs ↦ ?_), ?_⟩
· rcases φ.exists_lift_of_splits (hK s hs).1 (hK s hs).2 with ⟨y, h1, h2⟩
exact (hφ y h1).1 h2
· ext; apply hfφ.2
theorem nonempty_algHom_adjoin_of_splits : Nonempty (adjoin F S →ₐ[F] K) :=
have ⟨φ, _⟩ := exists_algHom_adjoin_of_splits hK (⊥ : Lifts F E K).emb bot_le; ⟨φ⟩
variable (hS : adjoin F S = ⊤)
theorem exists_algHom_of_adjoin_splits : ∃ φ : E →ₐ[F] K, φ.comp L.val = f :=
have ⟨φ, hφ⟩ := exists_algHom_adjoin_of_splits hK f (hS.symm ▸ le_top)
⟨φ.comp ((equivOfEq hS).trans topEquiv).symm.toAlgHom, hφ⟩
theorem nonempty_algHom_of_adjoin_splits : Nonempty (E →ₐ[F] K) :=
have ⟨φ, _⟩ := exists_algHom_of_adjoin_splits hK (⊥ : Lifts F E K).emb hS; ⟨φ⟩
variable {x : E} (hx : x ∈ adjoin F S) {y : K} (hy : aeval y (minpoly F x) = 0)
theorem exists_algHom_adjoin_of_splits_of_aeval : ∃ φ : adjoin F S →ₐ[F] K, φ ⟨x, hx⟩ = y := by
have := isAlgebraic_adjoin (fun s hs ↦ (hK s hs).1)
have ix : IsAlgebraic F _ := Algebra.IsAlgebraic.isAlgebraic (⟨x, hx⟩ : adjoin F S)
rw [isAlgebraic_iff_isIntegral, isIntegral_iff] at ix
obtain ⟨φ, hφ⟩ := exists_algHom_adjoin_of_splits hK ((algHomAdjoinIntegralEquiv F ix).symm
⟨y, mem_aroots.mpr ⟨minpoly.ne_zero ix, hy⟩⟩) (adjoin_simple_le_iff.mpr hx)
exact ⟨φ, (DFunLike.congr_fun hφ <| AdjoinSimple.gen F x).trans <|
algHomAdjoinIntegralEquiv_symm_apply_gen F ix _⟩
theorem exists_algHom_of_adjoin_splits_of_aeval : ∃ φ : E →ₐ[F] K, φ x = y :=
have ⟨φ, hφ⟩ := exists_algHom_adjoin_of_splits_of_aeval hK (hS ▸ mem_top) hy
⟨φ.comp ((equivOfEq hS).trans topEquiv).symm.toAlgHom, hφ⟩
/- The following uses the hypothesis
(hK' : ∀ s : E, IsIntegral F s ∧ (minpoly F s).Splits (algebraMap F K)) -/
theorem exists_algHom_of_splits : ∃ φ : E →ₐ[F] K, φ.comp L.val = f :=
exists_algHom_of_adjoin_splits (fun x _ ↦ hK' x) f (adjoin_univ F E)
theorem nonempty_algHom_of_splits : Nonempty (E →ₐ[F] K) :=
nonempty_algHom_of_adjoin_splits (fun x _ ↦ hK' x) (adjoin_univ F E)
theorem exists_algHom_of_splits_of_aeval : ∃ φ : E →ₐ[F] K, φ x = y :=
exists_algHom_of_adjoin_splits_of_aeval (fun x _ ↦ hK' x) (adjoin_univ F E) hy
end IntermediateField
section Algebra.IsAlgebraic
/-- Let `K/F` be an algebraic extension of fields and `L` a field in which all the minimal
polynomial over `F` of elements of `K` splits. Then, for `x ∈ K`, the images of `x` by the
`F`-algebra morphisms from `K` to `L` are exactly the roots in `L` of the minimal polynomial
of `x` over `F`. -/
theorem Algebra.IsAlgebraic.range_eval_eq_rootSet_minpoly_of_splits {F K : Type*} (L : Type*)
[Field F] [Field K] [Field L] [Algebra F L] [Algebra F K]
(hA : ∀ x : K, (minpoly F x).Splits (algebraMap F L))
[Algebra.IsAlgebraic F K] (x : K) :
(Set.range fun (ψ : K →ₐ[F] L) => ψ x) = (minpoly F x).rootSet L := by
ext a
rw [mem_rootSet_of_ne (minpoly.ne_zero (Algebra.IsIntegral.isIntegral x))]
refine ⟨fun ⟨ψ, hψ⟩ ↦ ?_, fun ha ↦ IntermediateField.exists_algHom_of_splits_of_aeval
(fun x ↦ ⟨Algebra.IsIntegral.isIntegral x, hA x⟩) ha⟩
rw [← hψ, Polynomial.aeval_algHom_apply ψ x, minpoly.aeval, map_zero]
end Algebra.IsAlgebraic
|
FieldTheory\Finiteness.lean | /-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.LinearAlgebra.Basis.VectorSpace
import Mathlib.LinearAlgebra.Dimension.Constructions
import Mathlib.LinearAlgebra.Dimension.Finite
/-!
# A module over a division ring is noetherian if and only if it is finite.
-/
universe u v
open Cardinal Submodule Module Function
namespace IsNoetherian
variable {K : Type u} {V : Type v} [DivisionRing K] [AddCommGroup V] [Module K V]
/-- A module over a division ring is noetherian if and only if
its dimension (as a cardinal) is strictly less than the first infinite cardinal `ℵ₀`.
-/
theorem iff_rank_lt_aleph0 : IsNoetherian K V ↔ Module.rank K V < ℵ₀ := by
let b := Basis.ofVectorSpace K V
rw [← b.mk_eq_rank'', lt_aleph0_iff_set_finite]
constructor
· intro
exact (Basis.ofVectorSpaceIndex.linearIndependent K V).set_finite_of_isNoetherian
· intro hbfinite
refine
@isNoetherian_of_linearEquiv K (⊤ : Submodule K V) V _ _ _ _ _ (LinearEquiv.ofTop _ rfl)
(id ?_)
refine isNoetherian_of_fg_of_noetherian _ ⟨Set.Finite.toFinset hbfinite, ?_⟩
rw [Set.Finite.coe_toFinset, ← b.span_eq, Basis.coe_ofVectorSpace, Subtype.range_coe]
/-- In a noetherian module over a division ring, all bases are indexed by a finite type. -/
noncomputable def fintypeBasisIndex {ι : Type*} [IsNoetherian K V] (b : Basis ι K V) : Fintype ι :=
b.fintypeIndexOfRankLtAleph0 (rank_lt_aleph0 K V)
/-- In a noetherian module over a division ring,
`Basis.ofVectorSpace` is indexed by a finite type. -/
noncomputable instance [IsNoetherian K V] : Fintype (Basis.ofVectorSpaceIndex K V) :=
fintypeBasisIndex (Basis.ofVectorSpace K V)
/-- In a noetherian module over a division ring,
if a basis is indexed by a set, that set is finite. -/
theorem finite_basis_index {ι : Type*} {s : Set ι} [IsNoetherian K V] (b : Basis s K V) :
s.Finite :=
b.finite_index_of_rank_lt_aleph0 (rank_lt_aleph0 K V)
variable (K V)
/-- In a noetherian module over a division ring,
there exists a finite basis. This is the indexing `Finset`. -/
noncomputable def finsetBasisIndex [IsNoetherian K V] : Finset V :=
(finite_basis_index (Basis.ofVectorSpace K V)).toFinset
@[simp]
theorem coe_finsetBasisIndex [IsNoetherian K V] :
(↑(finsetBasisIndex K V) : Set V) = Basis.ofVectorSpaceIndex K V :=
Set.Finite.coe_toFinset _
@[simp]
theorem coeSort_finsetBasisIndex [IsNoetherian K V] :
(finsetBasisIndex K V : Type _) = Basis.ofVectorSpaceIndex K V :=
Set.Finite.coeSort_toFinset _
/-- In a noetherian module over a division ring, there exists a finite basis.
This is indexed by the `Finset` `IsNoetherian.finsetBasisIndex`.
This is in contrast to the result `finite_basis_index (Basis.ofVectorSpace K V)`,
which provides a set and a `Set.finite`.
-/
noncomputable def finsetBasis [IsNoetherian K V] : Basis (finsetBasisIndex K V) K V :=
(Basis.ofVectorSpace K V).reindex (by rw [coeSort_finsetBasisIndex])
@[simp]
theorem range_finsetBasis [IsNoetherian K V] :
Set.range (finsetBasis K V) = Basis.ofVectorSpaceIndex K V := by
rw [finsetBasis, Basis.range_reindex, Basis.range_ofVectorSpace]
variable {K V}
/-- A module over a division ring is noetherian if and only if it is finitely generated. -/
theorem iff_fg : IsNoetherian K V ↔ Module.Finite K V := by
constructor
· intro h
exact
⟨⟨finsetBasisIndex K V, by
convert (finsetBasis K V).span_eq
simp⟩⟩
· rintro ⟨s, hs⟩
rw [IsNoetherian.iff_rank_lt_aleph0, ← rank_top, ← hs]
exact lt_of_le_of_lt (rank_span_le _) s.finite_toSet.lt_aleph0
end IsNoetherian
|
FieldTheory\Fixed.lean | /-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.Polynomial.GroupRingAction
import Mathlib.Algebra.Ring.Action.Field
import Mathlib.Algebra.Ring.Action.Invariant
import Mathlib.FieldTheory.Normal
import Mathlib.FieldTheory.Separable
import Mathlib.FieldTheory.Tower
/-!
# Fixed field under a group action.
This is the basis of the Fundamental Theorem of Galois Theory.
Given a (finite) group `G` that acts on a field `F`, we define `FixedPoints.subfield G F`,
the subfield consisting of elements of `F` fixed_points by every element of `G`.
This subfield is then normal and separable, and in addition (TODO) if `G` acts faithfully on `F`
then `finrank (FixedPoints.subfield G F) F = Fintype.card G`.
## Main Definitions
- `FixedPoints.subfield G F`, the subfield consisting of elements of `F` fixed_points by every
element of `G`, where `G` is a group that acts on `F`.
-/
noncomputable section
open MulAction Finset FiniteDimensional
universe u v w
variable {M : Type u} [Monoid M]
variable (G : Type u) [Group G]
variable (F : Type v) [Field F] [MulSemiringAction M F] [MulSemiringAction G F] (m : M)
/-- The subfield of F fixed by the field endomorphism `m`. -/
def FixedBy.subfield : Subfield F where
carrier := fixedBy F m
zero_mem' := smul_zero m
add_mem' hx hy := (smul_add m _ _).trans <| congr_arg₂ _ hx hy
neg_mem' hx := (smul_neg m _).trans <| congr_arg _ hx
one_mem' := smul_one m
mul_mem' hx hy := (smul_mul' m _ _).trans <| congr_arg₂ _ hx hy
inv_mem' x hx := (smul_inv'' m x).trans <| congr_arg _ hx
section InvariantSubfields
variable (M) {F}
/-- A typeclass for subrings invariant under a `MulSemiringAction`. -/
class IsInvariantSubfield (S : Subfield F) : Prop where
smul_mem : ∀ (m : M) {x : F}, x ∈ S → m • x ∈ S
variable (S : Subfield F)
instance IsInvariantSubfield.toMulSemiringAction [IsInvariantSubfield M S] :
MulSemiringAction M S where
smul m x := ⟨m • x.1, IsInvariantSubfield.smul_mem m x.2⟩
one_smul s := Subtype.eq <| one_smul M s.1
mul_smul m₁ m₂ s := Subtype.eq <| mul_smul m₁ m₂ s.1
smul_add m s₁ s₂ := Subtype.eq <| smul_add m s₁.1 s₂.1
smul_zero m := Subtype.eq <| smul_zero m
smul_one m := Subtype.eq <| smul_one m
smul_mul m s₁ s₂ := Subtype.eq <| smul_mul' m s₁.1 s₂.1
instance [IsInvariantSubfield M S] : IsInvariantSubring M S.toSubring where
smul_mem := IsInvariantSubfield.smul_mem
end InvariantSubfields
namespace FixedPoints
variable (M)
-- we use `Subfield.copy` so that the underlying set is `fixedPoints M F`
/-- The subfield of fixed points by a monoid action. -/
def subfield : Subfield F :=
Subfield.copy (⨅ m : M, FixedBy.subfield F m) (fixedPoints M F)
(by ext z; simp [fixedPoints, FixedBy.subfield, iInf, Subfield.mem_sInf]; rfl)
instance : IsInvariantSubfield M (FixedPoints.subfield M F) where
smul_mem g x hx g' := by rw [hx, hx]
instance : SMulCommClass M (FixedPoints.subfield M F) F where
smul_comm m f f' := show m • (↑f * f') = f * m • f' by rw [smul_mul', f.prop m]
instance smulCommClass' : SMulCommClass (FixedPoints.subfield M F) M F :=
SMulCommClass.symm _ _ _
@[simp]
theorem smul (m : M) (x : FixedPoints.subfield M F) : m • x = x :=
Subtype.eq <| x.2 m
-- Why is this so slow?
@[simp]
theorem smul_polynomial (m : M) (p : Polynomial (FixedPoints.subfield M F)) : m • p = p :=
Polynomial.induction_on p (fun x => by rw [Polynomial.smul_C, smul])
(fun p q ihp ihq => by rw [smul_add, ihp, ihq]) fun n x _ => by
rw [smul_mul', Polynomial.smul_C, smul, smul_pow', Polynomial.smul_X]
instance : Algebra (FixedPoints.subfield M F) F := by infer_instance
theorem coe_algebraMap :
algebraMap (FixedPoints.subfield M F) F = Subfield.subtype (FixedPoints.subfield M F) :=
rfl
theorem linearIndependent_smul_of_linearIndependent {s : Finset F} :
(LinearIndependent (FixedPoints.subfield G F) fun i : (s : Set F) => (i : F)) →
LinearIndependent F fun i : (s : Set F) => MulAction.toFun G F i := by
classical
have : IsEmpty ((∅ : Finset F) : Set F) := by simp
refine Finset.induction_on s (fun _ => linearIndependent_empty_type) fun a s has ih hs => ?_
rw [coe_insert] at hs ⊢
rw [linearIndependent_insert (mt mem_coe.1 has)] at hs
rw [linearIndependent_insert' (mt mem_coe.1 has)]; refine ⟨ih hs.1, fun ha => ?_⟩
rw [Finsupp.mem_span_image_iff_total] at ha; rcases ha with ⟨l, hl, hla⟩
rw [Finsupp.total_apply_of_mem_supported F hl] at hla
suffices ∀ i ∈ s, l i ∈ FixedPoints.subfield G F by
replace hla := (sum_apply _ _ fun i => l i • toFun G F i).symm.trans (congr_fun hla 1)
simp_rw [Pi.smul_apply, toFun_apply, one_smul] at hla
refine hs.2 (hla ▸ Submodule.sum_mem _ fun c hcs => ?_)
change (⟨l c, this c hcs⟩ : FixedPoints.subfield G F) • c ∈ _
exact Submodule.smul_mem _ _ (Submodule.subset_span <| mem_coe.2 hcs)
intro i his g
refine
eq_of_sub_eq_zero
(linearIndependent_iff'.1 (ih hs.1) s.attach (fun i => g • l i - l i) ?_ ⟨i, his⟩
(mem_attach _ _) :
_)
refine (sum_attach s fun i ↦ (g • l i - l i) • MulAction.toFun G F i).trans ?_
ext g'; dsimp only
conv_lhs =>
rw [sum_apply]
congr
· skip
· ext
rw [Pi.smul_apply, sub_smul, smul_eq_mul]
rw [sum_sub_distrib, Pi.zero_apply, sub_eq_zero]
conv_lhs =>
congr
· skip
· ext x
rw [toFun_apply, ← mul_inv_cancel_left g g', mul_smul, ← smul_mul', ← toFun_apply _ x]
show
(∑ x ∈ s, g • (fun y => l y • MulAction.toFun G F y) x (g⁻¹ * g')) =
∑ x ∈ s, (fun y => l y • MulAction.toFun G F y) x g'
rw [← smul_sum, ← sum_apply _ _ fun y => l y • toFun G F y, ←
sum_apply _ _ fun y => l y • toFun G F y]
rw [hla, toFun_apply, toFun_apply, smul_smul, mul_inv_cancel_left]
section Fintype
variable [Fintype G] (x : F)
/-- `minpoly G F x` is the minimal polynomial of `(x : F)` over `FixedPoints.subfield G F`. -/
def minpoly : Polynomial (FixedPoints.subfield G F) :=
(prodXSubSMul G F x).toSubring (FixedPoints.subfield G F).toSubring fun _ hc g =>
let ⟨n, _, hn⟩ := Polynomial.mem_coeffs_iff.1 hc
hn.symm ▸ prodXSubSMul.coeff G F x g n
namespace minpoly
theorem monic : (minpoly G F x).Monic := by
simp only [minpoly, Polynomial.monic_toSubring]
exact prodXSubSMul.monic G F x
theorem eval₂ :
Polynomial.eval₂ (Subring.subtype <| (FixedPoints.subfield G F).toSubring) x (minpoly G F x) =
0 := by
rw [← prodXSubSMul.eval G F x, Polynomial.eval₂_eq_eval_map]
simp only [minpoly, Polynomial.map_toSubring]
theorem eval₂' :
Polynomial.eval₂ (Subfield.subtype <| FixedPoints.subfield G F) x (minpoly G F x) = 0 :=
eval₂ G F x
theorem ne_one : minpoly G F x ≠ (1 : Polynomial (FixedPoints.subfield G F)) := fun H =>
have := eval₂ G F x
(one_ne_zero : (1 : F) ≠ 0) <| by rwa [H, Polynomial.eval₂_one] at this
theorem of_eval₂ (f : Polynomial (FixedPoints.subfield G F))
(hf : Polynomial.eval₂ (Subfield.subtype <| FixedPoints.subfield G F) x f = 0) :
minpoly G F x ∣ f := by
classical
-- Porting note: the two `have` below were not needed.
have : (subfield G F).subtype = (subfield G F).toSubring.subtype := rfl
have h : Polynomial.map (MulSemiringActionHom.toRingHom (IsInvariantSubring.subtypeHom G
(subfield G F).toSubring)) f = Polynomial.map
((IsInvariantSubring.subtypeHom G (subfield G F).toSubring)) f := rfl
erw [← Polynomial.map_dvd_map' (Subfield.subtype <| FixedPoints.subfield G F), minpoly, this,
Polynomial.map_toSubring _ _, prodXSubSMul]
refine
Fintype.prod_dvd_of_coprime
(Polynomial.pairwise_coprime_X_sub_C <| MulAction.injective_ofQuotientStabilizer G x) fun y =>
QuotientGroup.induction_on y fun g => ?_
rw [Polynomial.dvd_iff_isRoot, Polynomial.IsRoot.def, MulAction.ofQuotientStabilizer_mk,
Polynomial.eval_smul', ← this, ← Subfield.toSubring_subtype_eq_subtype, ←
IsInvariantSubring.coe_subtypeHom' G (FixedPoints.subfield G F).toSubring, h,
← MulSemiringActionHom.coe_polynomial, ← MulSemiringActionHom.map_smul, smul_polynomial,
MulSemiringActionHom.coe_polynomial, ← h, IsInvariantSubring.coe_subtypeHom',
Polynomial.eval_map, Subfield.toSubring_subtype_eq_subtype, hf, smul_zero]
-- Why is this so slow?
theorem irreducible_aux (f g : Polynomial (FixedPoints.subfield G F)) (hf : f.Monic) (hg : g.Monic)
(hfg : f * g = minpoly G F x) : f = 1 ∨ g = 1 := by
have hf2 : f ∣ minpoly G F x := by rw [← hfg]; exact dvd_mul_right _ _
have hg2 : g ∣ minpoly G F x := by rw [← hfg]; exact dvd_mul_left _ _
have := eval₂ G F x
rw [← hfg, Polynomial.eval₂_mul, mul_eq_zero] at this
cases' this with this this
· right
have hf3 : f = minpoly G F x :=
Polynomial.eq_of_monic_of_associated hf (monic G F x)
(associated_of_dvd_dvd hf2 <| @of_eval₂ G _ F _ _ _ x f this)
rwa [← mul_one (minpoly G F x), hf3, mul_right_inj' (monic G F x).ne_zero] at hfg
· left
have hg3 : g = minpoly G F x :=
Polynomial.eq_of_monic_of_associated hg (monic G F x)
(associated_of_dvd_dvd hg2 <| @of_eval₂ G _ F _ _ _ x g this)
rwa [← one_mul (minpoly G F x), hg3, mul_left_inj' (monic G F x).ne_zero] at hfg
theorem irreducible : Irreducible (minpoly G F x) :=
(Polynomial.irreducible_of_monic (monic G F x) (ne_one G F x)).2 (irreducible_aux G F x)
end minpoly
end Fintype
theorem isIntegral [Finite G] (x : F) : IsIntegral (FixedPoints.subfield G F) x := by
cases nonempty_fintype G; exact ⟨minpoly G F x, minpoly.monic G F x, minpoly.eval₂ G F x⟩
section Fintype
variable [Fintype G] (x : F)
theorem minpoly_eq_minpoly : minpoly G F x = _root_.minpoly (FixedPoints.subfield G F) x :=
minpoly.eq_of_irreducible_of_monic (minpoly.irreducible G F x) (minpoly.eval₂ G F x)
(minpoly.monic G F x)
theorem rank_le_card : Module.rank (FixedPoints.subfield G F) F ≤ Fintype.card G :=
rank_le fun s hs => by
simpa only [rank_fun', Cardinal.mk_coe_finset, Finset.coe_sort_coe, Cardinal.lift_natCast,
Cardinal.natCast_le] using
(linearIndependent_smul_of_linearIndependent G F hs).cardinal_lift_le_rank
end Fintype
section Finite
variable [Finite G]
instance normal : Normal (FixedPoints.subfield G F) F where
isAlgebraic x := (isIntegral G F x).isAlgebraic
splits' x :=
(Polynomial.splits_id_iff_splits _).1 <| by
cases nonempty_fintype G
rw [← minpoly_eq_minpoly, minpoly, coe_algebraMap, ← Subfield.toSubring_subtype_eq_subtype,
Polynomial.map_toSubring _ (subfield G F).toSubring, prodXSubSMul]
exact Polynomial.splits_prod _ fun _ _ => Polynomial.splits_X_sub_C _
instance isSeparable : Algebra.IsSeparable (FixedPoints.subfield G F) F := by
classical
exact ⟨fun x => by
cases nonempty_fintype G
-- this was a plain rw when we were using unbundled subrings
erw [IsSeparable, ← minpoly_eq_minpoly,
← Polynomial.separable_map (FixedPoints.subfield G F).subtype, minpoly,
Polynomial.map_toSubring _ (subfield G F).toSubring]
exact Polynomial.separable_prod_X_sub_C_iff.2 (injective_ofQuotientStabilizer G x)⟩
instance : FiniteDimensional (subfield G F) F := by
cases nonempty_fintype G
exact IsNoetherian.iff_fg.1
(IsNoetherian.iff_rank_lt_aleph0.2 <| (rank_le_card G F).trans_lt <| Cardinal.nat_lt_aleph0 _)
end Finite
theorem finrank_le_card [Fintype G] : finrank (subfield G F) F ≤ Fintype.card G := by
rw [← Cardinal.natCast_le, finrank_eq_rank]
apply rank_le_card
end FixedPoints
theorem linearIndependent_toLinearMap (R : Type u) (A : Type v) (B : Type w) [CommSemiring R]
[Ring A] [Algebra R A] [CommRing B] [IsDomain B] [Algebra R B] :
LinearIndependent B (AlgHom.toLinearMap : (A →ₐ[R] B) → A →ₗ[R] B) :=
have : LinearIndependent B (LinearMap.ltoFun R A B ∘ AlgHom.toLinearMap) :=
((linearIndependent_monoidHom A B).comp ((↑) : (A →ₐ[R] B) → A →* B) fun _ _ hfg =>
AlgHom.ext fun _ => DFunLike.ext_iff.1 hfg _ :
_)
this.of_comp _
theorem cardinal_mk_algHom (K : Type u) (V : Type v) (W : Type w) [Field K] [Field V] [Algebra K V]
[FiniteDimensional K V] [Field W] [Algebra K W] :
Cardinal.mk (V →ₐ[K] W) ≤ finrank W (V →ₗ[K] W) :=
(linearIndependent_toLinearMap K V W).cardinal_mk_le_finrank
noncomputable instance AlgEquiv.fintype (K : Type u) (V : Type v) [Field K] [Field V] [Algebra K V]
[FiniteDimensional K V] : Fintype (V ≃ₐ[K] V) :=
Fintype.ofEquiv (V →ₐ[K] V) (algEquivEquivAlgHom K V).symm
theorem finrank_algHom (K : Type u) (V : Type v) [Field K] [Field V] [Algebra K V]
[FiniteDimensional K V] : Fintype.card (V →ₐ[K] V) ≤ finrank V (V →ₗ[K] V) :=
(linearIndependent_toLinearMap K V V).fintype_card_le_finrank
namespace FixedPoints
theorem finrank_eq_card (G : Type u) (F : Type v) [Group G] [Field F] [Fintype G]
[MulSemiringAction G F] [FaithfulSMul G F] :
finrank (FixedPoints.subfield G F) F = Fintype.card G :=
le_antisymm (FixedPoints.finrank_le_card G F) <|
calc
Fintype.card G ≤ Fintype.card (F →ₐ[FixedPoints.subfield G F] F) :=
Fintype.card_le_of_injective _ (MulSemiringAction.toAlgHom_injective _ F)
_ ≤ finrank F (F →ₗ[FixedPoints.subfield G F] F) := finrank_algHom (subfield G F) F
_ = finrank (FixedPoints.subfield G F) F := finrank_linearMap_self _ _ _
/-- `MulSemiringAction.toAlgHom` is bijective. -/
theorem toAlgHom_bijective (G : Type u) (F : Type v) [Group G] [Field F] [Finite G]
[MulSemiringAction G F] [FaithfulSMul G F] :
Function.Bijective (MulSemiringAction.toAlgHom _ _ : G → F →ₐ[subfield G F] F) := by
cases nonempty_fintype G
rw [Fintype.bijective_iff_injective_and_card]
constructor
· exact MulSemiringAction.toAlgHom_injective _ F
· apply le_antisymm
· exact Fintype.card_le_of_injective _ (MulSemiringAction.toAlgHom_injective _ F)
· rw [← finrank_eq_card G F]
exact LE.le.trans_eq (finrank_algHom _ F) (finrank_linearMap_self _ _ _)
/-- Bijection between G and algebra homomorphisms that fix the fixed points -/
def toAlgHomEquiv (G : Type u) (F : Type v) [Group G] [Field F] [Finite G] [MulSemiringAction G F]
[FaithfulSMul G F] : G ≃ (F →ₐ[FixedPoints.subfield G F] F) :=
Equiv.ofBijective _ (toAlgHom_bijective G F)
end FixedPoints
|
FieldTheory\Galois.lean | /-
Copyright (c) 2020 Thomas Browning, Patrick Lutz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning, Patrick Lutz
-/
import Mathlib.FieldTheory.Fixed
import Mathlib.FieldTheory.NormalClosure
import Mathlib.FieldTheory.PrimitiveElement
import Mathlib.GroupTheory.GroupAction.FixingSubgroup
/-!
# Galois Extensions
In this file we define Galois extensions as extensions which are both separable and normal.
## Main definitions
- `IsGalois F E` where `E` is an extension of `F`
- `fixedField H` where `H : Subgroup (E ≃ₐ[F] E)`
- `fixingSubgroup K` where `K : IntermediateField F E`
- `intermediateFieldEquivSubgroup` where `E/F` is finite dimensional and Galois
## Main results
- `IntermediateField.fixingSubgroup_fixedField` : If `E/F` is finite dimensional (but not
necessarily Galois) then `fixingSubgroup (fixedField H) = H`
- `IntermediateField.fixedField_fixingSubgroup`: If `E/F` is finite dimensional and Galois
then `fixedField (fixingSubgroup K) = K`
Together, these two results prove the Galois correspondence.
- `IsGalois.tfae` : Equivalent characterizations of a Galois extension of finite degree
-/
open scoped Polynomial IntermediateField
open FiniteDimensional AlgEquiv
section
variable (F : Type*) [Field F] (E : Type*) [Field E] [Algebra F E]
/-- A field extension E/F is Galois if it is both separable and normal. Note that in mathlib
a separable extension of fields is by definition algebraic. -/
class IsGalois : Prop where
[to_isSeparable : Algebra.IsSeparable F E]
[to_normal : Normal F E]
variable {F E}
theorem isGalois_iff : IsGalois F E ↔ Algebra.IsSeparable F E ∧ Normal F E :=
⟨fun h => ⟨h.1, h.2⟩, fun h =>
{ to_isSeparable := h.1
to_normal := h.2 }⟩
attribute [instance 100] IsGalois.to_isSeparable IsGalois.to_normal
-- see Note [lower instance priority]
variable (F E)
namespace IsGalois
instance self : IsGalois F F :=
⟨⟩
variable {E}
theorem integral [IsGalois F E] (x : E) : IsIntegral F x :=
to_normal.isIntegral x
theorem separable [IsGalois F E] (x : E) : IsSeparable F x :=
Algebra.IsSeparable.isSeparable F x
theorem splits [IsGalois F E] (x : E) : (minpoly F x).Splits (algebraMap F E) :=
Normal.splits' x
variable (E)
instance of_fixed_field (G : Type*) [Group G] [Finite G] [MulSemiringAction G E] :
IsGalois (FixedPoints.subfield G E) E :=
⟨⟩
theorem IntermediateField.AdjoinSimple.card_aut_eq_finrank [FiniteDimensional F E] {α : E}
(hα : IsIntegral F α) (h_sep : IsSeparable F α)
(h_splits : (minpoly F α).Splits (algebraMap F F⟮α⟯)) :
Fintype.card (F⟮α⟯ ≃ₐ[F] F⟮α⟯) = finrank F F⟮α⟯ := by
letI : Fintype (F⟮α⟯ →ₐ[F] F⟮α⟯) := IntermediateField.fintypeOfAlgHomAdjoinIntegral F hα
rw [IntermediateField.adjoin.finrank hα]
rw [← IntermediateField.card_algHom_adjoin_integral F hα h_sep h_splits]
exact Fintype.card_congr (algEquivEquivAlgHom F F⟮α⟯)
theorem card_aut_eq_finrank [FiniteDimensional F E] [IsGalois F E] :
Fintype.card (E ≃ₐ[F] E) = finrank F E := by
cases' Field.exists_primitive_element F E with α hα
let iso : F⟮α⟯ ≃ₐ[F] E :=
{ toFun := fun e => e.val
invFun := fun e => ⟨e, by rw [hα]; exact IntermediateField.mem_top⟩
left_inv := fun _ => by ext; rfl
right_inv := fun _ => rfl
map_mul' := fun _ _ => rfl
map_add' := fun _ _ => rfl
commutes' := fun _ => rfl }
have H : IsIntegral F α := IsGalois.integral F α
have h_sep : IsSeparable F α := IsGalois.separable F α
have h_splits : (minpoly F α).Splits (algebraMap F E) := IsGalois.splits F α
replace h_splits : Polynomial.Splits (algebraMap F F⟮α⟯) (minpoly F α) := by
simpa using
Polynomial.splits_comp_of_splits (algebraMap F E) iso.symm.toAlgHom.toRingHom h_splits
rw [← LinearEquiv.finrank_eq iso.toLinearEquiv]
rw [← IntermediateField.AdjoinSimple.card_aut_eq_finrank F E H h_sep h_splits]
apply Fintype.card_congr
apply Equiv.mk (fun ϕ => iso.trans (ϕ.trans iso.symm)) fun ϕ => iso.symm.trans (ϕ.trans iso)
· intro ϕ; ext1; simp only [trans_apply, apply_symm_apply]
· intro ϕ; ext1; simp only [trans_apply, symm_apply_apply]
end IsGalois
end
section IsGaloisTower
variable (F K E : Type*) [Field F] [Field K] [Field E] {E' : Type*} [Field E'] [Algebra F E']
variable [Algebra F K] [Algebra F E] [Algebra K E] [IsScalarTower F K E]
theorem IsGalois.tower_top_of_isGalois [IsGalois F E] : IsGalois K E :=
{ to_isSeparable := Algebra.isSeparable_tower_top_of_isSeparable F K E
to_normal := Normal.tower_top_of_normal F K E }
variable {F E}
-- see Note [lower instance priority]
instance (priority := 100) IsGalois.tower_top_intermediateField (K : IntermediateField F E)
[IsGalois F E] : IsGalois K E :=
IsGalois.tower_top_of_isGalois F K E
theorem isGalois_iff_isGalois_bot : IsGalois (⊥ : IntermediateField F E) E ↔ IsGalois F E := by
constructor
· intro h
exact IsGalois.tower_top_of_isGalois (⊥ : IntermediateField F E) F E
· intro h; infer_instance
theorem IsGalois.of_algEquiv [IsGalois F E] (f : E ≃ₐ[F] E') : IsGalois F E' :=
{ to_isSeparable := Algebra.IsSeparable.of_algHom F E f.symm
to_normal := Normal.of_algEquiv f }
theorem AlgEquiv.transfer_galois (f : E ≃ₐ[F] E') : IsGalois F E ↔ IsGalois F E' :=
⟨fun _ => IsGalois.of_algEquiv f, fun _ => IsGalois.of_algEquiv f.symm⟩
theorem isGalois_iff_isGalois_top : IsGalois F (⊤ : IntermediateField F E) ↔ IsGalois F E :=
(IntermediateField.topEquiv : (⊤ : IntermediateField F E) ≃ₐ[F] E).transfer_galois
instance isGalois_bot : IsGalois F (⊥ : IntermediateField F E) :=
(IntermediateField.botEquiv F E).transfer_galois.mpr (IsGalois.self F)
end IsGaloisTower
section GaloisCorrespondence
variable {F : Type*} [Field F] {E : Type*} [Field E] [Algebra F E]
variable (H : Subgroup (E ≃ₐ[F] E)) (K : IntermediateField F E)
/-- The intermediate field of fixed points fixed by a monoid action that commutes with the
`F`-action on `E`. -/
def FixedPoints.intermediateField (M : Type*) [Monoid M] [MulSemiringAction M E]
[SMulCommClass M F E] : IntermediateField F E :=
{ FixedPoints.subfield M E with
carrier := MulAction.fixedPoints M E
algebraMap_mem' := fun a g => smul_algebraMap g a }
namespace IntermediateField
/-- The intermediate field fixed by a subgroup -/
def fixedField : IntermediateField F E :=
FixedPoints.intermediateField H
theorem finrank_fixedField_eq_card [FiniteDimensional F E] [DecidablePred (· ∈ H)] :
finrank (fixedField H) E = Fintype.card H :=
FixedPoints.finrank_eq_card H E
/-- The subgroup fixing an intermediate field -/
nonrec def fixingSubgroup : Subgroup (E ≃ₐ[F] E) :=
fixingSubgroup (E ≃ₐ[F] E) (K : Set E)
theorem le_iff_le : K ≤ fixedField H ↔ H ≤ fixingSubgroup K :=
⟨fun h g hg x => h (Subtype.mem x) ⟨g, hg⟩, fun h x hx g => h (Subtype.mem g) ⟨x, hx⟩⟩
/-- The fixing subgroup of `K : IntermediateField F E` is isomorphic to `E ≃ₐ[K] E` -/
def fixingSubgroupEquiv : fixingSubgroup K ≃* E ≃ₐ[K] E where
toFun ϕ := { AlgEquiv.toRingEquiv (ϕ : E ≃ₐ[F] E) with commutes' := ϕ.mem }
invFun ϕ := ⟨ϕ.restrictScalars _, ϕ.commutes⟩
left_inv _ := by ext; rfl
right_inv _ := by ext; rfl
map_mul' _ _ := by ext; rfl
theorem fixingSubgroup_fixedField [FiniteDimensional F E] : fixingSubgroup (fixedField H) = H := by
have H_le : H ≤ fixingSubgroup (fixedField H) := (le_iff_le _ _).mp le_rfl
classical
suffices Fintype.card H = Fintype.card (fixingSubgroup (fixedField H)) by
exact SetLike.coe_injective (Set.eq_of_inclusion_surjective
((Fintype.bijective_iff_injective_and_card (Set.inclusion H_le)).mpr
⟨Set.inclusion_injective H_le, this⟩).2).symm
apply Fintype.card_congr
refine (FixedPoints.toAlgHomEquiv H E).trans ?_
refine (algEquivEquivAlgHom (fixedField H) E).toEquiv.symm.trans ?_
exact (fixingSubgroupEquiv (fixedField H)).toEquiv.symm
-- Porting note: added `fixedField.smul` for `fixedField.isScalarTower`
instance fixedField.smul : SMul K (fixedField (fixingSubgroup K)) where
smul x y := ⟨x * y, fun ϕ => by
rw [smul_mul', show ϕ • (x : E) = ↑x from ϕ.2 x, show ϕ • (y : E) = ↑y from y.2 ϕ]⟩
instance fixedField.algebra : Algebra K (fixedField (fixingSubgroup K)) where
toFun x := ⟨x, fun ϕ => Subtype.mem ϕ x⟩
map_zero' := rfl
map_add' _ _ := rfl
map_one' := rfl
map_mul' _ _ := rfl
commutes' _ _ := mul_comm _ _
smul_def' _ _ := rfl
instance fixedField.isScalarTower : IsScalarTower K (fixedField (fixingSubgroup K)) E :=
⟨fun _ _ _ => mul_assoc _ _ _⟩
end IntermediateField
namespace IsGalois
theorem fixedField_fixingSubgroup [FiniteDimensional F E] [h : IsGalois F E] :
IntermediateField.fixedField (IntermediateField.fixingSubgroup K) = K := by
have K_le : K ≤ IntermediateField.fixedField (IntermediateField.fixingSubgroup K) :=
(IntermediateField.le_iff_le _ _).mpr le_rfl
suffices
finrank K E = finrank (IntermediateField.fixedField (IntermediateField.fixingSubgroup K)) E by
exact (IntermediateField.eq_of_le_of_finrank_eq' K_le this).symm
classical
rw [IntermediateField.finrank_fixedField_eq_card,
Fintype.card_congr (IntermediateField.fixingSubgroupEquiv K).toEquiv]
exact (card_aut_eq_finrank K E).symm
theorem card_fixingSubgroup_eq_finrank [DecidablePred (· ∈ IntermediateField.fixingSubgroup K)]
[FiniteDimensional F E] [IsGalois F E] :
Fintype.card (IntermediateField.fixingSubgroup K) = finrank K E := by
conv_rhs => rw [← fixedField_fixingSubgroup K, IntermediateField.finrank_fixedField_eq_card]
/-- The Galois correspondence from intermediate fields to subgroups -/
def intermediateFieldEquivSubgroup [FiniteDimensional F E] [IsGalois F E] :
IntermediateField F E ≃o (Subgroup (E ≃ₐ[F] E))ᵒᵈ where
toFun := IntermediateField.fixingSubgroup
invFun := IntermediateField.fixedField
left_inv K := fixedField_fixingSubgroup K
right_inv H := IntermediateField.fixingSubgroup_fixedField H
map_rel_iff' {K L} := by
rw [← fixedField_fixingSubgroup L, IntermediateField.le_iff_le, fixedField_fixingSubgroup L]
rfl
/-- The Galois correspondence as a `GaloisInsertion` -/
def galoisInsertionIntermediateFieldSubgroup [FiniteDimensional F E] :
GaloisInsertion (OrderDual.toDual ∘
(IntermediateField.fixingSubgroup : IntermediateField F E → Subgroup (E ≃ₐ[F] E)))
((IntermediateField.fixedField : Subgroup (E ≃ₐ[F] E) → IntermediateField F E) ∘
OrderDual.toDual) where
choice K _ := IntermediateField.fixingSubgroup K
gc K H := (IntermediateField.le_iff_le H K).symm
le_l_u H := le_of_eq (IntermediateField.fixingSubgroup_fixedField H).symm
choice_eq _ _ := rfl
/-- The Galois correspondence as a `GaloisCoinsertion` -/
def galoisCoinsertionIntermediateFieldSubgroup [FiniteDimensional F E] [IsGalois F E] :
GaloisCoinsertion (OrderDual.toDual ∘
(IntermediateField.fixingSubgroup : IntermediateField F E → Subgroup (E ≃ₐ[F] E)))
((IntermediateField.fixedField : Subgroup (E ≃ₐ[F] E) → IntermediateField F E) ∘
OrderDual.toDual) where
choice H _ := IntermediateField.fixedField H
gc K H := (IntermediateField.le_iff_le H K).symm
u_l_le K := le_of_eq (fixedField_fixingSubgroup K)
choice_eq _ _ := rfl
end IsGalois
end GaloisCorrespondence
section GaloisEquivalentDefinitions
variable (F : Type*) [Field F] (E : Type*) [Field E] [Algebra F E]
namespace IsGalois
theorem is_separable_splitting_field [FiniteDimensional F E] [IsGalois F E] :
∃ p : F[X], p.Separable ∧ p.IsSplittingField F E := by
cases' Field.exists_primitive_element F E with α h1
use minpoly F α, separable F α, IsGalois.splits F α
rw [eq_top_iff, ← IntermediateField.top_toSubalgebra, ← h1]
rw [IntermediateField.adjoin_simple_toSubalgebra_of_integral (integral F α)]
apply Algebra.adjoin_mono
rw [Set.singleton_subset_iff, Polynomial.mem_rootSet]
exact ⟨minpoly.ne_zero (integral F α), minpoly.aeval _ _⟩
theorem of_fixedField_eq_bot [FiniteDimensional F E]
(h : IntermediateField.fixedField (⊤ : Subgroup (E ≃ₐ[F] E)) = ⊥) : IsGalois F E := by
rw [← isGalois_iff_isGalois_bot, ← h]
classical exact IsGalois.of_fixed_field E (⊤ : Subgroup (E ≃ₐ[F] E))
theorem of_card_aut_eq_finrank [FiniteDimensional F E]
(h : Fintype.card (E ≃ₐ[F] E) = finrank F E) : IsGalois F E := by
apply of_fixedField_eq_bot
have p : 0 < finrank (IntermediateField.fixedField (⊤ : Subgroup (E ≃ₐ[F] E))) E := finrank_pos
classical
rw [← IntermediateField.finrank_eq_one_iff, ← mul_left_inj' (ne_of_lt p).symm,
finrank_mul_finrank, ← h, one_mul, IntermediateField.finrank_fixedField_eq_card]
apply Fintype.card_congr
exact
{ toFun := fun g => ⟨g, Subgroup.mem_top g⟩
invFun := (↑)
left_inv := fun g => rfl
right_inv := fun _ => by ext; rfl }
variable {F} {E}
variable {p : F[X]}
theorem of_separable_splitting_field_aux [hFE : FiniteDimensional F E] [sp : p.IsSplittingField F E]
(hp : p.Separable) (K : Type*) [Field K] [Algebra F K] [Algebra K E] [IsScalarTower F K E]
{x : E} (hx : x ∈ p.aroots E)
-- these are both implied by `hFE`, but as they carry data this makes the lemma more general
[Fintype (K →ₐ[F] E)]
[Fintype (K⟮x⟯.restrictScalars F →ₐ[F] E)] :
Fintype.card (K⟮x⟯.restrictScalars F →ₐ[F] E) = Fintype.card (K →ₐ[F] E) * finrank K K⟮x⟯ := by
have h : IsIntegral K x := (isIntegral_of_noetherian (IsNoetherian.iff_fg.2 hFE) x).tower_top
have h1 : p ≠ 0 := fun hp => by
rw [hp, Polynomial.aroots_zero] at hx
exact Multiset.not_mem_zero x hx
have h2 : minpoly K x ∣ p.map (algebraMap F K) := by
apply minpoly.dvd
rw [Polynomial.aeval_def, Polynomial.eval₂_map, ← Polynomial.eval_map, ←
IsScalarTower.algebraMap_eq]
exact (Polynomial.mem_roots (Polynomial.map_ne_zero h1)).mp hx
let key_equiv : (K⟮x⟯.restrictScalars F →ₐ[F] E) ≃
Σ f : K →ₐ[F] E, @AlgHom K K⟮x⟯ E _ _ _ _ (RingHom.toAlgebra f) := by
change (K⟮x⟯ →ₐ[F] E) ≃ Σ f : K →ₐ[F] E, _
exact algHomEquivSigma
haveI : ∀ f : K →ₐ[F] E, Fintype (@AlgHom K K⟮x⟯ E _ _ _ _ (RingHom.toAlgebra f)) := fun f => by
have := Fintype.ofEquiv _ key_equiv
apply Fintype.ofInjective (Sigma.mk f) fun _ _ H => eq_of_heq (Sigma.ext_iff.mp H).2
rw [Fintype.card_congr key_equiv, Fintype.card_sigma, IntermediateField.adjoin.finrank h]
apply Finset.sum_const_nat
intro f _
rw [← @IntermediateField.card_algHom_adjoin_integral K _ E _ _ x E _ (RingHom.toAlgebra f) h]
· congr!
· exact Polynomial.Separable.of_dvd ((Polynomial.separable_map (algebraMap F K)).mpr hp) h2
· refine Polynomial.splits_of_splits_of_dvd _ (Polynomial.map_ne_zero h1) ?_ h2
-- Porting note: use unification instead of synthesis for one argument of `algebraMap_eq`
rw [Polynomial.splits_map_iff, ← @IsScalarTower.algebraMap_eq _ _ _ _ _ _ _ (_) _ _]
exact sp.splits
theorem of_separable_splitting_field [sp : p.IsSplittingField F E] (hp : p.Separable) :
IsGalois F E := by
haveI hFE : FiniteDimensional F E := Polynomial.IsSplittingField.finiteDimensional E p
letI := Classical.decEq E
let s := p.rootSet E
have adjoin_root : IntermediateField.adjoin F s = ⊤ := by
apply IntermediateField.toSubalgebra_injective
rw [IntermediateField.top_toSubalgebra, ← top_le_iff, ← sp.adjoin_rootSet]
apply IntermediateField.algebra_adjoin_le_adjoin
let P : IntermediateField F E → Prop := fun K => Fintype.card (K →ₐ[F] E) = finrank F K
suffices P (IntermediateField.adjoin F s) by
rw [adjoin_root] at this
apply of_card_aut_eq_finrank
rw [← Eq.trans this (LinearEquiv.finrank_eq IntermediateField.topEquiv.toLinearEquiv)]
exact Fintype.card_congr ((algEquivEquivAlgHom F E).toEquiv.trans
(IntermediateField.topEquiv.symm.arrowCongr AlgEquiv.refl))
apply IntermediateField.induction_on_adjoin_finset _ P
· have key := IntermediateField.card_algHom_adjoin_integral F (K := E)
(show IsIntegral F (0 : E) from isIntegral_zero)
rw [IsSeparable, minpoly.zero, Polynomial.natDegree_X] at key
specialize key Polynomial.separable_X (Polynomial.splits_X (algebraMap F E))
rw [← @Subalgebra.finrank_bot F E _ _ _, ← IntermediateField.bot_toSubalgebra] at key
refine Eq.trans ?_ key
-- Porting note: use unification instead of synthesis for one argument of `card_congr`
apply @Fintype.card_congr _ _ _ (_) _
rw [IntermediateField.adjoin_zero]
intro K x hx hK
simp only [P] at *
-- Porting note: need to specify two implicit arguments of `finrank_mul_finrank`
letI := K⟮x⟯.module
letI := K⟮x⟯.isScalarTower (R := F)
rw [of_separable_splitting_field_aux hp K (Multiset.mem_toFinset.mp hx), hK, finrank_mul_finrank]
symm
refine LinearEquiv.finrank_eq ?_
rfl
/-- Equivalent characterizations of a Galois extension of finite degree-/
theorem tfae [FiniteDimensional F E] : List.TFAE [
IsGalois F E,
IntermediateField.fixedField (⊤ : Subgroup (E ≃ₐ[F] E)) = ⊥,
Fintype.card (E ≃ₐ[F] E) = finrank F E,
∃ p : F[X], p.Separable ∧ p.IsSplittingField F E] := by
tfae_have 1 → 2
· exact fun h => OrderIso.map_bot (@intermediateFieldEquivSubgroup F _ E _ _ _ h).symm
tfae_have 1 → 3
· intro; exact card_aut_eq_finrank F E
tfae_have 1 → 4
· intro; exact is_separable_splitting_field F E
tfae_have 2 → 1
· exact of_fixedField_eq_bot F E
tfae_have 3 → 1
· exact of_card_aut_eq_finrank F E
tfae_have 4 → 1
· rintro ⟨h, hp1, _⟩; exact of_separable_splitting_field hp1
tfae_finish
end IsGalois
end GaloisEquivalentDefinitions
section normalClosure
variable (k K F : Type*) [Field k] [Field K] [Field F] [Algebra k K] [Algebra k F] [Algebra K F]
[IsScalarTower k K F] [IsGalois k F]
instance IsGalois.normalClosure : IsGalois k (normalClosure k K F) where
to_isSeparable := Algebra.isSeparable_tower_bot_of_isSeparable k _ F
end normalClosure
section IsAlgClosure
instance (priority := 100) IsAlgClosure.isGalois (k K : Type*) [Field k] [Field K] [Algebra k K]
[IsAlgClosure k K] [CharZero k] : IsGalois k K where
end IsAlgClosure
|
FieldTheory\IntermediateField.lean | /-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.FieldTheory.Tower
import Mathlib.RingTheory.Algebraic
import Mathlib.FieldTheory.Minpoly.Basic
/-!
# Intermediate fields
Let `L / K` be a field extension, given as an instance `Algebra K L`.
This file defines the type of fields in between `K` and `L`, `IntermediateField K L`.
An `IntermediateField K L` is a subfield of `L` which contains (the image of) `K`,
i.e. it is a `Subfield L` and a `Subalgebra K L`.
## Main definitions
* `IntermediateField K L` : the type of intermediate fields between `K` and `L`.
* `Subalgebra.to_intermediateField`: turns a subalgebra closed under `⁻¹`
into an intermediate field
* `Subfield.to_intermediateField`: turns a subfield containing the image of `K`
into an intermediate field
* `IntermediateField.map`: map an intermediate field along an `AlgHom`
* `IntermediateField.restrict_scalars`: restrict the scalars of an intermediate field to a smaller
field in a tower of fields.
## Implementation notes
Intermediate fields are defined with a structure extending `Subfield` and `Subalgebra`.
A `Subalgebra` is closed under all operations except `⁻¹`,
## Tags
intermediate field, field extension
-/
open FiniteDimensional Polynomial
open Polynomial
variable (K L L' : Type*) [Field K] [Field L] [Field L'] [Algebra K L] [Algebra K L']
/-- `S : IntermediateField K L` is a subset of `L` such that there is a field
tower `L / S / K`. -/
structure IntermediateField extends Subalgebra K L where
inv_mem' : ∀ x ∈ carrier, x⁻¹ ∈ carrier
/-- Reinterpret an `IntermediateField` as a `Subalgebra`. -/
add_decl_doc IntermediateField.toSubalgebra
variable {K L L'}
variable (S : IntermediateField K L)
namespace IntermediateField
instance : SetLike (IntermediateField K L) L :=
⟨fun S => S.toSubalgebra.carrier, by
rintro ⟨⟨⟩⟩ ⟨⟨⟩⟩
simp ⟩
protected theorem neg_mem {x : L} (hx : x ∈ S) : -x ∈ S := by
show -x ∈S.toSubalgebra; simpa
/-- Reinterpret an `IntermediateField` as a `Subfield`. -/
def toSubfield : Subfield L :=
{ S.toSubalgebra with
neg_mem' := S.neg_mem,
inv_mem' := S.inv_mem' }
instance : SubfieldClass (IntermediateField K L) L where
add_mem {s} := s.add_mem'
zero_mem {s} := s.zero_mem'
neg_mem {s} := s.neg_mem
mul_mem {s} := s.mul_mem'
one_mem {s} := s.one_mem'
inv_mem {s} := s.inv_mem' _
--@[simp] Porting note (#10618): simp can prove it
theorem mem_carrier {s : IntermediateField K L} {x : L} : x ∈ s.carrier ↔ x ∈ s :=
Iff.rfl
/-- Two intermediate fields are equal if they have the same elements. -/
@[ext]
theorem ext {S T : IntermediateField K L} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T :=
SetLike.ext h
@[simp]
theorem coe_toSubalgebra : (S.toSubalgebra : Set L) = S :=
rfl
@[simp]
theorem coe_toSubfield : (S.toSubfield : Set L) = S :=
rfl
@[simp]
theorem mem_mk (s : Subsemiring L) (hK : ∀ x, algebraMap K L x ∈ s) (hi) (x : L) :
x ∈ IntermediateField.mk (Subalgebra.mk s hK) hi ↔ x ∈ s :=
Iff.rfl
@[simp]
theorem mem_toSubalgebra (s : IntermediateField K L) (x : L) : x ∈ s.toSubalgebra ↔ x ∈ s :=
Iff.rfl
@[simp]
theorem mem_toSubfield (s : IntermediateField K L) (x : L) : x ∈ s.toSubfield ↔ x ∈ s :=
Iff.rfl
/-- Copy of an intermediate field with a new `carrier` equal to the old one. Useful to fix
definitional equalities. -/
protected def copy (S : IntermediateField K L) (s : Set L) (hs : s = ↑S) :
IntermediateField K L where
toSubalgebra := S.toSubalgebra.copy s (hs : s = S.toSubalgebra.carrier)
inv_mem' :=
have hs' : (S.toSubalgebra.copy s hs).carrier = S.toSubalgebra.carrier := hs
hs'.symm ▸ S.inv_mem'
@[simp]
theorem coe_copy (S : IntermediateField K L) (s : Set L) (hs : s = ↑S) :
(S.copy s hs : Set L) = s :=
rfl
theorem copy_eq (S : IntermediateField K L) (s : Set L) (hs : s = ↑S) : S.copy s hs = S :=
SetLike.coe_injective hs
section InheritedLemmas
/-! ### Lemmas inherited from more general structures
The declarations in this section derive from the fact that an `IntermediateField` is also a
subalgebra or subfield. Their use should be replaceable with the corresponding lemma from a
subobject class.
-/
/-- An intermediate field contains the image of the smaller field. -/
theorem algebraMap_mem (x : K) : algebraMap K L x ∈ S :=
S.algebraMap_mem' x
/-- An intermediate field is closed under scalar multiplication. -/
theorem smul_mem {y : L} : y ∈ S → ∀ {x : K}, x • y ∈ S :=
S.toSubalgebra.smul_mem
/-- An intermediate field contains the ring's 1. -/
protected theorem one_mem : (1 : L) ∈ S :=
one_mem S
/-- An intermediate field contains the ring's 0. -/
protected theorem zero_mem : (0 : L) ∈ S :=
zero_mem S
/-- An intermediate field is closed under multiplication. -/
protected theorem mul_mem {x y : L} : x ∈ S → y ∈ S → x * y ∈ S :=
mul_mem
/-- An intermediate field is closed under addition. -/
protected theorem add_mem {x y : L} : x ∈ S → y ∈ S → x + y ∈ S :=
add_mem
/-- An intermediate field is closed under subtraction -/
protected theorem sub_mem {x y : L} : x ∈ S → y ∈ S → x - y ∈ S :=
sub_mem
/-- An intermediate field is closed under inverses. -/
protected theorem inv_mem {x : L} : x ∈ S → x⁻¹ ∈ S :=
inv_mem
/-- An intermediate field is closed under division. -/
protected theorem div_mem {x y : L} : x ∈ S → y ∈ S → x / y ∈ S :=
div_mem
/-- Product of a list of elements in an intermediate_field is in the intermediate_field. -/
protected theorem list_prod_mem {l : List L} : (∀ x ∈ l, x ∈ S) → l.prod ∈ S :=
list_prod_mem
/-- Sum of a list of elements in an intermediate field is in the intermediate_field. -/
protected theorem list_sum_mem {l : List L} : (∀ x ∈ l, x ∈ S) → l.sum ∈ S :=
list_sum_mem
/-- Product of a multiset of elements in an intermediate field is in the intermediate_field. -/
protected theorem multiset_prod_mem (m : Multiset L) : (∀ a ∈ m, a ∈ S) → m.prod ∈ S :=
multiset_prod_mem m
/-- Sum of a multiset of elements in an `IntermediateField` is in the `IntermediateField`. -/
protected theorem multiset_sum_mem (m : Multiset L) : (∀ a ∈ m, a ∈ S) → m.sum ∈ S :=
multiset_sum_mem m
/-- Product of elements of an intermediate field indexed by a `Finset` is in the intermediate_field.
-/
protected theorem prod_mem {ι : Type*} {t : Finset ι} {f : ι → L} (h : ∀ c ∈ t, f c ∈ S) :
(∏ i ∈ t, f i) ∈ S :=
prod_mem h
/-- Sum of elements in an `IntermediateField` indexed by a `Finset` is in the `IntermediateField`.
-/
protected theorem sum_mem {ι : Type*} {t : Finset ι} {f : ι → L} (h : ∀ c ∈ t, f c ∈ S) :
(∑ i ∈ t, f i) ∈ S :=
sum_mem h
protected theorem pow_mem {x : L} (hx : x ∈ S) (n : ℤ) : x ^ n ∈ S :=
zpow_mem hx n
protected theorem zsmul_mem {x : L} (hx : x ∈ S) (n : ℤ) : n • x ∈ S :=
zsmul_mem hx n
protected theorem intCast_mem (n : ℤ) : (n : L) ∈ S :=
intCast_mem S n
protected theorem coe_add (x y : S) : (↑(x + y) : L) = ↑x + ↑y :=
rfl
protected theorem coe_neg (x : S) : (↑(-x) : L) = -↑x :=
rfl
protected theorem coe_mul (x y : S) : (↑(x * y) : L) = ↑x * ↑y :=
rfl
protected theorem coe_inv (x : S) : (↑x⁻¹ : L) = (↑x)⁻¹ :=
rfl
protected theorem coe_zero : ((0 : S) : L) = 0 :=
rfl
protected theorem coe_one : ((1 : S) : L) = 1 :=
rfl
protected theorem coe_pow (x : S) (n : ℕ) : (↑(x ^ n : S) : L) = (x : L) ^ n :=
SubmonoidClass.coe_pow x n
end InheritedLemmas
theorem natCast_mem (n : ℕ) : (n : L) ∈ S := by simpa using intCast_mem S n
@[deprecated _root_.natCast_mem (since := "2024-04-05")] alias coe_nat_mem := natCast_mem
@[deprecated _root_.intCast_mem (since := "2024-04-05")] alias coe_int_mem := intCast_mem
end IntermediateField
/-- Turn a subalgebra closed under inverses into an intermediate field -/
def Subalgebra.toIntermediateField (S : Subalgebra K L) (inv_mem : ∀ x ∈ S, x⁻¹ ∈ S) :
IntermediateField K L :=
{ S with
inv_mem' := inv_mem }
@[simp]
theorem toSubalgebra_toIntermediateField (S : Subalgebra K L) (inv_mem : ∀ x ∈ S, x⁻¹ ∈ S) :
(S.toIntermediateField inv_mem).toSubalgebra = S := by
ext
rfl
@[simp]
theorem toIntermediateField_toSubalgebra (S : IntermediateField K L) :
(S.toSubalgebra.toIntermediateField fun x => S.inv_mem) = S := by
ext
rfl
/-- Turn a subalgebra satisfying `IsField` into an intermediate_field -/
def Subalgebra.toIntermediateField' (S : Subalgebra K L) (hS : IsField S) : IntermediateField K L :=
S.toIntermediateField fun x hx => by
by_cases hx0 : x = 0
· rw [hx0, inv_zero]
exact S.zero_mem
letI hS' := hS.toField
obtain ⟨y, hy⟩ := hS.mul_inv_cancel (show (⟨x, hx⟩ : S) ≠ 0 from Subtype.coe_ne_coe.1 hx0)
rw [Subtype.ext_iff, S.coe_mul, S.coe_one, Subtype.coe_mk, mul_eq_one_iff_inv_eq₀ hx0] at hy
exact hy.symm ▸ y.2
@[simp]
theorem toSubalgebra_toIntermediateField' (S : Subalgebra K L) (hS : IsField S) :
(S.toIntermediateField' hS).toSubalgebra = S := by
ext
rfl
@[simp]
theorem toIntermediateField'_toSubalgebra (S : IntermediateField K L) :
S.toSubalgebra.toIntermediateField' (Field.toIsField S) = S := by
ext
rfl
/-- Turn a subfield of `L` containing the image of `K` into an intermediate field -/
def Subfield.toIntermediateField (S : Subfield L) (algebra_map_mem : ∀ x, algebraMap K L x ∈ S) :
IntermediateField K L :=
{ S with
algebraMap_mem' := algebra_map_mem }
namespace IntermediateField
/-- An intermediate field inherits a field structure -/
instance toField : Field S :=
S.toSubfield.toField
@[simp, norm_cast]
theorem coe_sum {ι : Type*} [Fintype ι] (f : ι → S) : (↑(∑ i, f i) : L) = ∑ i, (f i : L) := by
classical
induction' (Finset.univ : Finset ι) using Finset.induction_on with i s hi H
· simp
· rw [Finset.sum_insert hi, AddMemClass.coe_add, H, Finset.sum_insert hi]
@[norm_cast] --Porting note (#10618): `simp` can prove it
theorem coe_prod {ι : Type*} [Fintype ι] (f : ι → S) : (↑(∏ i, f i) : L) = ∏ i, (f i : L) := by
classical
induction' (Finset.univ : Finset ι) using Finset.induction_on with i s hi H
· simp
· rw [Finset.prod_insert hi, MulMemClass.coe_mul, H, Finset.prod_insert hi]
/-! `IntermediateField`s inherit structure from their `Subalgebra` coercions. -/
instance module' {R} [Semiring R] [SMul R K] [Module R L] [IsScalarTower R K L] : Module R S :=
S.toSubalgebra.module'
instance module : Module K S :=
inferInstanceAs (Module K S.toSubsemiring)
instance isScalarTower {R} [Semiring R] [SMul R K] [Module R L] [IsScalarTower R K L] :
IsScalarTower R K S :=
inferInstanceAs (IsScalarTower R K S.toSubsemiring)
@[simp]
theorem coe_smul {R} [Semiring R] [SMul R K] [Module R L] [IsScalarTower R K L] (r : R) (x : S) :
↑(r • x : S) = (r • (x : L)) :=
rfl
instance algebra : Algebra K S :=
inferInstanceAs (Algebra K S.toSubsemiring)
@[simp] lemma algebraMap_apply (x : S) : algebraMap S L x = x := rfl
@[simp] lemma coe_algebraMap_apply (x : K) : ↑(algebraMap K S x) = algebraMap K L x := rfl
instance isScalarTower_bot {R : Type*} [Semiring R] [Algebra L R] : IsScalarTower S L R :=
IsScalarTower.subalgebra _ _ _ S.toSubalgebra
instance isScalarTower_mid {R : Type*} [Semiring R] [Algebra L R] [Algebra K R]
[IsScalarTower K L R] : IsScalarTower K S R :=
IsScalarTower.subalgebra' _ _ _ S.toSubalgebra
/-- Specialize `is_scalar_tower_mid` to the common case where the top field is `L` -/
instance isScalarTower_mid' : IsScalarTower K S L :=
S.isScalarTower_mid
section shortcut_instances
variable {E} [Field E] [Algebra L E] (T : IntermediateField S E) {S}
instance : Algebra S T := T.algebra
instance : Module S T := Algebra.toModule
instance : SMul S T := Algebra.toSMul
instance [Algebra K E] [IsScalarTower K L E] : IsScalarTower K S T := T.isScalarTower
end shortcut_instances
/-- Given `f : L →ₐ[K] L'`, `S.comap f` is the intermediate field between `K` and `L`
such that `f x ∈ S ↔ x ∈ S.comap f`. -/
def comap (f : L →ₐ[K] L') (S : IntermediateField K L') : IntermediateField K L where
__ := S.toSubalgebra.comap f
inv_mem' x hx := show f x⁻¹ ∈ S by rw [map_inv₀ f x]; exact S.inv_mem hx
/-- Given `f : L →ₐ[K] L'`, `S.map f` is the intermediate field between `K` and `L'`
such that `x ∈ S ↔ f x ∈ S.map f`. -/
def map (f : L →ₐ[K] L') (S : IntermediateField K L) : IntermediateField K L' where
__ := S.toSubalgebra.map f
inv_mem' := by
rintro _ ⟨x, hx, rfl⟩
exact ⟨x⁻¹, S.inv_mem hx, map_inv₀ f x⟩
@[simp]
theorem coe_map (f : L →ₐ[K] L') : (S.map f : Set L') = f '' S :=
rfl
@[simp]
theorem toSubalgebra_map (f : L →ₐ[K] L') : (S.map f).toSubalgebra = S.toSubalgebra.map f :=
rfl
@[simp]
theorem toSubfield_map (f : L →ₐ[K] L') : (S.map f).toSubfield = S.toSubfield.map f :=
rfl
theorem map_map {K L₁ L₂ L₃ : Type*} [Field K] [Field L₁] [Algebra K L₁] [Field L₂] [Algebra K L₂]
[Field L₃] [Algebra K L₃] (E : IntermediateField K L₁) (f : L₁ →ₐ[K] L₂) (g : L₂ →ₐ[K] L₃) :
(E.map f).map g = E.map (g.comp f) :=
SetLike.coe_injective <| Set.image_image _ _ _
theorem map_mono (f : L →ₐ[K] L') {S T : IntermediateField K L} (h : S ≤ T) :
S.map f ≤ T.map f :=
SetLike.coe_mono (Set.image_subset f h)
theorem map_le_iff_le_comap {f : L →ₐ[K] L'}
{s : IntermediateField K L} {t : IntermediateField K L'} :
s.map f ≤ t ↔ s ≤ t.comap f :=
Set.image_subset_iff
theorem gc_map_comap (f : L →ₐ[K] L') : GaloisConnection (map f) (comap f) :=
fun _ _ ↦ map_le_iff_le_comap
/-- Given an equivalence `e : L ≃ₐ[K] L'` of `K`-field extensions and an intermediate
field `E` of `L/K`, `intermediateFieldMap e E` is the induced equivalence
between `E` and `E.map e` -/
def intermediateFieldMap (e : L ≃ₐ[K] L') (E : IntermediateField K L) : E ≃ₐ[K] E.map e.toAlgHom :=
e.subalgebraMap E.toSubalgebra
/- We manually add these two simp lemmas because `@[simps]` before `intermediate_field_map`
led to a timeout. -/
-- This lemma has always been bad, but the linter only noticed after lean4#2644.
@[simp, nolint simpNF]
theorem intermediateFieldMap_apply_coe (e : L ≃ₐ[K] L') (E : IntermediateField K L) (a : E) :
↑(intermediateFieldMap e E a) = e a :=
rfl
-- This lemma has always been bad, but the linter only noticed after lean4#2644.
@[simp, nolint simpNF]
theorem intermediateFieldMap_symm_apply_coe (e : L ≃ₐ[K] L') (E : IntermediateField K L)
(a : E.map e.toAlgHom) : ↑((intermediateFieldMap e E).symm a) = e.symm a :=
rfl
end IntermediateField
namespace AlgHom
variable (f : L →ₐ[K] L')
/-- The range of an algebra homomorphism, as an intermediate field. -/
@[simps toSubalgebra]
def fieldRange : IntermediateField K L' :=
{ f.range, (f : L →+* L').fieldRange with }
@[simp]
theorem coe_fieldRange : ↑f.fieldRange = Set.range f :=
rfl
@[simp]
theorem fieldRange_toSubfield : f.fieldRange.toSubfield = (f : L →+* L').fieldRange :=
rfl
variable {f}
@[simp]
theorem mem_fieldRange {y : L'} : y ∈ f.fieldRange ↔ ∃ x, f x = y :=
Iff.rfl
end AlgHom
namespace IntermediateField
/-- The embedding from an intermediate field of `L / K` to `L`. -/
def val : S →ₐ[K] L :=
S.toSubalgebra.val
@[simp]
theorem coe_val : ⇑S.val = ((↑) : S → L) :=
rfl
@[simp]
theorem val_mk {x : L} (hx : x ∈ S) : S.val ⟨x, hx⟩ = x :=
rfl
theorem range_val : S.val.range = S.toSubalgebra :=
S.toSubalgebra.range_val
@[simp]
theorem fieldRange_val : S.val.fieldRange = S :=
SetLike.ext' Subtype.range_val
instance AlgHom.inhabited : Inhabited (S →ₐ[K] L) :=
⟨S.val⟩
theorem aeval_coe {R : Type*} [CommRing R] [Algebra R K] [Algebra R L] [IsScalarTower R K L]
(x : S) (P : R[X]) : aeval (x : L) P = aeval x P := by
refine Polynomial.induction_on' P (fun f g hf hg => ?_) fun n r => ?_
· rw [aeval_add, aeval_add, AddMemClass.coe_add, hf, hg]
· simp only [MulMemClass.coe_mul, aeval_monomial, SubmonoidClass.coe_pow, mul_eq_mul_right_iff]
left
rfl
theorem coe_isIntegral_iff {R : Type*} [CommRing R] [Algebra R K] [Algebra R L]
[IsScalarTower R K L] {x : S} : IsIntegral R (x : L) ↔ IsIntegral R x := by
refine ⟨fun h => ?_, fun h => ?_⟩
· obtain ⟨P, hPmo, hProot⟩ := h
refine ⟨P, hPmo, (injective_iff_map_eq_zero _).1 (algebraMap (↥S) L).injective _ ?_⟩
letI : IsScalarTower R S L := IsScalarTower.of_algebraMap_eq (congr_fun rfl)
rw [eval₂_eq_eval_map, ← eval₂_at_apply, eval₂_eq_eval_map, Polynomial.map_map, ←
IsScalarTower.algebraMap_eq, ← eval₂_eq_eval_map]
exact hProot
· obtain ⟨P, hPmo, hProot⟩ := h
refine ⟨P, hPmo, ?_⟩
rw [← aeval_def, aeval_coe, aeval_def, hProot, ZeroMemClass.coe_zero]
/-- The map `E → F` when `E` is an intermediate field contained in the intermediate field `F`.
This is the intermediate field version of `Subalgebra.inclusion`. -/
def inclusion {E F : IntermediateField K L} (hEF : E ≤ F) : E →ₐ[K] F :=
Subalgebra.inclusion hEF
theorem inclusion_injective {E F : IntermediateField K L} (hEF : E ≤ F) :
Function.Injective (inclusion hEF) :=
Subalgebra.inclusion_injective hEF
@[simp]
theorem inclusion_self {E : IntermediateField K L} : inclusion (le_refl E) = AlgHom.id K E :=
Subalgebra.inclusion_self
@[simp]
theorem inclusion_inclusion {E F G : IntermediateField K L} (hEF : E ≤ F) (hFG : F ≤ G) (x : E) :
inclusion hFG (inclusion hEF x) = inclusion (le_trans hEF hFG) x :=
Subalgebra.inclusion_inclusion hEF hFG x
@[simp]
theorem coe_inclusion {E F : IntermediateField K L} (hEF : E ≤ F) (e : E) :
(inclusion hEF e : L) = e :=
rfl
variable {S}
theorem toSubalgebra_injective :
Function.Injective (IntermediateField.toSubalgebra : IntermediateField K L → _) := by
intro S S' h
ext
rw [← mem_toSubalgebra, ← mem_toSubalgebra, h]
theorem map_injective (f : L →ₐ[K] L') :
Function.Injective (map f) := by
intro _ _ h
rwa [← toSubalgebra_injective.eq_iff, toSubalgebra_map, toSubalgebra_map,
(Subalgebra.map_injective f.injective).eq_iff, toSubalgebra_injective.eq_iff] at h
variable (S)
theorem set_range_subset : Set.range (algebraMap K L) ⊆ S :=
S.toSubalgebra.range_subset
theorem fieldRange_le : (algebraMap K L).fieldRange ≤ S.toSubfield := fun x hx =>
S.toSubalgebra.range_subset (by rwa [Set.mem_range, ← RingHom.mem_fieldRange])
@[simp]
theorem toSubalgebra_le_toSubalgebra {S S' : IntermediateField K L} :
S.toSubalgebra ≤ S'.toSubalgebra ↔ S ≤ S' :=
Iff.rfl
@[simp]
theorem toSubalgebra_lt_toSubalgebra {S S' : IntermediateField K L} :
S.toSubalgebra < S'.toSubalgebra ↔ S < S' :=
Iff.rfl
variable {S}
section Tower
/-- Lift an intermediate_field of an intermediate_field -/
def lift {F : IntermediateField K L} (E : IntermediateField K F) : IntermediateField K L :=
E.map (val F)
-- Porting note: change from `HasLiftT` to `CoeOut`
instance hasLift {F : IntermediateField K L} :
CoeOut (IntermediateField K F) (IntermediateField K L) :=
⟨lift⟩
theorem lift_injective (F : IntermediateField K L) : Function.Injective F.lift :=
map_injective F.val
theorem lift_le {F : IntermediateField K L} (E : IntermediateField K F) : lift E ≤ F := by
rintro _ ⟨x, _, rfl⟩
exact x.2
theorem mem_lift {F : IntermediateField K L} {E : IntermediateField K F} (x : F) :
x.1 ∈ lift E ↔ x ∈ E :=
Subtype.val_injective.mem_set_image
section RestrictScalars
variable (K)
variable [Algebra L' L] [IsScalarTower K L' L]
/-- Given a tower `L / ↥E / L' / K` of field extensions, where `E` is an `L'`-intermediate field of
`L`, reinterpret `E` as a `K`-intermediate field of `L`. -/
def restrictScalars (E : IntermediateField L' L) : IntermediateField K L :=
{ E.toSubfield, E.toSubalgebra.restrictScalars K with
carrier := E.carrier }
@[simp]
theorem coe_restrictScalars {E : IntermediateField L' L} :
(restrictScalars K E : Set L) = (E : Set L) :=
rfl
@[simp]
theorem restrictScalars_toSubalgebra {E : IntermediateField L' L} :
(E.restrictScalars K).toSubalgebra = E.toSubalgebra.restrictScalars K :=
SetLike.coe_injective rfl
@[simp]
theorem restrictScalars_toSubfield {E : IntermediateField L' L} :
(E.restrictScalars K).toSubfield = E.toSubfield :=
SetLike.coe_injective rfl
@[simp]
theorem mem_restrictScalars {E : IntermediateField L' L} {x : L} :
x ∈ restrictScalars K E ↔ x ∈ E :=
Iff.rfl
theorem restrictScalars_injective :
Function.Injective (restrictScalars K : IntermediateField L' L → IntermediateField K L) :=
fun U V H => ext fun x => by rw [← mem_restrictScalars K, H, mem_restrictScalars]
end RestrictScalars
/-- This was formerly an instance called `lift2_alg`, but an instance above already provides it. -/
example {F : IntermediateField K L} {E : IntermediateField F L} : Algebra K E := by infer_instance
end Tower
end IntermediateField
section ExtendScalars
namespace Subfield
variable {F E E' : Subfield L} (h : F ≤ E) (h' : F ≤ E') {x : L}
/-- If `F ≤ E` are two subfields of `L`, then `E` is also an intermediate field of
`L / F`. It can be viewed as an inverse to `IntermediateField.toSubfield`. -/
def extendScalars : IntermediateField F L := E.toIntermediateField fun ⟨_, hf⟩ ↦ h hf
@[simp]
theorem coe_extendScalars : (extendScalars h : Set L) = (E : Set L) := rfl
@[simp]
theorem extendScalars_toSubfield : (extendScalars h).toSubfield = E := SetLike.coe_injective rfl
@[simp]
theorem mem_extendScalars : x ∈ extendScalars h ↔ x ∈ E := Iff.rfl
theorem extendScalars_le_extendScalars_iff : extendScalars h ≤ extendScalars h' ↔ E ≤ E' := Iff.rfl
theorem extendScalars_le_iff (E' : IntermediateField F L) :
extendScalars h ≤ E' ↔ E ≤ E'.toSubfield := Iff.rfl
theorem le_extendScalars_iff (E' : IntermediateField F L) :
E' ≤ extendScalars h ↔ E'.toSubfield ≤ E := Iff.rfl
variable (F)
/-- `Subfield.extendScalars.orderIso` bundles `Subfield.extendScalars`
into an order isomorphism from
`{ E : Subfield L // F ≤ E }` to `IntermediateField F L`. Its inverse is
`IntermediateField.toSubfield`. -/
@[simps]
def extendScalars.orderIso :
{ E : Subfield L // F ≤ E } ≃o IntermediateField F L where
toFun E := extendScalars E.2
invFun E := ⟨E.toSubfield, fun x hx ↦ E.algebraMap_mem ⟨x, hx⟩⟩
left_inv E := rfl
right_inv E := rfl
map_rel_iff' {E E'} := by
simp only [Equiv.coe_fn_mk]
exact extendScalars_le_extendScalars_iff _ _
theorem extendScalars_injective :
Function.Injective fun E : { E : Subfield L // F ≤ E } ↦ extendScalars E.2 :=
(extendScalars.orderIso F).injective
end Subfield
namespace IntermediateField
variable {F E E' : IntermediateField K L} (h : F ≤ E) (h' : F ≤ E') {x : L}
/-- If `F ≤ E` are two intermediate fields of `L / K`, then `E` is also an intermediate field of
`L / F`. It can be viewed as an inverse to `IntermediateField.restrictScalars`. -/
def extendScalars : IntermediateField F L :=
Subfield.extendScalars (show F.toSubfield ≤ E.toSubfield from h)
@[simp]
theorem coe_extendScalars : (extendScalars h : Set L) = (E : Set L) := rfl
@[simp]
theorem extendScalars_toSubfield : (extendScalars h).toSubfield = E.toSubfield :=
SetLike.coe_injective rfl
@[simp]
theorem mem_extendScalars : x ∈ extendScalars h ↔ x ∈ E := Iff.rfl
@[simp]
theorem extendScalars_restrictScalars : (extendScalars h).restrictScalars K = E := rfl
theorem extendScalars_le_extendScalars_iff : extendScalars h ≤ extendScalars h' ↔ E ≤ E' := Iff.rfl
theorem extendScalars_le_iff (E' : IntermediateField F L) :
extendScalars h ≤ E' ↔ E ≤ E'.restrictScalars K := Iff.rfl
theorem le_extendScalars_iff (E' : IntermediateField F L) :
E' ≤ extendScalars h ↔ E'.restrictScalars K ≤ E := Iff.rfl
variable (F)
/-- `IntermediateField.extendScalars.orderIso` bundles `IntermediateField.extendScalars`
into an order isomorphism from
`{ E : IntermediateField K L // F ≤ E }` to `IntermediateField F L`. Its inverse is
`IntermediateField.restrictScalars`. -/
@[simps]
def extendScalars.orderIso : { E : IntermediateField K L // F ≤ E } ≃o IntermediateField F L where
toFun E := extendScalars E.2
invFun E := ⟨E.restrictScalars K, fun x hx ↦ E.algebraMap_mem ⟨x, hx⟩⟩
left_inv E := rfl
right_inv E := rfl
map_rel_iff' {E E'} := by
simp only [Equiv.coe_fn_mk]
exact extendScalars_le_extendScalars_iff _ _
theorem extendScalars_injective :
Function.Injective fun E : { E : IntermediateField K L // F ≤ E } ↦ extendScalars E.2 :=
(extendScalars.orderIso F).injective
end IntermediateField
end ExtendScalars
namespace IntermediateField
variable {S}
section Tower
section Restrict
variable {F E : IntermediateField K L} (h : F ≤ E)
/--
If `F ≤ E` are two intermediate fields of `L / K`, then `F` is also an intermediate field of
`E / K`. It is an inverse of `IntermediateField.lift`, and can be viewed as a dual to
`IntermediateField.extendScalars`.
-/
def restrict : IntermediateField K E :=
(IntermediateField.inclusion h).fieldRange
theorem mem_restrict (x : E) : x ∈ restrict h ↔ x.1 ∈ F :=
Set.ext_iff.mp (Set.range_inclusion h) x
@[simp]
theorem lift_restrict : lift (restrict h) = F := by
ext x
refine ⟨fun hx ↦ ?_, fun hx ↦ ?_⟩
· let y : E := ⟨x, lift_le (restrict h) hx⟩
exact (mem_restrict h y).1 ((mem_lift y).1 hx)
· let y : E := ⟨x, h hx⟩
exact (mem_lift y).2 ((mem_restrict h y).2 hx)
/--
`F` is equivalent to `F` as an intermediate field of `E / K`.
-/
noncomputable def restrict_algEquiv :
F ≃ₐ[K] ↥(IntermediateField.restrict h) :=
AlgEquiv.ofInjectiveField _
end Restrict
end Tower
section FiniteDimensional
variable (F E : IntermediateField K L)
instance finiteDimensional_left [FiniteDimensional K L] : FiniteDimensional K F :=
left K F L
instance finiteDimensional_right [FiniteDimensional K L] : FiniteDimensional F L :=
right K F L
@[simp]
theorem rank_eq_rank_subalgebra : Module.rank K F.toSubalgebra = Module.rank K F :=
rfl
@[simp]
theorem finrank_eq_finrank_subalgebra : finrank K F.toSubalgebra = finrank K F :=
rfl
variable {F} {E}
@[simp]
theorem toSubalgebra_eq_iff : F.toSubalgebra = E.toSubalgebra ↔ F = E := by
rw [SetLike.ext_iff, SetLike.ext'_iff, Set.ext_iff]
rfl
/-- If `F ≤ E` are two intermediate fields of `L / K` such that `[E : K] ≤ [F : K]` are finite,
then `F = E`. -/
theorem eq_of_le_of_finrank_le [hfin : FiniteDimensional K E] (h_le : F ≤ E)
(h_finrank : finrank K E ≤ finrank K F) : F = E :=
haveI : Module.Finite K E.toSubalgebra := hfin
toSubalgebra_injective <| Subalgebra.eq_of_le_of_finrank_le h_le h_finrank
/-- If `F ≤ E` are two intermediate fields of `L / K` such that `[F : K] = [E : K]` are finite,
then `F = E`. -/
theorem eq_of_le_of_finrank_eq [FiniteDimensional K E] (h_le : F ≤ E)
(h_finrank : finrank K F = finrank K E) : F = E :=
eq_of_le_of_finrank_le h_le h_finrank.ge
-- If `F ≤ E` are two intermediate fields of a finite extension `L / K` such that
-- `[L : F] ≤ [L : E]`, then `F = E`. Marked as private since it's a direct corollary of
-- `eq_of_le_of_finrank_le'` (the `FiniteDimensional K L` implies `FiniteDimensional F L`
-- automatically by typeclass resolution).
private theorem eq_of_le_of_finrank_le'' [FiniteDimensional K L] (h_le : F ≤ E)
(h_finrank : finrank F L ≤ finrank E L) : F = E := by
apply eq_of_le_of_finrank_le h_le
have h1 := finrank_mul_finrank K F L
have h2 := finrank_mul_finrank K E L
have h3 : 0 < finrank E L := finrank_pos
nlinarith
/-- If `F ≤ E` are two intermediate fields of `L / K` such that `[L : F] ≤ [L : E]` are finite,
then `F = E`. -/
theorem eq_of_le_of_finrank_le' [FiniteDimensional F L] (h_le : F ≤ E)
(h_finrank : finrank F L ≤ finrank E L) : F = E := by
refine le_antisymm h_le (fun l hl ↦ ?_)
rwa [← mem_extendScalars (le_refl F), eq_of_le_of_finrank_le''
((extendScalars_le_extendScalars_iff (le_refl F) h_le).2 h_le) h_finrank, mem_extendScalars]
/-- If `F ≤ E` are two intermediate fields of `L / K` such that `[L : F] = [L : E]` are finite,
then `F = E`. -/
theorem eq_of_le_of_finrank_eq' [FiniteDimensional F L] (h_le : F ≤ E)
(h_finrank : finrank F L = finrank E L) : F = E :=
eq_of_le_of_finrank_le' h_le h_finrank.le
end FiniteDimensional
theorem isAlgebraic_iff {x : S} : IsAlgebraic K x ↔ IsAlgebraic K (x : L) :=
(isAlgebraic_algebraMap_iff (algebraMap S L).injective).symm
theorem isIntegral_iff {x : S} : IsIntegral K x ↔ IsIntegral K (x : L) := by
rw [← isAlgebraic_iff_isIntegral, isAlgebraic_iff, isAlgebraic_iff_isIntegral]
theorem minpoly_eq (x : S) : minpoly K x = minpoly K (x : L) :=
(minpoly.algebraMap_eq (algebraMap S L).injective x).symm
end IntermediateField
/-- If `L/K` is algebraic, the `K`-subalgebras of `L` are all fields. -/
def subalgebraEquivIntermediateField [Algebra.IsAlgebraic K L] :
Subalgebra K L ≃o IntermediateField K L where
toFun S := S.toIntermediateField fun x hx => S.inv_mem_of_algebraic
(Algebra.IsAlgebraic.isAlgebraic ((⟨x, hx⟩ : S) : L))
invFun S := S.toSubalgebra
left_inv _ := toSubalgebra_toIntermediateField _ _
right_inv := toIntermediateField_toSubalgebra
map_rel_iff' := Iff.rfl
@[simp]
theorem mem_subalgebraEquivIntermediateField [Algebra.IsAlgebraic K L] {S : Subalgebra K L}
{x : L} : x ∈ subalgebraEquivIntermediateField S ↔ x ∈ S :=
Iff.rfl
@[simp]
theorem mem_subalgebraEquivIntermediateField_symm [Algebra.IsAlgebraic K L]
{S : IntermediateField K L} {x : L} :
x ∈ subalgebraEquivIntermediateField.symm S ↔ x ∈ S :=
Iff.rfl
|
FieldTheory\IsPerfectClosure.lean | /-
Copyright (c) 2024 Jz Pan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jz Pan
-/
import Mathlib.FieldTheory.PurelyInseparable
import Mathlib.FieldTheory.PerfectClosure
/-!
# `IsPerfectClosure` predicate
This file contains `IsPerfectClosure` which asserts that `L` is a perfect closure of `K` under a
ring homomorphism `i : K →+* L`, as well as its basic properties.
## Main definitions
- `pNilradical`: given a natural number `p`, the `p`-nilradical of a ring is defined to be the
nilradical if `p > 1` (`pNilradical_eq_nilradical`), and defined to be the zero ideal if `p ≤ 1`
(`pNilradical_eq_bot'`). Equivalently, it is the ideal consisting of elements `x` such that
`x ^ p ^ n = 0` for some `n` (`mem_pNilradical`).
- `IsPRadical`: a ring homomorphism `i : K →+* L` of characteristic `p` rings is called `p`-radical,
if or any element `x` of `L` there is `n : ℕ` such that `x ^ (p ^ n)` is contained in `K`,
and the kernel of `i` is contained in the `p`-nilradical of `K`.
A generalization of purely inseparable extension for fields.
- `IsPerfectClosure`: if `i : K →+* L` is `p`-radical ring homomorphism, then it makes `L` a
perfect closure of `K`, if `L` is perfect.
Our definition makes it synonymous to `IsPRadical` if `PerfectRing L p` is present. A caveat is
that you need to write `[PerfectRing L p] [IsPerfectClosure i p]`. This is similar to
`PerfectRing` which has `ExpChar` as a prerequisite.
- `PerfectRing.lift`: if a `p`-radical ring homomorphism `K →+* L` is given, `M` is a perfect ring,
then any ring homomorphism `K →+* M` can be lifted to `L →+* M`.
This is similar to `IsAlgClosed.lift` and `IsSepClosed.lift`.
- `PerfectRing.liftEquiv`: `K →+* M` is one-to-one correspondence to `L →+* M`,
given by `PerfectRing.lift`. This is a generalization to `PerfectClosure.lift`.
- `IsPerfectClosure.equiv`: perfect closures of a ring are isomorphic.
## Main results
- `IsPRadical.trans`: composition of `p`-radical ring homomorphisms is also `p`-radical.
- `PerfectClosure.isPRadical`: the absolute perfect closure `PerfectClosure` is a `p`-radical
extension over the base ring, in particular, it is a perfect closure of the base ring.
- `IsPRadical.isPurelyInseparable`, `IsPurelyInseparable.isPRadical`: `p`-radical and
purely inseparable are equivalent for fields.
- The (relative) perfect closure `perfectClosure` is a perfect closure
(inferred from `IsPurelyInseparable.isPRadical` automatically by Lean).
## Tags
perfect ring, perfect closure, purely inseparable
-/
open FiniteDimensional Polynomial IntermediateField Field
noncomputable section
/-- Given a natural number `p`, the `p`-nilradical of a ring is defined to be the
nilradical if `p > 1` (`pNilradical_eq_nilradical`), and defined to be the zero ideal if `p ≤ 1`
(`pNilradical_eq_bot'`). Equivalently, it is the ideal consisting of elements `x` such that
`x ^ p ^ n = 0` for some `n` (`mem_pNilradical`). -/
def pNilradical (R : Type*) [CommSemiring R] (p : ℕ) : Ideal R := if 1 < p then nilradical R else ⊥
theorem pNilradical_le_nilradical {R : Type*} [CommSemiring R] {p : ℕ} :
pNilradical R p ≤ nilradical R := by
by_cases hp : 1 < p
· rw [pNilradical, if_pos hp]
simp_rw [pNilradical, if_neg hp, bot_le]
theorem pNilradical_eq_nilradical {R : Type*} [CommSemiring R] {p : ℕ} (hp : 1 < p) :
pNilradical R p = nilradical R := by rw [pNilradical, if_pos hp]
theorem pNilradical_eq_bot {R : Type*} [CommSemiring R] {p : ℕ} (hp : ¬ 1 < p) :
pNilradical R p = ⊥ := by rw [pNilradical, if_neg hp]
theorem pNilradical_eq_bot' {R : Type*} [CommSemiring R] {p : ℕ} (hp : p ≤ 1) :
pNilradical R p = ⊥ := pNilradical_eq_bot (not_lt.2 hp)
theorem pNilradical_prime {R : Type*} [CommSemiring R] {p : ℕ} (hp : p.Prime) :
pNilradical R p = nilradical R := pNilradical_eq_nilradical hp.one_lt
theorem pNilradical_one {R : Type*} [CommSemiring R] :
pNilradical R 1 = ⊥ := pNilradical_eq_bot' rfl.le
theorem mem_pNilradical {R : Type*} [CommSemiring R] {p : ℕ} {x : R} :
x ∈ pNilradical R p ↔ ∃ n : ℕ, x ^ p ^ n = 0 := by
by_cases hp : 1 < p
· rw [pNilradical_eq_nilradical hp]
refine ⟨fun ⟨n, h⟩ ↦ ⟨n, ?_⟩, fun ⟨n, h⟩ ↦ ⟨p ^ n, h⟩⟩
rw [← Nat.sub_add_cancel ((Nat.lt_pow_self hp n).le), pow_add, h, mul_zero]
rw [pNilradical_eq_bot hp, Ideal.mem_bot]
refine ⟨fun h ↦ ⟨0, by rw [pow_zero, pow_one, h]⟩, fun ⟨n, h⟩ ↦ ?_⟩
rcases Nat.le_one_iff_eq_zero_or_eq_one.1 (not_lt.1 hp) with hp | hp
· by_cases hn : n = 0
· rwa [hn, pow_zero, pow_one] at h
rw [hp, zero_pow hn, pow_zero] at h
subsingleton [subsingleton_of_zero_eq_one h.symm]
rwa [hp, one_pow, pow_one] at h
theorem sub_mem_pNilradical_iff_pow_expChar_pow_eq {R : Type*} [CommRing R] {p : ℕ} [ExpChar R p]
{x y : R} : x - y ∈ pNilradical R p ↔ ∃ n : ℕ, x ^ p ^ n = y ^ p ^ n := by
simp_rw [mem_pNilradical, sub_pow_expChar_pow, sub_eq_zero]
theorem pow_expChar_pow_inj_of_pNilradical_eq_bot (R : Type*) [CommRing R] (p : ℕ) [ExpChar R p]
(h : pNilradical R p = ⊥) (n : ℕ) : Function.Injective fun x : R ↦ x ^ p ^ n := fun _ _ H ↦
sub_eq_zero.1 <| Ideal.mem_bot.1 <| h ▸ sub_mem_pNilradical_iff_pow_expChar_pow_eq.2 ⟨n, H⟩
theorem pNilradical_eq_bot_of_frobenius_inj (R : Type*) [CommRing R] (p : ℕ) [ExpChar R p]
(h : Function.Injective (frobenius R p)) : pNilradical R p = ⊥ := bot_unique fun x ↦ by
rw [mem_pNilradical, Ideal.mem_bot]
exact fun ⟨n, _⟩ ↦ h.iterate n (by rwa [← coe_iterateFrobenius, map_zero])
theorem PerfectRing.pNilradical_eq_bot (R : Type*) [CommRing R] (p : ℕ) [ExpChar R p]
[PerfectRing R p] : pNilradical R p = ⊥ :=
pNilradical_eq_bot_of_frobenius_inj R p (injective_frobenius R p)
section IsPerfectClosure
variable {K L M N : Type*}
section CommSemiring
variable [CommSemiring K] [CommSemiring L] [CommSemiring M]
(i : K →+* L) (j : K →+* M) (f : L →+* M) (p : ℕ)
/-- If `i : K →+* L` is a ring homomorphism of characteristic `p` rings, then it is called
`p`-radical if the following conditions are satisfied:
- For any element `x` of `L` there is `n : ℕ` such that `x ^ (p ^ n)` is contained in `K`.
- The kernel of `i` is contained in the `p`-nilradical of `K`.
It is a generalization of purely inseparable extension for fields. -/
@[mk_iff]
class IsPRadical : Prop where
pow_mem' : ∀ x : L, ∃ (n : ℕ) (y : K), i y = x ^ p ^ n
ker_le' : RingHom.ker i ≤ pNilradical K p
theorem IsPRadical.pow_mem [IsPRadical i p] (x : L) :
∃ (n : ℕ) (y : K), i y = x ^ p ^ n := pow_mem' x
theorem IsPRadical.ker_le [IsPRadical i p] :
RingHom.ker i ≤ pNilradical K p := ker_le'
theorem IsPRadical.comap_pNilradical [IsPRadical i p] :
(pNilradical L p).comap i = pNilradical K p := by
refine le_antisymm (fun x h ↦ mem_pNilradical.2 ?_) (fun x h ↦ ?_)
· obtain ⟨n, h⟩ := mem_pNilradical.1 <| Ideal.mem_comap.1 h
obtain ⟨m, h⟩ := mem_pNilradical.1 <| ker_le i p ((map_pow i x _).symm ▸ h)
exact ⟨n + m, by rwa [pow_add, pow_mul]⟩
simp only [Ideal.mem_comap, mem_pNilradical] at h ⊢
obtain ⟨n, h⟩ := h
exact ⟨n, by simpa only [map_pow, map_zero] using congr(i $h)⟩
variable (K) in
instance IsPRadical.of_id : IsPRadical (RingHom.id K) p where
pow_mem' x := ⟨0, x, by simp⟩
ker_le' x h := by convert Ideal.zero_mem _
/-- Composition of `p`-radical ring homomorphisms is also `p`-radical. -/
theorem IsPRadical.trans [IsPRadical i p] [IsPRadical f p] :
IsPRadical (f.comp i) p where
pow_mem' x := by
obtain ⟨n, y, hy⟩ := pow_mem f p x
obtain ⟨m, z, hz⟩ := pow_mem i p y
exact ⟨n + m, z, by rw [RingHom.comp_apply, hz, map_pow, hy, pow_add, pow_mul]⟩
ker_le' x h := by
rw [RingHom.mem_ker, RingHom.comp_apply, ← RingHom.mem_ker] at h
simpa only [← Ideal.mem_comap, comap_pNilradical] using ker_le f p h
/-- If `i : K →+* L` is a `p`-radical ring homomorphism, then it makes `L` a perfect closure
of `K`, if `L` is perfect.
In this case the kernel of `i` is equal to the `p`-nilradical of `K`
(see `IsPerfectClosure.ker_eq`).
Our definition makes it synonymous to `IsPRadical` if `PerfectRing L p` is present. A caveat is
that you need to write `[PerfectRing L p] [IsPerfectClosure i p]`. This is similar to
`PerfectRing` which has `ExpChar` as a prerequisite. -/
@[nolint unusedArguments]
abbrev IsPerfectClosure [ExpChar L p] [PerfectRing L p] := IsPRadical i p
/-- If `i : K →+* L` is a ring homomorphism of exponential characteristic `p` rings, such that `L`
is perfect, then the `p`-nilradical of `K` is contained in the kernel of `i`. -/
theorem RingHom.pNilradical_le_ker_of_perfectRing [ExpChar L p] [PerfectRing L p] :
pNilradical K p ≤ RingHom.ker i := fun x h ↦ by
obtain ⟨n, h⟩ := mem_pNilradical.1 h
replace h := congr((iterateFrobeniusEquiv L p n).symm (i $h))
rwa [map_pow, ← iterateFrobenius_def, ← iterateFrobeniusEquiv_apply, RingEquiv.symm_apply_apply,
map_zero, map_zero] at h
variable [ExpChar L p] [ExpChar M p] in
theorem IsPerfectClosure.ker_eq [PerfectRing L p] [IsPerfectClosure i p] :
RingHom.ker i = pNilradical K p :=
IsPRadical.ker_le'.antisymm (i.pNilradical_le_ker_of_perfectRing p)
namespace PerfectRing
/- NOTE: To define `PerfectRing.lift_aux`, only the `IsPRadical.pow_mem` is required, but not
`IsPRadical.ker_le`. But in order to use typeclass, here we require the whole `IsPRadical`. -/
variable [ExpChar M p] [PerfectRing M p] [IsPRadical i p]
theorem lift_aux (x : L) : ∃ y : ℕ × K, i y.2 = x ^ p ^ y.1 := by
obtain ⟨n, y, h⟩ := IsPRadical.pow_mem i p x
exact ⟨(n, y), h⟩
/-- If `i : K →+* L` and `j : K →+* M` are ring homomorphisms of characteristic `p` rings, such that
`i` is `p`-radical (in fact only the `IsPRadical.pow_mem` is required) and `M` is a perfect ring,
then one can define a map `L → M` which maps an element `x` of `L` to `y ^ (p ^ -n)` if
`x ^ (p ^ n)` is equal to some element `y` of `K`. -/
def liftAux (x : L) : M := (iterateFrobeniusEquiv M p (Classical.choose (lift_aux i p x)).1).symm
(j (Classical.choose (lift_aux i p x)).2)
@[simp]
theorem liftAux_self_apply [ExpChar L p] [PerfectRing L p] (x : L) : liftAux i i p x = x := by
rw [liftAux, Classical.choose_spec (lift_aux i p x), ← iterateFrobenius_def,
← iterateFrobeniusEquiv_apply, RingEquiv.symm_apply_apply]
@[simp]
theorem liftAux_self [ExpChar L p] [PerfectRing L p] : liftAux i i p = id :=
funext (liftAux_self_apply i p)
@[simp]
theorem liftAux_id_apply (x : K) : liftAux (RingHom.id K) j p x = j x := by
have := RingHom.id_apply _ ▸ Classical.choose_spec (lift_aux (RingHom.id K) p x)
rw [liftAux, this, map_pow, ← iterateFrobenius_def, ← iterateFrobeniusEquiv_apply,
RingEquiv.symm_apply_apply]
@[simp]
theorem liftAux_id : liftAux (RingHom.id K) j p = j := funext (liftAux_id_apply j p)
end PerfectRing
end CommSemiring
section CommRing
variable [CommRing K] [CommRing L] [CommRing M] [CommRing N]
(i : K →+* L) (j : K →+* M) (k : K →+* N) (f : L →+* M) (g : L →+* N)
(p : ℕ) [ExpChar M p]
namespace IsPRadical
/-- If `i : K →+* L` is `p`-radical, then for any ring `M` of exponential charactistic `p` whose
`p`-nilradical is zero, the map `(L →+* M) → (K →+* M)` induced by `i` is injective. -/
theorem injective_comp_of_pNilradical_eq_bot [IsPRadical i p] (h : pNilradical M p = ⊥) :
Function.Injective fun f : L →+* M ↦ f.comp i := fun f g heq ↦ by
ext x
obtain ⟨n, y, hx⟩ := IsPRadical.pow_mem i p x
apply_fun _ using pow_expChar_pow_inj_of_pNilradical_eq_bot M p h n
simpa only [← map_pow, ← hx] using congr($(heq) y)
variable (M)
/-- If `i : K →+* L` is `p`-radical, then for any reduced ring `M` of exponential charactistic `p`,
the map `(L →+* M) → (K →+* M)` induced by `i` is injective.
A special case of `IsPRadical.injective_comp_of_pNilradical_eq_bot`
and a generalization of `IsPurelyInseparable.injective_comp_algebraMap`. -/
theorem injective_comp [IsPRadical i p] [IsReduced M] :
Function.Injective fun f : L →+* M ↦ f.comp i :=
injective_comp_of_pNilradical_eq_bot i p <| bot_unique <|
pNilradical_le_nilradical.trans (nilradical_eq_zero M).le
/-- If `i : K →+* L` is `p`-radical, then for any perfect ring `M` of exponential charactistic `p`,
the map `(L →+* M) → (K →+* M)` induced by `i` is injective.
A special case of `IsPRadical.injective_comp_of_pNilradical_eq_bot`. -/
theorem injective_comp_of_perfect [IsPRadical i p] [PerfectRing M p] :
Function.Injective fun f : L →+* M ↦ f.comp i :=
injective_comp_of_pNilradical_eq_bot i p (PerfectRing.pNilradical_eq_bot M p)
end IsPRadical
namespace PerfectRing
variable [ExpChar K p] [PerfectRing M p] [IsPRadical i p]
/-- If `i : K →+* L` and `j : K →+* M` are ring homomorphisms of characteristic `p` rings, such that
`i` is `p`-radical, and `M` is a perfect ring, then `PerfectRing.liftAux` is well-defined. -/
theorem liftAux_apply (x : L) (n : ℕ) (y : K) (h : i y = x ^ p ^ n) :
liftAux i j p x = (iterateFrobeniusEquiv M p n).symm (j y) := by
rw [liftAux]
have h' := Classical.choose_spec (lift_aux i p x)
set n' := (Classical.choose (lift_aux i p x)).1
replace h := congr($(h.symm) ^ p ^ n')
rw [← pow_mul, mul_comm, pow_mul, ← h', ← map_pow, ← map_pow, ← sub_eq_zero, ← map_sub,
← RingHom.mem_ker] at h
obtain ⟨m, h⟩ := mem_pNilradical.1 (IsPRadical.ker_le i p h)
refine (iterateFrobeniusEquiv M p (m + n + n')).injective ?_
conv_lhs => rw [iterateFrobeniusEquiv_add_apply, RingEquiv.apply_symm_apply]
rw [add_assoc, add_comm n n', ← add_assoc,
iterateFrobeniusEquiv_add_apply (m := m + n'), RingEquiv.apply_symm_apply,
iterateFrobeniusEquiv_def, iterateFrobeniusEquiv_def,
← sub_eq_zero, ← map_pow, ← map_pow, ← map_sub,
add_comm m, add_comm m, pow_add, pow_mul, pow_add, pow_mul, ← sub_pow_expChar_pow, h, map_zero]
variable [ExpChar L p]
/-- If `i : K →+* L` and `j : K →+* M` are ring homomorphisms of characteristic `p` rings, such that
`i` is `p`-radical, and `M` is a perfect ring, then `PerfectRing.liftAux`
is a ring homomorphism. This is similar to `IsAlgClosed.lift` and `IsSepClosed.lift`. -/
def lift : L →+* M where
toFun := liftAux i j p
map_one' := by simp [liftAux_apply i j p 1 0 1 (by rw [one_pow, map_one])]
map_mul' x1 x2 := by
obtain ⟨n1, y1, h1⟩ := IsPRadical.pow_mem i p x1
obtain ⟨n2, y2, h2⟩ := IsPRadical.pow_mem i p x2
simp only; rw [liftAux_apply i j p _ _ _ h1, liftAux_apply i j p _ _ _ h2,
liftAux_apply i j p (x1 * x2) (n1 + n2) (y1 ^ p ^ n2 * y2 ^ p ^ n1) (by rw [map_mul,
map_pow, map_pow, h1, h2, ← pow_mul, ← pow_add, ← pow_mul, ← pow_add,
add_comm n2, mul_pow]),
map_mul, map_pow, map_pow, map_mul, ← iterateFrobeniusEquiv_def]
nth_rw 1 [iterateFrobeniusEquiv_symm_add_apply]
rw [RingEquiv.symm_apply_apply, add_comm n1, iterateFrobeniusEquiv_symm_add_apply,
← iterateFrobeniusEquiv_def, RingEquiv.symm_apply_apply]
map_zero' := by simp [liftAux_apply i j p 0 0 0 (by rw [pow_zero, pow_one, map_zero])]
map_add' x1 x2 := by
obtain ⟨n1, y1, h1⟩ := IsPRadical.pow_mem i p x1
obtain ⟨n2, y2, h2⟩ := IsPRadical.pow_mem i p x2
simp only; rw [liftAux_apply i j p _ _ _ h1, liftAux_apply i j p _ _ _ h2,
liftAux_apply i j p (x1 + x2) (n1 + n2) (y1 ^ p ^ n2 + y2 ^ p ^ n1) (by rw [map_add,
map_pow, map_pow, h1, h2, ← pow_mul, ← pow_add, ← pow_mul, ← pow_add,
add_comm n2, add_pow_expChar_pow]),
map_add, map_pow, map_pow, map_add, ← iterateFrobeniusEquiv_def]
nth_rw 1 [iterateFrobeniusEquiv_symm_add_apply]
rw [RingEquiv.symm_apply_apply, add_comm n1, iterateFrobeniusEquiv_symm_add_apply,
← iterateFrobeniusEquiv_def, RingEquiv.symm_apply_apply]
theorem lift_apply (x : L) (n : ℕ) (y : K) (h : i y = x ^ p ^ n) :
lift i j p x = (iterateFrobeniusEquiv M p n).symm (j y) :=
liftAux_apply i j p _ _ _ h
@[simp]
theorem lift_comp_apply (x : K) : lift i j p (i x) = j x := by
rw [lift_apply i j p _ 0 x (by rw [pow_zero, pow_one]), iterateFrobeniusEquiv_zero]; rfl
@[simp]
theorem lift_comp : (lift i j p).comp i = j := RingHom.ext (lift_comp_apply i j p)
theorem lift_self_apply [PerfectRing L p] (x : L) : lift i i p x = x := liftAux_self_apply i p x
@[simp]
theorem lift_self [PerfectRing L p] : lift i i p = RingHom.id L :=
RingHom.ext (liftAux_self_apply i p)
theorem lift_id_apply (x : K) : lift (RingHom.id K) j p x = j x := liftAux_id_apply j p x
@[simp]
theorem lift_id : lift (RingHom.id K) j p = j := RingHom.ext (liftAux_id_apply j p)
@[simp]
theorem comp_lift : lift i (f.comp i) p = f :=
IsPRadical.injective_comp_of_perfect _ i p (lift_comp i _ p)
theorem comp_lift_apply (x : L) : lift i (f.comp i) p x = f x := congr($(comp_lift i f p) x)
variable (M) in
/-- If `i : K →+* L` is a homomorphisms of characteristic `p` rings, such that
`i` is `p`-radical, and `M` is a perfect ring of characteristic `p`,
then `K →+* M` is one-to-one correspondence to
`L →+* M`, given by `PerfectRing.lift`. This is a generalization to `PerfectClosure.lift`. -/
def liftEquiv : (K →+* M) ≃ (L →+* M) where
toFun j := lift i j p
invFun f := f.comp i
left_inv f := lift_comp i f p
right_inv f := comp_lift i f p
theorem liftEquiv_apply : liftEquiv M i p j = lift i j p := rfl
theorem liftEquiv_symm_apply : (liftEquiv M i p).symm f = f.comp i := rfl
theorem liftEquiv_id_apply : liftEquiv M (RingHom.id K) p j = j :=
lift_id j p
@[simp]
theorem liftEquiv_id : liftEquiv M (RingHom.id K) p = Equiv.refl _ :=
Equiv.ext (liftEquiv_id_apply · p)
section comp
variable [ExpChar N p] [PerfectRing N p] [IsPRadical j p]
@[simp]
theorem lift_comp_lift : (lift j k p).comp (lift i j p) = lift i k p :=
IsPRadical.injective_comp_of_perfect _ i p (by ext; simp)
@[simp]
theorem lift_comp_lift_apply (x : L) : lift j k p (lift i j p x) = lift i k p x :=
congr($(lift_comp_lift i j k p) x)
theorem lift_comp_lift_apply_eq_self [PerfectRing L p] (x : L) :
lift j i p (lift i j p x) = x := by
rw [lift_comp_lift_apply, lift_self_apply]
theorem lift_comp_lift_eq_id [PerfectRing L p] :
(lift j i p).comp (lift i j p) = RingHom.id L :=
RingHom.ext (lift_comp_lift_apply_eq_self i j p)
end comp
section liftEquiv_comp
variable [ExpChar N p] [IsPRadical g p] [IsPRadical (g.comp i) p]
@[simp]
theorem lift_lift : lift g (lift i j p) p = lift (g.comp i) j p := by
refine IsPRadical.injective_comp_of_perfect _ (g.comp i) p ?_
simp_rw [← RingHom.comp_assoc _ _ (lift g _ p), lift_comp]
theorem lift_lift_apply (x : N) : lift g (lift i j p) p x = lift (g.comp i) j p x :=
congr($(lift_lift i j g p) x)
@[simp]
theorem liftEquiv_comp_apply :
liftEquiv M g p (liftEquiv M i p j) = liftEquiv M (g.comp i) p j := lift_lift i j g p
@[simp]
theorem liftEquiv_trans :
(liftEquiv M i p).trans (liftEquiv M g p) = liftEquiv M (g.comp i) p :=
Equiv.ext (liftEquiv_comp_apply i · g p)
end liftEquiv_comp
end PerfectRing
namespace IsPerfectClosure
variable [ExpChar K p] [ExpChar L p] [PerfectRing L p] [IsPerfectClosure i p] [PerfectRing M p]
[IsPerfectClosure j p]
/-- If `L` and `M` are both perfect closures of `K`, then there is a ring isomorphism `L ≃+* M`.
This is similar to `IsAlgClosure.equiv` and `IsSepClosure.equiv`. -/
def equiv : L ≃+* M where
__ := PerfectRing.lift i j p
invFun := PerfectRing.liftAux j i p
left_inv := PerfectRing.lift_comp_lift_apply_eq_self i j p
right_inv := PerfectRing.lift_comp_lift_apply_eq_self j i p
theorem equiv_toRingHom : (equiv i j p).toRingHom = PerfectRing.lift i j p := rfl
@[simp]
theorem equiv_symm : (equiv i j p).symm = equiv j i p := rfl
theorem equiv_symm_toRingHom :
(equiv i j p).symm.toRingHom = PerfectRing.lift j i p := rfl
theorem equiv_apply (x : L) (n : ℕ) (y : K) (h : i y = x ^ p ^ n) :
equiv i j p x = (iterateFrobeniusEquiv M p n).symm (j y) :=
PerfectRing.liftAux_apply i j p _ _ _ h
theorem equiv_symm_apply (x : M) (n : ℕ) (y : K) (h : j y = x ^ p ^ n) :
(equiv i j p).symm x = (iterateFrobeniusEquiv L p n).symm (i y) := by
rw [equiv_symm, equiv_apply j i p _ _ _ h]
theorem equiv_self_apply (x : L) : equiv i i p x = x :=
PerfectRing.liftAux_self_apply i p x
@[simp]
theorem equiv_self : equiv i i p = RingEquiv.refl L :=
RingEquiv.ext (equiv_self_apply i p)
@[simp]
theorem equiv_comp_apply (x : K) : equiv i j p (i x) = j x :=
PerfectRing.lift_comp_apply i j p x
@[simp]
theorem equiv_comp : RingHom.comp (equiv i j p) i = j :=
RingHom.ext (equiv_comp_apply i j p)
section comp
variable [ExpChar N p] [PerfectRing N p] [IsPerfectClosure k p]
@[simp]
theorem equiv_comp_equiv_apply (x : L) :
equiv j k p (equiv i j p x) = equiv i k p x :=
PerfectRing.lift_comp_lift_apply i j k p x
@[simp]
theorem equiv_comp_equiv : (equiv i j p).trans (equiv j k p) = equiv i k p :=
RingEquiv.ext (equiv_comp_equiv_apply i j k p)
theorem equiv_comp_equiv_apply_eq_self (x : L) :
equiv j i p (equiv i j p x) = x := by
rw [equiv_comp_equiv_apply, equiv_self_apply]
theorem equiv_comp_equiv_eq_id :
(equiv i j p).trans (equiv j i p) = RingEquiv.refl L :=
RingEquiv.ext (equiv_comp_equiv_apply_eq_self i j p)
end comp
end IsPerfectClosure
end CommRing
namespace PerfectClosure
variable [CommRing K] (p : ℕ) [Fact p.Prime] [CharP K p]
variable (K)
/-- The absolute perfect closure `PerfectClosure` is a `p`-radical extension over the base ring.
In particular, it is a perfect closure of the base ring, that is,
`IsPerfectClosure (PerfectClosure.of K p) p`. -/
instance isPRadical : IsPRadical (PerfectClosure.of K p) p where
pow_mem' x := PerfectClosure.induction_on x fun x ↦ ⟨x.1, x.2, by
rw [← iterate_frobenius, iterate_frobenius_mk K p x.1 x.2]⟩
ker_le' x h := by
rw [RingHom.mem_ker, of_apply, zero_def, mk_eq_iff] at h
obtain ⟨n, h⟩ := h
simp_rw [zero_add, ← coe_iterateFrobenius, map_zero] at h
exact mem_pNilradical.2 ⟨n, h⟩
end PerfectClosure
section Field
variable [Field K] [Field L] [Algebra K L] (p : ℕ) [ExpChar K p]
variable (K L)
/-- If `L / K` is a `p`-radical field extension, then it is purely inseparable. -/
theorem IsPRadical.isPurelyInseparable [IsPRadical (algebraMap K L) p] :
IsPurelyInseparable K L :=
(isPurelyInseparable_iff_pow_mem K p).2 (IsPRadical.pow_mem (algebraMap K L) p)
/-- If `L / K` is a purely inseparable field extension, then it is `p`-radical. In particular, if
`L` is perfect, then the (relative) perfect closure `perfectClosure K L` is a perfect closure
of `K`, that is, `IsPerfectClosure (algebraMap K (perfectClosure K L)) p`. -/
instance IsPurelyInseparable.isPRadical [IsPurelyInseparable K L] :
IsPRadical (algebraMap K L) p where
pow_mem' := (isPurelyInseparable_iff_pow_mem K p).1 ‹_›
ker_le' := (RingHom.injective_iff_ker_eq_bot _).1 (algebraMap K L).injective ▸ bot_le
end Field
end IsPerfectClosure
|
FieldTheory\IsSepClosed.lean | /-
Copyright (c) 2023 Jz Pan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jz Pan
-/
import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure
import Mathlib.FieldTheory.Galois
/-!
# Separably Closed Field
In this file we define the typeclass for separably closed fields and separable closures,
and prove some of their properties.
## Main Definitions
- `IsSepClosed k` is the typeclass saying `k` is a separably closed field, i.e. every separable
polynomial in `k` splits.
- `IsSepClosure k K` is the typeclass saying `K` is a separable closure of `k`, where `k` is a
field. This means that `K` is separably closed and separable over `k`.
- `IsSepClosed.lift` is a map from a separable extension `L` of `K`, into any separably
closed extension `M` of `K`.
- `IsSepClosure.equiv` is a proof that any two separable closures of the
same field are isomorphic.
- `IsSepClosure.isAlgClosure_of_perfectField`, `IsSepClosure.of_isAlgClosure_of_perfectField`:
if `k` is a perfect field, then its separable closure coincides with its algebraic closure.
## Tags
separable closure, separably closed
## Related
- `separableClosure`: maximal separable subextension of `K/k`, consisting of all elements of `K`
which are separable over `k`.
- `separableClosure.isSepClosure`: if `K` is a separably closed field containing `k`, then the
maximal separable subextension of `K/k` is a separable closure of `k`.
- In particular, a separable closure (`SeparableClosure`) exists.
- `Algebra.IsAlgebraic.isPurelyInseparable_of_isSepClosed`: an algebraic extension of a separably
closed field is purely inseparable.
-/
universe u v w
open Polynomial
variable (k : Type u) [Field k] (K : Type v) [Field K]
/-- Typeclass for separably closed fields.
To show `Polynomial.Splits p f` for an arbitrary ring homomorphism `f`,
see `IsSepClosed.splits_codomain` and `IsSepClosed.splits_domain`.
-/
class IsSepClosed : Prop where
splits_of_separable : ∀ p : k[X], p.Separable → (p.Splits <| RingHom.id k)
/-- An algebraically closed field is also separably closed. -/
instance IsSepClosed.of_isAlgClosed [IsAlgClosed k] : IsSepClosed k :=
⟨fun p _ ↦ IsAlgClosed.splits p⟩
variable {k} {K}
/-- Every separable polynomial splits in the field extension `f : k →+* K` if `K` is
separably closed.
See also `IsSepClosed.splits_domain` for the case where `k` is separably closed.
-/
theorem IsSepClosed.splits_codomain [IsSepClosed K] {f : k →+* K}
(p : k[X]) (h : p.Separable) : p.Splits f := by
convert IsSepClosed.splits_of_separable (p.map f) (Separable.map h); simp [splits_map_iff]
/-- Every separable polynomial splits in the field extension `f : k →+* K` if `k` is
separably closed.
See also `IsSepClosed.splits_codomain` for the case where `k` is separably closed.
-/
theorem IsSepClosed.splits_domain [IsSepClosed k] {f : k →+* K}
(p : k[X]) (h : p.Separable) : p.Splits f :=
Polynomial.splits_of_splits_id _ <| IsSepClosed.splits_of_separable _ h
namespace IsSepClosed
theorem exists_root [IsSepClosed k] (p : k[X]) (hp : p.degree ≠ 0) (hsep : p.Separable) :
∃ x, IsRoot p x :=
exists_root_of_splits _ (IsSepClosed.splits_of_separable p hsep) hp
variable (k) in
/-- A separably closed perfect field is also algebraically closed. -/
instance (priority := 100) isAlgClosed_of_perfectField [IsSepClosed k] [PerfectField k] :
IsAlgClosed k :=
IsAlgClosed.of_exists_root k fun p _ h ↦ exists_root p ((degree_pos_of_irreducible h).ne')
(PerfectField.separable_of_irreducible h)
theorem exists_pow_nat_eq [IsSepClosed k] (x : k) (n : ℕ) [hn : NeZero (n : k)] :
∃ z, z ^ n = x := by
have hn' : 0 < n := Nat.pos_of_ne_zero fun h => by
rw [h, Nat.cast_zero] at hn
exact hn.out rfl
have : degree (X ^ n - C x) ≠ 0 := by
rw [degree_X_pow_sub_C hn' x]
exact (WithBot.coe_lt_coe.2 hn').ne'
by_cases hx : x = 0
· exact ⟨0, by rw [hx, pow_eq_zero_iff hn'.ne']⟩
· obtain ⟨z, hz⟩ := exists_root _ this <| separable_X_pow_sub_C x hn.out hx
use z
simpa [eval_C, eval_X, eval_pow, eval_sub, IsRoot.def, sub_eq_zero] using hz
theorem exists_eq_mul_self [IsSepClosed k] (x : k) [h2 : NeZero (2 : k)] : ∃ z, x = z * z := by
rcases exists_pow_nat_eq x 2 with ⟨z, rfl⟩
exact ⟨z, sq z⟩
theorem roots_eq_zero_iff [IsSepClosed k] {p : k[X]} (hsep : p.Separable) :
p.roots = 0 ↔ p = Polynomial.C (p.coeff 0) := by
refine ⟨fun h => ?_, fun hp => by rw [hp, roots_C]⟩
rcases le_or_lt (degree p) 0 with hd | hd
· exact eq_C_of_degree_le_zero hd
· obtain ⟨z, hz⟩ := IsSepClosed.exists_root p hd.ne' hsep
rw [← mem_roots (ne_zero_of_degree_gt hd), h] at hz
simp at hz
theorem exists_eval₂_eq_zero [IsSepClosed K] (f : k →+* K)
(p : k[X]) (hp : p.degree ≠ 0) (hsep : p.Separable) :
∃ x, p.eval₂ f x = 0 :=
let ⟨x, hx⟩ := exists_root (p.map f) (by rwa [degree_map_eq_of_injective f.injective])
(Separable.map hsep)
⟨x, by rwa [eval₂_eq_eval_map, ← IsRoot]⟩
variable (K)
theorem exists_aeval_eq_zero [IsSepClosed K] [Algebra k K] (p : k[X])
(hp : p.degree ≠ 0) (hsep : p.Separable) : ∃ x : K, aeval x p = 0 :=
exists_eval₂_eq_zero (algebraMap k K) p hp hsep
variable (k) {K}
theorem of_exists_root (H : ∀ p : k[X], p.Monic → Irreducible p → Separable p → ∃ x, p.eval x = 0) :
IsSepClosed k := by
refine ⟨fun p hsep ↦ Or.inr ?_⟩
intro q hq hdvd
simp only [map_id] at hdvd
have hlc : IsUnit (leadingCoeff q)⁻¹ := IsUnit.inv <| Ne.isUnit <|
leadingCoeff_ne_zero.2 <| Irreducible.ne_zero hq
have hsep' : Separable (q * C (leadingCoeff q)⁻¹) :=
Separable.mul (Separable.of_dvd hsep hdvd) ((separable_C _).2 hlc)
(by simpa only [← isCoprime_mul_unit_right_right (isUnit_C.2 hlc) q 1, one_mul]
using isCoprime_one_right (x := q))
have hirr' := hq
rw [← irreducible_mul_isUnit (isUnit_C.2 hlc)] at hirr'
obtain ⟨x, hx⟩ := H (q * C (leadingCoeff q)⁻¹) (monic_mul_leadingCoeff_inv hq.ne_zero) hirr' hsep'
exact degree_mul_leadingCoeff_inv q hq.ne_zero ▸ degree_eq_one_of_irreducible_of_root hirr' hx
theorem degree_eq_one_of_irreducible [IsSepClosed k] {p : k[X]}
(hp : Irreducible p) (hsep : p.Separable) : p.degree = 1 :=
degree_eq_one_of_irreducible_of_splits hp (IsSepClosed.splits_codomain p hsep)
variable (K)
theorem algebraMap_surjective
[IsSepClosed k] [Algebra k K] [Algebra.IsSeparable k K] :
Function.Surjective (algebraMap k K) := by
refine fun x => ⟨-(minpoly k x).coeff 0, ?_⟩
have hq : (minpoly k x).leadingCoeff = 1 := minpoly.monic (Algebra.IsSeparable.isIntegral k x)
have hsep : IsSeparable k x := Algebra.IsSeparable.isSeparable k x
have h : (minpoly k x).degree = 1 :=
degree_eq_one_of_irreducible k (minpoly.irreducible (Algebra.IsSeparable.isIntegral k x)) hsep
have : aeval x (minpoly k x) = 0 := minpoly.aeval k x
rw [eq_X_add_C_of_degree_eq_one h, hq, C_1, one_mul, aeval_add, aeval_X, aeval_C,
add_eq_zero_iff_eq_neg] at this
exact (RingHom.map_neg (algebraMap k K) ((minpoly k x).coeff 0)).symm ▸ this.symm
end IsSepClosed
/-- If `k` is separably closed, `K / k` is a field extension, `L / k` is an intermediate field
which is separable, then `L` is equal to `k`. A corollary of `IsSepClosed.algebraMap_surjective`. -/
theorem IntermediateField.eq_bot_of_isSepClosed_of_isSeparable [IsSepClosed k] [Algebra k K]
(L : IntermediateField k K) [Algebra.IsSeparable k L] : L = ⊥ := bot_unique fun x hx ↦ by
obtain ⟨y, hy⟩ := IsSepClosed.algebraMap_surjective k L ⟨x, hx⟩
exact ⟨y, congr_arg (algebraMap L K) hy⟩
variable (k) (K)
/-- Typeclass for an extension being a separable closure. -/
class IsSepClosure [Algebra k K] : Prop where
sep_closed : IsSepClosed K
separable : Algebra.IsSeparable k K
/-- A separably closed field is its separable closure. -/
instance IsSepClosure.self_of_isSepClosed [IsSepClosed k] : IsSepClosure k k :=
⟨by assumption, Algebra.isSeparable_self k⟩
/-- If `K` is perfect and is a separable closure of `k`,
then it is also an algebraic closure of `k`. -/
instance (priority := 100) IsSepClosure.isAlgClosure_of_perfectField_top
[Algebra k K] [IsSepClosure k K] [PerfectField K] : IsAlgClosure k K :=
haveI : IsSepClosed K := IsSepClosure.sep_closed k
⟨inferInstance, IsSepClosure.separable.isAlgebraic⟩
/-- If `k` is perfect, `K` is a separable closure of `k`,
then it is also an algebraic closure of `k`. -/
instance (priority := 100) IsSepClosure.isAlgClosure_of_perfectField
[Algebra k K] [IsSepClosure k K] [PerfectField k] : IsAlgClosure k K :=
have halg : Algebra.IsAlgebraic k K := IsSepClosure.separable.isAlgebraic
haveI := halg.perfectField; inferInstance
/-- If `k` is perfect, `K` is an algebraic closure of `k`,
then it is also a separable closure of `k`. -/
instance (priority := 100) IsSepClosure.of_isAlgClosure_of_perfectField
[Algebra k K] [IsAlgClosure k K] [PerfectField k] : IsSepClosure k K :=
⟨haveI := IsAlgClosure.alg_closed (R := k) (K := K); inferInstance,
(IsAlgClosure.algebraic (R := k) (K := K)).isSeparable_of_perfectField⟩
variable {k} {K}
theorem isSepClosure_iff [Algebra k K] :
IsSepClosure k K ↔ IsSepClosed K ∧ Algebra.IsSeparable k K :=
⟨fun h ↦ ⟨h.1, h.2⟩, fun h ↦ ⟨h.1, h.2⟩⟩
namespace IsSepClosure
instance isSeparable [Algebra k K] [IsSepClosure k K] : Algebra.IsSeparable k K :=
IsSepClosure.separable
instance (priority := 100) isGalois [Algebra k K] [IsSepClosure k K] : IsGalois k K where
to_isSeparable := IsSepClosure.separable
to_normal.toIsAlgebraic := inferInstance
to_normal.splits' x := (IsSepClosure.sep_closed k).splits_codomain _
(Algebra.IsSeparable.isSeparable k x)
end IsSepClosure
namespace IsSepClosed
variable {K : Type u} (L : Type v) {M : Type w} [Field K] [Field L] [Algebra K L] [Field M]
[Algebra K M] [IsSepClosed M]
theorem surjective_comp_algebraMap_of_isSeparable {E : Type*}
[Field E] [Algebra K E] [Algebra L E] [IsScalarTower K L E] [Algebra.IsSeparable L E] :
Function.Surjective fun φ : E →ₐ[K] M ↦ φ.comp (IsScalarTower.toAlgHom K L E) :=
fun f ↦ IntermediateField.exists_algHom_of_splits' (E := E) f
fun s ↦ ⟨Algebra.IsSeparable.isIntegral L s,
IsSepClosed.splits_codomain _ <| Algebra.IsSeparable.isSeparable L s⟩
variable [Algebra.IsSeparable K L] {L}
/-- A (random) homomorphism from a separable extension L of K into a separably
closed extension M of K. -/
noncomputable irreducible_def lift : L →ₐ[K] M :=
Classical.choice <| IntermediateField.nonempty_algHom_of_adjoin_splits
(fun x _ ↦ ⟨Algebra.IsSeparable.isIntegral K x,
splits_codomain _ (Algebra.IsSeparable.isSeparable K x)⟩)
(IntermediateField.adjoin_univ K L)
end IsSepClosed
namespace IsSepClosure
variable (K : Type u) [Field K] (L : Type v) (M : Type w) [Field L] [Field M]
variable [Algebra K M] [IsSepClosure K M]
variable [Algebra K L] [IsSepClosure K L]
/-- A (random) isomorphism between two separable closures of `K`. -/
noncomputable def equiv : L ≃ₐ[K] M :=
-- Porting note (#10754): added to replace local instance above
haveI : IsSepClosed L := IsSepClosure.sep_closed K
haveI : IsSepClosed M := IsSepClosure.sep_closed K
AlgEquiv.ofBijective _ (Normal.toIsAlgebraic.algHom_bijective₂
(IsSepClosed.lift : L →ₐ[K] M) (IsSepClosed.lift : M →ₐ[K] L)).1
end IsSepClosure
|
FieldTheory\KrullTopology.lean | /-
Copyright (c) 2022 Sebastian Monnet. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sebastian Monnet
-/
import Mathlib.FieldTheory.Galois
import Mathlib.Topology.Algebra.FilterBasis
import Mathlib.Topology.Algebra.OpenSubgroup
import Mathlib.Tactic.ByContra
/-!
# Krull topology
We define the Krull topology on `L ≃ₐ[K] L` for an arbitrary field extension `L/K`. In order to do
this, we first define a `GroupFilterBasis` on `L ≃ₐ[K] L`, whose sets are `E.fixingSubgroup` for
all intermediate fields `E` with `E/K` finite dimensional.
## Main Definitions
- `finiteExts K L`. Given a field extension `L/K`, this is the set of intermediate fields that are
finite-dimensional over `K`.
- `fixedByFinite K L`. Given a field extension `L/K`, `fixedByFinite K L` is the set of
subsets `Gal(L/E)` of `Gal(L/K)`, where `E/K` is finite
- `galBasis K L`. Given a field extension `L/K`, this is the filter basis on `L ≃ₐ[K] L` whose
sets are `Gal(L/E)` for intermediate fields `E` with `E/K` finite.
- `galGroupBasis K L`. This is the same as `galBasis K L`, but with the added structure
that it is a group filter basis on `L ≃ₐ[K] L`, rather than just a filter basis.
- `krullTopology K L`. Given a field extension `L/K`, this is the topology on `L ≃ₐ[K] L`, induced
by the group filter basis `galGroupBasis K L`.
## Main Results
- `krullTopology_t2 K L`. For an integral field extension `L/K`, the topology `krullTopology K L`
is Hausdorff.
- `krullTopology_totallyDisconnected K L`. For an integral field extension `L/K`, the topology
`krullTopology K L` is totally disconnected.
## Notations
- In docstrings, we will write `Gal(L/E)` to denote the fixing subgroup of an intermediate field
`E`. That is, `Gal(L/E)` is the subgroup of `L ≃ₐ[K] L` consisting of automorphisms that fix
every element of `E`. In particular, we distinguish between `L ≃ₐ[E] L` and `Gal(L/E)`, since the
former is defined to be a subgroup of `L ≃ₐ[K] L`, while the latter is a group in its own right.
## Implementation Notes
- `krullTopology K L` is defined as an instance for type class inference.
-/
open scoped Pointwise
/-- Mapping intermediate fields along the identity does not change them -/
theorem IntermediateField.map_id {K L : Type*} [Field K] [Field L] [Algebra K L]
(E : IntermediateField K L) : E.map (AlgHom.id K L) = E :=
SetLike.coe_injective <| Set.image_id _
/-- Mapping a finite dimensional intermediate field along an algebra equivalence gives
a finite-dimensional intermediate field. -/
instance im_finiteDimensional {K L : Type*} [Field K] [Field L] [Algebra K L]
{E : IntermediateField K L} (σ : L ≃ₐ[K] L) [FiniteDimensional K E] :
FiniteDimensional K (E.map σ.toAlgHom) :=
LinearEquiv.finiteDimensional (IntermediateField.intermediateFieldMap σ E).toLinearEquiv
/-- Given a field extension `L/K`, `finiteExts K L` is the set of
intermediate field extensions `L/E/K` such that `E/K` is finite -/
def finiteExts (K : Type*) [Field K] (L : Type*) [Field L] [Algebra K L] :
Set (IntermediateField K L) :=
{E | FiniteDimensional K E}
/-- Given a field extension `L/K`, `fixedByFinite K L` is the set of
subsets `Gal(L/E)` of `L ≃ₐ[K] L`, where `E/K` is finite -/
def fixedByFinite (K L : Type*) [Field K] [Field L] [Algebra K L] : Set (Subgroup (L ≃ₐ[K] L)) :=
IntermediateField.fixingSubgroup '' finiteExts K L
/-- For a field extension `L/K`, the intermediate field `K` is finite-dimensional over `K` -/
theorem IntermediateField.finiteDimensional_bot (K L : Type*) [Field K] [Field L] [Algebra K L] :
FiniteDimensional K (⊥ : IntermediateField K L) :=
.of_rank_eq_one IntermediateField.rank_bot
/-- This lemma says that `Gal(L/K) = L ≃ₐ[K] L` -/
theorem IntermediateField.fixingSubgroup.bot {K L : Type*} [Field K] [Field L] [Algebra K L] :
IntermediateField.fixingSubgroup (⊥ : IntermediateField K L) = ⊤ := by
ext f
refine ⟨fun _ => Subgroup.mem_top _, fun _ => ?_⟩
rintro ⟨x, hx : x ∈ (⊥ : IntermediateField K L)⟩
rw [IntermediateField.mem_bot] at hx
rcases hx with ⟨y, rfl⟩
exact f.commutes y
/-- If `L/K` is a field extension, then we have `Gal(L/K) ∈ fixedByFinite K L` -/
theorem top_fixedByFinite {K L : Type*} [Field K] [Field L] [Algebra K L] :
⊤ ∈ fixedByFinite K L :=
⟨⊥, IntermediateField.finiteDimensional_bot K L, IntermediateField.fixingSubgroup.bot⟩
/-- If `E1` and `E2` are finite-dimensional intermediate fields, then so is their compositum.
This rephrases a result already in mathlib so that it is compatible with our type classes -/
theorem finiteDimensional_sup {K L : Type*} [Field K] [Field L] [Algebra K L]
(E1 E2 : IntermediateField K L) (_ : FiniteDimensional K E1) (_ : FiniteDimensional K E2) :
FiniteDimensional K (↥(E1 ⊔ E2)) :=
IntermediateField.finiteDimensional_sup E1 E2
/-- An element of `L ≃ₐ[K] L` is in `Gal(L/E)` if and only if it fixes every element of `E`-/
theorem IntermediateField.mem_fixingSubgroup_iff {K L : Type*} [Field K] [Field L] [Algebra K L]
(E : IntermediateField K L) (σ : L ≃ₐ[K] L) : σ ∈ E.fixingSubgroup ↔ ∀ x : L, x ∈ E → σ x = x :=
⟨fun hσ x hx => hσ ⟨x, hx⟩, fun h ⟨x, hx⟩ => h x hx⟩
/-- The map `E ↦ Gal(L/E)` is inclusion-reversing -/
theorem IntermediateField.fixingSubgroup.antimono {K L : Type*} [Field K] [Field L] [Algebra K L]
{E1 E2 : IntermediateField K L} (h12 : E1 ≤ E2) : E2.fixingSubgroup ≤ E1.fixingSubgroup := by
rintro σ hσ ⟨x, hx⟩
exact hσ ⟨x, h12 hx⟩
/-- Given a field extension `L/K`, `galBasis K L` is the filter basis on `L ≃ₐ[K] L` whose sets
are `Gal(L/E)` for intermediate fields `E` with `E/K` finite dimensional -/
def galBasis (K L : Type*) [Field K] [Field L] [Algebra K L] : FilterBasis (L ≃ₐ[K] L) where
sets := (fun g => g.carrier) '' fixedByFinite K L
nonempty := ⟨⊤, ⊤, top_fixedByFinite, rfl⟩
inter_sets := by
rintro X Y ⟨H1, ⟨E1, h_E1, rfl⟩, rfl⟩ ⟨H2, ⟨E2, h_E2, rfl⟩, rfl⟩
use (IntermediateField.fixingSubgroup (E1 ⊔ E2)).carrier
refine ⟨⟨_, ⟨_, finiteDimensional_sup E1 E2 h_E1 h_E2, rfl⟩, rfl⟩, ?_⟩
rw [Set.subset_inter_iff]
exact
⟨IntermediateField.fixingSubgroup.antimono le_sup_left,
IntermediateField.fixingSubgroup.antimono le_sup_right⟩
/-- A subset of `L ≃ₐ[K] L` is a member of `galBasis K L` if and only if it is the underlying set
of `Gal(L/E)` for some finite subextension `E/K`-/
theorem mem_galBasis_iff (K L : Type*) [Field K] [Field L] [Algebra K L] (U : Set (L ≃ₐ[K] L)) :
U ∈ galBasis K L ↔ U ∈ (fun g => g.carrier) '' fixedByFinite K L :=
Iff.rfl
/-- For a field extension `L/K`, `galGroupBasis K L` is the group filter basis on `L ≃ₐ[K] L`
whose sets are `Gal(L/E)` for finite subextensions `E/K` -/
def galGroupBasis (K L : Type*) [Field K] [Field L] [Algebra K L] :
GroupFilterBasis (L ≃ₐ[K] L) where
toFilterBasis := galBasis K L
one' := fun ⟨H, _, h2⟩ => h2 ▸ H.one_mem
mul' {U} hU :=
⟨U, hU, by
rcases hU with ⟨H, _, rfl⟩
rintro x ⟨a, haH, b, hbH, rfl⟩
exact H.mul_mem haH hbH⟩
inv' {U} hU :=
⟨U, hU, by
rcases hU with ⟨H, _, rfl⟩
exact fun _ => H.inv_mem'⟩
conj' := by
rintro σ U ⟨H, ⟨E, hE, rfl⟩, rfl⟩
let F : IntermediateField K L := E.map σ.symm.toAlgHom
refine ⟨F.fixingSubgroup.carrier, ⟨⟨F.fixingSubgroup, ⟨F, ?_, rfl⟩, rfl⟩, fun g hg => ?_⟩⟩
· have : FiniteDimensional K E := hE
apply im_finiteDimensional σ.symm
change σ * g * σ⁻¹ ∈ E.fixingSubgroup
rw [IntermediateField.mem_fixingSubgroup_iff]
intro x hx
change σ (g (σ⁻¹ x)) = x
have h_in_F : σ⁻¹ x ∈ F := ⟨x, hx, by dsimp; rw [← AlgEquiv.invFun_eq_symm]; rfl⟩
have h_g_fix : g (σ⁻¹ x) = σ⁻¹ x := by
rw [Subgroup.mem_carrier, IntermediateField.mem_fixingSubgroup_iff F g] at hg
exact hg (σ⁻¹ x) h_in_F
rw [h_g_fix]
change σ (σ⁻¹ x) = x
exact AlgEquiv.apply_symm_apply σ x
/-- For a field extension `L/K`, `krullTopology K L` is the topological space structure on
`L ≃ₐ[K] L` induced by the group filter basis `galGroupBasis K L` -/
instance krullTopology (K L : Type*) [Field K] [Field L] [Algebra K L] :
TopologicalSpace (L ≃ₐ[K] L) :=
GroupFilterBasis.topology (galGroupBasis K L)
/-- For a field extension `L/K`, the Krull topology on `L ≃ₐ[K] L` makes it a topological group. -/
instance (K L : Type*) [Field K] [Field L] [Algebra K L] : TopologicalGroup (L ≃ₐ[K] L) :=
GroupFilterBasis.isTopologicalGroup (galGroupBasis K L)
section KrullT2
open scoped Topology Filter
/-- Let `L/E/K` be a tower of fields with `E/K` finite. Then `Gal(L/E)` is an open subgroup of
`L ≃ₐ[K] L`. -/
theorem IntermediateField.fixingSubgroup_isOpen {K L : Type*} [Field K] [Field L] [Algebra K L]
(E : IntermediateField K L) [FiniteDimensional K E] :
IsOpen (E.fixingSubgroup : Set (L ≃ₐ[K] L)) := by
have h_basis : E.fixingSubgroup.carrier ∈ galGroupBasis K L :=
⟨E.fixingSubgroup, ⟨E, ‹_›, rfl⟩, rfl⟩
have h_nhd := GroupFilterBasis.mem_nhds_one (galGroupBasis K L) h_basis
exact Subgroup.isOpen_of_mem_nhds _ h_nhd
/-- Given a tower of fields `L/E/K`, with `E/K` finite, the subgroup `Gal(L/E) ≤ L ≃ₐ[K] L` is
closed. -/
theorem IntermediateField.fixingSubgroup_isClosed {K L : Type*} [Field K] [Field L] [Algebra K L]
(E : IntermediateField K L) [FiniteDimensional K E] :
IsClosed (E.fixingSubgroup : Set (L ≃ₐ[K] L)) :=
OpenSubgroup.isClosed ⟨E.fixingSubgroup, E.fixingSubgroup_isOpen⟩
/-- If `L/K` is an algebraic extension, then the Krull topology on `L ≃ₐ[K] L` is Hausdorff. -/
theorem krullTopology_t2 {K L : Type*} [Field K] [Field L] [Algebra K L]
[Algebra.IsIntegral K L] : T2Space (L ≃ₐ[K] L) :=
{ t2 := fun f g hfg => by
let φ := f⁻¹ * g
cases' DFunLike.exists_ne hfg with x hx
have hφx : φ x ≠ x := by
apply ne_of_apply_ne f
change f (f.symm (g x)) ≠ f x
rw [AlgEquiv.apply_symm_apply f (g x), ne_comm]
exact hx
let E : IntermediateField K L := IntermediateField.adjoin K {x}
let h_findim : FiniteDimensional K E := IntermediateField.adjoin.finiteDimensional
(Algebra.IsIntegral.isIntegral x)
let H := E.fixingSubgroup
have h_basis : (H : Set (L ≃ₐ[K] L)) ∈ galGroupBasis K L := ⟨H, ⟨E, ⟨h_findim, rfl⟩⟩, rfl⟩
have h_nhd := GroupFilterBasis.mem_nhds_one (galGroupBasis K L) h_basis
rw [mem_nhds_iff] at h_nhd
rcases h_nhd with ⟨W, hWH, hW_open, hW_1⟩
refine ⟨f • W, g • W,
⟨hW_open.leftCoset f, hW_open.leftCoset g, ⟨1, hW_1, mul_one _⟩, ⟨1, hW_1, mul_one _⟩, ?_⟩⟩
rw [Set.disjoint_left]
rintro σ ⟨w1, hw1, h⟩ ⟨w2, hw2, rfl⟩
dsimp at h
rw [eq_inv_mul_iff_mul_eq.symm, ← mul_assoc, mul_inv_eq_iff_eq_mul.symm] at h
have h_in_H : w1 * w2⁻¹ ∈ H := H.mul_mem (hWH hw1) (H.inv_mem (hWH hw2))
rw [h] at h_in_H
change φ ∈ E.fixingSubgroup at h_in_H
rw [IntermediateField.mem_fixingSubgroup_iff] at h_in_H
specialize h_in_H x
have hxE : x ∈ E := by
apply IntermediateField.subset_adjoin
apply Set.mem_singleton
exact hφx (h_in_H hxE) }
end KrullT2
section TotallyDisconnected
/-- If `L/K` is an algebraic field extension, then the Krull topology on `L ≃ₐ[K] L` is
totally disconnected. -/
theorem krullTopology_totallyDisconnected {K L : Type*} [Field K] [Field L] [Algebra K L]
[Algebra.IsIntegral K L] : IsTotallyDisconnected (Set.univ : Set (L ≃ₐ[K] L)) := by
apply isTotallyDisconnected_of_isClopen_set
intro σ τ h_diff
have hστ : σ⁻¹ * τ ≠ 1 := by rwa [Ne, inv_mul_eq_one]
rcases DFunLike.exists_ne hστ with ⟨x, hx : (σ⁻¹ * τ) x ≠ x⟩
let E := IntermediateField.adjoin K ({x} : Set L)
haveI := IntermediateField.adjoin.finiteDimensional
(Algebra.IsIntegral.isIntegral (R := K) x)
refine ⟨σ • E.fixingSubgroup,
⟨E.fixingSubgroup_isClosed.leftCoset σ, E.fixingSubgroup_isOpen.leftCoset σ⟩,
⟨1, E.fixingSubgroup.one_mem', mul_one σ⟩, ?_⟩
simp only [mem_leftCoset_iff, SetLike.mem_coe, IntermediateField.mem_fixingSubgroup_iff,
not_forall]
exact ⟨x, IntermediateField.mem_adjoin_simple_self K x, hx⟩
end TotallyDisconnected
@[simp] lemma IntermediateField.fixingSubgroup_top (K L : Type*) [Field K] [Field L] [Algebra K L] :
IntermediateField.fixingSubgroup (⊤ : IntermediateField K L) = ⊥ := by
ext
simp [mem_fixingSubgroup_iff, DFunLike.ext_iff]
@[simp] lemma IntermediateField.fixingSubgroup_bot (K L : Type*) [Field K] [Field L] [Algebra K L] :
IntermediateField.fixingSubgroup (⊥ : IntermediateField K L) = ⊤ := by
ext
simp [mem_fixingSubgroup_iff, mem_bot]
instance krullTopology_discreteTopology_of_finiteDimensional (K L : Type) [Field K] [Field L]
[Algebra K L] [FiniteDimensional K L] : DiscreteTopology (L ≃ₐ[K] L) := by
rw [discreteTopology_iff_isOpen_singleton_one]
change IsOpen (⊥ : Subgroup (L ≃ₐ[K] L))
rw [← IntermediateField.fixingSubgroup_top]
exact IntermediateField.fixingSubgroup_isOpen ⊤
|
FieldTheory\KummerExtension.lean | /-
Copyright (c) 2023 Andrew Yang, Patrick Lutz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.RingTheory.RootsOfUnity.Basic
import Mathlib.RingTheory.AdjoinRoot
import Mathlib.FieldTheory.Galois
import Mathlib.LinearAlgebra.Eigenspace.Minpoly
import Mathlib.RingTheory.Norm.Basic
/-!
# Kummer Extensions
## Main result
- `isCyclic_tfae`:
Suppose `L/K` is a finite extension of dimension `n`, and `K` contains all `n`-th roots of unity.
Then `L/K` is cyclic iff
`L` is a splitting field of some irreducible polynomial of the form `Xⁿ - a : K[X]` iff
`L = K[α]` for some `αⁿ ∈ K`.
- `autEquivRootsOfUnity`:
Given an instance `IsSplittingField K L (X ^ n - C a)`
(perhaps via `isSplittingField_X_pow_sub_C_of_root_adjoin_eq_top`),
then the galois group is isomorphic to `rootsOfUnity n K`, by sending
`σ ↦ σ α / α` for `α ^ n = a`, and the inverse is given by `μ ↦ (α ↦ μ • α)`.
- `autEquivZmod`:
Furthermore, given an explicit choice `ζ` of a primitive `n`-th root of unity, the galois group is
then isomorphic to `Multiplicative (ZMod n)` whose inverse is given by
`i ↦ (α ↦ ζⁱ • α)`.
## Other results
Criteria for `X ^ n - C a` to be irreducible is given:
- `X_pow_sub_C_irreducible_iff_of_prime`:
For `n = p` a prime, `X ^ n - C a` is irreducible iff `a` is not a `p`-power.
- `X_pow_sub_C_irreducible_iff_of_prime_pow`:
For `n = p ^ k` an odd prime power, `X ^ n - C a` is irreducible iff `a` is not a `p`-power.
- `X_pow_sub_C_irreducible_iff_forall_prime_of_odd`:
For `n` odd, `X ^ n - C a` is irreducible iff `a` is not a `p`-power for all prime `p ∣ n`.
- `X_pow_sub_C_irreducible_iff_of_odd`:
For `n` odd, `X ^ n - C a` is irreducible iff `a` is not a `d`-power for `d ∣ n` and `d ≠ 1`.
TODO: criteria for even `n`. See [serge_lang_algebra] VI,§9.
-/
universe u
variable {K : Type u} [Field K]
open Polynomial IntermediateField AdjoinRoot
section Splits
lemma root_X_pow_sub_C_pow (n : ℕ) (a : K) :
(AdjoinRoot.root (X ^ n - C a)) ^ n = AdjoinRoot.of _ a := by
rw [← sub_eq_zero, ← AdjoinRoot.eval₂_root, eval₂_sub, eval₂_C, eval₂_pow, eval₂_X]
lemma root_X_pow_sub_C_ne_zero {n : ℕ} (hn : 1 < n) (a : K) :
(AdjoinRoot.root (X ^ n - C a)) ≠ 0 :=
mk_ne_zero_of_natDegree_lt (monic_X_pow_sub_C _ (Nat.not_eq_zero_of_lt hn))
X_ne_zero <| by rwa [natDegree_X_pow_sub_C, natDegree_X]
lemma root_X_pow_sub_C_ne_zero' {n : ℕ} {a : K} (hn : 0 < n) (ha : a ≠ 0) :
(AdjoinRoot.root (X ^ n - C a)) ≠ 0 := by
obtain (rfl|hn) := (Nat.succ_le_iff.mpr hn).eq_or_lt
· rw [← Nat.one_eq_succ_zero, pow_one]
intro e
refine mk_ne_zero_of_natDegree_lt (monic_X_sub_C a) (C_ne_zero.mpr ha) (by simp) ?_
trans AdjoinRoot.mk (X - C a) (X - (X - C a))
· rw [sub_sub_cancel]
· rw [map_sub, mk_self, sub_zero, mk_X, e]
· exact root_X_pow_sub_C_ne_zero hn a
theorem X_pow_sub_C_splits_of_isPrimitiveRoot
{n : ℕ} {ζ : K} (hζ : IsPrimitiveRoot ζ n) {α a : K} (e : α ^ n = a) :
(X ^ n - C a).Splits (RingHom.id _) := by
cases n.eq_zero_or_pos with
| inl hn =>
rw [hn, pow_zero, ← C.map_one, ← map_sub]
exact splits_C _ _
| inr hn =>
rw [splits_iff_card_roots, ← nthRoots, hζ.card_nthRoots, natDegree_X_pow_sub_C, if_pos ⟨α, e⟩]
-- make this private, as we only use it to prove a strictly more general version
private
theorem X_pow_sub_C_eq_prod'
{n : ℕ} {ζ : K} (hζ : IsPrimitiveRoot ζ n) {α a : K} (hn : 0 < n) (e : α ^ n = a) :
(X ^ n - C a) = ∏ i ∈ Finset.range n, (X - C (ζ ^ i * α)) := by
rw [eq_prod_roots_of_monic_of_splits_id (monic_X_pow_sub_C _ (Nat.pos_iff_ne_zero.mp hn))
(X_pow_sub_C_splits_of_isPrimitiveRoot hζ e), ← nthRoots, hζ.nthRoots_eq e, Multiset.map_map]
rfl
lemma X_pow_sub_C_eq_prod {R : Type*} [CommRing R] [IsDomain R]
{n : ℕ} {ζ : R} (hζ : IsPrimitiveRoot ζ n) {α a : R} (hn : 0 < n) (e : α ^ n = a) :
(X ^ n - C a) = ∏ i ∈ Finset.range n, (X - C (ζ ^ i * α)) := by
let K := FractionRing R
let i := algebraMap R K
have h := NoZeroSMulDivisors.algebraMap_injective R K
apply_fun Polynomial.map i using map_injective i h
simpa only [Polynomial.map_sub, Polynomial.map_pow, map_X, map_C, map_mul, map_pow,
Polynomial.map_prod, Polynomial.map_mul]
using X_pow_sub_C_eq_prod' (hζ.map_of_injective h) hn <| map_pow i α n ▸ congrArg i e
end Splits
section Irreducible
lemma ne_zero_of_irreducible_X_pow_sub_C {n : ℕ} {a : K} (H : Irreducible (X ^ n - C a)) :
n ≠ 0 := by
rintro rfl
rw [pow_zero, ← C.map_one, ← map_sub] at H
exact not_irreducible_C _ H
lemma ne_zero_of_irreducible_X_pow_sub_C' {n : ℕ} (hn : n ≠ 1) {a : K}
(H : Irreducible (X ^ n - C a)) : a ≠ 0 := by
rintro rfl
rw [map_zero, sub_zero] at H
exact not_irreducible_pow hn H
lemma root_X_pow_sub_C_eq_zero_iff {n : ℕ} {a : K} (H : Irreducible (X ^ n - C a)) :
(AdjoinRoot.root (X ^ n - C a)) = 0 ↔ a = 0 := by
have hn := Nat.pos_iff_ne_zero.mpr (ne_zero_of_irreducible_X_pow_sub_C H)
refine ⟨not_imp_not.mp (root_X_pow_sub_C_ne_zero' hn), ?_⟩
rintro rfl
have := not_imp_not.mp (fun hn ↦ ne_zero_of_irreducible_X_pow_sub_C' hn H) rfl
rw [this, pow_one, map_zero, sub_zero, ← mk_X, mk_self]
lemma root_X_pow_sub_C_ne_zero_iff {n : ℕ} {a : K} (H : Irreducible (X ^ n - C a)) :
(AdjoinRoot.root (X ^ n - C a)) ≠ 0 ↔ a ≠ 0 :=
(root_X_pow_sub_C_eq_zero_iff H).not
theorem pow_ne_of_irreducible_X_pow_sub_C {n : ℕ} {a : K}
(H : Irreducible (X ^ n - C a)) {m : ℕ} (hm : m ∣ n) (hm' : m ≠ 1) (b : K) : b ^ m ≠ a := by
have hn : n ≠ 0 := fun e ↦ not_irreducible_C
(1 - a) (by simpa only [e, pow_zero, ← C.map_one, ← map_sub] using H)
obtain ⟨k, rfl⟩ := hm
rintro rfl
obtain ⟨q, hq⟩ := sub_dvd_pow_sub_pow (X ^ k) (C b) m
rw [mul_comm, pow_mul, map_pow, hq] at H
have : degree q = 0 := by
simpa [isUnit_iff_degree_eq_zero, degree_X_pow_sub_C,
Nat.pos_iff_ne_zero, (mul_ne_zero_iff.mp hn).2] using H.2 _ q rfl
apply_fun degree at hq
simp only [this, ← pow_mul, mul_comm k m, degree_X_pow_sub_C, Nat.pos_iff_ne_zero.mpr hn,
Nat.pos_iff_ne_zero.mpr (mul_ne_zero_iff.mp hn).2, degree_mul, ← map_pow, add_zero,
Nat.cast_injective.eq_iff] at hq
exact hm' ((mul_eq_right₀ (mul_ne_zero_iff.mp hn).2).mp hq)
theorem X_pow_sub_C_irreducible_of_prime {p : ℕ} (hp : p.Prime) {a : K} (ha : ∀ b : K, b ^ p ≠ a) :
Irreducible (X ^ p - C a) := by
-- First of all, We may find an irreducible factor `g` of `X ^ p - C a`.
have : ¬ IsUnit (X ^ p - C a) := by
rw [Polynomial.isUnit_iff_degree_eq_zero, degree_X_pow_sub_C hp.pos, Nat.cast_eq_zero]
exact hp.ne_zero
have ⟨g, hg, hg'⟩ := WfDvdMonoid.exists_irreducible_factor this (X_pow_sub_C_ne_zero hp.pos a)
-- It suffices to show that `deg g = p`.
suffices natDegree g = p from (associated_of_dvd_of_natDegree_le hg'
(X_pow_sub_C_ne_zero hp.pos a) (this.trans natDegree_X_pow_sub_C.symm).ge).irreducible hg
-- Suppose `deg g ≠ p`.
by_contra h
have : Fact (Irreducible g) := ⟨hg⟩
-- Let `r` be a root of `g`, then `N_K(r) ^ p = N_K(r ^ p) = N_K(a) = a ^ (deg g)`.
have key : (Algebra.norm K (AdjoinRoot.root g)) ^ p = a ^ g.natDegree := by
have := eval₂_eq_zero_of_dvd_of_eval₂_eq_zero _ _ hg' (AdjoinRoot.eval₂_root g)
rw [eval₂_sub, eval₂_pow, eval₂_C, eval₂_X, sub_eq_zero] at this
rw [← map_pow, this, ← AdjoinRoot.algebraMap_eq, Algebra.norm_algebraMap,
← finrank_top', ← IntermediateField.adjoin_root_eq_top g,
IntermediateField.adjoin.finrank,
AdjoinRoot.minpoly_root hg.ne_zero, natDegree_mul_C]
· simpa using hg.ne_zero
· exact AdjoinRoot.isIntegral_root hg.ne_zero
-- Since `a ^ (deg g)` is a `p`-power, and `p` is coprime to `deg g`, we conclude that `a` is
-- also a `p`-power, contradicting the hypothesis
have : p.Coprime (natDegree g) := hp.coprime_iff_not_dvd.mpr (fun e ↦ h (((natDegree_le_of_dvd hg'
(X_pow_sub_C_ne_zero hp.pos a)).trans_eq natDegree_X_pow_sub_C).antisymm (Nat.le_of_dvd
(natDegree_pos_iff_degree_pos.mpr <| Polynomial.degree_pos_of_irreducible hg) e)))
exact ha _ ((pow_mem_range_pow_of_coprime this.symm a).mp ⟨_, key⟩).choose_spec
theorem X_pow_sub_C_irreducible_iff_of_prime {p : ℕ} (hp : p.Prime) {a : K} :
Irreducible (X ^ p - C a) ↔ ∀ b, b ^ p ≠ a :=
⟨(pow_ne_of_irreducible_X_pow_sub_C · dvd_rfl hp.ne_one), X_pow_sub_C_irreducible_of_prime hp⟩
theorem X_pow_mul_sub_C_irreducible
{n m : ℕ} {a : K} (hm : Irreducible (X ^ m - C a))
(hn : ∀ (E : Type u) [Field E] [Algebra K E] (x : E) (hx : minpoly K x = X ^ m - C a),
Irreducible (X ^ n - C (AdjoinSimple.gen K x))) :
Irreducible (X ^ (n * m) - C a) := by
have hm' : m ≠ 0 := by
rintro rfl
rw [pow_zero, ← C.map_one, ← map_sub] at hm
exact not_irreducible_C _ hm
simpa [pow_mul] using irreducible_comp (monic_X_pow_sub_C a hm') (monic_X_pow n) hm
(by simpa only [Polynomial.map_pow, map_X] using hn)
-- TODO: generalize to even `n`
theorem X_pow_sub_C_irreducible_of_odd
{n : ℕ} (hn : Odd n) {a : K} (ha : ∀ p : ℕ, p.Prime → p ∣ n → ∀ b : K, b ^ p ≠ a) :
Irreducible (X ^ n - C a) := by
induction n using induction_on_primes generalizing K a with
| h₀ => simp at hn
| h₁ => simpa using irreducible_X_sub_C a
| h p n hp IH =>
rw [mul_comm]
apply X_pow_mul_sub_C_irreducible
(X_pow_sub_C_irreducible_of_prime hp (ha p hp (dvd_mul_right _ _)))
intro E _ _ x hx
have : IsIntegral K x := not_not.mp fun h ↦ by
simpa only [degree_zero, degree_X_pow_sub_C hp.pos,
WithBot.natCast_ne_bot] using congr_arg degree (hx.symm.trans (dif_neg h))
apply IH (Nat.odd_mul.mp hn).2
intros q hq hqn b hb
apply ha q hq (dvd_mul_of_dvd_right hqn p) (Algebra.norm _ b)
rw [← map_pow, hb, ← adjoin.powerBasis_gen this,
Algebra.PowerBasis.norm_gen_eq_coeff_zero_minpoly]
simp [minpoly_gen, hx, hp.ne_zero.symm, (Nat.odd_mul.mp hn).1.neg_pow]
theorem X_pow_sub_C_irreducible_iff_forall_prime_of_odd {n : ℕ} (hn : Odd n) {a : K} :
Irreducible (X ^ n - C a) ↔ (∀ p : ℕ, p.Prime → p ∣ n → ∀ b : K, b ^ p ≠ a) :=
⟨fun e _ hp hpn ↦ pow_ne_of_irreducible_X_pow_sub_C e hpn hp.ne_one,
X_pow_sub_C_irreducible_of_odd hn⟩
theorem X_pow_sub_C_irreducible_iff_of_odd {n : ℕ} (hn : Odd n) {a : K} :
Irreducible (X ^ n - C a) ↔ (∀ d, d ∣ n → d ≠ 1 → ∀ b : K, b ^ d ≠ a) :=
⟨fun e _ ↦ pow_ne_of_irreducible_X_pow_sub_C e,
fun H ↦ X_pow_sub_C_irreducible_of_odd hn fun p hp hpn ↦ (H p hpn hp.ne_one)⟩
-- TODO: generalize to `p = 2`
theorem X_pow_sub_C_irreducible_of_prime_pow
{p : ℕ} (hp : p.Prime) (hp' : p ≠ 2) (n : ℕ) {a : K} (ha : ∀ b : K, b ^ p ≠ a) :
Irreducible (X ^ (p ^ n) - C a) := by
apply X_pow_sub_C_irreducible_of_odd (hp.odd_of_ne_two hp').pow
intros q hq hq'
simpa [(Nat.prime_dvd_prime_iff_eq hq hp).mp (hq.dvd_of_dvd_pow hq')] using ha
theorem X_pow_sub_C_irreducible_iff_of_prime_pow
{p : ℕ} (hp : p.Prime) (hp' : p ≠ 2) {n} (hn : n ≠ 0) {a : K} :
Irreducible (X ^ p ^ n - C a) ↔ ∀ b, b ^ p ≠ a :=
⟨(pow_ne_of_irreducible_X_pow_sub_C · (dvd_pow dvd_rfl hn) hp.ne_one),
X_pow_sub_C_irreducible_of_prime_pow hp hp' n⟩
end Irreducible
/-!
### Galois Group of `K[n√a]`
We first develop the theory for a specific `K[n√a] := AdjoinRoot (X ^ n - C a)`.
The main result is the description of the galois group: `autAdjoinRootXPowSubCEquiv`.
-/
variable {n : ℕ} (hζ : (primitiveRoots n K).Nonempty) (hn : 0 < n)
variable (a : K) (H : Irreducible (X ^ n - C a))
set_option quotPrecheck false in
scoped[KummerExtension] notation3 "K[" n "√" a "]" => AdjoinRoot (Polynomial.X ^ n - Polynomial.C a)
attribute [nolint docBlame] KummerExtension.«termK[_√_]»
open scoped KummerExtension
section AdjoinRoot
/-- Also see `Polynomial.separable_X_pow_sub_C_unit` -/
theorem Polynomial.separable_X_pow_sub_C_of_irreducible : (X ^ n - C a).Separable := by
letI := Fact.mk H
letI : Algebra K K[n√a] := inferInstance
have hn := Nat.pos_iff_ne_zero.mpr (ne_zero_of_irreducible_X_pow_sub_C H)
by_cases hn' : n = 1
· rw [hn', pow_one]; exact separable_X_sub_C
have ⟨ζ, hζ⟩ := hζ
rw [mem_primitiveRoots (Nat.pos_of_ne_zero <| ne_zero_of_irreducible_X_pow_sub_C H)] at hζ
rw [← separable_map (algebraMap K K[n√a]), Polynomial.map_sub, Polynomial.map_pow, map_C, map_X,
AdjoinRoot.algebraMap_eq,
X_pow_sub_C_eq_prod (hζ.map_of_injective (algebraMap K _).injective) hn
(root_X_pow_sub_C_pow n a), separable_prod_X_sub_C_iff']
exact (hζ.map_of_injective (algebraMap K K[n√a]).injective).injOn_pow_mul
(root_X_pow_sub_C_ne_zero (lt_of_le_of_ne (show 1 ≤ n from hn) (Ne.symm hn')) _)
/-- The natural embedding of the roots of unity of `K` into `Gal(K[ⁿ√a]/K)`, by sending
`η ↦ (ⁿ√a ↦ η • ⁿ√a)`. Also see `autAdjoinRootXPowSubC` for the `AlgEquiv` version. -/
noncomputable
def autAdjoinRootXPowSubCHom :
rootsOfUnity ⟨n, hn⟩ K →* (K[n√a] →ₐ[K] K[n√a]) where
toFun := fun η ↦ liftHom (X ^ n - C a) (((η : Kˣ) : K) • (root _) : K[n√a]) <| by
have := (mem_rootsOfUnity' _ _).mp η.prop
dsimp at this
rw [map_sub, map_pow, aeval_C, aeval_X, Algebra.smul_def, mul_pow, root_X_pow_sub_C_pow,
AdjoinRoot.algebraMap_eq, ← map_pow, this, map_one, one_mul, sub_self]
map_one' := algHom_ext <| by simp
map_mul' := fun ε η ↦ algHom_ext <| by simp [mul_smul, smul_comm ((ε : Kˣ) : K)]
/-- The natural embedding of the roots of unity of `K` into `Gal(K[ⁿ√a]/K)`, by sending
`η ↦ (ⁿ√a ↦ η • ⁿ√a)`. This is an isomorphism when `K` contains a primitive root of unity.
See `autAdjoinRootXPowSubCEquiv`. -/
noncomputable
def autAdjoinRootXPowSubC :
rootsOfUnity ⟨n, hn⟩ K →* (K[n√a] ≃ₐ[K] K[n√a]) :=
(AlgEquiv.algHomUnitsEquiv _ _).toMonoidHom.comp (autAdjoinRootXPowSubCHom hn a).toHomUnits
lemma autAdjoinRootXPowSubC_root (η) :
autAdjoinRootXPowSubC hn a η (root _) = ((η : Kˣ) : K) • root _ := by
dsimp [autAdjoinRootXPowSubC, autAdjoinRootXPowSubCHom, AlgEquiv.algHomUnitsEquiv]
apply liftHom_root
variable {a}
/-- The inverse function of `autAdjoinRootXPowSubC` if `K` has all roots of unity.
See `autAdjoinRootXPowSubCEquiv`. -/
noncomputable
def AdjoinRootXPowSubCEquivToRootsOfUnity (σ : K[n√a] ≃ₐ[K] K[n√a]) :
rootsOfUnity ⟨n, hn⟩ K :=
letI := Fact.mk H
letI : IsDomain K[n√a] := inferInstance
letI := Classical.decEq K
(rootsOfUnityEquivOfPrimitiveRoots (n := ⟨n, hn⟩) (algebraMap K K[n√a]).injective hζ).symm
(rootsOfUnity.mkOfPowEq (if a = 0 then 1 else σ (root _) / root _) (by
-- The if is needed in case `n = 1` and `a = 0` and `K[n√a] = K`.
split
· exact one_pow _
rw [div_pow, ← map_pow]
simp only [PNat.mk_coe, root_X_pow_sub_C_pow, ← AdjoinRoot.algebraMap_eq, AlgEquiv.commutes]
rw [div_self]
rwa [Ne, map_eq_zero_iff _ (algebraMap K _).injective]))
/-- The equivalence between the roots of unity of `K` and `Gal(K[ⁿ√a]/K)`. -/
noncomputable
def autAdjoinRootXPowSubCEquiv :
rootsOfUnity ⟨n, hn⟩ K ≃* (K[n√a] ≃ₐ[K] K[n√a]) where
__ := autAdjoinRootXPowSubC hn a
invFun := AdjoinRootXPowSubCEquivToRootsOfUnity hζ hn H
left_inv := by
intro η
have := Fact.mk H
have : IsDomain K[n√a] := inferInstance
letI : Algebra K K[n√a] := inferInstance
apply (rootsOfUnityEquivOfPrimitiveRoots
(n := ⟨n, hn⟩) (algebraMap K K[n√a]).injective hζ).injective
ext
simp only [AdjoinRoot.algebraMap_eq, OneHom.toFun_eq_coe, MonoidHom.toOneHom_coe,
autAdjoinRootXPowSubC_root, Algebra.smul_def, ne_eq, MulEquiv.apply_symm_apply,
rootsOfUnity.val_mkOfPowEq_coe, val_rootsOfUnityEquivOfPrimitiveRoots_apply_coe,
AdjoinRootXPowSubCEquivToRootsOfUnity]
split_ifs with h
· obtain rfl := not_imp_not.mp (fun hn ↦ ne_zero_of_irreducible_X_pow_sub_C' hn H) h
have : (η : Kˣ) = 1 := (pow_one _).symm.trans η.prop
simp only [PNat.mk_one, this, Units.val_one, map_one]
· exact mul_div_cancel_right₀ _ (root_X_pow_sub_C_ne_zero' hn h)
right_inv := by
intro e
have := Fact.mk H
letI : Algebra K K[n√a] := inferInstance
apply AlgEquiv.coe_algHom_injective
apply AdjoinRoot.algHom_ext
simp only [AdjoinRoot.algebraMap_eq, OneHom.toFun_eq_coe, MonoidHom.toOneHom_coe,
AlgHom.coe_coe, autAdjoinRootXPowSubC_root, Algebra.smul_def, PNat.mk_coe,
AdjoinRootXPowSubCEquivToRootsOfUnity]
rw [rootsOfUnityEquivOfPrimitiveRoots_symm_apply, rootsOfUnity.val_mkOfPowEq_coe]
split_ifs with h
· obtain rfl := not_imp_not.mp (fun hn ↦ ne_zero_of_irreducible_X_pow_sub_C' hn H) h
rw [(pow_one _).symm.trans (root_X_pow_sub_C_pow 1 a), one_mul,
← AdjoinRoot.algebraMap_eq, AlgEquiv.commutes]
· refine div_mul_cancel₀ _ (root_X_pow_sub_C_ne_zero' hn h)
lemma autAdjoinRootXPowSubCEquiv_root (η) :
autAdjoinRootXPowSubCEquiv hζ hn H η (root _) = ((η : Kˣ) : K) • root _ :=
autAdjoinRootXPowSubC_root hn a η
set_option tactic.skipAssignedInstances false in
lemma autAdjoinRootXPowSubCEquiv_symm_smul (σ) :
((autAdjoinRootXPowSubCEquiv hζ hn H).symm σ : Kˣ) • (root _ : K[n√a]) = σ (root _) := by
have := Fact.mk H
simp only [autAdjoinRootXPowSubCEquiv, OneHom.toFun_eq_coe, MonoidHom.toOneHom_coe,
MulEquiv.symm_mk, MulEquiv.coe_mk, Equiv.coe_fn_symm_mk, AdjoinRootXPowSubCEquivToRootsOfUnity,
AdjoinRoot.algebraMap_eq, Units.smul_def, Algebra.smul_def,
rootsOfUnityEquivOfPrimitiveRoots_symm_apply, rootsOfUnity.mkOfPowEq, PNat.mk_coe,
Units.val_ofPowEqOne, ite_mul, one_mul, ne_eq]
simp_rw [← root_X_pow_sub_C_eq_zero_iff H]
split_ifs with h
· rw [h, mul_zero, map_zero]
· rw [div_mul_cancel₀ _ h]
end AdjoinRoot
/-! ### Galois Group of `IsSplittingField K L (X ^ n - C a)` -/
section IsSplittingField
variable {a}
variable {L : Type*} [Field L] [Algebra K L] [IsSplittingField K L (X ^ n - C a)]
lemma isSplittingField_AdjoinRoot_X_pow_sub_C :
haveI := Fact.mk H
letI : Algebra K K[n√a] := inferInstance
IsSplittingField K K[n√a] (X ^ n - C a) := by
have := Fact.mk H
letI : Algebra K K[n√a] := inferInstance
constructor
· rw [← splits_id_iff_splits, Polynomial.map_sub, Polynomial.map_pow, Polynomial.map_C,
Polynomial.map_X]
have ⟨_, hζ⟩ := hζ
rw [mem_primitiveRoots (Nat.pos_of_ne_zero <| ne_zero_of_irreducible_X_pow_sub_C H)] at hζ
exact X_pow_sub_C_splits_of_isPrimitiveRoot (hζ.map_of_injective (algebraMap K _).injective)
(root_X_pow_sub_C_pow n a)
· rw [eq_top_iff, ← AdjoinRoot.adjoinRoot_eq_top]
apply Algebra.adjoin_mono
have := ne_zero_of_irreducible_X_pow_sub_C H
rw [Set.singleton_subset_iff, mem_rootSet_of_ne (X_pow_sub_C_ne_zero
(Nat.pos_of_ne_zero this) a), aeval_def, AdjoinRoot.algebraMap_eq, AdjoinRoot.eval₂_root]
variable {α : L} (hα : α ^ n = algebraMap K L a)
/-- Suppose `L/K` is the splitting field of `Xⁿ - a`, then a choice of `ⁿ√a` gives an equivalence of
`L` with `K[n√a]`. -/
noncomputable
def adjoinRootXPowSubCEquiv :
K[n√a] ≃ₐ[K] L :=
AlgEquiv.ofBijective (AdjoinRoot.liftHom (X ^ n - C a) α (by simp [hα])) <| by
haveI := Fact.mk H
letI := isSplittingField_AdjoinRoot_X_pow_sub_C hζ H
refine ⟨(AlgHom.toRingHom _).injective, ?_⟩
rw [← Algebra.range_top_iff_surjective, ← IsSplittingField.adjoin_rootSet _ (X ^ n - C a),
eq_comm, adjoin_rootSet_eq_range, IsSplittingField.adjoin_rootSet]
exact IsSplittingField.splits _ _
lemma adjoinRootXPowSubCEquiv_root :
adjoinRootXPowSubCEquiv hζ H hα (root _) = α := by
rw [adjoinRootXPowSubCEquiv, AlgEquiv.coe_ofBijective, liftHom_root]
lemma adjoinRootXPowSubCEquiv_symm_eq_root :
(adjoinRootXPowSubCEquiv hζ H hα).symm α = root _ := by
apply (adjoinRootXPowSubCEquiv hζ H hα).injective
rw [(adjoinRootXPowSubCEquiv hζ H hα).apply_symm_apply, adjoinRootXPowSubCEquiv_root]
lemma Algebra.adjoin_root_eq_top_of_isSplittingField :
Algebra.adjoin K {α} = ⊤ := by
apply Subalgebra.map_injective (f := (adjoinRootXPowSubCEquiv hζ H hα).symm)
(adjoinRootXPowSubCEquiv hζ H hα).symm.injective
rw [Algebra.map_top, (Algebra.range_top_iff_surjective _).mpr
(adjoinRootXPowSubCEquiv hζ H hα).symm.surjective, AlgHom.map_adjoin,
Set.image_singleton, AlgHom.coe_coe, adjoinRootXPowSubCEquiv_symm_eq_root, adjoinRoot_eq_top]
lemma IntermediateField.adjoin_root_eq_top_of_isSplittingField :
K⟮α⟯ = ⊤ := by
refine (IntermediateField.eq_adjoin_of_eq_algebra_adjoin _ _ _ ?_).symm
exact (Algebra.adjoin_root_eq_top_of_isSplittingField hζ H hα).symm
variable (a) (L)
/-- An arbitrary choice of `ⁿ√a` in the splitting field of `Xⁿ - a`. -/
noncomputable
abbrev rootOfSplitsXPowSubC : L :=
(rootOfSplits _ (IsSplittingField.splits L (X ^ n - C a))
(by simpa [degree_X_pow_sub_C hn] using Nat.pos_iff_ne_zero.mp hn))
lemma rootOfSplitsXPowSubC_pow :
(rootOfSplitsXPowSubC hn a L) ^ n = algebraMap K L a := by
have := map_rootOfSplits _ (IsSplittingField.splits L (X ^ n - C a))
simp only [eval₂_sub, eval₂_X_pow, eval₂_C, sub_eq_zero] at this
exact this _
variable {a}
/-- Suppose `L/K` is the splitting field of `Xⁿ - a`, then `Gal(L/K)` is isomorphic to the
roots of unity in `K` if `K` contains all of them.
Note that this does not depend on a choice of `ⁿ√a`. -/
noncomputable
def autEquivRootsOfUnity :
(L ≃ₐ[K] L) ≃* (rootsOfUnity ⟨n, hn⟩ K) :=
(AlgEquiv.autCongr (adjoinRootXPowSubCEquiv hζ H (rootOfSplitsXPowSubC_pow hn a L)).symm).trans
(autAdjoinRootXPowSubCEquiv hζ hn H).symm
lemma autEquivRootsOfUnity_apply_rootOfSplit (σ : L ≃ₐ[K] L) :
σ (rootOfSplitsXPowSubC hn a L) =
autEquivRootsOfUnity hζ hn H L σ • (rootOfSplitsXPowSubC hn a L) := by
obtain ⟨η, rfl⟩ := (autEquivRootsOfUnity hζ hn H L).symm.surjective σ
rw [MulEquiv.apply_symm_apply, autEquivRootsOfUnity]
simp only [MulEquiv.symm_trans_apply, AlgEquiv.autCongr_symm, AlgEquiv.symm_symm,
MulEquiv.symm_symm, AlgEquiv.autCongr_apply, AlgEquiv.trans_apply,
adjoinRootXPowSubCEquiv_symm_eq_root, autAdjoinRootXPowSubCEquiv_root, map_smul,
adjoinRootXPowSubCEquiv_root]
rfl
lemma autEquivRootsOfUnity_smul (σ : L ≃ₐ[K] L) :
autEquivRootsOfUnity hζ hn H L σ • α = σ α := by
have ⟨ζ, hζ'⟩ := hζ
rw [mem_primitiveRoots hn] at hζ'
rw [← mem_nthRoots hn, (hζ'.map_of_injective (algebraMap K L).injective).nthRoots_eq
(rootOfSplitsXPowSubC_pow hn a L)] at hα
simp only [Finset.range_val, Multiset.mem_map, Multiset.mem_range] at hα
obtain ⟨i, _, rfl⟩ := hα
simp only [map_mul, ← map_pow, ← Algebra.smul_def, map_smul,
autEquivRootsOfUnity_apply_rootOfSplit hζ hn H L]
exact smul_comm _ _ _
/-- Suppose `L/K` is the splitting field of `Xⁿ - a`, and `ζ` is a `n`-th primitive root of unity
in `K`, then `Gal(L/K)` is isomorphic to `ZMod n`. -/
noncomputable
def autEquivZmod {ζ : K} (hζ : IsPrimitiveRoot ζ n) :
(L ≃ₐ[K] L) ≃* Multiplicative (ZMod n) :=
haveI hn := Nat.pos_iff_ne_zero.mpr (ne_zero_of_irreducible_X_pow_sub_C H)
(autEquivRootsOfUnity ⟨ζ, (mem_primitiveRoots hn).mpr hζ⟩ hn H L).trans
((MulEquiv.subgroupCongr (IsPrimitiveRoot.zpowers_eq (k := ⟨n, hn⟩)
(hζ.isUnit_unit' hn)).symm).trans (AddEquiv.toMultiplicative'
(hζ.isUnit_unit' hn).zmodEquivZPowers.symm))
lemma autEquivZmod_symm_apply_intCast {ζ : K} (hζ : IsPrimitiveRoot ζ n) (m : ℤ) :
(autEquivZmod H L hζ).symm (Multiplicative.ofAdd (m : ZMod n)) α = ζ ^ m • α := by
have hn := Nat.pos_iff_ne_zero.mpr (ne_zero_of_irreducible_X_pow_sub_C H)
rw [← autEquivRootsOfUnity_smul ⟨ζ, (mem_primitiveRoots hn).mpr hζ⟩ hn H L hα]
simp [MulEquiv.subgroupCongr_symm_apply, Subgroup.smul_def, Units.smul_def, autEquivZmod]
lemma autEquivZmod_symm_apply_natCast {ζ : K} (hζ : IsPrimitiveRoot ζ n) (m : ℕ) :
(autEquivZmod H L hζ).symm (Multiplicative.ofAdd (m : ZMod n)) α = ζ ^ m • α := by
simpa only [Int.cast_natCast, zpow_natCast] using autEquivZmod_symm_apply_intCast H L hα hζ m
lemma isCyclic_of_isSplittingField_X_pow_sub_C : IsCyclic (L ≃ₐ[K] L) :=
have hn := Nat.pos_iff_ne_zero.mpr (ne_zero_of_irreducible_X_pow_sub_C H)
isCyclic_of_surjective _
(autEquivZmod H _ <| (mem_primitiveRoots hn).mp hζ.choose_spec).symm.surjective
lemma isGalois_of_isSplittingField_X_pow_sub_C : IsGalois K L :=
IsGalois.of_separable_splitting_field (separable_X_pow_sub_C_of_irreducible hζ a H)
lemma finrank_of_isSplittingField_X_pow_sub_C : FiniteDimensional.finrank K L = n := by
have := Polynomial.IsSplittingField.finiteDimensional L (X ^ n - C a)
have := isGalois_of_isSplittingField_X_pow_sub_C hζ H L
have hn := Nat.pos_iff_ne_zero.mpr (ne_zero_of_irreducible_X_pow_sub_C H)
have : NeZero n := ⟨ne_zero_of_irreducible_X_pow_sub_C H⟩
rw [← IsGalois.card_aut_eq_finrank, Fintype.card_congr ((autEquivZmod H L <|
(mem_primitiveRoots hn).mp hζ.choose_spec).toEquiv.trans Multiplicative.toAdd), ZMod.card]
end IsSplittingField
/-! ### Cyclic extensions of order `n` when `K` has all `n`-th roots of unity. -/
section IsCyclic
variable {L} [Field L] [Algebra K L] [IsGalois K L] [FiniteDimensional K L] [IsCyclic (L ≃ₐ[K] L)]
variable (hK : (primitiveRoots (FiniteDimensional.finrank K L) K).Nonempty)
open FiniteDimensional
variable (K L)
/-- If `L/K` is a cyclic extension of degree `n`, and `K` contains all `n`-th roots of unity,
then `L = K[α]` for some `α ^ n ∈ K`. -/
lemma exists_root_adjoin_eq_top_of_isCyclic :
∃ (α : L), α ^ (finrank K L) ∈ Set.range (algebraMap K L) ∧ K⟮α⟯ = ⊤ := by
-- Let `ζ` be an `n`-th root of unity, and `σ` be a generator of `L ≃ₐ[K] L`.
have ⟨ζ, hζ⟩ := hK
rw [mem_primitiveRoots finrank_pos] at hζ
obtain ⟨σ, hσ⟩ := ‹IsCyclic (L ≃ₐ[K] L)›
have hσ' := orderOf_eq_card_of_forall_mem_zpowers hσ
-- Since the minimal polynomial of `σ` over `K` is `Xⁿ - 1`,
-- `σ` has an eigenvector `v` with eigenvalue `ζ`.
have : IsRoot (minpoly K σ.toLinearMap) ζ := by
simpa [minpoly_algEquiv_toLinearMap σ (isOfFinOrder_of_finite σ), hσ',
sub_eq_zero, IsGalois.card_aut_eq_finrank] using hζ.pow_eq_one
obtain ⟨v, hv⟩ := (Module.End.hasEigenvalue_of_isRoot this).exists_hasEigenvector
have hv' := hv.pow_apply
simp_rw [← AlgEquiv.pow_toLinearMap, AlgEquiv.toLinearMap_apply] at hv'
-- We claim that `v` is the desired root.
refine ⟨v, ?_, ?_⟩
· -- Since `v ^ n` is fixed by `σ` (`σ (v ^ n) = ζ ^ n • v ^ n = v ^ n`), it is in `K`.
rw [← IntermediateField.mem_bot,
← OrderIso.map_bot IsGalois.intermediateFieldEquivSubgroup.symm]
intro ⟨σ', hσ'⟩
obtain ⟨n, rfl : σ ^ n = σ'⟩ := mem_powers_iff_mem_zpowers.mpr (hσ σ')
rw [smul_pow', Submonoid.smul_def, AlgEquiv.smul_def, hv', smul_pow, ← pow_mul,
mul_comm, pow_mul, hζ.pow_eq_one, one_pow, one_smul]
· -- Since `σ` does not fix `K⟮α⟯`, `K⟮α⟯` is `L`.
apply IsGalois.intermediateFieldEquivSubgroup.injective
rw [map_top, eq_top_iff]
intros σ' hσ'
obtain ⟨n, rfl : σ ^ n = σ'⟩ := mem_powers_iff_mem_zpowers.mpr (hσ σ')
have := hσ' ⟨v, IntermediateField.mem_adjoin_simple_self K v⟩
simp only [AlgEquiv.smul_def, hv'] at this
conv_rhs at this => rw [← one_smul K v]
obtain ⟨k, rfl⟩ := hζ.dvd_of_pow_eq_one n (smul_left_injective K hv.2 this)
rw [pow_mul, ← IsGalois.card_aut_eq_finrank, pow_card_eq_one, one_pow]
exact one_mem _
variable {K L}
lemma irreducible_X_pow_sub_C_of_root_adjoin_eq_top
{a : K} {α : L} (ha : α ^ (finrank K L) = algebraMap K L a) (hα : K⟮α⟯ = ⊤) :
Irreducible (X ^ (finrank K L) - C a) := by
have : X ^ (finrank K L) - C a = minpoly K α := by
refine minpoly.unique _ _ (monic_X_pow_sub_C _ finrank_pos.ne.symm) ?_ ?_
· simp only [aeval_def, eval₂_sub, eval₂_X_pow, ha, eval₂_C, sub_self]
· intros q hq hq'
refine le_trans ?_ (degree_le_of_dvd (minpoly.dvd _ _ hq') hq.ne_zero)
rw [degree_X_pow_sub_C finrank_pos,
degree_eq_natDegree (minpoly.ne_zero (IsIntegral.of_finite K α)),
← IntermediateField.adjoin.finrank (IsIntegral.of_finite K α), hα, Nat.cast_le]
exact (finrank_top K L).ge
exact this ▸ minpoly.irreducible (IsIntegral.of_finite K α)
lemma isSplittingField_X_pow_sub_C_of_root_adjoin_eq_top
{a : K} {α : L} (ha : α ^ (finrank K L) = algebraMap K L a) (hα : K⟮α⟯ = ⊤) :
IsSplittingField K L (X ^ (finrank K L) - C a) := by
constructor
· rw [← splits_id_iff_splits, Polynomial.map_sub, Polynomial.map_pow, Polynomial.map_C,
Polynomial.map_X]
have ⟨_, hζ⟩ := hK
rw [mem_primitiveRoots finrank_pos] at hζ
exact X_pow_sub_C_splits_of_isPrimitiveRoot (hζ.map_of_injective (algebraMap K _).injective) ha
· rw [eq_top_iff, ← IntermediateField.top_toSubalgebra, ← hα,
IntermediateField.adjoin_simple_toSubalgebra_of_integral (IsIntegral.of_finite K α)]
apply Algebra.adjoin_mono
rw [Set.singleton_subset_iff, mem_rootSet_of_ne (X_pow_sub_C_ne_zero finrank_pos a),
aeval_def, eval₂_sub, eval₂_X_pow, eval₂_C, ha, sub_self]
end IsCyclic
open FiniteDimensional in
/--
Suppose `L/K` is a finite extension of dimension `n`, and `K` contains all `n`-th roots of unity.
Then `L/K` is cyclic iff
`L` is a splitting field of some irreducible polynomial of the form `Xⁿ - a : K[X]` iff
`L = K[α]` for some `αⁿ ∈ K`.
-/
lemma isCyclic_tfae (K L) [Field K] [Field L] [Algebra K L] [FiniteDimensional K L]
(hK : (primitiveRoots (FiniteDimensional.finrank K L) K).Nonempty) :
List.TFAE [
IsGalois K L ∧ IsCyclic (L ≃ₐ[K] L),
∃ a : K, Irreducible (X ^ (finrank K L) - C a) ∧
IsSplittingField K L (X ^ (finrank K L) - C a),
∃ (α : L), α ^ (finrank K L) ∈ Set.range (algebraMap K L) ∧ K⟮α⟯ = ⊤] := by
tfae_have 1 → 3
· intro ⟨inst₁, inst₂⟩
exact exists_root_adjoin_eq_top_of_isCyclic K L hK
tfae_have 3 → 2
· intro ⟨α, ⟨a, ha⟩, hα⟩
exact ⟨a, irreducible_X_pow_sub_C_of_root_adjoin_eq_top ha.symm hα,
isSplittingField_X_pow_sub_C_of_root_adjoin_eq_top hK ha.symm hα⟩
tfae_have 2 → 1
· intro ⟨a, H, inst⟩
exact ⟨isGalois_of_isSplittingField_X_pow_sub_C hK H L,
isCyclic_of_isSplittingField_X_pow_sub_C hK H L⟩
tfae_finish
|
FieldTheory\Laurent.lean | /-
Copyright (c) 2022 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky
-/
import Mathlib.Algebra.Polynomial.Taylor
import Mathlib.FieldTheory.RatFunc.AsPolynomial
/-!
# Laurent expansions of rational functions
## Main declarations
* `RatFunc.laurent`: the Laurent expansion of the rational function `f` at `r`, as an `AlgHom`.
* `RatFunc.laurent_injective`: the Laurent expansion at `r` is unique
## Implementation details
Implemented as the quotient of two Taylor expansions, over domains.
An auxiliary definition is provided first to make the construction of the `AlgHom` easier,
which works on `CommRing` which are not necessarily domains.
-/
universe u
namespace RatFunc
noncomputable section
open Polynomial
open scoped nonZeroDivisors
variable {R : Type u} [CommRing R] (r s : R) (p q : R[X]) (f : RatFunc R)
theorem taylor_mem_nonZeroDivisors (hp : p ∈ R[X]⁰) : taylor r p ∈ R[X]⁰ := by
rw [mem_nonZeroDivisors_iff]
intro x hx
have : x = taylor (r - r) x := by simp
rwa [this, sub_eq_add_neg, ← taylor_taylor, ← taylor_mul,
LinearMap.map_eq_zero_iff _ (taylor_injective _), mul_right_mem_nonZeroDivisors_eq_zero_iff hp,
LinearMap.map_eq_zero_iff _ (taylor_injective _)] at hx
/-- The Laurent expansion of rational functions about a value.
Auxiliary definition, usage when over integral domains should prefer `RatFunc.laurent`. -/
def laurentAux : RatFunc R →+* RatFunc R :=
RatFunc.mapRingHom
( { toFun := taylor r
map_add' := map_add (taylor r)
map_mul' := taylor_mul _
map_zero' := map_zero (taylor r)
map_one' := taylor_one r } : R[X] →+* R[X])
(taylor_mem_nonZeroDivisors _)
theorem laurentAux_ofFractionRing_mk (q : R[X]⁰) :
laurentAux r (ofFractionRing (Localization.mk p q)) =
ofFractionRing (.mk (taylor r p) ⟨taylor r q, taylor_mem_nonZeroDivisors r q q.prop⟩) :=
map_apply_ofFractionRing_mk _ _ _ _
variable [IsDomain R]
theorem laurentAux_div :
laurentAux r (algebraMap _ _ p / algebraMap _ _ q) =
algebraMap _ _ (taylor r p) / algebraMap _ _ (taylor r q) :=
-- Porting note: added `by exact taylor_mem_nonZeroDivisors r`
map_apply_div _ (by exact taylor_mem_nonZeroDivisors r) _ _
@[simp]
theorem laurentAux_algebraMap : laurentAux r (algebraMap _ _ p) = algebraMap _ _ (taylor r p) := by
rw [← mk_one, ← mk_one, mk_eq_div, laurentAux_div, mk_eq_div, taylor_one, map_one, map_one]
/-- The Laurent expansion of rational functions about a value. -/
def laurent : RatFunc R →ₐ[R] RatFunc R :=
RatFunc.mapAlgHom (.ofLinearMap (taylor r) (taylor_one _) (taylor_mul _))
(taylor_mem_nonZeroDivisors _)
theorem laurent_div :
laurent r (algebraMap _ _ p / algebraMap _ _ q) =
algebraMap _ _ (taylor r p) / algebraMap _ _ (taylor r q) :=
laurentAux_div r p q
@[simp]
theorem laurent_algebraMap : laurent r (algebraMap _ _ p) = algebraMap _ _ (taylor r p) :=
laurentAux_algebraMap _ _
@[simp]
theorem laurent_X : laurent r X = X + C r := by
rw [← algebraMap_X, laurent_algebraMap, taylor_X, _root_.map_add, algebraMap_C]
@[simp]
theorem laurent_C (x : R) : laurent r (C x) = C x := by
rw [← algebraMap_C, laurent_algebraMap, taylor_C]
@[simp]
theorem laurent_at_zero : laurent 0 f = f := by induction f using RatFunc.induction_on; simp
theorem laurent_laurent : laurent r (laurent s f) = laurent (r + s) f := by
induction f using RatFunc.induction_on
simp_rw [laurent_div, taylor_taylor]
theorem laurent_injective : Function.Injective (laurent r) := fun _ _ h => by
simpa [laurent_laurent] using congr_arg (laurent (-r)) h
end
end RatFunc
|
FieldTheory\MvPolynomial.lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Algebra.MvPolynomial.CommRing
import Mathlib.LinearAlgebra.Dimension.StrongRankCondition
import Mathlib.RingTheory.MvPolynomial.Basic
/-!
# Multivariate polynomials over fields
This file contains basic facts about multivariate polynomials over fields, for example that the
dimension of the space of multivariate polynomials over a field is equal to the cardinality of
finitely supported functions from the indexing set to `ℕ`.
-/
noncomputable section
open Set LinearMap Submodule
namespace MvPolynomial
universe u v
variable {σ : Type u} {K : Type v}
variable (σ K) [Field K]
theorem quotient_mk_comp_C_injective (I : Ideal (MvPolynomial σ K)) (hI : I ≠ ⊤) :
Function.Injective ((Ideal.Quotient.mk I).comp MvPolynomial.C) := by
refine (injective_iff_map_eq_zero _).2 fun x hx => ?_
rw [RingHom.comp_apply, Ideal.Quotient.eq_zero_iff_mem] at hx
refine _root_.by_contradiction fun hx0 => absurd (I.eq_top_iff_one.2 ?_) hI
have := I.mul_mem_left (MvPolynomial.C x⁻¹) hx
rwa [← MvPolynomial.C.map_mul, inv_mul_cancel hx0, MvPolynomial.C_1] at this
end MvPolynomial
namespace MvPolynomial
universe u
variable {σ : Type u} {K : Type u} [Field K]
theorem rank_mvPolynomial : Module.rank K (MvPolynomial σ K) = Cardinal.mk (σ →₀ ℕ) := by
rw [← Cardinal.lift_inj, ← (basisMonomials σ K).mk_eq_rank]
end MvPolynomial
|
FieldTheory\Normal.lean | /-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Thomas Browning, Patrick Lutz
-/
import Mathlib.FieldTheory.Extension
import Mathlib.FieldTheory.SplittingField.Construction
import Mathlib.GroupTheory.Solvable
/-!
# Normal field extensions
In this file we define normal field extensions and prove that for a finite extension, being normal
is the same as being a splitting field (`Normal.of_isSplittingField` and
`Normal.exists_isSplittingField`).
## Main Definitions
- `Normal F K` where `K` is a field extension of `F`.
-/
noncomputable section
open Polynomial IsScalarTower
variable (F K : Type*) [Field F] [Field K] [Algebra F K]
/-- Typeclass for normal field extension: `K` is a normal extension of `F` iff the minimal
polynomial of every element `x` in `K` splits in `K`, i.e. every conjugate of `x` is in `K`. -/
class Normal extends Algebra.IsAlgebraic F K : Prop where
splits' (x : K) : Splits (algebraMap F K) (minpoly F x)
variable {F K}
theorem Normal.isIntegral (_ : Normal F K) (x : K) : IsIntegral F x :=
Algebra.IsIntegral.isIntegral x
theorem Normal.splits (_ : Normal F K) (x : K) : Splits (algebraMap F K) (minpoly F x) :=
Normal.splits' x
theorem normal_iff : Normal F K ↔ ∀ x : K, IsIntegral F x ∧ Splits (algebraMap F K) (minpoly F x) :=
⟨fun h x => ⟨h.isIntegral x, h.splits x⟩, fun h =>
{ isAlgebraic := fun x => (h x).1.isAlgebraic
splits' := fun x => (h x).2 }⟩
theorem Normal.out : Normal F K → ∀ x : K, IsIntegral F x ∧ Splits (algebraMap F K) (minpoly F x) :=
normal_iff.1
variable (F K)
instance normal_self : Normal F F where
isAlgebraic := fun _ => isIntegral_algebraMap.isAlgebraic
splits' := fun x => (minpoly.eq_X_sub_C' x).symm ▸ splits_X_sub_C _
theorem Normal.exists_isSplittingField [h : Normal F K] [FiniteDimensional F K] :
∃ p : F[X], IsSplittingField F K p := by
classical
let s := Basis.ofVectorSpace F K
refine
⟨∏ x, minpoly F (s x), splits_prod _ fun x _ => h.splits (s x),
Subalgebra.toSubmodule.injective ?_⟩
rw [Algebra.top_toSubmodule, eq_top_iff, ← s.span_eq, Submodule.span_le, Set.range_subset_iff]
refine fun x =>
Algebra.subset_adjoin
(Multiset.mem_toFinset.mpr <|
(mem_roots <|
mt (Polynomial.map_eq_zero <| algebraMap F K).1 <|
Finset.prod_ne_zero_iff.2 fun x _ => ?_).2 ?_)
· exact minpoly.ne_zero (h.isIntegral (s x))
rw [IsRoot.def, eval_map, ← aeval_def, map_prod]
exact Finset.prod_eq_zero (Finset.mem_univ _) (minpoly.aeval _ _)
section NormalTower
variable (E : Type*) [Field E] [Algebra F E] [Algebra K E] [IsScalarTower F K E]
theorem Normal.tower_top_of_normal [h : Normal F E] : Normal K E :=
normal_iff.2 fun x => by
cases' h.out x with hx hhx
rw [algebraMap_eq F K E] at hhx
exact
⟨hx.tower_top,
Polynomial.splits_of_splits_of_dvd (algebraMap K E)
(Polynomial.map_ne_zero (minpoly.ne_zero hx))
((Polynomial.splits_map_iff (algebraMap F K) (algebraMap K E)).mpr hhx)
(minpoly.dvd_map_of_isScalarTower F K x)⟩
theorem AlgHom.normal_bijective [h : Normal F E] (ϕ : E →ₐ[F] K) : Function.Bijective ϕ :=
h.toIsAlgebraic.bijective_of_isScalarTower' ϕ
variable {E F}
variable {E' : Type*} [Field E'] [Algebra F E']
theorem Normal.of_algEquiv [h : Normal F E] (f : E ≃ₐ[F] E') : Normal F E' := by
rw [normal_iff] at h ⊢
intro x; specialize h (f.symm x)
rw [← f.apply_symm_apply x, minpoly.algEquiv_eq, ← f.toAlgHom.comp_algebraMap]
exact ⟨h.1.map f, splits_comp_of_splits _ _ h.2⟩
theorem AlgEquiv.transfer_normal (f : E ≃ₐ[F] E') : Normal F E ↔ Normal F E' :=
⟨fun _ ↦ Normal.of_algEquiv f, fun _ ↦ Normal.of_algEquiv f.symm⟩
open IntermediateField
theorem Normal.of_isSplittingField (p : F[X]) [hFEp : IsSplittingField F E p] : Normal F E := by
rcases eq_or_ne p 0 with (rfl | hp)
· have := hFEp.adjoin_rootSet
rw [rootSet_zero, Algebra.adjoin_empty] at this
exact Normal.of_algEquiv
(AlgEquiv.ofBijective (Algebra.ofId F E) (Algebra.bijective_algebraMap_iff.2 this.symm))
refine normal_iff.mpr fun x ↦ ?_
haveI : FiniteDimensional F E := IsSplittingField.finiteDimensional E p
have hx := IsIntegral.of_finite F x
let L := (p * minpoly F x).SplittingField
have hL := splits_of_splits_mul' _ ?_ (SplittingField.splits (p * minpoly F x))
· let j : E →ₐ[F] L := IsSplittingField.lift E p hL.1
refine ⟨hx, splits_of_comp _ (j : E →+* L) (j.comp_algebraMap ▸ hL.2) fun a ha ↦ ?_⟩
rw [j.comp_algebraMap] at ha
letI : Algebra F⟮x⟯ L := ((algHomAdjoinIntegralEquiv F hx).symm ⟨a, ha⟩).toRingHom.toAlgebra
let j' : E →ₐ[F⟮x⟯] L := IsSplittingField.lift E (p.map (algebraMap F F⟮x⟯)) ?_
· change a ∈ j.range
rw [← IsSplittingField.adjoin_rootSet_eq_range E p j,
IsSplittingField.adjoin_rootSet_eq_range E p (j'.restrictScalars F)]
exact ⟨x, (j'.commutes _).trans (algHomAdjoinIntegralEquiv_symm_apply_gen F hx _)⟩
· rw [splits_map_iff, ← IsScalarTower.algebraMap_eq]; exact hL.1
· rw [Polynomial.map_ne_zero_iff (algebraMap F L).injective, mul_ne_zero_iff]
exact ⟨hp, minpoly.ne_zero hx⟩
instance Polynomial.SplittingField.instNormal (p : F[X]) : Normal F p.SplittingField :=
Normal.of_isSplittingField p
end NormalTower
namespace IntermediateField
/-- A compositum of normal extensions is normal -/
instance normal_iSup {ι : Type*} (t : ι → IntermediateField F K) [h : ∀ i, Normal F (t i)] :
Normal F (⨆ i, t i : IntermediateField F K) := by
refine { toIsAlgebraic := isAlgebraic_iSup fun i => (h i).1, splits' := fun x => ?_ }
obtain ⟨s, hx⟩ := exists_finset_of_mem_supr'' (fun i => (h i).1) x.2
let E : IntermediateField F K := ⨆ i ∈ s, adjoin F ((minpoly F (i.2 : _)).rootSet K)
have hF : Normal F E := by
haveI : IsSplittingField F E (∏ i ∈ s, minpoly F i.snd) := by
refine isSplittingField_iSup ?_ fun i _ => adjoin_rootSet_isSplittingField ?_
· exact Finset.prod_ne_zero_iff.mpr fun i _ => minpoly.ne_zero ((h i.1).isIntegral i.2)
· exact Polynomial.splits_comp_of_splits _ (algebraMap (t i.1) K) ((h i.1).splits i.2)
apply Normal.of_isSplittingField (∏ i ∈ s, minpoly F i.2)
have hE : E ≤ ⨆ i, t i := by
refine iSup_le fun i => iSup_le fun _ => le_iSup_of_le i.1 ?_
rw [adjoin_le_iff, ← image_rootSet ((h i.1).splits i.2) (t i.1).val]
exact fun _ ⟨a, _, h⟩ => h ▸ a.2
have := hF.splits ⟨x, hx⟩
rw [minpoly_eq, Subtype.coe_mk, ← minpoly_eq] at this
exact Polynomial.splits_comp_of_splits _ (inclusion hE).toRingHom this
/-- If a set of algebraic elements in a field extension `K/F` have minimal polynomials that
split in another extension `L/F`, then all minimal polynomials in the intermediate field
generated by the set also split in `L/F`. -/
theorem splits_of_mem_adjoin {L} [Field L] [Algebra F L] {S : Set K}
(splits : ∀ x ∈ S, IsIntegral F x ∧ (minpoly F x).Splits (algebraMap F L)) {x : K}
(hx : x ∈ adjoin F S) : (minpoly F x).Splits (algebraMap F L) := by
let E : IntermediateField F L := ⨆ x : S, adjoin F ((minpoly F x.val).rootSet L)
have normal : Normal F E := normal_iSup (h := fun x ↦
Normal.of_isSplittingField (hFEp := adjoin_rootSet_isSplittingField (splits x x.2).2))
have : ∀ x ∈ S, (minpoly F x).Splits (algebraMap F E) := fun x hx ↦ splits_of_splits
(splits x hx).2 fun y hy ↦ (le_iSup _ ⟨x, hx⟩ : _ ≤ E) (subset_adjoin F _ <| by exact hy)
obtain ⟨φ⟩ := nonempty_algHom_adjoin_of_splits fun x hx ↦ ⟨(splits x hx).1, this x hx⟩
convert splits_comp_of_splits _ E.val.toRingHom (normal.splits <| φ ⟨x, hx⟩)
rw [minpoly.algHom_eq _ φ.injective, ← minpoly.algHom_eq _ (adjoin F S).val.injective, val_mk]
instance normal_sup
(E E' : IntermediateField F K) [Normal F E] [Normal F E'] :
Normal F (E ⊔ E' : IntermediateField F K) :=
iSup_bool_eq (f := Bool.rec E' E) ▸ normal_iSup (h := by rintro (_|_) <;> infer_instance)
variable {F K}
variable {L : Type*} [Field L] [Algebra F L] [Algebra K L] [IsScalarTower F K L]
@[simp]
theorem restrictScalars_normal {E : IntermediateField K L} :
Normal F (E.restrictScalars F) ↔ Normal F E :=
Iff.rfl
end IntermediateField
variable {F} {K}
variable {K₁ K₂ K₃ : Type*} [Field K₁] [Field K₂] [Field K₃] [Algebra F K₁]
[Algebra F K₂] [Algebra F K₃] (ϕ : K₁ →ₐ[F] K₂) (χ : K₁ ≃ₐ[F] K₂) (ψ : K₂ →ₐ[F] K₃)
(ω : K₂ ≃ₐ[F] K₃)
section Restrict
variable (E : Type*) [Field E] [Algebra F E] [Algebra E K₁] [Algebra E K₂] [Algebra E K₃]
[IsScalarTower F E K₁] [IsScalarTower F E K₂] [IsScalarTower F E K₃]
/-- Restrict algebra homomorphism to image of normal subfield -/
def AlgHom.restrictNormalAux [h : Normal F E] :
(toAlgHom F E K₁).range →ₐ[F] (toAlgHom F E K₂).range where
toFun x :=
⟨ϕ x, by
suffices (toAlgHom F E K₁).range.map ϕ ≤ _ by exact this ⟨x, Subtype.mem x, rfl⟩
rintro x ⟨y, ⟨z, hy⟩, hx⟩
rw [← hx, ← hy]
apply minpoly.mem_range_of_degree_eq_one E
refine
Or.resolve_left (h.splits z).def (minpoly.ne_zero (h.isIntegral z)) (minpoly.irreducible ?_)
(minpoly.dvd E _ (by simp [aeval_algHom_apply]))
simp only [AlgHom.toRingHom_eq_coe, AlgHom.coe_toRingHom]
suffices IsIntegral F _ by exact this.tower_top
exact ((h.isIntegral z).map <| toAlgHom F E K₁).map ϕ⟩
map_zero' := Subtype.ext (map_zero _)
map_one' := Subtype.ext (map_one _)
map_add' x y := Subtype.ext <| by simp
map_mul' x y := Subtype.ext <| by simp
commutes' x := Subtype.ext (ϕ.commutes x)
/-- Restrict algebra homomorphism to normal subfield -/
def AlgHom.restrictNormal [Normal F E] : E →ₐ[F] E :=
((AlgEquiv.ofInjectiveField (IsScalarTower.toAlgHom F E K₂)).symm.toAlgHom.comp
(ϕ.restrictNormalAux E)).comp
(AlgEquiv.ofInjectiveField (IsScalarTower.toAlgHom F E K₁)).toAlgHom
/-- Restrict algebra homomorphism to normal subfield (`AlgEquiv` version) -/
def AlgHom.restrictNormal' [Normal F E] : E ≃ₐ[F] E :=
AlgEquiv.ofBijective (AlgHom.restrictNormal ϕ E) (AlgHom.normal_bijective F E E _)
@[simp]
theorem AlgHom.restrictNormal_commutes [Normal F E] (x : E) :
algebraMap E K₂ (ϕ.restrictNormal E x) = ϕ (algebraMap E K₁ x) :=
Subtype.ext_iff.mp
(AlgEquiv.apply_symm_apply (AlgEquiv.ofInjectiveField (IsScalarTower.toAlgHom F E K₂))
(ϕ.restrictNormalAux E ⟨IsScalarTower.toAlgHom F E K₁ x, x, rfl⟩))
theorem AlgHom.restrictNormal_comp [Normal F E] :
(ψ.restrictNormal E).comp (ϕ.restrictNormal E) = (ψ.comp ϕ).restrictNormal E :=
AlgHom.ext fun _ =>
(algebraMap E K₃).injective (by simp only [AlgHom.comp_apply, AlgHom.restrictNormal_commutes])
theorem AlgHom.fieldRange_of_normal {E : IntermediateField F K} [Normal F E]
(f : E →ₐ[F] K) : f.fieldRange = E := by
let g := f.restrictNormal' E
rw [← show E.val.comp ↑g = f from DFunLike.ext_iff.mpr (f.restrictNormal_commutes E),
← AlgHom.map_fieldRange, AlgEquiv.fieldRange_eq_top g, ← AlgHom.fieldRange_eq_map,
IntermediateField.fieldRange_val]
/-- Restrict algebra isomorphism to a normal subfield -/
def AlgEquiv.restrictNormal [Normal F E] : E ≃ₐ[F] E :=
AlgHom.restrictNormal' χ.toAlgHom E
@[simp]
theorem AlgEquiv.restrictNormal_commutes [Normal F E] (x : E) :
algebraMap E K₂ (χ.restrictNormal E x) = χ (algebraMap E K₁ x) :=
χ.toAlgHom.restrictNormal_commutes E x
theorem AlgEquiv.restrictNormal_trans [Normal F E] :
(χ.trans ω).restrictNormal E = (χ.restrictNormal E).trans (ω.restrictNormal E) :=
AlgEquiv.ext fun _ =>
(algebraMap E K₃).injective
(by simp only [AlgEquiv.trans_apply, AlgEquiv.restrictNormal_commutes])
/-- Restriction to a normal subfield as a group homomorphism -/
def AlgEquiv.restrictNormalHom [Normal F E] : (K₁ ≃ₐ[F] K₁) →* E ≃ₐ[F] E :=
MonoidHom.mk' (fun χ => χ.restrictNormal E) fun ω χ => χ.restrictNormal_trans ω E
variable (F K₁)
/-- If `K₁/E/F` is a tower of fields with `E/F` normal then `AlgHom.restrictNormal'` is an
equivalence. -/
@[simps]
def Normal.algHomEquivAut [Normal F E] : (E →ₐ[F] K₁) ≃ E ≃ₐ[F] E where
toFun σ := AlgHom.restrictNormal' σ E
invFun σ := (IsScalarTower.toAlgHom F E K₁).comp σ.toAlgHom
left_inv σ := by
ext
simp [AlgHom.restrictNormal']
right_inv σ := by
ext
simp only [AlgHom.restrictNormal', AlgEquiv.toAlgHom_eq_coe, AlgEquiv.coe_ofBijective]
apply NoZeroSMulDivisors.algebraMap_injective E K₁
rw [AlgHom.restrictNormal_commutes]
simp
end Restrict
section lift
variable (E : Type*) [Field E] [Algebra F E] [Algebra K₁ E] [Algebra K₂ E] [IsScalarTower F K₁ E]
[IsScalarTower F K₂ E]
/-- If `E/Kᵢ/F` are towers of fields with `E/F` normal then we can lift
an algebra homomorphism `ϕ : K₁ →ₐ[F] K₂` to `ϕ.liftNormal E : E →ₐ[F] E`. -/
noncomputable def AlgHom.liftNormal [h : Normal F E] : E →ₐ[F] E :=
@AlgHom.restrictScalars F K₁ E E _ _ _ _ _ _
((IsScalarTower.toAlgHom F K₂ E).comp ϕ).toRingHom.toAlgebra _ _ _ _ <|
Nonempty.some <|
@IntermediateField.nonempty_algHom_of_adjoin_splits _ _ _ _ _ _ _
((IsScalarTower.toAlgHom F K₂ E).comp ϕ).toRingHom.toAlgebra _
(fun x _ ↦ ⟨(h.out x).1.tower_top,
splits_of_splits_of_dvd _ (map_ne_zero (minpoly.ne_zero (h.out x).1))
-- Porting note: had to override typeclass inference below using `(_)`
(by rw [splits_map_iff, ← @IsScalarTower.algebraMap_eq _ _ _ _ _ _ (_) (_) (_)]
exact (h.out x).2)
(minpoly.dvd_map_of_isScalarTower F K₁ x)⟩)
(IntermediateField.adjoin_univ _ _)
@[simp]
theorem AlgHom.liftNormal_commutes [Normal F E] (x : K₁) :
ϕ.liftNormal E (algebraMap K₁ E x) = algebraMap K₂ E (ϕ x) :=
-- Porting note: This seems to have been some sort of typeclass override trickery using `by apply`
-- Now we explicitly specify which typeclass to override, using `(_)` instead of `_`
@AlgHom.commutes K₁ E E _ _ _ _ (_) _ _
@[simp]
theorem AlgHom.restrict_liftNormal (ϕ : K₁ →ₐ[F] K₁) [Normal F K₁] [Normal F E] :
(ϕ.liftNormal E).restrictNormal K₁ = ϕ :=
AlgHom.ext fun x =>
(algebraMap K₁ E).injective
(Eq.trans (AlgHom.restrictNormal_commutes _ K₁ x) (ϕ.liftNormal_commutes E x))
/-- If `E/Kᵢ/F` are towers of fields with `E/F` normal then we can lift
an algebra isomorphism `ϕ : K₁ ≃ₐ[F] K₂` to `ϕ.liftNormal E : E ≃ₐ[F] E`. -/
noncomputable def AlgEquiv.liftNormal [Normal F E] : E ≃ₐ[F] E :=
AlgEquiv.ofBijective (χ.toAlgHom.liftNormal E) (AlgHom.normal_bijective F E E _)
@[simp]
theorem AlgEquiv.liftNormal_commutes [Normal F E] (x : K₁) :
χ.liftNormal E (algebraMap K₁ E x) = algebraMap K₂ E (χ x) :=
χ.toAlgHom.liftNormal_commutes E x
@[simp]
theorem AlgEquiv.restrict_liftNormal (χ : K₁ ≃ₐ[F] K₁) [Normal F K₁] [Normal F E] :
(χ.liftNormal E).restrictNormal K₁ = χ :=
AlgEquiv.ext fun x =>
(algebraMap K₁ E).injective
(Eq.trans (AlgEquiv.restrictNormal_commutes _ K₁ x) (χ.liftNormal_commutes E x))
theorem AlgEquiv.restrictNormalHom_surjective [Normal F K₁] [Normal F E] :
Function.Surjective (AlgEquiv.restrictNormalHom K₁ : (E ≃ₐ[F] E) → K₁ ≃ₐ[F] K₁) := fun χ =>
⟨χ.liftNormal E, χ.restrict_liftNormal E⟩
open IntermediateField in
theorem Normal.minpoly_eq_iff_mem_orbit [h : Normal F E] {x y : E} :
minpoly F x = minpoly F y ↔ x ∈ MulAction.orbit (E ≃ₐ[F] E) y := by
refine ⟨fun he ↦ ?_, fun ⟨f, he⟩ ↦ he ▸ minpoly.algEquiv_eq f y⟩
obtain ⟨φ, hφ⟩ := exists_algHom_of_splits_of_aeval (normal_iff.mp h) (he ▸ minpoly.aeval F x)
exact ⟨AlgEquiv.ofBijective φ (φ.normal_bijective F E E), hφ⟩
variable (F K₁)
theorem isSolvable_of_isScalarTower [Normal F K₁] [h1 : IsSolvable (K₁ ≃ₐ[F] K₁)]
[h2 : IsSolvable (E ≃ₐ[K₁] E)] : IsSolvable (E ≃ₐ[F] E) := by
let f : (E ≃ₐ[K₁] E) →* E ≃ₐ[F] E :=
{ toFun := fun ϕ =>
AlgEquiv.ofAlgHom (ϕ.toAlgHom.restrictScalars F) (ϕ.symm.toAlgHom.restrictScalars F)
(AlgHom.ext fun x => ϕ.apply_symm_apply x) (AlgHom.ext fun x => ϕ.symm_apply_apply x)
map_one' := AlgEquiv.ext fun _ => rfl
map_mul' := fun _ _ => AlgEquiv.ext fun _ => rfl }
refine
solvable_of_ker_le_range f (AlgEquiv.restrictNormalHom K₁) fun ϕ hϕ =>
⟨{ ϕ with commutes' := fun x => ?_ }, AlgEquiv.ext fun _ => rfl⟩
exact Eq.trans (ϕ.restrictNormal_commutes K₁ x).symm (congr_arg _ (AlgEquiv.ext_iff.mp hϕ x))
end lift
namespace minpoly
variable {K L : Type _} [Field K] [Field L] [Algebra K L]
open AlgEquiv IntermediateField
/-- If `x : L` is a root of `minpoly K y`, then we can find `(σ : L ≃ₐ[K] L)` with `σ x = y`.
That is, `x` and `y` are Galois conjugates. -/
theorem exists_algEquiv_of_root [Normal K L] {x y : L} (hy : IsAlgebraic K y)
(h_ev : (Polynomial.aeval x) (minpoly K y) = 0) : ∃ σ : L ≃ₐ[K] L, σ x = y := by
have hx : IsAlgebraic K x := ⟨minpoly K y, ne_zero hy.isIntegral, h_ev⟩
set f : K⟮x⟯ ≃ₐ[K] K⟮y⟯ := algEquiv hx (eq_of_root hy h_ev)
have hxy : (liftNormal f L) ((algebraMap (↥K⟮x⟯) L) (AdjoinSimple.gen K x)) = y := by
rw [liftNormal_commutes f L, algEquiv_apply, AdjoinSimple.algebraMap_gen K y]
exact ⟨(liftNormal f L), hxy⟩
/-- If `x : L` is a root of `minpoly K y`, then we can find `(σ : L ≃ₐ[K] L)` with `σ y = x`.
That is, `x` and `y` are Galois conjugates. -/
theorem exists_algEquiv_of_root' [Normal K L]{x y : L} (hy : IsAlgebraic K y)
(h_ev : (Polynomial.aeval x) (minpoly K y) = 0) : ∃ σ : L ≃ₐ[K] L, σ y = x := by
obtain ⟨σ, hσ⟩ := exists_algEquiv_of_root hy h_ev
use σ.symm
rw [← hσ, symm_apply_apply]
end minpoly
|
FieldTheory\NormalClosure.lean | /-
Copyright (c) 2023 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning
-/
import Mathlib.FieldTheory.Normal
import Mathlib.Order.Closure
/-!
# Normal closures
## Main definitions
Given field extensions `K/F` and `L/F`, the predicate `IsNormalClosure F K L` says that the
minimal polynomial of every element of `K` over `F` splits in `L`, and that `L` is generated
by the roots of such minimal polynomials. These conditions uniquely characterize `L/F` up to
`F`-algebra isomorphisms (`IsNormalClosure.equiv`).
The explicit construction `normalClosure F K L` of a field extension `K/F` inside another
field extension `L/F` is the smallest intermediate field of `L/F` that contains the image
of every `F`-algebra embedding `K →ₐ[F] L`. It satisfies the `IsNormalClosure` predicate
if `L/F` satisfies the abovementioned splitting condition, in particular if `L/K/F` form
a tower and `L/F` is normal.
-/
open IntermediateField IsScalarTower Polynomial
variable (F K L : Type*) [Field F] [Field K] [Field L] [Algebra F K] [Algebra F L]
/-- `L/F` is a normal closure of `K/F` if the minimal polynomial of every element of `K` over `F`
splits in `L`, and `L` is generated by roots of such minimal polynomials over `F`.
(Since the minimal polynomial of a transcendental element is 0,
the normal closure of `K/F` is the same as the normal closure over `F`
of the algebraic closure of `F` in `K`.) -/
class IsNormalClosure : Prop where
splits (x : K) : (minpoly F x).Splits (algebraMap F L)
adjoin_rootSet : ⨆ x : K, adjoin F ((minpoly F x).rootSet L) = ⊤
/- TODO: show `IsNormalClosure F K L ↔ IsNormalClosure F (integralClosure F K) L`; we can't state
this yet because `integralClosure F K` needs to have a `Field` instance. -/
/-- The normal closure of `K/F` in `L/F`. -/
noncomputable def normalClosure : IntermediateField F L :=
⨆ f : K →ₐ[F] L, f.fieldRange
lemma normalClosure_def : normalClosure F K L = ⨆ f : K →ₐ[F] L, f.fieldRange :=
rfl
variable {F K L}
/-- A normal closure is always normal. -/
lemma IsNormalClosure.normal [h : IsNormalClosure F K L] : Normal F L :=
Normal.of_algEquiv topEquiv (h := h.adjoin_rootSet ▸ IntermediateField.normal_iSup (h :=
fun _ ↦ Normal.of_isSplittingField (hFEp := adjoin_rootSet_isSplittingField <| h.splits _)))
lemma normalClosure_le_iff {K' : IntermediateField F L} :
normalClosure F K L ≤ K' ↔ ∀ f : K →ₐ[F] L, f.fieldRange ≤ K' :=
iSup_le_iff
lemma AlgHom.fieldRange_le_normalClosure (f : K →ₐ[F] L) : f.fieldRange ≤ normalClosure F K L :=
le_iSup AlgHom.fieldRange f
namespace Algebra.IsAlgebraic
variable [Algebra.IsAlgebraic F K]
lemma normalClosure_le_iSup_adjoin :
normalClosure F K L ≤ ⨆ x : K, IntermediateField.adjoin F ((minpoly F x).rootSet L) :=
iSup_le fun f _ ⟨x, hx⟩ ↦ le_iSup (α := IntermediateField F L) _ x <|
IntermediateField.subset_adjoin F _ <| by
rw [mem_rootSet_of_ne (minpoly.ne_zero (Algebra.IsIntegral.isIntegral x)), ← hx,
AlgHom.toRingHom_eq_coe, AlgHom.coe_toRingHom, aeval_algHom_apply, minpoly.aeval, map_zero]
variable (splits : ∀ x : K, (minpoly F x).Splits (algebraMap F L))
lemma normalClosure_eq_iSup_adjoin_of_splits :
normalClosure F K L = ⨆ x : K, IntermediateField.adjoin F ((minpoly F x).rootSet L) :=
normalClosure_le_iSup_adjoin.antisymm <|
iSup_le fun x ↦ IntermediateField.adjoin_le_iff.mpr fun _ hy ↦
let ⟨φ, hφ⟩ := IntermediateField.exists_algHom_of_splits_of_aeval
(fun x ↦ ⟨Algebra.IsIntegral.isIntegral x, splits x⟩) (mem_rootSet.mp hy).2
le_iSup AlgHom.fieldRange φ ⟨x, hφ⟩
/-- If `K/F` is algebraic, the "generated by roots" condition in IsNormalClosure can be replaced
by "generated by images of embeddings". -/
lemma isNormalClosure_iff : IsNormalClosure F K L ↔
(∀ x : K, (minpoly F x).Splits (algebraMap F L)) ∧ normalClosure F K L = ⊤ := by
refine ⟨fun ⟨splits, h⟩ ↦ ⟨splits, ?_⟩, fun ⟨splits, h⟩ ↦ ⟨splits, ?_⟩⟩ <;>
simpa only [normalClosure_eq_iSup_adjoin_of_splits splits] using h
-- TODO: IntermediateField.isNormalClosure_iff similar to IntermediateField.isSplittingField_iff
/-- `normalClosure F K L` is a valid normal closure if `K/F` is algebraic
and all minimal polynomials of `K/F` splits in `L/F`. -/
lemma isNormalClosure_normalClosure : IsNormalClosure F K (normalClosure F K L) := by
rw [isNormalClosure_iff]; constructor
· rw [normalClosure_eq_iSup_adjoin_of_splits splits]
exact fun x ↦ splits_of_splits (splits x) ((IntermediateField.subset_adjoin F _).trans <|
SetLike.coe_subset_coe.mpr <| by apply le_iSup _ x)
simp_rw [normalClosure, ← top_le_iff]
refine fun x _ ↦ (IntermediateField.val _).injective.mem_set_image.mp ?_
change x.val ∈ IntermediateField.map (IntermediateField.val _) _
rw [IntermediateField.map_iSup]
refine (iSup_le fun f ↦ ?_ : normalClosure F K L ≤ _) x.2
refine le_iSup_of_le (f.codRestrict _ fun x ↦ f.fieldRange_le_normalClosure ⟨x, rfl⟩) ?_
rw [AlgHom.map_fieldRange, val, AlgHom.val_comp_codRestrict]
end Algebra.IsAlgebraic
/-- A normal closure of `K/F` embeds into any `L/F`
where the minimal polynomials of `K/F` splits. -/
noncomputable def IsNormalClosure.lift [h : IsNormalClosure F K L] {L'} [Field L'] [Algebra F L']
(splits : ∀ x : K, (minpoly F x).Splits (algebraMap F L')) : L →ₐ[F] L' := by
have := h.adjoin_rootSet; rw [← gc.l_iSup] at this
refine Nonempty.some <| nonempty_algHom_of_adjoin_splits
(fun x hx ↦ ⟨isAlgebraic_iff_isIntegral.mp ((h.normal).isAlgebraic x), ?_⟩) this
obtain ⟨y, hx⟩ := Set.mem_iUnion.mp hx
by_cases iy : IsIntegral F y
· exact splits_of_splits_of_dvd _ (minpoly.ne_zero iy)
(splits y) (minpoly.dvd F x (mem_rootSet.mp hx).2)
· simp [minpoly.eq_zero iy] at hx
/-- Normal closures of `K/F` are unique up to F-algebra isomorphisms. -/
noncomputable def IsNormalClosure.equiv {L'} [Field L'] [Algebra F L']
[h : IsNormalClosure F K L] [h' : IsNormalClosure F K L'] : L ≃ₐ[F] L' :=
have := h.normal
AlgEquiv.ofBijective _ <| And.left <|
Normal.toIsAlgebraic.algHom_bijective₂
(IsNormalClosure.lift fun _ : K ↦ h'.splits _)
(IsNormalClosure.lift fun _ : K ↦ h.splits _)
variable (F K L)
instance isNormalClosure_normalClosure [ne : Nonempty (K →ₐ[F] L)] [h : Normal F L] :
IsNormalClosure F K (normalClosure F K L) := by
have ⟨φ⟩ := ne
apply (h.toIsAlgebraic.of_injective φ φ.injective).isNormalClosure_normalClosure
simp_rw [← minpoly.algHom_eq _ φ.injective]
exact fun _ ↦ h.splits _
theorem normalClosure_eq_iSup_adjoin' [ne : Nonempty (K →ₐ[F] L)] [h : Normal F L] :
normalClosure F K L = ⨆ x : K, adjoin F ((minpoly F x).rootSet L) := by
have ⟨φ⟩ := ne
refine h.toIsAlgebraic.of_injective φ φ.injective
|>.normalClosure_eq_iSup_adjoin_of_splits fun x ↦ ?_
rw [← minpoly.algHom_eq _ φ.injective]
apply h.splits
theorem normalClosure_eq_iSup_adjoin [Algebra K L] [IsScalarTower F K L] [Normal F L] :
normalClosure F K L = ⨆ x : K, adjoin F ((minpoly F x).rootSet L) :=
normalClosure_eq_iSup_adjoin' (ne := ⟨IsScalarTower.toAlgHom F K L⟩)
namespace normalClosure
/-- All `F`-`AlgHom`s from `K` to `L` factor through the normal closure of `K/F` in `L/F`. -/
noncomputable def algHomEquiv : (K →ₐ[F] normalClosure F K L) ≃ (K →ₐ[F] L) where
toFun := (normalClosure F K L).val.comp
invFun f := f.codRestrict _ fun x ↦ f.fieldRange_le_normalClosure ⟨x, rfl⟩
left_inv _ := rfl
right_inv _ := rfl
instance normal [h : Normal F L] : Normal F (normalClosure F K L) := by
obtain _ | φ := isEmpty_or_nonempty (K →ₐ[F] L)
· rw [normalClosure, iSup_of_empty]; exact Normal.of_algEquiv (botEquiv F L).symm
· exact (isNormalClosure_normalClosure F K L).normal
instance is_finiteDimensional [FiniteDimensional F K] :
FiniteDimensional F (normalClosure F K L) := by
haveI : ∀ f : K →ₐ[F] L, FiniteDimensional F f.fieldRange := fun f ↦
f.toLinearMap.finiteDimensional_range
apply IntermediateField.finiteDimensional_iSup_of_finite
variable [Algebra K L] [IsScalarTower F K L]
noncomputable instance algebra :
Algebra K (normalClosure F K L) :=
IntermediateField.algebra
{ ⨆ f : K →ₐ[F] L, f.fieldRange with
algebraMap_mem' := fun r ↦ (toAlgHom F K L).fieldRange_le_normalClosure ⟨r, rfl⟩ }
instance : IsScalarTower F K (normalClosure F K L) := by
apply of_algebraMap_eq'
ext x
exact algebraMap_apply F K L x
instance : IsScalarTower K (normalClosure F K L) L :=
of_algebraMap_eq' rfl
lemma restrictScalars_eq :
(toAlgHom K (normalClosure F K L) L).fieldRange.restrictScalars F = normalClosure F K L :=
SetLike.ext' Subtype.range_val
end normalClosure
variable {F K L}
open Cardinal in
/-- An extension `L/F` in which every minimal polynomial of `K/F` splits is maximal with respect
to `F`-embeddings of `K`, in the sense that `K →ₐ[F] L` achieves maximal cardinality.
We construct an explicit injective function from an arbitrary `K →ₐ[F] L'` into `K →ₐ[F] L`,
using an embedding of `normalClosure F K L'` into `L`. -/
noncomputable def Algebra.IsAlgebraic.algHomEmbeddingOfSplits [Algebra.IsAlgebraic F K]
(h : ∀ x : K, (minpoly F x).Splits (algebraMap F L)) (L' : Type*) [Field L'] [Algebra F L'] :
(K →ₐ[F] L') ↪ (K →ₐ[F] L) :=
let φ : ↑(⨆ x : K, IntermediateField.adjoin F ((minpoly F x).rootSet L')) →ₐ[F] L :=
Nonempty.some <| by
rw [← gc.l_iSup]
refine nonempty_algHom_adjoin_of_splits fun x hx ↦ ?_
obtain ⟨y, hx⟩ := Set.mem_iUnion.mp hx
refine ⟨isAlgebraic_iff_isIntegral.mp (isAlgebraic_of_mem_rootSet hx), ?_⟩
by_cases iy : IsIntegral F y
· exact splits_of_splits_of_dvd _ (minpoly.ne_zero iy)
(h y) (minpoly.dvd F x (mem_rootSet.mp hx).2)
· simp [minpoly.eq_zero iy] at hx
let φ' := (φ.comp <| inclusion normalClosure_le_iSup_adjoin)
{ toFun := φ'.comp ∘ (normalClosure.algHomEquiv F K L').symm
inj' := fun _ _ h ↦ (normalClosure.algHomEquiv F K L').symm.injective <| by
rw [DFunLike.ext'_iff] at h ⊢
exact φ'.injective.comp_left h }
namespace IntermediateField
variable (K K' : IntermediateField F L)
lemma le_normalClosure : K ≤ normalClosure F K L :=
K.fieldRange_val.symm.trans_le K.val.fieldRange_le_normalClosure
lemma normalClosure_of_normal [Normal F K] : normalClosure F K L = K := by
simp only [normalClosure_def, AlgHom.fieldRange_of_normal, iSup_const]
variable [Normal F L]
lemma normalClosure_def' : normalClosure F K L = ⨆ f : L →ₐ[F] L, K.map f := by
refine (normalClosure_def F K L).trans (le_antisymm (iSup_le (fun f ↦ ?_)) (iSup_le (fun f ↦ ?_)))
· exact le_iSup_of_le (f.liftNormal L) (fun b ⟨a, h⟩ ↦ ⟨a, a.2, h ▸ f.liftNormal_commutes L a⟩)
· exact le_iSup_of_le (f.comp K.val) (fun b ⟨a, h⟩ ↦ ⟨⟨a, h.1⟩, h.2⟩)
lemma normalClosure_def'' : normalClosure F K L = ⨆ f : L ≃ₐ[F] L, K.map f := by
refine (normalClosure_def' K).trans (le_antisymm (iSup_le (fun f ↦ ?_)) (iSup_le (fun f ↦ ?_)))
· exact le_iSup_of_le (f.restrictNormal' L)
(fun b ⟨a, h⟩ ↦ ⟨a, h.1, h.2 ▸ f.restrictNormal_commutes L a⟩)
· exact le_iSup_of_le f le_rfl
lemma normalClosure_mono (h : K ≤ K') : normalClosure F K L ≤ normalClosure F K' L := by
rw [normalClosure_def', normalClosure_def']
exact iSup_mono (fun f ↦ map_mono f h)
variable (F L)
/-- `normalClosure` as a `ClosureOperator`. -/
@[simps]
noncomputable def closureOperator : ClosureOperator (IntermediateField F L) where
toFun := fun K ↦ normalClosure F K L
monotone' := fun K K' ↦ normalClosure_mono K K'
le_closure' := le_normalClosure
idempotent' := fun K ↦ normalClosure_of_normal (normalClosure F K L)
variable {K : IntermediateField F L} {F L}
lemma normal_iff_normalClosure_eq : Normal F K ↔ normalClosure F K L = K :=
⟨@normalClosure_of_normal (K := K), fun h ↦ h ▸ normalClosure.normal F K L⟩
lemma normal_iff_normalClosure_le : Normal F K ↔ normalClosure F K L ≤ K :=
normal_iff_normalClosure_eq.trans (le_normalClosure K).le_iff_eq.symm
lemma normal_iff_forall_fieldRange_le : Normal F K ↔ ∀ σ : K →ₐ[F] L, σ.fieldRange ≤ K := by
rw [normal_iff_normalClosure_le, normalClosure_def, iSup_le_iff]
lemma normal_iff_forall_map_le : Normal F K ↔ ∀ σ : L →ₐ[F] L, K.map σ ≤ K := by
rw [normal_iff_normalClosure_le, normalClosure_def', iSup_le_iff]
lemma normal_iff_forall_map_le' : Normal F K ↔ ∀ σ : L ≃ₐ[F] L, K.map ↑σ ≤ K := by
rw [normal_iff_normalClosure_le, normalClosure_def'', iSup_le_iff]
lemma normal_iff_forall_fieldRange_eq : Normal F K ↔ ∀ σ : K →ₐ[F] L, σ.fieldRange = K :=
⟨@AlgHom.fieldRange_of_normal (E := K), normal_iff_forall_fieldRange_le.2 ∘ fun h σ ↦ (h σ).le⟩
lemma normal_iff_forall_map_eq : Normal F K ↔ ∀ σ : L →ₐ[F] L, K.map σ = K :=
⟨fun h σ ↦ (K.fieldRange_val ▸ AlgHom.map_fieldRange K.val σ).trans
(normal_iff_forall_fieldRange_eq.1 h _), fun h ↦ normal_iff_forall_map_le.2 (fun σ ↦ (h σ).le)⟩
lemma normal_iff_forall_map_eq' : Normal F K ↔ ∀ σ : L ≃ₐ[F] L, K.map ↑σ = K :=
⟨fun h σ ↦ normal_iff_forall_map_eq.1 h σ, fun h ↦ normal_iff_forall_map_le'.2 (fun σ ↦ (h σ).le)⟩
end IntermediateField
|
FieldTheory\Perfect.lean | /-
Copyright (c) 2023 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.FieldTheory.Separable
import Mathlib.FieldTheory.SplittingField.Construction
import Mathlib.Algebra.CharP.Reduced
/-!
# Perfect fields and rings
In this file we define perfect fields, together with a generalisation to (commutative) rings in
prime characteristic.
## Main definitions / statements:
* `PerfectRing`: a ring of characteristic `p` (prime) is said to be perfect in the sense of Serre,
if its absolute Frobenius map `x ↦ xᵖ` is bijective.
* `PerfectField`: a field `K` is said to be perfect if every irreducible polynomial over `K` is
separable.
* `PerfectRing.toPerfectField`: a field that is perfect in the sense of Serre is a perfect field.
* `PerfectField.toPerfectRing`: a perfect field of characteristic `p` (prime) is perfect in the
sense of Serre.
* `PerfectField.ofCharZero`: all fields of characteristic zero are perfect.
* `PerfectField.ofFinite`: all finite fields are perfect.
* `PerfectField.separable_iff_squarefree`: a polynomial over a perfect field is separable iff
it is square-free.
* `Algebra.IsAlgebraic.isSeparable_of_perfectField`, `Algebra.IsAlgebraic.perfectField`:
if `L / K` is an algebraic extension, `K` is a perfect field, then `L / K` is separable,
and `L` is also a perfect field.
-/
open Function Polynomial
/-- A perfect ring of characteristic `p` (prime) in the sense of Serre.
NB: This is not related to the concept with the same name introduced by Bass (related to projective
covers of modules). -/
class PerfectRing (R : Type*) (p : ℕ) [CommSemiring R] [ExpChar R p] : Prop where
/-- A ring is perfect if the Frobenius map is bijective. -/
bijective_frobenius : Bijective <| frobenius R p
section PerfectRing
variable (R : Type*) (p m n : ℕ) [CommSemiring R] [ExpChar R p]
/-- For a reduced ring, surjectivity of the Frobenius map is a sufficient condition for perfection.
-/
lemma PerfectRing.ofSurjective (R : Type*) (p : ℕ) [CommRing R] [ExpChar R p]
[IsReduced R] (h : Surjective <| frobenius R p) : PerfectRing R p :=
⟨frobenius_inj R p, h⟩
instance PerfectRing.ofFiniteOfIsReduced (R : Type*) [CommRing R] [ExpChar R p]
[Finite R] [IsReduced R] : PerfectRing R p :=
ofSurjective _ _ <| Finite.surjective_of_injective (frobenius_inj R p)
variable [PerfectRing R p]
@[simp]
theorem bijective_frobenius : Bijective (frobenius R p) := PerfectRing.bijective_frobenius
theorem bijective_iterateFrobenius : Bijective (iterateFrobenius R p n) :=
coe_iterateFrobenius R p n ▸ (bijective_frobenius R p).iterate n
@[simp]
theorem injective_frobenius : Injective (frobenius R p) := (bijective_frobenius R p).1
@[simp]
theorem surjective_frobenius : Surjective (frobenius R p) := (bijective_frobenius R p).2
/-- The Frobenius automorphism for a perfect ring. -/
@[simps! apply]
noncomputable def frobeniusEquiv : R ≃+* R :=
RingEquiv.ofBijective (frobenius R p) PerfectRing.bijective_frobenius
@[simp]
theorem coe_frobeniusEquiv : ⇑(frobeniusEquiv R p) = frobenius R p := rfl
theorem frobeniusEquiv_def (x : R) : frobeniusEquiv R p x = x ^ p := rfl
/-- The iterated Frobenius automorphism for a perfect ring. -/
@[simps! apply]
noncomputable def iterateFrobeniusEquiv : R ≃+* R :=
RingEquiv.ofBijective (iterateFrobenius R p n) (bijective_iterateFrobenius R p n)
@[simp]
theorem coe_iterateFrobeniusEquiv : ⇑(iterateFrobeniusEquiv R p n) = iterateFrobenius R p n := rfl
theorem iterateFrobeniusEquiv_def (x : R) : iterateFrobeniusEquiv R p n x = x ^ p ^ n := rfl
theorem iterateFrobeniusEquiv_add_apply (x : R) : iterateFrobeniusEquiv R p (m + n) x =
iterateFrobeniusEquiv R p m (iterateFrobeniusEquiv R p n x) :=
iterateFrobenius_add_apply R p m n x
theorem iterateFrobeniusEquiv_add : iterateFrobeniusEquiv R p (m + n) =
(iterateFrobeniusEquiv R p n).trans (iterateFrobeniusEquiv R p m) :=
RingEquiv.ext (iterateFrobeniusEquiv_add_apply R p m n)
theorem iterateFrobeniusEquiv_symm_add_apply (x : R) : (iterateFrobeniusEquiv R p (m + n)).symm x =
(iterateFrobeniusEquiv R p m).symm ((iterateFrobeniusEquiv R p n).symm x) :=
(iterateFrobeniusEquiv R p (m + n)).injective <| by rw [RingEquiv.apply_symm_apply, add_comm,
iterateFrobeniusEquiv_add_apply, RingEquiv.apply_symm_apply, RingEquiv.apply_symm_apply]
theorem iterateFrobeniusEquiv_symm_add : (iterateFrobeniusEquiv R p (m + n)).symm =
(iterateFrobeniusEquiv R p n).symm.trans (iterateFrobeniusEquiv R p m).symm :=
RingEquiv.ext (iterateFrobeniusEquiv_symm_add_apply R p m n)
theorem iterateFrobeniusEquiv_zero_apply (x : R) : iterateFrobeniusEquiv R p 0 x = x := by
rw [iterateFrobeniusEquiv_def, pow_zero, pow_one]
theorem iterateFrobeniusEquiv_one_apply (x : R) : iterateFrobeniusEquiv R p 1 x = x ^ p := by
rw [iterateFrobeniusEquiv_def, pow_one]
@[simp]
theorem iterateFrobeniusEquiv_zero : iterateFrobeniusEquiv R p 0 = RingEquiv.refl R :=
RingEquiv.ext (iterateFrobeniusEquiv_zero_apply R p)
@[simp]
theorem iterateFrobeniusEquiv_one : iterateFrobeniusEquiv R p 1 = frobeniusEquiv R p :=
RingEquiv.ext (iterateFrobeniusEquiv_one_apply R p)
theorem iterateFrobeniusEquiv_eq_pow : iterateFrobeniusEquiv R p n = frobeniusEquiv R p ^ n :=
DFunLike.ext' <| show _ = ⇑(RingAut.toPerm _ _) by
rw [map_pow, Equiv.Perm.coe_pow]; exact (pow_iterate p n).symm
theorem iterateFrobeniusEquiv_symm :
(iterateFrobeniusEquiv R p n).symm = (frobeniusEquiv R p).symm ^ n := by
rw [iterateFrobeniusEquiv_eq_pow]; exact (inv_pow _ _).symm
@[simp]
theorem frobeniusEquiv_symm_apply_frobenius (x : R) :
(frobeniusEquiv R p).symm (frobenius R p x) = x :=
leftInverse_surjInv PerfectRing.bijective_frobenius x
@[simp]
theorem frobenius_apply_frobeniusEquiv_symm (x : R) :
frobenius R p ((frobeniusEquiv R p).symm x) = x :=
surjInv_eq _ _
@[simp]
theorem frobenius_comp_frobeniusEquiv_symm :
(frobenius R p).comp (frobeniusEquiv R p).symm = RingHom.id R := by
ext; simp
@[simp]
theorem frobeniusEquiv_symm_comp_frobenius :
((frobeniusEquiv R p).symm : R →+* R).comp (frobenius R p) = RingHom.id R := by
ext; simp
@[simp]
theorem frobeniusEquiv_symm_pow_p (x : R) : ((frobeniusEquiv R p).symm x) ^ p = x :=
frobenius_apply_frobeniusEquiv_symm R p x
theorem injective_pow_p {x y : R} (h : x ^ p = y ^ p) : x = y := (frobeniusEquiv R p).injective h
lemma polynomial_expand_eq (f : R[X]) :
expand R p f = (f.map (frobeniusEquiv R p).symm) ^ p := by
rw [← (f.map (S := R) (frobeniusEquiv R p).symm).expand_char p, map_expand, map_map,
frobenius_comp_frobeniusEquiv_symm, map_id]
@[simp]
theorem not_irreducible_expand (R p) [CommSemiring R] [Fact p.Prime] [CharP R p] [PerfectRing R p]
(f : R[X]) : ¬ Irreducible (expand R p f) := by
rw [polynomial_expand_eq]
exact not_irreducible_pow (Fact.out : p.Prime).ne_one
instance instPerfectRingProd (S : Type*) [CommSemiring S] [ExpChar S p] [PerfectRing S p] :
PerfectRing (R × S) p where
bijective_frobenius := (bijective_frobenius R p).prodMap (bijective_frobenius S p)
end PerfectRing
/-- A perfect field.
See also `PerfectRing` for a generalisation in positive characteristic. -/
class PerfectField (K : Type*) [Field K] : Prop where
/-- A field is perfect if every irreducible polynomial is separable. -/
separable_of_irreducible : ∀ {f : K[X]}, Irreducible f → f.Separable
lemma PerfectRing.toPerfectField (K : Type*) (p : ℕ)
[Field K] [ExpChar K p] [PerfectRing K p] : PerfectField K := by
obtain hp | ⟨hp⟩ := ‹ExpChar K p›
· exact ⟨Irreducible.separable⟩
refine PerfectField.mk fun hf ↦ ?_
rcases separable_or p hf with h | ⟨-, g, -, rfl⟩
· assumption
· exfalso; revert hf; haveI := Fact.mk hp; simp
namespace PerfectField
variable {K : Type*} [Field K]
instance ofCharZero [CharZero K] : PerfectField K := ⟨Irreducible.separable⟩
instance ofFinite [Finite K] : PerfectField K := by
obtain ⟨p, _instP⟩ := CharP.exists K
have : Fact p.Prime := ⟨CharP.char_is_prime K p⟩
exact PerfectRing.toPerfectField K p
variable [PerfectField K]
/-- A perfect field of characteristic `p` (prime) is a perfect ring. -/
instance toPerfectRing (p : ℕ) [ExpChar K p] : PerfectRing K p := by
refine PerfectRing.ofSurjective _ _ fun y ↦ ?_
let f : K[X] := X ^ p - C y
let L := f.SplittingField
let ι := algebraMap K L
have hf_deg : f.degree ≠ 0 := by
rw [degree_X_pow_sub_C (expChar_pos K p) y, p.cast_ne_zero]; exact (expChar_pos K p).ne'
let a : L := f.rootOfSplits ι (SplittingField.splits f) hf_deg
have hfa : aeval a f = 0 := by rw [aeval_def, map_rootOfSplits _ (SplittingField.splits f) hf_deg]
have ha_pow : a ^ p = ι y := by rwa [map_sub, aeval_X_pow, aeval_C, sub_eq_zero] at hfa
let g : K[X] := minpoly K a
suffices (g.map ι).natDegree = 1 by
rw [g.natDegree_map, ← degree_eq_iff_natDegree_eq_of_pos Nat.one_pos] at this
obtain ⟨a' : K, ha' : ι a' = a⟩ := minpoly.mem_range_of_degree_eq_one K a this
refine ⟨a', NoZeroSMulDivisors.algebraMap_injective K L ?_⟩
rw [RingHom.map_frobenius, ha', frobenius_def, ha_pow]
have hg_dvd : g.map ι ∣ (X - C a) ^ p := by
convert Polynomial.map_dvd ι (minpoly.dvd K a hfa)
rw [sub_pow_expChar, Polynomial.map_sub, Polynomial.map_pow, map_X, map_C, ← ha_pow, map_pow]
have ha : IsIntegral K a := .of_finite K a
have hg_pow : g.map ι = (X - C a) ^ (g.map ι).natDegree := by
obtain ⟨q, -, hq⟩ := (dvd_prime_pow (prime_X_sub_C a) p).mp hg_dvd
rw [eq_of_monic_of_associated ((minpoly.monic ha).map ι) ((monic_X_sub_C a).pow q) hq,
natDegree_pow, natDegree_X_sub_C, mul_one]
have hg_sep : (g.map ι).Separable := (separable_of_irreducible <| minpoly.irreducible ha).map
rw [hg_pow] at hg_sep
refine (Separable.of_pow (not_isUnit_X_sub_C a) ?_ hg_sep).2
rw [g.natDegree_map ι, ← Nat.pos_iff_ne_zero, natDegree_pos_iff_degree_pos]
exact minpoly.degree_pos ha
theorem separable_iff_squarefree {g : K[X]} : g.Separable ↔ Squarefree g := by
refine ⟨Separable.squarefree, fun sqf ↦ isCoprime_of_irreducible_dvd (sqf.ne_zero ·.1) ?_⟩
rintro p (h : Irreducible p) ⟨q, rfl⟩ (dvd : p ∣ derivative (p * q))
replace dvd : p ∣ q := by
rw [derivative_mul, dvd_add_left (dvd_mul_right p _)] at dvd
exact (separable_of_irreducible h).dvd_of_dvd_mul_left dvd
exact (h.1 : ¬ IsUnit p) (sqf _ <| mul_dvd_mul_left _ dvd)
end PerfectField
/-- If `L / K` is an algebraic extension, `K` is a perfect field, then `L / K` is separable. -/
instance Algebra.IsAlgebraic.isSeparable_of_perfectField {K L : Type*} [Field K] [Field L]
[Algebra K L] [Algebra.IsAlgebraic K L] [PerfectField K] : Algebra.IsSeparable K L :=
⟨fun x ↦ PerfectField.separable_of_irreducible <|
minpoly.irreducible (Algebra.IsIntegral.isIntegral x)⟩
/-- If `L / K` is an algebraic extension, `K` is a perfect field, then so is `L`. -/
theorem Algebra.IsAlgebraic.perfectField {K L : Type*} [Field K] [Field L] [Algebra K L]
[Algebra.IsAlgebraic K L] [PerfectField K] : PerfectField L := ⟨fun {f} hf ↦ by
obtain ⟨_, _, hi, h⟩ := hf.exists_dvd_monic_irreducible_of_isIntegral (K := K)
exact (PerfectField.separable_of_irreducible hi).map |>.of_dvd h⟩
namespace Polynomial
variable {R : Type*} [CommRing R] [IsDomain R] (p n : ℕ) [ExpChar R p] (f : R[X])
open Multiset
theorem roots_expand_pow_map_iterateFrobenius_le :
(expand R (p ^ n) f).roots.map (iterateFrobenius R p n) ≤ p ^ n • f.roots := by
classical
refine le_iff_count.2 fun r ↦ ?_
by_cases h : ∃ s, r = s ^ p ^ n
· obtain ⟨s, rfl⟩ := h
simp_rw [count_nsmul, count_roots, ← rootMultiplicity_expand_pow, ← count_roots, count_map,
count_eq_card_filter_eq]
exact card_le_card (monotone_filter_right _ fun _ h ↦ iterateFrobenius_inj R p n h)
convert Nat.zero_le _
simp_rw [count_map, card_eq_zero]
exact ext' fun t ↦ count_zero t ▸ count_filter_of_neg fun h' ↦ h ⟨t, h'⟩
theorem roots_expand_map_frobenius_le :
(expand R p f).roots.map (frobenius R p) ≤ p • f.roots := by
rw [← iterateFrobenius_one]
convert ← roots_expand_pow_map_iterateFrobenius_le p 1 f <;> apply pow_one
theorem roots_expand_pow_image_iterateFrobenius_subset [DecidableEq R] :
(expand R (p ^ n) f).roots.toFinset.image (iterateFrobenius R p n) ⊆ f.roots.toFinset := by
rw [Finset.image_toFinset, ← (roots f).toFinset_nsmul _ (expChar_pow_pos R p n).ne',
toFinset_subset]
exact subset_of_le (roots_expand_pow_map_iterateFrobenius_le p n f)
theorem roots_expand_image_frobenius_subset [DecidableEq R] :
(expand R p f).roots.toFinset.image (frobenius R p) ⊆ f.roots.toFinset := by
rw [← iterateFrobenius_one]
convert ← roots_expand_pow_image_iterateFrobenius_subset p 1 f
apply pow_one
section PerfectRing
variable {p n f}
variable [PerfectRing R p]
theorem roots_expand_pow :
(expand R (p ^ n) f).roots = p ^ n • f.roots.map (iterateFrobeniusEquiv R p n).symm := by
classical
refine ext' fun r ↦ ?_
rw [count_roots, rootMultiplicity_expand_pow, ← count_roots, count_nsmul, count_map,
count_eq_card_filter_eq]; congr; ext
exact (iterateFrobeniusEquiv R p n).eq_symm_apply.symm
theorem roots_expand : (expand R p f).roots = p • f.roots.map (frobeniusEquiv R p).symm := by
conv_lhs => rw [← pow_one p, roots_expand_pow, iterateFrobeniusEquiv_eq_pow, pow_one]
rfl
theorem roots_X_pow_char_pow_sub_C {y : R} :
(X ^ p ^ n - C y).roots = p ^ n • {(iterateFrobeniusEquiv R p n).symm y} := by
have H := roots_expand_pow (p := p) (n := n) (f := X - C y)
rwa [roots_X_sub_C, Multiset.map_singleton, map_sub, expand_X, expand_C] at H
theorem roots_X_pow_char_pow_sub_C_pow {y : R} {m : ℕ} :
((X ^ p ^ n - C y) ^ m).roots = (m * p ^ n) • {(iterateFrobeniusEquiv R p n).symm y} := by
rw [roots_pow, roots_X_pow_char_pow_sub_C, mul_smul]
theorem roots_X_pow_char_sub_C {y : R} :
(X ^ p - C y).roots = p • {(frobeniusEquiv R p).symm y} := by
have H := roots_X_pow_char_pow_sub_C (p := p) (n := 1) (y := y)
rwa [pow_one, iterateFrobeniusEquiv_one] at H
theorem roots_X_pow_char_sub_C_pow {y : R} {m : ℕ} :
((X ^ p - C y) ^ m).roots = (m * p) • {(frobeniusEquiv R p).symm y} := by
have H := roots_X_pow_char_pow_sub_C_pow (p := p) (n := 1) (y := y) (m := m)
rwa [pow_one, iterateFrobeniusEquiv_one] at H
theorem roots_expand_pow_map_iterateFrobenius :
(expand R (p ^ n) f).roots.map (iterateFrobenius R p n) = p ^ n • f.roots := by
simp_rw [← coe_iterateFrobeniusEquiv, roots_expand_pow, Multiset.map_nsmul,
Multiset.map_map, comp_apply, RingEquiv.apply_symm_apply, map_id']
theorem roots_expand_map_frobenius : (expand R p f).roots.map (frobenius R p) = p • f.roots := by
simp [roots_expand, Multiset.map_nsmul]
theorem roots_expand_image_iterateFrobenius [DecidableEq R] :
(expand R (p ^ n) f).roots.toFinset.image (iterateFrobenius R p n) = f.roots.toFinset := by
rw [Finset.image_toFinset, roots_expand_pow_map_iterateFrobenius,
(roots f).toFinset_nsmul _ (expChar_pow_pos R p n).ne']
theorem roots_expand_image_frobenius [DecidableEq R] :
(expand R p f).roots.toFinset.image (frobenius R p) = f.roots.toFinset := by
rw [Finset.image_toFinset, roots_expand_map_frobenius,
(roots f).toFinset_nsmul _ (expChar_pos R p).ne']
end PerfectRing
variable [DecidableEq R]
/-- If `f` is a polynomial over an integral domain `R` of characteristic `p`, then there is
a map from the set of roots of `Polynomial.expand R p f` to the set of roots of `f`.
It's given by `x ↦ x ^ p`, see `rootsExpandToRoots_apply`. -/
noncomputable def rootsExpandToRoots : (expand R p f).roots.toFinset ↪ f.roots.toFinset where
toFun x := ⟨x ^ p, roots_expand_image_frobenius_subset p f (Finset.mem_image_of_mem _ x.2)⟩
inj' _ _ h := Subtype.ext (frobenius_inj R p <| Subtype.ext_iff.1 h)
@[simp]
theorem rootsExpandToRoots_apply (x) : (rootsExpandToRoots p f x : R) = x ^ p := rfl
open scoped Classical in
/-- If `f` is a polynomial over an integral domain `R` of characteristic `p`, then there is
a map from the set of roots of `Polynomial.expand R (p ^ n) f` to the set of roots of `f`.
It's given by `x ↦ x ^ (p ^ n)`, see `rootsExpandPowToRoots_apply`. -/
noncomputable def rootsExpandPowToRoots :
(expand R (p ^ n) f).roots.toFinset ↪ f.roots.toFinset where
toFun x := ⟨x ^ p ^ n,
roots_expand_pow_image_iterateFrobenius_subset p n f (Finset.mem_image_of_mem _ x.2)⟩
inj' _ _ h := Subtype.ext (iterateFrobenius_inj R p n <| Subtype.ext_iff.1 h)
@[simp]
theorem rootsExpandPowToRoots_apply (x) : (rootsExpandPowToRoots p n f x : R) = x ^ p ^ n := rfl
variable [PerfectRing R p]
/-- If `f` is a polynomial over a perfect integral domain `R` of characteristic `p`, then there is
a bijection from the set of roots of `Polynomial.expand R p f` to the set of roots of `f`.
It's given by `x ↦ x ^ p`, see `rootsExpandEquivRoots_apply`. -/
noncomputable def rootsExpandEquivRoots : (expand R p f).roots.toFinset ≃ f.roots.toFinset :=
((frobeniusEquiv R p).image _).trans <| .Set.ofEq <| show _ '' (setOf _) = setOf _ by
classical simp_rw [← roots_expand_image_frobenius (p := p) (f := f), Finset.mem_val,
Finset.setOf_mem, Finset.coe_image, RingEquiv.toEquiv_eq_coe, EquivLike.coe_coe,
frobeniusEquiv_apply]
@[simp]
theorem rootsExpandEquivRoots_apply (x) : (rootsExpandEquivRoots p f x : R) = x ^ p := rfl
/-- If `f` is a polynomial over a perfect integral domain `R` of characteristic `p`, then there is
a bijection from the set of roots of `Polynomial.expand R (p ^ n) f` to the set of roots of `f`.
It's given by `x ↦ x ^ (p ^ n)`, see `rootsExpandPowEquivRoots_apply`. -/
noncomputable def rootsExpandPowEquivRoots (n : ℕ) :
(expand R (p ^ n) f).roots.toFinset ≃ f.roots.toFinset :=
((iterateFrobeniusEquiv R p n).image _).trans <| .Set.ofEq <| show _ '' (setOf _) = setOf _ by
classical simp_rw [← roots_expand_image_iterateFrobenius (p := p) (f := f) (n := n),
Finset.mem_val, Finset.setOf_mem, Finset.coe_image, RingEquiv.toEquiv_eq_coe,
EquivLike.coe_coe, iterateFrobeniusEquiv_apply]
@[simp]
theorem rootsExpandPowEquivRoots_apply (n : ℕ) (x) :
(rootsExpandPowEquivRoots p f n x : R) = x ^ p ^ n := rfl
end Polynomial
|
FieldTheory\PerfectClosure.lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Yury Kudryashov
-/
import Mathlib.FieldTheory.Perfect
/-!
# The perfect closure of a characteristic `p` ring
## Main definitions
- `PerfectClosure`: the perfect closure of a characteristic `p` ring, which is the smallest
extension that makes frobenius surjective.
- `PerfectClosure.mk K p (n, x)`: for `n : ℕ` and `x : K` this is `x ^ (p ^ -n)` viewed as
an element of `PerfectClosure K p`. Every element of `PerfectClosure K p` is of this form
(`PerfectClosure.mk_surjective`).
- `PerfectClosure.of`: the structure map from `K` to `PerfectClosure K p`.
- `PerfectClosure.lift`: given a ring `K` of characteristic `p` and a perfect ring `L` of the same
characteristic, any homomorphism `K →+* L` can be lifted to `PerfectClosure K p`.
## Main results
- `PerfectClosure.induction_on`: to prove a result for all elements of the prefect closure, one only
needs to prove it for all elements of the form `x ^ (p ^ -n)`.
- `PerfectClosure.mk_mul_mk`, `PerfectClosure.one_def`, `PerfectClosure.mk_add_mk`,
`PerfectClosure.neg_mk`, `PerfectClosure.zero_def`, `PerfectClosure.mk_zero_zero`,
`PerfectClosure.mk_zero`, `PerfectClosure.mk_inv`, `PerfectClosure.mk_pow`:
how to do multiplication, addition, etc. on elements of form `x ^ (p ^ -n)`.
- `PerfectClosure.mk_eq_iff`: when does `x ^ (p ^ -n)` equal.
- `PerfectClosure.eq_iff`: same as `PerfectClosure.mk_eq_iff` but with additional assumption that
`K` being reduced, hence gives a simpler criterion.
- `PerfectClosure.instPerfectRing`: `PerfectClosure K p` is a perfect ring.
## Tags
perfect ring, perfect closure
-/
universe u v
open Function
section
variable (K : Type u) [CommRing K] (p : ℕ) [Fact p.Prime] [CharP K p]
/-- `PerfectClosure.R` is the relation `(n, x) ∼ (n + 1, x ^ p)` for `n : ℕ` and `x : K`.
`PerfectClosure K p` is the quotient by this relation. -/
@[mk_iff]
inductive PerfectClosure.R : ℕ × K → ℕ × K → Prop
| intro : ∀ n x, PerfectClosure.R (n, x) (n + 1, frobenius K p x)
/-- The perfect closure is the smallest extension that makes frobenius surjective. -/
def PerfectClosure : Type u :=
Quot (PerfectClosure.R K p)
end
namespace PerfectClosure
variable (K : Type u)
section Ring
variable [CommRing K] (p : ℕ) [Fact p.Prime] [CharP K p]
/-- `PerfectClosure.mk K p (n, x)` for `n : ℕ` and `x : K` is an element of `PerfectClosure K p`,
viewed as `x ^ (p ^ -n)`. Every element of `PerfectClosure K p` is of this form
(`PerfectClosure.mk_surjective`). -/
def mk (x : ℕ × K) : PerfectClosure K p :=
Quot.mk (R K p) x
theorem mk_surjective : Function.Surjective (mk K p) := surjective_quot_mk _
@[simp] theorem mk_succ_pow (m : ℕ) (x : K) : mk K p ⟨m + 1, x ^ p⟩ = mk K p ⟨m, x⟩ :=
Eq.symm <| Quot.sound (R.intro m x)
@[simp]
theorem quot_mk_eq_mk (x : ℕ × K) : (Quot.mk (R K p) x : PerfectClosure K p) = mk K p x :=
rfl
variable {K p}
/-- Lift a function `ℕ × K → L` to a function on `PerfectClosure K p`. -/
-- Porting note: removed `@[elab_as_elim]` for "unexpected eliminator resulting type L"
def liftOn {L : Type*} (x : PerfectClosure K p) (f : ℕ × K → L)
(hf : ∀ x y, R K p x y → f x = f y) : L :=
Quot.liftOn x f hf
@[simp]
theorem liftOn_mk {L : Sort _} (f : ℕ × K → L) (hf : ∀ x y, R K p x y → f x = f y) (x : ℕ × K) :
(mk K p x).liftOn f hf = f x :=
rfl
@[elab_as_elim]
theorem induction_on (x : PerfectClosure K p) {q : PerfectClosure K p → Prop}
(h : ∀ x, q (mk K p x)) : q x :=
Quot.inductionOn x h
variable (K p)
private theorem mul_aux_left (x1 x2 y : ℕ × K) (H : R K p x1 x2) :
mk K p (x1.1 + y.1, (frobenius K p)^[y.1] x1.2 * (frobenius K p)^[x1.1] y.2) =
mk K p (x2.1 + y.1, (frobenius K p)^[y.1] x2.2 * (frobenius K p)^[x2.1] y.2) :=
match x1, x2, H with
| _, _, R.intro n x =>
Quot.sound <| by
rw [← iterate_succ_apply, iterate_succ_apply', iterate_succ_apply', ← frobenius_mul,
Nat.succ_add]
apply R.intro
private theorem mul_aux_right (x y1 y2 : ℕ × K) (H : R K p y1 y2) :
mk K p (x.1 + y1.1, (frobenius K p)^[y1.1] x.2 * (frobenius K p)^[x.1] y1.2) =
mk K p (x.1 + y2.1, (frobenius K p)^[y2.1] x.2 * (frobenius K p)^[x.1] y2.2) :=
match y1, y2, H with
| _, _, R.intro n y =>
Quot.sound <| by
rw [← iterate_succ_apply, iterate_succ_apply', iterate_succ_apply', ← frobenius_mul]
apply R.intro
instance instMul : Mul (PerfectClosure K p) :=
⟨Quot.lift
(fun x : ℕ × K =>
Quot.lift
(fun y : ℕ × K =>
mk K p (x.1 + y.1, (frobenius K p)^[y.1] x.2 * (frobenius K p)^[x.1] y.2))
(mul_aux_right K p x))
fun x1 x2 (H : R K p x1 x2) =>
funext fun e => Quot.inductionOn e fun y => mul_aux_left K p x1 x2 y H⟩
@[simp]
theorem mk_mul_mk (x y : ℕ × K) :
mk K p x * mk K p y =
mk K p (x.1 + y.1, (frobenius K p)^[y.1] x.2 * (frobenius K p)^[x.1] y.2) :=
rfl
instance instCommMonoid : CommMonoid (PerfectClosure K p) :=
{ (inferInstance : Mul (PerfectClosure K p)) with
mul_assoc := fun e f g =>
Quot.inductionOn e fun ⟨m, x⟩ =>
Quot.inductionOn f fun ⟨n, y⟩ =>
Quot.inductionOn g fun ⟨s, z⟩ => by
simp only [quot_mk_eq_mk, mk_mul_mk] -- Porting note: added this line
apply congr_arg (Quot.mk _)
simp only [add_assoc, mul_assoc, iterate_map_mul, ← iterate_add_apply,
add_comm, add_left_comm]
one := mk K p (0, 1)
one_mul := fun e =>
Quot.inductionOn e fun ⟨n, x⟩ =>
congr_arg (Quot.mk _) <| by
simp only [iterate_map_one, iterate_zero_apply, one_mul, zero_add]
mul_one := fun e =>
Quot.inductionOn e fun ⟨n, x⟩ =>
congr_arg (Quot.mk _) <| by
simp only [iterate_map_one, iterate_zero_apply, mul_one, add_zero]
mul_comm := fun e f =>
Quot.inductionOn e fun ⟨m, x⟩ =>
Quot.inductionOn f fun ⟨n, y⟩ =>
congr_arg (Quot.mk _) <| by simp only [add_comm, mul_comm] }
theorem one_def : (1 : PerfectClosure K p) = mk K p (0, 1) :=
rfl
instance instInhabited : Inhabited (PerfectClosure K p) :=
⟨1⟩
private theorem add_aux_left (x1 x2 y : ℕ × K) (H : R K p x1 x2) :
mk K p (x1.1 + y.1, (frobenius K p)^[y.1] x1.2 + (frobenius K p)^[x1.1] y.2) =
mk K p (x2.1 + y.1, (frobenius K p)^[y.1] x2.2 + (frobenius K p)^[x2.1] y.2) :=
match x1, x2, H with
| _, _, R.intro n x =>
Quot.sound <| by
rw [← iterate_succ_apply, iterate_succ_apply', iterate_succ_apply', ← frobenius_add,
Nat.succ_add]
apply R.intro
private theorem add_aux_right (x y1 y2 : ℕ × K) (H : R K p y1 y2) :
mk K p (x.1 + y1.1, (frobenius K p)^[y1.1] x.2 + (frobenius K p)^[x.1] y1.2) =
mk K p (x.1 + y2.1, (frobenius K p)^[y2.1] x.2 + (frobenius K p)^[x.1] y2.2) :=
match y1, y2, H with
| _, _, R.intro n y =>
Quot.sound <| by
rw [← iterate_succ_apply, iterate_succ_apply', iterate_succ_apply', ← frobenius_add]
apply R.intro
instance instAdd : Add (PerfectClosure K p) :=
⟨Quot.lift
(fun x : ℕ × K =>
Quot.lift
(fun y : ℕ × K =>
mk K p (x.1 + y.1, (frobenius K p)^[y.1] x.2 + (frobenius K p)^[x.1] y.2))
(add_aux_right K p x))
fun x1 x2 (H : R K p x1 x2) =>
funext fun e => Quot.inductionOn e fun y => add_aux_left K p x1 x2 y H⟩
@[simp]
theorem mk_add_mk (x y : ℕ × K) :
mk K p x + mk K p y =
mk K p (x.1 + y.1, (frobenius K p)^[y.1] x.2 + (frobenius K p)^[x.1] y.2) :=
rfl
instance instNeg : Neg (PerfectClosure K p) :=
⟨Quot.lift (fun x : ℕ × K => mk K p (x.1, -x.2)) fun x y (H : R K p x y) =>
match x, y, H with
| _, _, R.intro n x => Quot.sound <| by rw [← frobenius_neg]; apply R.intro⟩
@[simp]
theorem neg_mk (x : ℕ × K) : -mk K p x = mk K p (x.1, -x.2) :=
rfl
instance instZero : Zero (PerfectClosure K p) :=
⟨mk K p (0, 0)⟩
theorem zero_def : (0 : PerfectClosure K p) = mk K p (0, 0) :=
rfl
@[simp]
theorem mk_zero_zero : mk K p (0, 0) = 0 :=
rfl
-- Porting note: improved proof structure
theorem mk_zero (n : ℕ) : mk K p (n, 0) = 0 := by
induction' n with n ih
· rfl
rw [← ih]
symm
apply Quot.sound
have := R.intro (p := p) n (0 : K)
rwa [frobenius_zero K p] at this
-- Porting note: improved proof structure
theorem R.sound (m n : ℕ) (x y : K) (H : (frobenius K p)^[m] x = y) :
mk K p (n, x) = mk K p (m + n, y) := by
subst H
induction' m with m ih
· simp only [Nat.zero_eq, zero_add, iterate_zero_apply]
rw [ih, Nat.succ_add, iterate_succ']
apply Quot.sound
apply R.intro
instance instAddCommGroup : AddCommGroup (PerfectClosure K p) :=
{ (inferInstance : Add (PerfectClosure K p)),
(inferInstance : Neg (PerfectClosure K p)) with
add_assoc := fun e f g =>
Quot.inductionOn e fun ⟨m, x⟩ =>
Quot.inductionOn f fun ⟨n, y⟩ =>
Quot.inductionOn g fun ⟨s, z⟩ => by
simp only [quot_mk_eq_mk, mk_add_mk] -- Porting note: added this line
apply congr_arg (Quot.mk _)
simp only [iterate_map_add, ← iterate_add_apply, add_assoc, add_comm s _]
zero := 0
zero_add := fun e =>
Quot.inductionOn e fun ⟨n, x⟩ =>
congr_arg (Quot.mk _) <| by
simp only [iterate_map_zero, iterate_zero_apply, zero_add]
add_zero := fun e =>
Quot.inductionOn e fun ⟨n, x⟩ =>
congr_arg (Quot.mk _) <| by
simp only [iterate_map_zero, iterate_zero_apply, add_zero]
sub_eq_add_neg := fun a b => rfl
add_left_neg := fun e =>
Quot.inductionOn e fun ⟨n, x⟩ => by
simp only [quot_mk_eq_mk, neg_mk, mk_add_mk, iterate_map_neg, add_left_neg, mk_zero]
add_comm := fun e f =>
Quot.inductionOn e fun ⟨m, x⟩ =>
Quot.inductionOn f fun ⟨n, y⟩ => congr_arg (Quot.mk _) <| by simp only [add_comm]
nsmul := nsmulRec
zsmul := zsmulRec }
instance instCommRing : CommRing (PerfectClosure K p) :=
{ instAddCommGroup K p, AddMonoidWithOne.unary,
(inferInstance : CommMonoid (PerfectClosure K p)) with
-- Porting note: added `zero_mul`, `mul_zero`
zero_mul := fun a => by
refine Quot.inductionOn a fun ⟨m, x⟩ => ?_
rw [zero_def, quot_mk_eq_mk, mk_mul_mk]
simp only [zero_add, iterate_zero, id_eq, iterate_map_zero, zero_mul, mk_zero]
mul_zero := fun a => by
refine Quot.inductionOn a fun ⟨m, x⟩ => ?_
rw [zero_def, quot_mk_eq_mk, mk_mul_mk]
simp only [zero_add, iterate_zero, id_eq, iterate_map_zero, mul_zero, mk_zero]
left_distrib := fun e f g =>
Quot.inductionOn e fun ⟨m, x⟩ =>
Quot.inductionOn f fun ⟨n, y⟩ =>
Quot.inductionOn g fun ⟨s, z⟩ => by
simp only [quot_mk_eq_mk, mk_add_mk, mk_mul_mk] -- Porting note: added this line
simp only [add_assoc, add_comm, add_left_comm]
apply R.sound
simp only [iterate_map_mul, iterate_map_add, ← iterate_add_apply,
mul_add, add_comm, add_left_comm]
right_distrib := fun e f g =>
Quot.inductionOn e fun ⟨m, x⟩ =>
Quot.inductionOn f fun ⟨n, y⟩ =>
Quot.inductionOn g fun ⟨s, z⟩ => by
simp only [quot_mk_eq_mk, mk_add_mk, mk_mul_mk] -- Porting note: added this line
simp only [add_assoc, add_comm _ s, add_left_comm _ s]
apply R.sound
simp only [iterate_map_mul, iterate_map_add, ← iterate_add_apply,
add_mul, add_comm, add_left_comm] }
theorem mk_eq_iff (x y : ℕ × K) :
mk K p x = mk K p y ↔ ∃ z, (frobenius K p)^[y.1 + z] x.2 = (frobenius K p)^[x.1 + z] y.2 := by
constructor
· intro H
replace H := Quot.exact _ H
induction H with
| rel x y H => cases' H with n x; exact ⟨0, rfl⟩
| refl H => exact ⟨0, rfl⟩
| symm x y H ih => cases' ih with w ih; exact ⟨w, ih.symm⟩
| trans x y z H1 H2 ih1 ih2 =>
cases' ih1 with z1 ih1
cases' ih2 with z2 ih2
exists z2 + (y.1 + z1)
rw [← add_assoc, iterate_add_apply, ih1]
rw [← iterate_add_apply, add_comm, iterate_add_apply, ih2]
rw [← iterate_add_apply]
simp only [add_comm, add_left_comm]
intro H
cases' x with m x
cases' y with n y
cases' H with z H; dsimp only at H
rw [R.sound K p (n + z) m x _ rfl, R.sound K p (m + z) n y _ rfl, H]
rw [add_assoc, add_comm, add_comm z]
@[simp]
theorem mk_pow (x : ℕ × K) (n : ℕ) : mk K p x ^ n = mk K p (x.1, x.2 ^ n) := by
induction n with
| zero =>
rw [pow_zero, pow_zero, one_def, mk_eq_iff]
exact ⟨0, by simp_rw [← coe_iterateFrobenius, map_one]⟩
| succ n ih =>
rw [pow_succ, pow_succ, ih, mk_mul_mk, mk_eq_iff]
exact ⟨0, by simp_rw [iterate_frobenius, add_zero, mul_pow, ← pow_mul,
← pow_add, mul_assoc, ← pow_add]⟩
theorem natCast (n x : ℕ) : (x : PerfectClosure K p) = mk K p (n, x) := by
induction' n with n ih
· induction' x with x ih
· simp
rw [Nat.cast_succ, Nat.cast_succ, ih]
rfl
rw [ih]; apply Quot.sound
-- Porting note: was `conv`
suffices R K p (n, (x : K)) (Nat.succ n, frobenius K p (x : K)) by
rwa [frobenius_natCast K p x] at this
apply R.intro
@[deprecated (since := "2024-04-17")]
alias nat_cast := natCast
theorem intCast (x : ℤ) : (x : PerfectClosure K p) = mk K p (0, x) := by
induction x <;> simp only [Int.ofNat_eq_coe, Int.cast_natCast, Int.cast_negSucc, natCast K p 0]
rfl
@[deprecated (since := "2024-04-17")]
alias int_cast := intCast
theorem natCast_eq_iff (x y : ℕ) : (x : PerfectClosure K p) = y ↔ (x : K) = y := by
constructor <;> intro H
· rw [natCast K p 0, natCast K p 0, mk_eq_iff] at H
cases' H with z H
simpa only [zero_add, iterate_fixed (frobenius_natCast K p _)] using H
rw [natCast K p 0, natCast K p 0, H]
@[deprecated (since := "2024-04-17")]
alias nat_cast_eq_iff := natCast_eq_iff
instance instCharP : CharP (PerfectClosure K p) p := by
constructor; intro x; rw [← CharP.cast_eq_zero_iff K]
rw [← Nat.cast_zero, natCast_eq_iff, Nat.cast_zero]
theorem frobenius_mk (x : ℕ × K) :
(frobenius (PerfectClosure K p) p : PerfectClosure K p → PerfectClosure K p) (mk K p x) =
mk _ _ (x.1, x.2 ^ p) := by
simp only [frobenius_def]
exact mk_pow K p x p
/-- Embedding of `K` into `PerfectClosure K p` -/
def of : K →+* PerfectClosure K p where
toFun x := mk _ _ (0, x)
map_one' := rfl
map_mul' _ _ := rfl
map_zero' := rfl
map_add' _ _ := rfl
theorem of_apply (x : K) : of K p x = mk _ _ (0, x) :=
rfl
instance instReduced : IsReduced (PerfectClosure K p) where
eq_zero x := induction_on x fun x ⟨n, h⟩ ↦ by
replace h : mk K p x ^ p ^ n = 0 := by
rw [← Nat.sub_add_cancel ((Nat.lt_pow_self (Fact.out : p.Prime).one_lt n).le),
pow_add, h, mul_zero]
simp only [zero_def, mk_pow, mk_eq_iff, zero_add, ← coe_iterateFrobenius, map_zero] at h ⊢
obtain ⟨m, h⟩ := h
exact ⟨n + m, by simpa only [iterateFrobenius_def, pow_add, pow_mul] using h⟩
instance instPerfectRing : PerfectRing (PerfectClosure K p) p where
bijective_frobenius := by
let f : PerfectClosure K p → PerfectClosure K p := fun e ↦
liftOn e (fun x => mk K p (x.1 + 1, x.2)) fun x y H =>
match x, y, H with
| _, _, R.intro n x => Quot.sound (R.intro _ _)
refine bijective_iff_has_inverse.mpr ⟨f, fun e ↦ induction_on e fun ⟨n, x⟩ ↦ ?_,
fun e ↦ induction_on e fun ⟨n, x⟩ ↦ ?_⟩ <;>
simp only [f, liftOn_mk, frobenius_mk, mk_succ_pow]
@[simp]
theorem iterate_frobenius_mk (n : ℕ) (x : K) :
(frobenius (PerfectClosure K p) p)^[n] (mk K p ⟨n, x⟩) = of K p x := by
induction' n with n ih
· rfl
rw [iterate_succ_apply, ← ih, frobenius_mk, mk_succ_pow]
/-- Given a ring `K` of characteristic `p` and a perfect ring `L` of the same characteristic,
any homomorphism `K →+* L` can be lifted to `PerfectClosure K p`. -/
noncomputable def lift (L : Type v) [CommSemiring L] [CharP L p] [PerfectRing L p] :
(K →+* L) ≃ (PerfectClosure K p →+* L) where
toFun f :=
{ toFun := by
refine fun e => liftOn e (fun x => (frobeniusEquiv L p).symm^[x.1] (f x.2)) ?_
rintro - - ⟨n, x⟩
simp [f.map_frobenius]
map_one' := f.map_one
map_zero' := f.map_zero
map_mul' := by
rintro ⟨n, x⟩ ⟨m, y⟩
simp only [quot_mk_eq_mk, liftOn_mk, f.map_iterate_frobenius, mk_mul_mk, map_mul,
iterate_map_mul]
have := LeftInverse.iterate (frobeniusEquiv_symm_apply_frobenius L p)
rw [iterate_add_apply, this _ _, add_comm, iterate_add_apply, this _ _]
map_add' := by
rintro ⟨n, x⟩ ⟨m, y⟩
simp only [quot_mk_eq_mk, liftOn_mk, f.map_iterate_frobenius, mk_add_mk, map_add,
iterate_map_add]
have := LeftInverse.iterate (frobeniusEquiv_symm_apply_frobenius L p)
rw [iterate_add_apply, this _ _, add_comm n, iterate_add_apply, this _ _] }
invFun f := f.comp (of K p)
left_inv f := by ext x; rfl
right_inv f := by
ext ⟨n, x⟩
simp only [quot_mk_eq_mk, RingHom.comp_apply, RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk,
liftOn_mk]
apply (injective_frobenius L p).iterate n
rw [← f.map_iterate_frobenius, iterate_frobenius_mk,
RightInverse.iterate (frobenius_apply_frobeniusEquiv_symm L p) n]
end Ring
theorem eq_iff [CommRing K] [IsReduced K] (p : ℕ) [Fact p.Prime] [CharP K p] (x y : ℕ × K) :
mk K p x = mk K p y ↔ (frobenius K p)^[y.1] x.2 = (frobenius K p)^[x.1] y.2 :=
(mk_eq_iff K p x y).trans
⟨fun ⟨z, H⟩ => (frobenius_inj K p).iterate z <| by simpa only [add_comm, iterate_add] using H,
fun H => ⟨0, H⟩⟩
section Field
variable [Field K] (p : ℕ) [Fact p.Prime] [CharP K p]
instance instInv : Inv (PerfectClosure K p) :=
⟨Quot.lift (fun x : ℕ × K => Quot.mk (R K p) (x.1, x.2⁻¹)) fun x y (H : R K p x y) =>
match x, y, H with
| _, _, R.intro n x =>
Quot.sound <| by
simp only [frobenius_def]
rw [← inv_pow]
apply R.intro⟩
@[simp]
theorem mk_inv (x : ℕ × K) : (mk K p x)⁻¹ = mk K p (x.1, x.2⁻¹) :=
rfl
-- Porting note: added to avoid "unknown free variable" error
instance instDivisionRing : DivisionRing (PerfectClosure K p) where
exists_pair_ne := ⟨0, 1, fun H => zero_ne_one ((eq_iff _ _ _ _).1 H)⟩
mul_inv_cancel e := induction_on e fun ⟨m, x⟩ H ↦ by
have := mt (eq_iff _ _ _ _).2 H
rw [mk_inv, mk_mul_mk]
refine (eq_iff K p _ _).2 ?_
simp only [iterate_map_one, iterate_map_zero, iterate_zero_apply, ← iterate_map_mul] at this ⊢
rw [mul_inv_cancel this, iterate_map_one]
inv_zero := congr_arg (Quot.mk (R K p)) (by rw [inv_zero])
nnqsmul := _
qsmul := _
instance instField : Field (PerfectClosure K p) :=
{ (inferInstance : DivisionRing (PerfectClosure K p)),
(inferInstance : CommRing (PerfectClosure K p)) with }
instance instPerfectField : PerfectField (PerfectClosure K p) := PerfectRing.toPerfectField _ p
end Field
end PerfectClosure
|
FieldTheory\PolynomialGaloisGroup.lean | /-
Copyright (c) 2020 Thomas Browning, Patrick Lutz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning, Patrick Lutz
-/
import Mathlib.FieldTheory.Galois
/-!
# Galois Groups of Polynomials
In this file, we introduce the Galois group of a polynomial `p` over a field `F`,
defined as the automorphism group of its splitting field. We also provide
some results about some extension `E` above `p.SplittingField`.
## Main definitions
- `Polynomial.Gal p`: the Galois group of a polynomial p.
- `Polynomial.Gal.restrict p E`: the restriction homomorphism `(E ≃ₐ[F] E) → gal p`.
- `Polynomial.Gal.galAction p E`: the action of `gal p` on the roots of `p` in `E`.
## Main results
- `Polynomial.Gal.restrict_smul`: `restrict p E` is compatible with `gal_action p E`.
- `Polynomial.Gal.galActionHom_injective`: `gal p` acting on the roots of `p` in `E` is faithful.
- `Polynomial.Gal.restrictProd_injective`: `gal (p * q)` embeds as a subgroup of `gal p × gal q`.
- `Polynomial.Gal.card_of_separable`: For a separable polynomial, its Galois group has cardinality
equal to the dimension of its splitting field over `F`.
- `Polynomial.Gal.galActionHom_bijective_of_prime_degree`:
An irreducible polynomial of prime degree with two non-real roots has full Galois group.
## Other results
- `Polynomial.Gal.card_complex_roots_eq_card_real_add_card_not_gal_inv`: The number of complex roots
equals the number of real roots plus the number of roots not fixed by complex conjugation
(i.e. with some imaginary component).
-/
noncomputable section
open scoped Polynomial
open FiniteDimensional
namespace Polynomial
variable {F : Type*} [Field F] (p q : F[X]) (E : Type*) [Field E] [Algebra F E]
/-- The Galois group of a polynomial. -/
def Gal :=
p.SplittingField ≃ₐ[F] p.SplittingField
-- Porting note(https://github.com/leanprover-community/mathlib4/issues/5020):
-- deriving Group, Fintype
namespace Gal
instance instGroup : Group (Gal p) :=
inferInstanceAs (Group (p.SplittingField ≃ₐ[F] p.SplittingField))
instance instFintype : Fintype (Gal p) :=
inferInstanceAs (Fintype (p.SplittingField ≃ₐ[F] p.SplittingField))
instance : EquivLike p.Gal p.SplittingField p.SplittingField :=
inferInstanceAs (EquivLike (p.SplittingField ≃ₐ[F] p.SplittingField) _ _)
instance : AlgEquivClass p.Gal F p.SplittingField p.SplittingField :=
inferInstanceAs (AlgEquivClass (p.SplittingField ≃ₐ[F] p.SplittingField) F _ _)
instance applyMulSemiringAction : MulSemiringAction p.Gal p.SplittingField :=
AlgEquiv.applyMulSemiringAction
@[ext]
theorem ext {σ τ : p.Gal} (h : ∀ x ∈ p.rootSet p.SplittingField, σ x = τ x) : σ = τ := by
refine
AlgEquiv.ext fun x =>
(AlgHom.mem_equalizer σ.toAlgHom τ.toAlgHom x).mp
((SetLike.ext_iff.mp ?_ x).mpr Algebra.mem_top)
rwa [eq_top_iff, ← SplittingField.adjoin_rootSet, Algebra.adjoin_le_iff]
/-- If `p` splits in `F` then the `p.gal` is trivial. -/
def uniqueGalOfSplits (h : p.Splits (RingHom.id F)) : Unique p.Gal where
default := 1
uniq f :=
AlgEquiv.ext fun x => by
obtain ⟨y, rfl⟩ :=
Algebra.mem_bot.mp
((SetLike.ext_iff.mp ((IsSplittingField.splits_iff _ p).mp h) x).mp Algebra.mem_top)
rw [AlgEquiv.commutes, AlgEquiv.commutes]
instance [h : Fact (p.Splits (RingHom.id F))] : Unique p.Gal :=
uniqueGalOfSplits _ h.1
instance uniqueGalZero : Unique (0 : F[X]).Gal :=
uniqueGalOfSplits _ (splits_zero _)
instance uniqueGalOne : Unique (1 : F[X]).Gal :=
uniqueGalOfSplits _ (splits_one _)
instance uniqueGalC (x : F) : Unique (C x).Gal :=
uniqueGalOfSplits _ (splits_C _ _)
instance uniqueGalX : Unique (X : F[X]).Gal :=
uniqueGalOfSplits _ (splits_X _)
instance uniqueGalXSubC (x : F) : Unique (X - C x).Gal :=
uniqueGalOfSplits _ (splits_X_sub_C _)
instance uniqueGalXPow (n : ℕ) : Unique (X ^ n : F[X]).Gal :=
uniqueGalOfSplits _ (splits_X_pow _ _)
instance [h : Fact (p.Splits (algebraMap F E))] : Algebra p.SplittingField E :=
(IsSplittingField.lift p.SplittingField p h.1).toRingHom.toAlgebra
instance [h : Fact (p.Splits (algebraMap F E))] : IsScalarTower F p.SplittingField E :=
IsScalarTower.of_algebraMap_eq fun x =>
((IsSplittingField.lift p.SplittingField p h.1).commutes x).symm
-- The `Algebra p.SplittingField E` instance above behaves badly when
-- `E := p.SplittingField`, since it may result in a unification problem
-- `IsSplittingField.lift.toRingHom.toAlgebra =?= Algebra.id`,
-- which takes an extremely long time to resolve, causing timeouts.
-- Since we don't really care about this definition, marking it as irreducible
-- causes that unification to error out early.
/-- Restrict from a superfield automorphism into a member of `gal p`. -/
def restrict [Fact (p.Splits (algebraMap F E))] : (E ≃ₐ[F] E) →* p.Gal :=
AlgEquiv.restrictNormalHom p.SplittingField
theorem restrict_surjective [Fact (p.Splits (algebraMap F E))] [Normal F E] :
Function.Surjective (restrict p E) :=
AlgEquiv.restrictNormalHom_surjective E
section RootsAction
/-- The function taking `rootSet p p.SplittingField` to `rootSet p E`. This is actually a bijection,
see `Polynomial.Gal.mapRoots_bijective`. -/
def mapRoots [Fact (p.Splits (algebraMap F E))] : rootSet p p.SplittingField → rootSet p E :=
Set.MapsTo.restrict (IsScalarTower.toAlgHom F p.SplittingField E) _ _ <| rootSet_mapsTo _
theorem mapRoots_bijective [h : Fact (p.Splits (algebraMap F E))] :
Function.Bijective (mapRoots p E) := by
constructor
· exact fun _ _ h => Subtype.ext (RingHom.injective _ (Subtype.ext_iff.mp h))
· intro y
-- this is just an equality of two different ways to write the roots of `p` as an `E`-polynomial
have key :=
roots_map (IsScalarTower.toAlgHom F p.SplittingField E : p.SplittingField →+* E)
((splits_id_iff_splits _).mpr (IsSplittingField.splits p.SplittingField p))
rw [map_map, AlgHom.comp_algebraMap] at key
have hy := Subtype.mem y
simp only [rootSet, Finset.mem_coe, Multiset.mem_toFinset, key, Multiset.mem_map] at hy
rcases hy with ⟨x, hx1, hx2⟩
exact ⟨⟨x, (@Multiset.mem_toFinset _ (Classical.decEq _) _ _).mpr hx1⟩, Subtype.ext hx2⟩
/-- The bijection between `rootSet p p.SplittingField` and `rootSet p E`. -/
def rootsEquivRoots [Fact (p.Splits (algebraMap F E))] : rootSet p p.SplittingField ≃ rootSet p E :=
Equiv.ofBijective (mapRoots p E) (mapRoots_bijective p E)
instance galActionAux : MulAction p.Gal (rootSet p p.SplittingField) where
smul ϕ := Set.MapsTo.restrict ϕ _ _ <| rootSet_mapsTo ϕ.toAlgHom
one_smul _ := by ext; rfl
mul_smul _ _ _ := by ext; rfl
-- Porting note: split out from `galAction` below to allow using `smul_def` there.
instance smul [Fact (p.Splits (algebraMap F E))] : SMul p.Gal (rootSet p E) where
smul ϕ x := rootsEquivRoots p E (ϕ • (rootsEquivRoots p E).symm x)
theorem smul_def [Fact (p.Splits (algebraMap F E))] (ϕ : p.Gal) (x : rootSet p E) :
ϕ • x = rootsEquivRoots p E (ϕ • (rootsEquivRoots p E).symm x) :=
rfl
/-- The action of `gal p` on the roots of `p` in `E`. -/
instance galAction [Fact (p.Splits (algebraMap F E))] : MulAction p.Gal (rootSet p E) where
one_smul _ := by simp only [smul_def, Equiv.apply_symm_apply, one_smul]
mul_smul _ _ _ := by
simp only [smul_def, Equiv.apply_symm_apply, Equiv.symm_apply_apply, mul_smul]
lemma galAction_isPretransitive [Fact (p.Splits (algebraMap F E))] (hp : Irreducible p) :
MulAction.IsPretransitive p.Gal (p.rootSet E) := by
refine ⟨fun x y ↦ ?_⟩
have hx := minpoly.eq_of_irreducible hp (mem_rootSet.mp ((rootsEquivRoots p E).symm x).2).2
have hy := minpoly.eq_of_irreducible hp (mem_rootSet.mp ((rootsEquivRoots p E).symm y).2).2
obtain ⟨g, hg⟩ := (Normal.minpoly_eq_iff_mem_orbit p.SplittingField).mp (hy.symm.trans hx)
exact ⟨g, (rootsEquivRoots p E).apply_eq_iff_eq_symm_apply.mpr (Subtype.ext hg)⟩
variable {p E}
/-- `Polynomial.Gal.restrict p E` is compatible with `Polynomial.Gal.galAction p E`. -/
@[simp]
theorem restrict_smul [Fact (p.Splits (algebraMap F E))] (ϕ : E ≃ₐ[F] E) (x : rootSet p E) :
↑(restrict p E ϕ • x) = ϕ x := by
let ψ := AlgEquiv.ofInjectiveField (IsScalarTower.toAlgHom F p.SplittingField E)
change ↑(ψ (ψ.symm _)) = ϕ x
rw [AlgEquiv.apply_symm_apply ψ]
change ϕ (rootsEquivRoots p E ((rootsEquivRoots p E).symm x)) = ϕ x
rw [Equiv.apply_symm_apply (rootsEquivRoots p E)]
variable (p E)
/-- `Polynomial.Gal.galAction` as a permutation representation -/
def galActionHom [Fact (p.Splits (algebraMap F E))] : p.Gal →* Equiv.Perm (rootSet p E) :=
MulAction.toPermHom _ _
theorem galActionHom_restrict [Fact (p.Splits (algebraMap F E))] (ϕ : E ≃ₐ[F] E) (x : rootSet p E) :
↑(galActionHom p E (restrict p E ϕ) x) = ϕ x :=
restrict_smul ϕ x
/-- `gal p` embeds as a subgroup of permutations of the roots of `p` in `E`. -/
theorem galActionHom_injective [Fact (p.Splits (algebraMap F E))] :
Function.Injective (galActionHom p E) := by
rw [injective_iff_map_eq_one]
intro ϕ hϕ
ext (x hx)
have key := Equiv.Perm.ext_iff.mp hϕ (rootsEquivRoots p E ⟨x, hx⟩)
change
rootsEquivRoots p E (ϕ • (rootsEquivRoots p E).symm (rootsEquivRoots p E ⟨x, hx⟩)) =
rootsEquivRoots p E ⟨x, hx⟩
at key
rw [Equiv.symm_apply_apply] at key
exact Subtype.ext_iff.mp (Equiv.injective (rootsEquivRoots p E) key)
end RootsAction
variable {p q}
/-- `Polynomial.Gal.restrict`, when both fields are splitting fields of polynomials. -/
def restrictDvd (hpq : p ∣ q) : q.Gal →* p.Gal :=
haveI := Classical.dec (q = 0)
if hq : q = 0 then 1
else
@restrict F _ p _ _ _
⟨splits_of_splits_of_dvd (algebraMap F q.SplittingField) hq (SplittingField.splits q) hpq⟩
theorem restrictDvd_def [Decidable (q = 0)] (hpq : p ∣ q) :
restrictDvd hpq =
if hq : q = 0 then 1
else
@restrict F _ p _ _ _
⟨splits_of_splits_of_dvd (algebraMap F q.SplittingField) hq (SplittingField.splits q)
hpq⟩ := by
-- Porting note: added `unfold`
unfold restrictDvd
convert rfl
theorem restrictDvd_surjective (hpq : p ∣ q) (hq : q ≠ 0) :
Function.Surjective (restrictDvd hpq) := by
classical
-- Porting note: was `simp only [restrictDvd_def, dif_neg hq, restrict_surjective]`
haveI := Fact.mk <|
splits_of_splits_of_dvd (algebraMap F q.SplittingField) hq (SplittingField.splits q) hpq
simp only [restrictDvd_def, dif_neg hq]
exact restrict_surjective _ _
variable (p q)
/-- The Galois group of a product maps into the product of the Galois groups. -/
def restrictProd : (p * q).Gal →* p.Gal × q.Gal :=
MonoidHom.prod (restrictDvd (dvd_mul_right p q)) (restrictDvd (dvd_mul_left q p))
/-- `Polynomial.Gal.restrictProd` is actually a subgroup embedding. -/
theorem restrictProd_injective : Function.Injective (restrictProd p q) := by
by_cases hpq : p * q = 0
· have : Unique (p * q).Gal := by rw [hpq]; infer_instance
exact fun f g _ => Eq.trans (Unique.eq_default f) (Unique.eq_default g).symm
intro f g hfg
classical
simp only [restrictProd, restrictDvd_def] at hfg
simp only [dif_neg hpq, MonoidHom.prod_apply, Prod.mk.inj_iff] at hfg
ext (x hx)
rw [rootSet_def, aroots_mul hpq] at hx
cases' Multiset.mem_add.mp (Multiset.mem_toFinset.mp hx) with h h
· haveI : Fact (p.Splits (algebraMap F (p * q).SplittingField)) :=
⟨splits_of_splits_of_dvd _ hpq (SplittingField.splits (p * q)) (dvd_mul_right p q)⟩
have key :
x =
algebraMap p.SplittingField (p * q).SplittingField
((rootsEquivRoots p _).invFun
⟨x, (@Multiset.mem_toFinset _ (Classical.decEq _) _ _).mpr h⟩) :=
Subtype.ext_iff.mp (Equiv.apply_symm_apply (rootsEquivRoots p _) ⟨x, _⟩).symm
rw [key, ← AlgEquiv.restrictNormal_commutes, ← AlgEquiv.restrictNormal_commutes]
exact congr_arg _ (AlgEquiv.ext_iff.mp hfg.1 _)
· haveI : Fact (q.Splits (algebraMap F (p * q).SplittingField)) :=
⟨splits_of_splits_of_dvd _ hpq (SplittingField.splits (p * q)) (dvd_mul_left q p)⟩
have key :
x =
algebraMap q.SplittingField (p * q).SplittingField
((rootsEquivRoots q _).invFun
⟨x, (@Multiset.mem_toFinset _ (Classical.decEq _) _ _).mpr h⟩) :=
Subtype.ext_iff.mp (Equiv.apply_symm_apply (rootsEquivRoots q _) ⟨x, _⟩).symm
rw [key, ← AlgEquiv.restrictNormal_commutes, ← AlgEquiv.restrictNormal_commutes]
exact congr_arg _ (AlgEquiv.ext_iff.mp hfg.2 _)
theorem mul_splits_in_splittingField_of_mul {p₁ q₁ p₂ q₂ : F[X]} (hq₁ : q₁ ≠ 0) (hq₂ : q₂ ≠ 0)
(h₁ : p₁.Splits (algebraMap F q₁.SplittingField))
(h₂ : p₂.Splits (algebraMap F q₂.SplittingField)) :
(p₁ * p₂).Splits (algebraMap F (q₁ * q₂).SplittingField) := by
apply splits_mul
· rw [←
(SplittingField.lift q₁
(splits_of_splits_of_dvd (algebraMap F (q₁ * q₂).SplittingField) (mul_ne_zero hq₁ hq₂)
(SplittingField.splits _) (dvd_mul_right q₁ q₂))).comp_algebraMap]
exact splits_comp_of_splits _ _ h₁
· rw [←
(SplittingField.lift q₂
(splits_of_splits_of_dvd (algebraMap F (q₁ * q₂).SplittingField) (mul_ne_zero hq₁ hq₂)
(SplittingField.splits _) (dvd_mul_left q₂ q₁))).comp_algebraMap]
exact splits_comp_of_splits _ _ h₂
/-- `p` splits in the splitting field of `p ∘ q`, for `q` non-constant. -/
theorem splits_in_splittingField_of_comp (hq : q.natDegree ≠ 0) :
p.Splits (algebraMap F (p.comp q).SplittingField) := by
let P : F[X] → Prop := fun r => r.Splits (algebraMap F (r.comp q).SplittingField)
have key1 : ∀ {r : F[X]}, Irreducible r → P r := by
intro r hr
by_cases hr' : natDegree r = 0
· exact splits_of_natDegree_le_one _ (le_trans (le_of_eq hr') zero_le_one)
obtain ⟨x, hx⟩ :=
exists_root_of_splits _ (SplittingField.splits (r.comp q)) fun h =>
hr'
((mul_eq_zero.mp
(natDegree_comp.symm.trans (natDegree_eq_of_degree_eq_some h))).resolve_right
hq)
rw [← aeval_def, aeval_comp] at hx
have h_normal : Normal F (r.comp q).SplittingField := SplittingField.instNormal (r.comp q)
have qx_int := Normal.isIntegral h_normal (aeval x q)
exact
splits_of_splits_of_dvd _ (minpoly.ne_zero qx_int) (Normal.splits h_normal _)
((minpoly.irreducible qx_int).dvd_symm hr (minpoly.dvd F _ hx))
have key2 : ∀ {p₁ p₂ : F[X]}, P p₁ → P p₂ → P (p₁ * p₂) := by
intro p₁ p₂ hp₁ hp₂
by_cases h₁ : p₁.comp q = 0
· cases' comp_eq_zero_iff.mp h₁ with h h
· rw [h, zero_mul]
exact splits_zero _
· exact False.elim (hq (by rw [h.2, natDegree_C]))
by_cases h₂ : p₂.comp q = 0
· cases' comp_eq_zero_iff.mp h₂ with h h
· rw [h, mul_zero]
exact splits_zero _
· exact False.elim (hq (by rw [h.2, natDegree_C]))
have key := mul_splits_in_splittingField_of_mul h₁ h₂ hp₁ hp₂
rwa [← mul_comp] at key
-- Porting note: the last part of the proof needs to be unfolded to avoid timeout
-- original proof
-- exact
-- WfDvdMonoid.induction_on_irreducible p (splits_zero _) (fun _ => splits_of_isUnit _)
-- fun _ _ _ h => key2 (key1 h)
induction p using WfDvdMonoid.induction_on_irreducible with
| h0 => exact splits_zero _
| hu u hu => exact splits_of_isUnit (algebraMap F (SplittingField (comp u q))) hu
-- Porting note: using `exact` instead of `apply` times out
| hi p₁ p₂ _ hp₂ hp₁ => apply key2 (key1 hp₂) hp₁
/-- `Polynomial.Gal.restrict` for the composition of polynomials. -/
def restrictComp (hq : q.natDegree ≠ 0) : (p.comp q).Gal →* p.Gal :=
let h : Fact (Splits (algebraMap F (p.comp q).SplittingField) p) :=
⟨splits_in_splittingField_of_comp p q hq⟩
@restrict F _ p _ _ _ h
theorem restrictComp_surjective (hq : q.natDegree ≠ 0) :
Function.Surjective (restrictComp p q hq) := by
-- Porting note: was
-- simp only [restrictComp, restrict_surjective]
haveI : Fact (Splits (algebraMap F (SplittingField (comp p q))) p) :=
⟨splits_in_splittingField_of_comp p q hq⟩
rw [restrictComp]
exact restrict_surjective _ _
variable {p q}
open scoped IntermediateField
/-- For a separable polynomial, its Galois group has cardinality
equal to the dimension of its splitting field over `F`. -/
theorem card_of_separable (hp : p.Separable) : Fintype.card p.Gal = finrank F p.SplittingField :=
haveI : IsGalois F p.SplittingField := IsGalois.of_separable_splitting_field hp
IsGalois.card_aut_eq_finrank F p.SplittingField
theorem prime_degree_dvd_card [CharZero F] (p_irr : Irreducible p) (p_deg : p.natDegree.Prime) :
p.natDegree ∣ Fintype.card p.Gal := by
rw [Gal.card_of_separable p_irr.separable]
have hp : p.degree ≠ 0 := fun h =>
Nat.Prime.ne_zero p_deg (natDegree_eq_zero_iff_degree_le_zero.mpr (le_of_eq h))
let α : p.SplittingField :=
rootOfSplits (algebraMap F p.SplittingField) (SplittingField.splits p) hp
have hα : IsIntegral F α := .of_finite F α
use FiniteDimensional.finrank F⟮α⟯ p.SplittingField
suffices (minpoly F α).natDegree = p.natDegree by
letI _ : AddCommGroup F⟮α⟯ := Ring.toAddCommGroup
rw [← FiniteDimensional.finrank_mul_finrank F F⟮α⟯ p.SplittingField,
IntermediateField.adjoin.finrank hα, this]
suffices minpoly F α ∣ p by
have key := (minpoly.irreducible hα).dvd_symm p_irr this
apply le_antisymm
· exact natDegree_le_of_dvd this p_irr.ne_zero
· exact natDegree_le_of_dvd key (minpoly.ne_zero hα)
apply minpoly.dvd F α
rw [aeval_def, map_rootOfSplits _ (SplittingField.splits p) hp]
end Gal
end Polynomial
assert_not_exists Real
|
FieldTheory\PrimitiveElement.lean | /-
Copyright (c) 2020 Thomas Browning, Patrick Lutz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning, Patrick Lutz
-/
import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure
import Mathlib.RingTheory.IntegralDomain
/-!
# Primitive Element Theorem
In this file we prove the primitive element theorem.
## Main results
- `exists_primitive_element`: a finite separable extension `E / F` has a primitive element, i.e.
there is an `α : E` such that `F⟮α⟯ = (⊤ : Subalgebra F E)`.
- `exists_primitive_element_iff_finite_intermediateField`: a finite extension `E / F` has a
primitive element if and only if there exist only finitely many intermediate fields between `E`
and `F`.
## Implementation notes
In declaration names, `primitive_element` abbreviates `adjoin_simple_eq_top`:
it stands for the statement `F⟮α⟯ = (⊤ : Subalgebra F E)`. We did not add an extra
declaration `IsPrimitiveElement F α := F⟮α⟯ = (⊤ : Subalgebra F E)` because this
requires more unfolding without much obvious benefit.
## Tags
primitive element, separable field extension, separable extension, intermediate field, adjoin,
exists_adjoin_simple_eq_top
-/
noncomputable section
open FiniteDimensional Polynomial IntermediateField
namespace Field
section PrimitiveElementFinite
variable (F : Type*) [Field F] (E : Type*) [Field E] [Algebra F E]
/-! ### Primitive element theorem for finite fields -/
/-- **Primitive element theorem** assuming E is finite. -/
theorem exists_primitive_element_of_finite_top [Finite E] : ∃ α : E, F⟮α⟯ = ⊤ := by
obtain ⟨α, hα⟩ := @IsCyclic.exists_generator Eˣ _ _
use α
rw [eq_top_iff]
rintro x -
by_cases hx : x = 0
· rw [hx]
exact F⟮α.val⟯.zero_mem
· obtain ⟨n, hn⟩ := Set.mem_range.mp (hα (Units.mk0 x hx))
rw [show x = α ^ n by norm_cast; rw [hn, Units.val_mk0]]
exact zpow_mem (mem_adjoin_simple_self F (E := E) ↑α) n
/-- Primitive element theorem for finite dimensional extension of a finite field. -/
theorem exists_primitive_element_of_finite_bot [Finite F] [FiniteDimensional F E] :
∃ α : E, F⟮α⟯ = ⊤ :=
haveI : Finite E := finite_of_finite F E
exists_primitive_element_of_finite_top F E
end PrimitiveElementFinite
/-! ### Primitive element theorem for infinite fields -/
section PrimitiveElementInf
variable {F : Type*} [Field F] [Infinite F] {E : Type*} [Field E] (ϕ : F →+* E) (α β : E)
theorem primitive_element_inf_aux_exists_c (f g : F[X]) :
∃ c : F, ∀ α' ∈ (f.map ϕ).roots, ∀ β' ∈ (g.map ϕ).roots, -(α' - α) / (β' - β) ≠ ϕ c := by
classical
let sf := (f.map ϕ).roots
let sg := (g.map ϕ).roots
classical
let s := (sf.bind fun α' => sg.map fun β' => -(α' - α) / (β' - β)).toFinset
let s' := s.preimage ϕ fun x _ y _ h => ϕ.injective h
obtain ⟨c, hc⟩ := Infinite.exists_not_mem_finset s'
simp_rw [s', s, Finset.mem_preimage, Multiset.mem_toFinset, Multiset.mem_bind, Multiset.mem_map]
at hc
push_neg at hc
exact ⟨c, hc⟩
variable (F)
variable [Algebra F E]
/-- This is the heart of the proof of the primitive element theorem. It shows that if `F` is
infinite and `α` and `β` are separable over `F` then `F⟮α, β⟯` is generated by a single element. -/
theorem primitive_element_inf_aux [Algebra.IsSeparable F E] : ∃ γ : E, F⟮α, β⟯ = F⟮γ⟯ := by
classical
have hα := Algebra.IsSeparable.isIntegral F α
have hβ := Algebra.IsSeparable.isIntegral F β
let f := minpoly F α
let g := minpoly F β
let ιFE := algebraMap F E
let ιEE' := algebraMap E (SplittingField (g.map ιFE))
obtain ⟨c, hc⟩ := primitive_element_inf_aux_exists_c (ιEE'.comp ιFE) (ιEE' α) (ιEE' β) f g
let γ := α + c • β
suffices β_in_Fγ : β ∈ F⟮γ⟯ by
use γ
apply le_antisymm
· rw [adjoin_le_iff]
have α_in_Fγ : α ∈ F⟮γ⟯ := by
rw [← add_sub_cancel_right α (c • β)]
exact F⟮γ⟯.sub_mem (mem_adjoin_simple_self F γ) (F⟮γ⟯.toSubalgebra.smul_mem β_in_Fγ c)
rintro x (rfl | rfl) <;> assumption
· rw [adjoin_simple_le_iff]
have α_in_Fαβ : α ∈ F⟮α, β⟯ := subset_adjoin F {α, β} (Set.mem_insert α {β})
have β_in_Fαβ : β ∈ F⟮α, β⟯ := subset_adjoin F {α, β} (Set.mem_insert_of_mem α rfl)
exact F⟮α, β⟯.add_mem α_in_Fαβ (F⟮α, β⟯.smul_mem β_in_Fαβ)
classical
let p := EuclideanDomain.gcd ((f.map (algebraMap F F⟮γ⟯)).comp
(C (AdjoinSimple.gen F γ) - (C ↑c : F⟮γ⟯[X]) * X)) (g.map (algebraMap F F⟮γ⟯))
let h := EuclideanDomain.gcd ((f.map ιFE).comp (C γ - C (ιFE c) * X)) (g.map ιFE)
have map_g_ne_zero : g.map ιFE ≠ 0 := map_ne_zero (minpoly.ne_zero hβ)
have h_ne_zero : h ≠ 0 :=
mt EuclideanDomain.gcd_eq_zero_iff.mp (not_and.mpr fun _ => map_g_ne_zero)
suffices p_linear : p.map (algebraMap F⟮γ⟯ E) = C h.leadingCoeff * (X - C β) by
have finale : β = algebraMap F⟮γ⟯ E (-p.coeff 0 / p.coeff 1) := by
rw [map_div₀, RingHom.map_neg, ← coeff_map, ← coeff_map, p_linear]
-- Porting note: had to add `-map_add` to avoid going in the wrong direction.
simp [mul_sub, coeff_C, mul_div_cancel_left₀ β (mt leadingCoeff_eq_zero.mp h_ne_zero),
-map_add]
-- Porting note: an alternative solution is:
-- simp_rw [Polynomial.coeff_C_mul, Polynomial.coeff_sub, mul_sub,
-- Polynomial.coeff_X_zero, Polynomial.coeff_X_one, mul_zero, mul_one, zero_sub, neg_neg,
-- Polynomial.coeff_C, eq_self_iff_true, Nat.one_ne_zero, if_true, if_false, mul_zero,
-- sub_zero, mul_div_cancel_left β (mt leadingCoeff_eq_zero.mp h_ne_zero)]
rw [finale]
exact Subtype.mem (-p.coeff 0 / p.coeff 1)
have h_sep : h.Separable := separable_gcd_right _ (Algebra.IsSeparable.isSeparable F β).map
have h_root : h.eval β = 0 := by
apply eval_gcd_eq_zero
· rw [eval_comp, eval_sub, eval_mul, eval_C, eval_C, eval_X, eval_map, ← aeval_def, ←
Algebra.smul_def, add_sub_cancel_right, minpoly.aeval]
· rw [eval_map, ← aeval_def, minpoly.aeval]
have h_splits : Splits ιEE' h :=
splits_of_splits_gcd_right ιEE' map_g_ne_zero (SplittingField.splits _)
have h_roots : ∀ x ∈ (h.map ιEE').roots, x = ιEE' β := by
intro x hx
rw [mem_roots_map h_ne_zero] at hx
specialize hc (ιEE' γ - ιEE' (ιFE c) * x) (by
have f_root := root_left_of_root_gcd hx
rw [eval₂_comp, eval₂_sub, eval₂_mul, eval₂_C, eval₂_C, eval₂_X, eval₂_map] at f_root
exact (mem_roots_map (minpoly.ne_zero hα)).mpr f_root)
specialize hc x (by
rw [mem_roots_map (minpoly.ne_zero hβ), ← eval₂_map]
exact root_right_of_root_gcd hx)
by_contra a
apply hc
apply (div_eq_iff (sub_ne_zero.mpr a)).mpr
simp only [γ, Algebra.smul_def, RingHom.map_add, RingHom.map_mul, RingHom.comp_apply]
ring
rw [← eq_X_sub_C_of_separable_of_root_eq h_sep h_root h_splits h_roots]
trans EuclideanDomain.gcd (?_ : E[X]) (?_ : E[X])
· dsimp only [γ]
convert (gcd_map (algebraMap F⟮γ⟯ E)).symm
· simp only [map_comp, Polynomial.map_map, ← IsScalarTower.algebraMap_eq, Polynomial.map_sub,
map_C, AdjoinSimple.algebraMap_gen, map_add, Polynomial.map_mul, map_X]
congr
-- If `F` is infinite and `E/F` has only finitely many intermediate fields, then for any
-- `α` and `β` in `E`, `F⟮α, β⟯` is generated by a single element.
-- Marked as private since it's a special case of
-- `exists_primitive_element_of_finite_intermediateField`.
private theorem primitive_element_inf_aux_of_finite_intermediateField
[Finite (IntermediateField F E)] : ∃ γ : E, F⟮α, β⟯ = F⟮γ⟯ := by
let f : F → IntermediateField F E := fun x ↦ F⟮α + x • β⟯
obtain ⟨x, y, hneq, heq⟩ := Finite.exists_ne_map_eq_of_infinite f
use α + x • β
apply le_antisymm
· rw [adjoin_le_iff]
have αxβ_in_K : α + x • β ∈ F⟮α + x • β⟯ := mem_adjoin_simple_self F _
have αyβ_in_K : α + y • β ∈ F⟮α + y • β⟯ := mem_adjoin_simple_self F _
dsimp [f] at *
simp only [← heq] at αyβ_in_K
have β_in_K := sub_mem αxβ_in_K αyβ_in_K
rw [show (α + x • β) - (α + y • β) = (x - y) • β by rw [sub_smul]; abel1] at β_in_K
replace β_in_K := smul_mem _ β_in_K (x := (x - y)⁻¹)
rw [smul_smul, inv_mul_eq_div, div_self (sub_ne_zero.2 hneq), one_smul] at β_in_K
have α_in_K : α ∈ F⟮α + x • β⟯ := by
convert ← sub_mem αxβ_in_K (smul_mem _ β_in_K)
apply add_sub_cancel_right
rintro x (rfl | rfl) <;> assumption
· rw [adjoin_simple_le_iff]
have α_in_Fαβ : α ∈ F⟮α, β⟯ := subset_adjoin F {α, β} (Set.mem_insert α {β})
have β_in_Fαβ : β ∈ F⟮α, β⟯ := subset_adjoin F {α, β} (Set.mem_insert_of_mem α rfl)
exact F⟮α, β⟯.add_mem α_in_Fαβ (F⟮α, β⟯.smul_mem β_in_Fαβ)
end PrimitiveElementInf
variable (F E : Type*) [Field F] [Field E]
variable [Algebra F E]
section SeparableAssumption
variable [FiniteDimensional F E] [Algebra.IsSeparable F E]
/-- **Primitive element theorem**: a finite separable field extension `E` of `F` has a
primitive element, i.e. there is an `α ∈ E` such that `F⟮α⟯ = (⊤ : Subalgebra F E)`. -/
theorem exists_primitive_element : ∃ α : E, F⟮α⟯ = ⊤ := by
rcases isEmpty_or_nonempty (Fintype F) with (F_inf | ⟨⟨F_finite⟩⟩)
· let P : IntermediateField F E → Prop := fun K => ∃ α : E, F⟮α⟯ = K
have base : P ⊥ := ⟨0, adjoin_zero⟩
have ih : ∀ (K : IntermediateField F E) (x : E), P K → P (K⟮x⟯.restrictScalars F) := by
intro K β hK
cases' hK with α hK
rw [← hK, adjoin_simple_adjoin_simple]
haveI : Infinite F := isEmpty_fintype.mp F_inf
cases' primitive_element_inf_aux F α β with γ hγ
exact ⟨γ, hγ.symm⟩
exact induction_on_adjoin P base ih ⊤
· exact exists_primitive_element_of_finite_bot F E
/-- Alternative phrasing of primitive element theorem:
a finite separable field extension has a basis `1, α, α^2, ..., α^n`.
See also `exists_primitive_element`. -/
noncomputable def powerBasisOfFiniteOfSeparable : PowerBasis F E :=
let α := (exists_primitive_element F E).choose
let pb := adjoin.powerBasis (Algebra.IsSeparable.isIntegral F α)
have e : F⟮α⟯ = ⊤ := (exists_primitive_element F E).choose_spec
pb.map ((IntermediateField.equivOfEq e).trans IntermediateField.topEquiv)
end SeparableAssumption
section FiniteIntermediateField
-- TODO: show a more generalized result: [F⟮α⟯ : F⟮α ^ m⟯] = m if m > 0 and α transcendental.
theorem isAlgebraic_of_adjoin_eq_adjoin {α : E} {m n : ℕ} (hneq : m ≠ n)
(heq : F⟮α ^ m⟯ = F⟮α ^ n⟯) : IsAlgebraic F α := by
wlog hmn : m < n
· exact this F E hneq.symm heq.symm (hneq.lt_or_lt.resolve_left hmn)
by_cases hm : m = 0
· rw [hm] at heq hmn
simp only [pow_zero, adjoin_one] at heq
obtain ⟨y, h⟩ := mem_bot.1 (heq.symm ▸ mem_adjoin_simple_self F (α ^ n))
refine ⟨X ^ n - C y, X_pow_sub_C_ne_zero hmn y, ?_⟩
simp only [map_sub, map_pow, aeval_X, aeval_C, h, sub_self]
obtain ⟨r, s, h⟩ := (mem_adjoin_simple_iff F _).1 (heq ▸ mem_adjoin_simple_self F (α ^ m))
by_cases hzero : aeval (α ^ n) s = 0
· simp only [hzero, div_zero, pow_eq_zero_iff hm] at h
exact h.symm ▸ isAlgebraic_zero
replace hm : 0 < m := Nat.pos_of_ne_zero hm
rw [eq_div_iff hzero, ← sub_eq_zero] at h
replace hzero : s ≠ 0 := by rintro rfl; simp only [map_zero, not_true_eq_false] at hzero
let f : F[X] := X ^ m * expand F n s - expand F n r
refine ⟨f, ?_, ?_⟩
· have : f.coeff (n * s.natDegree + m) ≠ 0 := by
have hn : 0 < n := by linarith only [hm, hmn]
have hndvd : ¬ n ∣ n * s.natDegree + m := by
rw [← Nat.dvd_add_iff_right (n.dvd_mul_right s.natDegree)]
exact Nat.not_dvd_of_pos_of_lt hm hmn
simp only [f, coeff_sub, coeff_X_pow_mul, s.coeff_expand_mul' hn, coeff_natDegree,
coeff_expand hn r, hndvd, ite_false, sub_zero]
exact leadingCoeff_ne_zero.2 hzero
intro h
simp only [h, coeff_zero, ne_eq, not_true_eq_false] at this
· simp only [f, map_sub, map_mul, map_pow, aeval_X, expand_aeval, h]
theorem isAlgebraic_of_finite_intermediateField
[Finite (IntermediateField F E)] : Algebra.IsAlgebraic F E := ⟨fun α ↦
have ⟨_m, _n, hneq, heq⟩ := Finite.exists_ne_map_eq_of_infinite fun n ↦ F⟮α ^ n⟯
isAlgebraic_of_adjoin_eq_adjoin F E hneq heq⟩
theorem FiniteDimensional.of_finite_intermediateField
[Finite (IntermediateField F E)] : FiniteDimensional F E := by
let IF := { K : IntermediateField F E // ∃ x, K = F⟮x⟯ }
have := isAlgebraic_of_finite_intermediateField F E
haveI : ∀ K : IF, FiniteDimensional F K.1 := fun ⟨_, x, rfl⟩ ↦ adjoin.finiteDimensional
(Algebra.IsIntegral.isIntegral _)
have hfin := finiteDimensional_iSup_of_finite (t := fun K : IF ↦ K.1)
have htop : ⨆ K : IF, K.1 = ⊤ := le_top.antisymm fun x _ ↦
le_iSup (fun K : IF ↦ K.1) ⟨F⟮x⟯, x, rfl⟩ <| mem_adjoin_simple_self F x
rw [htop] at hfin
exact topEquiv.toLinearEquiv.finiteDimensional
@[deprecated (since := "2024-02-02")]
alias finiteDimensional_of_finite_intermediateField := FiniteDimensional.of_finite_intermediateField
theorem exists_primitive_element_of_finite_intermediateField
[Finite (IntermediateField F E)] (K : IntermediateField F E) : ∃ α : E, F⟮α⟯ = K := by
haveI := FiniteDimensional.of_finite_intermediateField F E
rcases finite_or_infinite F with (_ | _)
· obtain ⟨α, h⟩ := exists_primitive_element_of_finite_bot F K
exact ⟨α, by simpa only [lift_adjoin_simple, lift_top] using congr_arg lift h⟩
· apply induction_on_adjoin (fun K ↦ ∃ α : E, F⟮α⟯ = K) ⟨0, adjoin_zero⟩
rintro K β ⟨α, rfl⟩
simp_rw [adjoin_simple_adjoin_simple, eq_comm]
exact primitive_element_inf_aux_of_finite_intermediateField F α β
theorem FiniteDimensional.of_exists_primitive_element [Algebra.IsAlgebraic F E]
(h : ∃ α : E, F⟮α⟯ = ⊤) : FiniteDimensional F E := by
obtain ⟨α, hprim⟩ := h
have hfin := adjoin.finiteDimensional (Algebra.IsIntegral.isIntegral (R := F) α)
rw [hprim] at hfin
exact topEquiv.toLinearEquiv.finiteDimensional
@[deprecated (since := "2024-02-02")]
alias finiteDimensional_of_exists_primitive_element := FiniteDimensional.of_exists_primitive_element
-- A finite simple extension has only finitely many intermediate fields
theorem finite_intermediateField_of_exists_primitive_element [Algebra.IsAlgebraic F E]
(h : ∃ α : E, F⟮α⟯ = ⊤) : Finite (IntermediateField F E) := by
haveI := FiniteDimensional.of_exists_primitive_element F E h
obtain ⟨α, hprim⟩ := h
-- Let `f` be the minimal polynomial of `α ∈ E` over `F`
let f : F[X] := minpoly F α
let G := { g : E[X] // g.Monic ∧ g ∣ f.map (algebraMap F E) }
-- Then `f` has only finitely many monic factors
have hfin : Finite G := @Finite.of_fintype _ <| fintypeSubtypeMonicDvd
(f.map (algebraMap F E)) <| map_ne_zero (minpoly.ne_zero_of_finite F α)
-- If `K` is an intermediate field of `E/F`, let `g` be the minimal polynomial of `α` over `K`
-- which is a monic factor of `f`
let g : IntermediateField F E → G := fun K ↦
⟨(minpoly K α).map (algebraMap K E), (minpoly.monic <| .of_finite K α).map _, by
convert Polynomial.map_dvd (algebraMap K E) (minpoly.dvd_map_of_isScalarTower F K α)
rw [Polynomial.map_map]; rfl⟩
-- The map `K ↦ g` is injective
have hinj : Function.Injective g := fun K K' heq ↦ by
rw [Subtype.mk.injEq] at heq
apply_fun fun f : E[X] ↦ adjoin F (f.coeffs : Set E) at heq
simpa only [adjoin_minpoly_coeff_of_exists_primitive_element F hprim] using heq
-- Therefore there are only finitely many intermediate fields
exact Finite.of_injective g hinj
/-- **Steinitz theorem**: an algebraic extension `E` of `F` has a
primitive element (i.e. there is an `α ∈ E` such that `F⟮α⟯ = (⊤ : Subalgebra F E)`)
if and only if there exist only finitely many intermediate fields between `E` and `F`. -/
theorem exists_primitive_element_iff_finite_intermediateField :
(Algebra.IsAlgebraic F E ∧ ∃ α : E, F⟮α⟯ = ⊤) ↔ Finite (IntermediateField F E) :=
⟨fun ⟨_, h⟩ ↦ finite_intermediateField_of_exists_primitive_element F E h,
fun _ ↦ ⟨isAlgebraic_of_finite_intermediateField F E,
exists_primitive_element_of_finite_intermediateField F E _⟩⟩
end FiniteIntermediateField
end Field
variable (F E : Type*) [Field F] [Field E] [Algebra F E]
[FiniteDimensional F E] [Algebra.IsSeparable F E]
@[simp]
theorem AlgHom.card (K : Type*) [Field K] [IsAlgClosed K] [Algebra F K] :
Fintype.card (E →ₐ[F] K) = finrank F E := by
convert (AlgHom.card_of_powerBasis (L := K) (Field.powerBasisOfFiniteOfSeparable F E)
(Algebra.IsSeparable.isSeparable _ _) (IsAlgClosed.splits_codomain _)).trans
(PowerBasis.finrank _).symm
@[simp]
theorem AlgHom.card_of_splits (L : Type*) [Field L] [Algebra F L]
(hL : ∀ x : E, (minpoly F x).Splits (algebraMap F L)) :
Fintype.card (E →ₐ[F] L) = finrank F E := by
rw [← Fintype.ofEquiv_card <| Algebra.IsAlgebraic.algHomEquivAlgHomOfSplits
(AlgebraicClosure L) _ hL]
convert AlgHom.card F E (AlgebraicClosure L)
section iff
namespace Field
open FiniteDimensional IntermediateField Polynomial Algebra Set
variable (F : Type*) {E : Type*} [Field F] [Field E] [Algebra F E] [FiniteDimensional F E]
theorem primitive_element_iff_minpoly_natDegree_eq (α : E) :
F⟮α⟯ = ⊤ ↔ (minpoly F α).natDegree = finrank F E := by
rw [← adjoin.finrank (IsIntegral.of_finite F α), ← finrank_top F E]
refine ⟨fun h => ?_, fun h => eq_of_le_of_finrank_eq le_top h⟩
exact congr_arg (fun K : IntermediateField F E => finrank F K) h
theorem primitive_element_iff_minpoly_degree_eq (α : E) :
F⟮α⟯ = ⊤ ↔ (minpoly F α).degree = finrank F E := by
rw [degree_eq_iff_natDegree_eq, primitive_element_iff_minpoly_natDegree_eq]
exact minpoly.ne_zero_of_finite F α
variable [Algebra.IsSeparable F E] (A : Type*) [Field A] [Algebra F A]
(hA : ∀ x : E, (minpoly F x).Splits (algebraMap F A))
theorem primitive_element_iff_algHom_eq_of_eval' (α : E) :
F⟮α⟯ = ⊤ ↔ Function.Injective fun φ : E →ₐ[F] A ↦ φ α := by
classical
simp_rw [primitive_element_iff_minpoly_natDegree_eq, ← card_rootSet_eq_natDegree (K := A)
(Algebra.IsSeparable.isSeparable F α) (hA _), ← toFinset_card,
← (Algebra.IsAlgebraic.of_finite F E).range_eval_eq_rootSet_minpoly_of_splits _ hA α,
← AlgHom.card_of_splits F E A hA, Fintype.card, toFinset_range, Finset.card_image_iff,
Finset.coe_univ, ← injective_iff_injOn_univ]
theorem primitive_element_iff_algHom_eq_of_eval (α : E)
(φ : E →ₐ[F] A) : F⟮α⟯ = ⊤ ↔ ∀ ψ : E →ₐ[F] A, φ α = ψ α → φ = ψ := by
refine ⟨fun h ψ hψ ↦ (Field.primitive_element_iff_algHom_eq_of_eval' F A hA α).mp h hψ,
fun h ↦ eq_of_le_of_finrank_eq' le_top ?_⟩
letI : Algebra F⟮α⟯ A := (φ.comp F⟮α⟯.val).toAlgebra
haveI := Algebra.isSeparable_tower_top_of_isSeparable F F⟮α⟯ E
rw [IntermediateField.finrank_top, ← AlgHom.card_of_splits _ _ A, Fintype.card_eq_one_iff]
· exact ⟨{ __ := φ, commutes' := fun _ ↦ rfl }, fun ψ ↦ AlgHom.restrictScalars_injective F <|
Eq.symm <| h _ (ψ.commutes <| AdjoinSimple.gen F α).symm⟩
· exact fun x ↦ (IsIntegral.of_finite F x).minpoly_splits_tower_top (hA x)
end Field
end iff
|
FieldTheory\PurelyInseparable.lean | /-
Copyright (c) 2024 Jz Pan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jz Pan
-/
import Mathlib.FieldTheory.SeparableClosure
import Mathlib.Algebra.CharP.IntermediateField
/-!
# Purely inseparable extension and relative perfect closure
This file contains basics about purely inseparable extensions and the relative perfect closure
of fields.
## Main definitions
- `IsPurelyInseparable`: typeclass for purely inseparable field extensions: an algebraic extension
`E / F` is purely inseparable if and only if the minimal polynomial of every element of `E ∖ F`
is not separable.
- `perfectClosure`: the relative perfect closure of `F` in `E`, it consists of the elements
`x` of `E` such that there exists a natural number `n` such that `x ^ (ringExpChar F) ^ n`
is contained in `F`, where `ringExpChar F` is the exponential characteristic of `F`.
It is also the maximal purely inseparable subextension of `E / F` (`le_perfectClosure_iff`).
## Main results
- `IsPurelyInseparable.surjective_algebraMap_of_isSeparable`,
`IsPurelyInseparable.bijective_algebraMap_of_isSeparable`,
`IntermediateField.eq_bot_of_isPurelyInseparable_of_isSeparable`:
if `E / F` is both purely inseparable and separable, then `algebraMap F E` is surjective
(hence bijective). In particular, if an intermediate field of `E / F` is both purely inseparable
and separable, then it is equal to `F`.
- `isPurelyInseparable_iff_pow_mem`: a field extension `E / F` of exponential characteristic `q` is
purely inseparable if and only if for every element `x` of `E`, there exists a natural number `n`
such that `x ^ (q ^ n)` is contained in `F`.
- `IsPurelyInseparable.trans`: if `E / F` and `K / E` are both purely inseparable extensions, then
`K / F` is also purely inseparable.
- `isPurelyInseparable_iff_natSepDegree_eq_one`: `E / F` is purely inseparable if and only if for
every element `x` of `E`, its minimal polynomial has separable degree one.
- `isPurelyInseparable_iff_minpoly_eq_X_pow_sub_C`: a field extension `E / F` of exponential
characteristic `q` is purely inseparable if and only if for every element `x` of `E`, the minimal
polynomial of `x` over `F` is of form `X ^ (q ^ n) - y` for some natural number `n` and some
element `y` of `F`.
- `isPurelyInseparable_iff_minpoly_eq_X_sub_C_pow`: a field extension `E / F` of exponential
characteristic `q` is purely inseparable if and only if for every element `x` of `E`, the minimal
polynomial of `x` over `F` is of form `(X - x) ^ (q ^ n)` for some natural number `n`.
- `isPurelyInseparable_iff_finSepDegree_eq_one`: an algebraic extension is purely inseparable
if and only if it has finite separable degree (`Field.finSepDegree`) one.
**TODO:** remove the algebraic assumption.
- `IsPurelyInseparable.normal`: a purely inseparable extension is normal.
- `separableClosure.isPurelyInseparable`: if `E / F` is algebraic, then `E` is purely inseparable
over the separable closure of `F` in `E`.
- `separableClosure_le_iff`: if `E / F` is algebraic, then an intermediate field of `E / F` contains
the separable closure of `F` in `E` if and only if `E` is purely inseparable over it.
- `eq_separableClosure_iff`: if `E / F` is algebraic, then an intermediate field of `E / F` is equal
to the separable closure of `F` in `E` if and only if it is separable over `F`, and `E`
is purely inseparable over it.
- `le_perfectClosure_iff`: an intermediate field of `E / F` is contained in the relative perfect
closure of `F` in `E` if and only if it is purely inseparable over `F`.
- `perfectClosure.perfectRing`, `perfectClosure.perfectField`: if `E` is a perfect field, then the
(relative) perfect closure `perfectClosure F E` is perfect.
- `IsPurelyInseparable.injective_comp_algebraMap`: if `E / F` is purely inseparable, then for any
reduced ring `L`, the map `(E →+* L) → (F →+* L)` induced by `algebraMap F E` is injective.
In particular, a purely inseparable field extension is an epimorphism in the category of fields.
- `IntermediateField.isPurelyInseparable_adjoin_iff_pow_mem`: if `F` is of exponential
characteristic `q`, then `F(S) / F` is a purely inseparable extension if and only if for any
`x ∈ S`, `x ^ (q ^ n)` is contained in `F` for some `n : ℕ`.
- `Field.finSepDegree_eq`: if `E / F` is algebraic, then the `Field.finSepDegree F E` is equal to
`Field.sepDegree F E` as a natural number. This means that the cardinality of `Field.Emb F E`
and the degree of `(separableClosure F E) / F` are both finite or infinite, and when they are
finite, they coincide.
- `Field.finSepDegree_mul_finInsepDegree`: the finite separable degree multiply by the finite
inseparable degree is equal to the (finite) field extension degree.
- `Field.lift_sepDegree_mul_lift_sepDegree_of_isAlgebraic`: the separable degrees satisfy the
tower law: $[E:F]_s [K:E]_s = [K:F]_s$.
- `IntermediateField.sepDegree_adjoin_eq_of_isAlgebraic_of_isPurelyInseparable`,
`IntermediateField.sepDegree_adjoin_eq_of_isAlgebraic_of_isPurelyInseparable'`:
if `K / E / F` is a field extension tower, such that `E / F` is purely inseparable, then
for any subset `S` of `K` such that `F(S) / F` is algebraic, the `E(S) / E` and `F(S) / F` have
the same separable degree. In particular, if `S` is an intermediate field of `K / F` such that
`S / F` is algebraic, the `E(S) / E` and `S / F` have the same separable degree.
- `minpoly.map_eq_of_isSeparable_of_isPurelyInseparable`: if `K / E / F` is a field extension tower,
such that `E / F` is purely inseparable, then for any element `x` of `K` separable over `F`,
it has the same minimal polynomials over `F` and over `E`.
- `Polynomial.Separable.map_irreducible_of_isPurelyInseparable`: if `E / F` is purely inseparable,
`f` is a separable irreducible polynomial over `F`, then it is also irreducible over `E`.
## Tags
separable degree, degree, separable closure, purely inseparable
## TODO
- `IsPurelyInseparable.of_injective_comp_algebraMap`: if `L` is an algebraically closed field
containing `E`, such that the map `(E →+* L) → (F →+* L)` induced by `algebraMap F E` is
injective, then `E / F` is purely inseparable. As a corollary, epimorphisms in the category of
fields must be purely inseparable extensions. Need to use the fact that `Emb F E` is infinite
(or just not a singleton) when `E / F` is (purely) transcendental.
- Restate some intermediate result in terms of linearly disjointness.
- Prove that the inseparable degrees satisfy the tower law: $[E:F]_i [K:E]_i = [K:F]_i$.
Probably an argument using linearly disjointness is needed.
-/
open FiniteDimensional Polynomial IntermediateField Field
noncomputable section
universe u v w
variable (F : Type u) (E : Type v) [Field F] [Field E] [Algebra F E]
variable (K : Type w) [Field K] [Algebra F K]
section IsPurelyInseparable
/-- Typeclass for purely inseparable field extensions: an algebraic extension `E / F` is purely
inseparable if and only if the minimal polynomial of every element of `E ∖ F` is not separable. -/
class IsPurelyInseparable : Prop where
isIntegral : Algebra.IsIntegral F E
inseparable' (x : E) : IsSeparable F x → x ∈ (algebraMap F E).range
attribute [instance] IsPurelyInseparable.isIntegral
variable {E} in
theorem IsPurelyInseparable.isIntegral' [IsPurelyInseparable F E] (x : E) : IsIntegral F x :=
Algebra.IsIntegral.isIntegral _
theorem IsPurelyInseparable.isAlgebraic [IsPurelyInseparable F E] :
Algebra.IsAlgebraic F E := inferInstance
variable {E}
theorem IsPurelyInseparable.inseparable [IsPurelyInseparable F E] :
∀ x : E, IsSeparable F x → x ∈ (algebraMap F E).range :=
IsPurelyInseparable.inseparable'
variable {F K}
theorem isPurelyInseparable_iff : IsPurelyInseparable F E ↔ ∀ x : E,
IsIntegral F x ∧ (IsSeparable F x → x ∈ (algebraMap F E).range) :=
⟨fun h x ↦ ⟨h.isIntegral' x, h.inseparable' x⟩, fun h ↦ ⟨⟨fun x ↦ (h x).1⟩, fun x ↦ (h x).2⟩⟩
/-- Transfer `IsPurelyInseparable` across an `AlgEquiv`. -/
theorem AlgEquiv.isPurelyInseparable (e : K ≃ₐ[F] E) [IsPurelyInseparable F K] :
IsPurelyInseparable F E := by
refine ⟨⟨fun _ ↦ by rw [← isIntegral_algEquiv e.symm]; exact IsPurelyInseparable.isIntegral' F _⟩,
fun x h ↦ ?_⟩
rw [IsSeparable, ← minpoly.algEquiv_eq e.symm] at h
simpa only [RingHom.mem_range, algebraMap_eq_apply] using IsPurelyInseparable.inseparable F _ h
theorem AlgEquiv.isPurelyInseparable_iff (e : K ≃ₐ[F] E) :
IsPurelyInseparable F K ↔ IsPurelyInseparable F E :=
⟨fun _ ↦ e.isPurelyInseparable, fun _ ↦ e.symm.isPurelyInseparable⟩
/-- If `E / F` is an algebraic extension, `F` is separably closed,
then `E / F` is purely inseparable. -/
theorem Algebra.IsAlgebraic.isPurelyInseparable_of_isSepClosed [Algebra.IsAlgebraic F E]
[IsSepClosed F] : IsPurelyInseparable F E :=
⟨inferInstance, fun x h ↦ minpoly.mem_range_of_degree_eq_one F x <|
IsSepClosed.degree_eq_one_of_irreducible F (minpoly.irreducible
(Algebra.IsIntegral.isIntegral _)) h⟩
variable (F E K)
/-- If `E / F` is both purely inseparable and separable, then `algebraMap F E` is surjective. -/
theorem IsPurelyInseparable.surjective_algebraMap_of_isSeparable
[IsPurelyInseparable F E] [Algebra.IsSeparable F E] : Function.Surjective (algebraMap F E) :=
fun x ↦ IsPurelyInseparable.inseparable F x (Algebra.IsSeparable.isSeparable F x)
/-- If `E / F` is both purely inseparable and separable, then `algebraMap F E` is bijective. -/
theorem IsPurelyInseparable.bijective_algebraMap_of_isSeparable
[IsPurelyInseparable F E] [Algebra.IsSeparable F E] : Function.Bijective (algebraMap F E) :=
⟨(algebraMap F E).injective, surjective_algebraMap_of_isSeparable F E⟩
variable {F E} in
/-- If an intermediate field of `E / F` is both purely inseparable and separable, then it is equal
to `F`. -/
theorem IntermediateField.eq_bot_of_isPurelyInseparable_of_isSeparable (L : IntermediateField F E)
[IsPurelyInseparable F L] [Algebra.IsSeparable F L] : L = ⊥ := bot_unique fun x hx ↦ by
obtain ⟨y, hy⟩ := IsPurelyInseparable.surjective_algebraMap_of_isSeparable F L ⟨x, hx⟩
exact ⟨y, congr_arg (algebraMap L E) hy⟩
/-- If `E / F` is purely inseparable, then the separable closure of `F` in `E` is
equal to `F`. -/
theorem separableClosure.eq_bot_of_isPurelyInseparable [IsPurelyInseparable F E] :
separableClosure F E = ⊥ :=
bot_unique fun x h ↦ IsPurelyInseparable.inseparable F x (mem_separableClosure_iff.1 h)
variable {F E} in
/-- If `E / F` is an algebraic extension, then the separable closure of `F` in `E` is
equal to `F` if and only if `E / F` is purely inseparable. -/
theorem separableClosure.eq_bot_iff [Algebra.IsAlgebraic F E] :
separableClosure F E = ⊥ ↔ IsPurelyInseparable F E :=
⟨fun h ↦ isPurelyInseparable_iff.2 fun x ↦ ⟨Algebra.IsIntegral.isIntegral x, fun hs ↦ by
simpa only [h] using mem_separableClosure_iff.2 hs⟩, fun _ ↦ eq_bot_of_isPurelyInseparable F E⟩
instance isPurelyInseparable_self : IsPurelyInseparable F F :=
⟨inferInstance, fun x _ ↦ ⟨x, rfl⟩⟩
variable {E}
/-- A field extension `E / F` of exponential characteristic `q` is purely inseparable
if and only if for every element `x` of `E`, there exists a natural number `n` such that
`x ^ (q ^ n)` is contained in `F`. -/
theorem isPurelyInseparable_iff_pow_mem (q : ℕ) [ExpChar F q] :
IsPurelyInseparable F E ↔ ∀ x : E, ∃ n : ℕ, x ^ q ^ n ∈ (algebraMap F E).range := by
rw [isPurelyInseparable_iff]
refine ⟨fun h x ↦ ?_, fun h x ↦ ?_⟩
· obtain ⟨g, h1, n, h2⟩ := (minpoly.irreducible (h x).1).hasSeparableContraction q
exact ⟨n, (h _).2 <| h1.of_dvd <| minpoly.dvd F _ <| by
simpa only [expand_aeval, minpoly.aeval] using congr_arg (aeval x) h2⟩
have hdeg := (minpoly.natSepDegree_eq_one_iff_pow_mem q).2 (h x)
have halg : IsIntegral F x := by_contra fun h' ↦ by
simp only [minpoly.eq_zero h', natSepDegree_zero, zero_ne_one] at hdeg
refine ⟨halg, fun hsep ↦ ?_⟩
rw [hsep.natSepDegree_eq_natDegree, ← adjoin.finrank halg,
IntermediateField.finrank_eq_one_iff] at hdeg
simpa only [hdeg] using mem_adjoin_simple_self F x
theorem IsPurelyInseparable.pow_mem (q : ℕ) [ExpChar F q] [IsPurelyInseparable F E] (x : E) :
∃ n : ℕ, x ^ q ^ n ∈ (algebraMap F E).range :=
(isPurelyInseparable_iff_pow_mem F q).1 ‹_› x
end IsPurelyInseparable
section perfectClosure
/-- The relative perfect closure of `F` in `E`, consists of the elements `x` of `E` such that there
exists a natural number `n` such that `x ^ (ringExpChar F) ^ n` is contained in `F`, where
`ringExpChar F` is the exponential characteristic of `F`. It is also the maximal purely inseparable
subextension of `E / F` (`le_perfectClosure_iff`). -/
def perfectClosure : IntermediateField F E where
carrier := {x : E | ∃ n : ℕ, x ^ (ringExpChar F) ^ n ∈ (algebraMap F E).range}
add_mem' := by
rintro x y ⟨n, hx⟩ ⟨m, hy⟩
use n + m
have := expChar_of_injective_algebraMap (algebraMap F E).injective (ringExpChar F)
rw [add_pow_expChar_pow, pow_add, pow_mul, mul_comm (_ ^ n), pow_mul]
exact add_mem (pow_mem hx _) (pow_mem hy _)
mul_mem' := by
rintro x y ⟨n, hx⟩ ⟨m, hy⟩
use n + m
rw [mul_pow, pow_add, pow_mul, mul_comm (_ ^ n), pow_mul]
exact mul_mem (pow_mem hx _) (pow_mem hy _)
inv_mem' := by
rintro x ⟨n, hx⟩
use n; rw [inv_pow]
apply inv_mem (id hx : _ ∈ (⊥ : IntermediateField F E))
algebraMap_mem' := fun x ↦ ⟨0, by rw [pow_zero, pow_one]; exact ⟨x, rfl⟩⟩
variable {F E}
theorem mem_perfectClosure_iff {x : E} :
x ∈ perfectClosure F E ↔ ∃ n : ℕ, x ^ (ringExpChar F) ^ n ∈ (algebraMap F E).range := Iff.rfl
theorem mem_perfectClosure_iff_pow_mem (q : ℕ) [ExpChar F q] {x : E} :
x ∈ perfectClosure F E ↔ ∃ n : ℕ, x ^ q ^ n ∈ (algebraMap F E).range := by
rw [mem_perfectClosure_iff, ringExpChar.eq F q]
/-- An element is contained in the relative perfect closure if and only if its mininal polynomial
has separable degree one. -/
theorem mem_perfectClosure_iff_natSepDegree_eq_one {x : E} :
x ∈ perfectClosure F E ↔ (minpoly F x).natSepDegree = 1 := by
rw [mem_perfectClosure_iff, minpoly.natSepDegree_eq_one_iff_pow_mem (ringExpChar F)]
/-- A field extension `E / F` is purely inseparable if and only if the relative perfect closure of
`F` in `E` is equal to `E`. -/
theorem isPurelyInseparable_iff_perfectClosure_eq_top :
IsPurelyInseparable F E ↔ perfectClosure F E = ⊤ := by
rw [isPurelyInseparable_iff_pow_mem F (ringExpChar F)]
exact ⟨fun H ↦ top_unique fun x _ ↦ H x, fun H _ ↦ H.ge trivial⟩
variable (F E)
/-- The relative perfect closure of `F` in `E` is purely inseparable over `F`. -/
instance perfectClosure.isPurelyInseparable : IsPurelyInseparable F (perfectClosure F E) := by
rw [isPurelyInseparable_iff_pow_mem F (ringExpChar F)]
exact fun ⟨_, n, y, h⟩ ↦ ⟨n, y, (algebraMap _ E).injective h⟩
/-- The relative perfect closure of `F` in `E` is algebraic over `F`. -/
instance perfectClosure.isAlgebraic : Algebra.IsAlgebraic F (perfectClosure F E) :=
IsPurelyInseparable.isAlgebraic F _
/-- If `E / F` is separable, then the perfect closure of `F` in `E` is equal to `F`. Note that
the converse is not necessarily true (see https://math.stackexchange.com/a/3009197)
even when `E / F` is algebraic. -/
theorem perfectClosure.eq_bot_of_isSeparable [Algebra.IsSeparable F E] : perfectClosure F E = ⊥ :=
haveI := Algebra.isSeparable_tower_bot_of_isSeparable F (perfectClosure F E) E
eq_bot_of_isPurelyInseparable_of_isSeparable _
/-- An intermediate field of `E / F` is contained in the relative perfect closure of `F` in `E`
if it is purely inseparable over `F`. -/
theorem le_perfectClosure (L : IntermediateField F E) [h : IsPurelyInseparable F L] :
L ≤ perfectClosure F E := by
rw [isPurelyInseparable_iff_pow_mem F (ringExpChar F)] at h
intro x hx
obtain ⟨n, y, hy⟩ := h ⟨x, hx⟩
exact ⟨n, y, congr_arg (algebraMap L E) hy⟩
/-- An intermediate field of `E / F` is contained in the relative perfect closure of `F` in `E`
if and only if it is purely inseparable over `F`. -/
theorem le_perfectClosure_iff (L : IntermediateField F E) :
L ≤ perfectClosure F E ↔ IsPurelyInseparable F L := by
refine ⟨fun h ↦ (isPurelyInseparable_iff_pow_mem F (ringExpChar F)).2 fun x ↦ ?_,
fun _ ↦ le_perfectClosure F E L⟩
obtain ⟨n, y, hy⟩ := h x.2
exact ⟨n, y, (algebraMap L E).injective hy⟩
theorem separableClosure_inf_perfectClosure : separableClosure F E ⊓ perfectClosure F E = ⊥ :=
haveI := (le_separableClosure_iff F E _).mp (inf_le_left (b := perfectClosure F E))
haveI := (le_perfectClosure_iff F E _).mp (inf_le_right (a := separableClosure F E))
eq_bot_of_isPurelyInseparable_of_isSeparable _
section map
variable {F E K}
/-- If `i` is an `F`-algebra homomorphism from `E` to `K`, then `i x` is contained in
`perfectClosure F K` if and only if `x` is contained in `perfectClosure F E`. -/
theorem map_mem_perfectClosure_iff (i : E →ₐ[F] K) {x : E} :
i x ∈ perfectClosure F K ↔ x ∈ perfectClosure F E := by
simp_rw [mem_perfectClosure_iff]
refine ⟨fun ⟨n, y, h⟩ ↦ ⟨n, y, ?_⟩, fun ⟨n, y, h⟩ ↦ ⟨n, y, ?_⟩⟩
· apply_fun i using i.injective
rwa [AlgHom.commutes, map_pow]
simpa only [AlgHom.commutes, map_pow] using congr_arg i h
/-- If `i` is an `F`-algebra homomorphism from `E` to `K`, then the preimage of `perfectClosure F K`
under the map `i` is equal to `perfectClosure F E`. -/
theorem perfectClosure.comap_eq_of_algHom (i : E →ₐ[F] K) :
(perfectClosure F K).comap i = perfectClosure F E := by
ext x
exact map_mem_perfectClosure_iff i
/-- If `i` is an `F`-algebra homomorphism from `E` to `K`, then the image of `perfectClosure F E`
under the map `i` is contained in `perfectClosure F K`. -/
theorem perfectClosure.map_le_of_algHom (i : E →ₐ[F] K) :
(perfectClosure F E).map i ≤ perfectClosure F K :=
map_le_iff_le_comap.mpr (perfectClosure.comap_eq_of_algHom i).ge
/-- If `i` is an `F`-algebra isomorphism of `E` and `K`, then the image of `perfectClosure F E`
under the map `i` is equal to in `perfectClosure F K`. -/
theorem perfectClosure.map_eq_of_algEquiv (i : E ≃ₐ[F] K) :
(perfectClosure F E).map i.toAlgHom = perfectClosure F K :=
(map_le_of_algHom i.toAlgHom).antisymm (fun x hx ↦ ⟨i.symm x,
(map_mem_perfectClosure_iff i.symm.toAlgHom).2 hx, i.right_inv x⟩)
/-- If `E` and `K` are isomorphic as `F`-algebras, then `perfectClosure F E` and
`perfectClosure F K` are also isomorphic as `F`-algebras. -/
def perfectClosure.algEquivOfAlgEquiv (i : E ≃ₐ[F] K) :
perfectClosure F E ≃ₐ[F] perfectClosure F K :=
(intermediateFieldMap i _).trans (equivOfEq (map_eq_of_algEquiv i))
alias AlgEquiv.perfectClosure := perfectClosure.algEquivOfAlgEquiv
end map
/-- If `E` is a perfect field of exponential characteristic `p`, then the (relative) perfect closure
`perfectClosure F E` is perfect. -/
instance perfectClosure.perfectRing (p : ℕ) [ExpChar E p]
[PerfectRing E p] : PerfectRing (perfectClosure F E) p := .ofSurjective _ p fun x ↦ by
haveI := RingHom.expChar _ (algebraMap F E).injective p
obtain ⟨x', hx⟩ := surjective_frobenius E p x.1
obtain ⟨n, y, hy⟩ := (mem_perfectClosure_iff_pow_mem p).1 x.2
rw [frobenius_def] at hx
rw [← hx, ← pow_mul, ← pow_succ'] at hy
exact ⟨⟨x', (mem_perfectClosure_iff_pow_mem p).2 ⟨n + 1, y, hy⟩⟩, by
simp_rw [frobenius_def, SubmonoidClass.mk_pow, hx]⟩
/-- If `E` is a perfect field, then the (relative) perfect closure
`perfectClosure F E` is perfect. -/
instance perfectClosure.perfectField [PerfectField E] : PerfectField (perfectClosure F E) :=
PerfectRing.toPerfectField _ (ringExpChar E)
end perfectClosure
section IsPurelyInseparable
/-- If `K / E / F` is a field extension tower such that `K / F` is purely inseparable,
then `E / F` is also purely inseparable. -/
theorem IsPurelyInseparable.tower_bot [Algebra E K] [IsScalarTower F E K]
[IsPurelyInseparable F K] : IsPurelyInseparable F E := by
refine ⟨⟨fun x ↦ (isIntegral' F (algebraMap E K x)).tower_bot_of_field⟩, fun x h ↦ ?_⟩
rw [IsSeparable, ← minpoly.algebraMap_eq (algebraMap E K).injective] at h
obtain ⟨y, h⟩ := inseparable F _ h
exact ⟨y, (algebraMap E K).injective (h.symm ▸ (IsScalarTower.algebraMap_apply F E K y).symm)⟩
/-- If `K / E / F` is a field extension tower such that `K / F` is purely inseparable,
then `K / E` is also purely inseparable. -/
theorem IsPurelyInseparable.tower_top [Algebra E K] [IsScalarTower F E K]
[h : IsPurelyInseparable F K] : IsPurelyInseparable E K := by
obtain ⟨q, _⟩ := ExpChar.exists F
haveI := expChar_of_injective_algebraMap (algebraMap F E).injective q
rw [isPurelyInseparable_iff_pow_mem _ q] at h ⊢
intro x
obtain ⟨n, y, h⟩ := h x
exact ⟨n, (algebraMap F E) y, h.symm ▸ (IsScalarTower.algebraMap_apply F E K y).symm⟩
/-- If `E / F` and `K / E` are both purely inseparable extensions, then `K / F` is also
purely inseparable. -/
theorem IsPurelyInseparable.trans [Algebra E K] [IsScalarTower F E K]
[h1 : IsPurelyInseparable F E] [h2 : IsPurelyInseparable E K] : IsPurelyInseparable F K := by
obtain ⟨q, _⟩ := ExpChar.exists F
haveI := expChar_of_injective_algebraMap (algebraMap F E).injective q
rw [isPurelyInseparable_iff_pow_mem _ q] at h1 h2 ⊢
intro x
obtain ⟨n, y, h2⟩ := h2 x
obtain ⟨m, z, h1⟩ := h1 y
refine ⟨n + m, z, ?_⟩
rw [IsScalarTower.algebraMap_apply F E K, h1, map_pow, h2, ← pow_mul, ← pow_add]
variable {E}
/-- A field extension `E / F` is purely inseparable if and only if for every element `x` of `E`,
its minimal polynomial has separable degree one. -/
theorem isPurelyInseparable_iff_natSepDegree_eq_one :
IsPurelyInseparable F E ↔ ∀ x : E, (minpoly F x).natSepDegree = 1 := by
obtain ⟨q, _⟩ := ExpChar.exists F
simp_rw [isPurelyInseparable_iff_pow_mem F q, minpoly.natSepDegree_eq_one_iff_pow_mem q]
theorem IsPurelyInseparable.natSepDegree_eq_one [IsPurelyInseparable F E] (x : E) :
(minpoly F x).natSepDegree = 1 :=
(isPurelyInseparable_iff_natSepDegree_eq_one F).1 ‹_› x
/-- A field extension `E / F` of exponential characteristic `q` is purely inseparable
if and only if for every element `x` of `E`, the minimal polynomial of `x` over `F` is of form
`X ^ (q ^ n) - y` for some natural number `n` and some element `y` of `F`. -/
theorem isPurelyInseparable_iff_minpoly_eq_X_pow_sub_C (q : ℕ) [hF : ExpChar F q] :
IsPurelyInseparable F E ↔ ∀ x : E, ∃ (n : ℕ) (y : F), minpoly F x = X ^ q ^ n - C y := by
simp_rw [isPurelyInseparable_iff_natSepDegree_eq_one,
minpoly.natSepDegree_eq_one_iff_eq_X_pow_sub_C q]
theorem IsPurelyInseparable.minpoly_eq_X_pow_sub_C (q : ℕ) [ExpChar F q] [IsPurelyInseparable F E]
(x : E) : ∃ (n : ℕ) (y : F), minpoly F x = X ^ q ^ n - C y :=
(isPurelyInseparable_iff_minpoly_eq_X_pow_sub_C F q).1 ‹_› x
/-- A field extension `E / F` of exponential characteristic `q` is purely inseparable
if and only if for every element `x` of `E`, the minimal polynomial of `x` over `F` is of form
`(X - x) ^ (q ^ n)` for some natural number `n`. -/
theorem isPurelyInseparable_iff_minpoly_eq_X_sub_C_pow (q : ℕ) [hF : ExpChar F q] :
IsPurelyInseparable F E ↔
∀ x : E, ∃ n : ℕ, (minpoly F x).map (algebraMap F E) = (X - C x) ^ q ^ n := by
simp_rw [isPurelyInseparable_iff_natSepDegree_eq_one,
minpoly.natSepDegree_eq_one_iff_eq_X_sub_C_pow q]
theorem IsPurelyInseparable.minpoly_eq_X_sub_C_pow (q : ℕ) [ExpChar F q] [IsPurelyInseparable F E]
(x : E) : ∃ n : ℕ, (minpoly F x).map (algebraMap F E) = (X - C x) ^ q ^ n :=
(isPurelyInseparable_iff_minpoly_eq_X_sub_C_pow F q).1 ‹_› x
variable (E)
-- TODO: remove `halg` assumption
variable {F E} in
/-- If an algebraic extension has finite separable degree one, then it is purely inseparable. -/
theorem isPurelyInseparable_of_finSepDegree_eq_one [Algebra.IsAlgebraic F E]
(hdeg : finSepDegree F E = 1) : IsPurelyInseparable F E := by
rw [isPurelyInseparable_iff]
refine fun x ↦ ⟨Algebra.IsIntegral.isIntegral x, fun hsep ↦ ?_⟩
have : Algebra.IsAlgebraic F⟮x⟯ E := Algebra.IsAlgebraic.tower_top (K := F) F⟮x⟯
have := finSepDegree_mul_finSepDegree_of_isAlgebraic F F⟮x⟯ E
rw [hdeg, mul_eq_one, (finSepDegree_adjoin_simple_eq_finrank_iff F E x
(Algebra.IsAlgebraic.isAlgebraic x)).2 hsep,
IntermediateField.finrank_eq_one_iff] at this
simpa only [this.1] using mem_adjoin_simple_self F x
/-- If `E / F` is purely inseparable, then for any reduced ring `L`, the map `(E →+* L) → (F →+* L)`
induced by `algebraMap F E` is injective. In particular, a purely inseparable field extension
is an epimorphism in the category of fields. -/
theorem IsPurelyInseparable.injective_comp_algebraMap [IsPurelyInseparable F E]
(L : Type w) [CommRing L] [IsReduced L] :
Function.Injective fun f : E →+* L ↦ f.comp (algebraMap F E) := fun f g heq ↦ by
ext x
let q := ringExpChar F
obtain ⟨n, y, h⟩ := IsPurelyInseparable.pow_mem F q x
replace heq := congr($heq y)
simp_rw [RingHom.comp_apply, h, map_pow] at heq
nontriviality L
haveI := expChar_of_injective_ringHom (f.comp (algebraMap F E)).injective q
exact iterateFrobenius_inj L q n heq
/-- If `E / F` is purely inseparable, then for any reduced `F`-algebra `L`, there exists at most one
`F`-algebra homomorphism from `E` to `L`. -/
instance instSubsingletonAlgHomOfIsPurelyInseparable [IsPurelyInseparable F E] (L : Type w)
[CommRing L] [IsReduced L] [Algebra F L] : Subsingleton (E →ₐ[F] L) where
allEq f g := AlgHom.coe_ringHom_injective <|
IsPurelyInseparable.injective_comp_algebraMap F E L (by simp_rw [AlgHom.comp_algebraMap])
instance instUniqueAlgHomOfIsPurelyInseparable [IsPurelyInseparable F E] (L : Type w)
[CommRing L] [IsReduced L] [Algebra F L] [Algebra E L] [IsScalarTower F E L] :
Unique (E →ₐ[F] L) := uniqueOfSubsingleton (IsScalarTower.toAlgHom F E L)
/-- If `E / F` is purely inseparable, then `Field.Emb F E` has exactly one element. -/
instance instUniqueEmbOfIsPurelyInseparable [IsPurelyInseparable F E] :
Unique (Emb F E) := instUniqueAlgHomOfIsPurelyInseparable F E _
/-- A purely inseparable extension has finite separable degree one. -/
theorem IsPurelyInseparable.finSepDegree_eq_one [IsPurelyInseparable F E] :
finSepDegree F E = 1 := Nat.card_unique
/-- A purely inseparable extension has separable degree one. -/
theorem IsPurelyInseparable.sepDegree_eq_one [IsPurelyInseparable F E] :
sepDegree F E = 1 := by
rw [sepDegree, separableClosure.eq_bot_of_isPurelyInseparable, IntermediateField.rank_bot]
/-- A purely inseparable extension has inseparable degree equal to degree. -/
theorem IsPurelyInseparable.insepDegree_eq [IsPurelyInseparable F E] :
insepDegree F E = Module.rank F E := by
rw [insepDegree, separableClosure.eq_bot_of_isPurelyInseparable, rank_bot']
/-- A purely inseparable extension has finite inseparable degree equal to degree. -/
theorem IsPurelyInseparable.finInsepDegree_eq [IsPurelyInseparable F E] :
finInsepDegree F E = finrank F E := congr(Cardinal.toNat $(insepDegree_eq F E))
-- TODO: remove `halg` assumption
/-- An algebraic extension is purely inseparable if and only if it has finite separable
degree one. -/
theorem isPurelyInseparable_iff_finSepDegree_eq_one [Algebra.IsAlgebraic F E] :
IsPurelyInseparable F E ↔ finSepDegree F E = 1 :=
⟨fun _ ↦ IsPurelyInseparable.finSepDegree_eq_one F E,
fun h ↦ isPurelyInseparable_of_finSepDegree_eq_one h⟩
variable {F E} in
/-- An algebraic extension is purely inseparable if and only if all of its finite dimensional
subextensions are purely inseparable. -/
theorem isPurelyInseparable_iff_fd_isPurelyInseparable [Algebra.IsAlgebraic F E] :
IsPurelyInseparable F E ↔
∀ L : IntermediateField F E, FiniteDimensional F L → IsPurelyInseparable F L := by
refine ⟨fun _ _ _ ↦ IsPurelyInseparable.tower_bot F _ E,
fun h ↦ isPurelyInseparable_iff.2 fun x ↦ ?_⟩
have hx : IsIntegral F x := Algebra.IsIntegral.isIntegral x
refine ⟨hx, fun _ ↦ ?_⟩
obtain ⟨y, h⟩ := (h _ (adjoin.finiteDimensional hx)).inseparable' _ <|
show Separable (minpoly F (AdjoinSimple.gen F x)) by rwa [minpoly_eq]
exact ⟨y, congr_arg (algebraMap _ E) h⟩
/-- A purely inseparable extension is normal. -/
instance IsPurelyInseparable.normal [IsPurelyInseparable F E] : Normal F E where
toIsAlgebraic := isAlgebraic F E
splits' x := by
obtain ⟨n, h⟩ := IsPurelyInseparable.minpoly_eq_X_sub_C_pow F (ringExpChar F) x
rw [← splits_id_iff_splits, h]
exact splits_pow _ (splits_X_sub_C _) _
/-- If `E / F` is algebraic, then `E` is purely inseparable over the
separable closure of `F` in `E`. -/
theorem separableClosure.isPurelyInseparable [Algebra.IsAlgebraic F E] :
IsPurelyInseparable (separableClosure F E) E := isPurelyInseparable_iff.2 fun x ↦ by
set L := separableClosure F E
refine ⟨(IsAlgebraic.tower_top L (Algebra.IsAlgebraic.isAlgebraic (R := F) x)).isIntegral,
fun h ↦ ?_⟩
haveI := (isSeparable_adjoin_simple_iff_isSeparable L E).2 h
haveI : Algebra.IsSeparable F (restrictScalars F L⟮x⟯) := Algebra.IsSeparable.trans F L L⟮x⟯
have hx : x ∈ restrictScalars F L⟮x⟯ := mem_adjoin_simple_self _ x
exact ⟨⟨x, mem_separableClosure_iff.2 <| isSeparable_of_mem_isSeparable F E hx⟩, rfl⟩
/-- An intermediate field of `E / F` contains the separable closure of `F` in `E`
if `E` is purely inseparable over it. -/
theorem separableClosure_le (L : IntermediateField F E)
[h : IsPurelyInseparable L E] : separableClosure F E ≤ L := fun x hx ↦ by
obtain ⟨y, rfl⟩ := h.inseparable' _ <|
IsSeparable.of_isScalarTower L (mem_separableClosure_iff.1 hx)
exact y.2
/-- If `E / F` is algebraic, then an intermediate field of `E / F` contains the
separable closure of `F` in `E` if and only if `E` is purely inseparable over it. -/
theorem separableClosure_le_iff [Algebra.IsAlgebraic F E] (L : IntermediateField F E) :
separableClosure F E ≤ L ↔ IsPurelyInseparable L E := by
refine ⟨fun h ↦ ?_, fun _ ↦ separableClosure_le F E L⟩
have := separableClosure.isPurelyInseparable F E
letI := (inclusion h).toAlgebra
letI : SMul (separableClosure F E) L := Algebra.toSMul
haveI : IsScalarTower (separableClosure F E) L E := IsScalarTower.of_algebraMap_eq (congrFun rfl)
exact IsPurelyInseparable.tower_top (separableClosure F E) L E
/-- If an intermediate field of `E / F` is separable over `F`, and `E` is purely inseparable
over it, then it is equal to the separable closure of `F` in `E`. -/
theorem eq_separableClosure (L : IntermediateField F E)
[Algebra.IsSeparable F L] [IsPurelyInseparable L E] : L = separableClosure F E :=
le_antisymm (le_separableClosure F E L) (separableClosure_le F E L)
open separableClosure in
/-- If `E / F` is algebraic, then an intermediate field of `E / F` is equal to the separable closure
of `F` in `E` if and only if it is separable over `F`, and `E` is purely inseparable
over it. -/
theorem eq_separableClosure_iff [Algebra.IsAlgebraic F E] (L : IntermediateField F E) :
L = separableClosure F E ↔ Algebra.IsSeparable F L ∧ IsPurelyInseparable L E :=
⟨by rintro rfl; exact ⟨isSeparable F E, isPurelyInseparable F E⟩,
fun ⟨_, _⟩ ↦ eq_separableClosure F E L⟩
-- TODO: prove it
set_option linter.unusedVariables false in
/-- If `L` is an algebraically closed field containing `E`, such that the map
`(E →+* L) → (F →+* L)` induced by `algebraMap F E` is injective, then `E / F` is
purely inseparable. As a corollary, epimorphisms in the category of fields must be
purely inseparable extensions. -/
proof_wanted IsPurelyInseparable.of_injective_comp_algebraMap (L : Type w) [Field L] [IsAlgClosed L]
(hn : Nonempty (E →+* L)) (h : Function.Injective fun f : E →+* L ↦ f.comp (algebraMap F E)) :
IsPurelyInseparable F E
end IsPurelyInseparable
namespace IntermediateField
instance isPurelyInseparable_bot : IsPurelyInseparable F (⊥ : IntermediateField F E) :=
(botEquiv F E).symm.isPurelyInseparable
/-- `F⟮x⟯ / F` is a purely inseparable extension if and only if the mininal polynomial of `x`
has separable degree one. -/
theorem isPurelyInseparable_adjoin_simple_iff_natSepDegree_eq_one {x : E} :
IsPurelyInseparable F F⟮x⟯ ↔ (minpoly F x).natSepDegree = 1 := by
rw [← le_perfectClosure_iff, adjoin_simple_le_iff, mem_perfectClosure_iff_natSepDegree_eq_one]
/-- If `F` is of exponential characteristic `q`, then `F⟮x⟯ / F` is a purely inseparable extension
if and only if `x ^ (q ^ n)` is contained in `F` for some `n : ℕ`. -/
theorem isPurelyInseparable_adjoin_simple_iff_pow_mem (q : ℕ) [hF : ExpChar F q] {x : E} :
IsPurelyInseparable F F⟮x⟯ ↔ ∃ n : ℕ, x ^ q ^ n ∈ (algebraMap F E).range := by
rw [← le_perfectClosure_iff, adjoin_simple_le_iff, mem_perfectClosure_iff_pow_mem q]
/-- If `F` is of exponential characteristic `q`, then `F(S) / F` is a purely inseparable extension
if and only if for any `x ∈ S`, `x ^ (q ^ n)` is contained in `F` for some `n : ℕ`. -/
theorem isPurelyInseparable_adjoin_iff_pow_mem (q : ℕ) [hF : ExpChar F q] {S : Set E} :
IsPurelyInseparable F (adjoin F S) ↔ ∀ x ∈ S, ∃ n : ℕ, x ^ q ^ n ∈ (algebraMap F E).range := by
simp_rw [← le_perfectClosure_iff, adjoin_le_iff, ← mem_perfectClosure_iff_pow_mem q,
Set.le_iff_subset, Set.subset_def, SetLike.mem_coe]
/-- A compositum of two purely inseparable extensions is purely inseparable. -/
instance isPurelyInseparable_sup (L1 L2 : IntermediateField F E)
[h1 : IsPurelyInseparable F L1] [h2 : IsPurelyInseparable F L2] :
IsPurelyInseparable F (L1 ⊔ L2 : IntermediateField F E) := by
rw [← le_perfectClosure_iff] at h1 h2 ⊢
exact sup_le h1 h2
/-- A compositum of purely inseparable extensions is purely inseparable. -/
instance isPurelyInseparable_iSup {ι : Sort*} {t : ι → IntermediateField F E}
[h : ∀ i, IsPurelyInseparable F (t i)] :
IsPurelyInseparable F (⨆ i, t i : IntermediateField F E) := by
simp_rw [← le_perfectClosure_iff] at h ⊢
exact iSup_le h
/-- If `F` is a field of exponential characteristic `q`, `F(S) / F` is separable, then
`F(S) = F(S ^ (q ^ n))` for any natural number `n`. -/
theorem adjoin_eq_adjoin_pow_expChar_pow_of_isSeparable (S : Set E)
[Algebra.IsSeparable F (adjoin F S)] (q : ℕ) [ExpChar F q] (n : ℕ) :
adjoin F S = adjoin F ((· ^ q ^ n) '' S) := by
set L := adjoin F S
set M := adjoin F ((· ^ q ^ n) '' S)
have hi : M ≤ L := by
rw [adjoin_le_iff]
rintro _ ⟨y, hy, rfl⟩
exact pow_mem (subset_adjoin F S hy) _
letI := (inclusion hi).toAlgebra
haveI : Algebra.IsSeparable M (extendScalars hi) :=
Algebra.isSeparable_tower_top_of_isSeparable F M L
haveI : IsPurelyInseparable M (extendScalars hi) := by
haveI := expChar_of_injective_algebraMap (algebraMap F M).injective q
rw [extendScalars_adjoin hi, isPurelyInseparable_adjoin_iff_pow_mem M _ q]
exact fun x hx ↦ ⟨n, ⟨x ^ q ^ n, subset_adjoin F _ ⟨x, hx, rfl⟩⟩, rfl⟩
simpa only [extendScalars_restrictScalars, restrictScalars_bot_eq_self] using congr_arg
(restrictScalars F) (extendScalars hi).eq_bot_of_isPurelyInseparable_of_isSeparable
/-- If `E / F` is a separable field extension of exponential characteristic `q`, then
`F(S) = F(S ^ (q ^ n))` for any subset `S` of `E` and any natural number `n`. -/
theorem adjoin_eq_adjoin_pow_expChar_pow_of_isSeparable' [Algebra.IsSeparable F E] (S : Set E)
(q : ℕ) [ExpChar F q] (n : ℕ) : adjoin F S = adjoin F ((· ^ q ^ n) '' S) :=
haveI := Algebra.isSeparable_tower_bot_of_isSeparable F (adjoin F S) E
adjoin_eq_adjoin_pow_expChar_pow_of_isSeparable F E S q n
-- TODO: prove the converse when `F(S) / F` is finite
/-- If `F` is a field of exponential characteristic `q`, `F(S) / F` is separable, then
`F(S) = F(S ^ q)`. -/
theorem adjoin_eq_adjoin_pow_expChar_of_isSeparable (S : Set E) [Algebra.IsSeparable F (adjoin F S)]
(q : ℕ) [ExpChar F q] : adjoin F S = adjoin F ((· ^ q) '' S) :=
pow_one q ▸ adjoin_eq_adjoin_pow_expChar_pow_of_isSeparable F E S q 1
/-- If `E / F` is a separable field extension of exponential characteristic `q`, then
`F(S) = F(S ^ q)` for any subset `S` of `E`. -/
theorem adjoin_eq_adjoin_pow_expChar_of_isSeparable' [Algebra.IsSeparable F E] (S : Set E)
(q : ℕ) [ExpChar F q] : adjoin F S = adjoin F ((· ^ q) '' S) :=
pow_one q ▸ adjoin_eq_adjoin_pow_expChar_pow_of_isSeparable' F E S q 1
end IntermediateField
section
variable (q n : ℕ) [hF : ExpChar F q] {ι : Type*} {v : ι → E} {F E}
/-- If `E / F` is a separable extension of exponential characteristic `q`, if `{ u_i }` is a family
of elements of `E` which `F`-linearly spans `E`, then `{ u_i ^ (q ^ n) }` also `F`-linearly spans
`E` for any natural number `n`. -/
theorem Field.span_map_pow_expChar_pow_eq_top_of_isSeparable [Algebra.IsSeparable F E]
(h : Submodule.span F (Set.range v) = ⊤) :
Submodule.span F (Set.range (v · ^ q ^ n)) = ⊤ := by
erw [← Algebra.top_toSubmodule, ← top_toSubalgebra, ← adjoin_univ,
adjoin_eq_adjoin_pow_expChar_pow_of_isSeparable' F E _ q n,
adjoin_algebraic_toSubalgebra fun x _ ↦ Algebra.IsAlgebraic.isAlgebraic x,
Set.image_univ, Algebra.adjoin_eq_span, (powMonoidHom _).mrange.closure_eq]
refine (Submodule.span_mono <| Set.range_comp_subset_range _ _).antisymm (Submodule.span_le.2 ?_)
rw [Set.range_comp, ← Set.image_univ]
haveI := expChar_of_injective_algebraMap (algebraMap F E).injective q
apply h ▸ Submodule.image_span_subset_span (LinearMap.iterateFrobenius F E q n) _
/-- If `E / F` is a finite separable extension of exponential characteristic `q`, if `{ u_i }` is a
family of elements of `E` which is `F`-linearly independent, then `{ u_i ^ (q ^ n) }` is also
`F`-linearly independent for any natural number `n`. A special case of
`LinearIndependent.map_pow_expChar_pow_of_isSeparable`
and is an intermediate result used to prove it. -/
private theorem LinearIndependent.map_pow_expChar_pow_of_fd_isSeparable
[FiniteDimensional F E] [Algebra.IsSeparable F E]
(h : LinearIndependent F v) : LinearIndependent F (v · ^ q ^ n) := by
have h' := h.coe_range
let ι' := h'.extend (Set.range v).subset_univ
let b : Basis ι' F E := Basis.extend h'
letI : Fintype ι' := fintypeBasisIndex b
have H := linearIndependent_of_top_le_span_of_card_eq_finrank
(span_map_pow_expChar_pow_eq_top_of_isSeparable q n b.span_eq).ge
(finrank_eq_card_basis b).symm
let f (i : ι) : ι' := ⟨v i, h'.subset_extend _ ⟨i, rfl⟩⟩
convert H.comp f fun _ _ heq ↦ h.injective (by simpa only [f, Subtype.mk.injEq] using heq)
simp_rw [Function.comp_apply, b, Basis.extend_apply_self]
/-- If `E / F` is a separable extension of exponential characteristic `q`, if `{ u_i }` is a
family of elements of `E` which is `F`-linearly independent, then `{ u_i ^ (q ^ n) }` is also
`F`-linearly independent for any natural number `n`. -/
theorem LinearIndependent.map_pow_expChar_pow_of_isSeparable [Algebra.IsSeparable F E]
(h : LinearIndependent F v) : LinearIndependent F (v · ^ q ^ n) := by
classical
have halg := Algebra.IsSeparable.isAlgebraic F E
rw [linearIndependent_iff_finset_linearIndependent] at h ⊢
intro s
let E' := adjoin F (s.image v : Set E)
haveI : FiniteDimensional F E' := finiteDimensional_adjoin
fun x _ ↦ Algebra.IsIntegral.isIntegral x
haveI : Algebra.IsSeparable F E' := Algebra.isSeparable_tower_bot_of_isSeparable F E' E
let v' (i : s) : E' := ⟨v i.1, subset_adjoin F _ (Finset.mem_image.2 ⟨i.1, i.2, rfl⟩)⟩
have h' : LinearIndependent F v' := (h s).of_comp E'.val.toLinearMap
exact (h'.map_pow_expChar_pow_of_fd_isSeparable q n).map'
E'.val.toLinearMap (LinearMap.ker_eq_bot_of_injective E'.val.injective)
/-- If `E / F` is a field extension of exponential characteristic `q`, if `{ u_i }` is a
family of separable elements of `E` which is `F`-linearly independent, then `{ u_i ^ (q ^ n) }`
is also `F`-linearly independent for any natural number `n`. -/
theorem LinearIndependent.map_pow_expChar_pow_of_isIntegral'
(hsep : ∀ i : ι, IsSeparable F (v i))
(h : LinearIndependent F v) : LinearIndependent F (v · ^ q ^ n) := by
let E' := adjoin F (Set.range v)
haveI : Algebra.IsSeparable F E' := (isSeparable_adjoin_iff_isSeparable F _).2 <| by
rintro _ ⟨y, rfl⟩; exact hsep y
let v' (i : ι) : E' := ⟨v i, subset_adjoin F _ ⟨i, rfl⟩⟩
have h' : LinearIndependent F v' := h.of_comp E'.val.toLinearMap
exact (h'.map_pow_expChar_pow_of_isSeparable q n).map'
E'.val.toLinearMap (LinearMap.ker_eq_bot_of_injective E'.val.injective)
/-- If `E / F` is a separable extension of exponential characteristic `q`, if `{ u_i }` is an
`F`-basis of `E`, then `{ u_i ^ (q ^ n) }` is also an `F`-basis of `E`
for any natural number `n`. -/
def Basis.mapPowExpCharPowOfIsSeparable [Algebra.IsSeparable F E]
(b : Basis ι F E) : Basis ι F E :=
Basis.mk (b.linearIndependent.map_pow_expChar_pow_of_isSeparable q n)
(span_map_pow_expChar_pow_eq_top_of_isSeparable q n b.span_eq).ge
end
/-- If `E` is an algebraic closure of `F`, then `F` is separably closed if and only if `E / F` is
purely inseparable. -/
theorem isSepClosed_iff_isPurelyInseparable_algebraicClosure [IsAlgClosure F E] :
IsSepClosed F ↔ IsPurelyInseparable F E :=
⟨fun _ ↦ IsAlgClosure.algebraic.isPurelyInseparable_of_isSepClosed, fun H ↦ by
haveI := IsAlgClosure.alg_closed F (K := E)
rwa [← separableClosure.eq_bot_iff, IsSepClosed.separableClosure_eq_bot_iff] at H⟩
variable {F E} in
/-- If `E / F` is an algebraic extension, `F` is separably closed,
then `E` is also separably closed. -/
theorem Algebra.IsAlgebraic.isSepClosed [Algebra.IsAlgebraic F E]
[IsSepClosed F] : IsSepClosed E :=
have : Algebra.IsAlgebraic F (AlgebraicClosure E) := Algebra.IsAlgebraic.trans (L := E)
have : IsPurelyInseparable F (AlgebraicClosure E) := isPurelyInseparable_of_isSepClosed
(isSepClosed_iff_isPurelyInseparable_algebraicClosure E _).mpr
(IsPurelyInseparable.tower_top F E <| AlgebraicClosure E)
theorem perfectField_of_perfectClosure_eq_bot [h : PerfectField E] (eq : perfectClosure F E = ⊥) :
PerfectField F := by
let p := ringExpChar F
haveI := expChar_of_injective_algebraMap (algebraMap F E).injective p
haveI := PerfectRing.ofSurjective F p fun x ↦ by
obtain ⟨y, h⟩ := surjective_frobenius E p (algebraMap F E x)
have : y ∈ perfectClosure F E := ⟨1, x, by rw [← h, pow_one, frobenius_def, ringExpChar.eq F p]⟩
obtain ⟨z, rfl⟩ := eq ▸ this
exact ⟨z, (algebraMap F E).injective (by erw [RingHom.map_frobenius, h])⟩
exact PerfectRing.toPerfectField F p
/-- If `E / F` is a separable extension, `E` is perfect, then `F` is also prefect. -/
theorem perfectField_of_isSeparable_of_perfectField_top [Algebra.IsSeparable F E] [PerfectField E] :
PerfectField F :=
perfectField_of_perfectClosure_eq_bot F E (perfectClosure.eq_bot_of_isSeparable F E)
/-- If `E` is an algebraic closure of `F`, then `F` is perfect if and only if `E / F` is
separable. -/
theorem perfectField_iff_isSeparable_algebraicClosure [IsAlgClosure F E] :
PerfectField F ↔ Algebra.IsSeparable F E :=
⟨fun _ ↦ IsSepClosure.separable, fun _ ↦ haveI : IsAlgClosed E := IsAlgClosure.alg_closed F
perfectField_of_isSeparable_of_perfectField_top F E⟩
namespace Field
/-- If `E / F` is algebraic, then the `Field.finSepDegree F E` is equal to `Field.sepDegree F E`
as a natural number. This means that the cardinality of `Field.Emb F E` and the degree of
`(separableClosure F E) / F` are both finite or infinite, and when they are finite, they
coincide. -/
theorem finSepDegree_eq [Algebra.IsAlgebraic F E] :
finSepDegree F E = Cardinal.toNat (sepDegree F E) := by
have : Algebra.IsAlgebraic (separableClosure F E) E := Algebra.IsAlgebraic.tower_top (K := F) _
have h := finSepDegree_mul_finSepDegree_of_isAlgebraic F (separableClosure F E) E |>.symm
haveI := separableClosure.isSeparable F E
haveI := separableClosure.isPurelyInseparable F E
rwa [finSepDegree_eq_finrank_of_isSeparable F (separableClosure F E),
IsPurelyInseparable.finSepDegree_eq_one (separableClosure F E) E, mul_one] at h
/-- The finite separable degree multiply by the finite inseparable degree is equal
to the (finite) field extension degree. -/
theorem finSepDegree_mul_finInsepDegree : finSepDegree F E * finInsepDegree F E = finrank F E := by
by_cases halg : Algebra.IsAlgebraic F E
· have := congr_arg Cardinal.toNat (sepDegree_mul_insepDegree F E)
rwa [Cardinal.toNat_mul, ← finSepDegree_eq F E] at this
rw [finInsepDegree, finrank_of_infinite_dimensional (K := F) (V := E) fun _ ↦
halg (Algebra.IsAlgebraic.of_finite F E),
finrank_of_infinite_dimensional (K := separableClosure F E) (V := E) fun _ ↦
halg ((separableClosure.isAlgebraic F E).trans),
mul_zero]
end Field
namespace separableClosure
variable [Algebra E K] [IsScalarTower F E K] {F E}
/-- If `K / E / F` is a field extension tower, such that `E / F` is algebraic and `K / E`
is separable, then `E` adjoin `separableClosure F K` is equal to `K`. It is a special case of
`separableClosure.adjoin_eq_of_isAlgebraic`, and is an intermediate result used to prove it. -/
lemma adjoin_eq_of_isAlgebraic_of_isSeparable [Algebra.IsAlgebraic F E]
[Algebra.IsSeparable E K] : adjoin E (separableClosure F K : Set K) = ⊤ :=
top_unique fun x _ ↦ by
set S := separableClosure F K
set L := adjoin E (S : Set K)
have := Algebra.isSeparable_tower_top_of_isSeparable E L K
let i : S →+* L := Subsemiring.inclusion fun x hx ↦ subset_adjoin E (S : Set K) hx
let _ : Algebra S L := i.toAlgebra
let _ : SMul S L := Algebra.toSMul
have : IsScalarTower S L K := IsScalarTower.of_algebraMap_eq (congrFun rfl)
have : Algebra.IsAlgebraic F K := Algebra.IsAlgebraic.trans (L := E)
have : IsPurelyInseparable S K := separableClosure.isPurelyInseparable F K
have := IsPurelyInseparable.tower_top S L K
obtain ⟨y, rfl⟩ := IsPurelyInseparable.surjective_algebraMap_of_isSeparable L K x
exact y.2
/-- If `K / E / F` is a field extension tower, such that `E / F` is algebraic, then
`E` adjoin `separableClosure F K` is equal to `separableClosure E K`. -/
theorem adjoin_eq_of_isAlgebraic [Algebra.IsAlgebraic F E] :
adjoin E (separableClosure F K) = separableClosure E K := by
set S := separableClosure E K
have h := congr_arg lift (adjoin_eq_of_isAlgebraic_of_isSeparable (F := F) S)
rw [lift_top, lift_adjoin] at h
haveI : IsScalarTower F S K := IsScalarTower.of_algebraMap_eq (congrFun rfl)
rw [← h, ← map_eq_of_separableClosure_eq_bot F (separableClosure_eq_bot E K)]
simp only [coe_map, IsScalarTower.coe_toAlgHom', IntermediateField.algebraMap_apply]
end separableClosure
section TowerLaw
variable [Algebra E K] [IsScalarTower F E K]
variable {F K} in
/-- If `K / E / F` is a field extension tower such that `E / F` is purely inseparable,
if `{ u_i }` is a family of separable elements of `K` which is `F`-linearly independent,
then it is also `E`-linearly independent. -/
theorem LinearIndependent.map_of_isPurelyInseparable_of_isSeparable [IsPurelyInseparable F E]
{ι : Type*} {v : ι → K} (hsep : ∀ i : ι, IsSeparable F (v i))
(h : LinearIndependent F v) : LinearIndependent E v := by
obtain ⟨q, _⟩ := ExpChar.exists F
haveI := expChar_of_injective_algebraMap (algebraMap F K).injective q
refine linearIndependent_iff.mpr fun l hl ↦ Finsupp.ext fun i ↦ ?_
choose f hf using fun i ↦ (isPurelyInseparable_iff_pow_mem F q).1 ‹_› (l i)
let n := l.support.sup f
have := (expChar_pow_pos F q n).ne'
replace hf (i : ι) : l i ^ q ^ n ∈ (algebraMap F E).range := by
by_cases hs : i ∈ l.support
· convert pow_mem (hf i) (q ^ (n - f i)) using 1
rw [← pow_mul, ← pow_add, Nat.add_sub_of_le (Finset.le_sup hs)]
exact ⟨0, by rw [map_zero, Finsupp.not_mem_support_iff.1 hs, zero_pow this]⟩
choose lF hlF using hf
let lF₀ := Finsupp.onFinset l.support lF fun i ↦ by
contrapose!
refine fun hs ↦ (injective_iff_map_eq_zero _).mp (algebraMap F E).injective _ ?_
rw [hlF, Finsupp.not_mem_support_iff.1 hs, zero_pow this]
replace h := linearIndependent_iff.1 (h.map_pow_expChar_pow_of_isIntegral' q n hsep) lF₀ <| by
replace hl := congr($hl ^ q ^ n)
rw [Finsupp.total_apply, Finsupp.sum, sum_pow_char_pow, zero_pow this] at hl
rw [← hl, Finsupp.total_apply, Finsupp.onFinset_sum _ (fun _ ↦ by exact zero_smul _ _)]
refine Finset.sum_congr rfl fun i _ ↦ ?_
simp_rw [Algebra.smul_def, mul_pow, IsScalarTower.algebraMap_apply F E K, hlF, map_pow]
refine pow_eq_zero ((hlF _).symm.trans ?_)
convert map_zero (algebraMap F E)
exact congr($h i)
namespace Field
/-- If `K / E / F` is a field extension tower, such that `E / F` is purely inseparable and `K / E`
is separable, then the separable degree of `K / F` is equal to the degree of `K / E`.
It is a special case of `Field.lift_sepDegree_mul_lift_sepDegree_of_isAlgebraic`, and is an
intermediate result used to prove it. -/
lemma sepDegree_eq_of_isPurelyInseparable_of_isSeparable
[IsPurelyInseparable F E] [Algebra.IsSeparable E K] : sepDegree F K = Module.rank E K := by
let S := separableClosure F K
have h := S.adjoin_rank_le_of_isAlgebraic_right E
rw [separableClosure.adjoin_eq_of_isAlgebraic_of_isSeparable K, rank_top'] at h
obtain ⟨ι, ⟨b⟩⟩ := Basis.exists_basis F S
exact h.antisymm' (b.mk_eq_rank'' ▸ (b.linearIndependent.map' S.val.toLinearMap
(LinearMap.ker_eq_bot_of_injective S.val.injective)
|>.map_of_isPurelyInseparable_of_isSeparable E (fun i ↦
by simpa only [IsSeparable, minpoly_eq] using Algebra.IsSeparable.isSeparable F (b i))
|>.cardinal_le_rank))
/-- If `K / E / F` is a field extension tower, such that `E / F` is separable,
then $[E:F] [K:E]_s = [K:F]_s$.
It is a special case of `Field.lift_sepDegree_mul_lift_sepDegree_of_isAlgebraic`, and is an
intermediate result used to prove it. -/
lemma lift_rank_mul_lift_sepDegree_of_isSeparable [Algebra.IsSeparable F E] :
Cardinal.lift.{w} (Module.rank F E) * Cardinal.lift.{v} (sepDegree E K) =
Cardinal.lift.{v} (sepDegree F K) := by
rw [sepDegree, sepDegree, separableClosure.eq_restrictScalars_of_isSeparable F E K]
exact lift_rank_mul_lift_rank F E (separableClosure E K)
/-- The same-universe version of `Field.lift_rank_mul_lift_sepDegree_of_isSeparable`. -/
lemma rank_mul_sepDegree_of_isSeparable (K : Type v) [Field K] [Algebra F K]
[Algebra E K] [IsScalarTower F E K] [Algebra.IsSeparable F E] :
Module.rank F E * sepDegree E K = sepDegree F K := by
simpa only [Cardinal.lift_id] using lift_rank_mul_lift_sepDegree_of_isSeparable F E K
/-- If `K / E / F` is a field extension tower, such that `E / F` is purely inseparable,
then $[K:F]_s = [K:E]_s$.
It is a special case of `Field.lift_sepDegree_mul_lift_sepDegree_of_isAlgebraic`, and is an
intermediate result used to prove it. -/
lemma sepDegree_eq_of_isPurelyInseparable [IsPurelyInseparable F E] :
sepDegree F K = sepDegree E K := by
convert sepDegree_eq_of_isPurelyInseparable_of_isSeparable F E (separableClosure E K)
haveI : IsScalarTower F (separableClosure E K) K := IsScalarTower.of_algebraMap_eq (congrFun rfl)
rw [sepDegree, ← separableClosure.map_eq_of_separableClosure_eq_bot F
(separableClosure.separableClosure_eq_bot E K)]
exact (separableClosure F (separableClosure E K)).equivMap
(IsScalarTower.toAlgHom F (separableClosure E K) K) |>.symm.toLinearEquiv.rank_eq
/-- If `K / E / F` is a field extension tower, such that `E / F` is algebraic, then their
separable degrees satisfy the tower law: $[E:F]_s [K:E]_s = [K:F]_s$. -/
theorem lift_sepDegree_mul_lift_sepDegree_of_isAlgebraic [Algebra.IsAlgebraic F E] :
Cardinal.lift.{w} (sepDegree F E) * Cardinal.lift.{v} (sepDegree E K) =
Cardinal.lift.{v} (sepDegree F K) := by
have h := lift_rank_mul_lift_sepDegree_of_isSeparable F (separableClosure F E) K
haveI := separableClosure.isPurelyInseparable F E
rwa [sepDegree_eq_of_isPurelyInseparable (separableClosure F E) E K] at h
/-- The same-universe version of `Field.lift_sepDegree_mul_lift_sepDegree_of_isAlgebraic`. -/
theorem sepDegree_mul_sepDegree_of_isAlgebraic (K : Type v) [Field K] [Algebra F K]
[Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic F E] :
sepDegree F E * sepDegree E K = sepDegree F K := by
simpa only [Cardinal.lift_id] using lift_sepDegree_mul_lift_sepDegree_of_isAlgebraic F E K
end Field
variable {F K} in
/-- If `K / E / F` is a field extension tower, such that `E / F` is purely inseparable, then
for any subset `S` of `K` such that `F(S) / F` is algebraic, the `E(S) / E` and `F(S) / F` have
the same separable degree. -/
theorem IntermediateField.sepDegree_adjoin_eq_of_isAlgebraic_of_isPurelyInseparable
(S : Set K) [Algebra.IsAlgebraic F (adjoin F S)] [IsPurelyInseparable F E] :
sepDegree E (adjoin E S) = sepDegree F (adjoin F S) := by
set M := adjoin F S
set L := adjoin E S
let E' := (IsScalarTower.toAlgHom F E K).fieldRange
let j : E ≃ₐ[F] E' := AlgEquiv.ofInjectiveField (IsScalarTower.toAlgHom F E K)
have hi : M ≤ L.restrictScalars F := by
rw [restrictScalars_adjoin_of_algEquiv (E := K) j rfl, restrictScalars_adjoin]
exact adjoin.mono _ _ _ Set.subset_union_right
let i : M →+* L := Subsemiring.inclusion hi
letI : Algebra M L := i.toAlgebra
letI : SMul M L := Algebra.toSMul
haveI : IsScalarTower F M L := IsScalarTower.of_algebraMap_eq (congrFun rfl)
haveI : IsPurelyInseparable M L := by
change IsPurelyInseparable M (extendScalars hi)
obtain ⟨q, _⟩ := ExpChar.exists F
have : extendScalars hi = adjoin M (E' : Set K) := restrictScalars_injective F <| by
conv_lhs => rw [extendScalars_restrictScalars, restrictScalars_adjoin_of_algEquiv
(E := K) j rfl, ← adjoin_self F E', adjoin_adjoin_comm]
rw [this, isPurelyInseparable_adjoin_iff_pow_mem _ _ q]
rintro x ⟨y, hy⟩
obtain ⟨n, z, hz⟩ := IsPurelyInseparable.pow_mem F q y
refine ⟨n, algebraMap F M z, ?_⟩
rw [← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply F E K, hz, ← hy, map_pow,
AlgHom.toRingHom_eq_coe, IsScalarTower.coe_toAlgHom]
have h := lift_sepDegree_mul_lift_sepDegree_of_isAlgebraic F E L
rw [IsPurelyInseparable.sepDegree_eq_one F E, Cardinal.lift_one, one_mul] at h
rw [Cardinal.lift_injective h, ← sepDegree_mul_sepDegree_of_isAlgebraic F M L,
IsPurelyInseparable.sepDegree_eq_one M L, mul_one]
variable {F K} in
/-- If `K / E / F` is a field extension tower, such that `E / F` is purely inseparable, then
for any intermediate field `S` of `K / F` such that `S / F` is algebraic, the `E(S) / E` and
`S / F` have the same separable degree. -/
theorem IntermediateField.sepDegree_adjoin_eq_of_isAlgebraic_of_isPurelyInseparable'
(S : IntermediateField F K) [Algebra.IsAlgebraic F S] [IsPurelyInseparable F E] :
sepDegree E (adjoin E (S : Set K)) = sepDegree F S := by
have : Algebra.IsAlgebraic F (adjoin F (S : Set K)) := by rwa [adjoin_self]
have := sepDegree_adjoin_eq_of_isAlgebraic_of_isPurelyInseparable (F := F) E (S : Set K)
rwa [adjoin_self] at this
variable {F K} in
/-- If `K / E / F` is a field extension tower, such that `E / F` is purely inseparable, then
for any element `x` of `K` separable over `F`, it has the same minimal polynomials over `F` and
over `E`. -/
theorem minpoly.map_eq_of_isSeparable_of_isPurelyInseparable (x : K)
(hsep : IsSeparable F x) [IsPurelyInseparable F E] :
(minpoly F x).map (algebraMap F E) = minpoly E x := by
have hi := IsSeparable.isIntegral hsep
have hi' : IsIntegral E x := IsIntegral.tower_top hi
refine eq_of_monic_of_dvd_of_natDegree_le (monic hi') ((monic hi).map (algebraMap F E))
(dvd_map_of_isScalarTower F E x) (le_of_eq ?_)
have hsep' := IsSeparable.of_isScalarTower E hsep
haveI := (isSeparable_adjoin_simple_iff_isSeparable _ _).2 hsep
haveI := (isSeparable_adjoin_simple_iff_isSeparable _ _).2 hsep'
have := Algebra.IsSeparable.isAlgebraic F F⟮x⟯
have := Algebra.IsSeparable.isAlgebraic E E⟮x⟯
rw [Polynomial.natDegree_map, ← adjoin.finrank hi, ← adjoin.finrank hi',
← finSepDegree_eq_finrank_of_isSeparable F _, ← finSepDegree_eq_finrank_of_isSeparable E _,
finSepDegree_eq, finSepDegree_eq,
sepDegree_adjoin_eq_of_isAlgebraic_of_isPurelyInseparable (F := F) E]
variable {F} in
/-- If `E / F` is a purely inseparable field extension, `f` is a separable irreducible polynomial
over `F`, then it is also irreducible over `E`. -/
theorem Polynomial.Separable.map_irreducible_of_isPurelyInseparable {f : F[X]} (hsep : f.Separable)
(hirr : Irreducible f) [IsPurelyInseparable F E] : Irreducible (f.map (algebraMap F E)) := by
let K := AlgebraicClosure E
obtain ⟨x, hx⟩ := IsAlgClosed.exists_aeval_eq_zero K f
(natDegree_pos_iff_degree_pos.1 hirr.natDegree_pos).ne'
have ha : Associated f (minpoly F x) := by
have := isUnit_C.2 (leadingCoeff_ne_zero.2 hirr.ne_zero).isUnit.inv
exact ⟨this.unit, by rw [IsUnit.unit_spec, minpoly.eq_of_irreducible hirr hx]⟩
have ha' : Associated (f.map (algebraMap F E)) ((minpoly F x).map (algebraMap F E)) :=
ha.map (mapRingHom (algebraMap F E)).toMonoidHom
have heq := minpoly.map_eq_of_isSeparable_of_isPurelyInseparable E x (ha.separable hsep)
rw [ha'.irreducible_iff, heq]
exact minpoly.irreducible (Algebra.IsIntegral.isIntegral x)
end TowerLaw
|
FieldTheory\Separable.lean | /-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.Polynomial.Expand
import Mathlib.Algebra.Polynomial.Splits
import Mathlib.Algebra.Squarefree.Basic
import Mathlib.FieldTheory.Minpoly.Field
import Mathlib.RingTheory.PowerBasis
/-!
# Separable polynomials
We define a polynomial to be separable if it is coprime with its derivative. We prove basic
properties about separable polynomials here.
## Main definitions
* `Polynomial.Separable f`: a polynomial `f` is separable iff it is coprime with its derivative.
* `IsSeparable K x`: an element `x` is separable over `K` iff the minimal polynomial of `x`
over `K` is separable.
* `Algebra.IsSeparable K L`: `L` is separable over `K` iff every element in `L` is separable
over `K`
-/
universe u v w
open Polynomial Finset
namespace Polynomial
section CommSemiring
variable {R : Type u} [CommSemiring R] {S : Type v} [CommSemiring S]
/-- A polynomial is separable iff it is coprime with its derivative. -/
def Separable (f : R[X]) : Prop :=
IsCoprime f (derivative f)
theorem separable_def (f : R[X]) : f.Separable ↔ IsCoprime f (derivative f) :=
Iff.rfl
theorem separable_def' (f : R[X]) : f.Separable ↔ ∃ a b : R[X], a * f + b * (derivative f) = 1 :=
Iff.rfl
theorem not_separable_zero [Nontrivial R] : ¬Separable (0 : R[X]) := by
rintro ⟨x, y, h⟩
simp only [derivative_zero, mul_zero, add_zero, zero_ne_one] at h
theorem Separable.ne_zero [Nontrivial R] {f : R[X]} (h : f.Separable) : f ≠ 0 :=
(not_separable_zero <| · ▸ h)
@[simp]
theorem separable_one : (1 : R[X]).Separable :=
isCoprime_one_left
@[nontriviality]
theorem separable_of_subsingleton [Subsingleton R] (f : R[X]) : f.Separable := by
simp [Separable, IsCoprime, eq_iff_true_of_subsingleton]
theorem separable_X_add_C (a : R) : (X + C a).Separable := by
rw [separable_def, derivative_add, derivative_X, derivative_C, add_zero]
exact isCoprime_one_right
theorem separable_X : (X : R[X]).Separable := by
rw [separable_def, derivative_X]
exact isCoprime_one_right
theorem separable_C (r : R) : (C r).Separable ↔ IsUnit r := by
rw [separable_def, derivative_C, isCoprime_zero_right, isUnit_C]
theorem Separable.of_mul_left {f g : R[X]} (h : (f * g).Separable) : f.Separable := by
have := h.of_mul_left_left; rw [derivative_mul] at this
exact IsCoprime.of_mul_right_left (IsCoprime.of_add_mul_left_right this)
theorem Separable.of_mul_right {f g : R[X]} (h : (f * g).Separable) : g.Separable := by
rw [mul_comm] at h
exact h.of_mul_left
theorem Separable.of_dvd {f g : R[X]} (hf : f.Separable) (hfg : g ∣ f) : g.Separable := by
rcases hfg with ⟨f', rfl⟩
exact Separable.of_mul_left hf
theorem separable_gcd_left {F : Type*} [Field F] [DecidableEq F[X]]
{f : F[X]} (hf : f.Separable) (g : F[X]) :
(EuclideanDomain.gcd f g).Separable :=
Separable.of_dvd hf (EuclideanDomain.gcd_dvd_left f g)
theorem separable_gcd_right {F : Type*} [Field F] [DecidableEq F[X]]
{g : F[X]} (f : F[X]) (hg : g.Separable) :
(EuclideanDomain.gcd f g).Separable :=
Separable.of_dvd hg (EuclideanDomain.gcd_dvd_right f g)
theorem Separable.isCoprime {f g : R[X]} (h : (f * g).Separable) : IsCoprime f g := by
have := h.of_mul_left_left; rw [derivative_mul] at this
exact IsCoprime.of_mul_right_right (IsCoprime.of_add_mul_left_right this)
theorem Separable.of_pow' {f : R[X]} :
∀ {n : ℕ} (_h : (f ^ n).Separable), IsUnit f ∨ f.Separable ∧ n = 1 ∨ n = 0
| 0 => fun _h => Or.inr <| Or.inr rfl
| 1 => fun h => Or.inr <| Or.inl ⟨pow_one f ▸ h, rfl⟩
| n + 2 => fun h => by
rw [pow_succ, pow_succ] at h
exact Or.inl (isCoprime_self.1 h.isCoprime.of_mul_left_right)
theorem Separable.of_pow {f : R[X]} (hf : ¬IsUnit f) {n : ℕ} (hn : n ≠ 0)
(hfs : (f ^ n).Separable) : f.Separable ∧ n = 1 :=
(hfs.of_pow'.resolve_left hf).resolve_right hn
theorem Separable.map {p : R[X]} (h : p.Separable) {f : R →+* S} : (p.map f).Separable :=
let ⟨a, b, H⟩ := h
⟨a.map f, b.map f, by
rw [derivative_map, ← Polynomial.map_mul, ← Polynomial.map_mul, ← Polynomial.map_add, H,
Polynomial.map_one]⟩
theorem _root_.Associated.separable {f g : R[X]}
(ha : Associated f g) (h : f.Separable) : g.Separable := by
obtain ⟨⟨u, v, h1, h2⟩, ha⟩ := ha
obtain ⟨a, b, h⟩ := h
refine ⟨a * v + b * derivative v, b * v, ?_⟩
replace h := congr($h * $(h1))
have h3 := congr(derivative $(h1))
simp only [← ha, derivative_mul, derivative_one] at h3 ⊢
calc
_ = (a * f + b * derivative f) * (u * v)
+ (b * f) * (derivative u * v + u * derivative v) := by ring1
_ = 1 := by rw [h, h3]; ring1
theorem _root_.Associated.separable_iff {f g : R[X]}
(ha : Associated f g) : f.Separable ↔ g.Separable := ⟨ha.separable, ha.symm.separable⟩
theorem Separable.mul_unit {f g : R[X]} (hf : f.Separable) (hg : IsUnit g) : (f * g).Separable :=
(associated_mul_unit_right f g hg).separable hf
theorem Separable.unit_mul {f g : R[X]} (hf : IsUnit f) (hg : g.Separable) : (f * g).Separable :=
(associated_unit_mul_right g f hf).separable hg
theorem Separable.eval₂_derivative_ne_zero [Nontrivial S] (f : R →+* S) {p : R[X]}
(h : p.Separable) {x : S} (hx : p.eval₂ f x = 0) :
(derivative p).eval₂ f x ≠ 0 := by
intro hx'
obtain ⟨a, b, e⟩ := h
apply_fun Polynomial.eval₂ f x at e
simp only [eval₂_add, eval₂_mul, hx, mul_zero, hx', add_zero, eval₂_one, zero_ne_one] at e
theorem Separable.aeval_derivative_ne_zero [Nontrivial S] [Algebra R S] {p : R[X]}
(h : p.Separable) {x : S} (hx : aeval x p = 0) :
aeval x (derivative p) ≠ 0 :=
h.eval₂_derivative_ne_zero (algebraMap R S) hx
variable (p q : ℕ)
theorem isUnit_of_self_mul_dvd_separable {p q : R[X]} (hp : p.Separable) (hq : q * q ∣ p) :
IsUnit q := by
obtain ⟨p, rfl⟩ := hq
apply isCoprime_self.mp
have : IsCoprime (q * (q * p))
(q * (derivative q * p + derivative q * p + q * derivative p)) := by
simp only [← mul_assoc, mul_add]
dsimp only [Separable] at hp
convert hp using 1
rw [derivative_mul, derivative_mul]
ring
exact IsCoprime.of_mul_right_left (IsCoprime.of_mul_left_left this)
theorem multiplicity_le_one_of_separable [DecidableRel fun (x : R[X]) x_1 ↦ x ∣ x_1]
{p q : R[X]} (hq : ¬IsUnit q) (hsep : Separable p) :
multiplicity q p ≤ 1 := by
contrapose! hq
apply isUnit_of_self_mul_dvd_separable hsep
rw [← sq]
apply multiplicity.pow_dvd_of_le_multiplicity
have h : ⟨Part.Dom 1 ∧ Part.Dom 1, fun _ ↦ 2⟩ ≤ multiplicity q p := PartENat.add_one_le_of_lt hq
rw [and_self] at h
exact h
/-- A separable polynomial is square-free.
See `PerfectField.separable_iff_squarefree` for the converse when the coefficients are a perfect
field. -/
theorem Separable.squarefree {p : R[X]} (hsep : Separable p) : Squarefree p := by
classical
rw [multiplicity.squarefree_iff_multiplicity_le_one p]
exact fun f => or_iff_not_imp_right.mpr fun hunit => multiplicity_le_one_of_separable hunit hsep
end CommSemiring
section CommRing
variable {R : Type u} [CommRing R]
theorem separable_X_sub_C {x : R} : Separable (X - C x) := by
simpa only [sub_eq_add_neg, C_neg] using separable_X_add_C (-x)
theorem Separable.mul {f g : R[X]} (hf : f.Separable) (hg : g.Separable) (h : IsCoprime f g) :
(f * g).Separable := by
rw [separable_def, derivative_mul]
exact
((hf.mul_right h).add_mul_left_right _).mul_left ((h.symm.mul_right hg).mul_add_right_right _)
theorem separable_prod' {ι : Sort _} {f : ι → R[X]} {s : Finset ι} :
(∀ x ∈ s, ∀ y ∈ s, x ≠ y → IsCoprime (f x) (f y)) →
(∀ x ∈ s, (f x).Separable) → (∏ x ∈ s, f x).Separable := by
classical
exact Finset.induction_on s (fun _ _ => separable_one) fun a s has ih h1 h2 => by
simp_rw [Finset.forall_mem_insert, forall_and] at h1 h2; rw [prod_insert has]
exact
h2.1.mul (ih h1.2.2 h2.2)
(IsCoprime.prod_right fun i his => h1.1.2 i his <| Ne.symm <| ne_of_mem_of_not_mem his has)
theorem separable_prod {ι : Sort _} [Fintype ι] {f : ι → R[X]} (h1 : Pairwise (IsCoprime on f))
(h2 : ∀ x, (f x).Separable) : (∏ x, f x).Separable :=
separable_prod' (fun _x _hx _y _hy hxy => h1 hxy) fun x _hx => h2 x
theorem Separable.inj_of_prod_X_sub_C [Nontrivial R] {ι : Sort _} {f : ι → R} {s : Finset ι}
(hfs : (∏ i ∈ s, (X - C (f i))).Separable) {x y : ι} (hx : x ∈ s) (hy : y ∈ s)
(hfxy : f x = f y) : x = y := by
classical
by_contra hxy
rw [← insert_erase hx, prod_insert (not_mem_erase _ _), ←
insert_erase (mem_erase_of_ne_of_mem (Ne.symm hxy) hy), prod_insert (not_mem_erase _ _), ←
mul_assoc, hfxy, ← sq] at hfs
cases (hfs.of_mul_left.of_pow (not_isUnit_X_sub_C _) two_ne_zero).2
theorem Separable.injective_of_prod_X_sub_C [Nontrivial R] {ι : Sort _} [Fintype ι] {f : ι → R}
(hfs : (∏ i, (X - C (f i))).Separable) : Function.Injective f := fun _x _y hfxy =>
hfs.inj_of_prod_X_sub_C (mem_univ _) (mem_univ _) hfxy
theorem nodup_of_separable_prod [Nontrivial R] {s : Multiset R}
(hs : Separable (Multiset.map (fun a => X - C a) s).prod) : s.Nodup := by
rw [Multiset.nodup_iff_ne_cons_cons]
rintro a t rfl
refine not_isUnit_X_sub_C a (isUnit_of_self_mul_dvd_separable hs ?_)
simpa only [Multiset.map_cons, Multiset.prod_cons] using mul_dvd_mul_left _ (dvd_mul_right _ _)
/-- If `IsUnit n` in a `CommRing R`, then `X ^ n - u` is separable for any unit `u`. -/
theorem separable_X_pow_sub_C_unit {n : ℕ} (u : Rˣ) (hn : IsUnit (n : R)) :
Separable (X ^ n - C (u : R)) := by
nontriviality R
rcases n.eq_zero_or_pos with (rfl | hpos)
· simp at hn
apply (separable_def' (X ^ n - C (u : R))).2
obtain ⟨n', hn'⟩ := hn.exists_left_inv
refine ⟨-C ↑u⁻¹, C (↑u⁻¹ : R) * C n' * X, ?_⟩
rw [derivative_sub, derivative_C, sub_zero, derivative_pow X n, derivative_X, mul_one]
calc
-C ↑u⁻¹ * (X ^ n - C ↑u) + C ↑u⁻¹ * C n' * X * (↑n * X ^ (n - 1)) =
C (↑u⁻¹ * ↑u) - C ↑u⁻¹ * X ^ n + C ↑u⁻¹ * C (n' * ↑n) * (X * X ^ (n - 1)) := by
simp only [C.map_mul, C_eq_natCast]
ring
_ = 1 := by
simp only [Units.inv_mul, hn', C.map_one, mul_one, ← pow_succ',
Nat.sub_add_cancel (show 1 ≤ n from hpos), sub_add_cancel]
theorem rootMultiplicity_le_one_of_separable [Nontrivial R] {p : R[X]} (hsep : Separable p)
(x : R) : rootMultiplicity x p ≤ 1 := by
classical
by_cases hp : p = 0
· simp [hp]
rw [rootMultiplicity_eq_multiplicity, dif_neg hp, ← PartENat.coe_le_coe, PartENat.natCast_get,
Nat.cast_one]
exact multiplicity_le_one_of_separable (not_isUnit_X_sub_C _) hsep
end CommRing
section IsDomain
variable {R : Type u} [CommRing R] [IsDomain R]
theorem count_roots_le_one [DecidableEq R] {p : R[X]} (hsep : Separable p) (x : R) :
p.roots.count x ≤ 1 := by
rw [count_roots p]
exact rootMultiplicity_le_one_of_separable hsep x
theorem nodup_roots {p : R[X]} (hsep : Separable p) : p.roots.Nodup := by
classical
exact Multiset.nodup_iff_count_le_one.mpr (count_roots_le_one hsep)
end IsDomain
section Field
variable {F : Type u} [Field F] {K : Type v} [Field K]
theorem separable_iff_derivative_ne_zero {f : F[X]} (hf : Irreducible f) :
f.Separable ↔ derivative f ≠ 0 :=
⟨fun h1 h2 => hf.not_unit <| isCoprime_zero_right.1 <| h2 ▸ h1, fun h =>
EuclideanDomain.isCoprime_of_dvd (mt And.right h) fun g hg1 _hg2 ⟨p, hg3⟩ hg4 =>
let ⟨u, hu⟩ := (hf.isUnit_or_isUnit hg3).resolve_left hg1
have : f ∣ derivative f := by
conv_lhs => rw [hg3, ← hu]
rwa [Units.mul_right_dvd]
not_lt_of_le (natDegree_le_of_dvd this h) <|
natDegree_derivative_lt <| mt derivative_of_natDegree_zero h⟩
attribute [local instance] Ideal.Quotient.field in
theorem separable_map {S} [CommRing S] [Nontrivial S] (f : F →+* S) {p : F[X]} :
(p.map f).Separable ↔ p.Separable := by
refine ⟨fun H ↦ ?_, fun H ↦ H.map⟩
obtain ⟨m, hm⟩ := Ideal.exists_maximal S
have := Separable.map H (f := Ideal.Quotient.mk m)
rwa [map_map, separable_def, derivative_map, isCoprime_map] at this
theorem separable_prod_X_sub_C_iff' {ι : Sort _} {f : ι → F} {s : Finset ι} :
(∏ i ∈ s, (X - C (f i))).Separable ↔ ∀ x ∈ s, ∀ y ∈ s, f x = f y → x = y :=
⟨fun hfs x hx y hy hfxy => hfs.inj_of_prod_X_sub_C hx hy hfxy, fun H => by
rw [← prod_attach]
exact
separable_prod'
(fun x _hx y _hy hxy =>
@pairwise_coprime_X_sub_C _ _ { x // x ∈ s } (fun x => f x)
(fun x y hxy => Subtype.eq <| H x.1 x.2 y.1 y.2 hxy) _ _ hxy)
fun _ _ => separable_X_sub_C⟩
theorem separable_prod_X_sub_C_iff {ι : Sort _} [Fintype ι] {f : ι → F} :
(∏ i, (X - C (f i))).Separable ↔ Function.Injective f :=
separable_prod_X_sub_C_iff'.trans <| by simp_rw [mem_univ, true_imp_iff, Function.Injective]
section CharP
variable (p : ℕ) [HF : CharP F p]
theorem separable_or {f : F[X]} (hf : Irreducible f) :
f.Separable ∨ ¬f.Separable ∧ ∃ g : F[X], Irreducible g ∧ expand F p g = f := by
classical
exact if H : derivative f = 0 then by
rcases p.eq_zero_or_pos with (rfl | hp)
· haveI := CharP.charP_to_charZero F
have := natDegree_eq_zero_of_derivative_eq_zero H
have := (natDegree_pos_iff_degree_pos.mpr <| degree_pos_of_irreducible hf).ne'
contradiction
haveI := isLocalRingHom_expand F hp
exact
Or.inr
⟨by rw [separable_iff_derivative_ne_zero hf, Classical.not_not, H], contract p f,
of_irreducible_map (expand F p : F[X] →+* F[X])
(by rwa [← expand_contract p H hp.ne'] at hf),
expand_contract p H hp.ne'⟩
else Or.inl <| (separable_iff_derivative_ne_zero hf).2 H
theorem exists_separable_of_irreducible {f : F[X]} (hf : Irreducible f) (hp : p ≠ 0) :
∃ (n : ℕ) (g : F[X]), g.Separable ∧ expand F (p ^ n) g = f := by
replace hp : p.Prime := (CharP.char_is_prime_or_zero F p).resolve_right hp
induction' hn : f.natDegree using Nat.strong_induction_on with N ih generalizing f
rcases separable_or p hf with (h | ⟨h1, g, hg, hgf⟩)
· refine ⟨0, f, h, ?_⟩
rw [pow_zero, expand_one]
· cases' N with N
· rw [natDegree_eq_zero_iff_degree_le_zero, degree_le_zero_iff] at hn
rw [hn, separable_C, isUnit_iff_ne_zero, Classical.not_not] at h1
have hf0 : f ≠ 0 := hf.ne_zero
rw [h1, C_0] at hn
exact absurd hn hf0
have hg1 : g.natDegree * p = N.succ := by rwa [← natDegree_expand, hgf]
have hg2 : g.natDegree ≠ 0 := by
intro this
rw [this, zero_mul] at hg1
cases hg1
have hg3 : g.natDegree < N.succ := by
rw [← mul_one g.natDegree, ← hg1]
exact Nat.mul_lt_mul_of_pos_left hp.one_lt hg2.bot_lt
rcases ih _ hg3 hg rfl with ⟨n, g, hg4, rfl⟩
refine ⟨n + 1, g, hg4, ?_⟩
rw [← hgf, expand_expand, pow_succ']
theorem isUnit_or_eq_zero_of_separable_expand {f : F[X]} (n : ℕ) (hp : 0 < p)
(hf : (expand F (p ^ n) f).Separable) : IsUnit f ∨ n = 0 := by
rw [or_iff_not_imp_right]
rintro hn : n ≠ 0
have hf2 : derivative (expand F (p ^ n) f) = 0 := by
rw [derivative_expand, Nat.cast_pow, CharP.cast_eq_zero, zero_pow hn, zero_mul, mul_zero]
rw [separable_def, hf2, isCoprime_zero_right, isUnit_iff] at hf
rcases hf with ⟨r, hr, hrf⟩
rw [eq_comm, expand_eq_C (pow_pos hp _)] at hrf
rwa [hrf, isUnit_C]
theorem unique_separable_of_irreducible {f : F[X]} (hf : Irreducible f) (hp : 0 < p) (n₁ : ℕ)
(g₁ : F[X]) (hg₁ : g₁.Separable) (hgf₁ : expand F (p ^ n₁) g₁ = f) (n₂ : ℕ) (g₂ : F[X])
(hg₂ : g₂.Separable) (hgf₂ : expand F (p ^ n₂) g₂ = f) : n₁ = n₂ ∧ g₁ = g₂ := by
revert g₁ g₂
-- Porting note: the variable `K` affects the `wlog` tactic.
clear! K
wlog hn : n₁ ≤ n₂
· intro g₁ hg₁ Hg₁ g₂ hg₂ Hg₂
simpa only [eq_comm] using this p hf hp n₂ n₁ (le_of_not_le hn) g₂ hg₂ Hg₂ g₁ hg₁ Hg₁
have hf0 : f ≠ 0 := hf.ne_zero
intros g₁ hg₁ hgf₁ g₂ hg₂ hgf₂
rw [le_iff_exists_add] at hn
rcases hn with ⟨k, rfl⟩
rw [← hgf₁, pow_add, expand_mul, expand_inj (pow_pos hp n₁)] at hgf₂
subst hgf₂
subst hgf₁
rcases isUnit_or_eq_zero_of_separable_expand p k hp hg₁ with (h | rfl)
· rw [isUnit_iff] at h
rcases h with ⟨r, hr, rfl⟩
simp_rw [expand_C] at hf
exact absurd (isUnit_C.2 hr) hf.1
· rw [add_zero, pow_zero, expand_one]
constructor <;> rfl
end CharP
/-- If `n ≠ 0` in `F`, then `X ^ n - a` is separable for any `a ≠ 0`. -/
theorem separable_X_pow_sub_C {n : ℕ} (a : F) (hn : (n : F) ≠ 0) (ha : a ≠ 0) :
Separable (X ^ n - C a) :=
separable_X_pow_sub_C_unit (Units.mk0 a ha) (IsUnit.mk0 (n : F) hn)
-- this can possibly be strengthened to making `separable_X_pow_sub_C_unit` a
-- bi-implication, but it is nontrivial!
/-- In a field `F`, `X ^ n - 1` is separable iff `↑n ≠ 0`. -/
theorem X_pow_sub_one_separable_iff {n : ℕ} : (X ^ n - 1 : F[X]).Separable ↔ (n : F) ≠ 0 := by
refine ⟨?_, fun h => separable_X_pow_sub_C_unit 1 (IsUnit.mk0 (↑n) h)⟩
rw [separable_def', derivative_sub, derivative_X_pow, derivative_one, sub_zero]
-- Suppose `(n : F) = 0`, then the derivative is `0`, so `X ^ n - 1` is a unit, contradiction.
rintro (h : IsCoprime _ _) hn'
rw [hn', C_0, zero_mul, isCoprime_zero_right] at h
exact not_isUnit_X_pow_sub_one F n h
section Splits
theorem card_rootSet_eq_natDegree [Algebra F K] {p : F[X]} (hsep : p.Separable)
(hsplit : Splits (algebraMap F K) p) : Fintype.card (p.rootSet K) = p.natDegree := by
classical
simp_rw [rootSet_def, Finset.coe_sort_coe, Fintype.card_coe]
rw [Multiset.toFinset_card_of_nodup (nodup_roots hsep.map), ← natDegree_eq_card_roots hsplit]
/-- If a non-zero polynomial splits, then it has no repeated roots on that field
if and only if it is separable. -/
theorem nodup_roots_iff_of_splits {f : F[X]} (hf : f ≠ 0) (h : f.Splits (RingHom.id F)) :
f.roots.Nodup ↔ f.Separable := by
classical
refine ⟨(fun hnsep ↦ ?_).mtr, nodup_roots⟩
rw [Separable, ← gcd_isUnit_iff, isUnit_iff_degree_eq_zero] at hnsep
obtain ⟨x, hx⟩ := exists_root_of_splits _
(splits_of_splits_of_dvd _ hf h (gcd_dvd_left f _)) hnsep
simp_rw [Multiset.nodup_iff_count_le_one, not_forall, not_le]
exact ⟨x, ((one_lt_rootMultiplicity_iff_isRoot_gcd hf).2 hx).trans_eq f.count_roots.symm⟩
/-- If a non-zero polynomial over `F` splits in `K`, then it has no repeated roots on `K`
if and only if it is separable. -/
theorem nodup_aroots_iff_of_splits [Algebra F K] {f : F[X]} (hf : f ≠ 0)
(h : f.Splits (algebraMap F K)) : (f.aroots K).Nodup ↔ f.Separable := by
rw [← (algebraMap F K).id_comp, ← splits_map_iff] at h
rw [nodup_roots_iff_of_splits (map_ne_zero hf) h, separable_map]
theorem card_rootSet_eq_natDegree_iff_of_splits [Algebra F K] {f : F[X]} (hf : f ≠ 0)
(h : f.Splits (algebraMap F K)) : Fintype.card (f.rootSet K) = f.natDegree ↔ f.Separable := by
classical
simp_rw [rootSet_def, Finset.coe_sort_coe, Fintype.card_coe, natDegree_eq_card_roots h,
Multiset.toFinset_card_eq_card_iff_nodup, nodup_aroots_iff_of_splits hf h]
variable {i : F →+* K}
theorem eq_X_sub_C_of_separable_of_root_eq {x : F} {h : F[X]} (h_sep : h.Separable)
(h_root : h.eval x = 0) (h_splits : Splits i h) (h_roots : ∀ y ∈ (h.map i).roots, y = i x) :
h = C (leadingCoeff h) * (X - C x) := by
have h_ne_zero : h ≠ 0 := by
rintro rfl
exact not_separable_zero h_sep
apply Polynomial.eq_X_sub_C_of_splits_of_single_root i h_splits
apply Finset.mk.inj
· change _ = {i x}
rw [Finset.eq_singleton_iff_unique_mem]
constructor
· apply Finset.mem_mk.mpr
· rw [mem_roots (show h.map i ≠ 0 from map_ne_zero h_ne_zero)]
rw [IsRoot.def, ← eval₂_eq_eval_map, eval₂_hom, h_root]
exact RingHom.map_zero i
· exact nodup_roots (Separable.map h_sep)
· exact h_roots
theorem exists_finset_of_splits (i : F →+* K) {f : F[X]} (sep : Separable f) (sp : Splits i f) :
∃ s : Finset K, f.map i = C (i f.leadingCoeff) * s.prod fun a : K => X - C a := by
classical
obtain ⟨s, h⟩ := (splits_iff_exists_multiset _).1 sp
use s.toFinset
rw [h, Finset.prod_eq_multiset_prod, ← Multiset.toFinset_eq]
apply nodup_of_separable_prod
apply Separable.of_mul_right
rw [← h]
exact sep.map
end Splits
theorem _root_.Irreducible.separable [CharZero F] {f : F[X]} (hf : Irreducible f) :
f.Separable := by
rw [separable_iff_derivative_ne_zero hf, Ne, ← degree_eq_bot, degree_derivative_eq]
· rintro ⟨⟩
rw [pos_iff_ne_zero, Ne, natDegree_eq_zero_iff_degree_le_zero, degree_le_zero_iff]
refine fun hf1 => hf.not_unit ?_
rw [hf1, isUnit_C, isUnit_iff_ne_zero]
intro hf2
rw [hf2, C_0] at hf1
exact absurd hf1 hf.ne_zero
end Field
end Polynomial
open Polynomial
section CommRing
variable (F K : Type*) [CommRing F] [Ring K] [Algebra F K]
-- TODO: refactor to allow transcendental extensions?
-- See: https://en.wikipedia.org/wiki/Separable_extension#Separability_of_transcendental_extensions
-- Note that right now a Galois extension (class `IsGalois`) is defined to be an extension which
-- is separable and normal, so if the definition of separable changes here at some point
-- to allow non-algebraic extensions, then the definition of `IsGalois` must also be changed.
variable {K} in
/--
An element `x` of an algebra `K` over a commutative ring `F` is said to be *separable*, if its
minimal polynamial over `K` is separable. Note that the minimal polynomial of any element not
integral over `F` is defined to be `0`, which is not a separable polynomial.
-/
def IsSeparable (x : K) : Prop := Polynomial.Separable (minpoly F x)
/-- Typeclass for separable field extension: `K` is a separable field extension of `F` iff
the minimal polynomial of every `x : K` is separable. This implies that `K/F` is an algebraic
extension, because the minimal polynomial of a non-integral element is `0`, which is not
separable.
We define this for general (commutative) rings and only assume `F` and `K` are fields if this
is needed for a proof.
-/
@[mk_iff isSeparable_def] protected class Algebra.IsSeparable : Prop where
isSeparable' : ∀ x : K, IsSeparable F x
variable {K}
theorem Algebra.IsSeparable.isSeparable [Algebra.IsSeparable F K] : ∀ x : K, IsSeparable F x :=
Algebra.IsSeparable.isSeparable'
variable {F} in
/-- If the minimal polynomial of `x : K` over `F` is separable, then `x` is integral over `F`,
because the minimal polynomial of a non-integral element is `0`, which is not separable. -/
theorem IsSeparable.isIntegral {x : K} (h : IsSeparable F x) : IsIntegral F x := by
cases subsingleton_or_nontrivial F
· haveI := Module.subsingleton F K
exact ⟨1, monic_one, Subsingleton.elim _ _⟩
· exact of_not_not (h.ne_zero <| minpoly.eq_zero ·)
theorem Algebra.IsSeparable.isIntegral [Algebra.IsSeparable F K] : ∀ x : K, IsIntegral F x :=
fun x ↦ _root_.IsSeparable.isIntegral (Algebra.IsSeparable.isSeparable F x)
variable {F}
theorem Algebra.isSeparable_iff :
Algebra.IsSeparable F K ↔ ∀ x : K, IsIntegral F x ∧ IsSeparable F x :=
⟨fun _ x => ⟨Algebra.IsSeparable.isIntegral F x, Algebra.IsSeparable.isSeparable F x⟩,
fun h => ⟨fun x => (h x).2⟩⟩
variable {E : Type*} [Ring E] [Algebra F E] (e : K ≃ₐ[F] E)
/-- Transfer `Algebra.IsSeparable` across an `AlgEquiv`. -/
theorem AlgEquiv.isSeparable [Algebra.IsSeparable F K] : Algebra.IsSeparable F E :=
⟨fun _ ↦
by rw [IsSeparable, ← minpoly.algEquiv_eq e.symm]; exact Algebra.IsSeparable.isSeparable F _⟩
theorem AlgEquiv.isSeparable_iff : Algebra.IsSeparable F K ↔ Algebra.IsSeparable F E :=
⟨fun _ ↦ e.isSeparable, fun _ ↦ e.symm.isSeparable⟩
variable (F K)
instance Algebra.IsSeparable.isAlgebraic [Nontrivial F] [Algebra.IsSeparable F K] :
Algebra.IsAlgebraic F K :=
⟨fun x ↦ (Algebra.IsSeparable.isIntegral F x).isAlgebraic⟩
end CommRing
instance Algebra.isSeparable_self (F : Type*) [Field F] : Algebra.IsSeparable F F :=
⟨fun x => by
rw [IsSeparable, minpoly.eq_X_sub_C']
exact separable_X_sub_C⟩
-- See note [lower instance priority]
/-- A finite field extension in characteristic 0 is separable. -/
instance (priority := 100) Algebra.IsSeparable.of_finite (F K : Type*) [Field F] [Field K]
[Algebra F K] [FiniteDimensional F K] [CharZero F] : Algebra.IsSeparable F K :=
⟨fun x => (minpoly.irreducible <| .of_finite F x).separable⟩
section IsSeparableTower
/-- If `R / K / A` is an extension tower, `x : R` is separable over `A`, then it's also separable
over `K`. -/
theorem IsSeparable.of_isScalarTower {A : Type*} [CommRing A]
(K : Type*) [Field K] [Algebra A K] {R : Type*} [CommRing R] [Algebra A R] [Algebra K R]
[IsScalarTower A K R] {x : R} (h : IsSeparable A x) : IsSeparable K x :=
h.map.of_dvd (minpoly.dvd_map_of_isScalarTower _ _ _)
variable (F K E : Type*) [Field F] [Field K] [Field E] [Algebra F K] [Algebra F E] [Algebra K E]
[IsScalarTower F K E]
theorem Algebra.isSeparable_tower_top_of_isSeparable [Algebra.IsSeparable F E] :
Algebra.IsSeparable K E :=
⟨fun x ↦ IsSeparable.of_isScalarTower _ (Algebra.IsSeparable.isSeparable F x)⟩
theorem Algebra.isSeparable_tower_bot_of_isSeparable [h : Algebra.IsSeparable F E] :
Algebra.IsSeparable F K :=
⟨fun x ↦
have ⟨_q, hq⟩ :=
minpoly.dvd F x
((aeval_algebraMap_eq_zero_iff _ _ _).mp (minpoly.aeval F ((algebraMap K E) x)))
(Eq.mp (congrArg Separable hq) (h.isSeparable _)).of_mul_left⟩
variable {E}
theorem Algebra.IsSeparable.of_algHom (E' : Type*) [Field E'] [Algebra F E'] (f : E →ₐ[F] E')
[Algebra.IsSeparable F E'] : Algebra.IsSeparable F E := by
letI : Algebra E E' := RingHom.toAlgebra f.toRingHom
haveI : IsScalarTower F E E' := IsScalarTower.of_algebraMap_eq fun x => (f.commutes x).symm
exact Algebra.isSeparable_tower_bot_of_isSeparable F E E'
lemma Algebra.IsSeparable.of_equiv_equiv {A₁ B₁ A₂ B₂ : Type*} [Field A₁] [Field B₁]
[Field A₂] [Field B₂] [Algebra A₁ B₁] [Algebra A₂ B₂] (e₁ : A₁ ≃+* A₂) (e₂ : B₁ ≃+* B₂)
(he : RingHom.comp (algebraMap A₂ B₂) ↑e₁ = RingHom.comp ↑e₂ (algebraMap A₁ B₁))
[Algebra.IsSeparable A₁ B₁] : Algebra.IsSeparable A₂ B₂ := by
letI := e₁.toRingHom.toAlgebra
letI := ((algebraMap A₁ B₁).comp e₁.symm.toRingHom).toAlgebra
haveI : IsScalarTower A₁ A₂ B₁ := IsScalarTower.of_algebraMap_eq
(fun x ↦ by simp [RingHom.algebraMap_toAlgebra])
let e : B₁ ≃ₐ[A₂] B₂ :=
{ e₂ with
commutes' := fun r ↦ by
simpa [RingHom.algebraMap_toAlgebra] using DFunLike.congr_fun he.symm (e₁.symm r) }
haveI := Algebra.isSeparable_tower_top_of_isSeparable A₁ A₂ B₁
exact Algebra.IsSeparable.of_algHom _ _ e.symm.toAlgHom
end IsSeparableTower
section CardAlgHom
variable {R S T : Type*} [CommRing S]
variable {K L F : Type*} [Field K] [Field L] [Field F]
variable [Algebra K S] [Algebra K L]
theorem AlgHom.card_of_powerBasis (pb : PowerBasis K S) (h_sep : IsSeparable K pb.gen)
(h_splits : (minpoly K pb.gen).Splits (algebraMap K L)) :
@Fintype.card (S →ₐ[K] L) (PowerBasis.AlgHom.fintype pb) = pb.dim := by
classical
let _ := (PowerBasis.AlgHom.fintype pb : Fintype (S →ₐ[K] L))
rw [Fintype.card_congr pb.liftEquiv', Fintype.card_of_subtype _ (fun x => Multiset.mem_toFinset),
← pb.natDegree_minpoly, natDegree_eq_card_roots h_splits, Multiset.toFinset_card_of_nodup]
exact nodup_roots ((separable_map (algebraMap K L)).mpr h_sep)
end CardAlgHom
|
FieldTheory\SeparableClosure.lean | /-
Copyright (c) 2023 Jz Pan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jz Pan
-/
import Mathlib.FieldTheory.SeparableDegree
import Mathlib.FieldTheory.IsSepClosed
/-!
# Separable closure
This file contains basics about the (relative) separable closure of a field extension.
## Main definitions
- `separableClosure`: the relative separable closure of `F` in `E`, or called maximal separable
subextension of `E / F`, is defined to be the intermediate field of `E / F` consisting of all
separable elements.
- `SeparableClosure`: the absolute separable closure, defined to be the relative separable
closure inside the algebraic closure.
- `Field.sepDegree F E`: the (infinite) separable degree $[E:F]_s$ of an algebraic extension
`E / F` of fields, defined to be the degree of `separableClosure F E / F`. Later we will show
that (`Field.finSepDegree_eq`, not in this file), if `Field.Emb F E` is finite, then this
coincides with `Field.finSepDegree F E`.
- `Field.insepDegree F E`: the (infinite) inseparable degree $[E:F]_i$ of an algebraic extension
`E / F` of fields, defined to be the degree of `E / separableClosure F E`.
- `Field.finInsepDegree F E`: the finite inseparable degree $[E:F]_i$ of an algebraic extension
`E / F` of fields, defined to be the degree of `E / separableClosure F E` as a natural number.
It is zero if such field extension is not finite.
## Main results
- `le_separableClosure_iff`: an intermediate field of `E / F` is contained in the
separable closure of `F` in `E` if and only if it is separable over `F`.
- `separableClosure.normalClosure_eq_self`: the normal closure of the separable
closure of `F` in `E` is equal to itself.
- `separableClosure.isGalois`: the separable closure in a normal extension is Galois
(namely, normal and separable).
- `separableClosure.isSepClosure`: the separable closure in a separably closed extension
is a separable closure of the base field.
- `IntermediateField.isSeparable_adjoin_iff_isSeparable`: `F(S) / F` is a separable extension if and
only if all elements of `S` are separable elements.
- `separableClosure.eq_top_iff`: the separable closure of `F` in `E` is equal to `E`
if and only if `E / F` is separable.
## Tags
separable degree, degree, separable closure
-/
open FiniteDimensional Polynomial IntermediateField Field
noncomputable section
universe u v w
variable (F : Type u) (E : Type v) [Field F] [Field E] [Algebra F E]
variable (K : Type w) [Field K] [Algebra F K]
section separableClosure
/-- The (relative) separable closure of `F` in `E`, or called maximal separable subextension
of `E / F`, is defined to be the intermediate field of `E / F` consisting of all separable
elements. The previous results prove that these elements are closed under field operations. -/
def separableClosure : IntermediateField F E where
carrier := {x | IsSeparable F x}
mul_mem' := isSeparable_mul
add_mem' := isSeparable_add
algebraMap_mem' := isSeparable_algebraMap E
inv_mem' _ := isSeparable_inv
variable {F E K}
/-- An element is contained in the separable closure of `F` in `E` if and only if
it is a separable element. -/
theorem mem_separableClosure_iff {x : E} :
x ∈ separableClosure F E ↔ IsSeparable F x := Iff.rfl
/-- If `i` is an `F`-algebra homomorphism from `E` to `K`, then `i x` is contained in
`separableClosure F K` if and only if `x` is contained in `separableClosure F E`. -/
theorem map_mem_separableClosure_iff (i : E →ₐ[F] K) {x : E} :
i x ∈ separableClosure F K ↔ x ∈ separableClosure F E := by
simp_rw [mem_separableClosure_iff, IsSeparable, minpoly.algHom_eq i i.injective]
/-- If `i` is an `F`-algebra homomorphism from `E` to `K`, then the preimage of
`separableClosure F K` under the map `i` is equal to `separableClosure F E`. -/
theorem separableClosure.comap_eq_of_algHom (i : E →ₐ[F] K) :
(separableClosure F K).comap i = separableClosure F E := by
ext x
exact map_mem_separableClosure_iff i
/-- If `i` is an `F`-algebra homomorphism from `E` to `K`, then the image of `separableClosure F E`
under the map `i` is contained in `separableClosure F K`. -/
theorem separableClosure.map_le_of_algHom (i : E →ₐ[F] K) :
(separableClosure F E).map i ≤ separableClosure F K :=
map_le_iff_le_comap.2 (comap_eq_of_algHom i).ge
variable (F) in
/-- If `K / E / F` is a field extension tower, such that `K / E` has no non-trivial separable
subextensions (when `K / E` is algebraic, this means that it is purely inseparable),
then the image of `separableClosure F E` in `K` is equal to `separableClosure F K`. -/
theorem separableClosure.map_eq_of_separableClosure_eq_bot [Algebra E K] [IsScalarTower F E K]
(h : separableClosure E K = ⊥) :
(separableClosure F E).map (IsScalarTower.toAlgHom F E K) = separableClosure F K := by
refine le_antisymm (map_le_of_algHom _) (fun x hx ↦ ?_)
obtain ⟨y, rfl⟩ := mem_bot.1 <| h ▸ mem_separableClosure_iff.2
(IsSeparable.of_isScalarTower E <| mem_separableClosure_iff.1 hx)
exact ⟨y, (map_mem_separableClosure_iff <| IsScalarTower.toAlgHom F E K).mp hx, rfl⟩
/-- If `i` is an `F`-algebra isomorphism of `E` and `K`, then the image of `separableClosure F E`
under the map `i` is equal to `separableClosure F K`. -/
theorem separableClosure.map_eq_of_algEquiv (i : E ≃ₐ[F] K) :
(separableClosure F E).map i = separableClosure F K :=
(map_le_of_algHom i.toAlgHom).antisymm
(fun x h ↦ ⟨_, (map_mem_separableClosure_iff i.symm).2 h, by simp⟩)
/-- If `E` and `K` are isomorphic as `F`-algebras, then `separableClosure F E` and
`separableClosure F K` are also isomorphic as `F`-algebras. -/
def separableClosure.algEquivOfAlgEquiv (i : E ≃ₐ[F] K) :
separableClosure F E ≃ₐ[F] separableClosure F K :=
(intermediateFieldMap i _).trans (equivOfEq (map_eq_of_algEquiv i))
alias AlgEquiv.separableClosure := separableClosure.algEquivOfAlgEquiv
variable (F E K)
/-- The separable closure of `F` in `E` is algebraic over `F`. -/
instance separableClosure.isAlgebraic : Algebra.IsAlgebraic F (separableClosure F E) :=
⟨fun x ↦ isAlgebraic_iff.2 (IsSeparable.isIntegral x.2).isAlgebraic⟩
/-- The separable closure of `F` in `E` is separable over `F`. -/
instance separableClosure.isSeparable : Algebra.IsSeparable F (separableClosure F E) :=
⟨fun x ↦ by simpa only [IsSeparable, minpoly_eq] using x.2⟩
/-- An intermediate field of `E / F` is contained in the separable closure of `F` in `E`
if all of its elements are separable over `F`. -/
theorem le_separableClosure' {L : IntermediateField F E} (hs : ∀ x : L, IsSeparable F x) :
L ≤ separableClosure F E := fun x h ↦ by simpa only [IsSeparable, minpoly_eq] using hs ⟨x, h⟩
/-- An intermediate field of `E / F` is contained in the separable closure of `F` in `E`
if it is separable over `F`. -/
theorem le_separableClosure (L : IntermediateField F E) [Algebra.IsSeparable F L] :
L ≤ separableClosure F E := le_separableClosure' F E (Algebra.IsSeparable.isSeparable F)
/-- An intermediate field of `E / F` is contained in the separable closure of `F` in `E`
if and only if it is separable over `F`. -/
theorem le_separableClosure_iff (L : IntermediateField F E) :
L ≤ separableClosure F E ↔ Algebra.IsSeparable F L :=
⟨fun h ↦ ⟨fun x ↦ by simpa only [IsSeparable, minpoly_eq] using h x.2⟩,
fun _ ↦ le_separableClosure _ _ _⟩
/-- The separable closure in `E` of the separable closure of `F` in `E` is equal to itself. -/
theorem separableClosure.separableClosure_eq_bot :
separableClosure (separableClosure F E) E = ⊥ :=
bot_unique fun x hx ↦ mem_bot.2
⟨⟨x, IsSeparable.of_algebra_isSeparable_of_isSeparable F (mem_separableClosure_iff.1 hx)⟩, rfl⟩
/-- The normal closure in `E/F` of the separable closure of `F` in `E` is equal to itself. -/
theorem separableClosure.normalClosure_eq_self :
normalClosure F (separableClosure F E) E = separableClosure F E :=
le_antisymm (normalClosure_le_iff.2 fun i ↦
haveI : Algebra.IsSeparable F i.fieldRange := (AlgEquiv.ofInjectiveField i).isSeparable
le_separableClosure F E _) (le_normalClosure _)
/-- If `E` is normal over `F`, then the separable closure of `F` in `E` is Galois (i.e.
normal and separable) over `F`. -/
instance separableClosure.isGalois [Normal F E] : IsGalois F (separableClosure F E) where
to_isSeparable := separableClosure.isSeparable F E
to_normal := by
rw [← separableClosure.normalClosure_eq_self]
exact normalClosure.normal F _ E
/-- If `E / F` is a field extension and `E` is separably closed, then the separable closure
of `F` in `E` is equal to `F` if and only if `F` is separably closed. -/
theorem IsSepClosed.separableClosure_eq_bot_iff [IsSepClosed E] :
separableClosure F E = ⊥ ↔ IsSepClosed F := by
refine ⟨fun h ↦ IsSepClosed.of_exists_root _ fun p _ hirr hsep ↦ ?_,
fun _ ↦ IntermediateField.eq_bot_of_isSepClosed_of_isSeparable _⟩
obtain ⟨x, hx⟩ := IsSepClosed.exists_aeval_eq_zero E p (degree_pos_of_irreducible hirr).ne' hsep
obtain ⟨x, rfl⟩ := h ▸ mem_separableClosure_iff.2 (hsep.of_dvd <| minpoly.dvd _ x hx)
exact ⟨x, by simpa [Algebra.ofId_apply] using hx⟩
/-- If `E` is separably closed, then the separable closure of `F` in `E` is an absolute
separable closure of `F`. -/
instance separableClosure.isSepClosure [IsSepClosed E] : IsSepClosure F (separableClosure F E) :=
⟨(IsSepClosed.separableClosure_eq_bot_iff _ E).mp (separableClosure.separableClosure_eq_bot F E),
isSeparable F E⟩
/-- The absolute separable closure is defined to be the relative separable closure inside the
algebraic closure. It is indeed a separable closure (`IsSepClosure`) by
`separableClosure.isSepClosure`, and it is Galois (`IsGalois`) by `separableClosure.isGalois`
or `IsSepClosure.isGalois`, and every separable extension embeds into it (`IsSepClosed.lift`). -/
abbrev SeparableClosure : Type _ := separableClosure F (AlgebraicClosure F)
/-- `F(S) / F` is a separable extension if and only if all elements of `S` are
separable elements. -/
theorem IntermediateField.isSeparable_adjoin_iff_isSeparable {S : Set E} :
Algebra.IsSeparable F (adjoin F S) ↔ ∀ x ∈ S, IsSeparable F x :=
(le_separableClosure_iff F E _).symm.trans adjoin_le_iff
/-- The separable closure of `F` in `E` is equal to `E` if and only if `E / F` is
separable. -/
theorem separableClosure.eq_top_iff : separableClosure F E = ⊤ ↔ Algebra.IsSeparable F E :=
⟨fun h ↦ ⟨fun _ ↦ mem_separableClosure_iff.1 (h ▸ mem_top)⟩,
fun _ ↦ top_unique fun x _ ↦ mem_separableClosure_iff.2 (Algebra.IsSeparable.isSeparable _ x)⟩
/-- If `K / E / F` is a field extension tower, then `separableClosure F K` is contained in
`separableClosure E K`. -/
theorem separableClosure.le_restrictScalars [Algebra E K] [IsScalarTower F E K] :
separableClosure F K ≤ (separableClosure E K).restrictScalars F :=
fun _ h ↦ IsSeparable.of_isScalarTower E h
/-- If `K / E / F` is a field extension tower, such that `E / F` is separable, then
`separableClosure F K` is equal to `separableClosure E K`. -/
theorem separableClosure.eq_restrictScalars_of_isSeparable [Algebra E K] [IsScalarTower F E K]
[Algebra.IsSeparable F E] : separableClosure F K = (separableClosure E K).restrictScalars F :=
(separableClosure.le_restrictScalars F E K).antisymm fun _ h ↦
IsSeparable.of_algebra_isSeparable_of_isSeparable F h
/-- If `K / E / F` is a field extension tower, then `E` adjoin `separableClosure F K` is contained
in `separableClosure E K`. -/
theorem separableClosure.adjoin_le [Algebra E K] [IsScalarTower F E K] :
adjoin E (separableClosure F K) ≤ separableClosure E K :=
adjoin_le_iff.2 <| le_restrictScalars F E K
/-- A compositum of two separable extensions is separable. -/
instance IntermediateField.isSeparable_sup (L1 L2 : IntermediateField F E)
[h1 : Algebra.IsSeparable F L1] [h2 : Algebra.IsSeparable F L2] :
Algebra.IsSeparable F (L1 ⊔ L2 : IntermediateField F E) := by
rw [← le_separableClosure_iff] at h1 h2 ⊢
exact sup_le h1 h2
/-- A compositum of separable extensions is separable. -/
instance IntermediateField.isSeparable_iSup {ι : Type*} {t : ι → IntermediateField F E}
[h : ∀ i, Algebra.IsSeparable F (t i)] :
Algebra.IsSeparable F (⨆ i, t i : IntermediateField F E) := by
simp_rw [← le_separableClosure_iff] at h ⊢
exact iSup_le h
end separableClosure
namespace Field
/-- The (infinite) separable degree for a general field extension `E / F` is defined
to be the degree of `separableClosure F E / F`. -/
def sepDegree := Module.rank F (separableClosure F E)
/-- The (infinite) inseparable degree for a general field extension `E / F` is defined
to be the degree of `E / separableClosure F E`. -/
def insepDegree := Module.rank (separableClosure F E) E
/-- The finite inseparable degree for a general field extension `E / F` is defined
to be the degree of `E / separableClosure F E` as a natural number. It is defined to be zero
if such field extension is infinite. -/
def finInsepDegree : ℕ := finrank (separableClosure F E) E
theorem finInsepDegree_def' : finInsepDegree F E = Cardinal.toNat (insepDegree F E) := rfl
instance instNeZeroSepDegree : NeZero (sepDegree F E) := ⟨rank_pos.ne'⟩
instance instNeZeroInsepDegree : NeZero (insepDegree F E) := ⟨rank_pos.ne'⟩
instance instNeZeroFinInsepDegree [FiniteDimensional F E] :
NeZero (finInsepDegree F E) := ⟨finrank_pos.ne'⟩
/-- If `E` and `K` are isomorphic as `F`-algebras, then they have the same
separable degree over `F`. -/
theorem lift_sepDegree_eq_of_equiv (i : E ≃ₐ[F] K) :
Cardinal.lift.{w} (sepDegree F E) = Cardinal.lift.{v} (sepDegree F K) :=
i.separableClosure.toLinearEquiv.lift_rank_eq
/-- The same-universe version of `Field.lift_sepDegree_eq_of_equiv`. -/
theorem sepDegree_eq_of_equiv (K : Type v) [Field K] [Algebra F K] (i : E ≃ₐ[F] K) :
sepDegree F E = sepDegree F K :=
i.separableClosure.toLinearEquiv.rank_eq
/-- The separable degree multiplied by the inseparable degree is equal
to the (infinite) field extension degree. -/
theorem sepDegree_mul_insepDegree : sepDegree F E * insepDegree F E = Module.rank F E :=
rank_mul_rank F (separableClosure F E) E
/-- If `E` and `K` are isomorphic as `F`-algebras, then they have the same
inseparable degree over `F`. -/
theorem lift_insepDegree_eq_of_equiv (i : E ≃ₐ[F] K) :
Cardinal.lift.{w} (insepDegree F E) = Cardinal.lift.{v} (insepDegree F K) :=
Algebra.lift_rank_eq_of_equiv_equiv i.separableClosure i rfl
/-- The same-universe version of `Field.lift_insepDegree_eq_of_equiv`. -/
theorem insepDegree_eq_of_equiv (K : Type v) [Field K] [Algebra F K] (i : E ≃ₐ[F] K) :
insepDegree F E = insepDegree F K :=
Algebra.rank_eq_of_equiv_equiv i.separableClosure i rfl
/-- If `E` and `K` are isomorphic as `F`-algebras, then they have the same finite
inseparable degree over `F`. -/
theorem finInsepDegree_eq_of_equiv (i : E ≃ₐ[F] K) :
finInsepDegree F E = finInsepDegree F K := by
simpa only [Cardinal.toNat_lift] using congr_arg Cardinal.toNat
(lift_insepDegree_eq_of_equiv F E K i)
@[simp]
theorem sepDegree_self : sepDegree F F = 1 := by
rw [sepDegree, Subsingleton.elim (separableClosure F F) ⊥, IntermediateField.rank_bot]
@[simp]
theorem insepDegree_self : insepDegree F F = 1 := by
rw [insepDegree, Subsingleton.elim (separableClosure F F) ⊤, IntermediateField.rank_top]
@[simp]
theorem finInsepDegree_self : finInsepDegree F F = 1 := by
rw [finInsepDegree_def', insepDegree_self, Cardinal.one_toNat]
end Field
namespace IntermediateField
@[simp]
theorem sepDegree_bot : sepDegree F (⊥ : IntermediateField F E) = 1 := by
have := lift_sepDegree_eq_of_equiv _ _ _ (botEquiv F E)
rwa [sepDegree_self, Cardinal.lift_one, ← Cardinal.lift_one.{v, u}, Cardinal.lift_inj] at this
@[simp]
theorem insepDegree_bot : insepDegree F (⊥ : IntermediateField F E) = 1 := by
have := lift_insepDegree_eq_of_equiv _ _ _ (botEquiv F E)
rwa [insepDegree_self, Cardinal.lift_one, ← Cardinal.lift_one.{v, u}, Cardinal.lift_inj] at this
@[simp]
theorem finInsepDegree_bot : finInsepDegree F (⊥ : IntermediateField F E) = 1 := by
rw [finInsepDegree_eq_of_equiv _ _ _ (botEquiv F E), finInsepDegree_self]
section Tower
variable [Algebra E K] [IsScalarTower F E K]
theorem lift_sepDegree_bot' : Cardinal.lift.{v} (sepDegree F (⊥ : IntermediateField E K)) =
Cardinal.lift.{w} (sepDegree F E) :=
lift_sepDegree_eq_of_equiv _ _ _ ((botEquiv E K).restrictScalars F)
theorem lift_insepDegree_bot' : Cardinal.lift.{v} (insepDegree F (⊥ : IntermediateField E K)) =
Cardinal.lift.{w} (insepDegree F E) :=
lift_insepDegree_eq_of_equiv _ _ _ ((botEquiv E K).restrictScalars F)
variable {F}
@[simp]
theorem finInsepDegree_bot' :
finInsepDegree F (⊥ : IntermediateField E K) = finInsepDegree F E := by
simpa only [Cardinal.toNat_lift] using congr_arg Cardinal.toNat (lift_insepDegree_bot' F E K)
@[simp]
theorem sepDegree_top : sepDegree F (⊤ : IntermediateField E K) = sepDegree F K :=
sepDegree_eq_of_equiv _ _ _ ((topEquiv (F := E) (E := K)).restrictScalars F)
@[simp]
theorem insepDegree_top : insepDegree F (⊤ : IntermediateField E K) = insepDegree F K :=
insepDegree_eq_of_equiv _ _ _ ((topEquiv (F := E) (E := K)).restrictScalars F)
@[simp]
theorem finInsepDegree_top : finInsepDegree F (⊤ : IntermediateField E K) = finInsepDegree F K := by
rw [finInsepDegree_def', insepDegree_top, ← finInsepDegree_def']
variable (K : Type v) [Field K] [Algebra F K] [Algebra E K] [IsScalarTower F E K]
@[simp]
theorem sepDegree_bot' : sepDegree F (⊥ : IntermediateField E K) = sepDegree F E :=
sepDegree_eq_of_equiv _ _ _ ((botEquiv E K).restrictScalars F)
@[simp]
theorem insepDegree_bot' : insepDegree F (⊥ : IntermediateField E K) = insepDegree F E :=
insepDegree_eq_of_equiv _ _ _ ((botEquiv E K).restrictScalars F)
end Tower
end IntermediateField
/-- A separable extension has separable degree equal to degree. -/
theorem Algebra.IsSeparable.sepDegree_eq [Algebra.IsSeparable F E] :
sepDegree F E = Module.rank F E := by
rw [sepDegree, (separableClosure.eq_top_iff F E).2 ‹_›, IntermediateField.rank_top']
/-- A separable extension has inseparable degree one. -/
theorem Algebra.IsSeparable.insepDegree_eq [Algebra.IsSeparable F E] : insepDegree F E = 1 := by
rw [insepDegree, (separableClosure.eq_top_iff F E).2 ‹_›, IntermediateField.rank_top]
/-- A separable extension has finite inseparable degree one. -/
theorem Algebra.IsSeparable.finInsepDegree_eq [Algebra.IsSeparable F E] : finInsepDegree F E = 1 :=
Cardinal.one_toNat ▸ congr(Cardinal.toNat $(insepDegree_eq F E))
|
FieldTheory\SeparableDegree.lean | /-
Copyright (c) 2023 Jz Pan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jz Pan
-/
import Mathlib.FieldTheory.SplittingField.Construction
import Mathlib.FieldTheory.IsAlgClosed.AlgebraicClosure
import Mathlib.FieldTheory.Separable
import Mathlib.FieldTheory.NormalClosure
import Mathlib.RingTheory.Polynomial.SeparableDegree
/-!
# Separable degree
This file contains basics about the separable degree of a field extension.
## Main definitions
- `Field.Emb F E`: the type of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`
(the algebraic closure of `F` is usually used in the literature, but our definition has the
advantage that `Field.Emb F E` lies in the same universe as `E` rather than the maximum over `F`
and `E`). Usually denoted by $\operatorname{Emb}_F(E)$ in textbooks.
**Remark:** if `E / F` is not algebraic, then this definition makes no mathematical sense,
and if it is infinite, then its cardinality doesn't behave as expected (namely, not equal to the
field extension degree of `separableClosure F E / F`). For example, if $F = \mathbb{Q}$ and
$E = \mathbb{Q}( \mu_{p^\infty} )$, then $\operatorname{Emb}_F (E)$ is in bijection with
$\operatorname{Gal}(E/F)$, which is isomorphic to
$\mathbb{Z}_p^\times$, which is uncountable, while $[E:F]$ is countable.
**TODO:** prove or disprove that if `E / F` is algebraic and `Emb F E` is infinite, then
`Field.Emb F E` has cardinality `2 ^ Module.rank F (separableClosure F E)`.
- `Field.finSepDegree F E`: the (finite) separable degree $[E:F]_s$ of an algebraic extension
`E / F` of fields, defined to be the number of `F`-algebra homomorphisms from `E` to the algebraic
closure of `E`, as a natural number. It is zero if `Field.Emb F E` is not finite.
Note that if `E / F` is not algebraic, then this definition makes no mathematical sense.
**Remark:** the `Cardinal`-valued, potentially infinite separable degree `Field.sepDegree F E`
for a general algebraic extension `E / F` is defined to be the degree of `L / F`, where `L` is
the (relative) separable closure `separableClosure F E` of `F` in `E`, which is not defined in
this file yet. Later we will show that (`Field.finSepDegree_eq`), if `Field.Emb F E` is finite,
then these two definitions coincide.
- `Polynomial.natSepDegree`: the separable degree of a polynomial is a natural number,
defined to be the number of distinct roots of it over its splitting field.
## Main results
- `Field.embEquivOfEquiv`, `Field.finSepDegree_eq_of_equiv`:
a random bijection between `Field.Emb F E` and `Field.Emb F K` when `E` and `K` are isomorphic
as `F`-algebras. In particular, they have the same cardinality (so their
`Field.finSepDegree` are equal).
- `Field.embEquivOfAdjoinSplits`,
`Field.finSepDegree_eq_of_adjoin_splits`: a random bijection between `Field.Emb F E` and
`E →ₐ[F] K` if `E = F(S)` such that every element `s` of `S` is integral (= algebraic) over `F`
and whose minimal polynomial splits in `K`. In particular, they have the same cardinality.
- `Field.embEquivOfIsAlgClosed`,
`Field.finSepDegree_eq_of_isAlgClosed`: a random bijection between `Field.Emb F E` and
`E →ₐ[F] K` when `E / F` is algebraic and `K / F` is algebraically closed.
In particular, they have the same cardinality.
- `Field.embProdEmbOfIsAlgebraic`, `Field.finSepDegree_mul_finSepDegree_of_isAlgebraic`:
if `K / E / F` is a field extension tower, such that `K / E` is algebraic,
then there is a non-canonical bijection `Field.Emb F E × Field.Emb E K ≃ Field.Emb F K`.
In particular, the separable degrees satisfy the tower law: $[E:F]_s [K:E]_s = [K:F]_s$
(see also `FiniteDimensional.finrank_mul_finrank`).
- `Polynomial.natSepDegree_le_natDegree`: the separable degree of a polynomial is smaller than
its degree.
- `Polynomial.natSepDegree_eq_natDegree_iff`: the separable degree of a non-zero polynomial is
equal to its degree if and only if it is separable.
- `Polynomial.natSepDegree_eq_of_splits`: if a polynomial splits over `E`, then its separable degree
is equal to the number of distinct roots of it over `E`.
- `Polynomial.natSepDegree_eq_of_isAlgClosed`: the separable degree of a polynomial is equal to
the number of distinct roots of it over any algebraically closed field.
- `Polynomial.natSepDegree_expand`: if a field `F` is of exponential characteristic
`q`, then `Polynomial.expand F (q ^ n) f` and `f` have the same separable degree.
- `Polynomial.HasSeparableContraction.natSepDegree_eq`: if a polynomial has separable
contraction, then its separable degree is equal to its separable contraction degree.
- `Irreducible.natSepDegree_dvd_natDegree`: the separable degree of an irreducible
polynomial divides its degree.
- `IntermediateField.finSepDegree_adjoin_simple_eq_natSepDegree`: the separable degree of
`F⟮α⟯ / F` is equal to the separable degree of the minimal polynomial of `α` over `F`.
- `IntermediateField.finSepDegree_adjoin_simple_eq_finrank_iff`: if `α` is algebraic over `F`, then
the separable degree of `F⟮α⟯ / F` is equal to the degree of `F⟮α⟯ / F` if and only if `α` is a
separable element.
- `Field.finSepDegree_dvd_finrank`: the separable degree of any field extension `E / F` divides
the degree of `E / F`.
- `Field.finSepDegree_le_finrank`: the separable degree of a finite extension `E / F` is smaller
than the degree of `E / F`.
- `Field.finSepDegree_eq_finrank_iff`: if `E / F` is a finite extension, then its separable degree
is equal to its degree if and only if it is a separable extension.
- `IntermediateField.isSeparable_adjoin_simple_iff_isSeparable`: `F⟮x⟯ / F` is a separable extension
if and only if `x` is a separable element.
- `Algebra.IsSeparable.trans`: if `E / F` and `K / E` are both separable, then `K / F` is also
separable.
## Tags
separable degree, degree, polynomial
-/
open FiniteDimensional Polynomial IntermediateField Field
noncomputable section
universe u v w
variable (F : Type u) (E : Type v) [Field F] [Field E] [Algebra F E]
variable (K : Type w) [Field K] [Algebra F K]
namespace Field
/-- `Field.Emb F E` is the type of `F`-algebra homomorphisms from `E` to the algebraic closure
of `E`. -/
def Emb := E →ₐ[F] AlgebraicClosure E
/-- If `E / F` is an algebraic extension, then the (finite) separable degree of `E / F`
is the number of `F`-algebra homomorphisms from `E` to the algebraic closure of `E`,
as a natural number. It is defined to be zero if there are infinitely many of them.
Note that if `E / F` is not algebraic, then this definition makes no mathematical sense. -/
def finSepDegree : ℕ := Nat.card (Emb F E)
instance instInhabitedEmb : Inhabited (Emb F E) := ⟨IsScalarTower.toAlgHom F E _⟩
instance instNeZeroFinSepDegree [FiniteDimensional F E] : NeZero (finSepDegree F E) :=
⟨Nat.card_ne_zero.2 ⟨inferInstance, Fintype.finite <| minpoly.AlgHom.fintype _ _ _⟩⟩
/-- A random bijection between `Field.Emb F E` and `Field.Emb F K` when `E` and `K` are isomorphic
as `F`-algebras. -/
def embEquivOfEquiv (i : E ≃ₐ[F] K) :
Emb F E ≃ Emb F K := AlgEquiv.arrowCongr i <| AlgEquiv.symm <| by
let _ : Algebra E K := i.toAlgHom.toRingHom.toAlgebra
have : Algebra.IsAlgebraic E K := by
constructor
intro x
have h := isAlgebraic_algebraMap (R := E) (A := K) (i.symm.toAlgHom x)
rw [show ∀ y : E, (algebraMap E K) y = i.toAlgHom y from fun y ↦ rfl] at h
simpa only [AlgEquiv.toAlgHom_eq_coe, AlgHom.coe_coe, AlgEquiv.apply_symm_apply] using h
apply AlgEquiv.restrictScalars (R := F) (S := E)
exact IsAlgClosure.equivOfAlgebraic E K (AlgebraicClosure K) (AlgebraicClosure E)
/-- If `E` and `K` are isomorphic as `F`-algebras, then they have the same `Field.finSepDegree`
over `F`. -/
theorem finSepDegree_eq_of_equiv (i : E ≃ₐ[F] K) :
finSepDegree F E = finSepDegree F K := Nat.card_congr (embEquivOfEquiv F E K i)
@[simp]
theorem finSepDegree_self : finSepDegree F F = 1 := by
have : Cardinal.mk (Emb F F) = 1 := le_antisymm
(Cardinal.le_one_iff_subsingleton.2 AlgHom.subsingleton)
(Cardinal.one_le_iff_ne_zero.2 <| Cardinal.mk_ne_zero _)
rw [finSepDegree, Nat.card, this, Cardinal.one_toNat]
end Field
namespace IntermediateField
@[simp]
theorem finSepDegree_bot : finSepDegree F (⊥ : IntermediateField F E) = 1 := by
rw [finSepDegree_eq_of_equiv _ _ _ (botEquiv F E), finSepDegree_self]
section Tower
variable {F}
variable [Algebra E K] [IsScalarTower F E K]
@[simp]
theorem finSepDegree_bot' : finSepDegree F (⊥ : IntermediateField E K) = finSepDegree F E :=
finSepDegree_eq_of_equiv _ _ _ ((botEquiv E K).restrictScalars F)
@[simp]
theorem finSepDegree_top : finSepDegree F (⊤ : IntermediateField E K) = finSepDegree F K :=
finSepDegree_eq_of_equiv _ _ _ ((topEquiv (F := E) (E := K)).restrictScalars F)
end Tower
end IntermediateField
namespace Field
/-- A random bijection between `Field.Emb F E` and `E →ₐ[F] K` if `E = F(S)` such that every
element `s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`.
Combined with `Field.instInhabitedEmb`, it can be viewed as a stronger version of
`IntermediateField.nonempty_algHom_of_adjoin_splits`. -/
def embEquivOfAdjoinSplits {S : Set E} (hS : adjoin F S = ⊤)
(hK : ∀ s ∈ S, IsIntegral F s ∧ Splits (algebraMap F K) (minpoly F s)) :
Emb F E ≃ (E →ₐ[F] K) :=
have : Algebra.IsAlgebraic F (⊤ : IntermediateField F E) :=
(hS ▸ isAlgebraic_adjoin (S := S) fun x hx ↦ (hK x hx).1)
have halg := (topEquiv (F := F) (E := E)).isAlgebraic
Classical.choice <| Function.Embedding.antisymm
(halg.algHomEmbeddingOfSplits (fun _ ↦ splits_of_mem_adjoin F (S := S) hK (hS ▸ mem_top)) _)
(halg.algHomEmbeddingOfSplits (fun _ ↦ IsAlgClosed.splits_codomain _) _)
/-- The `Field.finSepDegree F E` is equal to the cardinality of `E →ₐ[F] K`
if `E = F(S)` such that every element
`s` of `S` is integral (= algebraic) over `F` and whose minimal polynomial splits in `K`. -/
theorem finSepDegree_eq_of_adjoin_splits {S : Set E} (hS : adjoin F S = ⊤)
(hK : ∀ s ∈ S, IsIntegral F s ∧ Splits (algebraMap F K) (minpoly F s)) :
finSepDegree F E = Nat.card (E →ₐ[F] K) := Nat.card_congr (embEquivOfAdjoinSplits F E K hS hK)
/-- A random bijection between `Field.Emb F E` and `E →ₐ[F] K` when `E / F` is algebraic
and `K / F` is algebraically closed. -/
def embEquivOfIsAlgClosed [Algebra.IsAlgebraic F E] [IsAlgClosed K] :
Emb F E ≃ (E →ₐ[F] K) :=
embEquivOfAdjoinSplits F E K (adjoin_univ F E) fun s _ ↦
⟨Algebra.IsIntegral.isIntegral s, IsAlgClosed.splits_codomain _⟩
/-- The `Field.finSepDegree F E` is equal to the cardinality of `E →ₐ[F] K` as a natural number,
when `E / F` is algebraic and `K / F` is algebraically closed. -/
theorem finSepDegree_eq_of_isAlgClosed [Algebra.IsAlgebraic F E] [IsAlgClosed K] :
finSepDegree F E = Nat.card (E →ₐ[F] K) := Nat.card_congr (embEquivOfIsAlgClosed F E K)
/-- If `K / E / F` is a field extension tower, such that `K / E` is algebraic,
then there is a non-canonical bijection
`Field.Emb F E × Field.Emb E K ≃ Field.Emb F K`. A corollary of `algHomEquivSigma`. -/
def embProdEmbOfIsAlgebraic [Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic E K] :
Emb F E × Emb E K ≃ Emb F K :=
let e : ∀ f : E →ₐ[F] AlgebraicClosure K,
@AlgHom E K _ _ _ _ _ f.toRingHom.toAlgebra ≃ Emb E K := fun f ↦
(@embEquivOfIsAlgClosed E K _ _ _ _ _ f.toRingHom.toAlgebra).symm
(algHomEquivSigma (A := F) (B := E) (C := K) (D := AlgebraicClosure K) |>.trans
(Equiv.sigmaEquivProdOfEquiv e) |>.trans <| Equiv.prodCongrLeft <|
fun _ : Emb E K ↦ AlgEquiv.arrowCongr (@AlgEquiv.refl F E _ _ _) <|
(IsAlgClosure.equivOfAlgebraic E K (AlgebraicClosure K)
(AlgebraicClosure E)).restrictScalars F).symm
/-- If `K / E / F` is a field extension tower, such that `K / E` is algebraic, then their
separable degrees satisfy the tower law
$[E:F]_s [K:E]_s = [K:F]_s$. See also `FiniteDimensional.finrank_mul_finrank`. -/
theorem finSepDegree_mul_finSepDegree_of_isAlgebraic
[Algebra E K] [IsScalarTower F E K] [Algebra.IsAlgebraic E K] :
finSepDegree F E * finSepDegree E K = finSepDegree F K := by
simpa only [Nat.card_prod] using Nat.card_congr (embProdEmbOfIsAlgebraic F E K)
end Field
namespace Polynomial
variable {F E}
variable (f : F[X])
open Classical in
/-- The separable degree `Polynomial.natSepDegree` of a polynomial is a natural number,
defined to be the number of distinct roots of it over its splitting field.
This is similar to `Polynomial.natDegree` but not to `Polynomial.degree`, namely, the separable
degree of `0` is `0`, not negative infinity. -/
def natSepDegree : ℕ := (f.aroots f.SplittingField).toFinset.card
/-- The separable degree of a polynomial is smaller than its degree. -/
theorem natSepDegree_le_natDegree : f.natSepDegree ≤ f.natDegree := by
have := f.map (algebraMap F f.SplittingField) |>.card_roots'
rw [← aroots_def, natDegree_map] at this
classical
exact (f.aroots f.SplittingField).toFinset_card_le.trans this
@[simp]
theorem natSepDegree_X_sub_C (x : F) : (X - C x).natSepDegree = 1 := by
simp only [natSepDegree, aroots_X_sub_C, Multiset.toFinset_singleton, Finset.card_singleton]
@[simp]
theorem natSepDegree_X : (X : F[X]).natSepDegree = 1 := by
simp only [natSepDegree, aroots_X, Multiset.toFinset_singleton, Finset.card_singleton]
/-- A constant polynomial has zero separable degree. -/
theorem natSepDegree_eq_zero (h : f.natDegree = 0) : f.natSepDegree = 0 := by
linarith only [natSepDegree_le_natDegree f, h]
@[simp]
theorem natSepDegree_C (x : F) : (C x).natSepDegree = 0 := natSepDegree_eq_zero _ (natDegree_C _)
@[simp]
theorem natSepDegree_zero : (0 : F[X]).natSepDegree = 0 := by
rw [← C_0, natSepDegree_C]
@[simp]
theorem natSepDegree_one : (1 : F[X]).natSepDegree = 0 := by
rw [← C_1, natSepDegree_C]
/-- A non-constant polynomial has non-zero separable degree. -/
theorem natSepDegree_ne_zero (h : f.natDegree ≠ 0) : f.natSepDegree ≠ 0 := by
rw [natSepDegree, ne_eq, Finset.card_eq_zero, ← ne_eq, ← Finset.nonempty_iff_ne_empty]
use rootOfSplits _ (SplittingField.splits f) (ne_of_apply_ne _ h)
classical
rw [Multiset.mem_toFinset, mem_aroots]
exact ⟨ne_of_apply_ne _ h, map_rootOfSplits _ (SplittingField.splits f) (ne_of_apply_ne _ h)⟩
/-- A polynomial has zero separable degree if and only if it is constant. -/
theorem natSepDegree_eq_zero_iff : f.natSepDegree = 0 ↔ f.natDegree = 0 :=
⟨(natSepDegree_ne_zero f).mtr, natSepDegree_eq_zero f⟩
/-- A polynomial has non-zero separable degree if and only if it is non-constant. -/
theorem natSepDegree_ne_zero_iff : f.natSepDegree ≠ 0 ↔ f.natDegree ≠ 0 :=
Iff.not <| natSepDegree_eq_zero_iff f
/-- The separable degree of a non-zero polynomial is equal to its degree if and only if
it is separable. -/
theorem natSepDegree_eq_natDegree_iff (hf : f ≠ 0) :
f.natSepDegree = f.natDegree ↔ f.Separable := by
classical
simp_rw [← card_rootSet_eq_natDegree_iff_of_splits hf (SplittingField.splits f),
rootSet_def, Finset.coe_sort_coe, Fintype.card_coe]
rfl
/-- If a polynomial is separable, then its separable degree is equal to its degree. -/
theorem natSepDegree_eq_natDegree_of_separable (h : f.Separable) :
f.natSepDegree = f.natDegree := (natSepDegree_eq_natDegree_iff f h.ne_zero).2 h
variable {f} in
/-- Same as `Polynomial.natSepDegree_eq_natDegree_of_separable`, but enables the use of
dot notation. -/
theorem Separable.natSepDegree_eq_natDegree (h : f.Separable) :
f.natSepDegree = f.natDegree := natSepDegree_eq_natDegree_of_separable f h
/-- If a polynomial splits over `E`, then its separable degree is equal to
the number of distinct roots of it over `E`. -/
theorem natSepDegree_eq_of_splits [DecidableEq E] (h : f.Splits (algebraMap F E)) :
f.natSepDegree = (f.aroots E).toFinset.card := by
classical
rw [aroots, ← (SplittingField.lift f h).comp_algebraMap, ← map_map,
roots_map _ ((splits_id_iff_splits _).mpr <| SplittingField.splits f),
Multiset.toFinset_map, Finset.card_image_of_injective _ (RingHom.injective _), natSepDegree]
variable (E) in
/-- The separable degree of a polynomial is equal to
the number of distinct roots of it over any algebraically closed field. -/
theorem natSepDegree_eq_of_isAlgClosed [DecidableEq E] [IsAlgClosed E] :
f.natSepDegree = (f.aroots E).toFinset.card :=
natSepDegree_eq_of_splits f (IsAlgClosed.splits_codomain f)
variable (E) in
theorem natSepDegree_map : (f.map (algebraMap F E)).natSepDegree = f.natSepDegree := by
classical
simp_rw [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure E), aroots_def, map_map,
← IsScalarTower.algebraMap_eq]
@[simp]
theorem natSepDegree_C_mul {x : F} (hx : x ≠ 0) :
(C x * f).natSepDegree = f.natSepDegree := by
classical
simp only [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_C_mul _ hx]
@[simp]
theorem natSepDegree_smul_nonzero {x : F} (hx : x ≠ 0) :
(x • f).natSepDegree = f.natSepDegree := by
classical
simp only [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_smul_nonzero _ hx]
@[simp]
theorem natSepDegree_pow {n : ℕ} : (f ^ n).natSepDegree = if n = 0 then 0 else f.natSepDegree := by
classical
simp only [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_pow]
by_cases h : n = 0
· simp only [h, zero_smul, Multiset.toFinset_zero, Finset.card_empty, ite_true]
simp only [h, Multiset.toFinset_nsmul _ n h, ite_false]
theorem natSepDegree_pow_of_ne_zero {n : ℕ} (hn : n ≠ 0) :
(f ^ n).natSepDegree = f.natSepDegree := by simp_rw [natSepDegree_pow, hn, ite_false]
theorem natSepDegree_X_pow {n : ℕ} : (X ^ n : F[X]).natSepDegree = if n = 0 then 0 else 1 := by
simp only [natSepDegree_pow, natSepDegree_X]
theorem natSepDegree_X_sub_C_pow {x : F} {n : ℕ} :
((X - C x) ^ n).natSepDegree = if n = 0 then 0 else 1 := by
simp only [natSepDegree_pow, natSepDegree_X_sub_C]
theorem natSepDegree_C_mul_X_sub_C_pow {x y : F} {n : ℕ} (hx : x ≠ 0) :
(C x * (X - C y) ^ n).natSepDegree = if n = 0 then 0 else 1 := by
simp only [natSepDegree_C_mul _ hx, natSepDegree_X_sub_C_pow]
theorem natSepDegree_mul (g : F[X]) :
(f * g).natSepDegree ≤ f.natSepDegree + g.natSepDegree := by
by_cases h : f * g = 0
· simp only [h, natSepDegree_zero, zero_le]
classical
simp_rw [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_mul h, Multiset.toFinset_add]
exact Finset.card_union_le _ _
theorem natSepDegree_mul_eq_iff (g : F[X]) :
(f * g).natSepDegree = f.natSepDegree + g.natSepDegree ↔ (f = 0 ∧ g = 0) ∨ IsCoprime f g := by
by_cases h : f * g = 0
· rw [mul_eq_zero] at h
wlog hf : f = 0 generalizing f g
· simpa only [mul_comm, add_comm, and_comm,
isCoprime_comm] using this g f h.symm (h.resolve_left hf)
rw [hf, zero_mul, natSepDegree_zero, zero_add, isCoprime_zero_left, isUnit_iff, eq_comm,
natSepDegree_eq_zero_iff, natDegree_eq_zero]
refine ⟨fun ⟨x, h⟩ ↦ ?_, ?_⟩
· by_cases hx : x = 0
· exact .inl ⟨rfl, by rw [← h, hx, map_zero]⟩
exact .inr ⟨x, Ne.isUnit hx, h⟩
rintro (⟨-, h⟩ | ⟨x, -, h⟩)
· exact ⟨0, by rw [h, map_zero]⟩
exact ⟨x, h⟩
classical
simp_rw [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_mul h, Multiset.toFinset_add,
Finset.card_union_eq_card_add_card, Finset.disjoint_iff_ne, Multiset.mem_toFinset, mem_aroots]
rw [mul_eq_zero, not_or] at h
refine ⟨fun H ↦ .inr (isCoprime_of_irreducible_dvd (not_and.2 fun _ ↦ h.2)
fun u hu ⟨v, hf⟩ ⟨w, hg⟩ ↦ ?_), ?_⟩
· obtain ⟨x, hx⟩ := IsAlgClosed.exists_aeval_eq_zero
(AlgebraicClosure F) _ (degree_pos_of_irreducible hu).ne'
exact H x ⟨h.1, by simpa only [map_mul, hx, zero_mul] using congr(aeval x $hf)⟩
x ⟨h.2, by simpa only [map_mul, hx, zero_mul] using congr(aeval x $hg)⟩ rfl
rintro (⟨rfl, rfl⟩ | hc)
· exact (h.1 rfl).elim
rintro x hf _ hg rfl
obtain ⟨u, v, hfg⟩ := hc
simpa only [map_add, map_mul, map_one, hf.2, hg.2, mul_zero, add_zero,
zero_ne_one] using congr(aeval x $hfg)
theorem natSepDegree_mul_of_isCoprime (g : F[X]) (hc : IsCoprime f g) :
(f * g).natSepDegree = f.natSepDegree + g.natSepDegree :=
(natSepDegree_mul_eq_iff f g).2 (.inr hc)
theorem natSepDegree_le_of_dvd (g : F[X]) (h1 : f ∣ g) (h2 : g ≠ 0) :
f.natSepDegree ≤ g.natSepDegree := by
classical
simp_rw [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F)]
exact Finset.card_le_card <| Multiset.toFinset_subset.mpr <|
Multiset.Le.subset <| roots.le_of_dvd (map_ne_zero h2) <| map_dvd _ h1
/-- If a field `F` is of exponential characteristic `q`, then `Polynomial.expand F (q ^ n) f`
and `f` have the same separable degree. -/
theorem natSepDegree_expand (q : ℕ) [hF : ExpChar F q] {n : ℕ} :
(expand F (q ^ n) f).natSepDegree = f.natSepDegree := by
cases' hF with _ _ hprime _
· simp only [one_pow, expand_one]
haveI := Fact.mk hprime
classical
simpa only [natSepDegree_eq_of_isAlgClosed (AlgebraicClosure F), aroots_def, map_expand,
Fintype.card_coe] using Fintype.card_eq.2
⟨(f.map (algebraMap F (AlgebraicClosure F))).rootsExpandPowEquivRoots q n⟩
theorem natSepDegree_X_pow_char_pow_sub_C (q : ℕ) [ExpChar F q] (n : ℕ) (y : F) :
(X ^ q ^ n - C y).natSepDegree = 1 := by
rw [← expand_X, ← expand_C (q ^ n), ← map_sub, natSepDegree_expand, natSepDegree_X_sub_C]
variable {f} in
/-- If `g` is a separable contraction of `f`, then the separable degree of `f` is equal to
the degree of `g`. -/
theorem IsSeparableContraction.natSepDegree_eq {g : Polynomial F} {q : ℕ} [ExpChar F q]
(h : IsSeparableContraction q f g) : f.natSepDegree = g.natDegree := by
obtain ⟨h1, m, h2⟩ := h
rw [← h2, natSepDegree_expand, h1.natSepDegree_eq_natDegree]
variable {f} in
/-- If a polynomial has separable contraction, then its separable degree is equal to the degree of
the given separable contraction. -/
theorem HasSeparableContraction.natSepDegree_eq
{q : ℕ} [ExpChar F q] (hf : f.HasSeparableContraction q) :
f.natSepDegree = hf.degree := hf.isSeparableContraction.natSepDegree_eq
end Polynomial
namespace Irreducible
variable {F}
variable {f : F[X]}
/-- The separable degree of an irreducible polynomial divides its degree. -/
theorem natSepDegree_dvd_natDegree (h : Irreducible f) :
f.natSepDegree ∣ f.natDegree := by
obtain ⟨q, _⟩ := ExpChar.exists F
have hf := h.hasSeparableContraction q
rw [hf.natSepDegree_eq]
exact hf.dvd_degree
/-- A monic irreducible polynomial over a field `F` of exponential characteristic `q` has
separable degree one if and only if it is of the form `Polynomial.expand F (q ^ n) (X - C y)`
for some `n : ℕ` and `y : F`. -/
theorem natSepDegree_eq_one_iff_of_monic' (q : ℕ) [ExpChar F q] (hm : f.Monic)
(hi : Irreducible f) : f.natSepDegree = 1 ↔
∃ (n : ℕ) (y : F), f = expand F (q ^ n) (X - C y) := by
refine ⟨fun h ↦ ?_, fun ⟨n, y, h⟩ ↦ ?_⟩
· obtain ⟨g, h1, n, rfl⟩ := hi.hasSeparableContraction q
have h2 : g.natDegree = 1 := by
rwa [natSepDegree_expand _ q, h1.natSepDegree_eq_natDegree] at h
rw [((monic_expand_iff <| expChar_pow_pos F q n).mp hm).eq_X_add_C h2]
exact ⟨n, -(g.coeff 0), by rw [map_neg, sub_neg_eq_add]⟩
rw [h, natSepDegree_expand _ q, natSepDegree_X_sub_C]
/-- A monic irreducible polynomial over a field `F` of exponential characteristic `q` has
separable degree one if and only if it is of the form `X ^ (q ^ n) - C y`
for some `n : ℕ` and `y : F`. -/
theorem natSepDegree_eq_one_iff_of_monic (q : ℕ) [ExpChar F q] (hm : f.Monic)
(hi : Irreducible f) : f.natSepDegree = 1 ↔ ∃ (n : ℕ) (y : F), f = X ^ q ^ n - C y := by
simp_rw [hi.natSepDegree_eq_one_iff_of_monic' q hm, map_sub, expand_X, expand_C]
end Irreducible
namespace Polynomial
namespace Monic
variable {F}
variable {f : F[X]}
alias natSepDegree_eq_one_iff_of_irreducible' := Irreducible.natSepDegree_eq_one_iff_of_monic'
alias natSepDegree_eq_one_iff_of_irreducible := Irreducible.natSepDegree_eq_one_iff_of_monic
/-- If a monic polynomial of separable degree one splits, then it is of form `(X - C y) ^ m` for
some non-zero natural number `m` and some element `y` of `F`. -/
theorem eq_X_sub_C_pow_of_natSepDegree_eq_one_of_splits (hm : f.Monic)
(hs : f.Splits (RingHom.id F))
(h : f.natSepDegree = 1) : ∃ (m : ℕ) (y : F), m ≠ 0 ∧ f = (X - C y) ^ m := by
classical
have h1 := eq_prod_roots_of_monic_of_splits_id hm hs
have h2 := (natSepDegree_eq_of_splits f hs).symm
rw [h, aroots_def, Algebra.id.map_eq_id, map_id, Multiset.toFinset_card_eq_one_iff] at h2
obtain ⟨h2, y, h3⟩ := h2
exact ⟨_, y, h2, by rwa [h3, Multiset.map_nsmul, Multiset.map_singleton, Multiset.prod_nsmul,
Multiset.prod_singleton] at h1⟩
/-- If a monic irreducible polynomial over a field `F` of exponential characteristic `q` has
separable degree one, then it is of the form `X ^ (q ^ n) - C y` for some natural number `n`,
and some element `y` of `F`, such that either `n = 0` or `y` has no `q`-th root in `F`. -/
theorem eq_X_pow_char_pow_sub_C_of_natSepDegree_eq_one_of_irreducible (q : ℕ) [ExpChar F q]
(hm : f.Monic) (hi : Irreducible f) (h : f.natSepDegree = 1) : ∃ (n : ℕ) (y : F),
(n = 0 ∨ y ∉ (frobenius F q).range) ∧ f = X ^ q ^ n - C y := by
obtain ⟨n, y, hf⟩ := (hm.natSepDegree_eq_one_iff_of_irreducible q hi).1 h
cases id ‹ExpChar F q› with
| zero =>
simp_rw [one_pow, pow_one] at hf ⊢
exact ⟨0, y, .inl rfl, hf⟩
| prime hq =>
refine ⟨n, y, (em _).imp id fun hn ⟨z, hy⟩ ↦ ?_, hf⟩
haveI := expChar_of_injective_ringHom (R := F) C_injective q
rw [hf, ← Nat.succ_pred hn, pow_succ, pow_mul, ← hy, frobenius_def, map_pow,
← sub_pow_expChar] at hi
exact not_irreducible_pow hq.ne_one hi
/-- If a monic polynomial over a field `F` of exponential characteristic `q` has separable degree
one, then it is of the form `(X ^ (q ^ n) - C y) ^ m` for some non-zero natural number `m`,
some natural number `n`, and some element `y` of `F`, such that either `n = 0` or `y` has no
`q`-th root in `F`. -/
theorem eq_X_pow_char_pow_sub_C_pow_of_natSepDegree_eq_one (q : ℕ) [ExpChar F q] (hm : f.Monic)
(h : f.natSepDegree = 1) : ∃ (m n : ℕ) (y : F),
m ≠ 0 ∧ (n = 0 ∨ y ∉ (frobenius F q).range) ∧ f = (X ^ q ^ n - C y) ^ m := by
obtain ⟨p, hM, hI, hf⟩ := exists_monic_irreducible_factor _ <| not_isUnit_of_natDegree_pos _
<| Nat.pos_of_ne_zero <| (natSepDegree_ne_zero_iff _).1 (h.symm ▸ Nat.one_ne_zero)
have hD := (h ▸ natSepDegree_le_of_dvd p f hf hm.ne_zero).antisymm <|
Nat.pos_of_ne_zero <| (natSepDegree_ne_zero_iff _).2 hI.natDegree_pos.ne'
obtain ⟨n, y, H, hp⟩ := hM.eq_X_pow_char_pow_sub_C_of_natSepDegree_eq_one_of_irreducible q hI hD
have hF := multiplicity_finite_of_degree_pos_of_monic (degree_pos_of_irreducible hI) hM hm.ne_zero
classical
have hne := (multiplicity.pos_of_dvd hF hf).ne'
refine ⟨_, n, y, hne, H, ?_⟩
obtain ⟨c, hf, H⟩ := multiplicity.exists_eq_pow_mul_and_not_dvd hF
rw [hf, natSepDegree_mul_of_isCoprime _ c <| IsCoprime.pow_left <|
(hI.coprime_or_dvd c).resolve_right H, natSepDegree_pow_of_ne_zero _ hne, hD,
add_right_eq_self, natSepDegree_eq_zero_iff] at h
simpa only [eq_one_of_monic_natDegree_zero ((hM.pow _).of_mul_monic_left (hf ▸ hm)) h,
mul_one, ← hp] using hf
/-- A monic polynomial over a field `F` of exponential characteristic `q` has separable degree one
if and only if it is of the form `(X ^ (q ^ n) - C y) ^ m` for some non-zero natural number `m`,
some natural number `n`, and some element `y` of `F`. -/
theorem natSepDegree_eq_one_iff (q : ℕ) [ExpChar F q] (hm : f.Monic) :
f.natSepDegree = 1 ↔ ∃ (m n : ℕ) (y : F), m ≠ 0 ∧ f = (X ^ q ^ n - C y) ^ m := by
refine ⟨fun h ↦ ?_, fun ⟨m, n, y, hm, h⟩ ↦ ?_⟩
· obtain ⟨m, n, y, hm, -, h⟩ := hm.eq_X_pow_char_pow_sub_C_pow_of_natSepDegree_eq_one q h
exact ⟨m, n, y, hm, h⟩
simp_rw [h, natSepDegree_pow, hm, ite_false, natSepDegree_X_pow_char_pow_sub_C]
end Monic
end Polynomial
namespace minpoly
variable {F E}
variable (q : ℕ) [hF : ExpChar F q] {x : E}
/-- The minimal polynomial of an element of `E / F` of exponential characteristic `q` has
separable degree one if and only if the minimal polynomial is of the form
`Polynomial.expand F (q ^ n) (X - C y)` for some `n : ℕ` and `y : F`. -/
theorem natSepDegree_eq_one_iff_eq_expand_X_sub_C : (minpoly F x).natSepDegree = 1 ↔
∃ (n : ℕ) (y : F), minpoly F x = expand F (q ^ n) (X - C y) := by
refine ⟨fun h ↦ ?_, fun ⟨n, y, h⟩ ↦ ?_⟩
· have halg : IsIntegral F x := by_contra fun h' ↦ by
simp only [eq_zero h', natSepDegree_zero, zero_ne_one] at h
exact (minpoly.irreducible halg).natSepDegree_eq_one_iff_of_monic' q
(minpoly.monic halg) |>.1 h
rw [h, natSepDegree_expand _ q, natSepDegree_X_sub_C]
/-- The minimal polynomial of an element of `E / F` of exponential characteristic `q` has
separable degree one if and only if the minimal polynomial is of the form
`X ^ (q ^ n) - C y` for some `n : ℕ` and `y : F`. -/
theorem natSepDegree_eq_one_iff_eq_X_pow_sub_C : (minpoly F x).natSepDegree = 1 ↔
∃ (n : ℕ) (y : F), minpoly F x = X ^ q ^ n - C y := by
simp only [minpoly.natSepDegree_eq_one_iff_eq_expand_X_sub_C q, map_sub, expand_X, expand_C]
/-- The minimal polynomial of an element `x` of `E / F` of exponential characteristic `q` has
separable degree one if and only if `x ^ (q ^ n) ∈ F` for some `n : ℕ`. -/
theorem natSepDegree_eq_one_iff_pow_mem : (minpoly F x).natSepDegree = 1 ↔
∃ n : ℕ, x ^ q ^ n ∈ (algebraMap F E).range := by
convert_to _ ↔ ∃ (n : ℕ) (y : F), Polynomial.aeval x (X ^ q ^ n - C y) = 0
· simp_rw [RingHom.mem_range, map_sub, map_pow, aeval_C, aeval_X, sub_eq_zero, eq_comm]
refine ⟨fun h ↦ ?_, fun ⟨n, y, h⟩ ↦ ?_⟩
· obtain ⟨n, y, hx⟩ := (minpoly.natSepDegree_eq_one_iff_eq_X_pow_sub_C q).1 h
exact ⟨n, y, hx ▸ aeval F x⟩
have hnezero := X_pow_sub_C_ne_zero (expChar_pow_pos F q n) y
refine ((natSepDegree_le_of_dvd _ _ (minpoly.dvd F x h) hnezero).trans_eq <|
natSepDegree_X_pow_char_pow_sub_C q n y).antisymm ?_
rw [Nat.one_le_iff_ne_zero, natSepDegree_ne_zero_iff, ← Nat.one_le_iff_ne_zero]
exact minpoly.natDegree_pos <| IsAlgebraic.isIntegral ⟨_, hnezero, h⟩
/-- The minimal polynomial of an element `x` of `E / F` of exponential characteristic `q` has
separable degree one if and only if the minimal polynomial is of the form
`(X - x) ^ (q ^ n)` for some `n : ℕ`. -/
theorem natSepDegree_eq_one_iff_eq_X_sub_C_pow : (minpoly F x).natSepDegree = 1 ↔
∃ n : ℕ, (minpoly F x).map (algebraMap F E) = (X - C x) ^ q ^ n := by
haveI := expChar_of_injective_algebraMap (algebraMap F E).injective q
haveI := expChar_of_injective_algebraMap (NoZeroSMulDivisors.algebraMap_injective E E[X]) q
refine ⟨fun h ↦ ?_, fun ⟨n, h⟩ ↦ (natSepDegree_eq_one_iff_pow_mem q).2 ?_⟩
· obtain ⟨n, y, h⟩ := (natSepDegree_eq_one_iff_eq_X_pow_sub_C q).1 h
have hx := congr_arg (Polynomial.aeval x) h.symm
rw [minpoly.aeval, map_sub, map_pow, aeval_X, aeval_C, sub_eq_zero, eq_comm] at hx
use n
rw [h, Polynomial.map_sub, Polynomial.map_pow, map_X, map_C, hx, map_pow, ← sub_pow_expChar_pow]
apply_fun constantCoeff at h
simp_rw [map_pow, map_sub, constantCoeff_apply, coeff_map, coeff_X_zero, coeff_C_zero] at h
rw [zero_sub, neg_pow, ExpChar.neg_one_pow_expChar_pow] at h
exact ⟨n, -(minpoly F x).coeff 0, by rw [map_neg, h]; ring1⟩
end minpoly
namespace IntermediateField
/-- The separable degree of `F⟮α⟯ / F` is equal to the separable degree of the
minimal polynomial of `α` over `F`. -/
theorem finSepDegree_adjoin_simple_eq_natSepDegree {α : E} (halg : IsAlgebraic F α) :
finSepDegree F F⟮α⟯ = (minpoly F α).natSepDegree := by
have : finSepDegree F F⟮α⟯ = _ := Nat.card_congr
(algHomAdjoinIntegralEquiv F (K := AlgebraicClosure F⟮α⟯) halg.isIntegral)
classical
rw [this, Nat.card_eq_fintype_card, natSepDegree_eq_of_isAlgClosed (E := AlgebraicClosure F⟮α⟯),
← Fintype.card_coe]
simp_rw [Multiset.mem_toFinset]
-- The separable degree of `F⟮α⟯ / F` divides the degree of `F⟮α⟯ / F`.
-- Marked as `private` because it is a special case of `finSepDegree_dvd_finrank`.
private theorem finSepDegree_adjoin_simple_dvd_finrank (α : E) :
finSepDegree F F⟮α⟯ ∣ finrank F F⟮α⟯ := by
by_cases halg : IsAlgebraic F α
· rw [finSepDegree_adjoin_simple_eq_natSepDegree F E halg, adjoin.finrank halg.isIntegral]
exact (minpoly.irreducible halg.isIntegral).natSepDegree_dvd_natDegree
have : finrank F F⟮α⟯ = 0 := finrank_of_infinite_dimensional fun _ ↦
halg ((AdjoinSimple.isIntegral_gen F α).1 (IsIntegral.of_finite F _)).isAlgebraic
rw [this]
exact dvd_zero _
/-- The separable degree of `F⟮α⟯ / F` is smaller than the degree of `F⟮α⟯ / F` if `α` is
algebraic over `F`. -/
theorem finSepDegree_adjoin_simple_le_finrank (α : E) (halg : IsAlgebraic F α) :
finSepDegree F F⟮α⟯ ≤ finrank F F⟮α⟯ := by
haveI := adjoin.finiteDimensional halg.isIntegral
exact Nat.le_of_dvd finrank_pos <| finSepDegree_adjoin_simple_dvd_finrank F E α
/-- If `α` is algebraic over `F`, then the separable degree of `F⟮α⟯ / F` is equal to the degree
of `F⟮α⟯ / F` if and only if `α` is a separable element. -/
theorem finSepDegree_adjoin_simple_eq_finrank_iff (α : E) (halg : IsAlgebraic F α) :
finSepDegree F F⟮α⟯ = finrank F F⟮α⟯ ↔ IsSeparable F α := by
rw [finSepDegree_adjoin_simple_eq_natSepDegree F E halg, adjoin.finrank halg.isIntegral,
natSepDegree_eq_natDegree_iff _ (minpoly.ne_zero halg.isIntegral), IsSeparable]
end IntermediateField
namespace Field
/-- The separable degree of any field extension `E / F` divides the degree of `E / F`. -/
theorem finSepDegree_dvd_finrank : finSepDegree F E ∣ finrank F E := by
by_cases hfd : FiniteDimensional F E
· rw [← finSepDegree_top F, ← finrank_top F E]
refine induction_on_adjoin (fun K : IntermediateField F E ↦ finSepDegree F K ∣ finrank F K)
(by simp_rw [finSepDegree_bot, IntermediateField.finrank_bot, one_dvd]) (fun L x h ↦ ?_) ⊤
simp only at h ⊢
have hdvd := mul_dvd_mul h <| finSepDegree_adjoin_simple_dvd_finrank L E x
set M := L⟮x⟯
have := Algebra.IsAlgebraic.of_finite L M
rwa [finSepDegree_mul_finSepDegree_of_isAlgebraic F L M,
FiniteDimensional.finrank_mul_finrank F L M] at hdvd
rw [finrank_of_infinite_dimensional hfd]
exact dvd_zero _
/-- The separable degree of a finite extension `E / F` is smaller than the degree of `E / F`. -/
theorem finSepDegree_le_finrank [FiniteDimensional F E] :
finSepDegree F E ≤ finrank F E := Nat.le_of_dvd finrank_pos <| finSepDegree_dvd_finrank F E
/-- If `E / F` is a separable extension, then its separable degree is equal to its degree.
When `E / F` is infinite, it means that `Field.Emb F E` has infinitely many elements.
(But the cardinality of `Field.Emb F E` is not equal to `Module.rank F E` in general!) -/
theorem finSepDegree_eq_finrank_of_isSeparable [Algebra.IsSeparable F E] :
finSepDegree F E = finrank F E := by
wlog hfd : FiniteDimensional F E generalizing E with H
· rw [finrank_of_infinite_dimensional hfd]
have halg := Algebra.IsSeparable.isAlgebraic F E
obtain ⟨L, h, h'⟩ := exists_lt_finrank_of_infinite_dimensional hfd (finSepDegree F E)
have : Algebra.IsSeparable F L := Algebra.isSeparable_tower_bot_of_isSeparable F L E
have := (halg.tower_top L)
have hd := finSepDegree_mul_finSepDegree_of_isAlgebraic F L E
rw [H L h] at hd
by_cases hd' : finSepDegree L E = 0
· rw [← hd, hd', mul_zero]
linarith only [h', hd, Nat.le_mul_of_pos_right (finrank F L) (Nat.pos_of_ne_zero hd')]
rw [← finSepDegree_top F, ← finrank_top F E]
refine induction_on_adjoin (fun K : IntermediateField F E ↦ finSepDegree F K = finrank F K)
(by simp_rw [finSepDegree_bot, IntermediateField.finrank_bot]) (fun L x h ↦ ?_) ⊤
simp only at h ⊢
have heq : _ * _ = _ * _ := congr_arg₂ (· * ·) h <|
(finSepDegree_adjoin_simple_eq_finrank_iff L E x (IsAlgebraic.of_finite L x)).2 <|
IsSeparable.of_isScalarTower L (Algebra.IsSeparable.isSeparable F x)
set M := L⟮x⟯
have := Algebra.IsAlgebraic.of_finite L M
rwa [finSepDegree_mul_finSepDegree_of_isAlgebraic F L M,
FiniteDimensional.finrank_mul_finrank F L M] at heq
alias Algebra.IsSeparable.finSepDegree_eq := finSepDegree_eq_finrank_of_isSeparable
/-- If `E / F` is a finite extension, then its separable degree is equal to its degree if and
only if it is a separable extension. -/
theorem finSepDegree_eq_finrank_iff [FiniteDimensional F E] :
finSepDegree F E = finrank F E ↔ Algebra.IsSeparable F E :=
⟨fun heq ↦ ⟨fun x ↦ by
have halg := IsAlgebraic.of_finite F x
refine (finSepDegree_adjoin_simple_eq_finrank_iff F E x halg).1 <| le_antisymm
(finSepDegree_adjoin_simple_le_finrank F E x halg) <| le_of_not_lt fun h ↦ ?_
have := Nat.mul_lt_mul_of_lt_of_le' h (finSepDegree_le_finrank F⟮x⟯ E) Fin.size_pos'
rw [finSepDegree_mul_finSepDegree_of_isAlgebraic F F⟮x⟯ E,
FiniteDimensional.finrank_mul_finrank F F⟮x⟯ E] at this
linarith only [heq, this]⟩, fun _ ↦ finSepDegree_eq_finrank_of_isSeparable F E⟩
end Field
lemma IntermediateField.isSeparable_of_mem_isSeparable {L : IntermediateField F E}
[Algebra.IsSeparable F L] {x : E} (h : x ∈ L) : IsSeparable F x := by
simpa only [IsSeparable, minpoly_eq] using Algebra.IsSeparable.isSeparable F (K := L) ⟨x, h⟩
/-- `F⟮x⟯ / F` is a separable extension if and only if `x` is a separable element.
As a consequence, any rational function of `x` is also a separable element. -/
theorem IntermediateField.isSeparable_adjoin_simple_iff_isSeparable {x : E} :
Algebra.IsSeparable F F⟮x⟯ ↔ IsSeparable F x := by
refine ⟨fun _ ↦ ?_, fun hsep ↦ ?_⟩
· exact isSeparable_of_mem_isSeparable F E <| mem_adjoin_simple_self F x
· have h := IsSeparable.isIntegral hsep
haveI := adjoin.finiteDimensional h
rwa [← finSepDegree_eq_finrank_iff,
finSepDegree_adjoin_simple_eq_finrank_iff F E x h.isAlgebraic]
variable {E K} in
/-- If `K / E / F` is an extension tower such that `E / F` is separable,
`x : K` is separable over `E`, then it's also separable over `F`. -/
theorem IsSeparable.of_algebra_isSeparable_of_isSeparable [Algebra E K] [IsScalarTower F E K]
[Algebra.IsSeparable F E] {x : K} (hsep : IsSeparable E x) : IsSeparable F x := by
set f := minpoly E x with hf
let E' : IntermediateField F E := adjoin F f.coeffs
haveI : FiniteDimensional F E' :=
finiteDimensional_adjoin fun x _ ↦ Algebra.IsSeparable.isIntegral F x
let g : E'[X] := f.toSubring E'.toSubring (subset_adjoin F _)
have h : g.map (algebraMap E' E) = f := f.map_toSubring E'.toSubring (subset_adjoin F _)
clear_value g
have hx : x ∈ restrictScalars F E'⟮x⟯ := mem_adjoin_simple_self _ x
have hzero : aeval x g = 0 := by
simpa only [← hf, ← h, aeval_map_algebraMap] using minpoly.aeval E x
have halg : IsIntegral E' x :=
isIntegral_trans (R := F) (A := E) _ (IsSeparable.isIntegral hsep) |>.tower_top
simp only [IsSeparable, ← hf, ← h, separable_map] at hsep
replace hsep := hsep.of_dvd <| minpoly.dvd E' x hzero
haveI : Algebra.IsSeparable F E' := Algebra.isSeparable_tower_bot_of_isSeparable F E' E
haveI := (isSeparable_adjoin_simple_iff_isSeparable _ _).2 hsep
haveI := adjoin.finiteDimensional halg
haveI : FiniteDimensional F E'⟮x⟯ := FiniteDimensional.trans F E' E'⟮x⟯
have : Algebra.IsAlgebraic E' E'⟮x⟯ := Algebra.IsSeparable.isAlgebraic _ _
have := finSepDegree_mul_finSepDegree_of_isAlgebraic F E' E'⟮x⟯
rw [finSepDegree_eq_finrank_of_isSeparable F E',
finSepDegree_eq_finrank_of_isSeparable E' E'⟮x⟯,
FiniteDimensional.finrank_mul_finrank F E' E'⟮x⟯,
eq_comm, finSepDegree_eq_finrank_iff F E'⟮x⟯] at this
change Algebra.IsSeparable F (restrictScalars F E'⟮x⟯) at this
exact isSeparable_of_mem_isSeparable F K hx
/-- If `E / F` and `K / E` are both separable extensions, then `K / F` is also separable. -/
theorem Algebra.IsSeparable.trans [Algebra E K] [IsScalarTower F E K]
[Algebra.IsSeparable F E] [Algebra.IsSeparable E K] : Algebra.IsSeparable F K :=
⟨fun x ↦ IsSeparable.of_algebra_isSeparable_of_isSeparable F
(Algebra.IsSeparable.isSeparable E x)⟩
/-- If `x` and `y` are both separable elements, then `F⟮x, y⟯ / F` is a separable extension.
As a consequence, any rational function of `x` and `y` is also a separable element. -/
theorem IntermediateField.isSeparable_adjoin_pair_of_isSeparable {x y : E}
(hx : IsSeparable F x) (hy : IsSeparable F y) :
Algebra.IsSeparable F F⟮x, y⟯ := by
rw [← adjoin_simple_adjoin_simple]
replace hy := IsSeparable.of_isScalarTower F⟮x⟯ hy
rw [← isSeparable_adjoin_simple_iff_isSeparable] at hx hy
exact Algebra.IsSeparable.trans F F⟮x⟯ F⟮x⟯⟮y⟯
namespace Field
variable {F}
/-- Any element `x` of `F` is a separable element of `E / F` when embedded into `E`. -/
theorem isSeparable_algebraMap (x : F) : IsSeparable F ((algebraMap F E) x) := by
rw [IsSeparable, minpoly.algebraMap_eq (algebraMap F E).injective]
exact Algebra.IsSeparable.isSeparable F x
variable {E}
/-- If `x` and `y` are both separable elements, then `x * y` is also a separable element. -/
theorem isSeparable_mul {x y : E} (hx : IsSeparable F x) (hy : IsSeparable F y) :
IsSeparable F (x * y) :=
haveI := isSeparable_adjoin_pair_of_isSeparable F E hx hy
isSeparable_of_mem_isSeparable F E <| F⟮x, y⟯.mul_mem (subset_adjoin F _ (.inl rfl))
(subset_adjoin F _ (.inr rfl))
/-- If `x` and `y` are both separable elements, then `x + y` is also a separable element. -/
theorem isSeparable_add {x y : E} (hx : IsSeparable F x) (hy : IsSeparable F y) :
IsSeparable F (x + y) :=
haveI := isSeparable_adjoin_pair_of_isSeparable F E hx hy
isSeparable_of_mem_isSeparable F E <| F⟮x, y⟯.add_mem (subset_adjoin F _ (.inl rfl))
(subset_adjoin F _ (.inr rfl))
/-- If `x` is a separable element, then `x⁻¹` is also a separable element. -/
theorem isSeparable_inv {x : E} (hx : IsSeparable F x) : IsSeparable F x⁻¹ :=
haveI := (isSeparable_adjoin_simple_iff_isSeparable F E).2 hx
isSeparable_of_mem_isSeparable F E <| F⟮x⟯.inv_mem <| mem_adjoin_simple_self F x
end Field
/-- A field is a perfect field (which means that any irreducible polynomial is separable)
if and only if every separable degree one polynomial splits. -/
theorem perfectField_iff_splits_of_natSepDegree_eq_one (F : Type*) [Field F] :
PerfectField F ↔ ∀ f : F[X], f.natSepDegree = 1 → f.Splits (RingHom.id F) := by
refine ⟨fun ⟨h⟩ f hf ↦ or_iff_not_imp_left.2 fun hn g hg hd ↦ ?_, fun h ↦ ?_⟩
· rw [map_id] at hn hd
have := natSepDegree_le_of_dvd g f hd hn
rw [hf, (h hg).natSepDegree_eq_natDegree] at this
exact (degree_eq_iff_natDegree_eq_of_pos one_pos).2 <| this.antisymm <|
natDegree_pos_iff_degree_pos.2 (degree_pos_of_irreducible hg)
obtain ⟨p, _⟩ := ExpChar.exists F
haveI := PerfectRing.ofSurjective F p fun x ↦ by
obtain ⟨y, hy⟩ := exists_root_of_splits _
(h _ (pow_one p ▸ natSepDegree_X_pow_char_pow_sub_C p 1 x))
((degree_X_pow_sub_C (expChar_pos F p) x).symm ▸ Nat.cast_pos.2 (expChar_pos F p)).ne'
exact ⟨y, by rwa [← eval, eval_sub, eval_pow, eval_X, eval_C, sub_eq_zero] at hy⟩
exact PerfectRing.toPerfectField F p
|
FieldTheory\Tower.lean | /-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Data.Nat.Prime.Defs
import Mathlib.RingTheory.AlgebraTower
import Mathlib.LinearAlgebra.FiniteDimensional.Defs
import Mathlib.LinearAlgebra.FreeModule.Finite.Matrix
import Mathlib.RingTheory.LocalRing.Basic
/-!
# Tower of field extensions
In this file we prove the tower law for arbitrary extensions and finite extensions.
Suppose `L` is a field extension of `K` and `K` is a field extension of `F`.
Then `[L:F] = [L:K] [K:F]` where `[E₁:E₂]` means the `E₂`-dimension of `E₁`.
In fact we generalize it to rings and modules, where `L` is not necessarily a field,
but just a free module over `K`.
## Implementation notes
We prove two versions, since there are two notions of dimensions: `Module.rank` which gives
the dimension of an arbitrary vector space as a cardinal, and `FiniteDimensional.finrank` which
gives the dimension of a finite-dimensional vector space as a natural number.
## Tags
tower law
-/
universe u v w u₁ v₁ w₁
open Cardinal Submodule
variable (F : Type u) (K : Type v) (A : Type w)
section Field
variable [DivisionRing F] [DivisionRing K] [AddCommGroup A]
variable [Module F K] [Module K A] [Module F A] [IsScalarTower F K A]
namespace FiniteDimensional
open IsNoetherian
/-- In a tower of field extensions `A / K / F`, if `A / F` is finite, so is `K / F`.
(In fact, it suffices that `A` is a nontrivial ring.)
Note this cannot be an instance as Lean cannot infer `A`.
-/
theorem left [Nontrivial A] [FiniteDimensional F A] : FiniteDimensional F K :=
let ⟨x, hx⟩ := exists_ne (0 : A)
FiniteDimensional.of_injective
(LinearMap.ringLmapEquivSelf K ℕ A |>.symm x |>.restrictScalars F) (smul_left_injective K hx)
theorem right [hf : FiniteDimensional F A] : FiniteDimensional K A :=
let ⟨⟨b, hb⟩⟩ := hf
⟨⟨b, Submodule.restrictScalars_injective F _ _ <| by
rw [Submodule.restrictScalars_top, eq_top_iff, ← hb, Submodule.span_le]
exact Submodule.subset_span⟩⟩
theorem Subalgebra.isSimpleOrder_of_finrank_prime (F A) [Field F] [Ring A] [IsDomain A]
[Algebra F A] (hp : (finrank F A).Prime) : IsSimpleOrder (Subalgebra F A) :=
{ toNontrivial :=
⟨⟨⊥, ⊤, fun he =>
Nat.not_prime_one ((Subalgebra.bot_eq_top_iff_finrank_eq_one.1 he).subst hp)⟩⟩
eq_bot_or_eq_top := fun K => by
haveI : FiniteDimensional _ _ := .of_finrank_pos hp.pos
letI := divisionRingOfFiniteDimensional F K
refine (hp.eq_one_or_self_of_dvd _ ⟨_, (finrank_mul_finrank F K A).symm⟩).imp ?_ fun h => ?_
· exact fun h' => Subalgebra.eq_bot_of_finrank_one h'
· exact
Algebra.toSubmodule_eq_top.1 (eq_top_of_finrank_eq <| K.finrank_toSubmodule.trans h) }
-- TODO: `IntermediateField` version
@[deprecated (since := "2024-01-12")]
alias finrank_linear_map' := FiniteDimensional.finrank_linearMap_self
end FiniteDimensional
end Field
|
FieldTheory\Finite\Basic.lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Joey van Langen, Casper Putz
-/
import Mathlib.FieldTheory.Separable
import Mathlib.RingTheory.IntegralDomain
import Mathlib.Algebra.CharP.Reduced
import Mathlib.Tactic.ApplyFun
/-!
# Finite fields
This file contains basic results about finite fields.
Throughout most of this file, `K` denotes a finite field
and `q` is notation for the cardinality of `K`.
See `RingTheory.IntegralDomain` for the fact that the unit group of a finite field is a
cyclic group, as well as the fact that every finite integral domain is a field
(`Fintype.fieldOfDomain`).
## Main results
1. `Fintype.card_units`: The unit group of a finite field has cardinality `q - 1`.
2. `sum_pow_units`: The sum of `x^i`, where `x` ranges over the units of `K`, is
- `q-1` if `q-1 ∣ i`
- `0` otherwise
3. `FiniteField.card`: The cardinality `q` is a power of the characteristic of `K`.
See `FiniteField.card'` for a variant.
## Notation
Throughout most of this file, `K` denotes a finite field
and `q` is notation for the cardinality of `K`.
## Implementation notes
While `Fintype Kˣ` can be inferred from `Fintype K` in the presence of `DecidableEq K`,
in this file we take the `Fintype Kˣ` argument directly to reduce the chance of typeclass
diamonds, as `Fintype` carries data.
-/
variable {K : Type*} {R : Type*}
local notation "q" => Fintype.card K
open Finset
open scoped Polynomial
namespace FiniteField
section Polynomial
variable [CommRing R] [IsDomain R]
open Polynomial
/-- The cardinality of a field is at most `n` times the cardinality of the image of a degree `n`
polynomial -/
theorem card_image_polynomial_eval [DecidableEq R] [Fintype R] {p : R[X]} (hp : 0 < p.degree) :
Fintype.card R ≤ natDegree p * (univ.image fun x => eval x p).card :=
Finset.card_le_mul_card_image _ _ (fun a _ =>
calc
_ = (p - C a).roots.toFinset.card :=
congr_arg card (by simp [Finset.ext_iff, ← mem_roots_sub_C hp])
_ ≤ Multiset.card (p - C a).roots := Multiset.toFinset_card_le _
_ ≤ _ := card_roots_sub_C' hp)
/-- If `f` and `g` are quadratic polynomials, then the `f.eval a + g.eval b = 0` has a solution. -/
theorem exists_root_sum_quadratic [Fintype R] {f g : R[X]} (hf2 : degree f = 2) (hg2 : degree g = 2)
(hR : Fintype.card R % 2 = 1) : ∃ a b, f.eval a + g.eval b = 0 :=
letI := Classical.decEq R
suffices ¬Disjoint (univ.image fun x : R => eval x f)
(univ.image fun x : R => eval x (-g)) by
simp only [disjoint_left, mem_image] at this
push_neg at this
rcases this with ⟨x, ⟨a, _, ha⟩, ⟨b, _, hb⟩⟩
exact ⟨a, b, by rw [ha, ← hb, eval_neg, neg_add_self]⟩
fun hd : Disjoint _ _ =>
lt_irrefl (2 * ((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g)).card) <|
calc 2 * ((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g)).card
≤ 2 * Fintype.card R := Nat.mul_le_mul_left _ (Finset.card_le_univ _)
_ = Fintype.card R + Fintype.card R := two_mul _
_ < natDegree f * (univ.image fun x : R => eval x f).card +
natDegree (-g) * (univ.image fun x : R => eval x (-g)).card :=
(add_lt_add_of_lt_of_le
(lt_of_le_of_ne (card_image_polynomial_eval (by rw [hf2]; decide))
(mt (congr_arg (· % 2)) (by simp [natDegree_eq_of_degree_eq_some hf2, hR])))
(card_image_polynomial_eval (by rw [degree_neg, hg2]; decide)))
_ = 2 * ((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g)).card := by
rw [card_union_of_disjoint hd]
simp [natDegree_eq_of_degree_eq_some hf2, natDegree_eq_of_degree_eq_some hg2, mul_add]
end Polynomial
theorem prod_univ_units_id_eq_neg_one [CommRing K] [IsDomain K] [Fintype Kˣ] :
∏ x : Kˣ, x = (-1 : Kˣ) := by
classical
have : (∏ x ∈ (@univ Kˣ _).erase (-1), x) = 1 :=
prod_involution (fun x _ => x⁻¹) (by simp)
(fun a => by simp (config := { contextual := true }) [Units.inv_eq_self_iff])
(fun a => by simp [@inv_eq_iff_eq_inv _ _ a]) (by simp)
rw [← insert_erase (mem_univ (-1 : Kˣ)), prod_insert (not_mem_erase _ _), this, mul_one]
theorem card_cast_subgroup_card_ne_zero [Ring K] [NoZeroDivisors K] [Nontrivial K]
(G : Subgroup Kˣ) [Fintype G] : (Fintype.card G : K) ≠ 0 := by
let n := Fintype.card G
intro nzero
have ⟨p, char_p⟩ := CharP.exists K
have hd : p ∣ n := (CharP.cast_eq_zero_iff K p n).mp nzero
cases CharP.char_is_prime_or_zero K p with
| inr pzero =>
exact (Fintype.card_pos).ne' <| Nat.eq_zero_of_zero_dvd <| pzero ▸ hd
| inl pprime =>
have fact_pprime := Fact.mk pprime
-- G has an element x of order p by Cauchy's theorem
have ⟨x, hx⟩ := exists_prime_orderOf_dvd_card p hd
-- F has an element u (= ↑↑x) of order p
let u := ((x : Kˣ) : K)
have hu : orderOf u = p := by rwa [orderOf_units, Subgroup.orderOf_coe]
-- u ^ p = 1 implies (u - 1) ^ p = 0 and hence u = 1 ...
have h : u = 1 := by
rw [← sub_left_inj, sub_self 1]
apply pow_eq_zero (n := p)
rw [sub_pow_char_of_commute, one_pow, ← hu, pow_orderOf_eq_one, sub_self]
exact Commute.one_right u
-- ... meaning x didn't have order p after all, contradiction
apply pprime.one_lt.ne
rw [← hu, h, orderOf_one]
/-- The sum of a nontrivial subgroup of the units of a field is zero. -/
theorem sum_subgroup_units_eq_zero [Ring K] [NoZeroDivisors K]
{G : Subgroup Kˣ} [Fintype G] (hg : G ≠ ⊥) :
∑ x : G, (x.val : K) = 0 := by
rw [Subgroup.ne_bot_iff_exists_ne_one] at hg
rcases hg with ⟨a, ha⟩
-- The action of a on G as an embedding
let a_mul_emb : G ↪ G := mulLeftEmbedding a
-- ... and leaves G unchanged
have h_unchanged : Finset.univ.map a_mul_emb = Finset.univ := by simp
-- Therefore the sum of x over a G is the sum of a x over G
have h_sum_map := Finset.univ.sum_map a_mul_emb fun x => ((x : Kˣ) : K)
-- ... and the former is the sum of x over G.
-- By algebraic manipulation, we have Σ G, x = ∑ G, a x = a ∑ G, x
simp only [a_mul_emb, h_unchanged, Function.Embedding.coeFn_mk, Function.Embedding.toFun_eq_coe,
mulLeftEmbedding_apply, Submonoid.coe_mul, Subgroup.coe_toSubmonoid, Units.val_mul,
← Finset.mul_sum] at h_sum_map
-- thus one of (a - 1) or ∑ G, x is zero
have hzero : (((a : Kˣ) : K) - 1) = 0 ∨ ∑ x : ↥G, ((x : Kˣ) : K) = 0 := by
rw [← mul_eq_zero, sub_mul, ← h_sum_map, one_mul, sub_self]
apply Or.resolve_left hzero
contrapose! ha
ext
rwa [← sub_eq_zero]
/-- The sum of a subgroup of the units of a field is 1 if the subgroup is trivial and 1 otherwise -/
@[simp]
theorem sum_subgroup_units [Ring K] [NoZeroDivisors K]
{G : Subgroup Kˣ} [Fintype G] [Decidable (G = ⊥)] :
∑ x : G, (x.val : K) = if G = ⊥ then 1 else 0 := by
by_cases G_bot : G = ⊥
· subst G_bot
simp only [ite_true, Subgroup.mem_bot, Fintype.card_ofSubsingleton, Nat.cast_ite, Nat.cast_one,
Nat.cast_zero, univ_unique, Set.default_coe_singleton, sum_singleton, Units.val_one]
· simp only [G_bot, ite_false]
exact sum_subgroup_units_eq_zero G_bot
@[simp]
theorem sum_subgroup_pow_eq_zero [CommRing K] [NoZeroDivisors K]
{G : Subgroup Kˣ} [Fintype G] {k : ℕ} (k_pos : k ≠ 0) (k_lt_card_G : k < Fintype.card G) :
∑ x : G, ((x : Kˣ) : K) ^ k = 0 := by
nontriviality K
have := NoZeroDivisors.to_isDomain K
rcases (exists_pow_ne_one_of_isCyclic k_pos k_lt_card_G) with ⟨a, ha⟩
rw [Finset.sum_eq_multiset_sum]
have h_multiset_map :
Finset.univ.val.map (fun x : G => ((x : Kˣ) : K) ^ k) =
Finset.univ.val.map (fun x : G => ((x : Kˣ) : K) ^ k * ((a : Kˣ) : K) ^ k) := by
simp_rw [← mul_pow]
have as_comp :
(fun x : ↥G => (((x : Kˣ) : K) * ((a : Kˣ) : K)) ^ k)
= (fun x : ↥G => ((x : Kˣ) : K) ^ k) ∘ fun x : ↥G => x * a := by
funext x
simp only [Function.comp_apply, Submonoid.coe_mul, Subgroup.coe_toSubmonoid, Units.val_mul]
rw [as_comp, ← Multiset.map_map]
congr
rw [eq_comm]
exact Multiset.map_univ_val_equiv (Equiv.mulRight a)
have h_multiset_map_sum : (Multiset.map (fun x : G => ((x : Kˣ) : K) ^ k) Finset.univ.val).sum =
(Multiset.map (fun x : G => ((x : Kˣ) : K) ^ k * ((a : Kˣ) : K) ^ k) Finset.univ.val).sum := by
rw [h_multiset_map]
rw [Multiset.sum_map_mul_right] at h_multiset_map_sum
have hzero : (((a : Kˣ) : K) ^ k - 1 : K)
* (Multiset.map (fun i : G => (i.val : K) ^ k) Finset.univ.val).sum = 0 := by
rw [sub_mul, mul_comm, ← h_multiset_map_sum, one_mul, sub_self]
rw [mul_eq_zero] at hzero
refine hzero.resolve_left fun h => ha ?_
ext
rw [← sub_eq_zero]
simp_rw [SubmonoidClass.coe_pow, Units.val_pow_eq_pow_val, OneMemClass.coe_one, Units.val_one, h]
section
variable [GroupWithZero K] [Fintype K]
theorem pow_card_sub_one_eq_one (a : K) (ha : a ≠ 0) : a ^ (q - 1) = 1 := by
calc
a ^ (Fintype.card K - 1) = (Units.mk0 a ha ^ (Fintype.card K - 1) : Kˣ).1 := by
rw [Units.val_pow_eq_pow_val, Units.val_mk0]
_ = 1 := by
classical
rw [← Fintype.card_units, pow_card_eq_one]
rfl
theorem pow_card (a : K) : a ^ q = a := by
by_cases h : a = 0; · rw [h]; apply zero_pow Fintype.card_ne_zero
rw [← Nat.succ_pred_eq_of_pos Fintype.card_pos, pow_succ, Nat.pred_eq_sub_one,
pow_card_sub_one_eq_one a h, one_mul]
theorem pow_card_pow (n : ℕ) (a : K) : a ^ q ^ n = a := by
induction' n with n ih
· simp
· simp [pow_succ, pow_mul, ih, pow_card]
end
variable (K) [Field K] [Fintype K]
theorem card (p : ℕ) [CharP K p] : ∃ n : ℕ+, Nat.Prime p ∧ q = p ^ (n : ℕ) := by
haveI hp : Fact p.Prime := ⟨CharP.char_is_prime K p⟩
letI : Module (ZMod p) K := { (ZMod.castHom dvd_rfl K : ZMod p →+* _).toModule with }
obtain ⟨n, h⟩ := VectorSpace.card_fintype (ZMod p) K
rw [ZMod.card] at h
refine ⟨⟨n, ?_⟩, hp.1, h⟩
apply Or.resolve_left (Nat.eq_zero_or_pos n)
rintro rfl
rw [pow_zero] at h
have : (0 : K) = 1 := by apply Fintype.card_le_one_iff.mp (le_of_eq h)
exact absurd this zero_ne_one
-- this statement doesn't use `q` because we want `K` to be an explicit parameter
theorem card' : ∃ (p : ℕ) (n : ℕ+), Nat.Prime p ∧ Fintype.card K = p ^ (n : ℕ) :=
let ⟨p, hc⟩ := CharP.exists K
⟨p, @FiniteField.card K _ _ p hc⟩
-- Porting note: this was a `simp` lemma with a 5 lines proof.
theorem cast_card_eq_zero : (q : K) = 0 := by
simp
theorem forall_pow_eq_one_iff (i : ℕ) : (∀ x : Kˣ, x ^ i = 1) ↔ q - 1 ∣ i := by
classical
obtain ⟨x, hx⟩ := IsCyclic.exists_generator (α := Kˣ)
rw [← Fintype.card_units, ← orderOf_eq_card_of_forall_mem_zpowers hx,
orderOf_dvd_iff_pow_eq_one]
constructor
· intro h; apply h
· intro h y
simp_rw [← mem_powers_iff_mem_zpowers] at hx
rcases hx y with ⟨j, rfl⟩
rw [← pow_mul, mul_comm, pow_mul, h, one_pow]
/-- The sum of `x ^ i` as `x` ranges over the units of a finite field of cardinality `q`
is equal to `0` unless `(q - 1) ∣ i`, in which case the sum is `q - 1`. -/
theorem sum_pow_units [DecidableEq K] (i : ℕ) :
(∑ x : Kˣ, (x ^ i : K)) = if q - 1 ∣ i then -1 else 0 := by
let φ : Kˣ →* K :=
{ toFun := fun x => x ^ i
map_one' := by simp
map_mul' := by intros; simp [mul_pow] }
have : Decidable (φ = 1) := by classical infer_instance
calc (∑ x : Kˣ, φ x) = if φ = 1 then Fintype.card Kˣ else 0 := sum_hom_units φ
_ = if q - 1 ∣ i then -1 else 0 := by
suffices q - 1 ∣ i ↔ φ = 1 by
simp only [this]
split_ifs; swap
· exact Nat.cast_zero
· rw [Fintype.card_units, Nat.cast_sub,
cast_card_eq_zero, Nat.cast_one, zero_sub]
show 1 ≤ q; exact Fintype.card_pos_iff.mpr ⟨0⟩
rw [← forall_pow_eq_one_iff, DFunLike.ext_iff]
apply forall_congr'; intro x; simp [φ, Units.ext_iff]
/-- The sum of `x ^ i` as `x` ranges over a finite field of cardinality `q`
is equal to `0` if `i < q - 1`. -/
theorem sum_pow_lt_card_sub_one (i : ℕ) (h : i < q - 1) : ∑ x : K, x ^ i = 0 := by
by_cases hi : i = 0
· simp only [hi, nsmul_one, sum_const, pow_zero, card_univ, cast_card_eq_zero]
classical
have hiq : ¬q - 1 ∣ i := by contrapose! h; exact Nat.le_of_dvd (Nat.pos_of_ne_zero hi) h
let φ : Kˣ ↪ K := ⟨fun x ↦ x, Units.ext⟩
have : univ.map φ = univ \ {0} := by
ext x
simpa only [mem_map, mem_univ, Function.Embedding.coeFn_mk, true_and_iff, mem_sdiff,
mem_singleton, φ] using isUnit_iff_ne_zero
calc
∑ x : K, x ^ i = ∑ x ∈ univ \ {(0 : K)}, x ^ i := by
rw [← sum_sdiff ({0} : Finset K).subset_univ, sum_singleton, zero_pow hi, add_zero]
_ = ∑ x : Kˣ, (x ^ i : K) := by simp [φ, ← this, univ.sum_map φ]
_ = 0 := by rw [sum_pow_units K i, if_neg]; exact hiq
open Polynomial
section
variable (K' : Type*) [Field K'] {p n : ℕ}
theorem X_pow_card_sub_X_natDegree_eq (hp : 1 < p) : (X ^ p - X : K'[X]).natDegree = p := by
have h1 : (X : K'[X]).degree < (X ^ p : K'[X]).degree := by
rw [degree_X_pow, degree_X]
exact mod_cast hp
rw [natDegree_eq_of_degree_eq (degree_sub_eq_left_of_degree_lt h1), natDegree_X_pow]
theorem X_pow_card_pow_sub_X_natDegree_eq (hn : n ≠ 0) (hp : 1 < p) :
(X ^ p ^ n - X : K'[X]).natDegree = p ^ n :=
X_pow_card_sub_X_natDegree_eq K' <| Nat.one_lt_pow hn hp
theorem X_pow_card_sub_X_ne_zero (hp : 1 < p) : (X ^ p - X : K'[X]) ≠ 0 :=
ne_zero_of_natDegree_gt <|
calc
1 < _ := hp
_ = _ := (X_pow_card_sub_X_natDegree_eq K' hp).symm
theorem X_pow_card_pow_sub_X_ne_zero (hn : n ≠ 0) (hp : 1 < p) : (X ^ p ^ n - X : K'[X]) ≠ 0 :=
X_pow_card_sub_X_ne_zero K' <| Nat.one_lt_pow hn hp
end
variable (p : ℕ) [Fact p.Prime] [Algebra (ZMod p) K]
theorem roots_X_pow_card_sub_X : roots (X ^ q - X : K[X]) = Finset.univ.val := by
classical
have aux : (X ^ q - X : K[X]) ≠ 0 := X_pow_card_sub_X_ne_zero K Fintype.one_lt_card
have : (roots (X ^ q - X : K[X])).toFinset = Finset.univ := by
rw [eq_univ_iff_forall]
intro x
rw [Multiset.mem_toFinset, mem_roots aux, IsRoot.def, eval_sub, eval_pow, eval_X,
sub_eq_zero, pow_card]
rw [← this, Multiset.toFinset_val, eq_comm, Multiset.dedup_eq_self]
apply nodup_roots
rw [separable_def]
convert isCoprime_one_right.neg_right (R := K[X]) using 1
rw [derivative_sub, derivative_X, derivative_X_pow, Nat.cast_card_eq_zero K, C_0,
zero_mul, zero_sub]
variable {K}
theorem frobenius_pow {p : ℕ} [Fact p.Prime] [CharP K p] {n : ℕ} (hcard : q = p ^ n) :
frobenius K p ^ n = 1 := by
ext x; conv_rhs => rw [RingHom.one_def, RingHom.id_apply, ← pow_card x, hcard]
clear hcard
induction' n with n hn
· simp
· rw [pow_succ', pow_succ, pow_mul, RingHom.mul_def, RingHom.comp_apply, frobenius_def, hn]
open Polynomial
theorem expand_card (f : K[X]) : expand K q f = f ^ q := by
cases' CharP.exists K with p hp
letI := hp
rcases FiniteField.card K p with ⟨⟨n, npos⟩, ⟨hp, hn⟩⟩
haveI : Fact p.Prime := ⟨hp⟩
dsimp at hn
rw [hn, ← map_expand_pow_char, frobenius_pow hn, RingHom.one_def, map_id]
end FiniteField
namespace ZMod
open FiniteField Polynomial
theorem sq_add_sq (p : ℕ) [hp : Fact p.Prime] (x : ZMod p) : ∃ a b : ZMod p, a ^ 2 + b ^ 2 = x := by
cases' hp.1.eq_two_or_odd with hp2 hp_odd
· subst p
change Fin 2 at x
fin_cases x
· use 0; simp
· use 0, 1; simp
let f : (ZMod p)[X] := X ^ 2
let g : (ZMod p)[X] := X ^ 2 - C x
obtain ⟨a, b, hab⟩ : ∃ a b, f.eval a + g.eval b = 0 :=
@exists_root_sum_quadratic _ _ _ _ f g (degree_X_pow 2) (degree_X_pow_sub_C (by decide) _)
(by rw [ZMod.card, hp_odd])
refine ⟨a, b, ?_⟩
rw [← sub_eq_zero]
simpa only [f, g, eval_C, eval_X, eval_pow, eval_sub, ← add_sub_assoc] using hab
end ZMod
/-- If `p` is a prime natural number and `x` is an integer number, then there exist natural numbers
`a ≤ p / 2` and `b ≤ p / 2` such that `a ^ 2 + b ^ 2 ≡ x [ZMOD p]`. This is a version of
`ZMod.sq_add_sq` with estimates on `a` and `b`. -/
theorem Nat.sq_add_sq_zmodEq (p : ℕ) [Fact p.Prime] (x : ℤ) :
∃ a b : ℕ, a ≤ p / 2 ∧ b ≤ p / 2 ∧ (a : ℤ) ^ 2 + (b : ℤ) ^ 2 ≡ x [ZMOD p] := by
rcases ZMod.sq_add_sq p x with ⟨a, b, hx⟩
refine ⟨a.valMinAbs.natAbs, b.valMinAbs.natAbs, ZMod.natAbs_valMinAbs_le _,
ZMod.natAbs_valMinAbs_le _, ?_⟩
rw [← a.coe_valMinAbs, ← b.coe_valMinAbs] at hx
push_cast
rw [sq_abs, sq_abs, ← ZMod.intCast_eq_intCast_iff]
exact mod_cast hx
/-- If `p` is a prime natural number and `x` is a natural number, then there exist natural numbers
`a ≤ p / 2` and `b ≤ p / 2` such that `a ^ 2 + b ^ 2 ≡ x [MOD p]`. This is a version of
`ZMod.sq_add_sq` with estimates on `a` and `b`. -/
theorem Nat.sq_add_sq_modEq (p : ℕ) [Fact p.Prime] (x : ℕ) :
∃ a b : ℕ, a ≤ p / 2 ∧ b ≤ p / 2 ∧ a ^ 2 + b ^ 2 ≡ x [MOD p] := by
simpa only [← Int.natCast_modEq_iff] using Nat.sq_add_sq_zmodEq p x
namespace CharP
theorem sq_add_sq (R : Type*) [CommRing R] [IsDomain R] (p : ℕ) [NeZero p] [CharP R p] (x : ℤ) :
∃ a b : ℕ, ((a : R) ^ 2 + (b : R) ^ 2) = x := by
haveI := char_is_prime_of_pos R p
obtain ⟨a, b, hab⟩ := ZMod.sq_add_sq p x
refine ⟨a.val, b.val, ?_⟩
simpa using congr_arg (ZMod.castHom dvd_rfl R) hab
end CharP
open scoped Nat
open ZMod
/-- The **Fermat-Euler totient theorem**. `Nat.ModEq.pow_totient` is an alternative statement
of the same theorem. -/
@[simp]
theorem ZMod.pow_totient {n : ℕ} (x : (ZMod n)ˣ) : x ^ φ n = 1 := by
cases n
· rw [Nat.totient_zero, pow_zero]
· rw [← card_units_eq_totient, pow_card_eq_one]
/-- The **Fermat-Euler totient theorem**. `ZMod.pow_totient` is an alternative statement
of the same theorem. -/
theorem Nat.ModEq.pow_totient {x n : ℕ} (h : Nat.Coprime x n) : x ^ φ n ≡ 1 [MOD n] := by
rw [← ZMod.eq_iff_modEq_nat]
let x' : Units (ZMod n) := ZMod.unitOfCoprime _ h
have := ZMod.pow_totient x'
apply_fun ((fun (x : Units (ZMod n)) => (x : ZMod n)) : Units (ZMod n) → ZMod n) at this
simpa only [Nat.succ_eq_add_one, Nat.cast_pow, Units.val_one, Nat.cast_one,
coe_unitOfCoprime, Units.val_pow_eq_pow_val]
/-- For each `n ≥ 0`, the unit group of `ZMod n` is finite. -/
instance instFiniteZModUnits : (n : ℕ) → Finite (ZMod n)ˣ
| 0 => Finite.of_fintype ℤˣ
| _ + 1 => inferInstance
section
variable {V : Type*} [Fintype K] [DivisionRing K] [AddCommGroup V] [Module K V]
-- should this go in a namespace?
-- finite_dimensional would be natural,
-- but we don't assume it...
theorem card_eq_pow_finrank [Fintype V] : Fintype.card V = q ^ FiniteDimensional.finrank K V := by
let b := IsNoetherian.finsetBasis K V
rw [Module.card_fintype b, ← FiniteDimensional.finrank_eq_card_basis b]
end
open FiniteField
namespace ZMod
/-- A variation on Fermat's little theorem. See `ZMod.pow_card_sub_one_eq_one` -/
@[simp]
theorem pow_card {p : ℕ} [Fact p.Prime] (x : ZMod p) : x ^ p = x := by
have h := FiniteField.pow_card x; rwa [ZMod.card p] at h
@[simp]
theorem pow_card_pow {n p : ℕ} [Fact p.Prime] (x : ZMod p) : x ^ p ^ n = x := by
induction' n with n ih
· simp
· simp [pow_succ, pow_mul, ih, pow_card]
@[simp]
theorem frobenius_zmod (p : ℕ) [Fact p.Prime] : frobenius (ZMod p) p = RingHom.id _ := by
ext a
rw [frobenius_def, ZMod.pow_card, RingHom.id_apply]
-- Porting note: this was a `simp` lemma, but now the LHS simplify to `φ p`.
theorem card_units (p : ℕ) [Fact p.Prime] : Fintype.card (ZMod p)ˣ = p - 1 := by
rw [Fintype.card_units, card]
/-- **Fermat's Little Theorem**: for every unit `a` of `ZMod p`, we have `a ^ (p - 1) = 1`. -/
theorem units_pow_card_sub_one_eq_one (p : ℕ) [Fact p.Prime] (a : (ZMod p)ˣ) : a ^ (p - 1) = 1 := by
rw [← card_units p, pow_card_eq_one]
/-- **Fermat's Little Theorem**: for all nonzero `a : ZMod p`, we have `a ^ (p - 1) = 1`. -/
theorem pow_card_sub_one_eq_one {p : ℕ} [Fact p.Prime] {a : ZMod p} (ha : a ≠ 0) :
a ^ (p - 1) = 1 := by
have h := FiniteField.pow_card_sub_one_eq_one a ha
rwa [ZMod.card p] at h
lemma pow_card_sub_one {p : ℕ} [Fact p.Prime] (a : ZMod p) :
a ^ (p - 1) = if a ≠ 0 then 1 else 0 := by
split_ifs with ha
· exact pow_card_sub_one_eq_one ha
· simp [of_not_not ha, (Fact.out : p.Prime).one_lt, tsub_eq_zero_iff_le]
theorem orderOf_units_dvd_card_sub_one {p : ℕ} [Fact p.Prime] (u : (ZMod p)ˣ) : orderOf u ∣ p - 1 :=
orderOf_dvd_of_pow_eq_one <| units_pow_card_sub_one_eq_one _ _
theorem orderOf_dvd_card_sub_one {p : ℕ} [Fact p.Prime] {a : ZMod p} (ha : a ≠ 0) :
orderOf a ∣ p - 1 :=
orderOf_dvd_of_pow_eq_one <| pow_card_sub_one_eq_one ha
open Polynomial
theorem expand_card {p : ℕ} [Fact p.Prime] (f : Polynomial (ZMod p)) :
expand (ZMod p) p f = f ^ p := by have h := FiniteField.expand_card f; rwa [ZMod.card p] at h
end ZMod
/-- **Fermat's Little Theorem**: for all `a : ℤ` coprime to `p`, we have
`a ^ (p - 1) ≡ 1 [ZMOD p]`. -/
theorem Int.ModEq.pow_card_sub_one_eq_one {p : ℕ} (hp : Nat.Prime p) {n : ℤ} (hpn : IsCoprime n p) :
n ^ (p - 1) ≡ 1 [ZMOD p] := by
haveI : Fact p.Prime := ⟨hp⟩
have : ¬(n : ZMod p) = 0 := by
rw [CharP.intCast_eq_zero_iff _ p, ← (Nat.prime_iff_prime_int.mp hp).coprime_iff_not_dvd]
· exact hpn.symm
simpa [← ZMod.intCast_eq_intCast_iff] using ZMod.pow_card_sub_one_eq_one this
section
namespace FiniteField
variable {F : Type*} [Field F]
section Finite
variable [Finite F]
/-- In a finite field of characteristic `2`, all elements are squares. -/
theorem isSquare_of_char_two (hF : ringChar F = 2) (a : F) : IsSquare a :=
haveI hF' : CharP F 2 := ringChar.of_eq hF
isSquare_of_charTwo' a
/-- In a finite field of odd characteristic, not every element is a square. -/
theorem exists_nonsquare (hF : ringChar F ≠ 2) : ∃ a : F, ¬IsSquare a := by
-- Idea: the squaring map on `F` is not injective, hence not surjective
have h : ¬Function.Injective fun x : F ↦ x * x := fun h ↦
h.ne (Ring.neg_one_ne_one_of_char_ne_two hF) <| by simp
simpa [Finite.injective_iff_surjective, Function.Surjective, IsSquare, eq_comm] using h
end Finite
variable [Fintype F]
/-- The finite field `F` has even cardinality iff it has characteristic `2`. -/
theorem even_card_iff_char_two : ringChar F = 2 ↔ Fintype.card F % 2 = 0 := by
rcases FiniteField.card F (ringChar F) with ⟨n, hp, h⟩
rw [h, ← Nat.even_iff, Nat.even_pow, hp.even_iff]
simp
theorem even_card_of_char_two (hF : ringChar F = 2) : Fintype.card F % 2 = 0 :=
even_card_iff_char_two.mp hF
theorem odd_card_of_char_ne_two (hF : ringChar F ≠ 2) : Fintype.card F % 2 = 1 :=
Nat.mod_two_ne_zero.mp (mt even_card_iff_char_two.mpr hF)
/-- If `F` has odd characteristic, then for nonzero `a : F`, we have that `a ^ (#F / 2) = ±1`. -/
theorem pow_dichotomy (hF : ringChar F ≠ 2) {a : F} (ha : a ≠ 0) :
a ^ (Fintype.card F / 2) = 1 ∨ a ^ (Fintype.card F / 2) = -1 := by
have h₁ := FiniteField.pow_card_sub_one_eq_one a ha
rw [← Nat.two_mul_odd_div_two (FiniteField.odd_card_of_char_ne_two hF), mul_comm, pow_mul,
pow_two] at h₁
exact mul_self_eq_one_iff.mp h₁
/-- A unit `a` of a finite field `F` of odd characteristic is a square
if and only if `a ^ (#F / 2) = 1`. -/
theorem unit_isSquare_iff (hF : ringChar F ≠ 2) (a : Fˣ) :
IsSquare a ↔ a ^ (Fintype.card F / 2) = 1 := by
classical
obtain ⟨g, hg⟩ := IsCyclic.exists_generator (α := Fˣ)
obtain ⟨n, hn⟩ : a ∈ Submonoid.powers g := by rw [mem_powers_iff_mem_zpowers]; apply hg
have hodd := Nat.two_mul_odd_div_two (FiniteField.odd_card_of_char_ne_two hF)
constructor
· rintro ⟨y, rfl⟩
rw [← pow_two, ← pow_mul, hodd]
apply_fun Units.val using Units.ext
push_cast
exact FiniteField.pow_card_sub_one_eq_one (y : F) (Units.ne_zero y)
· subst a; intro h
have key : 2 * (Fintype.card F / 2) ∣ n * (Fintype.card F / 2) := by
rw [← pow_mul] at h
rw [hodd, ← Fintype.card_units, ← orderOf_eq_card_of_forall_mem_zpowers hg]
apply orderOf_dvd_of_pow_eq_one h
have : 0 < Fintype.card F / 2 := Nat.div_pos Fintype.one_lt_card (by norm_num)
obtain ⟨m, rfl⟩ := Nat.dvd_of_mul_dvd_mul_right this key
refine ⟨g ^ m, ?_⟩
dsimp
rw [mul_comm, pow_mul, pow_two]
/-- A non-zero `a : F` is a square if and only if `a ^ (#F / 2) = 1`. -/
theorem isSquare_iff (hF : ringChar F ≠ 2) {a : F} (ha : a ≠ 0) :
IsSquare a ↔ a ^ (Fintype.card F / 2) = 1 := by
apply
(iff_congr _ (by simp [Units.ext_iff])).mp (FiniteField.unit_isSquare_iff hF (Units.mk0 a ha))
simp only [IsSquare, Units.ext_iff, Units.val_mk0, Units.val_mul]
constructor
· rintro ⟨y, hy⟩; exact ⟨y, hy⟩
· rintro ⟨y, rfl⟩
have hy : y ≠ 0 := by rintro rfl; simp at ha
refine ⟨Units.mk0 y hy, ?_⟩; simp
end FiniteField
end
|
FieldTheory\Finite\GaloisField.lean | /-
Copyright (c) 2021 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Alex J. Best, Johan Commelin, Eric Rodriguez, Ruben Van de Velde
-/
import Mathlib.Algebra.CharP.Algebra
import Mathlib.Data.ZMod.Algebra
import Mathlib.FieldTheory.Finite.Basic
import Mathlib.FieldTheory.Galois
import Mathlib.FieldTheory.SplittingField.IsSplittingField
/-!
# Galois fields
If `p` is a prime number, and `n` a natural number,
then `GaloisField p n` is defined as the splitting field of `X^(p^n) - X` over `ZMod p`.
It is a finite field with `p ^ n` elements.
## Main definition
* `GaloisField p n` is a field with `p ^ n` elements
## Main Results
- `GaloisField.algEquivGaloisField`: Any finite field is isomorphic to some Galois field
- `FiniteField.algEquivOfCardEq`: Uniqueness of finite fields : algebra isomorphism
- `FiniteField.ringEquivOfCardEq`: Uniqueness of finite fields : ring isomorphism
-/
noncomputable section
open Polynomial Finset
open scoped Polynomial
instance FiniteField.isSplittingField_sub (K F : Type*) [Field K] [Fintype K]
[Field F] [Algebra F K] : IsSplittingField F K (X ^ Fintype.card K - X) where
splits' := by
have h : (X ^ Fintype.card K - X : K[X]).natDegree = Fintype.card K :=
FiniteField.X_pow_card_sub_X_natDegree_eq K Fintype.one_lt_card
rw [← splits_id_iff_splits, splits_iff_card_roots, Polynomial.map_sub, Polynomial.map_pow,
map_X, h, FiniteField.roots_X_pow_card_sub_X K, ← Finset.card_def, Finset.card_univ]
adjoin_rootSet' := by
classical
trans Algebra.adjoin F ((roots (X ^ Fintype.card K - X : K[X])).toFinset : Set K)
· simp only [rootSet, aroots, Polynomial.map_pow, map_X, Polynomial.map_sub]
· rw [FiniteField.roots_X_pow_card_sub_X, val_toFinset, coe_univ, Algebra.adjoin_univ]
theorem galois_poly_separable {K : Type*} [Field K] (p q : ℕ) [CharP K p] (h : p ∣ q) :
Separable (X ^ q - X : K[X]) := by
use 1, X ^ q - X - 1
rw [← CharP.cast_eq_zero_iff K[X] p] at h
rw [derivative_sub, derivative_X_pow, derivative_X, C_eq_natCast, h]
ring
variable (p : ℕ) [Fact p.Prime] (n : ℕ)
/-- A finite field with `p ^ n` elements.
Every field with the same cardinality is (non-canonically)
isomorphic to this field. -/
def GaloisField := SplittingField (X ^ p ^ n - X : (ZMod p)[X])
-- deriving Field -- Porting note: see https://github.com/leanprover-community/mathlib4/issues/5020
instance : Field (GaloisField p n) :=
inferInstanceAs (Field (SplittingField _))
instance : Inhabited (@GaloisField 2 (Fact.mk Nat.prime_two) 1) := ⟨37⟩
namespace GaloisField
variable (p : ℕ) [h_prime : Fact p.Prime] (n : ℕ)
instance : Algebra (ZMod p) (GaloisField p n) := SplittingField.algebra _
instance : IsSplittingField (ZMod p) (GaloisField p n) (X ^ p ^ n - X) :=
Polynomial.IsSplittingField.splittingField _
instance : CharP (GaloisField p n) p :=
(Algebra.charP_iff (ZMod p) (GaloisField p n) p).mp (by infer_instance)
instance : FiniteDimensional (ZMod p) (GaloisField p n) := by
dsimp only [GaloisField]; infer_instance
instance : Fintype (GaloisField p n) := by
dsimp only [GaloisField]
exact FiniteDimensional.fintypeOfFintype (ZMod p) (GaloisField p n)
theorem finrank {n} (h : n ≠ 0) : FiniteDimensional.finrank (ZMod p) (GaloisField p n) = n := by
set g_poly := (X ^ p ^ n - X : (ZMod p)[X])
have hp : 1 < p := h_prime.out.one_lt
have aux : g_poly ≠ 0 := FiniteField.X_pow_card_pow_sub_X_ne_zero _ h hp
-- Porting note: in the statment of `key`, replaced `g_poly` by its value otherwise the
-- proof fails
have key : Fintype.card (g_poly.rootSet (GaloisField p n)) = g_poly.natDegree :=
card_rootSet_eq_natDegree (galois_poly_separable p _ (dvd_pow (dvd_refl p) h))
(SplittingField.splits (X ^ p ^ n - X : (ZMod p)[X]))
have nat_degree_eq : g_poly.natDegree = p ^ n :=
FiniteField.X_pow_card_pow_sub_X_natDegree_eq _ h hp
rw [nat_degree_eq] at key
suffices g_poly.rootSet (GaloisField p n) = Set.univ by
simp_rw [this, ← Fintype.ofEquiv_card (Equiv.Set.univ _)] at key
-- Porting note: prevents `card_eq_pow_finrank` from using a wrong instance for `Fintype`
rw [@card_eq_pow_finrank (ZMod p) _ _ _ _ _ (_), ZMod.card] at key
exact Nat.pow_right_injective (Nat.Prime.one_lt' p).out key
rw [Set.eq_univ_iff_forall]
suffices ∀ (x) (hx : x ∈ (⊤ : Subalgebra (ZMod p) (GaloisField p n))),
x ∈ (X ^ p ^ n - X : (ZMod p)[X]).rootSet (GaloisField p n)
by simpa
rw [← SplittingField.adjoin_rootSet]
simp_rw [Algebra.mem_adjoin_iff]
intro x hx
-- We discharge the `p = 0` separately, to avoid typeclass issues on `ZMod p`.
cases p; cases hp
refine Subring.closure_induction hx ?_ ?_ ?_ ?_ ?_ ?_ <;> simp_rw [mem_rootSet_of_ne aux]
· rintro x (⟨r, rfl⟩ | hx)
· simp only [g_poly, map_sub, map_pow, aeval_X]
rw [← map_pow, ZMod.pow_card_pow, sub_self]
· dsimp only [GaloisField] at hx
rwa [mem_rootSet_of_ne aux] at hx
· rw [← coeff_zero_eq_aeval_zero']
simp only [g_poly, coeff_X_pow, coeff_X_zero, sub_zero, _root_.map_eq_zero, ite_eq_right_iff,
one_ne_zero, coeff_sub]
intro hn
exact Nat.not_lt_zero 1 (pow_eq_zero hn.symm ▸ hp)
· simp [g_poly]
· simp only [g_poly, aeval_X_pow, aeval_X, map_sub, add_pow_char_pow, sub_eq_zero]
intro x y hx hy
rw [hx, hy]
· intro x hx
simp only [g_poly, sub_eq_zero, aeval_X_pow, aeval_X, map_sub, sub_neg_eq_add] at *
rw [neg_pow, hx, CharP.neg_one_pow_char_pow]
simp
· simp only [g_poly, aeval_X_pow, aeval_X, map_sub, mul_pow, sub_eq_zero]
intro x y hx hy
rw [hx, hy]
theorem card (h : n ≠ 0) : Fintype.card (GaloisField p n) = p ^ n := by
let b := IsNoetherian.finsetBasis (ZMod p) (GaloisField p n)
rw [Module.card_fintype b, ← FiniteDimensional.finrank_eq_card_basis b, ZMod.card, finrank p h]
theorem splits_zmod_X_pow_sub_X : Splits (RingHom.id (ZMod p)) (X ^ p - X) := by
have hp : 1 < p := h_prime.out.one_lt
have h1 : roots (X ^ p - X : (ZMod p)[X]) = Finset.univ.val := by
convert FiniteField.roots_X_pow_card_sub_X (ZMod p)
exact (ZMod.card p).symm
have h2 := FiniteField.X_pow_card_sub_X_natDegree_eq (ZMod p) hp
-- We discharge the `p = 0` separately, to avoid typeclass issues on `ZMod p`.
cases p; cases hp
rw [splits_iff_card_roots, h1, ← Finset.card_def, Finset.card_univ, h2, ZMod.card]
/-- A Galois field with exponent 1 is equivalent to `ZMod` -/
def equivZmodP : GaloisField p 1 ≃ₐ[ZMod p] ZMod p :=
let h : (X ^ p ^ 1 : (ZMod p)[X]) = X ^ Fintype.card (ZMod p) := by rw [pow_one, ZMod.card p]
let inst : IsSplittingField (ZMod p) (ZMod p) (X ^ p ^ 1 - X) := by rw [h]; infer_instance
(@IsSplittingField.algEquiv _ (ZMod p) _ _ _ (X ^ p ^ 1 - X : (ZMod p)[X]) inst).symm
variable {K : Type*} [Field K] [Fintype K] [Algebra (ZMod p) K]
theorem splits_X_pow_card_sub_X : Splits (algebraMap (ZMod p) K) (X ^ Fintype.card K - X) :=
(FiniteField.isSplittingField_sub K (ZMod p)).splits
theorem isSplittingField_of_card_eq (h : Fintype.card K = p ^ n) :
IsSplittingField (ZMod p) K (X ^ p ^ n - X) :=
h ▸ FiniteField.isSplittingField_sub K (ZMod p)
instance (priority := 100) {K K' : Type*} [Field K] [Field K'] [Finite K'] [Algebra K K'] :
IsGalois K K' := by
cases nonempty_fintype K'
obtain ⟨p, hp⟩ := CharP.exists K
haveI : CharP K p := hp
haveI : CharP K' p := charP_of_injective_algebraMap' K K' p
exact IsGalois.of_separable_splitting_field
(galois_poly_separable p (Fintype.card K')
(let ⟨n, _, hn⟩ := FiniteField.card K' p
hn.symm ▸ dvd_pow_self p n.ne_zero))
/-- Any finite field is (possibly non canonically) isomorphic to some Galois field. -/
def algEquivGaloisField (h : Fintype.card K = p ^ n) : K ≃ₐ[ZMod p] GaloisField p n :=
haveI := isSplittingField_of_card_eq _ _ h
IsSplittingField.algEquiv _ _
end GaloisField
namespace FiniteField
variable {K : Type*} [Field K] [Fintype K] {K' : Type*} [Field K'] [Fintype K']
/-- Uniqueness of finite fields:
Any two finite fields of the same cardinality are (possibly non canonically) isomorphic-/
def algEquivOfCardEq (p : ℕ) [h_prime : Fact p.Prime] [Algebra (ZMod p) K] [Algebra (ZMod p) K']
(hKK' : Fintype.card K = Fintype.card K') : K ≃ₐ[ZMod p] K' := by
have : CharP K p := by rw [← Algebra.charP_iff (ZMod p) K p]; exact ZMod.charP p
have : CharP K' p := by rw [← Algebra.charP_iff (ZMod p) K' p]; exact ZMod.charP p
choose n a hK using FiniteField.card K p
choose n' a' hK' using FiniteField.card K' p
rw [hK, hK'] at hKK'
have hGalK := GaloisField.algEquivGaloisField p n hK
have hK'Gal := (GaloisField.algEquivGaloisField p n' hK').symm
rw [Nat.pow_right_injective h_prime.out.one_lt hKK'] at *
exact AlgEquiv.trans hGalK hK'Gal
/-- Uniqueness of finite fields:
Any two finite fields of the same cardinality are (possibly non canonically) isomorphic-/
def ringEquivOfCardEq (hKK' : Fintype.card K = Fintype.card K') : K ≃+* K' := by
choose p _char_p_K using CharP.exists K
choose p' _char_p'_K' using CharP.exists K'
choose n hp hK using FiniteField.card K p
choose n' hp' hK' using FiniteField.card K' p'
have hpp' : p = p' := by
by_contra hne
have h2 := Nat.coprime_pow_primes n n' hp hp' hne
rw [(Eq.congr hK hK').mp hKK', Nat.coprime_self, pow_eq_one_iff (PNat.ne_zero n')] at h2
exact Nat.Prime.ne_one hp' h2
rw [← hpp'] at _char_p'_K'
haveI := fact_iff.2 hp
letI : Algebra (ZMod p) K := ZMod.algebra _ _
letI : Algebra (ZMod p) K' := ZMod.algebra _ _
exact ↑(algEquivOfCardEq p hKK')
end FiniteField
|
FieldTheory\Finite\Polynomial.lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.MvPolynomial.Expand
import Mathlib.FieldTheory.Finite.Basic
import Mathlib.LinearAlgebra.FiniteDimensional
import Mathlib.RingTheory.MvPolynomial.Basic
/-!
## Polynomials over finite fields
-/
namespace MvPolynomial
variable {σ : Type*}
/-- A polynomial over the integers is divisible by `n : ℕ`
if and only if it is zero over `ZMod n`. -/
theorem C_dvd_iff_zmod (n : ℕ) (φ : MvPolynomial σ ℤ) :
C (n : ℤ) ∣ φ ↔ map (Int.castRingHom (ZMod n)) φ = 0 :=
C_dvd_iff_map_hom_eq_zero _ _ (CharP.intCast_eq_zero_iff (ZMod n) n) _
section frobenius
variable {p : ℕ} [Fact p.Prime]
theorem frobenius_zmod (f : MvPolynomial σ (ZMod p)) : frobenius _ p f = expand p f := by
apply induction_on f
· intro a; rw [expand_C, frobenius_def, ← C_pow, ZMod.pow_card]
· simp only [map_add]; intro _ _ hf hg; rw [hf, hg]
· simp only [expand_X, map_mul]
intro _ _ hf; rw [hf, frobenius_def]
theorem expand_zmod (f : MvPolynomial σ (ZMod p)) : expand p f = f ^ p :=
(frobenius_zmod _).symm
end frobenius
end MvPolynomial
namespace MvPolynomial
noncomputable section
open Set LinearMap Submodule
variable {K : Type*} {σ : Type*}
section Indicator
variable [Fintype K] [Fintype σ]
/-- Over a field, this is the indicator function as an `MvPolynomial`. -/
def indicator [CommRing K] (a : σ → K) : MvPolynomial σ K :=
∏ n, (1 - (X n - C (a n)) ^ (Fintype.card K - 1))
section CommRing
variable [CommRing K]
theorem eval_indicator_apply_eq_one (a : σ → K) : eval a (indicator a) = 1 := by
nontriviality
have : 0 < Fintype.card K - 1 := tsub_pos_of_lt Fintype.one_lt_card
simp only [indicator, map_prod, map_sub, map_one, map_pow, eval_X, eval_C, sub_self,
zero_pow this.ne', sub_zero, Finset.prod_const_one]
theorem degrees_indicator (c : σ → K) :
degrees (indicator c) ≤ ∑ s : σ, (Fintype.card K - 1) • {s} := by
rw [indicator]
refine le_trans (degrees_prod _ _) (Finset.sum_le_sum fun s _ => ?_)
classical
refine le_trans (degrees_sub _ _) ?_
rw [degrees_one, ← bot_eq_zero, bot_sup_eq]
refine le_trans (degrees_pow _ _) (nsmul_le_nsmul_right ?_ _)
refine le_trans (degrees_sub _ _) ?_
rw [degrees_C, ← bot_eq_zero, sup_bot_eq]
exact degrees_X' _
theorem indicator_mem_restrictDegree (c : σ → K) :
indicator c ∈ restrictDegree σ K (Fintype.card K - 1) := by
classical
rw [mem_restrictDegree_iff_sup, indicator]
intro n
refine le_trans (Multiset.count_le_of_le _ <| degrees_indicator _) (le_of_eq ?_)
simp_rw [← Multiset.coe_countAddMonoidHom, map_sum,
AddMonoidHom.map_nsmul, Multiset.coe_countAddMonoidHom, nsmul_eq_mul, Nat.cast_id]
trans
· refine Finset.sum_eq_single n ?_ ?_
· intro b _ ne
simp [Multiset.count_singleton, ne, if_neg (Ne.symm _)]
· intro h; exact (h <| Finset.mem_univ _).elim
· rw [Multiset.count_singleton_self, mul_one]
end CommRing
variable [Field K]
theorem eval_indicator_apply_eq_zero (a b : σ → K) (h : a ≠ b) : eval a (indicator b) = 0 := by
obtain ⟨i, hi⟩ : ∃ i, a i ≠ b i := by rwa [Ne, Function.funext_iff, not_forall] at h
simp only [indicator, map_prod, map_sub, map_one, map_pow, eval_X, eval_C, sub_self,
Finset.prod_eq_zero_iff]
refine ⟨i, Finset.mem_univ _, ?_⟩
rw [FiniteField.pow_card_sub_one_eq_one, sub_self]
rwa [Ne, sub_eq_zero]
end Indicator
section
variable (K σ)
/-- `MvPolynomial.eval` as a `K`-linear map. -/
@[simps]
def evalₗ [CommSemiring K] : MvPolynomial σ K →ₗ[K] (σ → K) → K where
toFun p e := eval e p
map_add' p q := by ext x; simp
map_smul' a p := by ext e; simp
variable [Field K] [Fintype K] [Finite σ]
-- Porting note: `K` and `σ` were implicit in mathlib3, even if they were declared via
-- `variable (K σ)` (I don't understand why). They are now explicit, as expected.
theorem map_restrict_dom_evalₗ : (restrictDegree σ K (Fintype.card K - 1)).map (evalₗ K σ) = ⊤ := by
cases nonempty_fintype σ
refine top_unique (SetLike.le_def.2 fun e _ => mem_map.2 ?_)
classical
refine ⟨∑ n : σ → K, e n • indicator n, ?_, ?_⟩
· exact sum_mem fun c _ => smul_mem _ _ (indicator_mem_restrictDegree _)
· ext n
simp only [_root_.map_sum, @Finset.sum_apply (σ → K) (fun _ => K) _ _ _ _ _, Pi.smul_apply,
map_smul]
simp only [evalₗ_apply]
trans
· refine Finset.sum_eq_single n (fun b _ h => ?_) ?_
· rw [eval_indicator_apply_eq_zero _ _ h.symm, smul_zero]
· exact fun h => (h <| Finset.mem_univ n).elim
· rw [eval_indicator_apply_eq_one, smul_eq_mul, mul_one]
end
end
end MvPolynomial
namespace MvPolynomial
open scoped Cardinal
open LinearMap Submodule
universe u
variable (σ : Type u) (K : Type u) [Fintype K]
-- Porting note: `@[derive [AddCommGroup, Module K, Inhabited]]` done by hand.
/-- The submodule of multivariate polynomials whose degree of each variable is strictly less
than the cardinality of K. -/
def R [CommRing K] : Type u :=
restrictDegree σ K (Fintype.card K - 1)
noncomputable instance [CommRing K] : AddCommGroup (R σ K) :=
inferInstanceAs (AddCommGroup (restrictDegree σ K (Fintype.card K - 1)))
noncomputable instance [CommRing K] : Module K (R σ K) :=
inferInstanceAs (Module K (restrictDegree σ K (Fintype.card K - 1)))
noncomputable instance [CommRing K] : Inhabited (R σ K) :=
inferInstanceAs (Inhabited (restrictDegree σ K (Fintype.card K - 1)))
/-- Evaluation in the `MvPolynomial.R` subtype. -/
def evalᵢ [CommRing K] : R σ K →ₗ[K] (σ → K) → K :=
(evalₗ K σ).comp (restrictDegree σ K (Fintype.card K - 1)).subtype
section CommRing
variable [CommRing K]
-- TODO: would be nice to replace this by suitable decidability assumptions
open Classical in
noncomputable instance decidableRestrictDegree (m : ℕ) :
DecidablePred (· ∈ { n : σ →₀ ℕ | ∀ i, n i ≤ m }) := by
simp only [Set.mem_setOf_eq]; infer_instance
end CommRing
variable [Field K]
open Classical in
theorem rank_R [Fintype σ] : Module.rank K (R σ K) = Fintype.card (σ → K) :=
calc
Module.rank K (R σ K) =
Module.rank K (↥{ s : σ →₀ ℕ | ∀ n : σ, s n ≤ Fintype.card K - 1 } →₀ K) :=
LinearEquiv.rank_eq
(Finsupp.supportedEquivFinsupp { s : σ →₀ ℕ | ∀ n : σ, s n ≤ Fintype.card K - 1 })
_ = #{ s : σ →₀ ℕ | ∀ n : σ, s n ≤ Fintype.card K - 1 } := by rw [rank_finsupp_self']
_ = #{ s : σ → ℕ | ∀ n : σ, s n < Fintype.card K } := by
refine Quotient.sound ⟨Equiv.subtypeEquiv Finsupp.equivFunOnFinite fun f => ?_⟩
refine forall_congr' fun n => le_tsub_iff_right ?_
exact Fintype.card_pos_iff.2 ⟨0⟩
_ = #(σ → { n // n < Fintype.card K }) :=
(@Equiv.subtypePiEquivPi σ (fun _ => ℕ) fun s n => n < Fintype.card K).cardinal_eq
_ = #(σ → Fin (Fintype.card K)) :=
(Equiv.arrowCongr (Equiv.refl σ) Fin.equivSubtype.symm).cardinal_eq
_ = #(σ → K) := (Equiv.arrowCongr (Equiv.refl σ) (Fintype.equivFin K).symm).cardinal_eq
_ = Fintype.card (σ → K) := Cardinal.mk_fintype _
instance [Finite σ] : FiniteDimensional K (R σ K) := by
cases nonempty_fintype σ
classical
exact
IsNoetherian.iff_fg.1
(IsNoetherian.iff_rank_lt_aleph0.mpr <| by
simpa only [rank_R] using Cardinal.nat_lt_aleph0 (Fintype.card (σ → K)))
open Classical in
theorem finrank_R [Fintype σ] : FiniteDimensional.finrank K (R σ K) = Fintype.card (σ → K) :=
FiniteDimensional.finrank_eq_of_rank_eq (rank_R σ K)
-- Porting note: was `(evalᵢ σ K).range`.
theorem range_evalᵢ [Finite σ] : range (evalᵢ σ K) = ⊤ := by
rw [evalᵢ, LinearMap.range_comp, range_subtype]
exact map_restrict_dom_evalₗ K σ
-- Porting note: was `(evalᵢ σ K).ker`.
theorem ker_evalₗ [Finite σ] : ker (evalᵢ σ K) = ⊥ := by
cases nonempty_fintype σ
refine (ker_eq_bot_iff_range_eq_top_of_finrank_eq_finrank ?_).mpr (range_evalᵢ σ K)
classical
rw [FiniteDimensional.finrank_fintype_fun_eq_card, finrank_R]
theorem eq_zero_of_eval_eq_zero [Finite σ] (p : MvPolynomial σ K) (h : ∀ v : σ → K, eval v p = 0)
(hp : p ∈ restrictDegree σ K (Fintype.card K - 1)) : p = 0 :=
let p' : R σ K := ⟨p, hp⟩
have : p' ∈ ker (evalᵢ σ K) := funext h
show p'.1 = (0 : R σ K).1 from congr_arg _ <| by rwa [ker_evalₗ, mem_bot] at this
end MvPolynomial
|
FieldTheory\Finite\Trace.lean | /-
Copyright (c) 2022 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Stoll
-/
import Mathlib.RingTheory.Trace.Basic
import Mathlib.FieldTheory.Finite.GaloisField
/-!
# The trace map for finite fields
We state the fact that the trace map from a finite field of
characteristic `p` to `ZMod p` is nondegenerate.
## Tags
finite field, trace
-/
namespace FiniteField
/-- The trace map from a finite field to its prime field is nongedenerate. -/
theorem trace_to_zmod_nondegenerate (F : Type*) [Field F] [Finite F]
[Algebra (ZMod (ringChar F)) F] {a : F} (ha : a ≠ 0) :
∃ b : F, Algebra.trace (ZMod (ringChar F)) F (a * b) ≠ 0 := by
haveI : Fact (ringChar F).Prime := ⟨CharP.char_is_prime F _⟩
have htr := traceForm_nondegenerate (ZMod (ringChar F)) F a
simp_rw [Algebra.traceForm_apply] at htr
by_contra! hf
exact ha (htr hf)
end FiniteField
|
FieldTheory\IsAlgClosed\AlgebraicClosure.lean | /-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.DirectLimit
import Mathlib.Algebra.CharP.Algebra
import Mathlib.FieldTheory.IsAlgClosed.Basic
import Mathlib.FieldTheory.SplittingField.Construction
/-!
# Algebraic Closure
In this file we construct the algebraic closure of a field
## Main Definitions
- `AlgebraicClosure k` is an algebraic closure of `k` (in the same universe).
It is constructed by taking the polynomial ring generated by indeterminates `x_f`
corresponding to monic irreducible polynomials `f` with coefficients in `k`, and quotienting
out by a maximal ideal containing every `f(x_f)`, and then repeating this step countably
many times. See Exercise 1.13 in Atiyah--Macdonald.
## Tags
algebraic closure, algebraically closed
-/
universe u v w
noncomputable section
open Polynomial
variable (k : Type u) [Field k]
namespace AlgebraicClosure
open MvPolynomial
/-- The subtype of monic irreducible polynomials -/
abbrev MonicIrreducible : Type u :=
{ f : k[X] // Monic f ∧ Irreducible f }
/-- Sends a monic irreducible polynomial `f` to `f(x_f)` where `x_f` is a formal indeterminate. -/
def evalXSelf (f : MonicIrreducible k) : MvPolynomial (MonicIrreducible k) k :=
Polynomial.eval₂ MvPolynomial.C (X f) f
/-- The span of `f(x_f)` across monic irreducible polynomials `f` where `x_f` is an
indeterminate. -/
def spanEval : Ideal (MvPolynomial (MonicIrreducible k) k) :=
Ideal.span <| Set.range <| evalXSelf k
open Classical in
/-- Given a finset of monic irreducible polynomials, construct an algebra homomorphism to the
splitting field of the product of the polynomials sending each indeterminate `x_f` represented by
the polynomial `f` in the finset to a root of `f`. -/
def toSplittingField (s : Finset (MonicIrreducible k)) :
MvPolynomial (MonicIrreducible k) k →ₐ[k] SplittingField (∏ x ∈ s, x : k[X]) :=
MvPolynomial.aeval fun f =>
if hf : f ∈ s then
rootOfSplits _
((splits_prod_iff _ fun (j : MonicIrreducible k) _ => j.2.2.ne_zero).1
(SplittingField.splits _) f hf)
(mt isUnit_iff_degree_eq_zero.2 f.2.2.not_unit)
else 37
theorem toSplittingField_evalXSelf {s : Finset (MonicIrreducible k)} {f} (hf : f ∈ s) :
toSplittingField k s (evalXSelf k f) = 0 := by
rw [toSplittingField, evalXSelf, ← AlgHom.coe_toRingHom, hom_eval₂, AlgHom.coe_toRingHom,
MvPolynomial.aeval_X, dif_pos hf, ← MvPolynomial.algebraMap_eq, AlgHom.comp_algebraMap]
exact map_rootOfSplits _ _ _
theorem spanEval_ne_top : spanEval k ≠ ⊤ := by
rw [Ideal.ne_top_iff_one, spanEval, Ideal.span, ← Set.image_univ,
Finsupp.mem_span_image_iff_total]
rintro ⟨v, _, hv⟩
replace hv := congr_arg (toSplittingField k v.support) hv
rw [map_one, Finsupp.total_apply, Finsupp.sum, map_sum, Finset.sum_eq_zero] at hv
· exact zero_ne_one hv
intro j hj
rw [smul_eq_mul, map_mul, toSplittingField_evalXSelf (s := v.support) hj,
mul_zero]
/-- A random maximal ideal that contains `spanEval k` -/
def maxIdeal : Ideal (MvPolynomial (MonicIrreducible k) k) :=
Classical.choose <| Ideal.exists_le_maximal _ <| spanEval_ne_top k
instance maxIdeal.isMaximal : (maxIdeal k).IsMaximal :=
(Classical.choose_spec <| Ideal.exists_le_maximal _ <| spanEval_ne_top k).1
theorem le_maxIdeal : spanEval k ≤ maxIdeal k :=
(Classical.choose_spec <| Ideal.exists_le_maximal _ <| spanEval_ne_top k).2
/-- The first step of constructing `AlgebraicClosure`: adjoin a root of all monic polynomials -/
def AdjoinMonic : Type u :=
MvPolynomial (MonicIrreducible k) k ⧸ maxIdeal k
instance AdjoinMonic.field : Field (AdjoinMonic k) :=
Ideal.Quotient.field _
instance AdjoinMonic.inhabited : Inhabited (AdjoinMonic k) :=
⟨37⟩
/-- The canonical ring homomorphism to `AdjoinMonic k`. -/
def toAdjoinMonic : k →+* AdjoinMonic k :=
(Ideal.Quotient.mk _).comp C
instance AdjoinMonic.algebra : Algebra k (AdjoinMonic k) :=
(toAdjoinMonic k).toAlgebra
-- Porting note: In the statement, the type of `C` had to be made explicit.
theorem AdjoinMonic.algebraMap : algebraMap k (AdjoinMonic k) = (Ideal.Quotient.mk _).comp
(C : k →+* MvPolynomial (MonicIrreducible k) k) := rfl
theorem AdjoinMonic.isIntegral (z : AdjoinMonic k) : IsIntegral k z := by
let ⟨p, hp⟩ := Ideal.Quotient.mk_surjective z
rw [← hp]
induction p using MvPolynomial.induction_on generalizing z with
| h_C => exact isIntegral_algebraMap
| h_add _ _ ha hb => exact (ha _ rfl).add (hb _ rfl)
| h_X p f ih =>
refine @IsIntegral.mul k _ _ _ _ _ (Ideal.Quotient.mk (maxIdeal k) _) (ih _ rfl) ?_
refine ⟨f, f.2.1, ?_⟩
erw [AdjoinMonic.algebraMap, ← hom_eval₂, Ideal.Quotient.eq_zero_iff_mem]
exact le_maxIdeal k (Ideal.subset_span ⟨f, rfl⟩)
theorem AdjoinMonic.exists_root {f : k[X]} (hfm : f.Monic) (hfi : Irreducible f) :
∃ x : AdjoinMonic k, f.eval₂ (toAdjoinMonic k) x = 0 :=
⟨Ideal.Quotient.mk _ <| X (⟨f, hfm, hfi⟩ : MonicIrreducible k), by
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [toAdjoinMonic, ← hom_eval₂, Ideal.Quotient.eq_zero_iff_mem]
exact le_maxIdeal k (Ideal.subset_span <| ⟨_, rfl⟩)⟩
/-- The `n`th step of constructing `AlgebraicClosure`, together with its `Field` instance. -/
def stepAux (n : ℕ) : Σ α : Type u, Field α :=
Nat.recOn n ⟨k, inferInstance⟩ fun _ ih => ⟨@AdjoinMonic ih.1 ih.2, @AdjoinMonic.field ih.1 ih.2⟩
/-- The `n`th step of constructing `AlgebraicClosure`. -/
def Step (n : ℕ) : Type u :=
(stepAux k n).1
-- Porting note: added during the port to help in the proof of `Step.isIntegral` below.
theorem Step.zero : Step k 0 = k := rfl
instance Step.field (n : ℕ) : Field (Step k n) :=
(stepAux k n).2
-- Porting note: added during the port to help in the proof of `Step.isIntegral` below.
theorem Step.succ (n : ℕ) : Step k (n + 1) = AdjoinMonic (Step k n) := rfl
instance Step.inhabited (n) : Inhabited (Step k n) :=
⟨37⟩
/-- The canonical inclusion to the `0`th step. -/
def toStepZero : k →+* Step k 0 :=
RingHom.id k
/-- The canonical ring homomorphism to the next step. -/
def toStepSucc (n : ℕ) : Step k n →+* (Step k (n + 1)) :=
@toAdjoinMonic (Step k n) (Step.field k n)
instance Step.algebraSucc (n) : Algebra (Step k n) (Step k (n + 1)) :=
(toStepSucc k n).toAlgebra
theorem toStepSucc.exists_root {n} {f : Polynomial (Step k n)} (hfm : f.Monic)
(hfi : Irreducible f) : ∃ x : Step k (n + 1), f.eval₂ (toStepSucc k n) x = 0 := by
-- Porting note: original proof was `@AdjoinMonic.exists_root _ (Step.field k n) _ hfm hfi`,
-- but it timeouts.
obtain ⟨x, hx⟩ := @AdjoinMonic.exists_root _ (Step.field k n) _ hfm hfi
-- Porting note: using `hx` instead of `by apply hx` timeouts.
exact ⟨x, by apply hx⟩
-- Porting note: the following two declarations were added during the port to be used in the
-- definition of toStepOfLE
private def toStepOfLE' (m n : ℕ) (h : m ≤ n) : Step k m → Step k n :=
Nat.leRecOn h @fun a => toStepSucc k a
private theorem toStepOfLE'.succ (m n : ℕ) (h : m ≤ n) :
toStepOfLE' k m (Nat.succ n) (h.trans n.le_succ) =
(toStepSucc k n) ∘ toStepOfLE' k m n h := by
ext x
exact Nat.leRecOn_succ h x
/-- The canonical ring homomorphism to a step with a greater index. -/
def toStepOfLE (m n : ℕ) (h : m ≤ n) : Step k m →+* Step k n where
toFun := toStepOfLE' k m n h
map_one' := by
-- Porting note: original proof was `induction' h with n h ih; · exact Nat.leRecOn_self 1`
-- `rw [Nat.leRecOn_succ h, ih, RingHom.map_one]`
induction' h with a h ih
· exact Nat.leRecOn_self 1
· rw [toStepOfLE'.succ k m a h]; simp [ih]
map_mul' x y := by
-- Porting note: original proof was `induction' h with n h ih; · simp_rw [Nat.leRecOn_self]`
-- `simp_rw [Nat.leRecOn_succ h, ih, RingHom.map_mul]`
induction' h with a h ih
· dsimp [toStepOfLE']; simp_rw [Nat.leRecOn_self]
· simp_rw [toStepOfLE'.succ k m a h]; simp only at ih; simp [ih]
-- Porting note: original proof was `induction' h with n h ih; · exact Nat.leRecOn_self 0`
-- `rw [Nat.leRecOn_succ h, ih, RingHom.map_zero]`
map_zero' := by
induction' h with a h ih
· exact Nat.leRecOn_self 0
· simp_rw [toStepOfLE'.succ k m a h]; simp only at ih; simp [ih]
map_add' x y := by
-- Porting note: original proof was `induction' h with n h ih; · simp_rw [Nat.leRecOn_self]`
-- `simp_rw [Nat.leRecOn_succ h, ih, RingHom.map_add]`
induction' h with a h ih
· dsimp [toStepOfLE']; simp_rw [Nat.leRecOn_self]
· simp_rw [toStepOfLE'.succ k m a h]; simp only at ih; simp [ih]
@[simp]
theorem coe_toStepOfLE (m n : ℕ) (h : m ≤ n) :
(toStepOfLE k m n h : Step k m → Step k n) = Nat.leRecOn h @fun n => toStepSucc k n :=
rfl
instance Step.algebra (n) : Algebra k (Step k n) :=
(toStepOfLE k 0 n n.zero_le).toAlgebra
instance Step.scalar_tower (n) : IsScalarTower k (Step k n) (Step k (n + 1)) :=
IsScalarTower.of_algebraMap_eq fun z =>
@Nat.leRecOn_succ (Step k) 0 n n.zero_le (n + 1).zero_le (@fun n => toStepSucc k n) z
-- Porting note: Added to make `Step.isIntegral` faster
private theorem toStepOfLE.succ (n : ℕ) (h : 0 ≤ n) :
toStepOfLE k 0 (n + 1) (h.trans n.le_succ) =
(toStepSucc k n).comp (toStepOfLE k 0 n h) := by
ext1 x
rw [RingHom.comp_apply]
simp only [toStepOfLE, RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk]
change _ = (_ ∘ _) x
rw [toStepOfLE'.succ k 0 n h]
theorem Step.isIntegral (n) : ∀ z : Step k n, IsIntegral k z := by
induction' n with a h
· intro z
exact isIntegral_algebraMap
· intro z
change RingHom.IsIntegralElem _ _
revert z
change RingHom.IsIntegral _
unfold algebraMap
unfold Algebra.toRingHom
unfold algebra
unfold RingHom.toAlgebra
unfold RingHom.toAlgebra'
simp only
rw [toStepOfLE.succ k a a.zero_le]
apply @RingHom.IsIntegral.trans (Step k 0) (Step k a) (Step k (a + 1)) _ _ _
(toStepOfLE k 0 a (a.zero_le : 0 ≤ a)) (toStepSucc k a) _
· intro z
have := AdjoinMonic.isIntegral (Step k a) (z : Step k (a + 1))
convert this
· convert h -- Porting note: This times out at 500000
instance toStepOfLE.directedSystem : DirectedSystem (Step k) fun i j h => toStepOfLE k i j h :=
⟨fun _ x _ => Nat.leRecOn_self x, fun h₁₂ h₂₃ x => (Nat.leRecOn_trans h₁₂ h₂₃ x).symm⟩
end AlgebraicClosure
/-- Auxiliary construction for `AlgebraicClosure`. Although `AlgebraicClosureAux` does define
the algebraic closure of a field, it is redefined at `AlgebraicClosure` in order to make sure
certain instance diamonds commute by definition.
-/
def AlgebraicClosureAux [Field k] : Type u :=
Ring.DirectLimit (AlgebraicClosure.Step k) fun i j h => AlgebraicClosure.toStepOfLE k i j h
namespace AlgebraicClosureAux
open AlgebraicClosure
/-- `AlgebraicClosureAux k` is a `Field` -/
local instance field : Field (AlgebraicClosureAux k) :=
Field.DirectLimit.field _ _
instance : Inhabited (AlgebraicClosureAux k) :=
⟨37⟩
/-- The canonical ring embedding from the `n`th step to the algebraic closure. -/
def ofStep (n : ℕ) : Step k n →+* AlgebraicClosureAux k :=
Ring.DirectLimit.of _ _ _
theorem ofStep_succ (n : ℕ) : (ofStep k (n + 1)).comp (toStepSucc k n) = ofStep k n := by
ext x
have hx : toStepOfLE' k n (n+1) n.le_succ x = toStepSucc k n x := Nat.leRecOn_succ' x
unfold ofStep
rw [RingHom.comp_apply]
dsimp [toStepOfLE]
rw [← hx]
change Ring.DirectLimit.of (Step k) (toStepOfLE' k) (n + 1) (_) =
Ring.DirectLimit.of (Step k) (toStepOfLE' k) n x
convert Ring.DirectLimit.of_f n.le_succ x
-- Porting Note: Original proof timed out at 2 mil. Heartbeats. The problem was likely
-- in comparing `toStepOfLE'` with `toStepSucc`. In the above, I made some things more explicit
-- Original proof:
-- RingHom.ext fun x =>
-- show Ring.DirectLimit.of (Step k) (fun i j h => toStepOfLE k i j h) _ _ = _ by
-- convert Ring.DirectLimit.of_f n.le_succ x; ext x; exact (Nat.leRecOn_succ' x).symm
theorem exists_ofStep (z : AlgebraicClosureAux k) : ∃ n x, ofStep k n x = z :=
Ring.DirectLimit.exists_of z
theorem exists_root {f : Polynomial (AlgebraicClosureAux k)}
(hfm : f.Monic) (hfi : Irreducible f) : ∃ x : AlgebraicClosureAux k, f.eval x = 0 := by
have : ∃ n p, Polynomial.map (ofStep k n) p = f := by
convert Ring.DirectLimit.Polynomial.exists_of f
obtain ⟨n, p, rfl⟩ := this
rw [monic_map_iff] at hfm
have := hfm.irreducible_of_irreducible_map (ofStep k n) p hfi
obtain ⟨x, hx⟩ := toStepSucc.exists_root k hfm this
refine ⟨ofStep k (n + 1) x, ?_⟩
rw [← ofStep_succ k n, eval_map, ← hom_eval₂, hx, RingHom.map_zero]
@[local instance] theorem instIsAlgClosed : IsAlgClosed (AlgebraicClosureAux k) :=
IsAlgClosed.of_exists_root _ fun _ => exists_root k
/-- `AlgebraicClosureAux k` is a `k`-`Algebra` -/
local instance instAlgebra : Algebra k (AlgebraicClosureAux k) :=
(ofStep k 0).toAlgebra
/-- Canonical algebra embedding from the `n`th step to the algebraic closure. -/
def ofStepHom (n) : Step k n →ₐ[k] AlgebraicClosureAux k :=
{ ofStep k n with
commutes' := by
-- Porting note: Originally `(fun x => Ring.DirectLimit.of_f n.zero_le x)`
-- I think one problem was in recognizing that we want `toStepOfLE` in `of_f`
intro x
simp only [RingHom.toMonoidHom_eq_coe, OneHom.toFun_eq_coe, MonoidHom.toOneHom_coe,
MonoidHom.coe_coe]
convert @Ring.DirectLimit.of_f ℕ _ (Step k) _ (fun m n h => (toStepOfLE k m n h : _ → _))
0 n n.zero_le x }
instance isAlgebraic : Algebra.IsAlgebraic k (AlgebraicClosureAux k) :=
⟨fun z =>
IsIntegral.isAlgebraic <|
let ⟨n, x, hx⟩ := exists_ofStep k z
hx ▸ (Step.isIntegral k n x).map (ofStepHom k n)⟩
@[local instance] theorem isAlgClosure : IsAlgClosure k (AlgebraicClosureAux k) :=
⟨AlgebraicClosureAux.instIsAlgClosed k, isAlgebraic k⟩
end AlgebraicClosureAux
attribute [local instance] AlgebraicClosureAux.field AlgebraicClosureAux.instAlgebra
AlgebraicClosureAux.instIsAlgClosed
/-- The canonical algebraic closure of a field, the direct limit of adding roots to the field for
each polynomial over the field. -/
def AlgebraicClosure : Type u :=
MvPolynomial (AlgebraicClosureAux k) k ⧸
RingHom.ker (MvPolynomial.aeval (R := k) id).toRingHom
namespace AlgebraicClosure
instance instCommRing : CommRing (AlgebraicClosure k) := Ideal.Quotient.commRing _
instance instInhabited : Inhabited (AlgebraicClosure k) := ⟨37⟩
instance {S : Type*} [DistribSMul S k] [IsScalarTower S k k] : SMul S (AlgebraicClosure k) :=
Submodule.Quotient.instSMul' _
instance instAlgebra {R : Type*} [CommSemiring R] [Algebra R k] : Algebra R (AlgebraicClosure k) :=
Ideal.Quotient.algebra _
instance {R S : Type*} [CommSemiring R] [CommSemiring S] [Algebra R S] [Algebra S k] [Algebra R k]
[IsScalarTower R S k] : IsScalarTower R S (AlgebraicClosure k) :=
Ideal.Quotient.isScalarTower _ _ _
/-- The equivalence between `AlgebraicClosure` and `AlgebraicClosureAux`, which we use to transfer
properties of `AlgebraicClosureAux` to `AlgebraicClosure` -/
def algEquivAlgebraicClosureAux :
AlgebraicClosure k ≃ₐ[k] AlgebraicClosureAux k := by
delta AlgebraicClosure
exact Ideal.quotientKerAlgEquivOfSurjective
(fun x => ⟨MvPolynomial.X x, by simp⟩)
-- Those two instances are copy-pasta from the analogous instances for `SplittingField`
instance instGroupWithZero : GroupWithZero (AlgebraicClosure k) :=
let e := algEquivAlgebraicClosureAux k
{ inv := fun a ↦ e.symm (e a)⁻¹
inv_zero := by simp
mul_inv_cancel := fun a ha ↦ e.injective $ by simp [(AddEquivClass.map_ne_zero_iff _).2 ha]
__ := e.surjective.nontrivial }
instance instField : Field (AlgebraicClosure k) where
__ := instCommRing _
__ := instGroupWithZero _
nnqsmul := (· • ·)
qsmul := (· • ·)
nnratCast q := algebraMap k _ q
ratCast q := algebraMap k _ q
nnratCast_def q := by change algebraMap k _ _ = _; simp_rw [NNRat.cast_def, map_div₀, map_natCast]
ratCast_def q := by
change algebraMap k _ _ = _; rw [Rat.cast_def, map_div₀, map_intCast, map_natCast]
nnqsmul_def q x := Quotient.inductionOn x fun p ↦ congr_arg Quotient.mk'' $ by
ext; simp [MvPolynomial.algebraMap_eq, NNRat.smul_def]
qsmul_def q x := Quotient.inductionOn x fun p ↦ congr_arg Quotient.mk'' $ by
ext; simp [MvPolynomial.algebraMap_eq, Rat.smul_def]
instance isAlgClosed : IsAlgClosed (AlgebraicClosure k) :=
IsAlgClosed.of_ringEquiv _ _ (algEquivAlgebraicClosureAux k).symm.toRingEquiv
instance : IsAlgClosure k (AlgebraicClosure k) := by
rw [isAlgClosure_iff]
exact ⟨inferInstance, (algEquivAlgebraicClosureAux k).symm.isAlgebraic⟩
instance isAlgebraic : Algebra.IsAlgebraic k (AlgebraicClosure k) :=
IsAlgClosure.algebraic
instance [CharZero k] : CharZero (AlgebraicClosure k) :=
charZero_of_injective_algebraMap (RingHom.injective (algebraMap k (AlgebraicClosure k)))
instance {p : ℕ} [CharP k p] : CharP (AlgebraicClosure k) p :=
charP_of_injective_algebraMap (RingHom.injective (algebraMap k (AlgebraicClosure k))) p
end AlgebraicClosure
|
FieldTheory\IsAlgClosed\Basic.lean | /-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.FieldTheory.Normal
import Mathlib.FieldTheory.Perfect
import Mathlib.RingTheory.Localization.Integral
/-!
# Algebraically Closed Field
In this file we define the typeclass for algebraically closed fields and algebraic closures,
and prove some of their properties.
## Main Definitions
- `IsAlgClosed k` is the typeclass saying `k` is an algebraically closed field, i.e. every
polynomial in `k` splits.
- `IsAlgClosure R K` is the typeclass saying `K` is an algebraic closure of `R`, where `R` is a
commutative ring. This means that the map from `R` to `K` is injective, and `K` is
algebraically closed and algebraic over `R`
- `IsAlgClosed.lift` is a map from an algebraic extension `L` of `R`, into any algebraically
closed extension of `R`.
- `IsAlgClosure.equiv` is a proof that any two algebraic closures of the
same field are isomorphic.
## Tags
algebraic closure, algebraically closed
## TODO
- Prove that if `K / k` is algebraic, and any monic irreducible polynomial over `k` has a root
in `K`, then `K` is algebraically closed (in fact an algebraic closure of `k`).
Reference: <https://kconrad.math.uconn.edu/blurbs/galoistheory/algclosure.pdf>, Theorem 2
-/
universe u v w
open Polynomial
variable (k : Type u) [Field k]
/-- Typeclass for algebraically closed fields.
To show `Polynomial.Splits p f` for an arbitrary ring homomorphism `f`,
see `IsAlgClosed.splits_codomain` and `IsAlgClosed.splits_domain`.
-/
class IsAlgClosed : Prop where
splits : ∀ p : k[X], p.Splits <| RingHom.id k
/-- Every polynomial splits in the field extension `f : K →+* k` if `k` is algebraically closed.
See also `IsAlgClosed.splits_domain` for the case where `K` is algebraically closed.
-/
theorem IsAlgClosed.splits_codomain {k K : Type*} [Field k] [IsAlgClosed k] [Field K] {f : K →+* k}
(p : K[X]) : p.Splits f := by convert IsAlgClosed.splits (p.map f); simp [splits_map_iff]
/-- Every polynomial splits in the field extension `f : K →+* k` if `K` is algebraically closed.
See also `IsAlgClosed.splits_codomain` for the case where `k` is algebraically closed.
-/
theorem IsAlgClosed.splits_domain {k K : Type*} [Field k] [IsAlgClosed k] [Field K] {f : k →+* K}
(p : k[X]) : p.Splits f :=
Polynomial.splits_of_splits_id _ <| IsAlgClosed.splits _
namespace IsAlgClosed
variable {k}
theorem exists_root [IsAlgClosed k] (p : k[X]) (hp : p.degree ≠ 0) : ∃ x, IsRoot p x :=
exists_root_of_splits _ (IsAlgClosed.splits p) hp
theorem exists_pow_nat_eq [IsAlgClosed k] (x : k) {n : ℕ} (hn : 0 < n) : ∃ z, z ^ n = x := by
have : degree (X ^ n - C x) ≠ 0 := by
rw [degree_X_pow_sub_C hn x]
exact ne_of_gt (WithBot.coe_lt_coe.2 hn)
obtain ⟨z, hz⟩ := exists_root (X ^ n - C x) this
use z
simp only [eval_C, eval_X, eval_pow, eval_sub, IsRoot.def] at hz
exact sub_eq_zero.1 hz
theorem exists_eq_mul_self [IsAlgClosed k] (x : k) : ∃ z, x = z * z := by
rcases exists_pow_nat_eq x zero_lt_two with ⟨z, rfl⟩
exact ⟨z, sq z⟩
theorem roots_eq_zero_iff [IsAlgClosed k] {p : k[X]} :
p.roots = 0 ↔ p = Polynomial.C (p.coeff 0) := by
refine ⟨fun h => ?_, fun hp => by rw [hp, roots_C]⟩
rcases le_or_lt (degree p) 0 with hd | hd
· exact eq_C_of_degree_le_zero hd
· obtain ⟨z, hz⟩ := IsAlgClosed.exists_root p hd.ne'
rw [← mem_roots (ne_zero_of_degree_gt hd), h] at hz
simp at hz
theorem exists_eval₂_eq_zero_of_injective {R : Type*} [Ring R] [IsAlgClosed k] (f : R →+* k)
(hf : Function.Injective f) (p : R[X]) (hp : p.degree ≠ 0) : ∃ x, p.eval₂ f x = 0 :=
let ⟨x, hx⟩ := exists_root (p.map f) (by rwa [degree_map_eq_of_injective hf])
⟨x, by rwa [eval₂_eq_eval_map, ← IsRoot]⟩
theorem exists_eval₂_eq_zero {R : Type*} [Field R] [IsAlgClosed k] (f : R →+* k) (p : R[X])
(hp : p.degree ≠ 0) : ∃ x, p.eval₂ f x = 0 :=
exists_eval₂_eq_zero_of_injective f f.injective p hp
variable (k)
theorem exists_aeval_eq_zero_of_injective {R : Type*} [CommRing R] [IsAlgClosed k] [Algebra R k]
(hinj : Function.Injective (algebraMap R k)) (p : R[X]) (hp : p.degree ≠ 0) :
∃ x : k, aeval x p = 0 :=
exists_eval₂_eq_zero_of_injective (algebraMap R k) hinj p hp
theorem exists_aeval_eq_zero {R : Type*} [Field R] [IsAlgClosed k] [Algebra R k] (p : R[X])
(hp : p.degree ≠ 0) : ∃ x : k, aeval x p = 0 :=
exists_eval₂_eq_zero (algebraMap R k) p hp
theorem of_exists_root (H : ∀ p : k[X], p.Monic → Irreducible p → ∃ x, p.eval x = 0) :
IsAlgClosed k := by
refine ⟨fun p ↦ Or.inr ?_⟩
intro q hq _
have : Irreducible (q * C (leadingCoeff q)⁻¹) := by
classical
rw [← coe_normUnit_of_ne_zero hq.ne_zero]
exact (associated_normalize _).irreducible hq
obtain ⟨x, hx⟩ := H (q * C (leadingCoeff q)⁻¹) (monic_mul_leadingCoeff_inv hq.ne_zero) this
exact degree_mul_leadingCoeff_inv q hq.ne_zero ▸ degree_eq_one_of_irreducible_of_root this hx
theorem of_ringEquiv (k' : Type u) [Field k'] (e : k ≃+* k')
[IsAlgClosed k] : IsAlgClosed k' := by
apply IsAlgClosed.of_exists_root
intro p hmp hp
have hpe : degree (p.map e.symm.toRingHom) ≠ 0 := by
rw [degree_map]
exact ne_of_gt (degree_pos_of_irreducible hp)
rcases IsAlgClosed.exists_root (k := k) (p.map e.symm) hpe with ⟨x, hx⟩
use e x
rw [IsRoot] at hx
apply e.symm.injective
rw [map_zero, ← hx]
clear hx hpe hp hmp
induction p using Polynomial.induction_on <;> simp_all
theorem degree_eq_one_of_irreducible [IsAlgClosed k] {p : k[X]} (hp : Irreducible p) :
p.degree = 1 :=
degree_eq_one_of_irreducible_of_splits hp (IsAlgClosed.splits_codomain _)
theorem algebraMap_surjective_of_isIntegral {k K : Type*} [Field k] [Ring K] [IsDomain K]
[hk : IsAlgClosed k] [Algebra k K] [Algebra.IsIntegral k K] :
Function.Surjective (algebraMap k K) := by
refine fun x => ⟨-(minpoly k x).coeff 0, ?_⟩
have hq : (minpoly k x).leadingCoeff = 1 := minpoly.monic (Algebra.IsIntegral.isIntegral x)
have h : (minpoly k x).degree = 1 := degree_eq_one_of_irreducible k (minpoly.irreducible
(Algebra.IsIntegral.isIntegral x))
have : aeval x (minpoly k x) = 0 := minpoly.aeval k x
rw [eq_X_add_C_of_degree_eq_one h, hq, C_1, one_mul, aeval_add, aeval_X, aeval_C,
add_eq_zero_iff_eq_neg] at this
exact (RingHom.map_neg (algebraMap k K) ((minpoly k x).coeff 0)).symm ▸ this.symm
theorem algebraMap_surjective_of_isIntegral' {k K : Type*} [Field k] [CommRing K] [IsDomain K]
[IsAlgClosed k] (f : k →+* K) (hf : f.IsIntegral) : Function.Surjective f :=
let _ : Algebra k K := f.toAlgebra
have : Algebra.IsIntegral k K := ⟨hf⟩
algebraMap_surjective_of_isIntegral
/--
Deprecated: `algebraMap_surjective_of_isIntegral` is identical apart from the `IsIntegral` argument,
which can be found by instance synthesis
-/
@[deprecated algebraMap_surjective_of_isIntegral (since := "2024-05-08")]
theorem algebraMap_surjective_of_isAlgebraic {k K : Type*} [Field k] [Ring K] [IsDomain K]
[IsAlgClosed k] [Algebra k K] [Algebra.IsAlgebraic k K] :
Function.Surjective (algebraMap k K) :=
algebraMap_surjective_of_isIntegral
end IsAlgClosed
/-- If `k` is algebraically closed, `K / k` is a field extension, `L / k` is an intermediate field
which is algebraic, then `L` is equal to `k`. A corollary of
`IsAlgClosed.algebraMap_surjective_of_isAlgebraic`. -/
theorem IntermediateField.eq_bot_of_isAlgClosed_of_isAlgebraic {k K : Type*} [Field k] [Field K]
[IsAlgClosed k] [Algebra k K] (L : IntermediateField k K) [Algebra.IsAlgebraic k L] :
L = ⊥ := bot_unique fun x hx ↦ by
obtain ⟨y, hy⟩ := IsAlgClosed.algebraMap_surjective_of_isIntegral (k := k) (⟨x, hx⟩ : L)
exact ⟨y, congr_arg (algebraMap L K) hy⟩
lemma Polynomial.isCoprime_iff_aeval_ne_zero_of_isAlgClosed (K : Type v) [Field K] [IsAlgClosed K]
[Algebra k K] (p q : k[X]) : IsCoprime p q ↔ ∀ a : K, aeval a p ≠ 0 ∨ aeval a q ≠ 0 := by
refine ⟨fun h => aeval_ne_zero_of_isCoprime h, fun h => isCoprime_of_dvd _ _ ?_ fun x hu h0 => ?_⟩
· replace h := h 0
contrapose! h
rw [h.left, h.right, map_zero, and_self]
· rintro ⟨_, rfl⟩ ⟨_, rfl⟩
obtain ⟨a, ha : _ = _⟩ := IsAlgClosed.exists_root (x.map <| algebraMap k K) <| by
simpa only [degree_map] using (ne_of_lt <| degree_pos_of_ne_zero_of_nonunit h0 hu).symm
exact not_and_or.mpr (h a) (by simp_rw [map_mul, ← eval_map_algebraMap, ha, zero_mul, true_and])
/-- Typeclass for an extension being an algebraic closure. -/
class IsAlgClosure (R : Type u) (K : Type v) [CommRing R] [Field K] [Algebra R K]
[NoZeroSMulDivisors R K] : Prop where
alg_closed : IsAlgClosed K
algebraic : Algebra.IsAlgebraic R K
attribute [instance] IsAlgClosure.algebraic
theorem isAlgClosure_iff (K : Type v) [Field K] [Algebra k K] :
IsAlgClosure k K ↔ IsAlgClosed K ∧ Algebra.IsAlgebraic k K :=
⟨fun h => ⟨h.1, h.2⟩, fun h => ⟨h.1, h.2⟩⟩
instance (priority := 100) IsAlgClosure.normal (R K : Type*) [Field R] [Field K] [Algebra R K]
[IsAlgClosure R K] : Normal R K where
toIsAlgebraic := IsAlgClosure.algebraic
splits' _ := @IsAlgClosed.splits_codomain _ _ _ (IsAlgClosure.alg_closed R) _ _ _
instance (priority := 100) IsAlgClosure.separable (R K : Type*) [Field R] [Field K] [Algebra R K]
[IsAlgClosure R K] [CharZero R] : Algebra.IsSeparable R K :=
⟨fun _ => (minpoly.irreducible (Algebra.IsIntegral.isIntegral _)).separable⟩
namespace IsAlgClosed
variable {K : Type u} [Field K] {L : Type v} {M : Type w} [Field L] [Algebra K L] [Field M]
[Algebra K M] [IsAlgClosed M]
/-- If E/L/K is a tower of field extensions with E/L algebraic, and if M is an algebraically
closed extension of K, then any embedding of L/K into M/K extends to an embedding of E/K.
Known as the extension lemma in https://math.stackexchange.com/a/687914. -/
theorem surjective_comp_algebraMap_of_isAlgebraic {E : Type*}
[Field E] [Algebra K E] [Algebra L E] [IsScalarTower K L E] [Algebra.IsAlgebraic L E] :
Function.Surjective fun φ : E →ₐ[K] M ↦ φ.comp (IsScalarTower.toAlgHom K L E) :=
fun f ↦ IntermediateField.exists_algHom_of_splits'
(E := E) f fun s ↦ ⟨Algebra.IsIntegral.isIntegral s, IsAlgClosed.splits_codomain _⟩
variable [Algebra.IsAlgebraic K L] (K L M)
/-- Less general version of `lift`. -/
private noncomputable irreducible_def lift_aux : L →ₐ[K] M :=
Classical.choice <| IntermediateField.nonempty_algHom_of_adjoin_splits
(fun x _ ↦ ⟨Algebra.IsIntegral.isIntegral x, splits_codomain (minpoly K x)⟩)
(IntermediateField.adjoin_univ K L)
variable {R : Type u} [CommRing R]
variable {S : Type v} [CommRing S] [IsDomain S] [Algebra R S] [Algebra R M] [NoZeroSMulDivisors R S]
[NoZeroSMulDivisors R M] [Algebra.IsAlgebraic R S]
variable {M}
private instance FractionRing.isAlgebraic :
letI : IsDomain R := (NoZeroSMulDivisors.algebraMap_injective R S).isDomain _
letI : Algebra (FractionRing R) (FractionRing S) := FractionRing.liftAlgebra R _
Algebra.IsAlgebraic (FractionRing R) (FractionRing S) := by
letI : IsDomain R := (NoZeroSMulDivisors.algebraMap_injective R S).isDomain _
letI : Algebra (FractionRing R) (FractionRing S) := FractionRing.liftAlgebra R _
have := FractionRing.isScalarTower_liftAlgebra R (FractionRing S)
have := (IsFractionRing.isAlgebraic_iff' R S (FractionRing S)).1 inferInstance
constructor
intro
exact (IsFractionRing.isAlgebraic_iff R (FractionRing R) (FractionRing S)).1
(Algebra.IsAlgebraic.isAlgebraic _)
/-- A (random) homomorphism from an algebraic extension of R into an algebraically
closed extension of R. -/
noncomputable irreducible_def lift : S →ₐ[R] M := by
letI : IsDomain R := (NoZeroSMulDivisors.algebraMap_injective R S).isDomain _
letI := FractionRing.liftAlgebra R M
letI := FractionRing.liftAlgebra R (FractionRing S)
have := FractionRing.isScalarTower_liftAlgebra R M
have := FractionRing.isScalarTower_liftAlgebra R (FractionRing S)
let f : FractionRing S →ₐ[FractionRing R] M := lift_aux (FractionRing R) (FractionRing S) M
exact (f.restrictScalars R).comp ((Algebra.ofId S (FractionRing S)).restrictScalars R)
noncomputable instance (priority := 100) perfectRing (p : ℕ) [Fact p.Prime] [CharP k p]
[IsAlgClosed k] : PerfectRing k p :=
PerfectRing.ofSurjective k p fun _ => IsAlgClosed.exists_pow_nat_eq _ <| NeZero.pos p
noncomputable instance (priority := 100) perfectField [IsAlgClosed k] : PerfectField k := by
obtain _ | ⟨p, _, _⟩ := CharP.exists' k
exacts [.ofCharZero, PerfectRing.toPerfectField k p]
/-- Algebraically closed fields are infinite since `Xⁿ⁺¹ - 1` is separable when `#K = n` -/
instance (priority := 500) {K : Type*} [Field K] [IsAlgClosed K] : Infinite K := by
apply Infinite.of_not_fintype
intro hfin
set n := Fintype.card K
set f := (X : K[X]) ^ (n + 1) - 1
have hfsep : Separable f := separable_X_pow_sub_C 1 (by simp [n]) one_ne_zero
apply Nat.not_succ_le_self (Fintype.card K)
have hroot : n.succ = Fintype.card (f.rootSet K) := by
erw [card_rootSet_eq_natDegree hfsep (IsAlgClosed.splits_domain _), natDegree_X_pow_sub_C]
rw [hroot]
exact Fintype.card_le_of_injective _ Subtype.coe_injective
end IsAlgClosed
namespace IsAlgClosure
-- Porting note: errors with
-- > cannot find synthesization order for instance alg_closed with type
-- > all remaining arguments have metavariables
-- attribute [local instance] IsAlgClosure.alg_closed
section
variable (R : Type u) [CommRing R] (L : Type v) (M : Type w) [Field L] [Field M]
variable [Algebra R M] [NoZeroSMulDivisors R M] [IsAlgClosure R M]
variable [Algebra R L] [NoZeroSMulDivisors R L] [IsAlgClosure R L]
/-- A (random) isomorphism between two algebraic closures of `R`. -/
noncomputable def equiv : L ≃ₐ[R] M :=
-- Porting note (#10754): added to replace local instance above
haveI : IsAlgClosed L := IsAlgClosure.alg_closed R
haveI : IsAlgClosed M := IsAlgClosure.alg_closed R
AlgEquiv.ofBijective _ (IsAlgClosure.algebraic.algHom_bijective₂
(IsAlgClosed.lift : L →ₐ[R] M)
(IsAlgClosed.lift : M →ₐ[R] L)).1
end
variable (K : Type*) (J : Type*) (R : Type u) (S : Type*) (L : Type v) (M : Type w)
[Field K] [Field J] [CommRing R] [CommRing S] [Field L] [Field M]
[Algebra R M] [NoZeroSMulDivisors R M] [IsAlgClosure R M] [Algebra K M] [IsAlgClosure K M]
[Algebra S L] [NoZeroSMulDivisors S L] [IsAlgClosure S L]
section EquivOfAlgebraic
variable [Algebra R S] [Algebra R L] [IsScalarTower R S L]
variable [Algebra K J] [Algebra J L] [IsAlgClosure J L] [Algebra K L] [IsScalarTower K J L]
/-- If `J` is an algebraic extension of `K` and `L` is an algebraic closure of `J`, then it is
also an algebraic closure of `K`. -/
theorem ofAlgebraic [hKJ : Algebra.IsAlgebraic K J] : IsAlgClosure K L :=
⟨IsAlgClosure.alg_closed J, hKJ.trans⟩
/-- A (random) isomorphism between an algebraic closure of `R` and an algebraic closure of
an algebraic extension of `R` -/
noncomputable def equivOfAlgebraic' [Nontrivial S] [NoZeroSMulDivisors R S]
[Algebra.IsAlgebraic R L] : L ≃ₐ[R] M := by
letI : NoZeroSMulDivisors R L := NoZeroSMulDivisors.of_algebraMap_injective <| by
rw [IsScalarTower.algebraMap_eq R S L]
exact (Function.Injective.comp (NoZeroSMulDivisors.algebraMap_injective S L)
(NoZeroSMulDivisors.algebraMap_injective R S) : _)
letI : IsAlgClosure R L :=
{ alg_closed := IsAlgClosure.alg_closed S
algebraic := ‹_› }
exact IsAlgClosure.equiv _ _ _
/-- A (random) isomorphism between an algebraic closure of `K` and an algebraic closure
of an algebraic extension of `K` -/
noncomputable def equivOfAlgebraic [hKJ : Algebra.IsAlgebraic K J] : L ≃ₐ[K] M :=
have : Algebra.IsAlgebraic K L := hKJ.trans
equivOfAlgebraic' K J _ _
end EquivOfAlgebraic
section EquivOfEquiv
variable {R S}
/-- Used in the definition of `equivOfEquiv` -/
noncomputable def equivOfEquivAux (hSR : S ≃+* R) :
{ e : L ≃+* M // e.toRingHom.comp (algebraMap S L) = (algebraMap R M).comp hSR.toRingHom } := by
letI : Algebra R S := RingHom.toAlgebra hSR.symm.toRingHom
letI : Algebra S R := RingHom.toAlgebra hSR.toRingHom
letI : IsDomain R := (NoZeroSMulDivisors.algebraMap_injective R M).isDomain _
letI : IsDomain S := (NoZeroSMulDivisors.algebraMap_injective S L).isDomain _
letI : Algebra R L := RingHom.toAlgebra ((algebraMap S L).comp (algebraMap R S))
haveI : IsScalarTower R S L := IsScalarTower.of_algebraMap_eq fun _ => rfl
haveI : IsScalarTower S R L :=
IsScalarTower.of_algebraMap_eq (by simp [RingHom.algebraMap_toAlgebra])
haveI : NoZeroSMulDivisors R S := NoZeroSMulDivisors.of_algebraMap_injective hSR.symm.injective
have : Algebra.IsAlgebraic R L := (IsAlgClosure.algebraic.tower_top_of_injective
(show Function.Injective (algebraMap S R) from hSR.injective))
refine
⟨equivOfAlgebraic' R S L M, ?_⟩
ext x
simp only [RingEquiv.toRingHom_eq_coe, Function.comp_apply, RingHom.coe_comp,
AlgEquiv.coe_ringEquiv, RingEquiv.coe_toRingHom]
conv_lhs => rw [← hSR.symm_apply_apply x]
show equivOfAlgebraic' R S L M (algebraMap R L (hSR x)) = _
rw [AlgEquiv.commutes]
/-- Algebraic closure of isomorphic fields are isomorphic -/
noncomputable def equivOfEquiv (hSR : S ≃+* R) : L ≃+* M :=
equivOfEquivAux L M hSR
@[simp]
theorem equivOfEquiv_comp_algebraMap (hSR : S ≃+* R) :
(↑(equivOfEquiv L M hSR) : L →+* M).comp (algebraMap S L) = (algebraMap R M).comp hSR :=
(equivOfEquivAux L M hSR).2
@[simp]
theorem equivOfEquiv_algebraMap (hSR : S ≃+* R) (s : S) :
equivOfEquiv L M hSR (algebraMap S L s) = algebraMap R M (hSR s) :=
RingHom.ext_iff.1 (equivOfEquiv_comp_algebraMap L M hSR) s
@[simp]
theorem equivOfEquiv_symm_algebraMap (hSR : S ≃+* R) (r : R) :
(equivOfEquiv L M hSR).symm (algebraMap R M r) = algebraMap S L (hSR.symm r) :=
(equivOfEquiv L M hSR).injective (by simp)
@[simp]
theorem equivOfEquiv_symm_comp_algebraMap (hSR : S ≃+* R) :
((equivOfEquiv L M hSR).symm : M →+* L).comp (algebraMap R M) =
(algebraMap S L).comp hSR.symm :=
RingHom.ext_iff.2 (equivOfEquiv_symm_algebraMap L M hSR)
end EquivOfEquiv
end IsAlgClosure
section Algebra.IsAlgebraic
variable {F K : Type*} (A : Type*) [Field F] [Field K] [Field A] [Algebra F K] [Algebra F A]
[Algebra.IsAlgebraic F K]
/-- Let `A` be an algebraically closed field and let `x ∈ K`, with `K/F` an algebraic extension
of fields. Then the images of `x` by the `F`-algebra morphisms from `K` to `A` are exactly
the roots in `A` of the minimal polynomial of `x` over `F`. -/
theorem Algebra.IsAlgebraic.range_eval_eq_rootSet_minpoly [IsAlgClosed A] (x : K) :
(Set.range fun ψ : K →ₐ[F] A ↦ ψ x) = (minpoly F x).rootSet A :=
range_eval_eq_rootSet_minpoly_of_splits A (fun _ ↦ IsAlgClosed.splits_codomain _) x
/-- All `F`-embeddings of a field `K` into another field `A` factor through any intermediate
field of `A/F` in which the minimal polynomial of elements of `K` splits. -/
@[simps]
def IntermediateField.algHomEquivAlgHomOfSplits (L : IntermediateField F A)
(hL : ∀ x : K, (minpoly F x).Splits (algebraMap F L)) :
(K →ₐ[F] L) ≃ (K →ₐ[F] A) where
toFun := L.val.comp
invFun f := f.codRestrict _ fun x ↦
((Algebra.IsIntegral.isIntegral x).map f).mem_intermediateField_of_minpoly_splits <| by
rw [minpoly.algHom_eq f f.injective]; exact hL x
left_inv _ := rfl
right_inv _ := by rfl
theorem IntermediateField.algHomEquivAlgHomOfSplits_apply_apply (L : IntermediateField F A)
(hL : ∀ x : K, (minpoly F x).Splits (algebraMap F L)) (f : K →ₐ[F] L) (x : K) :
algHomEquivAlgHomOfSplits A L hL f x = algebraMap L A (f x) := rfl
/-- All `F`-embeddings of a field `K` into another field `A` factor through any subextension
of `A/F` in which the minimal polynomial of elements of `K` splits. -/
noncomputable def Algebra.IsAlgebraic.algHomEquivAlgHomOfSplits (L : Type*) [Field L]
[Algebra F L] [Algebra L A] [IsScalarTower F L A]
(hL : ∀ x : K, (minpoly F x).Splits (algebraMap F L)) :
(K →ₐ[F] L) ≃ (K →ₐ[F] A) :=
(AlgEquiv.refl.arrowCongr (AlgEquiv.ofInjectiveField (IsScalarTower.toAlgHom F L A))).trans <|
IntermediateField.algHomEquivAlgHomOfSplits A (IsScalarTower.toAlgHom F L A).fieldRange
fun x ↦ splits_of_algHom (hL x) (AlgHom.rangeRestrict _)
theorem Algebra.IsAlgebraic.algHomEquivAlgHomOfSplits_apply_apply (L : Type*) [Field L]
[Algebra F L] [Algebra L A] [IsScalarTower F L A]
(hL : ∀ x : K, (minpoly F x).Splits (algebraMap F L)) (f : K →ₐ[F] L) (x : K) :
Algebra.IsAlgebraic.algHomEquivAlgHomOfSplits A L hL f x = algebraMap L A (f x) := rfl
end Algebra.IsAlgebraic
|
FieldTheory\IsAlgClosed\Classification.lean | /-
Copyright (c) 2022 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Algebra.Polynomial.Cardinal
import Mathlib.Algebra.MvPolynomial.Cardinal
import Mathlib.Data.ZMod.Algebra
import Mathlib.FieldTheory.IsAlgClosed.Basic
import Mathlib.RingTheory.AlgebraicIndependent
/-!
# Classification of Algebraically closed fields
This file contains results related to classifying algebraically closed fields.
## Main statements
* `IsAlgClosed.equivOfTranscendenceBasis` Two algebraically closed fields with the same
characteristic and the same cardinality of transcendence basis are isomorphic.
* `IsAlgClosed.ringEquivOfCardinalEqOfCharEq` Two uncountable algebraically closed fields
are isomorphic if they have the same characteristic and the same cardinality.
-/
universe u
open scoped Cardinal Polynomial
open Cardinal
section AlgebraicClosure
namespace Algebra.IsAlgebraic
variable (R L : Type u) [CommRing R] [CommRing L] [IsDomain L] [Algebra R L]
variable [NoZeroSMulDivisors R L] [Algebra.IsAlgebraic R L]
theorem cardinal_mk_le_sigma_polynomial :
#L ≤ #(Σ p : R[X], { x : L // x ∈ p.aroots L }) :=
@mk_le_of_injective L (Σ p : R[X], {x : L | x ∈ p.aroots L})
(fun x : L =>
let p := Classical.indefiniteDescription _ (Algebra.IsAlgebraic.isAlgebraic x)
⟨p.1, x, by
dsimp
have h : p.1.map (algebraMap R L) ≠ 0 := by
rw [Ne, ← Polynomial.degree_eq_bot,
Polynomial.degree_map_eq_of_injective (NoZeroSMulDivisors.algebraMap_injective R L),
Polynomial.degree_eq_bot]
exact p.2.1
erw [Polynomial.mem_roots h, Polynomial.IsRoot, Polynomial.eval_map, ← Polynomial.aeval_def,
p.2.2]⟩)
fun x y => by
intro h
simp? at h says simp only [Set.coe_setOf, ne_eq, Set.mem_setOf_eq, Sigma.mk.inj_iff] at h
refine (Subtype.heq_iff_coe_eq ?_).1 h.2
simp only [h.1, iff_self_iff, forall_true_iff]
/-- The cardinality of an algebraic extension is at most the maximum of the cardinality
of the base ring or `ℵ₀` -/
theorem cardinal_mk_le_max : #L ≤ max #R ℵ₀ :=
calc
#L ≤ #(Σ p : R[X], { x : L // x ∈ p.aroots L }) :=
cardinal_mk_le_sigma_polynomial R L
_ = Cardinal.sum fun p : R[X] => #{x : L | x ∈ p.aroots L} := by
rw [← mk_sigma]; rfl
_ ≤ Cardinal.sum.{u, u} fun _ : R[X] => ℵ₀ :=
(sum_le_sum _ _ fun p => (Multiset.finite_toSet _).lt_aleph0.le)
_ = #(R[X]) * ℵ₀ := sum_const' _ _
_ ≤ max (max #(R[X]) ℵ₀) ℵ₀ := mul_le_max _ _
_ ≤ max (max (max #R ℵ₀) ℵ₀) ℵ₀ :=
(max_le_max (max_le_max Polynomial.cardinal_mk_le_max le_rfl) le_rfl)
_ = max #R ℵ₀ := by simp only [max_assoc, max_comm ℵ₀, max_left_comm ℵ₀, max_self]
end Algebra.IsAlgebraic
end AlgebraicClosure
namespace IsAlgClosed
section Classification
noncomputable section
variable {R L K : Type*} [CommRing R]
variable [Field K] [Algebra R K]
variable [Field L] [Algebra R L]
variable {ι : Type*} (v : ι → K)
variable {κ : Type*} (w : κ → L)
variable (hv : AlgebraicIndependent R v)
theorem isAlgClosure_of_transcendence_basis [IsAlgClosed K] (hv : IsTranscendenceBasis R v) :
IsAlgClosure (Algebra.adjoin R (Set.range v)) K :=
letI := RingHom.domain_nontrivial (algebraMap R K)
{ alg_closed := by infer_instance
algebraic := hv.isAlgebraic }
variable (hw : AlgebraicIndependent R w)
/-- setting `R` to be `ZMod (ringChar R)` this result shows that if two algebraically
closed fields have equipotent transcendence bases and the same characteristic then they are
isomorphic. -/
def equivOfTranscendenceBasis [IsAlgClosed K] [IsAlgClosed L] (e : ι ≃ κ)
(hv : IsTranscendenceBasis R v) (hw : IsTranscendenceBasis R w) : K ≃+* L := by
letI := isAlgClosure_of_transcendence_basis v hv
letI := isAlgClosure_of_transcendence_basis w hw
have e : Algebra.adjoin R (Set.range v) ≃+* Algebra.adjoin R (Set.range w) := by
refine hv.1.aevalEquiv.symm.toRingEquiv.trans ?_
refine (AlgEquiv.ofAlgHom (MvPolynomial.rename e)
(MvPolynomial.rename e.symm) ?_ ?_).toRingEquiv.trans ?_
· ext; simp
· ext; simp
exact hw.1.aevalEquiv.toRingEquiv
exact IsAlgClosure.equivOfEquiv K L e
end
end Classification
section Cardinal
variable {R L K : Type u} [CommRing R]
variable [Field K] [Algebra R K] [IsAlgClosed K]
variable {ι : Type u} (v : ι → K)
variable (hv : IsTranscendenceBasis R v)
theorem cardinal_le_max_transcendence_basis (hv : IsTranscendenceBasis R v) :
#K ≤ max (max #R #ι) ℵ₀ :=
calc
#K ≤ max #(Algebra.adjoin R (Set.range v)) ℵ₀ :=
letI := isAlgClosure_of_transcendence_basis v hv
Algebra.IsAlgebraic.cardinal_mk_le_max _ _
_ = max #(MvPolynomial ι R) ℵ₀ := by rw [Cardinal.eq.2 ⟨hv.1.aevalEquiv.toEquiv⟩]
_ ≤ max (max (max #R #ι) ℵ₀) ℵ₀ := max_le_max MvPolynomial.cardinal_mk_le_max le_rfl
_ = _ := by simp [max_assoc]
/-- If `K` is an uncountable algebraically closed field, then its
cardinality is the same as that of a transcendence basis. -/
theorem cardinal_eq_cardinal_transcendence_basis_of_aleph0_lt [Nontrivial R]
(hv : IsTranscendenceBasis R v) (hR : #R ≤ ℵ₀) (hK : ℵ₀ < #K) : #K = #ι :=
have : ℵ₀ ≤ #ι := le_of_not_lt fun h => not_le_of_gt hK <|
calc
#K ≤ max (max #R #ι) ℵ₀ := cardinal_le_max_transcendence_basis v hv
_ ≤ _ := max_le (max_le hR (le_of_lt h)) le_rfl
le_antisymm
(calc
#K ≤ max (max #R #ι) ℵ₀ := cardinal_le_max_transcendence_basis v hv
_ = #ι := by
rw [max_eq_left, max_eq_right]
· exact le_trans hR this
· exact le_max_of_le_right this)
(mk_le_of_injective (show Function.Injective v from hv.1.injective))
end Cardinal
variable {K L : Type} [Field K] [Field L] [IsAlgClosed K] [IsAlgClosed L]
/-- Two uncountable algebraically closed fields of characteristic zero are isomorphic
if they have the same cardinality. -/
theorem ringEquivOfCardinalEqOfCharZero [CharZero K] [CharZero L] (hK : ℵ₀ < #K)
(hKL : #K = #L) : Nonempty (K ≃+* L) := by
cases' exists_isTranscendenceBasis ℤ
(show Function.Injective (algebraMap ℤ K) from Int.cast_injective) with s hs
cases' exists_isTranscendenceBasis ℤ
(show Function.Injective (algebraMap ℤ L) from Int.cast_injective) with t ht
have : #s = #t := by
rw [← cardinal_eq_cardinal_transcendence_basis_of_aleph0_lt _ hs (le_of_eq mk_int) hK, ←
cardinal_eq_cardinal_transcendence_basis_of_aleph0_lt _ ht (le_of_eq mk_int), hKL]
rwa [← hKL]
cases' Cardinal.eq.1 this with e
exact ⟨equivOfTranscendenceBasis _ _ e hs ht⟩
private theorem ringEquivOfCardinalEqOfCharP (p : ℕ) [Fact p.Prime] [CharP K p] [CharP L p]
(hK : ℵ₀ < #K) (hKL : #K = #L) : Nonempty (K ≃+* L) := by
letI : Algebra (ZMod p) K := ZMod.algebra _ _
letI : Algebra (ZMod p) L := ZMod.algebra _ _
cases' exists_isTranscendenceBasis (ZMod p)
(show Function.Injective (algebraMap (ZMod p) K) from RingHom.injective _) with s hs
cases' exists_isTranscendenceBasis (ZMod p)
(show Function.Injective (algebraMap (ZMod p) L) from RingHom.injective _) with t ht
have : #s = #t := by
rw [← cardinal_eq_cardinal_transcendence_basis_of_aleph0_lt _ hs
(lt_aleph0_of_finite (ZMod p)).le hK,
← cardinal_eq_cardinal_transcendence_basis_of_aleph0_lt _ ht
(lt_aleph0_of_finite (ZMod p)).le, hKL]
rwa [← hKL]
cases' Cardinal.eq.1 this with e
exact ⟨equivOfTranscendenceBasis _ _ e hs ht⟩
/-- Two uncountable algebraically closed fields are isomorphic
if they have the same cardinality and the same characteristic. -/
theorem ringEquivOfCardinalEqOfCharEq (p : ℕ) [CharP K p] [CharP L p] (hK : ℵ₀ < #K)
(hKL : #K = #L) : Nonempty (K ≃+* L) := by
rcases CharP.char_is_prime_or_zero K p with (hp | hp)
· haveI : Fact p.Prime := ⟨hp⟩
exact ringEquivOfCardinalEqOfCharP p hK hKL
· simp only [hp] at *
letI : CharZero K := CharP.charP_to_charZero K
letI : CharZero L := CharP.charP_to_charZero L
exact ringEquivOfCardinalEqOfCharZero hK hKL
end IsAlgClosed
|
FieldTheory\IsAlgClosed\Spectrum.lean | /-
Copyright (c) 2021 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.Algebra.Algebra.Spectrum
import Mathlib.FieldTheory.IsAlgClosed.Basic
/-!
# Spectrum mapping theorem
This file develops proves the spectral mapping theorem for polynomials over algebraically closed
fields. In particular, if `a` is an element of a `𝕜`-algebra `A` where `𝕜` is a field, and
`p : 𝕜[X]` is a polynomial, then the spectrum of `Polynomial.aeval a p` contains the image of the
spectrum of `a` under `(fun k ↦ Polynomial.eval k p)`. When `𝕜` is algebraically closed,
these are in fact equal (assuming either that the spectrum of `a` is nonempty or the polynomial
has positive degree), which is the **spectral mapping theorem**.
In addition, this file contains the fact that every element of a finite dimensional nontrivial
algebra over an algebraically closed field has nonempty spectrum. In particular, this is used in
`Module.End.exists_eigenvalue` to show that every linear map from a vector space to itself has an
eigenvalue.
## Main statements
* `spectrum.subset_polynomial_aeval`, `spectrum.map_polynomial_aeval_of_degree_pos`,
`spectrum.map_polynomial_aeval_of_nonempty`: variations on the **spectral mapping theorem**.
* `spectrum.nonempty_of_isAlgClosed_of_finiteDimensional`: the spectrum is nonempty for any
element of a nontrivial finite dimensional algebra over an algebraically closed field.
## Notations
* `σ a` : `spectrum R a` of `a : A`
-/
namespace spectrum
open Set Polynomial
open scoped Pointwise Polynomial
universe u v
section ScalarRing
variable {R : Type u} {A : Type v}
variable [CommRing R] [Ring A] [Algebra R A]
local notation "σ" => spectrum R
local notation "↑ₐ" => algebraMap R A
-- Porting note: removed an unneeded assumption `p ≠ 0`
theorem exists_mem_of_not_isUnit_aeval_prod [IsDomain R] {p : R[X]} {a : A}
(h : ¬IsUnit (aeval a (Multiset.map (fun x : R => X - C x) p.roots).prod)) :
∃ k : R, k ∈ σ a ∧ eval k p = 0 := by
rw [← Multiset.prod_toList, map_list_prod] at h
replace h := mt List.prod_isUnit h
simp only [not_forall, exists_prop, aeval_C, Multiset.mem_toList, List.mem_map, aeval_X,
exists_exists_and_eq_and, Multiset.mem_map, map_sub] at h
rcases h with ⟨r, r_mem, r_nu⟩
exact ⟨r, by rwa [mem_iff, ← IsUnit.sub_iff], (mem_roots'.1 r_mem).2⟩
end ScalarRing
section ScalarField
variable {𝕜 : Type u} {A : Type v}
variable [Field 𝕜] [Ring A] [Algebra 𝕜 A]
local notation "σ" => spectrum 𝕜
local notation "↑ₐ" => algebraMap 𝕜 A
open Polynomial
/-- Half of the spectral mapping theorem for polynomials. We prove it separately
because it holds over any field, whereas `spectrum.map_polynomial_aeval_of_degree_pos` and
`spectrum.map_polynomial_aeval_of_nonempty` need the field to be algebraically closed. -/
theorem subset_polynomial_aeval (a : A) (p : 𝕜[X]) : (eval · p) '' σ a ⊆ σ (aeval a p) := by
rintro _ ⟨k, hk, rfl⟩
let q := C (eval k p) - p
have hroot : IsRoot q k := by simp only [q, eval_C, eval_sub, sub_self, IsRoot.def]
rw [← mul_div_eq_iff_isRoot, ← neg_mul_neg, neg_sub] at hroot
have aeval_q_eq : ↑ₐ (eval k p) - aeval a p = aeval a q := by
simp only [q, aeval_C, map_sub, sub_left_inj]
rw [mem_iff, aeval_q_eq, ← hroot, aeval_mul]
have hcomm := (Commute.all (C k - X) (-(q / (X - C k)))).map (aeval a : 𝕜[X] →ₐ[𝕜] A)
apply mt fun h => (hcomm.isUnit_mul_iff.mp h).1
simpa only [aeval_X, aeval_C, map_sub] using hk
/-- The *spectral mapping theorem* for polynomials. Note: the assumption `degree p > 0`
is necessary in case `σ a = ∅`, for then the left-hand side is `∅` and the right-hand side,
assuming `[Nontrivial A]`, is `{k}` where `p = Polynomial.C k`. -/
theorem map_polynomial_aeval_of_degree_pos [IsAlgClosed 𝕜] (a : A) (p : 𝕜[X])
(hdeg : 0 < degree p) : σ (aeval a p) = (eval · p) '' σ a := by
-- handle the easy direction via `spectrum.subset_polynomial_aeval`
refine Set.eq_of_subset_of_subset (fun k hk => ?_) (subset_polynomial_aeval a p)
-- write `C k - p` product of linear factors and a constant; show `C k - p ≠ 0`.
have hprod := eq_prod_roots_of_splits_id (IsAlgClosed.splits (C k - p))
have h_ne : C k - p ≠ 0 := ne_zero_of_degree_gt <| by
rwa [degree_sub_eq_right_of_degree_lt (lt_of_le_of_lt degree_C_le hdeg)]
have lead_ne := leadingCoeff_ne_zero.mpr h_ne
have lead_unit := (Units.map ↑ₐ.toMonoidHom (Units.mk0 _ lead_ne)).isUnit
/- leading coefficient is a unit so product of linear factors is not a unit;
apply `exists_mem_of_not_is_unit_aeval_prod`. -/
have p_a_eq : aeval a (C k - p) = ↑ₐ k - aeval a p := by
simp only [aeval_C, map_sub, sub_left_inj]
rw [mem_iff, ← p_a_eq, hprod, aeval_mul,
((Commute.all _ _).map (aeval a : 𝕜[X] →ₐ[𝕜] A)).isUnit_mul_iff, aeval_C] at hk
replace hk := exists_mem_of_not_isUnit_aeval_prod (not_and.mp hk lead_unit)
rcases hk with ⟨r, r_mem, r_ev⟩
exact ⟨r, r_mem, symm (by simpa [eval_sub, eval_C, sub_eq_zero] using r_ev)⟩
/-- In this version of the spectral mapping theorem, we assume the spectrum
is nonempty instead of assuming the degree of the polynomial is positive. -/
theorem map_polynomial_aeval_of_nonempty [IsAlgClosed 𝕜] (a : A) (p : 𝕜[X])
(hnon : (σ a).Nonempty) : σ (aeval a p) = (fun k => eval k p) '' σ a := by
nontriviality A
refine Or.elim (le_or_gt (degree p) 0) (fun h => ?_) (map_polynomial_aeval_of_degree_pos a p)
rw [eq_C_of_degree_le_zero h]
simp only [Set.image_congr, eval_C, aeval_C, scalar_eq, Set.Nonempty.image_const hnon]
/-- A specialization of `spectrum.subset_polynomial_aeval` to monic monomials for convenience. -/
theorem pow_image_subset (a : A) (n : ℕ) : (fun x => x ^ n) '' σ a ⊆ σ (a ^ n) := by
simpa only [eval_pow, eval_X, aeval_X_pow] using subset_polynomial_aeval a (X ^ n : 𝕜[X])
/-- A specialization of `spectrum.map_polynomial_aeval_of_nonempty` to monic monomials for
convenience. -/
theorem map_pow_of_pos [IsAlgClosed 𝕜] (a : A) {n : ℕ} (hn : 0 < n) :
σ (a ^ n) = (· ^ n) '' σ a := by
simpa only [aeval_X_pow, eval_pow, eval_X]
using map_polynomial_aeval_of_degree_pos a (X ^ n : 𝕜[X]) (by rwa [degree_X_pow, Nat.cast_pos])
/-- A specialization of `spectrum.map_polynomial_aeval_of_nonempty` to monic monomials for
convenience. -/
theorem map_pow_of_nonempty [IsAlgClosed 𝕜] {a : A} (ha : (σ a).Nonempty) (n : ℕ) :
σ (a ^ n) = (· ^ n) '' σ a := by
simpa only [aeval_X_pow, eval_pow, eval_X] using map_polynomial_aeval_of_nonempty a (X ^ n) ha
variable (𝕜)
-- We will use this both to show eigenvalues exist, and to prove Schur's lemma.
/-- Every element `a` in a nontrivial finite-dimensional algebra `A`
over an algebraically closed field `𝕜` has non-empty spectrum. -/
theorem nonempty_of_isAlgClosed_of_finiteDimensional [IsAlgClosed 𝕜] [Nontrivial A]
[I : FiniteDimensional 𝕜 A] (a : A) : (σ a).Nonempty := by
obtain ⟨p, ⟨h_mon, h_eval_p⟩⟩ := isIntegral_of_noetherian (IsNoetherian.iff_fg.2 I) a
have nu : ¬IsUnit (aeval a p) := by rw [← aeval_def] at h_eval_p; rw [h_eval_p]; simp
rw [eq_prod_roots_of_monic_of_splits_id h_mon (IsAlgClosed.splits p)] at nu
obtain ⟨k, hk, _⟩ := exists_mem_of_not_isUnit_aeval_prod nu
exact ⟨k, hk⟩
end ScalarField
end spectrum
|
FieldTheory\Minpoly\Basic.lean | /-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johan Commelin
-/
import Mathlib.RingTheory.IntegralClosure.IsIntegral.Basic
/-!
# Minimal polynomials
This file defines the minimal polynomial of an element `x` of an `A`-algebra `B`,
under the assumption that x is integral over `A`, and derives some basic properties
such as irreducibility under the assumption `B` is a domain.
-/
open scoped Classical
open Polynomial Set Function
variable {A B B' : Type*}
section MinPolyDef
variable (A) [CommRing A] [Ring B] [Algebra A B]
/-- Suppose `x : B`, where `B` is an `A`-algebra.
The minimal polynomial `minpoly A x` of `x`
is a monic polynomial with coefficients in `A` of smallest degree that has `x` as its root,
if such exists (`IsIntegral A x`) or zero otherwise.
For example, if `V` is a `𝕜`-vector space for some field `𝕜` and `f : V →ₗ[𝕜] V` then
the minimal polynomial of `f` is `minpoly 𝕜 f`.
-/
noncomputable def minpoly (x : B) : A[X] :=
if hx : IsIntegral A x then degree_lt_wf.min _ hx else 0
end MinPolyDef
namespace minpoly
section Ring
variable [CommRing A] [Ring B] [Ring B'] [Algebra A B] [Algebra A B']
variable {x : B}
/-- A minimal polynomial is monic. -/
theorem monic (hx : IsIntegral A x) : Monic (minpoly A x) := by
delta minpoly
rw [dif_pos hx]
exact (degree_lt_wf.min_mem _ hx).1
/-- A minimal polynomial is nonzero. -/
theorem ne_zero [Nontrivial A] (hx : IsIntegral A x) : minpoly A x ≠ 0 :=
(monic hx).ne_zero
theorem eq_zero (hx : ¬IsIntegral A x) : minpoly A x = 0 :=
dif_neg hx
theorem algHom_eq (f : B →ₐ[A] B') (hf : Function.Injective f) (x : B) :
minpoly A (f x) = minpoly A x := by
refine dif_ctx_congr (isIntegral_algHom_iff _ hf) (fun _ => ?_) fun _ => rfl
simp_rw [← Polynomial.aeval_def, aeval_algHom, AlgHom.comp_apply, _root_.map_eq_zero_iff f hf]
theorem algebraMap_eq {B} [CommRing B] [Algebra A B] [Algebra B B'] [IsScalarTower A B B']
(h : Function.Injective (algebraMap B B')) (x : B) :
minpoly A (algebraMap B B' x) = minpoly A x :=
algHom_eq (IsScalarTower.toAlgHom A B B') h x
@[simp]
theorem algEquiv_eq (f : B ≃ₐ[A] B') (x : B) : minpoly A (f x) = minpoly A x :=
algHom_eq (f : B →ₐ[A] B') f.injective x
variable (A x)
/-- An element is a root of its minimal polynomial. -/
@[simp]
theorem aeval : aeval x (minpoly A x) = 0 := by
delta minpoly
split_ifs with hx
· exact (degree_lt_wf.min_mem _ hx).2
· exact aeval_zero _
/-- Given any `f : B →ₐ[A] B'` and any `x : L`, the minimal polynomial of `x` vanishes at `f x`. -/
@[simp]
theorem aeval_algHom (f : B →ₐ[A] B') (x : B) : (Polynomial.aeval (f x)) (minpoly A x) = 0 := by
rw [Polynomial.aeval_algHom, AlgHom.coe_comp, comp_apply, aeval, map_zero]
/-- A minimal polynomial is not `1`. -/
theorem ne_one [Nontrivial B] : minpoly A x ≠ 1 := by
intro h
refine (one_ne_zero : (1 : B) ≠ 0) ?_
simpa using congr_arg (Polynomial.aeval x) h
theorem map_ne_one [Nontrivial B] {R : Type*} [Semiring R] [Nontrivial R] (f : A →+* R) :
(minpoly A x).map f ≠ 1 := by
by_cases hx : IsIntegral A x
· exact mt ((monic hx).eq_one_of_map_eq_one f) (ne_one A x)
· rw [eq_zero hx, Polynomial.map_zero]
exact zero_ne_one
/-- A minimal polynomial is not a unit. -/
theorem not_isUnit [Nontrivial B] : ¬IsUnit (minpoly A x) := by
haveI : Nontrivial A := (algebraMap A B).domain_nontrivial
by_cases hx : IsIntegral A x
· exact mt (monic hx).eq_one_of_isUnit (ne_one A x)
· rw [eq_zero hx]
exact not_isUnit_zero
theorem mem_range_of_degree_eq_one (hx : (minpoly A x).degree = 1) :
x ∈ (algebraMap A B).range := by
have h : IsIntegral A x := by
by_contra h
rw [eq_zero h, degree_zero, ← WithBot.coe_one] at hx
exact ne_of_lt (show ⊥ < ↑1 from WithBot.bot_lt_coe 1) hx
have key := minpoly.aeval A x
rw [eq_X_add_C_of_degree_eq_one hx, (minpoly.monic h).leadingCoeff, C_1, one_mul, aeval_add,
aeval_C, aeval_X, ← eq_neg_iff_add_eq_zero, ← RingHom.map_neg] at key
exact ⟨-(minpoly A x).coeff 0, key.symm⟩
/-- The defining property of the minimal polynomial of an element `x`:
it is the monic polynomial with smallest degree that has `x` as its root. -/
theorem min {p : A[X]} (pmonic : p.Monic) (hp : Polynomial.aeval x p = 0) :
degree (minpoly A x) ≤ degree p := by
delta minpoly; split_ifs with hx
· exact le_of_not_lt (degree_lt_wf.not_lt_min _ hx ⟨pmonic, hp⟩)
· simp only [degree_zero, bot_le]
theorem unique' {p : A[X]} (hm : p.Monic) (hp : Polynomial.aeval x p = 0)
(hl : ∀ q : A[X], degree q < degree p → q = 0 ∨ Polynomial.aeval x q ≠ 0) :
p = minpoly A x := by
nontriviality A
have hx : IsIntegral A x := ⟨p, hm, hp⟩
obtain h | h := hl _ ((minpoly A x).degree_modByMonic_lt hm)
swap
· exact (h <| (aeval_modByMonic_eq_self_of_root hm hp).trans <| aeval A x).elim
obtain ⟨r, hr⟩ := (modByMonic_eq_zero_iff_dvd hm).1 h
rw [hr]
have hlead := congr_arg leadingCoeff hr
rw [mul_comm, leadingCoeff_mul_monic hm, (monic hx).leadingCoeff] at hlead
have : natDegree r ≤ 0 := by
have hr0 : r ≠ 0 := by
rintro rfl
exact ne_zero hx (mul_zero p ▸ hr)
apply_fun natDegree at hr
rw [hm.natDegree_mul' hr0] at hr
apply Nat.le_of_add_le_add_left
rw [add_zero]
exact hr.symm.trans_le (natDegree_le_natDegree <| min A x hm hp)
rw [eq_C_of_natDegree_le_zero this, ← Nat.eq_zero_of_le_zero this, ← leadingCoeff, ← hlead, C_1,
mul_one]
@[nontriviality]
theorem subsingleton [Subsingleton B] : minpoly A x = 1 := by
nontriviality A
have := minpoly.min A x monic_one (Subsingleton.elim _ _)
rw [degree_one] at this
rcases le_or_lt (minpoly A x).degree 0 with h | h
· rwa [(monic ⟨1, monic_one, by simp [eq_iff_true_of_subsingleton]⟩ :
(minpoly A x).Monic).degree_le_zero_iff_eq_one] at h
· exact (this.not_lt h).elim
end Ring
section CommRing
variable [CommRing A]
section Ring
variable [Ring B] [Algebra A B]
variable {x : B}
/-- The degree of a minimal polynomial, as a natural number, is positive. -/
theorem natDegree_pos [Nontrivial B] (hx : IsIntegral A x) : 0 < natDegree (minpoly A x) := by
rw [pos_iff_ne_zero]
intro ndeg_eq_zero
have eq_one : minpoly A x = 1 := by
rw [eq_C_of_natDegree_eq_zero ndeg_eq_zero]
convert C_1 (R := A)
simpa only [ndeg_eq_zero.symm] using (monic hx).leadingCoeff
simpa only [eq_one, map_one, one_ne_zero] using aeval A x
/-- The degree of a minimal polynomial is positive. -/
theorem degree_pos [Nontrivial B] (hx : IsIntegral A x) : 0 < degree (minpoly A x) :=
natDegree_pos_iff_degree_pos.mp (natDegree_pos hx)
section
variable [Nontrivial B]
open Polynomial in
theorem degree_eq_one_iff : (minpoly A x).degree = 1 ↔ x ∈ (algebraMap A B).range := by
refine ⟨minpoly.mem_range_of_degree_eq_one _ _, ?_⟩
rintro ⟨x, rfl⟩
haveI := Module.nontrivial A B
exact (degree_X_sub_C x ▸ minpoly.min A (algebraMap A B x) (monic_X_sub_C x) (by simp)).antisymm
(Nat.WithBot.add_one_le_of_lt <| minpoly.degree_pos isIntegral_algebraMap)
theorem natDegree_eq_one_iff :
(minpoly A x).natDegree = 1 ↔ x ∈ (algebraMap A B).range := by
rw [← Polynomial.degree_eq_iff_natDegree_eq_of_pos zero_lt_one]
exact degree_eq_one_iff
theorem two_le_natDegree_iff (int : IsIntegral A x) :
2 ≤ (minpoly A x).natDegree ↔ x ∉ (algebraMap A B).range := by
rw [iff_not_comm, ← natDegree_eq_one_iff, not_le]
exact ⟨fun h ↦ h.trans_lt one_lt_two, fun h ↦ by linarith only [minpoly.natDegree_pos int, h]⟩
theorem two_le_natDegree_subalgebra {B} [CommRing B] [Algebra A B] [Nontrivial B]
{S : Subalgebra A B} {x : B} (int : IsIntegral S x) : 2 ≤ (minpoly S x).natDegree ↔ x ∉ S := by
rw [two_le_natDegree_iff int, Iff.not]
apply Set.ext_iff.mp Subtype.range_val_subtype
end
/-- If `B/A` is an injective ring extension, and `a` is an element of `A`,
then the minimal polynomial of `algebraMap A B a` is `X - C a`. -/
theorem eq_X_sub_C_of_algebraMap_inj (a : A) (hf : Function.Injective (algebraMap A B)) :
minpoly A (algebraMap A B a) = X - C a := by
nontriviality A
refine (unique' A _ (monic_X_sub_C a) ?_ ?_).symm
· rw [map_sub, aeval_C, aeval_X, sub_self]
simp_rw [or_iff_not_imp_left]
intro q hl h0
rw [← natDegree_lt_natDegree_iff h0, natDegree_X_sub_C, Nat.lt_one_iff] at hl
rw [eq_C_of_natDegree_eq_zero hl] at h0 ⊢
rwa [aeval_C, map_ne_zero_iff _ hf, ← C_ne_zero]
end Ring
section IsDomain
variable [Ring B] [Algebra A B]
variable {x : B}
/-- If `a` strictly divides the minimal polynomial of `x`, then `x` cannot be a root for `a`. -/
theorem aeval_ne_zero_of_dvdNotUnit_minpoly {a : A[X]} (hx : IsIntegral A x) (hamonic : a.Monic)
(hdvd : DvdNotUnit a (minpoly A x)) : Polynomial.aeval x a ≠ 0 := by
refine fun ha => (min A x hamonic ha).not_lt (degree_lt_degree ?_)
obtain ⟨_, c, hu, he⟩ := hdvd
have hcm := hamonic.of_mul_monic_left (he.subst <| monic hx)
rw [he, hamonic.natDegree_mul hcm]
-- TODO: port Nat.lt_add_of_zero_lt_left from lean3 core
apply lt_add_of_pos_right
refine (lt_of_not_le fun h => hu ?_)
rw [eq_C_of_natDegree_le_zero h, ← Nat.eq_zero_of_le_zero h, ← leadingCoeff, hcm.leadingCoeff,
C_1]
exact isUnit_one
variable [IsDomain A] [IsDomain B]
/-- A minimal polynomial is irreducible. -/
theorem irreducible (hx : IsIntegral A x) : Irreducible (minpoly A x) := by
refine (irreducible_of_monic (monic hx) <| ne_one A x).2 fun f g hf hg he => ?_
rw [← hf.isUnit_iff, ← hg.isUnit_iff]
by_contra! h
have heval := congr_arg (Polynomial.aeval x) he
rw [aeval A x, aeval_mul, mul_eq_zero] at heval
cases' heval with heval heval
· exact aeval_ne_zero_of_dvdNotUnit_minpoly hx hf ⟨hf.ne_zero, g, h.2, he.symm⟩ heval
· refine aeval_ne_zero_of_dvdNotUnit_minpoly hx hg ⟨hg.ne_zero, f, h.1, ?_⟩ heval
rw [mul_comm, he]
end IsDomain
end CommRing
end minpoly
|
FieldTheory\Minpoly\Field.lean | /-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca, Johan Commelin
-/
import Mathlib.Algebra.Polynomial.FieldDivision
import Mathlib.FieldTheory.Minpoly.Basic
import Mathlib.RingTheory.Algebraic
/-!
# Minimal polynomials on an algebra over a field
This file specializes the theory of minpoly to the setting of field extensions
and derives some well-known properties, amongst which the fact that minimal polynomials
are irreducible, and uniquely determined by their defining property.
-/
open scoped Classical
open Polynomial Set Function minpoly
namespace minpoly
variable {A B : Type*}
variable (A) [Field A]
section Ring
variable [Ring B] [Algebra A B] (x : B)
/-- If an element `x` is a root of a nonzero polynomial `p`, then the degree of `p` is at least the
degree of the minimal polynomial of `x`. See also `minpoly.IsIntegrallyClosed.degree_le_of_ne_zero`
which relaxes the assumptions on `A` in exchange for stronger assumptions on `B`. -/
theorem degree_le_of_ne_zero {p : A[X]} (pnz : p ≠ 0) (hp : Polynomial.aeval x p = 0) :
degree (minpoly A x) ≤ degree p :=
calc
degree (minpoly A x) ≤ degree (p * C (leadingCoeff p)⁻¹) :=
min A x (monic_mul_leadingCoeff_inv pnz) (by simp [hp])
_ = degree p := degree_mul_leadingCoeff_inv p pnz
theorem ne_zero_of_finite (e : B) [FiniteDimensional A B] : minpoly A e ≠ 0 :=
minpoly.ne_zero <| .of_finite A _
/-- The minimal polynomial of an element `x` is uniquely characterized by its defining property:
if there is another monic polynomial of minimal degree that has `x` as a root, then this polynomial
is equal to the minimal polynomial of `x`. See also `minpoly.IsIntegrallyClosed.Minpoly.unique`
which relaxes the assumptions on `A` in exchange for stronger assumptions on `B`. -/
theorem unique {p : A[X]} (pmonic : p.Monic) (hp : Polynomial.aeval x p = 0)
(pmin : ∀ q : A[X], q.Monic → Polynomial.aeval x q = 0 → degree p ≤ degree q) :
p = minpoly A x := by
have hx : IsIntegral A x := ⟨p, pmonic, hp⟩
symm; apply eq_of_sub_eq_zero
by_contra hnz
apply degree_le_of_ne_zero A x hnz (by simp [hp]) |>.not_lt
apply degree_sub_lt _ (minpoly.ne_zero hx)
· rw [(monic hx).leadingCoeff, pmonic.leadingCoeff]
· exact le_antisymm (min A x pmonic hp) (pmin (minpoly A x) (monic hx) (aeval A x))
/-- If an element `x` is a root of a polynomial `p`, then the minimal polynomial of `x` divides `p`.
See also `minpoly.isIntegrallyClosed_dvd` which relaxes the assumptions on `A` in exchange for
stronger assumptions on `B`. -/
theorem dvd {p : A[X]} (hp : Polynomial.aeval x p = 0) : minpoly A x ∣ p := by
by_cases hp0 : p = 0
· simp only [hp0, dvd_zero]
have hx : IsIntegral A x := IsAlgebraic.isIntegral ⟨p, hp0, hp⟩
rw [← modByMonic_eq_zero_iff_dvd (monic hx)]
by_contra hnz
apply degree_le_of_ne_zero A x hnz
((aeval_modByMonic_eq_self_of_root (monic hx) (aeval _ _)).trans hp) |>.not_lt
exact degree_modByMonic_lt _ (monic hx)
variable {A x} in
lemma dvd_iff {p : A[X]} : minpoly A x ∣ p ↔ Polynomial.aeval x p = 0 :=
⟨fun ⟨q, hq⟩ ↦ by rw [hq, map_mul, aeval, zero_mul], minpoly.dvd A x⟩
theorem isRadical [IsReduced B] : IsRadical (minpoly A x) := fun n p dvd ↦ by
rw [dvd_iff] at dvd ⊢; rw [map_pow] at dvd; exact IsReduced.eq_zero _ ⟨n, dvd⟩
theorem dvd_map_of_isScalarTower (A K : Type*) {R : Type*} [CommRing A] [Field K] [CommRing R]
[Algebra A K] [Algebra A R] [Algebra K R] [IsScalarTower A K R] (x : R) :
minpoly K x ∣ (minpoly A x).map (algebraMap A K) := by
refine minpoly.dvd K x ?_
rw [aeval_map_algebraMap, minpoly.aeval]
theorem dvd_map_of_isScalarTower' (R : Type*) {S : Type*} (K L : Type*) [CommRing R]
[CommRing S] [Field K] [CommRing L] [Algebra R S] [Algebra R K] [Algebra S L] [Algebra K L]
[Algebra R L] [IsScalarTower R K L] [IsScalarTower R S L] (s : S) :
minpoly K (algebraMap S L s) ∣ map (algebraMap R K) (minpoly R s) := by
apply minpoly.dvd K (algebraMap S L s)
rw [← map_aeval_eq_aeval_map, minpoly.aeval, map_zero]
rw [← IsScalarTower.algebraMap_eq, ← IsScalarTower.algebraMap_eq]
/-- If `y` is a conjugate of `x` over a field `K`, then it is a conjugate over a subring `R`. -/
theorem aeval_of_isScalarTower (R : Type*) {K T U : Type*} [CommRing R] [Field K] [CommRing T]
[Algebra R K] [Algebra K T] [Algebra R T] [IsScalarTower R K T] [CommSemiring U] [Algebra K U]
[Algebra R U] [IsScalarTower R K U] (x : T) (y : U)
(hy : Polynomial.aeval y (minpoly K x) = 0) : Polynomial.aeval y (minpoly R x) = 0 :=
aeval_map_algebraMap K y (minpoly R x) ▸
eval₂_eq_zero_of_dvd_of_eval₂_eq_zero (algebraMap K U) y
(minpoly.dvd_map_of_isScalarTower R K x) hy
/-- See also `minpoly.ker_eval` which relaxes the assumptions on `A` in exchange for
stronger assumptions on `B`. -/
@[simp]
lemma ker_aeval_eq_span_minpoly :
RingHom.ker (Polynomial.aeval x) = A[X] ∙ minpoly A x := by
ext p
simp_rw [RingHom.mem_ker, ← minpoly.dvd_iff, Submodule.mem_span_singleton,
dvd_iff_exists_eq_mul_left, smul_eq_mul, eq_comm (a := p)]
variable {A x}
theorem eq_of_irreducible_of_monic [Nontrivial B] {p : A[X]} (hp1 : Irreducible p)
(hp2 : Polynomial.aeval x p = 0) (hp3 : p.Monic) : p = minpoly A x :=
let ⟨_, hq⟩ := dvd A x hp2
eq_of_monic_of_associated hp3 (monic ⟨p, ⟨hp3, hp2⟩⟩) <|
mul_one (minpoly A x) ▸ hq.symm ▸ Associated.mul_left _
(associated_one_iff_isUnit.2 <| (hp1.isUnit_or_isUnit hq).resolve_left <| not_isUnit A x)
theorem eq_of_irreducible [Nontrivial B] {p : A[X]} (hp1 : Irreducible p)
(hp2 : Polynomial.aeval x p = 0) : p * C p.leadingCoeff⁻¹ = minpoly A x := by
have : p.leadingCoeff ≠ 0 := leadingCoeff_ne_zero.mpr hp1.ne_zero
apply eq_of_irreducible_of_monic
· exact Associated.irreducible ⟨⟨C p.leadingCoeff⁻¹, C p.leadingCoeff,
by rwa [← C_mul, inv_mul_cancel, C_1], by rwa [← C_mul, mul_inv_cancel, C_1]⟩, rfl⟩ hp1
· rw [aeval_mul, hp2, zero_mul]
· rwa [Polynomial.Monic, leadingCoeff_mul, leadingCoeff_C, mul_inv_cancel]
theorem add_algebraMap {B : Type*} [CommRing B] [Algebra A B] {x : B} (hx : IsIntegral A x)
(a : A) : minpoly A (x + algebraMap A B a) = (minpoly A x).comp (X - C a) := by
refine (minpoly.unique _ _ ((minpoly.monic hx).comp_X_sub_C _) ?_ fun q qmo hq => ?_).symm
· simp [aeval_comp]
· have : (Polynomial.aeval x) (q.comp (X + C a)) = 0 := by simpa [aeval_comp] using hq
have H := minpoly.min A x (qmo.comp_X_add_C _) this
rw [degree_eq_natDegree qmo.ne_zero,
degree_eq_natDegree ((minpoly.monic hx).comp_X_sub_C _).ne_zero, natDegree_comp,
natDegree_X_sub_C, mul_one]
rwa [degree_eq_natDegree (minpoly.ne_zero hx),
degree_eq_natDegree (qmo.comp_X_add_C _).ne_zero, natDegree_comp,
natDegree_X_add_C, mul_one] at H
theorem sub_algebraMap {B : Type*} [CommRing B] [Algebra A B] {x : B} (hx : IsIntegral A x)
(a : A) : minpoly A (x - algebraMap A B a) = (minpoly A x).comp (X + C a) := by
simpa [sub_eq_add_neg] using add_algebraMap hx (-a)
section AlgHomFintype
/-- A technical finiteness result. -/
noncomputable def Fintype.subtypeProd {E : Type*} {X : Set E} (hX : X.Finite) {L : Type*}
(F : E → Multiset L) : Fintype (∀ x : X, { l : L // l ∈ F x }) :=
@Pi.fintype _ _ _ (Finite.fintype hX) _
variable (F E K : Type*) [Field F] [Ring E] [CommRing K] [IsDomain K] [Algebra F E] [Algebra F K]
[FiniteDimensional F E]
-- Porting note (#11083): removed `noncomputable!` since it seems not to be slow in lean 4,
-- though it isn't very computable in practice (since neither `finrank` nor `finBasis` are).
/-- Function from Hom_K(E,L) to pi type Π (x : basis), roots of min poly of x -/
def rootsOfMinPolyPiType (φ : E →ₐ[F] K)
(x : range (FiniteDimensional.finBasis F E : _ → E)) :
{ l : K // l ∈ (minpoly F x.1).aroots K } :=
⟨φ x, by
rw [mem_roots_map (minpoly.ne_zero_of_finite F x.val),
← aeval_def, aeval_algHom_apply, minpoly.aeval, map_zero]⟩
theorem aux_inj_roots_of_min_poly : Injective (rootsOfMinPolyPiType F E K) := by
intro f g h
-- needs explicit coercion on the RHS
suffices (f : E →ₗ[F] K) = (g : E →ₗ[F] K) by rwa [DFunLike.ext'_iff] at this ⊢
rw [funext_iff] at h
exact LinearMap.ext_on (FiniteDimensional.finBasis F E).span_eq fun e he =>
Subtype.ext_iff.mp (h ⟨e, he⟩)
/-- Given field extensions `E/F` and `K/F`, with `E/F` finite, there are finitely many `F`-algebra
homomorphisms `E →ₐ[K] K`. -/
noncomputable instance AlgHom.fintype : Fintype (E →ₐ[F] K) :=
@Fintype.ofInjective _ _
(Fintype.subtypeProd (finite_range (FiniteDimensional.finBasis F E)) fun e =>
(minpoly F e).aroots K)
_ (aux_inj_roots_of_min_poly F E K)
end AlgHomFintype
variable (B) [Nontrivial B]
/-- If `B/K` is a nontrivial algebra over a field, and `x` is an element of `K`,
then the minimal polynomial of `algebraMap K B x` is `X - C x`. -/
theorem eq_X_sub_C (a : A) : minpoly A (algebraMap A B a) = X - C a :=
eq_X_sub_C_of_algebraMap_inj a (algebraMap A B).injective
theorem eq_X_sub_C' (a : A) : minpoly A a = X - C a :=
eq_X_sub_C A a
variable (A)
/-- The minimal polynomial of `0` is `X`. -/
@[simp]
theorem zero : minpoly A (0 : B) = X := by
simpa only [add_zero, C_0, sub_eq_add_neg, neg_zero, RingHom.map_zero] using eq_X_sub_C B (0 : A)
/-- The minimal polynomial of `1` is `X - 1`. -/
@[simp]
theorem one : minpoly A (1 : B) = X - 1 := by
simpa only [RingHom.map_one, C_1, sub_eq_add_neg] using eq_X_sub_C B (1 : A)
end Ring
section IsDomain
variable [Ring B] [IsDomain B] [Algebra A B]
variable {A} {x : B}
/-- A minimal polynomial is prime. -/
theorem prime (hx : IsIntegral A x) : Prime (minpoly A x) := by
refine ⟨minpoly.ne_zero hx, not_isUnit A x, ?_⟩
rintro p q ⟨d, h⟩
have : Polynomial.aeval x (p * q) = 0 := by simp [h, aeval A x]
replace : Polynomial.aeval x p = 0 ∨ Polynomial.aeval x q = 0 := by simpa
exact Or.imp (dvd A x) (dvd A x) this
/-- If `L/K` is a field extension and an element `y` of `K` is a root of the minimal polynomial
of an element `x ∈ L`, then `y` maps to `x` under the field embedding. -/
theorem root {x : B} (hx : IsIntegral A x) {y : A} (h : IsRoot (minpoly A x) y) :
algebraMap A B y = x := by
have key : minpoly A x = X - C y := eq_of_monic_of_associated (monic hx) (monic_X_sub_C y)
(associated_of_dvd_dvd ((irreducible_X_sub_C y).dvd_symm (irreducible hx) (dvd_iff_isRoot.2 h))
(dvd_iff_isRoot.2 h))
have := aeval A x
rwa [key, map_sub, aeval_X, aeval_C, sub_eq_zero, eq_comm] at this
/-- The constant coefficient of the minimal polynomial of `x` is `0` if and only if `x = 0`. -/
@[simp]
theorem coeff_zero_eq_zero (hx : IsIntegral A x) : coeff (minpoly A x) 0 = 0 ↔ x = 0 := by
constructor
· intro h
have zero_root := zero_isRoot_of_coeff_zero_eq_zero h
rw [← root hx zero_root]
exact RingHom.map_zero _
· rintro rfl
simp
/-- The minimal polynomial of a nonzero element has nonzero constant coefficient. -/
theorem coeff_zero_ne_zero (hx : IsIntegral A x) (h : x ≠ 0) : coeff (minpoly A x) 0 ≠ 0 := by
contrapose! h
simpa only [hx, coeff_zero_eq_zero] using h
end IsDomain
end minpoly
section AlgHom
variable {K L} [Field K] [CommRing L] [IsDomain L] [Algebra K L]
/-- The minimal polynomial (over `K`) of `σ : Gal(L/K)` is `X ^ (orderOf σ) - 1`. -/
lemma minpoly_algEquiv_toLinearMap (σ : L ≃ₐ[K] L) (hσ : IsOfFinOrder σ) :
minpoly K σ.toLinearMap = X ^ (orderOf σ) - C 1 := by
refine (minpoly.unique _ _ (monic_X_pow_sub_C _ hσ.orderOf_pos.ne.symm) ?_ ?_).symm
· rw [map_sub]
simp [← AlgEquiv.pow_toLinearMap, pow_orderOf_eq_one]
· intros q hq hs
rw [degree_eq_natDegree hq.ne_zero, degree_X_pow_sub_C hσ.orderOf_pos, Nat.cast_le, ← not_lt]
intro H
rw [aeval_eq_sum_range' H, ← Fin.sum_univ_eq_sum_range] at hs
simp_rw [← AlgEquiv.pow_toLinearMap] at hs
apply hq.ne_zero
simpa using Fintype.linearIndependent_iff.mp
(((linearIndependent_algHom_toLinearMap' K L L).comp _ AlgEquiv.coe_algHom_injective).comp _
(Subtype.val_injective.comp ((finEquivPowers σ hσ).injective)))
(q.coeff ∘ (↑)) hs ⟨_, H⟩
/-- The minimal polynomial (over `K`) of `σ : Gal(L/K)` is `X ^ (orderOf σ) - 1`. -/
lemma minpoly_algHom_toLinearMap (σ : L →ₐ[K] L) (hσ : IsOfFinOrder σ) :
minpoly K σ.toLinearMap = X ^ (orderOf σ) - C 1 := by
have : orderOf σ = orderOf (AlgEquiv.algHomUnitsEquiv _ _ hσ.unit) := by
rw [← MonoidHom.coe_coe, orderOf_injective (AlgEquiv.algHomUnitsEquiv K L)
(AlgEquiv.algHomUnitsEquiv K L).injective, ← orderOf_units, IsOfFinOrder.val_unit]
rw [this, ← minpoly_algEquiv_toLinearMap]
· apply congr_arg
ext
simp
· rwa [← orderOf_pos_iff, ← this, orderOf_pos_iff]
end AlgHom
|
FieldTheory\Minpoly\IsIntegrallyClosed.lean | /-
Copyright (c) 2019 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca, Paul Lezeau, Junyan Xu
-/
import Mathlib.RingTheory.AdjoinRoot
import Mathlib.FieldTheory.Minpoly.Field
import Mathlib.RingTheory.Polynomial.GaussLemma
/-!
# Minimal polynomials over a GCD monoid
This file specializes the theory of minpoly to the case of an algebra over a GCD monoid.
## Main results
* `minpoly.isIntegrallyClosed_eq_field_fractions`: For integrally closed domains, the minimal
polynomial over the ring is the same as the minimal polynomial over the fraction field.
* `minpoly.isIntegrallyClosed_dvd` : For integrally closed domains, the minimal polynomial divides
any primitive polynomial that has the integral element as root.
* `IsIntegrallyClosed.Minpoly.unique` : The minimal polynomial of an element `x` is
uniquely characterized by its defining property: if there is another monic polynomial of minimal
degree that has `x` as a root, then this polynomial is equal to the minimal polynomial of `x`.
-/
open Polynomial Set Function minpoly
namespace minpoly
variable {R S : Type*} [CommRing R] [CommRing S] [IsDomain R] [Algebra R S]
section
variable (K L : Type*) [Field K] [Algebra R K] [IsFractionRing R K] [CommRing L] [Nontrivial L]
[Algebra R L] [Algebra S L] [Algebra K L] [IsScalarTower R K L] [IsScalarTower R S L]
variable [IsIntegrallyClosed R]
/-- For integrally closed domains, the minimal polynomial over the ring is the same as the minimal
polynomial over the fraction field. See `minpoly.isIntegrallyClosed_eq_field_fractions'` if
`S` is already a `K`-algebra. -/
theorem isIntegrallyClosed_eq_field_fractions [IsDomain S] {s : S} (hs : IsIntegral R s) :
minpoly K (algebraMap S L s) = (minpoly R s).map (algebraMap R K) := by
refine (eq_of_irreducible_of_monic ?_ ?_ ?_).symm
· exact ((monic hs).irreducible_iff_irreducible_map_fraction_map).1 (irreducible hs)
· rw [aeval_map_algebraMap, aeval_algebraMap_apply, aeval, map_zero]
· exact (monic hs).map _
/-- For integrally closed domains, the minimal polynomial over the ring is the same as the minimal
polynomial over the fraction field. Compared to `minpoly.isIntegrallyClosed_eq_field_fractions`,
this version is useful if the element is in a ring that is already a `K`-algebra. -/
theorem isIntegrallyClosed_eq_field_fractions' [IsDomain S] [Algebra K S] [IsScalarTower R K S]
{s : S} (hs : IsIntegral R s) : minpoly K s = (minpoly R s).map (algebraMap R K) := by
let L := FractionRing S
rw [← isIntegrallyClosed_eq_field_fractions K L hs, algebraMap_eq (IsFractionRing.injective S L)]
end
variable [IsDomain S] [NoZeroSMulDivisors R S]
variable [IsIntegrallyClosed R]
/-- For integrally closed rings, the minimal polynomial divides any polynomial that has the
integral element as root. See also `minpoly.dvd` which relaxes the assumptions on `S`
in exchange for stronger assumptions on `R`. -/
theorem isIntegrallyClosed_dvd {s : S} (hs : IsIntegral R s) {p : R[X]}
(hp : Polynomial.aeval s p = 0) : minpoly R s ∣ p := by
let K := FractionRing R
let L := FractionRing S
let _ : Algebra K L := FractionRing.liftAlgebra R L
have := FractionRing.isScalarTower_liftAlgebra R L
have : minpoly K (algebraMap S L s) ∣ map (algebraMap R K) (p %ₘ minpoly R s) := by
rw [map_modByMonic _ (minpoly.monic hs), modByMonic_eq_sub_mul_div]
· refine dvd_sub (minpoly.dvd K (algebraMap S L s) ?_) ?_
· rw [← map_aeval_eq_aeval_map, hp, map_zero]
rw [← IsScalarTower.algebraMap_eq, ← IsScalarTower.algebraMap_eq]
apply dvd_mul_of_dvd_left
rw [isIntegrallyClosed_eq_field_fractions K L hs]
exact Monic.map _ (minpoly.monic hs)
rw [isIntegrallyClosed_eq_field_fractions _ _ hs,
map_dvd_map (algebraMap R K) (IsFractionRing.injective R K) (minpoly.monic hs)] at this
rw [← modByMonic_eq_zero_iff_dvd (minpoly.monic hs)]
exact Polynomial.eq_zero_of_dvd_of_degree_lt this (degree_modByMonic_lt p <| minpoly.monic hs)
theorem isIntegrallyClosed_dvd_iff {s : S} (hs : IsIntegral R s) (p : R[X]) :
Polynomial.aeval s p = 0 ↔ minpoly R s ∣ p :=
⟨fun hp => isIntegrallyClosed_dvd hs hp, fun hp => by
simpa only [RingHom.mem_ker, RingHom.coe_comp, coe_evalRingHom, coe_mapRingHom,
Function.comp_apply, eval_map, ← aeval_def] using
aeval_eq_zero_of_dvd_aeval_eq_zero hp (minpoly.aeval R s)⟩
theorem ker_eval {s : S} (hs : IsIntegral R s) :
RingHom.ker ((Polynomial.aeval s).toRingHom : R[X] →+* S) =
Ideal.span ({minpoly R s} : Set R[X]) := by
ext p
simp_rw [RingHom.mem_ker, AlgHom.toRingHom_eq_coe, AlgHom.coe_toRingHom,
isIntegrallyClosed_dvd_iff hs, ← Ideal.mem_span_singleton]
/-- If an element `x` is a root of a nonzero polynomial `p`, then the degree of `p` is at least the
degree of the minimal polynomial of `x`. See also `minpoly.degree_le_of_ne_zero` which relaxes the
assumptions on `S` in exchange for stronger assumptions on `R`. -/
theorem IsIntegrallyClosed.degree_le_of_ne_zero {s : S} (hs : IsIntegral R s) {p : R[X]}
(hp0 : p ≠ 0) (hp : Polynomial.aeval s p = 0) : degree (minpoly R s) ≤ degree p := by
rw [degree_eq_natDegree (minpoly.ne_zero hs), degree_eq_natDegree hp0]
norm_cast
exact natDegree_le_of_dvd ((isIntegrallyClosed_dvd_iff hs _).mp hp) hp0
/-- The minimal polynomial of an element `x` is uniquely characterized by its defining property:
if there is another monic polynomial of minimal degree that has `x` as a root, then this polynomial
is equal to the minimal polynomial of `x`. See also `minpoly.unique` which relaxes the
assumptions on `S` in exchange for stronger assumptions on `R`. -/
theorem _root_.IsIntegrallyClosed.minpoly.unique {s : S} {P : R[X]} (hmo : P.Monic)
(hP : Polynomial.aeval s P = 0)
(Pmin : ∀ Q : R[X], Q.Monic → Polynomial.aeval s Q = 0 → degree P ≤ degree Q) :
P = minpoly R s := by
have hs : IsIntegral R s := ⟨P, hmo, hP⟩
symm; apply eq_of_sub_eq_zero
by_contra hnz
refine IsIntegrallyClosed.degree_le_of_ne_zero hs hnz (by simp [hP]) |>.not_lt ?_
refine degree_sub_lt ?_ (ne_zero hs) ?_
· exact le_antisymm (min R s hmo hP) (Pmin (minpoly R s) (monic hs) (aeval R s))
· rw [(monic hs).leadingCoeff, hmo.leadingCoeff]
theorem prime_of_isIntegrallyClosed {x : S} (hx : IsIntegral R x) : Prime (minpoly R x) := by
refine
⟨(minpoly.monic hx).ne_zero,
⟨fun h_contra => (ne_of_lt (minpoly.degree_pos hx)) (degree_eq_zero_of_isUnit h_contra).symm,
fun a b h => or_iff_not_imp_left.mpr fun h' => ?_⟩⟩
rw [← minpoly.isIntegrallyClosed_dvd_iff hx] at h' h ⊢
rw [aeval_mul] at h
exact eq_zero_of_ne_zero_of_mul_left_eq_zero h' h
noncomputable section AdjoinRoot
open Algebra Polynomial AdjoinRoot
variable {x : S}
theorem ToAdjoin.injective (hx : IsIntegral R x) : Function.Injective (Minpoly.toAdjoin R x) := by
refine (injective_iff_map_eq_zero _).2 fun P₁ hP₁ => ?_
obtain ⟨P, rfl⟩ := mk_surjective P₁
rwa [Minpoly.toAdjoin_apply', liftHom_mk, ← Subalgebra.coe_eq_zero, aeval_subalgebra_coe,
isIntegrallyClosed_dvd_iff hx, ← AdjoinRoot.mk_eq_zero] at hP₁
/-- The algebra isomorphism `AdjoinRoot (minpoly R x) ≃ₐ[R] adjoin R x` -/
@[simps!]
def equivAdjoin (hx : IsIntegral R x) : AdjoinRoot (minpoly R x) ≃ₐ[R] adjoin R ({x} : Set S) :=
AlgEquiv.ofBijective (Minpoly.toAdjoin R x)
⟨minpoly.ToAdjoin.injective hx, Minpoly.toAdjoin.surjective R x⟩
/-- The `PowerBasis` of `adjoin R {x}` given by `x`. See `Algebra.adjoin.powerBasis` for a version
over a field. -/
def _root_.Algebra.adjoin.powerBasis' (hx : IsIntegral R x) :
PowerBasis R (Algebra.adjoin R ({x} : Set S)) :=
PowerBasis.map (AdjoinRoot.powerBasis' (minpoly.monic hx)) (minpoly.equivAdjoin hx)
@[simp]
theorem _root_.Algebra.adjoin.powerBasis'_dim (hx : IsIntegral R x) :
(Algebra.adjoin.powerBasis' hx).dim = (minpoly R x).natDegree := rfl
@[simp]
theorem _root_.Algebra.adjoin.powerBasis'_gen (hx : IsIntegral R x) :
(adjoin.powerBasis' hx).gen = ⟨x, SetLike.mem_coe.1 <| subset_adjoin <| mem_singleton x⟩ := by
rw [Algebra.adjoin.powerBasis', PowerBasis.map_gen, AdjoinRoot.powerBasis'_gen, equivAdjoin,
AlgEquiv.ofBijective_apply, Minpoly.toAdjoin, liftHom_root]
/-- The power basis given by `x` if `B.gen ∈ adjoin R {x}`. -/
noncomputable def _root_.PowerBasis.ofGenMemAdjoin' (B : PowerBasis R S) (hint : IsIntegral R x)
(hx : B.gen ∈ adjoin R ({x} : Set S)) : PowerBasis R S :=
(Algebra.adjoin.powerBasis' hint).map <|
(Subalgebra.equivOfEq _ _ <| PowerBasis.adjoin_eq_top_of_gen_mem_adjoin hx).trans
Subalgebra.topEquiv
@[simp]
theorem _root_.PowerBasis.ofGenMemAdjoin'_dim (B : PowerBasis R S) (hint : IsIntegral R x)
(hx : B.gen ∈ adjoin R ({x} : Set S)) :
(B.ofGenMemAdjoin' hint hx).dim = (minpoly R x).natDegree := rfl
@[simp]
theorem _root_.PowerBasis.ofGenMemAdjoin'_gen (B : PowerBasis R S) (hint : IsIntegral R x)
(hx : B.gen ∈ adjoin R ({x} : Set S)) :
(B.ofGenMemAdjoin' hint hx).gen = x := by
simp [PowerBasis.ofGenMemAdjoin']
end AdjoinRoot
end minpoly
|
FieldTheory\Minpoly\MinpolyDiv.lean | /-
Copyright (c) 2023 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.FieldTheory.Minpoly.IsIntegrallyClosed
import Mathlib.FieldTheory.PrimitiveElement
import Mathlib.FieldTheory.IsAlgClosed.Basic
/-!
# Results about `minpoly R x / (X - C x)`
## Main definition
- `minpolyDiv`: The polynomial `minpoly R x / (X - C x)`.
We used the contents of this file to describe the dual basis of a powerbasis under the trace form.
See `traceForm_dualBasis_powerBasis_eq`.
## Main results
- `span_coeff_minpolyDiv`: The coefficients of `minpolyDiv` spans `R<x>`.
-/
open Polynomial FiniteDimensional
variable (R K) {L S} [CommRing R] [Field K] [Field L] [CommRing S] [Algebra R S] [Algebra K L]
variable (x : S)
/-- `minpolyDiv R x : S[X]` for `x : S` is the polynomial `minpoly R x / (X - C x)`. -/
noncomputable def minpolyDiv : S[X] := (minpoly R x).map (algebraMap R S) /ₘ (X - C x)
lemma minpolyDiv_spec :
minpolyDiv R x * (X - C x) = (minpoly R x).map (algebraMap R S) := by
delta minpolyDiv
rw [mul_comm, mul_divByMonic_eq_iff_isRoot, IsRoot, eval_map, ← aeval_def, minpoly.aeval]
lemma coeff_minpolyDiv (i) : coeff (minpolyDiv R x) i =
algebraMap R S (coeff (minpoly R x) (i + 1)) + coeff (minpolyDiv R x) (i + 1) * x := by
rw [← coeff_map, ← minpolyDiv_spec R x]; simp [mul_sub]
variable (hx : IsIntegral R x) {R x}
lemma minpolyDiv_ne_zero [Nontrivial S] : minpolyDiv R x ≠ 0 := by
intro e
have := minpolyDiv_spec R x
rw [e, zero_mul] at this
exact ((minpoly.monic hx).map (algebraMap R S)).ne_zero this.symm
lemma minpolyDiv_eq_zero (hx : ¬IsIntegral R x) : minpolyDiv R x = 0 := by
delta minpolyDiv minpoly
rw [dif_neg hx, Polynomial.map_zero, zero_divByMonic]
lemma minpolyDiv_monic : Monic (minpolyDiv R x) := by
nontriviality S
have := congr_arg leadingCoeff (minpolyDiv_spec R x)
rw [leadingCoeff_mul', ((minpoly.monic hx).map (algebraMap R S)).leadingCoeff] at this
· simpa using this
· simpa using minpolyDiv_ne_zero hx
lemma eval_minpolyDiv_self : (minpolyDiv R x).eval x = aeval x (derivative <| minpoly R x) := by
rw [aeval_def, ← eval_map, ← derivative_map, ← minpolyDiv_spec R x]; simp
lemma minpolyDiv_eval_eq_zero_of_ne_of_aeval_eq_zero [IsDomain S]
{y} (hxy : y ≠ x) (hy : aeval y (minpoly R x) = 0) : (minpolyDiv R x).eval y = 0 := by
rw [aeval_def, ← eval_map, ← minpolyDiv_spec R x] at hy
simp only [eval_mul, eval_sub, eval_X, eval_C, mul_eq_zero] at hy
exact hy.resolve_right (by rwa [sub_eq_zero])
lemma eval₂_minpolyDiv_of_eval₂_eq_zero {T} [CommRing T]
[IsDomain T] [DecidableEq T] {x y}
(σ : S →+* T) (hy : eval₂ (σ.comp (algebraMap R S)) y (minpoly R x) = 0) :
eval₂ σ y (minpolyDiv R x) =
if σ x = y then σ (aeval x (derivative <| minpoly R x)) else 0 := by
split_ifs with h
· rw [← h, eval₂_hom, eval_minpolyDiv_self]
· rw [← eval₂_map, ← minpolyDiv_spec] at hy
simpa [sub_eq_zero, Ne.symm h] using hy
lemma eval₂_minpolyDiv_self {T} [CommRing T] [Algebra R T] [IsDomain T] [DecidableEq T] (x : S)
(σ₁ σ₂ : S →ₐ[R] T) :
eval₂ σ₁ (σ₂ x) (minpolyDiv R x) =
if σ₁ x = σ₂ x then σ₁ (aeval x (derivative <| minpoly R x)) else 0 := by
apply eval₂_minpolyDiv_of_eval₂_eq_zero
rw [AlgHom.comp_algebraMap, ← σ₂.comp_algebraMap, ← eval₂_map, ← RingHom.coe_coe, eval₂_hom,
eval_map, ← aeval_def, minpoly.aeval, map_zero]
lemma eval_minpolyDiv_of_aeval_eq_zero [IsDomain S] [DecidableEq S]
{y} (hy : aeval y (minpoly R x) = 0) :
(minpolyDiv R x).eval y = if x = y then aeval x (derivative <| minpoly R x) else 0 := by
rw [eval, eval₂_minpolyDiv_of_eval₂_eq_zero, RingHom.id_apply, RingHom.id_apply]
simpa [aeval_def] using hy
lemma natDegree_minpolyDiv_succ [Nontrivial S] :
natDegree (minpolyDiv R x) + 1 = natDegree (minpoly R x) := by
rw [← (minpoly.monic hx).natDegree_map (algebraMap R S), ← minpolyDiv_spec, natDegree_mul']
· simp
· simpa using minpolyDiv_ne_zero hx
lemma natDegree_minpolyDiv :
natDegree (minpolyDiv R x) = natDegree (minpoly R x) - 1 := by
nontriviality S
by_cases hx : IsIntegral R x
· rw [← natDegree_minpolyDiv_succ hx]; rfl
· rw [minpolyDiv_eq_zero hx, minpoly.eq_zero hx]; rfl
lemma natDegree_minpolyDiv_lt [Nontrivial S] :
natDegree (minpolyDiv R x) < natDegree (minpoly R x) := by
rw [← natDegree_minpolyDiv_succ hx]
exact Nat.lt_succ_self _
lemma coeff_minpolyDiv_mem_adjoin (x : S) (i) :
coeff (minpolyDiv R x) i ∈ Algebra.adjoin R {x} := by
by_contra H
have : ∀ j, coeff (minpolyDiv R x) (i + j) ∉ Algebra.adjoin R {x} := by
intro j; induction j with
| zero => exact H
| succ j IH =>
intro H; apply IH
rw [coeff_minpolyDiv]
refine add_mem ?_ (mul_mem H (Algebra.self_mem_adjoin_singleton R x))
exact Subalgebra.algebraMap_mem _ _
apply this (natDegree (minpolyDiv R x) + 1)
rw [coeff_eq_zero_of_natDegree_lt]
· exact zero_mem _
· refine (Nat.le_add_left _ i).trans_lt ?_
rw [← add_assoc]
exact Nat.lt_succ_self _
lemma minpolyDiv_eq_of_isIntegrallyClosed [IsDomain R] [IsIntegrallyClosed R] [IsDomain S]
[Algebra R K] [Algebra K S] [IsScalarTower R K S] [IsFractionRing R K] :
minpolyDiv R x = minpolyDiv K x := by
delta minpolyDiv
rw [IsScalarTower.algebraMap_eq R K S, ← map_map,
← minpoly.isIntegrallyClosed_eq_field_fractions' _ hx]
lemma coeff_minpolyDiv_sub_pow_mem_span {i} (hi : i ≤ natDegree (minpolyDiv R x)) :
coeff (minpolyDiv R x) (natDegree (minpolyDiv R x) - i) - x ^ i ∈
Submodule.span R ((x ^ ·) '' Set.Iio i) := by
induction i with
| zero => simp [(minpolyDiv_monic hx).leadingCoeff]
| succ i IH =>
rw [coeff_minpolyDiv, add_sub_assoc, pow_succ, ← sub_mul, Algebra.algebraMap_eq_smul_one]
refine add_mem ?_ ?_
· apply Submodule.smul_mem
apply Submodule.subset_span
exact ⟨0, Nat.zero_lt_succ _, pow_zero _⟩
· rw [← tsub_tsub, tsub_add_cancel_of_le (le_tsub_of_add_le_left (b := 1) hi)]
apply SetLike.le_def.mp ?_
(Submodule.mul_mem_mul (IH ((Nat.le_succ _).trans hi))
(Submodule.mem_span_singleton_self x))
rw [Submodule.span_mul_span, Set.mul_singleton, Set.image_image]
apply Submodule.span_mono
rintro _ ⟨j, hj, rfl⟩
rw [Set.mem_Iio] at hj
exact ⟨j + 1, Nat.add_lt_of_lt_sub hj, pow_succ x j⟩
lemma span_coeff_minpolyDiv :
Submodule.span R (Set.range (coeff (minpolyDiv R x))) =
Subalgebra.toSubmodule (Algebra.adjoin R {x}) := by
nontriviality S
classical
apply le_antisymm
· rw [Submodule.span_le]
rintro _ ⟨i, rfl⟩
apply coeff_minpolyDiv_mem_adjoin
· rw [← Submodule.span_range_natDegree_eq_adjoin (minpoly.monic hx) (minpoly.aeval _ _),
Submodule.span_le]
simp only [Finset.coe_image, Finset.coe_range, Set.image_subset_iff]
intro i
apply Nat.strongInductionOn i
intro i hi hi'
have : coeff (minpolyDiv R x) (natDegree (minpolyDiv R x) - i) ∈
Submodule.span R (Set.range (coeff (minpolyDiv R x))) :=
Submodule.subset_span (Set.mem_range_self _)
rw [Set.mem_preimage, SetLike.mem_coe, ← Submodule.sub_mem_iff_right _ this]
refine SetLike.le_def.mp ?_ (coeff_minpolyDiv_sub_pow_mem_span hx ?_)
· rw [Submodule.span_le, Set.image_subset_iff]
intro j (hj : j < i)
exact hi j hj (lt_trans hj hi')
· rwa [← natDegree_minpolyDiv_succ hx, Set.mem_Iio, Nat.lt_succ_iff] at hi'
section PowerBasis
variable {K}
lemma sum_smul_minpolyDiv_eq_X_pow (E) [Field E] [Algebra K E] [IsAlgClosed E]
[FiniteDimensional K L] [Algebra.IsSeparable K L]
{x : L} (hxL : Algebra.adjoin K {x} = ⊤) {r : ℕ} (hr : r < finrank K L) :
∑ σ : L →ₐ[K] E, ((x ^ r / aeval x (derivative <| minpoly K x)) •
minpolyDiv K x).map σ = (X ^ r : E[X]) := by
classical
rw [← sub_eq_zero]
have : Function.Injective (fun σ : L →ₐ[K] E ↦ σ x) := fun _ _ h =>
AlgHom.ext_of_adjoin_eq_top hxL (fun _ hx ↦ hx ▸ h)
apply Polynomial.eq_zero_of_natDegree_lt_card_of_eval_eq_zero _ this
· intro σ
simp only [Polynomial.map_smul, map_div₀, map_pow, RingHom.coe_coe, eval_sub, eval_finset_sum,
eval_smul, eval_map, eval₂_minpolyDiv_self, this.eq_iff, smul_eq_mul, mul_ite, mul_zero,
Finset.sum_ite_eq', Finset.mem_univ, ite_true, eval_pow, eval_X]
rw [sub_eq_zero, div_mul_cancel₀]
rw [ne_eq, map_eq_zero_iff σ σ.toRingHom.injective]
exact (Algebra.IsSeparable.isSeparable _ _).aeval_derivative_ne_zero (minpoly.aeval _ _)
· refine (Polynomial.natDegree_sub_le _ _).trans_lt
(max_lt ((Polynomial.natDegree_sum_le _ _).trans_lt ?_) ?_)
· simp only [AlgEquiv.toAlgHom_eq_coe, Polynomial.map_smul,
map_div₀, map_pow, RingHom.coe_coe, AlgHom.coe_coe, Function.comp_apply,
Finset.mem_univ, forall_true_left, true_and, Finset.fold_max_lt, AlgHom.card]
refine ⟨finrank_pos, ?_⟩
intro σ
exact ((Polynomial.natDegree_smul_le _ _).trans (natDegree_map_le _ _)).trans_lt
((natDegree_minpolyDiv_lt (Algebra.IsIntegral.isIntegral x)).trans_le
(minpoly.natDegree_le _))
· rwa [natDegree_pow, natDegree_X, mul_one, AlgHom.card]
end PowerBasis
|
FieldTheory\RatFunc\AsPolynomial.lean | /-
Copyright (c) 2021 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, María Inés de Frutos-Fernández, Filippo A. E. Nuccio
-/
import Mathlib.FieldTheory.RatFunc.Basic
import Mathlib.RingTheory.EuclideanDomain
import Mathlib.RingTheory.DedekindDomain.AdicValuation
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.RingTheory.Polynomial.Content
/-!
# Generalities on the polynomial structure of rational functions
* Main evaluation properties
* Study of the X-adic valuation
## Main definitions
- `RatFunc.C` is the constant polynomial
- `RatFunc.X` is the indeterminate
- `RatFunc.eval` evaluates a rational function given a value for the indeterminate
- `idealX` is the principal ideal generated by `X` in the ring of polynomials over a field K,
regarded as an element of the height-one-spectrum.
-/
noncomputable section
universe u
variable {K : Type u}
namespace RatFunc
section Eval
open scoped Classical
open scoped nonZeroDivisors Polynomial
open RatFunc
/-! ### Polynomial structure: `C`, `X`, `eval` -/
section Domain
variable [CommRing K] [IsDomain K]
/-- `RatFunc.C a` is the constant rational function `a`. -/
def C : K →+* RatFunc K := algebraMap _ _
@[simp]
theorem algebraMap_eq_C : algebraMap K (RatFunc K) = C :=
rfl
@[simp]
theorem algebraMap_C (a : K) : algebraMap K[X] (RatFunc K) (Polynomial.C a) = C a :=
rfl
@[simp]
theorem algebraMap_comp_C : (algebraMap K[X] (RatFunc K)).comp Polynomial.C = C :=
rfl
theorem smul_eq_C_mul (r : K) (x : RatFunc K) : r • x = C r * x := by
rw [Algebra.smul_def, algebraMap_eq_C]
/-- `RatFunc.X` is the polynomial variable (aka indeterminate). -/
def X : RatFunc K :=
algebraMap K[X] (RatFunc K) Polynomial.X
@[simp]
theorem algebraMap_X : algebraMap K[X] (RatFunc K) Polynomial.X = X :=
rfl
end Domain
section Field
variable [Field K]
@[simp]
theorem num_C (c : K) : num (C c) = Polynomial.C c :=
num_algebraMap _
@[simp]
theorem denom_C (c : K) : denom (C c) = 1 :=
denom_algebraMap _
@[simp]
theorem num_X : num (X : RatFunc K) = Polynomial.X :=
num_algebraMap _
@[simp]
theorem denom_X : denom (X : RatFunc K) = 1 :=
denom_algebraMap _
theorem X_ne_zero : (X : RatFunc K) ≠ 0 :=
RatFunc.algebraMap_ne_zero Polynomial.X_ne_zero
variable {L : Type u} [Field L]
/-- Evaluate a rational function `p` given a ring hom `f` from the scalar field
to the target and a value `x` for the variable in the target.
Fractions are reduced by clearing common denominators before evaluating:
`eval id 1 ((X^2 - 1) / (X - 1)) = eval id 1 (X + 1) = 2`, not `0 / 0 = 0`.
-/
def eval (f : K →+* L) (a : L) (p : RatFunc K) : L :=
(num p).eval₂ f a / (denom p).eval₂ f a
variable {f : K →+* L} {a : L}
theorem eval_eq_zero_of_eval₂_denom_eq_zero {x : RatFunc K}
(h : Polynomial.eval₂ f a (denom x) = 0) : eval f a x = 0 := by rw [eval, h, div_zero]
theorem eval₂_denom_ne_zero {x : RatFunc K} (h : eval f a x ≠ 0) :
Polynomial.eval₂ f a (denom x) ≠ 0 :=
mt eval_eq_zero_of_eval₂_denom_eq_zero h
variable (f a)
@[simp]
theorem eval_C {c : K} : eval f a (C c) = f c := by simp [eval]
@[simp]
theorem eval_X : eval f a X = a := by simp [eval]
@[simp]
theorem eval_zero : eval f a 0 = 0 := by simp [eval]
@[simp]
theorem eval_one : eval f a 1 = 1 := by simp [eval]
@[simp]
theorem eval_algebraMap {S : Type*} [CommSemiring S] [Algebra S K[X]] (p : S) :
eval f a (algebraMap _ _ p) = (algebraMap _ K[X] p).eval₂ f a := by
simp [eval, IsScalarTower.algebraMap_apply S K[X] (RatFunc K)]
/-- `eval` is an additive homomorphism except when a denominator evaluates to `0`.
Counterexample: `eval _ 1 (X / (X-1)) + eval _ 1 (-1 / (X-1)) = 0`
`... ≠ 1 = eval _ 1 ((X-1) / (X-1))`.
See also `RatFunc.eval₂_denom_ne_zero` to make the hypotheses simpler but less general.
-/
theorem eval_add {x y : RatFunc K} (hx : Polynomial.eval₂ f a (denom x) ≠ 0)
(hy : Polynomial.eval₂ f a (denom y) ≠ 0) : eval f a (x + y) = eval f a x + eval f a y := by
unfold eval
by_cases hxy : Polynomial.eval₂ f a (denom (x + y)) = 0
· have := Polynomial.eval₂_eq_zero_of_dvd_of_eval₂_eq_zero f a (denom_add_dvd x y) hxy
rw [Polynomial.eval₂_mul] at this
cases mul_eq_zero.mp this <;> contradiction
rw [div_add_div _ _ hx hy, eq_div_iff (mul_ne_zero hx hy), div_eq_mul_inv, mul_right_comm, ←
div_eq_mul_inv, div_eq_iff hxy]
simp only [← Polynomial.eval₂_mul, ← Polynomial.eval₂_add]
congr 1
apply num_denom_add
/-- `eval` is a multiplicative homomorphism except when a denominator evaluates to `0`.
Counterexample: `eval _ 0 X * eval _ 0 (1/X) = 0 ≠ 1 = eval _ 0 1 = eval _ 0 (X * 1/X)`.
See also `RatFunc.eval₂_denom_ne_zero` to make the hypotheses simpler but less general.
-/
theorem eval_mul {x y : RatFunc K} (hx : Polynomial.eval₂ f a (denom x) ≠ 0)
(hy : Polynomial.eval₂ f a (denom y) ≠ 0) : eval f a (x * y) = eval f a x * eval f a y := by
unfold eval
by_cases hxy : Polynomial.eval₂ f a (denom (x * y)) = 0
· have := Polynomial.eval₂_eq_zero_of_dvd_of_eval₂_eq_zero f a (denom_mul_dvd x y) hxy
rw [Polynomial.eval₂_mul] at this
cases mul_eq_zero.mp this <;> contradiction
rw [div_mul_div_comm, eq_div_iff (mul_ne_zero hx hy), div_eq_mul_inv, mul_right_comm, ←
div_eq_mul_inv, div_eq_iff hxy]
repeat' rw [← Polynomial.eval₂_mul]
congr 1
apply num_denom_mul
end Field
end Eval
end RatFunc
section AdicValuation
variable (K : Type*) [Field K]
namespace Polynomial
open IsDedekindDomain.HeightOneSpectrum
/-- This is the principal ideal generated by `X` in the ring of polynomials over a field K,
regarded as an element of the height-one-spectrum. -/
def idealX : IsDedekindDomain.HeightOneSpectrum K[X] where
asIdeal := Ideal.span {X}
isPrime := by rw [Ideal.span_singleton_prime]; exacts [Polynomial.prime_X, Polynomial.X_ne_zero]
ne_bot := by rw [ne_eq, Ideal.span_singleton_eq_bot]; exact Polynomial.X_ne_zero
@[simp]
theorem idealX_span : (idealX K).asIdeal = Ideal.span {X} := rfl
@[simp]
theorem valuation_X_eq_neg_one :
(idealX K).valuation (RatFunc.X : RatFunc K) = Multiplicative.ofAdd (-1 : ℤ) := by
rw [← RatFunc.algebraMap_X, valuation_of_algebraMap, intValuation_singleton]
· exact Polynomial.X_ne_zero
· exact idealX_span K
theorem valuation_of_mk (f : Polynomial K) {g : Polynomial K} (hg : g ≠ 0) :
(Polynomial.idealX K).valuation (RatFunc.mk f g) =
(Polynomial.idealX K).intValuation f / (Polynomial.idealX K).intValuation g := by
simp only [RatFunc.mk_eq_mk' _ hg, valuation_of_mk']
end Polynomial
namespace RatFunc
open scoped DiscreteValuation
open Polynomial
instance : Valued (RatFunc K) ℤₘ₀ := Valued.mk' (idealX K).valuation
@[simp]
theorem WithZero.valued_def {x : RatFunc K} :
@Valued.v (RatFunc K) _ _ _ _ x = (idealX K).valuation x := rfl
end RatFunc
end AdicValuation
|
FieldTheory\RatFunc\Basic.lean | /-
Copyright (c) 2021 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.FieldTheory.RatFunc.Defs
import Mathlib.RingTheory.EuclideanDomain
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.RingTheory.Polynomial.Content
/-!
# The field structure of rational functions
## Main definitions
Working with rational functions as polynomials:
- `RatFunc.instField` provides a field structure
You can use `IsFractionRing` API to treat `RatFunc` as the field of fractions of polynomials:
* `algebraMap K[X] (RatFunc K)` maps polynomials to rational functions
* `IsFractionRing.algEquiv` maps other fields of fractions of `K[X]` to `RatFunc K`,
in particular:
* `FractionRing.algEquiv K[X] (RatFunc K)` maps the generic field of
fraction construction to `RatFunc K`. Combine this with `AlgEquiv.restrictScalars` to change
the `FractionRing K[X] ≃ₐ[K[X]] RatFunc K` to `FractionRing K[X] ≃ₐ[K] RatFunc K`.
Working with rational functions as fractions:
- `RatFunc.num` and `RatFunc.denom` give the numerator and denominator.
These values are chosen to be coprime and such that `RatFunc.denom` is monic.
Lifting homomorphisms of polynomials to other types, by mapping and dividing, as long
as the homomorphism retains the non-zero-divisor property:
- `RatFunc.liftMonoidWithZeroHom` lifts a `K[X] →*₀ G₀` to
a `RatFunc K →*₀ G₀`, where `[CommRing K] [CommGroupWithZero G₀]`
- `RatFunc.liftRingHom` lifts a `K[X] →+* L` to a `RatFunc K →+* L`,
where `[CommRing K] [Field L]`
- `RatFunc.liftAlgHom` lifts a `K[X] →ₐ[S] L` to a `RatFunc K →ₐ[S] L`,
where `[CommRing K] [Field L] [CommSemiring S] [Algebra S K[X]] [Algebra S L]`
This is satisfied by injective homs.
We also have lifting homomorphisms of polynomials to other polynomials,
with the same condition on retaining the non-zero-divisor property across the map:
- `RatFunc.map` lifts `K[X] →* R[X]` when `[CommRing K] [CommRing R]`
- `RatFunc.mapRingHom` lifts `K[X] →+* R[X]` when `[CommRing K] [CommRing R]`
- `RatFunc.mapAlgHom` lifts `K[X] →ₐ[S] R[X]` when
`[CommRing K] [IsDomain K] [CommRing R] [IsDomain R]`
-/
universe u v
noncomputable section
open scoped Classical
open scoped nonZeroDivisors Polynomial
variable {K : Type u}
namespace RatFunc
section Field
variable [CommRing K]
/-- The zero rational function. -/
protected irreducible_def zero : RatFunc K :=
⟨0⟩
instance : Zero (RatFunc K) :=
⟨RatFunc.zero⟩
-- Porting note: added `OfNat.ofNat`. using `simp?` produces `simp only [zero_def]`
-- that does not close the goal
theorem ofFractionRing_zero : (ofFractionRing 0 : RatFunc K) = 0 := by
simp only [Zero.zero, OfNat.ofNat, RatFunc.zero]
/-- Addition of rational functions. -/
protected irreducible_def add : RatFunc K → RatFunc K → RatFunc K
| ⟨p⟩, ⟨q⟩ => ⟨p + q⟩
instance : Add (RatFunc K) :=
⟨RatFunc.add⟩
-- Porting note: added `HAdd.hAdd`. using `simp?` produces `simp only [add_def]`
-- that does not close the goal
theorem ofFractionRing_add (p q : FractionRing K[X]) :
ofFractionRing (p + q) = ofFractionRing p + ofFractionRing q := by
simp only [HAdd.hAdd, Add.add, RatFunc.add]
/-- Subtraction of rational functions. -/
protected irreducible_def sub : RatFunc K → RatFunc K → RatFunc K
| ⟨p⟩, ⟨q⟩ => ⟨p - q⟩
instance : Sub (RatFunc K) :=
⟨RatFunc.sub⟩
-- Porting note: added `HSub.hSub`. using `simp?` produces `simp only [sub_def]`
-- that does not close the goal
theorem ofFractionRing_sub (p q : FractionRing K[X]) :
ofFractionRing (p - q) = ofFractionRing p - ofFractionRing q := by
simp only [Sub.sub, HSub.hSub, RatFunc.sub]
/-- Additive inverse of a rational function. -/
protected irreducible_def neg : RatFunc K → RatFunc K
| ⟨p⟩ => ⟨-p⟩
instance : Neg (RatFunc K) :=
⟨RatFunc.neg⟩
theorem ofFractionRing_neg (p : FractionRing K[X]) :
ofFractionRing (-p) = -ofFractionRing p := by simp only [Neg.neg, RatFunc.neg]
/-- The multiplicative unit of rational functions. -/
protected irreducible_def one : RatFunc K :=
⟨1⟩
instance : One (RatFunc K) :=
⟨RatFunc.one⟩
-- Porting note: added `OfNat.ofNat`. using `simp?` produces `simp only [one_def]`
-- that does not close the goal
theorem ofFractionRing_one : (ofFractionRing 1 : RatFunc K) = 1 := by
simp only [One.one, OfNat.ofNat, RatFunc.one]
/-- Multiplication of rational functions. -/
protected irreducible_def mul : RatFunc K → RatFunc K → RatFunc K
| ⟨p⟩, ⟨q⟩ => ⟨p * q⟩
instance : Mul (RatFunc K) :=
⟨RatFunc.mul⟩
-- Porting note: added `HMul.hMul`. using `simp?` produces `simp only [mul_def]`
-- that does not close the goal
theorem ofFractionRing_mul (p q : FractionRing K[X]) :
ofFractionRing (p * q) = ofFractionRing p * ofFractionRing q := by
simp only [Mul.mul, HMul.hMul, RatFunc.mul]
section IsDomain
variable [IsDomain K]
/-- Division of rational functions. -/
protected irreducible_def div : RatFunc K → RatFunc K → RatFunc K
| ⟨p⟩, ⟨q⟩ => ⟨p / q⟩
instance : Div (RatFunc K) :=
⟨RatFunc.div⟩
-- Porting note: added `HDiv.hDiv`. using `simp?` produces `simp only [div_def]`
-- that does not close the goal
theorem ofFractionRing_div (p q : FractionRing K[X]) :
ofFractionRing (p / q) = ofFractionRing p / ofFractionRing q := by
simp only [Div.div, HDiv.hDiv, RatFunc.div]
/-- Multiplicative inverse of a rational function. -/
protected irreducible_def inv : RatFunc K → RatFunc K
| ⟨p⟩ => ⟨p⁻¹⟩
instance : Inv (RatFunc K) :=
⟨RatFunc.inv⟩
theorem ofFractionRing_inv (p : FractionRing K[X]) :
ofFractionRing p⁻¹ = (ofFractionRing p)⁻¹ := by
simp only [Inv.inv, RatFunc.inv]
-- Auxiliary lemma for the `Field` instance
theorem mul_inv_cancel : ∀ {p : RatFunc K}, p ≠ 0 → p * p⁻¹ = 1
| ⟨p⟩, h => by
have : p ≠ 0 := fun hp => h <| by rw [hp, ofFractionRing_zero]
simpa only [← ofFractionRing_inv, ← ofFractionRing_mul, ← ofFractionRing_one,
ofFractionRing.injEq] using -- Porting note: `ofFractionRing.injEq` was not present
_root_.mul_inv_cancel this
end IsDomain
section SMul
variable {R : Type*}
/-- Scalar multiplication of rational functions. -/
protected irreducible_def smul [SMul R (FractionRing K[X])] : R → RatFunc K → RatFunc K
| r, ⟨p⟩ => ⟨r • p⟩
-- cannot reproduce
--@[nolint fails_quickly] -- Porting note: `linter 'fails_quickly' not found`
instance [SMul R (FractionRing K[X])] : SMul R (RatFunc K) :=
⟨RatFunc.smul⟩
-- Porting note: added `SMul.hSMul`. using `simp?` produces `simp only [smul_def]`
-- that does not close the goal
theorem ofFractionRing_smul [SMul R (FractionRing K[X])] (c : R) (p : FractionRing K[X]) :
ofFractionRing (c • p) = c • ofFractionRing p := by
simp only [SMul.smul, HSMul.hSMul, RatFunc.smul]
theorem toFractionRing_smul [SMul R (FractionRing K[X])] (c : R) (p : RatFunc K) :
toFractionRing (c • p) = c • toFractionRing p := by
cases p
rw [← ofFractionRing_smul]
theorem smul_eq_C_smul (x : RatFunc K) (r : K) : r • x = Polynomial.C r • x := by
cases' x with x
-- Porting note: had to specify the induction principle manually
induction x using Localization.induction_on
rw [← ofFractionRing_smul, ← ofFractionRing_smul, Localization.smul_mk,
Localization.smul_mk, smul_eq_mul, Polynomial.smul_eq_C_mul]
section IsDomain
variable [IsDomain K]
variable [Monoid R] [DistribMulAction R K[X]]
variable [IsScalarTower R K[X] K[X]]
theorem mk_smul (c : R) (p q : K[X]) : RatFunc.mk (c • p) q = c • RatFunc.mk p q := by
letI : SMulZeroClass R (FractionRing K[X]) := inferInstance
by_cases hq : q = 0
· rw [hq, mk_zero, mk_zero, ← ofFractionRing_smul, smul_zero]
· rw [mk_eq_localization_mk _ hq, mk_eq_localization_mk _ hq, ← Localization.smul_mk, ←
ofFractionRing_smul]
instance : IsScalarTower R K[X] (RatFunc K) :=
⟨fun c p q => q.induction_on' fun q r _ => by rw [← mk_smul, smul_assoc, mk_smul, mk_smul]⟩
end IsDomain
end SMul
variable (K)
instance [Subsingleton K] : Subsingleton (RatFunc K) :=
toFractionRing_injective.subsingleton
instance : Inhabited (RatFunc K) :=
⟨0⟩
instance instNontrivial [Nontrivial K] : Nontrivial (RatFunc K) :=
ofFractionRing_injective.nontrivial
/-- `RatFunc K` is isomorphic to the field of fractions of `K[X]`, as rings.
This is an auxiliary definition; `simp`-normal form is `IsLocalization.algEquiv`.
-/
@[simps apply]
def toFractionRingRingEquiv : RatFunc K ≃+* FractionRing K[X] where
toFun := toFractionRing
invFun := ofFractionRing
left_inv := fun ⟨_⟩ => rfl
right_inv _ := rfl
map_add' := fun ⟨_⟩ ⟨_⟩ => by simp [← ofFractionRing_add]
map_mul' := fun ⟨_⟩ ⟨_⟩ => by simp [← ofFractionRing_mul]
end Field
section TacticInterlude
-- Porting note: reimplemented the `frac_tac` and `smul_tac` as close to the originals as I could
/-- Solve equations for `RatFunc K` by working in `FractionRing K[X]`. -/
macro "frac_tac" : tactic => `(tactic| repeat (rintro (⟨⟩ : RatFunc _)) <;>
try simp only [← ofFractionRing_zero, ← ofFractionRing_add, ← ofFractionRing_sub,
← ofFractionRing_neg, ← ofFractionRing_one, ← ofFractionRing_mul, ← ofFractionRing_div,
← ofFractionRing_inv,
add_assoc, zero_add, add_zero, mul_assoc, mul_zero, mul_one, mul_add, inv_zero,
add_comm, add_left_comm, mul_comm, mul_left_comm, sub_eq_add_neg, div_eq_mul_inv,
add_mul, zero_mul, one_mul, neg_mul, mul_neg, add_right_neg])
/-- Solve equations for `RatFunc K` by applying `RatFunc.induction_on`. -/
macro "smul_tac" : tactic => `(tactic|
repeat
(first
| rintro (⟨⟩ : RatFunc _)
| intro) <;>
simp_rw [← ofFractionRing_smul] <;>
simp only [add_comm, mul_comm, zero_smul, succ_nsmul, zsmul_eq_mul, mul_add, mul_one, mul_zero,
neg_add, mul_neg,
Int.ofNat_eq_coe, Int.cast_zero, Int.cast_add, Int.cast_one,
Int.cast_negSucc, Int.cast_natCast, Nat.cast_succ,
Localization.mk_zero, Localization.add_mk_self, Localization.neg_mk,
ofFractionRing_zero, ← ofFractionRing_add, ← ofFractionRing_neg])
end TacticInterlude
section CommRing
variable (K) [CommRing K]
-- Porting note: split the CommRing instance up into multiple defs because it was hard to see
-- if the big instance declaration made any progress.
/-- `RatFunc K` is a commutative monoid.
This is an intermediate step on the way to the full instance `RatFunc.instCommRing`.
-/
def instCommMonoid : CommMonoid (RatFunc K) where
mul := (· * ·)
mul_assoc := by frac_tac
mul_comm := by frac_tac
one := 1
one_mul := by frac_tac
mul_one := by frac_tac
npow := npowRec
/-- `RatFunc K` is an additive commutative group.
This is an intermediate step on the way to the full instance `RatFunc.instCommRing`.
-/
def instAddCommGroup : AddCommGroup (RatFunc K) where
add := (· + ·)
add_assoc := by frac_tac
-- Porting note: `by frac_tac` didn't work:
add_comm := by repeat rintro (⟨⟩ : RatFunc _) <;> simp only [← ofFractionRing_add, add_comm]
zero := 0
zero_add := by frac_tac
add_zero := by frac_tac
neg := Neg.neg
add_left_neg := by frac_tac
sub := Sub.sub
sub_eq_add_neg := by frac_tac
nsmul := (· • ·)
nsmul_zero := by smul_tac
nsmul_succ _ := by smul_tac
zsmul := (· • ·)
zsmul_zero' := by smul_tac
zsmul_succ' _ := by smul_tac
zsmul_neg' _ := by smul_tac
instance instCommRing : CommRing (RatFunc K) :=
{ instCommMonoid K, instAddCommGroup K with
zero := 0
sub := Sub.sub
zero_mul := by frac_tac
mul_zero := by frac_tac
left_distrib := by frac_tac
right_distrib := by frac_tac
one := 1
nsmul := (· • ·)
zsmul := (· • ·)
npow := npowRec }
variable {K}
section LiftHom
open RatFunc
variable {G₀ L R S F : Type*} [CommGroupWithZero G₀] [Field L] [CommRing R] [CommRing S]
variable [FunLike F R[X] S[X]]
/-- Lift a monoid homomorphism that maps polynomials `φ : R[X] →* S[X]`
to a `RatFunc R →* RatFunc S`,
on the condition that `φ` maps non zero divisors to non zero divisors,
by mapping both the numerator and denominator and quotienting them. -/
def map [MonoidHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) :
RatFunc R →* RatFunc S where
toFun f :=
RatFunc.liftOn f
(fun n d => if h : φ d ∈ S[X]⁰ then ofFractionRing (Localization.mk (φ n) ⟨φ d, h⟩) else 0)
fun {p q p' q'} hq hq' h => by
beta_reduce -- Porting note(#12129): force the function to be applied
rw [dif_pos, dif_pos]
on_goal 1 =>
congr 1 -- Porting note: this was a `rw [ofFractionRing.inj_eq]` which was overkill anyway
rw [Localization.mk_eq_mk_iff]
rotate_left
· exact hφ hq
· exact hφ hq'
refine Localization.r_of_eq ?_
simpa only [map_mul] using congr_arg φ h
map_one' := by
beta_reduce -- Porting note(#12129): force the function to be applied
rw [← ofFractionRing_one, ← Localization.mk_one, liftOn_ofFractionRing_mk, dif_pos]
· simpa using ofFractionRing_one
· simpa using Submonoid.one_mem _
map_mul' x y := by
beta_reduce -- Porting note(#12129): force the function to be applied
cases' x with x; cases' y with y
-- Porting note: added `using Localization.rec` (`Localization.induction_on` didn't work)
induction' x using Localization.rec with p q
· induction' y using Localization.rec with p' q'
· have hq : φ q ∈ S[X]⁰ := hφ q.prop
have hq' : φ q' ∈ S[X]⁰ := hφ q'.prop
have hqq' : φ ↑(q * q') ∈ S[X]⁰ := by simpa using Submonoid.mul_mem _ hq hq'
simp_rw [← ofFractionRing_mul, Localization.mk_mul, liftOn_ofFractionRing_mk, dif_pos hq,
dif_pos hq', dif_pos hqq', ← ofFractionRing_mul, Submonoid.coe_mul, map_mul,
Localization.mk_mul, Submonoid.mk_mul_mk]
· rfl
· rfl
theorem map_apply_ofFractionRing_mk [MonoidHomClass F R[X] S[X]] (φ : F)
(hφ : R[X]⁰ ≤ S[X]⁰.comap φ) (n : R[X]) (d : R[X]⁰) :
map φ hφ (ofFractionRing (Localization.mk n d)) =
ofFractionRing (Localization.mk (φ n) ⟨φ d, hφ d.prop⟩) := by
-- Porting note: replaced `convert` with `refine Eq.trans`
refine (liftOn_ofFractionRing_mk n _ _ _).trans ?_
rw [dif_pos]
theorem map_injective [MonoidHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ)
(hf : Function.Injective φ) : Function.Injective (map φ hφ) := by
rintro ⟨x⟩ ⟨y⟩ h
-- Porting note: had to hint `induction` which induction principle to use
induction x using Localization.induction_on
induction y using Localization.induction_on
simpa only [map_apply_ofFractionRing_mk, ofFractionRing_injective.eq_iff,
Localization.mk_eq_mk_iff, Localization.r_iff_exists, mul_cancel_left_coe_nonZeroDivisors,
exists_const, ← map_mul, hf.eq_iff] using h
/-- Lift a ring homomorphism that maps polynomials `φ : R[X] →+* S[X]`
to a `RatFunc R →+* RatFunc S`,
on the condition that `φ` maps non zero divisors to non zero divisors,
by mapping both the numerator and denominator and quotienting them. -/
def mapRingHom [RingHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) :
RatFunc R →+* RatFunc S :=
{ map φ hφ with
map_zero' := by
simp_rw [MonoidHom.toFun_eq_coe, ← ofFractionRing_zero, ← Localization.mk_zero (1 : R[X]⁰),
← Localization.mk_zero (1 : S[X]⁰), map_apply_ofFractionRing_mk, map_zero,
Localization.mk_eq_mk', IsLocalization.mk'_zero]
map_add' := by
rintro ⟨x⟩ ⟨y⟩
-- Porting note: had to hint `induction` which induction principle to use
induction x using Localization.rec
induction y using Localization.rec
· simp only [← ofFractionRing_add, Localization.add_mk, map_add, map_mul,
MonoidHom.toFun_eq_coe, map_apply_ofFractionRing_mk, Submonoid.coe_mul]
-- Porting note: `Submonoid.mk_mul_mk` couldn't be applied: motive incorrect,
-- even though it is a rfl lemma.
rfl
· rfl
· rfl }
theorem coe_mapRingHom_eq_coe_map [RingHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) :
(mapRingHom φ hφ : RatFunc R → RatFunc S) = map φ hφ :=
rfl
-- TODO: Generalize to `FunLike` classes,
/-- Lift a monoid with zero homomorphism `R[X] →*₀ G₀` to a `RatFunc R →*₀ G₀`
on the condition that `φ` maps non zero divisors to non zero divisors,
by mapping both the numerator and denominator and quotienting them. -/
def liftMonoidWithZeroHom (φ : R[X] →*₀ G₀) (hφ : R[X]⁰ ≤ G₀⁰.comap φ) : RatFunc R →*₀ G₀ where
toFun f :=
RatFunc.liftOn f (fun p q => φ p / φ q) fun {p q p' q'} hq hq' h => by
cases subsingleton_or_nontrivial R
· rw [Subsingleton.elim p q, Subsingleton.elim p' q, Subsingleton.elim q' q]
rw [div_eq_div_iff, ← map_mul, mul_comm p, h, map_mul, mul_comm] <;>
exact nonZeroDivisors.ne_zero (hφ ‹_›)
map_one' := by
dsimp only -- Porting note: force the function to be applied (not just beta reduction!)
rw [← ofFractionRing_one, ← Localization.mk_one, liftOn_ofFractionRing_mk]
simp only [map_one, OneMemClass.coe_one, div_one]
map_mul' x y := by
cases' x with x
cases' y with y
induction' x using Localization.rec with p q
· induction' y using Localization.rec with p' q'
· rw [← ofFractionRing_mul, Localization.mk_mul]
simp only [liftOn_ofFractionRing_mk, div_mul_div_comm, map_mul, Submonoid.coe_mul]
· rfl
· rfl
map_zero' := by
beta_reduce -- Porting note(#12129): force the function to be applied
rw [← ofFractionRing_zero, ← Localization.mk_zero (1 : R[X]⁰), liftOn_ofFractionRing_mk]
simp only [map_zero, zero_div]
theorem liftMonoidWithZeroHom_apply_ofFractionRing_mk (φ : R[X] →*₀ G₀) (hφ : R[X]⁰ ≤ G₀⁰.comap φ)
(n : R[X]) (d : R[X]⁰) :
liftMonoidWithZeroHom φ hφ (ofFractionRing (Localization.mk n d)) = φ n / φ d :=
liftOn_ofFractionRing_mk _ _ _ _
theorem liftMonoidWithZeroHom_injective [Nontrivial R] (φ : R[X] →*₀ G₀) (hφ : Function.Injective φ)
(hφ' : R[X]⁰ ≤ G₀⁰.comap φ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ hφ) :
Function.Injective (liftMonoidWithZeroHom φ hφ') := by
rintro ⟨x⟩ ⟨y⟩
induction' x using Localization.induction_on with a
induction' y using Localization.induction_on with a'
simp_rw [liftMonoidWithZeroHom_apply_ofFractionRing_mk]
intro h
congr 1
refine Localization.mk_eq_mk_iff.mpr (Localization.r_of_eq (M := R[X]) ?_)
have := mul_eq_mul_of_div_eq_div _ _ ?_ ?_ h
· rwa [← map_mul, ← map_mul, hφ.eq_iff, mul_comm, mul_comm a'.fst] at this
all_goals exact map_ne_zero_of_mem_nonZeroDivisors _ hφ (SetLike.coe_mem _)
/-- Lift an injective ring homomorphism `R[X] →+* L` to a `RatFunc R →+* L`
by mapping both the numerator and denominator and quotienting them. -/
def liftRingHom (φ : R[X] →+* L) (hφ : R[X]⁰ ≤ L⁰.comap φ) : RatFunc R →+* L :=
{ liftMonoidWithZeroHom φ.toMonoidWithZeroHom hφ with
map_add' := fun x y => by
-- Porting note: used to invoke `MonoidWithZeroHom.toFun_eq_coe`
simp only [ZeroHom.toFun_eq_coe, MonoidWithZeroHom.toZeroHom_coe]
cases subsingleton_or_nontrivial R
· rw [Subsingleton.elim (x + y) y, Subsingleton.elim x 0, map_zero, zero_add]
cases' x with x
cases' y with y
-- Porting note: had to add the recursor explicitly below
induction' x using Localization.rec with p q
· induction' y using Localization.rec with p' q'
· rw [← ofFractionRing_add, Localization.add_mk]
simp only [RingHom.toMonoidWithZeroHom_eq_coe,
liftMonoidWithZeroHom_apply_ofFractionRing_mk]
rw [div_add_div, div_eq_div_iff]
· rw [mul_comm _ p, mul_comm _ p', mul_comm _ (φ p'), add_comm]
simp only [map_add, map_mul, Submonoid.coe_mul]
all_goals
try simp only [← map_mul, ← Submonoid.coe_mul]
exact nonZeroDivisors.ne_zero (hφ (SetLike.coe_mem _))
· rfl
· rfl }
theorem liftRingHom_apply_ofFractionRing_mk (φ : R[X] →+* L) (hφ : R[X]⁰ ≤ L⁰.comap φ) (n : R[X])
(d : R[X]⁰) : liftRingHom φ hφ (ofFractionRing (Localization.mk n d)) = φ n / φ d :=
liftMonoidWithZeroHom_apply_ofFractionRing_mk _ hφ _ _
theorem liftRingHom_injective [Nontrivial R] (φ : R[X] →+* L) (hφ : Function.Injective φ)
(hφ' : R[X]⁰ ≤ L⁰.comap φ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ hφ) :
Function.Injective (liftRingHom φ hφ') :=
liftMonoidWithZeroHom_injective _ hφ
end LiftHom
variable (K)
instance instField [IsDomain K] : Field (RatFunc K) where
-- Porting note: used to be `by frac_tac`
inv_zero := by rw [← ofFractionRing_zero, ← ofFractionRing_inv, inv_zero]
div := (· / ·)
div_eq_mul_inv := by frac_tac
mul_inv_cancel _ := mul_inv_cancel
zpow := zpowRec
nnqsmul := _
qsmul := _
section IsFractionRing
/-! ### `RatFunc` as field of fractions of `Polynomial` -/
section IsDomain
variable [IsDomain K]
instance (R : Type*) [CommSemiring R] [Algebra R K[X]] : Algebra R (RatFunc K) where
toFun x := RatFunc.mk (algebraMap _ _ x) 1
map_add' x y := by simp only [mk_one', RingHom.map_add, ofFractionRing_add]
map_mul' x y := by simp only [mk_one', RingHom.map_mul, ofFractionRing_mul]
map_one' := by simp only [mk_one', RingHom.map_one, ofFractionRing_one]
map_zero' := by simp only [mk_one', RingHom.map_zero, ofFractionRing_zero]
smul := (· • ·)
smul_def' c x := by
induction' x using RatFunc.induction_on' with p q hq
-- Porting note: the first `rw [...]` was not needed
rw [RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk]
rw [mk_one', ← mk_smul, mk_def_of_ne (c • p) hq, mk_def_of_ne p hq, ←
ofFractionRing_mul, IsLocalization.mul_mk'_eq_mk'_of_mul, Algebra.smul_def]
commutes' c x := mul_comm _ _
variable {K}
/-- The coercion from polynomials to rational functions, implemented as the algebra map from a
domain to its field of fractions -/
@[coe]
def coePolynomial (P : Polynomial K) : RatFunc K := algebraMap _ _ P
instance : Coe (Polynomial K) (RatFunc K) := ⟨coePolynomial⟩
theorem mk_one (x : K[X]) : RatFunc.mk x 1 = algebraMap _ _ x :=
rfl
theorem ofFractionRing_algebraMap (x : K[X]) :
ofFractionRing (algebraMap _ (FractionRing K[X]) x) = algebraMap _ _ x := by
rw [← mk_one, mk_one']
@[simp]
theorem mk_eq_div (p q : K[X]) : RatFunc.mk p q = algebraMap _ _ p / algebraMap _ _ q := by
simp only [mk_eq_div', ofFractionRing_div, ofFractionRing_algebraMap]
@[simp]
theorem div_smul {R} [Monoid R] [DistribMulAction R K[X]] [IsScalarTower R K[X] K[X]] (c : R)
(p q : K[X]) :
algebraMap _ (RatFunc K) (c • p) / algebraMap _ _ q =
c • (algebraMap _ _ p / algebraMap _ _ q) := by
rw [← mk_eq_div, mk_smul, mk_eq_div]
theorem algebraMap_apply {R : Type*} [CommSemiring R] [Algebra R K[X]] (x : R) :
algebraMap R (RatFunc K) x = algebraMap _ _ (algebraMap R K[X] x) / algebraMap K[X] _ 1 := by
rw [← mk_eq_div]
rfl
theorem map_apply_div_ne_zero {R F : Type*} [CommRing R] [IsDomain R]
[FunLike F K[X] R[X]] [MonoidHomClass F K[X] R[X]]
(φ : F) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) (p q : K[X]) (hq : q ≠ 0) :
map φ hφ (algebraMap _ _ p / algebraMap _ _ q) =
algebraMap _ _ (φ p) / algebraMap _ _ (φ q) := by
have hq' : φ q ≠ 0 := nonZeroDivisors.ne_zero (hφ (mem_nonZeroDivisors_iff_ne_zero.mpr hq))
simp only [← mk_eq_div, mk_eq_localization_mk _ hq, map_apply_ofFractionRing_mk,
mk_eq_localization_mk _ hq']
@[simp]
theorem map_apply_div {R F : Type*} [CommRing R] [IsDomain R]
[FunLike F K[X] R[X]] [MonoidWithZeroHomClass F K[X] R[X]]
(φ : F) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) (p q : K[X]) :
map φ hφ (algebraMap _ _ p / algebraMap _ _ q) =
algebraMap _ _ (φ p) / algebraMap _ _ (φ q) := by
rcases eq_or_ne q 0 with (rfl | hq)
· have : (0 : RatFunc K) = algebraMap K[X] _ 0 / algebraMap K[X] _ 1 := by simp
rw [map_zero, map_zero, map_zero, div_zero, div_zero, this, map_apply_div_ne_zero, map_one,
map_one, div_one, map_zero, map_zero]
exact one_ne_zero
exact map_apply_div_ne_zero _ _ _ _ hq
theorem liftMonoidWithZeroHom_apply_div {L : Type*} [CommGroupWithZero L]
(φ : MonoidWithZeroHom K[X] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) :
liftMonoidWithZeroHom φ hφ (algebraMap _ _ p / algebraMap _ _ q) = φ p / φ q := by
rcases eq_or_ne q 0 with (rfl | hq)
· simp only [div_zero, map_zero]
simp only [← mk_eq_div, mk_eq_localization_mk _ hq,
liftMonoidWithZeroHom_apply_ofFractionRing_mk]
@[simp]
theorem liftMonoidWithZeroHom_apply_div' {L : Type*} [CommGroupWithZero L]
(φ : MonoidWithZeroHom K[X] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) :
liftMonoidWithZeroHom φ hφ (algebraMap _ _ p) / liftMonoidWithZeroHom φ hφ (algebraMap _ _ q) =
φ p / φ q := by
rw [← map_div₀, liftMonoidWithZeroHom_apply_div]
theorem liftRingHom_apply_div {L : Type*} [Field L] (φ : K[X] →+* L) (hφ : K[X]⁰ ≤ L⁰.comap φ)
(p q : K[X]) : liftRingHom φ hφ (algebraMap _ _ p / algebraMap _ _ q) = φ p / φ q :=
liftMonoidWithZeroHom_apply_div _ hφ _ _ -- Porting note: gave explicitly the `hφ`
@[simp]
theorem liftRingHom_apply_div' {L : Type*} [Field L] (φ : K[X] →+* L) (hφ : K[X]⁰ ≤ L⁰.comap φ)
(p q : K[X]) : liftRingHom φ hφ (algebraMap _ _ p) / liftRingHom φ hφ (algebraMap _ _ q) =
φ p / φ q :=
liftMonoidWithZeroHom_apply_div' _ hφ _ _ -- Porting note: gave explicitly the `hφ`
variable (K)
theorem ofFractionRing_comp_algebraMap :
ofFractionRing ∘ algebraMap K[X] (FractionRing K[X]) = algebraMap _ _ :=
funext ofFractionRing_algebraMap
theorem algebraMap_injective : Function.Injective (algebraMap K[X] (RatFunc K)) := by
rw [← ofFractionRing_comp_algebraMap]
exact ofFractionRing_injective.comp (IsFractionRing.injective _ _)
@[simp]
theorem algebraMap_eq_zero_iff {x : K[X]} : algebraMap K[X] (RatFunc K) x = 0 ↔ x = 0 :=
⟨(injective_iff_map_eq_zero _).mp (algebraMap_injective K) _, fun hx => by
rw [hx, RingHom.map_zero]⟩
variable {K}
theorem algebraMap_ne_zero {x : K[X]} (hx : x ≠ 0) : algebraMap K[X] (RatFunc K) x ≠ 0 :=
mt (algebraMap_eq_zero_iff K).mp hx
section LiftAlgHom
variable {L R S : Type*} [Field L] [CommRing R] [IsDomain R] [CommSemiring S] [Algebra S K[X]]
[Algebra S L] [Algebra S R[X]] (φ : K[X] →ₐ[S] L) (hφ : K[X]⁰ ≤ L⁰.comap φ)
/-- Lift an algebra homomorphism that maps polynomials `φ : K[X] →ₐ[S] R[X]`
to a `RatFunc K →ₐ[S] RatFunc R`,
on the condition that `φ` maps non zero divisors to non zero divisors,
by mapping both the numerator and denominator and quotienting them. -/
def mapAlgHom (φ : K[X] →ₐ[S] R[X]) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) : RatFunc K →ₐ[S] RatFunc R :=
{ mapRingHom φ hφ with
commutes' := fun r => by
simp_rw [RingHom.toFun_eq_coe, coe_mapRingHom_eq_coe_map, algebraMap_apply r, map_apply_div,
map_one, AlgHom.commutes] }
theorem coe_mapAlgHom_eq_coe_map (φ : K[X] →ₐ[S] R[X]) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) :
(mapAlgHom φ hφ : RatFunc K → RatFunc R) = map φ hφ :=
rfl
/-- Lift an injective algebra homomorphism `K[X] →ₐ[S] L` to a `RatFunc K →ₐ[S] L`
by mapping both the numerator and denominator and quotienting them. -/
def liftAlgHom : RatFunc K →ₐ[S] L :=
{ liftRingHom φ.toRingHom hφ with
commutes' := fun r => by
simp_rw [RingHom.toFun_eq_coe, AlgHom.toRingHom_eq_coe, algebraMap_apply r,
liftRingHom_apply_div, AlgHom.coe_toRingHom, map_one, div_one, AlgHom.commutes] }
theorem liftAlgHom_apply_ofFractionRing_mk (n : K[X]) (d : K[X]⁰) :
liftAlgHom φ hφ (ofFractionRing (Localization.mk n d)) = φ n / φ d :=
liftMonoidWithZeroHom_apply_ofFractionRing_mk _ hφ _ _ -- Porting note: gave explicitly the `hφ`
theorem liftAlgHom_injective (φ : K[X] →ₐ[S] L) (hφ : Function.Injective φ)
(hφ' : K[X]⁰ ≤ L⁰.comap φ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ hφ) :
Function.Injective (liftAlgHom φ hφ') :=
liftMonoidWithZeroHom_injective _ hφ
@[simp]
theorem liftAlgHom_apply_div' (p q : K[X]) :
liftAlgHom φ hφ (algebraMap _ _ p) / liftAlgHom φ hφ (algebraMap _ _ q) = φ p / φ q :=
liftMonoidWithZeroHom_apply_div' _ hφ _ _ -- Porting note: gave explicitly the `hφ`
theorem liftAlgHom_apply_div (p q : K[X]) :
liftAlgHom φ hφ (algebraMap _ _ p / algebraMap _ _ q) = φ p / φ q :=
liftMonoidWithZeroHom_apply_div _ hφ _ _ -- Porting note: gave explicitly the `hφ`
end LiftAlgHom
variable (K)
/-- `RatFunc K` is the field of fractions of the polynomials over `K`. -/
instance : IsFractionRing K[X] (RatFunc K) where
map_units' y := by
rw [← ofFractionRing_algebraMap]
exact (toFractionRingRingEquiv K).symm.toRingHom.isUnit_map (IsLocalization.map_units _ y)
exists_of_eq {x y} := by
rw [← ofFractionRing_algebraMap, ← ofFractionRing_algebraMap]
exact fun h ↦ IsLocalization.exists_of_eq ((toFractionRingRingEquiv K).symm.injective h)
surj' := by
rintro ⟨z⟩
convert IsLocalization.surj K[X]⁰ z
-- Porting note: `ext ⟨x, y⟩` no longer necessary
simp only [← ofFractionRing_algebraMap, Function.comp_apply, ← ofFractionRing_mul]
rw [ofFractionRing.injEq] -- Porting note: added
variable {K}
@[simp]
theorem liftOn_div {P : Sort v} (p q : K[X]) (f : K[X] → K[X] → P) (f0 : ∀ p, f p 0 = f 0 1)
(H' : ∀ {p q p' q'} (_hq : q ≠ 0) (_hq' : q' ≠ 0), q' * p = q * p' → f p q = f p' q')
(H : ∀ {p q p' q'} (_hq : q ∈ K[X]⁰) (_hq' : q' ∈ K[X]⁰), q' * p = q * p' → f p q = f p' q' :=
fun {p q p' q'} hq hq' h => H' (nonZeroDivisors.ne_zero hq) (nonZeroDivisors.ne_zero hq') h) :
(RatFunc.liftOn (algebraMap _ (RatFunc K) p / algebraMap _ _ q)) f @H = f p q := by
rw [← mk_eq_div, liftOn_mk _ _ f f0 @H']
@[simp]
theorem liftOn'_div {P : Sort v} (p q : K[X]) (f : K[X] → K[X] → P) (f0 : ∀ p, f p 0 = f 0 1)
(H) :
(RatFunc.liftOn' (algebraMap _ (RatFunc K) p / algebraMap _ _ q)) f @H = f p q := by
rw [RatFunc.liftOn', liftOn_div _ _ _ f0]
apply liftOn_condition_of_liftOn'_condition H -- Porting note: `exact` did not work. Also,
-- was `@H` that still works, but is not needed.
/-- Induction principle for `RatFunc K`: if `f p q : P (p / q)` for all `p q : K[X]`,
then `P` holds on all elements of `RatFunc K`.
See also `induction_on'`, which is a recursion principle defined in terms of `RatFunc.mk`.
-/
protected theorem induction_on {P : RatFunc K → Prop} (x : RatFunc K)
(f : ∀ (p q : K[X]) (hq : q ≠ 0), P (algebraMap _ (RatFunc K) p / algebraMap _ _ q)) : P x :=
x.induction_on' fun p q hq => by simpa using f p q hq
theorem ofFractionRing_mk' (x : K[X]) (y : K[X]⁰) :
-- Porting note: I gave explicitly the argument `(FractionRing K[X])`
ofFractionRing (IsLocalization.mk' (FractionRing K[X]) x y) =
IsLocalization.mk' (RatFunc K) x y := by
rw [IsFractionRing.mk'_eq_div, IsFractionRing.mk'_eq_div, ← mk_eq_div', ← mk_eq_div]
theorem mk_eq_mk' (f : Polynomial K) {g : Polynomial K} (hg : g ≠ 0) :
RatFunc.mk f g = IsLocalization.mk' (RatFunc K) f ⟨g, mem_nonZeroDivisors_iff_ne_zero.2 hg⟩ :=
by simp only [mk_eq_div, IsFractionRing.mk'_eq_div]
@[simp]
theorem ofFractionRing_eq :
(ofFractionRing : FractionRing K[X] → RatFunc K) = IsLocalization.algEquiv K[X]⁰ _ _ :=
funext fun x =>
Localization.induction_on x fun x => by
simp only [IsLocalization.algEquiv_apply, IsLocalization.ringEquivOfRingEquiv_apply,
Localization.mk_eq_mk'_apply, IsLocalization.map_mk', ofFractionRing_mk',
RingEquiv.coe_toRingHom, RingEquiv.refl_apply, SetLike.eta]
-- Porting note: added following `simp`. The previous one can be squeezed.
simp only [IsFractionRing.mk'_eq_div, RingHom.id_apply, Subtype.coe_eta]
@[simp]
theorem toFractionRing_eq :
(toFractionRing : RatFunc K → FractionRing K[X]) = IsLocalization.algEquiv K[X]⁰ _ _ :=
funext fun ⟨x⟩ =>
Localization.induction_on x fun x => by
simp only [Localization.mk_eq_mk'_apply, ofFractionRing_mk', IsLocalization.algEquiv_apply,
IsLocalization.ringEquivOfRingEquiv_apply, IsLocalization.map_mk',
RingEquiv.coe_toRingHom, RingEquiv.refl_apply, SetLike.eta]
-- Porting note: added following `simp`. The previous one can be squeezed.
simp only [IsFractionRing.mk'_eq_div, RingHom.id_apply, Subtype.coe_eta]
@[simp]
theorem toFractionRingRingEquiv_symm_eq :
(toFractionRingRingEquiv K).symm = (IsLocalization.algEquiv K[X]⁰ _ _).toRingEquiv := by
ext x
simp [toFractionRingRingEquiv, ofFractionRing_eq, AlgEquiv.coe_ringEquiv']
end IsDomain
end IsFractionRing
end CommRing
section NumDenom
/-! ### Numerator and denominator -/
open GCDMonoid Polynomial
variable [Field K]
set_option tactic.skipAssignedInstances false in
/-- `RatFunc.numDenom` are numerator and denominator of a rational function over a field,
normalized such that the denominator is monic. -/
def numDenom (x : RatFunc K) : K[X] × K[X] :=
x.liftOn'
(fun p q =>
if q = 0 then ⟨0, 1⟩
else
let r := gcd p q
⟨Polynomial.C (q / r).leadingCoeff⁻¹ * (p / r),
Polynomial.C (q / r).leadingCoeff⁻¹ * (q / r)⟩)
(by
intros p q a hq ha
dsimp
rw [if_neg hq, if_neg (mul_ne_zero ha hq)]
have ha' : a.leadingCoeff ≠ 0 := Polynomial.leadingCoeff_ne_zero.mpr ha
have hainv : a.leadingCoeff⁻¹ ≠ 0 := inv_ne_zero ha'
simp only [Prod.ext_iff, gcd_mul_left, normalize_apply, Polynomial.coe_normUnit, mul_assoc,
CommGroupWithZero.coe_normUnit _ ha']
have hdeg : (gcd p q).degree ≤ q.degree := degree_gcd_le_right _ hq
have hdeg' : (Polynomial.C a.leadingCoeff⁻¹ * gcd p q).degree ≤ q.degree := by
rw [Polynomial.degree_mul, Polynomial.degree_C hainv, zero_add]
exact hdeg
have hdivp : Polynomial.C a.leadingCoeff⁻¹ * gcd p q ∣ p :=
(C_mul_dvd hainv).mpr (gcd_dvd_left p q)
have hdivq : Polynomial.C a.leadingCoeff⁻¹ * gcd p q ∣ q :=
(C_mul_dvd hainv).mpr (gcd_dvd_right p q)
-- Porting note: added `simp only [...]` and `rw [mul_assoc]`
-- Porting note: note the unfolding of `normalize` and `normUnit`!
simp only [normalize, normUnit, coe_normUnit, leadingCoeff_eq_zero, MonoidWithZeroHom.coe_mk,
ZeroHom.coe_mk, ha, dite_false, Units.val_inv_eq_inv_val, Units.val_mk0]
rw [mul_assoc]
rw [EuclideanDomain.mul_div_mul_cancel ha hdivp, EuclideanDomain.mul_div_mul_cancel ha hdivq,
leadingCoeff_div hdeg, leadingCoeff_div hdeg', Polynomial.leadingCoeff_mul,
Polynomial.leadingCoeff_C, div_C_mul, div_C_mul, ← mul_assoc, ← Polynomial.C_mul, ←
mul_assoc, ← Polynomial.C_mul]
constructor <;> congr <;>
rw [inv_div, mul_comm, mul_div_assoc, ← mul_assoc, inv_inv, _root_.mul_inv_cancel ha',
one_mul, inv_div])
@[simp]
theorem numDenom_div (p : K[X]) {q : K[X]} (hq : q ≠ 0) :
numDenom (algebraMap _ _ p / algebraMap _ _ q) =
(Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q),
Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (q / gcd p q)) := by
rw [numDenom, liftOn'_div, if_neg hq]
intro p
rw [if_pos rfl, if_neg (one_ne_zero' K[X])]
simp
/-- `RatFunc.num` is the numerator of a rational function,
normalized such that the denominator is monic. -/
def num (x : RatFunc K) : K[X] :=
x.numDenom.1
private theorem num_div' (p : K[X]) {q : K[X]} (hq : q ≠ 0) :
num (algebraMap _ _ p / algebraMap _ _ q) =
Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q) := by
rw [num, numDenom_div _ hq]
@[simp]
theorem num_zero : num (0 : RatFunc K) = 0 := by convert num_div' (0 : K[X]) one_ne_zero <;> simp
@[simp]
theorem num_div (p q : K[X]) :
num (algebraMap _ _ p / algebraMap _ _ q) =
Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q) := by
by_cases hq : q = 0
· simp [hq]
· exact num_div' p hq
@[simp]
theorem num_one : num (1 : RatFunc K) = 1 := by convert num_div (1 : K[X]) 1 <;> simp
@[simp]
theorem num_algebraMap (p : K[X]) : num (algebraMap _ _ p) = p := by convert num_div p 1 <;> simp
theorem num_div_dvd (p : K[X]) {q : K[X]} (hq : q ≠ 0) :
num (algebraMap _ _ p / algebraMap _ _ q) ∣ p := by
rw [num_div _ q, C_mul_dvd]
· exact EuclideanDomain.div_dvd_of_dvd (gcd_dvd_left p q)
· simpa only [Ne, inv_eq_zero, Polynomial.leadingCoeff_eq_zero] using right_div_gcd_ne_zero hq
/-- A version of `num_div_dvd` with the LHS in simp normal form -/
@[simp]
theorem num_div_dvd' (p : K[X]) {q : K[X]} (hq : q ≠ 0) :
C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q) ∣ p := by simpa using num_div_dvd p hq
/-- `RatFunc.denom` is the denominator of a rational function,
normalized such that it is monic. -/
def denom (x : RatFunc K) : K[X] :=
x.numDenom.2
@[simp]
theorem denom_div (p : K[X]) {q : K[X]} (hq : q ≠ 0) :
denom (algebraMap _ _ p / algebraMap _ _ q) =
Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (q / gcd p q) := by
rw [denom, numDenom_div _ hq]
theorem monic_denom (x : RatFunc K) : (denom x).Monic := by
induction x using RatFunc.induction_on with
| f p q hq =>
rw [denom_div p hq, mul_comm]
exact Polynomial.monic_mul_leadingCoeff_inv (right_div_gcd_ne_zero hq)
theorem denom_ne_zero (x : RatFunc K) : denom x ≠ 0 :=
(monic_denom x).ne_zero
@[simp]
theorem denom_zero : denom (0 : RatFunc K) = 1 := by
convert denom_div (0 : K[X]) one_ne_zero <;> simp
@[simp]
theorem denom_one : denom (1 : RatFunc K) = 1 := by
convert denom_div (1 : K[X]) one_ne_zero <;> simp
@[simp]
theorem denom_algebraMap (p : K[X]) : denom (algebraMap _ (RatFunc K) p) = 1 := by
convert denom_div p one_ne_zero <;> simp
@[simp]
theorem denom_div_dvd (p q : K[X]) : denom (algebraMap _ _ p / algebraMap _ _ q) ∣ q := by
by_cases hq : q = 0
· simp [hq]
rw [denom_div _ hq, C_mul_dvd]
· exact EuclideanDomain.div_dvd_of_dvd (gcd_dvd_right p q)
· simpa only [Ne, inv_eq_zero, Polynomial.leadingCoeff_eq_zero] using right_div_gcd_ne_zero hq
@[simp]
theorem num_div_denom (x : RatFunc K) : algebraMap _ _ (num x) / algebraMap _ _ (denom x) = x := by
induction' x using RatFunc.induction_on with p q hq
-- Porting note: had to hint the type of this `have`
have q_div_ne_zero : q / gcd p q ≠ 0 := right_div_gcd_ne_zero hq
rw [num_div p q, denom_div p hq, RingHom.map_mul, RingHom.map_mul, mul_div_mul_left,
div_eq_div_iff, ← RingHom.map_mul, ← RingHom.map_mul, mul_comm _ q, ←
EuclideanDomain.mul_div_assoc, ← EuclideanDomain.mul_div_assoc, mul_comm]
· apply gcd_dvd_right
· apply gcd_dvd_left
· exact algebraMap_ne_zero q_div_ne_zero
· exact algebraMap_ne_zero hq
· refine algebraMap_ne_zero (mt Polynomial.C_eq_zero.mp ?_)
exact inv_ne_zero (Polynomial.leadingCoeff_ne_zero.mpr q_div_ne_zero)
theorem isCoprime_num_denom (x : RatFunc K) : IsCoprime x.num x.denom := by
induction' x using RatFunc.induction_on with p q hq
rw [num_div, denom_div _ hq]
exact (isCoprime_mul_unit_left
((leadingCoeff_ne_zero.2 <| right_div_gcd_ne_zero hq).isUnit.inv.map C) _ _).2
(isCoprime_div_gcd_div_gcd hq)
@[simp]
theorem num_eq_zero_iff {x : RatFunc K} : num x = 0 ↔ x = 0 :=
⟨fun h => by rw [← num_div_denom x, h, RingHom.map_zero, zero_div], fun h => h.symm ▸ num_zero⟩
theorem num_ne_zero {x : RatFunc K} (hx : x ≠ 0) : num x ≠ 0 :=
mt num_eq_zero_iff.mp hx
theorem num_mul_eq_mul_denom_iff {x : RatFunc K} {p q : K[X]} (hq : q ≠ 0) :
x.num * q = p * x.denom ↔ x = algebraMap _ _ p / algebraMap _ _ q := by
rw [← (algebraMap_injective K).eq_iff, eq_div_iff (algebraMap_ne_zero hq)]
conv_rhs => rw [← num_div_denom x]
rw [RingHom.map_mul, RingHom.map_mul, div_eq_mul_inv, mul_assoc, mul_comm (Inv.inv _), ←
mul_assoc, ← div_eq_mul_inv, div_eq_iff]
exact algebraMap_ne_zero (denom_ne_zero x)
theorem num_denom_add (x y : RatFunc K) :
(x + y).num * (x.denom * y.denom) = (x.num * y.denom + x.denom * y.num) * (x + y).denom :=
(num_mul_eq_mul_denom_iff (mul_ne_zero (denom_ne_zero x) (denom_ne_zero y))).mpr <| by
conv_lhs => rw [← num_div_denom x, ← num_div_denom y]
rw [div_add_div, RingHom.map_mul, RingHom.map_add, RingHom.map_mul, RingHom.map_mul]
· exact algebraMap_ne_zero (denom_ne_zero x)
· exact algebraMap_ne_zero (denom_ne_zero y)
theorem num_denom_neg (x : RatFunc K) : (-x).num * x.denom = -x.num * (-x).denom := by
rw [num_mul_eq_mul_denom_iff (denom_ne_zero x), _root_.map_neg, neg_div, num_div_denom]
theorem num_denom_mul (x y : RatFunc K) :
(x * y).num * (x.denom * y.denom) = x.num * y.num * (x * y).denom :=
(num_mul_eq_mul_denom_iff (mul_ne_zero (denom_ne_zero x) (denom_ne_zero y))).mpr <| by
conv_lhs =>
rw [← num_div_denom x, ← num_div_denom y, div_mul_div_comm, ← RingHom.map_mul, ←
RingHom.map_mul]
theorem num_dvd {x : RatFunc K} {p : K[X]} (hp : p ≠ 0) :
num x ∣ p ↔ ∃ q : K[X], q ≠ 0 ∧ x = algebraMap _ _ p / algebraMap _ _ q := by
constructor
· rintro ⟨q, rfl⟩
obtain ⟨_hx, hq⟩ := mul_ne_zero_iff.mp hp
use denom x * q
rw [RingHom.map_mul, RingHom.map_mul, ← div_mul_div_comm, div_self, mul_one, num_div_denom]
· exact ⟨mul_ne_zero (denom_ne_zero x) hq, rfl⟩
· exact algebraMap_ne_zero hq
· rintro ⟨q, hq, rfl⟩
exact num_div_dvd p hq
theorem denom_dvd {x : RatFunc K} {q : K[X]} (hq : q ≠ 0) :
denom x ∣ q ↔ ∃ p : K[X], x = algebraMap _ _ p / algebraMap _ _ q := by
constructor
· rintro ⟨p, rfl⟩
obtain ⟨_hx, hp⟩ := mul_ne_zero_iff.mp hq
use num x * p
rw [RingHom.map_mul, RingHom.map_mul, ← div_mul_div_comm, div_self, mul_one, num_div_denom]
exact algebraMap_ne_zero hp
· rintro ⟨p, rfl⟩
exact denom_div_dvd p q
theorem num_mul_dvd (x y : RatFunc K) : num (x * y) ∣ num x * num y := by
by_cases hx : x = 0
· simp [hx]
by_cases hy : y = 0
· simp [hy]
rw [num_dvd (mul_ne_zero (num_ne_zero hx) (num_ne_zero hy))]
refine ⟨x.denom * y.denom, mul_ne_zero (denom_ne_zero x) (denom_ne_zero y), ?_⟩
rw [RingHom.map_mul, RingHom.map_mul, ← div_mul_div_comm, num_div_denom, num_div_denom]
theorem denom_mul_dvd (x y : RatFunc K) : denom (x * y) ∣ denom x * denom y := by
rw [denom_dvd (mul_ne_zero (denom_ne_zero x) (denom_ne_zero y))]
refine ⟨x.num * y.num, ?_⟩
rw [RingHom.map_mul, RingHom.map_mul, ← div_mul_div_comm, num_div_denom, num_div_denom]
theorem denom_add_dvd (x y : RatFunc K) : denom (x + y) ∣ denom x * denom y := by
rw [denom_dvd (mul_ne_zero (denom_ne_zero x) (denom_ne_zero y))]
refine ⟨x.num * y.denom + x.denom * y.num, ?_⟩
rw [RingHom.map_mul, RingHom.map_add, RingHom.map_mul, RingHom.map_mul, ← div_add_div,
num_div_denom, num_div_denom]
· exact algebraMap_ne_zero (denom_ne_zero x)
· exact algebraMap_ne_zero (denom_ne_zero y)
theorem map_denom_ne_zero {L F : Type*} [Zero L] [FunLike F K[X] L] [ZeroHomClass F K[X] L]
(φ : F) (hφ : Function.Injective φ) (f : RatFunc K) : φ f.denom ≠ 0 := fun H =>
(denom_ne_zero f) ((map_eq_zero_iff φ hφ).mp H)
theorem map_apply {R F : Type*} [CommRing R] [IsDomain R]
[FunLike F K[X] R[X]] [MonoidHomClass F K[X] R[X]] (φ : F)
(hφ : K[X]⁰ ≤ R[X]⁰.comap φ) (f : RatFunc K) :
map φ hφ f = algebraMap _ _ (φ f.num) / algebraMap _ _ (φ f.denom) := by
rw [← num_div_denom f, map_apply_div_ne_zero, num_div_denom f]
exact denom_ne_zero _
theorem liftMonoidWithZeroHom_apply {L : Type*} [CommGroupWithZero L] (φ : K[X] →*₀ L)
(hφ : K[X]⁰ ≤ L⁰.comap φ) (f : RatFunc K) :
liftMonoidWithZeroHom φ hφ f = φ f.num / φ f.denom := by
rw [← num_div_denom f, liftMonoidWithZeroHom_apply_div, num_div_denom]
theorem liftRingHom_apply {L : Type*} [Field L] (φ : K[X] →+* L) (hφ : K[X]⁰ ≤ L⁰.comap φ)
(f : RatFunc K) : liftRingHom φ hφ f = φ f.num / φ f.denom :=
liftMonoidWithZeroHom_apply _ hφ _ -- Porting note: added explicit `hφ`
theorem liftAlgHom_apply {L S : Type*} [Field L] [CommSemiring S] [Algebra S K[X]] [Algebra S L]
(φ : K[X] →ₐ[S] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (f : RatFunc K) :
liftAlgHom φ hφ f = φ f.num / φ f.denom :=
liftMonoidWithZeroHom_apply _ hφ _ -- Porting note: added explicit `hφ`
theorem num_mul_denom_add_denom_mul_num_ne_zero {x y : RatFunc K} (hxy : x + y ≠ 0) :
x.num * y.denom + x.denom * y.num ≠ 0 := by
intro h_zero
have h := num_denom_add x y
rw [h_zero, zero_mul] at h
exact (mul_ne_zero (num_ne_zero hxy) (mul_ne_zero x.denom_ne_zero y.denom_ne_zero)) h
end NumDenom
end RatFunc
|
FieldTheory\RatFunc\Defs.lean | /-
Copyright (c) 2021 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.Algebra.Polynomial.RingDivision
/-!
# The field of rational functions
Files in this folder define the field `RatFunc K` of rational functions over a field `K`, show it
is the field of fractions of `K[X]` and provide the main results concerning it. This file contains
the basic definition.
For connections with Laurent Series, see `Mathlib.RingTheory.LaurentSeries`.
## Main definitions
We provide a set of recursion and induction principles:
- `RatFunc.liftOn`: define a function by mapping a fraction of polynomials `p/q` to `f p q`,
if `f` is well-defined in the sense that `p/q = p'/q' → f p q = f p' q'`.
- `RatFunc.liftOn'`: define a function by mapping a fraction of polynomials `p/q` to `f p q`,
if `f` is well-defined in the sense that `f (a * p) (a * q) = f p' q'`.
- `RatFunc.induction_on`: if `P` holds on `p / q` for all polynomials `p q`, then `P` holds on all
rational functions
## Implementation notes
To provide good API encapsulation and speed up unification problems,
`RatFunc` is defined as a structure, and all operations are `@[irreducible] def`s
We need a couple of maps to set up the `Field` and `IsFractionRing` structure,
namely `RatFunc.ofFractionRing`, `RatFunc.toFractionRing`, `RatFunc.mk` and
`RatFunc.toFractionRingRingEquiv`.
All these maps get `simp`ed to bundled morphisms like `algebraMap K[X] (RatFunc K)`
and `IsLocalization.algEquiv`.
There are separate lifts and maps of homomorphisms, to provide routes of lifting even when
the codomain is not a field or even an integral domain.
## References
* [Kleiman, *Misconceptions about $K_X$*][kleiman1979]
* https://freedommathdance.blogspot.com/2012/11/misconceptions-about-kx.html
* https://stacks.math.columbia.edu/tag/01X1
-/
noncomputable section
open scoped Classical
open scoped nonZeroDivisors Polynomial
universe u v
variable (K : Type u)
/-- `RatFunc K` is `K(X)`, the field of rational functions over `K`.
The inclusion of polynomials into `RatFunc` is `algebraMap K[X] (RatFunc K)`,
the maps between `RatFunc K` and another field of fractions of `K[X]`,
especially `FractionRing K[X]`, are given by `IsLocalization.algEquiv`.
-/
structure RatFunc [CommRing K] : Type u where ofFractionRing ::
/-- the coercion to the fraction ring of the polynomial ring-/
toFractionRing : FractionRing K[X]
namespace RatFunc
section CommRing
variable {K}
variable [CommRing K]
section Rec
/-! ### Constructing `RatFunc`s and their induction principles -/
theorem ofFractionRing_injective : Function.Injective (ofFractionRing : _ → RatFunc K) :=
fun _ _ => ofFractionRing.inj
theorem toFractionRing_injective : Function.Injective (toFractionRing : _ → FractionRing K[X])
-- Porting note: the `xy` input was `rfl` and then there was no need for the `subst`
| ⟨x⟩, ⟨y⟩, xy => by subst xy; rfl
/-- Non-dependent recursion principle for `RatFunc K`:
To construct a term of `P : Sort*` out of `x : RatFunc K`,
it suffices to provide a constructor `f : Π (p q : K[X]), P`
and a proof that `f p q = f p' q'` for all `p q p' q'` such that `q' * p = q * p'` where
both `q` and `q'` are not zero divisors, stated as `q ∉ K[X]⁰`, `q' ∉ K[X]⁰`.
If considering `K` as an integral domain, this is the same as saying that
we construct a value of `P` for such elements of `RatFunc K` by setting
`liftOn (p / q) f _ = f p q`.
When `[IsDomain K]`, one can use `RatFunc.liftOn'`, which has the stronger requirement
of `∀ {p q a : K[X]} (hq : q ≠ 0) (ha : a ≠ 0), f (a * p) (a * q) = f p q)`.
-/
protected irreducible_def liftOn {P : Sort v} (x : RatFunc K) (f : K[X] → K[X] → P)
(H : ∀ {p q p' q'} (_hq : q ∈ K[X]⁰) (_hq' : q' ∈ K[X]⁰), q' * p = q * p' → f p q = f p' q') :
P := by
refine Localization.liftOn (toFractionRing x) (fun p q => f p q) ?_
intros p p' q q' h
exact H q.2 q'.2 (let ⟨⟨c, hc⟩, mul_eq⟩ := Localization.r_iff_exists.mp h
mul_cancel_left_coe_nonZeroDivisors.mp mul_eq)
-- Porting note: the definition above was as follows
-- (-- Fix timeout by manipulating elaboration order
-- fun p q => f p q)
-- fun p p' q q' h => by
-- exact H q.2 q'.2
-- (let ⟨⟨c, hc⟩, mul_eq⟩ := Localization.r_iff_exists.mp h
-- mul_cancel_left_coe_nonZeroDivisors.mp mul_eq)
theorem liftOn_ofFractionRing_mk {P : Sort v} (n : K[X]) (d : K[X]⁰) (f : K[X] → K[X] → P)
(H : ∀ {p q p' q'} (_hq : q ∈ K[X]⁰) (_hq' : q' ∈ K[X]⁰), q' * p = q * p' → f p q = f p' q') :
RatFunc.liftOn (ofFractionRing (Localization.mk n d)) f @H = f n d := by
rw [RatFunc.liftOn]
exact Localization.liftOn_mk _ _ _ _
theorem liftOn_condition_of_liftOn'_condition {P : Sort v} {f : K[X] → K[X] → P}
(H : ∀ {p q a} (hq : q ≠ 0) (_ha : a ≠ 0), f (a * p) (a * q) = f p q) ⦃p q p' q' : K[X]⦄
(hq : q ≠ 0) (hq' : q' ≠ 0) (h : q' * p = q * p') : f p q = f p' q' :=
calc
f p q = f (q' * p) (q' * q) := (H hq hq').symm
_ = f (q * p') (q * q') := by rw [h, mul_comm q']
_ = f p' q' := H hq' hq
section IsDomain
variable [IsDomain K]
/-- `RatFunc.mk (p q : K[X])` is `p / q` as a rational function.
If `q = 0`, then `mk` returns 0.
This is an auxiliary definition used to define an `Algebra` structure on `RatFunc`;
the `simp` normal form of `mk p q` is `algebraMap _ _ p / algebraMap _ _ q`.
-/
protected irreducible_def mk (p q : K[X]) : RatFunc K :=
ofFractionRing (algebraMap _ _ p / algebraMap _ _ q)
theorem mk_eq_div' (p q : K[X]) :
RatFunc.mk p q = ofFractionRing (algebraMap _ _ p / algebraMap _ _ q) := by rw [RatFunc.mk]
theorem mk_zero (p : K[X]) : RatFunc.mk p 0 = ofFractionRing (0 : FractionRing K[X]) := by
rw [mk_eq_div', RingHom.map_zero, div_zero]
theorem mk_coe_def (p : K[X]) (q : K[X]⁰) :
-- Porting note: filled in `(FractionRing K[X])` that was an underscore.
RatFunc.mk p q = ofFractionRing (IsLocalization.mk' (FractionRing K[X]) p q) := by
simp only [mk_eq_div', ← Localization.mk_eq_mk', FractionRing.mk_eq_div]
theorem mk_def_of_mem (p : K[X]) {q} (hq : q ∈ K[X]⁰) :
RatFunc.mk p q = ofFractionRing (IsLocalization.mk' (FractionRing K[X]) p ⟨q, hq⟩) := by
-- Porting note: there was an `[anonymous]` in the simp set
simp only [← mk_coe_def]
theorem mk_def_of_ne (p : K[X]) {q : K[X]} (hq : q ≠ 0) :
RatFunc.mk p q =
ofFractionRing (IsLocalization.mk' (FractionRing K[X]) p
⟨q, mem_nonZeroDivisors_iff_ne_zero.mpr hq⟩) :=
mk_def_of_mem p _
theorem mk_eq_localization_mk (p : K[X]) {q : K[X]} (hq : q ≠ 0) :
RatFunc.mk p q =
ofFractionRing (Localization.mk p ⟨q, mem_nonZeroDivisors_iff_ne_zero.mpr hq⟩) := by
-- Porting note: the original proof, did not need to pass `hq`
rw [mk_def_of_ne _ hq, Localization.mk_eq_mk']
-- porting note: replaced `algebraMap _ _` with `algebraMap K[X] (FractionRing K[X])`
theorem mk_one' (p : K[X]) :
RatFunc.mk p 1 = ofFractionRing (algebraMap K[X] (FractionRing K[X]) p) := by
-- Porting note: had to hint `M := K[X]⁰` below
rw [← IsLocalization.mk'_one (M := K[X]⁰) (FractionRing K[X]) p, ← mk_coe_def, Submonoid.coe_one]
theorem mk_eq_mk {p q p' q' : K[X]} (hq : q ≠ 0) (hq' : q' ≠ 0) :
RatFunc.mk p q = RatFunc.mk p' q' ↔ p * q' = p' * q := by
rw [mk_def_of_ne _ hq, mk_def_of_ne _ hq', ofFractionRing_injective.eq_iff,
IsLocalization.mk'_eq_iff_eq', -- Porting note: removed `[anonymous], [anonymous]`
(IsFractionRing.injective K[X] (FractionRing K[X])).eq_iff]
theorem liftOn_mk {P : Sort v} (p q : K[X]) (f : K[X] → K[X] → P) (f0 : ∀ p, f p 0 = f 0 1)
(H' : ∀ {p q p' q'} (_hq : q ≠ 0) (_hq' : q' ≠ 0), q' * p = q * p' → f p q = f p' q')
(H : ∀ {p q p' q'} (_hq : q ∈ K[X]⁰) (_hq' : q' ∈ K[X]⁰), q' * p = q * p' → f p q = f p' q' :=
fun {p q p' q'} hq hq' h => H' (nonZeroDivisors.ne_zero hq) (nonZeroDivisors.ne_zero hq') h) :
(RatFunc.mk p q).liftOn f @H = f p q := by
by_cases hq : q = 0
· subst hq
simp only [mk_zero, f0, ← Localization.mk_zero 1, Localization.liftOn_mk,
liftOn_ofFractionRing_mk, Submonoid.coe_one]
· simp only [mk_eq_localization_mk _ hq, Localization.liftOn_mk, liftOn_ofFractionRing_mk]
/-- Non-dependent recursion principle for `RatFunc K`: if `f p q : P` for all `p q`,
such that `f (a * p) (a * q) = f p q`, then we can find a value of `P`
for all elements of `RatFunc K` by setting `lift_on' (p / q) f _ = f p q`.
The value of `f p 0` for any `p` is never used and in principle this may be anything,
although many usages of `lift_on'` assume `f p 0 = f 0 1`.
-/
protected irreducible_def liftOn' {P : Sort v} (x : RatFunc K) (f : K[X] → K[X] → P)
(H : ∀ {p q a} (_hq : q ≠ 0) (_ha : a ≠ 0), f (a * p) (a * q) = f p q) : P :=
x.liftOn f fun {_p _q _p' _q'} hq hq' =>
liftOn_condition_of_liftOn'_condition (@H) (nonZeroDivisors.ne_zero hq)
(nonZeroDivisors.ne_zero hq')
theorem liftOn'_mk {P : Sort v} (p q : K[X]) (f : K[X] → K[X] → P) (f0 : ∀ p, f p 0 = f 0 1)
(H : ∀ {p q a} (_hq : q ≠ 0) (_ha : a ≠ 0), f (a * p) (a * q) = f p q) :
(RatFunc.mk p q).liftOn' f @H = f p q := by
rw [RatFunc.liftOn', RatFunc.liftOn_mk _ _ _ f0]
apply liftOn_condition_of_liftOn'_condition H
/-- Induction principle for `RatFunc K`: if `f p q : P (RatFunc.mk p q)` for all `p q`,
then `P` holds on all elements of `RatFunc K`.
See also `induction_on`, which is a recursion principle defined in terms of `algebraMap`.
-/
@[elab_as_elim]
protected theorem induction_on' {P : RatFunc K → Prop} :
∀ (x : RatFunc K) (_pq : ∀ (p q : K[X]) (_ : q ≠ 0), P (RatFunc.mk p q)), P x
| ⟨x⟩, f =>
Localization.induction_on x fun ⟨p, q⟩ => by
simpa only [mk_coe_def, Localization.mk_eq_mk'] using
f p q (mem_nonZeroDivisors_iff_ne_zero.mp q.2)
end IsDomain
end Rec
end CommRing
end RatFunc
|
FieldTheory\RatFunc\Degree.lean | /-
Copyright (c) 2021 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.FieldTheory.RatFunc.AsPolynomial
import Mathlib.RingTheory.EuclideanDomain
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.RingTheory.Polynomial.Content
/-!
# The degree of rational functions
## Main definitions
We define the degree of a rational function, with values in `ℤ`:
- `intDegree` is the degree of a rational function, defined as the difference between the
`natDegree` of its numerator and the `natDegree` of its denominator. In particular,
`intDegree 0 = 0`.
-/
noncomputable section
universe u
variable {K : Type u}
namespace RatFunc
section IntDegree
open Polynomial
variable [Field K]
/-- `intDegree x` is the degree of the rational function `x`, defined as the difference between
the `natDegree` of its numerator and the `natDegree` of its denominator. In particular,
`intDegree 0 = 0`. -/
def intDegree (x : RatFunc K) : ℤ :=
natDegree x.num - natDegree x.denom
@[simp]
theorem intDegree_zero : intDegree (0 : RatFunc K) = 0 := by
rw [intDegree, num_zero, natDegree_zero, denom_zero, natDegree_one, sub_self]
@[simp]
theorem intDegree_one : intDegree (1 : RatFunc K) = 0 := by
rw [intDegree, num_one, denom_one, sub_self]
@[simp]
theorem intDegree_C (k : K) : intDegree (C k) = 0 := by
rw [intDegree, num_C, natDegree_C, denom_C, natDegree_one, sub_self]
@[simp]
theorem intDegree_X : intDegree (X : RatFunc K) = 1 := by
rw [intDegree, num_X, Polynomial.natDegree_X, denom_X, Polynomial.natDegree_one,
Int.ofNat_one, Int.ofNat_zero, sub_zero]
@[simp]
theorem intDegree_polynomial {p : K[X]} :
intDegree (algebraMap K[X] (RatFunc K) p) = natDegree p := by
rw [intDegree, RatFunc.num_algebraMap, RatFunc.denom_algebraMap, Polynomial.natDegree_one,
Int.ofNat_zero, sub_zero]
theorem intDegree_mul {x y : RatFunc K} (hx : x ≠ 0) (hy : y ≠ 0) :
intDegree (x * y) = intDegree x + intDegree y := by
simp only [intDegree, add_sub, sub_add, sub_sub_eq_add_sub, sub_sub, sub_eq_sub_iff_add_eq_add]
norm_cast
rw [← Polynomial.natDegree_mul x.denom_ne_zero y.denom_ne_zero, ←
Polynomial.natDegree_mul (RatFunc.num_ne_zero (mul_ne_zero hx hy))
(mul_ne_zero x.denom_ne_zero y.denom_ne_zero),
← Polynomial.natDegree_mul (RatFunc.num_ne_zero hx) (RatFunc.num_ne_zero hy), ←
Polynomial.natDegree_mul (mul_ne_zero (RatFunc.num_ne_zero hx) (RatFunc.num_ne_zero hy))
(x * y).denom_ne_zero,
RatFunc.num_denom_mul]
@[simp]
theorem intDegree_neg (x : RatFunc K) : intDegree (-x) = intDegree x := by
by_cases hx : x = 0
· rw [hx, neg_zero]
· rw [intDegree, intDegree, ← natDegree_neg x.num]
exact
natDegree_sub_eq_of_prod_eq (num_ne_zero (neg_ne_zero.mpr hx)) (denom_ne_zero (-x))
(neg_ne_zero.mpr (num_ne_zero hx)) (denom_ne_zero x) (num_denom_neg x)
theorem intDegree_add {x y : RatFunc K} (hxy : x + y ≠ 0) :
(x + y).intDegree =
(x.num * y.denom + x.denom * y.num).natDegree - (x.denom * y.denom).natDegree :=
natDegree_sub_eq_of_prod_eq (num_ne_zero hxy) (x + y).denom_ne_zero
(num_mul_denom_add_denom_mul_num_ne_zero hxy) (mul_ne_zero x.denom_ne_zero y.denom_ne_zero)
(num_denom_add x y)
theorem natDegree_num_mul_right_sub_natDegree_denom_mul_left_eq_intDegree {x : RatFunc K}
(hx : x ≠ 0) {s : K[X]} (hs : s ≠ 0) :
((x.num * s).natDegree : ℤ) - (s * x.denom).natDegree = x.intDegree := by
apply natDegree_sub_eq_of_prod_eq (mul_ne_zero (num_ne_zero hx) hs)
(mul_ne_zero hs x.denom_ne_zero) (num_ne_zero hx) x.denom_ne_zero
rw [mul_assoc]
theorem intDegree_add_le {x y : RatFunc K} (hy : y ≠ 0) (hxy : x + y ≠ 0) :
intDegree (x + y) ≤ max (intDegree x) (intDegree y) := by
by_cases hx : x = 0
· simp only [hx, zero_add, ne_eq] at hxy
simp [hx, hxy]
rw [intDegree_add hxy, ←
natDegree_num_mul_right_sub_natDegree_denom_mul_left_eq_intDegree hx y.denom_ne_zero,
mul_comm y.denom, ←
natDegree_num_mul_right_sub_natDegree_denom_mul_left_eq_intDegree hy x.denom_ne_zero,
le_max_iff, sub_le_sub_iff_right, Int.ofNat_le, sub_le_sub_iff_right, Int.ofNat_le, ←
le_max_iff, mul_comm y.num]
exact natDegree_add_le _ _
end IntDegree
end RatFunc
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.