path stringlengths 11 71 | content stringlengths 75 124k |
|---|---|
RingTheory\Polynomial\Eisenstein\Basic.lean | /-
Copyright (c) 2022 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import Mathlib.RingTheory.EisensteinCriterion
import Mathlib.RingTheory.Polynomial.ScaleRoots
/-!
# Eisenstein polynomials
Given an ideal `𝓟` of a commutative semiring `R`, we say that a polynomial `f : R[X]` is
*Eisenstein at `𝓟`* if `f.leadingCoeff ∉ 𝓟`, `∀ n, n < f.natDegree → f.coeff n ∈ 𝓟` and
`f.coeff 0 ∉ 𝓟 ^ 2`. In this file we gather miscellaneous results about Eisenstein polynomials.
## Main definitions
* `Polynomial.IsEisensteinAt f 𝓟`: the property of being Eisenstein at `𝓟`.
## Main results
* `Polynomial.IsEisensteinAt.irreducible`: if a primitive `f` satisfies `f.IsEisensteinAt 𝓟`,
where `𝓟.IsPrime`, then `f` is irreducible.
## Implementation details
We also define a notion `IsWeaklyEisensteinAt` requiring only that
`∀ n < f.natDegree → f.coeff n ∈ 𝓟`. This makes certain results slightly more general and it is
useful since it is sometimes better behaved (for example it is stable under `Polynomial.map`).
-/
universe u v w z
variable {R : Type u}
open Ideal Algebra Finset
open Polynomial
namespace Polynomial
/-- Given an ideal `𝓟` of a commutative semiring `R`, we say that a polynomial `f : R[X]`
is *weakly Eisenstein at `𝓟`* if `∀ n, n < f.natDegree → f.coeff n ∈ 𝓟`. -/
@[mk_iff]
structure IsWeaklyEisensteinAt [CommSemiring R] (f : R[X]) (𝓟 : Ideal R) : Prop where
mem : ∀ {n}, n < f.natDegree → f.coeff n ∈ 𝓟
/-- Given an ideal `𝓟` of a commutative semiring `R`, we say that a polynomial `f : R[X]`
is *Eisenstein at `𝓟`* if `f.leadingCoeff ∉ 𝓟`, `∀ n, n < f.natDegree → f.coeff n ∈ 𝓟` and
`f.coeff 0 ∉ 𝓟 ^ 2`. -/
@[mk_iff]
structure IsEisensteinAt [CommSemiring R] (f : R[X]) (𝓟 : Ideal R) : Prop where
leading : f.leadingCoeff ∉ 𝓟
mem : ∀ {n}, n < f.natDegree → f.coeff n ∈ 𝓟
not_mem : f.coeff 0 ∉ 𝓟 ^ 2
namespace IsWeaklyEisensteinAt
section CommSemiring
variable [CommSemiring R] {𝓟 : Ideal R} {f : R[X]}
theorem map (hf : f.IsWeaklyEisensteinAt 𝓟) {A : Type v} [CommRing A] (φ : R →+* A) :
(f.map φ).IsWeaklyEisensteinAt (𝓟.map φ) := by
refine (isWeaklyEisensteinAt_iff _ _).2 fun hn => ?_
rw [coeff_map]
exact mem_map_of_mem _ (hf.mem (lt_of_lt_of_le hn (natDegree_map_le _ _)))
end CommSemiring
section CommRing
variable [CommRing R] {𝓟 : Ideal R} {f : R[X]}
variable {S : Type v} [CommRing S] [Algebra R S]
section Principal
variable {p : R}
theorem exists_mem_adjoin_mul_eq_pow_natDegree {x : S} (hx : aeval x f = 0) (hmo : f.Monic)
(hf : f.IsWeaklyEisensteinAt (Submodule.span R {p})) : ∃ y ∈ adjoin R ({x} : Set S),
(algebraMap R S) p * y = x ^ (f.map (algebraMap R S)).natDegree := by
rw [aeval_def, Polynomial.eval₂_eq_eval_map, eval_eq_sum_range, range_add_one,
sum_insert not_mem_range_self, sum_range, (hmo.map (algebraMap R S)).coeff_natDegree,
one_mul] at hx
replace hx := eq_neg_of_add_eq_zero_left hx
have : ∀ n < f.natDegree, p ∣ f.coeff n := by
intro n hn
exact mem_span_singleton.1 (by simpa using hf.mem hn)
choose! φ hφ using this
conv_rhs at hx =>
congr
congr
· skip
ext i
rw [coeff_map, hφ i.1 (lt_of_lt_of_le i.2 (natDegree_map_le _ _)),
RingHom.map_mul, mul_assoc]
rw [hx, ← mul_sum, neg_eq_neg_one_mul, ← mul_assoc (-1 : S), mul_comm (-1 : S), mul_assoc]
refine
⟨-1 * ∑ i : Fin (f.map (algebraMap R S)).natDegree, (algebraMap R S) (φ i.1) * x ^ i.1, ?_, rfl⟩
exact
Subalgebra.mul_mem _ (Subalgebra.neg_mem _ (Subalgebra.one_mem _))
(Subalgebra.sum_mem _ fun i _ =>
Subalgebra.mul_mem _ (Subalgebra.algebraMap_mem _ _)
(Subalgebra.pow_mem _ (subset_adjoin (Set.mem_singleton x)) _))
theorem exists_mem_adjoin_mul_eq_pow_natDegree_le {x : S} (hx : aeval x f = 0) (hmo : f.Monic)
(hf : f.IsWeaklyEisensteinAt (Submodule.span R {p})) :
∀ i, (f.map (algebraMap R S)).natDegree ≤ i →
∃ y ∈ adjoin R ({x} : Set S), (algebraMap R S) p * y = x ^ i := by
intro i hi
obtain ⟨k, hk⟩ := exists_add_of_le hi
rw [hk, pow_add]
obtain ⟨y, hy, H⟩ := exists_mem_adjoin_mul_eq_pow_natDegree hx hmo hf
refine ⟨y * x ^ k, ?_, ?_⟩
· exact Subalgebra.mul_mem _ hy (Subalgebra.pow_mem _ (subset_adjoin (Set.mem_singleton x)) _)
· rw [← mul_assoc _ y, H]
end Principal
-- Porting note: `Ideal.neg_mem_iff` was `neg_mem_iff` on line 142 but Lean was not able to find
-- NegMemClass
theorem pow_natDegree_le_of_root_of_monic_mem (hf : f.IsWeaklyEisensteinAt 𝓟)
{x : R} (hroot : IsRoot f x) (hmo : f.Monic) :
∀ i, f.natDegree ≤ i → x ^ i ∈ 𝓟 := by
intro i hi
obtain ⟨k, hk⟩ := exists_add_of_le hi
rw [hk, pow_add]
suffices x ^ f.natDegree ∈ 𝓟 by exact mul_mem_right (x ^ k) 𝓟 this
rw [IsRoot.def, eval_eq_sum_range, Finset.range_add_one,
Finset.sum_insert Finset.not_mem_range_self, Finset.sum_range, hmo.coeff_natDegree, one_mul] at
*
rw [eq_neg_of_add_eq_zero_left hroot, Ideal.neg_mem_iff]
exact Submodule.sum_mem _ fun i _ => mul_mem_right _ _ (hf.mem (Fin.is_lt i))
theorem pow_natDegree_le_of_aeval_zero_of_monic_mem_map (hf : f.IsWeaklyEisensteinAt 𝓟)
{x : S} (hx : aeval x f = 0) (hmo : f.Monic) :
∀ i, (f.map (algebraMap R S)).natDegree ≤ i → x ^ i ∈ 𝓟.map (algebraMap R S) := by
suffices x ^ (f.map (algebraMap R S)).natDegree ∈ 𝓟.map (algebraMap R S) by
intro i hi
obtain ⟨k, hk⟩ := exists_add_of_le hi
rw [hk, pow_add]
exact mul_mem_right _ _ this
rw [aeval_def, eval₂_eq_eval_map, ← IsRoot.def] at hx
exact pow_natDegree_le_of_root_of_monic_mem (hf.map _) hx (hmo.map _) _ rfl.le
end CommRing
end IsWeaklyEisensteinAt
section ScaleRoots
variable {A : Type*} [CommRing R] [CommRing A]
theorem scaleRoots.isWeaklyEisensteinAt (p : R[X]) {x : R} {P : Ideal R} (hP : x ∈ P) :
(scaleRoots p x).IsWeaklyEisensteinAt P := by
refine ⟨fun i => ?_⟩
rw [coeff_scaleRoots]
rw [natDegree_scaleRoots, ← tsub_pos_iff_lt] at i
exact Ideal.mul_mem_left _ _ (Ideal.pow_mem_of_mem P hP _ i)
theorem dvd_pow_natDegree_of_eval₂_eq_zero {f : R →+* A} (hf : Function.Injective f) {p : R[X]}
(hp : p.Monic) (x y : R) (z : A) (h : p.eval₂ f z = 0) (hz : f x * z = f y) :
x ∣ y ^ p.natDegree := by
rw [← natDegree_scaleRoots p x, ← Ideal.mem_span_singleton]
refine
(scaleRoots.isWeaklyEisensteinAt _
(Ideal.mem_span_singleton.mpr <| dvd_refl x)).pow_natDegree_le_of_root_of_monic_mem
?_ ((monic_scaleRoots_iff x).mpr hp) _ le_rfl
rw [injective_iff_map_eq_zero'] at hf
have : eval₂ f _ (p.scaleRoots x) = 0 := scaleRoots_eval₂_eq_zero f h
rwa [hz, Polynomial.eval₂_at_apply, hf] at this
theorem dvd_pow_natDegree_of_aeval_eq_zero [Algebra R A] [Nontrivial A] [NoZeroSMulDivisors R A]
{p : R[X]} (hp : p.Monic) (x y : R) (z : A) (h : Polynomial.aeval z p = 0)
(hz : z * algebraMap R A x = algebraMap R A y) : x ∣ y ^ p.natDegree :=
dvd_pow_natDegree_of_eval₂_eq_zero (NoZeroSMulDivisors.algebraMap_injective R A) hp x y z h
((mul_comm _ _).trans hz)
end ScaleRoots
namespace IsEisensteinAt
section CommSemiring
variable [CommSemiring R] {𝓟 : Ideal R} {f : R[X]}
theorem _root_.Polynomial.Monic.leadingCoeff_not_mem (hf : f.Monic) (h : 𝓟 ≠ ⊤) :
¬f.leadingCoeff ∈ 𝓟 := hf.leadingCoeff.symm ▸ (Ideal.ne_top_iff_one _).1 h
theorem _root_.Polynomial.Monic.isEisensteinAt_of_mem_of_not_mem (hf : f.Monic) (h : 𝓟 ≠ ⊤)
(hmem : ∀ {n}, n < f.natDegree → f.coeff n ∈ 𝓟) (hnot_mem : f.coeff 0 ∉ 𝓟 ^ 2) :
f.IsEisensteinAt 𝓟 :=
{ leading := Polynomial.Monic.leadingCoeff_not_mem hf h
mem := fun hn => hmem hn
not_mem := hnot_mem }
theorem isWeaklyEisensteinAt (hf : f.IsEisensteinAt 𝓟) : IsWeaklyEisensteinAt f 𝓟 :=
⟨fun h => hf.mem h⟩
theorem coeff_mem (hf : f.IsEisensteinAt 𝓟) {n : ℕ} (hn : n ≠ f.natDegree) : f.coeff n ∈ 𝓟 := by
cases' ne_iff_lt_or_gt.1 hn with h₁ h₂
· exact hf.mem h₁
· rw [coeff_eq_zero_of_natDegree_lt h₂]
exact Ideal.zero_mem _
end CommSemiring
section IsDomain
variable [CommRing R] [IsDomain R] {𝓟 : Ideal R} {f : R[X]}
/-- If a primitive `f` satisfies `f.IsEisensteinAt 𝓟`, where `𝓟.IsPrime`,
then `f` is irreducible. -/
theorem irreducible (hf : f.IsEisensteinAt 𝓟) (hprime : 𝓟.IsPrime) (hu : f.IsPrimitive)
(hfd0 : 0 < f.natDegree) : Irreducible f :=
irreducible_of_eisenstein_criterion hprime hf.leading (fun _ hn => hf.mem (coe_lt_degree.1 hn))
(natDegree_pos_iff_degree_pos.1 hfd0) hf.not_mem hu
end IsDomain
end IsEisensteinAt
end Polynomial
|
RingTheory\Polynomial\Eisenstein\IsIntegral.lean | /-
Copyright (c) 2022 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import Mathlib.Data.Nat.Choose.Dvd
import Mathlib.RingTheory.IntegralClosure.IntegrallyClosed
import Mathlib.RingTheory.Norm.Basic
import Mathlib.RingTheory.Polynomial.Cyclotomic.Expand
/-!
# Eisenstein polynomials
In this file we gather more miscellaneous results about Eisenstein polynomials
## Main results
* `mem_adjoin_of_smul_prime_pow_smul_of_minpoly_isEisensteinAt`: let `K` be the field of fraction
of an integrally closed domain `R` and let `L` be a separable extension of `K`, generated by an
integral power basis `B` such that the minimal polynomial of `B.gen` is Eisenstein at `p`. Given
`z : L` integral over `R`, if `p ^ n • z ∈ adjoin R {B.gen}`, then `z ∈ adjoin R {B.gen}`.
Together with `Algebra.discr_mul_isIntegral_mem_adjoin` this result often allows to compute the
ring of integers of `L`.
-/
universe u v w z
variable {R : Type u}
open Ideal Algebra Finset
open scoped Polynomial
section Cyclotomic
variable (p : ℕ)
local notation "𝓟" => Submodule.span ℤ {(p : ℤ)}
open Polynomial
theorem cyclotomic_comp_X_add_one_isEisensteinAt [hp : Fact p.Prime] :
((cyclotomic p ℤ).comp (X + 1)).IsEisensteinAt 𝓟 := by
refine Monic.isEisensteinAt_of_mem_of_not_mem ?_
(Ideal.IsPrime.ne_top <| (Ideal.span_singleton_prime (mod_cast hp.out.ne_zero)).2 <|
Nat.prime_iff_prime_int.1 hp.out) (fun {i hi} => ?_) ?_
· rw [show (X + 1 : ℤ[X]) = X + C 1 by simp]
refine (cyclotomic.monic p ℤ).comp (monic_X_add_C 1) fun h => ?_
rw [natDegree_X_add_C] at h
exact zero_ne_one h.symm
· rw [cyclotomic_prime, geom_sum_X_comp_X_add_one_eq_sum, ← lcoeff_apply, map_sum]
conv =>
congr
congr
next => skip
ext
rw [lcoeff_apply, ← C_eq_natCast, C_mul_X_pow_eq_monomial, coeff_monomial]
rw [natDegree_comp, show (X + 1 : ℤ[X]) = X + C 1 by simp, natDegree_X_add_C, mul_one,
natDegree_cyclotomic, Nat.totient_prime hp.out] at hi
simp only [hi.trans_le (Nat.sub_le _ _), sum_ite_eq', mem_range, if_true,
Ideal.submodule_span_eq, Ideal.mem_span_singleton, Int.natCast_dvd_natCast]
exact hp.out.dvd_choose_self i.succ_ne_zero (lt_tsub_iff_right.1 hi)
· rw [coeff_zero_eq_eval_zero, eval_comp, cyclotomic_prime, eval_add, eval_X, eval_one, zero_add,
eval_geom_sum, one_geom_sum, Ideal.submodule_span_eq, Ideal.span_singleton_pow,
Ideal.mem_span_singleton]
intro h
obtain ⟨k, hk⟩ := Int.natCast_dvd_natCast.1 h
rw [mul_assoc, mul_comm 1, mul_one] at hk
nth_rw 1 [← Nat.mul_one p] at hk
rw [mul_right_inj' hp.out.ne_zero] at hk
exact Nat.Prime.not_dvd_one hp.out (Dvd.intro k hk.symm)
theorem cyclotomic_prime_pow_comp_X_add_one_isEisensteinAt [hp : Fact p.Prime] (n : ℕ) :
((cyclotomic (p ^ (n + 1)) ℤ).comp (X + 1)).IsEisensteinAt 𝓟 := by
refine Monic.isEisensteinAt_of_mem_of_not_mem ?_
(Ideal.IsPrime.ne_top <| (Ideal.span_singleton_prime (mod_cast hp.out.ne_zero)).2 <|
Nat.prime_iff_prime_int.1 hp.out) ?_ ?_
· rw [show (X + 1 : ℤ[X]) = X + C 1 by simp]
refine (cyclotomic.monic _ ℤ).comp (monic_X_add_C 1) fun h => ?_
rw [natDegree_X_add_C] at h
exact zero_ne_one h.symm
· induction' n with n hn
· intro i hi
rw [Nat.zero_add, pow_one] at hi ⊢
exact (cyclotomic_comp_X_add_one_isEisensteinAt p).mem hi
· intro i hi
rw [Ideal.submodule_span_eq, Ideal.mem_span_singleton, ← ZMod.intCast_zmod_eq_zero_iff_dvd,
show ↑(_ : ℤ) = Int.castRingHom (ZMod p) _ by rfl, ← coeff_map, map_comp, map_cyclotomic,
Polynomial.map_add, map_X, Polynomial.map_one, pow_add, pow_one,
cyclotomic_mul_prime_dvd_eq_pow, pow_comp, ← ZMod.expand_card, coeff_expand hp.out.pos]
· simp only [ite_eq_right_iff]
rintro ⟨k, hk⟩
rw [natDegree_comp, show (X + 1 : ℤ[X]) = X + C 1 by simp, natDegree_X_add_C, mul_one,
natDegree_cyclotomic, Nat.totient_prime_pow hp.out (Nat.succ_pos _), Nat.add_one_sub_one]
at hn hi
rw [hk, pow_succ', mul_assoc] at hi
rw [hk, mul_comm, Nat.mul_div_cancel _ hp.out.pos]
replace hn := hn (lt_of_mul_lt_mul_left' hi)
rw [Ideal.submodule_span_eq, Ideal.mem_span_singleton, ← ZMod.intCast_zmod_eq_zero_iff_dvd,
show ↑(_ : ℤ) = Int.castRingHom (ZMod p) _ by rfl, ← coeff_map] at hn
simpa [map_comp] using hn
· exact ⟨p ^ n, by rw [pow_succ']⟩
· rw [coeff_zero_eq_eval_zero, eval_comp, cyclotomic_prime_pow_eq_geom_sum hp.out, eval_add,
eval_X, eval_one, zero_add, eval_finset_sum]
simp only [eval_pow, eval_X, one_pow, sum_const, card_range, Nat.smul_one_eq_cast,
submodule_span_eq, Ideal.submodule_span_eq, Ideal.span_singleton_pow,
Ideal.mem_span_singleton]
intro h
obtain ⟨k, hk⟩ := Int.natCast_dvd_natCast.1 h
rw [mul_assoc, mul_comm 1, mul_one] at hk
nth_rw 1 [← Nat.mul_one p] at hk
rw [mul_right_inj' hp.out.ne_zero] at hk
exact Nat.Prime.not_dvd_one hp.out (Dvd.intro k hk.symm)
end Cyclotomic
section IsIntegral
variable {K : Type v} {L : Type z} {p : R} [CommRing R] [Field K] [Field L]
variable [Algebra K L] [Algebra R L] [Algebra R K] [IsScalarTower R K L] [Algebra.IsSeparable K L]
variable [IsDomain R] [IsFractionRing R K] [IsIntegrallyClosed R]
local notation "𝓟" => Submodule.span R {(p : R)}
open IsIntegrallyClosed PowerBasis Nat Polynomial IsScalarTower
/-- Let `K` be the field of fraction of an integrally closed domain `R` and let `L` be a separable
extension of `K`, generated by an integral power basis `B` such that the minimal polynomial of
`B.gen` is Eisenstein at `p`. Given `z : L` integral over `R`, if `Q : R[X]` is such that
`aeval B.gen Q = p • z`, then `p ∣ Q.coeff 0`. -/
theorem dvd_coeff_zero_of_aeval_eq_prime_smul_of_minpoly_isEisensteinAt {B : PowerBasis K L}
(hp : Prime p) (hBint : IsIntegral R B.gen) {z : L} {Q : R[X]} (hQ : aeval B.gen Q = p • z)
(hzint : IsIntegral R z) (hei : (minpoly R B.gen).IsEisensteinAt 𝓟) : p ∣ Q.coeff 0 := by
-- First define some abbreviations.
letI := B.finite
let P := minpoly R B.gen
obtain ⟨n, hn⟩ := Nat.exists_eq_succ_of_ne_zero B.dim_pos.ne'
have finrank_K_L : FiniteDimensional.finrank K L = B.dim := B.finrank
have deg_K_P : (minpoly K B.gen).natDegree = B.dim := B.natDegree_minpoly
have deg_R_P : P.natDegree = B.dim := by
rw [← deg_K_P, minpoly.isIntegrallyClosed_eq_field_fractions' K hBint,
(minpoly.monic hBint).natDegree_map (algebraMap R K)]
choose! f hf using
hei.isWeaklyEisensteinAt.exists_mem_adjoin_mul_eq_pow_natDegree_le (minpoly.aeval R B.gen)
(minpoly.monic hBint)
simp only [(minpoly.monic hBint).natDegree_map, deg_R_P] at hf
-- The Eisenstein condition shows that `p` divides `Q.coeff 0`
-- if `p^n.succ` divides the following multiple of `Q.coeff 0^n.succ`:
suffices
p ^ n.succ ∣ Q.coeff 0 ^ n.succ * ((-1) ^ (n.succ * n) * (minpoly R B.gen).coeff 0 ^ n) by
have hndiv : ¬p ^ 2 ∣ (minpoly R B.gen).coeff 0 := fun h =>
hei.not_mem ((span_singleton_pow p 2).symm ▸ Ideal.mem_span_singleton.2 h)
refine @Prime.dvd_of_pow_dvd_pow_mul_pow_of_square_not_dvd R _ _ _ _ n hp (?_ : _ ∣ _) hndiv
convert (IsUnit.dvd_mul_right ⟨(-1) ^ (n.succ * n), rfl⟩).mpr this using 1
push_cast
ring_nf
rw [mul_comm _ 2, pow_mul, neg_one_sq, one_pow, mul_one]
-- We claim the quotient of `Q^n * _` by `p^n` is the following `r`:
have aux : ∀ i ∈ (range (Q.natDegree + 1)).erase 0, B.dim ≤ i + n := by
intro i hi
simp only [mem_range, mem_erase] at hi
rw [hn]
exact le_add_pred_of_pos _ hi.1
have hintsum :
IsIntegral R
(z * B.gen ^ n - ∑ x ∈ (range (Q.natDegree + 1)).erase 0, Q.coeff x • f (x + n)) := by
refine (hzint.mul (hBint.pow _)).sub (.sum _ fun i hi => .smul _ ?_)
exact adjoin_le_integralClosure hBint (hf _ (aux i hi)).1
obtain ⟨r, hr⟩ := isIntegral_iff.1 (isIntegral_norm K hintsum)
use r
-- Do the computation in `K` so we can work in terms of `z` instead of `r`.
apply IsFractionRing.injective R K
simp only [_root_.map_mul, _root_.map_pow, _root_.map_neg, _root_.map_one]
-- Both sides are actually norms:
calc
_ = norm K (Q.coeff 0 • B.gen ^ n) := ?_
_ = norm K (p • (z * B.gen ^ n) -
∑ x ∈ (range (Q.natDegree + 1)).erase 0, p • Q.coeff x • f (x + n)) :=
(congr_arg (norm K) (eq_sub_of_add_eq ?_))
_ = _ := ?_
· simp only [Algebra.smul_def, algebraMap_apply R K L, Algebra.norm_algebraMap, _root_.map_mul,
_root_.map_pow, finrank_K_L, PowerBasis.norm_gen_eq_coeff_zero_minpoly,
minpoly.isIntegrallyClosed_eq_field_fractions' K hBint, coeff_map, ← hn]
ring
swap
· simp_rw [← smul_sum, ← smul_sub, Algebra.smul_def p, algebraMap_apply R K L, _root_.map_mul,
Algebra.norm_algebraMap, finrank_K_L, hr, ← hn]
calc
_ = (Q.coeff 0 • ↑1 + ∑ x ∈ (range (Q.natDegree + 1)).erase 0, Q.coeff x • B.gen ^ x) *
B.gen ^ n := ?_
_ = (Q.coeff 0 • B.gen ^ 0 +
∑ x ∈ (range (Q.natDegree + 1)).erase 0, Q.coeff x • B.gen ^ x) * B.gen ^ n := by
rw [_root_.pow_zero]
_ = aeval B.gen Q * B.gen ^ n := ?_
_ = _ := by rw [hQ, Algebra.smul_mul_assoc]
· have : ∀ i ∈ (range (Q.natDegree + 1)).erase 0,
Q.coeff i • (B.gen ^ i * B.gen ^ n) = p • Q.coeff i • f (i + n) := by
intro i hi
rw [← pow_add, ← (hf _ (aux i hi)).2, ← Algebra.smul_def, smul_smul, mul_comm _ p, smul_smul]
simp only [add_mul, smul_mul_assoc, one_mul, sum_mul, sum_congr rfl this]
· rw [aeval_eq_sum_range,
Finset.add_sum_erase (range (Q.natDegree + 1)) fun i => Q.coeff i • B.gen ^ i]
simp
theorem mem_adjoin_of_dvd_coeff_of_dvd_aeval {A B : Type*} [CommSemiring A] [CommRing B]
[Algebra A B] [NoZeroSMulDivisors A B] {Q : A[X]} {p : A} {x z : B} (hp : p ≠ 0)
(hQ : ∀ i ∈ range (Q.natDegree + 1), p ∣ Q.coeff i) (hz : aeval x Q = p • z) :
z ∈ adjoin A ({x} : Set B) := by
choose! f hf using hQ
rw [aeval_eq_sum_range, sum_range] at hz
conv_lhs at hz =>
congr
next => skip
ext i
rw [hf i (mem_range.2 (Fin.is_lt i)), ← smul_smul]
rw [← smul_sum] at hz
rw [← smul_right_injective _ hp hz]
exact
Subalgebra.sum_mem _ fun _ _ =>
Subalgebra.smul_mem _ (Subalgebra.pow_mem _ (subset_adjoin (Set.mem_singleton _)) _) _
/-- Let `K` be the field of fraction of an integrally closed domain `R` and let `L` be a separable
extension of `K`, generated by an integral power basis `B` such that the minimal polynomial of
`B.gen` is Eisenstein at `p`. Given `z : L` integral over `R`, if `p • z ∈ adjoin R {B.gen}`, then
`z ∈ adjoin R {B.gen}`. -/
theorem mem_adjoin_of_smul_prime_smul_of_minpoly_isEisensteinAt {B : PowerBasis K L}
(hp : Prime p) (hBint : IsIntegral R B.gen) {z : L} (hzint : IsIntegral R z)
(hz : p • z ∈ adjoin R ({B.gen} : Set L)) (hei : (minpoly R B.gen).IsEisensteinAt 𝓟) :
z ∈ adjoin R ({B.gen} : Set L) := by
-- First define some abbreviations.
have hndiv : ¬p ^ 2 ∣ (minpoly R B.gen).coeff 0 := fun h =>
hei.not_mem ((span_singleton_pow p 2).symm ▸ Ideal.mem_span_singleton.2 h)
have := B.finite
set P := minpoly R B.gen with hP
obtain ⟨n, hn⟩ := Nat.exists_eq_succ_of_ne_zero B.dim_pos.ne'
haveI : NoZeroSMulDivisors R L := NoZeroSMulDivisors.trans R K L
let _ := P.map (algebraMap R L)
-- There is a polynomial `Q` such that `p • z = aeval B.gen Q`. We can assume that
-- `Q.degree < P.degree` and `Q ≠ 0`.
rw [adjoin_singleton_eq_range_aeval] at hz
obtain ⟨Q₁, hQ⟩ := hz
set Q := Q₁ %ₘ P with hQ₁
replace hQ : aeval B.gen Q = p • z := by
rw [← modByMonic_add_div Q₁ (minpoly.monic hBint)] at hQ
simpa using hQ
by_cases hQzero : Q = 0
· simp only [hQzero, Algebra.smul_def, zero_eq_mul, aeval_zero] at hQ
cases' hQ with H H₁
· have : Function.Injective (algebraMap R L) := by
rw [algebraMap_eq R K L]
exact (algebraMap K L).injective.comp (IsFractionRing.injective R K)
exfalso
exact hp.ne_zero ((injective_iff_map_eq_zero _).1 this _ H)
· rw [H₁]
exact Subalgebra.zero_mem _
-- It is enough to prove that all coefficients of `Q` are divisible by `p`, by induction.
-- The base case is `dvd_coeff_zero_of_aeval_eq_prime_smul_of_minpoly_isEisensteinAt`.
refine mem_adjoin_of_dvd_coeff_of_dvd_aeval hp.ne_zero (fun i => ?_) hQ
induction' i using Nat.case_strong_induction_on with j hind
· intro _
exact dvd_coeff_zero_of_aeval_eq_prime_smul_of_minpoly_isEisensteinAt hp hBint hQ hzint hei
· intro hj
convert hp.dvd_of_pow_dvd_pow_mul_pow_of_square_not_dvd (n := n) _ hndiv
-- Two technical results we will need about `P.natDegree` and `Q.natDegree`.
have H := degree_modByMonic_lt Q₁ (minpoly.monic hBint)
rw [← hQ₁, ← hP] at H
replace H := Nat.lt_iff_add_one_le.1
(lt_of_lt_of_le
(lt_of_le_of_lt (Nat.lt_iff_add_one_le.1 (Nat.lt_of_succ_lt_succ (mem_range.1 hj)))
(lt_succ_self _)) (Nat.lt_iff_add_one_le.1 ((natDegree_lt_natDegree_iff hQzero).2 H)))
have Hj : Q.natDegree + 1 = j + 1 + (Q.natDegree - j) := by
rw [← add_comm 1, ← add_comm 1, add_assoc, add_right_inj,
← Nat.add_sub_assoc (Nat.lt_of_succ_lt_succ (mem_range.1 hj)).le, add_comm,
Nat.add_sub_cancel]
-- By induction hypothesis we can find `g : ℕ → R` such that
-- `k ∈ range (j + 1) → Q.coeff k • B.gen ^ k = (algebraMap R L) p * g k • B.gen ^ k`-
choose! g hg using hind
replace hg : ∀ k ∈ range (j + 1), Q.coeff k • B.gen ^ k =
algebraMap R L p * g k • B.gen ^ k := by
intro k hk
rw [hg k (mem_range_succ_iff.1 hk)
(mem_range_succ_iff.2
(le_trans (mem_range_succ_iff.1 hk) (succ_le_iff.1 (mem_range_succ_iff.1 hj)).le)),
Algebra.smul_def, Algebra.smul_def, RingHom.map_mul, mul_assoc]
-- Since `minpoly R B.gen` is Eiseinstein, we can find `f : ℕ → L` such that
-- `(map (algebraMap R L) (minpoly R B.gen)).nat_degree ≤ i` implies `f i ∈ adjoin R {B.gen}`
-- and `(algebraMap R L) p * f i = B.gen ^ i`. We will also need `hf₁`, a reformulation of this
-- property.
choose! f hf using
IsWeaklyEisensteinAt.exists_mem_adjoin_mul_eq_pow_natDegree_le (minpoly.aeval R B.gen)
(minpoly.monic hBint) hei.isWeaklyEisensteinAt
have hf₁ : ∀ k ∈ (range (Q.natDegree - j)).erase 0,
Q.coeff (j + 1 + k) • B.gen ^ (j + 1 + k) * B.gen ^ (P.natDegree - (j + 2)) =
(algebraMap R L) p * Q.coeff (j + 1 + k) • f (k + P.natDegree - 1) := by
intro k hk
rw [smul_mul_assoc, ← pow_add, ← Nat.add_sub_assoc H, add_comm (j + 1) 1,
add_assoc (j + 1), add_comm _ (k + P.natDegree), Nat.add_sub_add_right,
← (hf (k + P.natDegree - 1) _).2, mul_smul_comm]
rw [(minpoly.monic hBint).natDegree_map, add_comm, Nat.add_sub_assoc, le_add_iff_nonneg_right]
· exact Nat.zero_le _
· refine one_le_iff_ne_zero.2 fun h => ?_
rw [h] at hk
simp at hk
-- The Eisenstein condition shows that `p` divides `Q.coeff j`
-- if `p^n.succ` divides the following multiple of `Q.coeff (succ j)^n.succ`:
suffices
p ^ n.succ ∣ Q.coeff (succ j) ^ n.succ *
(minpoly R B.gen).coeff 0 ^ (succ j + (P.natDegree - (j + 2))) by
convert this
rw [Nat.succ_eq_add_one, add_assoc, ← Nat.add_sub_assoc H, add_comm (j + 1),
Nat.add_sub_add_left, ← Nat.add_sub_assoc, Nat.add_sub_add_left, hP, ←
(minpoly.monic hBint).natDegree_map (algebraMap R K), ←
minpoly.isIntegrallyClosed_eq_field_fractions' K hBint, natDegree_minpoly, hn, Nat.sub_one,
Nat.pred_succ]
omega
-- Using `hQ : aeval B.gen Q = p • z`, we write `p • z` as a sum of terms of degree less than
-- `j+1`, that are multiples of `p` by induction, and terms of degree at least `j+1`.
rw [aeval_eq_sum_range, Hj, range_add, sum_union (disjoint_range_addLeftEmbedding _ _),
sum_congr rfl hg, add_comm] at hQ
-- We multiply this equality by `B.gen ^ (P.natDegree-(j+2))`, so we can use `hf₁` on the terms
-- we didn't know were multiples of `p`, and we take the norm on both sides.
replace hQ := congr_arg (fun x => x * B.gen ^ (P.natDegree - (j + 2))) hQ
simp_rw [sum_map, addLeftEmbedding_apply, add_mul, sum_mul, mul_assoc] at hQ
rw [← insert_erase
(mem_range.2 (tsub_pos_iff_lt.2 <| Nat.lt_of_succ_lt_succ <| mem_range.1 hj)),
sum_insert (not_mem_erase 0 _), add_zero, sum_congr rfl hf₁, ← mul_sum, ← mul_sum, add_assoc,
← mul_add, smul_mul_assoc, ← pow_add, Algebra.smul_def] at hQ
replace hQ := congr_arg (norm K) (eq_sub_of_add_eq hQ)
-- We obtain an equality of elements of `K`, but everything is integral, so we can move to `R`
-- and simplify `hQ`.
have hintsum : IsIntegral R (z * B.gen ^ (P.natDegree - (j + 2)) -
(∑ x ∈ (range (Q.natDegree - j)).erase 0,
Q.coeff (j + 1 + x) • f (x + P.natDegree - 1) +
∑ x ∈ range (j + 1), g x • B.gen ^ x * B.gen ^ (P.natDegree - (j + 2)))) := by
refine (hzint.mul (hBint.pow _)).sub
(.add (.sum _ fun k hk => .smul _ ?_)
(.sum _ fun k _ => .mul (.smul _ (.pow hBint _)) (hBint.pow _)))
refine adjoin_le_integralClosure hBint (hf _ ?_).1
rw [(minpoly.monic hBint).natDegree_map (algebraMap R L)]
rw [add_comm, Nat.add_sub_assoc, le_add_iff_nonneg_right]
· exact _root_.zero_le _
· refine one_le_iff_ne_zero.2 fun h => ?_
rw [h] at hk
simp at hk
obtain ⟨r, hr⟩ := isIntegral_iff.1 (isIntegral_norm K hintsum)
rw [Algebra.smul_def, mul_assoc, ← mul_sub, _root_.map_mul, algebraMap_apply R K L, map_pow,
Algebra.norm_algebraMap, _root_.map_mul, algebraMap_apply R K L, Algebra.norm_algebraMap,
finrank B, ← hr, PowerBasis.norm_gen_eq_coeff_zero_minpoly,
minpoly.isIntegrallyClosed_eq_field_fractions' K hBint, coeff_map,
show (-1 : K) = algebraMap R K (-1) by simp, ← map_pow, ← map_pow, ← _root_.map_mul, ←
map_pow, ← _root_.map_mul, ← map_pow, ← _root_.map_mul] at hQ
-- We can now finish the proof.
have hppdiv : p ^ B.dim ∣ p ^ B.dim * r := dvd_mul_of_dvd_left dvd_rfl _
rwa [← IsFractionRing.injective R K hQ, mul_comm, ← Units.coe_neg_one, mul_pow, ←
Units.val_pow_eq_pow_val, ← Units.val_pow_eq_pow_val, mul_assoc,
Units.dvd_mul_left, mul_comm, ← Nat.succ_eq_add_one, hn] at hppdiv
/-- Let `K` be the field of fraction of an integrally closed domain `R` and let `L` be a separable
extension of `K`, generated by an integral power basis `B` such that the minimal polynomial of
`B.gen` is Eisenstein at `p`. Given `z : L` integral over `R`, if `p ^ n • z ∈ adjoin R {B.gen}`,
then `z ∈ adjoin R {B.gen}`. Together with `Algebra.discr_mul_isIntegral_mem_adjoin` this result
often allows to compute the ring of integers of `L`. -/
theorem mem_adjoin_of_smul_prime_pow_smul_of_minpoly_isEisensteinAt {B : PowerBasis K L}
(hp : Prime p) (hBint : IsIntegral R B.gen) {n : ℕ} {z : L} (hzint : IsIntegral R z)
(hz : p ^ n • z ∈ adjoin R ({B.gen} : Set L)) (hei : (minpoly R B.gen).IsEisensteinAt 𝓟) :
z ∈ adjoin R ({B.gen} : Set L) := by
induction' n with n hn
· simpa using hz
· rw [_root_.pow_succ', mul_smul] at hz
exact
hn (mem_adjoin_of_smul_prime_smul_of_minpoly_isEisensteinAt hp hBint (hzint.smul _) hz hei)
end IsIntegral
|
RingTheory\Polynomial\Hermite\Basic.lean | /-
Copyright (c) 2023 Luke Mantle. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Luke Mantle
-/
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Algebra.Polynomial.Derivative
import Mathlib.Data.Nat.Factorial.DoubleFactorial
/-!
# Hermite polynomials
This file defines `Polynomial.hermite n`, the `n`th probabilists' Hermite polynomial.
## Main definitions
* `Polynomial.hermite n`: the `n`th probabilists' Hermite polynomial,
defined recursively as a `Polynomial ℤ`
## Results
* `Polynomial.hermite_succ`: the recursion `hermite (n+1) = (x - d/dx) (hermite n)`
* `Polynomial.coeff_hermite_explicit`: a closed formula for (nonvanishing) coefficients in terms
of binomial coefficients and double factorials.
* `Polynomial.coeff_hermite_of_odd_add`: for `n`,`k` where `n+k` is odd, `(hermite n).coeff k` is
zero.
* `Polynomial.coeff_hermite_of_even_add`: a closed formula for `(hermite n).coeff k` when `n+k` is
even, equivalent to `Polynomial.coeff_hermite_explicit`.
* `Polynomial.monic_hermite`: for all `n`, `hermite n` is monic.
* `Polynomial.degree_hermite`: for all `n`, `hermite n` has degree `n`.
## References
* [Hermite Polynomials](https://en.wikipedia.org/wiki/Hermite_polynomials)
-/
noncomputable section
open Polynomial
namespace Polynomial
/-- the probabilists' Hermite polynomials. -/
noncomputable def hermite : ℕ → Polynomial ℤ
| 0 => 1
| n + 1 => X * hermite n - derivative (hermite n)
/-- The recursion `hermite (n+1) = (x - d/dx) (hermite n)` -/
@[simp]
theorem hermite_succ (n : ℕ) : hermite (n + 1) = X * hermite n - derivative (hermite n) := by
rw [hermite]
theorem hermite_eq_iterate (n : ℕ) : hermite n = (fun p => X * p - derivative p)^[n] 1 := by
induction' n with n ih
· rfl
· rw [Function.iterate_succ_apply', ← ih, hermite_succ]
@[simp]
theorem hermite_zero : hermite 0 = C 1 :=
rfl
-- Porting note (#10618): There was initially @[simp] on this line but it was removed
-- because simp can prove this theorem
theorem hermite_one : hermite 1 = X := by
rw [hermite_succ, hermite_zero]
simp only [map_one, mul_one, derivative_one, sub_zero]
/-! ### Lemmas about `Polynomial.coeff` -/
section coeff
theorem coeff_hermite_succ_zero (n : ℕ) : coeff (hermite (n + 1)) 0 = -coeff (hermite n) 1 := by
simp [coeff_derivative]
theorem coeff_hermite_succ_succ (n k : ℕ) : coeff (hermite (n + 1)) (k + 1) =
coeff (hermite n) k - (k + 2) * coeff (hermite n) (k + 2) := by
rw [hermite_succ, coeff_sub, coeff_X_mul, coeff_derivative, mul_comm]
norm_cast
theorem coeff_hermite_of_lt {n k : ℕ} (hnk : n < k) : coeff (hermite n) k = 0 := by
obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_lt hnk
clear hnk
induction' n with n ih generalizing k
· apply coeff_C
· have : n + k + 1 + 2 = n + (k + 2) + 1 := by ring
rw [coeff_hermite_succ_succ, add_right_comm, this, ih k, ih (k + 2),
mul_zero, sub_zero]
@[simp]
theorem coeff_hermite_self (n : ℕ) : coeff (hermite n) n = 1 := by
induction' n with n ih
· apply coeff_C
· rw [coeff_hermite_succ_succ, ih, coeff_hermite_of_lt, mul_zero, sub_zero]
simp
@[simp]
theorem degree_hermite (n : ℕ) : (hermite n).degree = n := by
rw [degree_eq_of_le_of_coeff_ne_zero]
· simp_rw [degree_le_iff_coeff_zero, Nat.cast_lt]
rintro m hnm
exact coeff_hermite_of_lt hnm
· simp [coeff_hermite_self n]
@[simp]
theorem natDegree_hermite {n : ℕ} : (hermite n).natDegree = n :=
natDegree_eq_of_degree_eq_some (degree_hermite n)
@[simp]
theorem leadingCoeff_hermite (n : ℕ) : (hermite n).leadingCoeff = 1 := by
rw [← coeff_natDegree, natDegree_hermite, coeff_hermite_self]
theorem hermite_monic (n : ℕ) : (hermite n).Monic :=
leadingCoeff_hermite n
theorem coeff_hermite_of_odd_add {n k : ℕ} (hnk : Odd (n + k)) : coeff (hermite n) k = 0 := by
induction' n with n ih generalizing k
· rw [zero_add k] at hnk
exact coeff_hermite_of_lt hnk.pos
· cases' k with k
· rw [Nat.succ_add_eq_add_succ] at hnk
rw [coeff_hermite_succ_zero, ih hnk, neg_zero]
· rw [coeff_hermite_succ_succ, ih, ih, mul_zero, sub_zero]
· rwa [Nat.succ_add_eq_add_succ] at hnk
· rw [(by rw [Nat.succ_add, Nat.add_succ] : n.succ + k.succ = n + k + 2)] at hnk
exact (Nat.odd_add.mp hnk).mpr even_two
end coeff
section CoeffExplicit
open scoped Nat
/-- Because of `coeff_hermite_of_odd_add`, every nonzero coefficient is described as follows. -/
theorem coeff_hermite_explicit :
∀ n k : ℕ, coeff (hermite (2 * n + k)) k = (-1) ^ n * (2 * n - 1)‼ * Nat.choose (2 * n + k) k
| 0, _ => by simp
| n + 1, 0 => by
convert coeff_hermite_succ_zero (2 * n + 1) using 1
-- Porting note: ring_nf did not solve the goal on line 165
rw [coeff_hermite_explicit n 1, (by rw [Nat.left_distrib, mul_one, Nat.add_one_sub_one] :
2 * (n + 1) - 1 = 2 * n + 1), Nat.doubleFactorial_add_one, Nat.choose_zero_right,
Nat.choose_one_right, pow_succ]
push_cast
ring
| n + 1, k + 1 => by
let hermite_explicit : ℕ → ℕ → ℤ := fun n k =>
(-1) ^ n * (2 * n - 1)‼ * Nat.choose (2 * n + k) k
have hermite_explicit_recur :
∀ n k : ℕ,
hermite_explicit (n + 1) (k + 1) =
hermite_explicit (n + 1) k - (k + 2) * hermite_explicit n (k + 2) := by
intro n k
simp only [hermite_explicit]
-- Factor out (-1)'s.
rw [mul_comm (↑k + _ : ℤ), sub_eq_add_neg]
nth_rw 3 [neg_eq_neg_one_mul]
simp only [mul_assoc, ← mul_add, pow_succ']
congr 2
-- Factor out double factorials.
norm_cast
-- Porting note: ring_nf did not solve the goal on line 186
rw [(by rw [Nat.left_distrib, mul_one, Nat.add_one_sub_one] : 2 * (n + 1) - 1 = 2 * n + 1),
Nat.doubleFactorial_add_one, mul_comm (2 * n + 1)]
simp only [mul_assoc, ← mul_add]
congr 1
-- Match up binomial coefficients using `Nat.choose_succ_right_eq`.
rw [(by ring : 2 * (n + 1) + (k + 1) = 2 * n + 1 + (k + 1) + 1),
(by ring : 2 * (n + 1) + k = 2 * n + 1 + (k + 1)),
(by ring : 2 * n + (k + 2) = 2 * n + 1 + (k + 1))]
rw [Nat.choose, Nat.choose_succ_right_eq (2 * n + 1 + (k + 1)) (k + 1), Nat.add_sub_cancel]
ring
change _ = hermite_explicit _ _
rw [← add_assoc, coeff_hermite_succ_succ, hermite_explicit_recur]
congr
· rw [coeff_hermite_explicit (n + 1) k]
· rw [(by ring : 2 * (n + 1) + k = 2 * n + (k + 2)), coeff_hermite_explicit n (k + 2)]
theorem coeff_hermite_of_even_add {n k : ℕ} (hnk : Even (n + k)) :
coeff (hermite n) k = (-1) ^ ((n - k) / 2) * (n - k - 1)‼ * Nat.choose n k := by
rcases le_or_lt k n with h_le | h_lt
· rw [Nat.even_add, ← Nat.even_sub h_le] at hnk
obtain ⟨m, hm⟩ := hnk
-- Porting note: linarith failed to find a contradiction by itself
rw [(by omega : n = 2 * m + k),
Nat.add_sub_cancel, Nat.mul_div_cancel_left _ (Nat.succ_pos 1), coeff_hermite_explicit]
· simp [Nat.choose_eq_zero_of_lt h_lt, coeff_hermite_of_lt h_lt]
theorem coeff_hermite (n k : ℕ) :
coeff (hermite n) k =
if Even (n + k) then (-1 : ℤ) ^ ((n - k) / 2) * (n - k - 1)‼ * Nat.choose n k else 0 := by
split_ifs with h
· exact coeff_hermite_of_even_add h
· exact coeff_hermite_of_odd_add (Nat.odd_iff_not_even.mpr h)
end CoeffExplicit
end Polynomial
|
RingTheory\Polynomial\Hermite\Gaussian.lean | /-
Copyright (c) 2023 Luke Mantle. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Luke Mantle, Jake Levinson
-/
import Mathlib.RingTheory.Polynomial.Hermite.Basic
import Mathlib.Analysis.Calculus.Deriv.Add
import Mathlib.Analysis.Calculus.Deriv.Polynomial
import Mathlib.Analysis.SpecialFunctions.Exp
import Mathlib.Analysis.SpecialFunctions.ExpDeriv
/-!
# Hermite polynomials and Gaussians
This file shows that the Hermite polynomial `hermite n` is (up to sign) the
polynomial factor occurring in the `n`th derivative of a gaussian.
## Results
* `Polynomial.deriv_gaussian_eq_hermite_mul_gaussian`:
The Hermite polynomial is (up to sign) the polynomial factor occurring in the
`n`th derivative of a gaussian.
## References
* [Hermite Polynomials](https://en.wikipedia.org/wiki/Hermite_polynomials)
-/
noncomputable section
open Polynomial
namespace Polynomial
/-- `hermite n` is (up to sign) the factor appearing in `deriv^[n]` of a gaussian -/
theorem deriv_gaussian_eq_hermite_mul_gaussian (n : ℕ) (x : ℝ) :
deriv^[n] (fun y => Real.exp (-(y ^ 2 / 2))) x =
(-1 : ℝ) ^ n * aeval x (hermite n) * Real.exp (-(x ^ 2 / 2)) := by
rw [mul_assoc]
induction' n with n ih generalizing x
· rw [Function.iterate_zero_apply, pow_zero, one_mul, hermite_zero, C_1, map_one, one_mul]
· replace ih : deriv^[n] _ = _ := _root_.funext ih
have deriv_gaussian :
deriv (fun y => Real.exp (-(y ^ 2 / 2))) x = -x * Real.exp (-(x ^ 2 / 2)) := by
-- porting note (#10745): was `simp [mul_comm, ← neg_mul]`
rw [deriv_exp (by simp)]; simp; ring
rw [Function.iterate_succ_apply', ih, deriv_const_mul_field, deriv_mul, pow_succ (-1 : ℝ),
deriv_gaussian, hermite_succ, map_sub, map_mul, aeval_X, Polynomial.deriv_aeval]
· ring
· apply Polynomial.differentiable_aeval
· apply DifferentiableAt.exp; simp -- Porting note: was just `simp`
theorem hermite_eq_deriv_gaussian (n : ℕ) (x : ℝ) : aeval x (hermite n) =
(-1 : ℝ) ^ n * deriv^[n] (fun y => Real.exp (-(y ^ 2 / 2))) x / Real.exp (-(x ^ 2 / 2)) := by
rw [deriv_gaussian_eq_hermite_mul_gaussian]
field_simp [Real.exp_ne_zero]
rw [← @smul_eq_mul ℝ _ ((-1) ^ n), ← inv_smul_eq_iff₀, mul_assoc, smul_eq_mul, ← inv_pow, ←
neg_inv, inv_one]
exact pow_ne_zero _ (by norm_num)
theorem hermite_eq_deriv_gaussian' (n : ℕ) (x : ℝ) : aeval x (hermite n) =
(-1 : ℝ) ^ n * deriv^[n] (fun y => Real.exp (-(y ^ 2 / 2))) x * Real.exp (x ^ 2 / 2) := by
rw [hermite_eq_deriv_gaussian, Real.exp_neg]
field_simp [Real.exp_ne_zero]
end Polynomial
|
RingTheory\PowerSeries\Basic.lean | /-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Kenny Lau
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Basic
import Mathlib.RingTheory.Ideal.Maps
import Mathlib.RingTheory.MvPowerSeries.Basic
import Mathlib.Tactic.MoveAdd
/-!
# Formal power series (in one variable)
This file defines (univariate) formal power series
and develops the basic properties of these objects.
A formal power series is to a polynomial like an infinite sum is to a finite sum.
Formal power series in one variable are defined from multivariate
power series as `PowerSeries R := MvPowerSeries Unit R`.
The file sets up the (semi)ring structure on univariate power series.
We provide the natural inclusion from polynomials to formal power series.
Additional results can be found in:
* `Mathlib.RingTheory.PowerSeries.Trunc`, truncation of power series;
* `Mathlib.RingTheory.PowerSeries.Inverse`, about inverses of power series,
and the fact that power series over a local ring form a local ring;
* `Mathlib.RingTheory.PowerSeries.Order`, the order of a power series at 0,
and application to the fact that power series over an integral domain
form an integral domain.
## Implementation notes
Because of its definition,
`PowerSeries R := MvPowerSeries Unit R`.
a lot of proofs and properties from the multivariate case
can be ported to the single variable case.
However, it means that formal power series are indexed by `Unit →₀ ℕ`,
which is of course canonically isomorphic to `ℕ`.
We then build some glue to treat formal power series as if they were indexed by `ℕ`.
Occasionally this leads to proofs that are uglier than expected.
-/
noncomputable section
open Finset (antidiagonal mem_antidiagonal)
/-- Formal power series over a coefficient type `R` -/
abbrev PowerSeries (R : Type*) :=
MvPowerSeries Unit R
namespace PowerSeries
open Finsupp (single)
variable {R : Type*}
section
-- Porting note: not available in Lean 4
-- local reducible PowerSeries
/--
`R⟦X⟧` is notation for `PowerSeries R`,
the semiring of formal power series in one variable over a semiring `R`.
-/
scoped notation:9000 R "⟦X⟧" => PowerSeries R
instance [Inhabited R] : Inhabited R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [Zero R] : Zero R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [AddMonoid R] : AddMonoid R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [AddGroup R] : AddGroup R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [AddCommMonoid R] : AddCommMonoid R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [AddCommGroup R] : AddCommGroup R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [Semiring R] : Semiring R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [CommSemiring R] : CommSemiring R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [Ring R] : Ring R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [CommRing R] : CommRing R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance [Nontrivial R] : Nontrivial R⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance {A} [Semiring R] [AddCommMonoid A] [Module R A] : Module R A⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
instance {A S} [Semiring R] [Semiring S] [AddCommMonoid A] [Module R A] [Module S A] [SMul R S]
[IsScalarTower R S A] : IsScalarTower R S A⟦X⟧ :=
Pi.isScalarTower
instance {A} [Semiring A] [CommSemiring R] [Algebra R A] : Algebra R A⟦X⟧ := by
dsimp only [PowerSeries]
infer_instance
end
section Semiring
variable (R) [Semiring R]
/-- The `n`th coefficient of a formal power series. -/
def coeff (n : ℕ) : R⟦X⟧ →ₗ[R] R :=
MvPowerSeries.coeff R (single () n)
/-- The `n`th monomial with coefficient `a` as formal power series. -/
def monomial (n : ℕ) : R →ₗ[R] R⟦X⟧ :=
MvPowerSeries.monomial R (single () n)
variable {R}
theorem coeff_def {s : Unit →₀ ℕ} {n : ℕ} (h : s () = n) : coeff R n = MvPowerSeries.coeff R s := by
erw [coeff, ← h, ← Finsupp.unique_single s]
/-- Two formal power series are equal if all their coefficients are equal. -/
@[ext]
theorem ext {φ ψ : R⟦X⟧} (h : ∀ n, coeff R n φ = coeff R n ψ) : φ = ψ :=
MvPowerSeries.ext fun n => by
rw [← coeff_def]
· apply h
rfl
/-- Two formal power series are equal if all their coefficients are equal. -/
add_decl_doc PowerSeries.ext_iff
instance [Subsingleton R] : Subsingleton R⟦X⟧ := by
simp only [subsingleton_iff, PowerSeries.ext_iff]
subsingleton
/-- Constructor for formal power series. -/
def mk {R} (f : ℕ → R) : R⟦X⟧ := fun s => f (s ())
@[simp]
theorem coeff_mk (n : ℕ) (f : ℕ → R) : coeff R n (mk f) = f n :=
congr_arg f Finsupp.single_eq_same
theorem coeff_monomial (m n : ℕ) (a : R) : coeff R m (monomial R n a) = if m = n then a else 0 :=
calc
coeff R m (monomial R n a) = _ := MvPowerSeries.coeff_monomial _ _ _
_ = if m = n then a else 0 := by simp only [Finsupp.unique_single_eq_iff]
theorem monomial_eq_mk (n : ℕ) (a : R) : monomial R n a = mk fun m => if m = n then a else 0 :=
ext fun m => by rw [coeff_monomial, coeff_mk]
@[simp]
theorem coeff_monomial_same (n : ℕ) (a : R) : coeff R n (monomial R n a) = a :=
MvPowerSeries.coeff_monomial_same _ _
@[simp]
theorem coeff_comp_monomial (n : ℕ) : (coeff R n).comp (monomial R n) = LinearMap.id :=
LinearMap.ext <| coeff_monomial_same n
variable (R)
/-- The constant coefficient of a formal power series. -/
def constantCoeff : R⟦X⟧ →+* R :=
MvPowerSeries.constantCoeff Unit R
/-- The constant formal power series. -/
def C : R →+* R⟦X⟧ :=
MvPowerSeries.C Unit R
variable {R}
/-- The variable of the formal power series ring. -/
def X : R⟦X⟧ :=
MvPowerSeries.X ()
theorem commute_X (φ : R⟦X⟧) : Commute φ X :=
MvPowerSeries.commute_X _ _
@[simp]
theorem coeff_zero_eq_constantCoeff : ⇑(coeff R 0) = constantCoeff R := by
rw [coeff, Finsupp.single_zero]
rfl
theorem coeff_zero_eq_constantCoeff_apply (φ : R⟦X⟧) : coeff R 0 φ = constantCoeff R φ := by
rw [coeff_zero_eq_constantCoeff]
@[simp]
theorem monomial_zero_eq_C : ⇑(monomial R 0) = C R := by
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [monomial, Finsupp.single_zero, MvPowerSeries.monomial_zero_eq_C]
theorem monomial_zero_eq_C_apply (a : R) : monomial R 0 a = C R a := by simp
theorem coeff_C (n : ℕ) (a : R) : coeff R n (C R a : R⟦X⟧) = if n = 0 then a else 0 := by
rw [← monomial_zero_eq_C_apply, coeff_monomial]
@[simp]
theorem coeff_zero_C (a : R) : coeff R 0 (C R a) = a := by
rw [coeff_C, if_pos rfl]
theorem coeff_ne_zero_C {a : R} {n : ℕ} (h : n ≠ 0) : coeff R n (C R a) = 0 := by
rw [coeff_C, if_neg h]
@[simp]
theorem coeff_succ_C {a : R} {n : ℕ} : coeff R (n + 1) (C R a) = 0 :=
coeff_ne_zero_C n.succ_ne_zero
theorem C_injective : Function.Injective (C R) := by
intro a b H
simp_rw [PowerSeries.ext_iff] at H
simpa only [coeff_zero_C] using H 0
protected theorem subsingleton_iff : Subsingleton R⟦X⟧ ↔ Subsingleton R := by
refine ⟨fun h ↦ ?_, fun _ ↦ inferInstance⟩
rw [subsingleton_iff] at h ⊢
exact fun a b ↦ C_injective (h (C R a) (C R b))
theorem X_eq : (X : R⟦X⟧) = monomial R 1 1 :=
rfl
theorem coeff_X (n : ℕ) : coeff R n (X : R⟦X⟧) = if n = 1 then 1 else 0 := by
rw [X_eq, coeff_monomial]
@[simp]
theorem coeff_zero_X : coeff R 0 (X : R⟦X⟧) = 0 := by
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [coeff, Finsupp.single_zero, X, MvPowerSeries.coeff_zero_X]
@[simp]
theorem coeff_one_X : coeff R 1 (X : R⟦X⟧) = 1 := by rw [coeff_X, if_pos rfl]
@[simp]
theorem X_ne_zero [Nontrivial R] : (X : R⟦X⟧) ≠ 0 := fun H => by
simpa only [coeff_one_X, one_ne_zero, map_zero] using congr_arg (coeff R 1) H
theorem X_pow_eq (n : ℕ) : (X : R⟦X⟧) ^ n = monomial R n 1 :=
MvPowerSeries.X_pow_eq _ n
theorem coeff_X_pow (m n : ℕ) : coeff R m ((X : R⟦X⟧) ^ n) = if m = n then 1 else 0 := by
rw [X_pow_eq, coeff_monomial]
@[simp]
theorem coeff_X_pow_self (n : ℕ) : coeff R n ((X : R⟦X⟧) ^ n) = 1 := by
rw [coeff_X_pow, if_pos rfl]
@[simp]
theorem coeff_one (n : ℕ) : coeff R n (1 : R⟦X⟧) = if n = 0 then 1 else 0 :=
coeff_C n 1
theorem coeff_zero_one : coeff R 0 (1 : R⟦X⟧) = 1 :=
coeff_zero_C 1
theorem coeff_mul (n : ℕ) (φ ψ : R⟦X⟧) :
coeff R n (φ * ψ) = ∑ p ∈ antidiagonal n, coeff R p.1 φ * coeff R p.2 ψ := by
-- `rw` can't see that `PowerSeries = MvPowerSeries Unit`, so use `.trans`
refine (MvPowerSeries.coeff_mul _ φ ψ).trans ?_
rw [Finsupp.antidiagonal_single, Finset.sum_map]
rfl
@[simp]
theorem coeff_mul_C (n : ℕ) (φ : R⟦X⟧) (a : R) : coeff R n (φ * C R a) = coeff R n φ * a :=
MvPowerSeries.coeff_mul_C _ φ a
@[simp]
theorem coeff_C_mul (n : ℕ) (φ : R⟦X⟧) (a : R) : coeff R n (C R a * φ) = a * coeff R n φ :=
MvPowerSeries.coeff_C_mul _ φ a
@[simp]
theorem coeff_smul {S : Type*} [Semiring S] [Module R S] (n : ℕ) (φ : PowerSeries S) (a : R) :
coeff S n (a • φ) = a • coeff S n φ :=
rfl
@[simp]
theorem constantCoeff_smul {S : Type*} [Semiring S] [Module R S] (φ : PowerSeries S) (a : R) :
constantCoeff S (a • φ) = a • constantCoeff S φ :=
rfl
theorem smul_eq_C_mul (f : R⟦X⟧) (a : R) : a • f = C R a * f := by
ext
simp
@[simp]
theorem coeff_succ_mul_X (n : ℕ) (φ : R⟦X⟧) : coeff R (n + 1) (φ * X) = coeff R n φ := by
simp only [coeff, Finsupp.single_add]
convert φ.coeff_add_mul_monomial (single () n) (single () 1) _
rw [mul_one]
@[simp]
theorem coeff_succ_X_mul (n : ℕ) (φ : R⟦X⟧) : coeff R (n + 1) (X * φ) = coeff R n φ := by
simp only [coeff, Finsupp.single_add, add_comm n 1]
convert φ.coeff_add_monomial_mul (single () 1) (single () n) _
rw [one_mul]
@[simp]
theorem constantCoeff_C (a : R) : constantCoeff R (C R a) = a :=
rfl
@[simp]
theorem constantCoeff_comp_C : (constantCoeff R).comp (C R) = RingHom.id R :=
rfl
-- Porting note (#10618): simp can prove this.
-- @[simp]
theorem constantCoeff_zero : constantCoeff R 0 = 0 :=
rfl
-- Porting note (#10618): simp can prove this.
-- @[simp]
theorem constantCoeff_one : constantCoeff R 1 = 1 :=
rfl
@[simp]
theorem constantCoeff_X : constantCoeff R X = 0 :=
MvPowerSeries.coeff_zero_X _
@[simp]
theorem constantCoeff_mk {f : ℕ → R} : constantCoeff R (mk f) = f 0 := rfl
theorem coeff_zero_mul_X (φ : R⟦X⟧) : coeff R 0 (φ * X) = 0 := by simp
theorem coeff_zero_X_mul (φ : R⟦X⟧) : coeff R 0 (X * φ) = 0 := by simp
theorem constantCoeff_surj : Function.Surjective (constantCoeff R) :=
fun r => ⟨(C R) r, constantCoeff_C r⟩
-- The following section duplicates the API of `Data.Polynomial.Coeff` and should attempt to keep
-- up to date with that
section
theorem coeff_C_mul_X_pow (x : R) (k n : ℕ) :
coeff R n (C R x * X ^ k : R⟦X⟧) = if n = k then x else 0 := by
simp [X_pow_eq, coeff_monomial]
@[simp]
theorem coeff_mul_X_pow (p : R⟦X⟧) (n d : ℕ) :
coeff R (d + n) (p * X ^ n) = coeff R d p := by
rw [coeff_mul, Finset.sum_eq_single (d, n), coeff_X_pow, if_pos rfl, mul_one]
· rintro ⟨i, j⟩ h1 h2
rw [coeff_X_pow, if_neg, mul_zero]
rintro rfl
apply h2
rw [mem_antidiagonal, add_right_cancel_iff] at h1
subst h1
rfl
· exact fun h1 => (h1 (mem_antidiagonal.2 rfl)).elim
@[simp]
theorem coeff_X_pow_mul (p : R⟦X⟧) (n d : ℕ) :
coeff R (d + n) (X ^ n * p) = coeff R d p := by
rw [coeff_mul, Finset.sum_eq_single (n, d), coeff_X_pow, if_pos rfl, one_mul]
· rintro ⟨i, j⟩ h1 h2
rw [coeff_X_pow, if_neg, zero_mul]
rintro rfl
apply h2
rw [mem_antidiagonal, add_comm, add_right_cancel_iff] at h1
subst h1
rfl
· rw [add_comm]
exact fun h1 => (h1 (mem_antidiagonal.2 rfl)).elim
theorem coeff_mul_X_pow' (p : R⟦X⟧) (n d : ℕ) :
coeff R d (p * X ^ n) = ite (n ≤ d) (coeff R (d - n) p) 0 := by
split_ifs with h
· rw [← tsub_add_cancel_of_le h, coeff_mul_X_pow, add_tsub_cancel_right]
· refine (coeff_mul _ _ _).trans (Finset.sum_eq_zero fun x hx => ?_)
rw [coeff_X_pow, if_neg, mul_zero]
exact ((le_of_add_le_right (mem_antidiagonal.mp hx).le).trans_lt <| not_le.mp h).ne
theorem coeff_X_pow_mul' (p : R⟦X⟧) (n d : ℕ) :
coeff R d (X ^ n * p) = ite (n ≤ d) (coeff R (d - n) p) 0 := by
split_ifs with h
· rw [← tsub_add_cancel_of_le h, coeff_X_pow_mul]
simp
· refine (coeff_mul _ _ _).trans (Finset.sum_eq_zero fun x hx => ?_)
rw [coeff_X_pow, if_neg, zero_mul]
have := mem_antidiagonal.mp hx
rw [add_comm] at this
exact ((le_of_add_le_right this.le).trans_lt <| not_le.mp h).ne
end
/-- If a formal power series is invertible, then so is its constant coefficient. -/
theorem isUnit_constantCoeff (φ : R⟦X⟧) (h : IsUnit φ) : IsUnit (constantCoeff R φ) :=
MvPowerSeries.isUnit_constantCoeff φ h
/-- Split off the constant coefficient. -/
theorem eq_shift_mul_X_add_const (φ : R⟦X⟧) :
φ = (mk fun p => coeff R (p + 1) φ) * X + C R (constantCoeff R φ) := by
ext (_ | n)
· simp only [Nat.zero_eq, coeff_zero_eq_constantCoeff, map_add, map_mul, constantCoeff_X,
mul_zero, coeff_zero_C, zero_add]
· simp only [coeff_succ_mul_X, coeff_mk, LinearMap.map_add, coeff_C, n.succ_ne_zero, sub_zero,
if_false, add_zero]
/-- Split off the constant coefficient. -/
theorem eq_X_mul_shift_add_const (φ : R⟦X⟧) :
φ = (X * mk fun p => coeff R (p + 1) φ) + C R (constantCoeff R φ) := by
ext (_ | n)
· simp only [Nat.zero_eq, coeff_zero_eq_constantCoeff, map_add, map_mul, constantCoeff_X,
zero_mul, coeff_zero_C, zero_add]
· simp only [coeff_succ_X_mul, coeff_mk, LinearMap.map_add, coeff_C, n.succ_ne_zero, sub_zero,
if_false, add_zero]
section Map
variable {S : Type*} {T : Type*} [Semiring S] [Semiring T]
variable (f : R →+* S) (g : S →+* T)
/-- The map between formal power series induced by a map on the coefficients. -/
def map : R⟦X⟧ →+* S⟦X⟧ :=
MvPowerSeries.map _ f
@[simp]
theorem map_id : (map (RingHom.id R) : R⟦X⟧ → R⟦X⟧) = id :=
rfl
theorem map_comp : map (g.comp f) = (map g).comp (map f) :=
rfl
@[simp]
theorem coeff_map (n : ℕ) (φ : R⟦X⟧) : coeff S n (map f φ) = f (coeff R n φ) :=
rfl
@[simp]
theorem map_C (r : R) : map f (C _ r) = C _ (f r) := by
ext
simp [coeff_C, apply_ite f]
@[simp]
theorem map_X : map f X = X := by
ext
simp [coeff_X, apply_ite f]
end Map
theorem X_pow_dvd_iff {n : ℕ} {φ : R⟦X⟧} :
(X : R⟦X⟧) ^ n ∣ φ ↔ ∀ m, m < n → coeff R m φ = 0 := by
convert@MvPowerSeries.X_pow_dvd_iff Unit R _ () n φ
constructor <;> intro h m hm
· rw [Finsupp.unique_single m]
convert h _ hm
· apply h
simpa only [Finsupp.single_eq_same] using hm
theorem X_dvd_iff {φ : R⟦X⟧} : (X : R⟦X⟧) ∣ φ ↔ constantCoeff R φ = 0 := by
rw [← pow_one (X : R⟦X⟧), X_pow_dvd_iff, ← coeff_zero_eq_constantCoeff_apply]
constructor <;> intro h
· exact h 0 zero_lt_one
· intro m hm
rwa [Nat.eq_zero_of_le_zero (Nat.le_of_succ_le_succ hm)]
end Semiring
section CommSemiring
variable [CommSemiring R]
open Finset Nat
/-- The ring homomorphism taking a power series `f(X)` to `f(aX)`. -/
noncomputable def rescale (a : R) : R⟦X⟧ →+* R⟦X⟧ where
toFun f := PowerSeries.mk fun n => a ^ n * PowerSeries.coeff R n f
map_zero' := by
ext
simp only [LinearMap.map_zero, PowerSeries.coeff_mk, mul_zero]
map_one' := by
ext1
simp only [mul_boole, PowerSeries.coeff_mk, PowerSeries.coeff_one]
split_ifs with h
· rw [h, pow_zero a]
rfl
map_add' := by
intros
ext
dsimp only
exact mul_add _ _ _
map_mul' f g := by
ext
rw [PowerSeries.coeff_mul, PowerSeries.coeff_mk, PowerSeries.coeff_mul, Finset.mul_sum]
apply sum_congr rfl
simp only [coeff_mk, Prod.forall, mem_antidiagonal]
intro b c H
rw [← H, pow_add, mul_mul_mul_comm]
@[simp]
theorem coeff_rescale (f : R⟦X⟧) (a : R) (n : ℕ) :
coeff R n (rescale a f) = a ^ n * coeff R n f :=
coeff_mk n (fun n ↦ a ^ n * (coeff R n) f)
@[simp]
theorem rescale_zero : rescale 0 = (C R).comp (constantCoeff R) := by
ext x n
simp only [Function.comp_apply, RingHom.coe_comp, rescale, RingHom.coe_mk,
PowerSeries.coeff_mk _ _, coeff_C]
split_ifs with h <;> simp [h]
theorem rescale_zero_apply : rescale 0 X = C R (constantCoeff R X) := by simp
@[simp]
theorem rescale_one : rescale 1 = RingHom.id R⟦X⟧ := by
ext
simp only [coeff_rescale, one_pow, one_mul, RingHom.id_apply]
theorem rescale_mk (f : ℕ → R) (a : R) : rescale a (mk f) = mk fun n : ℕ => a ^ n * f n := by
ext
rw [coeff_rescale, coeff_mk, coeff_mk]
theorem rescale_rescale (f : R⟦X⟧) (a b : R) :
rescale b (rescale a f) = rescale (a * b) f := by
ext n
simp_rw [coeff_rescale]
rw [mul_pow, mul_comm _ (b ^ n), mul_assoc]
theorem rescale_mul (a b : R) : rescale (a * b) = (rescale b).comp (rescale a) := by
ext
simp [← rescale_rescale]
end CommSemiring
section CommSemiring
open Finset.HasAntidiagonal Finset
variable {R : Type*} [CommSemiring R] {ι : Type*} [DecidableEq ι]
/-- Coefficients of a product of power series -/
theorem coeff_prod (f : ι → PowerSeries R) (d : ℕ) (s : Finset ι) :
coeff R d (∏ j ∈ s, f j) = ∑ l ∈ finsuppAntidiag s d, ∏ i ∈ s, coeff R (l i) (f i) := by
simp only [coeff]
rw [MvPowerSeries.coeff_prod, ← AddEquiv.finsuppUnique_symm d, ← mapRange_finsuppAntidiag_eq,
sum_map, sum_congr rfl]
intro x _
apply prod_congr rfl
intro i _
congr 2
simp only [AddEquiv.toEquiv_eq_coe, Finsupp.mapRange.addEquiv_toEquiv, AddEquiv.toEquiv_symm,
Equiv.coe_toEmbedding, Finsupp.mapRange.equiv_apply, AddEquiv.coe_toEquiv_symm,
Finsupp.mapRange_apply, AddEquiv.finsuppUnique_symm]
/-- The `n`-th coefficient of the `k`-th power of a power series. -/
lemma coeff_pow (k n : ℕ) (φ : R⟦X⟧) :
coeff R n (φ ^ k) = ∑ l ∈ finsuppAntidiag (range k) n, ∏ i ∈ range k, coeff R (l i) φ := by
have h₁ (i : ℕ) : Function.const ℕ φ i = φ := rfl
have h₂ (i : ℕ) : ∏ j ∈ range i, Function.const ℕ φ j = φ ^ i := by
apply prod_range_induction (fun _ => φ) (fun i => φ ^ i) rfl (congrFun rfl) i
rw [← h₂, ← h₁ k]
apply coeff_prod (f := Function.const ℕ φ) (d := n) (s := range k)
/-- First coefficient of the product of two power series. -/
lemma coeff_one_mul (φ ψ : R⟦X⟧) : coeff R 1 (φ * ψ) =
coeff R 1 φ * constantCoeff R ψ + coeff R 1 ψ * constantCoeff R φ := by
have : Finset.antidiagonal 1 = {(0, 1), (1, 0)} := by exact rfl
rw [coeff_mul, this, Finset.sum_insert, Finset.sum_singleton, coeff_zero_eq_constantCoeff,
mul_comm, add_comm]
norm_num
/-- First coefficient of the `n`-th power of a power series. -/
lemma coeff_one_pow (n : ℕ) (φ : R⟦X⟧) :
coeff R 1 (φ ^ n) = n * coeff R 1 φ * (constantCoeff R φ) ^ (n - 1) := by
rcases Nat.eq_zero_or_pos n with (rfl | hn)
· simp
induction n with
| zero => by_contra; linarith
| succ n' ih =>
have h₁ (m : ℕ) : φ ^ (m + 1) = φ ^ m * φ := by exact rfl
have h₂ : Finset.antidiagonal 1 = {(0, 1), (1, 0)} := by exact rfl
rw [h₁, coeff_mul, h₂, Finset.sum_insert, Finset.sum_singleton]
· simp only [coeff_zero_eq_constantCoeff, map_pow, Nat.cast_add, Nat.cast_one,
add_tsub_cancel_right]
have h₀ : n' = 0 ∨ 1 ≤ n' := by omega
rcases h₀ with h' | h'
· by_contra h''
rw [h'] at h''
simp only [pow_zero, one_mul, coeff_one, one_ne_zero, ↓reduceIte, zero_mul, add_zero,
CharP.cast_eq_zero, zero_add, mul_one, not_true_eq_false] at h''
norm_num at h''
· rw [ih]
conv => lhs; arg 2; rw [mul_comm, ← mul_assoc]
move_mul [← (constantCoeff R) φ ^ (n' - 1)]
conv => enter [1, 2, 1, 1, 2]; rw [← pow_one (a := constantCoeff R φ)]
rw [← pow_add (a := constantCoeff R φ)]
conv => enter [1, 2, 1, 1]; rw [Nat.sub_add_cancel h']
conv => enter [1, 2, 1]; rw [mul_comm]
rw [mul_assoc, ← one_add_mul, add_comm, mul_assoc]
conv => enter [1, 2]; rw [mul_comm]
exact h'
· decide
end CommSemiring
section CommRing
variable {A : Type*} [CommRing A]
theorem not_isField : ¬IsField A⟦X⟧ := by
by_cases hA : Subsingleton A
· exact not_isField_of_subsingleton _
· nontriviality A
rw [Ring.not_isField_iff_exists_ideal_bot_lt_and_lt_top]
use Ideal.span {X}
constructor
· rw [bot_lt_iff_ne_bot, Ne, Ideal.span_singleton_eq_bot]
exact X_ne_zero
· rw [lt_top_iff_ne_top, Ne, Ideal.eq_top_iff_one, Ideal.mem_span_singleton,
X_dvd_iff, constantCoeff_one]
exact one_ne_zero
@[simp]
theorem rescale_X (a : A) : rescale a X = C A a * X := by
ext
simp only [coeff_rescale, coeff_C_mul, coeff_X]
split_ifs with h <;> simp [h]
theorem rescale_neg_one_X : rescale (-1 : A) X = -X := by
rw [rescale_X, map_neg, map_one, neg_one_mul]
/-- The ring homomorphism taking a power series `f(X)` to `f(-X)`. -/
noncomputable def evalNegHom : A⟦X⟧ →+* A⟦X⟧ :=
rescale (-1 : A)
@[simp]
theorem evalNegHom_X : evalNegHom (X : A⟦X⟧) = -X :=
rescale_neg_one_X
end CommRing
section Domain
variable [Ring R]
theorem eq_zero_or_eq_zero_of_mul_eq_zero [NoZeroDivisors R] (φ ψ : R⟦X⟧) (h : φ * ψ = 0) :
φ = 0 ∨ ψ = 0 := by
classical
rw [or_iff_not_imp_left]
intro H
have ex : ∃ m, coeff R m φ ≠ 0 := by
contrapose! H
exact ext H
let m := Nat.find ex
have hm₁ : coeff R m φ ≠ 0 := Nat.find_spec ex
have hm₂ : ∀ k < m, ¬coeff R k φ ≠ 0 := fun k => Nat.find_min ex
ext n
rw [(coeff R n).map_zero]
induction' n using Nat.strong_induction_on with n ih
replace h := congr_arg (coeff R (m + n)) h
rw [LinearMap.map_zero, coeff_mul, Finset.sum_eq_single (m, n)] at h
· replace h := NoZeroDivisors.eq_zero_or_eq_zero_of_mul_eq_zero h
rw [or_iff_not_imp_left] at h
exact h hm₁
· rintro ⟨i, j⟩ hij hne
by_cases hj : j < n
· rw [ih j hj, mul_zero]
by_cases hi : i < m
· specialize hm₂ _ hi
push_neg at hm₂
rw [hm₂, zero_mul]
rw [mem_antidiagonal] at hij
push_neg at hi hj
suffices m < i by
have : m + n < i + j := add_lt_add_of_lt_of_le this hj
exfalso
exact ne_of_lt this hij.symm
contrapose! hne
obtain rfl := le_antisymm hi hne
simpa [Ne, Prod.mk.inj_iff] using (add_right_inj m).mp hij
· contrapose!
intro
rw [mem_antidiagonal]
instance [NoZeroDivisors R] : NoZeroDivisors R⟦X⟧ where
eq_zero_or_eq_zero_of_mul_eq_zero := eq_zero_or_eq_zero_of_mul_eq_zero _ _
instance [IsDomain R] : IsDomain R⟦X⟧ :=
NoZeroDivisors.to_isDomain _
end Domain
section IsDomain
variable [CommRing R] [IsDomain R]
/-- The ideal spanned by the variable in the power series ring
over an integral domain is a prime ideal. -/
theorem span_X_isPrime : (Ideal.span ({X} : Set R⟦X⟧)).IsPrime := by
suffices Ideal.span ({X} : Set R⟦X⟧) = RingHom.ker (constantCoeff R) by
rw [this]
exact RingHom.ker_isPrime _
apply Ideal.ext
intro φ
rw [RingHom.mem_ker, Ideal.mem_span_singleton, X_dvd_iff]
/-- The variable of the power series ring over an integral domain is prime. -/
theorem X_prime : Prime (X : R⟦X⟧) := by
rw [← Ideal.span_singleton_prime]
· exact span_X_isPrime
· intro h
simpa [map_zero (coeff R 1)] using congr_arg (coeff R 1) h
/-- The variable of the power series ring over an integral domain is irreducible. -/
theorem X_irreducible : Irreducible (X : R⟦X⟧) := X_prime.irreducible
theorem rescale_injective {a : R} (ha : a ≠ 0) : Function.Injective (rescale a) := by
intro p q h
rw [PowerSeries.ext_iff] at *
intro n
specialize h n
rw [coeff_rescale, coeff_rescale, mul_eq_mul_left_iff] at h
apply h.resolve_right
intro h'
exact ha (pow_eq_zero h')
end IsDomain
section Algebra
variable {A : Type*} [CommSemiring R] [Semiring A] [Algebra R A]
theorem C_eq_algebraMap {r : R} : C R r = (algebraMap R R⟦X⟧) r :=
rfl
theorem algebraMap_apply {r : R} : algebraMap R A⟦X⟧ r = C A (algebraMap R A r) :=
MvPowerSeries.algebraMap_apply
instance [Nontrivial R] : Nontrivial (Subalgebra R R⟦X⟧) :=
{ inferInstanceAs <| Nontrivial <| Subalgebra R <| MvPowerSeries Unit R with }
end Algebra
end PowerSeries
namespace Polynomial
open Finsupp Polynomial
variable {σ : Type*} {R : Type*} [CommSemiring R] (φ ψ : R[X])
-- Porting note: added so we can add the `@[coe]` attribute
/-- The natural inclusion from polynomials into formal power series. -/
@[coe]
def ToPowerSeries : R[X] → (PowerSeries R) := fun φ =>
PowerSeries.mk fun n => coeff φ n
/-- The natural inclusion from polynomials into formal power series. -/
instance coeToPowerSeries : Coe R[X] (PowerSeries R) :=
⟨ToPowerSeries⟩
theorem coe_def : (φ : PowerSeries R) = PowerSeries.mk (coeff φ) :=
rfl
@[simp, norm_cast]
theorem coeff_coe (n) : PowerSeries.coeff R n φ = coeff φ n :=
congr_arg (coeff φ) Finsupp.single_eq_same
@[simp, norm_cast]
theorem coe_monomial (n : ℕ) (a : R) :
(monomial n a : PowerSeries R) = PowerSeries.monomial R n a := by
ext
simp [coeff_coe, PowerSeries.coeff_monomial, Polynomial.coeff_monomial, eq_comm]
@[simp, norm_cast]
theorem coe_zero : ((0 : R[X]) : PowerSeries R) = 0 :=
rfl
@[simp, norm_cast]
theorem coe_one : ((1 : R[X]) : PowerSeries R) = 1 := by
have := coe_monomial 0 (1 : R)
rwa [PowerSeries.monomial_zero_eq_C_apply] at this
@[simp, norm_cast]
theorem coe_add : ((φ + ψ : R[X]) : PowerSeries R) = φ + ψ := by
ext
simp
@[simp, norm_cast]
theorem coe_mul : ((φ * ψ : R[X]) : PowerSeries R) = φ * ψ :=
PowerSeries.ext fun n => by simp only [coeff_coe, PowerSeries.coeff_mul, coeff_mul]
@[simp, norm_cast]
theorem coe_C (a : R) : ((C a : R[X]) : PowerSeries R) = PowerSeries.C R a := by
have := coe_monomial 0 a
rwa [PowerSeries.monomial_zero_eq_C_apply] at this
@[simp, norm_cast]
theorem coe_X : ((X : R[X]) : PowerSeries R) = PowerSeries.X :=
coe_monomial _ _
@[simp]
theorem constantCoeff_coe : PowerSeries.constantCoeff R φ = φ.coeff 0 :=
rfl
variable (R)
theorem coe_injective : Function.Injective (Coe.coe : R[X] → PowerSeries R) := fun x y h => by
ext
simp_rw [← coeff_coe]
congr
variable {R φ ψ}
@[simp, norm_cast]
theorem coe_inj : (φ : PowerSeries R) = ψ ↔ φ = ψ :=
(coe_injective R).eq_iff
@[simp]
theorem coe_eq_zero_iff : (φ : PowerSeries R) = 0 ↔ φ = 0 := by rw [← coe_zero, coe_inj]
@[simp]
theorem coe_eq_one_iff : (φ : PowerSeries R) = 1 ↔ φ = 1 := by rw [← coe_one, coe_inj]
variable (φ ψ)
/-- The coercion from polynomials to power series
as a ring homomorphism.
-/
def coeToPowerSeries.ringHom : R[X] →+* PowerSeries R where
toFun := (Coe.coe : R[X] → PowerSeries R)
map_zero' := coe_zero
map_one' := coe_one
map_add' := coe_add
map_mul' := coe_mul
@[simp]
theorem coeToPowerSeries.ringHom_apply : coeToPowerSeries.ringHom φ = φ :=
rfl
@[simp, norm_cast]
theorem coe_pow (n : ℕ) : ((φ ^ n : R[X]) : PowerSeries R) = (φ : PowerSeries R) ^ n :=
coeToPowerSeries.ringHom.map_pow _ _
theorem eval₂_C_X_eq_coe : φ.eval₂ (PowerSeries.C R) PowerSeries.X = ↑φ := by
nth_rw 2 [← eval₂_C_X (p := φ)]
rw [← coeToPowerSeries.ringHom_apply, eval₂_eq_sum_range, eval₂_eq_sum_range, map_sum]
apply Finset.sum_congr rfl
intros
rw [map_mul, map_pow, coeToPowerSeries.ringHom_apply,
coeToPowerSeries.ringHom_apply, coe_C, coe_X]
variable (A : Type*) [Semiring A] [Algebra R A]
/-- The coercion from polynomials to power series
as an algebra homomorphism.
-/
def coeToPowerSeries.algHom : R[X] →ₐ[R] PowerSeries A :=
{ (PowerSeries.map (algebraMap R A)).comp coeToPowerSeries.ringHom with
commutes' := fun r => by simp [algebraMap_apply, PowerSeries.algebraMap_apply] }
@[simp]
theorem coeToPowerSeries.algHom_apply :
coeToPowerSeries.algHom A φ = PowerSeries.map (algebraMap R A) ↑φ :=
rfl
end Polynomial
namespace PowerSeries
section Algebra
open Polynomial
variable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A] (f : R⟦X⟧)
instance algebraPolynomial : Algebra R[X] A⟦X⟧ :=
RingHom.toAlgebra (Polynomial.coeToPowerSeries.algHom A).toRingHom
instance algebraPowerSeries : Algebra R⟦X⟧ A⟦X⟧ :=
(map (algebraMap R A)).toAlgebra
-- see Note [lower instance priority]
instance (priority := 100) algebraPolynomial' {A : Type*} [CommSemiring A] [Algebra R A[X]] :
Algebra R A⟦X⟧ :=
RingHom.toAlgebra <| Polynomial.coeToPowerSeries.ringHom.comp (algebraMap R A[X])
variable (A)
theorem algebraMap_apply' (p : R[X]) : algebraMap R[X] A⟦X⟧ p = map (algebraMap R A) p :=
rfl
theorem algebraMap_apply'' :
algebraMap R⟦X⟧ A⟦X⟧ f = map (algebraMap R A) f :=
rfl
end Algebra
end PowerSeries
end
|
RingTheory\PowerSeries\Derivative.lean | /-
Copyright (c) 2023 Richard M. Hill. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Richard M. Hill
-/
import Mathlib.RingTheory.PowerSeries.Trunc
import Mathlib.RingTheory.PowerSeries.Inverse
import Mathlib.RingTheory.Derivation.Basic
/-!
# Definitions
In this file we define an operation `derivative` (formal differentiation)
on the ring of formal power series in one variable (over an arbitrary commutative semiring).
Under suitable assumptions, we prove that two power series are equal if their derivatives
are equal and their constant terms are equal. This will give us a simple tool for proving
power series identities. For example, one can easily prove the power series identity
$\exp ( \log (1+X)) = 1+X$ by differentiating twice.
## Main Definition
- `PowerSeries.derivative R : Derivation R R⟦X⟧ R⟦X⟧` the formal derivative operation.
This is abbreviated `d⁄dX R`.
-/
namespace PowerSeries
open Polynomial Derivation Nat
section CommutativeSemiring
variable {R} [CommSemiring R]
/--
The formal derivative of a power series in one variable.
This is defined here as a function, but will be packaged as a
derivation `derivative` on `R⟦X⟧`.
-/
noncomputable def derivativeFun (f : R⟦X⟧) : R⟦X⟧ := mk fun n ↦ coeff R (n + 1) f * (n + 1)
theorem coeff_derivativeFun (f : R⟦X⟧) (n : ℕ) :
coeff R n f.derivativeFun = coeff R (n + 1) f * (n + 1) := by
rw [derivativeFun, coeff_mk]
theorem derivativeFun_coe (f : R[X]) : (f : R⟦X⟧).derivativeFun = derivative f := by
ext
rw [coeff_derivativeFun, coeff_coe, coeff_coe, coeff_derivative]
theorem derivativeFun_add (f g : R⟦X⟧) :
derivativeFun (f + g) = derivativeFun f + derivativeFun g := by
ext
rw [coeff_derivativeFun, map_add, map_add, coeff_derivativeFun,
coeff_derivativeFun, add_mul]
theorem derivativeFun_C (r : R) : derivativeFun (C R r) = 0 := by
ext n
-- Note that `map_zero` didn't get picked up, apparently due to a missing `FunLike.coe`
rw [coeff_derivativeFun, coeff_succ_C, zero_mul, (coeff R n).map_zero]
theorem trunc_derivativeFun (f : R⟦X⟧) (n : ℕ) :
trunc n f.derivativeFun = derivative (trunc (n + 1) f) := by
ext d
rw [coeff_trunc]
split_ifs with h
· have : d + 1 < n + 1 := succ_lt_succ_iff.2 h
rw [coeff_derivativeFun, coeff_derivative, coeff_trunc, if_pos this]
· have : ¬d + 1 < n + 1 := by rwa [succ_lt_succ_iff]
rw [coeff_derivative, coeff_trunc, if_neg this, zero_mul]
--A special case of `derivativeFun_mul`, used in its proof.
private theorem derivativeFun_coe_mul_coe (f g : R[X]) : derivativeFun (f * g : R⟦X⟧) =
f * derivative g + g * derivative f := by
rw [← coe_mul, derivativeFun_coe, derivative_mul,
add_comm, mul_comm _ g, ← coe_mul, ← coe_mul, Polynomial.coe_add]
/-- **Leibniz rule for formal power series**. -/
theorem derivativeFun_mul (f g : R⟦X⟧) :
derivativeFun (f * g) = f • g.derivativeFun + g • f.derivativeFun := by
ext n
have h₁ : n < n + 1 := lt_succ_self n
have h₂ : n < n + 1 + 1 := Nat.lt_add_right _ h₁
rw [coeff_derivativeFun, map_add, coeff_mul_eq_coeff_trunc_mul_trunc _ _ (lt_succ_self _),
smul_eq_mul, smul_eq_mul, coeff_mul_eq_coeff_trunc_mul_trunc₂ g f.derivativeFun h₂ h₁,
coeff_mul_eq_coeff_trunc_mul_trunc₂ f g.derivativeFun h₂ h₁, trunc_derivativeFun,
trunc_derivativeFun, ← map_add, ← derivativeFun_coe_mul_coe, coeff_derivativeFun]
theorem derivativeFun_one : derivativeFun (1 : R⟦X⟧) = 0 := by
rw [← map_one (C R), derivativeFun_C (1 : R)]
theorem derivativeFun_smul (r : R) (f : R⟦X⟧) : derivativeFun (r • f) = r • derivativeFun f := by
rw [smul_eq_C_mul, smul_eq_C_mul, derivativeFun_mul, derivativeFun_C, smul_zero, add_zero,
smul_eq_mul]
variable (R)
/-- The formal derivative of a formal power series -/
noncomputable def derivative : Derivation R R⟦X⟧ R⟦X⟧ where
toFun := derivativeFun
map_add' := derivativeFun_add
map_smul' := derivativeFun_smul
map_one_eq_zero' := derivativeFun_one
leibniz' := derivativeFun_mul
/-- Abbreviation of `PowerSeries.derivative`, the formal derivative on `R⟦X⟧` -/
scoped notation "d⁄dX" => derivative
variable {R}
@[simp] theorem derivative_C (r : R) : d⁄dX R (C R r) = 0 := derivativeFun_C r
theorem coeff_derivative (f : R⟦X⟧) (n : ℕ) :
coeff R n (d⁄dX R f) = coeff R (n + 1) f * (n + 1) := coeff_derivativeFun f n
theorem derivative_coe (f : R[X]) : d⁄dX R f = Polynomial.derivative f := derivativeFun_coe f
@[simp] theorem derivative_X : d⁄dX R (X : R⟦X⟧) = 1 := by
ext
rw [coeff_derivative, coeff_one, coeff_X, boole_mul]
simp_rw [add_left_eq_self]
split_ifs with h
· rw [h, cast_zero, zero_add]
· rfl
theorem trunc_derivative (f : R⟦X⟧) (n : ℕ) :
trunc n (d⁄dX R f) = Polynomial.derivative (trunc (n + 1) f) :=
trunc_derivativeFun ..
theorem trunc_derivative' (f : R⟦X⟧) (n : ℕ) :
trunc (n-1) (d⁄dX R f) = Polynomial.derivative (trunc n f) := by
cases n with
| zero =>
simp
| succ n =>
rw [succ_sub_one, trunc_derivative]
end CommutativeSemiring
/- In the next lemma, we use `smul_right_inj`, which requires not only `NoZeroSMulDivisors ℕ R`, but
also cancellation of addition in `R`. For this reason, the next lemma is stated in the case that `R`
is a `CommRing`. -/
/-- If `f` and `g` have the same constant term and derivative, then they are equal. -/
theorem derivative.ext {R} [CommRing R] [NoZeroSMulDivisors ℕ R] {f g} (hD : d⁄dX R f = d⁄dX R g)
(hc : constantCoeff R f = constantCoeff R g) : f = g := by
ext n
cases n with
| zero =>
rw [coeff_zero_eq_constantCoeff, hc]
| succ n =>
have equ : coeff R n (d⁄dX R f) = coeff R n (d⁄dX R g) := by rw [hD]
rwa [coeff_derivative, coeff_derivative, ← cast_succ, mul_comm, ← nsmul_eq_mul,
mul_comm, ← nsmul_eq_mul, smul_right_inj n.succ_ne_zero] at equ
@[simp] theorem derivative_inv {R} [CommRing R] (f : R⟦X⟧ˣ) :
d⁄dX R ↑f⁻¹ = -(↑f⁻¹ : R⟦X⟧) ^ 2 * d⁄dX R f := by
apply Derivation.leibniz_of_mul_eq_one
simp
@[simp] theorem derivative_invOf {R} [CommRing R] (f : R⟦X⟧) [Invertible f] :
d⁄dX R ⅟f = - ⅟f ^ 2 * d⁄dX R f := by
rw [Derivation.leibniz_invOf, smul_eq_mul]
/-
The following theorem is stated only in the case that `R` is a field. This is because
there is currently no instance of `Inv R⟦X⟧` for more general base rings `R`.
-/
@[simp] theorem derivative_inv' {R} [Field R] (f : R⟦X⟧) : d⁄dX R f⁻¹ = -f⁻¹ ^ 2 * d⁄dX R f := by
by_cases h : constantCoeff R f = 0
· suffices f⁻¹ = 0 by
rw [this, pow_two, zero_mul, neg_zero, zero_mul, map_zero]
rwa [MvPowerSeries.inv_eq_zero]
apply Derivation.leibniz_of_mul_eq_one
exact PowerSeries.inv_mul_cancel (h := h)
end PowerSeries
|
RingTheory\PowerSeries\Inverse.lean | /-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Kenny Lau, María Inés de Frutos-Fernández, Filippo A. E. Nuccio
-/
import Mathlib.RingTheory.DiscreteValuationRing.Basic
import Mathlib.RingTheory.MvPowerSeries.Inverse
import Mathlib.RingTheory.PowerSeries.Basic
import Mathlib.RingTheory.PowerSeries.Order
import Mathlib.RingTheory.LocalRing.ResidueField.Defs
/-! # Formal power series - Inverses
If the constant coefficient of a formal (univariate) power series is invertible,
then this formal power series is invertible.
(See the discussion in `Mathlib.RingTheory.MvPowerSeries.Inverse` for
the construction.)
Formal (univariate) power series over a local ring form a local ring.
Formal (univariate) power series over a field form a discrete valuation ring, and a normalization
monoid. The definition `residueFieldOfPowerSeries` provides the isomorphism between the residue
field of `k⟦X⟧` and `k`, when `k` is a field.
-/
noncomputable section
open Polynomial
open Finset (antidiagonal mem_antidiagonal)
namespace PowerSeries
open Finsupp (single)
variable {R : Type*}
section Ring
variable [Ring R]
/-- Auxiliary function used for computing inverse of a power series -/
protected def inv.aux : R → R⟦X⟧ → R⟦X⟧ :=
MvPowerSeries.inv.aux
theorem coeff_inv_aux (n : ℕ) (a : R) (φ : R⟦X⟧) :
coeff R n (inv.aux a φ) =
if n = 0 then a
else
-a *
∑ x ∈ antidiagonal n,
if x.2 < n then coeff R x.1 φ * coeff R x.2 (inv.aux a φ) else 0 := by
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [coeff, inv.aux, MvPowerSeries.coeff_inv_aux]
simp only [Finsupp.single_eq_zero]
split_ifs; · rfl
congr 1
symm
apply Finset.sum_nbij' (fun (a, b) ↦ (single () a, single () b))
fun (f, g) ↦ (f (), g ())
· aesop
· aesop
· aesop
· aesop
· rintro ⟨i, j⟩ _hij
obtain H | H := le_or_lt n j
· aesop
rw [if_pos H, if_pos]
· rfl
refine ⟨?_, fun hh ↦ H.not_le ?_⟩
· rintro ⟨⟩
simpa [Finsupp.single_eq_same] using le_of_lt H
· simpa [Finsupp.single_eq_same] using hh ()
/-- A formal power series is invertible if the constant coefficient is invertible. -/
def invOfUnit (φ : R⟦X⟧) (u : Rˣ) : R⟦X⟧ :=
MvPowerSeries.invOfUnit φ u
theorem coeff_invOfUnit (n : ℕ) (φ : R⟦X⟧) (u : Rˣ) :
coeff R n (invOfUnit φ u) =
if n = 0 then ↑u⁻¹
else
-↑u⁻¹ *
∑ x ∈ antidiagonal n,
if x.2 < n then coeff R x.1 φ * coeff R x.2 (invOfUnit φ u) else 0 :=
coeff_inv_aux n (↑u⁻¹ : R) φ
@[simp]
theorem constantCoeff_invOfUnit (φ : R⟦X⟧) (u : Rˣ) :
constantCoeff R (invOfUnit φ u) = ↑u⁻¹ := by
rw [← coeff_zero_eq_constantCoeff_apply, coeff_invOfUnit, if_pos rfl]
@[simp]
theorem mul_invOfUnit (φ : R⟦X⟧) (u : Rˣ) (h : constantCoeff R φ = u) :
φ * invOfUnit φ u = 1 :=
MvPowerSeries.mul_invOfUnit φ u <| h
@[simp]
theorem invOfUnit_mul (φ : R⟦X⟧) (u : Rˣ) (h : constantCoeff R φ = u) :
invOfUnit φ u * φ = 1 :=
MvPowerSeries.invOfUnit_mul φ u h
theorem isUnit_iff_constantCoeff {φ : R⟦X⟧} :
IsUnit φ ↔ IsUnit (constantCoeff R φ) :=
MvPowerSeries.isUnit_iff_constantCoeff
/-- Two ways of removing the constant coefficient of a power series are the same. -/
theorem sub_const_eq_shift_mul_X (φ : R⟦X⟧) :
φ - C R (constantCoeff R φ) = (mk fun p ↦ coeff R (p + 1) φ) * X :=
sub_eq_iff_eq_add.mpr (eq_shift_mul_X_add_const φ)
theorem sub_const_eq_X_mul_shift (φ : R⟦X⟧) :
φ - C R (constantCoeff R φ) = X * mk fun p ↦ coeff R (p + 1) φ :=
sub_eq_iff_eq_add.mpr (eq_X_mul_shift_add_const φ)
end Ring
section Field
variable {k : Type*} [Field k]
/-- The inverse 1/f of a power series f defined over a field -/
protected def inv : k⟦X⟧ → k⟦X⟧ :=
MvPowerSeries.inv
instance : Inv k⟦X⟧ := ⟨PowerSeries.inv⟩
theorem inv_eq_inv_aux (φ : k⟦X⟧) : φ⁻¹ = inv.aux (constantCoeff k φ)⁻¹ φ :=
rfl
theorem coeff_inv (n) (φ : k⟦X⟧) :
coeff k n φ⁻¹ =
if n = 0 then (constantCoeff k φ)⁻¹
else
-(constantCoeff k φ)⁻¹ *
∑ x ∈ antidiagonal n,
if x.2 < n then coeff k x.1 φ * coeff k x.2 φ⁻¹ else 0 := by
rw [inv_eq_inv_aux, coeff_inv_aux n (constantCoeff k φ)⁻¹ φ]
@[simp]
theorem constantCoeff_inv (φ : k⟦X⟧) : constantCoeff k φ⁻¹ = (constantCoeff k φ)⁻¹ :=
MvPowerSeries.constantCoeff_inv φ
theorem inv_eq_zero {φ : k⟦X⟧} : φ⁻¹ = 0 ↔ constantCoeff k φ = 0 :=
MvPowerSeries.inv_eq_zero
theorem zero_inv : (0 : k⟦X⟧)⁻¹ = 0 :=
MvPowerSeries.zero_inv
-- Porting note (#10618): simp can prove this.
-- @[simp]
theorem invOfUnit_eq (φ : k⟦X⟧) (h : constantCoeff k φ ≠ 0) :
invOfUnit φ (Units.mk0 _ h) = φ⁻¹ :=
MvPowerSeries.invOfUnit_eq _ _
@[simp]
theorem invOfUnit_eq' (φ : k⟦X⟧) (u : Units k) (h : constantCoeff k φ = u) :
invOfUnit φ u = φ⁻¹ :=
MvPowerSeries.invOfUnit_eq' φ _ h
@[simp]
protected theorem mul_inv_cancel (φ : k⟦X⟧) (h : constantCoeff k φ ≠ 0) : φ * φ⁻¹ = 1 :=
MvPowerSeries.mul_inv_cancel φ h
@[simp]
protected theorem inv_mul_cancel (φ : k⟦X⟧) (h : constantCoeff k φ ≠ 0) : φ⁻¹ * φ = 1 :=
MvPowerSeries.inv_mul_cancel φ h
theorem eq_mul_inv_iff_mul_eq {φ₁ φ₂ φ₃ : k⟦X⟧} (h : constantCoeff k φ₃ ≠ 0) :
φ₁ = φ₂ * φ₃⁻¹ ↔ φ₁ * φ₃ = φ₂ :=
MvPowerSeries.eq_mul_inv_iff_mul_eq h
theorem eq_inv_iff_mul_eq_one {φ ψ : k⟦X⟧} (h : constantCoeff k ψ ≠ 0) :
φ = ψ⁻¹ ↔ φ * ψ = 1 :=
MvPowerSeries.eq_inv_iff_mul_eq_one h
theorem inv_eq_iff_mul_eq_one {φ ψ : k⟦X⟧} (h : constantCoeff k ψ ≠ 0) :
ψ⁻¹ = φ ↔ φ * ψ = 1 :=
MvPowerSeries.inv_eq_iff_mul_eq_one h
protected theorem mul_inv_rev (φ ψ : k⟦X⟧) : (φ * ψ)⁻¹ = ψ⁻¹ * φ⁻¹ :=
MvPowerSeries.mul_inv_rev _ _
instance : InvOneClass k⟦X⟧ :=
{ inferInstanceAs <| InvOneClass <| MvPowerSeries Unit k with }
@[simp]
theorem C_inv (r : k) : (C k r)⁻¹ = C k r⁻¹ :=
MvPowerSeries.C_inv _
@[simp]
theorem X_inv : (X : k⟦X⟧)⁻¹ = 0 :=
MvPowerSeries.X_inv _
theorem smul_inv (r : k) (φ : k⟦X⟧) : (r • φ)⁻¹ = r⁻¹ • φ⁻¹ :=
MvPowerSeries.smul_inv _ _
/-- `firstUnitCoeff` is the non-zero coefficient whose index is `f.order`, seen as a unit of the
field. It is obtained using `divided_by_X_pow_order`, defined in `PowerSeries.Order`-/
def firstUnitCoeff {f : k⟦X⟧} (hf : f ≠ 0) : kˣ :=
let d := f.order.get (order_finite_iff_ne_zero.mpr hf)
have f_const : coeff k d f ≠ 0 := by apply coeff_order
have : Invertible (constantCoeff k (divided_by_X_pow_order hf)) := by
apply invertibleOfNonzero
convert f_const using 1
rw [← coeff_zero_eq_constantCoeff, ← zero_add d]
convert (coeff_X_pow_mul (exists_eq_mul_right_of_dvd (X_pow_order_dvd
(order_finite_iff_ne_zero.mpr hf))).choose d 0).symm
exact (self_eq_X_pow_order_mul_divided_by_X_pow_order hf).symm
unitOfInvertible (constantCoeff k (divided_by_X_pow_order hf))
/-- `Inv_divided_by_X_pow_order` is the inverse of the element obtained by diving a non-zero power
series by the largest power of `X` dividing it. Useful to create a term of type `Units`, done in
`Unit_divided_by_X_pow_order` -/
def Inv_divided_by_X_pow_order {f : k⟦X⟧} (hf : f ≠ 0) : k⟦X⟧ :=
invOfUnit (divided_by_X_pow_order hf) (firstUnitCoeff hf)
@[simp]
theorem Inv_divided_by_X_pow_order_rightInv {f : k⟦X⟧} (hf : f ≠ 0) :
divided_by_X_pow_order hf * Inv_divided_by_X_pow_order hf = 1 :=
mul_invOfUnit (divided_by_X_pow_order hf) (firstUnitCoeff hf) rfl
@[simp]
theorem Inv_divided_by_X_pow_order_leftInv {f : k⟦X⟧} (hf : f ≠ 0) :
(Inv_divided_by_X_pow_order hf) * (divided_by_X_pow_order hf) = 1 := by
rw [mul_comm]
exact mul_invOfUnit (divided_by_X_pow_order hf) (firstUnitCoeff hf) rfl
open scoped Classical
/-- `Unit_of_divided_by_X_pow_order` is the unit power series obtained by dividing a non-zero
power series by the largest power of `X` that divides it. -/
def Unit_of_divided_by_X_pow_order (f : k⟦X⟧) : k⟦X⟧ˣ :=
if hf : f = 0 then 1
else
{ val := divided_by_X_pow_order hf
inv := Inv_divided_by_X_pow_order hf
val_inv := Inv_divided_by_X_pow_order_rightInv hf
inv_val := Inv_divided_by_X_pow_order_leftInv hf }
theorem isUnit_divided_by_X_pow_order {f : k⟦X⟧} (hf : f ≠ 0) :
IsUnit (divided_by_X_pow_order hf) :=
⟨Unit_of_divided_by_X_pow_order f,
by simp only [Unit_of_divided_by_X_pow_order, dif_neg hf, Units.val_mk]⟩
theorem Unit_of_divided_by_X_pow_order_nonzero {f : k⟦X⟧} (hf : f ≠ 0) :
↑(Unit_of_divided_by_X_pow_order f) = divided_by_X_pow_order hf := by
simp only [Unit_of_divided_by_X_pow_order, dif_neg hf, Units.val_mk]
@[simp]
theorem Unit_of_divided_by_X_pow_order_zero : Unit_of_divided_by_X_pow_order (0 : k⟦X⟧) = 1 := by
simp only [Unit_of_divided_by_X_pow_order, dif_pos]
theorem eq_divided_by_X_pow_order_Iff_Unit {f : k⟦X⟧} (hf : f ≠ 0) :
f = divided_by_X_pow_order hf ↔ IsUnit f :=
⟨fun h ↦ by rw [h]; exact isUnit_divided_by_X_pow_order hf, fun h ↦ by
have : f.order.get (order_finite_iff_ne_zero.mpr hf) = 0 := by
simp only [order_zero_of_unit h, PartENat.get_zero]
convert (self_eq_X_pow_order_mul_divided_by_X_pow_order hf).symm
simp only [this, pow_zero, one_mul]⟩
end Field
section LocalRing
variable {S : Type*} [CommRing R] [CommRing S] (f : R →+* S) [IsLocalRingHom f]
instance map.isLocalRingHom : IsLocalRingHom (map f) :=
MvPowerSeries.map.isLocalRingHom f
variable [LocalRing R] [LocalRing S]
instance : LocalRing R⟦X⟧ :=
{ inferInstanceAs <| LocalRing <| MvPowerSeries Unit R with }
end LocalRing
section DiscreteValuationRing
variable {k : Type*} [Field k]
open DiscreteValuationRing
theorem hasUnitMulPowIrreducibleFactorization :
HasUnitMulPowIrreducibleFactorization k⟦X⟧ :=
⟨X, And.intro X_irreducible
(by
intro f hf
use f.order.get (order_finite_iff_ne_zero.mpr hf)
use Unit_of_divided_by_X_pow_order f
simp only [Unit_of_divided_by_X_pow_order_nonzero hf]
exact self_eq_X_pow_order_mul_divided_by_X_pow_order hf)⟩
instance : UniqueFactorizationMonoid k⟦X⟧ :=
hasUnitMulPowIrreducibleFactorization.toUniqueFactorizationMonoid
instance : DiscreteValuationRing k⟦X⟧ :=
ofHasUnitMulPowIrreducibleFactorization hasUnitMulPowIrreducibleFactorization
instance isNoetherianRing : IsNoetherianRing k⟦X⟧ :=
PrincipalIdealRing.isNoetherianRing
/-- The maximal ideal of `k⟦X⟧` is generated by `X`. -/
theorem maximalIdeal_eq_span_X : LocalRing.maximalIdeal (k⟦X⟧) = Ideal.span {X} := by
have hX : (Ideal.span {(X : k⟦X⟧)}).IsMaximal := by
rw [Ideal.isMaximal_iff]
constructor
· rw [Ideal.mem_span_singleton]
exact Prime.not_dvd_one X_prime
· intro I f hI hfX hfI
rw [Ideal.mem_span_singleton, X_dvd_iff] at hfX
have hfI0 : C k (f 0) ∈ I := by
have : C k (f 0) = f - (f - C k (f 0)) := by rw [sub_sub_cancel]
rw [this]
apply Ideal.sub_mem I hfI
apply hI
rw [Ideal.mem_span_singleton, X_dvd_iff, map_sub, constantCoeff_C, ←
coeff_zero_eq_constantCoeff_apply, sub_eq_zero, coeff_zero_eq_constantCoeff]
rfl
rw [← Ideal.eq_top_iff_one]
apply Ideal.eq_top_of_isUnit_mem I hfI0 (IsUnit.map (C k) (Ne.isUnit hfX))
rw [LocalRing.eq_maximalIdeal hX]
instance : NormalizationMonoid k⟦X⟧ where
normUnit f := (Unit_of_divided_by_X_pow_order f)⁻¹
normUnit_zero := by simp only [Unit_of_divided_by_X_pow_order_zero, inv_one]
normUnit_mul := fun hf hg ↦ by
simp only [← mul_inv, inv_inj]
simp only [Unit_of_divided_by_X_pow_order_nonzero (mul_ne_zero hf hg),
Unit_of_divided_by_X_pow_order_nonzero hf, Unit_of_divided_by_X_pow_order_nonzero hg,
Units.ext_iff, val_unitOfInvertible, Units.val_mul, divided_by_X_pow_orderMul]
normUnit_coe_units := by
intro u
set u₀ := u.1 with hu
have h₀ : IsUnit u₀ := ⟨u, hu.symm⟩
rw [inv_inj, Units.ext_iff, ← hu, Unit_of_divided_by_X_pow_order_nonzero h₀.ne_zero]
exact ((eq_divided_by_X_pow_order_Iff_Unit h₀.ne_zero).mpr h₀).symm
theorem normUnit_X : normUnit (X : k⟦X⟧) = 1 := by
simp [normUnit, ← Units.val_eq_one, Unit_of_divided_by_X_pow_order_nonzero]
theorem X_eq_normalizeX : (X : k⟦X⟧) = normalize X := by
simp only [normalize_apply, normUnit_X, Units.val_one, mul_one]
open UniqueFactorizationMonoid Classical
theorem normalized_count_X_eq_of_coe {P : k[X]} (hP : P ≠ 0) :
Multiset.count PowerSeries.X (normalizedFactors (P : k⟦X⟧)) =
Multiset.count Polynomial.X (normalizedFactors P) := by
apply eq_of_forall_le_iff
simp only [← PartENat.coe_le_coe]
rw [X_eq_normalize, PowerSeries.X_eq_normalizeX, ← multiplicity_eq_count_normalizedFactors
irreducible_X hP, ← multiplicity_eq_count_normalizedFactors X_irreducible] <;>
simp only [← multiplicity.pow_dvd_iff_le_multiplicity, Polynomial.X_pow_dvd_iff,
PowerSeries.X_pow_dvd_iff, Polynomial.coeff_coe P, implies_true, ne_eq, coe_eq_zero_iff, hP,
not_false_eq_true]
open LocalRing
theorem ker_coeff_eq_max_ideal : RingHom.ker (constantCoeff k) = maximalIdeal _ :=
Ideal.ext fun _ ↦ by
rw [RingHom.mem_ker, maximalIdeal_eq_span_X, Ideal.mem_span_singleton, X_dvd_iff]
/-- The ring isomorphism between the residue field of the ring of power series valued in a field `K`
and `K` itself. -/
def residueFieldOfPowerSeries : ResidueField k⟦X⟧ ≃+* k :=
(Ideal.quotEquivOfEq (ker_coeff_eq_max_ideal).symm).trans
(RingHom.quotientKerEquivOfSurjective constantCoeff_surj)
end DiscreteValuationRing
end PowerSeries
end
|
RingTheory\PowerSeries\Order.lean | /-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Kenny Lau
-/
import Mathlib.Algebra.CharP.Defs
import Mathlib.RingTheory.Multiplicity
import Mathlib.RingTheory.PowerSeries.Basic
/-! # Formal power series (in one variable) - Order
The `PowerSeries.order` of a formal power series `φ` is the multiplicity of the variable `X` in `φ`.
If the coefficients form an integral domain, then `PowerSeries.order` is an
additive valuation (`PowerSeries.order_mul`, `PowerSeries.le_order_add`).
We prove that if the commutative ring `R` of coefficients is an integral domain,
then the ring `R⟦X⟧` of formal power series in one variable over `R`
is an integral domain.
Given a non-zero power series `f`, `divided_by_X_pow_order f` is the power series obtained by
dividing out the largest power of X that divides `f`, that is its order. This is useful when
proving that `R⟦X⟧` is a normalization monoid, which is done in `PowerSeries.Inverse`.
-/
noncomputable section
open Polynomial
open Finset (antidiagonal mem_antidiagonal)
namespace PowerSeries
open Finsupp (single)
variable {R : Type*}
section OrderBasic
open multiplicity
variable [Semiring R] {φ : R⟦X⟧}
theorem exists_coeff_ne_zero_iff_ne_zero : (∃ n : ℕ, coeff R n φ ≠ 0) ↔ φ ≠ 0 := by
refine not_iff_not.mp ?_
push_neg
-- FIXME: the `FunLike.coe` doesn't seem to be picked up in the expression after #8386?
simp [PowerSeries.ext_iff, (coeff R _).map_zero]
/-- The order of a formal power series `φ` is the greatest `n : PartENat`
such that `X^n` divides `φ`. The order is `⊤` if and only if `φ = 0`. -/
def order (φ : R⟦X⟧) : PartENat :=
letI := Classical.decEq R
letI := Classical.decEq R⟦X⟧
if h : φ = 0 then ⊤ else Nat.find (exists_coeff_ne_zero_iff_ne_zero.mpr h)
/-- The order of the `0` power series is infinite. -/
@[simp]
theorem order_zero : order (0 : R⟦X⟧) = ⊤ :=
dif_pos rfl
theorem order_finite_iff_ne_zero : (order φ).Dom ↔ φ ≠ 0 := by
simp only [order]
constructor
· split_ifs with h <;> intro H
· simp only [PartENat.top_eq_none, Part.not_none_dom] at H
· exact h
· intro h
simp [h]
/-- If the order of a formal power series is finite,
then the coefficient indexed by the order is nonzero. -/
theorem coeff_order (h : (order φ).Dom) : coeff R (φ.order.get h) φ ≠ 0 := by
classical
simp only [order, order_finite_iff_ne_zero.mp h, not_false_iff, dif_neg, PartENat.get_natCast']
generalize_proofs h
exact Nat.find_spec h
/-- If the `n`th coefficient of a formal power series is nonzero,
then the order of the power series is less than or equal to `n`. -/
theorem order_le (n : ℕ) (h : coeff R n φ ≠ 0) : order φ ≤ n := by
classical
rw [order, dif_neg]
· simp only [PartENat.coe_le_coe]
exact Nat.find_le h
· exact exists_coeff_ne_zero_iff_ne_zero.mp ⟨n, h⟩
/-- The `n`th coefficient of a formal power series is `0` if `n` is strictly
smaller than the order of the power series. -/
theorem coeff_of_lt_order (n : ℕ) (h : ↑n < order φ) : coeff R n φ = 0 := by
contrapose! h
exact order_le _ h
/-- The `0` power series is the unique power series with infinite order. -/
@[simp]
theorem order_eq_top {φ : R⟦X⟧} : φ.order = ⊤ ↔ φ = 0 :=
PartENat.not_dom_iff_eq_top.symm.trans order_finite_iff_ne_zero.not_left
/-- The order of a formal power series is at least `n` if
the `i`th coefficient is `0` for all `i < n`. -/
theorem nat_le_order (φ : R⟦X⟧) (n : ℕ) (h : ∀ i < n, coeff R i φ = 0) : ↑n ≤ order φ := by
by_contra H; rw [not_le] at H
have : (order φ).Dom := PartENat.dom_of_le_natCast H.le
rw [← PartENat.natCast_get this, PartENat.coe_lt_coe] at H
exact coeff_order this (h _ H)
/-- The order of a formal power series is at least `n` if
the `i`th coefficient is `0` for all `i < n`. -/
theorem le_order (φ : R⟦X⟧) (n : PartENat) (h : ∀ i : ℕ, ↑i < n → coeff R i φ = 0) :
n ≤ order φ := by
induction n using PartENat.casesOn
· show _ ≤ _
rw [top_le_iff, order_eq_top]
ext i
exact h _ (PartENat.natCast_lt_top i)
· apply nat_le_order
simpa only [PartENat.coe_lt_coe] using h
/-- The order of a formal power series is exactly `n` if the `n`th coefficient is nonzero,
and the `i`th coefficient is `0` for all `i < n`. -/
theorem order_eq_nat {φ : R⟦X⟧} {n : ℕ} :
order φ = n ↔ coeff R n φ ≠ 0 ∧ ∀ i, i < n → coeff R i φ = 0 := by
classical
rcases eq_or_ne φ 0 with (rfl | hφ)
· simpa [(coeff R _).map_zero] using (PartENat.natCast_ne_top _).symm
simp [order, dif_neg hφ, Nat.find_eq_iff]
/-- The order of a formal power series is exactly `n` if the `n`th coefficient is nonzero,
and the `i`th coefficient is `0` for all `i < n`. -/
theorem order_eq {φ : R⟦X⟧} {n : PartENat} :
order φ = n ↔ (∀ i : ℕ, ↑i = n → coeff R i φ ≠ 0) ∧ ∀ i : ℕ, ↑i < n → coeff R i φ = 0 := by
induction n using PartENat.casesOn
· rw [order_eq_top]
constructor
· rintro rfl
constructor <;> intros
· exfalso
exact PartENat.natCast_ne_top ‹_› ‹_›
· exact (coeff _ _).map_zero
· rintro ⟨_h₁, h₂⟩
ext i
exact h₂ i (PartENat.natCast_lt_top i)
· simpa [PartENat.natCast_inj] using order_eq_nat
/-- The order of the sum of two formal power series
is at least the minimum of their orders. -/
theorem le_order_add (φ ψ : R⟦X⟧) : min (order φ) (order ψ) ≤ order (φ + ψ) := by
refine le_order _ _ ?_
simp (config := { contextual := true }) [coeff_of_lt_order]
private theorem order_add_of_order_eq.aux (φ ψ : R⟦X⟧) (_h : order φ ≠ order ψ)
(H : order φ < order ψ) : order (φ + ψ) ≤ order φ ⊓ order ψ := by
suffices order (φ + ψ) = order φ by
rw [le_inf_iff, this]
exact ⟨le_rfl, le_of_lt H⟩
rw [order_eq]
constructor
· intro i hi
rw [← hi] at H
rw [(coeff _ _).map_add, coeff_of_lt_order i H, add_zero]
exact (order_eq_nat.1 hi.symm).1
· intro i hi
rw [(coeff _ _).map_add, coeff_of_lt_order i hi, coeff_of_lt_order i (lt_trans hi H),
zero_add]
/-- The order of the sum of two formal power series
is the minimum of their orders if their orders differ. -/
theorem order_add_of_order_eq (φ ψ : R⟦X⟧) (h : order φ ≠ order ψ) :
order (φ + ψ) = order φ ⊓ order ψ := by
refine le_antisymm ?_ (le_order_add _ _)
by_cases H₁ : order φ < order ψ
· apply order_add_of_order_eq.aux _ _ h H₁
by_cases H₂ : order ψ < order φ
· simpa only [add_comm, inf_comm] using order_add_of_order_eq.aux _ _ h.symm H₂
exfalso; exact h (le_antisymm (not_lt.1 H₂) (not_lt.1 H₁))
/-- The order of the product of two formal power series
is at least the sum of their orders. -/
theorem order_mul_ge (φ ψ : R⟦X⟧) : order φ + order ψ ≤ order (φ * ψ) := by
apply le_order
intro n hn; rw [coeff_mul, Finset.sum_eq_zero]
rintro ⟨i, j⟩ hij
by_cases hi : ↑i < order φ
· rw [coeff_of_lt_order i hi, zero_mul]
by_cases hj : ↑j < order ψ
· rw [coeff_of_lt_order j hj, mul_zero]
rw [not_lt] at hi hj; rw [mem_antidiagonal] at hij
exfalso
apply ne_of_lt (lt_of_lt_of_le hn <| add_le_add hi hj)
rw [← Nat.cast_add, hij]
/-- The order of the monomial `a*X^n` is infinite if `a = 0` and `n` otherwise. -/
theorem order_monomial (n : ℕ) (a : R) [Decidable (a = 0)] :
order (monomial R n a) = if a = 0 then (⊤ : PartENat) else n := by
split_ifs with h
· rw [h, order_eq_top, LinearMap.map_zero]
· rw [order_eq]
constructor <;> intro i hi
· rw [PartENat.natCast_inj] at hi
rwa [hi, coeff_monomial_same]
· rw [PartENat.coe_lt_coe] at hi
rw [coeff_monomial, if_neg]
exact ne_of_lt hi
/-- The order of the monomial `a*X^n` is `n` if `a ≠ 0`. -/
theorem order_monomial_of_ne_zero (n : ℕ) (a : R) (h : a ≠ 0) : order (monomial R n a) = n := by
classical
rw [order_monomial, if_neg h]
/-- If `n` is strictly smaller than the order of `ψ`, then the `n`th coefficient of its product
with any other power series is `0`. -/
theorem coeff_mul_of_lt_order {φ ψ : R⟦X⟧} {n : ℕ} (h : ↑n < ψ.order) :
coeff R n (φ * ψ) = 0 := by
suffices coeff R n (φ * ψ) = ∑ p ∈ antidiagonal n, 0 by rw [this, Finset.sum_const_zero]
rw [coeff_mul]
apply Finset.sum_congr rfl
intro x hx
refine mul_eq_zero_of_right (coeff R x.fst φ) (coeff_of_lt_order x.snd (lt_of_le_of_lt ?_ h))
rw [mem_antidiagonal] at hx
norm_cast
omega
theorem coeff_mul_one_sub_of_lt_order {R : Type*} [CommRing R] {φ ψ : R⟦X⟧} (n : ℕ)
(h : ↑n < ψ.order) : coeff R n (φ * (1 - ψ)) = coeff R n φ := by
simp [coeff_mul_of_lt_order h, mul_sub]
theorem coeff_mul_prod_one_sub_of_lt_order {R ι : Type*} [CommRing R] (k : ℕ) (s : Finset ι)
(φ : R⟦X⟧) (f : ι → R⟦X⟧) :
(∀ i ∈ s, ↑k < (f i).order) → coeff R k (φ * ∏ i ∈ s, (1 - f i)) = coeff R k φ := by
classical
induction' s using Finset.induction_on with a s ha ih t
· simp
· intro t
simp only [Finset.mem_insert, forall_eq_or_imp] at t
rw [Finset.prod_insert ha, ← mul_assoc, mul_right_comm, coeff_mul_one_sub_of_lt_order _ t.1]
exact ih t.2
-- TODO: link with `X_pow_dvd_iff`
theorem X_pow_order_dvd (h : (order φ).Dom) : X ^ (order φ).get h ∣ φ := by
refine ⟨PowerSeries.mk fun n => coeff R (n + (order φ).get h) φ, ?_⟩
ext n
simp only [coeff_mul, coeff_X_pow, coeff_mk, boole_mul, Finset.sum_ite,
Finset.sum_const_zero, add_zero]
rw [Finset.filter_fst_eq_antidiagonal n (Part.get (order φ) h)]
split_ifs with hn
· simp [tsub_add_cancel_of_le hn]
· simp only [Finset.sum_empty]
refine coeff_of_lt_order _ ?_
simpa [PartENat.coe_lt_iff] using fun _ => hn
theorem order_eq_multiplicity_X {R : Type*} [Semiring R] [@DecidableRel R⟦X⟧ (· ∣ ·)] (φ : R⟦X⟧) :
order φ = multiplicity X φ := by
classical
rcases eq_or_ne φ 0 with (rfl | hφ)
· simp
induction' ho : order φ using PartENat.casesOn with n
· simp [hφ] at ho
have hn : φ.order.get (order_finite_iff_ne_zero.mpr hφ) = n := by simp [ho]
rw [← hn]
refine
le_antisymm (le_multiplicity_of_pow_dvd <| X_pow_order_dvd (order_finite_iff_ne_zero.mpr hφ))
(PartENat.find_le _ _ ?_)
rintro ⟨ψ, H⟩
have := congr_arg (coeff R n) H
rw [← (ψ.commute_X.pow_right _).eq, coeff_mul_of_lt_order, ← hn] at this
· exact coeff_order _ this
· rw [X_pow_eq, order_monomial]
split_ifs
· exact PartENat.natCast_lt_top _
· rw [← hn, PartENat.coe_lt_coe]
exact Nat.lt_succ_self _
/-- Given a non-zero power series `f`, `divided_by_X_pow_order f` is the power series obtained by
dividing out the largest power of X that divides `f`, that is its order-/
def divided_by_X_pow_order {f : PowerSeries R} (hf : f ≠ 0) : R⟦X⟧ :=
(exists_eq_mul_right_of_dvd (X_pow_order_dvd (order_finite_iff_ne_zero.2 hf))).choose
theorem self_eq_X_pow_order_mul_divided_by_X_pow_order {f : R⟦X⟧} (hf : f ≠ 0) :
X ^ f.order.get (order_finite_iff_ne_zero.mpr hf) * divided_by_X_pow_order hf = f :=
haveI dvd := X_pow_order_dvd (order_finite_iff_ne_zero.mpr hf)
(exists_eq_mul_right_of_dvd dvd).choose_spec.symm
end OrderBasic
section OrderZeroNeOne
variable [Semiring R] [Nontrivial R]
/-- The order of the formal power series `1` is `0`. -/
@[simp]
theorem order_one : order (1 : R⟦X⟧) = 0 := by
simpa using order_monomial_of_ne_zero 0 (1 : R) one_ne_zero
/-- The order of an invertible power series is `0`. -/
theorem order_zero_of_unit {f : PowerSeries R} : IsUnit f → f.order = 0 := by
rintro ⟨⟨u, v, hu, hv⟩, hf⟩
apply And.left
rw [← add_eq_zero_iff, ← hf, ← nonpos_iff_eq_zero, ← @order_one R _ _, ← hu]
exact order_mul_ge _ _
/-- The order of the formal power series `X` is `1`. -/
@[simp]
theorem order_X : order (X : R⟦X⟧) = 1 := by
simpa only [Nat.cast_one] using order_monomial_of_ne_zero 1 (1 : R) one_ne_zero
/-- The order of the formal power series `X^n` is `n`. -/
@[simp]
theorem order_X_pow (n : ℕ) : order ((X : R⟦X⟧) ^ n) = n := by
rw [X_pow_eq, order_monomial_of_ne_zero]
exact one_ne_zero
end OrderZeroNeOne
section OrderIsDomain
-- TODO: generalize to `[Semiring R] [NoZeroDivisors R]`
variable [CommRing R] [IsDomain R]
/-- The order of the product of two formal power series over an integral domain
is the sum of their orders. -/
theorem order_mul (φ ψ : R⟦X⟧) : order (φ * ψ) = order φ + order ψ := by
classical
simp_rw [order_eq_multiplicity_X]
exact multiplicity.mul X_prime
-- Dividing `X` by the maximal power of `X` dividing it leaves `1`.
@[simp]
theorem divided_by_X_pow_order_of_X_eq_one : divided_by_X_pow_order X_ne_zero = (1 : R⟦X⟧) := by
rw [← mul_eq_left₀ X_ne_zero]
simpa only [order_X, X_ne_zero, PartENat.get_one, pow_one, Ne, not_false_iff] using
self_eq_X_pow_order_mul_divided_by_X_pow_order (@X_ne_zero R _ _)
-- Dividing a power series by the maximal power of `X` dividing it, respects multiplication.
theorem divided_by_X_pow_orderMul {f g : R⟦X⟧} (hf : f ≠ 0) (hg : g ≠ 0) :
divided_by_X_pow_order hf * divided_by_X_pow_order hg =
divided_by_X_pow_order (mul_ne_zero hf hg) := by
set df := f.order.get (order_finite_iff_ne_zero.mpr hf)
set dg := g.order.get (order_finite_iff_ne_zero.mpr hg)
set dfg := (f * g).order.get (order_finite_iff_ne_zero.mpr (mul_ne_zero hf hg)) with hdfg
have H_add_d : df + dg = dfg := by simp_all only [PartENat.get_add, order_mul f g]
have H := self_eq_X_pow_order_mul_divided_by_X_pow_order (mul_ne_zero hf hg)
have : f * g = X ^ dfg * (divided_by_X_pow_order hf * divided_by_X_pow_order hg) := by
calc
f * g = X ^ df * divided_by_X_pow_order hf * (X ^ dg * divided_by_X_pow_order hg) := by
rw [self_eq_X_pow_order_mul_divided_by_X_pow_order,
self_eq_X_pow_order_mul_divided_by_X_pow_order]
_ = X ^ df * X ^ dg * divided_by_X_pow_order hf * divided_by_X_pow_order hg := by ring
_ = X ^ (df + dg) * divided_by_X_pow_order hf * divided_by_X_pow_order hg := by rw [pow_add]
_ = X ^ dfg * divided_by_X_pow_order hf * divided_by_X_pow_order hg := by rw [H_add_d]
_ = X ^ dfg * (divided_by_X_pow_order hf * divided_by_X_pow_order hg) := by rw [mul_assoc]
simp [← hdfg, this] at H
refine (IsLeftCancelMulZero.mul_left_cancel_of_ne_zero (pow_ne_zero dfg X_ne_zero) ?_).symm
convert H
end OrderIsDomain
end PowerSeries
end
|
RingTheory\PowerSeries\Trunc.lean | /-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Kenny Lau
-/
import Mathlib.Algebra.Polynomial.Coeff
import Mathlib.Algebra.Polynomial.Degree.Lemmas
import Mathlib.RingTheory.PowerSeries.Basic
/-!
# Formal power series in one variable - Truncation
`PowerSeries.trunc n φ` truncates a (univariate) formal power series
to the polynomial that has the same coefficients as `φ`, for all `m < n`,
and `0` otherwise.
-/
noncomputable section
open Polynomial
open Finset (antidiagonal mem_antidiagonal)
namespace PowerSeries
open Finsupp (single)
variable {R : Type*}
section Trunc
variable [Semiring R]
open Finset Nat
/-- The `n`th truncation of a formal power series to a polynomial -/
def trunc (n : ℕ) (φ : R⟦X⟧) : R[X] :=
∑ m ∈ Ico 0 n, Polynomial.monomial m (coeff R m φ)
theorem coeff_trunc (m) (n) (φ : R⟦X⟧) :
(trunc n φ).coeff m = if m < n then coeff R m φ else 0 := by
simp [trunc, Polynomial.coeff_sum, Polynomial.coeff_monomial, Nat.lt_succ_iff]
@[simp]
theorem trunc_zero (n) : trunc n (0 : R⟦X⟧) = 0 :=
Polynomial.ext fun m => by
rw [coeff_trunc, LinearMap.map_zero, Polynomial.coeff_zero]
split_ifs <;> rfl
@[simp]
theorem trunc_one (n) : trunc (n + 1) (1 : R⟦X⟧) = 1 :=
Polynomial.ext fun m => by
rw [coeff_trunc, coeff_one, Polynomial.coeff_one]
split_ifs with h _ h'
· rfl
· rfl
· subst h'; simp at h
· rfl
@[simp]
theorem trunc_C (n) (a : R) : trunc (n + 1) (C R a) = Polynomial.C a :=
Polynomial.ext fun m => by
rw [coeff_trunc, coeff_C, Polynomial.coeff_C]
split_ifs with H <;> first |rfl|try simp_all
@[simp]
theorem trunc_add (n) (φ ψ : R⟦X⟧) : trunc n (φ + ψ) = trunc n φ + trunc n ψ :=
Polynomial.ext fun m => by
simp only [coeff_trunc, AddMonoidHom.map_add, Polynomial.coeff_add]
split_ifs with H
· rfl
· rw [zero_add]
theorem trunc_succ (f : R⟦X⟧) (n : ℕ) :
trunc n.succ f = trunc n f + Polynomial.monomial n (coeff R n f) := by
rw [trunc, Ico_zero_eq_range, sum_range_succ, trunc, Ico_zero_eq_range]
theorem natDegree_trunc_lt (f : R⟦X⟧) (n) : (trunc (n + 1) f).natDegree < n + 1 := by
rw [Nat.lt_succ_iff, natDegree_le_iff_coeff_eq_zero]
intros
rw [coeff_trunc]
split_ifs with h
· rw [lt_succ, ← not_lt] at h
contradiction
· rfl
@[simp] lemma trunc_zero' {f : R⟦X⟧} : trunc 0 f = 0 := rfl
theorem degree_trunc_lt (f : R⟦X⟧) (n) : (trunc n f).degree < n := by
rw [degree_lt_iff_coeff_zero]
intros
rw [coeff_trunc]
split_ifs with h
· rw [← not_le] at h
contradiction
· rfl
theorem eval₂_trunc_eq_sum_range {S : Type*} [Semiring S] (s : S) (G : R →+* S) (n) (f : R⟦X⟧) :
(trunc n f).eval₂ G s = ∑ i ∈ range n, G (coeff R i f) * s ^ i := by
cases n with
| zero =>
rw [trunc_zero', range_zero, sum_empty, eval₂_zero]
| succ n =>
have := natDegree_trunc_lt f n
rw [eval₂_eq_sum_range' (hn := this)]
apply sum_congr rfl
intro _ h
rw [mem_range] at h
congr
rw [coeff_trunc, if_pos h]
@[simp] theorem trunc_X (n) : trunc (n + 2) X = (Polynomial.X : R[X]) := by
ext d
rw [coeff_trunc, coeff_X]
split_ifs with h₁ h₂
· rw [h₂, coeff_X_one]
· rw [coeff_X_of_ne_one h₂]
· rw [coeff_X_of_ne_one]
intro hd
apply h₁
rw [hd]
exact n.one_lt_succ_succ
lemma trunc_X_of {n : ℕ} (hn : 2 ≤ n) : trunc n X = (Polynomial.X : R[X]) := by
cases n with
| zero => contradiction
| succ n =>
cases n with
| zero => contradiction
| succ n => exact trunc_X n
end Trunc
section Trunc
/-
Lemmas in this section involve the coercion `R[X] → R⟦X⟧`, so they may only be stated in the case
`R` is commutative. This is because the coercion is an `R`-algebra map.
-/
variable {R : Type*} [CommSemiring R]
open Nat hiding pow_succ pow_zero
open Polynomial Finset Finset.Nat
theorem trunc_trunc_of_le {n m} (f : R⟦X⟧) (hnm : n ≤ m := by rfl) :
trunc n ↑(trunc m f) = trunc n f := by
ext d
rw [coeff_trunc, coeff_trunc, coeff_coe]
split_ifs with h
· rw [coeff_trunc, if_pos <| lt_of_lt_of_le h hnm]
· rfl
@[simp] theorem trunc_trunc {n} (f : R⟦X⟧) : trunc n ↑(trunc n f) = trunc n f :=
trunc_trunc_of_le f
@[simp] theorem trunc_trunc_mul {n} (f g : R ⟦X⟧) :
trunc n ((trunc n f) * g : R⟦X⟧) = trunc n (f * g) := by
ext m
rw [coeff_trunc, coeff_trunc]
split_ifs with h
· rw [coeff_mul, coeff_mul, sum_congr rfl]
intro _ hab
have ha := lt_of_le_of_lt (antidiagonal.fst_le hab) h
rw [coeff_coe, coeff_trunc, if_pos ha]
· rfl
@[simp] theorem trunc_mul_trunc {n} (f g : R ⟦X⟧) :
trunc n (f * (trunc n g) : R⟦X⟧) = trunc n (f * g) := by
rw [mul_comm, trunc_trunc_mul, mul_comm]
theorem trunc_trunc_mul_trunc {n} (f g : R⟦X⟧) :
trunc n (trunc n f * trunc n g : R⟦X⟧) = trunc n (f * g) := by
rw [trunc_trunc_mul, trunc_mul_trunc]
@[simp] theorem trunc_trunc_pow (f : R⟦X⟧) (n a : ℕ) :
trunc n ((trunc n f : R⟦X⟧) ^ a) = trunc n (f ^ a) := by
induction a with
| zero =>
rw [pow_zero, pow_zero]
| succ a ih =>
rw [_root_.pow_succ', _root_.pow_succ', trunc_trunc_mul,
← trunc_trunc_mul_trunc, ih, trunc_trunc_mul_trunc]
theorem trunc_coe_eq_self {n} {f : R[X]} (hn : natDegree f < n) : trunc n (f : R⟦X⟧) = f := by
rw [← Polynomial.coe_inj]
ext m
rw [coeff_coe, coeff_trunc]
split
case isTrue h => rfl
case isFalse h =>
rw [not_lt] at h
rw [coeff_coe]; symm
exact coeff_eq_zero_of_natDegree_lt <| lt_of_lt_of_le hn h
/-- The function `coeff n : R⟦X⟧ → R` is continuous. I.e. `coeff n f` depends only on a sufficiently
long truncation of the power series `f`. -/
theorem coeff_coe_trunc_of_lt {n m} {f : R⟦X⟧} (h : n < m) :
coeff R n (trunc m f) = coeff R n f := by
rwa [coeff_coe, coeff_trunc, if_pos]
/-- The `n`-th coefficient of `f*g` may be calculated
from the truncations of `f` and `g`. -/
theorem coeff_mul_eq_coeff_trunc_mul_trunc₂ {n a b} (f g) (ha : n < a) (hb : n < b) :
coeff R n (f * g) = coeff R n (trunc a f * trunc b g) := by
symm
rw [← coeff_coe_trunc_of_lt n.lt_succ_self, ← trunc_trunc_mul_trunc, trunc_trunc_of_le f ha,
trunc_trunc_of_le g hb, trunc_trunc_mul_trunc, coeff_coe_trunc_of_lt n.lt_succ_self]
theorem coeff_mul_eq_coeff_trunc_mul_trunc {d n} (f g) (h : d < n) :
coeff R d (f * g) = coeff R d (trunc n f * trunc n g) :=
coeff_mul_eq_coeff_trunc_mul_trunc₂ f g h h
end Trunc
end PowerSeries
end
|
RingTheory\PowerSeries\WellKnown.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.Algebra.Rat
import Mathlib.Algebra.BigOperators.NatAntidiagonal
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Data.Nat.Choose.Sum
import Mathlib.RingTheory.PowerSeries.Basic
/-!
# Definition of well-known power series
In this file we define the following power series:
* `PowerSeries.invUnitsSub`: given `u : Rˣ`, this is the series for `1 / (u - x)`.
It is given by `∑ n, x ^ n /ₚ u ^ (n + 1)`.
* `PowerSeries.invOneSubPow`: given a commutative ring `S` and a number `d : ℕ`,
`PowerSeries.invOneSubPow d : S⟦X⟧ˣ` is the power series `∑ n, Nat.choose (d + n) d`
whose multiplicative inverse is `(1 - X) ^ (d + 1)`.
* `PowerSeries.sin`, `PowerSeries.cos`, `PowerSeries.exp` : power series for sin, cosine, and
exponential functions.
-/
namespace PowerSeries
section Ring
variable {R S : Type*} [Ring R] [Ring S]
/-- The power series for `1 / (u - x)`. -/
def invUnitsSub (u : Rˣ) : PowerSeries R :=
mk fun n => 1 /ₚ u ^ (n + 1)
@[simp]
theorem coeff_invUnitsSub (u : Rˣ) (n : ℕ) : coeff R n (invUnitsSub u) = 1 /ₚ u ^ (n + 1) :=
coeff_mk _ _
@[simp]
theorem constantCoeff_invUnitsSub (u : Rˣ) : constantCoeff R (invUnitsSub u) = 1 /ₚ u := by
rw [← coeff_zero_eq_constantCoeff_apply, coeff_invUnitsSub, zero_add, pow_one]
@[simp]
theorem invUnitsSub_mul_X (u : Rˣ) : invUnitsSub u * X = invUnitsSub u * C R u - 1 := by
ext (_ | n)
· simp
· simp [n.succ_ne_zero, pow_succ']
@[simp]
theorem invUnitsSub_mul_sub (u : Rˣ) : invUnitsSub u * (C R u - X) = 1 := by
simp [mul_sub, sub_sub_cancel]
theorem map_invUnitsSub (f : R →+* S) (u : Rˣ) :
map f (invUnitsSub u) = invUnitsSub (Units.map (f : R →* S) u) := by
ext
simp only [← map_pow, coeff_map, coeff_invUnitsSub, one_divp]
rfl
end Ring
section invOneSubPow
variable {S : Type*} [CommRing S] (d : ℕ)
/--
(1 + X + X^2 + ...) * (1 - X) = 1.
Note that the power series `1 + X + X^2 + ...` is written as `mk 1` where `1` is the constant
function so that `mk 1` is the power series with all coefficients equal to one.
-/
theorem mk_one_mul_one_sub_eq_one : (mk 1 : S⟦X⟧) * (1 - X) = 1 := by
rw [mul_comm, PowerSeries.ext_iff]
intro n
cases n with
| zero => simp
| succ n => simp [sub_mul]
/--
Note that `mk 1` is the constant function `1` so the power series `1 + X + X^2 + ...`. This theorem
states that for any `d : ℕ`, `(1 + X + X^2 + ... : S⟦X⟧) ^ (d + 1)` is equal to the power series
`mk fun n => Nat.choose (d + n) d : S⟦X⟧`.
-/
theorem mk_one_pow_eq_mk_choose_add :
(mk 1 : S⟦X⟧) ^ (d + 1) = (mk fun n => Nat.choose (d + n) d : S⟦X⟧) := by
induction d with
| zero => ext; simp
| succ d hd =>
ext n
rw [pow_add, hd, pow_one, mul_comm, coeff_mul]
simp_rw [coeff_mk, Pi.one_apply, one_mul]
norm_cast
rw [Finset.sum_antidiagonal_choose_add, ← Nat.choose_succ_succ, Nat.succ_eq_add_one,
add_right_comm]
/--
The power series `mk fun n => Nat.choose (d + n) d`, whose multiplicative inverse is
`(1 - X) ^ (d + 1)`.
-/
noncomputable def invOneSubPow : S⟦X⟧ˣ where
val := mk fun n => Nat.choose (d + n) d
inv := (1 - X) ^ (d + 1)
val_inv := by
rw [← mk_one_pow_eq_mk_choose_add, ← mul_pow, mk_one_mul_one_sub_eq_one, one_pow]
inv_val := by
rw [← mk_one_pow_eq_mk_choose_add, ← mul_pow, mul_comm, mk_one_mul_one_sub_eq_one, one_pow]
theorem invOneSubPow_val_eq_mk_choose_add :
(invOneSubPow d).val = (mk fun n => Nat.choose (d + n) d : S⟦X⟧) := rfl
theorem invOneSubPow_val_zero_eq_invUnitSub_one :
(invOneSubPow 0).val = invUnitsSub (1 : Sˣ) := by
simp [invOneSubPow, invUnitsSub]
/--
The theorem `PowerSeries.mk_one_mul_one_sub_eq_one` implies that `1 - X` is a unit in `S⟦X⟧`
whose inverse is the power series `1 + X + X^2 + ...`. This theorem states that for any `d : ℕ`,
`PowerSeries.invOneSubPow d` is equal to `(1 - X)⁻¹ ^ (d + 1)`.
-/
theorem invOneSubPow_eq_inv_one_sub_pow :
invOneSubPow d = (Units.mkOfMulEqOne (1 - X) (mk 1 : S⟦X⟧)
<| Eq.trans (mul_comm _ _) mk_one_mul_one_sub_eq_one)⁻¹ ^ (d + 1) := by
rw [inv_pow]
exact (DivisionMonoid.inv_eq_of_mul _ (invOneSubPow d) <| by
rw [← Units.val_eq_one, Units.val_mul, Units.val_pow_eq_pow_val]
exact (invOneSubPow d).inv_val).symm
theorem invOneSubPow_inv_eq_one_sub_pow :
(invOneSubPow d).inv = (1 - X : S⟦X⟧) ^ (d + 1) := rfl
end invOneSubPow
section Field
variable (A A' : Type*) [Ring A] [Ring A'] [Algebra ℚ A] [Algebra ℚ A']
open Nat
/-- Power series for the exponential function at zero. -/
def exp : PowerSeries A :=
mk fun n => algebraMap ℚ A (1 / n !)
/-- Power series for the sine function at zero. -/
def sin : PowerSeries A :=
mk fun n => if Even n then 0 else algebraMap ℚ A ((-1) ^ (n / 2) / n !)
/-- Power series for the cosine function at zero. -/
def cos : PowerSeries A :=
mk fun n => if Even n then algebraMap ℚ A ((-1) ^ (n / 2) / n !) else 0
variable {A A'} (n : ℕ)
@[simp]
theorem coeff_exp : coeff A n (exp A) = algebraMap ℚ A (1 / n !) :=
coeff_mk _ _
@[simp]
theorem constantCoeff_exp : constantCoeff A (exp A) = 1 := by
rw [← coeff_zero_eq_constantCoeff_apply, coeff_exp]
simp
variable (f : A →+* A')
@[simp]
theorem map_exp : map (f : A →+* A') (exp A) = exp A' := by
ext
simp
@[simp]
theorem map_sin : map f (sin A) = sin A' := by
ext
simp [sin, apply_ite f]
@[simp]
theorem map_cos : map f (cos A) = cos A' := by
ext
simp [cos, apply_ite f]
end Field
open RingHom
open Finset Nat
variable {A : Type*} [CommRing A]
/-- Shows that $e^{aX} * e^{bX} = e^{(a + b)X}$ -/
theorem exp_mul_exp_eq_exp_add [Algebra ℚ A] (a b : A) :
rescale a (exp A) * rescale b (exp A) = rescale (a + b) (exp A) := by
ext n
simp only [coeff_mul, exp, rescale, coeff_mk, MonoidHom.coe_mk, OneHom.coe_mk, coe_mk,
factorial, Nat.sum_antidiagonal_eq_sum_range_succ_mk, add_pow, sum_mul]
apply sum_congr rfl
rintro x hx
suffices
a ^ x * b ^ (n - x) *
(algebraMap ℚ A (1 / ↑x.factorial) * algebraMap ℚ A (1 / ↑(n - x).factorial)) =
a ^ x * b ^ (n - x) * (↑(n.choose x) * (algebraMap ℚ A) (1 / ↑n.factorial))
by convert this using 1 <;> ring
congr 1
rw [← map_natCast (algebraMap ℚ A) (n.choose x), ← map_mul, ← map_mul]
refine RingHom.congr_arg _ ?_
rw [mul_one_div (↑(n.choose x) : ℚ), one_div_mul_one_div]
symm
rw [div_eq_iff, div_mul_eq_mul_div, one_mul, choose_eq_factorial_div_factorial]
· norm_cast
rw [cast_div_charZero]
apply factorial_mul_factorial_dvd_factorial (mem_range_succ_iff.1 hx)
· apply mem_range_succ_iff.1 hx
· rintro h
apply factorial_ne_zero n
rw [cast_eq_zero.1 h]
/-- Shows that $e^{x} * e^{-x} = 1$ -/
theorem exp_mul_exp_neg_eq_one [Algebra ℚ A] : exp A * evalNegHom (exp A) = 1 := by
convert exp_mul_exp_eq_exp_add (1 : A) (-1) <;> simp
/-- Shows that $(e^{X})^k = e^{kX}$. -/
theorem exp_pow_eq_rescale_exp [Algebra ℚ A] (k : ℕ) : exp A ^ k = rescale (k : A) (exp A) := by
induction' k with k h
· simp only [rescale_zero, constantCoeff_exp, Function.comp_apply, map_one, cast_zero, zero_eq,
pow_zero (exp A), coe_comp]
· simpa only [succ_eq_add_one, cast_add, ← exp_mul_exp_eq_exp_add (k : A), ← h, cast_one,
id_apply, rescale_one] using pow_succ (exp A) k
/-- Shows that
$\sum_{k = 0}^{n - 1} (e^{X})^k = \sum_{p = 0}^{\infty} \sum_{k = 0}^{n - 1} \frac{k^p}{p!}X^p$. -/
theorem exp_pow_sum [Algebra ℚ A] (n : ℕ) :
((Finset.range n).sum fun k => exp A ^ k) =
PowerSeries.mk fun p => (Finset.range n).sum
fun k => (k ^ p : A) * algebraMap ℚ A p.factorial⁻¹ := by
simp only [exp_pow_eq_rescale_exp, rescale]
ext
simp only [one_div, coeff_mk, cast_pow, coe_mk, MonoidHom.coe_mk, OneHom.coe_mk,
coeff_exp, factorial, map_sum]
end PowerSeries
|
RingTheory\Regular\IsSMulRegular.lean | /-
Copyright (c) 2024 Brendan Murphy. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Brendan Murphy
-/
import Mathlib.Algebra.Module.Torsion
import Mathlib.RingTheory.Flat.Basic
import Mathlib.RingTheory.Ideal.AssociatedPrime
import Mathlib.RingTheory.QuotSMulTop
/-!
# Lemmas about the `IsSMulRegular` Predicate
For modules over a ring the proposition `IsSMulRegular r M` is equivalent to
`r` being a *non zero-divisor*, i.e. `r • x = 0` only if `x = 0` for `x ∈ M`.
This specific result is `isSMulRegular_iff_smul_eq_zero_imp_eq_zero`.
Lots of results starting from this, especially ones about quotients (which
don't make sense without some algebraic assumptions), are in this file.
We don't pollute the `Mathlib.Algebra.Regular.SMul` file with these because
it's supposed to import a minimal amount of the algebraic hierarchy.
## Tags
module, regular element, commutative algebra
-/
section Congr
variable {R S M N} [Semiring R] [Semiring S] {σ : R →+* S} {σ' : S →+* R}
[RingHomInvPair σ σ'] [RingHomInvPair σ' σ] [AddCommMonoid M] [Module R M]
lemma LinearEquiv.isSMulRegular_congr' [AddCommMonoid N] [Module S N]
(e : M ≃ₛₗ[σ] N) (r : R) : IsSMulRegular M r ↔ IsSMulRegular N (σ r) :=
e.toEquiv.isSMulRegular_congr (e.map_smul' r)
lemma LinearEquiv.isSMulRegular_congr [AddCommMonoid N] [Module R N]
(e : M ≃ₗ[R] N) (r : R) : IsSMulRegular M r ↔ IsSMulRegular N r :=
e.isSMulRegular_congr' r
end Congr
variable {R S M M' M'' : Type*}
lemma IsSMulRegular.submodule [Semiring R] [AddCommMonoid M] [Module R M]
(N : Submodule R M) (r : R) (h : IsSMulRegular M r) : IsSMulRegular N r :=
h.of_injective N.subtype N.injective_subtype
section TensorProduct
open scoped TensorProduct
variable (M) [CommRing R] [AddCommGroup M] [AddCommGroup M']
[Module R M] [Module R M'] [Module.Flat R M] {r : R}
(h : IsSMulRegular M' r)
lemma IsSMulRegular.lTensor : IsSMulRegular (M ⊗[R] M') r :=
have h1 := congrArg DFunLike.coe (LinearMap.lTensor_smul_action M M' r)
h1.subst (Module.Flat.lTensor_preserves_injective_linearMap _ h)
lemma IsSMulRegular.rTensor : IsSMulRegular (M' ⊗[R] M) r :=
have h1 := congrArg DFunLike.coe (LinearMap.rTensor_smul_action M M' r)
h1.subst (Module.Flat.rTensor_preserves_injective_linearMap _ h)
end TensorProduct
lemma isSMulRegular_algebraMap_iff [CommSemiring R] [Semiring S] [Algebra R S]
[AddCommMonoid M] [Module R M] [Module S M] [IsScalarTower R S M] (r : R) :
IsSMulRegular M (algebraMap R S r) ↔ IsSMulRegular M r :=
(Equiv.refl M).isSMulRegular_congr (algebraMap_smul S r)
section Ring
variable (M) [Ring R] [AddCommGroup M] [Module R M]
[AddCommGroup M'] [Module R M'] [AddCommGroup M''] [Module R M'']
(N : Submodule R M) (r : R)
lemma isSMulRegular_iff_smul_eq_zero_imp_eq_zero :
IsSMulRegular M r ↔ ∀ x : M, r • x = 0 → x = 0 :=
Iff.trans (Module.toAddMonoidEnd R M r).ker_eq_bot_iff.symm
<| AddSubgroup.eq_bot_iff_forall _
lemma isSMulRegular_iff_mem_nonZeroSMulDivisors :
IsSMulRegular M r ↔ r ∈ nonZeroSMulDivisors R M :=
isSMulRegular_iff_smul_eq_zero_imp_eq_zero M r
variable {M r}
lemma isSMulRegular_of_smul_eq_zero_imp_eq_zero
(h : ∀ x : M, r • x = 0 → x = 0) : IsSMulRegular M r :=
(isSMulRegular_iff_smul_eq_zero_imp_eq_zero M r).mpr h
variable (r)
lemma isSMulRegular_on_submodule_iff_mem_imp_smul_eq_zero_imp_eq_zero :
IsSMulRegular N r ↔ ∀ x ∈ N, r • x = 0 → x = 0 :=
Iff.trans (isSMulRegular_iff_smul_eq_zero_imp_eq_zero N r) <|
Iff.trans Subtype.forall <| by
simp only [SetLike.mk_smul_mk, AddSubmonoid.mk_eq_zero]
lemma isSMulRegular_on_quot_iff_smul_mem_implies_mem :
IsSMulRegular (M ⧸ N) r ↔ ∀ x : M, r • x ∈ N → x ∈ N :=
Iff.trans (isSMulRegular_iff_smul_eq_zero_imp_eq_zero _ r) <|
Iff.trans N.mkQ_surjective.forall <| by
simp_rw [← map_smul, N.mkQ_apply, Submodule.Quotient.mk_eq_zero]
variable {N r}
lemma mem_of_isSMulRegular_on_quot_of_smul_mem (h1 : IsSMulRegular (M ⧸ N) r)
{x : M} (h2 : r • x ∈ N) : x ∈ N :=
(isSMulRegular_on_quot_iff_smul_mem_implies_mem N r).mp h1 x h2
/-- Given a left exact sequence `0 → M → M' → M''`, if `r` is regular on both
`M` and `M''` it's regular `M'` too. -/
lemma isSMulRegular_of_range_eq_ker {f : M →ₗ[R] M'} {g : M' →ₗ[R] M''}
(hf : Function.Injective f) (hfg : LinearMap.range f = LinearMap.ker g)
(h1 : IsSMulRegular M r) (h2 : IsSMulRegular M'' r) :
IsSMulRegular M' r := by
refine isSMulRegular_of_smul_eq_zero_imp_eq_zero ?_
intro x hx
obtain ⟨y, ⟨⟩⟩ := (congrArg (x ∈ ·) hfg).mpr <| h2.eq_zero_of_smul_eq_zero <|
Eq.trans (g.map_smul r x).symm <| Eq.trans (congrArg _ hx) g.map_zero
refine Eq.trans (congrArg f (h1.eq_zero_of_smul_eq_zero ?_)) f.map_zero
exact hf <| Eq.trans (f.map_smul r y) <| Eq.trans hx f.map_zero.symm
lemma isSMulRegular_of_isSMulRegular_on_submodule_on_quotient
(h1 : IsSMulRegular N r) (h2 : IsSMulRegular (M ⧸ N) r) : IsSMulRegular M r :=
isSMulRegular_of_range_eq_ker N.injective_subtype
(Eq.trans N.range_subtype N.ker_mkQ.symm) h1 h2
end Ring
section CommRing
open Submodule Pointwise
variable (M) [CommRing R] [AddCommGroup M] [Module R M]
[AddCommGroup M'] [Module R M'] [AddCommGroup M''] [Module R M'']
(I : Ideal R) (N : Submodule R M) (r : R)
variable (R) in
lemma biUnion_associatedPrimes_eq_compl_regular [IsNoetherianRing R] :
⋃ p ∈ associatedPrimes R M, p = { r : R | IsSMulRegular M r }ᶜ :=
Eq.trans (biUnion_associatedPrimes_eq_zero_divisors R M) <| by
simp_rw [Set.compl_setOf, isSMulRegular_iff_smul_eq_zero_imp_eq_zero,
not_forall, exists_prop, and_comm]
lemma isSMulRegular_iff_ker_lsmul_eq_bot :
IsSMulRegular M r ↔ LinearMap.ker (LinearMap.lsmul R M r) = ⊥ :=
isSMulRegular_iff_torsionBy_eq_bot M r
variable {M}
lemma isSMulRegular_on_submodule_iff_disjoint_ker_lsmul_submodule :
IsSMulRegular N r ↔ Disjoint (LinearMap.ker (LinearMap.lsmul R M r)) N :=
Iff.trans (isSMulRegular_on_submodule_iff_mem_imp_smul_eq_zero_imp_eq_zero N r) <|
Iff.symm <| Iff.trans disjoint_comm disjoint_def
lemma isSMulRegular_on_quot_iff_lsmul_comap_le :
IsSMulRegular (M ⧸ N) r ↔ N.comap (LinearMap.lsmul R M r) ≤ N :=
isSMulRegular_on_quot_iff_smul_mem_implies_mem N r
lemma isSMulRegular_on_quot_iff_lsmul_comap_eq :
IsSMulRegular (M ⧸ N) r ↔ N.comap (LinearMap.lsmul R M r) = N :=
Iff.trans (isSMulRegular_on_quot_iff_lsmul_comap_le N r) <|
LE.le.le_iff_eq (fun _ => N.smul_mem r)
variable {r}
lemma IsSMulRegular.isSMulRegular_on_quot_iff_smul_top_inf_eq_smul :
IsSMulRegular M r → (IsSMulRegular (M ⧸ N) r ↔ r • ⊤ ⊓ N ≤ r • N) := by
intro (h : Function.Injective (DistribMulAction.toLinearMap R M r))
rw [isSMulRegular_on_quot_iff_lsmul_comap_le, ← map_le_map_iff_of_injective h,
← LinearMap.lsmul_eq_DistribMulAction_toLinearMap,
map_comap_eq, LinearMap.range_eq_map]; rfl
lemma isSMulRegular_of_ker_lsmul_eq_bot
(h : LinearMap.ker (LinearMap.lsmul R M r) = ⊥) :
IsSMulRegular M r :=
(isSMulRegular_iff_ker_lsmul_eq_bot M r).mpr h
variable {N} in
lemma smul_top_inf_eq_smul_of_isSMulRegular_on_quot :
IsSMulRegular (M ⧸ N) r → r • ⊤ ⊓ N ≤ r • N := by
convert map_mono ∘ (isSMulRegular_on_quot_iff_lsmul_comap_le N r).mp using 2
exact Eq.trans (congrArg (· ⊓ N) (map_top _)) (map_comap_eq _ _).symm
-- Who knew this didn't rely on exactness at the right!?
open Function in
lemma QuotSMulTop.map_first_exact_on_four_term_exact_of_isSMulRegular_last
{M'''} [AddCommGroup M'''] [Module R M''']
{r : R} {f₁ : M →ₗ[R] M'} {f₂ : M' →ₗ[R] M''} {f₃ : M'' →ₗ[R] M'''}
(h₁₂ : Exact f₁ f₂) (h₂₃ : Exact f₂ f₃) (h : IsSMulRegular M''' r) :
Exact (map r f₁) (map r f₂) :=
suffices IsSMulRegular (M'' ⧸ LinearMap.range f₂) r by
dsimp [map, mapQLinear]
rw [Exact.exact_mapQ_iff h₁₂, map_pointwise_smul, Submodule.map_top, inf_comm]
exact smul_top_inf_eq_smul_of_isSMulRegular_on_quot this
h.of_injective _ <| LinearMap.ker_eq_bot.mp <|
ker_liftQ_eq_bot' _ _ h₂₃.linearMap_ker_eq.symm
end CommRing
|
RingTheory\Regular\RegularSequence.lean | /-
Copyright (c) 2024 Brendan Murphy. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Brendan Murphy
-/
import Mathlib.RingTheory.Regular.IsSMulRegular
import Mathlib.RingTheory.Artinian
import Mathlib.Logic.Equiv.TransferInstance
import Mathlib.RingTheory.LocalRing.MaximalIdeal.Basic
/-!
# Regular sequences and weakly regular sequences
The notion of a regular sequence is fundamental in commutative algebra.
Properties of regular sequences encode information about singularities of a
ring and regularity of a sequence can be tested homologically.
However the notion of a regular sequence is only really sensible for Noetherian local rings.
TODO: Koszul regular sequences, H_1-regular sequences, quasi-regular sequences, depth.
## Tags
module, regular element, regular sequence, commutative algebra
-/
universe u v
open scoped Pointwise
variable {R S M M₂ M₃ M₄ : Type*}
namespace Ideal
variable [Semiring R] [Semiring S]
/-- The ideal generated by a list of elements. -/
abbrev ofList (rs : List R) := span { r | r ∈ rs }
@[simp] lemma ofList_nil : (ofList [] : Ideal R) = ⊥ :=
have : { r | r ∈ [] } = ∅ := Set.eq_empty_of_forall_not_mem List.not_mem_nil
Eq.trans (congrArg span this) span_empty
@[simp] lemma ofList_append (rs₁ rs₂ : List R) :
ofList (rs₁ ++ rs₂) = ofList rs₁ ⊔ ofList rs₂ :=
have : { r | r ∈ rs₁ ++ rs₂ } = _ := Set.ext (fun _ => List.mem_append)
Eq.trans (congrArg span this) (span_union _ _)
@[simp] lemma ofList_singleton (r : R) : ofList [r] = span {r} :=
congrArg span (Set.ext fun _ => List.mem_singleton)
@[simp] lemma ofList_cons (r : R) (rs : List R) :
ofList (r::rs) = span {r} ⊔ ofList rs :=
Eq.trans (ofList_append [r] rs) (congrArg (· ⊔ _) (ofList_singleton r))
@[simp] lemma map_ofList (f : R →+* S) (rs : List R) :
map f (ofList rs) = ofList (rs.map f) :=
Eq.trans (map_span f { r | r ∈ rs }) <| congrArg span <|
Set.ext (fun _ => List.mem_map.symm)
lemma ofList_cons_smul {R} [CommSemiring R] (r : R) (rs : List R) {M}
[AddCommMonoid M] [Module R M] (N : Submodule R M) :
ofList (r :: rs) • N = r • N ⊔ ofList rs • N := by
rw [ofList_cons, Submodule.sup_smul, Submodule.ideal_span_singleton_smul]
end Ideal
namespace Submodule
lemma smul_top_le_comap_smul_top [CommSemiring R] [AddCommMonoid M]
[AddCommMonoid M₂] [Module R M] [Module R M₂] (I : Ideal R)
(f : M →ₗ[R] M₂) : I • ⊤ ≤ comap f (I • ⊤) :=
map_le_iff_le_comap.mp <| le_of_eq_of_le (map_smul'' _ _ _) <|
smul_mono_right _ le_top
variable (M) [CommRing R] [AddCommGroup M] [AddCommGroup M₂]
[Module R M] [Module R M₂] (r : R) (rs : List R)
/-- The equivalence between M ⧸ (r₀, r₁, …, rₙ)M and (M ⧸ r₀M) ⧸ (r₁, …, rₙ) (M ⧸ r₀M). -/
def quotOfListConsSMulTopEquivQuotSMulTopInner :
(M ⧸ (Ideal.ofList (r :: rs) • ⊤ : Submodule R M)) ≃ₗ[R]
QuotSMulTop r M ⧸ (Ideal.ofList rs • ⊤ : Submodule R (QuotSMulTop r M)) :=
quotEquivOfEq _ _ (Ideal.ofList_cons_smul r rs ⊤) ≪≫ₗ
(quotientQuotientEquivQuotientSup (r • ⊤) (Ideal.ofList rs • ⊤)).symm ≪≫ₗ
quotEquivOfEq _ _ (by rw [map_smul'', map_top, range_mkQ])
/-- The equivalence between M ⧸ (r₀, r₁, …, rₙ)M and (M ⧸ (r₁, …, rₙ)) ⧸ r₀ (M ⧸ (r₁, …, rₙ)). -/
def quotOfListConsSMulTopEquivQuotSMulTopOuter :
(M ⧸ (Ideal.ofList (r :: rs) • ⊤ : Submodule R M)) ≃ₗ[R]
QuotSMulTop r (M ⧸ (Ideal.ofList rs • ⊤ : Submodule R M)) :=
quotEquivOfEq _ _ (Eq.trans (Ideal.ofList_cons_smul r rs ⊤) (sup_comm _ _)) ≪≫ₗ
(quotientQuotientEquivQuotientSup (Ideal.ofList rs • ⊤) (r • ⊤)).symm ≪≫ₗ
quotEquivOfEq _ _ (by rw [map_pointwise_smul, map_top, range_mkQ])
variable {M}
lemma quotOfListConsSMulTopEquivQuotSMulTopInner_naturality (f : M →ₗ[R] M₂) :
(quotOfListConsSMulTopEquivQuotSMulTopInner M₂ r rs).toLinearMap ∘ₗ
mapQ _ _ _ (smul_top_le_comap_smul_top (Ideal.ofList (r :: rs)) f) =
mapQ _ _ _ (smul_top_le_comap_smul_top _ (QuotSMulTop.map r f)) ∘ₗ
(quotOfListConsSMulTopEquivQuotSMulTopInner M r rs).toLinearMap :=
quot_hom_ext _ _ _ fun _ => rfl
lemma top_eq_ofList_cons_smul_iff :
(⊤ : Submodule R M) = Ideal.ofList (r :: rs) • ⊤ ↔
(⊤ : Submodule R (QuotSMulTop r M)) = Ideal.ofList rs • ⊤ := by
conv => congr <;> rw [eq_comm, ← subsingleton_quotient_iff_eq_top]
exact (quotOfListConsSMulTopEquivQuotSMulTopInner M r rs).toEquiv.subsingleton_congr
end Submodule
namespace RingTheory.Sequence
open scoped TensorProduct List
open Function Submodule QuotSMulTop
variable (S M)
section Definitions
/-
In theory, regularity of `rs : List α` on `M` makes sense as soon as
`[Monoid α]`, `[AddCommGroup M]`, and `[DistribMulAction α M]`.
Instead of `Ideal.ofList (rs.take i) • (⊤ : Submodule R M)` we use
`⨆ (j : Fin i), rs[j] • (⊤ : AddSubgroup M)`.
However it's not clear that this is a useful generalization.
If we add the assumption `[SMulCommClass α α M]` this is essentially the same
as focusing on the commutative ring case, by passing to the monoid ring
`ℤ[abelianization of α]`.
-/
variable [CommRing R] [AddCommGroup M] [Module R M]
open Ideal
/-- A sequence `[r₁, …, rₙ]` is weakly regular on `M` iff `rᵢ` is regular on
`M⧸(r₁, …, rᵢ₋₁)M` for all `1 ≤ i ≤ n`. -/
@[mk_iff]
structure IsWeaklyRegular (rs : List R) : Prop where
regular_mod_prev : ∀ i (h : i < rs.length),
IsSMulRegular (M ⧸ (ofList (rs.take i) • ⊤ : Submodule R M)) rs[i]
lemma isWeaklyRegular_iff_Fin (rs : List R) :
IsWeaklyRegular M rs ↔ ∀ (i : Fin rs.length),
IsSMulRegular (M ⧸ (ofList (rs.take i) • ⊤ : Submodule R M)) (rs.get i) :=
Iff.trans (isWeaklyRegular_iff M rs) (Iff.symm Fin.forall_iff)
/-- A weakly regular sequence `rs` on `M` is regular if also `M/rsM ≠ 0`. -/
@[mk_iff]
structure IsRegular (rs : List R) extends IsWeaklyRegular M rs : Prop where
top_ne_smul : (⊤ : Submodule R M) ≠ Ideal.ofList rs • ⊤
end Definitions
section Congr
variable {S M} [CommRing R] [CommRing S] [AddCommGroup M] [AddCommGroup M₂]
[Module R M] [Module R M₂] [Module S M₂]
{σ : R →+* S} {σ' : S →+* R} [RingHomInvPair σ σ'] [RingHomInvPair σ' σ]
open DistribMulAction AddSubgroup in
private lemma _root_.AddHom.map_smul_top_toAddSubgroup_of_surjective
{f : M →+ M₂} {as : List R} {bs : List S} (hf : Function.Surjective f)
(h : List.Forall₂ (fun r s => ∀ x, f (r • x) = s • f x) as bs) :
(Ideal.ofList as • ⊤ : Submodule R M).toAddSubgroup.map f =
(Ideal.ofList bs • ⊤ : Submodule S M₂).toAddSubgroup := by
induction h with
| nil =>
convert AddSubgroup.map_bot f using 1 <;>
rw [Ideal.ofList_nil, bot_smul, bot_toAddSubgroup]
| @cons r s _ _ h _ ih =>
conv => congr <;> rw [Ideal.ofList_cons, sup_smul, sup_toAddSubgroup,
ideal_span_singleton_smul, pointwise_smul_toAddSubgroup,
top_toAddSubgroup, pointwise_smul_def]
apply DFunLike.ext (f.comp (toAddMonoidEnd R M r))
((toAddMonoidEnd S M₂ s).comp f) at h
rw [AddSubgroup.map_sup, ih, map_map, h, ← map_map,
map_top_of_surjective f hf]
lemma _root_.AddEquiv.isWeaklyRegular_congr {e : M ≃+ M₂} {as bs}
(h : List.Forall₂ (fun (r : R) (s : S) => ∀ x, e (r • x) = s • e x) as bs) :
IsWeaklyRegular M as ↔ IsWeaklyRegular M₂ bs := by
conv => congr <;> rw [isWeaklyRegular_iff_Fin]
let e' i : (M ⧸ (Ideal.ofList (as.take i) • ⊤ : Submodule R M)) ≃+
M₂ ⧸ (Ideal.ofList (bs.take i) • ⊤ : Submodule S M₂) :=
QuotientAddGroup.congr _ _ e <|
AddHom.map_smul_top_toAddSubgroup_of_surjective e.surjective <|
List.forall₂_take i h
refine (finCongr h.length_eq).forall_congr @fun _ => (e' _).isSMulRegular_congr ?_
exact (mkQ_surjective _).forall.mpr fun _ => congrArg (mkQ _) (h.get _ _ _)
lemma _root_.LinearEquiv.isWeaklyRegular_congr' (e : M ≃ₛₗ[σ] M₂) (rs : List R) :
IsWeaklyRegular M rs ↔ IsWeaklyRegular M₂ (rs.map σ) :=
e.toAddEquiv.isWeaklyRegular_congr <| List.forall₂_map_right_iff.mpr <|
List.forall₂_same.mpr fun r _ x => e.map_smul' r x
lemma _root_.LinearEquiv.isWeaklyRegular_congr (e : M ≃ₗ[R] M₂) (rs : List R) :
IsWeaklyRegular M rs ↔ IsWeaklyRegular M₂ rs :=
Iff.trans (e.isWeaklyRegular_congr' rs) <| iff_of_eq <| congrArg _ rs.map_id
lemma _root_.AddEquiv.isRegular_congr {e : M ≃+ M₂} {as bs}
(h : List.Forall₂ (fun (r : R) (s : S) => ∀ x, e (r • x) = s • e x) as bs) :
IsRegular M as ↔ IsRegular M₂ bs := by
conv => congr <;> rw [isRegular_iff, ne_eq, eq_comm,
← subsingleton_quotient_iff_eq_top]
let e' := QuotientAddGroup.congr _ _ e <|
AddHom.map_smul_top_toAddSubgroup_of_surjective e.surjective h
exact and_congr (e.isWeaklyRegular_congr h) e'.subsingleton_congr.not
lemma _root_.LinearEquiv.isRegular_congr' (e : M ≃ₛₗ[σ] M₂) (rs : List R) :
IsRegular M rs ↔ IsRegular M₂ (rs.map σ) :=
e.toAddEquiv.isRegular_congr <| List.forall₂_map_right_iff.mpr <|
List.forall₂_same.mpr fun r _ x => e.map_smul' r x
lemma _root_.LinearEquiv.isRegular_congr (e : M ≃ₗ[R] M₂) (rs : List R) :
IsRegular M rs ↔ IsRegular M₂ rs :=
Iff.trans (e.isRegular_congr' rs) <| iff_of_eq <| congrArg _ rs.map_id
end Congr
lemma isWeaklyRegular_map_algebraMap_iff [CommRing R] [CommRing S]
[Algebra R S] [AddCommGroup M] [Module R M] [Module S M]
[IsScalarTower R S M] (rs : List R) :
IsWeaklyRegular M (rs.map (algebraMap R S)) ↔ IsWeaklyRegular M rs :=
(AddEquiv.refl M).isWeaklyRegular_congr <| List.forall₂_map_left_iff.mpr <|
List.forall₂_same.mpr fun r _ => algebraMap_smul S r
variable [CommRing R] [AddCommGroup M] [AddCommGroup M₂] [AddCommGroup M₃]
[AddCommGroup M₄] [Module R M] [Module R M₂] [Module R M₃] [Module R M₄]
@[simp]
lemma isWeaklyRegular_cons_iff (r : R) (rs : List R) :
IsWeaklyRegular M (r :: rs) ↔
IsSMulRegular M r ∧ IsWeaklyRegular (QuotSMulTop r M) rs :=
have := Eq.trans (congrArg (· • ⊤) Ideal.ofList_nil) (bot_smul ⊤)
let e i := quotOfListConsSMulTopEquivQuotSMulTopInner M r (rs.take i)
Iff.trans (isWeaklyRegular_iff_Fin _ _) <| Iff.trans Fin.forall_fin_succ <|
and_congr ((quotEquivOfEqBot _ this).isSMulRegular_congr r) <|
Iff.trans (forall_congr' fun i => (e i).isSMulRegular_congr (rs.get i))
(isWeaklyRegular_iff_Fin _ _).symm
lemma isWeaklyRegular_cons_iff' (r : R) (rs : List R) :
IsWeaklyRegular M (r :: rs) ↔
IsSMulRegular M r ∧
IsWeaklyRegular (QuotSMulTop r M)
(rs.map (Ideal.Quotient.mk (Ideal.span {r}))) :=
Iff.trans (isWeaklyRegular_cons_iff M r rs) <| and_congr_right' <|
Iff.symm <| isWeaklyRegular_map_algebraMap_iff (R ⧸ Ideal.span {r}) _ rs
@[simp]
lemma isRegular_cons_iff (r : R) (rs : List R) :
IsRegular M (r :: rs) ↔
IsSMulRegular M r ∧ IsRegular (QuotSMulTop r M) rs := by
rw [isRegular_iff, isRegular_iff, isWeaklyRegular_cons_iff M r rs,
ne_eq, top_eq_ofList_cons_smul_iff, and_assoc]
lemma isRegular_cons_iff' (r : R) (rs : List R) :
IsRegular M (r :: rs) ↔
IsSMulRegular M r ∧ IsRegular (QuotSMulTop r M)
(rs.map (Ideal.Quotient.mk (Ideal.span {r}))) := by
conv => congr <;> rw [isRegular_iff, ne_eq]
rw [isWeaklyRegular_cons_iff', ← restrictScalars_inj R (R ⧸ _),
← Ideal.map_ofList, ← Ideal.Quotient.algebraMap_eq, Ideal.smul_restrictScalars,
restrictScalars_top, top_eq_ofList_cons_smul_iff, and_assoc]
variable {M}
namespace IsWeaklyRegular
variable (R M) in
@[simp] lemma nil : IsWeaklyRegular M ([] : List R) :=
.mk (False.elim <| Nat.not_lt_zero · ·)
lemma cons {r : R} {rs : List R} (h1 : IsSMulRegular M r)
(h2 : IsWeaklyRegular (QuotSMulTop r M) rs) : IsWeaklyRegular M (r :: rs) :=
(isWeaklyRegular_cons_iff M r rs).mpr ⟨h1, h2⟩
lemma cons' {r : R} {rs : List R} (h1 : IsSMulRegular M r)
(h2 : IsWeaklyRegular (QuotSMulTop r M)
(rs.map (Ideal.Quotient.mk (Ideal.span {r})))) :
IsWeaklyRegular M (r :: rs) :=
(isWeaklyRegular_cons_iff' M r rs).mpr ⟨h1, h2⟩
/-- Weakly regular sequences can be inductively characterized by:
* The empty sequence is weakly regular on any module.
* If `r` is regular on `M` and `rs` is a weakly regular sequence on `M⧸rM` then
the sequence obtained from `rs` by prepending `r` is weakly regular on `M`.
This is the induction principle produced by the inductive definition above.
The motive will usually be valued in `Prop`, but `Sort*` works too. -/
@[induction_eliminator]
def recIterModByRegular
{motive : (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) →
IsWeaklyRegular M rs → Sort*}
(nil : (M : Type v) → [AddCommGroup M] → [Module R M] → motive M [] (nil R M))
(cons : {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) →
(rs : List R) → (h1 : IsSMulRegular M r) →
(h2 : IsWeaklyRegular (QuotSMulTop r M) rs) →
(ih : motive (QuotSMulTop r M) rs h2) → motive M (r :: rs) (cons h1 h2)) :
{M : Type v} → [AddCommGroup M] → [Module R M] → {rs : List R} →
(h : IsWeaklyRegular M rs) → motive M rs h
| M, _, _, [], _ => nil M
| M, _, _, r :: rs, h =>
let ⟨h1, h2⟩ := (isWeaklyRegular_cons_iff M r rs).mp h
cons r rs h1 h2 (recIterModByRegular nil cons h2)
/-- A simplified version of `IsWeaklyRegular.recIterModByRegular` where the
motive is not allowed to depend on the proof of `IsWeaklyRegular`. -/
def ndrecIterModByRegular
{motive : (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → Sort*}
(nil : (M : Type v) → [AddCommGroup M] → [Module R M] → motive M [])
(cons : {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) →
(rs : List R) → IsSMulRegular M r → IsWeaklyRegular (QuotSMulTop r M) rs →
motive (QuotSMulTop r M) rs → motive M (r :: rs))
{M} [AddCommGroup M] [Module R M] {rs} :
IsWeaklyRegular M rs → motive M rs :=
recIterModByRegular (motive := fun M _ _ rs _ => motive M rs) nil cons
/-- An alternate induction principle from `IsWeaklyRegular.recIterModByRegular`
where we mod out by successive elements in both the module and the base ring.
This is useful for propogating certain properties of the initial `M`, e.g.
faithfulness or freeness, throughout the induction. -/
def recIterModByRegularWithRing
{motive : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] →
[Module R M] → (rs : List R) → IsWeaklyRegular M rs → Sort*}
(nil : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] →
[Module R M] → motive R M [] (nil R M))
(cons : {R : Type u} → [CommRing R] → {M : Type v} → [AddCommGroup M] →
[Module R M] → (r : R) → (rs : List R) → (h1 : IsSMulRegular M r) →
(h2 : IsWeaklyRegular (QuotSMulTop r M)
(rs.map (Ideal.Quotient.mk (Ideal.span {r})))) →
(ih : motive (R⧸Ideal.span {r}) (QuotSMulTop r M)
(rs.map (Ideal.Quotient.mk (Ideal.span {r}))) h2) →
motive R M (r :: rs) (cons' h1 h2)) :
{R : Type u} → [CommRing R] → {M : Type v} → [AddCommGroup M] →
[Module R M] → {rs : List R} → (h : IsWeaklyRegular M rs) → motive R M rs h
| R, _, M, _, _, [], _ => nil R M
| R, _, M, _, _, r :: rs, h =>
let ⟨h1, h2⟩ := (isWeaklyRegular_cons_iff' M r rs).mp h
cons r rs h1 h2 (recIterModByRegularWithRing nil cons h2)
termination_by _ _ _ _ _ rs => List.length rs
/-- A simplified version of `IsWeaklyRegular.recIterModByRegularWithRing` where
the motive is not allowed to depend on the proof of `IsWeaklyRegular`. -/
def ndrecWithRing
{motive : (R : Type u) → [CommRing R] → (M : Type v) →
[AddCommGroup M] → [Module R M] → (rs : List R) → Sort*}
(nil : (R : Type u) → [CommRing R] → (M : Type v) →
[AddCommGroup M] → [Module R M] → motive R M [])
(cons : {R : Type u} → [CommRing R] → {M : Type v} → [AddCommGroup M] →
[Module R M] → (r : R) → (rs : List R) → IsSMulRegular M r →
IsWeaklyRegular (QuotSMulTop r M)
(rs.map (Ideal.Quotient.mk (Ideal.span {r}))) →
motive (R⧸Ideal.span {r}) (QuotSMulTop r M)
(rs.map (Ideal.Quotient.mk (Ideal.span {r}))) → motive R M (r :: rs))
{R} [CommRing R] {M} [AddCommGroup M] [Module R M] {rs} :
IsWeaklyRegular M rs → motive R M rs :=
recIterModByRegularWithRing (motive := fun R _ M _ _ rs _ => motive R M rs)
nil cons
end IsWeaklyRegular
section
variable (M)
lemma isWeaklyRegular_singleton_iff (r : R) :
IsWeaklyRegular M [r] ↔ IsSMulRegular M r :=
Iff.trans (isWeaklyRegular_cons_iff M r []) (and_iff_left (.nil R _))
lemma isWeaklyRegular_append_iff (rs₁ rs₂ : List R) :
IsWeaklyRegular M (rs₁ ++ rs₂) ↔
IsWeaklyRegular M rs₁ ∧
IsWeaklyRegular (M ⧸ (Ideal.ofList rs₁ • ⊤ : Submodule R M)) rs₂ := by
induction rs₁ generalizing M with
| nil =>
refine Iff.symm <| Iff.trans (and_iff_right (.nil R M)) ?_
refine (quotEquivOfEqBot _ ?_).isWeaklyRegular_congr rs₂
rw [Ideal.ofList_nil, bot_smul]
| cons r rs₁ ih =>
let e := quotOfListConsSMulTopEquivQuotSMulTopInner M r rs₁
rw [List.cons_append, isWeaklyRegular_cons_iff, isWeaklyRegular_cons_iff,
ih, ← and_assoc, ← e.isWeaklyRegular_congr rs₂]
lemma isWeaklyRegular_append_iff' (rs₁ rs₂ : List R) :
IsWeaklyRegular M (rs₁ ++ rs₂) ↔
IsWeaklyRegular M rs₁ ∧
IsWeaklyRegular (M ⧸ (Ideal.ofList rs₁ • ⊤ : Submodule R M))
(rs₂.map (Ideal.Quotient.mk (Ideal.ofList rs₁))) :=
Iff.trans (isWeaklyRegular_append_iff M rs₁ rs₂) <| and_congr_right' <|
Iff.symm <| isWeaklyRegular_map_algebraMap_iff (R ⧸ Ideal.ofList rs₁) _ rs₂
end
namespace IsRegular
variable (R M) in
lemma nil [Nontrivial M] : IsRegular M ([] : List R) where
toIsWeaklyRegular := IsWeaklyRegular.nil R M
top_ne_smul h := by
rw [Ideal.ofList_nil, bot_smul, eq_comm, subsingleton_iff_bot_eq_top] at h
exact not_subsingleton M ((Submodule.subsingleton_iff _).mp h)
lemma cons {r : R} {rs : List R} (h1 : IsSMulRegular M r)
(h2 : IsRegular (QuotSMulTop r M) rs) : IsRegular M (r :: rs) :=
(isRegular_cons_iff M r rs).mpr ⟨h1, h2⟩
lemma cons' {r : R} {rs : List R} (h1 : IsSMulRegular M r)
(h2 : IsRegular (QuotSMulTop r M) (rs.map (Ideal.Quotient.mk (Ideal.span {r})))) :
IsRegular M (r :: rs) :=
(isRegular_cons_iff' M r rs).mpr ⟨h1, h2⟩
/-- Regular sequences can be inductively characterized by:
* The empty sequence is regular on any nonzero module.
* If `r` is regular on `M` and `rs` is a regular sequence on `M⧸rM` then the
sequence obtained from `rs` by prepending `r` is regular on `M`.
This is the induction principle produced by the inductive definition above.
The motive will usually be valued in `Prop`, but `Sort*` works too. -/
@[induction_eliminator]
def recIterModByRegular
{motive : (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) →
IsRegular M rs → Sort*}
(nil : (M : Type v) → [AddCommGroup M] → [Module R M] → [Nontrivial M] →
motive M [] (nil R M))
(cons : {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) →
(rs : List R) → (h1 : IsSMulRegular M r) → (h2 : IsRegular (QuotSMulTop r M) rs) →
(ih : motive (QuotSMulTop r M) rs h2) → motive M (r :: rs) (cons h1 h2))
{M} [AddCommGroup M] [Module R M] {rs} (h : IsRegular M rs) : motive M rs h :=
h.toIsWeaklyRegular.recIterModByRegular
(motive := fun N _ _ rs' h' => ∀ h'', motive N rs' ⟨h', h''⟩)
(fun N _ _ h' =>
haveI := (nontrivial_iff R).mp (nontrivial_of_ne _ _ h'); nil N)
(fun r rs' h1 h2 h3 h4 =>
have ⟨h5, h6⟩ := (isRegular_cons_iff _ _ _).mp ⟨h2.cons h1, h4⟩
cons r rs' h5 h6 (h3 h6.top_ne_smul))
h.top_ne_smul
/-- A simplified version of `IsRegular.recIterModByRegular` where the motive is
not allowed to depend on the proof of `IsRegular`. -/
def ndrecIterModByRegular
{motive : (M : Type v) → [AddCommGroup M] → [Module R M] → (rs : List R) → Sort*}
(nil : (M : Type v) → [AddCommGroup M] → [Module R M] → [Nontrivial M] → motive M [])
(cons : {M : Type v} → [AddCommGroup M] → [Module R M] → (r : R) →
(rs : List R) → IsSMulRegular M r → IsRegular (QuotSMulTop r M) rs →
motive (QuotSMulTop r M) rs → motive M (r :: rs))
{M} [AddCommGroup M] [Module R M] {rs} : IsRegular M rs → motive M rs :=
recIterModByRegular (motive := fun M _ _ rs _ => motive M rs) nil cons
/-- An alternate induction principle from `IsRegular.recIterModByRegular` where
we mod out by successive elements in both the module and the base ring. This is
useful for propogating certain properties of the initial `M`, e.g. faithfulness
or freeness, throughout the induction. -/
def recIterModByRegularWithRing
{motive : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] →
[Module R M] → (rs : List R) → IsRegular M rs → Sort*}
(nil : (R : Type u) → [CommRing R] → (M : Type v) → [AddCommGroup M] →
[Module R M] → [Nontrivial M] → motive R M [] (nil R M))
(cons : {R : Type u} → [CommRing R] → {M : Type v} → [AddCommGroup M] →
[Module R M] → (r : R) → (rs : List R) → (h1 : IsSMulRegular M r) →
(h2 : IsRegular (QuotSMulTop r M)
(rs.map (Ideal.Quotient.mk (Ideal.span {r})))) →
(ih : motive (R⧸Ideal.span {r}) (QuotSMulTop r M)
(rs.map (Ideal.Quotient.mk (Ideal.span {r}))) h2) →
motive R M (r :: rs) (cons' h1 h2))
{R} [CommRing R] {M} [AddCommGroup M] [Module R M] {rs}
(h : IsRegular M rs) : motive R M rs h :=
h.toIsWeaklyRegular.recIterModByRegularWithRing
(motive := fun R _ N _ _ rs' h' => ∀ h'', motive R N rs' ⟨h', h''⟩)
(fun R _ N _ _ h' =>
haveI := (nontrivial_iff R).mp (nontrivial_of_ne _ _ h'); nil R N)
(fun r rs' h1 h2 h3 h4 =>
have ⟨h5, h6⟩ := (isRegular_cons_iff' _ _ _).mp ⟨h2.cons' h1, h4⟩
cons r rs' h5 h6 <| h3 h6.top_ne_smul)
h.top_ne_smul
/-- A simplified version of `IsRegular.recIterModByRegularWithRing` where the
motive is not allowed to depend on the proof of `IsRegular`. -/
def ndrecIterModByRegularWithRing
{motive : (R : Type u) → [CommRing R] → (M : Type v) →
[AddCommGroup M] → [Module R M] → (rs : List R) → Sort*}
(nil : (R : Type u) → [CommRing R] → (M : Type v) →
[AddCommGroup M] → [Module R M] → [Nontrivial M] → motive R M [])
(cons : {R : Type u} → [CommRing R] → {M : Type v} →
[AddCommGroup M] → [Module R M] → (r : R) → (rs : List R) →
IsSMulRegular M r →
IsRegular (QuotSMulTop r M)
(rs.map (Ideal.Quotient.mk (Ideal.span {r}))) →
motive (R⧸Ideal.span {r}) (QuotSMulTop r M)
(rs.map (Ideal.Quotient.mk (Ideal.span {r}))) →
motive R M (r :: rs))
{R} [CommRing R] {M} [AddCommGroup M] [Module R M] {rs} :
IsRegular M rs → motive R M rs :=
recIterModByRegularWithRing (motive := fun R _ M _ _ rs _ => motive R M rs)
nil cons
lemma quot_ofList_smul_nontrivial {rs : List R} (h : IsRegular M rs)
(N : Submodule R M) : Nontrivial (M ⧸ Ideal.ofList rs • N) :=
Submodule.Quotient.nontrivial_of_lt_top _ <|
lt_of_le_of_lt (smul_mono_right _ le_top) h.top_ne_smul.symm.lt_top
lemma nontrivial {rs : List R} (h : IsRegular M rs) : Nontrivial M :=
haveI := quot_ofList_smul_nontrivial h ⊤
(mkQ_surjective (Ideal.ofList rs • ⊤ : Submodule R M)).nontrivial
end IsRegular
lemma isRegular_iff_isWeaklyRegular_of_subset_jacobson_annihilator
[Nontrivial M] [Module.Finite R M] {rs : List R}
(h : ∀ r ∈ rs, r ∈ Ideal.jacobson (Module.annihilator R M)) :
IsRegular M rs ↔ IsWeaklyRegular M rs :=
Iff.trans (isRegular_iff M rs) <| and_iff_left <|
top_ne_ideal_smul_of_le_jacobson_annihilator <| Ideal.span_le.mpr h
lemma _root_.LocalRing.isRegular_iff_isWeaklyRegular_of_subset_maximalIdeal
[LocalRing R] [Nontrivial M] [Module.Finite R M] {rs : List R}
(h : ∀ r ∈ rs, r ∈ LocalRing.maximalIdeal R) :
IsRegular M rs ↔ IsWeaklyRegular M rs :=
have H h' := bot_ne_top.symm <| annihilator_eq_top_iff.mp <|
Eq.trans annihilator_top h'
isRegular_iff_isWeaklyRegular_of_subset_jacobson_annihilator fun r hr =>
LocalRing.jacobson_eq_maximalIdeal (Module.annihilator R M) H ▸ h r hr
open IsWeaklyRegular IsArtinian in
lemma eq_nil_of_isRegular_on_artinian [IsArtinian R M] :
{rs : List R} → IsRegular M rs → rs = []
| [], _ => rfl
| r :: rs, h => by
rw [isRegular_iff, ne_comm, ← lt_top_iff_ne_top, Ideal.ofList_cons,
sup_smul, ideal_span_singleton_smul, isWeaklyRegular_cons_iff] at h
refine absurd ?_ (ne_of_lt (lt_of_le_of_lt le_sup_left h.right))
exact Eq.trans (Submodule.map_top _) <| LinearMap.range_eq_top.mpr <|
surjective_of_injective_endomorphism (LinearMap.lsmul R M r) h.left.left
lemma IsWeaklyRegular.isWeaklyRegular_lTensor [Module.Flat R M₂]
{rs : List R} (h : IsWeaklyRegular M rs) :
IsWeaklyRegular (M₂ ⊗[R] M) rs := by
induction h with
| nil N => exact nil R (M₂ ⊗[R] N)
| @cons N _ _ r rs' h1 _ ih =>
let e := tensorQuotSMulTopEquivQuotSMulTop r M₂ N
exact ((e.isWeaklyRegular_congr rs').mp ih).cons (h1.lTensor M₂)
lemma IsWeaklyRegular.isWeaklyRegular_rTensor [Module.Flat R M₂]
{rs : List R} (h : IsWeaklyRegular M rs) :
IsWeaklyRegular (M ⊗[R] M₂) rs := by
induction h with
| nil N => exact nil R (N ⊗[R] M₂)
| @cons N _ _ r rs' h1 _ ih =>
let e := quotSMulTopTensorEquivQuotSMulTop r M₂ N
exact ((e.isWeaklyRegular_congr rs').mp ih).cons (h1.rTensor M₂)
-- TODO: apply the above to localization and completion (Corollary 1.1.3 in B&H)
lemma map_first_exact_on_four_term_right_exact_of_isSMulRegular_last
{rs : List R} {f₁ : M →ₗ[R] M₂} {f₂ : M₂ →ₗ[R] M₃} {f₃ : M₃ →ₗ[R] M₄}
(h₁₂ : Exact f₁ f₂) (h₂₃ : Exact f₂ f₃) (h₃ : Surjective f₃)
(h₄ : IsWeaklyRegular M₄ rs) :
Exact (mapQ _ _ _ (smul_top_le_comap_smul_top (Ideal.ofList rs) f₁))
(mapQ _ _ _ (smul_top_le_comap_smul_top (Ideal.ofList rs) f₂)) := by
induction' h₄ with _ _ _ N _ _ r rs h₄ _ ih generalizing M M₂ M₃
· apply (Exact.iff_of_ladder_linearEquiv ?_ ?_).mp h₁₂
any_goals exact quotEquivOfEqBot _ <|
Eq.trans (congrArg (· • ⊤) Ideal.ofList_nil) (bot_smul ⊤)
all_goals exact quot_hom_ext _ _ _ fun _ => rfl
· specialize ih
(map_first_exact_on_four_term_exact_of_isSMulRegular_last h₁₂ h₂₃ h₄)
(map_exact r h₂₃ h₃) (map_surjective r h₃)
have H₁ := quotOfListConsSMulTopEquivQuotSMulTopInner_naturality r rs f₁
have H₂ := quotOfListConsSMulTopEquivQuotSMulTopInner_naturality r rs f₂
exact (Exact.iff_of_ladder_linearEquiv H₁.symm H₂.symm).mp ih
-- todo: modding out a complex by a regular sequence (prop 1.1.5 in B&H)
section Perm
open LinearMap in
private lemma IsWeaklyRegular.swap {a b : R} (h1 : IsWeaklyRegular M [a, b])
(h2 : torsionBy R M b = a • torsionBy R M b → torsionBy R M b = ⊥) :
IsWeaklyRegular M [b, a] := by
rw [isWeaklyRegular_cons_iff, isWeaklyRegular_singleton_iff] at h1 ⊢
obtain ⟨ha, hb⟩ := h1
rw [← isSMulRegular_iff_torsionBy_eq_bot] at h2
specialize h2 (le_antisymm ?_ (smul_le_self_of_tower a (torsionBy R M b)))
· refine le_of_eq_of_le ?_ <| smul_top_inf_eq_smul_of_isSMulRegular_on_quot <|
ha.of_injective _ <| ker_eq_bot.mp <| ker_liftQ_eq_bot' _ (lsmul R M b) rfl
rw [← (isSMulRegular_on_quot_iff_lsmul_comap_eq _ _).mp hb]
exact (inf_eq_right.mpr (ker_le_comap _)).symm
· rwa [ha.isSMulRegular_on_quot_iff_smul_top_inf_eq_smul, inf_comm, smul_comm,
← h2.isSMulRegular_on_quot_iff_smul_top_inf_eq_smul, and_iff_left hb]
-- TODO: Equivalence of permutability of regular sequences to regularity of
-- subsequences and regularity on poly ring. See [07DW] in stacks project
-- We need a theory of multivariate polynomial modules first
-- This is needed due to a bug in the linter
set_option linter.unusedVariables false in
lemma IsWeaklyRegular.prototype_perm {rs : List R} (h : IsWeaklyRegular M rs)
{rs'} (h'' : rs ~ rs') (h' : ∀ a b rs', (a :: b :: rs') <+~ rs →
let K := torsionBy R (M ⧸ (Ideal.ofList rs' • ⊤ : Submodule R M)) b
K = a • K → K = ⊥) : IsWeaklyRegular M rs' :=
have H := LinearEquiv.isWeaklyRegular_congr <| quotEquivOfEqBot _ <|
Eq.trans (congrArg (· • ⊤) Ideal.ofList_nil) (bot_smul ⊤)
(H rs').mp <| (aux [] h'' (.refl rs) (h''.symm.subperm)) <| (H rs).mpr h
where aux {rs₁ rs₂} (rs₀ : List R)
(h₁₂ : rs₁ ~ rs₂) (H₁ : rs₀ ++ rs₁ <+~ rs) (H₃ : rs₀ ++ rs₂ <+~ rs)
(h : IsWeaklyRegular (M ⧸ (Ideal.ofList rs₀ • ⊤ : Submodule R M)) rs₁) :
IsWeaklyRegular (M ⧸ (Ideal.ofList rs₀ • ⊤ : Submodule R M)) rs₂ := by {
induction h₁₂ generalizing rs₀ with
| nil => exact .nil R _
| cons r _ ih =>
let e := quotOfListConsSMulTopEquivQuotSMulTopOuter M r rs₀
rw [isWeaklyRegular_cons_iff, ← e.isWeaklyRegular_congr] at h ⊢
refine h.imp_right (ih (r :: rs₀) ?_ ?_) <;>
exact List.perm_middle.subperm_right.mp ‹_›
| swap a b t =>
rw [show ∀ x y z, x :: y :: z = [x, y] ++ z from fun _ _ _ => rfl,
isWeaklyRegular_append_iff] at h ⊢
have : Ideal.ofList [b, a] = Ideal.ofList [a, b] :=
congrArg Ideal.span <| Set.ext fun _ => (List.Perm.swap a b []).mem_iff
rw [(quotEquivOfEq _ _ (congrArg₂ _ this rfl)).isWeaklyRegular_congr] at h
rw [List.append_cons, List.append_cons, List.append_assoc _ [b] [a]] at H₁
apply (List.sublist_append_left (rs₀ ++ [b, a]) _).subperm.trans at H₁
apply List.perm_append_comm.subperm.trans at H₁
exact h.imp_left (swap · (h' b a rs₀ H₁))
| trans h₁₂ _ ih₁₂ ih₂₃ =>
have H₂ := (h₁₂.append_left rs₀).subperm_right.mp H₁
exact ih₂₃ rs₀ H₂ H₃ (ih₁₂ rs₀ H₁ H₂ h) }
-- putting `{rs' : List R}` and `h2` after `h3` would be better for partial
-- application, but this argument order seems nicer overall
lemma IsWeaklyRegular.of_perm_of_subset_jacobson_annihilator [IsNoetherian R M]
{rs rs' : List R} (h1 : IsWeaklyRegular M rs) (h2 : List.Perm rs rs')
(h3 : ∀ r ∈ rs, r ∈ (Module.annihilator R M).jacobson) :
IsWeaklyRegular M rs' :=
h1.prototype_perm h2 fun r _ _ h h' =>
eq_bot_of_eq_pointwise_smul_of_mem_jacobson_annihilator
(IsNoetherian.noetherian _) h'
(Ideal.jacobson_mono
(le_trans
-- The named argument `(R := R)` below isn't necessary, but
-- typechecking is much slower without it
(LinearMap.annihilator_le_of_surjective (R := R) _ (mkQ_surjective _))
(LinearMap.annihilator_le_of_injective _ (injective_subtype _)))
(h3 r (h.subset (List.mem_cons_self _ _))))
end Perm
lemma IsRegular.of_perm_of_subset_jacobson_annihilator [IsNoetherian R M]
{rs rs' : List R} (h1 : IsRegular M rs) (h2 : List.Perm rs rs')
(h3 : ∀ r ∈ rs, r ∈ (Module.annihilator R M).jacobson) : IsRegular M rs' :=
⟨h1.toIsWeaklyRegular.of_perm_of_subset_jacobson_annihilator h2 h3,
letI := h1.nontrivial
top_ne_ideal_smul_of_le_jacobson_annihilator <|
Ideal.span_le.mpr (h3 · <| h2.mem_iff.mpr ·)⟩
lemma _root_.LocalRing.isWeaklyRegular_of_perm_of_subset_maximalIdeal
[LocalRing R] [IsNoetherian R M] {rs rs' : List R}
(h1 : IsWeaklyRegular M rs) (h2 : List.Perm rs rs')
(h3 : ∀ r ∈ rs, r ∈ LocalRing.maximalIdeal R) : IsWeaklyRegular M rs' :=
IsWeaklyRegular.of_perm_of_subset_jacobson_annihilator h1 h2 fun r hr =>
LocalRing.maximalIdeal_le_jacobson _ (h3 r hr)
lemma _root_.LocalRing.isRegular_of_perm [LocalRing R] [IsNoetherian R M]
{rs rs' : List R} (h1 : IsRegular M rs) (h2 : List.Perm rs rs') :
IsRegular M rs' := by
obtain ⟨h3, h4⟩ := h1
refine ⟨LocalRing.isWeaklyRegular_of_perm_of_subset_maximalIdeal h3 h2 ?_, ?_⟩
· intro x (h6 : x ∈ { r | r ∈ rs })
refine LocalRing.le_maximalIdeal ?_ (Ideal.subset_span h6)
exact h4 ∘ Eq.trans (top_smul _).symm ∘ Eq.symm ∘ congrArg (· • ⊤)
· refine ne_of_ne_of_eq h4 (congrArg (Ideal.span · • ⊤) ?_)
exact Set.ext fun _ => h2.mem_iff
end RingTheory.Sequence
|
RingTheory\RingHom\Finite.lean | /-
Copyright (c) 2021 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.RingTheory.RingHomProperties
/-!
# The meta properties of finite ring homomorphisms.
-/
namespace RingHom
open scoped TensorProduct
open TensorProduct Algebra.TensorProduct
theorem finite_stableUnderComposition : StableUnderComposition @Finite := by
introv R hf hg
exact hg.comp hf
theorem finite_respectsIso : RespectsIso @Finite := by
apply finite_stableUnderComposition.respectsIso
intros
exact Finite.of_surjective _ (RingEquiv.toEquiv _).surjective
theorem finite_stableUnderBaseChange : StableUnderBaseChange @Finite := by
refine StableUnderBaseChange.mk _ finite_respectsIso ?_
classical
introv h
replace h : Module.Finite R T := by
rw [RingHom.Finite] at h; convert h; ext; simp_rw [Algebra.smul_def]; rfl
suffices Module.Finite S (S ⊗[R] T) by
rw [RingHom.Finite]; convert this; congr; ext; simp_rw [Algebra.smul_def]; rfl
exact inferInstance
end RingHom
|
RingTheory\RingHom\FinitePresentation.lean | /-
Copyright (c) 2024 Christian Merten. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Christian Merten
-/
import Mathlib.RingTheory.Localization.Finiteness
import Mathlib.RingTheory.MvPolynomial.Localization
import Mathlib.RingTheory.RingHom.FiniteType
import Mathlib.RingTheory.Localization.Away.AdjoinRoot
/-!
# The meta properties of finitely-presented ring homomorphisms.
The main result is `RingHom.finitePresentation_isLocal`.
-/
open scoped Pointwise TensorProduct
namespace RingHom
attribute [local instance] MvPolynomial.algebraMvPolynomial
/-- Being finitely-presented is preserved by localizations. -/
theorem finitePresentation_localizationPreserves : LocalizationPreserves @FinitePresentation := by
introv R hf
letI := f.toAlgebra
letI := ((algebraMap S S').comp f).toAlgebra
let f' : R' →+* S' := IsLocalization.map S' f M.le_comap_map
letI := f'.toAlgebra
haveI : IsScalarTower R R' S' :=
IsScalarTower.of_algebraMap_eq' (IsLocalization.map_comp M.le_comap_map).symm
obtain ⟨n, g, hgsurj, hgker⟩ := hf
let MX : Submonoid (MvPolynomial (Fin n) R) :=
Algebra.algebraMapSubmonoid (MvPolynomial (Fin n) R) M
haveI : IsLocalization MX (MvPolynomial (Fin n) R') :=
inferInstanceAs <| IsLocalization (M.map MvPolynomial.C) (MvPolynomial (Fin n) R')
haveI : IsScalarTower R S S' := IsScalarTower.of_algebraMap_eq' rfl
haveI : IsLocalization (Algebra.algebraMapSubmonoid S M) S' :=
inferInstanceAs <| IsLocalization (M.map f) S'
let g' : MvPolynomial (Fin n) R' →ₐ[R'] S' := IsLocalization.mapₐ M R' _ S' g
let k : RingHom.ker g →ₗ[MvPolynomial (Fin n) R] RingHom.ker g' :=
AlgHom.toKerIsLocalization M R' _ S' g
have : IsLocalizedModule MX k := AlgHom.toKerIsLocalization_isLocalizedModule M _ _ _ g
have : Module.Finite (MvPolynomial (Fin n) R) (ker g) := Module.Finite.iff_fg.mpr hgker
exact ⟨n, g', IsLocalization.mapₐ_surjective_of_surjective M R' _ S' g hgsurj,
Module.Finite.iff_fg.mp (Module.Finite.of_isLocalizedModule MX k)⟩
/-- Being finitely-presented is stable under composition. -/
theorem finitePresentation_stableUnderComposition : StableUnderComposition @FinitePresentation := by
introv R hf hg
exact hg.comp hf
/-- If `R` is a ring, then `Rᵣ` is `R`-finitely-presented for any `r : R`. -/
theorem finitePresentation_holdsForLocalizationAway :
HoldsForLocalizationAway @FinitePresentation := by
introv R _
suffices Algebra.FinitePresentation R S by
rw [RingHom.FinitePresentation]
convert this; ext;
rw [Algebra.smul_def]; rfl
exact IsLocalization.Away.finitePresentation r
/--
If `S` is an `R`-algebra with a surjection from a finitely-presented `R`-algebra `A`, such that
localized at a spanning set `{ r }` of elements of `A`, `Sᵣ` is finitely-presented, then
`S` is finitely presented.
This is almost `finitePresentation_ofLocalizationSpanTarget`. The difference is,
that here the set `t` generates the unit ideal of `A`, while in the general version,
it only generates a quotient of `A`.
-/
lemma finitePresentation_ofLocalizationSpanTarget_aux
{R S A : Type*} [CommRing R] [CommRing S] [CommRing A] [Algebra R S] [Algebra R A]
[Algebra.FinitePresentation R A] (f : A →ₐ[R] S) (hf : Function.Surjective f)
(t : Finset A) (ht : Ideal.span (t : Set A) = ⊤)
(H : ∀ g : t, Algebra.FinitePresentation R (Localization.Away (f g))) :
Algebra.FinitePresentation R S := by
apply Algebra.FinitePresentation.of_surjective hf
apply ker_fg_of_localizationSpan t ht
intro g
let f' : Localization.Away g.val →ₐ[R] Localization.Away (f g) :=
Localization.awayMapₐ f g.val
have (g : t) : Algebra.FinitePresentation R (Localization.Away g.val) :=
haveI : Algebra.FinitePresentation A (Localization.Away g.val) :=
IsLocalization.Away.finitePresentation g.val
Algebra.FinitePresentation.trans R A (Localization.Away g.val)
apply Algebra.FinitePresentation.ker_fG_of_surjective f'
exact IsLocalization.Away.mapₐ_surjective_of_surjective _ hf
/-- Finite-presentation can be checked on a standard covering of the target. -/
theorem finitePresentation_ofLocalizationSpanTarget :
OfLocalizationSpanTarget @FinitePresentation := by
rw [ofLocalizationSpanTarget_iff_finite]
introv R hs H
classical
letI := f.toAlgebra
replace H : ∀ r : s, Algebra.FinitePresentation R (Localization.Away (r : S)) := by
intro r; simp_rw [RingHom.FinitePresentation] at H;
convert H r; ext; simp_rw [Algebra.smul_def]; rfl
/-
We already know that `S` is of finite type over `R`, so we have a surjection
`MvPolynomial (Fin n) R →ₐ[R] S`. To reason about the kernel, we want to check it on the stalks
of preimages of `s`. But the preimages do not necessarily span `MvPolynomial (Fin n) R`, so
we quotient out by an ideal and apply `finitePresentation_ofLocalizationSpanTarget_aux`.
-/
have hfintype : Algebra.FiniteType R S := by
apply finiteType_ofLocalizationSpanTarget f s hs
intro r
convert_to Algebra.FiniteType R (Localization.Away r.val)
· rw [RingHom.FiniteType]
constructor <;> intro h <;> convert h <;> ext <;> simp_rw [Algebra.smul_def] <;> rfl
· infer_instance
rw [RingHom.FinitePresentation]
obtain ⟨n, f, hf⟩ := Algebra.FiniteType.iff_quotient_mvPolynomial''.mp hfintype
obtain ⟨l, hl⟩ := (Finsupp.mem_span_iff_total S (s : Set S) 1).mp
(show (1 : S) ∈ Ideal.span (s : Set S) by rw [hs]; trivial)
choose g' hg' using (fun g : s ↦ hf g)
choose h' hh' using (fun g : s ↦ hf (l g))
let I : Ideal (MvPolynomial (Fin n) R) := Ideal.span { ∑ g : s, g' g * h' g - 1 }
let A := MvPolynomial (Fin n) R ⧸ I
have hfI : ∀ a ∈ I, f a = 0 := by
intro p hp
simp only [Finset.univ_eq_attach, I, Ideal.mem_span_singleton] at hp
obtain ⟨q, rfl⟩ := hp
simp only [map_mul, map_sub, map_sum, map_one, hg', hh']
erw [Finsupp.total_apply_of_mem_supported S (s := s.attach)] at hl
· rw [← hl]
simp only [Finset.coe_sort_coe, smul_eq_mul, mul_comm, sub_self, mul_zero, zero_mul]
· rintro a -
simp
let f' : A →ₐ[R] S := Ideal.Quotient.liftₐ I f hfI
have hf' : Function.Surjective f' :=
Ideal.Quotient.lift_surjective_of_surjective I hfI hf
let t : Finset A := Finset.image (fun g ↦ g' g) Finset.univ
have ht : Ideal.span (t : Set A) = ⊤ := by
rw [Ideal.eq_top_iff_one]
have : ∑ g : { x // x ∈ s }, g' g * h' g = (1 : A) := by
apply eq_of_sub_eq_zero
rw [← map_one (Ideal.Quotient.mk I), ← map_sub, Ideal.Quotient.eq_zero_iff_mem]
apply Ideal.subset_span
simp
simp_rw [← this, Finset.univ_eq_attach, map_sum, map_mul]
refine Ideal.sum_mem _ (fun g _ ↦ Ideal.mul_mem_right _ _ <| Ideal.subset_span ?_)
simp [t]
have : Algebra.FinitePresentation R A := by
apply Algebra.FinitePresentation.quotient
simp only [Finset.univ_eq_attach, I]
exact ⟨{∑ g ∈ s.attach, g' g * h' g - 1}, by simp⟩
have Ht (g : t) : Algebra.FinitePresentation R (Localization.Away (f' g)) := by
have : ∃ (a : S) (hb : a ∈ s), (Ideal.Quotient.mk I) (g' ⟨a, hb⟩) = g.val := by
simpa [t] using g.property
obtain ⟨r, hr, hrr⟩ := this
simp only [f']
rw [← hrr, Ideal.Quotient.liftₐ_apply, Ideal.Quotient.lift_mk]
simp_rw [coe_coe]
rw [hg']
apply H
exact finitePresentation_ofLocalizationSpanTarget_aux f' hf' t ht Ht
/-- Being finitely-presented is a local property of rings. -/
theorem finitePresentation_isLocal : PropertyIsLocal @FinitePresentation :=
⟨finitePresentation_localizationPreserves,
finitePresentation_ofLocalizationSpanTarget, finitePresentation_stableUnderComposition,
finitePresentation_holdsForLocalizationAway⟩
/-- Being finitely-presented respects isomorphisms. -/
theorem finitePresentation_respectsIso : RingHom.RespectsIso @RingHom.FinitePresentation :=
RingHom.finitePresentation_isLocal.respectsIso
/-- Being finitely-presented is stable under base change. -/
theorem finitePresentation_stableUnderBaseChange : StableUnderBaseChange @FinitePresentation := by
apply StableUnderBaseChange.mk
· exact finitePresentation_respectsIso
· introv h
replace h : Algebra.FinitePresentation R T := by
rw [RingHom.FinitePresentation] at h; convert h; ext; simp_rw [Algebra.smul_def]; rfl
suffices Algebra.FinitePresentation S (S ⊗[R] T) by
rw [RingHom.FinitePresentation]; convert this; ext; simp_rw [Algebra.smul_def]; rfl
infer_instance
end RingHom
|
RingTheory\RingHom\FiniteType.lean | /-
Copyright (c) 2021 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.RingTheory.FiniteStability
import Mathlib.RingTheory.LocalProperties
import Mathlib.RingTheory.Localization.InvSubmonoid
/-!
# The meta properties of finite-type ring homomorphisms.
The main result is `RingHom.finiteType_is_local`.
-/
namespace RingHom
open scoped Pointwise TensorProduct
theorem finiteType_stableUnderComposition : StableUnderComposition @FiniteType := by
introv R hf hg
exact hg.comp hf
theorem finiteType_holdsForLocalizationAway : HoldsForLocalizationAway @FiniteType := by
introv R _
suffices Algebra.FiniteType R S by
rw [RingHom.FiniteType]
convert this; ext
rw [Algebra.smul_def]; rfl
exact IsLocalization.finiteType_of_monoid_fg (Submonoid.powers r) S
theorem finiteType_ofLocalizationSpanTarget : OfLocalizationSpanTarget @FiniteType := by
-- Setup algebra intances.
rw [ofLocalizationSpanTarget_iff_finite]
introv R hs H
classical
letI := f.toAlgebra
replace H : ∀ r : s, Algebra.FiniteType R (Localization.Away (r : S)) := by
intro r; simp_rw [RingHom.FiniteType] at H; convert H r; ext; simp_rw [Algebra.smul_def]; rfl
replace H := fun r => (H r).1
constructor
-- Suppose `s : Finset S` spans `S`, and each `Sᵣ` is finitely generated as an `R`-algebra.
-- Say `t r : Finset Sᵣ` generates `Sᵣ`. By assumption, we may find `lᵢ` such that
-- `∑ lᵢ * sᵢ = 1`. I claim that all `s` and `l` and the numerators of `t` and generates `S`.
choose t ht using H
obtain ⟨l, hl⟩ :=
(Finsupp.mem_span_iff_total S (s : Set S) 1).mp
(show (1 : S) ∈ Ideal.span (s : Set S) by rw [hs]; trivial)
let sf := fun x : s => IsLocalization.finsetIntegerMultiple (Submonoid.powers (x : S)) (t x)
use s.attach.biUnion sf ∪ s ∪ l.support.image l
rw [eq_top_iff]
-- We need to show that every `x` falls in the subalgebra generated by those elements.
-- Since all `s` and `l` are in the subalgebra, it suffices to check that `sᵢ ^ nᵢ • x` falls in
-- the algebra for each `sᵢ` and some `nᵢ`.
rintro x -
apply Subalgebra.mem_of_span_eq_top_of_smul_pow_mem _ (s : Set S) l hl _ _ x _
· intro x hx
apply Algebra.subset_adjoin
rw [Finset.coe_union, Finset.coe_union]
exact Or.inl (Or.inr hx)
· intro i
by_cases h : l i = 0; · rw [h]; exact zero_mem _
apply Algebra.subset_adjoin
rw [Finset.coe_union, Finset.coe_image]
exact Or.inr (Set.mem_image_of_mem _ (Finsupp.mem_support_iff.mpr h))
· intro r
rw [Finset.coe_union, Finset.coe_union, Finset.coe_biUnion]
-- Since all `sᵢ` and numerators of `t r` are in the algebra, it suffices to show that the
-- image of `x` in `Sᵣ` falls in the `R`-adjoin of `t r`, which is of course true.
-- Porting note: The following `obtain` fails because Lean wants to know right away what the
-- placeholders are, so we need to provide a little more guidance
-- obtain ⟨⟨_, n₂, rfl⟩, hn₂⟩ := IsLocalization.exists_smul_mem_of_mem_adjoin
-- (Submonoid.powers (r : S)) x (t r) (Algebra.adjoin R _) _ _ _
rw [show ∀ A : Set S, (∃ n, (r : S) ^ n • x ∈ Algebra.adjoin R A) ↔
(∃ m : (Submonoid.powers (r : S)), (m : S) • x ∈ Algebra.adjoin R A) by
{ exact fun _ => by simp [Submonoid.mem_powers_iff] }]
refine IsLocalization.exists_smul_mem_of_mem_adjoin
(Submonoid.powers (r : S)) x (t r) (Algebra.adjoin R _) ?_ ?_ ?_
· intro x hx
apply Algebra.subset_adjoin
exact Or.inl (Or.inl ⟨_, ⟨r, rfl⟩, _, ⟨s.mem_attach r, rfl⟩, hx⟩)
· rw [Submonoid.powers_eq_closure, Submonoid.closure_le, Set.singleton_subset_iff]
apply Algebra.subset_adjoin
exact Or.inl (Or.inr r.2)
· rw [ht]; trivial
theorem finiteType_is_local : PropertyIsLocal @FiniteType :=
⟨localization_finiteType, finiteType_ofLocalizationSpanTarget, finiteType_stableUnderComposition,
finiteType_holdsForLocalizationAway⟩
theorem finiteType_respectsIso : RingHom.RespectsIso @RingHom.FiniteType :=
RingHom.finiteType_is_local.respectsIso
theorem finiteType_stableUnderBaseChange : StableUnderBaseChange @FiniteType := by
apply StableUnderBaseChange.mk
· exact finiteType_respectsIso
· introv h
replace h : Algebra.FiniteType R T := by
rw [RingHom.FiniteType] at h; convert h; ext; simp_rw [Algebra.smul_def]; rfl
suffices Algebra.FiniteType S (S ⊗[R] T) by
rw [RingHom.FiniteType]; convert this; ext; simp_rw [Algebra.smul_def]; rfl
infer_instance
end RingHom
|
RingTheory\RingHom\Integral.lean | /-
Copyright (c) 2021 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.RingTheory.RingHomProperties
import Mathlib.RingTheory.IntegralClosure.IsIntegralClosure.Basic
/-!
# The meta properties of integral ring homomorphisms.
-/
namespace RingHom
open scoped TensorProduct
open TensorProduct Algebra.TensorProduct
theorem isIntegral_stableUnderComposition : StableUnderComposition fun f => f.IsIntegral := by
introv R hf hg; exact hf.trans _ _ hg
theorem isIntegral_respectsIso : RespectsIso fun f => f.IsIntegral := by
apply isIntegral_stableUnderComposition.respectsIso
introv x
rw [← e.apply_symm_apply x]
apply RingHom.isIntegralElem_map
theorem isIntegral_stableUnderBaseChange : StableUnderBaseChange fun f => f.IsIntegral := by
refine StableUnderBaseChange.mk _ isIntegral_respectsIso ?_
introv h x
refine TensorProduct.induction_on x ?_ ?_ ?_
· apply isIntegral_zero
· intro x y; exact IsIntegral.tmul x (h y)
· intro x y hx hy; exact IsIntegral.add hx hy
end RingHom
|
RingTheory\RingHom\Surjective.lean | /-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.RingTheory.LocalProperties
/-!
# The meta properties of surjective ring homomorphisms.
-/
namespace RingHom
open scoped TensorProduct
open TensorProduct Algebra.TensorProduct
local notation "surjective" => fun {X Y : Type _} [CommRing X] [CommRing Y] => fun f : X →+* Y =>
Function.Surjective f
theorem surjective_stableUnderComposition : StableUnderComposition surjective := by
introv R hf hg; exact hg.comp hf
theorem surjective_respectsIso : RespectsIso surjective := by
apply surjective_stableUnderComposition.respectsIso
intros _ _ _ _ e
exact e.surjective
theorem surjective_stableUnderBaseChange : StableUnderBaseChange surjective := by
refine StableUnderBaseChange.mk _ surjective_respectsIso ?_
classical
introv h x
induction x with
| zero => exact ⟨0, map_zero _⟩
| tmul x y =>
obtain ⟨y, rfl⟩ := h y; use y • x; dsimp
rw [TensorProduct.smul_tmul, Algebra.algebraMap_eq_smul_one]
| add x y ex ey => obtain ⟨⟨x, rfl⟩, ⟨y, rfl⟩⟩ := ex, ey; exact ⟨x + y, map_add _ x y⟩
theorem surjective_ofLocalizationSpan : OfLocalizationSpan surjective := by
introv R hs H
letI := f.toAlgebra
show Function.Surjective (Algebra.ofId R S)
rw [← Algebra.range_top_iff_surjective, eq_top_iff]
rintro x -
obtain ⟨l, hl⟩ :=
(Finsupp.mem_span_iff_total R s 1).mp (show _ ∈ Ideal.span s by rw [hs]; trivial)
fapply
Subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem _ l.support (fun x : s => f x) fun x : s =>
f (l x)
· simp_rw [← _root_.map_mul, ← map_sum, ← f.map_one]; exact f.congr_arg hl
· exact fun _ => Set.mem_range_self _
· exact fun _ => Set.mem_range_self _
· intro r
obtain ⟨y, hy⟩ := H r (IsLocalization.mk' _ x (1 : Submonoid.powers (f r)))
obtain ⟨z, ⟨_, n, rfl⟩, rfl⟩ := IsLocalization.mk'_surjective (Submonoid.powers (r : R)) y
erw [IsLocalization.map_mk', IsLocalization.eq] at hy
obtain ⟨⟨_, m, rfl⟩, hm⟩ := hy
refine ⟨m + n, ?_⟩
dsimp at hm ⊢
simp_rw [_root_.one_mul, ← _root_.mul_assoc, ← map_pow, ← f.map_mul, ← pow_add, map_pow] at hm
exact ⟨_, hm⟩
end RingHom
|
RingTheory\RootsOfUnity\Basic.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.CharP.Two
import Mathlib.Algebra.CharP.Reduced
import Mathlib.Algebra.NeZero
import Mathlib.Algebra.Polynomial.RingDivision
import Mathlib.GroupTheory.SpecificGroups.Cyclic
import Mathlib.NumberTheory.Divisors
import Mathlib.RingTheory.IntegralDomain
import Mathlib.Tactic.Zify
/-!
# Roots of unity and primitive roots of unity
We define roots of unity in the context of an arbitrary commutative monoid,
as a subgroup of the group of units. We also define a predicate `IsPrimitiveRoot` on commutative
monoids, expressing that an element is a primitive root of unity.
## Main definitions
* `rootsOfUnity n M`, for `n : ℕ+` is the subgroup of the units of a commutative monoid `M`
consisting of elements `x` that satisfy `x ^ n = 1`.
* `IsPrimitiveRoot ζ k`: an element `ζ` is a primitive `k`-th root of unity if `ζ ^ k = 1`,
and if `l` satisfies `ζ ^ l = 1` then `k ∣ l`.
* `primitiveRoots k R`: the finset of primitive `k`-th roots of unity in an integral domain `R`.
* `IsPrimitiveRoot.autToPow`: the monoid hom that takes an automorphism of a ring to the power
it sends that specific primitive root, as a member of `(ZMod n)ˣ`.
## Main results
* `rootsOfUnity.isCyclic`: the roots of unity in an integral domain form a cyclic group.
* `IsPrimitiveRoot.zmodEquivZPowers`: `ZMod k` is equivalent to
the subgroup generated by a primitive `k`-th root of unity.
* `IsPrimitiveRoot.zpowers_eq`: in an integral domain, the subgroup generated by
a primitive `k`-th root of unity is equal to the `k`-th roots of unity.
* `IsPrimitiveRoot.card_primitiveRoots`: if an integral domain
has a primitive `k`-th root of unity, then it has `φ k` of them.
## Implementation details
It is desirable that `rootsOfUnity` is a subgroup,
and it will mainly be applied to rings (e.g. the ring of integers in a number field) and fields.
We therefore implement it as a subgroup of the units of a commutative monoid.
We have chosen to define `rootsOfUnity n` for `n : ℕ+`, instead of `n : ℕ`,
because almost all lemmas need the positivity assumption,
and in particular the type class instances for `Fintype` and `IsCyclic`.
On the other hand, for primitive roots of unity, it is desirable to have a predicate
not just on units, but directly on elements of the ring/field.
For example, we want to say that `exp (2 * pi * I / n)` is a primitive `n`-th root of unity
in the complex numbers, without having to turn that number into a unit first.
This creates a little bit of friction, but lemmas like `IsPrimitiveRoot.isUnit` and
`IsPrimitiveRoot.coe_units_iff` should provide the necessary glue.
-/
open scoped Classical
noncomputable section
open Polynomial
open Finset
variable {M N G R S F : Type*}
variable [CommMonoid M] [CommMonoid N] [DivisionCommMonoid G]
section rootsOfUnity
variable {k l : ℕ+}
/-- `rootsOfUnity k M` is the subgroup of elements `m : Mˣ` that satisfy `m ^ k = 1`. -/
def rootsOfUnity (k : ℕ+) (M : Type*) [CommMonoid M] : Subgroup Mˣ where
carrier := {ζ | ζ ^ (k : ℕ) = 1}
one_mem' := one_pow _
mul_mem' _ _ := by simp_all only [Set.mem_setOf_eq, mul_pow, one_mul]
inv_mem' _ := by simp_all only [Set.mem_setOf_eq, inv_pow, inv_one]
@[simp]
theorem mem_rootsOfUnity (k : ℕ+) (ζ : Mˣ) : ζ ∈ rootsOfUnity k M ↔ ζ ^ (k : ℕ) = 1 :=
Iff.rfl
theorem mem_rootsOfUnity' (k : ℕ+) (ζ : Mˣ) : ζ ∈ rootsOfUnity k M ↔ (ζ : M) ^ (k : ℕ) = 1 := by
rw [mem_rootsOfUnity]; norm_cast
@[simp]
theorem rootsOfUnity_one (M : Type*) [CommMonoid M] : rootsOfUnity 1 M = ⊥ := by ext; simp
theorem rootsOfUnity.coe_injective {n : ℕ+} :
Function.Injective (fun x : rootsOfUnity n M ↦ x.val.val) :=
Units.ext.comp fun _ _ => Subtype.eq
/-- Make an element of `rootsOfUnity` from a member of the base ring, and a proof that it has
a positive power equal to one. -/
@[simps! coe_val]
def rootsOfUnity.mkOfPowEq (ζ : M) {n : ℕ+} (h : ζ ^ (n : ℕ) = 1) : rootsOfUnity n M :=
⟨Units.ofPowEqOne ζ n h n.ne_zero, Units.pow_ofPowEqOne _ _⟩
@[simp]
theorem rootsOfUnity.coe_mkOfPowEq {ζ : M} {n : ℕ+} (h : ζ ^ (n : ℕ) = 1) :
((rootsOfUnity.mkOfPowEq _ h : Mˣ) : M) = ζ :=
rfl
theorem rootsOfUnity_le_of_dvd (h : k ∣ l) : rootsOfUnity k M ≤ rootsOfUnity l M := by
obtain ⟨d, rfl⟩ := h
intro ζ h
simp_all only [mem_rootsOfUnity, PNat.mul_coe, pow_mul, one_pow]
theorem map_rootsOfUnity (f : Mˣ →* Nˣ) (k : ℕ+) : (rootsOfUnity k M).map f ≤ rootsOfUnity k N := by
rintro _ ⟨ζ, h, rfl⟩
simp_all only [← map_pow, mem_rootsOfUnity, SetLike.mem_coe, MonoidHom.map_one]
@[norm_cast]
theorem rootsOfUnity.coe_pow [CommMonoid R] (ζ : rootsOfUnity k R) (m : ℕ) :
(((ζ ^ m :) : Rˣ) : R) = ((ζ : Rˣ) : R) ^ m := by
rw [Subgroup.coe_pow, Units.val_pow_eq_pow_val]
section CommMonoid
variable [CommMonoid R] [CommMonoid S] [FunLike F R S]
/-- Restrict a ring homomorphism to the nth roots of unity. -/
def restrictRootsOfUnity [MonoidHomClass F R S] (σ : F) (n : ℕ+) :
rootsOfUnity n R →* rootsOfUnity n S :=
let h : ∀ ξ : rootsOfUnity n R, (σ (ξ : Rˣ)) ^ (n : ℕ) = 1 := fun ξ => by
rw [← map_pow, ← Units.val_pow_eq_pow_val, show (ξ : Rˣ) ^ (n : ℕ) = 1 from ξ.2, Units.val_one,
map_one σ]
{ toFun := fun ξ =>
⟨@unitOfInvertible _ _ _ (invertibleOfPowEqOne _ _ (h ξ) n.ne_zero), by
ext; rw [Units.val_pow_eq_pow_val]; exact h ξ⟩
map_one' := by ext; exact map_one σ
map_mul' := fun ξ₁ ξ₂ => by ext; rw [Subgroup.coe_mul, Units.val_mul]; exact map_mul σ _ _ }
@[simp]
theorem restrictRootsOfUnity_coe_apply [MonoidHomClass F R S] (σ : F) (ζ : rootsOfUnity k R) :
(restrictRootsOfUnity σ k ζ : Sˣ) = σ (ζ : Rˣ) :=
rfl
/-- Restrict a monoid isomorphism to the nth roots of unity. -/
nonrec def MulEquiv.restrictRootsOfUnity (σ : R ≃* S) (n : ℕ+) :
rootsOfUnity n R ≃* rootsOfUnity n S where
toFun := restrictRootsOfUnity σ n
invFun := restrictRootsOfUnity σ.symm n
left_inv ξ := by ext; exact σ.symm_apply_apply (ξ : Rˣ)
right_inv ξ := by ext; exact σ.apply_symm_apply (ξ : Sˣ)
map_mul' := (restrictRootsOfUnity _ n).map_mul
@[simp]
theorem MulEquiv.restrictRootsOfUnity_coe_apply (σ : R ≃* S) (ζ : rootsOfUnity k R) :
(σ.restrictRootsOfUnity k ζ : Sˣ) = σ (ζ : Rˣ) :=
rfl
@[simp]
theorem MulEquiv.restrictRootsOfUnity_symm (σ : R ≃* S) :
(σ.restrictRootsOfUnity k).symm = σ.symm.restrictRootsOfUnity k :=
rfl
end CommMonoid
section IsDomain
variable [CommRing R] [IsDomain R]
theorem mem_rootsOfUnity_iff_mem_nthRoots {ζ : Rˣ} :
ζ ∈ rootsOfUnity k R ↔ (ζ : R) ∈ nthRoots k (1 : R) := by
simp only [mem_rootsOfUnity, mem_nthRoots k.pos, Units.ext_iff, Units.val_one,
Units.val_pow_eq_pow_val]
variable (k R)
/-- Equivalence between the `k`-th roots of unity in `R` and the `k`-th roots of `1`.
This is implemented as equivalence of subtypes,
because `rootsOfUnity` is a subgroup of the group of units,
whereas `nthRoots` is a multiset. -/
def rootsOfUnityEquivNthRoots : rootsOfUnity k R ≃ { x // x ∈ nthRoots k (1 : R) } where
toFun x := ⟨(x : Rˣ), mem_rootsOfUnity_iff_mem_nthRoots.mp x.2⟩
invFun x := by
refine ⟨⟨x, ↑x ^ (k - 1 : ℕ), ?_, ?_⟩, ?_⟩
all_goals
rcases x with ⟨x, hx⟩; rw [mem_nthRoots k.pos] at hx
simp only [Subtype.coe_mk, ← pow_succ, ← pow_succ', hx,
tsub_add_cancel_of_le (show 1 ≤ (k : ℕ) from k.one_le)]
simp only [mem_rootsOfUnity, Units.ext_iff, hx, Units.val_mk, Units.val_one, Subtype.coe_mk,
Units.val_pow_eq_pow_val]
left_inv := by rintro ⟨x, hx⟩; ext; rfl
right_inv := by rintro ⟨x, hx⟩; ext; rfl
variable {k R}
@[simp]
theorem rootsOfUnityEquivNthRoots_apply (x : rootsOfUnity k R) :
(rootsOfUnityEquivNthRoots R k x : R) = ((x : Rˣ) : R) :=
rfl
@[simp]
theorem rootsOfUnityEquivNthRoots_symm_apply (x : { x // x ∈ nthRoots k (1 : R) }) :
(((rootsOfUnityEquivNthRoots R k).symm x : Rˣ) : R) = (x : R) :=
rfl
variable (k R)
instance rootsOfUnity.fintype : Fintype (rootsOfUnity k R) :=
Fintype.ofEquiv { x // x ∈ nthRoots k (1 : R) } <| (rootsOfUnityEquivNthRoots R k).symm
instance rootsOfUnity.isCyclic : IsCyclic (rootsOfUnity k R) :=
isCyclic_of_subgroup_isDomain ((Units.coeHom R).comp (rootsOfUnity k R).subtype)
(Units.ext.comp Subtype.val_injective)
theorem card_rootsOfUnity : Fintype.card (rootsOfUnity k R) ≤ k :=
calc
Fintype.card (rootsOfUnity k R) = Fintype.card { x // x ∈ nthRoots k (1 : R) } :=
Fintype.card_congr (rootsOfUnityEquivNthRoots R k)
_ ≤ Multiset.card (nthRoots k (1 : R)).attach := Multiset.card_le_card (Multiset.dedup_le _)
_ = Multiset.card (nthRoots k (1 : R)) := Multiset.card_attach
_ ≤ k := card_nthRoots k 1
variable {k R}
theorem map_rootsOfUnity_eq_pow_self [FunLike F R R] [RingHomClass F R R] (σ : F)
(ζ : rootsOfUnity k R) :
∃ m : ℕ, σ (ζ : Rˣ) = ((ζ : Rˣ) : R) ^ m := by
obtain ⟨m, hm⟩ := MonoidHom.map_cyclic (restrictRootsOfUnity σ k)
rw [← restrictRootsOfUnity_coe_apply, hm, ← zpow_mod_orderOf, ← Int.toNat_of_nonneg
(m.emod_nonneg (Int.natCast_ne_zero.mpr (pos_iff_ne_zero.mp (orderOf_pos ζ)))),
zpow_natCast, rootsOfUnity.coe_pow]
exact ⟨(m % orderOf ζ).toNat, rfl⟩
end IsDomain
section Reduced
variable (R) [CommRing R] [IsReduced R]
-- @[simp] -- Porting note: simp normal form is `mem_rootsOfUnity_prime_pow_mul_iff'`
theorem mem_rootsOfUnity_prime_pow_mul_iff (p k : ℕ) (m : ℕ+) [ExpChar R p]
{ζ : Rˣ} : ζ ∈ rootsOfUnity (⟨p, expChar_pos R p⟩ ^ k * m) R ↔ ζ ∈ rootsOfUnity m R := by
simp only [mem_rootsOfUnity', PNat.mul_coe, PNat.pow_coe, PNat.mk_coe,
ExpChar.pow_prime_pow_mul_eq_one_iff]
@[simp]
theorem mem_rootsOfUnity_prime_pow_mul_iff' (p k : ℕ) (m : ℕ+) [ExpChar R p]
{ζ : Rˣ} : ζ ^ (p ^ k * ↑m) = 1 ↔ ζ ∈ rootsOfUnity m R := by
rw [← PNat.mk_coe p (expChar_pos R p), ← PNat.pow_coe, ← PNat.mul_coe, ← mem_rootsOfUnity,
mem_rootsOfUnity_prime_pow_mul_iff]
end Reduced
end rootsOfUnity
/-- An element `ζ` is a primitive `k`-th root of unity if `ζ ^ k = 1`,
and if `l` satisfies `ζ ^ l = 1` then `k ∣ l`. -/
@[mk_iff IsPrimitiveRoot.iff_def]
structure IsPrimitiveRoot (ζ : M) (k : ℕ) : Prop where
pow_eq_one : ζ ^ (k : ℕ) = 1
dvd_of_pow_eq_one : ∀ l : ℕ, ζ ^ l = 1 → k ∣ l
/-- Turn a primitive root μ into a member of the `rootsOfUnity` subgroup. -/
@[simps!]
def IsPrimitiveRoot.toRootsOfUnity {μ : M} {n : ℕ+} (h : IsPrimitiveRoot μ n) : rootsOfUnity n M :=
rootsOfUnity.mkOfPowEq μ h.pow_eq_one
section primitiveRoots
variable {k : ℕ}
/-- `primitiveRoots k R` is the finset of primitive `k`-th roots of unity
in the integral domain `R`. -/
def primitiveRoots (k : ℕ) (R : Type*) [CommRing R] [IsDomain R] : Finset R :=
(nthRoots k (1 : R)).toFinset.filter fun ζ => IsPrimitiveRoot ζ k
variable [CommRing R] [IsDomain R]
@[simp]
theorem mem_primitiveRoots {ζ : R} (h0 : 0 < k) : ζ ∈ primitiveRoots k R ↔ IsPrimitiveRoot ζ k := by
rw [primitiveRoots, mem_filter, Multiset.mem_toFinset, mem_nthRoots h0, and_iff_right_iff_imp]
exact IsPrimitiveRoot.pow_eq_one
@[simp]
theorem primitiveRoots_zero : primitiveRoots 0 R = ∅ := by
rw [primitiveRoots, nthRoots_zero, Multiset.toFinset_zero, Finset.filter_empty]
theorem isPrimitiveRoot_of_mem_primitiveRoots {ζ : R} (h : ζ ∈ primitiveRoots k R) :
IsPrimitiveRoot ζ k :=
k.eq_zero_or_pos.elim (fun hk => by simp [hk] at h) fun hk => (mem_primitiveRoots hk).1 h
end primitiveRoots
namespace IsPrimitiveRoot
variable {k l : ℕ}
theorem mk_of_lt (ζ : M) (hk : 0 < k) (h1 : ζ ^ k = 1) (h : ∀ l : ℕ, 0 < l → l < k → ζ ^ l ≠ 1) :
IsPrimitiveRoot ζ k := by
refine ⟨h1, fun l hl => ?_⟩
suffices k.gcd l = k by exact this ▸ k.gcd_dvd_right l
rw [eq_iff_le_not_lt]
refine ⟨Nat.le_of_dvd hk (k.gcd_dvd_left l), ?_⟩
intro h'; apply h _ (Nat.gcd_pos_of_pos_left _ hk) h'
exact pow_gcd_eq_one _ h1 hl
section CommMonoid
variable {ζ : M} {f : F}
@[nontriviality]
theorem of_subsingleton [Subsingleton M] (x : M) : IsPrimitiveRoot x 1 :=
⟨Subsingleton.elim _ _, fun _ _ => one_dvd _⟩
theorem pow_eq_one_iff_dvd (h : IsPrimitiveRoot ζ k) (l : ℕ) : ζ ^ l = 1 ↔ k ∣ l :=
⟨h.dvd_of_pow_eq_one l, by
rintro ⟨i, rfl⟩; simp only [pow_mul, h.pow_eq_one, one_pow, PNat.mul_coe]⟩
theorem isUnit (h : IsPrimitiveRoot ζ k) (h0 : 0 < k) : IsUnit ζ := by
apply isUnit_of_mul_eq_one ζ (ζ ^ (k - 1))
rw [← pow_succ', tsub_add_cancel_of_le h0.nat_succ_le, h.pow_eq_one]
theorem pow_ne_one_of_pos_of_lt (h : IsPrimitiveRoot ζ k) (h0 : 0 < l) (hl : l < k) : ζ ^ l ≠ 1 :=
mt (Nat.le_of_dvd h0 ∘ h.dvd_of_pow_eq_one _) <| not_le_of_lt hl
theorem ne_one (h : IsPrimitiveRoot ζ k) (hk : 1 < k) : ζ ≠ 1 :=
h.pow_ne_one_of_pos_of_lt zero_lt_one hk ∘ (pow_one ζ).trans
theorem pow_inj (h : IsPrimitiveRoot ζ k) ⦃i j : ℕ⦄ (hi : i < k) (hj : j < k) (H : ζ ^ i = ζ ^ j) :
i = j := by
wlog hij : i ≤ j generalizing i j
· exact (this hj hi H.symm (le_of_not_le hij)).symm
apply le_antisymm hij
rw [← tsub_eq_zero_iff_le]
apply Nat.eq_zero_of_dvd_of_lt _ (lt_of_le_of_lt tsub_le_self hj)
apply h.dvd_of_pow_eq_one
rw [← ((h.isUnit (lt_of_le_of_lt (Nat.zero_le _) hi)).pow i).mul_left_inj, ← pow_add,
tsub_add_cancel_of_le hij, H, one_mul]
theorem one : IsPrimitiveRoot (1 : M) 1 :=
{ pow_eq_one := pow_one _
dvd_of_pow_eq_one := fun _ _ => one_dvd _ }
@[simp]
theorem one_right_iff : IsPrimitiveRoot ζ 1 ↔ ζ = 1 := by
constructor
· intro h; rw [← pow_one ζ, h.pow_eq_one]
· rintro rfl; exact one
@[simp]
theorem coe_submonoidClass_iff {M B : Type*} [CommMonoid M] [SetLike B M] [SubmonoidClass B M]
{N : B} {ζ : N} : IsPrimitiveRoot (ζ : M) k ↔ IsPrimitiveRoot ζ k := by
simp_rw [iff_def]
norm_cast
@[simp]
theorem coe_units_iff {ζ : Mˣ} : IsPrimitiveRoot (ζ : M) k ↔ IsPrimitiveRoot ζ k := by
simp only [iff_def, Units.ext_iff, Units.val_pow_eq_pow_val, Units.val_one]
lemma isUnit_unit {ζ : M} {n} (hn) (hζ : IsPrimitiveRoot ζ n) :
IsPrimitiveRoot (hζ.isUnit hn).unit n := coe_units_iff.mp hζ
lemma isUnit_unit' {ζ : G} {n} (hn) (hζ : IsPrimitiveRoot ζ n) :
IsPrimitiveRoot (hζ.isUnit hn).unit' n := coe_units_iff.mp hζ
theorem pow_of_coprime (h : IsPrimitiveRoot ζ k) (i : ℕ) (hi : i.Coprime k) :
IsPrimitiveRoot (ζ ^ i) k := by
by_cases h0 : k = 0
· subst k; simp_all only [pow_one, Nat.coprime_zero_right]
rcases h.isUnit (Nat.pos_of_ne_zero h0) with ⟨ζ, rfl⟩
rw [← Units.val_pow_eq_pow_val]
rw [coe_units_iff] at h ⊢
refine
{ pow_eq_one := by rw [← pow_mul', pow_mul, h.pow_eq_one, one_pow]
dvd_of_pow_eq_one := ?_ }
intro l hl
apply h.dvd_of_pow_eq_one
rw [← pow_one ζ, ← zpow_natCast ζ, ← hi.gcd_eq_one, Nat.gcd_eq_gcd_ab, zpow_add, mul_pow,
← zpow_natCast, ← zpow_mul, mul_right_comm]
simp only [zpow_mul, hl, h.pow_eq_one, one_zpow, one_pow, one_mul, zpow_natCast]
theorem pow_of_prime (h : IsPrimitiveRoot ζ k) {p : ℕ} (hprime : Nat.Prime p) (hdiv : ¬p ∣ k) :
IsPrimitiveRoot (ζ ^ p) k :=
h.pow_of_coprime p (hprime.coprime_iff_not_dvd.2 hdiv)
theorem pow_iff_coprime (h : IsPrimitiveRoot ζ k) (h0 : 0 < k) (i : ℕ) :
IsPrimitiveRoot (ζ ^ i) k ↔ i.Coprime k := by
refine ⟨?_, h.pow_of_coprime i⟩
intro hi
obtain ⟨a, ha⟩ := i.gcd_dvd_left k
obtain ⟨b, hb⟩ := i.gcd_dvd_right k
suffices b = k by
-- Porting note: was `rwa [this, ← one_mul k, mul_left_inj' h0.ne', eq_comm] at hb`
rw [this, eq_comm, Nat.mul_left_eq_self_iff h0] at hb
rwa [Nat.Coprime]
rw [ha] at hi
rw [mul_comm] at hb
apply Nat.dvd_antisymm ⟨i.gcd k, hb⟩ (hi.dvd_of_pow_eq_one b _)
rw [← pow_mul', ← mul_assoc, ← hb, pow_mul, h.pow_eq_one, one_pow]
protected theorem orderOf (ζ : M) : IsPrimitiveRoot ζ (orderOf ζ) :=
⟨pow_orderOf_eq_one ζ, fun _ => orderOf_dvd_of_pow_eq_one⟩
theorem unique {ζ : M} (hk : IsPrimitiveRoot ζ k) (hl : IsPrimitiveRoot ζ l) : k = l :=
Nat.dvd_antisymm (hk.2 _ hl.1) (hl.2 _ hk.1)
theorem eq_orderOf (h : IsPrimitiveRoot ζ k) : k = orderOf ζ :=
h.unique (IsPrimitiveRoot.orderOf ζ)
protected theorem iff (hk : 0 < k) :
IsPrimitiveRoot ζ k ↔ ζ ^ k = 1 ∧ ∀ l : ℕ, 0 < l → l < k → ζ ^ l ≠ 1 := by
refine ⟨fun h => ⟨h.pow_eq_one, fun l hl' hl => ?_⟩,
fun ⟨hζ, hl⟩ => IsPrimitiveRoot.mk_of_lt ζ hk hζ hl⟩
rw [h.eq_orderOf] at hl
exact pow_ne_one_of_lt_orderOf hl'.ne' hl
protected theorem not_iff : ¬IsPrimitiveRoot ζ k ↔ orderOf ζ ≠ k :=
⟨fun h hk => h <| hk ▸ IsPrimitiveRoot.orderOf ζ,
fun h hk => h.symm <| hk.unique <| IsPrimitiveRoot.orderOf ζ⟩
theorem pow_mul_pow_lcm {ζ' : M} {k' : ℕ} (hζ : IsPrimitiveRoot ζ k) (hζ' : IsPrimitiveRoot ζ' k')
(hk : k ≠ 0) (hk' : k' ≠ 0) :
IsPrimitiveRoot
(ζ ^ (k / Nat.factorizationLCMLeft k k') * ζ' ^ (k' / Nat.factorizationLCMRight k k'))
(Nat.lcm k k') := by
convert IsPrimitiveRoot.orderOf _
convert ((Commute.all ζ ζ').orderOf_mul_pow_eq_lcm
(by simpa [← hζ.eq_orderOf]) (by simpa [← hζ'.eq_orderOf])).symm using 2
all_goals simp [hζ.eq_orderOf, hζ'.eq_orderOf]
theorem pow_of_dvd (h : IsPrimitiveRoot ζ k) {p : ℕ} (hp : p ≠ 0) (hdiv : p ∣ k) :
IsPrimitiveRoot (ζ ^ p) (k / p) := by
suffices orderOf (ζ ^ p) = k / p by exact this ▸ IsPrimitiveRoot.orderOf (ζ ^ p)
rw [orderOf_pow' _ hp, ← eq_orderOf h, Nat.gcd_eq_right hdiv]
protected theorem mem_rootsOfUnity {ζ : Mˣ} {n : ℕ+} (h : IsPrimitiveRoot ζ n) :
ζ ∈ rootsOfUnity n M :=
h.pow_eq_one
/-- If there is an `n`-th primitive root of unity in `R` and `b` divides `n`,
then there is a `b`-th primitive root of unity in `R`. -/
theorem pow {n : ℕ} {a b : ℕ} (hn : 0 < n) (h : IsPrimitiveRoot ζ n) (hprod : n = a * b) :
IsPrimitiveRoot (ζ ^ a) b := by
subst n
simp only [iff_def, ← pow_mul, h.pow_eq_one, eq_self_iff_true, true_and_iff]
intro l hl
-- Porting note: was `by rintro rfl; simpa only [Nat.not_lt_zero, zero_mul] using hn`
have ha0 : a ≠ 0 := left_ne_zero_of_mul hn.ne'
rw [← mul_dvd_mul_iff_left ha0]
exact h.dvd_of_pow_eq_one _ hl
lemma injOn_pow {n : ℕ} {ζ : M} (hζ : IsPrimitiveRoot ζ n) :
Set.InjOn (ζ ^ ·) (Finset.range n) := by
obtain (rfl|hn) := n.eq_zero_or_pos; · simp
intros i hi j hj e
rw [Finset.coe_range, Set.mem_Iio] at hi hj
have : (hζ.isUnit hn).unit ^ i = (hζ.isUnit hn).unit ^ j := Units.ext (by simpa using e)
rw [pow_inj_mod, ← orderOf_injective ⟨⟨Units.val, Units.val_one⟩, Units.val_mul⟩
Units.ext (hζ.isUnit hn).unit] at this
simpa [← hζ.eq_orderOf, Nat.mod_eq_of_lt, hi, hj] using this
section Maps
open Function
variable [FunLike F M N]
theorem map_of_injective [MonoidHomClass F M N] (h : IsPrimitiveRoot ζ k) (hf : Injective f) :
IsPrimitiveRoot (f ζ) k where
pow_eq_one := by rw [← map_pow, h.pow_eq_one, _root_.map_one]
dvd_of_pow_eq_one := by
rw [h.eq_orderOf]
intro l hl
rw [← map_pow, ← map_one f] at hl
exact orderOf_dvd_of_pow_eq_one (hf hl)
theorem of_map_of_injective [MonoidHomClass F M N] (h : IsPrimitiveRoot (f ζ) k)
(hf : Injective f) : IsPrimitiveRoot ζ k where
pow_eq_one := by apply_fun f; rw [map_pow, _root_.map_one, h.pow_eq_one]
dvd_of_pow_eq_one := by
rw [h.eq_orderOf]
intro l hl
apply_fun f at hl
rw [map_pow, _root_.map_one] at hl
exact orderOf_dvd_of_pow_eq_one hl
theorem map_iff_of_injective [MonoidHomClass F M N] (hf : Injective f) :
IsPrimitiveRoot (f ζ) k ↔ IsPrimitiveRoot ζ k :=
⟨fun h => h.of_map_of_injective hf, fun h => h.map_of_injective hf⟩
end Maps
end CommMonoid
section CommMonoidWithZero
variable {M₀ : Type*} [CommMonoidWithZero M₀]
theorem zero [Nontrivial M₀] : IsPrimitiveRoot (0 : M₀) 0 :=
⟨pow_zero 0, fun l hl => by
simpa [zero_pow_eq, show ∀ p, ¬p → False ↔ p from @Classical.not_not] using hl⟩
protected theorem ne_zero [Nontrivial M₀] {ζ : M₀} (h : IsPrimitiveRoot ζ k) : k ≠ 0 → ζ ≠ 0 :=
mt fun hn => h.unique (hn.symm ▸ IsPrimitiveRoot.zero)
end CommMonoidWithZero
section CancelCommMonoidWithZero
variable {M₀ : Type*} [CancelCommMonoidWithZero M₀]
lemma injOn_pow_mul {n : ℕ} {ζ : M₀} (hζ : IsPrimitiveRoot ζ n)
{α : M₀} (hα : α ≠ 0) :
Set.InjOn (ζ ^ · * α) (Finset.range n) := fun i hi j hj e ↦
hζ.injOn_pow hi hj (by simpa [mul_eq_mul_right_iff, or_iff_left hα] using e)
end CancelCommMonoidWithZero
section DivisionCommMonoid
variable {ζ : G}
theorem zpow_eq_one (h : IsPrimitiveRoot ζ k) : ζ ^ (k : ℤ) = 1 := by
rw [zpow_natCast]; exact h.pow_eq_one
theorem zpow_eq_one_iff_dvd (h : IsPrimitiveRoot ζ k) (l : ℤ) : ζ ^ l = 1 ↔ (k : ℤ) ∣ l := by
by_cases h0 : 0 ≤ l
· lift l to ℕ using h0; rw [zpow_natCast]; norm_cast; exact h.pow_eq_one_iff_dvd l
· have : 0 ≤ -l := by simp only [not_le, neg_nonneg] at h0 ⊢; exact le_of_lt h0
lift -l to ℕ using this with l' hl'
rw [← dvd_neg, ← hl']
norm_cast
rw [← h.pow_eq_one_iff_dvd, ← inv_inj, ← zpow_neg, ← hl', zpow_natCast, inv_one]
theorem inv (h : IsPrimitiveRoot ζ k) : IsPrimitiveRoot ζ⁻¹ k :=
{ pow_eq_one := by simp only [h.pow_eq_one, inv_one, eq_self_iff_true, inv_pow]
dvd_of_pow_eq_one := by
intro l hl
apply h.dvd_of_pow_eq_one l
rw [← inv_inj, ← inv_pow, hl, inv_one] }
@[simp]
theorem inv_iff : IsPrimitiveRoot ζ⁻¹ k ↔ IsPrimitiveRoot ζ k := by
refine ⟨?_, fun h => inv h⟩; intro h; rw [← inv_inv ζ]; exact inv h
theorem zpow_of_gcd_eq_one (h : IsPrimitiveRoot ζ k) (i : ℤ) (hi : i.gcd k = 1) :
IsPrimitiveRoot (ζ ^ i) k := by
by_cases h0 : 0 ≤ i
· lift i to ℕ using h0
rw [zpow_natCast]
exact h.pow_of_coprime i hi
have : 0 ≤ -i := by simp only [not_le, neg_nonneg] at h0 ⊢; exact le_of_lt h0
lift -i to ℕ using this with i' hi'
rw [← inv_iff, ← zpow_neg, ← hi', zpow_natCast]
apply h.pow_of_coprime
rw [Int.gcd, ← Int.natAbs_neg, ← hi'] at hi
exact hi
end DivisionCommMonoid
section CommRing
variable [CommRing R] {n : ℕ} {ζ : R}
theorem sub_one_ne_zero (hn : 1 < n) (hζ : IsPrimitiveRoot ζ n) : ζ - 1 ≠ 0 :=
sub_ne_zero.mpr <| hζ.ne_one hn
end CommRing
section IsDomain
variable {ζ : R}
variable [CommRing R] [IsDomain R]
@[simp]
theorem primitiveRoots_one : primitiveRoots 1 R = {(1 : R)} := by
apply Finset.eq_singleton_iff_unique_mem.2
constructor
· simp only [IsPrimitiveRoot.one_right_iff, mem_primitiveRoots zero_lt_one]
· intro x hx
rw [mem_primitiveRoots zero_lt_one, IsPrimitiveRoot.one_right_iff] at hx
exact hx
theorem neZero' {n : ℕ+} (hζ : IsPrimitiveRoot ζ n) : NeZero ((n : ℕ) : R) := by
let p := ringChar R
have hfin := multiplicity.finite_nat_iff.2 ⟨CharP.char_ne_one R p, n.pos⟩
obtain ⟨m, hm⟩ := multiplicity.exists_eq_pow_mul_and_not_dvd hfin
by_cases hp : p ∣ n
· obtain ⟨k, hk⟩ := Nat.exists_eq_succ_of_ne_zero (multiplicity.pos_of_dvd hfin hp).ne'
haveI : NeZero p := NeZero.of_pos (Nat.pos_of_dvd_of_pos hp n.pos)
haveI hpri : Fact p.Prime := CharP.char_is_prime_of_pos R p
have := hζ.pow_eq_one
rw [hm.1, hk, pow_succ', mul_assoc, pow_mul', ← frobenius_def, ← frobenius_one p] at this
exfalso
have hpos : 0 < p ^ k * m := by
refine mul_pos (pow_pos hpri.1.pos _) (Nat.pos_of_ne_zero fun h => ?_)
have H := hm.1
rw [h] at H
simp at H
refine hζ.pow_ne_one_of_pos_of_lt hpos ?_ (frobenius_inj R p this)
rw [hm.1, hk, pow_succ', mul_assoc, mul_comm p]
exact lt_mul_of_one_lt_right hpos hpri.1.one_lt
· exact NeZero.of_not_dvd R hp
nonrec theorem mem_nthRootsFinset (hζ : IsPrimitiveRoot ζ k) (hk : 0 < k) :
ζ ∈ nthRootsFinset k R :=
(mem_nthRootsFinset hk).2 hζ.pow_eq_one
end IsDomain
section IsDomain
variable [CommRing R]
variable {ζ : Rˣ} (h : IsPrimitiveRoot ζ k)
theorem eq_neg_one_of_two_right [NoZeroDivisors R] {ζ : R} (h : IsPrimitiveRoot ζ 2) : ζ = -1 := by
apply (eq_or_eq_neg_of_sq_eq_sq ζ 1 _).resolve_left
· rw [← pow_one ζ]; apply h.pow_ne_one_of_pos_of_lt <;> decide
· simp only [h.pow_eq_one, one_pow]
theorem neg_one (p : ℕ) [Nontrivial R] [h : CharP R p] (hp : p ≠ 2) :
IsPrimitiveRoot (-1 : R) 2 := by
convert IsPrimitiveRoot.orderOf (-1 : R)
rw [orderOf_neg_one, if_neg]
rwa [ringChar.eq_iff.mpr h]
/-- If `1 < k` then `(∑ i ∈ range k, ζ ^ i) = 0`. -/
theorem geom_sum_eq_zero [IsDomain R] {ζ : R} (hζ : IsPrimitiveRoot ζ k) (hk : 1 < k) :
∑ i ∈ range k, ζ ^ i = 0 := by
refine eq_zero_of_ne_zero_of_mul_left_eq_zero (sub_ne_zero_of_ne (hζ.ne_one hk).symm) ?_
rw [mul_neg_geom_sum, hζ.pow_eq_one, sub_self]
/-- If `1 < k`, then `ζ ^ k.pred = -(∑ i ∈ range k.pred, ζ ^ i)`. -/
theorem pow_sub_one_eq [IsDomain R] {ζ : R} (hζ : IsPrimitiveRoot ζ k) (hk : 1 < k) :
ζ ^ k.pred = -∑ i ∈ range k.pred, ζ ^ i := by
rw [eq_neg_iff_add_eq_zero, add_comm, ← sum_range_succ, ← Nat.succ_eq_add_one,
Nat.succ_pred_eq_of_pos (pos_of_gt hk), hζ.geom_sum_eq_zero hk]
/-- The (additive) monoid equivalence between `ZMod k`
and the powers of a primitive root of unity `ζ`. -/
def zmodEquivZPowers (h : IsPrimitiveRoot ζ k) : ZMod k ≃+ Additive (Subgroup.zpowers ζ) :=
AddEquiv.ofBijective
(AddMonoidHom.liftOfRightInverse (Int.castAddHom <| ZMod k) _ ZMod.intCast_rightInverse
⟨{ toFun := fun i => Additive.ofMul (⟨_, i, rfl⟩ : Subgroup.zpowers ζ)
map_zero' := by simp only [zpow_zero]; rfl
map_add' := by intro i j; simp only [zpow_add]; rfl }, fun i hi => by
simp only [AddMonoidHom.mem_ker, CharP.intCast_eq_zero_iff (ZMod k) k, AddMonoidHom.coe_mk,
Int.coe_castAddHom] at hi ⊢
obtain ⟨i, rfl⟩ := hi
simp [zpow_mul, h.pow_eq_one, one_zpow, zpow_natCast]⟩)
(by
constructor
· rw [injective_iff_map_eq_zero]
intro i hi
rw [Subtype.ext_iff] at hi
have := (h.zpow_eq_one_iff_dvd _).mp hi
rw [← (CharP.intCast_eq_zero_iff (ZMod k) k _).mpr this, eq_comm]
exact ZMod.intCast_rightInverse i
· rintro ⟨ξ, i, rfl⟩
refine ⟨Int.castAddHom (ZMod k) i, ?_⟩
rw [AddMonoidHom.liftOfRightInverse_comp_apply]
rfl)
@[simp]
theorem zmodEquivZPowers_apply_coe_int (i : ℤ) :
h.zmodEquivZPowers i = Additive.ofMul (⟨ζ ^ i, i, rfl⟩ : Subgroup.zpowers ζ) := by
rw [zmodEquivZPowers, AddEquiv.ofBijective_apply] -- Porting note: Original proof didn't have `rw`
exact AddMonoidHom.liftOfRightInverse_comp_apply _ _ ZMod.intCast_rightInverse _ _
@[simp]
theorem zmodEquivZPowers_apply_coe_nat (i : ℕ) :
h.zmodEquivZPowers i = Additive.ofMul (⟨ζ ^ i, i, rfl⟩ : Subgroup.zpowers ζ) := by
have : (i : ZMod k) = (i : ℤ) := by norm_cast
simp only [this, zmodEquivZPowers_apply_coe_int, zpow_natCast]
@[simp]
theorem zmodEquivZPowers_symm_apply_zpow (i : ℤ) :
h.zmodEquivZPowers.symm (Additive.ofMul (⟨ζ ^ i, i, rfl⟩ : Subgroup.zpowers ζ)) = i := by
rw [← h.zmodEquivZPowers.symm_apply_apply i, zmodEquivZPowers_apply_coe_int]
@[simp]
theorem zmodEquivZPowers_symm_apply_zpow' (i : ℤ) : h.zmodEquivZPowers.symm ⟨ζ ^ i, i, rfl⟩ = i :=
h.zmodEquivZPowers_symm_apply_zpow i
@[simp]
theorem zmodEquivZPowers_symm_apply_pow (i : ℕ) :
h.zmodEquivZPowers.symm (Additive.ofMul (⟨ζ ^ i, i, rfl⟩ : Subgroup.zpowers ζ)) = i := by
rw [← h.zmodEquivZPowers.symm_apply_apply i, zmodEquivZPowers_apply_coe_nat]
@[simp]
theorem zmodEquivZPowers_symm_apply_pow' (i : ℕ) : h.zmodEquivZPowers.symm ⟨ζ ^ i, i, rfl⟩ = i :=
h.zmodEquivZPowers_symm_apply_pow i
variable [IsDomain R]
theorem zpowers_eq {k : ℕ+} {ζ : Rˣ} (h : IsPrimitiveRoot ζ k) :
Subgroup.zpowers ζ = rootsOfUnity k R := by
apply SetLike.coe_injective
haveI F : Fintype (Subgroup.zpowers ζ) := Fintype.ofEquiv _ h.zmodEquivZPowers.toEquiv
refine
@Set.eq_of_subset_of_card_le Rˣ (Subgroup.zpowers ζ) (rootsOfUnity k R) F
(rootsOfUnity.fintype R k)
(Subgroup.zpowers_le_of_mem <| show ζ ∈ rootsOfUnity k R from h.pow_eq_one) ?_
calc
Fintype.card (rootsOfUnity k R) ≤ k := card_rootsOfUnity R k
_ = Fintype.card (ZMod k) := (ZMod.card k).symm
_ = Fintype.card (Subgroup.zpowers ζ) := Fintype.card_congr h.zmodEquivZPowers.toEquiv
lemma map_rootsOfUnity {S F} [CommRing S] [IsDomain S] [FunLike F R S] [MonoidHomClass F R S]
{ζ : R} {n : ℕ+} (hζ : IsPrimitiveRoot ζ n) {f : F} (hf : Function.Injective f) :
(rootsOfUnity n R).map (Units.map f) = rootsOfUnity n S := by
letI : CommMonoid Sˣ := inferInstance
replace hζ := hζ.isUnit_unit n.2
rw [← hζ.zpowers_eq,
← (hζ.map_of_injective (Units.map_injective (f := (f : R →* S)) hf)).zpowers_eq,
MonoidHom.map_zpowers]
/-- If `R` contains a `n`-th primitive root, and `S/R` is a ring extension,
then the `n`-th roots of unity in `R` and `S` are isomorphic.
Also see `IsPrimitiveRoot.map_rootsOfUnity` for the equality as `Subgroup Sˣ`. -/
@[simps! (config := .lemmasOnly) apply_coe_val apply_coe_inv_val]
noncomputable
def _root_.rootsOfUnityEquivOfPrimitiveRoots {S F} [CommRing S] [IsDomain S]
[FunLike F R S] [MonoidHomClass F R S]
{n : ℕ+} {f : F} (hf : Function.Injective f) (hζ : (primitiveRoots n R).Nonempty) :
(rootsOfUnity n R) ≃* rootsOfUnity n S :=
(Subgroup.equivMapOfInjective _ _ (Units.map_injective hf)).trans (MulEquiv.subgroupCongr
(((mem_primitiveRoots (k := n) n.2).mp hζ.choose_spec).map_rootsOfUnity hf))
lemma _root_.rootsOfUnityEquivOfPrimitiveRoots_symm_apply
{S F} [CommRing S] [IsDomain S] [FunLike F R S] [MonoidHomClass F R S]
{n : ℕ+} {f : F} (hf : Function.Injective f) (hζ : (primitiveRoots n R).Nonempty) (η) :
f ((rootsOfUnityEquivOfPrimitiveRoots hf hζ).symm η : Rˣ) = (η : Sˣ) := by
obtain ⟨ε, rfl⟩ := (rootsOfUnityEquivOfPrimitiveRoots hf hζ).surjective η
rw [MulEquiv.symm_apply_apply, val_rootsOfUnityEquivOfPrimitiveRoots_apply_coe]
-- Porting note: rephrased the next few lemmas to avoid `∃ (Prop)`
theorem eq_pow_of_mem_rootsOfUnity {k : ℕ+} {ζ ξ : Rˣ} (h : IsPrimitiveRoot ζ k)
(hξ : ξ ∈ rootsOfUnity k R) : ∃ (i : ℕ), i < k ∧ ζ ^ i = ξ := by
obtain ⟨n, rfl⟩ : ∃ n : ℤ, ζ ^ n = ξ := by rwa [← h.zpowers_eq] at hξ
have hk0 : (0 : ℤ) < k := mod_cast k.pos
let i := n % k
have hi0 : 0 ≤ i := Int.emod_nonneg _ (ne_of_gt hk0)
lift i to ℕ using hi0 with i₀ hi₀
refine ⟨i₀, ?_, ?_⟩
· zify; rw [hi₀]; exact Int.emod_lt_of_pos _ hk0
· rw [← zpow_natCast, hi₀, ← Int.emod_add_ediv n k, zpow_add, zpow_mul, h.zpow_eq_one, one_zpow,
mul_one]
/-- A version of `IsPrimitiveRoot.eq_pow_of_mem_rootsOfUnity` that takes a natural number `k`
as argument instead of a `PNat` (and `ζ : R` instead of `ζ : Rˣ`). -/
lemma eq_pow_of_mem_rootsOfUnity' {k : ℕ} (hk : 0 < k) {ζ : R} (hζ : IsPrimitiveRoot ζ k) {ξ : Rˣ}
(hξ : ξ ∈ rootsOfUnity (⟨k, hk⟩ : ℕ+) R) :
∃ i < k, ζ ^ i = ξ := by
have hζ' : IsPrimitiveRoot (hζ.isUnit hk).unit (⟨k, hk⟩ : ℕ+) := isUnit_unit hk hζ
obtain ⟨i, hi₁, hi₂⟩ := hζ'.eq_pow_of_mem_rootsOfUnity hξ
simpa only [Units.val_pow_eq_pow_val, IsUnit.unit_spec]
using ⟨i, hi₁, congrArg ((↑) : Rˣ → R) hi₂⟩
theorem eq_pow_of_pow_eq_one {k : ℕ} {ζ ξ : R} (h : IsPrimitiveRoot ζ k) (hξ : ξ ^ k = 1)
(h0 : 0 < k) : ∃ i < k, ζ ^ i = ξ := by
lift ζ to Rˣ using h.isUnit h0
lift ξ to Rˣ using isUnit_ofPowEqOne hξ h0.ne'
lift k to ℕ+ using h0
simp only [← Units.val_pow_eq_pow_val, ← Units.ext_iff]
rw [coe_units_iff] at h
apply h.eq_pow_of_mem_rootsOfUnity
rw [mem_rootsOfUnity, Units.ext_iff, Units.val_pow_eq_pow_val, hξ, Units.val_one]
theorem isPrimitiveRoot_iff' {k : ℕ+} {ζ ξ : Rˣ} (h : IsPrimitiveRoot ζ k) :
IsPrimitiveRoot ξ k ↔ ∃ i < (k : ℕ), i.Coprime k ∧ ζ ^ i = ξ := by
constructor
· intro hξ
obtain ⟨i, hik, rfl⟩ := h.eq_pow_of_mem_rootsOfUnity hξ.pow_eq_one
rw [h.pow_iff_coprime k.pos] at hξ
exact ⟨i, hik, hξ, rfl⟩
· rintro ⟨i, -, hi, rfl⟩; exact h.pow_of_coprime i hi
theorem isPrimitiveRoot_iff {k : ℕ} {ζ ξ : R} (h : IsPrimitiveRoot ζ k) (h0 : 0 < k) :
IsPrimitiveRoot ξ k ↔ ∃ i < k, i.Coprime k ∧ ζ ^ i = ξ := by
constructor
· intro hξ
obtain ⟨i, hik, rfl⟩ := h.eq_pow_of_pow_eq_one hξ.pow_eq_one h0
rw [h.pow_iff_coprime h0] at hξ
exact ⟨i, hik, hξ, rfl⟩
· rintro ⟨i, -, hi, rfl⟩; exact h.pow_of_coprime i hi
theorem nthRoots_eq {n : ℕ} {ζ : R} (hζ : IsPrimitiveRoot ζ n)
{α a : R} (e : α ^ n = a) :
nthRoots n a = (Multiset.range n).map (ζ ^ · * α) := by
obtain (rfl|hn) := n.eq_zero_or_pos; · simp
by_cases hα : α = 0
· rw [hα, zero_pow hn.ne'] at e
simp only [hα, e.symm, nthRoots_zero_right, mul_zero,
Finset.range_val, Multiset.map_const', Multiset.card_range]
classical
symm; apply Multiset.eq_of_le_of_card_le
· rw [← Finset.range_val,
← Finset.image_val_of_injOn (hζ.injOn_pow_mul hα), Finset.val_le_iff_val_subset]
intro x hx
simp only [Finset.image_val, Finset.range_val, Multiset.mem_dedup, Multiset.mem_map,
Multiset.mem_range] at hx
obtain ⟨m, _, rfl⟩ := hx
rw [mem_nthRoots hn, mul_pow, e, ← pow_mul, mul_comm m,
pow_mul, hζ.pow_eq_one, one_pow, one_mul]
· simpa only [Multiset.card_map, Multiset.card_range] using card_nthRoots n a
theorem card_nthRoots {n : ℕ} {ζ : R} (hζ : IsPrimitiveRoot ζ n) (a : R) :
Multiset.card (nthRoots n a) = if ∃ α, α ^ n = a then n else 0 := by
split_ifs with h
· obtain ⟨α, hα⟩ := h
rw [nthRoots_eq hζ hα, Multiset.card_map, Multiset.card_range]
· obtain (rfl|hn) := n.eq_zero_or_pos; · simp
push_neg at h
simpa only [Multiset.card_eq_zero, Multiset.eq_zero_iff_forall_not_mem, mem_nthRoots hn]
theorem card_rootsOfUnity' {n : ℕ+} (h : IsPrimitiveRoot ζ n) :
Fintype.card (rootsOfUnity n R) = n := by
let e := h.zmodEquivZPowers
haveI F : Fintype (Subgroup.zpowers ζ) := Fintype.ofEquiv _ e.toEquiv
calc
Fintype.card (rootsOfUnity n R) = Fintype.card (Subgroup.zpowers ζ) :=
Fintype.card_congr <| by rw [h.zpowers_eq]
_ = Fintype.card (ZMod n) := Fintype.card_congr e.toEquiv.symm
_ = n := ZMod.card n
theorem card_rootsOfUnity {ζ : R} {n : ℕ+} (h : IsPrimitiveRoot ζ n) :
Fintype.card (rootsOfUnity n R) = n := by
obtain ⟨ζ, hζ⟩ := h.isUnit n.pos
rw [← hζ, IsPrimitiveRoot.coe_units_iff] at h
exact h.card_rootsOfUnity'
/-- The cardinality of the multiset `nthRoots ↑n (1 : R)` is `n`
if there is a primitive root of unity in `R`. -/
theorem card_nthRoots_one {ζ : R} {n : ℕ} (h : IsPrimitiveRoot ζ n) :
Multiset.card (nthRoots n (1 : R)) = n := by rw [card_nthRoots h, if_pos ⟨ζ, h.pow_eq_one⟩]
theorem nthRoots_nodup {ζ : R} {n : ℕ} (h : IsPrimitiveRoot ζ n) {a : R} (ha : a ≠ 0) :
(nthRoots n a).Nodup := by
obtain (rfl|hn) := n.eq_zero_or_pos; · simp
by_cases h : ∃ α, α ^ n = a
· obtain ⟨α, hα⟩ := h
by_cases hα' : α = 0
· exact (ha (by rwa [hα', zero_pow hn.ne', eq_comm] at hα)).elim
rw [nthRoots_eq h hα, Multiset.nodup_map_iff_inj_on (Multiset.nodup_range n)]
exact h.injOn_pow_mul hα'
· suffices nthRoots n a = 0 by simp [this]
push_neg at h
simpa only [Multiset.card_eq_zero, Multiset.eq_zero_iff_forall_not_mem, mem_nthRoots hn]
/-- The multiset `nthRoots ↑n (1 : R)` has no repeated elements
if there is a primitive root of unity in `R`. -/
theorem nthRoots_one_nodup {ζ : R} {n : ℕ} (h : IsPrimitiveRoot ζ n) :
(nthRoots n (1 : R)).Nodup :=
h.nthRoots_nodup one_ne_zero
@[simp]
theorem card_nthRootsFinset {ζ : R} {n : ℕ} (h : IsPrimitiveRoot ζ n) :
(nthRootsFinset n R).card = n := by
rw [nthRootsFinset, ← Multiset.toFinset_eq (nthRoots_one_nodup h), card_mk, h.card_nthRoots_one]
open scoped Nat
/-- If an integral domain has a primitive `k`-th root of unity, then it has `φ k` of them. -/
theorem card_primitiveRoots {ζ : R} {k : ℕ} (h : IsPrimitiveRoot ζ k) :
(primitiveRoots k R).card = φ k := by
by_cases h0 : k = 0
· simp [h0]
symm
refine Finset.card_bij (fun i _ ↦ ζ ^ i) ?_ ?_ ?_
· simp only [true_and_iff, and_imp, mem_filter, mem_range, mem_univ]
rintro i - hi
rw [mem_primitiveRoots (Nat.pos_of_ne_zero h0)]
exact h.pow_of_coprime i hi.symm
· simp only [true_and_iff, and_imp, mem_filter, mem_range, mem_univ]
rintro i hi - j hj - H
exact h.pow_inj hi hj H
· simp only [exists_prop, true_and_iff, mem_filter, mem_range, mem_univ]
intro ξ hξ
rw [mem_primitiveRoots (Nat.pos_of_ne_zero h0),
h.isPrimitiveRoot_iff (Nat.pos_of_ne_zero h0)] at hξ
rcases hξ with ⟨i, hin, hi, H⟩
exact ⟨i, ⟨hin, hi.symm⟩, H⟩
/-- The sets `primitiveRoots k R` are pairwise disjoint. -/
theorem disjoint {k l : ℕ} (h : k ≠ l) : Disjoint (primitiveRoots k R) (primitiveRoots l R) :=
Finset.disjoint_left.2 fun _ hk hl =>
h <|
(isPrimitiveRoot_of_mem_primitiveRoots hk).unique <| isPrimitiveRoot_of_mem_primitiveRoots hl
/-- `nthRoots n` as a `Finset` is equal to the union of `primitiveRoots i R` for `i ∣ n`
if there is a primitive root of unity in `R`.
This holds for any `Nat`, not just `PNat`, see `nthRoots_one_eq_bUnion_primitive_roots`. -/
theorem nthRoots_one_eq_biUnion_primitiveRoots' {ζ : R} {n : ℕ+} (h : IsPrimitiveRoot ζ n) :
nthRootsFinset n R = (Nat.divisors ↑n).biUnion fun i => primitiveRoots i R := by
symm
apply Finset.eq_of_subset_of_card_le
· intro x
simp only [nthRootsFinset, ← Multiset.toFinset_eq (nthRoots_one_nodup h), exists_prop,
Finset.mem_biUnion, Finset.mem_filter, Finset.mem_range, mem_nthRoots, Finset.mem_mk,
Nat.mem_divisors, and_true_iff, Ne, PNat.ne_zero, PNat.pos, not_false_iff]
rintro ⟨a, ⟨d, hd⟩, ha⟩
have hazero : 0 < a := by
contrapose! hd with ha0
simp_all only [nonpos_iff_eq_zero, zero_mul]
exact n.ne_zero
rw [mem_primitiveRoots hazero] at ha
rw [hd, pow_mul, ha.pow_eq_one, one_pow]
· apply le_of_eq
rw [h.card_nthRootsFinset, Finset.card_biUnion]
· nth_rw 1 [← Nat.sum_totient n]
refine sum_congr rfl ?_
simp only [Nat.mem_divisors]
rintro k ⟨⟨d, hd⟩, -⟩
rw [mul_comm] at hd
rw [(h.pow n.pos hd).card_primitiveRoots]
· intro i _ j _ hdiff
exact disjoint hdiff
/-- `nthRoots n` as a `Finset` is equal to the union of `primitiveRoots i R` for `i ∣ n`
if there is a primitive root of unity in `R`. -/
theorem nthRoots_one_eq_biUnion_primitiveRoots {ζ : R} {n : ℕ} (h : IsPrimitiveRoot ζ n) :
nthRootsFinset n R = (Nat.divisors n).biUnion fun i => primitiveRoots i R := by
by_cases hn : n = 0
· simp [hn]
exact nthRoots_one_eq_biUnion_primitiveRoots' (n := ⟨n, Nat.pos_of_ne_zero hn⟩) h
end IsDomain
section Automorphisms
variable [CommRing S] [IsDomain S] {μ : S} {n : ℕ+} (hμ : IsPrimitiveRoot μ n) (R) [CommRing R]
[Algebra R S]
/-- The `MonoidHom` that takes an automorphism to the power of μ that μ gets mapped to under it. -/
noncomputable def autToPow : (S ≃ₐ[R] S) →* (ZMod n)ˣ :=
let μ' := hμ.toRootsOfUnity
have ho : orderOf μ' = n := by
rw [hμ.eq_orderOf, ← hμ.val_toRootsOfUnity_coe, orderOf_units, Subgroup.orderOf_coe]
MonoidHom.toHomUnits
{ toFun := fun σ => (map_rootsOfUnity_eq_pow_self σ.toAlgHom μ').choose
map_one' := by
dsimp only
generalize_proofs h1
have h := h1.choose_spec
dsimp only [μ', AlgEquiv.one_apply, AlgEquiv.toRingEquiv_eq_coe, RingEquiv.toRingHom_eq_coe,
RingEquiv.coe_toRingHom, AlgEquiv.coe_ringEquiv] at *
replace h : μ' = μ' ^ h1.choose :=
rootsOfUnity.coe_injective (by simpa only [rootsOfUnity.coe_pow] using h)
nth_rw 1 [← pow_one μ'] at h
rw [← Nat.cast_one, ZMod.natCast_eq_natCast_iff, ← ho, ← pow_eq_pow_iff_modEq, h]
map_mul' := by
intro x y
dsimp only
generalize_proofs hxy' hx' hy'
have hxy := hxy'.choose_spec
have hx := hx'.choose_spec
have hy := hy'.choose_spec
dsimp only [μ', AlgEquiv.toRingEquiv_eq_coe, RingEquiv.toRingHom_eq_coe,
RingEquiv.coe_toRingHom, AlgEquiv.coe_ringEquiv, AlgEquiv.mul_apply] at *
replace hxy : x (((μ' : Sˣ) : S) ^ hy'.choose) = ((μ' : Sˣ) : S) ^ hxy'.choose := hy ▸ hxy
rw [map_pow] at hxy
replace hxy : (((μ' : Sˣ) : S) ^ hx'.choose) ^ hy'.choose = ((μ' : Sˣ) : S) ^ hxy'.choose :=
hx ▸ hxy
rw [← pow_mul] at hxy
replace hxy : μ' ^ (hx'.choose * hy'.choose) = μ' ^ hxy'.choose :=
rootsOfUnity.coe_injective (by simpa only [rootsOfUnity.coe_pow] using hxy)
rw [← Nat.cast_mul, ZMod.natCast_eq_natCast_iff, ← ho, ← pow_eq_pow_iff_modEq, hxy] }
-- We are not using @[simps] in aut_to_pow to avoid a timeout.
theorem coe_autToPow_apply (f : S ≃ₐ[R] S) :
(autToPow R hμ f : ZMod n) =
((map_rootsOfUnity_eq_pow_self f hμ.toRootsOfUnity).choose : ZMod n) :=
rfl
@[simp]
theorem autToPow_spec (f : S ≃ₐ[R] S) : μ ^ (hμ.autToPow R f : ZMod n).val = f μ := by
rw [IsPrimitiveRoot.coe_autToPow_apply]
generalize_proofs h
have := h.choose_spec
refine (?_ : ((hμ.toRootsOfUnity : Sˣ) : S) ^ _ = _).trans this.symm
rw [← rootsOfUnity.coe_pow, ← rootsOfUnity.coe_pow]
congr 2
rw [pow_eq_pow_iff_modEq, ZMod.val_natCast, hμ.eq_orderOf, ← Subgroup.orderOf_coe,
← orderOf_units]
exact Nat.mod_modEq _ _
end Automorphisms
end IsPrimitiveRoot
|
RingTheory\RootsOfUnity\Complex.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.Analysis.SpecialFunctions.Complex.Log
import Mathlib.RingTheory.RootsOfUnity.Basic
/-!
# Complex roots of unity
In this file we show that the `n`-th complex roots of unity
are exactly the complex numbers `exp (2 * π * I * (i / n))` for `i ∈ Finset.range n`.
## Main declarations
* `Complex.mem_rootsOfUnity`: the complex `n`-th roots of unity are exactly the
complex numbers of the form `exp (2 * π * I * (i / n))` for some `i < n`.
* `Complex.card_rootsOfUnity`: the number of `n`-th roots of unity is exactly `n`.
* `Complex.norm_rootOfUnity_eq_one`: A complex root of unity has norm `1`.
-/
namespace Complex
open Polynomial Real
open scoped Nat Real
theorem isPrimitiveRoot_exp_of_coprime (i n : ℕ) (h0 : n ≠ 0) (hi : i.Coprime n) :
IsPrimitiveRoot (exp (2 * π * I * (i / n))) n := by
rw [IsPrimitiveRoot.iff_def]
simp only [← exp_nat_mul, exp_eq_one_iff]
have hn0 : (n : ℂ) ≠ 0 := mod_cast h0
constructor
· use i
field_simp [hn0, mul_comm (i : ℂ), mul_comm (n : ℂ)]
· simp only [hn0, mul_right_comm _ _ ↑n, mul_left_inj' two_pi_I_ne_zero, Ne, not_false_iff,
mul_comm _ (i : ℂ), ← mul_assoc _ (i : ℂ), exists_imp, field_simps]
norm_cast
rintro l k hk
conv_rhs at hk => rw [mul_comm, ← mul_assoc]
have hz : 2 * ↑π * I ≠ 0 := by simp [pi_pos.ne.symm, I_ne_zero]
field_simp [hz] at hk
norm_cast at hk
have : n ∣ i * l := by rw [← Int.natCast_dvd_natCast, hk, mul_comm]; apply dvd_mul_left
exact hi.symm.dvd_of_dvd_mul_left this
theorem isPrimitiveRoot_exp (n : ℕ) (h0 : n ≠ 0) : IsPrimitiveRoot (exp (2 * π * I / n)) n := by
simpa only [Nat.cast_one, one_div] using
isPrimitiveRoot_exp_of_coprime 1 n h0 n.coprime_one_left
theorem isPrimitiveRoot_iff (ζ : ℂ) (n : ℕ) (hn : n ≠ 0) :
IsPrimitiveRoot ζ n ↔ ∃ i < (n : ℕ), ∃ _ : i.Coprime n, exp (2 * π * I * (i / n)) = ζ := by
have hn0 : (n : ℂ) ≠ 0 := mod_cast hn
constructor; swap
· rintro ⟨i, -, hi, rfl⟩; exact isPrimitiveRoot_exp_of_coprime i n hn hi
intro h
obtain ⟨i, hi, rfl⟩ :=
(isPrimitiveRoot_exp n hn).eq_pow_of_pow_eq_one h.pow_eq_one (Nat.pos_of_ne_zero hn)
refine ⟨i, hi, ((isPrimitiveRoot_exp n hn).pow_iff_coprime (Nat.pos_of_ne_zero hn) i).mp h, ?_⟩
rw [← exp_nat_mul]
congr 1
field_simp [hn0, mul_comm (i : ℂ)]
/-- The complex `n`-th roots of unity are exactly the
complex numbers of the form `exp (2 * Real.pi * Complex.I * (i / n))` for some `i < n`. -/
nonrec theorem mem_rootsOfUnity (n : ℕ+) (x : Units ℂ) :
x ∈ rootsOfUnity n ℂ ↔ ∃ i < (n : ℕ), exp (2 * π * I * (i / n)) = x := by
rw [mem_rootsOfUnity, Units.ext_iff, Units.val_pow_eq_pow_val, Units.val_one]
have hn0 : (n : ℂ) ≠ 0 := mod_cast n.ne_zero
constructor
· intro h
obtain ⟨i, hi, H⟩ : ∃ i < (n : ℕ), exp (2 * π * I / n) ^ i = x := by
simpa only using (isPrimitiveRoot_exp n n.ne_zero).eq_pow_of_pow_eq_one h n.pos
refine ⟨i, hi, ?_⟩
rw [← H, ← exp_nat_mul]
congr 1
field_simp [hn0, mul_comm (i : ℂ)]
· rintro ⟨i, _, H⟩
rw [← H, ← exp_nat_mul, exp_eq_one_iff]
use i
field_simp [hn0, mul_comm ((n : ℕ) : ℂ), mul_comm (i : ℂ)]
theorem card_rootsOfUnity (n : ℕ+) : Fintype.card (rootsOfUnity n ℂ) = n :=
(isPrimitiveRoot_exp n n.ne_zero).card_rootsOfUnity
theorem card_primitiveRoots (k : ℕ) : (primitiveRoots k ℂ).card = φ k := by
by_cases h : k = 0
· simp [h]
exact (isPrimitiveRoot_exp k h).card_primitiveRoots
end Complex
theorem IsPrimitiveRoot.norm'_eq_one {ζ : ℂ} {n : ℕ} (h : IsPrimitiveRoot ζ n) (hn : n ≠ 0) :
‖ζ‖ = 1 :=
Complex.norm_eq_one_of_pow_eq_one h.pow_eq_one hn
theorem IsPrimitiveRoot.nnnorm_eq_one {ζ : ℂ} {n : ℕ} (h : IsPrimitiveRoot ζ n) (hn : n ≠ 0) :
‖ζ‖₊ = 1 :=
Subtype.ext <| h.norm'_eq_one hn
theorem IsPrimitiveRoot.arg_ext {n m : ℕ} {ζ μ : ℂ} (hζ : IsPrimitiveRoot ζ n)
(hμ : IsPrimitiveRoot μ m) (hn : n ≠ 0) (hm : m ≠ 0) (h : ζ.arg = μ.arg) : ζ = μ :=
Complex.ext_abs_arg ((hζ.norm'_eq_one hn).trans (hμ.norm'_eq_one hm).symm) h
theorem IsPrimitiveRoot.arg_eq_zero_iff {n : ℕ} {ζ : ℂ} (hζ : IsPrimitiveRoot ζ n) (hn : n ≠ 0) :
ζ.arg = 0 ↔ ζ = 1 :=
⟨fun h => hζ.arg_ext IsPrimitiveRoot.one hn one_ne_zero (h.trans Complex.arg_one.symm), fun h =>
h.symm ▸ Complex.arg_one⟩
theorem IsPrimitiveRoot.arg_eq_pi_iff {n : ℕ} {ζ : ℂ} (hζ : IsPrimitiveRoot ζ n) (hn : n ≠ 0) :
ζ.arg = Real.pi ↔ ζ = -1 :=
⟨fun h =>
hζ.arg_ext (IsPrimitiveRoot.neg_one 0 two_ne_zero.symm) hn two_ne_zero
(h.trans Complex.arg_neg_one.symm),
fun h => h.symm ▸ Complex.arg_neg_one⟩
set_option tactic.skipAssignedInstances false in
theorem IsPrimitiveRoot.arg {n : ℕ} {ζ : ℂ} (h : IsPrimitiveRoot ζ n) (hn : n ≠ 0) :
∃ i : ℤ, ζ.arg = i / n * (2 * Real.pi) ∧ IsCoprime i n ∧ i.natAbs < n := by
rw [Complex.isPrimitiveRoot_iff _ _ hn] at h
obtain ⟨i, h, hin, rfl⟩ := h
rw [mul_comm, ← mul_assoc, Complex.exp_mul_I]
refine ⟨if i * 2 ≤ n then i else i - n, ?_, ?_, ?_⟩
on_goal 2 =>
replace hin := Nat.isCoprime_iff_coprime.mpr hin
split_ifs
· exact hin
· convert hin.add_mul_left_left (-1) using 1
rw [mul_neg_one, sub_eq_add_neg]
on_goal 2 =>
split_ifs with h₂
· exact mod_cast h
suffices (i - n : ℤ).natAbs = n - i by
rw [this]
apply tsub_lt_self hn.bot_lt
contrapose! h₂
rw [Nat.eq_zero_of_le_zero h₂, zero_mul]
exact zero_le _
rw [← Int.natAbs_neg, neg_sub, Int.natAbs_eq_iff]
exact Or.inl (Int.ofNat_sub h.le).symm
split_ifs with h₂
· convert Complex.arg_cos_add_sin_mul_I _
· push_cast; rfl
· push_cast; rfl
field_simp [hn]
refine ⟨(neg_lt_neg Real.pi_pos).trans_le ?_, ?_⟩
· rw [neg_zero]
exact mul_nonneg (mul_nonneg i.cast_nonneg <| by simp [Real.pi_pos.le])
(by rw [inv_nonneg]; simp only [Nat.cast_nonneg])
rw [← mul_rotate', mul_div_assoc]
rw [← mul_one n] at h₂
exact mul_le_of_le_one_right Real.pi_pos.le
((div_le_iff' <| mod_cast pos_of_gt h).mpr <| mod_cast h₂)
rw [← Complex.cos_sub_two_pi, ← Complex.sin_sub_two_pi]
convert Complex.arg_cos_add_sin_mul_I _
· push_cast
rw [← sub_one_mul, sub_div, div_self]
exact mod_cast hn
· push_cast
rw [← sub_one_mul, sub_div, div_self]
exact mod_cast hn
field_simp [hn]
refine ⟨?_, le_trans ?_ Real.pi_pos.le⟩
on_goal 2 =>
rw [mul_div_assoc]
exact mul_nonpos_of_nonpos_of_nonneg (sub_nonpos.mpr <| mod_cast h.le)
(div_nonneg (by simp [Real.pi_pos.le]) <| by simp)
rw [← mul_rotate', mul_div_assoc, neg_lt, ← mul_neg, mul_lt_iff_lt_one_right Real.pi_pos, ←
neg_div, ← neg_mul, neg_sub, div_lt_iff, one_mul, sub_mul, sub_lt_comm, ← mul_sub_one]
· norm_num
exact mod_cast not_le.mp h₂
· exact Nat.cast_pos.mpr hn.bot_lt
lemma Complex.norm_eq_one_of_mem_rootsOfUnity {ζ : ℂˣ} {n : ℕ+} (hζ : ζ ∈ rootsOfUnity n ℂ) :
‖(ζ : ℂ)‖ = 1 := by
refine norm_eq_one_of_pow_eq_one ?_ <| n.ne_zero
norm_cast
rw [_root_.mem_rootsOfUnity] at hζ
rw [hζ, Units.val_one]
|
RingTheory\RootsOfUnity\Lemmas.lean | /-
Copyright (c) 2024 Michael Stoll. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Stoll
-/
import Mathlib.FieldTheory.KummerExtension
import Mathlib.RingTheory.RootsOfUnity.Basic
/-!
# More results on primitive roots of unity
(We put these in a separate file because of the `KummerExtension` import.)
Assume that `μ` is a primitive `n`th root of unity in an integral domain `R`. Then
$$ \prod_{k=1}^{n-1} (1 - \mu^k) = n \,; $$
see `IsPrimitiveRoot.prod_one_sub_pow_eq_order` and its variant
`IsPrimitiveRoot.prod_pow_sub_one_eq_order` in terms of `∏ (μ^k - 1)`.
We use this to deduce that `n` is divisible by `(μ - 1)^k` in `ℤ[μ] ⊆ R` when `k < n`.
-/
variable {R : Type*} [CommRing R] [IsDomain R]
namespace IsPrimitiveRoot
open Finset Polynomial BigOperators
/-- If `μ` is a primitive `n`th root of unity in `R`, then `∏(1≤k<n) (1-μ^k) = n`.
(Stated with `n+1` in place of `n` to avoid the condition `n ≠ 0`.) -/
lemma prod_one_sub_pow_eq_order {n : ℕ} {μ : R} (hμ : IsPrimitiveRoot μ (n + 1)) :
∏ k ∈ range n, (1 - μ ^ (k + 1)) = n + 1 := by
have := X_pow_sub_C_eq_prod hμ n.zero_lt_succ (one_pow (n + 1))
rw [C_1, ← mul_geom_sum, prod_range_succ', pow_zero, mul_one, mul_comm, eq_comm] at this
replace this := mul_right_cancel₀ (Polynomial.X_sub_C_ne_zero 1) this
apply_fun Polynomial.eval 1 at this
simpa only [mul_one, map_pow, eval_prod, eval_sub, eval_X, eval_pow, eval_C, eval_geom_sum,
one_pow, sum_const, card_range, nsmul_eq_mul, Nat.cast_add, Nat.cast_one] using this
/-- If `μ` is a primitive `n`th root of unity in `R`, then `(-1)^(n-1) * ∏(1≤k<n) (μ^k-1) = n`.
(Stated with `n+1` in place of `n` to avoid the condition `n ≠ 0`.) -/
lemma prod_pow_sub_one_eq_order {n : ℕ} {μ : R} (hμ : IsPrimitiveRoot μ (n + 1)) :
(-1) ^ n * ∏ k ∈ range n, (μ ^ (k + 1) - 1) = n + 1 := by
have : (-1 : R) ^ n = ∏ k ∈ range n, -1 := by rw [prod_const, card_range]
simp only [this, ← prod_mul_distrib, neg_one_mul, neg_sub, ← prod_one_sub_pow_eq_order hμ]
open Algebra in
/-- If `μ` is a primitive `n`th root of unity in `R` and `k < n`, then `n` is divisible
by `(μ-1)^k` in `ℤ[μ] ⊆ R`. -/
lemma self_sub_one_pow_dvd_order {k n : ℕ} (hn : k < n) {μ : R} (hμ : IsPrimitiveRoot μ n) :
∃ z ∈ adjoin ℤ {μ}, n = z * (μ - 1) ^ k := by
let n' + 1 := n
obtain ⟨m, rfl⟩ := Nat.exists_eq_add_of_le' (Nat.le_of_lt_succ hn)
have hdvd k : ∃ z ∈ adjoin ℤ {μ}, μ ^ k - 1 = z * (μ - 1) := by
refine ⟨(Finset.range k).sum (μ ^ ·), ?_, (geom_sum_mul μ k).symm⟩
exact Subalgebra.sum_mem _ fun m _ ↦ Subalgebra.pow_mem _ (self_mem_adjoin_singleton _ μ) _
let Z k := Classical.choose <| hdvd k
have Zdef k : Z k ∈ adjoin ℤ {μ} ∧ μ ^ k - 1 = Z k * (μ - 1) :=
Classical.choose_spec <| hdvd k
refine ⟨(-1) ^ (m + k) * (∏ j ∈ range k, Z (j + 1)) * ∏ j ∈ Ico k (m + k), (μ ^ (j + 1) - 1),
?_, ?_⟩
· apply Subalgebra.mul_mem
· apply Subalgebra.mul_mem
· exact Subalgebra.pow_mem _ (Subalgebra.neg_mem _ <| Subalgebra.one_mem _) _
· exact Subalgebra.prod_mem _ fun _ _ ↦ (Zdef _).1
· refine Subalgebra.prod_mem _ fun _ _ ↦ ?_
apply Subalgebra.sub_mem
· exact Subalgebra.pow_mem _ (self_mem_adjoin_singleton ℤ μ) _
· exact Subalgebra.one_mem _
· push_cast
have := Nat.cast_add (R := R) m k ▸ hμ.prod_pow_sub_one_eq_order
rw [← this, mul_assoc, mul_assoc]
congr 1
conv => enter [2, 2, 2]; rw [← card_range k]
rw [← prod_range_mul_prod_Ico _ (Nat.le_add_left k m), mul_comm _ (_ ^ card _), ← mul_assoc,
prod_mul_pow_card]
conv => enter [2, 1, 2, j]; rw [← (Zdef _).2]
end IsPrimitiveRoot
|
RingTheory\RootsOfUnity\Minpoly.lean | /-
Copyright (c) 2020 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca, Johan Commelin
-/
import Mathlib.RingTheory.RootsOfUnity.Basic
import Mathlib.FieldTheory.Minpoly.IsIntegrallyClosed
import Mathlib.Algebra.GCDMonoid.IntegrallyClosed
import Mathlib.FieldTheory.Finite.Basic
/-!
# Minimal polynomial of roots of unity
We gather several results about minimal polynomial of root of unity.
## Main results
* `IsPrimitiveRoot.totient_le_degree_minpoly`: The degree of the minimal polynomial of an `n`-th
primitive root of unity is at least `totient n`.
-/
open minpoly Polynomial
open scoped Polynomial
namespace IsPrimitiveRoot
section CommRing
variable {n : ℕ} {K : Type*} [CommRing K] {μ : K} (h : IsPrimitiveRoot μ n)
/-- `μ` is integral over `ℤ`. -/
-- Porting note: `hpos` was in the `variable` line, with an `omit` in mathlib3 just after this
-- declaration. For some reason, in Lean4, `hpos` gets included also in the declarations below,
-- even if it is not used in the proof.
theorem isIntegral (hpos : 0 < n) : IsIntegral ℤ μ := by
use X ^ n - 1
constructor
· exact monic_X_pow_sub_C 1 (ne_of_lt hpos).symm
· simp only [((IsPrimitiveRoot.iff_def μ n).mp h).left, eval₂_one, eval₂_X_pow, eval₂_sub,
sub_self]
section IsDomain
variable [IsDomain K] [CharZero K]
/-- The minimal polynomial of a root of unity `μ` divides `X ^ n - 1`. -/
theorem minpoly_dvd_x_pow_sub_one : minpoly ℤ μ ∣ X ^ n - 1 := by
rcases n.eq_zero_or_pos with (rfl | h0)
· simp
apply minpoly.isIntegrallyClosed_dvd (isIntegral h h0)
simp only [((IsPrimitiveRoot.iff_def μ n).mp h).left, aeval_X_pow, eq_intCast, Int.cast_one,
aeval_one, map_sub, sub_self]
/-- The reduction modulo `p` of the minimal polynomial of a root of unity `μ` is separable. -/
theorem separable_minpoly_mod {p : ℕ} [Fact p.Prime] (hdiv : ¬p ∣ n) :
Separable (map (Int.castRingHom (ZMod p)) (minpoly ℤ μ)) := by
have hdvd : map (Int.castRingHom (ZMod p)) (minpoly ℤ μ) ∣ X ^ n - 1 := by
convert RingHom.map_dvd (mapRingHom (Int.castRingHom (ZMod p)))
(minpoly_dvd_x_pow_sub_one h)
simp only [map_sub, map_pow, coe_mapRingHom, map_X, map_one]
refine Separable.of_dvd (separable_X_pow_sub_C 1 ?_ one_ne_zero) hdvd
by_contra hzero
exact hdiv ((ZMod.natCast_zmod_eq_zero_iff_dvd n p).1 hzero)
/-- The reduction modulo `p` of the minimal polynomial of a root of unity `μ` is squarefree. -/
theorem squarefree_minpoly_mod {p : ℕ} [Fact p.Prime] (hdiv : ¬p ∣ n) :
Squarefree (map (Int.castRingHom (ZMod p)) (minpoly ℤ μ)) :=
(separable_minpoly_mod h hdiv).squarefree
/-- Let `P` be the minimal polynomial of a root of unity `μ` and `Q` be the minimal polynomial of
`μ ^ p`, where `p` is a natural number that does not divide `n`. Then `P` divides `expand ℤ p Q`. -/
theorem minpoly_dvd_expand {p : ℕ} (hdiv : ¬p ∣ n) :
minpoly ℤ μ ∣ expand ℤ p (minpoly ℤ (μ ^ p)) := by
rcases n.eq_zero_or_pos with (rfl | hpos)
· simp_all
letI : IsIntegrallyClosed ℤ := GCDMonoid.toIsIntegrallyClosed
refine minpoly.isIntegrallyClosed_dvd (h.isIntegral hpos) ?_
rw [aeval_def, coe_expand, ← comp, eval₂_eq_eval_map, map_comp, Polynomial.map_pow, map_X,
eval_comp, eval_pow, eval_X, ← eval₂_eq_eval_map, ← aeval_def]
exact minpoly.aeval _ _
/-- Let `P` be the minimal polynomial of a root of unity `μ` and `Q` be the minimal polynomial of
`μ ^ p`, where `p` is a prime that does not divide `n`. Then `P` divides `Q ^ p` modulo `p`. -/
theorem minpoly_dvd_pow_mod {p : ℕ} [hprime : Fact p.Prime] (hdiv : ¬p ∣ n) :
map (Int.castRingHom (ZMod p)) (minpoly ℤ μ) ∣
map (Int.castRingHom (ZMod p)) (minpoly ℤ (μ ^ p)) ^ p := by
set Q := minpoly ℤ (μ ^ p)
have hfrob :
map (Int.castRingHom (ZMod p)) Q ^ p = map (Int.castRingHom (ZMod p)) (expand ℤ p Q) := by
rw [← ZMod.expand_card, map_expand]
rw [hfrob]
apply RingHom.map_dvd (mapRingHom (Int.castRingHom (ZMod p)))
exact minpoly_dvd_expand h hdiv
/-- Let `P` be the minimal polynomial of a root of unity `μ` and `Q` be the minimal polynomial of
`μ ^ p`, where `p` is a prime that does not divide `n`. Then `P` divides `Q` modulo `p`. -/
theorem minpoly_dvd_mod_p {p : ℕ} [Fact p.Prime] (hdiv : ¬p ∣ n) :
map (Int.castRingHom (ZMod p)) (minpoly ℤ μ) ∣
map (Int.castRingHom (ZMod p)) (minpoly ℤ (μ ^ p)) :=
(squarefree_minpoly_mod h hdiv).isRadical _ _ (minpoly_dvd_pow_mod h hdiv)
/-- If `p` is a prime that does not divide `n`,
then the minimal polynomials of a primitive `n`-th root of unity `μ`
and of `μ ^ p` are the same. -/
theorem minpoly_eq_pow {p : ℕ} [hprime : Fact p.Prime] (hdiv : ¬p ∣ n) :
minpoly ℤ μ = minpoly ℤ (μ ^ p) := by
classical
by_cases hn : n = 0
· simp_all
have hpos := Nat.pos_of_ne_zero hn
by_contra hdiff
set P := minpoly ℤ μ
set Q := minpoly ℤ (μ ^ p)
have Pmonic : P.Monic := minpoly.monic (h.isIntegral hpos)
have Qmonic : Q.Monic := minpoly.monic ((h.pow_of_prime hprime.1 hdiv).isIntegral hpos)
have Pirr : Irreducible P := minpoly.irreducible (h.isIntegral hpos)
have Qirr : Irreducible Q := minpoly.irreducible ((h.pow_of_prime hprime.1 hdiv).isIntegral hpos)
have PQprim : IsPrimitive (P * Q) := Pmonic.isPrimitive.mul Qmonic.isPrimitive
have prod : P * Q ∣ X ^ n - 1 := by
rw [IsPrimitive.Int.dvd_iff_map_cast_dvd_map_cast (P * Q) (X ^ n - 1) PQprim
(monic_X_pow_sub_C (1 : ℤ) (ne_of_gt hpos)).isPrimitive,
Polynomial.map_mul]
refine IsCoprime.mul_dvd ?_ ?_ ?_
· have aux := IsPrimitive.Int.irreducible_iff_irreducible_map_cast Pmonic.isPrimitive
refine (dvd_or_coprime _ _ (aux.1 Pirr)).resolve_left ?_
rw [map_dvd_map (Int.castRingHom ℚ) Int.cast_injective Pmonic]
intro hdiv
refine hdiff (eq_of_monic_of_associated Pmonic Qmonic ?_)
exact associated_of_dvd_dvd hdiv (Pirr.dvd_symm Qirr hdiv)
· apply (map_dvd_map (Int.castRingHom ℚ) Int.cast_injective Pmonic).2
exact minpoly_dvd_x_pow_sub_one h
· apply (map_dvd_map (Int.castRingHom ℚ) Int.cast_injective Qmonic).2
exact minpoly_dvd_x_pow_sub_one (pow_of_prime h hprime.1 hdiv)
replace prod := RingHom.map_dvd (mapRingHom (Int.castRingHom (ZMod p))) prod
rw [coe_mapRingHom, Polynomial.map_mul, Polynomial.map_sub, Polynomial.map_one,
Polynomial.map_pow, map_X] at prod
obtain ⟨R, hR⟩ := minpoly_dvd_mod_p h hdiv
rw [hR, ← mul_assoc, ← Polynomial.map_mul, ← sq, Polynomial.map_pow] at prod
have habs : map (Int.castRingHom (ZMod p)) P ^ 2 ∣ map (Int.castRingHom (ZMod p)) P ^ 2 * R := by
use R
replace habs :=
lt_of_lt_of_le (PartENat.coe_lt_coe.2 one_lt_two)
(multiplicity.le_multiplicity_of_pow_dvd (dvd_trans habs prod))
have hfree : Squarefree (X ^ n - 1 : (ZMod p)[X]) :=
(separable_X_pow_sub_C 1 (fun h => hdiv <| (ZMod.natCast_zmod_eq_zero_iff_dvd n p).1 h)
one_ne_zero).squarefree
cases'
(multiplicity.squarefree_iff_multiplicity_le_one (X ^ n - 1)).1 hfree
(map (Int.castRingHom (ZMod p)) P) with
hle hunit
· rw [Nat.cast_one] at habs; exact hle.not_lt habs
· replace hunit := degree_eq_zero_of_isUnit hunit
rw [degree_map_eq_of_leadingCoeff_ne_zero (Int.castRingHom (ZMod p)) _] at hunit
· exact (minpoly.degree_pos (isIntegral h hpos)).ne' hunit
simp only [Pmonic, eq_intCast, Monic.leadingCoeff, Int.cast_one, Ne, not_false_iff,
one_ne_zero]
/-- If `m : ℕ` is coprime with `n`,
then the minimal polynomials of a primitive `n`-th root of unity `μ`
and of `μ ^ m` are the same. -/
theorem minpoly_eq_pow_coprime {m : ℕ} (hcop : Nat.Coprime m n) :
minpoly ℤ μ = minpoly ℤ (μ ^ m) := by
revert n hcop
refine UniqueFactorizationMonoid.induction_on_prime m ?_ ?_ ?_
· intro h hn
congr
simpa [(Nat.coprime_zero_left _).mp hn] using h
· intro u hunit _ _
congr
simp [Nat.isUnit_iff.mp hunit]
· intro a p _ hprime
intro hind h hcop
rw [hind h (Nat.Coprime.coprime_mul_left hcop)]; clear hind
replace hprime := hprime.nat_prime
have hdiv := (Nat.Prime.coprime_iff_not_dvd hprime).1 (Nat.Coprime.coprime_mul_right hcop)
haveI := Fact.mk hprime
rw [minpoly_eq_pow (h.pow_of_coprime a (Nat.Coprime.coprime_mul_left hcop)) hdiv]
congr 1
ring
/-- If `m : ℕ` is coprime with `n`,
then the minimal polynomial of a primitive `n`-th root of unity `μ`
has `μ ^ m` as root. -/
theorem pow_isRoot_minpoly {m : ℕ} (hcop : Nat.Coprime m n) :
IsRoot (map (Int.castRingHom K) (minpoly ℤ μ)) (μ ^ m) := by
simp only [minpoly_eq_pow_coprime h hcop, IsRoot.def, eval_map]
exact minpoly.aeval ℤ (μ ^ m)
/-- `primitiveRoots n K` is a subset of the roots of the minimal polynomial of a primitive
`n`-th root of unity `μ`. -/
theorem is_roots_of_minpoly [DecidableEq K] :
primitiveRoots n K ⊆ (map (Int.castRingHom K) (minpoly ℤ μ)).roots.toFinset := by
by_cases hn : n = 0; · simp_all
have hpos := Nat.pos_of_ne_zero hn
intro x hx
obtain ⟨m, _, hcop, rfl⟩ := (isPrimitiveRoot_iff h hpos).1 ((mem_primitiveRoots hpos).1 hx)
simp only [Multiset.mem_toFinset, mem_roots]
convert pow_isRoot_minpoly h hcop
rw [← mem_roots]
exact map_monic_ne_zero <| minpoly.monic <| isIntegral h hpos
/-- The degree of the minimal polynomial of `μ` is at least `totient n`. -/
theorem totient_le_degree_minpoly : Nat.totient n ≤ (minpoly ℤ μ).natDegree := by
classical
let P : ℤ[X] := minpoly ℤ μ
-- minimal polynomial of `μ`
let P_K : K[X] := map (Int.castRingHom K) P
-- minimal polynomial of `μ` sent to `K[X]`
calc
n.totient = (primitiveRoots n K).card := h.card_primitiveRoots.symm
_ ≤ P_K.roots.toFinset.card := Finset.card_le_card (is_roots_of_minpoly h)
_ ≤ Multiset.card P_K.roots := Multiset.toFinset_card_le _
_ ≤ P_K.natDegree := card_roots' _
_ ≤ P.natDegree := natDegree_map_le _ _
end IsDomain
end CommRing
end IsPrimitiveRoot
|
RingTheory\Smooth\Basic.lean | /-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.RingTheory.Ideal.Cotangent
import Mathlib.RingTheory.QuotientNilpotent
import Mathlib.RingTheory.TensorProduct.Basic
import Mathlib.RingTheory.FinitePresentation
import Mathlib.RingTheory.FiniteStability
import Mathlib.RingTheory.Localization.Away.Basic
import Mathlib.RingTheory.Localization.Away.AdjoinRoot
/-!
# Smooth morphisms
An `R`-algebra `A` is formally smooth if for every `R`-algebra,
every square-zero ideal `I : Ideal B` and `f : A →ₐ[R] B ⧸ I`, there exists
at least one lift `A →ₐ[R] B`.
It is smooth if it is formally smooth and of finite presentation.
We show that the property of being formally smooth extends onto nilpotent ideals,
and that it is stable under `R`-algebra homomorphisms and compositions.
We show that smooth is stable under algebra isomorphisms, composition and
localization at an element.
-/
-- Porting note: added to make the syntax work below.
open scoped TensorProduct
universe u
namespace Algebra
section
variable (R : Type u) [CommSemiring R]
variable (A : Type u) [Semiring A] [Algebra R A]
/-- An `R` algebra `A` is formally smooth if for every `R`-algebra, every square-zero ideal
`I : Ideal B` and `f : A →ₐ[R] B ⧸ I`, there exists at least one lift `A →ₐ[R] B`.
See <https://stacks.math.columbia.edu/tag/00TI>.
-/
@[mk_iff]
class FormallySmooth : Prop where
comp_surjective :
∀ ⦃B : Type u⦄ [CommRing B],
∀ [Algebra R B] (I : Ideal B) (_ : I ^ 2 = ⊥),
Function.Surjective ((Ideal.Quotient.mkₐ R I).comp : (A →ₐ[R] B) → A →ₐ[R] B ⧸ I)
end
namespace FormallySmooth
section
variable {R : Type u} [CommSemiring R]
variable {A : Type u} [Semiring A] [Algebra R A]
variable {B : Type u} [CommRing B] [Algebra R B] (I : Ideal B)
theorem exists_lift {B : Type u} [CommRing B] [_RB : Algebra R B]
[FormallySmooth R A] (I : Ideal B) (hI : IsNilpotent I) (g : A →ₐ[R] B ⧸ I) :
∃ f : A →ₐ[R] B, (Ideal.Quotient.mkₐ R I).comp f = g := by
revert g
change Function.Surjective (Ideal.Quotient.mkₐ R I).comp
revert _RB
apply Ideal.IsNilpotent.induction_on (R := B) I hI
· intro B _ I hI _; exact FormallySmooth.comp_surjective I hI
· intro B _ I J hIJ h₁ h₂ _ g
let this : ((B ⧸ I) ⧸ J.map (Ideal.Quotient.mk I)) ≃ₐ[R] B ⧸ J :=
{
(DoubleQuot.quotQuotEquivQuotSup I J).trans
(Ideal.quotEquivOfEq (sup_eq_right.mpr hIJ)) with
commutes' := fun x => rfl }
obtain ⟨g', e⟩ := h₂ (this.symm.toAlgHom.comp g)
obtain ⟨g', rfl⟩ := h₁ g'
replace e := congr_arg this.toAlgHom.comp e
conv_rhs at e =>
rw [← AlgHom.comp_assoc, AlgEquiv.toAlgHom_eq_coe, AlgEquiv.toAlgHom_eq_coe,
AlgEquiv.comp_symm, AlgHom.id_comp]
exact ⟨g', e⟩
/-- For a formally smooth `R`-algebra `A` and a map `f : A →ₐ[R] B ⧸ I` with `I` square-zero,
this is an arbitrary lift `A →ₐ[R] B`. -/
noncomputable def lift [FormallySmooth R A] (I : Ideal B) (hI : IsNilpotent I)
(g : A →ₐ[R] B ⧸ I) : A →ₐ[R] B :=
(FormallySmooth.exists_lift I hI g).choose
@[simp]
theorem comp_lift [FormallySmooth R A] (I : Ideal B) (hI : IsNilpotent I)
(g : A →ₐ[R] B ⧸ I) : (Ideal.Quotient.mkₐ R I).comp (FormallySmooth.lift I hI g) = g :=
(FormallySmooth.exists_lift I hI g).choose_spec
@[simp]
theorem mk_lift [FormallySmooth R A] (I : Ideal B) (hI : IsNilpotent I)
(g : A →ₐ[R] B ⧸ I) (x : A) : Ideal.Quotient.mk I (FormallySmooth.lift I hI g x) = g x :=
AlgHom.congr_fun (FormallySmooth.comp_lift I hI g : _) x
variable {C : Type u} [CommRing C] [Algebra R C]
/-- For a formally smooth `R`-algebra `A` and a map `f : A →ₐ[R] B ⧸ I` with `I` nilpotent,
this is an arbitrary lift `A →ₐ[R] B`. -/
noncomputable def liftOfSurjective [FormallySmooth R A] (f : A →ₐ[R] C)
(g : B →ₐ[R] C) (hg : Function.Surjective g) (hg' : IsNilpotent <| RingHom.ker (g : B →+* C)) :
A →ₐ[R] B :=
FormallySmooth.lift _ hg' ((Ideal.quotientKerAlgEquivOfSurjective hg).symm.toAlgHom.comp f)
@[simp]
theorem liftOfSurjective_apply [FormallySmooth R A] (f : A →ₐ[R] C) (g : B →ₐ[R] C)
(hg : Function.Surjective g) (hg' : IsNilpotent <| RingHom.ker (g : B →+* C)) (x : A) :
g (FormallySmooth.liftOfSurjective f g hg hg' x) = f x := by
apply (Ideal.quotientKerAlgEquivOfSurjective hg).symm.injective
change _ = ((Ideal.quotientKerAlgEquivOfSurjective hg).symm.toAlgHom.comp f) x
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [← FormallySmooth.mk_lift _ hg'
((Ideal.quotientKerAlgEquivOfSurjective hg).symm.toAlgHom.comp f)]
apply (Ideal.quotientKerAlgEquivOfSurjective hg).injective
simp only [liftOfSurjective, AlgEquiv.apply_symm_apply, AlgEquiv.toAlgHom_eq_coe,
Ideal.quotientKerAlgEquivOfSurjective_apply, RingHom.kerLift_mk, RingHom.coe_coe]
@[simp]
theorem comp_liftOfSurjective [FormallySmooth R A] (f : A →ₐ[R] C) (g : B →ₐ[R] C)
(hg : Function.Surjective g) (hg' : IsNilpotent <| RingHom.ker (g : B →+* C)) :
g.comp (FormallySmooth.liftOfSurjective f g hg hg') = f :=
AlgHom.ext (FormallySmooth.liftOfSurjective_apply f g hg hg')
end
section OfEquiv
variable {R : Type u} [CommSemiring R]
variable {A B : Type u} [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]
theorem of_equiv [FormallySmooth R A] (e : A ≃ₐ[R] B) : FormallySmooth R B := by
constructor
intro C _ _ I hI f
use (FormallySmooth.lift I ⟨2, hI⟩ (f.comp e : A →ₐ[R] C ⧸ I)).comp e.symm
rw [← AlgHom.comp_assoc, FormallySmooth.comp_lift, AlgHom.comp_assoc, AlgEquiv.comp_symm,
AlgHom.comp_id]
end OfEquiv
section Polynomial
open scoped Polynomial
variable (R : Type u) [CommSemiring R]
instance mvPolynomial (σ : Type u) : FormallySmooth R (MvPolynomial σ R) := by
constructor
intro C _ _ I _ f
have : ∀ s : σ, ∃ c : C, Ideal.Quotient.mk I c = f (MvPolynomial.X s) := fun s =>
Ideal.Quotient.mk_surjective _
choose g hg using this
refine ⟨MvPolynomial.aeval g, ?_⟩
ext s
rw [← hg, AlgHom.comp_apply, MvPolynomial.aeval_X]
rfl
instance polynomial : FormallySmooth R R[X] :=
FormallySmooth.of_equiv (MvPolynomial.pUnitAlgEquiv R)
end Polynomial
section Comp
variable (R : Type u) [CommSemiring R]
variable (A : Type u) [CommSemiring A] [Algebra R A]
variable (B : Type u) [Semiring B] [Algebra R B] [Algebra A B] [IsScalarTower R A B]
theorem comp [FormallySmooth R A] [FormallySmooth A B] : FormallySmooth R B := by
constructor
intro C _ _ I hI f
obtain ⟨f', e⟩ := FormallySmooth.comp_surjective I hI (f.comp (IsScalarTower.toAlgHom R A B))
letI := f'.toRingHom.toAlgebra
obtain ⟨f'', e'⟩ :=
FormallySmooth.comp_surjective I hI { f.toRingHom with commutes' := AlgHom.congr_fun e.symm }
apply_fun AlgHom.restrictScalars R at e'
exact ⟨f''.restrictScalars _, e'.trans (AlgHom.ext fun _ => rfl)⟩
end Comp
section OfSurjective
variable {R S : Type u} [CommRing R] [CommSemiring S]
variable {P A : Type u} [CommRing A] [Algebra R A] [CommRing P] [Algebra R P]
variable (I : Ideal P) (f : P →ₐ[R] A) (hf : Function.Surjective f)
theorem of_split [FormallySmooth R P] (g : A →ₐ[R] P ⧸ (RingHom.ker f.toRingHom) ^ 2)
(hg : f.kerSquareLift.comp g = AlgHom.id R A) : FormallySmooth R A := by
constructor
intro C _ _ I hI i
let l : P ⧸ (RingHom.ker f.toRingHom) ^ 2 →ₐ[R] C := by
refine Ideal.Quotient.liftₐ _ (FormallySmooth.lift I ⟨2, hI⟩ (i.comp f)) ?_
have : RingHom.ker f ≤ I.comap (FormallySmooth.lift I ⟨2, hI⟩ (i.comp f)) := by
rintro x (hx : f x = 0)
have : _ = i (f x) := (FormallySmooth.mk_lift I ⟨2, hI⟩ (i.comp f) x : _)
rwa [hx, map_zero, ← Ideal.Quotient.mk_eq_mk, Submodule.Quotient.mk_eq_zero] at this
intro x hx
have := (Ideal.pow_right_mono this 2).trans (Ideal.le_comap_pow _ 2) hx
rwa [hI] at this
have : i.comp f.kerSquareLift = (Ideal.Quotient.mkₐ R _).comp l := by
apply AlgHom.coe_ringHom_injective
apply Ideal.Quotient.ringHom_ext
ext x
exact (FormallySmooth.mk_lift I ⟨2, hI⟩ (i.comp f) x).symm
exact ⟨l.comp g, by rw [← AlgHom.comp_assoc, ← this, AlgHom.comp_assoc, hg, AlgHom.comp_id]⟩
/-- Let `P →ₐ[R] A` be a surjection with kernel `J`, and `P` a formally smooth `R`-algebra,
then `A` is formally smooth over `R` iff the surjection `P ⧸ J ^ 2 →ₐ[R] A` has a section.
Geometric intuition: we require that a first-order thickening of `Spec A` inside `Spec P` admits
a retraction. -/
theorem iff_split_surjection [FormallySmooth R P] :
FormallySmooth R A ↔ ∃ g, f.kerSquareLift.comp g = AlgHom.id R A := by
constructor
· intro
have surj : Function.Surjective f.kerSquareLift := fun x =>
⟨Submodule.Quotient.mk (hf x).choose, (hf x).choose_spec⟩
have sqz : RingHom.ker f.kerSquareLift.toRingHom ^ 2 = 0 := by
rw [AlgHom.ker_kerSquareLift, Ideal.cotangentIdeal_square, Ideal.zero_eq_bot]
refine
⟨FormallySmooth.lift _ ⟨2, sqz⟩ (Ideal.quotientKerAlgEquivOfSurjective surj).symm.toAlgHom,
?_⟩
ext x
have :=
(Ideal.quotientKerAlgEquivOfSurjective surj).toAlgHom.congr_arg
(FormallySmooth.mk_lift _ ⟨2, sqz⟩
(Ideal.quotientKerAlgEquivOfSurjective surj).symm.toAlgHom x)
-- Porting note: was
-- dsimp at this
-- rw [AlgEquiv.apply_symm_apply] at this
erw [AlgEquiv.apply_symm_apply] at this
conv_rhs => rw [← this, AlgHom.id_apply]
rfl
-- Porting note: lean3 was not finished here:
-- obtain ⟨y, e⟩ :=
-- Ideal.Quotient.mk_surjective
-- (FormallySmooth.lift _ ⟨2, sqz⟩
-- (Ideal.quotientKerAlgEquivOfSurjective surj).symm.toAlgHom
-- x)
-- dsimp at e ⊢
-- rw [← e]
-- rfl
· rintro ⟨g, hg⟩; exact FormallySmooth.of_split f g hg
end OfSurjective
section BaseChange
open scoped TensorProduct
variable {R : Type u} [CommSemiring R]
variable {A : Type u} [Semiring A] [Algebra R A]
variable (B : Type u) [CommSemiring B] [Algebra R B]
instance base_change [FormallySmooth R A] : FormallySmooth B (B ⊗[R] A) := by
constructor
intro C _ _ I hI f
letI := ((algebraMap B C).comp (algebraMap R B)).toAlgebra
haveI : IsScalarTower R B C := IsScalarTower.of_algebraMap_eq' rfl
refine ⟨TensorProduct.productLeftAlgHom (Algebra.ofId B C) ?_, ?_⟩
· exact FormallySmooth.lift I ⟨2, hI⟩ ((f.restrictScalars R).comp TensorProduct.includeRight)
· apply AlgHom.restrictScalars_injective R
apply TensorProduct.ext'
intro b a
suffices algebraMap B _ b * f (1 ⊗ₜ[R] a) = f (b ⊗ₜ[R] a) by simpa [Algebra.ofId_apply]
rw [← Algebra.smul_def, ← map_smul, TensorProduct.smul_tmul', smul_eq_mul, mul_one]
end BaseChange
section Localization
variable {R S Rₘ Sₘ : Type u} [CommRing R] [CommRing S] [CommRing Rₘ] [CommRing Sₘ]
variable (M : Submonoid R)
variable [Algebra R S] [Algebra R Sₘ] [Algebra S Sₘ] [Algebra R Rₘ] [Algebra Rₘ Sₘ]
variable [IsScalarTower R Rₘ Sₘ] [IsScalarTower R S Sₘ]
variable [IsLocalization M Rₘ] [IsLocalization (M.map (algebraMap R S)) Sₘ]
-- Porting note: no longer supported
-- attribute [local elab_as_elim] Ideal.IsNilpotent.induction_on
theorem of_isLocalization : FormallySmooth R Rₘ := by
constructor
intro Q _ _ I e f
have : ∀ x : M, IsUnit (algebraMap R Q x) := by
intro x
apply (IsNilpotent.isUnit_quotient_mk_iff ⟨2, e⟩).mp
convert (IsLocalization.map_units Rₘ x).map f
simp only [Ideal.Quotient.mk_algebraMap, AlgHom.commutes]
let this : Rₘ →ₐ[R] Q :=
{ IsLocalization.lift this with commutes' := IsLocalization.lift_eq this }
use this
apply AlgHom.coe_ringHom_injective
refine IsLocalization.ringHom_ext M ?_
ext
simp
theorem localization_base [FormallySmooth R Sₘ] : FormallySmooth Rₘ Sₘ := by
constructor
intro Q _ _ I e f
letI := ((algebraMap Rₘ Q).comp (algebraMap R Rₘ)).toAlgebra
letI : IsScalarTower R Rₘ Q := IsScalarTower.of_algebraMap_eq' rfl
let f : Sₘ →ₐ[Rₘ] Q := by
refine { FormallySmooth.lift I ⟨2, e⟩ (f.restrictScalars R) with commutes' := ?_ }
intro r
change
(RingHom.comp (FormallySmooth.lift I ⟨2, e⟩ (f.restrictScalars R) : Sₘ →+* Q)
(algebraMap _ _))
r =
algebraMap _ _ r
congr 1
refine IsLocalization.ringHom_ext M ?_
rw [RingHom.comp_assoc, ← IsScalarTower.algebraMap_eq, ← IsScalarTower.algebraMap_eq,
AlgHom.comp_algebraMap]
use f
ext
simp [f]
theorem localization_map [FormallySmooth R S] : FormallySmooth Rₘ Sₘ := by
haveI : FormallySmooth S Sₘ := FormallySmooth.of_isLocalization (M.map (algebraMap R S))
haveI : FormallySmooth R Sₘ := FormallySmooth.comp R S Sₘ
exact FormallySmooth.localization_base M
end Localization
end FormallySmooth
section
variable (R : Type u) [CommSemiring R]
variable (A : Type u) [Semiring A] [Algebra R A]
/-- An `R` algebra `A` is smooth if it is formally smooth and of finite presentation.
In the stacks project, the definition of smooth is completely different, and tag
<https://stacks.math.columbia.edu/tag/00TN> proves that their definition is equivalent
to this.
-/
class Smooth [CommSemiring R] (A : Type u) [Semiring A] [Algebra R A] : Prop where
formallySmooth : FormallySmooth R A := by infer_instance
finitePresentation : FinitePresentation R A := by infer_instance
end
namespace Smooth
attribute [instance] formallySmooth finitePresentation
variable {R : Type u} [CommRing R]
variable {A B : Type u} [CommRing A] [Algebra R A] [CommRing B] [Algebra R B]
/-- Being smooth is transported via algebra isomorphisms. -/
theorem of_equiv [Smooth R A] (e : A ≃ₐ[R] B) : Smooth R B where
formallySmooth := FormallySmooth.of_equiv e
finitePresentation := FinitePresentation.equiv e
/-- Localization at an element is smooth. -/
theorem of_isLocalization_Away (r : R) [IsLocalization.Away r A] : Smooth R A where
formallySmooth := Algebra.FormallySmooth.of_isLocalization (Submonoid.powers r)
finitePresentation := IsLocalization.Away.finitePresentation r
section Comp
variable (R A B)
/-- Smooth is stable under composition. -/
theorem comp [Algebra A B] [IsScalarTower R A B] [Smooth R A] [Smooth A B] : Smooth R B where
formallySmooth := FormallySmooth.comp R A B
finitePresentation := FinitePresentation.trans R A B
/-- Smooth is stable under base change. -/
instance baseChange [Smooth R A] : Smooth B (B ⊗[R] A) where
end Comp
end Smooth
end Algebra
|
RingTheory\Smooth\Kaehler.lean | /-
Copyright (c) 2024 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.RingTheory.Kaehler.Basic
/-!
# Relation of smoothness and `Ω[S⁄R]`
## Main results
- `retractionKerToTensorEquivSection`:
Given a surjective algebra homomorphism `f : P →ₐ[R] S` with square-zero kernel `I`,
there is a one-to-one correspondence between `P`-linear retractions of `I →ₗ[P] S ⊗[P] Ω[P/R]`
and algebra homomorphism sections of `f`.
## Future projects
- Show that relative smooth iff `H¹(L_{S/R}) = 0` and `Ω[S/R]` is projective.
- Show that being smooth is local on stalks.
- Show that being formally smooth is Zariski-local (very hard).
-/
universe u
open TensorProduct KaehlerDifferential
open Function (Surjective)
variable {R P S : Type u} [CommRing R] [CommRing P] [CommRing S]
variable [Algebra R S] [Algebra R P] [Algebra P S] [IsScalarTower R P S]
variable (hf : Surjective (algebraMap P S)) (hf' : (RingHom.ker (algebraMap P S)) ^ 2 = ⊥)
section ofSection
-- Suppose we have a section (as alghom) of `P →ₐ[R] S`.
variable (g : S →ₐ[R] P) (hg : (IsScalarTower.toAlgHom R P S).comp g = AlgHom.id R S)
/--
Given a surjective algebra homomorphism `f : P →ₐ[R] S` with square-zero kernel `I`,
and a section `g : S →ₐ[R] P` (as an algebra homomorphism),
we get an `R`-derivation `P → I` via `x ↦ x - g (f x)`.
-/
@[simps]
def derivationOfSectionOfKerSqZero (f : P →ₐ[R] S) (hf' : (RingHom.ker f) ^ 2 = ⊥) (g : S →ₐ[R] P)
(hg : f.comp g = AlgHom.id R S) : Derivation R P (RingHom.ker f) where
toFun x := ⟨x - g (f x), by
simpa [RingHom.mem_ker, sub_eq_zero] using AlgHom.congr_fun hg.symm (f x)⟩
map_add' x y := by simp only [map_add, AddSubmonoid.mk_add_mk, Subtype.mk.injEq]; ring
map_smul' x y := by
ext
simp only [Algebra.smul_def, _root_.map_mul, ← IsScalarTower.algebraMap_apply,
AlgHom.commutes, RingHom.id_apply, Submodule.coe_smul_of_tower]
ring
map_one_eq_zero' := by simp only [LinearMap.coe_mk, AddHom.coe_mk, _root_.map_one, sub_self,
AddSubmonoid.mk_eq_zero]
leibniz' a b := by
have : (a - g (f a)) * (b - g (f b)) = 0 := by
rw [← Ideal.mem_bot, ← hf', pow_two]
apply Ideal.mul_mem_mul
· simpa [RingHom.mem_ker, sub_eq_zero] using AlgHom.congr_fun hg.symm (f a)
· simpa [RingHom.mem_ker, sub_eq_zero] using AlgHom.congr_fun hg.symm (f b)
ext
rw [← sub_eq_zero]
conv_rhs => rw [← neg_zero, ← this]
simp only [LinearMap.coe_mk, AddHom.coe_mk, _root_.map_mul, SetLike.mk_smul_mk, smul_eq_mul,
mul_sub, AddSubmonoid.mk_add_mk, sub_mul, neg_sub]
ring
lemma isScalarTower_of_section_of_ker_sqZero :
letI := g.toRingHom.toAlgebra; IsScalarTower P S (RingHom.ker (algebraMap P S)) := by
letI := g.toRingHom.toAlgebra
constructor
intro p s m
ext
show g (p • s) * m = p * (g s * m)
simp only [Algebra.smul_def, _root_.map_mul, mul_assoc, mul_left_comm _ (g s)]
congr 1
rw [← sub_eq_zero, ← Ideal.mem_bot, ← hf', pow_two, ← sub_mul]
refine Ideal.mul_mem_mul ?_ m.2
simpa [RingHom.mem_ker, sub_eq_zero] using AlgHom.congr_fun hg (algebraMap P S p)
/--
Given a surjective algebra hom `f : P →ₐ[R] S` with square-zero kernel `I`,
and a section `g : S →ₐ[R] P` (as algebra homs),
we get a retraction of the injection `I → S ⊗[P] Ω[P/R]`.
-/
noncomputable
def retractionOfSectionOfKerSqZero : S ⊗[P] Ω[P⁄R] →ₗ[P] RingHom.ker (algebraMap P S) :=
letI := g.toRingHom.toAlgebra
haveI := isScalarTower_of_section_of_ker_sqZero hf' g hg
letI f : _ →ₗ[P] RingHom.ker (algebraMap P S) := (derivationOfSectionOfKerSqZero
(IsScalarTower.toAlgHom R P S) hf' g hg).liftKaehlerDifferential
(f.liftBaseChange S).restrictScalars P
@[simp]
lemma retractionOfSectionOfKerSqZero_tmul_D (s : S) (t : P) :
retractionOfSectionOfKerSqZero hf' g hg (s ⊗ₜ .D _ _ t) =
g s * t - g s * g (algebraMap _ _ t) := by
letI := g.toRingHom.toAlgebra
haveI := isScalarTower_of_section_of_ker_sqZero hf' g hg
simp only [retractionOfSectionOfKerSqZero, AlgHom.toRingHom_eq_coe, LinearMap.coe_restrictScalars,
LinearMap.liftBaseChange_tmul, SetLike.val_smul_of_tower]
erw [Derivation.liftKaehlerDifferential_comp_D]
exact mul_sub (g s) t (g (algebraMap P S t))
lemma retractionOfSectionOfKerSqZero_comp_kerToTensor :
(retractionOfSectionOfKerSqZero hf' g hg).comp (kerToTensor R P S) = LinearMap.id := by
ext x; simp [(RingHom.mem_ker _).mp x.2]
end ofSection
section ofRetraction
variable (l : S ⊗[P] Ω[P⁄R] →ₗ[P] RingHom.ker (algebraMap P S))
variable (hl : l.comp (kerToTensor R P S) = LinearMap.id)
-- suppose we have a (set-theoretic) section
variable (σ : S → P) (hσ : ∀ x, algebraMap P S (σ x) = x)
lemma sectionOfRetractionKerToTensorAux_prop (x y) (h : algebraMap P S x = algebraMap P S y) :
x - l (1 ⊗ₜ .D _ _ x) = y - l (1 ⊗ₜ .D _ _ y) := by
rw [sub_eq_iff_eq_add, sub_add_comm, ← sub_eq_iff_eq_add, ← Submodule.coe_sub,
← map_sub, ← tmul_sub, ← map_sub]
exact congr_arg Subtype.val (LinearMap.congr_fun hl.symm ⟨x - y, by simp [RingHom.mem_ker, h]⟩)
/--
Given a surjective algebra homomorphism `f : P →ₐ[R] S` with square-zero kernel `I`.
Let `σ` be an arbitrary (set-theoretic) section of `f`.
Suppose we have a retraction `l` of the injection `I →ₗ[P] S ⊗[P] Ω[P/R]`, then
`x ↦ σ x - l (1 ⊗ D (σ x))` is an algebra homomorphism and a section to `f`.
-/
noncomputable
def sectionOfRetractionKerToTensorAux : S →ₐ[R] P where
toFun x := σ x - l (1 ⊗ₜ .D _ _ (σ x))
map_one' := by simp [sectionOfRetractionKerToTensorAux_prop l hl (σ 1) 1 (by simp [hσ])]
map_mul' a b := by
have (x y) : (l x).1 * (l y).1 = 0 := by
rw [← Ideal.mem_bot, ← hf', pow_two]; exact Ideal.mul_mem_mul (l x).2 (l y).2
simp only [sectionOfRetractionKerToTensorAux_prop l hl (σ (a * b)) (σ a * σ b) (by simp [hσ]),
Derivation.leibniz, tmul_add, tmul_smul, map_add, map_smul, AddSubmonoid.coe_add, this,
Submodule.coe_toAddSubmonoid, SetLike.val_smul, smul_eq_mul, mul_sub, sub_mul, sub_zero]
ring
map_add' a b := by
simp only [sectionOfRetractionKerToTensorAux_prop l hl (σ (a + b)) (σ a + σ b) (by simp [hσ]),
map_add, tmul_add, AddSubmonoid.coe_add, Submodule.coe_toAddSubmonoid, add_sub_add_comm]
map_zero' := by simp [sectionOfRetractionKerToTensorAux_prop l hl (σ 0) 0 (by simp [hσ])]
commutes' r := by
simp [sectionOfRetractionKerToTensorAux_prop l hl
(σ (algebraMap R S r)) (algebraMap R P r) (by simp [hσ, ← IsScalarTower.algebraMap_apply])]
lemma sectionOfRetractionKerToTensorAux_algebraMap (x : P) :
sectionOfRetractionKerToTensorAux hf' l hl σ hσ (algebraMap P S x) = x - l (1 ⊗ₜ .D _ _ x) :=
sectionOfRetractionKerToTensorAux_prop l hl _ x (by simp [hσ])
lemma toAlgHom_comp_sectionOfRetractionKerToTensorAux :
(IsScalarTower.toAlgHom R P S).comp
(sectionOfRetractionKerToTensorAux hf' l hl σ hσ) = AlgHom.id _ _ := by
ext x
obtain ⟨x, rfl⟩ := hf x
simp [sectionOfRetractionKerToTensorAux_algebraMap, (RingHom.mem_ker _).mp]
/--
Given a surjective algebra homomorphism `f : P →ₐ[R] S` with square-zero kernel `I`.
Suppose we have a retraction `l` of the injection `I →ₗ[P] S ⊗[P] Ω[P/R]`, then
`x ↦ σ x - l (1 ⊗ D (σ x))` is an algebra homomorphism and a section to `f`,
where `σ` is an arbitrary (set-theoretic) section of `f`
-/
noncomputable def sectionOfRetractionKerToTensor : S →ₐ[R] P :=
sectionOfRetractionKerToTensorAux hf' l hl _ (fun x ↦ (hf x).choose_spec)
@[simp]
lemma sectionOfRetractionKerToTensor_algebraMap (x : P) :
sectionOfRetractionKerToTensor hf hf' l hl (algebraMap P S x) = x - l (1 ⊗ₜ .D _ _ x) :=
sectionOfRetractionKerToTensorAux_algebraMap hf' l hl _ _ x
@[simp]
lemma toAlgHom_comp_sectionOfRetractionKerToTensor :
(IsScalarTower.toAlgHom R P S).comp
(sectionOfRetractionKerToTensor hf hf' l hl) = AlgHom.id _ _ :=
toAlgHom_comp_sectionOfRetractionKerToTensorAux hf _ _ _ _ _
end ofRetraction
/--
Given a surjective algebra homomorphism `f : P →ₐ[R] S` with square-zero kernel `I`,
there is a one-to-one correspondence between `P`-linear retractions of `I →ₗ[P] S ⊗[P] Ω[P/R]`
and algebra homomorphism sections of `f`.
-/
noncomputable
def retractionKerToTensorEquivSection :
{ l // l ∘ₗ (kerToTensor R P S) = LinearMap.id } ≃
{ g // (IsScalarTower.toAlgHom R P S).comp g = AlgHom.id R S } where
toFun l := ⟨_, toAlgHom_comp_sectionOfRetractionKerToTensor hf hf' _ l.2⟩
invFun g := ⟨_, retractionOfSectionOfKerSqZero_comp_kerToTensor hf' _ g.2⟩
left_inv l := by
ext s p
obtain ⟨s, rfl⟩ := hf s
have (x y) : (l.1 x).1 * (l.1 y).1 = 0 := by
rw [← Ideal.mem_bot, ← hf', pow_two]; exact Ideal.mul_mem_mul (l.1 x).2 (l.1 y).2
simp only [AlgebraTensorModule.curry_apply,
Derivation.coe_comp, LinearMap.coe_comp, LinearMap.coe_restrictScalars, Derivation.coeFn_coe,
Function.comp_apply, curry_apply, retractionOfSectionOfKerSqZero_tmul_D,
sectionOfRetractionKerToTensor_algebraMap, ← mul_sub, sub_sub_cancel]
rw [sub_mul]
simp only [this, Algebra.algebraMap_eq_smul_one, ← smul_tmul', LinearMapClass.map_smul,
SetLike.val_smul, smul_eq_mul, sub_zero]
right_inv g := by ext s; obtain ⟨s, rfl⟩ := hf s; simp
|
RingTheory\Smooth\StandardSmooth.lean | /-
Copyright (c) 2024 Christian Merten. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jung Tao Cheng, Christian Merten, Andrew Yang
-/
import Mathlib.Algebra.MvPolynomial.PDeriv
import Mathlib.LinearAlgebra.Determinant
import Mathlib.RingTheory.Presentation
/-!
# Standard smooth algebras
In this file we define standard smooth algebras. For this we introduce
the notion of a `PreSubmersivePresentation`. This is a presentation `P` that has
fewer relations than generators. More precisely there exists an injective map from `P.rels`
to `P.vars`. To such a presentation we may associate a jacobian. `P` is then a submersive
presentation, if its jacobian is invertible.
Finally, a standard smooth algebra is an algebra that admits a submersive presentation.
While every standard smooth algebra is smooth, the converse does not hold. But if `S` is `R`-smooth,
then `S` is `R`-standard smooth locally on `S`, i.e. there exists a set `{ t }` of `S` that
generates the unit ideal, such that `Sₜ` is `R`-standard smooth for every `t` (TODO, see below).
## Main definitions
All of these are in the `Algebra` namespace. Let `S` be an `R`-algebra.
- `PreSubmersivePresentation`: A `Presentation` of `S` as `R`-algebra, equipped with an injective
map `P.map` from `P.rels` to `P.vars`. This map is used to define the differential of a
presubmersive presentation.
For a presubmersive presentation `P` of `S` over `R` we make the following definitions:
- `PreSubmersivePresentation.differential`: A linear endomorphism of `P.rels → P.Ring` sending
the `j`-th standard basis vector, corresponding to the `j`-th relation, to the vector
of partial derivatives of `P.relation j` with respect to the coordinates `P.map i` for
`i : P.rels`.
- `PreSubmersivePresentation.jacobian`: The determinant of `P.differential`.
- `PreSubmersivePresentation.jacobiMatrix`: If `P.rels` has a `Fintype` instance, we may form
the matrix corresponding to `P.differential`. Its determinant is `P.jacobian`.
- `SubmersivePresentation`: A submersive presentation is a finite, presubmersive presentation `P`
with in `S` invertible jacobian.
Furthermore, for algebras we define:
- `Algebra.IsStandardSmooth`: `S` is `R`-standard smooth if `S` admits a submersive
`R`-presentation.
- `Algebra.IsStandardSmooth.relativeDimension`: If `S` is `R`-standard smooth this is the dimension
of an arbitrary submersive `R`-presentation of `S`. This is independent of the choice
of the presentation (TODO, see below).
- `Algebra.IsStandardSmoothOfRelativeDimension n`: `S` is `R`-standard smooth of relative dimension
`n` if it admits a submersive `R`-presentation of dimension `n`.
Finally, for ring homomorphisms we define:
- `RingHom.IsStandardSmooth`: A ring homomorphism `R →+* S` is standard smooth if `S` is standard
smooth as `R`-algebra.
- `RingHom.IsStandardSmoothOfRelativeDimension n`: A ring homomorphism `R →+* S` is standard
smooth of relative dimension `n` if `S` is standard smooth of relative dimension `n` as
`R`-algebra.
## TODO
- Show that the canonical presentation for localization away from an element is standard smooth
of relative dimension 0.
- Show that the base change of a submersive presentation is submersive of equal relative
dimension.
- Show that the composition of submersive presentations of relative dimensions `n` and `m` is
submersive of relative dimension `n + m`.
- Show that the module of Kaehler differentials of a standard smooth `R`-algebra `S` of relative
dimension `n` is `S`-free of rank `n`. In particular this shows that the relative dimension
is independent of the choice of the standard smooth presentation.
- Show that standard smooth algebras are smooth. This relies on the computation of the module of
Kaehler differentials.
- Show that locally on the target, smooth algebras are standard smooth.
## Implementation details
Standard smooth algebras and ring homomorphisms feature 4 universe levels: The universe levels of
the rings involved and the universe levels of the types of the variables and relations.
## Notes
This contribution was created as part of the AIM workshop "Formalizing algebraic geometry"
in June 2024.
-/
universe t t' w w' u v
open TensorProduct
variable (n : ℕ)
namespace Algebra
variable (R : Type u) [CommRing R]
variable (S : Type v) [CommRing S] [Algebra R S]
/--
A `PreSubmersivePresentation` of an `R`-algebra `S` is a `Presentation`
with finitely-many relations equipped with an injective `map : relations → vars`.
This map determines how the differential of `P` is constructed. See
`PreSubmersivePresentation.differential` for details.
-/
@[nolint checkUnivs]
structure PreSubmersivePresentation extends Algebra.Presentation.{t, w} R S where
/-- A map from the relations type to the variables type. Used to compute the differential. -/
map : rels → vars
map_inj : Function.Injective map
relations_finite : Finite rels
namespace PreSubmersivePresentation
attribute [instance] relations_finite
variable {R S}
variable (P : PreSubmersivePresentation R S)
lemma card_relations_le_card_vars_of_isFinite [P.IsFinite] :
Nat.card P.rels ≤ Nat.card P.vars :=
Nat.card_le_card_of_injective P.map P.map_inj
/-- The standard basis of `P.rels → P.ring`. -/
noncomputable abbrev basis : Basis P.rels P.Ring (P.rels → P.Ring) :=
Pi.basisFun P.Ring P.rels
/--
The differential of a `P : PreSubmersivePresentation` is a `P.Ring`-linear map on
`P.rels → P.Ring`:
The `j`-th standard basis vector, corresponding to the `j`-th relation of `P`, is mapped
to the vector of partial derivatives of `P.relation j` with respect
to the coordinates `P.map i` for all `i : P.rels`.
The determinant of this map is the jacobian of `P` used to define when a `PreSubmersivePresentation`
is submersive. See `PreSubmersivePresentation.jacobian`.
-/
noncomputable def differential : (P.rels → P.Ring) →ₗ[P.Ring] (P.rels → P.Ring) :=
Basis.constr P.basis P.Ring
(fun j i : P.rels ↦ MvPolynomial.pderiv (P.map i) (P.relation j))
/-- The jacobian of a `P : PreSubmersivePresentation` is the determinant
of `P.differential` viewed as element of `S`. -/
noncomputable def jacobian : S :=
algebraMap P.Ring S <| LinearMap.det P.differential
section Matrix
variable [Fintype P.rels] [DecidableEq P.rels]
/--
If `P.rels` has a `Fintype` and `DecidableEq` instance, the differential of `P`
can be expressed in matrix form.
-/
noncomputable def jacobiMatrix : Matrix P.rels P.rels P.Ring :=
LinearMap.toMatrix P.basis P.basis P.differential
lemma jacobian_eq_jacobiMatrix_det : P.jacobian = algebraMap P.Ring S P.jacobiMatrix.det := by
simp [jacobiMatrix, jacobian]
lemma jacobiMatrix_apply (i j : P.rels) :
P.jacobiMatrix i j = MvPolynomial.pderiv (P.map i) (P.relation j) := by
simp [jacobiMatrix, LinearMap.toMatrix, differential]
end Matrix
end PreSubmersivePresentation
/--
A `PreSubmersivePresentation` is submersive if its jacobian is a unit in `S`
and the presentation is finite.
-/
@[nolint checkUnivs]
structure SubmersivePresentation extends PreSubmersivePresentation.{t, w} R S where
jacobian_isUnit : IsUnit toPreSubmersivePresentation.jacobian
isFinite : toPreSubmersivePresentation.IsFinite := by infer_instance
attribute [instance] SubmersivePresentation.isFinite
/--
An `R`-algebra `S` is called standard smooth, if there
exists a submersive presentation.
-/
class IsStandardSmooth : Prop where
out : Nonempty (SubmersivePresentation.{t, w} R S)
/--
The relative dimension of a standard smooth `R`-algebra `S` is
the dimension of an arbitrarily chosen submersive `R`-presentation of `S`.
Note: If `S` is non-trivial, this number is independent of the choice of the presentation as it is
equal to the `S`-rank of `Ω[S/R]` (TODO).
-/
noncomputable def IsStandardSmooth.relativeDimension [IsStandardSmooth R S] : ℕ :=
‹IsStandardSmooth R S›.out.some.dimension
/--
An `R`-algebra `S` is called standard smooth of relative dimension `n`, if there exists
a submersive presentation of dimension `n`.
-/
class IsStandardSmoothOfRelativeDimension : Prop where
out : ∃ P : SubmersivePresentation.{t, w} R S, P.dimension = n
variable {R} {S}
lemma IsStandardSmoothOfRelativeDimension.isStandardSmooth
[IsStandardSmoothOfRelativeDimension.{t, w} n R S] :
IsStandardSmooth.{t, w} R S :=
⟨‹IsStandardSmoothOfRelativeDimension n R S›.out.nonempty⟩
end Algebra
namespace RingHom
variable {R : Type u} [CommRing R]
variable {S : Type v} [CommRing S]
/-- A ring homomorphism `R →+* S` is standard smooth if `S` is standard smooth as `R`-algebra. -/
def IsStandardSmooth (f : R →+* S) : Prop :=
@Algebra.IsStandardSmooth.{t, w} _ _ _ _ f.toAlgebra
/-- A ring homomorphism `R →+* S` is standard smooth of relative dimension `n` if
`S` is standard smooth of relative dimension `n` as `R`-algebra. -/
def IsStandardSmoothOfRelativeDimension (f : R →+* S) : Prop :=
@Algebra.IsStandardSmoothOfRelativeDimension.{t, w} n _ _ _ _ f.toAlgebra
lemma IsStandardSmoothOfRelativeDimension.isStandardSmooth (f : R →+* S)
(hf : IsStandardSmoothOfRelativeDimension.{t, w} n f) :
IsStandardSmooth.{t, w} f :=
letI : Algebra R S := f.toAlgebra
letI : Algebra.IsStandardSmoothOfRelativeDimension.{t, w} n R S := hf
Algebra.IsStandardSmoothOfRelativeDimension.isStandardSmooth n
end RingHom
|
RingTheory\TensorProduct\Basic.lean | /-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Johan Commelin
-/
import Mathlib.LinearAlgebra.FiniteDimensional.Defs
import Mathlib.LinearAlgebra.TensorProduct.Tower
import Mathlib.RingTheory.Adjoin.Basic
import Mathlib.LinearAlgebra.DirectSum.Finsupp
/-!
# The tensor product of R-algebras
This file provides results about the multiplicative structure on `A ⊗[R] B` when `R` is a
commutative (semi)ring and `A` and `B` are both `R`-algebras. On these tensor products,
multiplication is characterized by `(a₁ ⊗ₜ b₁) * (a₂ ⊗ₜ b₂) = (a₁ * a₂) ⊗ₜ (b₁ * b₂)`.
## Main declarations
- `LinearMap.baseChange A f` is the `A`-linear map `A ⊗ f`, for an `R`-linear map `f`.
- `Algebra.TensorProduct.semiring`: the ring structure on `A ⊗[R] B` for two `R`-algebras `A`, `B`.
- `Algebra.TensorProduct.leftAlgebra`: the `S`-algebra structure on `A ⊗[R] B`, for when `A` is
additionally an `S` algebra.
- the structure isomorphisms
* `Algebra.TensorProduct.lid : R ⊗[R] A ≃ₐ[R] A`
* `Algebra.TensorProduct.rid : A ⊗[R] R ≃ₐ[S] A` (usually used with `S = R` or `S = A`)
* `Algebra.TensorProduct.comm : A ⊗[R] B ≃ₐ[R] B ⊗[R] A`
* `Algebra.TensorProduct.assoc : ((A ⊗[R] B) ⊗[R] C) ≃ₐ[R] (A ⊗[R] (B ⊗[R] C))`
- `Algebra.TensorProduct.liftEquiv`: a universal property for the tensor product of algebras.
## References
* [C. Kassel, *Quantum Groups* (§II.4)][Kassel1995]
-/
suppress_compilation
open scoped TensorProduct
open TensorProduct
namespace LinearMap
open TensorProduct
/-!
### The base-change of a linear map of `R`-modules to a linear map of `A`-modules
-/
section Semiring
variable {R A B M N P : Type*} [CommSemiring R]
variable [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]
variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P]
variable [Module R M] [Module R N] [Module R P]
variable (r : R) (f g : M →ₗ[R] N)
variable (A)
/-- `baseChange A f` for `f : M →ₗ[R] N` is the `A`-linear map `A ⊗[R] M →ₗ[A] A ⊗[R] N`.
This "base change" operation is also known as "extension of scalars". -/
def baseChange (f : M →ₗ[R] N) : A ⊗[R] M →ₗ[A] A ⊗[R] N :=
AlgebraTensorModule.map (LinearMap.id : A →ₗ[A] A) f
variable {A}
@[simp]
theorem baseChange_tmul (a : A) (x : M) : f.baseChange A (a ⊗ₜ x) = a ⊗ₜ f x :=
rfl
theorem baseChange_eq_ltensor : (f.baseChange A : A ⊗ M → A ⊗ N) = f.lTensor A :=
rfl
@[simp]
theorem baseChange_add : (f + g).baseChange A = f.baseChange A + g.baseChange A := by
ext
-- Porting note: added `-baseChange_tmul`
simp [baseChange_eq_ltensor, -baseChange_tmul]
@[simp]
theorem baseChange_zero : baseChange A (0 : M →ₗ[R] N) = 0 := by
ext
simp [baseChange_eq_ltensor]
@[simp]
theorem baseChange_smul : (r • f).baseChange A = r • f.baseChange A := by
ext
simp [baseChange_tmul]
@[simp]
lemma baseChange_id : (.id : M →ₗ[R] M).baseChange A = .id := by
ext; simp
lemma baseChange_comp (g : N →ₗ[R] P) :
(g ∘ₗ f).baseChange A = g.baseChange A ∘ₗ f.baseChange A := by
ext; simp
variable (R M) in
@[simp]
lemma baseChange_one : (1 : Module.End R M).baseChange A = 1 := baseChange_id
lemma baseChange_mul (f g : Module.End R M) :
(f * g).baseChange A = f.baseChange A * g.baseChange A := by
ext; simp
variable (R A M N)
/-- `baseChange` as a linear map.
When `M = N`, this is true more strongly as `Module.End.baseChangeHom`. -/
@[simps]
def baseChangeHom : (M →ₗ[R] N) →ₗ[R] A ⊗[R] M →ₗ[A] A ⊗[R] N where
toFun := baseChange A
map_add' := baseChange_add
map_smul' := baseChange_smul
/-- `baseChange` as an `AlgHom`. -/
@[simps!]
def _root_.Module.End.baseChangeHom : Module.End R M →ₐ[R] Module.End A (A ⊗[R] M) :=
.ofLinearMap (LinearMap.baseChangeHom _ _ _ _) (baseChange_one _ _) baseChange_mul
lemma baseChange_pow (f : Module.End R M) (n : ℕ) :
(f ^ n).baseChange A = f.baseChange A ^ n :=
map_pow (Module.End.baseChangeHom _ _ _) f n
end Semiring
section Ring
variable {R A B M N : Type*} [CommRing R]
variable [Ring A] [Algebra R A] [Ring B] [Algebra R B]
variable [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N]
variable (f g : M →ₗ[R] N)
@[simp]
theorem baseChange_sub : (f - g).baseChange A = f.baseChange A - g.baseChange A := by
ext
-- Porting note: `tmul_sub` wasn't needed in mathlib3
simp [baseChange_eq_ltensor, tmul_sub]
@[simp]
theorem baseChange_neg : (-f).baseChange A = -f.baseChange A := by
ext
-- Porting note: `tmul_neg` wasn't needed in mathlib3
simp [baseChange_eq_ltensor, tmul_neg]
end Ring
section liftBaseChange
variable {R M N} (A) [CommSemiring R] [CommSemiring A] [Algebra R A] [AddCommMonoid M]
variable [AddCommMonoid N] [Module R M] [Module R N] [Module A N] [IsScalarTower R A N]
/--
If `M` is an `R`-module and `N` is an `A`-module, then `A`-linear maps `A ⊗[R] M →ₗ[A] N`
correspond to `R` linear maps `M →ₗ[R] N` by composing with `M → A ⊗ M`, `x ↦ 1 ⊗ x`.
-/
noncomputable
def liftBaseChangeEquiv : (M →ₗ[R] N) ≃ₗ[A] (A ⊗[R] M →ₗ[A] N) :=
(LinearMap.ringLmapEquivSelf _ _ _).symm.trans (AlgebraTensorModule.lift.equiv _ _ _ _ _ _)
/-- If `N` is an `A` module, we may lift a linear map `M →ₗ[R] N` to `A ⊗[R] M →ₗ[A] N` -/
noncomputable
abbrev liftBaseChange (l : M →ₗ[R] N) : A ⊗[R] M →ₗ[A] N :=
LinearMap.liftBaseChangeEquiv A l
@[simp]
lemma liftBaseChange_tmul (l : M →ₗ[R] N) (x y) : l.liftBaseChange A (x ⊗ₜ y) = x • l y := rfl
lemma liftBaseChange_one_tmul (l : M →ₗ[R] N) (y) : l.liftBaseChange A (1 ⊗ₜ y) = l y := by simp
@[simp]
lemma liftBaseChangeEquiv_symm_apply (l : A ⊗[R] M →ₗ[A] N) (x) :
(liftBaseChangeEquiv A).symm l x = l (1 ⊗ₜ x) := rfl
lemma liftBaseChange_comp {P} [AddCommMonoid P] [Module A P] [Module R P] [IsScalarTower R A P]
(l : M →ₗ[R] N) (l' : N →ₗ[A] P) :
l' ∘ₗ l.liftBaseChange A = (l'.restrictScalars R ∘ₗ l).liftBaseChange A := by
ext
simp
@[simp]
lemma range_liftBaseChange (l : M →ₗ[R] N) :
LinearMap.range (l.liftBaseChange A) = Submodule.span A (LinearMap.range l) := by
apply le_antisymm
· rintro _ ⟨x, rfl⟩
induction x using TensorProduct.induction_on
· simp
· rw [LinearMap.liftBaseChange_tmul]
exact Submodule.smul_mem _ _ (Submodule.subset_span ⟨_, rfl⟩)
· rw [map_add]
exact add_mem ‹_› ‹_›
· rw [Submodule.span_le]
rintro _ ⟨x, rfl⟩
exact ⟨1 ⊗ₜ x, by simp⟩
end liftBaseChange
end LinearMap
namespace Algebra
namespace TensorProduct
universe uR uS uA uB uC uD uE uF
variable {R : Type uR} {S : Type uS}
variable {A : Type uA} {B : Type uB} {C : Type uC} {D : Type uD} {E : Type uE} {F : Type uF}
/-!
### The `R`-algebra structure on `A ⊗[R] B`
-/
section AddCommMonoidWithOne
variable [CommSemiring R]
variable [AddCommMonoidWithOne A] [Module R A]
variable [AddCommMonoidWithOne B] [Module R B]
instance : One (A ⊗[R] B) where one := 1 ⊗ₜ 1
theorem one_def : (1 : A ⊗[R] B) = (1 : A) ⊗ₜ (1 : B) :=
rfl
instance instAddCommMonoidWithOne : AddCommMonoidWithOne (A ⊗[R] B) where
natCast n := n ⊗ₜ 1
natCast_zero := by simp
natCast_succ n := by simp [add_tmul, one_def]
add_comm := add_comm
theorem natCast_def (n : ℕ) : (n : A ⊗[R] B) = (n : A) ⊗ₜ (1 : B) := rfl
theorem natCast_def' (n : ℕ) : (n : A ⊗[R] B) = (1 : A) ⊗ₜ (n : B) := by
rw [natCast_def, ← nsmul_one, smul_tmul, nsmul_one]
end AddCommMonoidWithOne
section NonUnitalNonAssocSemiring
variable [CommSemiring R]
variable [NonUnitalNonAssocSemiring A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]
variable [NonUnitalNonAssocSemiring B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B]
/-- (Implementation detail)
The multiplication map on `A ⊗[R] B`,
as an `R`-bilinear map.
-/
@[irreducible]
def mul : A ⊗[R] B →ₗ[R] A ⊗[R] B →ₗ[R] A ⊗[R] B :=
TensorProduct.map₂ (LinearMap.mul R A) (LinearMap.mul R B)
unseal mul in
@[simp]
theorem mul_apply (a₁ a₂ : A) (b₁ b₂ : B) :
mul (a₁ ⊗ₜ[R] b₁) (a₂ ⊗ₜ[R] b₂) = (a₁ * a₂) ⊗ₜ[R] (b₁ * b₂) :=
rfl
-- providing this instance separately makes some downstream code substantially faster
instance instMul : Mul (A ⊗[R] B) where
mul a b := mul a b
unseal mul in
@[simp]
theorem tmul_mul_tmul (a₁ a₂ : A) (b₁ b₂ : B) :
a₁ ⊗ₜ[R] b₁ * a₂ ⊗ₜ[R] b₂ = (a₁ * a₂) ⊗ₜ[R] (b₁ * b₂) :=
rfl
unseal mul in
theorem _root_.SemiconjBy.tmul {a₁ a₂ a₃ : A} {b₁ b₂ b₃ : B}
(ha : SemiconjBy a₁ a₂ a₃) (hb : SemiconjBy b₁ b₂ b₃) :
SemiconjBy (a₁ ⊗ₜ[R] b₁) (a₂ ⊗ₜ[R] b₂) (a₃ ⊗ₜ[R] b₃) :=
congr_arg₂ (· ⊗ₜ[R] ·) ha.eq hb.eq
nonrec theorem _root_.Commute.tmul {a₁ a₂ : A} {b₁ b₂ : B}
(ha : Commute a₁ a₂) (hb : Commute b₁ b₂) :
Commute (a₁ ⊗ₜ[R] b₁) (a₂ ⊗ₜ[R] b₂) :=
ha.tmul hb
instance instNonUnitalNonAssocSemiring : NonUnitalNonAssocSemiring (A ⊗[R] B) where
left_distrib a b c := by simp [HMul.hMul, Mul.mul]
right_distrib a b c := by simp [HMul.hMul, Mul.mul]
zero_mul a := by simp [HMul.hMul, Mul.mul]
mul_zero a := by simp [HMul.hMul, Mul.mul]
-- we want `isScalarTower_right` to take priority since it's better for unification elsewhere
instance (priority := 100) isScalarTower_right [Monoid S] [DistribMulAction S A]
[IsScalarTower S A A] [SMulCommClass R S A] : IsScalarTower S (A ⊗[R] B) (A ⊗[R] B) where
smul_assoc r x y := by
change r • x * y = r • (x * y)
induction y with
| zero => simp [smul_zero]
| tmul a b => induction x with
| zero => simp [smul_zero]
| tmul a' b' =>
dsimp
rw [TensorProduct.smul_tmul', TensorProduct.smul_tmul', tmul_mul_tmul, smul_mul_assoc]
| add x y hx hy => simp [smul_add, add_mul _, *]
| add x y hx hy => simp [smul_add, mul_add _, *]
-- we want `Algebra.to_smulCommClass` to take priority since it's better for unification elsewhere
instance (priority := 100) sMulCommClass_right [Monoid S] [DistribMulAction S A]
[SMulCommClass S A A] [SMulCommClass R S A] : SMulCommClass S (A ⊗[R] B) (A ⊗[R] B) where
smul_comm r x y := by
change r • (x * y) = x * r • y
induction y with
| zero => simp [smul_zero]
| tmul a b => induction x with
| zero => simp [smul_zero]
| tmul a' b' =>
dsimp
rw [TensorProduct.smul_tmul', TensorProduct.smul_tmul', tmul_mul_tmul, mul_smul_comm]
| add x y hx hy => simp [smul_add, add_mul _, *]
| add x y hx hy => simp [smul_add, mul_add _, *]
end NonUnitalNonAssocSemiring
section NonAssocSemiring
variable [CommSemiring R]
variable [NonAssocSemiring A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]
variable [NonAssocSemiring B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B]
protected theorem one_mul (x : A ⊗[R] B) : mul (1 ⊗ₜ 1) x = x := by
refine TensorProduct.induction_on x ?_ ?_ ?_ <;> simp (config := { contextual := true })
protected theorem mul_one (x : A ⊗[R] B) : mul x (1 ⊗ₜ 1) = x := by
refine TensorProduct.induction_on x ?_ ?_ ?_ <;> simp (config := { contextual := true })
instance instNonAssocSemiring : NonAssocSemiring (A ⊗[R] B) where
one_mul := Algebra.TensorProduct.one_mul
mul_one := Algebra.TensorProduct.mul_one
toNonUnitalNonAssocSemiring := instNonUnitalNonAssocSemiring
__ := instAddCommMonoidWithOne
end NonAssocSemiring
section NonUnitalSemiring
variable [CommSemiring R]
variable [NonUnitalSemiring A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]
variable [NonUnitalSemiring B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B]
unseal mul in
protected theorem mul_assoc (x y z : A ⊗[R] B) : mul (mul x y) z = mul x (mul y z) := by
-- restate as an equality of morphisms so that we can use `ext`
suffices LinearMap.llcomp R _ _ _ mul ∘ₗ mul =
(LinearMap.llcomp R _ _ _ LinearMap.lflip <| LinearMap.llcomp R _ _ _ mul.flip ∘ₗ mul).flip by
exact DFunLike.congr_fun (DFunLike.congr_fun (DFunLike.congr_fun this x) y) z
ext xa xb ya yb za zb
exact congr_arg₂ (· ⊗ₜ ·) (mul_assoc xa ya za) (mul_assoc xb yb zb)
instance instNonUnitalSemiring : NonUnitalSemiring (A ⊗[R] B) where
mul_assoc := Algebra.TensorProduct.mul_assoc
end NonUnitalSemiring
section Semiring
variable [CommSemiring R]
variable [Semiring A] [Algebra R A]
variable [Semiring B] [Algebra R B]
variable [Semiring C] [Algebra R C]
instance instSemiring : Semiring (A ⊗[R] B) where
left_distrib a b c := by simp [HMul.hMul, Mul.mul]
right_distrib a b c := by simp [HMul.hMul, Mul.mul]
zero_mul a := by simp [HMul.hMul, Mul.mul]
mul_zero a := by simp [HMul.hMul, Mul.mul]
mul_assoc := Algebra.TensorProduct.mul_assoc
one_mul := Algebra.TensorProduct.one_mul
mul_one := Algebra.TensorProduct.mul_one
natCast_zero := AddMonoidWithOne.natCast_zero
natCast_succ := AddMonoidWithOne.natCast_succ
@[simp]
theorem tmul_pow (a : A) (b : B) (k : ℕ) : a ⊗ₜ[R] b ^ k = (a ^ k) ⊗ₜ[R] (b ^ k) := by
induction' k with k ih
· simp [one_def]
· simp [pow_succ, ih]
/-- The ring morphism `A →+* A ⊗[R] B` sending `a` to `a ⊗ₜ 1`. -/
@[simps]
def includeLeftRingHom : A →+* A ⊗[R] B where
toFun a := a ⊗ₜ 1
map_zero' := by simp
map_add' := by simp [add_tmul]
map_one' := rfl
map_mul' := by simp
variable [CommSemiring S] [Algebra S A]
instance leftAlgebra [SMulCommClass R S A] : Algebra S (A ⊗[R] B) :=
{ commutes' := fun r x => by
dsimp only [RingHom.toFun_eq_coe, RingHom.comp_apply, includeLeftRingHom_apply]
rw [algebraMap_eq_smul_one, ← smul_tmul', ← one_def, mul_smul_comm, smul_mul_assoc, mul_one,
one_mul]
smul_def' := fun r x => by
dsimp only [RingHom.toFun_eq_coe, RingHom.comp_apply, includeLeftRingHom_apply]
rw [algebraMap_eq_smul_one, ← smul_tmul', smul_mul_assoc, ← one_def, one_mul]
toRingHom := TensorProduct.includeLeftRingHom.comp (algebraMap S A) }
example : (Semiring.toNatAlgebra : Algebra ℕ (ℕ ⊗[ℕ] B)) = leftAlgebra := rfl
-- This is for the `undergrad.yaml` list.
/-- The tensor product of two `R`-algebras is an `R`-algebra. -/
instance instAlgebra : Algebra R (A ⊗[R] B) :=
inferInstance
@[simp]
theorem algebraMap_apply [SMulCommClass R S A] (r : S) :
algebraMap S (A ⊗[R] B) r = (algebraMap S A) r ⊗ₜ 1 :=
rfl
theorem algebraMap_apply' (r : R) :
algebraMap R (A ⊗[R] B) r = 1 ⊗ₜ algebraMap R B r := by
rw [algebraMap_apply, Algebra.algebraMap_eq_smul_one, Algebra.algebraMap_eq_smul_one, smul_tmul]
/-- The `R`-algebra morphism `A →ₐ[R] A ⊗[R] B` sending `a` to `a ⊗ₜ 1`. -/
def includeLeft [SMulCommClass R S A] : A →ₐ[S] A ⊗[R] B :=
{ includeLeftRingHom with commutes' := by simp }
@[simp]
theorem includeLeft_apply [SMulCommClass R S A] (a : A) :
(includeLeft : A →ₐ[S] A ⊗[R] B) a = a ⊗ₜ 1 :=
rfl
/-- The algebra morphism `B →ₐ[R] A ⊗[R] B` sending `b` to `1 ⊗ₜ b`. -/
def includeRight : B →ₐ[R] A ⊗[R] B where
toFun b := 1 ⊗ₜ b
map_zero' := by simp
map_add' := by simp [tmul_add]
map_one' := rfl
map_mul' := by simp
commutes' r := by simp only [algebraMap_apply']
@[simp]
theorem includeRight_apply (b : B) : (includeRight : B →ₐ[R] A ⊗[R] B) b = 1 ⊗ₜ b :=
rfl
theorem includeLeftRingHom_comp_algebraMap :
(includeLeftRingHom.comp (algebraMap R A) : R →+* A ⊗[R] B) =
includeRight.toRingHom.comp (algebraMap R B) := by
ext
simp
section ext
variable [Algebra R S] [Algebra S C] [IsScalarTower R S A] [IsScalarTower R S C]
/-- A version of `TensorProduct.ext` for `AlgHom`.
Using this as the `@[ext]` lemma instead of `Algebra.TensorProduct.ext'` allows `ext` to apply
lemmas specific to `A →ₐ[S] _` and `B →ₐ[R] _`; notably this allows recursion into nested tensor
products of algebras.
See note [partially-applied ext lemmas]. -/
@[ext high]
theorem ext ⦃f g : (A ⊗[R] B) →ₐ[S] C⦄
(ha : f.comp includeLeft = g.comp includeLeft)
(hb : (f.restrictScalars R).comp includeRight = (g.restrictScalars R).comp includeRight) :
f = g := by
apply AlgHom.toLinearMap_injective
ext a b
have := congr_arg₂ HMul.hMul (AlgHom.congr_fun ha a) (AlgHom.congr_fun hb b)
dsimp at *
rwa [← _root_.map_mul, ← _root_.map_mul, tmul_mul_tmul, _root_.one_mul, _root_.mul_one] at this
theorem ext' {g h : A ⊗[R] B →ₐ[S] C} (H : ∀ a b, g (a ⊗ₜ b) = h (a ⊗ₜ b)) : g = h :=
ext (AlgHom.ext fun _ => H _ _) (AlgHom.ext fun _ => H _ _)
end ext
end Semiring
section AddCommGroupWithOne
variable [CommSemiring R]
variable [AddCommGroupWithOne A] [Module R A]
variable [AddCommGroupWithOne B] [Module R B]
instance instAddCommGroupWithOne : AddCommGroupWithOne (A ⊗[R] B) where
toAddCommGroup := TensorProduct.addCommGroup
__ := instAddCommMonoidWithOne
intCast z := z ⊗ₜ (1 : B)
intCast_ofNat n := by simp [natCast_def]
intCast_negSucc n := by simp [natCast_def, add_tmul, neg_tmul, one_def]
theorem intCast_def (z : ℤ) : (z : A ⊗[R] B) = (z : A) ⊗ₜ (1 : B) := rfl
end AddCommGroupWithOne
section NonUnitalNonAssocRing
variable [CommRing R]
variable [NonUnitalNonAssocRing A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]
variable [NonUnitalNonAssocRing B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B]
instance instNonUnitalNonAssocRing : NonUnitalNonAssocRing (A ⊗[R] B) where
toAddCommGroup := TensorProduct.addCommGroup
__ := instNonUnitalNonAssocSemiring
end NonUnitalNonAssocRing
section NonAssocRing
variable [CommRing R]
variable [NonAssocRing A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]
variable [NonAssocRing B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B]
instance instNonAssocRing : NonAssocRing (A ⊗[R] B) where
toAddCommGroup := TensorProduct.addCommGroup
__ := instNonAssocSemiring
__ := instAddCommGroupWithOne
end NonAssocRing
section NonUnitalRing
variable [CommRing R]
variable [NonUnitalRing A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]
variable [NonUnitalRing B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B]
instance instNonUnitalRing : NonUnitalRing (A ⊗[R] B) where
toAddCommGroup := TensorProduct.addCommGroup
__ := instNonUnitalSemiring
end NonUnitalRing
section CommSemiring
variable [CommSemiring R]
variable [CommSemiring A] [Algebra R A]
variable [CommSemiring B] [Algebra R B]
instance instCommSemiring : CommSemiring (A ⊗[R] B) where
toSemiring := inferInstance
mul_comm x y := by
refine TensorProduct.induction_on x ?_ ?_ ?_
· simp
· intro a₁ b₁
refine TensorProduct.induction_on y ?_ ?_ ?_
· simp
· intro a₂ b₂
simp [mul_comm]
· intro a₂ b₂ ha hb
simp [mul_add, add_mul, ha, hb]
· intro x₁ x₂ h₁ h₂
simp [mul_add, add_mul, h₁, h₂]
end CommSemiring
section Ring
variable [CommRing R]
variable [Ring A] [Algebra R A]
variable [Ring B] [Algebra R B]
instance instRing : Ring (A ⊗[R] B) where
toSemiring := instSemiring
__ := TensorProduct.addCommGroup
__ := instNonAssocRing
theorem intCast_def' (z : ℤ) : (z : A ⊗[R] B) = (1 : A) ⊗ₜ (z : B) := by
rw [intCast_def, ← zsmul_one, smul_tmul, zsmul_one]
-- verify there are no diamonds
example : (instRing : Ring (A ⊗[R] B)).toAddCommGroup = addCommGroup := by
with_reducible_and_instances rfl
-- fails at `with_reducible_and_instances rfl` #10906
example : (Ring.toIntAlgebra _ : Algebra ℤ (ℤ ⊗[ℤ] B)) = leftAlgebra := rfl
end Ring
section CommRing
variable [CommRing R]
variable [CommRing A] [Algebra R A]
variable [CommRing B] [Algebra R B]
instance instCommRing : CommRing (A ⊗[R] B) :=
{ toRing := inferInstance
mul_comm := mul_comm }
section RightAlgebra
/-- `S ⊗[R] T` has a `T`-algebra structure. This is not a global instance or else the action of
`S` on `S ⊗[R] S` would be ambiguous. -/
abbrev rightAlgebra : Algebra B (A ⊗[R] B) :=
(Algebra.TensorProduct.includeRight.toRingHom : B →+* A ⊗[R] B).toAlgebra
attribute [local instance] TensorProduct.rightAlgebra
instance right_isScalarTower : IsScalarTower R B (A ⊗[R] B) :=
IsScalarTower.of_algebraMap_eq fun r => (Algebra.TensorProduct.includeRight.commutes r).symm
end RightAlgebra
end CommRing
/-- Verify that typeclass search finds the ring structure on `A ⊗[ℤ] B`
when `A` and `B` are merely rings, by treating both as `ℤ`-algebras.
-/
example [Ring A] [Ring B] : Ring (A ⊗[ℤ] B) := by infer_instance
/-- Verify that typeclass search finds the comm_ring structure on `A ⊗[ℤ] B`
when `A` and `B` are merely comm_rings, by treating both as `ℤ`-algebras.
-/
example [CommRing A] [CommRing B] : CommRing (A ⊗[ℤ] B) := by infer_instance
/-!
We now build the structure maps for the symmetric monoidal category of `R`-algebras.
-/
section Monoidal
section
variable [CommSemiring R] [CommSemiring S] [Algebra R S]
variable [Semiring A] [Algebra R A] [Algebra S A] [IsScalarTower R S A]
variable [Semiring B] [Algebra R B]
variable [Semiring C] [Algebra S C]
variable [Semiring D] [Algebra R D]
/-- Build an algebra morphism from a linear map out of a tensor product, and evidence that on pure
tensors, it preserves multiplication and the identity.
Note that we state `h_one` using `1 ⊗ₜ[R] 1` instead of `1` so that lemmas about `f` applied to pure
tensors can be directly applied by the caller (without needing `TensorProduct.one_def`).
-/
def algHomOfLinearMapTensorProduct (f : A ⊗[R] B →ₗ[S] C)
(h_mul : ∀ (a₁ a₂ : A) (b₁ b₂ : B), f ((a₁ * a₂) ⊗ₜ (b₁ * b₂)) = f (a₁ ⊗ₜ b₁) * f (a₂ ⊗ₜ b₂))
(h_one : f (1 ⊗ₜ[R] 1) = 1) : A ⊗[R] B →ₐ[S] C :=
#adaptation_note
/--
After https://github.com/leanprover/lean4/pull/4119 we either need to specify
the `(R := S) (A := A ⊗[R] B)` arguments, or use `set_option maxSynthPendingDepth 2 in`.
-/
AlgHom.ofLinearMap f h_one <| (f.map_mul_iff (R := S) (A := A ⊗[R] B)).2 <| by
-- these instances are needed by the statement of `ext`, but not by the current definition.
letI : Algebra R C := RestrictScalars.algebra R S C
letI : IsScalarTower R S C := RestrictScalars.isScalarTower R S C
ext
dsimp
exact h_mul _ _ _ _
@[simp]
theorem algHomOfLinearMapTensorProduct_apply (f h_mul h_one x) :
(algHomOfLinearMapTensorProduct f h_mul h_one : A ⊗[R] B →ₐ[S] C) x = f x :=
rfl
/-- Build an algebra equivalence from a linear equivalence out of a tensor product, and evidence
that on pure tensors, it preserves multiplication and the identity.
Note that we state `h_one` using `1 ⊗ₜ[R] 1` instead of `1` so that lemmas about `f` applied to pure
tensors can be directly applied by the caller (without needing `TensorProduct.one_def`).
-/
def algEquivOfLinearEquivTensorProduct (f : A ⊗[R] B ≃ₗ[S] C)
(h_mul : ∀ (a₁ a₂ : A) (b₁ b₂ : B), f ((a₁ * a₂) ⊗ₜ (b₁ * b₂)) = f (a₁ ⊗ₜ b₁) * f (a₂ ⊗ₜ b₂))
(h_one : f (1 ⊗ₜ[R] 1) = 1) : A ⊗[R] B ≃ₐ[S] C :=
{ algHomOfLinearMapTensorProduct (f : A ⊗[R] B →ₗ[S] C) h_mul h_one, f with }
@[simp]
theorem algEquivOfLinearEquivTensorProduct_apply (f h_mul h_one x) :
(algEquivOfLinearEquivTensorProduct f h_mul h_one : A ⊗[R] B ≃ₐ[S] C) x = f x :=
rfl
variable [Algebra R C]
/-- Build an algebra equivalence from a linear equivalence out of a triple tensor product,
and evidence of multiplicativity on pure tensors.
-/
def algEquivOfLinearEquivTripleTensorProduct (f : (A ⊗[R] B) ⊗[R] C ≃ₗ[R] D)
(h_mul :
∀ (a₁ a₂ : A) (b₁ b₂ : B) (c₁ c₂ : C),
f ((a₁ * a₂) ⊗ₜ (b₁ * b₂) ⊗ₜ (c₁ * c₂)) = f (a₁ ⊗ₜ b₁ ⊗ₜ c₁) * f (a₂ ⊗ₜ b₂ ⊗ₜ c₂))
(h_one : f (((1 : A) ⊗ₜ[R] (1 : B)) ⊗ₜ[R] (1 : C)) = 1) :
(A ⊗[R] B) ⊗[R] C ≃ₐ[R] D :=
AlgEquiv.ofLinearEquiv f h_one <| f.map_mul_iff.2 <| by
ext
dsimp
exact h_mul _ _ _ _ _ _
@[simp]
theorem algEquivOfLinearEquivTripleTensorProduct_apply (f h_mul h_one x) :
(algEquivOfLinearEquivTripleTensorProduct f h_mul h_one : (A ⊗[R] B) ⊗[R] C ≃ₐ[R] D) x = f x :=
rfl
section lift
variable [IsScalarTower R S C]
/-- The forward direction of the universal property of tensor products of algebras; any algebra
morphism from the tensor product can be factored as the product of two algebra morphisms that
commute.
See `Algebra.TensorProduct.liftEquiv` for the fact that every morphism factors this way. -/
def lift (f : A →ₐ[S] C) (g : B →ₐ[R] C) (hfg : ∀ x y, Commute (f x) (g y)) : (A ⊗[R] B) →ₐ[S] C :=
algHomOfLinearMapTensorProduct
(AlgebraTensorModule.lift <|
letI restr : (C →ₗ[S] C) →ₗ[S] _ :=
{ toFun := (·.restrictScalars R)
map_add' := fun f g => LinearMap.ext fun x => rfl
map_smul' := fun c g => LinearMap.ext fun x => rfl }
LinearMap.flip <| (restr ∘ₗ LinearMap.mul S C ∘ₗ f.toLinearMap).flip ∘ₗ g)
(fun a₁ a₂ b₁ b₂ => show f (a₁ * a₂) * g (b₁ * b₂) = f a₁ * g b₁ * (f a₂ * g b₂) by
rw [_root_.map_mul, _root_.map_mul, (hfg a₂ b₁).mul_mul_mul_comm])
(show f 1 * g 1 = 1 by rw [_root_.map_one, _root_.map_one, one_mul])
@[simp]
theorem lift_tmul (f : A →ₐ[S] C) (g : B →ₐ[R] C) (hfg : ∀ x y, Commute (f x) (g y))
(a : A) (b : B) :
lift f g hfg (a ⊗ₜ b) = f a * g b :=
rfl
@[simp]
theorem lift_includeLeft_includeRight :
lift includeLeft includeRight (fun a b => (Commute.one_right _).tmul (Commute.one_left _)) =
.id S (A ⊗[R] B) := by
ext <;> simp
@[simp]
theorem lift_comp_includeLeft (f : A →ₐ[S] C) (g : B →ₐ[R] C) (hfg : ∀ x y, Commute (f x) (g y)) :
(lift f g hfg).comp includeLeft = f :=
AlgHom.ext <| by simp
@[simp]
theorem lift_comp_includeRight (f : A →ₐ[S] C) (g : B →ₐ[R] C) (hfg : ∀ x y, Commute (f x) (g y)) :
((lift f g hfg).restrictScalars R).comp includeRight = g :=
AlgHom.ext <| by simp
/-- The universal property of the tensor product of algebras.
Pairs of algebra morphisms that commute are equivalent to algebra morphisms from the tensor product.
This is `Algebra.TensorProduct.lift` as an equivalence.
See also `GradedTensorProduct.liftEquiv` for an alternative commutativity requirement for graded
algebra. -/
@[simps]
def liftEquiv : {fg : (A →ₐ[S] C) × (B →ₐ[R] C) // ∀ x y, Commute (fg.1 x) (fg.2 y)}
≃ ((A ⊗[R] B) →ₐ[S] C) where
toFun fg := lift fg.val.1 fg.val.2 fg.prop
invFun f' := ⟨(f'.comp includeLeft, (f'.restrictScalars R).comp includeRight), fun x y =>
((Commute.one_right _).tmul (Commute.one_left _)).map f'⟩
left_inv fg := by ext <;> simp
right_inv f' := by ext <;> simp
end lift
end
variable [CommSemiring R] [CommSemiring S] [Algebra R S]
variable [Semiring A] [Algebra R A] [Algebra S A] [IsScalarTower R S A]
variable [Semiring B] [Algebra R B] [Algebra S B] [IsScalarTower R S B]
variable [Semiring C] [Algebra R C]
variable [Semiring D] [Algebra R D]
variable [Semiring E] [Algebra R E]
variable [Semiring F] [Algebra R F]
section
variable (R A)
/-- The base ring is a left identity for the tensor product of algebra, up to algebra isomorphism.
-/
protected nonrec def lid : R ⊗[R] A ≃ₐ[R] A :=
algEquivOfLinearEquivTensorProduct (TensorProduct.lid R A) (by
simp only [mul_smul, lid_tmul, Algebra.smul_mul_assoc, Algebra.mul_smul_comm]
simp_rw [← mul_smul, mul_comm]
simp)
(by simp [Algebra.smul_def])
@[simp] theorem lid_toLinearEquiv :
(TensorProduct.lid R A).toLinearEquiv = _root_.TensorProduct.lid R A := rfl
variable {R} {A} in
@[simp]
theorem lid_tmul (r : R) (a : A) : TensorProduct.lid R A (r ⊗ₜ a) = r • a := rfl
variable {A} in
@[simp]
theorem lid_symm_apply (a : A) : (TensorProduct.lid R A).symm a = 1 ⊗ₜ a := rfl
variable (S)
/-- The base ring is a right identity for the tensor product of algebra, up to algebra isomorphism.
Note that if `A` is commutative this can be instantiated with `S = A`.
-/
protected nonrec def rid : A ⊗[R] R ≃ₐ[S] A :=
algEquivOfLinearEquivTensorProduct (AlgebraTensorModule.rid R S A)
(fun a₁ a₂ r₁ r₂ => smul_mul_smul r₁ r₂ a₁ a₂ |>.symm)
(one_smul R _)
@[simp] theorem rid_toLinearEquiv :
(TensorProduct.rid R S A).toLinearEquiv = AlgebraTensorModule.rid R S A := rfl
variable {R A} in
@[simp]
theorem rid_tmul (r : R) (a : A) : TensorProduct.rid R S A (a ⊗ₜ r) = r • a := rfl
variable {A} in
@[simp]
theorem rid_symm_apply (a : A) : (TensorProduct.rid R S A).symm a = a ⊗ₜ 1 := rfl
section
variable (B)
unseal mul in
/-- The tensor product of R-algebras is commutative, up to algebra isomorphism.
-/
protected def comm : A ⊗[R] B ≃ₐ[R] B ⊗[R] A :=
algEquivOfLinearEquivTensorProduct (_root_.TensorProduct.comm R A B) (fun _ _ _ _ => rfl) rfl
@[simp] theorem comm_toLinearEquiv :
(Algebra.TensorProduct.comm R A B).toLinearEquiv = _root_.TensorProduct.comm R A B := rfl
variable {A B} in
@[simp]
theorem comm_tmul (a : A) (b : B) :
TensorProduct.comm R A B (a ⊗ₜ b) = b ⊗ₜ a :=
rfl
variable {A B} in
@[simp]
theorem comm_symm_tmul (a : A) (b : B) :
(TensorProduct.comm R A B).symm (b ⊗ₜ a) = a ⊗ₜ b :=
rfl
theorem comm_symm :
(TensorProduct.comm R A B).symm = TensorProduct.comm R B A := by
ext; rfl
theorem adjoin_tmul_eq_top : adjoin R { t : A ⊗[R] B | ∃ a b, a ⊗ₜ[R] b = t } = ⊤ :=
top_le_iff.mp <| (top_le_iff.mpr <| span_tmul_eq_top R A B).trans (span_le_adjoin R _)
end
section
variable {R A}
unseal mul in
theorem assoc_aux_1 (a₁ a₂ : A) (b₁ b₂ : B) (c₁ c₂ : C) :
(TensorProduct.assoc R A B C) (((a₁ * a₂) ⊗ₜ[R] (b₁ * b₂)) ⊗ₜ[R] (c₁ * c₂)) =
(TensorProduct.assoc R A B C) ((a₁ ⊗ₜ[R] b₁) ⊗ₜ[R] c₁) *
(TensorProduct.assoc R A B C) ((a₂ ⊗ₜ[R] b₂) ⊗ₜ[R] c₂) :=
rfl
theorem assoc_aux_2 : (TensorProduct.assoc R A B C) ((1 ⊗ₜ[R] 1) ⊗ₜ[R] 1) = 1 :=
rfl
variable (R A B C)
-- Porting note: much nicer than Lean 3 proof
/-- The associator for tensor product of R-algebras, as an algebra isomorphism. -/
protected def assoc : (A ⊗[R] B) ⊗[R] C ≃ₐ[R] A ⊗[R] B ⊗[R] C :=
algEquivOfLinearEquivTripleTensorProduct
(_root_.TensorProduct.assoc R A B C)
Algebra.TensorProduct.assoc_aux_1
Algebra.TensorProduct.assoc_aux_2
@[simp] theorem assoc_toLinearEquiv :
(Algebra.TensorProduct.assoc R A B C).toLinearEquiv = _root_.TensorProduct.assoc R A B C := rfl
variable {A B C}
@[simp]
theorem assoc_tmul (a : A) (b : B) (c : C) :
Algebra.TensorProduct.assoc R A B C ((a ⊗ₜ b) ⊗ₜ c) = a ⊗ₜ (b ⊗ₜ c) :=
rfl
@[simp]
theorem assoc_symm_tmul (a : A) (b : B) (c : C) :
(Algebra.TensorProduct.assoc R A B C).symm (a ⊗ₜ (b ⊗ₜ c)) = (a ⊗ₜ b) ⊗ₜ c :=
rfl
end
variable {R S A}
/-- The tensor product of a pair of algebra morphisms. -/
def map (f : A →ₐ[S] B) (g : C →ₐ[R] D) : A ⊗[R] C →ₐ[S] B ⊗[R] D :=
algHomOfLinearMapTensorProduct (AlgebraTensorModule.map f.toLinearMap g.toLinearMap) (by simp)
(by simp [one_def])
@[simp]
theorem map_tmul (f : A →ₐ[S] B) (g : C →ₐ[R] D) (a : A) (c : C) : map f g (a ⊗ₜ c) = f a ⊗ₜ g c :=
rfl
@[simp]
theorem map_id : map (.id S A) (.id R C) = .id S _ :=
ext (AlgHom.ext fun _ => rfl) (AlgHom.ext fun _ => rfl)
theorem map_comp [Algebra S C] [IsScalarTower R S C]
(f₂ : B →ₐ[S] C) (f₁ : A →ₐ[S] B) (g₂ : E →ₐ[R] F) (g₁ : D →ₐ[R] E) :
map (f₂.comp f₁) (g₂.comp g₁) = (map f₂ g₂).comp (map f₁ g₁) :=
ext (AlgHom.ext fun _ => rfl) (AlgHom.ext fun _ => rfl)
@[simp]
theorem map_comp_includeLeft (f : A →ₐ[S] B) (g : C →ₐ[R] D) :
(map f g).comp includeLeft = includeLeft.comp f :=
AlgHom.ext <| by simp
@[simp]
theorem map_restrictScalars_comp_includeRight (f : A →ₐ[S] B) (g : C →ₐ[R] D) :
((map f g).restrictScalars R).comp includeRight = includeRight.comp g :=
AlgHom.ext <| by simp
@[simp]
theorem map_comp_includeRight (f : A →ₐ[R] B) (g : C →ₐ[R] D) :
(map f g).comp includeRight = includeRight.comp g :=
map_restrictScalars_comp_includeRight f g
theorem map_range (f : A →ₐ[R] B) (g : C →ₐ[R] D) :
(map f g).range = (includeLeft.comp f).range ⊔ (includeRight.comp g).range := by
apply le_antisymm
· rw [← map_top, ← adjoin_tmul_eq_top, ← adjoin_image, adjoin_le_iff]
rintro _ ⟨_, ⟨a, b, rfl⟩, rfl⟩
rw [map_tmul, ← _root_.mul_one (f a), ← _root_.one_mul (g b), ← tmul_mul_tmul]
exact mul_mem_sup (AlgHom.mem_range_self _ a) (AlgHom.mem_range_self _ b)
· rw [← map_comp_includeLeft f g, ← map_comp_includeRight f g]
exact sup_le (AlgHom.range_comp_le_range _ _) (AlgHom.range_comp_le_range _ _)
/-- Construct an isomorphism between tensor products of an S-algebra with an R-algebra
from S- and R- isomorphisms between the tensor factors.
-/
def congr (f : A ≃ₐ[S] B) (g : C ≃ₐ[R] D) : A ⊗[R] C ≃ₐ[S] B ⊗[R] D :=
AlgEquiv.ofAlgHom (map f g) (map f.symm g.symm)
(ext' fun b d => by simp) (ext' fun a c => by simp)
@[simp] theorem congr_toLinearEquiv (f : A ≃ₐ[S] B) (g : C ≃ₐ[R] D) :
(Algebra.TensorProduct.congr f g).toLinearEquiv =
TensorProduct.AlgebraTensorModule.congr f.toLinearEquiv g.toLinearEquiv := rfl
@[simp]
theorem congr_apply (f : A ≃ₐ[S] B) (g : C ≃ₐ[R] D) (x) :
congr f g x = (map (f : A →ₐ[S] B) (g : C →ₐ[R] D)) x :=
rfl
@[simp]
theorem congr_symm_apply (f : A ≃ₐ[S] B) (g : C ≃ₐ[R] D) (x) :
(congr f g).symm x = (map (f.symm : B →ₐ[S] A) (g.symm : D →ₐ[R] C)) x :=
rfl
@[simp]
theorem congr_refl : congr (.refl : A ≃ₐ[S] A) (.refl : C ≃ₐ[R] C) = .refl :=
AlgEquiv.coe_algHom_injective <| map_id
theorem congr_trans [Algebra S C] [IsScalarTower R S C]
(f₁ : A ≃ₐ[S] B) (f₂ : B ≃ₐ[S] C) (g₁ : D ≃ₐ[R] E) (g₂ : E ≃ₐ[R] F) :
congr (f₁.trans f₂) (g₁.trans g₂) = (congr f₁ g₁).trans (congr f₂ g₂) :=
AlgEquiv.coe_algHom_injective <| map_comp f₂.toAlgHom f₁.toAlgHom g₂.toAlgHom g₁.toAlgHom
theorem congr_symm (f : A ≃ₐ[S] B) (g : C ≃ₐ[R] D) : congr f.symm g.symm = (congr f g).symm := rfl
end
end Monoidal
section
variable [CommSemiring R] [CommSemiring S] [Algebra R S]
variable [Semiring A] [Algebra R A] [Algebra S A] [IsScalarTower R S A]
variable [Semiring B] [Algebra R B]
variable [CommSemiring C] [Algebra R C] [Algebra S C] [IsScalarTower R S C]
/-- If `A`, `B`, `C` are `R`-algebras, `A` and `C` are also `S`-algebras (forming a tower as
`·/S/R`), then the product map of `f : A →ₐ[S] C` and `g : B →ₐ[R] C` is an `S`-algebra
homomorphism.
This is just a special case of `Algebra.TensorProduct.lift` for when `C` is commutative. -/
abbrev productLeftAlgHom (f : A →ₐ[S] C) (g : B →ₐ[R] C) : A ⊗[R] B →ₐ[S] C :=
lift f g (fun _ _ => Commute.all _ _)
end
section
variable [CommSemiring R] [Semiring A] [Semiring B] [CommSemiring S]
variable [Algebra R A] [Algebra R B] [Algebra R S]
variable (f : A →ₐ[R] S) (g : B →ₐ[R] S)
variable (R)
/-- `LinearMap.mul'` is an `AlgHom` on commutative rings. -/
def lmul' : S ⊗[R] S →ₐ[R] S :=
algHomOfLinearMapTensorProduct (LinearMap.mul' R S)
(fun a₁ a₂ b₁ b₂ => by simp only [LinearMap.mul'_apply, mul_mul_mul_comm]) <| by
simp only [LinearMap.mul'_apply, _root_.mul_one]
variable {R}
theorem lmul'_toLinearMap : (lmul' R : _ →ₐ[R] S).toLinearMap = LinearMap.mul' R S :=
rfl
@[simp]
theorem lmul'_apply_tmul (a b : S) : lmul' (S := S) R (a ⊗ₜ[R] b) = a * b :=
rfl
@[simp]
theorem lmul'_comp_includeLeft : (lmul' R : _ →ₐ[R] S).comp includeLeft = AlgHom.id R S :=
AlgHom.ext <| _root_.mul_one
@[simp]
theorem lmul'_comp_includeRight : (lmul' R : _ →ₐ[R] S).comp includeRight = AlgHom.id R S :=
AlgHom.ext <| _root_.one_mul
/-- If `S` is commutative, for a pair of morphisms `f : A →ₐ[R] S`, `g : B →ₐ[R] S`,
We obtain a map `A ⊗[R] B →ₐ[R] S` that commutes with `f`, `g` via `a ⊗ b ↦ f(a) * g(b)`.
This is a special case of `Algebra.TensorProduct.productLeftAlgHom` for when the two base rings are
the same.
-/
def productMap : A ⊗[R] B →ₐ[R] S := productLeftAlgHom f g
theorem productMap_eq_comp_map : productMap f g = (lmul' R).comp (TensorProduct.map f g) := by
ext <;> rfl
@[simp]
theorem productMap_apply_tmul (a : A) (b : B) : productMap f g (a ⊗ₜ b) = f a * g b := rfl
theorem productMap_left_apply (a : A) : productMap f g (a ⊗ₜ 1) = f a := by
simp
@[simp]
theorem productMap_left : (productMap f g).comp includeLeft = f :=
lift_comp_includeLeft _ _ (fun _ _ => Commute.all _ _)
theorem productMap_right_apply (b : B) :
productMap f g (1 ⊗ₜ b) = g b := by simp
@[simp]
theorem productMap_right : (productMap f g).comp includeRight = g :=
lift_comp_includeRight _ _ (fun _ _ => Commute.all _ _)
theorem productMap_range : (productMap f g).range = f.range ⊔ g.range := by
rw [productMap_eq_comp_map, AlgHom.range_comp, map_range, map_sup, ← AlgHom.range_comp,
← AlgHom.range_comp,
← AlgHom.comp_assoc, ← AlgHom.comp_assoc, lmul'_comp_includeLeft, lmul'_comp_includeRight,
AlgHom.id_comp, AlgHom.id_comp]
end
section Basis
universe uM uι
variable {M : Type uM} {ι : Type uι}
variable [CommSemiring R] [Semiring A] [Algebra R A]
variable [AddCommMonoid M] [Module R M] (b : Basis ι R M)
variable (A)
/-- Given an `R`-algebra `A` and an `R`-basis of `M`, this is an `R`-linear isomorphism
`A ⊗[R] M ≃ (ι →₀ A)` (which is in fact `A`-linear). -/
noncomputable def basisAux : A ⊗[R] M ≃ₗ[R] ι →₀ A :=
_root_.TensorProduct.congr (Finsupp.LinearEquiv.finsuppUnique R A PUnit.{uι+1}).symm b.repr ≪≫ₗ
(finsuppTensorFinsupp R R A R PUnit ι).trans
(Finsupp.lcongr (Equiv.uniqueProd ι PUnit) (_root_.TensorProduct.rid R A))
variable {A}
theorem basisAux_tmul (a : A) (m : M) :
basisAux A b (a ⊗ₜ m) = a • Finsupp.mapRange (algebraMap R A) (map_zero _) (b.repr m) := by
ext
simp [basisAux, ← Algebra.commutes, Algebra.smul_def]
theorem basisAux_map_smul (a : A) (x : A ⊗[R] M) : basisAux A b (a • x) = a • basisAux A b x :=
TensorProduct.induction_on x (by simp)
(fun x y => by simp only [TensorProduct.smul_tmul', basisAux_tmul, smul_assoc])
fun x y hx hy => by simp [hx, hy]
variable (A)
/-- Given a `R`-algebra `A`, this is the `A`-basis of `A ⊗[R] M` induced by a `R`-basis of `M`. -/
noncomputable def basis : Basis ι A (A ⊗[R] M) where
repr := { basisAux A b with map_smul' := basisAux_map_smul b }
variable {A}
@[simp]
theorem basis_repr_tmul (a : A) (m : M) :
(basis A b).repr (a ⊗ₜ m) = a • Finsupp.mapRange (algebraMap R A) (map_zero _) (b.repr m) :=
basisAux_tmul b a m -- Porting note: Lean 3 had _ _ _
theorem basis_repr_symm_apply (a : A) (i : ι) :
(basis A b).repr.symm (Finsupp.single i a) = a ⊗ₜ b.repr.symm (Finsupp.single i 1) := by
rw [basis, LinearEquiv.coe_symm_mk] -- Porting note: `coe_symm_mk` isn't firing in `simp`
simp [Equiv.uniqueProd_symm_apply, basisAux]
@[simp]
theorem basis_apply (i : ι) : basis A b i = 1 ⊗ₜ b i := basis_repr_symm_apply b 1 i
theorem basis_repr_symm_apply' (a : A) (i : ι) : a • basis A b i = a ⊗ₜ b i := by
simpa using basis_repr_symm_apply b a i
section baseChange
open LinearMap
variable [Fintype ι]
variable {ι' N : Type*} [Fintype ι'] [DecidableEq ι'] [AddCommMonoid N] [Module R N]
variable (A : Type*) [CommSemiring A] [Algebra R A]
lemma _root_.Basis.baseChange_linearMap (b : Basis ι R M) (b' : Basis ι' R N) (ij : ι × ι') :
baseChange A (b'.linearMap b ij) = (basis A b').linearMap (basis A b) ij := by
apply (basis A b').ext
intro k
conv_lhs => simp only [basis_apply, baseChange_tmul]
simp_rw [Basis.linearMap_apply_apply, basis_apply]
split <;> simp only [TensorProduct.tmul_zero]
variable [DecidableEq ι]
lemma _root_.Basis.baseChange_end (b : Basis ι R M) (ij : ι × ι) :
baseChange A (b.end ij) = (basis A b).end ij :=
b.baseChange_linearMap A b ij
end baseChange
end Basis
instance (R A M : Type*)
[CommSemiring R] [AddCommMonoid M] [Module R M] [Module.Free R M]
[CommSemiring A] [Algebra R A] :
Module.Free A (A ⊗[R] M) :=
Module.Free.of_basis <| Algebra.TensorProduct.basis A (Module.Free.chooseBasis R M)
end TensorProduct
end Algebra
namespace LinearMap
open Algebra.TensorProduct
variable {R M₁ M₂ ι ι₂ : Type*} (A : Type*)
[Fintype ι] [Finite ι₂] [DecidableEq ι]
[CommSemiring R] [CommSemiring A] [Algebra R A]
[AddCommMonoid M₁] [Module R M₁] [AddCommMonoid M₂] [Module R M₂]
@[simp]
lemma toMatrix_baseChange (f : M₁ →ₗ[R] M₂) (b₁ : Basis ι R M₁) (b₂ : Basis ι₂ R M₂) :
toMatrix (basis A b₁) (basis A b₂) (f.baseChange A) =
(toMatrix b₁ b₂ f).map (algebraMap R A) := by
ext; simp [toMatrix_apply]
end LinearMap
namespace LinearMap
variable (R A M N : Type*) [CommRing R] [CommRing A] [Algebra R A]
variable [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N]
open Module
open scoped TensorProduct
/-- The natural linear map $A ⊗ \text{Hom}_R(M, N) → \text{Hom}_A (M_A, N_A)$,
where $M_A$ and $N_A$ are the respective modules over $A$ obtained by extension of scalars.
See `LinearMap.tensorProductEnd` for this map specialized to endomorphisms,
and bundled as `A`-algebra homomorphism. -/
@[simps!]
noncomputable
def tensorProduct : A ⊗[R] (M →ₗ[R] N) →ₗ[A] (A ⊗[R] M) →ₗ[A] (A ⊗[R] N) :=
TensorProduct.AlgebraTensorModule.lift <|
{ toFun := fun a ↦ a • baseChangeHom R A M N
map_add' := by simp only [add_smul, forall_true_iff]
map_smul' := by simp only [smul_assoc, RingHom.id_apply, forall_true_iff] }
/-- The natural `A`-algebra homomorphism $A ⊗ (\text{End}_R M) → \text{End}_A (A ⊗ M)$,
where `M` is an `R`-module, and `A` an `R`-algebra. -/
@[simps!]
noncomputable
def tensorProductEnd : A ⊗[R] (End R M) →ₐ[A] End A (A ⊗[R] M) :=
Algebra.TensorProduct.algHomOfLinearMapTensorProduct
(LinearMap.tensorProduct R A M M)
(fun a b f g ↦ by
apply LinearMap.ext
intro x
simp only [tensorProduct, mul_comm a b, mul_eq_comp,
TensorProduct.AlgebraTensorModule.lift_apply, TensorProduct.lift.tmul, coe_restrictScalars,
coe_mk, AddHom.coe_mk, mul_smul, smul_apply, baseChangeHom_apply, baseChange_comp,
comp_apply, Algebra.mul_smul_comm, Algebra.smul_mul_assoc])
(by
apply LinearMap.ext
intro x
simp only [tensorProduct, TensorProduct.AlgebraTensorModule.lift_apply,
TensorProduct.lift.tmul, coe_restrictScalars, coe_mk, AddHom.coe_mk, one_smul,
baseChangeHom_apply, baseChange_eq_ltensor, one_apply, one_eq_id, lTensor_id,
LinearMap.id_apply])
end LinearMap
namespace Module
variable {R S A M N : Type*} [CommSemiring R] [CommSemiring S] [Semiring A]
variable [AddCommMonoid M] [AddCommMonoid N]
variable [Algebra R S] [Algebra S A] [Algebra R A]
variable [Module R M] [Module S M] [Module A M] [Module R N]
variable [IsScalarTower R A M] [IsScalarTower S A M] [IsScalarTower R S M]
/-- The algebra homomorphism from `End M ⊗ End N` to `End (M ⊗ N)` sending `f ⊗ₜ g` to
the `TensorProduct.map f g`, the tensor product of the two maps.
This is an `AlgHom` version of `TensorProduct.AlgebraTensorModule.homTensorHomMap`. Like that
definition, this is generalized across many different rings; namely a tower of algebras `A/S/R`. -/
def endTensorEndAlgHom : End A M ⊗[R] End R N →ₐ[S] End A (M ⊗[R] N) :=
Algebra.TensorProduct.algHomOfLinearMapTensorProduct
(AlgebraTensorModule.homTensorHomMap R A S M N M N)
(fun _f₁ _f₂ _g₁ _g₂ => AlgebraTensorModule.ext fun _m _n => rfl)
(AlgebraTensorModule.ext fun _m _n => rfl)
theorem endTensorEndAlgHom_apply (f : End A M) (g : End R N) :
endTensorEndAlgHom (R := R) (S := S) (A := A) (M := M) (N := N) (f ⊗ₜ[R] g)
= AlgebraTensorModule.map f g :=
rfl
end Module
theorem Subalgebra.finite_sup {K L : Type*} [CommSemiring K] [CommSemiring L] [Algebra K L]
(E1 E2 : Subalgebra K L) [Module.Finite K E1] [Module.Finite K E2] :
Module.Finite K ↥(E1 ⊔ E2) := by
rw [← E1.range_val, ← E2.range_val, ← Algebra.TensorProduct.productMap_range]
exact Module.Finite.range (Algebra.TensorProduct.productMap E1.val E2.val).toLinearMap
@[deprecated Subalgebra.finite_sup (since := "2024-04-11")]
theorem Subalgebra.finiteDimensional_sup {K L : Type*} [Field K] [CommRing L] [Algebra K L]
(E1 E2 : Subalgebra K L) [FiniteDimensional K E1] [FiniteDimensional K E2] :
FiniteDimensional K (E1 ⊔ E2 : Subalgebra K L) := Subalgebra.finite_sup E1 E2
namespace TensorProduct.Algebra
variable {R A B M : Type*}
variable [CommSemiring R] [AddCommMonoid M] [Module R M]
variable [Semiring A] [Semiring B] [Module A M] [Module B M]
variable [Algebra R A] [Algebra R B]
variable [IsScalarTower R A M] [IsScalarTower R B M]
/-- An auxiliary definition, used for constructing the `Module (A ⊗[R] B) M` in
`TensorProduct.Algebra.module` below. -/
def moduleAux : A ⊗[R] B →ₗ[R] M →ₗ[R] M :=
TensorProduct.lift
{ toFun := fun a => a • (Algebra.lsmul R R M : B →ₐ[R] Module.End R M).toLinearMap
map_add' := fun r t => by
ext
simp only [add_smul, LinearMap.add_apply]
map_smul' := fun n r => by
ext
simp only [RingHom.id_apply, LinearMap.smul_apply, smul_assoc] }
theorem moduleAux_apply (a : A) (b : B) (m : M) : moduleAux (a ⊗ₜ[R] b) m = a • b • m :=
rfl
variable [SMulCommClass A B M]
/-- If `M` is a representation of two different `R`-algebras `A` and `B` whose actions commute,
then it is a representation the `R`-algebra `A ⊗[R] B`.
An important example arises from a semiring `S`; allowing `S` to act on itself via left and right
multiplication, the roles of `R`, `A`, `B`, `M` are played by `ℕ`, `S`, `Sᵐᵒᵖ`, `S`. This example
is important because a submodule of `S` as a `Module` over `S ⊗[ℕ] Sᵐᵒᵖ` is a two-sided ideal.
NB: This is not an instance because in the case `B = A` and `M = A ⊗[R] A` we would have a diamond
of `smul` actions. Furthermore, this would not be a mere definitional diamond but a true
mathematical diamond in which `A ⊗[R] A` had two distinct scalar actions on itself: one from its
multiplication, and one from this would-be instance. Arguably we could live with this but in any
case the real fix is to address the ambiguity in notation, probably along the lines outlined here:
https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.234773.20base.20change/near/240929258
-/
protected def module : Module (A ⊗[R] B) M where
smul x m := moduleAux x m
zero_smul m := by simp only [(· • ·), map_zero, LinearMap.zero_apply]
smul_zero x := by simp only [(· • ·), map_zero]
smul_add x m₁ m₂ := by simp only [(· • ·), map_add]
add_smul x y m := by simp only [(· • ·), map_add, LinearMap.add_apply]
one_smul m := by
-- Porting note: was one `simp only`, not two
simp only [(· • ·), Algebra.TensorProduct.one_def]
simp only [moduleAux_apply, one_smul]
mul_smul x y m := by
refine TensorProduct.induction_on x ?_ ?_ ?_ <;> refine TensorProduct.induction_on y ?_ ?_ ?_
· simp only [(· • ·), mul_zero, map_zero, LinearMap.zero_apply]
· intro a b
simp only [(· • ·), zero_mul, map_zero, LinearMap.zero_apply]
· intro z w _ _
simp only [(· • ·), zero_mul, map_zero, LinearMap.zero_apply]
· intro a b
simp only [(· • ·), mul_zero, map_zero, LinearMap.zero_apply]
· intro a₁ b₁ a₂ b₂
-- Porting note: was one `simp only`, not two
simp only [(· • ·), Algebra.TensorProduct.tmul_mul_tmul]
simp only [moduleAux_apply, mul_smul, smul_comm a₁ b₂]
· intro z w hz hw a b
-- Porting note: was one `simp only`, but random stuff doesn't work
simp only [(· • ·)] at hz hw ⊢
simp only [moduleAux_apply, mul_add, LinearMap.map_add,
LinearMap.add_apply, moduleAux_apply, hz, hw, smul_add]
· intro z w _ _
simp only [(· • ·), mul_zero, map_zero, LinearMap.zero_apply]
· intro a b z w hz hw
simp only [(· • ·)] at hz hw ⊢
simp only [LinearMap.map_add, add_mul, LinearMap.add_apply, hz, hw]
· intro u v _ _ z w hz hw
simp only [(· • ·)] at hz hw ⊢
simp only [add_mul, LinearMap.map_add, LinearMap.add_apply, hz, hw, add_add_add_comm]
attribute [local instance] TensorProduct.Algebra.module
theorem smul_def (a : A) (b : B) (m : M) : a ⊗ₜ[R] b • m = a • b • m :=
rfl
end TensorProduct.Algebra
|
RingTheory\TensorProduct\MvPolynomial.lean | /-
Copyright (c) 2024 Antoine Chambert-Loir. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Antoine Chambert-Loir
-/
import Mathlib.LinearAlgebra.DirectSum.Finsupp
import Mathlib.Algebra.MvPolynomial.Basic
import Mathlib.RingTheory.TensorProduct.Basic
import Mathlib.Algebra.MvPolynomial.Equiv
/-!
# Tensor Product of (multivariate) polynomial rings
Let `Semiring R`, `Algebra R S` and `Module R N`.
* `MvPolynomial.rTensor` gives the linear equivalence
`MvPolynomial σ S ⊗[R] N ≃ₗ[R] (σ →₀ ℕ) →₀ (S ⊗[R] N)` characterized,
for `p : MvPolynomial σ S`, `n : N` and `d : σ →₀ ℕ`, by
`rTensor (p ⊗ₜ[R] n) d = (coeff d p) ⊗ₜ[R] n`
* `MvPolynomial.scalarRTensor` gives the linear equivalence
`MvPolynomial σ R ⊗[R] N ≃ₗ[R] (σ →₀ ℕ) →₀ N`
such that `MvPolynomial.scalarRTensor (p ⊗ₜ[R] n) d = coeff d p • n`
for `p : MvPolynomial σ R`, `n : N` and `d : σ →₀ ℕ`, by
* `MvPolynomial.rTensorAlgHom`, the algebra morphism from the tensor product
of a polynomial algebra by an algebra to a polynomial algebra
* `MvPolynomial.rTensorAlgEquiv`, `MvPolynomial.scalarRTensorAlgEquiv`,
the tensor product of a polynomial algebra by an algebra
is algebraically equivalent to a polynomial algebra
## TODO :
* `MvPolynomial.rTensor` could be phrased in terms of `AddMonoidAlgebra`, and
`MvPolynomial.rTensor` then has `smul` by the polynomial algebra.
* `MvPolynomial.rTensorAlgHom` and `MvPolynomial.scalarRTensorAlgEquiv`
are morphisms for the algebra structure by `MvPolynomial σ R`.
-/
universe u v w
noncomputable section
namespace MvPolynomial
open DirectSum TensorProduct
open Set LinearMap Submodule
variable {R : Type u} {M : Type v} {N : Type w}
[CommSemiring R] [AddCommMonoid M] [Module R M]
variable {σ : Type*} [DecidableEq σ]
variable {S : Type*} [CommSemiring S] [Algebra R S]
section Module
variable [AddCommMonoid N] [Module R N]
/-- The tensor product of a polynomial ring by a module is
linearly equivalent to a Finsupp of a tensor product -/
noncomputable def rTensor :
MvPolynomial σ S ⊗[R] N ≃ₗ[S] (σ →₀ ℕ) →₀ (S ⊗[R] N) :=
TensorProduct.finsuppLeft' _ _ _ _ _
lemma rTensor_apply_tmul (p : MvPolynomial σ S) (n : N) :
rTensor (p ⊗ₜ[R] n) = p.sum (fun i m ↦ Finsupp.single i (m ⊗ₜ[R] n)) :=
TensorProduct.finsuppLeft_apply_tmul p n
lemma rTensor_apply_tmul_apply (p : MvPolynomial σ S) (n : N) (d : σ →₀ ℕ) :
rTensor (p ⊗ₜ[R] n) d = (coeff d p) ⊗ₜ[R] n :=
TensorProduct.finsuppLeft_apply_tmul_apply p n d
lemma rTensor_apply_monomial_tmul (e : σ →₀ ℕ) (s : S) (n : N) (d : σ →₀ ℕ) :
rTensor (monomial e s ⊗ₜ[R] n) d = if e = d then s ⊗ₜ[R] n else 0 := by
simp only [rTensor_apply_tmul_apply, coeff_monomial, ite_tmul]
lemma rTensor_apply_X_tmul (s : σ) (n : N) (d : σ →₀ ℕ) :
rTensor (X s ⊗ₜ[R] n) d = if Finsupp.single s 1 = d then (1 : S) ⊗ₜ[R] n else 0 := by
rw [rTensor_apply_tmul_apply, coeff_X', ite_tmul]
lemma rTensor_apply (t : MvPolynomial σ S ⊗[R] N) (d : σ →₀ ℕ) :
rTensor t d = ((lcoeff S d).restrictScalars R).rTensor N t :=
TensorProduct.finsuppLeft_apply t d
@[simp]
lemma rTensor_symm_apply_single (d : σ →₀ ℕ) (s : S) (n : N) :
rTensor.symm (Finsupp.single d (s ⊗ₜ n)) =
(monomial d s) ⊗ₜ[R] n :=
TensorProduct.finsuppLeft_symm_apply_single (R := R) d s n
/-- The tensor product of the polynomial algebra by a module
is linearly equivalent to a Finsupp of that module -/
noncomputable def scalarRTensor :
MvPolynomial σ R ⊗[R] N ≃ₗ[R] (σ →₀ ℕ) →₀ N :=
TensorProduct.finsuppScalarLeft _ _ _
lemma scalarRTensor_apply_tmul (p : MvPolynomial σ R) (n : N) :
scalarRTensor (p ⊗ₜ[R] n) = p.sum (fun i m ↦ Finsupp.single i (m • n)) :=
TensorProduct.finsuppScalarLeft_apply_tmul p n
lemma scalarRTensor_apply_tmul_apply (p : MvPolynomial σ R) (n : N) (d : σ →₀ ℕ) :
scalarRTensor (p ⊗ₜ[R] n) d = coeff d p • n :=
TensorProduct.finsuppScalarLeft_apply_tmul_apply p n d
lemma scalarRTensor_apply_monomial_tmul (e : σ →₀ ℕ) (r : R) (n : N) (d : σ →₀ ℕ) :
scalarRTensor (monomial e r ⊗ₜ[R] n) d = if e = d then r • n else 0 := by
rw [scalarRTensor_apply_tmul_apply, coeff_monomial, ite_smul, zero_smul]
lemma scalarRTensor_apply_X_tmul_apply (s : σ) (n : N) (d : σ →₀ ℕ) :
scalarRTensor (X s ⊗ₜ[R] n) d = if Finsupp.single s 1 = d then n else 0 := by
rw [scalarRTensor_apply_tmul_apply, coeff_X', ite_smul, one_smul, zero_smul]
lemma scalarRTensor_symm_apply_single (d : σ →₀ ℕ) (n : N) :
scalarRTensor.symm (Finsupp.single d n) = (monomial d 1) ⊗ₜ[R] n :=
TensorProduct.finsuppScalarLeft_symm_apply_single d n
end Module
section Algebra
variable [CommSemiring N] [Algebra R N]
/-- The algebra morphism from a tensor product of a polynomial algebra
by an algebra to a polynomial algebra -/
noncomputable def rTensorAlgHom :
(MvPolynomial σ S) ⊗[R] N →ₐ[S] MvPolynomial σ (S ⊗[R] N) :=
Algebra.TensorProduct.lift
(mapAlgHom Algebra.TensorProduct.includeLeft)
((IsScalarTower.toAlgHom R (S ⊗[R] N) _).comp Algebra.TensorProduct.includeRight)
(fun p n => by simp [commute_iff_eq, algebraMap_eq, mul_comm])
@[simp]
lemma coeff_rTensorAlgHom_tmul
(p : MvPolynomial σ S) (n : N) (d : σ →₀ ℕ) :
coeff d (rTensorAlgHom (p ⊗ₜ[R] n)) = (coeff d p) ⊗ₜ[R] n := by
rw [rTensorAlgHom, Algebra.TensorProduct.lift_tmul]
rw [AlgHom.coe_comp, IsScalarTower.coe_toAlgHom', Function.comp_apply,
Algebra.TensorProduct.includeRight_apply]
rw [algebraMap_eq, mul_comm, coeff_C_mul]
simp [mapAlgHom, coeff_map]
lemma coeff_rTensorAlgHom_monomial_tmul
(e : σ →₀ ℕ) (s : S) (n : N) (d : σ →₀ ℕ) :
coeff d (rTensorAlgHom (monomial e s ⊗ₜ[R] n)) =
if e = d then s ⊗ₜ[R] n else 0 := by
simp [ite_tmul]
lemma rTensorAlgHom_toLinearMap :
(rTensorAlgHom :
MvPolynomial σ S ⊗[R] N →ₐ[S] MvPolynomial σ (S ⊗[R] N)).toLinearMap =
rTensor.toLinearMap := by
ext d n e
dsimp only [AlgebraTensorModule.curry_apply, TensorProduct.curry_apply,
LinearMap.coe_restrictScalars, AlgHom.toLinearMap_apply]
simp only [coe_comp, Function.comp_apply, AlgebraTensorModule.curry_apply, curry_apply,
LinearMap.coe_restrictScalars, AlgHom.toLinearMap_apply]
rw [coeff_rTensorAlgHom_tmul]
simp only [coeff]
erw [finsuppLeft_apply_tmul_apply]
lemma rTensorAlgHom_apply_eq (p : MvPolynomial σ S ⊗[R] N) :
rTensorAlgHom (S := S) p = rTensor p := by
rw [← AlgHom.toLinearMap_apply, rTensorAlgHom_toLinearMap]
rfl
/-- The tensor product of a polynomial algebra by an algebra
is algebraically equivalent to a polynomial algebra -/
noncomputable def rTensorAlgEquiv :
(MvPolynomial σ S) ⊗[R] N ≃ₐ[S] MvPolynomial σ (S ⊗[R] N) := by
apply AlgEquiv.ofLinearEquiv rTensor
· simp only [Algebra.TensorProduct.one_def]
apply symm
rw [← LinearEquiv.symm_apply_eq]
exact finsuppLeft_symm_apply_single (R := R) (0 : σ →₀ ℕ) (1 : S) (1 : N)
· intro x y
erw [← rTensorAlgHom_apply_eq (S := S)]
simp only [_root_.map_mul, rTensorAlgHom_apply_eq]
rfl
/-- The tensor product of the polynomial algebra by an algebra
is algebraically equivalent to a polynomial algebra with
coefficients in that algegra -/
noncomputable def scalarRTensorAlgEquiv :
MvPolynomial σ R ⊗[R] N ≃ₐ[R] MvPolynomial σ N :=
rTensorAlgEquiv.trans (mapAlgEquiv σ (Algebra.TensorProduct.lid R N))
variable (R)
variable (A : Type*) [CommSemiring A] [Algebra R A]
/-- Tensoring `MvPolynomial σ R` on the left by an `R`-algebra `A` is algebraically
equivalent to `M̀vPolynomial σ A`. -/
noncomputable def algebraTensorAlgEquiv :
A ⊗[R] MvPolynomial σ R ≃ₐ[A] MvPolynomial σ A := AlgEquiv.ofAlgHom
(Algebra.TensorProduct.lift
(Algebra.ofId A (MvPolynomial σ A))
(MvPolynomial.mapAlgHom <| Algebra.ofId R A) (fun _ _ ↦ Commute.all _ _))
(aeval (fun s ↦ 1 ⊗ₜ X s))
(by ext s; simp)
(by ext s; simp)
@[simp]
lemma algebraTensorAlgEquiv_tmul (a : A) (p : MvPolynomial σ R) :
algebraTensorAlgEquiv R A (a ⊗ₜ p) = a • MvPolynomial.map (algebraMap R A) p := by
simp [algebraTensorAlgEquiv, Algebra.smul_def]
rfl
@[simp]
lemma algebraTensorAlgEquiv_symm_X (s : σ) :
(algebraTensorAlgEquiv R A).symm (X s) = 1 ⊗ₜ X s := by
simp [algebraTensorAlgEquiv]
@[simp]
lemma algebraTensorAlgEquiv_symm_monomial (m : σ →₀ ℕ) (a : A) :
(algebraTensorAlgEquiv R A).symm (monomial m a) = a ⊗ₜ monomial m 1 := by
apply @Finsupp.induction σ ℕ _ _ m
· simp [algebraTensorAlgEquiv]
· intro i n f _ _ hfa
simp only [algebraTensorAlgEquiv, AlgEquiv.ofAlgHom_symm_apply] at hfa ⊢
simp only [add_comm, monomial_add_single, _root_.map_mul, map_pow, aeval_X,
Algebra.TensorProduct.tmul_pow, one_pow, hfa]
nth_rw 2 [← mul_one a]
rw [Algebra.TensorProduct.tmul_mul_tmul]
end Algebra
end MvPolynomial
end
|
RingTheory\Trace\Basic.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.RingTheory.Trace.Defs
import Mathlib.LinearAlgebra.Determinant
import Mathlib.FieldTheory.Galois
import Mathlib.LinearAlgebra.Matrix.Charpoly.Minpoly
import Mathlib.LinearAlgebra.Vandermonde
import Mathlib.FieldTheory.Minpoly.MinpolyDiv
/-!
# Trace for (finite) ring extensions.
Suppose we have an `R`-algebra `S` with a finite basis. For each `s : S`,
the trace of the linear map given by multiplying by `s` gives information about
the roots of the minimal polynomial of `s` over `R`.
## Main definitions
* `Algebra.embeddingsMatrix A C b : Matrix κ (B →ₐ[A] C) C` is the matrix whose
`(i, σ)` coefficient is `σ (b i)`.
* `Algebra.embeddingsMatrixReindex A C b e : Matrix κ κ C` is the matrix whose `(i, j)`
coefficient is `σⱼ (b i)`, where `σⱼ : B →ₐ[A] C` is the embedding corresponding to `j : κ`
given by a bijection `e : κ ≃ (B →ₐ[A] C)`.
## Main results
* `trace_eq_sum_embeddings`: the trace of `x : K(x)` is the sum of all embeddings of `x` into an
algebraically closed field
* `traceForm_nondegenerate`: the trace form over a separable extension is a nondegenerate
bilinear form
* `traceForm_dualBasis_powerBasis_eq`: The dual basis of a powerbasis `{1, x, x²...}` under the
trace form is `aᵢ / f'(x)`, with `f` being the minpoly of `x` and `f / (X - x) = ∑ aᵢxⁱ`.
## References
* https://en.wikipedia.org/wiki/Field_trace
-/
universe u v w z
variable {R S T : Type*} [CommRing R] [CommRing S] [CommRing T]
variable [Algebra R S] [Algebra R T]
variable {K L : Type*} [Field K] [Field L] [Algebra K L]
variable {ι κ : Type w} [Fintype ι]
open FiniteDimensional
open LinearMap (BilinForm)
open LinearMap
open Matrix
open scoped Matrix
theorem Algebra.traceForm_toMatrix_powerBasis (h : PowerBasis R S) :
BilinForm.toMatrix h.basis (traceForm R S) = of fun i j => trace R S (h.gen ^ (i.1 + j.1)) := by
ext; rw [traceForm_toMatrix, of_apply, pow_add, h.basis_eq_pow, h.basis_eq_pow]
section EqSumRoots
open Algebra Polynomial
variable {F : Type*} [Field F]
variable [Algebra K S] [Algebra K F]
/-- Given `pb : PowerBasis K S`, the trace of `pb.gen` is `-(minpoly K pb.gen).nextCoeff`. -/
theorem PowerBasis.trace_gen_eq_nextCoeff_minpoly [Nontrivial S] (pb : PowerBasis K S) :
Algebra.trace K S pb.gen = -(minpoly K pb.gen).nextCoeff := by
have d_pos : 0 < pb.dim := PowerBasis.dim_pos pb
have d_pos' : 0 < (minpoly K pb.gen).natDegree := by simpa
haveI : Nonempty (Fin pb.dim) := ⟨⟨0, d_pos⟩⟩
rw [trace_eq_matrix_trace pb.basis, trace_eq_neg_charpoly_coeff, charpoly_leftMulMatrix, ←
pb.natDegree_minpoly, Fintype.card_fin, ← nextCoeff_of_natDegree_pos d_pos']
/-- Given `pb : PowerBasis K S`, then the trace of `pb.gen` is
`((minpoly K pb.gen).aroots F).sum`. -/
theorem PowerBasis.trace_gen_eq_sum_roots [Nontrivial S] (pb : PowerBasis K S)
(hf : (minpoly K pb.gen).Splits (algebraMap K F)) :
algebraMap K F (trace K S pb.gen) = ((minpoly K pb.gen).aroots F).sum := by
rw [PowerBasis.trace_gen_eq_nextCoeff_minpoly, RingHom.map_neg, ←
nextCoeff_map (algebraMap K F).injective,
sum_roots_eq_nextCoeff_of_monic_of_split ((minpoly.monic (PowerBasis.isIntegral_gen _)).map _)
((splits_id_iff_splits _).2 hf),
neg_neg]
namespace IntermediateField.AdjoinSimple
open IntermediateField
theorem trace_gen_eq_zero {x : L} (hx : ¬IsIntegral K x) :
Algebra.trace K K⟮x⟯ (AdjoinSimple.gen K x) = 0 := by
rw [trace_eq_zero_of_not_exists_basis, LinearMap.zero_apply]
contrapose! hx
obtain ⟨s, ⟨b⟩⟩ := hx
refine .of_mem_of_fg K⟮x⟯.toSubalgebra ?_ x ?_
· exact (Submodule.fg_iff_finiteDimensional _).mpr (FiniteDimensional.of_fintype_basis b)
· exact subset_adjoin K _ (Set.mem_singleton x)
theorem trace_gen_eq_sum_roots (x : L) (hf : (minpoly K x).Splits (algebraMap K F)) :
algebraMap K F (trace K K⟮x⟯ (AdjoinSimple.gen K x)) =
((minpoly K x).aroots F).sum := by
have injKxL := (algebraMap K⟮x⟯ L).injective
by_cases hx : IsIntegral K x; swap
· simp [minpoly.eq_zero hx, trace_gen_eq_zero hx, aroots_def]
rw [← adjoin.powerBasis_gen hx, (adjoin.powerBasis hx).trace_gen_eq_sum_roots] <;>
rw [adjoin.powerBasis_gen hx, ← minpoly.algebraMap_eq injKxL] <;>
try simp only [AdjoinSimple.algebraMap_gen _ _]
exact hf
end IntermediateField.AdjoinSimple
open IntermediateField
variable (K)
theorem trace_eq_trace_adjoin [FiniteDimensional K L] (x : L) :
Algebra.trace K L x = finrank K⟮x⟯ L • trace K K⟮x⟯ (AdjoinSimple.gen K x) := by
-- Porting note: `conv` was
-- `conv in x => rw [← IntermediateField.AdjoinSimple.algebraMap_gen K x]`
-- and it was after the first `rw`.
conv =>
lhs
rw [← IntermediateField.AdjoinSimple.algebraMap_gen K x]
rw [← trace_trace (S := K⟮x⟯), trace_algebraMap, LinearMap.map_smul_of_tower]
variable {K}
theorem trace_eq_sum_roots [FiniteDimensional K L] {x : L}
(hF : (minpoly K x).Splits (algebraMap K F)) :
algebraMap K F (Algebra.trace K L x) =
finrank K⟮x⟯ L • ((minpoly K x).aroots F).sum := by
rw [trace_eq_trace_adjoin K x, Algebra.smul_def, RingHom.map_mul, ← Algebra.smul_def,
IntermediateField.AdjoinSimple.trace_gen_eq_sum_roots _ hF, IsScalarTower.algebraMap_smul]
end EqSumRoots
variable {F : Type*} [Field F]
variable [Algebra R L] [Algebra L F] [Algebra R F] [IsScalarTower R L F]
open Polynomial
attribute [-instance] Field.toEuclideanDomain
theorem Algebra.isIntegral_trace [FiniteDimensional L F] {x : F} (hx : IsIntegral R x) :
IsIntegral R (Algebra.trace L F x) := by
have hx' : IsIntegral L x := hx.tower_top
rw [← isIntegral_algebraMap_iff (algebraMap L (AlgebraicClosure F)).injective, trace_eq_sum_roots]
· refine (IsIntegral.multiset_sum ?_).nsmul _
intro y hy
rw [mem_roots_map (minpoly.ne_zero hx')] at hy
use minpoly R x, minpoly.monic hx
rw [← aeval_def] at hy ⊢
exact minpoly.aeval_of_isScalarTower R x y hy
· apply IsAlgClosed.splits_codomain
lemma Algebra.trace_eq_of_algEquiv {A B C : Type*} [CommRing A] [CommRing B] [CommRing C]
[Algebra A B] [Algebra A C] (e : B ≃ₐ[A] C) (x) :
Algebra.trace A C (e x) = Algebra.trace A B x := by
simp_rw [Algebra.trace_apply, ← LinearMap.trace_conj' _ e.toLinearEquiv]
congr; ext; simp [LinearEquiv.conj_apply]
lemma Algebra.trace_eq_of_ringEquiv {A B C : Type*} [CommRing A] [CommRing B] [CommRing C]
[Algebra A C] [Algebra B C] (e : A ≃+* B) (he : (algebraMap B C).comp e = algebraMap A C) (x) :
e (Algebra.trace A C x) = Algebra.trace B C x := by
classical
by_cases h : ∃ s : Finset C, Nonempty (Basis s B C)
· obtain ⟨s, ⟨b⟩⟩ := h
letI : Algebra A B := RingHom.toAlgebra e
letI : IsScalarTower A B C := IsScalarTower.of_algebraMap_eq' he.symm
rw [Algebra.trace_eq_matrix_trace b,
Algebra.trace_eq_matrix_trace (b.mapCoeffs e.symm (by simp [Algebra.smul_def, ← he]))]
show e.toAddMonoidHom _ = _
rw [AddMonoidHom.map_trace]
congr
ext i j
simp [leftMulMatrix_apply, LinearMap.toMatrix_apply]
rw [trace_eq_zero_of_not_exists_basis _ h, trace_eq_zero_of_not_exists_basis,
LinearMap.zero_apply, LinearMap.zero_apply, map_zero]
intro ⟨s, ⟨b⟩⟩
exact h ⟨s, ⟨b.mapCoeffs e (by simp [Algebra.smul_def, ← he])⟩⟩
lemma Algebra.trace_eq_of_equiv_equiv {A₁ B₁ A₂ B₂ : Type*} [CommRing A₁] [CommRing B₁]
[CommRing A₂] [CommRing 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₁)) (x) :
Algebra.trace A₁ B₁ x = e₁.symm (Algebra.trace A₂ B₂ (e₂ x)) := by
letI := (RingHom.comp (e₂ : B₁ →+* B₂) (algebraMap A₁ B₁)).toAlgebra
let e' : B₁ ≃ₐ[A₁] B₂ := { e₂ with commutes' := fun _ ↦ rfl }
rw [← Algebra.trace_eq_of_ringEquiv e₁ he, ← Algebra.trace_eq_of_algEquiv e',
RingEquiv.symm_apply_apply]
rfl
section EqSumEmbeddings
variable [Algebra K F] [IsScalarTower K L F]
open Algebra IntermediateField
variable (F) (E : Type*) [Field E] [Algebra K E]
theorem trace_eq_sum_embeddings_gen (pb : PowerBasis K L)
(hE : (minpoly K pb.gen).Splits (algebraMap K E)) (hfx : IsSeparable K pb.gen) :
algebraMap K E (Algebra.trace K L pb.gen) =
(@Finset.univ _ (PowerBasis.AlgHom.fintype pb)).sum fun σ => σ pb.gen := by
letI := Classical.decEq E
-- Porting note: the following `letI` was not needed.
letI : Fintype (L →ₐ[K] E) := PowerBasis.AlgHom.fintype pb
rw [pb.trace_gen_eq_sum_roots hE, Fintype.sum_equiv pb.liftEquiv', Finset.sum_mem_multiset,
Finset.sum_eq_multiset_sum, Multiset.toFinset_val, Multiset.dedup_eq_self.mpr _,
Multiset.map_id]
· exact nodup_roots ((separable_map _).mpr hfx)
-- Porting note: the following goal does not exist in mathlib3.
· exact (fun x => x.1)
· intro x; rfl
· intro σ
rw [PowerBasis.liftEquiv'_apply_coe]
variable [IsAlgClosed E]
theorem sum_embeddings_eq_finrank_mul [FiniteDimensional K F] [Algebra.IsSeparable K F]
(pb : PowerBasis K L) :
∑ σ : F →ₐ[K] E, σ (algebraMap L F pb.gen) =
finrank L F •
(@Finset.univ _ (PowerBasis.AlgHom.fintype pb)).sum fun σ : L →ₐ[K] E => σ pb.gen := by
haveI : FiniteDimensional L F := FiniteDimensional.right K L F
haveI : Algebra.IsSeparable L F := Algebra.isSeparable_tower_top_of_isSeparable K L F
letI : Fintype (L →ₐ[K] E) := PowerBasis.AlgHom.fintype pb
letI : ∀ f : L →ₐ[K] E, Fintype (haveI := f.toRingHom.toAlgebra; AlgHom L F E) := ?_
· rw [Fintype.sum_equiv algHomEquivSigma (fun σ : F →ₐ[K] E => _) fun σ => σ.1 pb.gen, ←
Finset.univ_sigma_univ, Finset.sum_sigma, ← Finset.sum_nsmul]
· refine Finset.sum_congr rfl fun σ _ => ?_
letI : Algebra L E := σ.toRingHom.toAlgebra
-- Porting note: `Finset.card_univ` was inside `simp only`.
simp only [Finset.sum_const]
congr
rw [← AlgHom.card L F E]
exact Finset.card_univ (α := F →ₐ[L] E)
· intro σ
simp only [algHomEquivSigma, Equiv.coe_fn_mk, AlgHom.restrictDomain, AlgHom.comp_apply,
IsScalarTower.coe_toAlgHom']
theorem trace_eq_sum_embeddings [FiniteDimensional K L] [Algebra.IsSeparable K L] {x : L} :
algebraMap K E (Algebra.trace K L x) = ∑ σ : L →ₐ[K] E, σ x := by
have hx := Algebra.IsSeparable.isIntegral K x
let pb := adjoin.powerBasis hx
rw [trace_eq_trace_adjoin K x, Algebra.smul_def, RingHom.map_mul, ← adjoin.powerBasis_gen hx,
trace_eq_sum_embeddings_gen E pb (IsAlgClosed.splits_codomain _)]
-- Porting note: the following `convert` was `exact`, with `← Algebra.smul_def, algebraMap_smul`
-- in the previous `rw`.
· convert (sum_embeddings_eq_finrank_mul L E pb).symm
ext
simp
· haveI := Algebra.isSeparable_tower_bot_of_isSeparable K K⟮x⟯ L
exact Algebra.IsSeparable.isSeparable K _
theorem trace_eq_sum_automorphisms (x : L) [FiniteDimensional K L] [IsGalois K L] :
algebraMap K L (Algebra.trace K L x) = ∑ σ : L ≃ₐ[K] L, σ x := by
apply NoZeroSMulDivisors.algebraMap_injective L (AlgebraicClosure L)
rw [_root_.map_sum (algebraMap L (AlgebraicClosure L))]
rw [← Fintype.sum_equiv (Normal.algHomEquivAut K (AlgebraicClosure L) L)]
· rw [← trace_eq_sum_embeddings (AlgebraicClosure L)]
· simp only [algebraMap_eq_smul_one]
-- Porting note: `smul_one_smul` was in the `simp only`.
apply smul_one_smul
· intro σ
simp only [Normal.algHomEquivAut, AlgHom.restrictNormal', Equiv.coe_fn_mk,
AlgEquiv.coe_ofBijective, AlgHom.restrictNormal_commutes, id.map_eq_id, RingHom.id_apply]
end EqSumEmbeddings
section DetNeZero
namespace Algebra
variable (A : Type u) {B : Type v} (C : Type z)
variable [CommRing A] [CommRing B] [Algebra A B] [CommRing C] [Algebra A C]
open Finset
/-- Given an `A`-algebra `B` and `b`, a `κ`-indexed family of elements of `B`, we define
`traceMatrix A b` as the matrix whose `(i j)`-th element is the trace of `b i * b j`. -/
noncomputable def traceMatrix (b : κ → B) : Matrix κ κ A :=
of fun i j => traceForm A B (b i) (b j)
-- TODO: set as an equation lemma for `traceMatrix`, see mathlib4#3024
@[simp]
theorem traceMatrix_apply (b : κ → B) (i j) : traceMatrix A b i j = traceForm A B (b i) (b j) :=
rfl
theorem traceMatrix_reindex {κ' : Type*} (b : Basis κ A B) (f : κ ≃ κ') :
traceMatrix A (b.reindex f) = reindex f f (traceMatrix A b) := by ext (x y); simp
variable {A}
theorem traceMatrix_of_matrix_vecMul [Fintype κ] (b : κ → B) (P : Matrix κ κ A) :
traceMatrix A (b ᵥ* P.map (algebraMap A B)) = Pᵀ * traceMatrix A b * P := by
ext (α β)
rw [traceMatrix_apply, vecMul, dotProduct, vecMul, dotProduct, Matrix.mul_apply,
BilinForm.sum_left,
Fintype.sum_congr _ _ fun i : κ =>
BilinForm.sum_right _ _ (b i * P.map (algebraMap A B) i α) fun y : κ =>
b y * P.map (algebraMap A B) y β,
sum_comm]
congr; ext x
rw [Matrix.mul_apply, sum_mul]
congr; ext y
rw [map_apply, traceForm_apply, mul_comm (b y), ← smul_def]
simp only [id.smul_eq_mul, RingHom.id_apply, map_apply, transpose_apply, LinearMap.map_smulₛₗ,
traceForm_apply, Algebra.smul_mul_assoc]
rw [mul_comm (b x), ← smul_def]
ring_nf
rw [mul_assoc]
simp [mul_comm]
theorem traceMatrix_of_matrix_mulVec [Fintype κ] (b : κ → B) (P : Matrix κ κ A) :
traceMatrix A (P.map (algebraMap A B) *ᵥ b) = P * traceMatrix A b * Pᵀ := by
refine AddEquiv.injective (transposeAddEquiv κ κ A) ?_
rw [transposeAddEquiv_apply, transposeAddEquiv_apply, ← vecMul_transpose, ← transpose_map,
traceMatrix_of_matrix_vecMul, transpose_transpose]
theorem traceMatrix_of_basis [Fintype κ] [DecidableEq κ] (b : Basis κ A B) :
traceMatrix A b = BilinForm.toMatrix b (traceForm A B) := by
ext (i j)
rw [traceMatrix_apply, traceForm_apply, traceForm_toMatrix]
theorem traceMatrix_of_basis_mulVec (b : Basis ι A B) (z : B) :
traceMatrix A b *ᵥ b.equivFun z = fun i => trace A B (z * b i) := by
ext i
rw [← col_apply (ι := Fin 1) (traceMatrix A b *ᵥ b.equivFun z) i 0, col_mulVec,
Matrix.mul_apply, traceMatrix]
simp only [col_apply, traceForm_apply]
conv_lhs =>
congr
rfl
ext
rw [mul_comm _ (b.equivFun z _), ← smul_eq_mul, of_apply, ← LinearMap.map_smul]
rw [← _root_.map_sum]
congr
conv_lhs =>
congr
rfl
ext
rw [← mul_smul_comm]
rw [← Finset.mul_sum, mul_comm z]
congr
rw [b.sum_equivFun]
variable (A)
/-- `embeddingsMatrix A C b : Matrix κ (B →ₐ[A] C) C` is the matrix whose `(i, σ)` coefficient is
`σ (b i)`. It is mostly useful for fields when `Fintype.card κ = finrank A B` and `C` is
algebraically closed. -/
def embeddingsMatrix (b : κ → B) : Matrix κ (B →ₐ[A] C) C :=
of fun i (σ : B →ₐ[A] C) => σ (b i)
-- TODO: set as an equation lemma for `embeddingsMatrix`, see mathlib4#3024
@[simp]
theorem embeddingsMatrix_apply (b : κ → B) (i) (σ : B →ₐ[A] C) :
embeddingsMatrix A C b i σ = σ (b i) :=
rfl
/-- `embeddingsMatrixReindex A C b e : Matrix κ κ C` is the matrix whose `(i, j)` coefficient
is `σⱼ (b i)`, where `σⱼ : B →ₐ[A] C` is the embedding corresponding to `j : κ` given by a
bijection `e : κ ≃ (B →ₐ[A] C)`. It is mostly useful for fields and `C` is algebraically closed.
In this case, in presence of `h : Fintype.card κ = finrank A B`, one can take
`e := equivOfCardEq ((AlgHom.card A B C).trans h.symm)`. -/
def embeddingsMatrixReindex (b : κ → B) (e : κ ≃ (B →ₐ[A] C)) :=
reindex (Equiv.refl κ) e.symm (embeddingsMatrix A C b)
variable {A}
theorem embeddingsMatrixReindex_eq_vandermonde (pb : PowerBasis A B)
(e : Fin pb.dim ≃ (B →ₐ[A] C)) :
embeddingsMatrixReindex A C pb.basis e = (vandermonde fun i => e i pb.gen)ᵀ := by
ext i j
simp [embeddingsMatrixReindex, embeddingsMatrix]
section Field
variable (K) (E : Type z) [Field E]
variable [Algebra K E]
variable [Module.Finite K L] [Algebra.IsSeparable K L] [IsAlgClosed E]
variable (b : κ → L) (pb : PowerBasis K L)
theorem traceMatrix_eq_embeddingsMatrix_mul_trans : (traceMatrix K b).map (algebraMap K E) =
embeddingsMatrix K E b * (embeddingsMatrix K E b)ᵀ := by
ext (i j); simp [trace_eq_sum_embeddings, embeddingsMatrix, Matrix.mul_apply]
theorem traceMatrix_eq_embeddingsMatrixReindex_mul_trans [Fintype κ] (e : κ ≃ (L →ₐ[K] E)) :
(traceMatrix K b).map (algebraMap K E) =
embeddingsMatrixReindex K E b e * (embeddingsMatrixReindex K E b e)ᵀ := by
rw [traceMatrix_eq_embeddingsMatrix_mul_trans, embeddingsMatrixReindex, reindex_apply,
transpose_submatrix, ← submatrix_mul_transpose_submatrix, ← Equiv.coe_refl, Equiv.refl_symm]
end Field
end Algebra
open Algebra
variable (pb : PowerBasis K L)
theorem det_traceMatrix_ne_zero' [Algebra.IsSeparable K L] : det (traceMatrix K pb.basis) ≠ 0 := by
suffices algebraMap K (AlgebraicClosure L) (det (traceMatrix K pb.basis)) ≠ 0 by
refine mt (fun ht => ?_) this
rw [ht, RingHom.map_zero]
haveI : FiniteDimensional K L := pb.finite
let e : Fin pb.dim ≃ (L →ₐ[K] AlgebraicClosure L) := (Fintype.equivFinOfCardEq ?_).symm
· rw [RingHom.map_det, RingHom.mapMatrix_apply,
traceMatrix_eq_embeddingsMatrixReindex_mul_trans K _ _ e,
embeddingsMatrixReindex_eq_vandermonde, det_mul, det_transpose]
refine mt mul_self_eq_zero.mp ?_
simp only [det_vandermonde, Finset.prod_eq_zero_iff, not_exists, sub_eq_zero]
rintro i ⟨_, j, hij, h⟩
exact (Finset.mem_Ioi.mp hij).ne' (e.injective <| pb.algHom_ext h)
· rw [AlgHom.card, pb.finrank]
theorem det_traceForm_ne_zero [Algebra.IsSeparable K L] [DecidableEq ι] (b : Basis ι K L) :
det (BilinForm.toMatrix b (traceForm K L)) ≠ 0 := by
haveI : FiniteDimensional K L := FiniteDimensional.of_fintype_basis b
let pb : PowerBasis K L := Field.powerBasisOfFiniteOfSeparable _ _
rw [← BilinForm.toMatrix_mul_basis_toMatrix pb.basis b, ←
det_comm' (pb.basis.toMatrix_mul_toMatrix_flip b) _, ← Matrix.mul_assoc, det_mul]
swap; · apply Basis.toMatrix_mul_toMatrix_flip
refine
mul_ne_zero
(isUnit_of_mul_eq_one _ ((b.toMatrix pb.basis)ᵀ * b.toMatrix pb.basis).det ?_).ne_zero ?_
· calc
(pb.basis.toMatrix b * (pb.basis.toMatrix b)ᵀ).det *
((b.toMatrix pb.basis)ᵀ * b.toMatrix pb.basis).det =
(pb.basis.toMatrix b * (b.toMatrix pb.basis * pb.basis.toMatrix b)ᵀ *
b.toMatrix pb.basis).det := by
simp only [← det_mul, Matrix.mul_assoc, Matrix.transpose_mul]
_ = 1 := by
simp only [Basis.toMatrix_mul_toMatrix_flip, Matrix.transpose_one, Matrix.mul_one,
Matrix.det_one]
simpa only [traceMatrix_of_basis] using det_traceMatrix_ne_zero' pb
variable (K L)
theorem traceForm_nondegenerate [FiniteDimensional K L] [Algebra.IsSeparable K L] :
(traceForm K L).Nondegenerate :=
BilinForm.nondegenerate_of_det_ne_zero (traceForm K L) _
(det_traceForm_ne_zero (FiniteDimensional.finBasis K L))
theorem Algebra.trace_ne_zero [FiniteDimensional K L] [Algebra.IsSeparable K L] :
Algebra.trace K L ≠ 0 := by
intro e
let pb : PowerBasis K L := Field.powerBasisOfFiniteOfSeparable _ _
apply det_traceMatrix_ne_zero' pb
rw [show traceMatrix K pb.basis = 0 by ext; simp [e], Matrix.det_zero]
rw [← pb.finrank, ← Fin.pos_iff_nonempty]
exact finrank_pos
theorem Algebra.trace_surjective [FiniteDimensional K L] [Algebra.IsSeparable K L] :
Function.Surjective (Algebra.trace K L) := by
rw [← LinearMap.range_eq_top]
apply (IsSimpleOrder.eq_bot_or_eq_top (α := Ideal K) _).resolve_left
rw [LinearMap.range_eq_bot]
exact Algebra.trace_ne_zero K L
variable {K L}
/--
The dual basis of a powerbasis `{1, x, x²...}` under the trace form is `aᵢ / f'(x)`,
with `f` being the minimal polynomial of `x` and `f / (X - x) = ∑ aᵢxⁱ`.
-/
lemma traceForm_dualBasis_powerBasis_eq [FiniteDimensional K L] [Algebra.IsSeparable K L]
(pb : PowerBasis K L) (i) :
(Algebra.traceForm K L).dualBasis (traceForm_nondegenerate K L) pb.basis i =
(minpolyDiv K pb.gen).coeff i / aeval pb.gen (derivative <| minpoly K pb.gen) := by
classical
apply ((Algebra.traceForm K L).toDual (traceForm_nondegenerate K L)).injective
apply pb.basis.ext
intro j
simp only [BilinForm.toDual_def, BilinForm.apply_dualBasis_left]
apply (algebraMap K (AlgebraicClosure K)).injective
have := congr_arg (coeff · i) (sum_smul_minpolyDiv_eq_X_pow (AlgebraicClosure K)
pb.adjoin_gen_eq_top (r := j) (pb.finrank.symm ▸ j.prop))
simp only [AlgEquiv.toAlgHom_eq_coe, Polynomial.map_smul, map_div₀,
map_pow, RingHom.coe_coe, AlgHom.coe_coe, finset_sum_coeff, coeff_smul, coeff_map, smul_eq_mul,
coeff_X_pow, ← Fin.ext_iff, @eq_comm _ i] at this
rw [PowerBasis.coe_basis]
simp only [RingHom.map_ite_one_zero, traceForm_apply]
rw [← this, trace_eq_sum_embeddings (E := AlgebraicClosure K)]
apply Finset.sum_congr rfl
intro σ _
simp only [_root_.map_mul, map_div₀, map_pow]
ring
end DetNeZero
|
RingTheory\Trace\Defs.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.LinearAlgebra.Matrix.BilinearForm
import Mathlib.LinearAlgebra.FiniteDimensional
import Mathlib.LinearAlgebra.Trace
/-!
# Trace for (finite) ring extensions.
Suppose we have an `R`-algebra `S` with a finite basis. For each `s : S`,
the trace of the linear map given by multiplying by `s` gives information about
the roots of the minimal polynomial of `s` over `R`.
## Main definitions
* `Algebra.trace R S x`: the trace of an element `s` of an `R`-algebra `S`
* `Algebra.traceForm R S`: bilinear form sending `x`, `y` to the trace of `x * y`
* `Algebra.traceMatrix R b`: the matrix whose `(i j)`-th element is the trace of `b i * b j`.
## Main results
* `trace_algebraMap_of_basis`, `trace_algebraMap`: if `x : K`, then `Tr_{L/K} x = [L : K] x`
* `trace_trace_of_basis`, `trace_trace`: `Tr_{L/K} (Tr_{F/L} x) = Tr_{F/K} x`
## Implementation notes
Typically, the trace is defined specifically for finite field extensions.
The definition is as general as possible and the assumption that the extension is finite
is added to the lemmas as needed.
We only define the trace for left multiplication (`Algebra.leftMulMatrix`,
i.e. `LinearMap.mulLeft`).
For now, the definitions assume `S` is commutative, so the choice doesn't matter anyway.
## References
* https://en.wikipedia.org/wiki/Field_trace
-/
universe u v w z
variable {R S T : Type*} [CommRing R] [CommRing S] [CommRing T]
variable [Algebra R S] [Algebra R T]
variable {ι κ : Type w} [Fintype ι]
open FiniteDimensional
open LinearMap (BilinForm)
open LinearMap
open Matrix
open scoped Matrix
namespace Algebra
variable (b : Basis ι R S)
variable (R S)
/-- The trace of an element `s` of an `R`-algebra is the trace of `(s * ·)`,
as an `R`-linear map. -/
noncomputable def trace : S →ₗ[R] R :=
(LinearMap.trace R S).comp (lmul R S).toLinearMap
variable {S}
-- Not a `simp` lemma since there are more interesting ways to rewrite `trace R S x`,
-- for example `trace_trace`
theorem trace_apply (x) : trace R S x = LinearMap.trace R S (lmul R S x) :=
rfl
theorem trace_eq_zero_of_not_exists_basis (h : ¬∃ s : Finset S, Nonempty (Basis s R S)) :
trace R S = 0 := by ext s; simp [trace_apply, LinearMap.trace, h]
variable {R}
-- Can't be a `simp` lemma because it depends on a choice of basis
theorem trace_eq_matrix_trace [DecidableEq ι] (b : Basis ι R S) (s : S) :
trace R S s = Matrix.trace (Algebra.leftMulMatrix b s) := by
rw [trace_apply, LinearMap.trace_eq_matrix_trace _ b, ← toMatrix_lmul_eq]; rfl
/-- If `x` is in the base field `K`, then the trace is `[L : K] * x`. -/
theorem trace_algebraMap_of_basis (x : R) : trace R S (algebraMap R S x) = Fintype.card ι • x := by
haveI := Classical.decEq ι
rw [trace_apply, LinearMap.trace_eq_matrix_trace R b, Matrix.trace]
convert Finset.sum_const x
simp [-coe_lmul_eq_mul]
/-- If `x` is in the base field `K`, then the trace is `[L : K] * x`.
(If `L` is not finite-dimensional over `K`, then `trace` and `finrank` return `0`.)
-/
@[simp]
theorem trace_algebraMap [StrongRankCondition R] [Module.Free R S] (x : R) :
trace R S (algebraMap R S x) = finrank R S • x := by
by_cases H : ∃ s : Finset S, Nonempty (Basis s R S)
· rw [trace_algebraMap_of_basis H.choose_spec.some, finrank_eq_card_basis H.choose_spec.some]
· simp [trace_eq_zero_of_not_exists_basis R H, finrank_eq_zero_of_not_exists_basis_finset H]
theorem trace_trace_of_basis [Algebra S T] [IsScalarTower R S T] {ι κ : Type*} [Finite ι]
[Finite κ] (b : Basis ι R S) (c : Basis κ S T) (x : T) :
trace R S (trace S T x) = trace R T x := by
haveI := Classical.decEq ι
haveI := Classical.decEq κ
cases nonempty_fintype ι
cases nonempty_fintype κ
rw [trace_eq_matrix_trace (b.smulTower c), trace_eq_matrix_trace b, trace_eq_matrix_trace c,
Matrix.trace, Matrix.trace, Matrix.trace, ← Finset.univ_product_univ, Finset.sum_product]
refine Finset.sum_congr rfl fun i _ ↦ ?_
simp only [map_sum, smulTower_leftMulMatrix, Finset.sum_apply, Matrix.diag,
Finset.sum_apply i (Finset.univ : Finset κ) fun y => leftMulMatrix b (leftMulMatrix c x y y)]
theorem trace_comp_trace_of_basis [Algebra S T] [IsScalarTower R S T] {ι κ : Type*} [Finite ι]
[Finite κ] (b : Basis ι R S) (c : Basis κ S T) :
(trace R S).comp ((trace S T).restrictScalars R) = trace R T := by
ext
rw [LinearMap.comp_apply, LinearMap.restrictScalars_apply, trace_trace_of_basis b c]
@[simp]
theorem trace_trace [Algebra S T] [IsScalarTower R S T]
[Module.Free R S] [Module.Finite R S] [Module.Free S T] [Module.Finite S T] (x : T) :
trace R S (trace S T x) = trace R T x :=
trace_trace_of_basis (Module.Free.chooseBasis R S) (Module.Free.chooseBasis S T) x
@[simp]
theorem trace_comp_trace [Algebra S T] [IsScalarTower R S T]
[Module.Free R S] [Module.Finite R S] [Module.Free S T] [Module.Finite S T] :
(trace R S).comp ((trace S T).restrictScalars R) = trace R T :=
LinearMap.ext trace_trace
@[simp]
theorem trace_prod_apply [Module.Free R S] [Module.Free R T] [Module.Finite R S] [Module.Finite R T]
(x : S × T) : trace R (S × T) x = trace R S x.fst + trace R T x.snd := by
nontriviality R
let f := (lmul R S).toLinearMap.prodMap (lmul R T).toLinearMap
have : (lmul R (S × T)).toLinearMap = (prodMapLinear R S T S T R).comp f :=
LinearMap.ext₂ Prod.mul_def
simp_rw [trace, this]
exact trace_prodMap' _ _
theorem trace_prod [Module.Free R S] [Module.Free R T] [Module.Finite R S] [Module.Finite R T] :
trace R (S × T) = (trace R S).coprod (trace R T) :=
LinearMap.ext fun p => by rw [coprod_apply, trace_prod_apply]
section TraceForm
variable (R S)
/-- The `traceForm` maps `x y : S` to the trace of `x * y`.
It is a symmetric bilinear form and is nondegenerate if the extension is separable. -/
noncomputable def traceForm : BilinForm R S :=
LinearMap.compr₂ (lmul R S).toLinearMap (trace R S)
variable {S}
-- This is a nicer lemma than the one produced by `@[simps] def traceForm`.
@[simp]
theorem traceForm_apply (x y : S) : traceForm R S x y = trace R S (x * y) :=
rfl
theorem traceForm_isSymm : (traceForm R S).IsSymm := fun _ _ => congr_arg (trace R S) (mul_comm _ _)
theorem traceForm_toMatrix [DecidableEq ι] (i j) :
BilinForm.toMatrix b (traceForm R S) i j = trace R S (b i * b j) := by
rw [BilinForm.toMatrix_apply, traceForm_apply]
end TraceForm
end Algebra
|
RingTheory\TwoSidedIdeal\Basic.lean | /-
Copyright (c) 2024 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang
-/
import Mathlib.Tactic.Abel
import Mathlib.GroupTheory.GroupAction.SubMulAction
import Mathlib.RingTheory.Congruence.Basic
import Mathlib.Algebra.Module.LinearMap.Defs
/-!
# Two Sided Ideals
In this file, for any `Ring R`, we reinterpret `I : RingCon R` as a two-sided-ideal of a ring.
## Main definitions and results
* `TwoSidedIdeal`: For any `NonUnitalNonAssocRing R`, `TwoSidedIdeal R` is a wrapper around
`RingCon R`.
* `TwoSidedIdeal.setLike`: Every `I : TwoSidedIdeal R` can be interpreted as a set of `R` where
`x ∈ I` if and only if `I.ringCon x 0`.
* `TwoSidedIdeal.addCommGroup`: Every `I : TwoSidedIdeal R` is an abelian group.
-/
open MulOpposite
section definitions
/--
A two-sided ideal of a ring `R` is a subset of `R` that contains `0` and is closed under addition,
negation, and absorbs multiplication on both sides.
-/
structure TwoSidedIdeal (R : Type*) [NonUnitalNonAssocRing R] where
/-- every two-sided-ideal is induced by a congruence relation on the ring. -/
ringCon : RingCon R
end definitions
namespace TwoSidedIdeal
section NonUnitalNonAssocRing
variable {R : Type*} [NonUnitalNonAssocRing R] (I : TwoSidedIdeal R)
instance setLike : SetLike (TwoSidedIdeal R) R where
coe t := {r | t.ringCon r 0}
coe_injective' := by
rintro ⟨t₁⟩ ⟨t₂⟩ (h : {x | _} = {x | _})
congr 1
refine RingCon.ext fun a b ↦ ⟨fun H ↦ ?_, fun H ↦ ?_⟩
· have H' : a - b ∈ {x | t₁ x 0} := sub_self b ▸ t₁.sub H (t₁.refl b)
rw [h] at H'
convert t₂.add H' (t₂.refl b) using 1 <;> abel
· have H' : a - b ∈ {x | t₂ x 0} := sub_self b ▸ t₂.sub H (t₂.refl b)
rw [← h] at H'
convert t₁.add H' (t₁.refl b) using 1 <;> abel
lemma mem_iff (x : R) : x ∈ I ↔ I.ringCon x 0 := Iff.rfl
lemma rel_iff (x y : R) : I.ringCon x y ↔ x - y ∈ I := by
rw [mem_iff]
constructor
· intro h; convert I.ringCon.sub h (I.ringCon.refl y); abel
· intro h; convert I.ringCon.add h (I.ringCon.refl y) <;> abel
/--
the coercion from two-sided-ideals to sets is an order embedding
-/
@[simps]
def coeOrderEmbedding : TwoSidedIdeal R ↪o Set R where
toFun := SetLike.coe
inj' := SetLike.coe_injective
map_rel_iff' {I J} := ⟨fun (h : (I : Set R) ⊆ (J : Set R)) _ h' ↦ h h', fun h _ h' ↦ h h'⟩
lemma le_iff {I J : TwoSidedIdeal R} : I ≤ J ↔ (I : Set R) ⊆ (J : Set R) := Iff.rfl
/-- Two-sided-ideals corresponds to congruence relations on a ring. -/
def orderIsoRingCon : TwoSidedIdeal R ≃o RingCon R where
toFun := TwoSidedIdeal.ringCon
invFun := .mk
left_inv _ := rfl
right_inv _ := rfl
map_rel_iff' {I J} := Iff.symm $ le_iff.trans ⟨fun h x y r => by rw [rel_iff] at r ⊢; exact h r,
fun h x hx => by rw [SetLike.mem_coe, mem_iff] at hx ⊢; exact h hx⟩
lemma ringCon_injective : Function.Injective (TwoSidedIdeal.ringCon (R := R)) := by
rintro ⟨x⟩ ⟨y⟩ rfl; rfl
lemma ringCon_le_iff {I J : TwoSidedIdeal R} : I ≤ J ↔ I.ringCon ≤ J.ringCon :=
orderIsoRingCon.map_rel_iff.symm
@[ext]
lemma ext {I J : TwoSidedIdeal R} (h : ∀ x, x ∈ I ↔ x ∈ J) : I = J :=
coeOrderEmbedding.injective (Set.ext h)
lemma lt_iff (I J : TwoSidedIdeal R) : I < J ↔ (I : Set R) ⊂ (J : Set R) := by
rw [lt_iff_le_and_ne, Set.ssubset_iff_subset_ne, le_iff]
simp
lemma zero_mem : 0 ∈ I := I.ringCon.refl 0
lemma add_mem {x y} (hx : x ∈ I) (hy : y ∈ I) : x + y ∈ I := by simpa using I.ringCon.add hx hy
lemma neg_mem {x} (hx : x ∈ I) : -x ∈ I := by simpa using I.ringCon.neg hx
instance : AddSubgroupClass (TwoSidedIdeal R) R where
zero_mem := zero_mem
add_mem := @add_mem _ _
neg_mem := @neg_mem _ _
lemma sub_mem {x y} (hx : x ∈ I) (hy : y ∈ I) : x - y ∈ I := _root_.sub_mem hx hy
lemma mul_mem_left (x y) (hy : y ∈ I) : x * y ∈ I := by
simpa using I.ringCon.mul (I.ringCon.refl x) hy
lemma mul_mem_right (x y) (hx : x ∈ I) : x * y ∈ I := by
simpa using I.ringCon.mul hx (I.ringCon.refl y)
lemma nsmul_mem {x} (n : ℕ) (hx : x ∈ I) : n • x ∈ I := _root_.nsmul_mem hx _
lemma zsmul_mem {x} (n : ℤ) (hx : x ∈ I) : n • x ∈ I := _root_.zsmul_mem hx _
/--
The "set-theoretic-way" of constructing a two-sided ideal by providing:
- the underlying set `S`;
- a proof that `0 ∈ S`;
- a proof that `x + y ∈ S` if `x ∈ S` and `y ∈ S`;
- a proof that `-x ∈ S` if `x ∈ S`;
- a proof that `x * y ∈ S` if `y ∈ S`;
- a proof that `x * y ∈ S` if `x ∈ S`.
-/
def mk' (carrier : Set R)
(zero_mem : 0 ∈ carrier)
(add_mem : ∀ {x y}, x ∈ carrier → y ∈ carrier → x + y ∈ carrier)
(neg_mem : ∀ {x}, x ∈ carrier → -x ∈ carrier)
(mul_mem_left : ∀ {x y}, y ∈ carrier → x * y ∈ carrier)
(mul_mem_right : ∀ {x y}, x ∈ carrier → x * y ∈ carrier) : TwoSidedIdeal R where
ringCon :=
{ r := fun x y ↦ x - y ∈ carrier
iseqv :=
{ refl := fun x ↦ by simpa using zero_mem
symm := fun h ↦ by simpa using neg_mem h
trans := fun {x y z} h1 h2 ↦ by
simpa only [show x - z = (x - y) + (y - z) by abel] using add_mem h1 h2 }
mul' := fun {a b c d} (h1 : a - b ∈ carrier) (h2 : c - d ∈ carrier) ↦ show _ ∈ carrier by
rw [show a * c - b * d = a * (c - d) + (a - b) * d by rw [mul_sub, sub_mul]; abel]
exact add_mem (mul_mem_left h2) (mul_mem_right h1)
add' := fun {a b c d} (h1 : a - b ∈ carrier) (h2 : c - d ∈ carrier) ↦ show _ ∈ carrier by
rw [show a + c - (b + d) = (a - b) + (c - d) by abel]
exact add_mem h1 h2 }
lemma mem_mk' (carrier : Set R)
(zero_mem : 0 ∈ carrier)
(add_mem : ∀ {x y}, x ∈ carrier → y ∈ carrier → x + y ∈ carrier)
(neg_mem : ∀ {x}, x ∈ carrier → -x ∈ carrier)
(mul_mem_left : ∀ {x y}, y ∈ carrier → x * y ∈ carrier)
(mul_mem_right : ∀ {x y}, x ∈ carrier → x * y ∈ carrier)
(x : R) :
x ∈ mk' carrier zero_mem add_mem neg_mem mul_mem_left mul_mem_right ↔ x ∈ carrier := by
rw [mem_iff]
simp [mk']
instance : SMulMemClass (TwoSidedIdeal R) R R where
smul_mem _ _ h := TwoSidedIdeal.mul_mem_left _ _ _ h
instance : SMulMemClass (TwoSidedIdeal R) Rᵐᵒᵖ R where
smul_mem _ _ h := TwoSidedIdeal.mul_mem_right _ _ _ h
instance : Add I where add x y := ⟨x.1 + y.1, I.add_mem x.2 y.2⟩
instance : Zero I where zero := ⟨0, I.zero_mem⟩
instance : SMul ℕ I where smul n x := ⟨n • x.1, I.nsmul_mem n x.2⟩
instance : Neg I where neg x := ⟨-x.1, I.neg_mem x.2⟩
instance : Sub I where sub x y := ⟨x.1 - y.1, I.sub_mem x.2 y.2⟩
instance : SMul ℤ I where smul n x := ⟨n • x.1, I.zsmul_mem n x.2⟩
instance addCommGroup : AddCommGroup I :=
Function.Injective.addCommGroup _ Subtype.coe_injective
rfl (fun _ _ ↦ rfl) (fun _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl) (fun _ _ ↦ rfl)
/-- The coercion into the ring as a `AddMonoidHom` -/
@[simp]
def coeAddMonoidHom : I →+ R where
toFun := (↑)
map_zero' := rfl
map_add' _ _ := rfl
end NonUnitalNonAssocRing
section Ring
variable {R : Type*} [Ring R] (I : TwoSidedIdeal R)
instance : SMul R I where smul r x := ⟨r • x.1, I.mul_mem_left _ _ x.2⟩
instance : SMul Rᵐᵒᵖ I where smul r x := ⟨r • x.1, I.mul_mem_right _ _ x.2⟩
instance leftModule : Module R I :=
Function.Injective.module _ (coeAddMonoidHom I) Subtype.coe_injective fun _ _ ↦ rfl
@[simp]
lemma coe_smul {r : R} {x : I} : (r • x : R) = r * (x : R) := rfl
instance rightModule : Module Rᵐᵒᵖ I :=
Function.Injective.module _ (coeAddMonoidHom I) Subtype.coe_injective fun _ _ ↦ rfl
@[simp]
lemma coe_mop_smul {r : Rᵐᵒᵖ} {x : I} : (r • x : R) = (x : R) * r.unop := rfl
instance : SMulCommClass R Rᵐᵒᵖ I where
smul_comm r s x := Subtype.ext <| smul_comm r s x.1
/--
For any `I : RingCon R`, when we view it as an ideal, `I.subtype` is the injective `R`-linear map
`I → R`.
-/
@[simps]
def subtype : I →ₗ[R] R where
toFun x := x.1
map_add' _ _ := rfl
map_smul' _ _ := rfl
/--
For any `RingCon R`, when we view it as an ideal in `Rᵒᵖ`, `subtype` is the injective `Rᵐᵒᵖ`-linear
map `I → Rᵐᵒᵖ`.
-/
@[simps]
def subtypeMop : I →ₗ[Rᵐᵒᵖ] Rᵐᵒᵖ where
toFun x := MulOpposite.op x.1
map_add' _ _ := rfl
map_smul' _ _ := rfl
end Ring
end TwoSidedIdeal
|
RingTheory\TwoSidedIdeal\Lattice.lean | /-
Copyright (c) 2024 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang
-/
import Mathlib.RingTheory.TwoSidedIdeal.Basic
/-!
# The complete lattice structure on two-sided ideals
-/
namespace TwoSidedIdeal
variable (R : Type*) [NonUnitalNonAssocRing R]
instance : Sup (TwoSidedIdeal R) where
sup I J := { ringCon := I.ringCon ⊔ J.ringCon }
lemma sup_ringCon (I J : TwoSidedIdeal R) : (I ⊔ J).ringCon = I.ringCon ⊔ J.ringCon := rfl
instance : SemilatticeSup (TwoSidedIdeal R) where
le_sup_left I J := by rw [ringCon_le_iff]; exact le_sup_left
le_sup_right I J := by rw [ringCon_le_iff]; exact le_sup_right
sup_le I J K h1 h2 := by rw [ringCon_le_iff] at h1 h2 ⊢; exact sup_le h1 h2
section sup
variable {R}
lemma mem_sup_left {I J : TwoSidedIdeal R} {x : R} (h : x ∈ I) :
x ∈ I ⊔ J :=
(show I ≤ I ⊔ J from le_sup_left) h
lemma mem_sup_right {I J : TwoSidedIdeal R} {x : R} (h : x ∈ J) :
x ∈ I ⊔ J :=
(show J ≤ I ⊔ J from le_sup_right) h
lemma mem_sup {I J : TwoSidedIdeal R} {x : R} :
x ∈ I ⊔ J ↔ ∃ y ∈ I, ∃ z ∈ J, y + z = x := by
constructor
· let s : TwoSidedIdeal R := .mk'
{x | ∃ y ∈ I, ∃ z ∈ J, y + z = x}
⟨0, ⟨zero_mem _, ⟨0, ⟨zero_mem _, zero_add _⟩⟩⟩⟩
(by rintro _ _ ⟨x, ⟨hx, ⟨y, ⟨hy, rfl⟩⟩⟩⟩ ⟨a, ⟨ha, ⟨b, ⟨hb, rfl⟩⟩⟩⟩;
exact ⟨x + a, ⟨add_mem _ hx ha, ⟨y + b, ⟨add_mem _ hy hb, by abel⟩⟩⟩⟩)
(by rintro _ ⟨x, ⟨hx, ⟨y, ⟨hy, rfl⟩⟩⟩⟩
exact ⟨-x, ⟨neg_mem _ hx, ⟨-y, ⟨neg_mem _ hy, by abel⟩⟩⟩⟩)
(by rintro r _ ⟨x, ⟨hx, ⟨y, ⟨hy, rfl⟩⟩⟩⟩
exact ⟨_, ⟨mul_mem_left _ _ _ hx, ⟨_, ⟨mul_mem_left _ _ _ hy, mul_add _ _ _ |>.symm⟩⟩⟩⟩)
(by rintro r _ ⟨x, ⟨hx, ⟨y, ⟨hy, rfl⟩⟩⟩⟩
exact ⟨_, ⟨mul_mem_right _ _ _ hx, ⟨_, ⟨mul_mem_right _ _ _ hy, add_mul _ _ _ |>.symm⟩⟩⟩⟩)
suffices (I.ringCon ⊔ J.ringCon) ≤ s.ringCon by
intro h; convert this h; rw [rel_iff, sub_zero, mem_mk']; rfl
refine sup_le (fun x y h => ?_) (fun x y h => ?_) <;> rw [rel_iff] at h ⊢ <;> rw [mem_mk']
exacts [⟨_, ⟨h, ⟨0, ⟨zero_mem _, add_zero _⟩⟩⟩⟩, ⟨0, ⟨zero_mem _, ⟨_, ⟨h, zero_add _⟩⟩⟩⟩]
· rintro ⟨y, ⟨hy, ⟨z, ⟨hz, rfl⟩⟩⟩⟩; exact add_mem _ (mem_sup_left hy) (mem_sup_right hz)
end sup
instance : Inf (TwoSidedIdeal R) where
inf := fun I J => { ringCon := I.ringCon ⊓ J.ringCon }
lemma inf_ringCon (I J : TwoSidedIdeal R) : (I ⊓ J).ringCon = I.ringCon ⊓ J.ringCon := rfl
instance : SemilatticeInf (TwoSidedIdeal R) where
inf_le_left I J := by rw [ringCon_le_iff]; exact inf_le_left
inf_le_right I J := by rw [ringCon_le_iff]; exact inf_le_right
le_inf I J K h1 h2 := by rw [ringCon_le_iff] at h1 h2 ⊢; exact le_inf h1 h2
lemma mem_inf {I J : TwoSidedIdeal R} {x : R} :
x ∈ I ⊓ J ↔ x ∈ I ∧ x ∈ J :=
Iff.rfl
instance : SupSet (TwoSidedIdeal R) where
sSup s := { ringCon := sSup $ TwoSidedIdeal.ringCon '' s }
lemma sSup_ringCon (S : Set (TwoSidedIdeal R)) :
(sSup S).ringCon = sSup (TwoSidedIdeal.ringCon '' S) := rfl
lemma iSup_ringCon {ι : Type*} (I : ι → TwoSidedIdeal R) :
(⨆ i, I i).ringCon = ⨆ i, (I i).ringCon := by
simp only [iSup, sSup_ringCon]; congr; ext; simp
instance : CompleteSemilatticeSup (TwoSidedIdeal R) where
sSup_le s I h := by simp_rw [ringCon_le_iff] at h ⊢; exact sSup_le $ by aesop
le_sSup s I hI := by rw [ringCon_le_iff]; exact le_sSup $ by aesop
instance : InfSet (TwoSidedIdeal R) where
sInf s := { ringCon := sInf $ TwoSidedIdeal.ringCon '' s }
lemma sInf_ringCon (S : Set (TwoSidedIdeal R)) :
(sInf S).ringCon = sInf (TwoSidedIdeal.ringCon '' S) := rfl
lemma iInf_ringCon {ι : Type*} (I : ι → TwoSidedIdeal R) :
(⨅ i, I i).ringCon = ⨅ i, (I i).ringCon := by
simp only [iInf, sInf_ringCon]; congr!; ext; simp
instance : CompleteSemilatticeInf (TwoSidedIdeal R) where
le_sInf s I h := by simp_rw [ringCon_le_iff] at h ⊢; exact le_sInf $ by aesop
sInf_le s I hI := by rw [ringCon_le_iff]; exact sInf_le $ by aesop
lemma mem_iInf {ι : Type*} {I : ι → TwoSidedIdeal R} {x : R} :
x ∈ iInf I ↔ ∀ i, x ∈ I i :=
show (∀ _, _) ↔ _ by simp [mem_iff]
lemma mem_sInf {S : Set (TwoSidedIdeal R)} {x : R} :
x ∈ sInf S ↔ ∀ I ∈ S, x ∈ I :=
show (∀ _, _) ↔ _ by simp [mem_iff]
instance : Top (TwoSidedIdeal R) where
top := { ringCon := ⊤ }
lemma top_ringCon : (⊤ : TwoSidedIdeal R).ringCon = ⊤ := rfl
instance : Bot (TwoSidedIdeal R) where
bot := { ringCon := ⊥ }
lemma bot_ringCon : (⊥ : TwoSidedIdeal R).ringCon = ⊥ := rfl
lemma mem_bot {x : R} : x ∈ (⊥ : TwoSidedIdeal R) ↔ x = 0 :=
Iff.rfl
instance : CompleteLattice (TwoSidedIdeal R) where
__ := (inferInstance : SemilatticeSup (TwoSidedIdeal R))
__ := (inferInstance : SemilatticeInf (TwoSidedIdeal R))
__ := (inferInstance : CompleteSemilatticeSup (TwoSidedIdeal R))
__ := (inferInstance : CompleteSemilatticeInf (TwoSidedIdeal R))
le_top _ := by rw [ringCon_le_iff]; exact le_top
bot_le _ := by rw [ringCon_le_iff]; exact bot_le
end TwoSidedIdeal
|
RingTheory\Unramified\Basic.lean | /-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.RingTheory.FinitePresentation
import Mathlib.RingTheory.FiniteStability
import Mathlib.RingTheory.Localization.Away.Basic
import Mathlib.RingTheory.Localization.Away.AdjoinRoot
import Mathlib.RingTheory.QuotientNilpotent
import Mathlib.RingTheory.TensorProduct.Basic
/-!
# Unramified morphisms
An `R`-algebra `A` is formally unramified if for every `R`-algebra,
every square-zero ideal `I : Ideal B` and `f : A →ₐ[R] B ⧸ I`, there exists
at most one lift `A →ₐ[R] B`.
It is unramified if it is formally unramified and of finite type.
Note that there are multiple definitions in the literature. The definition we give is equivalent to
the one in the Stacks Project https://stacks.math.columbia.edu/tag/00US. Note that in EGA unramified
is defined as formally unramified and of finite presentation.
We show that the property extends onto nilpotent ideals, and that it is stable
under `R`-algebra homomorphisms and compositions.
We show that unramified is stable under algebra isomorphisms, composition and
localization at an element.
-/
-- Porting note: added to make the syntax work below.
open scoped TensorProduct
universe u
namespace Algebra
section
variable (R : Type u) [CommSemiring R]
variable (A : Type u) [Semiring A] [Algebra R A]
/-- An `R`-algebra `A` is formally unramified if for every `R`-algebra, every square-zero ideal
`I : Ideal B` and `f : A →ₐ[R] B ⧸ I`, there exists at most one lift `A →ₐ[R] B`.
See <https://stacks.math.columbia.edu/tag/00UM>. -/
@[mk_iff]
class FormallyUnramified : Prop where
comp_injective :
∀ ⦃B : Type u⦄ [CommRing B],
∀ [Algebra R B] (I : Ideal B) (_ : I ^ 2 = ⊥),
Function.Injective ((Ideal.Quotient.mkₐ R I).comp : (A →ₐ[R] B) → A →ₐ[R] B ⧸ I)
end
namespace FormallyUnramified
section
variable {R : Type u} [CommSemiring R]
variable {A : Type u} [Semiring A] [Algebra R A]
variable {B : Type u} [CommRing B] [Algebra R B] (I : Ideal B)
theorem lift_unique {B : Type u} [CommRing B] [_RB : Algebra R B]
[FormallyUnramified R A] (I : Ideal B) (hI : IsNilpotent I) (g₁ g₂ : A →ₐ[R] B)
(h : (Ideal.Quotient.mkₐ R I).comp g₁ = (Ideal.Quotient.mkₐ R I).comp g₂) : g₁ = g₂ := by
revert g₁ g₂
change Function.Injective (Ideal.Quotient.mkₐ R I).comp
revert _RB
apply Ideal.IsNilpotent.induction_on (R := B) I hI
· intro B _ I hI _; exact FormallyUnramified.comp_injective I hI
· intro B _ I J hIJ h₁ h₂ _ g₁ g₂ e
apply h₁
apply h₂
ext x
replace e := AlgHom.congr_fun e x
dsimp only [AlgHom.comp_apply, Ideal.Quotient.mkₐ_eq_mk] at e ⊢
rwa [Ideal.Quotient.eq, ← map_sub, Ideal.mem_quotient_iff_mem hIJ, ← Ideal.Quotient.eq]
theorem ext [FormallyUnramified R A] (hI : IsNilpotent I) {g₁ g₂ : A →ₐ[R] B}
(H : ∀ x, Ideal.Quotient.mk I (g₁ x) = Ideal.Quotient.mk I (g₂ x)) : g₁ = g₂ :=
FormallyUnramified.lift_unique I hI g₁ g₂ (AlgHom.ext H)
theorem lift_unique_of_ringHom [FormallyUnramified R A] {C : Type u} [CommRing C]
(f : B →+* C) (hf : IsNilpotent <| RingHom.ker f) (g₁ g₂ : A →ₐ[R] B)
(h : f.comp ↑g₁ = f.comp (g₂ : A →+* B)) : g₁ = g₂ :=
FormallyUnramified.lift_unique _ hf _ _
(by
ext x
have := RingHom.congr_fun h x
simpa only [Ideal.Quotient.eq, Function.comp_apply, AlgHom.coe_comp, Ideal.Quotient.mkₐ_eq_mk,
RingHom.mem_ker, map_sub, sub_eq_zero])
theorem ext' [FormallyUnramified R A] {C : Type u} [CommRing C] (f : B →+* C)
(hf : IsNilpotent <| RingHom.ker f) (g₁ g₂ : A →ₐ[R] B) (h : ∀ x, f (g₁ x) = f (g₂ x)) :
g₁ = g₂ :=
FormallyUnramified.lift_unique_of_ringHom f hf g₁ g₂ (RingHom.ext h)
theorem lift_unique' [FormallyUnramified R A] {C : Type u} [CommRing C]
[Algebra R C] (f : B →ₐ[R] C) (hf : IsNilpotent <| RingHom.ker (f : B →+* C))
(g₁ g₂ : A →ₐ[R] B) (h : f.comp g₁ = f.comp g₂) : g₁ = g₂ :=
FormallyUnramified.ext' _ hf g₁ g₂ (AlgHom.congr_fun h)
end
section OfEquiv
variable {R : Type u} [CommSemiring R]
variable {A B : Type u} [Semiring A] [Algebra R A] [Semiring B] [Algebra R B]
theorem of_equiv [FormallyUnramified R A] (e : A ≃ₐ[R] B) :
FormallyUnramified R B := by
constructor
intro C _ _ I hI f₁ f₂ e'
rw [← f₁.comp_id, ← f₂.comp_id, ← e.comp_symm, ← AlgHom.comp_assoc, ← AlgHom.comp_assoc]
congr 1
refine FormallyUnramified.comp_injective I hI ?_
rw [← AlgHom.comp_assoc, e', AlgHom.comp_assoc]
end OfEquiv
section Comp
variable (R : Type u) [CommSemiring R]
variable (A : Type u) [CommSemiring A] [Algebra R A]
variable (B : Type u) [Semiring B] [Algebra R B] [Algebra A B] [IsScalarTower R A B]
theorem comp [FormallyUnramified R A] [FormallyUnramified A B] :
FormallyUnramified R B := by
constructor
intro C _ _ I hI f₁ f₂ e
have e' :=
FormallyUnramified.lift_unique I ⟨2, hI⟩ (f₁.comp <| IsScalarTower.toAlgHom R A B)
(f₂.comp <| IsScalarTower.toAlgHom R A B) (by rw [← AlgHom.comp_assoc, e, AlgHom.comp_assoc])
letI := (f₁.comp (IsScalarTower.toAlgHom R A B)).toRingHom.toAlgebra
let F₁ : B →ₐ[A] C := { f₁ with commutes' := fun r => rfl }
let F₂ : B →ₐ[A] C := { f₂ with commutes' := AlgHom.congr_fun e'.symm }
ext1 x
change F₁ x = F₂ x
congr
exact FormallyUnramified.ext I ⟨2, hI⟩ (AlgHom.congr_fun e)
theorem of_comp [FormallyUnramified R B] : FormallyUnramified A B := by
constructor
intro Q _ _ I e f₁ f₂ e'
letI := ((algebraMap A Q).comp (algebraMap R A)).toAlgebra
letI : IsScalarTower R A Q := IsScalarTower.of_algebraMap_eq' rfl
refine AlgHom.restrictScalars_injective R ?_
refine FormallyUnramified.ext I ⟨2, e⟩ ?_
intro x
exact AlgHom.congr_fun e' x
end Comp
section BaseChange
open scoped TensorProduct
variable {R : Type u} [CommSemiring R]
variable {A : Type u} [Semiring A] [Algebra R A]
variable (B : Type u) [CommSemiring B] [Algebra R B]
instance base_change [FormallyUnramified R A] :
FormallyUnramified B (B ⊗[R] A) := by
constructor
intro C _ _ I hI f₁ f₂ e
letI := ((algebraMap B C).comp (algebraMap R B)).toAlgebra
haveI : IsScalarTower R B C := IsScalarTower.of_algebraMap_eq' rfl
ext : 1
· subsingleton
· exact FormallyUnramified.ext I ⟨2, hI⟩ fun x => AlgHom.congr_fun e (1 ⊗ₜ x)
end BaseChange
section Localization
variable {R S Rₘ Sₘ : Type u} [CommRing R] [CommRing S] [CommRing Rₘ] [CommRing Sₘ]
variable (M : Submonoid R)
variable [Algebra R S] [Algebra R Sₘ] [Algebra S Sₘ] [Algebra R Rₘ] [Algebra Rₘ Sₘ]
variable [IsScalarTower R Rₘ Sₘ] [IsScalarTower R S Sₘ]
variable [IsLocalization M Rₘ] [IsLocalization (M.map (algebraMap R S)) Sₘ]
-- Porting note: no longer supported
-- attribute [local elab_as_elim] Ideal.IsNilpotent.induction_on
/-- This holds in general for epimorphisms. -/
theorem of_isLocalization : FormallyUnramified R Rₘ := by
constructor
intro Q _ _ I _ f₁ f₂ _
apply AlgHom.coe_ringHom_injective
refine IsLocalization.ringHom_ext M ?_
ext
simp
/-- This actually does not need the localization instance, and is stated here again for
consistency. See `Algebra.FormallyUnramified.of_comp` instead.
The intended use is for copying proofs between `Formally{Unramified, Smooth, Etale}`
without the need to change anything (including removing redundant arguments). -/
-- @[nolint unusedArguments] -- Porting note: removed
theorem localization_base [FormallyUnramified R Sₘ] : FormallyUnramified Rₘ Sₘ :=
-- Porting note: added
let _ := M
FormallyUnramified.of_comp R Rₘ Sₘ
theorem localization_map [FormallyUnramified R S] :
FormallyUnramified Rₘ Sₘ := by
haveI : FormallyUnramified S Sₘ :=
FormallyUnramified.of_isLocalization (M.map (algebraMap R S))
haveI : FormallyUnramified R Sₘ := FormallyUnramified.comp R S Sₘ
exact FormallyUnramified.localization_base M
end Localization
end FormallyUnramified
section
variable (R : Type u) [CommSemiring R]
variable (A : Type u) [Semiring A] [Algebra R A]
/-- An `R`-algebra `A` is unramified if it is formally unramified and of finite type.
Note that the Stacks project has a different definition of unramified, and tag
<https://stacks.math.columbia.edu/tag/00UU> shows that their definition is the
same as this one.
-/
class Unramified : Prop where
formallyUnramified : FormallyUnramified R A := by infer_instance
finiteType : FiniteType R A := by infer_instance
end
namespace Unramified
attribute [instance] formallyUnramified finiteType
variable {R : Type u} [CommRing R]
variable {A B : Type u} [CommRing A] [Algebra R A] [CommRing B] [Algebra R B]
/-- Being unramified is transported via algebra isomorphisms. -/
theorem of_equiv [Unramified R A] (e : A ≃ₐ[R] B) : Unramified R B where
formallyUnramified := FormallyUnramified.of_equiv e
finiteType := FiniteType.equiv Unramified.finiteType e
/-- Localization at an element is unramified. -/
theorem of_isLocalization_Away (r : R) [IsLocalization.Away r A] : Unramified R A where
formallyUnramified := Algebra.FormallyUnramified.of_isLocalization (Submonoid.powers r)
finiteType :=
haveI : FinitePresentation R A := IsLocalization.Away.finitePresentation r
inferInstance
section Comp
variable (R A B)
/-- Unramified is stable under composition. -/
theorem comp [Algebra A B] [IsScalarTower R A B] [Unramified R A] [Unramified A B] :
Unramified R B where
formallyUnramified := FormallyUnramified.comp R A B
finiteType := FiniteType.trans (S := A) Unramified.finiteType
Unramified.finiteType
/-- Unramified is stable under base change. -/
instance baseChange [Unramified R A] : Unramified B (B ⊗[R] A) where
end Comp
end Unramified
end Algebra
|
RingTheory\Unramified\Derivations.lean | /-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.RingTheory.Kaehler.Basic
import Mathlib.RingTheory.Unramified.Basic
/-!
# Differential properties of formally unramified algebras
We show that `R`-algebra `A` is formally unramified iff the Kaehler differentials vanish.
-/
universe u
namespace Algebra
variable {R S : Type u} [CommRing R] [CommRing S] [Algebra R S]
instance FormallyUnramified.subsingleton_kaehlerDifferential [FormallyUnramified R S] :
Subsingleton (Ω[S⁄R]) := by
rw [← not_nontrivial_iff_subsingleton]
intro h
obtain ⟨f₁, f₂, e⟩ := (KaehlerDifferential.endEquiv R S).injective.nontrivial
apply e
ext1
apply FormallyUnramified.lift_unique' _ _ _ _ (f₁.2.trans f₂.2.symm)
rw [← AlgHom.toRingHom_eq_coe, AlgHom.ker_kerSquareLift]
exact ⟨_, Ideal.cotangentIdeal_square _⟩
theorem FormallyUnramified.iff_subsingleton_kaehlerDifferential :
FormallyUnramified R S ↔ Subsingleton (Ω[S⁄R]) := by
constructor
· intros; infer_instance
· intro H
constructor
intro B _ _ I hI f₁ f₂ e
letI := f₁.toRingHom.toAlgebra
haveI := IsScalarTower.of_algebraMap_eq' f₁.comp_algebraMap.symm
have :=
((KaehlerDifferential.linearMapEquivDerivation R S).toEquiv.trans
(derivationToSquareZeroEquivLift I hI)).surjective.subsingleton
exact Subtype.ext_iff.mp (@Subsingleton.elim _ this ⟨f₁, rfl⟩ ⟨f₂, e.symm⟩)
end Algebra
|
RingTheory\Unramified\Finite.lean | /-
Copyright (c) 2024 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.RingTheory.Ideal.IdempotentFG
import Mathlib.RingTheory.Unramified.Derivations
import Mathlib.RingTheory.Flat.Stability
/-!
# Various results about unramified algebras
We prove various theorems about unramified algebras. In fact we work in the more general setting
of formally unramified algebras which are essentially of finite type.
## Main results
- `Algebra.FormallyUnramified.iff_exists_tensorProduct`:
A finite-type `R`-algebra `S` is (formally) unramified iff
there exists a `t : S ⊗[R] S` satisfying
1. `t` annihilates every `1 ⊗ s - s ⊗ 1`.
2. the image of `t` is `1` under the map `S ⊗[R] S → S`.
- `Algebra.FormallyUnramified.finite_of_free`: An unramified free algebra is finitely generated.
- `Algebra.FormallyUnramified.flat_of_restrictScalars`:
If `S` is an unramified `R`-algebra, then `R`-flat implies `S`-flat.
## References
- [B. Iversen, *Generic Local Structure of the Morphisms in Commutative Algebra*][iversen]
-/
variable {R S} [CommRing R] [CommRing S] [Algebra R S]
variable (M : Type*) [AddCommGroup M] [Module R M] [Module S M] [IsScalarTower R S M]
open Algebra
open scoped TensorProduct
namespace Algebra.FormallyUnramified
/--
Proposition I.2.3 + I.2.6 of [iversen]
A finite-type `R`-algebra `S` is (formally) unramified iff there exists a `t : S ⊗[R] S` satisfying
1. `t` annihilates every `1 ⊗ s - s ⊗ 1`.
2. the image of `t` is `1` under the map `S ⊗[R] S → S`.
-/
theorem iff_exists_tensorProduct [EssFiniteType R S] :
FormallyUnramified R S ↔ ∃ t : S ⊗[R] S,
(∀ s, ((1 : S) ⊗ₜ[R] s - s ⊗ₜ[R] (1 : S)) * t = 0) ∧ TensorProduct.lmul' R t = 1 := by
rw [iff_subsingleton_kaehlerDifferential, KaehlerDifferential,
Ideal.cotangent_subsingleton_iff, Ideal.isIdempotentElem_iff_of_fg _
(KaehlerDifferential.ideal_fg R S)]
have : ∀ t : S ⊗[R] S, TensorProduct.lmul' R t = 1 ↔ 1 - t ∈ KaehlerDifferential.ideal R S := by
intro t
simp only [KaehlerDifferential.ideal, RingHom.mem_ker, map_sub, map_one,
sub_eq_zero, @eq_comm S 1]
simp_rw [this, ← KaehlerDifferential.span_range_eq_ideal]
constructor
· rintro ⟨e, he₁, he₂ : _ = Ideal.span _⟩
refine ⟨1 - e, ?_, ?_⟩
· intro s
obtain ⟨x, hx⟩ : e ∣ 1 ⊗ₜ[R] s - s ⊗ₜ[R] 1 := by
rw [← Ideal.mem_span_singleton, ← he₂]
exact Ideal.subset_span ⟨s, rfl⟩
rw [hx, mul_comm, ← mul_assoc, sub_mul, one_mul, he₁.eq, sub_self, zero_mul]
· rw [sub_sub_cancel, he₂, Ideal.mem_span_singleton]
· rintro ⟨t, ht₁, ht₂⟩
use 1 - t
rw [← sub_sub_self 1 t] at ht₁; generalize 1 - t = e at *
constructor
· suffices e ∈ (Submodule.span (S ⊗[R] S) {1 - e}).annihilator by
simpa [IsIdempotentElem, mul_sub, sub_eq_zero, eq_comm, -Ideal.submodule_span_eq,
Submodule.mem_annihilator_span_singleton] using this
exact (show Ideal.span _ ≤ _ by simpa only [Ideal.span_le, Set.range_subset_iff,
Submodule.mem_annihilator_span_singleton, SetLike.mem_coe]) ht₂
· apply le_antisymm <;> simp only [Ideal.submodule_span_eq, Ideal.mem_span_singleton, ht₂,
Ideal.span_le, Set.singleton_subset_iff, SetLike.mem_coe, Set.range_subset_iff]
intro s
use 1 ⊗ₜ[R] s - s ⊗ₜ[R] 1
linear_combination ht₁ s
lemma finite_of_free_aux (I) [DecidableEq I] (b : Basis I R S)
(f : I →₀ S) (x : S) (a : I → I →₀ R) (ha : a = fun i ↦ b.repr (b i * x)) :
(1 ⊗ₜ[R] x * Finsupp.sum f fun i y ↦ y ⊗ₜ[R] b i) =
Finset.sum (f.support.biUnion fun i ↦ (a i).support) fun k ↦
Finsupp.sum (b.repr (f.sum fun i y ↦ a i k • y)) fun j c ↦ c • b j ⊗ₜ[R] b k := by
rw [Finsupp.sum, Finset.mul_sum]
subst ha
let a i := b.repr (b i * x)
conv_lhs =>
simp only [TensorProduct.tmul_mul_tmul, one_mul, mul_comm x (b _),
← show ∀ i, Finsupp.total _ _ _ b (a i) = b i * x from fun _ ↦ b.total_repr _]
conv_lhs => simp only [Finsupp.total, Finsupp.coe_lsum,
LinearMap.coe_smulRight, LinearMap.id_coe, id_eq, Finsupp.sum, TensorProduct.tmul_sum,
← TensorProduct.smul_tmul]
have h₁ : ∀ k,
(Finsupp.sum (Finsupp.sum f fun i y ↦ a i k • b.repr y) fun j z ↦ z • b j ⊗ₜ[R] b k) =
(f.sum fun i y ↦ (b.repr y).sum fun j z ↦ a i k • z • b j ⊗ₜ[R] b k) := by
intro i
rw [Finsupp.sum_sum_index]
congr
ext j s
rw [Finsupp.sum_smul_index]
simp only [mul_smul, Finsupp.sum, ← Finset.smul_sum]
· intro; simp only [zero_smul]
· intro; simp only [zero_smul]
· intros; simp only [add_smul]
have h₂ : ∀ (x : S), ((b.repr x).support.sum fun a ↦ b.repr x a • b a) = x := by
simpa only [Finsupp.total_apply, Finsupp.sum] using b.total_repr
simp_rw [map_finsupp_sum, map_smul, h₁, Finsupp.sum, Finset.sum_comm (t := f.support),
TensorProduct.smul_tmul', ← TensorProduct.sum_tmul, ← Finset.smul_sum, h₂]
apply Finset.sum_congr rfl
intros i hi
apply Finset.sum_subset_zero_on_sdiff
· exact Finset.subset_biUnion_of_mem (fun i ↦ (a i).support) hi
· simp only [Finset.mem_sdiff, Finset.mem_biUnion, Finsupp.mem_support_iff, ne_eq, not_not,
and_imp, forall_exists_index]
simp (config := {contextual := true})
· exact fun _ _ ↦ rfl
variable [FormallyUnramified R S] [EssFiniteType R S]
variable (R S) in
/--
A finite-type `R`-algebra `S` is (formally) unramified iff there exists a `t : S ⊗[R] S` satisfying
1. `t` annihilates every `1 ⊗ s - s ⊗ 1`.
2. the image of `t` is `1` under the map `S ⊗[R] S → S`.
See `Algebra.FormallyUnramified.iff_exists_tensorProduct`.
This is the choice of such a `t`.
-/
noncomputable
def elem : S ⊗[R] S :=
(iff_exists_tensorProduct.mp inferInstance).choose
lemma one_tmul_sub_tmul_one_mul_elem
(s : S) : (1 ⊗ₜ s - s ⊗ₜ 1) * elem R S = 0 :=
(iff_exists_tensorProduct.mp inferInstance).choose_spec.1 s
lemma one_tmul_mul_elem
(s : S) : (1 ⊗ₜ s) * elem R S = (s ⊗ₜ 1) * elem R S := by
rw [← sub_eq_zero, ← sub_mul, one_tmul_sub_tmul_one_mul_elem]
lemma lmul_elem :
TensorProduct.lmul' R (elem R S) = 1 :=
(iff_exists_tensorProduct.mp inferInstance).choose_spec.2
variable (R S)
/-- An unramified free algebra is finitely generated. Iversen I.2.8 -/
lemma finite_of_free [Module.Free R S] : Module.Finite R S := by
classical
let I := Module.Free.ChooseBasisIndex R S
-- Let `bᵢ` be an `R`-basis of `S`.
let b : Basis I R S := Module.Free.chooseBasis R S
-- Let `∑ₛ fᵢ ⊗ bᵢ : S ⊗[R] S` (summing over some finite `s`) be an element such that
-- `∑ₛ fᵢbᵢ = 1` and `∀ x : S, xfᵢ ⊗ bᵢ = aᵢ ⊗ xfᵢ` which exists since `S` is unramified over `R`.
have ⟨f, hf⟩ : ∃ (a : I →₀ S), elem R S = a.sum (fun i x ↦ x ⊗ₜ b i) := by
let b' := ((Basis.singleton PUnit.{1} S).tensorProduct b).reindex (Equiv.punitProd I)
use b'.repr (elem R S)
conv_lhs => rw [← b'.total_repr (elem R S), Finsupp.total_apply]
congr! with _ i x
simp [b', Basis.tensorProduct, TensorProduct.smul_tmul']
constructor
-- I claim that `{ fᵢbⱼ | i, j ∈ s }` spans `S` over `R`.
use Finset.image₂ (fun i j ↦ f i * b j) f.support f.support
rw [← top_le_iff]
-- For all `x : S`, let `bᵢx = ∑ aᵢⱼbⱼ`.
rintro x -
let a : I → I →₀ R := fun i ↦ b.repr (b i * x)
-- Consider `F` such that `fⱼx = ∑ Fᵢⱼbⱼ`.
let F : I →₀ I →₀ R := Finsupp.onFinset f.support (fun j ↦ b.repr (x * f j))
(fun j ↦ not_imp_comm.mp fun hj ↦ by simp [Finsupp.not_mem_support_iff.mp hj])
have hG : ∀ j ∉ (Finset.biUnion f.support fun i ↦ (a i).support),
b.repr (f.sum (fun i y ↦ a i j • y)) = 0 := by
intros j hj
simp only [Finset.mem_biUnion, Finsupp.mem_support_iff, ne_eq, not_exists, not_and,
not_not] at hj
simp only [Finsupp.sum]
trans b.repr (f.support.sum (fun _ ↦ 0))
· refine congr_arg b.repr (Finset.sum_congr rfl ?_)
simp only [Finsupp.mem_support_iff]
intro i hi
rw [hj i hi, zero_smul]
· simp only [Finset.sum_const_zero, map_zero]
-- And `G` such that `∑ₛ aᵢⱼfᵢ = ∑ Gᵢⱼbⱼ`, where `aᵢⱼ` are the coefficients `bᵢx = ∑ aᵢⱼbⱼ`.
let G : I →₀ I →₀ R := Finsupp.onFinset (Finset.biUnion f.support (fun i ↦ (a i).support))
(fun j ↦ b.repr (f.sum (fun i y ↦ a i j • y)))
(fun j ↦ not_imp_comm.mp (hG j))
-- Then `∑ Fᵢⱼ(bⱼ ⊗ bᵢ) = ∑ fⱼx ⊗ bᵢ = ∑ fⱼ ⊗ xbᵢ = ∑ aᵢⱼ(fⱼ ⊗ bᵢ) = ∑ Gᵢⱼ(bⱼ ⊗ bᵢ)`.
-- Since `bⱼ ⊗ bᵢ` forms an `R`-basis of `S ⊗ S`, we conclude that `F = G`.
have : F = G := by
apply Finsupp.finsuppProdEquiv.symm.injective
apply (Finsupp.equivCongrLeft (Equiv.prodComm I I)).injective
apply (b.tensorProduct b).repr.symm.injective
simp only [Basis.repr_symm_apply, Finsupp.coe_lsum, LinearMap.coe_smulRight,
LinearMap.id_coe, id_eq, Basis.tensorProduct_apply, Finsupp.finsuppProdEquiv,
Equiv.coe_fn_symm_mk, Finsupp.uncurry, map_finsupp_sum,
Finsupp.total_single, Basis.tensorProduct_apply, Finsupp.equivCongrLeft_apply,
Finsupp.total_equivMapDomain, Equiv.coe_prodComm]
rw [Finsupp.onFinset_sum, Finsupp.onFinset_sum]
simp only [Function.comp_apply, Prod.swap_prod_mk, Basis.tensorProduct_apply]
have : ∀ i, ((b.repr (x * f i)).sum fun j k ↦ k • b j ⊗ₜ[R] b i) = (x * f i) ⊗ₜ[R] b i := by
intro i
simp_rw [Finsupp.sum, TensorProduct.smul_tmul', ← TensorProduct.sum_tmul]
congr 1
exact b.total_repr _
trans (x ⊗ₜ 1) * elem R S
· simp_rw [this, hf, Finsupp.sum, Finset.mul_sum, TensorProduct.tmul_mul_tmul, one_mul]
· rw [← one_tmul_mul_elem, hf, finite_of_free_aux]
rfl
· intro; simp
· intro; simp
-- In particular, `fⱼx = ∑ Fᵢⱼbⱼ = ∑ Gᵢⱼbⱼ = ∑ₛ aᵢⱼfᵢ` for all `j`.
have : ∀ j, x * f j = f.sum fun i y ↦ a i j • y := by
intro j
apply b.repr.injective
exact DFunLike.congr_fun this j
-- Since `∑ₛ fⱼbⱼ = 1`, `x = ∑ₛ aᵢⱼfᵢbⱼ` is indeed in the span of `{ fᵢbⱼ | i, j ∈ s }`.
rw [← mul_one x, ← @lmul_elem R, hf, map_finsupp_sum, Finsupp.sum, Finset.mul_sum]
simp only [TensorProduct.lmul'_apply_tmul, Finset.coe_image₂, ← mul_assoc, this,
Finsupp.sum, Finset.sum_mul, smul_mul_assoc]
apply Submodule.sum_mem; intro i hi
apply Submodule.sum_mem; intro j hj
apply Submodule.smul_mem
apply Submodule.subset_span
use j, hj, i, hi
/--
Proposition I.2.3 of [iversen]
If `S` is an unramified `R`-algebra, and `M` is a `S`-module, then the map
`S ⊗[R] M →ₗ[S] M` taking `(b, m) ↦ b • m` admits a `S`-linear section. -/
noncomputable
def sec :
M →ₗ[S] S ⊗[R] M where
__ := ((TensorProduct.AlgebraTensorModule.mapBilinear R S S S S S M
LinearMap.id).flip (elem R S)).comp (lsmul R R M).toLinearMap.flip
map_smul' r m := by
simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, LinearMap.coe_comp, Function.comp_apply,
LinearMap.flip_apply, TensorProduct.AlgebraTensorModule.mapBilinear_apply, RingHom.id_apply]
trans (TensorProduct.AlgebraTensorModule.map (LinearMap.id (R := S) (M := S))
((LinearMap.flip (AlgHom.toLinearMap (lsmul R R M))) m)) ((1 ⊗ₜ r) * elem R S)
· induction' elem R S using TensorProduct.induction_on
· simp
· simp [smul_comm r]
· simp only [map_add, mul_add, *]
· have := one_tmul_sub_tmul_one_mul_elem (R := R) r
rw [sub_mul, sub_eq_zero] at this
rw [this]
induction' elem R S using TensorProduct.induction_on
· simp
· simp [TensorProduct.smul_tmul']
· simp only [map_add, smul_add, mul_add, *]
lemma comp_sec :
(TensorProduct.AlgebraTensorModule.lift
((lsmul S S M).toLinearMap.flip.restrictScalars R).flip).comp (sec R S M) =
LinearMap.id := by
ext x
simp only [sec, LinearMap.coe_comp, LinearMap.coe_mk, LinearMap.coe_toAddHom,
Function.comp_apply, LinearMap.flip_apply, TensorProduct.AlgebraTensorModule.mapBilinear_apply,
TensorProduct.AlgebraTensorModule.lift_apply, LinearMap.id_coe, id_eq]
trans (TensorProduct.lmul' R (elem R S)) • x
· induction' elem R S using TensorProduct.induction_on with r s y z hy hz
· simp
· simp [mul_smul, smul_comm r s]
· simp [hy, hz, add_smul]
· rw [lmul_elem, one_smul]
/-- If `S` is an unramified `R`-algebra, then `R`-flat implies `S`-flat. Iversen I.2.7 -/
lemma flat_of_restrictScalars [Module.Flat R M] : Module.Flat S M :=
Module.Flat.of_retract _ _ _ _ _ (comp_sec R S M)
/-- If `S` is an unramified `R`-algebra, then `R`-projective implies `S`-projective. -/
lemma projective_of_restrictScalars [Module.Projective R M] : Module.Projective S M :=
Module.Projective.of_split _ _ (comp_sec R S M)
end Algebra.FormallyUnramified
|
RingTheory\Valuation\Basic.lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Johan Commelin, Patrick Massot
-/
import Mathlib.Algebra.Order.Ring.Basic
import Mathlib.RingTheory.Ideal.Maps
import Mathlib.Tactic.TFAE
/-!
# The basics of valuation theory.
The basic theory of valuations (non-archimedean norms) on a commutative ring,
following T. Wedhorn's unpublished notes “Adic Spaces” ([wedhorn_adic]).
The definition of a valuation we use here is Definition 1.22 of [wedhorn_adic].
A valuation on a ring `R` is a monoid homomorphism `v` to a linearly ordered
commutative monoid with zero, that in addition satisfies the following two axioms:
* `v 0 = 0`
* `∀ x y, v (x + y) ≤ max (v x) (v y)`
`Valuation R Γ₀`is the type of valuations `R → Γ₀`, with a coercion to the underlying
function. If `v` is a valuation from `R` to `Γ₀` then the induced group
homomorphism `Units(R) → Γ₀` is called `unit_map v`.
The equivalence "relation" `IsEquiv v₁ v₂ : Prop` defined in 1.27 of [wedhorn_adic] is not strictly
speaking a relation, because `v₁ : Valuation R Γ₁` and `v₂ : Valuation R Γ₂` might
not have the same type. This corresponds in ZFC to the set-theoretic difficulty
that the class of all valuations (as `Γ₀` varies) on a ring `R` is not a set.
The "relation" is however reflexive, symmetric and transitive in the obvious
sense. Note that we use 1.27(iii) of [wedhorn_adic] as the definition of equivalence.
## Main definitions
* `Valuation R Γ₀`, the type of valuations on `R` with values in `Γ₀`
* `Valuation.IsEquiv`, the heterogeneous equivalence relation on valuations
* `Valuation.supp`, the support of a valuation
* `AddValuation R Γ₀`, the type of additive valuations on `R` with values in a
linearly ordered additive commutative group with a top element, `Γ₀`.
## Implementation Details
`AddValuation R Γ₀` is implemented as `Valuation R (Multiplicative Γ₀)ᵒᵈ`.
## Notation
In the `DiscreteValuation` locale:
* `ℕₘ₀` is a shorthand for `WithZero (Multiplicative ℕ)`
* `ℤₘ₀` is a shorthand for `WithZero (Multiplicative ℤ)`
## TODO
If ever someone extends `Valuation`, we should fully comply to the `DFunLike` by migrating the
boilerplate lemmas to `ValuationClass`.
-/
open scoped Classical
open Function Ideal
noncomputable section
variable {K F R : Type*} [DivisionRing K]
section
variable (F R) (Γ₀ : Type*) [LinearOrderedCommMonoidWithZero Γ₀] [Ring R]
--porting note (#5171): removed @[nolint has_nonempty_instance]
/-- The type of `Γ₀`-valued valuations on `R`.
When you extend this structure, make sure to extend `ValuationClass`. -/
structure Valuation extends R →*₀ Γ₀ where
/-- The valuation of a a sum is less that the sum of the valuations -/
map_add_le_max' : ∀ x y, toFun (x + y) ≤ max (toFun x) (toFun y)
/-- `ValuationClass F α β` states that `F` is a type of valuations.
You should also extend this typeclass when you extend `Valuation`. -/
class ValuationClass (F) (R Γ₀ : outParam Type*) [LinearOrderedCommMonoidWithZero Γ₀] [Ring R]
[FunLike F R Γ₀]
extends MonoidWithZeroHomClass F R Γ₀ : Prop where
/-- The valuation of a a sum is less that the sum of the valuations -/
map_add_le_max (f : F) (x y : R) : f (x + y) ≤ max (f x) (f y)
export ValuationClass (map_add_le_max)
instance [FunLike F R Γ₀] [ValuationClass F R Γ₀] : CoeTC F (Valuation R Γ₀) :=
⟨fun f =>
{ toFun := f
map_one' := map_one f
map_zero' := map_zero f
map_mul' := map_mul f
map_add_le_max' := map_add_le_max f }⟩
end
namespace Valuation
variable {Γ₀ : Type*}
variable {Γ'₀ : Type*}
variable {Γ''₀ : Type*} [LinearOrderedCommMonoidWithZero Γ''₀]
section Basic
variable [Ring R]
section Monoid
variable [LinearOrderedCommMonoidWithZero Γ₀] [LinearOrderedCommMonoidWithZero Γ'₀]
instance : FunLike (Valuation R Γ₀) R Γ₀ where
coe f := f.toFun
coe_injective' f g h := by
obtain ⟨⟨⟨_,_⟩, _⟩, _⟩ := f
congr
instance : ValuationClass (Valuation R Γ₀) R Γ₀ where
map_mul f := f.map_mul'
map_one f := f.map_one'
map_zero f := f.map_zero'
map_add_le_max f := f.map_add_le_max'
@[simp]
theorem coe_mk (f : R →*₀ Γ₀) (h) : ⇑(Valuation.mk f h) = f := rfl
theorem toFun_eq_coe (v : Valuation R Γ₀) : v.toFun = v := rfl
@[simp] -- Porting note: requested by simpNF as toFun_eq_coe LHS simplifies
theorem toMonoidWithZeroHom_coe_eq_coe (v : Valuation R Γ₀) :
(v.toMonoidWithZeroHom : R → Γ₀) = v := rfl
@[ext]
theorem ext {v₁ v₂ : Valuation R Γ₀} (h : ∀ r, v₁ r = v₂ r) : v₁ = v₂ :=
DFunLike.ext _ _ h
variable (v : Valuation R Γ₀) {x y z : R}
@[simp, norm_cast]
theorem coe_coe : ⇑(v : R →*₀ Γ₀) = v := rfl
-- @[simp] Porting note (#10618): simp can prove this
theorem map_zero : v 0 = 0 :=
v.map_zero'
-- @[simp] Porting note (#10618): simp can prove this
theorem map_one : v 1 = 1 :=
v.map_one'
-- @[simp] Porting note (#10618): simp can prove this
theorem map_mul : ∀ x y, v (x * y) = v x * v y :=
v.map_mul'
-- Porting note: LHS side simplified so created map_add'
theorem map_add : ∀ x y, v (x + y) ≤ max (v x) (v y) :=
v.map_add_le_max'
@[simp]
theorem map_add' : ∀ x y, v (x + y) ≤ v x ∨ v (x + y) ≤ v y := by
intro x y
rw [← le_max_iff, ← ge_iff_le]
apply map_add
theorem map_add_le {x y g} (hx : v x ≤ g) (hy : v y ≤ g) : v (x + y) ≤ g :=
le_trans (v.map_add x y) <| max_le hx hy
theorem map_add_lt {x y g} (hx : v x < g) (hy : v y < g) : v (x + y) < g :=
lt_of_le_of_lt (v.map_add x y) <| max_lt hx hy
theorem map_sum_le {ι : Type*} {s : Finset ι} {f : ι → R} {g : Γ₀} (hf : ∀ i ∈ s, v (f i) ≤ g) :
v (∑ i ∈ s, f i) ≤ g := by
refine
Finset.induction_on s (fun _ => v.map_zero ▸ zero_le')
(fun a s has ih hf => ?_) hf
rw [Finset.forall_mem_insert] at hf; rw [Finset.sum_insert has]
exact v.map_add_le hf.1 (ih hf.2)
theorem map_sum_lt {ι : Type*} {s : Finset ι} {f : ι → R} {g : Γ₀} (hg : g ≠ 0)
(hf : ∀ i ∈ s, v (f i) < g) : v (∑ i ∈ s, f i) < g := by
refine
Finset.induction_on s (fun _ => v.map_zero ▸ (zero_lt_iff.2 hg))
(fun a s has ih hf => ?_) hf
rw [Finset.forall_mem_insert] at hf; rw [Finset.sum_insert has]
exact v.map_add_lt hf.1 (ih hf.2)
theorem map_sum_lt' {ι : Type*} {s : Finset ι} {f : ι → R} {g : Γ₀} (hg : 0 < g)
(hf : ∀ i ∈ s, v (f i) < g) : v (∑ i ∈ s, f i) < g :=
v.map_sum_lt (ne_of_gt hg) hf
-- @[simp] Porting note (#10618): simp can prove this
theorem map_pow : ∀ (x) (n : ℕ), v (x ^ n) = v x ^ n :=
v.toMonoidWithZeroHom.toMonoidHom.map_pow
-- The following definition is not an instance, because we have more than one `v` on a given `R`.
-- In addition, type class inference would not be able to infer `v`.
/-- A valuation gives a preorder on the underlying ring. -/
def toPreorder : Preorder R :=
Preorder.lift v
/-- If `v` is a valuation on a division ring then `v(x) = 0` iff `x = 0`. -/
-- @[simp] Porting note (#10618): simp can prove this
theorem zero_iff [Nontrivial Γ₀] (v : Valuation K Γ₀) {x : K} : v x = 0 ↔ x = 0 :=
map_eq_zero v
theorem ne_zero_iff [Nontrivial Γ₀] (v : Valuation K Γ₀) {x : K} : v x ≠ 0 ↔ x ≠ 0 :=
map_ne_zero v
theorem unit_map_eq (u : Rˣ) : (Units.map (v : R →* Γ₀) u : Γ₀) = v u :=
rfl
/-- A ring homomorphism `S → R` induces a map `Valuation R Γ₀ → Valuation S Γ₀`. -/
def comap {S : Type*} [Ring S] (f : S →+* R) (v : Valuation R Γ₀) : Valuation S Γ₀ :=
{ v.toMonoidWithZeroHom.comp f.toMonoidWithZeroHom with
toFun := v ∘ f
map_add_le_max' := fun x y => by simp only [comp_apply, map_add, f.map_add] }
@[simp]
theorem comap_apply {S : Type*} [Ring S] (f : S →+* R) (v : Valuation R Γ₀) (s : S) :
v.comap f s = v (f s) := rfl
@[simp]
theorem comap_id : v.comap (RingHom.id R) = v :=
ext fun _r => rfl
theorem comap_comp {S₁ : Type*} {S₂ : Type*} [Ring S₁] [Ring S₂] (f : S₁ →+* S₂) (g : S₂ →+* R) :
v.comap (g.comp f) = (v.comap g).comap f :=
ext fun _r => rfl
/-- A `≤`-preserving group homomorphism `Γ₀ → Γ'₀` induces a map `Valuation R Γ₀ → Valuation R Γ'₀`.
-/
def map (f : Γ₀ →*₀ Γ'₀) (hf : Monotone f) (v : Valuation R Γ₀) : Valuation R Γ'₀ :=
{ MonoidWithZeroHom.comp f v.toMonoidWithZeroHom with
toFun := f ∘ v
map_add_le_max' := fun r s =>
calc
f (v (r + s)) ≤ f (max (v r) (v s)) := hf (v.map_add r s)
_ = max (f (v r)) (f (v s)) := hf.map_max
}
/-- Two valuations on `R` are defined to be equivalent if they induce the same preorder on `R`. -/
def IsEquiv (v₁ : Valuation R Γ₀) (v₂ : Valuation R Γ'₀) : Prop :=
∀ r s, v₁ r ≤ v₁ s ↔ v₂ r ≤ v₂ s
end Monoid
section Group
variable [LinearOrderedCommGroupWithZero Γ₀] (v : Valuation R Γ₀) {x y z : R}
@[simp]
theorem map_neg (x : R) : v (-x) = v x :=
v.toMonoidWithZeroHom.toMonoidHom.map_neg x
theorem map_sub_swap (x y : R) : v (x - y) = v (y - x) :=
v.toMonoidWithZeroHom.toMonoidHom.map_sub_swap x y
theorem map_inv {R : Type*} [DivisionRing R] (v : Valuation R Γ₀) : ∀ x, v x⁻¹ = (v x)⁻¹ :=
map_inv₀ _
theorem map_div {R : Type*} [DivisionRing R] (v : Valuation R Γ₀) : ∀ x y, v (x / y) = v x / v y :=
map_div₀ _
theorem map_sub (x y : R) : v (x - y) ≤ max (v x) (v y) :=
calc
v (x - y) = v (x + -y) := by rw [sub_eq_add_neg]
_ ≤ max (v x) (v <| -y) := v.map_add _ _
_ = max (v x) (v y) := by rw [map_neg]
theorem map_sub_le {x y g} (hx : v x ≤ g) (hy : v y ≤ g) : v (x - y) ≤ g := by
rw [sub_eq_add_neg]
exact v.map_add_le hx (le_trans (le_of_eq (v.map_neg y)) hy)
theorem map_add_of_distinct_val (h : v x ≠ v y) : v (x + y) = max (v x) (v y) := by
suffices ¬v (x + y) < max (v x) (v y) from
or_iff_not_imp_right.1 (le_iff_eq_or_lt.1 (v.map_add x y)) this
intro h'
wlog vyx : v y < v x generalizing x y
· refine this h.symm ?_ (h.lt_or_lt.resolve_right vyx)
rwa [add_comm, max_comm]
rw [max_eq_left_of_lt vyx] at h'
apply lt_irrefl (v x)
calc
v x = v (x + y - y) := by simp
_ ≤ max (v <| x + y) (v y) := map_sub _ _ _
_ < v x := max_lt h' vyx
theorem map_add_eq_of_lt_right (h : v x < v y) : v (x + y) = v y :=
(v.map_add_of_distinct_val h.ne).trans (max_eq_right_iff.mpr h.le)
theorem map_add_eq_of_lt_left (h : v y < v x) : v (x + y) = v x := by
rw [add_comm]; exact map_add_eq_of_lt_right _ h
theorem map_sub_eq_of_lt_right (h : v x < v y) : v (x - y) = v y := by
rw [sub_eq_add_neg, map_add_eq_of_lt_right, map_neg]
rwa [map_neg]
theorem map_sub_eq_of_lt_left (h : v y < v x) : v (x - y) = v x := by
rw [sub_eq_add_neg, map_add_eq_of_lt_left]
rwa [map_neg]
theorem map_eq_of_sub_lt (h : v (y - x) < v x) : v y = v x := by
have := Valuation.map_add_of_distinct_val v (ne_of_gt h).symm
rw [max_eq_right (le_of_lt h)] at this
simpa using this
theorem map_one_add_of_lt (h : v x < 1) : v (1 + x) = 1 := by
rw [← v.map_one] at h
simpa only [v.map_one] using v.map_add_eq_of_lt_left h
theorem map_one_sub_of_lt (h : v x < 1) : v (1 - x) = 1 := by
rw [← v.map_one, ← v.map_neg] at h
rw [sub_eq_add_neg 1 x]
simpa only [v.map_one, v.map_neg] using v.map_add_eq_of_lt_left h
theorem one_lt_val_iff (v : Valuation K Γ₀) {x : K} (h : x ≠ 0) : 1 < v x ↔ v x⁻¹ < 1 := by
simpa using (inv_lt_inv₀ (v.ne_zero_iff.2 h) one_ne_zero).symm
theorem one_le_val_iff (v : Valuation K Γ₀) {x : K} (h : x ≠ 0) : 1 ≤ v x ↔ v x⁻¹ ≤ 1 := by
convert (one_lt_val_iff v (inv_ne_zero h)).symm.not <;>
push_neg <;> simp only [inv_inv]
theorem val_lt_one_iff (v : Valuation K Γ₀) {x : K} (h : x ≠ 0) : v x < 1 ↔ 1 < v x⁻¹ := by
simpa only [inv_inv] using (one_lt_val_iff v (inv_ne_zero h)).symm
theorem val_le_one_iff (v : Valuation K Γ₀) {x : K} (h : x ≠ 0) : v x ≤ 1 ↔ 1 ≤ v x⁻¹ := by
simpa [inv_inv] using (one_le_val_iff v (inv_ne_zero h)).symm
theorem val_eq_one_iff (v : Valuation K Γ₀) {x : K} : v x = 1 ↔ v x⁻¹ = 1 := by
by_cases h : x = 0
· simp only [map_inv₀, inv_eq_one]
· simpa only [le_antisymm_iff, And.comm] using and_congr (one_le_val_iff v h) (val_le_one_iff v h)
theorem val_le_one_or_val_inv_lt_one (v : Valuation K Γ₀) (x : K) : v x ≤ 1 ∨ v x⁻¹ < 1 := by
by_cases h : x = 0
· simp only [h, _root_.map_zero, zero_le', inv_zero, zero_lt_one, or_self]
· simp only [← one_lt_val_iff v h, le_or_lt]
/--
This theorem is a weaker version of `Valuation.val_le_one_or_val_inv_lt_one`, but more symmetric
in `x` and `x⁻¹`.
-/
theorem val_le_one_or_val_inv_le_one (v : Valuation K Γ₀) (x : K) : v x ≤ 1 ∨ v x⁻¹ ≤ 1 := by
by_cases h : x = 0
· simp only [h, _root_.map_zero, zero_le', inv_zero, or_self]
· simp only [← one_le_val_iff v h, le_total]
/-- The subgroup of elements whose valuation is less than a certain unit. -/
def ltAddSubgroup (v : Valuation R Γ₀) (γ : Γ₀ˣ) : AddSubgroup R where
carrier := { x | v x < γ }
zero_mem' := by simp
add_mem' {x y} x_in y_in := lt_of_le_of_lt (v.map_add x y) (max_lt x_in y_in)
neg_mem' x_in := by rwa [Set.mem_setOf, map_neg]
end Group
end Basic
-- end of section
namespace IsEquiv
variable [Ring R] [LinearOrderedCommMonoidWithZero Γ₀] [LinearOrderedCommMonoidWithZero Γ'₀]
{v : Valuation R Γ₀} {v₁ : Valuation R Γ₀} {v₂ : Valuation R Γ'₀} {v₃ : Valuation R Γ''₀}
@[refl]
theorem refl : v.IsEquiv v := fun _ _ => Iff.refl _
@[symm]
theorem symm (h : v₁.IsEquiv v₂) : v₂.IsEquiv v₁ := fun _ _ => Iff.symm (h _ _)
@[trans]
theorem trans (h₁₂ : v₁.IsEquiv v₂) (h₂₃ : v₂.IsEquiv v₃) : v₁.IsEquiv v₃ := fun _ _ =>
Iff.trans (h₁₂ _ _) (h₂₃ _ _)
theorem of_eq {v' : Valuation R Γ₀} (h : v = v') : v.IsEquiv v' := by subst h; rfl
theorem map {v' : Valuation R Γ₀} (f : Γ₀ →*₀ Γ'₀) (hf : Monotone f) (inf : Injective f)
(h : v.IsEquiv v') : (v.map f hf).IsEquiv (v'.map f hf) :=
let H : StrictMono f := hf.strictMono_of_injective inf
fun r s =>
calc
f (v r) ≤ f (v s) ↔ v r ≤ v s := by rw [H.le_iff_le]
_ ↔ v' r ≤ v' s := h r s
_ ↔ f (v' r) ≤ f (v' s) := by rw [H.le_iff_le]
/-- `comap` preserves equivalence. -/
theorem comap {S : Type*} [Ring S] (f : S →+* R) (h : v₁.IsEquiv v₂) :
(v₁.comap f).IsEquiv (v₂.comap f) := fun r s => h (f r) (f s)
theorem val_eq (h : v₁.IsEquiv v₂) {r s : R} : v₁ r = v₁ s ↔ v₂ r = v₂ s := by
simpa only [le_antisymm_iff] using and_congr (h r s) (h s r)
theorem ne_zero (h : v₁.IsEquiv v₂) {r : R} : v₁ r ≠ 0 ↔ v₂ r ≠ 0 := by
have : v₁ r ≠ v₁ 0 ↔ v₂ r ≠ v₂ 0 := not_congr h.val_eq
rwa [v₁.map_zero, v₂.map_zero] at this
end IsEquiv
-- end of namespace
section
theorem isEquiv_of_map_strictMono [LinearOrderedCommMonoidWithZero Γ₀]
[LinearOrderedCommMonoidWithZero Γ'₀] [Ring R] {v : Valuation R Γ₀} (f : Γ₀ →*₀ Γ'₀)
(H : StrictMono f) : IsEquiv (v.map f H.monotone) v := fun _x _y =>
⟨H.le_iff_le.mp, fun h => H.monotone h⟩
theorem isEquiv_of_val_le_one [LinearOrderedCommGroupWithZero Γ₀]
[LinearOrderedCommGroupWithZero Γ'₀] (v : Valuation K Γ₀) (v' : Valuation K Γ'₀)
(h : ∀ {x : K}, v x ≤ 1 ↔ v' x ≤ 1) : v.IsEquiv v' := by
intro x y
by_cases hy : y = 0; · simp [hy, zero_iff]
rw [show y = 1 * y by rw [one_mul]]
rw [← inv_mul_cancel_right₀ hy x]
iterate 2 rw [v.map_mul _ y, v'.map_mul _ y]
rw [v.map_one, v'.map_one]
constructor <;> intro H
· apply mul_le_mul_right'
replace hy := v.ne_zero_iff.mpr hy
replace H := le_of_le_mul_right hy H
rwa [h] at H
· apply mul_le_mul_right'
replace hy := v'.ne_zero_iff.mpr hy
replace H := le_of_le_mul_right hy H
rwa [h]
theorem isEquiv_iff_val_le_one [LinearOrderedCommGroupWithZero Γ₀]
[LinearOrderedCommGroupWithZero Γ'₀] (v : Valuation K Γ₀) (v' : Valuation K Γ'₀) :
v.IsEquiv v' ↔ ∀ {x : K}, v x ≤ 1 ↔ v' x ≤ 1 :=
⟨fun h x => by simpa using h x 1, isEquiv_of_val_le_one _ _⟩
theorem isEquiv_iff_val_eq_one [LinearOrderedCommGroupWithZero Γ₀]
[LinearOrderedCommGroupWithZero Γ'₀] (v : Valuation K Γ₀) (v' : Valuation K Γ'₀) :
v.IsEquiv v' ↔ ∀ {x : K}, v x = 1 ↔ v' x = 1 := by
constructor
· intro h x
simpa using @IsEquiv.val_eq _ _ _ _ _ _ v v' h x 1
· intro h
apply isEquiv_of_val_le_one
intro x
constructor
· intro hx
rcases lt_or_eq_of_le hx with hx' | hx'
· have : v (1 + x) = 1 := by
rw [← v.map_one]
apply map_add_eq_of_lt_left
simpa
rw [h] at this
rw [show x = -1 + (1 + x) by simp]
refine le_trans (v'.map_add _ _) ?_
simp [this]
· rw [h] at hx'
exact le_of_eq hx'
· intro hx
rcases lt_or_eq_of_le hx with hx' | hx'
· have : v' (1 + x) = 1 := by
rw [← v'.map_one]
apply map_add_eq_of_lt_left
simpa
rw [← h] at this
rw [show x = -1 + (1 + x) by simp]
refine le_trans (v.map_add _ _) ?_
simp [this]
· rw [← h] at hx'
exact le_of_eq hx'
theorem isEquiv_iff_val_lt_one [LinearOrderedCommGroupWithZero Γ₀]
[LinearOrderedCommGroupWithZero Γ'₀] (v : Valuation K Γ₀) (v' : Valuation K Γ'₀) :
v.IsEquiv v' ↔ ∀ {x : K}, v x < 1 ↔ v' x < 1 := by
constructor
· intro h x
simp only [lt_iff_le_and_ne,
and_congr ((isEquiv_iff_val_le_one _ _).1 h) ((isEquiv_iff_val_eq_one _ _).1 h).not]
· rw [isEquiv_iff_val_eq_one]
intro h x
by_cases hx : x = 0
· simp only [(zero_iff _).2 hx, zero_ne_one]
constructor
· intro hh
by_contra h_1
cases ne_iff_lt_or_gt.1 h_1 with
| inl h_2 => simpa [hh, lt_self_iff_false] using h.2 h_2
| inr h_2 =>
rw [← inv_one, ← inv_eq_iff_eq_inv, ← map_inv₀] at hh
exact hh.not_lt (h.2 ((one_lt_val_iff v' hx).1 h_2))
· intro hh
by_contra h_1
cases ne_iff_lt_or_gt.1 h_1 with
| inl h_2 => simpa [hh, lt_self_iff_false] using h.1 h_2
| inr h_2 =>
rw [← inv_one, ← inv_eq_iff_eq_inv, ← map_inv₀] at hh
exact hh.not_lt (h.1 ((one_lt_val_iff v hx).1 h_2))
theorem isEquiv_iff_val_sub_one_lt_one [LinearOrderedCommGroupWithZero Γ₀]
[LinearOrderedCommGroupWithZero Γ'₀] (v : Valuation K Γ₀) (v' : Valuation K Γ'₀) :
v.IsEquiv v' ↔ ∀ {x : K}, v (x - 1) < 1 ↔ v' (x - 1) < 1 := by
rw [isEquiv_iff_val_lt_one]
exact (Equiv.subRight 1).surjective.forall
theorem isEquiv_tfae [LinearOrderedCommGroupWithZero Γ₀] [LinearOrderedCommGroupWithZero Γ'₀]
(v : Valuation K Γ₀) (v' : Valuation K Γ'₀) :
[v.IsEquiv v', ∀ {x}, v x ≤ 1 ↔ v' x ≤ 1, ∀ {x}, v x = 1 ↔ v' x = 1, ∀ {x}, v x < 1 ↔ v' x < 1,
∀ {x}, v (x - 1) < 1 ↔ v' (x - 1) < 1].TFAE := by
tfae_have 1 ↔ 2; · apply isEquiv_iff_val_le_one
tfae_have 1 ↔ 3; · apply isEquiv_iff_val_eq_one
tfae_have 1 ↔ 4; · apply isEquiv_iff_val_lt_one
tfae_have 1 ↔ 5; · apply isEquiv_iff_val_sub_one_lt_one
tfae_finish
end
section Supp
variable [CommRing R]
variable [LinearOrderedCommMonoidWithZero Γ₀] [LinearOrderedCommMonoidWithZero Γ'₀]
variable (v : Valuation R Γ₀)
/-- The support of a valuation `v : R → Γ₀` is the ideal of `R` where `v` vanishes. -/
def supp : Ideal R where
carrier := { x | v x = 0 }
zero_mem' := map_zero v
add_mem' {x y} hx hy := le_zero_iff.mp <|
calc
v (x + y) ≤ max (v x) (v y) := v.map_add x y
_ ≤ 0 := max_le (le_zero_iff.mpr hx) (le_zero_iff.mpr hy)
smul_mem' c x hx :=
calc
v (c * x) = v c * v x := map_mul v c x
_ = v c * 0 := congr_arg _ hx
_ = 0 := mul_zero _
@[simp]
theorem mem_supp_iff (x : R) : x ∈ supp v ↔ v x = 0 :=
Iff.rfl
/-- The support of a valuation is a prime ideal. -/
instance [Nontrivial Γ₀] [NoZeroDivisors Γ₀] : Ideal.IsPrime (supp v) :=
⟨fun h =>
one_ne_zero (α := Γ₀) <|
calc
1 = v 1 := v.map_one.symm
_ = 0 := by rw [← mem_supp_iff, h]; exact Submodule.mem_top,
fun {x y} hxy => by
simp only [mem_supp_iff] at hxy ⊢
rw [v.map_mul x y] at hxy
exact eq_zero_or_eq_zero_of_mul_eq_zero hxy⟩
theorem map_add_supp (a : R) {s : R} (h : s ∈ supp v) : v (a + s) = v a := by
have aux : ∀ a s, v s = 0 → v (a + s) ≤ v a := by
intro a' s' h'
refine le_trans (v.map_add a' s') (max_le le_rfl ?_)
simp [h']
apply le_antisymm (aux a s h)
calc
v a = v (a + s + -s) := by simp
_ ≤ v (a + s) := aux (a + s) (-s) (by rwa [← Ideal.neg_mem_iff] at h)
theorem comap_supp {S : Type*} [CommRing S] (f : S →+* R) :
supp (v.comap f) = Ideal.comap f v.supp :=
Ideal.ext fun x => by rw [mem_supp_iff, Ideal.mem_comap, mem_supp_iff, comap_apply]
end Supp
-- end of section
end Valuation
section AddMonoid
variable (R) [Ring R] (Γ₀ : Type*) [LinearOrderedAddCommMonoidWithTop Γ₀]
/-- The type of `Γ₀`-valued additive valuations on `R`. -/
-- porting note (#5171): removed @[nolint has_nonempty_instance]
def AddValuation :=
Valuation R (Multiplicative Γ₀ᵒᵈ)
end AddMonoid
namespace AddValuation
variable {Γ₀ : Type*} {Γ'₀ : Type*}
section Basic
section Monoid
/-- A valuation is coerced to the underlying function `R → Γ₀`. -/
instance (R) (Γ₀) [Ring R] [LinearOrderedAddCommMonoidWithTop Γ₀] :
FunLike (AddValuation R Γ₀) R Γ₀ where
coe v := v.toMonoidWithZeroHom.toFun
coe_injective' f g := by cases f; cases g; simp (config := {contextual := true})
variable [Ring R] [LinearOrderedAddCommMonoidWithTop Γ₀] [LinearOrderedAddCommMonoidWithTop Γ'₀]
(v : AddValuation R Γ₀) {x y z : R}
section
variable (f : R → Γ₀) (h0 : f 0 = ⊤) (h1 : f 1 = 0)
variable (hadd : ∀ x y, min (f x) (f y) ≤ f (x + y)) (hmul : ∀ x y, f (x * y) = f x + f y)
/-- An alternate constructor of `AddValuation`, that doesn't reference `Multiplicative Γ₀ᵒᵈ` -/
def of : AddValuation R Γ₀ where
toFun := f
map_one' := h1
map_zero' := h0
map_add_le_max' := hadd
map_mul' := hmul
variable {h0} {h1} {hadd} {hmul} {r : R}
@[simp]
theorem of_apply : (of f h0 h1 hadd hmul) r = f r := rfl
/-- The `Valuation` associated to an `AddValuation` (useful if the latter is constructed using
`AddValuation.of`). -/
def valuation : Valuation R (Multiplicative Γ₀ᵒᵈ) :=
v
@[simp]
theorem valuation_apply (r : R) : v.valuation r = Multiplicative.ofAdd (OrderDual.toDual (v r)) :=
rfl
end
-- Porting note: Lean get confused about namespaces and instances below
@[simp]
theorem map_zero : v 0 = (⊤ : Γ₀) :=
Valuation.map_zero v
@[simp]
theorem map_one : v 1 = (0 : Γ₀) :=
Valuation.map_one v
/- Porting note: helper wrapper to coerce `v` to the correct function type -/
/-- A helper function for Lean to inferring types correctly -/
def asFun : R → Γ₀ := v
@[simp]
theorem map_mul : ∀ (x y : R), v (x * y) = v x + v y :=
Valuation.map_mul v
-- Porting note: LHS simplified so created map_add' and removed simp tag
theorem map_add : ∀ (x y : R), min (v x) (v y) ≤ v (x + y) :=
Valuation.map_add v
@[simp]
theorem map_add' : ∀ (x y : R), v x ≤ v (x + y) ∨ v y ≤ v (x + y) := by
intro x y
rw [← @min_le_iff _ _ (v x) (v y) (v (x+y)), ← ge_iff_le]
apply map_add
theorem map_le_add {x y : R} {g : Γ₀} (hx : g ≤ v x) (hy : g ≤ v y) : g ≤ v (x + y) :=
Valuation.map_add_le v hx hy
theorem map_lt_add {x y : R} {g : Γ₀} (hx : g < v x) (hy : g < v y) : g < v (x + y) :=
Valuation.map_add_lt v hx hy
theorem map_le_sum {ι : Type*} {s : Finset ι} {f : ι → R} {g : Γ₀} (hf : ∀ i ∈ s, g ≤ v (f i)) :
g ≤ v (∑ i ∈ s, f i) :=
v.map_sum_le hf
theorem map_lt_sum {ι : Type*} {s : Finset ι} {f : ι → R} {g : Γ₀} (hg : g ≠ ⊤)
(hf : ∀ i ∈ s, g < v (f i)) : g < v (∑ i ∈ s, f i) :=
v.map_sum_lt hg hf
theorem map_lt_sum' {ι : Type*} {s : Finset ι} {f : ι → R} {g : Γ₀} (hg : g < ⊤)
(hf : ∀ i ∈ s, g < v (f i)) : g < v (∑ i ∈ s, f i) :=
v.map_sum_lt' hg hf
@[simp]
theorem map_pow : ∀ (x : R) (n : ℕ), v (x ^ n) = n • (v x) :=
Valuation.map_pow v
@[ext]
theorem ext {v₁ v₂ : AddValuation R Γ₀} (h : ∀ r, v₁ r = v₂ r) : v₁ = v₂ :=
Valuation.ext h
-- The following definition is not an instance, because we have more than one `v` on a given `R`.
-- In addition, type class inference would not be able to infer `v`.
/-- A valuation gives a preorder on the underlying ring. -/
def toPreorder : Preorder R :=
Preorder.lift v
/-- If `v` is an additive valuation on a division ring then `v(x) = ⊤` iff `x = 0`. -/
@[simp]
theorem top_iff [Nontrivial Γ₀] (v : AddValuation K Γ₀) {x : K} : v x = (⊤ : Γ₀) ↔ x = 0 :=
v.zero_iff
theorem ne_top_iff [Nontrivial Γ₀] (v : AddValuation K Γ₀) {x : K} : v x ≠ (⊤ : Γ₀) ↔ x ≠ 0 :=
v.ne_zero_iff
/-- A ring homomorphism `S → R` induces a map `AddValuation R Γ₀ → AddValuation S Γ₀`. -/
def comap {S : Type*} [Ring S] (f : S →+* R) (v : AddValuation R Γ₀) : AddValuation S Γ₀ :=
Valuation.comap f v
@[simp]
theorem comap_id : v.comap (RingHom.id R) = v :=
Valuation.comap_id v
theorem comap_comp {S₁ : Type*} {S₂ : Type*} [Ring S₁] [Ring S₂] (f : S₁ →+* S₂) (g : S₂ →+* R) :
v.comap (g.comp f) = (v.comap g).comap f :=
Valuation.comap_comp v f g
/-- A `≤`-preserving, `⊤`-preserving group homomorphism `Γ₀ → Γ'₀` induces a map
`AddValuation R Γ₀ → AddValuation R Γ'₀`.
-/
def map (f : Γ₀ →+ Γ'₀) (ht : f ⊤ = ⊤) (hf : Monotone f) (v : AddValuation R Γ₀) :
AddValuation R Γ'₀ :=
@Valuation.map R (Multiplicative Γ₀ᵒᵈ) (Multiplicative Γ'₀ᵒᵈ) _ _ _
{ toFun := f
map_mul' := f.map_add
map_one' := f.map_zero
map_zero' := ht } (fun _ _ h => hf h) v
/-- Two additive valuations on `R` are defined to be equivalent if they induce the same
preorder on `R`. -/
def IsEquiv (v₁ : AddValuation R Γ₀) (v₂ : AddValuation R Γ'₀) : Prop :=
Valuation.IsEquiv v₁ v₂
end Monoid
section Group
variable [LinearOrderedAddCommGroupWithTop Γ₀] [Ring R] (v : AddValuation R Γ₀) {x y z : R}
@[simp]
theorem map_inv (v : AddValuation K Γ₀) {x : K} : v x⁻¹ = - (v x) :=
map_inv₀ v.valuation x
@[simp]
theorem map_div (v : AddValuation K Γ₀) {x y : K} : v (x / y) = v x - v y :=
map_div₀ v.valuation x y
@[simp]
theorem map_neg (x : R) : v (-x) = v x :=
Valuation.map_neg v x
theorem map_sub_swap (x y : R) : v (x - y) = v (y - x) :=
Valuation.map_sub_swap v x y
theorem map_sub (x y : R) : min (v x) (v y) ≤ v (x - y) :=
Valuation.map_sub v x y
theorem map_le_sub {x y : R} {g : Γ₀} (hx : g ≤ v x) (hy : g ≤ v y) : g ≤ v (x - y) :=
Valuation.map_sub_le v hx hy
theorem map_add_of_distinct_val (h : v x ≠ v y) : v (x + y) = @Min.min Γ₀ _ (v x) (v y) :=
Valuation.map_add_of_distinct_val v h
theorem map_add_eq_of_lt_left {x y : R} (h : v x < v y) :
v (x + y) = v x := by
rw [map_add_of_distinct_val _ h.ne, min_eq_left h.le]
theorem map_add_eq_of_lt_right {x y : R} (hx : v y < v x) :
v (x + y) = v y := add_comm y x ▸ map_add_eq_of_lt_left v hx
theorem map_sub_eq_of_lt_left {x y : R} (hx : v x < v y) :
v (x - y) = v x := by
rw [sub_eq_add_neg]
apply map_add_eq_of_lt_left
rwa [map_neg]
theorem map_sub_eq_of_lt_right {x y : R} (hx : v y < v x) :
v (x - y) = v y := map_sub_swap v x y ▸ map_sub_eq_of_lt_left v hx
theorem map_eq_of_lt_sub (h : v x < v (y - x)) : v y = v x :=
Valuation.map_eq_of_sub_lt v h
end Group
end Basic
namespace IsEquiv
variable [LinearOrderedAddCommMonoidWithTop Γ₀] [LinearOrderedAddCommMonoidWithTop Γ'₀]
[Ring R]
{Γ''₀ : Type*} [LinearOrderedAddCommMonoidWithTop Γ''₀]
{v : AddValuation R Γ₀}
{v₁ : AddValuation R Γ₀} {v₂ : AddValuation R Γ'₀} {v₃ : AddValuation R Γ''₀}
@[refl]
theorem refl : v.IsEquiv v :=
Valuation.IsEquiv.refl
@[symm]
theorem symm (h : v₁.IsEquiv v₂) : v₂.IsEquiv v₁ :=
Valuation.IsEquiv.symm h
@[trans]
theorem trans (h₁₂ : v₁.IsEquiv v₂) (h₂₃ : v₂.IsEquiv v₃) : v₁.IsEquiv v₃ :=
Valuation.IsEquiv.trans h₁₂ h₂₃
theorem of_eq {v' : AddValuation R Γ₀} (h : v = v') : v.IsEquiv v' :=
Valuation.IsEquiv.of_eq h
theorem map {v' : AddValuation R Γ₀} (f : Γ₀ →+ Γ'₀) (ht : f ⊤ = ⊤) (hf : Monotone f)
(inf : Injective f) (h : v.IsEquiv v') : (v.map f ht hf).IsEquiv (v'.map f ht hf) :=
@Valuation.IsEquiv.map R (Multiplicative Γ₀ᵒᵈ) (Multiplicative Γ'₀ᵒᵈ) _ _ _ _ _
{ toFun := f
map_mul' := f.map_add
map_one' := f.map_zero
map_zero' := ht } (fun _x _y h => hf h) inf h
/-- `comap` preserves equivalence. -/
theorem comap {S : Type*} [Ring S] (f : S →+* R) (h : v₁.IsEquiv v₂) :
(v₁.comap f).IsEquiv (v₂.comap f) :=
Valuation.IsEquiv.comap f h
theorem val_eq (h : v₁.IsEquiv v₂) {r s : R} : v₁ r = v₁ s ↔ v₂ r = v₂ s :=
Valuation.IsEquiv.val_eq h
theorem ne_top (h : v₁.IsEquiv v₂) {r : R} : v₁ r ≠ (⊤ : Γ₀) ↔ v₂ r ≠ (⊤ : Γ'₀) :=
Valuation.IsEquiv.ne_zero h
end IsEquiv
section Supp
variable [LinearOrderedAddCommMonoidWithTop Γ₀] [LinearOrderedAddCommMonoidWithTop Γ'₀]
variable [CommRing R]
variable (v : AddValuation R Γ₀)
/-- The support of an additive valuation `v : R → Γ₀` is the ideal of `R` where `v x = ⊤` -/
def supp : Ideal R :=
Valuation.supp v
@[simp]
theorem mem_supp_iff (x : R) : x ∈ supp v ↔ v x = (⊤ : Γ₀) :=
Valuation.mem_supp_iff v x
theorem map_add_supp (a : R) {s : R} (h : s ∈ supp v) : v (a + s) = v a :=
Valuation.map_add_supp v a h
end Supp
-- end of section
end AddValuation
section ValuationNotation
/-- Notation for `WithZero (Multiplicative ℕ)` -/
scoped[DiscreteValuation] notation "ℕₘ₀" => WithZero (Multiplicative ℕ)
/-- Notation for `WithZero (Multiplicative ℤ)` -/
scoped[DiscreteValuation] notation "ℤₘ₀" => WithZero (Multiplicative ℤ)
end ValuationNotation
|
RingTheory\Valuation\ExtendToLocalization.lean | /-
Copyright (c) 2022 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz
-/
import Mathlib.RingTheory.Localization.AtPrime
import Mathlib.RingTheory.Valuation.Basic
/-!
# Extending valuations to a localization
We show that, given a valuation `v` taking values in a linearly ordered commutative *group*
with zero `Γ`, and a submonoid `S` of `v.supp.primeCompl`, the valuation `v` can be naturally
extended to the localization `S⁻¹A`.
-/
variable {A : Type*} [CommRing A] {Γ : Type*} [LinearOrderedCommGroupWithZero Γ]
(v : Valuation A Γ) {S : Submonoid A} (hS : S ≤ v.supp.primeCompl) (B : Type*) [CommRing B]
[Algebra A B] [IsLocalization S B]
/-- We can extend a valuation `v` on a ring to a localization at a submonoid of
the complement of `v.supp`. -/
noncomputable def Valuation.extendToLocalization : Valuation B Γ :=
let f := IsLocalization.toLocalizationMap S B
let h : ∀ s : S, IsUnit (v.1.toMonoidHom s) := fun s => isUnit_iff_ne_zero.2 (hS s.2)
{ f.lift h with
map_zero' := by convert f.lift_eq (P := Γ) _ 0 <;> simp [f]
map_add_le_max' := fun x y => by
obtain ⟨a, b, s, rfl, rfl⟩ : ∃ (a b : A) (s : S), f.mk' a s = x ∧ f.mk' b s = y := by
obtain ⟨a, s, rfl⟩ := f.mk'_surjective x
obtain ⟨b, t, rfl⟩ := f.mk'_surjective y
use a * t, b * s, s * t
constructor <;>
· rw [f.mk'_eq_iff_eq, Submonoid.coe_mul]
ring_nf
convert_to f.lift h (f.mk' (a + b) s) ≤ max (f.lift h _) (f.lift h _)
· refine congr_arg (f.lift h) (IsLocalization.eq_mk'_iff_mul_eq.2 ?_)
rw [add_mul, _root_.map_add]
iterate 2 erw [IsLocalization.mk'_spec]
iterate 3 rw [f.lift_mk']
rw [max_mul_mul_right]
apply mul_le_mul_right' (v.map_add a b) }
@[simp]
theorem Valuation.extendToLocalization_apply_map_apply (a : A) :
v.extendToLocalization hS B (algebraMap A B a) = v a :=
Submonoid.LocalizationMap.lift_eq _ _ a
|
RingTheory\Valuation\Integers.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.RingTheory.Valuation.Basic
/-!
# Ring of integers under a given valuation
The elements with valuation less than or equal to 1.
TODO: Define characteristic predicate.
-/
universe u v w
namespace Valuation
section Ring
variable {R : Type u} {Γ₀ : Type v} [Ring R] [LinearOrderedCommGroupWithZero Γ₀]
variable (v : Valuation R Γ₀)
/-- The ring of integers under a given valuation is the subring of elements with valuation ≤ 1. -/
def integer : Subring R where
carrier := { x | v x ≤ 1 }
one_mem' := le_of_eq v.map_one
mul_mem' {x y} hx hy := by simp only [Set.mem_setOf_eq, _root_.map_mul, mul_le_one' hx hy]
zero_mem' := by simp only [Set.mem_setOf_eq, _root_.map_zero, zero_le']
add_mem' {x y} hx hy := le_trans (v.map_add x y) (max_le hx hy)
neg_mem' {x} hx := by simp only [Set.mem_setOf_eq] at hx; simpa only [Set.mem_setOf_eq, map_neg]
lemma mem_integer_iff (r : R) : r ∈ v.integer ↔ v r ≤ 1 := by rfl
end Ring
section CommRing
variable {R : Type u} {Γ₀ : Type v} [CommRing R] [LinearOrderedCommGroupWithZero Γ₀]
variable (v : Valuation R Γ₀)
variable (O : Type w) [CommRing O] [Algebra O R]
/-- Given a valuation v : R → Γ₀ and a ring homomorphism O →+* R, we say that O is the integers of v
if f is injective, and its range is exactly `v.integer`. -/
structure Integers : Prop where
hom_inj : Function.Injective (algebraMap O R)
map_le_one : ∀ x, v (algebraMap O R x) ≤ 1
exists_of_le_one : ∀ ⦃r⦄, v r ≤ 1 → ∃ x, algebraMap O R x = r
-- typeclass shortcut
instance : Algebra v.integer R :=
Algebra.ofSubring v.integer
theorem integer.integers : v.Integers v.integer :=
{ hom_inj := Subtype.coe_injective
map_le_one := fun r => r.2
exists_of_le_one := fun r hr => ⟨⟨r, hr⟩, rfl⟩ }
namespace Integers
variable {v O}
theorem one_of_isUnit' {x : O} (hx : IsUnit x) (H : ∀ x, v (algebraMap O R x) ≤ 1) :
v (algebraMap O R x) = 1 :=
let ⟨u, hu⟩ := hx
le_antisymm (H _) <| by
rw [← v.map_one, ← (algebraMap O R).map_one, ← u.mul_inv, ← mul_one (v (algebraMap O R x)), hu,
(algebraMap O R).map_mul, v.map_mul]
exact mul_le_mul_left' (H (u⁻¹ : Units O)) _
theorem one_of_isUnit (hv : Integers v O) {x : O} (hx : IsUnit x) : v (algebraMap O R x) = 1 :=
one_of_isUnit' hx hv.map_le_one
/--
Let `O` be the integers of the valuation `v` on some commutative ring `R`. For every element `x` in
`O`, `x` is a unit in `O` if and only if the image of `x` in `R` is a unit and has valuation 1.
-/
theorem isUnit_of_one (hv : Integers v O) {x : O} (hx : IsUnit (algebraMap O R x))
(hvx : v (algebraMap O R x) = 1) : IsUnit x :=
let ⟨u, hu⟩ := hx
have h1 : v u ≤ 1 := hu.symm ▸ hv.2 x
have h2 : v (u⁻¹ : Rˣ) ≤ 1 := by
rw [← one_mul (v _), ← hvx, ← v.map_mul, ← hu, u.mul_inv, hu, hvx, v.map_one]
let ⟨r1, hr1⟩ := hv.3 h1
let ⟨r2, hr2⟩ := hv.3 h2
⟨⟨r1, r2, hv.1 <| by rw [RingHom.map_mul, RingHom.map_one, hr1, hr2, Units.mul_inv],
hv.1 <| by rw [RingHom.map_mul, RingHom.map_one, hr1, hr2, Units.inv_mul]⟩,
hv.1 <| hr1.trans hu⟩
theorem le_of_dvd (hv : Integers v O) {x y : O} (h : x ∣ y) :
v (algebraMap O R y) ≤ v (algebraMap O R x) := by
let ⟨z, hz⟩ := h
rw [← mul_one (v (algebraMap O R x)), hz, RingHom.map_mul, v.map_mul]
exact mul_le_mul_left' (hv.2 z) _
end Integers
end CommRing
section Field
variable {F : Type u} {Γ₀ : Type v} [Field F] [LinearOrderedCommGroupWithZero Γ₀]
variable {v : Valuation F Γ₀} {O : Type w} [CommRing O] [Algebra O F]
namespace Integers
theorem dvd_of_le (hv : Integers v O) {x y : O}
(h : v (algebraMap O F x) ≤ v (algebraMap O F y)) : y ∣ x :=
by_cases
(fun hy : algebraMap O F y = 0 =>
have hx : x = 0 :=
hv.1 <|
(algebraMap O F).map_zero.symm ▸ (v.zero_iff.1 <| le_zero_iff.1 (v.map_zero ▸ hy ▸ h))
hx.symm ▸ dvd_zero y)
fun hy : algebraMap O F y ≠ 0 =>
have : v ((algebraMap O F y)⁻¹ * algebraMap O F x) ≤ 1 := by
rw [← v.map_one, ← inv_mul_cancel hy, v.map_mul, v.map_mul]
exact mul_le_mul_left' h _
let ⟨z, hz⟩ := hv.3 this
⟨z, hv.1 <| ((algebraMap O F).map_mul y z).symm ▸ hz.symm ▸ (mul_inv_cancel_left₀ hy _).symm⟩
theorem dvd_iff_le (hv : Integers v O) {x y : O} :
x ∣ y ↔ v (algebraMap O F y) ≤ v (algebraMap O F x) :=
⟨hv.le_of_dvd, hv.dvd_of_le⟩
theorem le_iff_dvd (hv : Integers v O) {x y : O} :
v (algebraMap O F x) ≤ v (algebraMap O F y) ↔ y ∣ x :=
⟨hv.dvd_of_le, hv.le_of_dvd⟩
/--
This is the special case of `Valuation.Integers.isUnit_of_one` when the valuation is defined
over a field. Let `v` be a valuation on some field `F` and `O` be its integers. For every element
`x` in `O`, `x` is a unit in `O` if and only if the image of `x` in `F` has valuation 1.
-/
theorem isUnit_of_one' (hv : Integers v O) {x : O} (hvx : v (algebraMap O F x) = 1) : IsUnit x := by
refine isUnit_of_one hv (IsUnit.mk0 _ ?_) hvx
simp only [← v.ne_zero_iff, hvx, ne_eq, one_ne_zero, not_false_eq_true]
theorem eq_algebraMap_or_inv_eq_algebraMap (hv : Integers v O) (x : F) :
∃ a : O, x = algebraMap O F a ∨ x⁻¹ = algebraMap O F a := by
rcases val_le_one_or_val_inv_le_one v x with h | h <;>
obtain ⟨a, ha⟩ := exists_of_le_one hv h
exacts [⟨a, Or.inl ha.symm⟩, ⟨a, Or.inr ha.symm⟩]
end Integers
end Field
end Valuation
|
RingTheory\Valuation\Integral.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.RingTheory.IntegralClosure.IntegrallyClosed
import Mathlib.RingTheory.Valuation.Integers
/-!
# Integral elements over the ring of integers of a valuation
The ring of integers is integrally closed inside the original ring.
-/
universe u v w
namespace Valuation
namespace Integers
section CommRing
variable {R : Type u} {Γ₀ : Type v} [CommRing R] [LinearOrderedCommGroupWithZero Γ₀]
variable {v : Valuation R Γ₀} {O : Type w} [CommRing O] [Algebra O R] (hv : Integers v O)
open Polynomial
theorem mem_of_integral {x : R} (hx : IsIntegral O x) : x ∈ v.integer :=
let ⟨p, hpm, hpx⟩ := hx
le_of_not_lt fun hvx : 1 < v x => by
rw [hpm.as_sum, eval₂_add, eval₂_pow, eval₂_X, eval₂_finset_sum, add_eq_zero_iff_eq_neg] at hpx
replace hpx := congr_arg v hpx; refine ne_of_gt ?_ hpx
rw [v.map_neg, v.map_pow]
refine v.map_sum_lt' (zero_lt_one.trans_le (one_le_pow_of_one_le' hvx.le _)) fun i hi => ?_
rw [eval₂_mul, eval₂_pow, eval₂_C, eval₂_X, v.map_mul, v.map_pow, ←
one_mul (v x ^ p.natDegree)]
cases' (hv.2 <| p.coeff i).lt_or_eq with hvpi hvpi
· exact mul_lt_mul₀ hvpi (pow_lt_pow_right₀ hvx <| Finset.mem_range.1 hi)
· erw [hvpi]; rw [one_mul, one_mul]; exact pow_lt_pow_right₀ hvx (Finset.mem_range.1 hi)
protected theorem integralClosure : integralClosure O R = ⊥ :=
bot_unique fun _ hr =>
let ⟨x, hx⟩ := hv.3 (hv.mem_of_integral hr)
Algebra.mem_bot.2 ⟨x, hx⟩
end CommRing
section FractionField
variable {K : Type u} {Γ₀ : Type v} [Field K] [LinearOrderedCommGroupWithZero Γ₀]
variable {v : Valuation K Γ₀} {O : Type w} [CommRing O] [IsDomain O]
variable [Algebra O K] [IsFractionRing O K]
variable (hv : Integers v O)
theorem integrallyClosed : IsIntegrallyClosed O :=
(IsIntegrallyClosed.integralClosure_eq_bot_iff K).mp (Valuation.Integers.integralClosure hv)
end FractionField
end Integers
end Valuation
|
RingTheory\Valuation\PrimeMultiplicity.lean | /-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Chris Hughes
-/
import Mathlib.RingTheory.Multiplicity
import Mathlib.RingTheory.Valuation.Basic
/-!
# `multiplicity` of a prime in an integral domain as an additive valuation
-/
variable {R : Type*} [CommRing R] [IsDomain R] {p : R} [DecidableRel (Dvd.dvd : R → R → Prop)]
/-- `multiplicity` of a prime in an integral domain as an additive valuation to `PartENat`. -/
noncomputable def multiplicity.addValuation (hp : Prime p) : AddValuation R PartENat :=
AddValuation.of (multiplicity p) (multiplicity.zero _) (one_right hp.not_unit)
(fun _ _ => min_le_multiplicity_add) fun _ _ => multiplicity.mul hp
@[simp]
theorem multiplicity.addValuation_apply {hp : Prime p} {r : R} :
addValuation hp r = multiplicity p r :=
rfl
|
RingTheory\Valuation\Quotient.lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Johan Commelin, Patrick Massot
-/
import Mathlib.RingTheory.Valuation.Basic
import Mathlib.RingTheory.Ideal.QuotientOperations
/-!
# The valuation on a quotient ring
The support of a valuation `v : Valuation R Γ₀` is `supp v`. If `J` is an ideal of `R`
with `h : J ⊆ supp v` then the induced valuation
on `R / J` = `Ideal.Quotient J` is `onQuot v h`.
-/
namespace Valuation
variable {R Γ₀ : Type*} [CommRing R] [LinearOrderedCommMonoidWithZero Γ₀]
variable (v : Valuation R Γ₀)
/-- If `hJ : J ⊆ supp v` then `onQuotVal hJ` is the induced function on `R / J` as a function.
Note: it's just the function; the valuation is `onQuot hJ`. -/
def onQuotVal {J : Ideal R} (hJ : J ≤ supp v) : R ⧸ J → Γ₀ := fun q =>
Quotient.liftOn' q v fun a b h =>
calc
v a = v (b + -(-a + b)) := by simp
_ = v b :=
v.map_add_supp b <| (Ideal.neg_mem_iff _).2 <| hJ <| QuotientAddGroup.leftRel_apply.mp h
/-- The extension of valuation `v` on `R` to valuation on `R / J` if `J ⊆ supp v`. -/
def onQuot {J : Ideal R} (hJ : J ≤ supp v) : Valuation (R ⧸ J) Γ₀ where
toFun := v.onQuotVal hJ
map_zero' := v.map_zero
map_one' := v.map_one
map_mul' xbar ybar := Quotient.ind₂' v.map_mul xbar ybar
map_add_le_max' xbar ybar := Quotient.ind₂' v.map_add xbar ybar
@[simp]
theorem onQuot_comap_eq {J : Ideal R} (hJ : J ≤ supp v) :
(v.onQuot hJ).comap (Ideal.Quotient.mk J) = v :=
ext fun _ => rfl
theorem self_le_supp_comap (J : Ideal R) (v : Valuation (R ⧸ J) Γ₀) :
J ≤ (v.comap (Ideal.Quotient.mk J)).supp := by
rw [comap_supp, ← Ideal.map_le_iff_le_comap]
simp
@[simp]
theorem comap_onQuot_eq (J : Ideal R) (v : Valuation (R ⧸ J) Γ₀) :
(v.comap (Ideal.Quotient.mk J)).onQuot (v.self_le_supp_comap J) = v :=
ext <| by
rintro ⟨x⟩
rfl
/-- The quotient valuation on `R / J` has support `(supp v) / J` if `J ⊆ supp v`. -/
theorem supp_quot {J : Ideal R} (hJ : J ≤ supp v) :
supp (v.onQuot hJ) = (supp v).map (Ideal.Quotient.mk J) := by
apply le_antisymm
· rintro ⟨x⟩ hx
apply Ideal.subset_span
exact ⟨x, hx, rfl⟩
· rw [Ideal.map_le_iff_le_comap]
intro x hx
exact hx
theorem supp_quot_supp : supp (v.onQuot le_rfl) = 0 := by
rw [supp_quot]
exact Ideal.map_quotient_self _
end Valuation
namespace AddValuation
variable {R Γ₀ : Type*}
variable [CommRing R] [LinearOrderedAddCommMonoidWithTop Γ₀]
variable (v : AddValuation R Γ₀)
-- attribute [local reducible] AddValuation -- Porting note: reducible not supported
/-- If `hJ : J ⊆ supp v` then `onQuotVal hJ` is the induced function on `R / J` as a function.
Note: it's just the function; the valuation is `onQuot hJ`. -/
def onQuotVal {J : Ideal R} (hJ : J ≤ supp v) : R ⧸ J → Γ₀ :=
Valuation.onQuotVal v hJ
/-- The extension of valuation `v` on `R` to valuation on `R / J` if `J ⊆ supp v`. -/
def onQuot {J : Ideal R} (hJ : J ≤ supp v) : AddValuation (R ⧸ J) Γ₀ :=
Valuation.onQuot v hJ
@[simp]
theorem onQuot_comap_eq {J : Ideal R} (hJ : J ≤ supp v) :
(v.onQuot hJ).comap (Ideal.Quotient.mk J) = v :=
Valuation.onQuot_comap_eq v hJ
theorem comap_supp {S : Type*} [CommRing S] (f : S →+* R) :
supp (v.comap f) = Ideal.comap f v.supp :=
Valuation.comap_supp v f
theorem self_le_supp_comap (J : Ideal R) (v : AddValuation (R ⧸ J) Γ₀) :
J ≤ (v.comap (Ideal.Quotient.mk J)).supp :=
Valuation.self_le_supp_comap J v
@[simp]
theorem comap_onQuot_eq (J : Ideal R) (v : AddValuation (R ⧸ J) Γ₀) :
(v.comap (Ideal.Quotient.mk J)).onQuot (v.self_le_supp_comap J) = v :=
Valuation.comap_onQuot_eq J v
/-- The quotient valuation on `R / J` has support `(supp v) / J` if `J ⊆ supp v`. -/
theorem supp_quot {J : Ideal R} (hJ : J ≤ supp v) :
supp (v.onQuot hJ) = (supp v).map (Ideal.Quotient.mk J) :=
Valuation.supp_quot v hJ
theorem supp_quot_supp : supp ((Valuation.onQuot v) le_rfl) = 0 :=
Valuation.supp_quot_supp v
end AddValuation
|
RingTheory\Valuation\RamificationGroup.lean | /-
Copyright (c) 2022 Michail Karatarakis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michail Karatarakis
-/
import Mathlib.RingTheory.LocalRing.ResidueField.Basic
import Mathlib.RingTheory.Valuation.ValuationSubring
/-!
# Ramification groups
The decomposition subgroup and inertia subgroups.
TODO: Define higher ramification groups in lower numbering
-/
namespace ValuationSubring
open scoped Pointwise
variable (K : Type*) {L : Type*} [Field K] [Field L] [Algebra K L]
/-- The decomposition subgroup defined as the stabilizer of the action
on the type of all valuation subrings of the field. -/
abbrev decompositionSubgroup (A : ValuationSubring L) : Subgroup (L ≃ₐ[K] L) :=
MulAction.stabilizer (L ≃ₐ[K] L) A
/-- The valuation subring `A` (considered as a subset of `L`)
is stable under the action of the decomposition group. -/
def subMulAction (A : ValuationSubring L) : SubMulAction (A.decompositionSubgroup K) L where
carrier := A
smul_mem' g _ h := Set.mem_of_mem_of_subset (Set.smul_mem_smul_set h) g.prop.le
/-- The multiplicative action of the decomposition subgroup on `A`. -/
instance decompositionSubgroupMulSemiringAction (A : ValuationSubring L) :
MulSemiringAction (A.decompositionSubgroup K) A :=
{ SubMulAction.mulAction (A.subMulAction K) with
smul_add := fun g k l => Subtype.ext <| smul_add (A := L) g k l
smul_zero := fun g => Subtype.ext <| smul_zero g
smul_one := fun g => Subtype.ext <| smul_one g
smul_mul := fun g k l => Subtype.ext <| smul_mul' (A := L) g k l }
/-- The inertia subgroup defined as the kernel of the group homomorphism from
the decomposition subgroup to the group of automorphisms of the residue field of `A`. -/
def inertiaSubgroup (A : ValuationSubring L) : Subgroup (A.decompositionSubgroup K) :=
MonoidHom.ker <|
MulSemiringAction.toRingAut (A.decompositionSubgroup K) (LocalRing.ResidueField A)
end ValuationSubring
|
RingTheory\Valuation\RankOne.lean | /-
Copyright (c) 2024 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.Data.NNReal.Basic
import Mathlib.RingTheory.Valuation.Basic
/-!
# Rank one valuations
We define rank one valuations.
## Main Definitions
* `RankOne` : A valuation `v` has rank one if it is nontrivial and its image is contained in `ℝ≥0`.
Note that this class contains the data of the inclusion of the codomain of `v` into `ℝ≥0`.
## Tags
valuation, rank one
-/
noncomputable section
open Function Multiplicative
open scoped NNReal
variable {R : Type*} [Ring R] {Γ₀ : Type*} [LinearOrderedCommGroupWithZero Γ₀]
namespace Valuation
/-- A valuation has rank one if it is nontrivial and its image is contained in `ℝ≥0`.
Note that this class includes the data of an inclusion morphism `Γ₀ → ℝ≥0`. -/
class RankOne (v : Valuation R Γ₀) where
/-- The inclusion morphism from `Γ₀` to `ℝ≥0`. -/
hom : Γ₀ →*₀ ℝ≥0
strictMono' : StrictMono hom
nontrivial' : ∃ r : R, v r ≠ 0 ∧ v r ≠ 1
namespace RankOne
variable (v : Valuation R Γ₀) [RankOne v]
lemma strictMono : StrictMono (hom v) := strictMono'
lemma nontrivial : ∃ r : R, v r ≠ 0 ∧ v r ≠ 1 := nontrivial'
/-- If `v` is a rank one valuation and `x : Γ₀` has image `0` under `RankOne.hom v`, then
`x = 0`. -/
theorem zero_of_hom_zero {x : Γ₀} (hx : hom v x = 0) : x = 0 := by
refine (eq_of_le_of_not_lt (zero_le' (a := x)) fun h_lt ↦ ?_).symm
have hs := strictMono v h_lt
rw [_root_.map_zero, hx] at hs
exact hs.false
/-- If `v` is a rank one valuation, then`x : Γ₀` has image `0` under `RankOne.hom v` if and
only if `x = 0`. -/
theorem hom_eq_zero_iff {x : Γ₀} : RankOne.hom v x = 0 ↔ x = 0 :=
⟨fun h ↦ zero_of_hom_zero v h, fun h ↦ by rw [h, _root_.map_zero]⟩
/-- A nontrivial unit of `Γ₀`, given that there exists a rank one `v : Valuation R Γ₀`. -/
def unit : Γ₀ˣ :=
Units.mk0 (v (nontrivial v).choose) ((nontrivial v).choose_spec).1
/-- A proof that `RankOne.unit v ≠ 1`. -/
theorem unit_ne_one : unit v ≠ 1 := by
rw [Ne, ← Units.eq_iff, Units.val_one]
exact ((nontrivial v).choose_spec ).2
end RankOne
end Valuation
|
RingTheory\Valuation\ValuationRing.lean | /-
Copyright (c) 2022 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz
-/
import Mathlib.RingTheory.Valuation.Integers
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.RingTheory.Localization.Integer
import Mathlib.RingTheory.DiscreteValuationRing.Basic
import Mathlib.RingTheory.Bezout
import Mathlib.Tactic.FieldSimp
/-!
# Valuation Rings
A valuation ring is a domain such that for every pair of elements `a b`, either `a` divides
`b` or vice-versa.
Any valuation ring induces a natural valuation on its fraction field, as we show in this file.
Namely, given the following instances:
`[CommRing A] [IsDomain A] [ValuationRing A] [Field K] [Algebra A K] [IsFractionRing A K]`,
there is a natural valuation `Valuation A K` on `K` with values in `value_group A K` where
the image of `A` under `algebraMap A K` agrees with `(Valuation A K).integer`.
We also provide the equivalence of the following notions for a domain `R` in `ValuationRing.TFAE`.
1. `R` is a valuation ring.
2. For each `x : FractionRing K`, either `x` or `x⁻¹` is in `R`.
3. "divides" is a total relation on the elements of `R`.
4. "contains" is a total relation on the ideals of `R`.
5. `R` is a local bezout domain.
We also show that, given a valuation `v` on a field `K`, the ring of valuation integers is a
valuation ring and `K` is the fraction field of this ring.
-/
universe u v w
/-- An integral domain is called a `ValuationRing` provided that for any pair
of elements `a b : A`, either `a` divides `b` or vice versa. -/
class ValuationRing (A : Type u) [CommRing A] [IsDomain A] : Prop where
cond' : ∀ a b : A, ∃ c : A, a * c = b ∨ b * c = a
-- Porting note: this lemma is needed since infer kinds are unsupported in Lean 4
lemma ValuationRing.cond {A : Type u} [CommRing A] [IsDomain A] [ValuationRing A] (a b : A) :
∃ c : A, a * c = b ∨ b * c = a := @ValuationRing.cond' A _ _ _ _ _
namespace ValuationRing
section
variable (A : Type u) [CommRing A]
variable (K : Type v) [Field K] [Algebra A K]
/-- The value group of the valuation ring `A`. Note: this is actually a group with zero. -/
def ValueGroup : Type v := Quotient (MulAction.orbitRel Aˣ K)
instance : Inhabited (ValueGroup A K) := ⟨Quotient.mk'' 0⟩
instance : LE (ValueGroup A K) :=
LE.mk fun x y =>
Quotient.liftOn₂' x y (fun a b => ∃ c : A, c • b = a)
(by
rintro _ _ a b ⟨c, rfl⟩ ⟨d, rfl⟩; ext
constructor
· rintro ⟨e, he⟩; use (c⁻¹ : Aˣ) * e * d
apply_fun fun t => c⁻¹ • t at he
simpa [mul_smul] using he
· rintro ⟨e, he⟩; dsimp
use c * e * (d⁻¹ : Aˣ)
simp_rw [Units.smul_def, ← he, mul_smul]
rw [← mul_smul _ _ b, Units.inv_mul, one_smul])
instance : Zero (ValueGroup A K) := ⟨Quotient.mk'' 0⟩
instance : One (ValueGroup A K) := ⟨Quotient.mk'' 1⟩
instance : Mul (ValueGroup A K) :=
Mul.mk fun x y =>
Quotient.liftOn₂' x y (fun a b => Quotient.mk'' <| a * b)
(by
rintro _ _ a b ⟨c, rfl⟩ ⟨d, rfl⟩
apply Quotient.sound'
dsimp
use c * d
simp only [mul_smul, Algebra.smul_def, Units.smul_def, RingHom.map_mul, Units.val_mul]
ring)
instance : Inv (ValueGroup A K) :=
Inv.mk fun x =>
Quotient.liftOn' x (fun a => Quotient.mk'' a⁻¹)
(by
rintro _ a ⟨b, rfl⟩
apply Quotient.sound'
use b⁻¹
dsimp
rw [Units.smul_def, Units.smul_def, Algebra.smul_def, Algebra.smul_def, mul_inv,
map_units_inv])
variable [IsDomain A] [ValuationRing A] [IsFractionRing A K]
protected theorem le_total (a b : ValueGroup A K) : a ≤ b ∨ b ≤ a := by
rcases a with ⟨a⟩; rcases b with ⟨b⟩
obtain ⟨xa, ya, hya, rfl⟩ : ∃ a b : A, _ := IsFractionRing.div_surjective a
obtain ⟨xb, yb, hyb, rfl⟩ : ∃ a b : A, _ := IsFractionRing.div_surjective b
have : (algebraMap A K) ya ≠ 0 := IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors hya
have : (algebraMap A K) yb ≠ 0 := IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors hyb
obtain ⟨c, h | h⟩ := ValuationRing.cond (xa * yb) (xb * ya)
· right
use c
rw [Algebra.smul_def]
field_simp
simp only [← RingHom.map_mul, ← h]; congr 1; ring
· left
use c
rw [Algebra.smul_def]
field_simp
simp only [← RingHom.map_mul, ← h]; congr 1; ring
-- Porting note: it is much faster to split the instance `LinearOrderedCommGroupWithZero`
-- into two parts
noncomputable instance linearOrder : LinearOrder (ValueGroup A K) where
le_refl := by rintro ⟨⟩; use 1; rw [one_smul]
le_trans := by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ ⟨e, rfl⟩ ⟨f, rfl⟩; use e * f; rw [mul_smul]
le_antisymm := by
rintro ⟨a⟩ ⟨b⟩ ⟨e, rfl⟩ ⟨f, hf⟩
by_cases hb : b = 0; · simp [hb]
have : IsUnit e := by
apply isUnit_of_dvd_one
use f
rw [mul_comm]
rw [← mul_smul, Algebra.smul_def] at hf
nth_rw 2 [← one_mul b] at hf
rw [← (algebraMap A K).map_one] at hf
exact IsFractionRing.injective _ _ (mul_right_cancel₀ hb hf).symm
apply Quotient.sound'
exact ⟨this.unit, rfl⟩
le_total := ValuationRing.le_total _ _
decidableLE := by classical infer_instance
noncomputable instance linearOrderedCommGroupWithZero :
LinearOrderedCommGroupWithZero (ValueGroup A K) :=
{ linearOrder .. with
mul_assoc := by rintro ⟨a⟩ ⟨b⟩ ⟨c⟩; apply Quotient.sound'; rw [mul_assoc]; apply Setoid.refl'
one_mul := by rintro ⟨a⟩; apply Quotient.sound'; rw [one_mul]; apply Setoid.refl'
mul_one := by rintro ⟨a⟩; apply Quotient.sound'; rw [mul_one]; apply Setoid.refl'
mul_comm := by rintro ⟨a⟩ ⟨b⟩; apply Quotient.sound'; rw [mul_comm]; apply Setoid.refl'
mul_le_mul_left := by
rintro ⟨a⟩ ⟨b⟩ ⟨c, rfl⟩ ⟨d⟩
use c; simp only [Algebra.smul_def]; ring
zero_mul := by rintro ⟨a⟩; apply Quotient.sound'; rw [zero_mul]; apply Setoid.refl'
mul_zero := by rintro ⟨a⟩; apply Quotient.sound'; rw [mul_zero]; apply Setoid.refl'
zero_le_one := ⟨0, by rw [zero_smul]⟩
exists_pair_ne := by
use 0, 1
intro c; obtain ⟨d, hd⟩ := Quotient.exact' c
apply_fun fun t => d⁻¹ • t at hd
simp only [inv_smul_smul, smul_zero, one_ne_zero] at hd
inv_zero := by apply Quotient.sound'; rw [inv_zero]; apply Setoid.refl'
mul_inv_cancel := by
rintro ⟨a⟩ ha
apply Quotient.sound'
use 1
simp only [one_smul, ne_eq]
apply (mul_inv_cancel _).symm
contrapose ha
simp only [Classical.not_not] at ha ⊢
rw [ha]
rfl }
/-- Any valuation ring induces a valuation on its fraction field. -/
def valuation : Valuation K (ValueGroup A K) where
toFun := Quotient.mk''
map_zero' := rfl
map_one' := rfl
map_mul' _ _ := rfl
map_add_le_max' := by
intro a b
obtain ⟨xa, ya, hya, rfl⟩ : ∃ a b : A, _ := IsFractionRing.div_surjective a
obtain ⟨xb, yb, hyb, rfl⟩ : ∃ a b : A, _ := IsFractionRing.div_surjective b
have : (algebraMap A K) ya ≠ 0 := IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors hya
have : (algebraMap A K) yb ≠ 0 := IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors hyb
obtain ⟨c, h | h⟩ := ValuationRing.cond (xa * yb) (xb * ya)
· dsimp
apply le_trans _ (le_max_left _ _)
use c + 1
rw [Algebra.smul_def]
field_simp
simp only [← RingHom.map_mul, ← RingHom.map_add, ← (algebraMap A K).map_one, ← h]
congr 1; ring
· apply le_trans _ (le_max_right _ _)
use c + 1
rw [Algebra.smul_def]
field_simp
simp only [← RingHom.map_mul, ← RingHom.map_add, ← (algebraMap A K).map_one, ← h]
congr 1; ring
theorem mem_integer_iff (x : K) : x ∈ (valuation A K).integer ↔ ∃ a : A, algebraMap A K a = x := by
constructor
· rintro ⟨c, rfl⟩
use c
rw [Algebra.smul_def, mul_one]
· rintro ⟨c, rfl⟩
use c
rw [Algebra.smul_def, mul_one]
/-- The valuation ring `A` is isomorphic to the ring of integers of its associated valuation. -/
noncomputable def equivInteger : A ≃+* (valuation A K).integer :=
RingEquiv.ofBijective
(show A →ₙ+* (valuation A K).integer from
{ toFun := fun a => ⟨algebraMap A K a, (mem_integer_iff _ _ _).mpr ⟨a, rfl⟩⟩
map_mul' := fun _ _ => by ext1; exact (algebraMap A K).map_mul _ _
map_zero' := by ext1; exact (algebraMap A K).map_zero
map_add' := fun _ _ => by ext1; exact (algebraMap A K).map_add _ _ })
(by
constructor
· intro x y h
apply_fun (algebraMap (valuation A K).integer K) at h
exact IsFractionRing.injective _ _ h
· rintro ⟨-, ha⟩
rw [mem_integer_iff] at ha
obtain ⟨a, rfl⟩ := ha
exact ⟨a, rfl⟩)
@[simp]
theorem coe_equivInteger_apply (a : A) : (equivInteger A K a : K) = algebraMap A K a := rfl
theorem range_algebraMap_eq : (valuation A K).integer = (algebraMap A K).range := by
ext; exact mem_integer_iff _ _ _
end
section
variable (A : Type u) [CommRing A] [IsDomain A] [ValuationRing A]
instance (priority := 100) localRing : LocalRing A :=
LocalRing.of_isUnit_or_isUnit_one_sub_self
(by
intro a
obtain ⟨c, h | h⟩ := ValuationRing.cond a (1 - a)
· left
apply isUnit_of_mul_eq_one _ (c + 1)
simp [mul_add, h]
· right
apply isUnit_of_mul_eq_one _ (c + 1)
simp [mul_add, h])
instance [DecidableRel ((· ≤ ·) : Ideal A → Ideal A → Prop)] : LinearOrder (Ideal A) :=
{ (inferInstance : CompleteLattice (Ideal A)) with
le_total := by
intro α β
by_cases h : α ≤ β; · exact Or.inl h
erw [not_forall] at h
push_neg at h
obtain ⟨a, h₁, h₂⟩ := h
right
intro b hb
obtain ⟨c, h | h⟩ := ValuationRing.cond a b
· rw [← h]
exact Ideal.mul_mem_right _ _ h₁
· exfalso; apply h₂; rw [← h]
apply Ideal.mul_mem_right _ _ hb
decidableLE := inferInstance }
end
section
variable {R : Type*} [CommRing R] [IsDomain R] {K : Type*}
variable [Field K] [Algebra R K] [IsFractionRing R K]
theorem iff_dvd_total : ValuationRing R ↔ IsTotal R (· ∣ ·) := by
classical
refine ⟨fun H => ⟨fun a b => ?_⟩, fun H => ⟨fun a b => ?_⟩⟩
· obtain ⟨c, rfl | rfl⟩ := ValuationRing.cond a b <;> simp
· obtain ⟨c, rfl⟩ | ⟨c, rfl⟩ := @IsTotal.total _ _ H a b <;> use c <;> simp
theorem iff_ideal_total : ValuationRing R ↔ IsTotal (Ideal R) (· ≤ ·) := by
classical
refine ⟨fun _ => ⟨le_total⟩, fun H => iff_dvd_total.mpr ⟨fun a b => ?_⟩⟩
have := @IsTotal.total _ _ H (Ideal.span {a}) (Ideal.span {b})
simp_rw [Ideal.span_singleton_le_span_singleton] at this
exact this.symm
variable (K)
theorem dvd_total [h : ValuationRing R] (x y : R) : x ∣ y ∨ y ∣ x :=
@IsTotal.total _ _ (iff_dvd_total.mp h) x y
theorem unique_irreducible [ValuationRing R] ⦃p q : R⦄ (hp : Irreducible p) (hq : Irreducible q) :
Associated p q := by
have := dvd_total p q
rw [Irreducible.dvd_comm hp hq, or_self_iff] at this
exact associated_of_dvd_dvd (Irreducible.dvd_symm hq hp this) this
variable (R)
theorem iff_isInteger_or_isInteger :
ValuationRing R ↔ ∀ x : K, IsLocalization.IsInteger R x ∨ IsLocalization.IsInteger R x⁻¹ := by
constructor
· intro H x
obtain ⟨x : R, y, hy, rfl⟩ := IsFractionRing.div_surjective (A := R) x
have := (map_ne_zero_iff _ (IsFractionRing.injective R K)).mpr (nonZeroDivisors.ne_zero hy)
obtain ⟨s, rfl | rfl⟩ := ValuationRing.cond x y
· exact Or.inr
⟨s, eq_inv_of_mul_eq_one_left <| by rwa [mul_div, div_eq_one_iff_eq, map_mul, mul_comm]⟩
· exact Or.inl ⟨s, by rwa [eq_div_iff, map_mul, mul_comm]⟩
· intro H
constructor
intro a b
by_cases ha : a = 0; · subst ha; exact ⟨0, Or.inr <| mul_zero b⟩
by_cases hb : b = 0; · subst hb; exact ⟨0, Or.inl <| mul_zero a⟩
replace ha := (map_ne_zero_iff _ (IsFractionRing.injective R K)).mpr ha
replace hb := (map_ne_zero_iff _ (IsFractionRing.injective R K)).mpr hb
obtain ⟨c, e⟩ | ⟨c, e⟩ := H (algebraMap R K a / algebraMap R K b)
· rw [eq_div_iff hb, ← map_mul, (IsFractionRing.injective R K).eq_iff, mul_comm] at e
exact ⟨c, Or.inr e⟩
· rw [inv_div, eq_div_iff ha, ← map_mul, (IsFractionRing.injective R K).eq_iff, mul_comm c] at e
exact ⟨c, Or.inl e⟩
variable {K}
theorem isInteger_or_isInteger [h : ValuationRing R] (x : K) :
IsLocalization.IsInteger R x ∨ IsLocalization.IsInteger R x⁻¹ :=
(iff_isInteger_or_isInteger R K).mp h x
variable {R}
-- This implies that valuation rings are integrally closed through typeclass search.
instance (priority := 100) [ValuationRing R] : IsBezout R := by
classical
rw [IsBezout.iff_span_pair_isPrincipal]
intro x y
rw [Ideal.span_insert]
rcases le_total (Ideal.span {x} : Ideal R) (Ideal.span {y}) with h | h
· erw [sup_eq_right.mpr h]; exact ⟨⟨_, rfl⟩⟩
· erw [sup_eq_left.mpr h]; exact ⟨⟨_, rfl⟩⟩
instance (priority := 100) [LocalRing R] [IsBezout R] : ValuationRing R := by
classical
refine iff_dvd_total.mpr ⟨fun a b => ?_⟩
obtain ⟨g, e : _ = Ideal.span _⟩ := IsBezout.span_pair_isPrincipal a b
obtain ⟨a, rfl⟩ := Ideal.mem_span_singleton'.mp
(show a ∈ Ideal.span {g} by rw [← e]; exact Ideal.subset_span (by simp))
obtain ⟨b, rfl⟩ := Ideal.mem_span_singleton'.mp
(show b ∈ Ideal.span {g} by rw [← e]; exact Ideal.subset_span (by simp))
obtain ⟨x, y, e'⟩ := Ideal.mem_span_pair.mp
(show g ∈ Ideal.span {a * g, b * g} by rw [e]; exact Ideal.subset_span (by simp))
rcases eq_or_ne g 0 with h | h
· simp [h]
have : x * a + y * b = 1 := by
apply mul_left_injective₀ h; convert e' using 1 <;> ring
cases' LocalRing.isUnit_or_isUnit_of_add_one this with h' h' <;> [left; right]
all_goals exact mul_dvd_mul_right (isUnit_iff_forall_dvd.mp (isUnit_of_mul_isUnit_right h') _) _
theorem iff_local_bezout_domain : ValuationRing R ↔ LocalRing R ∧ IsBezout R :=
⟨fun _ ↦ ⟨inferInstance, inferInstance⟩, fun ⟨_, _⟩ ↦ inferInstance⟩
protected theorem TFAE (R : Type u) [CommRing R] [IsDomain R] :
List.TFAE
[ValuationRing R,
∀ x : FractionRing R, IsLocalization.IsInteger R x ∨ IsLocalization.IsInteger R x⁻¹,
IsTotal R (· ∣ ·), IsTotal (Ideal R) (· ≤ ·), LocalRing R ∧ IsBezout R] := by
tfae_have 1 ↔ 2; · exact iff_isInteger_or_isInteger R _
tfae_have 1 ↔ 3; · exact iff_dvd_total
tfae_have 1 ↔ 4; · exact iff_ideal_total
tfae_have 1 ↔ 5; · exact iff_local_bezout_domain
tfae_finish
end
theorem _root_.Function.Surjective.valuationRing {R S : Type*} [CommRing R] [IsDomain R]
[ValuationRing R] [CommRing S] [IsDomain S] (f : R →+* S) (hf : Function.Surjective f) :
ValuationRing S :=
⟨fun a b => by
obtain ⟨⟨a, rfl⟩, ⟨b, rfl⟩⟩ := hf a, hf b
obtain ⟨c, rfl | rfl⟩ := ValuationRing.cond a b
exacts [⟨f c, Or.inl <| (map_mul _ _ _).symm⟩, ⟨f c, Or.inr <| (map_mul _ _ _).symm⟩]⟩
section
variable {𝒪 : Type u} {K : Type v} {Γ : Type w} [CommRing 𝒪] [IsDomain 𝒪] [Field K] [Algebra 𝒪 K]
[LinearOrderedCommGroupWithZero Γ]
/-- If `𝒪` satisfies `v.integers 𝒪` where `v` is a valuation on a field, then `𝒪`
is a valuation ring. -/
theorem of_integers (v : Valuation K Γ) (hh : v.Integers 𝒪) : ValuationRing 𝒪 := by
constructor
intro a b
rcases le_total (v (algebraMap 𝒪 K a)) (v (algebraMap 𝒪 K b)) with h | h
· obtain ⟨c, hc⟩ := Valuation.Integers.dvd_of_le hh h
use c; exact Or.inr hc.symm
· obtain ⟨c, hc⟩ := Valuation.Integers.dvd_of_le hh h
use c; exact Or.inl hc.symm
instance instValuationRingInteger (v : Valuation K Γ) : ValuationRing v.integer :=
of_integers (v := v) (Valuation.integer.integers v)
theorem isFractionRing_iff [ValuationRing 𝒪] :
IsFractionRing 𝒪 K ↔
(∀ (x : K), ∃ a : 𝒪, x = algebraMap 𝒪 K a ∨ x⁻¹ = algebraMap 𝒪 K a) ∧
Function.Injective (algebraMap 𝒪 K) := by
refine ⟨fun h ↦ ⟨fun x ↦ ?_, IsFractionRing.injective _ _⟩, fun h ↦ ?_⟩
· obtain (⟨a, e⟩ | ⟨a, e⟩) := isInteger_or_isInteger 𝒪 x
exacts [⟨a, .inl e.symm⟩, ⟨a, .inr e.symm⟩]
· constructor
· intro a
simpa using h.2.ne_iff.mpr (nonZeroDivisors.ne_zero a.2)
· intro x
obtain ⟨a, ha⟩ := h.1 x
by_cases h0 : a = 0
· exact ⟨⟨0, 1⟩, by simpa [h0] using ha⟩
· have : algebraMap 𝒪 K a ≠ 0 := by simpa using h.2.ne_iff.mpr h0
rw [inv_eq_iff_eq_inv, ← one_div, eq_div_iff this] at ha
cases ha with
| inl ha => exact ⟨⟨a, 1⟩, by simpa⟩
| inr ha => exact ⟨⟨1, ⟨a, mem_nonZeroDivisors_of_ne_zero h0⟩⟩, by simpa using ha⟩
· intro _ _ hab
exact ⟨1, by simp only [OneMemClass.coe_one, h.2 hab, one_mul]⟩
instance instIsFractionRingInteger (v : Valuation K Γ) : IsFractionRing v.integer K :=
ValuationRing.isFractionRing_iff.mpr
⟨Valuation.Integers.eq_algebraMap_or_inv_eq_algebraMap (Valuation.integer.integers v),
Subtype.coe_injective⟩
end
section
variable (K : Type u) [Field K]
/-- A field is a valuation ring. -/
instance (priority := 100) of_field : ValuationRing K := by
constructor
intro a b
by_cases h : b = 0
· use 0; left; simp [h]
· use a * b⁻¹; right; field_simp
end
section
variable (A : Type u) [CommRing A] [IsDomain A] [DiscreteValuationRing A]
/-- A DVR is a valuation ring. -/
instance (priority := 100) of_discreteValuationRing : ValuationRing A := by
constructor
intro a b
by_cases ha : a = 0; · use 0; right; simp [ha]
by_cases hb : b = 0; · use 0; left; simp [hb]
obtain ⟨ϖ, hϖ⟩ := DiscreteValuationRing.exists_irreducible A
obtain ⟨m, u, rfl⟩ := DiscreteValuationRing.eq_unit_mul_pow_irreducible ha hϖ
obtain ⟨n, v, rfl⟩ := DiscreteValuationRing.eq_unit_mul_pow_irreducible hb hϖ
rcases le_total m n with h | h
· use (u⁻¹ * v : Aˣ) * ϖ ^ (n - m); left
simp_rw [mul_comm (u : A), Units.val_mul, ← mul_assoc, mul_assoc _ (u : A)]
simp only [Units.mul_inv, mul_one, mul_comm _ (v : A), mul_assoc, ← pow_add]
congr 2
exact Nat.add_sub_of_le h
· use (v⁻¹ * u : Aˣ) * ϖ ^ (m - n); right
simp_rw [mul_comm (v : A), Units.val_mul, ← mul_assoc, mul_assoc _ (v : A)]
simp only [Units.mul_inv, mul_one, mul_comm _ (u : A), mul_assoc, ← pow_add]
congr 2
exact Nat.add_sub_of_le h
end
end ValuationRing
|
RingTheory\Valuation\ValuationSubring.lean | /-
Copyright (c) 2022 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz, Junyan Xu, Jack McKoen
-/
import Mathlib.RingTheory.Valuation.ValuationRing
import Mathlib.RingTheory.Localization.AsSubring
import Mathlib.Algebra.Ring.Subring.Pointwise
import Mathlib.Algebra.Ring.Action.Field
import Mathlib.RingTheory.PrimeSpectrum
import Mathlib.RingTheory.LocalRing.ResidueField.Basic
/-!
# Valuation subrings of a field
## Projects
The order structure on `ValuationSubring K`.
-/
universe u
open scoped Classical
noncomputable section
variable (K : Type u) [Field K]
/-- A valuation subring of a field `K` is a subring `A` such that for every `x : K`,
either `x ∈ A` or `x⁻¹ ∈ A`. -/
structure ValuationSubring extends Subring K where
mem_or_inv_mem' : ∀ x : K, x ∈ carrier ∨ x⁻¹ ∈ carrier
namespace ValuationSubring
variable {K}
variable (A : ValuationSubring K)
instance : SetLike (ValuationSubring K) K where
coe A := A.toSubring
coe_injective' := by
intro ⟨_, _⟩ ⟨_, _⟩ h
replace h := SetLike.coe_injective' h
congr
@[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove that
theorem mem_carrier (x : K) : x ∈ A.carrier ↔ x ∈ A := Iff.refl _
@[simp]
theorem mem_toSubring (x : K) : x ∈ A.toSubring ↔ x ∈ A := Iff.refl _
@[ext]
theorem ext (A B : ValuationSubring K) (h : ∀ x, x ∈ A ↔ x ∈ B) : A = B := SetLike.ext h
theorem zero_mem : (0 : K) ∈ A := A.toSubring.zero_mem
theorem one_mem : (1 : K) ∈ A := A.toSubring.one_mem
theorem add_mem (x y : K) : x ∈ A → y ∈ A → x + y ∈ A := A.toSubring.add_mem
theorem mul_mem (x y : K) : x ∈ A → y ∈ A → x * y ∈ A := A.toSubring.mul_mem
theorem neg_mem (x : K) : x ∈ A → -x ∈ A := A.toSubring.neg_mem
theorem mem_or_inv_mem (x : K) : x ∈ A ∨ x⁻¹ ∈ A := A.mem_or_inv_mem' _
instance : SubringClass (ValuationSubring K) K where
zero_mem := zero_mem
add_mem {_} a b := add_mem _ a b
one_mem := one_mem
mul_mem {_} a b := mul_mem _ a b
neg_mem {_} x := neg_mem _ x
theorem toSubring_injective : Function.Injective (toSubring : ValuationSubring K → Subring K) :=
fun x y h => by cases x; cases y; congr
instance : CommRing A :=
show CommRing A.toSubring by infer_instance
instance : IsDomain A :=
show IsDomain A.toSubring by infer_instance
instance : Top (ValuationSubring K) :=
Top.mk <| { (⊤ : Subring K) with mem_or_inv_mem' := fun _ => Or.inl trivial }
theorem mem_top (x : K) : x ∈ (⊤ : ValuationSubring K) :=
trivial
theorem le_top : A ≤ ⊤ := fun _a _ha => mem_top _
instance : OrderTop (ValuationSubring K) where
top := ⊤
le_top := le_top
instance : Inhabited (ValuationSubring K) :=
⟨⊤⟩
instance : ValuationRing A where
cond' a b := by
by_cases h : (b : K) = 0
· use 0
left
ext
simp [h]
by_cases h : (a : K) = 0
· use 0; right
ext
simp [h]
cases' A.mem_or_inv_mem (a / b) with hh hh
· use ⟨a / b, hh⟩
right
ext
field_simp
· rw [show (a / b : K)⁻¹ = b / a by field_simp] at hh
use ⟨b / a, hh⟩
left
ext
field_simp
instance : Algebra A K :=
show Algebra A.toSubring K by infer_instance
-- Porting note: Somehow it cannot find this instance and I'm too lazy to debug. wrong prio?
instance localRing : LocalRing A := ValuationRing.localRing A
@[simp]
theorem algebraMap_apply (a : A) : algebraMap A K a = a := rfl
instance : IsFractionRing A K where
map_units' := fun ⟨y, hy⟩ =>
(Units.mk0 (y : K) fun c => nonZeroDivisors.ne_zero hy <| Subtype.ext c).isUnit
surj' z := by
by_cases h : z = 0; · use (0, 1); simp [h]
cases' A.mem_or_inv_mem z with hh hh
· use (⟨z, hh⟩, 1); simp
· refine ⟨⟨1, ⟨⟨_, hh⟩, ?_⟩⟩, mul_inv_cancel h⟩
exact mem_nonZeroDivisors_iff_ne_zero.2 fun c => h (inv_eq_zero.mp (congr_arg Subtype.val c))
exists_of_eq {a b} h := ⟨1, by ext; simpa using h⟩
/-- The value group of the valuation associated to `A`. Note: it is actually a group with zero. -/
def ValueGroup :=
ValuationRing.ValueGroup A K
-- deriving LinearOrderedCommGroupWithZero
-- Porting note: see https://github.com/leanprover-community/mathlib4/issues/5020
instance : LinearOrderedCommGroupWithZero (ValueGroup A) := by
unfold ValueGroup
infer_instance
/-- Any valuation subring of `K` induces a natural valuation on `K`. -/
def valuation : Valuation K A.ValueGroup :=
ValuationRing.valuation A K
instance inhabitedValueGroup : Inhabited A.ValueGroup := ⟨A.valuation 0⟩
theorem valuation_le_one (a : A) : A.valuation a ≤ 1 :=
(ValuationRing.mem_integer_iff A K _).2 ⟨a, rfl⟩
theorem mem_of_valuation_le_one (x : K) (h : A.valuation x ≤ 1) : x ∈ A :=
let ⟨a, ha⟩ := (ValuationRing.mem_integer_iff A K x).1 h
ha ▸ a.2
theorem valuation_le_one_iff (x : K) : A.valuation x ≤ 1 ↔ x ∈ A :=
⟨mem_of_valuation_le_one _ _, fun ha => A.valuation_le_one ⟨x, ha⟩⟩
theorem valuation_eq_iff (x y : K) : A.valuation x = A.valuation y ↔ ∃ a : Aˣ, (a : K) * y = x :=
Quotient.eq''
theorem valuation_le_iff (x y : K) : A.valuation x ≤ A.valuation y ↔ ∃ a : A, (a : K) * y = x :=
Iff.rfl
theorem valuation_surjective : Function.Surjective A.valuation := surjective_quot_mk _
theorem valuation_unit (a : Aˣ) : A.valuation a = 1 := by
rw [← A.valuation.map_one, valuation_eq_iff]; use a; simp
theorem valuation_eq_one_iff (a : A) : IsUnit a ↔ A.valuation a = 1 :=
⟨fun h => A.valuation_unit h.unit, fun h => by
have ha : (a : K) ≠ 0 := by
intro c
rw [c, A.valuation.map_zero] at h
exact zero_ne_one h
have ha' : (a : K)⁻¹ ∈ A := by rw [← valuation_le_one_iff, map_inv₀, h, inv_one]
apply isUnit_of_mul_eq_one a ⟨a⁻¹, ha'⟩; ext; field_simp⟩
theorem valuation_lt_one_or_eq_one (a : A) : A.valuation a < 1 ∨ A.valuation a = 1 :=
lt_or_eq_of_le (A.valuation_le_one a)
theorem valuation_lt_one_iff (a : A) : a ∈ LocalRing.maximalIdeal A ↔ A.valuation a < 1 := by
rw [LocalRing.mem_maximalIdeal]
dsimp [nonunits]; rw [valuation_eq_one_iff]
exact (A.valuation_le_one a).lt_iff_ne.symm
/-- A subring `R` of `K` such that for all `x : K` either `x ∈ R` or `x⁻¹ ∈ R` is
a valuation subring of `K`. -/
def ofSubring (R : Subring K) (hR : ∀ x : K, x ∈ R ∨ x⁻¹ ∈ R) : ValuationSubring K :=
{ R with mem_or_inv_mem' := hR }
@[simp]
theorem mem_ofSubring (R : Subring K) (hR : ∀ x : K, x ∈ R ∨ x⁻¹ ∈ R) (x : K) :
x ∈ ofSubring R hR ↔ x ∈ R :=
Iff.refl _
/-- An overring of a valuation ring is a valuation ring. -/
def ofLE (R : ValuationSubring K) (S : Subring K) (h : R.toSubring ≤ S) : ValuationSubring K :=
{ S with mem_or_inv_mem' := fun x => (R.mem_or_inv_mem x).imp (@h x) (@h _) }
section Order
instance : SemilatticeSup (ValuationSubring K) :=
{ (inferInstance : PartialOrder (ValuationSubring K)) with
sup := fun R S => ofLE R (R.toSubring ⊔ S.toSubring) <| le_sup_left
le_sup_left := fun R S _ hx => (le_sup_left : R.toSubring ≤ R.toSubring ⊔ S.toSubring) hx
le_sup_right := fun R S _ hx => (le_sup_right : S.toSubring ≤ R.toSubring ⊔ S.toSubring) hx
sup_le := fun R S T hR hT _ hx => (sup_le hR hT : R.toSubring ⊔ S.toSubring ≤ T.toSubring) hx }
/-- The ring homomorphism induced by the partial order. -/
def inclusion (R S : ValuationSubring K) (h : R ≤ S) : R →+* S :=
Subring.inclusion h
/-- The canonical ring homomorphism from a valuation ring to its field of fractions. -/
def subtype (R : ValuationSubring K) : R →+* K :=
Subring.subtype R.toSubring
/-- The canonical map on value groups induced by a coarsening of valuation rings. -/
def mapOfLE (R S : ValuationSubring K) (h : R ≤ S) : R.ValueGroup →*₀ S.ValueGroup where
toFun := Quotient.map' id fun x y ⟨u, hu⟩ => ⟨Units.map (R.inclusion S h).toMonoidHom u, hu⟩
map_zero' := rfl
map_one' := rfl
map_mul' := by rintro ⟨⟩ ⟨⟩; rfl
@[mono]
theorem monotone_mapOfLE (R S : ValuationSubring K) (h : R ≤ S) : Monotone (R.mapOfLE S h) := by
rintro ⟨⟩ ⟨⟩ ⟨a, ha⟩; exact ⟨R.inclusion S h a, ha⟩
@[simp]
theorem mapOfLE_comp_valuation (R S : ValuationSubring K) (h : R ≤ S) :
R.mapOfLE S h ∘ R.valuation = S.valuation := by ext; rfl
@[simp]
theorem mapOfLE_valuation_apply (R S : ValuationSubring K) (h : R ≤ S) (x : K) :
R.mapOfLE S h (R.valuation x) = S.valuation x := rfl
/-- The ideal corresponding to a coarsening of a valuation ring. -/
def idealOfLE (R S : ValuationSubring K) (h : R ≤ S) : Ideal R :=
(LocalRing.maximalIdeal S).comap (R.inclusion S h)
instance prime_idealOfLE (R S : ValuationSubring K) (h : R ≤ S) : (idealOfLE R S h).IsPrime :=
(LocalRing.maximalIdeal S).comap_isPrime _
/-- The coarsening of a valuation ring associated to a prime ideal. -/
def ofPrime (A : ValuationSubring K) (P : Ideal A) [P.IsPrime] : ValuationSubring K :=
ofLE A (Localization.subalgebra.ofField K _ P.primeCompl_le_nonZeroDivisors).toSubring
-- Porting note: added `Subalgebra.mem_toSubring.mpr`
fun a ha => Subalgebra.mem_toSubring.mpr <|
Subalgebra.algebraMap_mem
(Localization.subalgebra.ofField K _ P.primeCompl_le_nonZeroDivisors) (⟨a, ha⟩ : A)
instance ofPrimeAlgebra (A : ValuationSubring K) (P : Ideal A) [P.IsPrime] :
Algebra A (A.ofPrime P) :=
-- Porting note: filled in the argument
Subalgebra.algebra (Localization.subalgebra.ofField K _ P.primeCompl_le_nonZeroDivisors)
instance ofPrime_scalar_tower (A : ValuationSubring K) (P : Ideal A) [P.IsPrime] :
-- porting note (#10754): added instance
letI : SMul A (A.ofPrime P) := SMulZeroClass.toSMul
IsScalarTower A (A.ofPrime P) K :=
IsScalarTower.subalgebra' A K K
-- Porting note: filled in the argument
(Localization.subalgebra.ofField K _ P.primeCompl_le_nonZeroDivisors)
instance ofPrime_localization (A : ValuationSubring K) (P : Ideal A) [P.IsPrime] :
IsLocalization.AtPrime (A.ofPrime P) P := by
apply
Localization.subalgebra.isLocalization_ofField K P.primeCompl
P.primeCompl_le_nonZeroDivisors
theorem le_ofPrime (A : ValuationSubring K) (P : Ideal A) [P.IsPrime] : A ≤ ofPrime A P :=
-- Porting note: added `Subalgebra.mem_toSubring.mpr`
fun a ha => Subalgebra.mem_toSubring.mpr <| Subalgebra.algebraMap_mem _ (⟨a, ha⟩ : A)
theorem ofPrime_valuation_eq_one_iff_mem_primeCompl (A : ValuationSubring K) (P : Ideal A)
[P.IsPrime] (x : A) : (ofPrime A P).valuation x = 1 ↔ x ∈ P.primeCompl := by
rw [← IsLocalization.AtPrime.isUnit_to_map_iff (A.ofPrime P) P x, valuation_eq_one_iff]; rfl
@[simp]
theorem idealOfLE_ofPrime (A : ValuationSubring K) (P : Ideal A) [P.IsPrime] :
idealOfLE A (ofPrime A P) (le_ofPrime A P) = P := by
refine Ideal.ext (fun x => ?_)
apply IsLocalization.AtPrime.to_map_mem_maximal_iff
exact localRing (ofPrime A P)
@[simp]
theorem ofPrime_idealOfLE (R S : ValuationSubring K) (h : R ≤ S) :
ofPrime R (idealOfLE R S h) = S := by
ext x; constructor
· rintro ⟨a, r, hr, rfl⟩; apply mul_mem; · exact h a.2
· rw [← valuation_le_one_iff, map_inv₀, ← inv_one, inv_le_inv₀]
· exact not_lt.1 ((not_iff_not.2 <| valuation_lt_one_iff S _).1 hr)
· intro hh; erw [Valuation.zero_iff, Subring.coe_eq_zero_iff] at hh
apply hr; rw [hh]; apply Ideal.zero_mem (R.idealOfLE S h)
· exact one_ne_zero
· intro hx; by_cases hr : x ∈ R; · exact R.le_ofPrime _ hr
have : x ≠ 0 := fun h => hr (by rw [h]; exact R.zero_mem)
replace hr := (R.mem_or_inv_mem x).resolve_left hr
refine ⟨1, ⟨x⁻¹, hr⟩, ?_, ?_⟩
· simp only [Ideal.primeCompl, Submonoid.mem_mk, Subsemigroup.mem_mk, Set.mem_compl_iff,
SetLike.mem_coe, idealOfLE, Ideal.mem_comap, LocalRing.mem_maximalIdeal, mem_nonunits_iff,
not_not]
change IsUnit (⟨x⁻¹, h hr⟩ : S)
apply isUnit_of_mul_eq_one _ (⟨x, hx⟩ : S)
ext; field_simp
· field_simp
theorem ofPrime_le_of_le (P Q : Ideal A) [P.IsPrime] [Q.IsPrime] (h : P ≤ Q) :
ofPrime A Q ≤ ofPrime A P := fun _x ⟨a, s, hs, he⟩ => ⟨a, s, fun c => hs (h c), he⟩
theorem idealOfLE_le_of_le (R S : ValuationSubring K) (hR : A ≤ R) (hS : A ≤ S) (h : R ≤ S) :
idealOfLE A S hS ≤ idealOfLE A R hR := fun x hx =>
(valuation_lt_one_iff R _).2
(by
by_contra c; push_neg at c; replace c := monotone_mapOfLE R S h c
rw [(mapOfLE _ _ _).map_one, mapOfLE_valuation_apply] at c
apply not_le_of_lt ((valuation_lt_one_iff S _).1 hx) c)
/-- The equivalence between coarsenings of a valuation ring and its prime ideals. -/
@[simps]
def primeSpectrumEquiv : PrimeSpectrum A ≃ {S // A ≤ S} where
toFun P := ⟨ofPrime A P.asIdeal, le_ofPrime _ _⟩
invFun S := ⟨idealOfLE _ S S.2, inferInstance⟩
left_inv P := by ext1; simp
right_inv S := by ext1; simp
/-- An ordered variant of `primeSpectrumEquiv`. -/
@[simps!]
def primeSpectrumOrderEquiv : (PrimeSpectrum A)ᵒᵈ ≃o {S // A ≤ S} :=
{ primeSpectrumEquiv A with
map_rel_iff' :=
⟨fun h => by
dsimp at h
have := idealOfLE_le_of_le A _ _ ?_ ?_ h
iterate 2 erw [idealOfLE_ofPrime] at this
· exact this
all_goals exact le_ofPrime A (PrimeSpectrum.asIdeal _),
fun h => by apply ofPrime_le_of_le; exact h⟩ }
instance linearOrderOverring : LinearOrder {S // A ≤ S} :=
{ (inferInstance : PartialOrder _) with
le_total :=
let i : IsTotal (PrimeSpectrum A) (· ≤ ·) := ⟨fun ⟨x, _⟩ ⟨y, _⟩ => LE.isTotal.total x y⟩
(primeSpectrumOrderEquiv A).symm.toRelEmbedding.isTotal.total
decidableLE := inferInstance }
end Order
end ValuationSubring
namespace Valuation
variable {K}
variable {Γ Γ₁ Γ₂ : Type*} [LinearOrderedCommGroupWithZero Γ]
[LinearOrderedCommGroupWithZero Γ₁] [LinearOrderedCommGroupWithZero Γ₂] (v : Valuation K Γ)
(v₁ : Valuation K Γ₁) (v₂ : Valuation K Γ₂)
/-- The valuation subring associated to a valuation. -/
def valuationSubring : ValuationSubring K :=
{ v.integer with
mem_or_inv_mem' := by
intro x
rcases val_le_one_or_val_inv_le_one v x with h | h
exacts [Or.inl h, Or.inr h] }
@[simp]
theorem mem_valuationSubring_iff (x : K) : x ∈ v.valuationSubring ↔ v x ≤ 1 := Iff.refl _
theorem isEquiv_iff_valuationSubring :
v₁.IsEquiv v₂ ↔ v₁.valuationSubring = v₂.valuationSubring := by
constructor
· intro h; ext x; specialize h x 1; simpa using h
· intro h; apply isEquiv_of_val_le_one
intro x
have : x ∈ v₁.valuationSubring ↔ x ∈ v₂.valuationSubring := by rw [h]
simpa using this
theorem isEquiv_valuation_valuationSubring : v.IsEquiv v.valuationSubring.valuation := by
rw [isEquiv_iff_val_le_one]
intro x
rw [ValuationSubring.valuation_le_one_iff]
rfl
end Valuation
namespace ValuationSubring
variable {K}
variable (A : ValuationSubring K)
@[simp]
theorem valuationSubring_valuation : A.valuation.valuationSubring = A := by
ext; rw [← A.valuation_le_one_iff]; rfl
section UnitGroup
/-- The unit group of a valuation subring, as a subgroup of `Kˣ`. -/
def unitGroup : Subgroup Kˣ :=
(A.valuation.toMonoidWithZeroHom.toMonoidHom.comp (Units.coeHom K)).ker
@[simp]
theorem mem_unitGroup_iff (x : Kˣ) : x ∈ A.unitGroup ↔ A.valuation x = 1 := Iff.rfl
/-- For a valuation subring `A`, `A.unitGroup` agrees with the units of `A`. -/
def unitGroupMulEquiv : A.unitGroup ≃* Aˣ where
toFun x :=
{ val := ⟨(x : Kˣ), mem_of_valuation_le_one A _ x.prop.le⟩
inv := ⟨((x⁻¹ : A.unitGroup) : Kˣ), mem_of_valuation_le_one _ _ x⁻¹.prop.le⟩
-- Porting note: was `Units.mul_inv x`
val_inv := Subtype.ext (by simp)
-- Porting note: was `Units.inv_mul x`
inv_val := Subtype.ext (by simp) }
invFun x := ⟨Units.map A.subtype.toMonoidHom x, A.valuation_unit x⟩
left_inv a := by ext; rfl
right_inv a := by ext; rfl
map_mul' a b := by ext; rfl
@[simp]
theorem coe_unitGroupMulEquiv_apply (a : A.unitGroup) :
((A.unitGroupMulEquiv a : A) : K) = ((a : Kˣ) : K) := rfl
@[simp]
theorem coe_unitGroupMulEquiv_symm_apply (a : Aˣ) : ((A.unitGroupMulEquiv.symm a : Kˣ) : K) = a :=
rfl
theorem unitGroup_le_unitGroup {A B : ValuationSubring K} : A.unitGroup ≤ B.unitGroup ↔ A ≤ B := by
constructor
· intro h x hx
rw [← A.valuation_le_one_iff x, le_iff_lt_or_eq] at hx
by_cases h_1 : x = 0; · simp only [h_1, zero_mem]
by_cases h_2 : 1 + x = 0
· simp only [← add_eq_zero_iff_neg_eq.1 h_2, neg_mem _ _ (one_mem _)]
cases' hx with hx hx
· have := h (show Units.mk0 _ h_2 ∈ A.unitGroup from A.valuation.map_one_add_of_lt hx)
simpa using
B.add_mem _ _ (show 1 + x ∈ B from SetLike.coe_mem (B.unitGroupMulEquiv ⟨_, this⟩ : B))
(B.neg_mem _ B.one_mem)
· have := h (show Units.mk0 x h_1 ∈ A.unitGroup from hx)
exact SetLike.coe_mem (B.unitGroupMulEquiv ⟨_, this⟩ : B)
· rintro h x (hx : A.valuation x = 1)
apply_fun A.mapOfLE B h at hx
simpa using hx
theorem unitGroup_injective : Function.Injective (unitGroup : ValuationSubring K → Subgroup _) :=
fun A B h => by simpa only [le_antisymm_iff, unitGroup_le_unitGroup] using h
theorem eq_iff_unitGroup {A B : ValuationSubring K} : A = B ↔ A.unitGroup = B.unitGroup :=
unitGroup_injective.eq_iff.symm
/-- The map on valuation subrings to their unit groups is an order embedding. -/
def unitGroupOrderEmbedding : ValuationSubring K ↪o Subgroup Kˣ where
toFun A := A.unitGroup
inj' := unitGroup_injective
map_rel_iff' {_A _B} := unitGroup_le_unitGroup
theorem unitGroup_strictMono : StrictMono (unitGroup : ValuationSubring K → Subgroup _) :=
unitGroupOrderEmbedding.strictMono
end UnitGroup
section nonunits
/-- The nonunits of a valuation subring of `K`, as a subsemigroup of `K`-/
def nonunits : Subsemigroup K where
carrier := {x | A.valuation x < 1}
-- Porting note: added `Set.mem_setOf.mp`
mul_mem' ha hb := (mul_lt_mul₀ (Set.mem_setOf.mp ha) (Set.mem_setOf.mp hb)).trans_eq <| mul_one _
theorem mem_nonunits_iff {x : K} : x ∈ A.nonunits ↔ A.valuation x < 1 :=
Iff.rfl
theorem nonunits_le_nonunits {A B : ValuationSubring K} : B.nonunits ≤ A.nonunits ↔ A ≤ B := by
constructor
· intro h x hx
by_cases h_1 : x = 0; · simp only [h_1, zero_mem]
rw [← valuation_le_one_iff, ← not_lt, Valuation.one_lt_val_iff _ h_1] at hx ⊢
by_contra h_2; exact hx (h h_2)
· intro h x hx
by_contra h_1; exact not_lt.2 (monotone_mapOfLE _ _ h (not_lt.1 h_1)) hx
theorem nonunits_injective : Function.Injective (nonunits : ValuationSubring K → Subsemigroup _) :=
fun A B h => by simpa only [le_antisymm_iff, nonunits_le_nonunits] using h.symm
theorem nonunits_inj {A B : ValuationSubring K} : A.nonunits = B.nonunits ↔ A = B :=
nonunits_injective.eq_iff
/-- The map on valuation subrings to their nonunits is a dual order embedding. -/
def nonunitsOrderEmbedding : ValuationSubring K ↪o (Subsemigroup K)ᵒᵈ where
toFun A := A.nonunits
inj' := nonunits_injective
map_rel_iff' {_A _B} := nonunits_le_nonunits
variable {A}
/-- The elements of `A.nonunits` are those of the maximal ideal of `A` after coercion to `K`.
See also `mem_nonunits_iff_exists_mem_maximalIdeal`, which gets rid of the coercion to `K`,
at the expense of a more complicated right hand side.
-/
theorem coe_mem_nonunits_iff {a : A} : (a : K) ∈ A.nonunits ↔ a ∈ LocalRing.maximalIdeal A :=
(valuation_lt_one_iff _ _).symm
theorem nonunits_le : A.nonunits ≤ A.toSubring.toSubmonoid.toSubsemigroup := fun _a ha =>
(A.valuation_le_one_iff _).mp (A.mem_nonunits_iff.mp ha).le
theorem nonunits_subset : (A.nonunits : Set K) ⊆ A :=
nonunits_le
/-- The elements of `A.nonunits` are those of the maximal ideal of `A`.
See also `coe_mem_nonunits_iff`, which has a simpler right hand side but requires the element
to be in `A` already.
-/
theorem mem_nonunits_iff_exists_mem_maximalIdeal {a : K} :
a ∈ A.nonunits ↔ ∃ ha, (⟨a, ha⟩ : A) ∈ LocalRing.maximalIdeal A :=
⟨fun h => ⟨nonunits_subset h, coe_mem_nonunits_iff.mp h⟩, fun ⟨_, h⟩ =>
coe_mem_nonunits_iff.mpr h⟩
/-- `A.nonunits` agrees with the maximal ideal of `A`, after taking its image in `K`. -/
theorem image_maximalIdeal : ((↑) : A → K) '' LocalRing.maximalIdeal A = A.nonunits := by
ext a
simp only [Set.mem_image, SetLike.mem_coe, mem_nonunits_iff_exists_mem_maximalIdeal]
erw [Subtype.exists]
simp_rw [exists_and_right, exists_eq_right]
-- Porting note: added
simp
end nonunits
section PrincipalUnitGroup
/-- The principal unit group of a valuation subring, as a subgroup of `Kˣ`. -/
def principalUnitGroup : Subgroup Kˣ where
carrier := {x | A.valuation (x - 1) < 1}
mul_mem' := by
intro a b ha hb
-- Porting note: added
rw [Set.mem_setOf] at ha hb
refine lt_of_le_of_lt ?_ (max_lt hb ha)
-- Porting note: `sub_add_sub_cancel` needed some help
rw [← one_mul (A.valuation (b - 1)), ← A.valuation.map_one_add_of_lt ha, add_sub_cancel,
← Valuation.map_mul, mul_sub_one, ← sub_add_sub_cancel (↑(a * b) : K) _ 1]
exact A.valuation.map_add _ _
one_mem' := by simp
inv_mem' := by
dsimp
intro a ha
conv =>
lhs
rw [← mul_one (A.valuation _), ← A.valuation.map_one_add_of_lt ha]
rwa [add_sub_cancel, ← Valuation.map_mul, sub_mul, Units.inv_mul, ← neg_sub, one_mul,
Valuation.map_neg]
theorem principal_units_le_units : A.principalUnitGroup ≤ A.unitGroup := fun a h => by
simpa only [add_sub_cancel] using A.valuation.map_one_add_of_lt h
theorem mem_principalUnitGroup_iff (x : Kˣ) :
x ∈ A.principalUnitGroup ↔ A.valuation ((x : K) - 1) < 1 :=
Iff.rfl
theorem principalUnitGroup_le_principalUnitGroup {A B : ValuationSubring K} :
B.principalUnitGroup ≤ A.principalUnitGroup ↔ A ≤ B := by
constructor
· intro h x hx
by_cases h_1 : x = 0; · simp only [h_1, zero_mem]
by_cases h_2 : x⁻¹ + 1 = 0
· rw [add_eq_zero_iff_eq_neg, inv_eq_iff_eq_inv, inv_neg, inv_one] at h_2
simpa only [h_2] using B.neg_mem _ B.one_mem
· rw [← valuation_le_one_iff, ← not_lt, Valuation.one_lt_val_iff _ h_1,
← add_sub_cancel_right x⁻¹, ← Units.val_mk0 h_2, ← mem_principalUnitGroup_iff] at hx ⊢
simpa only [hx] using @h (Units.mk0 (x⁻¹ + 1) h_2)
· intro h x hx
by_contra h_1; exact not_lt.2 (monotone_mapOfLE _ _ h (not_lt.1 h_1)) hx
theorem principalUnitGroup_injective :
Function.Injective (principalUnitGroup : ValuationSubring K → Subgroup _) := fun A B h => by
simpa [le_antisymm_iff, principalUnitGroup_le_principalUnitGroup] using h.symm
theorem eq_iff_principalUnitGroup {A B : ValuationSubring K} :
A = B ↔ A.principalUnitGroup = B.principalUnitGroup :=
principalUnitGroup_injective.eq_iff.symm
/-- The map on valuation subrings to their principal unit groups is an order embedding. -/
def principalUnitGroupOrderEmbedding : ValuationSubring K ↪o (Subgroup Kˣ)ᵒᵈ where
toFun A := A.principalUnitGroup
inj' := principalUnitGroup_injective
map_rel_iff' {_A _B} := principalUnitGroup_le_principalUnitGroup
theorem coe_mem_principalUnitGroup_iff {x : A.unitGroup} :
(x : Kˣ) ∈ A.principalUnitGroup ↔
A.unitGroupMulEquiv x ∈ (Units.map (LocalRing.residue A).toMonoidHom).ker := by
rw [MonoidHom.mem_ker, Units.ext_iff]
let π := Ideal.Quotient.mk (LocalRing.maximalIdeal A); convert_to _ ↔ π _ = 1
rw [← π.map_one, ← sub_eq_zero, ← π.map_sub, Ideal.Quotient.eq_zero_iff_mem, valuation_lt_one_iff]
simp [mem_principalUnitGroup_iff]
/-- The principal unit group agrees with the kernel of the canonical map from
the units of `A` to the units of the residue field of `A`. -/
def principalUnitGroupEquiv :
A.principalUnitGroup ≃* (Units.map (LocalRing.residue A).toMonoidHom).ker where
toFun x :=
⟨A.unitGroupMulEquiv ⟨_, A.principal_units_le_units x.2⟩,
A.coe_mem_principalUnitGroup_iff.1 x.2⟩
invFun x :=
⟨A.unitGroupMulEquiv.symm x, by
rw [A.coe_mem_principalUnitGroup_iff]; simpa using SetLike.coe_mem x⟩
left_inv x := by simp
right_inv x := by simp
map_mul' x y := rfl
theorem principalUnitGroupEquiv_apply (a : A.principalUnitGroup) :
(((principalUnitGroupEquiv A a : Aˣ) : A) : K) = (a : Kˣ) :=
rfl
theorem principalUnitGroup_symm_apply (a : (Units.map (LocalRing.residue A).toMonoidHom).ker) :
((A.principalUnitGroupEquiv.symm a : Kˣ) : K) = ((a : Aˣ) : A) :=
rfl
/-- The canonical map from the unit group of `A` to the units of the residue field of `A`. -/
def unitGroupToResidueFieldUnits : A.unitGroup →* (LocalRing.ResidueField A)ˣ :=
MonoidHom.comp (Units.map <| (Ideal.Quotient.mk _).toMonoidHom) A.unitGroupMulEquiv.toMonoidHom
@[simp]
theorem coe_unitGroupToResidueFieldUnits_apply (x : A.unitGroup) :
(A.unitGroupToResidueFieldUnits x : LocalRing.ResidueField A) =
Ideal.Quotient.mk _ (A.unitGroupMulEquiv x : A) :=
rfl
theorem ker_unitGroupToResidueFieldUnits :
A.unitGroupToResidueFieldUnits.ker = A.principalUnitGroup.comap A.unitGroup.subtype := by
ext
-- Porting note: simp fails but rw works
-- See https://github.com/leanprover-community/mathlib4/issues/5026
-- simp [Subgroup.mem_comap, Subgroup.coeSubtype, coe_mem_principalUnitGroup_iff]
rw [Subgroup.mem_comap, Subgroup.coeSubtype, coe_mem_principalUnitGroup_iff]
rfl
-- simp [Subgroup.mem_comap, Subgroup.coeSubtype, coe_mem_principalUnitGroup_iff]
theorem surjective_unitGroupToResidueFieldUnits :
Function.Surjective A.unitGroupToResidueFieldUnits :=
(LocalRing.surjective_units_map_of_local_ringHom _ Ideal.Quotient.mk_surjective
LocalRing.isLocalRingHom_residue).comp
(MulEquiv.surjective _)
/-- The quotient of the unit group of `A` by the principal unit group of `A` agrees with
the units of the residue field of `A`. -/
def unitsModPrincipalUnitsEquivResidueFieldUnits :
A.unitGroup ⧸ A.principalUnitGroup.comap A.unitGroup.subtype ≃* (LocalRing.ResidueField A)ˣ :=
(QuotientGroup.quotientMulEquivOfEq A.ker_unitGroupToResidueFieldUnits.symm).trans
(QuotientGroup.quotientKerEquivOfSurjective _ A.surjective_unitGroupToResidueFieldUnits)
/-- Porting note: Lean needs to be reminded of this instance -/
local instance : MulOneClass ({ x // x ∈ unitGroup A } ⧸
Subgroup.comap (Subgroup.subtype (unitGroup A)) (principalUnitGroup A)) := inferInstance
-- @[simp] -- Porting note: not in simpNF
theorem unitsModPrincipalUnitsEquivResidueFieldUnits_comp_quotientGroup_mk :
A.unitsModPrincipalUnitsEquivResidueFieldUnits.toMonoidHom.comp (QuotientGroup.mk' _) =
A.unitGroupToResidueFieldUnits := rfl
theorem unitsModPrincipalUnitsEquivResidueFieldUnits_comp_quotientGroup_mk_apply
(x : A.unitGroup) :
A.unitsModPrincipalUnitsEquivResidueFieldUnits.toMonoidHom (QuotientGroup.mk x) =
A.unitGroupToResidueFieldUnits x := rfl
end PrincipalUnitGroup
/-! ### Pointwise actions
This transfers the action from `Subring.pointwiseMulAction`, noting that it only applies when
the action is by a group. Notably this provides an instances when `G` is `K ≃+* K`.
These instances are in the `Pointwise` locale.
The lemmas in this section are copied from the file `Mathlib.Algebra.Ring.Subring.Pointwise`; try
to keep these in sync.
-/
section PointwiseActions
open scoped Pointwise
variable {G : Type*} [Group G] [MulSemiringAction G K]
/-- The action on a valuation subring corresponding to applying the action to every element.
This is available as an instance in the `Pointwise` locale. -/
def pointwiseHasSMul : SMul G (ValuationSubring K) where
smul g S :=-- TODO: if we add `ValuationSubring.map` at a later date, we should use it here
{ g • S.toSubring with
mem_or_inv_mem' := fun x =>
(mem_or_inv_mem S (g⁻¹ • x)).imp Subring.mem_pointwise_smul_iff_inv_smul_mem.mpr fun h =>
Subring.mem_pointwise_smul_iff_inv_smul_mem.mpr <| by rwa [smul_inv''] }
scoped[Pointwise] attribute [instance] ValuationSubring.pointwiseHasSMul
open scoped Pointwise
@[simp]
theorem coe_pointwise_smul (g : G) (S : ValuationSubring K) : ↑(g • S) = g • (S : Set K) := rfl
@[simp]
theorem pointwise_smul_toSubring (g : G) (S : ValuationSubring K) :
(g • S).toSubring = g • S.toSubring := rfl
/-- The action on a valuation subring corresponding to applying the action to every element.
This is available as an instance in the `Pointwise` locale.
This is a stronger version of `ValuationSubring.pointwiseSMul`. -/
def pointwiseMulAction : MulAction G (ValuationSubring K) :=
toSubring_injective.mulAction toSubring pointwise_smul_toSubring
scoped[Pointwise] attribute [instance] ValuationSubring.pointwiseMulAction
open scoped Pointwise
theorem smul_mem_pointwise_smul (g : G) (x : K) (S : ValuationSubring K) : x ∈ S → g • x ∈ g • S :=
(Set.smul_mem_smul_set : _ → _ ∈ g • (S : Set K))
instance : CovariantClass G (ValuationSubring K) HSMul.hSMul LE.le :=
⟨fun _ _ _ => Set.image_subset _⟩
theorem mem_smul_pointwise_iff_exists (g : G) (x : K) (S : ValuationSubring K) :
x ∈ g • S ↔ ∃ s : K, s ∈ S ∧ g • s = x :=
(Set.mem_smul_set : x ∈ g • (S : Set K) ↔ _)
instance pointwise_central_scalar [MulSemiringAction Gᵐᵒᵖ K] [IsCentralScalar G K] :
IsCentralScalar G (ValuationSubring K) :=
⟨fun g S => toSubring_injective <| op_smul_eq_smul g S.toSubring⟩
@[simp]
theorem smul_mem_pointwise_smul_iff {g : G} {S : ValuationSubring K} {x : K} :
g • x ∈ g • S ↔ x ∈ S := Set.smul_mem_smul_set_iff
theorem mem_pointwise_smul_iff_inv_smul_mem {g : G} {S : ValuationSubring K} {x : K} :
x ∈ g • S ↔ g⁻¹ • x ∈ S := Set.mem_smul_set_iff_inv_smul_mem
theorem mem_inv_pointwise_smul_iff {g : G} {S : ValuationSubring K} {x : K} :
x ∈ g⁻¹ • S ↔ g • x ∈ S := Set.mem_inv_smul_set_iff
@[simp]
theorem pointwise_smul_le_pointwise_smul_iff {g : G} {S T : ValuationSubring K} :
g • S ≤ g • T ↔ S ≤ T := Set.set_smul_subset_set_smul_iff
theorem pointwise_smul_subset_iff {g : G} {S T : ValuationSubring K} : g • S ≤ T ↔ S ≤ g⁻¹ • T :=
Set.set_smul_subset_iff
theorem subset_pointwise_smul_iff {g : G} {S T : ValuationSubring K} : S ≤ g • T ↔ g⁻¹ • S ≤ T :=
Set.subset_set_smul_iff
end PointwiseActions
section
variable {L J : Type*} [Field L] [Field J]
/-- The pullback of a valuation subring `A` along a ring homomorphism `K →+* L`. -/
def comap (A : ValuationSubring L) (f : K →+* L) : ValuationSubring K :=
{ A.toSubring.comap f with mem_or_inv_mem' := fun k => by simp [ValuationSubring.mem_or_inv_mem] }
@[simp]
theorem coe_comap (A : ValuationSubring L) (f : K →+* L) : (A.comap f : Set K) = f ⁻¹' A := rfl
@[simp]
theorem mem_comap {A : ValuationSubring L} {f : K →+* L} {x : K} : x ∈ A.comap f ↔ f x ∈ A :=
Iff.rfl
theorem comap_comap (A : ValuationSubring J) (g : L →+* J) (f : K →+* L) :
(A.comap g).comap f = A.comap (g.comp f) := rfl
end
end ValuationSubring
namespace Valuation
variable {Γ : Type*} [LinearOrderedCommGroupWithZero Γ] (v : Valuation K Γ) (x : Kˣ)
-- @[simp] -- Porting note: not in simpNF
theorem mem_unitGroup_iff : x ∈ v.valuationSubring.unitGroup ↔ v x = 1 :=
(Valuation.isEquiv_iff_val_eq_one _ _).mp (Valuation.isEquiv_valuation_valuationSubring _).symm
end Valuation
|
RingTheory\WittVector\Basic.lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import Mathlib.Algebra.MvPolynomial.Counit
import Mathlib.Algebra.MvPolynomial.Invertible
import Mathlib.RingTheory.WittVector.Defs
/-!
# Witt vectors
This file verifies that the ring operations on `WittVector p R`
satisfy the axioms of a commutative ring.
## Main definitions
* `WittVector.map`: lifts a ring homomorphism `R →+* S` to a ring homomorphism `𝕎 R →+* 𝕎 S`.
* `WittVector.ghostComponent n x`: evaluates the `n`th Witt polynomial
on the first `n` coefficients of `x`, producing a value in `R`.
This is a ring homomorphism.
* `WittVector.ghostMap`: a ring homomorphism `𝕎 R →+* (ℕ → R)`, obtained by packaging
all the ghost components together.
If `p` is invertible in `R`, then the ghost map is an equivalence,
which we use to define the ring operations on `𝕎 R`.
* `WittVector.CommRing`: the ring structure induced by the ghost components.
## Notation
We use notation `𝕎 R`, entered `\bbW`, for the Witt vectors over `R`.
## Implementation details
As we prove that the ghost components respect the ring operations, we face a number of repetitive
proofs. To avoid duplicating code we factor these proofs into a custom tactic, only slightly more
powerful than a tactic macro. This tactic is not particularly useful outside of its applications
in this file.
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
noncomputable section
open MvPolynomial Function
variable {p : ℕ} {R S T : Type*} [CommRing R] [CommRing S] [CommRing T]
variable {α : Type*} {β : Type*}
local notation "𝕎" => WittVector p
local notation "W_" => wittPolynomial p
-- type as `\bbW`
open scoped Witt
namespace WittVector
/-- `f : α → β` induces a map from `𝕎 α` to `𝕎 β` by applying `f` componentwise.
If `f` is a ring homomorphism, then so is `f`, see `WittVector.map f`. -/
def mapFun (f : α → β) : 𝕎 α → 𝕎 β := fun x => mk _ (f ∘ x.coeff)
namespace mapFun
-- Porting note: switched the proof to tactic mode. I think that `ext` was the issue.
theorem injective (f : α → β) (hf : Injective f) : Injective (mapFun f : 𝕎 α → 𝕎 β) := by
intros _ _ h
ext p
exact hf (congr_arg (fun x => coeff x p) h : _)
theorem surjective (f : α → β) (hf : Surjective f) : Surjective (mapFun f : 𝕎 α → 𝕎 β) := fun x =>
⟨mk _ fun n => Classical.choose <| hf <| x.coeff n,
by ext n; simp only [mapFun, coeff_mk, comp_apply, Classical.choose_spec (hf (x.coeff n))]⟩
/-- Auxiliary tactic for showing that `mapFun` respects the ring operations. -/
-- porting note: a very crude port.
macro "map_fun_tac" : tactic => `(tactic| (
ext n
simp only [mapFun, mk, comp_apply, zero_coeff, map_zero,
-- Porting note: the lemmas on the next line do not have the `simp` tag in mathlib4
add_coeff, sub_coeff, mul_coeff, neg_coeff, nsmul_coeff, zsmul_coeff, pow_coeff,
peval, map_aeval, algebraMap_int_eq, coe_eval₂Hom] <;>
try { cases n <;> simp <;> done } <;> -- Porting note: this line solves `one`
apply eval₂Hom_congr (RingHom.ext_int _ _) _ rfl <;>
ext ⟨i, k⟩ <;>
fin_cases i <;> rfl))
variable [Fact p.Prime]
-- Porting note: using `(x y : 𝕎 R)` instead of `(x y : WittVector p R)` produced sorries.
variable (f : R →+* S) (x y : WittVector p R)
-- and until `pow`.
-- We do not tag these lemmas as `@[simp]` because they will be bundled in `map` later on.
theorem zero : mapFun f (0 : 𝕎 R) = 0 := by map_fun_tac
theorem one : mapFun f (1 : 𝕎 R) = 1 := by map_fun_tac
theorem add : mapFun f (x + y) = mapFun f x + mapFun f y := by map_fun_tac
theorem sub : mapFun f (x - y) = mapFun f x - mapFun f y := by map_fun_tac
theorem mul : mapFun f (x * y) = mapFun f x * mapFun f y := by map_fun_tac
theorem neg : mapFun f (-x) = -mapFun f x := by map_fun_tac
theorem nsmul (n : ℕ) (x : WittVector p R) : mapFun f (n • x) = n • mapFun f x := by map_fun_tac
theorem zsmul (z : ℤ) (x : WittVector p R) : mapFun f (z • x) = z • mapFun f x := by map_fun_tac
theorem pow (n : ℕ) : mapFun f (x ^ n) = mapFun f x ^ n := by map_fun_tac
theorem natCast (n : ℕ) : mapFun f (n : 𝕎 R) = n :=
show mapFun f n.unaryCast = (n : WittVector p S) by
induction n <;> simp [*, Nat.unaryCast, add, one, zero] <;> rfl
@[deprecated (since := "2024-04-17")]
alias nat_cast := natCast
theorem intCast (n : ℤ) : mapFun f (n : 𝕎 R) = n :=
show mapFun f n.castDef = (n : WittVector p S) by
cases n <;> simp [*, Int.castDef, add, one, neg, zero, natCast] <;> rfl
@[deprecated (since := "2024-04-17")]
alias int_cast := intCast
end mapFun
end WittVector
namespace WittVector
/-- Evaluates the `n`th Witt polynomial on the first `n` coefficients of `x`,
producing a value in `R`.
This function will be bundled as the ring homomorphism `WittVector.ghostMap`
once the ring structure is available,
but we rely on it to set up the ring structure in the first place. -/
private def ghostFun : 𝕎 R → ℕ → R := fun x n => aeval x.coeff (W_ ℤ n)
section Tactic
open Lean Elab Tactic
/-- An auxiliary tactic for proving that `ghostFun` respects the ring operations. -/
elab "ghost_fun_tac" φ:term "," fn:term : tactic => do
evalTactic (← `(tactic| (
ext n
have := congr_fun (congr_arg (@peval R _ _) (wittStructureInt_prop p $φ n)) $fn
simp only [wittZero, OfNat.ofNat, Zero.zero, wittOne, One.one,
HAdd.hAdd, Add.add, HSub.hSub, Sub.sub, Neg.neg, HMul.hMul, Mul.mul,HPow.hPow, Pow.pow,
wittNSMul, wittZSMul, HSMul.hSMul, SMul.smul]
simpa (config := { unfoldPartialApp := true }) [WittVector.ghostFun, aeval_rename, aeval_bind₁,
comp, uncurry, peval, eval] using this
)))
end Tactic
section GhostFun
-- The following lemmas are not `@[simp]` because they will be bundled in `ghostMap` later on.
@[local simp]
theorem matrix_vecEmpty_coeff {R} (i j) :
@coeff p R (Matrix.vecEmpty i) j = (Matrix.vecEmpty i : ℕ → R) j := by
rcases i with ⟨_ | _ | _ | _ | i_val, ⟨⟩⟩
variable [Fact p.Prime]
variable (x y : WittVector p R)
private theorem ghostFun_zero : ghostFun (0 : 𝕎 R) = 0 := by
ghost_fun_tac 0, ![]
private theorem ghostFun_one : ghostFun (1 : 𝕎 R) = 1 := by
ghost_fun_tac 1, ![]
private theorem ghostFun_add : ghostFun (x + y) = ghostFun x + ghostFun y := by
ghost_fun_tac X 0 + X 1, ![x.coeff, y.coeff]
private theorem ghostFun_natCast (i : ℕ) : ghostFun (i : 𝕎 R) = i :=
show ghostFun i.unaryCast = _ by
induction i <;>
simp [*, Nat.unaryCast, ghostFun_zero, ghostFun_one, ghostFun_add, -Pi.natCast_def]
@[deprecated (since := "2024-04-17")]
alias ghostFun_nat_cast := ghostFun_natCast
private theorem ghostFun_sub : ghostFun (x - y) = ghostFun x - ghostFun y := by
ghost_fun_tac X 0 - X 1, ![x.coeff, y.coeff]
private theorem ghostFun_mul : ghostFun (x * y) = ghostFun x * ghostFun y := by
ghost_fun_tac X 0 * X 1, ![x.coeff, y.coeff]
private theorem ghostFun_neg : ghostFun (-x) = -ghostFun x := by ghost_fun_tac -X 0, ![x.coeff]
private theorem ghostFun_intCast (i : ℤ) : ghostFun (i : 𝕎 R) = i :=
show ghostFun i.castDef = _ by
cases i <;> simp [*, Int.castDef, ghostFun_natCast, ghostFun_neg, -Pi.natCast_def,
-Pi.intCast_def]
@[deprecated (since := "2024-04-17")]
alias ghostFun_int_cast := ghostFun_intCast
private lemma ghostFun_nsmul (m : ℕ) (x : WittVector p R) : ghostFun (m • x) = m • ghostFun x := by
ghost_fun_tac m • (X 0), ![x.coeff]
private lemma ghostFun_zsmul (m : ℤ) (x : WittVector p R) : ghostFun (m • x) = m • ghostFun x := by
ghost_fun_tac m • (X 0), ![x.coeff]
private theorem ghostFun_pow (m : ℕ) : ghostFun (x ^ m) = ghostFun x ^ m := by
ghost_fun_tac X 0 ^ m, ![x.coeff]
end GhostFun
variable (p) (R)
/-- The bijection between `𝕎 R` and `ℕ → R`, under the assumption that `p` is invertible in `R`.
In `WittVector.ghostEquiv` we upgrade this to an isomorphism of rings. -/
private def ghostEquiv' [Invertible (p : R)] : 𝕎 R ≃ (ℕ → R) where
toFun := ghostFun
invFun x := mk p fun n => aeval x (xInTermsOfW p R n)
left_inv := by
intro x
ext n
have := bind₁_wittPolynomial_xInTermsOfW p R n
apply_fun aeval x.coeff at this
simpa (config := { unfoldPartialApp := true }) only [aeval_bind₁, aeval_X, ghostFun,
aeval_wittPolynomial]
right_inv := by
intro x
ext n
have := bind₁_xInTermsOfW_wittPolynomial p R n
apply_fun aeval x at this
simpa only [aeval_bind₁, aeval_X, ghostFun, aeval_wittPolynomial]
variable [Fact p.Prime]
@[local instance]
private def comm_ring_aux₁ : CommRing (𝕎 (MvPolynomial R ℚ)) :=
(ghostEquiv' p (MvPolynomial R ℚ)).injective.commRing ghostFun ghostFun_zero ghostFun_one
ghostFun_add ghostFun_mul ghostFun_neg ghostFun_sub ghostFun_nsmul ghostFun_zsmul
ghostFun_pow ghostFun_natCast ghostFun_intCast
@[local instance]
private abbrev comm_ring_aux₂ : CommRing (𝕎 (MvPolynomial R ℤ)) :=
(mapFun.injective _ <| map_injective (Int.castRingHom ℚ) Int.cast_injective).commRing _
(mapFun.zero _) (mapFun.one _) (mapFun.add _) (mapFun.mul _) (mapFun.neg _) (mapFun.sub _)
(mapFun.nsmul _) (mapFun.zsmul _) (mapFun.pow _) (mapFun.natCast _) (mapFun.intCast _)
/-- The commutative ring structure on `𝕎 R`. -/
instance : CommRing (𝕎 R) :=
(mapFun.surjective _ <| counit_surjective _).commRing (mapFun <| MvPolynomial.counit _)
(mapFun.zero _) (mapFun.one _) (mapFun.add _) (mapFun.mul _) (mapFun.neg _) (mapFun.sub _)
(mapFun.nsmul _) (mapFun.zsmul _) (mapFun.pow _) (mapFun.natCast _) (mapFun.intCast _)
variable {p R}
/-- `WittVector.map f` is the ring homomorphism `𝕎 R →+* 𝕎 S` naturally induced
by a ring homomorphism `f : R →+* S`. It acts coefficientwise. -/
noncomputable def map (f : R →+* S) : 𝕎 R →+* 𝕎 S where
toFun := mapFun f
map_zero' := mapFun.zero f
map_one' := mapFun.one f
map_add' := mapFun.add f
map_mul' := mapFun.mul f
theorem map_injective (f : R →+* S) (hf : Injective f) : Injective (map f : 𝕎 R → 𝕎 S) :=
mapFun.injective f hf
theorem map_surjective (f : R →+* S) (hf : Surjective f) : Surjective (map f : 𝕎 R → 𝕎 S) :=
mapFun.surjective f hf
@[simp]
theorem map_coeff (f : R →+* S) (x : 𝕎 R) (n : ℕ) : (map f x).coeff n = f (x.coeff n) :=
rfl
/-- `WittVector.ghostMap` is a ring homomorphism that maps each Witt vector
to the sequence of its ghost components. -/
def ghostMap : 𝕎 R →+* ℕ → R where
toFun := ghostFun
map_zero' := ghostFun_zero
map_one' := ghostFun_one
map_add' := ghostFun_add
map_mul' := ghostFun_mul
/-- Evaluates the `n`th Witt polynomial on the first `n` coefficients of `x`,
producing a value in `R`. -/
def ghostComponent (n : ℕ) : 𝕎 R →+* R :=
(Pi.evalRingHom _ n).comp ghostMap
theorem ghostComponent_apply (n : ℕ) (x : 𝕎 R) : ghostComponent n x = aeval x.coeff (W_ ℤ n) :=
rfl
@[simp]
theorem ghostMap_apply (x : 𝕎 R) (n : ℕ) : ghostMap x n = ghostComponent n x :=
rfl
section Invertible
variable (p R)
variable [Invertible (p : R)]
/-- `WittVector.ghostMap` is a ring isomorphism when `p` is invertible in `R`. -/
def ghostEquiv : 𝕎 R ≃+* (ℕ → R) :=
{ (ghostMap : 𝕎 R →+* ℕ → R), ghostEquiv' p R with }
@[simp]
theorem ghostEquiv_coe : (ghostEquiv p R : 𝕎 R →+* ℕ → R) = ghostMap :=
rfl
theorem ghostMap.bijective_of_invertible : Function.Bijective (ghostMap : 𝕎 R → ℕ → R) :=
(ghostEquiv p R).bijective
end Invertible
/-- `WittVector.coeff x 0` as a `RingHom` -/
@[simps]
noncomputable def constantCoeff : 𝕎 R →+* R where
toFun x := x.coeff 0
map_zero' := by simp
map_one' := by simp
map_add' := add_coeff_zero
map_mul' := mul_coeff_zero
instance [Nontrivial R] : Nontrivial (𝕎 R) :=
constantCoeff.domain_nontrivial
end WittVector
|
RingTheory\WittVector\Compare.lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import Mathlib.RingTheory.WittVector.Truncated
import Mathlib.RingTheory.WittVector.Identities
import Mathlib.NumberTheory.Padics.RingHoms
/-!
# Comparison isomorphism between `WittVector p (ZMod p)` and `ℤ_[p]`
We construct a ring isomorphism between `WittVector p (ZMod p)` and `ℤ_[p]`.
This isomorphism follows from the fact that both satisfy the universal property
of the inverse limit of `ZMod (p^n)`.
## Main declarations
* `WittVector.toZModPow`: a family of compatible ring homs `𝕎 (ZMod p) → ZMod (p^k)`
* `WittVector.equiv`: the isomorphism
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
noncomputable section
variable {p : ℕ} [hp : Fact p.Prime]
local notation "𝕎" => WittVector p
namespace TruncatedWittVector
variable (p) (n : ℕ) (R : Type*) [CommRing R]
theorem eq_of_le_of_cast_pow_eq_zero [CharP R p] (i : ℕ) (hin : i ≤ n)
(hpi : (p : TruncatedWittVector p n R) ^ i = 0) : i = n := by
contrapose! hpi
replace hin := lt_of_le_of_ne hin hpi; clear hpi
have : (p : TruncatedWittVector p n R) ^ i = WittVector.truncate n ((p : 𝕎 R) ^ i) := by
rw [RingHom.map_pow, map_natCast]
rw [this, ne_eq, TruncatedWittVector.ext_iff, not_forall]; clear this
use ⟨i, hin⟩
rw [WittVector.coeff_truncate, coeff_zero, Fin.val_mk, WittVector.coeff_p_pow]
haveI : Nontrivial R := CharP.nontrivial_of_char_ne_one hp.1.ne_one
exact one_ne_zero
section Iso
variable {R}
theorem card_zmod : Fintype.card (TruncatedWittVector p n (ZMod p)) = p ^ n := by
rw [card, ZMod.card]
theorem charP_zmod : CharP (TruncatedWittVector p n (ZMod p)) (p ^ n) :=
charP_of_prime_pow_injective _ _ _ (card_zmod _ _) (eq_of_le_of_cast_pow_eq_zero p n (ZMod p))
attribute [local instance] charP_zmod
/-- The unique isomorphism between `ZMod p^n` and `TruncatedWittVector p n (ZMod p)`.
This isomorphism exists, because `TruncatedWittVector p n (ZMod p)` is a finite ring
with characteristic and cardinality `p^n`.
-/
def zmodEquivTrunc : ZMod (p ^ n) ≃+* TruncatedWittVector p n (ZMod p) :=
ZMod.ringEquiv (TruncatedWittVector p n (ZMod p)) (card_zmod _ _)
theorem zmodEquivTrunc_apply {x : ZMod (p ^ n)} :
zmodEquivTrunc p n x = ZMod.castHom (by rfl) (TruncatedWittVector p n (ZMod p)) x :=
rfl
/-- The following diagram commutes:
```text
ZMod (p^n) ----------------------------> ZMod (p^m)
| |
| |
v v
TruncatedWittVector p n (ZMod p) ----> TruncatedWittVector p m (ZMod p)
```
Here the vertical arrows are `TruncatedWittVector.zmodEquivTrunc`,
the horizontal arrow at the top is `ZMod.castHom`,
and the horizontal arrow at the bottom is `TruncatedWittVector.truncate`.
-/
theorem commutes {m : ℕ} (hm : n ≤ m) :
(truncate hm).comp (zmodEquivTrunc p m).toRingHom =
(zmodEquivTrunc p n).toRingHom.comp (ZMod.castHom (pow_dvd_pow p hm) _) :=
RingHom.ext_zmod _ _
theorem commutes' {m : ℕ} (hm : n ≤ m) (x : ZMod (p ^ m)) :
truncate hm (zmodEquivTrunc p m x) = zmodEquivTrunc p n (ZMod.castHom (pow_dvd_pow p hm) _ x) :=
show (truncate hm).comp (zmodEquivTrunc p m).toRingHom x = _ by rw [commutes _ _ hm]; rfl
theorem commutes_symm' {m : ℕ} (hm : n ≤ m) (x : TruncatedWittVector p m (ZMod p)) :
(zmodEquivTrunc p n).symm (truncate hm x) =
ZMod.castHom (pow_dvd_pow p hm) _ ((zmodEquivTrunc p m).symm x) := by
apply (zmodEquivTrunc p n).injective
rw [← commutes' _ _ hm]
simp
/-- The following diagram commutes:
```text
TruncatedWittVector p n (ZMod p) ----> TruncatedWittVector p m (ZMod p)
| |
| |
v v
ZMod (p^n) ----------------------------> ZMod (p^m)
```
Here the vertical arrows are `(TruncatedWittVector.zmodEquivTrunc p _).symm`,
the horizontal arrow at the top is `ZMod.castHom`,
and the horizontal arrow at the bottom is `TruncatedWittVector.truncate`.
-/
theorem commutes_symm {m : ℕ} (hm : n ≤ m) :
(zmodEquivTrunc p n).symm.toRingHom.comp (truncate hm) =
(ZMod.castHom (pow_dvd_pow p hm) _).comp (zmodEquivTrunc p m).symm.toRingHom := by
ext; apply commutes_symm'
end Iso
end TruncatedWittVector
namespace WittVector
open TruncatedWittVector
variable (p)
/-- `toZModPow` is a family of compatible ring homs. We get this family by composing
`TruncatedWittVector.zmodEquivTrunc` (in right-to-left direction) with `WittVector.truncate`. -/
def toZModPow (k : ℕ) : 𝕎 (ZMod p) →+* ZMod (p ^ k) :=
(zmodEquivTrunc p k).symm.toRingHom.comp (truncate k)
theorem toZModPow_compat (m n : ℕ) (h : m ≤ n) :
(ZMod.castHom (pow_dvd_pow p h) (ZMod (p ^ m))).comp (toZModPow p n) = toZModPow p m :=
calc
(ZMod.castHom _ (ZMod (p ^ m))).comp ((zmodEquivTrunc p n).symm.toRingHom.comp (truncate n))
_ = ((zmodEquivTrunc p m).symm.toRingHom.comp (TruncatedWittVector.truncate h)).comp
(truncate n) := by
rw [commutes_symm, RingHom.comp_assoc]
_ = (zmodEquivTrunc p m).symm.toRingHom.comp (truncate m) := by
rw [RingHom.comp_assoc, truncate_comp_wittVector_truncate]
/-- `toPadicInt` lifts `toZModPow : 𝕎 (ZMod p) →+* ZMod (p ^ k)` to a ring hom to `ℤ_[p]`
using `PadicInt.lift`, the universal property of `ℤ_[p]`.
-/
def toPadicInt : 𝕎 (ZMod p) →+* ℤ_[p] :=
PadicInt.lift <| toZModPow_compat p
theorem zmodEquivTrunc_compat (k₁ k₂ : ℕ) (hk : k₁ ≤ k₂) :
(TruncatedWittVector.truncate hk).comp
((zmodEquivTrunc p k₂).toRingHom.comp (PadicInt.toZModPow k₂)) =
(zmodEquivTrunc p k₁).toRingHom.comp (PadicInt.toZModPow k₁) := by
rw [← RingHom.comp_assoc, commutes, RingHom.comp_assoc,
PadicInt.zmod_cast_comp_toZModPow _ _ hk]
/-- `fromPadicInt` uses `WittVector.lift` to lift `TruncatedWittVector.zmodEquivTrunc`
composed with `PadicInt.toZModPow` to a ring hom `ℤ_[p] →+* 𝕎 (ZMod p)`.
-/
def fromPadicInt : ℤ_[p] →+* 𝕎 (ZMod p) :=
(WittVector.lift fun k => (zmodEquivTrunc p k).toRingHom.comp (PadicInt.toZModPow k)) <|
zmodEquivTrunc_compat _
theorem toPadicInt_comp_fromPadicInt : (toPadicInt p).comp (fromPadicInt p) = RingHom.id ℤ_[p] := by
rw [← PadicInt.toZModPow_eq_iff_ext]
intro n
rw [← RingHom.comp_assoc, toPadicInt, PadicInt.lift_spec]
simp only [fromPadicInt, toZModPow, RingHom.comp_id]
rw [RingHom.comp_assoc, truncate_comp_lift, ← RingHom.comp_assoc]
simp only [RingEquiv.symm_toRingHom_comp_toRingHom, RingHom.id_comp]
theorem toPadicInt_comp_fromPadicInt_ext (x) :
(toPadicInt p).comp (fromPadicInt p) x = RingHom.id ℤ_[p] x := by
rw [toPadicInt_comp_fromPadicInt]
theorem fromPadicInt_comp_toPadicInt :
(fromPadicInt p).comp (toPadicInt p) = RingHom.id (𝕎 (ZMod p)) := by
apply WittVector.hom_ext
intro n
rw [fromPadicInt, ← RingHom.comp_assoc, truncate_comp_lift, RingHom.comp_assoc]
simp only [toPadicInt, toZModPow, RingHom.comp_id, PadicInt.lift_spec, RingHom.id_comp, ←
RingHom.comp_assoc, RingEquiv.toRingHom_comp_symm_toRingHom]
theorem fromPadicInt_comp_toPadicInt_ext (x) :
(fromPadicInt p).comp (toPadicInt p) x = RingHom.id (𝕎 (ZMod p)) x := by
rw [fromPadicInt_comp_toPadicInt]
/-- The ring of Witt vectors over `ZMod p` is isomorphic to the ring of `p`-adic integers. This
equivalence is witnessed by `WittVector.toPadicInt` with inverse `WittVector.fromPadicInt`.
-/
def equiv : 𝕎 (ZMod p) ≃+* ℤ_[p] where
toFun := toPadicInt p
invFun := fromPadicInt p
left_inv := fromPadicInt_comp_toPadicInt_ext _
right_inv := toPadicInt_comp_fromPadicInt_ext _
map_mul' := RingHom.map_mul _
map_add' := RingHom.map_add _
end WittVector
|
RingTheory\WittVector\Defs.lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import Mathlib.RingTheory.WittVector.StructurePolynomial
/-!
# Witt vectors
In this file we define the type of `p`-typical Witt vectors and ring operations on it.
The ring axioms are verified in `Mathlib/RingTheory/WittVector/Basic.lean`.
For a fixed commutative ring `R` and prime `p`,
a Witt vector `x : 𝕎 R` is an infinite sequence `ℕ → R` of elements of `R`.
However, the ring operations `+` and `*` are not defined in the obvious component-wise way.
Instead, these operations are defined via certain polynomials
using the machinery in `Mathlib/RingTheory/WittVector/StructurePolynomial.lean`.
The `n`th value of the sum of two Witt vectors can depend on the `0`-th through `n`th values
of the summands. This effectively simulates a “carrying” operation.
## Main definitions
* `WittVector p R`: the type of `p`-typical Witt vectors with coefficients in `R`.
* `WittVector.coeff x n`: projects the `n`th value of the Witt vector `x`.
## Notation
We use notation `𝕎 R`, entered `\bbW`, for the Witt vectors over `R`.
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
noncomputable section
/-- `WittVector p R` is the ring of `p`-typical Witt vectors over the commutative ring `R`,
where `p` is a prime number.
If `p` is invertible in `R`, this ring is isomorphic to `ℕ → R` (the product of `ℕ` copies of `R`).
If `R` is a ring of characteristic `p`, then `WittVector p R` is a ring of characteristic `0`.
The canonical example is `WittVector p (ZMod p)`,
which is isomorphic to the `p`-adic integers `ℤ_[p]`. -/
structure WittVector (p : ℕ) (R : Type*) where mk' ::
/-- `x.coeff n` is the `n`th coefficient of the Witt vector `x`.
This concept does not have a standard name in the literature.
-/
coeff : ℕ → R
-- Porting note: added to make the `p` argument explicit
/-- Construct a Witt vector `mk p x : 𝕎 R` from a sequence `x` of elements of `R`. -/
def WittVector.mk (p : ℕ) {R : Type*} (coeff : ℕ → R) : WittVector p R := mk' coeff
variable {p : ℕ}
/- We cannot make this `localized` notation, because the `p` on the RHS doesn't occur on the left
Hiding the `p` in the notation is very convenient, so we opt for repeating the `local notation`
in other files that use Witt vectors. -/
local notation "𝕎" => WittVector p -- type as `\bbW`
namespace WittVector
variable {R : Type*}
@[ext]
theorem ext {x y : 𝕎 R} (h : ∀ n, x.coeff n = y.coeff n) : x = y := by
cases x
cases y
simp only at h
simp [Function.funext_iff, h]
variable (p)
theorem coeff_mk (x : ℕ → R) : (mk p x).coeff = x :=
rfl
/- These instances are not needed for the rest of the development,
but it is interesting to establish early on that `WittVector p` is a lawful functor. -/
instance : Functor (WittVector p) where
map f v := mk p (f ∘ v.coeff)
mapConst a _ := mk p fun _ => a
instance : LawfulFunctor (WittVector p) where
map_const := rfl
-- Porting note: no longer needs to deconstruct `v` to conclude `{coeff := v.coeff} = v`
id_map _ := rfl
comp_map _ _ _ := rfl
variable [hp : Fact p.Prime] [CommRing R]
open MvPolynomial
section RingOperations
/-- The polynomials used for defining the element `0` of the ring of Witt vectors. -/
def wittZero : ℕ → MvPolynomial (Fin 0 × ℕ) ℤ :=
wittStructureInt p 0
/-- The polynomials used for defining the element `1` of the ring of Witt vectors. -/
def wittOne : ℕ → MvPolynomial (Fin 0 × ℕ) ℤ :=
wittStructureInt p 1
/-- The polynomials used for defining the addition of the ring of Witt vectors. -/
def wittAdd : ℕ → MvPolynomial (Fin 2 × ℕ) ℤ :=
wittStructureInt p (X 0 + X 1)
/-- The polynomials used for defining repeated addition of the ring of Witt vectors. -/
def wittNSMul (n : ℕ) : ℕ → MvPolynomial (Fin 1 × ℕ) ℤ :=
wittStructureInt p (n • X (0 : (Fin 1)))
/-- The polynomials used for defining repeated addition of the ring of Witt vectors. -/
def wittZSMul (n : ℤ) : ℕ → MvPolynomial (Fin 1 × ℕ) ℤ :=
wittStructureInt p (n • X (0 : (Fin 1)))
/-- The polynomials used for describing the subtraction of the ring of Witt vectors. -/
def wittSub : ℕ → MvPolynomial (Fin 2 × ℕ) ℤ :=
wittStructureInt p (X 0 - X 1)
/-- The polynomials used for defining the multiplication of the ring of Witt vectors. -/
def wittMul : ℕ → MvPolynomial (Fin 2 × ℕ) ℤ :=
wittStructureInt p (X 0 * X 1)
/-- The polynomials used for defining the negation of the ring of Witt vectors. -/
def wittNeg : ℕ → MvPolynomial (Fin 1 × ℕ) ℤ :=
wittStructureInt p (-X 0)
/-- The polynomials used for defining repeated addition of the ring of Witt vectors. -/
def wittPow (n : ℕ) : ℕ → MvPolynomial (Fin 1 × ℕ) ℤ :=
wittStructureInt p (X 0 ^ n)
variable {p}
/-- An auxiliary definition used in `WittVector.eval`.
Evaluates a polynomial whose variables come from the disjoint union of `k` copies of `ℕ`,
with a curried evaluation `x`.
This can be defined more generally but we use only a specific instance here. -/
def peval {k : ℕ} (φ : MvPolynomial (Fin k × ℕ) ℤ) (x : Fin k → ℕ → R) : R :=
aeval (Function.uncurry x) φ
/-- Let `φ` be a family of polynomials, indexed by natural numbers, whose variables come from the
disjoint union of `k` copies of `ℕ`, and let `xᵢ` be a Witt vector for `0 ≤ i < k`.
`eval φ x` evaluates `φ` mapping the variable `X_(i, n)` to the `n`th coefficient of `xᵢ`.
Instantiating `φ` with certain polynomials defined in
`Mathlib/RingTheory/WittVector/StructurePolynomial.lean` establishes the
ring operations on `𝕎 R`. For example, `WittVector.wittAdd` is such a `φ` with `k = 2`;
evaluating this at `(x₀, x₁)` gives us the sum of two Witt vectors `x₀ + x₁`.
-/
def eval {k : ℕ} (φ : ℕ → MvPolynomial (Fin k × ℕ) ℤ) (x : Fin k → 𝕎 R) : 𝕎 R :=
mk p fun n => peval (φ n) fun i => (x i).coeff
variable (R) [Fact p.Prime]
instance : Zero (𝕎 R) :=
⟨eval (wittZero p) ![]⟩
instance : Inhabited (𝕎 R) :=
⟨0⟩
instance : One (𝕎 R) :=
⟨eval (wittOne p) ![]⟩
instance : Add (𝕎 R) :=
⟨fun x y => eval (wittAdd p) ![x, y]⟩
instance : Sub (𝕎 R) :=
⟨fun x y => eval (wittSub p) ![x, y]⟩
instance hasNatScalar : SMul ℕ (𝕎 R) :=
⟨fun n x => eval (wittNSMul p n) ![x]⟩
instance hasIntScalar : SMul ℤ (𝕎 R) :=
⟨fun n x => eval (wittZSMul p n) ![x]⟩
instance : Mul (𝕎 R) :=
⟨fun x y => eval (wittMul p) ![x, y]⟩
instance : Neg (𝕎 R) :=
⟨fun x => eval (wittNeg p) ![x]⟩
instance hasNatPow : Pow (𝕎 R) ℕ :=
⟨fun x n => eval (wittPow p n) ![x]⟩
instance : NatCast (𝕎 R) :=
⟨Nat.unaryCast⟩
instance : IntCast (𝕎 R) :=
⟨Int.castDef⟩
end RingOperations
section WittStructureSimplifications
@[simp]
theorem wittZero_eq_zero (n : ℕ) : wittZero p n = 0 := by
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
simp only [wittZero, wittStructureRat, bind₁, aeval_zero', constantCoeff_xInTermsOfW, map_zero,
map_wittStructureInt]
@[simp]
theorem wittOne_zero_eq_one : wittOne p 0 = 1 := by
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
simp only [wittOne, wittStructureRat, xInTermsOfW_zero, map_one, bind₁_X_right,
map_wittStructureInt]
@[simp]
theorem wittOne_pos_eq_zero (n : ℕ) (hn : 0 < n) : wittOne p n = 0 := by
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
simp only [wittOne, wittStructureRat, RingHom.map_zero, map_one, RingHom.map_one,
map_wittStructureInt]
induction n using Nat.strong_induction_on with | h n IH => ?_
rw [xInTermsOfW_eq]
simp only [map_mul, map_sub, map_sum, map_pow, bind₁_X_right,
bind₁_C_right]
rw [sub_mul, one_mul]
rw [Finset.sum_eq_single 0]
· simp only [invOf_eq_inv, one_mul, inv_pow, tsub_zero, RingHom.map_one, pow_zero]
simp only [one_pow, one_mul, xInTermsOfW_zero, sub_self, bind₁_X_right]
· intro i hin hi0
rw [Finset.mem_range] at hin
rw [IH _ hin (Nat.pos_of_ne_zero hi0), zero_pow (pow_ne_zero _ hp.1.ne_zero), mul_zero]
· rw [Finset.mem_range]; intro; contradiction
@[simp]
theorem wittAdd_zero : wittAdd p 0 = X (0, 0) + X (1, 0) := by
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
simp only [wittAdd, wittStructureRat, map_add, rename_X, xInTermsOfW_zero, map_X,
wittPolynomial_zero, bind₁_X_right, map_wittStructureInt]
@[simp]
theorem wittSub_zero : wittSub p 0 = X (0, 0) - X (1, 0) := by
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
simp only [wittSub, wittStructureRat, map_sub, rename_X, xInTermsOfW_zero, map_X,
wittPolynomial_zero, bind₁_X_right, map_wittStructureInt]
@[simp]
theorem wittMul_zero : wittMul p 0 = X (0, 0) * X (1, 0) := by
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
simp only [wittMul, wittStructureRat, rename_X, xInTermsOfW_zero, map_X, wittPolynomial_zero,
map_mul, bind₁_X_right, map_wittStructureInt]
@[simp]
theorem wittNeg_zero : wittNeg p 0 = -X (0, 0) := by
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
simp only [wittNeg, wittStructureRat, rename_X, xInTermsOfW_zero, map_X, wittPolynomial_zero,
map_neg, bind₁_X_right, map_wittStructureInt]
@[simp]
theorem constantCoeff_wittAdd (n : ℕ) : constantCoeff (wittAdd p n) = 0 := by
apply constantCoeff_wittStructureInt p _ _ n
simp only [add_zero, RingHom.map_add, constantCoeff_X]
@[simp]
theorem constantCoeff_wittSub (n : ℕ) : constantCoeff (wittSub p n) = 0 := by
apply constantCoeff_wittStructureInt p _ _ n
simp only [sub_zero, RingHom.map_sub, constantCoeff_X]
@[simp]
theorem constantCoeff_wittMul (n : ℕ) : constantCoeff (wittMul p n) = 0 := by
apply constantCoeff_wittStructureInt p _ _ n
simp only [mul_zero, RingHom.map_mul, constantCoeff_X]
@[simp]
theorem constantCoeff_wittNeg (n : ℕ) : constantCoeff (wittNeg p n) = 0 := by
apply constantCoeff_wittStructureInt p _ _ n
simp only [neg_zero, RingHom.map_neg, constantCoeff_X]
@[simp]
theorem constantCoeff_wittNSMul (m : ℕ) (n : ℕ) : constantCoeff (wittNSMul p m n) = 0 := by
apply constantCoeff_wittStructureInt p _ _ n
simp only [smul_zero, map_nsmul, constantCoeff_X]
@[simp]
theorem constantCoeff_wittZSMul (z : ℤ) (n : ℕ) : constantCoeff (wittZSMul p z n) = 0 := by
apply constantCoeff_wittStructureInt p _ _ n
simp only [smul_zero, map_zsmul, constantCoeff_X]
end WittStructureSimplifications
section Coeff
variable (R)
@[simp]
theorem zero_coeff (n : ℕ) : (0 : 𝕎 R).coeff n = 0 :=
show (aeval _ (wittZero p n) : R) = 0 by simp only [wittZero_eq_zero, map_zero]
@[simp]
theorem one_coeff_zero : (1 : 𝕎 R).coeff 0 = 1 :=
show (aeval _ (wittOne p 0) : R) = 1 by simp only [wittOne_zero_eq_one, map_one]
@[simp]
theorem one_coeff_eq_of_pos (n : ℕ) (hn : 0 < n) : coeff (1 : 𝕎 R) n = 0 :=
show (aeval _ (wittOne p n) : R) = 0 by simp only [hn, wittOne_pos_eq_zero, map_zero]
variable {p R}
@[simp]
theorem v2_coeff {p' R'} (x y : WittVector p' R') (i : Fin 2) :
(![x, y] i).coeff = ![x.coeff, y.coeff] i := by fin_cases i <;> simp
-- Porting note: the lemmas below needed `coeff_mk` added to the `simp` calls
theorem add_coeff (x y : 𝕎 R) (n : ℕ) :
(x + y).coeff n = peval (wittAdd p n) ![x.coeff, y.coeff] := by
simp [(· + ·), Add.add, eval, coeff_mk]
theorem sub_coeff (x y : 𝕎 R) (n : ℕ) :
(x - y).coeff n = peval (wittSub p n) ![x.coeff, y.coeff] := by
simp [(· - ·), Sub.sub, eval, coeff_mk]
theorem mul_coeff (x y : 𝕎 R) (n : ℕ) :
(x * y).coeff n = peval (wittMul p n) ![x.coeff, y.coeff] := by
simp [(· * ·), Mul.mul, eval, coeff_mk]
theorem neg_coeff (x : 𝕎 R) (n : ℕ) : (-x).coeff n = peval (wittNeg p n) ![x.coeff] := by
simp [Neg.neg, eval, Matrix.cons_fin_one, coeff_mk]
theorem nsmul_coeff (m : ℕ) (x : 𝕎 R) (n : ℕ) :
(m • x).coeff n = peval (wittNSMul p m n) ![x.coeff] := by
simp [(· • ·), SMul.smul, eval, Matrix.cons_fin_one, coeff_mk]
theorem zsmul_coeff (m : ℤ) (x : 𝕎 R) (n : ℕ) :
(m • x).coeff n = peval (wittZSMul p m n) ![x.coeff] := by
simp [(· • ·), SMul.smul, eval, Matrix.cons_fin_one, coeff_mk]
theorem pow_coeff (m : ℕ) (x : 𝕎 R) (n : ℕ) :
(x ^ m).coeff n = peval (wittPow p m n) ![x.coeff] := by
simp [(· ^ ·), Pow.pow, eval, Matrix.cons_fin_one, coeff_mk]
theorem add_coeff_zero (x y : 𝕎 R) : (x + y).coeff 0 = x.coeff 0 + y.coeff 0 := by
simp [add_coeff, peval]
theorem mul_coeff_zero (x y : 𝕎 R) : (x * y).coeff 0 = x.coeff 0 * y.coeff 0 := by
simp [mul_coeff, peval]
end Coeff
theorem wittAdd_vars (n : ℕ) : (wittAdd p n).vars ⊆ Finset.univ ×ˢ Finset.range (n + 1) :=
wittStructureInt_vars _ _ _
theorem wittSub_vars (n : ℕ) : (wittSub p n).vars ⊆ Finset.univ ×ˢ Finset.range (n + 1) :=
wittStructureInt_vars _ _ _
theorem wittMul_vars (n : ℕ) : (wittMul p n).vars ⊆ Finset.univ ×ˢ Finset.range (n + 1) :=
wittStructureInt_vars _ _ _
theorem wittNeg_vars (n : ℕ) : (wittNeg p n).vars ⊆ Finset.univ ×ˢ Finset.range (n + 1) :=
wittStructureInt_vars _ _ _
theorem wittNSMul_vars (m : ℕ) (n : ℕ) :
(wittNSMul p m n).vars ⊆ Finset.univ ×ˢ Finset.range (n + 1) :=
wittStructureInt_vars _ _ _
theorem wittZSMul_vars (m : ℤ) (n : ℕ) :
(wittZSMul p m n).vars ⊆ Finset.univ ×ˢ Finset.range (n + 1) :=
wittStructureInt_vars _ _ _
theorem wittPow_vars (m : ℕ) (n : ℕ) : (wittPow p m n).vars ⊆ Finset.univ ×ˢ Finset.range (n + 1) :=
wittStructureInt_vars _ _ _
end WittVector
|
RingTheory\WittVector\DiscreteValuationRing.lean | /-
Copyright (c) 2022 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Heather Macbeth, Johan Commelin
-/
import Mathlib.RingTheory.WittVector.Domain
import Mathlib.RingTheory.WittVector.MulCoeff
import Mathlib.RingTheory.DiscreteValuationRing.Basic
import Mathlib.Tactic.LinearCombination
/-!
# Witt vectors over a perfect ring
This file establishes that Witt vectors over a perfect field are a discrete valuation ring.
When `k` is a perfect ring, a nonzero `a : 𝕎 k` can be written as `p^m * b` for some `m : ℕ` and
`b : 𝕎 k` with nonzero 0th coefficient.
When `k` is also a field, this `b` can be chosen to be a unit of `𝕎 k`.
## Main declarations
* `WittVector.exists_eq_pow_p_mul`: the existence of this element `b` over a perfect ring
* `WittVector.exists_eq_pow_p_mul'`: the existence of this unit `b` over a perfect field
* `WittVector.discreteValuationRing`: `𝕎 k` is a discrete valuation ring if `k` is a perfect field
-/
noncomputable section
namespace WittVector
variable {p : ℕ} [hp : Fact p.Prime]
local notation "𝕎" => WittVector p
section CommRing
variable {k : Type*} [CommRing k] [CharP k p]
/-- This is the `n+1`st coefficient of our inverse. -/
def succNthValUnits (n : ℕ) (a : Units k) (A : 𝕎 k) (bs : Fin (n + 1) → k) : k :=
-↑(a⁻¹ ^ p ^ (n + 1)) *
(A.coeff (n + 1) * ↑(a⁻¹ ^ p ^ (n + 1)) + nthRemainder p n (truncateFun (n + 1) A) bs)
/--
Recursively defines the sequence of coefficients for the inverse to a Witt vector whose first entry
is a unit.
-/
noncomputable def inverseCoeff (a : Units k) (A : 𝕎 k) : ℕ → k
| 0 => ↑a⁻¹
| n + 1 => succNthValUnits n a A fun i => inverseCoeff a A i.val
/--
Upgrade a Witt vector `A` whose first entry `A.coeff 0` is a unit to be, itself, a unit in `𝕎 k`.
-/
def mkUnit {a : Units k} {A : 𝕎 k} (hA : A.coeff 0 = a) : Units (𝕎 k) :=
Units.mkOfMulEqOne A (@WittVector.mk' p _ (inverseCoeff a A)) (by
ext n
induction' n with n _
· simp [WittVector.mul_coeff_zero, inverseCoeff, hA]
let H_coeff := A.coeff (n + 1) * ↑(a⁻¹ ^ p ^ (n + 1)) +
nthRemainder p n (truncateFun (n + 1) A) fun i : Fin (n + 1) => inverseCoeff a A i
have H := Units.mul_inv (a ^ p ^ (n + 1))
linear_combination (norm := skip) -H_coeff * H
have ha : (a : k) ^ p ^ (n + 1) = ↑(a ^ p ^ (n + 1)) := by norm_cast
have ha_inv : (↑a⁻¹ : k) ^ p ^ (n + 1) = ↑(a ^ p ^ (n + 1))⁻¹ := by norm_cast
simp only [nthRemainder_spec, inverseCoeff, succNthValUnits, hA,
one_coeff_eq_of_pos, Nat.succ_pos', ha_inv, ha, inv_pow]
ring!)
@[simp]
theorem coe_mkUnit {a : Units k} {A : 𝕎 k} (hA : A.coeff 0 = a) : (mkUnit hA : 𝕎 k) = A :=
rfl
end CommRing
section Field
variable {k : Type*} [Field k] [CharP k p]
theorem isUnit_of_coeff_zero_ne_zero (x : 𝕎 k) (hx : x.coeff 0 ≠ 0) : IsUnit x := by
let y : kˣ := Units.mk0 (x.coeff 0) hx
have hy : x.coeff 0 = y := rfl
exact (mkUnit hy).isUnit
variable (p)
theorem irreducible : Irreducible (p : 𝕎 k) := by
have hp : ¬IsUnit (p : 𝕎 k) := by
intro hp
simpa only [constantCoeff_apply, coeff_p_zero, not_isUnit_zero] using
(constantCoeff : WittVector p k →+* _).isUnit_map hp
refine ⟨hp, fun a b hab => ?_⟩
obtain ⟨ha0, hb0⟩ : a ≠ 0 ∧ b ≠ 0 := by
rw [← mul_ne_zero_iff]; intro h; rw [h] at hab; exact p_nonzero p k hab
obtain ⟨m, a, ha, rfl⟩ := verschiebung_nonzero ha0
obtain ⟨n, b, hb, rfl⟩ := verschiebung_nonzero hb0
cases m; · exact Or.inl (isUnit_of_coeff_zero_ne_zero a ha)
cases' n with n; · exact Or.inr (isUnit_of_coeff_zero_ne_zero b hb)
rw [iterate_verschiebung_mul] at hab
apply_fun fun x => coeff x 1 at hab
simp only [coeff_p_one, Nat.add_succ, add_comm _ n, Function.iterate_succ', Function.comp_apply,
verschiebung_coeff_add_one, verschiebung_coeff_zero] at hab
exact (one_ne_zero hab).elim
end Field
section PerfectRing
variable {k : Type*} [CommRing k] [CharP k p] [PerfectRing k p]
theorem exists_eq_pow_p_mul (a : 𝕎 k) (ha : a ≠ 0) :
∃ (m : ℕ) (b : 𝕎 k), b.coeff 0 ≠ 0 ∧ a = (p : 𝕎 k) ^ m * b := by
obtain ⟨m, c, hc, hcm⟩ := WittVector.verschiebung_nonzero ha
obtain ⟨b, rfl⟩ := (frobenius_bijective p k).surjective.iterate m c
rw [WittVector.iterate_frobenius_coeff] at hc
have := congr_fun (WittVector.verschiebung_frobenius_comm.comp_iterate m) b
simp only [Function.comp_apply] at this
rw [← this] at hcm
refine ⟨m, b, ?_, ?_⟩
· contrapose! hc
simp [hc, zero_pow $ pow_ne_zero _ hp.out.ne_zero]
· simp_rw [← mul_left_iterate (p : 𝕎 k) m]
convert hcm using 2
ext1 x
rw [mul_comm, ← WittVector.verschiebung_frobenius x]; rfl
end PerfectRing
section PerfectField
variable {k : Type*} [Field k] [CharP k p] [PerfectRing k p]
theorem exists_eq_pow_p_mul' (a : 𝕎 k) (ha : a ≠ 0) :
∃ (m : ℕ) (b : Units (𝕎 k)), a = (p : 𝕎 k) ^ m * b := by
obtain ⟨m, b, h₁, h₂⟩ := exists_eq_pow_p_mul a ha
let b₀ := Units.mk0 (b.coeff 0) h₁
have hb₀ : b.coeff 0 = b₀ := rfl
exact ⟨m, mkUnit hb₀, h₂⟩
/-
Note: The following lemma should be an instance, but it seems to cause some
exponential blowups in certain typeclass resolution problems.
See the following Lean4 issue as well as the zulip discussion linked there:
https://github.com/leanprover/lean4/issues/1102
-/
/-- The ring of Witt Vectors of a perfect field of positive characteristic is a DVR.
-/
theorem discreteValuationRing : DiscreteValuationRing (𝕎 k) :=
DiscreteValuationRing.ofHasUnitMulPowIrreducibleFactorization (by
refine ⟨p, irreducible p, fun {x} hx => ?_⟩
obtain ⟨n, b, hb⟩ := exists_eq_pow_p_mul' x hx
exact ⟨n, b, hb.symm⟩)
end PerfectField
end WittVector
|
RingTheory\WittVector\Domain.lean | /-
Copyright (c) 2022 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis
-/
import Mathlib.RingTheory.WittVector.Identities
/-!
# Witt vectors over a domain
This file builds to the proof `WittVector.instIsDomain`,
an instance that says if `R` is an integral domain, then so is `𝕎 R`.
It depends on the API around iterated applications
of `WittVector.verschiebung` and `WittVector.frobenius`
found in `Identities.lean`.
The [proof sketch](https://math.stackexchange.com/questions/4117247/ring-of-witt-vectors-over-an-integral-domain/4118723#4118723)
goes as follows:
any nonzero $x$ is an iterated application of $V$
to some vector $w_x$ whose 0th component is nonzero (`WittVector.verschiebung_nonzero`).
Known identities (`WittVector.iterate_verschiebung_mul`) allow us to transform
the product of two such $x$ and $y$
to the form $V^{m+n}\left(F^n(w_x) \cdot F^m(w_y)\right)$,
the 0th component of which must be nonzero.
## Main declarations
* `WittVector.iterate_verschiebung_mul_coeff` : an identity from [Haze09]
* `WittVector.instIsDomain`
-/
noncomputable section
open scoped Classical
namespace WittVector
open Function
variable {p : ℕ} {R : Type*}
local notation "𝕎" => WittVector p -- type as `\bbW`
/-!
## The `shift` operator
-/
/--
`WittVector.verschiebung` translates the entries of a Witt vector upward, inserting 0s in the gaps.
`WittVector.shift` does the opposite, removing the first entries.
This is mainly useful as an auxiliary construction for `WittVector.verschiebung_nonzero`.
-/
def shift (x : 𝕎 R) (n : ℕ) : 𝕎 R :=
@mk' p R fun i => x.coeff (n + i)
theorem shift_coeff (x : 𝕎 R) (n k : ℕ) : (x.shift n).coeff k = x.coeff (n + k) :=
rfl
variable [hp : Fact p.Prime] [CommRing R]
theorem verschiebung_shift (x : 𝕎 R) (k : ℕ) (h : ∀ i < k + 1, x.coeff i = 0) :
verschiebung (x.shift k.succ) = x.shift k := by
ext ⟨j⟩
· rw [verschiebung_coeff_zero, shift_coeff, h]
apply Nat.lt_succ_self
· simp only [verschiebung_coeff_succ, shift]
congr 1
rw [Nat.add_succ, add_comm, Nat.add_succ, add_comm]
theorem eq_iterate_verschiebung {x : 𝕎 R} {n : ℕ} (h : ∀ i < n, x.coeff i = 0) :
x = verschiebung^[n] (x.shift n) := by
induction' n with k ih
· cases x; simp [shift]
· dsimp; rw [verschiebung_shift]
· exact ih fun i hi => h _ (hi.trans (Nat.lt_succ_self _))
· exact h
theorem verschiebung_nonzero {x : 𝕎 R} (hx : x ≠ 0) :
∃ n : ℕ, ∃ x' : 𝕎 R, x'.coeff 0 ≠ 0 ∧ x = verschiebung^[n] x' := by
have hex : ∃ k : ℕ, x.coeff k ≠ 0 := by
by_contra! hall
apply hx
ext i
simp only [hall, zero_coeff]
let n := Nat.find hex
use n, x.shift n
refine ⟨Nat.find_spec hex, eq_iterate_verschiebung fun i hi => not_not.mp ?_⟩
exact Nat.find_min hex hi
/-!
## Witt vectors over a domain
If `R` is an integral domain, then so is `𝕎 R`.
This argument is adapted from
<https://math.stackexchange.com/questions/4117247/ring-of-witt-vectors-over-an-integral-domain/4118723#4118723>.
-/
instance [CharP R p] [NoZeroDivisors R] : NoZeroDivisors (𝕎 R) :=
⟨fun {x y} => by
contrapose!
rintro ⟨ha, hb⟩
rcases verschiebung_nonzero ha with ⟨na, wa, hwa0, rfl⟩
rcases verschiebung_nonzero hb with ⟨nb, wb, hwb0, rfl⟩
refine ne_of_apply_ne (fun x => x.coeff (na + nb)) ?_
dsimp only
rw [iterate_verschiebung_mul_coeff, zero_coeff]
exact mul_ne_zero (pow_ne_zero _ hwa0) (pow_ne_zero _ hwb0)⟩
instance instIsDomain [CharP R p] [IsDomain R] : IsDomain (𝕎 R) :=
NoZeroDivisors.to_isDomain _
end WittVector
|
RingTheory\WittVector\Frobenius.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.Data.Nat.Multiplicity
import Mathlib.Data.ZMod.Algebra
import Mathlib.RingTheory.WittVector.Basic
import Mathlib.RingTheory.WittVector.IsPoly
import Mathlib.FieldTheory.Perfect
/-!
## The Frobenius operator
If `R` has characteristic `p`, then there is a ring endomorphism `frobenius R p`
that raises `r : R` to the power `p`.
By applying `WittVector.map` to `frobenius R p`, we obtain a ring endomorphism `𝕎 R →+* 𝕎 R`.
It turns out that this endomorphism can be described by polynomials over `ℤ`
that do not depend on `R` or the fact that it has characteristic `p`.
In this way, we obtain a Frobenius endomorphism `WittVector.frobeniusFun : 𝕎 R → 𝕎 R`
for every commutative ring `R`.
Unfortunately, the aforementioned polynomials can not be obtained using the machinery
of `wittStructureInt` that was developed in `StructurePolynomial.lean`.
We therefore have to define the polynomials by hand, and check that they have the required property.
In case `R` has characteristic `p`, we show in `frobenius_eq_map_frobenius`
that `WittVector.frobeniusFun` is equal to `WittVector.map (frobenius R p)`.
### Main definitions and results
* `frobeniusPoly`: the polynomials that describe the coefficients of `frobeniusFun`;
* `frobeniusFun`: the Frobenius endomorphism on Witt vectors;
* `frobeniusFun_isPoly`: the tautological assertion that Frobenius is a polynomial function;
* `frobenius_eq_map_frobenius`: the fact that in characteristic `p`, Frobenius is equal to
`WittVector.map (frobenius R p)`.
TODO: Show that `WittVector.frobeniusFun` is a ring homomorphism,
and bundle it into `WittVector.frobenius`.
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
namespace WittVector
variable {p : ℕ} {R S : Type*} [hp : Fact p.Prime] [CommRing R] [CommRing S]
local notation "𝕎" => WittVector p -- type as `\bbW`
noncomputable section
open MvPolynomial Finset
variable (p)
/-- The rational polynomials that give the coefficients of `frobenius x`,
in terms of the coefficients of `x`.
These polynomials actually have integral coefficients,
see `frobeniusPoly` and `map_frobeniusPoly`. -/
def frobeniusPolyRat (n : ℕ) : MvPolynomial ℕ ℚ :=
bind₁ (wittPolynomial p ℚ ∘ fun n => n + 1) (xInTermsOfW p ℚ n)
theorem bind₁_frobeniusPolyRat_wittPolynomial (n : ℕ) :
bind₁ (frobeniusPolyRat p) (wittPolynomial p ℚ n) = wittPolynomial p ℚ (n + 1) := by
delta frobeniusPolyRat
rw [← bind₁_bind₁, bind₁_xInTermsOfW_wittPolynomial, bind₁_X_right, Function.comp_apply]
/-- An auxiliary definition, to avoid an excessive amount of finiteness proofs
for `multiplicity p n`. -/
private def pnat_multiplicity (n : ℕ+) : ℕ :=
(multiplicity p n).get <| multiplicity.finite_nat_iff.mpr <| ⟨ne_of_gt hp.1.one_lt, n.2⟩
local notation "v" => pnat_multiplicity
/-- An auxiliary polynomial over the integers, that satisfies
`p * (frobeniusPolyAux p n) + X n ^ p = frobeniusPoly p n`.
This makes it easy to show that `frobeniusPoly p n` is congruent to `X n ^ p`
modulo `p`. -/
noncomputable def frobeniusPolyAux : ℕ → MvPolynomial ℕ ℤ
| n => X (n + 1) - ∑ i : Fin n, have _ := i.is_lt
∑ j ∈ range (p ^ (n - i)),
(((X (i : ℕ) ^ p) ^ (p ^ (n - (i : ℕ)) - (j + 1)) : MvPolynomial ℕ ℤ) *
(frobeniusPolyAux i) ^ (j + 1)) *
C (((p ^ (n - i)).choose (j + 1) / (p ^ (n - i - v p ⟨j + 1, Nat.succ_pos j⟩))
* ↑p ^ (j - v p ⟨j + 1, Nat.succ_pos j⟩) : ℕ) : ℤ)
theorem frobeniusPolyAux_eq (n : ℕ) :
frobeniusPolyAux p n =
X (n + 1) - ∑ i ∈ range n,
∑ j ∈ range (p ^ (n - i)),
(X i ^ p) ^ (p ^ (n - i) - (j + 1)) * frobeniusPolyAux p i ^ (j + 1) *
C ↑((p ^ (n - i)).choose (j + 1) / p ^ (n - i - v p ⟨j + 1, Nat.succ_pos j⟩) *
↑p ^ (j - v p ⟨j + 1, Nat.succ_pos j⟩) : ℕ) := by
rw [frobeniusPolyAux, ← Fin.sum_univ_eq_sum_range]
/-- The polynomials that give the coefficients of `frobenius x`,
in terms of the coefficients of `x`. -/
def frobeniusPoly (n : ℕ) : MvPolynomial ℕ ℤ :=
X n ^ p + C (p : ℤ) * frobeniusPolyAux p n
/-
Our next goal is to prove
```
lemma map_frobeniusPoly (n : ℕ) :
MvPolynomial.map (Int.castRingHom ℚ) (frobeniusPoly p n) = frobeniusPolyRat p n
```
This lemma has a rather long proof, but it mostly boils down to applying induction,
and then using the following two key facts at the right point.
-/
/-- A key divisibility fact for the proof of `WittVector.map_frobeniusPoly`. -/
theorem map_frobeniusPoly.key₁ (n j : ℕ) (hj : j < p ^ n) :
p ^ (n - v p ⟨j + 1, j.succ_pos⟩) ∣ (p ^ n).choose (j + 1) := by
apply multiplicity.pow_dvd_of_le_multiplicity
rw [hp.out.multiplicity_choose_prime_pow hj j.succ_ne_zero]
rfl
/-- A key numerical identity needed for the proof of `WittVector.map_frobeniusPoly`. -/
theorem map_frobeniusPoly.key₂ {n i j : ℕ} (hi : i ≤ n) (hj : j < p ^ (n - i)) :
j - v p ⟨j + 1, j.succ_pos⟩ + n = i + j + (n - i - v p ⟨j + 1, j.succ_pos⟩) := by
generalize h : v p ⟨j + 1, j.succ_pos⟩ = m
rsuffices ⟨h₁, h₂⟩ : m ≤ n - i ∧ m ≤ j
· rw [tsub_add_eq_add_tsub h₂, add_comm i j, add_tsub_assoc_of_le (h₁.trans (Nat.sub_le n i)),
add_assoc, tsub_right_comm, add_comm i,
tsub_add_cancel_of_le (le_tsub_of_add_le_right ((le_tsub_iff_left hi).mp h₁))]
have hle : p ^ m ≤ j + 1 := h ▸ Nat.le_of_dvd j.succ_pos (multiplicity.pow_multiplicity_dvd _)
exact ⟨(pow_le_pow_iff_right hp.1.one_lt).1 (hle.trans hj),
Nat.le_of_lt_succ ((Nat.lt_pow_self hp.1.one_lt m).trans_le hle)⟩
theorem map_frobeniusPoly (n : ℕ) :
MvPolynomial.map (Int.castRingHom ℚ) (frobeniusPoly p n) = frobeniusPolyRat p n := by
rw [frobeniusPoly, RingHom.map_add, RingHom.map_mul, RingHom.map_pow, map_C, map_X, eq_intCast,
Int.cast_natCast, frobeniusPolyRat]
refine Nat.strong_induction_on n ?_; clear n
intro n IH
rw [xInTermsOfW_eq]
simp only [map_sum, map_sub, map_mul, map_pow (bind₁ _), bind₁_C_right]
have h1 : (p : ℚ) ^ n * ⅟ (p : ℚ) ^ n = 1 := by rw [← mul_pow, mul_invOf_self, one_pow]
rw [bind₁_X_right, Function.comp_apply, wittPolynomial_eq_sum_C_mul_X_pow, sum_range_succ,
sum_range_succ, tsub_self, add_tsub_cancel_left, pow_zero, pow_one, pow_one, sub_mul, add_mul,
add_mul, mul_right_comm, mul_right_comm (C ((p : ℚ) ^ (n + 1))), ← C_mul, ← C_mul, pow_succ',
mul_assoc (p : ℚ) ((p : ℚ) ^ n), h1, mul_one, C_1, one_mul, add_comm _ (X n ^ p), add_assoc,
← add_sub, add_right_inj, frobeniusPolyAux_eq, RingHom.map_sub, map_X, mul_sub, sub_eq_add_neg,
add_comm _ (C (p : ℚ) * X (n + 1)), ← add_sub,
add_right_inj, neg_eq_iff_eq_neg, neg_sub, eq_comm]
simp only [map_sum, mul_sum, sum_mul, ← sum_sub_distrib]
apply sum_congr rfl
intro i hi
rw [mem_range] at hi
rw [← IH i hi]
clear IH
rw [add_comm (X i ^ p), add_pow, sum_range_succ', pow_zero, tsub_zero, Nat.choose_zero_right,
one_mul, Nat.cast_one, mul_one, mul_add, add_mul, Nat.succ_sub (le_of_lt hi),
Nat.succ_eq_add_one (n - i), pow_succ', pow_mul, add_sub_cancel_right, mul_sum, sum_mul]
apply sum_congr rfl
intro j hj
rw [mem_range] at hj
rw [RingHom.map_mul, RingHom.map_mul, RingHom.map_pow, RingHom.map_pow, RingHom.map_pow,
RingHom.map_pow, RingHom.map_pow, map_C, map_X, mul_pow]
rw [mul_comm (C (p : ℚ) ^ i), mul_comm _ ((X i ^ p) ^ _), mul_comm (C (p : ℚ) ^ (j + 1)),
mul_comm (C (p : ℚ))]
simp only [mul_assoc]
apply congr_arg
apply congr_arg
rw [← C_eq_coe_nat]
simp only [← RingHom.map_pow, ← C_mul]
rw [C_inj]
simp only [invOf_eq_inv, eq_intCast, inv_pow, Int.cast_natCast, Nat.cast_mul, Int.cast_mul]
rw [Rat.natCast_div _ _ (map_frobeniusPoly.key₁ p (n - i) j hj)]
simp only [Nat.cast_pow, pow_add, pow_one]
suffices
(((p ^ (n - i)).choose (j + 1) : ℚ) * (p : ℚ) ^ (j - v p ⟨j + 1, j.succ_pos⟩) * p * (p ^ n : ℚ))
= (p : ℚ) ^ j * p * ↑((p ^ (n - i)).choose (j + 1) * p ^ i) *
(p : ℚ) ^ (n - i - v p ⟨j + 1, j.succ_pos⟩) by
have aux : ∀ k : ℕ, (p : ℚ)^ k ≠ 0 := by
intro; apply pow_ne_zero; exact mod_cast hp.1.ne_zero
simpa [aux, -one_div, -pow_eq_zero_iff', field_simps] using this.symm
rw [mul_comm _ (p : ℚ), mul_assoc, mul_assoc, ← pow_add,
map_frobeniusPoly.key₂ p hi.le hj, Nat.cast_mul, Nat.cast_pow]
ring
theorem frobeniusPoly_zmod (n : ℕ) :
MvPolynomial.map (Int.castRingHom (ZMod p)) (frobeniusPoly p n) = X n ^ p := by
rw [frobeniusPoly, RingHom.map_add, RingHom.map_pow, RingHom.map_mul, map_X, map_C]
simp only [Int.cast_natCast, add_zero, eq_intCast, ZMod.natCast_self, zero_mul, C_0]
@[simp]
theorem bind₁_frobeniusPoly_wittPolynomial (n : ℕ) :
bind₁ (frobeniusPoly p) (wittPolynomial p ℤ n) = wittPolynomial p ℤ (n + 1) := by
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
simp only [map_bind₁, map_frobeniusPoly, bind₁_frobeniusPolyRat_wittPolynomial,
map_wittPolynomial]
variable {p}
/-- `frobeniusFun` is the function underlying the ring endomorphism
`frobenius : 𝕎 R →+* frobenius 𝕎 R`. -/
def frobeniusFun (x : 𝕎 R) : 𝕎 R :=
mk p fun n => MvPolynomial.aeval x.coeff (frobeniusPoly p n)
theorem coeff_frobeniusFun (x : 𝕎 R) (n : ℕ) :
coeff (frobeniusFun x) n = MvPolynomial.aeval x.coeff (frobeniusPoly p n) := by
rw [frobeniusFun, coeff_mk]
variable (p)
/-- `frobeniusFun` is tautologically a polynomial function.
See also `frobenius_isPoly`. -/
-- Porting note: replaced `@[is_poly]` with `instance`.
instance frobeniusFun_isPoly : IsPoly p fun R _Rcr => @frobeniusFun p R _ _Rcr :=
⟨⟨frobeniusPoly p, by intros; funext n; apply coeff_frobeniusFun⟩⟩
variable {p}
@[ghost_simps]
theorem ghostComponent_frobeniusFun (n : ℕ) (x : 𝕎 R) :
ghostComponent n (frobeniusFun x) = ghostComponent (n + 1) x := by
simp only [ghostComponent_apply, frobeniusFun, coeff_mk, ← bind₁_frobeniusPoly_wittPolynomial,
aeval_bind₁]
/-- If `R` has characteristic `p`, then there is a ring endomorphism
that raises `r : R` to the power `p`.
By applying `WittVector.map` to this endomorphism,
we obtain a ring endomorphism `frobenius R p : 𝕎 R →+* 𝕎 R`.
The underlying function of this morphism is `WittVector.frobeniusFun`.
-/
def frobenius : 𝕎 R →+* 𝕎 R where
toFun := frobeniusFun
map_zero' := by
-- Porting note: removing the placeholders give an error
refine IsPoly.ext (@IsPoly.comp p _ _ (frobeniusFun_isPoly p) WittVector.zeroIsPoly)
(@IsPoly.comp p _ _ WittVector.zeroIsPoly
(frobeniusFun_isPoly p)) ?_ _ 0
simp only [Function.comp_apply, map_zero, forall_const]
ghost_simp
map_one' := by
refine
-- Porting note: removing the placeholders give an error
IsPoly.ext (@IsPoly.comp p _ _ (frobeniusFun_isPoly p) WittVector.oneIsPoly)
(@IsPoly.comp p _ _ WittVector.oneIsPoly (frobeniusFun_isPoly p)) ?_ _ 0
simp only [Function.comp_apply, map_one, forall_const]
ghost_simp
map_add' := by ghost_calc _ _; ghost_simp
map_mul' := by ghost_calc _ _; ghost_simp
theorem coeff_frobenius (x : 𝕎 R) (n : ℕ) :
coeff (frobenius x) n = MvPolynomial.aeval x.coeff (frobeniusPoly p n) :=
coeff_frobeniusFun _ _
@[ghost_simps]
theorem ghostComponent_frobenius (n : ℕ) (x : 𝕎 R) :
ghostComponent n (frobenius x) = ghostComponent (n + 1) x :=
ghostComponent_frobeniusFun _ _
variable (p)
/-- `frobenius` is tautologically a polynomial function. -/
-- Porting note: replaced `@[is_poly]` with `instance`.
instance frobenius_isPoly : IsPoly p fun R _Rcr => @frobenius p R _ _Rcr :=
frobeniusFun_isPoly _
section CharP
variable [CharP R p]
@[simp]
theorem coeff_frobenius_charP (x : 𝕎 R) (n : ℕ) : coeff (frobenius x) n = x.coeff n ^ p := by
rw [coeff_frobenius]
letI : Algebra (ZMod p) R := ZMod.algebra _ _
-- outline of the calculation, proofs follow below
calc
aeval (fun k => x.coeff k) (frobeniusPoly p n) =
aeval (fun k => x.coeff k)
(MvPolynomial.map (Int.castRingHom (ZMod p)) (frobeniusPoly p n)) := ?_
_ = aeval (fun k => x.coeff k) (X n ^ p : MvPolynomial ℕ (ZMod p)) := ?_
_ = x.coeff n ^ p := ?_
· conv_rhs => rw [aeval_eq_eval₂Hom, eval₂Hom_map_hom]
apply eval₂Hom_congr (RingHom.ext_int _ _) rfl rfl
· rw [frobeniusPoly_zmod]
· rw [map_pow, aeval_X]
theorem frobenius_eq_map_frobenius : @frobenius p R _ _ = map (_root_.frobenius R p) := by
ext (x n)
simp only [coeff_frobenius_charP, map_coeff, frobenius_def]
@[simp]
theorem frobenius_zmodp (x : 𝕎 (ZMod p)) : frobenius x = x := by
simp only [WittVector.ext_iff, coeff_frobenius_charP, ZMod.pow_card, eq_self_iff_true,
forall_const]
variable (R)
/-- `WittVector.frobenius` as an equiv. -/
@[simps (config := .asFn)]
def frobeniusEquiv [PerfectRing R p] : WittVector p R ≃+* WittVector p R :=
{ (WittVector.frobenius : WittVector p R →+* WittVector p R) with
toFun := WittVector.frobenius
invFun := map (_root_.frobeniusEquiv R p).symm
left_inv := fun f => ext fun n => by
rw [frobenius_eq_map_frobenius]
exact frobeniusEquiv_symm_apply_frobenius R p _
right_inv := fun f => ext fun n => by
rw [frobenius_eq_map_frobenius]
exact frobenius_apply_frobeniusEquiv_symm R p _ }
theorem frobenius_bijective [PerfectRing R p] :
Function.Bijective (@WittVector.frobenius p R _ _) :=
(frobeniusEquiv p R).bijective
end CharP
end
end WittVector
|
RingTheory\WittVector\FrobeniusFractionField.lean | /-
Copyright (c) 2022 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Heather Macbeth
-/
import Mathlib.Data.Nat.Cast.WithTop
import Mathlib.FieldTheory.IsAlgClosed.Basic
import Mathlib.RingTheory.WittVector.DiscreteValuationRing
/-!
# Solving equations about the Frobenius map on the field of fractions of `𝕎 k`
The goal of this file is to prove `WittVector.exists_frobenius_solution_fractionRing`,
which says that for an algebraically closed field `k` of characteristic `p` and `a, b` in the
field of fractions of Witt vectors over `k`,
there is a solution `b` to the equation `φ b * a = p ^ m * b`, where `φ` is the Frobenius map.
Most of this file builds up the equivalent theorem over `𝕎 k` directly,
moving to the field of fractions at the end.
See `WittVector.frobeniusRotation` and its specification.
The construction proceeds by recursively defining a sequence of coefficients as solutions to a
polynomial equation in `k`. We must define these as generic polynomials using Witt vector API
(`WittVector.wittMul`, `wittPolynomial`) to show that they satisfy the desired equation.
Preliminary work is done in the dependency `RingTheory.WittVector.MulCoeff`
to isolate the `n+1`st coefficients of `x` and `y` in the `n+1`st coefficient of `x*y`.
This construction is described in Dupuis, Lewis, and Macbeth,
[Formalized functional analysis via semilinear maps][dupuis-lewis-macbeth2022].
We approximately follow an approach sketched on MathOverflow:
<https://mathoverflow.net/questions/62468/about-frobenius-of-witt-vectors>
The result is a dependency for the proof of `WittVector.isocrystal_classification`,
the classification of one-dimensional isocrystals over an algebraically closed field.
-/
noncomputable section
namespace WittVector
variable (p : ℕ) [hp : Fact p.Prime]
local notation "𝕎" => WittVector p
namespace RecursionMain
/-!
## The recursive case of the vector coefficients
The first coefficient of our solution vector is easy to define below.
In this section we focus on the recursive case.
The goal is to turn `WittVector.wittPolyProd n` into a univariate polynomial
whose variable represents the `n`th coefficient of `x` in `x * a`.
-/
section CommRing
variable {k : Type*} [CommRing k] [CharP k p]
open Polynomial
/-- The root of this polynomial determines the `n+1`st coefficient of our solution. -/
def succNthDefiningPoly (n : ℕ) (a₁ a₂ : 𝕎 k) (bs : Fin (n + 1) → k) : Polynomial k :=
X ^ p * C (a₁.coeff 0 ^ p ^ (n + 1)) - X * C (a₂.coeff 0 ^ p ^ (n + 1)) +
C
(a₁.coeff (n + 1) * (bs 0 ^ p) ^ p ^ (n + 1) +
nthRemainder p n (fun v => bs v ^ p) (truncateFun (n + 1) a₁) -
a₂.coeff (n + 1) * bs 0 ^ p ^ (n + 1) -
nthRemainder p n bs (truncateFun (n + 1) a₂))
theorem succNthDefiningPoly_degree [IsDomain k] (n : ℕ) (a₁ a₂ : 𝕎 k) (bs : Fin (n + 1) → k)
(ha₁ : a₁.coeff 0 ≠ 0) (ha₂ : a₂.coeff 0 ≠ 0) :
(succNthDefiningPoly p n a₁ a₂ bs).degree = p := by
have : (X ^ p * C (a₁.coeff 0 ^ p ^ (n + 1))).degree = (p : WithBot ℕ) := by
rw [degree_mul, degree_C]
· simp only [Nat.cast_withBot, add_zero, degree_X, degree_pow, Nat.smul_one_eq_cast]
· exact pow_ne_zero _ ha₁
have : (X ^ p * C (a₁.coeff 0 ^ p ^ (n + 1)) - X * C (a₂.coeff 0 ^ p ^ (n + 1))).degree =
(p : WithBot ℕ) := by
rw [degree_sub_eq_left_of_degree_lt, this]
rw [this, degree_mul, degree_C, degree_X, add_zero]
· exact mod_cast hp.out.one_lt
· exact pow_ne_zero _ ha₂
rw [succNthDefiningPoly, degree_add_eq_left_of_degree_lt, this]
apply lt_of_le_of_lt degree_C_le
rw [this]
exact mod_cast hp.out.pos
end CommRing
section IsAlgClosed
variable {k : Type*} [Field k] [CharP k p] [IsAlgClosed k]
theorem root_exists (n : ℕ) (a₁ a₂ : 𝕎 k) (bs : Fin (n + 1) → k) (ha₁ : a₁.coeff 0 ≠ 0)
(ha₂ : a₂.coeff 0 ≠ 0) : ∃ b : k, (succNthDefiningPoly p n a₁ a₂ bs).IsRoot b :=
IsAlgClosed.exists_root _ <| by
simp only [succNthDefiningPoly_degree p n a₁ a₂ bs ha₁ ha₂, ne_eq, Nat.cast_eq_zero,
hp.out.ne_zero, not_false_eq_true]
/-- This is the `n+1`st coefficient of our solution, projected from `root_exists`. -/
def succNthVal (n : ℕ) (a₁ a₂ : 𝕎 k) (bs : Fin (n + 1) → k) (ha₁ : a₁.coeff 0 ≠ 0)
(ha₂ : a₂.coeff 0 ≠ 0) : k :=
Classical.choose (root_exists p n a₁ a₂ bs ha₁ ha₂)
theorem succNthVal_spec (n : ℕ) (a₁ a₂ : 𝕎 k) (bs : Fin (n + 1) → k) (ha₁ : a₁.coeff 0 ≠ 0)
(ha₂ : a₂.coeff 0 ≠ 0) :
(succNthDefiningPoly p n a₁ a₂ bs).IsRoot (succNthVal p n a₁ a₂ bs ha₁ ha₂) :=
Classical.choose_spec (root_exists p n a₁ a₂ bs ha₁ ha₂)
theorem succNthVal_spec' (n : ℕ) (a₁ a₂ : 𝕎 k) (bs : Fin (n + 1) → k) (ha₁ : a₁.coeff 0 ≠ 0)
(ha₂ : a₂.coeff 0 ≠ 0) :
succNthVal p n a₁ a₂ bs ha₁ ha₂ ^ p * a₁.coeff 0 ^ p ^ (n + 1) +
a₁.coeff (n + 1) * (bs 0 ^ p) ^ p ^ (n + 1) +
nthRemainder p n (fun v => bs v ^ p) (truncateFun (n + 1) a₁) =
succNthVal p n a₁ a₂ bs ha₁ ha₂ * a₂.coeff 0 ^ p ^ (n + 1) +
a₂.coeff (n + 1) * bs 0 ^ p ^ (n + 1) +
nthRemainder p n bs (truncateFun (n + 1) a₂) := by
rw [← sub_eq_zero]
have := succNthVal_spec p n a₁ a₂ bs ha₁ ha₂
simp only [Polynomial.map_add, Polynomial.eval_X, Polynomial.map_pow, Polynomial.eval_C,
Polynomial.eval_pow, succNthDefiningPoly, Polynomial.eval_mul, Polynomial.eval_add,
Polynomial.eval_sub, Polynomial.map_mul, Polynomial.map_sub, Polynomial.IsRoot.def]
at this
convert this using 1
ring
end IsAlgClosed
end RecursionMain
namespace RecursionBase
variable {k : Type*} [Field k] [IsAlgClosed k]
theorem solution_pow (a₁ a₂ : 𝕎 k) : ∃ x : k, x ^ (p - 1) = a₂.coeff 0 / a₁.coeff 0 :=
IsAlgClosed.exists_pow_nat_eq _ <| tsub_pos_of_lt hp.out.one_lt
/-- The base case (0th coefficient) of our solution vector. -/
def solution (a₁ a₂ : 𝕎 k) : k :=
Classical.choose <| solution_pow p a₁ a₂
theorem solution_spec (a₁ a₂ : 𝕎 k) : solution p a₁ a₂ ^ (p - 1) = a₂.coeff 0 / a₁.coeff 0 :=
Classical.choose_spec <| solution_pow p a₁ a₂
theorem solution_nonzero {a₁ a₂ : 𝕎 k} (ha₁ : a₁.coeff 0 ≠ 0) (ha₂ : a₂.coeff 0 ≠ 0) :
solution p a₁ a₂ ≠ 0 := by
intro h
have := solution_spec p a₁ a₂
rw [h, zero_pow] at this
· simpa [ha₁, ha₂] using _root_.div_eq_zero_iff.mp this.symm
· exact Nat.sub_ne_zero_of_lt hp.out.one_lt
theorem solution_spec' {a₁ : 𝕎 k} (ha₁ : a₁.coeff 0 ≠ 0) (a₂ : 𝕎 k) :
solution p a₁ a₂ ^ p * a₁.coeff 0 = solution p a₁ a₂ * a₂.coeff 0 := by
have := solution_spec p a₁ a₂
cases' Nat.exists_eq_succ_of_ne_zero hp.out.ne_zero with q hq
have hq' : q = p - 1 := by simp only [hq, tsub_zero, Nat.succ_sub_succ_eq_sub]
conv_lhs =>
congr
congr
· skip
· rw [hq]
rw [pow_succ', hq', this]
field_simp [ha₁, mul_comm]
end RecursionBase
open RecursionMain RecursionBase
section FrobeniusRotation
section IsAlgClosed
variable {k : Type*} [Field k] [CharP k p] [IsAlgClosed k]
/-- Recursively defines the sequence of coefficients for `WittVector.frobeniusRotation`.
-/
-- Constructions by well-founded recursion are by default irreducible.
-- As we rely on definitional properties below, we mark this `@[semireducible]`.
@[semireducible] noncomputable def frobeniusRotationCoeff {a₁ a₂ : 𝕎 k} (ha₁ : a₁.coeff 0 ≠ 0)
(ha₂ : a₂.coeff 0 ≠ 0) : ℕ → k
| 0 => solution p a₁ a₂
| n + 1 => succNthVal p n a₁ a₂ (fun i => frobeniusRotationCoeff ha₁ ha₂ i.val) ha₁ ha₂
/-- For nonzero `a₁` and `a₂`, `frobeniusRotation a₁ a₂` is a Witt vector that satisfies the
equation `frobenius (frobeniusRotation a₁ a₂) * a₁ = (frobeniusRotation a₁ a₂) * a₂`.
-/
def frobeniusRotation {a₁ a₂ : 𝕎 k} (ha₁ : a₁.coeff 0 ≠ 0) (ha₂ : a₂.coeff 0 ≠ 0) : 𝕎 k :=
WittVector.mk p (frobeniusRotationCoeff p ha₁ ha₂)
theorem frobeniusRotation_nonzero {a₁ a₂ : 𝕎 k} (ha₁ : a₁.coeff 0 ≠ 0) (ha₂ : a₂.coeff 0 ≠ 0) :
frobeniusRotation p ha₁ ha₂ ≠ 0 := by
intro h
apply solution_nonzero p ha₁ ha₂
simpa [← h, frobeniusRotation, frobeniusRotationCoeff] using WittVector.zero_coeff p k 0
theorem frobenius_frobeniusRotation {a₁ a₂ : 𝕎 k} (ha₁ : a₁.coeff 0 ≠ 0) (ha₂ : a₂.coeff 0 ≠ 0) :
frobenius (frobeniusRotation p ha₁ ha₂) * a₁ = frobeniusRotation p ha₁ ha₂ * a₂ := by
ext n
cases' n with n
· simp only [WittVector.mul_coeff_zero, WittVector.coeff_frobenius_charP, frobeniusRotation,
frobeniusRotationCoeff, Nat.zero_eq]
apply solution_spec' _ ha₁
· simp only [nthRemainder_spec, WittVector.coeff_frobenius_charP, frobeniusRotationCoeff,
frobeniusRotation]
have :=
succNthVal_spec' p n a₁ a₂ (fun i : Fin (n + 1) => frobeniusRotationCoeff p ha₁ ha₂ i.val)
ha₁ ha₂
simp only [frobeniusRotationCoeff, Fin.val_zero] at this
convert this using 3
apply TruncatedWittVector.ext
intro i
simp only [WittVector.coeff_truncateFun, WittVector.coeff_frobenius_charP]
rfl
local notation "φ" => IsFractionRing.fieldEquivOfRingEquiv (frobeniusEquiv p k)
theorem exists_frobenius_solution_fractionRing_aux (m n : ℕ) (r' q' : 𝕎 k) (hr' : r'.coeff 0 ≠ 0)
(hq' : q'.coeff 0 ≠ 0) (hq : (p : 𝕎 k) ^ n * q' ∈ nonZeroDivisors (𝕎 k)) :
let b : 𝕎 k := frobeniusRotation p hr' hq'
IsFractionRing.fieldEquivOfRingEquiv (frobeniusEquiv p k)
(algebraMap (𝕎 k) (FractionRing (𝕎 k)) b) *
Localization.mk ((p : 𝕎 k) ^ m * r') ⟨(p : 𝕎 k) ^ n * q', hq⟩ =
(p : Localization (nonZeroDivisors (𝕎 k))) ^ (m - n : ℤ) *
algebraMap (𝕎 k) (FractionRing (𝕎 k)) b := by
intro b
have key : WittVector.frobenius b * (p : 𝕎 k) ^ m * r' * (p : 𝕎 k) ^ n =
(p : 𝕎 k) ^ m * b * ((p : 𝕎 k) ^ n * q') := by
have H := congr_arg (fun x : 𝕎 k => x * (p : 𝕎 k) ^ m * (p : 𝕎 k) ^ n)
(frobenius_frobeniusRotation p hr' hq')
dsimp at H
refine (Eq.trans ?_ H).trans ?_ <;> ring
have hq'' : algebraMap (𝕎 k) (FractionRing (𝕎 k)) q' ≠ 0 := by
have hq''' : q' ≠ 0 := fun h => hq' (by simp [h])
simpa only [Ne, map_zero] using
(IsFractionRing.injective (𝕎 k) (FractionRing (𝕎 k))).ne hq'''
rw [zpow_sub₀ (FractionRing.p_nonzero p k)]
field_simp [FractionRing.p_nonzero p k]
simp only [IsFractionRing.fieldEquivOfRingEquiv, IsLocalization.ringEquivOfRingEquiv_eq,
RingEquiv.coe_ofBijective]
convert congr_arg (fun x => algebraMap (𝕎 k) (FractionRing (𝕎 k)) x) key using 1
· simp only [RingHom.map_mul, RingHom.map_pow, map_natCast, frobeniusEquiv_apply]
ring
· simp only [RingHom.map_mul, RingHom.map_pow, map_natCast]
theorem exists_frobenius_solution_fractionRing {a : FractionRing (𝕎 k)} (ha : a ≠ 0) :
∃ᵉ (b ≠ 0) (m : ℤ), φ b * a = (p : FractionRing (𝕎 k)) ^ m * b := by
revert ha
refine Localization.induction_on a ?_
rintro ⟨r, q, hq⟩ hrq
have hq0 : q ≠ 0 := mem_nonZeroDivisors_iff_ne_zero.1 hq
have hr0 : r ≠ 0 := fun h => hrq (by simp [h])
obtain ⟨m, r', hr', rfl⟩ := exists_eq_pow_p_mul r hr0
obtain ⟨n, q', hq', rfl⟩ := exists_eq_pow_p_mul q hq0
let b := frobeniusRotation p hr' hq'
refine ⟨algebraMap (𝕎 k) (FractionRing (𝕎 k)) b, ?_, m - n, ?_⟩
· simpa only [map_zero] using
(IsFractionRing.injective (WittVector p k) (FractionRing (WittVector p k))).ne
(frobeniusRotation_nonzero p hr' hq')
exact exists_frobenius_solution_fractionRing_aux p m n r' q' hr' hq' hq
end IsAlgClosed
end FrobeniusRotation
end WittVector
|
RingTheory\WittVector\Identities.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.RingTheory.WittVector.Frobenius
import Mathlib.RingTheory.WittVector.Verschiebung
import Mathlib.RingTheory.WittVector.MulP
/-!
## Identities between operations on the ring of Witt vectors
In this file we derive common identities between the Frobenius and Verschiebung operators.
## Main declarations
* `frobenius_verschiebung`: the composition of Frobenius and Verschiebung is multiplication by `p`
* `verschiebung_mul_frobenius`: the “projection formula”: `V(x * F y) = V x * y`
* `iterate_verschiebung_mul_coeff`: an identity from [Haze09] 6.2
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
namespace WittVector
variable {p : ℕ} {R : Type*} [hp : Fact p.Prime] [CommRing R]
-- type as `\bbW`
local notation "𝕎" => WittVector p
noncomputable section
-- Porting note: `ghost_calc` failure: `simp only []` and the manual instances had to be added.
/-- The composition of Frobenius and Verschiebung is multiplication by `p`. -/
theorem frobenius_verschiebung (x : 𝕎 R) : frobenius (verschiebung x) = x * p := by
have : IsPoly p fun {R} [CommRing R] x ↦ frobenius (verschiebung x) :=
IsPoly.comp (hg := frobenius_isPoly p) (hf := verschiebung_isPoly)
have : IsPoly p fun {R} [CommRing R] x ↦ x * p := mulN_isPoly p p
ghost_calc x
ghost_simp [mul_comm]
/-- Verschiebung is the same as multiplication by `p` on the ring of Witt vectors of `ZMod p`. -/
theorem verschiebung_zmod (x : 𝕎 (ZMod p)) : verschiebung x = x * p := by
rw [← frobenius_verschiebung, frobenius_zmodp]
variable (p R)
theorem coeff_p_pow [CharP R p] (i : ℕ) : ((p : 𝕎 R) ^ i).coeff i = 1 := by
induction' i with i h
· simp only [Nat.zero_eq, one_coeff_zero, Ne, pow_zero]
· rw [pow_succ, ← frobenius_verschiebung, coeff_frobenius_charP,
verschiebung_coeff_succ, h, one_pow]
theorem coeff_p_pow_eq_zero [CharP R p] {i j : ℕ} (hj : j ≠ i) : ((p : 𝕎 R) ^ i).coeff j = 0 := by
induction' i with i hi generalizing j
· rw [pow_zero, one_coeff_eq_of_pos]
exact Nat.pos_of_ne_zero hj
· rw [pow_succ, ← frobenius_verschiebung, coeff_frobenius_charP]
cases j
· rw [verschiebung_coeff_zero, zero_pow hp.out.ne_zero]
· rw [verschiebung_coeff_succ, hi (ne_of_apply_ne _ hj), zero_pow hp.out.ne_zero]
theorem coeff_p [CharP R p] (i : ℕ) : (p : 𝕎 R).coeff i = if i = 1 then 1 else 0 := by
split_ifs with hi
· simpa only [hi, pow_one] using coeff_p_pow p R 1
· simpa only [pow_one] using coeff_p_pow_eq_zero p R hi
@[simp]
theorem coeff_p_zero [CharP R p] : (p : 𝕎 R).coeff 0 = 0 := by
rw [coeff_p, if_neg]
exact zero_ne_one
@[simp]
theorem coeff_p_one [CharP R p] : (p : 𝕎 R).coeff 1 = 1 := by rw [coeff_p, if_pos rfl]
theorem p_nonzero [Nontrivial R] [CharP R p] : (p : 𝕎 R) ≠ 0 := by
intro h
simpa only [h, zero_coeff, zero_ne_one] using coeff_p_one p R
theorem FractionRing.p_nonzero [Nontrivial R] [CharP R p] : (p : FractionRing (𝕎 R)) ≠ 0 := by
simpa using (IsFractionRing.injective (𝕎 R) (FractionRing (𝕎 R))).ne (WittVector.p_nonzero _ _)
variable {p R}
-- Porting note: `ghost_calc` failure: `simp only []` and the manual instances had to be added.
/-- The “projection formula” for Frobenius and Verschiebung. -/
theorem verschiebung_mul_frobenius (x y : 𝕎 R) :
verschiebung (x * frobenius y) = verschiebung x * y := by
have : IsPoly₂ p fun {R} [Rcr : CommRing R] x y ↦ verschiebung (x * frobenius y) :=
IsPoly.comp₂ (hg := verschiebung_isPoly)
(hf := IsPoly₂.comp (hh := mulIsPoly₂) (hf := idIsPolyI' p) (hg := frobenius_isPoly p))
have : IsPoly₂ p fun {R} [CommRing R] x y ↦ verschiebung x * y :=
IsPoly₂.comp (hh := mulIsPoly₂) (hf := verschiebung_isPoly) (hg := idIsPolyI' p)
ghost_calc x y
rintro ⟨⟩ <;> ghost_simp [mul_assoc]
theorem mul_charP_coeff_zero [CharP R p] (x : 𝕎 R) : (x * p).coeff 0 = 0 := by
rw [← frobenius_verschiebung, coeff_frobenius_charP, verschiebung_coeff_zero,
zero_pow hp.out.ne_zero]
theorem mul_charP_coeff_succ [CharP R p] (x : 𝕎 R) (i : ℕ) :
(x * p).coeff (i + 1) = x.coeff i ^ p := by
rw [← frobenius_verschiebung, coeff_frobenius_charP, verschiebung_coeff_succ]
theorem verschiebung_frobenius [CharP R p] (x : 𝕎 R) : verschiebung (frobenius x) = x * p := by
ext ⟨i⟩
· rw [mul_charP_coeff_zero, verschiebung_coeff_zero]
· rw [mul_charP_coeff_succ, verschiebung_coeff_succ, coeff_frobenius_charP]
theorem verschiebung_frobenius_comm [CharP R p] :
Function.Commute (verschiebung : 𝕎 R → 𝕎 R) frobenius := fun x => by
rw [verschiebung_frobenius, frobenius_verschiebung]
/-!
## Iteration lemmas
-/
open Function
theorem iterate_verschiebung_coeff (x : 𝕎 R) (n k : ℕ) :
(verschiebung^[n] x).coeff (k + n) = x.coeff k := by
induction' n with k ih
· simp
· rw [iterate_succ_apply', Nat.add_succ, verschiebung_coeff_succ]
exact ih
theorem iterate_verschiebung_mul_left (x y : 𝕎 R) (i : ℕ) :
verschiebung^[i] x * y = verschiebung^[i] (x * frobenius^[i] y) := by
induction' i with i ih generalizing y
· simp
· rw [iterate_succ_apply', ← verschiebung_mul_frobenius, ih, iterate_succ_apply']; rfl
section CharP
variable [CharP R p]
theorem iterate_verschiebung_mul (x y : 𝕎 R) (i j : ℕ) :
verschiebung^[i] x * verschiebung^[j] y =
verschiebung^[i + j] (frobenius^[j] x * frobenius^[i] y) := by
calc
_ = verschiebung^[i] (x * frobenius^[i] (verschiebung^[j] y)) := ?_
_ = verschiebung^[i] (x * verschiebung^[j] (frobenius^[i] y)) := ?_
_ = verschiebung^[i] (verschiebung^[j] (frobenius^[i] y) * x) := ?_
_ = verschiebung^[i] (verschiebung^[j] (frobenius^[i] y * frobenius^[j] x)) := ?_
_ = verschiebung^[i + j] (frobenius^[i] y * frobenius^[j] x) := ?_
_ = _ := ?_
· apply iterate_verschiebung_mul_left
· rw [verschiebung_frobenius_comm.iterate_iterate]
· rw [mul_comm]
· rw [iterate_verschiebung_mul_left]
· rw [iterate_add_apply]
· rw [mul_comm]
-- Porting note: `ring_nf` doesn't handle powers yet; needed to add `Nat.pow_succ` rewrite
theorem iterate_frobenius_coeff (x : 𝕎 R) (i k : ℕ) :
(frobenius^[i] x).coeff k = x.coeff k ^ p ^ i := by
induction' i with i ih
· simp
· rw [iterate_succ_apply', coeff_frobenius_charP, ih, Nat.pow_succ]
ring_nf
/-- This is a slightly specialized form of [Hazewinkel, *Witt Vectors*][Haze09] 6.2 equation 5. -/
theorem iterate_verschiebung_mul_coeff (x y : 𝕎 R) (i j : ℕ) :
(verschiebung^[i] x * verschiebung^[j] y).coeff (i + j) =
x.coeff 0 ^ p ^ j * y.coeff 0 ^ p ^ i := by
calc
_ = (verschiebung^[i + j] (frobenius^[j] x * frobenius^[i] y)).coeff (i + j) := ?_
_ = (frobenius^[j] x * frobenius^[i] y).coeff 0 := ?_
_ = (frobenius^[j] x).coeff 0 * (frobenius^[i] y).coeff 0 := ?_
_ = _ := ?_
· rw [iterate_verschiebung_mul]
· convert iterate_verschiebung_coeff (p := p) (R := R) _ _ _ using 2
rw [zero_add]
· apply mul_coeff_zero
· simp only [iterate_frobenius_coeff]
end CharP
end
end WittVector
|
RingTheory\WittVector\InitTail.lean | /-
Copyright (c) 2020 Johan Commelin, Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import Mathlib.RingTheory.WittVector.Basic
import Mathlib.RingTheory.WittVector.IsPoly
/-!
# `init` and `tail`
Given a Witt vector `x`, we are sometimes interested
in its components before and after an index `n`.
This file defines those operations, proves that `init` is polynomial,
and shows how that polynomial interacts with `MvPolynomial.bind₁`.
## Main declarations
* `WittVector.init n x`: the first `n` coefficients of `x`, as a Witt vector. All coefficients at
indices ≥ `n` are 0.
* `WittVector.tail n x`: the complementary part to `init`. All coefficients at indices < `n` are 0,
otherwise they are the same as in `x`.
* `WittVector.coeff_add_of_disjoint`: if `x` and `y` are Witt vectors such that for every `n`
the `n`-th coefficient of `x` or of `y` is `0`, then the coefficients of `x + y`
are just `x.coeff n + y.coeff n`.
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
variable {p : ℕ} (n : ℕ) {R : Type*} [CommRing R]
-- type as `\bbW`
local notation "𝕎" => WittVector p
namespace WittVector
open MvPolynomial
open scoped Classical
noncomputable section
section
/-- `WittVector.select P x`, for a predicate `P : ℕ → Prop` is the Witt vector
whose `n`-th coefficient is `x.coeff n` if `P n` is true, and `0` otherwise.
-/
def select (P : ℕ → Prop) (x : 𝕎 R) : 𝕎 R :=
mk p fun n => if P n then x.coeff n else 0
section Select
variable (P : ℕ → Prop)
/-- The polynomial that witnesses that `WittVector.select` is a polynomial function.
`selectPoly n` is `X n` if `P n` holds, and `0` otherwise. -/
def selectPoly (n : ℕ) : MvPolynomial ℕ ℤ :=
if P n then X n else 0
theorem coeff_select (x : 𝕎 R) (n : ℕ) :
(select P x).coeff n = aeval x.coeff (selectPoly P n) := by
dsimp [select, selectPoly]
split_ifs with hi
· rw [aeval_X, mk]; simp only [hi, if_true]
· rw [map_zero, mk]; simp only [hi, if_false]
-- Porting note: replaced `@[is_poly]` with `instance`. Made the argument `P` implicit in doing so.
instance select_isPoly {P : ℕ → Prop} : IsPoly p fun _ _ x => select P x := by
use selectPoly P
rintro R _Rcr x
funext i
apply coeff_select
variable [hp : Fact p.Prime]
theorem select_add_select_not : ∀ x : 𝕎 R, select P x + select (fun i => ¬P i) x = x := by
-- Porting note: TC search was insufficient to find this instance, even though all required
-- instances exist. See zulip: [https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/WittVector.20saga/near/370073526]
have : IsPoly p fun {R} [CommRing R] x ↦ select P x + select (fun i ↦ ¬P i) x :=
IsPoly₂.diag (hf := IsPoly₂.comp)
ghost_calc x
intro n
simp only [RingHom.map_add]
suffices
(bind₁ (selectPoly P)) (wittPolynomial p ℤ n) +
(bind₁ (selectPoly fun i => ¬P i)) (wittPolynomial p ℤ n) =
wittPolynomial p ℤ n by
apply_fun aeval x.coeff at this
simpa only [map_add, aeval_bind₁, ← coeff_select]
simp only [wittPolynomial_eq_sum_C_mul_X_pow, selectPoly, map_sum, map_pow, map_mul,
bind₁_X_right, bind₁_C_right, ← Finset.sum_add_distrib, ← mul_add]
apply Finset.sum_congr rfl
refine fun m _ => mul_eq_mul_left_iff.mpr (Or.inl ?_)
rw [ite_pow, zero_pow (pow_ne_zero _ hp.out.ne_zero)]
by_cases Pm : P m
· rw [if_pos Pm, if_neg $ not_not_intro Pm, zero_pow Fin.size_pos'.ne', add_zero]
· rwa [if_neg Pm, if_pos, zero_add]
theorem coeff_add_of_disjoint (x y : 𝕎 R) (h : ∀ n, x.coeff n = 0 ∨ y.coeff n = 0) :
(x + y).coeff n = x.coeff n + y.coeff n := by
let P : ℕ → Prop := fun n => y.coeff n = 0
haveI : DecidablePred P := Classical.decPred P
set z := mk p fun n => if P n then x.coeff n else y.coeff n
have hx : select P z = x := by
ext1 n; rw [select, coeff_mk, coeff_mk]
split_ifs with hn
· rfl
· rw [(h n).resolve_right hn]
have hy : select (fun i => ¬P i) z = y := by
ext1 n; rw [select, coeff_mk, coeff_mk]
split_ifs with hn
· exact hn.symm
· rfl
calc
(x + y).coeff n = z.coeff n := by rw [← hx, ← hy, select_add_select_not P z]
_ = x.coeff n + y.coeff n := by
simp only [z, mk.eq_1]
split_ifs with y0
· rw [y0, add_zero]
· rw [h n |>.resolve_right y0, zero_add]
end Select
variable [Fact p.Prime]
/-- `WittVector.init n x` is the Witt vector of which the first `n` coefficients are those from `x`
and all other coefficients are `0`.
See `WittVector.tail` for the complementary part.
-/
def init (n : ℕ) : 𝕎 R → 𝕎 R :=
select fun i => i < n
/-- `WittVector.tail n x` is the Witt vector of which the first `n` coefficients are `0`
and all other coefficients are those from `x`.
See `WittVector.init` for the complementary part. -/
def tail (n : ℕ) : 𝕎 R → 𝕎 R :=
select fun i => n ≤ i
@[simp]
theorem init_add_tail (x : 𝕎 R) (n : ℕ) : init n x + tail n x = x := by
simp only [init, tail, ← not_lt, select_add_select_not]
end
/--
`init_ring` is an auxiliary tactic that discharges goals factoring `init` over ring operations.
-/
syntax (name := initRing) "init_ring" (" using " term)? : tactic
-- Porting note: this tactic requires that we turn hygiene off (note the free `n`).
-- TODO: make this tactic hygienic.
open Lean Elab Tactic in
elab_rules : tactic
| `(tactic| init_ring $[ using $a:term]?) => withMainContext <| set_option hygiene false in do
evalTactic <|← `(tactic|(
rw [WittVector.ext_iff]
intro i
simp only [WittVector.init, WittVector.select, WittVector.coeff_mk]
split_ifs with hi <;> try {rfl}
))
if let some e := a then
evalTactic <|← `(tactic|(
simp only [WittVector.add_coeff, WittVector.mul_coeff, WittVector.neg_coeff,
WittVector.sub_coeff, WittVector.nsmul_coeff, WittVector.zsmul_coeff, WittVector.pow_coeff]
apply MvPolynomial.eval₂Hom_congr' (RingHom.ext_int _ _) _ rfl
rintro ⟨b, k⟩ h -
replace h := $e:term p _ h
simp only [Finset.mem_range, Finset.mem_product, true_and, Finset.mem_univ] at h
have hk : k < n := by linarith
fin_cases b <;> simp only [Function.uncurry, Matrix.cons_val_zero, Matrix.head_cons,
WittVector.coeff_mk, Matrix.cons_val_one, WittVector.mk, Fin.mk_zero, Matrix.cons_val',
Matrix.empty_val', Matrix.cons_val_fin_one, Matrix.cons_val_zero,
hk, if_true]
))
-- Porting note: `by init_ring` should suffice; this patches over an issue with `split_ifs`.
-- See zulip: [https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/.60split_ifs.60.20boxes.20itself.20into.20a.20corner]
@[simp]
theorem init_init (x : 𝕎 R) (n : ℕ) : init n (init n x) = init n x := by
rw [WittVector.ext_iff]
intro i
simp only [WittVector.init, WittVector.select, WittVector.coeff_mk]
by_cases hi : i < n <;> simp [hi]
section
variable [Fact p.Prime]
theorem init_add (x y : 𝕎 R) (n : ℕ) : init n (x + y) = init n (init n x + init n y) := by
init_ring using wittAdd_vars
theorem init_mul (x y : 𝕎 R) (n : ℕ) : init n (x * y) = init n (init n x * init n y) := by
init_ring using wittMul_vars
theorem init_neg (x : 𝕎 R) (n : ℕ) : init n (-x) = init n (-init n x) := by
init_ring using wittNeg_vars
theorem init_sub (x y : 𝕎 R) (n : ℕ) : init n (x - y) = init n (init n x - init n y) := by
init_ring using wittSub_vars
theorem init_nsmul (m : ℕ) (x : 𝕎 R) (n : ℕ) : init n (m • x) = init n (m • init n x) := by
init_ring using fun p [Fact (Nat.Prime p)] n => wittNSMul_vars p m n
theorem init_zsmul (m : ℤ) (x : 𝕎 R) (n : ℕ) : init n (m • x) = init n (m • init n x) := by
init_ring using fun p [Fact (Nat.Prime p)] n => wittZSMul_vars p m n
theorem init_pow (m : ℕ) (x : 𝕎 R) (n : ℕ) : init n (x ^ m) = init n (init n x ^ m) := by
init_ring using fun p [Fact (Nat.Prime p)] n => wittPow_vars p m n
end
section
variable (p)
/-- `WittVector.init n x` is polynomial in the coefficients of `x`. -/
theorem init_isPoly (n : ℕ) : IsPoly p fun _ _ => init n :=
select_isPoly (P := fun i => i < n)
end
end
end WittVector
|
RingTheory\WittVector\Isocrystal.lean | /-
Copyright (c) 2022 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth
-/
import Mathlib.RingTheory.WittVector.FrobeniusFractionField
import Mathlib.Algebra.Module.Rat
import Mathlib.Algebra.GroupWithZero.Units.Lemmas
/-!
## F-isocrystals over a perfect field
When `k` is an integral domain, so is `𝕎 k`, and we can consider its field of fractions `K(p, k)`.
The endomorphism `WittVector.frobenius` lifts to `φ : K(p, k) → K(p, k)`; if `k` is perfect, `φ` is
an automorphism.
Let `k` be a perfect integral domain. Let `V` be a vector space over `K(p,k)`.
An *isocrystal* is a bijective map `V → V` that is `φ`-semilinear.
A theorem of Dieudonné and Manin classifies the finite-dimensional isocrystals over algebraically
closed fields. In the one-dimensional case, this classification states that the isocrystal
structures are parametrized by their "slope" `m : ℤ`.
Any one-dimensional isocrystal is isomorphic to `φ(p^m • x) : K(p,k) → K(p,k)` for some `m`.
This file proves this one-dimensional case of the classification theorem.
The construction is described in Dupuis, Lewis, and Macbeth,
[Formalized functional analysis via semilinear maps][dupuis-lewis-macbeth2022].
## Main declarations
* `WittVector.Isocrystal`: a vector space over the field `K(p, k)` additionally equipped with a
Frobenius-linear automorphism.
* `WittVector.isocrystal_classification`: a one-dimensional isocrystal admits an isomorphism to one
of the standard one-dimensional isocrystals.
## Notation
This file introduces notation in the locale `Isocrystal`.
* `K(p, k)`: `FractionRing (WittVector p k)`
* `φ(p, k)`: `WittVector.FractionRing.frobeniusRingHom p k`
* `M →ᶠˡ[p, k] M₂`: `LinearMap (WittVector.FractionRing.frobeniusRingHom p k) M M₂`
* `M ≃ᶠˡ[p, k] M₂`: `LinearEquiv (WittVector.FractionRing.frobeniusRingHom p k) M M₂`
* `Φ(p, k)`: `WittVector.Isocrystal.frobenius p k`
* `M →ᶠⁱ[p, k] M₂`: `WittVector.IsocrystalHom p k M M₂`
* `M ≃ᶠⁱ[p, k] M₂`: `WittVector.IsocrystalEquiv p k M M₂`
## References
* [Formalized functional analysis via semilinear maps][dupuis-lewis-macbeth2022]
* [Theory of commutative formal groups over fields of finite characteristic][manin1963]
* <https://www.math.ias.edu/~lurie/205notes/Lecture26-Isocrystals.pdf>
-/
noncomputable section
open FiniteDimensional
namespace WittVector
variable (p : ℕ) [Fact p.Prime]
variable (k : Type*) [CommRing k]
scoped[Isocrystal] notation "K(" p ", " k ")" => FractionRing (WittVector p k)
open Isocrystal
section PerfectRing
variable [IsDomain k] [CharP k p] [PerfectRing k p]
/-! ### Frobenius-linear maps -/
/-- The Frobenius automorphism of `k` induces an automorphism of `K`. -/
def FractionRing.frobenius : K(p, k) ≃+* K(p, k) :=
IsFractionRing.fieldEquivOfRingEquiv (frobeniusEquiv p k)
/-- The Frobenius automorphism of `k` induces an endomorphism of `K`. For notation purposes. -/
def FractionRing.frobeniusRingHom : K(p, k) →+* K(p, k) :=
FractionRing.frobenius p k
scoped[Isocrystal] notation "φ(" p ", " k ")" => WittVector.FractionRing.frobeniusRingHom p k
instance inv_pair₁ : RingHomInvPair φ(p, k) (FractionRing.frobenius p k).symm :=
RingHomInvPair.of_ringEquiv (FractionRing.frobenius p k)
instance inv_pair₂ : RingHomInvPair ((FractionRing.frobenius p k).symm : K(p, k) →+* K(p, k))
(FractionRing.frobenius p k) :=
RingHomInvPair.of_ringEquiv (FractionRing.frobenius p k).symm
scoped[Isocrystal]
notation:50 M " →ᶠˡ[" p ", " k "] " M₂ =>
LinearMap (WittVector.FractionRing.frobeniusRingHom p k) M M₂
scoped[Isocrystal]
notation:50 M " ≃ᶠˡ[" p ", " k "] " M₂ =>
LinearEquiv (WittVector.FractionRing.frobeniusRingHom p k) M M₂
/-! ### Isocrystals -/
/-- An isocrystal is a vector space over the field `K(p, k)` additionally equipped with a
Frobenius-linear automorphism.
-/
class Isocrystal (V : Type*) [AddCommGroup V] extends Module K(p, k) V where
frob : V ≃ᶠˡ[p, k] V
open WittVector
variable (V : Type*) [AddCommGroup V] [Isocrystal p k V]
variable (V₂ : Type*) [AddCommGroup V₂] [Isocrystal p k V₂]
variable {V}
/--
Project the Frobenius automorphism from an isocrystal. Denoted by `Φ(p, k)` when V can be inferred.
-/
def Isocrystal.frobenius : V ≃ᶠˡ[p, k] V :=
@Isocrystal.frob p _ k _ _ _ _ _ _ _
variable (V)
scoped[Isocrystal] notation "Φ(" p ", " k ")" => WittVector.Isocrystal.frobenius p k
/-- A homomorphism between isocrystals respects the Frobenius map. -/
-- Porting note(#5171): this linter isn't ported yet. @[nolint has_nonempty_instance]
structure IsocrystalHom extends V →ₗ[K(p, k)] V₂ where
frob_equivariant : ∀ x : V, Φ(p, k) (toLinearMap x) = toLinearMap (Φ(p, k) x)
/-- An isomorphism between isocrystals respects the Frobenius map. -/
-- Porting note(#5171): this linter isn't ported yet. @[nolint has_nonempty_instance]
structure IsocrystalEquiv extends V ≃ₗ[K(p, k)] V₂ where
frob_equivariant : ∀ x : V, Φ(p, k) (toLinearEquiv x) = toLinearEquiv (Φ(p, k) x)
scoped[Isocrystal] notation:50 M " →ᶠⁱ[" p ", " k "] " M₂ => WittVector.IsocrystalHom p k M M₂
scoped[Isocrystal] notation:50 M " ≃ᶠⁱ[" p ", " k "] " M₂ => WittVector.IsocrystalEquiv p k M M₂
end PerfectRing
open scoped Isocrystal
/-! ### Classification of isocrystals in dimension 1 -/
/-- Type synonym for `K(p, k)` to carry the standard 1-dimensional isocrystal structure
of slope `m : ℤ`.
-/
@[nolint unusedArguments]
-- Porting note(#5171): this linter isn't ported yet. @[nolint has_nonempty_instance]
def StandardOneDimIsocrystal (_m : ℤ) : Type _ :=
K(p, k)
-- Porting note(https://github.com/leanprover-community/mathlib4/issues/5020): added
section Deriving
instance {m : ℤ} : AddCommGroup (StandardOneDimIsocrystal p k m) :=
inferInstanceAs (AddCommGroup K(p, k))
instance {m : ℤ} : Module K(p, k) (StandardOneDimIsocrystal p k m) :=
inferInstanceAs (Module K(p, k) K(p, k))
end Deriving
section PerfectRing
variable [IsDomain k] [CharP k p] [PerfectRing k p]
/-- The standard one-dimensional isocrystal of slope `m : ℤ` is an isocrystal. -/
instance (m : ℤ) : Isocrystal p k (StandardOneDimIsocrystal p k m) where
frob :=
(FractionRing.frobenius p k).toSemilinearEquiv.trans
(LinearEquiv.smulOfNeZero _ _ _ (zpow_ne_zero m (WittVector.FractionRing.p_nonzero p k)))
@[simp]
theorem StandardOneDimIsocrystal.frobenius_apply (m : ℤ) (x : StandardOneDimIsocrystal p k m) :
Φ(p, k) x = (p : K(p, k)) ^ m • φ(p, k) x := rfl
end PerfectRing
/-- A one-dimensional isocrystal over an algebraically closed field
admits an isomorphism to one of the standard (indexed by `m : ℤ`) one-dimensional isocrystals. -/
theorem isocrystal_classification (k : Type*) [Field k] [IsAlgClosed k] [CharP k p] (V : Type*)
[AddCommGroup V] [Isocrystal p k V] (h_dim : finrank K(p, k) V = 1) :
∃ m : ℤ, Nonempty (StandardOneDimIsocrystal p k m ≃ᶠⁱ[p, k] V) := by
haveI : Nontrivial V := FiniteDimensional.nontrivial_of_finrank_eq_succ h_dim
obtain ⟨x, hx⟩ : ∃ x : V, x ≠ 0 := exists_ne 0
have : Φ(p, k) x ≠ 0 := by simpa only [map_zero] using Φ(p, k).injective.ne hx
obtain ⟨a, ha, hax⟩ : ∃ a : K(p, k), a ≠ 0 ∧ Φ(p, k) x = a • x := by
rw [finrank_eq_one_iff_of_nonzero' x hx] at h_dim
obtain ⟨a, ha⟩ := h_dim (Φ(p, k) x)
refine ⟨a, ?_, ha.symm⟩
intro ha'
apply this
simp only [← ha, ha', zero_smul]
obtain ⟨b, hb, m, hmb⟩ := WittVector.exists_frobenius_solution_fractionRing p ha
replace hmb : φ(p, k) b * a = (p : K(p, k)) ^ m * b := by convert hmb
use m
let F₀ : StandardOneDimIsocrystal p k m →ₗ[K(p, k)] V := LinearMap.toSpanSingleton K(p, k) V x
let F : StandardOneDimIsocrystal p k m ≃ₗ[K(p, k)] V := by
refine LinearEquiv.ofBijective F₀ ⟨?_, ?_⟩
· rw [← LinearMap.ker_eq_bot]
exact LinearMap.ker_toSpanSingleton K(p, k) V hx
· rw [← LinearMap.range_eq_top]
rw [← (finrank_eq_one_iff_of_nonzero x hx).mp h_dim]
rw [LinearMap.span_singleton_eq_range]
refine ⟨⟨(LinearEquiv.smulOfNeZero K(p, k) _ _ hb).trans F, fun c ↦ ?_⟩⟩
rw [LinearEquiv.trans_apply, LinearEquiv.trans_apply, LinearEquiv.smulOfNeZero_apply,
LinearEquiv.smulOfNeZero_apply, Units.smul_mk0, Units.smul_mk0, LinearEquiv.map_smul,
LinearEquiv.map_smul]
-- Porting note: was
-- simp only [hax, LinearEquiv.ofBijective_apply, LinearMap.toSpanSingleton_apply,
-- LinearEquiv.map_smulₛₗ, StandardOneDimIsocrystal.frobenius_apply, Algebra.id.smul_eq_mul]
rw [LinearEquiv.ofBijective_apply, LinearEquiv.ofBijective_apply]
erw [LinearMap.toSpanSingleton_apply K(p, k) V x c, LinearMap.toSpanSingleton_apply K(p, k) V x]
simp only [hax, LinearEquiv.ofBijective_apply, LinearMap.toSpanSingleton_apply,
LinearEquiv.map_smulₛₗ, StandardOneDimIsocrystal.frobenius_apply, Algebra.id.smul_eq_mul]
simp only [← mul_smul]
congr 1
linear_combination φ(p, k) c * hmb
end WittVector
|
RingTheory\WittVector\IsPoly.lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import Mathlib.Algebra.MvPolynomial.Funext
import Mathlib.Algebra.Ring.ULift
import Mathlib.RingTheory.WittVector.Basic
/-!
# The `IsPoly` predicate
`WittVector.IsPoly` is a (type-valued) predicate on functions `f : Π R, 𝕎 R → 𝕎 R`.
It asserts that there is a family of polynomials `φ : ℕ → MvPolynomial ℕ ℤ`,
such that the `n`th coefficient of `f x` is equal to `φ n` evaluated on the coefficients of `x`.
Many operations on Witt vectors satisfy this predicate (or an analogue for higher arity functions).
We say that such a function `f` is a *polynomial function*.
The power of satisfying this predicate comes from `WittVector.IsPoly.ext`.
It shows that if `φ` and `ψ` witness that `f` and `g` are polynomial functions,
then `f = g` not merely when `φ = ψ`, but in fact it suffices to prove
```
∀ n, bind₁ φ (wittPolynomial p _ n) = bind₁ ψ (wittPolynomial p _ n)
```
(in other words, when evaluating the Witt polynomials on `φ` and `ψ`, we get the same values)
which will then imply `φ = ψ` and hence `f = g`.
Even though this sufficient condition looks somewhat intimidating,
it is rather pleasant to check in practice;
more so than direct checking of `φ = ψ`.
In practice, we apply this technique to show that the composition of `WittVector.frobenius`
and `WittVector.verschiebung` is equal to multiplication by `p`.
## Main declarations
* `WittVector.IsPoly`, `WittVector.IsPoly₂`:
two predicates that assert that a unary/binary function on Witt vectors
is polynomial in the coefficients of the input values.
* `WittVector.IsPoly.ext`, `WittVector.IsPoly₂.ext`:
two polynomial functions are equal if their families of polynomials are equal
after evaluating the Witt polynomials on them.
* `WittVector.IsPoly.comp` (+ many variants) show that unary/binary compositions
of polynomial functions are polynomial.
* `WittVector.idIsPoly`, `WittVector.negIsPoly`,
`WittVector.addIsPoly₂`, `WittVector.mulIsPoly₂`:
several well-known operations are polynomial functions
(for Verschiebung, Frobenius, and multiplication by `p`, see their respective files).
## On higher arity analogues
Ideally, there should be a predicate `IsPolyₙ` for functions of higher arity,
together with `IsPolyₙ.comp` that shows how such functions compose.
Since mathlib does not have a library on composition of higher arity functions,
we have only implemented the unary and binary variants so far.
Nullary functions (a.k.a. constants) are treated
as constant functions and fall under the unary case.
## Tactics
There are important metaprograms defined in this file:
the tactics `ghost_simp` and `ghost_calc` and the attribute `@[ghost_simps]`.
These are used in combination to discharge proofs of identities between polynomial functions.
The `ghost_calc` tactic makes use of the `IsPoly` and `IsPoly₂` typeclass and its instances.
(In Lean 3, there was an `@[is_poly]` attribute to manage these instances,
because typeclass resolution did not play well with function composition.
This no longer seems to be an issue, so that such instances can be defined directly.)
Any lemma doing "ring equation rewriting" with polynomial functions should be tagged
`@[ghost_simps]`, e.g.
```lean
@[ghost_simps]
lemma bind₁_frobenius_poly_wittPolynomial (n : ℕ) :
bind₁ (frobenius_poly p) (wittPolynomial p ℤ n) = (wittPolynomial p ℤ (n+1))
```
Proofs of identities between polynomial functions will often follow the pattern
```lean
ghost_calc _
<minor preprocessing>
ghost_simp
```
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
namespace WittVector
universe u
variable {p : ℕ} {R S : Type u} {σ idx : Type*} [CommRing R] [CommRing S]
local notation "𝕎" => WittVector p -- type as `\bbW`
open MvPolynomial
open Function (uncurry)
variable (p)
noncomputable section
/-!
### The `IsPoly` predicate
-/
theorem poly_eq_of_wittPolynomial_bind_eq' [Fact p.Prime] (f g : ℕ → MvPolynomial (idx × ℕ) ℤ)
(h : ∀ n, bind₁ f (wittPolynomial p _ n) = bind₁ g (wittPolynomial p _ n)) : f = g := by
ext1 n
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
rw [← Function.funext_iff] at h
replace h :=
congr_arg (fun fam => bind₁ (MvPolynomial.map (Int.castRingHom ℚ) ∘ fam) (xInTermsOfW p ℚ n)) h
simpa only [Function.comp, map_bind₁, map_wittPolynomial, ← bind₁_bind₁,
bind₁_wittPolynomial_xInTermsOfW, bind₁_X_right] using h
theorem poly_eq_of_wittPolynomial_bind_eq [Fact p.Prime] (f g : ℕ → MvPolynomial ℕ ℤ)
(h : ∀ n, bind₁ f (wittPolynomial p _ n) = bind₁ g (wittPolynomial p _ n)) : f = g := by
ext1 n
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
rw [← Function.funext_iff] at h
replace h :=
congr_arg (fun fam => bind₁ (MvPolynomial.map (Int.castRingHom ℚ) ∘ fam) (xInTermsOfW p ℚ n)) h
simpa only [Function.comp, map_bind₁, map_wittPolynomial, ← bind₁_bind₁,
bind₁_wittPolynomial_xInTermsOfW, bind₁_X_right] using h
-- Ideally, we would generalise this to n-ary functions
-- But we don't have a good theory of n-ary compositions in mathlib
/--
A function `f : Π R, 𝕎 R → 𝕎 R` that maps Witt vectors to Witt vectors over arbitrary base rings
is said to be *polynomial* if there is a family of polynomials `φₙ` over `ℤ` such that the `n`th
coefficient of `f x` is given by evaluating `φₙ` at the coefficients of `x`.
See also `WittVector.IsPoly₂` for the binary variant.
The `ghost_calc` tactic makes use of the `IsPoly` and `IsPoly₂` typeclass and its instances.
(In Lean 3, there was an `@[is_poly]` attribute to manage these instances,
because typeclass resolution did not play well with function composition.
This no longer seems to be an issue, so that such instances can be defined directly.)
-/
class IsPoly (f : ∀ ⦃R⦄ [CommRing R], WittVector p R → 𝕎 R) : Prop where mk' ::
poly :
∃ φ : ℕ → MvPolynomial ℕ ℤ,
∀ ⦃R⦄ [CommRing R] (x : 𝕎 R), (f x).coeff = fun n => aeval x.coeff (φ n)
/-- The identity function on Witt vectors is a polynomial function. -/
instance idIsPoly : IsPoly p fun _ _ => id :=
⟨⟨X, by intros; simp only [aeval_X, id]⟩⟩
instance idIsPolyI' : IsPoly p fun _ _ a => a :=
WittVector.idIsPoly _
namespace IsPoly
instance : Inhabited (IsPoly p fun _ _ => id) :=
⟨WittVector.idIsPoly p⟩
variable {p}
theorem ext [Fact p.Prime] {f g} (hf : IsPoly p f) (hg : IsPoly p g)
(h : ∀ (R : Type u) [_Rcr : CommRing R] (x : 𝕎 R) (n : ℕ),
ghostComponent n (f x) = ghostComponent n (g x)) :
∀ (R : Type u) [_Rcr : CommRing R] (x : 𝕎 R), f x = g x := by
obtain ⟨φ, hf⟩ := hf
obtain ⟨ψ, hg⟩ := hg
intros
ext n
rw [hf, hg, poly_eq_of_wittPolynomial_bind_eq p φ ψ]
intro k
apply MvPolynomial.funext
intro x
simp only [hom_bind₁]
specialize h (ULift ℤ) (mk p fun i => ⟨x i⟩) k
simp only [ghostComponent_apply, aeval_eq_eval₂Hom] at h
apply (ULift.ringEquiv.symm : ℤ ≃+* _).injective
simp only [← RingEquiv.coe_toRingHom, map_eval₂Hom]
convert h using 1
all_goals
simp only [hf, hg, MvPolynomial.eval, map_eval₂Hom]
apply eval₂Hom_congr (RingHom.ext_int _ _) _ rfl
ext1
apply eval₂Hom_congr (RingHom.ext_int _ _) _ rfl
simp only [coeff_mk]; rfl
/-- The composition of polynomial functions is polynomial. -/
-- Porting note (#10754): made this an instance
instance comp {g f} [hg : IsPoly p g] [hf : IsPoly p f] :
IsPoly p fun R _Rcr => @g R _Rcr ∘ @f R _Rcr := by
obtain ⟨φ, hf⟩ := hf
obtain ⟨ψ, hg⟩ := hg
use fun n => bind₁ φ (ψ n)
intros
simp only [aeval_bind₁, Function.comp, hg, hf]
end IsPoly
/-- A binary function `f : Π R, 𝕎 R → 𝕎 R → 𝕎 R` on Witt vectors
is said to be *polynomial* if there is a family of polynomials `φₙ` over `ℤ` such that the `n`th
coefficient of `f x y` is given by evaluating `φₙ` at the coefficients of `x` and `y`.
See also `WittVector.IsPoly` for the unary variant.
The `ghost_calc` tactic makes use of the `IsPoly` and `IsPoly₂` typeclass and its instances.
(In Lean 3, there was an `@[is_poly]` attribute to manage these instances,
because typeclass resolution did not play well with function composition.
This no longer seems to be an issue, so that such instances can be defined directly.)
-/
class IsPoly₂ (f : ∀ ⦃R⦄ [CommRing R], WittVector p R → 𝕎 R → 𝕎 R) : Prop where mk' ::
poly :
∃ φ : ℕ → MvPolynomial (Fin 2 × ℕ) ℤ,
∀ ⦃R⦄ [CommRing R] (x y : 𝕎 R), (f x y).coeff = fun n => peval (φ n) ![x.coeff, y.coeff]
variable {p}
/-- The composition of polynomial functions is polynomial. -/
-- Porting note (#10754): made this an instance
instance IsPoly₂.comp {h f g} [hh : IsPoly₂ p h] [hf : IsPoly p f] [hg : IsPoly p g] :
IsPoly₂ p fun R _Rcr x y => h (f x) (g y) := by
obtain ⟨φ, hf⟩ := hf
obtain ⟨ψ, hg⟩ := hg
obtain ⟨χ, hh⟩ := hh
refine ⟨⟨fun n ↦ bind₁ (uncurry <|
![fun k ↦ rename (Prod.mk (0 : Fin 2)) (φ k),
fun k ↦ rename (Prod.mk (1 : Fin 2)) (ψ k)]) (χ n), ?_⟩⟩
intros
funext n
simp (config := { unfoldPartialApp := true }) only [peval, aeval_bind₁, Function.comp, hh, hf, hg,
uncurry]
apply eval₂Hom_congr rfl _ rfl
ext ⟨i, n⟩
fin_cases i <;> simp [aeval_eq_eval₂Hom, eval₂Hom_rename, Function.comp]
/-- The composition of a polynomial function with a binary polynomial function is polynomial. -/
-- Porting note (#10754): made this an instance
instance IsPoly.comp₂ {g f} [hg : IsPoly p g] [hf : IsPoly₂ p f] :
IsPoly₂ p fun R _Rcr x y => g (f x y) := by
obtain ⟨φ, hf⟩ := hf
obtain ⟨ψ, hg⟩ := hg
use fun n => bind₁ φ (ψ n)
intros
simp only [peval, aeval_bind₁, Function.comp, hg, hf]
/-- The diagonal `fun x ↦ f x x` of a polynomial function `f` is polynomial. -/
-- Porting note (#10754): made this an instance
instance IsPoly₂.diag {f} [hf : IsPoly₂ p f] : IsPoly p fun R _Rcr x => f x x := by
obtain ⟨φ, hf⟩ := hf
refine ⟨⟨fun n => bind₁ (uncurry ![X, X]) (φ n), ?_⟩⟩
intros; funext n
simp (config := { unfoldPartialApp := true }) only [hf, peval, uncurry, aeval_bind₁]
apply eval₂Hom_congr rfl _ rfl
ext ⟨i, k⟩
fin_cases i <;> simp
-- Porting note: Lean 4's typeclass inference is sufficiently more powerful that we no longer
-- need the `@[is_poly]` attribute. Use of the attribute should just be replaced by changing the
-- theorem to an `instance`.
/-- The additive negation is a polynomial function on Witt vectors. -/
-- Porting note: replaced `@[is_poly]` with `instance`.
instance negIsPoly [Fact p.Prime] : IsPoly p fun R _ => @Neg.neg (𝕎 R) _ :=
⟨⟨fun n => rename Prod.snd (wittNeg p n), by
intros; funext n
rw [neg_coeff, aeval_eq_eval₂Hom, eval₂Hom_rename]
apply eval₂Hom_congr rfl _ rfl
ext ⟨i, k⟩; fin_cases i; rfl⟩⟩
section ZeroOne
/- To avoid a theory of 0-ary functions (a.k.a. constants)
we model them as constant unary functions. -/
/-- The function that is constantly zero on Witt vectors is a polynomial function. -/
instance zeroIsPoly [Fact p.Prime] : IsPoly p fun _ _ _ => 0 :=
⟨⟨0, by intros; funext n; simp only [Pi.zero_apply, map_zero, zero_coeff]⟩⟩
@[simp]
theorem bind₁_zero_wittPolynomial [Fact p.Prime] (n : ℕ) :
bind₁ (0 : ℕ → MvPolynomial ℕ R) (wittPolynomial p R n) = 0 := by
rw [← aeval_eq_bind₁, aeval_zero, constantCoeff_wittPolynomial, RingHom.map_zero]
/-- The coefficients of `1 : 𝕎 R` as polynomials. -/
def onePoly (n : ℕ) : MvPolynomial ℕ ℤ :=
if n = 0 then 1 else 0
@[simp]
theorem bind₁_onePoly_wittPolynomial [hp : Fact p.Prime] (n : ℕ) :
bind₁ onePoly (wittPolynomial p ℤ n) = 1 := by
rw [wittPolynomial_eq_sum_C_mul_X_pow, map_sum, Finset.sum_eq_single 0]
· simp only [onePoly, one_pow, one_mul, map_pow, C_1, pow_zero, bind₁_X_right, if_true,
eq_self_iff_true]
· intro i _hi hi0
simp only [onePoly, if_neg hi0, zero_pow (pow_ne_zero _ hp.1.ne_zero), mul_zero, map_pow,
bind₁_X_right, map_mul]
· simp
/-- The function that is constantly one on Witt vectors is a polynomial function. -/
instance oneIsPoly [Fact p.Prime] : IsPoly p fun _ _ _ => 1 :=
⟨⟨onePoly, by
intros; funext n; cases n
· -- Porting note: was `simp only [...]` but with slightly different `[...]`.
simp only [Nat.zero_eq, lt_self_iff_false, one_coeff_zero, onePoly, ite_true, map_one]
· -- Porting note: was `simp only [...]` but with slightly different `[...]`.
simp only [Nat.succ_pos', one_coeff_eq_of_pos, onePoly, Nat.succ_ne_zero, ite_false,
map_zero]
⟩⟩
end ZeroOne
/-- Addition of Witt vectors is a polynomial function. -/
-- Porting note: replaced `@[is_poly]` with `instance`.
instance addIsPoly₂ [Fact p.Prime] : IsPoly₂ p fun _ _ => (· + ·) :=
-- porting note: the proof was
-- `⟨⟨wittAdd p, by intros; dsimp only [WittVector.hasAdd]; simp [eval]⟩⟩`
⟨⟨wittAdd p, by intros; ext; exact add_coeff _ _ _⟩⟩
/-- Multiplication of Witt vectors is a polynomial function. -/
-- Porting note: replaced `@[is_poly]` with `instance`.
instance mulIsPoly₂ [Fact p.Prime] : IsPoly₂ p fun _ _ => (· * ·) :=
-- porting note: the proof was
-- `⟨⟨wittMul p, by intros; dsimp only [WittVector.hasMul]; simp [eval]⟩⟩`
⟨⟨wittMul p, by intros; ext; exact mul_coeff _ _ _⟩⟩
-- unfortunately this is not universe polymorphic, merely because `f` isn't
theorem IsPoly.map [Fact p.Prime] {f} (hf : IsPoly p f) (g : R →+* S) (x : 𝕎 R) :
map g (f x) = f (map g x) := by
-- this could be turned into a tactic “macro” (taking `hf` as parameter)
-- so that applications do not have to worry about the universe issue
-- see `IsPoly₂.map` for a slightly more general proof strategy
obtain ⟨φ, hf⟩ := hf
ext n
simp only [map_coeff, hf, map_aeval]
apply eval₂Hom_congr (RingHom.ext_int _ _) _ rfl
ext -- Porting note: this `ext` was not present in the mathport output
simp only [map_coeff]
namespace IsPoly₂
-- porting note: the argument `(fun _ _ => (· + ·))` to `IsPoly₂` was just `_`.
instance [Fact p.Prime] : Inhabited (IsPoly₂ p (fun _ _ => (· + ·))) :=
⟨addIsPoly₂⟩
-- Porting note: maybe just drop this now that it works by `inferInstance`
/-- The composition of a binary polynomial function
with a unary polynomial function in the first argument is polynomial. -/
theorem compLeft {g f} [IsPoly₂ p g] [IsPoly p f] :
IsPoly₂ p fun _R _Rcr x y => g (f x) y :=
inferInstance
-- Porting note: maybe just drop this now that it works by `inferInstance`
/-- The composition of a binary polynomial function
with a unary polynomial function in the second argument is polynomial. -/
theorem compRight {g f} [IsPoly₂ p g] [IsPoly p f] :
IsPoly₂ p fun _R _Rcr x y => g x (f y) :=
inferInstance
theorem ext [Fact p.Prime] {f g} (hf : IsPoly₂ p f) (hg : IsPoly₂ p g)
(h : ∀ (R : Type u) [_Rcr : CommRing R] (x y : 𝕎 R) (n : ℕ),
ghostComponent n (f x y) = ghostComponent n (g x y)) :
∀ (R) [_Rcr : CommRing R] (x y : 𝕎 R), f x y = g x y := by
obtain ⟨φ, hf⟩ := hf
obtain ⟨ψ, hg⟩ := hg
intros
ext n
rw [hf, hg, poly_eq_of_wittPolynomial_bind_eq' p φ ψ]
-- porting note: `clear x y` does not work, since `x, y` are now hygienic
intro k
apply MvPolynomial.funext
intro x
simp only [hom_bind₁]
specialize h (ULift ℤ) (mk p fun i => ⟨x (0, i)⟩) (mk p fun i => ⟨x (1, i)⟩) k
simp only [ghostComponent_apply, aeval_eq_eval₂Hom] at h
apply (ULift.ringEquiv.symm : ℤ ≃+* _).injective
simp only [← RingEquiv.coe_toRingHom, map_eval₂Hom]
convert h using 1
all_goals
simp only [hf, hg, MvPolynomial.eval, map_eval₂Hom]
apply eval₂Hom_congr (RingHom.ext_int _ _) _ rfl
ext1
apply eval₂Hom_congr (RingHom.ext_int _ _) _ rfl
ext ⟨b, _⟩
fin_cases b <;> simp only [coeff_mk, uncurry] <;> rfl
-- unfortunately this is not universe polymorphic, merely because `f` isn't
theorem map [Fact p.Prime] {f} (hf : IsPoly₂ p f) (g : R →+* S) (x y : 𝕎 R) :
map g (f x y) = f (map g x) (map g y) := by
-- this could be turned into a tactic “macro” (taking `hf` as parameter)
-- so that applications do not have to worry about the universe issue
obtain ⟨φ, hf⟩ := hf
ext n
simp (config := { unfoldPartialApp := true }) only [map_coeff, hf, map_aeval, peval, uncurry]
apply eval₂Hom_congr (RingHom.ext_int _ _) _ rfl
ext ⟨i, k⟩
fin_cases i <;> simp
end IsPoly₂
attribute [ghost_simps] AlgHom.map_zero AlgHom.map_one AlgHom.map_add AlgHom.map_mul AlgHom.map_sub
AlgHom.map_neg AlgHom.id_apply map_natCast RingHom.map_zero RingHom.map_one RingHom.map_mul
RingHom.map_add RingHom.map_sub RingHom.map_neg RingHom.id_apply mul_add add_mul add_zero zero_add
mul_one one_mul mul_zero zero_mul Nat.succ_ne_zero add_tsub_cancel_right
Nat.succ_eq_add_one if_true eq_self_iff_true if_false forall_true_iff forall₂_true_iff
forall₃_true_iff
end
namespace Tactic
open Lean Parser.Tactic Elab.Tactic
/-- A macro for a common simplification when rewriting with ghost component equations. -/
syntax (name := ghostSimp) "ghost_simp" (simpArgs)? : tactic
macro_rules
| `(tactic| ghost_simp $[[$simpArgs,*]]?) => do
let args := simpArgs.map (·.getElems) |>.getD #[]
`(tactic| simp only [← sub_eq_add_neg, ghost_simps, $args,*])
/-- `ghost_calc` is a tactic for proving identities between polynomial functions.
Typically, when faced with a goal like
```lean
∀ (x y : 𝕎 R), verschiebung (x * frobenius y) = verschiebung x * y
```
you can
1. call `ghost_calc`
2. do a small amount of manual work -- maybe nothing, maybe `rintro`, etc
3. call `ghost_simp`
and this will close the goal.
`ghost_calc` cannot detect whether you are dealing with unary or binary polynomial functions.
You must give it arguments to determine this.
If you are proving a universally quantified goal like the above,
call `ghost_calc _ _`.
If the variables are introduced already, call `ghost_calc x y`.
In the unary case, use `ghost_calc _` or `ghost_calc x`.
`ghost_calc` is a light wrapper around type class inference.
All it does is apply the appropriate extensionality lemma and try to infer the resulting goals.
This is subtle and Lean's elaborator doesn't like it because of the HO unification involved,
so it is easier (and prettier) to put it in a tactic script.
-/
syntax (name := ghostCalc) "ghost_calc" (ppSpace colGt term:max)* : tactic
private def runIntro (ref : Syntax) (n : Name) : TacticM FVarId := do
let fvarId ← liftMetaTacticAux fun g => do
let (fv, g') ← g.intro n
return (fv, [g'])
withMainContext do
Elab.Term.addLocalVarInfo ref (mkFVar fvarId)
return fvarId
private def getLocalOrIntro (t : Term) : TacticM FVarId := do
match t with
| `(_) => runIntro t `_
| `($id:ident) => getFVarId id <|> runIntro id id.getId
| _ => Elab.throwUnsupportedSyntax
elab_rules : tactic | `(tactic| ghost_calc $[$ids']*) => do
let ids ← ids'.mapM getLocalOrIntro
withMainContext do
let idsS ← ids.mapM (fun id => Elab.Term.exprToSyntax (.fvar id))
let some (α, lhs, rhs) := (← getMainTarget'').eq?
| throwError "ghost_calc expecting target to be an equality"
let (``WittVector, #[_, R]) := α.getAppFnArgs
| throwError "ghost_calc expecting target to be an equality of `WittVector`s"
let instR ← Meta.synthInstance (← Meta.mkAppM ``CommRing #[R])
unless instR.isFVar do
throwError "{← Meta.inferType instR} instance is not local"
let f ← Meta.mkLambdaFVars (#[R, instR] ++ ids.map .fvar) lhs
let g ← Meta.mkLambdaFVars (#[R, instR] ++ ids.map .fvar) rhs
let fS ← Elab.Term.exprToSyntax f
let gS ← Elab.Term.exprToSyntax g
match idsS with
| #[x] => evalTactic (← `(tactic| refine IsPoly.ext (f := $fS) (g := $gS) ?_ ?_ ?_ _ $x))
| #[x, y] => evalTactic (← `(tactic| refine IsPoly₂.ext (f := $fS) (g := $gS) ?_ ?_ ?_ _ $x $y))
| _ => throwError "ghost_calc takes either one or two arguments"
let nm ← withMainContext <|
if let .fvar fvarId := (R : Expr) then
fvarId.getUserName
else
Meta.getUnusedUserName `R
evalTactic <| ← `(tactic| iterate 2 infer_instance)
let R := mkIdent nm
evalTactic <| ← `(tactic| clear! $R)
evalTactic <| ← `(tactic| intro $(mkIdent nm):ident $(mkIdent (.str nm "_inst")):ident $ids'*)
end Tactic
end WittVector
|
RingTheory\WittVector\MulCoeff.lean | /-
Copyright (c) 2022 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Heather Macbeth
-/
import Mathlib.Algebra.MvPolynomial.Supported
import Mathlib.RingTheory.WittVector.Truncated
/-!
# Leading terms of Witt vector multiplication
The goal of this file is to study the leading terms of the formula for the `n+1`st coefficient
of a product of Witt vectors `x` and `y` over a ring of characteristic `p`.
We aim to isolate the `n+1`st coefficients of `x` and `y`, and express the rest of the product
in terms of a function of the lower coefficients.
For most of this file we work with terms of type `MvPolynomial (Fin 2 × ℕ) ℤ`.
We will eventually evaluate them in `k`, but first we must take care of a calculation
that needs to happen in characteristic 0.
## Main declarations
* `WittVector.nth_mul_coeff`: expresses the coefficient of a product of Witt vectors
in terms of the previous coefficients of the multiplicands.
-/
noncomputable section
namespace WittVector
variable (p : ℕ) [hp : Fact p.Prime]
variable {k : Type*} [CommRing k]
local notation "𝕎" => WittVector p
-- Porting note: new notation
local notation "𝕄" => MvPolynomial (Fin 2 × ℕ) ℤ
open Finset MvPolynomial
/--
```
(∑ i ∈ range n, (y.coeff i)^(p^(n-i)) * p^i.val) *
(∑ i ∈ range n, (y.coeff i)^(p^(n-i)) * p^i.val)
```
-/
def wittPolyProd (n : ℕ) : 𝕄 :=
rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ n) *
rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ n)
theorem wittPolyProd_vars (n : ℕ) : (wittPolyProd p n).vars ⊆ univ ×ˢ range (n + 1) := by
rw [wittPolyProd]
apply Subset.trans (vars_mul _ _)
refine union_subset ?_ ?_ <;>
· refine Subset.trans (vars_rename _ _) ?_
simp [wittPolynomial_vars, image_subset_iff]
/-- The "remainder term" of `WittVector.wittPolyProd`. See `mul_polyOfInterest_aux2`. -/
def wittPolyProdRemainder (n : ℕ) : 𝕄 :=
∑ i ∈ range n, (p : 𝕄) ^ i * wittMul p i ^ p ^ (n - i)
theorem wittPolyProdRemainder_vars (n : ℕ) :
(wittPolyProdRemainder p n).vars ⊆ univ ×ˢ range n := by
rw [wittPolyProdRemainder]
refine Subset.trans (vars_sum_subset _ _) ?_
rw [biUnion_subset]
intro x hx
apply Subset.trans (vars_mul _ _)
refine union_subset ?_ ?_
· apply Subset.trans (vars_pow _ _)
have : (p : 𝕄) = C (p : ℤ) := by simp only [Int.cast_natCast, eq_intCast]
rw [this, vars_C]
apply empty_subset
· apply Subset.trans (vars_pow _ _)
apply Subset.trans (wittMul_vars _ _)
apply product_subset_product (Subset.refl _)
simp only [mem_range, range_subset] at hx ⊢
exact hx
/-- `remainder p n` represents the remainder term from `mul_polyOfInterest_aux3`.
`wittPolyProd p (n+1)` will have variables up to `n+1`,
but `remainder` will only have variables up to `n`.
-/
def remainder (n : ℕ) : 𝕄 :=
(∑ x ∈ range (n + 1),
(rename (Prod.mk 0)) ((monomial (Finsupp.single x (p ^ (n + 1 - x)))) ((p : ℤ) ^ x))) *
∑ x ∈ range (n + 1),
(rename (Prod.mk 1)) ((monomial (Finsupp.single x (p ^ (n + 1 - x)))) ((p : ℤ) ^ x))
theorem remainder_vars (n : ℕ) : (remainder p n).vars ⊆ univ ×ˢ range (n + 1) := by
rw [remainder]
apply Subset.trans (vars_mul _ _)
refine union_subset ?_ ?_ <;>
· refine Subset.trans (vars_sum_subset _ _) ?_
rw [biUnion_subset]
intro x hx
rw [rename_monomial, vars_monomial, Finsupp.mapDomain_single]
· apply Subset.trans Finsupp.support_single_subset
simpa using mem_range.mp hx
· apply pow_ne_zero
exact mod_cast hp.out.ne_zero
/-- This is the polynomial whose degree we want to get a handle on. -/
def polyOfInterest (n : ℕ) : 𝕄 :=
wittMul p (n + 1) + (p : 𝕄) ^ (n + 1) * X (0, n + 1) * X (1, n + 1) -
X (0, n + 1) * rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ (n + 1)) -
X (1, n + 1) * rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ (n + 1))
theorem mul_polyOfInterest_aux1 (n : ℕ) :
∑ i ∈ range (n + 1), (p : 𝕄) ^ i * wittMul p i ^ p ^ (n - i) = wittPolyProd p n := by
simp only [wittPolyProd]
convert wittStructureInt_prop p (X (0 : Fin 2) * X 1) n using 1
· simp only [wittPolynomial, wittMul]
rw [map_sum]
congr 1 with i
congr 1
have hsupp : (Finsupp.single i (p ^ (n - i))).support = {i} := by
rw [Finsupp.support_eq_singleton]
simp only [and_true_iff, Finsupp.single_eq_same, eq_self_iff_true, Ne]
exact pow_ne_zero _ hp.out.ne_zero
simp only [bind₁_monomial, hsupp, Int.cast_natCast, prod_singleton, eq_intCast,
Finsupp.single_eq_same, C_pow, mul_eq_mul_left_iff, true_or_iff, eq_self_iff_true,
Int.cast_pow]
· simp only [map_mul, bind₁_X_right]
theorem mul_polyOfInterest_aux2 (n : ℕ) :
(p : 𝕄) ^ n * wittMul p n + wittPolyProdRemainder p n = wittPolyProd p n := by
convert mul_polyOfInterest_aux1 p n
rw [sum_range_succ, add_comm, Nat.sub_self, pow_zero, pow_one]
rfl
theorem mul_polyOfInterest_aux3 (n : ℕ) : wittPolyProd p (n + 1) =
-((p : 𝕄) ^ (n + 1) * X (0, n + 1)) * ((p : 𝕄) ^ (n + 1) * X (1, n + 1)) +
(p : 𝕄) ^ (n + 1) * X (0, n + 1) * rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ (n + 1)) +
(p : 𝕄) ^ (n + 1) * X (1, n + 1) * rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ (n + 1)) +
remainder p n := by
-- a useful auxiliary fact
have mvpz : (p : 𝕄) ^ (n + 1) = MvPolynomial.C ((p : ℤ) ^ (n + 1)) := by norm_cast
-- Porting note: the original proof applies `sum_range_succ` through a non-`conv` rewrite,
-- but this does not work in Lean 4; the whole proof also times out very badly. The proof has been
-- nearly totally rewritten here and now finishes quite fast.
rw [wittPolyProd, wittPolynomial, map_sum, map_sum]
conv_lhs =>
arg 1
rw [sum_range_succ, ← C_mul_X_pow_eq_monomial, tsub_self, pow_zero, pow_one, map_mul,
rename_C, rename_X, ← mvpz]
conv_lhs =>
arg 2
rw [sum_range_succ, ← C_mul_X_pow_eq_monomial, tsub_self, pow_zero, pow_one, map_mul,
rename_C, rename_X, ← mvpz]
conv_rhs =>
enter [1, 1, 2, 2]
rw [sum_range_succ, ← C_mul_X_pow_eq_monomial, tsub_self, pow_zero, pow_one, map_mul,
rename_C, rename_X, ← mvpz]
conv_rhs =>
enter [1, 2, 2]
rw [sum_range_succ, ← C_mul_X_pow_eq_monomial, tsub_self, pow_zero, pow_one, map_mul,
rename_C, rename_X, ← mvpz]
simp only [add_mul, mul_add]
rw [add_comm _ (remainder p n)]
simp only [add_assoc]
apply congrArg (Add.add _)
ring
theorem mul_polyOfInterest_aux4 (n : ℕ) :
(p : 𝕄) ^ (n + 1) * wittMul p (n + 1) =
-((p : 𝕄) ^ (n + 1) * X (0, n + 1)) * ((p : 𝕄) ^ (n + 1) * X (1, n + 1)) +
(p : 𝕄) ^ (n + 1) * X (0, n + 1) * rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ (n + 1)) +
(p : 𝕄) ^ (n + 1) * X (1, n + 1) * rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ (n + 1)) +
(remainder p n - wittPolyProdRemainder p (n + 1)) := by
rw [← add_sub_assoc, eq_sub_iff_add_eq, mul_polyOfInterest_aux2]
exact mul_polyOfInterest_aux3 _ _
theorem mul_polyOfInterest_aux5 (n : ℕ) :
(p : 𝕄) ^ (n + 1) * polyOfInterest p n = remainder p n - wittPolyProdRemainder p (n + 1) := by
simp only [polyOfInterest, mul_sub, mul_add, sub_eq_iff_eq_add']
rw [mul_polyOfInterest_aux4 p n]
ring
theorem mul_polyOfInterest_vars (n : ℕ) :
((p : 𝕄) ^ (n + 1) * polyOfInterest p n).vars ⊆ univ ×ˢ range (n + 1) := by
rw [mul_polyOfInterest_aux5]
apply Subset.trans (vars_sub_subset _)
refine union_subset ?_ ?_
· apply remainder_vars
· apply wittPolyProdRemainder_vars
theorem polyOfInterest_vars_eq (n : ℕ) : (polyOfInterest p n).vars =
((p : 𝕄) ^ (n + 1) * (wittMul p (n + 1) + (p : 𝕄) ^ (n + 1) * X (0, n + 1) * X (1, n + 1) -
X (0, n + 1) * rename (Prod.mk (1 : Fin 2)) (wittPolynomial p ℤ (n + 1)) -
X (1, n + 1) * rename (Prod.mk (0 : Fin 2)) (wittPolynomial p ℤ (n + 1)))).vars := by
have : (p : 𝕄) ^ (n + 1) = C ((p : ℤ) ^ (n + 1)) := by norm_cast
rw [polyOfInterest, this, vars_C_mul]
apply pow_ne_zero
exact mod_cast hp.out.ne_zero
theorem polyOfInterest_vars (n : ℕ) : (polyOfInterest p n).vars ⊆ univ ×ˢ range (n + 1) := by
rw [polyOfInterest_vars_eq]; apply mul_polyOfInterest_vars
theorem peval_polyOfInterest (n : ℕ) (x y : 𝕎 k) :
peval (polyOfInterest p n) ![fun i => x.coeff i, fun i => y.coeff i] =
(x * y).coeff (n + 1) + p ^ (n + 1) * x.coeff (n + 1) * y.coeff (n + 1) -
y.coeff (n + 1) * ∑ i ∈ range (n + 1 + 1), p ^ i * x.coeff i ^ p ^ (n + 1 - i) -
x.coeff (n + 1) * ∑ i ∈ range (n + 1 + 1), p ^ i * y.coeff i ^ p ^ (n + 1 - i) := by
simp only [polyOfInterest, peval, map_natCast, Matrix.head_cons, map_pow,
Function.uncurry_apply_pair, aeval_X, Matrix.cons_val_one, map_mul, Matrix.cons_val_zero,
map_sub]
rw [sub_sub, add_comm (_ * _), ← sub_sub]
simp [wittPolynomial_eq_sum_C_mul_X_pow, aeval, eval₂_rename, mul_coeff, peval, map_natCast,
map_add, map_pow, map_mul]
variable [CharP k p]
/-- The characteristic `p` version of `peval_polyOfInterest` -/
theorem peval_polyOfInterest' (n : ℕ) (x y : 𝕎 k) :
peval (polyOfInterest p n) ![fun i => x.coeff i, fun i => y.coeff i] =
(x * y).coeff (n + 1) - y.coeff (n + 1) * x.coeff 0 ^ p ^ (n + 1) -
x.coeff (n + 1) * y.coeff 0 ^ p ^ (n + 1) := by
rw [peval_polyOfInterest]
have : (p : k) = 0 := CharP.cast_eq_zero k p
simp only [this, Nat.cast_pow, ne_eq, add_eq_zero, and_false, zero_pow, zero_mul, add_zero,
not_false_eq_true]
have sum_zero_pow_mul_pow_p (y : 𝕎 k) : ∑ x ∈ range (n + 1 + 1),
(0 : k) ^ x * y.coeff x ^ p ^ (n + 1 - x) = y.coeff 0 ^ p ^ (n + 1) := by
rw [Finset.sum_eq_single_of_mem 0] <;> simp (config := { contextual := true })
congr <;> apply sum_zero_pow_mul_pow_p
variable (k)
theorem nth_mul_coeff' (n : ℕ) :
∃ f : TruncatedWittVector p (n + 1) k → TruncatedWittVector p (n + 1) k → k,
∀ x y : 𝕎 k, f (truncateFun (n + 1) x) (truncateFun (n + 1) y) =
(x * y).coeff (n + 1) - y.coeff (n + 1) * x.coeff 0 ^ p ^ (n + 1) -
x.coeff (n + 1) * y.coeff 0 ^ p ^ (n + 1) := by
simp only [← peval_polyOfInterest']
obtain ⟨f₀, hf₀⟩ := exists_restrict_to_vars k (polyOfInterest_vars p n)
have : ∀ (a : Multiset (Fin 2)) (b : Multiset ℕ), a ×ˢ b = a.product b := fun a b => rfl
let f : TruncatedWittVector p (n + 1) k → TruncatedWittVector p (n + 1) k → k := by
intro x y
apply f₀
rintro ⟨a, ha⟩
apply Function.uncurry ![x, y]
simp_rw [product_val, this, Multiset.mem_product, mem_univ_val, true_and_iff, range_val,
Multiset.range_succ, Multiset.mem_cons, Multiset.mem_range] at ha
refine ⟨a.fst, ⟨a.snd, ?_⟩⟩
cases' ha with ha ha <;> omega
use f
intro x y
dsimp [f, peval]
rw [← hf₀]
congr
ext a
cases' a with a ha
cases' a with i m
fin_cases i <;> rfl -- surely this case split is not necessary
theorem nth_mul_coeff (n : ℕ) :
∃ f : TruncatedWittVector p (n + 1) k → TruncatedWittVector p (n + 1) k → k,
∀ x y : 𝕎 k, (x * y).coeff (n + 1) =
x.coeff (n + 1) * y.coeff 0 ^ p ^ (n + 1) + y.coeff (n + 1) * x.coeff 0 ^ p ^ (n + 1) +
f (truncateFun (n + 1) x) (truncateFun (n + 1) y) := by
obtain ⟨f, hf⟩ := nth_mul_coeff' p k n
use f
intro x y
rw [hf x y]
ring
variable {k}
/--
Produces the "remainder function" of the `n+1`st coefficient, which does not depend on the `n+1`st
coefficients of the inputs. -/
def nthRemainder (n : ℕ) : (Fin (n + 1) → k) → (Fin (n + 1) → k) → k :=
Classical.choose (nth_mul_coeff p k n)
theorem nthRemainder_spec (n : ℕ) (x y : 𝕎 k) : (x * y).coeff (n + 1) =
x.coeff (n + 1) * y.coeff 0 ^ p ^ (n + 1) + y.coeff (n + 1) * x.coeff 0 ^ p ^ (n + 1) +
nthRemainder p n (truncateFun (n + 1) x) (truncateFun (n + 1) y) :=
Classical.choose_spec (nth_mul_coeff p k n) _ _
end WittVector
|
RingTheory\WittVector\MulP.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.RingTheory.WittVector.IsPoly
/-!
## Multiplication by `n` in the ring of Witt vectors
In this file we show that multiplication by `n` in the ring of Witt vectors
is a polynomial function. We then use this fact to show that the composition of Frobenius
and Verschiebung is equal to multiplication by `p`.
### Main declarations
* `mulN_isPoly`: multiplication by `n` is a polynomial function
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
namespace WittVector
variable {p : ℕ} {R : Type*} [hp : Fact p.Prime] [CommRing R]
local notation "𝕎" => WittVector p -- type as `\bbW`
open MvPolynomial
noncomputable section
variable (p)
/-- `wittMulN p n` is the family of polynomials that computes
the coefficients of `x * n` in terms of the coefficients of the Witt vector `x`. -/
noncomputable def wittMulN : ℕ → ℕ → MvPolynomial ℕ ℤ
| 0 => 0
| n + 1 => fun k => bind₁ (Function.uncurry <| ![wittMulN n, X]) (wittAdd p k)
variable {p}
theorem mulN_coeff (n : ℕ) (x : 𝕎 R) (k : ℕ) :
(x * n).coeff k = aeval x.coeff (wittMulN p n k) := by
induction' n with n ih generalizing k
· simp only [Nat.cast_zero, mul_zero, zero_coeff, wittMulN, Pi.zero_apply, map_zero]
· rw [wittMulN, Nat.cast_add, Nat.cast_one, mul_add, mul_one, aeval_bind₁, add_coeff]
apply eval₂Hom_congr (RingHom.ext_int _ _) _ rfl
ext1 ⟨b, i⟩
fin_cases b
· simp [Function.uncurry, Matrix.cons_val_zero, ih]
· simp [Function.uncurry, Matrix.cons_val_one, Matrix.head_cons, aeval_X]
variable (p)
/-- Multiplication by `n` is a polynomial function. -/
@[is_poly]
theorem mulN_isPoly (n : ℕ) : IsPoly p fun R _Rcr x => x * n :=
⟨⟨wittMulN p n, fun R _Rcr x => by funext k; exact mulN_coeff n x k⟩⟩
@[simp]
theorem bind₁_wittMulN_wittPolynomial (n k : ℕ) :
bind₁ (wittMulN p n) (wittPolynomial p ℤ k) = n * wittPolynomial p ℤ k := by
induction' n with n ih
· simp [wittMulN, Nat.cast_zero, zero_mul, bind₁_zero_wittPolynomial]
· rw [wittMulN, ← bind₁_bind₁, wittAdd, wittStructureInt_prop]
simp only [map_add, Nat.cast_succ, bind₁_X_right]
rw [add_mul, one_mul, bind₁_rename, bind₁_rename]
simp only [ih, Function.uncurry, Function.comp, bind₁_X_left, AlgHom.id_apply,
Matrix.cons_val_zero, Matrix.head_cons, Matrix.cons_val_one]
end
end WittVector
|
RingTheory\WittVector\StructurePolynomial.lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import Mathlib.FieldTheory.Finite.Polynomial
import Mathlib.NumberTheory.Basic
import Mathlib.RingTheory.WittVector.WittPolynomial
/-!
# Witt structure polynomials
In this file we prove the main theorem that makes the whole theory of Witt vectors work.
Briefly, consider a polynomial `Φ : MvPolynomial idx ℤ` over the integers,
with polynomials variables indexed by an arbitrary type `idx`.
Then there exists a unique family of polynomials `φ : ℕ → MvPolynomial (idx × ℕ) Φ`
such that for all `n : ℕ` we have (`wittStructureInt_existsUnique`)
```
bind₁ φ (wittPolynomial p ℤ n) = bind₁ (fun i ↦ (rename (prod.mk i) (wittPolynomial p ℤ n))) Φ
```
In other words: evaluating the `n`-th Witt polynomial on the family `φ`
is the same as evaluating `Φ` on the (appropriately renamed) `n`-th Witt polynomials.
N.b.: As far as we know, these polynomials do not have a name in the literature,
so we have decided to call them the “Witt structure polynomials”. See `wittStructureInt`.
## Special cases
With the main result of this file in place, we apply it to certain special polynomials.
For example, by taking `Φ = X tt + X ff` resp. `Φ = X tt * X ff`
we obtain families of polynomials `witt_add` resp. `witt_mul`
(with type `ℕ → MvPolynomial (Bool × ℕ) ℤ`) that will be used in later files to define the
addition and multiplication on the ring of Witt vectors.
## Outline of the proof
The proof of `wittStructureInt_existsUnique` is rather technical, and takes up most of this file.
We start by proving the analogous version for polynomials with rational coefficients,
instead of integer coefficients.
In this case, the solution is rather easy,
since the Witt polynomials form a faithful change of coordinates
in the polynomial ring `MvPolynomial ℕ ℚ`.
We therefore obtain a family of polynomials `wittStructureRat Φ`
for every `Φ : MvPolynomial idx ℚ`.
If `Φ` has integer coefficients, then the polynomials `wittStructureRat Φ n` do so as well.
Proving this claim is the essential core of this file, and culminates in
`map_wittStructureInt`, which proves that upon mapping the coefficients
of `wittStructureInt Φ n` from the integers to the rationals,
one obtains `wittStructureRat Φ n`.
Ultimately, the proof of `map_wittStructureInt` relies on
```
dvd_sub_pow_of_dvd_sub {R : Type*} [CommRing R] {p : ℕ} {a b : R} :
(p : R) ∣ a - b → ∀ (k : ℕ), (p : R) ^ (k + 1) ∣ a ^ p ^ k - b ^ p ^ k
```
## Main results
* `wittStructureRat Φ`: the family of polynomials `ℕ → MvPolynomial (idx × ℕ) ℚ`
associated with `Φ : MvPolynomial idx ℚ` and satisfying the property explained above.
* `wittStructureRat_prop`: the proof that `wittStructureRat` indeed satisfies the property.
* `wittStructureInt Φ`: the family of polynomials `ℕ → MvPolynomial (idx × ℕ) ℤ`
associated with `Φ : MvPolynomial idx ℤ` and satisfying the property explained above.
* `map_wittStructureInt`: the proof that the integral polynomials `with_structure_int Φ`
are equal to `wittStructureRat Φ` when mapped to polynomials with rational coefficients.
* `wittStructureInt_prop`: the proof that `wittStructureInt` indeed satisfies the property.
* Five families of polynomials that will be used to define the ring structure
on the ring of Witt vectors:
- `WittVector.wittZero`
- `WittVector.wittOne`
- `WittVector.wittAdd`
- `WittVector.wittMul`
- `WittVector.wittNeg`
(We also define `WittVector.wittSub`, and later we will prove that it describes subtraction,
which is defined as `fun a b ↦ a + -b`. See `WittVector.sub_coeff` for this proof.)
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
open MvPolynomial Set
open Finset (range)
open Finsupp (single)
-- This lemma reduces a bundled morphism to a "mere" function,
-- and consequently the simplifier cannot use a lot of powerful simp-lemmas.
-- We disable this locally, and probably it should be disabled globally in mathlib.
attribute [-simp] coe_eval₂Hom
variable {p : ℕ} {R : Type*} {idx : Type*} [CommRing R]
open scoped Witt
section PPrime
variable (p)
variable [hp : Fact p.Prime]
-- Notation with ring of coefficients explicit
set_option quotPrecheck false in
@[inherit_doc]
scoped[Witt] notation "W_" => wittPolynomial p
-- Notation with ring of coefficients implicit
set_option quotPrecheck false in
@[inherit_doc]
scoped[Witt] notation "W" => wittPolynomial p _
/-- `wittStructureRat Φ` is a family of polynomials `ℕ → MvPolynomial (idx × ℕ) ℚ`
that are uniquely characterised by the property that
```
bind₁ (wittStructureRat p Φ) (wittPolynomial p ℚ n) =
bind₁ (fun i ↦ (rename (prod.mk i) (wittPolynomial p ℚ n))) Φ
```
In other words: evaluating the `n`-th Witt polynomial on the family `wittStructureRat Φ`
is the same as evaluating `Φ` on the (appropriately renamed) `n`-th Witt polynomials.
See `wittStructureRat_prop` for this property,
and `wittStructureRat_existsUnique` for the fact that `wittStructureRat`
gives the unique family of polynomials with this property.
These polynomials turn out to have integral coefficients,
but it requires some effort to show this.
See `wittStructureInt` for the version with integral coefficients,
and `map_wittStructureInt` for the fact that it is equal to `wittStructureRat`
when mapped to polynomials over the rationals. -/
noncomputable def wittStructureRat (Φ : MvPolynomial idx ℚ) (n : ℕ) : MvPolynomial (idx × ℕ) ℚ :=
bind₁ (fun k => bind₁ (fun i => rename (Prod.mk i) (W_ ℚ k)) Φ) (xInTermsOfW p ℚ n)
theorem wittStructureRat_prop (Φ : MvPolynomial idx ℚ) (n : ℕ) :
bind₁ (wittStructureRat p Φ) (W_ ℚ n) = bind₁ (fun i => rename (Prod.mk i) (W_ ℚ n)) Φ :=
calc
bind₁ (wittStructureRat p Φ) (W_ ℚ n) =
bind₁ (fun k => bind₁ (fun i => (rename (Prod.mk i)) (W_ ℚ k)) Φ)
(bind₁ (xInTermsOfW p ℚ) (W_ ℚ n)) := by
rw [bind₁_bind₁]; exact eval₂Hom_congr (RingHom.ext_rat _ _) rfl rfl
_ = bind₁ (fun i => rename (Prod.mk i) (W_ ℚ n)) Φ := by
rw [bind₁_xInTermsOfW_wittPolynomial p _ n, bind₁_X_right]
theorem wittStructureRat_existsUnique (Φ : MvPolynomial idx ℚ) :
∃! φ : ℕ → MvPolynomial (idx × ℕ) ℚ,
∀ n : ℕ, bind₁ φ (W_ ℚ n) = bind₁ (fun i => rename (Prod.mk i) (W_ ℚ n)) Φ := by
refine ⟨wittStructureRat p Φ, ?_, ?_⟩
· intro n; apply wittStructureRat_prop
· intro φ H
funext n
rw [show φ n = bind₁ φ (bind₁ (W_ ℚ) (xInTermsOfW p ℚ n)) by
rw [bind₁_wittPolynomial_xInTermsOfW p, bind₁_X_right]]
rw [bind₁_bind₁]
exact eval₂Hom_congr (RingHom.ext_rat _ _) (funext H) rfl
theorem wittStructureRat_rec_aux (Φ : MvPolynomial idx ℚ) (n : ℕ) :
wittStructureRat p Φ n * C ((p : ℚ) ^ n) =
bind₁ (fun b => rename (fun i => (b, i)) (W_ ℚ n)) Φ -
∑ i ∈ range n, C ((p : ℚ) ^ i) * wittStructureRat p Φ i ^ p ^ (n - i) := by
have := xInTermsOfW_aux p ℚ n
replace := congr_arg (bind₁ fun k : ℕ => bind₁ (fun i => rename (Prod.mk i) (W_ ℚ k)) Φ) this
rw [map_mul, bind₁_C_right] at this
rw [wittStructureRat, this]; clear this
conv_lhs => simp only [map_sub, bind₁_X_right]
rw [sub_right_inj]
simp only [map_sum, map_mul, bind₁_C_right, map_pow]
rfl
/-- Write `wittStructureRat p φ n` in terms of `wittStructureRat p φ i` for `i < n`. -/
theorem wittStructureRat_rec (Φ : MvPolynomial idx ℚ) (n : ℕ) :
wittStructureRat p Φ n =
C (1 / (p : ℚ) ^ n) *
(bind₁ (fun b => rename (fun i => (b, i)) (W_ ℚ n)) Φ -
∑ i ∈ range n, C ((p : ℚ) ^ i) * wittStructureRat p Φ i ^ p ^ (n - i)) := by
calc
wittStructureRat p Φ n = C (1 / (p : ℚ) ^ n) * (wittStructureRat p Φ n * C ((p : ℚ) ^ n)) := ?_
_ = _ := by rw [wittStructureRat_rec_aux]
rw [mul_left_comm, ← C_mul, div_mul_cancel₀, C_1, mul_one]
exact pow_ne_zero _ (Nat.cast_ne_zero.2 hp.1.ne_zero)
/-- `wittStructureInt Φ` is a family of polynomials `ℕ → MvPolynomial (idx × ℕ) ℤ`
that are uniquely characterised by the property that
```
bind₁ (wittStructureInt p Φ) (wittPolynomial p ℤ n) =
bind₁ (fun i ↦ (rename (prod.mk i) (wittPolynomial p ℤ n))) Φ
```
In other words: evaluating the `n`-th Witt polynomial on the family `wittStructureInt Φ`
is the same as evaluating `Φ` on the (appropriately renamed) `n`-th Witt polynomials.
See `wittStructureInt_prop` for this property,
and `wittStructureInt_existsUnique` for the fact that `wittStructureInt`
gives the unique family of polynomials with this property. -/
noncomputable def wittStructureInt (Φ : MvPolynomial idx ℤ) (n : ℕ) : MvPolynomial (idx × ℕ) ℤ :=
Finsupp.mapRange Rat.num (Rat.num_intCast 0) (wittStructureRat p (map (Int.castRingHom ℚ) Φ) n)
variable {p}
theorem bind₁_rename_expand_wittPolynomial (Φ : MvPolynomial idx ℤ) (n : ℕ)
(IH :
∀ m : ℕ,
m < n + 1 →
map (Int.castRingHom ℚ) (wittStructureInt p Φ m) =
wittStructureRat p (map (Int.castRingHom ℚ) Φ) m) :
bind₁ (fun b => rename (fun i => (b, i)) (expand p (W_ ℤ n))) Φ =
bind₁ (fun i => expand p (wittStructureInt p Φ i)) (W_ ℤ n) := by
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
simp only [map_bind₁, map_rename, map_expand, rename_expand, map_wittPolynomial]
have key := (wittStructureRat_prop p (map (Int.castRingHom ℚ) Φ) n).symm
apply_fun expand p at key
simp only [expand_bind₁] at key
rw [key]; clear key
apply eval₂Hom_congr' rfl _ rfl
rintro i hi -
rw [wittPolynomial_vars, Finset.mem_range] at hi
simp only [IH i hi]
theorem C_p_pow_dvd_bind₁_rename_wittPolynomial_sub_sum (Φ : MvPolynomial idx ℤ) (n : ℕ)
(IH :
∀ m : ℕ,
m < n →
map (Int.castRingHom ℚ) (wittStructureInt p Φ m) =
wittStructureRat p (map (Int.castRingHom ℚ) Φ) m) :
(C ((p ^ n :) : ℤ) : MvPolynomial (idx × ℕ) ℤ) ∣
bind₁ (fun b : idx => rename (fun i => (b, i)) (wittPolynomial p ℤ n)) Φ -
∑ i ∈ range n, C ((p : ℤ) ^ i) * wittStructureInt p Φ i ^ p ^ (n - i) := by
cases' n with n
· simp only [isUnit_one, Int.ofNat_zero, Int.ofNat_succ, zero_add, pow_zero, C_1, IsUnit.dvd,
Nat.cast_one, Nat.zero_eq]
-- prepare a useful equation for rewriting
have key := bind₁_rename_expand_wittPolynomial Φ n IH
apply_fun map (Int.castRingHom (ZMod (p ^ (n + 1)))) at key
conv_lhs at key => simp only [map_bind₁, map_rename, map_expand, map_wittPolynomial]
-- clean up and massage
rw [C_dvd_iff_zmod, RingHom.map_sub, sub_eq_zero, map_bind₁]
simp only [map_rename, map_wittPolynomial, wittPolynomial_zmod_self]
rw [key]; clear key IH
rw [bind₁, aeval_wittPolynomial, map_sum, map_sum, Finset.sum_congr rfl]
intro k hk
rw [Finset.mem_range, Nat.lt_succ_iff] at hk
-- Porting note (#11083): was much slower
-- simp only [← sub_eq_zero, ← RingHom.map_sub, ← C_dvd_iff_zmod, C_eq_coe_nat, ← mul_sub, ←
-- Nat.cast_pow]
rw [← sub_eq_zero, ← RingHom.map_sub, ← C_dvd_iff_zmod, C_eq_coe_nat, ← Nat.cast_pow,
← Nat.cast_pow, C_eq_coe_nat, ← mul_sub]
have : p ^ (n + 1) = p ^ k * p ^ (n - k + 1) := by
rw [← pow_add, ← add_assoc]; congr 2; rw [add_comm, ← tsub_eq_iff_eq_add_of_le hk]
rw [this]
rw [Nat.cast_mul, Nat.cast_pow, Nat.cast_pow]
apply mul_dvd_mul_left ((p : MvPolynomial (idx × ℕ) ℤ) ^ k)
rw [show p ^ (n + 1 - k) = p * p ^ (n - k) by rw [← pow_succ', ← tsub_add_eq_add_tsub hk]]
rw [pow_mul]
-- the machine!
apply dvd_sub_pow_of_dvd_sub
rw [← C_eq_coe_nat, C_dvd_iff_zmod, RingHom.map_sub, sub_eq_zero, map_expand, RingHom.map_pow,
MvPolynomial.expand_zmod]
variable (p)
@[simp]
theorem map_wittStructureInt (Φ : MvPolynomial idx ℤ) (n : ℕ) :
map (Int.castRingHom ℚ) (wittStructureInt p Φ n) =
wittStructureRat p (map (Int.castRingHom ℚ) Φ) n := by
induction n using Nat.strong_induction_on with | h n IH => ?_
rw [wittStructureInt, map_mapRange_eq_iff, Int.coe_castRingHom]
intro c
rw [wittStructureRat_rec, coeff_C_mul, mul_comm, mul_div_assoc', mul_one]
have sum_induction_steps :
map (Int.castRingHom ℚ)
(∑ i ∈ range n, C ((p : ℤ) ^ i) * wittStructureInt p Φ i ^ p ^ (n - i)) =
∑ i ∈ range n,
C ((p : ℚ) ^ i) * wittStructureRat p (map (Int.castRingHom ℚ) Φ) i ^ p ^ (n - i) := by
rw [map_sum]
apply Finset.sum_congr rfl
intro i hi
rw [Finset.mem_range] at hi
simp only [IH i hi, RingHom.map_mul, RingHom.map_pow, map_C]
rfl
simp only [← sum_induction_steps, ← map_wittPolynomial p (Int.castRingHom ℚ), ← map_rename, ←
map_bind₁, ← RingHom.map_sub, coeff_map]
rw [show (p : ℚ) ^ n = ((↑(p ^ n) : ℤ) : ℚ) by norm_cast]
rw [← Rat.den_eq_one_iff, eq_intCast, Rat.den_div_intCast_eq_one_iff]
swap; · exact mod_cast pow_ne_zero n hp.1.ne_zero
revert c; rw [← C_dvd_iff_dvd_coeff]
exact C_p_pow_dvd_bind₁_rename_wittPolynomial_sub_sum Φ n IH
theorem wittStructureInt_prop (Φ : MvPolynomial idx ℤ) (n) :
bind₁ (wittStructureInt p Φ) (wittPolynomial p ℤ n) =
bind₁ (fun i => rename (Prod.mk i) (W_ ℤ n)) Φ := by
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
have := wittStructureRat_prop p (map (Int.castRingHom ℚ) Φ) n
simpa only [map_bind₁, ← eval₂Hom_map_hom, eval₂Hom_C_left, map_rename, map_wittPolynomial,
AlgHom.coe_toRingHom, map_wittStructureInt]
theorem eq_wittStructureInt (Φ : MvPolynomial idx ℤ) (φ : ℕ → MvPolynomial (idx × ℕ) ℤ)
(h : ∀ n, bind₁ φ (wittPolynomial p ℤ n) = bind₁ (fun i => rename (Prod.mk i) (W_ ℤ n)) Φ) :
φ = wittStructureInt p Φ := by
funext k
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
rw [map_wittStructureInt]
-- Porting note: was `refine' congr_fun _ k`
revert k
refine congr_fun ?_
apply ExistsUnique.unique (wittStructureRat_existsUnique p (map (Int.castRingHom ℚ) Φ))
· intro n
specialize h n
apply_fun map (Int.castRingHom ℚ) at h
simpa only [map_bind₁, ← eval₂Hom_map_hom, eval₂Hom_C_left, map_rename, map_wittPolynomial,
AlgHom.coe_toRingHom] using h
· intro n; apply wittStructureRat_prop
theorem wittStructureInt_existsUnique (Φ : MvPolynomial idx ℤ) :
∃! φ : ℕ → MvPolynomial (idx × ℕ) ℤ,
∀ n : ℕ,
bind₁ φ (wittPolynomial p ℤ n) = bind₁ (fun i : idx => rename (Prod.mk i) (W_ ℤ n)) Φ :=
⟨wittStructureInt p Φ, wittStructureInt_prop _ _, eq_wittStructureInt _ _⟩
theorem witt_structure_prop (Φ : MvPolynomial idx ℤ) (n) :
aeval (fun i => map (Int.castRingHom R) (wittStructureInt p Φ i)) (wittPolynomial p ℤ n) =
aeval (fun i => rename (Prod.mk i) (W n)) Φ := by
convert congr_arg (map (Int.castRingHom R)) (wittStructureInt_prop p Φ n) using 1 <;>
rw [hom_bind₁] <;>
apply eval₂Hom_congr (RingHom.ext_int _ _) _ rfl
· rfl
· simp only [map_rename, map_wittPolynomial]
theorem wittStructureInt_rename {σ : Type*} (Φ : MvPolynomial idx ℤ) (f : idx → σ) (n : ℕ) :
wittStructureInt p (rename f Φ) n = rename (Prod.map f id) (wittStructureInt p Φ n) := by
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective
simp only [map_rename, map_wittStructureInt, wittStructureRat, rename_bind₁, rename_rename,
bind₁_rename]
rfl
@[simp]
theorem constantCoeff_wittStructureRat_zero (Φ : MvPolynomial idx ℚ) :
constantCoeff (wittStructureRat p Φ 0) = constantCoeff Φ := by
simp only [wittStructureRat, bind₁, map_aeval, xInTermsOfW_zero, constantCoeff_rename,
constantCoeff_wittPolynomial, aeval_X, constantCoeff_comp_algebraMap, eval₂Hom_zero'_apply,
RingHom.id_apply]
theorem constantCoeff_wittStructureRat (Φ : MvPolynomial idx ℚ) (h : constantCoeff Φ = 0) (n : ℕ) :
constantCoeff (wittStructureRat p Φ n) = 0 := by
simp only [wittStructureRat, eval₂Hom_zero'_apply, h, bind₁, map_aeval, constantCoeff_rename,
constantCoeff_wittPolynomial, constantCoeff_comp_algebraMap, RingHom.id_apply,
constantCoeff_xInTermsOfW]
@[simp]
theorem constantCoeff_wittStructureInt_zero (Φ : MvPolynomial idx ℤ) :
constantCoeff (wittStructureInt p Φ 0) = constantCoeff Φ := by
have inj : Function.Injective (Int.castRingHom ℚ) := by intro m n; exact Int.cast_inj.mp
apply inj
rw [← constantCoeff_map, map_wittStructureInt, constantCoeff_wittStructureRat_zero,
constantCoeff_map]
theorem constantCoeff_wittStructureInt (Φ : MvPolynomial idx ℤ) (h : constantCoeff Φ = 0) (n : ℕ) :
constantCoeff (wittStructureInt p Φ n) = 0 := by
have inj : Function.Injective (Int.castRingHom ℚ) := by intro m n; exact Int.cast_inj.mp
apply inj
rw [← constantCoeff_map, map_wittStructureInt, constantCoeff_wittStructureRat, RingHom.map_zero]
rw [constantCoeff_map, h, RingHom.map_zero]
variable (R)
-- we could relax the fintype on `idx`, but then we need to cast from finset to set.
-- for our applications `idx` is always finite.
theorem wittStructureRat_vars [Fintype idx] (Φ : MvPolynomial idx ℚ) (n : ℕ) :
(wittStructureRat p Φ n).vars ⊆ Finset.univ ×ˢ Finset.range (n + 1) := by
rw [wittStructureRat]
intro x hx
simp only [Finset.mem_product, true_and_iff, Finset.mem_univ, Finset.mem_range]
obtain ⟨k, hk, hx'⟩ := mem_vars_bind₁ _ _ hx
obtain ⟨i, -, hx''⟩ := mem_vars_bind₁ _ _ hx'
obtain ⟨j, hj, rfl⟩ := mem_vars_rename _ _ hx''
rw [wittPolynomial_vars, Finset.mem_range] at hj
replace hk := xInTermsOfW_vars_subset p _ hk
rw [Finset.mem_range] at hk
exact lt_of_lt_of_le hj hk
-- we could relax the fintype on `idx`, but then we need to cast from finset to set.
-- for our applications `idx` is always finite.
theorem wittStructureInt_vars [Fintype idx] (Φ : MvPolynomial idx ℤ) (n : ℕ) :
(wittStructureInt p Φ n).vars ⊆ Finset.univ ×ˢ Finset.range (n + 1) := by
have : Function.Injective (Int.castRingHom ℚ) := Int.cast_injective
rw [← vars_map_of_injective _ this, map_wittStructureInt]
apply wittStructureRat_vars
end PPrime
|
RingTheory\WittVector\Teichmuller.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.RingTheory.WittVector.Basic
/-!
# Teichmüller lifts
This file defines `WittVector.teichmuller`, a monoid hom `R →* 𝕎 R`, which embeds `r : R` as the
`0`-th component of a Witt vector whose other coefficients are `0`.
## Main declarations
- `WittVector.teichmuller`: the Teichmuller map.
- `WittVector.map_teichmuller`: `WittVector.teichmuller` is a natural transformation.
- `WittVector.ghostComponent_teichmuller`:
the `n`-th ghost component of `WittVector.teichmuller p r` is `r ^ p ^ n`.
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
namespace WittVector
open MvPolynomial
variable (p : ℕ) {R S : Type*} [hp : Fact p.Prime] [CommRing R] [CommRing S]
local notation "𝕎" => WittVector p -- type as `\bbW`
/-- The underlying function of the monoid hom `WittVector.teichmuller`.
The `0`-th coefficient of `teichmullerFun p r` is `r`, and all others are `0`.
-/
def teichmullerFun (r : R) : 𝕎 R :=
⟨fun n => if n = 0 then r else 0⟩
/-!
## `teichmuller` is a monoid homomorphism
On ghost components, it is clear that `teichmullerFun` is a monoid homomorphism.
But in general the ghost map is not injective.
We follow the same strategy as for proving that the ring operations on `𝕎 R`
satisfy the ring axioms.
1. We first prove it for rings `R` where `p` is invertible,
because then the ghost map is in fact an isomorphism.
2. After that, we derive the result for `MvPolynomial R ℤ`,
3. and from that we can prove the result for arbitrary `R`.
-/
private theorem ghostComponent_teichmullerFun (r : R) (n : ℕ) :
ghostComponent n (teichmullerFun p r) = r ^ p ^ n := by
rw [ghostComponent_apply, aeval_wittPolynomial, Finset.sum_eq_single 0, pow_zero, one_mul,
tsub_zero]
· rfl
· intro i _ h0
simp [teichmullerFun, h0, hp.1.ne_zero]
· rw [Finset.mem_range]; intro h; exact (h (Nat.succ_pos n)).elim
private theorem map_teichmullerFun (f : R →+* S) (r : R) :
map f (teichmullerFun p r) = teichmullerFun p (f r) := by
ext n; cases n
· rfl
· exact f.map_zero
private theorem teichmuller_mul_aux₁ {R : Type*} (x y : MvPolynomial R ℚ) :
teichmullerFun p (x * y) = teichmullerFun p x * teichmullerFun p y := by
apply (ghostMap.bijective_of_invertible p (MvPolynomial R ℚ)).1
rw [RingHom.map_mul]
ext1 n
simp only [Pi.mul_apply, ghostMap_apply, ghostComponent_teichmullerFun, mul_pow]
private theorem teichmuller_mul_aux₂ {R : Type*} (x y : MvPolynomial R ℤ) :
teichmullerFun p (x * y) = teichmullerFun p x * teichmullerFun p y := by
refine map_injective (MvPolynomial.map (Int.castRingHom ℚ))
(MvPolynomial.map_injective _ Int.cast_injective) ?_
simp only [teichmuller_mul_aux₁, map_teichmullerFun, RingHom.map_mul]
/-- The Teichmüller lift of an element of `R` to `𝕎 R`.
The `0`-th coefficient of `teichmuller p r` is `r`, and all others are `0`.
This is a monoid homomorphism. -/
def teichmuller : R →* 𝕎 R where
toFun := teichmullerFun p
map_one' := by
ext ⟨⟩
· rw [one_coeff_zero]; rfl
· rw [one_coeff_eq_of_pos _ _ _ (Nat.succ_pos _)]; rfl
map_mul' := by
intro x y
rcases counit_surjective R x with ⟨x, rfl⟩
rcases counit_surjective R y with ⟨y, rfl⟩
simp only [← map_teichmullerFun, ← RingHom.map_mul, teichmuller_mul_aux₂]
@[simp]
theorem teichmuller_coeff_zero (r : R) : (teichmuller p r).coeff 0 = r :=
rfl
@[simp]
theorem teichmuller_coeff_pos (r : R) : ∀ (n : ℕ) (_ : 0 < n), (teichmuller p r).coeff n = 0
| _ + 1, _ => rfl
@[simp]
theorem teichmuller_zero : teichmuller p (0 : R) = 0 := by
ext ⟨⟩ <;> · rw [zero_coeff]; rfl
/-- `teichmuller` is a natural transformation. -/
@[simp]
theorem map_teichmuller (f : R →+* S) (r : R) : map f (teichmuller p r) = teichmuller p (f r) :=
map_teichmullerFun _ _ _
/-- The `n`-th ghost component of `teichmuller p r` is `r ^ p ^ n`. -/
@[simp]
theorem ghostComponent_teichmuller (r : R) (n : ℕ) :
ghostComponent n (teichmuller p r) = r ^ p ^ n :=
ghostComponent_teichmullerFun _ _ _
end WittVector
|
RingTheory\WittVector\Truncated.lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import Mathlib.RingTheory.WittVector.InitTail
/-!
# Truncated Witt vectors
The ring of truncated Witt vectors (of length `n`) is a quotient of the ring of Witt vectors.
It retains the first `n` coefficients of each Witt vector.
In this file, we set up the basic quotient API for this ring.
The ring of Witt vectors is the projective limit of all the rings of truncated Witt vectors.
## Main declarations
- `TruncatedWittVector`: the underlying type of the ring of truncated Witt vectors
- `TruncatedWittVector.instCommRing`: the ring structure on truncated Witt vectors
- `WittVector.truncate`: the quotient homomorphism that truncates a Witt vector,
to obtain a truncated Witt vector
- `TruncatedWittVector.truncate`: the homomorphism that truncates
a truncated Witt vector of length `n` to one of length `m` (for some `m ≤ n`)
- `WittVector.lift`: the unique ring homomorphism into the ring of Witt vectors
that is compatible with a family of ring homomorphisms to the truncated Witt vectors:
this realizes the ring of Witt vectors as projective limit of the rings of truncated Witt vectors
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
open Function (Injective Surjective)
noncomputable section
variable {p : ℕ} [hp : Fact p.Prime] (n : ℕ) (R : Type*)
local notation "𝕎" => WittVector p -- type as `\bbW`
/-- A truncated Witt vector over `R` is a vector of elements of `R`,
i.e., the first `n` coefficients of a Witt vector.
We will define operations on this type that are compatible with the (untruncated) Witt
vector operations.
`TruncatedWittVector p n R` takes a parameter `p : ℕ` that is not used in the definition.
In practice, this number `p` is assumed to be a prime number,
and under this assumption we construct a ring structure on `TruncatedWittVector p n R`.
(`TruncatedWittVector p₁ n R` and `TruncatedWittVector p₂ n R` are definitionally
equal as types but will have different ring operations.)
-/
@[nolint unusedArguments]
def TruncatedWittVector (_ : ℕ) (n : ℕ) (R : Type*) :=
Fin n → R
instance (p n : ℕ) (R : Type*) [Inhabited R] : Inhabited (TruncatedWittVector p n R) :=
⟨fun _ => default⟩
variable {n R}
namespace TruncatedWittVector
variable (p)
/-- Create a `TruncatedWittVector` from a vector `x`. -/
def mk (x : Fin n → R) : TruncatedWittVector p n R :=
x
variable {p}
/-- `x.coeff i` is the `i`th entry of `x`. -/
def coeff (i : Fin n) (x : TruncatedWittVector p n R) : R :=
x i
@[ext]
theorem ext {x y : TruncatedWittVector p n R} (h : ∀ i, x.coeff i = y.coeff i) : x = y :=
funext h
@[simp]
theorem coeff_mk (x : Fin n → R) (i : Fin n) : (mk p x).coeff i = x i :=
rfl
@[simp]
theorem mk_coeff (x : TruncatedWittVector p n R) : (mk p fun i => x.coeff i) = x := by
ext i; rw [coeff_mk]
variable [CommRing R]
/-- We can turn a truncated Witt vector `x` into a Witt vector
by setting all coefficients after `x` to be 0.
-/
def out (x : TruncatedWittVector p n R) : 𝕎 R :=
@WittVector.mk' p _ fun i => if h : i < n then x.coeff ⟨i, h⟩ else 0
@[simp]
theorem coeff_out (x : TruncatedWittVector p n R) (i : Fin n) : x.out.coeff i = x.coeff i := by
rw [out]; dsimp only; rw [dif_pos i.is_lt, Fin.eta]
theorem out_injective : Injective (@out p n R _) := by
intro x y h
ext i
rw [WittVector.ext_iff] at h
simpa only [coeff_out] using h ↑i
end TruncatedWittVector
namespace WittVector
variable (n)
section
/-- `truncateFun n x` uses the first `n` entries of `x` to construct a `TruncatedWittVector`,
which has the same base `p` as `x`.
This function is bundled into a ring homomorphism in `WittVector.truncate` -/
def truncateFun (x : 𝕎 R) : TruncatedWittVector p n R :=
TruncatedWittVector.mk p fun i => x.coeff i
end
variable {n}
@[simp]
theorem coeff_truncateFun (x : 𝕎 R) (i : Fin n) : (truncateFun n x).coeff i = x.coeff i := by
rw [truncateFun, TruncatedWittVector.coeff_mk]
variable [CommRing R]
@[simp]
theorem out_truncateFun (x : 𝕎 R) : (truncateFun n x).out = init n x := by
ext i
dsimp [TruncatedWittVector.out, init, select, coeff_mk]
split_ifs with hi; swap; · rfl
rw [coeff_truncateFun, Fin.val_mk]
end WittVector
namespace TruncatedWittVector
variable [CommRing R]
@[simp]
theorem truncateFun_out (x : TruncatedWittVector p n R) : x.out.truncateFun n = x := by
simp only [WittVector.truncateFun, coeff_out, mk_coeff]
open WittVector
variable (p n R)
instance : Zero (TruncatedWittVector p n R) :=
⟨truncateFun n 0⟩
instance : One (TruncatedWittVector p n R) :=
⟨truncateFun n 1⟩
instance : NatCast (TruncatedWittVector p n R) :=
⟨fun i => truncateFun n i⟩
instance : IntCast (TruncatedWittVector p n R) :=
⟨fun i => truncateFun n i⟩
instance : Add (TruncatedWittVector p n R) :=
⟨fun x y => truncateFun n (x.out + y.out)⟩
instance : Mul (TruncatedWittVector p n R) :=
⟨fun x y => truncateFun n (x.out * y.out)⟩
instance : Neg (TruncatedWittVector p n R) :=
⟨fun x => truncateFun n (-x.out)⟩
instance : Sub (TruncatedWittVector p n R) :=
⟨fun x y => truncateFun n (x.out - y.out)⟩
instance hasNatScalar : SMul ℕ (TruncatedWittVector p n R) :=
⟨fun m x => truncateFun n (m • x.out)⟩
instance hasIntScalar : SMul ℤ (TruncatedWittVector p n R) :=
⟨fun m x => truncateFun n (m • x.out)⟩
instance hasNatPow : Pow (TruncatedWittVector p n R) ℕ :=
⟨fun x m => truncateFun n (x.out ^ m)⟩
@[simp]
theorem coeff_zero (i : Fin n) : (0 : TruncatedWittVector p n R).coeff i = 0 := by
show coeff i (truncateFun _ 0 : TruncatedWittVector p n R) = 0
rw [coeff_truncateFun, WittVector.zero_coeff]
end TruncatedWittVector
/-- A macro tactic used to prove that `truncateFun` respects ring operations. -/
macro (name := witt_truncateFun_tac) "witt_truncateFun_tac" : tactic =>
`(tactic|
{ show _ = WittVector.truncateFun n _
apply TruncatedWittVector.out_injective
iterate rw [WittVector.out_truncateFun]
first
| rw [WittVector.init_add]
| rw [WittVector.init_mul]
| rw [WittVector.init_neg]
| rw [WittVector.init_sub]
| rw [WittVector.init_nsmul]
| rw [WittVector.init_zsmul]
| rw [WittVector.init_pow]})
namespace WittVector
variable (p n R)
variable [CommRing R]
theorem truncateFun_surjective : Surjective (@truncateFun p n R) :=
Function.RightInverse.surjective TruncatedWittVector.truncateFun_out
@[simp]
theorem truncateFun_zero : truncateFun n (0 : 𝕎 R) = 0 := rfl
@[simp]
theorem truncateFun_one : truncateFun n (1 : 𝕎 R) = 1 := rfl
variable {p R}
@[simp]
theorem truncateFun_add (x y : 𝕎 R) :
truncateFun n (x + y) = truncateFun n x + truncateFun n y := by
witt_truncateFun_tac
@[simp]
theorem truncateFun_mul (x y : 𝕎 R) :
truncateFun n (x * y) = truncateFun n x * truncateFun n y := by
witt_truncateFun_tac
theorem truncateFun_neg (x : 𝕎 R) : truncateFun n (-x) = -truncateFun n x := by
witt_truncateFun_tac
theorem truncateFun_sub (x y : 𝕎 R) :
truncateFun n (x - y) = truncateFun n x - truncateFun n y := by
witt_truncateFun_tac
theorem truncateFun_nsmul (m : ℕ) (x : 𝕎 R) : truncateFun n (m • x) = m • truncateFun n x := by
witt_truncateFun_tac
theorem truncateFun_zsmul (m : ℤ) (x : 𝕎 R) : truncateFun n (m • x) = m • truncateFun n x := by
witt_truncateFun_tac
theorem truncateFun_pow (x : 𝕎 R) (m : ℕ) : truncateFun n (x ^ m) = truncateFun n x ^ m := by
witt_truncateFun_tac
theorem truncateFun_natCast (m : ℕ) : truncateFun n (m : 𝕎 R) = m := rfl
@[deprecated (since := "2024-04-17")]
alias truncateFun_nat_cast := truncateFun_natCast
theorem truncateFun_intCast (m : ℤ) : truncateFun n (m : 𝕎 R) = m := rfl
@[deprecated (since := "2024-04-17")]
alias truncateFun_int_cast := truncateFun_intCast
end WittVector
namespace TruncatedWittVector
open WittVector
variable (p n R)
variable [CommRing R]
instance instCommRing : CommRing (TruncatedWittVector p n R) :=
(truncateFun_surjective p n R).commRing _ (truncateFun_zero p n R) (truncateFun_one p n R)
(truncateFun_add n) (truncateFun_mul n) (truncateFun_neg n) (truncateFun_sub n)
(truncateFun_nsmul n) (truncateFun_zsmul n) (truncateFun_pow n) (truncateFun_natCast n)
(truncateFun_intCast n)
end TruncatedWittVector
namespace WittVector
open TruncatedWittVector
variable (n)
variable [CommRing R]
/-- `truncate n` is a ring homomorphism that truncates `x` to its first `n` entries
to obtain a `TruncatedWittVector`, which has the same base `p` as `x`. -/
noncomputable def truncate : 𝕎 R →+* TruncatedWittVector p n R where
toFun := truncateFun n
map_zero' := truncateFun_zero p n R
map_add' := truncateFun_add n
map_one' := truncateFun_one p n R
map_mul' := truncateFun_mul n
variable (p R)
theorem truncate_surjective : Surjective (truncate n : 𝕎 R → TruncatedWittVector p n R) :=
truncateFun_surjective p n R
variable {p n R}
@[simp]
theorem coeff_truncate (x : 𝕎 R) (i : Fin n) : (truncate n x).coeff i = x.coeff i :=
coeff_truncateFun _ _
variable (n)
theorem mem_ker_truncate (x : 𝕎 R) :
x ∈ RingHom.ker (@truncate p _ n R _) ↔ ∀ i < n, x.coeff i = 0 := by
simp only [RingHom.mem_ker, truncate, truncateFun, RingHom.coe_mk, TruncatedWittVector.ext_iff,
TruncatedWittVector.coeff_mk, coeff_zero]
exact Fin.forall_iff
variable (p)
@[simp]
theorem truncate_mk' (f : ℕ → R) :
truncate n (@mk' p _ f) = TruncatedWittVector.mk _ fun k => f k := by
ext i
simp only [coeff_truncate, TruncatedWittVector.coeff_mk]
end WittVector
namespace TruncatedWittVector
variable [CommRing R]
/-- A ring homomorphism that truncates a truncated Witt vector of length `m` to
a truncated Witt vector of length `n`, for `n ≤ m`.
-/
def truncate {m : ℕ} (hm : n ≤ m) : TruncatedWittVector p m R →+* TruncatedWittVector p n R :=
RingHom.liftOfRightInverse (WittVector.truncate m) out truncateFun_out
⟨WittVector.truncate n, by
intro x
simp only [WittVector.mem_ker_truncate]
intro h i hi
exact h i (lt_of_lt_of_le hi hm)⟩
@[simp]
theorem truncate_comp_wittVector_truncate {m : ℕ} (hm : n ≤ m) :
(@truncate p _ n R _ m hm).comp (WittVector.truncate m) = WittVector.truncate n :=
RingHom.liftOfRightInverse_comp _ _ _ _
@[simp]
theorem truncate_wittVector_truncate {m : ℕ} (hm : n ≤ m) (x : 𝕎 R) :
truncate hm (WittVector.truncate m x) = WittVector.truncate n x :=
RingHom.liftOfRightInverse_comp_apply _ _ _ _ _
@[simp]
theorem truncate_truncate {n₁ n₂ n₃ : ℕ} (h1 : n₁ ≤ n₂) (h2 : n₂ ≤ n₃)
(x : TruncatedWittVector p n₃ R) :
(truncate h1) (truncate h2 x) = truncate (h1.trans h2) x := by
obtain ⟨x, rfl⟩ := @WittVector.truncate_surjective p _ n₃ R _ x
simp only [truncate_wittVector_truncate]
@[simp]
theorem truncate_comp {n₁ n₂ n₃ : ℕ} (h1 : n₁ ≤ n₂) (h2 : n₂ ≤ n₃) :
(@truncate p _ _ R _ _ h1).comp (truncate h2) = truncate (h1.trans h2) := by
ext1 x; simp only [truncate_truncate, Function.comp_apply, RingHom.coe_comp]
theorem truncate_surjective {m : ℕ} (hm : n ≤ m) : Surjective (@truncate p _ _ R _ _ hm) := by
intro x
obtain ⟨x, rfl⟩ := @WittVector.truncate_surjective p _ _ R _ x
exact ⟨WittVector.truncate _ x, truncate_wittVector_truncate _ _⟩
@[simp]
theorem coeff_truncate {m : ℕ} (hm : n ≤ m) (i : Fin n) (x : TruncatedWittVector p m R) :
(truncate hm x).coeff i = x.coeff (Fin.castLE hm i) := by
obtain ⟨y, rfl⟩ := @WittVector.truncate_surjective p _ _ _ _ x
simp only [truncate_wittVector_truncate, WittVector.coeff_truncate, Fin.coe_castLE]
section Fintype
instance {R : Type*} [Fintype R] : Fintype (TruncatedWittVector p n R) :=
Pi.fintype
variable (p n R)
theorem card {R : Type*} [Fintype R] :
Fintype.card (TruncatedWittVector p n R) = Fintype.card R ^ n := by
simp only [TruncatedWittVector, Fintype.card_fin, Fintype.card_fun]
end Fintype
theorem iInf_ker_truncate : ⨅ i : ℕ, RingHom.ker (@WittVector.truncate p _ i R _) = ⊥ := by
rw [Submodule.eq_bot_iff]
intro x hx
ext
simp only [WittVector.mem_ker_truncate, Ideal.mem_iInf, WittVector.zero_coeff] at hx ⊢
exact hx _ _ (Nat.lt_succ_self _)
end TruncatedWittVector
namespace WittVector
open TruncatedWittVector hiding truncate coeff
section lift
variable [CommRing R]
variable {S : Type*} [Semiring S]
variable (f : ∀ k : ℕ, S →+* TruncatedWittVector p k R)
variable
(f_compat : ∀ (k₁ k₂ : ℕ) (hk : k₁ ≤ k₂), (TruncatedWittVector.truncate hk).comp (f k₂) = f k₁)
variable (n)
/-- Given a family `fₖ : S → TruncatedWittVector p k R` and `s : S`, we produce a Witt vector by
defining the `k`th entry to be the final entry of `fₖ s`.
-/
def liftFun (s : S) : 𝕎 R :=
@WittVector.mk' p _ fun k => TruncatedWittVector.coeff (Fin.last k) (f (k + 1) s)
variable {f}
@[simp]
theorem truncate_liftFun (s : S) : WittVector.truncate n (liftFun f s) = f n s := by
ext i
simp only [liftFun, TruncatedWittVector.coeff_mk, WittVector.truncate_mk']
rw [← f_compat (i + 1) n i.is_lt, RingHom.comp_apply, TruncatedWittVector.coeff_truncate]
congr 1 with _
variable (f)
/--
Given compatible ring homs from `S` into `TruncatedWittVector n` for each `n`, we can lift these
to a ring hom `S → 𝕎 R`.
`lift` defines the universal property of `𝕎 R` as the inverse limit of `TruncatedWittVector n`.
-/
def lift : S →+* 𝕎 R := by
refine { toFun := liftFun f
map_zero' := ?_
map_one' := ?_
map_add' := ?_
map_mul' := ?_ } <;>
( intros
dsimp only
rw [← sub_eq_zero, ← Ideal.mem_bot, ← iInf_ker_truncate, Ideal.mem_iInf]
simp [RingHom.mem_ker, f_compat])
variable {f}
@[simp]
theorem truncate_lift (s : S) : WittVector.truncate n (lift _ f_compat s) = f n s :=
truncate_liftFun _ f_compat s
@[simp]
theorem truncate_comp_lift : (WittVector.truncate n).comp (lift _ f_compat) = f n := by
ext1; rw [RingHom.comp_apply, truncate_lift]
/-- The uniqueness part of the universal property of `𝕎 R`. -/
theorem lift_unique (g : S →+* 𝕎 R) (g_compat : ∀ k, (WittVector.truncate k).comp g = f k) :
lift _ f_compat = g := by
ext1 x
rw [← sub_eq_zero, ← Ideal.mem_bot, ← iInf_ker_truncate, Ideal.mem_iInf]
intro i
simp only [RingHom.mem_ker, g_compat, ← RingHom.comp_apply, truncate_comp_lift, RingHom.map_sub,
sub_self]
/-- The universal property of `𝕎 R` as projective limit of truncated Witt vector rings. -/
@[simps]
def liftEquiv : { f : ∀ k, S →+* TruncatedWittVector p k R // ∀ (k₁ k₂) (hk : k₁ ≤ k₂),
(TruncatedWittVector.truncate hk).comp (f k₂) = f k₁ } ≃ (S →+* 𝕎 R) where
toFun f := lift f.1 f.2
invFun g :=
⟨fun k => (truncate k).comp g, by
intro _ _ h
simp only [← RingHom.comp_assoc, truncate_comp_wittVector_truncate]⟩
left_inv := by rintro ⟨f, hf⟩; simp only [truncate_comp_lift]
right_inv g := lift_unique _ _ fun _ => rfl
theorem hom_ext (g₁ g₂ : S →+* 𝕎 R) (h : ∀ k, (truncate k).comp g₁ = (truncate k).comp g₂) :
g₁ = g₂ :=
liftEquiv.symm.injective <| Subtype.ext <| funext h
end lift
end WittVector
|
RingTheory\WittVector\Verschiebung.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.RingTheory.WittVector.Basic
import Mathlib.RingTheory.WittVector.IsPoly
/-!
## The Verschiebung operator
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
namespace WittVector
open MvPolynomial
variable {p : ℕ} {R S : Type*} [CommRing R] [CommRing S]
local notation "𝕎" => WittVector p -- type as `\bbW`
noncomputable section
/-- `verschiebungFun x` shifts the coefficients of `x` up by one,
by inserting 0 as the 0th coefficient.
`x.coeff i` then becomes `(verchiebungFun x).coeff (i + 1)`.
`verschiebungFun` is the underlying function of the additive monoid hom `WittVector.verschiebung`.
-/
def verschiebungFun (x : 𝕎 R) : 𝕎 R :=
@mk' p _ fun n => if n = 0 then 0 else x.coeff (n - 1)
theorem verschiebungFun_coeff (x : 𝕎 R) (n : ℕ) :
(verschiebungFun x).coeff n = if n = 0 then 0 else x.coeff (n - 1) := by
simp only [verschiebungFun]
theorem verschiebungFun_coeff_zero (x : 𝕎 R) : (verschiebungFun x).coeff 0 = 0 := by
rw [verschiebungFun_coeff, if_pos rfl]
@[simp]
theorem verschiebungFun_coeff_succ (x : 𝕎 R) (n : ℕ) :
(verschiebungFun x).coeff n.succ = x.coeff n :=
rfl
@[ghost_simps]
theorem ghostComponent_zero_verschiebungFun [hp : Fact p.Prime] (x : 𝕎 R) :
ghostComponent 0 (verschiebungFun x) = 0 := by
rw [ghostComponent_apply, aeval_wittPolynomial, Finset.range_one, Finset.sum_singleton,
verschiebungFun_coeff_zero, pow_zero, pow_zero, pow_one, one_mul]
@[ghost_simps]
theorem ghostComponent_verschiebungFun [hp : Fact p.Prime] (x : 𝕎 R) (n : ℕ) :
ghostComponent (n + 1) (verschiebungFun x) = p * ghostComponent n x := by
simp only [ghostComponent_apply, aeval_wittPolynomial]
rw [Finset.sum_range_succ', verschiebungFun_coeff, if_pos rfl,
zero_pow (pow_ne_zero _ hp.1.ne_zero), mul_zero, add_zero, Finset.mul_sum, Finset.sum_congr rfl]
rintro i -
simp only [pow_succ', verschiebungFun_coeff_succ, Nat.succ_sub_succ_eq_sub, mul_assoc]
/-- The 0th Verschiebung polynomial is 0. For `n > 0`, the `n`th Verschiebung polynomial is the
variable `X (n-1)`.
-/
def verschiebungPoly (n : ℕ) : MvPolynomial ℕ ℤ :=
if n = 0 then 0 else X (n - 1)
@[simp]
theorem verschiebungPoly_zero : verschiebungPoly 0 = 0 :=
rfl
theorem aeval_verschiebung_poly' (x : 𝕎 R) (n : ℕ) :
aeval x.coeff (verschiebungPoly n) = (verschiebungFun x).coeff n := by
cases' n with n
· simp only [verschiebungPoly, ite_true, map_zero, verschiebungFun_coeff_zero]
· rw [verschiebungPoly, verschiebungFun_coeff_succ, if_neg n.succ_ne_zero, aeval_X,
add_tsub_cancel_right]
variable (p)
/-- `WittVector.verschiebung` has polynomial structure given by `WittVector.verschiebungPoly`.
-/
-- Porting note: replaced `@[is_poly]` with `instance`.
instance verschiebungFun_isPoly : IsPoly p fun R _Rcr => @verschiebungFun p R _Rcr := by
use verschiebungPoly
simp only [aeval_verschiebung_poly', eq_self_iff_true, forall₃_true_iff]
-- Porting note: we add this example as a verification that Lean 4's instance resolution
-- can handle what in Lean 3 we needed the `@[is_poly]` attribute to help with.
example (p : ℕ) (f : ⦃R : Type _⦄ → [CommRing R] → WittVector p R → WittVector p R) [IsPoly p f] :
IsPoly p (fun (R : Type*) (I : CommRing R) ↦ verschiebungFun ∘ (@f R I)) :=
inferInstance
variable {p}
variable [hp : Fact p.Prime]
/--
`verschiebung x` shifts the coefficients of `x` up by one, by inserting 0 as the 0th coefficient.
`x.coeff i` then becomes `(verchiebung x).coeff (i + 1)`.
This is an additive monoid hom with underlying function `verschiebung_fun`.
-/
noncomputable def verschiebung : 𝕎 R →+ 𝕎 R where
toFun := verschiebungFun
map_zero' := by
ext ⟨⟩ <;> rw [verschiebungFun_coeff] <;>
simp only [if_true, eq_self_iff_true, zero_coeff, ite_self]
map_add' := by
dsimp
ghost_calc _ _
rintro ⟨⟩ <;> -- Uses the dumb induction principle, hence adding `Nat.zero_eq` to ghost_simps.
ghost_simp
/-- `WittVector.verschiebung` is a polynomial function. -/
@[is_poly]
theorem verschiebung_isPoly : IsPoly p fun _ _ => verschiebung (p := p) :=
verschiebungFun_isPoly p
/-- verschiebung is a natural transformation -/
@[simp]
theorem map_verschiebung (f : R →+* S) (x : 𝕎 R) :
map f (verschiebung x) = verschiebung (map f x) := by
ext ⟨-, -⟩
· exact f.map_zero
· rfl
@[ghost_simps]
theorem ghostComponent_zero_verschiebung (x : 𝕎 R) : ghostComponent 0 (verschiebung x) = 0 :=
ghostComponent_zero_verschiebungFun _
@[ghost_simps]
theorem ghostComponent_verschiebung (x : 𝕎 R) (n : ℕ) :
ghostComponent (n + 1) (verschiebung x) = p * ghostComponent n x :=
ghostComponent_verschiebungFun _ _
@[simp]
theorem verschiebung_coeff_zero (x : 𝕎 R) : (verschiebung x).coeff 0 = 0 :=
rfl
-- simp_nf complains if this is simp
theorem verschiebung_coeff_add_one (x : 𝕎 R) (n : ℕ) :
(verschiebung x).coeff (n + 1) = x.coeff n :=
rfl
@[simp]
theorem verschiebung_coeff_succ (x : 𝕎 R) (n : ℕ) : (verschiebung x).coeff n.succ = x.coeff n :=
rfl
theorem aeval_verschiebungPoly (x : 𝕎 R) (n : ℕ) :
aeval x.coeff (verschiebungPoly n) = (verschiebung x).coeff n :=
aeval_verschiebung_poly' x n
@[simp]
theorem bind₁_verschiebungPoly_wittPolynomial (n : ℕ) :
bind₁ verschiebungPoly (wittPolynomial p ℤ n) =
if n = 0 then 0 else p * wittPolynomial p ℤ (n - 1) := by
apply MvPolynomial.funext
intro x
split_ifs with hn
· simp only [hn, wittPolynomial_zero, bind₁_X_right, verschiebungPoly_zero, map_zero, ite_true]
· obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hn
rw [Nat.succ_eq_add_one, add_tsub_cancel_right]
simp only [add_eq_zero, and_false, ite_false, map_mul]
rw [map_natCast, hom_bind₁]
calc
_ = ghostComponent (n + 1) (verschiebung <| mk p x) := by
apply eval₂Hom_congr (RingHom.ext_int _ _) _ rfl
funext k
simp only [← aeval_verschiebungPoly]
exact eval₂Hom_congr (RingHom.ext_int _ _) rfl rfl
_ = _ := by rw [ghostComponent_verschiebung]; rfl
end
end WittVector
|
RingTheory\WittVector\WittPolynomial.lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import Mathlib.Algebra.CharP.Invertible
import Mathlib.Algebra.MvPolynomial.Variables
import Mathlib.Algebra.MvPolynomial.CommRing
import Mathlib.Algebra.MvPolynomial.Expand
import Mathlib.Data.Fintype.BigOperators
import Mathlib.Data.ZMod.Basic
/-!
# Witt polynomials
To endow `WittVector p R` with a ring structure,
we need to study the so-called Witt polynomials.
Fix a base value `p : ℕ`.
The `p`-adic Witt polynomials are an infinite family of polynomials
indexed by a natural number `n`, taking values in an arbitrary ring `R`.
The variables of these polynomials are represented by natural numbers.
The variable set of the `n`th Witt polynomial contains at most `n+1` elements `{0, ..., n}`,
with exactly these variables when `R` has characteristic `0`.
These polynomials are used to define the addition and multiplication operators
on the type of Witt vectors. (While this type itself is not complicated,
the ring operations are what make it interesting.)
When the base `p` is invertible in `R`, the `p`-adic Witt polynomials
form a basis for `MvPolynomial ℕ R`, equivalent to the standard basis.
## Main declarations
* `WittPolynomial p R n`: the `n`-th Witt polynomial, viewed as polynomial over the ring `R`
* `xInTermsOfW p R n`: if `p` is invertible, the polynomial `X n` is contained in the subalgebra
generated by the Witt polynomials. `xInTermsOfW p R n` is the explicit polynomial,
which upon being bound to the Witt polynomials yields `X n`.
* `bind₁_wittPolynomial_xInTermsOfW`: the proof of the claim that
`bind₁ (xInTermsOfW p R) (W_ R n) = X n`
* `bind₁_xInTermsOfW_wittPolynomial`: the converse of the above statement
## Notation
In this file we use the following notation
* `p` is a natural number, typically assumed to be prime.
* `R` and `S` are commutative rings
* `W n` (and `W_ R n` when the ring needs to be explicit) denotes the `n`th Witt polynomial
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
open MvPolynomial
open Finset hiding map
open Finsupp (single)
--attribute [-simp] coe_eval₂_hom
variable (p : ℕ)
variable (R : Type*) [CommRing R]
/-- `wittPolynomial p R n` is the `n`-th Witt polynomial
with respect to a prime `p` with coefficients in a commutative ring `R`.
It is defined as:
`∑_{i ≤ n} p^i X_i^{p^{n-i}} ∈ R[X_0, X_1, X_2, …]`. -/
noncomputable def wittPolynomial (n : ℕ) : MvPolynomial ℕ R :=
∑ i ∈ range (n + 1), monomial (single i (p ^ (n - i))) ((p : R) ^ i)
theorem wittPolynomial_eq_sum_C_mul_X_pow (n : ℕ) :
wittPolynomial p R n = ∑ i ∈ range (n + 1), C ((p : R) ^ i) * X i ^ p ^ (n - i) := by
apply sum_congr rfl
rintro i -
rw [monomial_eq, Finsupp.prod_single_index]
rw [pow_zero]
/-! We set up notation locally to this file, to keep statements short and comprehensible.
This allows us to simply write `W n` or `W_ ℤ n`. -/
-- Notation with ring of coefficients explicit
set_option quotPrecheck false in
@[inherit_doc]
scoped[Witt] notation "W_" => wittPolynomial p
-- Notation with ring of coefficients implicit
set_option quotPrecheck false in
@[inherit_doc]
scoped[Witt] notation "W" => wittPolynomial p _
open Witt
open MvPolynomial
/-! The first observation is that the Witt polynomial doesn't really depend on the coefficient ring.
If we map the coefficients through a ring homomorphism, we obtain the corresponding Witt polynomial
over the target ring. -/
section
variable {R} {S : Type*} [CommRing S]
@[simp]
theorem map_wittPolynomial (f : R →+* S) (n : ℕ) : map f (W n) = W n := by
rw [wittPolynomial, map_sum, wittPolynomial]
refine sum_congr rfl fun i _ => ?_
rw [map_monomial, RingHom.map_pow, map_natCast]
variable (R)
@[simp]
theorem constantCoeff_wittPolynomial [hp : Fact p.Prime] (n : ℕ) :
constantCoeff (wittPolynomial p R n) = 0 := by
simp only [wittPolynomial, map_sum, constantCoeff_monomial]
rw [sum_eq_zero]
rintro i _
rw [if_neg]
rw [Finsupp.single_eq_zero]
exact ne_of_gt (pow_pos hp.1.pos _)
@[simp]
theorem wittPolynomial_zero : wittPolynomial p R 0 = X 0 := by
simp only [wittPolynomial, X, sum_singleton, range_one, pow_zero, zero_add, tsub_self]
@[simp]
theorem wittPolynomial_one : wittPolynomial p R 1 = C (p : R) * X 1 + X 0 ^ p := by
simp only [wittPolynomial_eq_sum_C_mul_X_pow, sum_range_succ_comm, range_one, sum_singleton,
one_mul, pow_one, C_1, pow_zero, tsub_self, tsub_zero]
theorem aeval_wittPolynomial {A : Type*} [CommRing A] [Algebra R A] (f : ℕ → A) (n : ℕ) :
aeval f (W_ R n) = ∑ i ∈ range (n + 1), (p : A) ^ i * f i ^ p ^ (n - i) := by
simp [wittPolynomial, map_sum, aeval_monomial, Finsupp.prod_single_index]
/-- Over the ring `ZMod (p^(n+1))`, we produce the `n+1`st Witt polynomial
by expanding the `n`th Witt polynomial by `p`. -/
@[simp]
theorem wittPolynomial_zmod_self (n : ℕ) :
W_ (ZMod (p ^ (n + 1))) (n + 1) = expand p (W_ (ZMod (p ^ (n + 1))) n) := by
simp only [wittPolynomial_eq_sum_C_mul_X_pow]
rw [sum_range_succ, ← Nat.cast_pow, CharP.cast_eq_zero (ZMod (p ^ (n + 1))) (p ^ (n + 1)), C_0,
zero_mul, add_zero, map_sum, sum_congr rfl]
intro k hk
rw [map_mul (expand p), map_pow (expand p), expand_X, algHom_C, ← pow_mul, ← pow_succ']
congr
rw [mem_range] at hk
rw [add_comm, add_tsub_assoc_of_le (Nat.lt_succ_iff.mp hk), ← add_comm]
section PPrime
variable [hp : NeZero p]
theorem wittPolynomial_vars [CharZero R] (n : ℕ) : (wittPolynomial p R n).vars = range (n + 1) := by
have : ∀ i, (monomial (Finsupp.single i (p ^ (n - i))) ((p : R) ^ i)).vars = {i} := by
intro i
refine vars_monomial_single i (pow_ne_zero _ hp.1) ?_
rw [← Nat.cast_pow, Nat.cast_ne_zero]
exact pow_ne_zero i hp.1
rw [wittPolynomial, vars_sum_of_disjoint]
· simp only [this, biUnion_singleton_eq_self]
· simp only [this]
intro a b h
apply disjoint_singleton_left.mpr
rwa [mem_singleton]
theorem wittPolynomial_vars_subset (n : ℕ) : (wittPolynomial p R n).vars ⊆ range (n + 1) := by
rw [← map_wittPolynomial p (Int.castRingHom R), ← wittPolynomial_vars p ℤ]
apply vars_map
end PPrime
end
/-!
## Witt polynomials as a basis of the polynomial algebra
If `p` is invertible in `R`, then the Witt polynomials form a basis
of the polynomial algebra `MvPolynomial ℕ R`.
The polynomials `xInTermsOfW` give the coordinate transformation in the backwards direction.
-/
/-- The `xInTermsOfW p R n` is the polynomial on the basis of Witt polynomials
that corresponds to the ordinary `X n`. -/
noncomputable def xInTermsOfW [Invertible (p : R)] : ℕ → MvPolynomial ℕ R
| n => (X n - ∑ i : Fin n,
C ((p : R) ^ (i : ℕ)) * xInTermsOfW i ^ p ^ (n - (i : ℕ))) * C ((⅟ p : R) ^ n)
theorem xInTermsOfW_eq [Invertible (p : R)] {n : ℕ} : xInTermsOfW p R n =
(X n - ∑ i ∈ range n, C ((p : R) ^ i) *
xInTermsOfW p R i ^ p ^ (n - i)) * C ((⅟p : R) ^ n) := by
rw [xInTermsOfW, ← Fin.sum_univ_eq_sum_range]
@[simp]
theorem constantCoeff_xInTermsOfW [hp : Fact p.Prime] [Invertible (p : R)] (n : ℕ) :
constantCoeff (xInTermsOfW p R n) = 0 := by
apply Nat.strongInductionOn n; clear n
intro n IH
rw [xInTermsOfW_eq, mul_comm, RingHom.map_mul, RingHom.map_sub, map_sum, constantCoeff_C,
constantCoeff_X, zero_sub, mul_neg, neg_eq_zero]
-- Porting note: here, we should be able to do `rw [sum_eq_zero]`, but the goal that
-- is created is not what we expect, and the sum is not replaced by zero...
-- is it a bug in `rw` tactic?
refine Eq.trans (?_ : _ = ((⅟↑p : R) ^ n)* 0) (mul_zero _)
congr 1
rw [sum_eq_zero]
intro m H
rw [mem_range] at H
simp only [RingHom.map_mul, RingHom.map_pow, map_natCast, IH m H]
rw [zero_pow, mul_zero]
exact pow_ne_zero _ hp.1.ne_zero
@[simp]
theorem xInTermsOfW_zero [Invertible (p : R)] : xInTermsOfW p R 0 = X 0 := by
rw [xInTermsOfW_eq, range_zero, sum_empty, pow_zero, C_1, mul_one, sub_zero]
section PPrime
variable [hp : Fact p.Prime]
theorem xInTermsOfW_vars_aux (n : ℕ) :
n ∈ (xInTermsOfW p ℚ n).vars ∧ (xInTermsOfW p ℚ n).vars ⊆ range (n + 1) := by
apply Nat.strongInductionOn n; clear n
intro n ih
rw [xInTermsOfW_eq, mul_comm, vars_C_mul _ (nonzero_of_invertible _),
vars_sub_of_disjoint, vars_X, range_succ, insert_eq]
on_goal 1 =>
simp only [true_and_iff, true_or_iff, eq_self_iff_true, mem_union, mem_singleton]
intro i
rw [mem_union, mem_union]
apply Or.imp id
on_goal 2 => rw [vars_X, disjoint_singleton_left]
all_goals
intro H
replace H := vars_sum_subset _ _ H
rw [mem_biUnion] at H
rcases H with ⟨j, hj, H⟩
rw [vars_C_mul] at H
swap
· apply pow_ne_zero
exact mod_cast hp.1.ne_zero
rw [mem_range] at hj
replace H := (ih j hj).2 (vars_pow _ _ H)
rw [mem_range] at H
· rw [mem_range]
omega
· omega
theorem xInTermsOfW_vars_subset (n : ℕ) : (xInTermsOfW p ℚ n).vars ⊆ range (n + 1) :=
(xInTermsOfW_vars_aux p n).2
end PPrime
theorem xInTermsOfW_aux [Invertible (p : R)] (n : ℕ) :
xInTermsOfW p R n * C ((p : R) ^ n) =
X n - ∑ i ∈ range n, C ((p : R) ^ i) * xInTermsOfW p R i ^ p ^ (n - i) := by
rw [xInTermsOfW_eq, mul_assoc, ← C_mul, ← mul_pow, invOf_mul_self,
one_pow, C_1, mul_one]
@[simp]
theorem bind₁_xInTermsOfW_wittPolynomial [Invertible (p : R)] (k : ℕ) :
bind₁ (xInTermsOfW p R) (W_ R k) = X k := by
rw [wittPolynomial_eq_sum_C_mul_X_pow, map_sum]
simp only [Nat.cast_pow, map_pow, C_pow, map_mul, algHom_C, algebraMap_eq]
rw [sum_range_succ_comm, tsub_self, pow_zero, pow_one, bind₁_X_right, mul_comm, ← C_pow,
xInTermsOfW_aux]
simp only [Nat.cast_pow, C_pow, bind₁_X_right, sub_add_cancel]
@[simp]
theorem bind₁_wittPolynomial_xInTermsOfW [Invertible (p : R)] (n : ℕ) :
bind₁ (W_ R) (xInTermsOfW p R n) = X n := by
apply Nat.strongInductionOn n
clear n
intro n H
rw [xInTermsOfW_eq, map_mul, map_sub, bind₁_X_right, algHom_C, map_sum,
show X n = (X n * C ((p : R) ^ n)) * C ((⅟p : R) ^ n) by
rw [mul_assoc, ← C_mul, ← mul_pow, mul_invOf_self, one_pow, map_one, mul_one]]
congr 1
rw [wittPolynomial_eq_sum_C_mul_X_pow, sum_range_succ_comm,
tsub_self, pow_zero, pow_one, mul_comm (X n), add_sub_assoc, add_right_eq_self, sub_eq_zero]
apply sum_congr rfl
intro i h
rw [mem_range] at h
rw [map_mul, map_pow (bind₁ _), algHom_C, H i h, algebraMap_eq]
|
SetTheory\Lists.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.Sigma.Basic
import Mathlib.Algebra.Order.Ring.Nat
/-!
# A computable model of ZFA without infinity
In this file we define finite hereditary lists. This is useful for calculations in naive set theory.
We distinguish two kinds of ZFA lists:
* Atoms. Directly correspond to an element of the original type.
* Proper ZFA lists. Can be thought of (but aren't implemented) as a list of ZFA lists (not
necessarily proper).
For example, `Lists ℕ` contains stuff like `23`, `[]`, `[37]`, `[1, [[2], 3], 4]`.
## Implementation note
As we want to be able to append both atoms and proper ZFA lists to proper ZFA lists, it's handy that
atoms and proper ZFA lists belong to the same type, even though atoms of `α` could be modelled as
`α` directly. But we don't want to be able to append anything to atoms.
This calls for a two-steps definition of ZFA lists:
* First, define ZFA prelists as atoms and proper ZFA prelists. Those proper ZFA prelists are defined
by inductive appending of (not necessarily proper) ZFA lists.
* Second, define ZFA lists by rubbing out the distinction between atoms and proper lists.
## Main declarations
* `Lists' α false`: Atoms as ZFA prelists. Basically a copy of `α`.
* `Lists' α true`: Proper ZFA prelists. Defined inductively from the empty ZFA prelist
(`Lists'.nil`) and from appending a ZFA prelist to a proper ZFA prelist (`Lists'.cons a l`).
* `Lists α`: ZFA lists. Sum of the atoms and proper ZFA prelists.
* `Finsets α`: ZFA sets. Defined as `Lists` quotiented by `Lists.Equiv`, the extensional
equivalence.
-/
variable {α : Type*}
/-- Prelists, helper type to define `Lists`. `Lists' α false` are the "atoms", a copy of `α`.
`Lists' α true` are the "proper" ZFA prelists, inductively defined from the empty ZFA prelist and
from appending a ZFA prelist to a proper ZFA prelist. It is made so that you can't append anything
to an atom while having only one appending function for appending both atoms and proper ZFC prelists
to a proper ZFA prelist. -/
inductive Lists'.{u} (α : Type u) : Bool → Type u
| atom : α → Lists' α false
| nil : Lists' α true
| cons' {b} : Lists' α b → Lists' α true → Lists' α true
deriving DecidableEq
compile_inductive% Lists'
/-- Hereditarily finite list, aka ZFA list. A ZFA list is either an "atom" (`b = false`),
corresponding to an element of `α`, or a "proper" ZFA list, inductively defined from the empty ZFA
list and from appending a ZFA list to a proper ZFA list. -/
def Lists (α : Type*) :=
Σb, Lists' α b
namespace Lists'
instance [Inhabited α] : ∀ b, Inhabited (Lists' α b)
| true => ⟨nil⟩
| false => ⟨atom default⟩
/-- Appending a ZFA list to a proper ZFA prelist. -/
def cons : Lists α → Lists' α true → Lists' α true
| ⟨_, a⟩, l => cons' a l
/-- Converts a ZFA prelist to a `List` of ZFA lists. Atoms are sent to `[]`. -/
@[simp]
def toList : ∀ {b}, Lists' α b → List (Lists α)
| _, atom _ => []
| _, nil => []
| _, cons' a l => ⟨_, a⟩ :: l.toList
@[simp]
theorem toList_cons (a : Lists α) (l) : toList (cons a l) = a :: l.toList := rfl
/-- Converts a `List` of ZFA lists to a proper ZFA prelist. -/
@[simp]
def ofList : List (Lists α) → Lists' α true
| [] => nil
| a :: l => cons a (ofList l)
@[simp]
theorem to_ofList (l : List (Lists α)) : toList (ofList l) = l := by induction l <;> simp [*]
@[simp]
theorem of_toList : ∀ l : Lists' α true, ofList (toList l) = l :=
suffices
∀ (b) (h : true = b) (l : Lists' α b),
let l' : Lists' α true := by rw [h]; exact l
ofList (toList l') = l'
from this _ rfl
fun b h l => by
induction l with
| atom => cases h
| nil => simp
| cons' b a _ IH => simpa [cons] using IH rfl
end Lists'
mutual
/-- Equivalence of ZFA lists. Defined inductively. -/
inductive Lists.Equiv : Lists α → Lists α → Prop
| refl (l) : Lists.Equiv l l
| antisymm {l₁ l₂ : Lists' α true} :
Lists'.Subset l₁ l₂ → Lists'.Subset l₂ l₁ → Lists.Equiv ⟨_, l₁⟩ ⟨_, l₂⟩
/-- Subset relation for ZFA lists. Defined inductively. -/
inductive Lists'.Subset : Lists' α true → Lists' α true → Prop
| nil {l} : Lists'.Subset Lists'.nil l
| cons {a a' l l'} :
Lists.Equiv a a' →
a' ∈ Lists'.toList l' → Lists'.Subset l l' → Lists'.Subset (Lists'.cons a l) l'
end
local infixl:50 " ~ " => Lists.Equiv
namespace Lists'
instance : HasSubset (Lists' α true) :=
⟨Lists'.Subset⟩
/-- ZFA prelist membership. A ZFA list is in a ZFA prelist if some element of this ZFA prelist is
equivalent as a ZFA list to this ZFA list. -/
instance {b} : Membership (Lists α) (Lists' α b) :=
⟨fun a l => ∃ a' ∈ l.toList, a ~ a'⟩
theorem mem_def {b a} {l : Lists' α b} : a ∈ l ↔ ∃ a' ∈ l.toList, a ~ a' :=
Iff.rfl
@[simp]
theorem mem_cons {a y l} : a ∈ @cons α y l ↔ a ~ y ∨ a ∈ l := by
simp [mem_def, or_and_right, exists_or]
theorem cons_subset {a} {l₁ l₂ : Lists' α true} : Lists'.cons a l₁ ⊆ l₂ ↔ a ∈ l₂ ∧ l₁ ⊆ l₂ := by
refine ⟨fun h => ?_, fun ⟨⟨a', m, e⟩, s⟩ => Subset.cons e m s⟩
generalize h' : Lists'.cons a l₁ = l₁' at h
cases' h with l a' a'' l l' e m s
· cases a
cases h'
cases a; cases a'; cases h'; exact ⟨⟨_, m, e⟩, s⟩
theorem ofList_subset {l₁ l₂ : List (Lists α)} (h : l₁ ⊆ l₂) :
Lists'.ofList l₁ ⊆ Lists'.ofList l₂ := by
induction' l₁ with _ _ l₁_ih; · exact Subset.nil
refine Subset.cons (Lists.Equiv.refl _) ?_ (l₁_ih (List.subset_of_cons_subset h))
simp only [List.cons_subset] at h; simp [h]
@[refl]
theorem Subset.refl {l : Lists' α true} : l ⊆ l := by
rw [← Lists'.of_toList l]; exact ofList_subset (List.Subset.refl _)
theorem subset_nil {l : Lists' α true} : l ⊆ Lists'.nil → l = Lists'.nil := by
rw [← of_toList l]
induction toList l <;> intro h
· rfl
· rcases cons_subset.1 h with ⟨⟨_, ⟨⟩, _⟩, _⟩
theorem mem_of_subset' {a} : ∀ {l₁ l₂ : Lists' α true} (_ : l₁ ⊆ l₂) (_ : a ∈ l₁.toList), a ∈ l₂
| nil, _, Lists'.Subset.nil, h => by cases h
| cons' a0 l0, l₂, s, h => by
cases' s with _ _ _ _ _ e m s
simp only [toList, Sigma.eta, List.find?, List.mem_cons] at h
rcases h with (rfl | h)
· exact ⟨_, m, e⟩
· exact mem_of_subset' s h
theorem subset_def {l₁ l₂ : Lists' α true} : l₁ ⊆ l₂ ↔ ∀ a ∈ l₁.toList, a ∈ l₂ :=
⟨fun H a => mem_of_subset' H, fun H => by
rw [← of_toList l₁]
revert H; induction' toList l₁ with h t t_ih <;> intro H
· exact Subset.nil
· simp only [ofList, List.find?, List.mem_cons, forall_eq_or_imp] at *
exact cons_subset.2 ⟨H.1, t_ih H.2⟩⟩
end Lists'
namespace Lists
/-- Sends `a : α` to the corresponding atom in `Lists α`. -/
@[match_pattern]
def atom (a : α) : Lists α :=
⟨_, Lists'.atom a⟩
/-- Converts a proper ZFA prelist to a ZFA list. -/
@[match_pattern]
def of' (l : Lists' α true) : Lists α :=
⟨_, l⟩
/-- Converts a ZFA list to a `List` of ZFA lists. Atoms are sent to `[]`. -/
@[simp]
def toList : Lists α → List (Lists α)
| ⟨_, l⟩ => l.toList
/-- Predicate stating that a ZFA list is proper. -/
def IsList (l : Lists α) : Prop :=
l.1
/-- Converts a `List` of ZFA lists to a ZFA list. -/
def ofList (l : List (Lists α)) : Lists α :=
of' (Lists'.ofList l)
theorem isList_toList (l : List (Lists α)) : IsList (ofList l) :=
Eq.refl _
theorem to_ofList (l : List (Lists α)) : toList (ofList l) = l := by simp [ofList, of']
theorem of_toList : ∀ {l : Lists α}, IsList l → ofList (toList l) = l
| ⟨true, l⟩, _ => by simp_all [ofList, of']
instance : Inhabited (Lists α) :=
⟨of' Lists'.nil⟩
instance [DecidableEq α] : DecidableEq (Lists α) := by unfold Lists; infer_instance
instance [SizeOf α] : SizeOf (Lists α) := by unfold Lists; infer_instance
/-- A recursion principle for pairs of ZFA lists and proper ZFA prelists. -/
def inductionMut (C : Lists α → Sort*) (D : Lists' α true → Sort*)
(C0 : ∀ a, C (atom a)) (C1 : ∀ l, D l → C (of' l))
(D0 : D Lists'.nil) (D1 : ∀ a l, C a → D l → D (Lists'.cons a l)) :
PProd (∀ l, C l) (∀ l, D l) := by
suffices
∀ {b} (l : Lists' α b),
PProd (C ⟨_, l⟩)
(match b, l with
| true, l => D l
| false, _ => PUnit)
by exact ⟨fun ⟨b, l⟩ => (this _).1, fun l => (this l).2⟩
intros b l
induction' l with a b a l IH₁ IH
· exact ⟨C0 _, ⟨⟩⟩
· exact ⟨C1 _ D0, D0⟩
· have : D (Lists'.cons' a l) := D1 ⟨_, _⟩ _ IH₁.1 IH.2
exact ⟨C1 _ this, this⟩
/-- Membership of ZFA list. A ZFA list belongs to a proper ZFA list if it belongs to the latter as a
proper ZFA prelist. An atom has no members. -/
def mem (a : Lists α) : Lists α → Prop
| ⟨false, _⟩ => False
| ⟨_, l⟩ => a ∈ l
instance : Membership (Lists α) (Lists α) :=
⟨mem⟩
theorem isList_of_mem {a : Lists α} : ∀ {l : Lists α}, a ∈ l → IsList l
| ⟨_, Lists'.nil⟩, _ => rfl
| ⟨_, Lists'.cons' _ _⟩, _ => rfl
theorem Equiv.antisymm_iff {l₁ l₂ : Lists' α true} : of' l₁ ~ of' l₂ ↔ l₁ ⊆ l₂ ∧ l₂ ⊆ l₁ := by
refine ⟨fun h => ?_, fun ⟨h₁, h₂⟩ => Equiv.antisymm h₁ h₂⟩
cases' h with _ _ _ h₁ h₂
· simp [Lists'.Subset.refl]
· exact ⟨h₁, h₂⟩
attribute [refl] Equiv.refl
theorem equiv_atom {a} {l : Lists α} : atom a ~ l ↔ atom a = l :=
⟨fun h => by cases h; rfl, fun h => h ▸ Equiv.refl _⟩
@[symm]
theorem Equiv.symm {l₁ l₂ : Lists α} (h : l₁ ~ l₂) : l₂ ~ l₁ := by
cases' h with _ _ _ h₁ h₂ <;> [rfl; exact Equiv.antisymm h₂ h₁]
theorem Equiv.trans : ∀ {l₁ l₂ l₃ : Lists α}, l₁ ~ l₂ → l₂ ~ l₃ → l₁ ~ l₃ := by
let trans := fun l₁ : Lists α => ∀ ⦃l₂ l₃⦄, l₁ ~ l₂ → l₂ ~ l₃ → l₁ ~ l₃
suffices PProd (∀ l₁, trans l₁) (∀ (l : Lists' α true), ∀ l' ∈ l.toList, trans l') by exact this.1
apply inductionMut
· intro a l₂ l₃ h₁ h₂
rwa [← equiv_atom.1 h₁] at h₂
· intro l₁ IH l₂ l₃ h₁ h₂
cases' id h₁ with _ _ l₂
· exact h₂
cases' id h₂ with _ _ l₃
· exact h₁
cases' Equiv.antisymm_iff.1 h₁ with hl₁ hr₁
cases' Equiv.antisymm_iff.1 h₂ with hl₂ hr₂
apply Equiv.antisymm_iff.2; constructor <;> apply Lists'.subset_def.2
· intro a₁ m₁
rcases Lists'.mem_of_subset' hl₁ m₁ with ⟨a₂, m₂, e₁₂⟩
rcases Lists'.mem_of_subset' hl₂ m₂ with ⟨a₃, m₃, e₂₃⟩
exact ⟨a₃, m₃, IH _ m₁ e₁₂ e₂₃⟩
· intro a₃ m₃
rcases Lists'.mem_of_subset' hr₂ m₃ with ⟨a₂, m₂, e₃₂⟩
rcases Lists'.mem_of_subset' hr₁ m₂ with ⟨a₁, m₁, e₂₁⟩
exact ⟨a₁, m₁, (IH _ m₁ e₂₁.symm e₃₂.symm).symm⟩
· rintro _ ⟨⟩
· intro a l IH₁ IH₂
simpa using ⟨IH₁, IH₂⟩
instance instSetoidLists : Setoid (Lists α) :=
⟨(· ~ ·), Equiv.refl, @Equiv.symm _, @Equiv.trans _⟩
section Decidable
/-- Auxiliary function to prove termination of decidability checking -/
@[simp, deprecated (since := "2023-06-24")]
def Equiv.decidableMeas :
((Σ' _l₁ : Lists α, Lists α) ⊕'
((Σ' _l₁ : Lists' α true, Lists' α true) ⊕' (Σ' _a : Lists α, Lists' α true))) →
ℕ
| PSum.inl ⟨l₁, l₂⟩ => SizeOf.sizeOf l₁ + SizeOf.sizeOf l₂
| PSum.inr <| PSum.inl ⟨l₁, l₂⟩ => SizeOf.sizeOf l₁ + SizeOf.sizeOf l₂
| PSum.inr <| PSum.inr ⟨l₁, l₂⟩ => SizeOf.sizeOf l₁ + SizeOf.sizeOf l₂
theorem sizeof_pos {b} (l : Lists' α b) : 0 < SizeOf.sizeOf l := by
cases l <;> simp only [Lists'.atom.sizeOf_spec, Lists'.nil.sizeOf_spec, Lists'.cons'.sizeOf_spec,
true_or, add_pos_iff, zero_lt_one]
theorem lt_sizeof_cons' {b} (a : Lists' α b) (l) :
SizeOf.sizeOf (⟨b, a⟩ : Lists α) < SizeOf.sizeOf (Lists'.cons' a l) := by
simp only [Sigma.mk.sizeOf_spec, Lists'.cons'.sizeOf_spec, lt_add_iff_pos_right]
apply sizeof_pos
variable [DecidableEq α]
mutual
instance Equiv.decidable : ∀ l₁ l₂ : Lists α, Decidable (l₁ ~ l₂)
| ⟨false, l₁⟩, ⟨false, l₂⟩ =>
decidable_of_iff' (l₁ = l₂) <| by
cases l₁
apply equiv_atom.trans
simp only [atom]
constructor <;> (rintro ⟨rfl⟩; rfl)
| ⟨false, l₁⟩, ⟨true, l₂⟩ => isFalse <| by rintro ⟨⟩
| ⟨true, l₁⟩, ⟨false, l₂⟩ => isFalse <| by rintro ⟨⟩
| ⟨true, l₁⟩, ⟨true, l₂⟩ => by
haveI : Decidable (l₁ ⊆ l₂) :=
have : SizeOf.sizeOf l₁ + SizeOf.sizeOf l₂ <
SizeOf.sizeOf (⟨true, l₁⟩ : Lists α) + SizeOf.sizeOf (⟨true, l₂⟩ : Lists α) := by
decreasing_tactic
Subset.decidable l₁ l₂
haveI : Decidable (l₂ ⊆ l₁) :=
have : SizeOf.sizeOf l₂ + SizeOf.sizeOf l₁ <
SizeOf.sizeOf (⟨true, l₁⟩ : Lists α) + SizeOf.sizeOf (⟨true, l₂⟩ : Lists α) := by
decreasing_tactic
Subset.decidable l₂ l₁
exact decidable_of_iff' _ Equiv.antisymm_iff
termination_by x y => sizeOf x + sizeOf y
instance Subset.decidable : ∀ l₁ l₂ : Lists' α true, Decidable (l₁ ⊆ l₂)
| Lists'.nil, l₂ => isTrue Lists'.Subset.nil
| @Lists'.cons' _ b a l₁, l₂ => by
haveI :=
have : sizeOf (⟨b, a⟩ : Lists α) < 1 + 1 + sizeOf a + sizeOf l₁ := by simp [sizeof_pos]
mem.decidable ⟨b, a⟩ l₂
haveI :=
have : SizeOf.sizeOf l₁ + SizeOf.sizeOf l₂ <
SizeOf.sizeOf (Lists'.cons' a l₁) + SizeOf.sizeOf l₂ := by
decreasing_tactic
Subset.decidable l₁ l₂
exact decidable_of_iff' _ (@Lists'.cons_subset _ ⟨_, _⟩ _ _)
termination_by x y => sizeOf x + sizeOf y
instance mem.decidable : ∀ (a : Lists α) (l : Lists' α true), Decidable (a ∈ l)
| a, Lists'.nil => isFalse <| by rintro ⟨_, ⟨⟩, _⟩
| a, Lists'.cons' b l₂ => by
haveI :=
have : sizeOf (⟨_, b⟩ : Lists α) < 1 + 1 + sizeOf b + sizeOf l₂ := by simp [sizeof_pos]
Equiv.decidable a ⟨_, b⟩
haveI :=
have :
SizeOf.sizeOf a + SizeOf.sizeOf l₂ <
SizeOf.sizeOf a + SizeOf.sizeOf (Lists'.cons' b l₂) := by
decreasing_tactic
mem.decidable a l₂
refine decidable_of_iff' (a ~ ⟨_, b⟩ ∨ a ∈ l₂) ?_
rw [← Lists'.mem_cons]; rfl
termination_by x y => sizeOf x + sizeOf y
end
-- This is an autogenerated declaration, so there's nothing we can do about it.
attribute [nolint nonClassInstance] Lists.Equiv.decidable._mutual
end Decidable
end Lists
namespace Lists'
theorem mem_equiv_left {l : Lists' α true} : ∀ {a a'}, a ~ a' → (a ∈ l ↔ a' ∈ l) :=
suffices ∀ {a a'}, a ~ a' → a ∈ l → a' ∈ l from fun e => ⟨this e, this e.symm⟩
fun e₁ ⟨_, m₃, e₂⟩ => ⟨_, m₃, e₁.symm.trans e₂⟩
theorem mem_of_subset {a} {l₁ l₂ : Lists' α true} (s : l₁ ⊆ l₂) : a ∈ l₁ → a ∈ l₂
| ⟨_, m, e⟩ => (mem_equiv_left e).2 (mem_of_subset' s m)
theorem Subset.trans {l₁ l₂ l₃ : Lists' α true} (h₁ : l₁ ⊆ l₂) (h₂ : l₂ ⊆ l₃) : l₁ ⊆ l₃ :=
subset_def.2 fun _ m₁ => mem_of_subset h₂ <| mem_of_subset' h₁ m₁
end Lists'
/-- `Finsets` are defined via equivalence classes of `Lists` -/
def Finsets (α : Type*) :=
Quotient (@Lists.instSetoidLists α)
namespace Finsets
instance : EmptyCollection (Finsets α) :=
⟨⟦Lists.of' Lists'.nil⟧⟩
instance : Inhabited (Finsets α) :=
⟨∅⟩
instance [DecidableEq α] : DecidableEq (Finsets α) := by
unfold Finsets
-- Porting note: infer_instance does not work for some reason
exact (Quotient.decidableEq (d := fun _ _ => Lists.Equiv.decidable _ _))
end Finsets
|
SetTheory\Cardinal\Basic.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Floris van Doorn
-/
import Mathlib.Data.Fintype.BigOperators
import Mathlib.Data.Finsupp.Defs
import Mathlib.Data.Set.Countable
import Mathlib.Logic.Small.Set
import Mathlib.Order.SuccPred.CompleteLinearOrder
import Mathlib.SetTheory.Cardinal.SchroederBernstein
import Mathlib.Algebra.Order.Ring.Nat
import Mathlib.Data.Nat.Cast.Order.Basic
/-!
# Cardinal Numbers
We define cardinal numbers as a quotient of types under the equivalence relation of equinumerity.
## Main definitions
* `Cardinal` is the type of cardinal numbers (in a given universe).
* `Cardinal.mk α` or `#α` is the cardinality of `α`. The notation `#` lives in the locale
`Cardinal`.
* Addition `c₁ + c₂` is defined by `Cardinal.add_def α β : #α + #β = #(α ⊕ β)`.
* Multiplication `c₁ * c₂` is defined by `Cardinal.mul_def : #α * #β = #(α × β)`.
* The order `c₁ ≤ c₂` is defined by `Cardinal.le_def α β : #α ≤ #β ↔ Nonempty (α ↪ β)`.
* Exponentiation `c₁ ^ c₂` is defined by `Cardinal.power_def α β : #α ^ #β = #(β → α)`.
* `Cardinal.isLimit c` means that `c` is a (weak) limit cardinal: `c ≠ 0 ∧ ∀ x < c, succ x < c`.
* `Cardinal.aleph0` or `ℵ₀` is the cardinality of `ℕ`. This definition is universe polymorphic:
`Cardinal.aleph0.{u} : Cardinal.{u}` (contrast with `ℕ : Type`, which lives in a specific
universe). In some cases the universe level has to be given explicitly.
* `Cardinal.sum` is the sum of an indexed family of cardinals, i.e. the cardinality of the
corresponding sigma type.
* `Cardinal.prod` is the product of an indexed family of cardinals, i.e. the cardinality of the
corresponding pi type.
* `Cardinal.powerlt a b` or `a ^< b` is defined as the supremum of `a ^ c` for `c < b`.
## Main instances
* Cardinals form a `CanonicallyOrderedCommSemiring` with the aforementioned sum and product.
* Cardinals form a `SuccOrder`. Use `Order.succ c` for the smallest cardinal greater than `c`.
* The less than relation on cardinals forms a well-order.
* Cardinals form a `ConditionallyCompleteLinearOrderBot`. Bounded sets for cardinals in universe
`u` are precisely the sets indexed by some type in universe `u`, see
`Cardinal.bddAbove_iff_small`. One can use `sSup` for the cardinal supremum, and `sInf` for the
minimum of a set of cardinals.
## Main Statements
* Cantor's theorem: `Cardinal.cantor c : c < 2 ^ c`.
* König's theorem: `Cardinal.sum_lt_prod`
## Implementation notes
* There is a type of cardinal numbers in every universe level:
`Cardinal.{u} : Type (u + 1)` is the quotient of types in `Type u`.
The operation `Cardinal.lift` lifts cardinal numbers to a higher level.
* Cardinal arithmetic specifically for infinite cardinals (like `κ * κ = κ`) is in the file
`Mathlib/SetTheory/Cardinal/Ordinal.lean`.
* There is an instance `Pow Cardinal`, but this will only fire if Lean already knows that both
the base and the exponent live in the same universe. As a workaround, you can add
```
local infixr:80 " ^' " => @HPow.hPow Cardinal Cardinal Cardinal _
```
to a file. This notation will work even if Lean doesn't know yet that the base and the exponent
live in the same universe (but no exponents in other types can be used).
(Porting note: This last point might need to be updated.)
## References
* <https://en.wikipedia.org/wiki/Cardinal_number>
## Tags
cardinal number, cardinal arithmetic, cardinal exponentiation, aleph,
Cantor's theorem, König's theorem, Konig's theorem
-/
assert_not_exists Field
assert_not_exists Module
open scoped Classical
open Mathlib (Vector)
open Function Set Order
noncomputable section
universe u v w
variable {α β : Type u}
/-- The equivalence relation on types given by equivalence (bijective correspondence) of types.
Quotienting by this equivalence relation gives the cardinal numbers.
-/
instance Cardinal.isEquivalent : Setoid (Type u) where
r α β := Nonempty (α ≃ β)
iseqv := ⟨
fun α => ⟨Equiv.refl α⟩,
fun ⟨e⟩ => ⟨e.symm⟩,
fun ⟨e₁⟩ ⟨e₂⟩ => ⟨e₁.trans e₂⟩⟩
/-- `Cardinal.{u}` is the type of cardinal numbers in `Type u`,
defined as the quotient of `Type u` by existence of an equivalence
(a bijection with explicit inverse). -/
@[pp_with_univ]
def Cardinal : Type (u + 1) :=
Quotient Cardinal.isEquivalent
namespace Cardinal
/-- The cardinal number of a type -/
def mk : Type u → Cardinal :=
Quotient.mk'
@[inherit_doc]
scoped prefix:max "#" => Cardinal.mk
instance canLiftCardinalType : CanLift Cardinal.{u} (Type u) mk fun _ => True :=
⟨fun c _ => Quot.inductionOn c fun α => ⟨α, rfl⟩⟩
@[elab_as_elim]
theorem inductionOn {p : Cardinal → Prop} (c : Cardinal) (h : ∀ α, p #α) : p c :=
Quotient.inductionOn c h
@[elab_as_elim]
theorem inductionOn₂ {p : Cardinal → Cardinal → Prop} (c₁ : Cardinal) (c₂ : Cardinal)
(h : ∀ α β, p #α #β) : p c₁ c₂ :=
Quotient.inductionOn₂ c₁ c₂ h
@[elab_as_elim]
theorem inductionOn₃ {p : Cardinal → Cardinal → Cardinal → Prop} (c₁ : Cardinal) (c₂ : Cardinal)
(c₃ : Cardinal) (h : ∀ α β γ, p #α #β #γ) : p c₁ c₂ c₃ :=
Quotient.inductionOn₃ c₁ c₂ c₃ h
protected theorem eq : #α = #β ↔ Nonempty (α ≃ β) :=
Quotient.eq'
@[simp]
theorem mk'_def (α : Type u) : @Eq Cardinal ⟦α⟧ #α :=
rfl
@[simp]
theorem mk_out (c : Cardinal) : #c.out = c :=
Quotient.out_eq _
/-- The representative of the cardinal of a type is equivalent to the original type. -/
def outMkEquiv {α : Type v} : (#α).out ≃ α :=
Nonempty.some <| Cardinal.eq.mp (by simp)
theorem mk_congr (e : α ≃ β) : #α = #β :=
Quot.sound ⟨e⟩
alias _root_.Equiv.cardinal_eq := mk_congr
/-- Lift a function between `Type*`s to a function between `Cardinal`s. -/
def map (f : Type u → Type v) (hf : ∀ α β, α ≃ β → f α ≃ f β) : Cardinal.{u} → Cardinal.{v} :=
Quotient.map f fun α β ⟨e⟩ => ⟨hf α β e⟩
@[simp]
theorem map_mk (f : Type u → Type v) (hf : ∀ α β, α ≃ β → f α ≃ f β) (α : Type u) :
map f hf #α = #(f α) :=
rfl
/-- Lift a binary operation `Type* → Type* → Type*` to a binary operation on `Cardinal`s. -/
def map₂ (f : Type u → Type v → Type w) (hf : ∀ α β γ δ, α ≃ β → γ ≃ δ → f α γ ≃ f β δ) :
Cardinal.{u} → Cardinal.{v} → Cardinal.{w} :=
Quotient.map₂ f fun α β ⟨e₁⟩ γ δ ⟨e₂⟩ => ⟨hf α β γ δ e₁ e₂⟩
/-- The universe lift operation on cardinals. You can specify the universes explicitly with
`lift.{u v} : Cardinal.{v} → Cardinal.{max v u}` -/
@[pp_with_univ]
def lift (c : Cardinal.{v}) : Cardinal.{max v u} :=
map ULift.{u, v} (fun _ _ e => Equiv.ulift.trans <| e.trans Equiv.ulift.symm) c
@[simp]
theorem mk_uLift (α) : #(ULift.{v, u} α) = lift.{v} #α :=
rfl
-- Porting note: simpNF is not happy with universe levels, but this is needed as simp lemma
-- further down in this file
/-- `lift.{max u v, u}` equals `lift.{v, u}`. -/
@[simp, nolint simpNF]
theorem lift_umax : lift.{max u v, u} = lift.{v, u} :=
funext fun a => inductionOn a fun _ => (Equiv.ulift.trans Equiv.ulift.symm).cardinal_eq
-- Porting note: simpNF is not happy with universe levels, but this is needed as simp lemma
-- further down in this file
/-- `lift.{max v u, u}` equals `lift.{v, u}`. -/
@[simp, nolint simpNF]
theorem lift_umax' : lift.{max v u, u} = lift.{v, u} :=
lift_umax
-- Porting note: simpNF is not happy with universe levels, but this is needed as simp lemma
-- further down in this file
/-- A cardinal lifted to a lower or equal universe equals itself. -/
@[simp, nolint simpNF]
theorem lift_id' (a : Cardinal.{max u v}) : lift.{u} a = a :=
inductionOn a fun _ => mk_congr Equiv.ulift
/-- A cardinal lifted to the same universe equals itself. -/
@[simp]
theorem lift_id (a : Cardinal) : lift.{u, u} a = a :=
lift_id'.{u, u} a
/-- A cardinal lifted to the zero universe equals itself. -/
-- porting note (#10618): simp can prove this
-- @[simp]
theorem lift_uzero (a : Cardinal.{u}) : lift.{0} a = a :=
lift_id'.{0, u} a
@[simp]
theorem lift_lift.{u_1} (a : Cardinal.{u_1}) : lift.{w} (lift.{v} a) = lift.{max v w} a :=
inductionOn a fun _ => (Equiv.ulift.trans <| Equiv.ulift.trans Equiv.ulift.symm).cardinal_eq
/-- We define the order on cardinal numbers by `#α ≤ #β` if and only if
there exists an embedding (injective function) from α to β. -/
instance : LE Cardinal.{u} :=
⟨fun q₁ q₂ =>
Quotient.liftOn₂ q₁ q₂ (fun α β => Nonempty <| α ↪ β) fun _ _ _ _ ⟨e₁⟩ ⟨e₂⟩ =>
propext ⟨fun ⟨e⟩ => ⟨e.congr e₁ e₂⟩, fun ⟨e⟩ => ⟨e.congr e₁.symm e₂.symm⟩⟩⟩
instance partialOrder : PartialOrder Cardinal.{u} where
le := (· ≤ ·)
le_refl := by
rintro ⟨α⟩
exact ⟨Embedding.refl _⟩
le_trans := by
rintro ⟨α⟩ ⟨β⟩ ⟨γ⟩ ⟨e₁⟩ ⟨e₂⟩
exact ⟨e₁.trans e₂⟩
le_antisymm := by
rintro ⟨α⟩ ⟨β⟩ ⟨e₁⟩ ⟨e₂⟩
exact Quotient.sound (e₁.antisymm e₂)
instance linearOrder : LinearOrder Cardinal.{u} :=
{ Cardinal.partialOrder with
le_total := by
rintro ⟨α⟩ ⟨β⟩
apply Embedding.total
decidableLE := Classical.decRel _ }
theorem le_def (α β : Type u) : #α ≤ #β ↔ Nonempty (α ↪ β) :=
Iff.rfl
theorem mk_le_of_injective {α β : Type u} {f : α → β} (hf : Injective f) : #α ≤ #β :=
⟨⟨f, hf⟩⟩
theorem _root_.Function.Embedding.cardinal_le {α β : Type u} (f : α ↪ β) : #α ≤ #β :=
⟨f⟩
theorem mk_le_of_surjective {α β : Type u} {f : α → β} (hf : Surjective f) : #β ≤ #α :=
⟨Embedding.ofSurjective f hf⟩
theorem le_mk_iff_exists_set {c : Cardinal} {α : Type u} : c ≤ #α ↔ ∃ p : Set α, #p = c :=
⟨inductionOn c fun _ ⟨⟨f, hf⟩⟩ => ⟨Set.range f, (Equiv.ofInjective f hf).cardinal_eq.symm⟩,
fun ⟨_, e⟩ => e ▸ ⟨⟨Subtype.val, fun _ _ => Subtype.eq⟩⟩⟩
theorem mk_subtype_le {α : Type u} (p : α → Prop) : #(Subtype p) ≤ #α :=
⟨Embedding.subtype p⟩
theorem mk_set_le (s : Set α) : #s ≤ #α :=
mk_subtype_le s
@[simp]
lemma mk_preimage_down {s : Set α} : #(ULift.down.{v} ⁻¹' s) = lift.{v} (#s) := by
rw [← mk_uLift, Cardinal.eq]
constructor
let f : ULift.down ⁻¹' s → ULift s := fun x ↦ ULift.up (restrictPreimage s ULift.down x)
have : Function.Bijective f :=
ULift.up_bijective.comp (restrictPreimage_bijective _ (ULift.down_bijective))
exact Equiv.ofBijective f this
theorem out_embedding {c c' : Cardinal} : c ≤ c' ↔ Nonempty (c.out ↪ c'.out) := by
trans
· rw [← Quotient.out_eq c, ← Quotient.out_eq c']
· rw [mk'_def, mk'_def, le_def]
theorem lift_mk_le {α : Type v} {β : Type w} :
lift.{max u w} #α ≤ lift.{max u v} #β ↔ Nonempty (α ↪ β) :=
⟨fun ⟨f⟩ => ⟨Embedding.congr Equiv.ulift Equiv.ulift f⟩, fun ⟨f⟩ =>
⟨Embedding.congr Equiv.ulift.symm Equiv.ulift.symm f⟩⟩
/-- A variant of `Cardinal.lift_mk_le` with specialized universes.
Because Lean often can not realize it should use this specialization itself,
we provide this statement separately so you don't have to solve the specialization problem either.
-/
theorem lift_mk_le' {α : Type u} {β : Type v} : lift.{v} #α ≤ lift.{u} #β ↔ Nonempty (α ↪ β) :=
lift_mk_le.{0}
theorem lift_mk_eq {α : Type u} {β : Type v} :
lift.{max v w} #α = lift.{max u w} #β ↔ Nonempty (α ≃ β) :=
Quotient.eq'.trans
⟨fun ⟨f⟩ => ⟨Equiv.ulift.symm.trans <| f.trans Equiv.ulift⟩, fun ⟨f⟩ =>
⟨Equiv.ulift.trans <| f.trans Equiv.ulift.symm⟩⟩
/-- A variant of `Cardinal.lift_mk_eq` with specialized universes.
Because Lean often can not realize it should use this specialization itself,
we provide this statement separately so you don't have to solve the specialization problem either.
-/
theorem lift_mk_eq' {α : Type u} {β : Type v} : lift.{v} #α = lift.{u} #β ↔ Nonempty (α ≃ β) :=
lift_mk_eq.{u, v, 0}
@[simp]
theorem lift_le {a b : Cardinal.{v}} : lift.{u, v} a ≤ lift.{u, v} b ↔ a ≤ b :=
inductionOn₂ a b fun α β => by
rw [← lift_umax]
exact lift_mk_le.{u}
-- Porting note: changed `simps` to `simps!` because the linter told to do so.
/-- `Cardinal.lift` as an `OrderEmbedding`. -/
@[simps! (config := .asFn)]
def liftOrderEmbedding : Cardinal.{v} ↪o Cardinal.{max v u} :=
OrderEmbedding.ofMapLEIff lift.{u, v} fun _ _ => lift_le
theorem lift_injective : Injective lift.{u, v} :=
liftOrderEmbedding.injective
@[simp]
theorem lift_inj {a b : Cardinal.{u}} : lift.{v, u} a = lift.{v, u} b ↔ a = b :=
lift_injective.eq_iff
@[simp]
theorem lift_lt {a b : Cardinal.{u}} : lift.{v, u} a < lift.{v, u} b ↔ a < b :=
liftOrderEmbedding.lt_iff_lt
theorem lift_strictMono : StrictMono lift := fun _ _ => lift_lt.2
theorem lift_monotone : Monotone lift :=
lift_strictMono.monotone
instance : Zero Cardinal.{u} :=
-- `PEmpty` might be more canonical, but this is convenient for defeq with natCast
⟨lift #(Fin 0)⟩
instance : Inhabited Cardinal.{u} :=
⟨0⟩
@[simp]
theorem mk_eq_zero (α : Type u) [IsEmpty α] : #α = 0 :=
(Equiv.equivOfIsEmpty α (ULift (Fin 0))).cardinal_eq
@[simp]
theorem lift_zero : lift 0 = 0 := mk_eq_zero _
@[simp]
theorem lift_eq_zero {a : Cardinal.{v}} : lift.{u} a = 0 ↔ a = 0 :=
lift_injective.eq_iff' lift_zero
theorem mk_eq_zero_iff {α : Type u} : #α = 0 ↔ IsEmpty α :=
⟨fun e =>
let ⟨h⟩ := Quotient.exact e
h.isEmpty,
@mk_eq_zero α⟩
theorem mk_ne_zero_iff {α : Type u} : #α ≠ 0 ↔ Nonempty α :=
(not_iff_not.2 mk_eq_zero_iff).trans not_isEmpty_iff
@[simp]
theorem mk_ne_zero (α : Type u) [Nonempty α] : #α ≠ 0 :=
mk_ne_zero_iff.2 ‹_›
instance : One Cardinal.{u} :=
-- `PUnit` might be more canonical, but this is convenient for defeq with natCast
⟨lift #(Fin 1)⟩
instance : Nontrivial Cardinal.{u} :=
⟨⟨1, 0, mk_ne_zero _⟩⟩
theorem mk_eq_one (α : Type u) [Unique α] : #α = 1 :=
(Equiv.equivOfUnique α (ULift (Fin 1))).cardinal_eq
theorem le_one_iff_subsingleton {α : Type u} : #α ≤ 1 ↔ Subsingleton α :=
⟨fun ⟨f⟩ => ⟨fun _ _ => f.injective (Subsingleton.elim _ _)⟩, fun ⟨h⟩ =>
⟨fun _ => ULift.up 0, fun _ _ _ => h _ _⟩⟩
@[simp]
theorem mk_le_one_iff_set_subsingleton {s : Set α} : #s ≤ 1 ↔ s.Subsingleton :=
le_one_iff_subsingleton.trans s.subsingleton_coe
alias ⟨_, _root_.Set.Subsingleton.cardinal_mk_le_one⟩ := mk_le_one_iff_set_subsingleton
instance : Add Cardinal.{u} :=
⟨map₂ Sum fun _ _ _ _ => Equiv.sumCongr⟩
theorem add_def (α β : Type u) : #α + #β = #(α ⊕ β) :=
rfl
instance : NatCast Cardinal.{u} :=
⟨fun n => lift #(Fin n)⟩
@[simp]
theorem mk_sum (α : Type u) (β : Type v) : #(α ⊕ β) = lift.{v, u} #α + lift.{u, v} #β :=
mk_congr (Equiv.ulift.symm.sumCongr Equiv.ulift.symm)
@[simp]
theorem mk_option {α : Type u} : #(Option α) = #α + 1 := by
rw [(Equiv.optionEquivSumPUnit.{u, u} α).cardinal_eq, mk_sum, mk_eq_one PUnit, lift_id, lift_id]
@[simp]
theorem mk_psum (α : Type u) (β : Type v) : #(α ⊕' β) = lift.{v} #α + lift.{u} #β :=
(mk_congr (Equiv.psumEquivSum α β)).trans (mk_sum α β)
@[simp]
theorem mk_fintype (α : Type u) [h : Fintype α] : #α = Fintype.card α :=
mk_congr (Fintype.equivOfCardEq (by simp))
protected theorem cast_succ (n : ℕ) : ((n + 1 : ℕ) : Cardinal.{u}) = n + 1 := by
change #(ULift.{u} (Fin (n+1))) = # (ULift.{u} (Fin n)) + 1
rw [← mk_option, mk_fintype, mk_fintype]
simp only [Fintype.card_ulift, Fintype.card_fin, Fintype.card_option]
instance : Mul Cardinal.{u} :=
⟨map₂ Prod fun _ _ _ _ => Equiv.prodCongr⟩
theorem mul_def (α β : Type u) : #α * #β = #(α × β) :=
rfl
@[simp]
theorem mk_prod (α : Type u) (β : Type v) : #(α × β) = lift.{v, u} #α * lift.{u, v} #β :=
mk_congr (Equiv.ulift.symm.prodCongr Equiv.ulift.symm)
private theorem mul_comm' (a b : Cardinal.{u}) : a * b = b * a :=
inductionOn₂ a b fun α β => mk_congr <| Equiv.prodComm α β
/-- The cardinal exponential. `#α ^ #β` is the cardinal of `β → α`. -/
instance instPowCardinal : Pow Cardinal.{u} Cardinal.{u} :=
⟨map₂ (fun α β => β → α) fun _ _ _ _ e₁ e₂ => e₂.arrowCongr e₁⟩
theorem power_def (α β : Type u) : #α ^ #β = #(β → α) :=
rfl
theorem mk_arrow (α : Type u) (β : Type v) : #(α → β) = (lift.{u} #β^lift.{v} #α) :=
mk_congr (Equiv.ulift.symm.arrowCongr Equiv.ulift.symm)
@[simp]
theorem lift_power (a b : Cardinal.{u}) : lift.{v} (a ^ b) = lift.{v} a ^ lift.{v} b :=
inductionOn₂ a b fun _ _ =>
mk_congr <| Equiv.ulift.trans (Equiv.ulift.arrowCongr Equiv.ulift).symm
@[simp]
theorem power_zero {a : Cardinal} : a ^ (0 : Cardinal) = 1 :=
inductionOn a fun _ => mk_eq_one _
@[simp]
theorem power_one {a : Cardinal.{u}} : a ^ (1 : Cardinal) = a :=
inductionOn a fun α => mk_congr (Equiv.funUnique (ULift.{u} (Fin 1)) α)
theorem power_add {a b c : Cardinal} : a ^ (b + c) = a ^ b * a ^ c :=
inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.sumArrowEquivProdArrow β γ α
instance commSemiring : CommSemiring Cardinal.{u} where
zero := 0
one := 1
add := (· + ·)
mul := (· * ·)
zero_add a := inductionOn a fun α => mk_congr <| Equiv.emptySum (ULift (Fin 0)) α
add_zero a := inductionOn a fun α => mk_congr <| Equiv.sumEmpty α (ULift (Fin 0))
add_assoc a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.sumAssoc α β γ
add_comm a b := inductionOn₂ a b fun α β => mk_congr <| Equiv.sumComm α β
zero_mul a := inductionOn a fun α => mk_eq_zero _
mul_zero a := inductionOn a fun α => mk_eq_zero _
one_mul a := inductionOn a fun α => mk_congr <| Equiv.uniqueProd α (ULift (Fin 1))
mul_one a := inductionOn a fun α => mk_congr <| Equiv.prodUnique α (ULift (Fin 1))
mul_assoc a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.prodAssoc α β γ
mul_comm := mul_comm'
left_distrib a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.prodSumDistrib α β γ
right_distrib a b c := inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.sumProdDistrib α β γ
nsmul := nsmulRec
npow n c := c ^ (n : Cardinal)
npow_zero := @power_zero
npow_succ n c := show c ^ (↑(n + 1) : Cardinal) = c ^ (↑n : Cardinal) * c
by rw [Cardinal.cast_succ, power_add, power_one, mul_comm']
natCast := (fun n => lift.{u} #(Fin n) : ℕ → Cardinal.{u})
natCast_zero := rfl
natCast_succ := Cardinal.cast_succ
@[simp]
theorem one_power {a : Cardinal} : (1 : Cardinal) ^ a = 1 :=
inductionOn a fun _ => mk_eq_one _
-- porting note (#10618): simp can prove this
-- @[simp]
theorem mk_bool : #Bool = 2 := by simp
-- porting note (#10618): simp can prove this
-- @[simp]
theorem mk_Prop : #Prop = 2 := by simp
@[simp]
theorem zero_power {a : Cardinal} : a ≠ 0 → (0 : Cardinal) ^ a = 0 :=
inductionOn a fun _ heq =>
mk_eq_zero_iff.2 <|
isEmpty_pi.2 <|
let ⟨a⟩ := mk_ne_zero_iff.1 heq
⟨a, inferInstance⟩
theorem power_ne_zero {a : Cardinal} (b : Cardinal) : a ≠ 0 → a ^ b ≠ 0 :=
inductionOn₂ a b fun _ _ h =>
let ⟨a⟩ := mk_ne_zero_iff.1 h
mk_ne_zero_iff.2 ⟨fun _ => a⟩
theorem mul_power {a b c : Cardinal} : (a * b) ^ c = a ^ c * b ^ c :=
inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.arrowProdEquivProdArrow α β γ
theorem power_mul {a b c : Cardinal} : a ^ (b * c) = (a ^ b) ^ c := by
rw [mul_comm b c]
exact inductionOn₃ a b c fun α β γ => mk_congr <| Equiv.curry γ β α
@[simp]
theorem pow_cast_right (a : Cardinal.{u}) (n : ℕ) : a ^ (↑n : Cardinal.{u}) = a ^ n :=
rfl
@[simp]
theorem lift_one : lift 1 = 1 := mk_eq_one _
@[simp]
theorem lift_eq_one {a : Cardinal.{v}} : lift.{u} a = 1 ↔ a = 1 :=
lift_injective.eq_iff' lift_one
@[simp]
theorem lift_add (a b : Cardinal.{u}) : lift.{v} (a + b) = lift.{v} a + lift.{v} b :=
inductionOn₂ a b fun _ _ =>
mk_congr <| Equiv.ulift.trans (Equiv.sumCongr Equiv.ulift Equiv.ulift).symm
@[simp]
theorem lift_mul (a b : Cardinal.{u}) : lift.{v} (a * b) = lift.{v} a * lift.{v} b :=
inductionOn₂ a b fun _ _ =>
mk_congr <| Equiv.ulift.trans (Equiv.prodCongr Equiv.ulift Equiv.ulift).symm
-- Porting note: Proof used to be simp, needed to remind simp that 1 + 1 = 2
theorem lift_two : lift.{u, v} 2 = 2 := by simp [← one_add_one_eq_two]
@[simp]
theorem mk_set {α : Type u} : #(Set α) = 2 ^ #α := by simp [← one_add_one_eq_two, Set, mk_arrow]
/-- A variant of `Cardinal.mk_set` expressed in terms of a `Set` instead of a `Type`. -/
@[simp]
theorem mk_powerset {α : Type u} (s : Set α) : #(↥(𝒫 s)) = 2 ^ #(↥s) :=
(mk_congr (Equiv.Set.powerset s)).trans mk_set
theorem lift_two_power (a : Cardinal) : lift.{v} (2 ^ a) = 2 ^ lift.{v} a := by
simp [← one_add_one_eq_two]
section OrderProperties
open Sum
protected theorem zero_le : ∀ a : Cardinal, 0 ≤ a := by
rintro ⟨α⟩
exact ⟨Embedding.ofIsEmpty⟩
private theorem add_le_add' : ∀ {a b c d : Cardinal}, a ≤ b → c ≤ d → a + c ≤ b + d := by
rintro ⟨α⟩ ⟨β⟩ ⟨γ⟩ ⟨δ⟩ ⟨e₁⟩ ⟨e₂⟩; exact ⟨e₁.sumMap e₂⟩
instance add_covariantClass : CovariantClass Cardinal Cardinal (· + ·) (· ≤ ·) :=
⟨fun _ _ _ => add_le_add' le_rfl⟩
instance add_swap_covariantClass : CovariantClass Cardinal Cardinal (swap (· + ·)) (· ≤ ·) :=
⟨fun _ _ _ h => add_le_add' h le_rfl⟩
instance canonicallyOrderedCommSemiring : CanonicallyOrderedCommSemiring Cardinal.{u} :=
{ Cardinal.commSemiring,
Cardinal.partialOrder with
bot := 0
bot_le := Cardinal.zero_le
add_le_add_left := fun a b => add_le_add_left
exists_add_of_le := fun {a b} =>
inductionOn₂ a b fun α β ⟨⟨f, hf⟩⟩ =>
have : α ⊕ ((range f)ᶜ : Set β) ≃ β :=
(Equiv.sumCongr (Equiv.ofInjective f hf) (Equiv.refl _)).trans <|
Equiv.Set.sumCompl (range f)
⟨#(↥(range f)ᶜ), mk_congr this.symm⟩
le_self_add := fun a b => (add_zero a).ge.trans <| add_le_add_left (Cardinal.zero_le _) _
eq_zero_or_eq_zero_of_mul_eq_zero := fun {a b} =>
inductionOn₂ a b fun α β => by
simpa only [mul_def, mk_eq_zero_iff, isEmpty_prod] using id }
instance : CanonicallyLinearOrderedAddCommMonoid Cardinal.{u} :=
{ Cardinal.canonicallyOrderedCommSemiring, Cardinal.linearOrder with }
-- Computable instance to prevent a non-computable one being found via the one above
instance : CanonicallyOrderedAddCommMonoid Cardinal.{u} :=
{ Cardinal.canonicallyOrderedCommSemiring with }
instance : LinearOrderedCommMonoidWithZero Cardinal.{u} :=
{ Cardinal.commSemiring,
Cardinal.linearOrder with
mul_le_mul_left := @mul_le_mul_left' _ _ _ _
zero_le_one := zero_le _ }
-- Computable instance to prevent a non-computable one being found via the one above
instance : CommMonoidWithZero Cardinal.{u} :=
{ Cardinal.canonicallyOrderedCommSemiring with }
-- Porting note: new
-- Computable instance to prevent a non-computable one being found via the one above
instance : CommMonoid Cardinal.{u} :=
{ Cardinal.canonicallyOrderedCommSemiring with }
theorem zero_power_le (c : Cardinal.{u}) : (0 : Cardinal.{u}) ^ c ≤ 1 := by
by_cases h : c = 0
· rw [h, power_zero]
· rw [zero_power h]
apply zero_le
theorem power_le_power_left : ∀ {a b c : Cardinal}, a ≠ 0 → b ≤ c → a ^ b ≤ a ^ c := by
rintro ⟨α⟩ ⟨β⟩ ⟨γ⟩ hα ⟨e⟩
let ⟨a⟩ := mk_ne_zero_iff.1 hα
exact ⟨@Function.Embedding.arrowCongrLeft _ _ _ ⟨a⟩ e⟩
theorem self_le_power (a : Cardinal) {b : Cardinal} (hb : 1 ≤ b) : a ≤ a ^ b := by
rcases eq_or_ne a 0 with (rfl | ha)
· exact zero_le _
· convert power_le_power_left ha hb
exact power_one.symm
/-- **Cantor's theorem** -/
theorem cantor (a : Cardinal.{u}) : a < 2 ^ a := by
induction' a using Cardinal.inductionOn with α
rw [← mk_set]
refine ⟨⟨⟨singleton, fun a b => singleton_eq_singleton_iff.1⟩⟩, ?_⟩
rintro ⟨⟨f, hf⟩⟩
exact cantor_injective f hf
instance : NoMaxOrder Cardinal.{u} where exists_gt a := ⟨_, cantor a⟩
-- short-circuit type class inference
instance : DistribLattice Cardinal.{u} := inferInstance
theorem one_lt_iff_nontrivial {α : Type u} : 1 < #α ↔ Nontrivial α := by
rw [← not_le, le_one_iff_subsingleton, ← not_nontrivial_iff_subsingleton, Classical.not_not]
theorem power_le_max_power_one {a b c : Cardinal} (h : b ≤ c) : a ^ b ≤ max (a ^ c) 1 := by
by_cases ha : a = 0
· simp [ha, zero_power_le]
· exact (power_le_power_left ha h).trans (le_max_left _ _)
theorem power_le_power_right {a b c : Cardinal} : a ≤ b → a ^ c ≤ b ^ c :=
inductionOn₃ a b c fun _ _ _ ⟨e⟩ => ⟨Embedding.arrowCongrRight e⟩
theorem power_pos {a : Cardinal} (b : Cardinal) (ha : 0 < a) : 0 < a ^ b :=
(power_ne_zero _ ha.ne').bot_lt
end OrderProperties
protected theorem lt_wf : @WellFounded Cardinal.{u} (· < ·) :=
⟨fun a =>
by_contradiction fun h => by
let ι := { c : Cardinal // ¬Acc (· < ·) c }
let f : ι → Cardinal := Subtype.val
haveI hι : Nonempty ι := ⟨⟨_, h⟩⟩
obtain ⟨⟨c : Cardinal, hc : ¬Acc (· < ·) c⟩, ⟨h_1 : ∀ j, (f ⟨c, hc⟩).out ↪ (f j).out⟩⟩ :=
Embedding.min_injective fun i => (f i).out
refine hc (Acc.intro _ fun j h' => by_contradiction fun hj => h'.2 ?_)
have : #_ ≤ #_ := ⟨h_1 ⟨j, hj⟩⟩
simpa only [mk_out] using this⟩
instance : WellFoundedRelation Cardinal.{u} :=
⟨(· < ·), Cardinal.lt_wf⟩
-- Porting note: this no longer is automatically inferred.
instance : WellFoundedLT Cardinal.{u} :=
⟨Cardinal.lt_wf⟩
instance wo : @IsWellOrder Cardinal.{u} (· < ·) where
instance : ConditionallyCompleteLinearOrderBot Cardinal :=
IsWellOrder.conditionallyCompleteLinearOrderBot _
@[simp]
theorem sInf_empty : sInf (∅ : Set Cardinal.{u}) = 0 :=
dif_neg Set.not_nonempty_empty
lemma sInf_eq_zero_iff {s : Set Cardinal} : sInf s = 0 ↔ s = ∅ ∨ ∃ a ∈ s, a = 0 := by
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· rcases s.eq_empty_or_nonempty with rfl | hne
· exact Or.inl rfl
· exact Or.inr ⟨sInf s, csInf_mem hne, h⟩
· rcases h with rfl | ⟨a, ha, rfl⟩
· exact Cardinal.sInf_empty
· exact eq_bot_iff.2 (csInf_le' ha)
lemma iInf_eq_zero_iff {ι : Sort*} {f : ι → Cardinal} :
(⨅ i, f i) = 0 ↔ IsEmpty ι ∨ ∃ i, f i = 0 := by
simp [iInf, sInf_eq_zero_iff]
/-- Note that the successor of `c` is not the same as `c + 1` except in the case of finite `c`. -/
instance : SuccOrder Cardinal :=
SuccOrder.ofSuccLeIff (fun c => sInf { c' | c < c' })
-- Porting note: Needed to insert `by apply` in the next line
⟨by apply lt_of_lt_of_le <| csInf_mem <| exists_gt _,
-- Porting note used to be just `csInf_le'`
fun h ↦ csInf_le' h⟩
theorem succ_def (c : Cardinal) : succ c = sInf { c' | c < c' } :=
rfl
theorem succ_pos : ∀ c : Cardinal, 0 < succ c :=
bot_lt_succ
theorem succ_ne_zero (c : Cardinal) : succ c ≠ 0 :=
(succ_pos _).ne'
theorem add_one_le_succ (c : Cardinal.{u}) : c + 1 ≤ succ c := by
-- Porting note: rewrote the next three lines to avoid defeq abuse.
have : Set.Nonempty { c' | c < c' } := exists_gt c
simp_rw [succ_def, le_csInf_iff'' this, mem_setOf]
intro b hlt
rcases b, c with ⟨⟨β⟩, ⟨γ⟩⟩
cases' le_of_lt hlt with f
have : ¬Surjective f := fun hn => (not_le_of_lt hlt) (mk_le_of_surjective hn)
simp only [Surjective, not_forall] at this
rcases this with ⟨b, hb⟩
calc
#γ + 1 = #(Option γ) := mk_option.symm
_ ≤ #β := (f.optionElim b hb).cardinal_le
/-- A cardinal is a limit if it is not zero or a successor cardinal. Note that `ℵ₀` is a limit
cardinal by this definition, but `0` isn't.
Use `IsSuccLimit` if you want to include the `c = 0` case. -/
def IsLimit (c : Cardinal) : Prop :=
c ≠ 0 ∧ IsSuccLimit c
protected theorem IsLimit.ne_zero {c} (h : IsLimit c) : c ≠ 0 :=
h.1
protected theorem IsLimit.isSuccLimit {c} (h : IsLimit c) : IsSuccLimit c :=
h.2
theorem IsLimit.succ_lt {x c} (h : IsLimit c) : x < c → succ x < c :=
h.isSuccLimit.succ_lt
theorem isSuccLimit_zero : IsSuccLimit (0 : Cardinal) :=
isSuccLimit_bot
/-- The indexed sum of cardinals is the cardinality of the
indexed disjoint union, i.e. sigma type. -/
def sum {ι} (f : ι → Cardinal) : Cardinal :=
mk (Σi, (f i).out)
theorem le_sum {ι} (f : ι → Cardinal) (i) : f i ≤ sum f := by
rw [← Quotient.out_eq (f i)]
exact ⟨⟨fun a => ⟨i, a⟩, fun a b h => by injection h⟩⟩
@[simp]
theorem mk_sigma {ι} (f : ι → Type*) : #(Σ i, f i) = sum fun i => #(f i) :=
mk_congr <| Equiv.sigmaCongrRight fun _ => outMkEquiv.symm
@[simp]
theorem sum_const (ι : Type u) (a : Cardinal.{v}) :
(sum fun _ : ι => a) = lift.{v} #ι * lift.{u} a :=
inductionOn a fun α =>
mk_congr <|
calc
(Σ _ : ι, Quotient.out #α) ≃ ι × Quotient.out #α := Equiv.sigmaEquivProd _ _
_ ≃ ULift ι × ULift α := Equiv.ulift.symm.prodCongr (outMkEquiv.trans Equiv.ulift.symm)
theorem sum_const' (ι : Type u) (a : Cardinal.{u}) : (sum fun _ : ι => a) = #ι * a := by simp
@[simp]
theorem sum_add_distrib {ι} (f g : ι → Cardinal) : sum (f + g) = sum f + sum g := by
have := mk_congr (Equiv.sigmaSumDistrib (Quotient.out ∘ f) (Quotient.out ∘ g))
simp only [comp_apply, mk_sigma, mk_sum, mk_out, lift_id] at this
exact this
@[simp]
theorem sum_add_distrib' {ι} (f g : ι → Cardinal) :
(Cardinal.sum fun i => f i + g i) = sum f + sum g :=
sum_add_distrib f g
@[simp]
theorem lift_sum {ι : Type u} (f : ι → Cardinal.{v}) :
Cardinal.lift.{w} (Cardinal.sum f) = Cardinal.sum fun i => Cardinal.lift.{w} (f i) :=
Equiv.cardinal_eq <|
Equiv.ulift.trans <|
Equiv.sigmaCongrRight fun a =>
-- Porting note: Inserted universe hint .{_,_,v} below
Nonempty.some <| by rw [← lift_mk_eq.{_,_,v}, mk_out, mk_out, lift_lift]
theorem sum_le_sum {ι} (f g : ι → Cardinal) (H : ∀ i, f i ≤ g i) : sum f ≤ sum g :=
⟨(Embedding.refl _).sigmaMap fun i =>
Classical.choice <| by have := H i; rwa [← Quot.out_eq (f i), ← Quot.out_eq (g i)] at this⟩
theorem mk_le_mk_mul_of_mk_preimage_le {c : Cardinal} (f : α → β) (hf : ∀ b : β, #(f ⁻¹' {b}) ≤ c) :
#α ≤ #β * c := by
simpa only [← mk_congr (@Equiv.sigmaFiberEquiv α β f), mk_sigma, ← sum_const'] using
sum_le_sum _ _ hf
theorem lift_mk_le_lift_mk_mul_of_lift_mk_preimage_le {α : Type u} {β : Type v} {c : Cardinal}
(f : α → β) (hf : ∀ b : β, lift.{v} #(f ⁻¹' {b}) ≤ c) : lift.{v} #α ≤ lift.{u} #β * c :=
(mk_le_mk_mul_of_mk_preimage_le fun x : ULift.{v} α => ULift.up.{u} (f x.1)) <|
ULift.forall.2 fun b =>
(mk_congr <|
(Equiv.ulift.image _).trans
(Equiv.trans
(by
rw [Equiv.image_eq_preimage]
/- Porting note: Need to insert the following `have` b/c bad fun coercion
behaviour for Equivs -/
have : DFunLike.coe (Equiv.symm (Equiv.ulift (α := α))) = ULift.up (α := α) := rfl
rw [this]
simp only [preimage, mem_singleton_iff, ULift.up_inj, mem_setOf_eq, coe_setOf]
exact Equiv.refl _)
Equiv.ulift.symm)).trans_le
(hf b)
/-- The range of an indexed cardinal function, whose outputs live in a higher universe than the
inputs, is always bounded above. -/
theorem bddAbove_range {ι : Type u} (f : ι → Cardinal.{max u v}) : BddAbove (Set.range f) :=
⟨sum f, by
rintro a ⟨i, rfl⟩
exact le_sum f i⟩
instance (a : Cardinal.{u}) : Small.{u} (Set.Iic a) := by
rw [← mk_out a]
apply @small_of_surjective (Set a.out) (Iic #a.out) _ fun x => ⟨#x, mk_set_le x⟩
rintro ⟨x, hx⟩
simpa using le_mk_iff_exists_set.1 hx
instance (a : Cardinal.{u}) : Small.{u} (Set.Iio a) :=
small_subset Iio_subset_Iic_self
/-- A set of cardinals is bounded above iff it's small, i.e. it corresponds to a usual ZFC set. -/
theorem bddAbove_iff_small {s : Set Cardinal.{u}} : BddAbove s ↔ Small.{u} s :=
⟨fun ⟨a, ha⟩ => @small_subset _ (Iic a) s (fun x h => ha h) _, by
rintro ⟨ι, ⟨e⟩⟩
suffices (range fun x : ι => (e.symm x).1) = s by
rw [← this]
apply bddAbove_range.{u, u}
ext x
refine ⟨?_, fun hx => ⟨e ⟨x, hx⟩, ?_⟩⟩
· rintro ⟨a, rfl⟩
exact (e.symm a).2
· simp_rw [Equiv.symm_apply_apply]⟩
theorem bddAbove_of_small (s : Set Cardinal.{u}) [h : Small.{u} s] : BddAbove s :=
bddAbove_iff_small.2 h
theorem bddAbove_image (f : Cardinal.{u} → Cardinal.{max u v}) {s : Set Cardinal.{u}}
(hs : BddAbove s) : BddAbove (f '' s) := by
rw [bddAbove_iff_small] at hs ⊢
exact small_lift _
theorem bddAbove_range_comp {ι : Type u} {f : ι → Cardinal.{v}} (hf : BddAbove (range f))
(g : Cardinal.{v} → Cardinal.{max v w}) : BddAbove (range (g ∘ f)) := by
rw [range_comp]
exact bddAbove_image g hf
theorem iSup_le_sum {ι} (f : ι → Cardinal) : iSup f ≤ sum f :=
ciSup_le' <| le_sum _
theorem sum_le_iSup_lift {ι : Type u}
(f : ι → Cardinal.{max u v}) : sum f ≤ Cardinal.lift #ι * iSup f := by
rw [← (iSup f).lift_id, ← lift_umax, lift_umax.{max u v, u}, ← sum_const]
exact sum_le_sum _ _ (le_ciSup <| bddAbove_range f)
theorem sum_le_iSup {ι : Type u} (f : ι → Cardinal.{u}) : sum f ≤ #ι * iSup f := by
rw [← lift_id #ι]
exact sum_le_iSup_lift f
theorem sum_nat_eq_add_sum_succ (f : ℕ → Cardinal.{u}) :
Cardinal.sum f = f 0 + Cardinal.sum fun i => f (i + 1) := by
refine (Equiv.sigmaNatSucc fun i => Quotient.out (f i)).cardinal_eq.trans ?_
simp only [mk_sum, mk_out, lift_id, mk_sigma]
-- Porting note: LFS is not in normal form.
-- @[simp]
/-- A variant of `ciSup_of_empty` but with `0` on the RHS for convenience -/
protected theorem iSup_of_empty {ι} (f : ι → Cardinal) [IsEmpty ι] : iSup f = 0 :=
ciSup_of_empty f
lemma exists_eq_of_iSup_eq_of_not_isSuccLimit
{ι : Type u} (f : ι → Cardinal.{v}) (ω : Cardinal.{v})
(hω : ¬ Order.IsSuccLimit ω)
(h : ⨆ i : ι, f i = ω) : ∃ i, f i = ω := by
subst h
refine (isLUB_csSup' ?_).exists_of_not_isSuccLimit hω
contrapose! hω with hf
rw [iSup, csSup_of_not_bddAbove hf, csSup_empty]
exact Order.isSuccLimit_bot
lemma exists_eq_of_iSup_eq_of_not_isLimit
{ι : Type u} [hι : Nonempty ι] (f : ι → Cardinal.{v}) (hf : BddAbove (range f))
(ω : Cardinal.{v}) (hω : ¬ ω.IsLimit)
(h : ⨆ i : ι, f i = ω) : ∃ i, f i = ω := by
refine (not_and_or.mp hω).elim (fun e ↦ ⟨hι.some, ?_⟩)
(Cardinal.exists_eq_of_iSup_eq_of_not_isSuccLimit.{u, v} f ω · h)
cases not_not.mp e
rw [← le_zero_iff] at h ⊢
exact (le_ciSup hf _).trans h
-- Porting note: simpNF is not happy with universe levels.
@[simp, nolint simpNF]
theorem lift_mk_shrink (α : Type u) [Small.{v} α] :
Cardinal.lift.{max u w} #(Shrink.{v} α) = Cardinal.lift.{max v w} #α :=
lift_mk_eq.2 ⟨(equivShrink α).symm⟩
@[simp]
theorem lift_mk_shrink' (α : Type u) [Small.{v} α] :
Cardinal.lift.{u} #(Shrink.{v} α) = Cardinal.lift.{v} #α :=
lift_mk_shrink.{u, v, 0} α
@[simp]
theorem lift_mk_shrink'' (α : Type max u v) [Small.{v} α] :
Cardinal.lift.{u} #(Shrink.{v} α) = #α := by
rw [← lift_umax', lift_mk_shrink.{max u v, v, 0} α, ← lift_umax, lift_id]
/-- The indexed product of cardinals is the cardinality of the Pi type
(dependent product). -/
def prod {ι : Type u} (f : ι → Cardinal) : Cardinal :=
#(∀ i, (f i).out)
@[simp]
theorem mk_pi {ι : Type u} (α : ι → Type v) : #(∀ i, α i) = prod fun i => #(α i) :=
mk_congr <| Equiv.piCongrRight fun _ => outMkEquiv.symm
@[simp]
theorem prod_const (ι : Type u) (a : Cardinal.{v}) :
(prod fun _ : ι => a) = lift.{u} a ^ lift.{v} #ι :=
inductionOn a fun _ =>
mk_congr <| Equiv.piCongr Equiv.ulift.symm fun _ => outMkEquiv.trans Equiv.ulift.symm
theorem prod_const' (ι : Type u) (a : Cardinal.{u}) : (prod fun _ : ι => a) = a ^ #ι :=
inductionOn a fun _ => (mk_pi _).symm
theorem prod_le_prod {ι} (f g : ι → Cardinal) (H : ∀ i, f i ≤ g i) : prod f ≤ prod g :=
⟨Embedding.piCongrRight fun i =>
Classical.choice <| by have := H i; rwa [← mk_out (f i), ← mk_out (g i)] at this⟩
@[simp]
theorem prod_eq_zero {ι} (f : ι → Cardinal.{u}) : prod f = 0 ↔ ∃ i, f i = 0 := by
lift f to ι → Type u using fun _ => trivial
simp only [mk_eq_zero_iff, ← mk_pi, isEmpty_pi]
theorem prod_ne_zero {ι} (f : ι → Cardinal) : prod f ≠ 0 ↔ ∀ i, f i ≠ 0 := by simp [prod_eq_zero]
@[simp]
theorem lift_prod {ι : Type u} (c : ι → Cardinal.{v}) :
lift.{w} (prod c) = prod fun i => lift.{w} (c i) := by
lift c to ι → Type v using fun _ => trivial
simp only [← mk_pi, ← mk_uLift]
exact mk_congr (Equiv.ulift.trans <| Equiv.piCongrRight fun i => Equiv.ulift.symm)
theorem prod_eq_of_fintype {α : Type u} [h : Fintype α] (f : α → Cardinal.{v}) :
prod f = Cardinal.lift.{u} (∏ i, f i) := by
revert f
refine Fintype.induction_empty_option ?_ ?_ ?_ α (h_fintype := h)
· intro α β hβ e h f
letI := Fintype.ofEquiv β e.symm
rw [← e.prod_comp f, ← h]
exact mk_congr (e.piCongrLeft _).symm
· intro f
rw [Fintype.univ_pempty, Finset.prod_empty, lift_one, Cardinal.prod, mk_eq_one]
· intro α hα h f
rw [Cardinal.prod, mk_congr Equiv.piOptionEquivProd, mk_prod, lift_umax'.{v, u}, mk_out, ←
Cardinal.prod, lift_prod, Fintype.prod_option, lift_mul, ← h fun a => f (some a)]
simp only [lift_id]
@[simp]
theorem lift_sInf (s : Set Cardinal) : lift.{u, v} (sInf s) = sInf (lift.{u, v} '' s) := by
rcases eq_empty_or_nonempty s with (rfl | hs)
· simp
· exact lift_monotone.map_csInf hs
@[simp]
theorem lift_iInf {ι} (f : ι → Cardinal) : lift.{u, v} (iInf f) = ⨅ i, lift.{u, v} (f i) := by
unfold iInf
convert lift_sInf (range f)
simp_rw [← comp_apply (f := lift), range_comp]
theorem lift_down {a : Cardinal.{u}} {b : Cardinal.{max u v}} :
b ≤ lift.{v,u} a → ∃ a', lift.{v,u} a' = b :=
inductionOn₂ a b fun α β => by
rw [← lift_id #β, ← lift_umax, ← lift_umax.{u, v}, lift_mk_le.{v}]
exact fun ⟨f⟩ =>
⟨#(Set.range f),
Eq.symm <| lift_mk_eq.{_, _, v}.2
⟨Function.Embedding.equivOfSurjective (Embedding.codRestrict _ f Set.mem_range_self)
fun ⟨a, ⟨b, e⟩⟩ => ⟨b, Subtype.eq e⟩⟩⟩
theorem le_lift_iff {a : Cardinal.{u}} {b : Cardinal.{max u v}} :
b ≤ lift.{v, u} a ↔ ∃ a', lift.{v, u} a' = b ∧ a' ≤ a :=
⟨fun h =>
let ⟨a', e⟩ := lift_down h
⟨a', e, lift_le.1 <| e.symm ▸ h⟩,
fun ⟨_, e, h⟩ => e ▸ lift_le.2 h⟩
theorem lt_lift_iff {a : Cardinal.{u}} {b : Cardinal.{max u v}} :
b < lift.{v, u} a ↔ ∃ a', lift.{v, u} a' = b ∧ a' < a :=
⟨fun h =>
let ⟨a', e⟩ := lift_down h.le
⟨a', e, lift_lt.1 <| e.symm ▸ h⟩,
fun ⟨_, e, h⟩ => e ▸ lift_lt.2 h⟩
@[simp]
theorem lift_succ (a) : lift.{v, u} (succ a) = succ (lift.{v, u} a) :=
le_antisymm
(le_of_not_gt fun h => by
rcases lt_lift_iff.1 h with ⟨b, e, h⟩
rw [lt_succ_iff, ← lift_le, e] at h
exact h.not_lt (lt_succ _))
(succ_le_of_lt <| lift_lt.2 <| lt_succ a)
-- Porting note: simpNF is not happy with universe levels.
@[simp, nolint simpNF]
theorem lift_umax_eq {a : Cardinal.{u}} {b : Cardinal.{v}} :
lift.{max v w} a = lift.{max u w} b ↔ lift.{v} a = lift.{u} b := by
rw [← lift_lift.{v, w, u}, ← lift_lift.{u, w, v}, lift_inj]
@[simp]
theorem lift_min {a b : Cardinal} : lift.{u, v} (min a b) = min (lift.{u, v} a) (lift.{u, v} b) :=
lift_monotone.map_min
@[simp]
theorem lift_max {a b : Cardinal} : lift.{u, v} (max a b) = max (lift.{u, v} a) (lift.{u, v} b) :=
lift_monotone.map_max
/-- The lift of a supremum is the supremum of the lifts. -/
theorem lift_sSup {s : Set Cardinal} (hs : BddAbove s) :
lift.{u} (sSup s) = sSup (lift.{u} '' s) := by
apply ((le_csSup_iff' (bddAbove_image.{_,u} _ hs)).2 fun c hc => _).antisymm (csSup_le' _)
· intro c hc
by_contra h
obtain ⟨d, rfl⟩ := Cardinal.lift_down (not_le.1 h).le
simp_rw [lift_le] at h hc
rw [csSup_le_iff' hs] at h
exact h fun a ha => lift_le.1 <| hc (mem_image_of_mem _ ha)
· rintro i ⟨j, hj, rfl⟩
exact lift_le.2 (le_csSup hs hj)
/-- The lift of a supremum is the supremum of the lifts. -/
theorem lift_iSup {ι : Type v} {f : ι → Cardinal.{w}} (hf : BddAbove (range f)) :
lift.{u} (iSup f) = ⨆ i, lift.{u} (f i) := by
rw [iSup, iSup, lift_sSup hf, ← range_comp]
simp [Function.comp]
/-- To prove that the lift of a supremum is bounded by some cardinal `t`,
it suffices to show that the lift of each cardinal is bounded by `t`. -/
theorem lift_iSup_le {ι : Type v} {f : ι → Cardinal.{w}} {t : Cardinal} (hf : BddAbove (range f))
(w : ∀ i, lift.{u} (f i) ≤ t) : lift.{u} (iSup f) ≤ t := by
rw [lift_iSup hf]
exact ciSup_le' w
@[simp]
theorem lift_iSup_le_iff {ι : Type v} {f : ι → Cardinal.{w}} (hf : BddAbove (range f))
{t : Cardinal} : lift.{u} (iSup f) ≤ t ↔ ∀ i, lift.{u} (f i) ≤ t := by
rw [lift_iSup hf]
exact ciSup_le_iff' (bddAbove_range_comp.{_,_,u} hf _)
universe v' w'
/-- To prove an inequality between the lifts to a common universe of two different supremums,
it suffices to show that the lift of each cardinal from the smaller supremum
if bounded by the lift of some cardinal from the larger supremum.
-/
theorem lift_iSup_le_lift_iSup {ι : Type v} {ι' : Type v'} {f : ι → Cardinal.{w}}
{f' : ι' → Cardinal.{w'}} (hf : BddAbove (range f)) (hf' : BddAbove (range f')) {g : ι → ι'}
(h : ∀ i, lift.{w'} (f i) ≤ lift.{w} (f' (g i))) : lift.{w'} (iSup f) ≤ lift.{w} (iSup f') := by
rw [lift_iSup hf, lift_iSup hf']
exact ciSup_mono' (bddAbove_range_comp.{_,_,w} hf' _) fun i => ⟨_, h i⟩
/-- A variant of `lift_iSup_le_lift_iSup` with universes specialized via `w = v` and `w' = v'`.
This is sometimes necessary to avoid universe unification issues. -/
theorem lift_iSup_le_lift_iSup' {ι : Type v} {ι' : Type v'} {f : ι → Cardinal.{v}}
{f' : ι' → Cardinal.{v'}} (hf : BddAbove (range f)) (hf' : BddAbove (range f')) (g : ι → ι')
(h : ∀ i, lift.{v'} (f i) ≤ lift.{v} (f' (g i))) : lift.{v'} (iSup f) ≤ lift.{v} (iSup f') :=
lift_iSup_le_lift_iSup hf hf' h
/-- `ℵ₀` is the smallest infinite cardinal. -/
def aleph0 : Cardinal.{u} :=
lift #ℕ
@[inherit_doc]
scoped notation "ℵ₀" => Cardinal.aleph0
theorem mk_nat : #ℕ = ℵ₀ :=
(lift_id _).symm
theorem aleph0_ne_zero : ℵ₀ ≠ 0 :=
mk_ne_zero _
theorem aleph0_pos : 0 < ℵ₀ :=
pos_iff_ne_zero.2 aleph0_ne_zero
@[simp]
theorem lift_aleph0 : lift ℵ₀ = ℵ₀ :=
lift_lift _
@[simp]
theorem aleph0_le_lift {c : Cardinal.{u}} : ℵ₀ ≤ lift.{v} c ↔ ℵ₀ ≤ c := by
rw [← lift_aleph0.{v, u}, lift_le]
@[simp]
theorem lift_le_aleph0 {c : Cardinal.{u}} : lift.{v} c ≤ ℵ₀ ↔ c ≤ ℵ₀ := by
rw [← lift_aleph0.{v, u}, lift_le]
@[simp]
theorem aleph0_lt_lift {c : Cardinal.{u}} : ℵ₀ < lift.{v} c ↔ ℵ₀ < c := by
rw [← lift_aleph0.{v, u}, lift_lt]
@[simp]
theorem lift_lt_aleph0 {c : Cardinal.{u}} : lift.{v} c < ℵ₀ ↔ c < ℵ₀ := by
rw [← lift_aleph0.{v, u}, lift_lt]
/-! ### Properties about the cast from `ℕ` -/
section castFromN
-- porting note (#10618): simp can prove this
-- @[simp]
theorem mk_fin (n : ℕ) : #(Fin n) = n := by simp
@[simp]
theorem lift_natCast (n : ℕ) : lift.{u} (n : Cardinal.{v}) = n := by induction n <;> simp [*]
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem lift_ofNat (n : ℕ) [n.AtLeastTwo] :
lift.{u} (no_index (OfNat.ofNat n : Cardinal.{v})) = OfNat.ofNat n :=
lift_natCast n
@[simp]
theorem lift_eq_nat_iff {a : Cardinal.{u}} {n : ℕ} : lift.{v} a = n ↔ a = n :=
lift_injective.eq_iff' (lift_natCast n)
@[simp]
theorem lift_eq_ofNat_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] :
lift.{v} a = (no_index (OfNat.ofNat n)) ↔ a = OfNat.ofNat n :=
lift_eq_nat_iff
@[simp]
theorem nat_eq_lift_iff {n : ℕ} {a : Cardinal.{u}} :
(n : Cardinal) = lift.{v} a ↔ (n : Cardinal) = a := by
rw [← lift_natCast.{v,u} n, lift_inj]
@[simp]
theorem zero_eq_lift_iff {a : Cardinal.{u}} :
(0 : Cardinal) = lift.{v} a ↔ 0 = a := by
simpa using nat_eq_lift_iff (n := 0)
@[simp]
theorem one_eq_lift_iff {a : Cardinal.{u}} :
(1 : Cardinal) = lift.{v} a ↔ 1 = a := by
simpa using nat_eq_lift_iff (n := 1)
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem ofNat_eq_lift_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] :
(no_index (OfNat.ofNat n : Cardinal)) = lift.{v} a ↔ (OfNat.ofNat n : Cardinal) = a :=
nat_eq_lift_iff
@[simp]
theorem lift_le_nat_iff {a : Cardinal.{u}} {n : ℕ} : lift.{v} a ≤ n ↔ a ≤ n := by
rw [← lift_natCast.{v,u}, lift_le]
@[simp]
theorem lift_le_one_iff {a : Cardinal.{u}} :
lift.{v} a ≤ 1 ↔ a ≤ 1 := by
simpa using lift_le_nat_iff (n := 1)
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem lift_le_ofNat_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] :
lift.{v} a ≤ (no_index (OfNat.ofNat n)) ↔ a ≤ OfNat.ofNat n :=
lift_le_nat_iff
@[simp]
theorem nat_le_lift_iff {n : ℕ} {a : Cardinal.{u}} : n ≤ lift.{v} a ↔ n ≤ a := by
rw [← lift_natCast.{v,u}, lift_le]
@[simp]
theorem one_le_lift_iff {a : Cardinal.{u}} :
(1 : Cardinal) ≤ lift.{v} a ↔ 1 ≤ a := by
simpa using nat_le_lift_iff (n := 1)
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem ofNat_le_lift_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] :
(no_index (OfNat.ofNat n : Cardinal)) ≤ lift.{v} a ↔ (OfNat.ofNat n : Cardinal) ≤ a :=
nat_le_lift_iff
@[simp]
theorem lift_lt_nat_iff {a : Cardinal.{u}} {n : ℕ} : lift.{v} a < n ↔ a < n := by
rw [← lift_natCast.{v,u}, lift_lt]
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem lift_lt_ofNat_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] :
lift.{v} a < (no_index (OfNat.ofNat n)) ↔ a < OfNat.ofNat n :=
lift_lt_nat_iff
@[simp]
theorem nat_lt_lift_iff {n : ℕ} {a : Cardinal.{u}} : n < lift.{v} a ↔ n < a := by
rw [← lift_natCast.{v,u}, lift_lt]
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem zero_lt_lift_iff {a : Cardinal.{u}} :
(0 : Cardinal) < lift.{v} a ↔ 0 < a := by
simpa using nat_lt_lift_iff (n := 0)
@[simp]
theorem one_lt_lift_iff {a : Cardinal.{u}} :
(1 : Cardinal) < lift.{v} a ↔ 1 < a := by
simpa using nat_lt_lift_iff (n := 1)
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem ofNat_lt_lift_iff {a : Cardinal.{u}} {n : ℕ} [n.AtLeastTwo] :
(no_index (OfNat.ofNat n : Cardinal)) < lift.{v} a ↔ (OfNat.ofNat n : Cardinal) < a :=
nat_lt_lift_iff
theorem lift_mk_fin (n : ℕ) : lift #(Fin n) = n := rfl
theorem mk_coe_finset {α : Type u} {s : Finset α} : #s = ↑(Finset.card s) := by simp
theorem mk_finset_of_fintype [Fintype α] : #(Finset α) = 2 ^ Fintype.card α := by
simp [Pow.pow]
@[simp]
theorem mk_finsupp_lift_of_fintype (α : Type u) (β : Type v) [Fintype α] [Zero β] :
#(α →₀ β) = lift.{u} #β ^ Fintype.card α := by
simpa using (@Finsupp.equivFunOnFinite α β _ _).cardinal_eq
theorem mk_finsupp_of_fintype (α β : Type u) [Fintype α] [Zero β] :
#(α →₀ β) = #β ^ Fintype.card α := by simp
theorem card_le_of_finset {α} (s : Finset α) : (s.card : Cardinal) ≤ #α :=
@mk_coe_finset _ s ▸ mk_set_le _
-- Porting note: was `simp`. LHS is not normal form.
-- @[simp, norm_cast]
@[norm_cast]
theorem natCast_pow {m n : ℕ} : (↑(m ^ n) : Cardinal) = (↑m : Cardinal) ^ (↑n : Cardinal) := by
induction n <;> simp [pow_succ, power_add, *, Pow.pow]
-- porting note (#10618): simp can prove this
-- @[simp, norm_cast]
@[norm_cast]
theorem natCast_le {m n : ℕ} : (m : Cardinal) ≤ n ↔ m ≤ n := by
rw [← lift_mk_fin, ← lift_mk_fin, lift_le, le_def, Function.Embedding.nonempty_iff_card_le,
Fintype.card_fin, Fintype.card_fin]
-- porting note (#10618): simp can prove this
-- @[simp, norm_cast]
@[norm_cast]
theorem natCast_lt {m n : ℕ} : (m : Cardinal) < n ↔ m < n := by
rw [lt_iff_le_not_le, ← not_le]
simp only [natCast_le, not_le, and_iff_right_iff_imp]
exact fun h ↦ le_of_lt h
instance : CharZero Cardinal :=
⟨StrictMono.injective fun _ _ => natCast_lt.2⟩
theorem natCast_inj {m n : ℕ} : (m : Cardinal) = n ↔ m = n :=
Nat.cast_inj
theorem natCast_injective : Injective ((↑) : ℕ → Cardinal) :=
Nat.cast_injective
@[norm_cast]
theorem nat_succ (n : ℕ) : (n.succ : Cardinal) = succ ↑n := by
rw [Nat.cast_succ]
refine (add_one_le_succ _).antisymm (succ_le_of_lt ?_)
rw [← Nat.cast_succ]
exact natCast_lt.2 (Nat.lt_succ_self _)
lemma succ_natCast (n : ℕ) : Order.succ (n : Cardinal) = n + 1 := by
rw [← Cardinal.nat_succ]
norm_cast
lemma natCast_add_one_le_iff {n : ℕ} {c : Cardinal} : n + 1 ≤ c ↔ n < c := by
rw [← Order.succ_le_iff, Cardinal.succ_natCast]
lemma two_le_iff_one_lt {c : Cardinal} : 2 ≤ c ↔ 1 < c := by
convert natCast_add_one_le_iff
norm_cast
@[simp]
theorem succ_zero : succ (0 : Cardinal) = 1 := by norm_cast
theorem exists_finset_le_card (α : Type*) (n : ℕ) (h : n ≤ #α) :
∃ s : Finset α, n ≤ s.card := by
obtain hα|hα := finite_or_infinite α
· let hα := Fintype.ofFinite α
use Finset.univ
simpa only [mk_fintype, Nat.cast_le] using h
· obtain ⟨s, hs⟩ := Infinite.exists_subset_card_eq α n
exact ⟨s, hs.ge⟩
theorem card_le_of {α : Type u} {n : ℕ} (H : ∀ s : Finset α, s.card ≤ n) : #α ≤ n := by
contrapose! H
apply exists_finset_le_card α (n+1)
simpa only [nat_succ, succ_le_iff] using H
theorem cantor' (a) {b : Cardinal} (hb : 1 < b) : a < b ^ a := by
rw [← succ_le_iff, (by norm_cast : succ (1 : Cardinal) = 2)] at hb
exact (cantor a).trans_le (power_le_power_right hb)
theorem one_le_iff_pos {c : Cardinal} : 1 ≤ c ↔ 0 < c := by
rw [← succ_zero, succ_le_iff]
theorem one_le_iff_ne_zero {c : Cardinal} : 1 ≤ c ↔ c ≠ 0 := by
rw [one_le_iff_pos, pos_iff_ne_zero]
@[simp]
theorem lt_one_iff_zero {c : Cardinal} : c < 1 ↔ c = 0 := by
simpa using lt_succ_bot_iff (a := c)
theorem nat_lt_aleph0 (n : ℕ) : (n : Cardinal.{u}) < ℵ₀ :=
succ_le_iff.1
(by
rw [← nat_succ, ← lift_mk_fin, aleph0, lift_mk_le.{u}]
exact ⟨⟨(↑), fun a b => Fin.ext⟩⟩)
@[simp]
theorem one_lt_aleph0 : 1 < ℵ₀ := by simpa using nat_lt_aleph0 1
theorem one_le_aleph0 : 1 ≤ ℵ₀ :=
one_lt_aleph0.le
theorem lt_aleph0 {c : Cardinal} : c < ℵ₀ ↔ ∃ n : ℕ, c = n :=
⟨fun h => by
rcases lt_lift_iff.1 h with ⟨c, rfl, h'⟩
rcases le_mk_iff_exists_set.1 h'.1 with ⟨S, rfl⟩
suffices S.Finite by
lift S to Finset ℕ using this
simp
contrapose! h'
haveI := Infinite.to_subtype h'
exact ⟨Infinite.natEmbedding S⟩, fun ⟨n, e⟩ => e.symm ▸ nat_lt_aleph0 _⟩
lemma succ_eq_of_lt_aleph0 {c : Cardinal} (h : c < ℵ₀) : Order.succ c = c + 1 := by
obtain ⟨n, hn⟩ := Cardinal.lt_aleph0.mp h
rw [hn, succ_natCast]
theorem aleph0_le {c : Cardinal} : ℵ₀ ≤ c ↔ ∀ n : ℕ, ↑n ≤ c :=
⟨fun h n => (nat_lt_aleph0 _).le.trans h, fun h =>
le_of_not_lt fun hn => by
rcases lt_aleph0.1 hn with ⟨n, rfl⟩
exact (Nat.lt_succ_self _).not_le (natCast_le.1 (h (n + 1)))⟩
theorem isSuccLimit_aleph0 : IsSuccLimit ℵ₀ :=
isSuccLimit_of_succ_lt fun a ha => by
rcases lt_aleph0.1 ha with ⟨n, rfl⟩
rw [← nat_succ]
apply nat_lt_aleph0
theorem isLimit_aleph0 : IsLimit ℵ₀ :=
⟨aleph0_ne_zero, isSuccLimit_aleph0⟩
lemma not_isLimit_natCast : (n : ℕ) → ¬ IsLimit (n : Cardinal.{u})
| 0, e => e.1 rfl
| Nat.succ n, e => Order.not_isSuccLimit_succ _ (nat_succ n ▸ e.2)
theorem IsLimit.aleph0_le {c : Cardinal} (h : IsLimit c) : ℵ₀ ≤ c := by
by_contra! h'
rcases lt_aleph0.1 h' with ⟨n, rfl⟩
exact not_isLimit_natCast n h
lemma exists_eq_natCast_of_iSup_eq {ι : Type u} [Nonempty ι] (f : ι → Cardinal.{v})
(hf : BddAbove (range f)) (n : ℕ) (h : ⨆ i, f i = n) : ∃ i, f i = n :=
exists_eq_of_iSup_eq_of_not_isLimit.{u, v} f hf _ (not_isLimit_natCast n) h
@[simp]
theorem range_natCast : range ((↑) : ℕ → Cardinal) = Iio ℵ₀ :=
ext fun x => by simp only [mem_Iio, mem_range, eq_comm, lt_aleph0]
theorem mk_eq_nat_iff {α : Type u} {n : ℕ} : #α = n ↔ Nonempty (α ≃ Fin n) := by
rw [← lift_mk_fin, ← lift_uzero #α, lift_mk_eq']
theorem lt_aleph0_iff_finite {α : Type u} : #α < ℵ₀ ↔ Finite α := by
simp only [lt_aleph0, mk_eq_nat_iff, finite_iff_exists_equiv_fin]
theorem lt_aleph0_iff_fintype {α : Type u} : #α < ℵ₀ ↔ Nonempty (Fintype α) :=
lt_aleph0_iff_finite.trans (finite_iff_nonempty_fintype _)
theorem lt_aleph0_of_finite (α : Type u) [Finite α] : #α < ℵ₀ :=
lt_aleph0_iff_finite.2 ‹_›
-- porting note (#10618): simp can prove this
-- @[simp]
theorem lt_aleph0_iff_set_finite {S : Set α} : #S < ℵ₀ ↔ S.Finite :=
lt_aleph0_iff_finite.trans finite_coe_iff
alias ⟨_, _root_.Set.Finite.lt_aleph0⟩ := lt_aleph0_iff_set_finite
@[simp]
theorem lt_aleph0_iff_subtype_finite {p : α → Prop} : #{ x // p x } < ℵ₀ ↔ { x | p x }.Finite :=
lt_aleph0_iff_set_finite
theorem mk_le_aleph0_iff : #α ≤ ℵ₀ ↔ Countable α := by
rw [countable_iff_nonempty_embedding, aleph0, ← lift_uzero #α, lift_mk_le']
@[simp]
theorem mk_le_aleph0 [Countable α] : #α ≤ ℵ₀ :=
mk_le_aleph0_iff.mpr ‹_›
-- porting note (#10618): simp can prove this
-- @[simp]
theorem le_aleph0_iff_set_countable {s : Set α} : #s ≤ ℵ₀ ↔ s.Countable := mk_le_aleph0_iff
alias ⟨_, _root_.Set.Countable.le_aleph0⟩ := le_aleph0_iff_set_countable
@[simp]
theorem le_aleph0_iff_subtype_countable {p : α → Prop} :
#{ x // p x } ≤ ℵ₀ ↔ { x | p x }.Countable :=
le_aleph0_iff_set_countable
instance canLiftCardinalNat : CanLift Cardinal ℕ (↑) fun x => x < ℵ₀ :=
⟨fun _ hx =>
let ⟨n, hn⟩ := lt_aleph0.mp hx
⟨n, hn.symm⟩⟩
theorem add_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a + b < ℵ₀ :=
match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← Nat.cast_add]; apply nat_lt_aleph0
theorem add_lt_aleph0_iff {a b : Cardinal} : a + b < ℵ₀ ↔ a < ℵ₀ ∧ b < ℵ₀ :=
⟨fun h => ⟨(self_le_add_right _ _).trans_lt h, (self_le_add_left _ _).trans_lt h⟩,
fun ⟨h1, h2⟩ => add_lt_aleph0 h1 h2⟩
theorem aleph0_le_add_iff {a b : Cardinal} : ℵ₀ ≤ a + b ↔ ℵ₀ ≤ a ∨ ℵ₀ ≤ b := by
simp only [← not_lt, add_lt_aleph0_iff, not_and_or]
/-- See also `Cardinal.nsmul_lt_aleph0_iff_of_ne_zero` if you already have `n ≠ 0`. -/
theorem nsmul_lt_aleph0_iff {n : ℕ} {a : Cardinal} : n • a < ℵ₀ ↔ n = 0 ∨ a < ℵ₀ := by
cases n with
| zero => simpa using nat_lt_aleph0 0
| succ n =>
simp only [Nat.succ_ne_zero, false_or_iff]
induction' n with n ih
· simp
rw [succ_nsmul, add_lt_aleph0_iff, ih, and_self_iff]
/-- See also `Cardinal.nsmul_lt_aleph0_iff` for a hypothesis-free version. -/
theorem nsmul_lt_aleph0_iff_of_ne_zero {n : ℕ} {a : Cardinal} (h : n ≠ 0) : n • a < ℵ₀ ↔ a < ℵ₀ :=
nsmul_lt_aleph0_iff.trans <| or_iff_right h
theorem mul_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a * b < ℵ₀ :=
match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← Nat.cast_mul]; apply nat_lt_aleph0
theorem mul_lt_aleph0_iff {a b : Cardinal} : a * b < ℵ₀ ↔ a = 0 ∨ b = 0 ∨ a < ℵ₀ ∧ b < ℵ₀ := by
refine ⟨fun h => ?_, ?_⟩
· by_cases ha : a = 0
· exact Or.inl ha
right
by_cases hb : b = 0
· exact Or.inl hb
right
rw [← Ne, ← one_le_iff_ne_zero] at ha hb
constructor
· rw [← mul_one a]
exact (mul_le_mul' le_rfl hb).trans_lt h
· rw [← one_mul b]
exact (mul_le_mul' ha le_rfl).trans_lt h
rintro (rfl | rfl | ⟨ha, hb⟩) <;> simp only [*, mul_lt_aleph0, aleph0_pos, zero_mul, mul_zero]
/-- See also `Cardinal.aleph0_le_mul_iff`. -/
theorem aleph0_le_mul_iff {a b : Cardinal} : ℵ₀ ≤ a * b ↔ a ≠ 0 ∧ b ≠ 0 ∧ (ℵ₀ ≤ a ∨ ℵ₀ ≤ b) := by
let h := (@mul_lt_aleph0_iff a b).not
rwa [not_lt, not_or, not_or, not_and_or, not_lt, not_lt] at h
/-- See also `Cardinal.aleph0_le_mul_iff'`. -/
theorem aleph0_le_mul_iff' {a b : Cardinal.{u}} : ℵ₀ ≤ a * b ↔ a ≠ 0 ∧ ℵ₀ ≤ b ∨ ℵ₀ ≤ a ∧ b ≠ 0 := by
have : ∀ {a : Cardinal.{u}}, ℵ₀ ≤ a → a ≠ 0 := fun a => ne_bot_of_le_ne_bot aleph0_ne_zero a
simp only [aleph0_le_mul_iff, and_or_left, and_iff_right_of_imp this, @and_left_comm (a ≠ 0)]
simp only [and_comm, or_comm]
theorem mul_lt_aleph0_iff_of_ne_zero {a b : Cardinal} (ha : a ≠ 0) (hb : b ≠ 0) :
a * b < ℵ₀ ↔ a < ℵ₀ ∧ b < ℵ₀ := by simp [mul_lt_aleph0_iff, ha, hb]
theorem power_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a ^ b < ℵ₀ :=
match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← natCast_pow]; apply nat_lt_aleph0
theorem eq_one_iff_unique {α : Type*} : #α = 1 ↔ Subsingleton α ∧ Nonempty α :=
calc
#α = 1 ↔ #α ≤ 1 ∧ 1 ≤ #α := le_antisymm_iff
_ ↔ Subsingleton α ∧ Nonempty α :=
le_one_iff_subsingleton.and (one_le_iff_ne_zero.trans mk_ne_zero_iff)
theorem infinite_iff {α : Type u} : Infinite α ↔ ℵ₀ ≤ #α := by
rw [← not_lt, lt_aleph0_iff_finite, not_finite_iff_infinite]
lemma aleph0_le_mk_iff : ℵ₀ ≤ #α ↔ Infinite α := infinite_iff.symm
lemma mk_lt_aleph0_iff : #α < ℵ₀ ↔ Finite α := by simp [← not_le, aleph0_le_mk_iff]
@[simp]
theorem aleph0_le_mk (α : Type u) [Infinite α] : ℵ₀ ≤ #α :=
infinite_iff.1 ‹_›
@[simp]
theorem mk_eq_aleph0 (α : Type*) [Countable α] [Infinite α] : #α = ℵ₀ :=
mk_le_aleph0.antisymm <| aleph0_le_mk _
theorem denumerable_iff {α : Type u} : Nonempty (Denumerable α) ↔ #α = ℵ₀ :=
⟨fun ⟨h⟩ => mk_congr ((@Denumerable.eqv α h).trans Equiv.ulift.symm), fun h => by
cases' Quotient.exact h with f
exact ⟨Denumerable.mk' <| f.trans Equiv.ulift⟩⟩
-- porting note (#10618): simp can prove this
-- @[simp]
theorem mk_denumerable (α : Type u) [Denumerable α] : #α = ℵ₀ :=
denumerable_iff.1 ⟨‹_›⟩
theorem _root_.Set.countable_infinite_iff_nonempty_denumerable {α : Type*} {s : Set α} :
s.Countable ∧ s.Infinite ↔ Nonempty (Denumerable s) := by
rw [nonempty_denumerable_iff, ← Set.infinite_coe_iff, countable_coe_iff]
@[simp]
theorem aleph0_add_aleph0 : ℵ₀ + ℵ₀ = ℵ₀ :=
mk_denumerable _
theorem aleph0_mul_aleph0 : ℵ₀ * ℵ₀ = ℵ₀ :=
mk_denumerable _
@[simp]
theorem nat_mul_aleph0 {n : ℕ} (hn : n ≠ 0) : ↑n * ℵ₀ = ℵ₀ :=
le_antisymm (lift_mk_fin n ▸ mk_le_aleph0) <|
le_mul_of_one_le_left (zero_le _) <| by
rwa [← Nat.cast_one, natCast_le, Nat.one_le_iff_ne_zero]
@[simp]
theorem aleph0_mul_nat {n : ℕ} (hn : n ≠ 0) : ℵ₀ * n = ℵ₀ := by rw [mul_comm, nat_mul_aleph0 hn]
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem ofNat_mul_aleph0 {n : ℕ} [Nat.AtLeastTwo n] : no_index (OfNat.ofNat n) * ℵ₀ = ℵ₀ :=
nat_mul_aleph0 (NeZero.ne n)
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem aleph0_mul_ofNat {n : ℕ} [Nat.AtLeastTwo n] : ℵ₀ * no_index (OfNat.ofNat n) = ℵ₀ :=
aleph0_mul_nat (NeZero.ne n)
@[simp]
theorem add_le_aleph0 {c₁ c₂ : Cardinal} : c₁ + c₂ ≤ ℵ₀ ↔ c₁ ≤ ℵ₀ ∧ c₂ ≤ ℵ₀ :=
⟨fun h => ⟨le_self_add.trans h, le_add_self.trans h⟩, fun h =>
aleph0_add_aleph0 ▸ add_le_add h.1 h.2⟩
@[simp]
theorem aleph0_add_nat (n : ℕ) : ℵ₀ + n = ℵ₀ :=
(add_le_aleph0.2 ⟨le_rfl, (nat_lt_aleph0 n).le⟩).antisymm le_self_add
@[simp]
theorem nat_add_aleph0 (n : ℕ) : ↑n + ℵ₀ = ℵ₀ := by rw [add_comm, aleph0_add_nat]
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem ofNat_add_aleph0 {n : ℕ} [Nat.AtLeastTwo n] : no_index (OfNat.ofNat n) + ℵ₀ = ℵ₀ :=
nat_add_aleph0 n
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem aleph0_add_ofNat {n : ℕ} [Nat.AtLeastTwo n] : ℵ₀ + no_index (OfNat.ofNat n) = ℵ₀ :=
aleph0_add_nat n
theorem exists_nat_eq_of_le_nat {c : Cardinal} {n : ℕ} (h : c ≤ n) : ∃ m, m ≤ n ∧ c = m := by
lift c to ℕ using h.trans_lt (nat_lt_aleph0 _)
exact ⟨c, mod_cast h, rfl⟩
theorem mk_int : #ℤ = ℵ₀ :=
mk_denumerable ℤ
theorem mk_pNat : #ℕ+ = ℵ₀ :=
mk_denumerable ℕ+
end castFromN
variable {c : Cardinal}
/-- **König's theorem** -/
theorem sum_lt_prod {ι} (f g : ι → Cardinal) (H : ∀ i, f i < g i) : sum f < prod g :=
lt_of_not_ge fun ⟨F⟩ => by
have : Inhabited (∀ i : ι, (g i).out) := by
refine ⟨fun i => Classical.choice <| mk_ne_zero_iff.1 ?_⟩
rw [mk_out]
exact (H i).ne_bot
let G := invFun F
have sG : Surjective G := invFun_surjective F.2
choose C hc using
show ∀ i, ∃ b, ∀ a, G ⟨i, a⟩ i ≠ b by
intro i
simp only [not_exists.symm, not_forall.symm]
refine fun h => (H i).not_le ?_
rw [← mk_out (f i), ← mk_out (g i)]
exact ⟨Embedding.ofSurjective _ h⟩
let ⟨⟨i, a⟩, h⟩ := sG C
exact hc i a (congr_fun h _)
/-! Cardinalities of sets: cardinality of empty, finite sets, unions, subsets etc. -/
section sets
-- porting note (#10618): simp can prove this
-- @[simp]
theorem mk_empty : #Empty = 0 :=
mk_eq_zero _
-- porting note (#10618): simp can prove this
-- @[simp]
theorem mk_pempty : #PEmpty = 0 :=
mk_eq_zero _
-- porting note (#10618): simp can prove this
-- @[simp]
theorem mk_punit : #PUnit = 1 :=
mk_eq_one PUnit
theorem mk_unit : #Unit = 1 :=
mk_punit
-- porting note (#10618): simp can prove this
-- @[simp]
theorem mk_singleton {α : Type u} (x : α) : #({x} : Set α) = 1 :=
mk_eq_one _
-- porting note (#10618): simp can prove this
-- @[simp]
theorem mk_plift_true : #(PLift True) = 1 :=
mk_eq_one _
-- porting note (#10618): simp can prove this
-- @[simp]
theorem mk_plift_false : #(PLift False) = 0 :=
mk_eq_zero _
@[simp]
theorem mk_vector (α : Type u) (n : ℕ) : #(Vector α n) = #α ^ n :=
(mk_congr (Equiv.vectorEquivFin α n)).trans <| by simp
theorem mk_list_eq_sum_pow (α : Type u) : #(List α) = sum fun n : ℕ => #α ^ n :=
calc
#(List α) = #(Σn, Vector α n) := mk_congr (Equiv.sigmaFiberEquiv List.length).symm
_ = sum fun n : ℕ => #α ^ n := by simp
theorem mk_quot_le {α : Type u} {r : α → α → Prop} : #(Quot r) ≤ #α :=
mk_le_of_surjective Quot.exists_rep
theorem mk_quotient_le {α : Type u} {s : Setoid α} : #(Quotient s) ≤ #α :=
mk_quot_le
theorem mk_subtype_le_of_subset {α : Type u} {p q : α → Prop} (h : ∀ ⦃x⦄, p x → q x) :
#(Subtype p) ≤ #(Subtype q) :=
⟨Embedding.subtypeMap (Embedding.refl α) h⟩
-- porting note (#10618): simp can prove this
-- @[simp]
theorem mk_emptyCollection (α : Type u) : #(∅ : Set α) = 0 :=
mk_eq_zero _
theorem mk_emptyCollection_iff {α : Type u} {s : Set α} : #s = 0 ↔ s = ∅ := by
constructor
· intro h
rw [mk_eq_zero_iff] at h
exact eq_empty_iff_forall_not_mem.2 fun x hx => h.elim' ⟨x, hx⟩
· rintro rfl
exact mk_emptyCollection _
@[simp]
theorem mk_univ {α : Type u} : #(@univ α) = #α :=
mk_congr (Equiv.Set.univ α)
theorem mk_image_le {α β : Type u} {f : α → β} {s : Set α} : #(f '' s) ≤ #s :=
mk_le_of_surjective surjective_onto_image
theorem mk_image_le_lift {α : Type u} {β : Type v} {f : α → β} {s : Set α} :
lift.{u} #(f '' s) ≤ lift.{v} #s :=
lift_mk_le.{0}.mpr ⟨Embedding.ofSurjective _ surjective_onto_image⟩
theorem mk_range_le {α β : Type u} {f : α → β} : #(range f) ≤ #α :=
mk_le_of_surjective surjective_onto_range
theorem mk_range_le_lift {α : Type u} {β : Type v} {f : α → β} :
lift.{u} #(range f) ≤ lift.{v} #α :=
lift_mk_le.{0}.mpr ⟨Embedding.ofSurjective _ surjective_onto_range⟩
theorem mk_range_eq (f : α → β) (h : Injective f) : #(range f) = #α :=
mk_congr (Equiv.ofInjective f h).symm
theorem mk_range_eq_lift {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) :
lift.{max u w} #(range f) = lift.{max v w} #α :=
lift_mk_eq.{v,u,w}.mpr ⟨(Equiv.ofInjective f hf).symm⟩
theorem mk_range_eq_of_injective {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) :
lift.{u} #(range f) = lift.{v} #α :=
lift_mk_eq'.mpr ⟨(Equiv.ofInjective f hf).symm⟩
lemma lift_mk_le_lift_mk_of_injective {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) :
Cardinal.lift.{v} (#α) ≤ Cardinal.lift.{u} (#β) := by
rw [← Cardinal.mk_range_eq_of_injective hf]
exact Cardinal.lift_le.2 (Cardinal.mk_set_le _)
lemma lift_mk_le_lift_mk_of_surjective {α : Type u} {β : Type v} {f : α → β} (hf : Surjective f) :
Cardinal.lift.{u} (#β) ≤ Cardinal.lift.{v} (#α) :=
lift_mk_le_lift_mk_of_injective (injective_surjInv hf)
theorem mk_image_eq_of_injOn {α β : Type u} (f : α → β) (s : Set α) (h : InjOn f s) :
#(f '' s) = #s :=
mk_congr (Equiv.Set.imageOfInjOn f s h).symm
theorem mk_image_eq_of_injOn_lift {α : Type u} {β : Type v} (f : α → β) (s : Set α)
(h : InjOn f s) : lift.{u} #(f '' s) = lift.{v} #s :=
lift_mk_eq.{v, u, 0}.mpr ⟨(Equiv.Set.imageOfInjOn f s h).symm⟩
theorem mk_image_eq {α β : Type u} {f : α → β} {s : Set α} (hf : Injective f) : #(f '' s) = #s :=
mk_image_eq_of_injOn _ _ hf.injOn
theorem mk_image_eq_lift {α : Type u} {β : Type v} (f : α → β) (s : Set α) (h : Injective f) :
lift.{u} #(f '' s) = lift.{v} #s :=
mk_image_eq_of_injOn_lift _ _ h.injOn
theorem mk_iUnion_le_sum_mk {α ι : Type u} {f : ι → Set α} : #(⋃ i, f i) ≤ sum fun i => #(f i) :=
calc
#(⋃ i, f i) ≤ #(Σi, f i) := mk_le_of_surjective (Set.sigmaToiUnion_surjective f)
_ = sum fun i => #(f i) := mk_sigma _
theorem mk_iUnion_le_sum_mk_lift {α : Type u} {ι : Type v} {f : ι → Set α} :
lift.{v} #(⋃ i, f i) ≤ sum fun i => #(f i) :=
calc
lift.{v} #(⋃ i, f i) ≤ #(Σi, f i) :=
mk_le_of_surjective <| ULift.up_surjective.comp (Set.sigmaToiUnion_surjective f)
_ = sum fun i => #(f i) := mk_sigma _
theorem mk_iUnion_eq_sum_mk {α ι : Type u} {f : ι → Set α}
(h : Pairwise fun i j => Disjoint (f i) (f j)) : #(⋃ i, f i) = sum fun i => #(f i) :=
calc
#(⋃ i, f i) = #(Σi, f i) := mk_congr (Set.unionEqSigmaOfDisjoint h)
_ = sum fun i => #(f i) := mk_sigma _
theorem mk_iUnion_eq_sum_mk_lift {α : Type u} {ι : Type v} {f : ι → Set α}
(h : Pairwise fun i j => Disjoint (f i) (f j)) :
lift.{v} #(⋃ i, f i) = sum fun i => #(f i) :=
calc
lift.{v} #(⋃ i, f i) = #(Σi, f i) :=
mk_congr <| .trans Equiv.ulift (Set.unionEqSigmaOfDisjoint h)
_ = sum fun i => #(f i) := mk_sigma _
theorem mk_iUnion_le {α ι : Type u} (f : ι → Set α) : #(⋃ i, f i) ≤ #ι * ⨆ i, #(f i) :=
mk_iUnion_le_sum_mk.trans (sum_le_iSup _)
theorem mk_iUnion_le_lift {α : Type u} {ι : Type v} (f : ι → Set α) :
lift.{v} #(⋃ i, f i) ≤ lift.{u} #ι * ⨆ i, lift.{v} #(f i) := by
refine mk_iUnion_le_sum_mk_lift.trans <| Eq.trans_le ?_ (sum_le_iSup_lift _)
rw [← lift_sum, lift_id'.{_,u}]
theorem mk_sUnion_le {α : Type u} (A : Set (Set α)) : #(⋃₀ A) ≤ #A * ⨆ s : A, #s := by
rw [sUnion_eq_iUnion]
apply mk_iUnion_le
theorem mk_biUnion_le {ι α : Type u} (A : ι → Set α) (s : Set ι) :
#(⋃ x ∈ s, A x) ≤ #s * ⨆ x : s, #(A x.1) := by
rw [biUnion_eq_iUnion]
apply mk_iUnion_le
theorem mk_biUnion_le_lift {α : Type u} {ι : Type v} (A : ι → Set α) (s : Set ι) :
lift.{v} #(⋃ x ∈ s, A x) ≤ lift.{u} #s * ⨆ x : s, lift.{v} #(A x.1) := by
rw [biUnion_eq_iUnion]
apply mk_iUnion_le_lift
theorem finset_card_lt_aleph0 (s : Finset α) : #(↑s : Set α) < ℵ₀ :=
lt_aleph0_of_finite _
theorem mk_set_eq_nat_iff_finset {α} {s : Set α} {n : ℕ} :
#s = n ↔ ∃ t : Finset α, (t : Set α) = s ∧ t.card = n := by
constructor
· intro h
lift s to Finset α using lt_aleph0_iff_set_finite.1 (h.symm ▸ nat_lt_aleph0 n)
simpa using h
· rintro ⟨t, rfl, rfl⟩
exact mk_coe_finset
theorem mk_eq_nat_iff_finset {n : ℕ} :
#α = n ↔ ∃ t : Finset α, (t : Set α) = univ ∧ t.card = n := by
rw [← mk_univ, mk_set_eq_nat_iff_finset]
theorem mk_eq_nat_iff_fintype {n : ℕ} : #α = n ↔ ∃ h : Fintype α, @Fintype.card α h = n := by
rw [mk_eq_nat_iff_finset]
constructor
· rintro ⟨t, ht, hn⟩
exact ⟨⟨t, eq_univ_iff_forall.1 ht⟩, hn⟩
· rintro ⟨⟨t, ht⟩, hn⟩
exact ⟨t, eq_univ_iff_forall.2 ht, hn⟩
theorem mk_union_add_mk_inter {α : Type u} {S T : Set α} :
#(S ∪ T : Set α) + #(S ∩ T : Set α) = #S + #T :=
Quot.sound ⟨Equiv.Set.unionSumInter S T⟩
/-- The cardinality of a union is at most the sum of the cardinalities
of the two sets. -/
theorem mk_union_le {α : Type u} (S T : Set α) : #(S ∪ T : Set α) ≤ #S + #T :=
@mk_union_add_mk_inter α S T ▸ self_le_add_right #(S ∪ T : Set α) #(S ∩ T : Set α)
theorem mk_union_of_disjoint {α : Type u} {S T : Set α} (H : Disjoint S T) :
#(S ∪ T : Set α) = #S + #T :=
Quot.sound ⟨Equiv.Set.union H.le_bot⟩
theorem mk_insert {α : Type u} {s : Set α} {a : α} (h : a ∉ s) :
#(insert a s : Set α) = #s + 1 := by
rw [← union_singleton, mk_union_of_disjoint, mk_singleton]
simpa
theorem mk_insert_le {α : Type u} {s : Set α} {a : α} : #(insert a s : Set α) ≤ #s + 1 := by
by_cases h : a ∈ s
· simp only [insert_eq_of_mem h, self_le_add_right]
· rw [mk_insert h]
theorem mk_sum_compl {α} (s : Set α) : #s + #(sᶜ : Set α) = #α :=
mk_congr (Equiv.Set.sumCompl s)
theorem mk_le_mk_of_subset {α} {s t : Set α} (h : s ⊆ t) : #s ≤ #t :=
⟨Set.embeddingOfSubset s t h⟩
theorem mk_le_iff_forall_finset_subset_card_le {α : Type u} {n : ℕ} {t : Set α} :
#t ≤ n ↔ ∀ s : Finset α, (s : Set α) ⊆ t → s.card ≤ n := by
refine ⟨fun H s hs ↦ by simpa using (mk_le_mk_of_subset hs).trans H, fun H ↦ ?_⟩
apply card_le_of (fun s ↦ ?_)
let u : Finset α := s.image Subtype.val
have : u.card = s.card := Finset.card_image_of_injOn Subtype.coe_injective.injOn
rw [← this]
apply H
simp only [u, Finset.coe_image, image_subset_iff, Subtype.coe_preimage_self, subset_univ]
theorem mk_subtype_mono {p q : α → Prop} (h : ∀ x, p x → q x) :
#{ x // p x } ≤ #{ x // q x } :=
⟨embeddingOfSubset _ _ h⟩
theorem le_mk_diff_add_mk (S T : Set α) : #S ≤ #(S \ T : Set α) + #T :=
(mk_le_mk_of_subset <| subset_diff_union _ _).trans <| mk_union_le _ _
theorem mk_diff_add_mk {S T : Set α} (h : T ⊆ S) : #(S \ T : Set α) + #T = #S := by
refine (mk_union_of_disjoint <| ?_).symm.trans <| by rw [diff_union_of_subset h]
exact disjoint_sdiff_self_left
theorem mk_union_le_aleph0 {α} {P Q : Set α} :
#(P ∪ Q : Set α) ≤ ℵ₀ ↔ #P ≤ ℵ₀ ∧ #Q ≤ ℵ₀ := by
simp only [le_aleph0_iff_subtype_countable, mem_union, setOf_mem_eq, Set.union_def,
← countable_union]
theorem mk_subtype_of_equiv {α β : Type u} (p : β → Prop) (e : α ≃ β) :
#{ a : α // p (e a) } = #{ b : β // p b } :=
mk_congr (Equiv.subtypeEquivOfSubtype e)
theorem mk_sep (s : Set α) (t : α → Prop) : #({ x ∈ s | t x } : Set α) = #{ x : s | t x.1 } :=
mk_congr (Equiv.Set.sep s t)
theorem mk_preimage_of_injective_lift {α : Type u} {β : Type v} (f : α → β) (s : Set β)
(h : Injective f) : lift.{v} #(f ⁻¹' s) ≤ lift.{u} #s := by
rw [lift_mk_le.{0}]
-- Porting note: Needed to insert `mem_preimage.mp` below
use Subtype.coind (fun x => f x.1) fun x => mem_preimage.mp x.2
apply Subtype.coind_injective; exact h.comp Subtype.val_injective
theorem mk_preimage_of_subset_range_lift {α : Type u} {β : Type v} (f : α → β) (s : Set β)
(h : s ⊆ range f) : lift.{u} #s ≤ lift.{v} #(f ⁻¹' s) := by
rw [← image_preimage_eq_iff] at h
nth_rewrite 1 [← h]
apply mk_image_le_lift
theorem mk_preimage_of_injective_of_subset_range_lift {β : Type v} (f : α → β) (s : Set β)
(h : Injective f) (h2 : s ⊆ range f) : lift.{v} #(f ⁻¹' s) = lift.{u} #s :=
le_antisymm (mk_preimage_of_injective_lift f s h) (mk_preimage_of_subset_range_lift f s h2)
theorem mk_preimage_of_injective_of_subset_range (f : α → β) (s : Set β) (h : Injective f)
(h2 : s ⊆ range f) : #(f ⁻¹' s) = #s := by
convert mk_preimage_of_injective_of_subset_range_lift.{u, u} f s h h2 using 1 <;> rw [lift_id]
theorem mk_preimage_of_injective (f : α → β) (s : Set β) (h : Injective f) :
#(f ⁻¹' s) ≤ #s := by
rw [← lift_id #(↑(f ⁻¹' s)), ← lift_id #(↑s)]
exact mk_preimage_of_injective_lift f s h
theorem mk_preimage_of_subset_range (f : α → β) (s : Set β) (h : s ⊆ range f) :
#s ≤ #(f ⁻¹' s) := by
rw [← lift_id #(↑(f ⁻¹' s)), ← lift_id #(↑s)]
exact mk_preimage_of_subset_range_lift f s h
theorem mk_subset_ge_of_subset_image_lift {α : Type u} {β : Type v} (f : α → β) {s : Set α}
{t : Set β} (h : t ⊆ f '' s) : lift.{u} #t ≤ lift.{v} #({ x ∈ s | f x ∈ t } : Set α) := by
rw [image_eq_range] at h
convert mk_preimage_of_subset_range_lift _ _ h using 1
rw [mk_sep]
rfl
theorem mk_subset_ge_of_subset_image (f : α → β) {s : Set α} {t : Set β} (h : t ⊆ f '' s) :
#t ≤ #({ x ∈ s | f x ∈ t } : Set α) := by
rw [image_eq_range] at h
convert mk_preimage_of_subset_range _ _ h using 1
rw [mk_sep]
rfl
theorem le_mk_iff_exists_subset {c : Cardinal} {α : Type u} {s : Set α} :
c ≤ #s ↔ ∃ p : Set α, p ⊆ s ∧ #p = c := by
rw [le_mk_iff_exists_set, ← Subtype.exists_set_subtype]
apply exists_congr; intro t; rw [mk_image_eq]; apply Subtype.val_injective
theorem two_le_iff : (2 : Cardinal) ≤ #α ↔ ∃ x y : α, x ≠ y := by
rw [← Nat.cast_two, nat_succ, succ_le_iff, Nat.cast_one, one_lt_iff_nontrivial, nontrivial_iff]
theorem two_le_iff' (x : α) : (2 : Cardinal) ≤ #α ↔ ∃ y : α, y ≠ x := by
rw [two_le_iff, ← nontrivial_iff, nontrivial_iff_exists_ne x]
theorem mk_eq_two_iff : #α = 2 ↔ ∃ x y : α, x ≠ y ∧ ({x, y} : Set α) = univ := by
simp only [← @Nat.cast_two Cardinal, mk_eq_nat_iff_finset, Finset.card_eq_two]
constructor
· rintro ⟨t, ht, x, y, hne, rfl⟩
exact ⟨x, y, hne, by simpa using ht⟩
· rintro ⟨x, y, hne, h⟩
exact ⟨{x, y}, by simpa using h, x, y, hne, rfl⟩
theorem mk_eq_two_iff' (x : α) : #α = 2 ↔ ∃! y, y ≠ x := by
rw [mk_eq_two_iff]; constructor
· rintro ⟨a, b, hne, h⟩
simp only [eq_univ_iff_forall, mem_insert_iff, mem_singleton_iff] at h
rcases h x with (rfl | rfl)
exacts [⟨b, hne.symm, fun z => (h z).resolve_left⟩, ⟨a, hne, fun z => (h z).resolve_right⟩]
· rintro ⟨y, hne, hy⟩
exact ⟨x, y, hne.symm, eq_univ_of_forall fun z => or_iff_not_imp_left.2 (hy z)⟩
theorem exists_not_mem_of_length_lt {α : Type*} (l : List α) (h : ↑l.length < #α) :
∃ z : α, z ∉ l := by
contrapose! h
calc
#α = #(Set.univ : Set α) := mk_univ.symm
_ ≤ #l.toFinset := mk_le_mk_of_subset fun x _ => List.mem_toFinset.mpr (h x)
_ = l.toFinset.card := Cardinal.mk_coe_finset
_ ≤ l.length := Cardinal.natCast_le.mpr (List.toFinset_card_le l)
theorem three_le {α : Type*} (h : 3 ≤ #α) (x : α) (y : α) : ∃ z : α, z ≠ x ∧ z ≠ y := by
have : ↑(3 : ℕ) ≤ #α := by simpa using h
have : ↑(2 : ℕ) < #α := by rwa [← succ_le_iff, ← Cardinal.nat_succ]
have := exists_not_mem_of_length_lt [x, y] this
simpa [not_or] using this
end sets
section powerlt
/-- The function `a ^< b`, defined as the supremum of `a ^ c` for `c < b`. -/
def powerlt (a b : Cardinal.{u}) : Cardinal.{u} :=
⨆ c : Iio b, a ^ (c : Cardinal)
@[inherit_doc]
infixl:80 " ^< " => powerlt
theorem le_powerlt {b c : Cardinal.{u}} (a) (h : c < b) : (a^c) ≤ a ^< b := by
refine le_ciSup (f := fun y : Iio b => a ^ (y : Cardinal)) ?_ ⟨c, h⟩
rw [← image_eq_range]
exact bddAbove_image.{u, u} _ bddAbove_Iio
theorem powerlt_le {a b c : Cardinal.{u}} : a ^< b ≤ c ↔ ∀ x < b, a ^ x ≤ c := by
rw [powerlt, ciSup_le_iff']
· simp
· rw [← image_eq_range]
exact bddAbove_image.{u, u} _ bddAbove_Iio
theorem powerlt_le_powerlt_left {a b c : Cardinal} (h : b ≤ c) : a ^< b ≤ a ^< c :=
powerlt_le.2 fun _ hx => le_powerlt a <| hx.trans_le h
theorem powerlt_mono_left (a) : Monotone fun c => a ^< c := fun _ _ => powerlt_le_powerlt_left
theorem powerlt_succ {a b : Cardinal} (h : a ≠ 0) : a ^< succ b = a ^ b :=
(powerlt_le.2 fun _ h' => power_le_power_left h <| le_of_lt_succ h').antisymm <|
le_powerlt a (lt_succ b)
theorem powerlt_min {a b c : Cardinal} : a ^< min b c = min (a ^< b) (a ^< c) :=
(powerlt_mono_left a).map_min
theorem powerlt_max {a b c : Cardinal} : a ^< max b c = max (a ^< b) (a ^< c) :=
(powerlt_mono_left a).map_max
theorem zero_powerlt {a : Cardinal} (h : a ≠ 0) : 0 ^< a = 1 := by
apply (powerlt_le.2 fun c _ => zero_power_le _).antisymm
rw [← power_zero]
exact le_powerlt 0 (pos_iff_ne_zero.2 h)
@[simp]
theorem powerlt_zero {a : Cardinal} : a ^< 0 = 0 := by
convert Cardinal.iSup_of_empty _
exact Subtype.isEmpty_of_false fun x => mem_Iio.not.mpr (Cardinal.zero_le x).not_lt
end powerlt
end Cardinal
-- namespace Tactic
-- open Cardinal Positivity
-- Porting note: Meta code, do not port directly
-- /-- Extension for the `positivity` tactic: The cardinal power of a positive cardinal is
-- positive. -/
-- @[positivity]
-- unsafe def positivity_cardinal_pow : expr → tactic strictness
-- | q(@Pow.pow _ _ $(inst) $(a) $(b)) => do
-- let strictness_a ← core a
-- match strictness_a with
-- | positive p => positive <$> mk_app `` power_pos [b, p]
-- | _ => failed
-- |-- We already know that `0 ≤ x` for all `x : Cardinal`
-- _ =>
-- failed
-- end Tactic
|
SetTheory\Cardinal\Cofinality.lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn, Violeta Hernández Palacios
-/
import Mathlib.SetTheory.Cardinal.Ordinal
import Mathlib.SetTheory.Ordinal.FixedPoint
/-!
# Cofinality
This file contains the definition of cofinality of an ordinal number and regular cardinals
## Main Definitions
* `Ordinal.cof o` is the cofinality of the ordinal `o`.
If `o` is the order type of the relation `<` on `α`, then `o.cof` is the smallest cardinality of a
subset `s` of α that is *cofinal* in `α`, i.e. `∀ x : α, ∃ y ∈ s, ¬ y < x`.
* `Cardinal.IsStrongLimit c` means that `c` is a strong limit cardinal:
`c ≠ 0 ∧ ∀ x < c, 2 ^ x < c`.
* `Cardinal.IsRegular c` means that `c` is a regular cardinal: `ℵ₀ ≤ c ∧ c.ord.cof = c`.
* `Cardinal.IsInaccessible c` means that `c` is strongly inaccessible:
`ℵ₀ < c ∧ IsRegular c ∧ IsStrongLimit c`.
## Main Statements
* `Ordinal.infinite_pigeonhole_card`: the infinite pigeonhole principle
* `Cardinal.lt_power_cof`: A consequence of König's theorem stating that `c < c ^ c.ord.cof` for
`c ≥ ℵ₀`
* `Cardinal.univ_inaccessible`: The type of ordinals in `Type u` form an inaccessible cardinal
(in `Type v` with `v > u`). This shows (externally) that in `Type u` there are at least `u`
inaccessible cardinals.
## Implementation Notes
* The cofinality is defined for ordinals.
If `c` is a cardinal number, its cofinality is `c.ord.cof`.
## Tags
cofinality, regular cardinals, limits cardinals, inaccessible cardinals,
infinite pigeonhole principle
-/
noncomputable section
open Function Cardinal Set Order
open scoped Classical
open Cardinal Ordinal
universe u v w
variable {α : Type*} {r : α → α → Prop}
/-! ### Cofinality of orders -/
namespace Order
/-- Cofinality of a reflexive order `≼`. This is the smallest cardinality
of a subset `S : Set α` such that `∀ a, ∃ b ∈ S, a ≼ b`. -/
def cof (r : α → α → Prop) : Cardinal :=
sInf { c | ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = c }
/-- The set in the definition of `Order.cof` is nonempty. -/
theorem cof_nonempty (r : α → α → Prop) [IsRefl α r] :
{ c | ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = c }.Nonempty :=
⟨_, Set.univ, fun a => ⟨a, ⟨⟩, refl _⟩, rfl⟩
theorem cof_le (r : α → α → Prop) {S : Set α} (h : ∀ a, ∃ b ∈ S, r a b) : cof r ≤ #S :=
csInf_le' ⟨S, h, rfl⟩
theorem le_cof {r : α → α → Prop} [IsRefl α r] (c : Cardinal) :
c ≤ cof r ↔ ∀ {S : Set α}, (∀ a, ∃ b ∈ S, r a b) → c ≤ #S := by
rw [cof, le_csInf_iff'' (cof_nonempty r)]
use fun H S h => H _ ⟨S, h, rfl⟩
rintro H d ⟨S, h, rfl⟩
exact H h
end Order
theorem RelIso.cof_le_lift {α : Type u} {β : Type v} {r : α → α → Prop} {s} [IsRefl β s]
(f : r ≃r s) : Cardinal.lift.{max u v} (Order.cof r) ≤
Cardinal.lift.{max u v} (Order.cof s) := by
rw [Order.cof, Order.cof, lift_sInf, lift_sInf,
le_csInf_iff'' ((Order.cof_nonempty s).image _)]
rintro - ⟨-, ⟨u, H, rfl⟩, rfl⟩
apply csInf_le'
refine
⟨_, ⟨f.symm '' u, fun a => ?_, rfl⟩,
lift_mk_eq.{u, v, max u v}.2 ⟨(f.symm.toEquiv.image u).symm⟩⟩
rcases H (f a) with ⟨b, hb, hb'⟩
refine ⟨f.symm b, mem_image_of_mem _ hb, f.map_rel_iff.1 ?_⟩
rwa [RelIso.apply_symm_apply]
theorem RelIso.cof_eq_lift {α : Type u} {β : Type v} {r s} [IsRefl α r] [IsRefl β s] (f : r ≃r s) :
Cardinal.lift.{max u v} (Order.cof r) = Cardinal.lift.{max u v} (Order.cof s) :=
(RelIso.cof_le_lift f).antisymm (RelIso.cof_le_lift f.symm)
theorem RelIso.cof_le {α β : Type u} {r : α → α → Prop} {s} [IsRefl β s] (f : r ≃r s) :
Order.cof r ≤ Order.cof s :=
lift_le.1 (RelIso.cof_le_lift f)
theorem RelIso.cof_eq {α β : Type u} {r s} [IsRefl α r] [IsRefl β s] (f : r ≃r s) :
Order.cof r = Order.cof s :=
lift_inj.1 (RelIso.cof_eq_lift f)
/-- Cofinality of a strict order `≺`. This is the smallest cardinality of a set `S : Set α` such
that `∀ a, ∃ b ∈ S, ¬ b ≺ a`. -/
def StrictOrder.cof (r : α → α → Prop) : Cardinal :=
Order.cof (swap rᶜ)
/-- The set in the definition of `Order.StrictOrder.cof` is nonempty. -/
theorem StrictOrder.cof_nonempty (r : α → α → Prop) [IsIrrefl α r] :
{ c | ∃ S : Set α, Unbounded r S ∧ #S = c }.Nonempty :=
@Order.cof_nonempty α _ (IsRefl.swap rᶜ)
/-! ### Cofinality of ordinals -/
namespace Ordinal
/-- Cofinality of an ordinal. This is the smallest cardinal of a
subset `S` of the ordinal which is unbounded, in the sense
`∀ a, ∃ b ∈ S, a ≤ b`. It is defined for all ordinals, but
`cof 0 = 0` and `cof (succ o) = 1`, so it is only really
interesting on limit ordinals (when it is an infinite cardinal). -/
def cof (o : Ordinal.{u}) : Cardinal.{u} :=
o.liftOn (fun a => StrictOrder.cof a.r)
(by
rintro ⟨α, r, wo₁⟩ ⟨β, s, wo₂⟩ ⟨⟨f, hf⟩⟩
haveI := wo₁; haveI := wo₂
dsimp only
apply @RelIso.cof_eq _ _ _ _ ?_ ?_
· constructor
exact @fun a b => not_iff_not.2 hf
· dsimp only [swap]
exact ⟨fun _ => irrefl _⟩
· dsimp only [swap]
exact ⟨fun _ => irrefl _⟩)
theorem cof_type (r : α → α → Prop) [IsWellOrder α r] : (type r).cof = StrictOrder.cof r :=
rfl
theorem le_cof_type [IsWellOrder α r] {c} : c ≤ cof (type r) ↔ ∀ S, Unbounded r S → c ≤ #S :=
(le_csInf_iff'' (StrictOrder.cof_nonempty r)).trans
⟨fun H S h => H _ ⟨S, h, rfl⟩, by
rintro H d ⟨S, h, rfl⟩
exact H _ h⟩
theorem cof_type_le [IsWellOrder α r] {S : Set α} (h : Unbounded r S) : cof (type r) ≤ #S :=
le_cof_type.1 le_rfl S h
theorem lt_cof_type [IsWellOrder α r] {S : Set α} : #S < cof (type r) → Bounded r S := by
simpa using not_imp_not.2 cof_type_le
theorem cof_eq (r : α → α → Prop) [IsWellOrder α r] : ∃ S, Unbounded r S ∧ #S = cof (type r) :=
csInf_mem (StrictOrder.cof_nonempty r)
theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] :
∃ S, Unbounded r S ∧ type (Subrel r S) = (cof (type r)).ord := by
let ⟨S, hS, e⟩ := cof_eq r
let ⟨s, _, e'⟩ := Cardinal.ord_eq S
let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a }
suffices Unbounded r T by
refine ⟨T, this, le_antisymm ?_ (Cardinal.ord_le.2 <| cof_type_le this)⟩
rw [← e, e']
refine
(RelEmbedding.ofMonotone
(fun a : T =>
(⟨a,
let ⟨aS, _⟩ := a.2
aS⟩ :
S))
fun a b h => ?_).ordinal_type_le
rcases a with ⟨a, aS, ha⟩
rcases b with ⟨b, bS, hb⟩
change s ⟨a, _⟩ ⟨b, _⟩
refine ((trichotomous_of s _ _).resolve_left fun hn => ?_).resolve_left ?_
· exact asymm h (ha _ hn)
· intro e
injection e with e
subst b
exact irrefl _ h
intro a
have : { b : S | ¬r b a }.Nonempty :=
let ⟨b, bS, ba⟩ := hS a
⟨⟨b, bS⟩, ba⟩
let b := (IsWellFounded.wf : WellFounded s).min _ this
have ba : ¬r b a := IsWellFounded.wf.min_mem _ this
refine ⟨b, ⟨b.2, fun c => not_imp_not.1 fun h => ?_⟩, ba⟩
rw [show ∀ b : S, (⟨b, b.2⟩ : S) = b by intro b; cases b; rfl]
exact IsWellFounded.wf.not_lt_min _ this (IsOrderConnected.neg_trans h ba)
/-! ### Cofinality of suprema and least strict upper bounds -/
private theorem card_mem_cof {o} : ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = o.card :=
⟨_, _, lsub_typein o, mk_ordinal_out o⟩
/-- The set in the `lsub` characterization of `cof` is nonempty. -/
theorem cof_lsub_def_nonempty (o) :
{ a : Cardinal | ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a }.Nonempty :=
⟨_, card_mem_cof⟩
theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o =
sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by
refine le_antisymm (le_csInf (cof_lsub_def_nonempty o) ?_) (csInf_le' ?_)
· rintro a ⟨ι, f, hf, rfl⟩
rw [← type_lt o]
refine
(cof_type_le fun a => ?_).trans
(@mk_le_of_injective _ _
(fun s : typein ((· < ·) : o.out.α → o.out.α → Prop) ⁻¹' Set.range f =>
Classical.choose s.prop)
fun s t hst => by
let H := congr_arg f hst
rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj,
Subtype.coe_inj] at H)
have := typein_lt_self a
simp_rw [← hf, lt_lsub_iff] at this
cases' this with i hi
refine ⟨enum (· < ·) (f i) ?_, ?_, ?_⟩
· rw [type_lt, ← hf]
apply lt_lsub
· rw [mem_preimage, typein_enum]
exact mem_range_self i
· rwa [← typein_le_typein, typein_enum]
· rcases cof_eq (· < · : (Quotient.out o).α → (Quotient.out o).α → Prop) with ⟨S, hS, hS'⟩
let f : S → Ordinal := fun s => typein LT.lt s.val
refine ⟨S, f, le_antisymm (lsub_le fun i => typein_lt_self (o := o) i)
(le_of_forall_lt fun a ha => ?_), by rwa [type_lt o] at hS'⟩
rw [← type_lt o] at ha
rcases hS (enum (· < ·) a ha) with ⟨b, hb, hb'⟩
rw [← typein_le_typein, typein_enum] at hb'
exact hb'.trans_lt (lt_lsub.{u, u} f ⟨b, hb⟩)
@[simp]
theorem lift_cof (o) : Cardinal.lift.{u, v} (cof o) = cof (Ordinal.lift.{u, v} o) := by
refine inductionOn o ?_
intro α r _
apply le_antisymm
· refine le_cof_type.2 fun S H => ?_
have : Cardinal.lift.{u, v} #(ULift.up ⁻¹' S) ≤ #(S : Type (max u v)) := by
rw [← Cardinal.lift_umax.{v, u}, ← Cardinal.lift_id'.{v, u} #S]
exact mk_preimage_of_injective_lift.{v, max u v} ULift.up S (ULift.up_injective.{v, u})
refine (Cardinal.lift_le.2 <| cof_type_le ?_).trans this
exact fun a =>
let ⟨⟨b⟩, bs, br⟩ := H ⟨a⟩
⟨b, bs, br⟩
· rcases cof_eq r with ⟨S, H, e'⟩
have : #(ULift.down.{u, v} ⁻¹' S) ≤ Cardinal.lift.{u, v} #S :=
⟨⟨fun ⟨⟨x⟩, h⟩ => ⟨⟨x, h⟩⟩, fun ⟨⟨x⟩, h₁⟩ ⟨⟨y⟩, h₂⟩ e => by
simp at e; congr⟩⟩
rw [e'] at this
refine (cof_type_le ?_).trans this
exact fun ⟨a⟩ =>
let ⟨b, bs, br⟩ := H a
⟨⟨b⟩, bs, br⟩
theorem cof_le_card (o) : cof o ≤ card o := by
rw [cof_eq_sInf_lsub]
exact csInf_le' card_mem_cof
theorem cof_ord_le (c : Cardinal) : c.ord.cof ≤ c := by simpa using cof_le_card c.ord
theorem ord_cof_le (o : Ordinal.{u}) : o.cof.ord ≤ o :=
(ord_le_ord.2 (cof_le_card o)).trans (ord_card_le o)
theorem exists_lsub_cof (o : Ordinal) :
∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = cof o := by
rw [cof_eq_sInf_lsub]
exact csInf_mem (cof_lsub_def_nonempty o)
theorem cof_lsub_le {ι} (f : ι → Ordinal) : cof (lsub.{u, u} f) ≤ #ι := by
rw [cof_eq_sInf_lsub]
exact csInf_le' ⟨ι, f, rfl, rfl⟩
theorem cof_lsub_le_lift {ι} (f : ι → Ordinal) :
cof (lsub.{u, v} f) ≤ Cardinal.lift.{v, u} #ι := by
rw [← mk_uLift.{u, v}]
convert cof_lsub_le.{max u v} fun i : ULift.{v, u} ι => f i.down
exact
lsub_eq_of_range_eq.{u, max u v, max u v}
(Set.ext fun x => ⟨fun ⟨i, hi⟩ => ⟨ULift.up.{v, u} i, hi⟩, fun ⟨i, hi⟩ => ⟨_, hi⟩⟩)
theorem le_cof_iff_lsub {o : Ordinal} {a : Cardinal} :
a ≤ cof o ↔ ∀ {ι} (f : ι → Ordinal), lsub.{u, u} f = o → a ≤ #ι := by
rw [cof_eq_sInf_lsub]
exact
(le_csInf_iff'' (cof_lsub_def_nonempty o)).trans
⟨fun H ι f hf => H _ ⟨ι, f, hf, rfl⟩, fun H b ⟨ι, f, hf, hb⟩ => by
rw [← hb]
exact H _ hf⟩
theorem lsub_lt_ord_lift {ι} {f : ι → Ordinal} {c : Ordinal}
(hι : Cardinal.lift.{v, u} #ι < c.cof)
(hf : ∀ i, f i < c) : lsub.{u, v} f < c :=
lt_of_le_of_ne (lsub_le hf) fun h => by
subst h
exact (cof_lsub_le_lift.{u, v} f).not_lt hι
theorem lsub_lt_ord {ι} {f : ι → Ordinal} {c : Ordinal} (hι : #ι < c.cof) :
(∀ i, f i < c) → lsub.{u, u} f < c :=
lsub_lt_ord_lift (by rwa [(#ι).lift_id])
theorem cof_sup_le_lift {ι} {f : ι → Ordinal} (H : ∀ i, f i < sup.{u, v} f) :
cof (sup.{u, v} f) ≤ Cardinal.lift.{v, u} #ι := by
rw [← sup_eq_lsub_iff_lt_sup.{u, v}] at H
rw [H]
exact cof_lsub_le_lift f
theorem cof_sup_le {ι} {f : ι → Ordinal} (H : ∀ i, f i < sup.{u, u} f) :
cof (sup.{u, u} f) ≤ #ι := by
rw [← (#ι).lift_id]
exact cof_sup_le_lift H
theorem sup_lt_ord_lift {ι} {f : ι → Ordinal} {c : Ordinal} (hι : Cardinal.lift.{v, u} #ι < c.cof)
(hf : ∀ i, f i < c) : sup.{u, v} f < c :=
(sup_le_lsub.{u, v} f).trans_lt (lsub_lt_ord_lift hι hf)
theorem sup_lt_ord {ι} {f : ι → Ordinal} {c : Ordinal} (hι : #ι < c.cof) :
(∀ i, f i < c) → sup.{u, u} f < c :=
sup_lt_ord_lift (by rwa [(#ι).lift_id])
theorem iSup_lt_lift {ι} {f : ι → Cardinal} {c : Cardinal}
(hι : Cardinal.lift.{v, u} #ι < c.ord.cof)
(hf : ∀ i, f i < c) : iSup.{max u v + 1, u + 1} f < c := by
rw [← ord_lt_ord, iSup_ord (Cardinal.bddAbove_range.{u, v} _)]
refine sup_lt_ord_lift hι fun i => ?_
rw [ord_lt_ord]
apply hf
theorem iSup_lt {ι} {f : ι → Cardinal} {c : Cardinal} (hι : #ι < c.ord.cof) :
(∀ i, f i < c) → iSup f < c :=
iSup_lt_lift (by rwa [(#ι).lift_id])
theorem nfpFamily_lt_ord_lift {ι} {f : ι → Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c)
(hc' : Cardinal.lift.{v, u} #ι < cof c) (hf : ∀ (i), ∀ b < c, f i b < c) {a} (ha : a < c) :
nfpFamily.{u, v} f a < c := by
refine sup_lt_ord_lift ((Cardinal.lift_le.2 (mk_list_le_max ι)).trans_lt ?_) fun l => ?_
· rw [lift_max]
apply max_lt _ hc'
rwa [Cardinal.lift_aleph0]
· induction' l with i l H
· exact ha
· exact hf _ _ H
theorem nfpFamily_lt_ord {ι} {f : ι → Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hc' : #ι < cof c)
(hf : ∀ (i), ∀ b < c, f i b < c) {a} : a < c → nfpFamily.{u, u} f a < c :=
nfpFamily_lt_ord_lift hc (by rwa [(#ι).lift_id]) hf
theorem nfpBFamily_lt_ord_lift {o : Ordinal} {f : ∀ a < o, Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c)
(hc' : Cardinal.lift.{v, u} o.card < cof c) (hf : ∀ (i hi), ∀ b < c, f i hi b < c) {a} :
a < c → nfpBFamily.{u, v} o f a < c :=
nfpFamily_lt_ord_lift hc (by rwa [mk_ordinal_out]) fun i => hf _ _
theorem nfpBFamily_lt_ord {o : Ordinal} {f : ∀ a < o, Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c)
(hc' : o.card < cof c) (hf : ∀ (i hi), ∀ b < c, f i hi b < c) {a} :
a < c → nfpBFamily.{u, u} o f a < c :=
nfpBFamily_lt_ord_lift hc (by rwa [o.card.lift_id]) hf
theorem nfp_lt_ord {f : Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hf : ∀ i < c, f i < c) {a} :
a < c → nfp f a < c :=
nfpFamily_lt_ord_lift hc (by simpa using Cardinal.one_lt_aleph0.trans hc) fun _ => hf
theorem exists_blsub_cof (o : Ordinal) :
∃ f : ∀ a < (cof o).ord, Ordinal, blsub.{u, u} _ f = o := by
rcases exists_lsub_cof o with ⟨ι, f, hf, hι⟩
rcases Cardinal.ord_eq ι with ⟨r, hr, hι'⟩
rw [← @blsub_eq_lsub' ι r hr] at hf
rw [← hι, hι']
exact ⟨_, hf⟩
theorem le_cof_iff_blsub {b : Ordinal} {a : Cardinal} :
a ≤ cof b ↔ ∀ {o} (f : ∀ a < o, Ordinal), blsub.{u, u} o f = b → a ≤ o.card :=
le_cof_iff_lsub.trans
⟨fun H o f hf => by simpa using H _ hf, fun H ι f hf => by
rcases Cardinal.ord_eq ι with ⟨r, hr, hι'⟩
rw [← @blsub_eq_lsub' ι r hr] at hf
simpa using H _ hf⟩
theorem cof_blsub_le_lift {o} (f : ∀ a < o, Ordinal) :
cof (blsub.{u, v} o f) ≤ Cardinal.lift.{v, u} o.card := by
rw [← mk_ordinal_out o]
exact cof_lsub_le_lift _
theorem cof_blsub_le {o} (f : ∀ a < o, Ordinal) : cof (blsub.{u, u} o f) ≤ o.card := by
rw [← o.card.lift_id]
exact cof_blsub_le_lift f
theorem blsub_lt_ord_lift {o : Ordinal.{u}} {f : ∀ a < o, Ordinal} {c : Ordinal}
(ho : Cardinal.lift.{v, u} o.card < c.cof) (hf : ∀ i hi, f i hi < c) : blsub.{u, v} o f < c :=
lt_of_le_of_ne (blsub_le hf) fun h =>
ho.not_le (by simpa [← iSup_ord, hf, h] using cof_blsub_le_lift.{u, v} f)
theorem blsub_lt_ord {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : o.card < c.cof)
(hf : ∀ i hi, f i hi < c) : blsub.{u, u} o f < c :=
blsub_lt_ord_lift (by rwa [o.card.lift_id]) hf
theorem cof_bsup_le_lift {o : Ordinal} {f : ∀ a < o, Ordinal} (H : ∀ i h, f i h < bsup.{u, v} o f) :
cof (bsup.{u, v} o f) ≤ Cardinal.lift.{v, u} o.card := by
rw [← bsup_eq_blsub_iff_lt_bsup.{u, v}] at H
rw [H]
exact cof_blsub_le_lift.{u, v} f
theorem cof_bsup_le {o : Ordinal} {f : ∀ a < o, Ordinal} :
(∀ i h, f i h < bsup.{u, u} o f) → cof (bsup.{u, u} o f) ≤ o.card := by
rw [← o.card.lift_id]
exact cof_bsup_le_lift
theorem bsup_lt_ord_lift {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal}
(ho : Cardinal.lift.{v, u} o.card < c.cof) (hf : ∀ i hi, f i hi < c) : bsup.{u, v} o f < c :=
(bsup_le_blsub f).trans_lt (blsub_lt_ord_lift ho hf)
theorem bsup_lt_ord {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : o.card < c.cof) :
(∀ i hi, f i hi < c) → bsup.{u, u} o f < c :=
bsup_lt_ord_lift (by rwa [o.card.lift_id])
/-! ### Basic results -/
@[simp]
theorem cof_zero : cof 0 = 0 := by
refine LE.le.antisymm ?_ (Cardinal.zero_le _)
rw [← card_zero]
exact cof_le_card 0
@[simp]
theorem cof_eq_zero {o} : cof o = 0 ↔ o = 0 :=
⟨inductionOn o fun α r _ z =>
let ⟨S, hl, e⟩ := cof_eq r
type_eq_zero_iff_isEmpty.2 <|
⟨fun a =>
let ⟨b, h, _⟩ := hl a
(mk_eq_zero_iff.1 (e.trans z)).elim' ⟨_, h⟩⟩,
fun e => by simp [e]⟩
theorem cof_ne_zero {o} : cof o ≠ 0 ↔ o ≠ 0 :=
cof_eq_zero.not
@[simp]
theorem cof_succ (o) : cof (succ o) = 1 := by
apply le_antisymm
· refine inductionOn o fun α r _ => ?_
change cof (type _) ≤ _
rw [← (_ : #_ = 1)]
· apply cof_type_le
refine fun a => ⟨Sum.inr PUnit.unit, Set.mem_singleton _, ?_⟩
rcases a with (a | ⟨⟨⟨⟩⟩⟩) <;> simp [EmptyRelation]
· rw [Cardinal.mk_fintype, Set.card_singleton]
simp
· rw [← Cardinal.succ_zero, succ_le_iff]
simpa [lt_iff_le_and_ne, Cardinal.zero_le] using fun h =>
succ_ne_zero o (cof_eq_zero.1 (Eq.symm h))
@[simp]
theorem cof_eq_one_iff_is_succ {o} : cof.{u} o = 1 ↔ ∃ a, o = succ a :=
⟨inductionOn o fun α r _ z => by
rcases cof_eq r with ⟨S, hl, e⟩; rw [z] at e
cases' mk_ne_zero_iff.1 (by rw [e]; exact one_ne_zero) with a
refine
⟨typein r a,
Eq.symm <|
Quotient.sound
⟨RelIso.ofSurjective (RelEmbedding.ofMonotone ?_ fun x y => ?_) fun x => ?_⟩⟩
· apply Sum.rec <;> [exact Subtype.val; exact fun _ => a]
· rcases x with (x | ⟨⟨⟨⟩⟩⟩) <;> rcases y with (y | ⟨⟨⟨⟩⟩⟩) <;>
simp [Subrel, Order.Preimage, EmptyRelation]
exact x.2
· suffices r x a ∨ ∃ _ : PUnit.{u}, ↑a = x by
convert this
dsimp [RelEmbedding.ofMonotone]; simp
rcases trichotomous_of r x a with (h | h | h)
· exact Or.inl h
· exact Or.inr ⟨PUnit.unit, h.symm⟩
· rcases hl x with ⟨a', aS, hn⟩
refine absurd h ?_
convert hn
change _ = ↑(⟨a', aS⟩ : S)
have := le_one_iff_subsingleton.1 (le_of_eq e)
congr!,
fun ⟨a, e⟩ => by simp [e]⟩
/-- A fundamental sequence for `a` is an increasing sequence of length `o = cof a` that converges at
`a`. We provide `o` explicitly in order to avoid type rewrites. -/
def IsFundamentalSequence (a o : Ordinal.{u}) (f : ∀ b < o, Ordinal.{u}) : Prop :=
o ≤ a.cof.ord ∧ (∀ {i j} (hi hj), i < j → f i hi < f j hj) ∧ blsub.{u, u} o f = a
namespace IsFundamentalSequence
variable {a o : Ordinal.{u}} {f : ∀ b < o, Ordinal.{u}}
protected theorem cof_eq (hf : IsFundamentalSequence a o f) : a.cof.ord = o :=
hf.1.antisymm' <| by
rw [← hf.2.2]
exact (ord_le_ord.2 (cof_blsub_le f)).trans (ord_card_le o)
protected theorem strict_mono (hf : IsFundamentalSequence a o f) {i j} :
∀ hi hj, i < j → f i hi < f j hj :=
hf.2.1
theorem blsub_eq (hf : IsFundamentalSequence a o f) : blsub.{u, u} o f = a :=
hf.2.2
theorem ord_cof (hf : IsFundamentalSequence a o f) :
IsFundamentalSequence a a.cof.ord fun i hi => f i (hi.trans_le (by rw [hf.cof_eq])) := by
have H := hf.cof_eq
subst H
exact hf
theorem id_of_le_cof (h : o ≤ o.cof.ord) : IsFundamentalSequence o o fun a _ => a :=
⟨h, @fun _ _ _ _ => id, blsub_id o⟩
protected theorem zero {f : ∀ b < (0 : Ordinal), Ordinal} : IsFundamentalSequence 0 0 f :=
⟨by rw [cof_zero, ord_zero], @fun i j hi => (Ordinal.not_lt_zero i hi).elim, blsub_zero f⟩
protected theorem succ : IsFundamentalSequence (succ o) 1 fun _ _ => o := by
refine ⟨?_, @fun i j hi hj h => ?_, blsub_const Ordinal.one_ne_zero o⟩
· rw [cof_succ, ord_one]
· rw [lt_one_iff_zero] at hi hj
rw [hi, hj] at h
exact h.false.elim
protected theorem monotone (hf : IsFundamentalSequence a o f) {i j : Ordinal} (hi : i < o)
(hj : j < o) (hij : i ≤ j) : f i hi ≤ f j hj := by
rcases lt_or_eq_of_le hij with (hij | rfl)
· exact (hf.2.1 hi hj hij).le
· rfl
theorem trans {a o o' : Ordinal.{u}} {f : ∀ b < o, Ordinal.{u}} (hf : IsFundamentalSequence a o f)
{g : ∀ b < o', Ordinal.{u}} (hg : IsFundamentalSequence o o' g) :
IsFundamentalSequence a o' fun i hi =>
f (g i hi) (by rw [← hg.2.2]; apply lt_blsub) := by
refine ⟨?_, @fun i j _ _ h => hf.2.1 _ _ (hg.2.1 _ _ h), ?_⟩
· rw [hf.cof_eq]
exact hg.1.trans (ord_cof_le o)
· rw [@blsub_comp.{u, u, u} o _ f (@IsFundamentalSequence.monotone _ _ f hf)]
· exact hf.2.2
· exact hg.2.2
end IsFundamentalSequence
/-- Every ordinal has a fundamental sequence. -/
theorem exists_fundamental_sequence (a : Ordinal.{u}) :
∃ f, IsFundamentalSequence a a.cof.ord f := by
suffices h : ∃ o f, IsFundamentalSequence a o f by
rcases h with ⟨o, f, hf⟩
exact ⟨_, hf.ord_cof⟩
rcases exists_lsub_cof a with ⟨ι, f, hf, hι⟩
rcases ord_eq ι with ⟨r, wo, hr⟩
haveI := wo
let r' := Subrel r { i | ∀ j, r j i → f j < f i }
let hrr' : r' ↪r r := Subrel.relEmbedding _ _
haveI := hrr'.isWellOrder
refine
⟨_, _, hrr'.ordinal_type_le.trans ?_, @fun i j _ h _ => (enum r' j h).prop _ ?_,
le_antisymm (blsub_le fun i hi => lsub_le_iff.1 hf.le _) ?_⟩
· rw [← hι, hr]
· change r (hrr'.1 _) (hrr'.1 _)
rwa [hrr'.2, @enum_lt_enum _ r']
· rw [← hf, lsub_le_iff]
intro i
suffices h : ∃ i' hi', f i ≤ bfamilyOfFamily' r' (fun i => f i) i' hi' by
rcases h with ⟨i', hi', hfg⟩
exact hfg.trans_lt (lt_blsub _ _ _)
by_cases h : ∀ j, r j i → f j < f i
· refine ⟨typein r' ⟨i, h⟩, typein_lt_type _ _, ?_⟩
rw [bfamilyOfFamily'_typein]
· push_neg at h
cases' wo.wf.min_mem _ h with hji hij
refine ⟨typein r' ⟨_, fun k hkj => lt_of_lt_of_le ?_ hij⟩, typein_lt_type _ _, ?_⟩
· by_contra! H
exact (wo.wf.not_lt_min _ h ⟨IsTrans.trans _ _ _ hkj hji, H⟩) hkj
· rwa [bfamilyOfFamily'_typein]
@[simp]
theorem cof_cof (a : Ordinal.{u}) : cof (cof a).ord = cof a := by
cases' exists_fundamental_sequence a with f hf
cases' exists_fundamental_sequence a.cof.ord with g hg
exact ord_injective (hf.trans hg).cof_eq.symm
protected theorem IsNormal.isFundamentalSequence {f : Ordinal.{u} → Ordinal.{u}} (hf : IsNormal f)
{a o} (ha : IsLimit a) {g} (hg : IsFundamentalSequence a o g) :
IsFundamentalSequence (f a) o fun b hb => f (g b hb) := by
refine ⟨?_, @fun i j _ _ h => hf.strictMono (hg.2.1 _ _ h), ?_⟩
· rcases exists_lsub_cof (f a) with ⟨ι, f', hf', hι⟩
rw [← hg.cof_eq, ord_le_ord, ← hι]
suffices (lsub.{u, u} fun i => sInf { b : Ordinal | f' i ≤ f b }) = a by
rw [← this]
apply cof_lsub_le
have H : ∀ i, ∃ b < a, f' i ≤ f b := fun i => by
have := lt_lsub.{u, u} f' i
rw [hf', ← IsNormal.blsub_eq.{u, u} hf ha, lt_blsub_iff] at this
simpa using this
refine (lsub_le fun i => ?_).antisymm (le_of_forall_lt fun b hb => ?_)
· rcases H i with ⟨b, hb, hb'⟩
exact lt_of_le_of_lt (csInf_le' hb') hb
· have := hf.strictMono hb
rw [← hf', lt_lsub_iff] at this
cases' this with i hi
rcases H i with ⟨b, _, hb⟩
exact
((le_csInf_iff'' ⟨b, by exact hb⟩).2 fun c hc =>
hf.strictMono.le_iff_le.1 (hi.trans hc)).trans_lt (lt_lsub _ i)
· rw [@blsub_comp.{u, u, u} a _ (fun b _ => f b) (@fun i j _ _ h => hf.strictMono.monotone h) g
hg.2.2]
exact IsNormal.blsub_eq.{u, u} hf ha
theorem IsNormal.cof_eq {f} (hf : IsNormal f) {a} (ha : IsLimit a) : cof (f a) = cof a :=
let ⟨_, hg⟩ := exists_fundamental_sequence a
ord_injective (hf.isFundamentalSequence ha hg).cof_eq
theorem IsNormal.cof_le {f} (hf : IsNormal f) (a) : cof a ≤ cof (f a) := by
rcases zero_or_succ_or_limit a with (rfl | ⟨b, rfl⟩ | ha)
· rw [cof_zero]
exact zero_le _
· rw [cof_succ, Cardinal.one_le_iff_ne_zero, cof_ne_zero, ← Ordinal.pos_iff_ne_zero]
exact (Ordinal.zero_le (f b)).trans_lt (hf.1 b)
· rw [hf.cof_eq ha]
@[simp]
theorem cof_add (a b : Ordinal) : b ≠ 0 → cof (a + b) = cof b := fun h => by
rcases zero_or_succ_or_limit b with (rfl | ⟨c, rfl⟩ | hb)
· contradiction
· rw [add_succ, cof_succ, cof_succ]
· exact (add_isNormal a).cof_eq hb
theorem aleph0_le_cof {o} : ℵ₀ ≤ cof o ↔ IsLimit o := by
rcases zero_or_succ_or_limit o with (rfl | ⟨o, rfl⟩ | l)
· simp [not_zero_isLimit, Cardinal.aleph0_ne_zero]
· simp [not_succ_isLimit, Cardinal.one_lt_aleph0]
· simp only [l, iff_true]
refine le_of_not_lt fun h => ?_
cases' Cardinal.lt_aleph0.1 h with n e
have := cof_cof o
rw [e, ord_nat] at this
cases n
· simp at e
simp [e, not_zero_isLimit] at l
· rw [natCast_succ, cof_succ] at this
rw [← this, cof_eq_one_iff_is_succ] at e
rcases e with ⟨a, rfl⟩
exact not_succ_isLimit _ l
@[simp]
theorem aleph'_cof {o : Ordinal} (ho : o.IsLimit) : (aleph' o).ord.cof = o.cof :=
aleph'_isNormal.cof_eq ho
@[simp]
theorem aleph_cof {o : Ordinal} (ho : o.IsLimit) : (aleph o).ord.cof = o.cof :=
aleph_isNormal.cof_eq ho
@[simp]
theorem cof_omega : cof ω = ℵ₀ :=
(aleph0_le_cof.2 omega_isLimit).antisymm' <| by
rw [← card_omega]
apply cof_le_card
theorem cof_eq' (r : α → α → Prop) [IsWellOrder α r] (h : IsLimit (type r)) :
∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = cof (type r) :=
let ⟨S, H, e⟩ := cof_eq r
⟨S, fun a =>
let a' := enum r _ (h.2 _ (typein_lt_type r a))
let ⟨b, h, ab⟩ := H a'
⟨b, h,
(IsOrderConnected.conn a b a' <|
(typein_lt_typein r).1
(by
rw [typein_enum]
exact lt_succ (typein _ _))).resolve_right
ab⟩,
e⟩
@[simp]
theorem cof_univ : cof univ.{u, v} = Cardinal.univ.{u, v} :=
le_antisymm (cof_le_card _)
(by
refine le_of_forall_lt fun c h => ?_
rcases lt_univ'.1 h with ⟨c, rfl⟩
rcases @cof_eq Ordinal.{u} (· < ·) _ with ⟨S, H, Se⟩
rw [univ, ← lift_cof, ← Cardinal.lift_lift.{u+1, v, u}, Cardinal.lift_lt, ← Se]
refine lt_of_not_ge fun h => ?_
cases' Cardinal.lift_down h with a e
refine Quotient.inductionOn a (fun α e => ?_) e
cases' Quotient.exact e with f
have f := Equiv.ulift.symm.trans f
let g a := (f a).1
let o := succ (sup.{u, u} g)
rcases H o with ⟨b, h, l⟩
refine l (lt_succ_iff.2 ?_)
rw [← show g (f.symm ⟨b, h⟩) = b by simp [g]]
apply le_sup)
/-! ### Infinite pigeonhole principle -/
/-- If the union of s is unbounded and s is smaller than the cofinality,
then s has an unbounded member -/
theorem unbounded_of_unbounded_sUnion (r : α → α → Prop) [wo : IsWellOrder α r] {s : Set (Set α)}
(h₁ : Unbounded r <| ⋃₀ s) (h₂ : #s < StrictOrder.cof r) : ∃ x ∈ s, Unbounded r x := by
by_contra! h
simp_rw [not_unbounded_iff] at h
let f : s → α := fun x : s => wo.wf.sup x (h x.1 x.2)
refine h₂.not_le (le_trans (csInf_le' ⟨range f, fun x => ?_, rfl⟩) mk_range_le)
rcases h₁ x with ⟨y, ⟨c, hc, hy⟩, hxy⟩
exact ⟨f ⟨c, hc⟩, mem_range_self _, fun hxz => hxy (Trans.trans (wo.wf.lt_sup _ hy) hxz)⟩
/-- If the union of s is unbounded and s is smaller than the cofinality,
then s has an unbounded member -/
theorem unbounded_of_unbounded_iUnion {α β : Type u} (r : α → α → Prop) [wo : IsWellOrder α r]
(s : β → Set α) (h₁ : Unbounded r <| ⋃ x, s x) (h₂ : #β < StrictOrder.cof r) :
∃ x : β, Unbounded r (s x) := by
rw [← sUnion_range] at h₁
rcases unbounded_of_unbounded_sUnion r h₁ (mk_range_le.trans_lt h₂) with ⟨_, ⟨x, rfl⟩, u⟩
exact ⟨x, u⟩
/-- The infinite pigeonhole principle -/
theorem infinite_pigeonhole {β α : Type u} (f : β → α) (h₁ : ℵ₀ ≤ #β) (h₂ : #α < (#β).ord.cof) :
∃ a : α, #(f ⁻¹' {a}) = #β := by
have : ∃ a, #β ≤ #(f ⁻¹' {a}) := by
by_contra! h
apply mk_univ.not_lt
rw [← preimage_univ, ← iUnion_of_singleton, preimage_iUnion]
exact
mk_iUnion_le_sum_mk.trans_lt
((sum_le_iSup _).trans_lt <| mul_lt_of_lt h₁ (h₂.trans_le <| cof_ord_le _) (iSup_lt h₂ h))
cases' this with x h
refine ⟨x, h.antisymm' ?_⟩
rw [le_mk_iff_exists_set]
exact ⟨_, rfl⟩
/-- Pigeonhole principle for a cardinality below the cardinality of the domain -/
theorem infinite_pigeonhole_card {β α : Type u} (f : β → α) (θ : Cardinal) (hθ : θ ≤ #β)
(h₁ : ℵ₀ ≤ θ) (h₂ : #α < θ.ord.cof) : ∃ a : α, θ ≤ #(f ⁻¹' {a}) := by
rcases le_mk_iff_exists_set.1 hθ with ⟨s, rfl⟩
cases' infinite_pigeonhole (f ∘ Subtype.val : s → α) h₁ h₂ with a ha
use a; rw [← ha, @preimage_comp _ _ _ Subtype.val f]
exact mk_preimage_of_injective _ _ Subtype.val_injective
theorem infinite_pigeonhole_set {β α : Type u} {s : Set β} (f : s → α) (θ : Cardinal)
(hθ : θ ≤ #s) (h₁ : ℵ₀ ≤ θ) (h₂ : #α < θ.ord.cof) :
∃ (a : α) (t : Set β) (h : t ⊆ s), θ ≤ #t ∧ ∀ ⦃x⦄ (hx : x ∈ t), f ⟨x, h hx⟩ = a := by
cases' infinite_pigeonhole_card f θ hθ h₁ h₂ with a ha
refine ⟨a, { x | ∃ h, f ⟨x, h⟩ = a }, ?_, ?_, ?_⟩
· rintro x ⟨hx, _⟩
exact hx
· refine
ha.trans
(ge_of_eq <|
Quotient.sound ⟨Equiv.trans ?_ (Equiv.subtypeSubtypeEquivSubtypeExists _ _).symm⟩)
simp only [coe_eq_subtype, mem_singleton_iff, mem_preimage, mem_setOf_eq]
rfl
rintro x ⟨_, hx'⟩; exact hx'
end Ordinal
/-! ### Regular and inaccessible cardinals -/
namespace Cardinal
open Ordinal
/-- A cardinal is a strong limit if it is not zero and it is
closed under powersets. Note that `ℵ₀` is a strong limit by this definition. -/
def IsStrongLimit (c : Cardinal) : Prop :=
c ≠ 0 ∧ ∀ x < c, (2^x) < c
theorem IsStrongLimit.ne_zero {c} (h : IsStrongLimit c) : c ≠ 0 :=
h.1
theorem IsStrongLimit.two_power_lt {x c} (h : IsStrongLimit c) : x < c → (2^x) < c :=
h.2 x
theorem isStrongLimit_aleph0 : IsStrongLimit ℵ₀ :=
⟨aleph0_ne_zero, fun x hx => by
rcases lt_aleph0.1 hx with ⟨n, rfl⟩
exact mod_cast nat_lt_aleph0 (2 ^ n)⟩
protected theorem IsStrongLimit.isSuccLimit {c} (H : IsStrongLimit c) : IsSuccLimit c :=
isSuccLimit_of_succ_lt fun x h => (succ_le_of_lt <| cantor x).trans_lt (H.two_power_lt h)
theorem IsStrongLimit.isLimit {c} (H : IsStrongLimit c) : IsLimit c :=
⟨H.ne_zero, H.isSuccLimit⟩
theorem isStrongLimit_beth {o : Ordinal} (H : IsSuccLimit o) : IsStrongLimit (beth o) := by
rcases eq_or_ne o 0 with (rfl | h)
· rw [beth_zero]
exact isStrongLimit_aleph0
· refine ⟨beth_ne_zero o, fun a ha => ?_⟩
rw [beth_limit ⟨h, isSuccLimit_iff_succ_lt.1 H⟩] at ha
rcases exists_lt_of_lt_ciSup' ha with ⟨⟨i, hi⟩, ha⟩
have := power_le_power_left two_ne_zero ha.le
rw [← beth_succ] at this
exact this.trans_lt (beth_lt.2 (H.succ_lt hi))
theorem mk_bounded_subset {α : Type*} (h : ∀ x < #α, (2^x) < #α) {r : α → α → Prop}
[IsWellOrder α r] (hr : (#α).ord = type r) : #{ s : Set α // Bounded r s } = #α := by
rcases eq_or_ne #α 0 with (ha | ha)
· rw [ha]
haveI := mk_eq_zero_iff.1 ha
rw [mk_eq_zero_iff]
constructor
rintro ⟨s, hs⟩
exact (not_unbounded_iff s).2 hs (unbounded_of_isEmpty s)
have h' : IsStrongLimit #α := ⟨ha, h⟩
have ha := h'.isLimit.aleph0_le
apply le_antisymm
· have : { s : Set α | Bounded r s } = ⋃ i, 𝒫{ j | r j i } := setOf_exists _
rw [← coe_setOf, this]
refine mk_iUnion_le_sum_mk.trans ((sum_le_iSup (fun i => #(𝒫{ j | r j i }))).trans
((mul_le_max_of_aleph0_le_left ha).trans ?_))
rw [max_eq_left]
apply ciSup_le' _
intro i
rw [mk_powerset]
apply (h'.two_power_lt _).le
rw [coe_setOf, card_typein, ← lt_ord, hr]
apply typein_lt_type
· refine @mk_le_of_injective α _ (fun x => Subtype.mk {x} ?_) ?_
· apply bounded_singleton
rw [← hr]
apply ord_isLimit ha
· intro a b hab
simpa [singleton_eq_singleton_iff] using hab
theorem mk_subset_mk_lt_cof {α : Type*} (h : ∀ x < #α, (2^x) < #α) :
#{ s : Set α // #s < cof (#α).ord } = #α := by
rcases eq_or_ne #α 0 with (ha | ha)
· simp [ha]
have h' : IsStrongLimit #α := ⟨ha, h⟩
rcases ord_eq α with ⟨r, wo, hr⟩
haveI := wo
apply le_antisymm
· conv_rhs => rw [← mk_bounded_subset h hr]
apply mk_le_mk_of_subset
intro s hs
rw [hr] at hs
exact lt_cof_type hs
· refine @mk_le_of_injective α _ (fun x => Subtype.mk {x} ?_) ?_
· rw [mk_singleton]
exact one_lt_aleph0.trans_le (aleph0_le_cof.2 (ord_isLimit h'.isLimit.aleph0_le))
· intro a b hab
simpa [singleton_eq_singleton_iff] using hab
/-- A cardinal is regular if it is infinite and it equals its own cofinality. -/
def IsRegular (c : Cardinal) : Prop :=
ℵ₀ ≤ c ∧ c ≤ c.ord.cof
theorem IsRegular.aleph0_le {c : Cardinal} (H : c.IsRegular) : ℵ₀ ≤ c :=
H.1
theorem IsRegular.cof_eq {c : Cardinal} (H : c.IsRegular) : c.ord.cof = c :=
(cof_ord_le c).antisymm H.2
theorem IsRegular.pos {c : Cardinal} (H : c.IsRegular) : 0 < c :=
aleph0_pos.trans_le H.1
theorem IsRegular.nat_lt {c : Cardinal} (H : c.IsRegular) (n : ℕ) : n < c :=
lt_of_lt_of_le (nat_lt_aleph0 n) H.aleph0_le
theorem IsRegular.ord_pos {c : Cardinal} (H : c.IsRegular) : 0 < c.ord := by
rw [Cardinal.lt_ord, card_zero]
exact H.pos
theorem isRegular_cof {o : Ordinal} (h : o.IsLimit) : IsRegular o.cof :=
⟨aleph0_le_cof.2 h, (cof_cof o).ge⟩
theorem isRegular_aleph0 : IsRegular ℵ₀ :=
⟨le_rfl, by simp⟩
theorem isRegular_succ {c : Cardinal.{u}} (h : ℵ₀ ≤ c) : IsRegular (succ c) :=
⟨h.trans (le_succ c),
succ_le_of_lt
(by
cases' Quotient.exists_rep (@succ Cardinal _ _ c) with α αe; simp only [mk'_def] at αe
rcases ord_eq α with ⟨r, wo, re⟩
have := ord_isLimit (h.trans (le_succ _))
rw [← αe, re] at this ⊢
rcases cof_eq' r this with ⟨S, H, Se⟩
rw [← Se]
apply lt_imp_lt_of_le_imp_le fun h => mul_le_mul_right' h c
rw [mul_eq_self h, ← succ_le_iff, ← αe, ← sum_const']
refine le_trans ?_ (sum_le_sum (fun (x : S) => card (typein r (x : α))) _ fun i => ?_)
· simp only [← card_typein, ← mk_sigma]
exact
⟨Embedding.ofSurjective (fun x => x.2.1) fun a =>
let ⟨b, h, ab⟩ := H a
⟨⟨⟨_, h⟩, _, ab⟩, rfl⟩⟩
· rw [← lt_succ_iff, ← lt_ord, ← αe, re]
apply typein_lt_type)⟩
theorem isRegular_aleph_one : IsRegular (aleph 1) := by
rw [← succ_aleph0]
exact isRegular_succ le_rfl
theorem isRegular_aleph'_succ {o : Ordinal} (h : ω ≤ o) : IsRegular (aleph' (succ o)) := by
rw [aleph'_succ]
exact isRegular_succ (aleph0_le_aleph'.2 h)
theorem isRegular_aleph_succ (o : Ordinal) : IsRegular (aleph (succ o)) := by
rw [aleph_succ]
exact isRegular_succ (aleph0_le_aleph o)
/-- A function whose codomain's cardinality is infinite but strictly smaller than its domain's
has a fiber with cardinality strictly great than the codomain.
-/
theorem infinite_pigeonhole_card_lt {β α : Type u} (f : β → α) (w : #α < #β) (w' : ℵ₀ ≤ #α) :
∃ a : α, #α < #(f ⁻¹' {a}) := by
simp_rw [← succ_le_iff]
exact
Ordinal.infinite_pigeonhole_card f (succ #α) (succ_le_of_lt w) (w'.trans (lt_succ _).le)
((lt_succ _).trans_le (isRegular_succ w').2.ge)
/-- A function whose codomain's cardinality is infinite but strictly smaller than its domain's
has an infinite fiber.
-/
theorem exists_infinite_fiber {β α : Type u} (f : β → α) (w : #α < #β) (w' : Infinite α) :
∃ a : α, Infinite (f ⁻¹' {a}) := by
simp_rw [Cardinal.infinite_iff] at w' ⊢
cases' infinite_pigeonhole_card_lt f w w' with a ha
exact ⟨a, w'.trans ha.le⟩
/-- If an infinite type `β` can be expressed as a union of finite sets,
then the cardinality of the collection of those finite sets
must be at least the cardinality of `β`.
-/
theorem le_range_of_union_finset_eq_top {α β : Type*} [Infinite β] (f : α → Finset β)
(w : ⋃ a, (f a : Set β) = ⊤) : #β ≤ #(range f) := by
have k : _root_.Infinite (range f) := by
rw [infinite_coe_iff]
apply mt (union_finset_finite_of_range_finite f)
rw [w]
exact infinite_univ
by_contra h
simp only [not_le] at h
let u : ∀ b, ∃ a, b ∈ f a := fun b => by simpa using (w.ge : _) (Set.mem_univ b)
let u' : β → range f := fun b => ⟨f (u b).choose, by simp⟩
have v' : ∀ a, u' ⁻¹' {⟨f a, by simp⟩} ≤ f a := by
rintro a p m
simp? [u'] at m says simp only [mem_preimage, mem_singleton_iff, Subtype.mk.injEq, u'] at m
rw [← m]
apply fun b => (u b).choose_spec
obtain ⟨⟨-, ⟨a, rfl⟩⟩, p⟩ := exists_infinite_fiber u' h k
exact (@Infinite.of_injective _ _ p (inclusion (v' a)) (inclusion_injective _)).false
theorem lsub_lt_ord_lift_of_isRegular {ι} {f : ι → Ordinal} {c} (hc : IsRegular c)
(hι : Cardinal.lift.{v, u} #ι < c) : (∀ i, f i < c.ord) → Ordinal.lsub.{u, v} f < c.ord :=
lsub_lt_ord_lift (by rwa [hc.cof_eq])
theorem lsub_lt_ord_of_isRegular {ι} {f : ι → Ordinal} {c} (hc : IsRegular c) (hι : #ι < c) :
(∀ i, f i < c.ord) → Ordinal.lsub f < c.ord :=
lsub_lt_ord (by rwa [hc.cof_eq])
theorem sup_lt_ord_lift_of_isRegular {ι} {f : ι → Ordinal} {c} (hc : IsRegular c)
(hι : Cardinal.lift.{v, u} #ι < c) : (∀ i, f i < c.ord) → Ordinal.sup.{u, v} f < c.ord :=
sup_lt_ord_lift (by rwa [hc.cof_eq])
theorem sup_lt_ord_of_isRegular {ι} {f : ι → Ordinal} {c} (hc : IsRegular c) (hι : #ι < c) :
(∀ i, f i < c.ord) → Ordinal.sup f < c.ord :=
sup_lt_ord (by rwa [hc.cof_eq])
theorem blsub_lt_ord_lift_of_isRegular {o : Ordinal} {f : ∀ a < o, Ordinal} {c} (hc : IsRegular c)
(ho : Cardinal.lift.{v, u} o.card < c) :
(∀ i hi, f i hi < c.ord) → Ordinal.blsub.{u, v} o f < c.ord :=
blsub_lt_ord_lift (by rwa [hc.cof_eq])
theorem blsub_lt_ord_of_isRegular {o : Ordinal} {f : ∀ a < o, Ordinal} {c} (hc : IsRegular c)
(ho : o.card < c) : (∀ i hi, f i hi < c.ord) → Ordinal.blsub o f < c.ord :=
blsub_lt_ord (by rwa [hc.cof_eq])
theorem bsup_lt_ord_lift_of_isRegular {o : Ordinal} {f : ∀ a < o, Ordinal} {c} (hc : IsRegular c)
(hι : Cardinal.lift.{v, u} o.card < c) :
(∀ i hi, f i hi < c.ord) → Ordinal.bsup.{u, v} o f < c.ord :=
bsup_lt_ord_lift (by rwa [hc.cof_eq])
theorem bsup_lt_ord_of_isRegular {o : Ordinal} {f : ∀ a < o, Ordinal} {c} (hc : IsRegular c)
(hι : o.card < c) : (∀ i hi, f i hi < c.ord) → Ordinal.bsup o f < c.ord :=
bsup_lt_ord (by rwa [hc.cof_eq])
theorem iSup_lt_lift_of_isRegular {ι} {f : ι → Cardinal} {c} (hc : IsRegular c)
(hι : Cardinal.lift.{v, u} #ι < c) : (∀ i, f i < c) → iSup.{max u v + 1, u + 1} f < c :=
iSup_lt_lift.{u, v} (by rwa [hc.cof_eq])
theorem iSup_lt_of_isRegular {ι} {f : ι → Cardinal} {c} (hc : IsRegular c) (hι : #ι < c) :
(∀ i, f i < c) → iSup f < c :=
iSup_lt (by rwa [hc.cof_eq])
theorem sum_lt_lift_of_isRegular {ι : Type u} {f : ι → Cardinal} {c : Cardinal} (hc : IsRegular c)
(hι : Cardinal.lift.{v, u} #ι < c) (hf : ∀ i, f i < c) : sum f < c :=
(sum_le_iSup_lift _).trans_lt <| mul_lt_of_lt hc.1 hι (iSup_lt_lift_of_isRegular hc hι hf)
theorem sum_lt_of_isRegular {ι : Type u} {f : ι → Cardinal} {c : Cardinal} (hc : IsRegular c)
(hι : #ι < c) : (∀ i, f i < c) → sum f < c :=
sum_lt_lift_of_isRegular.{u, u} hc (by rwa [lift_id])
@[simp]
theorem card_lt_of_card_iUnion_lt {ι : Type u} {α : Type u} {t : ι → Set α} {c : Cardinal}
(h : #(⋃ i, t i) < c) (i : ι) : #(t i) < c :=
lt_of_le_of_lt (Cardinal.mk_le_mk_of_subset <| subset_iUnion _ _) h
@[simp]
theorem card_iUnion_lt_iff_forall_of_isRegular {ι : Type u} {α : Type u} {t : ι → Set α}
{c : Cardinal} (hc : c.IsRegular) (hι : #ι < c) : #(⋃ i, t i) < c ↔ ∀ i, #(t i) < c := by
refine ⟨card_lt_of_card_iUnion_lt, fun h ↦ ?_⟩
apply lt_of_le_of_lt (Cardinal.mk_sUnion_le _)
apply Cardinal.mul_lt_of_lt hc.aleph0_le
(lt_of_le_of_lt Cardinal.mk_range_le hι)
apply Cardinal.iSup_lt_of_isRegular hc (lt_of_le_of_lt Cardinal.mk_range_le hι)
simpa
theorem card_lt_of_card_biUnion_lt {α β : Type u} {s : Set α} {t : ∀ a ∈ s, Set β} {c : Cardinal}
(h : #(⋃ a ∈ s, t a ‹_›) < c) (a : α) (ha : a ∈ s) : # (t a ha) < c := by
rw [biUnion_eq_iUnion] at h
have := card_lt_of_card_iUnion_lt h
simp_all only [iUnion_coe_set,
Subtype.forall]
theorem card_biUnion_lt_iff_forall_of_isRegular {α β : Type u} {s : Set α} {t : ∀ a ∈ s, Set β}
{c : Cardinal} (hc : c.IsRegular) (hs : #s < c) :
#(⋃ a ∈ s, t a ‹_›) < c ↔ ∀ a (ha : a ∈ s), # (t a ha) < c := by
rw [biUnion_eq_iUnion, card_iUnion_lt_iff_forall_of_isRegular hc hs, SetCoe.forall']
theorem nfpFamily_lt_ord_lift_of_isRegular {ι} {f : ι → Ordinal → Ordinal} {c} (hc : IsRegular c)
(hι : Cardinal.lift.{v, u} #ι < c) (hc' : c ≠ ℵ₀) (hf : ∀ (i), ∀ b < c.ord, f i b < c.ord) {a}
(ha : a < c.ord) : nfpFamily.{u, v} f a < c.ord := by
apply nfpFamily_lt_ord_lift.{u, v} _ _ hf ha <;> rw [hc.cof_eq]
· exact lt_of_le_of_ne hc.1 hc'.symm
· exact hι
theorem nfpFamily_lt_ord_of_isRegular {ι} {f : ι → Ordinal → Ordinal} {c} (hc : IsRegular c)
(hι : #ι < c) (hc' : c ≠ ℵ₀) {a} (hf : ∀ (i), ∀ b < c.ord, f i b < c.ord) :
a < c.ord → nfpFamily.{u, u} f a < c.ord :=
nfpFamily_lt_ord_lift_of_isRegular hc (by rwa [lift_id]) hc' hf
theorem nfpBFamily_lt_ord_lift_of_isRegular {o : Ordinal} {f : ∀ a < o, Ordinal → Ordinal} {c}
(hc : IsRegular c) (ho : Cardinal.lift.{v, u} o.card < c) (hc' : c ≠ ℵ₀)
(hf : ∀ (i hi), ∀ b < c.ord, f i hi b < c.ord) {a} :
a < c.ord → nfpBFamily.{u, v} o f a < c.ord :=
nfpFamily_lt_ord_lift_of_isRegular hc (by rwa [mk_ordinal_out]) hc' fun i => hf _ _
theorem nfpBFamily_lt_ord_of_isRegular {o : Ordinal} {f : ∀ a < o, Ordinal → Ordinal} {c}
(hc : IsRegular c) (ho : o.card < c) (hc' : c ≠ ℵ₀)
(hf : ∀ (i hi), ∀ b < c.ord, f i hi b < c.ord) {a} :
a < c.ord → nfpBFamily.{u, u} o f a < c.ord :=
nfpBFamily_lt_ord_lift_of_isRegular hc (by rwa [lift_id]) hc' hf
theorem nfp_lt_ord_of_isRegular {f : Ordinal → Ordinal} {c} (hc : IsRegular c) (hc' : c ≠ ℵ₀)
(hf : ∀ i < c.ord, f i < c.ord) {a} : a < c.ord → nfp f a < c.ord :=
nfp_lt_ord
(by
rw [hc.cof_eq]
exact lt_of_le_of_ne hc.1 hc'.symm)
hf
theorem derivFamily_lt_ord_lift {ι} {f : ι → Ordinal → Ordinal} {c} (hc : IsRegular c)
(hι : Cardinal.lift.{v, u} #ι < c) (hc' : c ≠ ℵ₀)
(hf : ∀ (i), ∀ b < c.ord, f i b < c.ord) {a} :
a < c.ord → derivFamily.{u, v} f a < c.ord := by
have hω : ℵ₀ < c.ord.cof := by
rw [hc.cof_eq]
exact lt_of_le_of_ne hc.1 hc'.symm
induction a using limitRecOn with
| H₁ =>
rw [derivFamily_zero]
exact nfpFamily_lt_ord_lift hω (by rwa [hc.cof_eq]) hf
| H₂ b hb =>
intro hb'
rw [derivFamily_succ]
exact
nfpFamily_lt_ord_lift hω (by rwa [hc.cof_eq]) hf
((ord_isLimit hc.1).2 _ (hb ((lt_succ b).trans hb')))
| H₃ b hb H =>
intro hb'
rw [derivFamily_limit f hb]
exact
bsup_lt_ord_of_isRegular.{u, v} hc (ord_lt_ord.1 ((ord_card_le b).trans_lt hb')) fun o' ho' =>
H o' ho' (ho'.trans hb')
theorem derivFamily_lt_ord {ι} {f : ι → Ordinal → Ordinal} {c} (hc : IsRegular c) (hι : #ι < c)
(hc' : c ≠ ℵ₀) (hf : ∀ (i), ∀ b < c.ord, f i b < c.ord) {a} :
a < c.ord → derivFamily.{u, u} f a < c.ord :=
derivFamily_lt_ord_lift hc (by rwa [lift_id]) hc' hf
theorem derivBFamily_lt_ord_lift {o : Ordinal} {f : ∀ a < o, Ordinal → Ordinal} {c}
(hc : IsRegular c) (hι : Cardinal.lift.{v, u} o.card < c) (hc' : c ≠ ℵ₀)
(hf : ∀ (i hi), ∀ b < c.ord, f i hi b < c.ord) {a} :
a < c.ord → derivBFamily.{u, v} o f a < c.ord :=
derivFamily_lt_ord_lift hc (by rwa [mk_ordinal_out]) hc' fun i => hf _ _
theorem derivBFamily_lt_ord {o : Ordinal} {f : ∀ a < o, Ordinal → Ordinal} {c} (hc : IsRegular c)
(hι : o.card < c) (hc' : c ≠ ℵ₀) (hf : ∀ (i hi), ∀ b < c.ord, f i hi b < c.ord) {a} :
a < c.ord → derivBFamily.{u, u} o f a < c.ord :=
derivBFamily_lt_ord_lift hc (by rwa [lift_id]) hc' hf
theorem deriv_lt_ord {f : Ordinal.{u} → Ordinal} {c} (hc : IsRegular c) (hc' : c ≠ ℵ₀)
(hf : ∀ i < c.ord, f i < c.ord) {a} : a < c.ord → deriv f a < c.ord :=
derivFamily_lt_ord_lift hc
(by simpa using Cardinal.one_lt_aleph0.trans (lt_of_le_of_ne hc.1 hc'.symm)) hc' fun _ => hf
/-- A cardinal is inaccessible if it is an uncountable regular strong limit cardinal. -/
def IsInaccessible (c : Cardinal) :=
ℵ₀ < c ∧ IsRegular c ∧ IsStrongLimit c
theorem IsInaccessible.mk {c} (h₁ : ℵ₀ < c) (h₂ : c ≤ c.ord.cof) (h₃ : ∀ x < c, (2^x) < c) :
IsInaccessible c :=
⟨h₁, ⟨h₁.le, h₂⟩, (aleph0_pos.trans h₁).ne', h₃⟩
-- Lean's foundations prove the existence of ℵ₀ many inaccessible cardinals
theorem univ_inaccessible : IsInaccessible univ.{u, v} :=
IsInaccessible.mk (by simpa using lift_lt_univ' ℵ₀) (by simp) fun c h => by
rcases lt_univ'.1 h with ⟨c, rfl⟩
rw [← lift_two_power]
apply lift_lt_univ'
theorem lt_power_cof {c : Cardinal.{u}} : ℵ₀ ≤ c → c < (c^cof c.ord) :=
Quotient.inductionOn c fun α h => by
rcases ord_eq α with ⟨r, wo, re⟩
have := ord_isLimit h
rw [mk'_def, re] at this ⊢
rcases cof_eq' r this with ⟨S, H, Se⟩
have := sum_lt_prod (fun a : S => #{ x // r x a }) (fun _ => #α) fun i => ?_
· simp only [Cardinal.prod_const, Cardinal.lift_id, ← Se, ← mk_sigma, power_def] at this ⊢
refine lt_of_le_of_lt ?_ this
refine ⟨Embedding.ofSurjective ?_ ?_⟩
· exact fun x => x.2.1
· exact fun a =>
let ⟨b, h, ab⟩ := H a
⟨⟨⟨_, h⟩, _, ab⟩, rfl⟩
· have := typein_lt_type r i
rwa [← re, lt_ord] at this
theorem lt_cof_power {a b : Cardinal} (ha : ℵ₀ ≤ a) (b1 : 1 < b) : a < cof (b^a).ord := by
have b0 : b ≠ 0 := (zero_lt_one.trans b1).ne'
apply lt_imp_lt_of_le_imp_le (power_le_power_left <| power_ne_zero a b0)
rw [← power_mul, mul_eq_self ha]
exact lt_power_cof (ha.trans <| (cantor' _ b1).le)
end Cardinal
section Omega1
namespace Ordinal
open Cardinal
open scoped Ordinal
lemma sup_sequence_lt_omega1 {α} [Countable α] (o : α → Ordinal) (ho : ∀ n, o n < ω₁) :
sup o < ω₁ := by
apply sup_lt_ord_lift _ ho
rw [Cardinal.isRegular_aleph_one.cof_eq]
exact lt_of_le_of_lt mk_le_aleph0 aleph0_lt_aleph_one
end Ordinal
end Omega1
|
SetTheory\Cardinal\Continuum.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.SetTheory.Cardinal.Ordinal
/-!
# Cardinality of continuum
In this file we define `Cardinal.continuum` (notation: `𝔠`, localized in `Cardinal`) to be `2 ^ ℵ₀`.
We also prove some `simp` lemmas about cardinal arithmetic involving `𝔠`.
## Notation
- `𝔠` : notation for `Cardinal.continuum` in locale `Cardinal`.
-/
namespace Cardinal
universe u v
open Cardinal
/-- Cardinality of continuum. -/
def continuum : Cardinal.{u} :=
2 ^ ℵ₀
scoped notation "𝔠" => Cardinal.continuum
@[simp]
theorem two_power_aleph0 : 2 ^ aleph0.{u} = continuum.{u} :=
rfl
@[simp]
theorem lift_continuum : lift.{v} 𝔠 = 𝔠 := by
rw [← two_power_aleph0, lift_two_power, lift_aleph0, two_power_aleph0]
@[simp]
theorem continuum_le_lift {c : Cardinal.{u}} : 𝔠 ≤ lift.{v} c ↔ 𝔠 ≤ c := by
rw [← lift_continuum.{v, u}, lift_le]
@[simp]
theorem lift_le_continuum {c : Cardinal.{u}} : lift.{v} c ≤ 𝔠 ↔ c ≤ 𝔠 := by
rw [← lift_continuum.{v, u}, lift_le]
@[simp]
theorem continuum_lt_lift {c : Cardinal.{u}} : 𝔠 < lift.{v} c ↔ 𝔠 < c := by
rw [← lift_continuum.{v, u}, lift_lt]
@[simp]
theorem lift_lt_continuum {c : Cardinal.{u}} : lift.{v} c < 𝔠 ↔ c < 𝔠 := by
rw [← lift_continuum.{v, u}, lift_lt]
/-!
### Inequalities
-/
theorem aleph0_lt_continuum : ℵ₀ < 𝔠 :=
cantor ℵ₀
theorem aleph0_le_continuum : ℵ₀ ≤ 𝔠 :=
aleph0_lt_continuum.le
@[simp]
theorem beth_one : beth 1 = 𝔠 := by simpa using beth_succ 0
theorem nat_lt_continuum (n : ℕ) : ↑n < 𝔠 :=
(nat_lt_aleph0 n).trans aleph0_lt_continuum
theorem mk_set_nat : #(Set ℕ) = 𝔠 := by simp
theorem continuum_pos : 0 < 𝔠 :=
nat_lt_continuum 0
theorem continuum_ne_zero : 𝔠 ≠ 0 :=
continuum_pos.ne'
theorem aleph_one_le_continuum : aleph 1 ≤ 𝔠 := by
rw [← succ_aleph0]
exact Order.succ_le_of_lt aleph0_lt_continuum
@[simp]
theorem continuum_toNat : toNat continuum = 0 :=
toNat_apply_of_aleph0_le aleph0_le_continuum
@[simp]
theorem continuum_toPartENat : toPartENat continuum = ⊤ :=
toPartENat_apply_of_aleph0_le aleph0_le_continuum
/-!
### Addition
-/
@[simp]
theorem aleph0_add_continuum : ℵ₀ + 𝔠 = 𝔠 :=
add_eq_right aleph0_le_continuum aleph0_le_continuum
@[simp]
theorem continuum_add_aleph0 : 𝔠 + ℵ₀ = 𝔠 :=
(add_comm _ _).trans aleph0_add_continuum
@[simp]
theorem continuum_add_self : 𝔠 + 𝔠 = 𝔠 :=
add_eq_self aleph0_le_continuum
@[simp]
theorem nat_add_continuum (n : ℕ) : ↑n + 𝔠 = 𝔠 :=
nat_add_eq n aleph0_le_continuum
@[simp]
theorem continuum_add_nat (n : ℕ) : 𝔠 + n = 𝔠 :=
(add_comm _ _).trans (nat_add_continuum n)
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem ofNat_add_continuum {n : ℕ} [Nat.AtLeastTwo n] : no_index (OfNat.ofNat n) + 𝔠 = 𝔠 :=
nat_add_continuum n
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem continuum_add_ofNat {n : ℕ} [Nat.AtLeastTwo n] : 𝔠 + no_index (OfNat.ofNat n) = 𝔠 :=
continuum_add_nat n
/-!
### Multiplication
-/
@[simp]
theorem continuum_mul_self : 𝔠 * 𝔠 = 𝔠 :=
mul_eq_left aleph0_le_continuum le_rfl continuum_ne_zero
@[simp]
theorem continuum_mul_aleph0 : 𝔠 * ℵ₀ = 𝔠 :=
mul_eq_left aleph0_le_continuum aleph0_le_continuum aleph0_ne_zero
@[simp]
theorem aleph0_mul_continuum : ℵ₀ * 𝔠 = 𝔠 :=
(mul_comm _ _).trans continuum_mul_aleph0
@[simp]
theorem nat_mul_continuum {n : ℕ} (hn : n ≠ 0) : ↑n * 𝔠 = 𝔠 :=
mul_eq_right aleph0_le_continuum (nat_lt_continuum n).le (Nat.cast_ne_zero.2 hn)
@[simp]
theorem continuum_mul_nat {n : ℕ} (hn : n ≠ 0) : 𝔠 * n = 𝔠 :=
(mul_comm _ _).trans (nat_mul_continuum hn)
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem ofNat_mul_continuum {n : ℕ} [Nat.AtLeastTwo n] : no_index (OfNat.ofNat n) * 𝔠 = 𝔠 :=
nat_mul_continuum (OfNat.ofNat_ne_zero n)
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem continuum_mul_ofNat {n : ℕ} [Nat.AtLeastTwo n] : 𝔠 * no_index (OfNat.ofNat n) = 𝔠 :=
continuum_mul_nat (OfNat.ofNat_ne_zero n)
/-!
### Power
-/
@[simp]
theorem aleph0_power_aleph0 : aleph0.{u} ^ aleph0.{u} = 𝔠 :=
power_self_eq le_rfl
@[simp]
theorem nat_power_aleph0 {n : ℕ} (hn : 2 ≤ n) : (n ^ aleph0.{u} : Cardinal.{u}) = 𝔠 :=
nat_power_eq le_rfl hn
@[simp]
theorem continuum_power_aleph0 : continuum.{u} ^ aleph0.{u} = 𝔠 := by
rw [← two_power_aleph0, ← power_mul, mul_eq_left le_rfl le_rfl aleph0_ne_zero]
end Cardinal
|
SetTheory\Cardinal\CountableCover.lean | /-
Copyright (c) 2023 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.SetTheory.Cardinal.Ordinal
import Mathlib.Order.Filter.Basic
/-!
# Cardinality of a set with a countable cover
Assume that a set `t` is eventually covered by a countable family of sets, all with
cardinality `≤ a`. Then `t` itself has cardinality at most `a`. This is proved in
`Cardinal.mk_subtype_le_of_countable_eventually_mem`.
Versions are also given when `t = univ`, and with `= a` instead of `≤ a`.
-/
open Set Order Filter
open scoped Cardinal
namespace Cardinal
universe u v
/-- If a set `t` is eventually covered by a countable family of sets, all with cardinality at
most `a`, then the cardinality of `t` is also bounded by `a`.
Supersed by `mk_le_of_countable_eventually_mem` which does not assume
that the indexing set lives in the same universe. -/
lemma mk_subtype_le_of_countable_eventually_mem_aux {α ι : Type u} {a : Cardinal}
[Countable ι] {f : ι → Set α} {l : Filter ι} [NeBot l]
{t : Set α} (ht : ∀ x ∈ t, ∀ᶠ i in l, x ∈ f i)
(h'f : ∀ i, #(f i) ≤ a) : #t ≤ a := by
rcases lt_or_le a ℵ₀ with ha|ha
/- case `a` finite. In this case, it suffices to show that any finite subset `s` of `t` has
cardinality at most `a`. For this, we pick `i` such that `f i` contains all the points in `s`,
and apply the assumption that the cardinality of `f i` is at most `a`. -/
· obtain ⟨n, rfl⟩ : ∃ (n : ℕ), a = n := lt_aleph0.1 ha
apply mk_le_iff_forall_finset_subset_card_le.2 (fun s hs ↦ ?_)
have A : ∀ x ∈ s, ∀ᶠ i in l, x ∈ f i := fun x hx ↦ ht x (hs hx)
have B : ∀ᶠ i in l, ∀ x ∈ s, x ∈ f i := (s.eventually_all).2 A
rcases B.exists with ⟨i, hi⟩
have : ∀ i, Fintype (f i) := fun i ↦ (lt_aleph0_iff_fintype.1 ((h'f i).trans_lt ha)).some
let u : Finset α := (f i).toFinset
have I1 : s.card ≤ u.card := by
have : s ⊆ u := fun x hx ↦ by simpa only [u, Set.mem_toFinset] using hi x hx
exact Finset.card_le_card this
have I2 : (u.card : Cardinal) ≤ n := by
convert h'f i; simp only [u, Set.toFinset_card, mk_fintype]
exact I1.trans (Nat.cast_le.1 I2)
-- case `a` infinite:
· have : t ⊆ ⋃ i, f i := by
intro x hx
obtain ⟨i, hi⟩ : ∃ i, x ∈ f i := (ht x hx).exists
exact mem_iUnion_of_mem i hi
calc #t ≤ #(⋃ i, f i) := mk_le_mk_of_subset this
_ ≤ sum (fun i ↦ #(f i)) := mk_iUnion_le_sum_mk
_ ≤ sum (fun _ ↦ a) := sum_le_sum _ _ h'f
_ = #ι * a := by simp
_ ≤ ℵ₀ * a := mul_le_mul_right' mk_le_aleph0 a
_ = a := aleph0_mul_eq ha
/-- If a set `t` is eventually covered by a countable family of sets, all with cardinality at
most `a`, then the cardinality of `t` is also bounded by `a`. -/
lemma mk_subtype_le_of_countable_eventually_mem {α : Type u} {ι : Type v} {a : Cardinal}
[Countable ι] {f : ι → Set α} {l : Filter ι} [NeBot l]
{t : Set α} (ht : ∀ x ∈ t, ∀ᶠ i in l, x ∈ f i)
(h'f : ∀ i, #(f i) ≤ a) : #t ≤ a := by
let g : ULift.{u, v} ι → Set (ULift.{v, u} α) := (ULift.down ⁻¹' ·) ∘ f ∘ ULift.down
suffices #(ULift.down.{v} ⁻¹' t) ≤ Cardinal.lift.{v, u} a by simpa
let l' : Filter (ULift.{u} ι) := Filter.map ULift.up l
have : NeBot l' := map_neBot
apply mk_subtype_le_of_countable_eventually_mem_aux (ι := ULift.{u} ι) (l := l') (f := g)
· intro x hx
simpa only [Function.comp_apply, mem_preimage, eventually_map] using ht _ hx
· intro i
simpa [g] using h'f i.down
/-- If a space is eventually covered by a countable family of sets, all with cardinality at
most `a`, then the cardinality of the space is also bounded by `a`. -/
lemma mk_le_of_countable_eventually_mem {α : Type u} {ι : Type v} {a : Cardinal}
[Countable ι] {f : ι → Set α} {l : Filter ι} [NeBot l] (ht : ∀ x, ∀ᶠ i in l, x ∈ f i)
(h'f : ∀ i, #(f i) ≤ a) : #α ≤ a := by
rw [← mk_univ]
exact mk_subtype_le_of_countable_eventually_mem (l := l) (fun x _ ↦ ht x) h'f
/-- If a space is eventually covered by a countable family of sets, all with cardinality `a`,
then the cardinality of the space is also `a`. -/
lemma mk_of_countable_eventually_mem {α : Type u} {ι : Type v} {a : Cardinal}
[Countable ι] {f : ι → Set α} {l : Filter ι} [NeBot l] (ht : ∀ x, ∀ᶠ i in l, x ∈ f i)
(h'f : ∀ i, #(f i) = a) : #α = a := by
apply le_antisymm
· apply mk_le_of_countable_eventually_mem ht (fun i ↦ (h'f i).le)
· obtain ⟨i⟩ : Nonempty ι := nonempty_of_neBot l
rw [← (h'f i)]
exact mk_set_le (f i)
end Cardinal
|
SetTheory\Cardinal\Divisibility.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.IsPrimePow
import Mathlib.SetTheory.Cardinal.Ordinal
import Mathlib.Tactic.WLOG
/-!
# Cardinal Divisibility
We show basic results about divisibility in the cardinal numbers. This relation can be characterised
in the following simple way: if `a` and `b` are both less than `ℵ₀`, then `a ∣ b` iff they are
divisible as natural numbers. If `b` is greater than `ℵ₀`, then `a ∣ b` iff `a ≤ b`. This
furthermore shows that all infinite cardinals are prime; recall that `a * b = max a b` if
`ℵ₀ ≤ a * b`; therefore `a ∣ b * c = a ∣ max b c` and therefore clearly either `a ∣ b` or `a ∣ c`.
Note furthermore that no infinite cardinal is irreducible
(`Cardinal.not_irreducible_of_aleph0_le`), showing that the cardinal numbers do not form a
`CancelCommMonoidWithZero`.
## Main results
* `Cardinal.prime_of_aleph0_le`: a `Cardinal` is prime if it is infinite.
* `Cardinal.is_prime_iff`: a `Cardinal` is prime iff it is infinite or a prime natural number.
* `Cardinal.isPrimePow_iff`: a `Cardinal` is a prime power iff it is infinite or a natural number
which is itself a prime power.
-/
namespace Cardinal
open Cardinal
universe u
variable {a b : Cardinal.{u}} {n m : ℕ}
@[simp]
theorem isUnit_iff : IsUnit a ↔ a = 1 := by
refine
⟨fun h => ?_, by
rintro rfl
exact isUnit_one⟩
rcases eq_or_ne a 0 with (rfl | ha)
· exact (not_isUnit_zero h).elim
rw [isUnit_iff_forall_dvd] at h
cases' h 1 with t ht
rw [eq_comm, mul_eq_one_iff'] at ht
· exact ht.1
· exact one_le_iff_ne_zero.mpr ha
· apply one_le_iff_ne_zero.mpr
intro h
rw [h, mul_zero] at ht
exact zero_ne_one ht
instance : Unique Cardinal.{u}ˣ where
default := 1
uniq a := Units.val_eq_one.mp <| isUnit_iff.mp a.isUnit
theorem le_of_dvd : ∀ {a b : Cardinal}, b ≠ 0 → a ∣ b → a ≤ b
| a, x, b0, ⟨b, hab⟩ => by
simpa only [hab, mul_one] using
mul_le_mul_left' (one_le_iff_ne_zero.2 fun h : b = 0 => b0 (by rwa [h, mul_zero] at hab)) a
theorem dvd_of_le_of_aleph0_le (ha : a ≠ 0) (h : a ≤ b) (hb : ℵ₀ ≤ b) : a ∣ b :=
⟨b, (mul_eq_right hb h ha).symm⟩
@[simp]
theorem prime_of_aleph0_le (ha : ℵ₀ ≤ a) : Prime a := by
refine ⟨(aleph0_pos.trans_le ha).ne', ?_, fun b c hbc => ?_⟩
· rw [isUnit_iff]
exact (one_lt_aleph0.trans_le ha).ne'
rcases eq_or_ne (b * c) 0 with hz | hz
· rcases mul_eq_zero.mp hz with (rfl | rfl) <;> simp
wlog h : c ≤ b
· cases le_total c b <;> [solve_by_elim; rw [or_comm]]
apply_assumption
assumption'
all_goals rwa [mul_comm]
left
have habc := le_of_dvd hz hbc
rwa [mul_eq_max' <| ha.trans <| habc, max_def', if_pos h] at hbc
theorem not_irreducible_of_aleph0_le (ha : ℵ₀ ≤ a) : ¬Irreducible a := by
rw [irreducible_iff, not_and_or]
refine Or.inr fun h => ?_
simpa [mul_aleph0_eq ha, isUnit_iff, (one_lt_aleph0.trans_le ha).ne', one_lt_aleph0.ne'] using
h a ℵ₀
@[simp, norm_cast]
theorem nat_coe_dvd_iff : (n : Cardinal) ∣ m ↔ n ∣ m := by
refine ⟨?_, fun ⟨h, ht⟩ => ⟨h, mod_cast ht⟩⟩
rintro ⟨k, hk⟩
have : ↑m < ℵ₀ := nat_lt_aleph0 m
rw [hk, mul_lt_aleph0_iff] at this
rcases this with (h | h | ⟨-, hk'⟩)
iterate 2 simp only [h, mul_zero, zero_mul, Nat.cast_eq_zero] at hk; simp [hk]
lift k to ℕ using hk'
exact ⟨k, mod_cast hk⟩
@[simp]
theorem nat_is_prime_iff : Prime (n : Cardinal) ↔ n.Prime := by
simp only [Prime, Nat.prime_iff]
refine and_congr (by simp) (and_congr ?_ ⟨fun h b c hbc => ?_, fun h b c hbc => ?_⟩)
· simp only [isUnit_iff, Nat.isUnit_iff]
exact mod_cast Iff.rfl
· exact mod_cast h b c (mod_cast hbc)
cases' lt_or_le (b * c) ℵ₀ with h' h'
· rcases mul_lt_aleph0_iff.mp h' with (rfl | rfl | ⟨hb, hc⟩)
· simp
· simp
lift b to ℕ using hb
lift c to ℕ using hc
exact mod_cast h b c (mod_cast hbc)
rcases aleph0_le_mul_iff.mp h' with ⟨hb, hc, hℵ₀⟩
have hn : (n : Cardinal) ≠ 0 := by
intro h
rw [h, zero_dvd_iff, mul_eq_zero] at hbc
cases hbc <;> contradiction
wlog hℵ₀b : ℵ₀ ≤ b
apply (this h c b _ _ hc hb hℵ₀.symm hn (hℵ₀.resolve_left hℵ₀b)).symm <;> try assumption
· rwa [mul_comm] at hbc
· rwa [mul_comm] at h'
· exact Or.inl (dvd_of_le_of_aleph0_le hn ((nat_lt_aleph0 n).le.trans hℵ₀b) hℵ₀b)
theorem is_prime_iff {a : Cardinal} : Prime a ↔ ℵ₀ ≤ a ∨ ∃ p : ℕ, a = p ∧ p.Prime := by
rcases le_or_lt ℵ₀ a with h | h
· simp [h]
lift a to ℕ using id h
simp [not_le.mpr h]
theorem isPrimePow_iff {a : Cardinal} : IsPrimePow a ↔ ℵ₀ ≤ a ∨ ∃ n : ℕ, a = n ∧ IsPrimePow n := by
by_cases h : ℵ₀ ≤ a
· simp [h, (prime_of_aleph0_le h).isPrimePow]
simp only [h, Nat.cast_inj, exists_eq_left', false_or_iff, isPrimePow_nat_iff]
lift a to ℕ using not_le.mp h
rw [isPrimePow_def]
refine
⟨?_, fun ⟨n, han, p, k, hp, hk, h⟩ =>
⟨p, k, nat_is_prime_iff.2 hp, hk, by rw [han]; exact mod_cast h⟩⟩
rintro ⟨p, k, hp, hk, hpk⟩
have key : p ^ (1 : Cardinal) ≤ ↑a := by
rw [← hpk]; apply power_le_power_left hp.ne_zero; exact mod_cast hk
rw [power_one] at key
lift p to ℕ using key.trans_lt (nat_lt_aleph0 a)
exact ⟨a, rfl, p, k, nat_is_prime_iff.mp hp, hk, mod_cast hpk⟩
end Cardinal
|
SetTheory\Cardinal\ENat.lean | /-
Copyright (c) 2024 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.Order.Hom.Ring
import Mathlib.Data.ENat.Basic
import Mathlib.SetTheory.Cardinal.Basic
/-!
# Conversion between `Cardinal` and `ℕ∞`
In this file we define a coercion `Cardinal.ofENat : ℕ∞ → Cardinal`
and a projection `Cardinal.toENat : Cardinal →+*o ℕ∞`.
We also prove basic theorems about these definitions.
## Implementation notes
We define `Cardinal.ofENat` as a function instead of a bundled homomorphism
so that we can use it as a coercion and delaborate its application to `↑n`.
We define `Cardinal.toENat` as a bundled homomorphism
so that we can use all the theorems about homomorphisms without specializing them to this function.
Since it is not registered as a coercion, the argument about delaboration does not apply.
## Keywords
set theory, cardinals, extended natural numbers
-/
open Function Set
universe u v
namespace Cardinal
/-- Coercion `ℕ∞ → Cardinal`. It sends natural numbers to natural numbers and `⊤` to `ℵ₀`.
See also `Cardinal.ofENatHom` for a bundled homomorphism version. -/
@[coe] def ofENat : ℕ∞ → Cardinal
| (n : ℕ) => n
| ⊤ => ℵ₀
instance : Coe ENat Cardinal := ⟨Cardinal.ofENat⟩
@[simp, norm_cast] lemma ofENat_top : ofENat ⊤ = ℵ₀ := rfl
@[simp, norm_cast] lemma ofENat_nat (n : ℕ) : ofENat n = n := rfl
@[simp, norm_cast] lemma ofENat_zero : ofENat 0 = 0 := rfl
@[simp, norm_cast] lemma ofENat_one : ofENat 1 = 1 := rfl
@[simp, norm_cast] lemma ofENat_ofNat (n : ℕ) [n.AtLeastTwo] :
((no_index (OfNat.ofNat n : ℕ∞)) : Cardinal) = OfNat.ofNat n :=
rfl
lemma ofENat_strictMono : StrictMono ofENat :=
WithTop.strictMono_iff.2 ⟨Nat.strictMono_cast, nat_lt_aleph0⟩
@[simp, norm_cast]
lemma ofENat_lt_ofENat {m n : ℕ∞} : (m : Cardinal) < n ↔ m < n :=
ofENat_strictMono.lt_iff_lt
@[gcongr, mono] alias ⟨_, ofENat_lt_ofENat_of_lt⟩ := ofENat_lt_ofENat
@[simp, norm_cast]
lemma ofENat_lt_aleph0 {m : ℕ∞} : (m : Cardinal) < ℵ₀ ↔ m < ⊤ :=
ofENat_lt_ofENat (n := ⊤)
@[simp] lemma ofENat_lt_nat {m : ℕ∞} {n : ℕ} : ofENat m < n ↔ m < n := by norm_cast
@[simp] lemma ofENat_lt_ofNat {m : ℕ∞} {n : ℕ} [n.AtLeastTwo] :
ofENat m < no_index (OfNat.ofNat n) ↔ m < OfNat.ofNat n := ofENat_lt_nat
@[simp] lemma nat_lt_ofENat {m : ℕ} {n : ℕ∞} : (m : Cardinal) < n ↔ m < n := by norm_cast
@[simp] lemma ofENat_pos {m : ℕ∞} : 0 < (m : Cardinal) ↔ 0 < m := by norm_cast
@[simp] lemma one_lt_ofENat {m : ℕ∞} : 1 < (m : Cardinal) ↔ 1 < m := by norm_cast
@[simp, norm_cast] lemma ofNat_lt_ofENat {m : ℕ} [m.AtLeastTwo] {n : ℕ∞} :
no_index (OfNat.ofNat m : Cardinal) < n ↔ OfNat.ofNat m < n := nat_lt_ofENat
lemma ofENat_mono : Monotone ofENat := ofENat_strictMono.monotone
@[simp, norm_cast]
lemma ofENat_le_ofENat {m n : ℕ∞} : (m : Cardinal) ≤ n ↔ m ≤ n := ofENat_strictMono.le_iff_le
@[gcongr, mono] alias ⟨_, ofENat_le_ofENat_of_le⟩ := ofENat_le_ofENat
@[simp] lemma ofENat_le_aleph0 (n : ℕ∞) : ↑n ≤ ℵ₀ := ofENat_le_ofENat.2 le_top
@[simp] lemma ofENat_le_nat {m : ℕ∞} {n : ℕ} : ofENat m ≤ n ↔ m ≤ n := by norm_cast
@[simp] lemma ofENat_le_one {m : ℕ∞} : ofENat m ≤ 1 ↔ m ≤ 1 := by norm_cast
@[simp] lemma ofENat_le_ofNat {m : ℕ∞} {n : ℕ} [n.AtLeastTwo] :
ofENat m ≤ no_index (OfNat.ofNat n) ↔ m ≤ OfNat.ofNat n := ofENat_le_nat
@[simp] lemma nat_le_ofENat {m : ℕ} {n : ℕ∞} : (m : Cardinal) ≤ n ↔ m ≤ n := by norm_cast
@[simp] lemma one_le_ofENat {n : ℕ∞} : 1 ≤ (n : Cardinal) ↔ 1 ≤ n := by norm_cast
@[simp]
lemma ofNat_le_ofENat {m : ℕ} [m.AtLeastTwo] {n : ℕ∞} :
no_index (OfNat.ofNat m : Cardinal) ≤ n ↔ OfNat.ofNat m ≤ n := nat_le_ofENat
lemma ofENat_injective : Injective ofENat := ofENat_strictMono.injective
@[simp, norm_cast]
lemma ofENat_inj {m n : ℕ∞} : (m : Cardinal) = n ↔ m = n := ofENat_injective.eq_iff
@[simp] lemma ofENat_eq_nat {m : ℕ∞} {n : ℕ} : (m : Cardinal) = n ↔ m = n := by norm_cast
@[simp] lemma nat_eq_ofENat {m : ℕ} {n : ℕ∞} : (m : Cardinal) = n ↔ m = n := by norm_cast
@[simp] lemma ofENat_eq_zero {m : ℕ∞} : (m : Cardinal) = 0 ↔ m = 0 := by norm_cast
@[simp] lemma zero_eq_ofENat {m : ℕ∞} : 0 = (m : Cardinal) ↔ m = 0 := by norm_cast; apply eq_comm
@[simp] lemma ofENat_eq_one {m : ℕ∞} : (m : Cardinal) = 1 ↔ m = 1 := by norm_cast
@[simp] lemma one_eq_ofENat {m : ℕ∞} : 1 = (m : Cardinal) ↔ m = 1 := by norm_cast; apply eq_comm
@[simp] lemma ofENat_eq_ofNat {m : ℕ∞} {n : ℕ} [n.AtLeastTwo] :
(m : Cardinal) = no_index (OfNat.ofNat n) ↔ m = OfNat.ofNat n := ofENat_eq_nat
@[simp] lemma ofNat_eq_ofENat {m : ℕ} {n : ℕ∞} [m.AtLeastTwo] :
no_index (OfNat.ofNat m) = (n : Cardinal) ↔ OfNat.ofNat m = n := nat_eq_ofENat
@[simp, norm_cast] lemma lift_ofENat : ∀ m : ℕ∞, lift.{u, v} m = m
| (m : ℕ) => lift_natCast m
| ⊤ => lift_aleph0
@[simp] lemma lift_lt_ofENat {x : Cardinal.{v}} {m : ℕ∞} : lift.{u} x < m ↔ x < m := by
rw [← lift_ofENat.{u, v}, lift_lt]
@[simp] lemma lift_le_ofENat {x : Cardinal.{v}} {m : ℕ∞} : lift.{u} x ≤ m ↔ x ≤ m := by
rw [← lift_ofENat.{u, v}, lift_le]
@[simp] lemma lift_eq_ofENat {x : Cardinal.{v}} {m : ℕ∞} : lift.{u} x = m ↔ x = m := by
rw [← lift_ofENat.{u, v}, lift_inj]
@[simp] lemma ofENat_lt_lift {x : Cardinal.{v}} {m : ℕ∞} : m < lift.{u} x ↔ m < x := by
rw [← lift_ofENat.{u, v}, lift_lt]
@[simp] lemma ofENat_le_lift {x : Cardinal.{v}} {m : ℕ∞} : m ≤ lift.{u} x ↔ m ≤ x := by
rw [← lift_ofENat.{u, v}, lift_le]
@[simp] lemma ofENat_eq_lift {x : Cardinal.{v}} {m : ℕ∞} : m = lift.{u} x ↔ m = x := by
rw [← lift_ofENat.{u, v}, lift_inj]
@[simp]
lemma range_ofENat : range ofENat = Iic ℵ₀ := by
refine (range_subset_iff.2 ofENat_le_aleph0).antisymm fun x (hx : x ≤ ℵ₀) ↦ ?_
rcases hx.lt_or_eq with hlt | rfl
· lift x to ℕ using hlt
exact mem_range_self (x : ℕ∞)
· exact mem_range_self (⊤ : ℕ∞)
instance : CanLift Cardinal ℕ∞ (↑) (· ≤ ℵ₀) where
prf x := (Set.ext_iff.1 range_ofENat x).2
/-- Unbundled version of `Cardinal.toENat`. -/
noncomputable def toENatAux : Cardinal.{u} → ℕ∞ := extend Nat.cast Nat.cast fun _ ↦ ⊤
lemma toENatAux_nat (n : ℕ) : toENatAux n = n := Nat.cast_injective.extend_apply ..
lemma toENatAux_zero : toENatAux 0 = 0 := toENatAux_nat 0
lemma toENatAux_eq_top {a : Cardinal} (ha : ℵ₀ ≤ a) : toENatAux a = ⊤ :=
extend_apply' _ _ _ fun ⟨n, hn⟩ ↦ ha.not_lt <| hn ▸ nat_lt_aleph0 n
lemma toENatAux_ofENat : ∀ n : ℕ∞, toENatAux n = n
| (n : ℕ) => toENatAux_nat n
| ⊤ => toENatAux_eq_top le_rfl
attribute [local simp] toENatAux_nat toENatAux_zero toENatAux_ofENat
lemma toENatAux_gc : GaloisConnection (↑) toENatAux := fun n x ↦ by
cases lt_or_le x ℵ₀ with
| inl hx => lift x to ℕ using hx; simp
| inr hx => simp [toENatAux_eq_top hx, (ofENat_le_aleph0 n).trans hx]
theorem toENatAux_le_nat {x : Cardinal} {n : ℕ} : toENatAux x ≤ n ↔ x ≤ n := by
cases lt_or_le x ℵ₀ with
| inl hx => lift x to ℕ using hx; simp
| inr hx => simp [toENatAux_eq_top hx, (nat_lt_aleph0 n).trans_le hx]
lemma toENatAux_eq_nat {x : Cardinal} {n : ℕ} : toENatAux x = n ↔ x = n := by
simp only [le_antisymm_iff, toENatAux_le_nat, ← toENatAux_gc _, ofENat_nat]
lemma toENatAux_eq_zero {x : Cardinal} : toENatAux x = 0 ↔ x = 0 := toENatAux_eq_nat
/-- Projection from cardinals to `ℕ∞`. Sends all infinite cardinals to `⊤`.
We define this function as a bundled monotone ring homomorphism. -/
noncomputable def toENat : Cardinal.{u} →+*o ℕ∞ where
toFun := toENatAux
map_one' := toENatAux_nat 1
map_mul' x y := by
wlog hle : x ≤ y; · rw [mul_comm, this y x (le_of_not_le hle), mul_comm]
cases lt_or_le y ℵ₀ with
| inl hy =>
lift x to ℕ using hle.trans_lt hy; lift y to ℕ using hy
simp only [← Nat.cast_mul, toENatAux_nat]
| inr hy =>
rcases eq_or_ne x 0 with rfl | hx
· simp
· simp only [toENatAux_eq_top hy]
rw [toENatAux_eq_top, ENat.mul_top]
· rwa [Ne, toENatAux_eq_zero]
· exact le_mul_of_one_le_of_le (one_le_iff_ne_zero.2 hx) hy
map_add' x y := by
wlog hle : x ≤ y; · rw [add_comm, this y x (le_of_not_le hle), add_comm]
cases lt_or_le y ℵ₀ with
| inl hy =>
lift x to ℕ using hle.trans_lt hy; lift y to ℕ using hy
simp only [← Nat.cast_add, toENatAux_nat]
| inr hy =>
simp only [toENatAux_eq_top hy, add_top]
exact toENatAux_eq_top <| le_add_left hy
map_zero' := toENatAux_zero
monotone' := toENatAux_gc.monotone_u
/-- The coercion `Cardinal.ofENat` and the projection `Cardinal.toENat` form a Galois connection.
See also `Cardinal.gciENat`. -/
lemma enat_gc : GaloisConnection (↑) toENat := toENatAux_gc
@[simp] lemma toENat_ofENat (n : ℕ∞) : toENat n = n := toENatAux_ofENat n
@[simp] lemma toENat_comp_ofENat : toENat ∘ (↑) = id := funext toENat_ofENat
/-- The coercion `Cardinal.ofENat` and the projection `Cardinal.toENat`
form a Galois coinsertion. -/
noncomputable def gciENat : GaloisCoinsertion (↑) toENat :=
enat_gc.toGaloisCoinsertion fun n ↦ (toENat_ofENat n).le
lemma toENat_strictMonoOn : StrictMonoOn toENat (Iic ℵ₀) := by
simp only [← range_ofENat, StrictMonoOn, forall_mem_range, toENat_ofENat, ofENat_lt_ofENat]
exact fun _ _ ↦ id
lemma toENat_injOn : InjOn toENat (Iic ℵ₀) := toENat_strictMonoOn.injOn
lemma ofENat_toENat_le (a : Cardinal) : ↑(toENat a) ≤ a := enat_gc.l_u_le _
@[simp]
lemma ofENat_toENat_eq_self {a : Cardinal} : toENat a = a ↔ a ≤ ℵ₀ := by
rw [eq_comm, ← enat_gc.exists_eq_l]
simpa only [mem_range, eq_comm] using Set.ext_iff.1 range_ofENat a
@[simp] alias ⟨_, ofENat_toENat⟩ := ofENat_toENat_eq_self
lemma toENat_nat (n : ℕ) : toENat n = n := map_natCast _ n
@[simp] lemma toENat_le_nat {a : Cardinal} {n : ℕ} : toENat a ≤ n ↔ a ≤ n := toENatAux_le_nat
@[simp] lemma toENat_eq_nat {a : Cardinal} {n : ℕ} : toENat a = n ↔ a = n := toENatAux_eq_nat
@[simp] lemma toENat_eq_zero {a : Cardinal} : toENat a = 0 ↔ a = 0 := toENatAux_eq_zero
@[simp] lemma toENat_le_one {a : Cardinal} : toENat a ≤ 1 ↔ a ≤ 1 := toENat_le_nat
@[simp] lemma toENat_eq_one {a : Cardinal} : toENat a = 1 ↔ a = 1 := toENat_eq_nat
@[simp] lemma toENat_le_ofNat {a : Cardinal} {n : ℕ} [n.AtLeastTwo] :
toENat a ≤ no_index (OfNat.ofNat n) ↔ a ≤ OfNat.ofNat n := toENat_le_nat
@[simp] lemma toENat_eq_ofNat {a : Cardinal} {n : ℕ} [n.AtLeastTwo] :
toENat a = no_index (OfNat.ofNat n) ↔ a = OfNat.ofNat n := toENat_eq_nat
@[simp] lemma toENat_eq_top {a : Cardinal} : toENat a = ⊤ ↔ ℵ₀ ≤ a := enat_gc.u_eq_top
@[simp]
theorem toENat_lift {a : Cardinal.{v}} : toENat (lift.{u} a) = toENat a := by
cases le_total a ℵ₀ with
| inl ha => lift a to ℕ∞ using ha; simp
| inr ha => simp [toENat_eq_top.2, ha]
@[simp, norm_cast]
lemma ofENat_add (m n : ℕ∞) : ofENat (m + n) = m + n := by apply toENat_injOn <;> simp
@[simp] lemma aleph0_add_ofENat (m : ℕ∞) : ℵ₀ + m = ℵ₀ := (ofENat_add ⊤ m).symm
@[simp] lemma ofENat_add_aleph0 (m : ℕ∞) : m + ℵ₀ = ℵ₀ := by rw [add_comm, aleph0_add_ofENat]
@[simp] lemma ofENat_mul_aleph0 {m : ℕ∞} (hm : m ≠ 0) : ↑m * ℵ₀ = ℵ₀ := by
induction m with
| top => exact aleph0_mul_aleph0
| coe m => rw [ofENat_nat, nat_mul_aleph0 (mod_cast hm)]
@[simp] lemma aleph0_mul_ofENat {m : ℕ∞} (hm : m ≠ 0) : ℵ₀ * m = ℵ₀ := by
rw [mul_comm, ofENat_mul_aleph0 hm]
@[simp] lemma ofENat_mul (m n : ℕ∞) : ofENat (m * n) = m * n :=
toENat_injOn (by simp)
(aleph0_mul_aleph0 ▸ mul_le_mul' (ofENat_le_aleph0 _) (ofENat_le_aleph0 _)) (by simp)
/-- The coercion `Cardinal.ofENat` as a bundled homomorphism. -/
def ofENatHom : ℕ∞ →+*o Cardinal where
toFun := (↑)
map_one' := ofENat_one
map_mul' := ofENat_mul
map_zero' := ofENat_zero
map_add' := ofENat_add
monotone' := ofENat_mono
end Cardinal
|
SetTheory\Cardinal\Finite.lean | /-
Copyright (c) 2021 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.Data.ULift
import Mathlib.Data.ZMod.Defs
import Mathlib.SetTheory.Cardinal.PartENat
/-!
# Finite Cardinality Functions
## Main Definitions
* `Nat.card α` is the cardinality of `α` as a natural number.
If `α` is infinite, `Nat.card α = 0`.
* `PartENat.card α` is the cardinality of `α` as an extended natural number
(using `Part ℕ`). If `α` is infinite, `PartENat.card α = ⊤`.
-/
open Cardinal Function
noncomputable section
variable {α β : Type*}
universe u v
namespace Nat
/-- `Nat.card α` is the cardinality of `α` as a natural number.
If `α` is infinite, `Nat.card α = 0`. -/
protected def card (α : Type*) : ℕ :=
toNat (mk α)
@[simp]
theorem card_eq_fintype_card [Fintype α] : Nat.card α = Fintype.card α :=
mk_toNat_eq_card
/-- Because this theorem takes `Fintype α` as a non-instance argument, it can be used in particular
when `Fintype.card` ends up with different instance than the one found by inference -/
theorem _root_.Fintype.card_eq_nat_card {_ : Fintype α} : Fintype.card α = Nat.card α :=
mk_toNat_eq_card.symm
lemma card_eq_finsetCard (s : Finset α) : Nat.card s = s.card := by
simp only [Nat.card_eq_fintype_card, Fintype.card_coe]
lemma card_eq_card_toFinset (s : Set α) [Fintype s] : Nat.card s = s.toFinset.card := by
simp only [← Nat.card_eq_finsetCard, s.mem_toFinset]
lemma card_eq_card_finite_toFinset {s : Set α} (hs : s.Finite) : Nat.card s = hs.toFinset.card := by
simp only [← Nat.card_eq_finsetCard, hs.mem_toFinset]
@[simp] theorem card_of_isEmpty [IsEmpty α] : Nat.card α = 0 := by simp [Nat.card]
@[simp] lemma card_eq_zero_of_infinite [Infinite α] : Nat.card α = 0 := mk_toNat_of_infinite
lemma _root_.Set.Infinite.card_eq_zero {s : Set α} (hs : s.Infinite) : Nat.card s = 0 :=
@card_eq_zero_of_infinite _ hs.to_subtype
lemma card_eq_zero : Nat.card α = 0 ↔ IsEmpty α ∨ Infinite α := by
simp [Nat.card, mk_eq_zero_iff, aleph0_le_mk_iff]
lemma card_ne_zero : Nat.card α ≠ 0 ↔ Nonempty α ∧ Finite α := by simp [card_eq_zero, not_or]
lemma card_pos_iff : 0 < Nat.card α ↔ Nonempty α ∧ Finite α := by
simp [Nat.card, mk_eq_zero_iff, mk_lt_aleph0_iff]
@[simp] lemma card_pos [Nonempty α] [Finite α] : 0 < Nat.card α := card_pos_iff.2 ⟨‹_›, ‹_›⟩
theorem finite_of_card_ne_zero (h : Nat.card α ≠ 0) : Finite α := (card_ne_zero.1 h).2
theorem card_congr (f : α ≃ β) : Nat.card α = Nat.card β :=
Cardinal.toNat_congr f
lemma card_le_card_of_injective {α : Type u} {β : Type v} [Finite β] (f : α → β)
(hf : Injective f) : Nat.card α ≤ Nat.card β := by
simpa using toNat_le_toNat (lift_mk_le_lift_mk_of_injective hf) (by simp [lt_aleph0_of_finite])
lemma card_le_card_of_surjective {α : Type u} {β : Type v} [Finite α] (f : α → β)
(hf : Surjective f) : Nat.card β ≤ Nat.card α := by
have : lift.{u} #β ≤ lift.{v} #α := mk_le_of_surjective (ULift.map_surjective.2 hf)
simpa using toNat_le_toNat this (by simp [lt_aleph0_of_finite])
theorem card_eq_of_bijective (f : α → β) (hf : Function.Bijective f) : Nat.card α = Nat.card β :=
card_congr (Equiv.ofBijective f hf)
protected theorem bijective_iff_injective_and_card [Finite β] (f : α → β) :
Bijective f ↔ Injective f ∧ Nat.card α = Nat.card β := by
rw [Bijective, and_congr_right_iff]
intro h
have := Fintype.ofFinite β
have := Fintype.ofInjective f h
revert h
rw [← and_congr_right_iff, ← Bijective,
card_eq_fintype_card, card_eq_fintype_card, Fintype.bijective_iff_injective_and_card]
protected theorem bijective_iff_surjective_and_card [Finite α] (f : α → β) :
Bijective f ↔ Surjective f ∧ Nat.card α = Nat.card β := by
classical
rw [and_comm, Bijective, and_congr_left_iff]
intro h
have := Fintype.ofFinite α
have := Fintype.ofSurjective f h
revert h
rw [← and_congr_left_iff, ← Bijective, ← and_comm,
card_eq_fintype_card, card_eq_fintype_card, Fintype.bijective_iff_surjective_and_card]
theorem _root_.Function.Injective.bijective_of_nat_card_le [Finite β] {f : α → β}
(inj : Injective f) (hc : Nat.card β ≤ Nat.card α) : Bijective f :=
(Nat.bijective_iff_injective_and_card f).mpr
⟨inj, hc.antisymm (card_le_card_of_injective f inj) |>.symm⟩
theorem _root_.Function.Surjective.bijective_of_nat_card_le [Finite α] {f : α → β}
(surj : Surjective f) (hc : Nat.card α ≤ Nat.card β) : Bijective f :=
(Nat.bijective_iff_surjective_and_card f).mpr
⟨surj, hc.antisymm (card_le_card_of_surjective f surj)⟩
theorem card_eq_of_equiv_fin {α : Type*} {n : ℕ} (f : α ≃ Fin n) : Nat.card α = n := by
simpa only [card_eq_fintype_card, Fintype.card_fin] using card_congr f
section Set
open Set
variable {s t : Set α}
lemma card_mono (ht : t.Finite) (h : s ⊆ t) : Nat.card s ≤ Nat.card t :=
toNat_le_toNat (mk_le_mk_of_subset h) ht.lt_aleph0
lemma card_image_le {f : α → β} (hs : s.Finite) : Nat.card (f '' s) ≤ Nat.card s :=
have := hs.to_subtype; card_le_card_of_surjective (imageFactorization f s) surjective_onto_image
lemma card_image_of_injOn {f : α → β} (hf : s.InjOn f) : Nat.card (f '' s) = Nat.card s := by
classical
obtain hs | hs := s.finite_or_infinite
· have := hs.fintype
have := fintypeImage s f
simp_rw [Nat.card_eq_fintype_card, Set.card_image_of_inj_on hf]
· have := hs.to_subtype
have := (hs.image hf).to_subtype
simp [Nat.card_eq_zero_of_infinite]
lemma card_image_of_injective {f : α → β} (hf : Injective f) (s : Set α) :
Nat.card (f '' s) = Nat.card s := card_image_of_injOn hf.injOn
lemma card_image_equiv (e : α ≃ β) : Nat.card (e '' s) = Nat.card s :=
Nat.card_congr (e.image s).symm
lemma card_preimage_of_injOn {f : α → β} {s : Set β} (hf : (f ⁻¹' s).InjOn f) (hsf : s ⊆ range f) :
Nat.card (f ⁻¹' s) = Nat.card s := by
rw [← Nat.card_image_of_injOn hf, image_preimage_eq_iff.2 hsf]
lemma card_preimage_of_injective {f : α → β} {s : Set β} (hf : Injective f) (hsf : s ⊆ range f) :
Nat.card (f ⁻¹' s) = Nat.card s := card_preimage_of_injOn hf.injOn hsf
end Set
/-- If the cardinality is positive, that means it is a finite type, so there is
an equivalence between `α` and `Fin (Nat.card α)`. See also `Finite.equivFin`. -/
def equivFinOfCardPos {α : Type*} (h : Nat.card α ≠ 0) : α ≃ Fin (Nat.card α) := by
cases fintypeOrInfinite α
· simpa only [card_eq_fintype_card] using Fintype.equivFin α
· simp only [card_eq_zero_of_infinite, ne_eq, not_true_eq_false] at h
theorem card_of_subsingleton (a : α) [Subsingleton α] : Nat.card α = 1 := by
letI := Fintype.ofSubsingleton a
rw [card_eq_fintype_card, Fintype.card_ofSubsingleton a]
-- @[simp] -- Porting note (#10618): simp can prove this
theorem card_unique [Unique α] : Nat.card α = 1 :=
card_of_subsingleton default
theorem card_eq_one_iff_unique : Nat.card α = 1 ↔ Subsingleton α ∧ Nonempty α :=
Cardinal.toNat_eq_one_iff_unique
theorem card_eq_one_iff_exists : Nat.card α = 1 ↔ ∃ x : α, ∀ y : α, y = x := by
rw [card_eq_one_iff_unique]
exact ⟨fun ⟨s, ⟨a⟩⟩ ↦ ⟨a, fun x ↦ s.elim x a⟩, fun ⟨x, h⟩ ↦ ⟨subsingleton_of_forall_eq x h, ⟨x⟩⟩⟩
theorem card_eq_two_iff : Nat.card α = 2 ↔ ∃ x y : α, x ≠ y ∧ {x, y} = @Set.univ α :=
toNat_eq_ofNat.trans mk_eq_two_iff
theorem card_eq_two_iff' (x : α) : Nat.card α = 2 ↔ ∃! y, y ≠ x :=
toNat_eq_ofNat.trans (mk_eq_two_iff' x)
@[simp]
theorem card_sum [Finite α] [Finite β] : Nat.card (α ⊕ β) = Nat.card α + Nat.card β := by
have := Fintype.ofFinite α
have := Fintype.ofFinite β
simp_rw [Nat.card_eq_fintype_card, Fintype.card_sum]
@[simp]
theorem card_prod (α β : Type*) : Nat.card (α × β) = Nat.card α * Nat.card β := by
simp only [Nat.card, mk_prod, toNat_mul, toNat_lift]
@[simp]
theorem card_ulift (α : Type*) : Nat.card (ULift α) = Nat.card α :=
card_congr Equiv.ulift
@[simp]
theorem card_plift (α : Type*) : Nat.card (PLift α) = Nat.card α :=
card_congr Equiv.plift
theorem card_pi {β : α → Type*} [Fintype α] : Nat.card (∀ a, β a) = ∏ a, Nat.card (β a) := by
simp_rw [Nat.card, mk_pi, prod_eq_of_fintype, toNat_lift, map_prod]
theorem card_fun [Finite α] : Nat.card (α → β) = Nat.card β ^ Nat.card α := by
haveI := Fintype.ofFinite α
rw [Nat.card_pi, Finset.prod_const, Finset.card_univ, ← Nat.card_eq_fintype_card]
@[simp]
theorem card_zmod (n : ℕ) : Nat.card (ZMod n) = n := by
cases n
· exact @Nat.card_eq_zero_of_infinite _ Int.infinite
· rw [Nat.card_eq_fintype_card, ZMod.card]
end Nat
namespace Set
lemma card_singleton_prod (a : α) (t : Set β) : Nat.card ({a} ×ˢ t) = Nat.card t := by
rw [singleton_prod, Nat.card_image_of_injective (Prod.mk.inj_left a)]
lemma card_prod_singleton (s : Set α) (b : β) : Nat.card (s ×ˢ {b}) = Nat.card s := by
rw [prod_singleton, Nat.card_image_of_injective (Prod.mk.inj_right b)]
end Set
namespace PartENat
/-- `PartENat.card α` is the cardinality of `α` as an extended natural number.
If `α` is infinite, `PartENat.card α = ⊤`. -/
def card (α : Type*) : PartENat :=
toPartENat (mk α)
@[simp]
theorem card_eq_coe_fintype_card [Fintype α] : card α = Fintype.card α :=
mk_toPartENat_eq_coe_card
@[simp]
theorem card_eq_top_of_infinite [Infinite α] : card α = ⊤ :=
mk_toPartENat_of_infinite
@[simp]
theorem card_sum (α β : Type*) :
PartENat.card (α ⊕ β) = PartENat.card α + PartENat.card β := by
simp only [PartENat.card, Cardinal.mk_sum, map_add, Cardinal.toPartENat_lift]
theorem card_congr {α : Type*} {β : Type*} (f : α ≃ β) : PartENat.card α = PartENat.card β :=
Cardinal.toPartENat_congr f
@[simp] lemma card_ulift (α : Type*) : card (ULift α) = card α := card_congr Equiv.ulift
@[simp] lemma card_plift (α : Type*) : card (PLift α) = card α := card_congr Equiv.plift
theorem card_image_of_injOn {α : Type u} {β : Type v} {f : α → β} {s : Set α} (h : Set.InjOn f s) :
card (f '' s) = card s :=
card_congr (Equiv.Set.imageOfInjOn f s h).symm
theorem card_image_of_injective {α : Type u} {β : Type v} (f : α → β) (s : Set α)
(h : Function.Injective f) : card (f '' s) = card s := card_image_of_injOn h.injOn
-- Should I keep the 6 following lemmas ?
-- TODO: Add ofNat, zero, and one versions for simp confluence
@[simp]
theorem _root_.Cardinal.natCast_le_toPartENat_iff {n : ℕ} {c : Cardinal} :
↑n ≤ toPartENat c ↔ ↑n ≤ c := by
rw [← toPartENat_natCast n, toPartENat_le_iff_of_le_aleph0 (le_of_lt (nat_lt_aleph0 n))]
@[simp]
theorem _root_.Cardinal.toPartENat_le_natCast_iff {c : Cardinal} {n : ℕ} :
toPartENat c ≤ n ↔ c ≤ n := by
rw [← toPartENat_natCast n, toPartENat_le_iff_of_lt_aleph0 (nat_lt_aleph0 n)]
@[simp]
theorem _root_.Cardinal.natCast_eq_toPartENat_iff {n : ℕ} {c : Cardinal} :
↑n = toPartENat c ↔ ↑n = c := by
rw [le_antisymm_iff, le_antisymm_iff, Cardinal.toPartENat_le_natCast_iff,
Cardinal.natCast_le_toPartENat_iff]
@[simp]
theorem _root_.Cardinal.toPartENat_eq_natCast_iff {c : Cardinal} {n : ℕ} :
Cardinal.toPartENat c = n ↔ c = n := by
rw [eq_comm, Cardinal.natCast_eq_toPartENat_iff, eq_comm]
@[simp]
theorem _root_.Cardinal.natCast_lt_toPartENat_iff {n : ℕ} {c : Cardinal} :
↑n < toPartENat c ↔ ↑n < c := by
simp only [← not_le, Cardinal.toPartENat_le_natCast_iff]
@[simp]
theorem _root_.Cardinal.toPartENat_lt_natCast_iff {n : ℕ} {c : Cardinal} :
toPartENat c < ↑n ↔ c < ↑n := by
simp only [← not_le, Cardinal.natCast_le_toPartENat_iff]
theorem card_eq_zero_iff_empty (α : Type*) : card α = 0 ↔ IsEmpty α := by
rw [← Cardinal.mk_eq_zero_iff]
conv_rhs => rw [← Nat.cast_zero]
simp only [← Cardinal.toPartENat_eq_natCast_iff]
simp only [PartENat.card, Nat.cast_zero]
theorem card_le_one_iff_subsingleton (α : Type*) : card α ≤ 1 ↔ Subsingleton α := by
rw [← le_one_iff_subsingleton]
conv_rhs => rw [← Nat.cast_one]
rw [← Cardinal.toPartENat_le_natCast_iff]
simp only [PartENat.card, Nat.cast_one]
theorem one_lt_card_iff_nontrivial (α : Type*) : 1 < card α ↔ Nontrivial α := by
rw [← Cardinal.one_lt_iff_nontrivial]
conv_rhs => rw [← Nat.cast_one]
rw [← natCast_lt_toPartENat_iff]
simp only [PartENat.card, Nat.cast_one]
end PartENat
|
SetTheory\Cardinal\Ordinal.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Floris van Doorn
-/
import Mathlib.Data.Finsupp.Multiset
import Mathlib.Order.Bounded
import Mathlib.SetTheory.Cardinal.PartENat
import Mathlib.SetTheory.Ordinal.Principal
import Mathlib.Tactic.Linarith
/-!
# Cardinals and ordinals
Relationships between cardinals and ordinals, properties of cardinals that are proved
using ordinals.
## Main definitions
* The function `Cardinal.aleph'` gives the cardinals listed by their ordinal
index, and is the inverse of `Cardinal.aleph/idx`.
`aleph' n = n`, `aleph' ω = ℵ₀`, `aleph' (ω + 1) = succ ℵ₀`, etc.
It is an order isomorphism between ordinals and cardinals.
* The function `Cardinal.aleph` gives the infinite cardinals listed by their
ordinal index. `aleph 0 = ℵ₀`, `aleph 1 = succ ℵ₀` is the first
uncountable cardinal, and so on. The notation `ω_` combines the latter with `Cardinal.ord`,
giving an enumeration of (infinite) initial ordinals.
Thus `ω_ 0 = ω` and `ω₁ = ω_ 1` is the first uncountable ordinal.
* The function `Cardinal.beth` enumerates the Beth cardinals. `beth 0 = ℵ₀`,
`beth (succ o) = 2 ^ beth o`, and for a limit ordinal `o`, `beth o` is the supremum of `beth a`
for `a < o`.
## Main Statements
* `Cardinal.mul_eq_max` and `Cardinal.add_eq_max` state that the product (resp. sum) of two infinite
cardinals is just their maximum. Several variations around this fact are also given.
* `Cardinal.mk_list_eq_mk` : when `α` is infinite, `α` and `List α` have the same cardinality.
* simp lemmas for inequalities between `bit0 a` and `bit1 b` are registered, making `simp`
able to prove inequalities about numeral cardinals.
## Tags
cardinal arithmetic (for infinite cardinals)
-/
noncomputable section
open Function Set Cardinal Equiv Order Ordinal
open scoped Classical
universe u v w
namespace Cardinal
section UsingOrdinals
theorem ord_isLimit {c} (co : ℵ₀ ≤ c) : (ord c).IsLimit := by
refine ⟨fun h => aleph0_ne_zero ?_, fun a => lt_imp_lt_of_le_imp_le fun h => ?_⟩
· rw [← Ordinal.le_zero, ord_le] at h
simpa only [card_zero, nonpos_iff_eq_zero] using co.trans h
· rw [ord_le] at h ⊢
rwa [← @add_one_of_aleph0_le (card a), ← card_succ]
rw [← ord_le, ← le_succ_of_isLimit, ord_le]
· exact co.trans h
· rw [ord_aleph0]
exact omega_isLimit
theorem noMaxOrder {c} (h : ℵ₀ ≤ c) : NoMaxOrder c.ord.out.α :=
Ordinal.out_no_max_of_succ_lt (ord_isLimit h).2
/-! ### Aleph cardinals -/
section aleph
/-- The `aleph'` index function, which gives the ordinal index of a cardinal.
(The `aleph'` part is because unlike `aleph` this counts also the
finite stages. So `alephIdx n = n`, `alephIdx ω = ω`,
`alephIdx ℵ₁ = ω + 1` and so on.)
In this definition, we register additionally that this function is an initial segment,
i.e., it is order preserving and its range is an initial segment of the ordinals.
For the basic function version, see `alephIdx`.
For an upgraded version stating that the range is everything, see `AlephIdx.rel_iso`. -/
def alephIdx.initialSeg : @InitialSeg Cardinal Ordinal (· < ·) (· < ·) :=
@RelEmbedding.collapse Cardinal Ordinal (· < ·) (· < ·) _ Cardinal.ord.orderEmbedding.ltEmbedding
/-- The `aleph'` index function, which gives the ordinal index of a cardinal.
(The `aleph'` part is because unlike `aleph` this counts also the
finite stages. So `alephIdx n = n`, `alephIdx ω = ω`,
`alephIdx ℵ₁ = ω + 1` and so on.)
For an upgraded version stating that the range is everything, see `AlephIdx.rel_iso`. -/
def alephIdx : Cardinal → Ordinal :=
alephIdx.initialSeg
@[simp]
theorem alephIdx.initialSeg_coe : (alephIdx.initialSeg : Cardinal → Ordinal) = alephIdx :=
rfl
@[simp]
theorem alephIdx_lt {a b} : alephIdx a < alephIdx b ↔ a < b :=
alephIdx.initialSeg.toRelEmbedding.map_rel_iff
@[simp]
theorem alephIdx_le {a b} : alephIdx a ≤ alephIdx b ↔ a ≤ b := by
rw [← not_lt, ← not_lt, alephIdx_lt]
theorem alephIdx.init {a b} : b < alephIdx a → ∃ c, alephIdx c = b :=
alephIdx.initialSeg.init
/-- The `aleph'` index function, which gives the ordinal index of a cardinal.
(The `aleph'` part is because unlike `aleph` this counts also the
finite stages. So `alephIdx n = n`, `alephIdx ℵ₀ = ω`,
`alephIdx ℵ₁ = ω + 1` and so on.)
In this version, we register additionally that this function is an order isomorphism
between cardinals and ordinals.
For the basic function version, see `alephIdx`. -/
def alephIdx.relIso : @RelIso Cardinal.{u} Ordinal.{u} (· < ·) (· < ·) :=
@RelIso.ofSurjective Cardinal.{u} Ordinal.{u} (· < ·) (· < ·) alephIdx.initialSeg.{u} <|
(InitialSeg.eq_or_principal alephIdx.initialSeg.{u}).resolve_right fun ⟨o, e⟩ => by
have : ∀ c, alephIdx c < o := fun c => (e _).2 ⟨_, rfl⟩
refine Ordinal.inductionOn o ?_ this; intro α r _ h
let s := ⨆ a, invFun alephIdx (Ordinal.typein r a)
apply (lt_succ s).not_le
have I : Injective.{u+2, u+2} alephIdx := alephIdx.initialSeg.toEmbedding.injective
simpa only [typein_enum, leftInverse_invFun I (succ s)] using
le_ciSup
(Cardinal.bddAbove_range.{u, u} fun a : α => invFun alephIdx (Ordinal.typein r a))
(Ordinal.enum r _ (h (succ s)))
@[simp]
theorem alephIdx.relIso_coe : (alephIdx.relIso : Cardinal → Ordinal) = alephIdx :=
rfl
@[simp]
theorem type_cardinal : @type Cardinal (· < ·) _ = Ordinal.univ.{u, u + 1} := by
rw [Ordinal.univ_id]; exact Quotient.sound ⟨alephIdx.relIso⟩
@[simp]
theorem mk_cardinal : #Cardinal = univ.{u, u + 1} := by
simpa only [card_type, card_univ] using congr_arg card type_cardinal
/-- The `aleph'` function gives the cardinals listed by their ordinal
index, and is the inverse of `aleph_idx`.
`aleph' n = n`, `aleph' ω = ω`, `aleph' (ω + 1) = succ ℵ₀`, etc.
In this version, we register additionally that this function is an order isomorphism
between ordinals and cardinals.
For the basic function version, see `aleph'`. -/
def Aleph'.relIso :=
Cardinal.alephIdx.relIso.symm
/-- The `aleph'` function gives the cardinals listed by their ordinal
index, and is the inverse of `aleph_idx`.
`aleph' n = n`, `aleph' ω = ω`, `aleph' (ω + 1) = succ ℵ₀`, etc. -/
def aleph' : Ordinal → Cardinal :=
Aleph'.relIso
@[simp]
theorem aleph'.relIso_coe : (Aleph'.relIso : Ordinal → Cardinal) = aleph' :=
rfl
@[simp]
theorem aleph'_lt {o₁ o₂ : Ordinal} : aleph' o₁ < aleph' o₂ ↔ o₁ < o₂ :=
Aleph'.relIso.map_rel_iff
@[simp]
theorem aleph'_le {o₁ o₂ : Ordinal} : aleph' o₁ ≤ aleph' o₂ ↔ o₁ ≤ o₂ :=
le_iff_le_iff_lt_iff_lt.2 aleph'_lt
@[simp]
theorem aleph'_alephIdx (c : Cardinal) : aleph' c.alephIdx = c :=
Cardinal.alephIdx.relIso.toEquiv.symm_apply_apply c
@[simp]
theorem alephIdx_aleph' (o : Ordinal) : (aleph' o).alephIdx = o :=
Cardinal.alephIdx.relIso.toEquiv.apply_symm_apply o
@[simp]
theorem aleph'_zero : aleph' 0 = 0 := by
rw [← nonpos_iff_eq_zero, ← aleph'_alephIdx 0, aleph'_le]
apply Ordinal.zero_le
@[simp]
theorem aleph'_succ {o : Ordinal} : aleph' (succ o) = succ (aleph' o) := by
apply (succ_le_of_lt <| aleph'_lt.2 <| lt_succ o).antisymm' (Cardinal.alephIdx_le.1 <| _)
rw [alephIdx_aleph', succ_le_iff, ← aleph'_lt, aleph'_alephIdx]
apply lt_succ
@[simp]
theorem aleph'_nat : ∀ n : ℕ, aleph' n = n
| 0 => aleph'_zero
| n + 1 => show aleph' (succ n) = n.succ by rw [aleph'_succ, aleph'_nat n, nat_succ]
theorem aleph'_le_of_limit {o : Ordinal} (l : o.IsLimit) {c} :
aleph' o ≤ c ↔ ∀ o' < o, aleph' o' ≤ c :=
⟨fun h o' h' => (aleph'_le.2 <| h'.le).trans h, fun h => by
rw [← aleph'_alephIdx c, aleph'_le, limit_le l]
intro x h'
rw [← aleph'_le, aleph'_alephIdx]
exact h _ h'⟩
theorem aleph'_limit {o : Ordinal} (ho : o.IsLimit) : aleph' o = ⨆ a : Iio o, aleph' a := by
refine le_antisymm ?_ (ciSup_le' fun i => aleph'_le.2 (le_of_lt i.2))
rw [aleph'_le_of_limit ho]
exact fun a ha => le_ciSup (bddAbove_of_small _) (⟨a, ha⟩ : Iio o)
@[simp]
theorem aleph'_omega : aleph' ω = ℵ₀ :=
eq_of_forall_ge_iff fun c => by
simp only [aleph'_le_of_limit omega_isLimit, lt_omega, exists_imp, aleph0_le]
exact forall_swap.trans (forall_congr' fun n => by simp only [forall_eq, aleph'_nat])
/-- `aleph'` and `aleph_idx` form an equivalence between `Ordinal` and `Cardinal` -/
@[simp]
def aleph'Equiv : Ordinal ≃ Cardinal :=
⟨aleph', alephIdx, alephIdx_aleph', aleph'_alephIdx⟩
/-- The `aleph` function gives the infinite cardinals listed by their
ordinal index. `aleph 0 = ℵ₀`, `aleph 1 = succ ℵ₀` is the first
uncountable cardinal, and so on. -/
def aleph (o : Ordinal) : Cardinal :=
aleph' (ω + o)
@[simp]
theorem aleph_lt {o₁ o₂ : Ordinal} : aleph o₁ < aleph o₂ ↔ o₁ < o₂ :=
aleph'_lt.trans (add_lt_add_iff_left _)
@[simp]
theorem aleph_le {o₁ o₂ : Ordinal} : aleph o₁ ≤ aleph o₂ ↔ o₁ ≤ o₂ :=
le_iff_le_iff_lt_iff_lt.2 aleph_lt
@[simp]
theorem max_aleph_eq (o₁ o₂ : Ordinal) : max (aleph o₁) (aleph o₂) = aleph (max o₁ o₂) := by
rcases le_total (aleph o₁) (aleph o₂) with h | h
· rw [max_eq_right h, max_eq_right (aleph_le.1 h)]
· rw [max_eq_left h, max_eq_left (aleph_le.1 h)]
@[simp]
theorem aleph_succ {o : Ordinal} : aleph (succ o) = succ (aleph o) := by
rw [aleph, add_succ, aleph'_succ, aleph]
@[simp]
theorem aleph_zero : aleph 0 = ℵ₀ := by rw [aleph, add_zero, aleph'_omega]
theorem aleph_limit {o : Ordinal} (ho : o.IsLimit) : aleph o = ⨆ a : Iio o, aleph a := by
apply le_antisymm _ (ciSup_le' _)
· rw [aleph, aleph'_limit (ho.add _)]
refine ciSup_mono' (bddAbove_of_small _) ?_
rintro ⟨i, hi⟩
cases' lt_or_le i ω with h h
· rcases lt_omega.1 h with ⟨n, rfl⟩
use ⟨0, ho.pos⟩
simpa using (nat_lt_aleph0 n).le
· exact ⟨⟨_, (sub_lt_of_le h).2 hi⟩, aleph'_le.2 (le_add_sub _ _)⟩
· exact fun i => aleph_le.2 (le_of_lt i.2)
theorem aleph0_le_aleph' {o : Ordinal} : ℵ₀ ≤ aleph' o ↔ ω ≤ o := by rw [← aleph'_omega, aleph'_le]
theorem aleph0_le_aleph (o : Ordinal) : ℵ₀ ≤ aleph o := by
rw [aleph, aleph0_le_aleph']
apply Ordinal.le_add_right
theorem aleph'_pos {o : Ordinal} (ho : 0 < o) : 0 < aleph' o := by rwa [← aleph'_zero, aleph'_lt]
theorem aleph_pos (o : Ordinal) : 0 < aleph o :=
aleph0_pos.trans_le (aleph0_le_aleph o)
@[simp]
theorem aleph_toNat (o : Ordinal) : toNat (aleph o) = 0 :=
toNat_apply_of_aleph0_le <| aleph0_le_aleph o
@[simp]
theorem aleph_toPartENat (o : Ordinal) : toPartENat (aleph o) = ⊤ :=
toPartENat_apply_of_aleph0_le <| aleph0_le_aleph o
instance nonempty_out_aleph (o : Ordinal) : Nonempty (aleph o).ord.out.α := by
rw [out_nonempty_iff_ne_zero, ← ord_zero]
exact fun h => (ord_injective h).not_gt (aleph_pos o)
theorem ord_aleph_isLimit (o : Ordinal) : (aleph o).ord.IsLimit :=
ord_isLimit <| aleph0_le_aleph _
instance (o : Ordinal) : NoMaxOrder (aleph o).ord.out.α :=
out_no_max_of_succ_lt (ord_aleph_isLimit o).2
theorem exists_aleph {c : Cardinal} : ℵ₀ ≤ c ↔ ∃ o, c = aleph o :=
⟨fun h =>
⟨alephIdx c - ω, by
rw [aleph, Ordinal.add_sub_cancel_of_le, aleph'_alephIdx]
rwa [← aleph0_le_aleph', aleph'_alephIdx]⟩,
fun ⟨o, e⟩ => e.symm ▸ aleph0_le_aleph _⟩
theorem aleph'_isNormal : IsNormal (ord ∘ aleph') :=
⟨fun o => ord_lt_ord.2 <| aleph'_lt.2 <| lt_succ o, fun o l a => by
simp [ord_le, aleph'_le_of_limit l]⟩
theorem aleph_isNormal : IsNormal (ord ∘ aleph) :=
aleph'_isNormal.trans <| add_isNormal ω
theorem succ_aleph0 : succ ℵ₀ = aleph 1 := by rw [← aleph_zero, ← aleph_succ, Ordinal.succ_zero]
theorem aleph0_lt_aleph_one : ℵ₀ < aleph 1 := by
rw [← succ_aleph0]
apply lt_succ
theorem countable_iff_lt_aleph_one {α : Type*} (s : Set α) : s.Countable ↔ #s < aleph 1 := by
rw [← succ_aleph0, lt_succ_iff, le_aleph0_iff_set_countable]
/-- Ordinals that are cardinals are unbounded. -/
theorem ord_card_unbounded : Unbounded (· < ·) { b : Ordinal | b.card.ord = b } :=
unbounded_lt_iff.2 fun a =>
⟨_,
⟨by
dsimp
rw [card_ord], (lt_ord_succ_card a).le⟩⟩
theorem eq_aleph'_of_eq_card_ord {o : Ordinal} (ho : o.card.ord = o) : ∃ a, (aleph' a).ord = o :=
⟨Cardinal.alephIdx.relIso o.card, by simpa using ho⟩
/-- `ord ∘ aleph'` enumerates the ordinals that are cardinals. -/
theorem ord_aleph'_eq_enum_card : ord ∘ aleph' = enumOrd { b : Ordinal | b.card.ord = b } := by
rw [← eq_enumOrd _ ord_card_unbounded, range_eq_iff]
exact
⟨aleph'_isNormal.strictMono,
⟨fun a => by
dsimp
rw [card_ord], fun b hb => eq_aleph'_of_eq_card_ord hb⟩⟩
/-- Infinite ordinals that are cardinals are unbounded. -/
theorem ord_card_unbounded' : Unbounded (· < ·) { b : Ordinal | b.card.ord = b ∧ ω ≤ b } :=
(unbounded_lt_inter_le ω).2 ord_card_unbounded
theorem eq_aleph_of_eq_card_ord {o : Ordinal} (ho : o.card.ord = o) (ho' : ω ≤ o) :
∃ a, (aleph a).ord = o := by
cases' eq_aleph'_of_eq_card_ord ho with a ha
use a - ω
unfold aleph
rwa [Ordinal.add_sub_cancel_of_le]
rwa [← aleph0_le_aleph', ← ord_le_ord, ha, ord_aleph0]
/-- `ord ∘ aleph` enumerates the infinite ordinals that are cardinals. -/
theorem ord_aleph_eq_enum_card :
ord ∘ aleph = enumOrd { b : Ordinal | b.card.ord = b ∧ ω ≤ b } := by
rw [← eq_enumOrd _ ord_card_unbounded']
use aleph_isNormal.strictMono
rw [range_eq_iff]
refine ⟨fun a => ⟨?_, ?_⟩, fun b hb => eq_aleph_of_eq_card_ord hb.1 hb.2⟩
· rw [Function.comp_apply, card_ord]
· rw [← ord_aleph0, Function.comp_apply, ord_le_ord]
exact aleph0_le_aleph _
end aleph
/-! ### Beth cardinals -/
section beth
/-- Beth numbers are defined so that `beth 0 = ℵ₀`, `beth (succ o) = 2 ^ (beth o)`, and when `o` is
a limit ordinal, `beth o` is the supremum of `beth o'` for `o' < o`.
Assuming the generalized continuum hypothesis, which is undecidable in ZFC, `beth o = aleph o` for
every `o`. -/
def beth (o : Ordinal.{u}) : Cardinal.{u} :=
limitRecOn o aleph0 (fun _ x => (2 : Cardinal) ^ x) fun a _ IH => ⨆ b : Iio a, IH b.1 b.2
@[simp]
theorem beth_zero : beth 0 = aleph0 :=
limitRecOn_zero _ _ _
@[simp]
theorem beth_succ (o : Ordinal) : beth (succ o) = 2 ^ beth o :=
limitRecOn_succ _ _ _ _
theorem beth_limit {o : Ordinal} : o.IsLimit → beth o = ⨆ a : Iio o, beth a :=
limitRecOn_limit _ _ _ _
theorem beth_strictMono : StrictMono beth := by
intro a b
induction' b using Ordinal.induction with b IH generalizing a
intro h
rcases zero_or_succ_or_limit b with (rfl | ⟨c, rfl⟩ | hb)
· exact (Ordinal.not_lt_zero a h).elim
· rw [lt_succ_iff] at h
rw [beth_succ]
apply lt_of_le_of_lt _ (cantor _)
rcases eq_or_lt_of_le h with (rfl | h)
· rfl
exact (IH c (lt_succ c) h).le
· apply (cantor _).trans_le
rw [beth_limit hb, ← beth_succ]
exact le_ciSup (bddAbove_of_small _) (⟨_, hb.succ_lt h⟩ : Iio b)
theorem beth_mono : Monotone beth :=
beth_strictMono.monotone
@[simp]
theorem beth_lt {o₁ o₂ : Ordinal} : beth o₁ < beth o₂ ↔ o₁ < o₂ :=
beth_strictMono.lt_iff_lt
@[simp]
theorem beth_le {o₁ o₂ : Ordinal} : beth o₁ ≤ beth o₂ ↔ o₁ ≤ o₂ :=
beth_strictMono.le_iff_le
theorem aleph_le_beth (o : Ordinal) : aleph o ≤ beth o := by
induction o using limitRecOn with
| H₁ => simp
| H₂ o h =>
rw [aleph_succ, beth_succ, succ_le_iff]
exact (cantor _).trans_le (power_le_power_left two_ne_zero h)
| H₃ o ho IH =>
rw [aleph_limit ho, beth_limit ho]
exact ciSup_mono (bddAbove_of_small _) fun x => IH x.1 x.2
theorem aleph0_le_beth (o : Ordinal) : ℵ₀ ≤ beth o :=
(aleph0_le_aleph o).trans <| aleph_le_beth o
theorem beth_pos (o : Ordinal) : 0 < beth o :=
aleph0_pos.trans_le <| aleph0_le_beth o
theorem beth_ne_zero (o : Ordinal) : beth o ≠ 0 :=
(beth_pos o).ne'
theorem beth_normal : IsNormal.{u} fun o => (beth o).ord :=
(isNormal_iff_strictMono_limit _).2
⟨ord_strictMono.comp beth_strictMono, fun o ho a ha => by
rw [beth_limit ho, ord_le]
exact ciSup_le' fun b => ord_le.1 (ha _ b.2)⟩
end beth
/-! ### Properties of `mul` -/
section mulOrdinals
/-- If `α` is an infinite type, then `α × α` and `α` have the same cardinality. -/
theorem mul_eq_self {c : Cardinal} (h : ℵ₀ ≤ c) : c * c = c := by
refine le_antisymm ?_ (by simpa only [mul_one] using mul_le_mul_left' (one_le_aleph0.trans h) c)
-- the only nontrivial part is `c * c ≤ c`. We prove it inductively.
refine Acc.recOn (Cardinal.lt_wf.apply c) (fun c _ => Quotient.inductionOn c fun α IH ol => ?_) h
-- consider the minimal well-order `r` on `α` (a type with cardinality `c`).
rcases ord_eq α with ⟨r, wo, e⟩
letI := linearOrderOfSTO r
haveI : IsWellOrder α (· < ·) := wo
-- Define an order `s` on `α × α` by writing `(a, b) < (c, d)` if `max a b < max c d`, or
-- the max are equal and `a < c`, or the max are equal and `a = c` and `b < d`.
let g : α × α → α := fun p => max p.1 p.2
let f : α × α ↪ Ordinal × α × α :=
⟨fun p : α × α => (typein (· < ·) (g p), p), fun p q => congr_arg Prod.snd⟩
let s := f ⁻¹'o Prod.Lex (· < ·) (Prod.Lex (· < ·) (· < ·))
-- this is a well order on `α × α`.
haveI : IsWellOrder _ s := (RelEmbedding.preimage _ _).isWellOrder
/- it suffices to show that this well order is smaller than `r`
if it were larger, then `r` would be a strict prefix of `s`. It would be contained in
`β × β` for some `β` of cardinality `< c`. By the inductive assumption, this set has the
same cardinality as `β` (or it is finite if `β` is finite), so it is `< c`, which is a
contradiction. -/
suffices type s ≤ type r by exact card_le_card this
refine le_of_forall_lt fun o h => ?_
rcases typein_surj s h with ⟨p, rfl⟩
rw [← e, lt_ord]
refine lt_of_le_of_lt
(?_ : _ ≤ card (succ (typein (· < ·) (g p))) * card (succ (typein (· < ·) (g p)))) ?_
· have : { q | s q p } ⊆ insert (g p) { x | x < g p } ×ˢ insert (g p) { x | x < g p } := by
intro q h
simp only [s, f, Preimage, Embedding.coeFn_mk, Prod.lex_def, typein_lt_typein,
typein_inj, mem_setOf_eq] at h
exact max_le_iff.1 (le_iff_lt_or_eq.2 <| h.imp_right And.left)
suffices H : (insert (g p) { x | r x (g p) } : Set α) ≃ { x | r x (g p) } ⊕ PUnit from
⟨(Set.embeddingOfSubset _ _ this).trans
((Equiv.Set.prod _ _).trans (H.prodCongr H)).toEmbedding⟩
refine (Equiv.Set.insert ?_).trans ((Equiv.refl _).sumCongr punitEquivPUnit)
apply @irrefl _ r
cases' lt_or_le (card (succ (typein (· < ·) (g p)))) ℵ₀ with qo qo
· exact (mul_lt_aleph0 qo qo).trans_le ol
· suffices (succ (typein LT.lt (g p))).card < ⟦α⟧ from (IH _ this qo).trans_lt this
rw [← lt_ord]
apply (ord_isLimit ol).2
rw [mk'_def, e]
apply typein_lt_type
end mulOrdinals
end UsingOrdinals
/-! Properties of `mul`, not requiring ordinals -/
section mul
/-- If `α` and `β` are infinite types, then the cardinality of `α × β` is the maximum
of the cardinalities of `α` and `β`. -/
theorem mul_eq_max {a b : Cardinal} (ha : ℵ₀ ≤ a) (hb : ℵ₀ ≤ b) : a * b = max a b :=
le_antisymm
(mul_eq_self (ha.trans (le_max_left a b)) ▸
mul_le_mul' (le_max_left _ _) (le_max_right _ _)) <|
max_le (by simpa only [mul_one] using mul_le_mul_left' (one_le_aleph0.trans hb) a)
(by simpa only [one_mul] using mul_le_mul_right' (one_le_aleph0.trans ha) b)
@[simp]
theorem mul_mk_eq_max {α β : Type u} [Infinite α] [Infinite β] : #α * #β = max #α #β :=
mul_eq_max (aleph0_le_mk α) (aleph0_le_mk β)
@[simp]
theorem aleph_mul_aleph (o₁ o₂ : Ordinal) : aleph o₁ * aleph o₂ = aleph (max o₁ o₂) := by
rw [Cardinal.mul_eq_max (aleph0_le_aleph o₁) (aleph0_le_aleph o₂), max_aleph_eq]
@[simp]
theorem aleph0_mul_eq {a : Cardinal} (ha : ℵ₀ ≤ a) : ℵ₀ * a = a :=
(mul_eq_max le_rfl ha).trans (max_eq_right ha)
@[simp]
theorem mul_aleph0_eq {a : Cardinal} (ha : ℵ₀ ≤ a) : a * ℵ₀ = a :=
(mul_eq_max ha le_rfl).trans (max_eq_left ha)
-- Porting note (#10618): removed `simp`, `simp` can prove it
theorem aleph0_mul_mk_eq {α : Type*} [Infinite α] : ℵ₀ * #α = #α :=
aleph0_mul_eq (aleph0_le_mk α)
-- Porting note (#10618): removed `simp`, `simp` can prove it
theorem mk_mul_aleph0_eq {α : Type*} [Infinite α] : #α * ℵ₀ = #α :=
mul_aleph0_eq (aleph0_le_mk α)
@[simp]
theorem aleph0_mul_aleph (o : Ordinal) : ℵ₀ * aleph o = aleph o :=
aleph0_mul_eq (aleph0_le_aleph o)
@[simp]
theorem aleph_mul_aleph0 (o : Ordinal) : aleph o * ℵ₀ = aleph o :=
mul_aleph0_eq (aleph0_le_aleph o)
theorem mul_lt_of_lt {a b c : Cardinal} (hc : ℵ₀ ≤ c) (h1 : a < c) (h2 : b < c) : a * b < c :=
(mul_le_mul' (le_max_left a b) (le_max_right a b)).trans_lt <|
(lt_or_le (max a b) ℵ₀).elim (fun h => (mul_lt_aleph0 h h).trans_le hc) fun h => by
rw [mul_eq_self h]
exact max_lt h1 h2
theorem mul_le_max_of_aleph0_le_left {a b : Cardinal} (h : ℵ₀ ≤ a) : a * b ≤ max a b := by
convert mul_le_mul' (le_max_left a b) (le_max_right a b) using 1
rw [mul_eq_self]
exact h.trans (le_max_left a b)
theorem mul_eq_max_of_aleph0_le_left {a b : Cardinal} (h : ℵ₀ ≤ a) (h' : b ≠ 0) :
a * b = max a b := by
rcases le_or_lt ℵ₀ b with hb | hb
· exact mul_eq_max h hb
refine (mul_le_max_of_aleph0_le_left h).antisymm ?_
have : b ≤ a := hb.le.trans h
rw [max_eq_left this]
convert mul_le_mul_left' (one_le_iff_ne_zero.mpr h') a
rw [mul_one]
theorem mul_le_max_of_aleph0_le_right {a b : Cardinal} (h : ℵ₀ ≤ b) : a * b ≤ max a b := by
simpa only [mul_comm b, max_comm b] using mul_le_max_of_aleph0_le_left h
theorem mul_eq_max_of_aleph0_le_right {a b : Cardinal} (h' : a ≠ 0) (h : ℵ₀ ≤ b) :
a * b = max a b := by
rw [mul_comm, max_comm]
exact mul_eq_max_of_aleph0_le_left h h'
theorem mul_eq_max' {a b : Cardinal} (h : ℵ₀ ≤ a * b) : a * b = max a b := by
rcases aleph0_le_mul_iff.mp h with ⟨ha, hb, ha' | hb'⟩
· exact mul_eq_max_of_aleph0_le_left ha' hb
· exact mul_eq_max_of_aleph0_le_right ha hb'
theorem mul_le_max (a b : Cardinal) : a * b ≤ max (max a b) ℵ₀ := by
rcases eq_or_ne a 0 with (rfl | ha0); · simp
rcases eq_or_ne b 0 with (rfl | hb0); · simp
rcases le_or_lt ℵ₀ a with ha | ha
· rw [mul_eq_max_of_aleph0_le_left ha hb0]
exact le_max_left _ _
· rcases le_or_lt ℵ₀ b with hb | hb
· rw [mul_comm, mul_eq_max_of_aleph0_le_left hb ha0, max_comm]
exact le_max_left _ _
· exact le_max_of_le_right (mul_lt_aleph0 ha hb).le
theorem mul_eq_left {a b : Cardinal} (ha : ℵ₀ ≤ a) (hb : b ≤ a) (hb' : b ≠ 0) : a * b = a := by
rw [mul_eq_max_of_aleph0_le_left ha hb', max_eq_left hb]
theorem mul_eq_right {a b : Cardinal} (hb : ℵ₀ ≤ b) (ha : a ≤ b) (ha' : a ≠ 0) : a * b = b := by
rw [mul_comm, mul_eq_left hb ha ha']
theorem le_mul_left {a b : Cardinal} (h : b ≠ 0) : a ≤ b * a := by
convert mul_le_mul_right' (one_le_iff_ne_zero.mpr h) a
rw [one_mul]
theorem le_mul_right {a b : Cardinal} (h : b ≠ 0) : a ≤ a * b := by
rw [mul_comm]
exact le_mul_left h
theorem mul_eq_left_iff {a b : Cardinal} : a * b = a ↔ max ℵ₀ b ≤ a ∧ b ≠ 0 ∨ b = 1 ∨ a = 0 := by
rw [max_le_iff]
refine ⟨fun h => ?_, ?_⟩
· rcases le_or_lt ℵ₀ a with ha | ha
· have : a ≠ 0 := by
rintro rfl
exact ha.not_lt aleph0_pos
left
rw [and_assoc]
use ha
constructor
· rw [← not_lt]
exact fun hb => ne_of_gt (hb.trans_le (le_mul_left this)) h
· rintro rfl
apply this
rw [mul_zero] at h
exact h.symm
right
by_cases h2a : a = 0
· exact Or.inr h2a
have hb : b ≠ 0 := by
rintro rfl
apply h2a
rw [mul_zero] at h
exact h.symm
left
rw [← h, mul_lt_aleph0_iff, lt_aleph0, lt_aleph0] at ha
rcases ha with (rfl | rfl | ⟨⟨n, rfl⟩, ⟨m, rfl⟩⟩)
· contradiction
· contradiction
rw [← Ne] at h2a
rw [← one_le_iff_ne_zero] at h2a hb
norm_cast at h2a hb h ⊢
apply le_antisymm _ hb
rw [← not_lt]
apply fun h2b => ne_of_gt _ h
conv_rhs => left; rw [← mul_one n]
rw [mul_lt_mul_left]
· exact id
apply Nat.lt_of_succ_le h2a
· rintro (⟨⟨ha, hab⟩, hb⟩ | rfl | rfl)
· rw [mul_eq_max_of_aleph0_le_left ha hb, max_eq_left hab]
all_goals simp
end mul
/-! ### Properties of `add` -/
section add
/-- If `α` is an infinite type, then `α ⊕ α` and `α` have the same cardinality. -/
theorem add_eq_self {c : Cardinal} (h : ℵ₀ ≤ c) : c + c = c :=
le_antisymm
(by
convert mul_le_mul_right' ((nat_lt_aleph0 2).le.trans h) c using 1
<;> simp [two_mul, mul_eq_self h])
(self_le_add_left c c)
/-- If `α` is an infinite type, then the cardinality of `α ⊕ β` is the maximum
of the cardinalities of `α` and `β`. -/
theorem add_eq_max {a b : Cardinal} (ha : ℵ₀ ≤ a) : a + b = max a b :=
le_antisymm
(add_eq_self (ha.trans (le_max_left a b)) ▸
add_le_add (le_max_left _ _) (le_max_right _ _)) <|
max_le (self_le_add_right _ _) (self_le_add_left _ _)
theorem add_eq_max' {a b : Cardinal} (ha : ℵ₀ ≤ b) : a + b = max a b := by
rw [add_comm, max_comm, add_eq_max ha]
@[simp]
theorem add_mk_eq_max {α β : Type u} [Infinite α] : #α + #β = max #α #β :=
add_eq_max (aleph0_le_mk α)
@[simp]
theorem add_mk_eq_max' {α β : Type u} [Infinite β] : #α + #β = max #α #β :=
add_eq_max' (aleph0_le_mk β)
theorem add_le_max (a b : Cardinal) : a + b ≤ max (max a b) ℵ₀ := by
rcases le_or_lt ℵ₀ a with ha | ha
· rw [add_eq_max ha]
exact le_max_left _ _
· rcases le_or_lt ℵ₀ b with hb | hb
· rw [add_comm, add_eq_max hb, max_comm]
exact le_max_left _ _
· exact le_max_of_le_right (add_lt_aleph0 ha hb).le
theorem add_le_of_le {a b c : Cardinal} (hc : ℵ₀ ≤ c) (h1 : a ≤ c) (h2 : b ≤ c) : a + b ≤ c :=
(add_le_add h1 h2).trans <| le_of_eq <| add_eq_self hc
theorem add_lt_of_lt {a b c : Cardinal} (hc : ℵ₀ ≤ c) (h1 : a < c) (h2 : b < c) : a + b < c :=
(add_le_add (le_max_left a b) (le_max_right a b)).trans_lt <|
(lt_or_le (max a b) ℵ₀).elim (fun h => (add_lt_aleph0 h h).trans_le hc) fun h => by
rw [add_eq_self h]; exact max_lt h1 h2
theorem eq_of_add_eq_of_aleph0_le {a b c : Cardinal} (h : a + b = c) (ha : a < c) (hc : ℵ₀ ≤ c) :
b = c := by
apply le_antisymm
· rw [← h]
apply self_le_add_left
rw [← not_lt]; intro hb
have : a + b < c := add_lt_of_lt hc ha hb
simp [h, lt_irrefl] at this
theorem add_eq_left {a b : Cardinal} (ha : ℵ₀ ≤ a) (hb : b ≤ a) : a + b = a := by
rw [add_eq_max ha, max_eq_left hb]
theorem add_eq_right {a b : Cardinal} (hb : ℵ₀ ≤ b) (ha : a ≤ b) : a + b = b := by
rw [add_comm, add_eq_left hb ha]
theorem add_eq_left_iff {a b : Cardinal} : a + b = a ↔ max ℵ₀ b ≤ a ∨ b = 0 := by
rw [max_le_iff]
refine ⟨fun h => ?_, ?_⟩
· rcases le_or_lt ℵ₀ a with ha | ha
· left
use ha
rw [← not_lt]
apply fun hb => ne_of_gt _ h
intro hb
exact hb.trans_le (self_le_add_left b a)
right
rw [← h, add_lt_aleph0_iff, lt_aleph0, lt_aleph0] at ha
rcases ha with ⟨⟨n, rfl⟩, ⟨m, rfl⟩⟩
norm_cast at h ⊢
rw [← add_right_inj, h, add_zero]
· rintro (⟨h1, h2⟩ | h3)
· rw [add_eq_max h1, max_eq_left h2]
· rw [h3, add_zero]
theorem add_eq_right_iff {a b : Cardinal} : a + b = b ↔ max ℵ₀ a ≤ b ∨ a = 0 := by
rw [add_comm, add_eq_left_iff]
theorem add_nat_eq {a : Cardinal} (n : ℕ) (ha : ℵ₀ ≤ a) : a + n = a :=
add_eq_left ha ((nat_lt_aleph0 _).le.trans ha)
theorem nat_add_eq {a : Cardinal} (n : ℕ) (ha : ℵ₀ ≤ a) : n + a = a := by
rw [add_comm, add_nat_eq n ha]
theorem add_one_eq {a : Cardinal} (ha : ℵ₀ ≤ a) : a + 1 = a :=
add_one_of_aleph0_le ha
-- Porting note (#10618): removed `simp`, `simp` can prove it
theorem mk_add_one_eq {α : Type*} [Infinite α] : #α + 1 = #α :=
add_one_eq (aleph0_le_mk α)
protected theorem eq_of_add_eq_add_left {a b c : Cardinal} (h : a + b = a + c) (ha : a < ℵ₀) :
b = c := by
rcases le_or_lt ℵ₀ b with hb | hb
· have : a < b := ha.trans_le hb
rw [add_eq_right hb this.le, eq_comm] at h
rw [eq_of_add_eq_of_aleph0_le h this hb]
· have hc : c < ℵ₀ := by
rw [← not_le]
intro hc
apply lt_irrefl ℵ₀
apply (hc.trans (self_le_add_left _ a)).trans_lt
rw [← h]
apply add_lt_aleph0 ha hb
rw [lt_aleph0] at *
rcases ha with ⟨n, rfl⟩
rcases hb with ⟨m, rfl⟩
rcases hc with ⟨k, rfl⟩
norm_cast at h ⊢
apply add_left_cancel h
protected theorem eq_of_add_eq_add_right {a b c : Cardinal} (h : a + b = c + b) (hb : b < ℵ₀) :
a = c := by
rw [add_comm a b, add_comm c b] at h
exact Cardinal.eq_of_add_eq_add_left h hb
end add
section ciSup
variable {ι : Type u} {ι' : Type w} (f : ι → Cardinal.{v})
section add
variable [Nonempty ι] [Nonempty ι']
protected theorem ciSup_add (hf : BddAbove (range f)) (c : Cardinal.{v}) :
(⨆ i, f i) + c = ⨆ i, f i + c := by
have : ∀ i, f i + c ≤ (⨆ i, f i) + c := fun i ↦ add_le_add_right (le_ciSup hf i) c
refine le_antisymm ?_ (ciSup_le' this)
have bdd : BddAbove (range (f · + c)) := ⟨_, forall_mem_range.mpr this⟩
obtain hs | hs := lt_or_le (⨆ i, f i) ℵ₀
· obtain ⟨i, hi⟩ := exists_eq_of_iSup_eq_of_not_isLimit
f hf _ (fun h ↦ hs.not_le h.aleph0_le) rfl
exact hi ▸ le_ciSup bdd i
rw [add_eq_max hs, max_le_iff]
exact ⟨ciSup_mono bdd fun i ↦ self_le_add_right _ c,
(self_le_add_left _ _).trans (le_ciSup bdd <| Classical.arbitrary ι)⟩
protected theorem add_ciSup (hf : BddAbove (range f)) (c : Cardinal.{v}) :
c + (⨆ i, f i) = ⨆ i, c + f i := by
rw [add_comm, Cardinal.ciSup_add f hf]; simp_rw [add_comm]
protected theorem ciSup_add_ciSup (hf : BddAbove (range f)) (g : ι' → Cardinal.{v})
(hg : BddAbove (range g)) :
(⨆ i, f i) + (⨆ j, g j) = ⨆ (i) (j), f i + g j := by
simp_rw [Cardinal.ciSup_add f hf, Cardinal.add_ciSup g hg]
end add
protected theorem ciSup_mul (c : Cardinal.{v}) : (⨆ i, f i) * c = ⨆ i, f i * c := by
cases isEmpty_or_nonempty ι; · simp
obtain rfl | h0 := eq_or_ne c 0; · simp
by_cases hf : BddAbove (range f); swap
· have hfc : ¬ BddAbove (range (f · * c)) := fun bdd ↦ hf
⟨⨆ i, f i * c, forall_mem_range.mpr fun i ↦ (le_mul_right h0).trans (le_ciSup bdd i)⟩
simp [iSup, csSup_of_not_bddAbove, hf, hfc]
have : ∀ i, f i * c ≤ (⨆ i, f i) * c := fun i ↦ mul_le_mul_right' (le_ciSup hf i) c
refine le_antisymm ?_ (ciSup_le' this)
have bdd : BddAbove (range (f · * c)) := ⟨_, forall_mem_range.mpr this⟩
obtain hs | hs := lt_or_le (⨆ i, f i) ℵ₀
· obtain ⟨i, hi⟩ := exists_eq_of_iSup_eq_of_not_isLimit
f hf _ (fun h ↦ hs.not_le h.aleph0_le) rfl
exact hi ▸ le_ciSup bdd i
rw [mul_eq_max_of_aleph0_le_left hs h0, max_le_iff]
obtain ⟨i, hi⟩ := exists_lt_of_lt_ciSup' (one_lt_aleph0.trans_le hs)
exact ⟨ciSup_mono bdd fun i ↦ le_mul_right h0,
(le_mul_left (zero_lt_one.trans hi).ne').trans (le_ciSup bdd i)⟩
protected theorem mul_ciSup (c : Cardinal.{v}) : c * (⨆ i, f i) = ⨆ i, c * f i := by
rw [mul_comm, Cardinal.ciSup_mul f]; simp_rw [mul_comm]
protected theorem ciSup_mul_ciSup (g : ι' → Cardinal.{v}) :
(⨆ i, f i) * (⨆ j, g j) = ⨆ (i) (j), f i * g j := by
simp_rw [Cardinal.ciSup_mul f, Cardinal.mul_ciSup g]
end ciSup
@[simp]
theorem aleph_add_aleph (o₁ o₂ : Ordinal) : aleph o₁ + aleph o₂ = aleph (max o₁ o₂) := by
rw [Cardinal.add_eq_max (aleph0_le_aleph o₁), max_aleph_eq]
theorem principal_add_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Ordinal.Principal (· + ·) c.ord :=
fun a b ha hb => by
rw [lt_ord, Ordinal.card_add] at *
exact add_lt_of_lt hc ha hb
theorem principal_add_aleph (o : Ordinal) : Ordinal.Principal (· + ·) (aleph o).ord :=
principal_add_ord <| aleph0_le_aleph o
theorem add_right_inj_of_lt_aleph0 {α β γ : Cardinal} (γ₀ : γ < aleph0) : α + γ = β + γ ↔ α = β :=
⟨fun h => Cardinal.eq_of_add_eq_add_right h γ₀, fun h => congr_arg (· + γ) h⟩
@[simp]
theorem add_nat_inj {α β : Cardinal} (n : ℕ) : α + n = β + n ↔ α = β :=
add_right_inj_of_lt_aleph0 (nat_lt_aleph0 _)
@[simp]
theorem add_one_inj {α β : Cardinal} : α + 1 = β + 1 ↔ α = β :=
add_right_inj_of_lt_aleph0 one_lt_aleph0
theorem add_le_add_iff_of_lt_aleph0 {α β γ : Cardinal} (γ₀ : γ < Cardinal.aleph0) :
α + γ ≤ β + γ ↔ α ≤ β := by
refine ⟨fun h => ?_, fun h => add_le_add_right h γ⟩
contrapose h
rw [not_le, lt_iff_le_and_ne, Ne] at h ⊢
exact ⟨add_le_add_right h.1 γ, mt (add_right_inj_of_lt_aleph0 γ₀).1 h.2⟩
@[simp]
theorem add_nat_le_add_nat_iff {α β : Cardinal} (n : ℕ) : α + n ≤ β + n ↔ α ≤ β :=
add_le_add_iff_of_lt_aleph0 (nat_lt_aleph0 n)
@[deprecated (since := "2024-02-12")]
alias add_nat_le_add_nat_iff_of_lt_aleph_0 := add_nat_le_add_nat_iff
@[simp]
theorem add_one_le_add_one_iff {α β : Cardinal} : α + 1 ≤ β + 1 ↔ α ≤ β :=
add_le_add_iff_of_lt_aleph0 one_lt_aleph0
@[deprecated (since := "2024-02-12")]
alias add_one_le_add_one_iff_of_lt_aleph_0 := add_one_le_add_one_iff
/-! ### Properties about power -/
section pow
theorem pow_le {κ μ : Cardinal.{u}} (H1 : ℵ₀ ≤ κ) (H2 : μ < ℵ₀) : κ ^ μ ≤ κ :=
let ⟨n, H3⟩ := lt_aleph0.1 H2
H3.symm ▸
Quotient.inductionOn κ
(fun α H1 =>
Nat.recOn n
(lt_of_lt_of_le
(by
rw [Nat.cast_zero, power_zero]
exact one_lt_aleph0)
H1).le
fun n ih =>
le_of_le_of_eq
(by
rw [Nat.cast_succ, power_add, power_one]
exact mul_le_mul_right' ih _)
(mul_eq_self H1))
H1
theorem pow_eq {κ μ : Cardinal.{u}} (H1 : ℵ₀ ≤ κ) (H2 : 1 ≤ μ) (H3 : μ < ℵ₀) : κ ^ μ = κ :=
(pow_le H1 H3).antisymm <| self_le_power κ H2
theorem power_self_eq {c : Cardinal} (h : ℵ₀ ≤ c) : c ^ c = 2 ^ c := by
apply ((power_le_power_right <| (cantor c).le).trans _).antisymm
· exact power_le_power_right ((nat_lt_aleph0 2).le.trans h)
· rw [← power_mul, mul_eq_self h]
theorem prod_eq_two_power {ι : Type u} [Infinite ι] {c : ι → Cardinal.{v}} (h₁ : ∀ i, 2 ≤ c i)
(h₂ : ∀ i, lift.{u} (c i) ≤ lift.{v} #ι) : prod c = 2 ^ lift.{v} #ι := by
rw [← lift_id'.{u, v} (prod.{u, v} c), lift_prod, ← lift_two_power]
apply le_antisymm
· refine (prod_le_prod _ _ h₂).trans_eq ?_
rw [prod_const, lift_lift, ← lift_power, power_self_eq (aleph0_le_mk ι), lift_umax.{u, v}]
· rw [← prod_const', lift_prod]
refine prod_le_prod _ _ fun i => ?_
rw [lift_two, ← lift_two.{u, v}, lift_le]
exact h₁ i
theorem power_eq_two_power {c₁ c₂ : Cardinal} (h₁ : ℵ₀ ≤ c₁) (h₂ : 2 ≤ c₂) (h₂' : c₂ ≤ c₁) :
c₂ ^ c₁ = 2 ^ c₁ :=
le_antisymm (power_self_eq h₁ ▸ power_le_power_right h₂') (power_le_power_right h₂)
theorem nat_power_eq {c : Cardinal.{u}} (h : ℵ₀ ≤ c) {n : ℕ} (hn : 2 ≤ n) :
(n : Cardinal.{u}) ^ c = 2 ^ c :=
power_eq_two_power h (by assumption_mod_cast) ((nat_lt_aleph0 n).le.trans h)
theorem power_nat_le {c : Cardinal.{u}} {n : ℕ} (h : ℵ₀ ≤ c) : c ^ n ≤ c :=
pow_le h (nat_lt_aleph0 n)
theorem power_nat_eq {c : Cardinal.{u}} {n : ℕ} (h1 : ℵ₀ ≤ c) (h2 : 1 ≤ n) : c ^ n = c :=
pow_eq h1 (mod_cast h2) (nat_lt_aleph0 n)
theorem power_nat_le_max {c : Cardinal.{u}} {n : ℕ} : c ^ (n : Cardinal.{u}) ≤ max c ℵ₀ := by
rcases le_or_lt ℵ₀ c with hc | hc
· exact le_max_of_le_left (power_nat_le hc)
· exact le_max_of_le_right (power_lt_aleph0 hc (nat_lt_aleph0 _)).le
theorem powerlt_aleph0 {c : Cardinal} (h : ℵ₀ ≤ c) : c ^< ℵ₀ = c := by
apply le_antisymm
· rw [powerlt_le]
intro c'
rw [lt_aleph0]
rintro ⟨n, rfl⟩
apply power_nat_le h
convert le_powerlt c one_lt_aleph0; rw [power_one]
theorem powerlt_aleph0_le (c : Cardinal) : c ^< ℵ₀ ≤ max c ℵ₀ := by
rcases le_or_lt ℵ₀ c with h | h
· rw [powerlt_aleph0 h]
apply le_max_left
rw [powerlt_le]
exact fun c' hc' => (power_lt_aleph0 h hc').le.trans (le_max_right _ _)
end pow
/-! ### Computing cardinality of various types -/
section computing
section Function
variable {α β : Type u} {β' : Type v}
theorem mk_equiv_eq_zero_iff_lift_ne : #(α ≃ β') = 0 ↔ lift.{v} #α ≠ lift.{u} #β' := by
rw [mk_eq_zero_iff, ← not_nonempty_iff, ← lift_mk_eq']
theorem mk_equiv_eq_zero_iff_ne : #(α ≃ β) = 0 ↔ #α ≠ #β := by
rw [mk_equiv_eq_zero_iff_lift_ne, lift_id, lift_id]
/-- This lemma makes lemmas assuming `Infinite α` applicable to the situation where we have
`Infinite β` instead. -/
theorem mk_equiv_comm : #(α ≃ β') = #(β' ≃ α) :=
(ofBijective _ symm_bijective).cardinal_eq
theorem mk_embedding_eq_zero_iff_lift_lt : #(α ↪ β') = 0 ↔ lift.{u} #β' < lift.{v} #α := by
rw [mk_eq_zero_iff, ← not_nonempty_iff, ← lift_mk_le', not_le]
theorem mk_embedding_eq_zero_iff_lt : #(α ↪ β) = 0 ↔ #β < #α := by
rw [mk_embedding_eq_zero_iff_lift_lt, lift_lt]
theorem mk_arrow_eq_zero_iff : #(α → β') = 0 ↔ #α ≠ 0 ∧ #β' = 0 := by
simp_rw [mk_eq_zero_iff, mk_ne_zero_iff, isEmpty_fun]
theorem mk_surjective_eq_zero_iff_lift :
#{f : α → β' | Surjective f} = 0 ↔ lift.{v} #α < lift.{u} #β' ∨ (#α ≠ 0 ∧ #β' = 0) := by
rw [← not_iff_not, not_or, not_lt, lift_mk_le', ← Ne, not_and_or, not_ne_iff, and_comm]
simp_rw [mk_ne_zero_iff, mk_eq_zero_iff, nonempty_coe_sort,
Set.Nonempty, mem_setOf, exists_surjective_iff, nonempty_fun]
theorem mk_surjective_eq_zero_iff :
#{f : α → β | Surjective f} = 0 ↔ #α < #β ∨ (#α ≠ 0 ∧ #β = 0) := by
rw [mk_surjective_eq_zero_iff_lift, lift_lt]
variable (α β')
theorem mk_equiv_le_embedding : #(α ≃ β') ≤ #(α ↪ β') := ⟨⟨_, Equiv.toEmbedding_injective⟩⟩
theorem mk_embedding_le_arrow : #(α ↪ β') ≤ #(α → β') := ⟨⟨_, DFunLike.coe_injective⟩⟩
variable [Infinite α] {α β'}
theorem mk_perm_eq_self_power : #(Equiv.Perm α) = #α ^ #α :=
((mk_equiv_le_embedding α α).trans (mk_embedding_le_arrow α α)).antisymm <| by
suffices Nonempty ((α → Bool) ↪ Equiv.Perm (α × Bool)) by
obtain ⟨e⟩ : Nonempty (α ≃ α × Bool) := by
erw [← Cardinal.eq, mk_prod, lift_uzero, mk_bool,
lift_natCast, mul_two, add_eq_self (aleph0_le_mk α)]
erw [← le_def, mk_arrow, lift_uzero, mk_bool, lift_natCast 2] at this
rwa [← power_def, power_self_eq (aleph0_le_mk α), e.permCongr.cardinal_eq]
refine ⟨⟨fun f ↦ Involutive.toPerm (fun x ↦ ⟨x.1, xor (f x.1) x.2⟩) fun x ↦ ?_, fun f g h ↦ ?_⟩⟩
· simp_rw [← Bool.xor_assoc, Bool.xor_self, Bool.false_xor]
· ext a; rw [← (f a).xor_false, ← (g a).xor_false]; exact congr(($h ⟨a, false⟩).2)
theorem mk_perm_eq_two_power : #(Equiv.Perm α) = 2 ^ #α := by
rw [mk_perm_eq_self_power, power_self_eq (aleph0_le_mk α)]
theorem mk_equiv_eq_arrow_of_lift_eq (leq : lift.{v} #α = lift.{u} #β') :
#(α ≃ β') = #(α → β') := by
obtain ⟨e⟩ := lift_mk_eq'.mp leq
have e₁ := lift_mk_eq'.mpr ⟨.equivCongr (.refl α) e⟩
have e₂ := lift_mk_eq'.mpr ⟨.arrowCongr (.refl α) e⟩
rw [lift_id'.{u,v}] at e₁ e₂
rw [← e₁, ← e₂, lift_inj, mk_perm_eq_self_power, power_def]
theorem mk_equiv_eq_arrow_of_eq (eq : #α = #β) : #(α ≃ β) = #(α → β) :=
mk_equiv_eq_arrow_of_lift_eq congr(lift $eq)
theorem mk_equiv_of_lift_eq (leq : lift.{v} #α = lift.{u} #β') : #(α ≃ β') = 2 ^ lift.{v} #α := by
erw [← (lift_mk_eq'.2 ⟨.equivCongr (.refl α) (lift_mk_eq'.1 leq).some⟩).trans (lift_id'.{u,v} _),
lift_umax.{u,v}, mk_perm_eq_two_power, lift_power, lift_natCast]; rfl
theorem mk_equiv_of_eq (eq : #α = #β) : #(α ≃ β) = 2 ^ #α := by
rw [mk_equiv_of_lift_eq (lift_inj.mpr eq), lift_id]
theorem mk_embedding_eq_arrow_of_lift_le (lle : lift.{u} #β' ≤ lift.{v} #α) :
#(β' ↪ α) = #(β' → α) :=
(mk_embedding_le_arrow _ _).antisymm <| by
conv_rhs => rw [← (Equiv.embeddingCongr (.refl _)
(Cardinal.eq.mp <| mul_eq_self <| aleph0_le_mk α).some).cardinal_eq]
obtain ⟨e⟩ := lift_mk_le'.mp lle
exact ⟨⟨fun f ↦ ⟨fun b ↦ ⟨e b, f b⟩, fun _ _ h ↦ e.injective congr(Prod.fst $h)⟩,
fun f g h ↦ funext fun b ↦ congr(Prod.snd <| $h b)⟩⟩
theorem mk_embedding_eq_arrow_of_le (le : #β ≤ #α) : #(β ↪ α) = #(β → α) :=
mk_embedding_eq_arrow_of_lift_le (lift_le.mpr le)
theorem mk_surjective_eq_arrow_of_lift_le (lle : lift.{u} #β' ≤ lift.{v} #α) :
#{f : α → β' | Surjective f} = #(α → β') :=
(mk_set_le _).antisymm <|
have ⟨e⟩ : Nonempty (α ≃ α ⊕ β') := by
simp_rw [← lift_mk_eq', mk_sum, lift_add, lift_lift]; rw [lift_umax.{u,v}, eq_comm]
exact add_eq_left (aleph0_le_lift.mpr <| aleph0_le_mk α) lle
⟨⟨fun f ↦ ⟨fun a ↦ (e a).elim f id, fun b ↦ ⟨e.symm (.inr b), congr_arg _ (e.right_inv _)⟩⟩,
fun f g h ↦ funext fun a ↦ by
simpa only [e.apply_symm_apply] using congr_fun (Subtype.ext_iff.mp h) (e.symm <| .inl a)⟩⟩
theorem mk_surjective_eq_arrow_of_le (le : #β ≤ #α) : #{f : α → β | Surjective f} = #(α → β) :=
mk_surjective_eq_arrow_of_lift_le (lift_le.mpr le)
end Function
@[simp]
theorem mk_list_eq_mk (α : Type u) [Infinite α] : #(List α) = #α :=
have H1 : ℵ₀ ≤ #α := aleph0_le_mk α
Eq.symm <|
le_antisymm ((le_def _ _).2 ⟨⟨fun a => [a], fun _ => by simp⟩⟩) <|
calc
#(List α) = sum fun n : ℕ => #α ^ (n : Cardinal.{u}) := mk_list_eq_sum_pow α
_ ≤ sum fun _ : ℕ => #α := sum_le_sum _ _ fun n => pow_le H1 <| nat_lt_aleph0 n
_ = #α := by simp [H1]
theorem mk_list_eq_aleph0 (α : Type u) [Countable α] [Nonempty α] : #(List α) = ℵ₀ :=
mk_le_aleph0.antisymm (aleph0_le_mk _)
theorem mk_list_eq_max_mk_aleph0 (α : Type u) [Nonempty α] : #(List α) = max #α ℵ₀ := by
cases finite_or_infinite α
· rw [mk_list_eq_aleph0, eq_comm, max_eq_right]
exact mk_le_aleph0
· rw [mk_list_eq_mk, eq_comm, max_eq_left]
exact aleph0_le_mk α
theorem mk_list_le_max (α : Type u) : #(List α) ≤ max ℵ₀ #α := by
cases finite_or_infinite α
· exact mk_le_aleph0.trans (le_max_left _ _)
· rw [mk_list_eq_mk]
apply le_max_right
@[simp]
theorem mk_finset_of_infinite (α : Type u) [Infinite α] : #(Finset α) = #α :=
Eq.symm <|
le_antisymm (mk_le_of_injective fun _ _ => Finset.singleton_inj.1) <|
calc
#(Finset α) ≤ #(List α) := mk_le_of_surjective List.toFinset_surjective
_ = #α := mk_list_eq_mk α
@[simp]
theorem mk_finsupp_lift_of_infinite (α : Type u) (β : Type v) [Infinite α] [Zero β] [Nontrivial β] :
#(α →₀ β) = max (lift.{v} #α) (lift.{u} #β) := by
apply le_antisymm
· calc
#(α →₀ β) ≤ #(Finset (α × β)) := mk_le_of_injective (Finsupp.graph_injective α β)
_ = #(α × β) := mk_finset_of_infinite _
_ = max (lift.{v} #α) (lift.{u} #β) := by
rw [mk_prod, mul_eq_max_of_aleph0_le_left] <;> simp
· apply max_le <;> rw [← lift_id #(α →₀ β), ← lift_umax]
· cases' exists_ne (0 : β) with b hb
exact lift_mk_le.{v}.2 ⟨⟨_, Finsupp.single_left_injective hb⟩⟩
· inhabit α
exact lift_mk_le.{u}.2 ⟨⟨_, Finsupp.single_injective default⟩⟩
theorem mk_finsupp_of_infinite (α β : Type u) [Infinite α] [Zero β] [Nontrivial β] :
#(α →₀ β) = max #α #β := by simp
@[simp]
theorem mk_finsupp_lift_of_infinite' (α : Type u) (β : Type v) [Nonempty α] [Zero β] [Infinite β] :
#(α →₀ β) = max (lift.{v} #α) (lift.{u} #β) := by
cases fintypeOrInfinite α
· rw [mk_finsupp_lift_of_fintype]
have : ℵ₀ ≤ (#β).lift := aleph0_le_lift.2 (aleph0_le_mk β)
rw [max_eq_right (le_trans _ this), power_nat_eq this]
exacts [Fintype.card_pos, lift_le_aleph0.2 (lt_aleph0_of_finite _).le]
· apply mk_finsupp_lift_of_infinite
theorem mk_finsupp_of_infinite' (α β : Type u) [Nonempty α] [Zero β] [Infinite β] :
#(α →₀ β) = max #α #β := by simp
theorem mk_finsupp_nat (α : Type u) [Nonempty α] : #(α →₀ ℕ) = max #α ℵ₀ := by simp
@[simp]
theorem mk_multiset_of_nonempty (α : Type u) [Nonempty α] : #(Multiset α) = max #α ℵ₀ :=
Multiset.toFinsupp.toEquiv.cardinal_eq.trans (mk_finsupp_nat α)
theorem mk_multiset_of_infinite (α : Type u) [Infinite α] : #(Multiset α) = #α := by simp
theorem mk_multiset_of_isEmpty (α : Type u) [IsEmpty α] : #(Multiset α) = 1 :=
Multiset.toFinsupp.toEquiv.cardinal_eq.trans (by simp)
theorem mk_multiset_of_countable (α : Type u) [Countable α] [Nonempty α] : #(Multiset α) = ℵ₀ :=
Multiset.toFinsupp.toEquiv.cardinal_eq.trans (by simp)
theorem mk_bounded_set_le_of_infinite (α : Type u) [Infinite α] (c : Cardinal) :
#{ t : Set α // #t ≤ c } ≤ #α ^ c := by
refine le_trans ?_ (by rw [← add_one_eq (aleph0_le_mk α)])
induction' c using Cardinal.inductionOn with β
fapply mk_le_of_surjective
· intro f
use Sum.inl ⁻¹' range f
refine le_trans (mk_preimage_of_injective _ _ fun x y => Sum.inl.inj) ?_
apply mk_range_le
rintro ⟨s, ⟨g⟩⟩
use fun y => if h : ∃ x : s, g x = y then Sum.inl (Classical.choose h).val
else Sum.inr (ULift.up 0)
apply Subtype.eq; ext x
constructor
· rintro ⟨y, h⟩
dsimp only at h
by_cases h' : ∃ z : s, g z = y
· rw [dif_pos h'] at h
cases Sum.inl.inj h
exact (Classical.choose h').2
· rw [dif_neg h'] at h
cases h
· intro h
have : ∃ z : s, g z = g ⟨x, h⟩ := ⟨⟨x, h⟩, rfl⟩
use g ⟨x, h⟩
dsimp only
rw [dif_pos this]
congr
suffices Classical.choose this = ⟨x, h⟩ from congr_arg Subtype.val this
apply g.2
exact Classical.choose_spec this
theorem mk_bounded_set_le (α : Type u) (c : Cardinal) :
#{ t : Set α // #t ≤ c } ≤ max #α ℵ₀ ^ c := by
trans #{ t : Set ((ULift.{u} ℕ) ⊕ α) // #t ≤ c }
· refine ⟨Embedding.subtypeMap ?_ ?_⟩
· apply Embedding.image
use Sum.inr
apply Sum.inr.inj
intro s hs
exact mk_image_le.trans hs
apply (mk_bounded_set_le_of_infinite ((ULift.{u} ℕ) ⊕ α) c).trans
rw [max_comm, ← add_eq_max] <;> rfl
theorem mk_bounded_subset_le {α : Type u} (s : Set α) (c : Cardinal.{u}) :
#{ t : Set α // t ⊆ s ∧ #t ≤ c } ≤ max #s ℵ₀ ^ c := by
refine le_trans ?_ (mk_bounded_set_le s c)
refine ⟨Embedding.codRestrict _ ?_ ?_⟩
· use fun t => (↑) ⁻¹' t.1
rintro ⟨t, ht1, ht2⟩ ⟨t', h1t', h2t'⟩ h
apply Subtype.eq
dsimp only at h ⊢
refine (preimage_eq_preimage' ?_ ?_).1 h <;> rw [Subtype.range_coe] <;> assumption
rintro ⟨t, _, h2t⟩; exact (mk_preimage_of_injective _ _ Subtype.val_injective).trans h2t
end computing
/-! ### Properties of `compl` -/
section compl
theorem mk_compl_of_infinite {α : Type*} [Infinite α] (s : Set α) (h2 : #s < #α) :
#(sᶜ : Set α) = #α := by
refine eq_of_add_eq_of_aleph0_le ?_ h2 (aleph0_le_mk α)
exact mk_sum_compl s
theorem mk_compl_finset_of_infinite {α : Type*} [Infinite α] (s : Finset α) :
#((↑s)ᶜ : Set α) = #α := by
apply mk_compl_of_infinite
exact (finset_card_lt_aleph0 s).trans_le (aleph0_le_mk α)
theorem mk_compl_eq_mk_compl_infinite {α : Type*} [Infinite α] {s t : Set α} (hs : #s < #α)
(ht : #t < #α) : #(sᶜ : Set α) = #(tᶜ : Set α) := by
rw [mk_compl_of_infinite s hs, mk_compl_of_infinite t ht]
theorem mk_compl_eq_mk_compl_finite_lift {α : Type u} {β : Type v} [Finite α] {s : Set α}
{t : Set β} (h1 : (lift.{max v w, u} #α) = (lift.{max u w, v} #β))
(h2 : lift.{max v w, u} #s = lift.{max u w, v} #t) :
lift.{max v w} #(sᶜ : Set α) = lift.{max u w} #(tᶜ : Set β) := by
cases nonempty_fintype α
rcases lift_mk_eq.{u, v, w}.1 h1 with ⟨e⟩; letI : Fintype β := Fintype.ofEquiv α e
replace h1 : Fintype.card α = Fintype.card β := (Fintype.ofEquiv_card _).symm
classical
lift s to Finset α using s.toFinite
lift t to Finset β using t.toFinite
simp only [Finset.coe_sort_coe, mk_fintype, Fintype.card_coe, lift_natCast, Nat.cast_inj] at h2
simp only [← Finset.coe_compl, Finset.coe_sort_coe, mk_coe_finset, Finset.card_compl,
lift_natCast, Nat.cast_inj, h1, h2]
theorem mk_compl_eq_mk_compl_finite {α β : Type u} [Finite α] {s : Set α} {t : Set β}
(h1 : #α = #β) (h : #s = #t) : #(sᶜ : Set α) = #(tᶜ : Set β) := by
rw [← lift_inj.{u, u}]
apply mk_compl_eq_mk_compl_finite_lift.{u, u, u}
<;> rwa [lift_inj]
theorem mk_compl_eq_mk_compl_finite_same {α : Type u} [Finite α] {s t : Set α} (h : #s = #t) :
#(sᶜ : Set α) = #(tᶜ : Set α) :=
mk_compl_eq_mk_compl_finite.{u} rfl h
end compl
/-! ### Extending an injection to an equiv -/
theorem extend_function {α β : Type*} {s : Set α} (f : s ↪ β)
(h : Nonempty ((sᶜ : Set α) ≃ ((range f)ᶜ : Set β))) : ∃ g : α ≃ β, ∀ x : s, g x = f x := by
have := h; cases' this with g
let h : α ≃ β :=
(Set.sumCompl (s : Set α)).symm.trans
((sumCongr (Equiv.ofInjective f f.2) g).trans (Set.sumCompl (range f)))
refine ⟨h, ?_⟩; rintro ⟨x, hx⟩; simp [h, Set.sumCompl_symm_apply_of_mem, hx]
theorem extend_function_finite {α : Type u} {β : Type v} [Finite α] {s : Set α} (f : s ↪ β)
(h : Nonempty (α ≃ β)) : ∃ g : α ≃ β, ∀ x : s, g x = f x := by
apply extend_function.{u, v} f
cases' id h with g
rw [← lift_mk_eq.{u, v, max u v}] at h
rw [← lift_mk_eq.{u, v, max u v}, mk_compl_eq_mk_compl_finite_lift.{u, v, max u v} h]
rw [mk_range_eq_lift.{u, v, max u v}]; exact f.2
theorem extend_function_of_lt {α β : Type*} {s : Set α} (f : s ↪ β) (hs : #s < #α)
(h : Nonempty (α ≃ β)) : ∃ g : α ≃ β, ∀ x : s, g x = f x := by
cases fintypeOrInfinite α
· exact extend_function_finite f h
· apply extend_function f
cases' id h with g
haveI := Infinite.of_injective _ g.injective
rw [← lift_mk_eq'] at h ⊢
rwa [mk_compl_of_infinite s hs, mk_compl_of_infinite]
rwa [← lift_lt, mk_range_eq_of_injective f.injective, ← h, lift_lt]
-- Porting note: we no longer express literals as `bit0` and `bit1` in Lean 4, so we can't use this
-- section Bit
-- /-!
-- This section proves inequalities for `bit0` and `bit1`, enabling `simp` to solve inequalities
-- for numeral cardinals. The complexity of the resulting algorithm is not good, as in some cases
-- `simp` reduces an inequality to a disjunction of two situations, depending on whether a cardinal
-- is finite or infinite. Since the evaluation of the branches is not lazy, this is bad. It is good
-- enough for practical situations, though.
-- For specific numbers, these inequalities could also be deduced from the corresponding
-- inequalities of natural numbers using `norm_cast`:
-- ```
-- example : (37 : cardinal) < 42 :=
-- by { norm_cast, norm_num }
-- ```
-- -/
-- theorem bit0_ne_zero (a : Cardinal) : ¬bit0 a = 0 ↔ ¬a = 0 := by simp [bit0]
-- @[simp]
-- theorem bit1_ne_zero (a : Cardinal) : ¬bit1 a = 0 := by simp [bit1]
-- @[simp]
-- theorem zero_lt_bit0 (a : Cardinal) : 0 < bit0 a ↔ 0 < a := by
-- rw [← not_iff_not]
-- simp [bit0]
-- @[simp]
-- theorem zero_lt_bit1 (a : Cardinal) : 0 < bit1 a :=
-- zero_lt_one.trans_le (self_le_add_left _ _)
-- @[simp]
-- theorem one_le_bit0 (a : Cardinal) : 1 ≤ bit0 a ↔ 0 < a :=
-- ⟨fun h => (zero_lt_bit0 a).mp (zero_lt_one.trans_le h), fun h =>
-- (one_le_iff_pos.mpr h).trans (self_le_add_left a a)⟩
-- @[simp]
-- theorem one_le_bit1 (a : Cardinal) : 1 ≤ bit1 a :=
-- self_le_add_left _ _
-- theorem bit0_eq_self {c : Cardinal} (h : ℵ₀ ≤ c) : bit0 c = c :=
-- add_eq_self h
-- @[simp]
-- theorem bit0_lt_aleph0 {c : Cardinal} : bit0 c < ℵ₀ ↔ c < ℵ₀ :=
-- by simp [bit0, add_lt_aleph_0_iff]
-- @[simp]
-- theorem aleph0_le_bit0 {c : Cardinal} : ℵ₀ ≤ bit0 c ↔ ℵ₀ ≤ c := by
-- rw [← not_iff_not]
-- simp
-- @[simp]
-- theorem bit1_eq_self_iff {c : Cardinal} : bit1 c = c ↔ ℵ₀ ≤ c := by
-- by_cases h : ℵ₀ ≤ c
-- · simp only [bit1, bit0_eq_self h, h, eq_self_iff_true, add_one_of_aleph_0_le]
-- · refine' iff_of_false (ne_of_gt _) h
-- rcases lt_aleph_0.1 (not_le.1 h) with ⟨n, rfl⟩
-- norm_cast
-- dsimp [bit1, bit0]
-- linarith
-- @[simp]
-- theorem bit1_lt_aleph0 {c : Cardinal} : bit1 c < ℵ₀ ↔ c < ℵ₀ := by
-- simp [bit1, bit0, add_lt_aleph_0_iff, one_lt_aleph_0]
-- @[simp]
-- theorem aleph0_le_bit1 {c : Cardinal} : ℵ₀ ≤ bit1 c ↔ ℵ₀ ≤ c := by
-- rw [← not_iff_not]
-- simp
-- @[simp]
-- theorem bit0_le_bit0 {a b : Cardinal} : bit0 a ≤ bit0 b ↔ a ≤ b := by
-- rcases le_or_lt ℵ₀ a with ha | ha <;> rcases le_or_lt ℵ₀ b with hb | hb
-- · rw [bit0_eq_self ha, bit0_eq_self hb]
-- · rw [bit0_eq_self ha]
-- refine' iff_of_false (fun h => _) (hb.trans_le ha).not_le
-- have A : bit0 b < ℵ₀ := by simpa using hb
-- exact lt_irrefl _ ((A.trans_le ha).trans_le h)
-- · rw [bit0_eq_self hb]
-- exact iff_of_true ((bit0_lt_aleph_0.2 ha).le.trans hb) (ha.le.trans hb)
-- · rcases lt_aleph_0.1 ha with ⟨m, rfl⟩
-- rcases lt_aleph_0.1 hb with ⟨n, rfl⟩
-- norm_cast
-- exact bit0_le_bit0
-- @[simp]
-- theorem bit0_le_bit1 {a b : Cardinal} : bit0 a ≤ bit1 b ↔ a ≤ b := by
-- rcases le_or_lt ℵ₀ a with ha | ha <;> rcases le_or_lt ℵ₀ b with hb | hb
-- · rw [bit0_eq_self ha, bit1_eq_self_iff.2 hb]
-- · rw [bit0_eq_self ha]
-- refine' iff_of_false (fun h => _) (hb.trans_le ha).not_le
-- have A : bit1 b < ℵ₀ := by simpa using hb
-- exact lt_irrefl _ ((A.trans_le ha).trans_le h)
-- · rw [bit1_eq_self_iff.2 hb]
-- exact iff_of_true ((bit0_lt_aleph_0.2 ha).le.trans hb) (ha.le.trans hb)
-- · rcases lt_aleph_0.1 ha with ⟨m, rfl⟩
-- rcases lt_aleph_0.1 hb with ⟨n, rfl⟩
-- norm_cast
-- exact Nat.bit0_le_bit1_iff
-- @[simp]
-- theorem bit1_le_bit1 {a b : Cardinal} : bit1 a ≤ bit1 b ↔ a ≤ b :=
-- ⟨fun h => bit0_le_bit1.1 ((self_le_add_right (bit0 a) 1).trans h), fun h =>
-- (add_le_add_right (add_le_add_left h a) 1).trans (add_le_add_right (add_le_add_right h b) 1)⟩
-- @[simp]
-- theorem bit1_le_bit0 {a b : Cardinal} : bit1 a ≤ bit0 b ↔ a < b ∨ a ≤ b ∧ ℵ₀ ≤ a := by
-- rcases le_or_lt ℵ₀ a with ha | ha <;> rcases le_or_lt ℵ₀ b with hb | hb
-- · simp only [bit1_eq_self_iff.mpr ha, bit0_eq_self hb, ha, and_true_iff]
-- refine' ⟨fun h => Or.inr h, fun h => _⟩
-- cases h
-- · exact le_of_lt h
-- · exact h
-- · rw [bit1_eq_self_iff.2 ha]
-- refine' iff_of_false (fun h => _) fun h => _
-- · have A : bit0 b < ℵ₀ := by simpa using hb
-- exact lt_irrefl _ ((A.trans_le ha).trans_le h)
-- · exact not_le_of_lt (hb.trans_le ha) (h.elim le_of_lt And.left)
-- · rw [bit0_eq_self hb]
-- exact iff_of_true ((bit1_lt_aleph_0.2 ha).le.trans hb) (Or.inl <| ha.trans_le hb)
-- · rcases lt_aleph_0.1 ha with ⟨m, rfl⟩
-- rcases lt_aleph_0.1 hb with ⟨n, rfl⟩
-- norm_cast
-- simp [not_le.mpr ha]
-- @[simp]
-- theorem bit0_lt_bit0 {a b : Cardinal} : bit0 a < bit0 b ↔ a < b := by
-- rcases le_or_lt ℵ₀ a with ha | ha <;> rcases le_or_lt ℵ₀ b with hb | hb
-- · rw [bit0_eq_self ha, bit0_eq_self hb]
-- · rw [bit0_eq_self ha]
-- refine' iff_of_false (fun h => _) (hb.le.trans ha).not_lt
-- have A : bit0 b < ℵ₀ := by simpa using hb
-- exact lt_irrefl _ ((A.trans_le ha).trans h)
-- · rw [bit0_eq_self hb]
-- exact iff_of_true ((bit0_lt_aleph_0.2 ha).trans_le hb) (ha.trans_le hb)
-- · rcases lt_aleph_0.1 ha with ⟨m, rfl⟩
-- rcases lt_aleph_0.1 hb with ⟨n, rfl⟩
-- norm_cast
-- exact bit0_lt_bit0
-- @[simp]
-- theorem bit1_lt_bit0 {a b : Cardinal} : bit1 a < bit0 b ↔ a < b := by
-- rcases le_or_lt ℵ₀ a with ha | ha <;> rcases le_or_lt ℵ₀ b with hb | hb
-- · rw [bit1_eq_self_iff.2 ha, bit0_eq_self hb]
-- · rw [bit1_eq_self_iff.2 ha]
-- refine' iff_of_false (fun h => _) (hb.le.trans ha).not_lt
-- have A : bit0 b < ℵ₀ := by simpa using hb
-- exact lt_irrefl _ ((A.trans_le ha).trans h)
-- · rw [bit0_eq_self hb]
-- exact iff_of_true ((bit1_lt_aleph_0.2 ha).trans_le hb) (ha.trans_le hb)
-- · rcases lt_aleph_0.1 ha with ⟨m, rfl⟩
-- rcases lt_aleph_0.1 hb with ⟨n, rfl⟩
-- norm_cast
-- exact Nat.bit1_lt_bit0_iff
-- @[simp]
-- theorem bit1_lt_bit1 {a b : Cardinal} : bit1 a < bit1 b ↔ a < b := by
-- rcases le_or_lt ℵ₀ a with ha | ha <;> rcases le_or_lt ℵ₀ b with hb | hb
-- · rw [bit1_eq_self_iff.2 ha, bit1_eq_self_iff.2 hb]
-- · rw [bit1_eq_self_iff.2 ha]
-- refine' iff_of_false (fun h => _) (hb.le.trans ha).not_lt
-- have A : bit1 b < ℵ₀ := by simpa using hb
-- exact lt_irrefl _ ((A.trans_le ha).trans h)
-- · rw [bit1_eq_self_iff.2 hb]
-- exact iff_of_true ((bit1_lt_aleph_0.2 ha).trans_le hb) (ha.trans_le hb)
-- · rcases lt_aleph_0.1 ha with ⟨m, rfl⟩
-- rcases lt_aleph_0.1 hb with ⟨n, rfl⟩
-- norm_cast
-- exact bit1_lt_bit1
-- @[simp]
-- theorem bit0_lt_bit1 {a b : Cardinal} : bit0 a < bit1 b ↔ a < b ∨ a ≤ b ∧ a < ℵ₀ := by
-- rcases le_or_lt ℵ₀ a with ha | ha <;> rcases le_or_lt ℵ₀ b with hb | hb
-- · simp [bit0_eq_self ha, bit1_eq_self_iff.2 hb, not_lt.mpr ha]
-- · rw [bit0_eq_self ha]
-- refine' iff_of_false (fun h => _) fun h => _
-- · have A : bit1 b < ℵ₀ := by simpa using hb
-- exact lt_irrefl _ ((A.trans_le ha).trans h)
-- · exact (hb.trans_le ha).not_le (h.elim le_of_lt And.left)
-- · rw [bit1_eq_self_iff.2 hb]
-- exact iff_of_true ((bit0_lt_aleph_0.2 ha).trans_le hb) (Or.inl <| ha.trans_le hb)
-- · rcases lt_aleph_0.1 ha with ⟨m, rfl⟩
-- rcases lt_aleph_0.1 hb with ⟨n, rfl⟩
-- norm_cast
-- simp only [ha, and_true_iff, Nat.bit0_lt_bit1_iff, or_iff_right_of_imp le_of_lt]
-- theorem one_lt_two : (1 : Cardinal) < 2 := by
-- -- This strategy works generally to prove inequalities between numerals in `cardinality`.
-- norm_cast
-- norm_num
-- @[simp]
-- theorem one_lt_bit0 {a : Cardinal} : 1 < bit0 a ↔ 0 < a := by simp [← bit1_zero]
-- @[simp]
-- theorem one_lt_bit1 (a : Cardinal) : 1 < bit1 a ↔ 0 < a := by simp [← bit1_zero]
-- end Bit
end Cardinal
section Initial
namespace Ordinal
/--
`ω_ o` is a notation for the *initial ordinal* of cardinality
`aleph o`. Thus, for example `ω_ 0 = ω`.
-/
scoped notation "ω_" o => ord <| aleph o
/--
`ω₁` is the first uncountable ordinal.
-/
scoped notation "ω₁" => ord <| aleph 1
lemma omega_lt_omega1 : ω < ω₁ := ord_aleph0.symm.trans_lt (ord_lt_ord.mpr (aleph0_lt_aleph_one))
section OrdinalIndices
/-!
### Cardinal operations with ordinal indices
Results on cardinality of ordinal-indexed families of sets.
-/
namespace Cardinal
open scoped Cardinal
/--
Bounding the cardinal of an ordinal-indexed union of sets.
-/
lemma mk_iUnion_Ordinal_le_of_le {β : Type*} {o : Ordinal} {c : Cardinal}
(ho : o.card ≤ c) (hc : ℵ₀ ≤ c) (A : Ordinal → Set β)
(hA : ∀ j < o, #(A j) ≤ c) :
#(⋃ j < o, A j) ≤ c := by
simp_rw [← mem_Iio, biUnion_eq_iUnion, iUnion, iSup, ← o.enumIsoOut.symm.surjective.range_comp]
apply ((mk_iUnion_le _).trans _).trans_eq (mul_eq_self hc)
rw [mk_ordinal_out]
exact mul_le_mul' ho <| ciSup_le' <| (hA _ <| typein_lt_self ·)
end Cardinal
end OrdinalIndices
end Ordinal
end Initial
|
SetTheory\Cardinal\PartENat.lean | /-
Copyright (c) 2021 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.SetTheory.Cardinal.ToNat
import Mathlib.Data.Nat.PartENat
/-!
# Projection from cardinal numbers to `PartENat`
In this file we define the projection `Cardinal.toPartENat`
and prove basic properties of this projection.
-/
universe u v
open Function
variable {α : Type u}
namespace Cardinal
/-- This function sends finite cardinals to the corresponding natural, and infinite cardinals
to `⊤`. -/
noncomputable def toPartENat : Cardinal →+o PartENat :=
.comp
{ (PartENat.withTopAddEquiv.symm : ℕ∞ →+ PartENat),
(PartENat.withTopOrderIso.symm : ℕ∞ →o PartENat) with }
toENat
@[simp]
theorem partENatOfENat_toENat (c : Cardinal) : (toENat c : PartENat) = toPartENat c := rfl
@[simp]
theorem toPartENat_natCast (n : ℕ) : toPartENat n = n := by
simp only [← partENatOfENat_toENat, toENat_nat, PartENat.ofENat_coe]
theorem toPartENat_apply_of_lt_aleph0 {c : Cardinal} (h : c < ℵ₀) : toPartENat c = toNat c := by
lift c to ℕ using h; simp
theorem toPartENat_eq_top {c : Cardinal} :
toPartENat c = ⊤ ↔ ℵ₀ ≤ c := by
rw [← partENatOfENat_toENat, ← PartENat.withTopEquiv_symm_top, ← toENat_eq_top,
← PartENat.withTopEquiv.symm.injective.eq_iff]
simp
theorem toPartENat_apply_of_aleph0_le {c : Cardinal} (h : ℵ₀ ≤ c) : toPartENat c = ⊤ :=
congr_arg PartENat.ofENat (toENat_eq_top.2 h)
@[deprecated (since := "2024-02-15")]
alias toPartENat_cast := toPartENat_natCast
@[simp]
theorem mk_toPartENat_of_infinite [h : Infinite α] : toPartENat #α = ⊤ :=
toPartENat_apply_of_aleph0_le (infinite_iff.1 h)
@[simp]
theorem aleph0_toPartENat : toPartENat ℵ₀ = ⊤ :=
toPartENat_apply_of_aleph0_le le_rfl
theorem toPartENat_surjective : Surjective toPartENat := fun x =>
PartENat.casesOn x ⟨ℵ₀, toPartENat_apply_of_aleph0_le le_rfl⟩ fun n => ⟨n, toPartENat_natCast n⟩
@[deprecated (since := "2024-02-15")] alias toPartENat_eq_top_iff_le_aleph0 := toPartENat_eq_top
theorem toPartENat_strictMonoOn : StrictMonoOn toPartENat (Set.Iic ℵ₀) :=
PartENat.withTopOrderIso.symm.strictMono.comp_strictMonoOn toENat_strictMonoOn
lemma toPartENat_le_iff_of_le_aleph0 {c c' : Cardinal} (h : c ≤ ℵ₀) :
toPartENat c ≤ toPartENat c' ↔ c ≤ c' := by
lift c to ℕ∞ using h
simp_rw [← partENatOfENat_toENat, toENat_ofENat, enat_gc _,
← PartENat.withTopOrderIso.symm.le_iff_le, PartENat.ofENat_le, map_le_map_iff]
lemma toPartENat_le_iff_of_lt_aleph0 {c c' : Cardinal} (hc' : c' < ℵ₀) :
toPartENat c ≤ toPartENat c' ↔ c ≤ c' := by
lift c' to ℕ using hc'
simp_rw [← partENatOfENat_toENat, toENat_nat, ← toENat_le_nat,
← PartENat.withTopOrderIso.symm.le_iff_le, PartENat.ofENat_le, map_le_map_iff]
lemma toPartENat_eq_iff_of_le_aleph0 {c c' : Cardinal} (hc : c ≤ ℵ₀) (hc' : c' ≤ ℵ₀) :
toPartENat c = toPartENat c' ↔ c = c' :=
toPartENat_strictMonoOn.injOn.eq_iff hc hc'
theorem toPartENat_mono {c c' : Cardinal} (h : c ≤ c') :
toPartENat c ≤ toPartENat c' :=
OrderHomClass.mono _ h
theorem toPartENat_lift (c : Cardinal.{v}) : toPartENat (lift.{u, v} c) = toPartENat c := by
simp only [← partENatOfENat_toENat, toENat_lift]
theorem toPartENat_congr {β : Type v} (e : α ≃ β) : toPartENat #α = toPartENat #β := by
rw [← toPartENat_lift, lift_mk_eq.{_, _,v}.mpr ⟨e⟩, toPartENat_lift]
theorem mk_toPartENat_eq_coe_card [Fintype α] : toPartENat #α = Fintype.card α := by
simp
end Cardinal
|
SetTheory\Cardinal\SchroederBernstein.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Init.Classical
import Mathlib.Order.FixedPoints
import Mathlib.Order.Zorn
/-!
# Schröder-Bernstein theorem, well-ordering of cardinals
This file proves the Schröder-Bernstein theorem (see `schroeder_bernstein`), the well-ordering of
cardinals (see `min_injective`) and the totality of their order (see `total`).
## Notes
Cardinals are naturally ordered by `α ≤ β ↔ ∃ f : a → β, Injective f`:
* `schroeder_bernstein` states that, given injections `α → β` and `β → α`, one can get a
bijection `α → β`. This corresponds to the antisymmetry of the order.
* The order is also well-founded: any nonempty set of cardinals has a minimal element.
`min_injective` states that by saying that there exists an element of the set that injects into
all others.
Cardinals are defined and further developed in the folder `SetTheory.Cardinal`.
-/
open Set Function
universe u v
namespace Function
namespace Embedding
section antisymm
variable {α : Type u} {β : Type v}
/-- **The Schröder-Bernstein Theorem**:
Given injections `α → β` and `β → α`, we can get a bijection `α → β`. -/
theorem schroeder_bernstein {f : α → β} {g : β → α} (hf : Function.Injective f)
(hg : Function.Injective g) : ∃ h : α → β, Bijective h := by
classical
cases' isEmpty_or_nonempty β with hβ hβ
· have : IsEmpty α := Function.isEmpty f
exact ⟨_, ((Equiv.equivEmpty α).trans (Equiv.equivEmpty β).symm).bijective⟩
set F : Set α →o Set α :=
{ toFun := fun s => (g '' (f '' s)ᶜ)ᶜ
monotone' := fun s t hst =>
compl_subset_compl.mpr <| image_subset _ <| compl_subset_compl.mpr <| image_subset _ hst }
-- Porting note: dot notation `F.lfp` doesn't work here
set s : Set α := OrderHom.lfp F
have hs : (g '' (f '' s)ᶜ)ᶜ = s := F.map_lfp
have hns : g '' (f '' s)ᶜ = sᶜ := compl_injective (by simp [hs])
set g' := invFun g
have g'g : LeftInverse g' g := leftInverse_invFun hg
have hg'ns : g' '' sᶜ = (f '' s)ᶜ := by rw [← hns, g'g.image_image]
set h : α → β := s.piecewise f g'
have : Surjective h := by rw [← range_iff_surjective, range_piecewise, hg'ns, union_compl_self]
have : Injective h := by
refine (injective_piecewise_iff _).2 ⟨hf.injOn, ?_, ?_⟩
· intro x hx y hy hxy
obtain ⟨x', _, rfl⟩ : x ∈ g '' (f '' s)ᶜ := by rwa [hns]
obtain ⟨y', _, rfl⟩ : y ∈ g '' (f '' s)ᶜ := by rwa [hns]
rw [g'g _, g'g _] at hxy
rw [hxy]
· intro x hx y hy hxy
obtain ⟨y', hy', rfl⟩ : y ∈ g '' (f '' s)ᶜ := by rwa [hns]
rw [g'g _] at hxy
exact hy' ⟨x, hx, hxy⟩
exact ⟨h, ‹Injective h›, ‹Surjective h›⟩
/-- **The Schröder-Bernstein Theorem**: Given embeddings `α ↪ β` and `β ↪ α`, there exists an
equivalence `α ≃ β`. -/
theorem antisymm : (α ↪ β) → (β ↪ α) → Nonempty (α ≃ β)
| ⟨_, h₁⟩, ⟨_, h₂⟩ =>
let ⟨f, hf⟩ := schroeder_bernstein h₁ h₂
⟨Equiv.ofBijective f hf⟩
end antisymm
section Wo
variable {ι : Type u} (β : ι → Type v)
/-- `sets β` -/
private abbrev sets :=
{ s : Set (∀ i, β i) | ∀ x ∈ s, ∀ y ∈ s, ∀ (i), (x : ∀ i, β i) i = y i → x = y }
/-- The cardinals are well-ordered. We express it here by the fact that in any set of cardinals
there is an element that injects into the others.
See `Cardinal.conditionallyCompleteLinearOrderBot` for (one of) the lattice instances. -/
theorem min_injective [I : Nonempty ι] : ∃ i, Nonempty (∀ j, β i ↪ β j) :=
let ⟨s, hs, ms⟩ :=
show ∃ s ∈ sets β, ∀ a ∈ sets β, s ⊆ a → a = s from
zorn_subset (sets β) fun c hc hcc =>
⟨⋃₀c, fun x ⟨p, hpc, hxp⟩ y ⟨q, hqc, hyq⟩ i hi =>
(hcc.total hpc hqc).elim (fun h => hc hqc x (h hxp) y hyq i hi) fun h =>
hc hpc x hxp y (h hyq) i hi,
fun _ => subset_sUnion_of_mem⟩
let ⟨i, e⟩ :=
show ∃ i, ∀ y, ∃ x ∈ s, (x : ∀ i, β i) i = y from
Classical.by_contradiction fun h =>
have h : ∀ i, ∃ y, ∀ x ∈ s, (x : ∀ i, β i) i ≠ y := by
simpa only [ne_eq, not_exists, not_forall, not_and] using h
let ⟨f, hf⟩ := Classical.axiom_of_choice h
have : f ∈ s :=
have : insert f s ∈ sets β := fun x hx y hy => by
cases' hx with hx hx <;> cases' hy with hy hy; · simp [hx, hy]
· subst x
exact fun i e => (hf i y hy e.symm).elim
· subst y
exact fun i e => (hf i x hx e).elim
· exact hs x hx y hy
ms _ this (subset_insert f s) ▸ mem_insert _ _
let ⟨i⟩ := I
hf i f this rfl
let ⟨f, hf⟩ := Classical.axiom_of_choice e
⟨i,
⟨fun j =>
⟨fun a => f a j, fun a b e' => by
let ⟨sa, ea⟩ := hf a
let ⟨sb, eb⟩ := hf b
rw [← ea, ← eb, hs _ sa _ sb _ e']⟩⟩⟩
end Wo
/-- The cardinals are totally ordered. See
`Cardinal.conditionallyCompleteLinearOrderBot` for (one of) the lattice
instance. -/
-- Porting note: `ULift.{max u v, u} α` was `ULift α`
theorem total (α : Type u) (β : Type v) : Nonempty (α ↪ β) ∨ Nonempty (β ↪ α) :=
match @min_injective Bool (fun b => cond b (ULift.{max u v, u} α) (ULift.{max u v, v} β)) ⟨true⟩
with
| ⟨true, ⟨h⟩⟩ =>
let ⟨f, hf⟩ := h false
Or.inl ⟨Embedding.congr Equiv.ulift Equiv.ulift ⟨f, hf⟩⟩
| ⟨false, ⟨h⟩⟩ =>
let ⟨f, hf⟩ := h true
Or.inr ⟨Embedding.congr Equiv.ulift Equiv.ulift ⟨f, hf⟩⟩
end Embedding
end Function
|
SetTheory\Cardinal\Subfield.lean | /-
Copyright (c) 2023 Junyan Xu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Junyan Xu
-/
import Mathlib.Algebra.Field.Subfield
import Mathlib.Data.W.Cardinal
import Mathlib.Tactic.FinCases
/-!
# Cardinality of the division ring generated by a set
`Subfield.cardinal_mk_closure_le_max`: the cardinality of the (sub-)division ring
generated by a set is bounded by the cardinality of the set unless it is finite.
The method used to prove this (via `WType`) can be easily generalized to other algebraic
structures, but those cardinalities can usually be obtained by other means, using some
explicit universal objects.
-/
universe u
variable {α : Type u} (s : Set α)
namespace Subfield
private abbrev Operands : Fin 6 ⊕ s → Type
| .inl 0 => Bool -- add
| .inl 1 => Bool -- mul
| .inl 2 => Unit -- neg
| .inl 3 => Unit -- inv
| .inl 4 => Empty -- zero
| .inl 5 => Empty -- one
| .inr _ => Empty -- s
variable [DivisionRing α]
private def operate : (Σ n, Operands s n → closure s) → closure s
| ⟨.inl 0, f⟩ => f false + f true
| ⟨.inl 1, f⟩ => f false * f true
| ⟨.inl 2, f⟩ => - f ()
| ⟨.inl 3, f⟩ => (f ())⁻¹
| ⟨.inl 4, _⟩ => 0
| ⟨.inl 5, _⟩ => 1
| ⟨.inr a, _⟩ => ⟨a, subset_closure a.prop⟩
private def rangeOfWType : Subfield (closure s) where
carrier := Set.range (WType.elim _ <| operate s)
add_mem' := by rintro _ _ ⟨x, rfl⟩ ⟨y, rfl⟩; exact ⟨WType.mk (.inl 0) (Bool.rec x y), by rfl⟩
mul_mem' := by rintro _ _ ⟨x, rfl⟩ ⟨y, rfl⟩; exact ⟨WType.mk (.inl 1) (Bool.rec x y), by rfl⟩
neg_mem' := by rintro _ ⟨x, rfl⟩; exact ⟨WType.mk (.inl 2) fun _ ↦ x, rfl⟩
inv_mem' := by rintro _ ⟨x, rfl⟩; exact ⟨WType.mk (.inl 3) fun _ ↦ x, rfl⟩
zero_mem' := ⟨WType.mk (.inl 4) Empty.rec, rfl⟩
one_mem' := ⟨WType.mk (.inl 5) Empty.rec, rfl⟩
private lemma rangeOfWType_eq_top : rangeOfWType s = ⊤ := top_le_iff.mp fun a _ ↦ by
rw [← SetLike.mem_coe, ← Subtype.val_injective.mem_set_image]
change ↑a ∈ map (closure s).subtype _
refine closure_le.mpr (fun a ha ↦ ?_) a.prop
exact ⟨⟨a, subset_closure ha⟩, ⟨WType.mk (.inr ⟨a, ha⟩) Empty.rec, rfl⟩, rfl⟩
private lemma surjective_ofWType : Function.Surjective (WType.elim _ <| operate s) := by
rw [← Set.range_iff_surjective]
exact SetLike.coe_set_eq.mpr (rangeOfWType_eq_top s)
open Cardinal
lemma cardinal_mk_closure_le_max : #(closure s) ≤ max #s ℵ₀ :=
(Cardinal.mk_le_of_surjective <| surjective_ofWType s).trans <| by
convert WType.cardinal_mk_le_max_aleph0_of_finite' using 1
· rw [lift_uzero, mk_sum, lift_uzero]
have : lift.{u,0} #(Fin 6) < ℵ₀ := lift_lt_aleph0.mpr (lt_aleph0_of_finite _)
obtain h|h := lt_or_le #s ℵ₀
· rw [max_eq_right h.le, max_eq_right]
exact (add_lt_aleph0 this h).le
· rw [max_eq_left h, add_eq_right h (this.le.trans h), max_eq_left h]
rintro (n|_)
· fin_cases n <;> infer_instance
infer_instance
lemma cardinal_mk_closure [Infinite s] : #(closure s) = #s :=
((cardinal_mk_closure_le_max s).trans_eq <| max_eq_left <| aleph0_le_mk s).antisymm
(mk_le_mk_of_subset subset_closure)
end Subfield
|
SetTheory\Cardinal\ToNat.lean | /-
Copyright (c) 2021 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import Mathlib.SetTheory.Cardinal.ENat
/-!
# Projection from cardinal numbers to natural numbers
In this file we define `Cardinal.toNat` to be the natural projection `Cardinal → ℕ`,
sending all infinite cardinals to zero.
We also prove basic lemmas about this definition.
-/
universe u v
open Function Set
namespace Cardinal
variable {α : Type u} {c d : Cardinal.{u}}
/-- This function sends finite cardinals to the corresponding natural, and infinite cardinals
to 0. -/
noncomputable def toNat : Cardinal →*₀ ℕ :=
ENat.toNatHom.comp toENat
@[simp] lemma toNat_toENat (a : Cardinal) : ENat.toNat (toENat a) = toNat a := rfl
@[simp]
theorem toNat_ofENat (n : ℕ∞) : toNat n = ENat.toNat n :=
congr_arg ENat.toNat <| toENat_ofENat n
@[simp, norm_cast] theorem toNat_natCast (n : ℕ) : toNat n = n := toNat_ofENat n
@[simp]
lemma toNat_eq_zero : toNat c = 0 ↔ c = 0 ∨ ℵ₀ ≤ c := by
rw [← toNat_toENat, ENat.toNat_eq_zero, toENat_eq_zero, toENat_eq_top]
lemma toNat_ne_zero : toNat c ≠ 0 ↔ c ≠ 0 ∧ c < ℵ₀ := by simp [not_or]
@[simp] lemma toNat_pos : 0 < toNat c ↔ c ≠ 0 ∧ c < ℵ₀ := pos_iff_ne_zero.trans toNat_ne_zero
theorem cast_toNat_of_lt_aleph0 {c : Cardinal} (h : c < ℵ₀) : ↑(toNat c) = c := by
lift c to ℕ using h
rw [toNat_natCast]
theorem toNat_apply_of_lt_aleph0 {c : Cardinal.{u}} (h : c < ℵ₀) :
toNat c = Classical.choose (lt_aleph0.1 h) :=
Nat.cast_injective (R := Cardinal.{u}) <| by
rw [cast_toNat_of_lt_aleph0 h, ← Classical.choose_spec (lt_aleph0.1 h)]
theorem toNat_apply_of_aleph0_le {c : Cardinal} (h : ℵ₀ ≤ c) : toNat c = 0 := by simp [h]
theorem cast_toNat_of_aleph0_le {c : Cardinal} (h : ℵ₀ ≤ c) : ↑(toNat c) = (0 : Cardinal) := by
rw [toNat_apply_of_aleph0_le h, Nat.cast_zero]
theorem toNat_strictMonoOn : StrictMonoOn toNat (Iio ℵ₀) := by
simp only [← range_natCast, StrictMonoOn, forall_mem_range, toNat_natCast, Nat.cast_lt]
exact fun _ _ ↦ id
theorem toNat_monotoneOn : MonotoneOn toNat (Iio ℵ₀) := toNat_strictMonoOn.monotoneOn
theorem toNat_injOn : InjOn toNat (Iio ℵ₀) := toNat_strictMonoOn.injOn
/-- Two finite cardinals are equal
iff they are equal their `Cardinal.toNat` projections are equal. -/
theorem toNat_eq_iff_eq_of_lt_aleph0 (hc : c < ℵ₀) (hd : d < ℵ₀) :
toNat c = toNat d ↔ c = d :=
toNat_injOn.eq_iff hc hd
theorem toNat_le_iff_le_of_lt_aleph0 (hc : c < ℵ₀) (hd : d < ℵ₀) :
toNat c ≤ toNat d ↔ c ≤ d :=
toNat_strictMonoOn.le_iff_le hc hd
theorem toNat_lt_iff_lt_of_lt_aleph0 (hc : c < ℵ₀) (hd : d < ℵ₀) :
toNat c < toNat d ↔ c < d :=
toNat_strictMonoOn.lt_iff_lt hc hd
@[gcongr]
theorem toNat_le_toNat (hcd : c ≤ d) (hd : d < ℵ₀) : toNat c ≤ toNat d :=
toNat_monotoneOn (hcd.trans_lt hd) hd hcd
@[deprecated toNat_le_toNat (since := "2024-02-15")]
theorem toNat_le_of_le_of_lt_aleph0 (hd : d < ℵ₀) (hcd : c ≤ d) :
toNat c ≤ toNat d :=
toNat_le_toNat hcd hd
theorem toNat_lt_toNat (hcd : c < d) (hd : d < ℵ₀) : toNat c < toNat d :=
toNat_strictMonoOn (hcd.trans hd) hd hcd
@[deprecated toNat_lt_toNat (since := "2024-02-15")]
theorem toNat_lt_of_lt_of_lt_aleph0 (hd : d < ℵ₀) (hcd : c < d) : toNat c < toNat d :=
toNat_lt_toNat hcd hd
@[deprecated (since := "2024-02-15")] alias toNat_cast := toNat_natCast
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem toNat_ofNat (n : ℕ) [n.AtLeastTwo] :
Cardinal.toNat (no_index (OfNat.ofNat n)) = OfNat.ofNat n :=
toNat_natCast n
/-- `toNat` has a right-inverse: coercion. -/
theorem toNat_rightInverse : Function.RightInverse ((↑) : ℕ → Cardinal) toNat :=
toNat_natCast
theorem toNat_surjective : Surjective toNat :=
toNat_rightInverse.surjective
@[simp]
theorem mk_toNat_of_infinite [h : Infinite α] : toNat #α = 0 := by simp
@[simp]
theorem aleph0_toNat : toNat ℵ₀ = 0 :=
toNat_apply_of_aleph0_le le_rfl
theorem mk_toNat_eq_card [Fintype α] : toNat #α = Fintype.card α := by simp
-- porting note (#10618): simp can prove this
-- @[simp]
theorem zero_toNat : toNat 0 = 0 := map_zero _
theorem one_toNat : toNat 1 = 1 := map_one _
theorem toNat_eq_iff {n : ℕ} (hn : n ≠ 0) : toNat c = n ↔ c = n := by
rw [← toNat_toENat, ENat.toNat_eq_iff hn, toENat_eq_nat]
/-- A version of `toNat_eq_iff` for literals -/
theorem toNat_eq_ofNat {n : ℕ} [Nat.AtLeastTwo n] :
toNat c = OfNat.ofNat n ↔ c = OfNat.ofNat n :=
toNat_eq_iff <| OfNat.ofNat_ne_zero n
@[simp]
theorem toNat_eq_one : toNat c = 1 ↔ c = 1 := by
rw [toNat_eq_iff one_ne_zero, Nat.cast_one]
theorem toNat_eq_one_iff_unique : toNat #α = 1 ↔ Subsingleton α ∧ Nonempty α :=
toNat_eq_one.trans eq_one_iff_unique
@[simp]
theorem toNat_lift (c : Cardinal.{v}) : toNat (lift.{u, v} c) = toNat c := by
simp only [← toNat_toENat, toENat_lift]
theorem toNat_congr {β : Type v} (e : α ≃ β) : toNat #α = toNat #β := by
-- Porting note: Inserted universe hint below
rw [← toNat_lift, (lift_mk_eq.{_,_,v}).mpr ⟨e⟩, toNat_lift]
theorem toNat_mul (x y : Cardinal) : toNat (x * y) = toNat x * toNat y := map_mul toNat x y
@[deprecated map_prod (since := "2024-02-15")]
theorem toNat_finset_prod (s : Finset α) (f : α → Cardinal) :
toNat (∏ i ∈ s, f i) = ∏ i ∈ s, toNat (f i) :=
map_prod toNat _ _
@[simp]
theorem toNat_add (hc : c < ℵ₀) (hd : d < ℵ₀) : toNat (c + d) = toNat c + toNat d := by
lift c to ℕ using hc
lift d to ℕ using hd
norm_cast
@[simp]
theorem toNat_lift_add_lift {a : Cardinal.{u}} {b : Cardinal.{v}} (ha : a < ℵ₀) (hb : b < ℵ₀) :
toNat (lift.{v} a + lift.{u} b) = toNat a + toNat b := by
simp [*]
@[deprecated (since := "2024-02-15")]
alias toNat_add_of_lt_aleph0 := toNat_lift_add_lift
end Cardinal
|
SetTheory\Cardinal\UnivLE.lean | /-
Copyright (c) 2023 Junyan Xu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Junyan Xu
-/
import Mathlib.Logic.UnivLE
import Mathlib.SetTheory.Ordinal.Basic
/-!
# UnivLE and cardinals
-/
noncomputable section
universe u v
open Cardinal
theorem univLE_iff_cardinal_le : UnivLE.{u, v} ↔ univ.{u, v+1} ≤ univ.{v, u+1} := by
rw [← not_iff_not, UnivLE]; simp_rw [small_iff_lift_mk_lt_univ]; push_neg
-- strange: simp_rw [univ_umax.{v,u}] doesn't work
refine ⟨fun ⟨α, le⟩ ↦ ?_, fun h ↦ ?_⟩
· rw [univ_umax.{v,u}, ← lift_le.{u+1}, lift_univ, lift_lift] at le
exact le.trans_lt (lift_lt_univ'.{u,v+1} #α)
· obtain ⟨⟨α⟩, h⟩ := lt_univ'.mp h; use α
rw [univ_umax.{v,u}, ← lift_le.{u+1}, lift_univ, lift_lift]
exact h.le
/-- Together with transitivity, this shows UnivLE "IsTotalPreorder". -/
theorem univLE_total : UnivLE.{u, v} ∨ UnivLE.{v, u} := by
simp_rw [univLE_iff_cardinal_le]; apply le_total
|
SetTheory\Game\Basic.lean | /-
Copyright (c) 2019 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton, Mario Carneiro, Isabel Longbottom, Scott Morrison, Apurva Nakade
-/
import Mathlib.Algebra.Order.Group.Defs
import Mathlib.Algebra.Ring.Int
import Mathlib.SetTheory.Game.PGame
import Mathlib.Tactic.Abel
/-!
# Combinatorial games.
In this file we construct an instance `OrderedAddCommGroup SetTheory.Game`.
## Multiplication on pre-games
We define the operations of multiplication and inverse on pre-games, and prove a few basic theorems
about them. Multiplication is not well-behaved under equivalence of pre-games i.e. `x ≈ y` does not
imply `x * z ≈ y * z`. Hence, multiplication is not a well-defined operation on games. Nevertheless,
the abelian group structure on games allows us to simplify many proofs for pre-games.
-/
-- Porting note: many definitions here are noncomputable as the compiler does not support PGame.rec
noncomputable section
namespace SetTheory
open Function PGame
open PGame
universe u
-- Porting note: moved the setoid instance to PGame.lean
/-- The type of combinatorial games. In ZFC, a combinatorial game is constructed from
two sets of combinatorial games that have been constructed at an earlier
stage. To do this in type theory, we say that a combinatorial pre-game is built
inductively from two families of combinatorial games indexed over any type
in Type u. The resulting type `PGame.{u}` lives in `Type (u+1)`,
reflecting that it is a proper class in ZFC.
A combinatorial game is then constructed by quotienting by the equivalence
`x ≈ y ↔ x ≤ y ∧ y ≤ x`. -/
abbrev Game :=
Quotient PGame.setoid
namespace Game
-- Porting note (#11445): added this definition
/-- Negation of games. -/
instance : Neg Game where
neg := Quot.map Neg.neg <| fun _ _ => (neg_equiv_neg_iff).2
instance : Zero Game where zero := ⟦0⟧
instance : Add Game where
add := Quotient.map₂ HAdd.hAdd <| fun _ _ hx _ _ hy => PGame.add_congr hx hy
instance instAddCommGroupWithOneGame : AddCommGroupWithOne Game where
zero := ⟦0⟧
one := ⟦1⟧
add_zero := by
rintro ⟨x⟩
exact Quot.sound (add_zero_equiv x)
zero_add := by
rintro ⟨x⟩
exact Quot.sound (zero_add_equiv x)
add_assoc := by
rintro ⟨x⟩ ⟨y⟩ ⟨z⟩
exact Quot.sound add_assoc_equiv
add_left_neg := Quotient.ind <| fun x => Quot.sound (add_left_neg_equiv x)
add_comm := by
rintro ⟨x⟩ ⟨y⟩
exact Quot.sound add_comm_equiv
nsmul := nsmulRec
zsmul := zsmulRec
instance : Inhabited Game :=
⟨0⟩
instance instPartialOrderGame : PartialOrder Game where
le := Quotient.lift₂ (· ≤ ·) fun x₁ y₁ x₂ y₂ hx hy => propext (le_congr hx hy)
le_refl := by
rintro ⟨x⟩
exact le_refl x
le_trans := by
rintro ⟨x⟩ ⟨y⟩ ⟨z⟩
exact @le_trans _ _ x y z
le_antisymm := by
rintro ⟨x⟩ ⟨y⟩ h₁ h₂
apply Quot.sound
exact ⟨h₁, h₂⟩
lt := Quotient.lift₂ (· < ·) fun x₁ y₁ x₂ y₂ hx hy => propext (lt_congr hx hy)
lt_iff_le_not_le := by
rintro ⟨x⟩ ⟨y⟩
exact @lt_iff_le_not_le _ _ x y
/-- The less or fuzzy relation on games.
If `0 ⧏ x` (less or fuzzy with), then Left can win `x` as the first player. -/
def LF : Game → Game → Prop :=
Quotient.lift₂ PGame.LF fun _ _ _ _ hx hy => propext (lf_congr hx hy)
local infixl:50 " ⧏ " => LF
/-- On `Game`, simp-normal inequalities should use as few negations as possible. -/
@[simp]
theorem not_le : ∀ {x y : Game}, ¬x ≤ y ↔ y ⧏ x := by
rintro ⟨x⟩ ⟨y⟩
exact PGame.not_le
/-- On `Game`, simp-normal inequalities should use as few negations as possible. -/
@[simp]
theorem not_lf : ∀ {x y : Game}, ¬x ⧏ y ↔ y ≤ x := by
rintro ⟨x⟩ ⟨y⟩
exact PGame.not_lf
-- Porting note: had to replace ⧏ with LF, otherwise cannot differentiate with the operator on PGame
instance : IsTrichotomous Game LF :=
⟨by
rintro ⟨x⟩ ⟨y⟩
change _ ∨ ⟦x⟧ = ⟦y⟧ ∨ _
rw [Quotient.eq]
apply lf_or_equiv_or_gf⟩
/-! It can be useful to use these lemmas to turn `PGame` inequalities into `Game` inequalities, as
the `AddCommGroup` structure on `Game` often simplifies many proofs. -/
-- Porting note: In a lot of places, I had to add explicitely that the quotient element was a Game.
-- In Lean4, quotients don't have the setoid as an instance argument,
-- but as an explicit argument, see https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/confusion.20between.20equivalence.20and.20instance.20setoid/near/360822354
theorem PGame.le_iff_game_le {x y : PGame} : x ≤ y ↔ (⟦x⟧ : Game) ≤ ⟦y⟧ :=
Iff.rfl
theorem PGame.lf_iff_game_lf {x y : PGame} : PGame.LF x y ↔ ⟦x⟧ ⧏ ⟦y⟧ :=
Iff.rfl
theorem PGame.lt_iff_game_lt {x y : PGame} : x < y ↔ (⟦x⟧ : Game) < ⟦y⟧ :=
Iff.rfl
theorem PGame.equiv_iff_game_eq {x y : PGame} : x ≈ y ↔ (⟦x⟧ : Game) = ⟦y⟧ :=
(@Quotient.eq' _ _ x y).symm
/-- The fuzzy, confused, or incomparable relation on games.
If `x ‖ 0`, then the first player can always win `x`. -/
def Fuzzy : Game → Game → Prop :=
Quotient.lift₂ PGame.Fuzzy fun _ _ _ _ hx hy => propext (fuzzy_congr hx hy)
local infixl:50 " ‖ " => Fuzzy
theorem PGame.fuzzy_iff_game_fuzzy {x y : PGame} : PGame.Fuzzy x y ↔ ⟦x⟧ ‖ ⟦y⟧ :=
Iff.rfl
instance covariantClass_add_le : CovariantClass Game Game (· + ·) (· ≤ ·) :=
⟨by
rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ h
exact @add_le_add_left _ _ _ _ b c h a⟩
instance covariantClass_swap_add_le : CovariantClass Game Game (swap (· + ·)) (· ≤ ·) :=
⟨by
rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ h
exact @add_le_add_right _ _ _ _ b c h a⟩
instance covariantClass_add_lt : CovariantClass Game Game (· + ·) (· < ·) :=
⟨by
rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ h
exact @add_lt_add_left _ _ _ _ b c h a⟩
instance covariantClass_swap_add_lt : CovariantClass Game Game (swap (· + ·)) (· < ·) :=
⟨by
rintro ⟨a⟩ ⟨b⟩ ⟨c⟩ h
exact @add_lt_add_right _ _ _ _ b c h a⟩
theorem add_lf_add_right : ∀ {b c : Game} (_ : b ⧏ c) (a), (b + a : Game) ⧏ c + a := by
rintro ⟨b⟩ ⟨c⟩ h ⟨a⟩
apply PGame.add_lf_add_right h
theorem add_lf_add_left : ∀ {b c : Game} (_ : b ⧏ c) (a), (a + b : Game) ⧏ a + c := by
rintro ⟨b⟩ ⟨c⟩ h ⟨a⟩
apply PGame.add_lf_add_left h
instance orderedAddCommGroup : OrderedAddCommGroup Game :=
{ Game.instAddCommGroupWithOneGame, Game.instPartialOrderGame with
add_le_add_left := @add_le_add_left _ _ _ Game.covariantClass_add_le }
/-- A small family of games is bounded above. -/
lemma bddAbove_range_of_small {ι : Type*} [Small.{u} ι] (f : ι → Game.{u}) :
BddAbove (Set.range f) := by
obtain ⟨x, hx⟩ := PGame.bddAbove_range_of_small (Quotient.out ∘ f)
refine ⟨⟦x⟧, Set.forall_mem_range.2 fun i ↦ ?_⟩
simpa [PGame.le_iff_game_le] using hx $ Set.mem_range_self i
/-- A small set of games is bounded above. -/
lemma bddAbove_of_small (s : Set Game.{u}) [Small.{u} s] : BddAbove s := by
simpa using bddAbove_range_of_small (Subtype.val : s → Game.{u})
/-- A small family of games is bounded below. -/
lemma bddBelow_range_of_small {ι : Type*} [Small.{u} ι] (f : ι → Game.{u}) :
BddBelow (Set.range f) := by
obtain ⟨x, hx⟩ := PGame.bddBelow_range_of_small (Quotient.out ∘ f)
refine ⟨⟦x⟧, Set.forall_mem_range.2 fun i ↦ ?_⟩
simpa [PGame.le_iff_game_le] using hx $ Set.mem_range_self i
/-- A small set of games is bounded below. -/
lemma bddBelow_of_small (s : Set Game.{u}) [Small.{u} s] : BddBelow s := by
simpa using bddBelow_range_of_small (Subtype.val : s → Game.{u})
end Game
namespace PGame
@[simp]
theorem quot_neg (a : PGame) : (⟦-a⟧ : Game) = -⟦a⟧ :=
rfl
@[simp]
theorem quot_add (a b : PGame) : ⟦a + b⟧ = (⟦a⟧ : Game) + ⟦b⟧ :=
rfl
@[simp]
theorem quot_sub (a b : PGame) : ⟦a - b⟧ = (⟦a⟧ : Game) - ⟦b⟧ :=
rfl
theorem quot_eq_of_mk'_quot_eq {x y : PGame} (L : x.LeftMoves ≃ y.LeftMoves)
(R : x.RightMoves ≃ y.RightMoves) (hl : ∀ i, (⟦x.moveLeft i⟧ : Game) = ⟦y.moveLeft (L i)⟧)
(hr : ∀ j, (⟦x.moveRight j⟧ : Game) = ⟦y.moveRight (R j)⟧) : (⟦x⟧ : Game) = ⟦y⟧ := by
exact Quot.sound (equiv_of_mk_equiv L R (fun _ => Game.PGame.equiv_iff_game_eq.2 (hl _))
(fun _ => Game.PGame.equiv_iff_game_eq.2 (hr _)))
/-! Multiplicative operations can be defined at the level of pre-games,
but to prove their properties we need to use the abelian group structure of games.
Hence we define them here. -/
/-- The product of `x = {xL | xR}` and `y = {yL | yR}` is
`{xL*y + x*yL - xL*yL, xR*y + x*yR - xR*yR | xL*y + x*yR - xL*yR, x*yL + xR*y - xR*yL }`. -/
instance : Mul PGame.{u} :=
⟨fun x y => by
induction' x with xl xr _ _ IHxl IHxr generalizing y
induction' y with yl yr yL yR IHyl IHyr
have y := mk yl yr yL yR
refine ⟨(xl × yl) ⊕ (xr × yr), (xl × yr) ⊕ (xr × yl), ?_, ?_⟩ <;> rintro (⟨i, j⟩ | ⟨i, j⟩)
· exact IHxl i y + IHyl j - IHxl i (yL j)
· exact IHxr i y + IHyr j - IHxr i (yR j)
· exact IHxl i y + IHyr j - IHxl i (yR j)
· exact IHxr i y + IHyl j - IHxr i (yL j)⟩
theorem leftMoves_mul :
∀ x y : PGame.{u},
(x * y).LeftMoves = (x.LeftMoves × y.LeftMoves ⊕ x.RightMoves × y.RightMoves)
| ⟨_, _, _, _⟩, ⟨_, _, _, _⟩ => rfl
theorem rightMoves_mul :
∀ x y : PGame.{u},
(x * y).RightMoves = (x.LeftMoves × y.RightMoves ⊕ x.RightMoves × y.LeftMoves)
| ⟨_, _, _, _⟩, ⟨_, _, _, _⟩ => rfl
/-- Turns two left or right moves for `x` and `y` into a left move for `x * y` and vice versa.
Even though these types are the same (not definitionally so), this is the preferred way to convert
between them. -/
def toLeftMovesMul {x y : PGame} :
(x.LeftMoves × y.LeftMoves) ⊕ (x.RightMoves × y.RightMoves) ≃ (x * y).LeftMoves :=
Equiv.cast (leftMoves_mul x y).symm
/-- Turns a left and a right move for `x` and `y` into a right move for `x * y` and vice versa.
Even though these types are the same (not definitionally so), this is the preferred way to convert
between them. -/
def toRightMovesMul {x y : PGame} :
(x.LeftMoves × y.RightMoves) ⊕ (x.RightMoves × y.LeftMoves) ≃ (x * y).RightMoves :=
Equiv.cast (rightMoves_mul x y).symm
@[simp]
theorem mk_mul_moveLeft_inl {xl xr yl yr} {xL xR yL yR} {i j} :
(mk xl xr xL xR * mk yl yr yL yR).moveLeft (Sum.inl (i, j)) =
xL i * mk yl yr yL yR + mk xl xr xL xR * yL j - xL i * yL j :=
rfl
@[simp]
theorem mul_moveLeft_inl {x y : PGame} {i j} :
(x * y).moveLeft (toLeftMovesMul (Sum.inl (i, j))) =
x.moveLeft i * y + x * y.moveLeft j - x.moveLeft i * y.moveLeft j := by
cases x
cases y
rfl
@[simp]
theorem mk_mul_moveLeft_inr {xl xr yl yr} {xL xR yL yR} {i j} :
(mk xl xr xL xR * mk yl yr yL yR).moveLeft (Sum.inr (i, j)) =
xR i * mk yl yr yL yR + mk xl xr xL xR * yR j - xR i * yR j :=
rfl
@[simp]
theorem mul_moveLeft_inr {x y : PGame} {i j} :
(x * y).moveLeft (toLeftMovesMul (Sum.inr (i, j))) =
x.moveRight i * y + x * y.moveRight j - x.moveRight i * y.moveRight j := by
cases x
cases y
rfl
@[simp]
theorem mk_mul_moveRight_inl {xl xr yl yr} {xL xR yL yR} {i j} :
(mk xl xr xL xR * mk yl yr yL yR).moveRight (Sum.inl (i, j)) =
xL i * mk yl yr yL yR + mk xl xr xL xR * yR j - xL i * yR j :=
rfl
@[simp]
theorem mul_moveRight_inl {x y : PGame} {i j} :
(x * y).moveRight (toRightMovesMul (Sum.inl (i, j))) =
x.moveLeft i * y + x * y.moveRight j - x.moveLeft i * y.moveRight j := by
cases x
cases y
rfl
@[simp]
theorem mk_mul_moveRight_inr {xl xr yl yr} {xL xR yL yR} {i j} :
(mk xl xr xL xR * mk yl yr yL yR).moveRight (Sum.inr (i, j)) =
xR i * mk yl yr yL yR + mk xl xr xL xR * yL j - xR i * yL j :=
rfl
@[simp]
theorem mul_moveRight_inr {x y : PGame} {i j} :
(x * y).moveRight (toRightMovesMul (Sum.inr (i, j))) =
x.moveRight i * y + x * y.moveLeft j - x.moveRight i * y.moveLeft j := by
cases x
cases y
rfl
-- @[simp] -- Porting note: simpNF linter complains
theorem neg_mk_mul_moveLeft_inl {xl xr yl yr} {xL xR yL yR} {i j} :
(-(mk xl xr xL xR * mk yl yr yL yR)).moveLeft (Sum.inl (i, j)) =
-(xL i * mk yl yr yL yR + mk xl xr xL xR * yR j - xL i * yR j) :=
rfl
-- @[simp] -- Porting note: simpNF linter complains
theorem neg_mk_mul_moveLeft_inr {xl xr yl yr} {xL xR yL yR} {i j} :
(-(mk xl xr xL xR * mk yl yr yL yR)).moveLeft (Sum.inr (i, j)) =
-(xR i * mk yl yr yL yR + mk xl xr xL xR * yL j - xR i * yL j) :=
rfl
-- @[simp] -- Porting note: simpNF linter complains
theorem neg_mk_mul_moveRight_inl {xl xr yl yr} {xL xR yL yR} {i j} :
(-(mk xl xr xL xR * mk yl yr yL yR)).moveRight (Sum.inl (i, j)) =
-(xL i * mk yl yr yL yR + mk xl xr xL xR * yL j - xL i * yL j) :=
rfl
-- @[simp] -- Porting note: simpNF linter complains
theorem neg_mk_mul_moveRight_inr {xl xr yl yr} {xL xR yL yR} {i j} :
(-(mk xl xr xL xR * mk yl yr yL yR)).moveRight (Sum.inr (i, j)) =
-(xR i * mk yl yr yL yR + mk xl xr xL xR * yR j - xR i * yR j) :=
rfl
theorem leftMoves_mul_cases {x y : PGame} (k) {P : (x * y).LeftMoves → Prop}
(hl : ∀ ix iy, P <| toLeftMovesMul (Sum.inl ⟨ix, iy⟩))
(hr : ∀ jx jy, P <| toLeftMovesMul (Sum.inr ⟨jx, jy⟩)) : P k := by
rw [← toLeftMovesMul.apply_symm_apply k]
rcases toLeftMovesMul.symm k with (⟨ix, iy⟩ | ⟨jx, jy⟩)
· apply hl
· apply hr
theorem rightMoves_mul_cases {x y : PGame} (k) {P : (x * y).RightMoves → Prop}
(hl : ∀ ix jy, P <| toRightMovesMul (Sum.inl ⟨ix, jy⟩))
(hr : ∀ jx iy, P <| toRightMovesMul (Sum.inr ⟨jx, iy⟩)) : P k := by
rw [← toRightMovesMul.apply_symm_apply k]
rcases toRightMovesMul.symm k with (⟨ix, iy⟩ | ⟨jx, jy⟩)
· apply hl
· apply hr
/-- `x * y` and `y * x` have the same moves. -/
def mulCommRelabelling (x y : PGame.{u}) : x * y ≡r y * x :=
match x, y with
| ⟨xl, xr, xL, xR⟩, ⟨yl, yr, yL, yR⟩ => by
refine ⟨Equiv.sumCongr (Equiv.prodComm _ _) (Equiv.prodComm _ _),
(Equiv.sumComm _ _).trans (Equiv.sumCongr (Equiv.prodComm _ _) (Equiv.prodComm _ _)), ?_, ?_⟩
<;>
rintro (⟨i, j⟩ | ⟨i, j⟩) <;>
{ dsimp
exact ((addCommRelabelling _ _).trans <|
(mulCommRelabelling _ _).addCongr (mulCommRelabelling _ _)).subCongr
(mulCommRelabelling _ _) }
termination_by (x, y)
theorem quot_mul_comm (x y : PGame.{u}) : (⟦x * y⟧ : Game) = ⟦y * x⟧ :=
Quot.sound (mulCommRelabelling x y).equiv
/-- `x * y` is equivalent to `y * x`. -/
theorem mul_comm_equiv (x y : PGame) : x * y ≈ y * x :=
Quotient.exact <| quot_mul_comm _ _
instance isEmpty_mul_zero_leftMoves (x : PGame.{u}) : IsEmpty (x * 0).LeftMoves := by
cases x
exact instIsEmptySum
instance isEmpty_mul_zero_rightMoves (x : PGame.{u}) : IsEmpty (x * 0).RightMoves := by
cases x
apply instIsEmptySum
instance isEmpty_zero_mul_leftMoves (x : PGame.{u}) : IsEmpty (0 * x).LeftMoves := by
cases x
apply instIsEmptySum
instance isEmpty_zero_mul_rightMoves (x : PGame.{u}) : IsEmpty (0 * x).RightMoves := by
cases x
apply instIsEmptySum
/-- `x * 0` has exactly the same moves as `0`. -/
def mulZeroRelabelling (x : PGame) : x * 0 ≡r 0 :=
Relabelling.isEmpty _
/-- `x * 0` is equivalent to `0`. -/
theorem mul_zero_equiv (x : PGame) : x * 0 ≈ 0 :=
(mulZeroRelabelling x).equiv
@[simp]
theorem quot_mul_zero (x : PGame) : (⟦x * 0⟧ : Game) = ⟦0⟧ :=
@Quotient.sound _ _ (x * 0) _ x.mul_zero_equiv
/-- `0 * x` has exactly the same moves as `0`. -/
def zeroMulRelabelling (x : PGame) : 0 * x ≡r 0 :=
Relabelling.isEmpty _
/-- `0 * x` is equivalent to `0`. -/
theorem zero_mul_equiv (x : PGame) : 0 * x ≈ 0 :=
(zeroMulRelabelling x).equiv
@[simp]
theorem quot_zero_mul (x : PGame) : (⟦0 * x⟧ : Game) = ⟦0⟧ :=
@Quotient.sound _ _ (0 * x) _ x.zero_mul_equiv
/-- `-x * y` and `-(x * y)` have the same moves. -/
def negMulRelabelling (x y : PGame.{u}) : -x * y ≡r -(x * y) :=
match x, y with
| ⟨xl, xr, xL, xR⟩, ⟨yl, yr, yL, yR⟩ => by
refine ⟨Equiv.sumComm _ _, Equiv.sumComm _ _, ?_, ?_⟩ <;>
rintro (⟨i, j⟩ | ⟨i, j⟩) <;>
· dsimp
apply ((negAddRelabelling _ _).trans _).symm
apply ((negAddRelabelling _ _).trans (Relabelling.addCongr _ _)).subCongr
-- Porting note: we used to just do `<;> exact (negMulRelabelling _ _).symm` from here.
· exact (negMulRelabelling _ _).symm
· exact (negMulRelabelling _ _).symm
-- Porting note: not sure what has gone wrong here.
-- The goal is hideous here, and the `exact` doesn't work,
-- but if we just `change` it to look like the mathlib3 goal then we're fine!?
change -(mk xl xr xL xR * _) ≡r _
exact (negMulRelabelling _ _).symm
termination_by (x, y)
@[simp]
theorem quot_neg_mul (x y : PGame) : (⟦-x * y⟧ : Game) = -⟦x * y⟧ :=
Quot.sound (negMulRelabelling x y).equiv
/-- `x * -y` and `-(x * y)` have the same moves. -/
def mulNegRelabelling (x y : PGame) : x * -y ≡r -(x * y) :=
(mulCommRelabelling x _).trans <| (negMulRelabelling _ x).trans (mulCommRelabelling y x).negCongr
@[simp]
theorem quot_mul_neg (x y : PGame) : ⟦x * -y⟧ = (-⟦x * y⟧ : Game) :=
Quot.sound (mulNegRelabelling x y).equiv
theorem quot_neg_mul_neg (x y : PGame) : ⟦-x * -y⟧ = (⟦x * y⟧ : Game) := by simp
@[simp]
theorem quot_left_distrib (x y z : PGame) : (⟦x * (y + z)⟧ : Game) = ⟦x * y⟧ + ⟦x * z⟧ :=
match x, y, z with
| mk xl xr xL xR, mk yl yr yL yR, mk zl zr zL zR => by
let x := mk xl xr xL xR
let y := mk yl yr yL yR
let z := mk zl zr zL zR
refine quot_eq_of_mk'_quot_eq ?_ ?_ ?_ ?_
· fconstructor
· rintro (⟨_, _ | _⟩ | ⟨_, _ | _⟩) <;>
-- Porting note: we've increased `maxDepth` here from `5` to `6`.
-- Likely this sort of off-by-one error is just a change in the implementation
-- of `solve_by_elim`.
solve_by_elim (config := { maxDepth := 6 }) [Sum.inl, Sum.inr, Prod.mk]
· rintro (⟨⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, _⟩ | ⟨_, _⟩) <;>
solve_by_elim (config := { maxDepth := 6 }) [Sum.inl, Sum.inr, Prod.mk]
· rintro (⟨_, _ | _⟩ | ⟨_, _ | _⟩) <;> rfl
· rintro (⟨⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, _⟩ | ⟨_, _⟩) <;> rfl
· fconstructor
· rintro (⟨_, _ | _⟩ | ⟨_, _ | _⟩) <;>
solve_by_elim (config := { maxDepth := 6 }) [Sum.inl, Sum.inr, Prod.mk]
· rintro (⟨⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, _⟩ | ⟨_, _⟩) <;>
solve_by_elim (config := { maxDepth := 6 }) [Sum.inl, Sum.inr, Prod.mk]
· rintro (⟨_, _ | _⟩ | ⟨_, _ | _⟩) <;> rfl
· rintro (⟨⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, _⟩ | ⟨_, _⟩) <;> rfl
-- Porting note: explicitly wrote out arguments to each recursive
-- quot_left_distrib reference below, because otherwise the decreasing_by block
-- failed. Previously, each branch ended with: `simp [quot_left_distrib]; abel`
-- See https://github.com/leanprover/lean4/issues/2288
· rintro (⟨i, j | k⟩ | ⟨i, j | k⟩)
· change
⟦xL i * (y + z) + x * (yL j + z) - xL i * (yL j + z)⟧ =
⟦xL i * y + x * yL j - xL i * yL j + x * z⟧
simp only [quot_sub, quot_add]
rw [quot_left_distrib (xL i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_left_distrib (mk xl xr xL xR) (yL j) (mk zl zr zL zR)]
rw [quot_left_distrib (xL i) (yL j) (mk zl zr zL zR)]
abel
· change
⟦xL i * (y + z) + x * (y + zL k) - xL i * (y + zL k)⟧ =
⟦x * y + (xL i * z + x * zL k - xL i * zL k)⟧
simp only [quot_sub, quot_add]
rw [quot_left_distrib (xL i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_left_distrib (mk xl xr xL xR) (mk yl yr yL yR) (zL k)]
rw [quot_left_distrib (xL i) (mk yl yr yL yR) (zL k)]
abel
· change
⟦xR i * (y + z) + x * (yR j + z) - xR i * (yR j + z)⟧ =
⟦xR i * y + x * yR j - xR i * yR j + x * z⟧
simp only [quot_sub, quot_add]
rw [quot_left_distrib (xR i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_left_distrib (mk xl xr xL xR) (yR j) (mk zl zr zL zR)]
rw [quot_left_distrib (xR i) (yR j) (mk zl zr zL zR)]
abel
· change
⟦xR i * (y + z) + x * (y + zR k) - xR i * (y + zR k)⟧ =
⟦x * y + (xR i * z + x * zR k - xR i * zR k)⟧
simp only [quot_sub, quot_add]
rw [quot_left_distrib (xR i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_left_distrib (mk xl xr xL xR) (mk yl yr yL yR) (zR k)]
rw [quot_left_distrib (xR i) (mk yl yr yL yR) (zR k)]
abel
· rintro (⟨i, j | k⟩ | ⟨i, j | k⟩)
· change
⟦xL i * (y + z) + x * (yR j + z) - xL i * (yR j + z)⟧ =
⟦xL i * y + x * yR j - xL i * yR j + x * z⟧
simp only [quot_sub, quot_add]
rw [quot_left_distrib (xL i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_left_distrib (mk xl xr xL xR) (yR j) (mk zl zr zL zR)]
rw [quot_left_distrib (xL i) (yR j) (mk zl zr zL zR)]
abel
· change
⟦xL i * (y + z) + x * (y + zR k) - xL i * (y + zR k)⟧ =
⟦x * y + (xL i * z + x * zR k - xL i * zR k)⟧
simp only [quot_sub, quot_add]
rw [quot_left_distrib (xL i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_left_distrib (mk xl xr xL xR) (mk yl yr yL yR) (zR k)]
rw [quot_left_distrib (xL i) (mk yl yr yL yR) (zR k)]
abel
· change
⟦xR i * (y + z) + x * (yL j + z) - xR i * (yL j + z)⟧ =
⟦xR i * y + x * yL j - xR i * yL j + x * z⟧
simp only [quot_sub, quot_add]
rw [quot_left_distrib (xR i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_left_distrib (mk xl xr xL xR) (yL j) (mk zl zr zL zR)]
rw [quot_left_distrib (xR i) (yL j) (mk zl zr zL zR)]
abel
· change
⟦xR i * (y + z) + x * (y + zL k) - xR i * (y + zL k)⟧ =
⟦x * y + (xR i * z + x * zL k - xR i * zL k)⟧
simp only [quot_sub, quot_add]
rw [quot_left_distrib (xR i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_left_distrib (mk xl xr xL xR) (mk yl yr yL yR) (zL k)]
rw [quot_left_distrib (xR i) (mk yl yr yL yR) (zL k)]
abel
termination_by (x, y, z)
/-- `x * (y + z)` is equivalent to `x * y + x * z.`-/
theorem left_distrib_equiv (x y z : PGame) : x * (y + z) ≈ x * y + x * z :=
Quotient.exact <| quot_left_distrib _ _ _
@[simp]
theorem quot_left_distrib_sub (x y z : PGame) : (⟦x * (y - z)⟧ : Game) = ⟦x * y⟧ - ⟦x * z⟧ := by
change (⟦x * (y + -z)⟧ : Game) = ⟦x * y⟧ + -⟦x * z⟧
rw [quot_left_distrib, quot_mul_neg]
@[simp]
theorem quot_right_distrib (x y z : PGame) : (⟦(x + y) * z⟧ : Game) = ⟦x * z⟧ + ⟦y * z⟧ := by
simp only [quot_mul_comm, quot_left_distrib]
/-- `(x + y) * z` is equivalent to `x * z + y * z.`-/
theorem right_distrib_equiv (x y z : PGame) : (x + y) * z ≈ x * z + y * z :=
Quotient.exact <| quot_right_distrib _ _ _
@[simp]
theorem quot_right_distrib_sub (x y z : PGame) : (⟦(y - z) * x⟧ : Game) = ⟦y * x⟧ - ⟦z * x⟧ := by
change (⟦(y + -z) * x⟧ : Game) = ⟦y * x⟧ + -⟦z * x⟧
rw [quot_right_distrib, quot_neg_mul]
/-- `x * 1` has the same moves as `x`. -/
def mulOneRelabelling : ∀ x : PGame.{u}, x * 1 ≡r x
| ⟨xl, xr, xL, xR⟩ => by
-- Porting note: the next four lines were just `unfold has_one.one,`
show _ * One.one ≡r _
unfold One.one
unfold instOnePGame
change mk _ _ _ _ * mk _ _ _ _ ≡r _
refine ⟨(Equiv.sumEmpty _ _).trans (Equiv.prodPUnit _),
(Equiv.emptySum _ _).trans (Equiv.prodPUnit _), ?_, ?_⟩ <;>
(try rintro (⟨i, ⟨⟩⟩ | ⟨i, ⟨⟩⟩)) <;>
{ dsimp
apply (Relabelling.subCongr (Relabelling.refl _) (mulZeroRelabelling _)).trans
rw [sub_zero]
exact (addZeroRelabelling _).trans <|
(((mulOneRelabelling _).addCongr (mulZeroRelabelling _)).trans <| addZeroRelabelling _) }
@[simp]
theorem quot_mul_one (x : PGame) : (⟦x * 1⟧ : Game) = ⟦x⟧ :=
Quot.sound <| PGame.Relabelling.equiv <| mulOneRelabelling x
/-- `x * 1` is equivalent to `x`. -/
theorem mul_one_equiv (x : PGame) : x * 1 ≈ x :=
Quotient.exact <| quot_mul_one x
/-- `1 * x` has the same moves as `x`. -/
def oneMulRelabelling (x : PGame) : 1 * x ≡r x :=
(mulCommRelabelling 1 x).trans <| mulOneRelabelling x
@[simp]
theorem quot_one_mul (x : PGame) : (⟦1 * x⟧ : Game) = ⟦x⟧ :=
Quot.sound <| PGame.Relabelling.equiv <| oneMulRelabelling x
/-- `1 * x` is equivalent to `x`. -/
theorem one_mul_equiv (x : PGame) : 1 * x ≈ x :=
Quotient.exact <| quot_one_mul x
theorem quot_mul_assoc (x y z : PGame) : (⟦x * y * z⟧ : Game) = ⟦x * (y * z)⟧ :=
match x, y, z with
| mk xl xr xL xR, mk yl yr yL yR, mk zl zr zL zR => by
let x := mk xl xr xL xR
let y := mk yl yr yL yR
let z := mk zl zr zL zR
refine quot_eq_of_mk'_quot_eq ?_ ?_ ?_ ?_
· fconstructor
· rintro (⟨⟨_, _⟩ | ⟨_, _⟩, _⟩ | ⟨⟨_, _⟩ | ⟨_, _⟩, _⟩) <;>
-- Porting note: as above, increased the `maxDepth` here by 1.
solve_by_elim (config := { maxDepth := 8 }) [Sum.inl, Sum.inr, Prod.mk]
· rintro (⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩) <;>
solve_by_elim (config := { maxDepth := 8 }) [Sum.inl, Sum.inr, Prod.mk]
· rintro (⟨⟨_, _⟩ | ⟨_, _⟩, _⟩ | ⟨⟨_, _⟩ | ⟨_, _⟩, _⟩) <;> rfl
· rintro (⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩) <;> rfl
· fconstructor
· rintro (⟨⟨_, _⟩ | ⟨_, _⟩, _⟩ | ⟨⟨_, _⟩ | ⟨_, _⟩, _⟩) <;>
solve_by_elim (config := { maxDepth := 8 }) [Sum.inl, Sum.inr, Prod.mk]
· rintro (⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩) <;>
solve_by_elim (config := { maxDepth := 8 }) [Sum.inl, Sum.inr, Prod.mk]
· rintro (⟨⟨_, _⟩ | ⟨_, _⟩, _⟩ | ⟨⟨_, _⟩ | ⟨_, _⟩, _⟩) <;> rfl
· rintro (⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩ | ⟨_, ⟨_, _⟩ | ⟨_, _⟩⟩) <;> rfl
-- Porting note: explicitly wrote out arguments to each recursive
-- quot_mul_assoc reference below, because otherwise the decreasing_by block
-- failed. Each branch previously ended with: `simp [quot_mul_assoc]; abel`
-- See https://github.com/leanprover/lean4/issues/2288
· rintro (⟨⟨i, j⟩ | ⟨i, j⟩, k⟩ | ⟨⟨i, j⟩ | ⟨i, j⟩, k⟩)
· change
⟦(xL i * y + x * yL j - xL i * yL j) * z + x * y * zL k -
(xL i * y + x * yL j - xL i * yL j) * zL k⟧ =
⟦xL i * (y * z) + x * (yL j * z + y * zL k - yL j * zL k) -
xL i * (yL j * z + y * zL k - yL j * zL k)⟧
simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib,
quot_left_distrib_sub, quot_left_distrib]
rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (mk zl zr zL zR)]
rw [quot_mul_assoc (xL i) (yL j) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zL k)]
rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (zL k)]
rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (zL k)]
rw [quot_mul_assoc (xL i) (yL j) (zL k)]
abel
· change
⟦(xR i * y + x * yR j - xR i * yR j) * z + x * y * zL k -
(xR i * y + x * yR j - xR i * yR j) * zL k⟧ =
⟦xR i * (y * z) + x * (yR j * z + y * zL k - yR j * zL k) -
xR i * (yR j * z + y * zL k - yR j * zL k)⟧
simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib,
quot_left_distrib_sub, quot_left_distrib]
rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (mk zl zr zL zR)]
rw [quot_mul_assoc (xR i) (yR j) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zL k)]
rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (zL k)]
rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (zL k)]
rw [quot_mul_assoc (xR i) (yR j) (zL k)]
abel
· change
⟦(xL i * y + x * yR j - xL i * yR j) * z + x * y * zR k -
(xL i * y + x * yR j - xL i * yR j) * zR k⟧ =
⟦xL i * (y * z) + x * (yR j * z + y * zR k - yR j * zR k) -
xL i * (yR j * z + y * zR k - yR j * zR k)⟧
simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib,
quot_left_distrib_sub, quot_left_distrib]
rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (mk zl zr zL zR)]
rw [quot_mul_assoc (xL i) (yR j) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zR k)]
rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (zR k)]
rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (zR k)]
rw [quot_mul_assoc (xL i) (yR j) (zR k)]
abel
· change
⟦(xR i * y + x * yL j - xR i * yL j) * z + x * y * zR k -
(xR i * y + x * yL j - xR i * yL j) * zR k⟧ =
⟦xR i * (y * z) + x * (yL j * z + y * zR k - yL j * zR k) -
xR i * (yL j * z + y * zR k - yL j * zR k)⟧
simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib,
quot_left_distrib_sub, quot_left_distrib]
rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (mk zl zr zL zR)]
rw [quot_mul_assoc (xR i) (yL j) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zR k)]
rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (zR k)]
rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (zR k)]
rw [quot_mul_assoc (xR i) (yL j) (zR k)]
abel
· rintro (⟨⟨i, j⟩ | ⟨i, j⟩, k⟩ | ⟨⟨i, j⟩ | ⟨i, j⟩, k⟩)
· change
⟦(xL i * y + x * yL j - xL i * yL j) * z + x * y * zR k -
(xL i * y + x * yL j - xL i * yL j) * zR k⟧ =
⟦xL i * (y * z) + x * (yL j * z + y * zR k - yL j * zR k) -
xL i * (yL j * z + y * zR k - yL j * zR k)⟧
simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib,
quot_left_distrib_sub, quot_left_distrib]
rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (mk zl zr zL zR)]
rw [quot_mul_assoc (xL i) (yL j) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zR k)]
rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (zR k)]
rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (zR k)]
rw [quot_mul_assoc (xL i) (yL j) (zR k)]
abel
· change
⟦(xR i * y + x * yR j - xR i * yR j) * z + x * y * zR k -
(xR i * y + x * yR j - xR i * yR j) * zR k⟧ =
⟦xR i * (y * z) + x * (yR j * z + y * zR k - yR j * zR k) -
xR i * (yR j * z + y * zR k - yR j * zR k)⟧
simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib,
quot_left_distrib_sub, quot_left_distrib]
rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (mk zl zr zL zR)]
rw [quot_mul_assoc (xR i) (yR j) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zR k)]
rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (zR k)]
rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (zR k)]
rw [quot_mul_assoc (xR i) (yR j) (zR k)]
abel
· change
⟦(xL i * y + x * yR j - xL i * yR j) * z + x * y * zL k -
(xL i * y + x * yR j - xL i * yR j) * zL k⟧ =
⟦xL i * (y * z) + x * (yR j * z + y * zL k - yR j * zL k) -
xL i * (yR j * z + y * zL k - yR j * zL k)⟧
simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib,
quot_left_distrib_sub, quot_left_distrib]
rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (mk zl zr zL zR)]
rw [quot_mul_assoc (xL i) (yR j) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zL k)]
rw [quot_mul_assoc (xL i) (mk yl yr yL yR) (zL k)]
rw [quot_mul_assoc (mk xl xr xL xR) (yR j) (zL k)]
rw [quot_mul_assoc (xL i) (yR j) (zL k)]
abel
· change
⟦(xR i * y + x * yL j - xR i * yL j) * z + x * y * zL k -
(xR i * y + x * yL j - xR i * yL j) * zL k⟧ =
⟦xR i * (y * z) + x * (yL j * z + y * zL k - yL j * zL k) -
xR i * (yL j * z + y * zL k - yL j * zL k)⟧
simp only [quot_sub, quot_add, quot_right_distrib_sub, quot_right_distrib,
quot_left_distrib_sub, quot_left_distrib]
rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (mk zl zr zL zR)]
rw [quot_mul_assoc (xR i) (yL j) (mk zl zr zL zR)]
rw [quot_mul_assoc (mk xl xr xL xR) (mk yl yr yL yR) (zL k)]
rw [quot_mul_assoc (xR i) (mk yl yr yL yR) (zL k)]
rw [quot_mul_assoc (mk xl xr xL xR) (yL j) (zL k)]
rw [quot_mul_assoc (xR i) (yL j) (zL k)]
abel
termination_by (x, y, z)
/-- `x * y * z` is equivalent to `x * (y * z).`-/
theorem mul_assoc_equiv (x y z : PGame) : x * y * z ≈ x * (y * z) :=
Quotient.exact <| quot_mul_assoc _ _ _
/-- The left options of `x * y` of the first kind, i.e. of the form `xL * y + x * yL - xL * yL`. -/
def mulOption (x y : PGame) (i : LeftMoves x) (j : LeftMoves y) : PGame :=
x.moveLeft i * y + x * y.moveLeft j - x.moveLeft i * y.moveLeft j
/-- Any left option of `x * y` of the first kind is also a left option of `x * -(-y)` of
the first kind. -/
lemma mulOption_neg_neg {x} (y) {i j} :
mulOption x y i j = mulOption x (-(-y)) i (toLeftMovesNeg <| toRightMovesNeg j) := by
dsimp only [mulOption]
congr 2
· rw [neg_neg]
iterate 2 rw [moveLeft_neg, moveRight_neg, neg_neg]
/-- The left options of `x * y` agree with that of `y * x` up to equivalence. -/
lemma mulOption_symm (x y) {i j} : ⟦mulOption x y i j⟧ = (⟦mulOption y x j i⟧ : Game) := by
dsimp only [mulOption, quot_sub, quot_add]
rw [add_comm]
congr 1
on_goal 1 => congr 1
all_goals rw [quot_mul_comm]
/-- The left options of `x * y` of the second kind are the left options of `(-x) * (-y)` of the
first kind, up to equivalence. -/
lemma leftMoves_mul_iff {x y : PGame} (P : Game → Prop) :
(∀ k, P ⟦(x * y).moveLeft k⟧) ↔
(∀ i j, P ⟦mulOption x y i j⟧) ∧ (∀ i j, P ⟦mulOption (-x) (-y) i j⟧) := by
cases x; cases y
constructor <;> intro h
on_goal 1 =>
constructor <;> intros i j
· exact h (Sum.inl (i, j))
convert h (Sum.inr (i, j)) using 1
on_goal 2 =>
rintro (⟨i, j⟩ | ⟨i, j⟩)
· exact h.1 i j
convert h.2 i j using 1
all_goals
dsimp only [mk_mul_moveLeft_inr, quot_sub, quot_add, neg_def, mulOption, moveLeft_mk]
rw [← neg_def, ← neg_def]
congr 1
on_goal 1 => congr 1
all_goals rw [quot_neg_mul_neg]
/-- The right options of `x * y` are the left options of `x * (-y)` and of `(-x) * y` of the first
kind, up to equivalence. -/
lemma rightMoves_mul_iff {x y : PGame} (P : Game → Prop) :
(∀ k, P ⟦(x * y).moveRight k⟧) ↔
(∀ i j, P (-⟦mulOption x (-y) i j⟧)) ∧ (∀ i j, P (-⟦mulOption (-x) y i j⟧)) := by
cases x; cases y
constructor <;> intro h
on_goal 1 =>
constructor <;> intros i j
on_goal 1 => convert h (Sum.inl (i, j))
on_goal 2 => convert h (Sum.inr (i, j))
on_goal 3 =>
rintro (⟨i, j⟩ | ⟨i, j⟩)
on_goal 1 => convert h.1 i j using 1
on_goal 2 => convert h.2 i j using 1
all_goals
dsimp [mulOption]
rw [neg_sub', neg_add, ← neg_def]
congr 1
on_goal 1 => congr 1
any_goals rw [quot_neg_mul, neg_neg]
iterate 6 rw [quot_mul_neg, neg_neg]
/-- Because the two halves of the definition of `inv` produce more elements
on each side, we have to define the two families inductively.
This is the indexing set for the function, and `invVal` is the function part. -/
inductive InvTy (l r : Type u) : Bool → Type u
| zero : InvTy l r false
| left₁ : r → InvTy l r false → InvTy l r false
| left₂ : l → InvTy l r true → InvTy l r false
| right₁ : l → InvTy l r false → InvTy l r true
| right₂ : r → InvTy l r true → InvTy l r true
instance (l r : Type u) [IsEmpty l] [IsEmpty r] : IsEmpty (InvTy l r true) :=
⟨by rintro (_ | _ | _ | a | a) <;> exact isEmptyElim a⟩
instance InvTy.instInhabited (l r : Type u) : Inhabited (InvTy l r false) :=
⟨InvTy.zero⟩
instance uniqueInvTy (l r : Type u) [IsEmpty l] [IsEmpty r] : Unique (InvTy l r false) :=
{ InvTy.instInhabited l r with
uniq := by
rintro (a | a | a)
· rfl
all_goals exact isEmptyElim a }
/-- Because the two halves of the definition of `inv` produce more elements
of each side, we have to define the two families inductively.
This is the function part, defined by recursion on `InvTy`. -/
def invVal {l r} (L : l → PGame) (R : r → PGame) (IHl : l → PGame) (IHr : r → PGame)
(x : PGame) : ∀ {b}, InvTy l r b → PGame
| _, InvTy.zero => 0
| _, InvTy.left₁ i j => (1 + (R i - x) * invVal L R IHl IHr x j) * IHr i
| _, InvTy.left₂ i j => (1 + (L i - x) * invVal L R IHl IHr x j) * IHl i
| _, InvTy.right₁ i j => (1 + (L i - x) * invVal L R IHl IHr x j) * IHl i
| _, InvTy.right₂ i j => (1 + (R i - x) * invVal L R IHl IHr x j) * IHr i
@[simp]
theorem invVal_isEmpty {l r : Type u} {b} (L R IHl IHr) (i : InvTy l r b) (x) [IsEmpty l]
[IsEmpty r] : invVal L R IHl IHr x i = 0 := by
cases' i with a _ a _ a _ a
· rfl
all_goals exact isEmptyElim a
/-- The inverse of a positive surreal number `x = {L | R}` is
given by `x⁻¹ = {0,
(1 + (R - x) * x⁻¹L) * R, (1 + (L - x) * x⁻¹R) * L |
(1 + (L - x) * x⁻¹L) * L, (1 + (R - x) * x⁻¹R) * R}`.
Because the two halves `x⁻¹L, x⁻¹R` of `x⁻¹` are used in their own
definition, the sets and elements are inductively generated. -/
def inv' : PGame → PGame
| ⟨l, r, L, R⟩ =>
let l' := { i // 0 < L i }
let L' : l' → PGame := fun i => L i.1
let IHl' : l' → PGame := fun i => inv' (L i.1)
let IHr i := inv' (R i)
let x := mk l r L R
⟨InvTy l' r false, InvTy l' r true, invVal L' R IHl' IHr x, invVal L' R IHl' IHr x⟩
theorem zero_lf_inv' : ∀ x : PGame, 0 ⧏ inv' x
| ⟨xl, xr, xL, xR⟩ => by
convert lf_mk _ _ InvTy.zero
rfl
/-- `inv' 0` has exactly the same moves as `1`. -/
def inv'Zero : inv' 0 ≡r 1 := by
change mk _ _ _ _ ≡r 1
refine ⟨?_, ?_, fun i => ?_, IsEmpty.elim ?_⟩
· apply Equiv.equivPUnit (InvTy _ _ _)
· apply Equiv.equivPEmpty (InvTy _ _ _)
· -- Porting note: had to add `rfl`, because `simp` only uses the built-in `rfl`.
simp; rfl
· dsimp
infer_instance
theorem inv'_zero_equiv : inv' 0 ≈ 1 :=
inv'Zero.equiv
/-- `inv' 1` has exactly the same moves as `1`. -/
def inv'One : inv' 1 ≡r (1 : PGame.{u}) := by
change Relabelling (mk _ _ _ _) 1
have : IsEmpty { _i : PUnit.{u + 1} // (0 : PGame.{u}) < 0 } := by
rw [lt_self_iff_false]
infer_instance
refine ⟨?_, ?_, fun i => ?_, IsEmpty.elim ?_⟩ <;> dsimp
· apply Equiv.equivPUnit
· apply Equiv.equivOfIsEmpty
· -- Porting note: had to add `rfl`, because `simp` only uses the built-in `rfl`.
simp; rfl
· infer_instance
theorem inv'_one_equiv : inv' 1 ≈ 1 :=
inv'One.equiv
/-- The inverse of a pre-game in terms of the inverse on positive pre-games. -/
noncomputable instance : Inv PGame :=
⟨by classical exact fun x => if x ≈ 0 then 0 else if 0 < x then inv' x else -inv' (-x)⟩
noncomputable instance : Div PGame :=
⟨fun x y => x * y⁻¹⟩
theorem inv_eq_of_equiv_zero {x : PGame} (h : x ≈ 0) : x⁻¹ = 0 := by classical exact if_pos h
@[simp]
theorem inv_zero : (0 : PGame)⁻¹ = 0 :=
inv_eq_of_equiv_zero (equiv_refl _)
theorem inv_eq_of_pos {x : PGame} (h : 0 < x) : x⁻¹ = inv' x := by
classical exact (if_neg h.lf.not_equiv').trans (if_pos h)
theorem inv_eq_of_lf_zero {x : PGame} (h : x ⧏ 0) : x⁻¹ = -inv' (-x) := by
classical exact (if_neg h.not_equiv).trans (if_neg h.not_gt)
/-- `1⁻¹` has exactly the same moves as `1`. -/
def invOne : 1⁻¹ ≡r 1 := by
rw [inv_eq_of_pos PGame.zero_lt_one]
exact inv'One
theorem inv_one_equiv : (1⁻¹ : PGame) ≈ 1 :=
invOne.equiv
end PGame
end SetTheory
|
SetTheory\Game\Birthday.lean | /-
Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Violeta Hernández Palacios
-/
import Mathlib.SetTheory.Game.Ordinal
import Mathlib.SetTheory.Ordinal.NaturalOps
/-!
# Birthdays of games
The birthday of a game is an ordinal that represents at which "step" the game was constructed. We
define it recursively as the least ordinal larger than the birthdays of its left and right games. We
prove the basic properties about these.
# Main declarations
- `SetTheory.PGame.birthday`: The birthday of a pre-game.
# Todo
- Define the birthdays of `SetTheory.Game`s and `Surreal`s.
- Characterize the birthdays of basic arithmetical operations.
-/
universe u
open Ordinal
namespace SetTheory
open scoped NaturalOps PGame
namespace PGame
/-- The birthday of a pre-game is inductively defined as the least strict upper bound of the
birthdays of its left and right games. It may be thought as the "step" in which a certain game is
constructed. -/
noncomputable def birthday : PGame.{u} → Ordinal.{u}
| ⟨_, _, xL, xR⟩ =>
max (lsub.{u, u} fun i => birthday (xL i)) (lsub.{u, u} fun i => birthday (xR i))
theorem birthday_def (x : PGame) :
birthday x =
max (lsub.{u, u} fun i => birthday (x.moveLeft i))
(lsub.{u, u} fun i => birthday (x.moveRight i)) := by
cases x; rw [birthday]; rfl
theorem birthday_moveLeft_lt {x : PGame} (i : x.LeftMoves) :
(x.moveLeft i).birthday < x.birthday := by
cases x; rw [birthday]; exact lt_max_of_lt_left (lt_lsub _ i)
theorem birthday_moveRight_lt {x : PGame} (i : x.RightMoves) :
(x.moveRight i).birthday < x.birthday := by
cases x; rw [birthday]; exact lt_max_of_lt_right (lt_lsub _ i)
theorem lt_birthday_iff {x : PGame} {o : Ordinal} :
o < x.birthday ↔
(∃ i : x.LeftMoves, o ≤ (x.moveLeft i).birthday) ∨
∃ i : x.RightMoves, o ≤ (x.moveRight i).birthday := by
constructor
· rw [birthday_def]
intro h
cases' lt_max_iff.1 h with h' h'
· left
rwa [lt_lsub_iff] at h'
· right
rwa [lt_lsub_iff] at h'
· rintro (⟨i, hi⟩ | ⟨i, hi⟩)
· exact hi.trans_lt (birthday_moveLeft_lt i)
· exact hi.trans_lt (birthday_moveRight_lt i)
theorem Relabelling.birthday_congr : ∀ {x y : PGame.{u}}, x ≡r y → birthday x = birthday y
| ⟨xl, xr, xL, xR⟩, ⟨yl, yr, yL, yR⟩, r => by
unfold birthday
congr 1
all_goals
apply lsub_eq_of_range_eq.{u, u, u}
ext i; constructor
all_goals rintro ⟨j, rfl⟩
· exact ⟨_, (r.moveLeft j).birthday_congr.symm⟩
· exact ⟨_, (r.moveLeftSymm j).birthday_congr⟩
· exact ⟨_, (r.moveRight j).birthday_congr.symm⟩
· exact ⟨_, (r.moveRightSymm j).birthday_congr⟩
termination_by x y => (x, y)
@[simp]
theorem birthday_eq_zero {x : PGame} :
birthday x = 0 ↔ IsEmpty x.LeftMoves ∧ IsEmpty x.RightMoves := by
rw [birthday_def, max_eq_zero, lsub_eq_zero_iff, lsub_eq_zero_iff]
@[simp]
theorem birthday_zero : birthday 0 = 0 := by simp [inferInstanceAs (IsEmpty PEmpty)]
@[simp]
theorem birthday_one : birthday 1 = 1 := by rw [birthday_def]; simp
@[simp]
theorem birthday_star : birthday star = 1 := by rw [birthday_def]; simp
@[simp]
theorem neg_birthday : ∀ x : PGame, (-x).birthday = x.birthday
| ⟨xl, xr, xL, xR⟩ => by
rw [birthday_def, birthday_def, max_comm]
congr <;> funext <;> apply neg_birthday
@[simp]
theorem toPGame_birthday (o : Ordinal) : o.toPGame.birthday = o := by
induction' o using Ordinal.induction with o IH
rw [toPGame_def, PGame.birthday]
simp only [lsub_empty, max_zero_right]
-- Porting note: was `nth_rw 1 [← lsub_typein o]`
conv_rhs => rw [← lsub_typein o]
congr with x
exact IH _ (typein_lt_self x)
theorem le_birthday : ∀ x : PGame, x ≤ x.birthday.toPGame
| ⟨xl, _, xL, _⟩ =>
le_def.2
⟨fun i =>
Or.inl ⟨toLeftMovesToPGame ⟨_, birthday_moveLeft_lt i⟩, by simp [le_birthday (xL i)]⟩,
isEmptyElim⟩
variable (a b x : PGame.{u})
theorem neg_birthday_le : -x.birthday.toPGame ≤ x := by
simpa only [neg_birthday, ← neg_le_iff] using le_birthday (-x)
@[simp]
theorem birthday_add : ∀ x y : PGame.{u}, (x + y).birthday = x.birthday ♯ y.birthday
| ⟨xl, xr, xL, xR⟩, ⟨yl, yr, yL, yR⟩ => by
rw [birthday_def, nadd_def]
-- Porting note: `simp` doesn't apply
erw [lsub_sum, lsub_sum]
simp only [lsub_sum, mk_add_moveLeft_inl, moveLeft_mk, mk_add_moveLeft_inr,
mk_add_moveRight_inl, moveRight_mk, mk_add_moveRight_inr]
-- Porting note: Originally `simp only [birthday_add]`, but this causes an error in
-- `termination_by`. Use a workaround.
conv_lhs => left; left; right; intro a; rw [birthday_add (xL a) ⟨yl, yr, yL, yR⟩]
conv_lhs => left; right; right; intro b; rw [birthday_add ⟨xl, xr, xL, xR⟩ (yL b)]
conv_lhs => right; left; right; intro a; rw [birthday_add (xR a) ⟨yl, yr, yL, yR⟩]
conv_lhs => right; right; right; intro b; rw [birthday_add ⟨xl, xr, xL, xR⟩ (yR b)]
rw [max_max_max_comm]
congr <;> apply le_antisymm
any_goals
exact
max_le_iff.2
⟨lsub_le_iff.2 fun i => lt_blsub _ _ (birthday_moveLeft_lt _),
lsub_le_iff.2 fun i => lt_blsub _ _ (birthday_moveRight_lt _)⟩
all_goals
refine blsub_le_iff.2 fun i hi => ?_
rcases lt_birthday_iff.1 hi with (⟨j, hj⟩ | ⟨j, hj⟩)
· exact lt_max_of_lt_left ((nadd_le_nadd_right hj _).trans_lt (lt_lsub _ _))
· exact lt_max_of_lt_right ((nadd_le_nadd_right hj _).trans_lt (lt_lsub _ _))
· exact lt_max_of_lt_left ((nadd_le_nadd_left hj _).trans_lt (lt_lsub _ _))
· exact lt_max_of_lt_right ((nadd_le_nadd_left hj _).trans_lt (lt_lsub _ _))
termination_by a b => (a, b)
theorem birthday_add_zero : (a + 0).birthday = a.birthday := by simp
theorem birthday_zero_add : (0 + a).birthday = a.birthday := by simp
theorem birthday_add_one : (a + 1).birthday = Order.succ a.birthday := by simp
theorem birthday_one_add : (1 + a).birthday = Order.succ a.birthday := by simp
@[simp]
theorem birthday_natCast : ∀ n : ℕ, birthday n = n
| 0 => birthday_zero
| n + 1 => by simp [birthday_natCast]
@[deprecated (since := "2024-04-17")]
alias birthday_nat_cast := birthday_natCast
theorem birthday_add_nat (n : ℕ) : (a + n).birthday = a.birthday + n := by simp
theorem birthday_nat_add (n : ℕ) : (↑n + a).birthday = a.birthday + n := by simp
end PGame
end SetTheory
|
SetTheory\Game\Domineering.lean | /-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.SetTheory.Game.State
/-!
# Domineering as a combinatorial game.
We define the game of Domineering, played on a chessboard of arbitrary shape
(possibly even disconnected).
Left moves by placing a domino vertically, while Right moves by placing a domino horizontally.
This is only a fragment of a full development;
in order to successfully analyse positions we would need some more theorems.
Most importantly, we need a general statement that allows us to discard irrelevant moves.
Specifically to domineering, we need the fact that
disjoint parts of the chessboard give sums of games.
-/
namespace SetTheory
namespace PGame
namespace Domineering
open Function
/-- The equivalence `(x, y) ↦ (x, y+1)`. -/
@[simps!]
def shiftUp : ℤ × ℤ ≃ ℤ × ℤ :=
(Equiv.refl ℤ).prodCongr (Equiv.addRight (1 : ℤ))
/-- The equivalence `(x, y) ↦ (x+1, y)`. -/
@[simps!]
def shiftRight : ℤ × ℤ ≃ ℤ × ℤ :=
(Equiv.addRight (1 : ℤ)).prodCongr (Equiv.refl ℤ)
/-- A Domineering board is an arbitrary finite subset of `ℤ × ℤ`. -/
-- Porting note: reducibility cannot be `local`. For now there are no dependents of this file so
-- being globally reducible is fine.
abbrev Board :=
Finset (ℤ × ℤ)
/-- Left can play anywhere that a square and the square below it are open. -/
def left (b : Board) : Finset (ℤ × ℤ) :=
b ∩ b.map shiftUp
/-- Right can play anywhere that a square and the square to the left are open. -/
def right (b : Board) : Finset (ℤ × ℤ) :=
b ∩ b.map shiftRight
theorem mem_left {b : Board} (x : ℤ × ℤ) : x ∈ left b ↔ x ∈ b ∧ (x.1, x.2 - 1) ∈ b :=
Finset.mem_inter.trans (and_congr Iff.rfl Finset.mem_map_equiv)
theorem mem_right {b : Board} (x : ℤ × ℤ) : x ∈ right b ↔ x ∈ b ∧ (x.1 - 1, x.2) ∈ b :=
Finset.mem_inter.trans (and_congr Iff.rfl Finset.mem_map_equiv)
/-- After Left moves, two vertically adjacent squares are removed from the board. -/
def moveLeft (b : Board) (m : ℤ × ℤ) : Board :=
(b.erase m).erase (m.1, m.2 - 1)
/-- After Left moves, two horizontally adjacent squares are removed from the board. -/
def moveRight (b : Board) (m : ℤ × ℤ) : Board :=
(b.erase m).erase (m.1 - 1, m.2)
theorem fst_pred_mem_erase_of_mem_right {b : Board} {m : ℤ × ℤ} (h : m ∈ right b) :
(m.1 - 1, m.2) ∈ b.erase m := by
rw [mem_right] at h
apply Finset.mem_erase_of_ne_of_mem _ h.2
exact ne_of_apply_ne Prod.fst (pred_ne_self m.1)
theorem snd_pred_mem_erase_of_mem_left {b : Board} {m : ℤ × ℤ} (h : m ∈ left b) :
(m.1, m.2 - 1) ∈ b.erase m := by
rw [mem_left] at h
apply Finset.mem_erase_of_ne_of_mem _ h.2
exact ne_of_apply_ne Prod.snd (pred_ne_self m.2)
theorem card_of_mem_left {b : Board} {m : ℤ × ℤ} (h : m ∈ left b) : 2 ≤ Finset.card b := by
have w₁ : m ∈ b := (Finset.mem_inter.1 h).1
have w₂ : (m.1, m.2 - 1) ∈ b.erase m := snd_pred_mem_erase_of_mem_left h
have i₁ := Finset.card_erase_lt_of_mem w₁
have i₂ := Nat.lt_of_le_of_lt (Nat.zero_le _) (Finset.card_erase_lt_of_mem w₂)
exact Nat.lt_of_le_of_lt i₂ i₁
theorem card_of_mem_right {b : Board} {m : ℤ × ℤ} (h : m ∈ right b) : 2 ≤ Finset.card b := by
have w₁ : m ∈ b := (Finset.mem_inter.1 h).1
have w₂ := fst_pred_mem_erase_of_mem_right h
have i₁ := Finset.card_erase_lt_of_mem w₁
have i₂ := Nat.lt_of_le_of_lt (Nat.zero_le _) (Finset.card_erase_lt_of_mem w₂)
exact Nat.lt_of_le_of_lt i₂ i₁
theorem moveLeft_card {b : Board} {m : ℤ × ℤ} (h : m ∈ left b) :
Finset.card (moveLeft b m) + 2 = Finset.card b := by
dsimp [moveLeft]
rw [Finset.card_erase_of_mem (snd_pred_mem_erase_of_mem_left h)]
rw [Finset.card_erase_of_mem (Finset.mem_of_mem_inter_left h)]
exact tsub_add_cancel_of_le (card_of_mem_left h)
theorem moveRight_card {b : Board} {m : ℤ × ℤ} (h : m ∈ right b) :
Finset.card (moveRight b m) + 2 = Finset.card b := by
dsimp [moveRight]
rw [Finset.card_erase_of_mem (fst_pred_mem_erase_of_mem_right h)]
rw [Finset.card_erase_of_mem (Finset.mem_of_mem_inter_left h)]
exact tsub_add_cancel_of_le (card_of_mem_right h)
theorem moveLeft_smaller {b : Board} {m : ℤ × ℤ} (h : m ∈ left b) :
Finset.card (moveLeft b m) / 2 < Finset.card b / 2 := by simp [← moveLeft_card h, lt_add_one]
theorem moveRight_smaller {b : Board} {m : ℤ × ℤ} (h : m ∈ right b) :
Finset.card (moveRight b m) / 2 < Finset.card b / 2 := by simp [← moveRight_card h, lt_add_one]
/-- The instance describing allowed moves on a Domineering board. -/
instance state : State Board where
turnBound s := s.card / 2
l s := (left s).image (moveLeft s)
r s := (right s).image (moveRight s)
left_bound m := by
simp only [Finset.mem_image, Prod.exists] at m
rcases m with ⟨_, _, ⟨h, rfl⟩⟩
exact moveLeft_smaller h
right_bound m := by
simp only [Finset.mem_image, Prod.exists] at m
rcases m with ⟨_, _, ⟨h, rfl⟩⟩
exact moveRight_smaller h
end Domineering
/-- Construct a pre-game from a Domineering board. -/
def domineering (b : Domineering.Board) : PGame :=
PGame.ofState b
/-- All games of Domineering are short, because each move removes two squares. -/
instance shortDomineering (b : Domineering.Board) : Short (domineering b) := by
dsimp [domineering]
infer_instance
/-- The Domineering board with two squares arranged vertically, in which Left has the only move. -/
def domineering.one :=
domineering [(0, 0), (0, 1)].toFinset
/-- The `L` shaped Domineering board, in which Left is exactly half a move ahead. -/
def domineering.L :=
domineering [(0, 2), (0, 1), (0, 0), (1, 0)].toFinset
instance shortOne : Short domineering.one := by dsimp [domineering.one]; infer_instance
instance shortL : Short domineering.L := by dsimp [domineering.L]; infer_instance
-- The VM can play small games successfully:
-- #eval decide (domineering.one ≈ 1)
-- #eval decide (domineering.L + domineering.L ≈ 1)
-- The following no longer works since Lean 3.29, since definitions by well-founded
-- recursion no longer reduce definitionally.
-- We can check that `Decidable` instances reduce as expected,
-- and so our implementation of domineering is computable.
-- run_cmd tactic.whnf `(by apply_instance : Decidable (domineering.one ≤ 1)) >>= tactic.trace
-- dec_trivial can handle most of the dictionary of small games described in [conway2001]
-- example : domineering.one ≈ 1 := by decide
-- example : domineering.L + domineering.L ≈ 1 := by decide
-- example : domineering.L ≈ PGame.ofLists [0] [1] := by decide
-- example : (domineering ([(0,0), (0,1), (0,2), (0,3)].toFinset) ≈ 2) := by decide
-- example : (domineering ([(0,0), (0,1), (1,0), (1,1)].toFinset) ≈ PGame.ofLists [1] [-1]) :=
-- by decide
-- The 3x3 grid is doable, but takes a minute...
-- example :
-- (domineering ([(0,0), (0,1), (0,2), (1,0), (1,1), (1,2), (2,0), (2,1), (2,2)].toFinset) ≈
-- PGame.ofLists [1] [-1]) := by decide
-- The 5x5 grid is actually 0, but brute-forcing this is too challenging even for the VM.
-- #eval decide (domineering ([
-- (0,0), (0,1), (0,2), (0,3), (0,4),
-- (1,0), (1,1), (1,2), (1,3), (1,4),
-- (2,0), (2,1), (2,2), (2,3), (2,4),
-- (3,0), (3,1), (3,2), (3,3), (3,4),
-- (4,0), (4,1), (4,2), (4,3), (4,4)
-- ].toFinset) ≈ 0)
end PGame
end SetTheory
|
SetTheory\Game\Impartial.lean | /-
Copyright (c) 2020 Fox Thomson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Fox Thomson
-/
import Mathlib.SetTheory.Game.Basic
import Mathlib.Tactic.NthRewrite
/-!
# Basic definitions about impartial (pre-)games
We will define an impartial game, one in which left and right can make exactly the same moves.
Our definition differs slightly by saying that the game is always equivalent to its negative,
no matter what moves are played. This allows for games such as poker-nim to be classified as
impartial.
-/
universe u
namespace SetTheory
open scoped PGame
namespace PGame
/-- The definition for an impartial game, defined using Conway induction. -/
def ImpartialAux : PGame → Prop
| G => (G ≈ -G) ∧ (∀ i, ImpartialAux (G.moveLeft i)) ∧ ∀ j, ImpartialAux (G.moveRight j)
termination_by G => G -- Porting note: Added `termination_by`
theorem impartialAux_def {G : PGame} :
G.ImpartialAux ↔
(G ≈ -G) ∧ (∀ i, ImpartialAux (G.moveLeft i)) ∧ ∀ j, ImpartialAux (G.moveRight j) := by
rw [ImpartialAux]
/-- A typeclass on impartial games. -/
class Impartial (G : PGame) : Prop where
out : ImpartialAux G
theorem impartial_iff_aux {G : PGame} : G.Impartial ↔ G.ImpartialAux :=
⟨fun h => h.1, fun h => ⟨h⟩⟩
theorem impartial_def {G : PGame} :
G.Impartial ↔ (G ≈ -G) ∧ (∀ i, Impartial (G.moveLeft i)) ∧ ∀ j, Impartial (G.moveRight j) := by
simpa only [impartial_iff_aux] using impartialAux_def
namespace Impartial
instance impartial_zero : Impartial 0 := by rw [impartial_def]; dsimp; simp
instance impartial_star : Impartial star := by
rw [impartial_def]; simpa using Impartial.impartial_zero
theorem neg_equiv_self (G : PGame) [h : G.Impartial] : G ≈ -G :=
(impartial_def.1 h).1
-- Porting note: Changed `-⟦G⟧` to `-(⟦G⟧ : Quotient setoid)`
@[simp]
theorem mk'_neg_equiv_self (G : PGame) [G.Impartial] : -(⟦G⟧ : Quotient setoid) = ⟦G⟧ :=
Quot.sound (Equiv.symm (neg_equiv_self G))
instance moveLeft_impartial {G : PGame} [h : G.Impartial] (i : G.LeftMoves) :
(G.moveLeft i).Impartial :=
(impartial_def.1 h).2.1 i
instance moveRight_impartial {G : PGame} [h : G.Impartial] (j : G.RightMoves) :
(G.moveRight j).Impartial :=
(impartial_def.1 h).2.2 j
theorem impartial_congr : ∀ {G H : PGame} (_ : G ≡r H) [G.Impartial], H.Impartial
| G, H => fun e => by
intro h
exact impartial_def.2
⟨Equiv.trans e.symm.equiv (Equiv.trans (neg_equiv_self G) (neg_equiv_neg_iff.2 e.equiv)),
fun i => impartial_congr (e.moveLeftSymm i), fun j => impartial_congr (e.moveRightSymm j)⟩
termination_by G H => (G, H)
instance impartial_add : ∀ (G H : PGame) [G.Impartial] [H.Impartial], (G + H).Impartial
| G, H, _, _ => by
rw [impartial_def]
refine ⟨Equiv.trans (add_congr (neg_equiv_self G) (neg_equiv_self _))
(Equiv.symm (negAddRelabelling _ _).equiv), fun k => ?_, fun k => ?_⟩
· apply leftMoves_add_cases k
all_goals
intro i; simp only [add_moveLeft_inl, add_moveLeft_inr]
apply impartial_add
· apply rightMoves_add_cases k
all_goals
intro i; simp only [add_moveRight_inl, add_moveRight_inr]
apply impartial_add
termination_by G H => (G, H)
instance impartial_neg : ∀ (G : PGame) [G.Impartial], (-G).Impartial
| G, _ => by
rw [impartial_def]
refine ⟨?_, fun i => ?_, fun i => ?_⟩
· rw [neg_neg]
exact Equiv.symm (neg_equiv_self G)
· rw [moveLeft_neg']
apply impartial_neg
· rw [moveRight_neg']
apply impartial_neg
termination_by G => G
variable (G : PGame) [Impartial G]
theorem nonpos : ¬0 < G := fun h => by
have h' := neg_lt_neg_iff.2 h
rw [neg_zero, lt_congr_left (Equiv.symm (neg_equiv_self G))] at h'
exact (h.trans h').false
theorem nonneg : ¬G < 0 := fun h => by
have h' := neg_lt_neg_iff.2 h
rw [neg_zero, lt_congr_right (Equiv.symm (neg_equiv_self G))] at h'
exact (h.trans h').false
/-- In an impartial game, either the first player always wins, or the second player always wins. -/
theorem equiv_or_fuzzy_zero : (G ≈ 0) ∨ G ‖ 0 := by
rcases lt_or_equiv_or_gt_or_fuzzy G 0 with (h | h | h | h)
· exact ((nonneg G) h).elim
· exact Or.inl h
· exact ((nonpos G) h).elim
· exact Or.inr h
@[simp]
theorem not_equiv_zero_iff : ¬(G ≈ 0) ↔ G ‖ 0 :=
⟨(equiv_or_fuzzy_zero G).resolve_left, Fuzzy.not_equiv⟩
@[simp]
theorem not_fuzzy_zero_iff : ¬G ‖ 0 ↔ (G ≈ 0) :=
⟨(equiv_or_fuzzy_zero G).resolve_right, Equiv.not_fuzzy⟩
theorem add_self : G + G ≈ 0 :=
Equiv.trans (add_congr_left (neg_equiv_self G)) (add_left_neg_equiv G)
-- Porting note: Changed `⟦G⟧` to `(⟦G⟧ : Quotient setoid)`
@[simp]
theorem mk'_add_self : (⟦G⟧ : Quotient setoid) + ⟦G⟧ = 0 :=
Quot.sound (add_self G)
/-- This lemma doesn't require `H` to be impartial. -/
theorem equiv_iff_add_equiv_zero (H : PGame) : (H ≈ G) ↔ (H + G ≈ 0) := by
rw [Game.PGame.equiv_iff_game_eq, ← @add_right_cancel_iff _ _ _ ⟦G⟧, mk'_add_self, ← quot_add,
Game.PGame.equiv_iff_game_eq]
rfl
/-- This lemma doesn't require `H` to be impartial. -/
theorem equiv_iff_add_equiv_zero' (H : PGame) : (G ≈ H) ↔ (G + H ≈ 0) := by
rw [Game.PGame.equiv_iff_game_eq, ← @add_left_cancel_iff _ _ _ ⟦G⟧, mk'_add_self, ← quot_add,
Game.PGame.equiv_iff_game_eq]
exact ⟨Eq.symm, Eq.symm⟩
theorem le_zero_iff {G : PGame} [G.Impartial] : G ≤ 0 ↔ 0 ≤ G := by
rw [← zero_le_neg_iff, le_congr_right (neg_equiv_self G)]
theorem lf_zero_iff {G : PGame} [G.Impartial] : G ⧏ 0 ↔ 0 ⧏ G := by
rw [← zero_lf_neg_iff, lf_congr_right (neg_equiv_self G)]
theorem equiv_zero_iff_le : (G ≈ 0) ↔ G ≤ 0 :=
⟨And.left, fun h => ⟨h, le_zero_iff.1 h⟩⟩
theorem fuzzy_zero_iff_lf : G ‖ 0 ↔ G ⧏ 0 :=
⟨And.left, fun h => ⟨h, lf_zero_iff.1 h⟩⟩
theorem equiv_zero_iff_ge : (G ≈ 0) ↔ 0 ≤ G :=
⟨And.right, fun h => ⟨le_zero_iff.2 h, h⟩⟩
theorem fuzzy_zero_iff_gf : G ‖ 0 ↔ 0 ⧏ G :=
⟨And.right, fun h => ⟨lf_zero_iff.2 h, h⟩⟩
theorem forall_leftMoves_fuzzy_iff_equiv_zero : (∀ i, G.moveLeft i ‖ 0) ↔ (G ≈ 0) := by
refine ⟨fun hb => ?_, fun hp i => ?_⟩
· rw [equiv_zero_iff_le G, le_zero_lf]
exact fun i => (hb i).1
· rw [fuzzy_zero_iff_lf]
exact hp.1.moveLeft_lf i
theorem forall_rightMoves_fuzzy_iff_equiv_zero : (∀ j, G.moveRight j ‖ 0) ↔ (G ≈ 0) := by
refine ⟨fun hb => ?_, fun hp i => ?_⟩
· rw [equiv_zero_iff_ge G, zero_le_lf]
exact fun i => (hb i).2
· rw [fuzzy_zero_iff_gf]
exact hp.2.lf_moveRight i
theorem exists_left_move_equiv_iff_fuzzy_zero : (∃ i, G.moveLeft i ≈ 0) ↔ G ‖ 0 := by
refine ⟨fun ⟨i, hi⟩ => (fuzzy_zero_iff_gf G).2 (lf_of_le_moveLeft hi.2), fun hn => ?_⟩
rw [fuzzy_zero_iff_gf G, zero_lf_le] at hn
cases' hn with i hi
exact ⟨i, (equiv_zero_iff_ge _).2 hi⟩
theorem exists_right_move_equiv_iff_fuzzy_zero : (∃ j, G.moveRight j ≈ 0) ↔ G ‖ 0 := by
refine ⟨fun ⟨i, hi⟩ => (fuzzy_zero_iff_lf G).2 (lf_of_moveRight_le hi.1), fun hn => ?_⟩
rw [fuzzy_zero_iff_lf G, lf_zero_le] at hn
cases' hn with i hi
exact ⟨i, (equiv_zero_iff_le _).2 hi⟩
end Impartial
end PGame
end SetTheory
|
SetTheory\Game\Nim.lean | /-
Copyright (c) 2020 Fox Thomson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Fox Thomson, Markus Himmel
-/
import Mathlib.Data.Nat.Bitwise
import Mathlib.SetTheory.Game.Birthday
import Mathlib.SetTheory.Game.Impartial
/-!
# Nim and the Sprague-Grundy theorem
This file contains the definition for nim for any ordinal `o`. In the game of `nim o₁` both players
may move to `nim o₂` for any `o₂ < o₁`.
We also define a Grundy value for an impartial game `G` and prove the Sprague-Grundy theorem, that
`G` is equivalent to `nim (grundyValue G)`.
Finally, we compute the sum of finite Grundy numbers: if `G` and `H` have Grundy values `n` and `m`,
where `n` and `m` are natural numbers, then `G + H` has the Grundy value `n xor m`.
## Implementation details
The pen-and-paper definition of nim defines the possible moves of `nim o` to be `Set.Iio o`.
However, this definition does not work for us because it would make the type of nim
`Ordinal.{u} → SetTheory.PGame.{u + 1}`, which would make it impossible for us to state the
Sprague-Grundy theorem, since that requires the type of `nim` to be
`Ordinal.{u} → SetTheory.PGame.{u}`. For this reason, we
instead use `o.out.α` for the possible moves. You can use `to_left_moves_nim` and
`to_right_moves_nim` to convert an ordinal less than `o` into a left or right move of `nim o`, and
vice versa.
-/
noncomputable section
universe u
namespace SetTheory
open scoped PGame
namespace PGame
-- Uses `noncomputable!` to avoid `rec_fn_macro only allowed in meta definitions` VM error
/-- The definition of single-heap nim, which can be viewed as a pile of stones where each player can
take a positive number of stones from it on their turn. -/
noncomputable def nim : Ordinal.{u} → PGame.{u}
| o₁ =>
let f o₂ :=
have _ : Ordinal.typein o₁.out.r o₂ < o₁ := Ordinal.typein_lt_self o₂
nim (Ordinal.typein o₁.out.r o₂)
⟨o₁.out.α, o₁.out.α, f, f⟩
termination_by o => o
open Ordinal
theorem nim_def (o : Ordinal) :
have : IsWellOrder (Quotient.out o).α (· < ·) := inferInstance
nim o =
PGame.mk o.out.α o.out.α (fun o₂ => nim (Ordinal.typein (· < ·) o₂)) fun o₂ =>
nim (Ordinal.typein (· < ·) o₂) := by
rw [nim]; rfl
theorem leftMoves_nim (o : Ordinal) : (nim o).LeftMoves = o.out.α := by rw [nim_def]; rfl
theorem rightMoves_nim (o : Ordinal) : (nim o).RightMoves = o.out.α := by rw [nim_def]; rfl
theorem moveLeft_nim_hEq (o : Ordinal) :
have : IsWellOrder (Quotient.out o).α (· < ·) := inferInstance
HEq (nim o).moveLeft fun i : o.out.α => nim (typein (· < ·) i) := by rw [nim_def]; rfl
theorem moveRight_nim_hEq (o : Ordinal) :
have : IsWellOrder (Quotient.out o).α (· < ·) := inferInstance
HEq (nim o).moveRight fun i : o.out.α => nim (typein (· < ·) i) := by rw [nim_def]; rfl
/-- Turns an ordinal less than `o` into a left move for `nim o` and viceversa. -/
noncomputable def toLeftMovesNim {o : Ordinal} : Set.Iio o ≃ (nim o).LeftMoves :=
(enumIsoOut o).toEquiv.trans (Equiv.cast (leftMoves_nim o).symm)
/-- Turns an ordinal less than `o` into a right move for `nim o` and viceversa. -/
noncomputable def toRightMovesNim {o : Ordinal} : Set.Iio o ≃ (nim o).RightMoves :=
(enumIsoOut o).toEquiv.trans (Equiv.cast (rightMoves_nim o).symm)
@[simp]
theorem toLeftMovesNim_symm_lt {o : Ordinal} (i : (nim o).LeftMoves) :
↑(toLeftMovesNim.symm i) < o :=
(toLeftMovesNim.symm i).prop
@[simp]
theorem toRightMovesNim_symm_lt {o : Ordinal} (i : (nim o).RightMoves) :
↑(toRightMovesNim.symm i) < o :=
(toRightMovesNim.symm i).prop
@[simp]
theorem moveLeft_nim' {o : Ordinal.{u}} (i) :
(nim o).moveLeft i = nim (toLeftMovesNim.symm i).val :=
(congr_heq (moveLeft_nim_hEq o).symm (cast_heq _ i)).symm
theorem moveLeft_nim {o : Ordinal} (i) : (nim o).moveLeft (toLeftMovesNim i) = nim i := by simp
@[simp]
theorem moveRight_nim' {o : Ordinal} (i) : (nim o).moveRight i = nim (toRightMovesNim.symm i).val :=
(congr_heq (moveRight_nim_hEq o).symm (cast_heq _ i)).symm
theorem moveRight_nim {o : Ordinal} (i) : (nim o).moveRight (toRightMovesNim i) = nim i := by simp
/-- A recursion principle for left moves of a nim game. -/
@[elab_as_elim]
def leftMovesNimRecOn {o : Ordinal} {P : (nim o).LeftMoves → Sort*} (i : (nim o).LeftMoves)
(H : ∀ a (H : a < o), P <| toLeftMovesNim ⟨a, H⟩) : P i := by
rw [← toLeftMovesNim.apply_symm_apply i]; apply H
/-- A recursion principle for right moves of a nim game. -/
@[elab_as_elim]
def rightMovesNimRecOn {o : Ordinal} {P : (nim o).RightMoves → Sort*} (i : (nim o).RightMoves)
(H : ∀ a (H : a < o), P <| toRightMovesNim ⟨a, H⟩) : P i := by
rw [← toRightMovesNim.apply_symm_apply i]; apply H
instance isEmpty_nim_zero_leftMoves : IsEmpty (nim 0).LeftMoves := by
rw [nim_def]
exact Ordinal.isEmpty_out_zero
instance isEmpty_nim_zero_rightMoves : IsEmpty (nim 0).RightMoves := by
rw [nim_def]
exact Ordinal.isEmpty_out_zero
/-- `nim 0` has exactly the same moves as `0`. -/
def nimZeroRelabelling : nim 0 ≡r 0 :=
Relabelling.isEmpty _
theorem nim_zero_equiv : nim 0 ≈ 0 :=
Equiv.isEmpty _
noncomputable instance uniqueNimOneLeftMoves : Unique (nim 1).LeftMoves :=
(Equiv.cast <| leftMoves_nim 1).unique
noncomputable instance uniqueNimOneRightMoves : Unique (nim 1).RightMoves :=
(Equiv.cast <| rightMoves_nim 1).unique
@[simp]
theorem default_nim_one_leftMoves_eq :
(default : (nim 1).LeftMoves) = @toLeftMovesNim 1 ⟨0, Set.mem_Iio.mpr zero_lt_one⟩ :=
rfl
@[simp]
theorem default_nim_one_rightMoves_eq :
(default : (nim 1).RightMoves) = @toRightMovesNim 1 ⟨0, Set.mem_Iio.mpr zero_lt_one⟩ :=
rfl
@[simp]
theorem toLeftMovesNim_one_symm (i) :
(@toLeftMovesNim 1).symm i = ⟨0, Set.mem_Iio.mpr zero_lt_one⟩ := by
simp [eq_iff_true_of_subsingleton]
@[simp]
theorem toRightMovesNim_one_symm (i) :
(@toRightMovesNim 1).symm i = ⟨0, Set.mem_Iio.mpr zero_lt_one⟩ := by
simp [eq_iff_true_of_subsingleton]
theorem nim_one_moveLeft (x) : (nim 1).moveLeft x = nim 0 := by simp
theorem nim_one_moveRight (x) : (nim 1).moveRight x = nim 0 := by simp
/-- `nim 1` has exactly the same moves as `star`. -/
def nimOneRelabelling : nim 1 ≡r star := by
rw [nim_def]
refine ⟨?_, ?_, fun i => ?_, fun j => ?_⟩
any_goals dsimp; apply Equiv.equivOfUnique
all_goals simpa using nimZeroRelabelling
theorem nim_one_equiv : nim 1 ≈ star :=
nimOneRelabelling.equiv
@[simp]
theorem nim_birthday (o : Ordinal) : (nim o).birthday = o := by
induction' o using Ordinal.induction with o IH
rw [nim_def, birthday_def]
dsimp
rw [max_eq_right le_rfl]
convert lsub_typein o with i
exact IH _ (typein_lt_self i)
@[simp]
theorem neg_nim (o : Ordinal) : -nim o = nim o := by
induction' o using Ordinal.induction with o IH
rw [nim_def]; dsimp; congr <;> funext i <;> exact IH _ (Ordinal.typein_lt_self i)
instance nim_impartial (o : Ordinal) : Impartial (nim o) := by
induction' o using Ordinal.induction with o IH
rw [impartial_def, neg_nim]
refine ⟨equiv_rfl, fun i => ?_, fun i => ?_⟩ <;> simpa using IH _ (typein_lt_self _)
theorem nim_fuzzy_zero_of_ne_zero {o : Ordinal} (ho : o ≠ 0) : nim o ‖ 0 := by
rw [Impartial.fuzzy_zero_iff_lf, nim_def, lf_zero_le]
rw [← Ordinal.pos_iff_ne_zero] at ho
exact ⟨(Ordinal.principalSegOut ho).top, by simp⟩
@[simp]
theorem nim_add_equiv_zero_iff (o₁ o₂ : Ordinal) : (nim o₁ + nim o₂ ≈ 0) ↔ o₁ = o₂ := by
constructor
· refine not_imp_not.1 fun hne : _ ≠ _ => (Impartial.not_equiv_zero_iff (nim o₁ + nim o₂)).2 ?_
wlog h : o₁ < o₂
· exact (fuzzy_congr_left add_comm_equiv).1 (this _ _ hne.symm (hne.lt_or_lt.resolve_left h))
rw [Impartial.fuzzy_zero_iff_gf, zero_lf_le, nim_def o₂]
refine ⟨toLeftMovesAdd (Sum.inr ?_), ?_⟩
· exact (Ordinal.principalSegOut h).top
· -- Porting note: squeezed simp
simpa only [Ordinal.typein_top, Ordinal.type_lt, PGame.add_moveLeft_inr, PGame.moveLeft_mk]
using (Impartial.add_self (nim o₁)).2
· rintro rfl
exact Impartial.add_self (nim o₁)
@[simp]
theorem nim_add_fuzzy_zero_iff {o₁ o₂ : Ordinal} : nim o₁ + nim o₂ ‖ 0 ↔ o₁ ≠ o₂ := by
rw [iff_not_comm, Impartial.not_fuzzy_zero_iff, nim_add_equiv_zero_iff]
@[simp]
theorem nim_equiv_iff_eq {o₁ o₂ : Ordinal} : (nim o₁ ≈ nim o₂) ↔ o₁ = o₂ := by
rw [Impartial.equiv_iff_add_equiv_zero, nim_add_equiv_zero_iff]
/-- The Grundy value of an impartial game, the ordinal which corresponds to the game of nim that the
game is equivalent to -/
noncomputable def grundyValue : PGame.{u} → Ordinal.{u}
| G => Ordinal.mex.{u, u} fun i => grundyValue (G.moveLeft i)
termination_by G => G
theorem grundyValue_eq_mex_left (G : PGame) :
grundyValue G = Ordinal.mex.{u, u} fun i => grundyValue (G.moveLeft i) := by rw [grundyValue]
/-- The Sprague-Grundy theorem which states that every impartial game is equivalent to a game of
nim, namely the game of nim corresponding to the games Grundy value -/
theorem equiv_nim_grundyValue : ∀ (G : PGame.{u}) [G.Impartial], G ≈ nim (grundyValue G)
| G => by
rw [Impartial.equiv_iff_add_equiv_zero, ← Impartial.forall_leftMoves_fuzzy_iff_equiv_zero]
intro i
apply leftMoves_add_cases i
· intro i₁
rw [add_moveLeft_inl]
apply
(fuzzy_congr_left (add_congr_left (Equiv.symm (equiv_nim_grundyValue (G.moveLeft i₁))))).1
rw [nim_add_fuzzy_zero_iff]
intro heq
rw [eq_comm, grundyValue_eq_mex_left G] at heq
-- Porting note: added universe annotation, argument
have h := Ordinal.ne_mex.{u, u} (fun i ↦ grundyValue (moveLeft G i))
rw [heq] at h
exact (h i₁).irrefl
· intro i₂
rw [add_moveLeft_inr, ← Impartial.exists_left_move_equiv_iff_fuzzy_zero]
revert i₂
rw [nim_def]
intro i₂
have h' :
∃ i : G.LeftMoves,
grundyValue (G.moveLeft i) = Ordinal.typein (Quotient.out (grundyValue G)).r i₂ := by
revert i₂
rw [grundyValue_eq_mex_left]
intro i₂
have hnotin : _ ∉ _ := fun hin =>
(le_not_le_of_lt (Ordinal.typein_lt_self i₂)).2 (csInf_le' hin)
simpa using hnotin
cases' h' with i hi
use toLeftMovesAdd (Sum.inl i)
rw [add_moveLeft_inl, moveLeft_mk]
apply Equiv.trans (add_congr_left (equiv_nim_grundyValue (G.moveLeft i)))
simpa only [hi] using Impartial.add_self (nim (grundyValue (G.moveLeft i)))
termination_by G => G
decreasing_by all_goals pgame_wf_tac
theorem grundyValue_eq_iff_equiv_nim {G : PGame} [G.Impartial] {o : Ordinal} :
grundyValue G = o ↔ (G ≈ nim o) :=
⟨by rintro rfl; exact equiv_nim_grundyValue G,
by intro h; rw [← nim_equiv_iff_eq]; exact Equiv.trans (Equiv.symm (equiv_nim_grundyValue G)) h⟩
@[simp]
theorem nim_grundyValue (o : Ordinal.{u}) : grundyValue (nim o) = o :=
grundyValue_eq_iff_equiv_nim.2 PGame.equiv_rfl
theorem grundyValue_eq_iff_equiv (G H : PGame) [G.Impartial] [H.Impartial] :
grundyValue G = grundyValue H ↔ (G ≈ H) :=
grundyValue_eq_iff_equiv_nim.trans (equiv_congr_left.1 (equiv_nim_grundyValue H) _).symm
@[simp]
theorem grundyValue_zero : grundyValue 0 = 0 :=
grundyValue_eq_iff_equiv_nim.2 (Equiv.symm nim_zero_equiv)
theorem grundyValue_iff_equiv_zero (G : PGame) [G.Impartial] : grundyValue G = 0 ↔ (G ≈ 0) := by
rw [← grundyValue_eq_iff_equiv, grundyValue_zero]
@[simp]
theorem grundyValue_star : grundyValue star = 1 :=
grundyValue_eq_iff_equiv_nim.2 (Equiv.symm nim_one_equiv)
@[simp]
theorem grundyValue_neg (G : PGame) [G.Impartial] : grundyValue (-G) = grundyValue G := by
rw [grundyValue_eq_iff_equiv_nim, neg_equiv_iff, neg_nim, ← grundyValue_eq_iff_equiv_nim]
theorem grundyValue_eq_mex_right :
∀ (G : PGame) [G.Impartial],
grundyValue G = Ordinal.mex.{u, u} fun i => grundyValue (G.moveRight i)
| ⟨l, r, L, R⟩, _ => by
rw [← grundyValue_neg, grundyValue_eq_mex_left]
congr
ext i
haveI : (R i).Impartial := @Impartial.moveRight_impartial ⟨l, r, L, R⟩ _ i
apply grundyValue_neg
-- Todo: this actually generalizes to all ordinals, by defining `Ordinal.lxor` as the pairwise
-- `Nat.xor` of base `ω` Cantor normal forms.
/-- The Grundy value of the sum of two nim games with natural numbers of piles equals their bitwise
xor. -/
@[simp]
theorem grundyValue_nim_add_nim (n m : ℕ) :
grundyValue (nim.{u} n + nim.{u} m) = n ^^^ m := by
-- We do strong induction on both variables.
induction' n using Nat.strong_induction_on with n hn generalizing m
induction' m using Nat.strong_induction_on with m hm
rw [grundyValue_eq_mex_left]
refine (Ordinal.mex_le_of_ne.{u, u} fun i => ?_).antisymm
(Ordinal.le_mex_of_forall fun ou hu => ?_)
-- The Grundy value `n ^^^ m` can't be reached by left moves.
· apply leftMoves_add_cases i <;>
· -- A left move leaves us with a Grundy value of `k ^^^ m` for `k < n`, or
-- `n ^^^ k` for `k < m`.
refine fun a => leftMovesNimRecOn a fun ok hk => ?_
obtain ⟨k, rfl⟩ := Ordinal.lt_omega.1 (hk.trans (Ordinal.nat_lt_omega _))
simp only [add_moveLeft_inl, add_moveLeft_inr, moveLeft_nim', Equiv.symm_apply_apply]
-- The inequality follows from injectivity.
rw [natCast_lt] at hk
first
| rw [hn _ hk]
| rw [hm _ hk]
refine fun h => hk.ne ?_
rw [Ordinal.natCast_inj] at h
first
| rwa [Nat.xor_left_inj] at h
| rwa [Nat.xor_right_inj] at h
-- Every other smaller Grundy value can be reached by left moves.
· -- If `u < m ^^^ n`, then either `u ^^^ n < m` or `u ^^^ m < n`.
obtain ⟨u, rfl⟩ := Ordinal.lt_omega.1 (hu.trans (Ordinal.nat_lt_omega _))
replace hu := Ordinal.natCast_lt.1 hu
cases' Nat.lt_xor_cases hu with h h
-- In the first case, reducing the `m` pile to `u ^^^ n` gives the desired Grundy value.
· refine ⟨toLeftMovesAdd (Sum.inl <| toLeftMovesNim ⟨_, Ordinal.natCast_lt.2 h⟩), ?_⟩
simp [Nat.xor_cancel_right, hn _ h]
-- In the second case, reducing the `n` pile to `u ^^^ m` gives the desired Grundy value.
· refine ⟨toLeftMovesAdd (Sum.inr <| toLeftMovesNim ⟨_, Ordinal.natCast_lt.2 h⟩), ?_⟩
have : n ^^^ (u ^^^ n) = u := by rw [Nat.xor_comm u, Nat.xor_cancel_left]
simpa [hm _ h] using this
theorem nim_add_nim_equiv {n m : ℕ} : nim n + nim m ≈ nim (n ^^^ m) := by
rw [← grundyValue_eq_iff_equiv_nim, grundyValue_nim_add_nim]
theorem grundyValue_add (G H : PGame) [G.Impartial] [H.Impartial] {n m : ℕ} (hG : grundyValue G = n)
(hH : grundyValue H = m) : grundyValue (G + H) = n ^^^ m := by
rw [← nim_grundyValue (n ^^^ m), grundyValue_eq_iff_equiv]
refine Equiv.trans ?_ nim_add_nim_equiv
convert add_congr (equiv_nim_grundyValue G) (equiv_nim_grundyValue H) <;> simp only [hG, hH]
end PGame
end SetTheory
|
SetTheory\Game\Ordinal.lean | /-
Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Violeta Hernández Palacios
-/
import Mathlib.SetTheory.Game.Basic
import Mathlib.SetTheory.Ordinal.NaturalOps
/-!
# Ordinals as games
We define the canonical map `Ordinal → SetTheory.PGame`, where every ordinal is mapped to the
game whose left set consists of all previous ordinals.
The map to surreals is defined in `Ordinal.toSurreal`.
# Main declarations
- `Ordinal.toPGame`: The canonical map between ordinals and pre-games.
- `Ordinal.toPGameEmbedding`: The order embedding version of the previous map.
-/
universe u
open SetTheory PGame
open scoped NaturalOps PGame
namespace Ordinal
/-- Converts an ordinal into the corresponding pre-game. -/
noncomputable def toPGame : Ordinal.{u} → PGame.{u}
| o =>
have : IsWellOrder o.out.α (· < ·) := isWellOrder_out_lt o
⟨o.out.α, PEmpty, fun x =>
have := Ordinal.typein_lt_self x
(typein (· < ·) x).toPGame,
PEmpty.elim⟩
termination_by x => x
@[nolint unusedHavesSuffices]
theorem toPGame_def (o : Ordinal) :
have : IsWellOrder o.out.α (· < ·) := isWellOrder_out_lt o
o.toPGame = ⟨o.out.α, PEmpty, fun x => (typein (· < ·) x).toPGame, PEmpty.elim⟩ := by
rw [toPGame]
@[simp, nolint unusedHavesSuffices]
theorem toPGame_leftMoves (o : Ordinal) : o.toPGame.LeftMoves = o.out.α := by
rw [toPGame, LeftMoves]
@[simp, nolint unusedHavesSuffices]
theorem toPGame_rightMoves (o : Ordinal) : o.toPGame.RightMoves = PEmpty := by
rw [toPGame, RightMoves]
instance isEmpty_zero_toPGame_leftMoves : IsEmpty (toPGame 0).LeftMoves := by
rw [toPGame_leftMoves]; infer_instance
instance isEmpty_toPGame_rightMoves (o : Ordinal) : IsEmpty o.toPGame.RightMoves := by
rw [toPGame_rightMoves]; infer_instance
/-- Converts an ordinal less than `o` into a move for the `PGame` corresponding to `o`, and vice
versa. -/
noncomputable def toLeftMovesToPGame {o : Ordinal} : Set.Iio o ≃ o.toPGame.LeftMoves :=
(enumIsoOut o).toEquiv.trans (Equiv.cast (toPGame_leftMoves o).symm)
@[simp]
theorem toLeftMovesToPGame_symm_lt {o : Ordinal} (i : o.toPGame.LeftMoves) :
↑(toLeftMovesToPGame.symm i) < o :=
(toLeftMovesToPGame.symm i).prop
@[nolint unusedHavesSuffices]
theorem toPGame_moveLeft_hEq {o : Ordinal} :
have : IsWellOrder o.out.α (· < ·) := isWellOrder_out_lt o
HEq o.toPGame.moveLeft fun x : o.out.α => (typein (· < ·) x).toPGame := by
rw [toPGame]
rfl
@[simp]
theorem toPGame_moveLeft' {o : Ordinal} (i) :
o.toPGame.moveLeft i = (toLeftMovesToPGame.symm i).val.toPGame :=
(congr_heq toPGame_moveLeft_hEq.symm (cast_heq _ i)).symm
theorem toPGame_moveLeft {o : Ordinal} (i) :
o.toPGame.moveLeft (toLeftMovesToPGame i) = i.val.toPGame := by simp
/-- `0.toPGame` has the same moves as `0`. -/
noncomputable def zeroToPGameRelabelling : toPGame 0 ≡r 0 :=
Relabelling.isEmpty _
noncomputable instance uniqueOneToPGameLeftMoves : Unique (toPGame 1).LeftMoves :=
(Equiv.cast <| toPGame_leftMoves 1).unique
@[simp]
theorem one_toPGame_leftMoves_default_eq :
(default : (toPGame 1).LeftMoves) = @toLeftMovesToPGame 1 ⟨0, Set.mem_Iio.mpr zero_lt_one⟩ :=
rfl
@[simp]
theorem to_leftMoves_one_toPGame_symm (i) :
(@toLeftMovesToPGame 1).symm i = ⟨0, Set.mem_Iio.mpr zero_lt_one⟩ := by
simp [eq_iff_true_of_subsingleton]
theorem one_toPGame_moveLeft (x) : (toPGame 1).moveLeft x = toPGame 0 := by simp
/-- `1.toPGame` has the same moves as `1`. -/
noncomputable def oneToPGameRelabelling : toPGame 1 ≡r 1 :=
⟨Equiv.equivOfUnique _ _, Equiv.equivOfIsEmpty _ _, fun i => by
simpa using zeroToPGameRelabelling, isEmptyElim⟩
theorem toPGame_lf {a b : Ordinal} (h : a < b) : a.toPGame ⧏ b.toPGame := by
convert moveLeft_lf (toLeftMovesToPGame ⟨a, h⟩); rw [toPGame_moveLeft]
theorem toPGame_le {a b : Ordinal} (h : a ≤ b) : a.toPGame ≤ b.toPGame := by
refine le_iff_forall_lf.2 ⟨fun i => ?_, isEmptyElim⟩
rw [toPGame_moveLeft']
exact toPGame_lf ((toLeftMovesToPGame_symm_lt i).trans_le h)
theorem toPGame_lt {a b : Ordinal} (h : a < b) : a.toPGame < b.toPGame :=
⟨toPGame_le h.le, toPGame_lf h⟩
theorem toPGame_nonneg (a : Ordinal) : 0 ≤ a.toPGame :=
zeroToPGameRelabelling.ge.trans <| toPGame_le <| Ordinal.zero_le a
@[simp]
theorem toPGame_lf_iff {a b : Ordinal} : a.toPGame ⧏ b.toPGame ↔ a < b :=
⟨by contrapose; rw [not_lt, not_lf]; exact toPGame_le, toPGame_lf⟩
@[simp]
theorem toPGame_le_iff {a b : Ordinal} : a.toPGame ≤ b.toPGame ↔ a ≤ b :=
⟨by contrapose; rw [not_le, PGame.not_le]; exact toPGame_lf, toPGame_le⟩
@[simp]
theorem toPGame_lt_iff {a b : Ordinal} : a.toPGame < b.toPGame ↔ a < b :=
⟨by contrapose; rw [not_lt]; exact fun h => not_lt_of_le (toPGame_le h), toPGame_lt⟩
@[simp]
theorem toPGame_equiv_iff {a b : Ordinal} : (a.toPGame ≈ b.toPGame) ↔ a = b := by
-- Porting note: was `rw [PGame.Equiv]`
change _ ≤_ ∧ _ ≤ _ ↔ _
rw [le_antisymm_iff, toPGame_le_iff, toPGame_le_iff]
theorem toPGame_injective : Function.Injective Ordinal.toPGame := fun _ _ h =>
toPGame_equiv_iff.1 <| equiv_of_eq h
@[simp]
theorem toPGame_eq_iff {a b : Ordinal} : a.toPGame = b.toPGame ↔ a = b :=
toPGame_injective.eq_iff
/-- The order embedding version of `toPGame`. -/
@[simps]
noncomputable def toPGameEmbedding : Ordinal.{u} ↪o PGame.{u} where
toFun := Ordinal.toPGame
inj' := toPGame_injective
map_rel_iff' := @toPGame_le_iff
/-- The sum of ordinals as games corresponds to natural addition of ordinals. -/
theorem toPGame_add : ∀ a b : Ordinal.{u}, a.toPGame + b.toPGame ≈ (a ♯ b).toPGame
| a, b => by
refine ⟨le_of_forall_lf (fun i => ?_) isEmptyElim, le_of_forall_lf (fun i => ?_) isEmptyElim⟩
· apply leftMoves_add_cases i <;>
intro i <;>
let wf := toLeftMovesToPGame_symm_lt i <;>
(try rw [add_moveLeft_inl]) <;>
(try rw [add_moveLeft_inr]) <;>
rw [toPGame_moveLeft', lf_congr_left (toPGame_add _ _), toPGame_lf_iff]
· exact nadd_lt_nadd_right wf _
· exact nadd_lt_nadd_left wf _
· rw [toPGame_moveLeft']
rcases lt_nadd_iff.1 (toLeftMovesToPGame_symm_lt i) with (⟨c, hc, hc'⟩ | ⟨c, hc, hc'⟩) <;>
rw [← toPGame_le_iff, ← le_congr_right (toPGame_add _ _)] at hc' <;>
apply lf_of_le_of_lf hc'
· apply add_lf_add_right
rwa [toPGame_lf_iff]
· apply add_lf_add_left
rwa [toPGame_lf_iff]
termination_by a b => (a, b)
@[simp]
theorem toPGame_add_mk' (a b : Ordinal) : (⟦a.toPGame⟧ + ⟦b.toPGame⟧ : Game) = ⟦(a ♯ b).toPGame⟧ :=
Quot.sound (toPGame_add a b)
end Ordinal
|
SetTheory\Game\PGame.lean | /-
Copyright (c) 2019 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton, Mario Carneiro, Isabel Longbottom, Scott Morrison
-/
import Mathlib.Algebra.Order.ZeroLEOne
import Mathlib.Data.List.InsertNth
import Mathlib.Logic.Relation
import Mathlib.Logic.Small.Defs
import Mathlib.Order.GameAdd
/-!
# Combinatorial (pre-)games.
The basic theory of combinatorial games, following Conway's book `On Numbers and Games`. We
construct "pregames", define an ordering and arithmetic operations on them, then show that the
operations descend to "games", defined via the equivalence relation `p ≈ q ↔ p ≤ q ∧ q ≤ p`.
The surreal numbers will be built as a quotient of a subtype of pregames.
A pregame (`SetTheory.PGame` below) is axiomatised via an inductive type, whose sole constructor
takes two types (thought of as indexing the possible moves for the players Left and Right), and a
pair of functions out of these types to `SetTheory.PGame` (thought of as describing the resulting
game after making a move).
Combinatorial games themselves, as a quotient of pregames, are constructed in `Game.lean`.
## Conway induction
By construction, the induction principle for pregames is exactly "Conway induction". That is, to
prove some predicate `SetTheory.PGame → Prop` holds for all pregames, it suffices to prove
that for every pregame `g`, if the predicate holds for every game resulting from making a move,
then it also holds for `g`.
While it is often convenient to work "by induction" on pregames, in some situations this becomes
awkward, so we also define accessor functions `SetTheory.PGame.LeftMoves`,
`SetTheory.PGame.RightMoves`, `SetTheory.PGame.moveLeft` and `SetTheory.PGame.moveRight`.
There is a relation `PGame.Subsequent p q`, saying that
`p` can be reached by playing some non-empty sequence of moves starting from `q`, an instance
`WellFounded Subsequent`, and a local tactic `pgame_wf_tac` which is helpful for discharging proof
obligations in inductive proofs relying on this relation.
## Order properties
Pregames have both a `≤` and a `<` relation, satisfying the usual properties of a `Preorder`. The
relation `0 < x` means that `x` can always be won by Left, while `0 ≤ x` means that `x` can be won
by Left as the second player.
It turns out to be quite convenient to define various relations on top of these. We define the "less
or fuzzy" relation `x ⧏ y` as `¬ y ≤ x`, the equivalence relation `x ≈ y` as `x ≤ y ∧ y ≤ x`, and
the fuzzy relation `x ‖ y` as `x ⧏ y ∧ y ⧏ x`. If `0 ⧏ x`, then `x` can be won by Left as the
first player. If `x ≈ 0`, then `x` can be won by the second player. If `x ‖ 0`, then `x` can be won
by the first player.
Statements like `zero_le_lf`, `zero_lf_le`, etc. unfold these definitions. The theorems `le_def` and
`lf_def` give a recursive characterisation of each relation in terms of themselves two moves later.
The theorems `zero_le`, `zero_lf`, etc. also take into account that `0` has no moves.
Later, games will be defined as the quotient by the `≈` relation; that is to say, the
`Antisymmetrization` of `SetTheory.PGame`.
## Algebraic structures
We next turn to defining the operations necessary to make games into a commutative additive group.
Addition is defined for $x = \{xL | xR\}$ and $y = \{yL | yR\}$ by $x + y = \{xL + y, x + yL | xR +
y, x + yR\}$. Negation is defined by $\{xL | xR\} = \{-xR | -xL\}$.
The order structures interact in the expected way with addition, so we have
```
theorem le_iff_sub_nonneg {x y : PGame} : x ≤ y ↔ 0 ≤ y - x := sorry
theorem lt_iff_sub_pos {x y : PGame} : x < y ↔ 0 < y - x := sorry
```
We show that these operations respect the equivalence relation, and hence descend to games. At the
level of games, these operations satisfy all the laws of a commutative group. To prove the necessary
equivalence relations at the level of pregames, we introduce the notion of a `Relabelling` of a
game, and show, for example, that there is a relabelling between `x + (y + z)` and `(x + y) + z`.
## Future work
* The theory of dominated and reversible positions, and unique normal form for short games.
* Analysis of basic domineering positions.
* Hex.
* Temperature.
* The development of surreal numbers, based on this development of combinatorial games, is still
quite incomplete.
## References
The material here is all drawn from
* [Conway, *On numbers and games*][conway2001]
An interested reader may like to formalise some of the material from
* [Andreas Blass, *A game semantics for linear logic*][MR1167694]
* [André Joyal, *Remarques sur la théorie des jeux à deux personnes*][joyal1997]
-/
namespace SetTheory
open Function Relation
/-! ### Pre-game moves -/
universe u
/-- The type of pre-games, before we have quotiented
by equivalence (`PGame.Setoid`). In ZFC, a combinatorial game is constructed from
two sets of combinatorial games that have been constructed at an earlier
stage. To do this in type theory, we say that a pre-game is built
inductively from two families of pre-games indexed over any type
in Type u. The resulting type `PGame.{u}` lives in `Type (u+1)`,
reflecting that it is a proper class in ZFC. -/
inductive PGame : Type (u + 1)
| mk : ∀ α β : Type u, (α → PGame) → (β → PGame) → PGame
compile_inductive% PGame
namespace PGame
/-- The indexing type for allowable moves by Left. -/
def LeftMoves : PGame → Type u
| mk l _ _ _ => l
/-- The indexing type for allowable moves by Right. -/
def RightMoves : PGame → Type u
| mk _ r _ _ => r
/-- The new game after Left makes an allowed move. -/
def moveLeft : ∀ g : PGame, LeftMoves g → PGame
| mk _l _ L _ => L
/-- The new game after Right makes an allowed move. -/
def moveRight : ∀ g : PGame, RightMoves g → PGame
| mk _ _r _ R => R
@[simp]
theorem leftMoves_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).LeftMoves = xl :=
rfl
@[simp]
theorem moveLeft_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).moveLeft = xL :=
rfl
@[simp]
theorem rightMoves_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).RightMoves = xr :=
rfl
@[simp]
theorem moveRight_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).moveRight = xR :=
rfl
-- TODO define this at the level of games, as well, and perhaps also for finsets of games.
/-- Construct a pre-game from list of pre-games describing the available moves for Left and Right.
-/
def ofLists (L R : List PGame.{u}) : PGame.{u} :=
mk (ULift (Fin L.length)) (ULift (Fin R.length)) (fun i => L[i.down.1]) fun j ↦ R[j.down.1]
theorem leftMoves_ofLists (L R : List PGame) : (ofLists L R).LeftMoves = ULift (Fin L.length) :=
rfl
theorem rightMoves_ofLists (L R : List PGame) : (ofLists L R).RightMoves = ULift (Fin R.length) :=
rfl
/-- Converts a number into a left move for `ofLists`. -/
def toOfListsLeftMoves {L R : List PGame} : Fin L.length ≃ (ofLists L R).LeftMoves :=
((Equiv.cast (leftMoves_ofLists L R).symm).trans Equiv.ulift).symm
/-- Converts a number into a right move for `ofLists`. -/
def toOfListsRightMoves {L R : List PGame} : Fin R.length ≃ (ofLists L R).RightMoves :=
((Equiv.cast (rightMoves_ofLists L R).symm).trans Equiv.ulift).symm
theorem ofLists_moveLeft {L R : List PGame} (i : Fin L.length) :
(ofLists L R).moveLeft (toOfListsLeftMoves i) = L.get i :=
rfl
@[simp]
theorem ofLists_moveLeft' {L R : List PGame} (i : (ofLists L R).LeftMoves) :
(ofLists L R).moveLeft i = L.get (toOfListsLeftMoves.symm i) :=
rfl
theorem ofLists_moveRight {L R : List PGame} (i : Fin R.length) :
(ofLists L R).moveRight (toOfListsRightMoves i) = R.get i :=
rfl
@[simp]
theorem ofLists_moveRight' {L R : List PGame} (i : (ofLists L R).RightMoves) :
(ofLists L R).moveRight i = R.get (toOfListsRightMoves.symm i) :=
rfl
/-- A variant of `PGame.recOn` expressed in terms of `PGame.moveLeft` and `PGame.moveRight`.
Both this and `PGame.recOn` describe Conway induction on games. -/
@[elab_as_elim]
def moveRecOn {C : PGame → Sort*} (x : PGame)
(IH : ∀ y : PGame, (∀ i, C (y.moveLeft i)) → (∀ j, C (y.moveRight j)) → C y) : C x :=
x.recOn fun yl yr yL yR => IH (mk yl yr yL yR)
/-- `IsOption x y` means that `x` is either a left or right option for `y`. -/
@[mk_iff]
inductive IsOption : PGame → PGame → Prop
| moveLeft {x : PGame} (i : x.LeftMoves) : IsOption (x.moveLeft i) x
| moveRight {x : PGame} (i : x.RightMoves) : IsOption (x.moveRight i) x
theorem IsOption.mk_left {xl xr : Type u} (xL : xl → PGame) (xR : xr → PGame) (i : xl) :
(xL i).IsOption (mk xl xr xL xR) :=
@IsOption.moveLeft (mk _ _ _ _) i
theorem IsOption.mk_right {xl xr : Type u} (xL : xl → PGame) (xR : xr → PGame) (i : xr) :
(xR i).IsOption (mk xl xr xL xR) :=
@IsOption.moveRight (mk _ _ _ _) i
theorem wf_isOption : WellFounded IsOption :=
⟨fun x =>
moveRecOn x fun x IHl IHr =>
Acc.intro x fun y h => by
induction' h with _ i _ j
· exact IHl i
· exact IHr j⟩
/-- `Subsequent x y` says that `x` can be obtained by playing some nonempty sequence of moves from
`y`. It is the transitive closure of `IsOption`. -/
def Subsequent : PGame → PGame → Prop :=
TransGen IsOption
instance : IsTrans _ Subsequent :=
inferInstanceAs <| IsTrans _ (TransGen _)
@[trans]
theorem Subsequent.trans {x y z} : Subsequent x y → Subsequent y z → Subsequent x z :=
TransGen.trans
theorem wf_subsequent : WellFounded Subsequent :=
wf_isOption.transGen
instance : WellFoundedRelation PGame :=
⟨_, wf_subsequent⟩
@[simp]
theorem Subsequent.moveLeft {x : PGame} (i : x.LeftMoves) : Subsequent (x.moveLeft i) x :=
TransGen.single (IsOption.moveLeft i)
@[simp]
theorem Subsequent.moveRight {x : PGame} (j : x.RightMoves) : Subsequent (x.moveRight j) x :=
TransGen.single (IsOption.moveRight j)
@[simp]
theorem Subsequent.mk_left {xl xr} (xL : xl → PGame) (xR : xr → PGame) (i : xl) :
Subsequent (xL i) (mk xl xr xL xR) :=
@Subsequent.moveLeft (mk _ _ _ _) i
@[simp]
theorem Subsequent.mk_right {xl xr} (xL : xl → PGame) (xR : xr → PGame) (j : xr) :
Subsequent (xR j) (mk xl xr xL xR) :=
@Subsequent.moveRight (mk _ _ _ _) j
/--
Discharges proof obligations of the form `⊢ Subsequent ..` arising in termination proofs
of definitions using well-founded recursion on `PGame`.
-/
macro "pgame_wf_tac" : tactic =>
`(tactic| solve_by_elim (config := { maxDepth := 8 })
[Prod.Lex.left, Prod.Lex.right, PSigma.Lex.left, PSigma.Lex.right,
Subsequent.moveLeft, Subsequent.moveRight, Subsequent.mk_left, Subsequent.mk_right,
Subsequent.trans] )
-- Register some consequences of pgame_wf_tac as simp-lemmas for convenience
-- (which are applied by default for WF goals)
variable {xl xr : Type u}
-- This is different from mk_right from the POV of the simplifier,
-- because the unifier can't solve `xr =?= RightMoves (mk xl xr xL xR)` at reducible transparency.
@[simp]
theorem Subsequent.mk_right' (xL : xl → PGame) (xR : xr → PGame) (j : RightMoves (mk xl xr xL xR)) :
Subsequent (xR j) (mk xl xr xL xR) := by
pgame_wf_tac
@[simp] theorem Subsequent.moveRight_mk_left {xR : xr → PGame} {i : xl} (xL : xl → PGame) (j) :
Subsequent ((xL i).moveRight j) (mk xl xr xL xR) := by
pgame_wf_tac
@[simp] theorem Subsequent.moveRight_mk_right {xL : xl → PGame} {i : xr} (xR : xr → PGame) (j) :
Subsequent ((xR i).moveRight j) (mk xl xr xL xR) := by
pgame_wf_tac
@[simp] theorem Subsequent.moveLeft_mk_left {xR : xr → PGame} {i : xl} (xL : xl → PGame) (j) :
Subsequent ((xL i).moveLeft j) (mk xl xr xL xR) := by
pgame_wf_tac
@[simp] theorem Subsequent.moveLeft_mk_right {xL : xl → PGame} {i : xr} (xR : xr → PGame) (j) :
Subsequent ((xR i).moveLeft j) (mk xl xr xL xR) := by
pgame_wf_tac
-- Porting note: linter claims these lemmas don't simplify?
open Subsequent in attribute [nolint simpNF] mk_left mk_right mk_right'
moveRight_mk_left moveRight_mk_right moveLeft_mk_left moveLeft_mk_right
/-! ### Basic pre-games -/
/-- The pre-game `Zero` is defined by `0 = { | }`. -/
instance : Zero PGame :=
⟨⟨PEmpty, PEmpty, PEmpty.elim, PEmpty.elim⟩⟩
@[simp]
theorem zero_leftMoves : LeftMoves 0 = PEmpty :=
rfl
@[simp]
theorem zero_rightMoves : RightMoves 0 = PEmpty :=
rfl
instance isEmpty_zero_leftMoves : IsEmpty (LeftMoves 0) :=
instIsEmptyPEmpty
instance isEmpty_zero_rightMoves : IsEmpty (RightMoves 0) :=
instIsEmptyPEmpty
instance : Inhabited PGame :=
⟨0⟩
/-- The pre-game `One` is defined by `1 = { 0 | }`. -/
instance instOnePGame : One PGame :=
⟨⟨PUnit, PEmpty, fun _ => 0, PEmpty.elim⟩⟩
@[simp]
theorem one_leftMoves : LeftMoves 1 = PUnit :=
rfl
@[simp]
theorem one_moveLeft (x) : moveLeft 1 x = 0 :=
rfl
@[simp]
theorem one_rightMoves : RightMoves 1 = PEmpty :=
rfl
instance uniqueOneLeftMoves : Unique (LeftMoves 1) :=
PUnit.unique
instance isEmpty_one_rightMoves : IsEmpty (RightMoves 1) :=
instIsEmptyPEmpty
/-! ### Pre-game order relations -/
/-- The less or equal relation on pre-games.
If `0 ≤ x`, then Left can win `x` as the second player. -/
instance le : LE PGame :=
⟨Sym2.GameAdd.fix wf_isOption fun x y le =>
(∀ i, ¬le y (x.moveLeft i) (Sym2.GameAdd.snd_fst <| IsOption.moveLeft i)) ∧
∀ j, ¬le (y.moveRight j) x (Sym2.GameAdd.fst_snd <| IsOption.moveRight j)⟩
/-- The less or fuzzy relation on pre-games.
If `0 ⧏ x`, then Left can win `x` as the first player. -/
def LF (x y : PGame) : Prop :=
¬y ≤ x
@[inherit_doc]
scoped infixl:50 " ⧏ " => PGame.LF
@[simp]
protected theorem not_le {x y : PGame} : ¬x ≤ y ↔ y ⧏ x :=
Iff.rfl
@[simp]
theorem not_lf {x y : PGame} : ¬x ⧏ y ↔ y ≤ x :=
Classical.not_not
theorem _root_.LE.le.not_gf {x y : PGame} : x ≤ y → ¬y ⧏ x :=
not_lf.2
theorem LF.not_ge {x y : PGame} : x ⧏ y → ¬y ≤ x :=
id
/-- Definition of `x ≤ y` on pre-games, in terms of `⧏`.
The ordering here is chosen so that `And.left` refer to moves by Left, and `And.right` refer to
moves by Right. -/
theorem le_iff_forall_lf {x y : PGame} :
x ≤ y ↔ (∀ i, x.moveLeft i ⧏ y) ∧ ∀ j, x ⧏ y.moveRight j := by
unfold LE.le le
simp only
rw [Sym2.GameAdd.fix_eq]
rfl
/-- Definition of `x ≤ y` on pre-games built using the constructor. -/
@[simp]
theorem mk_le_mk {xl xr xL xR yl yr yL yR} :
mk xl xr xL xR ≤ mk yl yr yL yR ↔ (∀ i, xL i ⧏ mk yl yr yL yR) ∧ ∀ j, mk xl xr xL xR ⧏ yR j :=
le_iff_forall_lf
theorem le_of_forall_lf {x y : PGame} (h₁ : ∀ i, x.moveLeft i ⧏ y) (h₂ : ∀ j, x ⧏ y.moveRight j) :
x ≤ y :=
le_iff_forall_lf.2 ⟨h₁, h₂⟩
/-- Definition of `x ⧏ y` on pre-games, in terms of `≤`.
The ordering here is chosen so that `or.inl` refer to moves by Left, and `or.inr` refer to
moves by Right. -/
theorem lf_iff_exists_le {x y : PGame} :
x ⧏ y ↔ (∃ i, x ≤ y.moveLeft i) ∨ ∃ j, x.moveRight j ≤ y := by
rw [LF, le_iff_forall_lf, not_and_or]
simp
/-- Definition of `x ⧏ y` on pre-games built using the constructor. -/
@[simp]
theorem mk_lf_mk {xl xr xL xR yl yr yL yR} :
mk xl xr xL xR ⧏ mk yl yr yL yR ↔ (∃ i, mk xl xr xL xR ≤ yL i) ∨ ∃ j, xR j ≤ mk yl yr yL yR :=
lf_iff_exists_le
theorem le_or_gf (x y : PGame) : x ≤ y ∨ y ⧏ x := by
rw [← PGame.not_le]
apply em
theorem moveLeft_lf_of_le {x y : PGame} (h : x ≤ y) (i) : x.moveLeft i ⧏ y :=
(le_iff_forall_lf.1 h).1 i
alias _root_.LE.le.moveLeft_lf := moveLeft_lf_of_le
theorem lf_moveRight_of_le {x y : PGame} (h : x ≤ y) (j) : x ⧏ y.moveRight j :=
(le_iff_forall_lf.1 h).2 j
alias _root_.LE.le.lf_moveRight := lf_moveRight_of_le
theorem lf_of_moveRight_le {x y : PGame} {j} (h : x.moveRight j ≤ y) : x ⧏ y :=
lf_iff_exists_le.2 <| Or.inr ⟨j, h⟩
theorem lf_of_le_moveLeft {x y : PGame} {i} (h : x ≤ y.moveLeft i) : x ⧏ y :=
lf_iff_exists_le.2 <| Or.inl ⟨i, h⟩
theorem lf_of_le_mk {xl xr xL xR y} : mk xl xr xL xR ≤ y → ∀ i, xL i ⧏ y :=
moveLeft_lf_of_le
theorem lf_of_mk_le {x yl yr yL yR} : x ≤ mk yl yr yL yR → ∀ j, x ⧏ yR j :=
lf_moveRight_of_le
theorem mk_lf_of_le {xl xr y j} (xL) {xR : xr → PGame} : xR j ≤ y → mk xl xr xL xR ⧏ y :=
@lf_of_moveRight_le (mk _ _ _ _) y j
theorem lf_mk_of_le {x yl yr} {yL : yl → PGame} (yR) {i} : x ≤ yL i → x ⧏ mk yl yr yL yR :=
@lf_of_le_moveLeft x (mk _ _ _ _) i
/- We prove that `x ≤ y → y ≤ z → x ≤ z` inductively, by also simultaneously proving its cyclic
reorderings. This auxiliary lemma is used during said induction. -/
private theorem le_trans_aux {x y z : PGame}
(h₁ : ∀ {i}, y ≤ z → z ≤ x.moveLeft i → y ≤ x.moveLeft i)
(h₂ : ∀ {j}, z.moveRight j ≤ x → x ≤ y → z.moveRight j ≤ y) (hxy : x ≤ y) (hyz : y ≤ z) :
x ≤ z :=
le_of_forall_lf (fun i => PGame.not_le.1 fun h => (h₁ hyz h).not_gf <| hxy.moveLeft_lf i)
fun j => PGame.not_le.1 fun h => (h₂ h hxy).not_gf <| hyz.lf_moveRight j
instance : Preorder PGame :=
{ PGame.le with
le_refl := fun x => by
induction' x with _ _ _ _ IHl IHr
exact
le_of_forall_lf (fun i => lf_of_le_moveLeft (IHl i)) fun i => lf_of_moveRight_le (IHr i)
le_trans := by
suffices
∀ {x y z : PGame},
(x ≤ y → y ≤ z → x ≤ z) ∧ (y ≤ z → z ≤ x → y ≤ x) ∧ (z ≤ x → x ≤ y → z ≤ y) from
fun x y z => this.1
intro x y z
induction' x with xl xr xL xR IHxl IHxr generalizing y z
induction' y with yl yr yL yR IHyl IHyr generalizing z
induction' z with zl zr zL zR IHzl IHzr
exact
⟨le_trans_aux (fun {i} => (IHxl i).2.1) fun {j} => (IHzr j).2.2,
le_trans_aux (fun {i} => (IHyl i).2.2) fun {j} => (IHxr j).1,
le_trans_aux (fun {i} => (IHzl i).1) fun {j} => (IHyr j).2.1⟩
lt := fun x y => x ≤ y ∧ x ⧏ y }
theorem lt_iff_le_and_lf {x y : PGame} : x < y ↔ x ≤ y ∧ x ⧏ y :=
Iff.rfl
theorem lt_of_le_of_lf {x y : PGame} (h₁ : x ≤ y) (h₂ : x ⧏ y) : x < y :=
⟨h₁, h₂⟩
theorem lf_of_lt {x y : PGame} (h : x < y) : x ⧏ y :=
h.2
alias _root_.LT.lt.lf := lf_of_lt
theorem lf_irrefl (x : PGame) : ¬x ⧏ x :=
le_rfl.not_gf
instance : IsIrrefl _ (· ⧏ ·) :=
⟨lf_irrefl⟩
@[trans]
theorem lf_of_le_of_lf {x y z : PGame} (h₁ : x ≤ y) (h₂ : y ⧏ z) : x ⧏ z := by
rw [← PGame.not_le] at h₂ ⊢
exact fun h₃ => h₂ (h₃.trans h₁)
-- Porting note (#10754): added instance
instance : Trans (· ≤ ·) (· ⧏ ·) (· ⧏ ·) := ⟨lf_of_le_of_lf⟩
@[trans]
theorem lf_of_lf_of_le {x y z : PGame} (h₁ : x ⧏ y) (h₂ : y ≤ z) : x ⧏ z := by
rw [← PGame.not_le] at h₁ ⊢
exact fun h₃ => h₁ (h₂.trans h₃)
-- Porting note (#10754): added instance
instance : Trans (· ⧏ ·) (· ≤ ·) (· ⧏ ·) := ⟨lf_of_lf_of_le⟩
alias _root_.LE.le.trans_lf := lf_of_le_of_lf
alias LF.trans_le := lf_of_lf_of_le
@[trans]
theorem lf_of_lt_of_lf {x y z : PGame} (h₁ : x < y) (h₂ : y ⧏ z) : x ⧏ z :=
h₁.le.trans_lf h₂
@[trans]
theorem lf_of_lf_of_lt {x y z : PGame} (h₁ : x ⧏ y) (h₂ : y < z) : x ⧏ z :=
h₁.trans_le h₂.le
alias _root_.LT.lt.trans_lf := lf_of_lt_of_lf
alias LF.trans_lt := lf_of_lf_of_lt
theorem moveLeft_lf {x : PGame} : ∀ i, x.moveLeft i ⧏ x :=
le_rfl.moveLeft_lf
theorem lf_moveRight {x : PGame} : ∀ j, x ⧏ x.moveRight j :=
le_rfl.lf_moveRight
theorem lf_mk {xl xr} (xL : xl → PGame) (xR : xr → PGame) (i) : xL i ⧏ mk xl xr xL xR :=
@moveLeft_lf (mk _ _ _ _) i
theorem mk_lf {xl xr} (xL : xl → PGame) (xR : xr → PGame) (j) : mk xl xr xL xR ⧏ xR j :=
@lf_moveRight (mk _ _ _ _) j
/-- This special case of `PGame.le_of_forall_lf` is useful when dealing with surreals, where `<` is
preferred over `⧏`. -/
theorem le_of_forall_lt {x y : PGame} (h₁ : ∀ i, x.moveLeft i < y) (h₂ : ∀ j, x < y.moveRight j) :
x ≤ y :=
le_of_forall_lf (fun i => (h₁ i).lf) fun i => (h₂ i).lf
/-- The definition of `x ≤ y` on pre-games, in terms of `≤` two moves later. -/
theorem le_def {x y : PGame} :
x ≤ y ↔
(∀ i, (∃ i', x.moveLeft i ≤ y.moveLeft i') ∨ ∃ j, (x.moveLeft i).moveRight j ≤ y) ∧
∀ j, (∃ i, x ≤ (y.moveRight j).moveLeft i) ∨ ∃ j', x.moveRight j' ≤ y.moveRight j := by
rw [le_iff_forall_lf]
conv =>
lhs
simp only [lf_iff_exists_le]
/-- The definition of `x ⧏ y` on pre-games, in terms of `⧏` two moves later. -/
theorem lf_def {x y : PGame} :
x ⧏ y ↔
(∃ i, (∀ i', x.moveLeft i' ⧏ y.moveLeft i) ∧ ∀ j, x ⧏ (y.moveLeft i).moveRight j) ∨
∃ j, (∀ i, (x.moveRight j).moveLeft i ⧏ y) ∧ ∀ j', x.moveRight j ⧏ y.moveRight j' := by
rw [lf_iff_exists_le]
conv =>
lhs
simp only [le_iff_forall_lf]
/-- The definition of `0 ≤ x` on pre-games, in terms of `0 ⧏`. -/
theorem zero_le_lf {x : PGame} : 0 ≤ x ↔ ∀ j, 0 ⧏ x.moveRight j := by
rw [le_iff_forall_lf]
simp
/-- The definition of `x ≤ 0` on pre-games, in terms of `⧏ 0`. -/
theorem le_zero_lf {x : PGame} : x ≤ 0 ↔ ∀ i, x.moveLeft i ⧏ 0 := by
rw [le_iff_forall_lf]
simp
/-- The definition of `0 ⧏ x` on pre-games, in terms of `0 ≤`. -/
theorem zero_lf_le {x : PGame} : 0 ⧏ x ↔ ∃ i, 0 ≤ x.moveLeft i := by
rw [lf_iff_exists_le]
simp
/-- The definition of `x ⧏ 0` on pre-games, in terms of `≤ 0`. -/
theorem lf_zero_le {x : PGame} : x ⧏ 0 ↔ ∃ j, x.moveRight j ≤ 0 := by
rw [lf_iff_exists_le]
simp
/-- The definition of `0 ≤ x` on pre-games, in terms of `0 ≤` two moves later. -/
theorem zero_le {x : PGame} : 0 ≤ x ↔ ∀ j, ∃ i, 0 ≤ (x.moveRight j).moveLeft i := by
rw [le_def]
simp
/-- The definition of `x ≤ 0` on pre-games, in terms of `≤ 0` two moves later. -/
theorem le_zero {x : PGame} : x ≤ 0 ↔ ∀ i, ∃ j, (x.moveLeft i).moveRight j ≤ 0 := by
rw [le_def]
simp
/-- The definition of `0 ⧏ x` on pre-games, in terms of `0 ⧏` two moves later. -/
theorem zero_lf {x : PGame} : 0 ⧏ x ↔ ∃ i, ∀ j, 0 ⧏ (x.moveLeft i).moveRight j := by
rw [lf_def]
simp
/-- The definition of `x ⧏ 0` on pre-games, in terms of `⧏ 0` two moves later. -/
theorem lf_zero {x : PGame} : x ⧏ 0 ↔ ∃ j, ∀ i, (x.moveRight j).moveLeft i ⧏ 0 := by
rw [lf_def]
simp
@[simp]
theorem zero_le_of_isEmpty_rightMoves (x : PGame) [IsEmpty x.RightMoves] : 0 ≤ x :=
zero_le.2 isEmptyElim
@[simp]
theorem le_zero_of_isEmpty_leftMoves (x : PGame) [IsEmpty x.LeftMoves] : x ≤ 0 :=
le_zero.2 isEmptyElim
/-- Given a game won by the right player when they play second, provide a response to any move by
left. -/
noncomputable def rightResponse {x : PGame} (h : x ≤ 0) (i : x.LeftMoves) :
(x.moveLeft i).RightMoves :=
Classical.choose <| (le_zero.1 h) i
/-- Show that the response for right provided by `rightResponse` preserves the right-player-wins
condition. -/
theorem rightResponse_spec {x : PGame} (h : x ≤ 0) (i : x.LeftMoves) :
(x.moveLeft i).moveRight (rightResponse h i) ≤ 0 :=
Classical.choose_spec <| (le_zero.1 h) i
/-- Given a game won by the left player when they play second, provide a response to any move by
right. -/
noncomputable def leftResponse {x : PGame} (h : 0 ≤ x) (j : x.RightMoves) :
(x.moveRight j).LeftMoves :=
Classical.choose <| (zero_le.1 h) j
/-- Show that the response for left provided by `leftResponse` preserves the left-player-wins
condition. -/
theorem leftResponse_spec {x : PGame} (h : 0 ≤ x) (j : x.RightMoves) :
0 ≤ (x.moveRight j).moveLeft (leftResponse h j) :=
Classical.choose_spec <| (zero_le.1 h) j
/-- A small family of pre-games is bounded above. -/
lemma bddAbove_range_of_small {ι : Type*} [Small.{u} ι] (f : ι → PGame.{u}) :
BddAbove (Set.range f) := by
let x : PGame.{u} := ⟨Σ i, (f $ (equivShrink.{u} ι).symm i).LeftMoves, PEmpty,
fun x ↦ moveLeft _ x.2, PEmpty.elim⟩
refine ⟨x, Set.forall_mem_range.2 fun i ↦ ?_⟩
rw [← (equivShrink ι).symm_apply_apply i, le_iff_forall_lf]
simpa [x] using fun j ↦ @moveLeft_lf x ⟨equivShrink ι i, j⟩
/-- A small set of pre-games is bounded above. -/
lemma bddAbove_of_small (s : Set PGame.{u}) [Small.{u} s] : BddAbove s := by
simpa using bddAbove_range_of_small (Subtype.val : s → PGame.{u})
/-- A small family of pre-games is bounded below. -/
lemma bddBelow_range_of_small {ι : Type*} [Small.{u} ι] (f : ι → PGame.{u}) :
BddBelow (Set.range f) := by
let x : PGame.{u} := ⟨PEmpty, Σ i, (f $ (equivShrink.{u} ι).symm i).RightMoves, PEmpty.elim,
fun x ↦ moveRight _ x.2⟩
refine ⟨x, Set.forall_mem_range.2 fun i ↦ ?_⟩
rw [← (equivShrink ι).symm_apply_apply i, le_iff_forall_lf]
simpa [x] using fun j ↦ @lf_moveRight x ⟨equivShrink ι i, j⟩
/-- A small set of pre-games is bounded below. -/
lemma bddBelow_of_small (s : Set PGame.{u}) [Small.{u} s] : BddBelow s := by
simpa using bddBelow_range_of_small (Subtype.val : s → PGame.{u})
/-- The equivalence relation on pre-games. Two pre-games `x`, `y` are equivalent if `x ≤ y` and
`y ≤ x`.
If `x ≈ 0`, then the second player can always win `x`. -/
def Equiv (x y : PGame) : Prop :=
x ≤ y ∧ y ≤ x
-- Porting note: deleted the scoped notation due to notation overloading with the setoid
-- instance and this causes the PGame.equiv docstring to not show up on hover.
instance : IsEquiv _ PGame.Equiv where
refl _ := ⟨le_rfl, le_rfl⟩
trans := fun _ _ _ ⟨xy, yx⟩ ⟨yz, zy⟩ => ⟨xy.trans yz, zy.trans yx⟩
symm _ _ := And.symm
-- Porting note: moved the setoid instance from Basic.lean to here
instance setoid : Setoid PGame :=
⟨Equiv, refl, symm, Trans.trans⟩
theorem equiv_def {x y : PGame} : x ≈ y ↔ x ≤ y ∧ y ≤ x := Iff.rfl
theorem Equiv.le {x y : PGame} (h : x ≈ y) : x ≤ y :=
h.1
theorem Equiv.ge {x y : PGame} (h : x ≈ y) : y ≤ x :=
h.2
@[refl, simp]
theorem equiv_rfl {x : PGame} : x ≈ x :=
refl x
theorem equiv_refl (x : PGame) : x ≈ x :=
refl x
@[symm]
protected theorem Equiv.symm {x y : PGame} : (x ≈ y) → (y ≈ x) :=
symm
@[trans]
protected theorem Equiv.trans {x y z : PGame} : (x ≈ y) → (y ≈ z) → (x ≈ z) :=
_root_.trans
protected theorem equiv_comm {x y : PGame} : (x ≈ y) ↔ (y ≈ x) :=
comm
theorem equiv_of_eq {x y : PGame} (h : x = y) : x ≈ y := by subst h; rfl
@[trans]
theorem le_of_le_of_equiv {x y z : PGame} (h₁ : x ≤ y) (h₂ : y ≈ z) : x ≤ z :=
h₁.trans h₂.1
instance : Trans
((· ≤ ·) : PGame → PGame → Prop)
((· ≈ ·) : PGame → PGame → Prop)
((· ≤ ·) : PGame → PGame → Prop) where
trans := le_of_le_of_equiv
@[trans]
theorem le_of_equiv_of_le {x y z : PGame} (h₁ : x ≈ y) : y ≤ z → x ≤ z :=
h₁.1.trans
instance : Trans
((· ≈ ·) : PGame → PGame → Prop)
((· ≤ ·) : PGame → PGame → Prop)
((· ≤ ·) : PGame → PGame → Prop) where
trans := le_of_equiv_of_le
theorem LF.not_equiv {x y : PGame} (h : x ⧏ y) : ¬(x ≈ y) := fun h' => h.not_ge h'.2
theorem LF.not_equiv' {x y : PGame} (h : x ⧏ y) : ¬(y ≈ x) := fun h' => h.not_ge h'.1
theorem LF.not_gt {x y : PGame} (h : x ⧏ y) : ¬y < x := fun h' => h.not_ge h'.le
theorem le_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) (h : x₁ ≤ y₁) : x₂ ≤ y₂ :=
hx.2.trans (h.trans hy.1)
theorem le_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ≤ y₁ ↔ x₂ ≤ y₂ :=
⟨le_congr_imp hx hy, le_congr_imp (Equiv.symm hx) (Equiv.symm hy)⟩
theorem le_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ ≤ y ↔ x₂ ≤ y :=
le_congr hx equiv_rfl
theorem le_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x ≤ y₁ ↔ x ≤ y₂ :=
le_congr equiv_rfl hy
theorem lf_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ⧏ y₁ ↔ x₂ ⧏ y₂ :=
PGame.not_le.symm.trans <| (not_congr (le_congr hy hx)).trans PGame.not_le
theorem lf_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ⧏ y₁ → x₂ ⧏ y₂ :=
(lf_congr hx hy).1
theorem lf_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ ⧏ y ↔ x₂ ⧏ y :=
lf_congr hx equiv_rfl
theorem lf_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x ⧏ y₁ ↔ x ⧏ y₂ :=
lf_congr equiv_rfl hy
@[trans]
theorem lf_of_lf_of_equiv {x y z : PGame} (h₁ : x ⧏ y) (h₂ : y ≈ z) : x ⧏ z :=
lf_congr_imp equiv_rfl h₂ h₁
instance : Trans (· ⧏ ·) (· ≈ ·) (· ⧏ ·) := ⟨lf_of_lf_of_equiv⟩
@[trans]
theorem lf_of_equiv_of_lf {x y z : PGame} (h₁ : x ≈ y) : y ⧏ z → x ⧏ z :=
lf_congr_imp (Equiv.symm h₁) equiv_rfl
instance : Trans (· ≈ ·) (· ⧏ ·) (· ⧏ ·) := ⟨lf_of_equiv_of_lf⟩
@[trans]
theorem lt_of_lt_of_equiv {x y z : PGame} (h₁ : x < y) (h₂ : y ≈ z) : x < z :=
h₁.trans_le h₂.1
instance : Trans
((· < ·) : PGame → PGame → Prop)
((· ≈ ·) : PGame → PGame → Prop)
((· < ·) : PGame → PGame → Prop) where
trans := lt_of_lt_of_equiv
@[trans]
theorem lt_of_equiv_of_lt {x y z : PGame} (h₁ : x ≈ y) : y < z → x < z :=
h₁.1.trans_lt
instance : Trans
((· ≈ ·) : PGame → PGame → Prop)
((· < ·) : PGame → PGame → Prop)
((· < ·) : PGame → PGame → Prop) where
trans := lt_of_equiv_of_lt
theorem lt_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) (h : x₁ < y₁) : x₂ < y₂ :=
hx.2.trans_lt (h.trans_le hy.1)
theorem lt_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ < y₁ ↔ x₂ < y₂ :=
⟨lt_congr_imp hx hy, lt_congr_imp (Equiv.symm hx) (Equiv.symm hy)⟩
theorem lt_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ < y ↔ x₂ < y :=
lt_congr hx equiv_rfl
theorem lt_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x < y₁ ↔ x < y₂ :=
lt_congr equiv_rfl hy
theorem lt_or_equiv_of_le {x y : PGame} (h : x ≤ y) : x < y ∨ (x ≈ y) :=
and_or_left.mp ⟨h, (em <| y ≤ x).symm.imp_left PGame.not_le.1⟩
theorem lf_or_equiv_or_gf (x y : PGame) : x ⧏ y ∨ (x ≈ y) ∨ y ⧏ x := by
by_cases h : x ⧏ y
· exact Or.inl h
· right
cases' lt_or_equiv_of_le (PGame.not_lf.1 h) with h' h'
· exact Or.inr h'.lf
· exact Or.inl (Equiv.symm h')
theorem equiv_congr_left {y₁ y₂ : PGame} : (y₁ ≈ y₂) ↔ ∀ x₁, (x₁ ≈ y₁) ↔ (x₁ ≈ y₂) :=
⟨fun h _ => ⟨fun h' => Equiv.trans h' h, fun h' => Equiv.trans h' (Equiv.symm h)⟩,
fun h => (h y₁).1 <| equiv_rfl⟩
theorem equiv_congr_right {x₁ x₂ : PGame} : (x₁ ≈ x₂) ↔ ∀ y₁, (x₁ ≈ y₁) ↔ (x₂ ≈ y₁) :=
⟨fun h _ => ⟨fun h' => Equiv.trans (Equiv.symm h) h', fun h' => Equiv.trans h h'⟩,
fun h => (h x₂).2 <| equiv_rfl⟩
theorem equiv_of_mk_equiv {x y : PGame} (L : x.LeftMoves ≃ y.LeftMoves)
(R : x.RightMoves ≃ y.RightMoves) (hl : ∀ i, x.moveLeft i ≈ y.moveLeft (L i))
(hr : ∀ j, x.moveRight j ≈ y.moveRight (R j)) : x ≈ y := by
constructor <;> rw [le_def]
· exact ⟨fun i => Or.inl ⟨_, (hl i).1⟩, fun j => Or.inr ⟨_, by simpa using (hr (R.symm j)).1⟩⟩
· exact ⟨fun i => Or.inl ⟨_, by simpa using (hl (L.symm i)).2⟩, fun j => Or.inr ⟨_, (hr j).2⟩⟩
/-- The fuzzy, confused, or incomparable relation on pre-games.
If `x ‖ 0`, then the first player can always win `x`. -/
def Fuzzy (x y : PGame) : Prop :=
x ⧏ y ∧ y ⧏ x
@[inherit_doc]
scoped infixl:50 " ‖ " => PGame.Fuzzy
@[symm]
theorem Fuzzy.swap {x y : PGame} : x ‖ y → y ‖ x :=
And.symm
instance : IsSymm _ (· ‖ ·) :=
⟨fun _ _ => Fuzzy.swap⟩
theorem Fuzzy.swap_iff {x y : PGame} : x ‖ y ↔ y ‖ x :=
⟨Fuzzy.swap, Fuzzy.swap⟩
theorem fuzzy_irrefl (x : PGame) : ¬x ‖ x := fun h => lf_irrefl x h.1
instance : IsIrrefl _ (· ‖ ·) :=
⟨fuzzy_irrefl⟩
theorem lf_iff_lt_or_fuzzy {x y : PGame} : x ⧏ y ↔ x < y ∨ x ‖ y := by
simp only [lt_iff_le_and_lf, Fuzzy, ← PGame.not_le]
tauto
theorem lf_of_fuzzy {x y : PGame} (h : x ‖ y) : x ⧏ y :=
lf_iff_lt_or_fuzzy.2 (Or.inr h)
alias Fuzzy.lf := lf_of_fuzzy
theorem lt_or_fuzzy_of_lf {x y : PGame} : x ⧏ y → x < y ∨ x ‖ y :=
lf_iff_lt_or_fuzzy.1
theorem Fuzzy.not_equiv {x y : PGame} (h : x ‖ y) : ¬(x ≈ y) := fun h' => h'.1.not_gf h.2
theorem Fuzzy.not_equiv' {x y : PGame} (h : x ‖ y) : ¬(y ≈ x) := fun h' => h'.2.not_gf h.2
theorem not_fuzzy_of_le {x y : PGame} (h : x ≤ y) : ¬x ‖ y := fun h' => h'.2.not_ge h
theorem not_fuzzy_of_ge {x y : PGame} (h : y ≤ x) : ¬x ‖ y := fun h' => h'.1.not_ge h
theorem Equiv.not_fuzzy {x y : PGame} (h : x ≈ y) : ¬x ‖ y :=
not_fuzzy_of_le h.1
theorem Equiv.not_fuzzy' {x y : PGame} (h : x ≈ y) : ¬y ‖ x :=
not_fuzzy_of_le h.2
theorem fuzzy_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ‖ y₁ ↔ x₂ ‖ y₂ :=
show _ ∧ _ ↔ _ ∧ _ by rw [lf_congr hx hy, lf_congr hy hx]
theorem fuzzy_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ‖ y₁ → x₂ ‖ y₂ :=
(fuzzy_congr hx hy).1
theorem fuzzy_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ ‖ y ↔ x₂ ‖ y :=
fuzzy_congr hx equiv_rfl
theorem fuzzy_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x ‖ y₁ ↔ x ‖ y₂ :=
fuzzy_congr equiv_rfl hy
@[trans]
theorem fuzzy_of_fuzzy_of_equiv {x y z : PGame} (h₁ : x ‖ y) (h₂ : y ≈ z) : x ‖ z :=
(fuzzy_congr_right h₂).1 h₁
@[trans]
theorem fuzzy_of_equiv_of_fuzzy {x y z : PGame} (h₁ : x ≈ y) (h₂ : y ‖ z) : x ‖ z :=
(fuzzy_congr_left h₁).2 h₂
/-- Exactly one of the following is true (although we don't prove this here). -/
theorem lt_or_equiv_or_gt_or_fuzzy (x y : PGame) : x < y ∨ (x ≈ y) ∨ y < x ∨ x ‖ y := by
cases' le_or_gf x y with h₁ h₁ <;> cases' le_or_gf y x with h₂ h₂
· right
left
exact ⟨h₁, h₂⟩
· left
exact ⟨h₁, h₂⟩
· right
right
left
exact ⟨h₂, h₁⟩
· right
right
right
exact ⟨h₂, h₁⟩
theorem lt_or_equiv_or_gf (x y : PGame) : x < y ∨ (x ≈ y) ∨ y ⧏ x := by
rw [lf_iff_lt_or_fuzzy, Fuzzy.swap_iff]
exact lt_or_equiv_or_gt_or_fuzzy x y
/-! ### Relabellings -/
/-- `Relabelling x y` says that `x` and `y` are really the same game, just dressed up differently.
Specifically, there is a bijection between the moves for Left in `x` and in `y`, and similarly
for Right, and under these bijections we inductively have `Relabelling`s for the consequent games.
-/
inductive Relabelling : PGame.{u} → PGame.{u} → Type (u + 1)
|
mk :
∀ {x y : PGame} (L : x.LeftMoves ≃ y.LeftMoves) (R : x.RightMoves ≃ y.RightMoves),
(∀ i, Relabelling (x.moveLeft i) (y.moveLeft (L i))) →
(∀ j, Relabelling (x.moveRight j) (y.moveRight (R j))) → Relabelling x y
@[inherit_doc]
scoped infixl:50 " ≡r " => PGame.Relabelling
namespace Relabelling
variable {x y : PGame.{u}}
/-- A constructor for relabellings swapping the equivalences. -/
def mk' (L : y.LeftMoves ≃ x.LeftMoves) (R : y.RightMoves ≃ x.RightMoves)
(hL : ∀ i, x.moveLeft (L i) ≡r y.moveLeft i) (hR : ∀ j, x.moveRight (R j) ≡r y.moveRight j) :
x ≡r y :=
⟨L.symm, R.symm, fun i => by simpa using hL (L.symm i), fun j => by simpa using hR (R.symm j)⟩
/-- The equivalence between left moves of `x` and `y` given by the relabelling. -/
def leftMovesEquiv : x ≡r y → x.LeftMoves ≃ y.LeftMoves
| ⟨L,_, _,_⟩ => L
@[simp]
theorem mk_leftMovesEquiv {x y L R hL hR} : (@Relabelling.mk x y L R hL hR).leftMovesEquiv = L :=
rfl
@[simp]
theorem mk'_leftMovesEquiv {x y L R hL hR} :
(@Relabelling.mk' x y L R hL hR).leftMovesEquiv = L.symm :=
rfl
/-- The equivalence between right moves of `x` and `y` given by the relabelling. -/
def rightMovesEquiv : x ≡r y → x.RightMoves ≃ y.RightMoves
| ⟨_, R, _, _⟩ => R
@[simp]
theorem mk_rightMovesEquiv {x y L R hL hR} : (@Relabelling.mk x y L R hL hR).rightMovesEquiv = R :=
rfl
@[simp]
theorem mk'_rightMovesEquiv {x y L R hL hR} :
(@Relabelling.mk' x y L R hL hR).rightMovesEquiv = R.symm :=
rfl
/-- A left move of `x` is a relabelling of a left move of `y`. -/
def moveLeft : ∀ (r : x ≡r y) (i : x.LeftMoves), x.moveLeft i ≡r y.moveLeft (r.leftMovesEquiv i)
| ⟨_, _, hL, _⟩ => hL
/-- A left move of `y` is a relabelling of a left move of `x`. -/
def moveLeftSymm :
∀ (r : x ≡r y) (i : y.LeftMoves), x.moveLeft (r.leftMovesEquiv.symm i) ≡r y.moveLeft i
| ⟨L, R, hL, hR⟩, i => by simpa using hL (L.symm i)
/-- A right move of `x` is a relabelling of a right move of `y`. -/
def moveRight :
∀ (r : x ≡r y) (i : x.RightMoves), x.moveRight i ≡r y.moveRight (r.rightMovesEquiv i)
| ⟨_, _, _, hR⟩ => hR
/-- A right move of `y` is a relabelling of a right move of `x`. -/
def moveRightSymm :
∀ (r : x ≡r y) (i : y.RightMoves), x.moveRight (r.rightMovesEquiv.symm i) ≡r y.moveRight i
| ⟨L, R, hL, hR⟩, i => by simpa using hR (R.symm i)
/-- The identity relabelling. -/
@[refl]
def refl (x : PGame) : x ≡r x :=
⟨Equiv.refl _, Equiv.refl _, fun i => refl _, fun j => refl _⟩
termination_by x
instance (x : PGame) : Inhabited (x ≡r x) :=
⟨refl _⟩
/-- Flip a relabelling. -/
@[symm]
def symm : ∀ {x y : PGame}, x ≡r y → y ≡r x
| _, _, ⟨L, R, hL, hR⟩ => mk' L R (fun i => (hL i).symm) fun j => (hR j).symm
theorem le {x y : PGame} (r : x ≡r y) : x ≤ y :=
le_def.2
⟨fun i => Or.inl ⟨_, (r.moveLeft i).le⟩, fun j =>
Or.inr ⟨_, (r.moveRightSymm j).le⟩⟩
termination_by x
theorem ge {x y : PGame} (r : x ≡r y) : y ≤ x :=
r.symm.le
/-- A relabelling lets us prove equivalence of games. -/
theorem equiv (r : x ≡r y) : x ≈ y :=
⟨r.le, r.ge⟩
/-- Transitivity of relabelling. -/
@[trans]
def trans : ∀ {x y z : PGame}, x ≡r y → y ≡r z → x ≡r z
| _, _, _, ⟨L₁, R₁, hL₁, hR₁⟩, ⟨L₂, R₂, hL₂, hR₂⟩ =>
⟨L₁.trans L₂, R₁.trans R₂, fun i => (hL₁ i).trans (hL₂ _), fun j => (hR₁ j).trans (hR₂ _)⟩
/-- Any game without left or right moves is a relabelling of 0. -/
def isEmpty (x : PGame) [IsEmpty x.LeftMoves] [IsEmpty x.RightMoves] : x ≡r 0 :=
⟨Equiv.equivPEmpty _, Equiv.equivOfIsEmpty _ _, isEmptyElim, isEmptyElim⟩
end Relabelling
theorem Equiv.isEmpty (x : PGame) [IsEmpty x.LeftMoves] [IsEmpty x.RightMoves] : x ≈ 0 :=
(Relabelling.isEmpty x).equiv
instance {x y : PGame} : Coe (x ≡r y) (x ≈ y) :=
⟨Relabelling.equiv⟩
/-- Replace the types indexing the next moves for Left and Right by equivalent types. -/
def relabel {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) : PGame :=
⟨xl', xr', x.moveLeft ∘ el, x.moveRight ∘ er⟩
@[simp]
theorem relabel_moveLeft' {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves)
(i : xl') : moveLeft (relabel el er) i = x.moveLeft (el i) :=
rfl
theorem relabel_moveLeft {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves)
(i : x.LeftMoves) : moveLeft (relabel el er) (el.symm i) = x.moveLeft i := by simp
@[simp]
theorem relabel_moveRight' {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves)
(j : xr') : moveRight (relabel el er) j = x.moveRight (er j) :=
rfl
theorem relabel_moveRight {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves)
(j : x.RightMoves) : moveRight (relabel el er) (er.symm j) = x.moveRight j := by simp
/-- The game obtained by relabelling the next moves is a relabelling of the original game. -/
def relabelRelabelling {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) :
x ≡r relabel el er :=
-- Porting note: needed to add `rfl`
Relabelling.mk' el er (fun i => by simp; rfl) (fun j => by simp; rfl)
/-! ### Negation -/
/-- The negation of `{L | R}` is `{-R | -L}`. -/
def neg : PGame → PGame
| ⟨l, r, L, R⟩ => ⟨r, l, fun i => neg (R i), fun i => neg (L i)⟩
instance : Neg PGame :=
⟨neg⟩
@[simp]
theorem neg_def {xl xr xL xR} : -mk xl xr xL xR = mk xr xl (fun j => -xR j) fun i => -xL i :=
rfl
instance : InvolutiveNeg PGame :=
{ inferInstanceAs (Neg PGame) with
neg_neg := fun x => by
induction' x with xl xr xL xR ihL ihR
simp_rw [neg_def, ihL, ihR] }
instance : NegZeroClass PGame :=
{ inferInstanceAs (Zero PGame), inferInstanceAs (Neg PGame) with
neg_zero := by
dsimp [Zero.zero, Neg.neg, neg]
congr <;> funext i <;> cases i }
@[simp]
theorem neg_ofLists (L R : List PGame) :
-ofLists L R = ofLists (R.map fun x => -x) (L.map fun x => -x) := by
simp only [ofLists, neg_def, List.getElem_map, mk.injEq, List.length_map, true_and]
constructor
all_goals
apply hfunext
· simp
· rintro ⟨⟨a, ha⟩⟩ ⟨⟨b, hb⟩⟩ h
have :
∀ {m n} (_ : m = n) {b : ULift (Fin m)} {c : ULift (Fin n)} (_ : HEq b c),
(b.down : ℕ) = ↑c.down := by
rintro m n rfl b c
simp only [heq_eq_eq]
rintro rfl
rfl
simp only [heq_eq_eq]
congr 5
exact this (List.length_map _ _).symm h
theorem isOption_neg {x y : PGame} : IsOption x (-y) ↔ IsOption (-x) y := by
rw [isOption_iff, isOption_iff, or_comm]
cases y
apply or_congr <;>
· apply exists_congr
intro
rw [neg_eq_iff_eq_neg]
rfl
@[simp]
theorem isOption_neg_neg {x y : PGame} : IsOption (-x) (-y) ↔ IsOption x y := by
rw [isOption_neg, neg_neg]
theorem leftMoves_neg : ∀ x : PGame, (-x).LeftMoves = x.RightMoves
| ⟨_, _, _, _⟩ => rfl
theorem rightMoves_neg : ∀ x : PGame, (-x).RightMoves = x.LeftMoves
| ⟨_, _, _, _⟩ => rfl
/-- Turns a right move for `x` into a left move for `-x` and vice versa.
Even though these types are the same (not definitionally so), this is the preferred way to convert
between them. -/
def toLeftMovesNeg {x : PGame} : x.RightMoves ≃ (-x).LeftMoves :=
Equiv.cast (leftMoves_neg x).symm
/-- Turns a left move for `x` into a right move for `-x` and vice versa.
Even though these types are the same (not definitionally so), this is the preferred way to convert
between them. -/
def toRightMovesNeg {x : PGame} : x.LeftMoves ≃ (-x).RightMoves :=
Equiv.cast (rightMoves_neg x).symm
theorem moveLeft_neg {x : PGame} (i) : (-x).moveLeft (toLeftMovesNeg i) = -x.moveRight i := by
cases x
rfl
@[simp]
theorem moveLeft_neg' {x : PGame} (i) : (-x).moveLeft i = -x.moveRight (toLeftMovesNeg.symm i) := by
cases x
rfl
theorem moveRight_neg {x : PGame} (i) : (-x).moveRight (toRightMovesNeg i) = -x.moveLeft i := by
cases x
rfl
@[simp]
theorem moveRight_neg' {x : PGame} (i) :
(-x).moveRight i = -x.moveLeft (toRightMovesNeg.symm i) := by
cases x
rfl
theorem moveLeft_neg_symm {x : PGame} (i) :
x.moveLeft (toRightMovesNeg.symm i) = -(-x).moveRight i := by simp
theorem moveLeft_neg_symm' {x : PGame} (i) :
x.moveLeft i = -(-x).moveRight (toRightMovesNeg i) := by simp
theorem moveRight_neg_symm {x : PGame} (i) :
x.moveRight (toLeftMovesNeg.symm i) = -(-x).moveLeft i := by simp
theorem moveRight_neg_symm' {x : PGame} (i) :
x.moveRight i = -(-x).moveLeft (toLeftMovesNeg i) := by simp
/-- If `x` has the same moves as `y`, then `-x` has the same moves as `-y`. -/
def Relabelling.negCongr : ∀ {x y : PGame}, x ≡r y → -x ≡r -y
| ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, ⟨L, R, hL, hR⟩ =>
⟨R, L, fun j => (hR j).negCongr, fun i => (hL i).negCongr⟩
private theorem neg_le_lf_neg_iff : ∀ {x y : PGame.{u}}, (-y ≤ -x ↔ x ≤ y) ∧ (-y ⧏ -x ↔ x ⧏ y)
| mk xl xr xL xR, mk yl yr yL yR => by
simp_rw [neg_def, mk_le_mk, mk_lf_mk, ← neg_def]
constructor
· rw [and_comm]
apply and_congr <;> exact forall_congr' fun _ => neg_le_lf_neg_iff.2
· rw [or_comm]
apply or_congr <;> exact exists_congr fun _ => neg_le_lf_neg_iff.1
termination_by x y => (x, y)
@[simp]
theorem neg_le_neg_iff {x y : PGame} : -y ≤ -x ↔ x ≤ y :=
neg_le_lf_neg_iff.1
@[simp]
theorem neg_lf_neg_iff {x y : PGame} : -y ⧏ -x ↔ x ⧏ y :=
neg_le_lf_neg_iff.2
@[simp]
theorem neg_lt_neg_iff {x y : PGame} : -y < -x ↔ x < y := by
rw [lt_iff_le_and_lf, lt_iff_le_and_lf, neg_le_neg_iff, neg_lf_neg_iff]
@[simp]
theorem neg_equiv_neg_iff {x y : PGame} : (-x ≈ -y) ↔ (x ≈ y) := by
show Equiv (-x) (-y) ↔ Equiv x y
rw [Equiv, Equiv, neg_le_neg_iff, neg_le_neg_iff, and_comm]
@[simp]
theorem neg_fuzzy_neg_iff {x y : PGame} : -x ‖ -y ↔ x ‖ y := by
rw [Fuzzy, Fuzzy, neg_lf_neg_iff, neg_lf_neg_iff, and_comm]
theorem neg_le_iff {x y : PGame} : -y ≤ x ↔ -x ≤ y := by rw [← neg_neg x, neg_le_neg_iff, neg_neg]
theorem neg_lf_iff {x y : PGame} : -y ⧏ x ↔ -x ⧏ y := by rw [← neg_neg x, neg_lf_neg_iff, neg_neg]
theorem neg_lt_iff {x y : PGame} : -y < x ↔ -x < y := by rw [← neg_neg x, neg_lt_neg_iff, neg_neg]
theorem neg_equiv_iff {x y : PGame} : (-x ≈ y) ↔ (x ≈ -y) := by
rw [← neg_neg y, neg_equiv_neg_iff, neg_neg]
theorem neg_fuzzy_iff {x y : PGame} : -x ‖ y ↔ x ‖ -y := by
rw [← neg_neg y, neg_fuzzy_neg_iff, neg_neg]
theorem le_neg_iff {x y : PGame} : y ≤ -x ↔ x ≤ -y := by rw [← neg_neg x, neg_le_neg_iff, neg_neg]
theorem lf_neg_iff {x y : PGame} : y ⧏ -x ↔ x ⧏ -y := by rw [← neg_neg x, neg_lf_neg_iff, neg_neg]
theorem lt_neg_iff {x y : PGame} : y < -x ↔ x < -y := by rw [← neg_neg x, neg_lt_neg_iff, neg_neg]
@[simp]
theorem neg_le_zero_iff {x : PGame} : -x ≤ 0 ↔ 0 ≤ x := by rw [neg_le_iff, neg_zero]
@[simp]
theorem zero_le_neg_iff {x : PGame} : 0 ≤ -x ↔ x ≤ 0 := by rw [le_neg_iff, neg_zero]
@[simp]
theorem neg_lf_zero_iff {x : PGame} : -x ⧏ 0 ↔ 0 ⧏ x := by rw [neg_lf_iff, neg_zero]
@[simp]
theorem zero_lf_neg_iff {x : PGame} : 0 ⧏ -x ↔ x ⧏ 0 := by rw [lf_neg_iff, neg_zero]
@[simp]
theorem neg_lt_zero_iff {x : PGame} : -x < 0 ↔ 0 < x := by rw [neg_lt_iff, neg_zero]
@[simp]
theorem zero_lt_neg_iff {x : PGame} : 0 < -x ↔ x < 0 := by rw [lt_neg_iff, neg_zero]
@[simp]
theorem neg_equiv_zero_iff {x : PGame} : (-x ≈ 0) ↔ (x ≈ 0) := by rw [neg_equiv_iff, neg_zero]
@[simp]
theorem neg_fuzzy_zero_iff {x : PGame} : -x ‖ 0 ↔ x ‖ 0 := by rw [neg_fuzzy_iff, neg_zero]
@[simp]
theorem zero_equiv_neg_iff {x : PGame} : (0 ≈ -x) ↔ (0 ≈ x) := by rw [← neg_equiv_iff, neg_zero]
@[simp]
theorem zero_fuzzy_neg_iff {x : PGame} : 0 ‖ -x ↔ 0 ‖ x := by rw [← neg_fuzzy_iff, neg_zero]
/-! ### Addition and subtraction -/
/-- The sum of `x = {xL | xR}` and `y = {yL | yR}` is `{xL + y, x + yL | xR + y, x + yR}`. -/
instance : Add PGame.{u} :=
⟨fun x y => by
induction' x with xl xr _ _ IHxl IHxr generalizing y
induction' y with yl yr yL yR IHyl IHyr
have y := mk yl yr yL yR
refine ⟨xl ⊕ yl, xr ⊕ yr, Sum.rec ?_ ?_, Sum.rec ?_ ?_⟩
· exact fun i => IHxl i y
· exact IHyl
· exact fun i => IHxr i y
· exact IHyr⟩
/-- The pre-game `((0+1)+⋯)+1`. -/
instance : NatCast PGame :=
⟨Nat.unaryCast⟩
@[simp]
protected theorem nat_succ (n : ℕ) : ((n + 1 : ℕ) : PGame) = n + 1 :=
rfl
instance isEmpty_leftMoves_add (x y : PGame.{u}) [IsEmpty x.LeftMoves] [IsEmpty y.LeftMoves] :
IsEmpty (x + y).LeftMoves := by
cases x
cases y
apply isEmpty_sum.2 ⟨_, _⟩
assumption'
instance isEmpty_rightMoves_add (x y : PGame.{u}) [IsEmpty x.RightMoves] [IsEmpty y.RightMoves] :
IsEmpty (x + y).RightMoves := by
cases x
cases y
apply isEmpty_sum.2 ⟨_, _⟩
assumption'
/-- `x + 0` has exactly the same moves as `x`. -/
def addZeroRelabelling : ∀ x : PGame.{u}, x + 0 ≡r x
| ⟨xl, xr, xL, xR⟩ => by
refine ⟨Equiv.sumEmpty xl PEmpty, Equiv.sumEmpty xr PEmpty, ?_, ?_⟩ <;> rintro (⟨i⟩ | ⟨⟨⟩⟩) <;>
apply addZeroRelabelling
termination_by x => x
/-- `x + 0` is equivalent to `x`. -/
theorem add_zero_equiv (x : PGame.{u}) : x + 0 ≈ x :=
(addZeroRelabelling x).equiv
/-- `0 + x` has exactly the same moves as `x`. -/
def zeroAddRelabelling : ∀ x : PGame.{u}, 0 + x ≡r x
| ⟨xl, xr, xL, xR⟩ => by
refine ⟨Equiv.emptySum PEmpty xl, Equiv.emptySum PEmpty xr, ?_, ?_⟩ <;> rintro (⟨⟨⟩⟩ | ⟨i⟩) <;>
apply zeroAddRelabelling
/-- `0 + x` is equivalent to `x`. -/
theorem zero_add_equiv (x : PGame.{u}) : 0 + x ≈ x :=
(zeroAddRelabelling x).equiv
theorem leftMoves_add : ∀ x y : PGame.{u}, (x + y).LeftMoves = (x.LeftMoves ⊕ y.LeftMoves)
| ⟨_, _, _, _⟩, ⟨_, _, _, _⟩ => rfl
theorem rightMoves_add : ∀ x y : PGame.{u}, (x + y).RightMoves = (x.RightMoves ⊕ y.RightMoves)
| ⟨_, _, _, _⟩, ⟨_, _, _, _⟩ => rfl
/-- Converts a left move for `x` or `y` into a left move for `x + y` and vice versa.
Even though these types are the same (not definitionally so), this is the preferred way to convert
between them. -/
def toLeftMovesAdd {x y : PGame} : x.LeftMoves ⊕ y.LeftMoves ≃ (x + y).LeftMoves :=
Equiv.cast (leftMoves_add x y).symm
/-- Converts a right move for `x` or `y` into a right move for `x + y` and vice versa.
Even though these types are the same (not definitionally so), this is the preferred way to convert
between them. -/
def toRightMovesAdd {x y : PGame} : x.RightMoves ⊕ y.RightMoves ≃ (x + y).RightMoves :=
Equiv.cast (rightMoves_add x y).symm
@[simp]
theorem mk_add_moveLeft_inl {xl xr yl yr} {xL xR yL yR} {i} :
(mk xl xr xL xR + mk yl yr yL yR).moveLeft (Sum.inl i) =
(mk xl xr xL xR).moveLeft i + mk yl yr yL yR :=
rfl
@[simp]
theorem add_moveLeft_inl {x : PGame} (y : PGame) (i) :
(x + y).moveLeft (toLeftMovesAdd (Sum.inl i)) = x.moveLeft i + y := by
cases x
cases y
rfl
@[simp]
theorem mk_add_moveRight_inl {xl xr yl yr} {xL xR yL yR} {i} :
(mk xl xr xL xR + mk yl yr yL yR).moveRight (Sum.inl i) =
(mk xl xr xL xR).moveRight i + mk yl yr yL yR :=
rfl
@[simp]
theorem add_moveRight_inl {x : PGame} (y : PGame) (i) :
(x + y).moveRight (toRightMovesAdd (Sum.inl i)) = x.moveRight i + y := by
cases x
cases y
rfl
@[simp]
theorem mk_add_moveLeft_inr {xl xr yl yr} {xL xR yL yR} {i} :
(mk xl xr xL xR + mk yl yr yL yR).moveLeft (Sum.inr i) =
mk xl xr xL xR + (mk yl yr yL yR).moveLeft i :=
rfl
@[simp]
theorem add_moveLeft_inr (x : PGame) {y : PGame} (i) :
(x + y).moveLeft (toLeftMovesAdd (Sum.inr i)) = x + y.moveLeft i := by
cases x
cases y
rfl
@[simp]
theorem mk_add_moveRight_inr {xl xr yl yr} {xL xR yL yR} {i} :
(mk xl xr xL xR + mk yl yr yL yR).moveRight (Sum.inr i) =
mk xl xr xL xR + (mk yl yr yL yR).moveRight i :=
rfl
@[simp]
theorem add_moveRight_inr (x : PGame) {y : PGame} (i) :
(x + y).moveRight (toRightMovesAdd (Sum.inr i)) = x + y.moveRight i := by
cases x
cases y
rfl
theorem leftMoves_add_cases {x y : PGame} (k) {P : (x + y).LeftMoves → Prop}
(hl : ∀ i, P <| toLeftMovesAdd (Sum.inl i)) (hr : ∀ i, P <| toLeftMovesAdd (Sum.inr i)) :
P k := by
rw [← toLeftMovesAdd.apply_symm_apply k]
cases' toLeftMovesAdd.symm k with i i
· exact hl i
· exact hr i
theorem rightMoves_add_cases {x y : PGame} (k) {P : (x + y).RightMoves → Prop}
(hl : ∀ j, P <| toRightMovesAdd (Sum.inl j)) (hr : ∀ j, P <| toRightMovesAdd (Sum.inr j)) :
P k := by
rw [← toRightMovesAdd.apply_symm_apply k]
cases' toRightMovesAdd.symm k with i i
· exact hl i
· exact hr i
instance isEmpty_nat_rightMoves : ∀ n : ℕ, IsEmpty (RightMoves n)
| 0 => inferInstanceAs (IsEmpty PEmpty)
| n + 1 => by
haveI := isEmpty_nat_rightMoves n
rw [PGame.nat_succ, rightMoves_add]
infer_instance
/-- If `w` has the same moves as `x` and `y` has the same moves as `z`,
then `w + y` has the same moves as `x + z`. -/
def Relabelling.addCongr : ∀ {w x y z : PGame.{u}}, w ≡r x → y ≡r z → w + y ≡r x + z
| ⟨wl, wr, wL, wR⟩, ⟨xl, xr, xL, xR⟩, ⟨yl, yr, yL, yR⟩, ⟨zl, zr, zL, zR⟩, ⟨L₁, R₁, hL₁, hR₁⟩,
⟨L₂, R₂, hL₂, hR₂⟩ => by
let Hwx : ⟨wl, wr, wL, wR⟩ ≡r ⟨xl, xr, xL, xR⟩ := ⟨L₁, R₁, hL₁, hR₁⟩
let Hyz : ⟨yl, yr, yL, yR⟩ ≡r ⟨zl, zr, zL, zR⟩ := ⟨L₂, R₂, hL₂, hR₂⟩
refine ⟨Equiv.sumCongr L₁ L₂, Equiv.sumCongr R₁ R₂, ?_, ?_⟩ <;> rintro (i | j)
· exact (hL₁ i).addCongr Hyz
· exact Hwx.addCongr (hL₂ j)
· exact (hR₁ i).addCongr Hyz
· exact Hwx.addCongr (hR₂ j)
termination_by _ x _ z => (x, z)
instance : Sub PGame :=
⟨fun x y => x + -y⟩
@[simp]
theorem sub_zero (x : PGame) : x - 0 = x + 0 :=
show x + -0 = x + 0 by rw [neg_zero]
/-- If `w` has the same moves as `x` and `y` has the same moves as `z`,
then `w - y` has the same moves as `x - z`. -/
def Relabelling.subCongr {w x y z : PGame} (h₁ : w ≡r x) (h₂ : y ≡r z) : w - y ≡r x - z :=
h₁.addCongr h₂.negCongr
/-- `-(x + y)` has exactly the same moves as `-x + -y`. -/
def negAddRelabelling : ∀ x y : PGame, -(x + y) ≡r -x + -y
| ⟨xl, xr, xL, xR⟩, ⟨yl, yr, yL, yR⟩ => by
refine ⟨Equiv.refl _, Equiv.refl _, ?_, ?_⟩
all_goals
exact fun j =>
Sum.casesOn j (fun j => negAddRelabelling _ _) fun j =>
negAddRelabelling ⟨xl, xr, xL, xR⟩ _
termination_by x y => (x, y)
theorem neg_add_le {x y : PGame} : -(x + y) ≤ -x + -y :=
(negAddRelabelling x y).le
/-- `x + y` has exactly the same moves as `y + x`. -/
def addCommRelabelling : ∀ x y : PGame.{u}, x + y ≡r y + x
| mk xl xr xL xR, mk yl yr yL yR => by
refine ⟨Equiv.sumComm _ _, Equiv.sumComm _ _, ?_, ?_⟩ <;> rintro (_ | _) <;>
· dsimp
apply addCommRelabelling
termination_by x y => (x, y)
theorem add_comm_le {x y : PGame} : x + y ≤ y + x :=
(addCommRelabelling x y).le
theorem add_comm_equiv {x y : PGame} : x + y ≈ y + x :=
(addCommRelabelling x y).equiv
/-- `(x + y) + z` has exactly the same moves as `x + (y + z)`. -/
def addAssocRelabelling : ∀ x y z : PGame.{u}, x + y + z ≡r x + (y + z)
| ⟨xl, xr, xL, xR⟩, ⟨yl, yr, yL, yR⟩, ⟨zl, zr, zL, zR⟩ => by
refine ⟨Equiv.sumAssoc _ _ _, Equiv.sumAssoc _ _ _, ?_, ?_⟩
· rintro (⟨i | i⟩ | i)
· apply addAssocRelabelling
· apply addAssocRelabelling ⟨xl, xr, xL, xR⟩ (yL i)
· apply addAssocRelabelling ⟨xl, xr, xL, xR⟩ ⟨yl, yr, yL, yR⟩ (zL i)
· rintro (⟨i | i⟩ | i)
· apply addAssocRelabelling
· apply addAssocRelabelling ⟨xl, xr, xL, xR⟩ (yR i)
· apply addAssocRelabelling ⟨xl, xr, xL, xR⟩ ⟨yl, yr, yL, yR⟩ (zR i)
termination_by x y z => (x, y, z)
theorem add_assoc_equiv {x y z : PGame} : x + y + z ≈ x + (y + z) :=
(addAssocRelabelling x y z).equiv
theorem add_left_neg_le_zero : ∀ x : PGame, -x + x ≤ 0
| ⟨xl, xr, xL, xR⟩ =>
le_zero.2 fun i => by
cases' i with i i
· -- If Left played in -x, Right responds with the same move in x.
refine ⟨@toRightMovesAdd _ ⟨_, _, _, _⟩ (Sum.inr i), ?_⟩
convert @add_left_neg_le_zero (xR i)
apply add_moveRight_inr
· -- If Left in x, Right responds with the same move in -x.
dsimp
refine ⟨@toRightMovesAdd ⟨_, _, _, _⟩ _ (Sum.inl i), ?_⟩
convert @add_left_neg_le_zero (xL i)
apply add_moveRight_inl
theorem zero_le_add_left_neg (x : PGame) : 0 ≤ -x + x := by
rw [← neg_le_neg_iff, neg_zero]
exact neg_add_le.trans (add_left_neg_le_zero _)
theorem add_left_neg_equiv (x : PGame) : -x + x ≈ 0 :=
⟨add_left_neg_le_zero x, zero_le_add_left_neg x⟩
theorem add_right_neg_le_zero (x : PGame) : x + -x ≤ 0 :=
add_comm_le.trans (add_left_neg_le_zero x)
theorem zero_le_add_right_neg (x : PGame) : 0 ≤ x + -x :=
(zero_le_add_left_neg x).trans add_comm_le
theorem add_right_neg_equiv (x : PGame) : x + -x ≈ 0 :=
⟨add_right_neg_le_zero x, zero_le_add_right_neg x⟩
theorem sub_self_equiv : ∀ (x : PGame), x - x ≈ 0 :=
add_right_neg_equiv
private theorem add_le_add_right' : ∀ {x y z : PGame}, x ≤ y → x + z ≤ y + z
| mk xl xr xL xR, mk yl yr yL yR, mk zl zr zL zR => fun h => by
refine le_def.2 ⟨fun i => ?_, fun i => ?_⟩ <;> cases' i with i i
· rw [le_def] at h
cases' h with h_left h_right
rcases h_left i with (⟨i', ih⟩ | ⟨j, jh⟩)
· exact Or.inl ⟨toLeftMovesAdd (Sum.inl i'), add_le_add_right' ih⟩
· refine Or.inr ⟨toRightMovesAdd (Sum.inl j), ?_⟩
convert add_le_add_right' jh
apply add_moveRight_inl
· exact Or.inl ⟨@toLeftMovesAdd _ ⟨_, _, _, _⟩ (Sum.inr i), add_le_add_right' h⟩
· rw [le_def] at h
rcases h.right i with (⟨i, ih⟩ | ⟨j', jh⟩)
· refine Or.inl ⟨toLeftMovesAdd (Sum.inl i), ?_⟩
convert add_le_add_right' ih
apply add_moveLeft_inl
· exact Or.inr ⟨toRightMovesAdd (Sum.inl j'), add_le_add_right' jh⟩
· exact
Or.inr ⟨@toRightMovesAdd _ ⟨_, _, _, _⟩ (Sum.inr i), add_le_add_right' h⟩
termination_by x y z => (x, y, z)
instance covariantClass_swap_add_le : CovariantClass PGame PGame (swap (· + ·)) (· ≤ ·) :=
⟨fun _ _ _ => add_le_add_right'⟩
instance covariantClass_add_le : CovariantClass PGame PGame (· + ·) (· ≤ ·) :=
⟨fun x _ _ h => (add_comm_le.trans (add_le_add_right h x)).trans add_comm_le⟩
theorem add_lf_add_right {y z : PGame} (h : y ⧏ z) (x) : y + x ⧏ z + x :=
suffices z + x ≤ y + x → z ≤ y by
rw [← PGame.not_le] at h ⊢
exact mt this h
fun w =>
calc
z ≤ z + 0 := (addZeroRelabelling _).symm.le
_ ≤ z + (x + -x) := add_le_add_left (zero_le_add_right_neg x) _
_ ≤ z + x + -x := (addAssocRelabelling _ _ _).symm.le
_ ≤ y + x + -x := add_le_add_right w _
_ ≤ y + (x + -x) := (addAssocRelabelling _ _ _).le
_ ≤ y + 0 := add_le_add_left (add_right_neg_le_zero x) _
_ ≤ y := (addZeroRelabelling _).le
theorem add_lf_add_left {y z : PGame} (h : y ⧏ z) (x) : x + y ⧏ x + z := by
rw [lf_congr add_comm_equiv add_comm_equiv]
apply add_lf_add_right h
instance covariantClass_swap_add_lt : CovariantClass PGame PGame (swap (· + ·)) (· < ·) :=
⟨fun x _ _ h => ⟨add_le_add_right h.1 x, add_lf_add_right h.2 x⟩⟩
instance covariantClass_add_lt : CovariantClass PGame PGame (· + ·) (· < ·) :=
⟨fun x _ _ h => ⟨add_le_add_left h.1 x, add_lf_add_left h.2 x⟩⟩
theorem add_lf_add_of_lf_of_le {w x y z : PGame} (hwx : w ⧏ x) (hyz : y ≤ z) : w + y ⧏ x + z :=
lf_of_lf_of_le (add_lf_add_right hwx y) (add_le_add_left hyz x)
theorem add_lf_add_of_le_of_lf {w x y z : PGame} (hwx : w ≤ x) (hyz : y ⧏ z) : w + y ⧏ x + z :=
lf_of_le_of_lf (add_le_add_right hwx y) (add_lf_add_left hyz x)
theorem add_congr {w x y z : PGame} (h₁ : w ≈ x) (h₂ : y ≈ z) : w + y ≈ x + z :=
⟨(add_le_add_left h₂.1 w).trans (add_le_add_right h₁.1 z),
(add_le_add_left h₂.2 x).trans (add_le_add_right h₁.2 y)⟩
theorem add_congr_left {x y z : PGame} (h : x ≈ y) : x + z ≈ y + z :=
add_congr h equiv_rfl
theorem add_congr_right {x y z : PGame} : (y ≈ z) → (x + y ≈ x + z) :=
add_congr equiv_rfl
theorem sub_congr {w x y z : PGame} (h₁ : w ≈ x) (h₂ : y ≈ z) : w - y ≈ x - z :=
add_congr h₁ (neg_equiv_neg_iff.2 h₂)
theorem sub_congr_left {x y z : PGame} (h : x ≈ y) : x - z ≈ y - z :=
sub_congr h equiv_rfl
theorem sub_congr_right {x y z : PGame} : (y ≈ z) → (x - y ≈ x - z) :=
sub_congr equiv_rfl
theorem le_iff_sub_nonneg {x y : PGame} : x ≤ y ↔ 0 ≤ y - x :=
⟨fun h => (zero_le_add_right_neg x).trans (add_le_add_right h _), fun h =>
calc
x ≤ 0 + x := (zeroAddRelabelling x).symm.le
_ ≤ y - x + x := add_le_add_right h _
_ ≤ y + (-x + x) := (addAssocRelabelling _ _ _).le
_ ≤ y + 0 := add_le_add_left (add_left_neg_le_zero x) _
_ ≤ y := (addZeroRelabelling y).le
⟩
theorem lf_iff_sub_zero_lf {x y : PGame} : x ⧏ y ↔ 0 ⧏ y - x :=
⟨fun h => (zero_le_add_right_neg x).trans_lf (add_lf_add_right h _), fun h =>
calc
x ≤ 0 + x := (zeroAddRelabelling x).symm.le
_ ⧏ y - x + x := add_lf_add_right h _
_ ≤ y + (-x + x) := (addAssocRelabelling _ _ _).le
_ ≤ y + 0 := add_le_add_left (add_left_neg_le_zero x) _
_ ≤ y := (addZeroRelabelling y).le
⟩
theorem lt_iff_sub_pos {x y : PGame} : x < y ↔ 0 < y - x :=
⟨fun h => lt_of_le_of_lt (zero_le_add_right_neg x) (add_lt_add_right h _), fun h =>
calc
x ≤ 0 + x := (zeroAddRelabelling x).symm.le
_ < y - x + x := add_lt_add_right h _
_ ≤ y + (-x + x) := (addAssocRelabelling _ _ _).le
_ ≤ y + 0 := add_le_add_left (add_left_neg_le_zero x) _
_ ≤ y := (addZeroRelabelling y).le
⟩
/-! ### Inserting an option -/
/-- The pregame constructed by inserting `x'` as a new left option into x. -/
def insertLeft (x x' : PGame.{u}) : PGame :=
match x with
| mk xl xr xL xR => mk (xl ⊕ PUnit) xr (Sum.elim xL fun _ => x') xR
/-- A new left option cannot hurt Left. -/
lemma le_insertLeft (x x' : PGame) : x ≤ insertLeft x x' := by
rw [le_def]
constructor
· intro i
left
rcases x with ⟨xl, xr, xL, xR⟩
simp only [insertLeft, leftMoves_mk, moveLeft_mk, Sum.exists, Sum.elim_inl]
left
use i
· intro j
right
rcases x with ⟨xl, xr, xL, xR⟩
simp only [rightMoves_mk, moveRight_mk, insertLeft]
use j
/-- Adding a gift horse left option does not change the value of `x`. A gift horse left option is
a game `x'` with `x' ⧏ x`. It is called "gift horse" because it seems like Left has gotten the
"gift" of a new option, but actually the value of the game did not change. -/
lemma insertLeft_equiv_of_lf {x x' : PGame} (h : x' ⧏ x) : insertLeft x x' ≈ x := by
rw [equiv_def]
constructor
· rw [le_def]
constructor
· intro i
rcases x with ⟨xl, xr, xL, xR⟩
simp only [insertLeft, leftMoves_mk, moveLeft_mk] at i ⊢
rcases i with i | _
· simp only [Sum.elim_inl]
left
use i
· simp only [Sum.elim_inr]
rw [lf_iff_exists_le] at h
simp only [leftMoves_mk, moveLeft_mk] at h
exact h
· intro j
right
rcases x with ⟨xl, xr, xL, xR⟩
simp only [insertLeft, rightMoves_mk, moveRight_mk]
use j
· apply le_insertLeft
/-- The pregame constructed by inserting `x'` as a new right option into x. -/
def insertRight (x x' : PGame.{u}) : PGame :=
match x with
| mk xl xr xL xR => mk xl (xr ⊕ PUnit) xL (Sum.elim xR fun _ => x')
theorem neg_insertRight_neg (x x' : PGame.{u}) : (-x).insertRight (-x') = -x.insertLeft x' := by
cases x
cases x'
dsimp [insertRight, insertLeft]
congr! with (i | j)
theorem neg_insertLeft_neg (x x' : PGame.{u}) : (-x).insertLeft (-x') = -x.insertRight x' := by
rw [← neg_eq_iff_eq_neg, ← neg_insertRight_neg, neg_neg, neg_neg]
/-- A new right option cannot hurt Right. -/
lemma insertRight_le (x x' : PGame) : insertRight x x' ≤ x := by
rw [← neg_le_neg_iff, ← neg_insertLeft_neg]
exact le_insertLeft _ _
/-- Adding a gift horse right option does not change the value of `x`. A gift horse right option is
a game `x'` with `x ⧏ x'`. It is called "gift horse" because it seems like Right has gotten the
"gift" of a new option, but actually the value of the game did not change. -/
lemma insertRight_equiv_of_lf {x x' : PGame} (h : x ⧏ x') : insertRight x x' ≈ x := by
rw [← neg_equiv_neg_iff, ← neg_insertLeft_neg]
exact insertLeft_equiv_of_lf (neg_lf_neg_iff.mpr h)
/-- Inserting on the left and right commutes. -/
theorem insertRight_insertLeft {x x' x'' : PGame} :
insertRight (insertLeft x x') x'' = insertLeft (insertRight x x'') x' := by
cases x; cases x'; cases x''
dsimp [insertLeft, insertRight]
/-! ### Special pre-games -/
/-- The pre-game `star`, which is fuzzy with zero. -/
def star : PGame.{u} :=
⟨PUnit, PUnit, fun _ => 0, fun _ => 0⟩
@[simp]
theorem star_leftMoves : star.LeftMoves = PUnit :=
rfl
@[simp]
theorem star_rightMoves : star.RightMoves = PUnit :=
rfl
@[simp]
theorem star_moveLeft (x) : star.moveLeft x = 0 :=
rfl
@[simp]
theorem star_moveRight (x) : star.moveRight x = 0 :=
rfl
instance uniqueStarLeftMoves : Unique star.LeftMoves :=
PUnit.unique
instance uniqueStarRightMoves : Unique star.RightMoves :=
PUnit.unique
theorem star_fuzzy_zero : star ‖ 0 :=
⟨by
rw [lf_zero]
use default
rintro ⟨⟩,
by
rw [zero_lf]
use default
rintro ⟨⟩⟩
@[simp]
theorem neg_star : -star = star := by simp [star]
@[simp]
protected theorem zero_lt_one : (0 : PGame) < 1 :=
lt_of_le_of_lf (zero_le_of_isEmpty_rightMoves 1) (zero_lf_le.2 ⟨default, le_rfl⟩)
instance : ZeroLEOneClass PGame :=
⟨PGame.zero_lt_one.le⟩
@[simp]
theorem zero_lf_one : (0 : PGame) ⧏ 1 :=
PGame.zero_lt_one.lf
end PGame
end SetTheory
|
SetTheory\Game\Short.lean | /-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Data.Fintype.Basic
import Mathlib.SetTheory.Cardinal.Cofinality
import Mathlib.SetTheory.Game.Birthday
/-!
# Short games
A combinatorial game is `Short` [Conway, ch.9][conway2001] if it has only finitely many positions.
In particular, this means there is a finite set of moves at every point.
We prove that the order relations `≤` and `<`, and the equivalence relation `≈`, are decidable on
short games, although unfortunately in practice `decide` doesn't seem to be able to
prove anything using these instances.
-/
-- Porting note: The local instances `moveLeftShort'` and `fintypeLeft` (and resp. `Right`)
-- trigger this error.
set_option synthInstance.checkSynthOrder false
universe u
namespace SetTheory
open scoped PGame
namespace PGame
/-- A short game is a game with a finite set of moves at every turn. -/
inductive Short : PGame.{u} → Type (u + 1)
| mk :
∀ {α β : Type u} {L : α → PGame.{u}} {R : β → PGame.{u}} (_ : ∀ i : α, Short (L i))
(_ : ∀ j : β, Short (R j)) [Fintype α] [Fintype β], Short ⟨α, β, L, R⟩
-- Porting note: Added `simpNF` exception. It's unclear what puts `eq_iff_true_of_subsingleton` into
-- the simp set. A minimal reproduction of the simpNF error needs to import transitively at least
-- `Mathlib.Logic.Unique`.
--
-- The simplifier can already prove this using `eq_iff_true_of_subsingleton`
attribute [nolint simpNF] Short.mk.injEq
instance subsingleton_short (x : PGame) : Subsingleton (Short x) := by
induction x with
| mk xl xr xL xR =>
constructor
intro a b
cases a; cases b
congr!
-- Porting note: We use `induction` to prove `subsingleton_short` instead of recursion.
-- A proof using recursion generates a harder `decreasing_by` goal than in Lean 3 for some reason:
attribute [-instance] subsingleton_short in
theorem subsingleton_short_example : ∀ x : PGame, Subsingleton (Short x)
| mk xl xr xL xR =>
⟨fun a b => by
cases a; cases b
congr!
· funext x
apply @Subsingleton.elim _ (subsingleton_short_example (xL x))
-- Decreasing goal in Lean 4 is `Subsequent (xL x) (mk α β L R)`
-- where `α`, `β`, `L`, and `R` are fresh hypotheses only propositionally
-- equal to `xl`, `xr`, `xL`, and `xR`.
-- (In Lean 3 it was `(mk xl xr xL xR)` instead.)
· funext x
apply @Subsingleton.elim _ (subsingleton_short_example (xR x))⟩
termination_by x => x
-- We need to unify a bunch of hypotheses before `pgame_wf_tac` can work.
decreasing_by all_goals {
subst_vars
simp only [mk.injEq, heq_eq_eq, true_and] at *
casesm* _ ∧ _
subst_vars
pgame_wf_tac
}
/-- A synonym for `Short.mk` that specifies the pgame in an implicit argument. -/
def Short.mk' {x : PGame} [Fintype x.LeftMoves] [Fintype x.RightMoves]
(sL : ∀ i : x.LeftMoves, Short (x.moveLeft i))
(sR : ∀ j : x.RightMoves, Short (x.moveRight j)) : Short x := by
-- Porting note: Old proof relied on `unfreezingI`, which doesn't exist in Lean 4.
convert Short.mk sL sR
cases x
dsimp
attribute [class] Short
/-- Extracting the `Fintype` instance for the indexing type for Left's moves in a short game.
This is an unindexed typeclass, so it can't be made a global instance.
-/
def fintypeLeft {α β : Type u} {L : α → PGame.{u}} {R : β → PGame.{u}} [S : Short ⟨α, β, L, R⟩] :
Fintype α := by cases' S with _ _ _ _ _ _ F _; exact F
attribute [local instance] fintypeLeft
instance fintypeLeftMoves (x : PGame) [S : Short x] : Fintype x.LeftMoves := by
cases S; assumption
/-- Extracting the `Fintype` instance for the indexing type for Right's moves in a short game.
This is an unindexed typeclass, so it can't be made a global instance.
-/
def fintypeRight {α β : Type u} {L : α → PGame.{u}} {R : β → PGame.{u}} [S : Short ⟨α, β, L, R⟩] :
Fintype β := by cases' S with _ _ _ _ _ _ _ F; exact F
attribute [local instance] fintypeRight
instance fintypeRightMoves (x : PGame) [S : Short x] : Fintype x.RightMoves := by
cases S; assumption
instance moveLeftShort (x : PGame) [S : Short x] (i : x.LeftMoves) : Short (x.moveLeft i) := by
cases' S with _ _ _ _ L _ _ _; apply L
/-- Extracting the `Short` instance for a move by Left.
This would be a dangerous instance potentially introducing new metavariables
in typeclass search, so we only make it an instance locally.
-/
def moveLeftShort' {xl xr} (xL xR) [S : Short (mk xl xr xL xR)] (i : xl) : Short (xL i) := by
cases' S with _ _ _ _ L _ _ _; apply L
attribute [local instance] moveLeftShort'
instance moveRightShort (x : PGame) [S : Short x] (j : x.RightMoves) : Short (x.moveRight j) := by
cases' S with _ _ _ _ _ R _ _; apply R
/-- Extracting the `Short` instance for a move by Right.
This would be a dangerous instance potentially introducing new metavariables
in typeclass search, so we only make it an instance locally.
-/
def moveRightShort' {xl xr} (xL xR) [S : Short (mk xl xr xL xR)] (j : xr) : Short (xR j) := by
cases' S with _ _ _ _ _ R _ _; apply R
attribute [local instance] moveRightShort'
theorem short_birthday (x : PGame.{u}) : [Short x] → x.birthday < Ordinal.omega := by
-- Porting note: Again `induction` is used instead of `pgame_wf_tac`
induction x with
| mk xl xr xL xR ihl ihr =>
intro hs
rcases hs with ⟨sL, sR⟩
rw [birthday, max_lt_iff]
constructor
all_goals
rw [← Cardinal.ord_aleph0]
refine
Cardinal.lsub_lt_ord_of_isRegular.{u, u} Cardinal.isRegular_aleph0
(Cardinal.lt_aleph0_of_finite _) fun i => ?_
rw [Cardinal.ord_aleph0]
· apply ihl
· apply ihr
/-- This leads to infinite loops if made into an instance. -/
def Short.ofIsEmpty {l r xL xR} [IsEmpty l] [IsEmpty r] : Short (PGame.mk l r xL xR) := by
have : Fintype l := Fintype.ofIsEmpty
have : Fintype r := Fintype.ofIsEmpty
exact Short.mk isEmptyElim isEmptyElim
instance short0 : Short 0 :=
Short.ofIsEmpty
instance short1 : Short 1 :=
Short.mk (fun i => by cases i; infer_instance) fun j => by cases j
/-- Evidence that every `PGame` in a list is `Short`. -/
class inductive ListShort : List PGame.{u} → Type (u + 1)
| nil : ListShort []
-- Porting note: We introduce `cons` as a separate instance because attempting to use
-- `[ListShort tl]` as a constructor argument errors saying that `ListShort tl` is not a class.
-- Is this a bug in `class inductive`?
| cons' {hd : PGame.{u}} {tl : List PGame.{u}} : Short hd → ListShort tl → ListShort (hd::tl)
attribute [instance] ListShort.nil
instance ListShort.cons (hd : PGame.{u}) [short_hd : Short hd]
(tl : List PGame.{u}) [short_tl : ListShort tl] :
ListShort (hd::tl) :=
cons' short_hd short_tl
instance listShortGet :
∀ (L : List PGame.{u}) [ListShort L] (i : Nat) (h : i < List.length L), Short L[i]
| _::_, ListShort.cons' S _, 0, _ => S
| _::tl, ListShort.cons' _ S, n + 1, h =>
@listShortGet tl S n ((add_lt_add_iff_right 1).mp h)
instance shortOfLists : ∀ (L R : List PGame) [ListShort L] [ListShort R], Short (PGame.ofLists L R)
| L, R, _, _ => by
apply Short.mk
· intros; infer_instance
· intros; apply PGame.listShortGet
/-- If `x` is a short game, and `y` is a relabelling of `x`, then `y` is also short. -/
def shortOfRelabelling : ∀ {x y : PGame.{u}}, Relabelling x y → Short x → Short y
| x, y, ⟨L, R, rL, rR⟩, S => by
haveI := Fintype.ofEquiv _ L
haveI := Fintype.ofEquiv _ R
exact
Short.mk'
(fun i => by rw [← L.right_inv i]; apply shortOfRelabelling (rL (L.symm i)) inferInstance)
fun j => by simpa using shortOfRelabelling (rR (R.symm j)) inferInstance
instance shortNeg : ∀ (x : PGame.{u}) [Short x], Short (-x)
| mk xl xr xL xR, _ => by
exact Short.mk (fun i => shortNeg _) fun i => shortNeg _
instance shortAdd : ∀ (x y : PGame.{u}) [Short x] [Short y], Short (x + y)
| mk xl xr xL xR, mk yl yr yL yR, _, _ => by
apply Short.mk
all_goals
rintro ⟨i⟩
· apply shortAdd
· change Short (mk xl xr xL xR + _); apply shortAdd
termination_by x y => (x, y)
instance shortNat : ∀ n : ℕ, Short n
| 0 => PGame.short0
| n + 1 => @PGame.shortAdd _ _ (shortNat n) PGame.short1
instance shortOfNat (n : ℕ) [Nat.AtLeastTwo n] : Short (no_index (OfNat.ofNat n)) := shortNat n
-- Porting note: `bit0` and `bit1` are deprecated so these instances can probably be removed.
set_option linter.deprecated false in
instance shortBit0 (x : PGame.{u}) [Short x] : Short (x + x) := by infer_instance
set_option linter.deprecated false in
instance shortBit1 (x : PGame.{u}) [Short x] : Short ((x + x) + 1) := shortAdd _ _
/-- Auxiliary construction of decidability instances.
We build `Decidable (x ≤ y)` and `Decidable (x ⧏ y)` in a simultaneous induction.
Instances for the two projections separately are provided below.
-/
def leLFDecidable : ∀ (x y : PGame.{u}) [Short x] [Short y], Decidable (x ≤ y) × Decidable (x ⧏ y)
| mk xl xr xL xR, mk yl yr yL yR, shortx, shorty => by
constructor
· refine @decidable_of_iff' _ _ mk_le_mk (id ?_)
apply @And.decidable _ _ ?_ ?_
· apply @Fintype.decidableForallFintype xl _ ?_ _
intro i
apply (leLFDecidable _ _).2
· apply @Fintype.decidableForallFintype yr _ ?_ _
intro i
apply (leLFDecidable _ _).2
· refine @decidable_of_iff' _ _ mk_lf_mk (id ?_)
apply @Or.decidable _ _ ?_ ?_
· apply @Fintype.decidableExistsFintype yl _ ?_ _
intro i
apply (leLFDecidable _ _).1
· apply @Fintype.decidableExistsFintype xr _ ?_ _
intro i
apply (leLFDecidable _ _).1
termination_by x y => (x, y)
instance leDecidable (x y : PGame.{u}) [Short x] [Short y] : Decidable (x ≤ y) :=
(leLFDecidable x y).1
instance lfDecidable (x y : PGame.{u}) [Short x] [Short y] : Decidable (x ⧏ y) :=
(leLFDecidable x y).2
instance ltDecidable (x y : PGame.{u}) [Short x] [Short y] : Decidable (x < y) :=
And.decidable
instance equivDecidable (x y : PGame.{u}) [Short x] [Short y] : Decidable (x ≈ y) :=
And.decidable
example : Short 0 := by infer_instance
example : Short 1 := by infer_instance
example : Short 2 := by infer_instance
example : Short (-2) := by infer_instance
example : Short (ofLists [0] [1]) := by infer_instance
example : Short (ofLists [-2, -1] [1]) := by infer_instance
example : Short (0 + 0) := by infer_instance
example : Decidable ((1 : PGame) ≤ 1) := by infer_instance
-- No longer works since definitional reduction of well-founded definitions has been restricted.
-- example : (0 : PGame.{u}) ≤ 0 := by decide
-- example : (1 : PGame.{u}) ≤ 1 := by decide
end PGame
end SetTheory
|
SetTheory\Game\State.lean | /-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.SetTheory.Game.Short
/-!
# Games described via "the state of the board".
We provide a simple mechanism for constructing combinatorial (pre-)games, by describing
"the state of the board", and providing an upper bound on the number of turns remaining.
## Implementation notes
We're very careful to produce a computable definition, so small games can be evaluated
using `decide`. To achieve this, I've had to rely solely on induction on natural numbers:
relying on general well-foundedness seems to be poisonous to computation?
See `SetTheory/Game/Domineering` for an example using this construction.
-/
universe u
namespace SetTheory
namespace PGame
/-- `SetTheory.PGame.State S` describes how to interpret `s : S` as a state of a combinatorial game.
Use `SetTheory.PGame.ofState s` or `SetTheory.Game.ofState s` to construct the game.
`SetTheory.PGame.State.l : S → Finset S` and `SetTheory.PGame.State.r : S → Finset S` describe
the states reachable by a move by Left or Right. `SetTheory.PGame.State.turnBound : S → ℕ`
gives an upper bound on the number of possible turns remaining from this state.
-/
class State (S : Type u) where
turnBound : S → ℕ
l : S → Finset S
r : S → Finset S
left_bound : ∀ {s t : S}, t ∈ l s → turnBound t < turnBound s
right_bound : ∀ {s t : S}, t ∈ r s → turnBound t < turnBound s
open State
variable {S : Type u} [State S]
theorem turnBound_ne_zero_of_left_move {s t : S} (m : t ∈ l s) : turnBound s ≠ 0 := by
intro h
have t := left_bound m
rw [h] at t
exact Nat.not_succ_le_zero _ t
theorem turnBound_ne_zero_of_right_move {s t : S} (m : t ∈ r s) : turnBound s ≠ 0 := by
intro h
have t := right_bound m
rw [h] at t
exact Nat.not_succ_le_zero _ t
theorem turnBound_of_left {s t : S} (m : t ∈ l s) (n : ℕ) (h : turnBound s ≤ n + 1) :
turnBound t ≤ n :=
Nat.le_of_lt_succ (Nat.lt_of_lt_of_le (left_bound m) h)
theorem turnBound_of_right {s t : S} (m : t ∈ r s) (n : ℕ) (h : turnBound s ≤ n + 1) :
turnBound t ≤ n :=
Nat.le_of_lt_succ (Nat.lt_of_lt_of_le (right_bound m) h)
/-- Construct a `PGame` from a state and a (not necessarily optimal) bound on the number of
turns remaining.
-/
def ofStateAux : ∀ (n : ℕ) (s : S), turnBound s ≤ n → PGame
| 0, s, h =>
PGame.mk { t // t ∈ l s } { t // t ∈ r s }
(fun t => by exfalso; exact turnBound_ne_zero_of_left_move t.2 (nonpos_iff_eq_zero.mp h))
fun t => by exfalso; exact turnBound_ne_zero_of_right_move t.2 (nonpos_iff_eq_zero.mp h)
| n + 1, s, h =>
PGame.mk { t // t ∈ l s } { t // t ∈ r s }
(fun t => ofStateAux n t (turnBound_of_left t.2 n h)) fun t =>
ofStateAux n t (turnBound_of_right t.2 n h)
/-- Two different (valid) turn bounds give equivalent games. -/
def ofStateAuxRelabelling :
∀ (s : S) (n m : ℕ) (hn : turnBound s ≤ n) (hm : turnBound s ≤ m),
Relabelling (ofStateAux n s hn) (ofStateAux m s hm)
| s, 0, 0, hn, hm => by
dsimp [PGame.ofStateAux]
fconstructor
· rfl
· rfl
· intro i; dsimp at i; exfalso
exact turnBound_ne_zero_of_left_move i.2 (nonpos_iff_eq_zero.mp hn)
· intro j; dsimp at j; exfalso
exact turnBound_ne_zero_of_right_move j.2 (nonpos_iff_eq_zero.mp hm)
| s, 0, m + 1, hn, hm => by
dsimp [PGame.ofStateAux]
fconstructor
· rfl
· rfl
· intro i; dsimp at i; exfalso
exact turnBound_ne_zero_of_left_move i.2 (nonpos_iff_eq_zero.mp hn)
· intro j; dsimp at j; exfalso
exact turnBound_ne_zero_of_right_move j.2 (nonpos_iff_eq_zero.mp hn)
| s, n + 1, 0, hn, hm => by
dsimp [PGame.ofStateAux]
fconstructor
· rfl
· rfl
· intro i; dsimp at i; exfalso
exact turnBound_ne_zero_of_left_move i.2 (nonpos_iff_eq_zero.mp hm)
· intro j; dsimp at j; exfalso
exact turnBound_ne_zero_of_right_move j.2 (nonpos_iff_eq_zero.mp hm)
| s, n + 1, m + 1, hn, hm => by
dsimp [PGame.ofStateAux]
fconstructor
· rfl
· rfl
· intro i
apply ofStateAuxRelabelling
· intro j
apply ofStateAuxRelabelling
/-- Construct a combinatorial `PGame` from a state. -/
def ofState (s : S) : PGame :=
ofStateAux (turnBound s) s (refl _)
/-- The equivalence between `leftMoves` for a `PGame` constructed using `ofStateAux _ s _`, and
`L s`. -/
def leftMovesOfStateAux (n : ℕ) {s : S} (h : turnBound s ≤ n) :
LeftMoves (ofStateAux n s h) ≃ { t // t ∈ l s } := by induction n <;> rfl
/-- The equivalence between `leftMoves` for a `PGame` constructed using `ofState s`, and `l s`. -/
def leftMovesOfState (s : S) : LeftMoves (ofState s) ≃ { t // t ∈ l s } :=
leftMovesOfStateAux _ _
/-- The equivalence between `rightMoves` for a `PGame` constructed using `ofStateAux _ s _`, and
`R s`. -/
def rightMovesOfStateAux (n : ℕ) {s : S} (h : turnBound s ≤ n) :
RightMoves (ofStateAux n s h) ≃ { t // t ∈ r s } := by induction n <;> rfl
/-- The equivalence between `rightMoves` for a `PGame` constructed using `ofState s`, and
`R s`. -/
def rightMovesOfState (s : S) : RightMoves (ofState s) ≃ { t // t ∈ r s } :=
rightMovesOfStateAux _ _
/-- The relabelling showing `moveLeft` applied to a game constructed using `ofStateAux`
has itself been constructed using `ofStateAux`.
-/
def relabellingMoveLeftAux (n : ℕ) {s : S} (h : turnBound s ≤ n)
(t : LeftMoves (ofStateAux n s h)) :
Relabelling (moveLeft (ofStateAux n s h) t)
(ofStateAux (n - 1) ((leftMovesOfStateAux n h) t : S)
(turnBound_of_left ((leftMovesOfStateAux n h) t).2 (n - 1)
(Nat.le_trans h le_tsub_add))) := by
induction n
· have t' := (leftMovesOfStateAux 0 h) t
exfalso; exact turnBound_ne_zero_of_left_move t'.2 (nonpos_iff_eq_zero.mp h)
· rfl
/-- The relabelling showing `moveLeft` applied to a game constructed using `of`
has itself been constructed using `of`.
-/
def relabellingMoveLeft (s : S) (t : LeftMoves (ofState s)) :
Relabelling (moveLeft (ofState s) t) (ofState ((leftMovesOfState s).toFun t : S)) := by
trans
· apply relabellingMoveLeftAux
· apply ofStateAuxRelabelling
/-- The relabelling showing `moveRight` applied to a game constructed using `ofStateAux`
has itself been constructed using `ofStateAux`.
-/
def relabellingMoveRightAux (n : ℕ) {s : S} (h : turnBound s ≤ n)
(t : RightMoves (ofStateAux n s h)) :
Relabelling (moveRight (ofStateAux n s h) t)
(ofStateAux (n - 1) ((rightMovesOfStateAux n h) t : S)
(turnBound_of_right ((rightMovesOfStateAux n h) t).2 (n - 1)
(Nat.le_trans h le_tsub_add))) := by
induction n
· have t' := (rightMovesOfStateAux 0 h) t
exfalso; exact turnBound_ne_zero_of_right_move t'.2 (nonpos_iff_eq_zero.mp h)
· rfl
/-- The relabelling showing `moveRight` applied to a game constructed using `of`
has itself been constructed using `of`.
-/
def relabellingMoveRight (s : S) (t : RightMoves (ofState s)) :
Relabelling (moveRight (ofState s) t) (ofState ((rightMovesOfState s).toFun t : S)) := by
trans
· apply relabellingMoveRightAux
· apply ofStateAuxRelabelling
instance fintypeLeftMovesOfStateAux (n : ℕ) (s : S) (h : turnBound s ≤ n) :
Fintype (LeftMoves (ofStateAux n s h)) := by
apply Fintype.ofEquiv _ (leftMovesOfStateAux _ _).symm
instance fintypeRightMovesOfStateAux (n : ℕ) (s : S) (h : turnBound s ≤ n) :
Fintype (RightMoves (ofStateAux n s h)) := by
apply Fintype.ofEquiv _ (rightMovesOfStateAux _ _).symm
instance shortOfStateAux : ∀ (n : ℕ) {s : S} (h : turnBound s ≤ n), Short (ofStateAux n s h)
| 0, s, h =>
Short.mk'
(fun i => by
have i := (leftMovesOfStateAux _ _).toFun i
exfalso
exact turnBound_ne_zero_of_left_move i.2 (nonpos_iff_eq_zero.mp h))
fun j => by
have j := (rightMovesOfStateAux _ _).toFun j
exfalso
exact turnBound_ne_zero_of_right_move j.2 (nonpos_iff_eq_zero.mp h)
| n + 1, s, h =>
Short.mk'
(fun i =>
shortOfRelabelling (relabellingMoveLeftAux (n + 1) h i).symm (shortOfStateAux n _))
fun j =>
shortOfRelabelling (relabellingMoveRightAux (n + 1) h j).symm (shortOfStateAux n _)
instance shortOfState (s : S) : Short (ofState s) := by
dsimp [PGame.ofState]
infer_instance
end PGame
namespace Game
/-- Construct a combinatorial `Game` from a state. -/
def ofState {S : Type u} [PGame.State S] (s : S) : Game :=
⟦PGame.ofState s⟧
end Game
end SetTheory
|
SetTheory\Ordinal\Arithmetic.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn, Violeta Hernández Palacios
-/
import Mathlib.SetTheory.Ordinal.Basic
import Mathlib.Data.Nat.SuccPred
import Mathlib.Algebra.GroupWithZero.Divisibility
/-!
# Ordinal arithmetic
Ordinals have an addition (corresponding to disjoint union) that turns them into an additive
monoid, and a multiplication (corresponding to the lexicographic order on the product) that turns
them into a monoid. One can also define correspondingly a subtraction, a division, a successor
function, a power function and a logarithm function.
We also define limit ordinals and prove the basic induction principle on ordinals separating
successor ordinals and limit ordinals, in `limitRecOn`.
## Main definitions and results
* `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that
every element of `o₁` is smaller than every element of `o₂`.
* `o₁ - o₂` is the unique ordinal `o` such that `o₂ + o = o₁`, when `o₂ ≤ o₁`.
* `o₁ * o₂` is the lexicographic order on `o₂ × o₁`.
* `o₁ / o₂` is the ordinal `o` such that `o₁ = o₂ * o + o'` with `o' < o₂`. We also define the
divisibility predicate, and a modulo operation.
* `Order.succ o = o + 1` is the successor of `o`.
* `pred o` if the predecessor of `o`. If `o` is not a successor, we set `pred o = o`.
We discuss the properties of casts of natural numbers of and of `ω` with respect to these
operations.
Some properties of the operations are also used to discuss general tools on ordinals:
* `IsLimit o`: an ordinal is a limit ordinal if it is neither `0` nor a successor.
* `limitRecOn` is the main induction principle of ordinals: if one can prove a property by
induction at successor ordinals and at limit ordinals, then it holds for all ordinals.
* `IsNormal`: a function `f : Ordinal → Ordinal` satisfies `IsNormal` if it is strictly increasing
and order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for
`a < o`.
* `enumOrd`: enumerates an unbounded set of ordinals by the ordinals themselves.
* `sup`, `lsub`: the supremum / least strict upper bound of an indexed family of ordinals in
`Type u`, as an ordinal in `Type u`.
* `bsup`, `blsub`: the supremum / least strict upper bound of a set of ordinals indexed by ordinals
less than a given ordinal `o`.
Various other basic arithmetic results are given in `Principal.lean` instead.
-/
assert_not_exists Field
assert_not_exists Module
noncomputable section
open Function Cardinal Set Equiv Order
open scoped Classical
open Cardinal Ordinal
universe u v w
namespace Ordinal
variable {α : Type*} {β : Type*} {γ : Type*} {r : α → α → Prop} {s : β → β → Prop}
{t : γ → γ → Prop}
/-! ### Further properties of addition on ordinals -/
@[simp]
theorem lift_add (a b : Ordinal.{v}) : lift.{u} (a + b) = lift.{u} a + lift.{u} b :=
Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ =>
Quotient.sound
⟨(RelIso.preimage Equiv.ulift _).trans
(RelIso.sumLexCongr (RelIso.preimage Equiv.ulift _) (RelIso.preimage Equiv.ulift _)).symm⟩
@[simp]
theorem lift_succ (a : Ordinal.{v}) : lift.{u} (succ a) = succ (lift.{u} a) := by
rw [← add_one_eq_succ, lift_add, lift_one]
rfl
instance add_contravariantClass_le : ContravariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· ≤ ·) :=
⟨fun a b c =>
inductionOn a fun α r hr =>
inductionOn b fun β₁ s₁ hs₁ =>
inductionOn c fun β₂ s₂ hs₂ ⟨f⟩ =>
⟨have fl : ∀ a, f (Sum.inl a) = Sum.inl a := fun a => by
simpa only [InitialSeg.trans_apply, InitialSeg.leAdd_apply] using
@InitialSeg.eq _ _ _ _ _
((InitialSeg.leAdd r s₁).trans f) (InitialSeg.leAdd r s₂) a
have : ∀ b, { b' // f (Sum.inr b) = Sum.inr b' } := by
intro b; cases e : f (Sum.inr b)
· rw [← fl] at e
have := f.inj' e
contradiction
· exact ⟨_, rfl⟩
let g (b) := (this b).1
have fr : ∀ b, f (Sum.inr b) = Sum.inr (g b) := fun b => (this b).2
⟨⟨⟨g, fun x y h => by
injection f.inj' (by rw [fr, fr, h] : f (Sum.inr x) = f (Sum.inr y))⟩,
@fun a b => by
-- Porting note:
-- `relEmbedding.coe_fn_to_embedding` & `initial_seg.coe_fn_to_rel_embedding`
-- → `InitialSeg.coe_coe_fn`
simpa only [Sum.lex_inr_inr, fr, InitialSeg.coe_coe_fn, Embedding.coeFn_mk] using
@RelEmbedding.map_rel_iff _ _ _ _ f.toRelEmbedding (Sum.inr a) (Sum.inr b)⟩,
fun a b H => by
rcases f.init (by rw [fr] <;> exact Sum.lex_inr_inr.2 H) with ⟨a' | a', h⟩
· rw [fl] at h
cases h
· rw [fr] at h
exact ⟨a', Sum.inr.inj h⟩⟩⟩⟩
theorem add_left_cancel (a) {b c : Ordinal} : a + b = a + c ↔ b = c := by
simp only [le_antisymm_iff, add_le_add_iff_left]
private theorem add_lt_add_iff_left' (a) {b c : Ordinal} : a + b < a + c ↔ b < c := by
rw [← not_le, ← not_le, add_le_add_iff_left]
instance add_covariantClass_lt : CovariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· < ·) :=
⟨fun a _b _c => (add_lt_add_iff_left' a).2⟩
instance add_contravariantClass_lt : ContravariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· < ·) :=
⟨fun a _b _c => (add_lt_add_iff_left' a).1⟩
instance add_swap_contravariantClass_lt :
ContravariantClass Ordinal.{u} Ordinal.{u} (swap (· + ·)) (· < ·) :=
⟨fun _a _b _c => lt_imp_lt_of_le_imp_le fun h => add_le_add_right h _⟩
theorem add_le_add_iff_right {a b : Ordinal} : ∀ n : ℕ, a + n ≤ b + n ↔ a ≤ b
| 0 => by simp
| n + 1 => by
simp only [natCast_succ, add_succ, add_succ, succ_le_succ_iff, add_le_add_iff_right]
theorem add_right_cancel {a b : Ordinal} (n : ℕ) : a + n = b + n ↔ a = b := by
simp only [le_antisymm_iff, add_le_add_iff_right]
theorem add_eq_zero_iff {a b : Ordinal} : a + b = 0 ↔ a = 0 ∧ b = 0 :=
inductionOn a fun α r _ =>
inductionOn b fun β s _ => by
simp_rw [← type_sum_lex, type_eq_zero_iff_isEmpty]
exact isEmpty_sum
theorem left_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : a = 0 :=
(add_eq_zero_iff.1 h).1
theorem right_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : b = 0 :=
(add_eq_zero_iff.1 h).2
/-! ### The predecessor of an ordinal -/
/-- The ordinal predecessor of `o` is `o'` if `o = succ o'`,
and `o` otherwise. -/
def pred (o : Ordinal) : Ordinal :=
if h : ∃ a, o = succ a then Classical.choose h else o
@[simp]
theorem pred_succ (o) : pred (succ o) = o := by
have h : ∃ a, succ o = succ a := ⟨_, rfl⟩
simpa only [pred, dif_pos h] using (succ_injective <| Classical.choose_spec h).symm
theorem pred_le_self (o) : pred o ≤ o :=
if h : ∃ a, o = succ a then by
let ⟨a, e⟩ := h
rw [e, pred_succ]; exact le_succ a
else by rw [pred, dif_neg h]
theorem pred_eq_iff_not_succ {o} : pred o = o ↔ ¬∃ a, o = succ a :=
⟨fun e ⟨a, e'⟩ => by rw [e', pred_succ] at e; exact (lt_succ a).ne e, fun h => dif_neg h⟩
theorem pred_eq_iff_not_succ' {o} : pred o = o ↔ ∀ a, o ≠ succ a := by
simpa using pred_eq_iff_not_succ
theorem pred_lt_iff_is_succ {o} : pred o < o ↔ ∃ a, o = succ a :=
Iff.trans (by simp only [le_antisymm_iff, pred_le_self, true_and_iff, not_le])
(iff_not_comm.1 pred_eq_iff_not_succ).symm
@[simp]
theorem pred_zero : pred 0 = 0 :=
pred_eq_iff_not_succ'.2 fun a => (succ_ne_zero a).symm
theorem succ_pred_iff_is_succ {o} : succ (pred o) = o ↔ ∃ a, o = succ a :=
⟨fun e => ⟨_, e.symm⟩, fun ⟨a, e⟩ => by simp only [e, pred_succ]⟩
theorem succ_lt_of_not_succ {o b : Ordinal} (h : ¬∃ a, o = succ a) : succ b < o ↔ b < o :=
⟨(lt_succ b).trans, fun l => lt_of_le_of_ne (succ_le_of_lt l) fun e => h ⟨_, e.symm⟩⟩
theorem lt_pred {a b} : a < pred b ↔ succ a < b :=
if h : ∃ a, b = succ a then by
let ⟨c, e⟩ := h
rw [e, pred_succ, succ_lt_succ_iff]
else by simp only [pred, dif_neg h, succ_lt_of_not_succ h]
theorem pred_le {a b} : pred a ≤ b ↔ a ≤ succ b :=
le_iff_le_iff_lt_iff_lt.2 lt_pred
@[simp]
theorem lift_is_succ {o : Ordinal.{v}} : (∃ a, lift.{u} o = succ a) ↔ ∃ a, o = succ a :=
⟨fun ⟨a, h⟩ =>
let ⟨b, e⟩ := lift_down <| show a ≤ lift.{u} o from le_of_lt <| h.symm ▸ lt_succ a
⟨b, (lift_inj.{u,v}).1 <| by rw [h, ← e, lift_succ]⟩,
fun ⟨a, h⟩ => ⟨lift.{u} a, by simp only [h, lift_succ]⟩⟩
@[simp]
theorem lift_pred (o : Ordinal.{v}) : lift.{u} (pred o) = pred (lift.{u} o) :=
if h : ∃ a, o = succ a then by cases' h with a e; simp only [e, pred_succ, lift_succ]
else by rw [pred_eq_iff_not_succ.2 h, pred_eq_iff_not_succ.2 (mt lift_is_succ.1 h)]
/-! ### Limit ordinals -/
/-- A limit ordinal is an ordinal which is not zero and not a successor. -/
def IsLimit (o : Ordinal) : Prop :=
o ≠ 0 ∧ ∀ a < o, succ a < o
theorem IsLimit.isSuccLimit {o} (h : IsLimit o) : IsSuccLimit o := isSuccLimit_iff_succ_lt.mpr h.2
theorem IsLimit.succ_lt {o a : Ordinal} (h : IsLimit o) : a < o → succ a < o :=
h.2 a
theorem isSuccLimit_zero : IsSuccLimit (0 : Ordinal) := isSuccLimit_bot
theorem not_zero_isLimit : ¬IsLimit 0
| ⟨h, _⟩ => h rfl
theorem not_succ_isLimit (o) : ¬IsLimit (succ o)
| ⟨_, h⟩ => lt_irrefl _ (h _ (lt_succ o))
theorem not_succ_of_isLimit {o} (h : IsLimit o) : ¬∃ a, o = succ a
| ⟨a, e⟩ => not_succ_isLimit a (e ▸ h)
theorem succ_lt_of_isLimit {o a : Ordinal} (h : IsLimit o) : succ a < o ↔ a < o :=
⟨(lt_succ a).trans, h.2 _⟩
theorem le_succ_of_isLimit {o} (h : IsLimit o) {a} : o ≤ succ a ↔ o ≤ a :=
le_iff_le_iff_lt_iff_lt.2 <| succ_lt_of_isLimit h
theorem limit_le {o} (h : IsLimit o) {a} : o ≤ a ↔ ∀ x < o, x ≤ a :=
⟨fun h _x l => l.le.trans h, fun H =>
(le_succ_of_isLimit h).1 <| le_of_not_lt fun hn => not_lt_of_le (H _ hn) (lt_succ a)⟩
theorem lt_limit {o} (h : IsLimit o) {a} : a < o ↔ ∃ x < o, a < x := by
-- Porting note: `bex_def` is required.
simpa only [not_forall₂, not_le, bex_def] using not_congr (@limit_le _ h a)
@[simp]
theorem lift_isLimit (o : Ordinal.{v}) : IsLimit (lift.{u,v} o) ↔ IsLimit o :=
and_congr (not_congr <| by simpa only [lift_zero] using @lift_inj o 0)
⟨fun H a h => (lift_lt.{u,v}).1 <|
by simpa only [lift_succ] using H _ (lift_lt.2 h), fun H a h => by
obtain ⟨a', rfl⟩ := lift_down h.le
rw [← lift_succ, lift_lt]
exact H a' (lift_lt.1 h)⟩
theorem IsLimit.pos {o : Ordinal} (h : IsLimit o) : 0 < o :=
lt_of_le_of_ne (Ordinal.zero_le _) h.1.symm
theorem IsLimit.one_lt {o : Ordinal} (h : IsLimit o) : 1 < o := by
simpa only [succ_zero] using h.2 _ h.pos
theorem IsLimit.nat_lt {o : Ordinal} (h : IsLimit o) : ∀ n : ℕ, (n : Ordinal) < o
| 0 => h.pos
| n + 1 => h.2 _ (IsLimit.nat_lt h n)
theorem zero_or_succ_or_limit (o : Ordinal) : o = 0 ∨ (∃ a, o = succ a) ∨ IsLimit o :=
if o0 : o = 0 then Or.inl o0
else
if h : ∃ a, o = succ a then Or.inr (Or.inl h)
else Or.inr <| Or.inr ⟨o0, fun _a => (succ_lt_of_not_succ h).2⟩
/-- Main induction principle of ordinals: if one can prove a property by
induction at successor ordinals and at limit ordinals, then it holds for all ordinals. -/
@[elab_as_elim]
def limitRecOn {C : Ordinal → Sort*} (o : Ordinal) (H₁ : C 0) (H₂ : ∀ o, C o → C (succ o))
(H₃ : ∀ o, IsLimit o → (∀ o' < o, C o') → C o) : C o :=
SuccOrder.limitRecOn o (fun o _ ↦ H₂ o) fun o hl ↦
if h : o = 0 then fun _ ↦ h ▸ H₁ else H₃ o ⟨h, fun _ ↦ hl.succ_lt⟩
@[simp]
theorem limitRecOn_zero {C} (H₁ H₂ H₃) : @limitRecOn C 0 H₁ H₂ H₃ = H₁ := by
rw [limitRecOn, SuccOrder.limitRecOn_limit _ _ isSuccLimit_zero, dif_pos rfl]
@[simp]
theorem limitRecOn_succ {C} (o H₁ H₂ H₃) :
@limitRecOn C (succ o) H₁ H₂ H₃ = H₂ o (@limitRecOn C o H₁ H₂ H₃) := by
simp_rw [limitRecOn, SuccOrder.limitRecOn_succ _ _ (not_isMax _)]
@[simp]
theorem limitRecOn_limit {C} (o H₁ H₂ H₃ h) :
@limitRecOn C o H₁ H₂ H₃ = H₃ o h fun x _h => @limitRecOn C x H₁ H₂ H₃ := by
simp_rw [limitRecOn, SuccOrder.limitRecOn_limit _ _ h.isSuccLimit, dif_neg h.1]
instance orderTopOutSucc (o : Ordinal) : OrderTop (succ o).out.α :=
@OrderTop.mk _ _ (Top.mk _) le_enum_succ
theorem enum_succ_eq_top {o : Ordinal} :
enum (· < ·) o
(by
rw [type_lt]
exact lt_succ o) =
(⊤ : (succ o).out.α) :=
rfl
theorem has_succ_of_type_succ_lt {α} {r : α → α → Prop} [wo : IsWellOrder α r]
(h : ∀ a < type r, succ a < type r) (x : α) : ∃ y, r x y := by
use enum r (succ (typein r x)) (h _ (typein_lt_type r x))
convert (enum_lt_enum (typein_lt_type r x)
(h _ (typein_lt_type r x))).mpr (lt_succ _); rw [enum_typein]
theorem out_no_max_of_succ_lt {o : Ordinal} (ho : ∀ a < o, succ a < o) : NoMaxOrder o.out.α :=
⟨has_succ_of_type_succ_lt (by rwa [type_lt])⟩
theorem bounded_singleton {r : α → α → Prop} [IsWellOrder α r] (hr : (type r).IsLimit) (x) :
Bounded r {x} := by
refine ⟨enum r (succ (typein r x)) (hr.2 _ (typein_lt_type r x)), ?_⟩
intro b hb
rw [mem_singleton_iff.1 hb]
nth_rw 1 [← enum_typein r x]
rw [@enum_lt_enum _ r]
apply lt_succ
-- Porting note: `· < ·` requires a type ascription for an `IsWellOrder` instance.
theorem type_subrel_lt (o : Ordinal.{u}) :
type (Subrel ((· < ·) : Ordinal → Ordinal → Prop) { o' : Ordinal | o' < o })
= Ordinal.lift.{u + 1} o := by
refine Quotient.inductionOn o ?_
rintro ⟨α, r, wo⟩; apply Quotient.sound
-- Porting note: `symm; refine' [term]` → `refine' [term].symm`
constructor; refine ((RelIso.preimage Equiv.ulift r).trans (enumIso r).symm).symm
theorem mk_initialSeg (o : Ordinal.{u}) :
#{ o' : Ordinal | o' < o } = Cardinal.lift.{u + 1} o.card := by
rw [lift_card, ← type_subrel_lt, card_type]
/-! ### Normal ordinal functions -/
/-- A normal ordinal function is a strictly increasing function which is
order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for
`a < o`. -/
def IsNormal (f : Ordinal → Ordinal) : Prop :=
(∀ o, f o < f (succ o)) ∧ ∀ o, IsLimit o → ∀ a, f o ≤ a ↔ ∀ b < o, f b ≤ a
theorem IsNormal.limit_le {f} (H : IsNormal f) :
∀ {o}, IsLimit o → ∀ {a}, f o ≤ a ↔ ∀ b < o, f b ≤ a :=
@H.2
theorem IsNormal.limit_lt {f} (H : IsNormal f) {o} (h : IsLimit o) {a} :
a < f o ↔ ∃ b < o, a < f b :=
not_iff_not.1 <| by simpa only [exists_prop, not_exists, not_and, not_lt] using H.2 _ h a
theorem IsNormal.strictMono {f} (H : IsNormal f) : StrictMono f := fun a b =>
limitRecOn b (Not.elim (not_lt_of_le <| Ordinal.zero_le _))
(fun _b IH h =>
(lt_or_eq_of_le (le_of_lt_succ h)).elim (fun h => (IH h).trans (H.1 _)) fun e => e ▸ H.1 _)
fun _b l _IH h => lt_of_lt_of_le (H.1 a) ((H.2 _ l _).1 le_rfl _ (l.2 _ h))
theorem IsNormal.monotone {f} (H : IsNormal f) : Monotone f :=
H.strictMono.monotone
theorem isNormal_iff_strictMono_limit (f : Ordinal → Ordinal) :
IsNormal f ↔ StrictMono f ∧ ∀ o, IsLimit o → ∀ a, (∀ b < o, f b ≤ a) → f o ≤ a :=
⟨fun hf => ⟨hf.strictMono, fun a ha c => (hf.2 a ha c).2⟩, fun ⟨hs, hl⟩ =>
⟨fun a => hs (lt_succ a), fun a ha c =>
⟨fun hac _b hba => ((hs hba).trans_le hac).le, hl a ha c⟩⟩⟩
theorem IsNormal.lt_iff {f} (H : IsNormal f) {a b} : f a < f b ↔ a < b :=
StrictMono.lt_iff_lt <| H.strictMono
theorem IsNormal.le_iff {f} (H : IsNormal f) {a b} : f a ≤ f b ↔ a ≤ b :=
le_iff_le_iff_lt_iff_lt.2 H.lt_iff
theorem IsNormal.inj {f} (H : IsNormal f) {a b} : f a = f b ↔ a = b := by
simp only [le_antisymm_iff, H.le_iff]
theorem IsNormal.self_le {f} (H : IsNormal f) (a) : a ≤ f a :=
lt_wf.self_le_of_strictMono H.strictMono a
theorem IsNormal.le_set {f o} (H : IsNormal f) (p : Set Ordinal) (p0 : p.Nonempty) (b)
(H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f a ≤ o :=
⟨fun h a pa => (H.le_iff.2 ((H₂ _).1 le_rfl _ pa)).trans h, fun h => by
-- Porting note: `refine'` didn't work well so `induction` is used
induction b using limitRecOn with
| H₁ =>
cases' p0 with x px
have := Ordinal.le_zero.1 ((H₂ _).1 (Ordinal.zero_le _) _ px)
rw [this] at px
exact h _ px
| H₂ S _ =>
rcases not_forall₂.1 (mt (H₂ S).2 <| (lt_succ S).not_le) with ⟨a, h₁, h₂⟩
exact (H.le_iff.2 <| succ_le_of_lt <| not_le.1 h₂).trans (h _ h₁)
| H₃ S L _ =>
refine (H.2 _ L _).2 fun a h' => ?_
rcases not_forall₂.1 (mt (H₂ a).2 h'.not_le) with ⟨b, h₁, h₂⟩
exact (H.le_iff.2 <| (not_le.1 h₂).le).trans (h _ h₁)⟩
theorem IsNormal.le_set' {f o} (H : IsNormal f) (p : Set α) (p0 : p.Nonempty) (g : α → Ordinal) (b)
(H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, g a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f (g a) ≤ o := by
simpa [H₂] using H.le_set (g '' p) (p0.image g) b
theorem IsNormal.refl : IsNormal id :=
⟨lt_succ, fun _o l _a => Ordinal.limit_le l⟩
theorem IsNormal.trans {f g} (H₁ : IsNormal f) (H₂ : IsNormal g) : IsNormal (f ∘ g) :=
⟨fun _x => H₁.lt_iff.2 (H₂.1 _), fun o l _a =>
H₁.le_set' (· < o) ⟨0, l.pos⟩ g _ fun _c => H₂.2 _ l _⟩
theorem IsNormal.isLimit {f} (H : IsNormal f) {o} (l : IsLimit o) : IsLimit (f o) :=
⟨ne_of_gt <| (Ordinal.zero_le _).trans_lt <| H.lt_iff.2 l.pos, fun _ h =>
let ⟨_b, h₁, h₂⟩ := (H.limit_lt l).1 h
(succ_le_of_lt h₂).trans_lt (H.lt_iff.2 h₁)⟩
theorem IsNormal.le_iff_eq {f} (H : IsNormal f) {a} : f a ≤ a ↔ f a = a :=
(H.self_le a).le_iff_eq
theorem add_le_of_limit {a b c : Ordinal} (h : IsLimit b) : a + b ≤ c ↔ ∀ b' < b, a + b' ≤ c :=
⟨fun h b' l => (add_le_add_left l.le _).trans h, fun H =>
le_of_not_lt <| by
-- Porting note: `induction` tactics are required because of the parser bug.
induction a using inductionOn with
| H α r =>
induction b using inductionOn with
| H β s =>
intro l
suffices ∀ x : β, Sum.Lex r s (Sum.inr x) (enum _ _ l) by
-- Porting note: `revert` & `intro` is required because `cases'` doesn't replace
-- `enum _ _ l` in `this`.
revert this; cases' enum _ _ l with x x <;> intro this
· cases this (enum s 0 h.pos)
· exact irrefl _ (this _)
intro x
rw [← typein_lt_typein (Sum.Lex r s), typein_enum]
have := H _ (h.2 _ (typein_lt_type s x))
rw [add_succ, succ_le_iff] at this
refine
(RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this
· rcases a with ⟨a | b, h⟩
· exact Sum.inl a
· exact Sum.inr ⟨b, by cases h; assumption⟩
· rcases a with ⟨a | a, h₁⟩ <;> rcases b with ⟨b | b, h₂⟩ <;> cases h₁ <;> cases h₂ <;>
rintro ⟨⟩ <;> constructor <;> assumption⟩
theorem add_isNormal (a : Ordinal) : IsNormal (a + ·) :=
⟨fun b => (add_lt_add_iff_left a).2 (lt_succ b), fun _b l _c => add_le_of_limit l⟩
theorem add_isLimit (a) {b} : IsLimit b → IsLimit (a + b) :=
(add_isNormal a).isLimit
alias IsLimit.add := add_isLimit
/-! ### Subtraction on ordinals-/
/-- The set in the definition of subtraction is nonempty. -/
theorem sub_nonempty {a b : Ordinal} : { o | a ≤ b + o }.Nonempty :=
⟨a, le_add_left _ _⟩
/-- `a - b` is the unique ordinal satisfying `b + (a - b) = a` when `b ≤ a`. -/
instance sub : Sub Ordinal :=
⟨fun a b => sInf { o | a ≤ b + o }⟩
theorem le_add_sub (a b : Ordinal) : a ≤ b + (a - b) :=
csInf_mem sub_nonempty
theorem sub_le {a b c : Ordinal} : a - b ≤ c ↔ a ≤ b + c :=
⟨fun h => (le_add_sub a b).trans (add_le_add_left h _), fun h => csInf_le' h⟩
theorem lt_sub {a b c : Ordinal} : a < b - c ↔ c + a < b :=
lt_iff_lt_of_le_iff_le sub_le
theorem add_sub_cancel (a b : Ordinal) : a + b - a = b :=
le_antisymm (sub_le.2 <| le_rfl) ((add_le_add_iff_left a).1 <| le_add_sub _ _)
theorem sub_eq_of_add_eq {a b c : Ordinal} (h : a + b = c) : c - a = b :=
h ▸ add_sub_cancel _ _
theorem sub_le_self (a b : Ordinal) : a - b ≤ a :=
sub_le.2 <| le_add_left _ _
protected theorem add_sub_cancel_of_le {a b : Ordinal} (h : b ≤ a) : b + (a - b) = a :=
(le_add_sub a b).antisymm'
(by
rcases zero_or_succ_or_limit (a - b) with (e | ⟨c, e⟩ | l)
· simp only [e, add_zero, h]
· rw [e, add_succ, succ_le_iff, ← lt_sub, e]
exact lt_succ c
· exact (add_le_of_limit l).2 fun c l => (lt_sub.1 l).le)
theorem le_sub_of_le {a b c : Ordinal} (h : b ≤ a) : c ≤ a - b ↔ b + c ≤ a := by
rw [← add_le_add_iff_left b, Ordinal.add_sub_cancel_of_le h]
theorem sub_lt_of_le {a b c : Ordinal} (h : b ≤ a) : a - b < c ↔ a < b + c :=
lt_iff_lt_of_le_iff_le (le_sub_of_le h)
instance existsAddOfLE : ExistsAddOfLE Ordinal :=
⟨fun h => ⟨_, (Ordinal.add_sub_cancel_of_le h).symm⟩⟩
@[simp]
theorem sub_zero (a : Ordinal) : a - 0 = a := by simpa only [zero_add] using add_sub_cancel 0 a
@[simp]
theorem zero_sub (a : Ordinal) : 0 - a = 0 := by rw [← Ordinal.le_zero]; apply sub_le_self
@[simp]
theorem sub_self (a : Ordinal) : a - a = 0 := by simpa only [add_zero] using add_sub_cancel a 0
protected theorem sub_eq_zero_iff_le {a b : Ordinal} : a - b = 0 ↔ a ≤ b :=
⟨fun h => by simpa only [h, add_zero] using le_add_sub a b, fun h => by
rwa [← Ordinal.le_zero, sub_le, add_zero]⟩
theorem sub_sub (a b c : Ordinal) : a - b - c = a - (b + c) :=
eq_of_forall_ge_iff fun d => by rw [sub_le, sub_le, sub_le, add_assoc]
@[simp]
theorem add_sub_add_cancel (a b c : Ordinal) : a + b - (a + c) = b - c := by
rw [← sub_sub, add_sub_cancel]
theorem sub_isLimit {a b} (l : IsLimit a) (h : b < a) : IsLimit (a - b) :=
⟨ne_of_gt <| lt_sub.2 <| by rwa [add_zero], fun c h => by
rw [lt_sub, add_succ]; exact l.2 _ (lt_sub.1 h)⟩
-- @[simp] -- Porting note (#10618): simp can prove this
theorem one_add_omega : 1 + ω = ω := by
refine le_antisymm ?_ (le_add_left _ _)
rw [omega, ← lift_one.{0}, ← lift_add, lift_le, ← type_unit, ← type_sum_lex]
refine ⟨RelEmbedding.collapse (RelEmbedding.ofMonotone ?_ ?_)⟩
· apply Sum.rec
· exact fun _ => 0
· exact Nat.succ
· intro a b
cases a <;> cases b <;> intro H <;> cases' H with _ _ H _ _ H <;>
[exact H.elim; exact Nat.succ_pos _; exact Nat.succ_lt_succ H]
@[simp]
theorem one_add_of_omega_le {o} (h : ω ≤ o) : 1 + o = o := by
rw [← Ordinal.add_sub_cancel_of_le h, ← add_assoc, one_add_omega]
/-! ### Multiplication of ordinals-/
/-- The multiplication of ordinals `o₁` and `o₂` is the (well founded) lexicographic order on
`o₂ × o₁`. -/
instance monoid : Monoid Ordinal.{u} where
mul a b :=
Quotient.liftOn₂ a b
(fun ⟨α, r, wo⟩ ⟨β, s, wo'⟩ => ⟦⟨β × α, Prod.Lex s r, inferInstance⟩⟧ :
WellOrder → WellOrder → Ordinal)
fun ⟨α₁, r₁, o₁⟩ ⟨α₂, r₂, o₂⟩ ⟨β₁, s₁, p₁⟩ ⟨β₂, s₂, p₂⟩ ⟨f⟩ ⟨g⟩ =>
Quot.sound ⟨RelIso.prodLexCongr g f⟩
one := 1
mul_assoc a b c :=
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ =>
Eq.symm <|
Quotient.sound
⟨⟨prodAssoc _ _ _, @fun a b => by
rcases a with ⟨⟨a₁, a₂⟩, a₃⟩
rcases b with ⟨⟨b₁, b₂⟩, b₃⟩
simp [Prod.lex_def, and_or_left, or_assoc, and_assoc]⟩⟩
mul_one a :=
inductionOn a fun α r _ =>
Quotient.sound
⟨⟨punitProd _, @fun a b => by
rcases a with ⟨⟨⟨⟩⟩, a⟩; rcases b with ⟨⟨⟨⟩⟩, b⟩
simp only [Prod.lex_def, EmptyRelation, false_or_iff]
simp only [eq_self_iff_true, true_and_iff]
rfl⟩⟩
one_mul a :=
inductionOn a fun α r _ =>
Quotient.sound
⟨⟨prodPUnit _, @fun a b => by
rcases a with ⟨a, ⟨⟨⟩⟩⟩; rcases b with ⟨b, ⟨⟨⟩⟩⟩
simp only [Prod.lex_def, EmptyRelation, and_false_iff, or_false_iff]
rfl⟩⟩
@[simp]
theorem type_prod_lex {α β : Type u} (r : α → α → Prop) (s : β → β → Prop) [IsWellOrder α r]
[IsWellOrder β s] : type (Prod.Lex s r) = type r * type s :=
rfl
private theorem mul_eq_zero' {a b : Ordinal} : a * b = 0 ↔ a = 0 ∨ b = 0 :=
inductionOn a fun α _ _ =>
inductionOn b fun β _ _ => by
simp_rw [← type_prod_lex, type_eq_zero_iff_isEmpty]
rw [or_comm]
exact isEmpty_prod
instance monoidWithZero : MonoidWithZero Ordinal :=
{ Ordinal.monoid with
zero := 0
mul_zero := fun _a => mul_eq_zero'.2 <| Or.inr rfl
zero_mul := fun _a => mul_eq_zero'.2 <| Or.inl rfl }
instance noZeroDivisors : NoZeroDivisors Ordinal :=
⟨fun {_ _} => mul_eq_zero'.1⟩
@[simp]
theorem lift_mul (a b : Ordinal.{v}) : lift.{u} (a * b) = lift.{u} a * lift.{u} b :=
Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ =>
Quotient.sound
⟨(RelIso.preimage Equiv.ulift _).trans
(RelIso.prodLexCongr (RelIso.preimage Equiv.ulift _)
(RelIso.preimage Equiv.ulift _)).symm⟩
@[simp]
theorem card_mul (a b) : card (a * b) = card a * card b :=
Quotient.inductionOn₂ a b fun ⟨α, _r, _⟩ ⟨β, _s, _⟩ => mul_comm #β #α
instance leftDistribClass : LeftDistribClass Ordinal.{u} :=
⟨fun a b c =>
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ =>
Quotient.sound
⟨⟨sumProdDistrib _ _ _, by
rintro ⟨a₁ | a₁, a₂⟩ ⟨b₁ | b₁, b₂⟩ <;>
simp only [Prod.lex_def, Sum.lex_inl_inl, Sum.Lex.sep, Sum.lex_inr_inl,
Sum.lex_inr_inr, sumProdDistrib_apply_left, sumProdDistrib_apply_right] <;>
-- Porting note: `Sum.inr.inj_iff` is required.
simp only [Sum.inl.inj_iff, Sum.inr.inj_iff,
true_or_iff, false_and_iff, false_or_iff]⟩⟩⟩
theorem mul_succ (a b : Ordinal) : a * succ b = a * b + a :=
mul_add_one a b
instance mul_covariantClass_le : CovariantClass Ordinal.{u} Ordinal.{u} (· * ·) (· ≤ ·) :=
⟨fun c a b =>
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩ => by
refine
(RelEmbedding.ofMonotone (fun a : α × γ => (f a.1, a.2)) fun a b h => ?_).ordinal_type_le
cases' h with a₁ b₁ a₂ b₂ h' a b₁ b₂ h'
· exact Prod.Lex.left _ _ (f.toRelEmbedding.map_rel_iff.2 h')
· exact Prod.Lex.right _ h'⟩
instance mul_swap_covariantClass_le :
CovariantClass Ordinal.{u} Ordinal.{u} (swap (· * ·)) (· ≤ ·) :=
⟨fun c a b =>
Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩ => by
refine
(RelEmbedding.ofMonotone (fun a : γ × α => (a.1, f a.2)) fun a b h => ?_).ordinal_type_le
cases' h with a₁ b₁ a₂ b₂ h' a b₁ b₂ h'
· exact Prod.Lex.left _ _ h'
· exact Prod.Lex.right _ (f.toRelEmbedding.map_rel_iff.2 h')⟩
theorem le_mul_left (a : Ordinal) {b : Ordinal} (hb : 0 < b) : a ≤ a * b := by
convert mul_le_mul_left' (one_le_iff_pos.2 hb) a
rw [mul_one a]
theorem le_mul_right (a : Ordinal) {b : Ordinal} (hb : 0 < b) : a ≤ b * a := by
convert mul_le_mul_right' (one_le_iff_pos.2 hb) a
rw [one_mul a]
private theorem mul_le_of_limit_aux {α β r s} [IsWellOrder α r] [IsWellOrder β s] {c}
(h : IsLimit (type s)) (H : ∀ b' < type s, type r * b' ≤ c) (l : c < type r * type s) :
False := by
suffices ∀ a b, Prod.Lex s r (b, a) (enum _ _ l) by
cases' enum _ _ l with b a
exact irrefl _ (this _ _)
intro a b
rw [← typein_lt_typein (Prod.Lex s r), typein_enum]
have := H _ (h.2 _ (typein_lt_type s b))
rw [mul_succ] at this
have := ((add_lt_add_iff_left _).2 (typein_lt_type _ a)).trans_le this
refine (RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this
· rcases a with ⟨⟨b', a'⟩, h⟩
by_cases e : b = b'
· refine Sum.inr ⟨a', ?_⟩
subst e
cases' h with _ _ _ _ h _ _ _ h
· exact (irrefl _ h).elim
· exact h
· refine Sum.inl (⟨b', ?_⟩, a')
cases' h with _ _ _ _ h _ _ _ h
· exact h
· exact (e rfl).elim
· rcases a with ⟨⟨b₁, a₁⟩, h₁⟩
rcases b with ⟨⟨b₂, a₂⟩, h₂⟩
intro h
by_cases e₁ : b = b₁ <;> by_cases e₂ : b = b₂
· substs b₁ b₂
simpa only [subrel_val, Prod.lex_def, @irrefl _ s _ b, true_and_iff, false_or_iff,
eq_self_iff_true, dif_pos, Sum.lex_inr_inr] using h
· subst b₁
simp only [subrel_val, Prod.lex_def, e₂, Prod.lex_def, dif_pos, subrel_val, eq_self_iff_true,
or_false_iff, dif_neg, not_false_iff, Sum.lex_inr_inl, false_and_iff] at h ⊢
cases' h₂ with _ _ _ _ h₂_h h₂_h <;> [exact asymm h h₂_h; exact e₂ rfl]
· simp [e₂, dif_neg e₁, show b₂ ≠ b₁ from e₂ ▸ e₁]
· simpa only [dif_neg e₁, dif_neg e₂, Prod.lex_def, subrel_val, Subtype.mk_eq_mk,
Sum.lex_inl_inl] using h
theorem mul_le_of_limit {a b c : Ordinal} (h : IsLimit b) : a * b ≤ c ↔ ∀ b' < b, a * b' ≤ c :=
⟨fun h b' l => (mul_le_mul_left' l.le _).trans h, fun H =>
-- Porting note: `induction` tactics are required because of the parser bug.
le_of_not_lt <| by
induction a using inductionOn with
| H α r =>
induction b using inductionOn with
| H β s =>
exact mul_le_of_limit_aux h H⟩
theorem mul_isNormal {a : Ordinal} (h : 0 < a) : IsNormal (a * ·) :=
-- Porting note(#12129): additional beta reduction needed
⟨fun b => by
beta_reduce
rw [mul_succ]
simpa only [add_zero] using (add_lt_add_iff_left (a * b)).2 h,
fun b l c => mul_le_of_limit l⟩
theorem lt_mul_of_limit {a b c : Ordinal} (h : IsLimit c) : a < b * c ↔ ∃ c' < c, a < b * c' := by
-- Porting note: `bex_def` is required.
simpa only [not_forall₂, not_le, bex_def] using not_congr (@mul_le_of_limit b c a h)
theorem mul_lt_mul_iff_left {a b c : Ordinal} (a0 : 0 < a) : a * b < a * c ↔ b < c :=
(mul_isNormal a0).lt_iff
theorem mul_le_mul_iff_left {a b c : Ordinal} (a0 : 0 < a) : a * b ≤ a * c ↔ b ≤ c :=
(mul_isNormal a0).le_iff
theorem mul_lt_mul_of_pos_left {a b c : Ordinal} (h : a < b) (c0 : 0 < c) : c * a < c * b :=
(mul_lt_mul_iff_left c0).2 h
theorem mul_pos {a b : Ordinal} (h₁ : 0 < a) (h₂ : 0 < b) : 0 < a * b := by
simpa only [mul_zero] using mul_lt_mul_of_pos_left h₂ h₁
theorem mul_ne_zero {a b : Ordinal} : a ≠ 0 → b ≠ 0 → a * b ≠ 0 := by
simpa only [Ordinal.pos_iff_ne_zero] using mul_pos
theorem le_of_mul_le_mul_left {a b c : Ordinal} (h : c * a ≤ c * b) (h0 : 0 < c) : a ≤ b :=
le_imp_le_of_lt_imp_lt (fun h' => mul_lt_mul_of_pos_left h' h0) h
theorem mul_right_inj {a b c : Ordinal} (a0 : 0 < a) : a * b = a * c ↔ b = c :=
(mul_isNormal a0).inj
theorem mul_isLimit {a b : Ordinal} (a0 : 0 < a) : IsLimit b → IsLimit (a * b) :=
(mul_isNormal a0).isLimit
theorem mul_isLimit_left {a b : Ordinal} (l : IsLimit a) (b0 : 0 < b) : IsLimit (a * b) := by
rcases zero_or_succ_or_limit b with (rfl | ⟨b, rfl⟩ | lb)
· exact b0.false.elim
· rw [mul_succ]
exact add_isLimit _ l
· exact mul_isLimit l.pos lb
theorem smul_eq_mul : ∀ (n : ℕ) (a : Ordinal), n • a = a * n
| 0, a => by rw [zero_nsmul, Nat.cast_zero, mul_zero]
| n + 1, a => by rw [succ_nsmul, Nat.cast_add, mul_add, Nat.cast_one, mul_one, smul_eq_mul n]
/-! ### Division on ordinals -/
/-- The set in the definition of division is nonempty. -/
theorem div_nonempty {a b : Ordinal} (h : b ≠ 0) : { o | a < b * succ o }.Nonempty :=
⟨a, (succ_le_iff (a := a) (b := b * succ a)).1 <| by
simpa only [succ_zero, one_mul] using
mul_le_mul_right' (succ_le_of_lt (Ordinal.pos_iff_ne_zero.2 h)) (succ a)⟩
/-- `a / b` is the unique ordinal `o` satisfying `a = b * o + o'` with `o' < b`. -/
instance div : Div Ordinal :=
⟨fun a b => if _h : b = 0 then 0 else sInf { o | a < b * succ o }⟩
@[simp]
theorem div_zero (a : Ordinal) : a / 0 = 0 :=
dif_pos rfl
theorem div_def (a) {b : Ordinal} (h : b ≠ 0) : a / b = sInf { o | a < b * succ o } :=
dif_neg h
theorem lt_mul_succ_div (a) {b : Ordinal} (h : b ≠ 0) : a < b * succ (a / b) := by
rw [div_def a h]; exact csInf_mem (div_nonempty h)
theorem lt_mul_div_add (a) {b : Ordinal} (h : b ≠ 0) : a < b * (a / b) + b := by
simpa only [mul_succ] using lt_mul_succ_div a h
theorem div_le {a b c : Ordinal} (b0 : b ≠ 0) : a / b ≤ c ↔ a < b * succ c :=
⟨fun h => (lt_mul_succ_div a b0).trans_le (mul_le_mul_left' (succ_le_succ_iff.2 h) _), fun h => by
rw [div_def a b0]; exact csInf_le' h⟩
theorem lt_div {a b c : Ordinal} (h : c ≠ 0) : a < b / c ↔ c * succ a ≤ b := by
rw [← not_le, div_le h, not_lt]
theorem div_pos {b c : Ordinal} (h : c ≠ 0) : 0 < b / c ↔ c ≤ b := by simp [lt_div h]
theorem le_div {a b c : Ordinal} (c0 : c ≠ 0) : a ≤ b / c ↔ c * a ≤ b := by
induction a using limitRecOn with
| H₁ => simp only [mul_zero, Ordinal.zero_le]
| H₂ _ _ => rw [succ_le_iff, lt_div c0]
| H₃ _ h₁ h₂ =>
revert h₁ h₂
simp (config := { contextual := true }) only [mul_le_of_limit, limit_le, iff_self_iff,
forall_true_iff]
theorem div_lt {a b c : Ordinal} (b0 : b ≠ 0) : a / b < c ↔ a < b * c :=
lt_iff_lt_of_le_iff_le <| le_div b0
theorem div_le_of_le_mul {a b c : Ordinal} (h : a ≤ b * c) : a / b ≤ c :=
if b0 : b = 0 then by simp only [b0, div_zero, Ordinal.zero_le]
else
(div_le b0).2 <| h.trans_lt <| mul_lt_mul_of_pos_left (lt_succ c) (Ordinal.pos_iff_ne_zero.2 b0)
theorem mul_lt_of_lt_div {a b c : Ordinal} : a < b / c → c * a < b :=
lt_imp_lt_of_le_imp_le div_le_of_le_mul
@[simp]
theorem zero_div (a : Ordinal) : 0 / a = 0 :=
Ordinal.le_zero.1 <| div_le_of_le_mul <| Ordinal.zero_le _
theorem mul_div_le (a b : Ordinal) : b * (a / b) ≤ a :=
if b0 : b = 0 then by simp only [b0, zero_mul, Ordinal.zero_le] else (le_div b0).1 le_rfl
theorem mul_add_div (a) {b : Ordinal} (b0 : b ≠ 0) (c) : (b * a + c) / b = a + c / b := by
apply le_antisymm
· apply (div_le b0).2
rw [mul_succ, mul_add, add_assoc, add_lt_add_iff_left]
apply lt_mul_div_add _ b0
· rw [le_div b0, mul_add, add_le_add_iff_left]
apply mul_div_le
theorem div_eq_zero_of_lt {a b : Ordinal} (h : a < b) : a / b = 0 := by
rw [← Ordinal.le_zero, div_le <| Ordinal.pos_iff_ne_zero.1 <| (Ordinal.zero_le _).trans_lt h]
simpa only [succ_zero, mul_one] using h
@[simp]
theorem mul_div_cancel (a) {b : Ordinal} (b0 : b ≠ 0) : b * a / b = a := by
simpa only [add_zero, zero_div] using mul_add_div a b0 0
@[simp]
theorem div_one (a : Ordinal) : a / 1 = a := by
simpa only [one_mul] using mul_div_cancel a Ordinal.one_ne_zero
@[simp]
theorem div_self {a : Ordinal} (h : a ≠ 0) : a / a = 1 := by
simpa only [mul_one] using mul_div_cancel 1 h
theorem mul_sub (a b c : Ordinal) : a * (b - c) = a * b - a * c :=
if a0 : a = 0 then by simp only [a0, zero_mul, sub_self]
else
eq_of_forall_ge_iff fun d => by rw [sub_le, ← le_div a0, sub_le, ← le_div a0, mul_add_div _ a0]
theorem isLimit_add_iff {a b} : IsLimit (a + b) ↔ IsLimit b ∨ b = 0 ∧ IsLimit a := by
constructor <;> intro h
· by_cases h' : b = 0
· rw [h', add_zero] at h
right
exact ⟨h', h⟩
left
rw [← add_sub_cancel a b]
apply sub_isLimit h
suffices a + 0 < a + b by simpa only [add_zero] using this
rwa [add_lt_add_iff_left, Ordinal.pos_iff_ne_zero]
rcases h with (h | ⟨rfl, h⟩)
· exact add_isLimit a h
· simpa only [add_zero]
theorem dvd_add_iff : ∀ {a b c : Ordinal}, a ∣ b → (a ∣ b + c ↔ a ∣ c)
| a, _, c, ⟨b, rfl⟩ =>
⟨fun ⟨d, e⟩ => ⟨d - b, by rw [mul_sub, ← e, add_sub_cancel]⟩, fun ⟨d, e⟩ => by
rw [e, ← mul_add]
apply dvd_mul_right⟩
theorem div_mul_cancel : ∀ {a b : Ordinal}, a ≠ 0 → a ∣ b → a * (b / a) = b
| a, _, a0, ⟨b, rfl⟩ => by rw [mul_div_cancel _ a0]
theorem le_of_dvd : ∀ {a b : Ordinal}, b ≠ 0 → a ∣ b → a ≤ b
-- Porting note: `⟨b, rfl⟩ => by` → `⟨b, e⟩ => by subst e`
| a, _, b0, ⟨b, e⟩ => by
subst e
-- Porting note: `Ne` is required.
simpa only [mul_one] using
mul_le_mul_left'
(one_le_iff_ne_zero.2 fun h : b = 0 => by
simp only [h, mul_zero, Ne, not_true_eq_false] at b0) a
theorem dvd_antisymm {a b : Ordinal} (h₁ : a ∣ b) (h₂ : b ∣ a) : a = b :=
if a0 : a = 0 then by subst a; exact (eq_zero_of_zero_dvd h₁).symm
else
if b0 : b = 0 then by subst b; exact eq_zero_of_zero_dvd h₂
else (le_of_dvd b0 h₁).antisymm (le_of_dvd a0 h₂)
instance isAntisymm : IsAntisymm Ordinal (· ∣ ·) :=
⟨@dvd_antisymm⟩
/-- `a % b` is the unique ordinal `o'` satisfying
`a = b * o + o'` with `o' < b`. -/
instance mod : Mod Ordinal :=
⟨fun a b => a - b * (a / b)⟩
theorem mod_def (a b : Ordinal) : a % b = a - b * (a / b) :=
rfl
theorem mod_le (a b : Ordinal) : a % b ≤ a :=
sub_le_self a _
@[simp]
theorem mod_zero (a : Ordinal) : a % 0 = a := by simp only [mod_def, div_zero, zero_mul, sub_zero]
theorem mod_eq_of_lt {a b : Ordinal} (h : a < b) : a % b = a := by
simp only [mod_def, div_eq_zero_of_lt h, mul_zero, sub_zero]
@[simp]
theorem zero_mod (b : Ordinal) : 0 % b = 0 := by simp only [mod_def, zero_div, mul_zero, sub_self]
theorem div_add_mod (a b : Ordinal) : b * (a / b) + a % b = a :=
Ordinal.add_sub_cancel_of_le <| mul_div_le _ _
theorem mod_lt (a) {b : Ordinal} (h : b ≠ 0) : a % b < b :=
(add_lt_add_iff_left (b * (a / b))).1 <| by rw [div_add_mod]; exact lt_mul_div_add a h
@[simp]
theorem mod_self (a : Ordinal) : a % a = 0 :=
if a0 : a = 0 then by simp only [a0, zero_mod]
else by simp only [mod_def, div_self a0, mul_one, sub_self]
@[simp]
theorem mod_one (a : Ordinal) : a % 1 = 0 := by simp only [mod_def, div_one, one_mul, sub_self]
theorem dvd_of_mod_eq_zero {a b : Ordinal} (H : a % b = 0) : b ∣ a :=
⟨a / b, by simpa [H] using (div_add_mod a b).symm⟩
theorem mod_eq_zero_of_dvd {a b : Ordinal} (H : b ∣ a) : a % b = 0 := by
rcases H with ⟨c, rfl⟩
rcases eq_or_ne b 0 with (rfl | hb)
· simp
· simp [mod_def, hb]
theorem dvd_iff_mod_eq_zero {a b : Ordinal} : b ∣ a ↔ a % b = 0 :=
⟨mod_eq_zero_of_dvd, dvd_of_mod_eq_zero⟩
@[simp]
theorem mul_add_mod_self (x y z : Ordinal) : (x * y + z) % x = z % x := by
rcases eq_or_ne x 0 with rfl | hx
· simp
· rwa [mod_def, mul_add_div, mul_add, ← sub_sub, add_sub_cancel, mod_def]
@[simp]
theorem mul_mod (x y : Ordinal) : x * y % x = 0 := by
simpa using mul_add_mod_self x y 0
theorem mod_mod_of_dvd (a : Ordinal) {b c : Ordinal} (h : c ∣ b) : a % b % c = a % c := by
nth_rw 2 [← div_add_mod a b]
rcases h with ⟨d, rfl⟩
rw [mul_assoc, mul_add_mod_self]
@[simp]
theorem mod_mod (a b : Ordinal) : a % b % b = a % b :=
mod_mod_of_dvd a dvd_rfl
/-! ### Families of ordinals
There are two kinds of indexed families that naturally arise when dealing with ordinals: those
indexed by some type in the appropriate universe, and those indexed by ordinals less than another.
The following API allows one to convert from one kind of family to the other.
In many cases, this makes it easy to prove claims about one kind of family via the corresponding
claim on the other. -/
/-- Converts a family indexed by a `Type u` to one indexed by an `Ordinal.{u}` using a specified
well-ordering. -/
def bfamilyOfFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α) :
∀ a < type r, α := fun a ha => f (enum r a ha)
/-- Converts a family indexed by a `Type u` to one indexed by an `Ordinal.{u}` using a well-ordering
given by the axiom of choice. -/
def bfamilyOfFamily {ι : Type u} : (ι → α) → ∀ a < type (@WellOrderingRel ι), α :=
bfamilyOfFamily' WellOrderingRel
/-- Converts a family indexed by an `Ordinal.{u}` to one indexed by a `Type u` using a specified
well-ordering. -/
def familyOfBFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o} (ho : type r = o)
(f : ∀ a < o, α) : ι → α := fun i =>
f (typein r i)
(by
rw [← ho]
exact typein_lt_type r i)
/-- Converts a family indexed by an `Ordinal.{u}` to one indexed by a `Type u` using a well-ordering
given by the axiom of choice. -/
def familyOfBFamily (o : Ordinal) (f : ∀ a < o, α) : o.out.α → α :=
familyOfBFamily' (· < ·) (type_lt o) f
@[simp]
theorem bfamilyOfFamily'_typein {ι} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α) (i) :
bfamilyOfFamily' r f (typein r i) (typein_lt_type r i) = f i := by
simp only [bfamilyOfFamily', enum_typein]
@[simp]
theorem bfamilyOfFamily_typein {ι} (f : ι → α) (i) :
bfamilyOfFamily f (typein _ i) (typein_lt_type _ i) = f i :=
bfamilyOfFamily'_typein _ f i
@[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove this
theorem familyOfBFamily'_enum {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o}
(ho : type r = o) (f : ∀ a < o, α) (i hi) :
familyOfBFamily' r ho f (enum r i (by rwa [ho])) = f i hi := by
simp only [familyOfBFamily', typein_enum]
@[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove this
theorem familyOfBFamily_enum (o : Ordinal) (f : ∀ a < o, α) (i hi) :
familyOfBFamily o f
(enum (· < ·) i
(by
convert hi
exact type_lt _)) =
f i hi :=
familyOfBFamily'_enum _ (type_lt o) f _ _
/-- The range of a family indexed by ordinals. -/
def brange (o : Ordinal) (f : ∀ a < o, α) : Set α :=
{ a | ∃ i hi, f i hi = a }
theorem mem_brange {o : Ordinal} {f : ∀ a < o, α} {a} : a ∈ brange o f ↔ ∃ i hi, f i hi = a :=
Iff.rfl
theorem mem_brange_self {o} (f : ∀ a < o, α) (i hi) : f i hi ∈ brange o f :=
⟨i, hi, rfl⟩
@[simp]
theorem range_familyOfBFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o}
(ho : type r = o) (f : ∀ a < o, α) : range (familyOfBFamily' r ho f) = brange o f := by
refine Set.ext fun a => ⟨?_, ?_⟩
· rintro ⟨b, rfl⟩
apply mem_brange_self
· rintro ⟨i, hi, rfl⟩
exact ⟨_, familyOfBFamily'_enum _ _ _ _ _⟩
@[simp]
theorem range_familyOfBFamily {o} (f : ∀ a < o, α) : range (familyOfBFamily o f) = brange o f :=
range_familyOfBFamily' _ _ f
@[simp]
theorem brange_bfamilyOfFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α) :
brange _ (bfamilyOfFamily' r f) = range f := by
refine Set.ext fun a => ⟨?_, ?_⟩
· rintro ⟨i, hi, rfl⟩
apply mem_range_self
· rintro ⟨b, rfl⟩
exact ⟨_, _, bfamilyOfFamily'_typein _ _ _⟩
@[simp]
theorem brange_bfamilyOfFamily {ι : Type u} (f : ι → α) : brange _ (bfamilyOfFamily f) = range f :=
brange_bfamilyOfFamily' _ _
@[simp]
theorem brange_const {o : Ordinal} (ho : o ≠ 0) {c : α} : (brange o fun _ _ => c) = {c} := by
rw [← range_familyOfBFamily]
exact @Set.range_const _ o.out.α (out_nonempty_iff_ne_zero.2 ho) c
theorem comp_bfamilyOfFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → α)
(g : α → β) : (fun i hi => g (bfamilyOfFamily' r f i hi)) = bfamilyOfFamily' r (g ∘ f) :=
rfl
theorem comp_bfamilyOfFamily {ι : Type u} (f : ι → α) (g : α → β) :
(fun i hi => g (bfamilyOfFamily f i hi)) = bfamilyOfFamily (g ∘ f) :=
rfl
theorem comp_familyOfBFamily' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o}
(ho : type r = o) (f : ∀ a < o, α) (g : α → β) :
g ∘ familyOfBFamily' r ho f = familyOfBFamily' r ho fun i hi => g (f i hi) :=
rfl
theorem comp_familyOfBFamily {o} (f : ∀ a < o, α) (g : α → β) :
g ∘ familyOfBFamily o f = familyOfBFamily o fun i hi => g (f i hi) :=
rfl
/-! ### Supremum of a family of ordinals -/
-- Porting note: Universes should be specified in `sup`s.
/-- The supremum of a family of ordinals -/
def sup {ι : Type u} (f : ι → Ordinal.{max u v}) : Ordinal.{max u v} :=
iSup f
@[simp]
theorem sSup_eq_sup {ι : Type u} (f : ι → Ordinal.{max u v}) : sSup (Set.range f) = sup.{_, v} f :=
rfl
/-- The range of an indexed ordinal function, whose outputs live in a higher universe than the
inputs, is always bounded above. See `Ordinal.lsub` for an explicit bound. -/
theorem bddAbove_range {ι : Type u} (f : ι → Ordinal.{max u v}) : BddAbove (Set.range f) :=
⟨(iSup (succ ∘ card ∘ f)).ord, by
rintro a ⟨i, rfl⟩
exact le_of_lt (Cardinal.lt_ord.2 ((lt_succ _).trans_le
(le_ciSup (Cardinal.bddAbove_range.{_, v} _) _)))⟩
theorem le_sup {ι : Type u} (f : ι → Ordinal.{max u v}) : ∀ i, f i ≤ sup.{_, v} f := fun i =>
le_csSup (bddAbove_range.{_, v} f) (mem_range_self i)
theorem sup_le_iff {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : sup.{_, v} f ≤ a ↔ ∀ i, f i ≤ a :=
(csSup_le_iff' (bddAbove_range.{_, v} f)).trans (by simp)
theorem sup_le {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : (∀ i, f i ≤ a) → sup.{_, v} f ≤ a :=
sup_le_iff.2
theorem lt_sup {ι : Type u} {f : ι → Ordinal.{max u v}} {a} : a < sup.{_, v} f ↔ ∃ i, a < f i := by
simpa only [not_forall, not_le] using not_congr (@sup_le_iff.{_, v} _ f a)
theorem ne_sup_iff_lt_sup {ι : Type u} {f : ι → Ordinal.{max u v}} :
(∀ i, f i ≠ sup.{_, v} f) ↔ ∀ i, f i < sup.{_, v} f :=
⟨fun hf _ => lt_of_le_of_ne (le_sup _ _) (hf _), fun hf _ => ne_of_lt (hf _)⟩
theorem sup_not_succ_of_ne_sup {ι : Type u} {f : ι → Ordinal.{max u v}}
(hf : ∀ i, f i ≠ sup.{_, v} f) {a} (hao : a < sup.{_, v} f) : succ a < sup.{_, v} f := by
by_contra! hoa
exact
hao.not_le (sup_le fun i => le_of_lt_succ <| (lt_of_le_of_ne (le_sup _ _) (hf i)).trans_le hoa)
@[simp]
theorem sup_eq_zero_iff {ι : Type u} {f : ι → Ordinal.{max u v}} :
sup.{_, v} f = 0 ↔ ∀ i, f i = 0 := by
refine
⟨fun h i => ?_, fun h =>
le_antisymm (sup_le fun i => Ordinal.le_zero.2 (h i)) (Ordinal.zero_le _)⟩
rw [← Ordinal.le_zero, ← h]
exact le_sup f i
theorem IsNormal.sup {f : Ordinal.{max u v} → Ordinal.{max u w}} (H : IsNormal f) {ι : Type u}
(g : ι → Ordinal.{max u v}) [Nonempty ι] : f (sup.{_, v} g) = sup.{_, w} (f ∘ g) :=
eq_of_forall_ge_iff fun a => by
rw [sup_le_iff]; simp only [comp]; rw [H.le_set' Set.univ Set.univ_nonempty g] <;>
simp [sup_le_iff]
@[simp]
theorem sup_empty {ι} [IsEmpty ι] (f : ι → Ordinal) : sup f = 0 :=
ciSup_of_empty f
@[simp]
theorem sup_const {ι} [_hι : Nonempty ι] (o : Ordinal) : (sup fun _ : ι => o) = o :=
ciSup_const
@[simp]
theorem sup_unique {ι} [Unique ι] (f : ι → Ordinal) : sup f = f default :=
ciSup_unique
theorem sup_le_of_range_subset {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal}
(h : Set.range f ⊆ Set.range g) : sup.{u, max v w} f ≤ sup.{v, max u w} g :=
sup_le fun i =>
match h (mem_range_self i) with
| ⟨_j, hj⟩ => hj ▸ le_sup _ _
theorem sup_eq_of_range_eq {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal}
(h : Set.range f = Set.range g) : sup.{u, max v w} f = sup.{v, max u w} g :=
(sup_le_of_range_subset.{u, v, w} h.le).antisymm (sup_le_of_range_subset.{v, u, w} h.ge)
@[simp]
theorem sup_sum {α : Type u} {β : Type v} (f : α ⊕ β → Ordinal) :
sup.{max u v, w} f =
max (sup.{u, max v w} fun a => f (Sum.inl a)) (sup.{v, max u w} fun b => f (Sum.inr b)) := by
apply (sup_le_iff.2 _).antisymm (max_le_iff.2 ⟨_, _⟩)
· rintro (i | i)
· exact le_max_of_le_left (le_sup _ i)
· exact le_max_of_le_right (le_sup _ i)
all_goals
apply sup_le_of_range_subset.{_, max u v, w}
rintro i ⟨a, rfl⟩
apply mem_range_self
theorem unbounded_range_of_sup_ge {α β : Type u} (r : α → α → Prop) [IsWellOrder α r] (f : β → α)
(h : type r ≤ sup.{u, u} (typein r ∘ f)) : Unbounded r (range f) :=
(not_bounded_iff _).1 fun ⟨x, hx⟩ =>
not_lt_of_le h <|
lt_of_le_of_lt
(sup_le fun y => le_of_lt <| (typein_lt_typein r).2 <| hx _ <| mem_range_self y)
(typein_lt_type r x)
theorem le_sup_shrink_equiv {s : Set Ordinal.{u}} (hs : Small.{u} s) (a) (ha : a ∈ s) :
a ≤ sup.{u, u} fun x => ((@equivShrink s hs).symm x).val := by
convert le_sup.{u, u} (fun x => ((@equivShrink s hs).symm x).val) ((@equivShrink s hs) ⟨a, ha⟩)
rw [symm_apply_apply]
instance small_Iio (o : Ordinal.{u}) : Small.{u} (Set.Iio o) :=
let f : o.out.α → Set.Iio o :=
fun x => ⟨typein ((· < ·) : o.out.α → o.out.α → Prop) x, typein_lt_self x⟩
let hf : Surjective f := fun b =>
⟨enum (· < ·) b.val
(by
rw [type_lt]
exact b.prop),
Subtype.ext (typein_enum _ _)⟩
small_of_surjective hf
instance small_Iic (o : Ordinal.{u}) : Small.{u} (Set.Iic o) := by
rw [← Iio_succ]
infer_instance
theorem bddAbove_iff_small {s : Set Ordinal.{u}} : BddAbove s ↔ Small.{u} s :=
⟨fun ⟨a, h⟩ => small_subset <| show s ⊆ Iic a from fun _x hx => h hx, fun h =>
⟨sup.{u, u} fun x => ((@equivShrink s h).symm x).val, le_sup_shrink_equiv h⟩⟩
theorem bddAbove_of_small (s : Set Ordinal.{u}) [h : Small.{u} s] : BddAbove s :=
bddAbove_iff_small.2 h
theorem sup_eq_sSup {s : Set Ordinal.{u}} (hs : Small.{u} s) :
(sup.{u, u} fun x => (@equivShrink s hs).symm x) = sSup s :=
let hs' := bddAbove_iff_small.2 hs
((csSup_le_iff' hs').2 (le_sup_shrink_equiv hs)).antisymm'
(sup_le fun _x => le_csSup hs' (Subtype.mem _))
theorem sSup_ord {s : Set Cardinal.{u}} (hs : BddAbove s) : (sSup s).ord = sSup (ord '' s) :=
eq_of_forall_ge_iff fun a => by
rw [csSup_le_iff'
(bddAbove_iff_small.2 (@small_image _ _ _ s (Cardinal.bddAbove_iff_small.1 hs))),
ord_le, csSup_le_iff' hs]
simp [ord_le]
theorem iSup_ord {ι} {f : ι → Cardinal} (hf : BddAbove (range f)) :
(iSup f).ord = ⨆ i, (f i).ord := by
unfold iSup
convert sSup_ord hf
-- Porting note: `change` is required.
conv_lhs => change range (ord ∘ f)
rw [range_comp]
private theorem sup_le_sup {ι ι' : Type u} (r : ι → ι → Prop) (r' : ι' → ι' → Prop)
[IsWellOrder ι r] [IsWellOrder ι' r'] {o} (ho : type r = o) (ho' : type r' = o)
(f : ∀ a < o, Ordinal.{max u v}) :
sup.{_, v} (familyOfBFamily' r ho f) ≤ sup.{_, v} (familyOfBFamily' r' ho' f) :=
sup_le fun i => by
cases'
typein_surj r'
(by
rw [ho', ← ho]
exact typein_lt_type r i) with
j hj
simp_rw [familyOfBFamily', ← hj]
apply le_sup
theorem sup_eq_sup {ι ι' : Type u} (r : ι → ι → Prop) (r' : ι' → ι' → Prop) [IsWellOrder ι r]
[IsWellOrder ι' r'] {o : Ordinal.{u}} (ho : type r = o) (ho' : type r' = o)
(f : ∀ a < o, Ordinal.{max u v}) :
sup.{_, v} (familyOfBFamily' r ho f) = sup.{_, v} (familyOfBFamily' r' ho' f) :=
sup_eq_of_range_eq.{u, u, v} (by simp)
/-- The supremum of a family of ordinals indexed by the set of ordinals less than some
`o : Ordinal.{u}`. This is a special case of `sup` over the family provided by
`familyOfBFamily`. -/
def bsup (o : Ordinal.{u}) (f : ∀ a < o, Ordinal.{max u v}) : Ordinal.{max u v} :=
sup.{_, v} (familyOfBFamily o f)
@[simp]
theorem sup_eq_bsup {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
sup.{_, v} (familyOfBFamily o f) = bsup.{_, v} o f :=
rfl
@[simp]
theorem sup_eq_bsup' {o : Ordinal.{u}} {ι} (r : ι → ι → Prop) [IsWellOrder ι r] (ho : type r = o)
(f : ∀ a < o, Ordinal.{max u v}) : sup.{_, v} (familyOfBFamily' r ho f) = bsup.{_, v} o f :=
sup_eq_sup r _ ho _ f
@[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove this
theorem sSup_eq_bsup {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
sSup (brange o f) = bsup.{_, v} o f := by
congr
rw [range_familyOfBFamily]
@[simp]
theorem bsup_eq_sup' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] (f : ι → Ordinal.{max u v}) :
bsup.{_, v} _ (bfamilyOfFamily' r f) = sup.{_, v} f := by
simp (config := { unfoldPartialApp := true }) only [← sup_eq_bsup' r, enum_typein,
familyOfBFamily', bfamilyOfFamily']
theorem bsup_eq_bsup {ι : Type u} (r r' : ι → ι → Prop) [IsWellOrder ι r] [IsWellOrder ι r']
(f : ι → Ordinal.{max u v}) :
bsup.{_, v} _ (bfamilyOfFamily' r f) = bsup.{_, v} _ (bfamilyOfFamily' r' f) := by
rw [bsup_eq_sup', bsup_eq_sup']
@[simp]
theorem bsup_eq_sup {ι : Type u} (f : ι → Ordinal.{max u v}) :
bsup.{_, v} _ (bfamilyOfFamily f) = sup.{_, v} f :=
bsup_eq_sup' _ f
@[congr]
theorem bsup_congr {o₁ o₂ : Ordinal.{u}} (f : ∀ a < o₁, Ordinal.{max u v}) (ho : o₁ = o₂) :
bsup.{_, v} o₁ f = bsup.{_, v} o₂ fun a h => f a (h.trans_eq ho.symm) := by
subst ho
-- Porting note: `rfl` is required.
rfl
theorem bsup_le_iff {o f a} : bsup.{u, v} o f ≤ a ↔ ∀ i h, f i h ≤ a :=
sup_le_iff.trans
⟨fun h i hi => by
rw [← familyOfBFamily_enum o f]
exact h _, fun h i => h _ _⟩
theorem bsup_le {o : Ordinal} {f : ∀ b < o, Ordinal} {a} :
(∀ i h, f i h ≤ a) → bsup.{u, v} o f ≤ a :=
bsup_le_iff.2
theorem le_bsup {o} (f : ∀ a < o, Ordinal) (i h) : f i h ≤ bsup o f :=
bsup_le_iff.1 le_rfl _ _
theorem lt_bsup {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) {a} :
a < bsup.{_, v} o f ↔ ∃ i hi, a < f i hi := by
simpa only [not_forall, not_le] using not_congr (@bsup_le_iff.{_, v} _ f a)
theorem IsNormal.bsup {f : Ordinal.{max u v} → Ordinal.{max u w}} (H : IsNormal f)
{o : Ordinal.{u}} :
∀ (g : ∀ a < o, Ordinal), o ≠ 0 → f (bsup.{_, v} o g) = bsup.{_, w} o fun a h => f (g a h) :=
inductionOn o fun α r _ g h => by
haveI := type_ne_zero_iff_nonempty.1 h
rw [← sup_eq_bsup' r, IsNormal.sup.{_, v, w} H, ← sup_eq_bsup' r] <;> rfl
theorem lt_bsup_of_ne_bsup {o : Ordinal.{u}} {f : ∀ a < o, Ordinal.{max u v}} :
(∀ i h, f i h ≠ bsup.{_, v} o f) ↔ ∀ i h, f i h < bsup.{_, v} o f :=
⟨fun hf _ _ => lt_of_le_of_ne (le_bsup _ _ _) (hf _ _), fun hf _ _ => ne_of_lt (hf _ _)⟩
theorem bsup_not_succ_of_ne_bsup {o : Ordinal.{u}} {f : ∀ a < o, Ordinal.{max u v}}
(hf : ∀ {i : Ordinal} (h : i < o), f i h ≠ bsup.{_, v} o f) (a) :
a < bsup.{_, v} o f → succ a < bsup.{_, v} o f := by
rw [← sup_eq_bsup] at *
exact sup_not_succ_of_ne_sup fun i => hf _
@[simp]
theorem bsup_eq_zero_iff {o} {f : ∀ a < o, Ordinal} : bsup o f = 0 ↔ ∀ i hi, f i hi = 0 := by
refine
⟨fun h i hi => ?_, fun h =>
le_antisymm (bsup_le fun i hi => Ordinal.le_zero.2 (h i hi)) (Ordinal.zero_le _)⟩
rw [← Ordinal.le_zero, ← h]
exact le_bsup f i hi
theorem lt_bsup_of_limit {o : Ordinal} {f : ∀ a < o, Ordinal}
(hf : ∀ {a a'} (ha : a < o) (ha' : a' < o), a < a' → f a ha < f a' ha')
(ho : ∀ a < o, succ a < o) (i h) : f i h < bsup o f :=
(hf _ _ <| lt_succ i).trans_le (le_bsup f (succ i) <| ho _ h)
theorem bsup_succ_of_mono {o : Ordinal} {f : ∀ a < succ o, Ordinal}
(hf : ∀ {i j} (hi hj), i ≤ j → f i hi ≤ f j hj) : bsup _ f = f o (lt_succ o) :=
le_antisymm (bsup_le fun _i hi => hf _ _ <| le_of_lt_succ hi) (le_bsup _ _ _)
@[simp]
theorem bsup_zero (f : ∀ a < (0 : Ordinal), Ordinal) : bsup 0 f = 0 :=
bsup_eq_zero_iff.2 fun i hi => (Ordinal.not_lt_zero i hi).elim
theorem bsup_const {o : Ordinal.{u}} (ho : o ≠ 0) (a : Ordinal.{max u v}) :
(bsup.{_, v} o fun _ _ => a) = a :=
le_antisymm (bsup_le fun _ _ => le_rfl) (le_bsup _ 0 (Ordinal.pos_iff_ne_zero.2 ho))
@[simp]
theorem bsup_one (f : ∀ a < (1 : Ordinal), Ordinal) : bsup 1 f = f 0 zero_lt_one := by
simp_rw [← sup_eq_bsup, sup_unique, familyOfBFamily, familyOfBFamily', typein_one_out]
theorem bsup_le_of_brange_subset {o o'} {f : ∀ a < o, Ordinal} {g : ∀ a < o', Ordinal}
(h : brange o f ⊆ brange o' g) : bsup.{u, max v w} o f ≤ bsup.{v, max u w} o' g :=
bsup_le fun i hi => by
obtain ⟨j, hj, hj'⟩ := h ⟨i, hi, rfl⟩
rw [← hj']
apply le_bsup
theorem bsup_eq_of_brange_eq {o o'} {f : ∀ a < o, Ordinal} {g : ∀ a < o', Ordinal}
(h : brange o f = brange o' g) : bsup.{u, max v w} o f = bsup.{v, max u w} o' g :=
(bsup_le_of_brange_subset.{u, v, w} h.le).antisymm (bsup_le_of_brange_subset.{v, u, w} h.ge)
/-- The least strict upper bound of a family of ordinals. -/
def lsub {ι} (f : ι → Ordinal) : Ordinal :=
sup (succ ∘ f)
@[simp]
theorem sup_eq_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) :
sup.{_, v} (succ ∘ f) = lsub.{_, v} f :=
rfl
theorem lsub_le_iff {ι : Type u} {f : ι → Ordinal.{max u v}} {a} :
lsub.{_, v} f ≤ a ↔ ∀ i, f i < a := by
convert sup_le_iff.{_, v} (f := succ ∘ f) (a := a) using 2
-- Porting note: `comp_apply` is required.
simp only [comp_apply, succ_le_iff]
theorem lsub_le {ι} {f : ι → Ordinal} {a} : (∀ i, f i < a) → lsub f ≤ a :=
lsub_le_iff.2
theorem lt_lsub {ι} (f : ι → Ordinal) (i) : f i < lsub f :=
succ_le_iff.1 (le_sup _ i)
theorem lt_lsub_iff {ι : Type u} {f : ι → Ordinal.{max u v}} {a} :
a < lsub.{_, v} f ↔ ∃ i, a ≤ f i := by
simpa only [not_forall, not_lt, not_le] using not_congr (@lsub_le_iff.{_, v} _ f a)
theorem sup_le_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) : sup.{_, v} f ≤ lsub.{_, v} f :=
sup_le fun i => (lt_lsub f i).le
theorem lsub_le_sup_succ {ι : Type u} (f : ι → Ordinal.{max u v}) :
lsub.{_, v} f ≤ succ (sup.{_, v} f) :=
lsub_le fun i => lt_succ_iff.2 (le_sup f i)
theorem sup_eq_lsub_or_sup_succ_eq_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) :
sup.{_, v} f = lsub.{_, v} f ∨ succ (sup.{_, v} f) = lsub.{_, v} f := by
cases' eq_or_lt_of_le (sup_le_lsub.{_, v} f) with h h
· exact Or.inl h
· exact Or.inr ((succ_le_of_lt h).antisymm (lsub_le_sup_succ f))
theorem sup_succ_le_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) :
succ (sup.{_, v} f) ≤ lsub.{_, v} f ↔ ∃ i, f i = sup.{_, v} f := by
refine ⟨fun h => ?_, ?_⟩
· by_contra! hf
exact (succ_le_iff.1 h).ne ((sup_le_lsub f).antisymm (lsub_le (ne_sup_iff_lt_sup.1 hf)))
rintro ⟨_, hf⟩
rw [succ_le_iff, ← hf]
exact lt_lsub _ _
theorem sup_succ_eq_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) :
succ (sup.{_, v} f) = lsub.{_, v} f ↔ ∃ i, f i = sup.{_, v} f :=
(lsub_le_sup_succ f).le_iff_eq.symm.trans (sup_succ_le_lsub f)
theorem sup_eq_lsub_iff_succ {ι : Type u} (f : ι → Ordinal.{max u v}) :
sup.{_, v} f = lsub.{_, v} f ↔ ∀ a < lsub.{_, v} f, succ a < lsub.{_, v} f := by
refine ⟨fun h => ?_, fun hf => le_antisymm (sup_le_lsub f) (lsub_le fun i => ?_)⟩
· rw [← h]
exact fun a => sup_not_succ_of_ne_sup fun i => (lsub_le_iff.1 (le_of_eq h.symm) i).ne
by_contra! hle
have heq := (sup_succ_eq_lsub f).2 ⟨i, le_antisymm (le_sup _ _) hle⟩
have :=
hf _
(by
rw [← heq]
exact lt_succ (sup f))
rw [heq] at this
exact this.false
theorem sup_eq_lsub_iff_lt_sup {ι : Type u} (f : ι → Ordinal.{max u v}) :
sup.{_, v} f = lsub.{_, v} f ↔ ∀ i, f i < sup.{_, v} f :=
⟨fun h i => by
rw [h]
apply lt_lsub, fun h => le_antisymm (sup_le_lsub f) (lsub_le h)⟩
@[simp]
theorem lsub_empty {ι} [h : IsEmpty ι] (f : ι → Ordinal) : lsub f = 0 := by
rw [← Ordinal.le_zero, lsub_le_iff]
exact h.elim
theorem lsub_pos {ι : Type u} [h : Nonempty ι] (f : ι → Ordinal.{max u v}) : 0 < lsub.{_, v} f :=
h.elim fun i => (Ordinal.zero_le _).trans_lt (lt_lsub f i)
@[simp]
theorem lsub_eq_zero_iff {ι : Type u} (f : ι → Ordinal.{max u v}) :
lsub.{_, v} f = 0 ↔ IsEmpty ι := by
refine ⟨fun h => ⟨fun i => ?_⟩, fun h => @lsub_empty _ h _⟩
have := @lsub_pos.{_, v} _ ⟨i⟩ f
rw [h] at this
exact this.false
@[simp]
theorem lsub_const {ι} [Nonempty ι] (o : Ordinal) : (lsub fun _ : ι => o) = succ o :=
sup_const (succ o)
@[simp]
theorem lsub_unique {ι} [Unique ι] (f : ι → Ordinal) : lsub f = succ (f default) :=
sup_unique _
theorem lsub_le_of_range_subset {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal}
(h : Set.range f ⊆ Set.range g) : lsub.{u, max v w} f ≤ lsub.{v, max u w} g :=
sup_le_of_range_subset.{u, v, w} (by convert Set.image_subset succ h <;> apply Set.range_comp)
theorem lsub_eq_of_range_eq {ι ι'} {f : ι → Ordinal} {g : ι' → Ordinal}
(h : Set.range f = Set.range g) : lsub.{u, max v w} f = lsub.{v, max u w} g :=
(lsub_le_of_range_subset.{u, v, w} h.le).antisymm (lsub_le_of_range_subset.{v, u, w} h.ge)
@[simp]
theorem lsub_sum {α : Type u} {β : Type v} (f : α ⊕ β → Ordinal) :
lsub.{max u v, w} f =
max (lsub.{u, max v w} fun a => f (Sum.inl a)) (lsub.{v, max u w} fun b => f (Sum.inr b)) :=
sup_sum _
theorem lsub_not_mem_range {ι : Type u} (f : ι → Ordinal.{max u v}) :
lsub.{_, v} f ∉ Set.range f := fun ⟨i, h⟩ =>
h.not_lt (lt_lsub f i)
theorem nonempty_compl_range {ι : Type u} (f : ι → Ordinal.{max u v}) : (Set.range f)ᶜ.Nonempty :=
⟨_, lsub_not_mem_range.{_, v} f⟩
@[simp]
theorem lsub_typein (o : Ordinal) : lsub.{u, u} (typein ((· < ·) : o.out.α → o.out.α → Prop)) = o :=
(lsub_le.{u, u} typein_lt_self).antisymm
(by
by_contra! h
-- Porting note: `nth_rw` → `conv_rhs` & `rw`
conv_rhs at h => rw [← type_lt o]
simpa [typein_enum] using lt_lsub.{u, u} (typein (· < ·)) (enum (· < ·) _ h))
theorem sup_typein_limit {o : Ordinal} (ho : ∀ a, a < o → succ a < o) :
sup.{u, u} (typein ((· < ·) : o.out.α → o.out.α → Prop)) = o := by
-- Porting note: `rwa` → `rw` & `assumption`
rw [(sup_eq_lsub_iff_succ.{u, u} (typein (· < ·))).2] <;> rw [lsub_typein o]; assumption
@[simp]
theorem sup_typein_succ {o : Ordinal} :
sup.{u, u} (typein ((· < ·) : (succ o).out.α → (succ o).out.α → Prop)) = o := by
cases'
sup_eq_lsub_or_sup_succ_eq_lsub.{u, u}
(typein ((· < ·) : (succ o).out.α → (succ o).out.α → Prop)) with
h h
· rw [sup_eq_lsub_iff_succ] at h
simp only [lsub_typein] at h
exact (h o (lt_succ o)).false.elim
rw [← succ_eq_succ_iff, h]
apply lsub_typein
/-- The least strict upper bound of a family of ordinals indexed by the set of ordinals less than
some `o : Ordinal.{u}`.
This is to `lsub` as `bsup` is to `sup`. -/
def blsub (o : Ordinal.{u}) (f : ∀ a < o, Ordinal.{max u v}) : Ordinal.{max u v} :=
bsup.{_, v} o fun a ha => succ (f a ha)
@[simp]
theorem bsup_eq_blsub (o : Ordinal.{u}) (f : ∀ a < o, Ordinal.{max u v}) :
(bsup.{_, v} o fun a ha => succ (f a ha)) = blsub.{_, v} o f :=
rfl
theorem lsub_eq_blsub' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r] {o} (ho : type r = o)
(f : ∀ a < o, Ordinal.{max u v}) : lsub.{_, v} (familyOfBFamily' r ho f) = blsub.{_, v} o f :=
sup_eq_bsup'.{_, v} r ho fun a ha => succ (f a ha)
theorem lsub_eq_lsub {ι ι' : Type u} (r : ι → ι → Prop) (r' : ι' → ι' → Prop) [IsWellOrder ι r]
[IsWellOrder ι' r'] {o} (ho : type r = o) (ho' : type r' = o)
(f : ∀ a < o, Ordinal.{max u v}) :
lsub.{_, v} (familyOfBFamily' r ho f) = lsub.{_, v} (familyOfBFamily' r' ho' f) := by
rw [lsub_eq_blsub', lsub_eq_blsub']
@[simp]
theorem lsub_eq_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
lsub.{_, v} (familyOfBFamily o f) = blsub.{_, v} o f :=
lsub_eq_blsub' _ _ _
@[simp]
theorem blsub_eq_lsub' {ι : Type u} (r : ι → ι → Prop) [IsWellOrder ι r]
(f : ι → Ordinal.{max u v}) : blsub.{_, v} _ (bfamilyOfFamily' r f) = lsub.{_, v} f :=
bsup_eq_sup'.{_, v} r (succ ∘ f)
theorem blsub_eq_blsub {ι : Type u} (r r' : ι → ι → Prop) [IsWellOrder ι r] [IsWellOrder ι r']
(f : ι → Ordinal.{max u v}) :
blsub.{_, v} _ (bfamilyOfFamily' r f) = blsub.{_, v} _ (bfamilyOfFamily' r' f) := by
rw [blsub_eq_lsub', blsub_eq_lsub']
@[simp]
theorem blsub_eq_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) :
blsub.{_, v} _ (bfamilyOfFamily f) = lsub.{_, v} f :=
blsub_eq_lsub' _ _
@[congr]
theorem blsub_congr {o₁ o₂ : Ordinal.{u}} (f : ∀ a < o₁, Ordinal.{max u v}) (ho : o₁ = o₂) :
blsub.{_, v} o₁ f = blsub.{_, v} o₂ fun a h => f a (h.trans_eq ho.symm) := by
subst ho
-- Porting note: `rfl` is required.
rfl
theorem blsub_le_iff {o : Ordinal.{u}} {f : ∀ a < o, Ordinal.{max u v}} {a} :
blsub.{_, v} o f ≤ a ↔ ∀ i h, f i h < a := by
convert bsup_le_iff.{_, v} (f := fun a ha => succ (f a ha)) (a := a) using 2
simp_rw [succ_le_iff]
theorem blsub_le {o : Ordinal} {f : ∀ b < o, Ordinal} {a} : (∀ i h, f i h < a) → blsub o f ≤ a :=
blsub_le_iff.2
theorem lt_blsub {o} (f : ∀ a < o, Ordinal) (i h) : f i h < blsub o f :=
blsub_le_iff.1 le_rfl _ _
theorem lt_blsub_iff {o : Ordinal.{u}} {f : ∀ b < o, Ordinal.{max u v}} {a} :
a < blsub.{_, v} o f ↔ ∃ i hi, a ≤ f i hi := by
simpa only [not_forall, not_lt, not_le] using not_congr (@blsub_le_iff.{_, v} _ f a)
theorem bsup_le_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
bsup.{_, v} o f ≤ blsub.{_, v} o f :=
bsup_le fun i h => (lt_blsub f i h).le
theorem blsub_le_bsup_succ {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
blsub.{_, v} o f ≤ succ (bsup.{_, v} o f) :=
blsub_le fun i h => lt_succ_iff.2 (le_bsup f i h)
theorem bsup_eq_blsub_or_succ_bsup_eq_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
bsup.{_, v} o f = blsub.{_, v} o f ∨ succ (bsup.{_, v} o f) = blsub.{_, v} o f := by
rw [← sup_eq_bsup, ← lsub_eq_blsub]
exact sup_eq_lsub_or_sup_succ_eq_lsub _
theorem bsup_succ_le_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
succ (bsup.{_, v} o f) ≤ blsub.{_, v} o f ↔ ∃ i hi, f i hi = bsup.{_, v} o f := by
refine ⟨fun h => ?_, ?_⟩
· by_contra! hf
exact
ne_of_lt (succ_le_iff.1 h)
(le_antisymm (bsup_le_blsub f) (blsub_le (lt_bsup_of_ne_bsup.1 hf)))
rintro ⟨_, _, hf⟩
rw [succ_le_iff, ← hf]
exact lt_blsub _ _ _
theorem bsup_succ_eq_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
succ (bsup.{_, v} o f) = blsub.{_, v} o f ↔ ∃ i hi, f i hi = bsup.{_, v} o f :=
(blsub_le_bsup_succ f).le_iff_eq.symm.trans (bsup_succ_le_blsub f)
theorem bsup_eq_blsub_iff_succ {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
bsup.{_, v} o f = blsub.{_, v} o f ↔ ∀ a < blsub.{_, v} o f, succ a < blsub.{_, v} o f := by
rw [← sup_eq_bsup, ← lsub_eq_blsub]
apply sup_eq_lsub_iff_succ
theorem bsup_eq_blsub_iff_lt_bsup {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
bsup.{_, v} o f = blsub.{_, v} o f ↔ ∀ i hi, f i hi < bsup.{_, v} o f :=
⟨fun h i => by
rw [h]
apply lt_blsub, fun h => le_antisymm (bsup_le_blsub f) (blsub_le h)⟩
theorem bsup_eq_blsub_of_lt_succ_limit {o : Ordinal.{u}} (ho : IsLimit o)
{f : ∀ a < o, Ordinal.{max u v}} (hf : ∀ a ha, f a ha < f (succ a) (ho.2 a ha)) :
bsup.{_, v} o f = blsub.{_, v} o f := by
rw [bsup_eq_blsub_iff_lt_bsup]
exact fun i hi => (hf i hi).trans_le (le_bsup f _ _)
theorem blsub_succ_of_mono {o : Ordinal.{u}} {f : ∀ a < succ o, Ordinal.{max u v}}
(hf : ∀ {i j} (hi hj), i ≤ j → f i hi ≤ f j hj) : blsub.{_, v} _ f = succ (f o (lt_succ o)) :=
bsup_succ_of_mono fun {_ _} hi hj h => succ_le_succ (hf hi hj h)
@[simp]
theorem blsub_eq_zero_iff {o} {f : ∀ a < o, Ordinal} : blsub o f = 0 ↔ o = 0 := by
rw [← lsub_eq_blsub, lsub_eq_zero_iff]
exact out_empty_iff_eq_zero
-- Porting note: `rwa` → `rw`
@[simp]
theorem blsub_zero (f : ∀ a < (0 : Ordinal), Ordinal) : blsub 0 f = 0 := by rw [blsub_eq_zero_iff]
theorem blsub_pos {o : Ordinal} (ho : 0 < o) (f : ∀ a < o, Ordinal) : 0 < blsub o f :=
(Ordinal.zero_le _).trans_lt (lt_blsub f 0 ho)
theorem blsub_type {α : Type u} (r : α → α → Prop) [IsWellOrder α r]
(f : ∀ a < type r, Ordinal.{max u v}) :
blsub.{_, v} (type r) f = lsub.{_, v} fun a => f (typein r a) (typein_lt_type _ _) :=
eq_of_forall_ge_iff fun o => by
rw [blsub_le_iff, lsub_le_iff]
exact ⟨fun H b => H _ _, fun H i h => by simpa only [typein_enum] using H (enum r i h)⟩
theorem blsub_const {o : Ordinal} (ho : o ≠ 0) (a : Ordinal) :
(blsub.{u, v} o fun _ _ => a) = succ a :=
bsup_const.{u, v} ho (succ a)
@[simp]
theorem blsub_one (f : ∀ a < (1 : Ordinal), Ordinal) : blsub 1 f = succ (f 0 zero_lt_one) :=
bsup_one _
@[simp]
theorem blsub_id : ∀ o, (blsub.{u, u} o fun x _ => x) = o :=
lsub_typein
theorem bsup_id_limit {o : Ordinal} : (∀ a < o, succ a < o) → (bsup.{u, u} o fun x _ => x) = o :=
sup_typein_limit
@[simp]
theorem bsup_id_succ (o) : (bsup.{u, u} (succ o) fun x _ => x) = o :=
sup_typein_succ
theorem blsub_le_of_brange_subset {o o'} {f : ∀ a < o, Ordinal} {g : ∀ a < o', Ordinal}
(h : brange o f ⊆ brange o' g) : blsub.{u, max v w} o f ≤ blsub.{v, max u w} o' g :=
bsup_le_of_brange_subset.{u, v, w} fun a ⟨b, hb, hb'⟩ => by
obtain ⟨c, hc, hc'⟩ := h ⟨b, hb, rfl⟩
simp_rw [← hc'] at hb'
exact ⟨c, hc, hb'⟩
theorem blsub_eq_of_brange_eq {o o'} {f : ∀ a < o, Ordinal} {g : ∀ a < o', Ordinal}
(h : { o | ∃ i hi, f i hi = o } = { o | ∃ i hi, g i hi = o }) :
blsub.{u, max v w} o f = blsub.{v, max u w} o' g :=
(blsub_le_of_brange_subset.{u, v, w} h.le).antisymm (blsub_le_of_brange_subset.{v, u, w} h.ge)
theorem bsup_comp {o o' : Ordinal.{max u v}} {f : ∀ a < o, Ordinal.{max u v w}}
(hf : ∀ {i j} (hi) (hj), i ≤ j → f i hi ≤ f j hj) {g : ∀ a < o', Ordinal.{max u v}}
(hg : blsub.{_, u} o' g = o) :
(bsup.{_, w} o' fun a ha => f (g a ha) (by rw [← hg]; apply lt_blsub)) = bsup.{_, w} o f := by
apply le_antisymm <;> refine bsup_le fun i hi => ?_
· apply le_bsup
· rw [← hg, lt_blsub_iff] at hi
rcases hi with ⟨j, hj, hj'⟩
exact (hf _ _ hj').trans (le_bsup _ _ _)
theorem blsub_comp {o o' : Ordinal.{max u v}} {f : ∀ a < o, Ordinal.{max u v w}}
(hf : ∀ {i j} (hi) (hj), i ≤ j → f i hi ≤ f j hj) {g : ∀ a < o', Ordinal.{max u v}}
(hg : blsub.{_, u} o' g = o) :
(blsub.{_, w} o' fun a ha => f (g a ha) (by rw [← hg]; apply lt_blsub)) = blsub.{_, w} o f :=
@bsup_comp.{u, v, w} o _ (fun a ha => succ (f a ha))
(fun {_ _} _ _ h => succ_le_succ_iff.2 (hf _ _ h)) g hg
theorem IsNormal.bsup_eq {f : Ordinal.{u} → Ordinal.{max u v}} (H : IsNormal f) {o : Ordinal.{u}}
(h : IsLimit o) : (Ordinal.bsup.{_, v} o fun x _ => f x) = f o := by
rw [← IsNormal.bsup.{u, u, v} H (fun x _ => x) h.1, bsup_id_limit h.2]
theorem IsNormal.blsub_eq {f : Ordinal.{u} → Ordinal.{max u v}} (H : IsNormal f) {o : Ordinal.{u}}
(h : IsLimit o) : (blsub.{_, v} o fun x _ => f x) = f o := by
rw [← IsNormal.bsup_eq.{u, v} H h, bsup_eq_blsub_of_lt_succ_limit h]
exact fun a _ => H.1 a
theorem isNormal_iff_lt_succ_and_bsup_eq {f : Ordinal.{u} → Ordinal.{max u v}} :
IsNormal f ↔ (∀ a, f a < f (succ a)) ∧ ∀ o, IsLimit o → (bsup.{_, v} o fun x _ => f x) = f o :=
⟨fun h => ⟨h.1, @IsNormal.bsup_eq f h⟩, fun ⟨h₁, h₂⟩ =>
⟨h₁, fun o ho a => by
rw [← h₂ o ho]
exact bsup_le_iff⟩⟩
theorem isNormal_iff_lt_succ_and_blsub_eq {f : Ordinal.{u} → Ordinal.{max u v}} :
IsNormal f ↔ (∀ a, f a < f (succ a)) ∧
∀ o, IsLimit o → (blsub.{_, v} o fun x _ => f x) = f o := by
rw [isNormal_iff_lt_succ_and_bsup_eq.{u, v}, and_congr_right_iff]
intro h
constructor <;> intro H o ho <;> have := H o ho <;>
rwa [← bsup_eq_blsub_of_lt_succ_limit ho fun a _ => h a] at *
theorem IsNormal.eq_iff_zero_and_succ {f g : Ordinal.{u} → Ordinal.{u}} (hf : IsNormal f)
(hg : IsNormal g) : f = g ↔ f 0 = g 0 ∧ ∀ a, f a = g a → f (succ a) = g (succ a) :=
⟨fun h => by simp [h], fun ⟨h₁, h₂⟩ =>
funext fun a => by
induction' a using limitRecOn with _ _ _ ho H
any_goals solve_by_elim
rw [← IsNormal.bsup_eq.{u, u} hf ho, ← IsNormal.bsup_eq.{u, u} hg ho]
congr
ext b hb
exact H b hb⟩
/-- A two-argument version of `Ordinal.blsub`.
We don't develop a full API for this, since it's only used in a handful of existence results. -/
def blsub₂ (o₁ o₂ : Ordinal) (op : {a : Ordinal} → (a < o₁) → {b : Ordinal} → (b < o₂) → Ordinal) :
Ordinal :=
lsub (fun x : o₁.out.α × o₂.out.α => op (typein_lt_self x.1) (typein_lt_self x.2))
theorem lt_blsub₂ {o₁ o₂ : Ordinal}
(op : {a : Ordinal} → (a < o₁) → {b : Ordinal} → (b < o₂) → Ordinal) {a b : Ordinal}
(ha : a < o₁) (hb : b < o₂) : op ha hb < blsub₂ o₁ o₂ op := by
convert lt_lsub _ (Prod.mk (enum (· < ·) a (by rwa [type_lt]))
(enum (· < ·) b (by rwa [type_lt])))
simp only [typein_enum]
/-! ### Minimum excluded ordinals -/
/-- The minimum excluded ordinal in a family of ordinals. -/
def mex {ι : Type u} (f : ι → Ordinal.{max u v}) : Ordinal :=
sInf (Set.range f)ᶜ
theorem mex_not_mem_range {ι : Type u} (f : ι → Ordinal.{max u v}) : mex.{_, v} f ∉ Set.range f :=
csInf_mem (nonempty_compl_range.{_, v} f)
theorem le_mex_of_forall {ι : Type u} {f : ι → Ordinal.{max u v}} {a : Ordinal}
(H : ∀ b < a, ∃ i, f i = b) : a ≤ mex.{_, v} f := by
by_contra! h
exact mex_not_mem_range f (H _ h)
theorem ne_mex {ι : Type u} (f : ι → Ordinal.{max u v}) : ∀ i, f i ≠ mex.{_, v} f := by
simpa using mex_not_mem_range.{_, v} f
theorem mex_le_of_ne {ι} {f : ι → Ordinal} {a} (ha : ∀ i, f i ≠ a) : mex f ≤ a :=
csInf_le' (by simp [ha])
theorem exists_of_lt_mex {ι} {f : ι → Ordinal} {a} (ha : a < mex f) : ∃ i, f i = a := by
by_contra! ha'
exact ha.not_le (mex_le_of_ne ha')
theorem mex_le_lsub {ι : Type u} (f : ι → Ordinal.{max u v}) : mex.{_, v} f ≤ lsub.{_, v} f :=
csInf_le' (lsub_not_mem_range f)
theorem mex_monotone {α β : Type u} {f : α → Ordinal.{max u v}} {g : β → Ordinal.{max u v}}
(h : Set.range f ⊆ Set.range g) : mex.{_, v} f ≤ mex.{_, v} g := by
refine mex_le_of_ne fun i hi => ?_
cases' h ⟨i, rfl⟩ with j hj
rw [← hj] at hi
exact ne_mex g j hi
theorem mex_lt_ord_succ_mk {ι : Type u} (f : ι → Ordinal.{u}) :
mex.{_, u} f < (succ #ι).ord := by
by_contra! h
apply (lt_succ #ι).not_le
have H := fun a => exists_of_lt_mex ((typein_lt_self a).trans_le h)
let g : (succ #ι).ord.out.α → ι := fun a => Classical.choose (H a)
have hg : Injective g := fun a b h' => by
have Hf : ∀ x, f (g x) =
typein ((· < ·) : (succ #ι).ord.out.α → (succ #ι).ord.out.α → Prop) x :=
fun a => Classical.choose_spec (H a)
apply_fun f at h'
rwa [Hf, Hf, typein_inj] at h'
convert Cardinal.mk_le_of_injective hg
rw [Cardinal.mk_ord_out (succ #ι)]
/-- The minimum excluded ordinal of a family of ordinals indexed by the set of ordinals less than
some `o : Ordinal.{u}`. This is a special case of `mex` over the family provided by
`familyOfBFamily`.
This is to `mex` as `bsup` is to `sup`. -/
def bmex (o : Ordinal) (f : ∀ a < o, Ordinal) : Ordinal :=
mex (familyOfBFamily o f)
theorem bmex_not_mem_brange {o : Ordinal} (f : ∀ a < o, Ordinal) : bmex o f ∉ brange o f := by
rw [← range_familyOfBFamily]
apply mex_not_mem_range
theorem le_bmex_of_forall {o : Ordinal} (f : ∀ a < o, Ordinal) {a : Ordinal}
(H : ∀ b < a, ∃ i hi, f i hi = b) : a ≤ bmex o f := by
by_contra! h
exact bmex_not_mem_brange f (H _ h)
theorem ne_bmex {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) {i} (hi) :
f i hi ≠ bmex.{_, v} o f := by
convert (config := {transparency := .default})
ne_mex.{_, v} (familyOfBFamily o f) (enum (· < ·) i (by rwa [type_lt])) using 2
-- Porting note: `familyOfBFamily_enum` → `typein_enum`
rw [typein_enum]
theorem bmex_le_of_ne {o : Ordinal} {f : ∀ a < o, Ordinal} {a} (ha : ∀ i hi, f i hi ≠ a) :
bmex o f ≤ a :=
mex_le_of_ne fun _i => ha _ _
theorem exists_of_lt_bmex {o : Ordinal} {f : ∀ a < o, Ordinal} {a} (ha : a < bmex o f) :
∃ i hi, f i hi = a := by
cases' exists_of_lt_mex ha with i hi
exact ⟨_, typein_lt_self i, hi⟩
theorem bmex_le_blsub {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{max u v}) :
bmex.{_, v} o f ≤ blsub.{_, v} o f :=
mex_le_lsub _
theorem bmex_monotone {o o' : Ordinal.{u}}
{f : ∀ a < o, Ordinal.{max u v}} {g : ∀ a < o', Ordinal.{max u v}}
(h : brange o f ⊆ brange o' g) : bmex.{_, v} o f ≤ bmex.{_, v} o' g :=
mex_monotone (by rwa [range_familyOfBFamily, range_familyOfBFamily])
theorem bmex_lt_ord_succ_card {o : Ordinal.{u}} (f : ∀ a < o, Ordinal.{u}) :
bmex.{_, u} o f < (succ o.card).ord := by
rw [← mk_ordinal_out]
exact mex_lt_ord_succ_mk (familyOfBFamily o f)
end Ordinal
/-! ### Results about injectivity and surjectivity -/
theorem not_surjective_of_ordinal {α : Type u} (f : α → Ordinal.{u}) : ¬Surjective f := fun h =>
Ordinal.lsub_not_mem_range.{u, u} f (h _)
theorem not_injective_of_ordinal {α : Type u} (f : Ordinal.{u} → α) : ¬Injective f := fun h =>
not_surjective_of_ordinal _ (invFun_surjective h)
theorem not_surjective_of_ordinal_of_small {α : Type v} [Small.{u} α] (f : α → Ordinal.{u}) :
¬Surjective f := fun h => not_surjective_of_ordinal _ (h.comp (equivShrink _).symm.surjective)
theorem not_injective_of_ordinal_of_small {α : Type v} [Small.{u} α] (f : Ordinal.{u} → α) :
¬Injective f := fun h => not_injective_of_ordinal _ ((equivShrink _).injective.comp h)
/-- The type of ordinals in universe `u` is not `Small.{u}`. This is the type-theoretic analog of
the Burali-Forti paradox. -/
theorem not_small_ordinal : ¬Small.{u} Ordinal.{max u v} := fun h =>
@not_injective_of_ordinal_of_small _ h _ fun _a _b => Ordinal.lift_inj.{v, u}.1
/-! ### Enumerating unbounded sets of ordinals with ordinals -/
namespace Ordinal
section
/-- Enumerator function for an unbounded set of ordinals. -/
def enumOrd (S : Set Ordinal.{u}) : Ordinal → Ordinal :=
lt_wf.fix fun o f => sInf (S ∩ Set.Ici (blsub.{u, u} o f))
variable {S : Set Ordinal.{u}}
/-- The equation that characterizes `enumOrd` definitionally. This isn't the nicest expression to
work with, so consider using `enumOrd_def` instead. -/
theorem enumOrd_def' (o) :
enumOrd S o = sInf (S ∩ Set.Ici (blsub.{u, u} o fun a _ => enumOrd S a)) :=
lt_wf.fix_eq _ _
/-- The set in `enumOrd_def'` is nonempty. -/
theorem enumOrd_def'_nonempty (hS : Unbounded (· < ·) S) (a) : (S ∩ Set.Ici a).Nonempty :=
let ⟨b, hb, hb'⟩ := hS a
⟨b, hb, le_of_not_gt hb'⟩
private theorem enumOrd_mem_aux (hS : Unbounded (· < ·) S) (o) :
enumOrd S o ∈ S ∩ Set.Ici (blsub.{u, u} o fun c _ => enumOrd S c) := by
rw [enumOrd_def']
exact csInf_mem (enumOrd_def'_nonempty hS _)
theorem enumOrd_mem (hS : Unbounded (· < ·) S) (o) : enumOrd S o ∈ S :=
(enumOrd_mem_aux hS o).left
theorem blsub_le_enumOrd (hS : Unbounded (· < ·) S) (o) :
(blsub.{u, u} o fun c _ => enumOrd S c) ≤ enumOrd S o :=
(enumOrd_mem_aux hS o).right
theorem enumOrd_strictMono (hS : Unbounded (· < ·) S) : StrictMono (enumOrd S) := fun _ _ h =>
(lt_blsub.{u, u} _ _ h).trans_le (blsub_le_enumOrd hS _)
/-- A more workable definition for `enumOrd`. -/
theorem enumOrd_def (o) : enumOrd S o = sInf (S ∩ { b | ∀ c, c < o → enumOrd S c < b }) := by
rw [enumOrd_def']
congr; ext
exact ⟨fun h a hao => (lt_blsub.{u, u} _ _ hao).trans_le h, blsub_le⟩
/-- The set in `enumOrd_def` is nonempty. -/
theorem enumOrd_def_nonempty (hS : Unbounded (· < ·) S) {o} :
{ x | x ∈ S ∧ ∀ c, c < o → enumOrd S c < x }.Nonempty :=
⟨_, enumOrd_mem hS o, fun _ b => enumOrd_strictMono hS b⟩
@[simp]
theorem enumOrd_range {f : Ordinal → Ordinal} (hf : StrictMono f) : enumOrd (range f) = f :=
funext fun o => by
apply Ordinal.induction o
intro a H
rw [enumOrd_def a]
have Hfa : f a ∈ range f ∩ { b | ∀ c, c < a → enumOrd (range f) c < b } :=
⟨mem_range_self a, fun b hb => by
rw [H b hb]
exact hf hb⟩
refine (csInf_le' Hfa).antisymm ((le_csInf_iff'' ⟨_, Hfa⟩).2 ?_)
rintro _ ⟨⟨c, rfl⟩, hc : ∀ b < a, enumOrd (range f) b < f c⟩
rw [hf.le_iff_le]
contrapose! hc
exact ⟨c, hc, (H c hc).ge⟩
@[simp]
theorem enumOrd_univ : enumOrd Set.univ = id := by
rw [← range_id]
exact enumOrd_range strictMono_id
@[simp]
theorem enumOrd_zero : enumOrd S 0 = sInf S := by
rw [enumOrd_def]
simp [Ordinal.not_lt_zero]
theorem enumOrd_succ_le {a b} (hS : Unbounded (· < ·) S) (ha : a ∈ S) (hb : enumOrd S b < a) :
enumOrd S (succ b) ≤ a := by
rw [enumOrd_def]
exact
csInf_le' ⟨ha, fun c hc => ((enumOrd_strictMono hS).monotone (le_of_lt_succ hc)).trans_lt hb⟩
theorem enumOrd_le_of_subset {S T : Set Ordinal} (hS : Unbounded (· < ·) S) (hST : S ⊆ T) (a) :
enumOrd T a ≤ enumOrd S a := by
apply Ordinal.induction a
intro b H
rw [enumOrd_def]
exact csInf_le' ⟨hST (enumOrd_mem hS b), fun c h => (H c h).trans_lt (enumOrd_strictMono hS h)⟩
theorem enumOrd_surjective (hS : Unbounded (· < ·) S) : ∀ s ∈ S, ∃ a, enumOrd S a = s := fun s hs =>
⟨sSup { a | enumOrd S a ≤ s }, by
apply le_antisymm
· rw [enumOrd_def]
refine csInf_le' ⟨hs, fun a ha => ?_⟩
have : enumOrd S 0 ≤ s := by
rw [enumOrd_zero]
exact csInf_le' hs
-- Porting note: `flip` is required to infer a metavariable.
rcases flip exists_lt_of_lt_csSup ha ⟨0, this⟩ with ⟨b, hb, hab⟩
exact (enumOrd_strictMono hS hab).trans_le hb
· by_contra! h
exact
(le_csSup ⟨s, fun a => (lt_wf.self_le_of_strictMono (enumOrd_strictMono hS) a).trans⟩
(enumOrd_succ_le hS hs h)).not_lt
(lt_succ _)⟩
/-- An order isomorphism between an unbounded set of ordinals and the ordinals. -/
def enumOrdOrderIso (hS : Unbounded (· < ·) S) : Ordinal ≃o S :=
StrictMono.orderIsoOfSurjective (fun o => ⟨_, enumOrd_mem hS o⟩) (enumOrd_strictMono hS) fun s =>
let ⟨a, ha⟩ := enumOrd_surjective hS s s.prop
⟨a, Subtype.eq ha⟩
theorem range_enumOrd (hS : Unbounded (· < ·) S) : range (enumOrd S) = S := by
rw [range_eq_iff]
exact ⟨enumOrd_mem hS, enumOrd_surjective hS⟩
/-- A characterization of `enumOrd`: it is the unique strict monotonic function with range `S`. -/
theorem eq_enumOrd (f : Ordinal → Ordinal) (hS : Unbounded (· < ·) S) :
StrictMono f ∧ range f = S ↔ f = enumOrd S := by
constructor
· rintro ⟨h₁, h₂⟩
rwa [← lt_wf.eq_strictMono_iff_eq_range h₁ (enumOrd_strictMono hS), range_enumOrd hS]
· rintro rfl
exact ⟨enumOrd_strictMono hS, range_enumOrd hS⟩
end
/-! ### Casting naturals into ordinals, compatibility with operations -/
@[simp]
theorem one_add_natCast (m : ℕ) : 1 + (m : Ordinal) = succ m := by
rw [← Nat.cast_one, ← Nat.cast_add, add_comm]
rfl
@[deprecated (since := "2024-04-17")]
alias one_add_nat_cast := one_add_natCast
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem one_add_ofNat (m : ℕ) [m.AtLeastTwo] :
1 + (no_index (OfNat.ofNat m : Ordinal)) = Order.succ (OfNat.ofNat m : Ordinal) :=
one_add_natCast m
@[simp, norm_cast]
theorem natCast_mul (m : ℕ) : ∀ n : ℕ, ((m * n : ℕ) : Ordinal) = m * n
| 0 => by simp
| n + 1 => by rw [Nat.mul_succ, Nat.cast_add, natCast_mul m n, Nat.cast_succ, mul_add_one]
@[deprecated (since := "2024-04-17")]
alias nat_cast_mul := natCast_mul
/-- Alias of `Nat.cast_le`, specialized to `Ordinal` --/
theorem natCast_le {m n : ℕ} : (m : Ordinal) ≤ n ↔ m ≤ n := by
rw [← Cardinal.ord_nat, ← Cardinal.ord_nat, Cardinal.ord_le_ord, Cardinal.natCast_le]
@[deprecated (since := "2024-04-17")]
alias nat_cast_le := natCast_le
/-- Alias of `Nat.cast_inj`, specialized to `Ordinal` --/
theorem natCast_inj {m n : ℕ} : (m : Ordinal) = n ↔ m = n := by
simp only [le_antisymm_iff, natCast_le]
@[deprecated (since := "2024-04-17")]
alias nat_cast_inj := natCast_inj
instance charZero : CharZero Ordinal where
cast_injective _ _ := natCast_inj.mp
/-- Alias of `Nat.cast_lt`, specialized to `Ordinal` --/
theorem natCast_lt {m n : ℕ} : (m : Ordinal) < n ↔ m < n := Nat.cast_lt
@[deprecated (since := "2024-04-17")]
alias nat_cast_lt := natCast_lt
/-- Alias of `Nat.cast_eq_zero`, specialized to `Ordinal` --/
theorem natCast_eq_zero {n : ℕ} : (n : Ordinal) = 0 ↔ n = 0 := Nat.cast_eq_zero
@[deprecated (since := "2024-04-17")]
alias nat_cast_eq_zero := natCast_eq_zero
/-- Alias of `Nat.cast_eq_zero`, specialized to `Ordinal` --/
theorem natCast_ne_zero {n : ℕ} : (n : Ordinal) ≠ 0 ↔ n ≠ 0 := Nat.cast_ne_zero
@[deprecated (since := "2024-04-17")]
alias nat_cast_ne_zero := natCast_ne_zero
/-- Alias of `Nat.cast_pos'`, specialized to `Ordinal` --/
theorem natCast_pos {n : ℕ} : (0 : Ordinal) < n ↔ 0 < n := Nat.cast_pos'
@[deprecated (since := "2024-04-17")]
alias nat_cast_pos := natCast_pos
@[simp, norm_cast]
theorem natCast_sub (m n : ℕ) : ((m - n : ℕ) : Ordinal) = m - n := by
rcases le_total m n with h | h
· rw [tsub_eq_zero_iff_le.2 h, Ordinal.sub_eq_zero_iff_le.2 (natCast_le.2 h)]
rfl
· apply (add_left_cancel n).1
rw [← Nat.cast_add, add_tsub_cancel_of_le h, Ordinal.add_sub_cancel_of_le (natCast_le.2 h)]
@[deprecated (since := "2024-04-17")]
alias nat_cast_sub := natCast_sub
@[simp, norm_cast]
theorem natCast_div (m n : ℕ) : ((m / n : ℕ) : Ordinal) = m / n := by
rcases eq_or_ne n 0 with (rfl | hn)
· simp
· have hn' := natCast_ne_zero.2 hn
apply le_antisymm
· rw [le_div hn', ← natCast_mul, natCast_le, mul_comm]
apply Nat.div_mul_le_self
· rw [div_le hn', ← add_one_eq_succ, ← Nat.cast_succ, ← natCast_mul, natCast_lt, mul_comm, ←
Nat.div_lt_iff_lt_mul (Nat.pos_of_ne_zero hn)]
apply Nat.lt_succ_self
@[deprecated (since := "2024-04-17")]
alias nat_cast_div := natCast_div
@[simp, norm_cast]
theorem natCast_mod (m n : ℕ) : ((m % n : ℕ) : Ordinal) = m % n := by
rw [← add_left_cancel, div_add_mod, ← natCast_div, ← natCast_mul, ← Nat.cast_add,
Nat.div_add_mod]
@[deprecated (since := "2024-04-17")]
alias nat_cast_mod := natCast_mod
@[simp]
theorem lift_natCast : ∀ n : ℕ, lift.{u, v} n = n
| 0 => by simp
| n + 1 => by simp [lift_natCast n]
@[deprecated (since := "2024-04-17")]
alias lift_nat_cast := lift_natCast
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem lift_ofNat (n : ℕ) [n.AtLeastTwo] :
lift.{u, v} (no_index (OfNat.ofNat n)) = OfNat.ofNat n :=
lift_natCast n
end Ordinal
/-! ### Properties of `omega` -/
namespace Cardinal
open Ordinal
@[simp]
theorem ord_aleph0 : ord.{u} ℵ₀ = ω :=
le_antisymm (ord_le.2 <| le_rfl) <|
le_of_forall_lt fun o h => by
rcases Ordinal.lt_lift_iff.1 h with ⟨o, rfl, h'⟩
rw [lt_ord, ← lift_card, lift_lt_aleph0, ← typein_enum (· < ·) h']
exact lt_aleph0_iff_fintype.2 ⟨Set.fintypeLTNat _⟩
@[simp]
theorem add_one_of_aleph0_le {c} (h : ℵ₀ ≤ c) : c + 1 = c := by
rw [add_comm, ← card_ord c, ← card_one, ← card_add, one_add_of_omega_le]
rwa [← ord_aleph0, ord_le_ord]
end Cardinal
namespace Ordinal
theorem lt_add_of_limit {a b c : Ordinal.{u}} (h : IsLimit c) :
a < b + c ↔ ∃ c' < c, a < b + c' := by
-- Porting note: `bex_def` is required.
rw [← IsNormal.bsup_eq.{u, u} (add_isNormal b) h, lt_bsup, bex_def]
theorem lt_omega {o : Ordinal} : o < ω ↔ ∃ n : ℕ, o = n := by
simp_rw [← Cardinal.ord_aleph0, Cardinal.lt_ord, lt_aleph0, card_eq_nat]
theorem nat_lt_omega (n : ℕ) : ↑n < ω :=
lt_omega.2 ⟨_, rfl⟩
theorem omega_pos : 0 < ω :=
nat_lt_omega 0
theorem omega_ne_zero : ω ≠ 0 :=
omega_pos.ne'
theorem one_lt_omega : 1 < ω := by simpa only [Nat.cast_one] using nat_lt_omega 1
theorem omega_isLimit : IsLimit ω :=
⟨omega_ne_zero, fun o h => by
let ⟨n, e⟩ := lt_omega.1 h
rw [e]; exact nat_lt_omega (n + 1)⟩
theorem omega_le {o : Ordinal} : ω ≤ o ↔ ∀ n : ℕ, ↑n ≤ o :=
⟨fun h n => (nat_lt_omega _).le.trans h, fun H =>
le_of_forall_lt fun a h => by
let ⟨n, e⟩ := lt_omega.1 h
rw [e, ← succ_le_iff]; exact H (n + 1)⟩
@[simp]
theorem sup_natCast : sup Nat.cast = ω :=
(sup_le fun n => (nat_lt_omega n).le).antisymm <| omega_le.2 <| le_sup _
@[deprecated (since := "2024-04-17")]
alias sup_nat_cast := sup_natCast
theorem nat_lt_limit {o} (h : IsLimit o) : ∀ n : ℕ, ↑n < o
| 0 => lt_of_le_of_ne (Ordinal.zero_le o) h.1.symm
| n + 1 => h.2 _ (nat_lt_limit h n)
theorem omega_le_of_isLimit {o} (h : IsLimit o) : ω ≤ o :=
omega_le.2 fun n => le_of_lt <| nat_lt_limit h n
theorem isLimit_iff_omega_dvd {a : Ordinal} : IsLimit a ↔ a ≠ 0 ∧ ω ∣ a := by
refine ⟨fun l => ⟨l.1, ⟨a / ω, le_antisymm ?_ (mul_div_le _ _)⟩⟩, fun h => ?_⟩
· refine (limit_le l).2 fun x hx => le_of_lt ?_
rw [← div_lt omega_ne_zero, ← succ_le_iff, le_div omega_ne_zero, mul_succ,
add_le_of_limit omega_isLimit]
intro b hb
rcases lt_omega.1 hb with ⟨n, rfl⟩
exact
(add_le_add_right (mul_div_le _ _) _).trans
(lt_sub.1 <| nat_lt_limit (sub_isLimit l hx) _).le
· rcases h with ⟨a0, b, rfl⟩
refine mul_isLimit_left omega_isLimit (Ordinal.pos_iff_ne_zero.2 <| mt ?_ a0)
intro e
simp only [e, mul_zero]
theorem add_mul_limit_aux {a b c : Ordinal} (ba : b + a = a) (l : IsLimit c)
(IH : ∀ c' < c, (a + b) * succ c' = a * succ c' + b) : (a + b) * c = a * c :=
le_antisymm
((mul_le_of_limit l).2 fun c' h => by
apply (mul_le_mul_left' (le_succ c') _).trans
rw [IH _ h]
apply (add_le_add_left _ _).trans
· rw [← mul_succ]
exact mul_le_mul_left' (succ_le_of_lt <| l.2 _ h) _
· rw [← ba]
exact le_add_right _ _)
(mul_le_mul_right' (le_add_right _ _) _)
theorem add_mul_succ {a b : Ordinal} (c) (ba : b + a = a) : (a + b) * succ c = a * succ c + b := by
induction c using limitRecOn with
| H₁ => simp only [succ_zero, mul_one]
| H₂ c IH =>
rw [mul_succ, IH, ← add_assoc, add_assoc _ b, ba, ← mul_succ]
| H₃ c l IH =>
-- Porting note: Unused.
-- have := add_mul_limit_aux ba l IH
rw [mul_succ, add_mul_limit_aux ba l IH, mul_succ, add_assoc]
theorem add_mul_limit {a b c : Ordinal} (ba : b + a = a) (l : IsLimit c) : (a + b) * c = a * c :=
add_mul_limit_aux ba l fun c' _ => add_mul_succ c' ba
theorem add_le_of_forall_add_lt {a b c : Ordinal} (hb : 0 < b) (h : ∀ d < b, a + d < c) :
a + b ≤ c := by
have H : a + (c - a) = c :=
Ordinal.add_sub_cancel_of_le
(by
rw [← add_zero a]
exact (h _ hb).le)
rw [← H]
apply add_le_add_left _ a
by_contra! hb
exact (h _ hb).ne H
theorem IsNormal.apply_omega {f : Ordinal.{u} → Ordinal.{u}} (hf : IsNormal f) :
Ordinal.sup.{0, u} (f ∘ Nat.cast) = f ω := by rw [← sup_natCast, IsNormal.sup.{0, u, u} hf]
@[simp]
theorem sup_add_nat (o : Ordinal) : (sup fun n : ℕ => o + n) = o + ω :=
(add_isNormal o).apply_omega
@[simp]
theorem sup_mul_nat (o : Ordinal) : (sup fun n : ℕ => o * n) = o * ω := by
rcases eq_zero_or_pos o with (rfl | ho)
· rw [zero_mul]
exact sup_eq_zero_iff.2 fun n => zero_mul (n : Ordinal)
· exact (mul_isNormal ho).apply_omega
end Ordinal
variable {α : Type u} {r : α → α → Prop} {a b : α}
namespace Acc
/-- The rank of an element `a` accessible under a relation `r` is defined inductively as the
smallest ordinal greater than the ranks of all elements below it (i.e. elements `b` such that
`r b a`). -/
noncomputable def rank (h : Acc r a) : Ordinal.{u} :=
Acc.recOn h fun a _h ih => Ordinal.sup.{u, u} fun b : { b // r b a } => Order.succ <| ih b b.2
theorem rank_eq (h : Acc r a) :
h.rank = Ordinal.sup.{u, u} fun b : { b // r b a } => Order.succ (h.inv b.2).rank := by
change (Acc.intro a fun _ => h.inv).rank = _
rfl
/-- if `r a b` then the rank of `a` is less than the rank of `b`. -/
theorem rank_lt_of_rel (hb : Acc r b) (h : r a b) : (hb.inv h).rank < hb.rank :=
(Order.lt_succ _).trans_le <| by
rw [hb.rank_eq]
refine le_trans ?_ (Ordinal.le_sup _ ⟨a, h⟩)
rfl
end Acc
namespace WellFounded
variable (hwf : WellFounded r)
/-- The rank of an element `a` under a well-founded relation `r` is defined inductively as the
smallest ordinal greater than the ranks of all elements below it (i.e. elements `b` such that
`r b a`). -/
noncomputable def rank (a : α) : Ordinal.{u} :=
(hwf.apply a).rank
theorem rank_eq :
hwf.rank a = Ordinal.sup.{u, u} fun b : { b // r b a } => Order.succ <| hwf.rank b := by
rw [rank, Acc.rank_eq]
rfl
theorem rank_lt_of_rel (h : r a b) : hwf.rank a < hwf.rank b :=
Acc.rank_lt_of_rel _ h
theorem rank_strictMono [Preorder α] [WellFoundedLT α] :
StrictMono (rank <| @wellFounded_lt α _ _) := fun _ _ => rank_lt_of_rel _
theorem rank_strictAnti [Preorder α] [WellFoundedGT α] :
StrictAnti (rank <| @wellFounded_gt α _ _) := fun _ _ => rank_lt_of_rel wellFounded_gt
end WellFounded
|
SetTheory\Ordinal\Basic.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn
-/
import Mathlib.Data.Sum.Order
import Mathlib.Order.InitialSeg
import Mathlib.SetTheory.Cardinal.Basic
import Mathlib.Tactic.PPWithUniv
/-!
# Ordinals
Ordinals are defined as equivalences of well-ordered sets under order isomorphism. They are endowed
with a total order, where an ordinal is smaller than another one if it embeds into it as an
initial segment (or, equivalently, in any way). This total order is well founded.
## Main definitions
* `Ordinal`: the type of ordinals (in a given universe)
* `Ordinal.type r`: given a well-founded order `r`, this is the corresponding ordinal
* `Ordinal.typein r a`: given a well-founded order `r` on a type `α`, and `a : α`, the ordinal
corresponding to all elements smaller than `a`.
* `enum r o h`: given a well-order `r` on a type `α`, and an ordinal `o` strictly smaller than
the ordinal corresponding to `r` (this is the assumption `h`), returns the `o`-th element of `α`.
In other words, the elements of `α` can be enumerated using ordinals up to `type r`.
* `Ordinal.card o`: the cardinality of an ordinal `o`.
* `Ordinal.lift` lifts an ordinal in universe `u` to an ordinal in universe `max u v`.
For a version registering additionally that this is an initial segment embedding, see
`Ordinal.lift.initialSeg`.
For a version registering that it is a principal segment embedding if `u < v`, see
`Ordinal.lift.principalSeg`.
* `Ordinal.omega` or `ω` is the order type of `ℕ`. This definition is universe polymorphic:
`Ordinal.omega.{u} : Ordinal.{u}` (contrast with `ℕ : Type`, which lives in a specific
universe). In some cases the universe level has to be given explicitly.
* `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that
every element of `o₁` is smaller than every element of `o₂`.
The main properties of addition (and the other operations on ordinals) are stated and proved in
`Mathlib/SetTheory/Ordinal/Arithmetic.lean`.
Here, we only introduce it and prove its basic properties to deduce the fact that the order on
ordinals is total (and well founded).
* `succ o` is the successor of the ordinal `o`.
* `Cardinal.ord c`: when `c` is a cardinal, `ord c` is the smallest ordinal with this cardinality.
It is the canonical way to represent a cardinal with an ordinal.
A conditionally complete linear order with bot structure is registered on ordinals, where `⊥` is
`0`, the ordinal corresponding to the empty type, and `Inf` is the minimum for nonempty sets and `0`
for the empty set by convention.
## Notations
* `ω` is a notation for the first infinite ordinal in the locale `Ordinal`.
-/
assert_not_exists Module
assert_not_exists Field
noncomputable section
open Function Cardinal Set Equiv Order
open scoped Classical
open Cardinal InitialSeg
universe u v w
variable {α : Type u} {β : Type*} {γ : Type*} {r : α → α → Prop} {s : β → β → Prop}
{t : γ → γ → Prop}
/-! ### Well order on an arbitrary type -/
section WellOrderingThm
-- Porting note: `parameter` does not work
-- parameter {σ : Type u}
variable {σ : Type u}
open Function
theorem nonempty_embedding_to_cardinal : Nonempty (σ ↪ Cardinal.{u}) :=
(Embedding.total _ _).resolve_left fun ⟨⟨f, hf⟩⟩ =>
let g : σ → Cardinal.{u} := invFun f
let ⟨x, (hx : g x = 2 ^ sum g)⟩ := invFun_surjective hf (2 ^ sum g)
have : g x ≤ sum g := le_sum.{u, u} g x
not_le_of_gt (by rw [hx]; exact cantor _) this
/-- An embedding of any type to the set of cardinals. -/
def embeddingToCardinal : σ ↪ Cardinal.{u} :=
Classical.choice nonempty_embedding_to_cardinal
/-- Any type can be endowed with a well order, obtained by pulling back the well order over
cardinals by some embedding. -/
def WellOrderingRel : σ → σ → Prop :=
embeddingToCardinal ⁻¹'o (· < ·)
instance WellOrderingRel.isWellOrder : IsWellOrder σ WellOrderingRel :=
(RelEmbedding.preimage _ _).isWellOrder
instance IsWellOrder.subtype_nonempty : Nonempty { r // IsWellOrder σ r } :=
⟨⟨WellOrderingRel, inferInstance⟩⟩
end WellOrderingThm
/-! ### Definition of ordinals -/
/-- Bundled structure registering a well order on a type. Ordinals will be defined as a quotient
of this type. -/
structure WellOrder : Type (u + 1) where
/-- The underlying type of the order. -/
α : Type u
/-- The underlying relation of the order. -/
r : α → α → Prop
/-- The proposition that `r` is a well-ordering for `α`. -/
wo : IsWellOrder α r
attribute [instance] WellOrder.wo
namespace WellOrder
instance inhabited : Inhabited WellOrder :=
⟨⟨PEmpty, _, inferInstanceAs (IsWellOrder PEmpty EmptyRelation)⟩⟩
@[simp]
theorem eta (o : WellOrder) : mk o.α o.r o.wo = o := by
cases o
rfl
end WellOrder
/-- Equivalence relation on well orders on arbitrary types in universe `u`, given by order
isomorphism. -/
instance Ordinal.isEquivalent : Setoid WellOrder where
r := fun ⟨_, r, _⟩ ⟨_, s, _⟩ => Nonempty (r ≃r s)
iseqv :=
⟨fun _ => ⟨RelIso.refl _⟩, fun ⟨e⟩ => ⟨e.symm⟩, fun ⟨e₁⟩ ⟨e₂⟩ => ⟨e₁.trans e₂⟩⟩
/-- `Ordinal.{u}` is the type of well orders in `Type u`, up to order isomorphism. -/
@[pp_with_univ]
def Ordinal : Type (u + 1) :=
Quotient Ordinal.isEquivalent
instance hasWellFoundedOut (o : Ordinal) : WellFoundedRelation o.out.α :=
⟨o.out.r, o.out.wo.wf⟩
instance linearOrderOut (o : Ordinal) : LinearOrder o.out.α :=
IsWellOrder.linearOrder o.out.r
instance isWellOrder_out_lt (o : Ordinal) : IsWellOrder o.out.α (· < ·) :=
o.out.wo
namespace Ordinal
/-! ### Basic properties of the order type -/
/-- The order type of a well order is an ordinal. -/
def type (r : α → α → Prop) [wo : IsWellOrder α r] : Ordinal :=
⟦⟨α, r, wo⟩⟧
instance zero : Zero Ordinal :=
⟨type <| @EmptyRelation PEmpty⟩
instance inhabited : Inhabited Ordinal :=
⟨0⟩
instance one : One Ordinal :=
⟨type <| @EmptyRelation PUnit⟩
/-- The order type of an element inside a well order. For the embedding as a principal segment, see
`typein.principalSeg`. -/
def typein (r : α → α → Prop) [IsWellOrder α r] (a : α) : Ordinal :=
type (Subrel r { b | r b a })
@[simp]
theorem type_def' (w : WellOrder) : ⟦w⟧ = type w.r := by
cases w
rfl
@[simp]
theorem type_def (r) [wo : IsWellOrder α r] : (⟦⟨α, r, wo⟩⟧ : Ordinal) = type r := by
rfl
@[simp]
theorem type_out (o : Ordinal) : Ordinal.type o.out.r = o := by
rw [Ordinal.type, WellOrder.eta, Quotient.out_eq]
theorem type_eq {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] :
type r = type s ↔ Nonempty (r ≃r s) :=
Quotient.eq'
theorem _root_.RelIso.ordinal_type_eq {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r]
[IsWellOrder β s] (h : r ≃r s) : type r = type s :=
type_eq.2 ⟨h⟩
@[simp]
theorem type_lt (o : Ordinal) : type ((· < ·) : o.out.α → o.out.α → Prop) = o :=
(type_def' _).symm.trans <| Quotient.out_eq o
theorem type_eq_zero_of_empty (r) [IsWellOrder α r] [IsEmpty α] : type r = 0 :=
(RelIso.relIsoOfIsEmpty r _).ordinal_type_eq
@[simp]
theorem type_eq_zero_iff_isEmpty [IsWellOrder α r] : type r = 0 ↔ IsEmpty α :=
⟨fun h =>
let ⟨s⟩ := type_eq.1 h
s.toEquiv.isEmpty,
@type_eq_zero_of_empty α r _⟩
theorem type_ne_zero_iff_nonempty [IsWellOrder α r] : type r ≠ 0 ↔ Nonempty α := by simp
theorem type_ne_zero_of_nonempty (r) [IsWellOrder α r] [h : Nonempty α] : type r ≠ 0 :=
type_ne_zero_iff_nonempty.2 h
theorem type_pEmpty : type (@EmptyRelation PEmpty) = 0 :=
rfl
theorem type_empty : type (@EmptyRelation Empty) = 0 :=
type_eq_zero_of_empty _
theorem type_eq_one_of_unique (r) [IsWellOrder α r] [Unique α] : type r = 1 :=
(RelIso.relIsoOfUniqueOfIrrefl r _).ordinal_type_eq
@[simp]
theorem type_eq_one_iff_unique [IsWellOrder α r] : type r = 1 ↔ Nonempty (Unique α) :=
⟨fun h =>
let ⟨s⟩ := type_eq.1 h
⟨s.toEquiv.unique⟩,
fun ⟨h⟩ => @type_eq_one_of_unique α r _ h⟩
theorem type_pUnit : type (@EmptyRelation PUnit) = 1 :=
rfl
theorem type_unit : type (@EmptyRelation Unit) = 1 :=
rfl
@[simp]
theorem out_empty_iff_eq_zero {o : Ordinal} : IsEmpty o.out.α ↔ o = 0 := by
rw [← @type_eq_zero_iff_isEmpty o.out.α (· < ·), type_lt]
theorem eq_zero_of_out_empty (o : Ordinal) [h : IsEmpty o.out.α] : o = 0 :=
out_empty_iff_eq_zero.1 h
instance isEmpty_out_zero : IsEmpty (0 : Ordinal).out.α :=
out_empty_iff_eq_zero.2 rfl
@[simp]
theorem out_nonempty_iff_ne_zero {o : Ordinal} : Nonempty o.out.α ↔ o ≠ 0 := by
rw [← @type_ne_zero_iff_nonempty o.out.α (· < ·), type_lt]
theorem ne_zero_of_out_nonempty (o : Ordinal) [h : Nonempty o.out.α] : o ≠ 0 :=
out_nonempty_iff_ne_zero.1 h
protected theorem one_ne_zero : (1 : Ordinal) ≠ 0 :=
type_ne_zero_of_nonempty _
instance nontrivial : Nontrivial Ordinal.{u} :=
⟨⟨1, 0, Ordinal.one_ne_zero⟩⟩
--@[simp] -- Porting note: not in simp nf, added aux lemma below
theorem type_preimage {α β : Type u} (r : α → α → Prop) [IsWellOrder α r] (f : β ≃ α) :
type (f ⁻¹'o r) = type r :=
(RelIso.preimage f r).ordinal_type_eq
@[simp, nolint simpNF] -- `simpNF` incorrectly complains the LHS doesn't simplify.
theorem type_preimage_aux {α β : Type u} (r : α → α → Prop) [IsWellOrder α r] (f : β ≃ α) :
@type _ (fun x y => r (f x) (f y)) (inferInstanceAs (IsWellOrder β (↑f ⁻¹'o r))) = type r := by
convert (RelIso.preimage f r).ordinal_type_eq
@[elab_as_elim]
theorem inductionOn {C : Ordinal → Prop} (o : Ordinal)
(H : ∀ (α r) [IsWellOrder α r], C (type r)) : C o :=
Quot.inductionOn o fun ⟨α, r, wo⟩ => @H α r wo
/-! ### The order on ordinals -/
/--
For `Ordinal`:
* less-equal is defined such that well orders `r` and `s` satisfy `type r ≤ type s` if there exists
a function embedding `r` as an *initial* segment of `s`.
* less-than is defined such that well orders `r` and `s` satisfy `type r < type s` if there exists
a function embedding `r` as a *principal* segment of `s`.
-/
instance partialOrder : PartialOrder Ordinal where
le a b :=
Quotient.liftOn₂ a b (fun ⟨_, r, _⟩ ⟨_, s, _⟩ => Nonempty (r ≼i s))
fun _ _ _ _ ⟨f⟩ ⟨g⟩ =>
propext
⟨fun ⟨h⟩ => ⟨(InitialSeg.ofIso f.symm).trans <| h.trans (InitialSeg.ofIso g)⟩, fun ⟨h⟩ =>
⟨(InitialSeg.ofIso f).trans <| h.trans (InitialSeg.ofIso g.symm)⟩⟩
lt a b :=
Quotient.liftOn₂ a b (fun ⟨_, r, _⟩ ⟨_, s, _⟩ => Nonempty (r ≺i s))
fun _ _ _ _ ⟨f⟩ ⟨g⟩ =>
propext
⟨fun ⟨h⟩ => ⟨PrincipalSeg.equivLT f.symm <| h.ltLe (InitialSeg.ofIso g)⟩, fun ⟨h⟩ =>
⟨PrincipalSeg.equivLT f <| h.ltLe (InitialSeg.ofIso g.symm)⟩⟩
le_refl := Quot.ind fun ⟨_, _, _⟩ => ⟨InitialSeg.refl _⟩
le_trans a b c :=
Quotient.inductionOn₃ a b c fun _ _ _ ⟨f⟩ ⟨g⟩ => ⟨f.trans g⟩
lt_iff_le_not_le a b :=
Quotient.inductionOn₂ a b fun _ _ =>
⟨fun ⟨f⟩ => ⟨⟨f⟩, fun ⟨g⟩ => (f.ltLe g).irrefl⟩, fun ⟨⟨f⟩, h⟩ =>
Sum.recOn f.ltOrEq (fun g => ⟨g⟩) fun g => (h ⟨InitialSeg.ofIso g.symm⟩).elim⟩
le_antisymm a b :=
Quotient.inductionOn₂ a b fun _ _ ⟨h₁⟩ ⟨h₂⟩ =>
Quot.sound ⟨InitialSeg.antisymm h₁ h₂⟩
theorem type_le_iff {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r]
[IsWellOrder β s] : type r ≤ type s ↔ Nonempty (r ≼i s) :=
Iff.rfl
theorem type_le_iff' {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r]
[IsWellOrder β s] : type r ≤ type s ↔ Nonempty (r ↪r s) :=
⟨fun ⟨f⟩ => ⟨f⟩, fun ⟨f⟩ => ⟨f.collapse⟩⟩
theorem _root_.InitialSeg.ordinal_type_le {α β} {r : α → α → Prop} {s : β → β → Prop}
[IsWellOrder α r] [IsWellOrder β s] (h : r ≼i s) : type r ≤ type s :=
⟨h⟩
theorem _root_.RelEmbedding.ordinal_type_le {α β} {r : α → α → Prop} {s : β → β → Prop}
[IsWellOrder α r] [IsWellOrder β s] (h : r ↪r s) : type r ≤ type s :=
⟨h.collapse⟩
@[simp]
theorem type_lt_iff {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r]
[IsWellOrder β s] : type r < type s ↔ Nonempty (r ≺i s) :=
Iff.rfl
theorem _root_.PrincipalSeg.ordinal_type_lt {α β} {r : α → α → Prop} {s : β → β → Prop}
[IsWellOrder α r] [IsWellOrder β s] (h : r ≺i s) : type r < type s :=
⟨h⟩
@[simp]
protected theorem zero_le (o : Ordinal) : 0 ≤ o :=
inductionOn o fun _ r _ => (InitialSeg.ofIsEmpty _ r).ordinal_type_le
instance orderBot : OrderBot Ordinal where
bot := 0
bot_le := Ordinal.zero_le
@[simp]
theorem bot_eq_zero : (⊥ : Ordinal) = 0 :=
rfl
@[simp]
protected theorem le_zero {o : Ordinal} : o ≤ 0 ↔ o = 0 :=
le_bot_iff
protected theorem pos_iff_ne_zero {o : Ordinal} : 0 < o ↔ o ≠ 0 :=
bot_lt_iff_ne_bot
protected theorem not_lt_zero (o : Ordinal) : ¬o < 0 :=
not_lt_bot
theorem eq_zero_or_pos : ∀ a : Ordinal, a = 0 ∨ 0 < a :=
eq_bot_or_bot_lt
instance zeroLEOneClass : ZeroLEOneClass Ordinal :=
⟨Ordinal.zero_le _⟩
instance NeZero.one : NeZero (1 : Ordinal) :=
⟨Ordinal.one_ne_zero⟩
/-- Given two ordinals `α ≤ β`, then `initialSegOut α β` is the initial segment embedding
of `α` to `β`, as map from a model type for `α` to a model type for `β`. -/
def initialSegOut {α β : Ordinal} (h : α ≤ β) :
InitialSeg ((· < ·) : α.out.α → α.out.α → Prop) ((· < ·) : β.out.α → β.out.α → Prop) := by
change α.out.r ≼i β.out.r
rw [← Quotient.out_eq α, ← Quotient.out_eq β] at h; revert h
cases Quotient.out α; cases Quotient.out β; exact Classical.choice
/-- Given two ordinals `α < β`, then `principalSegOut α β` is the principal segment embedding
of `α` to `β`, as map from a model type for `α` to a model type for `β`. -/
def principalSegOut {α β : Ordinal} (h : α < β) :
PrincipalSeg ((· < ·) : α.out.α → α.out.α → Prop) ((· < ·) : β.out.α → β.out.α → Prop) := by
change α.out.r ≺i β.out.r
rw [← Quotient.out_eq α, ← Quotient.out_eq β] at h; revert h
cases Quotient.out α; cases Quotient.out β; exact Classical.choice
theorem typein_lt_type (r : α → α → Prop) [IsWellOrder α r] (a : α) : typein r a < type r :=
⟨PrincipalSeg.ofElement _ _⟩
theorem typein_lt_self {o : Ordinal} (i : o.out.α) :
@typein _ (· < ·) (isWellOrder_out_lt _) i < o := by
simp_rw [← type_lt o]
apply typein_lt_type
@[simp]
theorem typein_top {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s]
(f : r ≺i s) : typein s f.top = type r :=
Eq.symm <|
Quot.sound
⟨RelIso.ofSurjective (RelEmbedding.codRestrict _ f f.lt_top) fun ⟨a, h⟩ => by
rcases f.down.1 h with ⟨b, rfl⟩; exact ⟨b, rfl⟩⟩
@[simp]
theorem typein_apply {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s]
(f : r ≼i s) (a : α) : Ordinal.typein s (f a) = Ordinal.typein r a :=
Eq.symm <|
Quotient.sound
⟨RelIso.ofSurjective
(RelEmbedding.codRestrict _ ((Subrel.relEmbedding _ _).trans f) fun ⟨x, h⟩ => by
rw [RelEmbedding.trans_apply]; exact f.toRelEmbedding.map_rel_iff.2 h)
fun ⟨y, h⟩ => by
rcases f.init h with ⟨a, rfl⟩
exact ⟨⟨a, f.toRelEmbedding.map_rel_iff.1 h⟩,
Subtype.eq <| RelEmbedding.trans_apply _ _ _⟩⟩
@[simp]
theorem typein_lt_typein (r : α → α → Prop) [IsWellOrder α r] {a b : α} :
typein r a < typein r b ↔ r a b :=
⟨fun ⟨f⟩ => by
have : f.top.1 = a := by
let f' := PrincipalSeg.ofElement r a
let g' := f.trans (PrincipalSeg.ofElement r b)
have : g'.top = f'.top := by rw [Subsingleton.elim f' g']
exact this
rw [← this]
exact f.top.2, fun h =>
⟨PrincipalSeg.codRestrict _ (PrincipalSeg.ofElement r a) (fun x => @trans _ r _ _ _ _ x.2 h) h⟩⟩
theorem typein_surj (r : α → α → Prop) [IsWellOrder α r] {o} (h : o < type r) :
∃ a, typein r a = o :=
inductionOn o (fun _ _ _ ⟨f⟩ => ⟨f.top, typein_top _⟩) h
theorem typein_injective (r : α → α → Prop) [IsWellOrder α r] : Injective (typein r) :=
injective_of_increasing r (· < ·) (typein r) (typein_lt_typein r).2
@[simp]
theorem typein_inj (r : α → α → Prop) [IsWellOrder α r] {a b} : typein r a = typein r b ↔ a = b :=
(typein_injective r).eq_iff
/-- Principal segment version of the `typein` function, embedding a well order into
ordinals as a principal segment. -/
def typein.principalSeg {α : Type u} (r : α → α → Prop) [IsWellOrder α r] :
@PrincipalSeg α Ordinal.{u} r (· < ·) :=
⟨⟨⟨typein r, typein_injective r⟩, typein_lt_typein r⟩, type r,
fun _ ↦ ⟨typein_surj r, fun ⟨a, h⟩ ↦ h ▸ typein_lt_type r a⟩⟩
@[simp]
theorem typein.principalSeg_coe (r : α → α → Prop) [IsWellOrder α r] :
(typein.principalSeg r : α → Ordinal) = typein r :=
rfl
/-! ### Enumerating elements in a well-order with ordinals. -/
/-- `enum r o h` is the `o`-th element of `α` ordered by `r`.
That is, `enum` maps an initial segment of the ordinals, those
less than the order type of `r`, to the elements of `α`. -/
def enum (r : α → α → Prop) [IsWellOrder α r] (o) (h : o < type r) : α :=
(typein.principalSeg r).subrelIso ⟨o, h⟩
@[simp]
theorem typein_enum (r : α → α → Prop) [IsWellOrder α r] {o} (h : o < type r) :
typein r (enum r o h) = o :=
(typein.principalSeg r).apply_subrelIso _
theorem enum_type {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s]
(f : s ≺i r) {h : type s < type r} : enum r (type s) h = f.top :=
(typein.principalSeg r).injective <| (typein_enum _ _).trans (typein_top _).symm
@[simp]
theorem enum_typein (r : α → α → Prop) [IsWellOrder α r] (a : α) :
enum r (typein r a) (typein_lt_type r a) = a :=
enum_type (PrincipalSeg.ofElement r a)
theorem enum_lt_enum {r : α → α → Prop} [IsWellOrder α r] {o₁ o₂ : Ordinal} (h₁ : o₁ < type r)
(h₂ : o₂ < type r) : r (enum r o₁ h₁) (enum r o₂ h₂) ↔ o₁ < o₂ := by
rw [← typein_lt_typein r, typein_enum, typein_enum]
theorem relIso_enum' {α β : Type u} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r]
[IsWellOrder β s] (f : r ≃r s) (o : Ordinal) :
∀ (hr : o < type r) (hs : o < type s), f (enum r o hr) = enum s o hs := by
refine inductionOn o ?_; rintro γ t wo ⟨g⟩ ⟨h⟩
rw [enum_type g, enum_type (PrincipalSeg.ltEquiv g f)]; rfl
theorem relIso_enum {α β : Type u} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r]
[IsWellOrder β s] (f : r ≃r s) (o : Ordinal) (hr : o < type r) :
f (enum r o hr) =
enum s o
(by
convert hr using 1
apply Quotient.sound
exact ⟨f.symm⟩) :=
relIso_enum' _ _ _ _
theorem lt_wf : @WellFounded Ordinal (· < ·) :=
/-
wellFounded_iff_wellFounded_subrel.mpr (·.induction_on fun ⟨_, r, wo⟩ ↦
RelHomClass.wellFounded (typein.principalSeg r).subrelIso wo.wf)
-/
⟨fun a =>
inductionOn a fun α r wo =>
suffices ∀ a, Acc (· < ·) (typein r a) from
⟨_, fun o h =>
let ⟨a, e⟩ := typein_surj r h
e ▸ this a⟩
fun a =>
Acc.recOn (wo.wf.apply a) fun x _ IH =>
⟨_, fun o h => by
rcases typein_surj r (lt_trans h (typein_lt_type r _)) with ⟨b, rfl⟩
exact IH _ ((typein_lt_typein r).1 h)⟩⟩
instance wellFoundedRelation : WellFoundedRelation Ordinal :=
⟨(· < ·), lt_wf⟩
/-- Reformulation of well founded induction on ordinals as a lemma that works with the
`induction` tactic, as in `induction i using Ordinal.induction with | h i IH => ?_`. -/
theorem induction {p : Ordinal.{u} → Prop} (i : Ordinal.{u}) (h : ∀ j, (∀ k, k < j → p k) → p j) :
p i :=
lt_wf.induction i h
/-! ### Cardinality of ordinals -/
/-- The cardinal of an ordinal is the cardinality of any type on which a relation with that order
type is defined. -/
def card : Ordinal → Cardinal :=
Quotient.map WellOrder.α fun _ _ ⟨e⟩ => ⟨e.toEquiv⟩
@[simp]
theorem card_type (r : α → α → Prop) [IsWellOrder α r] : card (type r) = #α :=
rfl
-- Porting note: nolint, simpNF linter falsely claims the lemma never applies
@[simp, nolint simpNF]
theorem card_typein {r : α → α → Prop} [IsWellOrder α r] (x : α) :
#{ y // r y x } = (typein r x).card :=
rfl
theorem card_le_card {o₁ o₂ : Ordinal} : o₁ ≤ o₂ → card o₁ ≤ card o₂ :=
inductionOn o₁ fun _ _ _ => inductionOn o₂ fun _ _ _ ⟨⟨⟨f, _⟩, _⟩⟩ => ⟨f⟩
@[simp]
theorem card_zero : card 0 = 0 := mk_eq_zero _
@[simp]
theorem card_one : card 1 = 1 := mk_eq_one _
/-! ### Lifting ordinals to a higher universe -/
-- Porting note: Needed to add universe hint .{u} below
/-- The universe lift operation for ordinals, which embeds `Ordinal.{u}` as
a proper initial segment of `Ordinal.{v}` for `v > u`. For the initial segment version,
see `lift.initialSeg`. -/
@[pp_with_univ]
def lift (o : Ordinal.{v}) : Ordinal.{max v u} :=
Quotient.liftOn o (fun w => type <| ULift.down.{u} ⁻¹'o w.r) fun ⟨_, r, _⟩ ⟨_, s, _⟩ ⟨f⟩ =>
Quot.sound
⟨(RelIso.preimage Equiv.ulift r).trans <| f.trans (RelIso.preimage Equiv.ulift s).symm⟩
-- Porting note: Needed to add universe hints ULift.down.{v,u} below
-- @[simp] -- Porting note: Not in simpnf, added aux lemma below
theorem type_uLift (r : α → α → Prop) [IsWellOrder α r] :
type (ULift.down.{v,u} ⁻¹'o r) = lift.{v} (type r) := by
simp (config := { unfoldPartialApp := true })
rfl
-- Porting note: simpNF linter falsely claims that this never applies
@[simp, nolint simpNF]
theorem type_uLift_aux (r : α → α → Prop) [IsWellOrder α r] :
@type.{max v u} _ (fun x y => r (ULift.down.{v,u} x) (ULift.down.{v,u} y))
(inferInstanceAs (IsWellOrder (ULift α) (ULift.down ⁻¹'o r))) = lift.{v} (type r) :=
rfl
theorem _root_.RelIso.ordinal_lift_type_eq {α : Type u} {β : Type v} {r : α → α → Prop}
{s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] (f : r ≃r s) :
lift.{v} (type r) = lift.{u} (type s) :=
((RelIso.preimage Equiv.ulift r).trans <|
f.trans (RelIso.preimage Equiv.ulift s).symm).ordinal_type_eq
-- @[simp]
theorem type_lift_preimage {α : Type u} {β : Type v} (r : α → α → Prop) [IsWellOrder α r]
(f : β ≃ α) : lift.{u} (type (f ⁻¹'o r)) = lift.{v} (type r) :=
(RelIso.preimage f r).ordinal_lift_type_eq
@[simp, nolint simpNF]
theorem type_lift_preimage_aux {α : Type u} {β : Type v} (r : α → α → Prop) [IsWellOrder α r]
(f : β ≃ α) : lift.{u} (@type _ (fun x y => r (f x) (f y))
(inferInstanceAs (IsWellOrder β (f ⁻¹'o r)))) = lift.{v} (type r) :=
(RelIso.preimage f r).ordinal_lift_type_eq
/-- `lift.{max u v, u}` equals `lift.{v, u}`. -/
-- @[simp] -- Porting note: simp lemma never applies, tested
theorem lift_umax : lift.{max u v, u} = lift.{v, u} :=
funext fun a =>
inductionOn a fun _ r _ =>
Quotient.sound ⟨(RelIso.preimage Equiv.ulift r).trans (RelIso.preimage Equiv.ulift r).symm⟩
/-- `lift.{max v u, u}` equals `lift.{v, u}`. -/
-- @[simp] -- Porting note: simp lemma never applies, tested
theorem lift_umax' : lift.{max v u, u} = lift.{v, u} :=
lift_umax
/-- An ordinal lifted to a lower or equal universe equals itself. -/
-- @[simp] -- Porting note: simp lemma never applies, tested
theorem lift_id' (a : Ordinal) : lift a = a :=
inductionOn a fun _ r _ => Quotient.sound ⟨RelIso.preimage Equiv.ulift r⟩
/-- An ordinal lifted to the same universe equals itself. -/
@[simp]
theorem lift_id : ∀ a, lift.{u, u} a = a :=
lift_id'.{u, u}
/-- An ordinal lifted to the zero universe equals itself. -/
@[simp]
theorem lift_uzero (a : Ordinal.{u}) : lift.{0} a = a :=
lift_id' a
@[simp]
theorem lift_lift (a : Ordinal) : lift.{w} (lift.{v} a) = lift.{max v w} a :=
inductionOn a fun _ _ _ =>
Quotient.sound
⟨(RelIso.preimage Equiv.ulift _).trans <|
(RelIso.preimage Equiv.ulift _).trans (RelIso.preimage Equiv.ulift _).symm⟩
theorem lift_type_le {α : Type u} {β : Type v} {r s} [IsWellOrder α r] [IsWellOrder β s] :
lift.{max v w} (type r) ≤ lift.{max u w} (type s) ↔ Nonempty (r ≼i s) :=
⟨fun ⟨f⟩ =>
⟨(InitialSeg.ofIso (RelIso.preimage Equiv.ulift r).symm).trans <|
f.trans (InitialSeg.ofIso (RelIso.preimage Equiv.ulift s))⟩,
fun ⟨f⟩ =>
⟨(InitialSeg.ofIso (RelIso.preimage Equiv.ulift r)).trans <|
f.trans (InitialSeg.ofIso (RelIso.preimage Equiv.ulift s).symm)⟩⟩
theorem lift_type_eq {α : Type u} {β : Type v} {r s} [IsWellOrder α r] [IsWellOrder β s] :
lift.{max v w} (type r) = lift.{max u w} (type s) ↔ Nonempty (r ≃r s) :=
Quotient.eq'.trans
⟨fun ⟨f⟩ =>
⟨(RelIso.preimage Equiv.ulift r).symm.trans <| f.trans (RelIso.preimage Equiv.ulift s)⟩,
fun ⟨f⟩ =>
⟨(RelIso.preimage Equiv.ulift r).trans <| f.trans (RelIso.preimage Equiv.ulift s).symm⟩⟩
theorem lift_type_lt {α : Type u} {β : Type v} {r s} [IsWellOrder α r] [IsWellOrder β s] :
lift.{max v w} (type r) < lift.{max u w} (type s) ↔ Nonempty (r ≺i s) := by
haveI := @RelEmbedding.isWellOrder _ _ (@Equiv.ulift.{max v w} α ⁻¹'o r) r
(RelIso.preimage Equiv.ulift.{max v w} r) _
haveI := @RelEmbedding.isWellOrder _ _ (@Equiv.ulift.{max u w} β ⁻¹'o s) s
(RelIso.preimage Equiv.ulift.{max u w} s) _
exact ⟨fun ⟨f⟩ =>
⟨(f.equivLT (RelIso.preimage Equiv.ulift r).symm).ltLe
(InitialSeg.ofIso (RelIso.preimage Equiv.ulift s))⟩,
fun ⟨f⟩ =>
⟨(f.equivLT (RelIso.preimage Equiv.ulift r)).ltLe
(InitialSeg.ofIso (RelIso.preimage Equiv.ulift s).symm)⟩⟩
@[simp]
theorem lift_le {a b : Ordinal} : lift.{u,v} a ≤ lift.{u,v} b ↔ a ≤ b :=
inductionOn a fun α r _ =>
inductionOn b fun β s _ => by
rw [← lift_umax]
exact lift_type_le.{_,_,u}
@[simp]
theorem lift_inj {a b : Ordinal} : lift.{u,v} a = lift.{u,v} b ↔ a = b := by
simp only [le_antisymm_iff, lift_le]
@[simp]
theorem lift_lt {a b : Ordinal} : lift.{u,v} a < lift.{u,v} b ↔ a < b := by
simp only [lt_iff_le_not_le, lift_le]
@[simp]
theorem lift_zero : lift 0 = 0 :=
type_eq_zero_of_empty _
@[simp]
theorem lift_one : lift 1 = 1 :=
type_eq_one_of_unique _
@[simp]
theorem lift_card (a) : Cardinal.lift.{u,v} (card a)= card (lift.{u,v} a) :=
inductionOn a fun _ _ _ => rfl
theorem lift_down' {a : Cardinal.{u}} {b : Ordinal.{max u v}}
(h : card.{max u v} b ≤ Cardinal.lift.{v,u} a) : ∃ a', lift.{v,u} a' = b :=
let ⟨c, e⟩ := Cardinal.lift_down h
Cardinal.inductionOn c
(fun α =>
inductionOn b fun β s _ e' => by
rw [card_type, ← Cardinal.lift_id'.{max u v, u} #β, ← Cardinal.lift_umax.{u, v},
lift_mk_eq.{u, max u v, max u v}] at e'
cases' e' with f
have g := RelIso.preimage f s
haveI := (g : f ⁻¹'o s ↪r s).isWellOrder
have := lift_type_eq.{u, max u v, max u v}.2 ⟨g⟩
rw [lift_id, lift_umax.{u, v}] at this
exact ⟨_, this⟩)
e
theorem lift_down {a : Ordinal.{u}} {b : Ordinal.{max u v}} (h : b ≤ lift.{v,u} a) :
∃ a', lift.{v,u} a' = b :=
@lift_down' (card a) _ (by rw [lift_card]; exact card_le_card h)
theorem le_lift_iff {a : Ordinal.{u}} {b : Ordinal.{max u v}} :
b ≤ lift.{v,u} a ↔ ∃ a', lift.{v,u} a' = b ∧ a' ≤ a :=
⟨fun h =>
let ⟨a', e⟩ := lift_down h
⟨a', e, lift_le.1 <| e.symm ▸ h⟩,
fun ⟨_, e, h⟩ => e ▸ lift_le.2 h⟩
theorem lt_lift_iff {a : Ordinal.{u}} {b : Ordinal.{max u v}} :
b < lift.{v,u} a ↔ ∃ a', lift.{v,u} a' = b ∧ a' < a :=
⟨fun h =>
let ⟨a', e⟩ := lift_down (le_of_lt h)
⟨a', e, lift_lt.1 <| e.symm ▸ h⟩,
fun ⟨_, e, h⟩ => e ▸ lift_lt.2 h⟩
/-- Initial segment version of the lift operation on ordinals, embedding `ordinal.{u}` in
`ordinal.{v}` as an initial segment when `u ≤ v`. -/
def lift.initialSeg : @InitialSeg Ordinal.{u} Ordinal.{max u v} (· < ·) (· < ·) :=
⟨⟨⟨lift.{v}, fun _ _ => lift_inj.1⟩, lift_lt⟩, fun _ _ h => lift_down (le_of_lt h)⟩
@[simp]
theorem lift.initialSeg_coe : (lift.initialSeg.{u,v} : Ordinal → Ordinal) = lift.{v,u} :=
rfl
/-! ### The first infinite ordinal `omega` -/
/-- `ω` is the first infinite ordinal, defined as the order type of `ℕ`. -/
def omega : Ordinal.{u} :=
lift <| @type ℕ (· < ·) _
@[inherit_doc]
scoped notation "ω" => Ordinal.omega
/-- Note that the presence of this lemma makes `simp [omega]` form a loop. -/
@[simp]
theorem type_nat_lt : @type ℕ (· < ·) _ = ω :=
(lift_id _).symm
@[simp]
theorem card_omega : card ω = ℵ₀ :=
rfl
@[simp]
theorem lift_omega : lift ω = ω :=
lift_lift _
/-!
### Definition and first properties of addition on ordinals
In this paragraph, we introduce the addition on ordinals, and prove just enough properties to
deduce that the order on ordinals is total (and therefore well-founded). Further properties of
the addition, together with properties of the other operations, are proved in
`Mathlib/SetTheory/Ordinal/Arithmetic.lean`.
-/
/-- `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that
every element of `o₁` is smaller than every element of `o₂`. -/
instance add : Add Ordinal.{u} :=
⟨fun o₁ o₂ =>
Quotient.liftOn₂ o₁ o₂ (fun ⟨_, r, _⟩ ⟨_, s, _⟩ => type (Sum.Lex r s))
fun _ _ _ _ ⟨f⟩ ⟨g⟩ => Quot.sound ⟨RelIso.sumLexCongr f g⟩⟩
instance addMonoidWithOne : AddMonoidWithOne Ordinal.{u} where
add := (· + ·)
zero := 0
one := 1
zero_add o :=
inductionOn o fun α r _ =>
Eq.symm <| Quotient.sound ⟨⟨(emptySum PEmpty α).symm, Sum.lex_inr_inr⟩⟩
add_zero o :=
inductionOn o fun α r _ =>
Eq.symm <| Quotient.sound ⟨⟨(sumEmpty α PEmpty).symm, Sum.lex_inl_inl⟩⟩
add_assoc o₁ o₂ o₃ :=
Quotient.inductionOn₃ o₁ o₂ o₃ fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ =>
Quot.sound
⟨⟨sumAssoc _ _ _, by
intros a b
rcases a with (⟨a | a⟩ | a) <;> rcases b with (⟨b | b⟩ | b) <;>
simp only [sumAssoc_apply_inl_inl, sumAssoc_apply_inl_inr, sumAssoc_apply_inr,
Sum.lex_inl_inl, Sum.lex_inr_inr, Sum.Lex.sep, Sum.lex_inr_inl]⟩⟩
nsmul := nsmulRec
@[simp]
theorem card_add (o₁ o₂ : Ordinal) : card (o₁ + o₂) = card o₁ + card o₂ :=
inductionOn o₁ fun _ __ => inductionOn o₂ fun _ _ _ => rfl
@[simp]
theorem type_sum_lex {α β : Type u} (r : α → α → Prop) (s : β → β → Prop) [IsWellOrder α r]
[IsWellOrder β s] : type (Sum.Lex r s) = type r + type s :=
rfl
@[simp]
theorem card_nat (n : ℕ) : card.{u} n = n := by
induction n <;> [simp; simp only [card_add, card_one, Nat.cast_succ, *]]
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem card_ofNat (n : ℕ) [n.AtLeastTwo] :
card.{u} (no_index (OfNat.ofNat n)) = OfNat.ofNat n :=
card_nat n
-- Porting note: Rewritten proof of elim, previous version was difficult to debug
instance add_covariantClass_le : CovariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· ≤ ·) where
elim := fun c a b h => by
revert h c
refine inductionOn a (fun α₁ r₁ _ ↦ ?_)
refine inductionOn b (fun α₂ r₂ _ ↦ ?_)
rintro c ⟨⟨⟨f, fo⟩, fi⟩⟩
refine inductionOn c (fun β s _ ↦ ?_)
refine ⟨⟨⟨(Embedding.refl.{u+1} _).sumMap f, ?_⟩, ?_⟩⟩
· intros a b
match a, b with
| Sum.inl a, Sum.inl b => exact Sum.lex_inl_inl.trans Sum.lex_inl_inl.symm
| Sum.inl a, Sum.inr b => apply iff_of_true <;> apply Sum.Lex.sep
| Sum.inr a, Sum.inl b => apply iff_of_false <;> exact Sum.lex_inr_inl
| Sum.inr a, Sum.inr b => exact Sum.lex_inr_inr.trans <| fo.trans Sum.lex_inr_inr.symm
· intros a b H
match a, b, H with
| _, Sum.inl b, _ => exact ⟨Sum.inl b, rfl⟩
| Sum.inl a, Sum.inr b, H => exact (Sum.lex_inr_inl H).elim
| Sum.inr a, Sum.inr b, H =>
let ⟨w, h⟩ := fi _ _ (Sum.lex_inr_inr.1 H)
exact ⟨Sum.inr w, congr_arg Sum.inr h⟩
-- Porting note: Rewritten proof of elim, previous version was difficult to debug
instance add_swap_covariantClass_le :
CovariantClass Ordinal.{u} Ordinal.{u} (swap (· + ·)) (· ≤ ·) where
elim := fun c a b h => by
revert h c
refine inductionOn a (fun α₁ r₁ _ ↦ ?_)
refine inductionOn b (fun α₂ r₂ _ ↦ ?_)
rintro c ⟨⟨⟨f, fo⟩, fi⟩⟩
refine inductionOn c (fun β s _ ↦ ?_)
exact @RelEmbedding.ordinal_type_le _ _ (Sum.Lex r₁ s) (Sum.Lex r₂ s) _ _
⟨f.sumMap (Embedding.refl _), by
intro a b
constructor <;> intro H
· cases' a with a a <;> cases' b with b b <;> cases H <;> constructor <;>
[rwa [← fo]; assumption]
· cases H <;> constructor <;> [rwa [fo]; assumption]⟩
theorem le_add_right (a b : Ordinal) : a ≤ a + b := by
simpa only [add_zero] using add_le_add_left (Ordinal.zero_le b) a
theorem le_add_left (a b : Ordinal) : a ≤ b + a := by
simpa only [zero_add] using add_le_add_right (Ordinal.zero_le b) a
instance linearOrder : LinearOrder Ordinal :=
{inferInstanceAs (PartialOrder Ordinal) with
le_total := fun a b =>
match lt_or_eq_of_le (le_add_left b a), lt_or_eq_of_le (le_add_right a b) with
| Or.inr h, _ => by rw [h]; exact Or.inl (le_add_right _ _)
| _, Or.inr h => by rw [h]; exact Or.inr (le_add_left _ _)
| Or.inl h₁, Or.inl h₂ => by
revert h₁ h₂
refine inductionOn a ?_
intro α₁ r₁ _
refine inductionOn b ?_
intro α₂ r₂ _ ⟨f⟩ ⟨g⟩
rw [← typein_top f, ← typein_top g, le_iff_lt_or_eq, le_iff_lt_or_eq,
typein_lt_typein, typein_lt_typein]
rcases trichotomous_of (Sum.Lex r₁ r₂) g.top f.top with (h | h | h) <;>
[exact Or.inl (Or.inl h); (left; right; rw [h]); exact Or.inr (Or.inl h)]
decidableLE := Classical.decRel _ }
instance wellFoundedLT : WellFoundedLT Ordinal :=
⟨lt_wf⟩
instance isWellOrder : IsWellOrder Ordinal (· < ·) where
instance : ConditionallyCompleteLinearOrderBot Ordinal :=
IsWellOrder.conditionallyCompleteLinearOrderBot _
theorem max_zero_left : ∀ a : Ordinal, max 0 a = a :=
max_bot_left
theorem max_zero_right : ∀ a : Ordinal, max a 0 = a :=
max_bot_right
@[simp]
theorem max_eq_zero {a b : Ordinal} : max a b = 0 ↔ a = 0 ∧ b = 0 :=
max_eq_bot
@[simp]
theorem sInf_empty : sInf (∅ : Set Ordinal) = 0 :=
dif_neg Set.not_nonempty_empty
/-! ### Successor order properties -/
private theorem succ_le_iff' {a b : Ordinal} : a + 1 ≤ b ↔ a < b :=
⟨lt_of_lt_of_le
(inductionOn a fun α r _ =>
⟨⟨⟨⟨fun x => Sum.inl x, fun _ _ => Sum.inl.inj⟩, Sum.lex_inl_inl⟩,
Sum.inr PUnit.unit, fun b =>
Sum.recOn b (fun x => ⟨fun _ => ⟨x, rfl⟩, fun _ => Sum.Lex.sep _ _⟩) fun x =>
Sum.lex_inr_inr.trans ⟨False.elim, fun ⟨x, H⟩ => Sum.inl_ne_inr H⟩⟩⟩),
inductionOn a fun α r hr =>
inductionOn b fun β s hs ⟨⟨f, t, hf⟩⟩ => by
haveI := hs
refine ⟨⟨RelEmbedding.ofMonotone (Sum.rec f fun _ => t) (fun a b ↦ ?_), fun a b ↦ ?_⟩⟩
· rcases a with (a | _) <;> rcases b with (b | _)
· simpa only [Sum.lex_inl_inl] using f.map_rel_iff.2
· intro
rw [hf]
exact ⟨_, rfl⟩
· exact False.elim ∘ Sum.lex_inr_inl
· exact False.elim ∘ Sum.lex_inr_inr.1
· rcases a with (a | _)
· intro h
have := @PrincipalSeg.init _ _ _ _ _ ⟨f, t, hf⟩ _ _ h
cases' this with w h
exact ⟨Sum.inl w, h⟩
· intro h
cases' (hf b).1 h with w h
exact ⟨Sum.inl w, h⟩⟩
instance noMaxOrder : NoMaxOrder Ordinal :=
⟨fun _ => ⟨_, succ_le_iff'.1 le_rfl⟩⟩
instance succOrder : SuccOrder Ordinal.{u} :=
SuccOrder.ofSuccLeIff (fun o => o + 1) succ_le_iff'
@[simp]
theorem add_one_eq_succ (o : Ordinal) : o + 1 = succ o :=
rfl
@[simp]
theorem succ_zero : succ (0 : Ordinal) = 1 :=
zero_add 1
-- Porting note: Proof used to be rfl
@[simp]
theorem succ_one : succ (1 : Ordinal) = 2 := by congr; simp only [Nat.unaryCast, zero_add]
theorem add_succ (o₁ o₂ : Ordinal) : o₁ + succ o₂ = succ (o₁ + o₂) :=
(add_assoc _ _ _).symm
theorem one_le_iff_pos {o : Ordinal} : 1 ≤ o ↔ 0 < o := by rw [← succ_zero, succ_le_iff]
theorem one_le_iff_ne_zero {o : Ordinal} : 1 ≤ o ↔ o ≠ 0 := by
rw [one_le_iff_pos, Ordinal.pos_iff_ne_zero]
theorem succ_pos (o : Ordinal) : 0 < succ o :=
bot_lt_succ o
theorem succ_ne_zero (o : Ordinal) : succ o ≠ 0 :=
ne_of_gt <| succ_pos o
@[simp]
theorem lt_one_iff_zero {a : Ordinal} : a < 1 ↔ a = 0 := by
simpa using @lt_succ_bot_iff _ _ _ a _ _
theorem le_one_iff {a : Ordinal} : a ≤ 1 ↔ a = 0 ∨ a = 1 := by
simpa using @le_succ_bot_iff _ _ _ a _
@[simp]
theorem card_succ (o : Ordinal) : card (succ o) = card o + 1 := by
simp only [← add_one_eq_succ, card_add, card_one]
theorem natCast_succ (n : ℕ) : ↑n.succ = succ (n : Ordinal) :=
rfl
@[deprecated (since := "2024-04-17")]
alias nat_cast_succ := natCast_succ
instance uniqueIioOne : Unique (Iio (1 : Ordinal)) where
default := ⟨0, by simp⟩
uniq a := Subtype.ext <| lt_one_iff_zero.1 a.2
instance uniqueOutOne : Unique (1 : Ordinal).out.α where
default := enum (· < ·) 0 (by simp)
uniq a := by
unfold default
rw [← @enum_typein _ (· < ·) (isWellOrder_out_lt _) a]
congr
rw [← lt_one_iff_zero]
apply typein_lt_self
theorem one_out_eq (x : (1 : Ordinal).out.α) : x = enum (· < ·) 0 (by simp) :=
Unique.eq_default x
/-! ### Extra properties of typein and enum -/
@[simp]
theorem typein_one_out (x : (1 : Ordinal).out.α) :
@typein _ (· < ·) (isWellOrder_out_lt _) x = 0 := by
rw [one_out_eq x, typein_enum]
@[simp]
theorem typein_le_typein (r : α → α → Prop) [IsWellOrder α r] {x x' : α} :
typein r x ≤ typein r x' ↔ ¬r x' x := by rw [← not_lt, typein_lt_typein]
-- @[simp] -- Porting note (#10618): simp can prove this
theorem typein_le_typein' (o : Ordinal) {x x' : o.out.α} :
@typein _ (· < ·) (isWellOrder_out_lt _) x ≤ @typein _ (· < ·) (isWellOrder_out_lt _) x'
↔ x ≤ x' := by
rw [typein_le_typein]
exact not_lt
-- Porting note: added nolint, simpnf linter falsely claims it never applies
@[simp, nolint simpNF]
theorem enum_le_enum (r : α → α → Prop) [IsWellOrder α r] {o o' : Ordinal} (ho : o < type r)
(ho' : o' < type r) : ¬r (enum r o' ho') (enum r o ho) ↔ o ≤ o' := by
rw [← @not_lt _ _ o' o, enum_lt_enum ho']
@[simp]
theorem enum_le_enum' (a : Ordinal) {o o' : Ordinal} (ho : o < type (· < ·))
(ho' : o' < type (· < ·)) : enum (· < ·) o ho ≤ @enum a.out.α (· < ·) _ o' ho' ↔ o ≤ o' := by
rw [← @enum_le_enum _ (· < ·) (isWellOrder_out_lt _), ← not_lt]
theorem enum_zero_le {r : α → α → Prop} [IsWellOrder α r] (h0 : 0 < type r) (a : α) :
¬r a (enum r 0 h0) := by
rw [← enum_typein r a, enum_le_enum r]
apply Ordinal.zero_le
theorem enum_zero_le' {o : Ordinal} (h0 : 0 < o) (a : o.out.α) :
@enum o.out.α (· < ·) _ 0 (by rwa [type_lt]) ≤ a := by
rw [← not_lt]
apply enum_zero_le
theorem le_enum_succ {o : Ordinal} (a : (succ o).out.α) :
a ≤
@enum (succ o).out.α (· < ·) _ o
(by
rw [type_lt]
exact lt_succ o) := by
rw [← @enum_typein _ (· < ·) (isWellOrder_out_lt _) a, enum_le_enum', ← lt_succ_iff]
apply typein_lt_self
@[simp]
theorem enum_inj {r : α → α → Prop} [IsWellOrder α r] {o₁ o₂ : Ordinal} (h₁ : o₁ < type r)
(h₂ : o₂ < type r) : enum r o₁ h₁ = enum r o₂ h₂ ↔ o₁ = o₂ :=
(typein.principalSeg r).subrelIso.injective.eq_iff.trans Subtype.mk_eq_mk
-- TODO: Can we remove this definition and just use `(typein.principalSeg r).subrelIso` directly?
/-- A well order `r` is order isomorphic to the set of ordinals smaller than `type r`. -/
@[simps]
def enumIso (r : α → α → Prop) [IsWellOrder α r] : Subrel (· < ·) (· < type r) ≃r r :=
{ (typein.principalSeg r).subrelIso with
toFun := fun x ↦ enum r x.1 x.2
invFun := fun x ↦ ⟨typein r x, typein_lt_type r x⟩ }
/-- The order isomorphism between ordinals less than `o` and `o.out.α`. -/
@[simps!]
noncomputable def enumIsoOut (o : Ordinal) : Set.Iio o ≃o o.out.α where
toFun x :=
enum (· < ·) x.1 <| by
rw [type_lt]
exact x.2
invFun x := ⟨@typein _ (· < ·) (isWellOrder_out_lt _) x, typein_lt_self x⟩
left_inv := fun ⟨o', h⟩ => Subtype.ext_val (typein_enum _ _)
right_inv h := enum_typein _ _
map_rel_iff' := by
rintro ⟨a, _⟩ ⟨b, _⟩
apply enum_le_enum'
/-- `o.out.α` is an `OrderBot` whenever `0 < o`. -/
def outOrderBotOfPos {o : Ordinal} (ho : 0 < o) : OrderBot o.out.α where
bot_le := enum_zero_le' ho
theorem enum_zero_eq_bot {o : Ordinal} (ho : 0 < o) :
enum (· < ·) 0 (by rwa [type_lt]) =
haveI H := outOrderBotOfPos ho
(⊥ : (Quotient.out o).α) :=
rfl
/-! ### Universal ordinal -/
-- intended to be used with explicit universe parameters
/-- `univ.{u v}` is the order type of the ordinals of `Type u` as a member
of `Ordinal.{v}` (when `u < v`). It is an inaccessible cardinal. -/
@[pp_with_univ, nolint checkUnivs]
def univ : Ordinal.{max (u + 1) v} :=
lift.{v, u + 1} (@type Ordinal (· < ·) _)
theorem univ_id : univ.{u, u + 1} = @type Ordinal (· < ·) _ :=
lift_id _
@[simp]
theorem lift_univ : lift.{w} univ.{u, v} = univ.{u, max v w} :=
lift_lift _
theorem univ_umax : univ.{u, max (u + 1) v} = univ.{u, v} :=
congr_fun lift_umax _
/-- Principal segment version of the lift operation on ordinals, embedding `ordinal.{u}` in
`ordinal.{v}` as a principal segment when `u < v`. -/
def lift.principalSeg : @PrincipalSeg Ordinal.{u} Ordinal.{max (u + 1) v} (· < ·) (· < ·) :=
⟨↑lift.initialSeg.{u, max (u + 1) v}, univ.{u, v}, by
refine fun b => inductionOn b ?_; intro β s _
rw [univ, ← lift_umax]; constructor <;> intro h
· rw [← lift_id (type s)] at h ⊢
cases' lift_type_lt.{_,_,v}.1 h with f
cases' f with f a hf
exists a
revert hf
-- Porting note: apply inductionOn does not work, refine does
refine inductionOn a ?_
intro α r _ hf
refine
lift_type_eq.{u, max (u + 1) v, max (u + 1) v}.2
⟨(RelIso.ofSurjective (RelEmbedding.ofMonotone ?_ ?_) ?_).symm⟩
· exact fun b => enum r (f b) ((hf _).2 ⟨_, rfl⟩)
· refine fun a b h => (typein_lt_typein r).1 ?_
rw [typein_enum, typein_enum]
exact f.map_rel_iff.2 h
· intro a'
cases' (hf _).1 (typein_lt_type _ a') with b e
exists b
simp only [RelEmbedding.ofMonotone_coe]
simp [e]
· cases' h with a e
rw [← e]
refine inductionOn a ?_
intro α r _
exact lift_type_lt.{u, u + 1, max (u + 1) v}.2 ⟨typein.principalSeg r⟩⟩
@[simp]
theorem lift.principalSeg_coe :
(lift.principalSeg.{u, v} : Ordinal → Ordinal) = lift.{max (u + 1) v} :=
rfl
-- Porting note: Added universe hints below
@[simp]
theorem lift.principalSeg_top : (lift.principalSeg.{u,v}).top = univ.{u,v} :=
rfl
theorem lift.principalSeg_top' : lift.principalSeg.{u, u + 1}.top = @type Ordinal (· < ·) _ := by
simp only [lift.principalSeg_top, univ_id]
end Ordinal
/-! ### Representing a cardinal with an ordinal -/
namespace Cardinal
open Ordinal
@[simp]
theorem mk_ordinal_out (o : Ordinal) : #o.out.α = o.card :=
(Ordinal.card_type (· < ·)).symm.trans <| by rw [Ordinal.type_lt]
/-- The ordinal corresponding to a cardinal `c` is the least ordinal
whose cardinal is `c`. For the order-embedding version, see `ord.order_embedding`. -/
def ord (c : Cardinal) : Ordinal :=
let F := fun α : Type u => ⨅ r : { r // IsWellOrder α r }, @type α r.1 r.2
Quot.liftOn c F
(by
suffices ∀ {α β}, α ≈ β → F α ≤ F β from
fun α β h => (this h).antisymm (this (Setoid.symm h))
rintro α β ⟨f⟩
refine le_ciInf_iff'.2 fun i => ?_
haveI := @RelEmbedding.isWellOrder _ _ (f ⁻¹'o i.1) _ (↑(RelIso.preimage f i.1)) i.2
exact
(ciInf_le' _
(Subtype.mk (f ⁻¹'o i.val)
(@RelEmbedding.isWellOrder _ _ _ _ (↑(RelIso.preimage f i.1)) i.2))).trans_eq
(Quot.sound ⟨RelIso.preimage f i.1⟩))
theorem ord_eq_Inf (α : Type u) : ord #α = ⨅ r : { r // IsWellOrder α r }, @type α r.1 r.2 :=
rfl
theorem ord_eq (α) : ∃ (r : α → α → Prop) (wo : IsWellOrder α r), ord #α = @type α r wo :=
let ⟨r, wo⟩ := ciInf_mem fun r : { r // IsWellOrder α r } => @type α r.1 r.2
⟨r.1, r.2, wo.symm⟩
theorem ord_le_type (r : α → α → Prop) [h : IsWellOrder α r] : ord #α ≤ type r :=
ciInf_le' _ (Subtype.mk r h)
theorem ord_le {c o} : ord c ≤ o ↔ c ≤ o.card :=
inductionOn c fun α =>
Ordinal.inductionOn o fun β s _ => by
let ⟨r, _, e⟩ := ord_eq α
simp only [card_type]; constructor <;> intro h
· rw [e] at h
exact
let ⟨f⟩ := h
⟨f.toEmbedding⟩
· cases' h with f
have g := RelEmbedding.preimage f s
haveI := RelEmbedding.isWellOrder g
exact le_trans (ord_le_type _) g.ordinal_type_le
theorem gc_ord_card : GaloisConnection ord card := fun _ _ => ord_le
theorem lt_ord {c o} : o < ord c ↔ o.card < c :=
gc_ord_card.lt_iff_lt
@[simp]
theorem card_ord (c) : (ord c).card = c :=
Quotient.inductionOn c fun α => by
let ⟨r, _, e⟩ := ord_eq α
-- Porting note: cardinal.mk_def is now Cardinal.mk'_def, not sure why
simp only [mk'_def, e, card_type]
/-- Galois coinsertion between `Cardinal.ord` and `Ordinal.card`. -/
def gciOrdCard : GaloisCoinsertion ord card :=
gc_ord_card.toGaloisCoinsertion fun c => c.card_ord.le
theorem ord_card_le (o : Ordinal) : o.card.ord ≤ o :=
gc_ord_card.l_u_le _
theorem lt_ord_succ_card (o : Ordinal) : o < (succ o.card).ord :=
lt_ord.2 <| lt_succ _
theorem card_le_iff {o : Ordinal} {c : Cardinal} : o.card ≤ c ↔ o < (succ c).ord := by
rw [lt_ord, lt_succ_iff]
/--
A variation on `Cardinal.lt_ord` using `≤`: If `o` is no greater than the
initial ordinal of cardinality `c`, then its cardinal is no greater than `c`.
The converse, however, is false (for instance, `o = ω+1` and `c = ℵ₀`).
-/
lemma card_le_of_le_ord {o : Ordinal} {c : Cardinal} (ho : o ≤ c.ord) :
o.card ≤ c := by
rw [← card_ord c]; exact Ordinal.card_le_card ho
@[mono]
theorem ord_strictMono : StrictMono ord :=
gciOrdCard.strictMono_l
@[mono]
theorem ord_mono : Monotone ord :=
gc_ord_card.monotone_l
@[simp]
theorem ord_le_ord {c₁ c₂} : ord c₁ ≤ ord c₂ ↔ c₁ ≤ c₂ :=
gciOrdCard.l_le_l_iff
@[simp]
theorem ord_lt_ord {c₁ c₂} : ord c₁ < ord c₂ ↔ c₁ < c₂ :=
ord_strictMono.lt_iff_lt
@[simp]
theorem ord_zero : ord 0 = 0 :=
gc_ord_card.l_bot
@[simp]
theorem ord_nat (n : ℕ) : ord n = n :=
(ord_le.2 (card_nat n).ge).antisymm
(by
induction' n with n IH
· apply Ordinal.zero_le
· exact succ_le_of_lt (IH.trans_lt <| ord_lt_ord.2 <| natCast_lt.2 (Nat.lt_succ_self n)))
@[simp]
theorem ord_one : ord 1 = 1 := by simpa using ord_nat 1
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem ord_ofNat (n : ℕ) [n.AtLeastTwo] : ord (no_index (OfNat.ofNat n)) = OfNat.ofNat n :=
ord_nat n
@[simp]
theorem lift_ord (c) : Ordinal.lift.{u,v} (ord c) = ord (lift.{u,v} c) := by
refine le_antisymm (le_of_forall_lt fun a ha => ?_) ?_
· rcases Ordinal.lt_lift_iff.1 ha with ⟨a, rfl, _⟩
rwa [lt_ord, ← lift_card, lift_lt, ← lt_ord, ← Ordinal.lift_lt]
· rw [ord_le, ← lift_card, card_ord]
theorem mk_ord_out (c : Cardinal) : #c.ord.out.α = c := by simp
theorem card_typein_lt (r : α → α → Prop) [IsWellOrder α r] (x : α) (h : ord #α = type r) :
card (typein r x) < #α := by
rw [← lt_ord, h]
apply typein_lt_type
theorem card_typein_out_lt (c : Cardinal) (x : c.ord.out.α) :
card (@typein _ (· < ·) (isWellOrder_out_lt _) x) < c := by
rw [← lt_ord]
apply typein_lt_self
theorem mk_Iio_ord_out_α {c : Cardinal} (i : c.ord.out.α) : #(Iio i) < c := card_typein_out_lt c i
theorem ord_injective : Injective ord := by
intro c c' h
rw [← card_ord c, ← card_ord c', h]
/-- The ordinal corresponding to a cardinal `c` is the least ordinal
whose cardinal is `c`. This is the order-embedding version. For the regular function, see `ord`.
-/
def ord.orderEmbedding : Cardinal ↪o Ordinal :=
RelEmbedding.orderEmbeddingOfLTEmbedding
(RelEmbedding.ofMonotone Cardinal.ord fun _ _ => Cardinal.ord_lt_ord.2)
@[simp]
theorem ord.orderEmbedding_coe : (ord.orderEmbedding : Cardinal → Ordinal) = ord :=
rfl
-- intended to be used with explicit universe parameters
/-- The cardinal `univ` is the cardinality of ordinal `univ`, or
equivalently the cardinal of `Ordinal.{u}`, or `Cardinal.{u}`,
as an element of `Cardinal.{v}` (when `u < v`). -/
@[pp_with_univ, nolint checkUnivs]
def univ :=
lift.{v, u + 1} #Ordinal
theorem univ_id : univ.{u, u + 1} = #Ordinal :=
lift_id _
@[simp]
theorem lift_univ : lift.{w} univ.{u, v} = univ.{u, max v w} :=
lift_lift _
theorem univ_umax : univ.{u, max (u + 1) v} = univ.{u, v} :=
congr_fun lift_umax _
theorem lift_lt_univ (c : Cardinal) : lift.{u + 1, u} c < univ.{u, u + 1} := by
simpa only [lift.principalSeg_coe, lift_ord, lift_succ, ord_le, succ_le_iff] using
le_of_lt (lift.principalSeg.{u, u + 1}.lt_top (succ c).ord)
theorem lift_lt_univ' (c : Cardinal) : lift.{max (u + 1) v, u} c < univ.{u, v} := by
have := lift_lt.{_, max (u+1) v}.2 (lift_lt_univ c)
rw [lift_lift, lift_univ, univ_umax.{u,v}] at this
exact this
@[simp]
theorem ord_univ : ord univ.{u, v} = Ordinal.univ.{u, v} := by
refine le_antisymm (ord_card_le _) <| le_of_forall_lt fun o h => lt_ord.2 ?_
have := lift.principalSeg.{u, v}.down.1 (by simpa only [lift.principalSeg_coe] using h)
rcases this with ⟨o, h'⟩
rw [← h', lift.principalSeg_coe, ← lift_card]
apply lift_lt_univ'
theorem lt_univ {c} : c < univ.{u, u + 1} ↔ ∃ c', c = lift.{u + 1, u} c' :=
⟨fun h => by
have := ord_lt_ord.2 h
rw [ord_univ] at this
cases' lift.principalSeg.{u, u + 1}.down.1 (by simpa only [lift.principalSeg_top] ) with o e
have := card_ord c
rw [← e, lift.principalSeg_coe, ← lift_card] at this
exact ⟨_, this.symm⟩, fun ⟨c', e⟩ => e.symm ▸ lift_lt_univ _⟩
theorem lt_univ' {c} : c < univ.{u, v} ↔ ∃ c', c = lift.{max (u + 1) v, u} c' :=
⟨fun h => by
let ⟨a, e, h'⟩ := lt_lift_iff.1 h
rw [← univ_id] at h'
rcases lt_univ.{u}.1 h' with ⟨c', rfl⟩
exact ⟨c', by simp only [e.symm, lift_lift]⟩, fun ⟨c', e⟩ => e.symm ▸ lift_lt_univ' _⟩
theorem small_iff_lift_mk_lt_univ {α : Type u} :
Small.{v} α ↔ Cardinal.lift.{v+1,_} #α < univ.{v, max u (v + 1)} := by
rw [lt_univ']
constructor
· rintro ⟨β, e⟩
exact ⟨#β, lift_mk_eq.{u, _, v + 1}.2 e⟩
· rintro ⟨c, hc⟩
exact ⟨⟨c.out, lift_mk_eq.{u, _, v + 1}.1 (hc.trans (congr rfl c.mk_out.symm))⟩⟩
end Cardinal
namespace Ordinal
@[simp]
theorem card_univ : card univ.{u,v} = Cardinal.univ.{u,v} :=
rfl
@[simp]
theorem nat_le_card {o} {n : ℕ} : (n : Cardinal) ≤ card o ↔ (n : Ordinal) ≤ o := by
rw [← Cardinal.ord_le, Cardinal.ord_nat]
@[simp]
theorem one_le_card {o} : 1 ≤ card o ↔ 1 ≤ o := by
simpa using nat_le_card (n := 1)
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem ofNat_le_card {o} {n : ℕ} [n.AtLeastTwo] :
(no_index (OfNat.ofNat n : Cardinal)) ≤ card o ↔ (OfNat.ofNat n : Ordinal) ≤ o :=
nat_le_card
@[simp]
theorem nat_lt_card {o} {n : ℕ} : (n : Cardinal) < card o ↔ (n : Ordinal) < o := by
rw [← succ_le_iff, ← succ_le_iff, ← nat_succ, nat_le_card]
rfl
@[simp]
theorem zero_lt_card {o} : 0 < card o ↔ 0 < o := by
simpa using nat_lt_card (n := 0)
@[simp]
theorem one_lt_card {o} : 1 < card o ↔ 1 < o := by
simpa using nat_lt_card (n := 1)
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem ofNat_lt_card {o} {n : ℕ} [n.AtLeastTwo] :
(no_index (OfNat.ofNat n : Cardinal)) < card o ↔ (OfNat.ofNat n : Ordinal) < o :=
nat_lt_card
@[simp]
theorem card_lt_nat {o} {n : ℕ} : card o < n ↔ o < n :=
lt_iff_lt_of_le_iff_le nat_le_card
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem card_lt_ofNat {o} {n : ℕ} [n.AtLeastTwo] :
card o < (no_index (OfNat.ofNat n)) ↔ o < OfNat.ofNat n :=
card_lt_nat
@[simp]
theorem card_le_nat {o} {n : ℕ} : card o ≤ n ↔ o ≤ n :=
le_iff_le_iff_lt_iff_lt.2 nat_lt_card
@[simp]
theorem card_le_one {o} : card o ≤ 1 ↔ o ≤ 1 := by
simpa using card_le_nat (n := 1)
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem card_le_ofNat {o} {n : ℕ} [n.AtLeastTwo] :
card o ≤ (no_index (OfNat.ofNat n)) ↔ o ≤ OfNat.ofNat n :=
card_le_nat
@[simp]
theorem card_eq_nat {o} {n : ℕ} : card o = n ↔ o = n := by
simp only [le_antisymm_iff, card_le_nat, nat_le_card]
@[simp]
theorem card_eq_zero {o} : card o = 0 ↔ o = 0 := by
simpa using card_eq_nat (n := 0)
@[simp]
theorem card_eq_one {o} : card o = 1 ↔ o = 1 := by
simpa using card_eq_nat (n := 1)
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem card_eq_ofNat {o} {n : ℕ} [n.AtLeastTwo] :
card o = (no_index (OfNat.ofNat n)) ↔ o = OfNat.ofNat n :=
card_eq_nat
@[simp]
theorem type_fintype (r : α → α → Prop) [IsWellOrder α r] [Fintype α] :
type r = Fintype.card α := by rw [← card_eq_nat, card_type, mk_fintype]
theorem type_fin (n : ℕ) : @type (Fin n) (· < ·) _ = n := by simp
end Ordinal
/-! ### Sorted lists -/
theorem List.Sorted.lt_ord_of_lt [LinearOrder α] [IsWellOrder α (· < ·)] {l m : List α}
{o : Ordinal} (hl : l.Sorted (· > ·)) (hm : m.Sorted (· > ·)) (hmltl : m < l)
(hlt : ∀ i ∈ l, Ordinal.typein (· < ·) i < o) : ∀ i ∈ m, Ordinal.typein (· < ·) i < o := by
replace hmltl : List.Lex (· < ·) m l := hmltl
cases l with
| nil => simp at hmltl
| cons a as =>
cases m with
| nil => intro i hi; simp at hi
| cons b bs =>
intro i hi
suffices h : i ≤ a by refine lt_of_le_of_lt ?_ (hlt a (mem_cons_self a as)); simpa
cases hi with
| head as => exact List.head_le_of_lt hmltl
| tail b hi => exact le_of_lt (lt_of_lt_of_le (List.rel_of_sorted_cons hm _ hi)
(List.head_le_of_lt hmltl))
|
SetTheory\Ordinal\CantorNormalForm.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.SetTheory.Ordinal.Arithmetic
import Mathlib.SetTheory.Ordinal.Exponential
/-!
# Cantor Normal Form
The Cantor normal form of an ordinal is generally defined as its base `ω` expansion, with its
non-zero exponents in decreasing order. Here, we more generally define a base `b` expansion
`Ordinal.CNF` in this manner, which is well-behaved for any `b ≥ 2`.
# Implementation notes
We implement `Ordinal.CNF` as an association list, where keys are exponents and values are
coefficients. This is because this structure intrinsically reflects two key properties of the Cantor
normal form:
- It is ordered.
- It has finitely many entries.
# Todo
- Add API for the coefficients of the Cantor normal form.
- Prove the basic results relating the CNF to the arithmetic operations on ordinals.
-/
noncomputable section
universe u
open List
namespace Ordinal
/-- Inducts on the base `b` expansion of an ordinal. -/
@[elab_as_elim]
noncomputable def CNFRec (b : Ordinal) {C : Ordinal → Sort*} (H0 : C 0)
(H : ∀ o, o ≠ 0 → C (o % b ^ log b o) → C o) : ∀ o, C o := fun o ↦ by
by_cases h : o = 0
· rw [h]; exact H0
· exact H o h (CNFRec _ H0 H (o % b ^ log b o))
termination_by o => o
decreasing_by exact mod_opow_log_lt_self b h
@[simp]
theorem CNFRec_zero {C : Ordinal → Sort*} (b : Ordinal) (H0 : C 0)
(H : ∀ o, o ≠ 0 → C (o % b ^ log b o) → C o) : @CNFRec b C H0 H 0 = H0 := by
rw [CNFRec, dif_pos rfl]
rfl
theorem CNFRec_pos (b : Ordinal) {o : Ordinal} {C : Ordinal → Sort*} (ho : o ≠ 0) (H0 : C 0)
(H : ∀ o, o ≠ 0 → C (o % b ^ log b o) → C o) :
@CNFRec b C H0 H o = H o ho (@CNFRec b C H0 H _) := by rw [CNFRec, dif_neg ho]
/-- The Cantor normal form of an ordinal `o` is the list of coefficients and exponents in the
base-`b` expansion of `o`.
We special-case `CNF 0 o = CNF 1 o = [(0, o)]` for `o ≠ 0`.
`CNF b (b ^ u₁ * v₁ + b ^ u₂ * v₂) = [(u₁, v₁), (u₂, v₂)]` -/
@[pp_nodot]
def CNF (b o : Ordinal) : List (Ordinal × Ordinal) :=
CNFRec b [] (fun o _ho IH ↦ (log b o, o / b ^ log b o)::IH) o
@[simp]
theorem CNF_zero (b : Ordinal) : CNF b 0 = [] :=
CNFRec_zero b _ _
/-- Recursive definition for the Cantor normal form. -/
theorem CNF_ne_zero {b o : Ordinal} (ho : o ≠ 0) :
CNF b o = (log b o, o / b ^ log b o)::CNF b (o % b ^ log b o) :=
CNFRec_pos b ho _ _
theorem zero_CNF {o : Ordinal} (ho : o ≠ 0) : CNF 0 o = [⟨0, o⟩] := by simp [CNF_ne_zero ho]
theorem one_CNF {o : Ordinal} (ho : o ≠ 0) : CNF 1 o = [⟨0, o⟩] := by simp [CNF_ne_zero ho]
theorem CNF_of_le_one {b o : Ordinal} (hb : b ≤ 1) (ho : o ≠ 0) : CNF b o = [⟨0, o⟩] := by
rcases le_one_iff.1 hb with (rfl | rfl)
· exact zero_CNF ho
· exact one_CNF ho
theorem CNF_of_lt {b o : Ordinal} (ho : o ≠ 0) (hb : o < b) : CNF b o = [⟨0, o⟩] := by
simp only [CNF_ne_zero ho, log_eq_zero hb, opow_zero, div_one, mod_one, CNF_zero]
/-- Evaluating the Cantor normal form of an ordinal returns the ordinal. -/
theorem CNF_foldr (b o : Ordinal) : (CNF b o).foldr (fun p r ↦ b ^ p.1 * p.2 + r) 0 = o :=
CNFRec b (by rw [CNF_zero]; rfl)
(fun o ho IH ↦ by rw [CNF_ne_zero ho, foldr_cons, IH, div_add_mod]) o
/-- Every exponent in the Cantor normal form `CNF b o` is less or equal to `log b o`. -/
theorem CNF_fst_le_log {b o : Ordinal.{u}} {x : Ordinal × Ordinal} :
x ∈ CNF b o → x.1 ≤ log b o := by
refine CNFRec b ?_ (fun o ho H ↦ ?_) o
· rw [CNF_zero]
intro contra; contradiction
· rw [CNF_ne_zero ho, mem_cons]
rintro (rfl | h)
· exact le_rfl
· exact (H h).trans (log_mono_right _ (mod_opow_log_lt_self b ho).le)
/-- Every exponent in the Cantor normal form `CNF b o` is less or equal to `o`. -/
theorem CNF_fst_le {b o : Ordinal.{u}} {x : Ordinal × Ordinal} (h : x ∈ CNF b o) : x.1 ≤ o :=
(CNF_fst_le_log h).trans <| log_le_self _ _
/-- Every coefficient in a Cantor normal form is positive. -/
theorem CNF_lt_snd {b o : Ordinal.{u}} {x : Ordinal × Ordinal} : x ∈ CNF b o → 0 < x.2 := by
refine CNFRec b (by simp) (fun o ho IH ↦ ?_) o
rw [CNF_ne_zero ho]
rintro (h | ⟨_, h⟩)
· exact div_opow_log_pos b ho
· exact IH h
/-- Every coefficient in the Cantor normal form `CNF b o` is less than `b`. -/
theorem CNF_snd_lt {b o : Ordinal.{u}} (hb : 1 < b) {x : Ordinal × Ordinal} :
x ∈ CNF b o → x.2 < b := by
refine CNFRec b ?_ (fun o ho IH ↦ ?_) o
· simp only [CNF_zero, not_mem_nil, IsEmpty.forall_iff]
· rw [CNF_ne_zero ho]
intro h
cases' (mem_cons.mp h) with h h
· rw [h]; simpa only using div_opow_log_lt o hb
· exact IH h
/-- The exponents of the Cantor normal form are decreasing. -/
theorem CNF_sorted (b o : Ordinal) : ((CNF b o).map Prod.fst).Sorted (· > ·) := by
refine CNFRec b ?_ (fun o ho IH ↦ ?_) o
· simp only [gt_iff_lt, CNF_zero, map_nil, sorted_nil]
· rcases le_or_lt b 1 with hb | hb
· simp only [CNF_of_le_one hb ho, gt_iff_lt, map_cons, map, sorted_singleton]
· cases' lt_or_le o b with hob hbo
· simp only [CNF_of_lt ho hob, gt_iff_lt, map_cons, map, sorted_singleton]
· rw [CNF_ne_zero ho, map_cons, sorted_cons]
refine ⟨fun a H ↦ ?_, IH⟩
rw [mem_map] at H
rcases H with ⟨⟨a, a'⟩, H, rfl⟩
exact (CNF_fst_le_log H).trans_lt (log_mod_opow_log_lt_log_self hb ho hbo)
end Ordinal
|
SetTheory\Ordinal\Exponential.lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn, Violeta Hernández Palacios
-/
import Mathlib.SetTheory.Ordinal.Arithmetic
/-! # Ordinal exponential
In this file we define the power function and the logarithm function on ordinals. The two are
related by the lemma `Ordinal.opow_le_iff_le_log : b ^ c ≤ x ↔ c ≤ log b x` for nontrivial inputs
`b`, `c`.
-/
noncomputable section
open Function Cardinal Set Equiv Order
open scoped Classical
open Cardinal Ordinal
universe u v w
namespace Ordinal
/-- The ordinal exponential, defined by transfinite recursion. -/
instance pow : Pow Ordinal Ordinal :=
⟨fun a b => if a = 0 then 1 - b else limitRecOn b 1 (fun _ IH => IH * a) fun b _ => bsup.{u, u} b⟩
-- Porting note: Ambiguous notations.
-- local infixr:0 "^" => @Pow.pow Ordinal Ordinal Ordinal.instPowOrdinalOrdinal
theorem opow_def (a b : Ordinal) :
a ^ b = if a = 0 then 1 - b else limitRecOn b 1 (fun _ IH => IH * a) fun b _ => bsup.{u, u} b :=
rfl
-- Porting note: `if_pos rfl` → `if_true`
theorem zero_opow' (a : Ordinal) : 0 ^ a = 1 - a := by simp only [opow_def, if_true]
@[simp]
theorem zero_opow {a : Ordinal} (a0 : a ≠ 0) : (0 : Ordinal) ^ a = 0 := by
rwa [zero_opow', Ordinal.sub_eq_zero_iff_le, one_le_iff_ne_zero]
@[simp]
theorem opow_zero (a : Ordinal) : a ^ (0 : Ordinal) = 1 := by
by_cases h : a = 0
· simp only [opow_def, if_pos h, sub_zero]
· simp only [opow_def, if_neg h, limitRecOn_zero]
@[simp]
theorem opow_succ (a b : Ordinal) : a ^ succ b = a ^ b * a :=
if h : a = 0 then by subst a; simp only [zero_opow (succ_ne_zero _), mul_zero]
else by simp only [opow_def, limitRecOn_succ, if_neg h]
theorem opow_limit {a b : Ordinal} (a0 : a ≠ 0) (h : IsLimit b) :
a ^ b = bsup.{u, u} b fun c _ => a ^ c := by
simp only [opow_def, if_neg a0]; rw [limitRecOn_limit _ _ _ _ h]
theorem opow_le_of_limit {a b c : Ordinal} (a0 : a ≠ 0) (h : IsLimit b) :
a ^ b ≤ c ↔ ∀ b' < b, a ^ b' ≤ c := by rw [opow_limit a0 h, bsup_le_iff]
theorem lt_opow_of_limit {a b c : Ordinal} (b0 : b ≠ 0) (h : IsLimit c) :
a < b ^ c ↔ ∃ c' < c, a < b ^ c' := by
rw [← not_iff_not, not_exists]; simp only [not_lt, opow_le_of_limit b0 h, exists_prop, not_and]
@[simp]
theorem opow_one (a : Ordinal) : a ^ (1 : Ordinal) = a := by
rw [← succ_zero, opow_succ]; simp only [opow_zero, one_mul]
@[simp]
theorem one_opow (a : Ordinal) : (1 : Ordinal) ^ a = 1 := by
induction a using limitRecOn with
| H₁ => simp only [opow_zero]
| H₂ _ ih =>
simp only [opow_succ, ih, mul_one]
| H₃ b l IH =>
refine eq_of_forall_ge_iff fun c => ?_
rw [opow_le_of_limit Ordinal.one_ne_zero l]
exact ⟨fun H => by simpa only [opow_zero] using H 0 l.pos, fun H b' h => by rwa [IH _ h]⟩
theorem opow_pos {a : Ordinal} (b : Ordinal) (a0 : 0 < a) : 0 < a ^ b := by
have h0 : 0 < a ^ (0 : Ordinal) := by simp only [opow_zero, zero_lt_one]
induction b using limitRecOn with
| H₁ => exact h0
| H₂ b IH =>
rw [opow_succ]
exact mul_pos IH a0
| H₃ b l _ =>
exact (lt_opow_of_limit (Ordinal.pos_iff_ne_zero.1 a0) l).2 ⟨0, l.pos, h0⟩
theorem opow_ne_zero {a : Ordinal} (b : Ordinal) (a0 : a ≠ 0) : a ^ b ≠ 0 :=
Ordinal.pos_iff_ne_zero.1 <| opow_pos b <| Ordinal.pos_iff_ne_zero.2 a0
theorem opow_isNormal {a : Ordinal} (h : 1 < a) : IsNormal (a ^ ·) :=
have a0 : 0 < a := zero_lt_one.trans h
⟨fun b => by simpa only [mul_one, opow_succ] using (mul_lt_mul_iff_left (opow_pos b a0)).2 h,
fun b l c => opow_le_of_limit (ne_of_gt a0) l⟩
theorem opow_lt_opow_iff_right {a b c : Ordinal} (a1 : 1 < a) : a ^ b < a ^ c ↔ b < c :=
(opow_isNormal a1).lt_iff
theorem opow_le_opow_iff_right {a b c : Ordinal} (a1 : 1 < a) : a ^ b ≤ a ^ c ↔ b ≤ c :=
(opow_isNormal a1).le_iff
theorem opow_right_inj {a b c : Ordinal} (a1 : 1 < a) : a ^ b = a ^ c ↔ b = c :=
(opow_isNormal a1).inj
theorem opow_isLimit {a b : Ordinal} (a1 : 1 < a) : IsLimit b → IsLimit (a ^ b) :=
(opow_isNormal a1).isLimit
theorem opow_isLimit_left {a b : Ordinal} (l : IsLimit a) (hb : b ≠ 0) : IsLimit (a ^ b) := by
rcases zero_or_succ_or_limit b with (e | ⟨b, rfl⟩ | l')
· exact absurd e hb
· rw [opow_succ]
exact mul_isLimit (opow_pos _ l.pos) l
· exact opow_isLimit l.one_lt l'
theorem opow_le_opow_right {a b c : Ordinal} (h₁ : 0 < a) (h₂ : b ≤ c) : a ^ b ≤ a ^ c := by
rcases lt_or_eq_of_le (one_le_iff_pos.2 h₁) with h₁ | h₁
· exact (opow_le_opow_iff_right h₁).2 h₂
· subst a
-- Porting note: `le_refl` is required.
simp only [one_opow, le_refl]
theorem opow_le_opow_left {a b : Ordinal} (c : Ordinal) (ab : a ≤ b) : a ^ c ≤ b ^ c := by
by_cases a0 : a = 0
-- Porting note: `le_refl` is required.
· subst a
by_cases c0 : c = 0
· subst c
simp only [opow_zero, le_refl]
· simp only [zero_opow c0, Ordinal.zero_le]
· induction c using limitRecOn with
| H₁ => simp only [opow_zero, le_refl]
| H₂ c IH =>
simpa only [opow_succ] using mul_le_mul' IH ab
| H₃ c l IH =>
exact
(opow_le_of_limit a0 l).2 fun b' h =>
(IH _ h).trans (opow_le_opow_right ((Ordinal.pos_iff_ne_zero.2 a0).trans_le ab) h.le)
theorem left_le_opow (a : Ordinal) {b : Ordinal} (b1 : 0 < b) : a ≤ a ^ b := by
nth_rw 1 [← opow_one a]
cases' le_or_gt a 1 with a1 a1
· rcases lt_or_eq_of_le a1 with a0 | a1
· rw [lt_one_iff_zero] at a0
rw [a0, zero_opow Ordinal.one_ne_zero]
exact Ordinal.zero_le _
rw [a1, one_opow, one_opow]
rwa [opow_le_opow_iff_right a1, one_le_iff_pos]
theorem right_le_opow {a : Ordinal} (b : Ordinal) (a1 : 1 < a) : b ≤ a ^ b :=
(opow_isNormal a1).self_le _
theorem opow_lt_opow_left_of_succ {a b c : Ordinal} (ab : a < b) : a ^ succ c < b ^ succ c := by
rw [opow_succ, opow_succ]
exact
(mul_le_mul_right' (opow_le_opow_left c ab.le) a).trans_lt
(mul_lt_mul_of_pos_left ab (opow_pos c ((Ordinal.zero_le a).trans_lt ab)))
theorem opow_add (a b c : Ordinal) : a ^ (b + c) = a ^ b * a ^ c := by
rcases eq_or_ne a 0 with (rfl | a0)
· rcases eq_or_ne c 0 with (rfl | c0)
· simp
have : b + c ≠ 0 := ((Ordinal.pos_iff_ne_zero.2 c0).trans_le (le_add_left _ _)).ne'
simp only [zero_opow c0, zero_opow this, mul_zero]
rcases eq_or_lt_of_le (one_le_iff_ne_zero.2 a0) with (rfl | a1)
· simp only [one_opow, mul_one]
induction c using limitRecOn with
| H₁ => simp
| H₂ c IH =>
rw [add_succ, opow_succ, IH, opow_succ, mul_assoc]
| H₃ c l IH =>
refine
eq_of_forall_ge_iff fun d =>
(((opow_isNormal a1).trans (add_isNormal b)).limit_le l).trans ?_
dsimp only [Function.comp_def]
simp (config := { contextual := true }) only [IH]
exact
(((mul_isNormal <| opow_pos b (Ordinal.pos_iff_ne_zero.2 a0)).trans
(opow_isNormal a1)).limit_le
l).symm
theorem opow_one_add (a b : Ordinal) : a ^ (1 + b) = a * a ^ b := by rw [opow_add, opow_one]
theorem opow_dvd_opow (a : Ordinal) {b c : Ordinal} (h : b ≤ c) : a ^ b ∣ a ^ c :=
⟨a ^ (c - b), by rw [← opow_add, Ordinal.add_sub_cancel_of_le h]⟩
theorem opow_dvd_opow_iff {a b c : Ordinal} (a1 : 1 < a) : a ^ b ∣ a ^ c ↔ b ≤ c :=
⟨fun h =>
le_of_not_lt fun hn =>
not_le_of_lt ((opow_lt_opow_iff_right a1).2 hn) <|
le_of_dvd (opow_ne_zero _ <| one_le_iff_ne_zero.1 <| a1.le) h,
opow_dvd_opow _⟩
theorem opow_mul (a b c : Ordinal) : a ^ (b * c) = (a ^ b) ^ c := by
by_cases b0 : b = 0; · simp only [b0, zero_mul, opow_zero, one_opow]
by_cases a0 : a = 0
· subst a
by_cases c0 : c = 0
· simp only [c0, mul_zero, opow_zero]
simp only [zero_opow b0, zero_opow c0, zero_opow (mul_ne_zero b0 c0)]
cases' eq_or_lt_of_le (one_le_iff_ne_zero.2 a0) with a1 a1
· subst a1
simp only [one_opow]
induction c using limitRecOn with
| H₁ => simp only [mul_zero, opow_zero]
| H₂ c IH =>
rw [mul_succ, opow_add, IH, opow_succ]
| H₃ c l IH =>
refine
eq_of_forall_ge_iff fun d =>
(((opow_isNormal a1).trans (mul_isNormal (Ordinal.pos_iff_ne_zero.2 b0))).limit_le
l).trans
?_
dsimp only [Function.comp_def]
simp (config := { contextual := true }) only [IH]
exact (opow_le_of_limit (opow_ne_zero _ a0) l).symm
/-! ### Ordinal logarithm -/
/-- The ordinal logarithm is the solution `u` to the equation `x = b ^ u * v + w` where `v < b` and
`w < b ^ u`. -/
@[pp_nodot]
def log (b : Ordinal) (x : Ordinal) : Ordinal :=
if _h : 1 < b then pred (sInf { o | x < b ^ o }) else 0
/-- The set in the definition of `log` is nonempty. -/
theorem log_nonempty {b x : Ordinal} (h : 1 < b) : { o : Ordinal | x < b ^ o }.Nonempty :=
⟨_, succ_le_iff.1 (right_le_opow _ h)⟩
theorem log_def {b : Ordinal} (h : 1 < b) (x : Ordinal) :
log b x = pred (sInf { o | x < b ^ o }) := by simp only [log, dif_pos h]
theorem log_of_not_one_lt_left {b : Ordinal} (h : ¬1 < b) (x : Ordinal) : log b x = 0 := by
simp only [log, dif_neg h]
theorem log_of_left_le_one {b : Ordinal} (h : b ≤ 1) : ∀ x, log b x = 0 :=
log_of_not_one_lt_left h.not_lt
@[simp]
theorem log_zero_left : ∀ b, log 0 b = 0 :=
log_of_left_le_one zero_le_one
@[simp]
theorem log_zero_right (b : Ordinal) : log b 0 = 0 :=
if b1 : 1 < b then by
rw [log_def b1, ← Ordinal.le_zero, pred_le]
apply csInf_le'
dsimp
rw [succ_zero, opow_one]
exact zero_lt_one.trans b1
else by simp only [log_of_not_one_lt_left b1]
@[simp]
theorem log_one_left : ∀ b, log 1 b = 0 :=
log_of_left_le_one le_rfl
theorem succ_log_def {b x : Ordinal} (hb : 1 < b) (hx : x ≠ 0) :
succ (log b x) = sInf { o : Ordinal | x < b ^ o } := by
let t := sInf { o : Ordinal | x < b ^ o }
have : x < (b^t) := csInf_mem (log_nonempty hb)
rcases zero_or_succ_or_limit t with (h | h | h)
· refine ((one_le_iff_ne_zero.2 hx).not_lt ?_).elim
simpa only [h, opow_zero] using this
· rw [show log b x = pred t from log_def hb x, succ_pred_iff_is_succ.2 h]
· rcases (lt_opow_of_limit (zero_lt_one.trans hb).ne' h).1 this with ⟨a, h₁, h₂⟩
exact h₁.not_le.elim ((le_csInf_iff'' (log_nonempty hb)).1 le_rfl a h₂)
theorem lt_opow_succ_log_self {b : Ordinal} (hb : 1 < b) (x : Ordinal) :
x < b ^ succ (log b x) := by
rcases eq_or_ne x 0 with (rfl | hx)
· apply opow_pos _ (zero_lt_one.trans hb)
· rw [succ_log_def hb hx]
exact csInf_mem (log_nonempty hb)
theorem opow_log_le_self (b : Ordinal) {x : Ordinal} (hx : x ≠ 0) : b ^ log b x ≤ x := by
rcases eq_or_ne b 0 with (rfl | b0)
· rw [zero_opow']
exact (sub_le_self _ _).trans (one_le_iff_ne_zero.2 hx)
rcases lt_or_eq_of_le (one_le_iff_ne_zero.2 b0) with (hb | rfl)
· refine le_of_not_lt fun h => (lt_succ (log b x)).not_le ?_
have := @csInf_le' _ _ { o | x < b ^ o } _ h
rwa [← succ_log_def hb hx] at this
· rwa [one_opow, one_le_iff_ne_zero]
/-- `opow b` and `log b` (almost) form a Galois connection. -/
theorem opow_le_iff_le_log {b x c : Ordinal} (hb : 1 < b) (hx : x ≠ 0) : b ^ c ≤ x ↔ c ≤ log b x :=
⟨fun h =>
le_of_not_lt fun hn =>
(lt_opow_succ_log_self hb x).not_le <|
((opow_le_opow_iff_right hb).2 (succ_le_of_lt hn)).trans h,
fun h => ((opow_le_opow_iff_right hb).2 h).trans (opow_log_le_self b hx)⟩
theorem lt_opow_iff_log_lt {b x c : Ordinal} (hb : 1 < b) (hx : x ≠ 0) : x < b ^ c ↔ log b x < c :=
lt_iff_lt_of_le_iff_le (opow_le_iff_le_log hb hx)
theorem log_pos {b o : Ordinal} (hb : 1 < b) (ho : o ≠ 0) (hbo : b ≤ o) : 0 < log b o := by
rwa [← succ_le_iff, succ_zero, ← opow_le_iff_le_log hb ho, opow_one]
theorem log_eq_zero {b o : Ordinal} (hbo : o < b) : log b o = 0 := by
rcases eq_or_ne o 0 with (rfl | ho)
· exact log_zero_right b
rcases le_or_lt b 1 with hb | hb
· rcases le_one_iff.1 hb with (rfl | rfl)
· exact log_zero_left o
· exact log_one_left o
· rwa [← Ordinal.le_zero, ← lt_succ_iff, succ_zero, ← lt_opow_iff_log_lt hb ho, opow_one]
@[mono]
theorem log_mono_right (b : Ordinal) {x y : Ordinal} (xy : x ≤ y) : log b x ≤ log b y :=
if hx : x = 0 then by simp only [hx, log_zero_right, Ordinal.zero_le]
else
if hb : 1 < b then
(opow_le_iff_le_log hb (lt_of_lt_of_le (Ordinal.pos_iff_ne_zero.2 hx) xy).ne').1 <|
(opow_log_le_self _ hx).trans xy
else by simp only [log_of_not_one_lt_left hb, Ordinal.zero_le]
theorem log_le_self (b x : Ordinal) : log b x ≤ x :=
if hx : x = 0 then by simp only [hx, log_zero_right, Ordinal.zero_le]
else
if hb : 1 < b then (right_le_opow _ hb).trans (opow_log_le_self b hx)
else by simp only [log_of_not_one_lt_left hb, Ordinal.zero_le]
@[simp]
theorem log_one_right (b : Ordinal) : log b 1 = 0 :=
if hb : 1 < b then log_eq_zero hb else log_of_not_one_lt_left hb 1
theorem mod_opow_log_lt_self (b : Ordinal) {o : Ordinal} (ho : o ≠ 0) : o % (b ^ log b o) < o := by
rcases eq_or_ne b 0 with (rfl | hb)
· simpa using Ordinal.pos_iff_ne_zero.2 ho
· exact (mod_lt _ <| opow_ne_zero _ hb).trans_le (opow_log_le_self _ ho)
theorem log_mod_opow_log_lt_log_self {b o : Ordinal} (hb : 1 < b) (ho : o ≠ 0) (hbo : b ≤ o) :
log b (o % (b ^ log b o)) < log b o := by
rcases eq_or_ne (o % (b ^ log b o)) 0 with h | h
· rw [h, log_zero_right]
apply log_pos hb ho hbo
· rw [← succ_le_iff, succ_log_def hb h]
apply csInf_le'
apply mod_lt
rw [← Ordinal.pos_iff_ne_zero]
exact opow_pos _ (zero_lt_one.trans hb)
theorem opow_mul_add_pos {b v : Ordinal} (hb : b ≠ 0) (u : Ordinal) (hv : v ≠ 0) (w : Ordinal) :
0 < b ^ u * v + w :=
(opow_pos u <| Ordinal.pos_iff_ne_zero.2 hb).trans_le <|
(le_mul_left _ <| Ordinal.pos_iff_ne_zero.2 hv).trans <| le_add_right _ _
theorem opow_mul_add_lt_opow_mul_succ {b u w : Ordinal} (v : Ordinal) (hw : w < b ^ u) :
b ^ u * v + w < b ^ u * succ v := by rwa [mul_succ, add_lt_add_iff_left]
theorem opow_mul_add_lt_opow_succ {b u v w : Ordinal} (hvb : v < b) (hw : w < b ^ u) :
b ^ u * v + w < b ^ succ u := by
convert (opow_mul_add_lt_opow_mul_succ v hw).trans_le (mul_le_mul_left' (succ_le_of_lt hvb) _)
using 1
exact opow_succ b u
theorem log_opow_mul_add {b u v w : Ordinal} (hb : 1 < b) (hv : v ≠ 0) (hvb : v < b)
(hw : w < b ^ u) : log b (b ^ u * v + w) = u := by
have hne' := (opow_mul_add_pos (zero_lt_one.trans hb).ne' u hv w).ne'
by_contra! hne
cases' lt_or_gt_of_ne hne with h h
· rw [← lt_opow_iff_log_lt hb hne'] at h
exact h.not_le ((le_mul_left _ (Ordinal.pos_iff_ne_zero.2 hv)).trans (le_add_right _ _))
· conv at h => change u < log b (b ^ u * v + w)
rw [← succ_le_iff, ← opow_le_iff_le_log hb hne'] at h
exact (not_lt_of_le h) (opow_mul_add_lt_opow_succ hvb hw)
theorem log_opow {b : Ordinal} (hb : 1 < b) (x : Ordinal) : log b (b ^ x) = x := by
convert log_opow_mul_add hb zero_ne_one.symm hb (opow_pos x (zero_lt_one.trans hb))
using 1
rw [add_zero, mul_one]
theorem div_opow_log_pos (b : Ordinal) {o : Ordinal} (ho : o ≠ 0) : 0 < o / (b ^ log b o) := by
rcases eq_zero_or_pos b with (rfl | hb)
· simpa using Ordinal.pos_iff_ne_zero.2 ho
· rw [div_pos (opow_ne_zero _ hb.ne')]
exact opow_log_le_self b ho
theorem div_opow_log_lt {b : Ordinal} (o : Ordinal) (hb : 1 < b) : o / (b ^ log b o) < b := by
rw [div_lt (opow_pos _ (zero_lt_one.trans hb)).ne', ← opow_succ]
exact lt_opow_succ_log_self hb o
theorem add_log_le_log_mul {x y : Ordinal} (b : Ordinal) (hx : x ≠ 0) (hy : y ≠ 0) :
log b x + log b y ≤ log b (x * y) := by
by_cases hb : 1 < b
· rw [← opow_le_iff_le_log hb (mul_ne_zero hx hy), opow_add]
exact mul_le_mul' (opow_log_le_self b hx) (opow_log_le_self b hy)
-- Porting note: `le_refl` is required.
simp only [log_of_not_one_lt_left hb, zero_add, le_refl]
/-! ### Interaction with `Nat.cast` -/
@[simp, norm_cast]
theorem natCast_opow (m : ℕ) : ∀ n : ℕ, ↑(m ^ n : ℕ) = (m : Ordinal) ^ (n : Ordinal)
| 0 => by simp
| n + 1 => by
rw [pow_succ, natCast_mul, natCast_opow m n, Nat.cast_succ, add_one_eq_succ, opow_succ]
@[deprecated (since := "2024-04-17")]
alias nat_cast_opow := natCast_opow
theorem sup_opow_nat {o : Ordinal} (ho : 0 < o) : (sup fun n : ℕ => o ^ (n : Ordinal)) = o ^ ω := by
rcases lt_or_eq_of_le (one_le_iff_pos.2 ho) with (ho₁ | rfl)
· exact (opow_isNormal ho₁).apply_omega
· rw [one_opow]
refine le_antisymm (sup_le fun n => by rw [one_opow]) ?_
convert le_sup (fun n : ℕ => 1 ^ (n : Ordinal)) 0
rw [Nat.cast_zero, opow_zero]
end Ordinal
-- Porting note (#11215): TODO: Port this meta code.
-- namespace Tactic
-- open Ordinal Mathlib.Meta.Positivity
-- /-- Extension for the `positivity` tactic: `ordinal.opow` takes positive values on positive
-- inputs. -/
-- @[positivity]
-- unsafe def positivity_opow : expr → tactic strictness
-- | q(@Pow.pow _ _ $(inst) $(a) $(b)) => do
-- let strictness_a ← core a
-- match strictness_a with
-- | positive p => positive <$> mk_app `` opow_pos [b, p]
-- | _ => failed
-- |-- We already know that `0 ≤ x` for all `x : Ordinal`
-- _ =>
-- failed
-- end Tactic
|
SetTheory\Ordinal\FixedPoint.lean | /-
Copyright (c) 2018 Violeta Hernández Palacios, Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Violeta Hernández Palacios, Mario Carneiro
-/
import Mathlib.SetTheory.Ordinal.Arithmetic
import Mathlib.SetTheory.Ordinal.Exponential
/-!
# Fixed points of normal functions
We prove various statements about the fixed points of normal ordinal functions. We state them in
three forms: as statements about type-indexed families of normal functions, as statements about
ordinal-indexed families of normal functions, and as statements about a single normal function. For
the most part, the first case encompasses the others.
Moreover, we prove some lemmas about the fixed points of specific normal functions.
## Main definitions and results
* `nfpFamily`, `nfpBFamily`, `nfp`: the next fixed point of a (family of) normal function(s).
* `fp_family_unbounded`, `fp_bfamily_unbounded`, `fp_unbounded`: the (common) fixed points of a
(family of) normal function(s) are unbounded in the ordinals.
* `deriv_add_eq_mul_omega_add`: a characterization of the derivative of addition.
* `deriv_mul_eq_opow_omega_mul`: a characterization of the derivative of multiplication.
-/
noncomputable section
universe u v
open Function Order
namespace Ordinal
/-! ### Fixed points of type-indexed families of ordinals -/
section
variable {ι : Type u} {f : ι → Ordinal.{max u v} → Ordinal.{max u v}}
/-- The next common fixed point, at least `a`, for a family of normal functions.
This is defined for any family of functions, as the supremum of all values reachable by applying
finitely many functions in the family to `a`.
`Ordinal.nfpFamily_fp` shows this is a fixed point, `Ordinal.le_nfpFamily` shows it's at
least `a`, and `Ordinal.nfpFamily_le_fp` shows this is the least ordinal with these properties. -/
def nfpFamily (f : ι → Ordinal → Ordinal) (a : Ordinal) : Ordinal :=
sup (List.foldr f a)
theorem nfpFamily_eq_sup (f : ι → Ordinal.{max u v} → Ordinal.{max u v}) (a : Ordinal.{max u v}) :
nfpFamily.{u, v} f a = sup.{u, v} (List.foldr f a) :=
rfl
theorem foldr_le_nfpFamily (f : ι → Ordinal → Ordinal)
(a l) : List.foldr f a l ≤ nfpFamily.{u, v} f a :=
le_sup.{u, v} _ _
theorem le_nfpFamily (f : ι → Ordinal → Ordinal) (a) : a ≤ nfpFamily f a :=
le_sup _ []
theorem lt_nfpFamily {a b} : a < nfpFamily.{u, v} f b ↔ ∃ l, a < List.foldr f b l :=
lt_sup.{u, v}
theorem nfpFamily_le_iff {a b} : nfpFamily.{u, v} f a ≤ b ↔ ∀ l, List.foldr f a l ≤ b :=
sup_le_iff
theorem nfpFamily_le {a b} : (∀ l, List.foldr f a l ≤ b) → nfpFamily.{u, v} f a ≤ b :=
sup_le.{u, v}
theorem nfpFamily_monotone (hf : ∀ i, Monotone (f i)) : Monotone (nfpFamily.{u, v} f) :=
fun _ _ h => sup_le.{u, v} fun l => (List.foldr_monotone hf l h).trans (le_sup.{u, v} _ l)
theorem apply_lt_nfpFamily (H : ∀ i, IsNormal (f i)) {a b} (hb : b < nfpFamily.{u, v} f a) (i) :
f i b < nfpFamily.{u, v} f a :=
let ⟨l, hl⟩ := lt_nfpFamily.1 hb
lt_sup.2 ⟨i::l, (H i).strictMono hl⟩
theorem apply_lt_nfpFamily_iff [Nonempty ι] (H : ∀ i, IsNormal (f i)) {a b} :
(∀ i, f i b < nfpFamily.{u, v} f a) ↔ b < nfpFamily.{u, v} f a :=
⟨fun h =>
lt_nfpFamily.2 <|
let ⟨l, hl⟩ := lt_sup.1 <| h <| Classical.arbitrary ι
⟨l, ((H _).self_le b).trans_lt hl⟩,
apply_lt_nfpFamily H⟩
theorem nfpFamily_le_apply [Nonempty ι] (H : ∀ i, IsNormal (f i)) {a b} :
(∃ i, nfpFamily.{u, v} f a ≤ f i b) ↔ nfpFamily.{u, v} f a ≤ b := by
rw [← not_iff_not]
push_neg
exact apply_lt_nfpFamily_iff H
theorem nfpFamily_le_fp (H : ∀ i, Monotone (f i)) {a b} (ab : a ≤ b) (h : ∀ i, f i b ≤ b) :
nfpFamily.{u, v} f a ≤ b :=
sup_le fun l => by
by_cases hι : IsEmpty ι
· rwa [Unique.eq_default l]
· induction' l with i l IH generalizing a
· exact ab
exact (H i (IH ab)).trans (h i)
theorem nfpFamily_fp {i} (H : IsNormal (f i)) (a) :
f i (nfpFamily.{u, v} f a) = nfpFamily.{u, v} f a := by
unfold nfpFamily
rw [@IsNormal.sup.{u, v, v} _ H _ _ ⟨[]⟩]
apply le_antisymm <;> refine Ordinal.sup_le fun l => ?_
· exact le_sup _ (i::l)
· exact (H.self_le _).trans (le_sup _ _)
theorem apply_le_nfpFamily [hι : Nonempty ι] {f : ι → Ordinal → Ordinal} (H : ∀ i, IsNormal (f i))
{a b} : (∀ i, f i b ≤ nfpFamily.{u, v} f a) ↔ b ≤ nfpFamily.{u, v} f a := by
refine ⟨fun h => ?_, fun h i => ?_⟩
· cases' hι with i
exact ((H i).self_le b).trans (h i)
rw [← nfpFamily_fp (H i)]
exact (H i).monotone h
theorem nfpFamily_eq_self {f : ι → Ordinal → Ordinal} {a} (h : ∀ i, f i a = a) :
nfpFamily f a = a :=
le_antisymm (sup_le fun l => by rw [List.foldr_fixed' h l]) <| le_nfpFamily f a
-- Todo: This is actually a special case of the fact the intersection of club sets is a club set.
/-- A generalization of the fixed point lemma for normal functions: any family of normal functions
has an unbounded set of common fixed points. -/
theorem fp_family_unbounded (H : ∀ i, IsNormal (f i)) :
(⋂ i, Function.fixedPoints (f i)).Unbounded (· < ·) := fun a =>
⟨nfpFamily.{u, v} f a, fun s ⟨i, hi⟩ => by
rw [← hi, mem_fixedPoints_iff]
exact nfpFamily_fp.{u, v} (H i) a, (le_nfpFamily f a).not_lt⟩
/-- The derivative of a family of normal functions is the sequence of their common fixed points.
This is defined for all functions such that `Ordinal.derivFamily_zero`,
`Ordinal.derivFamily_succ`, and `Ordinal.derivFamily_limit` are satisfied. -/
def derivFamily (f : ι → Ordinal → Ordinal) (o : Ordinal) : Ordinal :=
limitRecOn o (nfpFamily.{u, v} f 0) (fun _ IH => nfpFamily.{u, v} f (succ IH))
fun a _ => bsup.{max u v, u} a
@[simp]
theorem derivFamily_zero (f : ι → Ordinal → Ordinal) :
derivFamily.{u, v} f 0 = nfpFamily.{u, v} f 0 :=
limitRecOn_zero _ _ _
@[simp]
theorem derivFamily_succ (f : ι → Ordinal → Ordinal) (o) :
derivFamily.{u, v} f (succ o) = nfpFamily.{u, v} f (succ (derivFamily.{u, v} f o)) :=
limitRecOn_succ _ _ _ _
theorem derivFamily_limit (f : ι → Ordinal → Ordinal) {o} :
IsLimit o → derivFamily.{u, v} f o = bsup.{max u v, u} o fun a _ => derivFamily.{u, v} f a :=
limitRecOn_limit _ _ _ _
theorem derivFamily_isNormal (f : ι → Ordinal → Ordinal) : IsNormal (derivFamily f) :=
⟨fun o => by rw [derivFamily_succ, ← succ_le_iff]; apply le_nfpFamily, fun o l a => by
rw [derivFamily_limit _ l, bsup_le_iff]⟩
theorem derivFamily_fp {i} (H : IsNormal (f i)) (o : Ordinal.{max u v}) :
f i (derivFamily.{u, v} f o) = derivFamily.{u, v} f o := by
induction' o using limitRecOn with o _ o l IH
· rw [derivFamily_zero]
exact nfpFamily_fp H 0
· rw [derivFamily_succ]
exact nfpFamily_fp H _
· rw [derivFamily_limit _ l,
IsNormal.bsup.{max u v, u, max u v} H (fun a _ => derivFamily f a) l.1]
refine eq_of_forall_ge_iff fun c => ?_
simp (config := { contextual := true }) only [bsup_le_iff, IH]
theorem le_iff_derivFamily (H : ∀ i, IsNormal (f i)) {a} :
(∀ i, f i a ≤ a) ↔ ∃ o, derivFamily.{u, v} f o = a :=
⟨fun ha => by
suffices ∀ (o) (_ : a ≤ derivFamily.{u, v} f o), ∃ o, derivFamily.{u, v} f o = a from
this a ((derivFamily_isNormal _).self_le _)
intro o
induction' o using limitRecOn with o IH o l IH
· intro h₁
refine ⟨0, le_antisymm ?_ h₁⟩
rw [derivFamily_zero]
exact nfpFamily_le_fp (fun i => (H i).monotone) (Ordinal.zero_le _) ha
· intro h₁
rcases le_or_lt a (derivFamily.{u, v} f o) with h | h
· exact IH h
refine ⟨succ o, le_antisymm ?_ h₁⟩
rw [derivFamily_succ]
exact nfpFamily_le_fp (fun i => (H i).monotone) (succ_le_of_lt h) ha
· intro h₁
cases' eq_or_lt_of_le h₁ with h h
· exact ⟨_, h.symm⟩
rw [derivFamily_limit _ l, ← not_le, bsup_le_iff, not_forall₂] at h
exact
let ⟨o', h, hl⟩ := h
IH o' h (le_of_not_le hl),
fun ⟨o, e⟩ i => e ▸ (derivFamily_fp (H i) _).le⟩
theorem fp_iff_derivFamily (H : ∀ i, IsNormal (f i)) {a} :
(∀ i, f i a = a) ↔ ∃ o, derivFamily.{u, v} f o = a :=
Iff.trans ⟨fun h i => le_of_eq (h i), fun h i => (H i).le_iff_eq.1 (h i)⟩ (le_iff_derivFamily H)
/-- For a family of normal functions, `Ordinal.derivFamily` enumerates the common fixed points. -/
theorem derivFamily_eq_enumOrd (H : ∀ i, IsNormal (f i)) :
derivFamily.{u, v} f = enumOrd (⋂ i, Function.fixedPoints (f i)) := by
rw [← eq_enumOrd _ (fp_family_unbounded.{u, v} H)]
use (derivFamily_isNormal f).strictMono
rw [Set.range_eq_iff]
refine ⟨?_, fun a ha => ?_⟩
· rintro a S ⟨i, hi⟩
rw [← hi]
exact derivFamily_fp (H i) a
rw [Set.mem_iInter] at ha
rwa [← fp_iff_derivFamily H]
end
/-! ### Fixed points of ordinal-indexed families of ordinals -/
section
variable {o : Ordinal.{u}} {f : ∀ b < o, Ordinal.{max u v} → Ordinal.{max u v}}
/-- The next common fixed point, at least `a`, for a family of normal functions indexed by ordinals.
This is defined as `Ordinal.nfpFamily` of the type-indexed family associated to `f`. -/
def nfpBFamily (o : Ordinal) (f : ∀ b < o, Ordinal → Ordinal) : Ordinal → Ordinal :=
nfpFamily (familyOfBFamily o f)
theorem nfpBFamily_eq_nfpFamily {o : Ordinal} (f : ∀ b < o, Ordinal → Ordinal) :
nfpBFamily.{u, v} o f = nfpFamily.{u, v} (familyOfBFamily o f) :=
rfl
theorem foldr_le_nfpBFamily {o : Ordinal}
(f : ∀ b < o, Ordinal → Ordinal) (a l) :
List.foldr (familyOfBFamily o f) a l ≤ nfpBFamily.{u, v} o f a :=
le_sup.{u, v} _ _
theorem le_nfpBFamily {o : Ordinal} (f : ∀ b < o, Ordinal → Ordinal) (a) :
a ≤ nfpBFamily.{u, v} o f a :=
le_sup.{u, v} _ []
theorem lt_nfpBFamily {a b} :
a < nfpBFamily.{u, v} o f b ↔ ∃ l, a < List.foldr (familyOfBFamily o f) b l :=
lt_sup.{u, v}
theorem nfpBFamily_le_iff {o : Ordinal} {f : ∀ b < o, Ordinal → Ordinal} {a b} :
nfpBFamily.{u, v} o f a ≤ b ↔ ∀ l, List.foldr (familyOfBFamily o f) a l ≤ b :=
sup_le_iff.{u, v}
theorem nfpBFamily_le {o : Ordinal} {f : ∀ b < o, Ordinal → Ordinal} {a b} :
(∀ l, List.foldr (familyOfBFamily o f) a l ≤ b) → nfpBFamily.{u, v} o f a ≤ b :=
sup_le.{u, v}
theorem nfpBFamily_monotone (hf : ∀ i hi, Monotone (f i hi)) : Monotone (nfpBFamily.{u, v} o f) :=
nfpFamily_monotone fun _ => hf _ _
theorem apply_lt_nfpBFamily (H : ∀ i hi, IsNormal (f i hi)) {a b} (hb : b < nfpBFamily.{u, v} o f a)
(i hi) : f i hi b < nfpBFamily.{u, v} o f a := by
rw [← familyOfBFamily_enum o f]
apply apply_lt_nfpFamily (fun _ => H _ _) hb
theorem apply_lt_nfpBFamily_iff (ho : o ≠ 0) (H : ∀ i hi, IsNormal (f i hi)) {a b} :
(∀ i hi, f i hi b < nfpBFamily.{u, v} o f a) ↔ b < nfpBFamily.{u, v} o f a :=
⟨fun h => by
haveI := out_nonempty_iff_ne_zero.2 ho
refine (apply_lt_nfpFamily_iff.{u, v} ?_).1 fun _ => h _ _
exact fun _ => H _ _, apply_lt_nfpBFamily H⟩
theorem nfpBFamily_le_apply (ho : o ≠ 0) (H : ∀ i hi, IsNormal (f i hi)) {a b} :
(∃ i hi, nfpBFamily.{u, v} o f a ≤ f i hi b) ↔ nfpBFamily.{u, v} o f a ≤ b := by
rw [← not_iff_not]
push_neg
exact apply_lt_nfpBFamily_iff.{u, v} ho H
theorem nfpBFamily_le_fp (H : ∀ i hi, Monotone (f i hi)) {a b} (ab : a ≤ b)
(h : ∀ i hi, f i hi b ≤ b) : nfpBFamily.{u, v} o f a ≤ b :=
nfpFamily_le_fp (fun _ => H _ _) ab fun _ => h _ _
theorem nfpBFamily_fp {i hi} (H : IsNormal (f i hi)) (a) :
f i hi (nfpBFamily.{u, v} o f a) = nfpBFamily.{u, v} o f a := by
rw [← familyOfBFamily_enum o f]
apply nfpFamily_fp
rw [familyOfBFamily_enum]
exact H
theorem apply_le_nfpBFamily (ho : o ≠ 0) (H : ∀ i hi, IsNormal (f i hi)) {a b} :
(∀ i hi, f i hi b ≤ nfpBFamily.{u, v} o f a) ↔ b ≤ nfpBFamily.{u, v} o f a := by
refine ⟨fun h => ?_, fun h i hi => ?_⟩
· have ho' : 0 < o := Ordinal.pos_iff_ne_zero.2 ho
exact ((H 0 ho').self_le b).trans (h 0 ho')
· rw [← nfpBFamily_fp (H i hi)]
exact (H i hi).monotone h
theorem nfpBFamily_eq_self {a} (h : ∀ i hi, f i hi a = a) : nfpBFamily.{u, v} o f a = a :=
nfpFamily_eq_self fun _ => h _ _
/-- A generalization of the fixed point lemma for normal functions: any family of normal functions
has an unbounded set of common fixed points. -/
theorem fp_bfamily_unbounded (H : ∀ i hi, IsNormal (f i hi)) :
(⋂ (i) (hi), Function.fixedPoints (f i hi)).Unbounded (· < ·) := fun a =>
⟨nfpBFamily.{u, v} _ f a, by
rw [Set.mem_iInter₂]
exact fun i hi => nfpBFamily_fp (H i hi) _, (le_nfpBFamily f a).not_lt⟩
/-- The derivative of a family of normal functions is the sequence of their common fixed points.
This is defined as `Ordinal.derivFamily` of the type-indexed family associated to `f`. -/
def derivBFamily (o : Ordinal) (f : ∀ b < o, Ordinal → Ordinal) : Ordinal → Ordinal :=
derivFamily (familyOfBFamily o f)
theorem derivBFamily_eq_derivFamily {o : Ordinal} (f : ∀ b < o, Ordinal → Ordinal) :
derivBFamily.{u, v} o f = derivFamily.{u, v} (familyOfBFamily o f) :=
rfl
theorem derivBFamily_isNormal {o : Ordinal} (f : ∀ b < o, Ordinal → Ordinal) :
IsNormal (derivBFamily o f) :=
derivFamily_isNormal _
theorem derivBFamily_fp {i hi} (H : IsNormal (f i hi)) (a : Ordinal) :
f i hi (derivBFamily.{u, v} o f a) = derivBFamily.{u, v} o f a := by
rw [← familyOfBFamily_enum o f]
apply derivFamily_fp
rw [familyOfBFamily_enum]
exact H
theorem le_iff_derivBFamily (H : ∀ i hi, IsNormal (f i hi)) {a} :
(∀ i hi, f i hi a ≤ a) ↔ ∃ b, derivBFamily.{u, v} o f b = a := by
unfold derivBFamily
rw [← le_iff_derivFamily]
· refine ⟨fun h i => h _ _, fun h i hi => ?_⟩
rw [← familyOfBFamily_enum o f]
apply h
· exact fun _ => H _ _
theorem fp_iff_derivBFamily (H : ∀ i hi, IsNormal (f i hi)) {a} :
(∀ i hi, f i hi a = a) ↔ ∃ b, derivBFamily.{u, v} o f b = a := by
rw [← le_iff_derivBFamily H]
refine ⟨fun h i hi => le_of_eq (h i hi), fun h i hi => ?_⟩
rw [← (H i hi).le_iff_eq]
exact h i hi
/-- For a family of normal functions, `Ordinal.derivBFamily` enumerates the common fixed points. -/
theorem derivBFamily_eq_enumOrd (H : ∀ i hi, IsNormal (f i hi)) :
derivBFamily.{u, v} o f = enumOrd (⋂ (i) (hi), Function.fixedPoints (f i hi)) := by
rw [← eq_enumOrd _ (fp_bfamily_unbounded.{u, v} H)]
use (derivBFamily_isNormal f).strictMono
rw [Set.range_eq_iff]
refine ⟨fun a => Set.mem_iInter₂.2 fun i hi => derivBFamily_fp (H i hi) a, fun a ha => ?_⟩
rw [Set.mem_iInter₂] at ha
rwa [← fp_iff_derivBFamily H]
end
/-! ### Fixed points of a single function -/
section
variable {f : Ordinal.{u} → Ordinal.{u}}
/-- The next fixed point function, the least fixed point of the normal function `f`, at least `a`.
This is defined as `ordinal.nfpFamily` applied to a family consisting only of `f`. -/
def nfp (f : Ordinal → Ordinal) : Ordinal → Ordinal :=
nfpFamily fun _ : Unit => f
theorem nfp_eq_nfpFamily (f : Ordinal → Ordinal) : nfp f = nfpFamily fun _ : Unit => f :=
rfl
@[simp]
theorem sup_iterate_eq_nfp (f : Ordinal.{u} → Ordinal.{u}) :
(fun a => sup fun n : ℕ => f^[n] a) = nfp f := by
refine funext fun a => le_antisymm ?_ (sup_le fun l => ?_)
· rw [sup_le_iff]
intro n
rw [← List.length_replicate n Unit.unit, ← List.foldr_const f a]
apply le_sup
· rw [List.foldr_const f a l]
exact le_sup _ _
theorem iterate_le_nfp (f a n) : f^[n] a ≤ nfp f a := by
rw [← sup_iterate_eq_nfp]
exact le_sup _ n
theorem le_nfp (f a) : a ≤ nfp f a :=
iterate_le_nfp f a 0
theorem lt_nfp {a b} : a < nfp f b ↔ ∃ n, a < f^[n] b := by
rw [← sup_iterate_eq_nfp]
exact lt_sup
theorem nfp_le_iff {a b} : nfp f a ≤ b ↔ ∀ n, f^[n] a ≤ b := by
rw [← sup_iterate_eq_nfp]
exact sup_le_iff
theorem nfp_le {a b} : (∀ n, f^[n] a ≤ b) → nfp f a ≤ b :=
nfp_le_iff.2
@[simp]
theorem nfp_id : nfp id = id :=
funext fun a => by
simp_rw [← sup_iterate_eq_nfp, iterate_id]
exact sup_const a
theorem nfp_monotone (hf : Monotone f) : Monotone (nfp f) :=
nfpFamily_monotone fun _ => hf
theorem IsNormal.apply_lt_nfp {f} (H : IsNormal f) {a b} : f b < nfp f a ↔ b < nfp f a := by
unfold nfp
rw [← @apply_lt_nfpFamily_iff Unit (fun _ => f) _ (fun _ => H) a b]
exact ⟨fun h _ => h, fun h => h Unit.unit⟩
theorem IsNormal.nfp_le_apply {f} (H : IsNormal f) {a b} : nfp f a ≤ f b ↔ nfp f a ≤ b :=
le_iff_le_iff_lt_iff_lt.2 H.apply_lt_nfp
theorem nfp_le_fp {f} (H : Monotone f) {a b} (ab : a ≤ b) (h : f b ≤ b) : nfp f a ≤ b :=
nfpFamily_le_fp (fun _ => H) ab fun _ => h
theorem IsNormal.nfp_fp {f} (H : IsNormal f) : ∀ a, f (nfp f a) = nfp f a :=
@nfpFamily_fp Unit (fun _ => f) Unit.unit H
theorem IsNormal.apply_le_nfp {f} (H : IsNormal f) {a b} : f b ≤ nfp f a ↔ b ≤ nfp f a :=
⟨le_trans (H.self_le _), fun h => by simpa only [H.nfp_fp] using H.le_iff.2 h⟩
theorem nfp_eq_self {f : Ordinal → Ordinal} {a} (h : f a = a) : nfp f a = a :=
nfpFamily_eq_self fun _ => h
/-- The fixed point lemma for normal functions: any normal function has an unbounded set of
fixed points. -/
theorem fp_unbounded (H : IsNormal f) : (Function.fixedPoints f).Unbounded (· < ·) := by
convert fp_family_unbounded fun _ : Unit => H
exact (Set.iInter_const _).symm
/-- The derivative of a normal function `f` is the sequence of fixed points of `f`.
This is defined as `Ordinal.derivFamily` applied to a trivial family consisting only of `f`. -/
def deriv (f : Ordinal → Ordinal) : Ordinal → Ordinal :=
derivFamily fun _ : Unit => f
theorem deriv_eq_derivFamily (f : Ordinal → Ordinal) : deriv f = derivFamily fun _ : Unit => f :=
rfl
@[simp]
theorem deriv_zero (f) : deriv f 0 = nfp f 0 :=
derivFamily_zero _
@[simp]
theorem deriv_succ (f o) : deriv f (succ o) = nfp f (succ (deriv f o)) :=
derivFamily_succ _ _
theorem deriv_limit (f) {o} : IsLimit o → deriv f o = bsup.{u, 0} o fun a _ => deriv f a :=
derivFamily_limit _
theorem deriv_isNormal (f) : IsNormal (deriv f) :=
derivFamily_isNormal _
theorem deriv_id_of_nfp_id {f : Ordinal → Ordinal} (h : nfp f = id) : deriv f = id :=
((deriv_isNormal _).eq_iff_zero_and_succ IsNormal.refl).2 (by simp [h])
theorem IsNormal.deriv_fp {f} (H : IsNormal f) : ∀ o, f (deriv f o) = deriv f o :=
@derivFamily_fp Unit (fun _ => f) Unit.unit H
theorem IsNormal.le_iff_deriv {f} (H : IsNormal f) {a} : f a ≤ a ↔ ∃ o, deriv f o = a := by
unfold deriv
rw [← le_iff_derivFamily fun _ : Unit => H]
exact ⟨fun h _ => h, fun h => h Unit.unit⟩
theorem IsNormal.fp_iff_deriv {f} (H : IsNormal f) {a} : f a = a ↔ ∃ o, deriv f o = a := by
rw [← H.le_iff_eq, H.le_iff_deriv]
/-- `Ordinal.deriv` enumerates the fixed points of a normal function. -/
theorem deriv_eq_enumOrd (H : IsNormal f) : deriv f = enumOrd (Function.fixedPoints f) := by
convert derivFamily_eq_enumOrd fun _ : Unit => H
exact (Set.iInter_const _).symm
theorem deriv_eq_id_of_nfp_eq_id {f : Ordinal → Ordinal} (h : nfp f = id) : deriv f = id :=
(IsNormal.eq_iff_zero_and_succ (deriv_isNormal _) IsNormal.refl).2 <| by simp [h]
end
/-! ### Fixed points of addition -/
@[simp]
theorem nfp_add_zero (a) : nfp (a + ·) 0 = a * omega := by
simp_rw [← sup_iterate_eq_nfp, ← sup_mul_nat]
congr; funext n
induction' n with n hn
· rw [Nat.cast_zero, mul_zero, iterate_zero_apply]
· rw [iterate_succ_apply', Nat.add_comm, Nat.cast_add, Nat.cast_one, mul_one_add, hn]
theorem nfp_add_eq_mul_omega {a b} (hba : b ≤ a * omega) : nfp (a + ·) b = a * omega := by
apply le_antisymm (nfp_le_fp (add_isNormal a).monotone hba _)
· rw [← nfp_add_zero]
exact nfp_monotone (add_isNormal a).monotone (Ordinal.zero_le b)
· dsimp; rw [← mul_one_add, one_add_omega]
theorem add_eq_right_iff_mul_omega_le {a b : Ordinal} : a + b = b ↔ a * omega ≤ b := by
refine ⟨fun h => ?_, fun h => ?_⟩
· rw [← nfp_add_zero a, ← deriv_zero]
cases' (add_isNormal a).fp_iff_deriv.1 h with c hc
rw [← hc]
exact (deriv_isNormal _).monotone (Ordinal.zero_le _)
· have := Ordinal.add_sub_cancel_of_le h
nth_rw 1 [← this]
rwa [← add_assoc, ← mul_one_add, one_add_omega]
theorem add_le_right_iff_mul_omega_le {a b : Ordinal} : a + b ≤ b ↔ a * omega ≤ b := by
rw [← add_eq_right_iff_mul_omega_le]
exact (add_isNormal a).le_iff_eq
theorem deriv_add_eq_mul_omega_add (a b : Ordinal.{u}) : deriv (a + ·) b = a * omega + b := by
revert b
rw [← funext_iff, IsNormal.eq_iff_zero_and_succ (deriv_isNormal _) (add_isNormal _)]
refine ⟨?_, fun a h => ?_⟩
· rw [deriv_zero, add_zero]
exact nfp_add_zero a
· rw [deriv_succ, h, add_succ]
exact nfp_eq_self (add_eq_right_iff_mul_omega_le.2 ((le_add_right _ _).trans (le_succ _)))
/-! ### Fixed points of multiplication -/
-- Porting note: commented out, doesn't seem necessary
-- local infixr:0 "^" => @Pow.pow Ordinal Ordinal Ordinal.hasPow
@[simp]
theorem nfp_mul_one {a : Ordinal} (ha : 0 < a) : nfp (a * ·) 1 = (a^omega) := by
rw [← sup_iterate_eq_nfp, ← sup_opow_nat]
· dsimp
congr
funext n
induction' n with n hn
· rw [Nat.cast_zero, opow_zero, iterate_zero_apply]
rw [iterate_succ_apply', Nat.add_comm, Nat.cast_add, Nat.cast_one, opow_add, opow_one, hn]
· exact ha
@[simp]
theorem nfp_mul_zero (a : Ordinal) : nfp (a * ·) 0 = 0 := by
rw [← Ordinal.le_zero, nfp_le_iff]
intro n
induction' n with n hn; · rfl
dsimp only; rwa [iterate_succ_apply, mul_zero]
@[simp]
theorem nfp_zero_mul : nfp (HMul.hMul 0) = id := by
rw [← sup_iterate_eq_nfp]
refine funext fun a => (sup_le fun n => ?_).antisymm (le_sup (fun n => (0 * ·)^[n] a) 0)
induction' n with n _
· rfl
rw [Function.iterate_succ']
change 0 * _ ≤ a
rw [zero_mul]
exact Ordinal.zero_le a
@[simp]
theorem deriv_mul_zero : deriv (HMul.hMul 0) = id :=
deriv_eq_id_of_nfp_eq_id nfp_zero_mul
theorem nfp_mul_eq_opow_omega {a b : Ordinal} (hb : 0 < b) (hba : b ≤ (a^omega)) :
nfp (a * ·) b = (a^omega.{u}) := by
rcases eq_zero_or_pos a with ha | ha
· rw [ha, zero_opow omega_ne_zero] at hba ⊢
rw [Ordinal.le_zero.1 hba, nfp_zero_mul]
rfl
apply le_antisymm
· apply nfp_le_fp (mul_isNormal ha).monotone hba
rw [← opow_one_add, one_add_omega]
rw [← nfp_mul_one ha]
exact nfp_monotone (mul_isNormal ha).monotone (one_le_iff_pos.2 hb)
theorem eq_zero_or_opow_omega_le_of_mul_eq_right {a b : Ordinal} (hab : a * b = b) :
b = 0 ∨ (a^omega.{u}) ≤ b := by
rcases eq_zero_or_pos a with ha | ha
· rw [ha, zero_opow omega_ne_zero]
exact Or.inr (Ordinal.zero_le b)
rw [or_iff_not_imp_left]
intro hb
rw [← nfp_mul_one ha]
rw [← Ne, ← one_le_iff_ne_zero] at hb
exact nfp_le_fp (mul_isNormal ha).monotone hb (le_of_eq hab)
theorem mul_eq_right_iff_opow_omega_dvd {a b : Ordinal} : a * b = b ↔ (a^omega) ∣ b := by
rcases eq_zero_or_pos a with ha | ha
· rw [ha, zero_mul, zero_opow omega_ne_zero, zero_dvd_iff]
exact eq_comm
refine ⟨fun hab => ?_, fun h => ?_⟩
· rw [dvd_iff_mod_eq_zero]
rw [← div_add_mod b (a^omega), mul_add, ← mul_assoc, ← opow_one_add, one_add_omega,
add_left_cancel] at hab
cases' eq_zero_or_opow_omega_le_of_mul_eq_right hab with hab hab
· exact hab
refine (not_lt_of_le hab (mod_lt b (opow_ne_zero omega ?_))).elim
rwa [← Ordinal.pos_iff_ne_zero]
cases' h with c hc
rw [hc, ← mul_assoc, ← opow_one_add, one_add_omega]
theorem mul_le_right_iff_opow_omega_dvd {a b : Ordinal} (ha : 0 < a) :
a * b ≤ b ↔ (a^omega) ∣ b := by
rw [← mul_eq_right_iff_opow_omega_dvd]
exact (mul_isNormal ha).le_iff_eq
theorem nfp_mul_opow_omega_add {a c : Ordinal} (b) (ha : 0 < a) (hc : 0 < c) (hca : c ≤ (a^omega)) :
nfp (a * ·) ((a^omega) * b + c) = (a^omega.{u}) * succ b := by
apply le_antisymm
· apply nfp_le_fp (mul_isNormal ha).monotone
· rw [mul_succ]
apply add_le_add_left hca
· dsimp only; rw [← mul_assoc, ← opow_one_add, one_add_omega]
· cases' mul_eq_right_iff_opow_omega_dvd.1 ((mul_isNormal ha).nfp_fp ((a^omega) * b + c)) with
d hd
rw [hd]
apply mul_le_mul_left'
have := le_nfp (Mul.mul a) ((a^omega) * b + c)
erw [hd] at this
have := (add_lt_add_left hc ((a^omega) * b)).trans_le this
rw [add_zero, mul_lt_mul_iff_left (opow_pos omega ha)] at this
rwa [succ_le_iff]
theorem deriv_mul_eq_opow_omega_mul {a : Ordinal.{u}} (ha : 0 < a) (b) :
deriv (a * ·) b = (a^omega) * b := by
revert b
rw [← funext_iff,
IsNormal.eq_iff_zero_and_succ (deriv_isNormal _) (mul_isNormal (opow_pos omega ha))]
refine ⟨?_, fun c h => ?_⟩
· dsimp only; rw [deriv_zero, nfp_mul_zero, mul_zero]
· rw [deriv_succ, h]
exact nfp_mul_opow_omega_add c ha zero_lt_one (one_le_iff_pos.2 (opow_pos _ ha))
end Ordinal
|
SetTheory\Ordinal\FixedPointApproximants.lean | /-
Copyright (c) 2024 Ira Fesefeldt. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ira Fesefeldt
-/
import Mathlib.SetTheory.Ordinal.Arithmetic
/-!
# Ordinal Approximants for the Fixed points on complete lattices
This file sets up the ordinal approximation theory of fixed points
of a monotone function in a complete lattice [Cousot1979].
The proof follows loosely the one from [Echenique2005].
However, the proof given here is not constructive as we use the non-constructive axiomatization of
ordinals from mathlib. It still allows an approximation scheme indexed over the ordinals.
## Main definitions
* `OrdinalApprox.lfpApprox`: The ordinal approximation of the least fixed point
greater or equal then an initial value of a bundled monotone function.
* `OrdinalApprox.gfpApprox`: The ordinal approximation of the greatest fixed point
less or equal then an initial value of a bundled monotone function.
## Main theorems
* `OrdinalApprox.lfp_mem_range_lfpApprox`: The approximation of
the least fixed point eventually reaches the least fixed point
* `OrdinalApprox.gfp_mem_range_gfpApprox`: The approximation of
the greatest fixed point eventually reaches the greatest fixed point
## References
* [F. Echenique, *A short and constructive proof of Tarski’s fixed-point theorem*][Echenique2005]
* [P. Cousot & R. Cousot, *Constructive Versions of Tarski's Fixed Point Theorems*][Cousot1979]
## Tags
fixed point, complete lattice, monotone function, ordinals, approximation
-/
namespace Cardinal
universe u
variable {α : Type u}
variable (g : Ordinal → α)
open Cardinal Ordinal SuccOrder Function Set
theorem not_injective_limitation_set : ¬ InjOn g (Iio (ord <| succ #α)) := by
intro h_inj
have h := lift_mk_le_lift_mk_of_injective <| injOn_iff_injective.1 h_inj
have mk_initialSeg_subtype :
#(Iio (ord <| succ #α)) = lift.{u + 1} (succ #α) := by
simpa only [coe_setOf, card_typein, card_ord] using mk_initialSeg (ord <| succ #α)
rw [mk_initialSeg_subtype, lift_lift, lift_le] at h
exact not_le_of_lt (Order.lt_succ #α) h
end Cardinal
namespace OrdinalApprox
universe u
variable {α : Type u}
variable [CompleteLattice α] (f : α →o α) (x : α)
open Function fixedPoints Cardinal Order OrderHom
set_option linter.unusedVariables false in
/-- Ordinal approximants of the least fixed point greater then an initial value x -/
def lfpApprox (a : Ordinal.{u}) : α :=
sSup ({ f (lfpApprox b) | (b : Ordinal) (h : b < a) } ∪ {x})
termination_by a
decreasing_by exact h
theorem lfpApprox_monotone : Monotone (lfpApprox f x) := by
unfold Monotone; intros a b h; unfold lfpApprox
refine sSup_le_sSup ?h
apply sup_le_sup_right
simp only [exists_prop, Set.le_eq_subset, Set.setOf_subset_setOf, forall_exists_index, and_imp,
forall_apply_eq_imp_iff₂]
intros a' h'
use a'
exact ⟨lt_of_lt_of_le h' h, rfl⟩
theorem le_lfpApprox {a : Ordinal} : x ≤ lfpApprox f x a := by
unfold lfpApprox
apply le_sSup
simp only [exists_prop, Set.union_singleton, Set.mem_insert_iff, Set.mem_setOf_eq, true_or]
theorem lfpApprox_add_one (h : x ≤ f x) (a : Ordinal) :
lfpApprox f x (a+1) = f (lfpApprox f x a) := by
apply le_antisymm
· conv => left; unfold lfpApprox
apply sSup_le
simp only [Ordinal.add_one_eq_succ, lt_succ_iff, exists_prop, Set.union_singleton,
Set.mem_insert_iff, Set.mem_setOf_eq, forall_eq_or_imp, forall_exists_index, and_imp,
forall_apply_eq_imp_iff₂]
apply And.intro
· apply le_trans h
apply Monotone.imp f.monotone
exact le_lfpApprox f x
· intros a' h
apply f.2; apply lfpApprox_monotone; exact h
· conv => right; unfold lfpApprox
apply le_sSup
simp only [Ordinal.add_one_eq_succ, lt_succ_iff, exists_prop]
rw [Set.mem_union]
apply Or.inl
simp only [Set.mem_setOf_eq]
use a
/-- The ordinal approximants of the least fixed point are stabilizing
when reaching a fixed point of f -/
theorem lfpApprox_eq_of_mem_fixedPoints {a b : Ordinal} (h_init : x ≤ f x) (h_ab : a ≤ b)
(h : lfpApprox f x a ∈ fixedPoints f) : lfpApprox f x b = lfpApprox f x a := by
rw [mem_fixedPoints_iff] at h
induction b using Ordinal.induction with | h b IH =>
apply le_antisymm
· conv => left; unfold lfpApprox
apply sSup_le
simp only [exists_prop, Set.union_singleton, Set.mem_insert_iff, Set.mem_setOf_eq,
forall_eq_or_imp, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂]
apply And.intro (le_lfpApprox f x)
intro a' ha'b
by_cases haa : a' < a
· rw [← lfpApprox_add_one f x h_init]
apply lfpApprox_monotone
simp only [Ordinal.add_one_eq_succ, succ_le_iff]
exact haa
· rw [IH a' ha'b (le_of_not_lt haa), h]
· exact lfpApprox_monotone f x h_ab
/-- There are distinct ordinals smaller than the successor of the domains cardinals
with equal value -/
theorem exists_lfpApprox_eq_lfpApprox : ∃ a < ord <| succ #α, ∃ b < ord <| succ #α,
a ≠ b ∧ lfpApprox f x a = lfpApprox f x b := by
have h_ninj := not_injective_limitation_set <| lfpApprox f x
rw [Set.injOn_iff_injective, Function.not_injective_iff] at h_ninj
let ⟨a, b, h_fab, h_nab⟩ := h_ninj
use a.val; apply And.intro a.prop
use b.val; apply And.intro b.prop
apply And.intro
· intro h_eq; rw [Subtype.coe_inj] at h_eq; exact h_nab h_eq
· exact h_fab
/-- If there are distinct ordinals with equal value then
every value succeding the smaller ordinal are fixed points -/
lemma lfpApprox_mem_fixedPoints_of_eq {a b c : Ordinal}
(h_init : x ≤ f x) (h_ab : a < b) (h_ac : a ≤ c) (h_fab : lfpApprox f x a = lfpApprox f x b) :
lfpApprox f x c ∈ fixedPoints f := by
have lfpApprox_mem_fixedPoint :
lfpApprox f x a ∈ fixedPoints f := by
rw [mem_fixedPoints_iff, ← lfpApprox_add_one f x h_init]
exact Monotone.eq_of_le_of_le (lfpApprox_monotone f x)
h_fab (SuccOrder.le_succ a) (SuccOrder.succ_le_of_lt h_ab)
rw [lfpApprox_eq_of_mem_fixedPoints f x h_init]
· exact lfpApprox_mem_fixedPoint
· exact h_ac
· exact lfpApprox_mem_fixedPoint
/-- A fixed point of f is reached after the successor of the domains cardinality -/
theorem lfpApprox_ord_mem_fixedPoint (h_init : x ≤ f x) :
lfpApprox f x (ord <| succ #α) ∈ fixedPoints f := by
let ⟨a, h_a, b, h_b, h_nab, h_fab⟩ := exists_lfpApprox_eq_lfpApprox f x
cases le_total a b with
| inl h_ab =>
exact lfpApprox_mem_fixedPoints_of_eq f x h_init
(h_nab.lt_of_le h_ab) (le_of_lt h_a) h_fab
| inr h_ba =>
exact lfpApprox_mem_fixedPoints_of_eq f x h_init
(h_nab.symm.lt_of_le h_ba) (le_of_lt h_b) (h_fab.symm)
/-- Every value of the ordinal approximants are less or equal than every fixed point of f greater
then the initial value -/
theorem lfpApprox_le_of_mem_fixedPoints {a : α}
(h_a : a ∈ fixedPoints f) (h_le_init : x ≤ a) (i : Ordinal) : lfpApprox f x i ≤ a := by
induction i using Ordinal.induction with
| h i IH =>
unfold lfpApprox
apply sSup_le
simp only [exists_prop]
intro y h_y
simp only [Set.mem_union, Set.mem_setOf_eq, Set.mem_singleton_iff] at h_y
cases h_y with
| inl h_y =>
let ⟨j, h_j_lt, h_j⟩ := h_y
rw [← h_j, ← h_a]
apply f.monotone'
exact IH j h_j_lt
| inr h_y =>
rw [h_y]
exact h_le_init
/-- The least fixed point of f is reached after the successor of the domains cardinality -/
theorem lfpApprox_ord_eq_lfp : lfpApprox f ⊥ (ord <| succ #α) = lfp f := by
apply le_antisymm
· have h_lfp : ∃ y : fixedPoints f, lfp f = y := by use ⊥; exact rfl
let ⟨y, h_y⟩ := h_lfp; rw [h_y]
exact lfpApprox_le_of_mem_fixedPoints f ⊥ y.2 bot_le (ord <| succ #α)
· have h_fix : ∃ y : fixedPoints f, lfpApprox f ⊥ (ord <| succ #α) = y := by
simpa only [Subtype.exists, mem_fixedPoints, exists_prop, exists_eq_right'] using
lfpApprox_ord_mem_fixedPoint f ⊥ bot_le
let ⟨x, h_x⟩ := h_fix; rw [h_x]
exact lfp_le_fixed f x.prop
/-- Some ordinal approximation of the least fixed point is the least fixed point. -/
theorem lfp_mem_range_lfpApprox : lfp f ∈ Set.range (lfpApprox f ⊥) := by
use ord <| succ #α
exact lfpApprox_ord_eq_lfp f
set_option linter.unusedVariables false in
/-- Ordinal approximants of the greatest fixed point -/
def gfpApprox (a : Ordinal.{u}) : α :=
sInf ({ f (gfpApprox b) | (b : Ordinal) (h : b < a) } ∪ {x})
termination_by a
decreasing_by exact h
-- By unsealing these recursive definitions we can relate them
-- by definitional equality
unseal gfpApprox lfpApprox
theorem gfpApprox_antitone : Antitone (gfpApprox f x) :=
lfpApprox_monotone (OrderHom.dual f) x
theorem gfpApprox_le {a : Ordinal} : gfpApprox f x a ≤ x :=
le_lfpApprox (OrderHom.dual f) x
theorem gfpApprox_add_one (h : f x ≤ x) (a : Ordinal) :
gfpApprox f x (a+1) = f (gfpApprox f x a) :=
lfpApprox_add_one (OrderHom.dual f) x h a
/-- The ordinal approximants of the least fixed point are stabilizing
when reaching a fixed point of f -/
theorem gfpApprox_eq_of_mem_fixedPoints {a b : Ordinal} (h_init : f x ≤ x) (h_ab : a ≤ b)
(h : gfpApprox f x a ∈ fixedPoints f) : gfpApprox f x b = gfpApprox f x a :=
lfpApprox_eq_of_mem_fixedPoints (OrderHom.dual f) x h_init h_ab h
/-- There are distinct ordinals smaller than the successor of the domains cardinals with
equal value -/
theorem exists_gfpApprox_eq_gfpApprox : ∃ a < ord <| succ #α, ∃ b < ord <| succ #α,
a ≠ b ∧ gfpApprox f x a = gfpApprox f x b :=
exists_lfpApprox_eq_lfpApprox (OrderHom.dual f) x
/-- A fixed point of f is reached after the successor of the domains cardinality -/
lemma gfpApprox_ord_mem_fixedPoint (h_init : f x ≤ x) :
gfpApprox f x (ord <| succ #α) ∈ fixedPoints f :=
lfpApprox_ord_mem_fixedPoint (OrderHom.dual f) x h_init
/-- Every value of the ordinal approximants are greater or equal than every fixed point of f
that is smaller then the initial value -/
lemma le_gfpApprox_of_mem_fixedPoints {a : α}
(h_a : a ∈ fixedPoints f) (h_le_init : a ≤ x) (i : Ordinal) : a ≤ gfpApprox f x i :=
lfpApprox_le_of_mem_fixedPoints (OrderHom.dual f) x h_a h_le_init i
/-- The greatest fixed point of f is reached after the successor of the domains cardinality -/
theorem gfpApprox_ord_eq_gfp : gfpApprox f ⊤ (ord <| succ #α) = gfp f :=
lfpApprox_ord_eq_lfp (OrderHom.dual f)
/-- Some ordinal approximation of the greatest fixed point is the greatest fixed point. -/
theorem gfp_mem_range_gfpApprox : gfp f ∈ Set.range (gfpApprox f ⊤) :=
lfp_mem_range_lfpApprox (OrderHom.dual f)
end OrdinalApprox
|
SetTheory\Ordinal\NaturalOps.lean | /-
Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Violeta Hernández Palacios
-/
import Mathlib.SetTheory.Ordinal.Arithmetic
import Mathlib.Tactic.Abel
/-!
# Natural operations on ordinals
The goal of this file is to define natural addition and multiplication on ordinals, also known as
the Hessenberg sum and product, and provide a basic API. The natural addition of two ordinals
`a ♯ b` is recursively defined as the least ordinal greater than `a' ♯ b` and `a ♯ b'` for `a' < a`
and `b' < b`. The natural multiplication `a ⨳ b` is likewise recursively defined as the least
ordinal such that `a ⨳ b ♯ a' ⨳ b'` is greater than `a' ⨳ b ♯ a ⨳ b'` for any `a' < a` and
`b' < b`.
These operations form a rich algebraic structure: they're commutative, associative, preserve order,
have the usual `0` and `1` from ordinals, and distribute over one another.
Moreover, these operations are the addition and multiplication of ordinals when viewed as
combinatorial `Game`s. This makes them particularly useful for game theory.
Finally, both operations admit simple, intuitive descriptions in terms of the Cantor normal form.
The natural addition of two ordinals corresponds to adding their Cantor normal forms as if they were
polynomials in `ω`. Likewise, their natural multiplication corresponds to multiplying the Cantor
normal forms as polynomials.
# Implementation notes
Given the rich algebraic structure of these two operations, we choose to create a type synonym
`NatOrdinal`, where we provide the appropriate instances. However, to avoid casting back and forth
between both types, we attempt to prove and state most results on `Ordinal`.
# Todo
- Prove the characterizations of natural addition and multiplication in terms of the Cantor normal
form.
-/
universe u v
open Function Order
noncomputable section
/-! ### Basic casts between `Ordinal` and `NatOrdinal` -/
/-- A type synonym for ordinals with natural addition and multiplication. -/
def NatOrdinal : Type _ :=
-- Porting note: used to derive LinearOrder & SuccOrder but need to manually define
Ordinal deriving Zero, Inhabited, One, WellFoundedRelation
instance NatOrdinal.linearOrder : LinearOrder NatOrdinal := {Ordinal.linearOrder with}
instance NatOrdinal.succOrder : SuccOrder NatOrdinal := {Ordinal.succOrder with}
/-- The identity function between `Ordinal` and `NatOrdinal`. -/
@[match_pattern]
def Ordinal.toNatOrdinal : Ordinal ≃o NatOrdinal :=
OrderIso.refl _
/-- The identity function between `NatOrdinal` and `Ordinal`. -/
@[match_pattern]
def NatOrdinal.toOrdinal : NatOrdinal ≃o Ordinal :=
OrderIso.refl _
namespace NatOrdinal
open Ordinal
@[simp]
theorem toOrdinal_symm_eq : NatOrdinal.toOrdinal.symm = Ordinal.toNatOrdinal :=
rfl
-- Porting note: used to use dot notation, but doesn't work in Lean 4 with `OrderIso`
@[simp]
theorem toOrdinal_toNatOrdinal (a : NatOrdinal) :
Ordinal.toNatOrdinal (NatOrdinal.toOrdinal a) = a := rfl
theorem lt_wf : @WellFounded NatOrdinal (· < ·) :=
Ordinal.lt_wf
instance : WellFoundedLT NatOrdinal :=
Ordinal.wellFoundedLT
instance : IsWellOrder NatOrdinal (· < ·) :=
Ordinal.isWellOrder
@[simp]
theorem toOrdinal_zero : toOrdinal 0 = 0 :=
rfl
@[simp]
theorem toOrdinal_one : toOrdinal 1 = 1 :=
rfl
@[simp]
theorem toOrdinal_eq_zero (a) : toOrdinal a = 0 ↔ a = 0 :=
Iff.rfl
@[simp]
theorem toOrdinal_eq_one (a) : toOrdinal a = 1 ↔ a = 1 :=
Iff.rfl
@[simp]
theorem toOrdinal_max {a b : NatOrdinal} : toOrdinal (max a b) = max (toOrdinal a) (toOrdinal b) :=
rfl
@[simp]
theorem toOrdinal_min {a b : NatOrdinal} : toOrdinal (min a b) = min (toOrdinal a) (toOrdinal b) :=
rfl
theorem succ_def (a : NatOrdinal) : succ a = toNatOrdinal (toOrdinal a + 1) :=
rfl
/-- A recursor for `NatOrdinal`. Use as `induction x`. -/
@[elab_as_elim, cases_eliminator, induction_eliminator]
protected def rec {β : NatOrdinal → Sort*} (h : ∀ a, β (toNatOrdinal a)) : ∀ a, β a := fun a =>
h (toOrdinal a)
/-- `Ordinal.induction` but for `NatOrdinal`. -/
theorem induction {p : NatOrdinal → Prop} : ∀ (i) (_ : ∀ j, (∀ k, k < j → p k) → p j), p i :=
Ordinal.induction
end NatOrdinal
namespace Ordinal
variable {a b c : Ordinal.{u}}
@[simp]
theorem toNatOrdinal_symm_eq : toNatOrdinal.symm = NatOrdinal.toOrdinal :=
rfl
@[simp]
theorem toNatOrdinal_toOrdinal (a : Ordinal) : NatOrdinal.toOrdinal (toNatOrdinal a) = a :=
rfl
@[simp]
theorem toNatOrdinal_zero : toNatOrdinal 0 = 0 :=
rfl
@[simp]
theorem toNatOrdinal_one : toNatOrdinal 1 = 1 :=
rfl
@[simp]
theorem toNatOrdinal_eq_zero (a) : toNatOrdinal a = 0 ↔ a = 0 :=
Iff.rfl
@[simp]
theorem toNatOrdinal_eq_one (a) : toNatOrdinal a = 1 ↔ a = 1 :=
Iff.rfl
@[simp]
theorem toNatOrdinal_max (a b : Ordinal) :
toNatOrdinal (max a b) = max (toNatOrdinal a) (toNatOrdinal b) :=
rfl
@[simp]
theorem toNatOrdinal_min (a b : Ordinal) :
toNatOrdinal (linearOrder.min a b) = linearOrder.min (toNatOrdinal a) (toNatOrdinal b) :=
rfl
/-! We place the definitions of `nadd` and `nmul` before actually developing their API, as this
guarantees we only need to open the `NaturalOps` locale once. -/
/-- Natural addition on ordinals `a ♯ b`, also known as the Hessenberg sum, is recursively defined
as the least ordinal greater than `a' ♯ b` and `a ♯ b'` for all `a' < a` and `b' < b`. In contrast
to normal ordinal addition, it is commutative.
Natural addition can equivalently be characterized as the ordinal resulting from adding up
corresponding coefficients in the Cantor normal forms of `a` and `b`. -/
noncomputable def nadd : Ordinal → Ordinal → Ordinal
| a, b =>
max (blsub.{u, u} a fun a' _ => nadd a' b) (blsub.{u, u} b fun b' _ => nadd a b')
termination_by o₁ o₂ => (o₁, o₂)
@[inherit_doc]
scoped[NaturalOps] infixl:65 " ♯ " => Ordinal.nadd
open NaturalOps
/-- Natural multiplication on ordinals `a ⨳ b`, also known as the Hessenberg product, is recursively
defined as the least ordinal such that `a ⨳ b + a' ⨳ b'` is greater than `a' ⨳ b + a ⨳ b'` for all
`a' < a` and `b < b'`. In contrast to normal ordinal multiplication, it is commutative and
distributive (over natural addition).
Natural multiplication can equivalently be characterized as the ordinal resulting from multiplying
the Cantor normal forms of `a` and `b` as if they were polynomials in `ω`. Addition of exponents is
done via natural addition. -/
noncomputable def nmul : Ordinal.{u} → Ordinal.{u} → Ordinal.{u}
| a, b => sInf {c | ∀ a' < a, ∀ b' < b, nmul a' b ♯ nmul a b' < c ♯ nmul a' b'}
termination_by a b => (a, b)
@[inherit_doc]
scoped[NaturalOps] infixl:70 " ⨳ " => Ordinal.nmul
/-! ### Natural addition -/
theorem nadd_def (a b : Ordinal) :
a ♯ b = max (blsub.{u, u} a fun a' _ => a' ♯ b) (blsub.{u, u} b fun b' _ => a ♯ b') := by
rw [nadd]
theorem lt_nadd_iff : a < b ♯ c ↔ (∃ b' < b, a ≤ b' ♯ c) ∨ ∃ c' < c, a ≤ b ♯ c' := by
rw [nadd_def]
simp [lt_blsub_iff]
theorem nadd_le_iff : b ♯ c ≤ a ↔ (∀ b' < b, b' ♯ c < a) ∧ ∀ c' < c, b ♯ c' < a := by
rw [nadd_def]
simp [blsub_le_iff]
theorem nadd_lt_nadd_left (h : b < c) (a) : a ♯ b < a ♯ c :=
lt_nadd_iff.2 (Or.inr ⟨b, h, le_rfl⟩)
theorem nadd_lt_nadd_right (h : b < c) (a) : b ♯ a < c ♯ a :=
lt_nadd_iff.2 (Or.inl ⟨b, h, le_rfl⟩)
theorem nadd_le_nadd_left (h : b ≤ c) (a) : a ♯ b ≤ a ♯ c := by
rcases lt_or_eq_of_le h with (h | rfl)
· exact (nadd_lt_nadd_left h a).le
· exact le_rfl
theorem nadd_le_nadd_right (h : b ≤ c) (a) : b ♯ a ≤ c ♯ a := by
rcases lt_or_eq_of_le h with (h | rfl)
· exact (nadd_lt_nadd_right h a).le
· exact le_rfl
variable (a b)
theorem nadd_comm : ∀ a b, a ♯ b = b ♯ a
| a, b => by
rw [nadd_def, nadd_def, max_comm]
congr <;> ext <;> apply nadd_comm
termination_by a b => (a,b)
theorem blsub_nadd_of_mono {f : ∀ c < a ♯ b, Ordinal.{max u v}}
(hf : ∀ {i j} (hi hj), i ≤ j → f i hi ≤ f j hj) :
-- Porting note: needed to add universe hint blsub.{u,v} in the line below
blsub.{u,v} _ f =
max (blsub.{u, v} a fun a' ha' => f (a' ♯ b) <| nadd_lt_nadd_right ha' b)
(blsub.{u, v} b fun b' hb' => f (a ♯ b') <| nadd_lt_nadd_left hb' a) := by
apply (blsub_le_iff.2 fun i h => _).antisymm (max_le _ _)
· intro i h
rcases lt_nadd_iff.1 h with (⟨a', ha', hi⟩ | ⟨b', hb', hi⟩)
· exact lt_max_of_lt_left ((hf h (nadd_lt_nadd_right ha' b) hi).trans_lt (lt_blsub _ _ ha'))
· exact lt_max_of_lt_right ((hf h (nadd_lt_nadd_left hb' a) hi).trans_lt (lt_blsub _ _ hb'))
all_goals
apply blsub_le_of_brange_subset.{u, u, v}
rintro c ⟨d, hd, rfl⟩
apply mem_brange_self
theorem nadd_assoc (a b c) : a ♯ b ♯ c = a ♯ (b ♯ c) := by
rw [nadd_def a (b ♯ c), nadd_def, blsub_nadd_of_mono, blsub_nadd_of_mono, max_assoc]
· congr <;> ext <;> apply nadd_assoc
· exact fun _ _ h => nadd_le_nadd_left h a
· exact fun _ _ h => nadd_le_nadd_right h c
termination_by (a, b, c)
@[simp]
theorem nadd_zero : a ♯ 0 = a := by
induction' a using Ordinal.induction with a IH
rw [nadd_def, blsub_zero, max_zero_right]
convert blsub_id a
rename_i hb
exact IH _ hb
@[simp]
theorem zero_nadd : 0 ♯ a = a := by rw [nadd_comm, nadd_zero]
@[simp]
theorem nadd_one : a ♯ 1 = succ a := by
induction' a using Ordinal.induction with a IH
rw [nadd_def, blsub_one, nadd_zero, max_eq_right_iff, blsub_le_iff]
intro i hi
rwa [IH i hi, succ_lt_succ_iff]
@[simp]
theorem one_nadd : 1 ♯ a = succ a := by rw [nadd_comm, nadd_one]
theorem nadd_succ : a ♯ succ b = succ (a ♯ b) := by rw [← nadd_one (a ♯ b), nadd_assoc, nadd_one]
theorem succ_nadd : succ a ♯ b = succ (a ♯ b) := by rw [← one_nadd (a ♯ b), ← nadd_assoc, one_nadd]
@[simp]
theorem nadd_nat (n : ℕ) : a ♯ n = a + n := by
induction' n with n hn
· simp
· rw [Nat.cast_succ, add_one_eq_succ, nadd_succ, add_succ, hn]
@[simp]
theorem nat_nadd (n : ℕ) : ↑n ♯ a = a + n := by rw [nadd_comm, nadd_nat]
theorem add_le_nadd : a + b ≤ a ♯ b := by
induction b using limitRecOn with
| H₁ => simp
| H₂ c h =>
rwa [add_succ, nadd_succ, succ_le_succ_iff]
| H₃ c hc H =>
simp_rw [← IsNormal.blsub_eq.{u, u} (add_isNormal a) hc, blsub_le_iff]
exact fun i hi => (H i hi).trans_lt (nadd_lt_nadd_left hi a)
end Ordinal
namespace NatOrdinal
open Ordinal NaturalOps
instance : Add NatOrdinal :=
⟨nadd⟩
instance add_covariantClass_lt : CovariantClass NatOrdinal.{u} NatOrdinal.{u} (· + ·) (· < ·) :=
⟨fun a _ _ h => nadd_lt_nadd_left h a⟩
instance add_covariantClass_le : CovariantClass NatOrdinal.{u} NatOrdinal.{u} (· + ·) (· ≤ ·) :=
⟨fun a _ _ h => nadd_le_nadd_left h a⟩
instance add_contravariantClass_le :
ContravariantClass NatOrdinal.{u} NatOrdinal.{u} (· + ·) (· ≤ ·) :=
⟨fun a b c h => by
by_contra! h'
exact h.not_lt (add_lt_add_left h' a)⟩
instance orderedCancelAddCommMonoid : OrderedCancelAddCommMonoid NatOrdinal :=
{ NatOrdinal.linearOrder with
add := (· + ·)
add_assoc := nadd_assoc
add_le_add_left := fun a b => add_le_add_left
le_of_add_le_add_left := fun a b c => le_of_add_le_add_left
zero := 0
zero_add := zero_nadd
add_zero := nadd_zero
add_comm := nadd_comm
nsmul := nsmulRec }
instance addMonoidWithOne : AddMonoidWithOne NatOrdinal :=
AddMonoidWithOne.unary
@[simp]
theorem add_one_eq_succ : ∀ a : NatOrdinal, a + 1 = succ a :=
nadd_one
@[simp]
theorem toOrdinal_cast_nat (n : ℕ) : toOrdinal n = n := by
induction' n with n hn
· rfl
· change (toOrdinal n) ♯ 1 = n + 1
rw [hn]; exact nadd_one n
end NatOrdinal
open NatOrdinal
open NaturalOps
namespace Ordinal
theorem nadd_eq_add (a b : Ordinal) : a ♯ b = toOrdinal (toNatOrdinal a + toNatOrdinal b) :=
rfl
@[simp]
theorem toNatOrdinal_cast_nat (n : ℕ) : toNatOrdinal n = n := by
rw [← toOrdinal_cast_nat n]
rfl
theorem lt_of_nadd_lt_nadd_left : ∀ {a b c}, a ♯ b < a ♯ c → b < c :=
@lt_of_add_lt_add_left NatOrdinal _ _ _
theorem lt_of_nadd_lt_nadd_right : ∀ {a b c}, b ♯ a < c ♯ a → b < c :=
@lt_of_add_lt_add_right NatOrdinal _ _ _
theorem le_of_nadd_le_nadd_left : ∀ {a b c}, a ♯ b ≤ a ♯ c → b ≤ c :=
@le_of_add_le_add_left NatOrdinal _ _ _
theorem le_of_nadd_le_nadd_right : ∀ {a b c}, b ♯ a ≤ c ♯ a → b ≤ c :=
@le_of_add_le_add_right NatOrdinal _ _ _
theorem nadd_lt_nadd_iff_left : ∀ (a) {b c}, a ♯ b < a ♯ c ↔ b < c :=
@add_lt_add_iff_left NatOrdinal _ _ _ _
theorem nadd_lt_nadd_iff_right : ∀ (a) {b c}, b ♯ a < c ♯ a ↔ b < c :=
@add_lt_add_iff_right NatOrdinal _ _ _ _
theorem nadd_le_nadd_iff_left : ∀ (a) {b c}, a ♯ b ≤ a ♯ c ↔ b ≤ c :=
@add_le_add_iff_left NatOrdinal _ _ _ _
theorem nadd_le_nadd_iff_right : ∀ (a) {b c}, b ♯ a ≤ c ♯ a ↔ b ≤ c :=
@_root_.add_le_add_iff_right NatOrdinal _ _ _ _
theorem nadd_le_nadd : ∀ {a b c d}, a ≤ b → c ≤ d → a ♯ c ≤ b ♯ d :=
@add_le_add NatOrdinal _ _ _ _
theorem nadd_lt_nadd : ∀ {a b c d}, a < b → c < d → a ♯ c < b ♯ d :=
@add_lt_add NatOrdinal _ _ _ _
theorem nadd_lt_nadd_of_lt_of_le : ∀ {a b c d}, a < b → c ≤ d → a ♯ c < b ♯ d :=
@add_lt_add_of_lt_of_le NatOrdinal _ _ _ _
theorem nadd_lt_nadd_of_le_of_lt : ∀ {a b c d}, a ≤ b → c < d → a ♯ c < b ♯ d :=
@add_lt_add_of_le_of_lt NatOrdinal _ _ _ _
theorem nadd_left_cancel : ∀ {a b c}, a ♯ b = a ♯ c → b = c :=
@_root_.add_left_cancel NatOrdinal _ _
theorem nadd_right_cancel : ∀ {a b c}, a ♯ b = c ♯ b → a = c :=
@_root_.add_right_cancel NatOrdinal _ _
theorem nadd_left_cancel_iff : ∀ {a b c}, a ♯ b = a ♯ c ↔ b = c :=
@add_left_cancel_iff NatOrdinal _ _
theorem nadd_right_cancel_iff : ∀ {a b c}, b ♯ a = c ♯ a ↔ b = c :=
@add_right_cancel_iff NatOrdinal _ _
theorem le_nadd_self {a b} : a ≤ b ♯ a := by simpa using nadd_le_nadd_right (Ordinal.zero_le b) a
theorem le_nadd_left {a b c} (h : a ≤ c) : a ≤ b ♯ c :=
le_nadd_self.trans (nadd_le_nadd_left h b)
theorem le_self_nadd {a b} : a ≤ a ♯ b := by simpa using nadd_le_nadd_left (Ordinal.zero_le b) a
theorem le_nadd_right {a b c} (h : a ≤ b) : a ≤ b ♯ c :=
le_self_nadd.trans (nadd_le_nadd_right h c)
theorem nadd_left_comm : ∀ a b c, a ♯ (b ♯ c) = b ♯ (a ♯ c) :=
@add_left_comm NatOrdinal _
theorem nadd_right_comm : ∀ a b c, a ♯ b ♯ c = a ♯ c ♯ b :=
@add_right_comm NatOrdinal _
/-! ### Natural multiplication -/
variable {a b c d : Ordinal.{u}}
theorem nmul_def (a b : Ordinal) :
a ⨳ b = sInf {c | ∀ a' < a, ∀ b' < b, a' ⨳ b ♯ a ⨳ b' < c ♯ a' ⨳ b'} := by rw [nmul]
/-- The set in the definition of `nmul` is nonempty. -/
theorem nmul_nonempty (a b : Ordinal.{u}) :
{c : Ordinal.{u} | ∀ a' < a, ∀ b' < b, a' ⨳ b ♯ a ⨳ b' < c ♯ a' ⨳ b'}.Nonempty :=
⟨_, fun _ ha _ hb => (lt_blsub₂.{u, u, u} _ ha hb).trans_le le_self_nadd⟩
theorem nmul_nadd_lt {a' b' : Ordinal} (ha : a' < a) (hb : b' < b) :
a' ⨳ b ♯ a ⨳ b' < a ⨳ b ♯ a' ⨳ b' := by
rw [nmul_def a b]
exact csInf_mem (nmul_nonempty a b) a' ha b' hb
theorem nmul_nadd_le {a' b' : Ordinal} (ha : a' ≤ a) (hb : b' ≤ b) :
a' ⨳ b ♯ a ⨳ b' ≤ a ⨳ b ♯ a' ⨳ b' := by
rcases lt_or_eq_of_le ha with (ha | rfl)
· rcases lt_or_eq_of_le hb with (hb | rfl)
· exact (nmul_nadd_lt ha hb).le
· rw [nadd_comm]
· exact le_rfl
theorem lt_nmul_iff : c < a ⨳ b ↔ ∃ a' < a, ∃ b' < b, c ♯ a' ⨳ b' ≤ a' ⨳ b ♯ a ⨳ b' := by
refine ⟨fun h => ?_, ?_⟩
· rw [nmul] at h
simpa using not_mem_of_lt_csInf h ⟨0, fun _ _ => bot_le⟩
· rintro ⟨a', ha, b', hb, h⟩
have := h.trans_lt (nmul_nadd_lt ha hb)
rwa [nadd_lt_nadd_iff_right] at this
theorem nmul_le_iff : a ⨳ b ≤ c ↔ ∀ a' < a, ∀ b' < b, a' ⨳ b ♯ a ⨳ b' < c ♯ a' ⨳ b' := by
rw [← not_iff_not]; simp [lt_nmul_iff]
theorem nmul_comm : ∀ a b, a ⨳ b = b ⨳ a
| a, b => by
rw [nmul, nmul]
congr; ext x; constructor <;> intro H c hc d hd
-- Porting note: had to add additional arguments to `nmul_comm` here
-- for the termination checker.
· rw [nadd_comm, ← nmul_comm d b, ← nmul_comm a c, ← nmul_comm d]
exact H _ hd _ hc
· rw [nadd_comm, nmul_comm a d, nmul_comm c, nmul_comm c]
exact H _ hd _ hc
termination_by a b => (a, b)
@[simp]
theorem nmul_zero (a) : a ⨳ 0 = 0 := by
rw [← Ordinal.le_zero, nmul_le_iff]
exact fun _ _ a ha => (Ordinal.not_lt_zero a ha).elim
@[simp]
theorem zero_nmul (a) : 0 ⨳ a = 0 := by rw [nmul_comm, nmul_zero]
@[simp]
theorem nmul_one (a : Ordinal) : a ⨳ 1 = a := by
rw [nmul]
simp only [lt_one_iff_zero, forall_eq, nmul_zero, nadd_zero]
convert csInf_Ici (α := Ordinal)
ext b
-- Porting note: added this `simp` line, as the result from `convert`
-- is slightly different.
simp only [Set.mem_setOf_eq, Set.mem_Ici]
refine ⟨fun H => le_of_forall_lt fun c hc => ?_, fun ha c hc => ?_⟩
-- Porting note: had to add arguments to `nmul_one` in the next two lines
-- for the termination checker.
· simpa only [nmul_one c] using H c hc
· simpa only [nmul_one c] using hc.trans_le ha
termination_by a
@[simp]
theorem one_nmul (a) : 1 ⨳ a = a := by rw [nmul_comm, nmul_one]
theorem nmul_lt_nmul_of_pos_left (h₁ : a < b) (h₂ : 0 < c) : c ⨳ a < c ⨳ b :=
lt_nmul_iff.2 ⟨0, h₂, a, h₁, by simp⟩
theorem nmul_lt_nmul_of_pos_right (h₁ : a < b) (h₂ : 0 < c) : a ⨳ c < b ⨳ c :=
lt_nmul_iff.2 ⟨a, h₁, 0, h₂, by simp⟩
theorem nmul_le_nmul_of_nonneg_left (h₁ : a ≤ b) (h₂ : 0 ≤ c) : c ⨳ a ≤ c ⨳ b := by
rcases lt_or_eq_of_le h₁ with (h₁ | rfl) <;> rcases lt_or_eq_of_le h₂ with (h₂ | rfl)
· exact (nmul_lt_nmul_of_pos_left h₁ h₂).le
all_goals simp
theorem nmul_le_nmul_of_nonneg_right (h₁ : a ≤ b) (h₂ : 0 ≤ c) : a ⨳ c ≤ b ⨳ c := by
rw [nmul_comm, nmul_comm b]
exact nmul_le_nmul_of_nonneg_left h₁ h₂
theorem nmul_nadd : ∀ a b c, a ⨳ (b ♯ c) = a ⨳ b ♯ a ⨳ c
| a, b, c => by
refine le_antisymm (nmul_le_iff.2 fun a' ha d hd => ?_)
(nadd_le_iff.2 ⟨fun d hd => ?_, fun d hd => ?_⟩)
· -- Porting note: adding arguments to `nmul_nadd` for the termination checker.
rw [nmul_nadd a' b c]
rcases lt_nadd_iff.1 hd with (⟨b', hb, hd⟩ | ⟨c', hc, hd⟩)
· have := nadd_lt_nadd_of_lt_of_le (nmul_nadd_lt ha hb) (nmul_nadd_le ha.le hd)
-- Porting note: adding arguments to `nmul_nadd` for the termination checker.
rw [nmul_nadd a' b' c, nmul_nadd a b' c] at this
simp only [nadd_assoc] at this
rwa [nadd_left_comm, nadd_left_comm _ (a ⨳ b'), nadd_left_comm (a ⨳ b),
nadd_lt_nadd_iff_left, nadd_left_comm (a' ⨳ b), nadd_left_comm (a ⨳ b),
nadd_lt_nadd_iff_left, ← nadd_assoc, ← nadd_assoc] at this
· have := nadd_lt_nadd_of_le_of_lt (nmul_nadd_le ha.le hd) (nmul_nadd_lt ha hc)
-- Porting note: adding arguments to `nmul_nadd` for the termination checker.
rw [nmul_nadd a' b c', nmul_nadd a b c'] at this
simp only [nadd_assoc] at this
rwa [nadd_left_comm, nadd_comm (a ⨳ c), nadd_left_comm (a' ⨳ d), nadd_left_comm (a ⨳ c'),
nadd_left_comm (a ⨳ b), nadd_lt_nadd_iff_left, nadd_comm (a' ⨳ c), nadd_left_comm (a ⨳ d),
nadd_left_comm (a' ⨳ b), nadd_left_comm (a ⨳ b), nadd_lt_nadd_iff_left, nadd_comm (a ⨳ d),
nadd_comm (a' ⨳ d), ← nadd_assoc, ← nadd_assoc] at this
· rcases lt_nmul_iff.1 hd with ⟨a', ha, b', hb, hd⟩
have := nadd_lt_nadd_of_le_of_lt hd (nmul_nadd_lt ha (nadd_lt_nadd_right hb c))
-- Porting note: adding arguments to `nmul_nadd` for the termination checker.
rw [nmul_nadd a' b c, nmul_nadd a b' c, nmul_nadd a'] at this
simp only [nadd_assoc] at this
rwa [nadd_left_comm (a' ⨳ b'), nadd_left_comm, nadd_lt_nadd_iff_left, nadd_left_comm,
nadd_left_comm _ (a' ⨳ b'), nadd_left_comm (a ⨳ b'), nadd_lt_nadd_iff_left,
nadd_left_comm (a' ⨳ c), nadd_left_comm, nadd_lt_nadd_iff_left, nadd_left_comm,
nadd_comm _ (a' ⨳ c), nadd_lt_nadd_iff_left] at this
· rcases lt_nmul_iff.1 hd with ⟨a', ha, c', hc, hd⟩
have := nadd_lt_nadd_of_lt_of_le (nmul_nadd_lt ha (nadd_lt_nadd_left hc b)) hd
-- Porting note: adding arguments to `nmul_nadd` for the termination checker.
rw [nmul_nadd a' b c, nmul_nadd a b c', nmul_nadd a'] at this
simp only [nadd_assoc] at this
rwa [nadd_left_comm _ (a' ⨳ b), nadd_lt_nadd_iff_left, nadd_left_comm (a' ⨳ c'),
nadd_left_comm _ (a' ⨳ c), nadd_lt_nadd_iff_left, nadd_left_comm, nadd_comm (a' ⨳ c'),
nadd_left_comm _ (a ⨳ c'), nadd_lt_nadd_iff_left, nadd_comm _ (a' ⨳ c'),
nadd_comm _ (a' ⨳ c'), nadd_left_comm, nadd_lt_nadd_iff_left] at this
termination_by a b c => (a, b, c)
theorem nadd_nmul (a b c) : (a ♯ b) ⨳ c = a ⨳ c ♯ b ⨳ c := by
rw [nmul_comm, nmul_nadd, nmul_comm, nmul_comm c]
theorem nmul_nadd_lt₃ {a' b' c' : Ordinal} (ha : a' < a) (hb : b' < b) (hc : c' < c) :
a' ⨳ b ⨳ c ♯ a ⨳ b' ⨳ c ♯ a ⨳ b ⨳ c' ♯ a' ⨳ b' ⨳ c' <
a ⨳ b ⨳ c ♯ a' ⨳ b' ⨳ c ♯ a' ⨳ b ⨳ c' ♯ a ⨳ b' ⨳ c' := by
simpa only [nadd_nmul, ← nadd_assoc] using nmul_nadd_lt (nmul_nadd_lt ha hb) hc
theorem nmul_nadd_le₃ {a' b' c' : Ordinal} (ha : a' ≤ a) (hb : b' ≤ b) (hc : c' ≤ c) :
a' ⨳ b ⨳ c ♯ a ⨳ b' ⨳ c ♯ a ⨳ b ⨳ c' ♯ a' ⨳ b' ⨳ c' ≤
a ⨳ b ⨳ c ♯ a' ⨳ b' ⨳ c ♯ a' ⨳ b ⨳ c' ♯ a ⨳ b' ⨳ c' := by
simpa only [nadd_nmul, ← nadd_assoc] using nmul_nadd_le (nmul_nadd_le ha hb) hc
theorem nmul_nadd_lt₃' {a' b' c' : Ordinal} (ha : a' < a) (hb : b' < b) (hc : c' < c) :
a' ⨳ (b ⨳ c) ♯ a ⨳ (b' ⨳ c) ♯ a ⨳ (b ⨳ c') ♯ a' ⨳ (b' ⨳ c') <
a ⨳ (b ⨳ c) ♯ a' ⨳ (b' ⨳ c) ♯ a' ⨳ (b ⨳ c') ♯ a ⨳ (b' ⨳ c') := by
simp only [nmul_comm _ (_ ⨳ _)]
convert nmul_nadd_lt₃ hb hc ha using 1 <;>
· simp only [nadd_eq_add, NatOrdinal.toOrdinal_toNatOrdinal]; abel_nf
theorem nmul_nadd_le₃' {a' b' c' : Ordinal} (ha : a' ≤ a) (hb : b' ≤ b) (hc : c' ≤ c) :
a' ⨳ (b ⨳ c) ♯ a ⨳ (b' ⨳ c) ♯ a ⨳ (b ⨳ c') ♯ a' ⨳ (b' ⨳ c') ≤
a ⨳ (b ⨳ c) ♯ a' ⨳ (b' ⨳ c) ♯ a' ⨳ (b ⨳ c') ♯ a ⨳ (b' ⨳ c') := by
simp only [nmul_comm _ (_ ⨳ _)]
convert nmul_nadd_le₃ hb hc ha using 1 <;>
· simp only [nadd_eq_add, NatOrdinal.toOrdinal_toNatOrdinal]; abel_nf
theorem lt_nmul_iff₃ :
d < a ⨳ b ⨳ c ↔
∃ a' < a, ∃ b' < b, ∃ c' < c,
d ♯ a' ⨳ b' ⨳ c ♯ a' ⨳ b ⨳ c' ♯ a ⨳ b' ⨳ c' ≤
a' ⨳ b ⨳ c ♯ a ⨳ b' ⨳ c ♯ a ⨳ b ⨳ c' ♯ a' ⨳ b' ⨳ c' := by
refine ⟨fun h => ?_, ?_⟩
· rcases lt_nmul_iff.1 h with ⟨e, he, c', hc, H₁⟩
rcases lt_nmul_iff.1 he with ⟨a', ha, b', hb, H₂⟩
refine ⟨a', ha, b', hb, c', hc, ?_⟩
have := nadd_le_nadd H₁ (nmul_nadd_le H₂ hc.le)
simp only [nadd_nmul, nadd_assoc] at this
rw [nadd_left_comm, nadd_left_comm d, nadd_left_comm, nadd_le_nadd_iff_left,
nadd_left_comm (a ⨳ b' ⨳ c), nadd_left_comm (a' ⨳ b ⨳ c), nadd_left_comm (a ⨳ b ⨳ c'),
nadd_le_nadd_iff_left, nadd_left_comm (a ⨳ b ⨳ c'), nadd_left_comm (a ⨳ b ⨳ c')] at this
simpa only [nadd_assoc]
· rintro ⟨a', ha, b', hb, c', hc, h⟩
have := h.trans_lt (nmul_nadd_lt₃ ha hb hc)
repeat' rw [nadd_lt_nadd_iff_right] at this
assumption
theorem nmul_le_iff₃ :
a ⨳ b ⨳ c ≤ d ↔
∀ a' < a, ∀ b' < b, ∀ c' < c,
a' ⨳ b ⨳ c ♯ a ⨳ b' ⨳ c ♯ a ⨳ b ⨳ c' ♯ a' ⨳ b' ⨳ c' <
d ♯ a' ⨳ b' ⨳ c ♯ a' ⨳ b ⨳ c' ♯ a ⨳ b' ⨳ c' := by
rw [← not_iff_not]; simp [lt_nmul_iff₃]
theorem lt_nmul_iff₃' :
d < a ⨳ (b ⨳ c) ↔
∃ a' < a, ∃ b' < b, ∃ c' < c,
d ♯ a' ⨳ (b' ⨳ c) ♯ a' ⨳ (b ⨳ c') ♯ a ⨳ (b' ⨳ c') ≤
a' ⨳ (b ⨳ c) ♯ a ⨳ (b' ⨳ c) ♯ a ⨳ (b ⨳ c') ♯ a' ⨳ (b' ⨳ c') := by
simp only [nmul_comm _ (_ ⨳ _), lt_nmul_iff₃, nadd_eq_add, NatOrdinal.toOrdinal_toNatOrdinal]
constructor <;> rintro ⟨b', hb, c', hc, a', ha, h⟩
· use a', ha, b', hb, c', hc; convert h using 1 <;> abel_nf
· use c', hc, a', ha, b', hb; convert h using 1 <;> abel_nf
theorem nmul_le_iff₃' :
a ⨳ (b ⨳ c) ≤ d ↔
∀ a' < a, ∀ b' < b, ∀ c' < c,
a' ⨳ (b ⨳ c) ♯ a ⨳ (b' ⨳ c) ♯ a ⨳ (b ⨳ c') ♯ a' ⨳ (b' ⨳ c') <
d ♯ a' ⨳ (b' ⨳ c) ♯ a' ⨳ (b ⨳ c') ♯ a ⨳ (b' ⨳ c') := by
rw [← not_iff_not]; simp [lt_nmul_iff₃']
theorem nmul_assoc : ∀ a b c, a ⨳ b ⨳ c = a ⨳ (b ⨳ c)
| a, b, c => by
apply le_antisymm
· rw [nmul_le_iff₃]
intro a' ha b' hb c' hc
-- Porting note: the next line was just
-- repeat' rw [nmul_assoc]
-- but we need to spell out the arguments for the termination checker.
rw [nmul_assoc a' b c, nmul_assoc a b' c, nmul_assoc a b c', nmul_assoc a' b' c',
nmul_assoc a' b' c, nmul_assoc a' b c', nmul_assoc a b' c']
exact nmul_nadd_lt₃' ha hb hc
· rw [nmul_le_iff₃']
intro a' ha b' hb c' hc
-- Porting note: the next line was just
-- repeat' rw [← nmul_assoc]
-- but we need to spell out the arguments for the termination checker.
rw [← nmul_assoc a' b c, ← nmul_assoc a b' c, ← nmul_assoc a b c', ← nmul_assoc a' b' c',
← nmul_assoc a' b' c, ← nmul_assoc a' b c', ← nmul_assoc a b' c']
exact nmul_nadd_lt₃ ha hb hc
termination_by a b c => (a, b, c)
end Ordinal
open Ordinal
instance : Mul NatOrdinal :=
⟨nmul⟩
-- Porting note: had to add universe annotations to ensure that the
-- two sources lived in the same universe.
instance : OrderedCommSemiring NatOrdinal.{u} :=
{ NatOrdinal.orderedCancelAddCommMonoid.{u},
NatOrdinal.linearOrder.{u} with
mul := (· * ·)
left_distrib := nmul_nadd
right_distrib := nadd_nmul
zero_mul := zero_nmul
mul_zero := nmul_zero
mul_assoc := nmul_assoc
one := 1
one_mul := one_nmul
mul_one := nmul_one
mul_comm := nmul_comm
zero_le_one := @zero_le_one Ordinal _ _ _ _
mul_le_mul_of_nonneg_left := fun a b c => nmul_le_nmul_of_nonneg_left
mul_le_mul_of_nonneg_right := fun a b c => nmul_le_nmul_of_nonneg_right }
namespace Ordinal
theorem nmul_eq_mul (a b) : a ⨳ b = toOrdinal (toNatOrdinal a * toNatOrdinal b) :=
rfl
theorem nmul_nadd_one : ∀ a b, a ⨳ (b ♯ 1) = a ⨳ b ♯ a :=
@mul_add_one NatOrdinal _ _ _
theorem nadd_one_nmul : ∀ a b, (a ♯ 1) ⨳ b = a ⨳ b ♯ b :=
@add_one_mul NatOrdinal _ _ _
theorem nmul_succ (a b) : a ⨳ succ b = a ⨳ b ♯ a := by rw [← nadd_one, nmul_nadd_one]
theorem succ_nmul (a b) : succ a ⨳ b = a ⨳ b ♯ b := by rw [← nadd_one, nadd_one_nmul]
theorem nmul_add_one : ∀ a b, a ⨳ (b + 1) = a ⨳ b ♯ a :=
nmul_succ
theorem add_one_nmul : ∀ a b, (a + 1) ⨳ b = a ⨳ b ♯ b :=
succ_nmul
end Ordinal
namespace NatOrdinal
open Ordinal
theorem mul_le_nmul (a b : Ordinal.{u}) : a * b ≤ a ⨳ b := by
refine b.limitRecOn ?_ ?_ ?_
· simp
· intro c h
rw [mul_succ, nmul_succ]
exact (add_le_nadd _ a).trans (nadd_le_nadd_right h a)
· intro c hc H
rcases eq_zero_or_pos a with (rfl | ha)
· simp
· rw [← IsNormal.blsub_eq.{u, u} (mul_isNormal ha) hc, blsub_le_iff]
exact fun i hi => (H i hi).trans_lt (nmul_lt_nmul_of_pos_left hi ha)
end NatOrdinal
|
SetTheory\Ordinal\Notation.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.Ring.Divisibility.Basic
import Mathlib.Data.Ordering.Lemmas
import Mathlib.SetTheory.Ordinal.Principal
import Mathlib.Tactic.NormNum
import Mathlib.Data.PNat.Basic
/-!
# Ordinal notation
Constructive ordinal arithmetic for ordinals below `ε₀`.
We define a type `ONote`, with constructors `0 : ONote` and `ONote.oadd e n a` representing
`ω ^ e * n + a`.
We say that `o` is in Cantor normal form - `ONote.NF o` - if either `o = 0` or
`o = ω ^ e * n + a` with `a < ω ^ e` and `a` in Cantor normal form.
The type `NONote` is the type of ordinals below `ε₀` in Cantor normal form.
Various operations (addition, subtraction, multiplication, power function)
are defined on `ONote` and `NONote`.
-/
open Ordinal Order
-- Porting note: the generated theorem is warned by `simpNF`.
set_option genSizeOfSpec false in
/-- Recursive definition of an ordinal notation. `zero` denotes the
ordinal 0, and `oadd e n a` is intended to refer to `ω^e * n + a`.
For this to be valid Cantor normal form, we must have the exponents
decrease to the right, but we can't state this condition until we've
defined `repr`, so it is a separate definition `NF`. -/
inductive ONote : Type
| zero : ONote
| oadd : ONote → ℕ+ → ONote → ONote
deriving DecidableEq
compile_inductive% ONote
namespace ONote
/-- Notation for 0 -/
instance : Zero ONote :=
⟨zero⟩
@[simp]
theorem zero_def : zero = 0 :=
rfl
instance : Inhabited ONote :=
⟨0⟩
/-- Notation for 1 -/
instance : One ONote :=
⟨oadd 0 1 0⟩
/-- Notation for ω -/
def omega : ONote :=
oadd 1 1 0
/-- The ordinal denoted by a notation -/
@[simp]
noncomputable def repr : ONote → Ordinal.{0}
| 0 => 0
| oadd e n a => ω ^ repr e * n + repr a
/-- Auxiliary definition to print an ordinal notation -/
def toStringAux1 (e : ONote) (n : ℕ) (s : String) : String :=
if e = 0 then toString n
else (if e = 1 then "ω" else "ω^(" ++ s ++ ")") ++ if n = 1 then "" else "*" ++ toString n
/-- Print an ordinal notation -/
def toString : ONote → String
| zero => "0"
| oadd e n 0 => toStringAux1 e n (toString e)
| oadd e n a => toStringAux1 e n (toString e) ++ " + " ++ toString a
open Lean in
/-- Print an ordinal notation -/
def repr' (prec : ℕ) : ONote → Format
| zero => "0"
| oadd e n a =>
Repr.addAppParen
("oadd " ++ (repr' max_prec e) ++ " " ++ Nat.repr (n : ℕ) ++ " " ++ (repr' max_prec a))
prec
instance : ToString ONote :=
⟨toString⟩
instance : Repr ONote where
reprPrec o prec := repr' prec o
instance : Preorder ONote where
le x y := repr x ≤ repr y
lt x y := repr x < repr y
le_refl _ := @le_refl Ordinal _ _
le_trans _ _ _ := @le_trans Ordinal _ _ _ _
lt_iff_le_not_le _ _ := @lt_iff_le_not_le Ordinal _ _ _
theorem lt_def {x y : ONote} : x < y ↔ repr x < repr y :=
Iff.rfl
theorem le_def {x y : ONote} : x ≤ y ↔ repr x ≤ repr y :=
Iff.rfl
instance : WellFoundedRelation ONote :=
⟨(· < ·), InvImage.wf repr Ordinal.lt_wf⟩
/-- Convert a `Nat` into an ordinal -/
@[coe]
def ofNat : ℕ → ONote
| 0 => 0
| Nat.succ n => oadd 0 n.succPNat 0
-- Porting note (#11467): during the port we marked these lemmas with `@[eqns]`
-- to emulate the old Lean 3 behaviour.
@[simp] theorem ofNat_zero : ofNat 0 = 0 :=
rfl
@[simp] theorem ofNat_succ (n) : ofNat (Nat.succ n) = oadd 0 n.succPNat 0 :=
rfl
instance nat (n : ℕ) : OfNat ONote n where
ofNat := ofNat n
@[simp 1200]
theorem ofNat_one : ofNat 1 = 1 :=
rfl
@[simp]
theorem repr_ofNat (n : ℕ) : repr (ofNat n) = n := by cases n <;> simp
-- @[simp] -- Porting note (#10618): simp can prove this
theorem repr_one : repr (ofNat 1) = (1 : ℕ) := repr_ofNat 1
theorem omega_le_oadd (e n a) : ω ^ repr e ≤ repr (oadd e n a) := by
refine le_trans ?_ (le_add_right _ _)
simpa using (Ordinal.mul_le_mul_iff_left <| opow_pos (repr e) omega_pos).2 (natCast_le.2 n.2)
theorem oadd_pos (e n a) : 0 < oadd e n a :=
@lt_of_lt_of_le _ _ _ (ω ^ repr e) _ (opow_pos (repr e) omega_pos) (omega_le_oadd e n a)
/-- Compare ordinal notations -/
def cmp : ONote → ONote → Ordering
| 0, 0 => Ordering.eq
| _, 0 => Ordering.gt
| 0, _ => Ordering.lt
| _o₁@(oadd e₁ n₁ a₁), _o₂@(oadd e₂ n₂ a₂) =>
(cmp e₁ e₂).orElse <| (_root_.cmp (n₁ : ℕ) n₂).orElse (cmp a₁ a₂)
theorem eq_of_cmp_eq : ∀ {o₁ o₂}, cmp o₁ o₂ = Ordering.eq → o₁ = o₂
| 0, 0, _ => rfl
| oadd e n a, 0, h => by injection h
| 0, oadd e n a, h => by injection h
| oadd e₁ n₁ a₁, oadd e₂ n₂ a₂, h => by
revert h; simp only [cmp]
cases h₁ : cmp e₁ e₂ <;> intro h <;> try cases h
obtain rfl := eq_of_cmp_eq h₁
revert h; cases h₂ : _root_.cmp (n₁ : ℕ) n₂ <;> intro h <;> try cases h
obtain rfl := eq_of_cmp_eq h
rw [_root_.cmp, cmpUsing_eq_eq] at h₂
obtain rfl := Subtype.eq (eq_of_incomp h₂)
simp
protected theorem zero_lt_one : (0 : ONote) < 1 := by
simp only [lt_def, repr, opow_zero, Nat.succPNat_coe, Nat.cast_one, mul_one, add_zero,
zero_lt_one]
/-- `NFBelow o b` says that `o` is a normal form ordinal notation
satisfying `repr o < ω ^ b`. -/
inductive NFBelow : ONote → Ordinal.{0} → Prop
| zero {b} : NFBelow 0 b
| oadd' {e n a eb b} : NFBelow e eb → NFBelow a (repr e) → repr e < b → NFBelow (oadd e n a) b
/-- A normal form ordinal notation has the form
ω ^ a₁ * n₁ + ω ^ a₂ * n₂ + ... ω ^ aₖ * nₖ
where `a₁ > a₂ > ... > aₖ` and all the `aᵢ` are
also in normal form.
We will essentially only be interested in normal form
ordinal notations, but to avoid complicating the algorithms
we define everything over general ordinal notations and
only prove correctness with normal form as an invariant. -/
class NF (o : ONote) : Prop where
out : Exists (NFBelow o)
instance NF.zero : NF 0 :=
⟨⟨0, NFBelow.zero⟩⟩
theorem NFBelow.oadd {e n a b} : NF e → NFBelow a (repr e) → repr e < b → NFBelow (oadd e n a) b
| ⟨⟨_, h⟩⟩ => NFBelow.oadd' h
theorem NFBelow.fst {e n a b} (h : NFBelow (ONote.oadd e n a) b) : NF e := by
cases' h with _ _ _ _ eb _ h₁ h₂ h₃; exact ⟨⟨_, h₁⟩⟩
theorem NF.fst {e n a} : NF (oadd e n a) → NF e
| ⟨⟨_, h⟩⟩ => h.fst
theorem NFBelow.snd {e n a b} (h : NFBelow (ONote.oadd e n a) b) : NFBelow a (repr e) := by
cases' h with _ _ _ _ eb _ h₁ h₂ h₃; exact h₂
theorem NF.snd' {e n a} : NF (oadd e n a) → NFBelow a (repr e)
| ⟨⟨_, h⟩⟩ => h.snd
theorem NF.snd {e n a} (h : NF (oadd e n a)) : NF a :=
⟨⟨_, h.snd'⟩⟩
theorem NF.oadd {e a} (h₁ : NF e) (n) (h₂ : NFBelow a (repr e)) : NF (oadd e n a) :=
⟨⟨_, NFBelow.oadd h₁ h₂ (lt_succ _)⟩⟩
instance NF.oadd_zero (e n) [h : NF e] : NF (ONote.oadd e n 0) :=
h.oadd _ NFBelow.zero
theorem NFBelow.lt {e n a b} (h : NFBelow (ONote.oadd e n a) b) : repr e < b := by
cases' h with _ _ _ _ eb _ h₁ h₂ h₃; exact h₃
theorem NFBelow_zero : ∀ {o}, NFBelow o 0 ↔ o = 0
| 0 => ⟨fun _ => rfl, fun _ => NFBelow.zero⟩
| oadd _ _ _ =>
⟨fun h => (not_le_of_lt h.lt).elim (Ordinal.zero_le _), fun e => e.symm ▸ NFBelow.zero⟩
theorem NF.zero_of_zero {e n a} (h : NF (ONote.oadd e n a)) (e0 : e = 0) : a = 0 := by
simpa [e0, NFBelow_zero] using h.snd'
theorem NFBelow.repr_lt {o b} (h : NFBelow o b) : repr o < ω ^ b := by
induction' h with _ e n a eb b h₁ h₂ h₃ _ IH
· exact opow_pos _ omega_pos
· rw [repr]
apply ((add_lt_add_iff_left _).2 IH).trans_le
rw [← mul_succ]
apply (mul_le_mul_left' (succ_le_of_lt (nat_lt_omega _)) _).trans
rw [← opow_succ]
exact opow_le_opow_right omega_pos (succ_le_of_lt h₃)
theorem NFBelow.mono {o b₁ b₂} (bb : b₁ ≤ b₂) (h : NFBelow o b₁) : NFBelow o b₂ := by
induction' h with _ e n a eb b h₁ h₂ h₃ _ _ <;> constructor
exacts [h₁, h₂, lt_of_lt_of_le h₃ bb]
theorem NF.below_of_lt {e n a b} (H : repr e < b) :
NF (ONote.oadd e n a) → NFBelow (ONote.oadd e n a) b
| ⟨⟨b', h⟩⟩ => by (cases' h with _ _ _ _ eb _ h₁ h₂ h₃; exact NFBelow.oadd' h₁ h₂ H)
theorem NF.below_of_lt' : ∀ {o b}, repr o < ω ^ b → NF o → NFBelow o b
| 0, _, _, _ => NFBelow.zero
| ONote.oadd _ _ _, _, H, h =>
h.below_of_lt <|
(opow_lt_opow_iff_right one_lt_omega).1 <| lt_of_le_of_lt (omega_le_oadd _ _ _) H
theorem nfBelow_ofNat : ∀ n, NFBelow (ofNat n) 1
| 0 => NFBelow.zero
| Nat.succ _ => NFBelow.oadd NF.zero NFBelow.zero zero_lt_one
instance nf_ofNat (n) : NF (ofNat n) :=
⟨⟨_, nfBelow_ofNat n⟩⟩
instance nf_one : NF 1 := by rw [← ofNat_one]; infer_instance
theorem oadd_lt_oadd_1 {e₁ n₁ o₁ e₂ n₂ o₂} (h₁ : NF (oadd e₁ n₁ o₁)) (h : e₁ < e₂) :
oadd e₁ n₁ o₁ < oadd e₂ n₂ o₂ :=
@lt_of_lt_of_le _ _ (repr (oadd e₁ n₁ o₁)) _ _
(NF.below_of_lt h h₁).repr_lt (omega_le_oadd e₂ n₂ o₂)
theorem oadd_lt_oadd_2 {e o₁ o₂ : ONote} {n₁ n₂ : ℕ+} (h₁ : NF (oadd e n₁ o₁)) (h : (n₁ : ℕ) < n₂) :
oadd e n₁ o₁ < oadd e n₂ o₂ := by
simp only [lt_def, repr]
refine lt_of_lt_of_le ((add_lt_add_iff_left _).2 h₁.snd'.repr_lt) (le_trans ?_ (le_add_right _ _))
rwa [← mul_succ,Ordinal.mul_le_mul_iff_left (opow_pos _ omega_pos), succ_le_iff, natCast_lt]
theorem oadd_lt_oadd_3 {e n a₁ a₂} (h : a₁ < a₂) : oadd e n a₁ < oadd e n a₂ := by
rw [lt_def]; unfold repr
exact @add_lt_add_left _ _ _ _ (repr a₁) _ h _
theorem cmp_compares : ∀ (a b : ONote) [NF a] [NF b], (cmp a b).Compares a b
| 0, 0, _, _ => rfl
| oadd e n a, 0, _, _ => oadd_pos _ _ _
| 0, oadd e n a, _, _ => oadd_pos _ _ _
| o₁@(oadd e₁ n₁ a₁), o₂@(oadd e₂ n₂ a₂), h₁, h₂ => by -- TODO: golf
rw [cmp]
have IHe := @cmp_compares _ _ h₁.fst h₂.fst
simp only [Ordering.Compares, gt_iff_lt] at IHe; revert IHe
cases cmp e₁ e₂
case lt => intro IHe; exact oadd_lt_oadd_1 h₁ IHe
case gt => intro IHe; exact oadd_lt_oadd_1 h₂ IHe
case eq =>
intro IHe; dsimp at IHe; subst IHe
unfold _root_.cmp; cases nh : cmpUsing (· < ·) (n₁ : ℕ) n₂ <;>
rw [cmpUsing, ite_eq_iff, not_lt] at nh
case lt =>
cases' nh with nh nh
· exact oadd_lt_oadd_2 h₁ nh.left
· rw [ite_eq_iff] at nh; cases' nh.right with nh nh <;> cases nh <;> contradiction
case gt =>
cases' nh with nh nh
· cases nh; contradiction
· cases' nh with _ nh
rw [ite_eq_iff] at nh; cases' nh with nh nh
· exact oadd_lt_oadd_2 h₂ nh.left
· cases nh; contradiction
cases' nh with nh nh
· cases nh; contradiction
cases' nh with nhl nhr
rw [ite_eq_iff] at nhr
cases' nhr with nhr nhr
· cases nhr; contradiction
obtain rfl := Subtype.eq (eq_of_incomp ⟨(not_lt_of_ge nhl), nhr.left⟩)
have IHa := @cmp_compares _ _ h₁.snd h₂.snd
revert IHa; cases cmp a₁ a₂ <;> intro IHa <;> dsimp at IHa
case lt => exact oadd_lt_oadd_3 IHa
case gt => exact oadd_lt_oadd_3 IHa
subst IHa; exact rfl
theorem repr_inj {a b} [NF a] [NF b] : repr a = repr b ↔ a = b :=
⟨fun e => match cmp a b, cmp_compares a b with
| Ordering.lt, (h : repr a < repr b) => (ne_of_lt h e).elim
| Ordering.gt, (h : repr a > repr b)=> (ne_of_gt h e).elim
| Ordering.eq, h => h,
congr_arg _⟩
theorem NF.of_dvd_omega_opow {b e n a} (h : NF (ONote.oadd e n a))
(d : ω ^ b ∣ repr (ONote.oadd e n a)) :
b ≤ repr e ∧ ω ^ b ∣ repr a := by
have := mt repr_inj.1 (fun h => by injection h : ONote.oadd e n a ≠ 0)
have L := le_of_not_lt fun l => not_le_of_lt (h.below_of_lt l).repr_lt (le_of_dvd this d)
simp only [repr] at d
exact ⟨L, (dvd_add_iff <| (opow_dvd_opow _ L).mul_right _).1 d⟩
theorem NF.of_dvd_omega {e n a} (h : NF (ONote.oadd e n a)) :
ω ∣ repr (ONote.oadd e n a) → repr e ≠ 0 ∧ ω ∣ repr a := by
(rw [← opow_one ω, ← one_le_iff_ne_zero]; exact h.of_dvd_omega_opow)
/-- `TopBelow b o` asserts that the largest exponent in `o`, if
it exists, is less than `b`. This is an auxiliary definition
for decidability of `NF`. -/
def TopBelow (b : ONote) : ONote → Prop
| 0 => True
| oadd e _ _ => cmp e b = Ordering.lt
instance decidableTopBelow : DecidableRel TopBelow := by
intro b o
cases o <;> delta TopBelow <;> infer_instance
theorem nfBelow_iff_topBelow {b} [NF b] : ∀ {o}, NFBelow o (repr b) ↔ NF o ∧ TopBelow b o
| 0 => ⟨fun h => ⟨⟨⟨_, h⟩⟩, trivial⟩, fun _ => NFBelow.zero⟩
| oadd _ _ _ =>
⟨fun h => ⟨⟨⟨_, h⟩⟩, (@cmp_compares _ b h.fst _).eq_lt.2 h.lt⟩, fun ⟨h₁, h₂⟩ =>
h₁.below_of_lt <| (@cmp_compares _ b h₁.fst _).eq_lt.1 h₂⟩
instance decidableNF : DecidablePred NF
| 0 => isTrue NF.zero
| oadd e n a => by
have := decidableNF e
have := decidableNF a
apply decidable_of_iff (NF e ∧ NF a ∧ TopBelow e a)
rw [← and_congr_right fun h => @nfBelow_iff_topBelow _ h _]
exact ⟨fun ⟨h₁, h₂⟩ => NF.oadd h₁ n h₂, fun h => ⟨h.fst, h.snd'⟩⟩
/-- Auxiliary definition for `add` -/
def addAux (e : ONote) (n : ℕ+) (o : ONote) : ONote :=
match o with
| 0 => oadd e n 0
| o'@(oadd e' n' a') =>
match cmp e e' with
| Ordering.lt => o'
| Ordering.eq => oadd e (n + n') a'
| Ordering.gt => oadd e n o'
/-- Addition of ordinal notations (correct only for normal input) -/
def add : ONote → ONote → ONote
| 0, o => o
| oadd e n a, o => addAux e n (add a o)
instance : Add ONote :=
⟨add⟩
@[simp]
theorem zero_add (o : ONote) : 0 + o = o :=
rfl
theorem oadd_add (e n a o) : oadd e n a + o = addAux e n (a + o) :=
rfl
/-- Subtraction of ordinal notations (correct only for normal input) -/
def sub : ONote → ONote → ONote
| 0, _ => 0
| o, 0 => o
| o₁@(oadd e₁ n₁ a₁), oadd e₂ n₂ a₂ =>
match cmp e₁ e₂ with
| Ordering.lt => 0
| Ordering.gt => o₁
| Ordering.eq =>
match (n₁ : ℕ) - n₂ with
| 0 => if n₁ = n₂ then sub a₁ a₂ else 0
| Nat.succ k => oadd e₁ k.succPNat a₁
instance : Sub ONote :=
⟨sub⟩
theorem add_nfBelow {b} : ∀ {o₁ o₂}, NFBelow o₁ b → NFBelow o₂ b → NFBelow (o₁ + o₂) b
| 0, _, _, h₂ => h₂
| oadd e n a, o, h₁, h₂ => by
have h' := add_nfBelow (h₁.snd.mono <| le_of_lt h₁.lt) h₂
simp only [oadd_add]; revert h'; cases' a + o with e' n' a' <;> intro h'
· exact NFBelow.oadd h₁.fst NFBelow.zero h₁.lt
have : ((e.cmp e').Compares e e') := @cmp_compares _ _ h₁.fst h'.fst
cases h : cmp e e' <;> dsimp [addAux] <;> simp only [h]
· exact h'
· simp only [h] at this
subst e'
exact NFBelow.oadd h'.fst h'.snd h'.lt
· simp only [h] at this
exact NFBelow.oadd h₁.fst (NF.below_of_lt this ⟨⟨_, h'⟩⟩) h₁.lt
instance add_nf (o₁ o₂) : ∀ [NF o₁] [NF o₂], NF (o₁ + o₂)
| ⟨⟨b₁, h₁⟩⟩, ⟨⟨b₂, h₂⟩⟩ =>
⟨(le_total b₁ b₂).elim (fun h => ⟨b₂, add_nfBelow (h₁.mono h) h₂⟩) fun h =>
⟨b₁, add_nfBelow h₁ (h₂.mono h)⟩⟩
@[simp]
theorem repr_add : ∀ (o₁ o₂) [NF o₁] [NF o₂], repr (o₁ + o₂) = repr o₁ + repr o₂
| 0, o, _, _ => by simp
| oadd e n a, o, h₁, h₂ => by
haveI := h₁.snd; have h' := repr_add a o
conv_lhs at h' => simp [HAdd.hAdd, Add.add]
have nf := ONote.add_nf a o
conv at nf => simp [HAdd.hAdd, Add.add]
conv in _ + o => simp [HAdd.hAdd, Add.add]
cases' h : add a o with e' n' a' <;>
simp only [Add.add, add, addAux, h'.symm, h, add_assoc, repr] at nf h₁ ⊢
have := h₁.fst; haveI := nf.fst; have ee := cmp_compares e e'
cases he : cmp e e' <;> simp only [he, Ordering.compares_gt, Ordering.compares_lt,
Ordering.compares_eq, repr, gt_iff_lt, PNat.add_coe, Nat.cast_add] at ee ⊢
· rw [← add_assoc, @add_absorp _ (repr e') (ω ^ repr e' * (n' : ℕ))]
· have := (h₁.below_of_lt ee).repr_lt
unfold repr at this
cases he' : e' <;> simp only [he', zero_def, opow_zero, repr, gt_iff_lt] at this ⊢ <;>
exact lt_of_le_of_lt (le_add_right _ _) this
· simpa using (Ordinal.mul_le_mul_iff_left <| opow_pos (repr e') omega_pos).2
(natCast_le.2 n'.pos)
· rw [ee, ← add_assoc, ← mul_add]
theorem sub_nfBelow : ∀ {o₁ o₂ b}, NFBelow o₁ b → NF o₂ → NFBelow (o₁ - o₂) b
| 0, o, b, _, h₂ => by cases o <;> exact NFBelow.zero
| oadd _ _ _, 0, _, h₁, _ => h₁
| oadd e₁ n₁ a₁, oadd e₂ n₂ a₂, b, h₁, h₂ => by
have h' := sub_nfBelow h₁.snd h₂.snd
simp only [HSub.hSub, Sub.sub, sub] at h' ⊢
have := @cmp_compares _ _ h₁.fst h₂.fst
cases h : cmp e₁ e₂
· apply NFBelow.zero
· rw [Nat.sub_eq]
simp only [h, Ordering.compares_eq] at this
subst e₂
cases (n₁ : ℕ) - n₂
· by_cases en : n₁ = n₂ <;> simp only [en, ↓reduceIte]
· exact h'.mono (le_of_lt h₁.lt)
· exact NFBelow.zero
· exact NFBelow.oadd h₁.fst h₁.snd h₁.lt
· exact h₁
instance sub_nf (o₁ o₂) : ∀ [NF o₁] [NF o₂], NF (o₁ - o₂)
| ⟨⟨b₁, h₁⟩⟩, h₂ => ⟨⟨b₁, sub_nfBelow h₁ h₂⟩⟩
@[simp]
theorem repr_sub : ∀ (o₁ o₂) [NF o₁] [NF o₂], repr (o₁ - o₂) = repr o₁ - repr o₂
| 0, o, _, h₂ => by cases o <;> exact (Ordinal.zero_sub _).symm
| oadd e n a, 0, _, _ => (Ordinal.sub_zero _).symm
| oadd e₁ n₁ a₁, oadd e₂ n₂ a₂, h₁, h₂ => by
haveI := h₁.snd; haveI := h₂.snd; have h' := repr_sub a₁ a₂
conv_lhs at h' => dsimp [HSub.hSub, Sub.sub, sub]
conv_lhs => dsimp only [HSub.hSub, Sub.sub]; dsimp only [sub]
have ee := @cmp_compares _ _ h₁.fst h₂.fst
cases h : cmp e₁ e₂ <;> simp only [h] at ee
· rw [Ordinal.sub_eq_zero_iff_le.2]
· rfl
exact le_of_lt (oadd_lt_oadd_1 h₁ ee)
· change e₁ = e₂ at ee
subst e₂
dsimp only
cases mn : (n₁ : ℕ) - n₂ <;> dsimp only
· by_cases en : n₁ = n₂
· simpa [en]
· simp only [en, ite_false]
exact
(Ordinal.sub_eq_zero_iff_le.2 <|
le_of_lt <|
oadd_lt_oadd_2 h₁ <|
lt_of_le_of_ne (tsub_eq_zero_iff_le.1 mn) (mt PNat.eq en)).symm
· simp [Nat.succPNat]
rw [(tsub_eq_iff_eq_add_of_le <| le_of_lt <| Nat.lt_of_sub_eq_succ mn).1 mn, add_comm,
Nat.cast_add, mul_add, add_assoc, add_sub_add_cancel]
refine
(Ordinal.sub_eq_of_add_eq <|
add_absorp h₂.snd'.repr_lt <| le_trans ?_ (le_add_right _ _)).symm
simpa using mul_le_mul_left' (natCast_le.2 <| Nat.succ_pos _) _
· exact
(Ordinal.sub_eq_of_add_eq <|
add_absorp (h₂.below_of_lt ee).repr_lt <| omega_le_oadd _ _ _).symm
/-- Multiplication of ordinal notations (correct only for normal input) -/
def mul : ONote → ONote → ONote
| 0, _ => 0
| _, 0 => 0
| o₁@(oadd e₁ n₁ a₁), oadd e₂ n₂ a₂ =>
if e₂ = 0 then oadd e₁ (n₁ * n₂) a₁ else oadd (e₁ + e₂) n₂ (mul o₁ a₂)
instance : Mul ONote :=
⟨mul⟩
instance : MulZeroClass ONote where
mul := (· * ·)
zero := 0
zero_mul o := by cases o <;> rfl
mul_zero o := by cases o <;> rfl
theorem oadd_mul (e₁ n₁ a₁ e₂ n₂ a₂) :
oadd e₁ n₁ a₁ * oadd e₂ n₂ a₂ =
if e₂ = 0 then oadd e₁ (n₁ * n₂) a₁ else oadd (e₁ + e₂) n₂ (oadd e₁ n₁ a₁ * a₂) :=
rfl
theorem oadd_mul_nfBelow {e₁ n₁ a₁ b₁} (h₁ : NFBelow (oadd e₁ n₁ a₁) b₁) :
∀ {o₂ b₂}, NFBelow o₂ b₂ → NFBelow (oadd e₁ n₁ a₁ * o₂) (repr e₁ + b₂)
| 0, b₂, _ => NFBelow.zero
| oadd e₂ n₂ a₂, b₂, h₂ => by
have IH := oadd_mul_nfBelow h₁ h₂.snd
by_cases e0 : e₂ = 0 <;> simp only [e0, oadd_mul, ↓reduceIte]
· apply NFBelow.oadd h₁.fst h₁.snd
simpa using (add_lt_add_iff_left (repr e₁)).2 (lt_of_le_of_lt (Ordinal.zero_le _) h₂.lt)
· haveI := h₁.fst
haveI := h₂.fst
apply NFBelow.oadd
· infer_instance
· rwa [repr_add]
· rw [repr_add, add_lt_add_iff_left]
exact h₂.lt
instance mul_nf : ∀ (o₁ o₂) [NF o₁] [NF o₂], NF (o₁ * o₂)
| 0, o, _, h₂ => by cases o <;> exact NF.zero
| oadd e n a, o, ⟨⟨b₁, hb₁⟩⟩, ⟨⟨b₂, hb₂⟩⟩ => ⟨⟨_, oadd_mul_nfBelow hb₁ hb₂⟩⟩
@[simp]
theorem repr_mul : ∀ (o₁ o₂) [NF o₁] [NF o₂], repr (o₁ * o₂) = repr o₁ * repr o₂
| 0, o, _, h₂ => by cases o <;> exact (zero_mul _).symm
| oadd e₁ n₁ a₁, 0, _, _ => (mul_zero _).symm
| oadd e₁ n₁ a₁, oadd e₂ n₂ a₂, h₁, h₂ => by
have IH : repr (mul _ _) = _ := @repr_mul _ _ h₁ h₂.snd
conv =>
lhs
simp [(· * ·)]
have ao : repr a₁ + ω ^ repr e₁ * (n₁ : ℕ) = ω ^ repr e₁ * (n₁ : ℕ) := by
apply add_absorp h₁.snd'.repr_lt
simpa using (Ordinal.mul_le_mul_iff_left <| opow_pos _ omega_pos).2 (natCast_le.2 n₁.2)
by_cases e0 : e₂ = 0
· cases' Nat.exists_eq_succ_of_ne_zero n₂.ne_zero with x xe
simp only [e0, repr, PNat.mul_coe, natCast_mul, opow_zero, one_mul]
simp only [xe, h₂.zero_of_zero e0, repr, add_zero]
rw [natCast_succ x, add_mul_succ _ ao, mul_assoc]
· simp only [repr]
haveI := h₁.fst
haveI := h₂.fst
simp only [Mul.mul, mul, e0, ite_false, repr.eq_2, repr_add, opow_add, IH, repr, mul_add]
rw [← mul_assoc]
congr 2
have := mt repr_inj.1 e0
rw [add_mul_limit ao (opow_isLimit_left omega_isLimit this), mul_assoc,
mul_omega_dvd (natCast_pos.2 n₁.pos) (nat_lt_omega _)]
simpa using opow_dvd_opow ω (one_le_iff_ne_zero.2 this)
/-- Calculate division and remainder of `o` mod ω.
`split' o = (a, n)` means `o = ω * a + n`. -/
def split' : ONote → ONote × ℕ
| 0 => (0, 0)
| oadd e n a =>
if e = 0 then (0, n)
else
let (a', m) := split' a
(oadd (e - 1) n a', m)
/-- Calculate division and remainder of `o` mod ω.
`split o = (a, n)` means `o = a + n`, where `ω ∣ a`. -/
def split : ONote → ONote × ℕ
| 0 => (0, 0)
| oadd e n a =>
if e = 0 then (0, n)
else
let (a', m) := split a
(oadd e n a', m)
/-- `scale x o` is the ordinal notation for `ω ^ x * o`. -/
def scale (x : ONote) : ONote → ONote
| 0 => 0
| oadd e n a => oadd (x + e) n (scale x a)
/-- `mulNat o n` is the ordinal notation for `o * n`. -/
def mulNat : ONote → ℕ → ONote
| 0, _ => 0
| _, 0 => 0
| oadd e n a, m + 1 => oadd e (n * m.succPNat) a
/-- Auxiliary definition to compute the ordinal notation for the ordinal
exponentiation in `opow` -/
def opowAux (e a0 a : ONote) : ℕ → ℕ → ONote
| _, 0 => 0
| 0, m + 1 => oadd e m.succPNat 0
| k + 1, m => scale (e + mulNat a0 k) a + (opowAux e a0 a k m)
/-- Auxiliary definition to compute the ordinal notation for the ordinal
exponentiation in `opow` -/
def opowAux2 (o₂ : ONote) (o₁ : ONote × ℕ) : ONote :=
match o₁ with
| (0, 0) => if o₂ = 0 then 1 else 0
| (0, 1) => 1
| (0, m + 1) =>
let (b', k) := split' o₂
oadd b' (m.succPNat ^ k) 0
| (a@(oadd a0 _ _), m) =>
match split o₂ with
| (b, 0) => oadd (a0 * b) 1 0
| (b, k + 1) =>
let eb := a0 * b
scale (eb + mulNat a0 k) a + opowAux eb a0 (mulNat a m) k m
/-- `opow o₁ o₂` calculates the ordinal notation for
the ordinal exponential `o₁ ^ o₂`. -/
def opow (o₁ o₂ : ONote) : ONote := opowAux2 o₂ (split o₁)
instance : Pow ONote ONote :=
⟨opow⟩
theorem opow_def (o₁ o₂ : ONote) : o₁ ^ o₂ = opowAux2 o₂ (split o₁) :=
rfl
theorem split_eq_scale_split' : ∀ {o o' m} [NF o], split' o = (o', m) → split o = (scale 1 o', m)
| 0, o', m, _, p => by injection p; substs o' m; rfl
| oadd e n a, o', m, h, p => by
by_cases e0 : e = 0 <;> simp [e0, split, split'] at p ⊢
· rcases p with ⟨rfl, rfl⟩
exact ⟨rfl, rfl⟩
· revert p
cases' h' : split' a with a' m'
haveI := h.fst
haveI := h.snd
simp only [split_eq_scale_split' h', and_imp]
have : 1 + (e - 1) = e := by
refine repr_inj.1 ?_
simp only [repr_add, repr, opow_zero, Nat.succPNat_coe, Nat.cast_one, mul_one, add_zero,
repr_sub]
have := mt repr_inj.1 e0
refine Ordinal.add_sub_cancel_of_le ?_
have := one_le_iff_ne_zero.2 this
exact this
intros
substs o' m
simp [scale, this]
theorem nf_repr_split' : ∀ {o o' m} [NF o], split' o = (o', m) → NF o' ∧ repr o = ω * repr o' + m
| 0, o', m, _, p => by injection p; substs o' m; simp [NF.zero]
| oadd e n a, o', m, h, p => by
by_cases e0 : e = 0 <;> simp [e0, split, split'] at p ⊢
· rcases p with ⟨rfl, rfl⟩
simp [h.zero_of_zero e0, NF.zero]
· revert p
cases' h' : split' a with a' m'
haveI := h.fst
haveI := h.snd
cases' nf_repr_split' h' with IH₁ IH₂
simp only [IH₂, and_imp]
intros
substs o' m
have : (ω : Ordinal.{0}) ^ repr e = ω ^ (1 : Ordinal.{0}) * ω ^ (repr e - 1) := by
have := mt repr_inj.1 e0
rw [← opow_add, Ordinal.add_sub_cancel_of_le (one_le_iff_ne_zero.2 this)]
refine ⟨NF.oadd (by infer_instance) _ ?_, ?_⟩
· simp at this ⊢
refine
IH₁.below_of_lt'
((Ordinal.mul_lt_mul_iff_left omega_pos).1 <| lt_of_le_of_lt (le_add_right _ m') ?_)
rw [← this, ← IH₂]
exact h.snd'.repr_lt
· rw [this]
simp [mul_add, mul_assoc, add_assoc]
theorem scale_eq_mul (x) [NF x] : ∀ (o) [NF o], scale x o = oadd x 1 0 * o
| 0, _ => rfl
| oadd e n a, h => by
simp only [HMul.hMul]; simp only [scale]
haveI := h.snd
by_cases e0 : e = 0
· simp_rw [scale_eq_mul]
simp [Mul.mul, mul, scale_eq_mul, e0, h.zero_of_zero,
show x + 0 = x from repr_inj.1 (by simp)]
· simp [e0, Mul.mul, mul, scale_eq_mul, (· * ·)]
instance nf_scale (x) [NF x] (o) [NF o] : NF (scale x o) := by
rw [scale_eq_mul]
infer_instance
@[simp]
theorem repr_scale (x) [NF x] (o) [NF o] : repr (scale x o) = ω ^ repr x * repr o := by
simp only [scale_eq_mul, repr_mul, repr, PNat.one_coe, Nat.cast_one, mul_one, add_zero]
theorem nf_repr_split {o o' m} [NF o] (h : split o = (o', m)) : NF o' ∧ repr o = repr o' + m := by
cases' e : split' o with a n
cases' nf_repr_split' e with s₁ s₂
rw [split_eq_scale_split' e] at h
injection h; substs o' n
simp only [repr_scale, repr, opow_zero, Nat.succPNat_coe, Nat.cast_one, mul_one, add_zero,
opow_one, s₂.symm, and_true]
infer_instance
theorem split_dvd {o o' m} [NF o] (h : split o = (o', m)) : ω ∣ repr o' := by
cases' e : split' o with a n
rw [split_eq_scale_split' e] at h
injection h; subst o'
cases nf_repr_split' e; simp
theorem split_add_lt {o e n a m} [NF o] (h : split o = (oadd e n a, m)) :
repr a + m < ω ^ repr e := by
cases' nf_repr_split h with h₁ h₂
cases' h₁.of_dvd_omega (split_dvd h) with e0 d
apply principal_add_omega_opow _ h₁.snd'.repr_lt (lt_of_lt_of_le (nat_lt_omega _) _)
simpa using opow_le_opow_right omega_pos (one_le_iff_ne_zero.2 e0)
@[simp]
theorem mulNat_eq_mul (n o) : mulNat o n = o * ofNat n := by cases o <;> cases n <;> rfl
instance nf_mulNat (o) [NF o] (n) : NF (mulNat o n) := by simpa using ONote.mul_nf o (ofNat n)
instance nf_opowAux (e a0 a) [NF e] [NF a0] [NF a] : ∀ k m, NF (opowAux e a0 a k m) := by
intro k m
unfold opowAux
cases' m with m m
· cases k <;> exact NF.zero
cases' k with k k
· exact NF.oadd_zero _ _
· haveI := nf_opowAux e a0 a k
simp only [Nat.succ_ne_zero m, IsEmpty.forall_iff, mulNat_eq_mul]; infer_instance
instance nf_opow (o₁ o₂) [NF o₁] [NF o₂] : NF (o₁ ^ o₂) := by
cases' e₁ : split o₁ with a m
have na := (nf_repr_split e₁).1
cases' e₂ : split' o₂ with b' k
haveI := (nf_repr_split' e₂).1
cases' a with a0 n a'
· cases' m with m
· by_cases o₂ = 0 <;> simp only [(· ^ ·), Pow.pow, pow, opow, opowAux2, *] <;> decide
· by_cases m = 0
· simp only [(· ^ ·), Pow.pow, pow, opow, opowAux2, *, zero_def]
decide
· simp only [(· ^ ·), Pow.pow, pow, opow, opowAux2, mulNat_eq_mul, ofNat, *]
infer_instance
· simp [(· ^ ·),Pow.pow,pow, opow, opowAux2, e₁, e₂, split_eq_scale_split' e₂]
have := na.fst
cases' k with k <;> simp
· infer_instance
· cases k <;> cases m <;> infer_instance
theorem scale_opowAux (e a0 a : ONote) [NF e] [NF a0] [NF a] :
∀ k m, repr (opowAux e a0 a k m) = ω ^ repr e * repr (opowAux 0 a0 a k m)
| 0, m => by cases m <;> simp [opowAux]
| k + 1, m => by
by_cases h : m = 0
· simp [h, opowAux, mul_add, opow_add, mul_assoc, scale_opowAux _ _ _ k]
· -- Porting note: rewrote proof
rw [opowAux]; swap
· assumption
rw [opowAux]; swap
· assumption
rw [repr_add, repr_scale, scale_opowAux _ _ _ k]
simp only [repr_add, repr_scale, opow_add, mul_assoc, zero_add, mul_add]
theorem repr_opow_aux₁ {e a} [Ne : NF e] [Na : NF a] {a' : Ordinal} (e0 : repr e ≠ 0)
(h : a' < (ω : Ordinal.{0}) ^ repr e) (aa : repr a = a') (n : ℕ+) :
((ω : Ordinal.{0}) ^ repr e * (n : ℕ) + a') ^ (ω : Ordinal.{0}) =
(ω ^ repr e) ^ (ω : Ordinal.{0}) := by
subst aa
have No := Ne.oadd n (Na.below_of_lt' h)
have := omega_le_oadd e n a
rw [repr] at this
refine le_antisymm ?_ (opow_le_opow_left _ this)
apply (opow_le_of_limit ((opow_pos _ omega_pos).trans_le this).ne' omega_isLimit).2
intro b l
have := (No.below_of_lt (lt_succ _)).repr_lt
rw [repr] at this
apply (opow_le_opow_left b <| this.le).trans
rw [← opow_mul, ← opow_mul]
apply opow_le_opow_right omega_pos
rcases le_or_lt ω (repr e) with h | h
· apply (mul_le_mul_left' (le_succ b) _).trans
rw [← add_one_eq_succ, add_mul_succ _ (one_add_of_omega_le h), add_one_eq_succ, succ_le_iff,
Ordinal.mul_lt_mul_iff_left (Ordinal.pos_iff_ne_zero.2 e0)]
exact omega_isLimit.2 _ l
· apply (principal_mul_omega (omega_isLimit.2 _ h) l).le.trans
simpa using mul_le_mul_right' (one_le_iff_ne_zero.2 e0) ω
section
-- Porting note: `R'` is used in the proof but marked as an unused variable.
set_option linter.unusedVariables false in
theorem repr_opow_aux₂ {a0 a'} [N0 : NF a0] [Na' : NF a'] (m : ℕ) (d : ω ∣ repr a')
(e0 : repr a0 ≠ 0) (h : repr a' + m < (ω ^ repr a0)) (n : ℕ+) (k : ℕ) :
let R := repr (opowAux 0 a0 (oadd a0 n a' * ofNat m) k m)
(k ≠ 0 → R < ((ω ^ repr a0) ^ succ (k : Ordinal))) ∧
((ω ^ repr a0) ^ (k : Ordinal)) * ((ω ^ repr a0) * (n : ℕ) + repr a') + R =
((ω ^ repr a0) * (n : ℕ) + repr a' + m) ^ succ (k : Ordinal) := by
intro R'
haveI No : NF (oadd a0 n a') :=
N0.oadd n (Na'.below_of_lt' <| lt_of_le_of_lt (le_add_right _ _) h)
induction' k with k IH
· cases m <;> simp [R', opowAux]
-- rename R => R'
let R := repr (opowAux 0 a0 (oadd a0 n a' * ofNat m) k m)
let ω0 := ω ^ repr a0
let α' := ω0 * n + repr a'
change (k ≠ 0 → R < (ω0 ^ succ (k : Ordinal))) ∧ (ω0 ^ (k : Ordinal)) * α' + R
= (α' + m) ^ (succ ↑k : Ordinal) at IH
have RR : R' = ω0 ^ (k : Ordinal) * (α' * m) + R := by
by_cases h : m = 0
· simp only [R, R', h, ONote.ofNat, Nat.cast_zero, zero_add, ONote.repr, mul_zero,
ONote.opowAux, add_zero]
· simp only [R', ONote.repr_scale, ONote.repr, ONote.mulNat_eq_mul, ONote.opowAux,
ONote.repr_ofNat, ONote.repr_mul, ONote.repr_add, Ordinal.opow_mul, ONote.zero_add]
have α0 : 0 < α' := by simpa [lt_def, repr] using oadd_pos a0 n a'
have ω00 : 0 < ω0 ^ (k : Ordinal) := opow_pos _ (opow_pos _ omega_pos)
have Rl : R < ω ^ (repr a0 * succ ↑k) := by
by_cases k0 : k = 0
· simp only [k0, Nat.cast_zero, succ_zero, mul_one, R]
refine lt_of_lt_of_le ?_ (opow_le_opow_right omega_pos (one_le_iff_ne_zero.2 e0))
cases' m with m <;> simp [opowAux, omega_pos]
rw [← add_one_eq_succ, ← Nat.cast_succ]
apply nat_lt_omega
· rw [opow_mul]
exact IH.1 k0
refine ⟨fun _ => ?_, ?_⟩
· rw [RR, ← opow_mul _ _ (succ k.succ)]
have e0 := Ordinal.pos_iff_ne_zero.2 e0
have rr0 : 0 < repr a0 + repr a0 := lt_of_lt_of_le e0 (le_add_left _ _)
apply principal_add_omega_opow
· simp [opow_mul, opow_add, mul_assoc]
rw [Ordinal.mul_lt_mul_iff_left ω00, ← Ordinal.opow_add]
have : _ < ω ^ (repr a0 + repr a0) := (No.below_of_lt ?_).repr_lt
· exact mul_lt_omega_opow rr0 this (nat_lt_omega _)
· simpa using (add_lt_add_iff_left (repr a0)).2 e0
· exact
lt_of_lt_of_le Rl
(opow_le_opow_right omega_pos <|
mul_le_mul_left' (succ_le_succ_iff.2 (natCast_le.2 (le_of_lt k.lt_succ_self))) _)
calc
(ω0 ^ (k.succ : Ordinal)) * α' + R'
_ = (ω0 ^ succ (k : Ordinal)) * α' + ((ω0 ^ (k : Ordinal)) * α' * m + R) := by
rw [natCast_succ, RR, ← mul_assoc]
_ = ((ω0 ^ (k : Ordinal)) * α' + R) * α' + ((ω0 ^ (k : Ordinal)) * α' + R) * m := ?_
_ = (α' + m) ^ succ (k.succ : Ordinal) := by rw [← mul_add, natCast_succ, opow_succ, IH.2]
congr 1
· have αd : ω ∣ α' :=
dvd_add (dvd_mul_of_dvd_left (by simpa using opow_dvd_opow ω (one_le_iff_ne_zero.2 e0)) _) d
rw [mul_add (ω0 ^ (k : Ordinal)), add_assoc, ← mul_assoc, ← opow_succ,
add_mul_limit _ (isLimit_iff_omega_dvd.2 ⟨ne_of_gt α0, αd⟩), mul_assoc,
@mul_omega_dvd n (natCast_pos.2 n.pos) (nat_lt_omega _) _ αd]
apply @add_absorp _ (repr a0 * succ ↑k)
· refine principal_add_omega_opow _ ?_ Rl
rw [opow_mul, opow_succ, Ordinal.mul_lt_mul_iff_left ω00]
exact No.snd'.repr_lt
· have := mul_le_mul_left' (one_le_iff_pos.2 <| natCast_pos.2 n.pos) (ω0 ^ succ (k : Ordinal))
rw [opow_mul]
simpa [-opow_succ]
· cases m
· have : R = 0 := by cases k <;> simp [R, opowAux]
simp [this]
· rw [natCast_succ, add_mul_succ]
apply add_absorp Rl
rw [opow_mul, opow_succ]
apply mul_le_mul_left'
simpa [repr] using omega_le_oadd a0 n a'
end
theorem repr_opow (o₁ o₂) [NF o₁] [NF o₂] : repr (o₁ ^ o₂) = repr o₁ ^ repr o₂ := by
cases' e₁ : split o₁ with a m
cases' nf_repr_split e₁ with N₁ r₁
cases' a with a0 n a'
· cases' m with m
· by_cases h : o₂ = 0 <;> simp [opow_def, opowAux2, opow, e₁, h, r₁]
have := mt repr_inj.1 h
rw [zero_opow this]
· cases' e₂ : split' o₂ with b' k
cases' nf_repr_split' e₂ with _ r₂
by_cases h : m = 0
· simp [opow_def, opow, e₁, h, r₁, e₂, r₂, ← Nat.one_eq_succ_zero]
simp only [opow_def, opowAux2, opow, e₁, h, r₁, e₂, r₂, repr,
opow_zero, Nat.succPNat_coe, Nat.cast_succ, Nat.cast_zero, _root_.zero_add, mul_one,
add_zero, one_opow, npow_eq_pow]
rw [opow_add, opow_mul, opow_omega, add_one_eq_succ]
· congr
conv_lhs =>
dsimp [(· ^ ·)]
simp [Pow.pow, opow, Ordinal.succ_ne_zero]
· simpa [Nat.one_le_iff_ne_zero]
· rw [← Nat.cast_succ, lt_omega]
exact ⟨_, rfl⟩
· haveI := N₁.fst
haveI := N₁.snd
cases' N₁.of_dvd_omega (split_dvd e₁) with a00 ad
have al := split_add_lt e₁
have aa : repr (a' + ofNat m) = repr a' + m := by
simp only [eq_self_iff_true, ONote.repr_ofNat, ONote.repr_add]
cases' e₂ : split' o₂ with b' k
cases' nf_repr_split' e₂ with _ r₂
simp only [opow_def, opow, e₁, r₁, split_eq_scale_split' e₂, opowAux2, repr]
cases' k with k
· simp [r₂, opow_mul, repr_opow_aux₁ a00 al aa, add_assoc]
· simp? [r₂, opow_add, opow_mul, mul_assoc, add_assoc, -repr] says
simp only [mulNat_eq_mul, repr_add, repr_scale, repr_mul, repr_ofNat, opow_add, opow_mul,
mul_assoc, add_assoc, r₂, Nat.cast_add, Nat.cast_one, add_one_eq_succ, opow_succ]
simp only [repr, opow_zero, Nat.succPNat_coe, Nat.cast_one, mul_one, add_zero, opow_one]
rw [repr_opow_aux₁ a00 al aa, scale_opowAux]
simp only [repr_mul, repr_scale, repr, opow_zero, Nat.succPNat_coe, Nat.cast_one, mul_one,
add_zero, opow_one, opow_mul]
rw [← mul_add, ← add_assoc ((ω : Ordinal.{0}) ^ repr a0 * (n : ℕ))]
congr 1
rw [← opow_succ]
exact (repr_opow_aux₂ _ ad a00 al _ _).2
/-- Given an ordinal, returns `inl none` for `0`, `inl (some a)` for `a+1`, and
`inr f` for a limit ordinal `a`, where `f i` is a sequence converging to `a`. -/
def fundamentalSequence : ONote → (Option ONote) ⊕ (ℕ → ONote)
| zero => Sum.inl none
| oadd a m b =>
match fundamentalSequence b with
| Sum.inr f => Sum.inr fun i => oadd a m (f i)
| Sum.inl (some b') => Sum.inl (some (oadd a m b'))
| Sum.inl none =>
match fundamentalSequence a, m.natPred with
| Sum.inl none, 0 => Sum.inl (some zero)
| Sum.inl none, m + 1 => Sum.inl (some (oadd zero m.succPNat zero))
| Sum.inl (some a'), 0 => Sum.inr fun i => oadd a' i.succPNat zero
| Sum.inl (some a'), m + 1 => Sum.inr fun i => oadd a m.succPNat (oadd a' i.succPNat zero)
| Sum.inr f, 0 => Sum.inr fun i => oadd (f i) 1 zero
| Sum.inr f, m + 1 => Sum.inr fun i => oadd a m.succPNat (oadd (f i) 1 zero)
private theorem exists_lt_add {α} [hα : Nonempty α] {o : Ordinal} {f : α → Ordinal}
(H : ∀ ⦃a⦄, a < o → ∃ i, a < f i) {b : Ordinal} ⦃a⦄ (h : a < b + o) : ∃ i, a < b + f i := by
cases' lt_or_le a b with h h'
· obtain ⟨i⟩ := id hα
exact ⟨i, h.trans_le (le_add_right _ _)⟩
· rw [← Ordinal.add_sub_cancel_of_le h', add_lt_add_iff_left] at h
refine (H h).imp fun i H => ?_
rwa [← Ordinal.add_sub_cancel_of_le h', add_lt_add_iff_left]
private theorem exists_lt_mul_omega' {o : Ordinal} ⦃a⦄ (h : a < o * ω) :
∃ i : ℕ, a < o * ↑i + o := by
obtain ⟨i, hi, h'⟩ := (lt_mul_of_limit omega_isLimit).1 h
obtain ⟨i, rfl⟩ := lt_omega.1 hi
exact ⟨i, h'.trans_le (le_add_right _ _)⟩
private theorem exists_lt_omega_opow' {α} {o b : Ordinal} (hb : 1 < b) (ho : o.IsLimit)
{f : α → Ordinal} (H : ∀ ⦃a⦄, a < o → ∃ i, a < f i) ⦃a⦄ (h : a < b ^ o) :
∃ i, a < b ^ f i := by
obtain ⟨d, hd, h'⟩ := (lt_opow_of_limit (zero_lt_one.trans hb).ne' ho).1 h
exact (H hd).imp fun i hi => h'.trans <| (opow_lt_opow_iff_right hb).2 hi
/-- The property satisfied by `fundamentalSequence o`:
* `inl none` means `o = 0`
* `inl (some a)` means `o = succ a`
* `inr f` means `o` is a limit ordinal and `f` is a
strictly increasing sequence which converges to `o` -/
def FundamentalSequenceProp (o : ONote) : (Option ONote) ⊕ (ℕ → ONote) → Prop
| Sum.inl none => o = 0
| Sum.inl (some a) => o.repr = succ a.repr ∧ (o.NF → a.NF)
| Sum.inr f =>
o.repr.IsLimit ∧
(∀ i, f i < f (i + 1) ∧ f i < o ∧ (o.NF → (f i).NF)) ∧ ∀ a, a < o.repr → ∃ i, a < (f i).repr
theorem fundamentalSequenceProp_inl_none (o) :
FundamentalSequenceProp o (Sum.inl none) ↔ o = 0 :=
Iff.rfl
theorem fundamentalSequenceProp_inl_some (o a) :
FundamentalSequenceProp o (Sum.inl (some a)) ↔ o.repr = succ a.repr ∧ (o.NF → a.NF) :=
Iff.rfl
theorem fundamentalSequenceProp_inr (o f) :
FundamentalSequenceProp o (Sum.inr f) ↔
o.repr.IsLimit ∧
(∀ i, f i < f (i + 1) ∧ f i < o ∧ (o.NF → (f i).NF)) ∧
∀ a, a < o.repr → ∃ i, a < (f i).repr :=
Iff.rfl
attribute
[eqns
fundamentalSequenceProp_inl_none
fundamentalSequenceProp_inl_some
fundamentalSequenceProp_inr]
FundamentalSequenceProp
theorem fundamentalSequence_has_prop (o) : FundamentalSequenceProp o (fundamentalSequence o) := by
induction' o with a m b iha ihb; · exact rfl
rw [fundamentalSequence]
rcases e : b.fundamentalSequence with (⟨_ | b'⟩ | f) <;>
simp only [FundamentalSequenceProp] <;>
rw [e, FundamentalSequenceProp] at ihb
· rcases e : a.fundamentalSequence with (⟨_ | a'⟩ | f) <;> cases' e' : m.natPred with m' <;>
simp only [FundamentalSequenceProp] <;>
rw [e, FundamentalSequenceProp] at iha <;>
(try rw [show m = 1 by
have := PNat.natPred_add_one m; rw [e'] at this; exact PNat.coe_inj.1 this.symm]) <;>
(try rw [show m = (m' + 1).succPNat by
rw [← e', ← PNat.coe_inj, Nat.succPNat_coe, ← Nat.add_one, PNat.natPred_add_one]]) <;>
simp only [repr, iha, ihb, opow_lt_opow_iff_right one_lt_omega, add_lt_add_iff_left, add_zero,
eq_self_iff_true, lt_add_iff_pos_right, lt_def, mul_one, Nat.cast_zero, Nat.cast_succ,
Nat.succPNat_coe, opow_succ, opow_zero, mul_add_one, PNat.one_coe, succ_zero,
true_and_iff, _root_.zero_add, zero_def]
· decide
· exact ⟨rfl, inferInstance⟩
· have := opow_pos (repr a') omega_pos
refine
⟨mul_isLimit this omega_isLimit, fun i =>
⟨this, ?_, fun H => @NF.oadd_zero _ _ (iha.2 H.fst)⟩, exists_lt_mul_omega'⟩
rw [← mul_succ, ← natCast_succ, Ordinal.mul_lt_mul_iff_left this]
apply nat_lt_omega
· have := opow_pos (repr a') omega_pos
refine
⟨add_isLimit _ (mul_isLimit this omega_isLimit), fun i => ⟨this, ?_, ?_⟩,
exists_lt_add exists_lt_mul_omega'⟩
· rw [← mul_succ, ← natCast_succ, Ordinal.mul_lt_mul_iff_left this]
apply nat_lt_omega
· refine fun H => H.fst.oadd _ (NF.below_of_lt' ?_ (@NF.oadd_zero _ _ (iha.2 H.fst)))
rw [repr, ← zero_def, repr, add_zero, iha.1, opow_succ, Ordinal.mul_lt_mul_iff_left this]
apply nat_lt_omega
· rcases iha with ⟨h1, h2, h3⟩
refine ⟨opow_isLimit one_lt_omega h1, fun i => ?_, exists_lt_omega_opow' one_lt_omega h1 h3⟩
obtain ⟨h4, h5, h6⟩ := h2 i
exact ⟨h4, h5, fun H => @NF.oadd_zero _ _ (h6 H.fst)⟩
· rcases iha with ⟨h1, h2, h3⟩
refine
⟨add_isLimit _ (opow_isLimit one_lt_omega h1), fun i => ?_,
exists_lt_add (exists_lt_omega_opow' one_lt_omega h1 h3)⟩
obtain ⟨h4, h5, h6⟩ := h2 i
refine ⟨h4, h5, fun H => H.fst.oadd _ (NF.below_of_lt' ?_ (@NF.oadd_zero _ _ (h6 H.fst)))⟩
rwa [repr, ← zero_def, repr, add_zero, PNat.one_coe, Nat.cast_one, mul_one,
opow_lt_opow_iff_right one_lt_omega]
· refine ⟨by
rw [repr, ihb.1, add_succ, repr], fun H => H.fst.oadd _ (NF.below_of_lt' ?_ (ihb.2 H.snd))⟩
have := H.snd'.repr_lt
rw [ihb.1] at this
exact (lt_succ _).trans this
· rcases ihb with ⟨h1, h2, h3⟩
simp only [repr]
exact
⟨Ordinal.add_isLimit _ h1, fun i =>
⟨oadd_lt_oadd_3 (h2 i).1, oadd_lt_oadd_3 (h2 i).2.1, fun H =>
H.fst.oadd _ (NF.below_of_lt' (lt_trans (h2 i).2.1 H.snd'.repr_lt) ((h2 i).2.2 H.snd))⟩,
exists_lt_add h3⟩
/-- The fast growing hierarchy for ordinal notations `< ε₀`. This is a sequence of
functions `ℕ → ℕ` indexed by ordinals, with the definition:
* `f_0(n) = n + 1`
* `f_(α+1)(n) = f_α^[n](n)`
* `f_α(n) = f_(α[n])(n)` where `α` is a limit ordinal
and `α[i]` is the fundamental sequence converging to `α` -/
def fastGrowing : ONote → ℕ → ℕ
| o =>
match fundamentalSequence o, fundamentalSequence_has_prop o with
| Sum.inl none, _ => Nat.succ
| Sum.inl (some a), h =>
have : a < o := by rw [lt_def, h.1]; apply lt_succ
fun i => (fastGrowing a)^[i] i
| Sum.inr f, h => fun i =>
have : f i < o := (h.2.1 i).2.1
fastGrowing (f i) i
termination_by o => o
-- Porting note: the bug of the linter, should be fixed.
@[nolint unusedHavesSuffices]
theorem fastGrowing_def {o : ONote} {x} (e : fundamentalSequence o = x) :
fastGrowing o =
match
(motive := (x : Option ONote ⊕ (ℕ → ONote)) → FundamentalSequenceProp o x → ℕ → ℕ)
x, e ▸ fundamentalSequence_has_prop o with
| Sum.inl none, _ => Nat.succ
| Sum.inl (some a), _ =>
fun i => (fastGrowing a)^[i] i
| Sum.inr f, _ => fun i =>
fastGrowing (f i) i := by
subst x
rw [fastGrowing]
theorem fastGrowing_zero' (o : ONote) (h : fundamentalSequence o = Sum.inl none) :
fastGrowing o = Nat.succ := by
rw [fastGrowing_def h]
theorem fastGrowing_succ (o) {a} (h : fundamentalSequence o = Sum.inl (some a)) :
fastGrowing o = fun i => (fastGrowing a)^[i] i := by
rw [fastGrowing_def h]
theorem fastGrowing_limit (o) {f} (h : fundamentalSequence o = Sum.inr f) :
fastGrowing o = fun i => fastGrowing (f i) i := by
rw [fastGrowing_def h]
@[simp]
theorem fastGrowing_zero : fastGrowing 0 = Nat.succ :=
fastGrowing_zero' _ rfl
@[simp]
theorem fastGrowing_one : fastGrowing 1 = fun n => 2 * n := by
rw [@fastGrowing_succ 1 0 rfl]; funext i; rw [two_mul, fastGrowing_zero]
suffices ∀ a b, Nat.succ^[a] b = b + a from this _ _
intro a b; induction a <;> simp [*, Function.iterate_succ', Nat.add_assoc, -Function.iterate_succ]
section
@[simp]
theorem fastGrowing_two : fastGrowing 2 = fun n => (2 ^ n) * n := by
rw [@fastGrowing_succ 2 1 rfl]; funext i; rw [fastGrowing_one]
suffices ∀ a b, (fun n : ℕ => 2 * n)^[a] b = (2 ^ a) * b from this _ _
intro a b; induction a <;>
simp [*, Function.iterate_succ, pow_succ, mul_assoc, -Function.iterate_succ]
end
/-- We can extend the fast growing hierarchy one more step to `ε₀` itself,
using `ω^(ω^...^ω^0)` as the fundamental sequence converging to `ε₀` (which is not an `ONote`).
Extending the fast growing hierarchy beyond this requires a definition of fundamental sequence
for larger ordinals. -/
def fastGrowingε₀ (i : ℕ) : ℕ :=
fastGrowing ((fun a => a.oadd 1 0)^[i] 0) i
theorem fastGrowingε₀_zero : fastGrowingε₀ 0 = 1 := by simp [fastGrowingε₀]
theorem fastGrowingε₀_one : fastGrowingε₀ 1 = 2 := by
simp [fastGrowingε₀, show oadd 0 1 0 = 1 from rfl]
theorem fastGrowingε₀_two : fastGrowingε₀ 2 = 2048 := by
norm_num [fastGrowingε₀, show oadd 0 1 0 = 1 from rfl, @fastGrowing_limit (oadd 1 1 0) _ rfl,
show oadd 0 (2 : Nat).succPNat 0 = 3 from rfl, @fastGrowing_succ 3 2 rfl]
end ONote
/-- The type of normal ordinal notations. (It would have been
nicer to define this right in the inductive type, but `NF o`
requires `repr` which requires `ONote`, so all these things
would have to be defined at once, which messes up the VM
representation.) -/
def NONote :=
{ o : ONote // o.NF }
instance : DecidableEq NONote := by unfold NONote; infer_instance
namespace NONote
open ONote
instance NF (o : NONote) : NF o.1 :=
o.2
/-- Construct a `NONote` from an ordinal notation
(and infer normality) -/
def mk (o : ONote) [h : ONote.NF o] : NONote :=
⟨o, h⟩
/-- The ordinal represented by an ordinal notation.
(This function is noncomputable because ordinal
arithmetic is noncomputable. In computational applications
`NONote` can be used exclusively without reference
to `Ordinal`, but this function allows for correctness
results to be stated.) -/
noncomputable def repr (o : NONote) : Ordinal :=
o.1.repr
instance : ToString NONote :=
⟨fun x => x.1.toString⟩
instance : Repr NONote :=
⟨fun x prec => x.1.repr' prec⟩
instance : Preorder NONote where
le x y := repr x ≤ repr y
lt x y := repr x < repr y
le_refl _ := @le_refl Ordinal _ _
le_trans _ _ _ := @le_trans Ordinal _ _ _ _
lt_iff_le_not_le _ _ := @lt_iff_le_not_le Ordinal _ _ _
instance : Zero NONote :=
⟨⟨0, NF.zero⟩⟩
instance : Inhabited NONote :=
⟨0⟩
theorem lt_wf : @WellFounded NONote (· < ·) :=
InvImage.wf repr Ordinal.lt_wf
instance : WellFoundedLT NONote :=
⟨lt_wf⟩
instance : WellFoundedRelation NONote :=
⟨(· < ·), lt_wf⟩
/-- Convert a natural number to an ordinal notation -/
def ofNat (n : ℕ) : NONote :=
⟨ONote.ofNat n, ⟨⟨_, nfBelow_ofNat _⟩⟩⟩
/-- Compare ordinal notations -/
def cmp (a b : NONote) : Ordering :=
ONote.cmp a.1 b.1
theorem cmp_compares : ∀ a b : NONote, (cmp a b).Compares a b
| ⟨a, ha⟩, ⟨b, hb⟩ => by
dsimp [cmp]
have := ONote.cmp_compares a b
cases h : ONote.cmp a b <;> simp only [h] at this <;> try exact this
exact Subtype.mk_eq_mk.2 this
instance : LinearOrder NONote :=
linearOrderOfCompares cmp cmp_compares
instance : IsWellOrder NONote (· < ·) where
/-- Asserts that `repr a < ω ^ repr b`. Used in `NONote.recOn` -/
def below (a b : NONote) : Prop :=
NFBelow a.1 (repr b)
/-- The `oadd` pseudo-constructor for `NONote` -/
def oadd (e : NONote) (n : ℕ+) (a : NONote) (h : below a e) : NONote :=
⟨_, NF.oadd e.2 n h⟩
/-- This is a recursor-like theorem for `NONote` suggesting an
inductive definition, which can't actually be defined this
way due to conflicting dependencies. -/
@[elab_as_elim]
def recOn {C : NONote → Sort*} (o : NONote) (H0 : C 0)
(H1 : ∀ e n a h, C e → C a → C (oadd e n a h)) : C o := by
cases' o with o h; induction' o with e n a IHe IHa
· exact H0
· exact H1 ⟨e, h.fst⟩ n ⟨a, h.snd⟩ h.snd' (IHe _) (IHa _)
/-- Addition of ordinal notations -/
instance : Add NONote :=
⟨fun x y => mk (x.1 + y.1)⟩
theorem repr_add (a b) : repr (a + b) = repr a + repr b :=
ONote.repr_add a.1 b.1
/-- Subtraction of ordinal notations -/
instance : Sub NONote :=
⟨fun x y => mk (x.1 - y.1)⟩
theorem repr_sub (a b) : repr (a - b) = repr a - repr b :=
ONote.repr_sub a.1 b.1
/-- Multiplication of ordinal notations -/
instance : Mul NONote :=
⟨fun x y => mk (x.1 * y.1)⟩
theorem repr_mul (a b) : repr (a * b) = repr a * repr b :=
ONote.repr_mul a.1 b.1
/-- Exponentiation of ordinal notations -/
def opow (x y : NONote) :=
mk (x.1 ^ y.1)
theorem repr_opow (a b) : repr (opow a b) = repr a ^ repr b :=
ONote.repr_opow a.1 b.1
end NONote
|
SetTheory\Ordinal\Principal.lean | /-
Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Violeta Hernández Palacios
-/
import Mathlib.SetTheory.Ordinal.FixedPoint
/-!
# Principal ordinals
We define principal or indecomposable ordinals, and we prove the standard properties about them.
## Main definitions and results
* `Principal`: A principal or indecomposable ordinal under some binary operation. We include 0 and
any other typically excluded edge cases for simplicity.
* `unbounded_principal`: Principal ordinals are unbounded.
* `principal_add_iff_zero_or_omega_opow`: The main characterization theorem for additive principal
ordinals.
* `principal_mul_iff_le_two_or_omega_opow_opow`: The main characterization theorem for
multiplicative principal ordinals.
## TODO
* Prove that exponential principal ordinals are 0, 1, 2, ω, or epsilon numbers, i.e. fixed points
of `fun x ↦ ω ^ x`.
-/
universe u v w
noncomputable section
open Order
namespace Ordinal
-- Porting note: commented out, doesn't seem necessary
--local infixr:0 "^" => @pow Ordinal Ordinal Ordinal.hasPow
/-! ### Principal ordinals -/
/-- An ordinal `o` is said to be principal or indecomposable under an operation when the set of
ordinals less than it is closed under that operation. In standard mathematical usage, this term is
almost exclusively used for additive and multiplicative principal ordinals.
For simplicity, we break usual convention and regard 0 as principal. -/
def Principal (op : Ordinal → Ordinal → Ordinal) (o : Ordinal) : Prop :=
∀ ⦃a b⦄, a < o → b < o → op a b < o
theorem principal_iff_principal_swap {op : Ordinal → Ordinal → Ordinal} {o : Ordinal} :
Principal op o ↔ Principal (Function.swap op) o := by
constructor <;> exact fun h a b ha hb => h hb ha
theorem principal_zero {op : Ordinal → Ordinal → Ordinal} : Principal op 0 := fun a _ h =>
(Ordinal.not_lt_zero a h).elim
@[simp]
theorem principal_one_iff {op : Ordinal → Ordinal → Ordinal} : Principal op 1 ↔ op 0 0 = 0 := by
refine ⟨fun h => ?_, fun h a b ha hb => ?_⟩
· rw [← lt_one_iff_zero]
exact h zero_lt_one zero_lt_one
· rwa [lt_one_iff_zero, ha, hb] at *
theorem Principal.iterate_lt {op : Ordinal → Ordinal → Ordinal} {a o : Ordinal} (hao : a < o)
(ho : Principal op o) (n : ℕ) : (op a)^[n] a < o := by
induction' n with n hn
· rwa [Function.iterate_zero]
· rw [Function.iterate_succ']
exact ho hao hn
theorem op_eq_self_of_principal {op : Ordinal → Ordinal → Ordinal} {a o : Ordinal.{u}} (hao : a < o)
(H : IsNormal (op a)) (ho : Principal op o) (ho' : IsLimit o) : op a o = o := by
refine le_antisymm ?_ (H.self_le _)
rw [← IsNormal.bsup_eq.{u, u} H ho', bsup_le_iff]
exact fun b hbo => (ho hao hbo).le
theorem nfp_le_of_principal {op : Ordinal → Ordinal → Ordinal} {a o : Ordinal} (hao : a < o)
(ho : Principal op o) : nfp (op a) a ≤ o :=
nfp_le fun n => (ho.iterate_lt hao n).le
/-! ### Principal ordinals are unbounded -/
#adaptation_note /-- 2024-04-23
After https://github.com/leanprover/lean4/pull/3965,
we need to write `lt_blsub₂.{u}` twice below,
where previously the universe annotation was not necessary.
This appears to be correct behaviour, as `lt_blsub₂.{0}` also works. -/
theorem principal_nfp_blsub₂ (op : Ordinal → Ordinal → Ordinal) (o : Ordinal) :
Principal op (nfp (fun o' => blsub₂.{u, u, u} o' o' (@fun a _ b _ => op a b)) o) :=
fun a b ha hb => by
rw [lt_nfp] at *
cases' ha with m hm
cases' hb with n hn
cases' le_total
((fun o' => blsub₂.{u, u, u} o' o' (@fun a _ b _ => op a b))^[m] o)
((fun o' => blsub₂.{u, u, u} o' o' (@fun a _ b _ => op a b))^[n] o) with h h
· use n + 1
rw [Function.iterate_succ']
exact lt_blsub₂.{u} (@fun a _ b _ => op a b) (hm.trans_le h) hn
· use m + 1
rw [Function.iterate_succ']
exact lt_blsub₂.{u} (@fun a _ b _ => op a b) hm (hn.trans_le h)
theorem unbounded_principal (op : Ordinal → Ordinal → Ordinal) :
Set.Unbounded (· < ·) { o | Principal op o } := fun o =>
⟨_, principal_nfp_blsub₂ op o, (le_nfp _ o).not_lt⟩
/-! #### Additive principal ordinals -/
theorem principal_add_one : Principal (· + ·) 1 :=
principal_one_iff.2 <| zero_add 0
theorem principal_add_of_le_one {o : Ordinal} (ho : o ≤ 1) : Principal (· + ·) o := by
rcases le_one_iff.1 ho with (rfl | rfl)
· exact principal_zero
· exact principal_add_one
theorem principal_add_isLimit {o : Ordinal} (ho₁ : 1 < o) (ho : Principal (· + ·) o) :
o.IsLimit := by
refine ⟨fun ho₀ => ?_, fun a hao => ?_⟩
· rw [ho₀] at ho₁
exact not_lt_of_gt zero_lt_one ho₁
· rcases eq_or_ne a 0 with ha | ha
· rw [ha, succ_zero]
exact ho₁
· refine lt_of_le_of_lt ?_ (ho hao hao)
rwa [← add_one_eq_succ, add_le_add_iff_left, one_le_iff_ne_zero]
theorem principal_add_iff_add_left_eq_self {o : Ordinal} :
Principal (· + ·) o ↔ ∀ a < o, a + o = o := by
refine ⟨fun ho a hao => ?_, fun h a b hao hbo => ?_⟩
· cases' lt_or_le 1 o with ho₁ ho₁
· exact op_eq_self_of_principal hao (add_isNormal a) ho (principal_add_isLimit ho₁ ho)
· rcases le_one_iff.1 ho₁ with (rfl | rfl)
· exact (Ordinal.not_lt_zero a hao).elim
· rw [lt_one_iff_zero] at hao
rw [hao, zero_add]
· rw [← h a hao]
exact (add_isNormal a).strictMono hbo
theorem exists_lt_add_of_not_principal_add {a} (ha : ¬Principal (· + ·) a) :
∃ b c, b < a ∧ c < a ∧ b + c = a := by
unfold Principal at ha
push_neg at ha
rcases ha with ⟨b, c, hb, hc, H⟩
refine
⟨b, _, hb, lt_of_le_of_ne (sub_le_self a b) fun hab => ?_, Ordinal.add_sub_cancel_of_le hb.le⟩
rw [← sub_le, hab] at H
exact H.not_lt hc
theorem principal_add_iff_add_lt_ne_self {a} :
Principal (· + ·) a ↔ ∀ ⦃b c⦄, b < a → c < a → b + c ≠ a :=
⟨fun ha b c hb hc => (ha hb hc).ne, fun H => by
by_contra! ha
rcases exists_lt_add_of_not_principal_add ha with ⟨b, c, hb, hc, rfl⟩
exact (H hb hc).irrefl⟩
theorem add_omega {a : Ordinal} (h : a < omega) : a + omega = omega := by
rcases lt_omega.1 h with ⟨n, rfl⟩
clear h; induction' n with n IH
· rw [Nat.cast_zero, zero_add]
· rwa [Nat.cast_succ, add_assoc, one_add_of_omega_le (le_refl _)]
theorem principal_add_omega : Principal (· + ·) omega :=
principal_add_iff_add_left_eq_self.2 fun _ => add_omega
theorem add_omega_opow {a b : Ordinal} (h : a < (omega^b)) : a + (omega^b) = (omega^b) := by
refine le_antisymm ?_ (le_add_left _ _)
induction' b using limitRecOn with b _ b l IH
· rw [opow_zero, ← succ_zero, lt_succ_iff, Ordinal.le_zero] at h
rw [h, zero_add]
· rw [opow_succ] at h
rcases (lt_mul_of_limit omega_isLimit).1 h with ⟨x, xo, ax⟩
refine le_trans (add_le_add_right (le_of_lt ax) _) ?_
rw [opow_succ, ← mul_add, add_omega xo]
· rcases (lt_opow_of_limit omega_ne_zero l).1 h with ⟨x, xb, ax⟩
exact
(((add_isNormal a).trans (opow_isNormal one_lt_omega)).limit_le l).2 fun y yb =>
(add_le_add_left (opow_le_opow_right omega_pos (le_max_right _ _)) _).trans
(le_trans
(IH _ (max_lt xb yb) (ax.trans_le <| opow_le_opow_right omega_pos (le_max_left _ _)))
(opow_le_opow_right omega_pos <| le_of_lt <| max_lt xb yb))
theorem principal_add_omega_opow (o : Ordinal) : Principal (· + ·) (omega^o) :=
principal_add_iff_add_left_eq_self.2 fun _ => add_omega_opow
/-- The main characterization theorem for additive principal ordinals. -/
theorem principal_add_iff_zero_or_omega_opow {o : Ordinal} :
Principal (· + ·) o ↔ o = 0 ∨ ∃ a : Ordinal, o = (omega^a) := by
rcases eq_or_ne o 0 with (rfl | ho)
· simp only [principal_zero, Or.inl]
· rw [principal_add_iff_add_left_eq_self]
simp only [ho, false_or_iff]
refine
⟨fun H => ⟨_, ((lt_or_eq_of_le (opow_log_le_self _ ho)).resolve_left fun h => ?_).symm⟩,
fun ⟨b, e⟩ => e.symm ▸ fun a => add_omega_opow⟩
have := H _ h
have := lt_opow_succ_log_self one_lt_omega o
rw [opow_succ, lt_mul_of_limit omega_isLimit] at this
rcases this with ⟨a, ao, h'⟩
rcases lt_omega.1 ao with ⟨n, rfl⟩
clear ao
revert h'
apply not_lt_of_le
suffices e : (omega^log omega o) * ↑n + o = o by
simpa only [e] using le_add_right ((omega^log omega o) * ↑n) o
induction' n with n IH
· simp [Nat.cast_zero, mul_zero, zero_add]
simp only [Nat.cast_succ, mul_add_one, add_assoc, this, IH]
theorem opow_principal_add_of_principal_add {a} (ha : Principal (· + ·) a) (b : Ordinal) :
Principal (· + ·) (a^b) := by
rcases principal_add_iff_zero_or_omega_opow.1 ha with (rfl | ⟨c, rfl⟩)
· rcases eq_or_ne b 0 with (rfl | hb)
· rw [opow_zero]
exact principal_add_one
· rwa [zero_opow hb]
· rw [← opow_mul]
exact principal_add_omega_opow _
theorem add_absorp {a b c : Ordinal} (h₁ : a < (omega^b)) (h₂ : (omega^b) ≤ c) : a + c = c := by
rw [← Ordinal.add_sub_cancel_of_le h₂, ← add_assoc, add_omega_opow h₁]
theorem mul_principal_add_is_principal_add (a : Ordinal.{u}) {b : Ordinal.{u}} (hb₁ : b ≠ 1)
(hb : Principal (· + ·) b) : Principal (· + ·) (a * b) := by
rcases eq_zero_or_pos a with (rfl | _)
· rw [zero_mul]
exact principal_zero
· rcases eq_zero_or_pos b with (rfl | hb₁')
· rw [mul_zero]
exact principal_zero
· rw [← succ_le_iff, succ_zero] at hb₁'
intro c d hc hd
rw [lt_mul_of_limit (principal_add_isLimit (lt_of_le_of_ne hb₁' hb₁.symm) hb)] at *
rcases hc with ⟨x, hx, hx'⟩
rcases hd with ⟨y, hy, hy'⟩
use x + y, hb hx hy
rw [mul_add]
exact Left.add_lt_add hx' hy'
/-! #### Multiplicative principal ordinals -/
theorem principal_mul_one : Principal (· * ·) 1 := by
rw [principal_one_iff]
exact zero_mul _
theorem principal_mul_two : Principal (· * ·) 2 := fun a b ha hb => by
have h₂ : succ (1 : Ordinal) = 2 := by simp
dsimp only
rw [← h₂, lt_succ_iff] at ha hb ⊢
convert mul_le_mul' ha hb
exact (mul_one 1).symm
theorem principal_mul_of_le_two {o : Ordinal} (ho : o ≤ 2) : Principal (· * ·) o := by
rcases lt_or_eq_of_le ho with (ho | rfl)
· have h₂ : succ (1 : Ordinal) = 2 := by simp
rw [← h₂, lt_succ_iff] at ho
rcases lt_or_eq_of_le ho with (ho | rfl)
· rw [lt_one_iff_zero.1 ho]
exact principal_zero
· exact principal_mul_one
· exact principal_mul_two
theorem principal_add_of_principal_mul {o : Ordinal} (ho : Principal (· * ·) o) (ho₂ : o ≠ 2) :
Principal (· + ·) o := by
cases' lt_or_gt_of_ne ho₂ with ho₁ ho₂
· replace ho₁ : o < succ 1 := by simpa using ho₁
rw [lt_succ_iff] at ho₁
exact principal_add_of_le_one ho₁
· refine fun a b hao hbo => lt_of_le_of_lt ?_ (ho (max_lt hao hbo) ho₂)
dsimp only
rw [← one_add_one_eq_two, mul_add, mul_one]
exact add_le_add (le_max_left a b) (le_max_right a b)
theorem principal_mul_isLimit {o : Ordinal.{u}} (ho₂ : 2 < o) (ho : Principal (· * ·) o) :
o.IsLimit :=
principal_add_isLimit ((lt_succ 1).trans (by simpa using ho₂))
(principal_add_of_principal_mul ho (ne_of_gt ho₂))
theorem principal_mul_iff_mul_left_eq {o : Ordinal} :
Principal (· * ·) o ↔ ∀ a, 0 < a → a < o → a * o = o := by
refine ⟨fun h a ha₀ hao => ?_, fun h a b hao hbo => ?_⟩
· cases' le_or_gt o 2 with ho ho
· convert one_mul o
apply le_antisymm
· have : a < succ 1 := hao.trans_le (by simpa using ho)
rwa [lt_succ_iff] at this
· rwa [← succ_le_iff, succ_zero] at ha₀
· exact op_eq_self_of_principal hao (mul_isNormal ha₀) h (principal_mul_isLimit ho h)
· rcases eq_or_ne a 0 with (rfl | ha)
· dsimp only; rwa [zero_mul]
rw [← Ordinal.pos_iff_ne_zero] at ha
rw [← h a ha hao]
exact (mul_isNormal ha).strictMono hbo
theorem principal_mul_omega : Principal (· * ·) omega := fun a b ha hb =>
match a, b, lt_omega.1 ha, lt_omega.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by
dsimp only; rw [← natCast_mul]
apply nat_lt_omega
theorem mul_omega {a : Ordinal} (a0 : 0 < a) (ha : a < omega) : a * omega = omega :=
principal_mul_iff_mul_left_eq.1 principal_mul_omega a a0 ha
theorem mul_lt_omega_opow {a b c : Ordinal} (c0 : 0 < c) (ha : a < (omega^c)) (hb : b < omega) :
a * b < (omega^c) := by
rcases zero_or_succ_or_limit c with (rfl | ⟨c, rfl⟩ | l)
· exact (lt_irrefl _).elim c0
· rw [opow_succ] at ha
rcases ((mul_isNormal <| opow_pos _ omega_pos).limit_lt omega_isLimit).1 ha with ⟨n, hn, an⟩
apply (mul_le_mul_right' (le_of_lt an) _).trans_lt
rw [opow_succ, mul_assoc, mul_lt_mul_iff_left (opow_pos _ omega_pos)]
exact principal_mul_omega hn hb
· rcases ((opow_isNormal one_lt_omega).limit_lt l).1 ha with ⟨x, hx, ax⟩
refine (mul_le_mul' (le_of_lt ax) (le_of_lt hb)).trans_lt ?_
rw [← opow_succ, opow_lt_opow_iff_right one_lt_omega]
exact l.2 _ hx
theorem mul_omega_opow_opow {a b : Ordinal} (a0 : 0 < a) (h : a < (omega^omega^b)) :
a * (omega^omega^b) = (omega^omega^b) := by
by_cases b0 : b = 0
· rw [b0, opow_zero, opow_one] at h ⊢
exact mul_omega a0 h
refine
le_antisymm ?_
(by simpa only [one_mul] using mul_le_mul_right' (one_le_iff_pos.2 a0) (omega^omega^b))
rcases (lt_opow_of_limit omega_ne_zero (opow_isLimit_left omega_isLimit b0)).1 h with ⟨x, xb, ax⟩
apply (mul_le_mul_right' (le_of_lt ax) _).trans
rw [← opow_add, add_omega_opow xb]
theorem principal_mul_omega_opow_opow (o : Ordinal) : Principal (· * ·) (omega^omega^o) :=
principal_mul_iff_mul_left_eq.2 fun _ => mul_omega_opow_opow
theorem principal_add_of_principal_mul_opow {o b : Ordinal} (hb : 1 < b)
(ho : Principal (· * ·) (b^o)) : Principal (· + ·) o := fun x y hx hy => by
have := ho ((opow_lt_opow_iff_right hb).2 hx) ((opow_lt_opow_iff_right hb).2 hy)
dsimp only at *; rwa [← opow_add, opow_lt_opow_iff_right hb] at this
/-- The main characterization theorem for multiplicative principal ordinals. -/
theorem principal_mul_iff_le_two_or_omega_opow_opow {o : Ordinal} :
Principal (· * ·) o ↔ o ≤ 2 ∨ ∃ a : Ordinal, o = (omega^omega^a) := by
refine ⟨fun ho => ?_, ?_⟩
· rcases le_or_lt o 2 with ho₂ | ho₂
· exact Or.inl ho₂
rcases principal_add_iff_zero_or_omega_opow.1 (principal_add_of_principal_mul ho ho₂.ne') with
(rfl | ⟨a, rfl⟩)
· exact (Ordinal.not_lt_zero 2 ho₂).elim
rcases principal_add_iff_zero_or_omega_opow.1
(principal_add_of_principal_mul_opow one_lt_omega ho) with
(rfl | ⟨b, rfl⟩)
· simp
exact Or.inr ⟨b, rfl⟩
· rintro (ho₂ | ⟨a, rfl⟩)
· exact principal_mul_of_le_two ho₂
· exact principal_mul_omega_opow_opow a
theorem mul_omega_dvd {a : Ordinal} (a0 : 0 < a) (ha : a < omega) : ∀ {b}, omega ∣ b → a * b = b
| _, ⟨b, rfl⟩ => by rw [← mul_assoc, mul_omega a0 ha]
theorem mul_eq_opow_log_succ {a b : Ordinal.{u}} (ha : a ≠ 0) (hb : Principal (· * ·) b)
(hb₂ : 2 < b) : a * b = (b^succ (log b a)) := by
apply le_antisymm
· have hbl := principal_mul_isLimit hb₂ hb
rw [← IsNormal.bsup_eq.{u, u} (mul_isNormal (Ordinal.pos_iff_ne_zero.2 ha)) hbl, bsup_le_iff]
intro c hcb
have hb₁ : 1 < b := (lt_succ 1).trans (by simpa using hb₂)
have hbo₀ : (b^b.log a) ≠ 0 := Ordinal.pos_iff_ne_zero.1 (opow_pos _ (zero_lt_one.trans hb₁))
apply le_trans (mul_le_mul_right' (le_of_lt (lt_mul_succ_div a hbo₀)) c)
rw [mul_assoc, opow_succ]
refine mul_le_mul_left' (le_of_lt (hb (hbl.2 _ ?_) hcb)) _
rw [div_lt hbo₀, ← opow_succ]
exact lt_opow_succ_log_self hb₁ _
· rw [opow_succ]
exact mul_le_mul_right' (opow_log_le_self b ha) b
/-! #### Exponential principal ordinals -/
theorem principal_opow_omega : Principal (·^·) omega := fun a b ha hb =>
match a, b, lt_omega.1 ha, lt_omega.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by
simp_rw [← natCast_opow]
apply nat_lt_omega
theorem opow_omega {a : Ordinal} (a1 : 1 < a) (h : a < omega) : (a^omega) = omega :=
le_antisymm
((opow_le_of_limit (one_le_iff_ne_zero.1 <| le_of_lt a1) omega_isLimit).2 fun _ hb =>
(principal_opow_omega h hb).le)
(right_le_opow _ a1)
end Ordinal
|
SetTheory\Ordinal\Topology.lean | /-
Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Violeta Hernández Palacios
-/
import Mathlib.SetTheory.Ordinal.Arithmetic
import Mathlib.Tactic.TFAE
import Mathlib.Topology.Order.Monotone
/-!
### Topology of ordinals
We prove some miscellaneous results involving the order topology of ordinals.
### Main results
* `Ordinal.isClosed_iff_sup` / `Ordinal.isClosed_iff_bsup`: A set of ordinals is closed iff it's
closed under suprema.
* `Ordinal.isNormal_iff_strictMono_and_continuous`: A characterization of normal ordinal
functions.
* `Ordinal.enumOrd_isNormal_iff_isClosed`: The function enumerating the ordinals of a set is
normal iff the set is closed.
-/
noncomputable section
universe u v
open Cardinal Order Topology
namespace Ordinal
variable {s : Set Ordinal.{u}} {a : Ordinal.{u}}
instance : TopologicalSpace Ordinal.{u} := Preorder.topology Ordinal.{u}
instance : OrderTopology Ordinal.{u} := ⟨rfl⟩
theorem isOpen_singleton_iff : IsOpen ({a} : Set Ordinal) ↔ ¬IsLimit a := by
refine ⟨fun h ⟨h₀, hsucc⟩ => ?_, fun ha => ?_⟩
· obtain ⟨b, c, hbc, hbc'⟩ :=
(mem_nhds_iff_exists_Ioo_subset' ⟨0, Ordinal.pos_iff_ne_zero.2 h₀⟩ ⟨_, lt_succ a⟩).1
(h.mem_nhds rfl)
have hba := hsucc b hbc.1
exact hba.ne (hbc' ⟨lt_succ b, hba.trans hbc.2⟩)
· rcases zero_or_succ_or_limit a with (rfl | ⟨b, rfl⟩ | ha')
· rw [← bot_eq_zero, ← Set.Iic_bot, ← Iio_succ]
exact isOpen_Iio
· rw [← Set.Icc_self, Icc_succ_left, ← Ioo_succ_right]
exact isOpen_Ioo
· exact (ha ha').elim
-- Porting note (#11215): TODO: generalize to a `SuccOrder`
theorem nhds_right' (a : Ordinal) : 𝓝[>] a = ⊥ := (covBy_succ a).nhdsWithin_Ioi
-- todo: generalize to a `SuccOrder`
theorem nhds_left'_eq_nhds_ne (a : Ordinal) : 𝓝[<] a = 𝓝[≠] a := by
rw [← nhds_left'_sup_nhds_right', nhds_right', sup_bot_eq]
-- todo: generalize to a `SuccOrder`
theorem nhds_left_eq_nhds (a : Ordinal) : 𝓝[≤] a = 𝓝 a := by
rw [← nhds_left_sup_nhds_right', nhds_right', sup_bot_eq]
-- todo: generalize to a `SuccOrder`
theorem nhdsBasis_Ioc (h : a ≠ 0) : (𝓝 a).HasBasis (· < a) (Set.Ioc · a) :=
nhds_left_eq_nhds a ▸ nhdsWithin_Iic_basis' ⟨0, h.bot_lt⟩
-- todo: generalize to a `SuccOrder`
theorem nhds_eq_pure : 𝓝 a = pure a ↔ ¬IsLimit a :=
(isOpen_singleton_iff_nhds_eq_pure _).symm.trans isOpen_singleton_iff
-- todo: generalize `Ordinal.IsLimit` and this lemma to a `SuccOrder`
theorem isOpen_iff : IsOpen s ↔ ∀ o ∈ s, IsLimit o → ∃ a < o, Set.Ioo a o ⊆ s := by
refine isOpen_iff_mem_nhds.trans <| forall₂_congr fun o ho => ?_
by_cases ho' : IsLimit o
· simp only [(nhdsBasis_Ioc ho'.1).mem_iff, ho', true_implies]
refine exists_congr fun a => and_congr_right fun ha => ?_
simp only [← Set.Ioo_insert_right ha, Set.insert_subset_iff, ho, true_and]
· simp [nhds_eq_pure.2 ho', ho, ho']
open List Set in
theorem mem_closure_tfae (a : Ordinal.{u}) (s : Set Ordinal) :
TFAE [a ∈ closure s,
a ∈ closure (s ∩ Iic a),
(s ∩ Iic a).Nonempty ∧ sSup (s ∩ Iic a) = a,
∃ t, t ⊆ s ∧ t.Nonempty ∧ BddAbove t ∧ sSup t = a,
∃ (o : Ordinal.{u}), o ≠ 0 ∧ ∃ (f : ∀ x < o, Ordinal),
(∀ x hx, f x hx ∈ s) ∧ bsup.{u, u} o f = a,
∃ (ι : Type u), Nonempty ι ∧ ∃ f : ι → Ordinal, (∀ i, f i ∈ s) ∧ sup.{u, u} f = a] := by
tfae_have 1 → 2
· simp only [mem_closure_iff_nhdsWithin_neBot, inter_comm s, nhdsWithin_inter', nhds_left_eq_nhds]
exact id
tfae_have 2 → 3
· intro h
rcases (s ∩ Iic a).eq_empty_or_nonempty with he | hne
· simp [he] at h
· refine ⟨hne, (isLUB_of_mem_closure ?_ h).csSup_eq hne⟩
exact fun x hx => hx.2
tfae_have 3 → 4
· exact fun h => ⟨_, inter_subset_left, h.1, bddAbove_Iic.mono inter_subset_right, h.2⟩
tfae_have 4 → 5
· rintro ⟨t, hts, hne, hbdd, rfl⟩
have hlub : IsLUB t (sSup t) := isLUB_csSup hne hbdd
let ⟨y, hyt⟩ := hne
classical
refine ⟨succ (sSup t), succ_ne_zero _, fun x _ => if x ∈ t then x else y, fun x _ => ?_, ?_⟩
· simp only
split_ifs with h <;> exact hts ‹_›
· refine le_antisymm (bsup_le fun x _ => ?_) (csSup_le hne fun x hx => ?_)
· split_ifs <;> exact hlub.1 ‹_›
· refine (if_pos hx).symm.trans_le (le_bsup _ _ <| (hlub.1 hx).trans_lt (lt_succ _))
tfae_have 5 → 6
· rintro ⟨o, h₀, f, hfs, rfl⟩
exact ⟨_, out_nonempty_iff_ne_zero.2 h₀, familyOfBFamily o f, fun _ => hfs _ _, rfl⟩
tfae_have 6 → 1
· rintro ⟨ι, hne, f, hfs, rfl⟩
rw [sup, iSup]
exact closure_mono (range_subset_iff.2 hfs) <| csSup_mem_closure (range_nonempty f)
(bddAbove_range.{u, u} f)
tfae_finish
theorem mem_closure_iff_sup :
a ∈ closure s ↔
∃ (ι : Type u) (_ : Nonempty ι) (f : ι → Ordinal), (∀ i, f i ∈ s) ∧ sup.{u, u} f = a :=
((mem_closure_tfae a s).out 0 5).trans <| by simp only [exists_prop]
theorem mem_closed_iff_sup (hs : IsClosed s) :
a ∈ s ↔ ∃ (ι : Type u) (_hι : Nonempty ι) (f : ι → Ordinal),
(∀ i, f i ∈ s) ∧ sup.{u, u} f = a := by
rw [← mem_closure_iff_sup, hs.closure_eq]
theorem mem_closure_iff_bsup :
a ∈ closure s ↔
∃ (o : Ordinal) (_ho : o ≠ 0) (f : ∀ a < o, Ordinal),
(∀ i hi, f i hi ∈ s) ∧ bsup.{u, u} o f = a :=
((mem_closure_tfae a s).out 0 4).trans <| by simp only [exists_prop]
theorem mem_closed_iff_bsup (hs : IsClosed s) :
a ∈ s ↔
∃ (o : Ordinal) (_ho : o ≠ 0) (f : ∀ a < o, Ordinal),
(∀ i hi, f i hi ∈ s) ∧ bsup.{u, u} o f = a := by
rw [← mem_closure_iff_bsup, hs.closure_eq]
theorem isClosed_iff_sup :
IsClosed s ↔
∀ {ι : Type u}, Nonempty ι → ∀ f : ι → Ordinal, (∀ i, f i ∈ s) → sup.{u, u} f ∈ s := by
use fun hs ι hι f hf => (mem_closed_iff_sup hs).2 ⟨ι, hι, f, hf, rfl⟩
rw [← closure_subset_iff_isClosed]
intro h x hx
rcases mem_closure_iff_sup.1 hx with ⟨ι, hι, f, hf, rfl⟩
exact h hι f hf
theorem isClosed_iff_bsup :
IsClosed s ↔
∀ {o : Ordinal}, o ≠ 0 → ∀ f : ∀ a < o, Ordinal,
(∀ i hi, f i hi ∈ s) → bsup.{u, u} o f ∈ s := by
rw [isClosed_iff_sup]
refine ⟨fun H o ho f hf => H (out_nonempty_iff_ne_zero.2 ho) _ ?_, fun H ι hι f hf => ?_⟩
· exact fun i => hf _ _
· rw [← bsup_eq_sup]
apply H (type_ne_zero_iff_nonempty.2 hι)
exact fun i hi => hf _
theorem isLimit_of_mem_frontier (ha : a ∈ frontier s) : IsLimit a := by
simp only [frontier_eq_closure_inter_closure, Set.mem_inter_iff, mem_closure_iff] at ha
by_contra h
rw [← isOpen_singleton_iff] at h
rcases ha.1 _ h rfl with ⟨b, hb, hb'⟩
rcases ha.2 _ h rfl with ⟨c, hc, hc'⟩
rw [Set.mem_singleton_iff] at *
subst hb; subst hc
exact hc' hb'
theorem isNormal_iff_strictMono_and_continuous (f : Ordinal.{u} → Ordinal.{u}) :
IsNormal f ↔ StrictMono f ∧ Continuous f := by
refine ⟨fun h => ⟨h.strictMono, ?_⟩, ?_⟩
· rw [continuous_def]
intro s hs
rw [isOpen_iff] at *
intro o ho ho'
rcases hs _ ho (h.isLimit ho') with ⟨a, ha, has⟩
rw [← IsNormal.bsup_eq.{u, u} h ho', lt_bsup] at ha
rcases ha with ⟨b, hb, hab⟩
exact
⟨b, hb, fun c hc =>
Set.mem_preimage.2 (has ⟨hab.trans (h.strictMono hc.1), h.strictMono hc.2⟩)⟩
· rw [isNormal_iff_strictMono_limit]
rintro ⟨h, h'⟩
refine ⟨h, fun o ho a h => ?_⟩
suffices o ∈ f ⁻¹' Set.Iic a from Set.mem_preimage.1 this
rw [mem_closed_iff_sup (IsClosed.preimage h' (@isClosed_Iic _ _ _ _ a))]
exact
⟨_, out_nonempty_iff_ne_zero.2 ho.1, typein (· < ·), fun i => h _ (typein_lt_self i),
sup_typein_limit ho.2⟩
theorem enumOrd_isNormal_iff_isClosed (hs : s.Unbounded (· < ·)) :
IsNormal (enumOrd s) ↔ IsClosed s := by
have Hs := enumOrd_strictMono hs
refine
⟨fun h => isClosed_iff_sup.2 fun {ι} hι f hf => ?_, fun h =>
(isNormal_iff_strictMono_limit _).2 ⟨Hs, fun a ha o H => ?_⟩⟩
· let g : ι → Ordinal.{u} := fun i => (enumOrdOrderIso hs).symm ⟨_, hf i⟩
suffices enumOrd s (sup.{u, u} g) = sup.{u, u} f by
rw [← this]
exact enumOrd_mem hs _
rw [@IsNormal.sup.{u, u, u} _ h ι g hι]
congr
ext x
change ((enumOrdOrderIso hs) _).val = f x
rw [OrderIso.apply_symm_apply]
· rw [isClosed_iff_bsup] at h
suffices enumOrd s a ≤ bsup.{u, u} a fun b (_ : b < a) => enumOrd s b from
this.trans (bsup_le H)
cases' enumOrd_surjective hs _
(h ha.1 (fun b _ => enumOrd s b) fun b _ => enumOrd_mem hs b) with
b hb
rw [← hb]
apply Hs.monotone
by_contra! hba
apply (Hs (lt_succ b)).not_le
rw [hb]
exact le_bsup.{u, u} _ _ (ha.2 _ hba)
end Ordinal
|
SetTheory\Surreal\Basic.lean | /-
Copyright (c) 2019 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Scott Morrison
-/
import Mathlib.Algebra.Order.Hom.Monoid
import Mathlib.SetTheory.Game.Ordinal
/-!
# Surreal numbers
The basic theory of surreal numbers, built on top of the theory of combinatorial (pre-)games.
A pregame is `Numeric` if all the Left options are strictly smaller than all the Right options, and
all those options are themselves numeric. In terms of combinatorial games, the numeric games have
"frozen"; you can only make your position worse by playing, and Left is some definite "number" of
moves ahead (or behind) Right.
A surreal number is an equivalence class of numeric pregames.
In fact, the surreals form a complete ordered field, containing a copy of the reals (and much else
besides!) but we do not yet have a complete development.
## Order properties
Surreal numbers inherit the relations `≤` and `<` from games (`Surreal.instLE` and
`Surreal.instLT`), and these relations satisfy the axioms of a partial order.
## Algebraic operations
In this file, we show that the surreals form a linear ordered commutative group.
In `Mathlib.SetTheory.Surreal.Multiplication`, we define multiplication and show that the
surreals form a linear ordered commutative ring.
One can also map all the ordinals into the surreals!
## TODO
- Define the field structure on the surreals.
## References
* [Conway, *On numbers and games*][Conway2001]
* [Schleicher, Stoll, *An introduction to Conway's games and numbers*][SchleicherStoll]
-/
universe u
namespace SetTheory
open scoped PGame
namespace PGame
/-- A pre-game is numeric if everything in the L set is less than everything in the R set,
and all the elements of L and R are also numeric. -/
def Numeric : PGame → Prop
| ⟨_, _, L, R⟩ => (∀ i j, L i < R j) ∧ (∀ i, Numeric (L i)) ∧ ∀ j, Numeric (R j)
theorem numeric_def {x : PGame} :
Numeric x ↔
(∀ i j, x.moveLeft i < x.moveRight j) ∧
(∀ i, Numeric (x.moveLeft i)) ∧ ∀ j, Numeric (x.moveRight j) := by
cases x; rfl
namespace Numeric
theorem mk {x : PGame} (h₁ : ∀ i j, x.moveLeft i < x.moveRight j) (h₂ : ∀ i, Numeric (x.moveLeft i))
(h₃ : ∀ j, Numeric (x.moveRight j)) : Numeric x :=
numeric_def.2 ⟨h₁, h₂, h₃⟩
theorem left_lt_right {x : PGame} (o : Numeric x) (i : x.LeftMoves) (j : x.RightMoves) :
x.moveLeft i < x.moveRight j := by cases x; exact o.1 i j
theorem moveLeft {x : PGame} (o : Numeric x) (i : x.LeftMoves) : Numeric (x.moveLeft i) := by
cases x; exact o.2.1 i
theorem moveRight {x : PGame} (o : Numeric x) (j : x.RightMoves) : Numeric (x.moveRight j) := by
cases x; exact o.2.2 j
lemma isOption {x' x} (h : IsOption x' x) (hx : Numeric x) : Numeric x' := by
cases h
· apply hx.moveLeft
· apply hx.moveRight
end Numeric
@[elab_as_elim]
theorem numeric_rec {C : PGame → Prop}
(H : ∀ (l r) (L : l → PGame) (R : r → PGame), (∀ i j, L i < R j) →
(∀ i, Numeric (L i)) → (∀ i, Numeric (R i)) → (∀ i, C (L i)) → (∀ i, C (R i)) →
C ⟨l, r, L, R⟩) :
∀ x, Numeric x → C x
| ⟨_, _, _, _⟩, ⟨h, hl, hr⟩ =>
H _ _ _ _ h hl hr (fun i => numeric_rec H _ (hl i)) fun i => numeric_rec H _ (hr i)
theorem Relabelling.numeric_imp {x y : PGame} (r : x ≡r y) (ox : Numeric x) : Numeric y := by
induction' x using PGame.moveRecOn with x IHl IHr generalizing y
apply Numeric.mk (fun i j => ?_) (fun i => ?_) fun j => ?_
· rw [← lt_congr (r.moveLeftSymm i).equiv (r.moveRightSymm j).equiv]
apply ox.left_lt_right
· exact IHl _ (r.moveLeftSymm i) (ox.moveLeft _)
· exact IHr _ (r.moveRightSymm j) (ox.moveRight _)
/-- Relabellings preserve being numeric. -/
theorem Relabelling.numeric_congr {x y : PGame} (r : x ≡r y) : Numeric x ↔ Numeric y :=
⟨r.numeric_imp, r.symm.numeric_imp⟩
theorem lf_asymm {x y : PGame} (ox : Numeric x) (oy : Numeric y) : x ⧏ y → ¬y ⧏ x := by
refine numeric_rec (C := fun x => ∀ z (_oz : Numeric z), x ⧏ z → ¬z ⧏ x)
(fun xl xr xL xR hx _oxl _oxr IHxl IHxr => ?_) x ox y oy
refine numeric_rec fun yl yr yL yR hy oyl oyr _IHyl _IHyr => ?_
rw [mk_lf_mk, mk_lf_mk]; rintro (⟨i, h₁⟩ | ⟨j, h₁⟩) (⟨i, h₂⟩ | ⟨j, h₂⟩)
· exact IHxl _ _ (oyl _) (h₁.moveLeft_lf _) (h₂.moveLeft_lf _)
· exact (le_trans h₂ h₁).not_gf (lf_of_lt (hy _ _))
· exact (le_trans h₁ h₂).not_gf (lf_of_lt (hx _ _))
· exact IHxr _ _ (oyr _) (h₁.lf_moveRight _) (h₂.lf_moveRight _)
theorem le_of_lf {x y : PGame} (h : x ⧏ y) (ox : Numeric x) (oy : Numeric y) : x ≤ y :=
not_lf.1 (lf_asymm ox oy h)
alias LF.le := le_of_lf
theorem lt_of_lf {x y : PGame} (h : x ⧏ y) (ox : Numeric x) (oy : Numeric y) : x < y :=
(lt_or_fuzzy_of_lf h).resolve_right (not_fuzzy_of_le (h.le ox oy))
alias LF.lt := lt_of_lf
theorem lf_iff_lt {x y : PGame} (ox : Numeric x) (oy : Numeric y) : x ⧏ y ↔ x < y :=
⟨fun h => h.lt ox oy, lf_of_lt⟩
/-- Definition of `x ≤ y` on numeric pre-games, in terms of `<` -/
theorem le_iff_forall_lt {x y : PGame} (ox : x.Numeric) (oy : y.Numeric) :
x ≤ y ↔ (∀ i, x.moveLeft i < y) ∧ ∀ j, x < y.moveRight j := by
refine le_iff_forall_lf.trans (and_congr ?_ ?_) <;>
refine forall_congr' fun i => lf_iff_lt ?_ ?_ <;>
apply_rules [Numeric.moveLeft, Numeric.moveRight]
/-- Definition of `x < y` on numeric pre-games, in terms of `≤` -/
theorem lt_iff_exists_le {x y : PGame} (ox : x.Numeric) (oy : y.Numeric) :
x < y ↔ (∃ i, x ≤ y.moveLeft i) ∨ ∃ j, x.moveRight j ≤ y := by
rw [← lf_iff_lt ox oy, lf_iff_exists_le]
theorem lt_of_exists_le {x y : PGame} (ox : x.Numeric) (oy : y.Numeric) :
((∃ i, x ≤ y.moveLeft i) ∨ ∃ j, x.moveRight j ≤ y) → x < y :=
(lt_iff_exists_le ox oy).2
/-- The definition of `x < y` on numeric pre-games, in terms of `<` two moves later. -/
theorem lt_def {x y : PGame} (ox : x.Numeric) (oy : y.Numeric) :
x < y ↔
(∃ i, (∀ i', x.moveLeft i' < y.moveLeft i) ∧ ∀ j, x < (y.moveLeft i).moveRight j) ∨
∃ j, (∀ i, (x.moveRight j).moveLeft i < y) ∧ ∀ j', x.moveRight j < y.moveRight j' := by
rw [← lf_iff_lt ox oy, lf_def]
refine or_congr ?_ ?_ <;> refine exists_congr fun x_1 => ?_ <;> refine and_congr ?_ ?_ <;>
refine forall_congr' fun i => lf_iff_lt ?_ ?_ <;>
apply_rules [Numeric.moveLeft, Numeric.moveRight]
theorem not_fuzzy {x y : PGame} (ox : Numeric x) (oy : Numeric y) : ¬Fuzzy x y :=
fun h => not_lf.2 ((lf_of_fuzzy h).le ox oy) h.2
theorem lt_or_equiv_or_gt {x y : PGame} (ox : Numeric x) (oy : Numeric y) :
x < y ∨ (x ≈ y) ∨ y < x :=
((lf_or_equiv_or_gf x y).imp fun h => h.lt ox oy) <| Or.imp_right fun h => h.lt oy ox
theorem numeric_of_isEmpty (x : PGame) [IsEmpty x.LeftMoves] [IsEmpty x.RightMoves] : Numeric x :=
Numeric.mk isEmptyElim isEmptyElim isEmptyElim
theorem numeric_of_isEmpty_leftMoves (x : PGame) [IsEmpty x.LeftMoves] :
(∀ j, Numeric (x.moveRight j)) → Numeric x :=
Numeric.mk isEmptyElim isEmptyElim
theorem numeric_of_isEmpty_rightMoves (x : PGame) [IsEmpty x.RightMoves]
(H : ∀ i, Numeric (x.moveLeft i)) : Numeric x :=
Numeric.mk (fun _ => isEmptyElim) H isEmptyElim
theorem numeric_zero : Numeric 0 :=
numeric_of_isEmpty 0
theorem numeric_one : Numeric 1 :=
numeric_of_isEmpty_rightMoves 1 fun _ => numeric_zero
theorem Numeric.neg : ∀ {x : PGame} (_ : Numeric x), Numeric (-x)
| ⟨_, _, _, _⟩, o =>
⟨fun j i => neg_lt_neg_iff.2 (o.1 i j), fun j => (o.2.2 j).neg, fun i => (o.2.1 i).neg⟩
/-- Inserting a smaller numeric left option into a numeric game results in a numeric game. -/
theorem insertLeft_numeric {x x' : PGame} (x_num : x.Numeric) (x'_num : x'.Numeric)
(h : x' ≤ x) : (insertLeft x x').Numeric := by
rw [le_iff_forall_lt x'_num x_num] at h
unfold Numeric at x_num ⊢
rcases x with ⟨xl, xr, xL, xR⟩
simp only [insertLeft, Sum.forall, forall_const, Sum.elim_inl, Sum.elim_inr] at x_num ⊢
constructor
· simp only [x_num.1, implies_true, true_and]
simp only [rightMoves_mk, moveRight_mk] at h
exact h.2
· simp only [x_num, implies_true, x'_num, and_self]
/-- Inserting a larger numeric right option into a numeric game results in a numeric game. -/
theorem insertRight_numeric {x x' : PGame} (x_num : x.Numeric) (x'_num : x'.Numeric)
(h : x ≤ x') : (insertRight x x').Numeric := by
rw [← neg_neg (x.insertRight x'), ← neg_insertLeft_neg]
apply Numeric.neg
exact insertLeft_numeric (Numeric.neg x_num) (Numeric.neg x'_num) (neg_le_neg_iff.mpr h)
namespace Numeric
theorem moveLeft_lt {x : PGame} (o : Numeric x) (i) : x.moveLeft i < x :=
(moveLeft_lf i).lt (o.moveLeft i) o
theorem moveLeft_le {x : PGame} (o : Numeric x) (i) : x.moveLeft i ≤ x :=
(o.moveLeft_lt i).le
theorem lt_moveRight {x : PGame} (o : Numeric x) (j) : x < x.moveRight j :=
(lf_moveRight j).lt o (o.moveRight j)
theorem le_moveRight {x : PGame} (o : Numeric x) (j) : x ≤ x.moveRight j :=
(o.lt_moveRight j).le
theorem add : ∀ {x y : PGame} (_ : Numeric x) (_ : Numeric y), Numeric (x + y)
| ⟨xl, xr, xL, xR⟩, ⟨yl, yr, yL, yR⟩, ox, oy =>
⟨by
rintro (ix | iy) (jx | jy)
· exact add_lt_add_right (ox.1 ix jx) _
· exact (add_lf_add_of_lf_of_le (lf_mk _ _ ix) (oy.le_moveRight jy)).lt
((ox.moveLeft ix).add oy) (ox.add (oy.moveRight jy))
· exact (add_lf_add_of_lf_of_le (mk_lf _ _ jx) (oy.moveLeft_le iy)).lt
(ox.add (oy.moveLeft iy)) ((ox.moveRight jx).add oy)
· exact add_lt_add_left (oy.1 iy jy) ⟨xl, xr, xL, xR⟩, by
constructor
· rintro (ix | iy)
· exact (ox.moveLeft ix).add oy
· exact ox.add (oy.moveLeft iy)
· rintro (jx | jy)
· apply (ox.moveRight jx).add oy
· apply ox.add (oy.moveRight jy)⟩
termination_by x y => (x, y) -- Porting note: Added `termination_by`
theorem sub {x y : PGame} (ox : Numeric x) (oy : Numeric y) : Numeric (x - y) :=
ox.add oy.neg
end Numeric
/-- Pre-games defined by natural numbers are numeric. -/
theorem numeric_nat : ∀ n : ℕ, Numeric n
| 0 => numeric_zero
| n + 1 => (numeric_nat n).add numeric_one
/-- Ordinal games are numeric. -/
theorem numeric_toPGame (o : Ordinal) : o.toPGame.Numeric := by
induction' o using Ordinal.induction with o IH
apply numeric_of_isEmpty_rightMoves
simpa using fun i => IH _ (Ordinal.toLeftMovesToPGame_symm_lt i)
end PGame
end SetTheory
open SetTheory PGame
/-- The type of surreal numbers. These are the numeric pre-games quotiented
by the equivalence relation `x ≈ y ↔ x ≤ y ∧ y ≤ x`. In the quotient,
the order becomes a total order. -/
def Surreal :=
Quotient (inferInstanceAs <| Setoid (Subtype Numeric))
namespace Surreal
/-- Construct a surreal number from a numeric pre-game. -/
def mk (x : PGame) (h : x.Numeric) : Surreal :=
⟦⟨x, h⟩⟧
instance : Zero Surreal :=
⟨mk 0 numeric_zero⟩
instance : One Surreal :=
⟨mk 1 numeric_one⟩
instance : Inhabited Surreal :=
⟨0⟩
lemma mk_eq_mk {x y : PGame.{u}} {hx hy} : mk x hx = mk y hy ↔ x ≈ y := Quotient.eq
lemma mk_eq_zero {x : PGame.{u}} {hx} : mk x hx = 0 ↔ x ≈ 0 := Quotient.eq
/-- Lift an equivalence-respecting function on pre-games to surreals. -/
def lift {α} (f : ∀ x, Numeric x → α)
(H : ∀ {x y} (hx : Numeric x) (hy : Numeric y), x.Equiv y → f x hx = f y hy) : Surreal → α :=
Quotient.lift (fun x : { x // Numeric x } => f x.1 x.2) fun x y => H x.2 y.2
/-- Lift a binary equivalence-respecting function on pre-games to surreals. -/
def lift₂ {α} (f : ∀ x y, Numeric x → Numeric y → α)
(H :
∀ {x₁ y₁ x₂ y₂} (ox₁ : Numeric x₁) (oy₁ : Numeric y₁) (ox₂ : Numeric x₂) (oy₂ : Numeric y₂),
x₁.Equiv x₂ → y₁.Equiv y₂ → f x₁ y₁ ox₁ oy₁ = f x₂ y₂ ox₂ oy₂) :
Surreal → Surreal → α :=
lift (fun x ox => lift (fun y oy => f x y ox oy) fun _ _ => H _ _ _ _ equiv_rfl)
fun _ _ h => funext <| Quotient.ind fun _ => H _ _ _ _ h equiv_rfl
instance instLE : LE Surreal :=
⟨lift₂ (fun x y _ _ => x ≤ y) fun _ _ _ _ hx hy => propext (le_congr hx hy)⟩
@[simp]
lemma mk_le_mk {x y : PGame.{u}} {hx hy} : mk x hx ≤ mk y hy ↔ x ≤ y := Iff.rfl
lemma zero_le_mk {x : PGame.{u}} {hx} : 0 ≤ mk x hx ↔ 0 ≤ x := Iff.rfl
instance instLT : LT Surreal :=
⟨lift₂ (fun x y _ _ => x < y) fun _ _ _ _ hx hy => propext (lt_congr hx hy)⟩
lemma mk_lt_mk {x y : PGame.{u}} {hx hy} : mk x hx < mk y hy ↔ x < y := Iff.rfl
lemma zero_lt_mk {x : PGame.{u}} {hx} : 0 < mk x hx ↔ 0 < x := Iff.rfl
/-- Same as `moveLeft_lt`, but for `Surreal` instead of `PGame` -/
theorem mk_moveLeft_lt_mk {x : PGame} (o : Numeric x) (i) :
Surreal.mk (x.moveLeft i) (Numeric.moveLeft o i) < Surreal.mk x o := Numeric.moveLeft_lt o i
/-- Same as `lt_moveRight`, but for `Surreal` instead of `PGame` -/
theorem mk_lt_mk_moveRight {x : PGame} (o : Numeric x) (j) :
Surreal.mk x o < Surreal.mk (x.moveRight j) (Numeric.moveRight o j) := Numeric.lt_moveRight o j
/-- Addition on surreals is inherited from pre-game addition:
the sum of `x = {xL | xR}` and `y = {yL | yR}` is `{xL + y, x + yL | xR + y, x + yR}`. -/
instance : Add Surreal :=
⟨Surreal.lift₂ (fun (x y : PGame) ox oy => ⟦⟨x + y, ox.add oy⟩⟧) fun _ _ _ _ hx hy =>
Quotient.sound (add_congr hx hy)⟩
/-- Negation for surreal numbers is inherited from pre-game negation:
the negation of `{L | R}` is `{-R | -L}`. -/
instance : Neg Surreal :=
⟨Surreal.lift (fun x ox => ⟦⟨-x, ox.neg⟩⟧) fun _ _ a => Quotient.sound (neg_equiv_neg_iff.2 a)⟩
instance orderedAddCommGroup : OrderedAddCommGroup Surreal where
add := (· + ·)
add_assoc := by rintro ⟨_⟩ ⟨_⟩ ⟨_⟩; exact Quotient.sound add_assoc_equiv
zero := 0
zero_add := by rintro ⟨a⟩; exact Quotient.sound (zero_add_equiv a)
add_zero := by rintro ⟨a⟩; exact Quotient.sound (add_zero_equiv a)
neg := Neg.neg
add_left_neg := by rintro ⟨a⟩; exact Quotient.sound (add_left_neg_equiv a)
add_comm := by rintro ⟨_⟩ ⟨_⟩; exact Quotient.sound add_comm_equiv
le := (· ≤ ·)
lt := (· < ·)
le_refl := by rintro ⟨_⟩; apply @le_rfl PGame
le_trans := by rintro ⟨_⟩ ⟨_⟩ ⟨_⟩; apply @le_trans PGame
lt_iff_le_not_le := by rintro ⟨_, ox⟩ ⟨_, oy⟩; apply @lt_iff_le_not_le PGame
le_antisymm := by rintro ⟨_⟩ ⟨_⟩ h₁ h₂; exact Quotient.sound ⟨h₁, h₂⟩
add_le_add_left := by rintro ⟨_⟩ ⟨_⟩ hx ⟨_⟩; exact @add_le_add_left PGame _ _ _ _ _ hx _
nsmul := nsmulRec
zsmul := zsmulRec
lemma mk_add {x y : PGame} (hx : x.Numeric) (hy : y.Numeric) :
Surreal.mk (x + y) (hx.add hy) = Surreal.mk x hx + Surreal.mk y hy := by rfl
lemma mk_sub {x y : PGame} (hx : x.Numeric) (hy : y.Numeric) :
Surreal.mk (x - y) (hx.sub hy) = Surreal.mk x hx - Surreal.mk y hy := by rfl
lemma zero_def : 0 = mk 0 numeric_zero := by rfl
noncomputable instance : LinearOrderedAddCommGroup Surreal :=
{ Surreal.orderedAddCommGroup with
le_total := by
rintro ⟨⟨x, ox⟩⟩ ⟨⟨y, oy⟩⟩
exact or_iff_not_imp_left.2 fun h => (PGame.not_le.1 h).le oy ox
decidableLE := Classical.decRel _ }
instance : AddMonoidWithOne Surreal :=
AddMonoidWithOne.unary
/-- Casts a `Surreal` number into a `Game`. -/
def toGame : Surreal →+o Game where
toFun := lift (fun x _ => ⟦x⟧) fun _ _ => Quot.sound
map_zero' := rfl
map_add' := by rintro ⟨_, _⟩ ⟨_, _⟩; rfl
monotone' := by rintro ⟨_, _⟩ ⟨_, _⟩; exact id
theorem zero_toGame : toGame 0 = 0 :=
rfl
@[simp]
theorem one_toGame : toGame 1 = 1 :=
rfl
@[simp]
theorem nat_toGame : ∀ n : ℕ, toGame n = n :=
map_natCast' _ one_toGame
/-- A small family of surreals is bounded above. -/
lemma bddAbove_range_of_small {ι : Type*} [Small.{u} ι] (f : ι → Surreal.{u}) :
BddAbove (Set.range f) := by
induction' f using Quotient.induction_on_pi with f
let g : ι → PGame.{u} := Subtype.val ∘ f
have hg (i) : (g i).Numeric := Subtype.prop _
conv in (⟦f _⟧) =>
change mk (g i) (hg i)
clear_value g
clear f
let x : PGame.{u} := ⟨Σ i, (g <| (equivShrink.{u} ι).symm i).LeftMoves, PEmpty,
fun x ↦ moveLeft _ x.2, PEmpty.elim⟩
refine ⟨mk x (.mk (by simp [x]) (fun _ ↦ (hg _).moveLeft _) (by simp [x])),
Set.forall_mem_range.2 fun i ↦ ?_⟩
rw [mk_le_mk, ← (equivShrink ι).symm_apply_apply i, le_iff_forall_lf]
simpa [x] using fun j ↦ @moveLeft_lf x ⟨equivShrink ι i, j⟩
/-- A small set of surreals is bounded above. -/
lemma bddAbove_of_small (s : Set Surreal.{u}) [Small.{u} s] : BddAbove s := by
simpa using bddAbove_range_of_small (Subtype.val : s → Surreal.{u})
/-- A small family of surreals is bounded below. -/
lemma bddBelow_range_of_small {ι : Type*} [Small.{u} ι] (f : ι → Surreal.{u}) :
BddBelow (Set.range f) := by
induction' f using Quotient.induction_on_pi with f
let g : ι → PGame.{u} := Subtype.val ∘ f
have hg (i) : (g i).Numeric := Subtype.prop _
conv in (⟦f _⟧) =>
change mk (g i) (hg i)
clear_value g
clear f
let x : PGame.{u} := ⟨PEmpty, Σ i, (g <| (equivShrink.{u} ι).symm i).RightMoves,
PEmpty.elim, fun x ↦ moveRight _ x.2⟩
refine ⟨mk x (.mk (by simp [x]) (by simp [x]) (fun _ ↦ (hg _).moveRight _) ),
Set.forall_mem_range.2 fun i ↦ ?_⟩
rw [mk_le_mk, ← (equivShrink ι).symm_apply_apply i, le_iff_forall_lf]
simpa [x] using fun j ↦ @lf_moveRight x ⟨equivShrink ι i, j⟩
/-- A small set of surreals is bounded below. -/
lemma bddBelow_of_small (s : Set Surreal.{u}) [Small.{u} s] : BddBelow s := by
simpa using bddBelow_range_of_small (Subtype.val : s → Surreal.{u})
end Surreal
open Surreal
namespace Ordinal
/-- Converts an ordinal into the corresponding surreal. -/
noncomputable def toSurreal : Ordinal ↪o Surreal where
toFun o := mk _ (numeric_toPGame o)
inj' a b h := toPGame_equiv_iff.1 (by apply Quotient.exact h) -- Porting note: Added `by apply`
map_rel_iff' := @toPGame_le_iff
end Ordinal
|
SetTheory\Surreal\Dyadic.lean | /-
Copyright (c) 2021 Apurva Nakade. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Apurva Nakade
-/
import Mathlib.Algebra.Algebra.Defs
import Mathlib.Algebra.Order.Group.Basic
import Mathlib.Algebra.Order.Ring.Basic
import Mathlib.RingTheory.Localization.Basic
import Mathlib.SetTheory.Game.Birthday
import Mathlib.SetTheory.Surreal.Multiplication
/-!
# Dyadic numbers
Dyadic numbers are obtained by localizing ℤ away from 2. They are the initial object in the category
of rings with no 2-torsion.
## Dyadic surreal numbers
We construct dyadic surreal numbers using the canonical map from ℤ[2 ^ {-1}] to surreals.
As we currently do not have a ring structure on `Surreal` we construct this map explicitly. Once we
have the ring structure, this map can be constructed directly by sending `2 ^ {-1}` to `half`.
## Embeddings
The above construction gives us an abelian group embedding of ℤ into `Surreal`. The goal is to
extend this to an embedding of dyadic rationals into `Surreal` and use Cauchy sequences of dyadic
rational numbers to construct an ordered field embedding of ℝ into `Surreal`.
-/
universe u
namespace SetTheory
namespace PGame
/-- For a natural number `n`, the pre-game `powHalf (n + 1)` is recursively defined as
`{0 | powHalf n}`. These are the explicit expressions of powers of `1 / 2`. By definition, we have
`powHalf 0 = 1` and `powHalf 1 ≈ 1 / 2` and we prove later on that
`powHalf (n + 1) + powHalf (n + 1) ≈ powHalf n`. -/
def powHalf : ℕ → PGame
| 0 => 1
| n + 1 => ⟨PUnit, PUnit, 0, fun _ => powHalf n⟩
@[simp]
theorem powHalf_zero : powHalf 0 = 1 :=
rfl
theorem powHalf_leftMoves (n) : (powHalf n).LeftMoves = PUnit := by cases n <;> rfl
theorem powHalf_zero_rightMoves : (powHalf 0).RightMoves = PEmpty :=
rfl
theorem powHalf_succ_rightMoves (n) : (powHalf (n + 1)).RightMoves = PUnit :=
rfl
@[simp]
theorem powHalf_moveLeft (n i) : (powHalf n).moveLeft i = 0 := by cases n <;> cases i <;> rfl
@[simp]
theorem powHalf_succ_moveRight (n i) : (powHalf (n + 1)).moveRight i = powHalf n :=
rfl
instance uniquePowHalfLeftMoves (n) : Unique (powHalf n).LeftMoves := by
cases n <;> exact PUnit.unique
instance isEmpty_powHalf_zero_rightMoves : IsEmpty (powHalf 0).RightMoves :=
inferInstanceAs (IsEmpty PEmpty)
instance uniquePowHalfSuccRightMoves (n) : Unique (powHalf (n + 1)).RightMoves :=
PUnit.unique
@[simp]
theorem birthday_half : birthday (powHalf 1) = 2 := by
rw [birthday_def]; simp
/-- For all natural numbers `n`, the pre-games `powHalf n` are numeric. -/
theorem numeric_powHalf (n) : (powHalf n).Numeric := by
induction' n with n hn
· exact numeric_one
· constructor
· simpa using hn.moveLeft_lt default
· exact ⟨fun _ => numeric_zero, fun _ => hn⟩
theorem powHalf_succ_lt_powHalf (n : ℕ) : powHalf (n + 1) < powHalf n :=
(numeric_powHalf (n + 1)).lt_moveRight default
theorem powHalf_succ_le_powHalf (n : ℕ) : powHalf (n + 1) ≤ powHalf n :=
(powHalf_succ_lt_powHalf n).le
theorem powHalf_le_one (n : ℕ) : powHalf n ≤ 1 := by
induction' n with n hn
· exact le_rfl
· exact (powHalf_succ_le_powHalf n).trans hn
theorem powHalf_succ_lt_one (n : ℕ) : powHalf (n + 1) < 1 :=
(powHalf_succ_lt_powHalf n).trans_le <| powHalf_le_one n
theorem powHalf_pos (n : ℕ) : 0 < powHalf n := by
rw [← lf_iff_lt numeric_zero (numeric_powHalf n), zero_lf_le]; simp
theorem zero_le_powHalf (n : ℕ) : 0 ≤ powHalf n :=
(powHalf_pos n).le
theorem add_powHalf_succ_self_eq_powHalf (n) : powHalf (n + 1) + powHalf (n + 1) ≈ powHalf n := by
induction' n using Nat.strong_induction_on with n hn
constructor <;> rw [le_iff_forall_lf] <;> constructor
· rintro (⟨⟨⟩⟩ | ⟨⟨⟩⟩) <;> apply lf_of_lt
· calc
0 + powHalf n.succ ≈ powHalf n.succ := zero_add_equiv _
_ < powHalf n := powHalf_succ_lt_powHalf n
· calc
powHalf n.succ + 0 ≈ powHalf n.succ := add_zero_equiv _
_ < powHalf n := powHalf_succ_lt_powHalf n
· cases' n with n
· rintro ⟨⟩
rintro ⟨⟩
apply lf_of_moveRight_le
swap
· exact Sum.inl default
calc
powHalf n.succ + powHalf (n.succ + 1) ≤ powHalf n.succ + powHalf n.succ :=
add_le_add_left (powHalf_succ_le_powHalf _) _
_ ≈ powHalf n := hn _ (Nat.lt_succ_self n)
· simp only [powHalf_moveLeft, forall_const]
apply lf_of_lt
calc
0 ≈ 0 + 0 := Equiv.symm (add_zero_equiv 0)
_ ≤ powHalf n.succ + 0 := add_le_add_right (zero_le_powHalf _) _
_ < powHalf n.succ + powHalf n.succ := add_lt_add_left (powHalf_pos _) _
· rintro (⟨⟨⟩⟩ | ⟨⟨⟩⟩) <;> apply lf_of_lt
· calc
powHalf n ≈ powHalf n + 0 := Equiv.symm (add_zero_equiv _)
_ < powHalf n + powHalf n.succ := add_lt_add_left (powHalf_pos _) _
· calc
powHalf n ≈ 0 + powHalf n := Equiv.symm (zero_add_equiv _)
_ < powHalf n.succ + powHalf n := add_lt_add_right (powHalf_pos _) _
theorem half_add_half_equiv_one : powHalf 1 + powHalf 1 ≈ 1 :=
add_powHalf_succ_self_eq_powHalf 0
end PGame
end SetTheory
namespace Surreal
open SetTheory PGame
/-- Powers of the surreal number `half`. -/
def powHalf (n : ℕ) : Surreal :=
⟦⟨PGame.powHalf n, PGame.numeric_powHalf n⟩⟧
@[simp]
theorem powHalf_zero : powHalf 0 = 1 :=
rfl
@[simp]
theorem double_powHalf_succ_eq_powHalf (n : ℕ) : 2 * powHalf (n + 1) = powHalf n := by
rw [two_mul]; exact Quotient.sound (PGame.add_powHalf_succ_self_eq_powHalf n)
@[simp]
theorem nsmul_pow_two_powHalf (n : ℕ) : 2 ^ n * powHalf n = 1 := by
induction' n with n hn
· simp only [pow_zero, powHalf_zero, mul_one]
· rw [← hn, ← double_powHalf_succ_eq_powHalf n, ← mul_assoc (2 ^ n) 2 (powHalf (n + 1)),
pow_succ', mul_comm 2 (2 ^ n)]
@[simp]
theorem nsmul_pow_two_powHalf' (n k : ℕ) : 2 ^ n * powHalf (n + k) = powHalf k := by
induction' k with k hk
· simp only [add_zero, Surreal.nsmul_pow_two_powHalf, Nat.zero_eq, eq_self_iff_true,
Surreal.powHalf_zero]
· rw [← double_powHalf_succ_eq_powHalf (n + k), ← double_powHalf_succ_eq_powHalf k,
← mul_assoc, mul_comm (2 ^ n) 2, mul_assoc] at hk
rw [← zsmul_eq_zsmul_iff' two_ne_zero]
simpa only [zsmul_eq_mul, Int.cast_ofNat]
theorem zsmul_pow_two_powHalf (m : ℤ) (n k : ℕ) :
(m * 2 ^ n) * powHalf (n + k) = m * powHalf k := by
rw [mul_assoc]
congr
exact nsmul_pow_two_powHalf' n k
theorem dyadic_aux {m₁ m₂ : ℤ} {y₁ y₂ : ℕ} (h₂ : m₁ * 2 ^ y₁ = m₂ * 2 ^ y₂) :
m₁ * powHalf y₂ = m₂ * powHalf y₁ := by
revert m₁ m₂
wlog h : y₁ ≤ y₂
· intro m₁ m₂ aux; exact (this (le_of_not_le h) aux.symm).symm
intro m₁ m₂ h₂
obtain ⟨c, rfl⟩ := le_iff_exists_add.mp h
rw [add_comm, pow_add, ← mul_assoc, mul_eq_mul_right_iff] at h₂
cases' h₂ with h₂ h₂
· rw [h₂, add_comm]
simp_rw [Int.cast_mul, Int.cast_pow, Int.cast_ofNat, zsmul_pow_two_powHalf m₂ c y₁]
· have := Nat.one_le_pow y₁ 2 Nat.succ_pos'
norm_cast at h₂; omega
/-- The additive monoid morphism `dyadicMap` sends ⟦⟨m, 2^n⟩⟧ to m • half ^ n. -/
noncomputable def dyadicMap : Localization.Away (2 : ℤ) →+ Surreal where
toFun x :=
(Localization.liftOn x fun x y => x * powHalf (Submonoid.log y)) <| by
intro m₁ m₂ n₁ n₂ h₁
obtain ⟨⟨n₃, y₃, hn₃⟩, h₂⟩ := Localization.r_iff_exists.mp h₁
simp only [Subtype.coe_mk, mul_eq_mul_left_iff] at h₂
cases h₂
· obtain ⟨a₁, ha₁⟩ := n₁.prop
obtain ⟨a₂, ha₂⟩ := n₂.prop
simp only at ha₁ ha₂ ⊢
have hn₁ : n₁ = Submonoid.pow 2 a₁ := Subtype.ext ha₁.symm
have hn₂ : n₂ = Submonoid.pow 2 a₂ := Subtype.ext ha₂.symm
have h₂ : 1 < (2 : ℤ).natAbs := one_lt_two
rw [hn₁, hn₂, Submonoid.log_pow_int_eq_self h₂, Submonoid.log_pow_int_eq_self h₂]
apply dyadic_aux
rwa [ha₁, ha₂, mul_comm, mul_comm m₂]
· have : (1 : ℤ) ≤ 2 ^ y₃ := mod_cast Nat.one_le_pow y₃ 2 Nat.succ_pos'
linarith
map_zero' := by simp_rw [Localization.liftOn_zero _ _, Int.cast_zero, zero_mul]
map_add' x y :=
Localization.induction_on₂ x y <| by
rintro ⟨a, ⟨b, ⟨b', rfl⟩⟩⟩ ⟨c, ⟨d, ⟨d', rfl⟩⟩⟩
have h₂ : 1 < (2 : ℤ).natAbs := one_lt_two
have hpow₂ := Submonoid.log_pow_int_eq_self h₂
simp_rw [Submonoid.pow_apply] at hpow₂
simp_rw [Localization.add_mk, Localization.liftOn_mk,
Submonoid.log_mul (Int.pow_right_injective h₂), hpow₂]
simp only [Int.cast_add, Int.cast_mul, Int.cast_pow, Int.cast_ofNat]
calc
(2 ^ b' * c + 2 ^ d' * a) * powHalf (b' + d') =
(c * 2 ^ b') * powHalf (b' + d') + (a * 2 ^ d') * powHalf (d' + b') := by
simp only [right_distrib, mul_comm, add_comm]
_ = c * powHalf d' + a * powHalf b' := by simp only [zsmul_pow_two_powHalf]
_ = a * powHalf b' + c * powHalf d' := add_comm _ _
@[simp]
theorem dyadicMap_apply (m : ℤ) (p : Submonoid.powers (2 : ℤ)) :
dyadicMap (IsLocalization.mk' (Localization (Submonoid.powers 2)) m p) =
m * powHalf (Submonoid.log p) := by
rw [← Localization.mk_eq_mk']; rfl
-- @[simp] -- Porting note: simp normal form is `dyadicMap_apply_pow'`
theorem dyadicMap_apply_pow (m : ℤ) (n : ℕ) :
dyadicMap (IsLocalization.mk' (Localization (Submonoid.powers 2)) m (Submonoid.pow 2 n)) =
m • powHalf n := by
rw [dyadicMap_apply, @Submonoid.log_pow_int_eq_self 2 one_lt_two]
simp only [zsmul_eq_mul]
@[simp]
theorem dyadicMap_apply_pow' (m : ℤ) (n : ℕ) :
m * Surreal.powHalf (Submonoid.log (Submonoid.pow (2 : ℤ) n)) = m * powHalf n := by
rw [@Submonoid.log_pow_int_eq_self 2 one_lt_two]
/-- We define dyadic surreals as the range of the map `dyadicMap`. -/
def dyadic : Set Surreal :=
Set.range dyadicMap
-- We conclude with some ideas for further work on surreals; these would make fun projects.
-- TODO show that the map from dyadic rationals to surreals is injective
-- TODO map the reals into the surreals, using dyadic Dedekind cuts
-- TODO show this is a group homomorphism, and injective
-- TODO show the maps from the dyadic rationals and from the reals
-- into the surreals are multiplicative
end Surreal
|
SetTheory\Surreal\Multiplication.lean | /-
Copyright (c) 2024 Theodore Hwa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Scott Morrison, Violeta Hernández Palacios, Junyan Xu, Theodore Hwa
-/
import Mathlib.Logic.Hydra
import Mathlib.SetTheory.Surreal.Basic
/-!
### Surreal multiplication
In this file, we show that multiplication of surreal numbers is well-defined, and thus the
surreal numbers form a linear ordered commutative ring.
An inductive argument proves the following three main theorems:
* P1: being numeric is closed under multiplication,
* P2: multiplying a numeric pregame by equivalent numeric pregames results in equivalent pregames,
* P3: the product of two positive numeric pregames is positive (`mul_pos`).
This is Theorem 8 in [Conway2001], or Theorem 3.8 in [SchleicherStoll]. P1 allows us to define
multiplication as an operation on numeric pregames, P2 says that this is well-defined as an
operation on the quotient by `PGame.Equiv`, namely the surreal numbers, and P3 is an axiom that
needs to be satisfied for the surreals to be a `OrderedRing`.
We follow the proof in [SchleicherStoll], except that we use the well-foundedness of
the hydra relation `CutExpand` on `Multiset PGame` instead of the argument based
on a depth function in the paper.
In the argument, P3 is stated with four variables `x₁`, `x₂`, `y₁`, `y₂` satisfying `x₁ < x₂` and
`y₁ < y₂`, and says that `x₁ * y₂ + x₂ * x₁ < x₁ * y₁ + x₂ * y₂`, which is equivalent to
`0 < x₂ - x₁ → 0 < y₂ - y₁ → 0 < (x₂ - x₁) * (y₂ - y₁)`, i.e.
`@mul_pos PGame _ (x₂ - x₁) (y₂ - y₁)`. It has to be stated in this form and not in terms of
`mul_pos` because we need to show show P1, P2 and (a specialized form of) P3 simultaneously, and
for example `P1 x y` will be deduced from P3 with variables taking values simpler than `x` or `y`
(among other induction hypotheses), but if you subtract two pregames simpler than `x` or `y`,
the result may no longer be simpler.
The specialized version of P3 is called P4, which takes only three arguments `x₁`, `x₂`, `y` and
requires that `y₂ = y` or `-y` and that `y₁` is a left option of `y₂`. After P1, P2 and P4 are
shown, a further inductive argument (this time using the `GameAdd` relation) proves P3 in full.
Implementation strategy of the inductive argument: we
* extract specialized versions (`IH1`, `IH2`, `IH3`, `IH4` and `IH24`) of the
induction hypothesis that are easier to apply (takes `IsOption` arguments directly), and
* show they are invariant under certain symmetries (permutation and negation of arguments)
and that the induction hypothesis indeed implies the specialized versions.
* utilize the symmetries to minimize calculation.
The whole proof features a clear separation into lemmas of different roles:
* verification of symmetry properties of P and IH (`P3_comm`, `ih1_neg_left`, etc.),
* calculations that connects P1, P2, P3, and inequalities between the product of
two surreals and its options (`mulOption_lt_iff_P1`, etc.),
* specializations of the induction hypothesis
(`numeric_option_mul`, `ih1`, `ih1_swap`, `ih₁₂`, `ih4`, etc.),
* application of specialized indution hypothesis
(`P1_of_ih`, `mul_right_le_of_equiv`, `P3_of_lt`, etc.).
## References
* [Conway, *On numbers and games*][Conway2001]
* [Schleicher, Stoll, *An introduction to Conway's games and numbers*][SchleicherStoll]
-/
universe u
open SetTheory Game PGame WellFounded
namespace Surreal.Multiplication
/-- The nontrivial part of P1 in [SchleicherStoll] says that the left options of `x * y`
are less than the right options, and this is the general form of these statements. -/
def P1 (x₁ x₂ x₃ y₁ y₂ y₃ : PGame) :=
⟦x₁ * y₁⟧ + ⟦x₂ * y₂⟧ - ⟦x₁ * y₂⟧ < ⟦x₃ * y₁⟧ + ⟦x₂ * y₃⟧ - (⟦x₃ * y₃⟧ : Game)
/-- The proposition P2, without numericity assumptions. -/
def P2 (x₁ x₂ y : PGame) := x₁ ≈ x₂ → ⟦x₁ * y⟧ = (⟦x₂ * y⟧ : Game)
/-- The proposition P3, without the `x₁ < x₂` and `y₁ < y₂` assumptions. -/
def P3 (x₁ x₂ y₁ y₂ : PGame) := ⟦x₁ * y₂⟧ + ⟦x₂ * y₁⟧ < ⟦x₁ * y₁⟧ + (⟦x₂ * y₂⟧ : Game)
/-- The proposition P4, without numericity assumptions. In the references, the second part of the
conjunction is stated as `∀ j, P3 x₁ x₂ y (y.moveRight j)`, which is equivalent to our statement
by `P3_comm` and `P3_neg`. We choose to state everything in terms of left options for uniform
treatment. -/
def P4 (x₁ x₂ y : PGame) :=
x₁ < x₂ → (∀ i, P3 x₁ x₂ (y.moveLeft i) y) ∧ ∀ j, P3 x₁ x₂ ((-y).moveLeft j) (-y)
/-- The conjunction of P2 and P4. -/
def P24 (x₁ x₂ y : PGame) : Prop := P2 x₁ x₂ y ∧ P4 x₁ x₂ y
variable {x x₁ x₂ x₃ x' y y₁ y₂ y₃ y' : PGame.{u}}
/-! #### Symmetry properties of P1, P2, P3, and P4 -/
lemma P3_comm : P3 x₁ x₂ y₁ y₂ ↔ P3 y₁ y₂ x₁ x₂ := by
rw [P3, P3, add_comm]
congr! 2 <;> rw [quot_mul_comm]
lemma P3.trans (h₁ : P3 x₁ x₂ y₁ y₂) (h₂ : P3 x₂ x₃ y₁ y₂) : P3 x₁ x₃ y₁ y₂ := by
rw [P3] at h₁ h₂
rw [P3, ← add_lt_add_iff_left (⟦x₂ * y₁⟧ + ⟦x₂ * y₂⟧)]
convert add_lt_add h₁ h₂ using 1 <;> abel
lemma P3_neg : P3 x₁ x₂ y₁ y₂ ↔ P3 (-x₂) (-x₁) y₁ y₂ := by
simp_rw [P3, quot_neg_mul]
rw [← _root_.neg_lt_neg_iff]
abel_nf
lemma P2_neg_left : P2 x₁ x₂ y ↔ P2 (-x₂) (-x₁) y := by
rw [P2, P2]
constructor
· rw [quot_neg_mul, quot_neg_mul, eq_comm, neg_inj, neg_equiv_neg_iff, PGame.equiv_comm]
exact (· ·)
· rw [PGame.equiv_comm, neg_equiv_neg_iff, quot_neg_mul, quot_neg_mul, neg_inj, eq_comm]
exact (· ·)
lemma P2_neg_right : P2 x₁ x₂ y ↔ P2 x₁ x₂ (-y) := by
rw [P2, P2, quot_mul_neg, quot_mul_neg, neg_inj]
lemma P4_neg_left : P4 x₁ x₂ y ↔ P4 (-x₂) (-x₁) y := by
simp_rw [P4, PGame.neg_lt_neg_iff, moveLeft_neg', ← P3_neg]
lemma P4_neg_right : P4 x₁ x₂ y ↔ P4 x₁ x₂ (-y) := by
rw [P4, P4, neg_neg, and_comm]
lemma P24_neg_left : P24 x₁ x₂ y ↔ P24 (-x₂) (-x₁) y := by rw [P24, P24, P2_neg_left, P4_neg_left]
lemma P24_neg_right : P24 x₁ x₂ y ↔ P24 x₁ x₂ (-y) := by rw [P24, P24, P2_neg_right, P4_neg_right]
/-! #### Explicit calculations necessary for the main proof -/
lemma mulOption_lt_iff_P1 {i j k l} :
(⟦mulOption x y i k⟧ : Game) < -⟦mulOption x (-y) j l⟧ ↔
P1 (x.moveLeft i) x (x.moveLeft j) y (y.moveLeft k) (-(-y).moveLeft l) := by
dsimp only [P1, mulOption, quot_sub, quot_add]
simp_rw [neg_sub', neg_add, quot_mul_neg, neg_neg]
lemma mulOption_lt_mul_iff_P3 {i j} :
⟦mulOption x y i j⟧ < (⟦x * y⟧ : Game) ↔ P3 (x.moveLeft i) x (y.moveLeft j) y := by
dsimp only [mulOption, quot_sub, quot_add]
exact sub_lt_iff_lt_add'
lemma P1_of_eq (he : x₁ ≈ x₃) (h₁ : P2 x₁ x₃ y₁) (h₃ : P2 x₁ x₃ y₃) (h3 : P3 x₁ x₂ y₂ y₃) :
P1 x₁ x₂ x₃ y₁ y₂ y₃ := by
rw [P1, ← h₁ he, ← h₃ he, sub_lt_sub_iff]
convert add_lt_add_left h3 ⟦x₁ * y₁⟧ using 1 <;> abel
lemma P1_of_lt (h₁ : P3 x₃ x₂ y₂ y₃) (h₂ : P3 x₁ x₃ y₂ y₁) : P1 x₁ x₂ x₃ y₁ y₂ y₃ := by
rw [P1, sub_lt_sub_iff, ← add_lt_add_iff_left ⟦x₃ * y₂⟧]
convert add_lt_add h₁ h₂ using 1 <;> abel
/-- The type of lists of arguments for P1, P2, and P4. -/
inductive Args : Type (u+1)
| P1 (x y : PGame.{u}) : Args
| P24 (x₁ x₂ y : PGame.{u}) : Args
/-- The multiset associated to a list of arguments. -/
def Args.toMultiset : Args → Multiset PGame
| (Args.P1 x y) => {x, y}
| (Args.P24 x₁ x₂ y) => {x₁, x₂, y}
/-- A list of arguments is numeric if all the arguments are. -/
def Args.Numeric (a : Args) := ∀ x ∈ a.toMultiset, SetTheory.PGame.Numeric x
lemma Args.numeric_P1 {x y} : (Args.P1 x y).Numeric ↔ x.Numeric ∧ y.Numeric := by
simp [Args.Numeric, Args.toMultiset]
lemma Args.numeric_P24 {x₁ x₂ y} :
(Args.P24 x₁ x₂ y).Numeric ↔ x₁.Numeric ∧ x₂.Numeric ∧ y.Numeric := by
simp [Args.Numeric, Args.toMultiset]
open Relation
/-- The relation specifying when a list of (pregame) arguments is considered simpler than another:
`ArgsRel a₁ a₂` is true if `a₁`, considered as a multiset, can be obtained from `a₂` by
repeatedly removing a pregame from `a₂` and adding back one or two options of the pregame. -/
def ArgsRel := InvImage (TransGen <| CutExpand IsOption) Args.toMultiset
/-- `ArgsRel` is well-founded. -/
theorem argsRel_wf : WellFounded ArgsRel := InvImage.wf _ wf_isOption.cutExpand.transGen
/-- The statement that we will show by induction using the well-founded relation `ArgsRel`. -/
def P124 : Args → Prop
| (Args.P1 x y) => Numeric (x * y)
| (Args.P24 x₁ x₂ y) => P24 x₁ x₂ y
/-- The property that all arguments are numeric is leftward-closed under `ArgsRel`. -/
lemma ArgsRel.numeric_closed {a' a} : ArgsRel a' a → a.Numeric → a'.Numeric :=
TransGen.closed' <| @cutExpand_closed _ IsOption ⟨wf_isOption.isIrrefl.1⟩ _ Numeric.isOption
/-- A specialized induction hypothesis used to prove P1. -/
def IH1 (x y : PGame) : Prop :=
∀ ⦃x₁ x₂ y'⦄, IsOption x₁ x → IsOption x₂ x → (y' = y ∨ IsOption y' y) → P24 x₁ x₂ y'
/-! #### Symmetry properties of `IH1` -/
lemma ih1_neg_left : IH1 x y → IH1 (-x) y :=
fun h x₁ x₂ y' h₁ h₂ hy ↦ by
rw [isOption_neg] at h₁ h₂
exact P24_neg_left.2 (h h₂ h₁ hy)
lemma ih1_neg_right : IH1 x y → IH1 x (-y) :=
fun h x₁ x₂ y' ↦ by
rw [← neg_eq_iff_eq_neg, isOption_neg, P24_neg_right]
apply h
/-! #### Specialize `ih` to obtain specialized induction hypotheses for P1 -/
lemma numeric_option_mul (ih : ∀ a, ArgsRel a (Args.P1 x y) → P124 a) (h : IsOption x' x) :
(x' * y).Numeric :=
ih (Args.P1 x' y) (TransGen.single <| cutExpand_pair_left h)
lemma numeric_mul_option (ih : ∀ a, ArgsRel a (Args.P1 x y) → P124 a) (h : IsOption y' y) :
(x * y').Numeric :=
ih (Args.P1 x y') (TransGen.single <| cutExpand_pair_right h)
lemma numeric_option_mul_option (ih : ∀ a, ArgsRel a (Args.P1 x y) → P124 a) (hx : IsOption x' x)
(hy : IsOption y' y) : (x' * y').Numeric :=
ih (Args.P1 x' y') ((TransGen.single <| cutExpand_pair_right hy).tail <| cutExpand_pair_left hx)
lemma ih1 (ih : ∀ a, ArgsRel a (Args.P1 x y) → P124 a) : IH1 x y := by
rintro x₁ x₂ y' h₁ h₂ (rfl|hy) <;> apply ih (Args.P24 _ _ _)
on_goal 2 => refine TransGen.tail ?_ (cutExpand_pair_right hy)
all_goals exact TransGen.single (cutExpand_double_left h₁ h₂)
lemma ih1_swap (ih : ∀ a, ArgsRel a (Args.P1 x y) → P124 a) : IH1 y x := ih1 <| by
simp_rw [ArgsRel, InvImage, Args.toMultiset, Multiset.pair_comm] at ih ⊢
exact ih
lemma P3_of_ih (hy : Numeric y) (ihyx : IH1 y x) (i k l) :
P3 (x.moveLeft i) x (y.moveLeft k) (-(-y).moveLeft l) :=
P3_comm.2 <| ((ihyx (IsOption.moveLeft k) (isOption_neg.1 <| .moveLeft l) <| Or.inl rfl).2
(by rw [← moveRight_neg_symm]; apply hy.left_lt_right)).1 i
lemma P24_of_ih (ihxy : IH1 x y) (i j) : P24 (x.moveLeft i) (x.moveLeft j) y :=
ihxy (IsOption.moveLeft i) (IsOption.moveLeft j) (Or.inl rfl)
section
lemma mulOption_lt_of_lt (hy : y.Numeric) (ihxy : IH1 x y) (ihyx : IH1 y x) (i j k l)
(h : x.moveLeft i < x.moveLeft j) :
(⟦mulOption x y i k⟧ : Game) < -⟦mulOption x (-y) j l⟧ :=
mulOption_lt_iff_P1.2 <| P1_of_lt (P3_of_ih hy ihyx j k l) <| ((P24_of_ih ihxy i j).2 h).1 k
lemma mulOption_lt (hx : x.Numeric) (hy : y.Numeric) (ihxy : IH1 x y) (ihyx : IH1 y x) (i j k l) :
(⟦mulOption x y i k⟧ : Game) < -⟦mulOption x (-y) j l⟧ := by
obtain (h|h|h) := lt_or_equiv_or_gt (hx.moveLeft i) (hx.moveLeft j)
· exact mulOption_lt_of_lt hy ihxy ihyx i j k l h
· have ml := @IsOption.moveLeft
exact mulOption_lt_iff_P1.2 (P1_of_eq h (P24_of_ih ihxy i j).1
(ihxy (ml i) (ml j) <| Or.inr <| isOption_neg.1 <| ml l).1 <| P3_of_ih hy ihyx i k l)
· rw [mulOption_neg_neg, lt_neg]
exact mulOption_lt_of_lt hy.neg (ih1_neg_right ihxy) (ih1_neg_left ihyx) j i l _ h
end
/-- P1 follows from the induction hypothesis. -/
theorem P1_of_ih (ih : ∀ a, ArgsRel a (Args.P1 x y) → P124 a) (hx : x.Numeric) (hy : y.Numeric) :
(x * y).Numeric := by
have ihxy := ih1 ih
have ihyx := ih1_swap ih
have ihxyn := ih1_neg_left (ih1_neg_right ihxy)
have ihyxn := ih1_neg_left (ih1_neg_right ihyx)
refine numeric_def.mpr ⟨?_, ?_, ?_⟩
· simp_rw [lt_iff_game_lt]
intro i
rw [rightMoves_mul_iff]
constructor <;> (intro j l; revert i; rw [leftMoves_mul_iff (_ > ·)]; constructor <;> intro i k)
· apply mulOption_lt hx hy ihxy ihyx
· simp_rw [← mulOption_symm (-y), mulOption_neg_neg x]
apply mulOption_lt hy.neg hx.neg ihyxn ihxyn
· simp only [← mulOption_symm y]
apply mulOption_lt hy hx ihyx ihxy
· rw [mulOption_neg_neg y]
apply mulOption_lt hx.neg hy.neg ihxyn ihyxn
all_goals
cases x; cases y
rintro (⟨i,j⟩|⟨i,j⟩) <;>
refine ((numeric_option_mul ih ?_).add <| numeric_mul_option ih ?_).sub
(numeric_option_mul_option ih ?_ ?_) <;>
solve_by_elim [IsOption.mk_left, IsOption.mk_right]
/-- A specialized induction hypothesis used to prove P2 and P4. -/
def IH24 (x₁ x₂ y : PGame) : Prop :=
∀ ⦃z⦄, (IsOption z x₁ → P24 z x₂ y) ∧ (IsOption z x₂ → P24 x₁ z y) ∧ (IsOption z y → P24 x₁ x₂ z)
/-- A specialized induction hypothesis used to prove P4. -/
def IH4 (x₁ x₂ y : PGame) : Prop :=
∀ ⦃z w⦄, IsOption w y → (IsOption z x₁ → P2 z x₂ w) ∧ (IsOption z x₂ → P2 x₁ z w)
/-! #### Specialize `ih'` to obtain specialized induction hypotheses for P2 and P4 -/
lemma ih₁₂ (ih' : ∀ a, ArgsRel a (Args.P24 x₁ x₂ y) → P124 a) : IH24 x₁ x₂ y := by
rw [IH24]
refine fun z ↦ ⟨?_, ?_, ?_⟩ <;>
refine fun h ↦ ih' (Args.P24 _ _ _) (TransGen.single ?_)
· exact (cutExpand_add_right {y}).2 (cutExpand_pair_left h)
· exact (cutExpand_add_left {x₁}).2 (cutExpand_pair_left h)
· exact (cutExpand_add_left {x₁}).2 (cutExpand_pair_right h)
lemma ih₂₁ (ih' : ∀ a, ArgsRel a (Args.P24 x₁ x₂ y) → P124 a) : IH24 x₂ x₁ y := ih₁₂ <| by
simp_rw [ArgsRel, InvImage, Args.toMultiset, Multiset.pair_comm] at ih' ⊢
suffices {x₁, y, x₂} = {x₂, y, x₁} by rwa [← this]
dsimp only [Multiset.insert_eq_cons, ← Multiset.singleton_add] at ih' ⊢
abel
lemma ih4 (ih' : ∀ a, ArgsRel a (Args.P24 x₁ x₂ y) → P124 a) : IH4 x₁ x₂ y := by
refine fun z w h ↦ ⟨?_, ?_⟩
all_goals
intro h'
apply (ih' (Args.P24 _ _ _) <| (TransGen.single _).tail <|
(cutExpand_add_left {x₁}).2 <| cutExpand_pair_right h).1
try exact (cutExpand_add_right {w}).2 <| cutExpand_pair_left h'
try exact (cutExpand_add_right {w}).2 <| cutExpand_pair_right h'
lemma numeric_of_ih (ih' : ∀ a, ArgsRel a (Args.P24 x₁ x₂ y) → P124 a) :
(x₁ * y).Numeric ∧ (x₂ * y).Numeric := by
constructor <;> refine ih' (Args.P1 _ _) (TransGen.single ?_)
· exact (cutExpand_add_right {y}).2 <| (cutExpand_add_left {x₁}).2 cutExpand_zero
· exact (cutExpand_add_right {x₂, y}).2 cutExpand_zero
/-- Symmetry properties of `IH24`. -/
lemma ih24_neg : IH24 x₁ x₂ y → IH24 (-x₂) (-x₁) y ∧ IH24 x₁ x₂ (-y) := by
simp_rw [IH24, ← P24_neg_right, isOption_neg]
refine fun h ↦ ⟨fun z ↦ ⟨?_, ?_, ?_⟩,
fun z ↦ ⟨(@h z).1, (@h z).2.1, P24_neg_right.2 ∘ (@h <| -z).2.2⟩⟩
all_goals
rw [P24_neg_left]
simp only [neg_neg]
first | exact (@h <| -z).2.1 | exact (@h <| -z).1 | exact (@h z).2.2
/-- Symmetry properties of `IH4`. -/
lemma ih4_neg : IH4 x₁ x₂ y → IH4 (-x₂) (-x₁) y ∧ IH4 x₁ x₂ (-y) := by
simp_rw [IH4, isOption_neg]
refine fun h ↦ ⟨fun z w h' ↦ ?_, fun z w h' ↦ ?_⟩
· convert (h h').symm using 2 <;> rw [P2_neg_left, neg_neg]
· convert h h' using 2 <;> rw [P2_neg_right]
lemma mulOption_lt_mul_of_equiv (hn : x₁.Numeric) (h : IH24 x₁ x₂ y) (he : x₁ ≈ x₂) (i j) :
⟦mulOption x₁ y i j⟧ < (⟦x₂ * y⟧ : Game) := by
convert sub_lt_iff_lt_add'.2 ((((@h _).1 <| IsOption.moveLeft i).2 _).1 j) using 1
· rw [← ((@h _).2.2 <| IsOption.moveLeft j).1 he]
rfl
· rw [← lt_congr_right he]
apply hn.moveLeft_lt
/-- P2 follows from specialized induction hypotheses (one half of the equality). -/
theorem mul_right_le_of_equiv (h₁ : x₁.Numeric) (h₂ : x₂.Numeric)
(h₁₂ : IH24 x₁ x₂ y) (h₂₁ : IH24 x₂ x₁ y) (he : x₁ ≈ x₂) : x₁ * y ≤ x₂ * y := by
have he' := neg_equiv_neg_iff.2 he
apply PGame.le_of_forall_lt <;> simp_rw [lt_iff_game_lt]
· rw [leftMoves_mul_iff (_ > ·)]
refine ⟨mulOption_lt_mul_of_equiv h₁ h₁₂ he, ?_⟩
rw [← quot_neg_mul_neg]
exact mulOption_lt_mul_of_equiv h₁.neg (ih24_neg <| (ih24_neg h₂₁).1).2 he'
· rw [rightMoves_mul_iff]
constructor <;> intros <;> rw [lt_neg]
· rw [← quot_mul_neg]
apply mulOption_lt_mul_of_equiv h₂ (ih24_neg h₂₁).2 (symm he)
· rw [← quot_neg_mul]
apply mulOption_lt_mul_of_equiv h₂.neg (ih24_neg h₁₂).1 (symm he')
/-- The statement that all left options of `x * y` of the first kind are less than itself. -/
def MulOptionsLTMul (x y : PGame) : Prop := ∀ ⦃i j⦄, ⟦mulOption x y i j⟧ < (⟦x * y⟧ : Game)
/-- That the left options of `x * y` are less than itself and the right options are greater, which
is part of the condition that `x * y` is numeric, is equivalent to the conjunction of various
`MulOptionsLTMul` statements for `x`, `y` and their negations. We only show the forward
direction. -/
lemma mulOptionsLTMul_of_numeric (hn : (x * y).Numeric) :
(MulOptionsLTMul x y ∧ MulOptionsLTMul (-x) (-y)) ∧
(MulOptionsLTMul x (-y) ∧ MulOptionsLTMul (-x) y) := by
constructor
· have h := hn.moveLeft_lt
simp_rw [lt_iff_game_lt] at h
convert (leftMoves_mul_iff <| GT.gt _).1 h
rw [← quot_neg_mul_neg]
rfl
· have h := hn.lt_moveRight
simp_rw [lt_iff_game_lt, rightMoves_mul_iff] at h
refine h.imp ?_ ?_ <;> refine forall₂_imp fun a b ↦ ?_
all_goals
rw [lt_neg]
first | rw [quot_mul_neg] | rw [quot_neg_mul]
exact id
/-- A condition just enough to deduce P3, which will always be used with `x'` being a left
option of `x₂`. When `y₁` is a left option of `y₂`, it can be deduced from induction hypotheses
`IH24 x₁ x₂ y₂`, `IH4 x₁ x₂ y₂`, and `(x₂ * y₂).Numeric` (`ih3_of_ih`); when `y₁` is
not necessarily an option of `y₂`, it follows from the induction hypothesis for P3 (with `x₂`
replaced by a left option `x'`) after the `main` theorem (P124) is established, and is used to
prove P3 in full (`P3_of_lt_of_lt`). -/
def IH3 (x₁ x' x₂ y₁ y₂ : PGame) : Prop :=
P2 x₁ x' y₁ ∧ P2 x₁ x' y₂ ∧ P3 x' x₂ y₁ y₂ ∧ (x₁ < x' → P3 x₁ x' y₁ y₂)
lemma ih3_of_ih (h24 : IH24 x₁ x₂ y) (h4 : IH4 x₁ x₂ y) (hl : MulOptionsLTMul x₂ y) (i j) :
IH3 x₁ (x₂.moveLeft i) x₂ (y.moveLeft j) y :=
have ml := @IsOption.moveLeft
have h24 := (@h24 _).2.1 (ml i)
⟨(h4 <| ml j).2 (ml i), h24.1, mulOption_lt_mul_iff_P3.1 (@hl i j), fun l ↦ (h24.2 l).1 _⟩
lemma P3_of_le_left {y₁ y₂} (i) (h : IH3 x₁ (x₂.moveLeft i) x₂ y₁ y₂) (hl : x₁ ≤ x₂.moveLeft i) :
P3 x₁ x₂ y₁ y₂ := by
obtain (hl|he) := lt_or_equiv_of_le hl
· exact (h.2.2.2 hl).trans h.2.2.1
· rw [P3, h.1 he, h.2.1 he]
exact h.2.2.1
/-- P3 follows from `IH3` (so P4 (with `y₁` a left option of `y₂`) follows from the induction
hypothesis). -/
theorem P3_of_lt {y₁ y₂} (h : ∀ i, IH3 x₁ (x₂.moveLeft i) x₂ y₁ y₂)
(hs : ∀ i, IH3 (-x₂) ((-x₁).moveLeft i) (-x₁) y₁ y₂) (hl : x₁ < x₂) :
P3 x₁ x₂ y₁ y₂ := by
obtain (⟨i,hi⟩|⟨i,hi⟩) := lf_iff_exists_le.1 (lf_of_lt hl)
· exact P3_of_le_left i (h i) hi
· exact P3_neg.2 <| P3_of_le_left _ (hs _) <| by
rw [moveLeft_neg]
exact neg_le_neg (le_iff_game_le.1 hi)
/-- The main chunk of Theorem 8 in [Conway2001] / Theorem 3.8 in [SchleicherStoll]. -/
theorem main (a : Args) : a.Numeric → P124 a := by
apply argsRel_wf.induction a
intros a ih ha
replace ih : ∀ a', ArgsRel a' a → P124 a' := fun a' hr ↦ ih a' hr (hr.numeric_closed ha)
cases a with
/- P1 -/
| P1 x y =>
rw [Args.numeric_P1] at ha
exact P1_of_ih ih ha.1 ha.2
| P24 x₁ x₂ y =>
have h₁₂ := ih₁₂ ih
have h₂₁ := ih₂₁ ih
have h4 := ih4 ih
obtain ⟨h₁₂x, h₁₂y⟩ := ih24_neg h₁₂
obtain ⟨h4x, h4y⟩ := ih4_neg h4
refine ⟨fun he ↦ Quotient.sound ?_, fun hl ↦ ?_⟩
· /- P2 -/
rw [Args.numeric_P24] at ha
exact ⟨mul_right_le_of_equiv ha.1 ha.2.1 h₁₂ h₂₁ he,
mul_right_le_of_equiv ha.2.1 ha.1 h₂₁ h₁₂ (symm he)⟩
· /- P4 -/
obtain ⟨hn₁, hn₂⟩ := numeric_of_ih ih
obtain ⟨⟨h₁, -⟩, h₂, -⟩ := mulOptionsLTMul_of_numeric hn₂
obtain ⟨⟨-, h₃⟩, -, h₄⟩ := mulOptionsLTMul_of_numeric hn₁
constructor <;> intro <;> refine P3_of_lt ?_ ?_ hl <;> intro <;> apply ih3_of_ih
any_goals assumption
exacts [(ih24_neg h₁₂y).1, (ih4_neg h4y).1]
end Surreal.Multiplication
namespace SetTheory.PGame
open Surreal.Multiplication
variable {x x₁ x₂ y y₁ y₂ : PGame.{u}}
theorem Numeric.mul (hx : x.Numeric) (hy : y.Numeric) : Numeric (x * y) :=
main _ <| Args.numeric_P1.mpr ⟨hx, hy⟩
theorem P24 (hx₁ : x₁.Numeric) (hx₂ : x₂.Numeric) (hy : y.Numeric) : P24 x₁ x₂ y :=
main _ <| Args.numeric_P24.mpr ⟨hx₁, hx₂, hy⟩
theorem Equiv.mul_congr_left (hx₁ : x₁.Numeric) (hx₂ : x₂.Numeric) (hy : y.Numeric)
(he : x₁ ≈ x₂) : x₁ * y ≈ x₂ * y :=
equiv_iff_game_eq.2 <| (P24 hx₁ hx₂ hy).1 he
theorem Equiv.mul_congr_right (hx : x.Numeric) (hy₁ : y₁.Numeric) (hy₂ : y₂.Numeric)
(he : y₁ ≈ y₂) : x * y₁ ≈ x * y₂ :=
.trans (mul_comm_equiv _ _) <| .trans (mul_congr_left hy₁ hy₂ hx he) (mul_comm_equiv _ _)
theorem Equiv.mul_congr (hx₁ : x₁.Numeric) (hx₂ : x₂.Numeric)
(hy₁ : y₁.Numeric) (hy₂ : y₂.Numeric) (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ * y₁ ≈ x₂ * y₂ :=
.trans (mul_congr_left hx₁ hx₂ hy₁ hx) (mul_congr_right hx₂ hy₁ hy₂ hy)
open Prod.GameAdd
/-- One additional inductive argument that supplies the last missing part of Theorem 8. -/
theorem P3_of_lt_of_lt (hx₁ : x₁.Numeric) (hx₂ : x₂.Numeric) (hy₁ : y₁.Numeric) (hy₂ : y₂.Numeric)
(hx : x₁ < x₂) (hy : y₁ < y₂) : P3 x₁ x₂ y₁ y₂ := by
revert x₁ x₂
rw [← Prod.forall']
refine (wf_isOption.prod_gameAdd wf_isOption).fix ?_
rintro ⟨x₁, x₂⟩ ih hx₁ hx₂ hx
refine P3_of_lt ?_ ?_ hx <;> intro i
· have hi := hx₂.moveLeft i
exact ⟨(P24 hx₁ hi hy₁).1, (P24 hx₁ hi hy₂).1,
P3_comm.2 <| ((P24 hy₁ hy₂ hx₂).2 hy).1 _,
ih _ (snd <| IsOption.moveLeft i) hx₁ hi⟩
· have hi := hx₁.neg.moveLeft i
exact ⟨(P24 hx₂.neg hi hy₁).1, (P24 hx₂.neg hi hy₂).1,
P3_comm.2 <| ((P24 hy₁ hy₂ hx₁).2 hy).2 _, by
rw [moveLeft_neg', ← P3_neg, neg_lt_neg_iff]
exact ih _ (fst <| IsOption.moveRight _) (hx₁.moveRight _) hx₂⟩
theorem Numeric.mul_pos (hx₁ : x₁.Numeric) (hx₂ : x₂.Numeric) (hp₁ : 0 < x₁) (hp₂ : 0 < x₂) :
0 < x₁ * x₂ := by
rw [lt_iff_game_lt]
have := P3_of_lt_of_lt numeric_zero hx₁ numeric_zero hx₂ hp₁ hp₂
simp_rw [P3, quot_zero_mul, quot_mul_zero, add_lt_add_iff_left] at this
exact this
end SetTheory.PGame
namespace Surreal
open SetTheory.PGame.Equiv
noncomputable instance : LinearOrderedCommRing Surreal where
__ := Surreal.orderedAddCommGroup
mul := Surreal.lift₂ (fun x y ox oy ↦ ⟦⟨x * y, ox.mul oy⟩⟧)
(fun ox₁ oy₁ ox₂ oy₂ hx hy ↦ Quotient.sound <| mul_congr ox₁ ox₂ oy₁ oy₂ hx hy)
mul_assoc := by rintro ⟨_⟩ ⟨_⟩ ⟨_⟩; exact Quotient.sound (mul_assoc_equiv _ _ _)
one := mk 1 numeric_one
one_mul := by rintro ⟨_⟩; exact Quotient.sound (one_mul_equiv _)
mul_one := by rintro ⟨_⟩; exact Quotient.sound (mul_one_equiv _)
left_distrib := by rintro ⟨_⟩ ⟨_⟩ ⟨_⟩; exact Quotient.sound (left_distrib_equiv _ _ _)
right_distrib := by rintro ⟨_⟩ ⟨_⟩ ⟨_⟩; exact Quotient.sound (right_distrib_equiv _ _ _)
mul_comm := by rintro ⟨_⟩ ⟨_⟩; exact Quotient.sound (mul_comm_equiv _ _)
le := lift₂ (fun x y _ _ ↦ x ≤ y) (fun _ _ _ _ hx hy ↦ propext <| le_congr hx hy)
lt := lift₂ (fun x y _ _ ↦ x < y) (fun _ _ _ _ hx hy ↦ propext <| lt_congr hx hy)
le_refl := by rintro ⟨_⟩; apply @le_rfl PGame
le_trans := by rintro ⟨_⟩ ⟨_⟩ ⟨_⟩; apply @le_trans PGame
lt_iff_le_not_le := by rintro ⟨_⟩ ⟨_⟩; exact lt_iff_le_not_le
le_antisymm := by rintro ⟨_⟩ ⟨_⟩ h₁ h₂; exact Quotient.sound ⟨h₁, h₂⟩
add_le_add_left := by rintro ⟨_⟩ ⟨_⟩ hx ⟨_⟩; exact add_le_add_left hx _
zero_le_one := PGame.zero_lt_one.le
zero_mul := by rintro ⟨_⟩; exact Quotient.sound (zero_mul_equiv _)
mul_zero := by rintro ⟨_⟩; exact Quotient.sound (mul_zero_equiv _)
exists_pair_ne := ⟨0, 1, ne_of_lt PGame.zero_lt_one⟩
le_total := by rintro ⟨x⟩ ⟨y⟩; exact (le_or_gf x.1 y.1).imp id (fun h ↦ h.le y.2 x.2)
mul_pos := by rintro ⟨x⟩ ⟨y⟩; exact x.2.mul_pos y.2
decidableLE := Classical.decRel _
end Surreal
|
SetTheory\ZFC\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.Set.Lattice
import Mathlib.Logic.Small.Basic
import Mathlib.Logic.Function.OfArity
import Mathlib.Order.WellFounded
/-!
# A model of ZFC
In this file, we model Zermelo-Fraenkel set theory (+ Choice) using Lean's underlying type theory.
We do this in four main steps:
* Define pre-sets inductively.
* Define extensional equivalence on pre-sets and give it a `setoid` instance.
* Define ZFC sets by quotienting pre-sets by extensional equivalence.
* Define classes as sets of ZFC sets.
Then the rest is usual set theory.
## The model
* `PSet`: Pre-set. A pre-set is inductively defined by its indexing type and its members, which are
themselves pre-sets.
* `ZFSet`: ZFC set. Defined as `PSet` quotiented by `PSet.Equiv`, the extensional equivalence.
* `Class`: Class. Defined as `Set ZFSet`.
* `ZFSet.choice`: Axiom of choice. Proved from Lean's axiom of choice.
## Other definitions
* `PSet.Type`: Underlying type of a pre-set.
* `PSet.Func`: Underlying family of pre-sets of a pre-set.
* `PSet.Equiv`: Extensional equivalence of pre-sets. Defined inductively.
* `PSet.omega`, `ZFSet.omega`: The von Neumann ordinal `ω` as a `PSet`, as a `Set`.
* `PSet.Arity.Equiv`: Extensional equivalence of `n`-ary `PSet`-valued functions. Extension of
`PSet.Equiv`.
* `PSet.Resp`: Collection of `n`-ary `PSet`-valued functions that respect extensional equivalence.
* `PSet.eval`: Turns a `PSet`-valued function that respect extensional equivalence into a
`ZFSet`-valued function.
* `Classical.allDefinable`: All functions are classically definable.
* `ZFSet.IsFunc` : Predicate that a ZFC set is a subset of `x × y` that can be considered as a ZFC
function `x → y`. That is, each member of `x` is related by the ZFC set to exactly one member of
`y`.
* `ZFSet.funs`: ZFC set of ZFC functions `x → y`.
* `ZFSet.Hereditarily p x`: Predicate that every set in the transitive closure of `x` has property
`p`.
* `Class.iota`: Definite description operator.
## Notes
To avoid confusion between the Lean `Set` and the ZFC `Set`, docstrings in this file refer to them
respectively as "`Set`" and "ZFC set".
## TODO
Prove `ZFSet.mapDefinableAux` computably.
-/
universe u v
open Function (OfArity)
/-- The type of pre-sets in universe `u`. A pre-set
is a family of pre-sets indexed by a type in `Type u`.
The ZFC universe is defined as a quotient of this
to ensure extensionality. -/
inductive PSet : Type (u + 1)
| mk (α : Type u) (A : α → PSet) : PSet
namespace PSet
/-- The underlying type of a pre-set -/
def «Type» : PSet → Type u
| ⟨α, _⟩ => α
/-- The underlying pre-set family of a pre-set -/
def Func : ∀ x : PSet, x.Type → PSet
| ⟨_, A⟩ => A
@[simp]
theorem mk_type (α A) : «Type» ⟨α, A⟩ = α :=
rfl
@[simp]
theorem mk_func (α A) : Func ⟨α, A⟩ = A :=
rfl
@[simp]
theorem eta : ∀ x : PSet, mk x.Type x.Func = x
| ⟨_, _⟩ => rfl
/-- Two pre-sets are extensionally equivalent if every element of the first family is extensionally
equivalent to some element of the second family and vice-versa. -/
def Equiv : PSet → PSet → Prop
| ⟨_, A⟩, ⟨_, B⟩ => (∀ a, ∃ b, Equiv (A a) (B b)) ∧ (∀ b, ∃ a, Equiv (A a) (B b))
theorem equiv_iff :
∀ {x y : PSet},
Equiv x y ↔ (∀ i, ∃ j, Equiv (x.Func i) (y.Func j)) ∧ ∀ j, ∃ i, Equiv (x.Func i) (y.Func j)
| ⟨_, _⟩, ⟨_, _⟩ => Iff.rfl
theorem Equiv.exists_left {x y : PSet} (h : Equiv x y) : ∀ i, ∃ j, Equiv (x.Func i) (y.Func j) :=
(equiv_iff.1 h).1
theorem Equiv.exists_right {x y : PSet} (h : Equiv x y) : ∀ j, ∃ i, Equiv (x.Func i) (y.Func j) :=
(equiv_iff.1 h).2
@[refl]
protected theorem Equiv.refl : ∀ x, Equiv x x
| ⟨_, _⟩ => ⟨fun a => ⟨a, Equiv.refl _⟩, fun a => ⟨a, Equiv.refl _⟩⟩
protected theorem Equiv.rfl {x} : Equiv x x :=
Equiv.refl x
protected theorem Equiv.euc : ∀ {x y z}, Equiv x y → Equiv z y → Equiv x z
| ⟨_, _⟩, ⟨_, _⟩, ⟨_, _⟩, ⟨αβ, βα⟩, ⟨γβ, βγ⟩ =>
⟨ fun a =>
let ⟨b, ab⟩ := αβ a
let ⟨c, bc⟩ := βγ b
⟨c, Equiv.euc ab bc⟩,
fun c =>
let ⟨b, cb⟩ := γβ c
let ⟨a, ba⟩ := βα b
⟨a, Equiv.euc ba cb⟩ ⟩
@[symm]
protected theorem Equiv.symm {x y} : Equiv x y → Equiv y x :=
(Equiv.refl y).euc
protected theorem Equiv.comm {x y} : Equiv x y ↔ Equiv y x :=
⟨Equiv.symm, Equiv.symm⟩
@[trans]
protected theorem Equiv.trans {x y z} (h1 : Equiv x y) (h2 : Equiv y z) : Equiv x z :=
h1.euc h2.symm
protected theorem equiv_of_isEmpty (x y : PSet) [IsEmpty x.Type] [IsEmpty y.Type] : Equiv x y :=
equiv_iff.2 <| by simp
instance setoid : Setoid PSet :=
⟨PSet.Equiv, Equiv.refl, Equiv.symm, Equiv.trans⟩
/-- A pre-set is a subset of another pre-set if every element of the first family is extensionally
equivalent to some element of the second family. -/
protected def Subset (x y : PSet) : Prop :=
∀ a, ∃ b, Equiv (x.Func a) (y.Func b)
instance : HasSubset PSet :=
⟨PSet.Subset⟩
instance : IsRefl PSet (· ⊆ ·) :=
⟨fun _ a => ⟨a, Equiv.refl _⟩⟩
instance : IsTrans PSet (· ⊆ ·) :=
⟨fun x y z hxy hyz a => by
cases' hxy a with b hb
cases' hyz b with c hc
exact ⟨c, hb.trans hc⟩⟩
theorem Equiv.ext : ∀ x y : PSet, Equiv x y ↔ x ⊆ y ∧ y ⊆ x
| ⟨_, _⟩, ⟨_, _⟩ =>
⟨fun ⟨αβ, βα⟩ =>
⟨αβ, fun b =>
let ⟨a, h⟩ := βα b
⟨a, Equiv.symm h⟩⟩,
fun ⟨αβ, βα⟩ =>
⟨αβ, fun b =>
let ⟨a, h⟩ := βα b
⟨a, Equiv.symm h⟩⟩⟩
theorem Subset.congr_left : ∀ {x y z : PSet}, Equiv x y → (x ⊆ z ↔ y ⊆ z)
| ⟨_, _⟩, ⟨_, _⟩, ⟨_, _⟩, ⟨αβ, βα⟩ =>
⟨fun αγ b =>
let ⟨a, ba⟩ := βα b
let ⟨c, ac⟩ := αγ a
⟨c, (Equiv.symm ba).trans ac⟩,
fun βγ a =>
let ⟨b, ab⟩ := αβ a
let ⟨c, bc⟩ := βγ b
⟨c, Equiv.trans ab bc⟩⟩
theorem Subset.congr_right : ∀ {x y z : PSet}, Equiv x y → (z ⊆ x ↔ z ⊆ y)
| ⟨_, _⟩, ⟨_, _⟩, ⟨_, _⟩, ⟨αβ, βα⟩ =>
⟨fun γα c =>
let ⟨a, ca⟩ := γα c
let ⟨b, ab⟩ := αβ a
⟨b, ca.trans ab⟩,
fun γβ c =>
let ⟨b, cb⟩ := γβ c
let ⟨a, ab⟩ := βα b
⟨a, cb.trans (Equiv.symm ab)⟩⟩
/-- `x ∈ y` as pre-sets if `x` is extensionally equivalent to a member of the family `y`. -/
protected def Mem (x y : PSet.{u}) : Prop :=
∃ b, Equiv x (y.Func b)
instance : Membership PSet PSet :=
⟨PSet.Mem⟩
theorem Mem.mk {α : Type u} (A : α → PSet) (a : α) : A a ∈ mk α A :=
⟨a, Equiv.refl (A a)⟩
theorem func_mem (x : PSet) (i : x.Type) : x.Func i ∈ x := by
cases x
apply Mem.mk
theorem Mem.ext : ∀ {x y : PSet.{u}}, (∀ w : PSet.{u}, w ∈ x ↔ w ∈ y) → Equiv x y
| ⟨_, A⟩, ⟨_, B⟩, h =>
⟨fun a => (h (A a)).1 (Mem.mk A a), fun b =>
let ⟨a, ha⟩ := (h (B b)).2 (Mem.mk B b)
⟨a, ha.symm⟩⟩
theorem Mem.congr_right : ∀ {x y : PSet.{u}}, Equiv x y → ∀ {w : PSet.{u}}, w ∈ x ↔ w ∈ y
| ⟨_, _⟩, ⟨_, _⟩, ⟨αβ, βα⟩, _ =>
⟨fun ⟨a, ha⟩ =>
let ⟨b, hb⟩ := αβ a
⟨b, ha.trans hb⟩,
fun ⟨b, hb⟩ =>
let ⟨a, ha⟩ := βα b
⟨a, hb.euc ha⟩⟩
theorem equiv_iff_mem {x y : PSet.{u}} : Equiv x y ↔ ∀ {w : PSet.{u}}, w ∈ x ↔ w ∈ y :=
⟨Mem.congr_right,
match x, y with
| ⟨_, A⟩, ⟨_, B⟩ => fun h =>
⟨fun a => h.1 (Mem.mk A a), fun b =>
let ⟨a, h⟩ := h.2 (Mem.mk B b)
⟨a, h.symm⟩⟩⟩
theorem Mem.congr_left : ∀ {x y : PSet.{u}}, Equiv x y → ∀ {w : PSet.{u}}, x ∈ w ↔ y ∈ w
| _, _, h, ⟨_, _⟩ => ⟨fun ⟨a, ha⟩ => ⟨a, h.symm.trans ha⟩, fun ⟨a, ha⟩ => ⟨a, h.trans ha⟩⟩
private theorem mem_wf_aux : ∀ {x y : PSet.{u}}, Equiv x y → Acc (· ∈ ·) y
| ⟨α, A⟩, ⟨β, B⟩, H =>
⟨_, by
rintro ⟨γ, C⟩ ⟨b, hc⟩
cases' H.exists_right b with a ha
have H := ha.trans hc.symm
rw [mk_func] at H
exact mem_wf_aux H⟩
theorem mem_wf : @WellFounded PSet (· ∈ ·) :=
⟨fun x => mem_wf_aux <| Equiv.refl x⟩
instance : WellFoundedRelation PSet :=
⟨_, mem_wf⟩
instance : IsAsymm PSet (· ∈ ·) :=
mem_wf.isAsymm
instance : IsIrrefl PSet (· ∈ ·) :=
mem_wf.isIrrefl
theorem mem_asymm {x y : PSet} : x ∈ y → y ∉ x :=
asymm
theorem mem_irrefl (x : PSet) : x ∉ x :=
irrefl x
/-- Convert a pre-set to a `Set` of pre-sets. -/
def toSet (u : PSet.{u}) : Set PSet.{u} :=
{ x | x ∈ u }
@[simp]
theorem mem_toSet (a u : PSet.{u}) : a ∈ u.toSet ↔ a ∈ u :=
Iff.rfl
/-- A nonempty set is one that contains some element. -/
protected def Nonempty (u : PSet) : Prop :=
u.toSet.Nonempty
theorem nonempty_def (u : PSet) : u.Nonempty ↔ ∃ x, x ∈ u :=
Iff.rfl
theorem nonempty_of_mem {x u : PSet} (h : x ∈ u) : u.Nonempty :=
⟨x, h⟩
@[simp]
theorem nonempty_toSet_iff {u : PSet} : u.toSet.Nonempty ↔ u.Nonempty :=
Iff.rfl
theorem nonempty_type_iff_nonempty {x : PSet} : Nonempty x.Type ↔ PSet.Nonempty x :=
⟨fun ⟨i⟩ => ⟨_, func_mem _ i⟩, fun ⟨_, j, _⟩ => ⟨j⟩⟩
theorem nonempty_of_nonempty_type (x : PSet) [h : Nonempty x.Type] : PSet.Nonempty x :=
nonempty_type_iff_nonempty.1 h
/-- Two pre-sets are equivalent iff they have the same members. -/
theorem Equiv.eq {x y : PSet} : Equiv x y ↔ toSet x = toSet y :=
equiv_iff_mem.trans Set.ext_iff.symm
instance : Coe PSet (Set PSet) :=
⟨toSet⟩
/-- The empty pre-set -/
protected def empty : PSet :=
⟨_, PEmpty.elim⟩
instance : EmptyCollection PSet :=
⟨PSet.empty⟩
instance : Inhabited PSet :=
⟨∅⟩
instance : IsEmpty («Type» ∅) :=
⟨PEmpty.elim⟩
@[simp]
theorem not_mem_empty (x : PSet.{u}) : x ∉ (∅ : PSet.{u}) :=
IsEmpty.exists_iff.1
@[simp]
theorem toSet_empty : toSet ∅ = ∅ := by simp [toSet]
@[simp]
theorem empty_subset (x : PSet.{u}) : (∅ : PSet) ⊆ x := fun x => x.elim
@[simp]
theorem not_nonempty_empty : ¬PSet.Nonempty ∅ := by simp [PSet.Nonempty]
protected theorem equiv_empty (x : PSet) [IsEmpty x.Type] : Equiv x ∅ :=
PSet.equiv_of_isEmpty x _
/-- Insert an element into a pre-set -/
protected def insert (x y : PSet) : PSet :=
⟨Option y.Type, fun o => Option.casesOn o x y.Func⟩
instance : Insert PSet PSet :=
⟨PSet.insert⟩
instance : Singleton PSet PSet :=
⟨fun s => insert s ∅⟩
instance : LawfulSingleton PSet PSet :=
⟨fun _ => rfl⟩
instance (x y : PSet) : Inhabited (insert x y).Type :=
inferInstanceAs (Inhabited <| Option y.Type)
/-- The n-th von Neumann ordinal -/
def ofNat : ℕ → PSet
| 0 => ∅
| n + 1 => insert (ofNat n) (ofNat n)
/-- The von Neumann ordinal ω -/
def omega : PSet :=
⟨ULift ℕ, fun n => ofNat n.down⟩
/-- The pre-set separation operation `{x ∈ a | p x}` -/
protected def sep (p : PSet → Prop) (x : PSet) : PSet :=
⟨{ a // p (x.Func a) }, fun y => x.Func y.1⟩
instance : Sep PSet PSet :=
⟨PSet.sep⟩
/-- The pre-set powerset operator -/
def powerset (x : PSet) : PSet :=
⟨Set x.Type, fun p => ⟨{ a // p a }, fun y => x.Func y.1⟩⟩
@[simp]
theorem mem_powerset : ∀ {x y : PSet}, y ∈ powerset x ↔ y ⊆ x
| ⟨_, A⟩, ⟨_, B⟩ =>
⟨fun ⟨_, e⟩ => (Subset.congr_left e).2 fun ⟨a, _⟩ => ⟨a, Equiv.refl (A a)⟩, fun βα =>
⟨{ a | ∃ b, Equiv (B b) (A a) }, fun b =>
let ⟨a, ba⟩ := βα b
⟨⟨a, b, ba⟩, ba⟩,
fun ⟨_, b, ba⟩ => ⟨b, ba⟩⟩⟩
/-- The pre-set union operator -/
def sUnion (a : PSet) : PSet :=
⟨Σx, (a.Func x).Type, fun ⟨x, y⟩ => (a.Func x).Func y⟩
@[inherit_doc]
prefix:110 "⋃₀ " => sUnion
@[simp]
theorem mem_sUnion : ∀ {x y : PSet.{u}}, y ∈ ⋃₀ x ↔ ∃ z ∈ x, y ∈ z
| ⟨α, A⟩, y =>
⟨fun ⟨⟨a, c⟩, (e : Equiv y ((A a).Func c))⟩ =>
have : Func (A a) c ∈ mk (A a).Type (A a).Func := Mem.mk (A a).Func c
⟨_, Mem.mk _ _, (Mem.congr_left e).2 (by rwa [eta] at this)⟩,
fun ⟨⟨β, B⟩, ⟨a, (e : Equiv (mk β B) (A a))⟩, ⟨b, yb⟩⟩ => by
rw [← eta (A a)] at e
exact
let ⟨βt, _⟩ := e
let ⟨c, bc⟩ := βt b
⟨⟨a, c⟩, yb.trans bc⟩⟩
@[simp]
theorem toSet_sUnion (x : PSet.{u}) : (⋃₀ x).toSet = ⋃₀ (toSet '' x.toSet) := by
ext
simp
/-- The image of a function from pre-sets to pre-sets. -/
def image (f : PSet.{u} → PSet.{u}) (x : PSet.{u}) : PSet :=
⟨x.Type, f ∘ x.Func⟩
-- Porting note: H arguments made explicit.
theorem mem_image {f : PSet.{u} → PSet.{u}} (H : ∀ x y, Equiv x y → Equiv (f x) (f y)) :
∀ {x y : PSet.{u}}, y ∈ image f x ↔ ∃ z ∈ x, Equiv y (f z)
| ⟨_, A⟩, _ =>
⟨fun ⟨a, ya⟩ => ⟨A a, Mem.mk A a, ya⟩, fun ⟨_, ⟨a, za⟩, yz⟩ => ⟨a, yz.trans <| H _ _ za⟩⟩
/-- Universe lift operation -/
protected def Lift : PSet.{u} → PSet.{max u v}
| ⟨α, A⟩ => ⟨ULift.{v, u} α, fun ⟨x⟩ => PSet.Lift (A x)⟩
-- intended to be used with explicit universe parameters
/-- Embedding of one universe in another -/
@[nolint checkUnivs]
def embed : PSet.{max (u + 1) v} :=
⟨ULift.{v, u + 1} PSet, fun ⟨x⟩ => PSet.Lift.{u, max (u + 1) v} x⟩
theorem lift_mem_embed : ∀ x : PSet.{u}, PSet.Lift.{u, max (u + 1) v} x ∈ embed.{u, v} := fun x =>
⟨⟨x⟩, Equiv.rfl⟩
/-- Function equivalence is defined so that `f ~ g` iff `∀ x y, x ~ y → f x ~ g y`. This extends to
equivalence of `n`-ary functions. -/
def Arity.Equiv : ∀ {n}, OfArity PSet.{u} PSet.{u} n → OfArity PSet.{u} PSet.{u} n → Prop
| 0, a, b => PSet.Equiv a b
| _ + 1, a, b => ∀ x y : PSet, PSet.Equiv x y → Arity.Equiv (a x) (b y)
theorem Arity.equiv_const {a : PSet.{u}} :
∀ n, Arity.Equiv (OfArity.const PSet.{u} a n) (OfArity.const PSet.{u} a n)
| 0 => Equiv.rfl
| _ + 1 => fun _ _ _ => Arity.equiv_const _
/-- `resp n` is the collection of n-ary functions on `PSet` that respect
equivalence, i.e. when the inputs are equivalent the output is as well. -/
def Resp (n) :=
{ x : OfArity PSet.{u} PSet.{u} n // Arity.Equiv x x }
instance Resp.inhabited {n} : Inhabited (Resp n) :=
⟨⟨OfArity.const _ default _, Arity.equiv_const _⟩⟩
/-- The `n`-ary image of a `(n + 1)`-ary function respecting equivalence as a function respecting
equivalence. -/
def Resp.f {n} (f : Resp (n + 1)) (x : PSet) : Resp n :=
⟨f.1 x, f.2 _ _ <| Equiv.refl x⟩
/-- Function equivalence for functions respecting equivalence. See `PSet.Arity.Equiv`. -/
def Resp.Equiv {n} (a b : Resp n) : Prop :=
Arity.Equiv a.1 b.1
@[refl]
protected theorem Resp.Equiv.refl {n} (a : Resp n) : Resp.Equiv a a :=
a.2
protected theorem Resp.Equiv.euc :
∀ {n} {a b c : Resp n}, Resp.Equiv a b → Resp.Equiv c b → Resp.Equiv a c
| 0, _, _, _, hab, hcb => PSet.Equiv.euc hab hcb
| n + 1, a, b, c, hab, hcb => fun x y h =>
@Resp.Equiv.euc n (a.f x) (b.f y) (c.f y) (hab _ _ h) (hcb _ _ <| PSet.Equiv.refl y)
@[symm]
protected theorem Resp.Equiv.symm {n} {a b : Resp n} : Resp.Equiv a b → Resp.Equiv b a :=
(Resp.Equiv.refl b).euc
@[trans]
protected theorem Resp.Equiv.trans {n} {x y z : Resp n} (h1 : Resp.Equiv x y)
(h2 : Resp.Equiv y z) : Resp.Equiv x z :=
h1.euc h2.symm
instance Resp.setoid {n} : Setoid (Resp n) :=
⟨Resp.Equiv, Resp.Equiv.refl, Resp.Equiv.symm, Resp.Equiv.trans⟩
end PSet
/-- The ZFC universe of sets consists of the type of pre-sets,
quotiented by extensional equivalence. -/
def ZFSet : Type (u + 1) :=
Quotient PSet.setoid.{u}
namespace PSet
namespace Resp
/-- Helper function for `PSet.eval`. -/
def evalAux :
∀ {n},
{ f : Resp n → OfArity ZFSet.{u} ZFSet.{u} n // ∀ a b : Resp n, Resp.Equiv a b → f a = f b }
| 0 => ⟨fun a => ⟦a.1⟧, fun _ _ h => Quotient.sound h⟩
| n + 1 =>
let F : Resp (n + 1) → OfArity ZFSet ZFSet (n + 1) := fun a =>
@Quotient.lift _ _ PSet.setoid (fun x => evalAux.1 (a.f x)) fun _ _ h =>
evalAux.2 _ _ (a.2 _ _ h)
⟨F, fun b c h =>
funext <|
(@Quotient.ind _ _ fun q => F b q = F c q) fun z =>
evalAux.2 (Resp.f b z) (Resp.f c z) (h _ _ (PSet.Equiv.refl z))⟩
/-- An equivalence-respecting function yields an n-ary ZFC set function. -/
def eval (n) : Resp n → OfArity ZFSet.{u} ZFSet.{u} n :=
evalAux.1
theorem eval_val {n f x} :
(@eval (n + 1) f : ZFSet → OfArity ZFSet ZFSet n) ⟦x⟧ = eval n (Resp.f f x) :=
rfl
end Resp
/-- A set function is "definable" if it is the image of some n-ary pre-set
function. This isn't exactly definability, but is useful as a sufficient
condition for functions that have a computable image. -/
class inductive Definable (n) : OfArity ZFSet.{u} ZFSet.{u} n → Type (u + 1)
| mk (f) : Definable n (Resp.eval n f)
attribute [instance] Definable.mk
/-- The evaluation of a function respecting equivalence is definable, by that same function. -/
def Definable.EqMk {n} (f) :
∀ {s : OfArity ZFSet.{u} ZFSet.{u} n} (_ : Resp.eval _ f = s), Definable n s
| _, rfl => ⟨f⟩
/-- Turns a definable function into a function that respects equivalence. -/
def Definable.Resp {n} : ∀ (s : OfArity ZFSet.{u} ZFSet.{u} n) [Definable n s], Resp n
| _, ⟨f⟩ => f
theorem Definable.eq {n} :
∀ (s : OfArity ZFSet.{u} ZFSet.{u} n) [H : Definable n s], (@Definable.Resp n s H).eval _ = s
| _, ⟨_⟩ => rfl
end PSet
namespace Classical
open PSet
/-- All functions are classically definable. -/
noncomputable def allDefinable : ∀ {n} (F : OfArity ZFSet ZFSet n), Definable n F
| 0, F =>
let p := @Quotient.exists_rep PSet _ F
@Definable.EqMk 0 ⟨choose p, Equiv.rfl⟩ _ (choose_spec p)
| n + 1, (F : OfArity ZFSet ZFSet (n + 1)) => by
have I : (x : ZFSet) → Definable n (F x) := fun x => allDefinable (F x)
refine @Definable.EqMk (n + 1) ⟨fun x : PSet => (@Definable.Resp _ _ (I ⟦x⟧)).1, ?_⟩ _ ?_
· dsimp [Arity.Equiv]
intro x y h
rw [@Quotient.sound PSet _ _ _ h]
exact (Definable.Resp (F ⟦y⟧)).2
refine funext fun q => Quotient.inductionOn q fun x => ?_
simp_rw [Resp.eval_val, Resp.f]
exact @Definable.eq _ (F ⟦x⟧) (I ⟦x⟧)
end Classical
namespace ZFSet
open PSet
/-- Turns a pre-set into a ZFC set. -/
def mk : PSet → ZFSet :=
Quotient.mk''
@[simp]
theorem mk_eq (x : PSet) : @Eq ZFSet ⟦x⟧ (mk x) :=
rfl
@[simp]
theorem mk_out : ∀ x : ZFSet, mk x.out = x :=
Quotient.out_eq
theorem eq {x y : PSet} : mk x = mk y ↔ Equiv x y :=
Quotient.eq
theorem sound {x y : PSet} (h : PSet.Equiv x y) : mk x = mk y :=
Quotient.sound h
theorem exact {x y : PSet} : mk x = mk y → PSet.Equiv x y :=
Quotient.exact
@[simp]
theorem eval_mk {n f x} :
(@Resp.eval (n + 1) f : ZFSet → OfArity ZFSet ZFSet n) (mk x) = Resp.eval n (Resp.f f x) :=
rfl
/-- The membership relation for ZFC sets is inherited from the membership relation for pre-sets. -/
protected def Mem : ZFSet → ZFSet → Prop :=
Quotient.lift₂ PSet.Mem fun _ _ _ _ hx hy =>
propext ((Mem.congr_left hx).trans (Mem.congr_right hy))
instance : Membership ZFSet ZFSet :=
⟨ZFSet.Mem⟩
@[simp]
theorem mk_mem_iff {x y : PSet} : mk x ∈ mk y ↔ x ∈ y :=
Iff.rfl
/-- Convert a ZFC set into a `Set` of ZFC sets -/
def toSet (u : ZFSet.{u}) : Set ZFSet.{u} :=
{ x | x ∈ u }
@[simp]
theorem mem_toSet (a u : ZFSet.{u}) : a ∈ u.toSet ↔ a ∈ u :=
Iff.rfl
instance small_toSet (x : ZFSet.{u}) : Small.{u} x.toSet :=
Quotient.inductionOn x fun a => by
let f : a.Type → (mk a).toSet := fun i => ⟨mk <| a.Func i, func_mem a i⟩
suffices Function.Surjective f by exact small_of_surjective this
rintro ⟨y, hb⟩
induction y using Quotient.inductionOn
cases' hb with i h
exact ⟨i, Subtype.coe_injective (Quotient.sound h.symm)⟩
/-- A nonempty set is one that contains some element. -/
protected def Nonempty (u : ZFSet) : Prop :=
u.toSet.Nonempty
theorem nonempty_def (u : ZFSet) : u.Nonempty ↔ ∃ x, x ∈ u :=
Iff.rfl
theorem nonempty_of_mem {x u : ZFSet} (h : x ∈ u) : u.Nonempty :=
⟨x, h⟩
@[simp]
theorem nonempty_toSet_iff {u : ZFSet} : u.toSet.Nonempty ↔ u.Nonempty :=
Iff.rfl
/-- `x ⊆ y` as ZFC sets means that all members of `x` are members of `y`. -/
protected def Subset (x y : ZFSet.{u}) :=
∀ ⦃z⦄, z ∈ x → z ∈ y
instance hasSubset : HasSubset ZFSet :=
⟨ZFSet.Subset⟩
theorem subset_def {x y : ZFSet.{u}} : x ⊆ y ↔ ∀ ⦃z⦄, z ∈ x → z ∈ y :=
Iff.rfl
instance : IsRefl ZFSet (· ⊆ ·) :=
⟨fun _ _ => id⟩
instance : IsTrans ZFSet (· ⊆ ·) :=
⟨fun _ _ _ hxy hyz _ ha => hyz (hxy ha)⟩
@[simp]
theorem subset_iff : ∀ {x y : PSet}, mk x ⊆ mk y ↔ x ⊆ y
| ⟨_, A⟩, ⟨_, _⟩ =>
⟨fun h a => @h ⟦A a⟧ (Mem.mk A a), fun h z =>
Quotient.inductionOn z fun _ ⟨a, za⟩ =>
let ⟨b, ab⟩ := h a
⟨b, za.trans ab⟩⟩
@[simp]
theorem toSet_subset_iff {x y : ZFSet} : x.toSet ⊆ y.toSet ↔ x ⊆ y := by
simp [subset_def, Set.subset_def]
@[ext]
theorem ext {x y : ZFSet.{u}} : (∀ z : ZFSet.{u}, z ∈ x ↔ z ∈ y) → x = y :=
Quotient.inductionOn₂ x y fun _ _ h => Quotient.sound (Mem.ext fun w => h ⟦w⟧)
theorem toSet_injective : Function.Injective toSet := fun _ _ h => ext <| Set.ext_iff.1 h
@[simp]
theorem toSet_inj {x y : ZFSet} : x.toSet = y.toSet ↔ x = y :=
toSet_injective.eq_iff
instance : IsAntisymm ZFSet (· ⊆ ·) :=
⟨fun _ _ hab hba => ext fun c => ⟨@hab c, @hba c⟩⟩
/-- The empty ZFC set -/
protected def empty : ZFSet :=
mk ∅
instance : EmptyCollection ZFSet :=
⟨ZFSet.empty⟩
instance : Inhabited ZFSet :=
⟨∅⟩
@[simp]
theorem not_mem_empty (x) : x ∉ (∅ : ZFSet.{u}) :=
Quotient.inductionOn x PSet.not_mem_empty
@[simp]
theorem toSet_empty : toSet ∅ = ∅ := by simp [toSet]
@[simp]
theorem empty_subset (x : ZFSet.{u}) : (∅ : ZFSet) ⊆ x :=
Quotient.inductionOn x fun y => subset_iff.2 <| PSet.empty_subset y
@[simp]
theorem not_nonempty_empty : ¬ZFSet.Nonempty ∅ := by simp [ZFSet.Nonempty]
@[simp]
theorem nonempty_mk_iff {x : PSet} : (mk x).Nonempty ↔ x.Nonempty := by
refine ⟨?_, fun ⟨a, h⟩ => ⟨mk a, h⟩⟩
rintro ⟨a, h⟩
induction a using Quotient.inductionOn
exact ⟨_, h⟩
theorem eq_empty (x : ZFSet.{u}) : x = ∅ ↔ ∀ y : ZFSet.{u}, y ∉ x := by
simp [ZFSet.ext_iff]
theorem eq_empty_or_nonempty (u : ZFSet) : u = ∅ ∨ u.Nonempty := by
rw [eq_empty, ← not_exists]
apply em'
/-- `Insert x y` is the set `{x} ∪ y` -/
protected def Insert : ZFSet → ZFSet → ZFSet :=
Resp.eval 2
⟨PSet.insert, fun _ _ uv ⟨_, _⟩ ⟨_, _⟩ ⟨αβ, βα⟩ =>
⟨fun o =>
match o with
| some a =>
let ⟨b, hb⟩ := αβ a
⟨some b, hb⟩
| none => ⟨none, uv⟩,
fun o =>
match o with
| some b =>
let ⟨a, ha⟩ := βα b
⟨some a, ha⟩
| none => ⟨none, uv⟩⟩⟩
instance : Insert ZFSet ZFSet :=
⟨ZFSet.Insert⟩
instance : Singleton ZFSet ZFSet :=
⟨fun x => insert x ∅⟩
instance : LawfulSingleton ZFSet ZFSet :=
⟨fun _ => rfl⟩
@[simp]
theorem mem_insert_iff {x y z : ZFSet.{u}} : x ∈ insert y z ↔ x = y ∨ x ∈ z :=
Quotient.inductionOn₃ x y z fun x y ⟨α, A⟩ =>
show (x ∈ PSet.mk (Option α) fun o => Option.rec y A o) ↔ mk x = mk y ∨ x ∈ PSet.mk α A from
⟨fun m =>
match m with
| ⟨some a, ha⟩ => Or.inr ⟨a, ha⟩
| ⟨none, h⟩ => Or.inl (Quotient.sound h),
fun m =>
match m with
| Or.inr ⟨a, ha⟩ => ⟨some a, ha⟩
| Or.inl h => ⟨none, Quotient.exact h⟩⟩
theorem mem_insert (x y : ZFSet) : x ∈ insert x y :=
mem_insert_iff.2 <| Or.inl rfl
theorem mem_insert_of_mem {y z : ZFSet} (x) (h : z ∈ y) : z ∈ insert x y :=
mem_insert_iff.2 <| Or.inr h
@[simp]
theorem toSet_insert (x y : ZFSet) : (insert x y).toSet = insert x y.toSet := by
ext
simp
@[simp]
theorem mem_singleton {x y : ZFSet.{u}} : x ∈ @singleton ZFSet.{u} ZFSet.{u} _ y ↔ x = y :=
Iff.trans mem_insert_iff
⟨fun o => Or.rec (fun h => h) (fun n => absurd n (not_mem_empty _)) o, Or.inl⟩
@[simp]
theorem toSet_singleton (x : ZFSet) : ({x} : ZFSet).toSet = {x} := by
ext
simp
theorem insert_nonempty (u v : ZFSet) : (insert u v).Nonempty :=
⟨u, mem_insert u v⟩
theorem singleton_nonempty (u : ZFSet) : ZFSet.Nonempty {u} :=
insert_nonempty u ∅
theorem mem_pair {x y z : ZFSet.{u}} : x ∈ ({y, z} : ZFSet) ↔ x = y ∨ x = z := by
simp
/-- `omega` is the first infinite von Neumann ordinal -/
def omega : ZFSet :=
mk PSet.omega
@[simp]
theorem omega_zero : ∅ ∈ omega :=
⟨⟨0⟩, Equiv.rfl⟩
@[simp]
theorem omega_succ {n} : n ∈ omega.{u} → insert n n ∈ omega.{u} :=
Quotient.inductionOn n fun x ⟨⟨n⟩, h⟩ =>
⟨⟨n + 1⟩,
ZFSet.exact <|
show insert (mk x) (mk x) = insert (mk <| ofNat n) (mk <| ofNat n) by
rw [ZFSet.sound h]
rfl⟩
/-- `{x ∈ a | p x}` is the set of elements in `a` satisfying `p` -/
protected def sep (p : ZFSet → Prop) : ZFSet → ZFSet :=
Resp.eval 1
⟨PSet.sep fun y => p (mk y), fun ⟨α, A⟩ ⟨β, B⟩ ⟨αβ, βα⟩ =>
⟨fun ⟨a, pa⟩ =>
let ⟨b, hb⟩ := αβ a
⟨⟨b, by simpa only [mk_func, ← ZFSet.sound hb]⟩, hb⟩,
fun ⟨b, pb⟩ =>
let ⟨a, ha⟩ := βα b
⟨⟨a, by simpa only [mk_func, ZFSet.sound ha]⟩, ha⟩⟩⟩
-- Porting note: the { x | p x } notation appears to be disabled in Lean 4.
instance : Sep ZFSet ZFSet :=
⟨ZFSet.sep⟩
@[simp]
theorem mem_sep {p : ZFSet.{u} → Prop} {x y : ZFSet.{u}} :
y ∈ ZFSet.sep p x ↔ y ∈ x ∧ p y :=
Quotient.inductionOn₂ x y fun ⟨α, A⟩ y =>
⟨fun ⟨⟨a, pa⟩, h⟩ => ⟨⟨a, h⟩, by rwa [@Quotient.sound PSet _ _ _ h]⟩, fun ⟨⟨a, h⟩, pa⟩ =>
⟨⟨a, by
rw [mk_func] at h
rwa [mk_func, ← ZFSet.sound h]⟩,
h⟩⟩
@[simp]
theorem toSet_sep (a : ZFSet) (p : ZFSet → Prop) :
(ZFSet.sep p a).toSet = { x ∈ a.toSet | p x } := by
ext
simp
/-- The powerset operation, the collection of subsets of a ZFC set -/
def powerset : ZFSet → ZFSet :=
Resp.eval 1
⟨PSet.powerset, fun ⟨_, A⟩ ⟨_, B⟩ ⟨αβ, βα⟩ =>
⟨fun p =>
⟨{ b | ∃ a, p a ∧ Equiv (A a) (B b) }, fun ⟨a, pa⟩ =>
let ⟨b, ab⟩ := αβ a
⟨⟨b, a, pa, ab⟩, ab⟩,
fun ⟨_, a, pa, ab⟩ => ⟨⟨a, pa⟩, ab⟩⟩,
fun q =>
⟨{ a | ∃ b, q b ∧ Equiv (A a) (B b) }, fun ⟨_, b, qb, ab⟩ => ⟨⟨b, qb⟩, ab⟩, fun ⟨b, qb⟩ =>
let ⟨a, ab⟩ := βα b
⟨⟨a, b, qb, ab⟩, ab⟩⟩⟩⟩
@[simp]
theorem mem_powerset {x y : ZFSet.{u}} : y ∈ powerset x ↔ y ⊆ x :=
Quotient.inductionOn₂ x y fun ⟨α, A⟩ ⟨β, B⟩ =>
show (⟨β, B⟩ : PSet.{u}) ∈ PSet.powerset.{u} ⟨α, A⟩ ↔ _ by simp [mem_powerset, subset_iff]
theorem sUnion_lem {α β : Type u} (A : α → PSet) (B : β → PSet) (αβ : ∀ a, ∃ b, Equiv (A a) (B b)) :
∀ a, ∃ b, Equiv ((sUnion ⟨α, A⟩).Func a) ((sUnion ⟨β, B⟩).Func b)
| ⟨a, c⟩ => by
let ⟨b, hb⟩ := αβ a
induction' ea : A a with γ Γ
induction' eb : B b with δ Δ
rw [ea, eb] at hb
cases' hb with γδ δγ
let c : (A a).Type := c
let ⟨d, hd⟩ := γδ (by rwa [ea] at c)
use ⟨b, Eq.ndrec d (Eq.symm eb)⟩
change PSet.Equiv ((A a).Func c) ((B b).Func (Eq.ndrec d eb.symm))
match A a, B b, ea, eb, c, d, hd with
| _, _, rfl, rfl, _, _, hd => exact hd
/-- The union operator, the collection of elements of elements of a ZFC set -/
def sUnion : ZFSet → ZFSet :=
Resp.eval 1
⟨PSet.sUnion, fun ⟨_, A⟩ ⟨_, B⟩ ⟨αβ, βα⟩ =>
⟨sUnion_lem A B αβ, fun a =>
Exists.elim
(sUnion_lem B A (fun b => Exists.elim (βα b) fun c hc => ⟨c, PSet.Equiv.symm hc⟩) a)
fun b hb => ⟨b, PSet.Equiv.symm hb⟩⟩⟩
@[inherit_doc]
prefix:110 "⋃₀ " => ZFSet.sUnion
/-- The intersection operator, the collection of elements in all of the elements of a ZFC set. We
special-case `⋂₀ ∅ = ∅`. -/
noncomputable def sInter (x : ZFSet) : ZFSet := by
classical exact if h : x.Nonempty then ZFSet.sep (fun y => ∀ z ∈ x, y ∈ z) h.some else ∅
@[inherit_doc]
prefix:110 "⋂₀ " => ZFSet.sInter
@[simp]
theorem mem_sUnion {x y : ZFSet.{u}} : y ∈ ⋃₀ x ↔ ∃ z ∈ x, y ∈ z :=
Quotient.inductionOn₂ x y fun _ _ =>
Iff.trans PSet.mem_sUnion
⟨fun ⟨z, h⟩ => ⟨⟦z⟧, h⟩, fun ⟨z, h⟩ => Quotient.inductionOn z (fun z h => ⟨z, h⟩) h⟩
theorem mem_sInter {x y : ZFSet} (h : x.Nonempty) : y ∈ ⋂₀ x ↔ ∀ z ∈ x, y ∈ z := by
rw [sInter, dif_pos h]
simp only [mem_toSet, mem_sep, and_iff_right_iff_imp]
exact fun H => H _ h.some_mem
@[simp]
theorem sUnion_empty : ⋃₀ (∅ : ZFSet.{u}) = ∅ := by
ext
simp
@[simp]
theorem sInter_empty : ⋂₀ (∅ : ZFSet) = ∅ := dif_neg <| by simp
theorem mem_of_mem_sInter {x y z : ZFSet} (hy : y ∈ ⋂₀ x) (hz : z ∈ x) : y ∈ z := by
rcases eq_empty_or_nonempty x with (rfl | hx)
· exact (not_mem_empty z hz).elim
· exact (mem_sInter hx).1 hy z hz
theorem mem_sUnion_of_mem {x y z : ZFSet} (hy : y ∈ z) (hz : z ∈ x) : y ∈ ⋃₀ x :=
mem_sUnion.2 ⟨z, hz, hy⟩
theorem not_mem_sInter_of_not_mem {x y z : ZFSet} (hy : ¬y ∈ z) (hz : z ∈ x) : ¬y ∈ ⋂₀ x :=
fun hx => hy <| mem_of_mem_sInter hx hz
@[simp]
theorem sUnion_singleton {x : ZFSet.{u}} : ⋃₀ ({x} : ZFSet) = x :=
ext fun y => by simp_rw [mem_sUnion, mem_singleton, exists_eq_left]
@[simp]
theorem sInter_singleton {x : ZFSet.{u}} : ⋂₀ ({x} : ZFSet) = x :=
ext fun y => by simp_rw [mem_sInter (singleton_nonempty x), mem_singleton, forall_eq]
@[simp]
theorem toSet_sUnion (x : ZFSet.{u}) : (⋃₀ x).toSet = ⋃₀ (toSet '' x.toSet) := by
ext
simp
theorem toSet_sInter {x : ZFSet.{u}} (h : x.Nonempty) : (⋂₀ x).toSet = ⋂₀ (toSet '' x.toSet) := by
ext
simp [mem_sInter h]
theorem singleton_injective : Function.Injective (@singleton ZFSet ZFSet _) := fun x y H => by
let this := congr_arg sUnion H
rwa [sUnion_singleton, sUnion_singleton] at this
@[simp]
theorem singleton_inj {x y : ZFSet} : ({x} : ZFSet) = {y} ↔ x = y :=
singleton_injective.eq_iff
/-- The binary union operation -/
protected def union (x y : ZFSet.{u}) : ZFSet.{u} :=
⋃₀ {x, y}
/-- The binary intersection operation -/
protected def inter (x y : ZFSet.{u}) : ZFSet.{u} :=
ZFSet.sep (fun z => z ∈ y) x -- { z ∈ x | z ∈ y }
/-- The set difference operation -/
protected def diff (x y : ZFSet.{u}) : ZFSet.{u} :=
ZFSet.sep (fun z => z ∉ y) x -- { z ∈ x | z ∉ y }
instance : Union ZFSet :=
⟨ZFSet.union⟩
instance : Inter ZFSet :=
⟨ZFSet.inter⟩
instance : SDiff ZFSet :=
⟨ZFSet.diff⟩
@[simp]
theorem toSet_union (x y : ZFSet.{u}) : (x ∪ y).toSet = x.toSet ∪ y.toSet := by
change (⋃₀ {x, y}).toSet = _
simp
@[simp]
theorem toSet_inter (x y : ZFSet.{u}) : (x ∩ y).toSet = x.toSet ∩ y.toSet := by
change (ZFSet.sep (fun z => z ∈ y) x).toSet = _
ext
simp
@[simp]
theorem toSet_sdiff (x y : ZFSet.{u}) : (x \ y).toSet = x.toSet \ y.toSet := by
change (ZFSet.sep (fun z => z ∉ y) x).toSet = _
ext
simp
@[simp]
theorem mem_union {x y z : ZFSet.{u}} : z ∈ x ∪ y ↔ z ∈ x ∨ z ∈ y := by
rw [← mem_toSet]
simp
@[simp]
theorem mem_inter {x y z : ZFSet.{u}} : z ∈ x ∩ y ↔ z ∈ x ∧ z ∈ y :=
@mem_sep (fun z : ZFSet.{u} => z ∈ y) x z
@[simp]
theorem mem_diff {x y z : ZFSet.{u}} : z ∈ x \ y ↔ z ∈ x ∧ z ∉ y :=
@mem_sep (fun z : ZFSet.{u} => z ∉ y) x z
@[simp]
theorem sUnion_pair {x y : ZFSet.{u}} : ⋃₀ ({x, y} : ZFSet.{u}) = x ∪ y :=
rfl
theorem mem_wf : @WellFounded ZFSet (· ∈ ·) :=
(wellFounded_lift₂_iff (H := fun a b c d hx hy =>
propext ((@Mem.congr_left a c hx).trans (@Mem.congr_right b d hy _)))).mpr PSet.mem_wf
/-- Induction on the `∈` relation. -/
@[elab_as_elim]
theorem inductionOn {p : ZFSet → Prop} (x) (h : ∀ x, (∀ y ∈ x, p y) → p x) : p x :=
mem_wf.induction x h
instance : WellFoundedRelation ZFSet :=
⟨_, mem_wf⟩
instance : IsAsymm ZFSet (· ∈ ·) :=
mem_wf.isAsymm
-- Porting note: this can't be inferred automatically for some reason.
instance : IsIrrefl ZFSet (· ∈ ·) :=
mem_wf.isIrrefl
theorem mem_asymm {x y : ZFSet} : x ∈ y → y ∉ x :=
asymm
theorem mem_irrefl (x : ZFSet) : x ∉ x :=
irrefl x
theorem regularity (x : ZFSet.{u}) (h : x ≠ ∅) : ∃ y ∈ x, x ∩ y = ∅ :=
by_contradiction fun ne =>
h <| (eq_empty x).2 fun y =>
@inductionOn (fun z => z ∉ x) y fun z IH zx =>
ne ⟨z, zx, (eq_empty _).2 fun w wxz =>
let ⟨wx, wz⟩ := mem_inter.1 wxz
IH w wz wx⟩
/-- The image of a (definable) ZFC set function -/
def image (f : ZFSet → ZFSet) [Definable 1 f] : ZFSet → ZFSet :=
let ⟨r, hr⟩ := @Definable.Resp 1 f _
Resp.eval 1
⟨PSet.image r, fun _ _ e =>
Mem.ext fun _ =>
(mem_image hr).trans <|
Iff.trans
⟨fun ⟨w, h1, h2⟩ => ⟨w, (Mem.congr_right e).1 h1, h2⟩, fun ⟨w, h1, h2⟩ =>
⟨w, (Mem.congr_right e).2 h1, h2⟩⟩ <|
(mem_image hr).symm⟩
theorem image.mk :
∀ (f : ZFSet.{u} → ZFSet.{u}) [H : Definable 1 f] (x) {y} (_ : y ∈ x), f y ∈ @image f H x
| _, ⟨F⟩, x, y => Quotient.inductionOn₂ x y fun ⟨_, _⟩ _ ⟨a, ya⟩ => ⟨a, F.2 _ _ ya⟩
@[simp]
theorem mem_image :
∀ {f : ZFSet.{u} → ZFSet.{u}} [H : Definable 1 f] {x y : ZFSet.{u}},
y ∈ @image f H x ↔ ∃ z ∈ x, f z = y
| _, ⟨_⟩, x, y =>
Quotient.inductionOn₂ x y fun ⟨_, A⟩ _ =>
⟨fun ⟨a, ya⟩ => ⟨⟦A a⟧, Mem.mk A a, Eq.symm <| Quotient.sound ya⟩, fun ⟨_, hz, e⟩ =>
e ▸ image.mk _ _ hz⟩
@[simp]
theorem toSet_image (f : ZFSet → ZFSet) [H : Definable 1 f] (x : ZFSet) :
(image f x).toSet = f '' x.toSet := by
ext
simp
/-- The range of an indexed family of sets. The universes allow for a more general index type
without manual use of `ULift`. -/
noncomputable def range {α : Type u} (f : α → ZFSet.{max u v}) : ZFSet.{max u v} :=
⟦⟨ULift.{v} α, Quotient.out ∘ f ∘ ULift.down⟩⟧
@[simp]
theorem mem_range {α : Type u} {f : α → ZFSet.{max u v}} {x : ZFSet.{max u v}} :
x ∈ range.{u, v} f ↔ x ∈ Set.range f :=
Quotient.inductionOn x fun y => by
constructor
· rintro ⟨z, hz⟩
exact ⟨z.down, Quotient.eq_mk_iff_out.2 hz.symm⟩
· rintro ⟨z, hz⟩
use ULift.up z
simpa [hz] using PSet.Equiv.symm (Quotient.mk_out y)
@[simp]
theorem toSet_range {α : Type u} (f : α → ZFSet.{max u v}) :
(range.{u, v} f).toSet = Set.range f := by
ext
simp
/-- Kuratowski ordered pair -/
def pair (x y : ZFSet.{u}) : ZFSet.{u} :=
{{x}, {x, y}}
@[simp]
theorem toSet_pair (x y : ZFSet.{u}) : (pair x y).toSet = {{x}, {x, y}} := by simp [pair]
/-- A subset of pairs `{(a, b) ∈ x × y | p a b}` -/
def pairSep (p : ZFSet.{u} → ZFSet.{u} → Prop) (x y : ZFSet.{u}) : ZFSet.{u} :=
ZFSet.sep (fun z => ∃ a ∈ x, ∃ b ∈ y, z = pair a b ∧ p a b) (powerset (powerset (x ∪ y)))
@[simp]
theorem mem_pairSep {p} {x y z : ZFSet.{u}} :
z ∈ pairSep p x y ↔ ∃ a ∈ x, ∃ b ∈ y, z = pair a b ∧ p a b := by
refine mem_sep.trans ⟨And.right, fun e => ⟨?_, e⟩⟩
rcases e with ⟨a, ax, b, bY, rfl, pab⟩
simp only [mem_powerset, subset_def, mem_union, pair, mem_pair]
rintro u (rfl | rfl) v <;> simp only [mem_singleton, mem_pair]
· rintro rfl
exact Or.inl ax
· rintro (rfl | rfl) <;> [left; right] <;> assumption
theorem pair_injective : Function.Injective2 pair := fun x x' y y' H => by
have ae := ZFSet.ext_iff.1 H
simp only [pair, mem_pair] at ae
obtain rfl : x = x' := by
cases' (ae {x}).1 (by simp) with h h
· exact singleton_injective h
· have m : x' ∈ ({x} : ZFSet) := by simp [h]
rw [mem_singleton.mp m]
have he : x = y → y = y' := by
rintro rfl
cases' (ae {x, y'}).2 (by simp only [eq_self_iff_true, or_true_iff]) with xy'x xy'xx
· rw [eq_comm, ← mem_singleton, ← xy'x, mem_pair]
exact Or.inr rfl
· simpa [eq_comm] using (ZFSet.ext_iff.1 xy'xx y').1 (by simp)
obtain xyx | xyy' := (ae {x, y}).1 (by simp)
· obtain rfl := mem_singleton.mp ((ZFSet.ext_iff.1 xyx y).1 <| by simp)
simp [he rfl]
· obtain rfl | yy' := mem_pair.mp ((ZFSet.ext_iff.1 xyy' y).1 <| by simp)
· simp [he rfl]
· simp [yy']
@[simp]
theorem pair_inj {x y x' y' : ZFSet} : pair x y = pair x' y' ↔ x = x' ∧ y = y' :=
pair_injective.eq_iff
/-- The cartesian product, `{(a, b) | a ∈ x, b ∈ y}` -/
def prod : ZFSet.{u} → ZFSet.{u} → ZFSet.{u} :=
pairSep fun _ _ => True
@[simp]
theorem mem_prod {x y z : ZFSet.{u}} : z ∈ prod x y ↔ ∃ a ∈ x, ∃ b ∈ y, z = pair a b := by
simp [prod]
theorem pair_mem_prod {x y a b : ZFSet.{u}} : pair a b ∈ prod x y ↔ a ∈ x ∧ b ∈ y := by
simp
/-- `isFunc x y f` is the assertion that `f` is a subset of `x × y` which relates to each element
of `x` a unique element of `y`, so that we can consider `f` as a ZFC function `x → y`. -/
def IsFunc (x y f : ZFSet.{u}) : Prop :=
f ⊆ prod x y ∧ ∀ z : ZFSet.{u}, z ∈ x → ∃! w, pair z w ∈ f
/-- `funs x y` is `y ^ x`, the set of all set functions `x → y` -/
def funs (x y : ZFSet.{u}) : ZFSet.{u} :=
ZFSet.sep (IsFunc x y) (powerset (prod x y))
@[simp]
theorem mem_funs {x y f : ZFSet.{u}} : f ∈ funs x y ↔ IsFunc x y f := by simp [funs, IsFunc]
-- TODO(Mario): Prove this computably
/- Porting note: the `Definable` argument in `mapDefinableAux` is unused, though the TODO remark
suggests it shouldn't be. -/
@[nolint unusedArguments]
noncomputable instance mapDefinableAux (f : ZFSet → ZFSet) [Definable 1 f] :
Definable 1 fun (y : ZFSet) => pair y (f y) :=
@Classical.allDefinable 1 _
/-- Graph of a function: `map f x` is the ZFC function which maps `a ∈ x` to `f a` -/
noncomputable def map (f : ZFSet → ZFSet) [Definable 1 f] : ZFSet → ZFSet :=
image fun y => pair y (f y)
@[simp]
theorem mem_map {f : ZFSet → ZFSet} [Definable 1 f] {x y : ZFSet} :
y ∈ map f x ↔ ∃ z ∈ x, pair z (f z) = y :=
mem_image
theorem map_unique {f : ZFSet.{u} → ZFSet.{u}} [H : Definable 1 f] {x z : ZFSet.{u}}
(zx : z ∈ x) : ∃! w, pair z w ∈ map f x :=
⟨f z, image.mk _ _ zx, fun y yx => by
let ⟨w, _, we⟩ := mem_image.1 yx
let ⟨wz, fy⟩ := pair_injective we
rw [← fy, wz]⟩
@[simp]
theorem map_isFunc {f : ZFSet → ZFSet} [Definable 1 f] {x y : ZFSet} :
IsFunc x y (map f x) ↔ ∀ z ∈ x, f z ∈ y :=
⟨fun ⟨ss, h⟩ z zx =>
let ⟨_, t1, t2⟩ := h z zx
(t2 (f z) (image.mk _ _ zx)).symm ▸ (pair_mem_prod.1 (ss t1)).right,
fun h =>
⟨fun _ yx =>
let ⟨z, zx, ze⟩ := mem_image.1 yx
ze ▸ pair_mem_prod.2 ⟨zx, h z zx⟩,
fun _ => map_unique⟩⟩
/-- Given a predicate `p` on ZFC sets. `Hereditarily p x` means that `x` has property `p` and the
members of `x` are all `Hereditarily p`. -/
def Hereditarily (p : ZFSet → Prop) (x : ZFSet) : Prop :=
p x ∧ ∀ y ∈ x, Hereditarily p y
termination_by x
section Hereditarily
variable {p : ZFSet.{u} → Prop} {x y : ZFSet.{u}}
theorem hereditarily_iff : Hereditarily p x ↔ p x ∧ ∀ y ∈ x, Hereditarily p y := by
rw [← Hereditarily]
alias ⟨Hereditarily.def, _⟩ := hereditarily_iff
theorem Hereditarily.self (h : x.Hereditarily p) : p x :=
h.def.1
theorem Hereditarily.mem (h : x.Hereditarily p) (hy : y ∈ x) : y.Hereditarily p :=
h.def.2 _ hy
theorem Hereditarily.empty : Hereditarily p x → p ∅ := by
apply @ZFSet.inductionOn _ x
intro y IH h
rcases ZFSet.eq_empty_or_nonempty y with (rfl | ⟨a, ha⟩)
· exact h.self
· exact IH a ha (h.mem ha)
end Hereditarily
end ZFSet
/-- The collection of all classes.
We define `Class` as `Set ZFSet`, as this allows us to get many instances automatically. However, in
practice, we treat it as (the definitionally equal) `ZFSet → Prop`. This means, the preferred way to
state that `x : ZFSet` belongs to `A : Class` is to write `A x`. -/
def Class :=
Set ZFSet deriving HasSubset, EmptyCollection, Nonempty, Union, Inter, HasCompl, SDiff
instance : Insert ZFSet Class :=
⟨Set.insert⟩
namespace Class
-- Porting note: this is no longer an automatically derived instance.
/-- `{x ∈ A | p x}` is the class of elements in `A` satisfying `p` -/
protected def sep (p : ZFSet → Prop) (A : Class) : Class :=
{y | A y ∧ p y}
@[ext]
theorem ext {x y : Class.{u}} : (∀ z : ZFSet.{u}, x z ↔ y z) → x = y :=
Set.ext
/-- Coerce a ZFC set into a class -/
@[coe]
def ofSet (x : ZFSet.{u}) : Class.{u} :=
{ y | y ∈ x }
instance : Coe ZFSet Class :=
⟨ofSet⟩
/-- The universal class -/
def univ : Class :=
Set.univ
/-- Assert that `A` is a ZFC set satisfying `B` -/
def ToSet (B : Class.{u}) (A : Class.{u}) : Prop :=
∃ x : ZFSet, ↑x = A ∧ B x
/-- `A ∈ B` if `A` is a ZFC set which satisfies `B` -/
protected def Mem (A B : Class.{u}) : Prop :=
ToSet.{u} B A
instance : Membership Class Class :=
⟨Class.Mem⟩
theorem mem_def (A B : Class.{u}) : A ∈ B ↔ ∃ x : ZFSet, ↑x = A ∧ B x :=
Iff.rfl
@[simp]
theorem not_mem_empty (x : Class.{u}) : x ∉ (∅ : Class.{u}) := fun ⟨_, _, h⟩ => h
@[simp]
theorem not_empty_hom (x : ZFSet.{u}) : ¬(∅ : Class.{u}) x :=
id
@[simp]
theorem mem_univ {A : Class.{u}} : A ∈ univ.{u} ↔ ∃ x : ZFSet.{u}, ↑x = A :=
exists_congr fun _ => and_true_iff _
@[simp]
theorem mem_univ_hom (x : ZFSet.{u}) : univ.{u} x :=
trivial
theorem eq_univ_iff_forall {A : Class.{u}} : A = univ ↔ ∀ x : ZFSet, A x :=
Set.eq_univ_iff_forall
theorem eq_univ_of_forall {A : Class.{u}} : (∀ x : ZFSet, A x) → A = univ :=
Set.eq_univ_of_forall
theorem mem_wf : @WellFounded Class.{u} (· ∈ ·) :=
⟨by
have H : ∀ x : ZFSet.{u}, @Acc Class.{u} (· ∈ ·) ↑x := by
refine fun a => ZFSet.inductionOn a fun x IH => ⟨_, ?_⟩
rintro A ⟨z, rfl, hz⟩
exact IH z hz
refine fun A => ⟨A, ?_⟩
rintro B ⟨x, rfl, _⟩
exact H x⟩
instance : WellFoundedRelation Class :=
⟨_, mem_wf⟩
instance : IsAsymm Class (· ∈ ·) :=
mem_wf.isAsymm
-- Porting note: this can't be inferred automatically for some reason.
instance : IsIrrefl Class (· ∈ ·) :=
mem_wf.isIrrefl
theorem mem_asymm {x y : Class} : x ∈ y → y ∉ x :=
asymm
theorem mem_irrefl (x : Class) : x ∉ x :=
irrefl x
/-- **There is no universal set.**
This is stated as `univ ∉ univ`, meaning that `univ` (the class of all sets) is proper (does not
belong to the class of all sets). -/
theorem univ_not_mem_univ : univ ∉ univ :=
mem_irrefl _
/-- Convert a conglomerate (a collection of classes) into a class -/
def congToClass (x : Set Class.{u}) : Class.{u} :=
{ y | ↑y ∈ x }
@[simp]
theorem congToClass_empty : congToClass ∅ = ∅ := by
ext z
simp only [congToClass, not_empty_hom, iff_false_iff]
exact Set.not_mem_empty z
/-- Convert a class into a conglomerate (a collection of classes) -/
def classToCong (x : Class.{u}) : Set Class.{u} :=
{ y | y ∈ x }
@[simp]
theorem classToCong_empty : classToCong ∅ = ∅ := by
ext
simp [classToCong]
/-- The power class of a class is the class of all subclasses that are ZFC sets -/
def powerset (x : Class) : Class :=
congToClass (Set.powerset x)
/-- The union of a class is the class of all members of ZFC sets in the class -/
def sUnion (x : Class) : Class :=
⋃₀ classToCong x
@[inherit_doc]
prefix:110 "⋃₀ " => Class.sUnion
/-- The intersection of a class is the class of all members of ZFC sets in the class -/
def sInter (x : Class) : Class :=
⋂₀ classToCong x
@[inherit_doc]
prefix:110 "⋂₀ " => Class.sInter
theorem ofSet.inj {x y : ZFSet.{u}} (h : (x : Class.{u}) = y) : x = y :=
ZFSet.ext fun z => by
change (x : Class.{u}) z ↔ (y : Class.{u}) z
rw [h]
@[simp]
theorem toSet_of_ZFSet (A : Class.{u}) (x : ZFSet.{u}) : ToSet A x ↔ A x :=
⟨fun ⟨y, yx, py⟩ => by rwa [ofSet.inj yx] at py, fun px => ⟨x, rfl, px⟩⟩
@[simp, norm_cast]
theorem coe_mem {x : ZFSet.{u}} {A : Class.{u}} : ↑x ∈ A ↔ A x :=
toSet_of_ZFSet _ _
@[simp]
theorem coe_apply {x y : ZFSet.{u}} : (y : Class.{u}) x ↔ x ∈ y :=
Iff.rfl
@[simp, norm_cast]
theorem coe_subset (x y : ZFSet.{u}) : (x : Class.{u}) ⊆ y ↔ x ⊆ y :=
Iff.rfl
@[simp, norm_cast]
theorem coe_sep (p : Class.{u}) (x : ZFSet.{u}) :
(ZFSet.sep p x : Class) = { y ∈ x | p y } :=
ext fun _ => ZFSet.mem_sep
@[simp, norm_cast]
theorem coe_empty : ↑(∅ : ZFSet.{u}) = (∅ : Class.{u}) :=
ext fun y => iff_false_iff.2 <| ZFSet.not_mem_empty y
@[simp, norm_cast]
theorem coe_insert (x y : ZFSet.{u}) : ↑(insert x y) = @insert ZFSet.{u} Class.{u} _ x y :=
ext fun _ => ZFSet.mem_insert_iff
@[simp, norm_cast]
theorem coe_union (x y : ZFSet.{u}) : ↑(x ∪ y) = (x : Class.{u}) ∪ y :=
ext fun _ => ZFSet.mem_union
@[simp, norm_cast]
theorem coe_inter (x y : ZFSet.{u}) : ↑(x ∩ y) = (x : Class.{u}) ∩ y :=
ext fun _ => ZFSet.mem_inter
@[simp, norm_cast]
theorem coe_diff (x y : ZFSet.{u}) : ↑(x \ y) = (x : Class.{u}) \ y :=
ext fun _ => ZFSet.mem_diff
@[simp, norm_cast]
theorem coe_powerset (x : ZFSet.{u}) : ↑x.powerset = powerset.{u} x :=
ext fun _ => ZFSet.mem_powerset
@[simp]
theorem powerset_apply {A : Class.{u}} {x : ZFSet.{u}} : powerset A x ↔ ↑x ⊆ A :=
Iff.rfl
@[simp]
theorem sUnion_apply {x : Class} {y : ZFSet} : (⋃₀ x) y ↔ ∃ z : ZFSet, x z ∧ y ∈ z := by
constructor
· rintro ⟨-, ⟨z, rfl, hxz⟩, hyz⟩
exact ⟨z, hxz, hyz⟩
· exact fun ⟨z, hxz, hyz⟩ => ⟨_, coe_mem.2 hxz, hyz⟩
@[simp, norm_cast]
theorem coe_sUnion (x : ZFSet.{u}) : ↑(⋃₀ x : ZFSet) = ⋃₀ (x : Class.{u}) :=
ext fun y =>
ZFSet.mem_sUnion.trans (sUnion_apply.trans <| by rfl).symm
@[simp]
theorem mem_sUnion {x y : Class.{u}} : y ∈ ⋃₀ x ↔ ∃ z, z ∈ x ∧ y ∈ z := by
constructor
· rintro ⟨w, rfl, z, hzx, hwz⟩
exact ⟨z, hzx, coe_mem.2 hwz⟩
· rintro ⟨w, hwx, z, rfl, hwz⟩
exact ⟨z, rfl, w, hwx, hwz⟩
theorem sInter_apply {x : Class.{u}} {y : ZFSet.{u}} : (⋂₀ x) y ↔ ∀ z : ZFSet.{u}, x z → y ∈ z := by
refine ⟨fun hxy z hxz => hxy _ ⟨z, rfl, hxz⟩, ?_⟩
rintro H - ⟨z, rfl, hxz⟩
exact H _ hxz
@[simp, norm_cast]
theorem coe_sInter {x : ZFSet.{u}} (h : x.Nonempty) : ↑(⋂₀ x : ZFSet) = ⋂₀ (x : Class.{u}) :=
Set.ext fun _ => (ZFSet.mem_sInter h).trans sInter_apply.symm
theorem mem_of_mem_sInter {x y z : Class} (hy : y ∈ ⋂₀ x) (hz : z ∈ x) : y ∈ z := by
obtain ⟨w, rfl, hw⟩ := hy
exact coe_mem.2 (hw z hz)
theorem mem_sInter {x y : Class.{u}} (h : x.Nonempty) : y ∈ ⋂₀ x ↔ ∀ z, z ∈ x → y ∈ z := by
refine ⟨fun hy z => mem_of_mem_sInter hy, fun H => ?_⟩
simp_rw [mem_def, sInter_apply]
obtain ⟨z, hz⟩ := h
obtain ⟨y, rfl, _⟩ := H z (coe_mem.2 hz)
refine ⟨y, rfl, fun w hxw => ?_⟩
simpa only [coe_mem, coe_apply] using H w (coe_mem.2 hxw)
@[simp]
theorem sUnion_empty : ⋃₀ (∅ : Class.{u}) = (∅ : Class.{u}) := by
ext
simp
@[simp]
theorem sInter_empty : ⋂₀ (∅ : Class.{u}) = univ := by
rw [sInter, classToCong_empty, Set.sInter_empty, univ]
/-- An induction principle for sets. If every subset of a class is a member, then the class is
universal. -/
theorem eq_univ_of_powerset_subset {A : Class} (hA : powerset A ⊆ A) : A = univ :=
eq_univ_of_forall
(by
by_contra! hnA
exact
WellFounded.min_mem ZFSet.mem_wf _ hnA
(hA fun x hx =>
Classical.not_not.1 fun hB =>
WellFounded.not_lt_min ZFSet.mem_wf _ hnA hB <| coe_apply.1 hx))
/-- The definite description operator, which is `{x}` if `{y | A y} = {x}` and `∅` otherwise. -/
def iota (A : Class) : Class :=
⋃₀ { x | ∀ y, A y ↔ y = x }
theorem iota_val (A : Class) (x : ZFSet) (H : ∀ y, A y ↔ y = x) : iota A = ↑x :=
ext fun y =>
⟨fun ⟨_, ⟨x', rfl, h⟩, yx'⟩ => by rwa [← (H x').1 <| (h x').2 rfl], fun yx =>
⟨_, ⟨x, rfl, H⟩, yx⟩⟩
/-- Unlike the other set constructors, the `iota` definite descriptor
is a set for any set input, but not constructively so, so there is no
associated `Class → Set` function. -/
theorem iota_ex (A) : iota.{u} A ∈ univ.{u} :=
mem_univ.2 <|
Or.elim (Classical.em <| ∃ x, ∀ y, A y ↔ y = x) (fun ⟨x, h⟩ => ⟨x, Eq.symm <| iota_val A x h⟩)
fun hn =>
⟨∅, ext fun _ => coe_empty.symm ▸ ⟨False.rec, fun ⟨_, ⟨x, rfl, H⟩, _⟩ => hn ⟨x, H⟩⟩⟩
/-- Function value -/
def fval (F A : Class.{u}) : Class.{u} :=
iota fun y => ToSet (fun x => F (ZFSet.pair x y)) A
@[inherit_doc]
infixl:100 " ′ " => fval
theorem fval_ex (F A : Class.{u}) : F ′ A ∈ univ.{u} :=
iota_ex _
end Class
namespace ZFSet
@[simp]
theorem map_fval {f : ZFSet.{u} → ZFSet.{u}} [H : PSet.Definable 1 f] {x y : ZFSet.{u}}
(h : y ∈ x) : (ZFSet.map f x ′ y : Class.{u}) = f y :=
Class.iota_val _ _ fun z => by
rw [Class.toSet_of_ZFSet, Class.coe_apply, mem_map]
exact
⟨fun ⟨w, _, pr⟩ => by
let ⟨wy, fw⟩ := ZFSet.pair_injective pr
rw [← fw, wy], fun e => by
subst e
exact ⟨_, h, rfl⟩⟩
variable (x : ZFSet.{u})
/-- A choice function on the class of nonempty ZFC sets. -/
noncomputable def choice : ZFSet :=
@map (fun y => Classical.epsilon fun z => z ∈ y) (Classical.allDefinable _) x
theorem choice_mem_aux (h : ∅ ∉ x) (y : ZFSet.{u}) (yx : y ∈ x) :
(Classical.epsilon fun z : ZFSet.{u} => z ∈ y) ∈ y :=
(@Classical.epsilon_spec _ fun z : ZFSet.{u} => z ∈ y) <|
by_contradiction fun n => h <| by rwa [← (eq_empty y).2 fun z zx => n ⟨z, zx⟩]
theorem choice_isFunc (h : ∅ ∉ x) : IsFunc x (⋃₀ x) (choice x) :=
(@map_isFunc _ (Classical.allDefinable _) _ _).2 fun y yx =>
mem_sUnion.2 ⟨y, yx, choice_mem_aux x h y yx⟩
theorem choice_mem (h : ∅ ∉ x) (y : ZFSet.{u}) (yx : y ∈ x) :
(choice x ′ y : Class.{u}) ∈ (y : Class.{u}) := by
delta choice
rw [@map_fval _ (Classical.allDefinable _) x y yx, Class.coe_mem, Class.coe_apply]
exact choice_mem_aux x h y yx
private lemma toSet_equiv_aux {s : Set ZFSet.{u}} (hs : Small.{u} s) :
(mk <| PSet.mk (Shrink s) fun x ↦ ((equivShrink s).symm x).1.out).toSet = s := by
ext x
rw [mem_toSet, ← mk_out x, mk_mem_iff, mk_out]
refine ⟨?_, fun xs ↦ ⟨equivShrink s (Subtype.mk x xs), ?_⟩⟩
· rintro ⟨b, h2⟩
rw [← ZFSet.eq, ZFSet.mk_out] at h2
simp [h2]
· simp [PSet.Equiv.refl]
/-- `ZFSet.toSet` as an equivalence. -/
@[simps apply_coe]
noncomputable def toSet_equiv : ZFSet.{u} ≃ {s : Set ZFSet.{u} // Small.{u, u+1} s} where
toFun x := ⟨x.toSet, x.small_toSet⟩
invFun := fun ⟨s, h⟩ ↦ mk <| PSet.mk (Shrink s) fun x ↦ ((equivShrink.{u, u+1} s).symm x).1.out
left_inv := Function.rightInverse_of_injective_of_leftInverse (by intros x y; simp)
fun s ↦ Subtype.coe_injective <| toSet_equiv_aux s.2
right_inv s := Subtype.coe_injective <| toSet_equiv_aux s.2
end ZFSet
|
SetTheory\ZFC\Ordinal.lean | /-
Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Violeta Hernández Palacios
-/
import Mathlib.SetTheory.ZFC.Basic
/-!
# Von Neumann ordinals
This file works towards the development of von Neumann ordinals, i.e. transitive sets, well-ordered
under `∈`. We currently only have an initial development of transitive sets.
Further development can be found on the branch `von_neumann_v2`.
## Definitions
- `ZFSet.IsTransitive` means that every element of a set is a subset.
## TODO
- Define von Neumann ordinals.
- Define the basic arithmetic operations on ordinals from a purely set-theoretic perspective.
- Prove the equivalences between these definitions and those provided in
`SetTheory/Ordinal/Arithmetic.lean`.
-/
universe u
variable {x y z : ZFSet.{u}}
namespace ZFSet
/-- A transitive set is one where every element is a subset. -/
def IsTransitive (x : ZFSet) : Prop :=
∀ y ∈ x, y ⊆ x
@[simp]
theorem empty_isTransitive : IsTransitive ∅ := fun y hy => (not_mem_empty y hy).elim
theorem IsTransitive.subset_of_mem (h : x.IsTransitive) : y ∈ x → y ⊆ x :=
h y
theorem isTransitive_iff_mem_trans : z.IsTransitive ↔ ∀ {x y : ZFSet}, x ∈ y → y ∈ z → x ∈ z :=
⟨fun h _ _ hx hy => h.subset_of_mem hy hx, fun H _ hx _ hy => H hy hx⟩
alias ⟨IsTransitive.mem_trans, _⟩ := isTransitive_iff_mem_trans
protected theorem IsTransitive.inter (hx : x.IsTransitive) (hy : y.IsTransitive) :
(x ∩ y).IsTransitive := fun z hz w hw => by
rw [mem_inter] at hz ⊢
exact ⟨hx.mem_trans hw hz.1, hy.mem_trans hw hz.2⟩
protected theorem IsTransitive.sUnion (h : x.IsTransitive) :
(⋃₀ x : ZFSet).IsTransitive := fun y hy z hz => by
rcases mem_sUnion.1 hy with ⟨w, hw, hw'⟩
exact mem_sUnion_of_mem hz (h.mem_trans hw' hw)
theorem IsTransitive.sUnion' (H : ∀ y ∈ x, IsTransitive y) :
(⋃₀ x : ZFSet).IsTransitive := fun y hy z hz => by
rcases mem_sUnion.1 hy with ⟨w, hw, hw'⟩
exact mem_sUnion_of_mem ((H w hw).mem_trans hz hw') hw
protected theorem IsTransitive.union (hx : x.IsTransitive) (hy : y.IsTransitive) :
(x ∪ y).IsTransitive := by
rw [← sUnion_pair]
apply IsTransitive.sUnion' fun z => _
intro
rw [mem_pair]
rintro (rfl | rfl)
assumption'
protected theorem IsTransitive.powerset (h : x.IsTransitive) : (powerset x).IsTransitive :=
fun y hy z hz => by
rw [mem_powerset] at hy ⊢
exact h.subset_of_mem (hy hz)
theorem isTransitive_iff_sUnion_subset : x.IsTransitive ↔ (⋃₀ x : ZFSet) ⊆ x :=
⟨fun h y hy => by
rcases mem_sUnion.1 hy with ⟨z, hz, hz'⟩
exact h.mem_trans hz' hz, fun H y hy z hz => H <| mem_sUnion_of_mem hz hy⟩
alias ⟨IsTransitive.sUnion_subset, _⟩ := isTransitive_iff_sUnion_subset
theorem isTransitive_iff_subset_powerset : x.IsTransitive ↔ x ⊆ powerset x :=
⟨fun h _ hy => mem_powerset.2 <| h.subset_of_mem hy, fun H _ hy _ hz => mem_powerset.1 (H hy) hz⟩
alias ⟨IsTransitive.subset_powerset, _⟩ := isTransitive_iff_subset_powerset
end ZFSet
|
Tactic\Abel.lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Scott Morrison
-/
import Mathlib.Tactic.NormNum.Basic
import Mathlib.Tactic.TryThis
import Mathlib.Util.AtomM
/-!
# The `abel` tactic
Evaluate expressions in the language of additive, commutative monoids and groups.
-/
-- TODO: assert_not_exists NonUnitalNonAssociativeSemiring
assert_not_exists OrderedAddCommMonoid
assert_not_exists TopologicalSpace
assert_not_exists PseudoMetricSpace
namespace Mathlib.Tactic.Abel
open Lean Elab Meta Tactic Qq
initialize registerTraceClass `abel
initialize registerTraceClass `abel.detail
/-- The `Context` for a call to `abel`.
Stores a few options for this call, and caches some common subexpressions
such as typeclass instances and `0 : α`.
-/
structure Context where
/-- The type of the ambient additive commutative group or monoid. -/
α : Expr
/-- The universe level for `α`. -/
univ : Level
/-- The expression representing `0 : α`. -/
α0 : Expr
/-- Specify whether we are in an additive commutative group or an additive commutative monoid. -/
isGroup : Bool
/-- The `AddCommGroup α` or `AddCommMonoid α` expression. -/
inst : Expr
/-- Populate a `context` object for evaluating `e`. -/
def mkContext (e : Expr) : MetaM Context := do
let α ← inferType e
let c ← synthInstance (← mkAppM ``AddCommMonoid #[α])
let cg ← synthInstance? (← mkAppM ``AddCommGroup #[α])
let u ← mkFreshLevelMVar
_ ← isDefEq (.sort (.succ u)) (← inferType α)
let α0 ← Expr.ofNat α 0
match cg with
| some cg => return ⟨α, u, α0, true, cg⟩
| _ => return ⟨α, u, α0, false, c⟩
/-- The monad for `Abel` contains, in addition to the `AtomM` state,
some information about the current type we are working over, so that we can consistently
use group lemmas or monoid lemmas as appropriate. -/
abbrev M := ReaderT Context AtomM
/-- Apply the function `n : ∀ {α} [inst : AddWhatever α], _` to the
implicit parameters in the context, and the given list of arguments. -/
def Context.app (c : Context) (n : Name) (inst : Expr) : Array Expr → Expr :=
mkAppN (((@Expr.const n [c.univ]).app c.α).app inst)
/-- Apply the function `n : ∀ {α} [inst α], _` to the implicit parameters in the
context, and the given list of arguments.
Compared to `context.app`, this takes the name of the typeclass, rather than an
inferred typeclass instance.
-/
def Context.mkApp (c : Context) (n inst : Name) (l : Array Expr) : MetaM Expr := do
return c.app n (← synthInstance ((Expr.const inst [c.univ]).app c.α)) l
/-- Add the letter "g" to the end of the name, e.g. turning `term` into `termg`.
This is used to choose between declarations taking `AddCommMonoid` and those
taking `AddCommGroup` instances.
-/
def addG : Name → Name
| .str p s => .str p (s ++ "g")
| n => n
/-- Apply the function `n : ∀ {α} [AddComm{Monoid,Group} α]` to the given list of arguments.
Will use the `AddComm{Monoid,Group}` instance that has been cached in the context.
-/
def iapp (n : Name) (xs : Array Expr) : M Expr := do
let c ← read
return c.app (if c.isGroup then addG n else n) c.inst xs
/-- A type synonym used by `abel` to represent `n • x + a` in an additive commutative monoid. -/
def term {α} [AddCommMonoid α] (n : ℕ) (x a : α) : α := n • x + a
/-- A type synonym used by `abel` to represent `n • x + a` in an additive commutative group. -/
def termg {α} [AddCommGroup α] (n : ℤ) (x a : α) : α := n • x + a
/-- Evaluate a term with coefficient `n`, atom `x` and successor terms `a`. -/
def mkTerm (n x a : Expr) : M Expr := iapp ``term #[n, x, a]
/-- Interpret an integer as a coefficient to a term. -/
def intToExpr (n : ℤ) : M Expr := do
Expr.ofInt (mkConst (if (← read).isGroup then ``Int else ``Nat) []) n
/-- A normal form for `abel`.
Expressions are represented as a list of terms of the form `e = n • x`,
where `n : ℤ` and `x` is an arbitrary element of the additive commutative monoid or group.
We explicitly track the `Expr` forms of `e` and `n`, even though they could be reconstructed,
for efficiency. -/
inductive NormalExpr : Type
| zero (e : Expr) : NormalExpr
| nterm (e : Expr) (n : Expr × ℤ) (x : ℕ × Expr) (a : NormalExpr) : NormalExpr
deriving Inhabited
/-- Extract the expression from a normal form. -/
def NormalExpr.e : NormalExpr → Expr
| .zero e => e
| .nterm e .. => e
instance : Coe NormalExpr Expr where coe := NormalExpr.e
/-- Construct the normal form representing a single term. -/
def NormalExpr.term' (n : Expr × ℤ) (x : ℕ × Expr) (a : NormalExpr) : M NormalExpr :=
return .nterm (← mkTerm n.1 x.2 a) n x a
/-- Construct the normal form representing zero. -/
def NormalExpr.zero' : M NormalExpr := return NormalExpr.zero (← read).α0
open NormalExpr
theorem const_add_term {α} [AddCommMonoid α] (k n x a a') (h : k + a = a') :
k + @term α _ n x a = term n x a' := by
simp [h.symm, term, add_comm, add_assoc]
theorem const_add_termg {α} [AddCommGroup α] (k n x a a') (h : k + a = a') :
k + @termg α _ n x a = termg n x a' := by
simp [h.symm, termg, add_comm, add_assoc]
theorem term_add_const {α} [AddCommMonoid α] (n x a k a') (h : a + k = a') :
@term α _ n x a + k = term n x a' := by
simp [h.symm, term, add_assoc]
theorem term_add_constg {α} [AddCommGroup α] (n x a k a') (h : a + k = a') :
@termg α _ n x a + k = termg n x a' := by
simp [h.symm, termg, add_assoc]
theorem term_add_term {α} [AddCommMonoid α] (n₁ x a₁ n₂ a₂ n' a') (h₁ : n₁ + n₂ = n')
(h₂ : a₁ + a₂ = a') : @term α _ n₁ x a₁ + @term α _ n₂ x a₂ = term n' x a' := by
simp [h₁.symm, h₂.symm, term, add_nsmul, add_assoc, add_left_comm]
theorem term_add_termg {α} [AddCommGroup α] (n₁ x a₁ n₂ a₂ n' a')
(h₁ : n₁ + n₂ = n') (h₂ : a₁ + a₂ = a') :
@termg α _ n₁ x a₁ + @termg α _ n₂ x a₂ = termg n' x a' := by
simp only [termg, h₁.symm, add_zsmul, h₂.symm]
exact add_add_add_comm (n₁ • x) a₁ (n₂ • x) a₂
theorem zero_term {α} [AddCommMonoid α] (x a) : @term α _ 0 x a = a := by
simp [term, zero_nsmul, one_nsmul]
theorem zero_termg {α} [AddCommGroup α] (x a) : @termg α _ 0 x a = a := by
simp [termg, zero_zsmul]
/--
Interpret the sum of two expressions in `abel`'s normal form.
-/
partial def evalAdd : NormalExpr → NormalExpr → M (NormalExpr × Expr)
| zero _, e₂ => do
let p ← mkAppM ``zero_add #[e₂]
return (e₂, p)
| e₁, zero _ => do
let p ← mkAppM ``add_zero #[e₁]
return (e₁, p)
| he₁@(nterm e₁ n₁ x₁ a₁), he₂@(nterm e₂ n₂ x₂ a₂) => do
if x₁.1 = x₂.1 then
let n' ← Mathlib.Meta.NormNum.eval (← mkAppM ``HAdd.hAdd #[n₁.1, n₂.1])
let (a', h₂) ← evalAdd a₁ a₂
let k := n₁.2 + n₂.2
let p₁ ← iapp ``term_add_term
#[n₁.1, x₁.2, a₁, n₂.1, a₂, n'.expr, a', ← n'.getProof, h₂]
if k = 0 then do
let p ← mkEqTrans p₁ (← iapp ``zero_term #[x₁.2, a'])
return (a', p)
else return (← term' (n'.expr, k) x₁ a', p₁)
else if x₁.1 < x₂.1 then do
let (a', h) ← evalAdd a₁ he₂
return (← term' n₁ x₁ a', ← iapp ``term_add_const #[n₁.1, x₁.2, a₁, e₂, a', h])
else do
let (a', h) ← evalAdd he₁ a₂
return (← term' n₂ x₂ a', ← iapp ``const_add_term #[e₁, n₂.1, x₂.2, a₂, a', h])
theorem term_neg {α} [AddCommGroup α] (n x a n' a')
(h₁ : -n = n') (h₂ : -a = a') : -@termg α _ n x a = termg n' x a' := by
simpa [h₂.symm, h₁.symm, termg] using add_comm _ _
/--
Interpret a negated expression in `abel`'s normal form.
-/
def evalNeg : NormalExpr → M (NormalExpr × Expr)
| (zero _) => do
let p ← (← read).mkApp ``neg_zero ``NegZeroClass #[]
return (← zero', p)
| (nterm _ n x a) => do
let n' ← Mathlib.Meta.NormNum.eval (← mkAppM ``Neg.neg #[n.1])
let (a', h₂) ← evalNeg a
return (← term' (n'.expr, -n.2) x a',
(← read).app ``term_neg (← read).inst #[n.1, x.2, a, n'.expr, a', ← n'.getProof, h₂])
/-- A synonym for `•`, used internally in `abel`. -/
def smul {α} [AddCommMonoid α] (n : ℕ) (x : α) : α := n • x
/-- A synonym for `•`, used internally in `abel`. -/
def smulg {α} [AddCommGroup α] (n : ℤ) (x : α) : α := n • x
theorem zero_smul {α} [AddCommMonoid α] (c) : smul c (0 : α) = 0 := by
simp [smul, nsmul_zero]
theorem zero_smulg {α} [AddCommGroup α] (c) : smulg c (0 : α) = 0 := by
simp [smulg, zsmul_zero]
theorem term_smul {α} [AddCommMonoid α] (c n x a n' a')
(h₁ : c * n = n') (h₂ : smul c a = a') :
smul c (@term α _ n x a) = term n' x a' := by
simp [h₂.symm, h₁.symm, term, smul, nsmul_add, mul_nsmul']
theorem term_smulg {α} [AddCommGroup α] (c n x a n' a')
(h₁ : c * n = n') (h₂ : smulg c a = a') :
smulg c (@termg α _ n x a) = termg n' x a' := by
simp [h₂.symm, h₁.symm, termg, smulg, zsmul_add, mul_zsmul]
/--
Auxiliary function for `evalSMul'`.
-/
def evalSMul (k : Expr × ℤ) : NormalExpr → M (NormalExpr × Expr)
| zero _ => return (← zero', ← iapp ``zero_smul #[k.1])
| nterm _ n x a => do
let n' ← Mathlib.Meta.NormNum.eval (← mkAppM ``HMul.hMul #[k.1, n.1])
let (a', h₂) ← evalSMul k a
return (← term' (n'.expr, k.2 * n.2) x a',
← iapp ``term_smul #[k.1, n.1, x.2, a, n'.expr, a', ← n'.getProof, h₂])
theorem term_atom {α} [AddCommMonoid α] (x : α) : x = term 1 x 0 := by simp [term]
theorem term_atomg {α} [AddCommGroup α] (x : α) : x = termg 1 x 0 := by simp [termg]
theorem term_atom_pf {α} [AddCommMonoid α] (x x' : α) (h : x = x') : x = term 1 x' 0 := by
simp [term, h]
theorem term_atom_pfg {α} [AddCommGroup α] (x x' : α) (h : x = x') : x = termg 1 x' 0 := by
simp [termg, h]
/-- Interpret an expression as an atom for `abel`'s normal form. -/
def evalAtom (e : Expr) : M (NormalExpr × Expr) := do
let { expr := e', proof?, .. } ← (← readThe AtomM.Context).evalAtom e
let i ← AtomM.addAtom e'
let p ← match proof? with
| none => iapp ``term_atom #[e]
| some p => iapp ``term_atom_pf #[e, e', p]
return (← term' (← intToExpr 1, 1) (i, e') (← zero'), p)
theorem unfold_sub {α} [SubtractionMonoid α] (a b c : α) (h : a + -b = c) : a - b = c := by
rw [sub_eq_add_neg, h]
theorem unfold_smul {α} [AddCommMonoid α] (n) (x y : α)
(h : smul n x = y) : n • x = y := h
theorem unfold_smulg {α} [AddCommGroup α] (n : ℕ) (x y : α)
(h : smulg (Int.ofNat n) x = y) : (n : ℤ) • x = y := h
theorem unfold_zsmul {α} [AddCommGroup α] (n : ℤ) (x y : α)
(h : smulg n x = y) : n • x = y := h
lemma subst_into_smul {α} [AddCommMonoid α]
(l r tl tr t) (prl : l = tl) (prr : r = tr)
(prt : @smul α _ tl tr = t) : smul l r = t := by simp [prl, prr, prt]
lemma subst_into_smulg {α} [AddCommGroup α]
(l r tl tr t) (prl : l = tl) (prr : r = tr)
(prt : @smulg α _ tl tr = t) : smulg l r = t := by simp [prl, prr, prt]
lemma subst_into_smul_upcast {α} [AddCommGroup α]
(l r tl zl tr t) (prl₁ : l = tl) (prl₂ : ↑tl = zl) (prr : r = tr)
(prt : @smulg α _ zl tr = t) : smul l r = t := by
simp [← prt, prl₁, ← prl₂, prr, smul, smulg, natCast_zsmul]
lemma subst_into_add {α} [AddCommMonoid α] (l r tl tr t)
(prl : (l : α) = tl) (prr : r = tr) (prt : tl + tr = t) : l + r = t := by
rw [prl, prr, prt]
lemma subst_into_addg {α} [AddCommGroup α] (l r tl tr t)
(prl : (l : α) = tl) (prr : r = tr) (prt : tl + tr = t) : l + r = t := by
rw [prl, prr, prt]
lemma subst_into_negg {α} [AddCommGroup α] (a ta t : α)
(pra : a = ta) (prt : -ta = t) : -a = t := by
simp [pra, prt]
/-- Normalize a term `orig` of the form `smul e₁ e₂` or `smulg e₁ e₂`.
Normalized terms use `smul` for monoids and `smulg` for groups,
so there are actually four cases to handle:
* Using `smul` in a monoid just simplifies the pieces using `subst_into_smul`
* Using `smulg` in a group just simplifies the pieces using `subst_into_smulg`
* Using `smul a b` in a group requires converting `a` from a nat to an int and
then simplifying `smulg ↑a b` using `subst_into_smul_upcast`
* Using `smulg` in a monoid is impossible (or at least out of scope),
because you need a group argument to write a `smulg` term -/
def evalSMul' (eval : Expr → M (NormalExpr × Expr))
(is_smulg : Bool) (orig e₁ e₂ : Expr) : M (NormalExpr × Expr) := do
trace[abel] "Calling NormNum on {e₁}"
let ⟨e₁', p₁, _⟩ ← try Meta.NormNum.eval e₁ catch _ => pure { expr := e₁ }
let p₁ ← p₁.getDM (mkEqRefl e₁')
match e₁'.int? with
| some n => do
let c ← read
let (e₂', p₂) ← eval e₂
if c.isGroup = is_smulg then do
let (e', p) ← evalSMul (e₁', n) e₂'
return (e', ← iapp ``subst_into_smul #[e₁, e₂, e₁', e₂', e', p₁, p₂, p])
else do
if ¬ c.isGroup then throwError "Doesn't make sense to us `smulg` in a monoid. "
-- We are multiplying by a natural number in an additive group.
let zl ← Expr.ofInt q(ℤ) n
let p₁' ← mkEqRefl zl
let (e', p) ← evalSMul (zl, n) e₂'
return (e', c.app ``subst_into_smul_upcast c.inst #[e₁, e₂, e₁', zl, e₂', e', p₁, p₁', p₂, p])
| none => evalAtom orig
/-- Evaluate an expression into its `abel` normal form, by recursing into subexpressions. -/
partial def eval (e : Expr) : M (NormalExpr × Expr) := do
trace[abel.detail] "running eval on {e}"
trace[abel.detail] "getAppFnArgs: {e.getAppFnArgs}"
match e.getAppFnArgs with
| (``HAdd.hAdd, #[_, _, _, _, e₁, e₂]) => do
let (e₁', p₁) ← eval e₁
let (e₂', p₂) ← eval e₂
let (e', p') ← evalAdd e₁' e₂'
return (e', ← iapp ``subst_into_add #[e₁, e₂, e₁', e₂', e', p₁, p₂, p'])
| (``HSub.hSub, #[_, _, _ ,_, e₁, e₂]) => do
let e₂' ← mkAppM ``Neg.neg #[e₂]
let e ← mkAppM ``HAdd.hAdd #[e₁, e₂']
let (e', p) ← eval e
let p' ← (← read).mkApp ``unfold_sub ``SubtractionMonoid #[e₁, e₂, e', p]
return (e', p')
| (``Neg.neg, #[_, _, e]) => do
let (e₁, p₁) ← eval e
let (e₂, p₂) ← evalNeg e₁
return (e₂, ← iapp `Mathlib.Tactic.Abel.subst_into_neg #[e, e₁, e₂, p₁, p₂])
| (`AddMonoid.nsmul, #[_, _, e₁, e₂]) => do
let n ← if (← read).isGroup then mkAppM ``Int.ofNat #[e₁] else pure e₁
let (e', p) ← eval <| ← iapp ``smul #[n, e₂]
return (e', ← iapp ``unfold_smul #[e₁, e₂, e', p])
| (``SubNegMonoid.zsmul, #[_, _, e₁, e₂]) => do
if ¬ (← read).isGroup then failure
let (e', p) ← eval <| ← iapp ``smul #[e₁, e₂]
return (e', (← read).app ``unfold_zsmul (← read).inst #[e₁, e₂, e', p])
| (``SMul.smul, #[.const ``Int _, _, _, e₁, e₂]) =>
evalSMul' eval true e e₁ e₂
| (``SMul.smul, #[.const ``Nat _, _, _, e₁, e₂]) =>
evalSMul' eval false e e₁ e₂
| (``HSMul.hSMul, #[.const ``Int _, _, _, _, e₁, e₂]) =>
evalSMul' eval true e e₁ e₂
| (``HSMul.hSMul, #[.const ``Nat _, _, _, _, e₁, e₂]) =>
evalSMul' eval false e e₁ e₂
| (``smul, #[_, _, e₁, e₂]) => evalSMul' eval false e e₁ e₂
| (``smulg, #[_, _, e₁, e₂]) => evalSMul' eval true e e₁ e₂
| (``OfNat.ofNat, #[_, .lit (.natVal 0), _])
| (``Zero.zero, #[_, _]) =>
if ← isDefEq e (← read).α0 then
pure (← zero', ← mkEqRefl (← read).α0)
else
evalAtom e
| _ => evalAtom e
/-- Tactic for solving equations in the language of
*additive*, commutative monoids and groups.
This version of `abel` fails if the target is not an equality
that is provable by the axioms of commutative monoids/groups.
`abel1!` will use a more aggressive reducibility setting to identify atoms.
This can prove goals that `abel` cannot, but is more expensive.
-/
syntax (name := abel1) "abel1" "!"? : tactic
open Lean Elab Meta Tactic
/-- The `abel1` tactic, which solves equations in the language of commutative additive groups
(or monoids). -/
elab_rules : tactic | `(tactic| abel1 $[!%$tk]?) => withMainContext do
let tm := if tk.isSome then .default else .reducible
let some (_, e₁, e₂) := (← whnfR <| ← getMainTarget).eq?
| throwError "abel1 requires an equality goal"
trace[abel] "running on an equality `{e₁} = {e₂}`."
let c ← mkContext e₁
closeMainGoal `abel1 <| ← AtomM.run tm <| ReaderT.run (r := c) do
let (e₁', p₁) ← eval e₁
trace[abel] "found `{p₁}`, a proof that `{e₁} = {e₁'.e}`"
let (e₂', p₂) ← eval e₂
trace[abel] "found `{p₂}`, a proof that `{e₂} = {e₂'.e}`"
unless ← isDefEq e₁' e₂' do
throwError "abel1 found that the two sides were not equal"
trace[abel] "verified that the simplified forms are identical"
mkEqTrans p₁ (← mkEqSymm p₂)
@[inherit_doc abel1] macro (name := abel1!) "abel1!" : tactic => `(tactic| abel1 !)
theorem term_eq {α : Type*} [AddCommMonoid α] (n : ℕ) (x a : α) : term n x a = n • x + a := rfl
/-- A type synonym used by `abel` to represent `n • x + a` in an additive commutative group. -/
theorem termg_eq {α : Type*} [AddCommGroup α] (n : ℤ) (x a : α) : termg n x a = n • x + a := rfl
/-- True if this represents an atomic expression. -/
def NormalExpr.isAtom : NormalExpr → Bool
| .nterm _ (_, 1) _ (.zero _) => true
| _ => false
/-- The normalization style for `abel_nf`. -/
inductive AbelMode where
/-- The default form -/
| term
/-- Raw form: the representation `abel` uses internally. -/
| raw
/-- Configuration for `abel_nf`. -/
structure AbelNF.Config where
/-- the reducibility setting to use when comparing atoms for defeq -/
red := TransparencyMode.reducible
/-- if true, atoms inside ring expressions will be reduced recursively -/
recursive := true
/-- The normalization style. -/
mode := AbelMode.term
/-- Function elaborating `AbelNF.Config`. -/
declare_config_elab elabAbelNFConfig AbelNF.Config
/--
The core of `abel_nf`, which rewrites the expression `e` into `abel` normal form.
* `s`: a reference to the mutable state of `abel`, for persisting across calls.
This ensures that atom ordering is used consistently.
* `cfg`: the configuration options
* `e`: the expression to rewrite
-/
partial def abelNFCore
(s : IO.Ref AtomM.State) (cfg : AbelNF.Config) (e : Expr) : MetaM Simp.Result := do
let ctx := {
simpTheorems := #[← Elab.Tactic.simpOnlyBuiltins.foldlM (·.addConst ·) {}]
congrTheorems := ← getSimpCongrTheorems }
let simp ← match cfg.mode with
| .raw => pure pure
| .term =>
let thms := [``term_eq, ``termg_eq, ``add_zero, ``one_nsmul, ``one_zsmul, ``zsmul_zero]
let ctx' := { ctx with simpTheorems := #[← thms.foldlM (·.addConst ·) {:_}] }
pure fun r' : Simp.Result ↦ do
r'.mkEqTrans (← Simp.main r'.expr ctx' (methods := ← Lean.Meta.Simp.mkDefaultMethods)).1
let rec
/-- The recursive case of `abelNF`.
* `root`: true when the function is called directly from `abelNFCore`
and false when called by `evalAtom` in recursive mode.
* `parent`: The input expression to simplify. In `pre` we make use of both `parent` and `e`
to determine if we are at the top level in order to prevent a loop
`go -> eval -> evalAtom -> go` which makes no progress.
-/
go root parent :=
let pre : Simp.Simproc := fun e =>
try
guard <| root || parent != e -- recursion guard
let e ← withReducible <| whnf e
guard e.isApp -- all interesting group expressions are applications
let (a, pa) ← eval e (← mkContext e) { red := cfg.red, evalAtom } s
guard !a.isAtom
let r ← simp { expr := a, proof? := pa }
if ← withReducible <| isDefEq r.expr e then return .done { expr := r.expr }
pure (.done r)
catch _ => pure <| .continue
let post : Simp.Simproc := Simp.postDefault #[]
(·.1) <$> Simp.main parent ctx (methods := { pre, post }),
/-- The `evalAtom` implementation passed to `eval` calls `go` if `cfg.recursive` is true,
and does nothing otherwise. -/
evalAtom := if cfg.recursive then go false else fun e ↦ pure { expr := e }
go true e
open Elab.Tactic Parser.Tactic
/-- Use `abel_nf` to rewrite the main goal. -/
def abelNFTarget (s : IO.Ref AtomM.State) (cfg : AbelNF.Config) : TacticM Unit := withMainContext do
let goal ← getMainGoal
let tgt ← withReducible goal.getType'
let r ← abelNFCore s cfg tgt
if r.expr.isConstOf ``True then
goal.assign (← mkOfEqTrue (← r.getProof))
replaceMainGoal []
else
if r.expr == tgt then throwError "abel_nf made no progress"
replaceMainGoal [← applySimpResultToTarget goal tgt r]
/-- Use `abel_nf` to rewrite hypothesis `h`. -/
def abelNFLocalDecl (s : IO.Ref AtomM.State) (cfg : AbelNF.Config) (fvarId : FVarId) :
TacticM Unit := withMainContext do
let tgt ← instantiateMVars (← fvarId.getType)
let goal ← getMainGoal
let myres ← abelNFCore s cfg tgt
if myres.expr == tgt then throwError "abel_nf made no progress"
match ← applySimpResultToLocalDecl goal fvarId myres false with
| none => replaceMainGoal []
| some (_, newGoal) => replaceMainGoal [newGoal]
/-- Unsupported legacy syntax from mathlib3, which allowed passing additional terms to `abel`. -/
syntax (name := abel_term) "abel" (&" raw" <|> &" term")? (location)? : tactic
/-- Unsupported legacy syntax from mathlib3, which allowed passing additional terms to `abel!`. -/
syntax (name := abel!_term) "abel!" (&" raw" <|> &" term")? (location)? : tactic
/--
Simplification tactic for expressions in the language of abelian groups,
which rewrites all group expressions into a normal form.
* `abel_nf!` will use a more aggressive reducibility setting to identify atoms.
* `abel_nf (config := cfg)` allows for additional configuration:
* `red`: the reducibility setting (overridden by `!`)
* `recursive`: if true, `abel_nf` will also recurse into atoms
* `abel_nf` works as both a tactic and a conv tactic.
In tactic mode, `abel_nf at h` can be used to rewrite in a hypothesis.
-/
elab (name := abelNF) "abel_nf" tk:"!"? cfg:(config ?) loc:(location)? : tactic => do
let mut cfg ← elabAbelNFConfig cfg
if tk.isSome then cfg := { cfg with red := .default }
let loc := (loc.map expandLocation).getD (.targets #[] true)
let s ← IO.mkRef {}
withLocation loc (abelNFLocalDecl s cfg) (abelNFTarget s cfg)
fun _ ↦ throwError "abel_nf made no progress"
@[inherit_doc abelNF] macro "abel_nf!" cfg:(config)? loc:(location)? : tactic =>
`(tactic| abel_nf ! $(cfg)? $(loc)?)
@[inherit_doc abelNF] syntax (name := abelNFConv) "abel_nf" "!"? (config)? : conv
/-- Elaborator for the `abel_nf` tactic. -/
@[tactic abelNFConv] def elabAbelNFConv : Tactic := fun stx ↦ match stx with
| `(conv| abel_nf $[!%$tk]? $(_cfg)?) => withMainContext do
let mut cfg ← elabAbelNFConfig stx[2]
if tk.isSome then cfg := { cfg with red := .default }
Conv.applySimpResult (← abelNFCore (← IO.mkRef {}) cfg (← instantiateMVars (← Conv.getLhs)))
| _ => Elab.throwUnsupportedSyntax
@[inherit_doc abelNF] macro "abel_nf!" cfg:(config)? : conv => `(conv| abel_nf ! $(cfg)?)
/--
Tactic for evaluating expressions in abelian groups.
* `abel!` will use a more aggressive reducibility setting to determine equality of atoms.
* `abel1` fails if the target is not an equality.
For example:
```
example [AddCommMonoid α] (a b : α) : a + (b + a) = a + a + b := by abel
example [AddCommGroup α] (a : α) : (3 : ℤ) • a = a + (2 : ℤ) • a := by abel
```
-/
macro (name := abel) "abel" : tactic =>
`(tactic| first | abel1 | try_this abel_nf)
@[inherit_doc abel] macro "abel!" : tactic =>
`(tactic| first | abel1! | try_this abel_nf!)
/--
The tactic `abel` evaluates expressions in abelian groups.
This is the conv tactic version, which rewrites a target which is an abel equality to `True`.
See also the `abel` tactic.
-/
macro (name := abelConv) "abel" : conv =>
`(conv| first | discharge => abel1 | try_this abel_nf)
@[inherit_doc abelConv] macro "abel!" : conv =>
`(conv| first | discharge => abel1! | try_this abel_nf!)
end Abel
end Tactic
end Mathlib
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.