blob_id
stringlengths
40
40
directory_id
stringlengths
40
40
path
stringlengths
7
139
content_id
stringlengths
40
40
detected_licenses
listlengths
0
16
license_type
stringclasses
2 values
repo_name
stringlengths
7
55
snapshot_id
stringlengths
40
40
revision_id
stringlengths
40
40
branch_name
stringclasses
6 values
visit_date
int64
1,471B
1,694B
revision_date
int64
1,378B
1,694B
committer_date
int64
1,378B
1,694B
github_id
float64
1.33M
604M
star_events_count
int64
0
43.5k
fork_events_count
int64
0
1.5k
gha_license_id
stringclasses
6 values
gha_event_created_at
int64
1,402B
1,695B
gha_created_at
int64
1,359B
1,637B
gha_language
stringclasses
19 values
src_encoding
stringclasses
2 values
language
stringclasses
1 value
is_vendor
bool
1 class
is_generated
bool
1 class
length_bytes
int64
3
6.4M
extension
stringclasses
4 values
content
stringlengths
3
6.12M
8b43de381b67b58a735c219efcaa2b02ceaea0d2
a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940
/stage0/src/Init/Prelude.lean
add4a7083c28e8d87907a1cbfa58a3838afdede4
[ "Apache-2.0" ]
permissive
WojciechKarpiel/lean4
7f89706b8e3c1f942b83a2c91a3a00b05da0e65b
f6e1314fa08293dea66a329e05b6c196a0189163
refs/heads/master
1,686,633,402,214
1,625,821,189,000
1,625,821,258,000
384,640,886
0
0
Apache-2.0
1,625,903,617,000
1,625,903,026,000
null
UTF-8
Lean
false
false
75,058
lean
/- Copyright (c) 2020 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ prelude universe u v w @[inline] def id {α : Sort u} (a : α) : α := a /- `idRhs` is an auxiliary declaration used to implement "smart unfolding". It is used as a marker. -/ @[macroInline, reducible] def idRhs (α : Sort u) (a : α) : α := a abbrev Function.comp {α : Sort u} {β : Sort v} {δ : Sort w} (f : β → δ) (g : α → β) : α → δ := fun x => f (g x) abbrev Function.const {α : Sort u} (β : Sort v) (a : α) : β → α := fun x => a set_option checkBinderAnnotations false in @[reducible] def inferInstance {α : Sort u} [i : α] : α := i set_option checkBinderAnnotations false in @[reducible] def inferInstanceAs (α : Sort u) [i : α] : α := i set_option bootstrap.inductiveCheckResultingUniverse false in inductive PUnit : Sort u where | unit : PUnit /-- An abbreviation for `PUnit.{0}`, its most common instantiation. This Type should be preferred over `PUnit` where possible to avoid unnecessary universe parameters. -/ abbrev Unit : Type := PUnit @[matchPattern] abbrev Unit.unit : Unit := PUnit.unit /-- Auxiliary unsafe constant used by the Compiler when erasing proofs from code. -/ unsafe axiom lcProof {α : Prop} : α /-- Auxiliary unsafe constant used by the Compiler to mark unreachable code. -/ unsafe axiom lcUnreachable {α : Sort u} : α inductive True : Prop where | intro : True inductive False : Prop inductive Empty : Type def Not (a : Prop) : Prop := a → False @[macroInline] def False.elim {C : Sort u} (h : False) : C := False.rec (fun _ => C) h @[macroInline] def absurd {a : Prop} {b : Sort v} (h₁ : a) (h₂ : Not a) : b := False.elim (h₂ h₁) inductive Eq {α : Sort u} (a : α) : α → Prop where | refl {} : Eq a a @[simp] abbrev Eq.ndrec.{u1, u2} {α : Sort u2} {a : α} {motive : α → Sort u1} (m : motive a) {b : α} (h : Eq a b) : motive b := Eq.rec (motive := fun α _ => motive α) m h @[matchPattern] def rfl {α : Sort u} {a : α} : Eq a a := Eq.refl a @[simp] theorem id_eq (a : α) : Eq (id a) a := rfl theorem Eq.subst {α : Sort u} {motive : α → Prop} {a b : α} (h₁ : Eq a b) (h₂ : motive a) : motive b := Eq.ndrec h₂ h₁ theorem Eq.symm {α : Sort u} {a b : α} (h : Eq a b) : Eq b a := h ▸ rfl theorem Eq.trans {α : Sort u} {a b c : α} (h₁ : Eq a b) (h₂ : Eq b c) : Eq a c := h₂ ▸ h₁ @[macroInline] def cast {α β : Sort u} (h : Eq α β) (a : α) : β := Eq.rec (motive := fun α _ => α) a h theorem congrArg {α : Sort u} {β : Sort v} {a₁ a₂ : α} (f : α → β) (h : Eq a₁ a₂) : Eq (f a₁) (f a₂) := h ▸ rfl theorem congr {α : Sort u} {β : Sort v} {f₁ f₂ : α → β} {a₁ a₂ : α} (h₁ : Eq f₁ f₂) (h₂ : Eq a₁ a₂) : Eq (f₁ a₁) (f₂ a₂) := h₁ ▸ h₂ ▸ rfl theorem congrFun {α : Sort u} {β : α → Sort v} {f g : (x : α) → β x} (h : Eq f g) (a : α) : Eq (f a) (g a) := h ▸ rfl /- Initialize the Quotient Module, which effectively adds the following definitions: constant Quot {α : Sort u} (r : α → α → Prop) : Sort u constant Quot.mk {α : Sort u} (r : α → α → Prop) (a : α) : Quot r constant Quot.lift {α : Sort u} {r : α → α → Prop} {β : Sort v} (f : α → β) : (∀ a b : α, r a b → Eq (f a) (f b)) → Quot r → β constant Quot.ind {α : Sort u} {r : α → α → Prop} {β : Quot r → Prop} : (∀ a : α, β (Quot.mk r a)) → ∀ q : Quot r, β q -/ init_quot inductive HEq {α : Sort u} (a : α) : {β : Sort u} → β → Prop where | refl {} : HEq a a @[matchPattern] def HEq.rfl {α : Sort u} {a : α} : HEq a a := HEq.refl a theorem eqOfHEq {α : Sort u} {a a' : α} (h : HEq a a') : Eq a a' := have : (α β : Sort u) → (a : α) → (b : β) → HEq a b → (h : Eq α β) → Eq (cast h a) b := fun α β a b h₁ => HEq.rec (motive := fun {β} (b : β) (h : HEq a b) => (h₂ : Eq α β) → Eq (cast h₂ a) b) (fun (h₂ : Eq α α) => rfl) h₁ this α α a a' h rfl structure Prod (α : Type u) (β : Type v) where fst : α snd : β attribute [unbox] Prod /-- Similar to `Prod`, but `α` and `β` can be propositions. We use this Type internally to automatically generate the brecOn recursor. -/ structure PProd (α : Sort u) (β : Sort v) where fst : α snd : β /-- Similar to `Prod`, but `α` and `β` are in the same universe. -/ structure MProd (α β : Type u) where fst : α snd : β structure And (a b : Prop) : Prop where intro :: (left : a) (right : b) inductive Or (a b : Prop) : Prop where | inl (h : a) : Or a b | inr (h : b) : Or a b inductive Bool : Type where | false : Bool | true : Bool export Bool (false true) /- Remark: Subtype must take a Sort instead of Type because of the axiom strongIndefiniteDescription. -/ structure Subtype {α : Sort u} (p : α → Prop) where val : α property : p val /-- Gadget for optional parameter support. -/ @[reducible] def optParam (α : Sort u) (default : α) : Sort u := α /-- Gadget for marking output parameters in type classes. -/ @[reducible] def outParam (α : Sort u) : Sort u := α /-- Auxiliary Declaration used to implement the notation (a : α) -/ @[reducible] def typedExpr (α : Sort u) (a : α) : α := a /-- Auxiliary Declaration used to implement the named patterns `x@p` -/ @[reducible] def namedPattern {α : Sort u} (x a : α) : α := a /- Auxiliary axiom used to implement `sorry`. -/ @[extern "lean_sorry", neverExtract] axiom sorryAx (α : Sort u) (synthetic := true) : α theorem eqFalseOfNeTrue : {b : Bool} → Not (Eq b true) → Eq b false | true, h => False.elim (h rfl) | false, h => rfl theorem eqTrueOfNeFalse : {b : Bool} → Not (Eq b false) → Eq b true | true, h => rfl | false, h => False.elim (h rfl) theorem neFalseOfEqTrue : {b : Bool} → Eq b true → Not (Eq b false) | true, _ => fun h => Bool.noConfusion h | false, h => Bool.noConfusion h theorem neTrueOfEqFalse : {b : Bool} → Eq b false → Not (Eq b true) | true, h => Bool.noConfusion h | false, _ => fun h => Bool.noConfusion h class Inhabited (α : Sort u) where mk {} :: (default : α) constant arbitrary [Inhabited α] : α := Inhabited.default instance : Inhabited (Sort u) where default := PUnit instance (α : Sort u) {β : Sort v} [Inhabited β] : Inhabited (α → β) where default := fun _ => arbitrary instance (α : Sort u) {β : α → Sort v} [(a : α) → Inhabited (β a)] : Inhabited ((a : α) → β a) where default := fun _ => arbitrary deriving instance Inhabited for Bool /-- Universe lifting operation from Sort to Type -/ structure PLift (α : Sort u) : Type u where up :: (down : α) /- Bijection between α and PLift α -/ theorem PLift.upDown {α : Sort u} : ∀ (b : PLift α), Eq (up (down b)) b | up a => rfl theorem PLift.downUp {α : Sort u} (a : α) : Eq (down (up a)) a := rfl /- Pointed types -/ structure PointedType where (type : Type u) (val : type) instance : Inhabited PointedType.{u} where default := { type := PUnit.{u+1}, val := ⟨⟩ } /-- Universe lifting operation -/ structure ULift.{r, s} (α : Type s) : Type (max s r) where up :: (down : α) /- Bijection between α and ULift.{v} α -/ theorem ULift.upDown {α : Type u} : ∀ (b : ULift.{v} α), Eq (up (down b)) b | up a => rfl theorem ULift.downUp {α : Type u} (a : α) : Eq (down (up.{v} a)) a := rfl class inductive Decidable (p : Prop) where | isFalse (h : Not p) : Decidable p | isTrue (h : p) : Decidable p @[inlineIfReduce, nospecialize] def Decidable.decide (p : Prop) [h : Decidable p] : Bool := Decidable.casesOn (motive := fun _ => Bool) h (fun _ => false) (fun _ => true) export Decidable (isTrue isFalse decide) abbrev DecidablePred {α : Sort u} (r : α → Prop) := (a : α) → Decidable (r a) abbrev DecidableRel {α : Sort u} (r : α → α → Prop) := (a b : α) → Decidable (r a b) abbrev DecidableEq (α : Sort u) := (a b : α) → Decidable (Eq a b) def decEq {α : Sort u} [s : DecidableEq α] (a b : α) : Decidable (Eq a b) := s a b theorem decideEqTrue : [s : Decidable p] → p → Eq (decide p) true | isTrue _, _ => rfl | isFalse h₁, h₂ => absurd h₂ h₁ theorem decideEqFalse : [s : Decidable p] → Not p → Eq (decide p) false | isTrue h₁, h₂ => absurd h₁ h₂ | isFalse h, _ => rfl theorem ofDecideEqTrue [s : Decidable p] : Eq (decide p) true → p := fun h => match (generalizing := false) s with | isTrue h₁ => h₁ | isFalse h₁ => absurd h (neTrueOfEqFalse (decideEqFalse h₁)) theorem ofDecideEqFalse [s : Decidable p] : Eq (decide p) false → Not p := fun h => match (generalizing := false) s with | isTrue h₁ => absurd h (neFalseOfEqTrue (decideEqTrue h₁)) | isFalse h₁ => h₁ @[inline] instance : DecidableEq Bool := fun a b => match a, b with | false, false => isTrue rfl | false, true => isFalse (fun h => Bool.noConfusion h) | true, false => isFalse (fun h => Bool.noConfusion h) | true, true => isTrue rfl class BEq (α : Type u) where beq : α → α → Bool open BEq (beq) instance [DecidableEq α] : BEq α where beq a b := decide (Eq a b) -- We use "dependent" if-then-else to be able to communicate the if-then-else condition -- to the branches @[macroInline] def dite {α : Sort u} (c : Prop) [h : Decidable c] (t : c → α) (e : Not c → α) : α := Decidable.casesOn (motive := fun _ => α) h e t /- if-then-else -/ @[macroInline] def ite {α : Sort u} (c : Prop) [h : Decidable c] (t e : α) : α := Decidable.casesOn (motive := fun _ => α) h (fun _ => e) (fun _ => t) @[macroInline] instance {p q} [dp : Decidable p] [dq : Decidable q] : Decidable (And p q) := match dp with | isTrue hp => match dq with | isTrue hq => isTrue ⟨hp, hq⟩ | isFalse hq => isFalse (fun h => hq (And.right h)) | isFalse hp => isFalse (fun h => hp (And.left h)) @[macroInline] instance [dp : Decidable p] [dq : Decidable q] : Decidable (Or p q) := match dp with | isTrue hp => isTrue (Or.inl hp) | isFalse hp => match dq with | isTrue hq => isTrue (Or.inr hq) | isFalse hq => isFalse fun h => match h with | Or.inl h => hp h | Or.inr h => hq h instance [dp : Decidable p] : Decidable (Not p) := match dp with | isTrue hp => isFalse (absurd hp) | isFalse hp => isTrue hp /- Boolean operators -/ @[macroInline] def cond {α : Type u} (c : Bool) (x y : α) : α := match c with | true => x | false => y @[macroInline] def or (x y : Bool) : Bool := match x with | true => true | false => y @[macroInline] def and (x y : Bool) : Bool := match x with | false => false | true => y @[inline] def not : Bool → Bool | true => false | false => true inductive Nat where | zero : Nat | succ (n : Nat) : Nat instance : Inhabited Nat where default := Nat.zero /- For numeric literals notation -/ class OfNat (α : Type u) (n : Nat) where ofNat : α @[defaultInstance 100] /- low prio -/ instance (n : Nat) : OfNat Nat n where ofNat := n class LE (α : Type u) where le : α → α → Prop class LT (α : Type u) where lt : α → α → Prop @[reducible] def GE.ge {α : Type u} [LE α] (a b : α) : Prop := LE.le b a @[reducible] def GT.gt {α : Type u} [LT α] (a b : α) : Prop := LT.lt b a @[inline] def max [LT α] [DecidableRel (@LT.lt α _)] (a b : α) : α := ite (LT.lt b a) a b @[inline] def min [LE α] [DecidableRel (@LE.le α _)] (a b : α) : α := ite (LE.le a b) a b class HAdd (α : Type u) (β : Type v) (γ : outParam (Type w)) where hAdd : α → β → γ class HSub (α : Type u) (β : Type v) (γ : outParam (Type w)) where hSub : α → β → γ class HMul (α : Type u) (β : Type v) (γ : outParam (Type w)) where hMul : α → β → γ class HDiv (α : Type u) (β : Type v) (γ : outParam (Type w)) where hDiv : α → β → γ class HMod (α : Type u) (β : Type v) (γ : outParam (Type w)) where hMod : α → β → γ class HPow (α : Type u) (β : Type v) (γ : outParam (Type w)) where hPow : α → β → γ class HAppend (α : Type u) (β : Type v) (γ : outParam (Type w)) where hAppend : α → β → γ class HOrElse (α : Type u) (β : Type v) (γ : outParam (Type w)) where hOrElse : α → β → γ class HAndThen (α : Type u) (β : Type v) (γ : outParam (Type w)) where hAndThen : α → β → γ class HAnd (α : Type u) (β : Type v) (γ : outParam (Type w)) where hAnd : α → β → γ class HXor (α : Type u) (β : Type v) (γ : outParam (Type w)) where hXor : α → β → γ class HOr (α : Type u) (β : Type v) (γ : outParam (Type w)) where hOr : α → β → γ class HShiftLeft (α : Type u) (β : Type v) (γ : outParam (Type w)) where hShiftLeft : α → β → γ class HShiftRight (α : Type u) (β : Type v) (γ : outParam (Type w)) where hShiftRight : α → β → γ class Add (α : Type u) where add : α → α → α class Sub (α : Type u) where sub : α → α → α class Mul (α : Type u) where mul : α → α → α class Neg (α : Type u) where neg : α → α class Div (α : Type u) where div : α → α → α class Mod (α : Type u) where mod : α → α → α class Pow (α : Type u) where pow : α → α → α class Append (α : Type u) where append : α → α → α class OrElse (α : Type u) where orElse : α → α → α class AndThen (α : Type u) where andThen : α → α → α class AndOp (α : Type u) where and : α → α → α class Xor (α : Type u) where xor : α → α → α class OrOp (α : Type u) where or : α → α → α class Complement (α : Type u) where complement : α → α class ShiftLeft (α : Type u) where shiftLeft : α → α → α class ShiftRight (α : Type u) where shiftRight : α → α → α @[defaultInstance] instance [Add α] : HAdd α α α where hAdd a b := Add.add a b @[defaultInstance] instance [Sub α] : HSub α α α where hSub a b := Sub.sub a b @[defaultInstance] instance [Mul α] : HMul α α α where hMul a b := Mul.mul a b @[defaultInstance] instance [Div α] : HDiv α α α where hDiv a b := Div.div a b @[defaultInstance] instance [Mod α] : HMod α α α where hMod a b := Mod.mod a b @[defaultInstance] instance [Pow α] : HPow α α α where hPow a b := Pow.pow a b @[defaultInstance] instance [Append α] : HAppend α α α where hAppend a b := Append.append a b @[defaultInstance] instance [OrElse α] : HOrElse α α α where hOrElse a b := OrElse.orElse a b @[defaultInstance] instance [AndThen α] : HAndThen α α α where hAndThen a b := AndThen.andThen a b @[defaultInstance] instance [AndOp α] : HAnd α α α where hAnd a b := AndOp.and a b @[defaultInstance] instance [Xor α] : HXor α α α where hXor a b := Xor.xor a b @[defaultInstance] instance [OrOp α] : HOr α α α where hOr a b := OrOp.or a b @[defaultInstance] instance [ShiftLeft α] : HShiftLeft α α α where hShiftLeft a b := ShiftLeft.shiftLeft a b @[defaultInstance] instance [ShiftRight α] : HShiftRight α α α where hShiftRight a b := ShiftRight.shiftRight a b open HAdd (hAdd) open HMul (hMul) open HPow (hPow) open HAppend (hAppend) set_option bootstrap.genMatcherCode false in @[extern "lean_nat_add"] protected def Nat.add : (@& Nat) → (@& Nat) → Nat | a, Nat.zero => a | a, Nat.succ b => Nat.succ (Nat.add a b) instance : Add Nat where add := Nat.add /- We mark the following definitions as pattern to make sure they can be used in recursive equations, and reduced by the equation Compiler. -/ attribute [matchPattern] Nat.add Add.add HAdd.hAdd Neg.neg set_option bootstrap.genMatcherCode false in @[extern "lean_nat_mul"] protected def Nat.mul : (@& Nat) → (@& Nat) → Nat | a, 0 => 0 | a, Nat.succ b => Nat.add (Nat.mul a b) a instance : Mul Nat where mul := Nat.mul set_option bootstrap.genMatcherCode false in @[extern "lean_nat_pow"] protected def Nat.pow (m : @& Nat) : (@& Nat) → Nat | 0 => 1 | succ n => Nat.mul (Nat.pow m n) m instance : Pow Nat where pow := Nat.pow set_option bootstrap.genMatcherCode false in @[extern "lean_nat_dec_eq"] def Nat.beq : (@& Nat) → (@& Nat) → Bool | zero, zero => true | zero, succ m => false | succ n, zero => false | succ n, succ m => beq n m theorem Nat.eqOfBeqEqTrue : {n m : Nat} → Eq (beq n m) true → Eq n m | zero, zero, h => rfl | zero, succ m, h => Bool.noConfusion h | succ n, zero, h => Bool.noConfusion h | succ n, succ m, h => have : Eq (beq n m) true := h have : Eq n m := eqOfBeqEqTrue this this ▸ rfl theorem Nat.neOfBeqEqFalse : {n m : Nat} → Eq (beq n m) false → Not (Eq n m) | zero, zero, h₁, h₂ => Bool.noConfusion h₁ | zero, succ m, h₁, h₂ => Nat.noConfusion h₂ | succ n, zero, h₁, h₂ => Nat.noConfusion h₂ | succ n, succ m, h₁, h₂ => have : Eq (beq n m) false := h₁ Nat.noConfusion h₂ (fun h₂ => absurd h₂ (neOfBeqEqFalse this)) @[extern "lean_nat_dec_eq"] protected def Nat.decEq (n m : @& Nat) : Decidable (Eq n m) := match h:beq n m with | true => isTrue (eqOfBeqEqTrue h) | false => isFalse (neOfBeqEqFalse h) @[inline] instance : DecidableEq Nat := Nat.decEq set_option bootstrap.genMatcherCode false in @[extern "lean_nat_dec_le"] def Nat.ble : @& Nat → @& Nat → Bool | zero, zero => true | zero, succ m => true | succ n, zero => false | succ n, succ m => ble n m protected def Nat.le (n m : Nat) : Prop := Eq (ble n m) true instance : LE Nat where le := Nat.le protected def Nat.lt (n m : Nat) : Prop := Nat.le (succ n) m instance : LT Nat where lt := Nat.lt theorem Nat.notSuccLeZero : ∀ (n : Nat), LE.le (succ n) 0 → False | 0, h => nomatch h | succ n, h => nomatch h theorem Nat.notLtZero (n : Nat) : Not (LT.lt n 0) := notSuccLeZero n @[extern "lean_nat_dec_le"] instance Nat.decLe (n m : @& Nat) : Decidable (LE.le n m) := decEq (Nat.ble n m) true @[extern "lean_nat_dec_lt"] instance Nat.decLt (n m : @& Nat) : Decidable (LT.lt n m) := decLe (succ n) m theorem Nat.zeroLe : (n : Nat) → LE.le 0 n | zero => rfl | succ n => rfl theorem Nat.succLeSucc {n m : Nat} (h : LE.le n m) : LE.le (succ n) (succ m) := h theorem Nat.zeroLtSucc (n : Nat) : LT.lt 0 (succ n) := succLeSucc (zeroLe n) theorem Nat.leStep : {n m : Nat} → LE.le n m → LE.le n (succ m) | zero, zero, h => rfl | zero, succ n, h => rfl | succ n, zero, h => Bool.noConfusion h | succ n, succ m, h => have : LE.le n m := h have : LE.le n (succ m) := leStep this succLeSucc this protected theorem Nat.leTrans : {n m k : Nat} → LE.le n m → LE.le m k → LE.le n k | zero, m, k, h₁, h₂ => zeroLe _ | succ n, zero, k, h₁, h₂ => Bool.noConfusion h₁ | succ n, succ m, zero, h₁, h₂ => Bool.noConfusion h₂ | succ n, succ m, succ k, h₁, h₂ => have h₁' : LE.le n m := h₁ have h₂' : LE.le m k := h₂ show LE.le n k from Nat.leTrans h₁' h₂' protected theorem Nat.ltTrans {n m k : Nat} (h₁ : LT.lt n m) : LT.lt m k → LT.lt n k := Nat.leTrans (leStep h₁) theorem Nat.leSucc : (n : Nat) → LE.le n (succ n) | zero => rfl | succ n => leSucc n theorem Nat.leSuccOfLe {n m : Nat} (h : LE.le n m) : LE.le n (succ m) := Nat.leTrans h (leSucc m) protected theorem Nat.eqOrLtOfLe : {n m: Nat} → LE.le n m → Or (Eq n m) (LT.lt n m) | zero, zero, h => Or.inl rfl | zero, succ n, h => Or.inr (zeroLe n) | succ n, zero, h => Bool.noConfusion h | succ n, succ m, h => have : LE.le n m := h match Nat.eqOrLtOfLe this with | Or.inl h => Or.inl (h ▸ rfl) | Or.inr h => Or.inr (succLeSucc h) protected def Nat.leRefl : (n : Nat) → LE.le n n | zero => rfl | succ n => Nat.leRefl n protected theorem Nat.ltOrGe (n m : Nat) : Or (LT.lt n m) (GE.ge n m) := match m with | zero => Or.inr (zeroLe n) | succ m => match Nat.ltOrGe n m with | Or.inl h => Or.inl (leSuccOfLe h) | Or.inr h => match Nat.eqOrLtOfLe h with | Or.inl h1 => Or.inl (h1 ▸ Nat.leRefl _) | Or.inr h1 => Or.inr h1 protected theorem Nat.leAntisymm : {n m : Nat} → LE.le n m → LE.le m n → Eq n m | zero, zero, h₁, h₂ => rfl | succ n, zero, h₁, h₂ => Bool.noConfusion h₁ | zero, succ m, h₁, h₂ => Bool.noConfusion h₂ | succ n, succ m, h₁, h₂ => have h₁' : LE.le n m := h₁ have h₂' : LE.le m n := h₂ (Nat.leAntisymm h₁' h₂') ▸ rfl protected theorem Nat.ltOfLeOfNe {n m : Nat} (h₁ : LE.le n m) (h₂ : Not (Eq n m)) : LT.lt n m := match Nat.ltOrGe n m with | Or.inl h₃ => h₃ | Or.inr h₃ => absurd (Nat.leAntisymm h₁ h₃) h₂ set_option bootstrap.genMatcherCode false in @[extern c inline "lean_nat_sub(#1, lean_box(1))"] def Nat.pred : (@& Nat) → Nat | 0 => 0 | succ a => a set_option bootstrap.genMatcherCode false in @[extern "lean_nat_sub"] protected def Nat.sub : (@& Nat) → (@& Nat) → Nat | a, 0 => a | a, succ b => pred (Nat.sub a b) instance : Sub Nat where sub := Nat.sub theorem Nat.predLePred : {n m : Nat} → LE.le n m → LE.le (pred n) (pred m) | zero, zero, h => rfl | zero, succ n, h => zeroLe n | succ n, zero, h => Bool.noConfusion h | succ n, succ m, h => h theorem Nat.leOfSuccLeSucc {n m : Nat} : LE.le (succ n) (succ m) → LE.le n m := predLePred theorem Nat.leOfLtSucc {m n : Nat} : LT.lt m (succ n) → LE.le m n := leOfSuccLeSucc @[extern "lean_system_platform_nbits"] constant System.Platform.getNumBits : Unit → Subtype fun (n : Nat) => Or (Eq n 32) (Eq n 64) := fun _ => ⟨64, Or.inr rfl⟩ -- inhabitant def System.Platform.numBits : Nat := (getNumBits ()).val theorem System.Platform.numBitsEq : Or (Eq numBits 32) (Eq numBits 64) := (getNumBits ()).property structure Fin (n : Nat) where val : Nat isLt : LT.lt val n theorem Fin.eqOfVeq {n} : ∀ {i j : Fin n}, Eq i.val j.val → Eq i j | ⟨v, h⟩, ⟨_, _⟩, rfl => rfl theorem Fin.veqOfEq {n} {i j : Fin n} (h : Eq i j) : Eq i.val j.val := h ▸ rfl theorem Fin.neOfVne {n} {i j : Fin n} (h : Not (Eq i.val j.val)) : Not (Eq i j) := fun h' => absurd (veqOfEq h') h instance (n : Nat) : DecidableEq (Fin n) := fun i j => match decEq i.val j.val with | isTrue h => isTrue (Fin.eqOfVeq h) | isFalse h => isFalse (Fin.neOfVne h) instance {n} : LT (Fin n) where lt a b := LT.lt a.val b.val instance {n} : LE (Fin n) where le a b := LE.le a.val b.val instance Fin.decLt {n} (a b : Fin n) : Decidable (LT.lt a b) := Nat.decLt .. instance Fin.decLe {n} (a b : Fin n) : Decidable (LE.le a b) := Nat.decLe .. def UInt8.size : Nat := 256 structure UInt8 where val : Fin UInt8.size attribute [extern "lean_uint8_of_nat_mk"] UInt8.mk attribute [extern "lean_uint8_to_nat"] UInt8.val @[extern "lean_uint8_of_nat"] def UInt8.ofNatCore (n : @& Nat) (h : LT.lt n UInt8.size) : UInt8 := { val := { val := n, isLt := h } } set_option bootstrap.genMatcherCode false in @[extern c inline "#1 == #2"] def UInt8.decEq (a b : UInt8) : Decidable (Eq a b) := match a, b with | ⟨n⟩, ⟨m⟩ => dite (Eq n m) (fun h => isTrue (h ▸ rfl)) (fun h => isFalse (fun h' => UInt8.noConfusion h' (fun h' => absurd h' h))) instance : DecidableEq UInt8 := UInt8.decEq instance : Inhabited UInt8 where default := UInt8.ofNatCore 0 (by decide) def UInt16.size : Nat := 65536 structure UInt16 where val : Fin UInt16.size attribute [extern "lean_uint16_of_nat_mk"] UInt16.mk attribute [extern "lean_uint16_to_nat"] UInt16.val @[extern "lean_uint16_of_nat"] def UInt16.ofNatCore (n : @& Nat) (h : LT.lt n UInt16.size) : UInt16 := { val := { val := n, isLt := h } } set_option bootstrap.genMatcherCode false in @[extern c inline "#1 == #2"] def UInt16.decEq (a b : UInt16) : Decidable (Eq a b) := match a, b with | ⟨n⟩, ⟨m⟩ => dite (Eq n m) (fun h => isTrue (h ▸ rfl)) (fun h => isFalse (fun h' => UInt16.noConfusion h' (fun h' => absurd h' h))) instance : DecidableEq UInt16 := UInt16.decEq instance : Inhabited UInt16 where default := UInt16.ofNatCore 0 (by decide) def UInt32.size : Nat := 4294967296 structure UInt32 where val : Fin UInt32.size attribute [extern "lean_uint32_of_nat_mk"] UInt32.mk attribute [extern "lean_uint32_to_nat"] UInt32.val @[extern "lean_uint32_of_nat"] def UInt32.ofNatCore (n : @& Nat) (h : LT.lt n UInt32.size) : UInt32 := { val := { val := n, isLt := h } } @[extern "lean_uint32_to_nat"] def UInt32.toNat (n : UInt32) : Nat := n.val.val set_option bootstrap.genMatcherCode false in @[extern c inline "#1 == #2"] def UInt32.decEq (a b : UInt32) : Decidable (Eq a b) := match a, b with | ⟨n⟩, ⟨m⟩ => dite (Eq n m) (fun h => isTrue (h ▸ rfl)) (fun h => isFalse (fun h' => UInt32.noConfusion h' (fun h' => absurd h' h))) instance : DecidableEq UInt32 := UInt32.decEq instance : Inhabited UInt32 where default := UInt32.ofNatCore 0 (by decide) instance : LT UInt32 where lt a b := LT.lt a.val b.val instance : LE UInt32 where le a b := LE.le a.val b.val set_option bootstrap.genMatcherCode false in @[extern c inline "#1 < #2"] def UInt32.decLt (a b : UInt32) : Decidable (LT.lt a b) := match a, b with | ⟨n⟩, ⟨m⟩ => inferInstanceAs (Decidable (LT.lt n m)) set_option bootstrap.genMatcherCode false in @[extern c inline "#1 <= #2"] def UInt32.decLe (a b : UInt32) : Decidable (LE.le a b) := match a, b with | ⟨n⟩, ⟨m⟩ => inferInstanceAs (Decidable (LE.le n m)) instance (a b : UInt32) : Decidable (LT.lt a b) := UInt32.decLt a b instance (a b : UInt32) : Decidable (LE.le a b) := UInt32.decLe a b def UInt64.size : Nat := 18446744073709551616 structure UInt64 where val : Fin UInt64.size attribute [extern "lean_uint64_of_nat_mk"] UInt64.mk attribute [extern "lean_uint64_to_nat"] UInt64.val @[extern "lean_uint64_of_nat"] def UInt64.ofNatCore (n : @& Nat) (h : LT.lt n UInt64.size) : UInt64 := { val := { val := n, isLt := h } } set_option bootstrap.genMatcherCode false in @[extern c inline "#1 == #2"] def UInt64.decEq (a b : UInt64) : Decidable (Eq a b) := match a, b with | ⟨n⟩, ⟨m⟩ => dite (Eq n m) (fun h => isTrue (h ▸ rfl)) (fun h => isFalse (fun h' => UInt64.noConfusion h' (fun h' => absurd h' h))) instance : DecidableEq UInt64 := UInt64.decEq instance : Inhabited UInt64 where default := UInt64.ofNatCore 0 (by decide) def USize.size : Nat := hPow 2 System.Platform.numBits theorem usizeSzEq : Or (Eq USize.size 4294967296) (Eq USize.size 18446744073709551616) := show Or (Eq (hPow 2 System.Platform.numBits) 4294967296) (Eq (hPow 2 System.Platform.numBits) 18446744073709551616) from match System.Platform.numBits, System.Platform.numBitsEq with | _, Or.inl rfl => Or.inl (by decide) | _, Or.inr rfl => Or.inr (by decide) structure USize where val : Fin USize.size attribute [extern "lean_usize_of_nat_mk"] USize.mk attribute [extern "lean_usize_to_nat"] USize.val @[extern "lean_usize_of_nat"] def USize.ofNatCore (n : @& Nat) (h : LT.lt n USize.size) : USize := { val := { val := n, isLt := h } } set_option bootstrap.genMatcherCode false in @[extern c inline "#1 == #2"] def USize.decEq (a b : USize) : Decidable (Eq a b) := match a, b with | ⟨n⟩, ⟨m⟩ => dite (Eq n m) (fun h =>isTrue (h ▸ rfl)) (fun h => isFalse (fun h' => USize.noConfusion h' (fun h' => absurd h' h))) instance : DecidableEq USize := USize.decEq instance : Inhabited USize where default := USize.ofNatCore 0 (match USize.size, usizeSzEq with | _, Or.inl rfl => by decide | _, Or.inr rfl => by decide) @[extern "lean_usize_of_nat"] def USize.ofNat32 (n : @& Nat) (h : LT.lt n 4294967296) : USize := { val := { val := n isLt := match USize.size, usizeSzEq with | _, Or.inl rfl => h | _, Or.inr rfl => Nat.ltTrans h (by decide) } } abbrev Nat.isValidChar (n : Nat) : Prop := Or (LT.lt n 0xd800) (And (LT.lt 0xdfff n) (LT.lt n 0x110000)) abbrev UInt32.isValidChar (n : UInt32) : Prop := n.toNat.isValidChar /-- The `Char` Type represents an unicode scalar value. See http://www.unicode.org/glossary/#unicode_scalar_value). -/ structure Char where val : UInt32 valid : val.isValidChar private theorem validCharIsUInt32 {n : Nat} (h : n.isValidChar) : LT.lt n UInt32.size := match h with | Or.inl h => Nat.ltTrans h (by decide) | Or.inr ⟨_, h⟩ => Nat.ltTrans h (by decide) @[extern "lean_uint32_of_nat"] private def Char.ofNatAux (n : @& Nat) (h : n.isValidChar) : Char := { val := ⟨{ val := n, isLt := validCharIsUInt32 h }⟩, valid := h } @[noinline, matchPattern] def Char.ofNat (n : Nat) : Char := dite (n.isValidChar) (fun h => Char.ofNatAux n h) (fun _ => { val := ⟨{ val := 0, isLt := by decide }⟩, valid := Or.inl (by decide) }) theorem Char.eqOfVeq : ∀ {c d : Char}, Eq c.val d.val → Eq c d | ⟨v, h⟩, ⟨_, _⟩, rfl => rfl theorem Char.veqOfEq : ∀ {c d : Char}, Eq c d → Eq c.val d.val | _, _, rfl => rfl theorem Char.neOfVne {c d : Char} (h : Not (Eq c.val d.val)) : Not (Eq c d) := fun h' => absurd (veqOfEq h') h theorem Char.vneOfNe {c d : Char} (h : Not (Eq c d)) : Not (Eq c.val d.val) := fun h' => absurd (eqOfVeq h') h instance : DecidableEq Char := fun c d => match decEq c.val d.val with | isTrue h => isTrue (Char.eqOfVeq h) | isFalse h => isFalse (Char.neOfVne h) def Char.utf8Size (c : Char) : UInt32 := let v := c.val ite (LE.le v (UInt32.ofNatCore 0x7F (by decide))) (UInt32.ofNatCore 1 (by decide)) (ite (LE.le v (UInt32.ofNatCore 0x7FF (by decide))) (UInt32.ofNatCore 2 (by decide)) (ite (LE.le v (UInt32.ofNatCore 0xFFFF (by decide))) (UInt32.ofNatCore 3 (by decide)) (UInt32.ofNatCore 4 (by decide)))) inductive Option (α : Type u) where | none : Option α | some (val : α) : Option α attribute [unbox] Option export Option (none some) instance {α} : Inhabited (Option α) where default := none @[macroInline] def Option.getD : Option α → α → α | some x, _ => x | none, e => e inductive List (α : Type u) where | nil : List α | cons (head : α) (tail : List α) : List α instance {α} : Inhabited (List α) where default := List.nil protected def List.hasDecEq {α: Type u} [DecidableEq α] : (a b : List α) → Decidable (Eq a b) | nil, nil => isTrue rfl | cons a as, nil => isFalse (fun h => List.noConfusion h) | nil, cons b bs => isFalse (fun h => List.noConfusion h) | cons a as, cons b bs => match decEq a b with | isTrue hab => match List.hasDecEq as bs with | isTrue habs => isTrue (hab ▸ habs ▸ rfl) | isFalse nabs => isFalse (fun h => List.noConfusion h (fun _ habs => absurd habs nabs)) | isFalse nab => isFalse (fun h => List.noConfusion h (fun hab _ => absurd hab nab)) instance {α : Type u} [DecidableEq α] : DecidableEq (List α) := List.hasDecEq @[specialize] def List.foldl {α β} (f : α → β → α) : (init : α) → List β → α | a, nil => a | a, cons b l => foldl f (f a b) l def List.set : List α → Nat → α → List α | cons a as, 0, b => cons b as | cons a as, Nat.succ n, b => cons a (set as n b) | nil, _, _ => nil def List.lengthAux {α : Type u} : List α → Nat → Nat | nil, n => n | cons a as, n => lengthAux as (Nat.succ n) def List.length {α : Type u} (as : List α) : Nat := lengthAux as 0 @[simp] theorem List.length_cons {α} (a : α) (as : List α) : Eq (cons a as).length as.length.succ := let rec aux (a : α) (as : List α) : (n : Nat) → Eq ((cons a as).lengthAux n) (as.lengthAux n).succ := match as with | nil => fun _ => rfl | cons a as => fun n => aux a as n.succ aux a as 0 def List.concat {α : Type u} : List α → α → List α | nil, b => cons b nil | cons a as, b => cons a (concat as b) def List.get {α : Type u} : (as : List α) → (i : Nat) → LT.lt i as.length → α | nil, i, h => absurd h (Nat.notLtZero _) | cons a as, 0, h => a | cons a as, Nat.succ i, h => have : LT.lt i.succ as.length.succ := length_cons .. ▸ h get as i (Nat.leOfSuccLeSucc this) structure String where data : List Char attribute [extern "lean_string_mk"] String.mk attribute [extern "lean_string_data"] String.data @[extern "lean_string_dec_eq"] def String.decEq (s₁ s₂ : @& String) : Decidable (Eq s₁ s₂) := match s₁, s₂ with | ⟨s₁⟩, ⟨s₂⟩ => dite (Eq s₁ s₂) (fun h => isTrue (congrArg _ h)) (fun h => isFalse (fun h' => String.noConfusion h' (fun h' => absurd h' h))) instance : DecidableEq String := String.decEq /-- A byte position in a `String`. Internally, `String`s are UTF-8 encoded. Codepoint positions (counting the Unicode codepoints rather than bytes) are represented by plain `Nat`s instead. Indexing a `String` by a byte position is constant-time, while codepoint positions need to be translated internally to byte positions in linear-time. -/ abbrev String.Pos := Nat structure Substring where str : String startPos : String.Pos stopPos : String.Pos @[inline] def Substring.bsize : Substring → Nat | ⟨_, b, e⟩ => e.sub b def String.csize (c : Char) : Nat := c.utf8Size.toNat private def String.utf8ByteSizeAux : List Char → Nat → Nat | List.nil, r => r | List.cons c cs, r => utf8ByteSizeAux cs (hAdd r (csize c)) @[extern "lean_string_utf8_byte_size"] def String.utf8ByteSize : (@& String) → Nat | ⟨s⟩ => utf8ByteSizeAux s 0 @[inline] def String.bsize (s : String) : Nat := utf8ByteSize s @[inline] def String.toSubstring (s : String) : Substring := { str := s startPos := 0 stopPos := s.bsize } @[extern c inline "#3"] unsafe def unsafeCast {α : Type u} {β : Type v} (a : α) : β := cast lcProof (PUnit.{v}) @[neverExtract, extern "lean_panic_fn"] constant panic {α : Type u} [Inhabited α] (msg : String) : α /- The Compiler has special support for arrays. They are implemented using dynamic arrays: https://en.wikipedia.org/wiki/Dynamic_array -/ structure Array (α : Type u) where data : List α attribute [extern "lean_array_data"] Array.data attribute [extern "lean_array_mk"] Array.mk /- The parameter `c` is the initial capacity -/ @[extern "lean_mk_empty_array_with_capacity"] def Array.mkEmpty {α : Type u} (c : @& Nat) : Array α := { data := List.nil } def Array.empty {α : Type u} : Array α := mkEmpty 0 @[reducible, extern "lean_array_get_size"] def Array.size {α : Type u} (a : @& Array α) : Nat := a.data.length @[extern "lean_array_fget"] def Array.get {α : Type u} (a : @& Array α) (i : @& Fin a.size) : α := a.data.get i.val i.isLt @[inline] def Array.getD (a : Array α) (i : Nat) (v₀ : α) : α := dite (LT.lt i a.size) (fun h => a.get ⟨i, h⟩) (fun _ => v₀) /- "Comfortable" version of `fget`. It performs a bound check at runtime. -/ @[extern "lean_array_get"] def Array.get! {α : Type u} [Inhabited α] (a : @& Array α) (i : @& Nat) : α := Array.getD a i arbitrary def Array.getOp {α : Type u} [Inhabited α] (self : Array α) (idx : Nat) : α := self.get! idx @[extern "lean_array_push"] def Array.push {α : Type u} (a : Array α) (v : α) : Array α := { data := List.concat a.data v } @[extern "lean_array_fset"] def Array.set (a : Array α) (i : @& Fin a.size) (v : α) : Array α := { data := a.data.set i.val v } @[inline] def Array.setD (a : Array α) (i : Nat) (v : α) : Array α := dite (LT.lt i a.size) (fun h => a.set ⟨i, h⟩ v) (fun _ => a) @[extern "lean_array_set"] def Array.set! (a : Array α) (i : @& Nat) (v : α) : Array α := Array.setD a i v -- Slower `Array.append` used in quotations. protected def Array.appendCore {α : Type u} (as : Array α) (bs : Array α) : Array α := let rec loop (i : Nat) (j : Nat) (as : Array α) : Array α := dite (LT.lt j bs.size) (fun hlt => match i with | 0 => as | Nat.succ i' => loop i' (hAdd j 1) (as.push (bs.get ⟨j, hlt⟩))) (fun _ => as) loop bs.size 0 as @[inlineIfReduce] def List.toArrayAux : List α → Array α → Array α | nil, r => r | cons a as, r => toArrayAux as (r.push a) @[inlineIfReduce] def List.redLength : List α → Nat | nil => 0 | cons _ as => as.redLength.succ @[inline, matchPattern, export lean_list_to_array] def List.toArray (as : List α) : Array α := as.toArrayAux (Array.mkEmpty as.redLength) class Bind (m : Type u → Type v) where bind : {α β : Type u} → m α → (α → m β) → m β export Bind (bind) class Pure (f : Type u → Type v) where pure {α : Type u} : α → f α export Pure (pure) class Functor (f : Type u → Type v) : Type (max (u+1) v) where map : {α β : Type u} → (α → β) → f α → f β mapConst : {α β : Type u} → α → f β → f α := Function.comp map (Function.const _) class Seq (f : Type u → Type v) : Type (max (u+1) v) where seq : {α β : Type u} → f (α → β) → f α → f β class SeqLeft (f : Type u → Type v) : Type (max (u+1) v) where seqLeft : {α β : Type u} → f α → f β → f α class SeqRight (f : Type u → Type v) : Type (max (u+1) v) where seqRight : {α β : Type u} → f α → f β → f β class Applicative (f : Type u → Type v) extends Functor f, Pure f, Seq f, SeqLeft f, SeqRight f where map := fun x y => Seq.seq (pure x) y seqLeft := fun a b => Seq.seq (Functor.map (Function.const _) a) b seqRight := fun a b => Seq.seq (Functor.map (Function.const _ id) a) b class Monad (m : Type u → Type v) extends Applicative m, Bind m : Type (max (u+1) v) where map f x := bind x (Function.comp pure f) seq f x := bind f fun y => Functor.map y x seqLeft x y := bind x fun a => bind y (fun _ => pure a) seqRight x y := bind x fun _ => y instance {α : Type u} {m : Type u → Type v} [Monad m] : Inhabited (α → m α) where default := pure instance {α : Type u} {m : Type u → Type v} [Monad m] [Inhabited α] : Inhabited (m α) where default := pure arbitrary -- A fusion of Haskell's `sequence` and `map` def Array.sequenceMap {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (as : Array α) (f : α → m β) : m (Array β) := let rec loop (i : Nat) (j : Nat) (bs : Array β) : m (Array β) := dite (LT.lt j as.size) (fun hlt => match i with | 0 => pure bs | Nat.succ i' => Bind.bind (f (as.get ⟨j, hlt⟩)) fun b => loop i' (hAdd j 1) (bs.push b)) (fun _ => bs) loop as.size 0 Array.empty /-- A Function for lifting a computation from an inner Monad to an outer Monad. Like [MonadTrans](https://hackage.haskell.org/package/transformers-0.5.5.0/docs/Control-Monad-Trans-Class.html), but `n` does not have to be a monad transformer. Alternatively, an implementation of [MonadLayer](https://hackage.haskell.org/package/layers-0.1/docs/Control-Monad-Layer.html#t:MonadLayer) without `layerInvmap` (so far). -/ class MonadLift (m : Type u → Type v) (n : Type u → Type w) where monadLift : {α : Type u} → m α → n α /-- The reflexive-transitive closure of `MonadLift`. `monadLift` is used to transitively lift monadic computations such as `StateT.get` or `StateT.put s`. Corresponds to [MonadLift](https://hackage.haskell.org/package/layers-0.1/docs/Control-Monad-Layer.html#t:MonadLift). -/ class MonadLiftT (m : Type u → Type v) (n : Type u → Type w) where monadLift : {α : Type u} → m α → n α export MonadLiftT (monadLift) abbrev liftM := @monadLift instance (m n o) [MonadLift n o] [MonadLiftT m n] : MonadLiftT m o where monadLift x := MonadLift.monadLift (m := n) (monadLift x) instance (m) : MonadLiftT m m where monadLift x := x /-- A functor in the category of monads. Can be used to lift monad-transforming functions. Based on pipes' [MFunctor](https://hackage.haskell.org/package/pipes-2.4.0/docs/Control-MFunctor.html), but not restricted to monad transformers. Alternatively, an implementation of [MonadTransFunctor](http://duairc.netsoc.ie/layers-docs/Control-Monad-Layer.html#t:MonadTransFunctor). -/ class MonadFunctor (m : Type u → Type v) (n : Type u → Type w) where monadMap {α : Type u} : ({β : Type u} → m β → m β) → n α → n α /-- The reflexive-transitive closure of `MonadFunctor`. `monadMap` is used to transitively lift Monad morphisms -/ class MonadFunctorT (m : Type u → Type v) (n : Type u → Type w) where monadMap {α : Type u} : ({β : Type u} → m β → m β) → n α → n α export MonadFunctorT (monadMap) instance (m n o) [MonadFunctor n o] [MonadFunctorT m n] : MonadFunctorT m o where monadMap f := MonadFunctor.monadMap (m := n) (monadMap (m := m) f) instance monadFunctorRefl (m) : MonadFunctorT m m where monadMap f := f inductive Except (ε : Type u) (α : Type v) where | error : ε → Except ε α | ok : α → Except ε α attribute [unbox] Except instance {ε : Type u} {α : Type v} [Inhabited ε] : Inhabited (Except ε α) where default := Except.error arbitrary /-- An implementation of [MonadError](https://hackage.haskell.org/package/mtl-2.2.2/docs/Control-Monad-Except.html#t:MonadError) -/ class MonadExceptOf (ε : Type u) (m : Type v → Type w) where throw {α : Type v} : ε → m α tryCatch {α : Type v} : m α → (ε → m α) → m α abbrev throwThe (ε : Type u) {m : Type v → Type w} [MonadExceptOf ε m] {α : Type v} (e : ε) : m α := MonadExceptOf.throw e abbrev tryCatchThe (ε : Type u) {m : Type v → Type w} [MonadExceptOf ε m] {α : Type v} (x : m α) (handle : ε → m α) : m α := MonadExceptOf.tryCatch x handle /-- Similar to `MonadExceptOf`, but `ε` is an outParam for convenience -/ class MonadExcept (ε : outParam (Type u)) (m : Type v → Type w) where throw {α : Type v} : ε → m α tryCatch {α : Type v} : m α → (ε → m α) → m α export MonadExcept (throw tryCatch) instance (ε : outParam (Type u)) (m : Type v → Type w) [MonadExceptOf ε m] : MonadExcept ε m where throw := throwThe ε tryCatch := tryCatchThe ε namespace MonadExcept variable {ε : Type u} {m : Type v → Type w} @[inline] protected def orelse [MonadExcept ε m] {α : Type v} (t₁ t₂ : m α) : m α := tryCatch t₁ fun _ => t₂ instance [MonadExcept ε m] {α : Type v} : OrElse (m α) where orElse := MonadExcept.orelse end MonadExcept /-- An implementation of [ReaderT](https://hackage.haskell.org/package/transformers-0.5.5.0/docs/Control-Monad-Trans-Reader.html#t:ReaderT) -/ def ReaderT (ρ : Type u) (m : Type u → Type v) (α : Type u) : Type (max u v) := ρ → m α instance (ρ : Type u) (m : Type u → Type v) (α : Type u) [Inhabited (m α)] : Inhabited (ReaderT ρ m α) where default := fun _ => arbitrary @[inline] def ReaderT.run {ρ : Type u} {m : Type u → Type v} {α : Type u} (x : ReaderT ρ m α) (r : ρ) : m α := x r namespace ReaderT section variable {ρ : Type u} {m : Type u → Type v} {α : Type u} instance : MonadLift m (ReaderT ρ m) where monadLift x := fun _ => x instance (ε) [MonadExceptOf ε m] : MonadExceptOf ε (ReaderT ρ m) where throw e := liftM (m := m) (throw e) tryCatch := fun x c r => tryCatchThe ε (x r) (fun e => (c e) r) end section variable {ρ : Type u} {m : Type u → Type v} [Monad m] {α β : Type u} @[inline] protected def read : ReaderT ρ m ρ := pure @[inline] protected def pure (a : α) : ReaderT ρ m α := fun r => pure a @[inline] protected def bind (x : ReaderT ρ m α) (f : α → ReaderT ρ m β) : ReaderT ρ m β := fun r => bind (x r) fun a => f a r @[inline] protected def map (f : α → β) (x : ReaderT ρ m α) : ReaderT ρ m β := fun r => Functor.map f (x r) instance : Monad (ReaderT ρ m) where pure := ReaderT.pure bind := ReaderT.bind map := ReaderT.map instance (ρ m) [Monad m] : MonadFunctor m (ReaderT ρ m) where monadMap f x := fun ctx => f (x ctx) @[inline] protected def adapt {ρ' : Type u} [Monad m] {α : Type u} (f : ρ' → ρ) : ReaderT ρ m α → ReaderT ρ' m α := fun x r => x (f r) end end ReaderT /-- An implementation of [MonadReader](https://hackage.haskell.org/package/mtl-2.2.2/docs/Control-Monad-Reader-Class.html#t:MonadReader). It does not contain `local` because this Function cannot be lifted using `monadLift`. Instead, the `MonadReaderAdapter` class provides the more general `adaptReader` Function. Note: This class can be seen as a simplification of the more "principled" definition ``` class MonadReader (ρ : outParam (Type u)) (n : Type u → Type u) where lift {α : Type u} : ({m : Type u → Type u} → [Monad m] → ReaderT ρ m α) → n α ``` -/ class MonadReaderOf (ρ : Type u) (m : Type u → Type v) where read : m ρ @[inline] def readThe (ρ : Type u) {m : Type u → Type v} [MonadReaderOf ρ m] : m ρ := MonadReaderOf.read /-- Similar to `MonadReaderOf`, but `ρ` is an outParam for convenience -/ class MonadReader (ρ : outParam (Type u)) (m : Type u → Type v) where read : m ρ export MonadReader (read) instance (ρ : Type u) (m : Type u → Type v) [MonadReaderOf ρ m] : MonadReader ρ m where read := readThe ρ instance {ρ : Type u} {m : Type u → Type v} {n : Type u → Type w} [MonadLift m n] [MonadReaderOf ρ m] : MonadReaderOf ρ n where read := liftM (m := m) read instance {ρ : Type u} {m : Type u → Type v} [Monad m] : MonadReaderOf ρ (ReaderT ρ m) where read := ReaderT.read class MonadWithReaderOf (ρ : Type u) (m : Type u → Type v) where withReader {α : Type u} : (ρ → ρ) → m α → m α @[inline] def withTheReader (ρ : Type u) {m : Type u → Type v} [MonadWithReaderOf ρ m] {α : Type u} (f : ρ → ρ) (x : m α) : m α := MonadWithReaderOf.withReader f x class MonadWithReader (ρ : outParam (Type u)) (m : Type u → Type v) where withReader {α : Type u} : (ρ → ρ) → m α → m α export MonadWithReader (withReader) instance (ρ : Type u) (m : Type u → Type v) [MonadWithReaderOf ρ m] : MonadWithReader ρ m where withReader := withTheReader ρ instance {ρ : Type u} {m : Type u → Type v} {n : Type u → Type v} [MonadFunctor m n] [MonadWithReaderOf ρ m] : MonadWithReaderOf ρ n where withReader f := monadMap (m := m) (withTheReader ρ f) instance {ρ : Type u} {m : Type u → Type v} [Monad m] : MonadWithReaderOf ρ (ReaderT ρ m) where withReader f x := fun ctx => x (f ctx) /-- An implementation of [MonadState](https://hackage.haskell.org/package/mtl-2.2.2/docs/Control-Monad-State-Class.html). In contrast to the Haskell implementation, we use overlapping instances to derive instances automatically from `monadLift`. -/ class MonadStateOf (σ : Type u) (m : Type u → Type v) where /- Obtain the top-most State of a Monad stack. -/ get : m σ /- Set the top-most State of a Monad stack. -/ set : σ → m PUnit /- Map the top-most State of a Monad stack. Note: `modifyGet f` may be preferable to `do s <- get; let (a, s) := f s; put s; pure a` because the latter does not use the State linearly (without sufficient inlining). -/ modifyGet {α : Type u} : (σ → Prod α σ) → m α export MonadStateOf (set) abbrev getThe (σ : Type u) {m : Type u → Type v} [MonadStateOf σ m] : m σ := MonadStateOf.get @[inline] abbrev modifyThe (σ : Type u) {m : Type u → Type v} [MonadStateOf σ m] (f : σ → σ) : m PUnit := MonadStateOf.modifyGet fun s => (PUnit.unit, f s) @[inline] abbrev modifyGetThe {α : Type u} (σ : Type u) {m : Type u → Type v} [MonadStateOf σ m] (f : σ → Prod α σ) : m α := MonadStateOf.modifyGet f /-- Similar to `MonadStateOf`, but `σ` is an outParam for convenience -/ class MonadState (σ : outParam (Type u)) (m : Type u → Type v) where get : m σ set : σ → m PUnit modifyGet {α : Type u} : (σ → Prod α σ) → m α export MonadState (get modifyGet) instance (σ : Type u) (m : Type u → Type v) [MonadStateOf σ m] : MonadState σ m where set := MonadStateOf.set get := getThe σ modifyGet f := MonadStateOf.modifyGet f @[inline] def modify {σ : Type u} {m : Type u → Type v} [MonadState σ m] (f : σ → σ) : m PUnit := modifyGet fun s => (PUnit.unit, f s) @[inline] def getModify {σ : Type u} {m : Type u → Type v} [MonadState σ m] [Monad m] (f : σ → σ) : m σ := modifyGet fun s => (s, f s) -- NOTE: The Ordering of the following two instances determines that the top-most `StateT` Monad layer -- will be picked first instance {σ : Type u} {m : Type u → Type v} {n : Type u → Type w} [MonadLift m n] [MonadStateOf σ m] : MonadStateOf σ n where get := liftM (m := m) MonadStateOf.get set s := liftM (m := m) (MonadStateOf.set s) modifyGet f := monadLift (m := m) (MonadState.modifyGet f) namespace EStateM inductive Result (ε σ α : Type u) where | ok : α → σ → Result ε σ α | error : ε → σ → Result ε σ α variable {ε σ α : Type u} instance [Inhabited ε] [Inhabited σ] : Inhabited (Result ε σ α) where default := Result.error arbitrary arbitrary end EStateM open EStateM (Result) in def EStateM (ε σ α : Type u) := σ → Result ε σ α namespace EStateM variable {ε σ α β : Type u} instance [Inhabited ε] : Inhabited (EStateM ε σ α) where default := fun s => Result.error arbitrary s @[inline] protected def pure (a : α) : EStateM ε σ α := fun s => Result.ok a s @[inline] protected def set (s : σ) : EStateM ε σ PUnit := fun _ => Result.ok ⟨⟩ s @[inline] protected def get : EStateM ε σ σ := fun s => Result.ok s s @[inline] protected def modifyGet (f : σ → Prod α σ) : EStateM ε σ α := fun s => match f s with | (a, s) => Result.ok a s @[inline] protected def throw (e : ε) : EStateM ε σ α := fun s => Result.error e s /-- Auxiliary instance for saving/restoring the "backtrackable" part of the state. -/ class Backtrackable (δ : outParam (Type u)) (σ : Type u) where save : σ → δ restore : σ → δ → σ @[inline] protected def tryCatch {δ} [Backtrackable δ σ] {α} (x : EStateM ε σ α) (handle : ε → EStateM ε σ α) : EStateM ε σ α := fun s => let d := Backtrackable.save s match x s with | Result.error e s => handle e (Backtrackable.restore s d) | ok => ok @[inline] protected def orElse {δ} [Backtrackable δ σ] (x₁ x₂ : EStateM ε σ α) : EStateM ε σ α := fun s => let d := Backtrackable.save s; match x₁ s with | Result.error _ s => x₂ (Backtrackable.restore s d) | ok => ok @[inline] def adaptExcept {ε' : Type u} (f : ε → ε') (x : EStateM ε σ α) : EStateM ε' σ α := fun s => match x s with | Result.error e s => Result.error (f e) s | Result.ok a s => Result.ok a s @[inline] protected def bind (x : EStateM ε σ α) (f : α → EStateM ε σ β) : EStateM ε σ β := fun s => match x s with | Result.ok a s => f a s | Result.error e s => Result.error e s @[inline] protected def map (f : α → β) (x : EStateM ε σ α) : EStateM ε σ β := fun s => match x s with | Result.ok a s => Result.ok (f a) s | Result.error e s => Result.error e s @[inline] protected def seqRight (x : EStateM ε σ α) (y : EStateM ε σ β) : EStateM ε σ β := fun s => match x s with | Result.ok _ s => y s | Result.error e s => Result.error e s instance : Monad (EStateM ε σ) where bind := EStateM.bind pure := EStateM.pure map := EStateM.map seqRight := EStateM.seqRight instance {δ} [Backtrackable δ σ] : OrElse (EStateM ε σ α) where orElse := EStateM.orElse instance : MonadStateOf σ (EStateM ε σ) where set := EStateM.set get := EStateM.get modifyGet := EStateM.modifyGet instance {δ} [Backtrackable δ σ] : MonadExceptOf ε (EStateM ε σ) where throw := EStateM.throw tryCatch := EStateM.tryCatch @[inline] def run (x : EStateM ε σ α) (s : σ) : Result ε σ α := x s @[inline] def run' (x : EStateM ε σ α) (s : σ) : Option α := match run x s with | Result.ok v _ => some v | Result.error .. => none @[inline] def dummySave : σ → PUnit := fun _ => ⟨⟩ @[inline] def dummyRestore : σ → PUnit → σ := fun s _ => s /- Dummy default instance -/ instance nonBacktrackable : Backtrackable PUnit σ where save := dummySave restore := dummyRestore end EStateM class Hashable (α : Sort u) where hash : α → UInt64 export Hashable (hash) @[extern c inline "(size_t)#1"] constant UInt64.toUSize (u : UInt64) : USize @[extern c inline "(uint64_t)#1"] constant USize.toUInt64 (u : USize) : UInt64 @[extern "lean_uint64_mix_hash"] constant mixHash (u₁ u₂ : UInt64) : UInt64 @[extern "lean_string_hash"] protected constant String.hash (s : @& String) : UInt64 instance : Hashable String where hash := String.hash namespace Lean /- Hierarchical names -/ inductive Name where | anonymous : Name | str : Name → String → UInt64 → Name | num : Name → Nat → UInt64 → Name instance : Inhabited Name where default := Name.anonymous protected def Name.hash : Name → UInt64 | Name.anonymous => UInt64.ofNatCore 1723 (by decide) | Name.str p s h => h | Name.num p v h => h instance : Hashable Name where hash := Name.hash namespace Name @[export lean_name_mk_string] def mkStr (p : Name) (s : String) : Name := Name.str p s (mixHash (hash p) (hash s)) @[export lean_name_mk_numeral] def mkNum (p : Name) (v : Nat) : Name := Name.num p v (mixHash (hash p) (dite (LT.lt v UInt64.size) (fun h => UInt64.ofNatCore v h) (fun _ => UInt64.ofNatCore 17 (by decide)))) def mkSimple (s : String) : Name := mkStr Name.anonymous s @[extern "lean_name_eq"] protected def beq : (@& Name) → (@& Name) → Bool | anonymous, anonymous => true | str p₁ s₁ _, str p₂ s₂ _ => and (BEq.beq s₁ s₂) (Name.beq p₁ p₂) | num p₁ n₁ _, num p₂ n₂ _ => and (BEq.beq n₁ n₂) (Name.beq p₁ p₂) | _, _ => false instance : BEq Name where beq := Name.beq protected def append : Name → Name → Name | n, anonymous => n | n, str p s _ => Name.mkStr (Name.append n p) s | n, num p d _ => Name.mkNum (Name.append n p) d instance : Append Name where append := Name.append end Name /- Syntax -/ /-- Source information of tokens. -/ inductive SourceInfo where /- Token from original input with whitespace and position information. `leading` will be inferred after parsing by `Syntax.updateLeading`. During parsing, it is not at all clear what the preceding token was, especially with backtracking. -/ | original (leading : Substring) (pos : String.Pos) (trailing : Substring) (endPos : String.Pos) /- Synthesized token (e.g. from a quotation) annotated with a span from the original source. In the delaborator, we "misuse" this constructor to store synthetic positions identifying subterms. -/ | synthetic (pos : String.Pos) (endPos : String.Pos) /- Synthesized token without position information. -/ | protected none instance : Inhabited SourceInfo := ⟨SourceInfo.none⟩ namespace SourceInfo def getPos? (info : SourceInfo) (originalOnly := false) : Option String.Pos := match info, originalOnly with | original (pos := pos) .., _ => some pos | synthetic (pos := pos) .., false => some pos | _, _ => none end SourceInfo abbrev SyntaxNodeKind := Name /- Syntax AST -/ inductive Syntax where | missing : Syntax | node (kind : SyntaxNodeKind) (args : Array Syntax) : Syntax | atom (info : SourceInfo) (val : String) : Syntax | ident (info : SourceInfo) (rawVal : Substring) (val : Name) (preresolved : List (Prod Name (List String))) : Syntax instance : Inhabited Syntax where default := Syntax.missing /- Builtin kinds -/ def choiceKind : SyntaxNodeKind := `choice def nullKind : SyntaxNodeKind := `null def groupKind : SyntaxNodeKind := `group def identKind : SyntaxNodeKind := `ident def strLitKind : SyntaxNodeKind := `strLit def charLitKind : SyntaxNodeKind := `charLit def numLitKind : SyntaxNodeKind := `numLit def scientificLitKind : SyntaxNodeKind := `scientificLit def nameLitKind : SyntaxNodeKind := `nameLit def fieldIdxKind : SyntaxNodeKind := `fieldIdx def interpolatedStrLitKind : SyntaxNodeKind := `interpolatedStrLitKind def interpolatedStrKind : SyntaxNodeKind := `interpolatedStrKind namespace Syntax def getKind (stx : Syntax) : SyntaxNodeKind := match stx with | Syntax.node k args => k -- We use these "pseudo kinds" for antiquotation kinds. -- For example, an antiquotation `$id:ident` (using Lean.Parser.Term.ident) -- is compiled to ``if stx.isOfKind `ident ...`` | Syntax.missing => `missing | Syntax.atom _ v => Name.mkSimple v | Syntax.ident .. => identKind def setKind (stx : Syntax) (k : SyntaxNodeKind) : Syntax := match stx with | Syntax.node _ args => Syntax.node k args | _ => stx def isOfKind (stx : Syntax) (k : SyntaxNodeKind) : Bool := beq stx.getKind k def getArg (stx : Syntax) (i : Nat) : Syntax := match stx with | Syntax.node _ args => args.getD i Syntax.missing | _ => Syntax.missing -- Add `stx[i]` as sugar for `stx.getArg i` @[inline] def getOp (self : Syntax) (idx : Nat) : Syntax := self.getArg idx def getArgs (stx : Syntax) : Array Syntax := match stx with | Syntax.node _ args => args | _ => Array.empty def getNumArgs (stx : Syntax) : Nat := match stx with | Syntax.node _ args => args.size | _ => 0 def isMissing : Syntax → Bool | Syntax.missing => true | _ => false def isNodeOf (stx : Syntax) (k : SyntaxNodeKind) (n : Nat) : Bool := and (stx.isOfKind k) (beq stx.getNumArgs n) def isIdent : Syntax → Bool | ident _ _ _ _ => true | _ => false def getId : Syntax → Name | ident _ _ val _ => val | _ => Name.anonymous def matchesNull (stx : Syntax) (n : Nat) : Bool := isNodeOf stx nullKind n def matchesIdent (stx : Syntax) (id : Name) : Bool := and stx.isIdent (beq stx.getId id) def setArgs (stx : Syntax) (args : Array Syntax) : Syntax := match stx with | node k _ => node k args | stx => stx def setArg (stx : Syntax) (i : Nat) (arg : Syntax) : Syntax := match stx with | node k args => node k (args.setD i arg) | stx => stx /-- Retrieve the left-most leaf's info in the Syntax tree. -/ partial def getHeadInfo? : Syntax → Option SourceInfo | atom info _ => some info | ident info .. => some info | node _ args => let rec loop (i : Nat) : Option SourceInfo := match decide (LT.lt i args.size) with | true => match getHeadInfo? (args.get! i) with | some info => some info | none => loop (hAdd i 1) | false => none loop 0 | _ => none /-- Retrieve the left-most leaf's info in the Syntax tree, or `none` if there is no token. -/ partial def getHeadInfo (stx : Syntax) : SourceInfo := match stx.getHeadInfo? with | some info => info | none => SourceInfo.none def getPos? (stx : Syntax) (originalOnly := false) : Option String.Pos := stx.getHeadInfo.getPos? originalOnly partial def getTailPos? (stx : Syntax) (originalOnly := false) : Option String.Pos := match stx, originalOnly with | atom (SourceInfo.original (endPos := pos) ..) .., _ => some pos | atom (SourceInfo.synthetic (endPos := pos) ..) _, false => some pos | ident (SourceInfo.original (endPos := pos) ..) .., _ => some pos | ident (SourceInfo.synthetic (endPos := pos) ..) .., false => some pos | node _ args, _ => let rec loop (i : Nat) : Option String.Pos := match decide (LT.lt i args.size) with | true => match getTailPos? (args.get! ((args.size.sub i).sub 1)) originalOnly with | some info => some info | none => loop (hAdd i 1) | false => none loop 0 | _, _ => none /-- An array of syntax elements interspersed with separators. Can be coerced to/from `Array Syntax` to automatically remove/insert the separators. -/ structure SepArray (sep : String) where elemsAndSeps : Array Syntax end Syntax def SourceInfo.fromRef (ref : Syntax) : SourceInfo := match ref.getPos?, ref.getTailPos? with | some pos, some tailPos => SourceInfo.synthetic pos tailPos | _, _ => SourceInfo.none def mkAtom (val : String) : Syntax := Syntax.atom SourceInfo.none val def mkAtomFrom (src : Syntax) (val : String) : Syntax := Syntax.atom src.getHeadInfo val /- Parser descriptions -/ inductive ParserDescr where | const (name : Name) | unary (name : Name) (p : ParserDescr) | binary (name : Name) (p₁ p₂ : ParserDescr) | node (kind : SyntaxNodeKind) (prec : Nat) (p : ParserDescr) | trailingNode (kind : SyntaxNodeKind) (prec lhsPrec : Nat) (p : ParserDescr) | symbol (val : String) | nonReservedSymbol (val : String) (includeIdent : Bool) | cat (catName : Name) (rbp : Nat) | parser (declName : Name) | nodeWithAntiquot (name : String) (kind : SyntaxNodeKind) (p : ParserDescr) | sepBy (p : ParserDescr) (sep : String) (psep : ParserDescr) (allowTrailingSep : Bool := false) | sepBy1 (p : ParserDescr) (sep : String) (psep : ParserDescr) (allowTrailingSep : Bool := false) instance : Inhabited ParserDescr where default := ParserDescr.symbol "" abbrev TrailingParserDescr := ParserDescr /- Runtime support for making quotation terms auto-hygienic, by mangling identifiers introduced by them with a "macro scope" supplied by the context. Details to appear in a paper soon. -/ abbrev MacroScope := Nat /-- Macro scope used internally. It is not available for our frontend. -/ def reservedMacroScope := 0 /-- First macro scope available for our frontend -/ def firstFrontendMacroScope := hAdd reservedMacroScope 1 class MonadRef (m : Type → Type) where getRef : m Syntax withRef {α} : Syntax → m α → m α export MonadRef (getRef) instance (m n : Type → Type) [MonadLift m n] [MonadFunctor m n] [MonadRef m] : MonadRef n where getRef := liftM (getRef : m _) withRef ref x := monadMap (m := m) (MonadRef.withRef ref) x def replaceRef (ref : Syntax) (oldRef : Syntax) : Syntax := match ref.getPos? with | some _ => ref | _ => oldRef @[inline] def withRef {m : Type → Type} [Monad m] [MonadRef m] {α} (ref : Syntax) (x : m α) : m α := bind getRef fun oldRef => let ref := replaceRef ref oldRef MonadRef.withRef ref x /-- A monad that supports syntax quotations. Syntax quotations (in term position) are monadic values that when executed retrieve the current "macro scope" from the monad and apply it to every identifier they introduce (independent of whether this identifier turns out to be a reference to an existing declaration, or an actually fresh binding during further elaboration). We also apply the position of the result of `getRef` to each introduced symbol, which results in better error positions than not applying any position. -/ class MonadQuotation (m : Type → Type) extends MonadRef m where -- Get the fresh scope of the current macro invocation getCurrMacroScope : m MacroScope getMainModule : m Name /- Execute action in a new macro invocation context. This transformer should be used at all places that morally qualify as the beginning of a "macro call", e.g. `elabCommand` and `elabTerm` in the case of the elaborator. However, it can also be used internally inside a "macro" if identifiers introduced by e.g. different recursive calls should be independent and not collide. While returning an intermediate syntax tree that will recursively be expanded by the elaborator can be used for the same effect, doing direct recursion inside the macro guarded by this transformer is often easier because one is not restricted to passing a single syntax tree. Modelling this helper as a transformer and not just a monadic action ensures that the current macro scope before the recursive call is restored after it, as expected. -/ withFreshMacroScope {α : Type} : m α → m α export MonadQuotation (getCurrMacroScope getMainModule withFreshMacroScope) def MonadRef.mkInfoFromRefPos [Monad m] [MonadRef m] : m SourceInfo := do SourceInfo.fromRef (← getRef) instance {m n : Type → Type} [MonadFunctor m n] [MonadLift m n] [MonadQuotation m] : MonadQuotation n where getCurrMacroScope := liftM (m := m) getCurrMacroScope getMainModule := liftM (m := m) getMainModule withFreshMacroScope := monadMap (m := m) withFreshMacroScope /- We represent a name with macro scopes as ``` <actual name>._@.(<module_name>.<scopes>)*.<module_name>._hyg.<scopes> ``` Example: suppose the module name is `Init.Data.List.Basic`, and name is `foo.bla`, and macroscopes [2, 5] ``` foo.bla._@.Init.Data.List.Basic._hyg.2.5 ``` We may have to combine scopes from different files/modules. The main modules being processed is always the right most one. This situation may happen when we execute a macro generated in an imported file in the current file. ``` foo.bla._@.Init.Data.List.Basic.2.1.Init.Lean.Expr_hyg.4 ``` The delimiter `_hyg` is used just to improve the `hasMacroScopes` performance. -/ def Name.hasMacroScopes : Name → Bool | str _ s _ => beq s "_hyg" | num p _ _ => hasMacroScopes p | _ => false private def eraseMacroScopesAux : Name → Name | Name.str p s _ => match beq s "_@" with | true => p | false => eraseMacroScopesAux p | Name.num p _ _ => eraseMacroScopesAux p | Name.anonymous => Name.anonymous @[export lean_erase_macro_scopes] def Name.eraseMacroScopes (n : Name) : Name := match n.hasMacroScopes with | true => eraseMacroScopesAux n | false => n private def simpMacroScopesAux : Name → Name | Name.num p i _ => Name.mkNum (simpMacroScopesAux p) i | n => eraseMacroScopesAux n /- Helper function we use to create binder names that do not need to be unique. -/ @[export lean_simp_macro_scopes] def Name.simpMacroScopes (n : Name) : Name := match n.hasMacroScopes with | true => simpMacroScopesAux n | false => n structure MacroScopesView where name : Name imported : Name mainModule : Name scopes : List MacroScope instance : Inhabited MacroScopesView where default := ⟨arbitrary, arbitrary, arbitrary, arbitrary⟩ def MacroScopesView.review (view : MacroScopesView) : Name := match view.scopes with | List.nil => view.name | List.cons _ _ => let base := (Name.mkStr (hAppend (hAppend (Name.mkStr view.name "_@") view.imported) view.mainModule) "_hyg") view.scopes.foldl Name.mkNum base private def assembleParts : List Name → Name → Name | List.nil, acc => acc | List.cons (Name.str _ s _) ps, acc => assembleParts ps (Name.mkStr acc s) | List.cons (Name.num _ n _) ps, acc => assembleParts ps (Name.mkNum acc n) | _, acc => panic "Error: unreachable @ assembleParts" private def extractImported (scps : List MacroScope) (mainModule : Name) : Name → List Name → MacroScopesView | n@(Name.str p str _), parts => match beq str "_@" with | true => { name := p, mainModule := mainModule, imported := assembleParts parts Name.anonymous, scopes := scps } | false => extractImported scps mainModule p (List.cons n parts) | n@(Name.num p str _), parts => extractImported scps mainModule p (List.cons n parts) | _, _ => panic "Error: unreachable @ extractImported" private def extractMainModule (scps : List MacroScope) : Name → List Name → MacroScopesView | n@(Name.str p str _), parts => match beq str "_@" with | true => { name := p, mainModule := assembleParts parts Name.anonymous, imported := Name.anonymous, scopes := scps } | false => extractMainModule scps p (List.cons n parts) | n@(Name.num p num _), acc => extractImported scps (assembleParts acc Name.anonymous) n List.nil | _, _ => panic "Error: unreachable @ extractMainModule" private def extractMacroScopesAux : Name → List MacroScope → MacroScopesView | Name.num p scp _, acc => extractMacroScopesAux p (List.cons scp acc) | Name.str p str _, acc => extractMainModule acc p List.nil -- str must be "_hyg" | _, _ => panic "Error: unreachable @ extractMacroScopesAux" /-- Revert all `addMacroScope` calls. `v = extractMacroScopes n → n = v.review`. This operation is useful for analyzing/transforming the original identifiers, then adding back the scopes (via `MacroScopesView.review`). -/ def extractMacroScopes (n : Name) : MacroScopesView := match n.hasMacroScopes with | true => extractMacroScopesAux n List.nil | false => { name := n, scopes := List.nil, imported := Name.anonymous, mainModule := Name.anonymous } def addMacroScope (mainModule : Name) (n : Name) (scp : MacroScope) : Name := match n.hasMacroScopes with | true => let view := extractMacroScopes n match beq view.mainModule mainModule with | true => Name.mkNum n scp | false => { view with imported := view.scopes.foldl Name.mkNum (hAppend view.imported view.mainModule) mainModule := mainModule scopes := List.cons scp List.nil }.review | false => Name.mkNum (Name.mkStr (hAppend (Name.mkStr n "_@") mainModule) "_hyg") scp @[inline] def MonadQuotation.addMacroScope {m : Type → Type} [MonadQuotation m] [Monad m] (n : Name) : m Name := bind getMainModule fun mainModule => bind getCurrMacroScope fun scp => pure (Lean.addMacroScope mainModule n scp) def defaultMaxRecDepth := 512 def maxRecDepthErrorMessage : String := "maximum recursion depth has been reached (use `set_option maxRecDepth <num>` to increase limit)" namespace Macro /- References -/ private constant MethodsRefPointed : PointedType.{0} private def MethodsRef : Type := MethodsRefPointed.type structure Context where methods : MethodsRef mainModule : Name currMacroScope : MacroScope currRecDepth : Nat := 0 maxRecDepth : Nat := defaultMaxRecDepth ref : Syntax inductive Exception where | error : Syntax → String → Exception | unsupportedSyntax : Exception structure State where macroScope : MacroScope traceMsgs : List (Prod Name String) := List.nil deriving Inhabited end Macro abbrev MacroM := ReaderT Macro.Context (EStateM Macro.Exception Macro.State) abbrev Macro := Syntax → MacroM Syntax namespace Macro instance : MonadRef MacroM where getRef := bind read fun ctx => pure ctx.ref withRef := fun ref x => withReader (fun ctx => { ctx with ref := ref }) x def addMacroScope (n : Name) : MacroM Name := bind read fun ctx => pure (Lean.addMacroScope ctx.mainModule n ctx.currMacroScope) def throwUnsupported {α} : MacroM α := throw Exception.unsupportedSyntax def throwError {α} (msg : String) : MacroM α := bind getRef fun ref => throw (Exception.error ref msg) def throwErrorAt {α} (ref : Syntax) (msg : String) : MacroM α := withRef ref (throwError msg) @[inline] protected def withFreshMacroScope {α} (x : MacroM α) : MacroM α := bind (modifyGet (fun s => (s.macroScope, { s with macroScope := hAdd s.macroScope 1 }))) fun fresh => withReader (fun ctx => { ctx with currMacroScope := fresh }) x @[inline] def withIncRecDepth {α} (ref : Syntax) (x : MacroM α) : MacroM α := bind read fun ctx => match beq ctx.currRecDepth ctx.maxRecDepth with | true => throw (Exception.error ref maxRecDepthErrorMessage) | false => withReader (fun ctx => { ctx with currRecDepth := hAdd ctx.currRecDepth 1 }) x instance : MonadQuotation MacroM where getCurrMacroScope ctx := pure ctx.currMacroScope getMainModule ctx := pure ctx.mainModule withFreshMacroScope := Macro.withFreshMacroScope structure Methods where expandMacro? : Syntax → MacroM (Option Syntax) getCurrNamespace : MacroM Name hasDecl : Name → MacroM Bool resolveNamespace? : Name → MacroM (Option Name) resolveGlobalName : Name → MacroM (List (Prod Name (List String))) deriving Inhabited unsafe def mkMethodsImp (methods : Methods) : MethodsRef := unsafeCast methods @[implementedBy mkMethodsImp] constant mkMethods (methods : Methods) : MethodsRef := MethodsRefPointed.val instance : Inhabited MethodsRef where default := mkMethods arbitrary unsafe def getMethodsImp : MacroM Methods := bind read fun ctx => pure (unsafeCast (ctx.methods)) @[implementedBy getMethodsImp] constant getMethods : MacroM Methods /-- `expandMacro? stx` return `some stxNew` if `stx` is a macro, and `stxNew` is its expansion. -/ def expandMacro? (stx : Syntax) : MacroM (Option Syntax) := do (← getMethods).expandMacro? stx /-- Return `true` if the environment contains a declaration with name `declName` -/ def hasDecl (declName : Name) : MacroM Bool := do (← getMethods).hasDecl declName def getCurrNamespace : MacroM Name := do (← getMethods).getCurrNamespace def resolveNamespace? (n : Name) : MacroM (Option Name) := do (← getMethods).resolveNamespace? n def resolveGlobalName (n : Name) : MacroM (List (Prod Name (List String))) := do (← getMethods).resolveGlobalName n def trace (clsName : Name) (msg : String) : MacroM Unit := do modify fun s => { s with traceMsgs := List.cons (Prod.mk clsName msg) s.traceMsgs } end Macro export Macro (expandMacro?) namespace PrettyPrinter abbrev UnexpandM := EStateM Unit Unit /-- Function that tries to reverse macro expansions as a post-processing step of delaboration. While less general than an arbitrary delaborator, it can be declared without importing `Lean`. Used by the `[appUnexpander]` attribute. -/ -- a `kindUnexpander` could reasonably be added later abbrev Unexpander := Syntax → UnexpandM Syntax -- unexpanders should not need to introduce new names instance : MonadQuotation UnexpandM where getRef := pure Syntax.missing withRef := fun _ => id getCurrMacroScope := pure 0 getMainModule := pure `_fakeMod withFreshMacroScope := id end PrettyPrinter end Lean
4b890a95956afe0f8684036e29ccf0d43a954e48
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/simpperf/pre2500.lean
11a61f9c254cbdc55240db80a80a685c51309336
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach" ]
permissive
leanprover/lean4
4bdf9790294964627eb9be79f5e8f6157780b4cc
f1f9dc0f2f531af3312398999d8b8303fa5f096b
refs/heads/master
1,693,360,665,786
1,693,350,868,000
1,693,350,868,000
129,571,436
2,827
311
Apache-2.0
1,694,716,156,000
1,523,760,560,000
Lean
UTF-8
Lean
false
false
218,030
lean
axiom f (x : Prop) : Prop axiom g0 (x : Prop) : Prop axiom g1 (x : Prop) : Prop axiom g2 (x : Prop) : Prop axiom g3 (x : Prop) : Prop axiom g4 (x : Prop) : Prop axiom g5 (x : Prop) : Prop axiom g6 (x : Prop) : Prop axiom g7 (x : Prop) : Prop axiom g8 (x : Prop) : Prop axiom g9 (x : Prop) : Prop axiom g10 (x : Prop) : Prop axiom g11 (x : Prop) : Prop axiom g12 (x : Prop) : Prop axiom g13 (x : Prop) : Prop axiom g14 (x : Prop) : Prop axiom g15 (x : Prop) : Prop axiom g16 (x : Prop) : Prop axiom g17 (x : Prop) : Prop axiom g18 (x : Prop) : Prop axiom g19 (x : Prop) : Prop axiom g20 (x : Prop) : Prop axiom g21 (x : Prop) : Prop axiom g22 (x : Prop) : Prop axiom g23 (x : Prop) : Prop axiom g24 (x : Prop) : Prop axiom g25 (x : Prop) : Prop axiom g26 (x : Prop) : Prop axiom g27 (x : Prop) : Prop axiom g28 (x : Prop) : Prop axiom g29 (x : Prop) : Prop axiom g30 (x : Prop) : Prop axiom g31 (x : Prop) : Prop axiom g32 (x : Prop) : Prop axiom g33 (x : Prop) : Prop axiom g34 (x : Prop) : Prop axiom g35 (x : Prop) : Prop axiom g36 (x : Prop) : Prop axiom g37 (x : Prop) : Prop axiom g38 (x : Prop) : Prop axiom g39 (x : Prop) : Prop axiom g40 (x : Prop) : Prop axiom g41 (x : Prop) : Prop axiom g42 (x : Prop) : Prop axiom g43 (x : Prop) : Prop axiom g44 (x : Prop) : Prop axiom g45 (x : Prop) : Prop axiom g46 (x : Prop) : Prop axiom g47 (x : Prop) : Prop axiom g48 (x : Prop) : Prop axiom g49 (x : Prop) : Prop axiom g50 (x : Prop) : Prop axiom g51 (x : Prop) : Prop axiom g52 (x : Prop) : Prop axiom g53 (x : Prop) : Prop axiom g54 (x : Prop) : Prop axiom g55 (x : Prop) : Prop axiom g56 (x : Prop) : Prop axiom g57 (x : Prop) : Prop axiom g58 (x : Prop) : Prop axiom g59 (x : Prop) : Prop axiom g60 (x : Prop) : Prop axiom g61 (x : Prop) : Prop axiom g62 (x : Prop) : Prop axiom g63 (x : Prop) : Prop axiom g64 (x : Prop) : Prop axiom g65 (x : Prop) : Prop axiom g66 (x : Prop) : Prop axiom g67 (x : Prop) : Prop axiom g68 (x : Prop) : Prop axiom g69 (x : Prop) : Prop axiom g70 (x : Prop) : Prop axiom g71 (x : Prop) : Prop axiom g72 (x : Prop) : Prop axiom g73 (x : Prop) : Prop axiom g74 (x : Prop) : Prop axiom g75 (x : Prop) : Prop axiom g76 (x : Prop) : Prop axiom g77 (x : Prop) : Prop axiom g78 (x : Prop) : Prop axiom g79 (x : Prop) : Prop axiom g80 (x : Prop) : Prop axiom g81 (x : Prop) : Prop axiom g82 (x : Prop) : Prop axiom g83 (x : Prop) : Prop axiom g84 (x : Prop) : Prop axiom g85 (x : Prop) : Prop axiom g86 (x : Prop) : Prop axiom g87 (x : Prop) : Prop axiom g88 (x : Prop) : Prop axiom g89 (x : Prop) : Prop axiom g90 (x : Prop) : Prop axiom g91 (x : Prop) : Prop axiom g92 (x : Prop) : Prop axiom g93 (x : Prop) : Prop axiom g94 (x : Prop) : Prop axiom g95 (x : Prop) : Prop axiom g96 (x : Prop) : Prop axiom g97 (x : Prop) : Prop axiom g98 (x : Prop) : Prop axiom g99 (x : Prop) : Prop axiom g100 (x : Prop) : Prop axiom g101 (x : Prop) : Prop axiom g102 (x : Prop) : Prop axiom g103 (x : Prop) : Prop axiom g104 (x : Prop) : Prop axiom g105 (x : Prop) : Prop axiom g106 (x : Prop) : Prop axiom g107 (x : Prop) : Prop axiom g108 (x : Prop) : Prop axiom g109 (x : Prop) : Prop axiom g110 (x : Prop) : Prop axiom g111 (x : Prop) : Prop axiom g112 (x : Prop) : Prop axiom g113 (x : Prop) : Prop axiom g114 (x : Prop) : Prop axiom g115 (x : Prop) : Prop axiom g116 (x : Prop) : Prop axiom g117 (x : Prop) : Prop axiom g118 (x : Prop) : Prop axiom g119 (x : Prop) : Prop axiom g120 (x : Prop) : Prop axiom g121 (x : Prop) : Prop axiom g122 (x : Prop) : Prop axiom g123 (x : Prop) : Prop axiom g124 (x : Prop) : Prop axiom g125 (x : Prop) : Prop axiom g126 (x : Prop) : Prop axiom g127 (x : Prop) : Prop axiom g128 (x : Prop) : Prop axiom g129 (x : Prop) : Prop axiom g130 (x : Prop) : Prop axiom g131 (x : Prop) : Prop axiom g132 (x : Prop) : Prop axiom g133 (x : Prop) : Prop axiom g134 (x : Prop) : Prop axiom g135 (x : Prop) : Prop axiom g136 (x : Prop) : Prop axiom g137 (x : Prop) : Prop axiom g138 (x : Prop) : Prop axiom g139 (x : Prop) : Prop axiom g140 (x : Prop) : Prop axiom g141 (x : Prop) : Prop axiom g142 (x : Prop) : Prop axiom g143 (x : Prop) : Prop axiom g144 (x : Prop) : Prop axiom g145 (x : Prop) : Prop axiom g146 (x : Prop) : Prop axiom g147 (x : Prop) : Prop axiom g148 (x : Prop) : Prop axiom g149 (x : Prop) : Prop axiom g150 (x : Prop) : Prop axiom g151 (x : Prop) : Prop axiom g152 (x : Prop) : Prop axiom g153 (x : Prop) : Prop axiom g154 (x : Prop) : Prop axiom g155 (x : Prop) : Prop axiom g156 (x : Prop) : Prop axiom g157 (x : Prop) : Prop axiom g158 (x : Prop) : Prop axiom g159 (x : Prop) : Prop axiom g160 (x : Prop) : Prop axiom g161 (x : Prop) : Prop axiom g162 (x : Prop) : Prop axiom g163 (x : Prop) : Prop axiom g164 (x : Prop) : Prop axiom g165 (x : Prop) : Prop axiom g166 (x : Prop) : Prop axiom g167 (x : Prop) : Prop axiom g168 (x : Prop) : Prop axiom g169 (x : Prop) : Prop axiom g170 (x : Prop) : Prop axiom g171 (x : Prop) : Prop axiom g172 (x : Prop) : Prop axiom g173 (x : Prop) : Prop axiom g174 (x : Prop) : Prop axiom g175 (x : Prop) : Prop axiom g176 (x : Prop) : Prop axiom g177 (x : Prop) : Prop axiom g178 (x : Prop) : Prop axiom g179 (x : Prop) : Prop axiom g180 (x : Prop) : Prop axiom g181 (x : Prop) : Prop axiom g182 (x : Prop) : Prop axiom g183 (x : Prop) : Prop axiom g184 (x : Prop) : Prop axiom g185 (x : Prop) : Prop axiom g186 (x : Prop) : Prop axiom g187 (x : Prop) : Prop axiom g188 (x : Prop) : Prop axiom g189 (x : Prop) : Prop axiom g190 (x : Prop) : Prop axiom g191 (x : Prop) : Prop axiom g192 (x : Prop) : Prop axiom g193 (x : Prop) : Prop axiom g194 (x : Prop) : Prop axiom g195 (x : Prop) : Prop axiom g196 (x : Prop) : Prop axiom g197 (x : Prop) : Prop axiom g198 (x : Prop) : Prop axiom g199 (x : Prop) : Prop axiom g200 (x : Prop) : Prop axiom g201 (x : Prop) : Prop axiom g202 (x : Prop) : Prop axiom g203 (x : Prop) : Prop axiom g204 (x : Prop) : Prop axiom g205 (x : Prop) : Prop axiom g206 (x : Prop) : Prop axiom g207 (x : Prop) : Prop axiom g208 (x : Prop) : Prop axiom g209 (x : Prop) : Prop axiom g210 (x : Prop) : Prop axiom g211 (x : Prop) : Prop axiom g212 (x : Prop) : Prop axiom g213 (x : Prop) : Prop axiom g214 (x : Prop) : Prop axiom g215 (x : Prop) : Prop axiom g216 (x : Prop) : Prop axiom g217 (x : Prop) : Prop axiom g218 (x : Prop) : Prop axiom g219 (x : Prop) : Prop axiom g220 (x : Prop) : Prop axiom g221 (x : Prop) : Prop axiom g222 (x : Prop) : Prop axiom g223 (x : Prop) : Prop axiom g224 (x : Prop) : Prop axiom g225 (x : Prop) : Prop axiom g226 (x : Prop) : Prop axiom g227 (x : Prop) : Prop axiom g228 (x : Prop) : Prop axiom g229 (x : Prop) : Prop axiom g230 (x : Prop) : Prop axiom g231 (x : Prop) : Prop axiom g232 (x : Prop) : Prop axiom g233 (x : Prop) : Prop axiom g234 (x : Prop) : Prop axiom g235 (x : Prop) : Prop axiom g236 (x : Prop) : Prop axiom g237 (x : Prop) : Prop axiom g238 (x : Prop) : Prop axiom g239 (x : Prop) : Prop axiom g240 (x : Prop) : Prop axiom g241 (x : Prop) : Prop axiom g242 (x : Prop) : Prop axiom g243 (x : Prop) : Prop axiom g244 (x : Prop) : Prop axiom g245 (x : Prop) : Prop axiom g246 (x : Prop) : Prop axiom g247 (x : Prop) : Prop axiom g248 (x : Prop) : Prop axiom g249 (x : Prop) : Prop axiom g250 (x : Prop) : Prop axiom g251 (x : Prop) : Prop axiom g252 (x : Prop) : Prop axiom g253 (x : Prop) : Prop axiom g254 (x : Prop) : Prop axiom g255 (x : Prop) : Prop axiom g256 (x : Prop) : Prop axiom g257 (x : Prop) : Prop axiom g258 (x : Prop) : Prop axiom g259 (x : Prop) : Prop axiom g260 (x : Prop) : Prop axiom g261 (x : Prop) : Prop axiom g262 (x : Prop) : Prop axiom g263 (x : Prop) : Prop axiom g264 (x : Prop) : Prop axiom g265 (x : Prop) : Prop axiom g266 (x : Prop) : Prop axiom g267 (x : Prop) : Prop axiom g268 (x : Prop) : Prop axiom g269 (x : Prop) : Prop axiom g270 (x : Prop) : Prop axiom g271 (x : Prop) : Prop axiom g272 (x : Prop) : Prop axiom g273 (x : Prop) : Prop axiom g274 (x : Prop) : Prop axiom g275 (x : Prop) : Prop axiom g276 (x : Prop) : Prop axiom g277 (x : Prop) : Prop axiom g278 (x : Prop) : Prop axiom g279 (x : Prop) : Prop axiom g280 (x : Prop) : Prop axiom g281 (x : Prop) : Prop axiom g282 (x : Prop) : Prop axiom g283 (x : Prop) : Prop axiom g284 (x : Prop) : Prop axiom g285 (x : Prop) : Prop axiom g286 (x : Prop) : Prop axiom g287 (x : Prop) : Prop axiom g288 (x : Prop) : Prop axiom g289 (x : Prop) : Prop axiom g290 (x : Prop) : Prop axiom g291 (x : Prop) : Prop axiom g292 (x : Prop) : Prop axiom g293 (x : Prop) : Prop axiom g294 (x : Prop) : Prop axiom g295 (x : Prop) : Prop axiom g296 (x : Prop) : Prop axiom g297 (x : Prop) : Prop axiom g298 (x : Prop) : Prop axiom g299 (x : Prop) : Prop axiom g300 (x : Prop) : Prop axiom g301 (x : Prop) : Prop axiom g302 (x : Prop) : Prop axiom g303 (x : Prop) : Prop axiom g304 (x : Prop) : Prop axiom g305 (x : Prop) : Prop axiom g306 (x : Prop) : Prop axiom g307 (x : Prop) : Prop axiom g308 (x : Prop) : Prop axiom g309 (x : Prop) : Prop axiom g310 (x : Prop) : Prop axiom g311 (x : Prop) : Prop axiom g312 (x : Prop) : Prop axiom g313 (x : Prop) : Prop axiom g314 (x : Prop) : Prop axiom g315 (x : Prop) : Prop axiom g316 (x : Prop) : Prop axiom g317 (x : Prop) : Prop axiom g318 (x : Prop) : Prop axiom g319 (x : Prop) : Prop axiom g320 (x : Prop) : Prop axiom g321 (x : Prop) : Prop axiom g322 (x : Prop) : Prop axiom g323 (x : Prop) : Prop axiom g324 (x : Prop) : Prop axiom g325 (x : Prop) : Prop axiom g326 (x : Prop) : Prop axiom g327 (x : Prop) : Prop axiom g328 (x : Prop) : Prop axiom g329 (x : Prop) : Prop axiom g330 (x : Prop) : Prop axiom g331 (x : Prop) : Prop axiom g332 (x : Prop) : Prop axiom g333 (x : Prop) : Prop axiom g334 (x : Prop) : Prop axiom g335 (x : Prop) : Prop axiom g336 (x : Prop) : Prop axiom g337 (x : Prop) : Prop axiom g338 (x : Prop) : Prop axiom g339 (x : Prop) : Prop axiom g340 (x : Prop) : Prop axiom g341 (x : Prop) : Prop axiom g342 (x : Prop) : Prop axiom g343 (x : Prop) : Prop axiom g344 (x : Prop) : Prop axiom g345 (x : Prop) : Prop axiom g346 (x : Prop) : Prop axiom g347 (x : Prop) : Prop axiom g348 (x : Prop) : Prop axiom g349 (x : Prop) : Prop axiom g350 (x : Prop) : Prop axiom g351 (x : Prop) : Prop axiom g352 (x : Prop) : Prop axiom g353 (x : Prop) : Prop axiom g354 (x : Prop) : Prop axiom g355 (x : Prop) : Prop axiom g356 (x : Prop) : Prop axiom g357 (x : Prop) : Prop axiom g358 (x : Prop) : Prop axiom g359 (x : Prop) : Prop axiom g360 (x : Prop) : Prop axiom g361 (x : Prop) : Prop axiom g362 (x : Prop) : Prop axiom g363 (x : Prop) : Prop axiom g364 (x : Prop) : Prop axiom g365 (x : Prop) : Prop axiom g366 (x : Prop) : Prop axiom g367 (x : Prop) : Prop axiom g368 (x : Prop) : Prop axiom g369 (x : Prop) : Prop axiom g370 (x : Prop) : Prop axiom g371 (x : Prop) : Prop axiom g372 (x : Prop) : Prop axiom g373 (x : Prop) : Prop axiom g374 (x : Prop) : Prop axiom g375 (x : Prop) : Prop axiom g376 (x : Prop) : Prop axiom g377 (x : Prop) : Prop axiom g378 (x : Prop) : Prop axiom g379 (x : Prop) : Prop axiom g380 (x : Prop) : Prop axiom g381 (x : Prop) : Prop axiom g382 (x : Prop) : Prop axiom g383 (x : Prop) : Prop axiom g384 (x : Prop) : Prop axiom g385 (x : Prop) : Prop axiom g386 (x : Prop) : Prop axiom g387 (x : Prop) : Prop axiom g388 (x : Prop) : Prop axiom g389 (x : Prop) : Prop axiom g390 (x : Prop) : Prop axiom g391 (x : Prop) : Prop axiom g392 (x : Prop) : Prop axiom g393 (x : Prop) : Prop axiom g394 (x : Prop) : Prop axiom g395 (x : Prop) : Prop axiom g396 (x : Prop) : Prop axiom g397 (x : Prop) : Prop axiom g398 (x : Prop) : Prop axiom g399 (x : Prop) : Prop axiom g400 (x : Prop) : Prop axiom g401 (x : Prop) : Prop axiom g402 (x : Prop) : Prop axiom g403 (x : Prop) : Prop axiom g404 (x : Prop) : Prop axiom g405 (x : Prop) : Prop axiom g406 (x : Prop) : Prop axiom g407 (x : Prop) : Prop axiom g408 (x : Prop) : Prop axiom g409 (x : Prop) : Prop axiom g410 (x : Prop) : Prop axiom g411 (x : Prop) : Prop axiom g412 (x : Prop) : Prop axiom g413 (x : Prop) : Prop axiom g414 (x : Prop) : Prop axiom g415 (x : Prop) : Prop axiom g416 (x : Prop) : Prop axiom g417 (x : Prop) : Prop axiom g418 (x : Prop) : Prop axiom g419 (x : Prop) : Prop axiom g420 (x : Prop) : Prop axiom g421 (x : Prop) : Prop axiom g422 (x : Prop) : Prop axiom g423 (x : Prop) : Prop axiom g424 (x : Prop) : Prop axiom g425 (x : Prop) : Prop axiom g426 (x : Prop) : Prop axiom g427 (x : Prop) : Prop axiom g428 (x : Prop) : Prop axiom g429 (x : Prop) : Prop axiom g430 (x : Prop) : Prop axiom g431 (x : Prop) : Prop axiom g432 (x : Prop) : Prop axiom g433 (x : Prop) : Prop axiom g434 (x : Prop) : Prop axiom g435 (x : Prop) : Prop axiom g436 (x : Prop) : Prop axiom g437 (x : Prop) : Prop axiom g438 (x : Prop) : Prop axiom g439 (x : Prop) : Prop axiom g440 (x : Prop) : Prop axiom g441 (x : Prop) : Prop axiom g442 (x : Prop) : Prop axiom g443 (x : Prop) : Prop axiom g444 (x : Prop) : Prop axiom g445 (x : Prop) : Prop axiom g446 (x : Prop) : Prop axiom g447 (x : Prop) : Prop axiom g448 (x : Prop) : Prop axiom g449 (x : Prop) : Prop axiom g450 (x : Prop) : Prop axiom g451 (x : Prop) : Prop axiom g452 (x : Prop) : Prop axiom g453 (x : Prop) : Prop axiom g454 (x : Prop) : Prop axiom g455 (x : Prop) : Prop axiom g456 (x : Prop) : Prop axiom g457 (x : Prop) : Prop axiom g458 (x : Prop) : Prop axiom g459 (x : Prop) : Prop axiom g460 (x : Prop) : Prop axiom g461 (x : Prop) : Prop axiom g462 (x : Prop) : Prop axiom g463 (x : Prop) : Prop axiom g464 (x : Prop) : Prop axiom g465 (x : Prop) : Prop axiom g466 (x : Prop) : Prop axiom g467 (x : Prop) : Prop axiom g468 (x : Prop) : Prop axiom g469 (x : Prop) : Prop axiom g470 (x : Prop) : Prop axiom g471 (x : Prop) : Prop axiom g472 (x : Prop) : Prop axiom g473 (x : Prop) : Prop axiom g474 (x : Prop) : Prop axiom g475 (x : Prop) : Prop axiom g476 (x : Prop) : Prop axiom g477 (x : Prop) : Prop axiom g478 (x : Prop) : Prop axiom g479 (x : Prop) : Prop axiom g480 (x : Prop) : Prop axiom g481 (x : Prop) : Prop axiom g482 (x : Prop) : Prop axiom g483 (x : Prop) : Prop axiom g484 (x : Prop) : Prop axiom g485 (x : Prop) : Prop axiom g486 (x : Prop) : Prop axiom g487 (x : Prop) : Prop axiom g488 (x : Prop) : Prop axiom g489 (x : Prop) : Prop axiom g490 (x : Prop) : Prop axiom g491 (x : Prop) : Prop axiom g492 (x : Prop) : Prop axiom g493 (x : Prop) : Prop axiom g494 (x : Prop) : Prop axiom g495 (x : Prop) : Prop axiom g496 (x : Prop) : Prop axiom g497 (x : Prop) : Prop axiom g498 (x : Prop) : Prop axiom g499 (x : Prop) : Prop axiom g500 (x : Prop) : Prop axiom g501 (x : Prop) : Prop axiom g502 (x : Prop) : Prop axiom g503 (x : Prop) : Prop axiom g504 (x : Prop) : Prop axiom g505 (x : Prop) : Prop axiom g506 (x : Prop) : Prop axiom g507 (x : Prop) : Prop axiom g508 (x : Prop) : Prop axiom g509 (x : Prop) : Prop axiom g510 (x : Prop) : Prop axiom g511 (x : Prop) : Prop axiom g512 (x : Prop) : Prop axiom g513 (x : Prop) : Prop axiom g514 (x : Prop) : Prop axiom g515 (x : Prop) : Prop axiom g516 (x : Prop) : Prop axiom g517 (x : Prop) : Prop axiom g518 (x : Prop) : Prop axiom g519 (x : Prop) : Prop axiom g520 (x : Prop) : Prop axiom g521 (x : Prop) : Prop axiom g522 (x : Prop) : Prop axiom g523 (x : Prop) : Prop axiom g524 (x : Prop) : Prop axiom g525 (x : Prop) : Prop axiom g526 (x : Prop) : Prop axiom g527 (x : Prop) : Prop axiom g528 (x : Prop) : Prop axiom g529 (x : Prop) : Prop axiom g530 (x : Prop) : Prop axiom g531 (x : Prop) : Prop axiom g532 (x : Prop) : Prop axiom g533 (x : Prop) : Prop axiom g534 (x : Prop) : Prop axiom g535 (x : Prop) : Prop axiom g536 (x : Prop) : Prop axiom g537 (x : Prop) : Prop axiom g538 (x : Prop) : Prop axiom g539 (x : Prop) : Prop axiom g540 (x : Prop) : Prop axiom g541 (x : Prop) : Prop axiom g542 (x : Prop) : Prop axiom g543 (x : Prop) : Prop axiom g544 (x : Prop) : Prop axiom g545 (x : Prop) : Prop axiom g546 (x : Prop) : Prop axiom g547 (x : Prop) : Prop axiom g548 (x : Prop) : Prop axiom g549 (x : Prop) : Prop axiom g550 (x : Prop) : Prop axiom g551 (x : Prop) : Prop axiom g552 (x : Prop) : Prop axiom g553 (x : Prop) : Prop axiom g554 (x : Prop) : Prop axiom g555 (x : Prop) : Prop axiom g556 (x : Prop) : Prop axiom g557 (x : Prop) : Prop axiom g558 (x : Prop) : Prop axiom g559 (x : Prop) : Prop axiom g560 (x : Prop) : Prop axiom g561 (x : Prop) : Prop axiom g562 (x : Prop) : Prop axiom g563 (x : Prop) : Prop axiom g564 (x : Prop) : Prop axiom g565 (x : Prop) : Prop axiom g566 (x : Prop) : Prop axiom g567 (x : Prop) : Prop axiom g568 (x : Prop) : Prop axiom g569 (x : Prop) : Prop axiom g570 (x : Prop) : Prop axiom g571 (x : Prop) : Prop axiom g572 (x : Prop) : Prop axiom g573 (x : Prop) : Prop axiom g574 (x : Prop) : Prop axiom g575 (x : Prop) : Prop axiom g576 (x : Prop) : Prop axiom g577 (x : Prop) : Prop axiom g578 (x : Prop) : Prop axiom g579 (x : Prop) : Prop axiom g580 (x : Prop) : Prop axiom g581 (x : Prop) : Prop axiom g582 (x : Prop) : Prop axiom g583 (x : Prop) : Prop axiom g584 (x : Prop) : Prop axiom g585 (x : Prop) : Prop axiom g586 (x : Prop) : Prop axiom g587 (x : Prop) : Prop axiom g588 (x : Prop) : Prop axiom g589 (x : Prop) : Prop axiom g590 (x : Prop) : Prop axiom g591 (x : Prop) : Prop axiom g592 (x : Prop) : Prop axiom g593 (x : Prop) : Prop axiom g594 (x : Prop) : Prop axiom g595 (x : Prop) : Prop axiom g596 (x : Prop) : Prop axiom g597 (x : Prop) : Prop axiom g598 (x : Prop) : Prop axiom g599 (x : Prop) : Prop axiom g600 (x : Prop) : Prop axiom g601 (x : Prop) : Prop axiom g602 (x : Prop) : Prop axiom g603 (x : Prop) : Prop axiom g604 (x : Prop) : Prop axiom g605 (x : Prop) : Prop axiom g606 (x : Prop) : Prop axiom g607 (x : Prop) : Prop axiom g608 (x : Prop) : Prop axiom g609 (x : Prop) : Prop axiom g610 (x : Prop) : Prop axiom g611 (x : Prop) : Prop axiom g612 (x : Prop) : Prop axiom g613 (x : Prop) : Prop axiom g614 (x : Prop) : Prop axiom g615 (x : Prop) : Prop axiom g616 (x : Prop) : Prop axiom g617 (x : Prop) : Prop axiom g618 (x : Prop) : Prop axiom g619 (x : Prop) : Prop axiom g620 (x : Prop) : Prop axiom g621 (x : Prop) : Prop axiom g622 (x : Prop) : Prop axiom g623 (x : Prop) : Prop axiom g624 (x : Prop) : Prop axiom g625 (x : Prop) : Prop axiom g626 (x : Prop) : Prop axiom g627 (x : Prop) : Prop axiom g628 (x : Prop) : Prop axiom g629 (x : Prop) : Prop axiom g630 (x : Prop) : Prop axiom g631 (x : Prop) : Prop axiom g632 (x : Prop) : Prop axiom g633 (x : Prop) : Prop axiom g634 (x : Prop) : Prop axiom g635 (x : Prop) : Prop axiom g636 (x : Prop) : Prop axiom g637 (x : Prop) : Prop axiom g638 (x : Prop) : Prop axiom g639 (x : Prop) : Prop axiom g640 (x : Prop) : Prop axiom g641 (x : Prop) : Prop axiom g642 (x : Prop) : Prop axiom g643 (x : Prop) : Prop axiom g644 (x : Prop) : Prop axiom g645 (x : Prop) : Prop axiom g646 (x : Prop) : Prop axiom g647 (x : Prop) : Prop axiom g648 (x : Prop) : Prop axiom g649 (x : Prop) : Prop axiom g650 (x : Prop) : Prop axiom g651 (x : Prop) : Prop axiom g652 (x : Prop) : Prop axiom g653 (x : Prop) : Prop axiom g654 (x : Prop) : Prop axiom g655 (x : Prop) : Prop axiom g656 (x : Prop) : Prop axiom g657 (x : Prop) : Prop axiom g658 (x : Prop) : Prop axiom g659 (x : Prop) : Prop axiom g660 (x : Prop) : Prop axiom g661 (x : Prop) : Prop axiom g662 (x : Prop) : Prop axiom g663 (x : Prop) : Prop axiom g664 (x : Prop) : Prop axiom g665 (x : Prop) : Prop axiom g666 (x : Prop) : Prop axiom g667 (x : Prop) : Prop axiom g668 (x : Prop) : Prop axiom g669 (x : Prop) : Prop axiom g670 (x : Prop) : Prop axiom g671 (x : Prop) : Prop axiom g672 (x : Prop) : Prop axiom g673 (x : Prop) : Prop axiom g674 (x : Prop) : Prop axiom g675 (x : Prop) : Prop axiom g676 (x : Prop) : Prop axiom g677 (x : Prop) : Prop axiom g678 (x : Prop) : Prop axiom g679 (x : Prop) : Prop axiom g680 (x : Prop) : Prop axiom g681 (x : Prop) : Prop axiom g682 (x : Prop) : Prop axiom g683 (x : Prop) : Prop axiom g684 (x : Prop) : Prop axiom g685 (x : Prop) : Prop axiom g686 (x : Prop) : Prop axiom g687 (x : Prop) : Prop axiom g688 (x : Prop) : Prop axiom g689 (x : Prop) : Prop axiom g690 (x : Prop) : Prop axiom g691 (x : Prop) : Prop axiom g692 (x : Prop) : Prop axiom g693 (x : Prop) : Prop axiom g694 (x : Prop) : Prop axiom g695 (x : Prop) : Prop axiom g696 (x : Prop) : Prop axiom g697 (x : Prop) : Prop axiom g698 (x : Prop) : Prop axiom g699 (x : Prop) : Prop axiom g700 (x : Prop) : Prop axiom g701 (x : Prop) : Prop axiom g702 (x : Prop) : Prop axiom g703 (x : Prop) : Prop axiom g704 (x : Prop) : Prop axiom g705 (x : Prop) : Prop axiom g706 (x : Prop) : Prop axiom g707 (x : Prop) : Prop axiom g708 (x : Prop) : Prop axiom g709 (x : Prop) : Prop axiom g710 (x : Prop) : Prop axiom g711 (x : Prop) : Prop axiom g712 (x : Prop) : Prop axiom g713 (x : Prop) : Prop axiom g714 (x : Prop) : Prop axiom g715 (x : Prop) : Prop axiom g716 (x : Prop) : Prop axiom g717 (x : Prop) : Prop axiom g718 (x : Prop) : Prop axiom g719 (x : Prop) : Prop axiom g720 (x : Prop) : Prop axiom g721 (x : Prop) : Prop axiom g722 (x : Prop) : Prop axiom g723 (x : Prop) : Prop axiom g724 (x : Prop) : Prop axiom g725 (x : Prop) : Prop axiom g726 (x : Prop) : Prop axiom g727 (x : Prop) : Prop axiom g728 (x : Prop) : Prop axiom g729 (x : Prop) : Prop axiom g730 (x : Prop) : Prop axiom g731 (x : Prop) : Prop axiom g732 (x : Prop) : Prop axiom g733 (x : Prop) : Prop axiom g734 (x : Prop) : Prop axiom g735 (x : Prop) : Prop axiom g736 (x : Prop) : Prop axiom g737 (x : Prop) : Prop axiom g738 (x : Prop) : Prop axiom g739 (x : Prop) : Prop axiom g740 (x : Prop) : Prop axiom g741 (x : Prop) : Prop axiom g742 (x : Prop) : Prop axiom g743 (x : Prop) : Prop axiom g744 (x : Prop) : Prop axiom g745 (x : Prop) : Prop axiom g746 (x : Prop) : Prop axiom g747 (x : Prop) : Prop axiom g748 (x : Prop) : Prop axiom g749 (x : Prop) : Prop axiom g750 (x : Prop) : Prop axiom g751 (x : Prop) : Prop axiom g752 (x : Prop) : Prop axiom g753 (x : Prop) : Prop axiom g754 (x : Prop) : Prop axiom g755 (x : Prop) : Prop axiom g756 (x : Prop) : Prop axiom g757 (x : Prop) : Prop axiom g758 (x : Prop) : Prop axiom g759 (x : Prop) : Prop axiom g760 (x : Prop) : Prop axiom g761 (x : Prop) : Prop axiom g762 (x : Prop) : Prop axiom g763 (x : Prop) : Prop axiom g764 (x : Prop) : Prop axiom g765 (x : Prop) : Prop axiom g766 (x : Prop) : Prop axiom g767 (x : Prop) : Prop axiom g768 (x : Prop) : Prop axiom g769 (x : Prop) : Prop axiom g770 (x : Prop) : Prop axiom g771 (x : Prop) : Prop axiom g772 (x : Prop) : Prop axiom g773 (x : Prop) : Prop axiom g774 (x : Prop) : Prop axiom g775 (x : Prop) : Prop axiom g776 (x : Prop) : Prop axiom g777 (x : Prop) : Prop axiom g778 (x : Prop) : Prop axiom g779 (x : Prop) : Prop axiom g780 (x : Prop) : Prop axiom g781 (x : Prop) : Prop axiom g782 (x : Prop) : Prop axiom g783 (x : Prop) : Prop axiom g784 (x : Prop) : Prop axiom g785 (x : Prop) : Prop axiom g786 (x : Prop) : Prop axiom g787 (x : Prop) : Prop axiom g788 (x : Prop) : Prop axiom g789 (x : Prop) : Prop axiom g790 (x : Prop) : Prop axiom g791 (x : Prop) : Prop axiom g792 (x : Prop) : Prop axiom g793 (x : Prop) : Prop axiom g794 (x : Prop) : Prop axiom g795 (x : Prop) : Prop axiom g796 (x : Prop) : Prop axiom g797 (x : Prop) : Prop axiom g798 (x : Prop) : Prop axiom g799 (x : Prop) : Prop axiom g800 (x : Prop) : Prop axiom g801 (x : Prop) : Prop axiom g802 (x : Prop) : Prop axiom g803 (x : Prop) : Prop axiom g804 (x : Prop) : Prop axiom g805 (x : Prop) : Prop axiom g806 (x : Prop) : Prop axiom g807 (x : Prop) : Prop axiom g808 (x : Prop) : Prop axiom g809 (x : Prop) : Prop axiom g810 (x : Prop) : Prop axiom g811 (x : Prop) : Prop axiom g812 (x : Prop) : Prop axiom g813 (x : Prop) : Prop axiom g814 (x : Prop) : Prop axiom g815 (x : Prop) : Prop axiom g816 (x : Prop) : Prop axiom g817 (x : Prop) : Prop axiom g818 (x : Prop) : Prop axiom g819 (x : Prop) : Prop axiom g820 (x : Prop) : Prop axiom g821 (x : Prop) : Prop axiom g822 (x : Prop) : Prop axiom g823 (x : Prop) : Prop axiom g824 (x : Prop) : Prop axiom g825 (x : Prop) : Prop axiom g826 (x : Prop) : Prop axiom g827 (x : Prop) : Prop axiom g828 (x : Prop) : Prop axiom g829 (x : Prop) : Prop axiom g830 (x : Prop) : Prop axiom g831 (x : Prop) : Prop axiom g832 (x : Prop) : Prop axiom g833 (x : Prop) : Prop axiom g834 (x : Prop) : Prop axiom g835 (x : Prop) : Prop axiom g836 (x : Prop) : Prop axiom g837 (x : Prop) : Prop axiom g838 (x : Prop) : Prop axiom g839 (x : Prop) : Prop axiom g840 (x : Prop) : Prop axiom g841 (x : Prop) : Prop axiom g842 (x : Prop) : Prop axiom g843 (x : Prop) : Prop axiom g844 (x : Prop) : Prop axiom g845 (x : Prop) : Prop axiom g846 (x : Prop) : Prop axiom g847 (x : Prop) : Prop axiom g848 (x : Prop) : Prop axiom g849 (x : Prop) : Prop axiom g850 (x : Prop) : Prop axiom g851 (x : Prop) : Prop axiom g852 (x : Prop) : Prop axiom g853 (x : Prop) : Prop axiom g854 (x : Prop) : Prop axiom g855 (x : Prop) : Prop axiom g856 (x : Prop) : Prop axiom g857 (x : Prop) : Prop axiom g858 (x : Prop) : Prop axiom g859 (x : Prop) : Prop axiom g860 (x : Prop) : Prop axiom g861 (x : Prop) : Prop axiom g862 (x : Prop) : Prop axiom g863 (x : Prop) : Prop axiom g864 (x : Prop) : Prop axiom g865 (x : Prop) : Prop axiom g866 (x : Prop) : Prop axiom g867 (x : Prop) : Prop axiom g868 (x : Prop) : Prop axiom g869 (x : Prop) : Prop axiom g870 (x : Prop) : Prop axiom g871 (x : Prop) : Prop axiom g872 (x : Prop) : Prop axiom g873 (x : Prop) : Prop axiom g874 (x : Prop) : Prop axiom g875 (x : Prop) : Prop axiom g876 (x : Prop) : Prop axiom g877 (x : Prop) : Prop axiom g878 (x : Prop) : Prop axiom g879 (x : Prop) : Prop axiom g880 (x : Prop) : Prop axiom g881 (x : Prop) : Prop axiom g882 (x : Prop) : Prop axiom g883 (x : Prop) : Prop axiom g884 (x : Prop) : Prop axiom g885 (x : Prop) : Prop axiom g886 (x : Prop) : Prop axiom g887 (x : Prop) : Prop axiom g888 (x : Prop) : Prop axiom g889 (x : Prop) : Prop axiom g890 (x : Prop) : Prop axiom g891 (x : Prop) : Prop axiom g892 (x : Prop) : Prop axiom g893 (x : Prop) : Prop axiom g894 (x : Prop) : Prop axiom g895 (x : Prop) : Prop axiom g896 (x : Prop) : Prop axiom g897 (x : Prop) : Prop axiom g898 (x : Prop) : Prop axiom g899 (x : Prop) : Prop axiom g900 (x : Prop) : Prop axiom g901 (x : Prop) : Prop axiom g902 (x : Prop) : Prop axiom g903 (x : Prop) : Prop axiom g904 (x : Prop) : Prop axiom g905 (x : Prop) : Prop axiom g906 (x : Prop) : Prop axiom g907 (x : Prop) : Prop axiom g908 (x : Prop) : Prop axiom g909 (x : Prop) : Prop axiom g910 (x : Prop) : Prop axiom g911 (x : Prop) : Prop axiom g912 (x : Prop) : Prop axiom g913 (x : Prop) : Prop axiom g914 (x : Prop) : Prop axiom g915 (x : Prop) : Prop axiom g916 (x : Prop) : Prop axiom g917 (x : Prop) : Prop axiom g918 (x : Prop) : Prop axiom g919 (x : Prop) : Prop axiom g920 (x : Prop) : Prop axiom g921 (x : Prop) : Prop axiom g922 (x : Prop) : Prop axiom g923 (x : Prop) : Prop axiom g924 (x : Prop) : Prop axiom g925 (x : Prop) : Prop axiom g926 (x : Prop) : Prop axiom g927 (x : Prop) : Prop axiom g928 (x : Prop) : Prop axiom g929 (x : Prop) : Prop axiom g930 (x : Prop) : Prop axiom g931 (x : Prop) : Prop axiom g932 (x : Prop) : Prop axiom g933 (x : Prop) : Prop axiom g934 (x : Prop) : Prop axiom g935 (x : Prop) : Prop axiom g936 (x : Prop) : Prop axiom g937 (x : Prop) : Prop axiom g938 (x : Prop) : Prop axiom g939 (x : Prop) : Prop axiom g940 (x : Prop) : Prop axiom g941 (x : Prop) : Prop axiom g942 (x : Prop) : Prop axiom g943 (x : Prop) : Prop axiom g944 (x : Prop) : Prop axiom g945 (x : Prop) : Prop axiom g946 (x : Prop) : Prop axiom g947 (x : Prop) : Prop axiom g948 (x : Prop) : Prop axiom g949 (x : Prop) : Prop axiom g950 (x : Prop) : Prop axiom g951 (x : Prop) : Prop axiom g952 (x : Prop) : Prop axiom g953 (x : Prop) : Prop axiom g954 (x : Prop) : Prop axiom g955 (x : Prop) : Prop axiom g956 (x : Prop) : Prop axiom g957 (x : Prop) : Prop axiom g958 (x : Prop) : Prop axiom g959 (x : Prop) : Prop axiom g960 (x : Prop) : Prop axiom g961 (x : Prop) : Prop axiom g962 (x : Prop) : Prop axiom g963 (x : Prop) : Prop axiom g964 (x : Prop) : Prop axiom g965 (x : Prop) : Prop axiom g966 (x : Prop) : Prop axiom g967 (x : Prop) : Prop axiom g968 (x : Prop) : Prop axiom g969 (x : Prop) : Prop axiom g970 (x : Prop) : Prop axiom g971 (x : Prop) : Prop axiom g972 (x : Prop) : Prop axiom g973 (x : Prop) : Prop axiom g974 (x : Prop) : Prop axiom g975 (x : Prop) : Prop axiom g976 (x : Prop) : Prop axiom g977 (x : Prop) : Prop axiom g978 (x : Prop) : Prop axiom g979 (x : Prop) : Prop axiom g980 (x : Prop) : Prop axiom g981 (x : Prop) : Prop axiom g982 (x : Prop) : Prop axiom g983 (x : Prop) : Prop axiom g984 (x : Prop) : Prop axiom g985 (x : Prop) : Prop axiom g986 (x : Prop) : Prop axiom g987 (x : Prop) : Prop axiom g988 (x : Prop) : Prop axiom g989 (x : Prop) : Prop axiom g990 (x : Prop) : Prop axiom g991 (x : Prop) : Prop axiom g992 (x : Prop) : Prop axiom g993 (x : Prop) : Prop axiom g994 (x : Prop) : Prop axiom g995 (x : Prop) : Prop axiom g996 (x : Prop) : Prop axiom g997 (x : Prop) : Prop axiom g998 (x : Prop) : Prop axiom g999 (x : Prop) : Prop axiom g1000 (x : Prop) : Prop axiom g1001 (x : Prop) : Prop axiom g1002 (x : Prop) : Prop axiom g1003 (x : Prop) : Prop axiom g1004 (x : Prop) : Prop axiom g1005 (x : Prop) : Prop axiom g1006 (x : Prop) : Prop axiom g1007 (x : Prop) : Prop axiom g1008 (x : Prop) : Prop axiom g1009 (x : Prop) : Prop axiom g1010 (x : Prop) : Prop axiom g1011 (x : Prop) : Prop axiom g1012 (x : Prop) : Prop axiom g1013 (x : Prop) : Prop axiom g1014 (x : Prop) : Prop axiom g1015 (x : Prop) : Prop axiom g1016 (x : Prop) : Prop axiom g1017 (x : Prop) : Prop axiom g1018 (x : Prop) : Prop axiom g1019 (x : Prop) : Prop axiom g1020 (x : Prop) : Prop axiom g1021 (x : Prop) : Prop axiom g1022 (x : Prop) : Prop axiom g1023 (x : Prop) : Prop axiom g1024 (x : Prop) : Prop axiom g1025 (x : Prop) : Prop axiom g1026 (x : Prop) : Prop axiom g1027 (x : Prop) : Prop axiom g1028 (x : Prop) : Prop axiom g1029 (x : Prop) : Prop axiom g1030 (x : Prop) : Prop axiom g1031 (x : Prop) : Prop axiom g1032 (x : Prop) : Prop axiom g1033 (x : Prop) : Prop axiom g1034 (x : Prop) : Prop axiom g1035 (x : Prop) : Prop axiom g1036 (x : Prop) : Prop axiom g1037 (x : Prop) : Prop axiom g1038 (x : Prop) : Prop axiom g1039 (x : Prop) : Prop axiom g1040 (x : Prop) : Prop axiom g1041 (x : Prop) : Prop axiom g1042 (x : Prop) : Prop axiom g1043 (x : Prop) : Prop axiom g1044 (x : Prop) : Prop axiom g1045 (x : Prop) : Prop axiom g1046 (x : Prop) : Prop axiom g1047 (x : Prop) : Prop axiom g1048 (x : Prop) : Prop axiom g1049 (x : Prop) : Prop axiom g1050 (x : Prop) : Prop axiom g1051 (x : Prop) : Prop axiom g1052 (x : Prop) : Prop axiom g1053 (x : Prop) : Prop axiom g1054 (x : Prop) : Prop axiom g1055 (x : Prop) : Prop axiom g1056 (x : Prop) : Prop axiom g1057 (x : Prop) : Prop axiom g1058 (x : Prop) : Prop axiom g1059 (x : Prop) : Prop axiom g1060 (x : Prop) : Prop axiom g1061 (x : Prop) : Prop axiom g1062 (x : Prop) : Prop axiom g1063 (x : Prop) : Prop axiom g1064 (x : Prop) : Prop axiom g1065 (x : Prop) : Prop axiom g1066 (x : Prop) : Prop axiom g1067 (x : Prop) : Prop axiom g1068 (x : Prop) : Prop axiom g1069 (x : Prop) : Prop axiom g1070 (x : Prop) : Prop axiom g1071 (x : Prop) : Prop axiom g1072 (x : Prop) : Prop axiom g1073 (x : Prop) : Prop axiom g1074 (x : Prop) : Prop axiom g1075 (x : Prop) : Prop axiom g1076 (x : Prop) : Prop axiom g1077 (x : Prop) : Prop axiom g1078 (x : Prop) : Prop axiom g1079 (x : Prop) : Prop axiom g1080 (x : Prop) : Prop axiom g1081 (x : Prop) : Prop axiom g1082 (x : Prop) : Prop axiom g1083 (x : Prop) : Prop axiom g1084 (x : Prop) : Prop axiom g1085 (x : Prop) : Prop axiom g1086 (x : Prop) : Prop axiom g1087 (x : Prop) : Prop axiom g1088 (x : Prop) : Prop axiom g1089 (x : Prop) : Prop axiom g1090 (x : Prop) : Prop axiom g1091 (x : Prop) : Prop axiom g1092 (x : Prop) : Prop axiom g1093 (x : Prop) : Prop axiom g1094 (x : Prop) : Prop axiom g1095 (x : Prop) : Prop axiom g1096 (x : Prop) : Prop axiom g1097 (x : Prop) : Prop axiom g1098 (x : Prop) : Prop axiom g1099 (x : Prop) : Prop axiom g1100 (x : Prop) : Prop axiom g1101 (x : Prop) : Prop axiom g1102 (x : Prop) : Prop axiom g1103 (x : Prop) : Prop axiom g1104 (x : Prop) : Prop axiom g1105 (x : Prop) : Prop axiom g1106 (x : Prop) : Prop axiom g1107 (x : Prop) : Prop axiom g1108 (x : Prop) : Prop axiom g1109 (x : Prop) : Prop axiom g1110 (x : Prop) : Prop axiom g1111 (x : Prop) : Prop axiom g1112 (x : Prop) : Prop axiom g1113 (x : Prop) : Prop axiom g1114 (x : Prop) : Prop axiom g1115 (x : Prop) : Prop axiom g1116 (x : Prop) : Prop axiom g1117 (x : Prop) : Prop axiom g1118 (x : Prop) : Prop axiom g1119 (x : Prop) : Prop axiom g1120 (x : Prop) : Prop axiom g1121 (x : Prop) : Prop axiom g1122 (x : Prop) : Prop axiom g1123 (x : Prop) : Prop axiom g1124 (x : Prop) : Prop axiom g1125 (x : Prop) : Prop axiom g1126 (x : Prop) : Prop axiom g1127 (x : Prop) : Prop axiom g1128 (x : Prop) : Prop axiom g1129 (x : Prop) : Prop axiom g1130 (x : Prop) : Prop axiom g1131 (x : Prop) : Prop axiom g1132 (x : Prop) : Prop axiom g1133 (x : Prop) : Prop axiom g1134 (x : Prop) : Prop axiom g1135 (x : Prop) : Prop axiom g1136 (x : Prop) : Prop axiom g1137 (x : Prop) : Prop axiom g1138 (x : Prop) : Prop axiom g1139 (x : Prop) : Prop axiom g1140 (x : Prop) : Prop axiom g1141 (x : Prop) : Prop axiom g1142 (x : Prop) : Prop axiom g1143 (x : Prop) : Prop axiom g1144 (x : Prop) : Prop axiom g1145 (x : Prop) : Prop axiom g1146 (x : Prop) : Prop axiom g1147 (x : Prop) : Prop axiom g1148 (x : Prop) : Prop axiom g1149 (x : Prop) : Prop axiom g1150 (x : Prop) : Prop axiom g1151 (x : Prop) : Prop axiom g1152 (x : Prop) : Prop axiom g1153 (x : Prop) : Prop axiom g1154 (x : Prop) : Prop axiom g1155 (x : Prop) : Prop axiom g1156 (x : Prop) : Prop axiom g1157 (x : Prop) : Prop axiom g1158 (x : Prop) : Prop axiom g1159 (x : Prop) : Prop axiom g1160 (x : Prop) : Prop axiom g1161 (x : Prop) : Prop axiom g1162 (x : Prop) : Prop axiom g1163 (x : Prop) : Prop axiom g1164 (x : Prop) : Prop axiom g1165 (x : Prop) : Prop axiom g1166 (x : Prop) : Prop axiom g1167 (x : Prop) : Prop axiom g1168 (x : Prop) : Prop axiom g1169 (x : Prop) : Prop axiom g1170 (x : Prop) : Prop axiom g1171 (x : Prop) : Prop axiom g1172 (x : Prop) : Prop axiom g1173 (x : Prop) : Prop axiom g1174 (x : Prop) : Prop axiom g1175 (x : Prop) : Prop axiom g1176 (x : Prop) : Prop axiom g1177 (x : Prop) : Prop axiom g1178 (x : Prop) : Prop axiom g1179 (x : Prop) : Prop axiom g1180 (x : Prop) : Prop axiom g1181 (x : Prop) : Prop axiom g1182 (x : Prop) : Prop axiom g1183 (x : Prop) : Prop axiom g1184 (x : Prop) : Prop axiom g1185 (x : Prop) : Prop axiom g1186 (x : Prop) : Prop axiom g1187 (x : Prop) : Prop axiom g1188 (x : Prop) : Prop axiom g1189 (x : Prop) : Prop axiom g1190 (x : Prop) : Prop axiom g1191 (x : Prop) : Prop axiom g1192 (x : Prop) : Prop axiom g1193 (x : Prop) : Prop axiom g1194 (x : Prop) : Prop axiom g1195 (x : Prop) : Prop axiom g1196 (x : Prop) : Prop axiom g1197 (x : Prop) : Prop axiom g1198 (x : Prop) : Prop axiom g1199 (x : Prop) : Prop axiom g1200 (x : Prop) : Prop axiom g1201 (x : Prop) : Prop axiom g1202 (x : Prop) : Prop axiom g1203 (x : Prop) : Prop axiom g1204 (x : Prop) : Prop axiom g1205 (x : Prop) : Prop axiom g1206 (x : Prop) : Prop axiom g1207 (x : Prop) : Prop axiom g1208 (x : Prop) : Prop axiom g1209 (x : Prop) : Prop axiom g1210 (x : Prop) : Prop axiom g1211 (x : Prop) : Prop axiom g1212 (x : Prop) : Prop axiom g1213 (x : Prop) : Prop axiom g1214 (x : Prop) : Prop axiom g1215 (x : Prop) : Prop axiom g1216 (x : Prop) : Prop axiom g1217 (x : Prop) : Prop axiom g1218 (x : Prop) : Prop axiom g1219 (x : Prop) : Prop axiom g1220 (x : Prop) : Prop axiom g1221 (x : Prop) : Prop axiom g1222 (x : Prop) : Prop axiom g1223 (x : Prop) : Prop axiom g1224 (x : Prop) : Prop axiom g1225 (x : Prop) : Prop axiom g1226 (x : Prop) : Prop axiom g1227 (x : Prop) : Prop axiom g1228 (x : Prop) : Prop axiom g1229 (x : Prop) : Prop axiom g1230 (x : Prop) : Prop axiom g1231 (x : Prop) : Prop axiom g1232 (x : Prop) : Prop axiom g1233 (x : Prop) : Prop axiom g1234 (x : Prop) : Prop axiom g1235 (x : Prop) : Prop axiom g1236 (x : Prop) : Prop axiom g1237 (x : Prop) : Prop axiom g1238 (x : Prop) : Prop axiom g1239 (x : Prop) : Prop axiom g1240 (x : Prop) : Prop axiom g1241 (x : Prop) : Prop axiom g1242 (x : Prop) : Prop axiom g1243 (x : Prop) : Prop axiom g1244 (x : Prop) : Prop axiom g1245 (x : Prop) : Prop axiom g1246 (x : Prop) : Prop axiom g1247 (x : Prop) : Prop axiom g1248 (x : Prop) : Prop axiom g1249 (x : Prop) : Prop axiom g1250 (x : Prop) : Prop axiom g1251 (x : Prop) : Prop axiom g1252 (x : Prop) : Prop axiom g1253 (x : Prop) : Prop axiom g1254 (x : Prop) : Prop axiom g1255 (x : Prop) : Prop axiom g1256 (x : Prop) : Prop axiom g1257 (x : Prop) : Prop axiom g1258 (x : Prop) : Prop axiom g1259 (x : Prop) : Prop axiom g1260 (x : Prop) : Prop axiom g1261 (x : Prop) : Prop axiom g1262 (x : Prop) : Prop axiom g1263 (x : Prop) : Prop axiom g1264 (x : Prop) : Prop axiom g1265 (x : Prop) : Prop axiom g1266 (x : Prop) : Prop axiom g1267 (x : Prop) : Prop axiom g1268 (x : Prop) : Prop axiom g1269 (x : Prop) : Prop axiom g1270 (x : Prop) : Prop axiom g1271 (x : Prop) : Prop axiom g1272 (x : Prop) : Prop axiom g1273 (x : Prop) : Prop axiom g1274 (x : Prop) : Prop axiom g1275 (x : Prop) : Prop axiom g1276 (x : Prop) : Prop axiom g1277 (x : Prop) : Prop axiom g1278 (x : Prop) : Prop axiom g1279 (x : Prop) : Prop axiom g1280 (x : Prop) : Prop axiom g1281 (x : Prop) : Prop axiom g1282 (x : Prop) : Prop axiom g1283 (x : Prop) : Prop axiom g1284 (x : Prop) : Prop axiom g1285 (x : Prop) : Prop axiom g1286 (x : Prop) : Prop axiom g1287 (x : Prop) : Prop axiom g1288 (x : Prop) : Prop axiom g1289 (x : Prop) : Prop axiom g1290 (x : Prop) : Prop axiom g1291 (x : Prop) : Prop axiom g1292 (x : Prop) : Prop axiom g1293 (x : Prop) : Prop axiom g1294 (x : Prop) : Prop axiom g1295 (x : Prop) : Prop axiom g1296 (x : Prop) : Prop axiom g1297 (x : Prop) : Prop axiom g1298 (x : Prop) : Prop axiom g1299 (x : Prop) : Prop axiom g1300 (x : Prop) : Prop axiom g1301 (x : Prop) : Prop axiom g1302 (x : Prop) : Prop axiom g1303 (x : Prop) : Prop axiom g1304 (x : Prop) : Prop axiom g1305 (x : Prop) : Prop axiom g1306 (x : Prop) : Prop axiom g1307 (x : Prop) : Prop axiom g1308 (x : Prop) : Prop axiom g1309 (x : Prop) : Prop axiom g1310 (x : Prop) : Prop axiom g1311 (x : Prop) : Prop axiom g1312 (x : Prop) : Prop axiom g1313 (x : Prop) : Prop axiom g1314 (x : Prop) : Prop axiom g1315 (x : Prop) : Prop axiom g1316 (x : Prop) : Prop axiom g1317 (x : Prop) : Prop axiom g1318 (x : Prop) : Prop axiom g1319 (x : Prop) : Prop axiom g1320 (x : Prop) : Prop axiom g1321 (x : Prop) : Prop axiom g1322 (x : Prop) : Prop axiom g1323 (x : Prop) : Prop axiom g1324 (x : Prop) : Prop axiom g1325 (x : Prop) : Prop axiom g1326 (x : Prop) : Prop axiom g1327 (x : Prop) : Prop axiom g1328 (x : Prop) : Prop axiom g1329 (x : Prop) : Prop axiom g1330 (x : Prop) : Prop axiom g1331 (x : Prop) : Prop axiom g1332 (x : Prop) : Prop axiom g1333 (x : Prop) : Prop axiom g1334 (x : Prop) : Prop axiom g1335 (x : Prop) : Prop axiom g1336 (x : Prop) : Prop axiom g1337 (x : Prop) : Prop axiom g1338 (x : Prop) : Prop axiom g1339 (x : Prop) : Prop axiom g1340 (x : Prop) : Prop axiom g1341 (x : Prop) : Prop axiom g1342 (x : Prop) : Prop axiom g1343 (x : Prop) : Prop axiom g1344 (x : Prop) : Prop axiom g1345 (x : Prop) : Prop axiom g1346 (x : Prop) : Prop axiom g1347 (x : Prop) : Prop axiom g1348 (x : Prop) : Prop axiom g1349 (x : Prop) : Prop axiom g1350 (x : Prop) : Prop axiom g1351 (x : Prop) : Prop axiom g1352 (x : Prop) : Prop axiom g1353 (x : Prop) : Prop axiom g1354 (x : Prop) : Prop axiom g1355 (x : Prop) : Prop axiom g1356 (x : Prop) : Prop axiom g1357 (x : Prop) : Prop axiom g1358 (x : Prop) : Prop axiom g1359 (x : Prop) : Prop axiom g1360 (x : Prop) : Prop axiom g1361 (x : Prop) : Prop axiom g1362 (x : Prop) : Prop axiom g1363 (x : Prop) : Prop axiom g1364 (x : Prop) : Prop axiom g1365 (x : Prop) : Prop axiom g1366 (x : Prop) : Prop axiom g1367 (x : Prop) : Prop axiom g1368 (x : Prop) : Prop axiom g1369 (x : Prop) : Prop axiom g1370 (x : Prop) : Prop axiom g1371 (x : Prop) : Prop axiom g1372 (x : Prop) : Prop axiom g1373 (x : Prop) : Prop axiom g1374 (x : Prop) : Prop axiom g1375 (x : Prop) : Prop axiom g1376 (x : Prop) : Prop axiom g1377 (x : Prop) : Prop axiom g1378 (x : Prop) : Prop axiom g1379 (x : Prop) : Prop axiom g1380 (x : Prop) : Prop axiom g1381 (x : Prop) : Prop axiom g1382 (x : Prop) : Prop axiom g1383 (x : Prop) : Prop axiom g1384 (x : Prop) : Prop axiom g1385 (x : Prop) : Prop axiom g1386 (x : Prop) : Prop axiom g1387 (x : Prop) : Prop axiom g1388 (x : Prop) : Prop axiom g1389 (x : Prop) : Prop axiom g1390 (x : Prop) : Prop axiom g1391 (x : Prop) : Prop axiom g1392 (x : Prop) : Prop axiom g1393 (x : Prop) : Prop axiom g1394 (x : Prop) : Prop axiom g1395 (x : Prop) : Prop axiom g1396 (x : Prop) : Prop axiom g1397 (x : Prop) : Prop axiom g1398 (x : Prop) : Prop axiom g1399 (x : Prop) : Prop axiom g1400 (x : Prop) : Prop axiom g1401 (x : Prop) : Prop axiom g1402 (x : Prop) : Prop axiom g1403 (x : Prop) : Prop axiom g1404 (x : Prop) : Prop axiom g1405 (x : Prop) : Prop axiom g1406 (x : Prop) : Prop axiom g1407 (x : Prop) : Prop axiom g1408 (x : Prop) : Prop axiom g1409 (x : Prop) : Prop axiom g1410 (x : Prop) : Prop axiom g1411 (x : Prop) : Prop axiom g1412 (x : Prop) : Prop axiom g1413 (x : Prop) : Prop axiom g1414 (x : Prop) : Prop axiom g1415 (x : Prop) : Prop axiom g1416 (x : Prop) : Prop axiom g1417 (x : Prop) : Prop axiom g1418 (x : Prop) : Prop axiom g1419 (x : Prop) : Prop axiom g1420 (x : Prop) : Prop axiom g1421 (x : Prop) : Prop axiom g1422 (x : Prop) : Prop axiom g1423 (x : Prop) : Prop axiom g1424 (x : Prop) : Prop axiom g1425 (x : Prop) : Prop axiom g1426 (x : Prop) : Prop axiom g1427 (x : Prop) : Prop axiom g1428 (x : Prop) : Prop axiom g1429 (x : Prop) : Prop axiom g1430 (x : Prop) : Prop axiom g1431 (x : Prop) : Prop axiom g1432 (x : Prop) : Prop axiom g1433 (x : Prop) : Prop axiom g1434 (x : Prop) : Prop axiom g1435 (x : Prop) : Prop axiom g1436 (x : Prop) : Prop axiom g1437 (x : Prop) : Prop axiom g1438 (x : Prop) : Prop axiom g1439 (x : Prop) : Prop axiom g1440 (x : Prop) : Prop axiom g1441 (x : Prop) : Prop axiom g1442 (x : Prop) : Prop axiom g1443 (x : Prop) : Prop axiom g1444 (x : Prop) : Prop axiom g1445 (x : Prop) : Prop axiom g1446 (x : Prop) : Prop axiom g1447 (x : Prop) : Prop axiom g1448 (x : Prop) : Prop axiom g1449 (x : Prop) : Prop axiom g1450 (x : Prop) : Prop axiom g1451 (x : Prop) : Prop axiom g1452 (x : Prop) : Prop axiom g1453 (x : Prop) : Prop axiom g1454 (x : Prop) : Prop axiom g1455 (x : Prop) : Prop axiom g1456 (x : Prop) : Prop axiom g1457 (x : Prop) : Prop axiom g1458 (x : Prop) : Prop axiom g1459 (x : Prop) : Prop axiom g1460 (x : Prop) : Prop axiom g1461 (x : Prop) : Prop axiom g1462 (x : Prop) : Prop axiom g1463 (x : Prop) : Prop axiom g1464 (x : Prop) : Prop axiom g1465 (x : Prop) : Prop axiom g1466 (x : Prop) : Prop axiom g1467 (x : Prop) : Prop axiom g1468 (x : Prop) : Prop axiom g1469 (x : Prop) : Prop axiom g1470 (x : Prop) : Prop axiom g1471 (x : Prop) : Prop axiom g1472 (x : Prop) : Prop axiom g1473 (x : Prop) : Prop axiom g1474 (x : Prop) : Prop axiom g1475 (x : Prop) : Prop axiom g1476 (x : Prop) : Prop axiom g1477 (x : Prop) : Prop axiom g1478 (x : Prop) : Prop axiom g1479 (x : Prop) : Prop axiom g1480 (x : Prop) : Prop axiom g1481 (x : Prop) : Prop axiom g1482 (x : Prop) : Prop axiom g1483 (x : Prop) : Prop axiom g1484 (x : Prop) : Prop axiom g1485 (x : Prop) : Prop axiom g1486 (x : Prop) : Prop axiom g1487 (x : Prop) : Prop axiom g1488 (x : Prop) : Prop axiom g1489 (x : Prop) : Prop axiom g1490 (x : Prop) : Prop axiom g1491 (x : Prop) : Prop axiom g1492 (x : Prop) : Prop axiom g1493 (x : Prop) : Prop axiom g1494 (x : Prop) : Prop axiom g1495 (x : Prop) : Prop axiom g1496 (x : Prop) : Prop axiom g1497 (x : Prop) : Prop axiom g1498 (x : Prop) : Prop axiom g1499 (x : Prop) : Prop axiom g1500 (x : Prop) : Prop axiom g1501 (x : Prop) : Prop axiom g1502 (x : Prop) : Prop axiom g1503 (x : Prop) : Prop axiom g1504 (x : Prop) : Prop axiom g1505 (x : Prop) : Prop axiom g1506 (x : Prop) : Prop axiom g1507 (x : Prop) : Prop axiom g1508 (x : Prop) : Prop axiom g1509 (x : Prop) : Prop axiom g1510 (x : Prop) : Prop axiom g1511 (x : Prop) : Prop axiom g1512 (x : Prop) : Prop axiom g1513 (x : Prop) : Prop axiom g1514 (x : Prop) : Prop axiom g1515 (x : Prop) : Prop axiom g1516 (x : Prop) : Prop axiom g1517 (x : Prop) : Prop axiom g1518 (x : Prop) : Prop axiom g1519 (x : Prop) : Prop axiom g1520 (x : Prop) : Prop axiom g1521 (x : Prop) : Prop axiom g1522 (x : Prop) : Prop axiom g1523 (x : Prop) : Prop axiom g1524 (x : Prop) : Prop axiom g1525 (x : Prop) : Prop axiom g1526 (x : Prop) : Prop axiom g1527 (x : Prop) : Prop axiom g1528 (x : Prop) : Prop axiom g1529 (x : Prop) : Prop axiom g1530 (x : Prop) : Prop axiom g1531 (x : Prop) : Prop axiom g1532 (x : Prop) : Prop axiom g1533 (x : Prop) : Prop axiom g1534 (x : Prop) : Prop axiom g1535 (x : Prop) : Prop axiom g1536 (x : Prop) : Prop axiom g1537 (x : Prop) : Prop axiom g1538 (x : Prop) : Prop axiom g1539 (x : Prop) : Prop axiom g1540 (x : Prop) : Prop axiom g1541 (x : Prop) : Prop axiom g1542 (x : Prop) : Prop axiom g1543 (x : Prop) : Prop axiom g1544 (x : Prop) : Prop axiom g1545 (x : Prop) : Prop axiom g1546 (x : Prop) : Prop axiom g1547 (x : Prop) : Prop axiom g1548 (x : Prop) : Prop axiom g1549 (x : Prop) : Prop axiom g1550 (x : Prop) : Prop axiom g1551 (x : Prop) : Prop axiom g1552 (x : Prop) : Prop axiom g1553 (x : Prop) : Prop axiom g1554 (x : Prop) : Prop axiom g1555 (x : Prop) : Prop axiom g1556 (x : Prop) : Prop axiom g1557 (x : Prop) : Prop axiom g1558 (x : Prop) : Prop axiom g1559 (x : Prop) : Prop axiom g1560 (x : Prop) : Prop axiom g1561 (x : Prop) : Prop axiom g1562 (x : Prop) : Prop axiom g1563 (x : Prop) : Prop axiom g1564 (x : Prop) : Prop axiom g1565 (x : Prop) : Prop axiom g1566 (x : Prop) : Prop axiom g1567 (x : Prop) : Prop axiom g1568 (x : Prop) : Prop axiom g1569 (x : Prop) : Prop axiom g1570 (x : Prop) : Prop axiom g1571 (x : Prop) : Prop axiom g1572 (x : Prop) : Prop axiom g1573 (x : Prop) : Prop axiom g1574 (x : Prop) : Prop axiom g1575 (x : Prop) : Prop axiom g1576 (x : Prop) : Prop axiom g1577 (x : Prop) : Prop axiom g1578 (x : Prop) : Prop axiom g1579 (x : Prop) : Prop axiom g1580 (x : Prop) : Prop axiom g1581 (x : Prop) : Prop axiom g1582 (x : Prop) : Prop axiom g1583 (x : Prop) : Prop axiom g1584 (x : Prop) : Prop axiom g1585 (x : Prop) : Prop axiom g1586 (x : Prop) : Prop axiom g1587 (x : Prop) : Prop axiom g1588 (x : Prop) : Prop axiom g1589 (x : Prop) : Prop axiom g1590 (x : Prop) : Prop axiom g1591 (x : Prop) : Prop axiom g1592 (x : Prop) : Prop axiom g1593 (x : Prop) : Prop axiom g1594 (x : Prop) : Prop axiom g1595 (x : Prop) : Prop axiom g1596 (x : Prop) : Prop axiom g1597 (x : Prop) : Prop axiom g1598 (x : Prop) : Prop axiom g1599 (x : Prop) : Prop axiom g1600 (x : Prop) : Prop axiom g1601 (x : Prop) : Prop axiom g1602 (x : Prop) : Prop axiom g1603 (x : Prop) : Prop axiom g1604 (x : Prop) : Prop axiom g1605 (x : Prop) : Prop axiom g1606 (x : Prop) : Prop axiom g1607 (x : Prop) : Prop axiom g1608 (x : Prop) : Prop axiom g1609 (x : Prop) : Prop axiom g1610 (x : Prop) : Prop axiom g1611 (x : Prop) : Prop axiom g1612 (x : Prop) : Prop axiom g1613 (x : Prop) : Prop axiom g1614 (x : Prop) : Prop axiom g1615 (x : Prop) : Prop axiom g1616 (x : Prop) : Prop axiom g1617 (x : Prop) : Prop axiom g1618 (x : Prop) : Prop axiom g1619 (x : Prop) : Prop axiom g1620 (x : Prop) : Prop axiom g1621 (x : Prop) : Prop axiom g1622 (x : Prop) : Prop axiom g1623 (x : Prop) : Prop axiom g1624 (x : Prop) : Prop axiom g1625 (x : Prop) : Prop axiom g1626 (x : Prop) : Prop axiom g1627 (x : Prop) : Prop axiom g1628 (x : Prop) : Prop axiom g1629 (x : Prop) : Prop axiom g1630 (x : Prop) : Prop axiom g1631 (x : Prop) : Prop axiom g1632 (x : Prop) : Prop axiom g1633 (x : Prop) : Prop axiom g1634 (x : Prop) : Prop axiom g1635 (x : Prop) : Prop axiom g1636 (x : Prop) : Prop axiom g1637 (x : Prop) : Prop axiom g1638 (x : Prop) : Prop axiom g1639 (x : Prop) : Prop axiom g1640 (x : Prop) : Prop axiom g1641 (x : Prop) : Prop axiom g1642 (x : Prop) : Prop axiom g1643 (x : Prop) : Prop axiom g1644 (x : Prop) : Prop axiom g1645 (x : Prop) : Prop axiom g1646 (x : Prop) : Prop axiom g1647 (x : Prop) : Prop axiom g1648 (x : Prop) : Prop axiom g1649 (x : Prop) : Prop axiom g1650 (x : Prop) : Prop axiom g1651 (x : Prop) : Prop axiom g1652 (x : Prop) : Prop axiom g1653 (x : Prop) : Prop axiom g1654 (x : Prop) : Prop axiom g1655 (x : Prop) : Prop axiom g1656 (x : Prop) : Prop axiom g1657 (x : Prop) : Prop axiom g1658 (x : Prop) : Prop axiom g1659 (x : Prop) : Prop axiom g1660 (x : Prop) : Prop axiom g1661 (x : Prop) : Prop axiom g1662 (x : Prop) : Prop axiom g1663 (x : Prop) : Prop axiom g1664 (x : Prop) : Prop axiom g1665 (x : Prop) : Prop axiom g1666 (x : Prop) : Prop axiom g1667 (x : Prop) : Prop axiom g1668 (x : Prop) : Prop axiom g1669 (x : Prop) : Prop axiom g1670 (x : Prop) : Prop axiom g1671 (x : Prop) : Prop axiom g1672 (x : Prop) : Prop axiom g1673 (x : Prop) : Prop axiom g1674 (x : Prop) : Prop axiom g1675 (x : Prop) : Prop axiom g1676 (x : Prop) : Prop axiom g1677 (x : Prop) : Prop axiom g1678 (x : Prop) : Prop axiom g1679 (x : Prop) : Prop axiom g1680 (x : Prop) : Prop axiom g1681 (x : Prop) : Prop axiom g1682 (x : Prop) : Prop axiom g1683 (x : Prop) : Prop axiom g1684 (x : Prop) : Prop axiom g1685 (x : Prop) : Prop axiom g1686 (x : Prop) : Prop axiom g1687 (x : Prop) : Prop axiom g1688 (x : Prop) : Prop axiom g1689 (x : Prop) : Prop axiom g1690 (x : Prop) : Prop axiom g1691 (x : Prop) : Prop axiom g1692 (x : Prop) : Prop axiom g1693 (x : Prop) : Prop axiom g1694 (x : Prop) : Prop axiom g1695 (x : Prop) : Prop axiom g1696 (x : Prop) : Prop axiom g1697 (x : Prop) : Prop axiom g1698 (x : Prop) : Prop axiom g1699 (x : Prop) : Prop axiom g1700 (x : Prop) : Prop axiom g1701 (x : Prop) : Prop axiom g1702 (x : Prop) : Prop axiom g1703 (x : Prop) : Prop axiom g1704 (x : Prop) : Prop axiom g1705 (x : Prop) : Prop axiom g1706 (x : Prop) : Prop axiom g1707 (x : Prop) : Prop axiom g1708 (x : Prop) : Prop axiom g1709 (x : Prop) : Prop axiom g1710 (x : Prop) : Prop axiom g1711 (x : Prop) : Prop axiom g1712 (x : Prop) : Prop axiom g1713 (x : Prop) : Prop axiom g1714 (x : Prop) : Prop axiom g1715 (x : Prop) : Prop axiom g1716 (x : Prop) : Prop axiom g1717 (x : Prop) : Prop axiom g1718 (x : Prop) : Prop axiom g1719 (x : Prop) : Prop axiom g1720 (x : Prop) : Prop axiom g1721 (x : Prop) : Prop axiom g1722 (x : Prop) : Prop axiom g1723 (x : Prop) : Prop axiom g1724 (x : Prop) : Prop axiom g1725 (x : Prop) : Prop axiom g1726 (x : Prop) : Prop axiom g1727 (x : Prop) : Prop axiom g1728 (x : Prop) : Prop axiom g1729 (x : Prop) : Prop axiom g1730 (x : Prop) : Prop axiom g1731 (x : Prop) : Prop axiom g1732 (x : Prop) : Prop axiom g1733 (x : Prop) : Prop axiom g1734 (x : Prop) : Prop axiom g1735 (x : Prop) : Prop axiom g1736 (x : Prop) : Prop axiom g1737 (x : Prop) : Prop axiom g1738 (x : Prop) : Prop axiom g1739 (x : Prop) : Prop axiom g1740 (x : Prop) : Prop axiom g1741 (x : Prop) : Prop axiom g1742 (x : Prop) : Prop axiom g1743 (x : Prop) : Prop axiom g1744 (x : Prop) : Prop axiom g1745 (x : Prop) : Prop axiom g1746 (x : Prop) : Prop axiom g1747 (x : Prop) : Prop axiom g1748 (x : Prop) : Prop axiom g1749 (x : Prop) : Prop axiom g1750 (x : Prop) : Prop axiom g1751 (x : Prop) : Prop axiom g1752 (x : Prop) : Prop axiom g1753 (x : Prop) : Prop axiom g1754 (x : Prop) : Prop axiom g1755 (x : Prop) : Prop axiom g1756 (x : Prop) : Prop axiom g1757 (x : Prop) : Prop axiom g1758 (x : Prop) : Prop axiom g1759 (x : Prop) : Prop axiom g1760 (x : Prop) : Prop axiom g1761 (x : Prop) : Prop axiom g1762 (x : Prop) : Prop axiom g1763 (x : Prop) : Prop axiom g1764 (x : Prop) : Prop axiom g1765 (x : Prop) : Prop axiom g1766 (x : Prop) : Prop axiom g1767 (x : Prop) : Prop axiom g1768 (x : Prop) : Prop axiom g1769 (x : Prop) : Prop axiom g1770 (x : Prop) : Prop axiom g1771 (x : Prop) : Prop axiom g1772 (x : Prop) : Prop axiom g1773 (x : Prop) : Prop axiom g1774 (x : Prop) : Prop axiom g1775 (x : Prop) : Prop axiom g1776 (x : Prop) : Prop axiom g1777 (x : Prop) : Prop axiom g1778 (x : Prop) : Prop axiom g1779 (x : Prop) : Prop axiom g1780 (x : Prop) : Prop axiom g1781 (x : Prop) : Prop axiom g1782 (x : Prop) : Prop axiom g1783 (x : Prop) : Prop axiom g1784 (x : Prop) : Prop axiom g1785 (x : Prop) : Prop axiom g1786 (x : Prop) : Prop axiom g1787 (x : Prop) : Prop axiom g1788 (x : Prop) : Prop axiom g1789 (x : Prop) : Prop axiom g1790 (x : Prop) : Prop axiom g1791 (x : Prop) : Prop axiom g1792 (x : Prop) : Prop axiom g1793 (x : Prop) : Prop axiom g1794 (x : Prop) : Prop axiom g1795 (x : Prop) : Prop axiom g1796 (x : Prop) : Prop axiom g1797 (x : Prop) : Prop axiom g1798 (x : Prop) : Prop axiom g1799 (x : Prop) : Prop axiom g1800 (x : Prop) : Prop axiom g1801 (x : Prop) : Prop axiom g1802 (x : Prop) : Prop axiom g1803 (x : Prop) : Prop axiom g1804 (x : Prop) : Prop axiom g1805 (x : Prop) : Prop axiom g1806 (x : Prop) : Prop axiom g1807 (x : Prop) : Prop axiom g1808 (x : Prop) : Prop axiom g1809 (x : Prop) : Prop axiom g1810 (x : Prop) : Prop axiom g1811 (x : Prop) : Prop axiom g1812 (x : Prop) : Prop axiom g1813 (x : Prop) : Prop axiom g1814 (x : Prop) : Prop axiom g1815 (x : Prop) : Prop axiom g1816 (x : Prop) : Prop axiom g1817 (x : Prop) : Prop axiom g1818 (x : Prop) : Prop axiom g1819 (x : Prop) : Prop axiom g1820 (x : Prop) : Prop axiom g1821 (x : Prop) : Prop axiom g1822 (x : Prop) : Prop axiom g1823 (x : Prop) : Prop axiom g1824 (x : Prop) : Prop axiom g1825 (x : Prop) : Prop axiom g1826 (x : Prop) : Prop axiom g1827 (x : Prop) : Prop axiom g1828 (x : Prop) : Prop axiom g1829 (x : Prop) : Prop axiom g1830 (x : Prop) : Prop axiom g1831 (x : Prop) : Prop axiom g1832 (x : Prop) : Prop axiom g1833 (x : Prop) : Prop axiom g1834 (x : Prop) : Prop axiom g1835 (x : Prop) : Prop axiom g1836 (x : Prop) : Prop axiom g1837 (x : Prop) : Prop axiom g1838 (x : Prop) : Prop axiom g1839 (x : Prop) : Prop axiom g1840 (x : Prop) : Prop axiom g1841 (x : Prop) : Prop axiom g1842 (x : Prop) : Prop axiom g1843 (x : Prop) : Prop axiom g1844 (x : Prop) : Prop axiom g1845 (x : Prop) : Prop axiom g1846 (x : Prop) : Prop axiom g1847 (x : Prop) : Prop axiom g1848 (x : Prop) : Prop axiom g1849 (x : Prop) : Prop axiom g1850 (x : Prop) : Prop axiom g1851 (x : Prop) : Prop axiom g1852 (x : Prop) : Prop axiom g1853 (x : Prop) : Prop axiom g1854 (x : Prop) : Prop axiom g1855 (x : Prop) : Prop axiom g1856 (x : Prop) : Prop axiom g1857 (x : Prop) : Prop axiom g1858 (x : Prop) : Prop axiom g1859 (x : Prop) : Prop axiom g1860 (x : Prop) : Prop axiom g1861 (x : Prop) : Prop axiom g1862 (x : Prop) : Prop axiom g1863 (x : Prop) : Prop axiom g1864 (x : Prop) : Prop axiom g1865 (x : Prop) : Prop axiom g1866 (x : Prop) : Prop axiom g1867 (x : Prop) : Prop axiom g1868 (x : Prop) : Prop axiom g1869 (x : Prop) : Prop axiom g1870 (x : Prop) : Prop axiom g1871 (x : Prop) : Prop axiom g1872 (x : Prop) : Prop axiom g1873 (x : Prop) : Prop axiom g1874 (x : Prop) : Prop axiom g1875 (x : Prop) : Prop axiom g1876 (x : Prop) : Prop axiom g1877 (x : Prop) : Prop axiom g1878 (x : Prop) : Prop axiom g1879 (x : Prop) : Prop axiom g1880 (x : Prop) : Prop axiom g1881 (x : Prop) : Prop axiom g1882 (x : Prop) : Prop axiom g1883 (x : Prop) : Prop axiom g1884 (x : Prop) : Prop axiom g1885 (x : Prop) : Prop axiom g1886 (x : Prop) : Prop axiom g1887 (x : Prop) : Prop axiom g1888 (x : Prop) : Prop axiom g1889 (x : Prop) : Prop axiom g1890 (x : Prop) : Prop axiom g1891 (x : Prop) : Prop axiom g1892 (x : Prop) : Prop axiom g1893 (x : Prop) : Prop axiom g1894 (x : Prop) : Prop axiom g1895 (x : Prop) : Prop axiom g1896 (x : Prop) : Prop axiom g1897 (x : Prop) : Prop axiom g1898 (x : Prop) : Prop axiom g1899 (x : Prop) : Prop axiom g1900 (x : Prop) : Prop axiom g1901 (x : Prop) : Prop axiom g1902 (x : Prop) : Prop axiom g1903 (x : Prop) : Prop axiom g1904 (x : Prop) : Prop axiom g1905 (x : Prop) : Prop axiom g1906 (x : Prop) : Prop axiom g1907 (x : Prop) : Prop axiom g1908 (x : Prop) : Prop axiom g1909 (x : Prop) : Prop axiom g1910 (x : Prop) : Prop axiom g1911 (x : Prop) : Prop axiom g1912 (x : Prop) : Prop axiom g1913 (x : Prop) : Prop axiom g1914 (x : Prop) : Prop axiom g1915 (x : Prop) : Prop axiom g1916 (x : Prop) : Prop axiom g1917 (x : Prop) : Prop axiom g1918 (x : Prop) : Prop axiom g1919 (x : Prop) : Prop axiom g1920 (x : Prop) : Prop axiom g1921 (x : Prop) : Prop axiom g1922 (x : Prop) : Prop axiom g1923 (x : Prop) : Prop axiom g1924 (x : Prop) : Prop axiom g1925 (x : Prop) : Prop axiom g1926 (x : Prop) : Prop axiom g1927 (x : Prop) : Prop axiom g1928 (x : Prop) : Prop axiom g1929 (x : Prop) : Prop axiom g1930 (x : Prop) : Prop axiom g1931 (x : Prop) : Prop axiom g1932 (x : Prop) : Prop axiom g1933 (x : Prop) : Prop axiom g1934 (x : Prop) : Prop axiom g1935 (x : Prop) : Prop axiom g1936 (x : Prop) : Prop axiom g1937 (x : Prop) : Prop axiom g1938 (x : Prop) : Prop axiom g1939 (x : Prop) : Prop axiom g1940 (x : Prop) : Prop axiom g1941 (x : Prop) : Prop axiom g1942 (x : Prop) : Prop axiom g1943 (x : Prop) : Prop axiom g1944 (x : Prop) : Prop axiom g1945 (x : Prop) : Prop axiom g1946 (x : Prop) : Prop axiom g1947 (x : Prop) : Prop axiom g1948 (x : Prop) : Prop axiom g1949 (x : Prop) : Prop axiom g1950 (x : Prop) : Prop axiom g1951 (x : Prop) : Prop axiom g1952 (x : Prop) : Prop axiom g1953 (x : Prop) : Prop axiom g1954 (x : Prop) : Prop axiom g1955 (x : Prop) : Prop axiom g1956 (x : Prop) : Prop axiom g1957 (x : Prop) : Prop axiom g1958 (x : Prop) : Prop axiom g1959 (x : Prop) : Prop axiom g1960 (x : Prop) : Prop axiom g1961 (x : Prop) : Prop axiom g1962 (x : Prop) : Prop axiom g1963 (x : Prop) : Prop axiom g1964 (x : Prop) : Prop axiom g1965 (x : Prop) : Prop axiom g1966 (x : Prop) : Prop axiom g1967 (x : Prop) : Prop axiom g1968 (x : Prop) : Prop axiom g1969 (x : Prop) : Prop axiom g1970 (x : Prop) : Prop axiom g1971 (x : Prop) : Prop axiom g1972 (x : Prop) : Prop axiom g1973 (x : Prop) : Prop axiom g1974 (x : Prop) : Prop axiom g1975 (x : Prop) : Prop axiom g1976 (x : Prop) : Prop axiom g1977 (x : Prop) : Prop axiom g1978 (x : Prop) : Prop axiom g1979 (x : Prop) : Prop axiom g1980 (x : Prop) : Prop axiom g1981 (x : Prop) : Prop axiom g1982 (x : Prop) : Prop axiom g1983 (x : Prop) : Prop axiom g1984 (x : Prop) : Prop axiom g1985 (x : Prop) : Prop axiom g1986 (x : Prop) : Prop axiom g1987 (x : Prop) : Prop axiom g1988 (x : Prop) : Prop axiom g1989 (x : Prop) : Prop axiom g1990 (x : Prop) : Prop axiom g1991 (x : Prop) : Prop axiom g1992 (x : Prop) : Prop axiom g1993 (x : Prop) : Prop axiom g1994 (x : Prop) : Prop axiom g1995 (x : Prop) : Prop axiom g1996 (x : Prop) : Prop axiom g1997 (x : Prop) : Prop axiom g1998 (x : Prop) : Prop axiom g1999 (x : Prop) : Prop axiom g2000 (x : Prop) : Prop axiom g2001 (x : Prop) : Prop axiom g2002 (x : Prop) : Prop axiom g2003 (x : Prop) : Prop axiom g2004 (x : Prop) : Prop axiom g2005 (x : Prop) : Prop axiom g2006 (x : Prop) : Prop axiom g2007 (x : Prop) : Prop axiom g2008 (x : Prop) : Prop axiom g2009 (x : Prop) : Prop axiom g2010 (x : Prop) : Prop axiom g2011 (x : Prop) : Prop axiom g2012 (x : Prop) : Prop axiom g2013 (x : Prop) : Prop axiom g2014 (x : Prop) : Prop axiom g2015 (x : Prop) : Prop axiom g2016 (x : Prop) : Prop axiom g2017 (x : Prop) : Prop axiom g2018 (x : Prop) : Prop axiom g2019 (x : Prop) : Prop axiom g2020 (x : Prop) : Prop axiom g2021 (x : Prop) : Prop axiom g2022 (x : Prop) : Prop axiom g2023 (x : Prop) : Prop axiom g2024 (x : Prop) : Prop axiom g2025 (x : Prop) : Prop axiom g2026 (x : Prop) : Prop axiom g2027 (x : Prop) : Prop axiom g2028 (x : Prop) : Prop axiom g2029 (x : Prop) : Prop axiom g2030 (x : Prop) : Prop axiom g2031 (x : Prop) : Prop axiom g2032 (x : Prop) : Prop axiom g2033 (x : Prop) : Prop axiom g2034 (x : Prop) : Prop axiom g2035 (x : Prop) : Prop axiom g2036 (x : Prop) : Prop axiom g2037 (x : Prop) : Prop axiom g2038 (x : Prop) : Prop axiom g2039 (x : Prop) : Prop axiom g2040 (x : Prop) : Prop axiom g2041 (x : Prop) : Prop axiom g2042 (x : Prop) : Prop axiom g2043 (x : Prop) : Prop axiom g2044 (x : Prop) : Prop axiom g2045 (x : Prop) : Prop axiom g2046 (x : Prop) : Prop axiom g2047 (x : Prop) : Prop axiom g2048 (x : Prop) : Prop axiom g2049 (x : Prop) : Prop axiom g2050 (x : Prop) : Prop axiom g2051 (x : Prop) : Prop axiom g2052 (x : Prop) : Prop axiom g2053 (x : Prop) : Prop axiom g2054 (x : Prop) : Prop axiom g2055 (x : Prop) : Prop axiom g2056 (x : Prop) : Prop axiom g2057 (x : Prop) : Prop axiom g2058 (x : Prop) : Prop axiom g2059 (x : Prop) : Prop axiom g2060 (x : Prop) : Prop axiom g2061 (x : Prop) : Prop axiom g2062 (x : Prop) : Prop axiom g2063 (x : Prop) : Prop axiom g2064 (x : Prop) : Prop axiom g2065 (x : Prop) : Prop axiom g2066 (x : Prop) : Prop axiom g2067 (x : Prop) : Prop axiom g2068 (x : Prop) : Prop axiom g2069 (x : Prop) : Prop axiom g2070 (x : Prop) : Prop axiom g2071 (x : Prop) : Prop axiom g2072 (x : Prop) : Prop axiom g2073 (x : Prop) : Prop axiom g2074 (x : Prop) : Prop axiom g2075 (x : Prop) : Prop axiom g2076 (x : Prop) : Prop axiom g2077 (x : Prop) : Prop axiom g2078 (x : Prop) : Prop axiom g2079 (x : Prop) : Prop axiom g2080 (x : Prop) : Prop axiom g2081 (x : Prop) : Prop axiom g2082 (x : Prop) : Prop axiom g2083 (x : Prop) : Prop axiom g2084 (x : Prop) : Prop axiom g2085 (x : Prop) : Prop axiom g2086 (x : Prop) : Prop axiom g2087 (x : Prop) : Prop axiom g2088 (x : Prop) : Prop axiom g2089 (x : Prop) : Prop axiom g2090 (x : Prop) : Prop axiom g2091 (x : Prop) : Prop axiom g2092 (x : Prop) : Prop axiom g2093 (x : Prop) : Prop axiom g2094 (x : Prop) : Prop axiom g2095 (x : Prop) : Prop axiom g2096 (x : Prop) : Prop axiom g2097 (x : Prop) : Prop axiom g2098 (x : Prop) : Prop axiom g2099 (x : Prop) : Prop axiom g2100 (x : Prop) : Prop axiom g2101 (x : Prop) : Prop axiom g2102 (x : Prop) : Prop axiom g2103 (x : Prop) : Prop axiom g2104 (x : Prop) : Prop axiom g2105 (x : Prop) : Prop axiom g2106 (x : Prop) : Prop axiom g2107 (x : Prop) : Prop axiom g2108 (x : Prop) : Prop axiom g2109 (x : Prop) : Prop axiom g2110 (x : Prop) : Prop axiom g2111 (x : Prop) : Prop axiom g2112 (x : Prop) : Prop axiom g2113 (x : Prop) : Prop axiom g2114 (x : Prop) : Prop axiom g2115 (x : Prop) : Prop axiom g2116 (x : Prop) : Prop axiom g2117 (x : Prop) : Prop axiom g2118 (x : Prop) : Prop axiom g2119 (x : Prop) : Prop axiom g2120 (x : Prop) : Prop axiom g2121 (x : Prop) : Prop axiom g2122 (x : Prop) : Prop axiom g2123 (x : Prop) : Prop axiom g2124 (x : Prop) : Prop axiom g2125 (x : Prop) : Prop axiom g2126 (x : Prop) : Prop axiom g2127 (x : Prop) : Prop axiom g2128 (x : Prop) : Prop axiom g2129 (x : Prop) : Prop axiom g2130 (x : Prop) : Prop axiom g2131 (x : Prop) : Prop axiom g2132 (x : Prop) : Prop axiom g2133 (x : Prop) : Prop axiom g2134 (x : Prop) : Prop axiom g2135 (x : Prop) : Prop axiom g2136 (x : Prop) : Prop axiom g2137 (x : Prop) : Prop axiom g2138 (x : Prop) : Prop axiom g2139 (x : Prop) : Prop axiom g2140 (x : Prop) : Prop axiom g2141 (x : Prop) : Prop axiom g2142 (x : Prop) : Prop axiom g2143 (x : Prop) : Prop axiom g2144 (x : Prop) : Prop axiom g2145 (x : Prop) : Prop axiom g2146 (x : Prop) : Prop axiom g2147 (x : Prop) : Prop axiom g2148 (x : Prop) : Prop axiom g2149 (x : Prop) : Prop axiom g2150 (x : Prop) : Prop axiom g2151 (x : Prop) : Prop axiom g2152 (x : Prop) : Prop axiom g2153 (x : Prop) : Prop axiom g2154 (x : Prop) : Prop axiom g2155 (x : Prop) : Prop axiom g2156 (x : Prop) : Prop axiom g2157 (x : Prop) : Prop axiom g2158 (x : Prop) : Prop axiom g2159 (x : Prop) : Prop axiom g2160 (x : Prop) : Prop axiom g2161 (x : Prop) : Prop axiom g2162 (x : Prop) : Prop axiom g2163 (x : Prop) : Prop axiom g2164 (x : Prop) : Prop axiom g2165 (x : Prop) : Prop axiom g2166 (x : Prop) : Prop axiom g2167 (x : Prop) : Prop axiom g2168 (x : Prop) : Prop axiom g2169 (x : Prop) : Prop axiom g2170 (x : Prop) : Prop axiom g2171 (x : Prop) : Prop axiom g2172 (x : Prop) : Prop axiom g2173 (x : Prop) : Prop axiom g2174 (x : Prop) : Prop axiom g2175 (x : Prop) : Prop axiom g2176 (x : Prop) : Prop axiom g2177 (x : Prop) : Prop axiom g2178 (x : Prop) : Prop axiom g2179 (x : Prop) : Prop axiom g2180 (x : Prop) : Prop axiom g2181 (x : Prop) : Prop axiom g2182 (x : Prop) : Prop axiom g2183 (x : Prop) : Prop axiom g2184 (x : Prop) : Prop axiom g2185 (x : Prop) : Prop axiom g2186 (x : Prop) : Prop axiom g2187 (x : Prop) : Prop axiom g2188 (x : Prop) : Prop axiom g2189 (x : Prop) : Prop axiom g2190 (x : Prop) : Prop axiom g2191 (x : Prop) : Prop axiom g2192 (x : Prop) : Prop axiom g2193 (x : Prop) : Prop axiom g2194 (x : Prop) : Prop axiom g2195 (x : Prop) : Prop axiom g2196 (x : Prop) : Prop axiom g2197 (x : Prop) : Prop axiom g2198 (x : Prop) : Prop axiom g2199 (x : Prop) : Prop axiom g2200 (x : Prop) : Prop axiom g2201 (x : Prop) : Prop axiom g2202 (x : Prop) : Prop axiom g2203 (x : Prop) : Prop axiom g2204 (x : Prop) : Prop axiom g2205 (x : Prop) : Prop axiom g2206 (x : Prop) : Prop axiom g2207 (x : Prop) : Prop axiom g2208 (x : Prop) : Prop axiom g2209 (x : Prop) : Prop axiom g2210 (x : Prop) : Prop axiom g2211 (x : Prop) : Prop axiom g2212 (x : Prop) : Prop axiom g2213 (x : Prop) : Prop axiom g2214 (x : Prop) : Prop axiom g2215 (x : Prop) : Prop axiom g2216 (x : Prop) : Prop axiom g2217 (x : Prop) : Prop axiom g2218 (x : Prop) : Prop axiom g2219 (x : Prop) : Prop axiom g2220 (x : Prop) : Prop axiom g2221 (x : Prop) : Prop axiom g2222 (x : Prop) : Prop axiom g2223 (x : Prop) : Prop axiom g2224 (x : Prop) : Prop axiom g2225 (x : Prop) : Prop axiom g2226 (x : Prop) : Prop axiom g2227 (x : Prop) : Prop axiom g2228 (x : Prop) : Prop axiom g2229 (x : Prop) : Prop axiom g2230 (x : Prop) : Prop axiom g2231 (x : Prop) : Prop axiom g2232 (x : Prop) : Prop axiom g2233 (x : Prop) : Prop axiom g2234 (x : Prop) : Prop axiom g2235 (x : Prop) : Prop axiom g2236 (x : Prop) : Prop axiom g2237 (x : Prop) : Prop axiom g2238 (x : Prop) : Prop axiom g2239 (x : Prop) : Prop axiom g2240 (x : Prop) : Prop axiom g2241 (x : Prop) : Prop axiom g2242 (x : Prop) : Prop axiom g2243 (x : Prop) : Prop axiom g2244 (x : Prop) : Prop axiom g2245 (x : Prop) : Prop axiom g2246 (x : Prop) : Prop axiom g2247 (x : Prop) : Prop axiom g2248 (x : Prop) : Prop axiom g2249 (x : Prop) : Prop axiom g2250 (x : Prop) : Prop axiom g2251 (x : Prop) : Prop axiom g2252 (x : Prop) : Prop axiom g2253 (x : Prop) : Prop axiom g2254 (x : Prop) : Prop axiom g2255 (x : Prop) : Prop axiom g2256 (x : Prop) : Prop axiom g2257 (x : Prop) : Prop axiom g2258 (x : Prop) : Prop axiom g2259 (x : Prop) : Prop axiom g2260 (x : Prop) : Prop axiom g2261 (x : Prop) : Prop axiom g2262 (x : Prop) : Prop axiom g2263 (x : Prop) : Prop axiom g2264 (x : Prop) : Prop axiom g2265 (x : Prop) : Prop axiom g2266 (x : Prop) : Prop axiom g2267 (x : Prop) : Prop axiom g2268 (x : Prop) : Prop axiom g2269 (x : Prop) : Prop axiom g2270 (x : Prop) : Prop axiom g2271 (x : Prop) : Prop axiom g2272 (x : Prop) : Prop axiom g2273 (x : Prop) : Prop axiom g2274 (x : Prop) : Prop axiom g2275 (x : Prop) : Prop axiom g2276 (x : Prop) : Prop axiom g2277 (x : Prop) : Prop axiom g2278 (x : Prop) : Prop axiom g2279 (x : Prop) : Prop axiom g2280 (x : Prop) : Prop axiom g2281 (x : Prop) : Prop axiom g2282 (x : Prop) : Prop axiom g2283 (x : Prop) : Prop axiom g2284 (x : Prop) : Prop axiom g2285 (x : Prop) : Prop axiom g2286 (x : Prop) : Prop axiom g2287 (x : Prop) : Prop axiom g2288 (x : Prop) : Prop axiom g2289 (x : Prop) : Prop axiom g2290 (x : Prop) : Prop axiom g2291 (x : Prop) : Prop axiom g2292 (x : Prop) : Prop axiom g2293 (x : Prop) : Prop axiom g2294 (x : Prop) : Prop axiom g2295 (x : Prop) : Prop axiom g2296 (x : Prop) : Prop axiom g2297 (x : Prop) : Prop axiom g2298 (x : Prop) : Prop axiom g2299 (x : Prop) : Prop axiom g2300 (x : Prop) : Prop axiom g2301 (x : Prop) : Prop axiom g2302 (x : Prop) : Prop axiom g2303 (x : Prop) : Prop axiom g2304 (x : Prop) : Prop axiom g2305 (x : Prop) : Prop axiom g2306 (x : Prop) : Prop axiom g2307 (x : Prop) : Prop axiom g2308 (x : Prop) : Prop axiom g2309 (x : Prop) : Prop axiom g2310 (x : Prop) : Prop axiom g2311 (x : Prop) : Prop axiom g2312 (x : Prop) : Prop axiom g2313 (x : Prop) : Prop axiom g2314 (x : Prop) : Prop axiom g2315 (x : Prop) : Prop axiom g2316 (x : Prop) : Prop axiom g2317 (x : Prop) : Prop axiom g2318 (x : Prop) : Prop axiom g2319 (x : Prop) : Prop axiom g2320 (x : Prop) : Prop axiom g2321 (x : Prop) : Prop axiom g2322 (x : Prop) : Prop axiom g2323 (x : Prop) : Prop axiom g2324 (x : Prop) : Prop axiom g2325 (x : Prop) : Prop axiom g2326 (x : Prop) : Prop axiom g2327 (x : Prop) : Prop axiom g2328 (x : Prop) : Prop axiom g2329 (x : Prop) : Prop axiom g2330 (x : Prop) : Prop axiom g2331 (x : Prop) : Prop axiom g2332 (x : Prop) : Prop axiom g2333 (x : Prop) : Prop axiom g2334 (x : Prop) : Prop axiom g2335 (x : Prop) : Prop axiom g2336 (x : Prop) : Prop axiom g2337 (x : Prop) : Prop axiom g2338 (x : Prop) : Prop axiom g2339 (x : Prop) : Prop axiom g2340 (x : Prop) : Prop axiom g2341 (x : Prop) : Prop axiom g2342 (x : Prop) : Prop axiom g2343 (x : Prop) : Prop axiom g2344 (x : Prop) : Prop axiom g2345 (x : Prop) : Prop axiom g2346 (x : Prop) : Prop axiom g2347 (x : Prop) : Prop axiom g2348 (x : Prop) : Prop axiom g2349 (x : Prop) : Prop axiom g2350 (x : Prop) : Prop axiom g2351 (x : Prop) : Prop axiom g2352 (x : Prop) : Prop axiom g2353 (x : Prop) : Prop axiom g2354 (x : Prop) : Prop axiom g2355 (x : Prop) : Prop axiom g2356 (x : Prop) : Prop axiom g2357 (x : Prop) : Prop axiom g2358 (x : Prop) : Prop axiom g2359 (x : Prop) : Prop axiom g2360 (x : Prop) : Prop axiom g2361 (x : Prop) : Prop axiom g2362 (x : Prop) : Prop axiom g2363 (x : Prop) : Prop axiom g2364 (x : Prop) : Prop axiom g2365 (x : Prop) : Prop axiom g2366 (x : Prop) : Prop axiom g2367 (x : Prop) : Prop axiom g2368 (x : Prop) : Prop axiom g2369 (x : Prop) : Prop axiom g2370 (x : Prop) : Prop axiom g2371 (x : Prop) : Prop axiom g2372 (x : Prop) : Prop axiom g2373 (x : Prop) : Prop axiom g2374 (x : Prop) : Prop axiom g2375 (x : Prop) : Prop axiom g2376 (x : Prop) : Prop axiom g2377 (x : Prop) : Prop axiom g2378 (x : Prop) : Prop axiom g2379 (x : Prop) : Prop axiom g2380 (x : Prop) : Prop axiom g2381 (x : Prop) : Prop axiom g2382 (x : Prop) : Prop axiom g2383 (x : Prop) : Prop axiom g2384 (x : Prop) : Prop axiom g2385 (x : Prop) : Prop axiom g2386 (x : Prop) : Prop axiom g2387 (x : Prop) : Prop axiom g2388 (x : Prop) : Prop axiom g2389 (x : Prop) : Prop axiom g2390 (x : Prop) : Prop axiom g2391 (x : Prop) : Prop axiom g2392 (x : Prop) : Prop axiom g2393 (x : Prop) : Prop axiom g2394 (x : Prop) : Prop axiom g2395 (x : Prop) : Prop axiom g2396 (x : Prop) : Prop axiom g2397 (x : Prop) : Prop axiom g2398 (x : Prop) : Prop axiom g2399 (x : Prop) : Prop axiom g2400 (x : Prop) : Prop axiom g2401 (x : Prop) : Prop axiom g2402 (x : Prop) : Prop axiom g2403 (x : Prop) : Prop axiom g2404 (x : Prop) : Prop axiom g2405 (x : Prop) : Prop axiom g2406 (x : Prop) : Prop axiom g2407 (x : Prop) : Prop axiom g2408 (x : Prop) : Prop axiom g2409 (x : Prop) : Prop axiom g2410 (x : Prop) : Prop axiom g2411 (x : Prop) : Prop axiom g2412 (x : Prop) : Prop axiom g2413 (x : Prop) : Prop axiom g2414 (x : Prop) : Prop axiom g2415 (x : Prop) : Prop axiom g2416 (x : Prop) : Prop axiom g2417 (x : Prop) : Prop axiom g2418 (x : Prop) : Prop axiom g2419 (x : Prop) : Prop axiom g2420 (x : Prop) : Prop axiom g2421 (x : Prop) : Prop axiom g2422 (x : Prop) : Prop axiom g2423 (x : Prop) : Prop axiom g2424 (x : Prop) : Prop axiom g2425 (x : Prop) : Prop axiom g2426 (x : Prop) : Prop axiom g2427 (x : Prop) : Prop axiom g2428 (x : Prop) : Prop axiom g2429 (x : Prop) : Prop axiom g2430 (x : Prop) : Prop axiom g2431 (x : Prop) : Prop axiom g2432 (x : Prop) : Prop axiom g2433 (x : Prop) : Prop axiom g2434 (x : Prop) : Prop axiom g2435 (x : Prop) : Prop axiom g2436 (x : Prop) : Prop axiom g2437 (x : Prop) : Prop axiom g2438 (x : Prop) : Prop axiom g2439 (x : Prop) : Prop axiom g2440 (x : Prop) : Prop axiom g2441 (x : Prop) : Prop axiom g2442 (x : Prop) : Prop axiom g2443 (x : Prop) : Prop axiom g2444 (x : Prop) : Prop axiom g2445 (x : Prop) : Prop axiom g2446 (x : Prop) : Prop axiom g2447 (x : Prop) : Prop axiom g2448 (x : Prop) : Prop axiom g2449 (x : Prop) : Prop axiom g2450 (x : Prop) : Prop axiom g2451 (x : Prop) : Prop axiom g2452 (x : Prop) : Prop axiom g2453 (x : Prop) : Prop axiom g2454 (x : Prop) : Prop axiom g2455 (x : Prop) : Prop axiom g2456 (x : Prop) : Prop axiom g2457 (x : Prop) : Prop axiom g2458 (x : Prop) : Prop axiom g2459 (x : Prop) : Prop axiom g2460 (x : Prop) : Prop axiom g2461 (x : Prop) : Prop axiom g2462 (x : Prop) : Prop axiom g2463 (x : Prop) : Prop axiom g2464 (x : Prop) : Prop axiom g2465 (x : Prop) : Prop axiom g2466 (x : Prop) : Prop axiom g2467 (x : Prop) : Prop axiom g2468 (x : Prop) : Prop axiom g2469 (x : Prop) : Prop axiom g2470 (x : Prop) : Prop axiom g2471 (x : Prop) : Prop axiom g2472 (x : Prop) : Prop axiom g2473 (x : Prop) : Prop axiom g2474 (x : Prop) : Prop axiom g2475 (x : Prop) : Prop axiom g2476 (x : Prop) : Prop axiom g2477 (x : Prop) : Prop axiom g2478 (x : Prop) : Prop axiom g2479 (x : Prop) : Prop axiom g2480 (x : Prop) : Prop axiom g2481 (x : Prop) : Prop axiom g2482 (x : Prop) : Prop axiom g2483 (x : Prop) : Prop axiom g2484 (x : Prop) : Prop axiom g2485 (x : Prop) : Prop axiom g2486 (x : Prop) : Prop axiom g2487 (x : Prop) : Prop axiom g2488 (x : Prop) : Prop axiom g2489 (x : Prop) : Prop axiom g2490 (x : Prop) : Prop axiom g2491 (x : Prop) : Prop axiom g2492 (x : Prop) : Prop axiom g2493 (x : Prop) : Prop axiom g2494 (x : Prop) : Prop axiom g2495 (x : Prop) : Prop axiom g2496 (x : Prop) : Prop axiom g2497 (x : Prop) : Prop axiom g2498 (x : Prop) : Prop axiom g2499 (x : Prop) : Prop @[simp] axiom s0 (x : Prop) : f (g1 x) = f (g0 x) @[simp] axiom s1 (x : Prop) : f (g2 x) = f (g1 x) @[simp] axiom s2 (x : Prop) : f (g3 x) = f (g2 x) @[simp] axiom s3 (x : Prop) : f (g4 x) = f (g3 x) @[simp] axiom s4 (x : Prop) : f (g5 x) = f (g4 x) @[simp] axiom s5 (x : Prop) : f (g6 x) = f (g5 x) @[simp] axiom s6 (x : Prop) : f (g7 x) = f (g6 x) @[simp] axiom s7 (x : Prop) : f (g8 x) = f (g7 x) @[simp] axiom s8 (x : Prop) : f (g9 x) = f (g8 x) @[simp] axiom s9 (x : Prop) : f (g10 x) = f (g9 x) @[simp] axiom s10 (x : Prop) : f (g11 x) = f (g10 x) @[simp] axiom s11 (x : Prop) : f (g12 x) = f (g11 x) @[simp] axiom s12 (x : Prop) : f (g13 x) = f (g12 x) @[simp] axiom s13 (x : Prop) : f (g14 x) = f (g13 x) @[simp] axiom s14 (x : Prop) : f (g15 x) = f (g14 x) @[simp] axiom s15 (x : Prop) : f (g16 x) = f (g15 x) @[simp] axiom s16 (x : Prop) : f (g17 x) = f (g16 x) @[simp] axiom s17 (x : Prop) : f (g18 x) = f (g17 x) @[simp] axiom s18 (x : Prop) : f (g19 x) = f (g18 x) @[simp] axiom s19 (x : Prop) : f (g20 x) = f (g19 x) @[simp] axiom s20 (x : Prop) : f (g21 x) = f (g20 x) @[simp] axiom s21 (x : Prop) : f (g22 x) = f (g21 x) @[simp] axiom s22 (x : Prop) : f (g23 x) = f (g22 x) @[simp] axiom s23 (x : Prop) : f (g24 x) = f (g23 x) @[simp] axiom s24 (x : Prop) : f (g25 x) = f (g24 x) @[simp] axiom s25 (x : Prop) : f (g26 x) = f (g25 x) @[simp] axiom s26 (x : Prop) : f (g27 x) = f (g26 x) @[simp] axiom s27 (x : Prop) : f (g28 x) = f (g27 x) @[simp] axiom s28 (x : Prop) : f (g29 x) = f (g28 x) @[simp] axiom s29 (x : Prop) : f (g30 x) = f (g29 x) @[simp] axiom s30 (x : Prop) : f (g31 x) = f (g30 x) @[simp] axiom s31 (x : Prop) : f (g32 x) = f (g31 x) @[simp] axiom s32 (x : Prop) : f (g33 x) = f (g32 x) @[simp] axiom s33 (x : Prop) : f (g34 x) = f (g33 x) @[simp] axiom s34 (x : Prop) : f (g35 x) = f (g34 x) @[simp] axiom s35 (x : Prop) : f (g36 x) = f (g35 x) @[simp] axiom s36 (x : Prop) : f (g37 x) = f (g36 x) @[simp] axiom s37 (x : Prop) : f (g38 x) = f (g37 x) @[simp] axiom s38 (x : Prop) : f (g39 x) = f (g38 x) @[simp] axiom s39 (x : Prop) : f (g40 x) = f (g39 x) @[simp] axiom s40 (x : Prop) : f (g41 x) = f (g40 x) @[simp] axiom s41 (x : Prop) : f (g42 x) = f (g41 x) @[simp] axiom s42 (x : Prop) : f (g43 x) = f (g42 x) @[simp] axiom s43 (x : Prop) : f (g44 x) = f (g43 x) @[simp] axiom s44 (x : Prop) : f (g45 x) = f (g44 x) @[simp] axiom s45 (x : Prop) : f (g46 x) = f (g45 x) @[simp] axiom s46 (x : Prop) : f (g47 x) = f (g46 x) @[simp] axiom s47 (x : Prop) : f (g48 x) = f (g47 x) @[simp] axiom s48 (x : Prop) : f (g49 x) = f (g48 x) @[simp] axiom s49 (x : Prop) : f (g50 x) = f (g49 x) @[simp] axiom s50 (x : Prop) : f (g51 x) = f (g50 x) @[simp] axiom s51 (x : Prop) : f (g52 x) = f (g51 x) @[simp] axiom s52 (x : Prop) : f (g53 x) = f (g52 x) @[simp] axiom s53 (x : Prop) : f (g54 x) = f (g53 x) @[simp] axiom s54 (x : Prop) : f (g55 x) = f (g54 x) @[simp] axiom s55 (x : Prop) : f (g56 x) = f (g55 x) @[simp] axiom s56 (x : Prop) : f (g57 x) = f (g56 x) @[simp] axiom s57 (x : Prop) : f (g58 x) = f (g57 x) @[simp] axiom s58 (x : Prop) : f (g59 x) = f (g58 x) @[simp] axiom s59 (x : Prop) : f (g60 x) = f (g59 x) @[simp] axiom s60 (x : Prop) : f (g61 x) = f (g60 x) @[simp] axiom s61 (x : Prop) : f (g62 x) = f (g61 x) @[simp] axiom s62 (x : Prop) : f (g63 x) = f (g62 x) @[simp] axiom s63 (x : Prop) : f (g64 x) = f (g63 x) @[simp] axiom s64 (x : Prop) : f (g65 x) = f (g64 x) @[simp] axiom s65 (x : Prop) : f (g66 x) = f (g65 x) @[simp] axiom s66 (x : Prop) : f (g67 x) = f (g66 x) @[simp] axiom s67 (x : Prop) : f (g68 x) = f (g67 x) @[simp] axiom s68 (x : Prop) : f (g69 x) = f (g68 x) @[simp] axiom s69 (x : Prop) : f (g70 x) = f (g69 x) @[simp] axiom s70 (x : Prop) : f (g71 x) = f (g70 x) @[simp] axiom s71 (x : Prop) : f (g72 x) = f (g71 x) @[simp] axiom s72 (x : Prop) : f (g73 x) = f (g72 x) @[simp] axiom s73 (x : Prop) : f (g74 x) = f (g73 x) @[simp] axiom s74 (x : Prop) : f (g75 x) = f (g74 x) @[simp] axiom s75 (x : Prop) : f (g76 x) = f (g75 x) @[simp] axiom s76 (x : Prop) : f (g77 x) = f (g76 x) @[simp] axiom s77 (x : Prop) : f (g78 x) = f (g77 x) @[simp] axiom s78 (x : Prop) : f (g79 x) = f (g78 x) @[simp] axiom s79 (x : Prop) : f (g80 x) = f (g79 x) @[simp] axiom s80 (x : Prop) : f (g81 x) = f (g80 x) @[simp] axiom s81 (x : Prop) : f (g82 x) = f (g81 x) @[simp] axiom s82 (x : Prop) : f (g83 x) = f (g82 x) @[simp] axiom s83 (x : Prop) : f (g84 x) = f (g83 x) @[simp] axiom s84 (x : Prop) : f (g85 x) = f (g84 x) @[simp] axiom s85 (x : Prop) : f (g86 x) = f (g85 x) @[simp] axiom s86 (x : Prop) : f (g87 x) = f (g86 x) @[simp] axiom s87 (x : Prop) : f (g88 x) = f (g87 x) @[simp] axiom s88 (x : Prop) : f (g89 x) = f (g88 x) @[simp] axiom s89 (x : Prop) : f (g90 x) = f (g89 x) @[simp] axiom s90 (x : Prop) : f (g91 x) = f (g90 x) @[simp] axiom s91 (x : Prop) : f (g92 x) = f (g91 x) @[simp] axiom s92 (x : Prop) : f (g93 x) = f (g92 x) @[simp] axiom s93 (x : Prop) : f (g94 x) = f (g93 x) @[simp] axiom s94 (x : Prop) : f (g95 x) = f (g94 x) @[simp] axiom s95 (x : Prop) : f (g96 x) = f (g95 x) @[simp] axiom s96 (x : Prop) : f (g97 x) = f (g96 x) @[simp] axiom s97 (x : Prop) : f (g98 x) = f (g97 x) @[simp] axiom s98 (x : Prop) : f (g99 x) = f (g98 x) @[simp] axiom s99 (x : Prop) : f (g100 x) = f (g99 x) @[simp] axiom s100 (x : Prop) : f (g101 x) = f (g100 x) @[simp] axiom s101 (x : Prop) : f (g102 x) = f (g101 x) @[simp] axiom s102 (x : Prop) : f (g103 x) = f (g102 x) @[simp] axiom s103 (x : Prop) : f (g104 x) = f (g103 x) @[simp] axiom s104 (x : Prop) : f (g105 x) = f (g104 x) @[simp] axiom s105 (x : Prop) : f (g106 x) = f (g105 x) @[simp] axiom s106 (x : Prop) : f (g107 x) = f (g106 x) @[simp] axiom s107 (x : Prop) : f (g108 x) = f (g107 x) @[simp] axiom s108 (x : Prop) : f (g109 x) = f (g108 x) @[simp] axiom s109 (x : Prop) : f (g110 x) = f (g109 x) @[simp] axiom s110 (x : Prop) : f (g111 x) = f (g110 x) @[simp] axiom s111 (x : Prop) : f (g112 x) = f (g111 x) @[simp] axiom s112 (x : Prop) : f (g113 x) = f (g112 x) @[simp] axiom s113 (x : Prop) : f (g114 x) = f (g113 x) @[simp] axiom s114 (x : Prop) : f (g115 x) = f (g114 x) @[simp] axiom s115 (x : Prop) : f (g116 x) = f (g115 x) @[simp] axiom s116 (x : Prop) : f (g117 x) = f (g116 x) @[simp] axiom s117 (x : Prop) : f (g118 x) = f (g117 x) @[simp] axiom s118 (x : Prop) : f (g119 x) = f (g118 x) @[simp] axiom s119 (x : Prop) : f (g120 x) = f (g119 x) @[simp] axiom s120 (x : Prop) : f (g121 x) = f (g120 x) @[simp] axiom s121 (x : Prop) : f (g122 x) = f (g121 x) @[simp] axiom s122 (x : Prop) : f (g123 x) = f (g122 x) @[simp] axiom s123 (x : Prop) : f (g124 x) = f (g123 x) @[simp] axiom s124 (x : Prop) : f (g125 x) = f (g124 x) @[simp] axiom s125 (x : Prop) : f (g126 x) = f (g125 x) @[simp] axiom s126 (x : Prop) : f (g127 x) = f (g126 x) @[simp] axiom s127 (x : Prop) : f (g128 x) = f (g127 x) @[simp] axiom s128 (x : Prop) : f (g129 x) = f (g128 x) @[simp] axiom s129 (x : Prop) : f (g130 x) = f (g129 x) @[simp] axiom s130 (x : Prop) : f (g131 x) = f (g130 x) @[simp] axiom s131 (x : Prop) : f (g132 x) = f (g131 x) @[simp] axiom s132 (x : Prop) : f (g133 x) = f (g132 x) @[simp] axiom s133 (x : Prop) : f (g134 x) = f (g133 x) @[simp] axiom s134 (x : Prop) : f (g135 x) = f (g134 x) @[simp] axiom s135 (x : Prop) : f (g136 x) = f (g135 x) @[simp] axiom s136 (x : Prop) : f (g137 x) = f (g136 x) @[simp] axiom s137 (x : Prop) : f (g138 x) = f (g137 x) @[simp] axiom s138 (x : Prop) : f (g139 x) = f (g138 x) @[simp] axiom s139 (x : Prop) : f (g140 x) = f (g139 x) @[simp] axiom s140 (x : Prop) : f (g141 x) = f (g140 x) @[simp] axiom s141 (x : Prop) : f (g142 x) = f (g141 x) @[simp] axiom s142 (x : Prop) : f (g143 x) = f (g142 x) @[simp] axiom s143 (x : Prop) : f (g144 x) = f (g143 x) @[simp] axiom s144 (x : Prop) : f (g145 x) = f (g144 x) @[simp] axiom s145 (x : Prop) : f (g146 x) = f (g145 x) @[simp] axiom s146 (x : Prop) : f (g147 x) = f (g146 x) @[simp] axiom s147 (x : Prop) : f (g148 x) = f (g147 x) @[simp] axiom s148 (x : Prop) : f (g149 x) = f (g148 x) @[simp] axiom s149 (x : Prop) : f (g150 x) = f (g149 x) @[simp] axiom s150 (x : Prop) : f (g151 x) = f (g150 x) @[simp] axiom s151 (x : Prop) : f (g152 x) = f (g151 x) @[simp] axiom s152 (x : Prop) : f (g153 x) = f (g152 x) @[simp] axiom s153 (x : Prop) : f (g154 x) = f (g153 x) @[simp] axiom s154 (x : Prop) : f (g155 x) = f (g154 x) @[simp] axiom s155 (x : Prop) : f (g156 x) = f (g155 x) @[simp] axiom s156 (x : Prop) : f (g157 x) = f (g156 x) @[simp] axiom s157 (x : Prop) : f (g158 x) = f (g157 x) @[simp] axiom s158 (x : Prop) : f (g159 x) = f (g158 x) @[simp] axiom s159 (x : Prop) : f (g160 x) = f (g159 x) @[simp] axiom s160 (x : Prop) : f (g161 x) = f (g160 x) @[simp] axiom s161 (x : Prop) : f (g162 x) = f (g161 x) @[simp] axiom s162 (x : Prop) : f (g163 x) = f (g162 x) @[simp] axiom s163 (x : Prop) : f (g164 x) = f (g163 x) @[simp] axiom s164 (x : Prop) : f (g165 x) = f (g164 x) @[simp] axiom s165 (x : Prop) : f (g166 x) = f (g165 x) @[simp] axiom s166 (x : Prop) : f (g167 x) = f (g166 x) @[simp] axiom s167 (x : Prop) : f (g168 x) = f (g167 x) @[simp] axiom s168 (x : Prop) : f (g169 x) = f (g168 x) @[simp] axiom s169 (x : Prop) : f (g170 x) = f (g169 x) @[simp] axiom s170 (x : Prop) : f (g171 x) = f (g170 x) @[simp] axiom s171 (x : Prop) : f (g172 x) = f (g171 x) @[simp] axiom s172 (x : Prop) : f (g173 x) = f (g172 x) @[simp] axiom s173 (x : Prop) : f (g174 x) = f (g173 x) @[simp] axiom s174 (x : Prop) : f (g175 x) = f (g174 x) @[simp] axiom s175 (x : Prop) : f (g176 x) = f (g175 x) @[simp] axiom s176 (x : Prop) : f (g177 x) = f (g176 x) @[simp] axiom s177 (x : Prop) : f (g178 x) = f (g177 x) @[simp] axiom s178 (x : Prop) : f (g179 x) = f (g178 x) @[simp] axiom s179 (x : Prop) : f (g180 x) = f (g179 x) @[simp] axiom s180 (x : Prop) : f (g181 x) = f (g180 x) @[simp] axiom s181 (x : Prop) : f (g182 x) = f (g181 x) @[simp] axiom s182 (x : Prop) : f (g183 x) = f (g182 x) @[simp] axiom s183 (x : Prop) : f (g184 x) = f (g183 x) @[simp] axiom s184 (x : Prop) : f (g185 x) = f (g184 x) @[simp] axiom s185 (x : Prop) : f (g186 x) = f (g185 x) @[simp] axiom s186 (x : Prop) : f (g187 x) = f (g186 x) @[simp] axiom s187 (x : Prop) : f (g188 x) = f (g187 x) @[simp] axiom s188 (x : Prop) : f (g189 x) = f (g188 x) @[simp] axiom s189 (x : Prop) : f (g190 x) = f (g189 x) @[simp] axiom s190 (x : Prop) : f (g191 x) = f (g190 x) @[simp] axiom s191 (x : Prop) : f (g192 x) = f (g191 x) @[simp] axiom s192 (x : Prop) : f (g193 x) = f (g192 x) @[simp] axiom s193 (x : Prop) : f (g194 x) = f (g193 x) @[simp] axiom s194 (x : Prop) : f (g195 x) = f (g194 x) @[simp] axiom s195 (x : Prop) : f (g196 x) = f (g195 x) @[simp] axiom s196 (x : Prop) : f (g197 x) = f (g196 x) @[simp] axiom s197 (x : Prop) : f (g198 x) = f (g197 x) @[simp] axiom s198 (x : Prop) : f (g199 x) = f (g198 x) @[simp] axiom s199 (x : Prop) : f (g200 x) = f (g199 x) @[simp] axiom s200 (x : Prop) : f (g201 x) = f (g200 x) @[simp] axiom s201 (x : Prop) : f (g202 x) = f (g201 x) @[simp] axiom s202 (x : Prop) : f (g203 x) = f (g202 x) @[simp] axiom s203 (x : Prop) : f (g204 x) = f (g203 x) @[simp] axiom s204 (x : Prop) : f (g205 x) = f (g204 x) @[simp] axiom s205 (x : Prop) : f (g206 x) = f (g205 x) @[simp] axiom s206 (x : Prop) : f (g207 x) = f (g206 x) @[simp] axiom s207 (x : Prop) : f (g208 x) = f (g207 x) @[simp] axiom s208 (x : Prop) : f (g209 x) = f (g208 x) @[simp] axiom s209 (x : Prop) : f (g210 x) = f (g209 x) @[simp] axiom s210 (x : Prop) : f (g211 x) = f (g210 x) @[simp] axiom s211 (x : Prop) : f (g212 x) = f (g211 x) @[simp] axiom s212 (x : Prop) : f (g213 x) = f (g212 x) @[simp] axiom s213 (x : Prop) : f (g214 x) = f (g213 x) @[simp] axiom s214 (x : Prop) : f (g215 x) = f (g214 x) @[simp] axiom s215 (x : Prop) : f (g216 x) = f (g215 x) @[simp] axiom s216 (x : Prop) : f (g217 x) = f (g216 x) @[simp] axiom s217 (x : Prop) : f (g218 x) = f (g217 x) @[simp] axiom s218 (x : Prop) : f (g219 x) = f (g218 x) @[simp] axiom s219 (x : Prop) : f (g220 x) = f (g219 x) @[simp] axiom s220 (x : Prop) : f (g221 x) = f (g220 x) @[simp] axiom s221 (x : Prop) : f (g222 x) = f (g221 x) @[simp] axiom s222 (x : Prop) : f (g223 x) = f (g222 x) @[simp] axiom s223 (x : Prop) : f (g224 x) = f (g223 x) @[simp] axiom s224 (x : Prop) : f (g225 x) = f (g224 x) @[simp] axiom s225 (x : Prop) : f (g226 x) = f (g225 x) @[simp] axiom s226 (x : Prop) : f (g227 x) = f (g226 x) @[simp] axiom s227 (x : Prop) : f (g228 x) = f (g227 x) @[simp] axiom s228 (x : Prop) : f (g229 x) = f (g228 x) @[simp] axiom s229 (x : Prop) : f (g230 x) = f (g229 x) @[simp] axiom s230 (x : Prop) : f (g231 x) = f (g230 x) @[simp] axiom s231 (x : Prop) : f (g232 x) = f (g231 x) @[simp] axiom s232 (x : Prop) : f (g233 x) = f (g232 x) @[simp] axiom s233 (x : Prop) : f (g234 x) = f (g233 x) @[simp] axiom s234 (x : Prop) : f (g235 x) = f (g234 x) @[simp] axiom s235 (x : Prop) : f (g236 x) = f (g235 x) @[simp] axiom s236 (x : Prop) : f (g237 x) = f (g236 x) @[simp] axiom s237 (x : Prop) : f (g238 x) = f (g237 x) @[simp] axiom s238 (x : Prop) : f (g239 x) = f (g238 x) @[simp] axiom s239 (x : Prop) : f (g240 x) = f (g239 x) @[simp] axiom s240 (x : Prop) : f (g241 x) = f (g240 x) @[simp] axiom s241 (x : Prop) : f (g242 x) = f (g241 x) @[simp] axiom s242 (x : Prop) : f (g243 x) = f (g242 x) @[simp] axiom s243 (x : Prop) : f (g244 x) = f (g243 x) @[simp] axiom s244 (x : Prop) : f (g245 x) = f (g244 x) @[simp] axiom s245 (x : Prop) : f (g246 x) = f (g245 x) @[simp] axiom s246 (x : Prop) : f (g247 x) = f (g246 x) @[simp] axiom s247 (x : Prop) : f (g248 x) = f (g247 x) @[simp] axiom s248 (x : Prop) : f (g249 x) = f (g248 x) @[simp] axiom s249 (x : Prop) : f (g250 x) = f (g249 x) @[simp] axiom s250 (x : Prop) : f (g251 x) = f (g250 x) @[simp] axiom s251 (x : Prop) : f (g252 x) = f (g251 x) @[simp] axiom s252 (x : Prop) : f (g253 x) = f (g252 x) @[simp] axiom s253 (x : Prop) : f (g254 x) = f (g253 x) @[simp] axiom s254 (x : Prop) : f (g255 x) = f (g254 x) @[simp] axiom s255 (x : Prop) : f (g256 x) = f (g255 x) @[simp] axiom s256 (x : Prop) : f (g257 x) = f (g256 x) @[simp] axiom s257 (x : Prop) : f (g258 x) = f (g257 x) @[simp] axiom s258 (x : Prop) : f (g259 x) = f (g258 x) @[simp] axiom s259 (x : Prop) : f (g260 x) = f (g259 x) @[simp] axiom s260 (x : Prop) : f (g261 x) = f (g260 x) @[simp] axiom s261 (x : Prop) : f (g262 x) = f (g261 x) @[simp] axiom s262 (x : Prop) : f (g263 x) = f (g262 x) @[simp] axiom s263 (x : Prop) : f (g264 x) = f (g263 x) @[simp] axiom s264 (x : Prop) : f (g265 x) = f (g264 x) @[simp] axiom s265 (x : Prop) : f (g266 x) = f (g265 x) @[simp] axiom s266 (x : Prop) : f (g267 x) = f (g266 x) @[simp] axiom s267 (x : Prop) : f (g268 x) = f (g267 x) @[simp] axiom s268 (x : Prop) : f (g269 x) = f (g268 x) @[simp] axiom s269 (x : Prop) : f (g270 x) = f (g269 x) @[simp] axiom s270 (x : Prop) : f (g271 x) = f (g270 x) @[simp] axiom s271 (x : Prop) : f (g272 x) = f (g271 x) @[simp] axiom s272 (x : Prop) : f (g273 x) = f (g272 x) @[simp] axiom s273 (x : Prop) : f (g274 x) = f (g273 x) @[simp] axiom s274 (x : Prop) : f (g275 x) = f (g274 x) @[simp] axiom s275 (x : Prop) : f (g276 x) = f (g275 x) @[simp] axiom s276 (x : Prop) : f (g277 x) = f (g276 x) @[simp] axiom s277 (x : Prop) : f (g278 x) = f (g277 x) @[simp] axiom s278 (x : Prop) : f (g279 x) = f (g278 x) @[simp] axiom s279 (x : Prop) : f (g280 x) = f (g279 x) @[simp] axiom s280 (x : Prop) : f (g281 x) = f (g280 x) @[simp] axiom s281 (x : Prop) : f (g282 x) = f (g281 x) @[simp] axiom s282 (x : Prop) : f (g283 x) = f (g282 x) @[simp] axiom s283 (x : Prop) : f (g284 x) = f (g283 x) @[simp] axiom s284 (x : Prop) : f (g285 x) = f (g284 x) @[simp] axiom s285 (x : Prop) : f (g286 x) = f (g285 x) @[simp] axiom s286 (x : Prop) : f (g287 x) = f (g286 x) @[simp] axiom s287 (x : Prop) : f (g288 x) = f (g287 x) @[simp] axiom s288 (x : Prop) : f (g289 x) = f (g288 x) @[simp] axiom s289 (x : Prop) : f (g290 x) = f (g289 x) @[simp] axiom s290 (x : Prop) : f (g291 x) = f (g290 x) @[simp] axiom s291 (x : Prop) : f (g292 x) = f (g291 x) @[simp] axiom s292 (x : Prop) : f (g293 x) = f (g292 x) @[simp] axiom s293 (x : Prop) : f (g294 x) = f (g293 x) @[simp] axiom s294 (x : Prop) : f (g295 x) = f (g294 x) @[simp] axiom s295 (x : Prop) : f (g296 x) = f (g295 x) @[simp] axiom s296 (x : Prop) : f (g297 x) = f (g296 x) @[simp] axiom s297 (x : Prop) : f (g298 x) = f (g297 x) @[simp] axiom s298 (x : Prop) : f (g299 x) = f (g298 x) @[simp] axiom s299 (x : Prop) : f (g300 x) = f (g299 x) @[simp] axiom s300 (x : Prop) : f (g301 x) = f (g300 x) @[simp] axiom s301 (x : Prop) : f (g302 x) = f (g301 x) @[simp] axiom s302 (x : Prop) : f (g303 x) = f (g302 x) @[simp] axiom s303 (x : Prop) : f (g304 x) = f (g303 x) @[simp] axiom s304 (x : Prop) : f (g305 x) = f (g304 x) @[simp] axiom s305 (x : Prop) : f (g306 x) = f (g305 x) @[simp] axiom s306 (x : Prop) : f (g307 x) = f (g306 x) @[simp] axiom s307 (x : Prop) : f (g308 x) = f (g307 x) @[simp] axiom s308 (x : Prop) : f (g309 x) = f (g308 x) @[simp] axiom s309 (x : Prop) : f (g310 x) = f (g309 x) @[simp] axiom s310 (x : Prop) : f (g311 x) = f (g310 x) @[simp] axiom s311 (x : Prop) : f (g312 x) = f (g311 x) @[simp] axiom s312 (x : Prop) : f (g313 x) = f (g312 x) @[simp] axiom s313 (x : Prop) : f (g314 x) = f (g313 x) @[simp] axiom s314 (x : Prop) : f (g315 x) = f (g314 x) @[simp] axiom s315 (x : Prop) : f (g316 x) = f (g315 x) @[simp] axiom s316 (x : Prop) : f (g317 x) = f (g316 x) @[simp] axiom s317 (x : Prop) : f (g318 x) = f (g317 x) @[simp] axiom s318 (x : Prop) : f (g319 x) = f (g318 x) @[simp] axiom s319 (x : Prop) : f (g320 x) = f (g319 x) @[simp] axiom s320 (x : Prop) : f (g321 x) = f (g320 x) @[simp] axiom s321 (x : Prop) : f (g322 x) = f (g321 x) @[simp] axiom s322 (x : Prop) : f (g323 x) = f (g322 x) @[simp] axiom s323 (x : Prop) : f (g324 x) = f (g323 x) @[simp] axiom s324 (x : Prop) : f (g325 x) = f (g324 x) @[simp] axiom s325 (x : Prop) : f (g326 x) = f (g325 x) @[simp] axiom s326 (x : Prop) : f (g327 x) = f (g326 x) @[simp] axiom s327 (x : Prop) : f (g328 x) = f (g327 x) @[simp] axiom s328 (x : Prop) : f (g329 x) = f (g328 x) @[simp] axiom s329 (x : Prop) : f (g330 x) = f (g329 x) @[simp] axiom s330 (x : Prop) : f (g331 x) = f (g330 x) @[simp] axiom s331 (x : Prop) : f (g332 x) = f (g331 x) @[simp] axiom s332 (x : Prop) : f (g333 x) = f (g332 x) @[simp] axiom s333 (x : Prop) : f (g334 x) = f (g333 x) @[simp] axiom s334 (x : Prop) : f (g335 x) = f (g334 x) @[simp] axiom s335 (x : Prop) : f (g336 x) = f (g335 x) @[simp] axiom s336 (x : Prop) : f (g337 x) = f (g336 x) @[simp] axiom s337 (x : Prop) : f (g338 x) = f (g337 x) @[simp] axiom s338 (x : Prop) : f (g339 x) = f (g338 x) @[simp] axiom s339 (x : Prop) : f (g340 x) = f (g339 x) @[simp] axiom s340 (x : Prop) : f (g341 x) = f (g340 x) @[simp] axiom s341 (x : Prop) : f (g342 x) = f (g341 x) @[simp] axiom s342 (x : Prop) : f (g343 x) = f (g342 x) @[simp] axiom s343 (x : Prop) : f (g344 x) = f (g343 x) @[simp] axiom s344 (x : Prop) : f (g345 x) = f (g344 x) @[simp] axiom s345 (x : Prop) : f (g346 x) = f (g345 x) @[simp] axiom s346 (x : Prop) : f (g347 x) = f (g346 x) @[simp] axiom s347 (x : Prop) : f (g348 x) = f (g347 x) @[simp] axiom s348 (x : Prop) : f (g349 x) = f (g348 x) @[simp] axiom s349 (x : Prop) : f (g350 x) = f (g349 x) @[simp] axiom s350 (x : Prop) : f (g351 x) = f (g350 x) @[simp] axiom s351 (x : Prop) : f (g352 x) = f (g351 x) @[simp] axiom s352 (x : Prop) : f (g353 x) = f (g352 x) @[simp] axiom s353 (x : Prop) : f (g354 x) = f (g353 x) @[simp] axiom s354 (x : Prop) : f (g355 x) = f (g354 x) @[simp] axiom s355 (x : Prop) : f (g356 x) = f (g355 x) @[simp] axiom s356 (x : Prop) : f (g357 x) = f (g356 x) @[simp] axiom s357 (x : Prop) : f (g358 x) = f (g357 x) @[simp] axiom s358 (x : Prop) : f (g359 x) = f (g358 x) @[simp] axiom s359 (x : Prop) : f (g360 x) = f (g359 x) @[simp] axiom s360 (x : Prop) : f (g361 x) = f (g360 x) @[simp] axiom s361 (x : Prop) : f (g362 x) = f (g361 x) @[simp] axiom s362 (x : Prop) : f (g363 x) = f (g362 x) @[simp] axiom s363 (x : Prop) : f (g364 x) = f (g363 x) @[simp] axiom s364 (x : Prop) : f (g365 x) = f (g364 x) @[simp] axiom s365 (x : Prop) : f (g366 x) = f (g365 x) @[simp] axiom s366 (x : Prop) : f (g367 x) = f (g366 x) @[simp] axiom s367 (x : Prop) : f (g368 x) = f (g367 x) @[simp] axiom s368 (x : Prop) : f (g369 x) = f (g368 x) @[simp] axiom s369 (x : Prop) : f (g370 x) = f (g369 x) @[simp] axiom s370 (x : Prop) : f (g371 x) = f (g370 x) @[simp] axiom s371 (x : Prop) : f (g372 x) = f (g371 x) @[simp] axiom s372 (x : Prop) : f (g373 x) = f (g372 x) @[simp] axiom s373 (x : Prop) : f (g374 x) = f (g373 x) @[simp] axiom s374 (x : Prop) : f (g375 x) = f (g374 x) @[simp] axiom s375 (x : Prop) : f (g376 x) = f (g375 x) @[simp] axiom s376 (x : Prop) : f (g377 x) = f (g376 x) @[simp] axiom s377 (x : Prop) : f (g378 x) = f (g377 x) @[simp] axiom s378 (x : Prop) : f (g379 x) = f (g378 x) @[simp] axiom s379 (x : Prop) : f (g380 x) = f (g379 x) @[simp] axiom s380 (x : Prop) : f (g381 x) = f (g380 x) @[simp] axiom s381 (x : Prop) : f (g382 x) = f (g381 x) @[simp] axiom s382 (x : Prop) : f (g383 x) = f (g382 x) @[simp] axiom s383 (x : Prop) : f (g384 x) = f (g383 x) @[simp] axiom s384 (x : Prop) : f (g385 x) = f (g384 x) @[simp] axiom s385 (x : Prop) : f (g386 x) = f (g385 x) @[simp] axiom s386 (x : Prop) : f (g387 x) = f (g386 x) @[simp] axiom s387 (x : Prop) : f (g388 x) = f (g387 x) @[simp] axiom s388 (x : Prop) : f (g389 x) = f (g388 x) @[simp] axiom s389 (x : Prop) : f (g390 x) = f (g389 x) @[simp] axiom s390 (x : Prop) : f (g391 x) = f (g390 x) @[simp] axiom s391 (x : Prop) : f (g392 x) = f (g391 x) @[simp] axiom s392 (x : Prop) : f (g393 x) = f (g392 x) @[simp] axiom s393 (x : Prop) : f (g394 x) = f (g393 x) @[simp] axiom s394 (x : Prop) : f (g395 x) = f (g394 x) @[simp] axiom s395 (x : Prop) : f (g396 x) = f (g395 x) @[simp] axiom s396 (x : Prop) : f (g397 x) = f (g396 x) @[simp] axiom s397 (x : Prop) : f (g398 x) = f (g397 x) @[simp] axiom s398 (x : Prop) : f (g399 x) = f (g398 x) @[simp] axiom s399 (x : Prop) : f (g400 x) = f (g399 x) @[simp] axiom s400 (x : Prop) : f (g401 x) = f (g400 x) @[simp] axiom s401 (x : Prop) : f (g402 x) = f (g401 x) @[simp] axiom s402 (x : Prop) : f (g403 x) = f (g402 x) @[simp] axiom s403 (x : Prop) : f (g404 x) = f (g403 x) @[simp] axiom s404 (x : Prop) : f (g405 x) = f (g404 x) @[simp] axiom s405 (x : Prop) : f (g406 x) = f (g405 x) @[simp] axiom s406 (x : Prop) : f (g407 x) = f (g406 x) @[simp] axiom s407 (x : Prop) : f (g408 x) = f (g407 x) @[simp] axiom s408 (x : Prop) : f (g409 x) = f (g408 x) @[simp] axiom s409 (x : Prop) : f (g410 x) = f (g409 x) @[simp] axiom s410 (x : Prop) : f (g411 x) = f (g410 x) @[simp] axiom s411 (x : Prop) : f (g412 x) = f (g411 x) @[simp] axiom s412 (x : Prop) : f (g413 x) = f (g412 x) @[simp] axiom s413 (x : Prop) : f (g414 x) = f (g413 x) @[simp] axiom s414 (x : Prop) : f (g415 x) = f (g414 x) @[simp] axiom s415 (x : Prop) : f (g416 x) = f (g415 x) @[simp] axiom s416 (x : Prop) : f (g417 x) = f (g416 x) @[simp] axiom s417 (x : Prop) : f (g418 x) = f (g417 x) @[simp] axiom s418 (x : Prop) : f (g419 x) = f (g418 x) @[simp] axiom s419 (x : Prop) : f (g420 x) = f (g419 x) @[simp] axiom s420 (x : Prop) : f (g421 x) = f (g420 x) @[simp] axiom s421 (x : Prop) : f (g422 x) = f (g421 x) @[simp] axiom s422 (x : Prop) : f (g423 x) = f (g422 x) @[simp] axiom s423 (x : Prop) : f (g424 x) = f (g423 x) @[simp] axiom s424 (x : Prop) : f (g425 x) = f (g424 x) @[simp] axiom s425 (x : Prop) : f (g426 x) = f (g425 x) @[simp] axiom s426 (x : Prop) : f (g427 x) = f (g426 x) @[simp] axiom s427 (x : Prop) : f (g428 x) = f (g427 x) @[simp] axiom s428 (x : Prop) : f (g429 x) = f (g428 x) @[simp] axiom s429 (x : Prop) : f (g430 x) = f (g429 x) @[simp] axiom s430 (x : Prop) : f (g431 x) = f (g430 x) @[simp] axiom s431 (x : Prop) : f (g432 x) = f (g431 x) @[simp] axiom s432 (x : Prop) : f (g433 x) = f (g432 x) @[simp] axiom s433 (x : Prop) : f (g434 x) = f (g433 x) @[simp] axiom s434 (x : Prop) : f (g435 x) = f (g434 x) @[simp] axiom s435 (x : Prop) : f (g436 x) = f (g435 x) @[simp] axiom s436 (x : Prop) : f (g437 x) = f (g436 x) @[simp] axiom s437 (x : Prop) : f (g438 x) = f (g437 x) @[simp] axiom s438 (x : Prop) : f (g439 x) = f (g438 x) @[simp] axiom s439 (x : Prop) : f (g440 x) = f (g439 x) @[simp] axiom s440 (x : Prop) : f (g441 x) = f (g440 x) @[simp] axiom s441 (x : Prop) : f (g442 x) = f (g441 x) @[simp] axiom s442 (x : Prop) : f (g443 x) = f (g442 x) @[simp] axiom s443 (x : Prop) : f (g444 x) = f (g443 x) @[simp] axiom s444 (x : Prop) : f (g445 x) = f (g444 x) @[simp] axiom s445 (x : Prop) : f (g446 x) = f (g445 x) @[simp] axiom s446 (x : Prop) : f (g447 x) = f (g446 x) @[simp] axiom s447 (x : Prop) : f (g448 x) = f (g447 x) @[simp] axiom s448 (x : Prop) : f (g449 x) = f (g448 x) @[simp] axiom s449 (x : Prop) : f (g450 x) = f (g449 x) @[simp] axiom s450 (x : Prop) : f (g451 x) = f (g450 x) @[simp] axiom s451 (x : Prop) : f (g452 x) = f (g451 x) @[simp] axiom s452 (x : Prop) : f (g453 x) = f (g452 x) @[simp] axiom s453 (x : Prop) : f (g454 x) = f (g453 x) @[simp] axiom s454 (x : Prop) : f (g455 x) = f (g454 x) @[simp] axiom s455 (x : Prop) : f (g456 x) = f (g455 x) @[simp] axiom s456 (x : Prop) : f (g457 x) = f (g456 x) @[simp] axiom s457 (x : Prop) : f (g458 x) = f (g457 x) @[simp] axiom s458 (x : Prop) : f (g459 x) = f (g458 x) @[simp] axiom s459 (x : Prop) : f (g460 x) = f (g459 x) @[simp] axiom s460 (x : Prop) : f (g461 x) = f (g460 x) @[simp] axiom s461 (x : Prop) : f (g462 x) = f (g461 x) @[simp] axiom s462 (x : Prop) : f (g463 x) = f (g462 x) @[simp] axiom s463 (x : Prop) : f (g464 x) = f (g463 x) @[simp] axiom s464 (x : Prop) : f (g465 x) = f (g464 x) @[simp] axiom s465 (x : Prop) : f (g466 x) = f (g465 x) @[simp] axiom s466 (x : Prop) : f (g467 x) = f (g466 x) @[simp] axiom s467 (x : Prop) : f (g468 x) = f (g467 x) @[simp] axiom s468 (x : Prop) : f (g469 x) = f (g468 x) @[simp] axiom s469 (x : Prop) : f (g470 x) = f (g469 x) @[simp] axiom s470 (x : Prop) : f (g471 x) = f (g470 x) @[simp] axiom s471 (x : Prop) : f (g472 x) = f (g471 x) @[simp] axiom s472 (x : Prop) : f (g473 x) = f (g472 x) @[simp] axiom s473 (x : Prop) : f (g474 x) = f (g473 x) @[simp] axiom s474 (x : Prop) : f (g475 x) = f (g474 x) @[simp] axiom s475 (x : Prop) : f (g476 x) = f (g475 x) @[simp] axiom s476 (x : Prop) : f (g477 x) = f (g476 x) @[simp] axiom s477 (x : Prop) : f (g478 x) = f (g477 x) @[simp] axiom s478 (x : Prop) : f (g479 x) = f (g478 x) @[simp] axiom s479 (x : Prop) : f (g480 x) = f (g479 x) @[simp] axiom s480 (x : Prop) : f (g481 x) = f (g480 x) @[simp] axiom s481 (x : Prop) : f (g482 x) = f (g481 x) @[simp] axiom s482 (x : Prop) : f (g483 x) = f (g482 x) @[simp] axiom s483 (x : Prop) : f (g484 x) = f (g483 x) @[simp] axiom s484 (x : Prop) : f (g485 x) = f (g484 x) @[simp] axiom s485 (x : Prop) : f (g486 x) = f (g485 x) @[simp] axiom s486 (x : Prop) : f (g487 x) = f (g486 x) @[simp] axiom s487 (x : Prop) : f (g488 x) = f (g487 x) @[simp] axiom s488 (x : Prop) : f (g489 x) = f (g488 x) @[simp] axiom s489 (x : Prop) : f (g490 x) = f (g489 x) @[simp] axiom s490 (x : Prop) : f (g491 x) = f (g490 x) @[simp] axiom s491 (x : Prop) : f (g492 x) = f (g491 x) @[simp] axiom s492 (x : Prop) : f (g493 x) = f (g492 x) @[simp] axiom s493 (x : Prop) : f (g494 x) = f (g493 x) @[simp] axiom s494 (x : Prop) : f (g495 x) = f (g494 x) @[simp] axiom s495 (x : Prop) : f (g496 x) = f (g495 x) @[simp] axiom s496 (x : Prop) : f (g497 x) = f (g496 x) @[simp] axiom s497 (x : Prop) : f (g498 x) = f (g497 x) @[simp] axiom s498 (x : Prop) : f (g499 x) = f (g498 x) @[simp] axiom s499 (x : Prop) : f (g500 x) = f (g499 x) @[simp] axiom s500 (x : Prop) : f (g501 x) = f (g500 x) @[simp] axiom s501 (x : Prop) : f (g502 x) = f (g501 x) @[simp] axiom s502 (x : Prop) : f (g503 x) = f (g502 x) @[simp] axiom s503 (x : Prop) : f (g504 x) = f (g503 x) @[simp] axiom s504 (x : Prop) : f (g505 x) = f (g504 x) @[simp] axiom s505 (x : Prop) : f (g506 x) = f (g505 x) @[simp] axiom s506 (x : Prop) : f (g507 x) = f (g506 x) @[simp] axiom s507 (x : Prop) : f (g508 x) = f (g507 x) @[simp] axiom s508 (x : Prop) : f (g509 x) = f (g508 x) @[simp] axiom s509 (x : Prop) : f (g510 x) = f (g509 x) @[simp] axiom s510 (x : Prop) : f (g511 x) = f (g510 x) @[simp] axiom s511 (x : Prop) : f (g512 x) = f (g511 x) @[simp] axiom s512 (x : Prop) : f (g513 x) = f (g512 x) @[simp] axiom s513 (x : Prop) : f (g514 x) = f (g513 x) @[simp] axiom s514 (x : Prop) : f (g515 x) = f (g514 x) @[simp] axiom s515 (x : Prop) : f (g516 x) = f (g515 x) @[simp] axiom s516 (x : Prop) : f (g517 x) = f (g516 x) @[simp] axiom s517 (x : Prop) : f (g518 x) = f (g517 x) @[simp] axiom s518 (x : Prop) : f (g519 x) = f (g518 x) @[simp] axiom s519 (x : Prop) : f (g520 x) = f (g519 x) @[simp] axiom s520 (x : Prop) : f (g521 x) = f (g520 x) @[simp] axiom s521 (x : Prop) : f (g522 x) = f (g521 x) @[simp] axiom s522 (x : Prop) : f (g523 x) = f (g522 x) @[simp] axiom s523 (x : Prop) : f (g524 x) = f (g523 x) @[simp] axiom s524 (x : Prop) : f (g525 x) = f (g524 x) @[simp] axiom s525 (x : Prop) : f (g526 x) = f (g525 x) @[simp] axiom s526 (x : Prop) : f (g527 x) = f (g526 x) @[simp] axiom s527 (x : Prop) : f (g528 x) = f (g527 x) @[simp] axiom s528 (x : Prop) : f (g529 x) = f (g528 x) @[simp] axiom s529 (x : Prop) : f (g530 x) = f (g529 x) @[simp] axiom s530 (x : Prop) : f (g531 x) = f (g530 x) @[simp] axiom s531 (x : Prop) : f (g532 x) = f (g531 x) @[simp] axiom s532 (x : Prop) : f (g533 x) = f (g532 x) @[simp] axiom s533 (x : Prop) : f (g534 x) = f (g533 x) @[simp] axiom s534 (x : Prop) : f (g535 x) = f (g534 x) @[simp] axiom s535 (x : Prop) : f (g536 x) = f (g535 x) @[simp] axiom s536 (x : Prop) : f (g537 x) = f (g536 x) @[simp] axiom s537 (x : Prop) : f (g538 x) = f (g537 x) @[simp] axiom s538 (x : Prop) : f (g539 x) = f (g538 x) @[simp] axiom s539 (x : Prop) : f (g540 x) = f (g539 x) @[simp] axiom s540 (x : Prop) : f (g541 x) = f (g540 x) @[simp] axiom s541 (x : Prop) : f (g542 x) = f (g541 x) @[simp] axiom s542 (x : Prop) : f (g543 x) = f (g542 x) @[simp] axiom s543 (x : Prop) : f (g544 x) = f (g543 x) @[simp] axiom s544 (x : Prop) : f (g545 x) = f (g544 x) @[simp] axiom s545 (x : Prop) : f (g546 x) = f (g545 x) @[simp] axiom s546 (x : Prop) : f (g547 x) = f (g546 x) @[simp] axiom s547 (x : Prop) : f (g548 x) = f (g547 x) @[simp] axiom s548 (x : Prop) : f (g549 x) = f (g548 x) @[simp] axiom s549 (x : Prop) : f (g550 x) = f (g549 x) @[simp] axiom s550 (x : Prop) : f (g551 x) = f (g550 x) @[simp] axiom s551 (x : Prop) : f (g552 x) = f (g551 x) @[simp] axiom s552 (x : Prop) : f (g553 x) = f (g552 x) @[simp] axiom s553 (x : Prop) : f (g554 x) = f (g553 x) @[simp] axiom s554 (x : Prop) : f (g555 x) = f (g554 x) @[simp] axiom s555 (x : Prop) : f (g556 x) = f (g555 x) @[simp] axiom s556 (x : Prop) : f (g557 x) = f (g556 x) @[simp] axiom s557 (x : Prop) : f (g558 x) = f (g557 x) @[simp] axiom s558 (x : Prop) : f (g559 x) = f (g558 x) @[simp] axiom s559 (x : Prop) : f (g560 x) = f (g559 x) @[simp] axiom s560 (x : Prop) : f (g561 x) = f (g560 x) @[simp] axiom s561 (x : Prop) : f (g562 x) = f (g561 x) @[simp] axiom s562 (x : Prop) : f (g563 x) = f (g562 x) @[simp] axiom s563 (x : Prop) : f (g564 x) = f (g563 x) @[simp] axiom s564 (x : Prop) : f (g565 x) = f (g564 x) @[simp] axiom s565 (x : Prop) : f (g566 x) = f (g565 x) @[simp] axiom s566 (x : Prop) : f (g567 x) = f (g566 x) @[simp] axiom s567 (x : Prop) : f (g568 x) = f (g567 x) @[simp] axiom s568 (x : Prop) : f (g569 x) = f (g568 x) @[simp] axiom s569 (x : Prop) : f (g570 x) = f (g569 x) @[simp] axiom s570 (x : Prop) : f (g571 x) = f (g570 x) @[simp] axiom s571 (x : Prop) : f (g572 x) = f (g571 x) @[simp] axiom s572 (x : Prop) : f (g573 x) = f (g572 x) @[simp] axiom s573 (x : Prop) : f (g574 x) = f (g573 x) @[simp] axiom s574 (x : Prop) : f (g575 x) = f (g574 x) @[simp] axiom s575 (x : Prop) : f (g576 x) = f (g575 x) @[simp] axiom s576 (x : Prop) : f (g577 x) = f (g576 x) @[simp] axiom s577 (x : Prop) : f (g578 x) = f (g577 x) @[simp] axiom s578 (x : Prop) : f (g579 x) = f (g578 x) @[simp] axiom s579 (x : Prop) : f (g580 x) = f (g579 x) @[simp] axiom s580 (x : Prop) : f (g581 x) = f (g580 x) @[simp] axiom s581 (x : Prop) : f (g582 x) = f (g581 x) @[simp] axiom s582 (x : Prop) : f (g583 x) = f (g582 x) @[simp] axiom s583 (x : Prop) : f (g584 x) = f (g583 x) @[simp] axiom s584 (x : Prop) : f (g585 x) = f (g584 x) @[simp] axiom s585 (x : Prop) : f (g586 x) = f (g585 x) @[simp] axiom s586 (x : Prop) : f (g587 x) = f (g586 x) @[simp] axiom s587 (x : Prop) : f (g588 x) = f (g587 x) @[simp] axiom s588 (x : Prop) : f (g589 x) = f (g588 x) @[simp] axiom s589 (x : Prop) : f (g590 x) = f (g589 x) @[simp] axiom s590 (x : Prop) : f (g591 x) = f (g590 x) @[simp] axiom s591 (x : Prop) : f (g592 x) = f (g591 x) @[simp] axiom s592 (x : Prop) : f (g593 x) = f (g592 x) @[simp] axiom s593 (x : Prop) : f (g594 x) = f (g593 x) @[simp] axiom s594 (x : Prop) : f (g595 x) = f (g594 x) @[simp] axiom s595 (x : Prop) : f (g596 x) = f (g595 x) @[simp] axiom s596 (x : Prop) : f (g597 x) = f (g596 x) @[simp] axiom s597 (x : Prop) : f (g598 x) = f (g597 x) @[simp] axiom s598 (x : Prop) : f (g599 x) = f (g598 x) @[simp] axiom s599 (x : Prop) : f (g600 x) = f (g599 x) @[simp] axiom s600 (x : Prop) : f (g601 x) = f (g600 x) @[simp] axiom s601 (x : Prop) : f (g602 x) = f (g601 x) @[simp] axiom s602 (x : Prop) : f (g603 x) = f (g602 x) @[simp] axiom s603 (x : Prop) : f (g604 x) = f (g603 x) @[simp] axiom s604 (x : Prop) : f (g605 x) = f (g604 x) @[simp] axiom s605 (x : Prop) : f (g606 x) = f (g605 x) @[simp] axiom s606 (x : Prop) : f (g607 x) = f (g606 x) @[simp] axiom s607 (x : Prop) : f (g608 x) = f (g607 x) @[simp] axiom s608 (x : Prop) : f (g609 x) = f (g608 x) @[simp] axiom s609 (x : Prop) : f (g610 x) = f (g609 x) @[simp] axiom s610 (x : Prop) : f (g611 x) = f (g610 x) @[simp] axiom s611 (x : Prop) : f (g612 x) = f (g611 x) @[simp] axiom s612 (x : Prop) : f (g613 x) = f (g612 x) @[simp] axiom s613 (x : Prop) : f (g614 x) = f (g613 x) @[simp] axiom s614 (x : Prop) : f (g615 x) = f (g614 x) @[simp] axiom s615 (x : Prop) : f (g616 x) = f (g615 x) @[simp] axiom s616 (x : Prop) : f (g617 x) = f (g616 x) @[simp] axiom s617 (x : Prop) : f (g618 x) = f (g617 x) @[simp] axiom s618 (x : Prop) : f (g619 x) = f (g618 x) @[simp] axiom s619 (x : Prop) : f (g620 x) = f (g619 x) @[simp] axiom s620 (x : Prop) : f (g621 x) = f (g620 x) @[simp] axiom s621 (x : Prop) : f (g622 x) = f (g621 x) @[simp] axiom s622 (x : Prop) : f (g623 x) = f (g622 x) @[simp] axiom s623 (x : Prop) : f (g624 x) = f (g623 x) @[simp] axiom s624 (x : Prop) : f (g625 x) = f (g624 x) @[simp] axiom s625 (x : Prop) : f (g626 x) = f (g625 x) @[simp] axiom s626 (x : Prop) : f (g627 x) = f (g626 x) @[simp] axiom s627 (x : Prop) : f (g628 x) = f (g627 x) @[simp] axiom s628 (x : Prop) : f (g629 x) = f (g628 x) @[simp] axiom s629 (x : Prop) : f (g630 x) = f (g629 x) @[simp] axiom s630 (x : Prop) : f (g631 x) = f (g630 x) @[simp] axiom s631 (x : Prop) : f (g632 x) = f (g631 x) @[simp] axiom s632 (x : Prop) : f (g633 x) = f (g632 x) @[simp] axiom s633 (x : Prop) : f (g634 x) = f (g633 x) @[simp] axiom s634 (x : Prop) : f (g635 x) = f (g634 x) @[simp] axiom s635 (x : Prop) : f (g636 x) = f (g635 x) @[simp] axiom s636 (x : Prop) : f (g637 x) = f (g636 x) @[simp] axiom s637 (x : Prop) : f (g638 x) = f (g637 x) @[simp] axiom s638 (x : Prop) : f (g639 x) = f (g638 x) @[simp] axiom s639 (x : Prop) : f (g640 x) = f (g639 x) @[simp] axiom s640 (x : Prop) : f (g641 x) = f (g640 x) @[simp] axiom s641 (x : Prop) : f (g642 x) = f (g641 x) @[simp] axiom s642 (x : Prop) : f (g643 x) = f (g642 x) @[simp] axiom s643 (x : Prop) : f (g644 x) = f (g643 x) @[simp] axiom s644 (x : Prop) : f (g645 x) = f (g644 x) @[simp] axiom s645 (x : Prop) : f (g646 x) = f (g645 x) @[simp] axiom s646 (x : Prop) : f (g647 x) = f (g646 x) @[simp] axiom s647 (x : Prop) : f (g648 x) = f (g647 x) @[simp] axiom s648 (x : Prop) : f (g649 x) = f (g648 x) @[simp] axiom s649 (x : Prop) : f (g650 x) = f (g649 x) @[simp] axiom s650 (x : Prop) : f (g651 x) = f (g650 x) @[simp] axiom s651 (x : Prop) : f (g652 x) = f (g651 x) @[simp] axiom s652 (x : Prop) : f (g653 x) = f (g652 x) @[simp] axiom s653 (x : Prop) : f (g654 x) = f (g653 x) @[simp] axiom s654 (x : Prop) : f (g655 x) = f (g654 x) @[simp] axiom s655 (x : Prop) : f (g656 x) = f (g655 x) @[simp] axiom s656 (x : Prop) : f (g657 x) = f (g656 x) @[simp] axiom s657 (x : Prop) : f (g658 x) = f (g657 x) @[simp] axiom s658 (x : Prop) : f (g659 x) = f (g658 x) @[simp] axiom s659 (x : Prop) : f (g660 x) = f (g659 x) @[simp] axiom s660 (x : Prop) : f (g661 x) = f (g660 x) @[simp] axiom s661 (x : Prop) : f (g662 x) = f (g661 x) @[simp] axiom s662 (x : Prop) : f (g663 x) = f (g662 x) @[simp] axiom s663 (x : Prop) : f (g664 x) = f (g663 x) @[simp] axiom s664 (x : Prop) : f (g665 x) = f (g664 x) @[simp] axiom s665 (x : Prop) : f (g666 x) = f (g665 x) @[simp] axiom s666 (x : Prop) : f (g667 x) = f (g666 x) @[simp] axiom s667 (x : Prop) : f (g668 x) = f (g667 x) @[simp] axiom s668 (x : Prop) : f (g669 x) = f (g668 x) @[simp] axiom s669 (x : Prop) : f (g670 x) = f (g669 x) @[simp] axiom s670 (x : Prop) : f (g671 x) = f (g670 x) @[simp] axiom s671 (x : Prop) : f (g672 x) = f (g671 x) @[simp] axiom s672 (x : Prop) : f (g673 x) = f (g672 x) @[simp] axiom s673 (x : Prop) : f (g674 x) = f (g673 x) @[simp] axiom s674 (x : Prop) : f (g675 x) = f (g674 x) @[simp] axiom s675 (x : Prop) : f (g676 x) = f (g675 x) @[simp] axiom s676 (x : Prop) : f (g677 x) = f (g676 x) @[simp] axiom s677 (x : Prop) : f (g678 x) = f (g677 x) @[simp] axiom s678 (x : Prop) : f (g679 x) = f (g678 x) @[simp] axiom s679 (x : Prop) : f (g680 x) = f (g679 x) @[simp] axiom s680 (x : Prop) : f (g681 x) = f (g680 x) @[simp] axiom s681 (x : Prop) : f (g682 x) = f (g681 x) @[simp] axiom s682 (x : Prop) : f (g683 x) = f (g682 x) @[simp] axiom s683 (x : Prop) : f (g684 x) = f (g683 x) @[simp] axiom s684 (x : Prop) : f (g685 x) = f (g684 x) @[simp] axiom s685 (x : Prop) : f (g686 x) = f (g685 x) @[simp] axiom s686 (x : Prop) : f (g687 x) = f (g686 x) @[simp] axiom s687 (x : Prop) : f (g688 x) = f (g687 x) @[simp] axiom s688 (x : Prop) : f (g689 x) = f (g688 x) @[simp] axiom s689 (x : Prop) : f (g690 x) = f (g689 x) @[simp] axiom s690 (x : Prop) : f (g691 x) = f (g690 x) @[simp] axiom s691 (x : Prop) : f (g692 x) = f (g691 x) @[simp] axiom s692 (x : Prop) : f (g693 x) = f (g692 x) @[simp] axiom s693 (x : Prop) : f (g694 x) = f (g693 x) @[simp] axiom s694 (x : Prop) : f (g695 x) = f (g694 x) @[simp] axiom s695 (x : Prop) : f (g696 x) = f (g695 x) @[simp] axiom s696 (x : Prop) : f (g697 x) = f (g696 x) @[simp] axiom s697 (x : Prop) : f (g698 x) = f (g697 x) @[simp] axiom s698 (x : Prop) : f (g699 x) = f (g698 x) @[simp] axiom s699 (x : Prop) : f (g700 x) = f (g699 x) @[simp] axiom s700 (x : Prop) : f (g701 x) = f (g700 x) @[simp] axiom s701 (x : Prop) : f (g702 x) = f (g701 x) @[simp] axiom s702 (x : Prop) : f (g703 x) = f (g702 x) @[simp] axiom s703 (x : Prop) : f (g704 x) = f (g703 x) @[simp] axiom s704 (x : Prop) : f (g705 x) = f (g704 x) @[simp] axiom s705 (x : Prop) : f (g706 x) = f (g705 x) @[simp] axiom s706 (x : Prop) : f (g707 x) = f (g706 x) @[simp] axiom s707 (x : Prop) : f (g708 x) = f (g707 x) @[simp] axiom s708 (x : Prop) : f (g709 x) = f (g708 x) @[simp] axiom s709 (x : Prop) : f (g710 x) = f (g709 x) @[simp] axiom s710 (x : Prop) : f (g711 x) = f (g710 x) @[simp] axiom s711 (x : Prop) : f (g712 x) = f (g711 x) @[simp] axiom s712 (x : Prop) : f (g713 x) = f (g712 x) @[simp] axiom s713 (x : Prop) : f (g714 x) = f (g713 x) @[simp] axiom s714 (x : Prop) : f (g715 x) = f (g714 x) @[simp] axiom s715 (x : Prop) : f (g716 x) = f (g715 x) @[simp] axiom s716 (x : Prop) : f (g717 x) = f (g716 x) @[simp] axiom s717 (x : Prop) : f (g718 x) = f (g717 x) @[simp] axiom s718 (x : Prop) : f (g719 x) = f (g718 x) @[simp] axiom s719 (x : Prop) : f (g720 x) = f (g719 x) @[simp] axiom s720 (x : Prop) : f (g721 x) = f (g720 x) @[simp] axiom s721 (x : Prop) : f (g722 x) = f (g721 x) @[simp] axiom s722 (x : Prop) : f (g723 x) = f (g722 x) @[simp] axiom s723 (x : Prop) : f (g724 x) = f (g723 x) @[simp] axiom s724 (x : Prop) : f (g725 x) = f (g724 x) @[simp] axiom s725 (x : Prop) : f (g726 x) = f (g725 x) @[simp] axiom s726 (x : Prop) : f (g727 x) = f (g726 x) @[simp] axiom s727 (x : Prop) : f (g728 x) = f (g727 x) @[simp] axiom s728 (x : Prop) : f (g729 x) = f (g728 x) @[simp] axiom s729 (x : Prop) : f (g730 x) = f (g729 x) @[simp] axiom s730 (x : Prop) : f (g731 x) = f (g730 x) @[simp] axiom s731 (x : Prop) : f (g732 x) = f (g731 x) @[simp] axiom s732 (x : Prop) : f (g733 x) = f (g732 x) @[simp] axiom s733 (x : Prop) : f (g734 x) = f (g733 x) @[simp] axiom s734 (x : Prop) : f (g735 x) = f (g734 x) @[simp] axiom s735 (x : Prop) : f (g736 x) = f (g735 x) @[simp] axiom s736 (x : Prop) : f (g737 x) = f (g736 x) @[simp] axiom s737 (x : Prop) : f (g738 x) = f (g737 x) @[simp] axiom s738 (x : Prop) : f (g739 x) = f (g738 x) @[simp] axiom s739 (x : Prop) : f (g740 x) = f (g739 x) @[simp] axiom s740 (x : Prop) : f (g741 x) = f (g740 x) @[simp] axiom s741 (x : Prop) : f (g742 x) = f (g741 x) @[simp] axiom s742 (x : Prop) : f (g743 x) = f (g742 x) @[simp] axiom s743 (x : Prop) : f (g744 x) = f (g743 x) @[simp] axiom s744 (x : Prop) : f (g745 x) = f (g744 x) @[simp] axiom s745 (x : Prop) : f (g746 x) = f (g745 x) @[simp] axiom s746 (x : Prop) : f (g747 x) = f (g746 x) @[simp] axiom s747 (x : Prop) : f (g748 x) = f (g747 x) @[simp] axiom s748 (x : Prop) : f (g749 x) = f (g748 x) @[simp] axiom s749 (x : Prop) : f (g750 x) = f (g749 x) @[simp] axiom s750 (x : Prop) : f (g751 x) = f (g750 x) @[simp] axiom s751 (x : Prop) : f (g752 x) = f (g751 x) @[simp] axiom s752 (x : Prop) : f (g753 x) = f (g752 x) @[simp] axiom s753 (x : Prop) : f (g754 x) = f (g753 x) @[simp] axiom s754 (x : Prop) : f (g755 x) = f (g754 x) @[simp] axiom s755 (x : Prop) : f (g756 x) = f (g755 x) @[simp] axiom s756 (x : Prop) : f (g757 x) = f (g756 x) @[simp] axiom s757 (x : Prop) : f (g758 x) = f (g757 x) @[simp] axiom s758 (x : Prop) : f (g759 x) = f (g758 x) @[simp] axiom s759 (x : Prop) : f (g760 x) = f (g759 x) @[simp] axiom s760 (x : Prop) : f (g761 x) = f (g760 x) @[simp] axiom s761 (x : Prop) : f (g762 x) = f (g761 x) @[simp] axiom s762 (x : Prop) : f (g763 x) = f (g762 x) @[simp] axiom s763 (x : Prop) : f (g764 x) = f (g763 x) @[simp] axiom s764 (x : Prop) : f (g765 x) = f (g764 x) @[simp] axiom s765 (x : Prop) : f (g766 x) = f (g765 x) @[simp] axiom s766 (x : Prop) : f (g767 x) = f (g766 x) @[simp] axiom s767 (x : Prop) : f (g768 x) = f (g767 x) @[simp] axiom s768 (x : Prop) : f (g769 x) = f (g768 x) @[simp] axiom s769 (x : Prop) : f (g770 x) = f (g769 x) @[simp] axiom s770 (x : Prop) : f (g771 x) = f (g770 x) @[simp] axiom s771 (x : Prop) : f (g772 x) = f (g771 x) @[simp] axiom s772 (x : Prop) : f (g773 x) = f (g772 x) @[simp] axiom s773 (x : Prop) : f (g774 x) = f (g773 x) @[simp] axiom s774 (x : Prop) : f (g775 x) = f (g774 x) @[simp] axiom s775 (x : Prop) : f (g776 x) = f (g775 x) @[simp] axiom s776 (x : Prop) : f (g777 x) = f (g776 x) @[simp] axiom s777 (x : Prop) : f (g778 x) = f (g777 x) @[simp] axiom s778 (x : Prop) : f (g779 x) = f (g778 x) @[simp] axiom s779 (x : Prop) : f (g780 x) = f (g779 x) @[simp] axiom s780 (x : Prop) : f (g781 x) = f (g780 x) @[simp] axiom s781 (x : Prop) : f (g782 x) = f (g781 x) @[simp] axiom s782 (x : Prop) : f (g783 x) = f (g782 x) @[simp] axiom s783 (x : Prop) : f (g784 x) = f (g783 x) @[simp] axiom s784 (x : Prop) : f (g785 x) = f (g784 x) @[simp] axiom s785 (x : Prop) : f (g786 x) = f (g785 x) @[simp] axiom s786 (x : Prop) : f (g787 x) = f (g786 x) @[simp] axiom s787 (x : Prop) : f (g788 x) = f (g787 x) @[simp] axiom s788 (x : Prop) : f (g789 x) = f (g788 x) @[simp] axiom s789 (x : Prop) : f (g790 x) = f (g789 x) @[simp] axiom s790 (x : Prop) : f (g791 x) = f (g790 x) @[simp] axiom s791 (x : Prop) : f (g792 x) = f (g791 x) @[simp] axiom s792 (x : Prop) : f (g793 x) = f (g792 x) @[simp] axiom s793 (x : Prop) : f (g794 x) = f (g793 x) @[simp] axiom s794 (x : Prop) : f (g795 x) = f (g794 x) @[simp] axiom s795 (x : Prop) : f (g796 x) = f (g795 x) @[simp] axiom s796 (x : Prop) : f (g797 x) = f (g796 x) @[simp] axiom s797 (x : Prop) : f (g798 x) = f (g797 x) @[simp] axiom s798 (x : Prop) : f (g799 x) = f (g798 x) @[simp] axiom s799 (x : Prop) : f (g800 x) = f (g799 x) @[simp] axiom s800 (x : Prop) : f (g801 x) = f (g800 x) @[simp] axiom s801 (x : Prop) : f (g802 x) = f (g801 x) @[simp] axiom s802 (x : Prop) : f (g803 x) = f (g802 x) @[simp] axiom s803 (x : Prop) : f (g804 x) = f (g803 x) @[simp] axiom s804 (x : Prop) : f (g805 x) = f (g804 x) @[simp] axiom s805 (x : Prop) : f (g806 x) = f (g805 x) @[simp] axiom s806 (x : Prop) : f (g807 x) = f (g806 x) @[simp] axiom s807 (x : Prop) : f (g808 x) = f (g807 x) @[simp] axiom s808 (x : Prop) : f (g809 x) = f (g808 x) @[simp] axiom s809 (x : Prop) : f (g810 x) = f (g809 x) @[simp] axiom s810 (x : Prop) : f (g811 x) = f (g810 x) @[simp] axiom s811 (x : Prop) : f (g812 x) = f (g811 x) @[simp] axiom s812 (x : Prop) : f (g813 x) = f (g812 x) @[simp] axiom s813 (x : Prop) : f (g814 x) = f (g813 x) @[simp] axiom s814 (x : Prop) : f (g815 x) = f (g814 x) @[simp] axiom s815 (x : Prop) : f (g816 x) = f (g815 x) @[simp] axiom s816 (x : Prop) : f (g817 x) = f (g816 x) @[simp] axiom s817 (x : Prop) : f (g818 x) = f (g817 x) @[simp] axiom s818 (x : Prop) : f (g819 x) = f (g818 x) @[simp] axiom s819 (x : Prop) : f (g820 x) = f (g819 x) @[simp] axiom s820 (x : Prop) : f (g821 x) = f (g820 x) @[simp] axiom s821 (x : Prop) : f (g822 x) = f (g821 x) @[simp] axiom s822 (x : Prop) : f (g823 x) = f (g822 x) @[simp] axiom s823 (x : Prop) : f (g824 x) = f (g823 x) @[simp] axiom s824 (x : Prop) : f (g825 x) = f (g824 x) @[simp] axiom s825 (x : Prop) : f (g826 x) = f (g825 x) @[simp] axiom s826 (x : Prop) : f (g827 x) = f (g826 x) @[simp] axiom s827 (x : Prop) : f (g828 x) = f (g827 x) @[simp] axiom s828 (x : Prop) : f (g829 x) = f (g828 x) @[simp] axiom s829 (x : Prop) : f (g830 x) = f (g829 x) @[simp] axiom s830 (x : Prop) : f (g831 x) = f (g830 x) @[simp] axiom s831 (x : Prop) : f (g832 x) = f (g831 x) @[simp] axiom s832 (x : Prop) : f (g833 x) = f (g832 x) @[simp] axiom s833 (x : Prop) : f (g834 x) = f (g833 x) @[simp] axiom s834 (x : Prop) : f (g835 x) = f (g834 x) @[simp] axiom s835 (x : Prop) : f (g836 x) = f (g835 x) @[simp] axiom s836 (x : Prop) : f (g837 x) = f (g836 x) @[simp] axiom s837 (x : Prop) : f (g838 x) = f (g837 x) @[simp] axiom s838 (x : Prop) : f (g839 x) = f (g838 x) @[simp] axiom s839 (x : Prop) : f (g840 x) = f (g839 x) @[simp] axiom s840 (x : Prop) : f (g841 x) = f (g840 x) @[simp] axiom s841 (x : Prop) : f (g842 x) = f (g841 x) @[simp] axiom s842 (x : Prop) : f (g843 x) = f (g842 x) @[simp] axiom s843 (x : Prop) : f (g844 x) = f (g843 x) @[simp] axiom s844 (x : Prop) : f (g845 x) = f (g844 x) @[simp] axiom s845 (x : Prop) : f (g846 x) = f (g845 x) @[simp] axiom s846 (x : Prop) : f (g847 x) = f (g846 x) @[simp] axiom s847 (x : Prop) : f (g848 x) = f (g847 x) @[simp] axiom s848 (x : Prop) : f (g849 x) = f (g848 x) @[simp] axiom s849 (x : Prop) : f (g850 x) = f (g849 x) @[simp] axiom s850 (x : Prop) : f (g851 x) = f (g850 x) @[simp] axiom s851 (x : Prop) : f (g852 x) = f (g851 x) @[simp] axiom s852 (x : Prop) : f (g853 x) = f (g852 x) @[simp] axiom s853 (x : Prop) : f (g854 x) = f (g853 x) @[simp] axiom s854 (x : Prop) : f (g855 x) = f (g854 x) @[simp] axiom s855 (x : Prop) : f (g856 x) = f (g855 x) @[simp] axiom s856 (x : Prop) : f (g857 x) = f (g856 x) @[simp] axiom s857 (x : Prop) : f (g858 x) = f (g857 x) @[simp] axiom s858 (x : Prop) : f (g859 x) = f (g858 x) @[simp] axiom s859 (x : Prop) : f (g860 x) = f (g859 x) @[simp] axiom s860 (x : Prop) : f (g861 x) = f (g860 x) @[simp] axiom s861 (x : Prop) : f (g862 x) = f (g861 x) @[simp] axiom s862 (x : Prop) : f (g863 x) = f (g862 x) @[simp] axiom s863 (x : Prop) : f (g864 x) = f (g863 x) @[simp] axiom s864 (x : Prop) : f (g865 x) = f (g864 x) @[simp] axiom s865 (x : Prop) : f (g866 x) = f (g865 x) @[simp] axiom s866 (x : Prop) : f (g867 x) = f (g866 x) @[simp] axiom s867 (x : Prop) : f (g868 x) = f (g867 x) @[simp] axiom s868 (x : Prop) : f (g869 x) = f (g868 x) @[simp] axiom s869 (x : Prop) : f (g870 x) = f (g869 x) @[simp] axiom s870 (x : Prop) : f (g871 x) = f (g870 x) @[simp] axiom s871 (x : Prop) : f (g872 x) = f (g871 x) @[simp] axiom s872 (x : Prop) : f (g873 x) = f (g872 x) @[simp] axiom s873 (x : Prop) : f (g874 x) = f (g873 x) @[simp] axiom s874 (x : Prop) : f (g875 x) = f (g874 x) @[simp] axiom s875 (x : Prop) : f (g876 x) = f (g875 x) @[simp] axiom s876 (x : Prop) : f (g877 x) = f (g876 x) @[simp] axiom s877 (x : Prop) : f (g878 x) = f (g877 x) @[simp] axiom s878 (x : Prop) : f (g879 x) = f (g878 x) @[simp] axiom s879 (x : Prop) : f (g880 x) = f (g879 x) @[simp] axiom s880 (x : Prop) : f (g881 x) = f (g880 x) @[simp] axiom s881 (x : Prop) : f (g882 x) = f (g881 x) @[simp] axiom s882 (x : Prop) : f (g883 x) = f (g882 x) @[simp] axiom s883 (x : Prop) : f (g884 x) = f (g883 x) @[simp] axiom s884 (x : Prop) : f (g885 x) = f (g884 x) @[simp] axiom s885 (x : Prop) : f (g886 x) = f (g885 x) @[simp] axiom s886 (x : Prop) : f (g887 x) = f (g886 x) @[simp] axiom s887 (x : Prop) : f (g888 x) = f (g887 x) @[simp] axiom s888 (x : Prop) : f (g889 x) = f (g888 x) @[simp] axiom s889 (x : Prop) : f (g890 x) = f (g889 x) @[simp] axiom s890 (x : Prop) : f (g891 x) = f (g890 x) @[simp] axiom s891 (x : Prop) : f (g892 x) = f (g891 x) @[simp] axiom s892 (x : Prop) : f (g893 x) = f (g892 x) @[simp] axiom s893 (x : Prop) : f (g894 x) = f (g893 x) @[simp] axiom s894 (x : Prop) : f (g895 x) = f (g894 x) @[simp] axiom s895 (x : Prop) : f (g896 x) = f (g895 x) @[simp] axiom s896 (x : Prop) : f (g897 x) = f (g896 x) @[simp] axiom s897 (x : Prop) : f (g898 x) = f (g897 x) @[simp] axiom s898 (x : Prop) : f (g899 x) = f (g898 x) @[simp] axiom s899 (x : Prop) : f (g900 x) = f (g899 x) @[simp] axiom s900 (x : Prop) : f (g901 x) = f (g900 x) @[simp] axiom s901 (x : Prop) : f (g902 x) = f (g901 x) @[simp] axiom s902 (x : Prop) : f (g903 x) = f (g902 x) @[simp] axiom s903 (x : Prop) : f (g904 x) = f (g903 x) @[simp] axiom s904 (x : Prop) : f (g905 x) = f (g904 x) @[simp] axiom s905 (x : Prop) : f (g906 x) = f (g905 x) @[simp] axiom s906 (x : Prop) : f (g907 x) = f (g906 x) @[simp] axiom s907 (x : Prop) : f (g908 x) = f (g907 x) @[simp] axiom s908 (x : Prop) : f (g909 x) = f (g908 x) @[simp] axiom s909 (x : Prop) : f (g910 x) = f (g909 x) @[simp] axiom s910 (x : Prop) : f (g911 x) = f (g910 x) @[simp] axiom s911 (x : Prop) : f (g912 x) = f (g911 x) @[simp] axiom s912 (x : Prop) : f (g913 x) = f (g912 x) @[simp] axiom s913 (x : Prop) : f (g914 x) = f (g913 x) @[simp] axiom s914 (x : Prop) : f (g915 x) = f (g914 x) @[simp] axiom s915 (x : Prop) : f (g916 x) = f (g915 x) @[simp] axiom s916 (x : Prop) : f (g917 x) = f (g916 x) @[simp] axiom s917 (x : Prop) : f (g918 x) = f (g917 x) @[simp] axiom s918 (x : Prop) : f (g919 x) = f (g918 x) @[simp] axiom s919 (x : Prop) : f (g920 x) = f (g919 x) @[simp] axiom s920 (x : Prop) : f (g921 x) = f (g920 x) @[simp] axiom s921 (x : Prop) : f (g922 x) = f (g921 x) @[simp] axiom s922 (x : Prop) : f (g923 x) = f (g922 x) @[simp] axiom s923 (x : Prop) : f (g924 x) = f (g923 x) @[simp] axiom s924 (x : Prop) : f (g925 x) = f (g924 x) @[simp] axiom s925 (x : Prop) : f (g926 x) = f (g925 x) @[simp] axiom s926 (x : Prop) : f (g927 x) = f (g926 x) @[simp] axiom s927 (x : Prop) : f (g928 x) = f (g927 x) @[simp] axiom s928 (x : Prop) : f (g929 x) = f (g928 x) @[simp] axiom s929 (x : Prop) : f (g930 x) = f (g929 x) @[simp] axiom s930 (x : Prop) : f (g931 x) = f (g930 x) @[simp] axiom s931 (x : Prop) : f (g932 x) = f (g931 x) @[simp] axiom s932 (x : Prop) : f (g933 x) = f (g932 x) @[simp] axiom s933 (x : Prop) : f (g934 x) = f (g933 x) @[simp] axiom s934 (x : Prop) : f (g935 x) = f (g934 x) @[simp] axiom s935 (x : Prop) : f (g936 x) = f (g935 x) @[simp] axiom s936 (x : Prop) : f (g937 x) = f (g936 x) @[simp] axiom s937 (x : Prop) : f (g938 x) = f (g937 x) @[simp] axiom s938 (x : Prop) : f (g939 x) = f (g938 x) @[simp] axiom s939 (x : Prop) : f (g940 x) = f (g939 x) @[simp] axiom s940 (x : Prop) : f (g941 x) = f (g940 x) @[simp] axiom s941 (x : Prop) : f (g942 x) = f (g941 x) @[simp] axiom s942 (x : Prop) : f (g943 x) = f (g942 x) @[simp] axiom s943 (x : Prop) : f (g944 x) = f (g943 x) @[simp] axiom s944 (x : Prop) : f (g945 x) = f (g944 x) @[simp] axiom s945 (x : Prop) : f (g946 x) = f (g945 x) @[simp] axiom s946 (x : Prop) : f (g947 x) = f (g946 x) @[simp] axiom s947 (x : Prop) : f (g948 x) = f (g947 x) @[simp] axiom s948 (x : Prop) : f (g949 x) = f (g948 x) @[simp] axiom s949 (x : Prop) : f (g950 x) = f (g949 x) @[simp] axiom s950 (x : Prop) : f (g951 x) = f (g950 x) @[simp] axiom s951 (x : Prop) : f (g952 x) = f (g951 x) @[simp] axiom s952 (x : Prop) : f (g953 x) = f (g952 x) @[simp] axiom s953 (x : Prop) : f (g954 x) = f (g953 x) @[simp] axiom s954 (x : Prop) : f (g955 x) = f (g954 x) @[simp] axiom s955 (x : Prop) : f (g956 x) = f (g955 x) @[simp] axiom s956 (x : Prop) : f (g957 x) = f (g956 x) @[simp] axiom s957 (x : Prop) : f (g958 x) = f (g957 x) @[simp] axiom s958 (x : Prop) : f (g959 x) = f (g958 x) @[simp] axiom s959 (x : Prop) : f (g960 x) = f (g959 x) @[simp] axiom s960 (x : Prop) : f (g961 x) = f (g960 x) @[simp] axiom s961 (x : Prop) : f (g962 x) = f (g961 x) @[simp] axiom s962 (x : Prop) : f (g963 x) = f (g962 x) @[simp] axiom s963 (x : Prop) : f (g964 x) = f (g963 x) @[simp] axiom s964 (x : Prop) : f (g965 x) = f (g964 x) @[simp] axiom s965 (x : Prop) : f (g966 x) = f (g965 x) @[simp] axiom s966 (x : Prop) : f (g967 x) = f (g966 x) @[simp] axiom s967 (x : Prop) : f (g968 x) = f (g967 x) @[simp] axiom s968 (x : Prop) : f (g969 x) = f (g968 x) @[simp] axiom s969 (x : Prop) : f (g970 x) = f (g969 x) @[simp] axiom s970 (x : Prop) : f (g971 x) = f (g970 x) @[simp] axiom s971 (x : Prop) : f (g972 x) = f (g971 x) @[simp] axiom s972 (x : Prop) : f (g973 x) = f (g972 x) @[simp] axiom s973 (x : Prop) : f (g974 x) = f (g973 x) @[simp] axiom s974 (x : Prop) : f (g975 x) = f (g974 x) @[simp] axiom s975 (x : Prop) : f (g976 x) = f (g975 x) @[simp] axiom s976 (x : Prop) : f (g977 x) = f (g976 x) @[simp] axiom s977 (x : Prop) : f (g978 x) = f (g977 x) @[simp] axiom s978 (x : Prop) : f (g979 x) = f (g978 x) @[simp] axiom s979 (x : Prop) : f (g980 x) = f (g979 x) @[simp] axiom s980 (x : Prop) : f (g981 x) = f (g980 x) @[simp] axiom s981 (x : Prop) : f (g982 x) = f (g981 x) @[simp] axiom s982 (x : Prop) : f (g983 x) = f (g982 x) @[simp] axiom s983 (x : Prop) : f (g984 x) = f (g983 x) @[simp] axiom s984 (x : Prop) : f (g985 x) = f (g984 x) @[simp] axiom s985 (x : Prop) : f (g986 x) = f (g985 x) @[simp] axiom s986 (x : Prop) : f (g987 x) = f (g986 x) @[simp] axiom s987 (x : Prop) : f (g988 x) = f (g987 x) @[simp] axiom s988 (x : Prop) : f (g989 x) = f (g988 x) @[simp] axiom s989 (x : Prop) : f (g990 x) = f (g989 x) @[simp] axiom s990 (x : Prop) : f (g991 x) = f (g990 x) @[simp] axiom s991 (x : Prop) : f (g992 x) = f (g991 x) @[simp] axiom s992 (x : Prop) : f (g993 x) = f (g992 x) @[simp] axiom s993 (x : Prop) : f (g994 x) = f (g993 x) @[simp] axiom s994 (x : Prop) : f (g995 x) = f (g994 x) @[simp] axiom s995 (x : Prop) : f (g996 x) = f (g995 x) @[simp] axiom s996 (x : Prop) : f (g997 x) = f (g996 x) @[simp] axiom s997 (x : Prop) : f (g998 x) = f (g997 x) @[simp] axiom s998 (x : Prop) : f (g999 x) = f (g998 x) @[simp] axiom s999 (x : Prop) : f (g1000 x) = f (g999 x) @[simp] axiom s1000 (x : Prop) : f (g1001 x) = f (g1000 x) @[simp] axiom s1001 (x : Prop) : f (g1002 x) = f (g1001 x) @[simp] axiom s1002 (x : Prop) : f (g1003 x) = f (g1002 x) @[simp] axiom s1003 (x : Prop) : f (g1004 x) = f (g1003 x) @[simp] axiom s1004 (x : Prop) : f (g1005 x) = f (g1004 x) @[simp] axiom s1005 (x : Prop) : f (g1006 x) = f (g1005 x) @[simp] axiom s1006 (x : Prop) : f (g1007 x) = f (g1006 x) @[simp] axiom s1007 (x : Prop) : f (g1008 x) = f (g1007 x) @[simp] axiom s1008 (x : Prop) : f (g1009 x) = f (g1008 x) @[simp] axiom s1009 (x : Prop) : f (g1010 x) = f (g1009 x) @[simp] axiom s1010 (x : Prop) : f (g1011 x) = f (g1010 x) @[simp] axiom s1011 (x : Prop) : f (g1012 x) = f (g1011 x) @[simp] axiom s1012 (x : Prop) : f (g1013 x) = f (g1012 x) @[simp] axiom s1013 (x : Prop) : f (g1014 x) = f (g1013 x) @[simp] axiom s1014 (x : Prop) : f (g1015 x) = f (g1014 x) @[simp] axiom s1015 (x : Prop) : f (g1016 x) = f (g1015 x) @[simp] axiom s1016 (x : Prop) : f (g1017 x) = f (g1016 x) @[simp] axiom s1017 (x : Prop) : f (g1018 x) = f (g1017 x) @[simp] axiom s1018 (x : Prop) : f (g1019 x) = f (g1018 x) @[simp] axiom s1019 (x : Prop) : f (g1020 x) = f (g1019 x) @[simp] axiom s1020 (x : Prop) : f (g1021 x) = f (g1020 x) @[simp] axiom s1021 (x : Prop) : f (g1022 x) = f (g1021 x) @[simp] axiom s1022 (x : Prop) : f (g1023 x) = f (g1022 x) @[simp] axiom s1023 (x : Prop) : f (g1024 x) = f (g1023 x) @[simp] axiom s1024 (x : Prop) : f (g1025 x) = f (g1024 x) @[simp] axiom s1025 (x : Prop) : f (g1026 x) = f (g1025 x) @[simp] axiom s1026 (x : Prop) : f (g1027 x) = f (g1026 x) @[simp] axiom s1027 (x : Prop) : f (g1028 x) = f (g1027 x) @[simp] axiom s1028 (x : Prop) : f (g1029 x) = f (g1028 x) @[simp] axiom s1029 (x : Prop) : f (g1030 x) = f (g1029 x) @[simp] axiom s1030 (x : Prop) : f (g1031 x) = f (g1030 x) @[simp] axiom s1031 (x : Prop) : f (g1032 x) = f (g1031 x) @[simp] axiom s1032 (x : Prop) : f (g1033 x) = f (g1032 x) @[simp] axiom s1033 (x : Prop) : f (g1034 x) = f (g1033 x) @[simp] axiom s1034 (x : Prop) : f (g1035 x) = f (g1034 x) @[simp] axiom s1035 (x : Prop) : f (g1036 x) = f (g1035 x) @[simp] axiom s1036 (x : Prop) : f (g1037 x) = f (g1036 x) @[simp] axiom s1037 (x : Prop) : f (g1038 x) = f (g1037 x) @[simp] axiom s1038 (x : Prop) : f (g1039 x) = f (g1038 x) @[simp] axiom s1039 (x : Prop) : f (g1040 x) = f (g1039 x) @[simp] axiom s1040 (x : Prop) : f (g1041 x) = f (g1040 x) @[simp] axiom s1041 (x : Prop) : f (g1042 x) = f (g1041 x) @[simp] axiom s1042 (x : Prop) : f (g1043 x) = f (g1042 x) @[simp] axiom s1043 (x : Prop) : f (g1044 x) = f (g1043 x) @[simp] axiom s1044 (x : Prop) : f (g1045 x) = f (g1044 x) @[simp] axiom s1045 (x : Prop) : f (g1046 x) = f (g1045 x) @[simp] axiom s1046 (x : Prop) : f (g1047 x) = f (g1046 x) @[simp] axiom s1047 (x : Prop) : f (g1048 x) = f (g1047 x) @[simp] axiom s1048 (x : Prop) : f (g1049 x) = f (g1048 x) @[simp] axiom s1049 (x : Prop) : f (g1050 x) = f (g1049 x) @[simp] axiom s1050 (x : Prop) : f (g1051 x) = f (g1050 x) @[simp] axiom s1051 (x : Prop) : f (g1052 x) = f (g1051 x) @[simp] axiom s1052 (x : Prop) : f (g1053 x) = f (g1052 x) @[simp] axiom s1053 (x : Prop) : f (g1054 x) = f (g1053 x) @[simp] axiom s1054 (x : Prop) : f (g1055 x) = f (g1054 x) @[simp] axiom s1055 (x : Prop) : f (g1056 x) = f (g1055 x) @[simp] axiom s1056 (x : Prop) : f (g1057 x) = f (g1056 x) @[simp] axiom s1057 (x : Prop) : f (g1058 x) = f (g1057 x) @[simp] axiom s1058 (x : Prop) : f (g1059 x) = f (g1058 x) @[simp] axiom s1059 (x : Prop) : f (g1060 x) = f (g1059 x) @[simp] axiom s1060 (x : Prop) : f (g1061 x) = f (g1060 x) @[simp] axiom s1061 (x : Prop) : f (g1062 x) = f (g1061 x) @[simp] axiom s1062 (x : Prop) : f (g1063 x) = f (g1062 x) @[simp] axiom s1063 (x : Prop) : f (g1064 x) = f (g1063 x) @[simp] axiom s1064 (x : Prop) : f (g1065 x) = f (g1064 x) @[simp] axiom s1065 (x : Prop) : f (g1066 x) = f (g1065 x) @[simp] axiom s1066 (x : Prop) : f (g1067 x) = f (g1066 x) @[simp] axiom s1067 (x : Prop) : f (g1068 x) = f (g1067 x) @[simp] axiom s1068 (x : Prop) : f (g1069 x) = f (g1068 x) @[simp] axiom s1069 (x : Prop) : f (g1070 x) = f (g1069 x) @[simp] axiom s1070 (x : Prop) : f (g1071 x) = f (g1070 x) @[simp] axiom s1071 (x : Prop) : f (g1072 x) = f (g1071 x) @[simp] axiom s1072 (x : Prop) : f (g1073 x) = f (g1072 x) @[simp] axiom s1073 (x : Prop) : f (g1074 x) = f (g1073 x) @[simp] axiom s1074 (x : Prop) : f (g1075 x) = f (g1074 x) @[simp] axiom s1075 (x : Prop) : f (g1076 x) = f (g1075 x) @[simp] axiom s1076 (x : Prop) : f (g1077 x) = f (g1076 x) @[simp] axiom s1077 (x : Prop) : f (g1078 x) = f (g1077 x) @[simp] axiom s1078 (x : Prop) : f (g1079 x) = f (g1078 x) @[simp] axiom s1079 (x : Prop) : f (g1080 x) = f (g1079 x) @[simp] axiom s1080 (x : Prop) : f (g1081 x) = f (g1080 x) @[simp] axiom s1081 (x : Prop) : f (g1082 x) = f (g1081 x) @[simp] axiom s1082 (x : Prop) : f (g1083 x) = f (g1082 x) @[simp] axiom s1083 (x : Prop) : f (g1084 x) = f (g1083 x) @[simp] axiom s1084 (x : Prop) : f (g1085 x) = f (g1084 x) @[simp] axiom s1085 (x : Prop) : f (g1086 x) = f (g1085 x) @[simp] axiom s1086 (x : Prop) : f (g1087 x) = f (g1086 x) @[simp] axiom s1087 (x : Prop) : f (g1088 x) = f (g1087 x) @[simp] axiom s1088 (x : Prop) : f (g1089 x) = f (g1088 x) @[simp] axiom s1089 (x : Prop) : f (g1090 x) = f (g1089 x) @[simp] axiom s1090 (x : Prop) : f (g1091 x) = f (g1090 x) @[simp] axiom s1091 (x : Prop) : f (g1092 x) = f (g1091 x) @[simp] axiom s1092 (x : Prop) : f (g1093 x) = f (g1092 x) @[simp] axiom s1093 (x : Prop) : f (g1094 x) = f (g1093 x) @[simp] axiom s1094 (x : Prop) : f (g1095 x) = f (g1094 x) @[simp] axiom s1095 (x : Prop) : f (g1096 x) = f (g1095 x) @[simp] axiom s1096 (x : Prop) : f (g1097 x) = f (g1096 x) @[simp] axiom s1097 (x : Prop) : f (g1098 x) = f (g1097 x) @[simp] axiom s1098 (x : Prop) : f (g1099 x) = f (g1098 x) @[simp] axiom s1099 (x : Prop) : f (g1100 x) = f (g1099 x) @[simp] axiom s1100 (x : Prop) : f (g1101 x) = f (g1100 x) @[simp] axiom s1101 (x : Prop) : f (g1102 x) = f (g1101 x) @[simp] axiom s1102 (x : Prop) : f (g1103 x) = f (g1102 x) @[simp] axiom s1103 (x : Prop) : f (g1104 x) = f (g1103 x) @[simp] axiom s1104 (x : Prop) : f (g1105 x) = f (g1104 x) @[simp] axiom s1105 (x : Prop) : f (g1106 x) = f (g1105 x) @[simp] axiom s1106 (x : Prop) : f (g1107 x) = f (g1106 x) @[simp] axiom s1107 (x : Prop) : f (g1108 x) = f (g1107 x) @[simp] axiom s1108 (x : Prop) : f (g1109 x) = f (g1108 x) @[simp] axiom s1109 (x : Prop) : f (g1110 x) = f (g1109 x) @[simp] axiom s1110 (x : Prop) : f (g1111 x) = f (g1110 x) @[simp] axiom s1111 (x : Prop) : f (g1112 x) = f (g1111 x) @[simp] axiom s1112 (x : Prop) : f (g1113 x) = f (g1112 x) @[simp] axiom s1113 (x : Prop) : f (g1114 x) = f (g1113 x) @[simp] axiom s1114 (x : Prop) : f (g1115 x) = f (g1114 x) @[simp] axiom s1115 (x : Prop) : f (g1116 x) = f (g1115 x) @[simp] axiom s1116 (x : Prop) : f (g1117 x) = f (g1116 x) @[simp] axiom s1117 (x : Prop) : f (g1118 x) = f (g1117 x) @[simp] axiom s1118 (x : Prop) : f (g1119 x) = f (g1118 x) @[simp] axiom s1119 (x : Prop) : f (g1120 x) = f (g1119 x) @[simp] axiom s1120 (x : Prop) : f (g1121 x) = f (g1120 x) @[simp] axiom s1121 (x : Prop) : f (g1122 x) = f (g1121 x) @[simp] axiom s1122 (x : Prop) : f (g1123 x) = f (g1122 x) @[simp] axiom s1123 (x : Prop) : f (g1124 x) = f (g1123 x) @[simp] axiom s1124 (x : Prop) : f (g1125 x) = f (g1124 x) @[simp] axiom s1125 (x : Prop) : f (g1126 x) = f (g1125 x) @[simp] axiom s1126 (x : Prop) : f (g1127 x) = f (g1126 x) @[simp] axiom s1127 (x : Prop) : f (g1128 x) = f (g1127 x) @[simp] axiom s1128 (x : Prop) : f (g1129 x) = f (g1128 x) @[simp] axiom s1129 (x : Prop) : f (g1130 x) = f (g1129 x) @[simp] axiom s1130 (x : Prop) : f (g1131 x) = f (g1130 x) @[simp] axiom s1131 (x : Prop) : f (g1132 x) = f (g1131 x) @[simp] axiom s1132 (x : Prop) : f (g1133 x) = f (g1132 x) @[simp] axiom s1133 (x : Prop) : f (g1134 x) = f (g1133 x) @[simp] axiom s1134 (x : Prop) : f (g1135 x) = f (g1134 x) @[simp] axiom s1135 (x : Prop) : f (g1136 x) = f (g1135 x) @[simp] axiom s1136 (x : Prop) : f (g1137 x) = f (g1136 x) @[simp] axiom s1137 (x : Prop) : f (g1138 x) = f (g1137 x) @[simp] axiom s1138 (x : Prop) : f (g1139 x) = f (g1138 x) @[simp] axiom s1139 (x : Prop) : f (g1140 x) = f (g1139 x) @[simp] axiom s1140 (x : Prop) : f (g1141 x) = f (g1140 x) @[simp] axiom s1141 (x : Prop) : f (g1142 x) = f (g1141 x) @[simp] axiom s1142 (x : Prop) : f (g1143 x) = f (g1142 x) @[simp] axiom s1143 (x : Prop) : f (g1144 x) = f (g1143 x) @[simp] axiom s1144 (x : Prop) : f (g1145 x) = f (g1144 x) @[simp] axiom s1145 (x : Prop) : f (g1146 x) = f (g1145 x) @[simp] axiom s1146 (x : Prop) : f (g1147 x) = f (g1146 x) @[simp] axiom s1147 (x : Prop) : f (g1148 x) = f (g1147 x) @[simp] axiom s1148 (x : Prop) : f (g1149 x) = f (g1148 x) @[simp] axiom s1149 (x : Prop) : f (g1150 x) = f (g1149 x) @[simp] axiom s1150 (x : Prop) : f (g1151 x) = f (g1150 x) @[simp] axiom s1151 (x : Prop) : f (g1152 x) = f (g1151 x) @[simp] axiom s1152 (x : Prop) : f (g1153 x) = f (g1152 x) @[simp] axiom s1153 (x : Prop) : f (g1154 x) = f (g1153 x) @[simp] axiom s1154 (x : Prop) : f (g1155 x) = f (g1154 x) @[simp] axiom s1155 (x : Prop) : f (g1156 x) = f (g1155 x) @[simp] axiom s1156 (x : Prop) : f (g1157 x) = f (g1156 x) @[simp] axiom s1157 (x : Prop) : f (g1158 x) = f (g1157 x) @[simp] axiom s1158 (x : Prop) : f (g1159 x) = f (g1158 x) @[simp] axiom s1159 (x : Prop) : f (g1160 x) = f (g1159 x) @[simp] axiom s1160 (x : Prop) : f (g1161 x) = f (g1160 x) @[simp] axiom s1161 (x : Prop) : f (g1162 x) = f (g1161 x) @[simp] axiom s1162 (x : Prop) : f (g1163 x) = f (g1162 x) @[simp] axiom s1163 (x : Prop) : f (g1164 x) = f (g1163 x) @[simp] axiom s1164 (x : Prop) : f (g1165 x) = f (g1164 x) @[simp] axiom s1165 (x : Prop) : f (g1166 x) = f (g1165 x) @[simp] axiom s1166 (x : Prop) : f (g1167 x) = f (g1166 x) @[simp] axiom s1167 (x : Prop) : f (g1168 x) = f (g1167 x) @[simp] axiom s1168 (x : Prop) : f (g1169 x) = f (g1168 x) @[simp] axiom s1169 (x : Prop) : f (g1170 x) = f (g1169 x) @[simp] axiom s1170 (x : Prop) : f (g1171 x) = f (g1170 x) @[simp] axiom s1171 (x : Prop) : f (g1172 x) = f (g1171 x) @[simp] axiom s1172 (x : Prop) : f (g1173 x) = f (g1172 x) @[simp] axiom s1173 (x : Prop) : f (g1174 x) = f (g1173 x) @[simp] axiom s1174 (x : Prop) : f (g1175 x) = f (g1174 x) @[simp] axiom s1175 (x : Prop) : f (g1176 x) = f (g1175 x) @[simp] axiom s1176 (x : Prop) : f (g1177 x) = f (g1176 x) @[simp] axiom s1177 (x : Prop) : f (g1178 x) = f (g1177 x) @[simp] axiom s1178 (x : Prop) : f (g1179 x) = f (g1178 x) @[simp] axiom s1179 (x : Prop) : f (g1180 x) = f (g1179 x) @[simp] axiom s1180 (x : Prop) : f (g1181 x) = f (g1180 x) @[simp] axiom s1181 (x : Prop) : f (g1182 x) = f (g1181 x) @[simp] axiom s1182 (x : Prop) : f (g1183 x) = f (g1182 x) @[simp] axiom s1183 (x : Prop) : f (g1184 x) = f (g1183 x) @[simp] axiom s1184 (x : Prop) : f (g1185 x) = f (g1184 x) @[simp] axiom s1185 (x : Prop) : f (g1186 x) = f (g1185 x) @[simp] axiom s1186 (x : Prop) : f (g1187 x) = f (g1186 x) @[simp] axiom s1187 (x : Prop) : f (g1188 x) = f (g1187 x) @[simp] axiom s1188 (x : Prop) : f (g1189 x) = f (g1188 x) @[simp] axiom s1189 (x : Prop) : f (g1190 x) = f (g1189 x) @[simp] axiom s1190 (x : Prop) : f (g1191 x) = f (g1190 x) @[simp] axiom s1191 (x : Prop) : f (g1192 x) = f (g1191 x) @[simp] axiom s1192 (x : Prop) : f (g1193 x) = f (g1192 x) @[simp] axiom s1193 (x : Prop) : f (g1194 x) = f (g1193 x) @[simp] axiom s1194 (x : Prop) : f (g1195 x) = f (g1194 x) @[simp] axiom s1195 (x : Prop) : f (g1196 x) = f (g1195 x) @[simp] axiom s1196 (x : Prop) : f (g1197 x) = f (g1196 x) @[simp] axiom s1197 (x : Prop) : f (g1198 x) = f (g1197 x) @[simp] axiom s1198 (x : Prop) : f (g1199 x) = f (g1198 x) @[simp] axiom s1199 (x : Prop) : f (g1200 x) = f (g1199 x) @[simp] axiom s1200 (x : Prop) : f (g1201 x) = f (g1200 x) @[simp] axiom s1201 (x : Prop) : f (g1202 x) = f (g1201 x) @[simp] axiom s1202 (x : Prop) : f (g1203 x) = f (g1202 x) @[simp] axiom s1203 (x : Prop) : f (g1204 x) = f (g1203 x) @[simp] axiom s1204 (x : Prop) : f (g1205 x) = f (g1204 x) @[simp] axiom s1205 (x : Prop) : f (g1206 x) = f (g1205 x) @[simp] axiom s1206 (x : Prop) : f (g1207 x) = f (g1206 x) @[simp] axiom s1207 (x : Prop) : f (g1208 x) = f (g1207 x) @[simp] axiom s1208 (x : Prop) : f (g1209 x) = f (g1208 x) @[simp] axiom s1209 (x : Prop) : f (g1210 x) = f (g1209 x) @[simp] axiom s1210 (x : Prop) : f (g1211 x) = f (g1210 x) @[simp] axiom s1211 (x : Prop) : f (g1212 x) = f (g1211 x) @[simp] axiom s1212 (x : Prop) : f (g1213 x) = f (g1212 x) @[simp] axiom s1213 (x : Prop) : f (g1214 x) = f (g1213 x) @[simp] axiom s1214 (x : Prop) : f (g1215 x) = f (g1214 x) @[simp] axiom s1215 (x : Prop) : f (g1216 x) = f (g1215 x) @[simp] axiom s1216 (x : Prop) : f (g1217 x) = f (g1216 x) @[simp] axiom s1217 (x : Prop) : f (g1218 x) = f (g1217 x) @[simp] axiom s1218 (x : Prop) : f (g1219 x) = f (g1218 x) @[simp] axiom s1219 (x : Prop) : f (g1220 x) = f (g1219 x) @[simp] axiom s1220 (x : Prop) : f (g1221 x) = f (g1220 x) @[simp] axiom s1221 (x : Prop) : f (g1222 x) = f (g1221 x) @[simp] axiom s1222 (x : Prop) : f (g1223 x) = f (g1222 x) @[simp] axiom s1223 (x : Prop) : f (g1224 x) = f (g1223 x) @[simp] axiom s1224 (x : Prop) : f (g1225 x) = f (g1224 x) @[simp] axiom s1225 (x : Prop) : f (g1226 x) = f (g1225 x) @[simp] axiom s1226 (x : Prop) : f (g1227 x) = f (g1226 x) @[simp] axiom s1227 (x : Prop) : f (g1228 x) = f (g1227 x) @[simp] axiom s1228 (x : Prop) : f (g1229 x) = f (g1228 x) @[simp] axiom s1229 (x : Prop) : f (g1230 x) = f (g1229 x) @[simp] axiom s1230 (x : Prop) : f (g1231 x) = f (g1230 x) @[simp] axiom s1231 (x : Prop) : f (g1232 x) = f (g1231 x) @[simp] axiom s1232 (x : Prop) : f (g1233 x) = f (g1232 x) @[simp] axiom s1233 (x : Prop) : f (g1234 x) = f (g1233 x) @[simp] axiom s1234 (x : Prop) : f (g1235 x) = f (g1234 x) @[simp] axiom s1235 (x : Prop) : f (g1236 x) = f (g1235 x) @[simp] axiom s1236 (x : Prop) : f (g1237 x) = f (g1236 x) @[simp] axiom s1237 (x : Prop) : f (g1238 x) = f (g1237 x) @[simp] axiom s1238 (x : Prop) : f (g1239 x) = f (g1238 x) @[simp] axiom s1239 (x : Prop) : f (g1240 x) = f (g1239 x) @[simp] axiom s1240 (x : Prop) : f (g1241 x) = f (g1240 x) @[simp] axiom s1241 (x : Prop) : f (g1242 x) = f (g1241 x) @[simp] axiom s1242 (x : Prop) : f (g1243 x) = f (g1242 x) @[simp] axiom s1243 (x : Prop) : f (g1244 x) = f (g1243 x) @[simp] axiom s1244 (x : Prop) : f (g1245 x) = f (g1244 x) @[simp] axiom s1245 (x : Prop) : f (g1246 x) = f (g1245 x) @[simp] axiom s1246 (x : Prop) : f (g1247 x) = f (g1246 x) @[simp] axiom s1247 (x : Prop) : f (g1248 x) = f (g1247 x) @[simp] axiom s1248 (x : Prop) : f (g1249 x) = f (g1248 x) @[simp] axiom s1249 (x : Prop) : f (g1250 x) = f (g1249 x) @[simp] axiom s1250 (x : Prop) : f (g1251 x) = f (g1250 x) @[simp] axiom s1251 (x : Prop) : f (g1252 x) = f (g1251 x) @[simp] axiom s1252 (x : Prop) : f (g1253 x) = f (g1252 x) @[simp] axiom s1253 (x : Prop) : f (g1254 x) = f (g1253 x) @[simp] axiom s1254 (x : Prop) : f (g1255 x) = f (g1254 x) @[simp] axiom s1255 (x : Prop) : f (g1256 x) = f (g1255 x) @[simp] axiom s1256 (x : Prop) : f (g1257 x) = f (g1256 x) @[simp] axiom s1257 (x : Prop) : f (g1258 x) = f (g1257 x) @[simp] axiom s1258 (x : Prop) : f (g1259 x) = f (g1258 x) @[simp] axiom s1259 (x : Prop) : f (g1260 x) = f (g1259 x) @[simp] axiom s1260 (x : Prop) : f (g1261 x) = f (g1260 x) @[simp] axiom s1261 (x : Prop) : f (g1262 x) = f (g1261 x) @[simp] axiom s1262 (x : Prop) : f (g1263 x) = f (g1262 x) @[simp] axiom s1263 (x : Prop) : f (g1264 x) = f (g1263 x) @[simp] axiom s1264 (x : Prop) : f (g1265 x) = f (g1264 x) @[simp] axiom s1265 (x : Prop) : f (g1266 x) = f (g1265 x) @[simp] axiom s1266 (x : Prop) : f (g1267 x) = f (g1266 x) @[simp] axiom s1267 (x : Prop) : f (g1268 x) = f (g1267 x) @[simp] axiom s1268 (x : Prop) : f (g1269 x) = f (g1268 x) @[simp] axiom s1269 (x : Prop) : f (g1270 x) = f (g1269 x) @[simp] axiom s1270 (x : Prop) : f (g1271 x) = f (g1270 x) @[simp] axiom s1271 (x : Prop) : f (g1272 x) = f (g1271 x) @[simp] axiom s1272 (x : Prop) : f (g1273 x) = f (g1272 x) @[simp] axiom s1273 (x : Prop) : f (g1274 x) = f (g1273 x) @[simp] axiom s1274 (x : Prop) : f (g1275 x) = f (g1274 x) @[simp] axiom s1275 (x : Prop) : f (g1276 x) = f (g1275 x) @[simp] axiom s1276 (x : Prop) : f (g1277 x) = f (g1276 x) @[simp] axiom s1277 (x : Prop) : f (g1278 x) = f (g1277 x) @[simp] axiom s1278 (x : Prop) : f (g1279 x) = f (g1278 x) @[simp] axiom s1279 (x : Prop) : f (g1280 x) = f (g1279 x) @[simp] axiom s1280 (x : Prop) : f (g1281 x) = f (g1280 x) @[simp] axiom s1281 (x : Prop) : f (g1282 x) = f (g1281 x) @[simp] axiom s1282 (x : Prop) : f (g1283 x) = f (g1282 x) @[simp] axiom s1283 (x : Prop) : f (g1284 x) = f (g1283 x) @[simp] axiom s1284 (x : Prop) : f (g1285 x) = f (g1284 x) @[simp] axiom s1285 (x : Prop) : f (g1286 x) = f (g1285 x) @[simp] axiom s1286 (x : Prop) : f (g1287 x) = f (g1286 x) @[simp] axiom s1287 (x : Prop) : f (g1288 x) = f (g1287 x) @[simp] axiom s1288 (x : Prop) : f (g1289 x) = f (g1288 x) @[simp] axiom s1289 (x : Prop) : f (g1290 x) = f (g1289 x) @[simp] axiom s1290 (x : Prop) : f (g1291 x) = f (g1290 x) @[simp] axiom s1291 (x : Prop) : f (g1292 x) = f (g1291 x) @[simp] axiom s1292 (x : Prop) : f (g1293 x) = f (g1292 x) @[simp] axiom s1293 (x : Prop) : f (g1294 x) = f (g1293 x) @[simp] axiom s1294 (x : Prop) : f (g1295 x) = f (g1294 x) @[simp] axiom s1295 (x : Prop) : f (g1296 x) = f (g1295 x) @[simp] axiom s1296 (x : Prop) : f (g1297 x) = f (g1296 x) @[simp] axiom s1297 (x : Prop) : f (g1298 x) = f (g1297 x) @[simp] axiom s1298 (x : Prop) : f (g1299 x) = f (g1298 x) @[simp] axiom s1299 (x : Prop) : f (g1300 x) = f (g1299 x) @[simp] axiom s1300 (x : Prop) : f (g1301 x) = f (g1300 x) @[simp] axiom s1301 (x : Prop) : f (g1302 x) = f (g1301 x) @[simp] axiom s1302 (x : Prop) : f (g1303 x) = f (g1302 x) @[simp] axiom s1303 (x : Prop) : f (g1304 x) = f (g1303 x) @[simp] axiom s1304 (x : Prop) : f (g1305 x) = f (g1304 x) @[simp] axiom s1305 (x : Prop) : f (g1306 x) = f (g1305 x) @[simp] axiom s1306 (x : Prop) : f (g1307 x) = f (g1306 x) @[simp] axiom s1307 (x : Prop) : f (g1308 x) = f (g1307 x) @[simp] axiom s1308 (x : Prop) : f (g1309 x) = f (g1308 x) @[simp] axiom s1309 (x : Prop) : f (g1310 x) = f (g1309 x) @[simp] axiom s1310 (x : Prop) : f (g1311 x) = f (g1310 x) @[simp] axiom s1311 (x : Prop) : f (g1312 x) = f (g1311 x) @[simp] axiom s1312 (x : Prop) : f (g1313 x) = f (g1312 x) @[simp] axiom s1313 (x : Prop) : f (g1314 x) = f (g1313 x) @[simp] axiom s1314 (x : Prop) : f (g1315 x) = f (g1314 x) @[simp] axiom s1315 (x : Prop) : f (g1316 x) = f (g1315 x) @[simp] axiom s1316 (x : Prop) : f (g1317 x) = f (g1316 x) @[simp] axiom s1317 (x : Prop) : f (g1318 x) = f (g1317 x) @[simp] axiom s1318 (x : Prop) : f (g1319 x) = f (g1318 x) @[simp] axiom s1319 (x : Prop) : f (g1320 x) = f (g1319 x) @[simp] axiom s1320 (x : Prop) : f (g1321 x) = f (g1320 x) @[simp] axiom s1321 (x : Prop) : f (g1322 x) = f (g1321 x) @[simp] axiom s1322 (x : Prop) : f (g1323 x) = f (g1322 x) @[simp] axiom s1323 (x : Prop) : f (g1324 x) = f (g1323 x) @[simp] axiom s1324 (x : Prop) : f (g1325 x) = f (g1324 x) @[simp] axiom s1325 (x : Prop) : f (g1326 x) = f (g1325 x) @[simp] axiom s1326 (x : Prop) : f (g1327 x) = f (g1326 x) @[simp] axiom s1327 (x : Prop) : f (g1328 x) = f (g1327 x) @[simp] axiom s1328 (x : Prop) : f (g1329 x) = f (g1328 x) @[simp] axiom s1329 (x : Prop) : f (g1330 x) = f (g1329 x) @[simp] axiom s1330 (x : Prop) : f (g1331 x) = f (g1330 x) @[simp] axiom s1331 (x : Prop) : f (g1332 x) = f (g1331 x) @[simp] axiom s1332 (x : Prop) : f (g1333 x) = f (g1332 x) @[simp] axiom s1333 (x : Prop) : f (g1334 x) = f (g1333 x) @[simp] axiom s1334 (x : Prop) : f (g1335 x) = f (g1334 x) @[simp] axiom s1335 (x : Prop) : f (g1336 x) = f (g1335 x) @[simp] axiom s1336 (x : Prop) : f (g1337 x) = f (g1336 x) @[simp] axiom s1337 (x : Prop) : f (g1338 x) = f (g1337 x) @[simp] axiom s1338 (x : Prop) : f (g1339 x) = f (g1338 x) @[simp] axiom s1339 (x : Prop) : f (g1340 x) = f (g1339 x) @[simp] axiom s1340 (x : Prop) : f (g1341 x) = f (g1340 x) @[simp] axiom s1341 (x : Prop) : f (g1342 x) = f (g1341 x) @[simp] axiom s1342 (x : Prop) : f (g1343 x) = f (g1342 x) @[simp] axiom s1343 (x : Prop) : f (g1344 x) = f (g1343 x) @[simp] axiom s1344 (x : Prop) : f (g1345 x) = f (g1344 x) @[simp] axiom s1345 (x : Prop) : f (g1346 x) = f (g1345 x) @[simp] axiom s1346 (x : Prop) : f (g1347 x) = f (g1346 x) @[simp] axiom s1347 (x : Prop) : f (g1348 x) = f (g1347 x) @[simp] axiom s1348 (x : Prop) : f (g1349 x) = f (g1348 x) @[simp] axiom s1349 (x : Prop) : f (g1350 x) = f (g1349 x) @[simp] axiom s1350 (x : Prop) : f (g1351 x) = f (g1350 x) @[simp] axiom s1351 (x : Prop) : f (g1352 x) = f (g1351 x) @[simp] axiom s1352 (x : Prop) : f (g1353 x) = f (g1352 x) @[simp] axiom s1353 (x : Prop) : f (g1354 x) = f (g1353 x) @[simp] axiom s1354 (x : Prop) : f (g1355 x) = f (g1354 x) @[simp] axiom s1355 (x : Prop) : f (g1356 x) = f (g1355 x) @[simp] axiom s1356 (x : Prop) : f (g1357 x) = f (g1356 x) @[simp] axiom s1357 (x : Prop) : f (g1358 x) = f (g1357 x) @[simp] axiom s1358 (x : Prop) : f (g1359 x) = f (g1358 x) @[simp] axiom s1359 (x : Prop) : f (g1360 x) = f (g1359 x) @[simp] axiom s1360 (x : Prop) : f (g1361 x) = f (g1360 x) @[simp] axiom s1361 (x : Prop) : f (g1362 x) = f (g1361 x) @[simp] axiom s1362 (x : Prop) : f (g1363 x) = f (g1362 x) @[simp] axiom s1363 (x : Prop) : f (g1364 x) = f (g1363 x) @[simp] axiom s1364 (x : Prop) : f (g1365 x) = f (g1364 x) @[simp] axiom s1365 (x : Prop) : f (g1366 x) = f (g1365 x) @[simp] axiom s1366 (x : Prop) : f (g1367 x) = f (g1366 x) @[simp] axiom s1367 (x : Prop) : f (g1368 x) = f (g1367 x) @[simp] axiom s1368 (x : Prop) : f (g1369 x) = f (g1368 x) @[simp] axiom s1369 (x : Prop) : f (g1370 x) = f (g1369 x) @[simp] axiom s1370 (x : Prop) : f (g1371 x) = f (g1370 x) @[simp] axiom s1371 (x : Prop) : f (g1372 x) = f (g1371 x) @[simp] axiom s1372 (x : Prop) : f (g1373 x) = f (g1372 x) @[simp] axiom s1373 (x : Prop) : f (g1374 x) = f (g1373 x) @[simp] axiom s1374 (x : Prop) : f (g1375 x) = f (g1374 x) @[simp] axiom s1375 (x : Prop) : f (g1376 x) = f (g1375 x) @[simp] axiom s1376 (x : Prop) : f (g1377 x) = f (g1376 x) @[simp] axiom s1377 (x : Prop) : f (g1378 x) = f (g1377 x) @[simp] axiom s1378 (x : Prop) : f (g1379 x) = f (g1378 x) @[simp] axiom s1379 (x : Prop) : f (g1380 x) = f (g1379 x) @[simp] axiom s1380 (x : Prop) : f (g1381 x) = f (g1380 x) @[simp] axiom s1381 (x : Prop) : f (g1382 x) = f (g1381 x) @[simp] axiom s1382 (x : Prop) : f (g1383 x) = f (g1382 x) @[simp] axiom s1383 (x : Prop) : f (g1384 x) = f (g1383 x) @[simp] axiom s1384 (x : Prop) : f (g1385 x) = f (g1384 x) @[simp] axiom s1385 (x : Prop) : f (g1386 x) = f (g1385 x) @[simp] axiom s1386 (x : Prop) : f (g1387 x) = f (g1386 x) @[simp] axiom s1387 (x : Prop) : f (g1388 x) = f (g1387 x) @[simp] axiom s1388 (x : Prop) : f (g1389 x) = f (g1388 x) @[simp] axiom s1389 (x : Prop) : f (g1390 x) = f (g1389 x) @[simp] axiom s1390 (x : Prop) : f (g1391 x) = f (g1390 x) @[simp] axiom s1391 (x : Prop) : f (g1392 x) = f (g1391 x) @[simp] axiom s1392 (x : Prop) : f (g1393 x) = f (g1392 x) @[simp] axiom s1393 (x : Prop) : f (g1394 x) = f (g1393 x) @[simp] axiom s1394 (x : Prop) : f (g1395 x) = f (g1394 x) @[simp] axiom s1395 (x : Prop) : f (g1396 x) = f (g1395 x) @[simp] axiom s1396 (x : Prop) : f (g1397 x) = f (g1396 x) @[simp] axiom s1397 (x : Prop) : f (g1398 x) = f (g1397 x) @[simp] axiom s1398 (x : Prop) : f (g1399 x) = f (g1398 x) @[simp] axiom s1399 (x : Prop) : f (g1400 x) = f (g1399 x) @[simp] axiom s1400 (x : Prop) : f (g1401 x) = f (g1400 x) @[simp] axiom s1401 (x : Prop) : f (g1402 x) = f (g1401 x) @[simp] axiom s1402 (x : Prop) : f (g1403 x) = f (g1402 x) @[simp] axiom s1403 (x : Prop) : f (g1404 x) = f (g1403 x) @[simp] axiom s1404 (x : Prop) : f (g1405 x) = f (g1404 x) @[simp] axiom s1405 (x : Prop) : f (g1406 x) = f (g1405 x) @[simp] axiom s1406 (x : Prop) : f (g1407 x) = f (g1406 x) @[simp] axiom s1407 (x : Prop) : f (g1408 x) = f (g1407 x) @[simp] axiom s1408 (x : Prop) : f (g1409 x) = f (g1408 x) @[simp] axiom s1409 (x : Prop) : f (g1410 x) = f (g1409 x) @[simp] axiom s1410 (x : Prop) : f (g1411 x) = f (g1410 x) @[simp] axiom s1411 (x : Prop) : f (g1412 x) = f (g1411 x) @[simp] axiom s1412 (x : Prop) : f (g1413 x) = f (g1412 x) @[simp] axiom s1413 (x : Prop) : f (g1414 x) = f (g1413 x) @[simp] axiom s1414 (x : Prop) : f (g1415 x) = f (g1414 x) @[simp] axiom s1415 (x : Prop) : f (g1416 x) = f (g1415 x) @[simp] axiom s1416 (x : Prop) : f (g1417 x) = f (g1416 x) @[simp] axiom s1417 (x : Prop) : f (g1418 x) = f (g1417 x) @[simp] axiom s1418 (x : Prop) : f (g1419 x) = f (g1418 x) @[simp] axiom s1419 (x : Prop) : f (g1420 x) = f (g1419 x) @[simp] axiom s1420 (x : Prop) : f (g1421 x) = f (g1420 x) @[simp] axiom s1421 (x : Prop) : f (g1422 x) = f (g1421 x) @[simp] axiom s1422 (x : Prop) : f (g1423 x) = f (g1422 x) @[simp] axiom s1423 (x : Prop) : f (g1424 x) = f (g1423 x) @[simp] axiom s1424 (x : Prop) : f (g1425 x) = f (g1424 x) @[simp] axiom s1425 (x : Prop) : f (g1426 x) = f (g1425 x) @[simp] axiom s1426 (x : Prop) : f (g1427 x) = f (g1426 x) @[simp] axiom s1427 (x : Prop) : f (g1428 x) = f (g1427 x) @[simp] axiom s1428 (x : Prop) : f (g1429 x) = f (g1428 x) @[simp] axiom s1429 (x : Prop) : f (g1430 x) = f (g1429 x) @[simp] axiom s1430 (x : Prop) : f (g1431 x) = f (g1430 x) @[simp] axiom s1431 (x : Prop) : f (g1432 x) = f (g1431 x) @[simp] axiom s1432 (x : Prop) : f (g1433 x) = f (g1432 x) @[simp] axiom s1433 (x : Prop) : f (g1434 x) = f (g1433 x) @[simp] axiom s1434 (x : Prop) : f (g1435 x) = f (g1434 x) @[simp] axiom s1435 (x : Prop) : f (g1436 x) = f (g1435 x) @[simp] axiom s1436 (x : Prop) : f (g1437 x) = f (g1436 x) @[simp] axiom s1437 (x : Prop) : f (g1438 x) = f (g1437 x) @[simp] axiom s1438 (x : Prop) : f (g1439 x) = f (g1438 x) @[simp] axiom s1439 (x : Prop) : f (g1440 x) = f (g1439 x) @[simp] axiom s1440 (x : Prop) : f (g1441 x) = f (g1440 x) @[simp] axiom s1441 (x : Prop) : f (g1442 x) = f (g1441 x) @[simp] axiom s1442 (x : Prop) : f (g1443 x) = f (g1442 x) @[simp] axiom s1443 (x : Prop) : f (g1444 x) = f (g1443 x) @[simp] axiom s1444 (x : Prop) : f (g1445 x) = f (g1444 x) @[simp] axiom s1445 (x : Prop) : f (g1446 x) = f (g1445 x) @[simp] axiom s1446 (x : Prop) : f (g1447 x) = f (g1446 x) @[simp] axiom s1447 (x : Prop) : f (g1448 x) = f (g1447 x) @[simp] axiom s1448 (x : Prop) : f (g1449 x) = f (g1448 x) @[simp] axiom s1449 (x : Prop) : f (g1450 x) = f (g1449 x) @[simp] axiom s1450 (x : Prop) : f (g1451 x) = f (g1450 x) @[simp] axiom s1451 (x : Prop) : f (g1452 x) = f (g1451 x) @[simp] axiom s1452 (x : Prop) : f (g1453 x) = f (g1452 x) @[simp] axiom s1453 (x : Prop) : f (g1454 x) = f (g1453 x) @[simp] axiom s1454 (x : Prop) : f (g1455 x) = f (g1454 x) @[simp] axiom s1455 (x : Prop) : f (g1456 x) = f (g1455 x) @[simp] axiom s1456 (x : Prop) : f (g1457 x) = f (g1456 x) @[simp] axiom s1457 (x : Prop) : f (g1458 x) = f (g1457 x) @[simp] axiom s1458 (x : Prop) : f (g1459 x) = f (g1458 x) @[simp] axiom s1459 (x : Prop) : f (g1460 x) = f (g1459 x) @[simp] axiom s1460 (x : Prop) : f (g1461 x) = f (g1460 x) @[simp] axiom s1461 (x : Prop) : f (g1462 x) = f (g1461 x) @[simp] axiom s1462 (x : Prop) : f (g1463 x) = f (g1462 x) @[simp] axiom s1463 (x : Prop) : f (g1464 x) = f (g1463 x) @[simp] axiom s1464 (x : Prop) : f (g1465 x) = f (g1464 x) @[simp] axiom s1465 (x : Prop) : f (g1466 x) = f (g1465 x) @[simp] axiom s1466 (x : Prop) : f (g1467 x) = f (g1466 x) @[simp] axiom s1467 (x : Prop) : f (g1468 x) = f (g1467 x) @[simp] axiom s1468 (x : Prop) : f (g1469 x) = f (g1468 x) @[simp] axiom s1469 (x : Prop) : f (g1470 x) = f (g1469 x) @[simp] axiom s1470 (x : Prop) : f (g1471 x) = f (g1470 x) @[simp] axiom s1471 (x : Prop) : f (g1472 x) = f (g1471 x) @[simp] axiom s1472 (x : Prop) : f (g1473 x) = f (g1472 x) @[simp] axiom s1473 (x : Prop) : f (g1474 x) = f (g1473 x) @[simp] axiom s1474 (x : Prop) : f (g1475 x) = f (g1474 x) @[simp] axiom s1475 (x : Prop) : f (g1476 x) = f (g1475 x) @[simp] axiom s1476 (x : Prop) : f (g1477 x) = f (g1476 x) @[simp] axiom s1477 (x : Prop) : f (g1478 x) = f (g1477 x) @[simp] axiom s1478 (x : Prop) : f (g1479 x) = f (g1478 x) @[simp] axiom s1479 (x : Prop) : f (g1480 x) = f (g1479 x) @[simp] axiom s1480 (x : Prop) : f (g1481 x) = f (g1480 x) @[simp] axiom s1481 (x : Prop) : f (g1482 x) = f (g1481 x) @[simp] axiom s1482 (x : Prop) : f (g1483 x) = f (g1482 x) @[simp] axiom s1483 (x : Prop) : f (g1484 x) = f (g1483 x) @[simp] axiom s1484 (x : Prop) : f (g1485 x) = f (g1484 x) @[simp] axiom s1485 (x : Prop) : f (g1486 x) = f (g1485 x) @[simp] axiom s1486 (x : Prop) : f (g1487 x) = f (g1486 x) @[simp] axiom s1487 (x : Prop) : f (g1488 x) = f (g1487 x) @[simp] axiom s1488 (x : Prop) : f (g1489 x) = f (g1488 x) @[simp] axiom s1489 (x : Prop) : f (g1490 x) = f (g1489 x) @[simp] axiom s1490 (x : Prop) : f (g1491 x) = f (g1490 x) @[simp] axiom s1491 (x : Prop) : f (g1492 x) = f (g1491 x) @[simp] axiom s1492 (x : Prop) : f (g1493 x) = f (g1492 x) @[simp] axiom s1493 (x : Prop) : f (g1494 x) = f (g1493 x) @[simp] axiom s1494 (x : Prop) : f (g1495 x) = f (g1494 x) @[simp] axiom s1495 (x : Prop) : f (g1496 x) = f (g1495 x) @[simp] axiom s1496 (x : Prop) : f (g1497 x) = f (g1496 x) @[simp] axiom s1497 (x : Prop) : f (g1498 x) = f (g1497 x) @[simp] axiom s1498 (x : Prop) : f (g1499 x) = f (g1498 x) @[simp] axiom s1499 (x : Prop) : f (g1500 x) = f (g1499 x) @[simp] axiom s1500 (x : Prop) : f (g1501 x) = f (g1500 x) @[simp] axiom s1501 (x : Prop) : f (g1502 x) = f (g1501 x) @[simp] axiom s1502 (x : Prop) : f (g1503 x) = f (g1502 x) @[simp] axiom s1503 (x : Prop) : f (g1504 x) = f (g1503 x) @[simp] axiom s1504 (x : Prop) : f (g1505 x) = f (g1504 x) @[simp] axiom s1505 (x : Prop) : f (g1506 x) = f (g1505 x) @[simp] axiom s1506 (x : Prop) : f (g1507 x) = f (g1506 x) @[simp] axiom s1507 (x : Prop) : f (g1508 x) = f (g1507 x) @[simp] axiom s1508 (x : Prop) : f (g1509 x) = f (g1508 x) @[simp] axiom s1509 (x : Prop) : f (g1510 x) = f (g1509 x) @[simp] axiom s1510 (x : Prop) : f (g1511 x) = f (g1510 x) @[simp] axiom s1511 (x : Prop) : f (g1512 x) = f (g1511 x) @[simp] axiom s1512 (x : Prop) : f (g1513 x) = f (g1512 x) @[simp] axiom s1513 (x : Prop) : f (g1514 x) = f (g1513 x) @[simp] axiom s1514 (x : Prop) : f (g1515 x) = f (g1514 x) @[simp] axiom s1515 (x : Prop) : f (g1516 x) = f (g1515 x) @[simp] axiom s1516 (x : Prop) : f (g1517 x) = f (g1516 x) @[simp] axiom s1517 (x : Prop) : f (g1518 x) = f (g1517 x) @[simp] axiom s1518 (x : Prop) : f (g1519 x) = f (g1518 x) @[simp] axiom s1519 (x : Prop) : f (g1520 x) = f (g1519 x) @[simp] axiom s1520 (x : Prop) : f (g1521 x) = f (g1520 x) @[simp] axiom s1521 (x : Prop) : f (g1522 x) = f (g1521 x) @[simp] axiom s1522 (x : Prop) : f (g1523 x) = f (g1522 x) @[simp] axiom s1523 (x : Prop) : f (g1524 x) = f (g1523 x) @[simp] axiom s1524 (x : Prop) : f (g1525 x) = f (g1524 x) @[simp] axiom s1525 (x : Prop) : f (g1526 x) = f (g1525 x) @[simp] axiom s1526 (x : Prop) : f (g1527 x) = f (g1526 x) @[simp] axiom s1527 (x : Prop) : f (g1528 x) = f (g1527 x) @[simp] axiom s1528 (x : Prop) : f (g1529 x) = f (g1528 x) @[simp] axiom s1529 (x : Prop) : f (g1530 x) = f (g1529 x) @[simp] axiom s1530 (x : Prop) : f (g1531 x) = f (g1530 x) @[simp] axiom s1531 (x : Prop) : f (g1532 x) = f (g1531 x) @[simp] axiom s1532 (x : Prop) : f (g1533 x) = f (g1532 x) @[simp] axiom s1533 (x : Prop) : f (g1534 x) = f (g1533 x) @[simp] axiom s1534 (x : Prop) : f (g1535 x) = f (g1534 x) @[simp] axiom s1535 (x : Prop) : f (g1536 x) = f (g1535 x) @[simp] axiom s1536 (x : Prop) : f (g1537 x) = f (g1536 x) @[simp] axiom s1537 (x : Prop) : f (g1538 x) = f (g1537 x) @[simp] axiom s1538 (x : Prop) : f (g1539 x) = f (g1538 x) @[simp] axiom s1539 (x : Prop) : f (g1540 x) = f (g1539 x) @[simp] axiom s1540 (x : Prop) : f (g1541 x) = f (g1540 x) @[simp] axiom s1541 (x : Prop) : f (g1542 x) = f (g1541 x) @[simp] axiom s1542 (x : Prop) : f (g1543 x) = f (g1542 x) @[simp] axiom s1543 (x : Prop) : f (g1544 x) = f (g1543 x) @[simp] axiom s1544 (x : Prop) : f (g1545 x) = f (g1544 x) @[simp] axiom s1545 (x : Prop) : f (g1546 x) = f (g1545 x) @[simp] axiom s1546 (x : Prop) : f (g1547 x) = f (g1546 x) @[simp] axiom s1547 (x : Prop) : f (g1548 x) = f (g1547 x) @[simp] axiom s1548 (x : Prop) : f (g1549 x) = f (g1548 x) @[simp] axiom s1549 (x : Prop) : f (g1550 x) = f (g1549 x) @[simp] axiom s1550 (x : Prop) : f (g1551 x) = f (g1550 x) @[simp] axiom s1551 (x : Prop) : f (g1552 x) = f (g1551 x) @[simp] axiom s1552 (x : Prop) : f (g1553 x) = f (g1552 x) @[simp] axiom s1553 (x : Prop) : f (g1554 x) = f (g1553 x) @[simp] axiom s1554 (x : Prop) : f (g1555 x) = f (g1554 x) @[simp] axiom s1555 (x : Prop) : f (g1556 x) = f (g1555 x) @[simp] axiom s1556 (x : Prop) : f (g1557 x) = f (g1556 x) @[simp] axiom s1557 (x : Prop) : f (g1558 x) = f (g1557 x) @[simp] axiom s1558 (x : Prop) : f (g1559 x) = f (g1558 x) @[simp] axiom s1559 (x : Prop) : f (g1560 x) = f (g1559 x) @[simp] axiom s1560 (x : Prop) : f (g1561 x) = f (g1560 x) @[simp] axiom s1561 (x : Prop) : f (g1562 x) = f (g1561 x) @[simp] axiom s1562 (x : Prop) : f (g1563 x) = f (g1562 x) @[simp] axiom s1563 (x : Prop) : f (g1564 x) = f (g1563 x) @[simp] axiom s1564 (x : Prop) : f (g1565 x) = f (g1564 x) @[simp] axiom s1565 (x : Prop) : f (g1566 x) = f (g1565 x) @[simp] axiom s1566 (x : Prop) : f (g1567 x) = f (g1566 x) @[simp] axiom s1567 (x : Prop) : f (g1568 x) = f (g1567 x) @[simp] axiom s1568 (x : Prop) : f (g1569 x) = f (g1568 x) @[simp] axiom s1569 (x : Prop) : f (g1570 x) = f (g1569 x) @[simp] axiom s1570 (x : Prop) : f (g1571 x) = f (g1570 x) @[simp] axiom s1571 (x : Prop) : f (g1572 x) = f (g1571 x) @[simp] axiom s1572 (x : Prop) : f (g1573 x) = f (g1572 x) @[simp] axiom s1573 (x : Prop) : f (g1574 x) = f (g1573 x) @[simp] axiom s1574 (x : Prop) : f (g1575 x) = f (g1574 x) @[simp] axiom s1575 (x : Prop) : f (g1576 x) = f (g1575 x) @[simp] axiom s1576 (x : Prop) : f (g1577 x) = f (g1576 x) @[simp] axiom s1577 (x : Prop) : f (g1578 x) = f (g1577 x) @[simp] axiom s1578 (x : Prop) : f (g1579 x) = f (g1578 x) @[simp] axiom s1579 (x : Prop) : f (g1580 x) = f (g1579 x) @[simp] axiom s1580 (x : Prop) : f (g1581 x) = f (g1580 x) @[simp] axiom s1581 (x : Prop) : f (g1582 x) = f (g1581 x) @[simp] axiom s1582 (x : Prop) : f (g1583 x) = f (g1582 x) @[simp] axiom s1583 (x : Prop) : f (g1584 x) = f (g1583 x) @[simp] axiom s1584 (x : Prop) : f (g1585 x) = f (g1584 x) @[simp] axiom s1585 (x : Prop) : f (g1586 x) = f (g1585 x) @[simp] axiom s1586 (x : Prop) : f (g1587 x) = f (g1586 x) @[simp] axiom s1587 (x : Prop) : f (g1588 x) = f (g1587 x) @[simp] axiom s1588 (x : Prop) : f (g1589 x) = f (g1588 x) @[simp] axiom s1589 (x : Prop) : f (g1590 x) = f (g1589 x) @[simp] axiom s1590 (x : Prop) : f (g1591 x) = f (g1590 x) @[simp] axiom s1591 (x : Prop) : f (g1592 x) = f (g1591 x) @[simp] axiom s1592 (x : Prop) : f (g1593 x) = f (g1592 x) @[simp] axiom s1593 (x : Prop) : f (g1594 x) = f (g1593 x) @[simp] axiom s1594 (x : Prop) : f (g1595 x) = f (g1594 x) @[simp] axiom s1595 (x : Prop) : f (g1596 x) = f (g1595 x) @[simp] axiom s1596 (x : Prop) : f (g1597 x) = f (g1596 x) @[simp] axiom s1597 (x : Prop) : f (g1598 x) = f (g1597 x) @[simp] axiom s1598 (x : Prop) : f (g1599 x) = f (g1598 x) @[simp] axiom s1599 (x : Prop) : f (g1600 x) = f (g1599 x) @[simp] axiom s1600 (x : Prop) : f (g1601 x) = f (g1600 x) @[simp] axiom s1601 (x : Prop) : f (g1602 x) = f (g1601 x) @[simp] axiom s1602 (x : Prop) : f (g1603 x) = f (g1602 x) @[simp] axiom s1603 (x : Prop) : f (g1604 x) = f (g1603 x) @[simp] axiom s1604 (x : Prop) : f (g1605 x) = f (g1604 x) @[simp] axiom s1605 (x : Prop) : f (g1606 x) = f (g1605 x) @[simp] axiom s1606 (x : Prop) : f (g1607 x) = f (g1606 x) @[simp] axiom s1607 (x : Prop) : f (g1608 x) = f (g1607 x) @[simp] axiom s1608 (x : Prop) : f (g1609 x) = f (g1608 x) @[simp] axiom s1609 (x : Prop) : f (g1610 x) = f (g1609 x) @[simp] axiom s1610 (x : Prop) : f (g1611 x) = f (g1610 x) @[simp] axiom s1611 (x : Prop) : f (g1612 x) = f (g1611 x) @[simp] axiom s1612 (x : Prop) : f (g1613 x) = f (g1612 x) @[simp] axiom s1613 (x : Prop) : f (g1614 x) = f (g1613 x) @[simp] axiom s1614 (x : Prop) : f (g1615 x) = f (g1614 x) @[simp] axiom s1615 (x : Prop) : f (g1616 x) = f (g1615 x) @[simp] axiom s1616 (x : Prop) : f (g1617 x) = f (g1616 x) @[simp] axiom s1617 (x : Prop) : f (g1618 x) = f (g1617 x) @[simp] axiom s1618 (x : Prop) : f (g1619 x) = f (g1618 x) @[simp] axiom s1619 (x : Prop) : f (g1620 x) = f (g1619 x) @[simp] axiom s1620 (x : Prop) : f (g1621 x) = f (g1620 x) @[simp] axiom s1621 (x : Prop) : f (g1622 x) = f (g1621 x) @[simp] axiom s1622 (x : Prop) : f (g1623 x) = f (g1622 x) @[simp] axiom s1623 (x : Prop) : f (g1624 x) = f (g1623 x) @[simp] axiom s1624 (x : Prop) : f (g1625 x) = f (g1624 x) @[simp] axiom s1625 (x : Prop) : f (g1626 x) = f (g1625 x) @[simp] axiom s1626 (x : Prop) : f (g1627 x) = f (g1626 x) @[simp] axiom s1627 (x : Prop) : f (g1628 x) = f (g1627 x) @[simp] axiom s1628 (x : Prop) : f (g1629 x) = f (g1628 x) @[simp] axiom s1629 (x : Prop) : f (g1630 x) = f (g1629 x) @[simp] axiom s1630 (x : Prop) : f (g1631 x) = f (g1630 x) @[simp] axiom s1631 (x : Prop) : f (g1632 x) = f (g1631 x) @[simp] axiom s1632 (x : Prop) : f (g1633 x) = f (g1632 x) @[simp] axiom s1633 (x : Prop) : f (g1634 x) = f (g1633 x) @[simp] axiom s1634 (x : Prop) : f (g1635 x) = f (g1634 x) @[simp] axiom s1635 (x : Prop) : f (g1636 x) = f (g1635 x) @[simp] axiom s1636 (x : Prop) : f (g1637 x) = f (g1636 x) @[simp] axiom s1637 (x : Prop) : f (g1638 x) = f (g1637 x) @[simp] axiom s1638 (x : Prop) : f (g1639 x) = f (g1638 x) @[simp] axiom s1639 (x : Prop) : f (g1640 x) = f (g1639 x) @[simp] axiom s1640 (x : Prop) : f (g1641 x) = f (g1640 x) @[simp] axiom s1641 (x : Prop) : f (g1642 x) = f (g1641 x) @[simp] axiom s1642 (x : Prop) : f (g1643 x) = f (g1642 x) @[simp] axiom s1643 (x : Prop) : f (g1644 x) = f (g1643 x) @[simp] axiom s1644 (x : Prop) : f (g1645 x) = f (g1644 x) @[simp] axiom s1645 (x : Prop) : f (g1646 x) = f (g1645 x) @[simp] axiom s1646 (x : Prop) : f (g1647 x) = f (g1646 x) @[simp] axiom s1647 (x : Prop) : f (g1648 x) = f (g1647 x) @[simp] axiom s1648 (x : Prop) : f (g1649 x) = f (g1648 x) @[simp] axiom s1649 (x : Prop) : f (g1650 x) = f (g1649 x) @[simp] axiom s1650 (x : Prop) : f (g1651 x) = f (g1650 x) @[simp] axiom s1651 (x : Prop) : f (g1652 x) = f (g1651 x) @[simp] axiom s1652 (x : Prop) : f (g1653 x) = f (g1652 x) @[simp] axiom s1653 (x : Prop) : f (g1654 x) = f (g1653 x) @[simp] axiom s1654 (x : Prop) : f (g1655 x) = f (g1654 x) @[simp] axiom s1655 (x : Prop) : f (g1656 x) = f (g1655 x) @[simp] axiom s1656 (x : Prop) : f (g1657 x) = f (g1656 x) @[simp] axiom s1657 (x : Prop) : f (g1658 x) = f (g1657 x) @[simp] axiom s1658 (x : Prop) : f (g1659 x) = f (g1658 x) @[simp] axiom s1659 (x : Prop) : f (g1660 x) = f (g1659 x) @[simp] axiom s1660 (x : Prop) : f (g1661 x) = f (g1660 x) @[simp] axiom s1661 (x : Prop) : f (g1662 x) = f (g1661 x) @[simp] axiom s1662 (x : Prop) : f (g1663 x) = f (g1662 x) @[simp] axiom s1663 (x : Prop) : f (g1664 x) = f (g1663 x) @[simp] axiom s1664 (x : Prop) : f (g1665 x) = f (g1664 x) @[simp] axiom s1665 (x : Prop) : f (g1666 x) = f (g1665 x) @[simp] axiom s1666 (x : Prop) : f (g1667 x) = f (g1666 x) @[simp] axiom s1667 (x : Prop) : f (g1668 x) = f (g1667 x) @[simp] axiom s1668 (x : Prop) : f (g1669 x) = f (g1668 x) @[simp] axiom s1669 (x : Prop) : f (g1670 x) = f (g1669 x) @[simp] axiom s1670 (x : Prop) : f (g1671 x) = f (g1670 x) @[simp] axiom s1671 (x : Prop) : f (g1672 x) = f (g1671 x) @[simp] axiom s1672 (x : Prop) : f (g1673 x) = f (g1672 x) @[simp] axiom s1673 (x : Prop) : f (g1674 x) = f (g1673 x) @[simp] axiom s1674 (x : Prop) : f (g1675 x) = f (g1674 x) @[simp] axiom s1675 (x : Prop) : f (g1676 x) = f (g1675 x) @[simp] axiom s1676 (x : Prop) : f (g1677 x) = f (g1676 x) @[simp] axiom s1677 (x : Prop) : f (g1678 x) = f (g1677 x) @[simp] axiom s1678 (x : Prop) : f (g1679 x) = f (g1678 x) @[simp] axiom s1679 (x : Prop) : f (g1680 x) = f (g1679 x) @[simp] axiom s1680 (x : Prop) : f (g1681 x) = f (g1680 x) @[simp] axiom s1681 (x : Prop) : f (g1682 x) = f (g1681 x) @[simp] axiom s1682 (x : Prop) : f (g1683 x) = f (g1682 x) @[simp] axiom s1683 (x : Prop) : f (g1684 x) = f (g1683 x) @[simp] axiom s1684 (x : Prop) : f (g1685 x) = f (g1684 x) @[simp] axiom s1685 (x : Prop) : f (g1686 x) = f (g1685 x) @[simp] axiom s1686 (x : Prop) : f (g1687 x) = f (g1686 x) @[simp] axiom s1687 (x : Prop) : f (g1688 x) = f (g1687 x) @[simp] axiom s1688 (x : Prop) : f (g1689 x) = f (g1688 x) @[simp] axiom s1689 (x : Prop) : f (g1690 x) = f (g1689 x) @[simp] axiom s1690 (x : Prop) : f (g1691 x) = f (g1690 x) @[simp] axiom s1691 (x : Prop) : f (g1692 x) = f (g1691 x) @[simp] axiom s1692 (x : Prop) : f (g1693 x) = f (g1692 x) @[simp] axiom s1693 (x : Prop) : f (g1694 x) = f (g1693 x) @[simp] axiom s1694 (x : Prop) : f (g1695 x) = f (g1694 x) @[simp] axiom s1695 (x : Prop) : f (g1696 x) = f (g1695 x) @[simp] axiom s1696 (x : Prop) : f (g1697 x) = f (g1696 x) @[simp] axiom s1697 (x : Prop) : f (g1698 x) = f (g1697 x) @[simp] axiom s1698 (x : Prop) : f (g1699 x) = f (g1698 x) @[simp] axiom s1699 (x : Prop) : f (g1700 x) = f (g1699 x) @[simp] axiom s1700 (x : Prop) : f (g1701 x) = f (g1700 x) @[simp] axiom s1701 (x : Prop) : f (g1702 x) = f (g1701 x) @[simp] axiom s1702 (x : Prop) : f (g1703 x) = f (g1702 x) @[simp] axiom s1703 (x : Prop) : f (g1704 x) = f (g1703 x) @[simp] axiom s1704 (x : Prop) : f (g1705 x) = f (g1704 x) @[simp] axiom s1705 (x : Prop) : f (g1706 x) = f (g1705 x) @[simp] axiom s1706 (x : Prop) : f (g1707 x) = f (g1706 x) @[simp] axiom s1707 (x : Prop) : f (g1708 x) = f (g1707 x) @[simp] axiom s1708 (x : Prop) : f (g1709 x) = f (g1708 x) @[simp] axiom s1709 (x : Prop) : f (g1710 x) = f (g1709 x) @[simp] axiom s1710 (x : Prop) : f (g1711 x) = f (g1710 x) @[simp] axiom s1711 (x : Prop) : f (g1712 x) = f (g1711 x) @[simp] axiom s1712 (x : Prop) : f (g1713 x) = f (g1712 x) @[simp] axiom s1713 (x : Prop) : f (g1714 x) = f (g1713 x) @[simp] axiom s1714 (x : Prop) : f (g1715 x) = f (g1714 x) @[simp] axiom s1715 (x : Prop) : f (g1716 x) = f (g1715 x) @[simp] axiom s1716 (x : Prop) : f (g1717 x) = f (g1716 x) @[simp] axiom s1717 (x : Prop) : f (g1718 x) = f (g1717 x) @[simp] axiom s1718 (x : Prop) : f (g1719 x) = f (g1718 x) @[simp] axiom s1719 (x : Prop) : f (g1720 x) = f (g1719 x) @[simp] axiom s1720 (x : Prop) : f (g1721 x) = f (g1720 x) @[simp] axiom s1721 (x : Prop) : f (g1722 x) = f (g1721 x) @[simp] axiom s1722 (x : Prop) : f (g1723 x) = f (g1722 x) @[simp] axiom s1723 (x : Prop) : f (g1724 x) = f (g1723 x) @[simp] axiom s1724 (x : Prop) : f (g1725 x) = f (g1724 x) @[simp] axiom s1725 (x : Prop) : f (g1726 x) = f (g1725 x) @[simp] axiom s1726 (x : Prop) : f (g1727 x) = f (g1726 x) @[simp] axiom s1727 (x : Prop) : f (g1728 x) = f (g1727 x) @[simp] axiom s1728 (x : Prop) : f (g1729 x) = f (g1728 x) @[simp] axiom s1729 (x : Prop) : f (g1730 x) = f (g1729 x) @[simp] axiom s1730 (x : Prop) : f (g1731 x) = f (g1730 x) @[simp] axiom s1731 (x : Prop) : f (g1732 x) = f (g1731 x) @[simp] axiom s1732 (x : Prop) : f (g1733 x) = f (g1732 x) @[simp] axiom s1733 (x : Prop) : f (g1734 x) = f (g1733 x) @[simp] axiom s1734 (x : Prop) : f (g1735 x) = f (g1734 x) @[simp] axiom s1735 (x : Prop) : f (g1736 x) = f (g1735 x) @[simp] axiom s1736 (x : Prop) : f (g1737 x) = f (g1736 x) @[simp] axiom s1737 (x : Prop) : f (g1738 x) = f (g1737 x) @[simp] axiom s1738 (x : Prop) : f (g1739 x) = f (g1738 x) @[simp] axiom s1739 (x : Prop) : f (g1740 x) = f (g1739 x) @[simp] axiom s1740 (x : Prop) : f (g1741 x) = f (g1740 x) @[simp] axiom s1741 (x : Prop) : f (g1742 x) = f (g1741 x) @[simp] axiom s1742 (x : Prop) : f (g1743 x) = f (g1742 x) @[simp] axiom s1743 (x : Prop) : f (g1744 x) = f (g1743 x) @[simp] axiom s1744 (x : Prop) : f (g1745 x) = f (g1744 x) @[simp] axiom s1745 (x : Prop) : f (g1746 x) = f (g1745 x) @[simp] axiom s1746 (x : Prop) : f (g1747 x) = f (g1746 x) @[simp] axiom s1747 (x : Prop) : f (g1748 x) = f (g1747 x) @[simp] axiom s1748 (x : Prop) : f (g1749 x) = f (g1748 x) @[simp] axiom s1749 (x : Prop) : f (g1750 x) = f (g1749 x) @[simp] axiom s1750 (x : Prop) : f (g1751 x) = f (g1750 x) @[simp] axiom s1751 (x : Prop) : f (g1752 x) = f (g1751 x) @[simp] axiom s1752 (x : Prop) : f (g1753 x) = f (g1752 x) @[simp] axiom s1753 (x : Prop) : f (g1754 x) = f (g1753 x) @[simp] axiom s1754 (x : Prop) : f (g1755 x) = f (g1754 x) @[simp] axiom s1755 (x : Prop) : f (g1756 x) = f (g1755 x) @[simp] axiom s1756 (x : Prop) : f (g1757 x) = f (g1756 x) @[simp] axiom s1757 (x : Prop) : f (g1758 x) = f (g1757 x) @[simp] axiom s1758 (x : Prop) : f (g1759 x) = f (g1758 x) @[simp] axiom s1759 (x : Prop) : f (g1760 x) = f (g1759 x) @[simp] axiom s1760 (x : Prop) : f (g1761 x) = f (g1760 x) @[simp] axiom s1761 (x : Prop) : f (g1762 x) = f (g1761 x) @[simp] axiom s1762 (x : Prop) : f (g1763 x) = f (g1762 x) @[simp] axiom s1763 (x : Prop) : f (g1764 x) = f (g1763 x) @[simp] axiom s1764 (x : Prop) : f (g1765 x) = f (g1764 x) @[simp] axiom s1765 (x : Prop) : f (g1766 x) = f (g1765 x) @[simp] axiom s1766 (x : Prop) : f (g1767 x) = f (g1766 x) @[simp] axiom s1767 (x : Prop) : f (g1768 x) = f (g1767 x) @[simp] axiom s1768 (x : Prop) : f (g1769 x) = f (g1768 x) @[simp] axiom s1769 (x : Prop) : f (g1770 x) = f (g1769 x) @[simp] axiom s1770 (x : Prop) : f (g1771 x) = f (g1770 x) @[simp] axiom s1771 (x : Prop) : f (g1772 x) = f (g1771 x) @[simp] axiom s1772 (x : Prop) : f (g1773 x) = f (g1772 x) @[simp] axiom s1773 (x : Prop) : f (g1774 x) = f (g1773 x) @[simp] axiom s1774 (x : Prop) : f (g1775 x) = f (g1774 x) @[simp] axiom s1775 (x : Prop) : f (g1776 x) = f (g1775 x) @[simp] axiom s1776 (x : Prop) : f (g1777 x) = f (g1776 x) @[simp] axiom s1777 (x : Prop) : f (g1778 x) = f (g1777 x) @[simp] axiom s1778 (x : Prop) : f (g1779 x) = f (g1778 x) @[simp] axiom s1779 (x : Prop) : f (g1780 x) = f (g1779 x) @[simp] axiom s1780 (x : Prop) : f (g1781 x) = f (g1780 x) @[simp] axiom s1781 (x : Prop) : f (g1782 x) = f (g1781 x) @[simp] axiom s1782 (x : Prop) : f (g1783 x) = f (g1782 x) @[simp] axiom s1783 (x : Prop) : f (g1784 x) = f (g1783 x) @[simp] axiom s1784 (x : Prop) : f (g1785 x) = f (g1784 x) @[simp] axiom s1785 (x : Prop) : f (g1786 x) = f (g1785 x) @[simp] axiom s1786 (x : Prop) : f (g1787 x) = f (g1786 x) @[simp] axiom s1787 (x : Prop) : f (g1788 x) = f (g1787 x) @[simp] axiom s1788 (x : Prop) : f (g1789 x) = f (g1788 x) @[simp] axiom s1789 (x : Prop) : f (g1790 x) = f (g1789 x) @[simp] axiom s1790 (x : Prop) : f (g1791 x) = f (g1790 x) @[simp] axiom s1791 (x : Prop) : f (g1792 x) = f (g1791 x) @[simp] axiom s1792 (x : Prop) : f (g1793 x) = f (g1792 x) @[simp] axiom s1793 (x : Prop) : f (g1794 x) = f (g1793 x) @[simp] axiom s1794 (x : Prop) : f (g1795 x) = f (g1794 x) @[simp] axiom s1795 (x : Prop) : f (g1796 x) = f (g1795 x) @[simp] axiom s1796 (x : Prop) : f (g1797 x) = f (g1796 x) @[simp] axiom s1797 (x : Prop) : f (g1798 x) = f (g1797 x) @[simp] axiom s1798 (x : Prop) : f (g1799 x) = f (g1798 x) @[simp] axiom s1799 (x : Prop) : f (g1800 x) = f (g1799 x) @[simp] axiom s1800 (x : Prop) : f (g1801 x) = f (g1800 x) @[simp] axiom s1801 (x : Prop) : f (g1802 x) = f (g1801 x) @[simp] axiom s1802 (x : Prop) : f (g1803 x) = f (g1802 x) @[simp] axiom s1803 (x : Prop) : f (g1804 x) = f (g1803 x) @[simp] axiom s1804 (x : Prop) : f (g1805 x) = f (g1804 x) @[simp] axiom s1805 (x : Prop) : f (g1806 x) = f (g1805 x) @[simp] axiom s1806 (x : Prop) : f (g1807 x) = f (g1806 x) @[simp] axiom s1807 (x : Prop) : f (g1808 x) = f (g1807 x) @[simp] axiom s1808 (x : Prop) : f (g1809 x) = f (g1808 x) @[simp] axiom s1809 (x : Prop) : f (g1810 x) = f (g1809 x) @[simp] axiom s1810 (x : Prop) : f (g1811 x) = f (g1810 x) @[simp] axiom s1811 (x : Prop) : f (g1812 x) = f (g1811 x) @[simp] axiom s1812 (x : Prop) : f (g1813 x) = f (g1812 x) @[simp] axiom s1813 (x : Prop) : f (g1814 x) = f (g1813 x) @[simp] axiom s1814 (x : Prop) : f (g1815 x) = f (g1814 x) @[simp] axiom s1815 (x : Prop) : f (g1816 x) = f (g1815 x) @[simp] axiom s1816 (x : Prop) : f (g1817 x) = f (g1816 x) @[simp] axiom s1817 (x : Prop) : f (g1818 x) = f (g1817 x) @[simp] axiom s1818 (x : Prop) : f (g1819 x) = f (g1818 x) @[simp] axiom s1819 (x : Prop) : f (g1820 x) = f (g1819 x) @[simp] axiom s1820 (x : Prop) : f (g1821 x) = f (g1820 x) @[simp] axiom s1821 (x : Prop) : f (g1822 x) = f (g1821 x) @[simp] axiom s1822 (x : Prop) : f (g1823 x) = f (g1822 x) @[simp] axiom s1823 (x : Prop) : f (g1824 x) = f (g1823 x) @[simp] axiom s1824 (x : Prop) : f (g1825 x) = f (g1824 x) @[simp] axiom s1825 (x : Prop) : f (g1826 x) = f (g1825 x) @[simp] axiom s1826 (x : Prop) : f (g1827 x) = f (g1826 x) @[simp] axiom s1827 (x : Prop) : f (g1828 x) = f (g1827 x) @[simp] axiom s1828 (x : Prop) : f (g1829 x) = f (g1828 x) @[simp] axiom s1829 (x : Prop) : f (g1830 x) = f (g1829 x) @[simp] axiom s1830 (x : Prop) : f (g1831 x) = f (g1830 x) @[simp] axiom s1831 (x : Prop) : f (g1832 x) = f (g1831 x) @[simp] axiom s1832 (x : Prop) : f (g1833 x) = f (g1832 x) @[simp] axiom s1833 (x : Prop) : f (g1834 x) = f (g1833 x) @[simp] axiom s1834 (x : Prop) : f (g1835 x) = f (g1834 x) @[simp] axiom s1835 (x : Prop) : f (g1836 x) = f (g1835 x) @[simp] axiom s1836 (x : Prop) : f (g1837 x) = f (g1836 x) @[simp] axiom s1837 (x : Prop) : f (g1838 x) = f (g1837 x) @[simp] axiom s1838 (x : Prop) : f (g1839 x) = f (g1838 x) @[simp] axiom s1839 (x : Prop) : f (g1840 x) = f (g1839 x) @[simp] axiom s1840 (x : Prop) : f (g1841 x) = f (g1840 x) @[simp] axiom s1841 (x : Prop) : f (g1842 x) = f (g1841 x) @[simp] axiom s1842 (x : Prop) : f (g1843 x) = f (g1842 x) @[simp] axiom s1843 (x : Prop) : f (g1844 x) = f (g1843 x) @[simp] axiom s1844 (x : Prop) : f (g1845 x) = f (g1844 x) @[simp] axiom s1845 (x : Prop) : f (g1846 x) = f (g1845 x) @[simp] axiom s1846 (x : Prop) : f (g1847 x) = f (g1846 x) @[simp] axiom s1847 (x : Prop) : f (g1848 x) = f (g1847 x) @[simp] axiom s1848 (x : Prop) : f (g1849 x) = f (g1848 x) @[simp] axiom s1849 (x : Prop) : f (g1850 x) = f (g1849 x) @[simp] axiom s1850 (x : Prop) : f (g1851 x) = f (g1850 x) @[simp] axiom s1851 (x : Prop) : f (g1852 x) = f (g1851 x) @[simp] axiom s1852 (x : Prop) : f (g1853 x) = f (g1852 x) @[simp] axiom s1853 (x : Prop) : f (g1854 x) = f (g1853 x) @[simp] axiom s1854 (x : Prop) : f (g1855 x) = f (g1854 x) @[simp] axiom s1855 (x : Prop) : f (g1856 x) = f (g1855 x) @[simp] axiom s1856 (x : Prop) : f (g1857 x) = f (g1856 x) @[simp] axiom s1857 (x : Prop) : f (g1858 x) = f (g1857 x) @[simp] axiom s1858 (x : Prop) : f (g1859 x) = f (g1858 x) @[simp] axiom s1859 (x : Prop) : f (g1860 x) = f (g1859 x) @[simp] axiom s1860 (x : Prop) : f (g1861 x) = f (g1860 x) @[simp] axiom s1861 (x : Prop) : f (g1862 x) = f (g1861 x) @[simp] axiom s1862 (x : Prop) : f (g1863 x) = f (g1862 x) @[simp] axiom s1863 (x : Prop) : f (g1864 x) = f (g1863 x) @[simp] axiom s1864 (x : Prop) : f (g1865 x) = f (g1864 x) @[simp] axiom s1865 (x : Prop) : f (g1866 x) = f (g1865 x) @[simp] axiom s1866 (x : Prop) : f (g1867 x) = f (g1866 x) @[simp] axiom s1867 (x : Prop) : f (g1868 x) = f (g1867 x) @[simp] axiom s1868 (x : Prop) : f (g1869 x) = f (g1868 x) @[simp] axiom s1869 (x : Prop) : f (g1870 x) = f (g1869 x) @[simp] axiom s1870 (x : Prop) : f (g1871 x) = f (g1870 x) @[simp] axiom s1871 (x : Prop) : f (g1872 x) = f (g1871 x) @[simp] axiom s1872 (x : Prop) : f (g1873 x) = f (g1872 x) @[simp] axiom s1873 (x : Prop) : f (g1874 x) = f (g1873 x) @[simp] axiom s1874 (x : Prop) : f (g1875 x) = f (g1874 x) @[simp] axiom s1875 (x : Prop) : f (g1876 x) = f (g1875 x) @[simp] axiom s1876 (x : Prop) : f (g1877 x) = f (g1876 x) @[simp] axiom s1877 (x : Prop) : f (g1878 x) = f (g1877 x) @[simp] axiom s1878 (x : Prop) : f (g1879 x) = f (g1878 x) @[simp] axiom s1879 (x : Prop) : f (g1880 x) = f (g1879 x) @[simp] axiom s1880 (x : Prop) : f (g1881 x) = f (g1880 x) @[simp] axiom s1881 (x : Prop) : f (g1882 x) = f (g1881 x) @[simp] axiom s1882 (x : Prop) : f (g1883 x) = f (g1882 x) @[simp] axiom s1883 (x : Prop) : f (g1884 x) = f (g1883 x) @[simp] axiom s1884 (x : Prop) : f (g1885 x) = f (g1884 x) @[simp] axiom s1885 (x : Prop) : f (g1886 x) = f (g1885 x) @[simp] axiom s1886 (x : Prop) : f (g1887 x) = f (g1886 x) @[simp] axiom s1887 (x : Prop) : f (g1888 x) = f (g1887 x) @[simp] axiom s1888 (x : Prop) : f (g1889 x) = f (g1888 x) @[simp] axiom s1889 (x : Prop) : f (g1890 x) = f (g1889 x) @[simp] axiom s1890 (x : Prop) : f (g1891 x) = f (g1890 x) @[simp] axiom s1891 (x : Prop) : f (g1892 x) = f (g1891 x) @[simp] axiom s1892 (x : Prop) : f (g1893 x) = f (g1892 x) @[simp] axiom s1893 (x : Prop) : f (g1894 x) = f (g1893 x) @[simp] axiom s1894 (x : Prop) : f (g1895 x) = f (g1894 x) @[simp] axiom s1895 (x : Prop) : f (g1896 x) = f (g1895 x) @[simp] axiom s1896 (x : Prop) : f (g1897 x) = f (g1896 x) @[simp] axiom s1897 (x : Prop) : f (g1898 x) = f (g1897 x) @[simp] axiom s1898 (x : Prop) : f (g1899 x) = f (g1898 x) @[simp] axiom s1899 (x : Prop) : f (g1900 x) = f (g1899 x) @[simp] axiom s1900 (x : Prop) : f (g1901 x) = f (g1900 x) @[simp] axiom s1901 (x : Prop) : f (g1902 x) = f (g1901 x) @[simp] axiom s1902 (x : Prop) : f (g1903 x) = f (g1902 x) @[simp] axiom s1903 (x : Prop) : f (g1904 x) = f (g1903 x) @[simp] axiom s1904 (x : Prop) : f (g1905 x) = f (g1904 x) @[simp] axiom s1905 (x : Prop) : f (g1906 x) = f (g1905 x) @[simp] axiom s1906 (x : Prop) : f (g1907 x) = f (g1906 x) @[simp] axiom s1907 (x : Prop) : f (g1908 x) = f (g1907 x) @[simp] axiom s1908 (x : Prop) : f (g1909 x) = f (g1908 x) @[simp] axiom s1909 (x : Prop) : f (g1910 x) = f (g1909 x) @[simp] axiom s1910 (x : Prop) : f (g1911 x) = f (g1910 x) @[simp] axiom s1911 (x : Prop) : f (g1912 x) = f (g1911 x) @[simp] axiom s1912 (x : Prop) : f (g1913 x) = f (g1912 x) @[simp] axiom s1913 (x : Prop) : f (g1914 x) = f (g1913 x) @[simp] axiom s1914 (x : Prop) : f (g1915 x) = f (g1914 x) @[simp] axiom s1915 (x : Prop) : f (g1916 x) = f (g1915 x) @[simp] axiom s1916 (x : Prop) : f (g1917 x) = f (g1916 x) @[simp] axiom s1917 (x : Prop) : f (g1918 x) = f (g1917 x) @[simp] axiom s1918 (x : Prop) : f (g1919 x) = f (g1918 x) @[simp] axiom s1919 (x : Prop) : f (g1920 x) = f (g1919 x) @[simp] axiom s1920 (x : Prop) : f (g1921 x) = f (g1920 x) @[simp] axiom s1921 (x : Prop) : f (g1922 x) = f (g1921 x) @[simp] axiom s1922 (x : Prop) : f (g1923 x) = f (g1922 x) @[simp] axiom s1923 (x : Prop) : f (g1924 x) = f (g1923 x) @[simp] axiom s1924 (x : Prop) : f (g1925 x) = f (g1924 x) @[simp] axiom s1925 (x : Prop) : f (g1926 x) = f (g1925 x) @[simp] axiom s1926 (x : Prop) : f (g1927 x) = f (g1926 x) @[simp] axiom s1927 (x : Prop) : f (g1928 x) = f (g1927 x) @[simp] axiom s1928 (x : Prop) : f (g1929 x) = f (g1928 x) @[simp] axiom s1929 (x : Prop) : f (g1930 x) = f (g1929 x) @[simp] axiom s1930 (x : Prop) : f (g1931 x) = f (g1930 x) @[simp] axiom s1931 (x : Prop) : f (g1932 x) = f (g1931 x) @[simp] axiom s1932 (x : Prop) : f (g1933 x) = f (g1932 x) @[simp] axiom s1933 (x : Prop) : f (g1934 x) = f (g1933 x) @[simp] axiom s1934 (x : Prop) : f (g1935 x) = f (g1934 x) @[simp] axiom s1935 (x : Prop) : f (g1936 x) = f (g1935 x) @[simp] axiom s1936 (x : Prop) : f (g1937 x) = f (g1936 x) @[simp] axiom s1937 (x : Prop) : f (g1938 x) = f (g1937 x) @[simp] axiom s1938 (x : Prop) : f (g1939 x) = f (g1938 x) @[simp] axiom s1939 (x : Prop) : f (g1940 x) = f (g1939 x) @[simp] axiom s1940 (x : Prop) : f (g1941 x) = f (g1940 x) @[simp] axiom s1941 (x : Prop) : f (g1942 x) = f (g1941 x) @[simp] axiom s1942 (x : Prop) : f (g1943 x) = f (g1942 x) @[simp] axiom s1943 (x : Prop) : f (g1944 x) = f (g1943 x) @[simp] axiom s1944 (x : Prop) : f (g1945 x) = f (g1944 x) @[simp] axiom s1945 (x : Prop) : f (g1946 x) = f (g1945 x) @[simp] axiom s1946 (x : Prop) : f (g1947 x) = f (g1946 x) @[simp] axiom s1947 (x : Prop) : f (g1948 x) = f (g1947 x) @[simp] axiom s1948 (x : Prop) : f (g1949 x) = f (g1948 x) @[simp] axiom s1949 (x : Prop) : f (g1950 x) = f (g1949 x) @[simp] axiom s1950 (x : Prop) : f (g1951 x) = f (g1950 x) @[simp] axiom s1951 (x : Prop) : f (g1952 x) = f (g1951 x) @[simp] axiom s1952 (x : Prop) : f (g1953 x) = f (g1952 x) @[simp] axiom s1953 (x : Prop) : f (g1954 x) = f (g1953 x) @[simp] axiom s1954 (x : Prop) : f (g1955 x) = f (g1954 x) @[simp] axiom s1955 (x : Prop) : f (g1956 x) = f (g1955 x) @[simp] axiom s1956 (x : Prop) : f (g1957 x) = f (g1956 x) @[simp] axiom s1957 (x : Prop) : f (g1958 x) = f (g1957 x) @[simp] axiom s1958 (x : Prop) : f (g1959 x) = f (g1958 x) @[simp] axiom s1959 (x : Prop) : f (g1960 x) = f (g1959 x) @[simp] axiom s1960 (x : Prop) : f (g1961 x) = f (g1960 x) @[simp] axiom s1961 (x : Prop) : f (g1962 x) = f (g1961 x) @[simp] axiom s1962 (x : Prop) : f (g1963 x) = f (g1962 x) @[simp] axiom s1963 (x : Prop) : f (g1964 x) = f (g1963 x) @[simp] axiom s1964 (x : Prop) : f (g1965 x) = f (g1964 x) @[simp] axiom s1965 (x : Prop) : f (g1966 x) = f (g1965 x) @[simp] axiom s1966 (x : Prop) : f (g1967 x) = f (g1966 x) @[simp] axiom s1967 (x : Prop) : f (g1968 x) = f (g1967 x) @[simp] axiom s1968 (x : Prop) : f (g1969 x) = f (g1968 x) @[simp] axiom s1969 (x : Prop) : f (g1970 x) = f (g1969 x) @[simp] axiom s1970 (x : Prop) : f (g1971 x) = f (g1970 x) @[simp] axiom s1971 (x : Prop) : f (g1972 x) = f (g1971 x) @[simp] axiom s1972 (x : Prop) : f (g1973 x) = f (g1972 x) @[simp] axiom s1973 (x : Prop) : f (g1974 x) = f (g1973 x) @[simp] axiom s1974 (x : Prop) : f (g1975 x) = f (g1974 x) @[simp] axiom s1975 (x : Prop) : f (g1976 x) = f (g1975 x) @[simp] axiom s1976 (x : Prop) : f (g1977 x) = f (g1976 x) @[simp] axiom s1977 (x : Prop) : f (g1978 x) = f (g1977 x) @[simp] axiom s1978 (x : Prop) : f (g1979 x) = f (g1978 x) @[simp] axiom s1979 (x : Prop) : f (g1980 x) = f (g1979 x) @[simp] axiom s1980 (x : Prop) : f (g1981 x) = f (g1980 x) @[simp] axiom s1981 (x : Prop) : f (g1982 x) = f (g1981 x) @[simp] axiom s1982 (x : Prop) : f (g1983 x) = f (g1982 x) @[simp] axiom s1983 (x : Prop) : f (g1984 x) = f (g1983 x) @[simp] axiom s1984 (x : Prop) : f (g1985 x) = f (g1984 x) @[simp] axiom s1985 (x : Prop) : f (g1986 x) = f (g1985 x) @[simp] axiom s1986 (x : Prop) : f (g1987 x) = f (g1986 x) @[simp] axiom s1987 (x : Prop) : f (g1988 x) = f (g1987 x) @[simp] axiom s1988 (x : Prop) : f (g1989 x) = f (g1988 x) @[simp] axiom s1989 (x : Prop) : f (g1990 x) = f (g1989 x) @[simp] axiom s1990 (x : Prop) : f (g1991 x) = f (g1990 x) @[simp] axiom s1991 (x : Prop) : f (g1992 x) = f (g1991 x) @[simp] axiom s1992 (x : Prop) : f (g1993 x) = f (g1992 x) @[simp] axiom s1993 (x : Prop) : f (g1994 x) = f (g1993 x) @[simp] axiom s1994 (x : Prop) : f (g1995 x) = f (g1994 x) @[simp] axiom s1995 (x : Prop) : f (g1996 x) = f (g1995 x) @[simp] axiom s1996 (x : Prop) : f (g1997 x) = f (g1996 x) @[simp] axiom s1997 (x : Prop) : f (g1998 x) = f (g1997 x) @[simp] axiom s1998 (x : Prop) : f (g1999 x) = f (g1998 x) @[simp] axiom s1999 (x : Prop) : f (g2000 x) = f (g1999 x) @[simp] axiom s2000 (x : Prop) : f (g2001 x) = f (g2000 x) @[simp] axiom s2001 (x : Prop) : f (g2002 x) = f (g2001 x) @[simp] axiom s2002 (x : Prop) : f (g2003 x) = f (g2002 x) @[simp] axiom s2003 (x : Prop) : f (g2004 x) = f (g2003 x) @[simp] axiom s2004 (x : Prop) : f (g2005 x) = f (g2004 x) @[simp] axiom s2005 (x : Prop) : f (g2006 x) = f (g2005 x) @[simp] axiom s2006 (x : Prop) : f (g2007 x) = f (g2006 x) @[simp] axiom s2007 (x : Prop) : f (g2008 x) = f (g2007 x) @[simp] axiom s2008 (x : Prop) : f (g2009 x) = f (g2008 x) @[simp] axiom s2009 (x : Prop) : f (g2010 x) = f (g2009 x) @[simp] axiom s2010 (x : Prop) : f (g2011 x) = f (g2010 x) @[simp] axiom s2011 (x : Prop) : f (g2012 x) = f (g2011 x) @[simp] axiom s2012 (x : Prop) : f (g2013 x) = f (g2012 x) @[simp] axiom s2013 (x : Prop) : f (g2014 x) = f (g2013 x) @[simp] axiom s2014 (x : Prop) : f (g2015 x) = f (g2014 x) @[simp] axiom s2015 (x : Prop) : f (g2016 x) = f (g2015 x) @[simp] axiom s2016 (x : Prop) : f (g2017 x) = f (g2016 x) @[simp] axiom s2017 (x : Prop) : f (g2018 x) = f (g2017 x) @[simp] axiom s2018 (x : Prop) : f (g2019 x) = f (g2018 x) @[simp] axiom s2019 (x : Prop) : f (g2020 x) = f (g2019 x) @[simp] axiom s2020 (x : Prop) : f (g2021 x) = f (g2020 x) @[simp] axiom s2021 (x : Prop) : f (g2022 x) = f (g2021 x) @[simp] axiom s2022 (x : Prop) : f (g2023 x) = f (g2022 x) @[simp] axiom s2023 (x : Prop) : f (g2024 x) = f (g2023 x) @[simp] axiom s2024 (x : Prop) : f (g2025 x) = f (g2024 x) @[simp] axiom s2025 (x : Prop) : f (g2026 x) = f (g2025 x) @[simp] axiom s2026 (x : Prop) : f (g2027 x) = f (g2026 x) @[simp] axiom s2027 (x : Prop) : f (g2028 x) = f (g2027 x) @[simp] axiom s2028 (x : Prop) : f (g2029 x) = f (g2028 x) @[simp] axiom s2029 (x : Prop) : f (g2030 x) = f (g2029 x) @[simp] axiom s2030 (x : Prop) : f (g2031 x) = f (g2030 x) @[simp] axiom s2031 (x : Prop) : f (g2032 x) = f (g2031 x) @[simp] axiom s2032 (x : Prop) : f (g2033 x) = f (g2032 x) @[simp] axiom s2033 (x : Prop) : f (g2034 x) = f (g2033 x) @[simp] axiom s2034 (x : Prop) : f (g2035 x) = f (g2034 x) @[simp] axiom s2035 (x : Prop) : f (g2036 x) = f (g2035 x) @[simp] axiom s2036 (x : Prop) : f (g2037 x) = f (g2036 x) @[simp] axiom s2037 (x : Prop) : f (g2038 x) = f (g2037 x) @[simp] axiom s2038 (x : Prop) : f (g2039 x) = f (g2038 x) @[simp] axiom s2039 (x : Prop) : f (g2040 x) = f (g2039 x) @[simp] axiom s2040 (x : Prop) : f (g2041 x) = f (g2040 x) @[simp] axiom s2041 (x : Prop) : f (g2042 x) = f (g2041 x) @[simp] axiom s2042 (x : Prop) : f (g2043 x) = f (g2042 x) @[simp] axiom s2043 (x : Prop) : f (g2044 x) = f (g2043 x) @[simp] axiom s2044 (x : Prop) : f (g2045 x) = f (g2044 x) @[simp] axiom s2045 (x : Prop) : f (g2046 x) = f (g2045 x) @[simp] axiom s2046 (x : Prop) : f (g2047 x) = f (g2046 x) @[simp] axiom s2047 (x : Prop) : f (g2048 x) = f (g2047 x) @[simp] axiom s2048 (x : Prop) : f (g2049 x) = f (g2048 x) @[simp] axiom s2049 (x : Prop) : f (g2050 x) = f (g2049 x) @[simp] axiom s2050 (x : Prop) : f (g2051 x) = f (g2050 x) @[simp] axiom s2051 (x : Prop) : f (g2052 x) = f (g2051 x) @[simp] axiom s2052 (x : Prop) : f (g2053 x) = f (g2052 x) @[simp] axiom s2053 (x : Prop) : f (g2054 x) = f (g2053 x) @[simp] axiom s2054 (x : Prop) : f (g2055 x) = f (g2054 x) @[simp] axiom s2055 (x : Prop) : f (g2056 x) = f (g2055 x) @[simp] axiom s2056 (x : Prop) : f (g2057 x) = f (g2056 x) @[simp] axiom s2057 (x : Prop) : f (g2058 x) = f (g2057 x) @[simp] axiom s2058 (x : Prop) : f (g2059 x) = f (g2058 x) @[simp] axiom s2059 (x : Prop) : f (g2060 x) = f (g2059 x) @[simp] axiom s2060 (x : Prop) : f (g2061 x) = f (g2060 x) @[simp] axiom s2061 (x : Prop) : f (g2062 x) = f (g2061 x) @[simp] axiom s2062 (x : Prop) : f (g2063 x) = f (g2062 x) @[simp] axiom s2063 (x : Prop) : f (g2064 x) = f (g2063 x) @[simp] axiom s2064 (x : Prop) : f (g2065 x) = f (g2064 x) @[simp] axiom s2065 (x : Prop) : f (g2066 x) = f (g2065 x) @[simp] axiom s2066 (x : Prop) : f (g2067 x) = f (g2066 x) @[simp] axiom s2067 (x : Prop) : f (g2068 x) = f (g2067 x) @[simp] axiom s2068 (x : Prop) : f (g2069 x) = f (g2068 x) @[simp] axiom s2069 (x : Prop) : f (g2070 x) = f (g2069 x) @[simp] axiom s2070 (x : Prop) : f (g2071 x) = f (g2070 x) @[simp] axiom s2071 (x : Prop) : f (g2072 x) = f (g2071 x) @[simp] axiom s2072 (x : Prop) : f (g2073 x) = f (g2072 x) @[simp] axiom s2073 (x : Prop) : f (g2074 x) = f (g2073 x) @[simp] axiom s2074 (x : Prop) : f (g2075 x) = f (g2074 x) @[simp] axiom s2075 (x : Prop) : f (g2076 x) = f (g2075 x) @[simp] axiom s2076 (x : Prop) : f (g2077 x) = f (g2076 x) @[simp] axiom s2077 (x : Prop) : f (g2078 x) = f (g2077 x) @[simp] axiom s2078 (x : Prop) : f (g2079 x) = f (g2078 x) @[simp] axiom s2079 (x : Prop) : f (g2080 x) = f (g2079 x) @[simp] axiom s2080 (x : Prop) : f (g2081 x) = f (g2080 x) @[simp] axiom s2081 (x : Prop) : f (g2082 x) = f (g2081 x) @[simp] axiom s2082 (x : Prop) : f (g2083 x) = f (g2082 x) @[simp] axiom s2083 (x : Prop) : f (g2084 x) = f (g2083 x) @[simp] axiom s2084 (x : Prop) : f (g2085 x) = f (g2084 x) @[simp] axiom s2085 (x : Prop) : f (g2086 x) = f (g2085 x) @[simp] axiom s2086 (x : Prop) : f (g2087 x) = f (g2086 x) @[simp] axiom s2087 (x : Prop) : f (g2088 x) = f (g2087 x) @[simp] axiom s2088 (x : Prop) : f (g2089 x) = f (g2088 x) @[simp] axiom s2089 (x : Prop) : f (g2090 x) = f (g2089 x) @[simp] axiom s2090 (x : Prop) : f (g2091 x) = f (g2090 x) @[simp] axiom s2091 (x : Prop) : f (g2092 x) = f (g2091 x) @[simp] axiom s2092 (x : Prop) : f (g2093 x) = f (g2092 x) @[simp] axiom s2093 (x : Prop) : f (g2094 x) = f (g2093 x) @[simp] axiom s2094 (x : Prop) : f (g2095 x) = f (g2094 x) @[simp] axiom s2095 (x : Prop) : f (g2096 x) = f (g2095 x) @[simp] axiom s2096 (x : Prop) : f (g2097 x) = f (g2096 x) @[simp] axiom s2097 (x : Prop) : f (g2098 x) = f (g2097 x) @[simp] axiom s2098 (x : Prop) : f (g2099 x) = f (g2098 x) @[simp] axiom s2099 (x : Prop) : f (g2100 x) = f (g2099 x) @[simp] axiom s2100 (x : Prop) : f (g2101 x) = f (g2100 x) @[simp] axiom s2101 (x : Prop) : f (g2102 x) = f (g2101 x) @[simp] axiom s2102 (x : Prop) : f (g2103 x) = f (g2102 x) @[simp] axiom s2103 (x : Prop) : f (g2104 x) = f (g2103 x) @[simp] axiom s2104 (x : Prop) : f (g2105 x) = f (g2104 x) @[simp] axiom s2105 (x : Prop) : f (g2106 x) = f (g2105 x) @[simp] axiom s2106 (x : Prop) : f (g2107 x) = f (g2106 x) @[simp] axiom s2107 (x : Prop) : f (g2108 x) = f (g2107 x) @[simp] axiom s2108 (x : Prop) : f (g2109 x) = f (g2108 x) @[simp] axiom s2109 (x : Prop) : f (g2110 x) = f (g2109 x) @[simp] axiom s2110 (x : Prop) : f (g2111 x) = f (g2110 x) @[simp] axiom s2111 (x : Prop) : f (g2112 x) = f (g2111 x) @[simp] axiom s2112 (x : Prop) : f (g2113 x) = f (g2112 x) @[simp] axiom s2113 (x : Prop) : f (g2114 x) = f (g2113 x) @[simp] axiom s2114 (x : Prop) : f (g2115 x) = f (g2114 x) @[simp] axiom s2115 (x : Prop) : f (g2116 x) = f (g2115 x) @[simp] axiom s2116 (x : Prop) : f (g2117 x) = f (g2116 x) @[simp] axiom s2117 (x : Prop) : f (g2118 x) = f (g2117 x) @[simp] axiom s2118 (x : Prop) : f (g2119 x) = f (g2118 x) @[simp] axiom s2119 (x : Prop) : f (g2120 x) = f (g2119 x) @[simp] axiom s2120 (x : Prop) : f (g2121 x) = f (g2120 x) @[simp] axiom s2121 (x : Prop) : f (g2122 x) = f (g2121 x) @[simp] axiom s2122 (x : Prop) : f (g2123 x) = f (g2122 x) @[simp] axiom s2123 (x : Prop) : f (g2124 x) = f (g2123 x) @[simp] axiom s2124 (x : Prop) : f (g2125 x) = f (g2124 x) @[simp] axiom s2125 (x : Prop) : f (g2126 x) = f (g2125 x) @[simp] axiom s2126 (x : Prop) : f (g2127 x) = f (g2126 x) @[simp] axiom s2127 (x : Prop) : f (g2128 x) = f (g2127 x) @[simp] axiom s2128 (x : Prop) : f (g2129 x) = f (g2128 x) @[simp] axiom s2129 (x : Prop) : f (g2130 x) = f (g2129 x) @[simp] axiom s2130 (x : Prop) : f (g2131 x) = f (g2130 x) @[simp] axiom s2131 (x : Prop) : f (g2132 x) = f (g2131 x) @[simp] axiom s2132 (x : Prop) : f (g2133 x) = f (g2132 x) @[simp] axiom s2133 (x : Prop) : f (g2134 x) = f (g2133 x) @[simp] axiom s2134 (x : Prop) : f (g2135 x) = f (g2134 x) @[simp] axiom s2135 (x : Prop) : f (g2136 x) = f (g2135 x) @[simp] axiom s2136 (x : Prop) : f (g2137 x) = f (g2136 x) @[simp] axiom s2137 (x : Prop) : f (g2138 x) = f (g2137 x) @[simp] axiom s2138 (x : Prop) : f (g2139 x) = f (g2138 x) @[simp] axiom s2139 (x : Prop) : f (g2140 x) = f (g2139 x) @[simp] axiom s2140 (x : Prop) : f (g2141 x) = f (g2140 x) @[simp] axiom s2141 (x : Prop) : f (g2142 x) = f (g2141 x) @[simp] axiom s2142 (x : Prop) : f (g2143 x) = f (g2142 x) @[simp] axiom s2143 (x : Prop) : f (g2144 x) = f (g2143 x) @[simp] axiom s2144 (x : Prop) : f (g2145 x) = f (g2144 x) @[simp] axiom s2145 (x : Prop) : f (g2146 x) = f (g2145 x) @[simp] axiom s2146 (x : Prop) : f (g2147 x) = f (g2146 x) @[simp] axiom s2147 (x : Prop) : f (g2148 x) = f (g2147 x) @[simp] axiom s2148 (x : Prop) : f (g2149 x) = f (g2148 x) @[simp] axiom s2149 (x : Prop) : f (g2150 x) = f (g2149 x) @[simp] axiom s2150 (x : Prop) : f (g2151 x) = f (g2150 x) @[simp] axiom s2151 (x : Prop) : f (g2152 x) = f (g2151 x) @[simp] axiom s2152 (x : Prop) : f (g2153 x) = f (g2152 x) @[simp] axiom s2153 (x : Prop) : f (g2154 x) = f (g2153 x) @[simp] axiom s2154 (x : Prop) : f (g2155 x) = f (g2154 x) @[simp] axiom s2155 (x : Prop) : f (g2156 x) = f (g2155 x) @[simp] axiom s2156 (x : Prop) : f (g2157 x) = f (g2156 x) @[simp] axiom s2157 (x : Prop) : f (g2158 x) = f (g2157 x) @[simp] axiom s2158 (x : Prop) : f (g2159 x) = f (g2158 x) @[simp] axiom s2159 (x : Prop) : f (g2160 x) = f (g2159 x) @[simp] axiom s2160 (x : Prop) : f (g2161 x) = f (g2160 x) @[simp] axiom s2161 (x : Prop) : f (g2162 x) = f (g2161 x) @[simp] axiom s2162 (x : Prop) : f (g2163 x) = f (g2162 x) @[simp] axiom s2163 (x : Prop) : f (g2164 x) = f (g2163 x) @[simp] axiom s2164 (x : Prop) : f (g2165 x) = f (g2164 x) @[simp] axiom s2165 (x : Prop) : f (g2166 x) = f (g2165 x) @[simp] axiom s2166 (x : Prop) : f (g2167 x) = f (g2166 x) @[simp] axiom s2167 (x : Prop) : f (g2168 x) = f (g2167 x) @[simp] axiom s2168 (x : Prop) : f (g2169 x) = f (g2168 x) @[simp] axiom s2169 (x : Prop) : f (g2170 x) = f (g2169 x) @[simp] axiom s2170 (x : Prop) : f (g2171 x) = f (g2170 x) @[simp] axiom s2171 (x : Prop) : f (g2172 x) = f (g2171 x) @[simp] axiom s2172 (x : Prop) : f (g2173 x) = f (g2172 x) @[simp] axiom s2173 (x : Prop) : f (g2174 x) = f (g2173 x) @[simp] axiom s2174 (x : Prop) : f (g2175 x) = f (g2174 x) @[simp] axiom s2175 (x : Prop) : f (g2176 x) = f (g2175 x) @[simp] axiom s2176 (x : Prop) : f (g2177 x) = f (g2176 x) @[simp] axiom s2177 (x : Prop) : f (g2178 x) = f (g2177 x) @[simp] axiom s2178 (x : Prop) : f (g2179 x) = f (g2178 x) @[simp] axiom s2179 (x : Prop) : f (g2180 x) = f (g2179 x) @[simp] axiom s2180 (x : Prop) : f (g2181 x) = f (g2180 x) @[simp] axiom s2181 (x : Prop) : f (g2182 x) = f (g2181 x) @[simp] axiom s2182 (x : Prop) : f (g2183 x) = f (g2182 x) @[simp] axiom s2183 (x : Prop) : f (g2184 x) = f (g2183 x) @[simp] axiom s2184 (x : Prop) : f (g2185 x) = f (g2184 x) @[simp] axiom s2185 (x : Prop) : f (g2186 x) = f (g2185 x) @[simp] axiom s2186 (x : Prop) : f (g2187 x) = f (g2186 x) @[simp] axiom s2187 (x : Prop) : f (g2188 x) = f (g2187 x) @[simp] axiom s2188 (x : Prop) : f (g2189 x) = f (g2188 x) @[simp] axiom s2189 (x : Prop) : f (g2190 x) = f (g2189 x) @[simp] axiom s2190 (x : Prop) : f (g2191 x) = f (g2190 x) @[simp] axiom s2191 (x : Prop) : f (g2192 x) = f (g2191 x) @[simp] axiom s2192 (x : Prop) : f (g2193 x) = f (g2192 x) @[simp] axiom s2193 (x : Prop) : f (g2194 x) = f (g2193 x) @[simp] axiom s2194 (x : Prop) : f (g2195 x) = f (g2194 x) @[simp] axiom s2195 (x : Prop) : f (g2196 x) = f (g2195 x) @[simp] axiom s2196 (x : Prop) : f (g2197 x) = f (g2196 x) @[simp] axiom s2197 (x : Prop) : f (g2198 x) = f (g2197 x) @[simp] axiom s2198 (x : Prop) : f (g2199 x) = f (g2198 x) @[simp] axiom s2199 (x : Prop) : f (g2200 x) = f (g2199 x) @[simp] axiom s2200 (x : Prop) : f (g2201 x) = f (g2200 x) @[simp] axiom s2201 (x : Prop) : f (g2202 x) = f (g2201 x) @[simp] axiom s2202 (x : Prop) : f (g2203 x) = f (g2202 x) @[simp] axiom s2203 (x : Prop) : f (g2204 x) = f (g2203 x) @[simp] axiom s2204 (x : Prop) : f (g2205 x) = f (g2204 x) @[simp] axiom s2205 (x : Prop) : f (g2206 x) = f (g2205 x) @[simp] axiom s2206 (x : Prop) : f (g2207 x) = f (g2206 x) @[simp] axiom s2207 (x : Prop) : f (g2208 x) = f (g2207 x) @[simp] axiom s2208 (x : Prop) : f (g2209 x) = f (g2208 x) @[simp] axiom s2209 (x : Prop) : f (g2210 x) = f (g2209 x) @[simp] axiom s2210 (x : Prop) : f (g2211 x) = f (g2210 x) @[simp] axiom s2211 (x : Prop) : f (g2212 x) = f (g2211 x) @[simp] axiom s2212 (x : Prop) : f (g2213 x) = f (g2212 x) @[simp] axiom s2213 (x : Prop) : f (g2214 x) = f (g2213 x) @[simp] axiom s2214 (x : Prop) : f (g2215 x) = f (g2214 x) @[simp] axiom s2215 (x : Prop) : f (g2216 x) = f (g2215 x) @[simp] axiom s2216 (x : Prop) : f (g2217 x) = f (g2216 x) @[simp] axiom s2217 (x : Prop) : f (g2218 x) = f (g2217 x) @[simp] axiom s2218 (x : Prop) : f (g2219 x) = f (g2218 x) @[simp] axiom s2219 (x : Prop) : f (g2220 x) = f (g2219 x) @[simp] axiom s2220 (x : Prop) : f (g2221 x) = f (g2220 x) @[simp] axiom s2221 (x : Prop) : f (g2222 x) = f (g2221 x) @[simp] axiom s2222 (x : Prop) : f (g2223 x) = f (g2222 x) @[simp] axiom s2223 (x : Prop) : f (g2224 x) = f (g2223 x) @[simp] axiom s2224 (x : Prop) : f (g2225 x) = f (g2224 x) @[simp] axiom s2225 (x : Prop) : f (g2226 x) = f (g2225 x) @[simp] axiom s2226 (x : Prop) : f (g2227 x) = f (g2226 x) @[simp] axiom s2227 (x : Prop) : f (g2228 x) = f (g2227 x) @[simp] axiom s2228 (x : Prop) : f (g2229 x) = f (g2228 x) @[simp] axiom s2229 (x : Prop) : f (g2230 x) = f (g2229 x) @[simp] axiom s2230 (x : Prop) : f (g2231 x) = f (g2230 x) @[simp] axiom s2231 (x : Prop) : f (g2232 x) = f (g2231 x) @[simp] axiom s2232 (x : Prop) : f (g2233 x) = f (g2232 x) @[simp] axiom s2233 (x : Prop) : f (g2234 x) = f (g2233 x) @[simp] axiom s2234 (x : Prop) : f (g2235 x) = f (g2234 x) @[simp] axiom s2235 (x : Prop) : f (g2236 x) = f (g2235 x) @[simp] axiom s2236 (x : Prop) : f (g2237 x) = f (g2236 x) @[simp] axiom s2237 (x : Prop) : f (g2238 x) = f (g2237 x) @[simp] axiom s2238 (x : Prop) : f (g2239 x) = f (g2238 x) @[simp] axiom s2239 (x : Prop) : f (g2240 x) = f (g2239 x) @[simp] axiom s2240 (x : Prop) : f (g2241 x) = f (g2240 x) @[simp] axiom s2241 (x : Prop) : f (g2242 x) = f (g2241 x) @[simp] axiom s2242 (x : Prop) : f (g2243 x) = f (g2242 x) @[simp] axiom s2243 (x : Prop) : f (g2244 x) = f (g2243 x) @[simp] axiom s2244 (x : Prop) : f (g2245 x) = f (g2244 x) @[simp] axiom s2245 (x : Prop) : f (g2246 x) = f (g2245 x) @[simp] axiom s2246 (x : Prop) : f (g2247 x) = f (g2246 x) @[simp] axiom s2247 (x : Prop) : f (g2248 x) = f (g2247 x) @[simp] axiom s2248 (x : Prop) : f (g2249 x) = f (g2248 x) @[simp] axiom s2249 (x : Prop) : f (g2250 x) = f (g2249 x) @[simp] axiom s2250 (x : Prop) : f (g2251 x) = f (g2250 x) @[simp] axiom s2251 (x : Prop) : f (g2252 x) = f (g2251 x) @[simp] axiom s2252 (x : Prop) : f (g2253 x) = f (g2252 x) @[simp] axiom s2253 (x : Prop) : f (g2254 x) = f (g2253 x) @[simp] axiom s2254 (x : Prop) : f (g2255 x) = f (g2254 x) @[simp] axiom s2255 (x : Prop) : f (g2256 x) = f (g2255 x) @[simp] axiom s2256 (x : Prop) : f (g2257 x) = f (g2256 x) @[simp] axiom s2257 (x : Prop) : f (g2258 x) = f (g2257 x) @[simp] axiom s2258 (x : Prop) : f (g2259 x) = f (g2258 x) @[simp] axiom s2259 (x : Prop) : f (g2260 x) = f (g2259 x) @[simp] axiom s2260 (x : Prop) : f (g2261 x) = f (g2260 x) @[simp] axiom s2261 (x : Prop) : f (g2262 x) = f (g2261 x) @[simp] axiom s2262 (x : Prop) : f (g2263 x) = f (g2262 x) @[simp] axiom s2263 (x : Prop) : f (g2264 x) = f (g2263 x) @[simp] axiom s2264 (x : Prop) : f (g2265 x) = f (g2264 x) @[simp] axiom s2265 (x : Prop) : f (g2266 x) = f (g2265 x) @[simp] axiom s2266 (x : Prop) : f (g2267 x) = f (g2266 x) @[simp] axiom s2267 (x : Prop) : f (g2268 x) = f (g2267 x) @[simp] axiom s2268 (x : Prop) : f (g2269 x) = f (g2268 x) @[simp] axiom s2269 (x : Prop) : f (g2270 x) = f (g2269 x) @[simp] axiom s2270 (x : Prop) : f (g2271 x) = f (g2270 x) @[simp] axiom s2271 (x : Prop) : f (g2272 x) = f (g2271 x) @[simp] axiom s2272 (x : Prop) : f (g2273 x) = f (g2272 x) @[simp] axiom s2273 (x : Prop) : f (g2274 x) = f (g2273 x) @[simp] axiom s2274 (x : Prop) : f (g2275 x) = f (g2274 x) @[simp] axiom s2275 (x : Prop) : f (g2276 x) = f (g2275 x) @[simp] axiom s2276 (x : Prop) : f (g2277 x) = f (g2276 x) @[simp] axiom s2277 (x : Prop) : f (g2278 x) = f (g2277 x) @[simp] axiom s2278 (x : Prop) : f (g2279 x) = f (g2278 x) @[simp] axiom s2279 (x : Prop) : f (g2280 x) = f (g2279 x) @[simp] axiom s2280 (x : Prop) : f (g2281 x) = f (g2280 x) @[simp] axiom s2281 (x : Prop) : f (g2282 x) = f (g2281 x) @[simp] axiom s2282 (x : Prop) : f (g2283 x) = f (g2282 x) @[simp] axiom s2283 (x : Prop) : f (g2284 x) = f (g2283 x) @[simp] axiom s2284 (x : Prop) : f (g2285 x) = f (g2284 x) @[simp] axiom s2285 (x : Prop) : f (g2286 x) = f (g2285 x) @[simp] axiom s2286 (x : Prop) : f (g2287 x) = f (g2286 x) @[simp] axiom s2287 (x : Prop) : f (g2288 x) = f (g2287 x) @[simp] axiom s2288 (x : Prop) : f (g2289 x) = f (g2288 x) @[simp] axiom s2289 (x : Prop) : f (g2290 x) = f (g2289 x) @[simp] axiom s2290 (x : Prop) : f (g2291 x) = f (g2290 x) @[simp] axiom s2291 (x : Prop) : f (g2292 x) = f (g2291 x) @[simp] axiom s2292 (x : Prop) : f (g2293 x) = f (g2292 x) @[simp] axiom s2293 (x : Prop) : f (g2294 x) = f (g2293 x) @[simp] axiom s2294 (x : Prop) : f (g2295 x) = f (g2294 x) @[simp] axiom s2295 (x : Prop) : f (g2296 x) = f (g2295 x) @[simp] axiom s2296 (x : Prop) : f (g2297 x) = f (g2296 x) @[simp] axiom s2297 (x : Prop) : f (g2298 x) = f (g2297 x) @[simp] axiom s2298 (x : Prop) : f (g2299 x) = f (g2298 x) @[simp] axiom s2299 (x : Prop) : f (g2300 x) = f (g2299 x) @[simp] axiom s2300 (x : Prop) : f (g2301 x) = f (g2300 x) @[simp] axiom s2301 (x : Prop) : f (g2302 x) = f (g2301 x) @[simp] axiom s2302 (x : Prop) : f (g2303 x) = f (g2302 x) @[simp] axiom s2303 (x : Prop) : f (g2304 x) = f (g2303 x) @[simp] axiom s2304 (x : Prop) : f (g2305 x) = f (g2304 x) @[simp] axiom s2305 (x : Prop) : f (g2306 x) = f (g2305 x) @[simp] axiom s2306 (x : Prop) : f (g2307 x) = f (g2306 x) @[simp] axiom s2307 (x : Prop) : f (g2308 x) = f (g2307 x) @[simp] axiom s2308 (x : Prop) : f (g2309 x) = f (g2308 x) @[simp] axiom s2309 (x : Prop) : f (g2310 x) = f (g2309 x) @[simp] axiom s2310 (x : Prop) : f (g2311 x) = f (g2310 x) @[simp] axiom s2311 (x : Prop) : f (g2312 x) = f (g2311 x) @[simp] axiom s2312 (x : Prop) : f (g2313 x) = f (g2312 x) @[simp] axiom s2313 (x : Prop) : f (g2314 x) = f (g2313 x) @[simp] axiom s2314 (x : Prop) : f (g2315 x) = f (g2314 x) @[simp] axiom s2315 (x : Prop) : f (g2316 x) = f (g2315 x) @[simp] axiom s2316 (x : Prop) : f (g2317 x) = f (g2316 x) @[simp] axiom s2317 (x : Prop) : f (g2318 x) = f (g2317 x) @[simp] axiom s2318 (x : Prop) : f (g2319 x) = f (g2318 x) @[simp] axiom s2319 (x : Prop) : f (g2320 x) = f (g2319 x) @[simp] axiom s2320 (x : Prop) : f (g2321 x) = f (g2320 x) @[simp] axiom s2321 (x : Prop) : f (g2322 x) = f (g2321 x) @[simp] axiom s2322 (x : Prop) : f (g2323 x) = f (g2322 x) @[simp] axiom s2323 (x : Prop) : f (g2324 x) = f (g2323 x) @[simp] axiom s2324 (x : Prop) : f (g2325 x) = f (g2324 x) @[simp] axiom s2325 (x : Prop) : f (g2326 x) = f (g2325 x) @[simp] axiom s2326 (x : Prop) : f (g2327 x) = f (g2326 x) @[simp] axiom s2327 (x : Prop) : f (g2328 x) = f (g2327 x) @[simp] axiom s2328 (x : Prop) : f (g2329 x) = f (g2328 x) @[simp] axiom s2329 (x : Prop) : f (g2330 x) = f (g2329 x) @[simp] axiom s2330 (x : Prop) : f (g2331 x) = f (g2330 x) @[simp] axiom s2331 (x : Prop) : f (g2332 x) = f (g2331 x) @[simp] axiom s2332 (x : Prop) : f (g2333 x) = f (g2332 x) @[simp] axiom s2333 (x : Prop) : f (g2334 x) = f (g2333 x) @[simp] axiom s2334 (x : Prop) : f (g2335 x) = f (g2334 x) @[simp] axiom s2335 (x : Prop) : f (g2336 x) = f (g2335 x) @[simp] axiom s2336 (x : Prop) : f (g2337 x) = f (g2336 x) @[simp] axiom s2337 (x : Prop) : f (g2338 x) = f (g2337 x) @[simp] axiom s2338 (x : Prop) : f (g2339 x) = f (g2338 x) @[simp] axiom s2339 (x : Prop) : f (g2340 x) = f (g2339 x) @[simp] axiom s2340 (x : Prop) : f (g2341 x) = f (g2340 x) @[simp] axiom s2341 (x : Prop) : f (g2342 x) = f (g2341 x) @[simp] axiom s2342 (x : Prop) : f (g2343 x) = f (g2342 x) @[simp] axiom s2343 (x : Prop) : f (g2344 x) = f (g2343 x) @[simp] axiom s2344 (x : Prop) : f (g2345 x) = f (g2344 x) @[simp] axiom s2345 (x : Prop) : f (g2346 x) = f (g2345 x) @[simp] axiom s2346 (x : Prop) : f (g2347 x) = f (g2346 x) @[simp] axiom s2347 (x : Prop) : f (g2348 x) = f (g2347 x) @[simp] axiom s2348 (x : Prop) : f (g2349 x) = f (g2348 x) @[simp] axiom s2349 (x : Prop) : f (g2350 x) = f (g2349 x) @[simp] axiom s2350 (x : Prop) : f (g2351 x) = f (g2350 x) @[simp] axiom s2351 (x : Prop) : f (g2352 x) = f (g2351 x) @[simp] axiom s2352 (x : Prop) : f (g2353 x) = f (g2352 x) @[simp] axiom s2353 (x : Prop) : f (g2354 x) = f (g2353 x) @[simp] axiom s2354 (x : Prop) : f (g2355 x) = f (g2354 x) @[simp] axiom s2355 (x : Prop) : f (g2356 x) = f (g2355 x) @[simp] axiom s2356 (x : Prop) : f (g2357 x) = f (g2356 x) @[simp] axiom s2357 (x : Prop) : f (g2358 x) = f (g2357 x) @[simp] axiom s2358 (x : Prop) : f (g2359 x) = f (g2358 x) @[simp] axiom s2359 (x : Prop) : f (g2360 x) = f (g2359 x) @[simp] axiom s2360 (x : Prop) : f (g2361 x) = f (g2360 x) @[simp] axiom s2361 (x : Prop) : f (g2362 x) = f (g2361 x) @[simp] axiom s2362 (x : Prop) : f (g2363 x) = f (g2362 x) @[simp] axiom s2363 (x : Prop) : f (g2364 x) = f (g2363 x) @[simp] axiom s2364 (x : Prop) : f (g2365 x) = f (g2364 x) @[simp] axiom s2365 (x : Prop) : f (g2366 x) = f (g2365 x) @[simp] axiom s2366 (x : Prop) : f (g2367 x) = f (g2366 x) @[simp] axiom s2367 (x : Prop) : f (g2368 x) = f (g2367 x) @[simp] axiom s2368 (x : Prop) : f (g2369 x) = f (g2368 x) @[simp] axiom s2369 (x : Prop) : f (g2370 x) = f (g2369 x) @[simp] axiom s2370 (x : Prop) : f (g2371 x) = f (g2370 x) @[simp] axiom s2371 (x : Prop) : f (g2372 x) = f (g2371 x) @[simp] axiom s2372 (x : Prop) : f (g2373 x) = f (g2372 x) @[simp] axiom s2373 (x : Prop) : f (g2374 x) = f (g2373 x) @[simp] axiom s2374 (x : Prop) : f (g2375 x) = f (g2374 x) @[simp] axiom s2375 (x : Prop) : f (g2376 x) = f (g2375 x) @[simp] axiom s2376 (x : Prop) : f (g2377 x) = f (g2376 x) @[simp] axiom s2377 (x : Prop) : f (g2378 x) = f (g2377 x) @[simp] axiom s2378 (x : Prop) : f (g2379 x) = f (g2378 x) @[simp] axiom s2379 (x : Prop) : f (g2380 x) = f (g2379 x) @[simp] axiom s2380 (x : Prop) : f (g2381 x) = f (g2380 x) @[simp] axiom s2381 (x : Prop) : f (g2382 x) = f (g2381 x) @[simp] axiom s2382 (x : Prop) : f (g2383 x) = f (g2382 x) @[simp] axiom s2383 (x : Prop) : f (g2384 x) = f (g2383 x) @[simp] axiom s2384 (x : Prop) : f (g2385 x) = f (g2384 x) @[simp] axiom s2385 (x : Prop) : f (g2386 x) = f (g2385 x) @[simp] axiom s2386 (x : Prop) : f (g2387 x) = f (g2386 x) @[simp] axiom s2387 (x : Prop) : f (g2388 x) = f (g2387 x) @[simp] axiom s2388 (x : Prop) : f (g2389 x) = f (g2388 x) @[simp] axiom s2389 (x : Prop) : f (g2390 x) = f (g2389 x) @[simp] axiom s2390 (x : Prop) : f (g2391 x) = f (g2390 x) @[simp] axiom s2391 (x : Prop) : f (g2392 x) = f (g2391 x) @[simp] axiom s2392 (x : Prop) : f (g2393 x) = f (g2392 x) @[simp] axiom s2393 (x : Prop) : f (g2394 x) = f (g2393 x) @[simp] axiom s2394 (x : Prop) : f (g2395 x) = f (g2394 x) @[simp] axiom s2395 (x : Prop) : f (g2396 x) = f (g2395 x) @[simp] axiom s2396 (x : Prop) : f (g2397 x) = f (g2396 x) @[simp] axiom s2397 (x : Prop) : f (g2398 x) = f (g2397 x) @[simp] axiom s2398 (x : Prop) : f (g2399 x) = f (g2398 x) @[simp] axiom s2399 (x : Prop) : f (g2400 x) = f (g2399 x) @[simp] axiom s2400 (x : Prop) : f (g2401 x) = f (g2400 x) @[simp] axiom s2401 (x : Prop) : f (g2402 x) = f (g2401 x) @[simp] axiom s2402 (x : Prop) : f (g2403 x) = f (g2402 x) @[simp] axiom s2403 (x : Prop) : f (g2404 x) = f (g2403 x) @[simp] axiom s2404 (x : Prop) : f (g2405 x) = f (g2404 x) @[simp] axiom s2405 (x : Prop) : f (g2406 x) = f (g2405 x) @[simp] axiom s2406 (x : Prop) : f (g2407 x) = f (g2406 x) @[simp] axiom s2407 (x : Prop) : f (g2408 x) = f (g2407 x) @[simp] axiom s2408 (x : Prop) : f (g2409 x) = f (g2408 x) @[simp] axiom s2409 (x : Prop) : f (g2410 x) = f (g2409 x) @[simp] axiom s2410 (x : Prop) : f (g2411 x) = f (g2410 x) @[simp] axiom s2411 (x : Prop) : f (g2412 x) = f (g2411 x) @[simp] axiom s2412 (x : Prop) : f (g2413 x) = f (g2412 x) @[simp] axiom s2413 (x : Prop) : f (g2414 x) = f (g2413 x) @[simp] axiom s2414 (x : Prop) : f (g2415 x) = f (g2414 x) @[simp] axiom s2415 (x : Prop) : f (g2416 x) = f (g2415 x) @[simp] axiom s2416 (x : Prop) : f (g2417 x) = f (g2416 x) @[simp] axiom s2417 (x : Prop) : f (g2418 x) = f (g2417 x) @[simp] axiom s2418 (x : Prop) : f (g2419 x) = f (g2418 x) @[simp] axiom s2419 (x : Prop) : f (g2420 x) = f (g2419 x) @[simp] axiom s2420 (x : Prop) : f (g2421 x) = f (g2420 x) @[simp] axiom s2421 (x : Prop) : f (g2422 x) = f (g2421 x) @[simp] axiom s2422 (x : Prop) : f (g2423 x) = f (g2422 x) @[simp] axiom s2423 (x : Prop) : f (g2424 x) = f (g2423 x) @[simp] axiom s2424 (x : Prop) : f (g2425 x) = f (g2424 x) @[simp] axiom s2425 (x : Prop) : f (g2426 x) = f (g2425 x) @[simp] axiom s2426 (x : Prop) : f (g2427 x) = f (g2426 x) @[simp] axiom s2427 (x : Prop) : f (g2428 x) = f (g2427 x) @[simp] axiom s2428 (x : Prop) : f (g2429 x) = f (g2428 x) @[simp] axiom s2429 (x : Prop) : f (g2430 x) = f (g2429 x) @[simp] axiom s2430 (x : Prop) : f (g2431 x) = f (g2430 x) @[simp] axiom s2431 (x : Prop) : f (g2432 x) = f (g2431 x) @[simp] axiom s2432 (x : Prop) : f (g2433 x) = f (g2432 x) @[simp] axiom s2433 (x : Prop) : f (g2434 x) = f (g2433 x) @[simp] axiom s2434 (x : Prop) : f (g2435 x) = f (g2434 x) @[simp] axiom s2435 (x : Prop) : f (g2436 x) = f (g2435 x) @[simp] axiom s2436 (x : Prop) : f (g2437 x) = f (g2436 x) @[simp] axiom s2437 (x : Prop) : f (g2438 x) = f (g2437 x) @[simp] axiom s2438 (x : Prop) : f (g2439 x) = f (g2438 x) @[simp] axiom s2439 (x : Prop) : f (g2440 x) = f (g2439 x) @[simp] axiom s2440 (x : Prop) : f (g2441 x) = f (g2440 x) @[simp] axiom s2441 (x : Prop) : f (g2442 x) = f (g2441 x) @[simp] axiom s2442 (x : Prop) : f (g2443 x) = f (g2442 x) @[simp] axiom s2443 (x : Prop) : f (g2444 x) = f (g2443 x) @[simp] axiom s2444 (x : Prop) : f (g2445 x) = f (g2444 x) @[simp] axiom s2445 (x : Prop) : f (g2446 x) = f (g2445 x) @[simp] axiom s2446 (x : Prop) : f (g2447 x) = f (g2446 x) @[simp] axiom s2447 (x : Prop) : f (g2448 x) = f (g2447 x) @[simp] axiom s2448 (x : Prop) : f (g2449 x) = f (g2448 x) @[simp] axiom s2449 (x : Prop) : f (g2450 x) = f (g2449 x) @[simp] axiom s2450 (x : Prop) : f (g2451 x) = f (g2450 x) @[simp] axiom s2451 (x : Prop) : f (g2452 x) = f (g2451 x) @[simp] axiom s2452 (x : Prop) : f (g2453 x) = f (g2452 x) @[simp] axiom s2453 (x : Prop) : f (g2454 x) = f (g2453 x) @[simp] axiom s2454 (x : Prop) : f (g2455 x) = f (g2454 x) @[simp] axiom s2455 (x : Prop) : f (g2456 x) = f (g2455 x) @[simp] axiom s2456 (x : Prop) : f (g2457 x) = f (g2456 x) @[simp] axiom s2457 (x : Prop) : f (g2458 x) = f (g2457 x) @[simp] axiom s2458 (x : Prop) : f (g2459 x) = f (g2458 x) @[simp] axiom s2459 (x : Prop) : f (g2460 x) = f (g2459 x) @[simp] axiom s2460 (x : Prop) : f (g2461 x) = f (g2460 x) @[simp] axiom s2461 (x : Prop) : f (g2462 x) = f (g2461 x) @[simp] axiom s2462 (x : Prop) : f (g2463 x) = f (g2462 x) @[simp] axiom s2463 (x : Prop) : f (g2464 x) = f (g2463 x) @[simp] axiom s2464 (x : Prop) : f (g2465 x) = f (g2464 x) @[simp] axiom s2465 (x : Prop) : f (g2466 x) = f (g2465 x) @[simp] axiom s2466 (x : Prop) : f (g2467 x) = f (g2466 x) @[simp] axiom s2467 (x : Prop) : f (g2468 x) = f (g2467 x) @[simp] axiom s2468 (x : Prop) : f (g2469 x) = f (g2468 x) @[simp] axiom s2469 (x : Prop) : f (g2470 x) = f (g2469 x) @[simp] axiom s2470 (x : Prop) : f (g2471 x) = f (g2470 x) @[simp] axiom s2471 (x : Prop) : f (g2472 x) = f (g2471 x) @[simp] axiom s2472 (x : Prop) : f (g2473 x) = f (g2472 x) @[simp] axiom s2473 (x : Prop) : f (g2474 x) = f (g2473 x) @[simp] axiom s2474 (x : Prop) : f (g2475 x) = f (g2474 x) @[simp] axiom s2475 (x : Prop) : f (g2476 x) = f (g2475 x) @[simp] axiom s2476 (x : Prop) : f (g2477 x) = f (g2476 x) @[simp] axiom s2477 (x : Prop) : f (g2478 x) = f (g2477 x) @[simp] axiom s2478 (x : Prop) : f (g2479 x) = f (g2478 x) @[simp] axiom s2479 (x : Prop) : f (g2480 x) = f (g2479 x) @[simp] axiom s2480 (x : Prop) : f (g2481 x) = f (g2480 x) @[simp] axiom s2481 (x : Prop) : f (g2482 x) = f (g2481 x) @[simp] axiom s2482 (x : Prop) : f (g2483 x) = f (g2482 x) @[simp] axiom s2483 (x : Prop) : f (g2484 x) = f (g2483 x) @[simp] axiom s2484 (x : Prop) : f (g2485 x) = f (g2484 x) @[simp] axiom s2485 (x : Prop) : f (g2486 x) = f (g2485 x) @[simp] axiom s2486 (x : Prop) : f (g2487 x) = f (g2486 x) @[simp] axiom s2487 (x : Prop) : f (g2488 x) = f (g2487 x) @[simp] axiom s2488 (x : Prop) : f (g2489 x) = f (g2488 x) @[simp] axiom s2489 (x : Prop) : f (g2490 x) = f (g2489 x) @[simp] axiom s2490 (x : Prop) : f (g2491 x) = f (g2490 x) @[simp] axiom s2491 (x : Prop) : f (g2492 x) = f (g2491 x) @[simp] axiom s2492 (x : Prop) : f (g2493 x) = f (g2492 x) @[simp] axiom s2493 (x : Prop) : f (g2494 x) = f (g2493 x) @[simp] axiom s2494 (x : Prop) : f (g2495 x) = f (g2494 x) @[simp] axiom s2495 (x : Prop) : f (g2496 x) = f (g2495 x) @[simp] axiom s2496 (x : Prop) : f (g2497 x) = f (g2496 x) @[simp] axiom s2497 (x : Prop) : f (g2498 x) = f (g2497 x) @[simp] axiom s2498 (x : Prop) : f (g2499 x) = f (g2498 x)
50914e1579a4a1c0281d472ae476afcf43b43817
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/computability/DFA.lean
165c409dd3a1c8de78044d357903c526a52c5e5b
[ "Apache-2.0" ]
permissive
jjgarzella/mathlib
96a345378c4e0bf26cf604aed84f90329e4896a2
395d8716c3ad03747059d482090e2bb97db612c8
refs/heads/master
1,686,480,124,379
1,625,163,323,000
1,625,163,323,000
281,190,421
2
0
Apache-2.0
1,595,268,170,000
1,595,268,169,000
null
UTF-8
Lean
false
false
4,589
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 data.fintype.basic import computability.language import tactic.norm_num /-! # Deterministic Finite Automata This file contains the definition of a Deterministic Finite Automaton (DFA), a state machine which determines whether a string (implemented as a list over an arbitrary alphabet) is in a regular set in linear time. Note that this definition allows for Automaton with infinite states, a `fintype` instance must be supplied for true DFA's. -/ universes u v /-- A DFA is a set of states (`σ`), a transition function from state to state labelled by the alphabet (`step`), a starting state (`start`) and a set of acceptance states (`accept`). -/ structure DFA (α : Type u) (σ : Type v) := (step : σ → α → σ) (start : σ) (accept : set σ) namespace DFA variables {α : Type u} {σ : Type v} (M : DFA α σ) instance [inhabited σ] : inhabited (DFA α σ) := ⟨DFA.mk (λ _ _, default σ) (default σ) ∅⟩ /-- `M.eval_from s x` evaluates `M` with input `x` starting from the state `s`. -/ def eval_from (start : σ) : list α → σ := list.foldl M.step start /-- `M.eval x` evaluates `M` with input `x` starting from the state `M.start`. -/ def eval := M.eval_from M.start /-- `M.accepts` is the language of `x` such that `M.eval x` is an accept state. -/ def accepts : language α := λ x, M.eval x ∈ M.accept lemma mem_accepts (x : list α) : x ∈ M.accepts ↔ M.eval_from M.start x ∈ M.accept := by refl lemma eval_from_of_append (start : σ) (x y : list α) : M.eval_from start (x ++ y) = M.eval_from (M.eval_from start x) y := x.foldl_append _ _ y lemma eval_from_split [fintype σ] {x : list α} {s t : σ} (hlen : fintype.card σ + 1 ≤ x.length) (hx : M.eval_from s x = t) : ∃ q a b c, x = a ++ b ++ c ∧ a.length + b.length ≤ fintype.card σ + 1 ∧ b ≠ [] ∧ M.eval_from s a = q ∧ M.eval_from q b = q ∧ M.eval_from q c = t := begin obtain ⟨⟨n, hn⟩, ⟨m, hm⟩, hneq, heq⟩ := fintype.exists_ne_map_eq_of_card_lt (λ n : fin (fintype.card σ + 1), M.eval_from s (x.take n)) (by norm_num), wlog hle : n ≤ m := le_total n m using [n m, m n], refine ⟨M.eval_from s ((x.take m).take n), (x.take m).take n, (x.take m).drop n, x.drop m, _, _, _, by refl, _⟩, { rw [list.take_append_drop, list.take_append_drop] }, { simp only [list.length_drop, list.length_take], rw [min_eq_left (hm.le.trans hlen), min_eq_left hle, nat.add_sub_cancel' hle], exact hm.le }, { intro h, have hlen' := congr_arg list.length h, simp only [list.length_drop, list.length, list.length_take] at hlen', rw [min_eq_left_of_lt, nat.sub_eq_zero_iff_le] at hlen', { apply hneq, apply le_antisymm, assumption' }, exact hm.trans_le hlen, }, have hq : M.eval_from (M.eval_from s ((x.take m).take n)) ((x.take m).drop n) = M.eval_from s ((x.take m).take n), { simp only [fin.coe_mk] at heq, rw [list.take_take, min_eq_left hle, ←eval_from_of_append, heq, ←min_eq_left hle, ←list.take_take, min_eq_left hle, list.take_append_drop] }, use hq, rwa [←hq, ←eval_from_of_append, ←eval_from_of_append, ←list.append_assoc, list.take_append_drop, list.take_append_drop] end lemma eval_from_of_pow {x y : list α} {s : σ} (hx : M.eval_from s x = s) (hy : y ∈ @language.star α {x}) : M.eval_from s y = s := begin rw language.mem_star at hy, rcases hy with ⟨ S, rfl, hS ⟩, induction S with a S ih, { refl }, { have ha := hS a (list.mem_cons_self _ _), rw set.mem_singleton_iff at ha, rw [list.join, eval_from_of_append, ha, hx], apply ih, intros z hz, exact hS z (list.mem_cons_of_mem a hz) } end lemma pumping_lemma [fintype σ] {x : list α} (hx : x ∈ M.accepts) (hlen : fintype.card σ + 1 ≤ list.length x) : ∃ a b c, x = a ++ b ++ c ∧ a.length + b.length ≤ fintype.card σ + 1 ∧ b ≠ [] ∧ {a} * language.star {b} * {c} ≤ M.accepts := begin obtain ⟨_, a, b, c, hx, hlen, hnil, rfl, hb, hc⟩ := M.eval_from_split hlen rfl, use [a, b, c, hx, hlen, hnil], intros y hy, rw language.mem_mul at hy, rcases hy with ⟨ ab, c', hab, hc', rfl ⟩, rw language.mem_mul at hab, rcases hab with ⟨ a', b', ha', hb', rfl ⟩, rw set.mem_singleton_iff at ha' hc', substs ha' hc', have h := M.eval_from_of_pow hb hb', rwa [mem_accepts, eval_from_of_append, eval_from_of_append, h, hc] end end DFA
d977914349a8ccf5aa05a2f53c1ffc2313959fee
12dabd587ce2621d9a4eff9f16e354d02e206c8e
/world06/level09.lean
d900fe579585cbc2e70410717edcb3f3ab60ed1e
[]
no_license
abdelq/natural-number-game
a1b5b8f1d52625a7addcefc97c966d3f06a48263
bbddadc6d2e78ece2e9acd40fa7702ecc2db75c2
refs/heads/master
1,668,606,478,691
1,594,175,058,000
1,594,175,058,000
278,673,209
0
1
null
null
null
null
UTF-8
Lean
false
false
300
lean
example (A B C D E F G H I J K L : Prop) (f1 : A → B) (f2 : B → E) (f3 : E → D) (f4 : D → A) (f5 : E → F) (f6 : F → C) (f7 : B → C) (f8 : F → G) (f9 : G → J) (f10 : I → J) (f11 : J → I) (f12 : I → H) (f13 : E → H) (f14 : H → K) (f15 : I → L) : A → L := begin cc, end
98b05be53a6a8ae2059513f752e3a0e2b199fa96
798dd332c1ad790518589a09bc82459fb12e5156
/analysis/topology/topological_structures.lean
f5ba3f27ce833124f28c922d40012b6a62ab1a15
[ "Apache-2.0" ]
permissive
tobiasgrosser/mathlib
b040b7eb42d5942206149371cf92c61404de3c31
120635628368ec261e031cefc6d30e0304088b03
refs/heads/master
1,644,803,442,937
1,536,663,752,000
1,536,663,907,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
47,182
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 Theory of topological monoids, groups and rings. TODO: generalize `topological_monoid` and `topological_add_monoid` to semigroups, or add a type class `topological_operator α (*)`. -/ import algebra.big_operators import order.liminf_limsup import analysis.topology.topological_space analysis.topology.continuity analysis.topology.uniform_space open classical set lattice filter topological_space local attribute [instance] classical.prop_decidable universes u v w variables {α : Type u} {β : Type v} {γ : Type w} lemma dense_or_discrete [linear_order α] {a₁ a₂ : α} (h : a₁ < a₂) : (∃a, a₁ < a ∧ a < a₂) ∨ ((∀a>a₁, a ≥ a₂) ∧ (∀a<a₂, a ≤ a₁)) := classical.or_iff_not_imp_left.2 $ assume h, ⟨assume a ha₁, le_of_not_gt $ assume ha₂, h ⟨a, ha₁, ha₂⟩, assume a ha₂, le_of_not_gt $ assume ha₁, h ⟨a, ha₁, ha₂⟩⟩ section topological_monoid /-- A topological monoid is a monoid in which the multiplication is continuous as a function `α × α → α`. -/ class topological_monoid (α : Type u) [topological_space α] [monoid α] : Prop := (continuous_mul : continuous (λp:α×α, p.1 * p.2)) section variables [topological_space α] [monoid α] [topological_monoid α] lemma continuous_mul' : continuous (λp:α×α, p.1 * p.2) := topological_monoid.continuous_mul α lemma continuous_mul [topological_space β] {f : β → α} {g : β → α} (hf : continuous f) (hg : continuous g) : continuous (λx, f x * g x) := (hf.prod_mk hg).comp continuous_mul' lemma tendsto_mul' {a b : α} : tendsto (λp:α×α, p.fst * p.snd) (nhds (a, b)) (nhds (a * b)) := continuous_iff_tendsto.mp (topological_monoid.continuous_mul α) (a, b) lemma tendsto_mul {f : β → α} {g : β → α} {x : filter β} {a b : α} (hf : tendsto f x (nhds a)) (hg : tendsto g x (nhds b)) : tendsto (λx, f x * g x) x (nhds (a * b)) := (hf.prod_mk hg).comp (by rw [←nhds_prod_eq]; exact tendsto_mul') lemma tendsto_list_prod {f : γ → β → α} {x : filter β} {a : γ → α} : ∀l:list γ, (∀c∈l, tendsto (f c) x (nhds (a c))) → tendsto (λb, (l.map (λc, f c b)).prod) x (nhds ((l.map a).prod)) | [] _ := by simp [tendsto_const_nhds] | (f :: l) h := begin simp, exact tendsto_mul (h f (list.mem_cons_self _ _)) (tendsto_list_prod l (assume c hc, h c (list.mem_cons_of_mem _ hc))) end lemma continuous_list_prod [topological_space β] {f : γ → β → α} (l : list γ) (h : ∀c∈l, continuous (f c)) : continuous (λa, (l.map (λc, f c a)).prod) := continuous_iff_tendsto.2 $ assume x, tendsto_list_prod l $ assume c hc, continuous_iff_tendsto.1 (h c hc) x end section variables [topological_space α] [comm_monoid α] [topological_monoid α] lemma tendsto_multiset_prod {f : γ → β → α} {x : filter β} {a : γ → α} (s : multiset γ) : (∀c∈s, tendsto (f c) x (nhds (a c))) → tendsto (λb, (s.map (λc, f c b)).prod) x (nhds ((s.map a).prod)) := by { rcases s with ⟨l⟩, simp, exact tendsto_list_prod l } lemma tendsto_finset_prod {f : γ → β → α} {x : filter β} {a : γ → α} (s : finset γ) : (∀c∈s, tendsto (f c) x (nhds (a c))) → tendsto (λb, s.prod (λc, f c b)) x (nhds (s.prod a)) := tendsto_multiset_prod _ lemma continuous_multiset_prod [topological_space β] {f : γ → β → α} (s : multiset γ) : (∀c∈s, continuous (f c)) → continuous (λa, (s.map (λc, f c a)).prod) := by { rcases s with ⟨l⟩, simp, exact continuous_list_prod l } lemma continuous_finset_prod [topological_space β] {f : γ → β → α} (s : finset γ) : (∀c∈s, continuous (f c)) → continuous (λa, s.prod (λc, f c a)) := continuous_multiset_prod _ end end topological_monoid section topological_add_monoid /-- A topological (additive) monoid is a monoid in which the addition is continuous as a function `α × α → α`. -/ class topological_add_monoid (α : Type u) [topological_space α] [add_monoid α] : Prop := (continuous_add : continuous (λp:α×α, p.1 + p.2)) section variables [topological_space α] [add_monoid α] [topological_add_monoid α] lemma continuous_add' : continuous (λp:α×α, p.1 + p.2) := topological_add_monoid.continuous_add α lemma continuous_add [topological_space β] {f : β → α} {g : β → α} (hf : continuous f) (hg : continuous g) : continuous (λx, f x + g x) := (hf.prod_mk hg).comp continuous_add' lemma tendsto_add' {a b : α} : tendsto (λp:α×α, p.fst + p.snd) (nhds (a, b)) (nhds (a + b)) := continuous_iff_tendsto.mp (topological_add_monoid.continuous_add α) (a, b) lemma tendsto_add {f : β → α} {g : β → α} {x : filter β} {a b : α} (hf : tendsto f x (nhds a)) (hg : tendsto g x (nhds b)) : tendsto (λx, f x + g x) x (nhds (a + b)) := (hf.prod_mk hg).comp (by rw [←nhds_prod_eq]; exact tendsto_add') lemma tendsto_list_sum {f : γ → β → α} {x : filter β} {a : γ → α} : ∀l:list γ, (∀c∈l, tendsto (f c) x (nhds (a c))) → tendsto (λb, (l.map (λc, f c b)).sum) x (nhds ((l.map a).sum)) | [] _ := by simp [tendsto_const_nhds] | (f :: l) h := begin simp, exact tendsto_add (h f (list.mem_cons_self _ _)) (tendsto_list_sum l (assume c hc, h c (list.mem_cons_of_mem _ hc))) end lemma continuous_list_sum [topological_space β] {f : γ → β → α} (l : list γ) (h : ∀c∈l, continuous (f c)) : continuous (λa, (l.map (λc, f c a)).sum) := continuous_iff_tendsto.2 $ assume x, tendsto_list_sum l $ assume c hc, continuous_iff_tendsto.1 (h c hc) x end section variables [topological_space α] [add_comm_monoid α] [topological_add_monoid α] lemma tendsto_multiset_sum {f : γ → β → α} {x : filter β} {a : γ → α} : ∀ (s : multiset γ), (∀c∈s, tendsto (f c) x (nhds (a c))) → tendsto (λb, (s.map (λc, f c b)).sum) x (nhds ((s.map a).sum)) := by rintros ⟨l⟩; simp; exact tendsto_list_sum l lemma tendsto_finset_sum {f : γ → β → α} {x : filter β} {a : γ → α} (s : finset γ) : (∀c∈s, tendsto (f c) x (nhds (a c))) → tendsto (λb, s.sum (λc, f c b)) x (nhds (s.sum a)) := tendsto_multiset_sum _ lemma continuous_multiset_sum [topological_space β] {f : γ → β → α} : ∀(s : multiset γ), (∀c∈s, continuous (f c)) → continuous (λa, (s.map (λc, f c a)).sum) := by rintros ⟨l⟩; simp; exact continuous_list_sum l lemma continuous_finset_sum [topological_space β] {f : γ → β → α} (s : finset γ) : (∀c∈s, continuous (f c)) → continuous (λa, s.sum (λc, f c a)) := continuous_multiset_sum _ end end topological_add_monoid section topological_add_group /-- A topological (additive) group is a group in which the addition and negation operations are continuous. -/ class topological_add_group (α : Type u) [topological_space α] [add_group α] extends topological_add_monoid α : Prop := (continuous_neg : continuous (λa:α, -a)) variables [topological_space α] [add_group α] lemma continuous_neg' [topological_add_group α] : continuous (λx:α, - x) := topological_add_group.continuous_neg α lemma continuous_neg [topological_add_group α] [topological_space β] {f : β → α} (hf : continuous f) : continuous (λx, - f x) := hf.comp continuous_neg' lemma tendsto_neg [topological_add_group α] {f : β → α} {x : filter β} {a : α} (hf : tendsto f x (nhds a)) : tendsto (λx, - f x) x (nhds (- a)) := hf.comp (continuous_iff_tendsto.mp (topological_add_group.continuous_neg α) a) lemma continuous_sub [topological_add_group α] [topological_space β] {f : β → α} {g : β → α} (hf : continuous f) (hg : continuous g) : continuous (λx, f x - g x) := by simp; exact continuous_add hf (continuous_neg hg) lemma continuous_sub' [topological_add_group α] : continuous (λp:α×α, p.1 - p.2) := continuous_sub continuous_fst continuous_snd lemma tendsto_sub [topological_add_group α] {f : β → α} {g : β → α} {x : filter β} {a b : α} (hf : tendsto f x (nhds a)) (hg : tendsto g x (nhds b)) : tendsto (λx, f x - g x) x (nhds (a - b)) := by simp; exact tendsto_add hf (tendsto_neg hg) end topological_add_group section uniform_add_group /-- A uniform (additive) group is a group in which the addition and negation are uniformly continuous. -/ class uniform_add_group (α : Type u) [uniform_space α] [add_group α] : Prop := (uniform_continuous_sub : uniform_continuous (λp:α×α, p.1 - p.2)) theorem uniform_add_group.mk' {α} [uniform_space α] [add_group α] (h₁ : uniform_continuous (λp:α×α, p.1 + p.2)) (h₂ : uniform_continuous (λp:α, -p)) : uniform_add_group α := ⟨(uniform_continuous_fst.prod_mk (uniform_continuous_snd.comp h₂)).comp h₁⟩ variables [uniform_space α] [add_group α] lemma uniform_continuous_sub' [uniform_add_group α] : uniform_continuous (λp:α×α, p.1 - p.2) := uniform_add_group.uniform_continuous_sub α lemma uniform_continuous_sub [uniform_add_group α] [uniform_space β] {f : β → α} {g : β → α} (hf : uniform_continuous f) (hg : uniform_continuous g) : uniform_continuous (λx, f x - g x) := (hf.prod_mk hg).comp uniform_continuous_sub' lemma uniform_continuous_neg [uniform_add_group α] [uniform_space β] {f : β → α} (hf : uniform_continuous f) : uniform_continuous (λx, - f x) := have uniform_continuous (λx, 0 - f x), from uniform_continuous_sub uniform_continuous_const hf, by simp * at * lemma uniform_continuous_neg' [uniform_add_group α] : uniform_continuous (λx:α, - x) := uniform_continuous_neg uniform_continuous_id lemma uniform_continuous_add [uniform_add_group α] [uniform_space β] {f : β → α} {g : β → α} (hf : uniform_continuous f) (hg : uniform_continuous g) : uniform_continuous (λx, f x + g x) := have uniform_continuous (λx, f x - - g x), from uniform_continuous_sub hf $ uniform_continuous_neg hg, by simp * at * lemma uniform_continuous_add' [uniform_add_group α] : uniform_continuous (λp:α×α, p.1 + p.2) := uniform_continuous_add uniform_continuous_fst uniform_continuous_snd instance uniform_add_group.to_topological_add_group [uniform_add_group α] : topological_add_group α := { continuous_add := uniform_continuous_add'.continuous, continuous_neg := uniform_continuous_neg'.continuous } end uniform_add_group /-- A topological semiring is a semiring where addition and multiplication are continuous. -/ class topological_semiring (α : Type u) [topological_space α] [semiring α] extends topological_add_monoid α, topological_monoid α : Prop /-- A topological ring is a ring where the ring operations are continuous. -/ class topological_ring (α : Type u) [topological_space α] [ring α] extends topological_add_monoid α, topological_monoid α : Prop := (continuous_neg : continuous (λa:α, -a)) instance topological_ring.to_topological_semiring [topological_space α] [ring α] [t : topological_ring α] : topological_semiring α := {..t} instance topological_ring.to_topological_add_group [topological_space α] [ring α] [t : topological_ring α] : topological_add_group α := {..t} /-- (Partially) ordered topology Also called: partially ordered spaces (pospaces). Usually ordered topology is used for a topology on linear ordered spaces, where the open intervals are open sets. This is a generalization as for each linear order where open interals are open sets, the order relation is closed. -/ class ordered_topology (α : Type*) [t : topological_space α] [partial_order α] : Prop := (is_closed_le' : is_closed (λp:α×α, p.1 ≤ p.2)) section ordered_topology section partial_order variables [topological_space α] [partial_order α] [t : ordered_topology α] include t lemma is_closed_le [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) : is_closed {b | f b ≤ g b} := continuous_iff_is_closed.mp (hf.prod_mk hg) _ t.is_closed_le' lemma is_closed_le' (a : α) : is_closed {b | b ≤ a} := is_closed_le continuous_id continuous_const lemma is_closed_ge' (a : α) : is_closed {b | a ≤ b} := is_closed_le continuous_const continuous_id lemma is_closed_Icc {a b : α} : is_closed (Icc a b) := is_closed_inter (is_closed_ge' a) (is_closed_le' b) lemma le_of_tendsto {f g : β → α} {b : filter β} {a₁ a₂ : α} (hb : b ≠ ⊥) (hf : tendsto f b (nhds a₁)) (hg : tendsto g b (nhds a₂)) (h : {b | f b ≤ g b} ∈ b.sets) : a₁ ≤ a₂ := have tendsto (λb, (f b, g b)) b (nhds (a₁, a₂)), by rw [nhds_prod_eq]; exact hf.prod_mk hg, show (a₁, a₂) ∈ {p:α×α | p.1 ≤ p.2}, from mem_of_closed_of_tendsto hb this t.is_closed_le' h private lemma is_closed_eq : is_closed {p : α × α | p.1 = p.2} := by simp [le_antisymm_iff]; exact is_closed_inter t.is_closed_le' (is_closed_le continuous_snd continuous_fst) instance ordered_topology.to_t2_space : t2_space α := { t2 := have is_open {p : α × α | p.1 ≠ p.2}, from is_closed_eq, assume a b h, let ⟨u, v, hu, hv, ha, hb, h⟩ := is_open_prod_iff.mp this a b h in ⟨u, v, hu, hv, ha, hb, set.eq_empty_iff_forall_not_mem.2 $ assume a ⟨h₁, h₂⟩, have a ≠ a, from @h (a, a) ⟨h₁, h₂⟩, this rfl⟩ } @[simp] lemma closure_le_eq [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) : closure {b | f b ≤ g b} = {b | f b ≤ g b} := closure_eq_iff_is_closed.mpr $ is_closed_le hf hg end partial_order section linear_order variables [topological_space α] [linear_order α] [t : ordered_topology α] include t lemma is_open_lt [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) : is_open {b | f b < g b} := by simp [lt_iff_not_ge, -not_le]; exact is_closed_le hg hf lemma is_open_Ioo {a b : α} : is_open (Ioo a b) := is_open_and (is_open_lt continuous_const continuous_id) (is_open_lt continuous_id continuous_const) lemma is_open_Iio {a : α} : is_open (Iio a) := is_open_lt continuous_id continuous_const end linear_order section decidable_linear_order variables [topological_space α] [decidable_linear_order α] [t : ordered_topology α] [topological_space β] {f g : β → α} include t section variables (hf : continuous f) (hg : continuous g) include hf hg lemma frontier_le_subset_eq : frontier {b | f b ≤ g b} ⊆ {b | f b = g b} := assume b ⟨hb₁, hb₂⟩, le_antisymm (by simpa [closure_le_eq hf hg] using hb₁) (not_lt.1 $ assume hb : f b < g b, have {b | f b < g b} ⊆ interior {b | f b ≤ g b}, from (subset_interior_iff_subset_of_open $ is_open_lt hf hg).mpr $ assume x, le_of_lt, have b ∈ interior {b | f b ≤ g b}, from this hb, by exact hb₂ this) lemma frontier_lt_subset_eq : frontier {b | f b < g b} ⊆ {b | f b = g b} := by rw ← frontier_compl; convert frontier_le_subset_eq hg hf; simp [ext_iff, eq_comm] lemma continuous_max : continuous (λb, max (f b) (g b)) := have ∀b∈frontier {b | f b ≤ g b}, g b = f b, from assume b hb, (frontier_le_subset_eq hf hg hb).symm, continuous_if this hg hf lemma continuous_min : continuous (λb, min (f b) (g b)) := have ∀b∈frontier {b | f b ≤ g b}, f b = g b, from assume b hb, frontier_le_subset_eq hf hg hb, continuous_if this hf hg end lemma tendsto_max {b : filter β} {a₁ a₂ : α} (hf : tendsto f b (nhds a₁)) (hg : tendsto g b (nhds a₂)) : tendsto (λb, max (f b) (g b)) b (nhds (max a₁ a₂)) := show tendsto ((λp:α×α, max p.1 p.2) ∘ (λb, (f b, g b))) b (nhds (max a₁ a₂)), from (hf.prod_mk hg).comp begin rw [←nhds_prod_eq], from continuous_iff_tendsto.mp (continuous_max continuous_fst continuous_snd) _ end lemma tendsto_min {b : filter β} {a₁ a₂ : α} (hf : tendsto f b (nhds a₁)) (hg : tendsto g b (nhds a₂)) : tendsto (λb, min (f b) (g b)) b (nhds (min a₁ a₂)) := show tendsto ((λp:α×α, min p.1 p.2) ∘ (λb, (f b, g b))) b (nhds (min a₁ a₂)), from (hf.prod_mk hg).comp begin rw [←nhds_prod_eq], from continuous_iff_tendsto.mp (continuous_min continuous_fst continuous_snd) _ end end decidable_linear_order end ordered_topology /-- Topologies generated by the open intervals. This is restricted to linear orders. Only then it is guaranteed that they are also a ordered topology. -/ class orderable_topology (α : Type*) [t : topological_space α] [partial_order α] : Prop := (topology_eq_generate_intervals : t = generate_from {s | ∃a, s = {b : α | a < b} ∨ s = {b : α | b < a}}) section orderable_topology section partial_order variables [topological_space α] [partial_order α] [t : orderable_topology α] include t lemma is_open_iff_generate_intervals {s : set α} : is_open s ↔ generate_open {s | ∃a, s = {b : α | a < b} ∨ s = {b : α | b < a}} s := by rw [t.topology_eq_generate_intervals]; refl lemma is_open_lt' (a : α) : is_open {b:α | a < b} := by rw [@is_open_iff_generate_intervals α _ _ t]; exact generate_open.basic _ ⟨a, or.inl rfl⟩ lemma is_open_gt' (a : α) : is_open {b:α | b < a} := by rw [@is_open_iff_generate_intervals α _ _ t]; exact generate_open.basic _ ⟨a, or.inr rfl⟩ lemma lt_mem_nhds {a b : α} (h : a < b) : {b | a < b} ∈ (nhds b).sets := mem_nhds_sets (is_open_lt' _) h lemma le_mem_nhds {a b : α} (h : a < b) : {b | a ≤ b} ∈ (nhds b).sets := (nhds b).sets_of_superset (lt_mem_nhds h) $ assume b hb, le_of_lt hb lemma gt_mem_nhds {a b : α} (h : a < b) : {a | a < b} ∈ (nhds a).sets := mem_nhds_sets (is_open_gt' _) h lemma ge_mem_nhds {a b : α} (h : a < b) : {a | a ≤ b} ∈ (nhds a).sets := (nhds a).sets_of_superset (gt_mem_nhds h) $ assume b hb, le_of_lt hb lemma nhds_eq_orderable {a : α} : nhds a = (⨅b<a, principal {c | b < c}) ⊓ (⨅b>a, principal {c | c < b}) := by rw [t.topology_eq_generate_intervals, nhds_generate_from]; from le_antisymm (le_inf (le_infi $ assume b, le_infi $ assume hb, infi_le_of_le {c : α | b < c} $ infi_le _ ⟨hb, b, or.inl rfl⟩) (le_infi $ assume b, le_infi $ assume hb, infi_le_of_le {c : α | c < b} $ infi_le _ ⟨hb, b, or.inr rfl⟩)) (le_infi $ assume s, le_infi $ assume ⟨ha, b, hs⟩, match s, ha, hs with | _, h, (or.inl rfl) := inf_le_left_of_le $ infi_le_of_le b $ infi_le _ h | _, h, (or.inr rfl) := inf_le_right_of_le $ infi_le_of_le b $ infi_le _ h end) lemma tendsto_orderable {f : β → α} {a : α} {x : filter β} : tendsto f x (nhds a) ↔ (∀a'<a, {b | a' < f b} ∈ x.sets) ∧ (∀a'>a, {b | a' > f b} ∈ x.sets) := by simp [@nhds_eq_orderable α _ _, tendsto_inf, tendsto_infi, tendsto_principal] /-- Also known as squeeze or sandwich theorem. -/ lemma tendsto_of_tendsto_of_tendsto_of_le_of_le {f g h : β → α} {b : filter β} {a : α} (hg : tendsto g b (nhds a)) (hh : tendsto h b (nhds a)) (hgf : {b | g b ≤ f b} ∈ b.sets) (hfh : {b | f b ≤ h b} ∈ b.sets) : tendsto f b (nhds a) := tendsto_orderable.2 ⟨assume a' h', have {b : β | a' < g b} ∈ b.sets, from (tendsto_orderable.1 hg).left a' h', by filter_upwards [this, hgf] assume a, lt_of_lt_of_le, assume a' h', have {b : β | h b < a'} ∈ b.sets, from (tendsto_orderable.1 hh).right a' h', by filter_upwards [this, hfh] assume a h₁ h₂, lt_of_le_of_lt h₂ h₁⟩ lemma nhds_orderable_unbounded {a : α} (hu : ∃u, a < u) (hl : ∃l, l < a) : nhds a = (⨅l (h₂ : l < a) u (h₂ : a < u), principal {x | l < x ∧ x < u }) := let ⟨u, hu⟩ := hu, ⟨l, hl⟩ := hl in calc nhds a = (⨅b<a, principal {c | b < c}) ⊓ (⨅b>a, principal {c | c < b}) : nhds_eq_orderable ... = (⨅b<a, principal {c | b < c} ⊓ (⨅b>a, principal {c | c < b})) : binfi_inf hl ... = (⨅l<a, (⨅u>a, principal {c | c < u} ⊓ principal {c | l < c})) : begin congr, funext x, congr, funext hx, rw [inf_comm], apply binfi_inf hu end ... = _ : by simp [inter_comm]; refl lemma tendsto_orderable_unbounded {f : β → α} {a : α} {x : filter β} (hu : ∃u, a < u) (hl : ∃l, l < a) (h : ∀l u, l < a → a < u → {b | l < f b ∧ f b < u } ∈ x.sets) : tendsto f x (nhds a) := by rw [nhds_orderable_unbounded hu hl]; from (tendsto_infi.2 $ assume l, tendsto_infi.2 $ assume hl, tendsto_infi.2 $ assume u, tendsto_infi.2 $ assume hu, tendsto_principal.2 $ h l u hl hu) end partial_order theorem induced_orderable_topology' {α : Type u} {β : Type v} [partial_order α] [ta : topological_space β] [partial_order β] [orderable_topology β] (f : α → β) (hf : ∀ {x y}, f x < f y ↔ x < y) (H₁ : ∀ {a x}, x < f a → ∃ b < a, x ≤ f b) (H₂ : ∀ {a x}, f a < x → ∃ b > a, f b ≤ x) : @orderable_topology _ (induced f ta) _ := begin letI := induced f ta, refine ⟨eq_of_nhds_eq_nhds (λ a, _)⟩, rw [nhds_induced_eq_comap, nhds_generate_from, @nhds_eq_orderable β _ _], apply le_antisymm, { rw [← map_le_iff_le_comap], refine le_inf _ _; refine le_infi (λ x, le_infi $ λ h, le_principal_iff.2 _); simp, { rcases H₁ h with ⟨b, ab, xb⟩, refine mem_infi_sets _ (mem_infi_sets ⟨ab, b, or.inl rfl⟩ (mem_principal_sets.2 _)), exact λ c hc, lt_of_le_of_lt xb (hf.2 hc) }, { rcases H₂ h with ⟨b, ab, xb⟩, refine mem_infi_sets _ (mem_infi_sets ⟨ab, b, or.inr rfl⟩ (mem_principal_sets.2 _)), exact λ c hc, lt_of_lt_of_le (hf.2 hc) xb } }, refine le_infi (λ s, le_infi $ λ hs, le_principal_iff.2 _), rcases hs with ⟨ab, b, rfl|rfl⟩, { exact mem_comap_sets.2 ⟨{x | f b < x}, mem_inf_sets_of_left $ mem_infi_sets _ $ mem_infi_sets (hf.2 ab) $ mem_principal_self _, λ x, hf.1⟩ }, { exact mem_comap_sets.2 ⟨{x | x < f b}, mem_inf_sets_of_right $ mem_infi_sets _ $ mem_infi_sets (hf.2 ab) $ mem_principal_self _, λ x, hf.1⟩ } end theorem induced_orderable_topology {α : Type u} {β : Type v} [partial_order α] [ta : topological_space β] [partial_order β] [orderable_topology β] (f : α → β) (hf : ∀ {x y}, f x < f y ↔ x < y) (H : ∀ {x y}, x < y → ∃ a, x < f a ∧ f a < y) : @orderable_topology _ (induced f ta) _ := induced_orderable_topology' f @hf (λ a x xa, let ⟨b, xb, ba⟩ := H xa in ⟨b, hf.1 ba, le_of_lt xb⟩) (λ a x ax, let ⟨b, ab, bx⟩ := H ax in ⟨b, hf.1 ab, le_of_lt bx⟩) lemma nhds_top_orderable [topological_space α] [order_top α] [orderable_topology α] : nhds (⊤:α) = (⨅l (h₂ : l < ⊤), principal {x | l < x}) := by rw [@nhds_eq_orderable α _ _]; simp [(>)] lemma nhds_bot_orderable [topological_space α] [order_bot α] [orderable_topology α] : nhds (⊥:α) = (⨅l (h₂ : ⊥ < l), principal {x | x < l}) := by rw [@nhds_eq_orderable α _ _]; simp section linear_order variables [topological_space α] [linear_order α] [t : orderable_topology α] include t lemma mem_nhds_orderable_dest {a : α} {s : set α} (hs : s ∈ (nhds a).sets) : ((∃u, u>a) → ∃u, a < u ∧ ∀b, a ≤ b → b < u → b ∈ s) ∧ ((∃l, l<a) → ∃l, l < a ∧ ∀b, l < b → b ≤ a → b ∈ s) := let ⟨t₁, ht₁, t₂, ht₂, hts⟩ := mem_inf_sets.mp $ by rw [@nhds_eq_orderable α _ _ _] at hs; exact hs in have ht₁ : ((∃l, l<a) → ∃l, l < a ∧ ∀b, l < b → b ∈ t₁) ∧ (∀b, a ≤ b → b ∈ t₁), from infi_sets_induct ht₁ (by simp {contextual := tt}) (assume a' s₁ s₂ hs₁ ⟨hs₂, hs₃⟩, begin by_cases a' < a, { simp [h] at hs₁, letI := classical.DLO α, exact ⟨assume hx, let ⟨u, hu₁, hu₂⟩ := hs₂ hx in ⟨max u a', max_lt hu₁ h, assume b hb, ⟨hs₁ $ lt_of_le_of_lt (le_max_right _ _) hb, hu₂ _ $ lt_of_le_of_lt (le_max_left _ _) hb⟩⟩, assume b hb, ⟨hs₁ $ lt_of_lt_of_le h hb, hs₃ _ hb⟩⟩ }, { simp [h] at hs₁, simp [hs₁], exact ⟨by simpa using hs₂, hs₃⟩ } end) (assume s₁ s₂ h ih, and.intro (assume hx, let ⟨u, hu₁, hu₂⟩ := ih.left hx in ⟨u, hu₁, assume b hb, h $ hu₂ _ hb⟩) (assume b hb, h $ ih.right _ hb)), have ht₂ : ((∃u, u>a) → ∃u, a < u ∧ ∀b, b < u → b ∈ t₂) ∧ (∀b, b ≤ a → b ∈ t₂), from infi_sets_induct ht₂ (by simp {contextual := tt}) (assume a' s₁ s₂ hs₁ ⟨hs₂, hs₃⟩, begin by_cases a' > a, { simp [h] at hs₁, letI := classical.DLO α, exact ⟨assume hx, let ⟨u, hu₁, hu₂⟩ := hs₂ hx in ⟨min u a', lt_min hu₁ h, assume b hb, ⟨hs₁ $ lt_of_lt_of_le hb (min_le_right _ _), hu₂ _ $ lt_of_lt_of_le hb (min_le_left _ _)⟩⟩, assume b hb, ⟨hs₁ $ lt_of_le_of_lt hb h, hs₃ _ hb⟩⟩ }, { simp [h] at hs₁, simp [hs₁], exact ⟨by simpa using hs₂, hs₃⟩ } end) (assume s₁ s₂ h ih, and.intro (assume hx, let ⟨u, hu₁, hu₂⟩ := ih.left hx in ⟨u, hu₁, assume b hb, h $ hu₂ _ hb⟩) (assume b hb, h $ ih.right _ hb)), and.intro (assume hx, let ⟨u, hu, h⟩ := ht₂.left hx in ⟨u, hu, assume b hb hbu, hts ⟨ht₁.right b hb, h _ hbu⟩⟩) (assume hx, let ⟨l, hl, h⟩ := ht₁.left hx in ⟨l, hl, assume b hbl hb, hts ⟨h _ hbl, ht₂.right b hb⟩⟩) lemma mem_nhds_unbounded {a : α} {s : set α} (hu : ∃u, a < u) (hl : ∃l, l < a) : s ∈ (nhds a).sets ↔ (∃l u, l < a ∧ a < u ∧ ∀b, l < b → b < u → b ∈ s) := let ⟨l, hl'⟩ := hl, ⟨u, hu'⟩ := hu in have nhds a = (⨅p : {l // l < a} × {u // a < u}, principal {x | p.1.val < x ∧ x < p.2.val }), by simp [nhds_orderable_unbounded hu hl, infi_subtype, infi_prod], iff.intro (assume hs, by rw [this] at hs; from infi_sets_induct hs ⟨l, u, hl', hu', by simp⟩ begin intro p, rcases p with ⟨⟨l, hl⟩, ⟨u, hu⟩⟩, simp [set.subset_def], intros s₁ s₂ hs₁ l' hl' u' hu' hs₂, letI := classical.DLO α, refine ⟨max l l', _, min u u', _⟩; simp [*, lt_min_iff, max_lt_iff] {contextual := tt} end (assume s₁ s₂ h ⟨l, u, h₁, h₂, h₃⟩, ⟨l, u, h₁, h₂, assume b hu hl, h $ h₃ _ hu hl⟩)) (assume ⟨l, u, hl, hu, h⟩, by rw [this]; exact mem_infi_sets ⟨⟨l, hl⟩, ⟨u, hu⟩⟩ (assume b ⟨h₁, h₂⟩, h b h₁ h₂)) lemma order_separated {a₁ a₂ : α} (h : a₁ < a₂) : ∃u v : set α, is_open u ∧ is_open v ∧ a₁ ∈ u ∧ a₂ ∈ v ∧ (∀b₁∈u, ∀b₂∈v, b₁ < b₂) := match dense_or_discrete h with | or.inl ⟨a, ha₁, ha₂⟩ := ⟨{a' | a' < a}, {a' | a < a'}, is_open_gt' a, is_open_lt' a, ha₁, ha₂, assume b₁ h₁ b₂ h₂, lt_trans h₁ h₂⟩ | or.inr ⟨h₁, h₂⟩ := ⟨{a | a < a₂}, {a | a₁ < a}, is_open_gt' a₂, is_open_lt' a₁, h, h, assume b₁ hb₁ b₂ hb₂, calc b₁ ≤ a₁ : h₂ _ hb₁ ... < a₂ : h ... ≤ b₂ : h₁ _ hb₂⟩ end instance orderable_topology.to_ordered_topology : ordered_topology α := { is_closed_le' := is_open_prod_iff.mpr $ assume a₁ a₂ (h : ¬ a₁ ≤ a₂), have h : a₂ < a₁, from lt_of_not_ge h, let ⟨u, v, hu, hv, ha₁, ha₂, h⟩ := order_separated h in ⟨v, u, hv, hu, ha₂, ha₁, assume ⟨b₁, b₂⟩ ⟨h₁, h₂⟩, not_le_of_gt $ h b₂ h₂ b₁ h₁⟩ } instance orderable_topology.t2_space : t2_space α := by apply_instance instance orderable_topology.regular_space : regular_space α := { regular := assume s a hs ha, have -s ∈ (nhds a).sets, from mem_nhds_sets hs ha, let ⟨h₁, h₂⟩ := mem_nhds_orderable_dest this in have ∃t:set α, is_open t ∧ (∀l∈ s, l < a → l ∈ t) ∧ nhds a ⊓ principal t = ⊥, from by_cases (assume h : ∃l, l < a, let ⟨l, hl, h⟩ := h₂ h in match dense_or_discrete hl with | or.inl ⟨b, hb₁, hb₂⟩ := ⟨{a | a < b}, is_open_gt' _, assume c hcs hca, show c < b, from lt_of_not_ge $ assume hbc, h c (lt_of_lt_of_le hb₁ hbc) (le_of_lt hca) hcs, inf_principal_eq_bot $ (nhds a).sets_of_superset (mem_nhds_sets (is_open_lt' _) hb₂) $ assume x (hx : b < x), show ¬ x < b, from not_lt.2 $ le_of_lt hx⟩ | or.inr ⟨h₁, h₂⟩ := ⟨{a' | a' < a}, is_open_gt' _, assume b hbs hba, hba, inf_principal_eq_bot $ (nhds a).sets_of_superset (mem_nhds_sets (is_open_lt' _) hl) $ assume x (hx : l < x), show ¬ x < a, from not_lt.2 $ h₁ _ hx⟩ end) (assume : ¬ ∃l, l < a, ⟨∅, is_open_empty, assume l _ hl, (this ⟨l, hl⟩).elim, by rw [principal_empty, inf_bot_eq]⟩), let ⟨t₁, ht₁o, ht₁s, ht₁a⟩ := this in have ∃t:set α, is_open t ∧ (∀u∈ s, u>a → u ∈ t) ∧ nhds a ⊓ principal t = ⊥, from by_cases (assume h : ∃u, u > a, let ⟨u, hu, h⟩ := h₁ h in match dense_or_discrete hu with | or.inl ⟨b, hb₁, hb₂⟩ := ⟨{a | b < a}, is_open_lt' _, assume c hcs hca, show c > b, from lt_of_not_ge $ assume hbc, h c (le_of_lt hca) (lt_of_le_of_lt hbc hb₂) hcs, inf_principal_eq_bot $ (nhds a).sets_of_superset (mem_nhds_sets (is_open_gt' _) hb₁) $ assume x (hx : b > x), show ¬ x > b, from not_lt.2 $ le_of_lt hx⟩ | or.inr ⟨h₁, h₂⟩ := ⟨{a' | a' > a}, is_open_lt' _, assume b hbs hba, hba, inf_principal_eq_bot $ (nhds a).sets_of_superset (mem_nhds_sets (is_open_gt' _) hu) $ assume x (hx : u > x), show ¬ x > a, from not_lt.2 $ h₂ _ hx⟩ end) (assume : ¬ ∃u, u > a, ⟨∅, is_open_empty, assume l _ hl, (this ⟨l, hl⟩).elim, by rw [principal_empty, inf_bot_eq]⟩), let ⟨t₂, ht₂o, ht₂s, ht₂a⟩ := this in ⟨t₁ ∪ t₂, is_open_union ht₁o ht₂o, assume x hx, have x ≠ a, from assume eq, ha $ eq ▸ hx, (ne_iff_lt_or_gt.mp this).imp (ht₁s _ hx) (ht₂s _ hx), by rw [←sup_principal, inf_sup_left, ht₁a, ht₂a, bot_sup_eq]⟩, ..orderable_topology.t2_space } end linear_order lemma preimage_neg [add_group α] : preimage (has_neg.neg : α → α) = image (has_neg.neg : α → α) := (image_eq_preimage_of_inverse neg_neg neg_neg).symm lemma filter.map_neg [add_group α] : map (has_neg.neg : α → α) = comap (has_neg.neg : α → α) := funext $ assume f, map_eq_comap_of_inverse (funext neg_neg) (funext neg_neg) section topological_add_group variables [topological_space α] [ordered_comm_group α] [orderable_topology α] [topological_add_group α] lemma neg_preimage_closure {s : set α} : (λr:α, -r) ⁻¹' closure s = closure ((λr:α, -r) '' s) := have (λr:α, -r) ∘ (λr:α, -r) = id, from funext neg_neg, by rw [preimage_neg]; exact (subset.antisymm (image_closure_subset_closure_image continuous_neg') $ calc closure ((λ (r : α), -r) '' s) = (λr, -r) '' ((λr, -r) '' closure ((λ (r : α), -r) '' s)) : by rw [←image_comp, this, image_id] ... ⊆ (λr, -r) '' closure ((λr, -r) '' ((λ (r : α), -r) '' s)) : mono_image $ image_closure_subset_closure_image continuous_neg' ... = _ : by rw [←image_comp, this, image_id]) end topological_add_group section order_topology variables [topological_space α] [topological_space β] [decidable_linear_order α] [decidable_linear_order β] [orderable_topology α] [orderable_topology β] lemma nhds_principal_ne_bot_of_is_lub {a : α} {s : set α} (ha : is_lub s a) (hs : s ≠ ∅) : nhds a ⊓ principal s ≠ ⊥ := let ⟨a', ha'⟩ := exists_mem_of_ne_empty hs in forall_sets_neq_empty_iff_neq_bot.mp $ assume t ht, let ⟨t₁, ht₁, t₂, ht₂, ht⟩ := mem_inf_sets.mp ht in let ⟨hu, hl⟩ := mem_nhds_orderable_dest ht₁ in by_cases (assume h : a = a', have a ∈ t₁, from mem_of_nhds ht₁, have a ∈ t₂, from ht₂ $ by rwa [h], ne_empty_iff_exists_mem.mpr ⟨a, ht ⟨‹a ∈ t₁›, ‹a ∈ t₂›⟩⟩) (assume : a ≠ a', have a' < a, from lt_of_le_of_ne (ha.left _ ‹a' ∈ s›) this.symm, let ⟨l, hl, hlt₁⟩ := hl ⟨a', this⟩ in have ∃a'∈s, l < a', from classical.by_contradiction $ assume : ¬ ∃a'∈s, l < a', have ∀a'∈s, a' ≤ l, from assume a ha, not_lt.1 $ assume ha', this ⟨a, ha, ha'⟩, have ¬ l < a, from not_lt.2 $ ha.right _ this, this ‹l < a›, let ⟨a', ha', ha'l⟩ := this in have a' ∈ t₁, from hlt₁ _ ‹l < a'› $ ha.left _ ha', ne_empty_iff_exists_mem.mpr ⟨a', ht ⟨‹a' ∈ t₁›, ht₂ ‹a' ∈ s›⟩⟩) lemma nhds_principal_ne_bot_of_is_glb {a : α} {s : set α} (ha : is_glb s a) (hs : s ≠ ∅) : nhds a ⊓ principal s ≠ ⊥ := let ⟨a', ha'⟩ := exists_mem_of_ne_empty hs in forall_sets_neq_empty_iff_neq_bot.mp $ assume t ht, let ⟨t₁, ht₁, t₂, ht₂, ht⟩ := mem_inf_sets.mp ht in let ⟨hu, hl⟩ := mem_nhds_orderable_dest ht₁ in by_cases (assume h : a = a', have a ∈ t₁, from mem_of_nhds ht₁, have a ∈ t₂, from ht₂ $ by rwa [h], ne_empty_iff_exists_mem.mpr ⟨a, ht ⟨‹a ∈ t₁›, ‹a ∈ t₂›⟩⟩) (assume : a ≠ a', have a < a', from lt_of_le_of_ne (ha.left _ ‹a' ∈ s›) this, let ⟨u, hu, hut₁⟩ := hu ⟨a', this⟩ in have ∃a'∈s, a' < u, from classical.by_contradiction $ assume : ¬ ∃a'∈s, a' < u, have ∀a'∈s, u ≤ a', from assume a ha, not_lt.1 $ assume ha', this ⟨a, ha, ha'⟩, have ¬ a < u, from not_lt.2 $ ha.right _ this, this ‹a < u›, let ⟨a', ha', ha'l⟩ := this in have a' ∈ t₁, from hut₁ _ (ha.left _ ha') ‹a' < u›, ne_empty_iff_exists_mem.mpr ⟨a', ht ⟨‹a' ∈ t₁›, ht₂ ‹a' ∈ s›⟩⟩) lemma is_lub_of_mem_nhds {s : set α} {a : α} {f : filter α} (hsa : a ∈ upper_bounds s) (hsf : s ∈ f.sets) (hfa : f ⊓ nhds a ≠ ⊥) : is_lub s a := ⟨hsa, assume b hb, not_lt.1 $ assume hba, have s ∩ {a | b < a} ∈ (f ⊓ nhds a).sets, from inter_mem_inf_sets hsf (mem_nhds_sets (is_open_lt' _) hba), let ⟨x, ⟨hxs, hxb⟩⟩ := inhabited_of_mem_sets hfa this in have b < b, from lt_of_lt_of_le hxb $ hb _ hxs, lt_irrefl b this⟩ lemma is_glb_of_mem_nhds {s : set α} {a : α} {f : filter α} (hsa : a ∈ lower_bounds s) (hsf : s ∈ f.sets) (hfa : f ⊓ nhds a ≠ ⊥) : is_glb s a := ⟨hsa, assume b hb, not_lt.1 $ assume hba, have s ∩ {a | a < b} ∈ (f ⊓ nhds a).sets, from inter_mem_inf_sets hsf (mem_nhds_sets (is_open_gt' _) hba), let ⟨x, ⟨hxs, hxb⟩⟩ := inhabited_of_mem_sets hfa this in have b < b, from lt_of_le_of_lt (hb _ hxs) hxb, lt_irrefl b this⟩ lemma is_lub_of_is_lub_of_tendsto {f : α → β} {s : set α} {a : α} {b : β} (hf : ∀x∈s, ∀y∈s, x ≤ y → f x ≤ f y) (ha : is_lub s a) (hs : s ≠ ∅) (hb : tendsto f (nhds a ⊓ principal s) (nhds b)) : is_lub (f '' s) b := have hnbot : (nhds a ⊓ principal s) ≠ ⊥, from nhds_principal_ne_bot_of_is_lub ha hs, have ∀a'∈s, ¬ b < f a', from assume a' ha' h, have {x | x < f a'} ∈ (nhds b).sets, from mem_nhds_sets (is_open_gt' _) h, let ⟨t₁, ht₁, t₂, ht₂, hs⟩ := mem_inf_sets.mp (hb this) in by_cases (assume h : a = a', have a ∈ t₁ ∩ t₂, from ⟨mem_of_nhds ht₁, ht₂ $ by rwa [h]⟩, have f a < f a', from hs this, lt_irrefl (f a') $ by rwa [h] at this) (assume h : a ≠ a', have a' < a, from lt_of_le_of_ne (ha.left _ ha') h.symm, have {x | a' < x} ∈ (nhds a).sets, from mem_nhds_sets (is_open_lt' _) this, have {x | a' < x} ∩ t₁ ∈ (nhds a).sets, from inter_mem_sets this ht₁, have ({x | a' < x} ∩ t₁) ∩ s ∈ (nhds a ⊓ principal s).sets, from inter_mem_inf_sets this (subset.refl s), let ⟨x, ⟨hx₁, hx₂⟩, hx₃⟩ := inhabited_of_mem_sets hnbot this in have hxa' : f x < f a', from hs ⟨hx₂, ht₂ hx₃⟩, have ha'x : f a' ≤ f x, from hf _ ha' _ hx₃ $ le_of_lt hx₁, lt_irrefl _ (lt_of_le_of_lt ha'x hxa')), and.intro (assume b' ⟨a', ha', h_eq⟩, h_eq ▸ not_lt.1 $ this _ ha') (assume b' hb', le_of_tendsto hnbot hb tendsto_const_nhds $ mem_inf_sets_of_right $ assume x hx, hb' _ $ mem_image_of_mem _ hx) lemma is_glb_of_is_glb_of_tendsto {f : α → β} {s : set α} {a : α} {b : β} (hf : ∀x∈s, ∀y∈s, x ≤ y → f x ≤ f y) (ha : is_glb s a) (hs : s ≠ ∅) (hb : tendsto f (nhds a ⊓ principal s) (nhds b)) : is_glb (f '' s) b := have hnbot : (nhds a ⊓ principal s) ≠ ⊥, from nhds_principal_ne_bot_of_is_glb ha hs, have ∀a'∈s, ¬ b > f a', from assume a' ha' h, have {x | x > f a'} ∈ (nhds b).sets, from mem_nhds_sets (is_open_lt' _) h, let ⟨t₁, ht₁, t₂, ht₂, hs⟩ := mem_inf_sets.mp (hb this) in by_cases (assume h : a = a', have a ∈ t₁ ∩ t₂, from ⟨mem_of_nhds ht₁, ht₂ $ by rwa [h]⟩, have f a > f a', from hs this, lt_irrefl (f a') $ by rwa [h] at this) (assume h : a ≠ a', have a' > a, from lt_of_le_of_ne (ha.left _ ha') h, have {x | a' > x} ∈ (nhds a).sets, from mem_nhds_sets (is_open_gt' _) this, have {x | a' > x} ∩ t₁ ∈ (nhds a).sets, from inter_mem_sets this ht₁, have ({x | a' > x} ∩ t₁) ∩ s ∈ (nhds a ⊓ principal s).sets, from inter_mem_inf_sets this (subset.refl s), let ⟨x, ⟨hx₁, hx₂⟩, hx₃⟩ := inhabited_of_mem_sets hnbot this in have hxa' : f x > f a', from hs ⟨hx₂, ht₂ hx₃⟩, have ha'x : f a' ≥ f x, from hf _ hx₃ _ ha' $ le_of_lt hx₁, lt_irrefl _ (lt_of_lt_of_le hxa' ha'x)), and.intro (assume b' ⟨a', ha', h_eq⟩, h_eq ▸ not_lt.1 $ this _ ha') (assume b' hb', le_of_tendsto hnbot tendsto_const_nhds hb $ mem_inf_sets_of_right $ assume x hx, hb' _ $ mem_image_of_mem _ hx) lemma is_glb_of_is_lub_of_tendsto {f : α → β} {s : set α} {a : α} {b : β} (hf : ∀x∈s, ∀y∈s, x ≤ y → f y ≤ f x) (ha : is_lub s a) (hs : s ≠ ∅) (hb : tendsto f (nhds a ⊓ principal s) (nhds b)) : is_glb (f '' s) b := have hnbot : (nhds a ⊓ principal s) ≠ ⊥, from nhds_principal_ne_bot_of_is_lub ha hs, have ∀a'∈s, ¬ b > f a', from assume a' ha' h, have {x | x > f a'} ∈ (nhds b).sets, from mem_nhds_sets (is_open_lt' _) h, let ⟨t₁, ht₁, t₂, ht₂, hs⟩ := mem_inf_sets.mp (hb this) in by_cases (assume h : a = a', have a ∈ t₁ ∩ t₂, from ⟨mem_of_nhds ht₁, ht₂ $ by rwa [h]⟩, have f a > f a', from hs this, lt_irrefl (f a') $ by rwa [h] at this) (assume h : a ≠ a', have a' < a, from lt_of_le_of_ne (ha.left _ ha') h.symm, have {x | a' < x} ∈ (nhds a).sets, from mem_nhds_sets (is_open_lt' _) this, have {x | a' < x} ∩ t₁ ∈ (nhds a).sets, from inter_mem_sets this ht₁, have ({x | a' < x} ∩ t₁) ∩ s ∈ (nhds a ⊓ principal s).sets, from inter_mem_inf_sets this (subset.refl s), let ⟨x, ⟨hx₁, hx₂⟩, hx₃⟩ := inhabited_of_mem_sets hnbot this in have hxa' : f x > f a', from hs ⟨hx₂, ht₂ hx₃⟩, have ha'x : f a' ≥ f x, from hf _ ha' _ hx₃ $ le_of_lt hx₁, lt_irrefl _ (lt_of_lt_of_le hxa' ha'x)), and.intro (assume b' ⟨a', ha', h_eq⟩, h_eq ▸ not_lt.1 $ this _ ha') (assume b' hb', le_of_tendsto hnbot tendsto_const_nhds hb $ mem_inf_sets_of_right $ assume x hx, hb' _ $ mem_image_of_mem _ hx) end order_topology section liminf_limsup section ordered_topology variables [semilattice_sup α] [topological_space α] [orderable_topology α] lemma is_bounded_le_nhds (a : α) : (nhds a).is_bounded (≤) := match forall_le_or_exists_lt_sup a with | or.inl h := ⟨a, univ_mem_sets' h⟩ | or.inr ⟨b, hb⟩ := ⟨b, ge_mem_nhds hb⟩ end lemma is_bounded_under_le_of_tendsto {f : filter β} {u : β → α} {a : α} (h : tendsto u f (nhds a)) : f.is_bounded_under (≤) u := is_bounded_of_le h (is_bounded_le_nhds a) lemma is_cobounded_ge_nhds (a : α) : (nhds a).is_cobounded (≥) := is_cobounded_of_is_bounded nhds_neq_bot (is_bounded_le_nhds a) lemma is_cobounded_under_ge_of_tendsto {f : filter β} {u : β → α} {a : α} (hf : f ≠ ⊥) (h : tendsto u f (nhds a)) : f.is_cobounded_under (≥) u := is_cobounded_of_is_bounded (map_ne_bot hf) (is_bounded_under_le_of_tendsto h) end ordered_topology section ordered_topology variables [semilattice_inf α] [topological_space α] [orderable_topology α] lemma is_bounded_ge_nhds (a : α) : (nhds a).is_bounded (≥) := match forall_le_or_exists_lt_inf a with | or.inl h := ⟨a, univ_mem_sets' h⟩ | or.inr ⟨b, hb⟩ := ⟨b, le_mem_nhds hb⟩ end lemma is_bounded_under_ge_of_tendsto {f : filter β} {u : β → α} {a : α} (h : tendsto u f (nhds a)) : f.is_bounded_under (≥) u := is_bounded_of_le h (is_bounded_ge_nhds a) lemma is_cobounded_le_nhds (a : α) : (nhds a).is_cobounded (≤) := is_cobounded_of_is_bounded nhds_neq_bot (is_bounded_ge_nhds a) lemma is_cobounded_under_le_of_tendsto {f : filter β} {u : β → α} {a : α} (hf : f ≠ ⊥) (h : tendsto u f (nhds a)) : f.is_cobounded_under (≤) u := is_cobounded_of_is_bounded (map_ne_bot hf) (is_bounded_under_ge_of_tendsto h) end ordered_topology section conditionally_complete_linear_order variables [conditionally_complete_linear_order α] [topological_space α] [orderable_topology α] theorem lt_mem_sets_of_Limsup_lt {f : filter α} {b} (h : f.is_bounded (≤)) (l : f.Limsup < b) : {a | a < b} ∈ f.sets := let ⟨c, (h : {a : α | a ≤ c} ∈ f.sets), hcb⟩ := exists_lt_of_cInf_lt (ne_empty_iff_exists_mem.2 h) l in mem_sets_of_superset h $ assume a hac, lt_of_le_of_lt hac hcb theorem gt_mem_sets_of_Liminf_gt {f : filter α} {b} (h : f.is_bounded (≥)) (l : f.Liminf > b) : {a | a > b} ∈ f.sets := let ⟨c, (h : {a : α | c ≤ a} ∈ f.sets), hbc⟩ := exists_lt_of_lt_cSup (ne_empty_iff_exists_mem.2 h) l in mem_sets_of_superset h $ assume a hca, lt_of_lt_of_le hbc hca /-- If the liminf and the limsup of a filter coincide, then this filter converges to their common value, at least if the filter is eventually bounded above and below. -/ theorem le_nhds_of_Limsup_eq_Liminf {f : filter α} {a : α} (hl : f.is_bounded (≤)) (hg : f.is_bounded (≥)) (hs : f.Limsup = a) (hi : f.Liminf = a) : f ≤ nhds a := tendsto_orderable.2 $ and.intro (assume b hb, gt_mem_sets_of_Liminf_gt hg $ hi.symm ▸ hb) (assume b hb, lt_mem_sets_of_Limsup_lt hl $ hs.symm ▸ hb) theorem Limsup_nhds (a : α) : Limsup (nhds a) = a := cInf_intro (ne_empty_iff_exists_mem.2 $ is_bounded_le_nhds a) (assume a' (h : {n : α | n ≤ a'} ∈ (nhds a).sets), show a ≤ a', from @mem_of_nhds α _ a _ h) (assume b (hba : a < b), show ∃c (h : {n : α | n ≤ c} ∈ (nhds a).sets), c < b, from match dense_or_discrete hba with | or.inl ⟨c, hac, hcb⟩ := ⟨c, ge_mem_nhds hac, hcb⟩ | or.inr ⟨_, h⟩ := ⟨a, (nhds a).sets_of_superset (gt_mem_nhds hba) h, hba⟩ end) theorem Liminf_nhds (a : α) : Liminf (nhds a) = a := cSup_intro (ne_empty_iff_exists_mem.2 $ is_bounded_ge_nhds a) (assume a' (h : {n : α | a' ≤ n} ∈ (nhds a).sets), show a' ≤ a, from mem_of_nhds h) (assume b (hba : b < a), show ∃c (h : {n : α | c ≤ n} ∈ (nhds a).sets), b < c, from match dense_or_discrete hba with | or.inl ⟨c, hbc, hca⟩ := ⟨c, le_mem_nhds hca, hbc⟩ | or.inr ⟨h, _⟩ := ⟨a, (nhds a).sets_of_superset (lt_mem_nhds hba) h, hba⟩ end) /-- If a filter is converging, its limsup coincides with its limit. -/ theorem Liminf_eq_of_le_nhds {f : filter α} {a : α} (hf : f ≠ ⊥) (h : f ≤ nhds a) : f.Liminf = a := have hb_ge : is_bounded (≥) f, from is_bounded_of_le h (is_bounded_ge_nhds a), have hb_le : is_bounded (≤) f, from is_bounded_of_le h (is_bounded_le_nhds a), le_antisymm (calc f.Liminf ≤ f.Limsup : Liminf_le_Limsup hf hb_le hb_ge ... ≤ (nhds a).Limsup : Limsup_le_Limsup_of_le h (is_cobounded_of_is_bounded hf hb_ge) (is_bounded_le_nhds a) ... = a : Limsup_nhds a) (calc a = (nhds a).Liminf : (Liminf_nhds a).symm ... ≤ f.Liminf : Liminf_le_Liminf_of_le h (is_bounded_ge_nhds a) (is_cobounded_of_is_bounded hf hb_le)) /-- If a filter is converging, its liminf coincides with its limit. -/ theorem Limsup_eq_of_le_nhds {f : filter α} {a : α} (hf : f ≠ ⊥) (h : f ≤ nhds a) : f.Limsup = a := have hb_ge : is_bounded (≥) f, from is_bounded_of_le h (is_bounded_ge_nhds a), le_antisymm (calc f.Limsup ≤ (nhds a).Limsup : Limsup_le_Limsup_of_le h (is_cobounded_of_is_bounded hf hb_ge) (is_bounded_le_nhds a) ... = a : Limsup_nhds a) (calc a = f.Liminf : (Liminf_eq_of_le_nhds hf h).symm ... ≤ f.Limsup : Liminf_le_Limsup hf (is_bounded_of_le h (is_bounded_le_nhds a)) hb_ge) end conditionally_complete_linear_order end liminf_limsup end orderable_topology lemma orderable_topology_of_nhds_abs {α : Type*} [decidable_linear_ordered_comm_group α] [topological_space α] (h_nhds : ∀a:α, nhds a = (⨅r>0, principal {b | abs (a - b) < r})) : orderable_topology α := orderable_topology.mk $ eq_of_nhds_eq_nhds $ assume a:α, le_antisymm_iff.mpr begin simp [infi_and, topological_space.nhds_generate_from, h_nhds, le_infi_iff, -le_principal_iff, and_comm], refine ⟨λ s ha b hs, _, λ r hr, _⟩, { rcases hs with rfl | rfl, { refine infi_le_of_le (a - b) (infi_le_of_le (lt_sub_left_of_add_lt $ by simpa using ha) $ principal_mono.mpr $ assume c (hc : abs (a - c) < a - b), _), have : a - c < a - b := lt_of_le_of_lt (le_abs_self _) hc, exact lt_of_neg_lt_neg (lt_of_add_lt_add_left this) }, { refine infi_le_of_le (b - a) (infi_le_of_le (lt_sub_left_of_add_lt $ by simpa using ha) $ principal_mono.mpr $ assume c (hc : abs (a - c) < b - a), _), have : abs (c - a) < b - a, {rw abs_sub; simpa using hc}, have : c - a < b - a := lt_of_le_of_lt (le_abs_self _) this, exact lt_of_add_lt_add_right this } }, { have h : {b | abs (a + -b) < r} = {b | a - r < b} ∩ {b | b < a + r}, from set.ext (assume b, by simp [abs_lt, -sub_eq_add_neg, (sub_eq_add_neg _ _).symm, sub_lt, lt_sub_iff_add_lt, and_comm, sub_lt_iff_lt_add']), rw [h, ← inf_principal], apply le_inf _ _, { exact infi_le_of_le {b : α | a - r < b} (infi_le_of_le (sub_lt_self a hr) $ infi_le_of_le (a - r) $ infi_le _ (or.inl rfl)) }, { exact infi_le_of_le {b : α | b < a + r} (infi_le_of_le (lt_add_of_pos_right _ hr) $ infi_le_of_le (a + r) $ infi_le _ (or.inr rfl)) } } end
2699d51d09b89f0ea7f8e4fea7ee76b4eab4c270
4727251e0cd73359b15b664c3170e5d754078599
/src/analysis/normed/group/SemiNormedGroup/kernels.lean
29102a8b0c423718134caa91ba5ab547a318f349
[ "Apache-2.0" ]
permissive
Vierkantor/mathlib
0ea59ac32a3a43c93c44d70f441c4ee810ccceca
83bc3b9ce9b13910b57bda6b56222495ebd31c2f
refs/heads/master
1,658,323,012,449
1,652,256,003,000
1,652,256,003,000
209,296,341
0
1
Apache-2.0
1,568,807,655,000
1,568,807,655,000
null
UTF-8
Lean
false
false
13,139
lean
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca, Johan Commelin, Scott Morrison -/ import analysis.normed.group.SemiNormedGroup import analysis.normed.group.quotient import category_theory.limits.shapes.kernels /-! # Kernels and cokernels in SemiNormedGroup₁ and SemiNormedGroup We show that `SemiNormedGroup₁` has cokernels (for which of course the `cokernel.π f` maps are norm non-increasing), as well as the easier result that `SemiNormedGroup` has cokernels. We also show that `SemiNormedGroup` has kernels. So far, I don't see a way to state nicely what we really want: `SemiNormedGroup` has cokernels, and `cokernel.π f` is norm non-increasing. The problem is that the limits API doesn't promise you any particular model of the cokernel, and in `SemiNormedGroup` one can always take a cokernel and rescale its norm (and hence making `cokernel.π f` arbitrarily large in norm), obtaining another categorical cokernel. -/ open category_theory category_theory.limits universe u namespace SemiNormedGroup₁ noncomputable theory /-- Auxiliary definition for `has_cokernels SemiNormedGroup₁`. -/ def cokernel_cocone {X Y : SemiNormedGroup₁.{u}} (f : X ⟶ Y) : cofork f 0 := cofork.of_π (@SemiNormedGroup₁.mk_hom _ (SemiNormedGroup.of (Y ⧸ (normed_group_hom.range f.1))) f.1.range.normed_mk (normed_group_hom.is_quotient_quotient _).norm_le) begin ext, simp only [comp_apply, limits.zero_comp, normed_group_hom.zero_apply, SemiNormedGroup₁.mk_hom_apply, SemiNormedGroup₁.zero_apply, ←normed_group_hom.mem_ker, f.1.range.ker_normed_mk, f.1.mem_range], use x, refl, end /-- Auxiliary definition for `has_cokernels SemiNormedGroup₁`. -/ def cokernel_lift {X Y : SemiNormedGroup₁.{u}} (f : X ⟶ Y) (s : cokernel_cofork f) : (cokernel_cocone f).X ⟶ s.X := begin fsplit, -- The lift itself: { apply normed_group_hom.lift _ s.π.1, rintro _ ⟨b, rfl⟩, change (f ≫ s.π) b = 0, simp, }, -- The lift has norm at most one: exact normed_group_hom.lift_norm_noninc _ _ _ s.π.2, end instance : has_cokernels SemiNormedGroup₁.{u} := { has_colimit := λ X Y f, has_colimit.mk { cocone := cokernel_cocone f, is_colimit := is_colimit_aux _ (cokernel_lift f) (λ s, begin ext, apply normed_group_hom.lift_mk f.1.range, rintro _ ⟨b, rfl⟩, change (f ≫ s.π) b = 0, simp, end) (λ s m w, subtype.eq (normed_group_hom.lift_unique f.1.range _ _ _ (congr_arg subtype.val w : _))), } } -- Sanity check example : has_cokernels SemiNormedGroup₁ := by apply_instance end SemiNormedGroup₁ namespace SemiNormedGroup section equalizers_and_kernels /-- The equalizer cone for a parallel pair of morphisms of seminormed groups. -/ def fork {V W : SemiNormedGroup.{u}} (f g : V ⟶ W) : fork f g := @fork.of_ι _ _ _ _ _ _ (of (f - g).ker) (normed_group_hom.incl (f - g).ker) $ begin ext v, have : v.1 ∈ (f - g).ker := v.2, simpa only [normed_group_hom.incl_apply, pi.zero_apply, coe_comp, normed_group_hom.coe_zero, subtype.val_eq_coe, normed_group_hom.mem_ker, normed_group_hom.coe_sub, pi.sub_apply, sub_eq_zero] using this end instance has_limit_parallel_pair {V W : SemiNormedGroup.{u}} (f g : V ⟶ W) : has_limit (parallel_pair f g) := { exists_limit := nonempty.intro { cone := fork f g, is_limit := fork.is_limit.mk _ (λ c, normed_group_hom.ker.lift (fork.ι c) _ $ show normed_group_hom.comp_hom (f - g) c.ι = 0, by { rw [add_monoid_hom.map_sub, add_monoid_hom.sub_apply, sub_eq_zero], exact c.condition }) (λ c, normed_group_hom.ker.incl_comp_lift _ _ _) (λ c g h, by { ext x, dsimp, rw ← h, refl }) } } instance : limits.has_equalizers.{u (u+1)} SemiNormedGroup := @has_equalizers_of_has_limit_parallel_pair SemiNormedGroup _ $ λ V W f g, SemiNormedGroup.has_limit_parallel_pair f g end equalizers_and_kernels section cokernel -- PROJECT: can we reuse the work to construct cokernels in `SemiNormedGroup₁` here? -- I don't see a way to do this that is less work than just repeating the relevant parts. /-- Auxiliary definition for `has_cokernels SemiNormedGroup`. -/ def cokernel_cocone {X Y : SemiNormedGroup.{u}} (f : X ⟶ Y) : cofork f 0 := @cofork.of_π _ _ _ _ _ _ (SemiNormedGroup.of (Y ⧸ (normed_group_hom.range f))) f.range.normed_mk begin ext, simp only [comp_apply, limits.zero_comp, normed_group_hom.zero_apply, ←normed_group_hom.mem_ker, f.range.ker_normed_mk, f.mem_range, exists_apply_eq_apply], end /-- Auxiliary definition for `has_cokernels SemiNormedGroup`. -/ def cokernel_lift {X Y : SemiNormedGroup.{u}} (f : X ⟶ Y) (s : cokernel_cofork f) : (cokernel_cocone f).X ⟶ s.X := normed_group_hom.lift _ s.π begin rintro _ ⟨b, rfl⟩, change (f ≫ s.π) b = 0, simp, end /-- Auxiliary definition for `has_cokernels SemiNormedGroup`. -/ def is_colimit_cokernel_cocone {X Y : SemiNormedGroup.{u}} (f : X ⟶ Y) : is_colimit (cokernel_cocone f) := is_colimit_aux _ (cokernel_lift f) (λ s, begin ext, apply normed_group_hom.lift_mk f.range, rintro _ ⟨b, rfl⟩, change (f ≫ s.π) b = 0, simp, end) (λ s m w, normed_group_hom.lift_unique f.range _ _ _ w) instance : has_cokernels SemiNormedGroup.{u} := { has_colimit := λ X Y f, has_colimit.mk { cocone := cokernel_cocone f, is_colimit := is_colimit_cokernel_cocone f } } -- Sanity check example : has_cokernels SemiNormedGroup := by apply_instance section explicit_cokernel /-- An explicit choice of cokernel, which has good properties with respect to the norm. -/ def explicit_cokernel {X Y : SemiNormedGroup.{u}} (f : X ⟶ Y) : SemiNormedGroup.{u} := (cokernel_cocone f).X /-- Descend to the explicit cokernel. -/ def explicit_cokernel_desc {X Y Z : SemiNormedGroup.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} (w : f ≫ g = 0) : explicit_cokernel f ⟶ Z := (is_colimit_cokernel_cocone f).desc (cofork.of_π g (by simp [w])) /-- The projection from `Y` to the explicit cokernel of `X ⟶ Y`. -/ def explicit_cokernel_π {X Y : SemiNormedGroup.{u}} (f : X ⟶ Y) : Y ⟶ explicit_cokernel f := (cokernel_cocone f).ι.app walking_parallel_pair.one lemma explicit_cokernel_π_surjective {X Y : SemiNormedGroup.{u}} {f : X ⟶ Y} : function.surjective (explicit_cokernel_π f) := surjective_quot_mk _ @[simp, reassoc] lemma comp_explicit_cokernel_π {X Y : SemiNormedGroup.{u}} (f : X ⟶ Y) : f ≫ explicit_cokernel_π f = 0 := begin convert (cokernel_cocone f).w walking_parallel_pair_hom.left, simp, end @[simp] lemma explicit_cokernel_π_apply_dom_eq_zero {X Y : SemiNormedGroup.{u}} {f : X ⟶ Y} (x : X) : (explicit_cokernel_π f) (f x) = 0 := show (f ≫ (explicit_cokernel_π f)) x = 0, by { rw [comp_explicit_cokernel_π], refl } @[simp, reassoc] lemma explicit_cokernel_π_desc {X Y Z : SemiNormedGroup.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} (w : f ≫ g = 0) : explicit_cokernel_π f ≫ explicit_cokernel_desc w = g := (is_colimit_cokernel_cocone f).fac _ _ @[simp] lemma explicit_cokernel_π_desc_apply {X Y Z : SemiNormedGroup.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} {cond : f ≫ g = 0} (x : Y) : explicit_cokernel_desc cond (explicit_cokernel_π f x) = g x := show (explicit_cokernel_π f ≫ explicit_cokernel_desc cond) x = g x, by rw explicit_cokernel_π_desc lemma explicit_cokernel_desc_unique {X Y Z : SemiNormedGroup.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} (w : f ≫ g = 0) (e : explicit_cokernel f ⟶ Z) (he : explicit_cokernel_π f ≫ e = g) : e = explicit_cokernel_desc w := begin apply (is_colimit_cokernel_cocone f).uniq (cofork.of_π g (by simp [w])), rintro (_|_), { convert w.symm, simp }, { exact he } end lemma explicit_cokernel_desc_comp_eq_desc {X Y Z W : SemiNormedGroup.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} {h : Z ⟶ W} {cond : f ≫ g = 0} : explicit_cokernel_desc cond ≫ h = explicit_cokernel_desc (show f ≫ (g ≫ h) = 0, by rw [← category_theory.category.assoc, cond, limits.zero_comp]) := begin refine explicit_cokernel_desc_unique _ _ _, rw [← category_theory.category.assoc, explicit_cokernel_π_desc] end @[simp] lemma explicit_cokernel_desc_zero {X Y Z : SemiNormedGroup.{u}} {f : X ⟶ Y} : explicit_cokernel_desc (show f ≫ (0 : Y ⟶ Z) = 0, from category_theory.limits.comp_zero) = 0 := eq.symm $ explicit_cokernel_desc_unique _ _ category_theory.limits.comp_zero @[ext] lemma explicit_cokernel_hom_ext {X Y Z : SemiNormedGroup.{u}} {f : X ⟶ Y} (e₁ e₂ : explicit_cokernel f ⟶ Z) (h : explicit_cokernel_π f ≫ e₁ = explicit_cokernel_π f ≫ e₂) : e₁ = e₂ := begin let g : Y ⟶ Z := explicit_cokernel_π f ≫ e₂, have w : f ≫ g = 0, by simp, have : e₂ = explicit_cokernel_desc w, { apply explicit_cokernel_desc_unique, refl }, rw this, apply explicit_cokernel_desc_unique, exact h, end instance explicit_cokernel_π.epi {X Y : SemiNormedGroup.{u}} {f : X ⟶ Y} : epi (explicit_cokernel_π f) := begin constructor, intros Z g h H, ext x, obtain ⟨x, hx⟩ := explicit_cokernel_π_surjective (explicit_cokernel_π f x), change (explicit_cokernel_π f ≫ g) _ = _, rw [H] end lemma is_quotient_explicit_cokernel_π {X Y : SemiNormedGroup.{u}} (f : X ⟶ Y) : normed_group_hom.is_quotient (explicit_cokernel_π f) := normed_group_hom.is_quotient_quotient _ lemma norm_noninc_explicit_cokernel_π {X Y : SemiNormedGroup.{u}} (f : X ⟶ Y) : (explicit_cokernel_π f).norm_noninc := (is_quotient_explicit_cokernel_π f).norm_le open_locale nnreal lemma explicit_cokernel_desc_norm_le_of_norm_le {X Y Z : SemiNormedGroup.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} (w : f ≫ g = 0) (c : ℝ≥0) (h : ∥ g ∥ ≤ c) : ∥ explicit_cokernel_desc w ∥ ≤ c := normed_group_hom.lift_norm_le _ _ _ h lemma explicit_cokernel_desc_norm_noninc {X Y Z : SemiNormedGroup.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} {cond : f ≫ g = 0} (hg : g.norm_noninc) : (explicit_cokernel_desc cond).norm_noninc := begin refine normed_group_hom.norm_noninc.norm_noninc_iff_norm_le_one.2 _, rw [← nnreal.coe_one], exact explicit_cokernel_desc_norm_le_of_norm_le cond 1 (normed_group_hom.norm_noninc.norm_noninc_iff_norm_le_one.1 hg) end lemma explicit_cokernel_desc_comp_eq_zero {X Y Z W : SemiNormedGroup.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} {h : Z ⟶ W} (cond : f ≫ g = 0) (cond2 : g ≫ h = 0) : explicit_cokernel_desc cond ≫ h = 0 := begin rw [← cancel_epi (explicit_cokernel_π f), ← category.assoc, explicit_cokernel_π_desc], simp [cond2] end lemma explicit_cokernel_desc_norm_le {X Y Z : SemiNormedGroup.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} (w : f ≫ g = 0) : ∥ explicit_cokernel_desc w ∥ ≤ ∥ g ∥ := explicit_cokernel_desc_norm_le_of_norm_le w ∥ g ∥₊ le_rfl /-- The explicit cokernel is isomorphic to the usual cokernel. -/ def explicit_cokernel_iso {X Y : SemiNormedGroup.{u}} (f : X ⟶ Y) : explicit_cokernel f ≅ cokernel f := (is_colimit_cokernel_cocone f).cocone_point_unique_up_to_iso (colimit.is_colimit _) @[simp] lemma explicit_cokernel_iso_hom_π {X Y : SemiNormedGroup.{u}} (f : X ⟶ Y) : explicit_cokernel_π f ≫ (explicit_cokernel_iso f).hom = cokernel.π _ := by simp [explicit_cokernel_π, explicit_cokernel_iso, is_colimit.cocone_point_unique_up_to_iso] @[simp] lemma explicit_cokernel_iso_inv_π {X Y : SemiNormedGroup.{u}} (f : X ⟶ Y) : cokernel.π f ≫ (explicit_cokernel_iso f).inv = explicit_cokernel_π f := by simp [explicit_cokernel_π, explicit_cokernel_iso] @[simp] lemma explicit_cokernel_iso_hom_desc {X Y Z : SemiNormedGroup.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} (w : f ≫ g = 0) : (explicit_cokernel_iso f).hom ≫ cokernel.desc f g w = explicit_cokernel_desc w := begin ext1, simp [explicit_cokernel_desc, explicit_cokernel_π, explicit_cokernel_iso, is_colimit.cocone_point_unique_up_to_iso], end /-- A special case of `category_theory.limits.cokernel.map` adapted to `explicit_cokernel`. -/ noncomputable def explicit_cokernel.map {A B C D : SemiNormedGroup.{u}} {fab : A ⟶ B} {fbd : B ⟶ D} {fac : A ⟶ C} {fcd : C ⟶ D} (h : fab ≫ fbd = fac ≫ fcd) : explicit_cokernel fab ⟶ explicit_cokernel fcd := @explicit_cokernel_desc _ _ _ fab (fbd ≫ explicit_cokernel_π _) $ by simp [reassoc_of h] /-- A special case of `category_theory.limits.cokernel.map_desc` adapted to `explicit_cokernel`. -/ lemma explicit_coker.map_desc {A B C D B' D' : SemiNormedGroup.{u}} {fab : A ⟶ B} {fbd : B ⟶ D} {fac : A ⟶ C} {fcd : C ⟶ D} {h : fab ≫ fbd = fac ≫ fcd} {fbb' : B ⟶ B'} {fdd' : D ⟶ D'} {condb : fab ≫ fbb' = 0} {condd : fcd ≫ fdd' = 0} {g : B' ⟶ D'} (h' : fbb' ≫ g = fbd ≫ fdd'): explicit_cokernel_desc condb ≫ g = explicit_cokernel.map h ≫ explicit_cokernel_desc condd := begin delta explicit_cokernel.map, simp [← cancel_epi (explicit_cokernel_π fab), category.assoc, explicit_cokernel_π_desc, h'] end end explicit_cokernel end cokernel end SemiNormedGroup
16583ce666f2847e28d37b4519a54caa56179c09
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/algebra/regular/smul.lean
be04083079e37baeee8ebb77085aa0fdc7d797a3
[ "Apache-2.0" ]
permissive
alreadydone/mathlib
dc0be621c6c8208c581f5170a8216c5ba6721927
c982179ec21091d3e102d8a5d9f5fe06c8fafb73
refs/heads/master
1,685,523,275,196
1,670,184,141,000
1,670,184,141,000
287,574,545
0
0
Apache-2.0
1,670,290,714,000
1,597,421,623,000
Lean
UTF-8
Lean
false
false
7,822
lean
/- Copyright (c) 2021 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import algebra.smul_with_zero import algebra.regular.basic /-! # Action of regular elements on a module We introduce `M`-regular elements, in the context of an `R`-module `M`. The corresponding predicate is called `is_smul_regular`. There are very limited typeclass assumptions on `R` and `M`, but the "mathematical" case of interest is a commutative ring `R` acting an a module `M`. Since the properties are "multiplicative", there is no actual requirement of having an addition, but there is a zero in both `R` and `M`. Smultiplications involving `0` are, of course, all trivial. The defining property is that an element `a ∈ R` is `M`-regular if the smultiplication map `M → M`, defined by `m ↦ a • m`, is injective. This property is the direct generalization to modules of the property `is_left_regular` defined in `algebra/regular`. Lemma `is_smul_regular.is_left_regular_iff` shows that indeed the two notions coincide. -/ variables {R S : Type*} (M : Type*) {a b : R} {s : S} /-- An `M`-regular element is an element `c` such that multiplication on the left by `c` is an injective map `M → M`. -/ def is_smul_regular [has_smul R M] (c : R) := function.injective ((•) c : M → M) lemma is_left_regular.is_smul_regular [has_mul R] {c : R} (h : is_left_regular c) : is_smul_regular R c := h /-- Left-regular multiplication on `R` is equivalent to `R`-regularity of `R` itself. -/ lemma is_left_regular_iff [has_mul R] {a : R} : is_left_regular a ↔ is_smul_regular R a := iff.rfl lemma is_right_regular.is_smul_regular [has_mul R] {c : R} (h : is_right_regular c) : is_smul_regular R (mul_opposite.op c) := h /-- Right-regular multiplication on `R` is equivalent to `Rᵐᵒᵖ`-regularity of `R` itself. -/ lemma is_right_regular_iff [has_mul R] {a : R} : is_right_regular a ↔ is_smul_regular R (mul_opposite.op a) := iff.rfl namespace is_smul_regular variables {M} section has_smul variables [has_smul R M] [has_smul R S] [has_smul S M] [is_scalar_tower R S M] /-- The product of `M`-regular elements is `M`-regular. -/ lemma smul (ra : is_smul_regular M a) (rs : is_smul_regular M s) : is_smul_regular M (a • s) := λ a b ab, rs (ra ((smul_assoc _ _ _).symm.trans (ab.trans (smul_assoc _ _ _)))) /-- If an element `b` becomes `M`-regular after multiplying it on the left by an `M`-regular element, then `b` is `M`-regular. -/ lemma of_smul (a : R) (ab : is_smul_regular M (a • s)) : is_smul_regular M s := @function.injective.of_comp _ _ _ (λ m : M, a • m) _ (λ c d cd, ab (by rwa [smul_assoc, smul_assoc])) /-- An element is `M`-regular if and only if multiplying it on the left by an `M`-regular element is `M`-regular. -/ @[simp] lemma smul_iff (b : S) (ha : is_smul_regular M a) : is_smul_regular M (a • b) ↔ is_smul_regular M b := ⟨of_smul _, ha.smul⟩ lemma is_left_regular [has_mul R] {a : R} (h : is_smul_regular R a) : is_left_regular a := h lemma is_right_regular [has_mul R] {a : R} (h : is_smul_regular R (mul_opposite.op a)) : is_right_regular a := h lemma mul [has_mul R] [is_scalar_tower R R M] (ra : is_smul_regular M a) (rb : is_smul_regular M b) : is_smul_regular M (a * b) := ra.smul rb lemma of_mul [has_mul R] [is_scalar_tower R R M] (ab : is_smul_regular M (a * b)) : is_smul_regular M b := by { rw ← smul_eq_mul at ab, exact ab.of_smul _ } @[simp] lemma mul_iff_right [has_mul R] [is_scalar_tower R R M] (ha : is_smul_regular M a) : is_smul_regular M (a * b) ↔ is_smul_regular M b := ⟨of_mul, ha.mul⟩ /-- Two elements `a` and `b` are `M`-regular if and only if both products `a * b` and `b * a` are `M`-regular. -/ lemma mul_and_mul_iff [has_mul R] [is_scalar_tower R R M] : is_smul_regular M (a * b) ∧ is_smul_regular M (b * a) ↔ is_smul_regular M a ∧ is_smul_regular M b := begin refine ⟨_, _⟩, { rintros ⟨ab, ba⟩, refine ⟨ba.of_mul, ab.of_mul⟩ }, { rintros ⟨ha, hb⟩, exact ⟨ha.mul hb, hb.mul ha⟩ } end end has_smul section monoid variables [monoid R] [mul_action R M] variable (M) /-- One is `M`-regular always. -/ @[simp] lemma one : is_smul_regular M (1 : R) := λ a b ab, by rwa [one_smul, one_smul] at ab variable {M} /-- An element of `R` admitting a left inverse is `M`-regular. -/ lemma of_mul_eq_one (h : a * b = 1) : is_smul_regular M b := of_mul (by { rw h, exact one M }) /-- Any power of an `M`-regular element is `M`-regular. -/ lemma pow (n : ℕ) (ra : is_smul_regular M a) : is_smul_regular M (a ^ n) := begin induction n with n hn, { simp only [one, pow_zero] }, { rw pow_succ, exact (ra.smul_iff (a ^ n)).mpr hn } end /-- An element `a` is `M`-regular if and only if a positive power of `a` is `M`-regular. -/ lemma pow_iff {n : ℕ} (n0 : 0 < n) : is_smul_regular M (a ^ n) ↔ is_smul_regular M a := begin refine ⟨_, pow n⟩, rw [← nat.succ_pred_eq_of_pos n0, pow_succ', ← smul_eq_mul], exact of_smul _, end end monoid section monoid_smul variables [monoid S] [has_smul R M] [has_smul R S] [mul_action S M] [is_scalar_tower R S M] /-- An element of `S` admitting a left inverse in `R` is `M`-regular. -/ lemma of_smul_eq_one (h : a • s = 1) : is_smul_regular M s := of_smul a (by { rw h, exact one M }) end monoid_smul section monoid_with_zero variables [monoid_with_zero R] [monoid_with_zero S] [has_zero M] [mul_action_with_zero R M] [mul_action_with_zero R S] [mul_action_with_zero S M] [is_scalar_tower R S M] /-- The element `0` is `M`-regular if and only if `M` is trivial. -/ protected lemma subsingleton (h : is_smul_regular M (0 : R)) : subsingleton M := ⟨λ a b, h (by repeat { rw mul_action_with_zero.zero_smul })⟩ /-- The element `0` is `M`-regular if and only if `M` is trivial. -/ lemma zero_iff_subsingleton : is_smul_regular M (0 : R) ↔ subsingleton M := ⟨λ h, h.subsingleton, λ H a b h, @subsingleton.elim _ H a b⟩ /-- The `0` element is not `M`-regular, on a non-trivial module. -/ lemma not_zero_iff : ¬ is_smul_regular M (0 : R) ↔ nontrivial M := begin rw [nontrivial_iff, not_iff_comm, zero_iff_subsingleton, subsingleton_iff], push_neg, exact iff.rfl end /-- The element `0` is `M`-regular when `M` is trivial. -/ lemma zero [sM : subsingleton M] : is_smul_regular M (0 : R) := zero_iff_subsingleton.mpr sM /-- The `0` element is not `M`-regular, on a non-trivial module. -/ lemma not_zero [nM : nontrivial M] : ¬ is_smul_regular M (0 : R) := not_zero_iff.mpr nM end monoid_with_zero section comm_semigroup variables [comm_semigroup R] [has_smul R M] [is_scalar_tower R R M] /-- A product is `M`-regular if and only if the factors are. -/ lemma mul_iff : is_smul_regular M (a * b) ↔ is_smul_regular M a ∧ is_smul_regular M b := begin rw ← mul_and_mul_iff, exact ⟨λ ab, ⟨ab, by rwa mul_comm⟩, λ rab, rab.1⟩ end end comm_semigroup end is_smul_regular section group variables {G : Type*} [group G] /-- An element of a group acting on a Type is regular. This relies on the availability of the inverse given by groups, since there is no `left_cancel_smul` typeclass. -/ lemma is_smul_regular_of_group [mul_action G R] (g : G) : is_smul_regular R g := begin intros x y h, convert congr_arg ((•) g⁻¹) h using 1; simp [←smul_assoc] end end group section units variables [monoid R] [mul_action R M] /-- Any element in `Rˣ` is `M`-regular. -/ lemma units.is_smul_regular (a : Rˣ) : is_smul_regular M (a : R) := is_smul_regular.of_mul_eq_one a.inv_val /-- A unit is `M`-regular. -/ lemma is_unit.is_smul_regular (ua : is_unit a) : is_smul_regular M a := begin rcases ua with ⟨a, rfl⟩, exact a.is_smul_regular M end end units
b27b1a15d5d9fd91761af1bb8f2d1886d5a5c877
efce24474b28579aba3272fdb77177dc2b11d7aa
/src/category_theory/congruence.lean
67b40d18695ca9b41584bdd95f3724a50920b46b
[ "Apache-2.0" ]
permissive
rwbarton/lean-homotopy-theory
cff499f24268d60e1c546e7c86c33f58c62888ed
39e1b4ea1ed1b0eca2f68bc64162dde6a6396dee
refs/heads/lean-3.4.2
1,622,711,883,224
1,598,550,958,000
1,598,550,958,000
136,023,667
12
6
Apache-2.0
1,573,187,573,000
1,528,116,262,000
Lean
UTF-8
Lean
false
false
1,836
lean
import category_theory.base import category_theory.functor universes v u namespace category_theory local notation f ` ∘ `:80 g:80 := g ≫ f variables {C : Type u} [category.{v} C] class congruence (r : Π ⦃a b : C⦄, (a ⟶ b) → (a ⟶ b) → Prop) := (is_equiv : ∀ {a b}, equivalence (@r a b)) (congr : ∀ {a b c} {f f' : a ⟶ b} {g g' : b ⟶ c}, r f f' → r g g' → r (g ∘ f) (g' ∘ f')) def congruence.mk' {r : Π ⦃a b : C⦄, (a ⟶ b) → (a ⟶ b) → Prop} (is_equiv : ∀ {a b}, equivalence (@r a b)) (congr_left : ∀ {a b c} {f f' : a ⟶ b} {g : b ⟶ c}, r f f' → r (g ∘ f) (g ∘ f')) (congr_right : ∀ {a b c} {f : a ⟶ b} {g g' : b ⟶ c}, r g g' → r (g ∘ f) (g' ∘ f)) : congruence r := { is_equiv := @is_equiv, congr := λ _ _ _ f f' g g' rff' rgg', is_equiv.2.2 (congr_right rgg') (congr_left rff') } variables (C) variables (r : Π ⦃a b : C⦄, (a ⟶ b) → (a ⟶ b) → Prop) [congruence r] include r def category_mod_congruence : Type u := C omit r instance Hom.setoid (a b : C) : setoid (a ⟶ b) := { r := @r a b, iseqv := congruence.is_equiv } instance category_mod_congruence.category : category (category_mod_congruence C r) := { hom := λ a b, quotient (Hom.setoid C r a b), id := λ a, ⟦𝟙 a⟧, comp := λ a b c f₀ g₀, quotient.lift_on₂ f₀ g₀ (λ f g, ⟦g ∘ f⟧) (λ f g f' g' rff' rgg', quotient.sound (congruence.congr rff' rgg' : r _ _)), id_comp' := begin rintros a b ⟨f⟩, change quot.mk _ _ = _, simp end, comp_id' := begin rintros a b ⟨f⟩, change quot.mk _ _ = _, simp end, assoc' := begin rintros a b c d ⟨f⟩ ⟨g⟩ ⟨h⟩, change quot.mk _ _ = quot.mk _ _, simp end } def quotient_functor : C ↝ category_mod_congruence C r := { obj := λ a, a, map := λ a b f, ⟦f⟧ } end category_theory
0bd2fe44b220dd98adafbb947c702f0138ddf75d
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/tactic/reassoc_axiom.lean
ade0b6a1bd5facf39e5ae46d61e6a67a2d1e96c8
[ "Apache-2.0" ]
permissive
jjgarzella/mathlib
96a345378c4e0bf26cf604aed84f90329e4896a2
395d8716c3ad03747059d482090e2bb97db612c8
refs/heads/master
1,686,480,124,379
1,625,163,323,000
1,625,163,323,000
281,190,421
2
0
Apache-2.0
1,595,268,170,000
1,595,268,169,000
null
UTF-8
Lean
false
false
8,009
lean
/- Copyright (c) 2019 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon -/ import category_theory.category /-! # Tools to reformulate category-theoretic axioms in a more associativity-friendly way ## The `reassoc` attribute The `reassoc` attribute can be applied to a lemma ```lean @[reassoc] lemma some_lemma : foo ≫ bar = baz := ... ``` and produce ```lean lemma some_lemma_assoc {Y : C} (f : X ⟶ Y) : foo ≫ bar ≫ f = baz ≫ f := ... ``` The name of the produced lemma can be specified with `@[reassoc other_lemma_name]`. If `simp` is added first, the generated lemma will also have the `simp` attribute. ## The `reassoc_axiom` command When declaring a class of categories, the axioms can be reformulated to be more amenable to manipulation in right associated expressions: ```lean class some_class (C : Type) [category C] := (foo : Π X : C, X ⟶ X) (bar : ∀ {X Y : C} (f : X ⟶ Y), foo X ≫ f = f ≫ foo Y) reassoc_axiom some_class.bar ``` Here too, the `reassoc` attribute can be used instead. It works well when combined with `simp`: ```lean attribute [simp, reassoc] some_class.bar ``` -/ namespace tactic open interactive lean.parser category_theory /-- From an expression `f ≫ g`, extract the expression representing the category instance. -/ meta def get_cat_inst : expr → tactic expr | `(@category_struct.comp _ %%struct_inst _ _ _ _ _) := pure struct_inst | _ := failed /-- (internals for `@[reassoc]`) Given a lemma of the form `∀ ..., f ≫ g = h`, proves a new lemma of the form `h : ∀ ... {W} (k), f ≫ (g ≫ k) = h ≫ k`, and returns the type and proof of this lemma. -/ meta def prove_reassoc (h : expr) : tactic (expr × expr) := do (vs,t) ← infer_type h >>= open_pis, (lhs,rhs) ← match_eq t, struct_inst ← get_cat_inst lhs <|> get_cat_inst rhs <|> fail "no composition found in statement", `(@quiver.hom _ %%hom_inst %%X %%Y) ← infer_type lhs, C ← infer_type X, X' ← mk_local' `X' binder_info.implicit C, ft ← to_expr ``(@quiver.hom _ %%hom_inst %%Y %%X'), f' ← mk_local_def `f' ft, t' ← to_expr ``(@category_struct.comp _ %%struct_inst _ _ _%%lhs %%f' = @category_struct.comp _ %%struct_inst _ _ _ %%rhs %%f'), let c' := h.mk_app vs, (_,pr) ← solve_aux t' (rewrite_target c'; reflexivity), pr ← instantiate_mvars pr, let s := simp_lemmas.mk, s ← s.add_simp ``category.assoc, s ← s.add_simp ``category.id_comp, s ← s.add_simp ``category.comp_id, (t'', pr', _) ← simplify s [] t', pr' ← mk_eq_mp pr' pr, t'' ← pis (vs ++ [X',f']) t'', pr' ← lambdas (vs ++ [X',f']) pr', pure (t'',pr') /-- (implementation for `@[reassoc]`) Given a declaration named `n` of the form `∀ ..., f ≫ g = h`, proves a new lemma named `n'` of the form `∀ ... {W} (k), f ≫ (g ≫ k) = h ≫ k`. -/ meta def reassoc_axiom (n : name) (n' : name := n.append_suffix "_assoc") : tactic unit := do d ← get_decl n, let ls := d.univ_params.map level.param, let c := @expr.const tt n ls, (t'',pr') ← prove_reassoc c, add_decl $ declaration.thm n' d.univ_params t'' (pure pr'), copy_attribute `simp n n' /-- The `reassoc` attribute can be applied to a lemma ```lean @[reassoc] lemma some_lemma : foo ≫ bar = baz := ... ``` to produce ```lean lemma some_lemma_assoc {Y : C} (f : X ⟶ Y) : foo ≫ bar ≫ f = baz ≫ f := ... ``` The name of the produced lemma can be specified with `@[reassoc other_lemma_name]`. If `simp` is added first, the generated lemma will also have the `simp` attribute. -/ @[user_attribute] meta def reassoc_attr : user_attribute unit (option name) := { name := `reassoc, descr := "create a companion lemma for associativity-aware rewriting", parser := optional ident, after_set := some (λ n _ _, do some n' ← reassoc_attr.get_param n | reassoc_axiom n (n.append_suffix "_assoc"), reassoc_axiom n $ n.get_prefix ++ n' ) } add_tactic_doc { name := "reassoc", category := doc_category.attr, decl_names := [`tactic.reassoc_attr], tags := ["category theory"] } /-- When declaring a class of categories, the axioms can be reformulated to be more amenable to manipulation in right associated expressions: ```lean class some_class (C : Type) [category C] := (foo : Π X : C, X ⟶ X) (bar : ∀ {X Y : C} (f : X ⟶ Y), foo X ≫ f = f ≫ foo Y) reassoc_axiom some_class.bar ``` The above will produce: ```lean lemma some_class.bar_assoc {Z : C} (g : Y ⟶ Z) : foo X ≫ f ≫ g = f ≫ foo Y ≫ g := ... ``` Here too, the `reassoc` attribute can be used instead. It works well when combined with `simp`: ```lean attribute [simp, reassoc] some_class.bar ``` -/ @[user_command] meta def reassoc_cmd (_ : parse $ tk "reassoc_axiom") : lean.parser unit := do n ← ident, of_tactic $ do n ← resolve_constant n, reassoc_axiom n add_tactic_doc { name := "reassoc_axiom", category := doc_category.cmd, decl_names := [`tactic.reassoc_cmd], tags := ["category theory"] } namespace interactive setup_tactic_parser /-- `reassoc h`, for assumption `h : x ≫ y = z`, creates a new assumption `h : ∀ {W} (f : Z ⟶ W), x ≫ y ≫ f = z ≫ f`. `reassoc! h`, does the same but deletes the initial `h` assumption. (You can also add the attribute `@[reassoc]` to lemmas to generate new declarations generalized in this way.) -/ meta def reassoc (del : parse (tk "!")?) (ns : parse ident*) : tactic unit := do ns.mmap' (λ n, do h ← get_local n, (t,pr) ← prove_reassoc h, assertv n t pr, when del.is_some (tactic.clear h) ) end interactive def calculated_Prop {α} (β : Prop) (hh : α) := β meta def derive_reassoc_proof : tactic unit := do `(calculated_Prop %%v %%h) ← target, (t,pr) ← prove_reassoc h, unify v t, exact pr end tactic /-- With `h : x ≫ y ≫ z = x` (with universal quantifiers tolerated), `reassoc_of h : ∀ {X'} (f : W ⟶ X'), x ≫ y ≫ z ≫ f = x ≫ f`. The type and proof of `reassoc_of h` is generated by `tactic.derive_reassoc_proof` which make `reassoc_of` meta-programming adjacent. It is not called as a tactic but as an expression. The goal is to avoid creating assumptions that are dismissed after one use: ```lean example (X Y Z W : C) (x : X ⟶ Y) (y : Y ⟶ Z) (z z' : Z ⟶ W) (w : X ⟶ Z) (h : x ≫ y = w) (h' : y ≫ z = y ≫ z') : x ≫ y ≫ z = w ≫ z' := begin rw [h',reassoc_of h], end ``` -/ theorem category_theory.reassoc_of {α} (hh : α) {β} (x : tactic.calculated_Prop β hh . tactic.derive_reassoc_proof) : β := x /-- `reassoc_of h` takes local assumption `h` and add a ` ≫ f` term on the right of both sides of the equality. Instead of creating a new assumption from the result, `reassoc_of h` stands for the proof of that reassociated statement. This keeps complicated assumptions that are used only once or twice from polluting the local context. In the following, assumption `h` is needed in a reassociated form. Instead of proving it as a new goal and adding it as an assumption, we use `reassoc_of h` as a rewrite rule which works just as well. ```lean example (X Y Z W : C) (x : X ⟶ Y) (y : Y ⟶ Z) (z z' : Z ⟶ W) (w : X ⟶ Z) (h : x ≫ y = w) (h' : y ≫ z = y ≫ z') : x ≫ y ≫ z = w ≫ z' := begin -- reassoc_of h : ∀ {X' : C} (f : W ⟶ X'), x ≫ y ≫ f = w ≫ f rw [h',reassoc_of h], end ``` Although `reassoc_of` is not a tactic or a meta program, its type is generated through meta-programming to make it usable inside normal expressions. -/ add_tactic_doc { name := "category_theory.reassoc_of", category := doc_category.tactic, decl_names := [`category_theory.reassoc_of], tags := ["category theory"] }
fa8ca5818e2dfe409fa33e0a17b110973efcead2
94e33a31faa76775069b071adea97e86e218a8ee
/src/measure_theory/covering/differentiation.lean
997b9240f317f534023a01aeedf687f1b7cc6a27
[ "Apache-2.0" ]
permissive
urkud/mathlib
eab80095e1b9f1513bfb7f25b4fa82fa4fd02989
6379d39e6b5b279df9715f8011369a301b634e41
refs/heads/master
1,658,425,342,662
1,658,078,703,000
1,658,078,703,000
186,910,338
0
0
Apache-2.0
1,568,512,083,000
1,557,958,709,000
Lean
UTF-8
Lean
false
false
42,155
lean
/- Copyright (c) 2021 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 measure_theory.covering.vitali_family import measure_theory.measure.regular import measure_theory.function.ae_measurable_order import measure_theory.integral.lebesgue import measure_theory.decomposition.radon_nikodym /-! # Differentiation of measures On a metric space with a measure `μ`, consider a Vitali family (i.e., for each `x` one has a family of sets shrinking to `x`, with a good behavior with respect to covering theorems). Consider also another measure `ρ`. Then, for almost every `x`, the ratio `ρ a / μ a` converges when `a` shrinks to `x` along the Vitali family, towards the Radon-Nikodym derivative of `ρ` with respect to `μ`. This is the main theorem on differentiation of measures. This theorem is proved in this file, under the name `vitali_family.ae_tendsto_rn_deriv`. Note that, almost surely, `μ a` is eventually positive and finite (see `vitali_family.ae_eventually_measure_pos` and `vitali_family.eventually_measure_lt_top`), so the ratio really makes sense. For concrete applications, one needs concrete instances of Vitali families, as provided for instance by `besicovitch.vitali_family` (for balls) or by `vitali.vitali_family` (for doubling measures). ## Sketch of proof Let `v` be a Vitali family for `μ`. Assume for simplicity that `ρ` is absolutely continuous with respect to `μ`, as the case of a singular measure is easier. It is easy to see that a set `s` on which `liminf ρ a / μ a < q` satisfies `ρ s ≤ q * μ s`, by using a disjoint subcovering provided by the definition of Vitali families. Similarly for the limsup. It follows that a set on which `ρ a / μ a` oscillates has measure `0`, and therefore that `ρ a / μ a` converges almost surely (`vitali_family.ae_tendsto_div`). Moreover, on a set where the limit is close to a constant `c`, one gets `ρ s ∼ c μ s`, using again a covering lemma as above. It follows that `ρ` is equal to `μ.with_density (v.lim_ratio ρ x)`, where `v.lim_ratio ρ x` is the limit of `ρ a / μ a` at `x` (which is well defined almost everywhere). By uniqueness of the Radon-Nikodym derivative, one gets `v.lim_ratio ρ x = ρ.rn_deriv μ x` almost everywhere, completing the proof. There is a difficulty in this sketch: this argument works well when `v.lim_ratio ρ` is measurable, but there is no guarantee that this is the case, especially if one doesn't make further assumptions on the Vitali family. We use an indirect argument to show that `v.lim_ratio ρ` is always almost everywhere measurable, again based on the disjoint subcovering argument (see `vitali_family.exists_measurable_supersets_lim_ratio`), and then proceed as sketched above but replacing `v.lim_ratio ρ` by a measurable version called `v.lim_ratio_meas ρ`. ## References * [Herbert Federer, Geometric Measure Theory, Chapter 2.9][Federer1996] -/ open measure_theory metric set filter topological_space measure_theory.measure open_locale filter ennreal measure_theory nnreal topological_space local attribute [instance] emetric.second_countable_of_sigma_compact variables {α : Type*} [metric_space α] {m0 : measurable_space α} {μ : measure α} (v : vitali_family μ) include v namespace vitali_family /-- The limit along a Vitali family of `ρ a / μ a` where it makes sense, and garbage otherwise. Do *not* use this definition: it is only a temporary device to show that this ratio tends almost everywhere to the Radon-Nikodym derivative. -/ noncomputable def lim_ratio (ρ : measure α) (x : α) : ℝ≥0∞ := lim (v.filter_at x) (λ a, ρ a / μ a) /-- For almost every point `x`, sufficiently small sets in a Vitali family around `x` have positive measure. (This is a nontrivial result, following from the covering property of Vitali families). -/ theorem ae_eventually_measure_pos [second_countable_topology α] : ∀ᵐ x ∂μ, ∀ᶠ a in v.filter_at x, 0 < μ a := begin set s := {x | ¬ (∀ᶠ a in v.filter_at x, 0 < μ a)} with hs, simp only [not_lt, not_eventually, nonpos_iff_eq_zero] at hs, change μ s = 0, let f : α → set (set α) := λ x, {a | μ a = 0}, have h : v.fine_subfamily_on f s, { assume x hx ε εpos, rw hs at hx, simp only [frequently_filter_at_iff, exists_prop, gt_iff_lt, mem_set_of_eq] at hx, rcases hx ε εpos with ⟨a, a_sets, ax, μa⟩, exact ⟨a, ⟨a_sets, μa⟩, ax⟩ }, refine le_antisymm _ bot_le, calc μ s ≤ ∑' (x : h.index), μ (h.covering x) : h.measure_le_tsum ... = ∑' (x : h.index), 0 : by { congr, ext1 x, exact h.covering_mem x.2 } ... = 0 : by simp only [tsum_zero, add_zero] end /-- For every point `x`, sufficiently small sets in a Vitali family around `x` have finite measure. (This is a trivial result, following from the fact that the measure is locally finite). -/ theorem eventually_measure_lt_top [is_locally_finite_measure μ] (x : α) : ∀ᶠ a in v.filter_at x, μ a < ∞ := begin obtain ⟨ε, εpos, με⟩ : ∃ (ε : ℝ) (hi : 0 < ε), μ (closed_ball x ε) < ∞ := (μ.finite_at_nhds x).exists_mem_basis nhds_basis_closed_ball, exact v.eventually_filter_at_iff.2 ⟨ε, εpos, λ a ha haε, (measure_mono haε).trans_lt με⟩, end /-- If two measures `ρ` and `ν` have, at every point of a set `s`, arbitrarily small sets in a Vitali family satisfying `ρ a ≤ ν a`, then `ρ s ≤ ν s` if `ρ ≪ μ`.-/ theorem measure_le_of_frequently_le [sigma_compact_space α] [borel_space α] {ρ : measure α} (ν : measure α) [is_locally_finite_measure ν] (hρ : ρ ≪ μ) (s : set α) (hs : ∀ x ∈ s, ∃ᶠ a in v.filter_at x, ρ a ≤ ν a) : ρ s ≤ ν s := begin -- this follows from a covering argument using the sets satisfying `ρ a ≤ ν a`. apply ennreal.le_of_forall_pos_le_add (λ ε εpos hc, _), obtain ⟨U, sU, U_open, νU⟩ : ∃ (U : set α) (H : s ⊆ U), is_open U ∧ ν U ≤ ν s + ε := exists_is_open_le_add s ν (ennreal.coe_pos.2 εpos).ne', let f : α → set (set α) := λ x, {a | ρ a ≤ ν a ∧ a ⊆ U}, have h : v.fine_subfamily_on f s, { apply v.fine_subfamily_on_of_frequently f s (λ x hx, _), have := (hs x hx).and_eventually ((v.eventually_filter_at_mem_sets x).and (v.eventually_filter_at_subset_of_nhds (U_open.mem_nhds (sU hx)))), apply frequently.mono this, rintros a ⟨ρa, av, aU⟩, exact ⟨ρa, aU⟩ }, haveI : encodable h.index := h.index_countable.to_encodable, calc ρ s ≤ ∑' (x : h.index), ρ (h.covering x) : h.measure_le_tsum_of_absolutely_continuous hρ ... ≤ ∑' (x : h.index), ν (h.covering x) : ennreal.tsum_le_tsum (λ x, (h.covering_mem x.2).1) ... = ν (⋃ (x : h.index), h.covering x) : by rw [measure_Union h.covering_disjoint_subtype (λ i, h.measurable_set_u i.2)] ... ≤ ν U : measure_mono (Union_subset (λ i, (h.covering_mem i.2).2)) ... ≤ ν s + ε : νU end section variables [sigma_compact_space α] [borel_space α] [is_locally_finite_measure μ] {ρ : measure α} [is_locally_finite_measure ρ] /-- If a measure `ρ` is singular with respect to `μ`, then for `μ` almost every `x`, the ratio `ρ a / μ a` tends to zero when `a` shrinks to `x` along the Vitali family. This makes sense as `μ a` is eventually positive by `ae_eventually_measure_pos`. -/ lemma ae_eventually_measure_zero_of_singular (hρ : ρ ⊥ₘ μ) : ∀ᵐ x ∂μ, tendsto (λ a, ρ a / μ a) (v.filter_at x) (𝓝 0) := begin have A : ∀ ε > (0 : ℝ≥0), ∀ᵐ x ∂μ, ∀ᶠ a in v.filter_at x, ρ a < ε * μ a, { assume ε εpos, set s := {x | ¬(∀ᶠ a in v.filter_at x, ρ a < ε * μ a) } with hs, change μ s = 0, obtain ⟨o, o_meas, ρo, μo⟩ : ∃ (o : set α), measurable_set o ∧ ρ o = 0 ∧ μ oᶜ = 0 := hρ, apply le_antisymm _ bot_le, calc μ s ≤ μ ((s ∩ o) ∪ oᶜ) : begin conv_lhs { rw ← inter_union_compl s o }, exact measure_mono (union_subset_union_right _ (inter_subset_right _ _)) end ... ≤ μ (s ∩ o) + μ (oᶜ) : measure_union_le _ _ ... = μ (s ∩ o) : by rw [μo, add_zero] ... = ε⁻¹ * (ε • μ) (s ∩ o) : begin simp only [coe_nnreal_smul_apply, ← mul_assoc, mul_comm _ (ε : ℝ≥0∞)], rw [ennreal.mul_inv_cancel (ennreal.coe_pos.2 εpos).ne' ennreal.coe_ne_top, one_mul], end ... ≤ ε⁻¹ * ρ (s ∩ o) : begin apply ennreal.mul_le_mul le_rfl, refine v.measure_le_of_frequently_le ρ ((measure.absolutely_continuous.refl μ).smul ε) _ _, assume x hx, rw hs at hx, simp only [mem_inter_eq, not_lt, not_eventually, mem_set_of_eq] at hx, exact hx.1 end ... ≤ ε⁻¹ * ρ o : ennreal.mul_le_mul le_rfl (measure_mono (inter_subset_right _ _)) ... = 0 : by rw [ρo, mul_zero] }, obtain ⟨u, u_anti, u_pos, u_lim⟩ : ∃ (u : ℕ → ℝ≥0), strict_anti u ∧ (∀ (n : ℕ), 0 < u n) ∧ tendsto u at_top (𝓝 0) := exists_seq_strict_anti_tendsto (0 : ℝ≥0), have B : ∀ᵐ x ∂μ, ∀ n, ∀ᶠ a in v.filter_at x, ρ a < u n * μ a := ae_all_iff.2 (λ n, A (u n) (u_pos n)), filter_upwards [B, v.ae_eventually_measure_pos], assume x hx h'x, refine tendsto_order.2 ⟨λ z hz, (ennreal.not_lt_zero hz).elim, λ z hz, _⟩, obtain ⟨w, w_pos, w_lt⟩ : ∃ (w : ℝ≥0), (0 : ℝ≥0∞) < w ∧ (w : ℝ≥0∞) < z := ennreal.lt_iff_exists_nnreal_btwn.1 hz, obtain ⟨n, hn⟩ : ∃ n, u n < w := ((tendsto_order.1 u_lim).2 w (ennreal.coe_pos.1 w_pos)).exists, filter_upwards [hx n, h'x, v.eventually_measure_lt_top x], assume a ha μa_pos μa_lt_top, rw ennreal.div_lt_iff (or.inl μa_pos.ne') (or.inl μa_lt_top.ne), exact ha.trans_le (ennreal.mul_le_mul ((ennreal.coe_le_coe.2 hn.le).trans w_lt.le) le_rfl) end section absolutely_continuous variable (hρ : ρ ≪ μ) include hρ /-- A set of points `s` satisfying both `ρ a ≤ c * μ a` and `ρ a ≥ d * μ a` at arbitrarily small sets in a Vitali family has measure `0` if `c < d`. Indeed, the first inequality should imply that `ρ s ≤ c * μ s`, and the second one that `ρ s ≥ d * μ s`, a contradiction if `0 < μ s`. -/ theorem null_of_frequently_le_of_frequently_ge {c d : ℝ≥0} (hcd : c < d) (s : set α) (hc : ∀ x ∈ s, ∃ᶠ a in v.filter_at x, ρ a ≤ c * μ a) (hd : ∀ x ∈ s, ∃ᶠ a in v.filter_at x, (d : ℝ≥0∞) * μ a ≤ ρ a) : μ s = 0 := begin apply null_of_locally_null s (λ x hx, _), obtain ⟨o, xo, o_open, μo⟩ : ∃ o : set α, x ∈ o ∧ is_open o ∧ μ o < ∞ := measure.exists_is_open_measure_lt_top μ x, refine ⟨s ∩ o, inter_mem_nhds_within _ (o_open.mem_nhds xo), _⟩, let s' := s ∩ o, by_contra, apply lt_irrefl (ρ s'), calc ρ s' ≤ c * μ s' : v.measure_le_of_frequently_le (c • μ) hρ s' (λ x hx, hc x hx.1) ... < d * μ s' : begin apply (ennreal.mul_lt_mul_right h _).2 (ennreal.coe_lt_coe.2 hcd), exact (lt_of_le_of_lt (measure_mono (inter_subset_right _ _)) μo).ne, end ... ≤ ρ s' : v.measure_le_of_frequently_le ρ ((measure.absolutely_continuous.refl μ).smul d) s' (λ x hx, hd x hx.1) end /-- If `ρ` is absolutely continuous with respect to `μ`, then for almost every `x`, the ratio `ρ a / μ a` converges as `a` shrinks to `x` along a Vitali family for `μ`. -/ theorem ae_tendsto_div : ∀ᵐ x ∂μ, ∃ c, tendsto (λ a, ρ a / μ a) (v.filter_at x) (𝓝 c) := begin obtain ⟨w, w_count, w_dense, w_zero, w_top⟩ : ∃ w : set ℝ≥0∞, w.countable ∧ dense w ∧ 0 ∉ w ∧ ∞ ∉ w := ennreal.exists_countable_dense_no_zero_top, have I : ∀ x ∈ w, x ≠ ∞ := λ x xs hx, w_top (hx ▸ xs), have A : ∀ (c ∈ w) (d ∈ w), (c < d) → ∀ᵐ x ∂μ, ¬((∃ᶠ a in v.filter_at x, ρ a / μ a < c) ∧ (∃ᶠ a in v.filter_at x, d < ρ a / μ a)), { assume c hc d hd hcd, lift c to ℝ≥0 using I c hc, lift d to ℝ≥0 using I d hd, apply v.null_of_frequently_le_of_frequently_ge hρ (ennreal.coe_lt_coe.1 hcd), { simp only [and_imp, exists_prop, not_frequently, not_and, not_lt, not_le, not_eventually, mem_set_of_eq, mem_compl_eq, not_forall], assume x h1x h2x, apply h1x.mono (λ a ha, _), refine (ennreal.div_le_iff_le_mul _ (or.inr (bot_le.trans_lt ha).ne')).1 ha.le, simp only [ennreal.coe_ne_top, ne.def, or_true, not_false_iff] }, { simp only [and_imp, exists_prop, not_frequently, not_and, not_lt, not_le, not_eventually, mem_set_of_eq, mem_compl_eq, not_forall], assume x h1x h2x, apply h2x.mono (λ a ha, _), exact ennreal.mul_le_of_le_div ha.le } }, have B : ∀ᵐ x ∂μ, ∀ (c ∈ w) (d ∈ w), (c < d) → ¬((∃ᶠ a in v.filter_at x, ρ a / μ a < c) ∧ (∃ᶠ a in v.filter_at x, d < ρ a / μ a)), by simpa only [ae_ball_iff w_count, ae_imp_iff], filter_upwards [B], assume x hx, exact tendsto_of_no_upcrossings w_dense hx, end lemma ae_tendsto_lim_ratio : ∀ᵐ x ∂μ, tendsto (λ a, ρ a / μ a) (v.filter_at x) (𝓝 (v.lim_ratio ρ x)) := begin filter_upwards [v.ae_tendsto_div hρ], assume x hx, exact tendsto_nhds_lim hx, end /-- Given two thresholds `p < q`, the sets `{x | v.lim_ratio ρ x < p}` and `{x | q < v.lim_ratio ρ x}` are obviously disjoint. The key to proving that `v.lim_ratio ρ` is almost everywhere measurable is to show that these sets have measurable supersets which are also disjoint, up to zero measure. This is the content of this lemma. -/ lemma exists_measurable_supersets_lim_ratio {p q : ℝ≥0} (hpq : p < q) : ∃ a b, measurable_set a ∧ measurable_set b ∧ {x | v.lim_ratio ρ x < p} ⊆ a ∧ {x | (q : ℝ≥0∞) < v.lim_ratio ρ x} ⊆ b ∧ μ (a ∩ b) = 0 := begin /- Here is a rough sketch, assuming that the measure is finite and the limit is well defined everywhere. Let `u := {x | v.lim_ratio ρ x < p}` and `w := {x | q < v.lim_ratio ρ x}`. They have measurable supersets `u'` and `w'` of the same measure. We will show that these satisfy the conclusion of the theorem, i.e., `μ (u' ∩ w') = 0`. For this, note that `ρ (u' ∩ w') = ρ (u ∩ w')` (as `w'` is measurable, see `measure_to_measurable_add_inter_left`). The latter set is included in the set where the limit of the ratios is `< p`, and therefore its measure is `≤ p * μ (u ∩ w')`. Using the same trick in the other direction gives that this is `p * μ (u' ∩ w')`. We have shown that `ρ (u' ∩ w') ≤ p * μ (u' ∩ w')`. Arguing in the same way but using the `w` part gives `q * μ (u' ∩ w') ≤ ρ (u' ∩ w')`. If `μ (u' ∩ w')` were nonzero, this would be a contradiction as `p < q`. For the rigorous proof, we need to work on a part of the space where the measure is finite (provided by `spanning_sets (ρ + μ)`) and to restrict to the set where the limit is well defined (called `s` below, of full measure). Otherwise, the argument goes through. -/ let s := {x | ∃ c, tendsto (λ a, ρ a / μ a) (v.filter_at x) (𝓝 c)}, let o : ℕ → set α := spanning_sets (ρ + μ), let u := λ n, s ∩ {x | v.lim_ratio ρ x < p} ∩ o n, let w := λ n, s ∩ {x | (q : ℝ≥0∞) < v.lim_ratio ρ x} ∩ o n, -- the supersets are obtained by restricting to the set `s` where the limit is well defined, to -- a finite measure part `o n`, taking a measurable superset here, and then taking the union over -- `n`. refine ⟨to_measurable μ sᶜ ∪ (⋃ n, to_measurable (ρ + μ) (u n)), to_measurable μ sᶜ ∪ (⋃ n, to_measurable (ρ + μ) (w n)), _, _, _, _, _⟩, -- check that these sets are measurable supersets as required { exact (measurable_set_to_measurable _ _).union (measurable_set.Union (λ n, (measurable_set_to_measurable _ _))) }, { exact (measurable_set_to_measurable _ _).union (measurable_set.Union (λ n, (measurable_set_to_measurable _ _))) }, { assume x hx, by_cases h : x ∈ s, { refine or.inr (mem_Union.2 ⟨spanning_sets_index (ρ + μ) x, _⟩), exact subset_to_measurable _ _ ⟨⟨h, hx⟩, mem_spanning_sets_index _ _⟩ }, { exact or.inl (subset_to_measurable μ sᶜ h) } }, { assume x hx, by_cases h : x ∈ s, { refine or.inr (mem_Union.2 ⟨spanning_sets_index (ρ + μ) x, _⟩), exact subset_to_measurable _ _ ⟨⟨h, hx⟩, mem_spanning_sets_index _ _⟩ }, { exact or.inl (subset_to_measurable μ sᶜ h) } }, -- it remains to check the nontrivial part that these sets have zero measure intersection. -- it suffices to do it for fixed `m` and `n`, as one is taking countable unions. suffices H : ∀ (m n : ℕ), μ (to_measurable (ρ + μ) (u m) ∩ to_measurable (ρ + μ) (w n)) = 0, { have A : (to_measurable μ sᶜ ∪ (⋃ n, to_measurable (ρ + μ) (u n))) ∩ (to_measurable μ sᶜ ∪ (⋃ n, to_measurable (ρ + μ) (w n))) ⊆ to_measurable μ sᶜ ∪ (⋃ m n, (to_measurable (ρ + μ) (u m)) ∩ (to_measurable (ρ + μ) (w n))), { simp only [inter_distrib_left, inter_distrib_right, true_and, subset_union_left, union_subset_iff, inter_self], refine ⟨_, _, _⟩, { exact (inter_subset_left _ _).trans (subset_union_left _ _) }, { exact (inter_subset_right _ _).trans (subset_union_left _ _) }, { simp_rw [Union_inter, inter_Union], exact subset_union_right _ _ } }, refine le_antisymm ((measure_mono A).trans _) bot_le, calc μ (to_measurable μ sᶜ ∪ (⋃ m n, (to_measurable (ρ + μ) (u m)) ∩ (to_measurable (ρ + μ) (w n)))) ≤ μ (to_measurable μ sᶜ) + μ (⋃ m n, (to_measurable (ρ + μ) (u m)) ∩ (to_measurable (ρ + μ) (w n))) : measure_union_le _ _ ... = μ (⋃ m n, (to_measurable (ρ + μ) (u m)) ∩ (to_measurable (ρ + μ) (w n))) : by { have : μ sᶜ = 0 := v.ae_tendsto_div hρ, rw [measure_to_measurable, this, zero_add] } ... ≤ ∑' m n, μ ((to_measurable (ρ + μ) (u m)) ∩ (to_measurable (ρ + μ) (w n))) : (measure_Union_le _).trans (ennreal.tsum_le_tsum (λ m, measure_Union_le _)) ... = 0 : by simp only [H, tsum_zero] }, -- now starts the nontrivial part of the argument. We fix `m` and `n`, and show that the -- measurable supersets of `u m` and `w n` have zero measure intersection by using the lemmas -- `measure_to_measurable_add_inter_left` (to reduce to `u m` or `w n` instead of the measurable -- superset) and `measure_le_of_frequently_le` to compare their measures for `ρ` and `μ`. assume m n, have I : (ρ + μ) (u m) ≠ ∞, { apply (lt_of_le_of_lt (measure_mono _) (measure_spanning_sets_lt_top (ρ + μ) m)).ne, exact inter_subset_right _ _ }, have J : (ρ + μ) (w n) ≠ ∞, { apply (lt_of_le_of_lt (measure_mono _) (measure_spanning_sets_lt_top (ρ + μ) n)).ne, exact inter_subset_right _ _ }, have A : ρ (to_measurable (ρ + μ) (u m) ∩ to_measurable (ρ + μ) (w n)) ≤ p * μ (to_measurable (ρ + μ) (u m) ∩ to_measurable (ρ + μ) (w n)) := calc ρ (to_measurable (ρ + μ) (u m) ∩ to_measurable (ρ + μ) (w n)) = ρ (u m ∩ to_measurable (ρ + μ) (w n)) : measure_to_measurable_add_inter_left (measurable_set_to_measurable _ _) I ... ≤ (p • μ) (u m ∩ to_measurable (ρ + μ) (w n)) : begin refine v.measure_le_of_frequently_le _ hρ _ (λ x hx, _), have L : tendsto (λ (a : set α), ρ a / μ a) (v.filter_at x) (𝓝 (v.lim_ratio ρ x)) := tendsto_nhds_lim hx.1.1.1, have I : ∀ᶠ (b : set α) in v.filter_at x, ρ b / μ b < p := (tendsto_order.1 L).2 _ hx.1.1.2, apply I.frequently.mono (λ a ha, _), rw [coe_nnreal_smul_apply], refine (ennreal.div_le_iff_le_mul _ (or.inr (bot_le.trans_lt ha).ne')).1 ha.le, simp only [ennreal.coe_ne_top, ne.def, or_true, not_false_iff] end ... = p * μ (to_measurable (ρ + μ) (u m) ∩ to_measurable (ρ + μ) (w n)) : by simp only [coe_nnreal_smul_apply, (measure_to_measurable_add_inter_right (measurable_set_to_measurable _ _) I)], have B : (q : ℝ≥0∞) * μ (to_measurable (ρ + μ) (u m) ∩ to_measurable (ρ + μ) (w n)) ≤ ρ (to_measurable (ρ + μ) (u m) ∩ to_measurable (ρ + μ) (w n)) := calc (q : ℝ≥0∞) * μ (to_measurable (ρ + μ) (u m) ∩ to_measurable (ρ + μ) (w n)) = (q : ℝ≥0∞) * μ (to_measurable (ρ + μ) (u m) ∩ w n) : begin conv_rhs { rw inter_comm }, rw [inter_comm, measure_to_measurable_add_inter_right (measurable_set_to_measurable _ _) J] end ... ≤ ρ (to_measurable (ρ + μ) (u m) ∩ w n) : begin rw [← coe_nnreal_smul_apply], refine v.measure_le_of_frequently_le _ (absolutely_continuous.rfl.smul _) _ _, assume x hx, have L : tendsto (λ (a : set α), ρ a / μ a) (v.filter_at x) (𝓝 (v.lim_ratio ρ x)) := tendsto_nhds_lim hx.2.1.1, have I : ∀ᶠ (b : set α) in v.filter_at x, (q : ℝ≥0∞) < ρ b / μ b := (tendsto_order.1 L).1 _ hx.2.1.2, apply I.frequently.mono (λ a ha, _), rw [coe_nnreal_smul_apply], exact ennreal.mul_le_of_le_div ha.le end ... = ρ (to_measurable (ρ + μ) (u m) ∩ to_measurable (ρ + μ) (w n)) : begin conv_rhs { rw inter_comm }, rw inter_comm, exact (measure_to_measurable_add_inter_left (measurable_set_to_measurable _ _) J).symm, end, by_contra, apply lt_irrefl (ρ (to_measurable (ρ + μ) (u m) ∩ to_measurable (ρ + μ) (w n))), calc ρ (to_measurable (ρ + μ) (u m) ∩ to_measurable (ρ + μ) (w n)) ≤ p * μ (to_measurable (ρ + μ) (u m) ∩ to_measurable (ρ + μ) (w n)) : A ... < q * μ (to_measurable (ρ + μ) (u m) ∩ to_measurable (ρ + μ) (w n)) : begin apply (ennreal.mul_lt_mul_right h _).2 (ennreal.coe_lt_coe.2 hpq), suffices H : (ρ + μ) (to_measurable (ρ + μ) (u m) ∩ to_measurable (ρ + μ) (w n)) ≠ ∞, { simp only [not_or_distrib, ennreal.add_eq_top, pi.add_apply, ne.def, coe_add] at H, exact H.2 }, apply (lt_of_le_of_lt (measure_mono (inter_subset_left _ _)) _).ne, rw measure_to_measurable, apply lt_of_le_of_lt (measure_mono _) (measure_spanning_sets_lt_top (ρ + μ) m), exact inter_subset_right _ _ end ... ≤ ρ (to_measurable (ρ + μ) (u m) ∩ to_measurable (ρ + μ) (w n)) : B end theorem ae_measurable_lim_ratio : ae_measurable (v.lim_ratio ρ) μ := begin apply ennreal.ae_measurable_of_exist_almost_disjoint_supersets _ _ (λ p q hpq, _), exact v.exists_measurable_supersets_lim_ratio hρ hpq, end /-- A measurable version of `v.lim_ratio ρ`. Do *not* use this definition: it is only a temporary device to show that `v.lim_ratio` is almost everywhere equal to the Radon-Nikodym derivative. -/ noncomputable def lim_ratio_meas : α → ℝ≥0∞ := (v.ae_measurable_lim_ratio hρ).mk _ lemma lim_ratio_meas_measurable : measurable (v.lim_ratio_meas hρ) := ae_measurable.measurable_mk _ lemma ae_tendsto_lim_ratio_meas : ∀ᵐ x ∂μ, tendsto (λ a, ρ a / μ a) (v.filter_at x) (𝓝 (v.lim_ratio_meas hρ x)) := begin filter_upwards [v.ae_tendsto_lim_ratio hρ, ae_measurable.ae_eq_mk (v.ae_measurable_lim_ratio hρ)], assume x hx h'x, rwa h'x at hx, end /-- If, for all `x` in a set `s`, one has frequently `ρ a / μ a < p`, then `ρ s ≤ p * μ s`, as proved in `measure_le_of_frequently_le`. Since `ρ a / μ a` tends almost everywhere to `v.lim_ratio_meas hρ x`, the same property holds for sets `s` on which `v.lim_ratio_meas hρ < p`. -/ lemma measure_le_mul_of_subset_lim_ratio_meas_lt {p : ℝ≥0} {s : set α} (h : s ⊆ {x | v.lim_ratio_meas hρ x < p}) : ρ s ≤ p * μ s := begin let t := {x : α | tendsto (λ a, ρ a / μ a) (v.filter_at x) (𝓝 (v.lim_ratio_meas hρ x))}, have A : μ tᶜ = 0 := v.ae_tendsto_lim_ratio_meas hρ, suffices H : ρ (s ∩ t) ≤ (p • μ) (s ∩ t), from calc ρ s = ρ ((s ∩ t) ∪ (s ∩ tᶜ)) : by rw inter_union_compl ... ≤ ρ (s ∩ t) + ρ (s ∩ tᶜ) : measure_union_le _ _ ... ≤ p * μ (s ∩ t) + 0 : add_le_add H ((measure_mono (inter_subset_right _ _)).trans (hρ A).le) ... ≤ p * μ s : by { rw add_zero, exact ennreal.mul_le_mul le_rfl (measure_mono (inter_subset_left _ _)) }, refine v.measure_le_of_frequently_le _ hρ _ (λ x hx, _), have I : ∀ᶠ (b : set α) in v.filter_at x, ρ b / μ b < p := (tendsto_order.1 hx.2).2 _ (h hx.1), apply I.frequently.mono (λ a ha, _), rw [coe_nnreal_smul_apply], refine (ennreal.div_le_iff_le_mul _ (or.inr (bot_le.trans_lt ha).ne')).1 ha.le, simp only [ennreal.coe_ne_top, ne.def, or_true, not_false_iff] end /-- If, for all `x` in a set `s`, one has frequently `q < ρ a / μ a`, then `q * μ s ≤ ρ s`, as proved in `measure_le_of_frequently_le`. Since `ρ a / μ a` tends almost everywhere to `v.lim_ratio_meas hρ x`, the same property holds for sets `s` on which `q < v.lim_ratio_meas hρ`. -/ lemma mul_measure_le_of_subset_lt_lim_ratio_meas {q : ℝ≥0} {s : set α} (h : s ⊆ {x | (q : ℝ≥0∞) < v.lim_ratio_meas hρ x}) : (q : ℝ≥0∞) * μ s ≤ ρ s := begin let t := {x : α | tendsto (λ a, ρ a / μ a) (v.filter_at x) (𝓝 (v.lim_ratio_meas hρ x))}, have A : μ tᶜ = 0 := v.ae_tendsto_lim_ratio_meas hρ, suffices H : (q • μ) (s ∩ t) ≤ ρ (s ∩ t), from calc (q • μ) s = (q • μ) ((s ∩ t) ∪ (s ∩ tᶜ)) : by rw inter_union_compl ... ≤ (q • μ) (s ∩ t) + (q • μ) (s ∩ tᶜ) : measure_union_le _ _ ... ≤ ρ (s ∩ t) + q * μ tᶜ : begin apply add_le_add H, rw [coe_nnreal_smul_apply], exact ennreal.mul_le_mul le_rfl (measure_mono (inter_subset_right _ _)), end ... ≤ ρ s : by { rw [A, mul_zero, add_zero], exact measure_mono (inter_subset_left _ _) }, refine v.measure_le_of_frequently_le _ (absolutely_continuous.rfl.smul _) _ _, assume x hx, have I : ∀ᶠ a in v.filter_at x, (q : ℝ≥0∞) < ρ a / μ a := (tendsto_order.1 hx.2).1 _ (h hx.1), apply I.frequently.mono (λ a ha, _), rw [coe_nnreal_smul_apply], exact ennreal.mul_le_of_le_div ha.le end /-- The points with `v.lim_ratio_meas hρ x = ∞` have measure `0` for `μ`. -/ lemma measure_lim_ratio_meas_top : μ {x | v.lim_ratio_meas hρ x = ∞} = 0 := begin refine null_of_locally_null _ (λ x hx, _), obtain ⟨o, xo, o_open, μo⟩ : ∃ o : set α, x ∈ o ∧ is_open o ∧ ρ o < ∞ := measure.exists_is_open_measure_lt_top ρ x, let s := {x : α | v.lim_ratio_meas hρ x = ∞} ∩ o, refine ⟨s, inter_mem_nhds_within _ (o_open.mem_nhds xo), le_antisymm _ bot_le⟩, have ρs : ρ s ≠ ∞ := ((measure_mono (inter_subset_right _ _)).trans_lt μo).ne, have A : ∀ (q : ℝ≥0), 1 ≤ q → μ s ≤ q⁻¹ * ρ s, { assume q hq, rw [mul_comm, ← div_eq_mul_inv, ennreal.le_div_iff_mul_le _ (or.inr ρs), mul_comm], { apply v.mul_measure_le_of_subset_lt_lim_ratio_meas hρ, assume y hy, have : v.lim_ratio_meas hρ y = ∞ := hy.1, simp only [this, ennreal.coe_lt_top, mem_set_of_eq], }, { simp only [(zero_lt_one.trans_le hq).ne', true_or, ennreal.coe_eq_zero, ne.def, not_false_iff] } }, have B : tendsto (λ (q : ℝ≥0), (q : ℝ≥0∞)⁻¹ * ρ s) at_top (𝓝 (∞⁻¹ * ρ s)), { apply ennreal.tendsto.mul_const _ (or.inr ρs), exact ennreal.tendsto_inv_iff.2 (ennreal.tendsto_coe_nhds_top.2 tendsto_id) }, simp only [zero_mul, ennreal.inv_top] at B, apply ge_of_tendsto B, exact eventually_at_top.2 ⟨1, A⟩, end /-- The points with `v.lim_ratio_meas hρ x = 0` have measure `0` for `ρ`. -/ lemma measure_lim_ratio_meas_zero : ρ {x | v.lim_ratio_meas hρ x = 0} = 0 := begin refine null_of_locally_null _ (λ x hx, _), obtain ⟨o, xo, o_open, μo⟩ : ∃ o : set α, x ∈ o ∧ is_open o ∧ μ o < ∞ := measure.exists_is_open_measure_lt_top μ x, let s := {x : α | v.lim_ratio_meas hρ x = 0} ∩ o, refine ⟨s, inter_mem_nhds_within _ (o_open.mem_nhds xo), le_antisymm _ bot_le⟩, have μs : μ s ≠ ∞ := ((measure_mono (inter_subset_right _ _)).trans_lt μo).ne, have A : ∀ (q : ℝ≥0), 0 < q → ρ s ≤ q * μ s, { assume q hq, apply v.measure_le_mul_of_subset_lim_ratio_meas_lt hρ, assume y hy, have : v.lim_ratio_meas hρ y = 0 := hy.1, simp only [this, mem_set_of_eq, hq, ennreal.coe_pos], }, have B : tendsto (λ (q : ℝ≥0), (q : ℝ≥0∞) * μ s) (𝓝[>] (0 : ℝ≥0)) (𝓝 ((0 : ℝ≥0) * μ s)), { apply ennreal.tendsto.mul_const _ (or.inr μs), rw ennreal.tendsto_coe, exact nhds_within_le_nhds }, simp only [zero_mul, ennreal.coe_zero] at B, apply ge_of_tendsto B, filter_upwards [self_mem_nhds_within] using A, end /-- As an intermediate step to show that `μ.with_density (v.lim_ratio_meas hρ) = ρ`, we show here that `μ.with_density (v.lim_ratio_meas hρ) ≤ t^2 ρ` for any `t > 1`. -/ lemma with_density_le_mul {s : set α} (hs : measurable_set s) {t : ℝ≥0} (ht : 1 < t) : μ.with_density (v.lim_ratio_meas hρ) s ≤ t^2 * ρ s := begin /- We cut `s` into the sets where `v.lim_ratio_meas hρ = 0`, where `v.lim_ratio_meas hρ = ∞`, and where `v.lim_ratio_meas hρ ∈ [t^n, t^(n+1))` for `n : ℤ`. The first and second have measure `0`. For the latter, since `v.lim_ratio_meas hρ` fluctuates by at most `t` on this slice, we can use `measure_le_mul_of_subset_lim_ratio_meas_lt` and `mul_measure_le_of_subset_lt_lim_ratio_meas` to show that the two measures are comparable up to `t` (in fact `t^2` for technical reasons of strict inequalities). -/ have t_ne_zero' : t ≠ 0 := (zero_lt_one.trans ht).ne', have t_ne_zero : (t : ℝ≥0∞) ≠ 0, by simpa only [ennreal.coe_eq_zero, ne.def] using t_ne_zero', let ν := μ.with_density (v.lim_ratio_meas hρ), let f := v.lim_ratio_meas hρ, have f_meas : measurable f := v.lim_ratio_meas_measurable hρ, have A : ν (s ∩ f ⁻¹' ({0})) ≤ ((t : ℝ≥0∞)^2 • ρ) (s ∩ f⁻¹' {0}), { apply le_trans _ (zero_le _), have M : measurable_set (s ∩ f ⁻¹' ({0})) := hs.inter (f_meas (measurable_set_singleton _)), simp only [ν, f, nonpos_iff_eq_zero, M, with_density_apply, lintegral_eq_zero_iff f_meas], apply (ae_restrict_iff' M).2, exact eventually_of_forall (λ x hx, hx.2) }, have B : ν (s ∩ f ⁻¹' ({∞})) ≤ ((t : ℝ≥0∞)^2 • ρ) (s ∩ f⁻¹' {∞}), { apply le_trans (le_of_eq _) (zero_le _), apply with_density_absolutely_continuous μ _, rw ← nonpos_iff_eq_zero, exact (measure_mono (inter_subset_right _ _)).trans (v.measure_lim_ratio_meas_top hρ).le }, have C : ∀ (n : ℤ), ν (s ∩ f⁻¹' (Ico (t^n) (t^(n+1)))) ≤ ((t : ℝ≥0∞)^2 • ρ) (s ∩ f⁻¹' (Ico (t^n) (t^(n+1)))), { assume n, let I := Ico ((t : ℝ≥0∞)^n) (t^(n+1)), have M : measurable_set (s ∩ f ⁻¹' I) := hs.inter (f_meas measurable_set_Ico), simp only [f, M, with_density_apply, coe_nnreal_smul_apply], calc ∫⁻ x in s ∩ f⁻¹' I, f x ∂μ ≤ ∫⁻ x in s ∩ f⁻¹' I, t^(n+1) ∂μ : lintegral_mono_ae ((ae_restrict_iff' M).2 (eventually_of_forall (λ x hx, hx.2.2.le))) ... = t^(n+1) * μ (s ∩ f⁻¹' I) : by simp only [lintegral_const, measurable_set.univ, measure.restrict_apply, univ_inter] ... = t^(2 : ℤ) * (t^(n-1) * μ (s ∩ f⁻¹' I)) : begin rw [← mul_assoc, ← ennreal.zpow_add t_ne_zero ennreal.coe_ne_top], congr' 2, abel, end ... ≤ t^2 * ρ (s ∩ f ⁻¹' I) : begin apply ennreal.mul_le_mul le_rfl _, rw ← ennreal.coe_zpow (zero_lt_one.trans ht).ne', apply v.mul_measure_le_of_subset_lt_lim_ratio_meas hρ, assume x hx, apply lt_of_lt_of_le _ hx.2.1, rw [← ennreal.coe_zpow (zero_lt_one.trans ht).ne', ennreal.coe_lt_coe, sub_eq_add_neg, zpow_add₀ t_ne_zero'], conv_rhs { rw ← mul_one (t^ n) }, refine mul_lt_mul' le_rfl _ (zero_le _) (nnreal.zpow_pos t_ne_zero' _), rw zpow_neg_one, exact nnreal.inv_lt_one ht, end }, calc ν s = ν (s ∩ f⁻¹' {0}) + ν (s ∩ f⁻¹' {∞}) + ∑' (n : ℤ), ν (s ∩ f⁻¹' (Ico (t^n) (t^(n+1)))) : measure_eq_measure_preimage_add_measure_tsum_Ico_zpow ν f_meas hs ht ... ≤ ((t : ℝ≥0∞)^2 • ρ) (s ∩ f⁻¹' {0}) + ((t : ℝ≥0∞)^2 • ρ) (s ∩ f⁻¹' {∞}) + ∑' (n : ℤ), ((t : ℝ≥0∞)^2 • ρ) (s ∩ f⁻¹' (Ico (t^n) (t^(n+1)))) : add_le_add (add_le_add A B) (ennreal.tsum_le_tsum C) ... = ((t : ℝ≥0∞)^2 • ρ) s : (measure_eq_measure_preimage_add_measure_tsum_Ico_zpow ((t : ℝ≥0∞)^2 • ρ) f_meas hs ht).symm end /-- As an intermediate step to show that `μ.with_density (v.lim_ratio_meas hρ) = ρ`, we show here that `ρ ≤ t μ.with_density (v.lim_ratio_meas hρ)` for any `t > 1`. -/ lemma le_mul_with_density {s : set α} (hs : measurable_set s) {t : ℝ≥0} (ht : 1 < t) : ρ s ≤ t * μ.with_density (v.lim_ratio_meas hρ) s := begin /- We cut `s` into the sets where `v.lim_ratio_meas hρ = 0`, where `v.lim_ratio_meas hρ = ∞`, and where `v.lim_ratio_meas hρ ∈ [t^n, t^(n+1))` for `n : ℤ`. The first and second have measure `0`. For the latter, since `v.lim_ratio_meas hρ` fluctuates by at most `t` on this slice, we can use `measure_le_mul_of_subset_lim_ratio_meas_lt` and `mul_measure_le_of_subset_lt_lim_ratio_meas` to show that the two measures are comparable up to `t`. -/ have t_ne_zero' : t ≠ 0 := (zero_lt_one.trans ht).ne', have t_ne_zero : (t : ℝ≥0∞) ≠ 0, by simpa only [ennreal.coe_eq_zero, ne.def] using t_ne_zero', let ν := μ.with_density (v.lim_ratio_meas hρ), let f := v.lim_ratio_meas hρ, have f_meas : measurable f := v.lim_ratio_meas_measurable hρ, have A : ρ (s ∩ f ⁻¹' ({0})) ≤ (t • ν) (s ∩ f⁻¹' {0}), { refine le_trans (measure_mono (inter_subset_right _ _)) (le_trans (le_of_eq _) (zero_le _)), exact v.measure_lim_ratio_meas_zero hρ }, have B : ρ (s ∩ f ⁻¹' ({∞})) ≤ (t • ν) (s ∩ f⁻¹' {∞}), { apply le_trans (le_of_eq _) (zero_le _), apply hρ, rw ← nonpos_iff_eq_zero, exact (measure_mono (inter_subset_right _ _)).trans (v.measure_lim_ratio_meas_top hρ).le }, have C : ∀ (n : ℤ), ρ (s ∩ f⁻¹' (Ico (t^n) (t^(n+1)))) ≤ (t • ν) (s ∩ f⁻¹' (Ico (t^n) (t^(n+1)))), { assume n, let I := Ico ((t : ℝ≥0∞)^n) (t^(n+1)), have M : measurable_set (s ∩ f ⁻¹' I) := hs.inter (f_meas measurable_set_Ico), simp only [f, M, with_density_apply, coe_nnreal_smul_apply], calc ρ (s ∩ f ⁻¹' I) ≤ t^ (n+1) * μ (s ∩ f ⁻¹' I) : begin rw ← ennreal.coe_zpow t_ne_zero', apply v.measure_le_mul_of_subset_lim_ratio_meas_lt hρ, assume x hx, apply hx.2.2.trans_le (le_of_eq _), rw ennreal.coe_zpow t_ne_zero', end ... = ∫⁻ x in s ∩ f⁻¹' I, t^(n+1) ∂μ : by simp only [lintegral_const, measurable_set.univ, measure.restrict_apply, univ_inter] ... ≤ ∫⁻ x in s ∩ f⁻¹' I, t * f x ∂μ : begin apply lintegral_mono_ae ((ae_restrict_iff' M).2 (eventually_of_forall (λ x hx, _))), rw [add_comm, ennreal.zpow_add t_ne_zero ennreal.coe_ne_top, zpow_one], exact ennreal.mul_le_mul le_rfl hx.2.1, end ... = t * ∫⁻ x in s ∩ f⁻¹' I, f x ∂μ : lintegral_const_mul _ f_meas }, calc ρ s = ρ (s ∩ f⁻¹' {0}) + ρ (s ∩ f⁻¹' {∞}) + ∑' (n : ℤ), ρ (s ∩ f⁻¹' (Ico (t^n) (t^(n+1)))) : measure_eq_measure_preimage_add_measure_tsum_Ico_zpow ρ f_meas hs ht ... ≤ (t • ν) (s ∩ f⁻¹' {0}) + (t • ν) (s ∩ f⁻¹' {∞}) + ∑' (n : ℤ), (t • ν) (s ∩ f⁻¹' (Ico (t^n) (t^(n+1)))) : add_le_add (add_le_add A B) (ennreal.tsum_le_tsum C) ... = (t • ν) s : (measure_eq_measure_preimage_add_measure_tsum_Ico_zpow (t • ν) f_meas hs ht).symm end theorem with_density_lim_ratio_meas_eq : μ.with_density (v.lim_ratio_meas hρ) = ρ := begin ext1 s hs, refine le_antisymm _ _, { have : tendsto (λ (t : ℝ≥0), (t^2 * ρ s : ℝ≥0∞)) (𝓝[>] 1) (𝓝 ((1 : ℝ≥0)^2 * ρ s)), { refine ennreal.tendsto.mul _ _ tendsto_const_nhds _, { exact ennreal.tendsto.pow (ennreal.tendsto_coe.2 nhds_within_le_nhds) }, { simp only [one_pow, ennreal.coe_one, true_or, ne.def, not_false_iff, one_ne_zero] }, { simp only [one_pow, ennreal.coe_one, ne.def, or_true, ennreal.one_ne_top, not_false_iff] } }, simp only [one_pow, one_mul, ennreal.coe_one] at this, refine ge_of_tendsto this _, filter_upwards [self_mem_nhds_within] with _ ht, exact v.with_density_le_mul hρ hs ht, }, { have : tendsto (λ (t : ℝ≥0), (t : ℝ≥0∞) * μ.with_density (v.lim_ratio_meas hρ) s) (𝓝[>] 1) (𝓝 ((1 : ℝ≥0) * μ.with_density (v.lim_ratio_meas hρ) s)), { refine ennreal.tendsto.mul_const (ennreal.tendsto_coe.2 nhds_within_le_nhds) _, simp only [ennreal.coe_one, true_or, ne.def, not_false_iff, one_ne_zero], }, simp only [one_mul, ennreal.coe_one] at this, refine ge_of_tendsto this _, filter_upwards [self_mem_nhds_within] with _ ht, exact v.le_mul_with_density hρ hs ht } end /-- Weak version of the main theorem on differentiation of measures: given a Vitali family `v` for a locally finite measure `μ`, and another locally finite measure `ρ`, then for `μ`-almost every `x` the ratio `ρ a / μ a` converges, when `a` shrinks to `x` along the Vitali family, towards the Radon-Nikodym derivative of `ρ` with respect to `μ`. This version assumes that `ρ` is absolutely continuous with respect to `μ`. The general version without this superfluous assumption is `vitali_family.ae_tendsto_rn_deriv`. -/ theorem ae_tendsto_rn_deriv_of_absolutely_continuous : ∀ᵐ x ∂μ, tendsto (λ a, ρ a / μ a) (v.filter_at x) (𝓝 (ρ.rn_deriv μ x)) := begin have A : (μ.with_density (v.lim_ratio_meas hρ)).rn_deriv μ =ᵐ[μ] v.lim_ratio_meas hρ := rn_deriv_with_density μ (v.lim_ratio_meas_measurable hρ), rw v.with_density_lim_ratio_meas_eq hρ at A, filter_upwards [v.ae_tendsto_lim_ratio_meas hρ, A] with _ _ h'x, rwa h'x, end end absolutely_continuous variable (ρ) /-- Main theorem on differentiation of measures: given a Vitali family `v` for a locally finite measure `μ`, and another locally finite measure `ρ`, then for `μ`-almost every `x` the ratio `ρ a / μ a` converges, when `a` shrinks to `x` along the Vitali family, towards the Radon-Nikodym derivative of `ρ` with respect to `μ`. -/ theorem ae_tendsto_rn_deriv : ∀ᵐ x ∂μ, tendsto (λ a, ρ a / μ a) (v.filter_at x) (𝓝 (ρ.rn_deriv μ x)) := begin let t := μ.with_density (ρ.rn_deriv μ), have eq_add : ρ = ρ.singular_part μ + t := have_lebesgue_decomposition_add _ _, have A : ∀ᵐ x ∂μ, tendsto (λ a, ρ.singular_part μ a / μ a) (v.filter_at x) (𝓝 0) := v.ae_eventually_measure_zero_of_singular (mutually_singular_singular_part ρ μ), have B : ∀ᵐ x ∂μ, t.rn_deriv μ x = ρ.rn_deriv μ x := rn_deriv_with_density μ (measurable_rn_deriv ρ μ), have C : ∀ᵐ x ∂μ, tendsto (λ a, t a / μ a) (v.filter_at x) (𝓝 (t.rn_deriv μ x)) := v.ae_tendsto_rn_deriv_of_absolutely_continuous (with_density_absolutely_continuous _ _), filter_upwards [A, B, C] with _ Ax Bx Cx, convert Ax.add Cx, { ext1 a, conv_lhs { rw [eq_add] }, simp only [pi.add_apply, coe_add, ennreal.add_div] }, { simp only [Bx, zero_add] } end /-- Given a measurable set `s`, then `μ (s ∩ a) / μ a` converges when `a` shrinks to a typical point `x` along a Vitali family. The limit is `1` for `x ∈ s` and `0` for `x ∉ s`. This shows that almost every point of `s` is a Lebesgue density point for `s`. A version for non-measurable sets holds, but it only gives the first conclusion, see `ae_tendsto_measure_inter_div`. -/ lemma ae_tendsto_measure_inter_div_of_measurable_set {s : set α} (hs : measurable_set s) : ∀ᵐ x ∂μ, tendsto (λ a, μ (s ∩ a) / μ a) (v.filter_at x) (𝓝 (s.indicator 1 x)) := begin haveI : is_locally_finite_measure (μ.restrict s) := is_locally_finite_measure_of_le restrict_le_self, filter_upwards [ae_tendsto_rn_deriv v (μ.restrict s), rn_deriv_restrict μ hs], assume x hx h'x, simpa only [h'x, restrict_apply' hs, inter_comm] using hx, end /-- Given an arbitrary set `s`, then `μ (s ∩ a) / μ a` converges to `1` when `a` shrinks to a typical point of `s` along a Vitali family. This shows that almost every point of `s` is a Lebesgue density point for `s`. A stronger version for measurable sets is given in `ae_tendsto_measure_inter_div_of_measurable_set`. -/ lemma ae_tendsto_measure_inter_div (s : set α) : ∀ᵐ x ∂(μ.restrict s), tendsto (λ a, μ (s ∩ a) / μ a) (v.filter_at x) (𝓝 1) := begin let t := to_measurable μ s, have A : ∀ᵐ x ∂(μ.restrict s), tendsto (λ a, μ (t ∩ a) / μ a) (v.filter_at x) (𝓝 (t.indicator 1 x)), { apply ae_mono restrict_le_self, apply ae_tendsto_measure_inter_div_of_measurable_set, exact measurable_set_to_measurable _ _ }, have B : ∀ᵐ x ∂(μ.restrict s), t.indicator 1 x = (1 : ℝ≥0∞), { refine ae_restrict_of_ae_restrict_of_subset (subset_to_measurable μ s) _, filter_upwards [ae_restrict_mem (measurable_set_to_measurable μ s)] with _ hx, simp only [hx, pi.one_apply, indicator_of_mem] }, filter_upwards [A, B] with x hx h'x, rw [h'x] at hx, apply hx.congr' _, filter_upwards [v.eventually_filter_at_measurable_set x] with _ ha, congr' 1, exact measure_to_measurable_inter_of_sigma_finite ha _, end end end vitali_family
f0c03449c9380cb3f0e9d5ffde03006e7eb32981
bbecf0f1968d1fba4124103e4f6b55251d08e9c4
/src/group_theory/solvable.lean
602ba5dea7e19479163e1dcb58b7b9120aa09f44
[ "Apache-2.0" ]
permissive
waynemunro/mathlib
e3fd4ff49f4cb43d4a8ded59d17be407bc5ee552
065a70810b5480d584033f7bbf8e0409480c2118
refs/heads/master
1,693,417,182,397
1,634,644,781,000
1,634,644,781,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
10,147
lean
/- Copyright (c) 2021 Jordan Brown, Thomas Browning, Patrick Lutz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jordan Brown, Thomas Browning, Patrick Lutz -/ import data.matrix.notation import group_theory.abelianization import set_theory.cardinal import group_theory.general_commutator /-! # Solvable Groups In this file we introduce the notion of a solvable group. We define a solvable group as one whose derived series is eventually trivial. This requires defining the commutator of two subgroups and the derived series of a group. ## Main definitions * `derived_series G n` : the `n`th term in the derived series of `G`, defined by iterating `general_commutator` starting with the top subgroup * `is_solvable G` : the group `G` is solvable -/ open subgroup variables {G G' : Type*} [group G] [group G'] {f : G →* G'} section derived_series variables (G) /-- The derived series of the group `G`, obtained by starting from the subgroup `⊤` and repeatedly taking the commutator of the previous subgroup with itself for `n` times. -/ def derived_series : ℕ → subgroup G | 0 := ⊤ | (n + 1) := ⁅(derived_series n), (derived_series n)⁆ @[simp] lemma derived_series_zero : derived_series G 0 = ⊤ := rfl @[simp] lemma derived_series_succ (n : ℕ) : derived_series G (n + 1) = ⁅(derived_series G n), (derived_series G n)⁆ := rfl lemma derived_series_normal (n : ℕ) : (derived_series G n).normal := begin induction n with n ih, { exact subgroup.top_normal, }, { rw derived_series_succ, exactI general_commutator_normal (derived_series G n) (derived_series G n), } end @[simp] lemma general_commutator_eq_commutator : ⁅(⊤ : subgroup G), (⊤ : subgroup G)⁆ = commutator G := begin rw [commutator, general_commutator_def'], apply le_antisymm; apply normal_closure_mono, { exact λ x ⟨p, _, q, _, h⟩, ⟨p, q, h⟩, }, { exact λ x ⟨p, q, h⟩, ⟨p, mem_top p, q, mem_top q, h⟩, } end lemma commutator_def' : commutator G = subgroup.closure {x : G | ∃ p q, p * q * p⁻¹ * q⁻¹ = x} := begin rw [← general_commutator_eq_commutator, general_commutator], apply le_antisymm; apply closure_mono, { exact λ x ⟨p, _, q, _, h⟩, ⟨p, q, h⟩ }, { exact λ x ⟨p, q, h⟩, ⟨p, mem_top p, q, mem_top q, h⟩ } end @[simp] lemma derived_series_one : derived_series G 1 = commutator G := general_commutator_eq_commutator G end derived_series section commutator_map lemma map_commutator_eq_commutator_map (H₁ H₂ : subgroup G) : ⁅H₁, H₂⁆.map f = ⁅H₁.map f, H₂.map f⁆ := begin rw [general_commutator, general_commutator, monoid_hom.map_closure], apply le_antisymm; apply closure_mono, { rintros _ ⟨x, ⟨p, hp, q, hq, rfl⟩, rfl⟩, refine ⟨f p, mem_map.mpr ⟨p, hp, rfl⟩, f q, mem_map.mpr ⟨q, hq, rfl⟩, by simp *⟩, }, { rintros x ⟨_, ⟨p, hp, rfl⟩, _, ⟨q, hq, rfl⟩, rfl⟩, refine ⟨p * q * p⁻¹ * q⁻¹, ⟨p, hp, q, hq, rfl⟩, by simp *⟩, }, end lemma commutator_le_map_commutator {H₁ H₂ : subgroup G} {K₁ K₂ : subgroup G'} (h₁ : K₁ ≤ H₁.map f) (h₂ : K₂ ≤ H₂.map f) : ⁅K₁, K₂⁆ ≤ ⁅H₁, H₂⁆.map f := by { rw map_commutator_eq_commutator_map, exact general_commutator_mono h₁ h₂ } section derived_series_map variables (f) lemma map_derived_series_le_derived_series (n : ℕ) : (derived_series G n).map f ≤ derived_series G' n := begin induction n with n ih, { simp only [derived_series_zero, le_top], }, { simp only [derived_series_succ, map_commutator_eq_commutator_map, general_commutator_mono, *], } end variables {f} lemma derived_series_le_map_derived_series (hf : function.surjective f) (n : ℕ) : derived_series G' n ≤ (derived_series G n).map f := begin induction n with n ih, { rwa [derived_series_zero, derived_series_zero, top_le_iff, ← monoid_hom.range_eq_map, ← monoid_hom.range_top_iff_surjective.mpr], }, { simp only [*, derived_series_succ, commutator_le_map_commutator], } end lemma map_derived_series_eq (hf : function.surjective f) (n : ℕ) : (derived_series G n).map f = derived_series G' n := le_antisymm (map_derived_series_le_derived_series f n) (derived_series_le_map_derived_series hf n) end derived_series_map end commutator_map section solvable variables (G) /-- A group `G` is solvable if its derived series is eventually trivial. We use this definition because it's the most convenient one to work with. -/ class is_solvable : Prop := (solvable : ∃ n : ℕ, derived_series G n = ⊥) lemma is_solvable_def : is_solvable G ↔ ∃ n : ℕ, derived_series G n = ⊥ := ⟨λ h, h.solvable, λ h, ⟨h⟩⟩ @[priority 100] instance comm_group.is_solvable {G : Type*} [comm_group G] : is_solvable G := begin use 1, rw [eq_bot_iff, derived_series_one], calc commutator G ≤ (monoid_hom.id G).ker : abelianization.commutator_subset_ker (monoid_hom.id G) ... = ⊥ : rfl, end lemma is_solvable_of_comm {G : Type*} [hG : group G] (h : ∀ a b : G, a * b = b * a) : is_solvable G := begin letI hG' : comm_group G := { mul_comm := h .. hG }, tactic.unfreeze_local_instances, cases hG, exact comm_group.is_solvable, end lemma is_solvable_of_top_eq_bot (h : (⊤ : subgroup G) = ⊥) : is_solvable G := ⟨⟨0, h⟩⟩ @[priority 100] instance is_solvable_of_subsingleton [subsingleton G] : is_solvable G := is_solvable_of_top_eq_bot G (by ext; simp at *) variables {G} lemma solvable_of_solvable_injective (hf : function.injective f) [h : is_solvable G'] : is_solvable G := begin rw is_solvable_def at *, cases h with n hn, use n, rw ← map_eq_bot_iff_of_injective _ hf, rw eq_bot_iff at *, calc map f (derived_series G n) ≤ derived_series G' n : map_derived_series_le_derived_series f n ... ≤ ⊥ : hn, end instance subgroup_solvable_of_solvable (H : subgroup G) [h : is_solvable G] : is_solvable H := solvable_of_solvable_injective (show function.injective (subtype H), from subtype.val_injective) lemma solvable_of_surjective (hf : function.surjective f) [h : is_solvable G] : is_solvable G' := begin rw is_solvable_def at *, cases h with n hn, use n, calc derived_series G' n = (derived_series G n).map f : eq.symm (map_derived_series_eq hf n) ... = (⊥ : subgroup G).map f : by rw hn ... = ⊥ : map_bot f, end instance solvable_quotient_of_solvable (H : subgroup G) [H.normal] [h : is_solvable G] : is_solvable (quotient_group.quotient H) := solvable_of_surjective (show function.surjective (quotient_group.mk' H), by tidy) lemma solvable_of_ker_le_range {G' G'' : Type*} [group G'] [group G''] (f : G' →* G) (g : G →* G'') (hfg : g.ker ≤ f.range) [hG' : is_solvable G'] [hG'' : is_solvable G''] : is_solvable G := begin tactic.unfreeze_local_instances, obtain ⟨n, hn⟩ := hG'', suffices : ∀ k : ℕ, derived_series G (n + k) ≤ (derived_series G' k).map f, { obtain ⟨m, hm⟩ := hG', use n + m, specialize this m, rwa [hm, map_bot, le_bot_iff] at this }, intro k, induction k with k hk, { rw [add_zero, derived_series_zero, ←monoid_hom.range_eq_map], refine le_trans _ hfg, rw [←map_eq_bot_iff, eq_bot_iff, ←hn], exact map_derived_series_le_derived_series g n }, { rw [nat.add_succ, derived_series_succ, derived_series_succ], exact commutator_le_map_commutator hk hk }, end instance solvable_prod {G' : Type*} [group G'] [h : is_solvable G] [h' : is_solvable G'] : is_solvable (G × G') := solvable_of_ker_le_range (monoid_hom.inl G G') (monoid_hom.snd G G') (λ x hx, ⟨x.1, prod.ext rfl hx.symm⟩) end solvable section is_simple_group variable [is_simple_group G] lemma is_simple_group.derived_series_succ {n : ℕ} : derived_series G n.succ = commutator G := begin induction n with n ih, { exact derived_series_one _ }, rw [derived_series_succ, ih], cases (commutator.normal G).eq_bot_or_eq_top with h h; simp [h] end lemma is_simple_group.comm_iff_is_solvable : (∀ a b : G, a * b = b * a) ↔ is_solvable G := ⟨is_solvable_of_comm, λ ⟨⟨n, hn⟩⟩, begin cases n, { rw derived_series_zero at hn, intros a b, refine (mem_bot.1 _).trans (mem_bot.1 _).symm; { rw ← hn, exact mem_top _ } }, { rw is_simple_group.derived_series_succ at hn, intros a b, rw [← mul_inv_eq_one, mul_inv_rev, ← mul_assoc, ← mem_bot, ← hn], exact subset_normal_closure ⟨a, b, rfl⟩ } end⟩ end is_simple_group section perm_not_solvable lemma not_solvable_of_mem_derived_series {g : G} (h1 : g ≠ 1) (h2 : ∀ n : ℕ, g ∈ derived_series G n) : ¬ is_solvable G := mt (is_solvable_def _).mp (not_exists_of_forall_not (λ n h, h1 (subgroup.mem_bot.mp ((congr_arg (has_mem.mem g) h).mp (h2 n))))) lemma equiv.perm.fin_5_not_solvable : ¬ is_solvable (equiv.perm (fin 5)) := begin let x : equiv.perm (fin 5) := ⟨![1, 2, 0, 3, 4], ![2, 0, 1, 3, 4], dec_trivial, dec_trivial⟩, let y : equiv.perm (fin 5) := ⟨![3, 4, 2, 0, 1], ![3, 4, 2, 0, 1], dec_trivial, dec_trivial⟩, let z : equiv.perm (fin 5) := ⟨![0, 3, 2, 1, 4], ![0, 3, 2, 1, 4], dec_trivial, dec_trivial⟩, have x_ne_one : x ≠ 1, { rw [ne.def, equiv.ext_iff], dec_trivial }, have key : x = z * (x * (y * x * y⁻¹) * x⁻¹ * (y * x * y⁻¹)⁻¹) * z⁻¹, { ext a, dec_trivial! }, refine not_solvable_of_mem_derived_series x_ne_one (λ n, _), induction n with n ih, { exact mem_top x }, { rw key, exact (derived_series_normal _ _).conj_mem _ (general_commutator_containment _ _ ih ((derived_series_normal _ _).conj_mem _ ih _)) _ }, end lemma equiv.perm.not_solvable (X : Type*) (hX : 5 ≤ cardinal.mk X) : ¬ is_solvable (equiv.perm X) := begin introI h, have key : nonempty (fin 5 ↪ X), { rwa [←cardinal.lift_mk_le, cardinal.mk_fin, cardinal.lift_nat_cast, nat.cast_bit1, nat.cast_bit0, nat.cast_one, cardinal.lift_id] }, exact equiv.perm.fin_5_not_solvable (solvable_of_solvable_injective (equiv.perm.via_embedding_hom_injective (nonempty.some key))), end end perm_not_solvable
58ded144bdf657182e6c94f7dcb707c16c4346c5
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/src/Lean/Message.lean
0c9ae5a452cbe8886a38405da7b7aa888b2d2131
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach" ]
permissive
leanprover/lean4
4bdf9790294964627eb9be79f5e8f6157780b4cc
f1f9dc0f2f531af3312398999d8b8303fa5f096b
refs/heads/master
1,693,360,665,786
1,693,350,868,000
1,693,350,868,000
129,571,436
2,827
311
Apache-2.0
1,694,716,156,000
1,523,760,560,000
Lean
UTF-8
Lean
false
false
16,664
lean
/- Copyright (c) 2018 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Sebastian Ullrich, Leonardo de Moura Message type used by the Lean frontend -/ import Lean.Data.Position import Lean.Data.OpenDecl import Lean.MetavarContext import Lean.Environment import Lean.Util.PPExt import Lean.Util.Sorry namespace Lean def mkErrorStringWithPos (fileName : String) (pos : Position) (msg : String) (endPos : Option Position := none) : String := let endPos := match endPos with | some endPos => s!"-{endPos.line}:{endPos.column}" | none => "" s!"{fileName}:{pos.line}:{pos.column}{endPos}: {msg}" inductive MessageSeverity where | information | warning | error deriving Inhabited, BEq structure MessageDataContext where env : Environment mctx : MetavarContext lctx : LocalContext opts : Options /-- A naming context is the information needed to shorten names in pretty printing. It gives the current namespace and the list of open declarations. -/ structure NamingContext where currNamespace : Name openDecls : List OpenDecl /-- Lazily formatted text to be used in `MessageData`. -/ structure PPFormat where /-- Pretty-prints text using surrounding context, if any. -/ pp : Option PPContext → IO FormatWithInfos /-- Searches for synthetic sorries in original input. Used to filter out certain messages. -/ hasSyntheticSorry : MetavarContext → Bool := fun _ => false /-- Structured message data. We use it for reporting errors, trace messages, etc. -/ inductive MessageData where /-- Eagerly formatted text. We inspect this in various hacks, so it is not immediately subsumed by `ofPPFormat`. -/ | ofFormat : Format → MessageData /-- Lazily formatted text. -/ | ofPPFormat : PPFormat → MessageData | ofGoal : MVarId → MessageData /-- `withContext ctx d` specifies the pretty printing context `(env, mctx, lctx, opts)` for the nested expressions in `d`. -/ | withContext : MessageDataContext → MessageData → MessageData | withNamingContext : NamingContext → MessageData → MessageData /-- Lifted `Format.nest` -/ | nest : Nat → MessageData → MessageData /-- Lifted `Format.group` -/ | group : MessageData → MessageData /-- Lifted `Format.compose` -/ | compose : MessageData → MessageData → MessageData /-- Tagged sections. `Name` should be viewed as a "kind", and is used by `MessageData` inspector functions. Example: an inspector that tries to find "definitional equality failures" may look for the tag "DefEqFailure". -/ | tagged : Name → MessageData → MessageData | trace (cls : Name) (msg : MessageData) (children : Array MessageData) (collapsed : Bool := false) deriving Inhabited namespace MessageData /-- Determines whether the message contains any content. -/ def isEmpty : MessageData → Bool | ofFormat f => f.isEmpty | withContext _ m => m.isEmpty | withNamingContext _ m => m.isEmpty | nest _ m => m.isEmpty | group m => m.isEmpty | compose m₁ m₂ => m₁.isEmpty && m₂.isEmpty | tagged _ m => m.isEmpty | _ => false variable (p : Name → Bool) in /-- Returns true when the message contains a `MessageData.tagged tag ..` constructor where `p tag` is true. -/ partial def hasTag : MessageData → Bool | withContext _ msg => hasTag msg | withNamingContext _ msg => hasTag msg | nest _ msg => hasTag msg | group msg => hasTag msg | compose msg₁ msg₂ => hasTag msg₁ || hasTag msg₂ | tagged n msg => p n || hasTag msg | trace cls msg msgs _ => p cls || hasTag msg || msgs.any hasTag | _ => false /-- An empty message. -/ def nil : MessageData := ofFormat Format.nil def mkPPContext (nCtx : NamingContext) (ctx : MessageDataContext) : PPContext := { env := ctx.env, mctx := ctx.mctx, lctx := ctx.lctx, opts := ctx.opts, currNamespace := nCtx.currNamespace, openDecls := nCtx.openDecls } def ofSyntax (stx : Syntax) : MessageData := -- discard leading/trailing whitespace let stx := stx.copyHeadTailInfoFrom .missing .ofPPFormat { pp := fun | some ctx => ppTerm ctx ⟨stx⟩ -- HACK: might not be a term | none => return stx.formatStx } def ofExpr (e : Expr) : MessageData := .ofPPFormat { pp := fun | some ctx => ppExprWithInfos ctx e | none => return format (toString e) hasSyntheticSorry := (instantiateMVarsCore · e |>.1.hasSyntheticSorry) } def ofLevel (l : Level) : MessageData := ofFormat (format l) def ofName (n : Name) : MessageData := ofFormat (format n) partial def hasSyntheticSorry (msg : MessageData) : Bool := visit none msg where visit (mctx? : Option MetavarContext) : MessageData → Bool | ofPPFormat f => f.hasSyntheticSorry (mctx?.getD {}) | withContext ctx msg => visit ctx.mctx msg | withNamingContext _ msg => visit mctx? msg | nest _ msg => visit mctx? msg | group msg => visit mctx? msg | compose msg₁ msg₂ => visit mctx? msg₁ || visit mctx? msg₂ | tagged _ msg => visit mctx? msg | trace _ msg msgs _ => visit mctx? msg || msgs.any (visit mctx?) | _ => false partial def formatAux : NamingContext → Option MessageDataContext → MessageData → IO Format | _, _, ofFormat fmt => return fmt | nCtx, ctx?, ofPPFormat f => (·.fmt) <$> f.pp (ctx?.map (mkPPContext nCtx)) | _, none, ofGoal mvarId => return "goal " ++ format (mkMVar mvarId) | nCtx, some ctx, ofGoal mvarId => ppGoal (mkPPContext nCtx ctx) mvarId | nCtx, _, withContext ctx d => formatAux nCtx ctx d | _, ctx, withNamingContext nCtx d => formatAux nCtx ctx d | nCtx, ctx, tagged _ d => formatAux nCtx ctx d | nCtx, ctx, nest n d => Format.nest n <$> formatAux nCtx ctx d | nCtx, ctx, compose d₁ d₂ => return (← formatAux nCtx ctx d₁) ++ (← formatAux nCtx ctx d₂) | nCtx, ctx, group d => Format.group <$> formatAux nCtx ctx d | nCtx, ctx, trace cls header children _ => do let msg := f!"[{cls}] {(← formatAux nCtx ctx header).nest 2}" let children ← children.mapM (formatAux nCtx ctx) return .nest 2 (.joinSep (msg::children.toList) "\n") protected def format (msgData : MessageData) : IO Format := formatAux { currNamespace := Name.anonymous, openDecls := [] } none msgData protected def toString (msgData : MessageData) : IO String := do return toString (← msgData.format) instance : Append MessageData := ⟨compose⟩ instance : Coe String MessageData := ⟨ofFormat ∘ format⟩ instance : Coe Format MessageData := ⟨ofFormat⟩ instance : Coe Level MessageData := ⟨ofLevel⟩ instance : Coe Expr MessageData := ⟨ofExpr⟩ instance : Coe Name MessageData := ⟨ofName⟩ instance : Coe Syntax MessageData := ⟨ofSyntax⟩ instance : Coe MVarId MessageData := ⟨ofGoal⟩ instance : Coe (Option Expr) MessageData := ⟨fun o => match o with | none => "none" | some e => ofExpr e⟩ partial def arrayExpr.toMessageData (es : Array Expr) (i : Nat) (acc : MessageData) : MessageData := if h : i < es.size then let e := es.get ⟨i, h⟩; let acc := if i == 0 then acc ++ ofExpr e else acc ++ ", " ++ ofExpr e; toMessageData es (i+1) acc else acc ++ "]" instance : Coe (Array Expr) MessageData := ⟨fun es => arrayExpr.toMessageData es 0 "#["⟩ /-- Wrap the given message in `l` and `r`. See also `Format.bracket`. -/ def bracket (l : String) (f : MessageData) (r : String) : MessageData := group (nest l.length <| l ++ f ++ r) /-- Wrap the given message in parentheses `()`. -/ def paren (f : MessageData) : MessageData := bracket "(" f ")" /-- Wrap the given message in square brackets `[]`. -/ def sbracket (f : MessageData) : MessageData := bracket "[" f "]" /-- Append the given list of messages with the given separarator. -/ def joinSep : List MessageData → MessageData → MessageData | [], _ => Format.nil | [a], _ => a | a::as, sep => a ++ sep ++ joinSep as sep /-- Write the given list of messages as a list, separating each item with `,\n` and surrounding with square brackets. -/ def ofList : List MessageData → MessageData | [] => "[]" | xs => sbracket <| joinSep xs (ofFormat "," ++ Format.line) /-- See `MessageData.ofList`. -/ def ofArray (msgs : Array MessageData) : MessageData := ofList msgs.toList instance : Coe (List MessageData) MessageData := ⟨ofList⟩ instance : Coe (List Expr) MessageData := ⟨fun es => ofList <| es.map ofExpr⟩ end MessageData /-- A `Message` is a richly formatted piece of information emitted by Lean. They are rendered by client editors in the infoview and in diagnostic windows. -/ structure Message where fileName : String pos : Position endPos : Option Position := none severity : MessageSeverity := MessageSeverity.error caption : String := "" /-- The content of the message. -/ data : MessageData deriving Inhabited namespace Message protected def toString (msg : Message) (includeEndPos := false) : IO String := do let mut str ← msg.data.toString let endPos := if includeEndPos then msg.endPos else none unless msg.caption == "" do str := msg.caption ++ ":\n" ++ str match msg.severity with | MessageSeverity.information => pure () | MessageSeverity.warning => str := mkErrorStringWithPos msg.fileName msg.pos (endPos := endPos) "warning: " ++ str | MessageSeverity.error => str := mkErrorStringWithPos msg.fileName msg.pos (endPos := endPos) "error: " ++ str if str.isEmpty || str.back != '\n' then str := str ++ "\n" return str end Message /-- A persistent array of messages. -/ structure MessageLog where msgs : PersistentArray Message := {} deriving Inhabited namespace MessageLog def empty : MessageLog := ⟨{}⟩ def isEmpty (log : MessageLog) : Bool := log.msgs.isEmpty def add (msg : Message) (log : MessageLog) : MessageLog := ⟨log.msgs.push msg⟩ protected def append (l₁ l₂ : MessageLog) : MessageLog := ⟨l₁.msgs ++ l₂.msgs⟩ instance : Append MessageLog := ⟨MessageLog.append⟩ def hasErrors (log : MessageLog) : Bool := log.msgs.any fun m => match m.severity with | MessageSeverity.error => true | _ => false def errorsToWarnings (log : MessageLog) : MessageLog := { msgs := log.msgs.map (fun m => match m.severity with | MessageSeverity.error => { m with severity := MessageSeverity.warning } | _ => m) } def getInfoMessages (log : MessageLog) : MessageLog := { msgs := log.msgs.filter fun m => match m.severity with | MessageSeverity.information => true | _ => false } def forM {m : Type → Type} [Monad m] (log : MessageLog) (f : Message → m Unit) : m Unit := log.msgs.forM f def toList (log : MessageLog) : List Message := (log.msgs.foldl (fun acc msg => msg :: acc) []).reverse end MessageLog def MessageData.nestD (msg : MessageData) : MessageData := MessageData.nest 2 msg def indentD (msg : MessageData) : MessageData := MessageData.nestD (Format.line ++ msg) def indentExpr (e : Expr) : MessageData := indentD e class AddMessageContext (m : Type → Type) where addMessageContext : MessageData → m MessageData export AddMessageContext (addMessageContext) instance (m n) [MonadLift m n] [AddMessageContext m] : AddMessageContext n where addMessageContext := fun msg => liftM (addMessageContext msg : m _) def addMessageContextPartial {m} [Monad m] [MonadEnv m] [MonadOptions m] (msgData : MessageData) : m MessageData := do let env ← getEnv let opts ← getOptions return MessageData.withContext { env := env, mctx := {}, lctx := {}, opts := opts } msgData def addMessageContextFull {m} [Monad m] [MonadEnv m] [MonadMCtx m] [MonadLCtx m] [MonadOptions m] (msgData : MessageData) : m MessageData := do let env ← getEnv let mctx ← getMCtx let lctx ← getLCtx let opts ← getOptions return MessageData.withContext { env := env, mctx := mctx, lctx := lctx, opts := opts } msgData class ToMessageData (α : Type) where toMessageData : α → MessageData export ToMessageData (toMessageData) def stringToMessageData (str : String) : MessageData := let lines := str.split (· == '\n') let lines := lines.map (MessageData.ofFormat ∘ format) MessageData.joinSep lines (MessageData.ofFormat Format.line) instance [ToFormat α] : ToMessageData α := ⟨MessageData.ofFormat ∘ format⟩ instance : ToMessageData Expr := ⟨MessageData.ofExpr⟩ instance : ToMessageData Level := ⟨MessageData.ofLevel⟩ instance : ToMessageData Name := ⟨MessageData.ofName⟩ instance : ToMessageData String := ⟨stringToMessageData⟩ instance : ToMessageData Syntax := ⟨MessageData.ofSyntax⟩ instance : ToMessageData (TSyntax k) := ⟨(MessageData.ofSyntax ·)⟩ instance : ToMessageData Format := ⟨MessageData.ofFormat⟩ instance : ToMessageData MVarId := ⟨MessageData.ofGoal⟩ instance : ToMessageData MessageData := ⟨id⟩ instance [ToMessageData α] : ToMessageData (List α) := ⟨fun as => MessageData.ofList <| as.map toMessageData⟩ instance [ToMessageData α] : ToMessageData (Array α) := ⟨fun as => toMessageData as.toList⟩ instance [ToMessageData α] : ToMessageData (Subarray α) := ⟨fun as => toMessageData as.toArray.toList⟩ instance [ToMessageData α] : ToMessageData (Option α) := ⟨fun | none => "none" | some e => "some (" ++ toMessageData e ++ ")"⟩ instance : ToMessageData (Option Expr) := ⟨fun | none => "<not-available>" | some e => toMessageData e⟩ syntax:max "m!" interpolatedStr(term) : term macro_rules | `(m! $interpStr) => do interpStr.expandInterpolatedStr (← `(MessageData)) (← `(toMessageData)) def toMessageList (msgs : Array MessageData) : MessageData := indentD (MessageData.joinSep msgs.toList m!"\n\n") namespace KernelException private def mkCtx (env : Environment) (lctx : LocalContext) (opts : Options) (msg : MessageData) : MessageData := MessageData.withContext { env := env, mctx := {}, lctx := lctx, opts := opts } msg def toMessageData (e : KernelException) (opts : Options) : MessageData := match e with | unknownConstant env constName => mkCtx env {} opts m!"(kernel) unknown constant '{constName}'" | alreadyDeclared env constName => mkCtx env {} opts m!"(kernel) constant has already been declared '{constName}'" | declTypeMismatch env decl givenType => mkCtx env {} opts <| let process (n : Name) (expectedType : Expr) : MessageData := m!"(kernel) declaration type mismatch, '{n}' has type{indentExpr givenType}\nbut it is expected to have type{indentExpr expectedType}"; match decl with | Declaration.defnDecl { name := n, type := type, .. } => process n type | Declaration.thmDecl { name := n, type := type, .. } => process n type | _ => "(kernel) declaration type mismatch" -- TODO fix type checker, type mismatch for mutual decls does not have enough information | declHasMVars env constName _ => mkCtx env {} opts m!"(kernel) declaration has metavariables '{constName}'" | declHasFVars env constName _ => mkCtx env {} opts m!"(kernel) declaration has free variables '{constName}'" | funExpected env lctx e => mkCtx env lctx opts m!"(kernel) function expected{indentExpr e}" | typeExpected env lctx e => mkCtx env lctx opts m!"(kernel) type expected{indentExpr e}" | letTypeMismatch env lctx n _ _ => mkCtx env lctx opts m!"(kernel) let-declaration type mismatch '{n}'" | exprTypeMismatch env lctx e _ => mkCtx env lctx opts m!"(kernel) type mismatch at{indentExpr e}" | appTypeMismatch env lctx e fnType argType => mkCtx env lctx opts m!"application type mismatch{indentExpr e}\nargument has type{indentExpr argType}\nbut function has type{indentExpr fnType}" | invalidProj env lctx e => mkCtx env lctx opts m!"(kernel) invalid projection{indentExpr e}" | other msg => m!"(kernel) {msg}" | deterministicTimeout => "(kernel) deterministic timeout" | excessiveMemory => "(kernel) excessive memory consumption detected" | deepRecursion => "(kernel) deep recursion detected" end KernelException end Lean
ebbed72e5319e37e22ebc7810057511ddf3f08a9
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/group_theory/group_action/conj_act.lean
6c216817766fe84483d59fe0e4b2b64695443a8f
[ "Apache-2.0" ]
permissive
alreadydone/mathlib
dc0be621c6c8208c581f5170a8216c5ba6721927
c982179ec21091d3e102d8a5d9f5fe06c8fafb73
refs/heads/master
1,685,523,275,196
1,670,184,141,000
1,670,184,141,000
287,574,545
0
0
Apache-2.0
1,670,290,714,000
1,597,421,623,000
Lean
UTF-8
Lean
false
false
9,251
lean
/- Copyright (c) 2021 . All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import group_theory.group_action.basic import group_theory.subgroup.basic import algebra.group_ring_action.basic /-! # Conjugation action of a group on itself This file defines the conjugation action of a group on itself. See also `mul_aut.conj` for the definition of conjugation as a homomorphism into the automorphism group. ## Main definitions A type alias `conj_act G` is introduced for a group `G`. The group `conj_act G` acts on `G` by conjugation. The group `conj_act G` also acts on any normal subgroup of `G` by conjugation. As a generalization, this also allows: * `conj_act Mˣ` to act on `M`, when `M` is a `monoid` * `conj_act G₀` to act on `G₀`, when `G₀` is a `group_with_zero` ## Implementation Notes The scalar action in defined in this file can also be written using `mul_aut.conj g • h`. This has the advantage of not using the type alias `conj_act`, but the downside of this approach is that some theorems about the group actions will not apply when since this `mul_aut.conj g • h` describes an action of `mul_aut G` on `G`, and not an action of `G`. -/ variables (α M G G₀ R K : Type*) /-- A type alias for a group `G`. `conj_act G` acts on `G` by conjugation -/ def conj_act : Type* := G namespace conj_act open mul_action subgroup variables {M G G₀ R K} instance : Π [group G], group (conj_act G) := id instance : Π [div_inv_monoid G], div_inv_monoid (conj_act G) := id instance : Π [group_with_zero G], group_with_zero (conj_act G) := id instance : Π [fintype G], fintype (conj_act G) := id @[simp] lemma card [fintype G] : fintype.card (conj_act G) = fintype.card G := rfl section div_inv_monoid variable [div_inv_monoid G] instance : inhabited (conj_act G) := ⟨1⟩ /-- Reinterpret `g : conj_act G` as an element of `G`. -/ def of_conj_act : conj_act G ≃* G := ⟨id, id, λ _, rfl, λ _, rfl, λ _ _, rfl⟩ /-- Reinterpret `g : G` as an element of `conj_act G`. -/ def to_conj_act : G ≃* conj_act G := of_conj_act.symm /-- A recursor for `conj_act`, for use as `induction x using conj_act.rec` when `x : conj_act G`. -/ protected def rec {C : conj_act G → Sort*} (h : Π g, C (to_conj_act g)) : Π g, C g := h @[simp] lemma «forall» (p : conj_act G → Prop) : (∀ (x : conj_act G), p x) ↔ ∀ x : G, p (to_conj_act x) := iff.rfl @[simp] lemma of_mul_symm_eq : (@of_conj_act G _).symm = to_conj_act := rfl @[simp] lemma to_mul_symm_eq : (@to_conj_act G _).symm = of_conj_act := rfl @[simp] lemma to_conj_act_of_conj_act (x : conj_act G) : to_conj_act (of_conj_act x) = x := rfl @[simp] lemma of_conj_act_to_conj_act (x : G) : of_conj_act (to_conj_act x) = x := rfl @[simp] lemma of_conj_act_one : of_conj_act (1 : conj_act G) = 1 := rfl @[simp] lemma to_conj_act_one : to_conj_act (1 : G) = 1 := rfl @[simp] lemma of_conj_act_inv (x : conj_act G) : of_conj_act (x⁻¹) = (of_conj_act x)⁻¹ := rfl @[simp] lemma to_conj_act_inv (x : G) : to_conj_act (x⁻¹) = (to_conj_act x)⁻¹ := rfl @[simp] lemma of_conj_act_mul (x y : conj_act G) : of_conj_act (x * y) = of_conj_act x * of_conj_act y := rfl @[simp] lemma to_conj_act_mul (x y : G) : to_conj_act (x * y) = to_conj_act x * to_conj_act y := rfl instance : has_smul (conj_act G) G := { smul := λ g h, of_conj_act g * h * (of_conj_act g)⁻¹ } lemma smul_def (g : conj_act G) (h : G) : g • h = of_conj_act g * h * (of_conj_act g)⁻¹ := rfl end div_inv_monoid section units section monoid variables [monoid M] instance has_units_scalar : has_smul (conj_act Mˣ) M := { smul := λ g h, of_conj_act g * h * ↑(of_conj_act g)⁻¹ } lemma units_smul_def (g : conj_act Mˣ) (h : M) : g • h = of_conj_act g * h * ↑(of_conj_act g)⁻¹ := rfl instance units_mul_distrib_mul_action : mul_distrib_mul_action (conj_act Mˣ) M := { smul := (•), one_smul := by simp [units_smul_def], mul_smul := by simp [units_smul_def, mul_assoc, mul_inv_rev], smul_mul := by simp [units_smul_def, mul_assoc], smul_one := by simp [units_smul_def], } instance units_smul_comm_class [has_smul α M] [smul_comm_class α M M] [is_scalar_tower α M M] : smul_comm_class α (conj_act Mˣ) M := { smul_comm := λ a um m, by rw [units_smul_def, units_smul_def, mul_smul_comm, smul_mul_assoc] } instance units_smul_comm_class' [has_smul α M] [smul_comm_class M α M] [is_scalar_tower α M M] : smul_comm_class (conj_act Mˣ) α M := by { haveI : smul_comm_class α M M := smul_comm_class.symm _ _ _, exact smul_comm_class.symm _ _ _ } end monoid section semiring variables [semiring R] instance units_mul_semiring_action : mul_semiring_action (conj_act Rˣ) R := { smul := (•), smul_zero := by simp [units_smul_def], smul_add := by simp [units_smul_def, mul_add, add_mul], ..conj_act.units_mul_distrib_mul_action} end semiring end units section group_with_zero variable [group_with_zero G₀] @[simp] lemma of_conj_act_zero : of_conj_act (0 : conj_act G₀) = 0 := rfl @[simp] lemma to_conj_act_zero : to_conj_act (0 : G₀) = 0 := rfl instance mul_action₀ : mul_action (conj_act G₀) G₀ := { smul := (•), one_smul := by simp [smul_def], mul_smul := by simp [smul_def, mul_assoc, mul_inv_rev] } instance smul_comm_class₀ [has_smul α G₀] [smul_comm_class α G₀ G₀] [is_scalar_tower α G₀ G₀] : smul_comm_class α (conj_act G₀) G₀ := { smul_comm := λ a ug g, by rw [smul_def, smul_def, mul_smul_comm, smul_mul_assoc] } instance smul_comm_class₀' [has_smul α G₀] [smul_comm_class G₀ α G₀] [is_scalar_tower α G₀ G₀] : smul_comm_class (conj_act G₀) α G₀ := by { haveI := smul_comm_class.symm G₀ α G₀, exact smul_comm_class.symm _ _ _ } end group_with_zero section division_ring variables [division_ring K] instance distrib_mul_action₀ : distrib_mul_action (conj_act K) K := { smul := (•), smul_zero := by simp [smul_def], smul_add := by simp [smul_def, mul_add, add_mul], ..conj_act.mul_action₀ } end division_ring variables [group G] instance : mul_distrib_mul_action (conj_act G) G := { smul := (•), smul_mul := by simp [smul_def, mul_assoc], smul_one := by simp [smul_def], one_smul := by simp [smul_def], mul_smul := by simp [smul_def, mul_assoc] } instance smul_comm_class [has_smul α G] [smul_comm_class α G G] [is_scalar_tower α G G] : smul_comm_class α (conj_act G) G := { smul_comm := λ a ug g, by rw [smul_def, smul_def, mul_smul_comm, smul_mul_assoc] } instance smul_comm_class' [has_smul α G] [smul_comm_class G α G] [is_scalar_tower α G G] : smul_comm_class (conj_act G) α G := by { haveI := smul_comm_class.symm G α G, exact smul_comm_class.symm _ _ _ } lemma smul_eq_mul_aut_conj (g : conj_act G) (h : G) : g • h = mul_aut.conj (of_conj_act g) h := rfl /-- The set of fixed points of the conjugation action of `G` on itself is the center of `G`. -/ lemma fixed_points_eq_center : fixed_points (conj_act G) G = center G := begin ext x, simp [mem_center_iff, smul_def, mul_inv_eq_iff_eq_mul] end lemma stabilizer_eq_centralizer (g : G) : stabilizer (conj_act G) g = (zpowers g).centralizer := le_antisymm (le_centralizer_iff.mp (zpowers_le.mpr (λ x, mul_inv_eq_iff_eq_mul.mp))) (λ x h, mul_inv_eq_of_eq_mul (h g (mem_zpowers g)).symm) /-- As normal subgroups are closed under conjugation, they inherit the conjugation action of the underlying group. -/ instance subgroup.conj_action {H : subgroup G} [hH : H.normal] : has_smul (conj_act G) H := ⟨λ g h, ⟨g • h, hH.conj_mem h.1 h.2 (of_conj_act g)⟩⟩ lemma subgroup.coe_conj_smul {H : subgroup G} [hH : H.normal] (g : conj_act G) (h : H) : ↑(g • h) = g • (h : G) := rfl instance subgroup.conj_mul_distrib_mul_action {H : subgroup G} [hH : H.normal] : mul_distrib_mul_action (conj_act G) H := (subtype.coe_injective).mul_distrib_mul_action H.subtype subgroup.coe_conj_smul /-- Group conjugation on a normal subgroup. Analogous to `mul_aut.conj`. -/ def _root_.mul_aut.conj_normal {H : subgroup G} [hH : H.normal] : G →* mul_aut H := (mul_distrib_mul_action.to_mul_aut (conj_act G) H).comp to_conj_act.to_monoid_hom @[simp] lemma _root_.mul_aut.conj_normal_apply {H : subgroup G} [H.normal] (g : G) (h : H) : ↑(mul_aut.conj_normal g h) = g * h * g⁻¹ := rfl @[simp] lemma _root_.mul_aut.conj_normal_symm_apply {H : subgroup G} [H.normal] (g : G) (h : H) : ↑((mul_aut.conj_normal g).symm h) = g⁻¹ * h * g := by { change _ * (_)⁻¹⁻¹ = _, rw inv_inv, refl } @[simp] lemma _root_.mul_aut.conj_normal_inv_apply {H : subgroup G} [H.normal] (g : G) (h : H) : ↑((mul_aut.conj_normal g)⁻¹ h) = g⁻¹ * h * g := mul_aut.conj_normal_symm_apply g h lemma _root_.mul_aut.conj_normal_coe {H : subgroup G} [H.normal] {h : H} : mul_aut.conj_normal ↑h = mul_aut.conj h := mul_equiv.ext (λ x, rfl) instance normal_of_characteristic_of_normal {H : subgroup G} [hH : H.normal] {K : subgroup H} [h : K.characteristic] : (K.map H.subtype).normal := ⟨λ a ha b, by { obtain ⟨a, ha, rfl⟩ := ha, exact K.apply_coe_mem_map H.subtype ⟨_, ((set_like.ext_iff.mp (h.fixed (mul_aut.conj_normal b)) a).mpr ha)⟩ }⟩ end conj_act
bc02c7f4cb335e9c3a7788f174acc1e2aa4e7c7d
6065973b1fa7bbacba932011c9e2f32bf7bdd6c1
/src/analysis/normed_space/operator_norm.lean
799e1057c40d2e7fba884906931475c30c1fb87b
[ "Apache-2.0" ]
permissive
khmacdonald/mathlib
90a0fa2222369fa69ed2fbfb841b74d2bdfd66cb
3669cb35c578441812ad30fd967d21a94b6f387e
refs/heads/master
1,675,863,801,090
1,609,761,876,000
1,609,761,876,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
44,284
lean
/- Copyright (c) 2019 Jan-David Salchow. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jan-David Salchow, Sébastien Gouëzel, Jean Lo -/ import linear_algebra.finite_dimensional import analysis.normed_space.riesz_lemma import analysis.asymptotics /-! # Operator norm on the space of continuous linear maps Define the operator norm on the space of continuous linear maps between normed spaces, and prove its basic properties. In particular, show that this space is itself a normed space. -/ noncomputable theory open_locale classical nnreal variables {𝕜 : Type*} {E : Type*} {F : Type*} {G : Type*} [normed_group E] [normed_group F] [normed_group G] open metric continuous_linear_map lemma exists_pos_bound_of_bound {f : E → F} (M : ℝ) (h : ∀x, ∥f x∥ ≤ M * ∥x∥) : ∃ N, 0 < N ∧ ∀x, ∥f x∥ ≤ N * ∥x∥ := ⟨max M 1, lt_of_lt_of_le zero_lt_one (le_max_right _ _), λx, calc ∥f x∥ ≤ M * ∥x∥ : h x ... ≤ max M 1 * ∥x∥ : mul_le_mul_of_nonneg_right (le_max_left _ _) (norm_nonneg _) ⟩ section normed_field /- Most statements in this file require the field to be non-discrete, as this is necessary to deduce an inequality `∥f x∥ ≤ C ∥x∥` from the continuity of f. However, the other direction always holds. In this section, we just assume that `𝕜` is a normed field. In the remainder of the file, it will be non-discrete. -/ variables [normed_field 𝕜] [normed_space 𝕜 E] [normed_space 𝕜 F] (f : E →ₗ[𝕜] F) lemma linear_map.lipschitz_of_bound (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) : lipschitz_with (nnreal.of_real C) f := lipschitz_with.of_dist_le' $ λ x y, by simpa only [dist_eq_norm, f.map_sub] using h (x - y) theorem linear_map.antilipschitz_of_bound {K : ℝ≥0} (h : ∀ x, ∥x∥ ≤ K * ∥f x∥) : antilipschitz_with K f := antilipschitz_with.of_le_mul_dist $ λ x y, by simpa only [dist_eq_norm, f.map_sub] using h (x - y) lemma linear_map.bound_of_antilipschitz {K : ℝ≥0} (h : antilipschitz_with K f) (x) : ∥x∥ ≤ K * ∥f x∥ := by simpa only [dist_zero_right, f.map_zero] using h.le_mul_dist x 0 lemma linear_map.uniform_continuous_of_bound (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) : uniform_continuous f := (f.lipschitz_of_bound C h).uniform_continuous lemma linear_map.continuous_of_bound (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) : continuous f := (f.lipschitz_of_bound C h).continuous /-- Construct a continuous linear map from a linear map and a bound on this linear map. The fact that the norm of the continuous linear map is then controlled is given in `linear_map.mk_continuous_norm_le`. -/ def linear_map.mk_continuous (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) : E →L[𝕜] F := ⟨f, linear_map.continuous_of_bound f C h⟩ /-- Reinterpret a linear map `𝕜 →ₗ[𝕜] E` as a continuous linear map. This construction is generalized to the case of any finite dimensional domain in `linear_map.to_continuous_linear_map`. -/ def linear_map.to_continuous_linear_map₁ (f : 𝕜 →ₗ[𝕜] E) : 𝕜 →L[𝕜] E := f.mk_continuous (∥f 1∥) $ λ x, le_of_eq $ by { conv_lhs { rw ← mul_one x }, rw [← smul_eq_mul, f.map_smul, norm_smul, mul_comm] } /-- Construct a continuous linear map from a linear map and the existence of a bound on this linear map. If you have an explicit bound, use `linear_map.mk_continuous` instead, as a norm estimate will follow automatically in `linear_map.mk_continuous_norm_le`. -/ def linear_map.mk_continuous_of_exists_bound (h : ∃C, ∀x, ∥f x∥ ≤ C * ∥x∥) : E →L[𝕜] F := ⟨f, let ⟨C, hC⟩ := h in linear_map.continuous_of_bound f C hC⟩ lemma continuous_of_linear_of_bound {f : E → F} (h_add : ∀ x y, f (x + y) = f x + f y) (h_smul : ∀ (c : 𝕜) x, f (c • x) = c • f x) {C : ℝ} (h_bound : ∀ x, ∥f x∥ ≤ C*∥x∥) : continuous f := let φ : E →ₗ[𝕜] F := ⟨f, h_add, h_smul⟩ in φ.continuous_of_bound C h_bound @[simp, norm_cast] lemma linear_map.mk_continuous_coe (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) : ((f.mk_continuous C h) : E →ₗ[𝕜] F) = f := rfl @[simp] lemma linear_map.mk_continuous_apply (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) (x : E) : f.mk_continuous C h x = f x := rfl @[simp, norm_cast] lemma linear_map.mk_continuous_of_exists_bound_coe (h : ∃C, ∀x, ∥f x∥ ≤ C * ∥x∥) : ((f.mk_continuous_of_exists_bound h) : E →ₗ[𝕜] F) = f := rfl @[simp] lemma linear_map.mk_continuous_of_exists_bound_apply (h : ∃C, ∀x, ∥f x∥ ≤ C * ∥x∥) (x : E) : f.mk_continuous_of_exists_bound h x = f x := rfl @[simp] lemma linear_map.to_continuous_linear_map₁_coe (f : 𝕜 →ₗ[𝕜] E) : (f.to_continuous_linear_map₁ : 𝕜 →ₗ[𝕜] E) = f := rfl @[simp] lemma linear_map.to_continuous_linear_map₁_apply (f : 𝕜 →ₗ[𝕜] E) (x) : f.to_continuous_linear_map₁ x = f x := rfl lemma linear_map.continuous_iff_is_closed_ker {f : E →ₗ[𝕜] 𝕜} : continuous f ↔ is_closed (f.ker : set E) := begin -- the continuity of f obviously implies that its kernel is closed refine ⟨λh, (continuous_iff_is_closed.1 h) {0} (t1_space.t1 0), λh, _⟩, -- for the other direction, we assume that the kernel is closed by_cases hf : ∀x, x ∈ f.ker, { -- if `f = 0`, its continuity is obvious have : (f : E → 𝕜) = (λx, 0), by { ext x, simpa using hf x }, rw this, exact continuous_const }, { /- if `f` is not zero, we use an element `x₀ ∉ ker f` such that `∥x₀∥ ≤ 2 ∥x₀ - y∥` for all `y ∈ ker f`, given by Riesz's lemma, and prove that `2 ∥f x₀∥ / ∥x₀∥` gives a bound on the operator norm of `f`. For this, start from an arbitrary `x` and note that `y = x₀ - (f x₀ / f x) x` belongs to the kernel of `f`. Applying the above inequality to `x₀` and `y` readily gives the conclusion. -/ push_neg at hf, let r : ℝ := (2 : ℝ)⁻¹, have : 0 ≤ r, by norm_num [r], have : r < 1, by norm_num [r], obtain ⟨x₀, x₀ker, h₀⟩ : ∃ (x₀ : E), x₀ ∉ f.ker ∧ ∀ y ∈ linear_map.ker f, r * ∥x₀∥ ≤ ∥x₀ - y∥, from riesz_lemma h hf this, have : x₀ ≠ 0, { assume h, have : x₀ ∈ f.ker, by { rw h, exact (linear_map.ker f).zero_mem }, exact x₀ker this }, have rx₀_ne_zero : r * ∥x₀∥ ≠ 0, by { simp [norm_eq_zero, this], norm_num }, have : ∀x, ∥f x∥ ≤ (((r * ∥x₀∥)⁻¹) * ∥f x₀∥) * ∥x∥, { assume x, by_cases hx : f x = 0, { rw [hx, norm_zero], apply_rules [mul_nonneg, norm_nonneg, inv_nonneg.2] }, { let y := x₀ - (f x₀ * (f x)⁻¹ ) • x, have fy_zero : f y = 0, by calc f y = f x₀ - (f x₀ * (f x)⁻¹ ) * f x : by simp [y] ... = 0 : by { rw [mul_assoc, inv_mul_cancel hx, mul_one, sub_eq_zero_of_eq], refl }, have A : r * ∥x₀∥ ≤ ∥f x₀∥ * ∥f x∥⁻¹ * ∥x∥, from calc r * ∥x₀∥ ≤ ∥x₀ - y∥ : h₀ _ (linear_map.mem_ker.2 fy_zero) ... = ∥(f x₀ * (f x)⁻¹ ) • x∥ : by { dsimp [y], congr, abel } ... = ∥f x₀∥ * ∥f x∥⁻¹ * ∥x∥ : by rw [norm_smul, normed_field.norm_mul, normed_field.norm_inv], calc ∥f x∥ = (r * ∥x₀∥)⁻¹ * (r * ∥x₀∥) * ∥f x∥ : by rwa [inv_mul_cancel, one_mul] ... ≤ (r * ∥x₀∥)⁻¹ * (∥f x₀∥ * ∥f x∥⁻¹ * ∥x∥) * ∥f x∥ : begin apply mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left A _) (norm_nonneg _), exact inv_nonneg.2 (mul_nonneg (by norm_num) (norm_nonneg _)) end ... = (∥f x∥ ⁻¹ * ∥f x∥) * (((r * ∥x₀∥)⁻¹) * ∥f x₀∥) * ∥x∥ : by ring ... = (((r * ∥x₀∥)⁻¹) * ∥f x₀∥) * ∥x∥ : by { rw [inv_mul_cancel, one_mul], simp [norm_eq_zero, hx] } } }, exact linear_map.continuous_of_bound f _ this } end end normed_field section add_monoid_hom lemma add_monoid_hom.isometry_of_norm (f : E →+ F) (hf : ∀ x, ∥f x∥ = ∥x∥) : isometry f := begin intros x y, simp_rw [edist_dist], congr', simp_rw [dist_eq_norm, ←add_monoid_hom.map_sub], exact hf (x - y), end end add_monoid_hom variables [nondiscrete_normed_field 𝕜] [normed_space 𝕜 E] [normed_space 𝕜 F] [normed_space 𝕜 G] (c : 𝕜) (f g : E →L[𝕜] F) (h : F →L[𝕜] G) (x y z : E) include 𝕜 lemma linear_map.bound_of_shell (f : E →ₗ[𝕜] F) {ε C : ℝ} (ε_pos : 0 < ε) {c : 𝕜} (hc : 1 < ∥c∥) (hf : ∀ x, ε / ∥c∥ ≤ ∥x∥ → ∥x∥ < ε → ∥f x∥ ≤ C * ∥x∥) (x : E) : ∥f x∥ ≤ C * ∥x∥ := begin by_cases hx : x = 0, { simp [hx] }, rcases rescale_to_shell hc ε_pos hx with ⟨δ, hδ, δxle, leδx, δinv⟩, simpa only [f.map_smul, norm_smul, mul_left_comm C, mul_le_mul_left (norm_pos_iff.2 hδ)] using hf (δ • x) leδx δxle end /-- A continuous linear map between normed spaces is bounded when the field is nondiscrete. The continuity ensures boundedness on a ball of some radius `ε`. The nondiscreteness is then used to rescale any element into an element of norm in `[ε/C, ε]`, whose image has a controlled norm. The norm control for the original element follows by rescaling. -/ lemma linear_map.bound_of_continuous (f : E →ₗ[𝕜] F) (hf : continuous f) : ∃ C, 0 < C ∧ (∀ x : E, ∥f x∥ ≤ C * ∥x∥) := begin have : continuous_at f 0 := continuous_iff_continuous_at.1 hf _, rcases (nhds_basis_closed_ball.tendsto_iff nhds_basis_closed_ball).1 this 1 zero_lt_one with ⟨ε, ε_pos, hε⟩, simp only [mem_closed_ball, dist_zero_right, f.map_zero] at hε, rcases normed_field.exists_one_lt_norm 𝕜 with ⟨c, hc⟩, refine ⟨ε⁻¹ * ∥c∥, mul_pos (inv_pos.2 ε_pos) (lt_trans zero_lt_one hc), _⟩, suffices : ∀ x, ε / ∥c∥ ≤ ∥x∥ → ∥x∥ < ε → ∥f x∥ ≤ ε⁻¹ * ∥c∥ * ∥x∥, from f.bound_of_shell ε_pos hc this, intros x hle hlt, refine (hε _ hlt.le).trans _, rwa [mul_assoc, ← div_le_iff' (inv_pos.2 ε_pos), div_eq_mul_inv, inv_inv', one_mul, ← div_le_iff' (zero_lt_one.trans hc)] end namespace continuous_linear_map theorem bound : ∃ C, 0 < C ∧ (∀ x : E, ∥f x∥ ≤ C * ∥x∥) := f.to_linear_map.bound_of_continuous f.2 section open asymptotics filter theorem is_O_id (l : filter E) : is_O f (λ x, x) l := let ⟨M, hMp, hM⟩ := f.bound in is_O_of_le' l hM theorem is_O_comp {α : Type*} (g : F →L[𝕜] G) (f : α → F) (l : filter α) : is_O (λ x', g (f x')) f l := (g.is_O_id ⊤).comp_tendsto le_top theorem is_O_sub (f : E →L[𝕜] F) (l : filter E) (x : E) : is_O (λ x', f (x' - x)) (λ x', x' - x) l := f.is_O_comp _ l /-- A linear map which is a homothety is a continuous linear map. Since the field `𝕜` need not have `ℝ` as a subfield, this theorem is not directly deducible from the corresponding theorem about isometries plus a theorem about scalar multiplication. Likewise for the other theorems about homotheties in this file. -/ def of_homothety (f : E →ₗ[𝕜] F) (a : ℝ) (hf : ∀x, ∥f x∥ = a * ∥x∥) : E →L[𝕜] F := f.mk_continuous a (λ x, le_of_eq (hf x)) variable (𝕜) lemma to_span_singleton_homothety (x : E) (c : 𝕜) : ∥linear_map.to_span_singleton 𝕜 E x c∥ = ∥x∥ * ∥c∥ := by {rw mul_comm, exact norm_smul _ _} /-- Given an element `x` of a normed space `E` over a field `𝕜`, the natural continuous linear map from `E` to the span of `x`.-/ def to_span_singleton (x : E) : 𝕜 →L[𝕜] E := of_homothety (linear_map.to_span_singleton 𝕜 E x) ∥x∥ (to_span_singleton_homothety 𝕜 x) end section op_norm open set real /-- The operator norm of a continuous linear map is the inf of all its bounds. -/ def op_norm := Inf {c | 0 ≤ c ∧ ∀ x, ∥f x∥ ≤ c * ∥x∥} instance has_op_norm : has_norm (E →L[𝕜] F) := ⟨op_norm⟩ lemma norm_def : ∥f∥ = Inf {c | 0 ≤ c ∧ ∀ x, ∥f x∥ ≤ c * ∥x∥} := rfl -- So that invocations of `real.Inf_le` make sense: we show that the set of -- bounds is nonempty and bounded below. lemma bounds_nonempty {f : E →L[𝕜] F} : ∃ c, c ∈ { c | 0 ≤ c ∧ ∀ x, ∥f x∥ ≤ c * ∥x∥ } := let ⟨M, hMp, hMb⟩ := f.bound in ⟨M, le_of_lt hMp, hMb⟩ lemma bounds_bdd_below {f : E →L[𝕜] F} : bdd_below { c | 0 ≤ c ∧ ∀ x, ∥f x∥ ≤ c * ∥x∥ } := ⟨0, λ _ ⟨hn, _⟩, hn⟩ lemma op_norm_nonneg : 0 ≤ ∥f∥ := lb_le_Inf _ bounds_nonempty (λ _ ⟨hx, _⟩, hx) /-- The fundamental property of the operator norm: `∥f x∥ ≤ ∥f∥ * ∥x∥`. -/ theorem le_op_norm : ∥f x∥ ≤ ∥f∥ * ∥x∥ := classical.by_cases (λ heq : x = 0, by { rw heq, simp }) (λ hne, have hlt : 0 < ∥x∥, from norm_pos_iff.2 hne, (div_le_iff hlt).mp ((le_Inf _ bounds_nonempty bounds_bdd_below).2 (λ c ⟨_, hc⟩, (div_le_iff hlt).mpr $ by { apply hc }))) theorem le_op_norm_of_le {c : ℝ} {x} (h : ∥x∥ ≤ c) : ∥f x∥ ≤ ∥f∥ * c := le_trans (f.le_op_norm x) (mul_le_mul_of_nonneg_left h f.op_norm_nonneg) theorem le_of_op_norm_le {c : ℝ} (h : ∥f∥ ≤ c) (x : E) : ∥f x∥ ≤ c * ∥x∥ := (f.le_op_norm x).trans (mul_le_mul_of_nonneg_right h (norm_nonneg x)) /-- continuous linear maps are Lipschitz continuous. -/ theorem lipschitz : lipschitz_with ⟨∥f∥, op_norm_nonneg f⟩ f := lipschitz_with.of_dist_le_mul $ λ x y, by { rw [dist_eq_norm, dist_eq_norm, ←map_sub], apply le_op_norm } lemma ratio_le_op_norm : ∥f x∥ / ∥x∥ ≤ ∥f∥ := div_le_iff_of_nonneg_of_le (norm_nonneg _) f.op_norm_nonneg (le_op_norm _ _) /-- The image of the unit ball under a continuous linear map is bounded. -/ lemma unit_le_op_norm : ∥x∥ ≤ 1 → ∥f x∥ ≤ ∥f∥ := mul_one ∥f∥ ▸ f.le_op_norm_of_le /-- If one controls the norm of every `A x`, then one controls the norm of `A`. -/ lemma op_norm_le_bound {M : ℝ} (hMp: 0 ≤ M) (hM : ∀ x, ∥f x∥ ≤ M * ∥x∥) : ∥f∥ ≤ M := Inf_le _ bounds_bdd_below ⟨hMp, hM⟩ theorem op_norm_le_of_lipschitz {f : E →L[𝕜] F} {K : ℝ≥0} (hf : lipschitz_with K f) : ∥f∥ ≤ K := f.op_norm_le_bound K.2 $ λ x, by simpa only [dist_zero_right, f.map_zero] using hf.dist_le_mul x 0 lemma op_norm_le_of_shell {f : E →L[𝕜] F} {ε C : ℝ} (ε_pos : 0 < ε) (hC : 0 ≤ C) {c : 𝕜} (hc : 1 < ∥c∥) (hf : ∀ x, ε / ∥c∥ ≤ ∥x∥ → ∥x∥ < ε → ∥f x∥ ≤ C * ∥x∥) : ∥f∥ ≤ C := f.op_norm_le_bound hC $ (f : E →ₗ[𝕜] F).bound_of_shell ε_pos hc hf lemma op_norm_le_of_ball {f : E →L[𝕜] F} {ε : ℝ} {C : ℝ} (ε_pos : 0 < ε) (hC : 0 ≤ C) (hf : ∀ x ∈ ball (0 : E) ε, ∥f x∥ ≤ C * ∥x∥) : ∥f∥ ≤ C := begin rcases normed_field.exists_one_lt_norm 𝕜 with ⟨c, hc⟩, refine op_norm_le_of_shell ε_pos hC hc (λ x _ hx, hf x _), rwa ball_0_eq end lemma op_norm_le_of_shell' {f : E →L[𝕜] F} {ε C : ℝ} (ε_pos : 0 < ε) (hC : 0 ≤ C) {c : 𝕜} (hc : ∥c∥ < 1) (hf : ∀ x, ε * ∥c∥ ≤ ∥x∥ → ∥x∥ < ε → ∥f x∥ ≤ C * ∥x∥) : ∥f∥ ≤ C := begin by_cases h0 : c = 0, { refine op_norm_le_of_ball ε_pos hC (λ x hx, hf x _ _), { simp [h0] }, { rwa ball_0_eq at hx } }, { rw [← inv_inv' c, normed_field.norm_inv, inv_lt_one_iff_of_pos (norm_pos_iff.2 $ inv_ne_zero h0)] at hc, refine op_norm_le_of_shell ε_pos hC hc _, rwa [normed_field.norm_inv, div_eq_mul_inv, inv_inv'] } end lemma op_norm_eq_of_bounds {φ : E →L[𝕜] F} {M : ℝ} (M_nonneg : 0 ≤ M) (h_above : ∀ x, ∥φ x∥ ≤ M*∥x∥) (h_below : ∀ N ≥ 0, (∀ x, ∥φ x∥ ≤ N*∥x∥) → M ≤ N) : ∥φ∥ = M := le_antisymm (φ.op_norm_le_bound M_nonneg h_above) ((le_cInf_iff continuous_linear_map.bounds_bdd_below ⟨M, M_nonneg, h_above⟩).mpr $ λ N ⟨N_nonneg, hN⟩, h_below N N_nonneg hN) /-- The operator norm satisfies the triangle inequality. -/ theorem op_norm_add_le : ∥f + g∥ ≤ ∥f∥ + ∥g∥ := show ∥f + g∥ ≤ (coe : ℝ≥0 → ℝ) (⟨_, f.op_norm_nonneg⟩ + ⟨_, g.op_norm_nonneg⟩), from op_norm_le_of_lipschitz (f.lipschitz.add g.lipschitz) /-- An operator is zero iff its norm vanishes. -/ theorem op_norm_zero_iff : ∥f∥ = 0 ↔ f = 0 := iff.intro (λ hn, continuous_linear_map.ext (λ x, norm_le_zero_iff.1 (calc _ ≤ ∥f∥ * ∥x∥ : le_op_norm _ _ ... = _ : by rw [hn, zero_mul]))) (λ hf, le_antisymm (Inf_le _ bounds_bdd_below ⟨ge_of_eq rfl, λ _, le_of_eq (by { rw [zero_mul, hf], exact norm_zero })⟩) (op_norm_nonneg _)) /-- The norm of the identity is at most `1`. It is in fact `1`, except when the space is trivial where it is `0`. It means that one can not do better than an inequality in general. -/ lemma norm_id_le : ∥id 𝕜 E∥ ≤ 1 := op_norm_le_bound _ zero_le_one (λx, by simp) /-- If a space is non-trivial, then the norm of the identity equals `1`. -/ lemma norm_id [nontrivial E] : ∥id 𝕜 E∥ = 1 := le_antisymm norm_id_le $ let ⟨x, hx⟩ := exists_ne (0 : E) in have _ := (id 𝕜 E).ratio_le_op_norm x, by rwa [id_apply, div_self (ne_of_gt $ norm_pos_iff.2 hx)] at this @[simp] lemma norm_id_field : ∥id 𝕜 𝕜∥ = 1 := norm_id @[simp] lemma norm_id_field' : ∥(1 : 𝕜 →L[𝕜] 𝕜)∥ = 1 := norm_id_field lemma op_norm_smul_le : ∥c • f∥ ≤ ∥c∥ * ∥f∥ := ((c • f).op_norm_le_bound (mul_nonneg (norm_nonneg _) (op_norm_nonneg _)) (λ _, begin erw [norm_smul, mul_assoc], exact mul_le_mul_of_nonneg_left (le_op_norm _ _) (norm_nonneg _) end)) lemma op_norm_neg : ∥-f∥ = ∥f∥ := by { rw norm_def, apply congr_arg, ext, simp } /-- Continuous linear maps themselves form a normed space with respect to the operator norm. -/ instance to_normed_group : normed_group (E →L[𝕜] F) := normed_group.of_core _ ⟨op_norm_zero_iff, op_norm_add_le, op_norm_neg⟩ instance to_normed_space : normed_space 𝕜 (E →L[𝕜] F) := ⟨op_norm_smul_le⟩ /-- The operator norm is submultiplicative. -/ lemma op_norm_comp_le (f : E →L[𝕜] F) : ∥h.comp f∥ ≤ ∥h∥ * ∥f∥ := (Inf_le _ bounds_bdd_below ⟨mul_nonneg (op_norm_nonneg _) (op_norm_nonneg _), λ x, by { rw mul_assoc, exact h.le_op_norm_of_le (f.le_op_norm x) } ⟩) /-- Continuous linear maps form a normed ring with respect to the operator norm. -/ instance to_normed_ring : normed_ring (E →L[𝕜] E) := { norm_mul := op_norm_comp_le, .. continuous_linear_map.to_normed_group } /-- For a nonzero normed space `E`, continuous linear endomorphisms form a normed algebra with respect to the operator norm. -/ instance to_normed_algebra [nontrivial E] : normed_algebra 𝕜 (E →L[𝕜] E) := { norm_algebra_map_eq := λ c, show ∥c • id 𝕜 E∥ = ∥c∥, by {rw [norm_smul, norm_id], simp}, .. continuous_linear_map.algebra } /-- A continuous linear map is automatically uniformly continuous. -/ protected theorem uniform_continuous : uniform_continuous f := f.lipschitz.uniform_continuous variable {f} /-- A continuous linear map is an isometry if and only if it preserves the norm. -/ lemma isometry_iff_norm_image_eq_norm : isometry f ↔ ∀x, ∥f x∥ = ∥x∥ := begin rw isometry_emetric_iff_metric, split, { assume H x, have := H x 0, rwa [dist_eq_norm, dist_eq_norm, f.map_zero, sub_zero, sub_zero] at this }, { assume H x y, rw [dist_eq_norm, dist_eq_norm, ← f.map_sub, H] } end lemma homothety_norm [nontrivial E] (f : E →L[𝕜] F) {a : ℝ} (hf : ∀x, ∥f x∥ = a * ∥x∥) : ∥f∥ = a := begin obtain ⟨x, hx⟩ : ∃ (x : E), x ≠ 0 := exists_ne 0, have ha : 0 ≤ a, { apply nonneg_of_mul_nonneg_right, rw ← hf x, apply norm_nonneg, exact norm_pos_iff.mpr hx }, refine le_antisymm_iff.mpr ⟨_, _⟩, { exact continuous_linear_map.op_norm_le_bound f ha (λ y, le_of_eq (hf y)) }, { rw continuous_linear_map.norm_def, apply real.lb_le_Inf _ continuous_linear_map.bounds_nonempty, intros c h, rw mem_set_of_eq at h, apply (mul_le_mul_right (norm_pos_iff.mpr hx)).mp, rw ← hf x, exact h.2 x } end lemma to_span_singleton_norm (x : E) : ∥to_span_singleton 𝕜 x∥ = ∥x∥ := homothety_norm _ (to_span_singleton_homothety 𝕜 x) variable (f) theorem uniform_embedding_of_bound {K : ℝ≥0} (hf : ∀ x, ∥x∥ ≤ K * ∥f x∥) : uniform_embedding f := (f.to_linear_map.antilipschitz_of_bound hf).uniform_embedding f.uniform_continuous /-- If a continuous linear map is a uniform embedding, then it is expands the distances by a positive factor.-/ theorem antilipschitz_of_uniform_embedding (hf : uniform_embedding f) : ∃ K, antilipschitz_with K f := begin obtain ⟨ε, εpos, hε⟩ : ∃ (ε : ℝ) (H : ε > 0), ∀ {x y : E}, dist (f x) (f y) < ε → dist x y < 1, from (uniform_embedding_iff.1 hf).2.2 1 zero_lt_one, let δ := ε/2, have δ_pos : δ > 0 := half_pos εpos, have H : ∀{x}, ∥f x∥ ≤ δ → ∥x∥ ≤ 1, { assume x hx, have : dist x 0 ≤ 1, { refine (hε _).le, rw [f.map_zero, dist_zero_right], exact hx.trans_lt (half_lt_self εpos) }, simpa using this }, rcases normed_field.exists_one_lt_norm 𝕜 with ⟨c, hc⟩, refine ⟨⟨δ⁻¹, _⟩ * nnnorm c, f.to_linear_map.antilipschitz_of_bound $ λx, _⟩, exact inv_nonneg.2 (le_of_lt δ_pos), by_cases hx : f x = 0, { have : f x = f 0, by { simp [hx] }, have : x = 0 := (uniform_embedding_iff.1 hf).1 this, simp [this] }, { rcases rescale_to_shell hc δ_pos hx with ⟨d, hd, dxlt, ledx, dinv⟩, rw [← f.map_smul d] at dxlt, have : ∥d • x∥ ≤ 1 := H dxlt.le, calc ∥x∥ = ∥d∥⁻¹ * ∥d • x∥ : by rwa [← normed_field.norm_inv, ← norm_smul, ← mul_smul, inv_mul_cancel, one_smul] ... ≤ ∥d∥⁻¹ * 1 : mul_le_mul_of_nonneg_left this (inv_nonneg.2 (norm_nonneg _)) ... ≤ δ⁻¹ * ∥c∥ * ∥f x∥ : by rwa [mul_one] } end section completeness open_locale topological_space open filter /-- If the target space is complete, the space of continuous linear maps with its norm is also complete. -/ instance [complete_space F] : complete_space (E →L[𝕜] F) := begin -- We show that every Cauchy sequence converges. refine metric.complete_of_cauchy_seq_tendsto (λ f hf, _), -- We now expand out the definition of a Cauchy sequence, rcases cauchy_seq_iff_le_tendsto_0.1 hf with ⟨b, b0, b_bound, b_lim⟩, clear hf, -- and establish that the evaluation at any point `v : E` is Cauchy. have cau : ∀ v, cauchy_seq (λ n, f n v), { assume v, apply cauchy_seq_iff_le_tendsto_0.2 ⟨λ n, b n * ∥v∥, λ n, _, _, _⟩, { exact mul_nonneg (b0 n) (norm_nonneg _) }, { assume n m N hn hm, rw dist_eq_norm, apply le_trans ((f n - f m).le_op_norm v) _, exact mul_le_mul_of_nonneg_right (b_bound n m N hn hm) (norm_nonneg v) }, { simpa using b_lim.mul tendsto_const_nhds } }, -- We assemble the limits points of those Cauchy sequences -- (which exist as `F` is complete) -- into a function which we call `G`. choose G hG using λv, cauchy_seq_tendsto_of_complete (cau v), -- Next, we show that this `G` is linear, let Glin : E →ₗ[𝕜] F := { to_fun := G, map_add' := λ v w, begin have A := hG (v + w), have B := (hG v).add (hG w), simp only [map_add] at A B, exact tendsto_nhds_unique A B, end, map_smul' := λ c v, begin have A := hG (c • v), have B := filter.tendsto.smul (@tendsto_const_nhds _ ℕ _ c _) (hG v), simp only [map_smul] at A B, exact tendsto_nhds_unique A B end }, -- and that `G` has norm at most `(b 0 + ∥f 0∥)`. have Gnorm : ∀ v, ∥G v∥ ≤ (b 0 + ∥f 0∥) * ∥v∥, { assume v, have A : ∀ n, ∥f n v∥ ≤ (b 0 + ∥f 0∥) * ∥v∥, { assume n, apply le_trans ((f n).le_op_norm _) _, apply mul_le_mul_of_nonneg_right _ (norm_nonneg v), calc ∥f n∥ = ∥(f n - f 0) + f 0∥ : by { congr' 1, abel } ... ≤ ∥f n - f 0∥ + ∥f 0∥ : norm_add_le _ _ ... ≤ b 0 + ∥f 0∥ : begin apply add_le_add_right, simpa [dist_eq_norm] using b_bound n 0 0 (zero_le _) (zero_le _) end }, exact le_of_tendsto (hG v).norm (eventually_of_forall A) }, -- Thus `G` is continuous, and we propose that as the limit point of our original Cauchy sequence. let Gcont := Glin.mk_continuous _ Gnorm, use Gcont, -- Our last task is to establish convergence to `G` in norm. have : ∀ n, ∥f n - Gcont∥ ≤ b n, { assume n, apply op_norm_le_bound _ (b0 n) (λ v, _), have A : ∀ᶠ m in at_top, ∥(f n - f m) v∥ ≤ b n * ∥v∥, { refine eventually_at_top.2 ⟨n, λ m hm, _⟩, apply le_trans ((f n - f m).le_op_norm _) _, exact mul_le_mul_of_nonneg_right (b_bound n m n (le_refl _) hm) (norm_nonneg v) }, have B : tendsto (λ m, ∥(f n - f m) v∥) at_top (𝓝 (∥(f n - Gcont) v∥)) := tendsto.norm (tendsto_const_nhds.sub (hG v)), exact le_of_tendsto B A }, erw tendsto_iff_norm_tendsto_zero, exact squeeze_zero (λ n, norm_nonneg _) this b_lim, end end completeness section uniformly_extend variables [complete_space F] (e : E →L[𝕜] G) (h_dense : dense_range e) section variables (h_e : uniform_inducing e) /-- Extension of a continuous linear map `f : E →L[𝕜] F`, with `E` a normed space and `F` a complete normed space, along a uniform and dense embedding `e : E →L[𝕜] G`. -/ def extend : G →L[𝕜] F := /- extension of `f` is continuous -/ have cont : _ := (uniform_continuous_uniformly_extend h_e h_dense f.uniform_continuous).continuous, /- extension of `f` agrees with `f` on the domain of the embedding `e` -/ have eq : _ := uniformly_extend_of_ind h_e h_dense f.uniform_continuous, { to_fun := (h_e.dense_inducing h_dense).extend f, map_add' := begin refine h_dense.induction_on₂ _ _, { exact is_closed_eq (cont.comp continuous_add) ((cont.comp continuous_fst).add (cont.comp continuous_snd)) }, { assume x y, simp only [eq, ← e.map_add], exact f.map_add _ _ }, end, map_smul' := λk, begin refine (λ b, h_dense.induction_on b _ _), { exact is_closed_eq (cont.comp (continuous_const.smul continuous_id)) ((continuous_const.smul continuous_id).comp cont) }, { assume x, rw ← map_smul, simp only [eq], exact map_smul _ _ _ }, end, cont := cont } lemma extend_unique (g : G →L[𝕜] F) (H : g.comp e = f) : extend f e h_dense h_e = g := continuous_linear_map.injective_coe_fn $ uniformly_extend_unique h_e h_dense (continuous_linear_map.ext_iff.1 H) g.continuous @[simp] lemma extend_zero : extend (0 : E →L[𝕜] F) e h_dense h_e = 0 := extend_unique _ _ _ _ _ (zero_comp _) end section variables {N : ℝ≥0} (h_e : ∀x, ∥x∥ ≤ N * ∥e x∥) local notation `ψ` := f.extend e h_dense (uniform_embedding_of_bound _ h_e).to_uniform_inducing /-- If a dense embedding `e : E →L[𝕜] G` expands the norm by a constant factor `N⁻¹`, then the norm of the extension of `f` along `e` is bounded by `N * ∥f∥`. -/ lemma op_norm_extend_le : ∥ψ∥ ≤ N * ∥f∥ := begin have uni : uniform_inducing e := (uniform_embedding_of_bound _ h_e).to_uniform_inducing, have eq : ∀x, ψ (e x) = f x := uniformly_extend_of_ind uni h_dense f.uniform_continuous, by_cases N0 : 0 ≤ N, { refine op_norm_le_bound ψ _ (is_closed_property h_dense (is_closed_le _ _) _), { exact mul_nonneg N0 (norm_nonneg _) }, { exact continuous_norm.comp (cont ψ) }, { exact continuous_const.mul continuous_norm }, { assume x, rw eq, calc ∥f x∥ ≤ ∥f∥ * ∥x∥ : le_op_norm _ _ ... ≤ ∥f∥ * (N * ∥e x∥) : mul_le_mul_of_nonneg_left (h_e x) (norm_nonneg _) ... ≤ N * ∥f∥ * ∥e x∥ : by rw [mul_comm ↑N ∥f∥, mul_assoc] } }, { have he : ∀ x : E, x = 0, { assume x, have N0 : N ≤ 0 := le_of_lt (lt_of_not_ge N0), rw ← norm_le_zero_iff, exact le_trans (h_e x) (mul_nonpos_of_nonpos_of_nonneg N0 (norm_nonneg _)) }, have hf : f = 0, { ext, simp only [he x, zero_apply, map_zero] }, have hψ : ψ = 0, { rw hf, apply extend_zero }, rw [hψ, hf, norm_zero, norm_zero, mul_zero] } end end end uniformly_extend end op_norm end continuous_linear_map /-- If a continuous linear map is constructed from a linear map via the constructor `mk_continuous`, then its norm is bounded by the bound given to the constructor if it is nonnegative. -/ lemma linear_map.mk_continuous_norm_le (f : E →ₗ[𝕜] F) {C : ℝ} (hC : 0 ≤ C) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) : ∥f.mk_continuous C h∥ ≤ C := continuous_linear_map.op_norm_le_bound _ hC h namespace continuous_linear_map /-- The norm of the tensor product of a scalar linear map and of an element of a normed space is the product of the norms. -/ @[simp] lemma norm_smul_right_apply (c : E →L[𝕜] 𝕜) (f : F) : ∥smul_right c f∥ = ∥c∥ * ∥f∥ := begin refine le_antisymm _ _, { apply op_norm_le_bound _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) (λx, _), calc ∥(c x) • f∥ = ∥c x∥ * ∥f∥ : norm_smul _ _ ... ≤ (∥c∥ * ∥x∥) * ∥f∥ : mul_le_mul_of_nonneg_right (le_op_norm _ _) (norm_nonneg _) ... = ∥c∥ * ∥f∥ * ∥x∥ : by ring }, { by_cases h : ∥f∥ = 0, { rw h, simp [norm_nonneg] }, { have : 0 < ∥f∥ := lt_of_le_of_ne (norm_nonneg _) (ne.symm h), rw ← le_div_iff this, apply op_norm_le_bound _ (div_nonneg (norm_nonneg _) (norm_nonneg f)) (λx, _), rw [div_mul_eq_mul_div, le_div_iff this], calc ∥c x∥ * ∥f∥ = ∥c x • f∥ : (norm_smul _ _).symm ... = ∥((smul_right c f) : E → F) x∥ : rfl ... ≤ ∥smul_right c f∥ * ∥x∥ : le_op_norm _ _ } }, end /-- Given `c : c : E →L[𝕜] 𝕜`, `c.smul_rightL` is the continuous linear map from `F` to `E →L[𝕜] F` sending `f` to `λ e, c e • f`. -/ def smul_rightL (c : E →L[𝕜] 𝕜) : F →L[𝕜] (E →L[𝕜] F) := (c.smul_rightₗ : F →ₗ[𝕜] (E →L[𝕜] F)).mk_continuous _ (λ f, le_of_eq $ c.norm_smul_right_apply f) @[simp] lemma norm_smul_rightL_apply (c : E →L[𝕜] 𝕜) (f : F) : ∥c.smul_rightL f∥ = ∥c∥ * ∥f∥ := by simp [continuous_linear_map.smul_rightL, continuous_linear_map.smul_rightₗ] @[simp] lemma norm_smul_rightL (c : E →L[𝕜] 𝕜) [nontrivial F] : ∥(c.smul_rightL : F →L[𝕜] (E →L[𝕜] F))∥ = ∥c∥ := continuous_linear_map.homothety_norm _ c.norm_smul_right_apply variables (𝕜 F) /-- The linear map obtained by applying a continuous linear map at a given vector. -/ def applyₗ (v : E) : (E →L[𝕜] F) →ₗ[𝕜] F := { to_fun := λ f, f v, map_add' := λ f g, f.add_apply g v, map_smul' := λ x f, f.smul_apply x v } lemma continuous_applyₗ (v : E) : continuous (continuous_linear_map.applyₗ 𝕜 F v) := begin apply (continuous_linear_map.applyₗ 𝕜 F v).continuous_of_bound, intro f, rw mul_comm, exact f.le_op_norm v, end /-- The continuous linear map obtained by applying a continuous linear map at a given vector. -/ def apply (v : E) : (E →L[𝕜] F) →L[𝕜] F := ⟨continuous_linear_map.applyₗ 𝕜 F v, continuous_linear_map.continuous_applyₗ _ _ _⟩ variables {𝕜 F} section multiplication_linear variables (𝕜) (𝕜' : Type*) [normed_ring 𝕜'] [normed_algebra 𝕜 𝕜'] /-- Left-multiplication in a normed algebra, considered as a continuous linear map. -/ def lmul_left : 𝕜' → (𝕜' →L[𝕜] 𝕜') := λ x, (algebra.lmul_left 𝕜 x).mk_continuous ∥x∥ (λ y, by {rw algebra.lmul_left_apply, exact norm_mul_le x y}) /-- Right-multiplication in a normed algebra, considered as a continuous linear map. -/ def lmul_right : 𝕜' → (𝕜' →L[𝕜] 𝕜') := λ x, (algebra.lmul_right 𝕜 x).mk_continuous ∥x∥ (λ y, by {rw [algebra.lmul_right_apply, mul_comm], exact norm_mul_le y x}) /-- Simultaneous left- and right-multiplication in a normed algebra, considered as a continuous linear map. -/ def lmul_left_right (vw : 𝕜' × 𝕜') : 𝕜' →L[𝕜] 𝕜' := (lmul_right 𝕜 𝕜' vw.2).comp (lmul_left 𝕜 𝕜' vw.1) @[simp] lemma lmul_left_apply (x y : 𝕜') : lmul_left 𝕜 𝕜' x y = x * y := rfl @[simp] lemma lmul_right_apply (x y : 𝕜') : lmul_right 𝕜 𝕜' x y = y * x := rfl @[simp] lemma lmul_left_right_apply (vw : 𝕜' × 𝕜') (x : 𝕜') : lmul_left_right 𝕜 𝕜' vw x = vw.1 * x * vw.2 := rfl end multiplication_linear section restrict_scalars variable (𝕜) variables {𝕜' : Type*} [normed_field 𝕜'] [normed_algebra 𝕜 𝕜'] variables {E' : Type*} [normed_group E'] [normed_space 𝕜 E'] [normed_space 𝕜' E'] variables [is_scalar_tower 𝕜 𝕜' E'] variables {F' : Type*} [normed_group F'] [normed_space 𝕜 F'] [normed_space 𝕜' F'] variables [is_scalar_tower 𝕜 𝕜' F'] /-- `𝕜`-linear continuous function induced by a `𝕜'`-linear continuous function when `𝕜'` is a normed algebra over `𝕜`. -/ def restrict_scalars (f : E' →L[𝕜'] F') : E' →L[𝕜] F' := { cont := f.cont, ..linear_map.restrict_scalars 𝕜 (f.to_linear_map) } @[simp, norm_cast] lemma restrict_scalars_coe_eq_coe (f : E' →L[𝕜'] F') : (f.restrict_scalars 𝕜 : E' →ₗ[𝕜] F') = (f : E' →ₗ[𝕜'] F').restrict_scalars 𝕜 := rfl @[simp, norm_cast squash] lemma restrict_scalars_coe_eq_coe' (f : E' →L[𝕜'] F') : (f.restrict_scalars 𝕜 : E' → F') = f := rfl end restrict_scalars section extend_scalars variables {𝕜' : Type*} [normed_field 𝕜'] [normed_algebra 𝕜 𝕜'] variables {F' : Type*} [normed_group F'] [normed_space 𝕜 F'] [normed_space 𝕜' F'] variables [is_scalar_tower 𝕜 𝕜' F'] instance has_scalar_extend_scalars : has_scalar 𝕜' (E →L[𝕜] F') := { smul := λ c f, (c • f.to_linear_map).mk_continuous (∥c∥ * ∥f∥) begin assume x, calc ∥c • (f x)∥ = ∥c∥ * ∥f x∥ : norm_smul c _ ... ≤ ∥c∥ * (∥f∥ * ∥x∥) : mul_le_mul_of_nonneg_left (le_op_norm f x) (norm_nonneg _) ... = ∥c∥ * ∥f∥ * ∥x∥ : (mul_assoc _ _ _).symm end } instance module_extend_scalars : module 𝕜' (E →L[𝕜] F') := { smul_zero := λ _, ext $ λ _, smul_zero _, zero_smul := λ _, ext $ λ _, zero_smul _ _, one_smul := λ _, ext $ λ _, one_smul _ _, mul_smul := λ _ _ _, ext $ λ _, mul_smul _ _ _, add_smul := λ _ _ _, ext $ λ _, add_smul _ _ _, smul_add := λ _ _ _, ext $ λ _, smul_add _ _ _ } instance normed_space_extend_scalars : normed_space 𝕜' (E →L[𝕜] F') := { norm_smul_le := λ c f, linear_map.mk_continuous_norm_le _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) _ } /-- When `f` is a continuous linear map taking values in `S`, then `λb, f b • x` is a continuous linear map. -/ def smul_algebra_right (f : E →L[𝕜] 𝕜') (x : F') : E →L[𝕜] F' := { cont := by continuity!, .. f.to_linear_map.smul_algebra_right x } @[simp] theorem smul_algebra_right_apply (f : E →L[𝕜] 𝕜') (x : F') (c : E) : smul_algebra_right f x c = f c • x := rfl end extend_scalars end continuous_linear_map section has_sum -- Results in this section hold for continuous additive monoid homomorphisms or equivalences but we -- don't have bundled continuous additive homomorphisms. variables {ι R M M₂ : Type*} [semiring R] [add_comm_monoid M] [semimodule R M] [add_comm_monoid M₂] [semimodule R M₂] [topological_space M] [topological_space M₂] omit 𝕜 /-- Applying a continuous linear map commutes with taking an (infinite) sum. -/ protected lemma continuous_linear_map.has_sum {f : ι → M} (φ : M →L[R] M₂) {x : M} (hf : has_sum f x) : has_sum (λ (b:ι), φ (f b)) (φ x) := by simpa only using hf.map φ.to_linear_map.to_add_monoid_hom φ.continuous alias continuous_linear_map.has_sum ← has_sum.mapL protected lemma continuous_linear_map.summable {f : ι → M} (φ : M →L[R] M₂) (hf : summable f) : summable (λ b:ι, φ (f b)) := (hf.has_sum.mapL φ).summable alias continuous_linear_map.summable ← summable.mapL protected lemma continuous_linear_map.map_tsum [t2_space M₂] {f : ι → M} (φ : M →L[R] M₂) (hf : summable f) : φ (∑' z, f z) = ∑' z, φ (f z) := (hf.has_sum.mapL φ).tsum_eq.symm /-- Applying a continuous linear map commutes with taking an (infinite) sum. -/ protected lemma continuous_linear_equiv.has_sum {f : ι → M} (e : M ≃L[R] M₂) {y : M₂} : has_sum (λ (b:ι), e (f b)) y ↔ has_sum f (e.symm y) := ⟨λ h, by simpa only [e.symm.coe_coe, e.symm_apply_apply] using h.mapL (e.symm : M₂ →L[R] M), λ h, by simpa only [e.coe_coe, e.apply_symm_apply] using (e : M →L[R] M₂).has_sum h⟩ protected lemma continuous_linear_equiv.summable {f : ι → M} (e : M ≃L[R] M₂) : summable (λ b:ι, e (f b)) ↔ summable f := ⟨λ hf, (e.has_sum.1 hf.has_sum).summable, (e : M →L[R] M₂).summable⟩ lemma continuous_linear_equiv.tsum_eq_iff [t2_space M] [t2_space M₂] {f : ι → M} (e : M ≃L[R] M₂) {y : M₂} : (∑' z, e (f z)) = y ↔ (∑' z, f z) = e.symm y := begin by_cases hf : summable f, { exact ⟨λ h, (e.has_sum.mp ((e.summable.mpr hf).has_sum_iff.mpr h)).tsum_eq, λ h, (e.has_sum.mpr (hf.has_sum_iff.mpr h)).tsum_eq⟩ }, { have hf' : ¬summable (λ z, e (f z)) := λ h, hf (e.summable.mp h), rw [tsum_eq_zero_of_not_summable hf, tsum_eq_zero_of_not_summable hf'], exact ⟨by { rintro rfl, simp }, λ H, by simpa using (congr_arg (λ z, e z) H)⟩ } end protected lemma continuous_linear_equiv.map_tsum [t2_space M] [t2_space M₂] {f : ι → M} (e : M ≃L[R] M₂) : e (∑' z, f z) = ∑' z, e (f z) := by { refine symm (e.tsum_eq_iff.mpr _), rw e.symm_apply_apply _ } end has_sum namespace continuous_linear_equiv variable (e : E ≃L[𝕜] F) protected lemma lipschitz : lipschitz_with (nnnorm (e : E →L[𝕜] F)) e := (e : E →L[𝕜] F).lipschitz protected lemma antilipschitz : antilipschitz_with (nnnorm (e.symm : F →L[𝕜] E)) e := e.symm.lipschitz.to_right_inverse e.left_inv theorem is_O_comp {α : Type*} (f : α → E) (l : filter α) : asymptotics.is_O (λ x', e (f x')) f l := (e : E →L[𝕜] F).is_O_comp f l theorem is_O_sub (l : filter E) (x : E) : asymptotics.is_O (λ x', e (x' - x)) (λ x', x' - x) l := (e : E →L[𝕜] F).is_O_sub l x theorem is_O_comp_rev {α : Type*} (f : α → E) (l : filter α) : asymptotics.is_O f (λ x', e (f x')) l := (e.symm.is_O_comp _ l).congr_left $ λ _, e.symm_apply_apply _ theorem is_O_sub_rev (l : filter E) (x : E) : asymptotics.is_O (λ x', x' - x) (λ x', e (x' - x)) l := e.is_O_comp_rev _ _ /-- A continuous linear equiv is a uniform embedding. -/ lemma uniform_embedding : uniform_embedding e := e.antilipschitz.uniform_embedding e.lipschitz.uniform_continuous lemma one_le_norm_mul_norm_symm [nontrivial E] : 1 ≤ ∥(e : E →L[𝕜] F)∥ * ∥(e.symm : F →L[𝕜] E)∥ := begin rw [mul_comm], convert (e.symm : F →L[𝕜] E).op_norm_comp_le (e : E →L[𝕜] F), rw [e.coe_symm_comp_coe, continuous_linear_map.norm_id] end lemma norm_pos [nontrivial E] : 0 < ∥(e : E →L[𝕜] F)∥ := pos_of_mul_pos_right (lt_of_lt_of_le zero_lt_one e.one_le_norm_mul_norm_symm) (norm_nonneg _) lemma norm_symm_pos [nontrivial E] : 0 < ∥(e.symm : F →L[𝕜] E)∥ := pos_of_mul_pos_left (lt_of_lt_of_le zero_lt_one e.one_le_norm_mul_norm_symm) (norm_nonneg _) lemma subsingleton_or_norm_symm_pos : subsingleton E ∨ 0 < ∥(e.symm : F →L[𝕜] E)∥ := begin rcases subsingleton_or_nontrivial E with _i|_i; resetI, { left, apply_instance }, { right, exact e.norm_symm_pos } end lemma subsingleton_or_nnnorm_symm_pos : subsingleton E ∨ 0 < (nnnorm $ (e.symm : F →L[𝕜] E)) := subsingleton_or_norm_symm_pos e lemma homothety_inverse (a : ℝ) (ha : 0 < a) (f : E ≃ₗ[𝕜] F) : (∀ (x : E), ∥f x∥ = a * ∥x∥) → (∀ (y : F), ∥f.symm y∥ = a⁻¹ * ∥y∥) := begin intros hf y, calc ∥(f.symm) y∥ = a⁻¹ * (a * ∥ (f.symm) y∥) : _ ... = a⁻¹ * ∥f ((f.symm) y)∥ : by rw hf ... = a⁻¹ * ∥y∥ : by simp, rw [← mul_assoc, inv_mul_cancel (ne_of_lt ha).symm, one_mul], end variable (𝕜) /-- A linear equivalence which is a homothety is a continuous linear equivalence. -/ def of_homothety (f : E ≃ₗ[𝕜] F) (a : ℝ) (ha : 0 < a) (hf : ∀x, ∥f x∥ = a * ∥x∥) : E ≃L[𝕜] F := { to_linear_equiv := f, continuous_to_fun := f.to_linear_map.continuous_of_bound a (λ x, le_of_eq (hf x)), continuous_inv_fun := f.symm.to_linear_map.continuous_of_bound a⁻¹ (λ x, le_of_eq (homothety_inverse a ha f hf x)) } lemma to_span_nonzero_singleton_homothety (x : E) (h : x ≠ 0) (c : 𝕜) : ∥linear_equiv.to_span_nonzero_singleton 𝕜 E x h c∥ = ∥x∥ * ∥c∥ := continuous_linear_map.to_span_singleton_homothety _ _ _ /-- Given a nonzero element `x` of a normed space `E` over a field `𝕜`, the natural continuous linear equivalence from `E` to the span of `x`.-/ def to_span_nonzero_singleton (x : E) (h : x ≠ 0) : 𝕜 ≃L[𝕜] (𝕜 ∙ x) := of_homothety 𝕜 (linear_equiv.to_span_nonzero_singleton 𝕜 E x h) ∥x∥ (norm_pos_iff.mpr h) (to_span_nonzero_singleton_homothety 𝕜 x h) /-- Given a nonzero element `x` of a normed space `E` over a field `𝕜`, the natural continuous linear map from the span of `x` to `𝕜`.-/ abbreviation coord (x : E) (h : x ≠ 0) : (𝕜 ∙ x) →L[𝕜] 𝕜 := (to_span_nonzero_singleton 𝕜 x h).symm lemma coord_norm (x : E) (h : x ≠ 0) : ∥coord 𝕜 x h∥ = ∥x∥⁻¹ := begin have hx : 0 < ∥x∥ := (norm_pos_iff.mpr h), haveI : nontrivial (𝕜 ∙ x) := submodule.nontrivial_span_singleton h, exact continuous_linear_map.homothety_norm _ (λ y, homothety_inverse _ hx _ (to_span_nonzero_singleton_homothety 𝕜 x h) _) end lemma coord_self (x : E) (h : x ≠ 0) : (coord 𝕜 x h) (⟨x, submodule.mem_span_singleton_self x⟩ : 𝕜 ∙ x) = 1 := linear_equiv.coord_self 𝕜 E x h end continuous_linear_equiv lemma linear_equiv.uniform_embedding (e : E ≃ₗ[𝕜] F) (h₁ : continuous e) (h₂ : continuous e.symm) : uniform_embedding e := continuous_linear_equiv.uniform_embedding { continuous_to_fun := h₁, continuous_inv_fun := h₂, .. e } /-- Construct a continuous linear equivalence from a linear equivalence together with bounds in both directions. -/ def linear_equiv.to_continuous_linear_equiv_of_bounds (e : E ≃ₗ[𝕜] F) (C_to C_inv : ℝ) (h_to : ∀ x, ∥e x∥ ≤ C_to * ∥x∥) (h_inv : ∀ x : F, ∥e.symm x∥ ≤ C_inv * ∥x∥) : E ≃L[𝕜] F := { to_linear_equiv := e, continuous_to_fun := e.to_linear_map.continuous_of_bound C_to h_to, continuous_inv_fun := e.symm.to_linear_map.continuous_of_bound C_inv h_inv } namespace continuous_linear_map variables (𝕜) (𝕜' : Type*) [normed_ring 𝕜'] [normed_algebra 𝕜 𝕜'] @[simp] lemma lmul_left_norm (v : 𝕜') : ∥lmul_left 𝕜 𝕜' v∥ = ∥v∥ := begin refine le_antisymm _ _, { exact linear_map.mk_continuous_norm_le _ (norm_nonneg v) _ }, { simpa [@normed_algebra.norm_one 𝕜 _ 𝕜' _ _] using le_op_norm (lmul_left 𝕜 𝕜' v) (1:𝕜') } end @[simp] lemma lmul_right_norm (v : 𝕜') : ∥lmul_right 𝕜 𝕜' v∥ = ∥v∥ := begin refine le_antisymm _ _, { exact linear_map.mk_continuous_norm_le _ (norm_nonneg v) _ }, { simpa [@normed_algebra.norm_one 𝕜 _ 𝕜' _ _] using le_op_norm (lmul_right 𝕜 𝕜' v) (1:𝕜') } end lemma lmul_left_right_norm_le (vw : 𝕜' × 𝕜') : ∥lmul_left_right 𝕜 𝕜' vw∥ ≤ ∥vw.1∥ * ∥vw.2∥ := by simpa [mul_comm] using op_norm_comp_le (lmul_right 𝕜 𝕜' vw.2) (lmul_left 𝕜 𝕜' vw.1) end continuous_linear_map
839cb31b5f334e94e689f0266f020d8850eb093c
35960c5b117752aca7e3e7767c0b393e4dbd72a7
/src/typ/subst.lean
3a51af85db5c7568737f1ef069c215aab16e2f87
[ "Apache-2.0" ]
permissive
spl/tts
461dc76b83df8db47e4660d0941dc97e6d4fd7d1
b65298fea68ce47c8ed3ba3dbce71c1a20dd3481
refs/heads/master
1,541,049,198,347
1,537,967,023,000
1,537,967,029,000
119,653,145
1
0
null
null
null
null
UTF-8
Lean
false
false
6,874
lean
import .fv .lc local attribute [simp] not_or_distrib and_assoc namespace tts ------------------------------------------------------------------ namespace typ ------------------------------------------------------------------ variables {V : Type} [_root_.decidable_eq V] -- Type of variable names variables {x y : tagged V} -- Variables variables {xs : list (tagged V)} -- List of variables variables {t tx t₁ t₂ : typ V} -- Types variables {ts txs ts₂ : list (typ V)} -- Lists of types open list occurs /- subst -/ /-- Substitute a free variable for a type in a type -/ def subst (x : tagged V) (tx : typ V) : typ V → typ V | (var bound y) := var bound y | (var free y) := if x = y then tx else var free y | (arr t₁ t₂) := arr (subst t₁) (subst t₂) @[simp] theorem subst_var_bound : subst x tx (var bound y) = var bound y := rfl @[simp] theorem subst_var_free_eq (h : x = y) : subst x tx (var free y) = tx := by simp [subst, h] @[simp] theorem subst_var_free_ne (h : x ≠ y) : subst x tx (var free y) = var free y := by simp [subst, h] @[simp] theorem subst_arr : subst x tx (arr t₁ t₂) = arr (subst x tx t₁) (subst x tx t₂) := rfl -- Substitution with a fresh name is the identity @[simp] theorem subst_fresh (h : x ∉ fv t) : subst x tx t = t := by induction t with o; try {cases o}; try {simp at h}; try {cases h}; simp * -- Mapping substitution over a list with a fresh name is the identity @[simp] theorem subst_fresh_list (h : x ∉ fv_list ts) : map (subst x t) ts = ts := by induction ts; try {simp at h}; try {cases h}; simp * @[simp] theorem subst_fresh_var_free (h : x ∉ xs) : map (subst x tx) (map (var free) xs) = map (var free) xs := begin apply subst_fresh_list, induction xs with _ _ ih; simp, exact ⟨ne_of_not_mem_cons h, ih (not_mem_of_not_mem_cons h)⟩ end /- subst_list -/ /-- Substitute a list of free variables for a list of types in a type -/ def subst_list : list (tagged V) → list (typ V) → typ V → typ V | (x :: xs) (tx :: txs) t := subst_list xs txs (subst x tx t) | _ _ t := t @[simp] theorem subst_list_nil_left : subst_list [] txs t = t := rfl @[simp] theorem subst_list_nil_right : subst_list xs [] t = t := by cases xs; refl @[simp] theorem subst_list_cons_cons : subst_list (x :: xs) (tx :: txs) t = subst_list xs txs (subst x tx t) := rfl @[simp] theorem subst_list_fresh (F : ∀ x ∈ xs, x ∉ fv t) : subst_list xs txs t = t := begin induction xs generalizing txs t, case list.nil { simp }, case list.cons : _ _ ih { simp at F, cases txs; [simp, {simp [F.1, ih F.2]}] } end private theorem nth_of_map {α} {a} {f : α → α} (p : f a = a) : ∀ {l n}, option.get_or_else ((nth l n).map f) a = f (option.get_or_else (nth l n) a) | [] n := by simp [option.get_or_else, p] | (hd::tl) 0 := by simp [option.get_or_else] | (hd::tl) (n+1) := by simp [option.get_or_else, nth_of_map] -- Substitution distributes over open theorem subst_open_typs (lx : lc tx) : subst x tx (open_typs ts t) = open_typs (map (subst x tx) ts) (subst x tx t) := begin induction t, case typ.var : o y { cases o, case occurs.bound { simp [nth_of_map] }, case occurs.free { by_cases x = y; simp * } }, case typ.arr { simp * } end -- Substitution and open_vars for distinct names commute theorem subst_open_vars (h : x ∉ xs) (lx : lc tx) : open_vars xs (subst x tx t) = subst x tx (open_vars xs t) := by simp [open_vars, h, subst_open_typs lx] theorem subst_list_intro_aux (ts : list (typ V)) (d : xs.nodup) (ln_eq : xs.length = txs.length) (F : ∀ x ∈ xs, x ∉ fv t ∪ fv_list txs ∪ fv_list ts) (ltxs : ∀ t ∈ txs, lc t) (l₂ : ∀ t ∈ ts, lc t) : open_typs (ts ++ txs) t = subst_list xs txs (open_typs (ts ++ map (var free) xs) t) := begin induction xs generalizing txs ts d, case list.nil { have : txs = [] := length_eq_zero.mp (by simp at ln_eq; simp [ln_eq]), simp [this] }, case list.cons : hd tl ih { cases txs; simp at ln_eq, case list.nil { cases ln_eq }, case list.cons : hdxs tlxs { simp at ltxs, have lhdxs : lc hdxs := ltxs.1, have ltlxs : ∀ t ∈ tlxs, lc t := ltxs.2, simp at F, have hdFt : hd ∉ fv t := F.1, have hdFhdxs : hd ∉ fv hdxs := F.2.1, have hdFts : hd ∉ fv_list ts := F.2.2.1, have tlF : ∀ x ∈ tl, x ∉ fv t ∪ fv_list tlxs ∪ fv_list (ts ++ [hdxs]) := λ x h, let H := F.2.2.2.2 x h in by simp [H.1, H.2.1, H.2.2.1, H.2.2.2], have lts_hdxs : ∀ t ∈ ts ++ [hdxs], lc t := λ t h, by simp at h; cases h; simp [h, l₂ t, lhdxs], simp at d, have ih : open_typs (ts ++ [hdxs] ++ tlxs) t = subst_list tl tlxs (open_typs (ts ++ [hdxs] ++ map (var free) tl) t) := ih _ d.2 ln_eq tlF ltlxs lts_hdxs, have append_cons_mid : ∀ {α} {a : α} {l₁ l₂ : list α}, l₁ ++ a :: l₂ = l₁ ++ [a] ++ l₂, by intros; simp, rw [append_cons_mid, ih, ←append_cons_mid], simp [ih, subst_open_typs lhdxs, subst_fresh hdFt, subst_fresh_list hdFts, subst_fresh_var_free d.1] } } end -- Opening up a type `t` with `ts` is the same as opening up `t` with fresh -- names `xs` and then substituting `xs` for `ts`. theorem subst_list_intro (d : xs.nodup) (ln_eq : xs.length = ts.length) (F : ∀ x ∈ xs, x ∉ fv t ∪ fv_list ts) (l : ∀ t ∈ ts, lc t) : open_typs ts t = subst_list xs ts (open_vars xs t) := subst_list_intro_aux [] d ln_eq (λ x, by simpa using F x) l (by simp) -- A type substituted with another type is locally-closed if all type arguments -- are locally-closed. theorem subst_lc (lx : lc tx) (l : lc t) : lc (subst x tx t) := begin induction l, case lc.var : y { by_cases h : x = y; simp [h, lx] }, case lc.arr { simp * } end -- A type substituted with a list of types is locally-closed if all type -- arguments are locally-closed. theorem subst_list_lc (ln_eq : xs.length = txs.length) (ltxs : ∀ tx ∈ txs, lc tx) (lt : lc t) : lc (subst_list xs txs t) := begin induction xs generalizing txs t, case list.nil { simp [lt] }, case list.cons : _ _ ih { cases txs, case list.nil { simp [lt] }, case list.cons { simp at ln_eq, simp at ltxs, simp [ih ln_eq ltxs.2 (subst_lc ltxs.1 lt)] } } end -- Mapping substitution over a list of types is locally-closed if all type -- arguments are locally-closed. theorem map_subst_lc (lt : lc t) (lts : ∀ t ∈ ts, lc t) : ∀ t ∈ map (subst x t) ts, lc t := begin induction ts, case list.nil { simp }, case list.cons : _ _ ih { simp at lts, exact forall_mem_cons.mpr ⟨subst_lc lt lts.1, ih lts.2⟩ } end end /- namespace -/ typ -------------------------------------------------------- end /- namespace -/ tts --------------------------------------------------------
22962881689393b958cf80a8b706a358d2800e4a
cc060cf567f81c404a13ee79bf21f2e720fa6db0
/lean/20170714-lean-user.lean
5c67c96c3ef68bc044e4513228f2917f129cf760
[ "Apache-2.0" ]
permissive
semorrison/proof
cf0a8c6957153bdb206fd5d5a762a75958a82bca
5ee398aa239a379a431190edbb6022b1a0aa2c70
refs/heads/master
1,610,414,502,842
1,518,696,851,000
1,518,696,851,000
78,375,937
2
1
null
null
null
null
UTF-8
Lean
false
false
1,447
lean
def ℤ₀ := ℕ × ℕ def eqv : ℤ₀ → ℤ₀ → Prop | (a, b) (c, d) := a + d = c + b infix ` ∽ `:50 := eqv -- Definition 4.1.2. def add_ℤ₀ : ℤ₀ → ℤ₀ → ℤ₀ | (a, b) (c, d) := (a + c, b + d) -- Lemma 4.1.3 (Addition and multiplication are well-defined). private theorem add_ℤ₀.respects_eqv : ∀ {a b a' b'}, a ∽ a' → b ∽ b' → add_ℤ₀ a b ∽ add_ℤ₀ a' b' | (a₁, a₂) (b₁, b₂) (a'₁, a'₂) (b'₁, b'₂) := assume a_eqv_a' b_eqv_b', have h₁ : a₁ + a'₂ = a'₁ + a₂, from a_eqv_a', have h₂ : b₁ + b'₂ = b'₁ + b₂, from b_eqv_b', have h₃ : a₁ + b₁ + a'₂ + b'₂ = a'₁ + b'₁ + a₂ + b₂, from calc a₁ + b₁ + a'₂ + b'₂ = a₁ + a'₂ + b₁ + b'₂ : by simp [add_comm] ... = a₁ + a'₂ + b'₁ + b₂ : by simp [add_assoc, h₂^.symm] ... = a'₁ + a₂ + b'₁ + b₂ : by simp [add_assoc, h₁^.symm] ... = a'₁ + b'₁ + a₂ + b₂ : by simp [add_comm], have h₄ : (a₁ + b₁, a₂ + b₂) ∽ (a'₁ + b'₁, a'₂ + b'₂), from h₃, -- Why does this fail? have h₅ : add_ℤ₀ (a₁, a₂) (b₁, b₂) = (a₁ + b₁, a₂ + b₂), from rfl, have h₆ : add_ℤ₀ (a'₁, a'₂) (b'₁, b'₂) = (a'₁ + b'₁, a'₂ + b'₂), from rfl, show add_ℤ₀ (a₁, a₂) (b₁, b₂) ∽ add_ℤ₀ (a'₁, a'₂) (b'₁, b'₂), from sorry
602440742ae99b66f02f22a0df1b59ff020cb422
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
/hott/types/trunc.hlean
25d62e78135c6375688aa24ba3d702fd68b776ef
[ "Apache-2.0" ]
permissive
soonhokong/lean-osx
4a954262c780e404c1369d6c06516161d07fcb40
3670278342d2f4faa49d95b46d86642d7875b47c
refs/heads/master
1,611,410,334,552
1,474,425,686,000
1,474,425,686,000
12,043,103
5
1
null
null
null
null
UTF-8
Lean
false
false
18,771
hlean
/- Copyright (c) 2015 Jakob von Raumer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn Properties of is_trunc and trunctype -/ -- NOTE: the fact that (is_trunc n A) is a mere proposition is proved in .prop_trunc import .pointed2 ..function algebra.order types.nat.order open eq sigma sigma.ops pi function equiv trunctype is_equiv prod pointed nat is_trunc algebra namespace trunc_index definition minus_one_le_succ (n : ℕ₋₂) : -1 ≤ n.+1 := succ_le_succ (minus_two_le n) definition zero_le_of_nat (n : ℕ) : 0 ≤ of_nat n := succ_le_succ !minus_one_le_succ open decidable protected definition has_decidable_eq [instance] : Π(n m : ℕ₋₂), decidable (n = m) | has_decidable_eq -2 -2 := inl rfl | has_decidable_eq (n.+1) -2 := inr (by contradiction) | has_decidable_eq -2 (m.+1) := inr (by contradiction) | has_decidable_eq (n.+1) (m.+1) := match has_decidable_eq n m with | inl xeqy := inl (by rewrite xeqy) | inr xney := inr (λ h : succ n = succ m, by injection h with xeqy; exact absurd xeqy xney) end definition not_succ_le_minus_two {n : ℕ₋₂} (H : n .+1 ≤ -2) : empty := by cases H protected definition le_trans {n m k : ℕ₋₂} (H1 : n ≤ m) (H2 : m ≤ k) : n ≤ k := begin induction H2 with k H2 IH, { exact H1}, { exact le.step IH} end definition le_of_succ_le_succ {n m : ℕ₋₂} (H : n.+1 ≤ m.+1) : n ≤ m := begin cases H with m H', { apply le.tr_refl}, { exact trunc_index.le_trans (le.step !le.tr_refl) H'} end theorem not_succ_le_self {n : ℕ₋₂} : ¬n.+1 ≤ n := begin induction n with n IH: intro H, { exact not_succ_le_minus_two H}, { exact IH (le_of_succ_le_succ H)} end protected definition le_antisymm {n m : ℕ₋₂} (H1 : n ≤ m) (H2 : m ≤ n) : n = m := begin induction H2 with n H2 IH, { reflexivity}, { exfalso, apply @not_succ_le_self n, exact trunc_index.le_trans H1 H2} end protected definition le_succ {n m : ℕ₋₂} (H1 : n ≤ m): n ≤ m.+1 := le.step H1 end trunc_index open trunc_index definition weak_order_trunc_index [trans_instance] [reducible] : weak_order trunc_index := weak_order.mk le trunc_index.le.tr_refl @trunc_index.le_trans @trunc_index.le_antisymm namespace trunc_index /- more theorems about truncation indices -/ definition zero_add (n : ℕ₋₂) : (0 : ℕ₋₂) + n = n := begin cases n with n, reflexivity, cases n with n, reflexivity, induction n with n IH, reflexivity, exact ap succ IH end definition add_zero (n : ℕ₋₂) : n + (0 : ℕ₋₂) = n := by reflexivity definition succ_add_nat (n : ℕ₋₂) (m : ℕ) : n.+1 + m = (n + m).+1 := by induction m with m IH; reflexivity; exact ap succ IH definition nat_add_succ (n : ℕ) (m : ℕ₋₂) : n + m.+1 = (n + m).+1 := begin cases m with m, reflexivity, cases m with m, reflexivity, induction m with m IH, reflexivity, exact ap succ IH end definition add_nat_succ (n : ℕ₋₂) (m : ℕ) : n + (nat.succ m) = (n + m).+1 := by reflexivity definition nat_succ_add (n : ℕ) (m : ℕ₋₂) : (nat.succ n) + m = (n + m).+1 := begin cases m with m, reflexivity, cases m with m, reflexivity, induction m with m IH, reflexivity, exact ap succ IH end definition sub_two_add_two (n : ℕ₋₂) : sub_two (add_two n) = n := begin induction n with n IH, { reflexivity}, { exact ap succ IH} end definition add_two_sub_two (n : ℕ) : add_two (sub_two n) = n := begin induction n with n IH, { reflexivity}, { exact ap nat.succ IH} end definition of_nat_add_plus_two_of_nat (n m : ℕ) : n +2+ m = of_nat (n + m + 2) := begin induction m with m IH, { reflexivity}, { exact ap succ IH} end definition of_nat_add_of_nat (n m : ℕ) : of_nat n + of_nat m = of_nat (n + m) := begin induction m with m IH, { reflexivity}, { exact ap succ IH} end definition succ_add_plus_two (n m : ℕ₋₂) : n.+1 +2+ m = (n +2+ m).+1 := begin induction m with m IH, { reflexivity}, { exact ap succ IH} end definition add_plus_two_succ (n m : ℕ₋₂) : n +2+ m.+1 = (n +2+ m).+1 := idp definition add_succ_succ (n m : ℕ₋₂) : n + m.+2 = n +2+ m := idp definition succ_add_succ (n m : ℕ₋₂) : n.+1 + m.+1 = n +2+ m := begin cases m with m IH, { reflexivity}, { apply succ_add_plus_two} end definition succ_succ_add (n m : ℕ₋₂) : n.+2 + m = n +2+ m := begin cases m with m IH, { reflexivity}, { exact !succ_add_succ ⬝ !succ_add_plus_two} end definition succ_sub_two (n : ℕ) : (nat.succ n).-2 = n.-2 .+1 := rfl definition sub_two_succ_succ (n : ℕ) : n.-2.+1.+1 = n := rfl definition succ_sub_two_succ (n : ℕ) : (nat.succ n).-2.+1 = n := rfl definition of_nat_le_of_nat {n m : ℕ} (H : n ≤ m) : (of_nat n ≤ of_nat m) := begin induction H with m H IH, { apply le.refl}, { exact trunc_index.le_succ IH} end definition sub_two_le_sub_two {n m : ℕ} (H : n ≤ m) : n.-2 ≤ m.-2 := begin induction H with m H IH, { apply le.refl}, { exact trunc_index.le_succ IH} end definition add_two_le_add_two {n m : ℕ₋₂} (H : n ≤ m) : add_two n ≤ add_two m := begin induction H with m H IH, { reflexivity}, { constructor, exact IH}, end definition le_of_sub_two_le_sub_two {n m : ℕ} (H : n.-2 ≤ m.-2) : n ≤ m := begin rewrite [-add_two_sub_two n, -add_two_sub_two m], exact add_two_le_add_two H, end definition le_of_of_nat_le_of_nat {n m : ℕ} (H : of_nat n ≤ of_nat m) : n ≤ m := begin apply le_of_sub_two_le_sub_two, exact le_of_succ_le_succ (le_of_succ_le_succ H) end end trunc_index open trunc_index namespace is_trunc variables {A B : Type} {n : ℕ₋₂} /- theorems about trunctype -/ protected definition trunctype.sigma_char.{l} [constructor] (n : ℕ₋₂) : (trunctype.{l} n) ≃ (Σ (A : Type.{l}), is_trunc n A) := begin fapply equiv.MK, { intro A, exact (⟨carrier A, struct A⟩)}, { intro S, exact (trunctype.mk S.1 S.2)}, { intro S, induction S with S1 S2, reflexivity}, { intro A, induction A with A1 A2, reflexivity}, end definition trunctype_eq_equiv [constructor] (n : ℕ₋₂) (A B : n-Type) : (A = B) ≃ (carrier A = carrier B) := calc (A = B) ≃ (to_fun (trunctype.sigma_char n) A = to_fun (trunctype.sigma_char n) B) : eq_equiv_fn_eq_of_equiv ... ≃ ((to_fun (trunctype.sigma_char n) A).1 = (to_fun (trunctype.sigma_char n) B).1) : equiv.symm (!equiv_subtype) ... ≃ (carrier A = carrier B) : equiv.refl theorem is_trunc_is_embedding_closed (f : A → B) [Hf : is_embedding f] [HB : is_trunc n B] (Hn : -1 ≤ n) : is_trunc n A := begin induction n with n, {exfalso, exact not_succ_le_minus_two Hn}, {apply is_trunc_succ_intro, intro a a', fapply @is_trunc_is_equiv_closed_rev _ _ n (ap f)} end theorem is_trunc_is_retraction_closed (f : A → B) [Hf : is_retraction f] (n : ℕ₋₂) [HA : is_trunc n A] : is_trunc n B := begin revert A B f Hf HA, induction n with n IH, { intro A B f Hf HA, induction Hf with g ε, fapply is_contr.mk, { exact f (center A)}, { intro b, apply concat, { apply (ap f), exact (center_eq (g b))}, { apply ε}}}, { intro A B f Hf HA, induction Hf with g ε, apply is_trunc_succ_intro, intro b b', fapply (IH (g b = g b')), { intro q, exact ((ε b)⁻¹ ⬝ ap f q ⬝ ε b')}, { apply (is_retraction.mk (ap g)), { intro p, induction p, {rewrite [↑ap, con.left_inv]}}}, { apply is_trunc_eq}} end definition is_embedding_to_fun (A B : Type) : is_embedding (@to_fun A B) := λf f', !is_equiv_ap_to_fun theorem is_trunc_trunctype [instance] (n : ℕ₋₂) : is_trunc n.+1 (n-Type) := begin apply is_trunc_succ_intro, intro X Y, fapply is_trunc_equiv_closed, { apply equiv.symm, apply trunctype_eq_equiv}, fapply is_trunc_equiv_closed, { apply equiv.symm, apply eq_equiv_equiv}, induction n, { apply @is_contr_of_inhabited_prop, { apply is_trunc_is_embedding_closed, { apply is_embedding_to_fun} , { reflexivity}}, { apply equiv_of_is_contr_of_is_contr}}, { apply is_trunc_is_embedding_closed, { apply is_embedding_to_fun}, { apply minus_one_le_succ}} end /- theorems about decidable equality and axiom K -/ theorem is_set_of_axiom_K {A : Type} (K : Π{a : A} (p : a = a), p = idp) : is_set A := is_set.mk _ (λa b p q, eq.rec_on q K p) theorem is_set_of_relation.{u} {A : Type.{u}} (R : A → A → Type.{u}) (mere : Π(a b : A), is_prop (R a b)) (refl : Π(a : A), R a a) (imp : Π{a b : A}, R a b → a = b) : is_set A := is_set_of_axiom_K (λa p, have H2 : transport (λx, R a x → a = x) p (@imp a a) = @imp a a, from !apd, have H3 : Π(r : R a a), transport (λx, a = x) p (imp r) = imp (transport (λx, R a x) p r), from to_fun (equiv.symm !heq_pi) H2, have H4 : imp (refl a) ⬝ p = imp (refl a), from calc imp (refl a) ⬝ p = transport (λx, a = x) p (imp (refl a)) : transport_eq_r ... = imp (transport (λx, R a x) p (refl a)) : H3 ... = imp (refl a) : is_prop.elim, cancel_left (imp (refl a)) H4) definition relation_equiv_eq {A : Type} (R : A → A → Type) (mere : Π(a b : A), is_prop (R a b)) (refl : Π(a : A), R a a) (imp : Π{a b : A}, R a b → a = b) (a b : A) : R a b ≃ a = b := @equiv_of_is_prop _ _ _ (@is_trunc_eq _ _ (is_set_of_relation R mere refl @imp) a b) imp (λp, p ▸ refl a) local attribute not [reducible] theorem is_set_of_double_neg_elim {A : Type} (H : Π(a b : A), ¬¬a = b → a = b) : is_set A := is_set_of_relation (λa b, ¬¬a = b) _ (λa n, n idp) H section open decidable --this is proven differently in init.hedberg theorem is_set_of_decidable_eq (A : Type) [H : decidable_eq A] : is_set A := is_set_of_double_neg_elim (λa b, by_contradiction) end theorem is_trunc_of_axiom_K_of_le {A : Type} (n : ℕ₋₂) (H : -1 ≤ n) (K : Π(a : A), is_trunc n (a = a)) : is_trunc (n.+1) A := @is_trunc_succ_intro _ _ (λa b, is_trunc_of_imp_is_trunc_of_le H (λp, eq.rec_on p !K)) theorem is_trunc_succ_of_is_trunc_loop (Hn : -1 ≤ n) (Hp : Π(a : A), is_trunc n (a = a)) : is_trunc (n.+1) A := begin apply is_trunc_succ_intro, intros a a', apply is_trunc_of_imp_is_trunc_of_le Hn, intro p, induction p, apply Hp end theorem is_prop_iff_is_contr {A : Type} (a : A) : is_prop A ↔ is_contr A := iff.intro (λH, is_contr.mk a (is_prop.elim a)) _ theorem is_trunc_succ_iff_is_trunc_loop (A : Type) (Hn : -1 ≤ n) : is_trunc (n.+1) A ↔ Π(a : A), is_trunc n (a = a) := iff.intro _ (is_trunc_succ_of_is_trunc_loop Hn) theorem is_trunc_iff_is_contr_loop_succ (n : ℕ) (A : Type) : is_trunc n A ↔ Π(a : A), is_contr (Ω[succ n](pointed.Mk a)) := begin revert A, induction n with n IH, { intro A, esimp [iterated_ploop_space], transitivity _, { apply is_trunc_succ_iff_is_trunc_loop, apply le.refl}, { apply pi_iff_pi, intro a, esimp, apply is_prop_iff_is_contr, reflexivity}}, { intro A, esimp [iterated_ploop_space], transitivity _, { apply @is_trunc_succ_iff_is_trunc_loop @n, esimp, apply minus_one_le_succ}, apply pi_iff_pi, intro a, transitivity _, apply IH, transitivity _, apply pi_iff_pi, intro p, rewrite [iterated_loop_space_loop_irrel n p], apply iff.refl, esimp, apply imp_iff, reflexivity} end theorem is_trunc_iff_is_contr_loop (n : ℕ) (A : Type) : is_trunc (n.-2.+1) A ↔ (Π(a : A), is_contr (Ω[n](pointed.Mk a))) := begin induction n with n, { esimp [sub_two,iterated_ploop_space], apply iff.intro, intro H a, exact is_contr_of_inhabited_prop a, intro H, apply is_prop_of_imp_is_contr, exact H}, { apply is_trunc_iff_is_contr_loop_succ}, end theorem is_contr_loop_of_is_trunc (n : ℕ) (A : Type*) [H : is_trunc (n.-2.+1) A] : is_contr (Ω[n] A) := begin induction A, apply iff.mp !is_trunc_iff_is_contr_loop H end theorem is_trunc_loop_of_is_trunc (n : ℕ₋₂) (k : ℕ) (A : Type*) [H : is_trunc n A] : is_trunc n (Ω[k] A) := begin induction k with k IH, { exact H}, { apply is_trunc_eq} end end is_trunc open is_trunc namespace trunc variable {A : Type} protected definition code (n : ℕ₋₂) (aa aa' : trunc n.+1 A) : n-Type := trunc.rec_on aa (λa, trunc.rec_on aa' (λa', trunctype.mk' n (trunc n (a = a')))) protected definition encode (n : ℕ₋₂) (aa aa' : trunc n.+1 A) : aa = aa' → trunc.code n aa aa' := begin intro p, induction p, induction aa with a, esimp [trunc.code,trunc.rec_on], exact (tr idp) end protected definition decode (n : ℕ₋₂) (aa aa' : trunc n.+1 A) : trunc.code n aa aa' → aa = aa' := begin induction aa' with a', induction aa with a, esimp [trunc.code, trunc.rec_on], intro x, induction x with p, exact ap tr p, end definition trunc_eq_equiv [constructor] (n : ℕ₋₂) (aa aa' : trunc n.+1 A) : aa = aa' ≃ trunc.code n aa aa' := begin fapply equiv.MK, { apply trunc.encode}, { apply trunc.decode}, { eapply (trunc.rec_on aa'), eapply (trunc.rec_on aa), intro a a' x, esimp [trunc.code, trunc.rec_on] at x, refine (@trunc.rec_on n _ _ x _ _), intro x, apply is_trunc_eq, intro p, induction p, reflexivity}, { intro p, induction p, apply (trunc.rec_on aa), intro a, exact idp}, end definition tr_eq_tr_equiv [constructor] (n : ℕ₋₂) (a a' : A) : (tr a = tr a' :> trunc n.+1 A) ≃ trunc n (a = a') := !trunc_eq_equiv definition is_trunc_trunc_of_is_trunc [instance] [priority 500] (A : Type) (n m : ℕ₋₂) [H : is_trunc n A] : is_trunc n (trunc m A) := begin revert A m H, eapply (trunc_index.rec_on n), { clear n, intro A m H, apply is_contr_equiv_closed, { apply equiv.symm, apply trunc_equiv, apply (@is_trunc_of_le _ -2), apply minus_two_le} }, { clear n, intro n IH A m H, induction m with m, { apply (@is_trunc_of_le _ -2), apply minus_two_le}, { apply is_trunc_succ_intro, intro aa aa', apply (@trunc.rec_on _ _ _ aa (λy, !is_trunc_succ_of_is_prop)), eapply (@trunc.rec_on _ _ _ aa' (λy, !is_trunc_succ_of_is_prop)), intro a a', apply (is_trunc_equiv_closed_rev), { apply tr_eq_tr_equiv}, { exact (IH _ _ _)}}} end definition unique_choice {P : A → Type} [H : Πa, is_prop (P a)] (f : Πa, ∥ P a ∥) (a : A) : P a := !trunc_equiv (f a) /- transport over a truncated family -/ definition trunc_transport {a a' : A} {P : A → Type} (p : a = a') (n : ℕ₋₂) (x : P a) : transport (λa, trunc n (P a)) p (tr x) = tr (p ▸ x) := by induction p; reflexivity definition trunc_trunc_equiv_left [constructor] (A : Type) (n m : ℕ₋₂) (H : n ≤ m) : trunc n (trunc m A) ≃ trunc n A := begin note H2 := is_trunc_of_le (trunc n A) H, fapply equiv.MK, { intro x, induction x with x, induction x with x, exact tr x}, { intro x, induction x with x, exact tr (tr x)}, { intro x, induction x with x, reflexivity}, { intro x, induction x with x, induction x with x, reflexivity} end definition trunc_trunc_equiv_right [constructor] (A : Type) (n m : ℕ₋₂) (H : n ≤ m) : trunc m (trunc n A) ≃ trunc n A := begin apply trunc_equiv, exact is_trunc_of_le _ H, end definition image [constructor] {A B : Type} (f : A → B) (b : B) : Prop := ∥ fiber f b ∥ definition image.mk [constructor] {A B : Type} {f : A → B} {b : B} (a : A) (p : f a = b) : image f b := tr (fiber.mk a p) -- truncation of pointed types definition ptrunc [constructor] (n : ℕ₋₂) (X : Type*) : n-Type* := ptrunctype.mk (trunc n X) _ (tr pt) definition ptrunc_functor [constructor] {X Y : Type*} (n : ℕ₋₂) (f : X →* Y) : ptrunc n X →* ptrunc n Y := pmap.mk (trunc_functor n f) (ap tr (respect_pt f)) definition ptrunc_pequiv [constructor] (n : ℕ₋₂) {X Y : Type*} (H : X ≃* Y) : ptrunc n X ≃* ptrunc n Y := pequiv_of_equiv (trunc_equiv_trunc n H) (ap tr (respect_pt H)) definition loop_ptrunc_pequiv [constructor] (n : ℕ₋₂) (A : Type*) : Ω (ptrunc (n+1) A) ≃* ptrunc n (Ω A) := pequiv_of_equiv !tr_eq_tr_equiv idp definition iterated_loop_ptrunc_pequiv [constructor] (n : ℕ₋₂) (k : ℕ) (A : Type*) : Ω[k] (ptrunc (n+k) A) ≃* ptrunc n (Ω[k] A) := begin revert n, induction k with k IH: intro n, { reflexivity}, { refine _ ⬝e* loop_ptrunc_pequiv n (Ω[k] A), rewrite [iterated_ploop_space_succ], apply loop_pequiv_loop, refine _ ⬝e* IH (n.+1), rewrite succ_add_nat} end definition ptrunc_functor_pcompose [constructor] {X Y Z : Type*} (n : ℕ₋₂) (g : Y →* Z) (f : X →* Y) : ptrunc_functor n (g ∘* f) ~* ptrunc_functor n g ∘* ptrunc_functor n f := begin fapply phomotopy.mk, { apply trunc_functor_compose}, { esimp, refine !idp_con ⬝ _, refine whisker_right !ap_compose'⁻¹ᵖ _ ⬝ _, esimp, refine whisker_right (ap_compose' tr g _) _ ⬝ _, exact !ap_con⁻¹}, end definition ptrunc_functor_pid [constructor] (X : Type*) (n : ℕ₋₂) : ptrunc_functor n (pid X) ~* pid (ptrunc n X) := begin fapply phomotopy.mk, { apply trunc_functor_id}, { reflexivity}, end definition ptrunc_functor_pcast [constructor] {X Y : Type*} (n : ℕ₋₂) (p : X = Y) : ptrunc_functor n (pcast p) ~* pcast (ap (ptrunc n) p) := begin fapply phomotopy.mk, { intro x, esimp, refine !trunc_functor_cast ⬝ _, refine ap010 cast _ x, refine !ap_compose'⁻¹ ⬝ !ap_compose'}, { induction p, reflexivity}, end end trunc open trunc namespace function variables {A B : Type} definition is_surjective_of_is_equiv [instance] (f : A → B) [H : is_equiv f] : is_surjective f := λb, begin esimp, apply center end definition is_equiv_equiv_is_embedding_times_is_surjective [constructor] (f : A → B) : is_equiv f ≃ (is_embedding f × is_surjective f) := equiv_of_is_prop (λH, (_, _)) (λP, prod.rec_on P (λH₁ H₂, !is_equiv_of_is_surjective_of_is_embedding)) end function
a479cdababc7606c70cc91a61830356038cc990d
57c233acf9386e610d99ed20ef139c5f97504ba3
/src/data/set/intervals/infinite.lean
70b92219d666ee8c2d36c03d294cd6e575077016
[ "Apache-2.0" ]
permissive
robertylewis/mathlib
3d16e3e6daf5ddde182473e03a1b601d2810952c
1d13f5b932f5e40a8308e3840f96fc882fae01f0
refs/heads/master
1,651,379,945,369
1,644,276,960,000
1,644,276,960,000
98,875,504
0
0
Apache-2.0
1,644,253,514,000
1,501,495,700,000
Lean
UTF-8
Lean
false
false
1,893
lean
/- Copyright (c) 2020 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton -/ import data.set.finite /-! # Infinitude of intervals Bounded intervals in dense orders are infinite, as are unbounded intervals in orders that are unbounded on the appropriate side. -/ namespace set variables {α : Type*} [preorder α] section bounded variables [densely_ordered α] lemma Ioo.infinite {a b : α} (h : a < b) : infinite (Ioo a b) := begin rintro (f : finite (Ioo a b)), obtain ⟨m, hm₁, hm₂⟩ : ∃ m ∈ Ioo a b, ∀ x ∈ Ioo a b, ¬x < m, { simpa [h] using finset.exists_minimal f.to_finset }, obtain ⟨z, hz₁, hz₂⟩ : ∃ z, a < z ∧ z < m := exists_between hm₁.1, exact hm₂ z ⟨hz₁, lt_trans hz₂ hm₁.2⟩ hz₂, end lemma Ico.infinite {a b : α} (h : a < b) : infinite (Ico a b) := (Ioo.infinite h).mono Ioo_subset_Ico_self lemma Ioc.infinite {a b : α} (h : a < b) : infinite (Ioc a b) := (Ioo.infinite h).mono Ioo_subset_Ioc_self lemma Icc.infinite {a b : α} (h : a < b) : infinite (Icc a b) := (Ioo.infinite h).mono Ioo_subset_Icc_self end bounded section unbounded_below variables [no_min_order α] lemma Iio.infinite {b : α} : infinite (Iio b) := begin rintro (f : finite (Iio b)), obtain ⟨m, hm₁, hm₂⟩ : ∃ m < b, ∀ x < b, ¬x < m, { simpa using finset.exists_minimal f.to_finset }, obtain ⟨z, hz⟩ : ∃ z, z < m := exists_lt _, exact hm₂ z (lt_trans hz hm₁) hz end lemma Iic.infinite {b : α} : infinite (Iic b) := Iio.infinite.mono Iio_subset_Iic_self end unbounded_below section unbounded_above variables [no_max_order α] lemma Ioi.infinite {a : α} : infinite (Ioi a) := by apply @Iio.infinite (order_dual α) lemma Ici.infinite {a : α} : infinite (Ici a) := Ioi.infinite.mono Ioi_subset_Ici_self end unbounded_above end set
8cf25e5f9d17b3e1c1d98cc7b7ab6cfae0a78a0c
680b0d1592ce164979dab866b232f6fa743f2cc8
/library/data/finset/partition.lean
34326a7b5b6f3aa25c35b9924ebb23aff5c7af01
[ "Apache-2.0" ]
permissive
syohex/lean
657428ab520f8277fc18cf04bea2ad200dbae782
081ad1212b686780f3ff8a6d0e5f8a1d29a7d8bc
refs/heads/master
1,611,274,838,635
1,452,668,188,000
1,452,668,188,000
49,562,028
0
0
null
1,452,675,604,000
1,452,675,602,000
null
UTF-8
Lean
false
false
5,822
lean
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Haitao Zhang Partitions of a type A into finite subsets of A. Such a partition is represented by a function f : A → finset A which maps every element a : A to its equivalence class. -/ import .card open function eq.ops variable {A : Type} variable [deceqA : decidable_eq A] include deceqA namespace finset definition is_partition (f : A → finset A) := ∀ a b, a ∈ f b = (f a = f b) structure partition : Type := (set : finset A) (part : A → finset A) (is_part : is_partition part) (complete : set = Union set part) attribute partition.part [coercion] namespace partition definition equiv_classes (f : partition) : finset (finset A) := image (partition.part f) (partition.set f) lemma equiv_class_disjoint (f : partition) (a1 a2 : finset A) (Pa1 : a1 ∈ equiv_classes f) (Pa2 : a2 ∈ equiv_classes f) : a1 ≠ a2 → a1 ∩ a2 = ∅ := assume Pne, assert Pe1 : _, from exists_of_mem_image Pa1, obtain g1 Pg1, from Pe1, assert Pe2 : _, from exists_of_mem_image Pa2, obtain g2 Pg2, from Pe2, begin apply inter_eq_empty_of_disjoint, apply disjoint.intro, rewrite [eq.symm (and.right Pg1), eq.symm (and.right Pg2)], intro x, rewrite [*partition.is_part f], intro Pxg1, rewrite [Pxg1, and.right Pg1, and.right Pg2], intro Pe, exact absurd Pe Pne end open nat theorem class_equation (f : @partition A _) : card (partition.set f) = finset.Sum (equiv_classes f) card := let s := (partition.set f), p := (partition.part f), img := image p s in calc card s = card (Union s p) : partition.complete f ... = card (Union img id) : image_eq_Union_index_image s p ... = card (Union (equiv_classes f) id) : rfl ... = finset.Sum (equiv_classes f) card : card_Union_of_disjoint _ id (equiv_class_disjoint f) lemma equiv_class_refl {f : A → finset A} (Pequiv : is_partition f) : ∀ a, a ∈ f a := take a, by rewrite [Pequiv a a] -- make it a little easier to prove union from restriction lemma restriction_imp_union {s : finset A} (f : A → finset A) (Pequiv : is_partition f) (Psub : ∀{a}, a ∈ s → f a ⊆ s) : s = Union s f := ext (take a, iff.intro (assume Pains, begin rewrite [(Union_insert_of_mem f Pains)⁻¹, Union_insert], apply mem_union_l, exact equiv_class_refl Pequiv a end) (assume Painu, have Pclass : ∃ x, x ∈ s ∧ a ∈ f x, from iff.elim_left (mem_Union_iff s f _) Painu, obtain x Px, from Pclass, have Pfx : f x ⊆ s, from Psub (and.left Px), mem_of_subset_of_mem Pfx (and.right Px))) lemma binary_union (P : A → Prop) [decP : decidable_pred P] {S : finset A} : S = {a ∈ S | P a} ∪ {a ∈ S | ¬(P a)} := ext take a, iff.intro (suppose a ∈ S, decidable.by_cases (suppose P a, mem_union_l (mem_sep_of_mem `a ∈ S` this)) (suppose ¬ P a, mem_union_r (mem_sep_of_mem `a ∈ S` this))) (suppose a ∈ sep P S ∪ {a ∈ S | ¬ P a}, or.elim (mem_or_mem_of_mem_union this) (suppose a ∈ sep P S, mem_of_mem_sep this) (suppose a ∈ {a ∈ S | ¬ P a}, mem_of_mem_sep this)) lemma binary_inter_empty {P : A → Prop} [decP : decidable_pred P] {S : finset A} : {a ∈ S | P a} ∩ {a ∈ S | ¬(P a)} = ∅ := inter_eq_empty (take a, assume Pa nPa, absurd (of_mem_sep Pa) (of_mem_sep nPa)) definition disjoint_sets (S : finset (finset A)) : Prop := ∀ s₁ s₂ (P₁ : s₁ ∈ S) (P₂ : s₂ ∈ S), s₁ ≠ s₂ → s₁ ∩ s₂ = ∅ lemma disjoint_sets_sep_of_disjoint_sets {P : finset A → Prop} [decP : decidable_pred P] {S : finset (finset A)} : disjoint_sets S → disjoint_sets {s ∈ S | P s} := assume Pds, take s₁ s₂, assume P₁ P₂, Pds s₁ s₂ (mem_of_mem_sep P₁) (mem_of_mem_sep P₂) lemma binary_inter_empty_Union_disjoint_sets {P : finset A → Prop} [decP : decidable_pred P] {S : finset (finset A)} : disjoint_sets S → Union {s ∈ S | P s} id ∩ Union {s ∈ S | ¬P s} id = ∅ := assume Pds, inter_eq_empty (take a, assume Pa nPa, obtain s Psin Pains, from iff.elim_left !mem_Union_iff Pa, obtain t Ptin Paint, from iff.elim_left !mem_Union_iff nPa, assert s ≠ t, from assume Peq, absurd (Peq ▸ of_mem_sep Psin) (of_mem_sep Ptin), Pds s t (mem_of_mem_sep Psin) (mem_of_mem_sep Ptin) `s ≠ t` ▸ mem_inter Pains Paint) section variables {B: Type} [deceqB : decidable_eq B] include deceqB lemma binary_Union (f : A → finset B) {P : A → Prop} [decP : decidable_pred P] {s : finset A} : Union s f = Union {a ∈ s | P a} f ∪ Union {a ∈ s | ¬P a} f := begin rewrite [binary_union P at {1}], apply Union_union, exact binary_inter_empty end end open nat section variables {B : Type} [acmB : add_comm_monoid B] include acmB lemma Sum_binary_union (f : A → B) (P : A → Prop) [decP : decidable_pred P] {S : finset A} : Sum S f = Sum {s ∈ S | P s} f + Sum {s ∈ S | ¬P s} f := calc Sum S f = Sum ({s ∈ S | P s} ∪ {s ∈ S | ¬(P s)}) f : binary_union ... = Sum {s ∈ S | P s} f + Sum {s ∈ S | ¬P s} f : Sum_union f binary_inter_empty end lemma card_binary_Union_disjoint_sets (P : finset A → Prop) [decP : decidable_pred P] {S : finset (finset A)} : disjoint_sets S → card (Union S id) = Sum {s ∈ S | P s} card + Sum {s ∈ S | ¬P s} card := assume Pds, calc card (Union S id) = card (Union {s ∈ S | P s} id ∪ Union {s ∈ S | ¬P s} id) : binary_Union ... = card (Union {s ∈ S | P s} id) + card (Union {s ∈ S | ¬P s} id) : card_union_of_disjoint (binary_inter_empty_Union_disjoint_sets Pds) ... = Sum {s ∈ S | P s} card + Sum {s ∈ S | ¬P s} card : by rewrite [*(card_Union_of_disjoint _ id (disjoint_sets_sep_of_disjoint_sets Pds))] end partition end finset
44f2d672fe803a6d7d6cc8117d604118998eff33
6b45072eb2b3db3ecaace2a7a0241ce81f815787
/data/set/default.lean
5e037486c92d535b67f907e53961562adc355eb4
[]
no_license
avigad/library_dev
27b47257382667b5eb7e6476c4f5b0d685dd3ddc
9d8ac7c7798ca550874e90fed585caad030bbfac
refs/heads/master
1,610,452,468,791
1,500,712,839,000
1,500,713,478,000
69,311,142
1
0
null
1,474,942,903,000
1,474,942,902,000
null
UTF-8
Lean
false
false
22
lean
import .basic .finite
915da2e57532b12110db026c8bae7da1d8e5fd47
4efff1f47634ff19e2f786deadd394270a59ecd2
/src/topology/algebra/infinite_sum.lean
a4d346170b9f7327f50f51663bec7b0d396a192c
[ "Apache-2.0" ]
permissive
agjftucker/mathlib
d634cd0d5256b6325e3c55bb7fb2403548371707
87fe50de17b00af533f72a102d0adefe4a2285e8
refs/heads/master
1,625,378,131,941
1,599,166,526,000
1,599,166,526,000
160,748,509
0
0
Apache-2.0
1,544,141,789,000
1,544,141,789,000
null
UTF-8
Lean
false
false
36,409
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 -/ import algebra.big_operators.intervals import topology.instances.real import data.indicator_function import data.equiv.encodable.lattice import order.filter.at_top_bot /-! # Infinite sum over a topological monoid This sum is known as unconditionally convergent, as it sums to the same value under all possible permutations. For Euclidean spaces (finite dimensional Banach spaces) this is equivalent to absolute convergence. Note: There are summable sequences which are not unconditionally convergent! The other way holds generally, see `has_sum.tendsto_sum_nat`. ## References * Bourbaki: General Topology (1995), Chapter 3 §5 (Infinite sums in commutative groups) -/ noncomputable theory open finset filter function classical open_locale topological_space classical big_operators variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} section has_sum variables [add_comm_monoid α] [topological_space α] /-- Infinite sum on a topological monoid The `at_top` filter on `finset α` is the limit of all finite sets towards the entire type. So we sum up bigger and bigger sets. This sum operation is still invariant under reordering, and a absolute sum operator. This is based on Mario Carneiro's infinite sum in Metamath. For the definition or many statements, α does not need to be a topological monoid. We only add this assumption later, for the lemmas where it is relevant. -/ def has_sum (f : β → α) (a : α) : Prop := tendsto (λs:finset β, ∑ b in s, f b) at_top (𝓝 a) /-- `summable f` means that `f` has some (infinite) sum. Use `tsum` to get the value. -/ def summable (f : β → α) : Prop := ∃a, has_sum f a /-- `∑' i, f i` is the sum of `f` it exists, or 0 otherwise -/ def tsum {β} (f : β → α) := if h : summable f then classical.some h else 0 notation `∑'` binders `, ` r:(scoped f, tsum f) := r variables {f g : β → α} {a b : α} {s : finset β} lemma summable.has_sum (ha : summable f) : has_sum f (∑'b, f b) := by simp [ha, tsum]; exact some_spec ha lemma has_sum.summable (h : has_sum f a) : summable f := ⟨a, h⟩ /-- Constant zero function has sum `0` -/ lemma has_sum_zero : has_sum (λb, 0 : β → α) 0 := by simp [has_sum, tendsto_const_nhds] lemma summable_zero : summable (λb, 0 : β → α) := has_sum_zero.summable lemma tsum_eq_zero_of_not_summable (h : ¬ summable f) : (∑'b, f b) = 0 := by simp [tsum, h] lemma has_sum.has_sum_of_sum_eq {g : γ → α} (h_eq : ∀u:finset γ, ∃v:finset β, ∀v', v ⊆ v' → ∃u', u ⊆ u' ∧ ∑ x in u', g x = ∑ b in v', f b) (hf : has_sum g a) : has_sum f a := le_trans (map_at_top_finset_sum_le_of_sum_eq h_eq) hf lemma has_sum_iff_has_sum {g : γ → α} (h₁ : ∀u:finset γ, ∃v:finset β, ∀v', v ⊆ v' → ∃u', u ⊆ u' ∧ ∑ x in u', g x = ∑ b in v', f b) (h₂ : ∀v:finset β, ∃u:finset γ, ∀u', u ⊆ u' → ∃v', v ⊆ v' ∧ ∑ b in v', f b = ∑ x in u', g x) : has_sum f a ↔ has_sum g a := ⟨has_sum.has_sum_of_sum_eq h₂, has_sum.has_sum_of_sum_eq h₁⟩ lemma function.injective.has_sum_iff {g : γ → β} (hg : injective g) (hf : ∀ x ∉ set.range g, f x = 0) : has_sum (f ∘ g) a ↔ has_sum f a := by simp only [has_sum, tendsto, hg.map_at_top_finset_sum_eq hf] lemma function.injective.summable_iff {g : γ → β} (hg : injective g) (hf : ∀ x ∉ set.range g, f x = 0) : summable (f ∘ g) ↔ summable f := exists_congr $ λ _, hg.has_sum_iff hf lemma has_sum_subtype_iff_of_support_subset {s : set β} (hf : support f ⊆ s) : has_sum (f ∘ coe : s → α) a ↔ has_sum f a := subtype.coe_injective.has_sum_iff $ by simpa using support_subset_iff'.1 hf lemma has_sum_subtype_iff_indicator {s : set β} : has_sum (f ∘ coe : s → α) a ↔ has_sum (s.indicator f) a := by rw [← set.indicator_range_comp, subtype.range_coe, has_sum_subtype_iff_of_support_subset set.support_indicator] @[simp] lemma has_sum_subtype_support : has_sum (f ∘ coe : support f → α) a ↔ has_sum f a := has_sum_subtype_iff_of_support_subset $ set.subset.refl _ lemma has_sum_fintype [fintype β] (f : β → α) : has_sum f (∑ b, f b) := order_top.tendsto_at_top_nhds _ protected lemma finset.has_sum (s : finset β) (f : β → α) : has_sum (f ∘ coe : (↑s : set β) → α) (∑ b in s, f b) := by { rw ← sum_attach, exact has_sum_fintype _ } protected lemma finset.summable (s : finset β) (f : β → α) : summable (f ∘ coe : (↑s : set β) → α) := (s.has_sum f).summable protected lemma set.finite.summable {s : set β} (hs : s.finite) (f : β → α) : summable (f ∘ coe : s → α) := by convert hs.to_finset.summable f; simp only [hs.coe_to_finset] /-- If a function `f` vanishes outside of a finite set `s`, then it `has_sum` `∑ b in s, f b`. -/ lemma has_sum_sum_of_ne_finset_zero (hf : ∀b∉s, f b = 0) : has_sum f (∑ b in s, f b) := (has_sum_subtype_iff_of_support_subset $ support_subset_iff'.2 hf).1 $ s.has_sum f lemma summable_of_ne_finset_zero (hf : ∀b∉s, f b = 0) : summable f := (has_sum_sum_of_ne_finset_zero hf).summable lemma has_sum_single {f : β → α} (b : β) (hf : ∀b' ≠ b, f b' = 0) : has_sum f (f b) := suffices has_sum f (∑ b' in {b}, f b'), by simpa using this, has_sum_sum_of_ne_finset_zero $ by simpa [hf] lemma has_sum_ite_eq (b : β) (a : α) : has_sum (λb', if b' = b then a else 0) a := begin convert has_sum_single b _, { exact (if_pos rfl).symm }, assume b' hb', exact if_neg hb' end lemma equiv.has_sum_iff (e : γ ≃ β) : has_sum (f ∘ e) a ↔ has_sum f a := e.injective.has_sum_iff $ by simp lemma equiv.summable_iff (e : γ ≃ β) : summable (f ∘ e) ↔ summable f := exists_congr $ λ a, e.has_sum_iff lemma summable.prod_symm {f : β × γ → α} (hf : summable f) : summable (λ p : γ × β, f p.swap) := (equiv.prod_comm γ β).summable_iff.2 hf lemma equiv.has_sum_iff_of_support {g : γ → α} (e : support f ≃ support g) (he : ∀ x : support f, g (e x) = f x) : has_sum f a ↔ has_sum g a := have (g ∘ coe) ∘ e = f ∘ coe, from funext he, by rw [← has_sum_subtype_support, ← this, e.has_sum_iff, has_sum_subtype_support] lemma has_sum_iff_has_sum_of_ne_zero_bij {g : γ → α} (i : support g → β) (hi : ∀ ⦃x y⦄, i x = i y → (x : γ) = y) (hf : support f ⊆ set.range i) (hfg : ∀ x, f (i x) = g x) : has_sum f a ↔ has_sum g a := iff.symm $ equiv.has_sum_iff_of_support (equiv.of_bijective (λ x, ⟨i x, λ hx, x.coe_prop $ hfg x ▸ hx⟩) ⟨λ x y h, subtype.ext $ hi $ subtype.ext_iff.1 h, λ y, (hf y.coe_prop).imp $ λ x hx, subtype.ext hx⟩) hfg lemma equiv.summable_iff_of_support {g : γ → α} (e : support f ≃ support g) (he : ∀ x : support f, g (e x) = f x) : summable f ↔ summable g := exists_congr $ λ _, e.has_sum_iff_of_support he protected lemma has_sum.map [add_comm_monoid γ] [topological_space γ] (hf : has_sum f a) (g : α →+ γ) (h₃ : continuous g) : has_sum (g ∘ f) (g a) := have g ∘ (λs:finset β, ∑ b in s, f b) = (λs:finset β, ∑ b in s, g (f b)), from funext $ g.map_sum _, show tendsto (λs:finset β, ∑ b in s, g (f b)) at_top (𝓝 (g a)), from this ▸ (h₃.tendsto a).comp hf /-- If `f : ℕ → α` has sum `a`, then the partial sums `∑_{i=0}^{n-1} f i` converge to `a`. -/ lemma has_sum.tendsto_sum_nat {f : ℕ → α} (h : has_sum f a) : tendsto (λn:ℕ, ∑ i in range n, f i) at_top (𝓝 a) := h.comp tendsto_finset_range lemma has_sum.unique {a₁ a₂ : α} [t2_space α] : has_sum f a₁ → has_sum f a₂ → a₁ = a₂ := tendsto_nhds_unique lemma summable.has_sum_iff_tendsto_nat [t2_space α] {f : ℕ → α} {a : α} (hf : summable f) : has_sum f a ↔ tendsto (λn:ℕ, ∑ i in range n, f i) at_top (𝓝 a) := begin refine ⟨λ h, h.tendsto_sum_nat, λ h, _⟩, rw tendsto_nhds_unique h hf.has_sum.tendsto_sum_nat, exact hf.has_sum end lemma equiv.summable_iff_of_has_sum_iff {α' : Type*} [add_comm_monoid α'] [topological_space α'] (e : α' ≃ α) {f : β → α} {g : γ → α'} (he : ∀ {a}, has_sum f (e a) ↔ has_sum g a) : summable f ↔ summable g := ⟨λ ⟨a, ha⟩, ⟨e.symm a, he.1 $ by rwa [e.apply_symm_apply]⟩, λ ⟨a, ha⟩, ⟨e a, he.2 ha⟩⟩ variable [has_continuous_add α] lemma has_sum.add (hf : has_sum f a) (hg : has_sum g b) : has_sum (λb, f b + g b) (a + b) := by simp only [has_sum, sum_add_distrib]; exact hf.add hg lemma summable.add (hf : summable f) (hg : summable g) : summable (λb, f b + g b) := (hf.has_sum.add hg.has_sum).summable lemma has_sum_sum {f : γ → β → α} {a : γ → α} {s : finset γ} : (∀i∈s, has_sum (f i) (a i)) → has_sum (λb, ∑ i in s, f i b) (∑ i in s, a i) := finset.induction_on s (by simp [has_sum_zero]) (by simp [has_sum.add] {contextual := tt}) lemma summable_sum {f : γ → β → α} {s : finset γ} (hf : ∀i∈s, summable (f i)) : summable (λb, ∑ i in s, f i b) := (has_sum_sum $ assume i hi, (hf i hi).has_sum).summable lemma has_sum.add_compl {s : set β} (ha : has_sum (f ∘ coe : s → α) a) (hb : has_sum (f ∘ coe : sᶜ → α) b) : has_sum f (a + b) := by simpa using (has_sum_subtype_iff_indicator.1 ha).add (has_sum_subtype_iff_indicator.1 hb) lemma summable.add_compl {s : set β} (hs : summable (f ∘ coe : s → α)) (hsc : summable (f ∘ coe : sᶜ → α)) : summable f := (hs.has_sum.add_compl hsc.has_sum).summable lemma has_sum.compl_add {s : set β} (ha : has_sum (f ∘ coe : sᶜ → α) a) (hb : has_sum (f ∘ coe : s → α) b) : has_sum f (a + b) := by simpa using (has_sum_subtype_iff_indicator.1 ha).add (has_sum_subtype_iff_indicator.1 hb) lemma summable.compl_add {s : set β} (hs : summable (f ∘ coe : sᶜ → α)) (hsc : summable (f ∘ coe : s → α)) : summable f := (hs.has_sum.compl_add hsc.has_sum).summable lemma has_sum.sigma [regular_space α] {γ : β → Type*} {f : (Σ b:β, γ b) → α} {g : β → α} {a : α} (ha : has_sum f a) (hf : ∀b, has_sum (λc, f ⟨b, c⟩) (g b)) : has_sum g a := begin refine (at_top_basis.tendsto_iff (closed_nhds_basis a)).mpr _, rintros s ⟨hs, hsc⟩, rcases mem_at_top_sets.mp (ha hs) with ⟨u, hu⟩, use [u.image sigma.fst, trivial], intros bs hbs, simp only [set.mem_preimage, ge_iff_le, finset.le_iff_subset] at hu, have : tendsto (λ t : finset (Σ b, γ b), ∑ p in t.filter (λ p, p.1 ∈ bs), f p) at_top (𝓝 $ ∑ b in bs, g b), { simp only [← sigma_preimage_mk, sum_sigma], refine tendsto_finset_sum _ (λ b hb, _), change tendsto (λ t, (λ t, ∑ s in t, f ⟨b, s⟩) (preimage t (sigma.mk b) _)) at_top (𝓝 (g b)), exact tendsto.comp (hf b) (tendsto_finset_preimage_at_top_at_top _) }, refine hsc.mem_of_tendsto this (eventually_at_top.2 ⟨u, λ t ht, hu _ (λ x hx, _)⟩), exact mem_filter.2 ⟨ht hx, hbs $ mem_image_of_mem _ hx⟩ end /-- If a series `f` on `β × γ` has sum `a` and for each `b` the restriction of `f` to `{b} × γ` has sum `g b`, then the series `g` has sum `a`. -/ lemma has_sum.prod_fiberwise [regular_space α] {f : β × γ → α} {g : β → α} {a : α} (ha : has_sum f a) (hf : ∀b, has_sum (λc, f (b, c)) (g b)) : has_sum g a := has_sum.sigma ((equiv.sigma_equiv_prod β γ).has_sum_iff.2 ha) hf lemma summable.sigma' [regular_space α] {γ : β → Type*} {f : (Σb:β, γ b) → α} (ha : summable f) (hf : ∀b, summable (λc, f ⟨b, c⟩)) : summable (λb, ∑'c, f ⟨b, c⟩) := (ha.has_sum.sigma (assume b, (hf b).has_sum)).summable lemma has_sum.sigma_of_has_sum [regular_space α] {γ : β → Type*} {f : (Σ b:β, γ b) → α} {g : β → α} {a : α} (ha : has_sum g a) (hf : ∀b, has_sum (λc, f ⟨b, c⟩) (g b)) (hf' : summable f) : has_sum f a := by simpa [(hf'.has_sum.sigma hf).unique ha] using hf'.has_sum end has_sum section tsum variables [add_comm_monoid α] [topological_space α] [t2_space α] variables {f g : β → α} {a a₁ a₂ : α} lemma has_sum.tsum_eq (ha : has_sum f a) : (∑'b, f b) = a := (summable.has_sum ⟨a, ha⟩).unique ha lemma summable.has_sum_iff (h : summable f) : has_sum f a ↔ (∑'b, f b) = a := iff.intro has_sum.tsum_eq (assume eq, eq ▸ h.has_sum) @[simp] lemma tsum_zero : (∑'b:β, 0:α) = 0 := has_sum_zero.tsum_eq lemma tsum_eq_sum {f : β → α} {s : finset β} (hf : ∀b∉s, f b = 0) : (∑'b, f b) = ∑ b in s, f b := (has_sum_sum_of_ne_finset_zero hf).tsum_eq lemma tsum_fintype [fintype β] (f : β → α) : (∑'b, f b) = ∑ b, f b := (has_sum_fintype f).tsum_eq @[simp] lemma finset.tsum_subtype (s : finset β) (f : β → α) : (∑'x : {x // x ∈ s}, f x) = ∑ x in s, f x := (s.has_sum f).tsum_eq lemma tsum_eq_single {f : β → α} (b : β) (hf : ∀b' ≠ b, f b' = 0) : (∑'b, f b) = f b := (has_sum_single b hf).tsum_eq @[simp] lemma tsum_ite_eq (b : β) (a : α) : (∑'b', if b' = b then a else 0) = a := (has_sum_ite_eq b a).tsum_eq lemma equiv.tsum_eq_tsum_of_has_sum_iff_has_sum {α' : Type*} [add_comm_monoid α'] [topological_space α'] (e : α' ≃ α) (h0 : e 0 = 0) {f : β → α} {g : γ → α'} (h : ∀ {a}, has_sum f (e a) ↔ has_sum g a) : (∑' b, f b) = e (∑' c, g c) := by_cases (assume : summable g, (h.mpr this.has_sum).tsum_eq) (assume hg : ¬ summable g, have hf : ¬ summable f, from mt (e.summable_iff_of_has_sum_iff @h).1 hg, by simp [tsum, hf, hg, h0]) lemma tsum_eq_tsum_of_has_sum_iff_has_sum {f : β → α} {g : γ → α} (h : ∀{a}, has_sum f a ↔ has_sum g a) : (∑'b, f b) = (∑'c, g c) := (equiv.refl α).tsum_eq_tsum_of_has_sum_iff_has_sum rfl @h lemma equiv.tsum_eq (j : γ ≃ β) (f : β → α) : (∑'c, f (j c)) = (∑'b, f b) := tsum_eq_tsum_of_has_sum_iff_has_sum $ λ a, j.has_sum_iff lemma equiv.tsum_eq_tsum_of_support {f : β → α} {g : γ → α} (e : support f ≃ support g) (he : ∀ x, g (e x) = f x) : (∑' x, f x) = ∑' y, g y := tsum_eq_tsum_of_has_sum_iff_has_sum $ λ _, e.has_sum_iff_of_support he lemma tsum_eq_tsum_of_ne_zero_bij {g : γ → α} (i : support g → β) (hi : ∀ ⦃x y⦄, i x = i y → (x : γ) = y) (hf : support f ⊆ set.range i) (hfg : ∀ x, f (i x) = g x) : (∑' x, f x) = ∑' y, g y := tsum_eq_tsum_of_has_sum_iff_has_sum $ λ _, has_sum_iff_has_sum_of_ne_zero_bij i hi hf hfg lemma tsum_subtype (s : set β) (f : β → α) : (∑' x : s, f x) = ∑' x, s.indicator f x := tsum_eq_tsum_of_has_sum_iff_has_sum $ λ _, has_sum_subtype_iff_indicator section has_continuous_add variable [has_continuous_add α] lemma tsum_add (hf : summable f) (hg : summable g) : (∑'b, f b + g b) = (∑'b, f b) + (∑'b, g b) := (hf.has_sum.add hg.has_sum).tsum_eq lemma tsum_sum {f : γ → β → α} {s : finset γ} (hf : ∀i∈s, summable (f i)) : (∑'b, ∑ i in s, f i b) = ∑ i in s, ∑'b, f i b := (has_sum_sum $ assume i hi, (hf i hi).has_sum).tsum_eq lemma tsum_sigma' [regular_space α] {γ : β → Type*} {f : (Σb:β, γ b) → α} (h₁ : ∀b, summable (λc, f ⟨b, c⟩)) (h₂ : summable f) : (∑'p, f p) = (∑'b c, f ⟨b, c⟩) := (h₂.has_sum.sigma (assume b, (h₁ b).has_sum)).tsum_eq.symm lemma tsum_prod' [regular_space α] {f : β × γ → α} (h : summable f) (h₁ : ∀b, summable (λc, f (b, c))) : (∑'p, f p) = (∑'b c, f (b, c)) := (h.has_sum.prod_fiberwise (assume b, (h₁ b).has_sum)).tsum_eq.symm lemma tsum_comm' [regular_space α] {f : β → γ → α} (h : summable (function.uncurry f)) (h₁ : ∀b, summable (f b)) (h₂ : ∀ c, summable (λ b, f b c)) : (∑' c b, f b c) = (∑' b c, f b c) := begin erw [← tsum_prod' h h₁, ← tsum_prod' h.prod_symm h₂, ← (equiv.prod_comm β γ).tsum_eq], refl, assumption end end has_continuous_add section encodable open encodable variable [encodable γ] /-- You can compute a sum over an encodably type by summing over the natural numbers and taking a supremum. This is useful for outer measures. -/ theorem tsum_supr_decode2 [complete_lattice β] (m : β → α) (m0 : m ⊥ = 0) (s : γ → β) : (∑' i : ℕ, m (⨆ b ∈ decode2 γ i, s b)) = (∑' b : γ, m (s b)) := begin have H : ∀ n, m (⨆ b ∈ decode2 γ n, s b) ≠ 0 → (decode2 γ n).is_some, { intros n h, cases decode2 γ n with b, { refine (h $ by simp [m0]).elim }, { exact rfl } }, symmetry, refine tsum_eq_tsum_of_ne_zero_bij (λ a, option.get (H a.1 a.2)) _ _ _, { rintros ⟨m, hm⟩ ⟨n, hn⟩ e, have := mem_decode2.1 (option.get_mem (H n hn)), rwa [← e, mem_decode2.1 (option.get_mem (H m hm))] at this }, { intros b h, refine ⟨⟨encode b, _⟩, _⟩, { simp only [mem_support, encodek2] at h ⊢, convert h, simp [set.ext_iff, encodek2] }, { exact option.get_of_mem _ (encodek2 _) } }, { rintros ⟨n, h⟩, dsimp only [subtype.coe_mk], transitivity, swap, rw [show decode2 γ n = _, from option.get_mem (H n h)], congr, simp [ext_iff, -option.some_get] } end /-- `tsum_supr_decode2` specialized to the complete lattice of sets. -/ theorem tsum_Union_decode2 (m : set β → α) (m0 : m ∅ = 0) (s : γ → set β) : (∑' i, m (⋃ b ∈ decode2 γ i, s b)) = (∑' b, m (s b)) := tsum_supr_decode2 m m0 s /-! Some properties about measure-like functions. These could also be functions defined on complete sublattices of sets, with the property that they are countably sub-additive. `R` will probably be instantiated with `(≤)` in all applications. -/ /-- If a function is countably sub-additive then it is sub-additive on encodable types -/ theorem rel_supr_tsum [complete_lattice β] (m : β → α) (m0 : m ⊥ = 0) (R : α → α → Prop) (m_supr : ∀(s : ℕ → β), R (m (⨆ i, s i)) (∑' i, m (s i))) (s : γ → β) : R (m (⨆ b : γ, s b)) (∑' b : γ, m (s b)) := by { rw [← supr_decode2, ← tsum_supr_decode2 _ m0 s], exact m_supr _ } /-- If a function is countably sub-additive then it is sub-additive on finite sets -/ theorem rel_supr_sum [complete_lattice β] (m : β → α) (m0 : m ⊥ = 0) (R : α → α → Prop) (m_supr : ∀(s : ℕ → β), R (m (⨆ i, s i)) (∑' i, m (s i))) (s : δ → β) (t : finset δ) : R (m (⨆ d ∈ t, s d)) (∑ d in t, m (s d)) := by { cases t.nonempty_encodable, rw [supr_subtype'], convert rel_supr_tsum m m0 R m_supr _, rw [← finset.tsum_subtype], assumption } /-- If a function is countably sub-additive then it is binary sub-additive -/ theorem rel_sup_add [complete_lattice β] (m : β → α) (m0 : m ⊥ = 0) (R : α → α → Prop) (m_supr : ∀(s : ℕ → β), R (m (⨆ i, s i)) (∑' i, m (s i))) (s₁ s₂ : β) : R (m (s₁ ⊔ s₂)) (m s₁ + m s₂) := begin convert rel_supr_tsum m m0 R m_supr (λ b, cond b s₁ s₂), { simp only [supr_bool_eq, cond] }, { rw [tsum_fintype, fintype.sum_bool, cond, cond] } end end encodable end tsum section topological_group variables [add_comm_group α] [topological_space α] [topological_add_group α] variables {f g : β → α} {a a₁ a₂ : α} -- `by simpa using` speeds up elaboration. Why? lemma has_sum.neg (h : has_sum f a) : has_sum (λb, - f b) (- a) := by simpa only using h.map (-add_monoid_hom.id α) continuous_neg lemma summable.neg (hf : summable f) : summable (λb, - f b) := hf.has_sum.neg.summable lemma has_sum.sub (hf : has_sum f a₁) (hg : has_sum g a₂) : has_sum (λb, f b - g b) (a₁ - a₂) := by { simp [sub_eq_add_neg], exact hf.add hg.neg } lemma summable.sub (hf : summable f) (hg : summable g) : summable (λb, f b - g b) := (hf.has_sum.sub hg.has_sum).summable lemma has_sum.has_sum_compl_iff {s : set β} (hf : has_sum (f ∘ coe : s → α) a₁) : has_sum (f ∘ coe : sᶜ → α) a₂ ↔ has_sum f (a₁ + a₂) := begin refine ⟨λ h, hf.add_compl h, λ h, _⟩, rw [has_sum_subtype_iff_indicator] at hf ⊢, rw [set.indicator_compl], simpa only [add_sub_cancel'] using h.sub hf end lemma has_sum.has_sum_iff_compl {s : set β} (hf : has_sum (f ∘ coe : s → α) a₁) : has_sum f a₂ ↔ has_sum (f ∘ coe : sᶜ → α) (a₂ - a₁) := iff.symm $ hf.has_sum_compl_iff.trans $ by rw [add_sub_cancel'_right] lemma summable.summable_compl_iff {s : set β} (hf : summable (f ∘ coe : s → α)) : summable (f ∘ coe : sᶜ → α) ↔ summable f := ⟨λ ⟨a, ha⟩, (hf.has_sum.has_sum_compl_iff.1 ha).summable, λ ⟨a, ha⟩, (hf.has_sum.has_sum_iff_compl.1 ha).summable⟩ protected lemma finset.has_sum_compl_iff (s : finset β) : has_sum (λ x : {x // x ∉ s}, f x) a ↔ has_sum f (a + ∑ i in s, f i) := (s.has_sum f).has_sum_compl_iff.trans $ by rw [add_comm] protected lemma finset.has_sum_iff_compl (s : finset β) : has_sum f a ↔ has_sum (λ x : {x // x ∉ s}, f x) (a - ∑ i in s, f i) := (s.has_sum f).has_sum_iff_compl protected lemma finset.summable_compl_iff (s : finset β) : summable (λ x : {x // x ∉ s}, f x) ↔ summable f := (s.summable f).summable_compl_iff lemma set.finite.summable_compl_iff {s : set β} (hs : s.finite) : summable (f ∘ coe : sᶜ → α) ↔ summable f := (hs.summable f).summable_compl_iff section tsum variables [t2_space α] lemma tsum_neg (hf : summable f) : (∑'b, - f b) = - (∑'b, f b) := hf.has_sum.neg.tsum_eq lemma tsum_sub (hf : summable f) (hg : summable g) : (∑'b, f b - g b) = (∑'b, f b) - (∑'b, g b) := (hf.has_sum.sub hg.has_sum).tsum_eq lemma tsum_add_tsum_compl {s : set β} (hs : summable (f ∘ coe : s → α)) (hsc : summable (f ∘ coe : sᶜ → α)) : (∑' x : s, f x) + (∑' x : sᶜ, f x) = ∑' x, f x := (hs.has_sum.add_compl hsc.has_sum).tsum_eq.symm lemma sum_add_tsum_compl {s : finset β} (hf : summable f) : (∑ x in s, f x) + (∑' x : (↑s : set β)ᶜ, f x) = ∑' x, f x := ((s.has_sum f).add_compl (s.summable_compl_iff.2 hf).has_sum).tsum_eq.symm end tsum /-! ### Sums on subtypes If `s` is a finset of `α`, we show that the summability of `f` in the whole space and on the subtype `univ - s` are equivalent, and relate their sums. For a function defined on `ℕ`, we deduce the formula `(∑ i in range k, f i) + (∑' i, f (i + k)) = (∑' i, f i)`, in `sum_add_tsum_nat_add`. -/ section subtype variables {s : finset β} lemma has_sum_nat_add_iff {f : ℕ → α} (k : ℕ) {a : α} : has_sum (λ n, f (n + k)) a ↔ has_sum f (a + ∑ i in range k, f i) := begin refine iff.trans _ ((range k).has_sum_compl_iff), rw [← (not_mem_range_equiv k).symm.has_sum_iff], refl end lemma summable_nat_add_iff {f : ℕ → α} (k : ℕ) : summable (λ n, f (n + k)) ↔ summable f := iff.symm $ (equiv.add_right (∑ i in range k, f i)).summable_iff_of_has_sum_iff $ λ a, (has_sum_nat_add_iff k).symm lemma has_sum_nat_add_iff' {f : ℕ → α} (k : ℕ) {a : α} : has_sum (λ n, f (n + k)) (a - ∑ i in range k, f i) ↔ has_sum f a := by simp [has_sum_nat_add_iff] lemma sum_add_tsum_nat_add [t2_space α] {f : ℕ → α} (k : ℕ) (h : summable f) : (∑ i in range k, f i) + (∑' i, f (i + k)) = (∑' i, f i) := by simpa [add_comm] using ((has_sum_nat_add_iff k).1 ((summable_nat_add_iff k).2 h).has_sum).unique h.has_sum lemma tsum_eq_zero_add [t2_space α] {f : ℕ → α} (hf : summable f) : (∑'b, f b) = f 0 + (∑'b, f (b + 1)) := by simpa only [range_one, sum_singleton] using (sum_add_tsum_nat_add 1 hf).symm end subtype end topological_group section topological_semiring variables [semiring α] [topological_space α] [topological_semiring α] variables {f g : β → α} {a a₁ a₂ : α} lemma has_sum.mul_left (a₂) (h : has_sum f a₁) : has_sum (λb, a₂ * f b) (a₂ * a₁) := by simpa only using h.map (add_monoid_hom.mul_left a₂) (continuous_const.mul continuous_id) lemma has_sum.mul_right (a₂) (hf : has_sum f a₁) : has_sum (λb, f b * a₂) (a₁ * a₂) := by simpa only using hf.map (add_monoid_hom.mul_right a₂) (continuous_id.mul continuous_const) lemma summable.mul_left (a) (hf : summable f) : summable (λb, a * f b) := (hf.has_sum.mul_left _).summable lemma summable.mul_right (a) (hf : summable f) : summable (λb, f b * a) := (hf.has_sum.mul_right _).summable section tsum variables [t2_space α] lemma tsum_mul_left (a) (hf : summable f) : (∑'b, a * f b) = a * (∑'b, f b) := (hf.has_sum.mul_left _).tsum_eq lemma tsum_mul_right (a) (hf : summable f) : (∑'b, f b * a) = (∑'b, f b) * a := (hf.has_sum.mul_right _).tsum_eq end tsum end topological_semiring section division_ring variables [division_ring α] [topological_space α] [topological_semiring α] {f g : β → α} {a a₁ a₂ : α} lemma has_sum_mul_left_iff (h : a₂ ≠ 0) : has_sum f a₁ ↔ has_sum (λb, a₂ * f b) (a₂ * a₁) := ⟨has_sum.mul_left _, λ H, by simpa only [inv_mul_cancel_left' h] using H.mul_left a₂⁻¹⟩ lemma has_sum_mul_right_iff (h : a₂ ≠ 0) : has_sum f a₁ ↔ has_sum (λb, f b * a₂) (a₁ * a₂) := ⟨has_sum.mul_right _, λ H, by simpa only [mul_inv_cancel_right' h] using H.mul_right a₂⁻¹⟩ lemma summable_mul_left_iff (h : a ≠ 0) : summable f ↔ summable (λb, a * f b) := ⟨λ H, H.mul_left _, λ H, by simpa only [inv_mul_cancel_left' h] using H.mul_left a⁻¹⟩ lemma summable_mul_right_iff (h : a ≠ 0) : summable f ↔ summable (λb, f b * a) := ⟨λ H, H.mul_right _, λ H, by simpa only [mul_inv_cancel_right' h] using H.mul_right a⁻¹⟩ end division_ring section order_topology variables [ordered_add_comm_monoid α] [topological_space α] [order_closed_topology α] variables {f g : β → α} {a a₁ a₂ : α} lemma has_sum_le (h : ∀b, f b ≤ g b) (hf : has_sum f a₁) (hg : has_sum g a₂) : a₁ ≤ a₂ := le_of_tendsto_of_tendsto' hf hg $ assume s, sum_le_sum $ assume b _, h b lemma has_sum_le_inj {g : γ → α} (i : β → γ) (hi : injective i) (hs : ∀c∉set.range i, 0 ≤ g c) (h : ∀b, f b ≤ g (i b)) (hf : has_sum f a₁) (hg : has_sum g a₂) : a₁ ≤ a₂ := have has_sum (λc, (partial_inv i c).cases_on' 0 f) a₁, begin refine (has_sum_iff_has_sum_of_ne_zero_bij (i ∘ coe) _ _ _).2 hf, { exact assume c₁ c₂ eq, hi eq }, { intros c hc, rw [mem_support] at hc, cases eq : partial_inv i c with b; rw eq at hc, { contradiction }, { rw [partial_inv_of_injective hi] at eq, exact ⟨⟨b, hc⟩, eq⟩ } }, { assume c, simp [partial_inv_left hi, option.cases_on'] } end, begin refine has_sum_le (assume c, _) this hg, by_cases c ∈ set.range i, { rcases h with ⟨b, rfl⟩, rw [partial_inv_left hi, option.cases_on'], exact h _ }, { have : partial_inv i c = none := dif_neg h, rw [this, option.cases_on'], exact hs _ h } end lemma tsum_le_tsum_of_inj {g : γ → α} (i : β → γ) (hi : injective i) (hs : ∀c∉set.range i, 0 ≤ g c) (h : ∀b, f b ≤ g (i b)) (hf : summable f) (hg : summable g) : tsum f ≤ tsum g := has_sum_le_inj i hi hs h hf.has_sum hg.has_sum lemma sum_le_has_sum {f : β → α} (s : finset β) (hs : ∀ b∉s, 0 ≤ f b) (hf : has_sum f a) : ∑ b in s, f b ≤ a := ge_of_tendsto hf (eventually_at_top.2 ⟨s, λ t hst, sum_le_sum_of_subset_of_nonneg hst $ λ b hbt hbs, hs b hbs⟩) lemma sum_le_tsum {f : β → α} (s : finset β) (hs : ∀ b∉s, 0 ≤ f b) (hf : summable f) : ∑ b in s, f b ≤ tsum f := sum_le_has_sum s hs hf.has_sum lemma tsum_le_tsum (h : ∀b, f b ≤ g b) (hf : summable f) (hg : summable g) : (∑'b, f b) ≤ (∑'b, g b) := has_sum_le h hf.has_sum hg.has_sum lemma tsum_nonneg (h : ∀ b, 0 ≤ g b) : 0 ≤ (∑'b, g b) := begin by_cases hg : summable g, { simpa using tsum_le_tsum h summable_zero hg }, { simp [tsum_eq_zero_of_not_summable hg] } end lemma tsum_nonpos (h : ∀ b, f b ≤ 0) : (∑'b, f b) ≤ 0 := begin by_cases hf : summable f, { simpa using tsum_le_tsum h hf summable_zero}, { simp [tsum_eq_zero_of_not_summable hf] } end end order_topology section uniform_group variables [add_comm_group α] [uniform_space α] variables {f g : β → α} {a a₁ a₂ : α} lemma summable_iff_cauchy_seq_finset [complete_space α] : summable f ↔ cauchy_seq (λ (s : finset β), ∑ b in s, f b) := cauchy_map_iff_exists_tendsto.symm variable [uniform_add_group α] lemma cauchy_seq_finset_iff_vanishing : cauchy_seq (λ (s : finset β), ∑ b in s, f b) ↔ ∀ e ∈ 𝓝 (0:α), (∃s:finset β, ∀t, disjoint t s → ∑ b in t, f b ∈ e) := begin simp only [cauchy_seq, cauchy_map_iff, and_iff_right at_top_ne_bot, prod_at_top_at_top_eq, uniformity_eq_comap_nhds_zero α, tendsto_comap_iff, (∘)], rw [tendsto_at_top' (_ : finset β × finset β → α)], split, { assume h e he, rcases h e he with ⟨⟨s₁, s₂⟩, h⟩, use [s₁ ∪ s₂], assume t ht, specialize h (s₁ ∪ s₂, (s₁ ∪ s₂) ∪ t) ⟨le_sup_left, le_sup_left_of_le le_sup_right⟩, simpa only [finset.sum_union ht.symm, add_sub_cancel'] using h }, { assume h e he, rcases exists_nhds_half_neg he with ⟨d, hd, hde⟩, rcases h d hd with ⟨s, h⟩, use [(s, s)], rintros ⟨t₁, t₂⟩ ⟨ht₁, ht₂⟩, have : ∑ b in t₂, f b - ∑ b in t₁, f b = ∑ b in t₂ \ s, f b - ∑ b in t₁ \ s, f b, { simp only [(finset.sum_sdiff ht₁).symm, (finset.sum_sdiff ht₂).symm, add_sub_add_right_eq_sub] }, simp only [this], exact hde _ (h _ finset.sdiff_disjoint) _ (h _ finset.sdiff_disjoint) } end variable [complete_space α] lemma summable_iff_vanishing : summable f ↔ ∀ e ∈ 𝓝 (0:α), (∃s:finset β, ∀t, disjoint t s → ∑ b in t, f b ∈ e) := by rw [summable_iff_cauchy_seq_finset, cauchy_seq_finset_iff_vanishing] /- TODO: generalize to monoid with a uniform continuous subtraction operator: `(a + b) - b = a` -/ lemma summable.summable_of_eq_zero_or_self (hf : summable f) (h : ∀b, g b = 0 ∨ g b = f b) : summable g := summable_iff_vanishing.2 $ assume e he, let ⟨s, hs⟩ := summable_iff_vanishing.1 hf e he in ⟨s, assume t ht, have eq : ∑ b in t.filter (λb, g b = f b), f b = ∑ b in t, g b := calc ∑ b in t.filter (λb, g b = f b), f b = ∑ b in t.filter (λb, g b = f b), g b : finset.sum_congr rfl (assume b hb, (finset.mem_filter.1 hb).2.symm) ... = ∑ b in t, g b : begin refine finset.sum_subset (finset.filter_subset _) _, assume b hbt hb, simp only [(∉), finset.mem_filter, and_iff_right hbt] at hb, exact (h b).resolve_right hb end, eq ▸ hs _ $ finset.disjoint_of_subset_left (finset.filter_subset _) ht⟩ protected lemma summable.indicator (hf : summable f) (s : set β) : summable (s.indicator f) := hf.summable_of_eq_zero_or_self $ λ b, if hb : b ∈ s then or.inr (set.indicator_of_mem hb _) else or.inl (set.indicator_of_not_mem hb _) lemma summable.comp_injective {i : γ → β} (hf : summable f) (hi : injective i) : summable (f ∘ i) := begin simpa only [set.indicator_range_comp] using (hi.summable_iff _).2 (hf.indicator (set.range i)), exact λ x hx, set.indicator_of_not_mem hx _ end lemma summable.subtype (hf : summable f) (s : set β) : summable (f ∘ coe : s → α) := hf.comp_injective subtype.coe_injective lemma summable.sigma_factor {γ : β → Type*} {f : (Σb:β, γ b) → α} (ha : summable f) (b : β) : summable (λc, f ⟨b, c⟩) := ha.comp_injective sigma_mk_injective lemma summable.sigma [regular_space α] {γ : β → Type*} {f : (Σb:β, γ b) → α} (ha : summable f) : summable (λb, ∑'c, f ⟨b, c⟩) := ha.sigma' (λ b, ha.sigma_factor b) lemma summable.prod_factor {f : β × γ → α} (h : summable f) (b : β) : summable (λ c, f (b, c)) := h.comp_injective $ λ c₁ c₂ h, (prod.ext_iff.1 h).2 lemma tsum_sigma [regular_space α] {γ : β → Type*} {f : (Σb:β, γ b) → α} (ha : summable f) : (∑'p, f p) = (∑'b c, f ⟨b, c⟩) := tsum_sigma' (λ b, ha.sigma_factor b) ha lemma tsum_prod [regular_space α] {f : β × γ → α} (h : summable f) : (∑'p, f p) = (∑'b c, f ⟨b, c⟩) := tsum_prod' h h.prod_factor lemma tsum_comm [regular_space α] {f : β → γ → α} (h : summable (function.uncurry f)) : (∑' c b, f b c) = (∑' b c, f b c) := tsum_comm' h h.prod_factor h.prod_symm.prod_factor end uniform_group section cauchy_seq open finset.Ico filter /-- If the extended distance between consequent points of a sequence is estimated by a summable series of `nnreal`s, then the original sequence is a Cauchy sequence. -/ lemma cauchy_seq_of_edist_le_of_summable [emetric_space α] {f : ℕ → α} (d : ℕ → nnreal) (hf : ∀ n, edist (f n) (f n.succ) ≤ d n) (hd : summable d) : cauchy_seq f := begin refine emetric.cauchy_seq_iff_nnreal.2 (λ ε εpos, _), -- Actually we need partial sums of `d` to be a Cauchy sequence replace hd : cauchy_seq (λ (n : ℕ), ∑ x in range n, d x) := let ⟨_, H⟩ := hd in cauchy_seq_of_tendsto_nhds _ H.tendsto_sum_nat, -- Now we take the same `N` as in one of the definitions of a Cauchy sequence refine (metric.cauchy_seq_iff'.1 hd ε (nnreal.coe_pos.2 εpos)).imp (λ N hN n hn, _), have hsum := hN n hn, -- We simplify the known inequality rw [dist_nndist, nnreal.nndist_eq, ← sum_range_add_sum_Ico _ hn, nnreal.add_sub_cancel'] at hsum, norm_cast at hsum, replace hsum := lt_of_le_of_lt (le_max_left _ _) hsum, rw edist_comm, -- Then use `hf` to simplify the goal to the same form apply lt_of_le_of_lt (edist_le_Ico_sum_of_edist_le hn (λ k _ _, hf k)), assumption_mod_cast end /-- If the distance between consequent points of a sequence is estimated by a summable series, then the original sequence is a Cauchy sequence. -/ lemma cauchy_seq_of_dist_le_of_summable [metric_space α] {f : ℕ → α} (d : ℕ → ℝ) (hf : ∀ n, dist (f n) (f n.succ) ≤ d n) (hd : summable d) : cauchy_seq f := begin refine metric.cauchy_seq_iff'.2 (λε εpos, _), replace hd : cauchy_seq (λ (n : ℕ), ∑ x in range n, d x) := let ⟨_, H⟩ := hd in cauchy_seq_of_tendsto_nhds _ H.tendsto_sum_nat, refine (metric.cauchy_seq_iff'.1 hd ε εpos).imp (λ N hN n hn, _), have hsum := hN n hn, rw [real.dist_eq, ← sum_Ico_eq_sub _ hn] at hsum, calc dist (f n) (f N) = dist (f N) (f n) : dist_comm _ _ ... ≤ ∑ x in Ico N n, d x : dist_le_Ico_sum_of_dist_le hn (λ k _ _, hf k) ... ≤ abs (∑ x in Ico N n, d x) : le_abs_self _ ... < ε : hsum end lemma cauchy_seq_of_summable_dist [metric_space α] {f : ℕ → α} (h : summable (λn, dist (f n) (f n.succ))) : cauchy_seq f := cauchy_seq_of_dist_le_of_summable _ (λ _, le_refl _) h lemma dist_le_tsum_of_dist_le_of_tendsto [metric_space α] {f : ℕ → α} (d : ℕ → ℝ) (hf : ∀ n, dist (f n) (f n.succ) ≤ d n) (hd : summable d) {a : α} (ha : tendsto f at_top (𝓝 a)) (n : ℕ) : dist (f n) a ≤ ∑' m, d (n + m) := begin refine le_of_tendsto (tendsto_const_nhds.dist ha) (eventually_at_top.2 ⟨n, λ m hnm, _⟩), refine le_trans (dist_le_Ico_sum_of_dist_le hnm (λ k _ _, hf k)) _, rw [sum_Ico_eq_sum_range], refine sum_le_tsum (range _) (λ _ _, le_trans dist_nonneg (hf _)) _, exact hd.comp_injective (add_right_injective n) end lemma dist_le_tsum_of_dist_le_of_tendsto₀ [metric_space α] {f : ℕ → α} (d : ℕ → ℝ) (hf : ∀ n, dist (f n) (f n.succ) ≤ d n) (hd : summable d) {a : α} (ha : tendsto f at_top (𝓝 a)) : dist (f 0) a ≤ tsum d := by simpa only [zero_add] using dist_le_tsum_of_dist_le_of_tendsto d hf hd ha 0 lemma dist_le_tsum_dist_of_tendsto [metric_space α] {f : ℕ → α} (h : summable (λn, dist (f n) (f n.succ))) {a : α} (ha : tendsto f at_top (𝓝 a)) (n) : dist (f n) a ≤ ∑' m, dist (f (n+m)) (f (n+m).succ) := show dist (f n) a ≤ ∑' m, (λx, dist (f x) (f x.succ)) (n + m), from dist_le_tsum_of_dist_le_of_tendsto (λ n, dist (f n) (f n.succ)) (λ _, le_refl _) h ha n lemma dist_le_tsum_dist_of_tendsto₀ [metric_space α] {f : ℕ → α} (h : summable (λn, dist (f n) (f n.succ))) {a : α} (ha : tendsto f at_top (𝓝 a)) : dist (f 0) a ≤ ∑' n, dist (f n) (f n.succ) := by simpa only [zero_add] using dist_le_tsum_dist_of_tendsto h ha 0 end cauchy_seq
e4e718b498aac399a0b6ada0e20811ad4c6121f7
9dd3f3912f7321eb58ee9aa8f21778ad6221f87c
/tests/lean/run/imp2.lean
49a8c8362d386a890c2ccdc8142828f4f0b7c458
[ "Apache-2.0" ]
permissive
bre7k30/lean
de893411bcfa7b3c5572e61b9e1c52951b310aa4
5a924699d076dab1bd5af23a8f910b433e598d7a
refs/heads/master
1,610,900,145,817
1,488,006,845,000
1,488,006,845,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
130
lean
check (λ {A : Type} (a : A), a) (10:num) set_option trace.app_builder true check (λ {A} (a : A), a) 10 check (λ a, a) (10:num)
7513f04fb4ddafd472729dd3083bc7d597ea5926
0845ae2ca02071debcfd4ac24be871236c01784f
/library/init/lean/parser/default.lean
b996bd2566b2fc5e2dada8d14fdf8feda192f6fb
[ "Apache-2.0" ]
permissive
GaloisInc/lean4
74c267eb0e900bfaa23df8de86039483ecbd60b7
228ddd5fdcd98dd4e9c009f425284e86917938aa
refs/heads/master
1,643,131,356,301
1,562,715,572,000
1,562,715,572,000
192,390,898
0
0
null
1,560,792,750,000
1,560,792,749,000
null
UTF-8
Lean
false
false
281
lean
/- Copyright (c) 2019 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Sebastian Ullrich -/ prelude import init.lean.parser.parser import init.lean.parser.level import init.lean.parser.term
7656ecedf4143441f11e81ca73309f1a171aefc0
624f6f2ae8b3b1adc5f8f67a365c51d5126be45a
/src/Init/Lean/Elab/Level.lean
611da2e1c87928b72dd75fdbe5e20f006b3eaa16
[ "Apache-2.0" ]
permissive
mhuisi/lean4
28d35a4febc2e251c7f05492e13f3b05d6f9b7af
dda44bc47f3e5d024508060dac2bcb59fd12e4c0
refs/heads/master
1,621,225,489,283
1,585,142,689,000
1,585,142,689,000
250,590,438
0
2
Apache-2.0
1,602,443,220,000
1,585,327,814,000
C
UTF-8
Lean
false
false
2,673
lean
/- Copyright (c) 2019 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ prelude import Init.Lean.Meta.LevelDefEq import Init.Lean.Elab.Exception import Init.Lean.Elab.Log namespace Lean namespace Elab namespace Level structure Context := (fileName : String) (fileMap : FileMap) (cmdPos : String.Pos) (levelNames : List Name) structure State := (ngen : NameGenerator) (mctx : MetavarContext) abbrev LevelElabM := ReaderT Context (EStateM Exception State) instance LevelElabM.MonadLog : MonadPosInfo LevelElabM := { getCmdPos := do ctx ← read; pure ctx.cmdPos, getFileMap := do ctx ← read; pure ctx.fileMap, getFileName := do ctx ← read; pure ctx.fileName, addContext := fun msg => pure msg } def mkFreshId : LevelElabM Name := do s ← get; let id := s.ngen.curr; modify $ fun s => { ngen := s.ngen.next, .. s }; pure id def mkFreshLevelMVar : LevelElabM Level := do mvarId ← mkFreshId; modify $ fun s => { mctx := s.mctx.addLevelMVarDecl mvarId, .. s}; pure $ mkLevelMVar mvarId partial def elabLevel : Syntax → LevelElabM Level | stx => do let kind := stx.getKind; if kind == `Lean.Parser.Level.paren then elabLevel (stx.getArg 1) else if kind == `Lean.Parser.Level.max then do let args := (stx.getArg 1).getArgs; lvl ← elabLevel args.back; args.foldrRangeM 0 (args.size - 1) (fun stx lvl => do arg ← elabLevel stx; pure (mkLevelMax lvl arg)) lvl else if kind == `Lean.Parser.Level.imax then do let args := (stx.getArg 1).getArgs; lvl ← elabLevel args.back; args.foldrRangeM 0 (args.size - 1) (fun stx lvl => do arg ← elabLevel stx; pure (mkLevelIMax lvl arg)) lvl else if kind == `Lean.Parser.Level.hole then do mkFreshLevelMVar else if kind == `Lean.Parser.Level.num then do match (stx.getArg 0).isNatLit? with | some val => pure (Level.ofNat val) | none => throwError stx "ill-formed universe level syntax" else if kind == `Lean.Parser.Level.ident then do let paramName := stx.getIdAt 0; ctx ← read; unless (ctx.levelNames.contains paramName) $ throwError stx ("unknown universe level " ++ paramName); pure $ mkLevelParam paramName else if kind == `Lean.Parser.Level.addLit then do lvl ← elabLevel (stx.getArg 0); match (stx.getArg 2).isNatLit? with | some val => pure (lvl.addOffset val) | none => throwError stx "ill-formed universe level syntax" else throwError stx "unexpected universe level syntax kind" end Level export Level (LevelElabM) end Elab end Lean
993dfdc727e3607c2192458a172310a5d9b6f433
432d948a4d3d242fdfb44b81c9e1b1baacd58617
/src/ring_theory/polynomial/content.lean
b024b59c3382a99c632331d6ef5f4cc452659c51
[ "Apache-2.0" ]
permissive
JLimperg/aesop3
306cc6570c556568897ed2e508c8869667252e8a
a4a116f650cc7403428e72bd2e2c4cda300fe03f
refs/heads/master
1,682,884,916,368
1,620,320,033,000
1,620,320,033,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
17,116
lean
/- Copyright (c) 2020 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import data.finset.gcd import data.polynomial import data.polynomial.erase_lead import data.polynomial.cancel_leads /-! # GCD structures on polynomials Definitions and basic results about polynomials over GCD domains, particularly their contents and primitive polynomials. ## Main Definitions Let `p : polynomial R`. - `p.content` is the `gcd` of the coefficients of `p`. - `p.is_primitive` indicates that `p.content = 1`. ## Main Results - `polynomial.content_mul`: If `p q : polynomial R`, then `(p * q).content = p.content * q.content`. - `polynomial.gcd_monoid`: The polynomial ring of a GCD domain is itself a GCD domain. -/ namespace polynomial section primitive variables {R : Type*} [comm_semiring R] /-- A polynomial is primitive when the only constant polynomials dividing it are units -/ def is_primitive (p : polynomial R) : Prop := ∀ (r : R), C r ∣ p → is_unit r lemma is_primitive_iff_is_unit_of_C_dvd {p : polynomial R} : p.is_primitive ↔ ∀ (r : R), C r ∣ p → is_unit r := iff.rfl @[simp] lemma is_primitive_one : is_primitive (1 : polynomial R) := λ r h, is_unit_C.mp (is_unit_of_dvd_one (C r) h) lemma monic.is_primitive {p : polynomial R} (hp : p.monic) : p.is_primitive := begin rintros r ⟨q, h⟩, exact is_unit_of_mul_eq_one r (q.coeff p.nat_degree) (by rwa [←coeff_C_mul, ←h]), end lemma is_primitive.ne_zero [nontrivial R] {p : polynomial R} (hp : p.is_primitive) : p ≠ 0 := begin rintro rfl, exact (hp 0 (dvd_zero (C 0))).ne_zero rfl, end end primitive variables {R : Type*} [integral_domain R] section gcd_monoid variable [gcd_monoid R] /-- `p.content` is the `gcd` of the coefficients of `p`. -/ def content (p : polynomial R) : R := (p.support).gcd p.coeff lemma content_dvd_coeff {p : polynomial R} (n : ℕ) : p.content ∣ p.coeff n := begin by_cases h : n ∈ p.support, { apply finset.gcd_dvd h }, rw [mem_support_iff, not_not] at h, rw h, apply dvd_zero, end @[simp] lemma content_C {r : R} : (C r).content = normalize r := begin rw content, by_cases h0 : r = 0, { simp [h0] }, have h : (C r).support = {0} := finsupp.support_single_ne_zero h0, simp [h], end @[simp] lemma content_zero : content (0 : polynomial R) = 0 := by rw [← C_0, content_C, normalize_zero] @[simp] lemma content_one : content (1 : polynomial R) = 1 := by rw [← C_1, content_C, normalize_one] lemma content_X_mul {p : polynomial R} : content (X * p) = content p := begin rw [content, content, finset.gcd_def, finset.gcd_def], refine congr rfl _, have h : (X * p).support = p.support.map ⟨nat.succ, nat.succ_injective⟩, { ext a, simp only [exists_prop, finset.mem_map, function.embedding.coe_fn_mk, ne.def, mem_support_iff], cases a, { simp [coeff_X_mul_zero, nat.succ_ne_zero] }, rw [mul_comm, coeff_mul_X], split, { intro h, use a, simp [h] }, { rintros ⟨b, ⟨h1, h2⟩⟩, rw ← nat.succ_injective h2, apply h1 } }, rw h, simp only [finset.map_val, function.comp_app, function.embedding.coe_fn_mk, multiset.map_map], refine congr (congr rfl _) rfl, ext a, rw mul_comm, simp [coeff_mul_X], end @[simp] lemma content_X_pow {k : ℕ} : content ((X : polynomial R) ^ k) = 1 := begin induction k with k hi, { simp }, rw [pow_succ, content_X_mul, hi] end @[simp] lemma content_X : content (X : polynomial R) = 1 := by { rw [← mul_one X, content_X_mul, content_one] } lemma content_C_mul (r : R) (p : polynomial R) : (C r * p).content = normalize r * p.content := begin by_cases h0 : r = 0, { simp [h0] }, rw content, rw content, rw ← finset.gcd_mul_left, refine congr (congr rfl _) _; ext; simp [h0, mem_support_iff] end @[simp] lemma content_monomial {r : R} {k : ℕ} : content (monomial k r) = normalize r := by { rw [single_eq_C_mul_X, content_C_mul, content_X_pow, mul_one] } lemma content_eq_zero_iff {p : polynomial R} : content p = 0 ↔ p = 0 := begin rw [content, finset.gcd_eq_zero_iff], split; intro h, { ext n, by_cases h0 : n ∈ p.support, { rw [h n h0, coeff_zero], }, { rw mem_support_iff at h0, push_neg at h0, simp [h0] } }, { intros x h0, simp [h] } end @[simp] lemma normalize_content {p : polynomial R} : normalize p.content = p.content := finset.normalize_gcd lemma content_eq_gcd_range_of_lt (p : polynomial R) (n : ℕ) (h : p.nat_degree < n) : p.content = (finset.range n).gcd p.coeff := begin apply dvd_antisymm_of_normalize_eq normalize_content finset.normalize_gcd, { rw finset.dvd_gcd_iff, intros i hi, apply content_dvd_coeff _ }, { apply finset.gcd_mono, intro i, simp only [nat.lt_succ_iff, mem_support_iff, ne.def, finset.mem_range], contrapose!, intro h1, apply coeff_eq_zero_of_nat_degree_lt (lt_of_lt_of_le h h1), } end lemma content_eq_gcd_range_succ (p : polynomial R) : p.content = (finset.range p.nat_degree.succ).gcd p.coeff := content_eq_gcd_range_of_lt _ _ (nat.lt_succ_self _) lemma content_eq_gcd_leading_coeff_content_erase_lead (p : polynomial R) : p.content = gcd_monoid.gcd p.leading_coeff (erase_lead p).content := begin by_cases h : p = 0, { simp [h] }, rw [← leading_coeff_eq_zero, leading_coeff, ← ne.def, ← mem_support_iff] at h, rw [content, ← finset.insert_erase h, finset.gcd_insert, leading_coeff, content, erase_lead_support], refine congr rfl (finset.gcd_congr rfl (λ i hi, _)), rw finset.mem_erase at hi, rw [erase_lead_coeff, if_neg hi.1], end lemma dvd_content_iff_C_dvd {p : polynomial R} {r : R} : r ∣ p.content ↔ C r ∣ p := begin rw C_dvd_iff_dvd_coeff, split, { intros h i, apply dvd_trans h (content_dvd_coeff _) }, { intro h, rw [content, finset.dvd_gcd_iff], intros i hi, apply h i } end lemma C_content_dvd (p : polynomial R) : C p.content ∣ p := dvd_content_iff_C_dvd.1 (dvd_refl _) lemma is_primitive_iff_content_eq_one {p : polynomial R} : p.is_primitive ↔ p.content = 1 := begin rw [←normalize_content, normalize_eq_one, is_primitive], simp_rw [←dvd_content_iff_C_dvd], exact ⟨λ h, h p.content (dvd_refl p.content), λ h r hdvd, is_unit_of_dvd_unit hdvd h⟩, end lemma is_primitive.content_eq_one {p : polynomial R} (hp : p.is_primitive) : p.content = 1 := is_primitive_iff_content_eq_one.mp hp open_locale classical noncomputable theory section prim_part /-- The primitive part of a polynomial `p` is the primitive polynomial gained by dividing `p` by `p.content`. If `p = 0`, then `p.prim_part = 1`. -/ def prim_part (p : polynomial R) : polynomial R := if p = 0 then 1 else classical.some (C_content_dvd p) lemma eq_C_content_mul_prim_part (p : polynomial R) : p = C p.content * p.prim_part := begin by_cases h : p = 0, { simp [h] }, rw [prim_part, if_neg h, ← classical.some_spec (C_content_dvd p)], end @[simp] lemma prim_part_zero : prim_part (0 : polynomial R) = 1 := if_pos rfl lemma is_primitive_prim_part (p : polynomial R) : p.prim_part.is_primitive := begin by_cases h : p = 0, { simp [h] }, rw ← content_eq_zero_iff at h, rw is_primitive_iff_content_eq_one, apply mul_left_cancel' h, conv_rhs { rw [p.eq_C_content_mul_prim_part, mul_one, content_C_mul, normalize_content] } end lemma content_prim_part (p : polynomial R) : p.prim_part.content = 1 := p.is_primitive_prim_part.content_eq_one lemma prim_part_ne_zero (p : polynomial R) : p.prim_part ≠ 0 := p.is_primitive_prim_part.ne_zero lemma nat_degree_prim_part (p : polynomial R) : p.prim_part.nat_degree = p.nat_degree := begin by_cases h : C p.content = 0, { rw [C_eq_zero, content_eq_zero_iff] at h, simp [h] }, conv_rhs { rw [p.eq_C_content_mul_prim_part, nat_degree_mul h p.prim_part_ne_zero, nat_degree_C, zero_add] }, end @[simp] lemma is_primitive.prim_part_eq {p : polynomial R} (hp : p.is_primitive) : p.prim_part = p := by rw [← one_mul p.prim_part, ← C_1, ← hp.content_eq_one, ← p.eq_C_content_mul_prim_part] lemma is_unit_prim_part_C (r : R) : is_unit (C r).prim_part := begin by_cases h0 : r = 0, { simp [h0] }, unfold is_unit, refine ⟨⟨C ↑(norm_unit r)⁻¹, C ↑(norm_unit r), by rw [← ring_hom.map_mul, units.inv_mul, C_1], by rw [← ring_hom.map_mul, units.mul_inv, C_1]⟩, _⟩, rw [← normalize_eq_zero, ← C_eq_zero] at h0, apply mul_left_cancel' h0, conv_rhs { rw [← content_C, ← (C r).eq_C_content_mul_prim_part], }, simp only [units.coe_mk, normalize_apply, ring_hom.map_mul], rw [mul_assoc, ← ring_hom.map_mul, units.mul_inv, C_1, mul_one], end lemma prim_part_dvd (p : polynomial R) : p.prim_part ∣ p := dvd.intro_left (C p.content) p.eq_C_content_mul_prim_part.symm end prim_part lemma gcd_content_eq_of_dvd_sub {a : R} {p q : polynomial R} (h : C a ∣ p - q) : gcd_monoid.gcd a p.content = gcd_monoid.gcd a q.content := begin rw content_eq_gcd_range_of_lt p (max p.nat_degree q.nat_degree).succ (lt_of_le_of_lt (le_max_left _ _) (nat.lt_succ_self _)), rw content_eq_gcd_range_of_lt q (max p.nat_degree q.nat_degree).succ (lt_of_le_of_lt (le_max_right _ _) (nat.lt_succ_self _)), apply finset.gcd_eq_of_dvd_sub, intros x hx, cases h with w hw, use w.coeff x, rw [← coeff_sub, hw, coeff_C_mul] end lemma content_mul_aux {p q : polynomial R} : gcd_monoid.gcd (p * q).erase_lead.content p.leading_coeff = gcd_monoid.gcd (p.erase_lead * q).content p.leading_coeff := begin rw [gcd_comm (content _) _, gcd_comm (content _) _], apply gcd_content_eq_of_dvd_sub, rw [← self_sub_C_mul_X_pow, ← self_sub_C_mul_X_pow, sub_mul, sub_sub, add_comm, sub_add, sub_sub_cancel, leading_coeff_mul, ring_hom.map_mul, mul_assoc, mul_assoc], apply dvd_sub (dvd.intro _ rfl) (dvd.intro _ rfl), end @[simp] theorem content_mul {p q : polynomial R} : (p * q).content = p.content * q.content := begin classical, suffices h : ∀ (n : ℕ) (p q : polynomial R), ((p * q).degree < n) → (p * q).content = p.content * q.content, { apply h, apply (lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 (nat.lt_succ_self _))) }, intro n, induction n with n ih, { intros p q hpq, rw [with_bot.coe_zero, nat.with_bot.lt_zero_iff, degree_eq_bot, mul_eq_zero] at hpq, rcases hpq with rfl | rfl; simp }, intros p q hpq, by_cases p0 : p = 0, { simp [p0] }, by_cases q0 : q = 0, { simp [q0] }, rw [degree_eq_nat_degree (mul_ne_zero p0 q0), with_bot.coe_lt_coe, nat.lt_succ_iff_lt_or_eq, ← with_bot.coe_lt_coe, ← degree_eq_nat_degree (mul_ne_zero p0 q0), nat_degree_mul p0 q0] at hpq, rcases hpq with hlt | heq, { apply ih _ _ hlt }, rw [← p.nat_degree_prim_part, ← q.nat_degree_prim_part, ← with_bot.coe_eq_coe, with_bot.coe_add, ← degree_eq_nat_degree p.prim_part_ne_zero, ← degree_eq_nat_degree q.prim_part_ne_zero] at heq, rw [p.eq_C_content_mul_prim_part, q.eq_C_content_mul_prim_part], suffices h : (q.prim_part * p.prim_part).content = 1, { rw [mul_assoc, content_C_mul, content_C_mul, mul_comm p.prim_part, mul_assoc, content_C_mul, content_C_mul, h, mul_one, content_prim_part, content_prim_part, mul_one, mul_one] }, rw [← normalize_content, normalize_eq_one, is_unit_iff_dvd_one, content_eq_gcd_leading_coeff_content_erase_lead, leading_coeff_mul, gcd_comm], apply dvd_trans (gcd_mul_dvd_mul_gcd _ _ _), rw [content_mul_aux, ih, content_prim_part, mul_one, gcd_comm, ← content_eq_gcd_leading_coeff_content_erase_lead, content_prim_part, one_mul, mul_comm q.prim_part, content_mul_aux, ih, content_prim_part, mul_one, gcd_comm, ← content_eq_gcd_leading_coeff_content_erase_lead, content_prim_part], { rw [← heq, degree_mul, with_bot.add_lt_add_iff_right], { apply degree_erase_lt p.prim_part_ne_zero }, { rw [bot_lt_iff_ne_bot, ne.def, degree_eq_bot], apply q.prim_part_ne_zero } }, { rw [mul_comm, ← heq, degree_mul, with_bot.add_lt_add_iff_left], { apply degree_erase_lt q.prim_part_ne_zero }, { rw [bot_lt_iff_ne_bot, ne.def, degree_eq_bot], apply p.prim_part_ne_zero } } end theorem is_primitive.mul {p q : polynomial R} (hp : p.is_primitive) (hq : q.is_primitive) : (p * q).is_primitive := by rw [is_primitive_iff_content_eq_one, content_mul, hp.content_eq_one, hq.content_eq_one, mul_one] @[simp] theorem prim_part_mul {p q : polynomial R} (h0 : p * q ≠ 0) : (p * q).prim_part = p.prim_part * q.prim_part := begin rw [ne.def, ← content_eq_zero_iff, ← C_eq_zero] at h0, apply mul_left_cancel' h0, conv_lhs { rw [← (p * q).eq_C_content_mul_prim_part, p.eq_C_content_mul_prim_part, q.eq_C_content_mul_prim_part] }, rw [content_mul, ring_hom.map_mul], ring, end lemma is_primitive.is_primitive_of_dvd {p q : polynomial R} (hp : p.is_primitive) (hdvd : q ∣ p) : q.is_primitive := begin rcases hdvd with ⟨r, rfl⟩, rw [is_primitive_iff_content_eq_one, ← normalize_content, normalize_eq_one, is_unit_iff_dvd_one], apply dvd.intro r.content, rwa [is_primitive_iff_content_eq_one, content_mul] at hp, end lemma is_primitive.dvd_prim_part_iff_dvd {p q : polynomial R} (hp : p.is_primitive) (hq : q ≠ 0) : p ∣ q.prim_part ↔ p ∣ q := begin refine ⟨λ h, dvd.trans h (dvd.intro_left _ q.eq_C_content_mul_prim_part.symm), λ h, _⟩, rcases h with ⟨r, rfl⟩, apply dvd.intro _, rw [prim_part_mul hq, hp.prim_part_eq], end theorem exists_primitive_lcm_of_is_primitive {p q : polynomial R} (hp : p.is_primitive) (hq : q.is_primitive) : ∃ r : polynomial R, r.is_primitive ∧ (∀ s : polynomial R, p ∣ s ∧ q ∣ s ↔ r ∣ s) := begin classical, have h : ∃ (n : ℕ) (r : polynomial R), r.nat_degree = n ∧ r.is_primitive ∧ p ∣ r ∧ q ∣ r := ⟨(p * q).nat_degree, p * q, rfl, hp.mul hq, dvd_mul_right _ _, dvd_mul_left _ _⟩, rcases nat.find_spec h with ⟨r, rdeg, rprim, pr, qr⟩, refine ⟨r, rprim, λ s, ⟨_, λ rs, ⟨dvd.trans pr rs, dvd.trans qr rs⟩⟩⟩, suffices hs : ∀ (n : ℕ) (s : polynomial R), s.nat_degree = n → (p ∣ s ∧ q ∣ s → r ∣ s), { apply hs s.nat_degree s rfl }, clear s, by_contra con, push_neg at con, rcases nat.find_spec con with ⟨s, sdeg, ⟨ps, qs⟩, rs⟩, have s0 : s ≠ 0, { contrapose! rs, simp [rs] }, have hs := nat.find_min' h ⟨_, s.nat_degree_prim_part, s.is_primitive_prim_part, (hp.dvd_prim_part_iff_dvd s0).2 ps, (hq.dvd_prim_part_iff_dvd s0).2 qs⟩, rw ← rdeg at hs, by_cases sC : s.nat_degree ≤ 0, { rw [eq_C_of_nat_degree_le_zero (le_trans hs sC), is_primitive_iff_content_eq_one, content_C, normalize_eq_one] at rprim, rw [eq_C_of_nat_degree_le_zero (le_trans hs sC), ← dvd_content_iff_C_dvd] at rs, apply rs rprim.dvd }, have hcancel := nat_degree_cancel_leads_lt_of_nat_degree_le_nat_degree hs (lt_of_not_ge sC), rw sdeg at hcancel, apply nat.find_min con hcancel, refine ⟨_, rfl, ⟨dvd_cancel_leads_of_dvd_of_dvd pr ps, dvd_cancel_leads_of_dvd_of_dvd qr qs⟩, λ rcs, rs _⟩, rw ← rprim.dvd_prim_part_iff_dvd s0, rw [cancel_leads, nat.sub_eq_zero_of_le hs, pow_zero, mul_one] at rcs, have h := dvd_add rcs (dvd.intro_left _ rfl), have hC0 := rprim.ne_zero, rw [ne.def, ← leading_coeff_eq_zero, ← C_eq_zero] at hC0, rw [sub_add_cancel, ← rprim.dvd_prim_part_iff_dvd (mul_ne_zero hC0 s0)] at h, rcases is_unit_prim_part_C r.leading_coeff with ⟨u, hu⟩, apply dvd.trans h (dvd_of_associated (associated.symm ⟨u, _⟩)), rw [prim_part_mul (mul_ne_zero hC0 s0), hu, mul_comm], end lemma dvd_iff_content_dvd_content_and_prim_part_dvd_prim_part {p q : polynomial R} (hq : q ≠ 0) : p ∣ q ↔ p.content ∣ q.content ∧ p.prim_part ∣ q.prim_part := begin split; intro h, { rcases h with ⟨r, rfl⟩, rw [content_mul, p.is_primitive_prim_part.dvd_prim_part_iff_dvd hq], exact ⟨dvd.intro _ rfl, dvd.trans p.prim_part_dvd (dvd.intro _ rfl)⟩ }, { rw [p.eq_C_content_mul_prim_part, q.eq_C_content_mul_prim_part], exact mul_dvd_mul (ring_hom.map_dvd C h.1) h.2 } end @[priority 100] instance gcd_monoid : gcd_monoid (polynomial R) := gcd_monoid_of_exists_lcm $ λ p q, begin rcases exists_primitive_lcm_of_is_primitive p.is_primitive_prim_part q.is_primitive_prim_part with ⟨r, rprim, hr⟩, refine ⟨C (lcm p.content q.content) * r, λ s, _⟩, by_cases hs : s = 0, { simp [hs] }, by_cases hpq : C (lcm p.content q.content) = 0, { rw [C_eq_zero, lcm_eq_zero_iff, content_eq_zero_iff, content_eq_zero_iff] at hpq, rcases hpq with hpq | hpq; simp [hpq, hs] }, iterate 3 { rw dvd_iff_content_dvd_content_and_prim_part_dvd_prim_part hs }, rw [content_mul, rprim.content_eq_one, mul_one, content_C, normalize_lcm, lcm_dvd_iff, prim_part_mul (mul_ne_zero hpq rprim.ne_zero), rprim.prim_part_eq, is_unit.mul_left_dvd _ _ _ (is_unit_prim_part_C (lcm p.content q.content)), ← hr s.prim_part], tauto, end end gcd_monoid end polynomial
e226c8acd7bf9631cb94a2ccf890a5fae550b0e4
25adb3ce35902d6e9c57e494fe055c47c9881db4
/src/classical_time.lean
4824241c3c772457934c6f3362d2fcb469d43e2c
[]
no_license
rohanrajnair/phys
fefb5e430f8e4b61c2acbaecb9d1c6702495ef87
0172c81b24bc94e2df5e32904c9f6904d8f24da7
refs/heads/master
1,673,021,045,568
1,603,474,638,000
1,603,474,638,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
465
lean
import .....math.new_affine.real_affine_space import ..metrology.dimension structure classicalTime : Type := mk :: (name : ℕ) -- name serves as unique ID for a given geometric space -- provide standard world time object def worldTime := classicalTime.mk 0 noncomputable def classicalTimeAlgebra : classicalTime → real_affine.Algebra | (classicalTime.mk n) := real_affine.Algebra.aff_space (real_affine.to_affine 1) -- Kevin: add has_to_algebra typeclass
c7ccc310c5149d98383a966ff6582fb6d08ab511
4767244035cdd124e1ce3d0c81128f8929df6163
/logic/basic.lean
ac6c8cbbedce9f5413292413d6024e1cf7a8e6d1
[ "Apache-2.0" ]
permissive
5HT/mathlib
b941fecacd31a9c5dd0abad58770084b8a1e56b1
40fa9ade2f5649569639608db5e621e5fad0cc02
refs/heads/master
1,586,978,681,358
1,546,681,764,000
1,546,681,764,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
25,383
lean
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura Theorems that require decidability hypotheses are in the namespace "decidable". Classical versions are in the namespace "classical". Note: in the presence of automation, this whole file may be unnecessary. On the other hand, maybe it is useful for writing automation. -/ import data.prod tactic.cache /- miscellany TODO: move elsewhere -/ section miscellany variables {α : Type*} {β : Type*} @[reducible] def hidden {a : α} := a def empty.elim {C : Sort*} : empty → C. instance : subsingleton empty := ⟨λa, a.elim⟩ instance : decidable_eq empty := λa, a.elim @[priority 0] instance decidable_eq_of_subsingleton {α} [subsingleton α] : decidable_eq α | a b := is_true (subsingleton.elim a b) /- Add an instance to "undo" coercion transitivity into a chain of coercions, because most simp lemmas are stated with respect to simple coercions and will not match when part of a chain. -/ @[simp] theorem coe_coe {α β γ} [has_coe α β] [has_coe_t β γ] (a : α) : (a : γ) = (a : β) := rfl @[simp] theorem coe_fn_coe_trans {α β γ} [has_coe α β] [has_coe_t_aux β γ] [has_coe_to_fun γ] (x : α) : @coe_fn α _ x = @coe_fn β _ x := rfl @[simp] theorem coe_fn_coe_base {α β} [has_coe α β] [has_coe_to_fun β] (x : α) : @coe_fn α _ x = @coe_fn β _ x := rfl @[simp] theorem coe_sort_coe_trans {α β γ} [has_coe α β] [has_coe_t_aux β γ] [has_coe_to_sort γ] (x : α) : @coe_sort α _ x = @coe_sort β _ x := rfl @[simp] theorem coe_sort_coe_base {α β} [has_coe α β] [has_coe_to_sort β] (x : α) : @coe_sort α _ x = @coe_sort β _ x := rfl /-- `pempty` is the universe-polymorphic analogue of `empty`. -/ @[derive decidable_eq] inductive {u} pempty : Sort u def pempty.elim {C : Sort*} : pempty → C. instance subsingleton_pempty : subsingleton pempty := ⟨λa, a.elim⟩ lemma congr_arg_heq {α} {β : α → Sort*} (f : ∀ a, β a) : ∀ {a₁ a₂ : α}, a₁ = a₂ → f a₁ == f a₂ | a _ rfl := heq.rfl end miscellany /- propositional connectives -/ @[simp] theorem false_ne_true : false ≠ true | h := h.symm ▸ trivial section propositional variables {a b c d : Prop} /- implies -/ theorem iff_of_eq (e : a = b) : a ↔ b := e ▸ iff.rfl theorem iff_iff_eq : (a ↔ b) ↔ a = b := ⟨propext, iff_of_eq⟩ @[simp] theorem imp_self : (a → a) ↔ true := iff_true_intro id theorem imp_intro {α β} (h : α) (h₂ : β) : α := h theorem imp_false : (a → false) ↔ ¬ a := iff.rfl theorem imp_and_distrib {α} : (α → b ∧ c) ↔ (α → b) ∧ (α → c) := ⟨λ h, ⟨λ ha, (h ha).left, λ ha, (h ha).right⟩, λ h ha, ⟨h.left ha, h.right ha⟩⟩ @[simp] theorem and_imp : (a ∧ b → c) ↔ (a → b → c) := iff.intro (λ h ha hb, h ⟨ha, hb⟩) (λ h ⟨ha, hb⟩, h ha hb) theorem iff_def : (a ↔ b) ↔ (a → b) ∧ (b → a) := iff_iff_implies_and_implies _ _ theorem iff_def' : (a ↔ b) ↔ (b → a) ∧ (a → b) := iff_def.trans and.comm @[simp] theorem imp_true_iff {α : Sort*} : (α → true) ↔ true := iff_true_intro $ λ_, trivial @[simp] theorem imp_iff_right (ha : a) : (a → b) ↔ b := ⟨λf, f ha, imp_intro⟩ /- not -/ theorem not.elim {α : Sort*} (H1 : ¬a) (H2 : a) : α := absurd H2 H1 @[reducible] theorem not.imp {a b : Prop} (H2 : ¬b) (H1 : a → b) : ¬a := mt H1 H2 theorem not_not_of_not_imp : ¬(a → b) → ¬¬a := mt not.elim theorem not_of_not_imp {α} : ¬(α → b) → ¬b := mt imp_intro theorem dec_em (p : Prop) [decidable p] : p ∨ ¬p := decidable.em p theorem by_contradiction {p} [decidable p] : (¬p → false) → p := decidable.by_contradiction @[simp] theorem not_not [decidable a] : ¬¬a ↔ a := iff.intro by_contradiction not_not_intro theorem of_not_not [decidable a] : ¬¬a → a := by_contradiction theorem of_not_imp [decidable a] (h : ¬ (a → b)) : a := by_contradiction (not_not_of_not_imp h) theorem not.imp_symm [decidable a] (h : ¬a → b) (hb : ¬b) : a := by_contradiction $ hb ∘ h theorem not_imp_comm [decidable a] [decidable b] : (¬a → b) ↔ (¬b → a) := ⟨not.imp_symm, not.imp_symm⟩ theorem imp.swap : (a → b → c) ↔ (b → a → c) := ⟨function.swap, function.swap⟩ theorem imp_not_comm : (a → ¬b) ↔ (b → ¬a) := imp.swap /- and -/ theorem not_and_of_not_left (b : Prop) : ¬a → ¬(a ∧ b) := mt and.left theorem not_and_of_not_right (a : Prop) {b : Prop} : ¬b → ¬(a ∧ b) := mt and.right theorem and.imp_left (h : a → b) : a ∧ c → b ∧ c := and.imp h id theorem and.imp_right (h : a → b) : c ∧ a → c ∧ b := and.imp id h lemma and.right_comm : (a ∧ b) ∧ c ↔ (a ∧ c) ∧ b := by simp [and.left_comm, and.comm] lemma and.rotate : a ∧ b ∧ c ↔ b ∧ c ∧ a := by simp [and.left_comm, and.comm] theorem and_not_self_iff (a : Prop) : a ∧ ¬ a ↔ false := iff.intro (assume h, (h.right) (h.left)) (assume h, h.elim) theorem not_and_self_iff (a : Prop) : ¬ a ∧ a ↔ false := iff.intro (assume ⟨hna, ha⟩, hna ha) false.elim theorem and_iff_left_of_imp {a b : Prop} (h : a → b) : (a ∧ b) ↔ a := iff.intro and.left (λ ha, ⟨ha, h ha⟩) theorem and_iff_right_of_imp {a b : Prop} (h : b → a) : (a ∧ b) ↔ b := iff.intro and.right (λ hb, ⟨h hb, hb⟩) lemma and.congr_right_iff : (a ∧ b ↔ a ∧ c) ↔ (a → (b ↔ c)) := ⟨λ h ha, by simp [ha] at h; exact h, and_congr_right⟩ /- or -/ theorem or_of_or_of_imp_of_imp (h₁ : a ∨ b) (h₂ : a → c) (h₃ : b → d) : c ∨ d := or.imp h₂ h₃ h₁ theorem or_of_or_of_imp_left (h₁ : a ∨ c) (h : a → b) : b ∨ c := or.imp_left h h₁ theorem or_of_or_of_imp_right (h₁ : c ∨ a) (h : a → b) : c ∨ b := or.imp_right h h₁ theorem or.elim3 (h : a ∨ b ∨ c) (ha : a → d) (hb : b → d) (hc : c → d) : d := or.elim h ha (assume h₂, or.elim h₂ hb hc) theorem or_imp_distrib : (a ∨ b → c) ↔ (a → c) ∧ (b → c) := ⟨assume h, ⟨assume ha, h (or.inl ha), assume hb, h (or.inr hb)⟩, assume ⟨ha, hb⟩, or.rec ha hb⟩ theorem or_iff_not_imp_left [decidable a] : a ∨ b ↔ (¬ a → b) := ⟨or.resolve_left, λ h, dite _ or.inl (or.inr ∘ h)⟩ theorem or_iff_not_imp_right [decidable b] : a ∨ b ↔ (¬ b → a) := or.comm.trans or_iff_not_imp_left theorem not_imp_not [decidable a] : (¬ a → ¬ b) ↔ (b → a) := ⟨assume h hb, by_contradiction $ assume na, h na hb, mt⟩ /- distributivity -/ theorem and_or_distrib_left : a ∧ (b ∨ c) ↔ (a ∧ b) ∨ (a ∧ c) := ⟨λ ⟨ha, hbc⟩, hbc.imp (and.intro ha) (and.intro ha), or.rec (and.imp_right or.inl) (and.imp_right or.inr)⟩ theorem or_and_distrib_right : (a ∨ b) ∧ c ↔ (a ∧ c) ∨ (b ∧ c) := (and.comm.trans and_or_distrib_left).trans (or_congr and.comm and.comm) theorem or_and_distrib_left : a ∨ (b ∧ c) ↔ (a ∨ b) ∧ (a ∨ c) := ⟨or.rec (λha, and.intro (or.inl ha) (or.inl ha)) (and.imp or.inr or.inr), and.rec $ or.rec (imp_intro ∘ or.inl) (or.imp_right ∘ and.intro)⟩ theorem and_or_distrib_right : (a ∧ b) ∨ c ↔ (a ∨ c) ∧ (b ∨ c) := (or.comm.trans or_and_distrib_left).trans (and_congr or.comm or.comm) /- iff -/ theorem iff_of_true (ha : a) (hb : b) : a ↔ b := ⟨λ_, hb, λ _, ha⟩ theorem iff_of_false (ha : ¬a) (hb : ¬b) : a ↔ b := ⟨ha.elim, hb.elim⟩ theorem iff_true_left (ha : a) : (a ↔ b) ↔ b := ⟨λ h, h.1 ha, iff_of_true ha⟩ theorem iff_true_right (ha : a) : (b ↔ a) ↔ b := iff.comm.trans (iff_true_left ha) theorem iff_false_left (ha : ¬a) : (a ↔ b) ↔ ¬b := ⟨λ h, mt h.2 ha, iff_of_false ha⟩ theorem iff_false_right (ha : ¬a) : (b ↔ a) ↔ ¬b := iff.comm.trans (iff_false_left ha) theorem not_or_of_imp [decidable a] (h : a → b) : ¬ a ∨ b := if ha : a then or.inr (h ha) else or.inl ha theorem imp_iff_not_or [decidable a] : (a → b) ↔ (¬ a ∨ b) := ⟨not_or_of_imp, or.neg_resolve_left⟩ theorem imp_or_distrib [decidable a] : (a → b ∨ c) ↔ (a → b) ∨ (a → c) := by simp [imp_iff_not_or, or.comm, or.left_comm] theorem imp_or_distrib' [decidable b] : (a → b ∨ c) ↔ (a → b) ∨ (a → c) := by by_cases b; simp [h, or_iff_right_of_imp ((∘) false.elim)] theorem not_imp_of_and_not : a ∧ ¬ b → ¬ (a → b) | ⟨ha, hb⟩ h := hb $ h ha @[simp] theorem not_imp [decidable a] : ¬(a → b) ↔ a ∧ ¬b := ⟨λ h, ⟨of_not_imp h, not_of_not_imp h⟩, not_imp_of_and_not⟩ -- for monotonicity lemma imp_imp_imp (h₀ : c → a) (h₁ : b → d) : (a → b) → (c → d) := assume (h₂ : a → b), h₁ ∘ h₂ ∘ h₀ theorem peirce (a b : Prop) [decidable a] : ((a → b) → a) → a := if ha : a then λ h, ha else λ h, h ha.elim theorem peirce' {a : Prop} (H : ∀ b : Prop, (a → b) → a) : a := H _ id theorem not_iff_not [decidable a] [decidable b] : (¬ a ↔ ¬ b) ↔ (a ↔ b) := by rw [@iff_def (¬ a), @iff_def' a]; exact and_congr not_imp_not not_imp_not theorem not_iff_comm [decidable a] [decidable b] : (¬ a ↔ b) ↔ (¬ b ↔ a) := by rw [@iff_def (¬ a), @iff_def (¬ b)]; exact and_congr not_imp_comm imp_not_comm theorem not_iff [decidable a] [decidable b] : ¬ (a ↔ b) ↔ (¬ a ↔ b) := by split; intro h; [split, skip]; intro h'; [by_contradiction,intro,skip]; try { refine h _; simp [*] }; rw [h',not_iff_self] at h; exact h theorem iff_not_comm [decidable a] [decidable b] : (a ↔ ¬ b) ↔ (b ↔ ¬ a) := by rw [@iff_def a, @iff_def b]; exact and_congr imp_not_comm not_imp_comm theorem iff_iff_and_or_not_and_not [decidable b] : (a ↔ b) ↔ (a ∧ b) ∨ (¬ a ∧ ¬ b) := by { split; intro h, { rw h; by_cases b; [left,right]; split; assumption }, { cases h with h h; cases h; split; intro; { contradiction <|> assumption } } } @[simp] theorem not_and_not_right [decidable b] : ¬(a ∧ ¬b) ↔ (a → b) := ⟨λ h ha, h.imp_symm $ and.intro ha, λ h ⟨ha, hb⟩, hb $ h ha⟩ @[inline] def decidable_of_iff (a : Prop) (h : a ↔ b) [D : decidable a] : decidable b := decidable_of_decidable_of_iff D h @[inline] def decidable_of_iff' (b : Prop) (h : a ↔ b) [D : decidable b] : decidable a := decidable_of_decidable_of_iff D h.symm def decidable_of_bool : ∀ (b : bool) (h : b ↔ a), decidable a | tt h := is_true (h.1 rfl) | ff h := is_false (mt h.2 bool.ff_ne_tt) /- de morgan's laws -/ theorem not_and_of_not_or_not (h : ¬ a ∨ ¬ b) : ¬ (a ∧ b) | ⟨ha, hb⟩ := or.elim h (absurd ha) (absurd hb) theorem not_and_distrib [decidable a] : ¬ (a ∧ b) ↔ ¬a ∨ ¬b := ⟨λ h, if ha : a then or.inr (λ hb, h ⟨ha, hb⟩) else or.inl ha, not_and_of_not_or_not⟩ theorem not_and_distrib' [decidable b] : ¬ (a ∧ b) ↔ ¬a ∨ ¬b := ⟨λ h, if hb : b then or.inl (λ ha, h ⟨ha, hb⟩) else or.inr hb, not_and_of_not_or_not⟩ @[simp] theorem not_and : ¬ (a ∧ b) ↔ (a → ¬ b) := and_imp theorem not_and' : ¬ (a ∧ b) ↔ b → ¬a := not_and.trans imp_not_comm theorem not_or_distrib : ¬ (a ∨ b) ↔ ¬ a ∧ ¬ b := ⟨λ h, ⟨λ ha, h (or.inl ha), λ hb, h (or.inr hb)⟩, λ ⟨h₁, h₂⟩ h, or.elim h h₁ h₂⟩ theorem or_iff_not_and_not [decidable a] [decidable b] : a ∨ b ↔ ¬ (¬a ∧ ¬b) := by rw [← not_or_distrib, not_not] theorem and_iff_not_or_not [decidable a] [decidable b] : a ∧ b ↔ ¬ (¬ a ∨ ¬ b) := by rw [← not_and_distrib, not_not] end propositional /- equality -/ section equality variables {α : Sort*} {a b : α} @[simp] theorem heq_iff_eq : a == b ↔ a = b := ⟨eq_of_heq, heq_of_eq⟩ theorem proof_irrel_heq {p q : Prop} (hp : p) (hq : q) : hp == hq := have p = q, from propext ⟨λ _, hq, λ _, hp⟩, by subst q; refl theorem ne_of_mem_of_not_mem {α β} [has_mem α β] {s : β} {a b : α} (h : a ∈ s) : b ∉ s → a ≠ b := mt $ λ e, e ▸ h theorem eq_equivalence : equivalence (@eq α) := ⟨eq.refl, @eq.symm _, @eq.trans _⟩ lemma heq_of_eq_mp : ∀ {α β : Sort*} {a : α} {a' : β} (e : α = β) (h₂ : (eq.mp e a) = a'), a == a' | α ._ a a' rfl h := eq.rec_on h (heq.refl _) lemma rec_heq_of_heq {β} {C : α → Sort*} {x : C a} {y : β} (eq : a = b) (h : x == y) : @eq.rec α a C x b eq == y := by subst eq; exact h end equality /- quantifiers -/ section quantifiers variables {α : Sort*} {p q : α → Prop} {b : Prop} def Exists.imp := @exists_imp_exists theorem forall_swap {α β} {p : α → β → Prop} : (∀ x y, p x y) ↔ ∀ y x, p x y := ⟨function.swap, function.swap⟩ theorem exists_swap {α β} {p : α → β → Prop} : (∃ x y, p x y) ↔ ∃ y x, p x y := ⟨λ ⟨x, y, h⟩, ⟨y, x, h⟩, λ ⟨y, x, h⟩, ⟨x, y, h⟩⟩ @[simp] theorem exists_imp_distrib : ((∃ x, p x) → b) ↔ ∀ x, p x → b := ⟨λ h x hpx, h ⟨x, hpx⟩, λ h ⟨x, hpx⟩, h x hpx⟩ --theorem forall_not_of_not_exists (h : ¬ ∃ x, p x) : ∀ x, ¬ p x := --forall_imp_of_exists_imp h theorem not_exists_of_forall_not (h : ∀ x, ¬ p x) : ¬ ∃ x, p x := exists_imp_distrib.2 h @[simp] theorem not_exists : (¬ ∃ x, p x) ↔ ∀ x, ¬ p x := exists_imp_distrib theorem not_forall_of_exists_not : (∃ x, ¬ p x) → ¬ ∀ x, p x | ⟨x, hn⟩ h := hn (h x) theorem not_forall {p : α → Prop} [decidable (∃ x, ¬ p x)] [∀ x, decidable (p x)] : (¬ ∀ x, p x) ↔ ∃ x, ¬ p x := ⟨not.imp_symm $ λ nx x, nx.imp_symm $ λ h, ⟨x, h⟩, not_forall_of_exists_not⟩ @[simp] theorem not_forall_not [decidable (∃ x, p x)] : (¬ ∀ x, ¬ p x) ↔ ∃ x, p x := by haveI := decidable_of_iff (¬ ∃ x, p x) not_exists; exact not_iff_comm.1 not_exists @[simp] theorem not_exists_not [∀ x, decidable (p x)] : (¬ ∃ x, ¬ p x) ↔ ∀ x, p x := by simp @[simp] theorem forall_true_iff : (α → true) ↔ true := iff_true_intro (λ _, trivial) -- Unfortunately this causes simp to loop sometimes, so we -- add the 2 and 3 cases as simp lemmas instead theorem forall_true_iff' (h : ∀ a, p a ↔ true) : (∀ a, p a) ↔ true := iff_true_intro (λ _, of_iff_true (h _)) @[simp] theorem forall_2_true_iff {β : α → Sort*} : (∀ a, β a → true) ↔ true := forall_true_iff' $ λ _, forall_true_iff @[simp] theorem forall_3_true_iff {β : α → Sort*} {γ : Π a, β a → Sort*} : (∀ a (b : β a), γ a b → true) ↔ true := forall_true_iff' $ λ _, forall_2_true_iff @[simp] theorem forall_const (α : Sort*) [inhabited α] : (α → b) ↔ b := ⟨λ h, h (arbitrary α), λ hb x, hb⟩ @[simp] theorem exists_const (α : Sort*) [inhabited α] : (∃ x : α, b) ↔ b := ⟨λ ⟨x, h⟩, h, λ h, ⟨arbitrary α, h⟩⟩ theorem forall_and_distrib : (∀ x, p x ∧ q x) ↔ (∀ x, p x) ∧ (∀ x, q x) := ⟨λ h, ⟨λ x, (h x).left, λ x, (h x).right⟩, λ ⟨h₁, h₂⟩ x, ⟨h₁ x, h₂ x⟩⟩ theorem exists_or_distrib : (∃ x, p x ∨ q x) ↔ (∃ x, p x) ∨ (∃ x, q x) := ⟨λ ⟨x, hpq⟩, hpq.elim (λ hpx, or.inl ⟨x, hpx⟩) (λ hqx, or.inr ⟨x, hqx⟩), λ hepq, hepq.elim (λ ⟨x, hpx⟩, ⟨x, or.inl hpx⟩) (λ ⟨x, hqx⟩, ⟨x, or.inr hqx⟩)⟩ @[simp] theorem exists_and_distrib_left {q : Prop} {p : α → Prop} : (∃x, q ∧ p x) ↔ q ∧ (∃x, p x) := ⟨λ ⟨x, hq, hp⟩, ⟨hq, x, hp⟩, λ ⟨hq, x, hp⟩, ⟨x, hq, hp⟩⟩ @[simp] theorem exists_and_distrib_right {q : Prop} {p : α → Prop} : (∃x, p x ∧ q) ↔ (∃x, p x) ∧ q := by simp [and_comm] @[simp] theorem forall_eq {a' : α} : (∀a, a = a' → p a) ↔ p a' := ⟨λ h, h a' rfl, λ h a e, e.symm ▸ h⟩ @[simp] theorem exists_eq {a' : α} : ∃ a, a = a' := ⟨_, rfl⟩ @[simp] theorem exists_eq_left {a' : α} : (∃ a, a = a' ∧ p a) ↔ p a' := ⟨λ ⟨a, e, h⟩, e ▸ h, λ h, ⟨_, rfl, h⟩⟩ @[simp] theorem exists_eq_right {a' : α} : (∃ a, p a ∧ a = a') ↔ p a' := (exists_congr $ by exact λ a, and.comm).trans exists_eq_left @[simp] theorem forall_eq' {a' : α} : (∀a, a' = a → p a) ↔ p a' := by simp [@eq_comm _ a'] @[simp] theorem exists_eq_left' {a' : α} : (∃ a, a' = a ∧ p a) ↔ p a' := by simp [@eq_comm _ a'] @[simp] theorem exists_eq_right' {a' : α} : (∃ a, p a ∧ a' = a) ↔ p a' := by simp [@eq_comm _ a'] theorem forall_or_of_or_forall (h : b ∨ ∀x, p x) (x) : b ∨ p x := h.imp_right $ λ h₂, h₂ x theorem forall_or_distrib_left {q : Prop} {p : α → Prop} [decidable q] : (∀x, q ∨ p x) ↔ q ∨ (∀x, p x) := ⟨λ h, if hq : q then or.inl hq else or.inr $ λ x, (h x).resolve_left hq, forall_or_of_or_forall⟩ @[simp] theorem exists_prop {p q : Prop} : (∃ h : p, q) ↔ p ∧ q := ⟨λ ⟨h₁, h₂⟩, ⟨h₁, h₂⟩, λ ⟨h₁, h₂⟩, ⟨h₁, h₂⟩⟩ @[simp] theorem exists_false : ¬ (∃a:α, false) := assume ⟨a, h⟩, h theorem Exists.fst {p : b → Prop} : Exists p → b | ⟨h, _⟩ := h theorem Exists.snd {p : b → Prop} : ∀ h : Exists p, p h.fst | ⟨_, h⟩ := h @[simp] theorem forall_prop_of_true {p : Prop} {q : p → Prop} (h : p) : (∀ h' : p, q h') ↔ q h := @forall_const (q h) p ⟨h⟩ @[simp] theorem exists_prop_of_true {p : Prop} {q : p → Prop} (h : p) : (∃ h' : p, q h') ↔ q h := @exists_const (q h) p ⟨h⟩ @[simp] theorem forall_prop_of_false {p : Prop} {q : p → Prop} (hn : ¬ p) : (∀ h' : p, q h') ↔ true := iff_true_intro $ λ h, hn.elim h @[simp] theorem exists_prop_of_false {p : Prop} {q : p → Prop} : ¬ p → ¬ (∃ h' : p, q h') := mt Exists.fst end quantifiers /- classical versions -/ namespace classical variables {α : Sort*} {p : α → Prop} local attribute [instance] prop_decidable protected theorem not_forall : (¬ ∀ x, p x) ↔ (∃ x, ¬ p x) := not_forall protected theorem forall_or_distrib_left {q : Prop} {p : α → Prop} : (∀x, q ∨ p x) ↔ q ∨ (∀x, p x) := forall_or_distrib_left theorem cases {p : Prop → Prop} (h1 : p true) (h2 : p false) : ∀a, p a := assume a, cases_on a h1 h2 theorem or_not {p : Prop} : p ∨ ¬ p := by_cases or.inl or.inr protected theorem or_iff_not_imp_left {p q : Prop} : p ∨ q ↔ (¬ p → q) := or_iff_not_imp_left protected theorem or_iff_not_imp_right {p q : Prop} : q ∨ p ↔ (¬ p → q) := or_iff_not_imp_right protected lemma not_not {p : Prop} : ¬¬p ↔ p := not_not /- use shortened names to avoid conflict when classical namespace is open -/ noncomputable theorem dec (p : Prop) : decidable p := by apply_instance noncomputable theorem dec_pred (p : α → Prop) : decidable_pred p := by apply_instance noncomputable theorem dec_rel (p : α → α → Prop) : decidable_rel p := by apply_instance noncomputable theorem dec_eq (α : Sort*) : decidable_eq α := by apply_instance @[elab_as_eliminator] noncomputable def {u} exists_cases {C : Sort u} (H0 : C) (H : ∀ a, p a → C) : C := if h : ∃ a, p a then H (classical.some h) (classical.some_spec h) else H0 lemma some_spec2 {α : Type*} {p : α → Prop} {h : ∃a, p a} (q : α → Prop) (hpq : ∀a, p a → q a) : q (some h) := hpq _ $ some_spec _ end classical @[elab_as_eliminator] noncomputable def {u} exists.classical_rec_on {α} {p : α → Prop} (h : ∃ a, p a) {C : Sort u} (H : ∀ a, p a → C) : C := H (classical.some h) (classical.some_spec h) /- bounded quantifiers -/ section bounded_quantifiers variables {α : Sort*} {r p q : α → Prop} {P Q : ∀ x, p x → Prop} {b : Prop} theorem bex_def : (∃ x (h : p x), q x) ↔ ∃ x, p x ∧ q x := ⟨λ ⟨x, px, qx⟩, ⟨x, px, qx⟩, λ ⟨x, px, qx⟩, ⟨x, px, qx⟩⟩ theorem bex.elim {b : Prop} : (∃ x h, P x h) → (∀ a h, P a h → b) → b | ⟨a, h₁, h₂⟩ h' := h' a h₁ h₂ theorem bex.intro (a : α) (h₁ : p a) (h₂ : P a h₁) : ∃ x (h : p x), P x h := ⟨a, h₁, h₂⟩ theorem ball_congr (H : ∀ x h, P x h ↔ Q x h) : (∀ x h, P x h) ↔ (∀ x h, Q x h) := forall_congr $ λ x, forall_congr (H x) theorem bex_congr (H : ∀ x h, P x h ↔ Q x h) : (∃ x h, P x h) ↔ (∃ x h, Q x h) := exists_congr $ λ x, exists_congr (H x) theorem ball.imp_right (H : ∀ x h, (P x h → Q x h)) (h₁ : ∀ x h, P x h) (x h) : Q x h := H _ _ $ h₁ _ _ theorem bex.imp_right (H : ∀ x h, (P x h → Q x h)) : (∃ x h, P x h) → ∃ x h, Q x h | ⟨x, h, h'⟩ := ⟨_, _, H _ _ h'⟩ theorem ball.imp_left (H : ∀ x, p x → q x) (h₁ : ∀ x, q x → r x) (x) (h : p x) : r x := h₁ _ $ H _ h theorem bex.imp_left (H : ∀ x, p x → q x) : (∃ x (_ : p x), r x) → ∃ x (_ : q x), r x | ⟨x, hp, hr⟩ := ⟨x, H _ hp, hr⟩ theorem ball_of_forall (h : ∀ x, p x) (x) (_ : q x) : p x := h x theorem forall_of_ball (H : ∀ x, p x) (h : ∀ x, p x → q x) (x) : q x := h x $ H x theorem bex_of_exists (H : ∀ x, p x) : (∃ x, q x) → ∃ x (_ : p x), q x | ⟨x, hq⟩ := ⟨x, H x, hq⟩ theorem exists_of_bex : (∃ x (_ : p x), q x) → ∃ x, q x | ⟨x, _, hq⟩ := ⟨x, hq⟩ @[simp] theorem bex_imp_distrib : ((∃ x h, P x h) → b) ↔ (∀ x h, P x h → b) := by simp theorem not_bex : (¬ ∃ x h, P x h) ↔ ∀ x h, ¬ P x h := bex_imp_distrib theorem not_ball_of_bex_not : (∃ x h, ¬ P x h) → ¬ ∀ x h, P x h | ⟨x, h, hp⟩ al := hp $ al x h theorem not_ball [decidable (∃ x h, ¬ P x h)] [∀ x h, decidable (P x h)] : (¬ ∀ x h, P x h) ↔ (∃ x h, ¬ P x h) := ⟨not.imp_symm $ λ nx x h, nx.imp_symm $ λ h', ⟨x, h, h'⟩, not_ball_of_bex_not⟩ theorem ball_true_iff (p : α → Prop) : (∀ x, p x → true) ↔ true := iff_true_intro (λ h hrx, trivial) theorem ball_and_distrib : (∀ x h, P x h ∧ Q x h) ↔ (∀ x h, P x h) ∧ (∀ x h, Q x h) := iff.trans (forall_congr $ λ x, forall_and_distrib) forall_and_distrib theorem bex_or_distrib : (∃ x h, P x h ∨ Q x h) ↔ (∃ x h, P x h) ∨ (∃ x h, Q x h) := iff.trans (exists_congr $ λ x, exists_or_distrib) exists_or_distrib end bounded_quantifiers namespace classical local attribute [instance] prop_decidable theorem not_ball {α : Sort*} {p : α → Prop} {P : Π (x : α), p x → Prop} : (¬ ∀ x h, P x h) ↔ (∃ x h, ¬ P x h) := _root_.not_ball end classical section nonempty universes u v w variables {α : Type u} {β : Type v} {γ : α → Type w} attribute [simp] nonempty_of_inhabited lemma exists_true_iff_nonempty {α : Sort*} : (∃a:α, true) ↔ nonempty α := iff.intro (λ⟨a, _⟩, ⟨a⟩) (λ⟨a⟩, ⟨a, trivial⟩) @[simp] lemma nonempty_Prop {p : Prop} : nonempty p ↔ p := iff.intro (assume ⟨h⟩, h) (assume h, ⟨h⟩) lemma not_nonempty_iff_imp_false {p : Prop} : ¬ nonempty α ↔ α → false := ⟨λ h a, h ⟨a⟩, λ h ⟨a⟩, h a⟩ @[simp] lemma nonempty_sigma : nonempty (Σa:α, γ a) ↔ (∃a:α, nonempty (γ a)) := iff.intro (assume ⟨⟨a, c⟩⟩, ⟨a, ⟨c⟩⟩) (assume ⟨a, ⟨c⟩⟩, ⟨⟨a, c⟩⟩) @[simp] lemma nonempty_subtype {α : Sort u} {p : α → Prop} : nonempty (subtype p) ↔ (∃a:α, p a) := iff.intro (assume ⟨⟨a, h⟩⟩, ⟨a, h⟩) (assume ⟨a, h⟩, ⟨⟨a, h⟩⟩) @[simp] lemma nonempty_prod : nonempty (α × β) ↔ (nonempty α ∧ nonempty β) := iff.intro (assume ⟨⟨a, b⟩⟩, ⟨⟨a⟩, ⟨b⟩⟩) (assume ⟨⟨a⟩, ⟨b⟩⟩, ⟨⟨a, b⟩⟩) @[simp] lemma nonempty_pprod {α : Sort u} {β : Sort v} : nonempty (pprod α β) ↔ (nonempty α ∧ nonempty β) := iff.intro (assume ⟨⟨a, b⟩⟩, ⟨⟨a⟩, ⟨b⟩⟩) (assume ⟨⟨a⟩, ⟨b⟩⟩, ⟨⟨a, b⟩⟩) @[simp] lemma nonempty_sum : nonempty (α ⊕ β) ↔ (nonempty α ∨ nonempty β) := iff.intro (assume ⟨h⟩, match h with sum.inl a := or.inl ⟨a⟩ | sum.inr b := or.inr ⟨b⟩ end) (assume h, match h with or.inl ⟨a⟩ := ⟨sum.inl a⟩ | or.inr ⟨b⟩ := ⟨sum.inr b⟩ end) @[simp] lemma nonempty_psum {α : Sort u} {β : Sort v} : nonempty (psum α β) ↔ (nonempty α ∨ nonempty β) := iff.intro (assume ⟨h⟩, match h with psum.inl a := or.inl ⟨a⟩ | psum.inr b := or.inr ⟨b⟩ end) (assume h, match h with or.inl ⟨a⟩ := ⟨psum.inl a⟩ | or.inr ⟨b⟩ := ⟨psum.inr b⟩ end) @[simp] lemma nonempty_psigma {α : Sort u} {β : α → Sort v} : nonempty (psigma β) ↔ (∃a:α, nonempty (β a)) := iff.intro (assume ⟨⟨a, c⟩⟩, ⟨a, ⟨c⟩⟩) (assume ⟨a, ⟨c⟩⟩, ⟨⟨a, c⟩⟩) @[simp] lemma nonempty_empty : ¬ nonempty empty := assume ⟨h⟩, h.elim @[simp] lemma nonempty_ulift : nonempty (ulift α) ↔ nonempty α := iff.intro (assume ⟨⟨a⟩⟩, ⟨a⟩) (assume ⟨a⟩, ⟨⟨a⟩⟩) @[simp] lemma nonempty_plift {α : Sort u} : nonempty (plift α) ↔ nonempty α := iff.intro (assume ⟨⟨a⟩⟩, ⟨a⟩) (assume ⟨a⟩, ⟨⟨a⟩⟩) @[simp] lemma nonempty.forall {α : Sort u} {p : nonempty α → Prop} : (∀h:nonempty α, p h) ↔ (∀a, p ⟨a⟩) := iff.intro (assume h a, h _) (assume h ⟨a⟩, h _) @[simp] lemma nonempty.exists {α : Sort u} {p : nonempty α → Prop} : (∃h:nonempty α, p h) ↔ (∃a, p ⟨a⟩) := iff.intro (assume ⟨⟨a⟩, h⟩, ⟨a, h⟩) (assume ⟨a, h⟩, ⟨⟨a⟩, h⟩) lemma classical.nonempty_pi {α : Sort u} {β : α → Sort v} : nonempty (Πa:α, β a) ↔ (∀a:α, nonempty (β a)) := iff.intro (assume ⟨f⟩ a, ⟨f a⟩) (assume f, ⟨assume a, classical.choice $ f a⟩) end nonempty
ddd9d5666efcc95b2ca593ccfc02729d01633989
55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5
/src/tactic/lint/type_classes.lean
92dac00ff84959ab2fc5381d2d04347d0b0d626f
[ "Apache-2.0" ]
permissive
dupuisf/mathlib
62de4ec6544bf3b79086afd27b6529acfaf2c1bb
8582b06b0a5d06c33ee07d0bdf7c646cae22cf36
refs/heads/master
1,669,494,854,016
1,595,692,409,000
1,595,692,409,000
272,046,630
0
0
Apache-2.0
1,592,066,143,000
1,592,066,142,000
null
UTF-8
Lean
false
false
17,277
lean
/- Copyright (c) 2020 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Robert Y. Lewis, Gabriel Ebner -/ import tactic.lint.basic /-! # Linters about type classes This file defines several linters checking the correct usage of type classes and the appropriate definition of instances: * `instance_priority` ensures that blanket instances have low priority * `has_inhabited_instances` checks that every type has an `inhabited` instance * `impossible_instance` checks that there are no instances which can never apply * `incorrect_type_class_argument` checks that only type classes are used in instance-implicit arguments * `dangerous_instance` checks for instances that generate subproblems with metavariables * `fails_quickly` checks that type class resolution finishes quickly * `has_coe_variable` checks that there is no instance of type `has_coe α t` * `inhabited_nonempty` checks whether `[inhabited α]` arguments could be generalized to `[nonempty α]` * `decidable_classical` checks propositions for `[decidable_... p]` hypotheses that are not used in the statement, and could thus be removed by using `classical` in the proof. -/ open tactic /-- Pretty prints a list of arguments of a declaration. Assumes `l` is a list of argument positions and binders (or any other element that can be pretty printed). `l` can be obtained e.g. by applying `list.indexes_values` to a list obtained by `get_pi_binders`. -/ meta def print_arguments {α} [has_to_tactic_format α] (l : list (ℕ × α)) : tactic string := do fs ← l.mmap (λ ⟨n, b⟩, (λ s, to_fmt "argument " ++ to_fmt (n+1) ++ ": " ++ s) <$> pp b), return $ fs.to_string_aux tt /-- checks whether an instance that always applies has priority ≥ 1000. -/ private meta def instance_priority (d : declaration) : tactic (option string) := do let nm := d.to_name, b ← is_instance nm, /- return `none` if `d` is not an instance -/ if ¬ b then return none else do (is_persistent, prio) ← has_attribute `instance nm, /- return `none` if `d` is has low priority -/ if prio < 1000 then return none else do let (fn, args) := d.type.pi_codomain.get_app_fn_args, cls ← get_decl fn.const_name, let (pi_args, _) := cls.type.pi_binders, guard (args.length = pi_args.length), /- List all the arguments of the class that block type-class inference from firing (if they are metavariables). These are all the arguments except instance-arguments and out-params. -/ let relevant_args := (args.zip pi_args).filter_map $ λ⟨e, ⟨_, info, tp⟩⟩, if info = binder_info.inst_implicit ∨ tp.get_app_fn.is_constant_of `out_param then none else some e, let always_applies := relevant_args.all expr.is_var ∧ relevant_args.nodup, if always_applies then return $ some "set priority below 1000" else return none /-- Certain instances always apply during type-class resolution. For example, the instance `add_comm_group.to_add_group {α} [add_comm_group α] : add_group α` applies to all type-class resolution problems of the form `add_group _`, and type-class inference will then do an exhaustive search to find a commutative group. These instances take a long time to fail. Other instances will only apply if the goal has a certain shape. For example `int.add_group : add_group ℤ` or `add_group.prod {α β} [add_group α] [add_group β] : add_group (α × β)`. Usually these instances will fail quickly, and when they apply, they are almost the desired instance. For this reason, we want the instances of the second type (that only apply in specific cases) to always have higher priority than the instances of the first type (that always apply). See also #1561. Therefore, if we create an instance that always applies, we set the priority of these instances to 100 (or something similar, which is below the default value of 1000). -/ library_note "lower instance priority" /-- Instances that always apply should be applied after instances that only apply in specific cases, see note [lower instance priority] above. Classes that use the `extends` keyword automatically generate instances that always apply. Therefore, we set the priority of these instances to 100 (or something similar, which is below the default value of 1000) using `set_option default_priority 100`. We have to put this option inside a section, so that the default priority is the default 1000 outside the section. -/ library_note "default priority" /-- A linter object for checking instance priorities of instances that always apply. This is in the default linter set. -/ @[linter] meta def linter.instance_priority : linter := { test := instance_priority, no_errors_found := "All instance priorities are good", errors_found := "DANGEROUS INSTANCE PRIORITIES. The following instances always apply, and therefore should have a priority < 1000. If you don't know what priority to choose, use priority 100. If this is an automatically generated instance (using the keywords `class` and `extends`), see note [lower instance priority] and see note [default priority] for instructions to change the priority", auto_decls := tt } /-- Reports declarations of types that do not have an associated `inhabited` instance. -/ private meta def has_inhabited_instance (d : declaration) : tactic (option string) := do tt ← pure d.is_trusted | pure none, ff ← has_attribute' `reducible d.to_name | pure none, ff ← has_attribute' `class d.to_name | pure none, (_, ty) ← mk_local_pis d.type, ty ← whnf ty, if ty = `(Prop) then pure none else do `(Sort _) ← whnf ty | pure none, insts ← attribute.get_instances `instance, insts_tys ← insts.mmap $ λ i, expr.pi_codomain <$> declaration.type <$> get_decl i, let inhabited_insts := insts_tys.filter (λ i, i.app_fn.const_name = ``inhabited ∨ i.app_fn.const_name = `unique), let inhabited_tys := inhabited_insts.map (λ i, i.app_arg.get_app_fn.const_name), if d.to_name ∈ inhabited_tys then pure none else pure "inhabited instance missing" /-- A linter for missing `inhabited` instances. -/ @[linter] meta def linter.has_inhabited_instance : linter := { test := has_inhabited_instance, auto_decls := ff, no_errors_found := "No types have missing inhabited instances", errors_found := "TYPES ARE MISSING INHABITED INSTANCES", is_fast := ff } attribute [nolint has_inhabited_instance] pempty /-- Checks whether an instance can never be applied. -/ private meta def impossible_instance (d : declaration) : tactic (option string) := do tt ← is_instance d.to_name | return none, (binders, _) ← get_pi_binders_dep d.type, let bad_arguments := binders.filter $ λ nb, nb.2.info ≠ binder_info.inst_implicit, _ :: _ ← return bad_arguments | return none, (λ s, some $ "Impossible to infer " ++ s) <$> print_arguments bad_arguments /-- A linter object for `impossible_instance`. -/ @[linter] meta def linter.impossible_instance : linter := { test := impossible_instance, auto_decls := tt, no_errors_found := "All instances are applicable", errors_found := "IMPOSSIBLE INSTANCES FOUND. These instances have an argument that cannot be found during type-class resolution, and therefore can never succeed. Either mark the arguments with square brackets (if it is a class), or don't make it an instance" } /-- Checks whether an instance can never be applied. -/ private meta def incorrect_type_class_argument (d : declaration) : tactic (option string) := do (binders, _) ← get_pi_binders d.type, let instance_arguments := binders.indexes_values $ λ b : binder, b.info = binder_info.inst_implicit, /- the head of the type should either unfold to a class, or be a local constant. A local constant is allowed, because that could be a class when applied to the proper arguments. -/ bad_arguments ← instance_arguments.mfilter (λ ⟨_, b⟩, do (_, head) ← mk_local_pis b.type, if head.get_app_fn.is_local_constant then return ff else do bnot <$> is_class head), _ :: _ ← return bad_arguments | return none, (λ s, some $ "These are not classes. " ++ s) <$> print_arguments bad_arguments /-- A linter object for `incorrect_type_class_argument`. -/ @[linter] meta def linter.incorrect_type_class_argument : linter := { test := incorrect_type_class_argument, auto_decls := tt, no_errors_found := "All declarations have correct type-class arguments", errors_found := "INCORRECT TYPE-CLASS ARGUMENTS. Some declarations have non-classes between [square brackets]" } /-- Checks whether an instance is dangerous: it creates a new type-class problem with metavariable arguments. -/ private meta def dangerous_instance (d : declaration) : tactic (option string) := do tt ← is_instance d.to_name | return none, (local_constants, target) ← mk_local_pis d.type, let instance_arguments := local_constants.indexes_values $ λ e : expr, e.local_binding_info = binder_info.inst_implicit, let bad_arguments := local_constants.indexes_values $ λ x, !target.has_local_constant x && (x.local_binding_info ≠ binder_info.inst_implicit) && instance_arguments.any (λ nb, nb.2.local_type.has_local_constant x), let bad_arguments : list (ℕ × binder) := bad_arguments.map $ λ ⟨n, e⟩, ⟨n, e.to_binder⟩, _ :: _ ← return bad_arguments | return none, (λ s, some $ "The following arguments become metavariables. " ++ s) <$> print_arguments bad_arguments /-- A linter object for `dangerous_instance`. -/ @[linter] meta def linter.dangerous_instance : linter := { test := dangerous_instance, no_errors_found := "No dangerous instances", errors_found := "DANGEROUS INSTANCES FOUND.\nThese instances are recursive, and create a new type-class problem which will have metavariables. Possible solution: remove the instance attribute or make it a local instance instead. Currently this linter does not check whether the metavariables only occur in arguments marked with `out_param`, in which case this linter gives a false positive.", auto_decls := tt } /-- Applies expression `e` to local constants, but lifts all the arguments that are `Sort`-valued to `Type`-valued sorts. -/ meta def apply_to_fresh_variables (e : expr) : tactic expr := do t ← infer_type e, (xs, b) ← mk_local_pis t, xs.mmap' $ λ x, try $ do { u ← mk_meta_univ, tx ← infer_type x, ttx ← infer_type tx, unify ttx (expr.sort u.succ) }, return $ e.app_of_list xs /-- Tests whether type-class inference search for a class will end quickly when applied to variables. This tactic succeeds if `mk_instance` succeeds quickly or fails quickly with the error message that it cannot find an instance. It fails if the tactic takes too long, or if any other error message is raised. We make sure that we apply the tactic to variables living in `Type u` instead of `Sort u`, because many instances only apply in that special case, and we do want to catch those loops. -/ meta def fails_quickly (max_steps : ℕ) (d : declaration) : tactic (option string) := do e ← mk_const d.to_name, tt ← is_class e | return none, e' ← apply_to_fresh_variables e, sum.inr msg ← retrieve_or_report_error $ tactic.try_for max_steps $ succeeds_or_fails_with_msg (mk_instance e') $ λ s, "tactic.mk_instance failed to generate instance for".is_prefix_of s | return none, return $ some $ if msg = "try_for tactic failed, timeout" then "type-class inference timed out" else msg /-- A linter object for `fails_quickly`. If we want to increase the maximum number of steps type-class inference is allowed to take, we can increase the number `3000` in the definition. As of 5 Mar 2020 the longest trace (for `is_add_hom`) takes 2900-3000 "heartbeats". -/ @[linter] meta def linter.fails_quickly : linter := { test := fails_quickly 3000, auto_decls := tt, no_errors_found := "No type-class searches timed out", errors_found := "TYPE CLASS SEARCHES TIMED OUT. For the following classes, there is an instance that causes a loop, or an excessively long search.", is_fast := ff } /-- Tests whether there is no instance of type `has_coe α t` where `α` is a variable, or `has_coe t α` where `α` does not occur in `t`. See note [use has_coe_t]. -/ private meta def has_coe_variable (d : declaration) : tactic (option string) := do tt ← is_instance d.to_name | return none, `(has_coe %%a %%b) ← return d.type.pi_codomain | return none, if a.is_var then return $ some $ "illegal instance, first argument is variable" else if b.is_var ∧ ¬ b.occurs a then return $ some $ "illegal instance, second argument is variable not occurring in first argument" else return none /-- A linter object for `has_coe_variable`. -/ @[linter] meta def linter.has_coe_variable : linter := { test := has_coe_variable, auto_decls := tt, no_errors_found := "No invalid `has_coe` instances", errors_found := "INVALID `has_coe` INSTANCES. Make the following declarations instances of the class `has_coe_t` instead of `has_coe`." } /-- Checks whether a declaration is prop-valued and takes an `inhabited _` argument that is unused elsewhere in the type. In this case, that argument can be replaced with `nonempty _`. -/ private meta def inhabited_nonempty (d : declaration) : tactic (option string) := do tt ← is_prop d.type | return none, (binders, _) ← get_pi_binders_dep d.type, let inhd_binders := binders.filter $ λ pr, pr.2.type.is_app_of `inhabited, if inhd_binders.length = 0 then return none else (λ s, some $ "The following `inhabited` instances should be `nonempty`. " ++ s) <$> print_arguments inhd_binders /-- A linter object for `inhabited_nonempty`. -/ @[linter] meta def linter.inhabited_nonempty : linter := { test := inhabited_nonempty, auto_decls := ff, no_errors_found := "No uses of `inhabited` arguments should be replaced with `nonempty`", errors_found := "USES OF `inhabited` SHOULD BE REPLACED WITH `nonempty`." } /-- Checks whether a declaration is `Prop`-valued and takes a `decidable* _` hypothesis that is unused elsewhere in the type. In this case, that hypothesis can be replaced with `classical` in the proof. -/ private meta def decidable_classical (d : declaration) : tactic (option string) := do tt ← is_prop d.type | return none, (binders, _) ← get_pi_binders_dep d.type, let deceq_binders := binders.filter $ λ pr, pr.2.type.is_app_of `decidable_eq ∨ pr.2.type.is_app_of `decidable_pred ∨ pr.2.type.is_app_of `decidable_rel ∨ pr.2.type.is_app_of `decidable, if deceq_binders.length = 0 then return none else (λ s, some $ "The following `decidable` hypotheses should be replaced with `classical` in the proof. " ++ s) <$> print_arguments deceq_binders /-- A linter object for `decidable_classical`. -/ @[linter] meta def linter.decidable_classical : linter := { test := decidable_classical, auto_decls := ff, no_errors_found := "No uses of `decidable` arguments should be replaced with `classical`", errors_found := "USES OF `decidable` SHOULD BE REPLACED WITH `classical` IN THE PROOF." } /- The file `logic/basic.lean` emphasizes the differences between what holds under classical and non-classical logic. It makes little sense to make all these lemmas classical, so we add them to the list of lemmas which are not checked by the linter `decidable_classical`. -/ attribute [nolint decidable_classical] dec_em by_contradiction not_not of_not_not of_not_imp not.imp_symm not_imp_comm or_iff_not_imp_left or_iff_not_imp_right not_imp_not not_or_of_imp imp_iff_not_or imp_or_distrib imp_or_distrib' not_imp peirce not_iff_not not_iff_comm not_iff iff_not_comm iff_iff_and_or_not_and_not not_and_not_right not_and_distrib not_and_distrib' or_iff_not_and_not and_iff_not_or_not not_forall not_forall_not forall_or_distrib_left forall_or_distrib_right not_ball private meta def has_coe_to_fun_linter (d : declaration) : tactic (option string) := retrieve $ do mk_meta_var d.type >>= set_goals ∘ pure, args ← unfreezing intros, expr.sort _ ← target | pure none, let ty : expr := (expr.const d.to_name d.univ_levels).mk_app args, some coe_fn_inst ← try_core $ to_expr ``(_root_.has_coe_to_fun %%ty) >>= mk_instance | pure none, some trans_inst@(expr.app (expr.app _ trans_inst_1) trans_inst_2) ← try_core $ to_expr ``(@_root_.coe_fn_trans %%ty _ _ _) | pure none, tt ← succeeds $ unify trans_inst coe_fn_inst transparency.reducible | pure none, set_bool_option `pp.all true, trans_inst_1 ← pp trans_inst_1, trans_inst_2 ← pp trans_inst_2, pure $ format.to_string $ "`has_coe_to_fun` instance is definitionally equal to a transitive instance composed of: " ++ trans_inst_1.group.indent 2 ++ format.line ++ "and" ++ trans_inst_2.group.indent 2 /-- Linter that checks whether `has_coe_to_fun` instances comply with Note [function coercion]. -/ @[linter] meta def linter.has_coe_to_fun : linter := { test := has_coe_to_fun_linter, auto_decls := tt, no_errors_found := "has_coe_to_fun is used correctly", errors_found := "INVALID/MISSING `has_coe_to_fun` instances. You should add a `has_coe_to_fun` instance for the following types. See Note function coercions]." }
783bfe4cf541dc014c39e14541f8562cc228cf9a
bb31430994044506fa42fd667e2d556327e18dfe
/src/linear_algebra/affine_space/independent.lean
1bd97d41439488c7062a576dfa1e6d7aeae53fc5
[ "Apache-2.0" ]
permissive
sgouezel/mathlib
0cb4e5335a2ba189fa7af96d83a377f83270e503
00638177efd1b2534fc5269363ebf42a7871df9a
refs/heads/master
1,674,527,483,042
1,673,665,568,000
1,673,665,568,000
119,598,202
0
0
null
1,517,348,647,000
1,517,348,646,000
null
UTF-8
Lean
false
false
43,925
lean
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import data.finset.sort import data.fin.vec_notation import data.sign import linear_algebra.affine_space.combination import linear_algebra.affine_space.affine_equiv import linear_algebra.basis /-! # Affine independence This file defines affinely independent families of points. ## Main definitions * `affine_independent` defines affinely independent families of points as those where no nontrivial weighted subtraction is `0`. This is proved equivalent to two other formulations: linear independence of the results of subtracting a base point in the family from the other points in the family, or any equal affine combinations having the same weights. A bundled type `simplex` is provided for finite affinely independent families of points, with an abbreviation `triangle` for the case of three points. ## References * https://en.wikipedia.org/wiki/Affine_space -/ noncomputable theory open_locale big_operators affine open function section affine_independent variables (k : Type*) {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V] variables [affine_space V P] {ι : Type*} include V /-- An indexed family is said to be affinely independent if no nontrivial weighted subtractions (where the sum of weights is 0) are 0. -/ def affine_independent (p : ι → P) : Prop := ∀ (s : finset ι) (w : ι → k), ∑ i in s, w i = 0 → s.weighted_vsub p w = (0:V) → ∀ i ∈ s, w i = 0 /-- The definition of `affine_independent`. -/ lemma affine_independent_def (p : ι → P) : affine_independent k p ↔ ∀ (s : finset ι) (w : ι → k), ∑ i in s, w i = 0 → s.weighted_vsub p w = (0 : V) → ∀ i ∈ s, w i = 0 := iff.rfl /-- A family with at most one point is affinely independent. -/ lemma affine_independent_of_subsingleton [subsingleton ι] (p : ι → P) : affine_independent k p := λ s w h hs i hi, fintype.eq_of_subsingleton_of_sum_eq h i hi /-- A family indexed by a `fintype` is affinely independent if and only if no nontrivial weighted subtractions over `finset.univ` (where the sum of the weights is 0) are 0. -/ lemma affine_independent_iff_of_fintype [fintype ι] (p : ι → P) : affine_independent k p ↔ ∀ w : ι → k, ∑ i, w i = 0 → finset.univ.weighted_vsub p w = (0 : V) → ∀ i, w i = 0 := begin split, { exact λ h w hw hs i, h finset.univ w hw hs i (finset.mem_univ _) }, { intros h s w hw hs i hi, rw finset.weighted_vsub_indicator_subset _ _ (finset.subset_univ s) at hs, rw set.sum_indicator_subset _ (finset.subset_univ s) at hw, replace h := h ((↑s : set ι).indicator w) hw hs i, simpa [hi] using h } end /-- A family is affinely independent if and only if the differences from a base point in that family are linearly independent. -/ lemma affine_independent_iff_linear_independent_vsub (p : ι → P) (i1 : ι) : affine_independent k p ↔ linear_independent k (λ i : {x // x ≠ i1}, (p i -ᵥ p i1 : V)) := begin classical, split, { intro h, rw linear_independent_iff', intros s g hg i hi, set f : ι → k := λ x, if hx : x = i1 then -∑ y in s, g y else g ⟨x, hx⟩ with hfdef, let s2 : finset ι := insert i1 (s.map (embedding.subtype _)), have hfg : ∀ x : {x // x ≠ i1}, g x = f x, { intro x, rw hfdef, dsimp only [], erw [dif_neg x.property, subtype.coe_eta] }, rw hfg, have hf : ∑ ι in s2, f ι = 0, { rw [finset.sum_insert (finset.not_mem_map_subtype_of_not_property s (not_not.2 rfl)), finset.sum_subtype_map_embedding (λ x hx, (hfg x).symm)], rw hfdef, dsimp only [], rw dif_pos rfl, exact neg_add_self _ }, have hs2 : s2.weighted_vsub p f = (0:V), { set f2 : ι → V := λ x, f x • (p x -ᵥ p i1) with hf2def, set g2 : {x // x ≠ i1} → V := λ x, g x • (p x -ᵥ p i1) with hg2def, have hf2g2 : ∀ x : {x // x ≠ i1}, f2 x = g2 x, { simp_rw [hf2def, hg2def, hfg], exact λ x, rfl }, rw [finset.weighted_vsub_eq_weighted_vsub_of_point_of_sum_eq_zero s2 f p hf (p i1), finset.weighted_vsub_of_point_insert, finset.weighted_vsub_of_point_apply, finset.sum_subtype_map_embedding (λ x hx, hf2g2 x)], exact hg }, exact h s2 f hf hs2 i (finset.mem_insert_of_mem (finset.mem_map.2 ⟨i, hi, rfl⟩)) }, { intro h, rw linear_independent_iff' at h, intros s w hw hs i hi, rw [finset.weighted_vsub_eq_weighted_vsub_of_point_of_sum_eq_zero s w p hw (p i1), ←s.weighted_vsub_of_point_erase w p i1, finset.weighted_vsub_of_point_apply] at hs, let f : ι → V := λ i, w i • (p i -ᵥ p i1), have hs2 : ∑ i in (s.erase i1).subtype (λ i, i ≠ i1), f i = 0, { rw [←hs], convert finset.sum_subtype_of_mem f (λ x, finset.ne_of_mem_erase) }, have h2 := h ((s.erase i1).subtype (λ i, i ≠ i1)) (λ x, w x) hs2, simp_rw [finset.mem_subtype] at h2, have h2b : ∀ i ∈ s, i ≠ i1 → w i = 0 := λ i his hi, h2 ⟨i, hi⟩ (finset.mem_erase_of_ne_of_mem hi his), exact finset.eq_zero_of_sum_eq_zero hw h2b i hi } end /-- A set is affinely independent if and only if the differences from a base point in that set are linearly independent. -/ lemma affine_independent_set_iff_linear_independent_vsub {s : set P} {p₁ : P} (hp₁ : p₁ ∈ s) : affine_independent k (λ p, p : s → P) ↔ linear_independent k (λ v, v : (λ p, (p -ᵥ p₁ : V)) '' (s \ {p₁}) → V) := begin rw affine_independent_iff_linear_independent_vsub k (λ p, p : s → P) ⟨p₁, hp₁⟩, split, { intro h, have hv : ∀ v : (λ p, (p -ᵥ p₁ : V)) '' (s \ {p₁}), (v : V) +ᵥ p₁ ∈ s \ {p₁} := λ v, (vsub_left_injective p₁).mem_set_image.1 ((vadd_vsub (v : V) p₁).symm ▸ v.property), let f : (λ p : P, (p -ᵥ p₁ : V)) '' (s \ {p₁}) → {x : s // x ≠ ⟨p₁, hp₁⟩} := λ x, ⟨⟨(x : V) +ᵥ p₁, set.mem_of_mem_diff (hv x)⟩, λ hx, set.not_mem_of_mem_diff (hv x) (subtype.ext_iff.1 hx)⟩, convert h.comp f (λ x1 x2 hx, (subtype.ext (vadd_right_cancel p₁ (subtype.ext_iff.1 (subtype.ext_iff.1 hx))))), ext v, exact (vadd_vsub (v : V) p₁).symm }, { intro h, let f : {x : s // x ≠ ⟨p₁, hp₁⟩} → (λ p : P, (p -ᵥ p₁ : V)) '' (s \ {p₁}) := λ x, ⟨((x : s) : P) -ᵥ p₁, ⟨x, ⟨⟨(x : s).property, λ hx, x.property (subtype.ext hx)⟩, rfl⟩⟩⟩, convert h.comp f (λ x1 x2 hx, subtype.ext (subtype.ext (vsub_left_cancel (subtype.ext_iff.1 hx)))) } end /-- A set of nonzero vectors is linearly independent if and only if, given a point `p₁`, the vectors added to `p₁` and `p₁` itself are affinely independent. -/ lemma linear_independent_set_iff_affine_independent_vadd_union_singleton {s : set V} (hs : ∀ v ∈ s, v ≠ (0 : V)) (p₁ : P) : linear_independent k (λ v, v : s → V) ↔ affine_independent k (λ p, p : {p₁} ∪ ((λ v, v +ᵥ p₁) '' s) → P) := begin rw affine_independent_set_iff_linear_independent_vsub k (set.mem_union_left _ (set.mem_singleton p₁)), have h : (λ p, (p -ᵥ p₁ : V)) '' (({p₁} ∪ (λ v, v +ᵥ p₁) '' s) \ {p₁}) = s, { simp_rw [set.union_diff_left, set.image_diff (vsub_left_injective p₁), set.image_image, set.image_singleton, vsub_self, vadd_vsub, set.image_id'], exact set.diff_singleton_eq_self (λ h, hs 0 h rfl) }, rw h end /-- A family is affinely independent if and only if any affine combinations (with sum of weights 1) that evaluate to the same point have equal `set.indicator`. -/ lemma affine_independent_iff_indicator_eq_of_affine_combination_eq (p : ι → P) : affine_independent k p ↔ ∀ (s1 s2 : finset ι) (w1 w2 : ι → k), ∑ i in s1, w1 i = 1 → ∑ i in s2, w2 i = 1 → s1.affine_combination p w1 = s2.affine_combination p w2 → set.indicator ↑s1 w1 = set.indicator ↑s2 w2 := begin classical, split, { intros ha s1 s2 w1 w2 hw1 hw2 heq, ext i, by_cases hi : i ∈ (s1 ∪ s2), { rw ←sub_eq_zero, rw set.sum_indicator_subset _ (finset.subset_union_left s1 s2) at hw1, rw set.sum_indicator_subset _ (finset.subset_union_right s1 s2) at hw2, have hws : ∑ i in s1 ∪ s2, (set.indicator ↑s1 w1 - set.indicator ↑s2 w2) i = 0, { simp [hw1, hw2] }, rw [finset.affine_combination_indicator_subset _ _ (finset.subset_union_left s1 s2), finset.affine_combination_indicator_subset _ _ (finset.subset_union_right s1 s2), ←@vsub_eq_zero_iff_eq V, finset.affine_combination_vsub] at heq, exact ha (s1 ∪ s2) (set.indicator ↑s1 w1 - set.indicator ↑s2 w2) hws heq i hi }, { rw [←finset.mem_coe, finset.coe_union] at hi, simp [mt (set.mem_union_left ↑s2) hi, mt (set.mem_union_right ↑s1) hi] } }, { intros ha s w hw hs i0 hi0, let w1 : ι → k := function.update (function.const ι 0) i0 1, have hw1 : ∑ i in s, w1 i = 1, { rw [finset.sum_update_of_mem hi0, finset.sum_const_zero, add_zero] }, have hw1s : s.affine_combination p w1 = p i0 := s.affine_combination_of_eq_one_of_eq_zero w1 p hi0 (function.update_same _ _ _) (λ _ _ hne, function.update_noteq hne _ _), let w2 := w + w1, have hw2 : ∑ i in s, w2 i = 1, { simp [w2, finset.sum_add_distrib, hw, hw1] }, have hw2s : s.affine_combination p w2 = p i0, { simp [w2, ←finset.weighted_vsub_vadd_affine_combination, hs, hw1s] }, replace ha := ha s s w2 w1 hw2 hw1 (hw1s.symm ▸ hw2s), have hws : w2 i0 - w1 i0 = 0, { rw ←finset.mem_coe at hi0, rw [←set.indicator_of_mem hi0 w2, ←set.indicator_of_mem hi0 w1, ha, sub_self] }, simpa [w2] using hws } end /-- A finite family is affinely independent if and only if any affine combinations (with sum of weights 1) that evaluate to the same point are equal. -/ lemma affine_independent_iff_eq_of_fintype_affine_combination_eq [fintype ι] (p : ι → P) : affine_independent k p ↔ ∀ (w1 w2 : ι → k), ∑ i, w1 i = 1 → ∑ i, w2 i = 1 → finset.univ.affine_combination p w1 = finset.univ.affine_combination p w2 → w1 = w2 := begin rw affine_independent_iff_indicator_eq_of_affine_combination_eq, split, { intros h w1 w2 hw1 hw2 hweq, simpa only [set.indicator_univ, finset.coe_univ] using h _ _ w1 w2 hw1 hw2 hweq, }, { intros h s1 s2 w1 w2 hw1 hw2 hweq, have hw1' : ∑ i, (s1 : set ι).indicator w1 i = 1, { rwa set.sum_indicator_subset _ (finset.subset_univ s1) at hw1, }, have hw2' : ∑ i, (s2 : set ι).indicator w2 i = 1, { rwa set.sum_indicator_subset _ (finset.subset_univ s2) at hw2, }, rw [finset.affine_combination_indicator_subset w1 p (finset.subset_univ s1), finset.affine_combination_indicator_subset w2 p (finset.subset_univ s2)] at hweq, exact h _ _ hw1' hw2' hweq, }, end variables {k} /-- If we single out one member of an affine-independent family of points and affinely transport all others along the line joining them to this member, the resulting new family of points is affine- independent. This is the affine version of `linear_independent.units_smul`. -/ lemma affine_independent.units_line_map {p : ι → P} (hp : affine_independent k p) (j : ι) (w : ι → units k) : affine_independent k (λ i, affine_map.line_map (p j) (p i) (w i : k)) := begin rw affine_independent_iff_linear_independent_vsub k _ j at hp ⊢, simp only [affine_map.line_map_vsub_left, affine_map.coe_const, affine_map.line_map_same], exact hp.units_smul (λ i, w i), end lemma affine_independent.indicator_eq_of_affine_combination_eq {p : ι → P} (ha : affine_independent k p) (s₁ s₂ : finset ι) (w₁ w₂ : ι → k) (hw₁ : ∑ i in s₁, w₁ i = 1) (hw₂ : ∑ i in s₂, w₂ i = 1) (h : s₁.affine_combination p w₁ = s₂.affine_combination p w₂) : set.indicator ↑s₁ w₁ = set.indicator ↑s₂ w₂ := (affine_independent_iff_indicator_eq_of_affine_combination_eq k p).1 ha s₁ s₂ w₁ w₂ hw₁ hw₂ h /-- An affinely independent family is injective, if the underlying ring is nontrivial. -/ protected lemma affine_independent.injective [nontrivial k] {p : ι → P} (ha : affine_independent k p) : function.injective p := begin intros i j hij, rw affine_independent_iff_linear_independent_vsub _ _ j at ha, by_contra hij', exact ha.ne_zero ⟨i, hij'⟩ (vsub_eq_zero_iff_eq.mpr hij) end /-- If a family is affinely independent, so is any subfamily given by composition of an embedding into index type with the original family. -/ lemma affine_independent.comp_embedding {ι2 : Type*} (f : ι2 ↪ ι) {p : ι → P} (ha : affine_independent k p) : affine_independent k (p ∘ f) := begin classical, intros fs w hw hs i0 hi0, let fs' := fs.map f, let w' := λ i, if h : ∃ i2, f i2 = i then w h.some else 0, have hw' : ∀ i2 : ι2, w' (f i2) = w i2, { intro i2, have h : ∃ i : ι2, f i = f i2 := ⟨i2, rfl⟩, have hs : h.some = i2 := f.injective h.some_spec, simp_rw [w', dif_pos h, hs] }, have hw's : ∑ i in fs', w' i = 0, { rw [←hw, finset.sum_map], simp [hw'] }, have hs' : fs'.weighted_vsub p w' = (0:V), { rw [←hs, finset.weighted_vsub_map], congr' with i, simp [hw'] }, rw [←ha fs' w' hw's hs' (f i0) ((finset.mem_map' _).2 hi0), hw'] end /-- If a family is affinely independent, so is any subfamily indexed by a subtype of the index type. -/ protected lemma affine_independent.subtype {p : ι → P} (ha : affine_independent k p) (s : set ι) : affine_independent k (λ i : s, p i) := ha.comp_embedding (embedding.subtype _) /-- If an indexed family of points is affinely independent, so is the corresponding set of points. -/ protected lemma affine_independent.range {p : ι → P} (ha : affine_independent k p) : affine_independent k (λ x, x : set.range p → P) := begin let f : set.range p → ι := λ x, x.property.some, have hf : ∀ x, p (f x) = x := λ x, x.property.some_spec, let fe : set.range p ↪ ι := ⟨f, λ x₁ x₂ he, subtype.ext (hf x₁ ▸ hf x₂ ▸ he ▸ rfl)⟩, convert ha.comp_embedding fe, ext, simp [hf] end lemma affine_independent_equiv {ι' : Type*} (e : ι ≃ ι') {p : ι' → P} : affine_independent k (p ∘ e) ↔ affine_independent k p := begin refine ⟨_, affine_independent.comp_embedding e.to_embedding⟩, intros h, have : p = p ∘ e ∘ e.symm.to_embedding, { ext, simp, }, rw this, exact h.comp_embedding e.symm.to_embedding, end /-- If a set of points is affinely independent, so is any subset. -/ protected lemma affine_independent.mono {s t : set P} (ha : affine_independent k (λ x, x : t → P)) (hs : s ⊆ t) : affine_independent k (λ x, x : s → P) := ha.comp_embedding (s.embedding_of_subset t hs) /-- If the range of an injective indexed family of points is affinely independent, so is that family. -/ lemma affine_independent.of_set_of_injective {p : ι → P} (ha : affine_independent k (λ x, x : set.range p → P)) (hi : function.injective p) : affine_independent k p := ha.comp_embedding (⟨λ i, ⟨p i, set.mem_range_self _⟩, λ x y h, hi (subtype.mk_eq_mk.1 h)⟩ : ι ↪ set.range p) section composition variables {V₂ P₂ : Type*} [add_comm_group V₂] [module k V₂] [affine_space V₂ P₂] include V₂ /-- If the image of a family of points in affine space under an affine transformation is affine- independent, then the original family of points is also affine-independent. -/ lemma affine_independent.of_comp {p : ι → P} (f : P →ᵃ[k] P₂) (hai : affine_independent k (f ∘ p)) : affine_independent k p := begin cases is_empty_or_nonempty ι with h h, { haveI := h, apply affine_independent_of_subsingleton, }, obtain ⟨i⟩ := h, rw affine_independent_iff_linear_independent_vsub k p i, simp_rw [affine_independent_iff_linear_independent_vsub k (f ∘ p) i, function.comp_app, ← f.linear_map_vsub] at hai, exact linear_independent.of_comp f.linear hai, end /-- The image of a family of points in affine space, under an injective affine transformation, is affine-independent. -/ lemma affine_independent.map' {p : ι → P} (hai : affine_independent k p) (f : P →ᵃ[k] P₂) (hf : function.injective f) : affine_independent k (f ∘ p) := begin cases is_empty_or_nonempty ι with h h, { haveI := h, apply affine_independent_of_subsingleton, }, obtain ⟨i⟩ := h, rw affine_independent_iff_linear_independent_vsub k p i at hai, simp_rw [affine_independent_iff_linear_independent_vsub k (f ∘ p) i, function.comp_app, ← f.linear_map_vsub], have hf' : f.linear.ker = ⊥, { rwa [linear_map.ker_eq_bot, f.linear_injective_iff], }, exact linear_independent.map' hai f.linear hf', end /-- Injective affine maps preserve affine independence. -/ lemma affine_map.affine_independent_iff {p : ι → P} (f : P →ᵃ[k] P₂) (hf : function.injective f) : affine_independent k (f ∘ p) ↔ affine_independent k p := ⟨affine_independent.of_comp f, λ hai, affine_independent.map' hai f hf⟩ /-- Affine equivalences preserve affine independence of families of points. -/ lemma affine_equiv.affine_independent_iff {p : ι → P} (e : P ≃ᵃ[k] P₂) : affine_independent k (e ∘ p) ↔ affine_independent k p := e.to_affine_map.affine_independent_iff e.to_equiv.injective /-- Affine equivalences preserve affine independence of subsets. -/ lemma affine_equiv.affine_independent_set_of_eq_iff {s : set P} (e : P ≃ᵃ[k] P₂) : affine_independent k (coe : (e '' s) → P₂) ↔ affine_independent k (coe : s → P) := begin have : e ∘ (coe : s → P) = (coe : e '' s → P₂) ∘ ((e : P ≃ P₂).image s) := rfl, rw [← e.affine_independent_iff, this, affine_independent_equiv], end end composition /-- If a family is affinely independent, and the spans of points indexed by two subsets of the index type have a point in common, those subsets of the index type have an element in common, if the underlying ring is nontrivial. -/ lemma affine_independent.exists_mem_inter_of_exists_mem_inter_affine_span [nontrivial k] {p : ι → P} (ha : affine_independent k p) {s1 s2 : set ι} {p0 : P} (hp0s1 : p0 ∈ affine_span k (p '' s1)) (hp0s2 : p0 ∈ affine_span k (p '' s2)): ∃ (i : ι), i ∈ s1 ∩ s2 := begin rw set.image_eq_range at hp0s1 hp0s2, rw [mem_affine_span_iff_eq_affine_combination, ←finset.eq_affine_combination_subset_iff_eq_affine_combination_subtype] at hp0s1 hp0s2, rcases hp0s1 with ⟨fs1, hfs1, w1, hw1, hp0s1⟩, rcases hp0s2 with ⟨fs2, hfs2, w2, hw2, hp0s2⟩, rw affine_independent_iff_indicator_eq_of_affine_combination_eq at ha, replace ha := ha fs1 fs2 w1 w2 hw1 hw2 (hp0s1 ▸ hp0s2), have hnz : ∑ i in fs1, w1 i ≠ 0 := hw1.symm ▸ one_ne_zero, rcases finset.exists_ne_zero_of_sum_ne_zero hnz with ⟨i, hifs1, hinz⟩, simp_rw [←set.indicator_of_mem (finset.mem_coe.2 hifs1) w1, ha] at hinz, use [i, hfs1 hifs1, hfs2 (set.mem_of_indicator_ne_zero hinz)] end /-- If a family is affinely independent, the spans of points indexed by disjoint subsets of the index type are disjoint, if the underlying ring is nontrivial. -/ lemma affine_independent.affine_span_disjoint_of_disjoint [nontrivial k] {p : ι → P} (ha : affine_independent k p) {s1 s2 : set ι} (hd : disjoint s1 s2) : disjoint (affine_span k (p '' s1) : set P) (affine_span k (p '' s2)) := begin refine set.disjoint_left.2 (λ p0 hp0s1 hp0s2, _), cases ha.exists_mem_inter_of_exists_mem_inter_affine_span hp0s1 hp0s2 with i hi, exact set.disjoint_iff.1 hd hi, end /-- If a family is affinely independent, a point in the family is in the span of some of the points given by a subset of the index type if and only if that point's index is in the subset, if the underlying ring is nontrivial. -/ @[simp] protected lemma affine_independent.mem_affine_span_iff [nontrivial k] {p : ι → P} (ha : affine_independent k p) (i : ι) (s : set ι) : p i ∈ affine_span k (p '' s) ↔ i ∈ s := begin split, { intro hs, have h := affine_independent.exists_mem_inter_of_exists_mem_inter_affine_span ha hs (mem_affine_span k (set.mem_image_of_mem _ (set.mem_singleton _))), rwa [←set.nonempty_def, set.inter_singleton_nonempty] at h }, { exact λ h, mem_affine_span k (set.mem_image_of_mem p h) } end /-- If a family is affinely independent, a point in the family is not in the affine span of the other points, if the underlying ring is nontrivial. -/ lemma affine_independent.not_mem_affine_span_diff [nontrivial k] {p : ι → P} (ha : affine_independent k p) (i : ι) (s : set ι) : p i ∉ affine_span k (p '' (s \ {i})) := by simp [ha] lemma exists_nontrivial_relation_sum_zero_of_not_affine_ind {t : finset V} (h : ¬ affine_independent k (coe : t → V)) : ∃ f : V → k, ∑ e in t, f e • e = 0 ∧ ∑ e in t, f e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := begin classical, rw affine_independent_iff_of_fintype at h, simp only [exists_prop, not_forall] at h, obtain ⟨w, hw, hwt, i, hi⟩ := h, simp only [finset.weighted_vsub_eq_weighted_vsub_of_point_of_sum_eq_zero _ w (coe : t → V) hw 0, vsub_eq_sub, finset.weighted_vsub_of_point_apply, sub_zero] at hwt, let f : Π (x : V), x ∈ t → k := λ x hx, w ⟨x, hx⟩, refine ⟨λ x, if hx : x ∈ t then f x hx else (0 : k), _, _, by { use i, simp [hi, f], }⟩, suffices : ∑ (e : V) in t, dite (e ∈ t) (λ hx, (f e hx) • e) (λ hx, 0) = 0, { convert this, ext, by_cases hx : x ∈ t; simp [hx], }, all_goals { simp only [finset.sum_dite_of_true (λx h, h), subtype.val_eq_coe, finset.mk_coe, f, hwt, hw], }, end /-- Viewing a module as an affine space modelled on itself, we can characterise affine independence in terms of linear combinations. -/ lemma affine_independent_iff {ι} {p : ι → V} : affine_independent k p ↔ ∀ (s : finset ι) (w : ι → k), s.sum w = 0 → ∑ e in s, w e • p e = 0 → ∀ (e ∈ s), w e = 0 := forall₃_congr (λ s w hw, by simp [s.weighted_vsub_eq_linear_combination hw]) /-- Given an affinely independent family of points, a weighted subtraction lies in the `vector_span` of two points given as affine combinations if and only if it is a weighted subtraction with weights a multiple of the difference between the weights of the two points. -/ lemma weighted_vsub_mem_vector_span_pair {p : ι → P} (h : affine_independent k p) {w w₁ w₂ : ι → k} {s : finset ι} (hw : ∑ i in s, w i = 0) (hw₁ : ∑ i in s, w₁ i = 1) (hw₂ : ∑ i in s, w₂ i = 1) : s.weighted_vsub p w ∈ vector_span k ({s.affine_combination p w₁, s.affine_combination p w₂} : set P) ↔ ∃ r : k, ∀ i ∈ s, w i = r * (w₁ i - w₂ i) := begin rw mem_vector_span_pair, refine ⟨λ h, _, λ h, _⟩, { rcases h with ⟨r, hr⟩, refine ⟨r, λ i hi, _⟩, rw [s.affine_combination_vsub, ←s.weighted_vsub_const_smul, ←sub_eq_zero, ←map_sub] at hr, have hw' : ∑ j in s, (r • (w₁ - w₂) - w) j = 0, { simp_rw [pi.sub_apply, pi.smul_apply, pi.sub_apply, smul_sub, finset.sum_sub_distrib, ←finset.smul_sum, hw, hw₁, hw₂, sub_self] }, have hr' := h s _ hw' hr i hi, rw [eq_comm, ←sub_eq_zero, ←smul_eq_mul], exact hr' }, { rcases h with ⟨r, hr⟩, refine ⟨r, _⟩, let w' := λ i, r * (w₁ i - w₂ i), change ∀ i ∈ s, w i = w' i at hr, rw [s.weighted_vsub_congr hr (λ _ _, rfl), s.affine_combination_vsub, ←s.weighted_vsub_const_smul], congr } end /-- Given an affinely independent family of points, an affine combination lies in the span of two points given as affine combinations if and only if it is an affine combination with weights those of one point plus a multiple of the difference between the weights of the two points. -/ lemma affine_combination_mem_affine_span_pair {p : ι → P} (h : affine_independent k p) {w w₁ w₂ : ι → k} {s : finset ι} (hw : ∑ i in s, w i = 1) (hw₁ : ∑ i in s, w₁ i = 1) (hw₂ : ∑ i in s, w₂ i = 1) : s.affine_combination p w ∈ line[k, s.affine_combination p w₁, s.affine_combination p w₂] ↔ ∃ r : k, ∀ i ∈ s, w i = r * (w₂ i - w₁ i) + w₁ i := begin rw [←vsub_vadd (s.affine_combination p w) (s.affine_combination p w₁), affine_subspace.vadd_mem_iff_mem_direction _ (left_mem_affine_span_pair _ _ _), direction_affine_span, s.affine_combination_vsub, set.pair_comm, weighted_vsub_mem_vector_span_pair h _ hw₂ hw₁], { simp only [pi.sub_apply, sub_eq_iff_eq_add] }, { simp_rw [pi.sub_apply, finset.sum_sub_distrib, hw, hw₁, sub_self] } end end affine_independent section division_ring variables {k : Type*} {V : Type*} {P : Type*} [division_ring k] [add_comm_group V] [module k V] variables [affine_space V P] {ι : Type*} include V /-- An affinely independent set of points can be extended to such a set that spans the whole space. -/ lemma exists_subset_affine_independent_affine_span_eq_top {s : set P} (h : affine_independent k (λ p, p : s → P)) : ∃ t : set P, s ⊆ t ∧ affine_independent k (λ p, p : t → P) ∧ affine_span k t = ⊤ := begin rcases s.eq_empty_or_nonempty with rfl | ⟨p₁, hp₁⟩, { have p₁ : P := add_torsor.nonempty.some, let hsv := basis.of_vector_space k V, have hsvi := hsv.linear_independent, have hsvt := hsv.span_eq, rw basis.coe_of_vector_space at hsvi hsvt, have h0 : ∀ v : V, v ∈ (basis.of_vector_space_index _ _) → v ≠ 0, { intros v hv, simpa using hsv.ne_zero ⟨v, hv⟩ }, rw linear_independent_set_iff_affine_independent_vadd_union_singleton k h0 p₁ at hsvi, exact ⟨{p₁} ∪ (λ v, v +ᵥ p₁) '' _, set.empty_subset _, hsvi, affine_span_singleton_union_vadd_eq_top_of_span_eq_top p₁ hsvt⟩ }, { rw affine_independent_set_iff_linear_independent_vsub k hp₁ at h, let bsv := basis.extend h, have hsvi := bsv.linear_independent, have hsvt := bsv.span_eq, rw basis.coe_extend at hsvi hsvt, have hsv := h.subset_extend (set.subset_univ _), have h0 : ∀ v : V, v ∈ (h.extend _) → v ≠ 0, { intros v hv, simpa using bsv.ne_zero ⟨v, hv⟩ }, rw linear_independent_set_iff_affine_independent_vadd_union_singleton k h0 p₁ at hsvi, refine ⟨{p₁} ∪ (λ v, v +ᵥ p₁) '' h.extend (set.subset_univ _), _, _⟩, { refine set.subset.trans _ (set.union_subset_union_right _ (set.image_subset _ hsv)), simp [set.image_image] }, { use [hsvi, affine_span_singleton_union_vadd_eq_top_of_span_eq_top p₁ hsvt] } } end variables (k V) lemma exists_affine_independent (s : set P) : ∃ t ⊆ s, affine_span k t = affine_span k s ∧ affine_independent k (coe : t → P) := begin rcases s.eq_empty_or_nonempty with rfl | ⟨p, hp⟩, { exact ⟨∅, set.empty_subset ∅, rfl, affine_independent_of_subsingleton k _⟩, }, obtain ⟨b, hb₁, hb₂, hb₃⟩ := exists_linear_independent k ((equiv.vadd_const p).symm '' s), have hb₀ : ∀ (v : V), v ∈ b → v ≠ 0, { exact λ v hv, hb₃.ne_zero (⟨v, hv⟩ : b), }, rw linear_independent_set_iff_affine_independent_vadd_union_singleton k hb₀ p at hb₃, refine ⟨{p} ∪ (equiv.vadd_const p) '' b, _, _, hb₃⟩, { apply set.union_subset (set.singleton_subset_iff.mpr hp), rwa ← (equiv.vadd_const p).subset_image' b s, }, { rw [equiv.coe_vadd_const_symm, ← vector_span_eq_span_vsub_set_right k hp] at hb₂, apply affine_subspace.ext_of_direction_eq, { have : submodule.span k b = submodule.span k (insert 0 b), { simp, }, simp only [direction_affine_span, ← hb₂, equiv.coe_vadd_const, set.singleton_union, vector_span_eq_span_vsub_set_right k (set.mem_insert p _), this], congr, change (equiv.vadd_const p).symm '' insert p ((equiv.vadd_const p) '' b) = _, rw [set.image_insert_eq, ← set.image_comp], simp, }, { use p, simp only [equiv.coe_vadd_const, set.singleton_union, set.mem_inter_iff, coe_affine_span], exact ⟨mem_span_points k _ _ (set.mem_insert p _), mem_span_points k _ _ hp⟩, }, }, end variables (k) {V P} /-- Two different points are affinely independent. -/ lemma affine_independent_of_ne {p₁ p₂ : P} (h : p₁ ≠ p₂) : affine_independent k ![p₁, p₂] := begin rw affine_independent_iff_linear_independent_vsub k ![p₁, p₂] 0, let i₁ : {x // x ≠ (0 : fin 2)} := ⟨1, by norm_num⟩, have he' : ∀ i, i = i₁, { rintro ⟨i, hi⟩, ext, fin_cases i, { simpa using hi } }, haveI : unique {x // x ≠ (0 : fin 2)} := ⟨⟨i₁⟩, he'⟩, have hz : (![p₁, p₂] ↑default -ᵥ ![p₁, p₂] 0 : V) ≠ 0, { rw he' default, simpa using h.symm }, exact linear_independent_unique _ hz end variables {k V P} /-- If all but one point of a family are affinely independent, and that point does not lie in the affine span of that family, the family is affinely independent. -/ lemma affine_independent.affine_independent_of_not_mem_span {p : ι → P} {i : ι} (ha : affine_independent k (λ x : {y // y ≠ i}, p x)) (hi : p i ∉ affine_span k (p '' {x | x ≠ i})) : affine_independent k p := begin classical, intros s w hw hs, let s' : finset {y // y ≠ i} := s.subtype (≠ i), let p' : {y // y ≠ i} → P := λ x, p x, by_cases his : i ∈ s ∧ w i ≠ 0, { refine false.elim (hi _), let wm : ι → k := -(w i)⁻¹ • w, have hms : s.weighted_vsub p wm = (0 : V), { simp [wm, hs] }, have hwm : ∑ i in s, wm i = 0, { simp [wm, ←finset.mul_sum, hw] }, have hwmi : wm i = -1, { simp [wm, his.2] }, let w' : {y // y ≠ i} → k := λ x, wm x, have hw' : ∑ x in s', w' x = 1, { simp_rw [w', finset.sum_subtype_eq_sum_filter], rw ←s.sum_filter_add_sum_filter_not (≠ i) at hwm, simp_rw [not_not, finset.filter_eq', if_pos his.1, finset.sum_singleton, ←wm, hwmi, ←sub_eq_add_neg, sub_eq_zero] at hwm, exact hwm }, rw [←s.affine_combination_eq_of_weighted_vsub_eq_zero_of_eq_neg_one hms his.1 hwmi, ←(subtype.range_coe : _ = {x | x ≠ i}), ←set.range_comp, ←s.affine_combination_subtype_eq_filter], exact affine_combination_mem_affine_span hw' p' }, { rw [not_and_distrib, not_not] at his, let w' : {y // y ≠ i} → k := λ x, w x, have hw' : ∑ x in s', w' x = 0, { simp_rw [finset.sum_subtype_eq_sum_filter], rw [finset.sum_filter_of_ne, hw], rintro x hxs hwx rfl, exact hwx (his.neg_resolve_left hxs) }, have hs' : s'.weighted_vsub p' w' = (0 : V), { simp_rw finset.weighted_vsub_subtype_eq_filter, rw [finset.weighted_vsub_filter_of_ne, hs], rintro x hxs hwx rfl, exact hwx (his.neg_resolve_left hxs) }, intros j hj, by_cases hji : j = i, { rw hji at hj, exact hji.symm ▸ (his.neg_resolve_left hj) }, { exact ha s' w' hw' hs' ⟨j, hji⟩ (finset.mem_subtype.2 hj) } } end /-- If distinct points `p₁` and `p₂` lie in `s` but `p₃` does not, the three points are affinely independent. -/ lemma affine_independent_of_ne_of_mem_of_mem_of_not_mem {s : affine_subspace k P} {p₁ p₂ p₃ : P} (hp₁p₂ : p₁ ≠ p₂) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∉ s) : affine_independent k ![p₁, p₂, p₃] := begin have ha : affine_independent k (λ x : {x : fin 3 // x ≠ 2}, ![p₁, p₂, p₃] x), { rw ←affine_independent_equiv ((fin_succ_above_equiv (2 : fin 3)).to_equiv), convert affine_independent_of_ne k hp₁p₂, ext x, fin_cases x; refl }, refine ha.affine_independent_of_not_mem_span _, intro h, refine hp₃ ((affine_subspace.le_def' _ s).1 _ p₃ h), simp_rw [affine_span_le, set.image_subset_iff, set.subset_def, set.mem_preimage], intro x, fin_cases x; simp [hp₁, hp₂] end /-- If distinct points `p₁` and `p₃` lie in `s` but `p₂` does not, the three points are affinely independent. -/ lemma affine_independent_of_ne_of_mem_of_not_mem_of_mem {s : affine_subspace k P} {p₁ p₂ p₃ : P} (hp₁p₃ : p₁ ≠ p₃) (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∉ s) (hp₃ : p₃ ∈ s) : affine_independent k ![p₁, p₂, p₃] := begin rw ←affine_independent_equiv (equiv.swap (1 : fin 3) 2), convert affine_independent_of_ne_of_mem_of_mem_of_not_mem hp₁p₃ hp₁ hp₃ hp₂ using 1, ext x, fin_cases x; refl end /-- If distinct points `p₂` and `p₃` lie in `s` but `p₁` does not, the three points are affinely independent. -/ lemma affine_independent_of_ne_of_not_mem_of_mem_of_mem {s : affine_subspace k P} {p₁ p₂ p₃ : P} (hp₂p₃ : p₂ ≠ p₃) (hp₁ : p₁ ∉ s) (hp₂ : p₂ ∈ s) (hp₃ : p₃ ∈ s) : affine_independent k ![p₁, p₂, p₃] := begin rw ←affine_independent_equiv (equiv.swap (0 : fin 3) 2), convert affine_independent_of_ne_of_mem_of_mem_of_not_mem hp₂p₃.symm hp₃ hp₂ hp₁ using 1, ext x, fin_cases x; refl end end division_ring section ordered variables {k : Type*} {V : Type*} {P : Type*} [linear_ordered_ring k] [add_comm_group V] variables [module k V] [affine_space V P] {ι : Type*} include V local attribute [instance] linear_ordered_ring.decidable_lt /-- Given an affinely independent family of points, suppose that an affine combination lies in the span of two points given as affine combinations, and suppose that, for two indices, the coefficients in the first point in the span are zero and those in the second point in the span have the same sign. Then the coefficients in the combination lying in the span have the same sign. -/ lemma sign_eq_of_affine_combination_mem_affine_span_pair {p : ι → P} (h : affine_independent k p) {w w₁ w₂ : ι → k} {s : finset ι} (hw : ∑ i in s, w i = 1) (hw₁ : ∑ i in s, w₁ i = 1) (hw₂ : ∑ i in s, w₂ i = 1) (hs : s.affine_combination p w ∈ line[k, s.affine_combination p w₁, s.affine_combination p w₂]) {i j : ι} (hi : i ∈ s) (hj : j ∈ s) (hi0 : w₁ i = 0) (hj0 : w₁ j = 0) (hij : sign (w₂ i) = sign (w₂ j)) : sign (w i) = sign (w j) := begin rw affine_combination_mem_affine_span_pair h hw hw₁ hw₂ at hs, rcases hs with ⟨r, hr⟩, dsimp only at hr, rw [hr i hi, hr j hj, hi0, hj0, add_zero, add_zero, sub_zero, sub_zero, sign_mul, sign_mul, hij] end /-- Given an affinely independent family of points, suppose that an affine combination lies in the span of one point of that family and a combination of another two points of that family given by `line_map` with coefficient between 0 and 1. Then the coefficients of those two points in the combination lying in the span have the same sign. -/ lemma sign_eq_of_affine_combination_mem_affine_span_single_line_map {p : ι → P} (h : affine_independent k p) {w : ι → k} {s : finset ι} (hw : ∑ i in s, w i = 1) {i₁ i₂ i₃ : ι} (h₁ : i₁ ∈ s) (h₂ : i₂ ∈ s) (h₃ : i₃ ∈ s) (h₁₂ : i₁ ≠ i₂) (h₁₃ : i₁ ≠ i₃) (h₂₃ : i₂ ≠ i₃) {c : k} (hc0 : 0 < c) (hc1 : c < 1) (hs : s.affine_combination p w ∈ line[k, p i₁, affine_map.line_map (p i₂) (p i₃) c]) : sign (w i₂) = sign (w i₃) := begin classical, rw [←s.affine_combination_affine_combination_single_weights k p h₁, ←s.affine_combination_affine_combination_line_map_weights p h₂ h₃ c] at hs, refine sign_eq_of_affine_combination_mem_affine_span_pair h hw (s.sum_affine_combination_single_weights k h₁) (s.sum_affine_combination_line_map_weights h₂ h₃ c) hs h₂ h₃ (finset.affine_combination_single_weights_apply_of_ne k h₁₂.symm) (finset.affine_combination_single_weights_apply_of_ne k h₁₃.symm) _, rw [finset.affine_combination_line_map_weights_apply_left h₂₃, finset.affine_combination_line_map_weights_apply_right h₂₃], simp [hc0, sub_pos.2 hc1] end end ordered namespace affine variables (k : Type*) {V : Type*} (P : Type*) [ring k] [add_comm_group V] [module k V] variables [affine_space V P] include V /-- A `simplex k P n` is a collection of `n + 1` affinely independent points. -/ structure simplex (n : ℕ) := (points : fin (n + 1) → P) (independent : affine_independent k points) /-- A `triangle k P` is a collection of three affinely independent points. -/ abbreviation triangle := simplex k P 2 namespace simplex variables {P} /-- Construct a 0-simplex from a point. -/ def mk_of_point (p : P) : simplex k P 0 := ⟨λ _, p, affine_independent_of_subsingleton k _⟩ /-- The point in a simplex constructed with `mk_of_point`. -/ @[simp] lemma mk_of_point_points (p : P) (i : fin 1) : (mk_of_point k p).points i = p := rfl instance [inhabited P] : inhabited (simplex k P 0) := ⟨mk_of_point k default⟩ instance nonempty : nonempty (simplex k P 0) := ⟨mk_of_point k $ add_torsor.nonempty.some⟩ variables {k V} /-- Two simplices are equal if they have the same points. -/ @[ext] lemma ext {n : ℕ} {s1 s2 : simplex k P n} (h : ∀ i, s1.points i = s2.points i) : s1 = s2 := begin cases s1, cases s2, congr' with i, exact h i end /-- Two simplices are equal if and only if they have the same points. -/ lemma ext_iff {n : ℕ} (s1 s2 : simplex k P n): s1 = s2 ↔ ∀ i, s1.points i = s2.points i := ⟨λ h _, h ▸ rfl, ext⟩ /-- A face of a simplex is a simplex with the given subset of points. -/ def face {n : ℕ} (s : simplex k P n) {fs : finset (fin (n + 1))} {m : ℕ} (h : fs.card = m + 1) : simplex k P m := ⟨s.points ∘ fs.order_emb_of_fin h, s.independent.comp_embedding (fs.order_emb_of_fin h).to_embedding⟩ /-- The points of a face of a simplex are given by `mono_of_fin`. -/ lemma face_points {n : ℕ} (s : simplex k P n) {fs : finset (fin (n + 1))} {m : ℕ} (h : fs.card = m + 1) (i : fin (m + 1)) : (s.face h).points i = s.points (fs.order_emb_of_fin h i) := rfl /-- The points of a face of a simplex are given by `mono_of_fin`. -/ lemma face_points' {n : ℕ} (s : simplex k P n) {fs : finset (fin (n + 1))} {m : ℕ} (h : fs.card = m + 1) : (s.face h).points = s.points ∘ (fs.order_emb_of_fin h) := rfl /-- A single-point face equals the 0-simplex constructed with `mk_of_point`. -/ @[simp] lemma face_eq_mk_of_point {n : ℕ} (s : simplex k P n) (i : fin (n + 1)) : s.face (finset.card_singleton i) = mk_of_point k (s.points i) := by { ext, simp [face_points] } /-- The set of points of a face. -/ @[simp] lemma range_face_points {n : ℕ} (s : simplex k P n) {fs : finset (fin (n + 1))} {m : ℕ} (h : fs.card = m + 1) : set.range (s.face h).points = s.points '' ↑fs := by rw [face_points', set.range_comp, finset.range_order_emb_of_fin] /-- Remap a simplex along an `equiv` of index types. -/ @[simps] def reindex {m n : ℕ} (s : simplex k P m) (e : fin (m + 1) ≃ fin (n + 1)) : simplex k P n := ⟨s.points ∘ e.symm, (affine_independent_equiv e.symm).2 s.independent⟩ /-- Reindexing by `equiv.refl` yields the original simplex. -/ @[simp] lemma reindex_refl {n : ℕ} (s : simplex k P n) : s.reindex (equiv.refl (fin (n + 1))) = s := ext $ λ _, rfl /-- Reindexing by the composition of two equivalences is the same as reindexing twice. -/ @[simp] lemma reindex_trans {n₁ n₂ n₃ : ℕ} (e₁₂ : fin (n₁ + 1) ≃ fin (n₂ + 1)) (e₂₃ : fin (n₂ + 1) ≃ fin (n₃ + 1)) (s : simplex k P n₁) : s.reindex (e₁₂.trans e₂₃) = (s.reindex e₁₂).reindex e₂₃ := rfl /-- Reindexing by an equivalence and its inverse yields the original simplex. -/ @[simp] lemma reindex_reindex_symm {m n : ℕ} (s : simplex k P m) (e : fin (m + 1) ≃ fin (n + 1)) : (s.reindex e).reindex e.symm = s := by rw [←reindex_trans, equiv.self_trans_symm, reindex_refl] /-- Reindexing by the inverse of an equivalence and that equivalence yields the original simplex. -/ @[simp] lemma reindex_symm_reindex {m n : ℕ} (s : simplex k P m) (e : fin (n + 1) ≃ fin (m + 1)) : (s.reindex e.symm).reindex e = s := by rw [←reindex_trans, equiv.symm_trans_self, reindex_refl] /-- Reindexing a simplex produces one with the same set of points. -/ @[simp] lemma reindex_range_points {m n : ℕ} (s : simplex k P m) (e : fin (m + 1) ≃ fin (n + 1)) : set.range (s.reindex e).points = set.range s.points := by rw [reindex, set.range_comp, equiv.range_eq_univ, set.image_univ] end simplex end affine namespace affine namespace simplex variables {k : Type*} {V : Type*} {P : Type*} [division_ring k] [add_comm_group V] [module k V] [affine_space V P] include V /-- The centroid of a face of a simplex as the centroid of a subset of the points. -/ @[simp] lemma face_centroid_eq_centroid {n : ℕ} (s : simplex k P n) {fs : finset (fin (n + 1))} {m : ℕ} (h : fs.card = m + 1) : finset.univ.centroid k (s.face h).points = fs.centroid k s.points := begin convert (finset.univ.centroid_map k (fs.order_emb_of_fin h).to_embedding s.points).symm, rw [← finset.coe_inj, finset.coe_map, finset.coe_univ, set.image_univ], simp end /-- Over a characteristic-zero division ring, the centroids given by two subsets of the points of a simplex are equal if and only if those faces are given by the same subset of points. -/ @[simp] lemma centroid_eq_iff [char_zero k] {n : ℕ} (s : simplex k P n) {fs₁ fs₂ : finset (fin (n + 1))} {m₁ m₂ : ℕ} (h₁ : fs₁.card = m₁ + 1) (h₂ : fs₂.card = m₂ + 1) : fs₁.centroid k s.points = fs₂.centroid k s.points ↔ fs₁ = fs₂ := begin refine ⟨λ h, _, congr_arg _⟩, rw [finset.centroid_eq_affine_combination_fintype, finset.centroid_eq_affine_combination_fintype] at h, have ha := (affine_independent_iff_indicator_eq_of_affine_combination_eq k s.points).1 s.independent _ _ _ _ (fs₁.sum_centroid_weights_indicator_eq_one_of_card_eq_add_one k h₁) (fs₂.sum_centroid_weights_indicator_eq_one_of_card_eq_add_one k h₂) h, simp_rw [finset.coe_univ, set.indicator_univ, function.funext_iff, finset.centroid_weights_indicator_def, finset.centroid_weights, h₁, h₂] at ha, ext i, specialize ha i, have key : ∀ n : ℕ, (n : k) + 1 ≠ 0 := λ n h, by norm_cast at h, -- we should be able to golf this to `refine ⟨λ hi, decidable.by_contradiction (λ hni, _), ...⟩`, -- but for some unknown reason it doesn't work. split; intro hi; by_contra hni, { simpa [hni, hi, key] using ha }, { simpa [hni, hi, key] using ha.symm } end /-- Over a characteristic-zero division ring, the centroids of two faces of a simplex are equal if and only if those faces are given by the same subset of points. -/ lemma face_centroid_eq_iff [char_zero k] {n : ℕ} (s : simplex k P n) {fs₁ fs₂ : finset (fin (n + 1))} {m₁ m₂ : ℕ} (h₁ : fs₁.card = m₁ + 1) (h₂ : fs₂.card = m₂ + 1) : finset.univ.centroid k (s.face h₁).points = finset.univ.centroid k (s.face h₂).points ↔ fs₁ = fs₂ := begin rw [face_centroid_eq_centroid, face_centroid_eq_centroid], exact s.centroid_eq_iff h₁ h₂ end /-- Two simplices with the same points have the same centroid. -/ lemma centroid_eq_of_range_eq {n : ℕ} {s₁ s₂ : simplex k P n} (h : set.range s₁.points = set.range s₂.points) : finset.univ.centroid k s₁.points = finset.univ.centroid k s₂.points := begin rw [←set.image_univ, ←set.image_univ, ←finset.coe_univ] at h, exact finset.univ.centroid_eq_of_inj_on_of_image_eq k _ (λ _ _ _ _ he, affine_independent.injective s₁.independent he) (λ _ _ _ _ he, affine_independent.injective s₂.independent he) h end end simplex end affine
f5ca8240403dc00faae40973bd9ea7b169a7b651
e00ea76a720126cf9f6d732ad6216b5b824d20a7
/src/data/nat/basic.lean
a3a1278d34f148abd10242d897499e2ec4dc5bfc
[ "Apache-2.0" ]
permissive
vaibhavkarve/mathlib
a574aaf68c0a431a47fa82ce0637f0f769826bfe
17f8340912468f49bdc30acdb9a9fa02eeb0473a
refs/heads/master
1,621,263,802,637
1,585,399,588,000
1,585,399,588,000
250,833,447
0
0
Apache-2.0
1,585,410,341,000
1,585,410,341,000
null
UTF-8
Lean
false
false
56,510
lean
/- Copyright (c) 2014 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad, Mario Carneiro -/ import logic.basic algebra.ordered_ring data.option.basic algebra.order_functions /-! # Basic operations on the natural numbers This files has some basic lemmas about natural numbers, definition of the `choice` function, and extra recursors: * `le_rec_on`, `le_induction`: recursion and induction principles starting at non-zero numbers. * `decreasing_induction` : recursion gowing downwards. * `strong_rec'` : recursion based on strong inequalities. -/ universes u v namespace nat variables {m n k : ℕ} -- Sometimes a bare `nat.add` or similar appears as a consequence of unfolding -- during pattern matching. These lemmas package them back up as typeclass -- mediated operations. @[simp] theorem add_def {a b : ℕ} : nat.add a b = a + b := rfl @[simp] theorem mul_def {a b : ℕ} : nat.mul a b = a * b := rfl attribute [simp] nat.add_sub_cancel nat.add_sub_cancel_left attribute [simp] nat.sub_self @[simp] lemma succ_pos' {n : ℕ} : 0 < succ n := succ_pos n theorem succ_inj' {n m : ℕ} : succ n = succ m ↔ n = m := ⟨succ_inj, congr_arg _⟩ theorem succ_le_succ_iff {m n : ℕ} : succ m ≤ succ n ↔ m ≤ n := ⟨le_of_succ_le_succ, succ_le_succ⟩ lemma zero_max {m : nat} : max 0 m = m := max_eq_right (zero_le _) theorem max_succ_succ {m n : ℕ} : max (succ m) (succ n) = succ (max m n) := begin by_cases h1 : m ≤ n, rw [max_eq_right h1, max_eq_right (succ_le_succ h1)], { rw not_le at h1, have h2 := le_of_lt h1, rw [max_eq_left h2, max_eq_left (succ_le_succ h2)] } end lemma not_succ_lt_self {n : ℕ} : ¬succ n < n := not_lt_of_ge (nat.le_succ _) theorem lt_succ_iff {m n : ℕ} : m < succ n ↔ m ≤ n := succ_le_succ_iff lemma succ_le_iff {m n : ℕ} : succ m ≤ n ↔ m < n := ⟨lt_of_succ_le, succ_le_of_lt⟩ lemma lt_iff_add_one_le {m n : ℕ} : m < n ↔ m + 1 ≤ n := by rw succ_le_iff -- Just a restatement of `nat.lt_succ_iff` using `+1`. lemma lt_add_one_iff {a b : ℕ} : a < b + 1 ↔ a ≤ b := lt_succ_iff -- A flipped version of `lt_add_one_iff`. lemma lt_one_add_iff {a b : ℕ} : a < 1 + b ↔ a ≤ b := by simp only [add_comm, lt_succ_iff] -- This is true reflexively, by the definition of `≤` on ℕ, -- but it's still useful to have, to convince Lean to change the syntactic type. lemma add_one_le_iff {a b : ℕ} : a + 1 ≤ b ↔ a < b := iff.refl _ lemma one_add_le_iff {a b : ℕ} : 1 + a ≤ b ↔ a < b := by simp only [add_comm, add_one_le_iff] theorem of_le_succ {n m : ℕ} (H : n ≤ m.succ) : n ≤ m ∨ n = m.succ := (lt_or_eq_of_le H).imp le_of_lt_succ id /-- Recursion starting at a non-zero number: given a map `C k → C (k+1)` for each `k`, there is a map from `C n` to each `C m`, `n ≤ m`. -/ @[elab_as_eliminator] def le_rec_on {C : ℕ → Sort u} {n : ℕ} : Π {m : ℕ}, n ≤ m → (Π {k}, C k → C (k+1)) → C n → C m | 0 H next x := eq.rec_on (eq_zero_of_le_zero H) x | (m+1) H next x := or.by_cases (of_le_succ H) (λ h : n ≤ m, next $ le_rec_on h @next x) (λ h : n = m + 1, eq.rec_on h x) theorem le_rec_on_self {C : ℕ → Sort u} {n} {h : n ≤ n} {next} (x : C n) : (le_rec_on h next x : C n) = x := by cases n; unfold le_rec_on or.by_cases; rw [dif_neg n.not_succ_le_self, dif_pos rfl] theorem le_rec_on_succ {C : ℕ → Sort u} {n m} (h1 : n ≤ m) {h2 : n ≤ m+1} {next} (x : C n) : (le_rec_on h2 @next x : C (m+1)) = next (le_rec_on h1 @next x : C m) := by conv { to_lhs, rw [le_rec_on, or.by_cases, dif_pos h1] } theorem le_rec_on_succ' {C : ℕ → Sort u} {n} {h : n ≤ n+1} {next} (x : C n) : (le_rec_on h next x : C (n+1)) = next x := by rw [le_rec_on_succ (le_refl n), le_rec_on_self] theorem le_rec_on_trans {C : ℕ → Sort u} {n m k} (hnm : n ≤ m) (hmk : m ≤ k) {next} (x : C n) : (le_rec_on (le_trans hnm hmk) @next x : C k) = le_rec_on hmk @next (le_rec_on hnm @next x) := begin induction hmk with k hmk ih, { rw le_rec_on_self }, rw [le_rec_on_succ (le_trans hnm hmk), ih, le_rec_on_succ] end theorem le_rec_on_succ_left {C : ℕ → Sort u} {n m} (h1 : n ≤ m) (h2 : n+1 ≤ m) {next : Π{{k}}, C k → C (k+1)} (x : C n) : (le_rec_on h2 next (next x) : C m) = (le_rec_on h1 next x : C m) := begin rw [subsingleton.elim h1 (le_trans (le_succ n) h2), le_rec_on_trans (le_succ n) h2, le_rec_on_succ'] end theorem le_rec_on_injective {C : ℕ → Sort u} {n m} (hnm : n ≤ m) (next : Π n, C n → C (n+1)) (Hnext : ∀ n, function.injective (next n)) : function.injective (le_rec_on hnm next) := begin induction hnm with m hnm ih, { intros x y H, rwa [le_rec_on_self, le_rec_on_self] at H }, intros x y H, rw [le_rec_on_succ hnm, le_rec_on_succ hnm] at H, exact ih (Hnext _ H) end theorem le_rec_on_surjective {C : ℕ → Sort u} {n m} (hnm : n ≤ m) (next : Π n, C n → C (n+1)) (Hnext : ∀ n, function.surjective (next n)) : function.surjective (le_rec_on hnm next) := begin induction hnm with m hnm ih, { intros x, use x, rw le_rec_on_self }, intros x, rcases Hnext _ x with ⟨w, rfl⟩, rcases ih w with ⟨x, rfl⟩, use x, rw le_rec_on_succ end theorem pred_eq_of_eq_succ {m n : ℕ} (H : m = n.succ) : m.pred = n := by simp [H] @[simp] lemma pred_eq_succ_iff {n m : ℕ} : pred n = succ m ↔ n = m + 2 := by cases n; split; rintro ⟨⟩; refl theorem pred_sub (n m : ℕ) : pred n - m = pred (n - m) := by rw [← sub_one, nat.sub_sub, one_add]; refl lemma pred_eq_sub_one (n : ℕ) : pred n = n - 1 := rfl lemma one_le_of_lt {n m : ℕ} (h : n < m) : 1 ≤ m := lt_of_le_of_lt (nat.zero_le _) h lemma le_pred_of_lt {n m : ℕ} (h : m < n) : m ≤ n - 1 := nat.sub_le_sub_right h 1 lemma le_of_pred_lt {m n : ℕ} : pred m < n → m ≤ n := match m with | 0 := le_of_lt | m+1 := id end /-- This ensures that `simp` succeeds on `pred (n + 1) = n`. -/ @[simp] lemma pred_one_add (n : ℕ) : pred (1 + n) = n := by rw [add_comm, add_one, pred_succ] theorem pos_iff_ne_zero : 0 < n ↔ n ≠ 0 := ⟨ne_of_gt, nat.pos_of_ne_zero⟩ lemma one_lt_iff_ne_zero_and_ne_one : ∀ {n : ℕ}, 1 < n ↔ n ≠ 0 ∧ n ≠ 1 | 0 := dec_trivial | 1 := dec_trivial | (n+2) := dec_trivial theorem eq_of_lt_succ_of_not_lt {a b : ℕ} (h1 : a < b + 1) (h2 : ¬ a < b) : a = b := have h3 : a ≤ b, from le_of_lt_succ h1, or.elim (eq_or_lt_of_not_lt h2) (λ h, h) (λ h, absurd h (not_lt_of_ge h3)) protected theorem le_sub_add (n m : ℕ) : n ≤ n - m + m := or.elim (le_total n m) (assume : n ≤ m, begin rw [sub_eq_zero_of_le this, zero_add], exact this end) (assume : m ≤ n, begin rw (nat.sub_add_cancel this) end) theorem sub_add_eq_max (n m : ℕ) : n - m + m = max n m := eq_max (nat.le_sub_add _ _) (le_add_left _ _) $ λ k h₁ h₂, by rw ← nat.sub_add_cancel h₂; exact add_le_add_right (nat.sub_le_sub_right h₁ _) _ theorem sub_add_min (n m : ℕ) : n - m + min n m = n := (le_total n m).elim (λ h, by rw [min_eq_left h, sub_eq_zero_of_le h, zero_add]) (λ h, by rw [min_eq_right h, nat.sub_add_cancel h]) protected theorem add_sub_cancel' {n m : ℕ} (h : m ≤ n) : m + (n - m) = n := by rw [add_comm, nat.sub_add_cancel h] protected theorem sub_eq_of_eq_add (h : k = m + n) : k - m = n := begin rw [h, nat.add_sub_cancel_left] end theorem sub_cancel {a b c : ℕ} (h₁ : a ≤ b) (h₂ : a ≤ c) (w : b - a = c - a) : b = c := by rw [←nat.sub_add_cancel h₁, ←nat.sub_add_cancel h₂, w] lemma sub_sub_sub_cancel_right {a b c : ℕ} (h₂ : c ≤ b) : (a - c) - (b - c) = a - b := by rw [nat.sub_sub, ←nat.add_sub_assoc h₂, nat.add_sub_cancel_left] lemma add_sub_cancel_right (n m k : ℕ) : n + (m + k) - k = n + m := by { rw [nat.add_sub_assoc, nat.add_sub_cancel], apply k.le_add_left } protected lemma sub_add_eq_add_sub {a b c : ℕ} (h : b ≤ a) : (a - b) + c = (a + c) - b := by rw [add_comm a, nat.add_sub_assoc h, add_comm] theorem sub_min (n m : ℕ) : n - min n m = n - m := nat.sub_eq_of_eq_add $ by rw [add_comm, sub_add_min] theorem sub_sub_assoc {a b c : ℕ} (h₁ : b ≤ a) (h₂ : c ≤ b) : a - (b - c) = a - b + c := (nat.sub_eq_iff_eq_add (le_trans (nat.sub_le _ _) h₁)).2 $ by rw [add_right_comm, add_assoc, nat.sub_add_cancel h₂, nat.sub_add_cancel h₁] protected theorem lt_of_sub_pos (h : 0 < n - m) : m < n := lt_of_not_ge (assume : n ≤ m, have n - m = 0, from sub_eq_zero_of_le this, begin rw this at h, exact lt_irrefl _ h end) protected theorem lt_of_sub_lt_sub_right : m - k < n - k → m < n := lt_imp_lt_of_le_imp_le (λ h, nat.sub_le_sub_right h _) protected theorem lt_of_sub_lt_sub_left : m - n < m - k → k < n := lt_imp_lt_of_le_imp_le (nat.sub_le_sub_left _) protected theorem sub_lt_self (h₁ : 0 < m) (h₂ : 0 < n) : m - n < m := calc m - n = succ (pred m) - succ (pred n) : by rw [succ_pred_eq_of_pos h₁, succ_pred_eq_of_pos h₂] ... = pred m - pred n : by rw succ_sub_succ ... ≤ pred m : sub_le _ _ ... < succ (pred m) : lt_succ_self _ ... = m : succ_pred_eq_of_pos h₁ protected theorem le_sub_right_of_add_le (h : m + k ≤ n) : m ≤ n - k := by rw ← nat.add_sub_cancel m k; exact nat.sub_le_sub_right h k protected theorem le_sub_left_of_add_le (h : k + m ≤ n) : m ≤ n - k := nat.le_sub_right_of_add_le (by rwa add_comm at h) protected theorem lt_sub_right_of_add_lt (h : m + k < n) : m < n - k := lt_of_succ_le $ nat.le_sub_right_of_add_le $ by rw succ_add; exact succ_le_of_lt h protected theorem lt_sub_left_of_add_lt (h : k + m < n) : m < n - k := nat.lt_sub_right_of_add_lt (by rwa add_comm at h) protected theorem add_lt_of_lt_sub_right (h : m < n - k) : m + k < n := @nat.lt_of_sub_lt_sub_right _ _ k (by rwa nat.add_sub_cancel) protected theorem add_lt_of_lt_sub_left (h : m < n - k) : k + m < n := by rw add_comm; exact nat.add_lt_of_lt_sub_right h protected theorem le_add_of_sub_le_right : n - k ≤ m → n ≤ m + k := le_imp_le_of_lt_imp_lt nat.lt_sub_right_of_add_lt protected theorem le_add_of_sub_le_left : n - k ≤ m → n ≤ k + m := le_imp_le_of_lt_imp_lt nat.lt_sub_left_of_add_lt protected theorem lt_add_of_sub_lt_right : n - k < m → n < m + k := lt_imp_lt_of_le_imp_le nat.le_sub_right_of_add_le protected theorem lt_add_of_sub_lt_left : n - k < m → n < k + m := lt_imp_lt_of_le_imp_le nat.le_sub_left_of_add_le protected theorem sub_le_left_of_le_add : n ≤ k + m → n - k ≤ m := le_imp_le_of_lt_imp_lt nat.add_lt_of_lt_sub_left protected theorem sub_le_right_of_le_add : n ≤ m + k → n - k ≤ m := le_imp_le_of_lt_imp_lt nat.add_lt_of_lt_sub_right protected theorem sub_lt_left_iff_lt_add (H : n ≤ k) : k - n < m ↔ k < n + m := ⟨nat.lt_add_of_sub_lt_left, λ h₁, have succ k ≤ n + m, from succ_le_of_lt h₁, have succ (k - n) ≤ m, from calc succ (k - n) = succ k - n : by rw (succ_sub H) ... ≤ n + m - n : nat.sub_le_sub_right this n ... = m : by rw nat.add_sub_cancel_left, lt_of_succ_le this⟩ protected theorem le_sub_left_iff_add_le (H : m ≤ k) : n ≤ k - m ↔ m + n ≤ k := le_iff_le_iff_lt_iff_lt.2 (nat.sub_lt_left_iff_lt_add H) protected theorem le_sub_right_iff_add_le (H : n ≤ k) : m ≤ k - n ↔ m + n ≤ k := by rw [nat.le_sub_left_iff_add_le H, add_comm] protected theorem lt_sub_left_iff_add_lt : n < k - m ↔ m + n < k := ⟨nat.add_lt_of_lt_sub_left, nat.lt_sub_left_of_add_lt⟩ protected theorem lt_sub_right_iff_add_lt : m < k - n ↔ m + n < k := by rw [nat.lt_sub_left_iff_add_lt, add_comm] theorem sub_le_left_iff_le_add : m - n ≤ k ↔ m ≤ n + k := le_iff_le_iff_lt_iff_lt.2 nat.lt_sub_left_iff_add_lt theorem sub_le_right_iff_le_add : m - k ≤ n ↔ m ≤ n + k := by rw [nat.sub_le_left_iff_le_add, add_comm] protected theorem sub_lt_right_iff_lt_add (H : k ≤ m) : m - k < n ↔ m < n + k := by rw [nat.sub_lt_left_iff_lt_add H, add_comm] protected theorem sub_le_sub_left_iff (H : k ≤ m) : m - n ≤ m - k ↔ k ≤ n := ⟨λ h, have k + (m - k) - n ≤ m - k, by rwa nat.add_sub_cancel' H, nat.le_of_add_le_add_right (nat.le_add_of_sub_le_left this), nat.sub_le_sub_left _⟩ protected theorem sub_lt_sub_right_iff (H : k ≤ m) : m - k < n - k ↔ m < n := lt_iff_lt_of_le_iff_le (nat.sub_le_sub_right_iff _ _ _ H) protected theorem sub_lt_sub_left_iff (H : n ≤ m) : m - n < m - k ↔ k < n := lt_iff_lt_of_le_iff_le (nat.sub_le_sub_left_iff H) protected theorem sub_le_iff : m - n ≤ k ↔ m - k ≤ n := nat.sub_le_left_iff_le_add.trans nat.sub_le_right_iff_le_add.symm protected lemma sub_le_self (n m : ℕ) : n - m ≤ n := nat.sub_le_left_of_le_add (nat.le_add_left _ _) protected theorem sub_lt_iff (h₁ : n ≤ m) (h₂ : k ≤ m) : m - n < k ↔ m - k < n := (nat.sub_lt_left_iff_lt_add h₁).trans (nat.sub_lt_right_iff_lt_add h₂).symm lemma pred_le_iff {n m : ℕ} : pred n ≤ m ↔ n ≤ succ m := @nat.sub_le_right_iff_le_add n m 1 lemma lt_pred_iff {n m : ℕ} : n < pred m ↔ succ n < m := @nat.lt_sub_right_iff_add_lt n 1 m protected theorem mul_ne_zero {n m : ℕ} (n0 : n ≠ 0) (m0 : m ≠ 0) : n * m ≠ 0 | nm := (eq_zero_of_mul_eq_zero nm).elim n0 m0 @[simp] protected theorem mul_eq_zero {a b : ℕ} : a * b = 0 ↔ a = 0 ∨ b = 0 := iff.intro eq_zero_of_mul_eq_zero (by simp [or_imp_distrib] {contextual := tt}) @[simp] protected theorem zero_eq_mul {a b : ℕ} : 0 = a * b ↔ a = 0 ∨ b = 0 := by rw [eq_comm, nat.mul_eq_zero] lemma eq_zero_of_double_le {a : ℕ} (h : 2 * a ≤ a) : a = 0 := nat.eq_zero_of_le_zero $ by rwa [two_mul, nat.add_le_to_le_sub, nat.sub_self] at h; refl lemma eq_zero_of_mul_le {a b : ℕ} (hb : 2 ≤ b) (h : b * a ≤ a) : a = 0 := eq_zero_of_double_le $ le_trans (nat.mul_le_mul_right _ hb) h lemma le_mul_of_pos_left {m n : ℕ} (h : 0 < n) : m ≤ n * m := begin conv {to_lhs, rw [← one_mul(m)]}, exact mul_le_mul_of_nonneg_right (nat.succ_le_of_lt h) dec_trivial, end lemma le_mul_of_pos_right {m n : ℕ} (h : 0 < n) : m ≤ m * n := begin conv {to_lhs, rw [← mul_one(m)]}, exact mul_le_mul_of_nonneg_left (nat.succ_le_of_lt h) dec_trivial, end theorem two_mul_ne_two_mul_add_one {n m} : 2 * n ≠ 2 * m + 1 := mt (congr_arg (%2)) (by rw [add_comm, add_mul_mod_self_left, mul_mod_right]; exact dec_trivial) /-- Recursion principle based on `<`. -/ @[elab_as_eliminator] protected def strong_rec' {p : ℕ → Sort u} (H : ∀ n, (∀ m, m < n → p m) → p n) : ∀ (n : ℕ), p n | n := H n (λ m hm, strong_rec' m) attribute [simp] nat.div_self protected lemma div_le_of_le_mul' {m n : ℕ} {k} (h : m ≤ k * n) : m / k ≤ n := (eq_zero_or_pos k).elim (λ k0, by rw [k0, nat.div_zero]; apply zero_le) (λ k0, (decidable.mul_le_mul_left k0).1 $ calc k * (m / k) ≤ m % k + k * (m / k) : le_add_left _ _ ... = m : mod_add_div _ _ ... ≤ k * n : h) protected lemma div_le_self' (m n : ℕ) : m / n ≤ m := (eq_zero_or_pos n).elim (λ n0, by rw [n0, nat.div_zero]; apply zero_le) (λ n0, nat.div_le_of_le_mul' $ calc m = 1 * m : (one_mul _).symm ... ≤ n * m : mul_le_mul_right _ n0) theorem le_div_iff_mul_le' {x y : ℕ} {k : ℕ} (k0 : 0 < k) : x ≤ y / k ↔ x * k ≤ y := begin revert x, refine nat.strong_rec' _ y, clear y, intros y IH x, cases decidable.lt_or_le y k with h h, { rw [div_eq_of_lt h], cases x with x, { simp [zero_mul, zero_le] }, { rw succ_mul, exact iff_of_false (not_succ_le_zero _) (not_le_of_lt $ lt_of_lt_of_le h (le_add_left _ _)) } }, { rw [div_eq_sub_div k0 h], cases x with x, { simp [zero_mul, zero_le] }, { rw [← add_one, nat.add_le_add_iff_le_right, succ_mul, IH _ (sub_lt_of_pos_le _ _ k0 h), add_le_to_le_sub _ h] } } end theorem div_mul_le_self' (m n : ℕ) : m / n * n ≤ m := (nat.eq_zero_or_pos n).elim (λ n0, by simp [n0, zero_le]) $ λ n0, (le_div_iff_mul_le' n0).1 (le_refl _) theorem div_lt_iff_lt_mul' {x y : ℕ} {k : ℕ} (k0 : 0 < k) : x / k < y ↔ x < y * k := lt_iff_lt_of_le_iff_le $ le_div_iff_mul_le' k0 protected theorem div_le_div_right {n m : ℕ} (h : n ≤ m) {k : ℕ} : n / k ≤ m / k := (nat.eq_zero_or_pos k).elim (λ k0, by simp [k0]) $ λ hk, (le_div_iff_mul_le' hk).2 $ le_trans (nat.div_mul_le_self' _ _) h lemma lt_of_div_lt_div {m n k : ℕ} (h : m / k < n / k) : m < n := by_contradiction $ λ h₁, absurd h (not_lt_of_ge (nat.div_le_div_right (not_lt.1 h₁))) protected theorem eq_mul_of_div_eq_right {a b c : ℕ} (H1 : b ∣ a) (H2 : a / b = c) : a = b * c := by rw [← H2, nat.mul_div_cancel' H1] protected theorem div_eq_iff_eq_mul_right {a b c : ℕ} (H : 0 < b) (H' : b ∣ a) : a / b = c ↔ a = b * c := ⟨nat.eq_mul_of_div_eq_right H', nat.div_eq_of_eq_mul_right H⟩ protected theorem div_eq_iff_eq_mul_left {a b c : ℕ} (H : 0 < b) (H' : b ∣ a) : a / b = c ↔ a = c * b := by rw mul_comm; exact nat.div_eq_iff_eq_mul_right H H' protected theorem eq_mul_of_div_eq_left {a b c : ℕ} (H1 : b ∣ a) (H2 : a / b = c) : a = c * b := by rw [mul_comm, nat.eq_mul_of_div_eq_right H1 H2] protected theorem mul_div_cancel_left' {a b : ℕ} (Hd : a ∣ b) : a * (b / a) = b := by rw [mul_comm,nat.div_mul_cancel Hd] protected theorem div_mod_unique {n k m d : ℕ} (h : 0 < k) : n / k = d ∧ n % k = m ↔ m + k * d = n ∧ m < k := ⟨λ ⟨e₁, e₂⟩, e₁ ▸ e₂ ▸ ⟨mod_add_div _ _, mod_lt _ h⟩, λ ⟨h₁, h₂⟩, h₁ ▸ by rw [add_mul_div_left _ _ h, add_mul_mod_self_left]; simp [div_eq_of_lt, mod_eq_of_lt, h₂]⟩ lemma two_mul_odd_div_two {n : ℕ} (hn : n % 2 = 1) : 2 * (n / 2) = n - 1 := by conv {to_rhs, rw [← nat.mod_add_div n 2, hn, nat.add_sub_cancel_left]} lemma div_dvd_of_dvd {a b : ℕ} (h : b ∣ a) : (a / b) ∣ a := ⟨b, (nat.div_mul_cancel h).symm⟩ protected lemma div_pos {a b : ℕ} (hba : b ≤ a) (hb : 0 < b) : 0 < a / b := nat.pos_of_ne_zero (λ h, lt_irrefl a (calc a = a % b : by simpa [h] using (mod_add_div a b).symm ... < b : nat.mod_lt a hb ... ≤ a : hba)) protected theorem mul_right_inj {a b c : ℕ} (ha : 0 < a) : b * a = c * a ↔ b = c := ⟨nat.eq_of_mul_eq_mul_right ha, λ e, e ▸ rfl⟩ protected theorem mul_left_inj {a b c : ℕ} (ha : 0 < a) : a * b = a * c ↔ b = c := ⟨nat.eq_of_mul_eq_mul_left ha, λ e, e ▸ rfl⟩ protected lemma div_div_self : ∀ {a b : ℕ}, b ∣ a → 0 < a → a / (a / b) = b | a 0 h₁ h₂ := by rw eq_zero_of_zero_dvd h₁; refl | 0 b h₁ h₂ := absurd h₂ dec_trivial | (a+1) (b+1) h₁ h₂ := (nat.mul_right_inj (nat.div_pos (le_of_dvd (succ_pos a) h₁) (succ_pos b))).1 $ by rw [nat.div_mul_cancel (div_dvd_of_dvd h₁), nat.mul_div_cancel' h₁] protected lemma div_lt_of_lt_mul {m n k : ℕ} (h : m < n * k) : m / n < k := lt_of_mul_lt_mul_left (calc n * (m / n) ≤ m % n + n * (m / n) : nat.le_add_left _ _ ... = m : mod_add_div _ _ ... < n * k : h) (nat.zero_le n) lemma lt_mul_of_div_lt {a b c : ℕ} (h : a / c < b) (w : 0 < c) : a < b * c := lt_of_not_ge $ not_le_of_gt h ∘ (nat.le_div_iff_mul_le _ _ w).2 protected lemma div_eq_zero_iff {a b : ℕ} (hb : 0 < b) : a / b = 0 ↔ a < b := ⟨λ h, by rw [← mod_add_div a b, h, mul_zero, add_zero]; exact mod_lt _ hb, λ h, by rw [← nat.mul_left_inj hb, ← @add_left_cancel_iff _ _ (a % b), mod_add_div, mod_eq_of_lt h, mul_zero, add_zero]⟩ lemma eq_zero_of_le_div {a b : ℕ} (hb : 2 ≤ b) (h : a ≤ a / b) : a = 0 := eq_zero_of_mul_le hb $ by rw mul_comm; exact (nat.le_div_iff_mul_le' (lt_of_lt_of_le dec_trivial hb)).1 h lemma mul_div_le_mul_div_assoc (a b c : ℕ) : a * (b / c) ≤ (a * b) / c := if hc0 : c = 0 then by simp [hc0] else (nat.le_div_iff_mul_le _ _ (nat.pos_of_ne_zero hc0)).2 (by rw [mul_assoc]; exact mul_le_mul_left _ (nat.div_mul_le_self _ _)) lemma div_mul_div_le_div (a b c : ℕ) : ((a / c) * b) / a ≤ b / c := if ha0 : a = 0 then by simp [ha0] else calc a / c * b / a ≤ b * a / c / a : nat.div_le_div_right (by rw [mul_comm]; exact mul_div_le_mul_div_assoc _ _ _) ... = b / c : by rw [nat.div_div_eq_div_mul, mul_comm b, mul_comm c, nat.mul_div_mul _ _ (nat.pos_of_ne_zero ha0)] lemma eq_zero_of_le_half {a : ℕ} (h : a ≤ a / 2) : a = 0 := eq_zero_of_le_div (le_refl _) h lemma mod_mul_right_div_self (a b c : ℕ) : a % (b * c) / b = (a / b) % c := if hb : b = 0 then by simp [hb] else if hc : c = 0 then by simp [hc] else by conv {to_rhs, rw ← mod_add_div a (b * c)}; rw [mul_assoc, nat.add_mul_div_left _ _ (nat.pos_of_ne_zero hb), add_mul_mod_self_left, mod_eq_of_lt (nat.div_lt_of_lt_mul (mod_lt _ (mul_pos (nat.pos_of_ne_zero hb) (nat.pos_of_ne_zero hc))))] lemma mod_mul_left_div_self (a b c : ℕ) : a % (c * b) / b = (a / b) % c := by rw [mul_comm c, mod_mul_right_div_self] /- The `n+1`-st triangle number is `n` more than the `n`-th triangle number -/ lemma triangle_succ (n : ℕ) : (n + 1) * ((n + 1) - 1) / 2 = n * (n - 1) / 2 + n := begin rw [← add_mul_div_left, mul_comm 2 n, ← mul_add, nat.add_sub_cancel, mul_comm], cases n; refl, apply zero_lt_succ end @[simp] protected theorem dvd_one {n : ℕ} : n ∣ 1 ↔ n = 1 := ⟨eq_one_of_dvd_one, λ e, e.symm ▸ dvd_refl _⟩ protected theorem dvd_add_left {k m n : ℕ} (h : k ∣ n) : k ∣ m + n ↔ k ∣ m := (nat.dvd_add_iff_left h).symm protected theorem dvd_add_right {k m n : ℕ} (h : k ∣ m) : k ∣ m + n ↔ k ∣ n := (nat.dvd_add_iff_right h).symm /-- A natural number m divides the sum m + n if and only if m divides b.-/ @[simp] protected lemma dvd_add_self_left {m n : ℕ} : m ∣ m + n ↔ m ∣ n := nat.dvd_add_right (dvd_refl m) /-- A natural number m divides the sum n + m if and only if m divides b.-/ @[simp] protected lemma dvd_add_self_right {m n : ℕ} : m ∣ n + m ↔ m ∣ n := nat.dvd_add_left (dvd_refl m) protected theorem mul_dvd_mul_iff_left {a b c : ℕ} (ha : 0 < a) : a * b ∣ a * c ↔ b ∣ c := exists_congr $ λ d, by rw [mul_assoc, nat.mul_left_inj ha] protected theorem mul_dvd_mul_iff_right {a b c : ℕ} (hc : 0 < c) : a * c ∣ b * c ↔ a ∣ b := exists_congr $ λ d, by rw [mul_right_comm, nat.mul_right_inj hc] lemma succ_div : ∀ (a b : ℕ), (a + 1) / b = a / b + if b ∣ a + 1 then 1 else 0 | a 0 := by simp | 0 1 := rfl | 0 (b+2) := have hb2 : b + 2 > 1, from dec_trivial, by simp [ne_of_gt hb2, div_eq_of_lt hb2] | (a+1) (b+1) := begin rw [nat.div_def], conv_rhs { rw nat.div_def }, by_cases hb_eq_a : b = a + 1, { simp [hb_eq_a, le_refl] }, by_cases hb_le_a1 : b ≤ a + 1, { have hb_le_a : b ≤ a, from le_of_lt_succ (lt_of_le_of_ne hb_le_a1 hb_eq_a), have h₁ : (0 < b + 1 ∧ b + 1 ≤ a + 1 + 1), from ⟨succ_pos _, (add_le_add_iff_right _).2 hb_le_a1⟩, have h₂ : (0 < b + 1 ∧ b + 1 ≤ a + 1), from ⟨succ_pos _, (add_le_add_iff_right _).2 hb_le_a⟩, have dvd_iff : b + 1 ∣ a - b + 1 ↔ b + 1 ∣ a + 1 + 1, { rw [nat.dvd_add_iff_left (dvd_refl (b + 1)), ← nat.add_sub_add_right a 1 b, add_comm (_ - _), add_assoc, nat.sub_add_cancel (succ_le_succ hb_le_a), add_comm 1] }, have wf : a - b < a + 1, from lt_succ_of_le (nat.sub_le_self _ _), rw [if_pos h₁, if_pos h₂, nat.add_sub_add_right, nat.sub_add_comm hb_le_a, by exact have _ := wf, succ_div (a - b), nat.add_sub_add_right], simp [dvd_iff, succ_eq_add_one, add_comm 1], congr }, { have hba : ¬ b ≤ a, from not_le_of_gt (lt_trans (lt_succ_self a) (lt_of_not_ge hb_le_a1)), have hb_dvd_a : ¬ b + 1 ∣ a + 2, from λ h, hb_le_a1 (le_of_succ_le_succ (le_of_dvd (succ_pos _) h)), simp [hba, hb_le_a1, hb_dvd_a], } end lemma succ_div_of_dvd {a b : ℕ} (hba : b ∣ a + 1) : (a + 1) / b = a / b + 1 := by rw [succ_div, if_pos hba] lemma succ_div_of_not_dvd {a b : ℕ} (hba : ¬ b ∣ a + 1) : (a + 1) / b = a / b := by rw [succ_div, if_neg hba, add_zero] @[simp] theorem mod_mod_of_dvd (n : nat) {m k : nat} (h : m ∣ k) : n % k % m = n % m := begin conv { to_rhs, rw ←mod_add_div n k }, rcases h with ⟨t, rfl⟩, rw [mul_assoc, add_mul_mod_self_left] end @[simp] theorem mod_mod (a n : ℕ) : (a % n) % n = a % n := (eq_zero_or_pos n).elim (λ n0, by simp [n0]) (λ npos, mod_eq_of_lt (mod_lt _ npos)) theorem add_pos_left {m : ℕ} (h : 0 < m) (n : ℕ) : 0 < m + n := calc m + n > 0 + n : nat.add_lt_add_right h n ... = n : nat.zero_add n ... ≥ 0 : zero_le n theorem add_pos_right (m : ℕ) {n : ℕ} (h : 0 < n) : 0 < m + n := begin rw add_comm, exact add_pos_left h m end theorem add_pos_iff_pos_or_pos (m n : ℕ) : 0 < m + n ↔ 0 < m ∨ 0 < n := iff.intro begin intro h, cases m with m, {simp [zero_add] at h, exact or.inr h}, exact or.inl (succ_pos _) end begin intro h, cases h with mpos npos, { apply add_pos_left mpos }, apply add_pos_right _ npos end lemma add_eq_one_iff : ∀ {a b : ℕ}, a + b = 1 ↔ (a = 0 ∧ b = 1) ∨ (a = 1 ∧ b = 0) | 0 0 := dec_trivial | 0 1 := dec_trivial | 1 0 := dec_trivial | 1 1 := dec_trivial | (a+2) _ := by rw add_right_comm; exact dec_trivial | _ (b+2) := by rw [← add_assoc]; simp only [nat.succ_inj', nat.succ_ne_zero]; simp lemma mul_eq_one_iff : ∀ {a b : ℕ}, a * b = 1 ↔ a = 1 ∧ b = 1 | 0 0 := dec_trivial | 0 1 := dec_trivial | 1 0 := dec_trivial | (a+2) 0 := by simp | 0 (b+2) := by simp | (a+1) (b+1) := ⟨λ h, by simp only [add_mul, mul_add, mul_add, one_mul, mul_one, (add_assoc _ _ _).symm, nat.succ_inj', add_eq_zero_iff] at h; simp [h.1.2, h.2], by clear_aux_decl; finish⟩ lemma mul_right_eq_self_iff {a b : ℕ} (ha : 0 < a) : a * b = a ↔ b = 1 := suffices a * b = a * 1 ↔ b = 1, by rwa mul_one at this, nat.mul_left_inj ha lemma mul_left_eq_self_iff {a b : ℕ} (hb : 0 < b) : a * b = b ↔ a = 1 := by rw [mul_comm, nat.mul_right_eq_self_iff hb] lemma lt_succ_iff_lt_or_eq {n i : ℕ} : n < i.succ ↔ (n < i ∨ n = i) := lt_succ_iff.trans le_iff_lt_or_eq theorem le_zero_iff {i : ℕ} : i ≤ 0 ↔ i = 0 := ⟨nat.eq_zero_of_le_zero, assume h, h ▸ le_refl i⟩ theorem le_add_one_iff {i j : ℕ} : i ≤ j + 1 ↔ (i ≤ j ∨ i = j + 1) := ⟨assume h, match nat.eq_or_lt_of_le h with | or.inl h := or.inr h | or.inr h := or.inl $ nat.le_of_succ_le_succ h end, or.rec (assume h, le_trans h $ nat.le_add_right _ _) le_of_eq⟩ theorem mul_self_inj {n m : ℕ} : n * n = m * m ↔ n = m := le_antisymm_iff.trans (le_antisymm_iff.trans (and_congr mul_self_le_mul_self_iff mul_self_le_mul_self_iff)).symm instance decidable_ball_lt (n : nat) (P : Π k < n, Prop) : ∀ [H : ∀ n h, decidable (P n h)], decidable (∀ n h, P n h) := begin induction n with n IH; intro; resetI, { exact is_true (λ n, dec_trivial) }, cases IH (λ k h, P k (lt_succ_of_lt h)) with h, { refine is_false (mt _ h), intros hn k h, apply hn }, by_cases p : P n (lt_succ_self n), { exact is_true (λ k h', (lt_or_eq_of_le $ le_of_lt_succ h').elim (h _) (λ e, match k, e, h' with _, rfl, h := p end)) }, { exact is_false (mt (λ hn, hn _ _) p) } end instance decidable_forall_fin {n : ℕ} (P : fin n → Prop) [H : decidable_pred P] : decidable (∀ i, P i) := decidable_of_iff (∀ k h, P ⟨k, h⟩) ⟨λ a ⟨k, h⟩, a k h, λ a k h, a ⟨k, h⟩⟩ instance decidable_ball_le (n : ℕ) (P : Π k ≤ n, Prop) [H : ∀ n h, decidable (P n h)] : decidable (∀ n h, P n h) := decidable_of_iff (∀ k (h : k < succ n), P k (le_of_lt_succ h)) ⟨λ a k h, a k (lt_succ_of_le h), λ a k h, a k _⟩ instance decidable_lo_hi (lo hi : ℕ) (P : ℕ → Prop) [H : decidable_pred P] : decidable (∀x, lo ≤ x → x < hi → P x) := decidable_of_iff (∀ x < hi - lo, P (lo + x)) ⟨λal x hl hh, by have := al (x - lo) (lt_of_not_ge $ (not_congr (nat.sub_le_sub_right_iff _ _ _ hl)).2 $ not_le_of_gt hh); rwa [nat.add_sub_of_le hl] at this, λal x h, al _ (nat.le_add_right _ _) (nat.add_lt_of_lt_sub_left h)⟩ instance decidable_lo_hi_le (lo hi : ℕ) (P : ℕ → Prop) [H : decidable_pred P] : decidable (∀x, lo ≤ x → x ≤ hi → P x) := decidable_of_iff (∀x, lo ≤ x → x < hi + 1 → P x) $ ball_congr $ λ x hl, imp_congr lt_succ_iff iff.rfl protected theorem bit0_le {n m : ℕ} (h : n ≤ m) : bit0 n ≤ bit0 m := add_le_add h h protected theorem bit1_le {n m : ℕ} (h : n ≤ m) : bit1 n ≤ bit1 m := succ_le_succ (add_le_add h h) theorem bit_le : ∀ (b : bool) {n m : ℕ}, n ≤ m → bit b n ≤ bit b m | tt n m h := nat.bit1_le h | ff n m h := nat.bit0_le h theorem bit_ne_zero (b) {n} (h : n ≠ 0) : bit b n ≠ 0 := by cases b; [exact nat.bit0_ne_zero h, exact nat.bit1_ne_zero _] theorem bit0_le_bit : ∀ (b) {m n : ℕ}, m ≤ n → bit0 m ≤ bit b n | tt m n h := le_of_lt $ nat.bit0_lt_bit1 h | ff m n h := nat.bit0_le h theorem bit_le_bit1 : ∀ (b) {m n : ℕ}, m ≤ n → bit b m ≤ bit1 n | ff m n h := le_of_lt $ nat.bit0_lt_bit1 h | tt m n h := nat.bit1_le h theorem bit_lt_bit0 : ∀ (b) {n m : ℕ}, n < m → bit b n < bit0 m | tt n m h := nat.bit1_lt_bit0 h | ff n m h := nat.bit0_lt h theorem bit_lt_bit (a b) {n m : ℕ} (h : n < m) : bit a n < bit b m := lt_of_lt_of_le (bit_lt_bit0 _ h) (bit0_le_bit _ (le_refl _)) lemma pos_of_bit0_pos {n : ℕ} (h : 0 < bit0 n) : 0 < n := by { cases n, cases h, apply succ_pos, } /- partial subtraction -/ /-- Partial predecessor operation. Returns `ppred n = some m` if `n = m + 1`, otherwise `none`. -/ @[simp] def ppred : ℕ → option ℕ | 0 := none | (n+1) := some n /-- Partial subtraction operation. Returns `psub m n = some k` if `m = n + k`, otherwise `none`. -/ @[simp] def psub (m : ℕ) : ℕ → option ℕ | 0 := some m | (n+1) := psub n >>= ppred theorem pred_eq_ppred (n : ℕ) : pred n = (ppred n).get_or_else 0 := by cases n; refl theorem sub_eq_psub (m : ℕ) : ∀ n, m - n = (psub m n).get_or_else 0 | 0 := rfl | (n+1) := (pred_eq_ppred (m-n)).trans $ by rw [sub_eq_psub, psub]; cases psub m n; refl @[simp] theorem ppred_eq_some {m : ℕ} : ∀ {n}, ppred n = some m ↔ succ m = n | 0 := by split; intro h; contradiction | (n+1) := by dsimp; split; intro h; injection h; subst n @[simp] theorem ppred_eq_none : ∀ {n : ℕ}, ppred n = none ↔ n = 0 | 0 := by simp | (n+1) := by dsimp; split; contradiction theorem psub_eq_some {m : ℕ} : ∀ {n k}, psub m n = some k ↔ k + n = m | 0 k := by simp [eq_comm] | (n+1) k := begin dsimp, apply option.bind_eq_some.trans, simp [psub_eq_some, add_comm, add_left_comm, nat.succ_eq_add_one] end theorem psub_eq_none (m n : ℕ) : psub m n = none ↔ m < n := begin cases s : psub m n; simp [eq_comm], { show m < n, refine lt_of_not_ge (λ h, _), cases le.dest h with k e, injection s.symm.trans (psub_eq_some.2 $ (add_comm _ _).trans e) }, { show n ≤ m, rw ← psub_eq_some.1 s, apply le_add_left } end theorem ppred_eq_pred {n} (h : 0 < n) : ppred n = some (pred n) := ppred_eq_some.2 $ succ_pred_eq_of_pos h theorem psub_eq_sub {m n} (h : n ≤ m) : psub m n = some (m - n) := psub_eq_some.2 $ nat.sub_add_cancel h theorem psub_add (m n k) : psub m (n + k) = do x ← psub m n, psub x k := by induction k; simp [*, add_succ, bind_assoc] /- pow -/ attribute [simp] nat.pow_zero nat.pow_one @[simp] lemma one_pow : ∀ n : ℕ, 1 ^ n = 1 | 0 := rfl | (k+1) := show 1^k * 1 = 1, by rw [mul_one, one_pow] theorem pow_add (a m n : ℕ) : a^(m + n) = a^m * a^n := by induction n; simp [*, pow_succ, mul_assoc] theorem pow_two (a : ℕ) : a ^ 2 = a * a := show (1 * a) * a = _, by rw one_mul theorem pow_dvd_pow (a : ℕ) {m n : ℕ} (h : m ≤ n) : a^m ∣ a^n := by rw [← nat.add_sub_cancel' h, pow_add]; apply dvd_mul_right theorem pow_dvd_pow_of_dvd {a b : ℕ} (h : a ∣ b) : ∀ n:ℕ, a^n ∣ b^n | 0 := dvd_refl _ | (n+1) := mul_dvd_mul (pow_dvd_pow_of_dvd n) h theorem mul_pow (a b n : ℕ) : (a * b) ^ n = a ^ n * b ^ n := by induction n; simp [*, nat.pow_succ, mul_comm, mul_assoc, mul_left_comm] protected theorem pow_mul (a b n : ℕ) : n ^ (a * b) = (n ^ a) ^ b := by induction b; simp [*, nat.succ_eq_add_one, nat.pow_add, mul_add, mul_comm] theorem pow_pos {p : ℕ} (hp : 0 < p) : ∀ n : ℕ, 0 < p ^ n | 0 := by simp | (k+1) := mul_pos (pow_pos _) hp lemma pow_eq_mul_pow_sub (p : ℕ) {m n : ℕ} (h : m ≤ n) : p ^ m * p ^ (n - m) = p ^ n := by rw [←nat.pow_add, nat.add_sub_cancel' h] lemma pow_lt_pow_succ {p : ℕ} (h : 1 < p) (n : ℕ) : p^n < p^(n+1) := suffices p^n*1 < p^n*p, by simpa, nat.mul_lt_mul_of_pos_left h (nat.pow_pos (lt_of_succ_lt h) n) lemma lt_pow_self {p : ℕ} (h : 1 < p) : ∀ n : ℕ, n < p ^ n | 0 := by simp [zero_lt_one] | (n+1) := calc n + 1 < p^n + 1 : nat.add_lt_add_right (lt_pow_self _) _ ... ≤ p ^ (n+1) : pow_lt_pow_succ h _ lemma pow_right_strict_mono {x : ℕ} (k : 2 ≤ x) : strict_mono (nat.pow x) := λ _ _, pow_lt_pow_of_lt_right k lemma pow_le_iff_le_right {x m n : ℕ} (k : 2 ≤ x) : x^m ≤ x^n ↔ m ≤ n := strict_mono.le_iff_le (pow_right_strict_mono k) lemma pow_lt_iff_lt_right {x m n : ℕ} (k : 2 ≤ x) : x^m < x^n ↔ m < n := strict_mono.lt_iff_lt (pow_right_strict_mono k) lemma pow_right_injective {x : ℕ} (k : 2 ≤ x) : function.injective (nat.pow x) := strict_mono.injective (pow_right_strict_mono k) lemma pow_left_strict_mono {m : ℕ} (k : 1 ≤ m) : strict_mono (λ (x : ℕ), x^m) := λ _ _ h, pow_lt_pow_of_lt_left h k lemma pow_le_iff_le_left {m x y : ℕ} (k : 1 ≤ m) : x^m ≤ y^m ↔ x ≤ y := strict_mono.le_iff_le (pow_left_strict_mono k) lemma pow_lt_iff_lt_left {m x y : ℕ} (k : 1 ≤ m) : x^m < y^m ↔ x < y := strict_mono.lt_iff_lt (pow_left_strict_mono k) lemma pow_left_injective {m : ℕ} (k : 1 ≤ m) : function.injective (λ (x : ℕ), x^m) := strict_mono.injective (pow_left_strict_mono k) lemma not_pos_pow_dvd : ∀ {p k : ℕ} (hp : 1 < p) (hk : 1 < k), ¬ p^k ∣ p | (succ p) (succ k) hp hk h := have (succ p)^k * succ p ∣ 1 * succ p, by simpa, have (succ p) ^ k ∣ 1, from dvd_of_mul_dvd_mul_right (succ_pos _) this, have he : (succ p) ^ k = 1, from eq_one_of_dvd_one this, have k < (succ p) ^ k, from lt_pow_self hp k, have k < 1, by rwa [he] at this, have k = 0, from eq_zero_of_le_zero $ le_of_lt_succ this, have 1 < 1, by rwa [this] at hk, absurd this dec_trivial @[simp] theorem bodd_div2_eq (n : ℕ) : bodd_div2 n = (bodd n, div2 n) := by unfold bodd div2; cases bodd_div2 n; refl @[simp] lemma bodd_bit0 (n) : bodd (bit0 n) = ff := bodd_bit ff n @[simp] lemma bodd_bit1 (n) : bodd (bit1 n) = tt := bodd_bit tt n @[simp] lemma div2_bit0 (n) : div2 (bit0 n) = n := div2_bit ff n @[simp] lemma div2_bit1 (n) : div2 (bit1 n) = n := div2_bit tt n /- iterate -/ section variables {α : Sort*} (op : α → α) @[simp] theorem iterate_zero (a : α) : op^[0] a = a := rfl @[simp] theorem iterate_succ (n : ℕ) (a : α) : op^[succ n] a = (op^[n]) (op a) := rfl theorem iterate_add : ∀ (m n : ℕ) (a : α), op^[m + n] a = (op^[m]) (op^[n] a) | m 0 a := rfl | m (succ n) a := iterate_add m n _ theorem iterate_succ' (n : ℕ) (a : α) : op^[succ n] a = op (op^[n] a) := by rw [← one_add, iterate_add]; refl theorem iterate₀ {α : Type u} {op : α → α} {x : α} (H : op x = x) {n : ℕ} : op^[n] x = x := by induction n; [simp only [iterate_zero], simp only [iterate_succ', H, *]] theorem iterate₁ {α : Type u} {β : Type v} {op : α → α} {op' : β → β} {op'' : α → β} (H : ∀ x, op' (op'' x) = op'' (op x)) {n : ℕ} {x : α} : op'^[n] (op'' x) = op'' (op^[n] x) := by induction n; [simp only [iterate_zero], simp only [iterate_succ', H, *]] theorem iterate₂ {α : Type u} {op : α → α} {op' : α → α → α} (H : ∀ x y, op (op' x y) = op' (op x) (op y)) {n : ℕ} {x y : α} : op^[n] (op' x y) = op' (op^[n] x) (op^[n] y) := by induction n; [simp only [iterate_zero], simp only [iterate_succ', H, *]] theorem iterate_cancel {α : Type u} {op op' : α → α} (H : ∀ x, op (op' x) = x) {n : ℕ} {x : α} : op^[n] (op'^[n] x) = x := by induction n; [refl, rwa [iterate_succ, iterate_succ', H]] theorem iterate_inj {α : Type u} {op : α → α} (Hinj : function.injective op) (n : ℕ) (x y : α) (H : (op^[n] x) = (op^[n] y)) : x = y := by induction n with n ih; simp only [iterate_zero, iterate_succ'] at H; [exact H, exact ih (Hinj H)] end /- size and shift -/ theorem shiftl'_ne_zero_left (b) {m} (h : m ≠ 0) (n) : shiftl' b m n ≠ 0 := by induction n; simp [shiftl', bit_ne_zero, *] theorem shiftl'_tt_ne_zero (m) : ∀ {n} (h : n ≠ 0), shiftl' tt m n ≠ 0 | 0 h := absurd rfl h | (succ n) _ := nat.bit1_ne_zero _ @[simp] theorem size_zero : size 0 = 0 := rfl @[simp] theorem size_bit {b n} (h : bit b n ≠ 0) : size (bit b n) = succ (size n) := begin rw size, conv { to_lhs, rw [binary_rec], simp [h] }, rw div2_bit, end @[simp] theorem size_bit0 {n} (h : n ≠ 0) : size (bit0 n) = succ (size n) := @size_bit ff n (nat.bit0_ne_zero h) @[simp] theorem size_bit1 (n) : size (bit1 n) = succ (size n) := @size_bit tt n (nat.bit1_ne_zero n) @[simp] theorem size_one : size 1 = 1 := by apply size_bit1 0 @[simp] theorem size_shiftl' {b m n} (h : shiftl' b m n ≠ 0) : size (shiftl' b m n) = size m + n := begin induction n with n IH; simp [shiftl'] at h ⊢, rw [size_bit h, nat.add_succ], by_cases s0 : shiftl' b m n = 0; [skip, rw [IH s0]], rw s0 at h ⊢, cases b, {exact absurd rfl h}, have : shiftl' tt m n + 1 = 1 := congr_arg (+1) s0, rw [shiftl'_tt_eq_mul_pow] at this, have m0 := succ_inj (eq_one_of_dvd_one ⟨_, this.symm⟩), subst m0, simp at this, have : n = 0 := eq_zero_of_le_zero (le_of_not_gt $ λ hn, ne_of_gt (pow_lt_pow_of_lt_right dec_trivial hn) this), subst n, refl end @[simp] theorem size_shiftl {m} (h : m ≠ 0) (n) : size (shiftl m n) = size m + n := size_shiftl' (shiftl'_ne_zero_left _ h _) theorem lt_size_self (n : ℕ) : n < 2^size n := begin rw [← one_shiftl], have : ∀ {n}, n = 0 → n < shiftl 1 (size n) := λ n e, by subst e; exact dec_trivial, apply binary_rec _ _ n, {apply this rfl}, intros b n IH, by_cases bit b n = 0, {apply this h}, rw [size_bit h, shiftl_succ], exact bit_lt_bit0 _ IH end theorem size_le {m n : ℕ} : size m ≤ n ↔ m < 2^n := ⟨λ h, lt_of_lt_of_le (lt_size_self _) (pow_le_pow_of_le_right dec_trivial h), begin rw [← one_shiftl], revert n, apply binary_rec _ _ m, { intros n h, apply zero_le }, { intros b m IH n h, by_cases e : bit b m = 0, { rw e, apply zero_le }, rw [size_bit e], cases n with n, { exact e.elim (eq_zero_of_le_zero (le_of_lt_succ h)) }, { apply succ_le_succ (IH _), apply lt_imp_lt_of_le_imp_le (λ h', bit0_le_bit _ h') h } } end⟩ theorem lt_size {m n : ℕ} : m < size n ↔ 2^m ≤ n := by rw [← not_lt, iff_not_comm, not_lt, size_le] theorem size_pos {n : ℕ} : 0 < size n ↔ 0 < n := by rw lt_size; refl theorem size_eq_zero {n : ℕ} : size n = 0 ↔ n = 0 := by have := @size_pos n; simp [pos_iff_ne_zero] at this; exact not_iff_not.1 this theorem size_pow {n : ℕ} : size (2^n) = n+1 := le_antisymm (size_le.2 $ pow_lt_pow_of_lt_right dec_trivial (lt_succ_self _)) (lt_size.2 $ le_refl _) theorem size_le_size {m n : ℕ} (h : m ≤ n) : size m ≤ size n := size_le.2 $ lt_of_le_of_lt h (lt_size_self _) /- factorial -/ /-- `fact n` is the factorial of `n`. -/ @[simp] def fact : nat → nat | 0 := 1 | (succ n) := succ n * fact n @[simp] theorem fact_zero : fact 0 = 1 := rfl @[simp] theorem fact_succ (n) : fact (succ n) = succ n * fact n := rfl @[simp] theorem fact_one : fact 1 = 1 := rfl theorem fact_pos : ∀ n, 0 < fact n | 0 := zero_lt_one | (succ n) := mul_pos (succ_pos _) (fact_pos n) theorem fact_ne_zero (n : ℕ) : fact n ≠ 0 := ne_of_gt (fact_pos _) theorem fact_dvd_fact {m n} (h : m ≤ n) : fact m ∣ fact n := begin induction n with n IH; simp, { have := eq_zero_of_le_zero h, subst m, simp }, { cases eq_or_lt_of_le h with he hl, { subst m, simp }, { apply dvd_mul_of_dvd_right (IH (le_of_lt_succ hl)) } } end theorem dvd_fact : ∀ {m n}, 0 < m → m ≤ n → m ∣ fact n | (succ m) n _ h := dvd_of_mul_right_dvd (fact_dvd_fact h) theorem fact_le {m n} (h : m ≤ n) : fact m ≤ fact n := le_of_dvd (fact_pos _) (fact_dvd_fact h) lemma fact_mul_pow_le_fact : ∀ {m n : ℕ}, m.fact * m.succ ^ n ≤ (m + n).fact | m 0 := by simp | m (n+1) := by rw [← add_assoc, nat.fact_succ, mul_comm (nat.succ _), nat.pow_succ, ← mul_assoc]; exact mul_le_mul fact_mul_pow_le_fact (nat.succ_le_succ (nat.le_add_right _ _)) (nat.zero_le _) (nat.zero_le _) lemma monotone_fact : monotone fact := λ n m, fact_le lemma fact_lt (h0 : 0 < n) : n.fact < m.fact ↔ n < m := begin split; intro h, { rw [← not_le], intro hmn, apply not_le_of_lt h (fact_le hmn) }, { have : ∀(n : ℕ), 0 < n → n.fact < n.succ.fact, { intros k hk, rw [fact_succ, succ_mul, lt_add_iff_pos_left], apply mul_pos hk (fact_pos k) }, induction h generalizing h0, { exact this _ h0, }, { refine lt_trans (h_ih h0) (this _ _), exact lt_trans h0 (lt_of_succ_le h_a) }} end lemma one_lt_fact : 1 < n.fact ↔ 1 < n := by { convert fact_lt _, refl, exact one_pos } lemma fact_eq_one : n.fact = 1 ↔ n ≤ 1 := begin split; intro h, { rw [← not_lt, ← one_lt_fact, h], apply lt_irrefl }, { cases h with h h, refl, cases h, refl } end lemma fact_inj (h0 : 1 < n.fact) : n.fact = m.fact ↔ n = m := begin split; intro h, { rcases lt_trichotomy n m with hnm|hnm|hnm, { exfalso, rw [← fact_lt, h] at hnm, exact lt_irrefl _ hnm, rw [one_lt_fact] at h0, exact lt_trans one_pos h0 }, { exact hnm }, { exfalso, rw [← fact_lt, h] at hnm, exact lt_irrefl _ hnm, rw [h, one_lt_fact] at h0, exact lt_trans one_pos h0 }}, { rw h } end /- choose -/ /-- `choose n k` is the number of `k`-element subsets in an `n`-element set. Also known as binomial coefficients. -/ def choose : ℕ → ℕ → ℕ | _ 0 := 1 | 0 (k + 1) := 0 | (n + 1) (k + 1) := choose n k + choose n (k + 1) @[simp] lemma choose_zero_right (n : ℕ) : choose n 0 = 1 := by cases n; refl @[simp] lemma choose_zero_succ (k : ℕ) : choose 0 (succ k) = 0 := rfl lemma choose_succ_succ (n k : ℕ) : choose (succ n) (succ k) = choose n k + choose n (succ k) := rfl lemma choose_eq_zero_of_lt : ∀ {n k}, n < k → choose n k = 0 | _ 0 hk := absurd hk dec_trivial | 0 (k + 1) hk := choose_zero_succ _ | (n + 1) (k + 1) hk := have hnk : n < k, from lt_of_succ_lt_succ hk, have hnk1 : n < k + 1, from lt_of_succ_lt hk, by rw [choose_succ_succ, choose_eq_zero_of_lt hnk, choose_eq_zero_of_lt hnk1] @[simp] lemma choose_self (n : ℕ) : choose n n = 1 := by induction n; simp [*, choose, choose_eq_zero_of_lt (lt_succ_self _)] @[simp] lemma choose_succ_self (n : ℕ) : choose n (succ n) = 0 := choose_eq_zero_of_lt (lt_succ_self _) @[simp] lemma choose_one_right (n : ℕ) : choose n 1 = n := by induction n; simp [*, choose, add_comm] /-- `choose n 2` is the `n`-th triangle number. -/ lemma choose_two_right (n : ℕ) : choose n 2 = n * (n - 1) / 2 := begin induction n with n ih, simp, {rw triangle_succ n, simp [choose, ih], rw add_comm}, end lemma choose_pos : ∀ {n k}, k ≤ n → 0 < choose n k | 0 _ hk := by rw [eq_zero_of_le_zero hk]; exact dec_trivial | (n + 1) 0 hk := by simp; exact dec_trivial | (n + 1) (k + 1) hk := by rw choose_succ_succ; exact add_pos_of_pos_of_nonneg (choose_pos (le_of_succ_le_succ hk)) (nat.zero_le _) lemma succ_mul_choose_eq : ∀ n k, succ n * choose n k = choose (succ n) (succ k) * succ k | 0 0 := dec_trivial | 0 (k + 1) := by simp [choose] | (n + 1) 0 := by simp | (n + 1) (k + 1) := by rw [choose_succ_succ (succ n) (succ k), add_mul, ←succ_mul_choose_eq, mul_succ, ←succ_mul_choose_eq, add_right_comm, ←mul_add, ←choose_succ_succ, ←succ_mul] lemma choose_mul_fact_mul_fact : ∀ {n k}, k ≤ n → choose n k * fact k * fact (n - k) = fact n | 0 _ hk := by simp [eq_zero_of_le_zero hk] | (n + 1) 0 hk := by simp | (n + 1) (succ k) hk := begin cases lt_or_eq_of_le hk with hk₁ hk₁, { have h : choose n k * fact (succ k) * fact (n - k) = succ k * fact n := by rw ← choose_mul_fact_mul_fact (le_of_succ_le_succ hk); simp [fact_succ, mul_comm, mul_left_comm], have h₁ : fact (n - k) = (n - k) * fact (n - succ k) := by rw [← succ_sub_succ, succ_sub (le_of_lt_succ hk₁), fact_succ], have h₂ : choose n (succ k) * fact (succ k) * ((n - k) * fact (n - succ k)) = (n - k) * fact n := by rw ← choose_mul_fact_mul_fact (le_of_lt_succ hk₁); simp [fact_succ, mul_comm, mul_left_comm, mul_assoc], have h₃ : k * fact n ≤ n * fact n := mul_le_mul_right _ (le_of_succ_le_succ hk), rw [choose_succ_succ, add_mul, add_mul, succ_sub_succ, h, h₁, h₂, ← add_one, add_mul, nat.mul_sub_right_distrib, fact_succ, ← nat.add_sub_assoc h₃, add_assoc, ← add_mul, nat.add_sub_cancel_left, add_comm] }, { simp [hk₁, mul_comm, choose, nat.sub_self] } end theorem choose_eq_fact_div_fact {n k : ℕ} (hk : k ≤ n) : choose n k = fact n / (fact k * fact (n - k)) := begin have : fact n = choose n k * (fact k * fact (n - k)) := by rw ← mul_assoc; exact (choose_mul_fact_mul_fact hk).symm, exact (nat.div_eq_of_eq_mul_left (mul_pos (fact_pos _) (fact_pos _)) this).symm end theorem fact_mul_fact_dvd_fact {n k : ℕ} (hk : k ≤ n) : fact k * fact (n - k) ∣ fact n := by rw [←choose_mul_fact_mul_fact hk, mul_assoc]; exact dvd_mul_left _ _ @[simp] lemma choose_symm {n k : ℕ} (hk : k ≤ n) : choose n (n-k) = choose n k := by rw [choose_eq_fact_div_fact hk, choose_eq_fact_div_fact (sub_le _ _), nat.sub_sub_self hk, mul_comm] lemma choose_succ_right_eq (n k : ℕ) : choose n (k + 1) * (k + 1) = choose n k * (n - k) := begin have e : (n+1) * choose n k = choose n k * (k+1) + choose n (k+1) * (k+1), rw [← right_distrib, ← choose_succ_succ, succ_mul_choose_eq], rw [← nat.sub_eq_of_eq_add e, mul_comm, ← nat.mul_sub_left_distrib, nat.add_sub_add_right] end @[simp] lemma choose_succ_self_right : ∀ (n:ℕ), (n+1).choose n = n+1 | 0 := rfl | (n+1) := by rw [choose_succ_succ, choose_succ_self_right, choose_self] lemma choose_mul_succ_eq (n k : ℕ) : (n.choose k) * (n + 1) = ((n+1).choose k) * (n + 1 - k) := begin induction k with k ih, { simp }, by_cases hk : n < k + 1, { rw [choose_eq_zero_of_lt hk, sub_eq_zero_of_le hk, zero_mul, mul_zero] }, push_neg at hk, replace hk : k + 1 ≤ n + 1 := _root_.le_add_right hk, rw [choose_succ_succ], rw [add_mul, succ_sub_succ], rw [← choose_succ_right_eq], rw [← succ_sub_succ, nat.mul_sub_left_distrib], symmetry, apply nat.add_sub_cancel', exact mul_le_mul_left _ hk, end section find_greatest /-- `find_greatest P b` is the largest `i ≤ bound` such that `P i` holds, or `0` if no such `i` exists -/ protected def find_greatest (P : ℕ → Prop) [decidable_pred P] : ℕ → ℕ | 0 := 0 | (n + 1) := if P (n + 1) then n + 1 else find_greatest n variables {P : ℕ → Prop} [decidable_pred P] @[simp] lemma find_greatest_zero : nat.find_greatest P 0 = 0 := rfl @[simp] lemma find_greatest_eq : ∀{b}, P b → nat.find_greatest P b = b | 0 h := rfl | (n + 1) h := by simp [nat.find_greatest, h] @[simp] lemma find_greatest_of_not {b} (h : ¬ P (b + 1)) : nat.find_greatest P (b + 1) = nat.find_greatest P b := by simp [nat.find_greatest, h] lemma find_greatest_spec_and_le : ∀{b m}, m ≤ b → P m → P (nat.find_greatest P b) ∧ m ≤ nat.find_greatest P b | 0 m hm hP := have m = 0, from le_antisymm hm (nat.zero_le _), show P 0 ∧ m ≤ 0, from this ▸ ⟨hP, le_refl _⟩ | (b + 1) m hm hP := begin by_cases h : P (b + 1), { simp [h, hm] }, { have : m ≠ b + 1 := assume this, h $ this ▸ hP, have : m ≤ b := (le_of_not_gt $ assume h : b + 1 ≤ m, this $ le_antisymm hm h), have : P (nat.find_greatest P b) ∧ m ≤ nat.find_greatest P b := find_greatest_spec_and_le this hP, simp [h, this] } end lemma find_greatest_spec {b} : (∃m, m ≤ b ∧ P m) → P (nat.find_greatest P b) | ⟨m, hmb, hm⟩ := (find_greatest_spec_and_le hmb hm).1 lemma find_greatest_le : ∀ {b}, nat.find_greatest P b ≤ b | 0 := le_refl _ | (b + 1) := have nat.find_greatest P b ≤ b + 1, from le_trans find_greatest_le (nat.le_succ b), by by_cases P (b + 1); simp [h, this] lemma le_find_greatest {b m} (hmb : m ≤ b) (hm : P m) : m ≤ nat.find_greatest P b := (find_greatest_spec_and_le hmb hm).2 lemma find_greatest_is_greatest {P : ℕ → Prop} [decidable_pred P] {b} : (∃ m, m ≤ b ∧ P m) → ∀ k, nat.find_greatest P b < k ∧ k ≤ b → ¬ P k | ⟨m, hmb, hP⟩ k ⟨hk, hkb⟩ hPk := lt_irrefl k $ lt_of_le_of_lt (le_find_greatest hkb hPk) hk lemma find_greatest_eq_zero {P : ℕ → Prop} [decidable_pred P] : ∀ {b}, (∀ n ≤ b, ¬ P n) → nat.find_greatest P b = 0 | 0 h := find_greatest_zero | (n + 1) h := begin have := nat.find_greatest_of_not (h (n + 1) (le_refl _)), rw this, exact find_greatest_eq_zero (assume k hk, h k (le_trans hk $ nat.le_succ _)) end lemma find_greatest_of_ne_zero {P : ℕ → Prop} [decidable_pred P] : ∀ {b m}, nat.find_greatest P b = m → m ≠ 0 → P m | 0 m rfl h := by { have := @find_greatest_zero P _, contradiction } | (b + 1) m rfl h := decidable.by_cases (assume hb : P (b + 1), by { have := find_greatest_eq hb, rw this, exact hb }) (assume hb : ¬ P (b + 1), find_greatest_of_ne_zero (find_greatest_of_not hb).symm h) end find_greatest section div lemma dvd_div_of_mul_dvd {a b c : ℕ} (h : a * b ∣ c) : b ∣ c / a := if ha : a = 0 then by simp [ha] else have ha : 0 < a, from nat.pos_of_ne_zero ha, have h1 : ∃ d, c = a * b * d, from h, let ⟨d, hd⟩ := h1 in have hac : a ∣ c, from dvd_of_mul_right_dvd h, have h2 : c / a = b * d, from nat.div_eq_of_eq_mul_right ha (by simpa [mul_assoc] using hd), show ∃ d, c / a = b * d, from ⟨d, h2⟩ lemma mul_dvd_of_dvd_div {a b c : ℕ} (hab : c ∣ b) (h : a ∣ b / c) : c * a ∣ b := have h1 : ∃ d, b / c = a * d, from h, have h2 : ∃ e, b = c * e, from hab, let ⟨d, hd⟩ := h1, ⟨e, he⟩ := h2 in have h3 : b = a * d * c, from nat.eq_mul_of_div_eq_left hab hd, show ∃ d, b = c * a * d, from ⟨d, by cc⟩ lemma div_mul_div {a b c d : ℕ} (hab : b ∣ a) (hcd : d ∣ c) : (a / b) * (c / d) = (a * c) / (b * d) := have exi1 : ∃ x, a = b * x, from hab, have exi2 : ∃ y, c = d * y, from hcd, if hb : b = 0 then by simp [hb] else have 0 < b, from nat.pos_of_ne_zero hb, if hd : d = 0 then by simp [hd] else have 0 < d, from nat.pos_of_ne_zero hd, begin cases exi1 with x hx, cases exi2 with y hy, rw [hx, hy, nat.mul_div_cancel_left, nat.mul_div_cancel_left], symmetry, apply nat.div_eq_of_eq_mul_left, apply mul_pos, repeat {assumption}, cc end lemma pow_dvd_of_le_of_pow_dvd {p m n k : ℕ} (hmn : m ≤ n) (hdiv : p ^ n ∣ k) : p ^ m ∣ k := have p ^ m ∣ p ^ n, from pow_dvd_pow _ hmn, dvd_trans this hdiv lemma dvd_of_pow_dvd {p k m : ℕ} (hk : 1 ≤ k) (hpk : p^k ∣ m) : p ∣ m := by rw ←nat.pow_one p; exact pow_dvd_of_le_of_pow_dvd hk hpk lemma eq_of_dvd_of_div_eq_one {a b : ℕ} (w : a ∣ b) (h : b / a = 1) : a = b := by rw [←nat.div_mul_cancel w, h, one_mul] lemma eq_zero_of_dvd_of_div_eq_zero {a b : ℕ} (w : a ∣ b) (h : b / a = 0) : b = 0 := by rw [←nat.div_mul_cancel w, h, zero_mul] lemma div_le_div_left {a b c : ℕ} (h₁ : c ≤ b) (h₂ : 0 < c) : a / b ≤ a / c := (nat.le_div_iff_mul_le _ _ h₂).2 $ le_trans (mul_le_mul_left _ h₁) (div_mul_le_self _ _) lemma div_eq_self {a b : ℕ} : a / b = a ↔ a = 0 ∨ b = 1 := begin split, { intro, cases b, { simp * at * }, { cases b, { right, refl }, { left, have : a / (b + 2) ≤ a / 2 := div_le_div_left (by simp) dec_trivial, refine eq_zero_of_le_half _, simp * at * } } }, { rintros (rfl|rfl); simp } end end div lemma exists_eq_add_of_le : ∀ {m n : ℕ}, m ≤ n → ∃ k : ℕ, n = m + k | 0 0 h := ⟨0, by simp⟩ | 0 (n+1) h := ⟨n+1, by simp⟩ | (m+1) (n+1) h := let ⟨k, hk⟩ := exists_eq_add_of_le (nat.le_of_succ_le_succ h) in ⟨k, by simp [hk, add_comm, add_left_comm]⟩ lemma exists_eq_add_of_lt : ∀ {m n : ℕ}, m < n → ∃ k : ℕ, n = m + k + 1 | 0 0 h := false.elim $ lt_irrefl _ h | 0 (n+1) h := ⟨n, by simp⟩ | (m+1) (n+1) h := let ⟨k, hk⟩ := exists_eq_add_of_le (nat.le_of_succ_le_succ h) in ⟨k, by simp [hk]⟩ lemma with_bot.add_eq_zero_iff : ∀ {n m : with_bot ℕ}, n + m = 0 ↔ n = 0 ∧ m = 0 | none m := iff_of_false dec_trivial (λ h, absurd h.1 dec_trivial) | n none := iff_of_false (by cases n; exact dec_trivial) (λ h, absurd h.2 dec_trivial) | (some n) (some m) := show (n + m : with_bot ℕ) = (0 : ℕ) ↔ (n : with_bot ℕ) = (0 : ℕ) ∧ (m : with_bot ℕ) = (0 : ℕ), by rw [← with_bot.coe_add, with_bot.coe_eq_coe, with_bot.coe_eq_coe, with_bot.coe_eq_coe, add_eq_zero_iff' (nat.zero_le _) (nat.zero_le _)] lemma with_bot.add_eq_one_iff : ∀ {n m : with_bot ℕ}, n + m = 1 ↔ (n = 0 ∧ m = 1) ∨ (n = 1 ∧ m = 0) | none none := dec_trivial | none (some m) := dec_trivial | (some n) none := iff_of_false dec_trivial (λ h, h.elim (λ h, absurd h.2 dec_trivial) (λ h, absurd h.2 dec_trivial)) | (some n) (some 0) := by erw [with_bot.coe_eq_coe, with_bot.coe_eq_coe, with_bot.coe_eq_coe, with_bot.coe_eq_coe]; simp | (some n) (some (m + 1)) := by erw [with_bot.coe_eq_coe, with_bot.coe_eq_coe, with_bot.coe_eq_coe, with_bot.coe_eq_coe, with_bot.coe_eq_coe]; simp [nat.add_succ, nat.succ_inj', nat.succ_ne_zero] -- induction /-- Induction principle starting at a non-zero number. For maps to a `Sort*` see `le_rec_on`. -/ @[elab_as_eliminator] lemma le_induction {P : nat → Prop} {m} (h0 : P m) (h1 : ∀ n, m ≤ n → P n → P (n + 1)) : ∀ n, m ≤ n → P n := by apply nat.less_than_or_equal.rec h0; exact h1 /-- Decreasing induction: if `P (k+1)` implies `P k`, then `P n` implies `P m` for all `m ≤ n`. Also works for functions to `Sort*`. -/ @[elab_as_eliminator] def decreasing_induction {P : ℕ → Sort*} (h : ∀n, P (n+1) → P n) {m n : ℕ} (mn : m ≤ n) (hP : P n) : P m := le_rec_on mn (λ k ih hsk, ih $ h k hsk) (λ h, h) hP @[simp] lemma decreasing_induction_self {P : ℕ → Sort*} (h : ∀n, P (n+1) → P n) {n : ℕ} (nn : n ≤ n) (hP : P n) : (decreasing_induction h nn hP : P n) = hP := by { dunfold decreasing_induction, rw [le_rec_on_self] } lemma decreasing_induction_succ {P : ℕ → Sort*} (h : ∀n, P (n+1) → P n) {m n : ℕ} (mn : m ≤ n) (msn : m ≤ n + 1) (hP : P (n+1)) : (decreasing_induction h msn hP : P m) = decreasing_induction h mn (h n hP) := by { dunfold decreasing_induction, rw [le_rec_on_succ] } @[simp] lemma decreasing_induction_succ' {P : ℕ → Sort*} (h : ∀n, P (n+1) → P n) {m : ℕ} (msm : m ≤ m + 1) (hP : P (m+1)) : (decreasing_induction h msm hP : P m) = h m hP := by { dunfold decreasing_induction, rw [le_rec_on_succ'] } lemma decreasing_induction_trans {P : ℕ → Sort*} (h : ∀n, P (n+1) → P n) {m n k : ℕ} (mn : m ≤ n) (nk : n ≤ k) (hP : P k) : (decreasing_induction h (le_trans mn nk) hP : P m) = decreasing_induction h mn (decreasing_induction h nk hP) := by { induction nk with k nk ih, rw [decreasing_induction_self], rw [decreasing_induction_succ h (le_trans mn nk), ih, decreasing_induction_succ] } lemma decreasing_induction_succ_left {P : ℕ → Sort*} (h : ∀n, P (n+1) → P n) {m n : ℕ} (smn : m + 1 ≤ n) (mn : m ≤ n) (hP : P n) : (decreasing_induction h mn hP : P m) = h m (decreasing_induction h smn hP) := by { rw [subsingleton.elim mn (le_trans (le_succ m) smn), decreasing_induction_trans, decreasing_induction_succ'] } end nat
5d7c376b8fc75abd5dc7bb4d865eb244a89441fb
947fa6c38e48771ae886239b4edce6db6e18d0fb
/src/number_theory/modular.lean
0f32ee0bba55b987c301783769d1b6a5f8b4677c
[ "Apache-2.0" ]
permissive
ramonfmir/mathlib
c5dc8b33155473fab97c38bd3aa6723dc289beaa
14c52e990c17f5a00c0cc9e09847af16fabbed25
refs/heads/master
1,661,979,343,526
1,660,830,384,000
1,660,830,384,000
182,072,989
0
0
null
1,555,585,876,000
1,555,585,876,000
null
UTF-8
Lean
false
false
24,550
lean
/- Copyright (c) 2021 Alex Kontorovich and Heather Macbeth and Marc Masdeu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex Kontorovich, Heather Macbeth, Marc Masdeu -/ import analysis.complex.upper_half_plane.basic import linear_algebra.general_linear_group import analysis.matrix /-! # The action of the modular group SL(2, ℤ) on the upper half-plane We define the action of `SL(2,ℤ)` on `ℍ` (via restriction of the `SL(2,ℝ)` action in `analysis.complex.upper_half_plane`). We then define the standard fundamental domain (`modular_group.fd`, `𝒟`) for this action and show (`modular_group.exists_smul_mem_fd`) that any point in `ℍ` can be moved inside `𝒟`. ## Main definitions The standard (closed) fundamental domain of the action of `SL(2,ℤ)` on `ℍ`, denoted `𝒟`: `fd := {z | 1 ≤ (z : ℂ).norm_sq ∧ |z.re| ≤ (1 : ℝ) / 2}` The standard open fundamental domain of the action of `SL(2,ℤ)` on `ℍ`, denoted `𝒟ᵒ`: `fdo := {z | 1 < (z : ℂ).norm_sq ∧ |z.re| < (1 : ℝ) / 2}` These notations are localized in the `modular` locale and can be enabled via `open_locale modular`. ## Main results Any `z : ℍ` can be moved to `𝒟` by an element of `SL(2,ℤ)`: `exists_smul_mem_fd (z : ℍ) : ∃ g : SL(2,ℤ), g • z ∈ 𝒟` If both `z` and `γ • z` are in the open domain `𝒟ᵒ` then `z = γ • z`: `eq_smul_self_of_mem_fdo_mem_fdo {z : ℍ} {g : SL(2,ℤ)} (hz : z ∈ 𝒟ᵒ) (hg : g • z ∈ 𝒟ᵒ) : z = g • z` # Discussion Standard proofs make use of the identity `g • z = a / c - 1 / (c (cz + d))` for `g = [[a, b], [c, d]]` in `SL(2)`, but this requires separate handling of whether `c = 0`. Instead, our proof makes use of the following perhaps novel identity (see `modular_group.smul_eq_lc_row0_add`): `g • z = (a c + b d) / (c^2 + d^2) + (d z - c) / ((c^2 + d^2) (c z + d))` where there is no issue of division by zero. Another feature is that we delay until the very end the consideration of special matrices `T=[[1,1],[0,1]]` (see `modular_group.T`) and `S=[[0,-1],[1,0]]` (see `modular_group.S`), by instead using abstract theory on the properness of certain maps (phrased in terms of the filters `filter.cocompact`, `filter.cofinite`, etc) to deduce existence theorems, first to prove the existence of `g` maximizing `(g•z).im` (see `modular_group.exists_max_im`), and then among those, to minimize `|(g•z).re|` (see `modular_group.exists_row_one_eq_and_min_re`). -/ /- Disable these instances as they are not the simp-normal form, and having them disabled ensures we state lemmas in this file without spurious `coe_fn` terms. -/ local attribute [-instance] matrix.special_linear_group.has_coe_to_fun local attribute [-instance] matrix.general_linear_group.has_coe_to_fun open complex (hiding abs_one abs_two abs_mul abs_add) open matrix (hiding mul_smul) matrix.special_linear_group upper_half_plane noncomputable theory local notation `SL(` n `, ` R `)`:= special_linear_group (fin n) R local prefix `↑ₘ`:1024 := @coe _ (matrix (fin 2) (fin 2) ℤ) _ open_locale upper_half_plane complex_conjugate local attribute [instance] fintype.card_fin_even namespace modular_group variables {g : SL(2, ℤ)} (z : ℍ) section bottom_row /-- The two numbers `c`, `d` in the "bottom_row" of `g=[[*,*],[c,d]]` in `SL(2, ℤ)` are coprime. -/ lemma bottom_row_coprime {R : Type*} [comm_ring R] (g : SL(2, R)) : is_coprime ((↑g : matrix (fin 2) (fin 2) R) 1 0) ((↑g : matrix (fin 2) (fin 2) R) 1 1) := begin use [- (↑g : matrix (fin 2) (fin 2) R) 0 1, (↑g : matrix (fin 2) (fin 2) R) 0 0], rw [add_comm, neg_mul, ←sub_eq_add_neg, ←det_fin_two], exact g.det_coe, end /-- Every pair `![c, d]` of coprime integers is the "bottom_row" of some element `g=[[*,*],[c,d]]` of `SL(2,ℤ)`. -/ lemma bottom_row_surj {R : Type*} [comm_ring R] : set.surj_on (λ g : SL(2, R), @coe _ (matrix (fin 2) (fin 2) R) _ g 1) set.univ {cd | is_coprime (cd 0) (cd 1)} := begin rintros cd ⟨b₀, a, gcd_eqn⟩, let A := of ![![a, -b₀], cd], have det_A_1 : det A = 1, { convert gcd_eqn, simp [A, det_fin_two, (by ring : a * (cd 1) + b₀ * (cd 0) = b₀ * (cd 0) + a * (cd 1))] }, refine ⟨⟨A, det_A_1⟩, set.mem_univ _, _⟩, ext; simp [A] end end bottom_row section tendsto_lemmas open filter continuous_linear_map local attribute [instance] matrix.normed_add_comm_group matrix.normed_space local attribute [simp] coe_smul /-- The function `(c,d) → |cz+d|^2` is proper, that is, preimages of bounded-above sets are finite. -/ lemma tendsto_norm_sq_coprime_pair : filter.tendsto (λ p : fin 2 → ℤ, ((p 0 : ℂ) * z + p 1).norm_sq) cofinite at_top := begin let π₀ : (fin 2 → ℝ) →ₗ[ℝ] ℝ := linear_map.proj 0, let π₁ : (fin 2 → ℝ) →ₗ[ℝ] ℝ := linear_map.proj 1, let f : (fin 2 → ℝ) →ₗ[ℝ] ℂ := π₀.smul_right (z:ℂ) + π₁.smul_right 1, have f_def : ⇑f = λ (p : fin 2 → ℝ), (p 0 : ℂ) * ↑z + p 1, { ext1, dsimp only [linear_map.coe_proj, real_smul, linear_map.coe_smul_right, linear_map.add_apply], rw mul_one, }, have : (λ (p : fin 2 → ℤ), norm_sq ((p 0 : ℂ) * ↑z + ↑(p 1))) = norm_sq ∘ f ∘ (λ p : fin 2 → ℤ, (coe : ℤ → ℝ) ∘ p), { ext1, rw f_def, dsimp only [function.comp], rw [of_real_int_cast, of_real_int_cast], }, rw this, have hf : f.ker = ⊥, { let g : ℂ →ₗ[ℝ] (fin 2 → ℝ) := linear_map.pi ![im_lm, im_lm.comp ((z:ℂ) • (conj_ae : ℂ →ₗ[ℝ] ℂ))], suffices : ((z:ℂ).im⁻¹ • g).comp f = linear_map.id, { exact linear_map.ker_eq_bot_of_inverse this }, apply linear_map.ext, intros c, have hz : (z:ℂ).im ≠ 0 := z.2.ne', rw [linear_map.comp_apply, linear_map.smul_apply, linear_map.id_apply], ext i, dsimp only [g, pi.smul_apply, linear_map.pi_apply, smul_eq_mul], fin_cases i, { show ((z : ℂ).im)⁻¹ * (f c).im = c 0, rw [f_def, add_im, of_real_mul_im, of_real_im, add_zero, mul_left_comm, inv_mul_cancel hz, mul_one], }, { show ((z : ℂ).im)⁻¹ * ((z : ℂ) * conj (f c)).im = c 1, rw [f_def, ring_hom.map_add, ring_hom.map_mul, mul_add, mul_left_comm, mul_conj, conj_of_real, conj_of_real, ← of_real_mul, add_im, of_real_im, zero_add, inv_mul_eq_iff_eq_mul₀ hz], simp only [of_real_im, of_real_re, mul_im, zero_add, mul_zero] } }, have h₁ := (linear_equiv.closed_embedding_of_injective hf).tendsto_cocompact, have h₂ : tendsto (λ p : fin 2 → ℤ, (coe : ℤ → ℝ) ∘ p) cofinite (cocompact _), { convert tendsto.pi_map_Coprod (λ i, int.tendsto_coe_cofinite), { rw Coprod_cofinite }, { rw Coprod_cocompact } }, exact tendsto_norm_sq_cocompact_at_top.comp (h₁.comp h₂) end /-- Given `coprime_pair` `p=(c,d)`, the matrix `[[a,b],[*,*]]` is sent to `a*c+b*d`. This is the linear map version of this operation. -/ def lc_row0 (p : fin 2 → ℤ) : (matrix (fin 2) (fin 2) ℝ) →ₗ[ℝ] ℝ := ((p 0:ℝ) • linear_map.proj 0 + (p 1:ℝ) • linear_map.proj 1 : (fin 2 → ℝ) →ₗ[ℝ] ℝ).comp (linear_map.proj 0) @[simp] lemma lc_row0_apply (p : fin 2 → ℤ) (g : matrix (fin 2) (fin 2) ℝ) : lc_row0 p g = p 0 * g 0 0 + p 1 * g 0 1 := rfl /-- Linear map sending the matrix [a, b; c, d] to the matrix [ac₀ + bd₀, - ad₀ + bc₀; c, d], for some fixed `(c₀, d₀)`. -/ @[simps] def lc_row0_extend {cd : fin 2 → ℤ} (hcd : is_coprime (cd 0) (cd 1)) : (matrix (fin 2) (fin 2) ℝ) ≃ₗ[ℝ] matrix (fin 2) (fin 2) ℝ := linear_equiv.Pi_congr_right ![begin refine linear_map.general_linear_group.general_linear_equiv ℝ (fin 2 → ℝ) (general_linear_group.to_linear (plane_conformal_matrix (cd 0 : ℝ) (-(cd 1 : ℝ)) _)), norm_cast, rw neg_sq, exact hcd.sq_add_sq_ne_zero end, linear_equiv.refl ℝ (fin 2 → ℝ)] /-- The map `lc_row0` is proper, that is, preimages of cocompact sets are finite in `[[* , *], [c, d]]`.-/ theorem tendsto_lc_row0 {cd : fin 2 → ℤ} (hcd : is_coprime (cd 0) (cd 1)) : tendsto (λ g : {g : SL(2, ℤ) // ↑ₘg 1 = cd}, lc_row0 cd ↑(↑g : SL(2, ℝ))) cofinite (cocompact ℝ) := begin let mB : ℝ → (matrix (fin 2) (fin 2) ℝ) := λ t, of ![![t, (-(1:ℤ):ℝ)], coe ∘ cd], have hmB : continuous mB, { refine continuous_matrix _, simp only [fin.forall_fin_two, mB, continuous_const, continuous_id', of_apply, cons_val_zero, cons_val_one, and_self ] }, refine filter.tendsto.of_tendsto_comp _ (comap_cocompact_le hmB), let f₁ : SL(2, ℤ) → matrix (fin 2) (fin 2) ℝ := λ g, matrix.map (↑g : matrix _ _ ℤ) (coe : ℤ → ℝ), have cocompact_ℝ_to_cofinite_ℤ_matrix : tendsto (λ m : matrix (fin 2) (fin 2) ℤ, matrix.map m (coe : ℤ → ℝ)) cofinite (cocompact _), { simpa only [Coprod_cofinite, Coprod_cocompact] using tendsto.pi_map_Coprod (λ i : fin 2, tendsto.pi_map_Coprod (λ j : fin 2, int.tendsto_coe_cofinite)) }, have hf₁ : tendsto f₁ cofinite (cocompact _) := cocompact_ℝ_to_cofinite_ℤ_matrix.comp subtype.coe_injective.tendsto_cofinite, have hf₂ : closed_embedding (lc_row0_extend hcd) := (lc_row0_extend hcd).to_continuous_linear_equiv.to_homeomorph.closed_embedding, convert hf₂.tendsto_cocompact.comp (hf₁.comp subtype.coe_injective.tendsto_cofinite) using 1, ext ⟨g, rfl⟩ i j : 3, fin_cases i; [fin_cases j, skip], -- the following are proved by `simp`, but it is replaced by `simp only` to avoid timeouts. { simp only [mB, mul_vec, dot_product, fin.sum_univ_two, _root_.coe_coe, coe_matrix_coe, int.coe_cast_ring_hom, lc_row0_apply, function.comp_app, cons_val_zero, lc_row0_extend_apply, linear_map.general_linear_group.coe_fn_general_linear_equiv, general_linear_group.to_linear_apply, coe_plane_conformal_matrix, neg_neg, mul_vec_lin_apply, cons_val_one, head_cons, of_apply] }, { convert congr_arg (λ n : ℤ, (-n:ℝ)) g.det_coe.symm using 1, simp only [f₁, mul_vec, dot_product, fin.sum_univ_two, matrix.det_fin_two, function.comp_app, subtype.coe_mk, lc_row0_extend_apply, cons_val_zero, linear_map.general_linear_group.coe_fn_general_linear_equiv, general_linear_group.to_linear_apply, coe_plane_conformal_matrix, mul_vec_lin_apply, cons_val_one, head_cons, map_apply, neg_mul, int.cast_sub, int.cast_mul, neg_sub, of_apply], ring }, { refl } end /-- This replaces `(g•z).re = a/c + *` in the standard theory with the following novel identity: `g • z = (a c + b d) / (c^2 + d^2) + (d z - c) / ((c^2 + d^2) (c z + d))` which does not need to be decomposed depending on whether `c = 0`. -/ lemma smul_eq_lc_row0_add {p : fin 2 → ℤ} (hp : is_coprime (p 0) (p 1)) (hg : ↑ₘg 1 = p) : ↑(g • z) = ((lc_row0 p ↑(g : SL(2, ℝ))) : ℂ) / (p 0 ^ 2 + p 1 ^ 2) + ((p 1 : ℂ) * z - p 0) / ((p 0 ^ 2 + p 1 ^ 2) * (p 0 * z + p 1)) := begin have nonZ1 : (p 0 : ℂ) ^ 2 + (p 1) ^ 2 ≠ 0 := by exact_mod_cast hp.sq_add_sq_ne_zero, have : (coe : ℤ → ℝ) ∘ p ≠ 0 := λ h, hp.ne_zero (by ext i; simpa using congr_fun h i), have nonZ2 : (p 0 : ℂ) * z + p 1 ≠ 0 := by simpa using linear_ne_zero _ z this, field_simp [nonZ1, nonZ2, denom_ne_zero, -upper_half_plane.denom, -denom_apply], rw (by simp : (p 1 : ℂ) * z - p 0 = ((p 1) * z - p 0) * ↑(det (↑g : matrix (fin 2) (fin 2) ℤ))), rw [←hg, det_fin_two], simp only [int.coe_cast_ring_hom, coe_matrix_coe, int.cast_mul, of_real_int_cast, map_apply, denom, int.cast_sub, _root_.coe_coe,coe_GL_pos_coe_GL_coe_matrix], ring, end lemma tendsto_abs_re_smul {p : fin 2 → ℤ} (hp : is_coprime (p 0) (p 1)) : tendsto (λ g : {g : SL(2, ℤ) // ↑ₘg 1 = p}, |((g : SL(2, ℤ)) • z).re|) cofinite at_top := begin suffices : tendsto (λ g : (λ g : SL(2, ℤ), ↑ₘg 1) ⁻¹' {p}, (((g : SL(2, ℤ)) • z).re)) cofinite (cocompact ℝ), { exact tendsto_norm_cocompact_at_top.comp this }, have : ((p 0 : ℝ) ^ 2 + p 1 ^ 2)⁻¹ ≠ 0, { apply inv_ne_zero, exact_mod_cast hp.sq_add_sq_ne_zero }, let f := homeomorph.mul_right₀ _ this, let ff := homeomorph.add_right (((p 1:ℂ)* z - p 0) / ((p 0 ^ 2 + p 1 ^ 2) * (p 0 * z + p 1))).re, convert ((f.trans ff).closed_embedding.tendsto_cocompact).comp (tendsto_lc_row0 hp), ext g, change ((g : SL(2, ℤ)) • z).re = (lc_row0 p ↑(↑g : SL(2, ℝ))) / (p 0 ^ 2 + p 1 ^ 2) + (((p 1:ℂ )* z - p 0) / ((p 0 ^ 2 + p 1 ^ 2) * (p 0 * z + p 1))).re, exact_mod_cast (congr_arg complex.re (smul_eq_lc_row0_add z hp g.2)) end end tendsto_lemmas section fundamental_domain local attribute [simp] coe_smul re_smul /-- For `z : ℍ`, there is a `g : SL(2,ℤ)` maximizing `(g•z).im` -/ lemma exists_max_im : ∃ g : SL(2, ℤ), ∀ g' : SL(2, ℤ), (g' • z).im ≤ (g • z).im := begin classical, let s : set (fin 2 → ℤ) := {cd | is_coprime (cd 0) (cd 1)}, have hs : s.nonempty := ⟨![1, 1], is_coprime_one_left⟩, obtain ⟨p, hp_coprime, hp⟩ := filter.tendsto.exists_within_forall_le hs (tendsto_norm_sq_coprime_pair z), obtain ⟨g, -, hg⟩ := bottom_row_surj hp_coprime, refine ⟨g, λ g', _⟩, rw [special_linear_group.im_smul_eq_div_norm_sq, special_linear_group.im_smul_eq_div_norm_sq, div_le_div_left], { simpa [← hg] using hp (↑ₘg' 1) (bottom_row_coprime g') }, { exact z.im_pos }, { exact norm_sq_denom_pos g' z }, { exact norm_sq_denom_pos g z }, end /-- Given `z : ℍ` and a bottom row `(c,d)`, among the `g : SL(2,ℤ)` with this bottom row, minimize `|(g•z).re|`. -/ lemma exists_row_one_eq_and_min_re {cd : fin 2 → ℤ} (hcd : is_coprime (cd 0) (cd 1)) : ∃ g : SL(2,ℤ), ↑ₘg 1 = cd ∧ (∀ g' : SL(2,ℤ), ↑ₘg 1 = ↑ₘg' 1 → |(g • z).re| ≤ |(g' • z).re|) := begin haveI : nonempty {g : SL(2, ℤ) // ↑ₘg 1 = cd} := let ⟨x, hx⟩ := bottom_row_surj hcd in ⟨⟨x, hx.2⟩⟩, obtain ⟨g, hg⟩ := filter.tendsto.exists_forall_le (tendsto_abs_re_smul z hcd), refine ⟨g, g.2, _⟩, { intros g1 hg1, have : g1 ∈ ((λ g : SL(2, ℤ), ↑ₘg 1) ⁻¹' {cd}), { rw [set.mem_preimage, set.mem_singleton_iff], exact eq.trans hg1.symm (set.mem_singleton_iff.mp (set.mem_preimage.mp g.2)) }, exact hg ⟨g1, this⟩ }, end /-- The matrix `T = [[1,1],[0,1]]` as an element of `SL(2,ℤ)` -/ def T : SL(2,ℤ) := ⟨!![1, 1; 0, 1], by norm_num [matrix.det_fin_two_of]⟩ /-- The matrix `S = [[0,-1],[1,0]]` as an element of `SL(2,ℤ)` -/ def S : SL(2,ℤ) := ⟨!![0, -1; 1, 0], by norm_num [matrix.det_fin_two_of]⟩ lemma coe_S : ↑ₘS = !![0, -1; 1, 0] := rfl lemma coe_T : ↑ₘT = !![1, 1; 0, 1] := rfl lemma coe_T_inv : ↑ₘ(T⁻¹) = !![1, -1; 0, 1] := by simp [coe_inv, coe_T, adjugate_fin_two] lemma coe_T_zpow (n : ℤ) : ↑ₘ(T ^ n) = !![1, n; 0, 1] := begin induction n using int.induction_on with n h n h, { rw [zpow_zero, coe_one, matrix.one_fin_two] }, { simp_rw [zpow_add, zpow_one, coe_mul, h, coe_T, matrix.mul_fin_two], congrm !![_, _; _, _], rw [mul_one, mul_one, add_comm] }, { simp_rw [zpow_sub, zpow_one, coe_mul, h, coe_T_inv, matrix.mul_fin_two], congrm !![_, _; _, _]; ring }, end @[simp] lemma T_pow_mul_apply_one (n : ℤ) (g : SL(2, ℤ)) : ↑ₘ(T ^ n * g) 1 = ↑ₘg 1 := by simp [coe_T_zpow, matrix.mul, matrix.dot_product, fin.sum_univ_succ] @[simp] lemma T_mul_apply_one (g : SL(2, ℤ)) : ↑ₘ(T * g) 1 = ↑ₘg 1 := by simpa using T_pow_mul_apply_one 1 g @[simp] lemma T_inv_mul_apply_one (g : SL(2, ℤ)) : ↑ₘ(T⁻¹ * g) 1 = ↑ₘg 1 := by simpa using T_pow_mul_apply_one (-1) g lemma coe_T_zpow_smul_eq {n : ℤ} : (↑((T^n) • z) : ℂ) = z + n := by simp [coe_T_zpow] lemma re_T_zpow_smul (n : ℤ) : ((T^n) • z).re = z.re + n := by rw [←coe_re, coe_T_zpow_smul_eq, add_re, int_cast_re, coe_re] lemma im_T_zpow_smul (n : ℤ) : ((T^n) • z).im = z.im := by rw [←coe_im, coe_T_zpow_smul_eq, add_im, int_cast_im, add_zero, coe_im] lemma re_T_smul : (T • z).re = z.re + 1 := by simpa using re_T_zpow_smul z 1 lemma im_T_smul : (T • z).im = z.im := by simpa using im_T_zpow_smul z 1 lemma re_T_inv_smul : (T⁻¹ • z).re = z.re - 1 := by simpa using re_T_zpow_smul z (-1) lemma im_T_inv_smul : (T⁻¹ • z).im = z.im := by simpa using im_T_zpow_smul z (-1) variables {z} -- If instead we had `g` and `T` of type `PSL(2, ℤ)`, then we could simply state `g = T^n`. lemma exists_eq_T_zpow_of_c_eq_zero (hc : ↑ₘg 1 0 = 0) : ∃ (n : ℤ), ∀ (z : ℍ), g • z = T^n • z := begin have had := g.det_coe, replace had : ↑ₘg 0 0 * ↑ₘg 1 1 = 1, { rw [det_fin_two, hc] at had, linarith, }, rcases int.eq_one_or_neg_one_of_mul_eq_one' had with ⟨ha, hd⟩ | ⟨ha, hd⟩, { use ↑ₘg 0 1, suffices : g = T^(↑ₘg 0 1), { intros z, conv_lhs { rw this, }, }, ext i j, fin_cases i; fin_cases j; simp [ha, hc, hd, coe_T_zpow], }, { use -↑ₘg 0 1, suffices : g = -T^(-↑ₘg 0 1), { intros z, conv_lhs { rw [this, SL_neg_smul], }, }, ext i j, fin_cases i; fin_cases j; simp [ha, hc, hd, coe_T_zpow], }, end /- If `c = 1`, then `g` factorises into a product terms involving only `T` and `S`. -/ lemma g_eq_of_c_eq_one (hc : ↑ₘg 1 0 = 1) : g = T^(↑ₘg 0 0) * S * T^(↑ₘg 1 1) := begin have hg := g.det_coe.symm, replace hg : ↑ₘg 0 1 = ↑ₘg 0 0 * ↑ₘg 1 1 - 1, { rw [det_fin_two, hc] at hg, linarith, }, refine subtype.ext _, conv_lhs { rw matrix.eta_fin_two ↑ₘg }, rw [hc, hg], simp only [coe_mul, coe_T_zpow, coe_S, mul_fin_two], congrm !![_, _; _, _]; ring end /-- If `1 < |z|`, then `|S • z| < 1`. -/ lemma norm_sq_S_smul_lt_one (h: 1 < norm_sq z) : norm_sq ↑(S • z) < 1 := by simpa [coe_S] using (inv_lt_inv z.norm_sq_pos zero_lt_one).mpr h /-- If `|z| < 1`, then applying `S` strictly decreases `im`. -/ lemma im_lt_im_S_smul (h: norm_sq z < 1) : z.im < (S • z).im := begin have : z.im < z.im / norm_sq (z:ℂ), { have imz : 0 < z.im := im_pos z, apply (lt_div_iff z.norm_sq_pos).mpr, nlinarith }, convert this, simp only [special_linear_group.im_smul_eq_div_norm_sq], field_simp [norm_sq_denom_ne_zero, norm_sq_ne_zero, S] end /-- The standard (closed) fundamental domain of the action of `SL(2,ℤ)` on `ℍ`. -/ def fd : set ℍ := {z | 1 ≤ (z : ℂ).norm_sq ∧ |z.re| ≤ (1 : ℝ) / 2} /-- The standard open fundamental domain of the action of `SL(2,ℤ)` on `ℍ`. -/ def fdo : set ℍ := {z | 1 < (z : ℂ).norm_sq ∧ |z.re| < (1 : ℝ) / 2} localized "notation `𝒟` := modular_group.fd" in modular localized "notation `𝒟ᵒ` := modular_group.fdo" in modular lemma abs_two_mul_re_lt_one_of_mem_fdo (h : z ∈ 𝒟ᵒ) : |2 * z.re| < 1 := begin rw [abs_mul, abs_two, ← lt_div_iff' (@two_pos ℝ _ _)], exact h.2, end lemma three_lt_four_mul_im_sq_of_mem_fdo (h : z ∈ 𝒟ᵒ) : 3 < 4 * z.im^2 := begin have : 1 < z.re * z.re + z.im * z.im := by simpa [complex.norm_sq_apply] using h.1, have := h.2, cases abs_cases z.re; nlinarith, end /-- If `z ∈ 𝒟ᵒ`, and `n : ℤ`, then `|z + n| > 1`. -/ lemma one_lt_norm_sq_T_zpow_smul (hz : z ∈ 𝒟ᵒ) (n : ℤ) : 1 < norm_sq (((T^n) • z) : ℍ) := begin have hz₁ : 1 < z.re * z.re + z.im * z.im := hz.1, have hzn := int.nneg_mul_add_sq_of_abs_le_one n (abs_two_mul_re_lt_one_of_mem_fdo hz).le, have : 1 < (z.re + ↑n) * (z.re + ↑n) + z.im * z.im, { linarith, }, simpa [coe_T_zpow, norm_sq], end lemma eq_zero_of_mem_fdo_of_T_zpow_mem_fdo {n : ℤ} (hz : z ∈ 𝒟ᵒ) (hg : (T^n) • z ∈ 𝒟ᵒ) : n = 0 := begin suffices : |(n : ℝ)| < 1, { rwa [← int.cast_abs, ← int.cast_one, int.cast_lt, int.abs_lt_one_iff] at this, }, have h₁ := hz.2, have h₂ := hg.2, rw [re_T_zpow_smul] at h₂, calc |(n : ℝ)| ≤ |z.re| + |z.re + (n : ℝ)| : abs_add' (n : ℝ) z.re ... < 1/2 + 1/2 : add_lt_add h₁ h₂ ... = 1 : add_halves 1, end /-- Any `z : ℍ` can be moved to `𝒟` by an element of `SL(2,ℤ)` -/ lemma exists_smul_mem_fd (z : ℍ) : ∃ g : SL(2,ℤ), g • z ∈ 𝒟 := begin -- obtain a g₀ which maximizes im (g • z), obtain ⟨g₀, hg₀⟩ := exists_max_im z, -- then among those, minimize re obtain ⟨g, hg, hg'⟩ := exists_row_one_eq_and_min_re z (bottom_row_coprime g₀), refine ⟨g, _⟩, -- `g` has same max im property as `g₀` have hg₀' : ∀ (g' : SL(2,ℤ)), (g' • z).im ≤ (g • z).im, { have hg'' : (g • z).im = (g₀ • z).im, { rw [special_linear_group.im_smul_eq_div_norm_sq, special_linear_group.im_smul_eq_div_norm_sq, denom_apply, denom_apply, hg]}, simpa only [hg''] using hg₀ }, split, { -- Claim: `1 ≤ ⇑norm_sq ↑(g • z)`. If not, then `S•g•z` has larger imaginary part contrapose! hg₀', refine ⟨S * g, _⟩, rw mul_smul, exact im_lt_im_S_smul hg₀' }, { show |(g • z).re| ≤ 1 / 2, -- if not, then either `T` or `T'` decrease |Re|. rw abs_le, split, { contrapose! hg', refine ⟨T * g, (T_mul_apply_one _).symm, _⟩, rw [mul_smul, re_T_smul], cases abs_cases ((g • z).re + 1); cases abs_cases (g • z).re; linarith }, { contrapose! hg', refine ⟨T⁻¹ * g, (T_inv_mul_apply_one _).symm, _⟩, rw [mul_smul, re_T_inv_smul], cases abs_cases ((g • z).re - 1); cases abs_cases (g • z).re; linarith } } end section unique_representative variables {z} /-- An auxiliary result en route to `modular_group.c_eq_zero`. -/ lemma abs_c_le_one (hz : z ∈ 𝒟ᵒ) (hg : g • z ∈ 𝒟ᵒ) : |↑ₘg 1 0| ≤ 1 := begin let c' : ℤ := ↑ₘg 1 0, let c : ℝ := (c' : ℝ), suffices : 3 * c^2 < 4, { rw [← int.cast_pow, ← int.cast_three, ← int.cast_four, ← int.cast_mul, int.cast_lt] at this, replace this : c' ^ 2 ≤ 1 ^ 2, { linarith, }, rwa [sq_le_sq, abs_one] at this }, suffices : c ≠ 0 → 9 * c^4 < 16, { rcases eq_or_ne c 0 with hc | hc, { rw hc, norm_num, }, { refine (abs_lt_of_sq_lt_sq' _ (by norm_num)).2, specialize this hc, linarith, }, }, intros hc, replace hc : 0 < c^4, { rw pow_bit0_pos_iff; trivial, }, have h₁ := mul_lt_mul_of_pos_right (mul_lt_mul'' (three_lt_four_mul_im_sq_of_mem_fdo hg) (three_lt_four_mul_im_sq_of_mem_fdo hz) (by linarith) (by linarith)) hc, have h₂ : (c * z.im) ^ 4 / norm_sq (denom ↑g z) ^ 2 ≤ 1 := div_le_one_of_le (pow_four_le_pow_two_of_pow_two_le (upper_half_plane.c_mul_im_sq_le_norm_sq_denom z g)) (sq_nonneg _), let nsq := norm_sq (denom g z), calc 9 * c^4 < c^4 * z.im^2 * (g • z).im^2 * 16 : by linarith ... = c^4 * z.im^4 / nsq^2 * 16 : by { rw [special_linear_group.im_smul_eq_div_norm_sq, div_pow], ring, } ... ≤ 16 : by { rw ← mul_pow, linarith, }, end /-- An auxiliary result en route to `modular_group.eq_smul_self_of_mem_fdo_mem_fdo`. -/ lemma c_eq_zero (hz : z ∈ 𝒟ᵒ) (hg : g • z ∈ 𝒟ᵒ) : ↑ₘg 1 0 = 0 := begin have hp : ∀ {g' : SL(2, ℤ)} (hg' : g' • z ∈ 𝒟ᵒ), ↑ₘg' 1 0 ≠ 1, { intros, by_contra hc, let a := ↑ₘg' 0 0, let d := ↑ₘg' 1 1, have had : T^(-a) * g' = S * T^d, { rw g_eq_of_c_eq_one hc, group, }, let w := T^(-a) • (g' • z), have h₁ : w = S • (T^d • z), { simp only [w, ← mul_smul, had], }, replace h₁ : norm_sq w < 1 := h₁.symm ▸ norm_sq_S_smul_lt_one (one_lt_norm_sq_T_zpow_smul hz d), have h₂ : 1 < norm_sq w := one_lt_norm_sq_T_zpow_smul hg' (-a), linarith, }, have hn : ↑ₘg 1 0 ≠ -1, { intros hc, replace hc : ↑ₘ(-g) 1 0 = 1, { simp [eq_neg_of_eq_neg hc], }, replace hg : (-g) • z ∈ 𝒟ᵒ := (SL_neg_smul g z).symm ▸ hg, exact hp hg hc, }, specialize hp hg, rcases (int.abs_le_one_iff.mp $ abs_c_le_one hz hg); tauto, end /-- Second Main Fundamental Domain Lemma: if both `z` and `g • z` are in the open domain `𝒟ᵒ`, where `z : ℍ` and `g : SL(2,ℤ)`, then `z = g • z`. -/ lemma eq_smul_self_of_mem_fdo_mem_fdo (hz : z ∈ 𝒟ᵒ) (hg : g • z ∈ 𝒟ᵒ) : z = g • z := begin obtain ⟨n, hn⟩ := exists_eq_T_zpow_of_c_eq_zero (c_eq_zero hz hg), rw hn at hg ⊢, simp [eq_zero_of_mem_fdo_of_T_zpow_mem_fdo hz hg, one_smul], end end unique_representative end fundamental_domain end modular_group
c4fd4ec0e93b85abaad7b32f77a12d32c450eced
4fa118f6209450d4e8d058790e2967337811b2b5
/src/valuation/canonical.lean
68a8907cbc97f412e35f6a720a6925e518e51e43
[ "Apache-2.0" ]
permissive
leanprover-community/lean-perfectoid-spaces
16ab697a220ed3669bf76311daa8c466382207f7
95a6520ce578b30a80b4c36e36ab2d559a842690
refs/heads/master
1,639,557,829,139
1,638,797,866,000
1,638,797,866,000
135,769,296
96
10
Apache-2.0
1,638,797,866,000
1,527,892,754,000
Lean
UTF-8
Lean
false
false
32,925
lean
import for_mathlib.quotient_group import valuation.localization /-! # The canonical valuation The purpose of this file is to define a “canonical” valuation equivalent to a given valuation. The whole raison d'etre for this is that there are set-theoretic issues with the equivalence “relation” on valuations, because the target group Γ can be arbitrary. ## Idea The main idea is this. If v : R → Γ₀ is an arbitrary valuation, then v extends to a valuation on K = Frac(R/supp(v)) and hence to a monoid homomorphism K^* → units Γ₀, whose kernel is A^*, the units in the valuation ring (or equivalently the things in K^* of norm at most 1). This embeds K^*/A^* into Γ₀ and hence gives K^*/A^* the structure of a linearly ordered commutative group. There is an induced map R → (K^*/A^*), and we call this the _canonical valuation_ associated to v; this valuation is equivalent to v. A technical advantage that this valuation has from the point of view of Lean's type theory is that if R is in universe u₁ and Γ₀ in universe u₂, then v : valuation R Γ₀ will be in universe `max u₁ u₂` but the canonical valuation will just be in universe u₁. In particular, if v and v' are equivalent then their associated canonical valuations are isomorphic and furthermore in the same universe. ## Implementation details All of the below names are in the `valuation` namespace. The canonical valuation takes values in `value_monoid v`. Technically this is not defined exactly in the way explained above. So `value_monoid v` is not defined as `with_zero (K^* / A^*)`. Instead, we take the equivalence relation on K^* given by A^*, and extend it in the obvious way to K. The resulting quotient is naturally a monoid, with an order and a zero element. Indeed, it is a linear_ordered_comm_group_with_zero. Its unit group is canonically isomorphic to K^*/A^*. (Note that it is also isomorphic to the subgroup of Γ₀ which Wedhorn calls the value group in [Wedhorn; 1.22]). `value_monoid.to_Γ₀` is the monoid homomorphism to Γ₀. `canonical_valuation v` is the canonical valuation. `canonical_valuation.to_Γ₀ v` is the lemma that says that we can recover v from `canonical_valuation v` using the monoid homomorphism from (value_monoid v) to Γ₀. -- TODO -- rewrite this when I've remembered what we proved. We then prove some of Proposition-and-Definition 1.27 of Wedhorn, where we note that we used (iii) for the definition, and we're now using a different definition to Wedhorn for the value group (because it's isomorphic so no mathematician will care, and it's easier for us because it's in a smaller universe). -/ local attribute [instance] classical.prop_decidable local attribute [instance, priority 0] classical.DLO noncomputable theory universes u u₀ u₁ u₂ u₃ open linear_ordered_structure variables {R : Type u₀} [comm_ring R] /- TODO(jmc): Refactor this file to use valued_field, instead of working explicitly with v.valuation_field. -/ namespace valuation variables {Γ₀ : Type u} [linear_ordered_comm_group_with_zero Γ₀] variables (v : valuation R Γ₀) /-- The elements of `units (valuation_field v)` with norm 1. -/ definition valuation_field_norm_one := is_group_hom.ker (units.map (v.on_valuation_field : v.valuation_field →* Γ₀)) /-- `valuation_field_norm_one v is a normal subgroup of `units (valuation_field v)`. -/ instance (v : valuation R Γ₀) : normal_subgroup (valuation_field_norm_one v) := by unfold valuation_field_norm_one; apply_instance namespace value_monoid /-- The relation on a valuation field induced by the valuation: a ≈ b if and only if there is a unit c of valuation 1 such that a * c = b.-/ def quotient_rel (a b : v.valuation_field) : Prop := ∃ c : units v.valuation_field, c ∈ v.valuation_field_norm_one ∧ a * c = b namespace quotient_rel lemma refl (a : v.valuation_field) : quotient_rel v a a := ⟨1, is_submonoid.one_mem _, mul_one a⟩ lemma symm (a b : v.valuation_field) : quotient_rel v a b → quotient_rel v b a := by { rintro ⟨c, hc, rfl⟩, exact ⟨c⁻¹, is_subgroup.inv_mem hc, c.mul_inv_cancel_right a⟩ } lemma trans (a b c : v.valuation_field) : quotient_rel v a b → quotient_rel v b c → quotient_rel v a c := begin rintro ⟨c, hc, rfl⟩ ⟨c', hc', rfl⟩, exact ⟨c * c', is_submonoid.mul_mem hc hc', (mul_assoc _ _ _).symm⟩ end end quotient_rel /-- The setoid on a valuation field induced by the valuation: a ≈ b if and only if there is a unit c of valuation 1 such that a * c = b.-/ def setoid : setoid (v.valuation_field) := { r := quotient_rel v, iseqv := ⟨quotient_rel.refl v, quotient_rel.symm v, quotient_rel.trans v⟩ } end value_monoid /-- The value group of the canonical valuation.-/ def value_monoid (v : valuation R Γ₀) : Type u₀ := @quotient v.valuation_field (value_monoid.setoid v) namespace value_monoid open function /-- The natural map from the canonical value monoid to Γ₀, for a valuation with values in Γ₀. -/ def to_Γ₀ : v.value_monoid → Γ₀ := λ x, quotient.lift_on' x v.on_valuation_field $ begin rintros a b ⟨c, hc, rfl⟩, replace hc : v.on_valuation_field c = 1 := units.ext_iff.mp (is_subgroup.mem_trivial.mp hc), rw [v.on_valuation_field.map_mul, hc, mul_one], end lemma to_Γ₀_inj : injective (to_Γ₀ v) := begin rintros ⟨a⟩ ⟨b⟩ h, change v.on_valuation_field a = v.on_valuation_field b at h, by_cases ha : a = 0, { subst a, rw [valuation.map_zero, eq_comm, valuation.zero_iff] at h, rw h }, { have hb : b ≠ 0, { rintro rfl, rw [valuation.map_zero, valuation.zero_iff] at h, exact ha h }, refine quotient.sound' ⟨(units.mk0 a ha)⁻¹ * (units.mk0 b hb), is_subgroup.mem_trivial.mpr _, (units.mk0 a ha).mul_inv_cancel_left _⟩, rw ← v.on_valuation_field.ne_zero_iff at hb, simp [units.ext_iff, h, hb] } end /--The linear order on the canonical value monoid associated with a valuation.-/ instance : linear_order (v.value_monoid) := linear_order.lift (to_Γ₀ v) (to_Γ₀_inj v) infer_instance lemma to_Γ₀_strict_mono : strict_mono (to_Γ₀ v) := λ a b, id @[simp] lemma triangle (a : v.valuation_field) : to_Γ₀ v (quotient.mk' a) = v.on_valuation_field a := rfl /--The zero element of the canonical value monoid associated with a valuation.-/ instance : has_zero (v.value_monoid) := ⟨quotient.mk' 0⟩ /--The unit element of the canonical value monoid associated with a valuation.-/ instance : has_one (v.value_monoid) := ⟨quotient.mk' 1⟩ /--The inversion function of the canonical value monoid associated with a valuation.-/ instance : has_inv (v.value_monoid) := ⟨λ x, quotient.lift_on' x (λ a, quotient.mk' a⁻¹) begin rintros a b ⟨c, hc, rfl⟩, replace hc : v.on_valuation_field c = 1 := units.ext_iff.mp (is_subgroup.mem_trivial.mp hc), apply to_Γ₀_inj, simp [hc], end⟩ /--The multiplication on the canonical value monoid associated with a valuation.-/ instance : has_mul (v.value_monoid) := ⟨λ x y, quotient.lift_on₂' x y (λ a b, quotient.mk' (a*b)) begin rintros a₁ b₁ a₂ b₂ ⟨c₁, hc₁, rfl⟩ ⟨c₂, hc₂, rfl⟩, replace hc₁ : v.on_valuation_field c₁ = 1 := units.ext_iff.mp (is_subgroup.mem_trivial.mp hc₁), replace hc₂ : v.on_valuation_field c₂ = 1 := units.ext_iff.mp (is_subgroup.mem_trivial.mp hc₂), apply to_Γ₀_inj, simp [hc₁, hc₂], end⟩ @[simp] lemma to_Γ₀_zero : to_Γ₀ v 0 = 0 := v.on_valuation_field.map_zero @[simp] lemma to_Γ₀_one : to_Γ₀ v 1 = 1 := v.on_valuation_field.map_one @[simp] lemma to_Γ₀_inv (a) : to_Γ₀ v a⁻¹ = (to_Γ₀ v a)⁻¹ := quotient.induction_on' a $ λ x, v.on_valuation_field.map_inv @[simp] lemma to_Γ₀_mul (a b) : to_Γ₀ v (a*b) = (to_Γ₀ v a) * (to_Γ₀ v b) := quotient.induction_on₂' a b $ λ x y, v.on_valuation_field.map_mul x y /--The canonical value monoid associated with a valuation is a group with zero.-/ instance : group_with_zero (v.value_monoid) := begin refine_struct { .. value_monoid.has_zero v, .. value_monoid.has_one v, .. value_monoid.has_inv v, .. value_monoid.has_mul v, }, show decidable_eq (value_monoid v), { apply_instance }, show (0 : v.value_monoid) ≠ 1, { assume this, replace := congr_arg (to_Γ₀ v) this, simpa using this, }, all_goals { intros, apply to_Γ₀_inj, simp }, { exact mul_assoc _ _ _ }, { apply mul_inv_cancel', intro this, apply_assumption, apply to_Γ₀_inj, simpa } end /--The canonical value monoid associated with a valuation is a linearly ordered commutative group with zero.-/ instance : linear_ordered_comm_group_with_zero (v.value_monoid) := { mul_comm := λ a b, to_Γ₀_inj v $ by simpa using mul_comm _ _, mul_le_mul_left := λ a b h c, begin rw ← (to_Γ₀_strict_mono v).le_iff_le at h ⊢, simpa using linear_ordered_structure.mul_le_mul_left h _ end, zero_le' := λ a, by { rw ← (to_Γ₀_strict_mono v).le_iff_le, simp }, .. value_monoid.group_with_zero v, .. value_monoid.linear_order v } /-- The natural quotient map from `units (valuation_field v)` to `value_monoid v`. -/ def mk (v : valuation R Γ₀) : valuation_field v →* value_monoid v := { to_fun := quotient.mk', map_one' := rfl, map_mul' := λ a b, rfl, } end value_monoid /-- The canonical valuation on Frac(R/supp(v)), taking values in `value_monoid v`. -/ def valuation_field.canonical_valuation : valuation (valuation_field v) (value_monoid v) := { map_zero' := rfl, map_add' := λ a b, begin rw ← (value_monoid.to_Γ₀_strict_mono v).le_iff_le, rw (value_monoid.to_Γ₀_strict_mono v).monotone.map_max, exact v.on_valuation_field.map_add a b end, .. value_monoid.mk v } -- ⟨valuation_field.canonical_valuation_v v, valuation_field.canonical_valuation_v.is_valuation v⟩ /-- The canonical valuation on R/supp(v), taking values in `value_monoid v`. -/ definition quotient.canonical_valuation : valuation (ideal.quotient (supp v)) (value_monoid v) := @comap _ _ _ _ _ _ (localization.of) (by apply_instance) (valuation_field.canonical_valuation v) /-- The canonical valuation on R, taking values in `value_monoid v`. -/ definition canonical_valuation : valuation R (value_monoid v) := (quotient.canonical_valuation v).comap (ideal.quotient.mk (supp v)) /-- The relation between `v.canonical_valuation r` and `v r`. -/ lemma canonical_valuation_eq (r : R) : v.canonical_valuation r = value_monoid.mk v (v.valuation_field_mk r) := rfl namespace canonical_valuation -- This looks handy to know but we never actually use it. /-- Every element of `value_monoid v` is a ratio of things in the image of `canonical_valuation v`.-/ lemma value_monoid.is_ratio (v : valuation R Γ₀) (g : value_monoid v) : ∃ r s : R, s ∉ v.supp ∧ v.canonical_valuation s * g = v.canonical_valuation r := begin apply quotient.induction_on' g, clear g, rintros ⟨⟨r⟩, ⟨s⟩, h⟩, change ideal.quotient.mk _ s ∈ _ at h, use [r, s], split, { show s ∉ supp v, assume mem_supp, erw [localization.fraction_ring.mem_non_zero_divisors_iff_ne_zero, (ideal.quotient.eq_zero_iff_mem).2 mem_supp] at h, contradiction }, show value_monoid.mk v _ * value_monoid.mk v _ = value_monoid.mk v _, rw ← monoid_hom.map_mul, refine congr_arg _ _, let rq := ideal.quotient.mk (supp v) r, let sq := ideal.quotient.mk (supp v) s, show (localization.of sq : valuation_field v) * (localization.mk rq ⟨sq, h⟩) = localization.of rq, erw [localization.mk_eq, mul_comm, mul_assoc, units.inv_val _, mul_one], refl end /-- v can be reconstructed from `canonical_valuation v` by pushing forward along the map `value_monoid v → Γ₀`. -/ lemma to_Γ₀ : (canonical_valuation v).map (monoid_hom.mk (value_monoid.to_Γ₀ v) (value_monoid.to_Γ₀_one v) (value_monoid.to_Γ₀_mul v)) (value_monoid.to_Γ₀_zero v) (value_monoid.to_Γ₀_strict_mono v).monotone = v := ext $ λ r, show v r * (v 1)⁻¹ = v r, by simp end canonical_valuation -- end of namespace end valuation -- end of namespace namespace valuation variables {Γ₀ : Type u} [linear_ordered_comm_group_with_zero Γ₀] variables {Γ'₀ : Type u₁} [linear_ordered_comm_group_with_zero Γ'₀] variables {Γ''₀ : Type u₂} [linear_ordered_comm_group_with_zero Γ''₀] variables {Γ₀₃ : Type u₃} [linear_ordered_comm_group_with_zero Γ₀₃] /-- A valuation is equivalent to its canonical valuation -/ lemma canonical_valuation_is_equiv (v : valuation R Γ₀) : v.canonical_valuation.is_equiv v := begin have h := is_equiv.of_eq (canonical_valuation.to_Γ₀ v), symmetry, refine h.symm.trans _, exact is_equiv_of_map_strict_mono _ _ _, end namespace is_equiv -- Various lemmas about valuations being equivalent. variables {v : valuation R Γ₀} {v₁ : valuation R Γ'₀} {v₂ : valuation R Γ''₀} {v₃ : valuation R Γ₀₃} /-- If J ⊆ supp(v) then pulling back the induced valuation on R / J back to R gives a valuation equivalent to v. -/ lemma on_quot_comap_self {J : ideal R} (hJ : J ≤ supp v) : is_equiv ((v.on_quot hJ).comap (ideal.quotient.mk J)) v := of_eq (on_quot_comap_eq _ _) /-- Two valuations on R/J are equivalent iff their pullbacks to R are equivalent. -/ lemma comap_on_quot (J : ideal R) (v₁ : valuation J.quotient Γ'₀) (v₂ : valuation J.quotient Γ''₀) : (v₁.comap (ideal.quotient.mk J)).is_equiv (v₂.comap (ideal.quotient.mk J)) ↔ v₁.is_equiv v₂ := { mp := begin rintros h ⟨x⟩ ⟨y⟩, exact h x y end, mpr := λ h, comap _ h } open localization /-- If supp(v)=0 then v is equivalent to the pullback of the extension of v to Frac(R). -/ lemma on_frac_comap_self {R : Type u₀} [integral_domain R] (v : valuation R Γ₀) (hv : supp v = 0) : is_equiv ((v.on_frac hv).comap of) v := of_eq (on_frac_comap_eq v hv) /-- If R is an ID then two valuations on R are equivalent iff their extensions to Frac(R) are equivalent. -/ lemma comap_on_frac {R : Type u₀} [integral_domain R] (v₁ : valuation (fraction_ring R) Γ'₀) (v₂ : valuation (fraction_ring R) Γ''₀) : (v₁.comap of).is_equiv (v₂.comap of) ↔ is_equiv v₁ v₂ := { mp := begin rintros h ⟨x⟩ ⟨y⟩, erw [← comap_on_frac_eq v₁, ← comap_on_frac_eq v₂], show _ * _ ≤ _ * _ ↔ _ * _ ≤ _ * _, erw div_le_div', erw div_le_div', { repeat {erw ← valuation.map_mul}, exact h _ _ }, all_goals { intro H, erw [← mem_supp_iff, comap_supp, (supp _).eq_bot_of_prime] at H, simp at H, replace H := fraction_ring.eq_zero_of _ H, refine fraction_ring.mem_non_zero_divisors_iff_ne_zero.mp _ H, apply subtype.val_prop _, apply_instance }, end, mpr := λ h, h.comap _ } /-- [Wed 1.27] (iii) -> first part of (ii). -/ lemma supp_eq (h : v₁.is_equiv v₂) : supp v₁ = supp v₂ := ideal.ext $ λ r, calc r ∈ supp v₁ ↔ v₁ r = 0 : iff.rfl ... ↔ v₁ r ≤ v₁ 0 : by simp ... ↔ v₂ r ≤ v₂ 0 : h r 0 ... ↔ v₂ r = 0 : by simp ... ↔ r ∈ supp v₂ : iff.rfl /-- If v₁ and v₂ are equivalent then v₁(r)=1 → v₂(r)=1. -/ lemma v_eq_one_of_v_eq_one (h : v₁.is_equiv v₂) {r : R} : v₁ r = 1 → v₂ r = 1 := begin rw [←v₁.map_one, ←v₂.map_one], intro hr, exact le_antisymm ((h r 1).1 (le_of_eq hr)) ((h 1 r).1 (le_of_eq hr.symm)), end /-- If v₁ and v₂ are equivalent then v₁(r)=1 ↔ v₂(r)=1. -/ lemma v_eq_one (h : v₁.is_equiv v₂) (r : R) : v₁ r = 1 ↔ v₂ r = 1 := ⟨v_eq_one_of_v_eq_one h,v_eq_one_of_v_eq_one h.symm⟩ /-- If v₁ and v₂ are equivalent then their canonical valuations are too. -/ lemma canonical_equiv_of_is_equiv (h : v₁.is_equiv v₂) : (canonical_valuation v₁).is_equiv (canonical_valuation v₂) := begin refine is_equiv.trans v₁.canonical_valuation_is_equiv _, refine is_equiv.trans h _, apply is_equiv.symm, exact v₂.canonical_valuation_is_equiv end end is_equiv -- end of namespace /-- The supports of v and v.canonical_valuation are equal. -/ lemma canonical_valuation_supp (v : valuation R Γ₀) : supp (v.canonical_valuation) = supp v := (canonical_valuation_is_equiv v).supp_eq /-- The canonical valuation of a valuation on a field is surjective. -/ lemma canonical_valuation.surjective {K : Type*} [discrete_field K] (v : valuation K Γ₀) : function.surjective (v.canonical_valuation) := begin rintro ⟨⟨⟨r⟩,⟨⟨s⟩,h⟩⟩⟩, refine ⟨s⁻¹ * r, _⟩, apply quotient.sound, refine ⟨1, is_submonoid.one_mem _, _⟩, rw [units.coe_one, mul_one], apply quotient.sound, refine ⟨_, h, _⟩, dsimp only [-sub_eq_add_neg], convert zero_mul _, rw [sub_eq_zero], dsimp, rw ← mul_assoc, congr, symmetry, show ideal.quotient.mk (supp v) _ * ideal.quotient.mk (supp v) _ = 1, rw ← is_ring_hom.map_mul (ideal.quotient.mk (supp v)), convert is_ring_hom.map_one (ideal.quotient.mk (supp v)), apply mul_inv_cancel, contrapose! h, subst s, refine (not_iff_not_of_iff localization.fraction_ring.mem_non_zero_divisors_iff_ne_zero).mpr _, exact not_not.mpr rfl end section Wedhorn1_27_equivalences variables {v : valuation R Γ₀} {v₁ : valuation R Γ'₀} {v₂ : valuation R Γ''₀} {v₃ : valuation R Γ₀₃} open is_group_hom quotient_group function -- We now start on the equivalences of Wedhorn 1.27. The first one is easy. /-- Wedhorn 1.27 (i) → (iii) : An ordered isomorphism of value groups which commutes with canonical valuations implies that valuations are equivalent. -/ lemma of_inj_value_monoid (f : v₁.value_monoid →* v₂.value_monoid) (h₀ : f 0 = 0) (hf : strict_mono f) (H : v₂.canonical_valuation = v₁.canonical_valuation.map f h₀ (hf.monotone)) : v₁.is_equiv v₂ := begin refine (v₁.canonical_valuation_is_equiv.symm).trans _, refine (is_equiv.trans _ (v₂.canonical_valuation_is_equiv)), rw H, symmetry, exact is_equiv_of_map_strict_mono _ _ _ end -- These lemmas look slightly ridiculous to a mathematician but they are avoiding equality of -- types and instead defining and reasoning about maps which mathematicians would call -- "the identiy map". /-- Natural map R/supp(v₁) → R/supp(v₂) induced by equality supp(v₁)=supp(v₂). -/ def quot_of_quot_of_eq_supp (h : supp v₁ = supp v₂) : valuation_ID v₁ → valuation_ID v₂ := ideal.quotient.lift _ (ideal.quotient.mk _) (λ r hr, ideal.quotient.eq_zero_iff_mem.2 $ h ▸ hr) lemma quot_of_quot_of_eq_supp.id (r : valuation_ID v) : quot_of_quot_of_eq_supp (rfl) r = r := by rcases r;refl lemma quot_of_quot_of_eq_supp.comp (h12 : supp v₁ = supp v₂) (h23 : supp v₂ = supp v₃) (r : valuation_ID v₁) : quot_of_quot_of_eq_supp h23 (quot_of_quot_of_eq_supp h12 r) = quot_of_quot_of_eq_supp (h23 ▸ h12 : supp v₁ = supp v₃) r := by rcases r;refl /-- If supp(v₁)=supp(v₂) then R/supp(v₁) is isomorphic to R/supp(v₂). -/ def valuation_ID.equiv (h : supp v₁ = supp v₂) : valuation_ID v₁ ≃ valuation_ID v₂ := { to_fun := quot_of_quot_of_eq_supp h, inv_fun := quot_of_quot_of_eq_supp (h.symm), left_inv := λ r, by rw quot_of_quot_of_eq_supp.comp h h.symm; exact quot_of_quot_of_eq_supp.id r, right_inv := λ r, by rw quot_of_quot_of_eq_supp.comp h.symm h; exact quot_of_quot_of_eq_supp.id r } @[simp] lemma quot_of_quot_of_eq_supp_quotient_mk (h : supp v₁ = supp v₂) : quot_of_quot_of_eq_supp h ∘ ideal.quotient.mk _ = ideal.quotient.mk _ := funext $ λ x, ideal.quotient.lift_mk lemma quot_of_quot_of_eq_supp_quotient_mk' (h : supp v₁ = supp v₂) (r : R) : quot_of_quot_of_eq_supp h (ideal.quotient.mk _ r) = ideal.quotient.mk _ r := by rw ←quot_of_quot_of_eq_supp_quotient_mk h /-- If supp(v₁)=supp(v₂) then the identity map R/supp(v₁) → R/supp(v₂) is a ring homomorphism. -/ instance quot_of_quot_of_eq_supp.is_ring_hom (h : supp v₁ = supp v₂) : is_ring_hom (quot_of_quot_of_eq_supp h) := by delta quot_of_quot_of_eq_supp; apply_instance /-- If supp(v₁)=supp(v₂) then R/supp(v₁) and R/supp(v₂) are isomorphic rings. -/ def quot_equiv_quot_of_eq_supp (h : supp v₁ = supp v₂) : valuation_ID v₁ ≃+* valuation_ID v₂ := { .. ring_hom.of (quot_of_quot_of_eq_supp h), .. valuation_ID.equiv h } /-- If supp(v₁)=supp(v₂) then the triangle R → R/supp(v₁) → R/supp(v₂) commutes. -/ lemma quot_equiv_quot_mk_eq_mk (h : supp v₁ = supp v₂) (r : R) : (quot_equiv_quot_of_eq_supp h).to_equiv (ideal.quotient.mk _ r) = ideal.quotient.mk _ r := quot_of_quot_of_eq_supp_quotient_mk' h r lemma quot_of_quot_of_eq_supp_inj (h : supp v₁ = supp v₂) : injective (quot_of_quot_of_eq_supp h) := injective_of_left_inverse (quot_equiv_quot_of_eq_supp h).left_inv lemma valuation_ID_le_of_le_of_equiv (h : v₁.is_equiv v₂) (a b : valuation_ID v₁) : (a ≤ b) ↔ quot_of_quot_of_eq_supp (is_equiv.supp_eq h) a ≤ quot_of_quot_of_eq_supp (is_equiv.supp_eq h) b := by rcases a; rcases b; exact (h a b) /-- If v₁ and v₂ are equivalent, then the associated preorders on R/supp(v₁)=R/supp(v₂) are equivalent. -/ def valuation_ID.preorder_equiv (h : v₁.is_equiv v₂) : preorder_equiv (valuation_ID v₁) (valuation_ID v₂) := { le_map := valuation_ID_le_of_le_of_equiv h, ..valuation_ID.equiv h.supp_eq } section valuation_field open localization /-- The natural map Frac(R/supp(v₁)) → Frac(R/supp(v₂)) if supp(v₁) = supp(v₂). -/ def valfield_of_valfield_of_eq_supp (h : supp v₁ = supp v₂) : valuation_field v₁ → valuation_field v₂ := fraction_ring.map (quot_of_quot_of_eq_supp h) (quot_of_quot_of_eq_supp_inj h) /-- The triangle R → Frac(R/supp(v₁)) → Frac(R/supp(v₂)) commutes if supp(v₁)=supp(v₂). -/ lemma valfield_of_valfield_of_eq_supp_quotient_mk (h : supp v₁ = supp v₂) (r : R) : valfield_of_valfield_of_eq_supp h (of $ ideal.quotient.mk _ r) = of (ideal.quotient.mk _ r) := begin unfold valfield_of_valfield_of_eq_supp, rw fraction_ring.map_of, rw quot_of_quot_of_eq_supp_quotient_mk', end /-- If supp(v₁)=supp(v₂) then the natural map Frac(R/supp(v₁)) → Frac(R/supp(v₂)) is a homomorphism of fields. -/ instance is_ring_hom_of_supp (h : supp v₁ = supp v₂) : is_ring_hom (valfield_of_valfield_of_eq_supp h) := by delta valfield_of_valfield_of_eq_supp; apply_instance -- This should be possible using type class inference but there are max class -- instance issues. /-- If supp(v₁)=supp(v₂) then the natural map Frac(R/supp(v₁)) → Frac(R/supp(v₂)) is a homomorphism of monoids. -/ instance (h : supp v₁ = supp v₂) : is_monoid_hom (valfield_of_valfield_of_eq_supp h) := is_semiring_hom.is_monoid_hom (valfield_of_valfield_of_eq_supp h) /-- If supp(v₁)=supp(v₂) then the natural map Frac(R/supp(v₁)) → Frac(R/supp(v₂)) is an isomorphism of rings. -/ def valfield_equiv_valfield_of_eq_supp (h : supp v₁ = supp v₂) : valuation_field v₁ ≃+* valuation_field v₂ := fraction_ring.equiv_of_equiv (quot_equiv_quot_of_eq_supp h) lemma valfield_equiv_eq_valfield_of_valfield (h : supp v₁ = supp v₂) (q : valuation_field v₁) : (valfield_equiv_valfield_of_eq_supp h).to_equiv q = valfield_of_valfield_of_eq_supp h q := rfl lemma valfield_equiv_valfield_mk_eq_mk (h : supp v₁ = supp v₂) (r : R) : (valfield_equiv_valfield_of_eq_supp h).to_equiv (of $ ideal.quotient.mk _ r) = of (ideal.quotient.mk _ r) := valfield_of_valfield_of_eq_supp_quotient_mk h r /-- If v₁ and v₂ are equivalent then the induced valuations on R/supp(v₁) and R/supp(v₂) (pulled back to R/supp(v₁) are equivalent. -/ lemma is_equiv.comap_quot_of_quot (h : v₁.is_equiv v₂) : (v₁.on_quot (set.subset.refl _)).is_equiv ((v₂.on_quot (set.subset.refl _)).comap (quot_of_quot_of_eq_supp h.supp_eq)) := begin rw [← is_equiv.comap_on_quot, ← comap_comp], simp [h], end /-- If v₁ and v₂ are equivalent then the induced valuations on Frac(R/supp(v₁)) and Frac(R/supp(v₂)) [pulled back] are equivalent. -/ lemma is_equiv.on_valuation_field_is_equiv (h : v₁.is_equiv v₂) : v₁.on_valuation_field.is_equiv (v₂.on_valuation_field.comap (valfield_of_valfield_of_eq_supp h.supp_eq)) := begin delta valfield_of_valfield_of_eq_supp, delta on_valuation_field, erw [← is_equiv.comap_on_frac, ← comap_comp, on_frac_comap_eq], simp [comap_comp, h.comap_quot_of_quot], end /-- The valuation rings of two equivalent valuations are isomorphic (as types). -/ def val_ring_equiv_of_is_equiv_aux (h : v₁.is_equiv v₂) : v₁.valuation_ring ≃ v₂.valuation_ring := equiv.subtype_congr (valfield_equiv_valfield_of_eq_supp h.supp_eq).to_equiv $ begin intro x, show _ ≤ _ ↔ _ ≤ _, erw [← v₁.on_valuation_field.map_one, h.on_valuation_field_is_equiv], convert iff.refl _, symmetry, exact valuation.map_one _, end /-- The valuation rings of two equivalent valuations are isomorphic as rings. -/ def val_ring_equiv_of_is_equiv (h : v₁.is_equiv v₂) : v₁.valuation_ring ≃+* v₂.valuation_ring := { map_add' := λ x y, subtype.val_injective $ (valfield_equiv_valfield_of_eq_supp h.supp_eq).map_add x y, map_mul' := λ x y, subtype.val_injective $ (valfield_equiv_valfield_of_eq_supp h.supp_eq).map_mul x y, .. val_ring_equiv_of_is_equiv_aux h, } -- we omit the proof that the diagram {r | v₁ r ≤ 1} → v₁.valuation_ring → v₂.valuation_ring -- commutes. lemma valfield_le_of_le_of_equiv (h : v₁.is_equiv v₂) (a b : valuation_field v₁) : (a ≤ b) ↔ valfield_of_valfield_of_eq_supp (h.supp_eq) a ≤ valfield_of_valfield_of_eq_supp (h.supp_eq) b := calc a ≤ b ↔ v₁.on_valuation_field a ≤ v₁.on_valuation_field b : iff.rfl ... ↔ _ : h.on_valuation_field_is_equiv a b def valfield.preorder_equiv (h : v₁.is_equiv v₂) : preorder_equiv (valuation_field v₁) (valuation_field v₂) := { le_map := valfield_le_of_le_of_equiv h, ..(valfield_equiv_valfield_of_eq_supp h.supp_eq).to_equiv } -- units /-- The induced map between the unit groups of the valuation fields of two valuations with the same support.-/ def valfield_units_of_valfield_units_of_eq_supp (h : supp v₁ = supp v₂) : units (valuation_field v₁) → units (valuation_field v₂) := units.map' $ valfield_of_valfield_of_eq_supp h /-- The induced map between the unit groups of the valuation fields of two valuations with the same support is a group homomorphism.-/ instance valfield_units.is_group_hom (h : supp v₁ = supp v₂) : is_group_hom (valfield_units_of_valfield_units_of_eq_supp h) := by unfold valfield_units_of_valfield_units_of_eq_supp; apply_instance lemma units_valfield_of_units_valfield_of_eq_supp_mk (h : supp v₁ = supp v₂) (r : R) (hr : r ∉ supp v₁) : valfield_units_of_valfield_units_of_eq_supp h (units_valfield_mk v₁ r hr) = units_valfield_mk v₂ r (h ▸ hr) := units.ext $ valfield_equiv_valfield_mk_eq_mk h r def valfield_units_equiv_units_of_eq_supp (h : supp v₁ = supp v₂) : (units (valuation_field v₁)) ≃* (units (valuation_field v₂)) := units.map_equiv { .. valfield_equiv_valfield_of_eq_supp h } end valuation_field -- section lemma valfield_units_equiv_units_mk_eq_mk (h : supp v₁ = supp v₂) (r : R) (hr : r ∉ supp v₁): (valfield_units_equiv_units_of_eq_supp h).to_equiv (units_valfield_mk v₁ r hr) = units_valfield_mk v₂ r (h ▸ hr) := units_valfield_of_units_valfield_of_eq_supp_mk h r hr def valfield_units_preorder_equiv (h : v₁.is_equiv v₂) : preorder_equiv (units (valuation_field v₁)) (units (valuation_field v₂)) := { le_map := λ u v, @le_equiv.le_map _ _ _ _ (valfield.preorder_equiv h) u.val v.val, ..valfield_units_equiv_units_of_eq_supp (h.supp_eq) } lemma val_one_iff_unit_val_one (x : units (valuation_field v)) : x ∈ valuation_field_norm_one v ↔ v.on_valuation_field x = 1 := calc x ∈ valuation_field_norm_one v ↔ (units.map (v.on_valuation_field : v.valuation_field →* Γ₀) x = 1) : is_subgroup.mem_trivial ... ↔ v.on_valuation_field x = 1 : units.ext_iff lemma is_equiv.norm_one_eq_norm_one (h : is_equiv v₁ v₂) : valfield_units_of_valfield_units_of_eq_supp (is_equiv.supp_eq h) ⁻¹' valuation_field_norm_one v₂ = valuation_field_norm_one v₁ := begin ext x, rw [set.mem_preimage, val_one_iff_unit_val_one x, is_equiv.v_eq_one (is_equiv.on_valuation_field_is_equiv h) x, val_one_iff_unit_val_one], refl, end /-- Two equivalent valuations have isomorphic canonical value monoids. This is part of the statement of [Wedhorn, 1.27 (iii) -> (i)]. -/ def is_equiv.value_mul_equiv (h : is_equiv v₁ v₂) : (value_monoid v₁) ≃* (value_monoid v₂) := { to_fun := λ x, quotient.lift_on' x ((valuation_field.canonical_valuation v₂).comap (valfield_of_valfield_of_eq_supp h.supp_eq)) begin rintros a b ⟨c, hc, rfl⟩, rw valuation.map_mul, convert (mul_one _).symm, rw val_one_iff_unit_val_one at hc, rw h.on_valuation_field_is_equiv.v_eq_one c at hc, suffices : v₂.on_valuation_field.is_equiv (valuation_field.canonical_valuation v₂), { have tmp := (this.comap (valfield_of_valfield_of_eq_supp _)), rwa tmp.v_eq_one at hc, }, intros a b, exact iff.rfl end, inv_fun := λ x, quotient.lift_on' x ((valuation_field.canonical_valuation v₁).comap (valfield_of_valfield_of_eq_supp h.symm.supp_eq)) begin rintros a b ⟨c, hc, rfl⟩, rw valuation.map_mul, convert (mul_one _).symm, rw val_one_iff_unit_val_one at hc, rw h.symm.on_valuation_field_is_equiv.v_eq_one c at hc, suffices : v₁.on_valuation_field.is_equiv (valuation_field.canonical_valuation v₁), { have tmp := (this.comap (valfield_of_valfield_of_eq_supp _)), rwa tmp.v_eq_one at hc, }, intros a b, exact iff.rfl end, left_inv := by { rintro ⟨a⟩, apply quotient.sound', refine ⟨1, is_submonoid.one_mem _, _⟩, rw [units.coe_one, mul_one], exact (valfield_equiv_valfield_of_eq_supp h.supp_eq).to_equiv.left_inv a }, right_inv := by { rintro ⟨a⟩, apply quotient.sound', refine ⟨1, is_submonoid.one_mem _, _⟩, rw [units.coe_one, mul_one], exact (valfield_equiv_valfield_of_eq_supp h.symm.supp_eq).to_equiv.left_inv a }, map_mul' := begin rintro ⟨a⟩ ⟨b⟩, apply quotient.sound', refine ⟨1, is_submonoid.one_mem _, _⟩, rw [units.coe_one, mul_one], exact is_ring_hom.map_mul _, end } -- ordering part of 1.27 (iii) -> (i) lemma is_equiv.value_monoid_order_equiv_aux (h : is_equiv v₁ v₂) (x y : value_monoid v₁) (h2 : x ≤ y) : h.value_mul_equiv x ≤ h.value_mul_equiv y := begin induction x with x, induction y, swap, refl, swap, refl, exact (is_equiv.on_valuation_field_is_equiv h x y).1 h2, end /-- The canonical value monoids of two equivalent valuations are order equivalent.-/ def is_equiv.value_monoid_le_equiv (h : is_equiv v₁ v₂) : (value_monoid v₁) ≃≤ (value_monoid v₂) := { le_map := λ x y, linear_order_le_iff_of_monotone_injective (h.value_mul_equiv.to_equiv.bijective.1) (is_equiv.value_monoid_order_equiv_aux h) x y ..h.value_mul_equiv} lemma is_equiv.value_mul_equiv_monotone (h : is_equiv v₁ v₂) : monotone (h.value_mul_equiv) := λ x y, (@@le_equiv.le_map _ _ (is_equiv.value_monoid_le_equiv h)).1 lemma is_equiv.value_mul_equiv_map_zero (h : is_equiv v₁ v₂) : h.value_mul_equiv 0 = 0 := begin apply quotient.sound', refine ⟨1, is_submonoid.one_mem _, _⟩, rw [units.coe_one, mul_one], exact is_ring_hom.map_zero _, end lemma is_equiv.with_zero_value_mul_equiv_mk_eq_mk (h : v₁.is_equiv v₂) : (canonical_valuation v₁).map h.value_mul_equiv.to_monoid_hom h.value_mul_equiv_map_zero h.value_mul_equiv_monotone = canonical_valuation v₂ := begin ext r, apply quotient.sound', refine ⟨1, is_submonoid.one_mem _, _⟩, rw [units.coe_one, mul_one], apply valfield_of_valfield_of_eq_supp_quotient_mk, end end Wedhorn1_27_equivalences -- section end valuation
02e7271c2af3b0b56226d5c6a475494cf07016ef
61ccc57f9d72048e493dd6969b56ebd7f0a8f9e8
/src/algebra/group/hom.lean
77e12f15cbdd11d829a2624fa988388473330324
[ "Apache-2.0" ]
permissive
jtristan/mathlib
375b3c8682975df28f79f53efcb7c88840118467
8fa8f175271320d675277a672f59ec53abd62f10
refs/heads/master
1,651,072,765,551
1,588,255,641,000
1,588,255,641,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
10,548
lean
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Kevin Buzzard, Scott Morrison, Johan Commelin, Chris Hughes, Johannes Hölzl, Yury Kudryashov -/ import algebra.group.basic /-! # monoid and group homomorphisms This file defines the bundled structures for monoid and group homomorphisms. Namely, we define `monoid_hom` (resp., `add_monoid_hom`) to be bundled homomorphisms between multiplicative (resp., additive) monoids or groups. We also define coercion to a function, and usual operations: composition, identity homomorphism, pointwise multiplication and pointwise inversion. ## Notations * `→*` for bundled monoid homs (also use for group homs) * `→+` for bundled add_monoid homs (also use for add_group homs) ## implementation notes There's a coercion from bundled homs to fun, and the canonical notation is to use the bundled hom as a function via this coercion. There is no `group_hom` -- the idea is that `monoid_hom` is used. The constructor for `monoid_hom` needs a proof of `map_one` as well as `map_mul`; a separate constructor `monoid_hom.mk'` will construct group homs (i.e. monoid homs between groups) given only a proof that multiplication is preserved, Implicit `{}` brackets are often used instead of type class `[]` brackets. This is done when the instances can be inferred because they are implicit arguments to the type `monoid_hom`. When they can be inferred from the type it is faster to use this method than to use type class inference. Historically this file also included definitions of unbundled homomorphism classes; they were deprecated and moved to `deprecated/group`. ## Tags monoid_hom, add_monoid_hom -/ variables {M : Type*} {N : Type*} {P : Type*} -- monoids {G : Type*} {H : Type*} -- groups /-- Bundled add_monoid homomorphisms; use this for bundled add_group homomorphisms too. -/ structure add_monoid_hom (M : Type*) (N : Type*) [add_monoid M] [add_monoid N] := (to_fun : M → N) (map_zero' : to_fun 0 = 0) (map_add' : ∀ x y, to_fun (x + y) = to_fun x + to_fun y) infixr ` →+ `:25 := add_monoid_hom /-- Bundled monoid homomorphisms; use this for bundled group homomorphisms too. -/ @[to_additive add_monoid_hom] structure monoid_hom (M : Type*) (N : Type*) [monoid M] [monoid N] := (to_fun : M → N) (map_one' : to_fun 1 = 1) (map_mul' : ∀ x y, to_fun (x * y) = to_fun x * to_fun y) infixr ` →* `:25 := monoid_hom @[to_additive] instance {M : Type*} {N : Type*} {mM : monoid M} {mN : monoid N} : has_coe_to_fun (M →* N) := ⟨_, monoid_hom.to_fun⟩ namespace monoid_hom variables {mM : monoid M} {mN : monoid N} {mP : monoid P} variables [group G] [comm_group H] include mM mN @[simp, to_additive] lemma coe_mk (f : M → N) (h1 hmul) : ⇑(monoid_hom.mk f h1 hmul) = f := rfl @[to_additive] lemma coe_inj ⦃f g : M →* N⦄ (h : (f : M → N) = g) : f = g := by cases f; cases g; cases h; refl @[ext, to_additive] lemma ext ⦃f g : M →* N⦄ (h : ∀ x, f x = g x) : f = g := coe_inj (funext h) attribute [ext] _root_.add_monoid_hom.ext @[to_additive] lemma ext_iff {f g : M →* N} : f = g ↔ ∀ x, f x = g x := ⟨λ h x, h ▸ rfl, λ h, ext h⟩ /-- If f is a monoid homomorphism then f 1 = 1. -/ @[simp, to_additive] lemma map_one (f : M →* N) : f 1 = 1 := f.map_one' /-- If f is a monoid homomorphism then f (a * b) = f a * f b. -/ @[simp, to_additive] lemma map_mul (f : M →* N) (a b : M) : f (a * b) = f a * f b := f.map_mul' a b omit mN mM /-- The identity map from a monoid to itself. -/ @[to_additive] def id (M : Type*) [monoid M] : M →* M := { to_fun := id, map_one' := rfl, map_mul' := λ _ _, rfl } include mM mN mP /-- Composition of monoid morphisms is a monoid morphism. -/ @[to_additive] def comp (hnp : N →* P) (hmn : M →* N) : M →* P := { to_fun := hnp ∘ hmn, map_one' := by simp, map_mul' := by simp } @[simp, to_additive] lemma comp_apply (g : N →* P) (f : M →* N) (x : M) : g.comp f x = g (f x) := rfl /-- Composition of monoid homomorphisms is associative. -/ @[to_additive] lemma comp_assoc {Q : Type*} [monoid Q] (f : M →* N) (g : N →* P) (h : P →* Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl /-- Given a monoid homomorphism `f : M →* N` and a set `S ⊆ M` such that `f` maps elements of `S` to invertible elements of `N`, any monoid homomorphism `g : N →* P` maps elements of `f(S)` to invertible elements of `P`. -/ @[to_additive "Given an add_monoid homomorphism `f : M →+ N` and a set `S ⊆ M` such that `f` maps elements of `S` to invertible elements of `N`, any add_monoid homomorphism `g : N →+ P` maps elements of `f(S)` to invertible elements of `P`."] lemma exists_inv_of_comp_exists_inv {S : set M} {f : M →* N} (hf : ∀ s ∈ S, ∃ b, f s * b = 1) (g : N →* P) (s ∈ S) : ∃ x : P, g.comp f s * x = 1 := let ⟨c, hc⟩ := hf s H in ⟨g c, show g _ * _ = _, by rw [←g.map_mul, hc, g.map_one]⟩ @[to_additive] lemma cancel_right {g₁ g₂ : N →* P} {f : M →* N} (hf : function.surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨λ h, monoid_hom.ext $ (forall_iff_forall_surj hf).1 (ext_iff.1 h), λ h, h ▸ rfl⟩ @[to_additive] lemma cancel_left {g : N →* P} {f₁ f₂ : M →* N} (hg : function.injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨λ h, monoid_hom.ext $ λ x, hg $ by rw [← comp_apply, h, comp_apply], λ h, h ▸ rfl⟩ omit mP @[simp, to_additive] lemma comp_id (f : M →* N) : f.comp (id M) = f := ext $ λ x, rfl @[simp, to_additive] lemma id_comp (f : M →* N) : (id N).comp f = f := ext $ λ x, rfl variables [mM] [mN] @[to_additive] protected def one : M →* N := { to_fun := λ _, 1, map_one' := rfl, map_mul' := λ _ _, (one_mul 1).symm } @[to_additive] instance : has_one (M →* N) := ⟨monoid_hom.one⟩ @[simp, to_additive] lemma one_apply (x : M) : (1 : M →* N) x = 1 := rfl @[to_additive] instance : inhabited (M →* N) := ⟨1⟩ omit mM mN /-- The product of two monoid morphisms is a monoid morphism if the target is commutative. -/ @[to_additive] protected def mul {M N} {mM : monoid M} [comm_monoid N] (f g : M →* N) : M →* N := { to_fun := λ m, f m * g m, map_one' := show f 1 * g 1 = 1, by simp, map_mul' := begin intros, show f (x * y) * g (x * y) = f x * g x * (f y * g y), rw [f.map_mul, g.map_mul, ←mul_assoc, ←mul_assoc, mul_right_comm (f x)], end } @[to_additive] instance {M N} {mM : monoid M} [comm_monoid N] : has_mul (M →* N) := ⟨monoid_hom.mul⟩ @[simp, to_additive] lemma mul_apply {M N} {mM : monoid M} {mN : comm_monoid N} (f g : M →* N) (x : M) : (f * g) x = f x * g x := rfl /-- (M →* N) is a comm_monoid if N is commutative. -/ @[to_additive add_comm_monoid] instance {M N} [monoid M] [comm_monoid N] : comm_monoid (M →* N) := { mul := (*), mul_assoc := by intros; ext; apply mul_assoc, one := 1, one_mul := by intros; ext; apply one_mul, mul_one := by intros; ext; apply mul_one, mul_comm := by intros; ext; apply mul_comm } /-- `flip` arguments of `f : M →* N →* P` -/ @[to_additive "`flip` arguments of `f : M →+ N →+ P`"] def flip {mM : monoid M} {mN : monoid N} {mP : comm_monoid P} (f : M →* N →* P) : N →* M →* P := { to_fun := λ y, ⟨λ x, f x y, by rw [f.map_one, one_apply], λ x₁ x₂, by rw [f.map_mul, mul_apply]⟩, map_one' := ext $ λ x, (f x).map_one, map_mul' := λ y₁ y₂, ext $ λ x, (f x).map_mul y₁ y₂ } @[simp, to_additive] lemma flip_apply {mM : monoid M} {mN : monoid N} {mP : comm_monoid P} (f : M →* N →* P) (x : M) (y : N) : f.flip y x = f x y := rfl /-- Group homomorphisms preserve inverse. -/ @[simp, to_additive] theorem map_inv {G H} [group G] [group H] (f : G →* H) (g : G) : f g⁻¹ = (f g)⁻¹ := eq_inv_of_mul_eq_one $ by rw [←f.map_mul, inv_mul_self, f.map_one] /-- Group homomorphisms preserve division. -/ @[simp, to_additive] theorem map_mul_inv {G H} [group G] [group H] (f : G →* H) (g h : G) : f (g * h⁻¹) = (f g) * (f h)⁻¹ := by rw [f.map_mul, f.map_inv] /-- A group homomorphism is injective iff its kernel is trivial. -/ @[to_additive] lemma injective_iff {G H} [group G] [group H] (f : G →* H) : function.injective f ↔ (∀ a, f a = 1 → a = 1) := ⟨λ h _, by rw ← f.map_one; exact @h _ _, λ h x y hxy, by rw [← inv_inv (f x), inv_eq_iff_mul_eq_one, ← f.map_inv, ← f.map_mul] at hxy; simpa using inv_eq_of_mul_eq_one (h _ hxy)⟩ include mM /-- Makes a group homomomorphism from a proof that the map preserves multiplication. -/ @[to_additive] def mk' (f : M → G) (map_mul : ∀ a b : M, f (a * b) = f a * f b) : M →* G := { to_fun := f, map_mul' := map_mul, map_one' := mul_self_iff_eq_one.1 $ by rw [←map_mul, mul_one] } omit mM /-- The inverse of a monoid homomorphism is a monoid homomorphism if the target is a commutative group.-/ @[to_additive] protected def inv {M G} {mM : monoid M} [comm_group G] (f : M →* G) : M →* G := mk' (λ g, (f g)⁻¹) $ λ a b, by rw [←mul_inv, f.map_mul] @[to_additive] instance {M G} [monoid M] [comm_group G] : has_inv (M →* G) := ⟨monoid_hom.inv⟩ @[simp, to_additive] lemma inv_apply {M G} {mM : monoid M} {gG : comm_group G} (f : M →* G) (x : M) : f⁻¹ x = (f x)⁻¹ := rfl /-- (M →* G) is a comm_group if G is a comm_group -/ @[to_additive add_comm_group] instance {M G} [monoid M] [comm_group G] : comm_group (M →* G) := { inv := has_inv.inv, mul_left_inv := by intros; ext; apply mul_left_inv, ..monoid_hom.comm_monoid } end monoid_hom namespace add_monoid_hom /-- Additive group homomorphisms preserve subtraction. -/ @[simp] theorem map_sub {G H} [add_group G] [add_group H] (f : G →+ H) (g h : G) : f (g - h) = (f g) - (f h) := f.map_add_neg g h /-- Left multiplication by an element of a (semi)ring is an `add_monoid_hom` -/ def mul_left {R : Type*} [semiring R] (r : R) : R →+ R := { to_fun := (*) r, map_zero' := mul_zero r, map_add' := mul_add r } @[simp] lemma coe_mul_left {R : Type*} [semiring R] (r : R) : ⇑(mul_left r) = (*) r := rfl /-- Right multiplication by an element of a (semi)ring is an `add_monoid_hom` -/ def mul_right {R : Type*} [semiring R] (r : R) : R →+ R := { to_fun := λ a, a * r, map_zero' := zero_mul r, map_add' := λ _ _, add_mul _ _ r } @[simp] lemma mul_right_apply {R : Type*} [semiring R] (a r : R) : (mul_right r : R → R) a = a * r := rfl end add_monoid_hom
dfa6af1c7ea773ab9d9c0d3ce3f1e30ca69f4941
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/logic/equiv/defs.lean
490c633c499db2f26bdd74032c2386cfc1b389da
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
35,488
lean
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Mario Carneiro -/ import data.fun_like.equiv import logic.unique /-! # Equivalence between types > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. In this file we define two types: * `equiv α β` a.k.a. `α ≃ β`: a bijective map `α → β` bundled with its inverse map; we use this (and not equality!) to express that various `Type`s or `Sort`s are equivalent. * `equiv.perm α`: the group of permutations `α ≃ α`. More lemmas about `equiv.perm` can be found in `group_theory/perm`. Then we define * canonical isomorphisms between various types: e.g., - `equiv.refl α` is the identity map interpreted as `α ≃ α`; * operations on equivalences: e.g., - `equiv.symm e : β ≃ α` is the inverse of `e : α ≃ β`; - `equiv.trans e₁ e₂ : α ≃ γ` is the composition of `e₁ : α ≃ β` and `e₂ : β ≃ γ` (note the order of the arguments!); * definitions that transfer some instances along an equivalence. By convention, we transfer instances from right to left. - `equiv.inhabited` takes `e : α ≃ β` and `[inhabited β]` and returns `inhabited α`; - `equiv.unique` takes `e : α ≃ β` and `[unique β]` and returns `unique α`; - `equiv.decidable_eq` takes `e : α ≃ β` and `[decidable_eq β]` and returns `decidable_eq α`. More definitions of this kind can be found in other files. E.g., `data/equiv/transfer_instance` does it for many algebraic type classes like `group`, `module`, etc. Many more such isomorphisms and operations are defined in `logic/equiv/basic`. ## Tags equivalence, congruence, bijective map -/ open function universes u v w z variables {α : Sort u} {β : Sort v} {γ : Sort w} /-- `α ≃ β` is the type of functions from `α → β` with a two-sided inverse. -/ structure equiv (α : Sort*) (β : Sort*) := (to_fun : α → β) (inv_fun : β → α) (left_inv : left_inverse inv_fun to_fun) (right_inv : right_inverse inv_fun to_fun) infix ` ≃ `:25 := equiv instance {F} [equiv_like F α β] : has_coe_t F (α ≃ β) := ⟨λ f, { to_fun := f, inv_fun := equiv_like.inv f, left_inv := equiv_like.left_inv f, right_inv := equiv_like.right_inv f }⟩ /-- `perm α` is the type of bijections from `α` to itself. -/ @[reducible] def equiv.perm (α : Sort*) := equiv α α namespace equiv instance : equiv_like (α ≃ β) α β := { coe := to_fun, inv := inv_fun, left_inv := left_inv, right_inv := right_inv, coe_injective' := λ e₁ e₂ h₁ h₂, by { cases e₁, cases e₂, congr' } } instance : has_coe_to_fun (α ≃ β) (λ _, α → β) := ⟨to_fun⟩ @[simp] theorem coe_fn_mk (f : α → β) (g l r) : (equiv.mk f g l r : α → β) = f := rfl /-- The map `coe_fn : (r ≃ s) → (r → s)` is injective. -/ theorem coe_fn_injective : @function.injective (α ≃ β) (α → β) coe_fn := fun_like.coe_injective protected lemma coe_inj {e₁ e₂ : α ≃ β} : (e₁ : α → β) = e₂ ↔ e₁ = e₂ := fun_like.coe_fn_eq @[ext] lemma ext {f g : equiv α β} (H : ∀ x, f x = g x) : f = g := fun_like.ext f g H protected lemma congr_arg {f : equiv α β} {x x' : α} : x = x' → f x = f x' := fun_like.congr_arg f protected lemma congr_fun {f g : equiv α β} (h : f = g) (x : α) : f x = g x := fun_like.congr_fun h x lemma ext_iff {f g : equiv α β} : f = g ↔ ∀ x, f x = g x := fun_like.ext_iff @[ext] lemma perm.ext {σ τ : equiv.perm α} (H : ∀ x, σ x = τ x) : σ = τ := equiv.ext H protected lemma perm.congr_arg {f : equiv.perm α} {x x' : α} : x = x' → f x = f x' := equiv.congr_arg protected lemma perm.congr_fun {f g : equiv.perm α} (h : f = g) (x : α) : f x = g x := equiv.congr_fun h x lemma perm.ext_iff {σ τ : equiv.perm α} : σ = τ ↔ ∀ x, σ x = τ x := ext_iff /-- Any type is equivalent to itself. -/ @[refl] protected def refl (α : Sort*) : α ≃ α := ⟨id, id, λ x, rfl, λ x, rfl⟩ instance inhabited' : inhabited (α ≃ α) := ⟨equiv.refl α⟩ /-- Inverse of an equivalence `e : α ≃ β`. -/ @[symm] protected def symm (e : α ≃ β) : β ≃ α := ⟨e.inv_fun, e.to_fun, e.right_inv, e.left_inv⟩ /-- See Note [custom simps projection] -/ def simps.symm_apply (e : α ≃ β) : β → α := e.symm initialize_simps_projections equiv (to_fun → apply, inv_fun → symm_apply) /-- Composition of equivalences `e₁ : α ≃ β` and `e₂ : β ≃ γ`. -/ @[trans] protected def trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ := ⟨e₂ ∘ e₁, e₁.symm ∘ e₂.symm, e₂.left_inv.comp e₁.left_inv, e₂.right_inv.comp e₁.right_inv⟩ @[simp, transport_simps, mfld_simps] lemma to_fun_as_coe (e : α ≃ β) : e.to_fun = e := rfl @[simp, mfld_simps] lemma inv_fun_as_coe (e : α ≃ β) : e.inv_fun = e.symm := rfl protected theorem injective (e : α ≃ β) : injective e := equiv_like.injective e protected theorem surjective (e : α ≃ β) : surjective e := equiv_like.surjective e protected theorem bijective (e : α ≃ β) : bijective e := equiv_like.bijective e protected theorem subsingleton (e : α ≃ β) [subsingleton β] : subsingleton α := e.injective.subsingleton protected theorem subsingleton.symm (e : α ≃ β) [subsingleton α] : subsingleton β := e.symm.injective.subsingleton lemma subsingleton_congr (e : α ≃ β) : subsingleton α ↔ subsingleton β := ⟨λ h, by exactI e.symm.subsingleton, λ h, by exactI e.subsingleton⟩ instance equiv_subsingleton_cod [subsingleton β] : subsingleton (α ≃ β) := fun_like.subsingleton_cod instance equiv_subsingleton_dom [subsingleton α] : subsingleton (α ≃ β) := equiv_like.subsingleton_dom instance perm_unique [subsingleton α] : unique (perm α) := unique_of_subsingleton (equiv.refl α) lemma perm.subsingleton_eq_refl [subsingleton α] (e : perm α) : e = equiv.refl α := subsingleton.elim _ _ /-- Transfer `decidable_eq` across an equivalence. -/ protected def decidable_eq (e : α ≃ β) [decidable_eq β] : decidable_eq α := e.injective.decidable_eq lemma nonempty_congr (e : α ≃ β) : nonempty α ↔ nonempty β := nonempty.congr e e.symm protected lemma nonempty (e : α ≃ β) [nonempty β] : nonempty α := e.nonempty_congr.mpr ‹_› /-- If `α ≃ β` and `β` is inhabited, then so is `α`. -/ protected def inhabited [inhabited β] (e : α ≃ β) : inhabited α := ⟨e.symm default⟩ /-- If `α ≃ β` and `β` is a singleton type, then so is `α`. -/ protected def unique [unique β] (e : α ≃ β) : unique α := e.symm.surjective.unique /-- Equivalence between equal types. -/ protected def cast {α β : Sort*} (h : α = β) : α ≃ β := ⟨cast h, cast h.symm, λ x, by { cases h, refl }, λ x, by { cases h, refl }⟩ @[simp] theorem coe_fn_symm_mk (f : α → β) (g l r) : ((equiv.mk f g l r).symm : β → α) = g := rfl @[simp] theorem coe_refl : ⇑(equiv.refl α) = id := rfl /-- This cannot be a `simp` lemmas as it incorrectly matches against `e : α ≃ synonym α`, when `synonym α` is semireducible. This makes a mess of `multiplicative.of_add` etc. -/ theorem perm.coe_subsingleton {α : Type*} [subsingleton α] (e : perm α) : ⇑(e) = id := by rw [perm.subsingleton_eq_refl e, coe_refl] theorem refl_apply (x : α) : equiv.refl α x = x := rfl @[simp] theorem coe_trans (f : α ≃ β) (g : β ≃ γ) : ⇑(f.trans g) = g ∘ f := rfl theorem trans_apply (f : α ≃ β) (g : β ≃ γ) (a : α) : (f.trans g) a = g (f a) := rfl @[simp, equiv_rw_simp] theorem apply_symm_apply (e : α ≃ β) (x : β) : e (e.symm x) = x := e.right_inv x @[simp, equiv_rw_simp, transport_simps] theorem symm_apply_apply (e : α ≃ β) (x : α) : e.symm (e x) = x := e.left_inv x @[simp] theorem symm_comp_self (e : α ≃ β) : e.symm ∘ e = id := funext e.symm_apply_apply @[simp] theorem self_comp_symm (e : α ≃ β) : e ∘ e.symm = id := funext e.apply_symm_apply @[simp] lemma symm_trans_apply (f : α ≃ β) (g : β ≃ γ) (a : γ) : (f.trans g).symm a = f.symm (g.symm a) := rfl -- The `simp` attribute is needed to make this a `dsimp` lemma. -- `simp` will always rewrite with `equiv.symm_symm` before this has a chance to fire. @[simp, nolint simp_nf] theorem symm_symm_apply (f : α ≃ β) (b : α) : f.symm.symm b = f b := rfl theorem apply_eq_iff_eq (f : α ≃ β) {x y : α} : f x = f y ↔ x = y := equiv_like.apply_eq_iff_eq f @[transport_simps] theorem apply_eq_iff_eq_symm_apply {α β : Sort*} (f : α ≃ β) {x : α} {y : β} : f x = y ↔ x = f.symm y := begin conv_lhs { rw ←apply_symm_apply f y, }, rw apply_eq_iff_eq, end @[simp] theorem cast_apply {α β} (h : α = β) (x : α) : equiv.cast h x = cast h x := rfl @[simp] theorem cast_symm {α β} (h : α = β) : (equiv.cast h).symm = equiv.cast h.symm := rfl @[simp] theorem cast_refl {α} (h : α = α := rfl) : equiv.cast h = equiv.refl α := rfl @[simp] theorem cast_trans {α β γ} (h : α = β) (h2 : β = γ) : (equiv.cast h).trans (equiv.cast h2) = equiv.cast (h.trans h2) := ext $ λ x, by { substs h h2, refl } lemma cast_eq_iff_heq {α β} (h : α = β) {a : α} {b : β} : equiv.cast h a = b ↔ a == b := by { subst h, simp } lemma symm_apply_eq {α β} (e : α ≃ β) {x y} : e.symm x = y ↔ x = e y := ⟨λ H, by simp [H.symm], λ H, by simp [H]⟩ lemma eq_symm_apply {α β} (e : α ≃ β) {x y} : y = e.symm x ↔ e y = x := (eq_comm.trans e.symm_apply_eq).trans eq_comm @[simp, equiv_rw_simp] theorem symm_symm (e : α ≃ β) : e.symm.symm = e := by { cases e, refl } @[simp] theorem trans_refl (e : α ≃ β) : e.trans (equiv.refl β) = e := by { cases e, refl } @[simp] theorem refl_symm : (equiv.refl α).symm = equiv.refl α := rfl @[simp] theorem refl_trans (e : α ≃ β) : (equiv.refl α).trans e = e := by { cases e, refl } @[simp] theorem symm_trans_self (e : α ≃ β) : e.symm.trans e = equiv.refl β := ext (by simp) @[simp] theorem self_trans_symm (e : α ≃ β) : e.trans e.symm = equiv.refl α := ext (by simp) lemma trans_assoc {δ} (ab : α ≃ β) (bc : β ≃ γ) (cd : γ ≃ δ) : (ab.trans bc).trans cd = ab.trans (bc.trans cd) := equiv.ext $ assume a, rfl theorem left_inverse_symm (f : equiv α β) : left_inverse f.symm f := f.left_inv theorem right_inverse_symm (f : equiv α β) : function.right_inverse f.symm f := f.right_inv lemma injective_comp (e : α ≃ β) (f : β → γ) : injective (f ∘ e) ↔ injective f := equiv_like.injective_comp e f lemma comp_injective (f : α → β) (e : β ≃ γ) : injective (e ∘ f) ↔ injective f := equiv_like.comp_injective f e lemma surjective_comp (e : α ≃ β) (f : β → γ) : surjective (f ∘ e) ↔ surjective f := equiv_like.surjective_comp e f lemma comp_surjective (f : α → β) (e : β ≃ γ) : surjective (e ∘ f) ↔ surjective f := equiv_like.comp_surjective f e lemma bijective_comp (e : α ≃ β) (f : β → γ) : bijective (f ∘ e) ↔ bijective f := equiv_like.bijective_comp e f lemma comp_bijective (f : α → β) (e : β ≃ γ) : bijective (e ∘ f) ↔ bijective f := equiv_like.comp_bijective f e /-- If `α` is equivalent to `β` and `γ` is equivalent to `δ`, then the type of equivalences `α ≃ γ` is equivalent to the type of equivalences `β ≃ δ`. -/ def equiv_congr {δ} (ab : α ≃ β) (cd : γ ≃ δ) : (α ≃ γ) ≃ (β ≃ δ) := ⟨ λac, (ab.symm.trans ac).trans cd, λbd, ab.trans $ bd.trans $ cd.symm, assume ac, by { ext x, simp }, assume ac, by { ext x, simp } ⟩ @[simp] lemma equiv_congr_refl {α β} : (equiv.refl α).equiv_congr (equiv.refl β) = equiv.refl (α ≃ β) := by { ext, refl } @[simp] lemma equiv_congr_symm {δ} (ab : α ≃ β) (cd : γ ≃ δ) : (ab.equiv_congr cd).symm = ab.symm.equiv_congr cd.symm := by { ext, refl } @[simp] lemma equiv_congr_trans {δ ε ζ} (ab : α ≃ β) (de : δ ≃ ε) (bc : β ≃ γ) (ef : ε ≃ ζ) : (ab.equiv_congr de).trans (bc.equiv_congr ef) = (ab.trans bc).equiv_congr (de.trans ef) := by { ext, refl } @[simp] lemma equiv_congr_refl_left {α β γ} (bg : β ≃ γ) (e : α ≃ β) : (equiv.refl α).equiv_congr bg e = e.trans bg := rfl @[simp] lemma equiv_congr_refl_right {α β} (ab e : α ≃ β) : ab.equiv_congr (equiv.refl β) e = ab.symm.trans e := rfl @[simp] lemma equiv_congr_apply_apply {δ} (ab : α ≃ β) (cd : γ ≃ δ) (e : α ≃ γ) (x) : ab.equiv_congr cd e x = cd (e (ab.symm x)) := rfl section perm_congr variables {α' β' : Type*} (e : α' ≃ β') /-- If `α` is equivalent to `β`, then `perm α` is equivalent to `perm β`. -/ def perm_congr : perm α' ≃ perm β' := equiv_congr e e lemma perm_congr_def (p : equiv.perm α') : e.perm_congr p = (e.symm.trans p).trans e := rfl @[simp] lemma perm_congr_refl : e.perm_congr (equiv.refl _) = equiv.refl _ := by simp [perm_congr_def] @[simp] lemma perm_congr_symm : e.perm_congr.symm = e.symm.perm_congr := rfl @[simp] lemma perm_congr_apply (p : equiv.perm α') (x) : e.perm_congr p x = e (p (e.symm x)) := rfl lemma perm_congr_symm_apply (p : equiv.perm β') (x) : e.perm_congr.symm p x = e.symm (p (e x)) := rfl lemma perm_congr_trans (p p' : equiv.perm α') : (e.perm_congr p).trans (e.perm_congr p') = e.perm_congr (p.trans p') := by { ext, simp } end perm_congr /-- Two empty types are equivalent. -/ def equiv_of_is_empty (α β : Sort*) [is_empty α] [is_empty β] : α ≃ β := ⟨is_empty_elim, is_empty_elim, is_empty_elim, is_empty_elim⟩ /-- If `α` is an empty type, then it is equivalent to the `empty` type. -/ def equiv_empty (α : Sort u) [is_empty α] : α ≃ empty := equiv_of_is_empty α _ /-- If `α` is an empty type, then it is equivalent to the `pempty` type in any universe. -/ def equiv_pempty (α : Sort v) [is_empty α] : α ≃ pempty.{u} := equiv_of_is_empty α _ /-- `α` is equivalent to an empty type iff `α` is empty. -/ def equiv_empty_equiv (α : Sort u) : (α ≃ empty) ≃ is_empty α := ⟨λ e, function.is_empty e, @equiv_empty α, λ e, ext $ λ x, (e x).elim, λ p, rfl⟩ /-- The `Sort` of proofs of a false proposition is equivalent to `pempty`. -/ def prop_equiv_pempty {p : Prop} (h : ¬p) : p ≃ pempty := @equiv_pempty p $ is_empty.prop_iff.2 h /-- If both `α` and `β` have a unique element, then `α ≃ β`. -/ def equiv_of_unique (α β : Sort*) [unique α] [unique β] : α ≃ β := { to_fun := default, inv_fun := default, left_inv := λ _, subsingleton.elim _ _, right_inv := λ _, subsingleton.elim _ _ } /-- If `α` has a unique element, then it is equivalent to any `punit`. -/ def equiv_punit (α : Sort*) [unique α] : α ≃ punit.{v} := equiv_of_unique α _ /-- The `Sort` of proofs of a true proposition is equivalent to `punit`. -/ def prop_equiv_punit {p : Prop} (h : p) : p ≃ punit := @equiv_punit p $ unique_prop h /-- `ulift α` is equivalent to `α`. -/ @[simps apply symm_apply {fully_applied := ff}] protected def ulift {α : Type v} : ulift.{u} α ≃ α := ⟨ulift.down, ulift.up, ulift.up_down, λ a, rfl⟩ /-- `plift α` is equivalent to `α`. -/ @[simps apply symm_apply {fully_applied := ff}] protected def plift : plift α ≃ α := ⟨plift.down, plift.up, plift.up_down, plift.down_up⟩ /-- equivalence of propositions is the same as iff -/ def of_iff {P Q : Prop} (h : P ↔ Q) : P ≃ Q := { to_fun := h.mp, inv_fun := h.mpr, left_inv := λ x, rfl, right_inv := λ y, rfl } /-- If `α₁` is equivalent to `α₂` and `β₁` is equivalent to `β₂`, then the type of maps `α₁ → β₁` is equivalent to the type of maps `α₂ → β₂`. -/ @[congr, simps apply] def arrow_congr {α₁ β₁ α₂ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : (α₁ → β₁) ≃ (α₂ → β₂) := { to_fun := λ f, e₂ ∘ f ∘ e₁.symm, inv_fun := λ f, e₂.symm ∘ f ∘ e₁, left_inv := λ f, funext $ λ x, by simp, right_inv := λ f, funext $ λ x, by simp } lemma arrow_congr_comp {α₁ β₁ γ₁ α₂ β₂ γ₂ : Sort*} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) (ec : γ₁ ≃ γ₂) (f : α₁ → β₁) (g : β₁ → γ₁) : arrow_congr ea ec (g ∘ f) = (arrow_congr eb ec g) ∘ (arrow_congr ea eb f) := by { ext, simp only [comp, arrow_congr_apply, eb.symm_apply_apply] } @[simp] lemma arrow_congr_refl {α β : Sort*} : arrow_congr (equiv.refl α) (equiv.refl β) = equiv.refl (α → β) := rfl @[simp] lemma arrow_congr_trans {α₁ β₁ α₂ β₂ α₃ β₃ : Sort*} (e₁ : α₁ ≃ α₂) (e₁' : β₁ ≃ β₂) (e₂ : α₂ ≃ α₃) (e₂' : β₂ ≃ β₃) : arrow_congr (e₁.trans e₂) (e₁'.trans e₂') = (arrow_congr e₁ e₁').trans (arrow_congr e₂ e₂') := rfl @[simp] lemma arrow_congr_symm {α₁ β₁ α₂ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : (arrow_congr e₁ e₂).symm = arrow_congr e₁.symm e₂.symm := rfl /-- A version of `equiv.arrow_congr` in `Type`, rather than `Sort`. The `equiv_rw` tactic is not able to use the default `Sort` level `equiv.arrow_congr`, because Lean's universe rules will not unify `?l_1` with `imax (1 ?m_1)`. -/ @[congr, simps apply { attrs := [`simp, `transport_simps] }] def arrow_congr' {α₁ β₁ α₂ β₂ : Type*} (hα : α₁ ≃ α₂) (hβ : β₁ ≃ β₂) : (α₁ → β₁) ≃ (α₂ → β₂) := equiv.arrow_congr hα hβ @[simp] lemma arrow_congr'_refl {α β : Type*} : arrow_congr' (equiv.refl α) (equiv.refl β) = equiv.refl (α → β) := rfl @[simp] lemma arrow_congr'_trans {α₁ β₁ α₂ β₂ α₃ β₃ : Type*} (e₁ : α₁ ≃ α₂) (e₁' : β₁ ≃ β₂) (e₂ : α₂ ≃ α₃) (e₂' : β₂ ≃ β₃) : arrow_congr' (e₁.trans e₂) (e₁'.trans e₂') = (arrow_congr' e₁ e₁').trans (arrow_congr' e₂ e₂') := rfl @[simp] lemma arrow_congr'_symm {α₁ β₁ α₂ β₂ : Type*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : (arrow_congr' e₁ e₂).symm = arrow_congr' e₁.symm e₂.symm := rfl /-- Conjugate a map `f : α → α` by an equivalence `α ≃ β`. -/ @[simps apply] def conj (e : α ≃ β) : (α → α) ≃ (β → β) := arrow_congr e e @[simp] lemma conj_refl : conj (equiv.refl α) = equiv.refl (α → α) := rfl @[simp] lemma conj_symm (e : α ≃ β) : e.conj.symm = e.symm.conj := rfl @[simp] lemma conj_trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : (e₁.trans e₂).conj = e₁.conj.trans e₂.conj := rfl -- This should not be a simp lemma as long as `(∘)` is reducible: -- when `(∘)` is reducible, Lean can unify `f₁ ∘ f₂` with any `g` using -- `f₁ := g` and `f₂ := λ x, x`. This causes nontermination. lemma conj_comp (e : α ≃ β) (f₁ f₂ : α → α) : e.conj (f₁ ∘ f₂) = (e.conj f₁) ∘ (e.conj f₂) := by apply arrow_congr_comp lemma eq_comp_symm {α β γ} (e : α ≃ β) (f : β → γ) (g : α → γ) : f = g ∘ e.symm ↔ f ∘ e = g := (e.arrow_congr (equiv.refl γ)).symm_apply_eq.symm lemma comp_symm_eq {α β γ} (e : α ≃ β) (f : β → γ) (g : α → γ) : g ∘ e.symm = f ↔ g = f ∘ e := (e.arrow_congr (equiv.refl γ)).eq_symm_apply.symm lemma eq_symm_comp {α β γ} (e : α ≃ β) (f : γ → α) (g : γ → β) : f = e.symm ∘ g ↔ e ∘ f = g := ((equiv.refl γ).arrow_congr e).eq_symm_apply lemma symm_comp_eq {α β γ} (e : α ≃ β) (f : γ → α) (g : γ → β) : e.symm ∘ g = f ↔ g = e ∘ f := ((equiv.refl γ).arrow_congr e).symm_apply_eq /-- `punit` sorts in any two universes are equivalent. -/ def punit_equiv_punit : punit.{v} ≃ punit.{w} := ⟨λ _, punit.star, λ _, punit.star, λ u, by { cases u, refl }, λ u, by { cases u, reflexivity }⟩ /-- `Prop` is noncomputably equivalent to `bool`. -/ noncomputable def Prop_equiv_bool : Prop ≃ bool := ⟨λ p, @to_bool p (classical.prop_decidable _), λ b, b, λ p, by simp, λ b, by simp⟩ section /-- The sort of maps to `punit.{v}` is equivalent to `punit.{w}`. -/ def arrow_punit_equiv_punit (α : Sort*) : (α → punit.{v}) ≃ punit.{w} := ⟨λ f, punit.star, λ u f, punit.star, λ f, by { funext x, cases f x, refl }, λ u, by { cases u, reflexivity }⟩ /-- If `α` is `subsingleton` and `a : α`, then the type of dependent functions `Π (i : α), β i` is equivalent to `β i`. -/ @[simps] def Pi_subsingleton {α} (β : α → Sort*) [subsingleton α] (a : α) : (Π a', β a') ≃ β a := { to_fun := eval a, inv_fun := λ x b, cast (congr_arg β $ subsingleton.elim a b) x, left_inv := λ f, funext $ λ b, by { rw subsingleton.elim b a, reflexivity }, right_inv := λ b, rfl } /-- If `α` has a unique term, then the type of function `α → β` is equivalent to `β`. -/ @[simps { fully_applied := ff }] def fun_unique (α β) [unique α] : (α → β) ≃ β := Pi_subsingleton _ default /-- The sort of maps from `punit` is equivalent to the codomain. -/ def punit_arrow_equiv (α : Sort*) : (punit.{u} → α) ≃ α := fun_unique _ _ /-- The sort of maps from `true` is equivalent to the codomain. -/ def true_arrow_equiv (α : Sort*) : (true → α) ≃ α := fun_unique _ _ /-- The sort of maps from a type that `is_empty` is equivalent to `punit`. -/ def arrow_punit_of_is_empty (α β : Sort*) [is_empty α] : (α → β) ≃ punit.{u} := ⟨λ f, punit.star, λ u, is_empty_elim, λ f, funext is_empty_elim, λ u, by { cases u, refl }⟩ /-- The sort of maps from `empty` is equivalent to `punit`. -/ def empty_arrow_equiv_punit (α : Sort*) : (empty → α) ≃ punit.{u} := arrow_punit_of_is_empty _ _ /-- The sort of maps from `pempty` is equivalent to `punit`. -/ def pempty_arrow_equiv_punit (α : Sort*) : (pempty → α) ≃ punit.{u} := arrow_punit_of_is_empty _ _ /-- The sort of maps from `false` is equivalent to `punit`. -/ def false_arrow_equiv_punit (α : Sort*) : (false → α) ≃ punit.{u} := arrow_punit_of_is_empty _ _ end section /-- A `psigma`-type is equivalent to the corresponding `sigma`-type. -/ @[simps apply symm_apply] def psigma_equiv_sigma {α} (β : α → Type*) : (Σ' i, β i) ≃ Σ i, β i := ⟨λ a, ⟨a.1, a.2⟩, λ a, ⟨a.1, a.2⟩, λ ⟨a, b⟩, rfl, λ ⟨a, b⟩, rfl⟩ /-- A `psigma`-type is equivalent to the corresponding `sigma`-type. -/ @[simps apply symm_apply] def psigma_equiv_sigma_plift {α} (β : α → Sort*) : (Σ' i, β i) ≃ Σ i : plift α, plift (β i.down) := ⟨λ a, ⟨plift.up a.1, plift.up a.2⟩, λ a, ⟨a.1.down, a.2.down⟩, λ ⟨a, b⟩, rfl, λ ⟨⟨a⟩, ⟨b⟩⟩, rfl⟩ /-- A family of equivalences `Π a, β₁ a ≃ β₂ a` generates an equivalence between `Σ' a, β₁ a` and `Σ' a, β₂ a`. -/ @[simps apply] def psigma_congr_right {α} {β₁ β₂ : α → Sort*} (F : Π a, β₁ a ≃ β₂ a) : (Σ' a, β₁ a) ≃ Σ' a, β₂ a := ⟨λ a, ⟨a.1, F a.1 a.2⟩, λ a, ⟨a.1, (F a.1).symm a.2⟩, λ ⟨a, b⟩, congr_arg (psigma.mk a) $ symm_apply_apply (F a) b, λ ⟨a, b⟩, congr_arg (psigma.mk a) $ apply_symm_apply (F a) b⟩ @[simp] lemma psigma_congr_right_trans {α} {β₁ β₂ β₃ : α → Sort*} (F : Π a, β₁ a ≃ β₂ a) (G : Π a, β₂ a ≃ β₃ a) : (psigma_congr_right F).trans (psigma_congr_right G) = psigma_congr_right (λ a, (F a).trans (G a)) := by { ext1 x, cases x, refl } @[simp] lemma psigma_congr_right_symm {α} {β₁ β₂ : α → Sort*} (F : Π a, β₁ a ≃ β₂ a) : (psigma_congr_right F).symm = psigma_congr_right (λ a, (F a).symm) := by { ext1 x, cases x, refl } @[simp] lemma psigma_congr_right_refl {α} {β : α → Sort*} : (psigma_congr_right (λ a, equiv.refl (β a))) = equiv.refl (Σ' a, β a) := by { ext1 x, cases x, refl } /-- A family of equivalences `Π a, β₁ a ≃ β₂ a` generates an equivalence between `Σ a, β₁ a` and `Σ a, β₂ a`. -/ @[simps apply] def sigma_congr_right {α} {β₁ β₂ : α → Type*} (F : Π a, β₁ a ≃ β₂ a) : (Σ a, β₁ a) ≃ Σ a, β₂ a := ⟨λ a, ⟨a.1, F a.1 a.2⟩, λ a, ⟨a.1, (F a.1).symm a.2⟩, λ ⟨a, b⟩, congr_arg (sigma.mk a) $ symm_apply_apply (F a) b, λ ⟨a, b⟩, congr_arg (sigma.mk a) $ apply_symm_apply (F a) b⟩ @[simp] lemma sigma_congr_right_trans {α} {β₁ β₂ β₃ : α → Type*} (F : Π a, β₁ a ≃ β₂ a) (G : Π a, β₂ a ≃ β₃ a) : (sigma_congr_right F).trans (sigma_congr_right G) = sigma_congr_right (λ a, (F a).trans (G a)) := by { ext1 x, cases x, refl } @[simp] lemma sigma_congr_right_symm {α} {β₁ β₂ : α → Type*} (F : Π a, β₁ a ≃ β₂ a) : (sigma_congr_right F).symm = sigma_congr_right (λ a, (F a).symm) := by { ext1 x, cases x, refl } @[simp] lemma sigma_congr_right_refl {α} {β : α → Type*} : (sigma_congr_right (λ a, equiv.refl (β a))) = equiv.refl (Σ a, β a) := by { ext1 x, cases x, refl } /-- A `psigma` with `Prop` fibers is equivalent to the subtype. -/ def psigma_equiv_subtype {α : Type v} (P : α → Prop) : (Σ' i, P i) ≃ subtype P := { to_fun := λ x, ⟨x.1, x.2⟩, inv_fun := λ x, ⟨x.1, x.2⟩, left_inv := λ x, by { cases x, refl, }, right_inv := λ x, by { cases x, refl, }, } /-- A `sigma` with `plift` fibers is equivalent to the subtype. -/ def sigma_plift_equiv_subtype {α : Type v} (P : α → Prop) : (Σ i, plift (P i)) ≃ subtype P := ((psigma_equiv_sigma _).symm.trans (psigma_congr_right (λ a, equiv.plift))).trans (psigma_equiv_subtype P) /-- A `sigma` with `λ i, ulift (plift (P i))` fibers is equivalent to `{ x // P x }`. Variant of `sigma_plift_equiv_subtype`. -/ def sigma_ulift_plift_equiv_subtype {α : Type v} (P : α → Prop) : (Σ i, ulift (plift (P i))) ≃ subtype P := (sigma_congr_right (λ a, equiv.ulift)).trans (sigma_plift_equiv_subtype P) namespace perm /-- A family of permutations `Π a, perm (β a)` generates a permuation `perm (Σ a, β₁ a)`. -/ @[reducible] def sigma_congr_right {α} {β : α → Sort*} (F : Π a, perm (β a)) : perm (Σ a, β a) := equiv.sigma_congr_right F @[simp] lemma sigma_congr_right_trans {α} {β : α → Sort*} (F : Π a, perm (β a)) (G : Π a, perm (β a)) : (sigma_congr_right F).trans (sigma_congr_right G) = sigma_congr_right (λ a, (F a).trans (G a)) := equiv.sigma_congr_right_trans F G @[simp] lemma sigma_congr_right_symm {α} {β : α → Sort*} (F : Π a, perm (β a)) : (sigma_congr_right F).symm = sigma_congr_right (λ a, (F a).symm) := equiv.sigma_congr_right_symm F @[simp] lemma sigma_congr_right_refl {α} {β : α → Sort*} : (sigma_congr_right (λ a, equiv.refl (β a))) = equiv.refl (Σ a, β a) := equiv.sigma_congr_right_refl end perm /-- An equivalence `f : α₁ ≃ α₂` generates an equivalence between `Σ a, β (f a)` and `Σ a, β a`. -/ @[simps apply] def sigma_congr_left {α₁ α₂} {β : α₂ → Sort*} (e : α₁ ≃ α₂) : (Σ a:α₁, β (e a)) ≃ (Σ a:α₂, β a) := ⟨λ a, ⟨e a.1, a.2⟩, λ a, ⟨e.symm a.1, @@eq.rec β a.2 (e.right_inv a.1).symm⟩, λ ⟨a, b⟩, match e.symm (e a), e.left_inv a : ∀ a' (h : a' = a), @sigma.mk _ (β ∘ e) _ (@@eq.rec β b (congr_arg e h.symm)) = ⟨a, b⟩ with | _, rfl := rfl end, λ ⟨a, b⟩, match e (e.symm a), _ : ∀ a' (h : a' = a), sigma.mk a' (@@eq.rec β b h.symm) = ⟨a, b⟩ with | _, rfl := rfl end⟩ /-- Transporting a sigma type through an equivalence of the base -/ def sigma_congr_left' {α₁ α₂} {β : α₁ → Sort*} (f : α₁ ≃ α₂) : (Σ a:α₁, β a) ≃ (Σ a:α₂, β (f.symm a)) := (sigma_congr_left f.symm).symm /-- Transporting a sigma type through an equivalence of the base and a family of equivalences of matching fibers -/ def sigma_congr {α₁ α₂} {β₁ : α₁ → Sort*} {β₂ : α₂ → Sort*} (f : α₁ ≃ α₂) (F : ∀ a, β₁ a ≃ β₂ (f a)) : sigma β₁ ≃ sigma β₂ := (sigma_congr_right F).trans (sigma_congr_left f) /-- `sigma` type with a constant fiber is equivalent to the product. -/ @[simps apply symm_apply { attrs := [`simp, `mfld_simps] }] def sigma_equiv_prod (α β : Type*) : (Σ_:α, β) ≃ α × β := ⟨λ a, ⟨a.1, a.2⟩, λ a, ⟨a.1, a.2⟩, λ ⟨a, b⟩, rfl, λ ⟨a, b⟩, rfl⟩ /-- If each fiber of a `sigma` type is equivalent to a fixed type, then the sigma type is equivalent to the product. -/ def sigma_equiv_prod_of_equiv {α β} {β₁ : α → Sort*} (F : Π a, β₁ a ≃ β) : sigma β₁ ≃ α × β := (sigma_congr_right F).trans (sigma_equiv_prod α β) /-- Dependent product of types is associative up to an equivalence. -/ def sigma_assoc {α : Type*} {β : α → Type*} (γ : Π (a : α), β a → Type*) : (Σ (ab : Σ (a : α), β a), γ ab.1 ab.2) ≃ Σ (a : α), (Σ (b : β a), γ a b) := { to_fun := λ x, ⟨x.1.1, ⟨x.1.2, x.2⟩⟩, inv_fun := λ x, ⟨⟨x.1, x.2.1⟩, x.2.2⟩, left_inv := λ ⟨⟨a, b⟩, c⟩, rfl, right_inv := λ ⟨a, ⟨b, c⟩⟩, rfl } end protected lemma exists_unique_congr {p : α → Prop} {q : β → Prop} (f : α ≃ β) (h : ∀{x}, p x ↔ q (f x)) : (∃! x, p x) ↔ ∃! y, q y := begin split, { rintro ⟨a, ha₁, ha₂⟩, exact ⟨f a, h.1 ha₁, λ b hb, f.symm_apply_eq.1 (ha₂ (f.symm b) (h.2 (by simpa using hb)))⟩ }, { rintro ⟨b, hb₁, hb₂⟩, exact ⟨f.symm b, h.2 (by simpa using hb₁), λ y hy, (eq_symm_apply f).2 (hb₂ _ (h.1 hy))⟩ } end protected lemma exists_unique_congr_left' {p : α → Prop} (f : α ≃ β) : (∃! x, p x) ↔ (∃! y, p (f.symm y)) := equiv.exists_unique_congr f (λx, by simp) protected lemma exists_unique_congr_left {p : β → Prop} (f : α ≃ β) : (∃! x, p (f x)) ↔ (∃! y, p y) := (equiv.exists_unique_congr_left' f.symm).symm protected lemma forall_congr {p : α → Prop} {q : β → Prop} (f : α ≃ β) (h : ∀{x}, p x ↔ q (f x)) : (∀x, p x) ↔ (∀y, q y) := begin split; intros h₂ x, { rw [←f.right_inv x], apply h.mp, apply h₂ }, apply h.mpr, apply h₂ end protected lemma forall_congr' {p : α → Prop} {q : β → Prop} (f : α ≃ β) (h : ∀{x}, p (f.symm x) ↔ q x) : (∀x, p x) ↔ (∀y, q y) := (equiv.forall_congr f.symm (λ x, h.symm)).symm -- We next build some higher arity versions of `equiv.forall_congr`. -- Although they appear to just be repeated applications of `equiv.forall_congr`, -- unification of metavariables works better with these versions. -- In particular, they are necessary in `equiv_rw`. -- (Stopping at ternary functions seems reasonable: at least in 1-categorical mathematics, -- it's rare to have axioms involving more than 3 elements at once.) universes ua1 ua2 ub1 ub2 ug1 ug2 variables {α₁ : Sort ua1} {α₂ : Sort ua2} {β₁ : Sort ub1} {β₂ : Sort ub2} {γ₁ : Sort ug1} {γ₂ : Sort ug2} protected lemma forall₂_congr {p : α₁ → β₁ → Prop} {q : α₂ → β₂ → Prop} (eα : α₁ ≃ α₂) (eβ : β₁ ≃ β₂) (h : ∀{x y}, p x y ↔ q (eα x) (eβ y)) : (∀x y, p x y) ↔ (∀x y, q x y) := begin apply equiv.forall_congr, intros, apply equiv.forall_congr, intros, apply h, end protected lemma forall₂_congr' {p : α₁ → β₁ → Prop} {q : α₂ → β₂ → Prop} (eα : α₁ ≃ α₂) (eβ : β₁ ≃ β₂) (h : ∀{x y}, p (eα.symm x) (eβ.symm y) ↔ q x y) : (∀x y, p x y) ↔ (∀x y, q x y) := (equiv.forall₂_congr eα.symm eβ.symm (λ x y, h.symm)).symm protected lemma forall₃_congr {p : α₁ → β₁ → γ₁ → Prop} {q : α₂ → β₂ → γ₂ → Prop} (eα : α₁ ≃ α₂) (eβ : β₁ ≃ β₂) (eγ : γ₁ ≃ γ₂) (h : ∀{x y z}, p x y z ↔ q (eα x) (eβ y) (eγ z)) : (∀x y z, p x y z) ↔ (∀x y z, q x y z) := begin apply equiv.forall₂_congr, intros, apply equiv.forall_congr, intros, apply h, end protected lemma forall₃_congr' {p : α₁ → β₁ → γ₁ → Prop} {q : α₂ → β₂ → γ₂ → Prop} (eα : α₁ ≃ α₂) (eβ : β₁ ≃ β₂) (eγ : γ₁ ≃ γ₂) (h : ∀{x y z}, p (eα.symm x) (eβ.symm y) (eγ.symm z) ↔ q x y z) : (∀x y z, p x y z) ↔ (∀x y z, q x y z) := (equiv.forall₃_congr eα.symm eβ.symm eγ.symm (λ x y z, h.symm)).symm protected lemma forall_congr_left' {p : α → Prop} (f : α ≃ β) : (∀x, p x) ↔ (∀y, p (f.symm y)) := equiv.forall_congr f (λx, by simp) protected lemma forall_congr_left {p : β → Prop} (f : α ≃ β) : (∀x, p (f x)) ↔ (∀y, p y) := (equiv.forall_congr_left' f.symm).symm protected lemma exists_congr_left {α β} (f : α ≃ β) {p : α → Prop} : (∃ a, p a) ↔ (∃ b, p (f.symm b)) := ⟨λ ⟨a, h⟩, ⟨f a, by simpa using h⟩, λ ⟨b, h⟩, ⟨_, h⟩⟩ end equiv namespace quot /-- An equivalence `e : α ≃ β` generates an equivalence between quotient spaces, if `ra a₁ a₂ ↔ rb (e a₁) (e a₂). -/ protected def congr {ra : α → α → Prop} {rb : β → β → Prop} (e : α ≃ β) (eq : ∀a₁ a₂, ra a₁ a₂ ↔ rb (e a₁) (e a₂)) : quot ra ≃ quot rb := { to_fun := quot.map e (assume a₁ a₂, (eq a₁ a₂).1), inv_fun := quot.map e.symm (assume b₁ b₂ h, (eq (e.symm b₁) (e.symm b₂)).2 ((e.apply_symm_apply b₁).symm ▸ (e.apply_symm_apply b₂).symm ▸ h)), left_inv := by { rintros ⟨a⟩, dunfold quot.map, simp only [equiv.symm_apply_apply] }, right_inv := by { rintros ⟨a⟩, dunfold quot.map, simp only [equiv.apply_symm_apply] } } @[simp] lemma congr_mk {ra : α → α → Prop} {rb : β → β → Prop} (e : α ≃ β) (eq : ∀ (a₁ a₂ : α), ra a₁ a₂ ↔ rb (e a₁) (e a₂)) (a : α) : quot.congr e eq (quot.mk ra a) = quot.mk rb (e a) := rfl /-- Quotients are congruent on equivalences under equality of their relation. An alternative is just to use rewriting with `eq`, but then computational proofs get stuck. -/ protected def congr_right {r r' : α → α → Prop} (eq : ∀a₁ a₂, r a₁ a₂ ↔ r' a₁ a₂) : quot r ≃ quot r' := quot.congr (equiv.refl α) eq /-- An equivalence `e : α ≃ β` generates an equivalence between the quotient space of `α` by a relation `ra` and the quotient space of `β` by the image of this relation under `e`. -/ protected def congr_left {r : α → α → Prop} (e : α ≃ β) : quot r ≃ quot (λ b b', r (e.symm b) (e.symm b')) := @quot.congr α β r (λ b b', r (e.symm b) (e.symm b')) e (λ a₁ a₂, by simp only [e.symm_apply_apply]) end quot namespace quotient /-- An equivalence `e : α ≃ β` generates an equivalence between quotient spaces, if `ra a₁ a₂ ↔ rb (e a₁) (e a₂). -/ protected def congr {ra : setoid α} {rb : setoid β} (e : α ≃ β) (eq : ∀a₁ a₂, @setoid.r α ra a₁ a₂ ↔ @setoid.r β rb (e a₁) (e a₂)) : quotient ra ≃ quotient rb := quot.congr e eq @[simp] lemma congr_mk {ra : setoid α} {rb : setoid β} (e : α ≃ β) (eq : ∀ (a₁ a₂ : α), setoid.r a₁ a₂ ↔ setoid.r (e a₁) (e a₂)) (a : α): quotient.congr e eq (quotient.mk a) = quotient.mk (e a) := rfl /-- Quotients are congruent on equivalences under equality of their relation. An alternative is just to use rewriting with `eq`, but then computational proofs get stuck. -/ protected def congr_right {r r' : setoid α} (eq : ∀a₁ a₂, @setoid.r α r a₁ a₂ ↔ @setoid.r α r' a₁ a₂) : quotient r ≃ quotient r' := quot.congr_right eq end quotient
a0481de1a258424512125aa50d6c93fe3f51056e
57aec6ee746bc7e3a3dd5e767e53bd95beb82f6d
/stage0/src/Lean/Parser/Do.lean
d665ab1716788f1eba238abc657527a2d7cd5e0d
[ "Apache-2.0" ]
permissive
collares/lean4
861a9269c4592bce49b71059e232ff0bfe4594cc
52a4f535d853a2c7c7eea5fee8a4fa04c682c1ee
refs/heads/master
1,691,419,031,324
1,618,678,138,000
1,618,678,138,000
358,989,750
0
0
Apache-2.0
1,618,696,333,000
1,618,696,333,000
null
UTF-8
Lean
false
false
7,287
lean
/- Copyright (c) 2020 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Lean.Parser.Term namespace Lean namespace Parser builtin_initialize registerBuiltinParserAttribute `builtinDoElemParser `doElem builtin_initialize registerBuiltinDynamicParserAttribute `doElemParser `doElem @[inline] def doElemParser (rbp : Nat := 0) : Parser := categoryParser `doElem rbp namespace Term def leftArrow : Parser := unicodeSymbol " ← " " <- " @[builtinTermParser] def liftMethod := leading_parser:minPrec leftArrow >> termParser def doSeqItem := leading_parser ppLine >> doElemParser >> optional "; " def doSeqIndent := leading_parser many1Indent doSeqItem def doSeqBracketed := leading_parser "{" >> withoutPosition (many1 doSeqItem) >> ppLine >> "}" def doSeq := doSeqBracketed <|> doSeqIndent def termBeforeDo := withForbidden "do" termParser attribute [runBuiltinParserAttributeHooks] doSeq termBeforeDo builtin_initialize register_parser_alias "doSeq" doSeq register_parser_alias "termBeforeDo" termBeforeDo def notFollowedByRedefinedTermToken := -- Remark: we don't currently support `open` and `set_option` in `do`-blocks, but we include them in the following list to fix the ambiguity -- "open" command following `do`-block. If we don't add `do`, then users would have to indent `do` blocks or use `{ ... }`. notFollowedBy ("set_option" <|> "open" <|> "if" <|> "match" <|> "let" <|> "have" <|> "do" <|> "dbg_trace" <|> "assert!" <|> "for" <|> "unless" <|> "return" <|> symbol "try") "token at 'do' element" @[builtinDoElemParser] def doLet := leading_parser "let " >> optional "mut " >> letDecl @[builtinDoElemParser] def doLetRec := leading_parser group ("let " >> nonReservedSymbol "rec ") >> letRecDecls def doIdDecl := leading_parser atomic (ident >> optType >> leftArrow) >> doElemParser def doPatDecl := leading_parser atomic (termParser >> leftArrow) >> doElemParser >> optional (checkColGt >> " | " >> doElemParser) @[builtinDoElemParser] def doLetArrow := leading_parser withPosition ("let " >> optional "mut " >> (doIdDecl <|> doPatDecl)) -- We use `letIdDeclNoBinders` to define `doReassign`. -- Motivation: we do not reassign functions, and avoid parser conflict def letIdDeclNoBinders := node `Lean.Parser.Term.letIdDecl $ atomic (ident >> pushNone >> optType >> " := ") >> termParser @[builtinDoElemParser] def doReassign := leading_parser notFollowedByRedefinedTermToken >> (letIdDeclNoBinders <|> letPatDecl) @[builtinDoElemParser] def doReassignArrow := leading_parser notFollowedByRedefinedTermToken >> withPosition (doIdDecl <|> doPatDecl) @[builtinDoElemParser] def doHave := leading_parser "have " >> Term.haveDecl /- In `do` blocks, we support `if` without an `else`. Thus, we use indentation to prevent examples such as ``` if c_1 then if c_2 then action_1 else action_2 ``` from being parsed as ``` if c_1 then { if c_2 then { action_1 } else { action_2 } } ``` We also have special support for `else if` because we don't want to write ``` if c_1 then action_1 else if c_2 then action_2 else action_3 ``` -/ def elseIf := atomic (group (withPosition (" else " >> checkLineEq >> " if "))) -- ensure `if $e then ...` still binds to `e:term` def doIfLetPure := leading_parser " := " >> termParser def doIfLetBind := leading_parser " ← " >> termParser def doIfLet := nodeWithAntiquot "doIfLet" `Lean.Parser.Term.doIfLet <| "let " >> termParser >> (doIfLetPure <|> doIfLetBind) def doIfProp := nodeWithAntiquot "doIfProp" `Lean.Parser.Term.doIfProp <| optIdent >> termParser def doIfCond := withAntiquot (mkAntiquot "doIfCond" none (anonymous := false)) <| doIfLet <|> doIfProp @[builtinDoElemParser] def doIf := leading_parser withPosition $ "if " >> doIfCond >> " then " >> doSeq >> many (checkColGe "'else if' in 'do' must be indented" >> group (elseIf >> doIfCond >> " then " >> doSeq)) >> optional (checkColGe "'else' in 'do' must be indented" >> " else " >> doSeq) @[builtinDoElemParser] def doUnless := leading_parser "unless " >> withForbidden "do" termParser >> "do " >> doSeq def doForDecl := leading_parser termParser >> " in " >> withForbidden "do" termParser @[builtinDoElemParser] def doFor := leading_parser "for " >> sepBy1 doForDecl ", " >> "do " >> doSeq def doMatchAlts := matchAlts (rhsParser := doSeq) @[builtinDoElemParser] def doMatch := leading_parser:leadPrec "match " >> optional Term.generalizingParam >> sepBy1 matchDiscr ", " >> optType >> " with " >> doMatchAlts def doCatch := leading_parser atomic ("catch " >> binderIdent) >> optional (" : " >> termParser) >> darrow >> doSeq def doCatchMatch := leading_parser "catch " >> doMatchAlts def doFinally := leading_parser "finally " >> doSeq @[builtinDoElemParser] def doTry := leading_parser "try " >> doSeq >> many (doCatch <|> doCatchMatch) >> optional doFinally @[builtinDoElemParser] def doBreak := leading_parser "break" @[builtinDoElemParser] def doContinue := leading_parser "continue" @[builtinDoElemParser] def doReturn := leading_parser:leadPrec withPosition ("return " >> optional (checkLineEq >> termParser)) @[builtinDoElemParser] def doDbgTrace := leading_parser:leadPrec "dbg_trace " >> ((interpolatedStr termParser) <|> termParser) @[builtinDoElemParser] def doAssert := leading_parser:leadPrec "assert! " >> termParser /- We use `notFollowedBy` to avoid counterintuitive behavior. For example, the `if`-term parser doesn't enforce indentation restrictions, but we don't want it to be used when `doIf` fails. Note that parser priorities would not solve this problem since the `doIf` parser is failing while the `if` parser is succeeding. The first `notFollowedBy` prevents this problem. Consider the `doElem` `x := (a, b⟩` it contains an error since we are using `⟩` instead of `)`. Thus, `doReassign` parser fails. However, `doExpr` would succeed consuming just `x`, and cryptic error message is generated after that. The second `notFollowedBy` prevents this problem. -/ @[builtinDoElemParser] def doExpr := leading_parser notFollowedByRedefinedTermToken >> termParser >> notFollowedBy (symbol ":=" <|> symbol "←" <|> symbol "<-") "unexpected token after 'expr' in 'do' block" @[builtinDoElemParser] def doNested := leading_parser "do " >> doSeq @[builtinTermParser] def «do» := leading_parser:argPrec "do " >> doSeq @[builtinTermParser] def doElem.quot : Parser := leading_parser "`(doElem|" >> toggleInsideQuot doElemParser >> ")" /- macros for using `unless`, `for`, `try`, `return` as terms. They expand into `do unless ...`, `do for ...`, `do try ...`, and `do return ...` -/ @[builtinTermParser] def termUnless := leading_parser "unless " >> withForbidden "do" termParser >> "do " >> doSeq @[builtinTermParser] def termFor := leading_parser "for " >> sepBy1 doForDecl ", " >> "do " >> doSeq @[builtinTermParser] def termTry := leading_parser "try " >> doSeq >> many (doCatch <|> doCatchMatch) >> optional doFinally @[builtinTermParser] def termReturn := leading_parser:leadPrec withPosition ("return " >> optional (checkLineEq >> termParser)) end Term end Parser end Lean
aa40a987bba046b480ea1636a037dc36c68ef859
d9d511f37a523cd7659d6f573f990e2a0af93c6f
/src/data/set/function.lean
98d57403328fa992ddc9ce13188443a4e1b9fc87
[ "Apache-2.0" ]
permissive
hikari0108/mathlib
b7ea2b7350497ab1a0b87a09d093ecc025a50dfa
a9e7d333b0cfd45f13a20f7b96b7d52e19fa2901
refs/heads/master
1,690,483,608,260
1,631,541,580,000
1,631,541,580,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
37,665
lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Andrew Zipperer, Haitao Zhang, Minchao Wu, Yury Kudryashov -/ import data.set.basic import logic.function.conjugate /-! # Functions over sets ## Main definitions ### Predicate * `set.eq_on f₁ f₂ s` : functions `f₁` and `f₂` are equal at every point of `s`; * `set.maps_to f s t` : `f` sends every point of `s` to a point of `t`; * `set.inj_on f s` : restriction of `f` to `s` is injective; * `set.surj_on f s t` : every point in `s` has a preimage in `s`; * `set.bij_on f s t` : `f` is a bijection between `s` and `t`; * `set.left_inv_on f' f s` : for every `x ∈ s` we have `f' (f x) = x`; * `set.right_inv_on f' f t` : for every `y ∈ t` we have `f (f' y) = y`; * `set.inv_on f' f s t` : `f'` is a two-side inverse of `f` on `s` and `t`, i.e. we have `set.left_inv_on f' f s` and `set.right_inv_on f' f t`. ### Functions * `set.restrict f s` : restrict the domain of `f` to the set `s`; * `set.cod_restrict f s h` : given `h : ∀ x, f x ∈ s`, restrict the codomain of `f` to the set `s`; * `set.maps_to.restrict f s t h`: given `h : maps_to f s t`, restrict the domain of `f` to `s` and the codomain to `t`. -/ universes u v w x y variables {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} open function namespace set /-! ### Restrict -/ /-- Restrict domain of a function `f` to a set `s`. Same as `subtype.restrict` but this version takes an argument `↥s` instead of `subtype s`. -/ def restrict (f : α → β) (s : set α) : s → β := λ x, f x lemma restrict_eq (f : α → β) (s : set α) : s.restrict f = f ∘ coe := rfl @[simp] lemma restrict_apply (f : α → β) (s : set α) (x : s) : restrict f s x = f x := rfl @[simp] lemma range_restrict (f : α → β) (s : set α) : set.range (restrict f s) = f '' s := (range_comp _ _).trans $ congr_arg (('') f) subtype.range_coe lemma image_restrict (f : α → β) (s t : set α) : s.restrict f '' (coe ⁻¹' t) = f '' (t ∩ s) := by rw [restrict, image_comp, image_preimage_eq_inter_range, subtype.range_coe] /-- Restrict codomain of a function `f` to a set `s`. Same as `subtype.coind` but this version has codomain `↥s` instead of `subtype s`. -/ def cod_restrict (f : α → β) (s : set β) (h : ∀ x, f x ∈ s) : α → s := λ x, ⟨f x, h x⟩ @[simp] lemma coe_cod_restrict_apply (f : α → β) (s : set β) (h : ∀ x, f x ∈ s) (x : α) : (cod_restrict f s h x : β) = f x := rfl variables {s s₁ s₂ : set α} {t t₁ t₂ : set β} {p : set γ} {f f₁ f₂ f₃ : α → β} {g : β → γ} {f' f₁' f₂' : β → α} {g' : γ → β} /-! ### Equality on a set -/ /-- Two functions `f₁ f₂ : α → β` are equal on `s` if `f₁ x = f₂ x` for all `x ∈ a`. -/ def eq_on (f₁ f₂ : α → β) (s : set α) : Prop := ∀ ⦃x⦄, x ∈ s → f₁ x = f₂ x @[simp] lemma eq_on_empty (f₁ f₂ : α → β) : eq_on f₁ f₂ ∅ := λ x, false.elim @[symm] lemma eq_on.symm (h : eq_on f₁ f₂ s) : eq_on f₂ f₁ s := λ x hx, (h hx).symm lemma eq_on_comm : eq_on f₁ f₂ s ↔ eq_on f₂ f₁ s := ⟨eq_on.symm, eq_on.symm⟩ @[refl] lemma eq_on_refl (f : α → β) (s : set α) : eq_on f f s := λ _ _, rfl @[trans] lemma eq_on.trans (h₁ : eq_on f₁ f₂ s) (h₂ : eq_on f₂ f₃ s) : eq_on f₁ f₃ s := λ x hx, (h₁ hx).trans (h₂ hx) theorem eq_on.image_eq (heq : eq_on f₁ f₂ s) : f₁ '' s = f₂ '' s := image_congr heq theorem eq_on.inter_preimage_eq (heq : eq_on f₁ f₂ s) (t : set β) : s ∩ f₁ ⁻¹' t = s ∩ f₂ ⁻¹' t := ext $ λ x, and.congr_right_iff.2 $ λ hx, by rw [mem_preimage, mem_preimage, heq hx] lemma eq_on.mono (hs : s₁ ⊆ s₂) (hf : eq_on f₁ f₂ s₂) : eq_on f₁ f₂ s₁ := λ x hx, hf (hs hx) lemma comp_eq_of_eq_on_range {ι : Sort*} {f : ι → α} {g₁ g₂ : α → β} (h : eq_on g₁ g₂ (range f)) : g₁ ∘ f = g₂ ∘ f := funext $ λ x, h $ mem_range_self _ /-! ### maps to -/ /-- `maps_to f a b` means that the image of `a` is contained in `b`. -/ @[reducible] def maps_to (f : α → β) (s : set α) (t : set β) : Prop := ∀ ⦃x⦄, x ∈ s → f x ∈ t /-- Given a map `f` sending `s : set α` into `t : set β`, restrict domain of `f` to `s` and the codomain to `t`. Same as `subtype.map`. -/ def maps_to.restrict (f : α → β) (s : set α) (t : set β) (h : maps_to f s t) : s → t := subtype.map f h @[simp] lemma maps_to.coe_restrict_apply (h : maps_to f s t) (x : s) : (h.restrict f s t x : β) = f x := rfl lemma maps_to_iff_exists_map_subtype : maps_to f s t ↔ ∃ g : s → t, ∀ x : s, f x = g x := ⟨λ h, ⟨h.restrict f s t, λ _, rfl⟩, λ ⟨g, hg⟩ x hx, by { erw [hg ⟨x, hx⟩], apply subtype.coe_prop }⟩ theorem maps_to' : maps_to f s t ↔ f '' s ⊆ t := image_subset_iff.symm theorem maps_to_empty (f : α → β) (t : set β) : maps_to f ∅ t := empty_subset _ theorem maps_to.image_subset (h : maps_to f s t) : f '' s ⊆ t := maps_to'.1 h theorem maps_to.congr (h₁ : maps_to f₁ s t) (h : eq_on f₁ f₂ s) : maps_to f₂ s t := λ x hx, h hx ▸ h₁ hx theorem eq_on.maps_to_iff (H : eq_on f₁ f₂ s) : maps_to f₁ s t ↔ maps_to f₂ s t := ⟨λ h, h.congr H, λ h, h.congr H.symm⟩ theorem maps_to.comp (h₁ : maps_to g t p) (h₂ : maps_to f s t) : maps_to (g ∘ f) s p := λ x h, h₁ (h₂ h) theorem maps_to_id (s : set α) : maps_to id s s := λ x, id theorem maps_to.iterate {f : α → α} {s : set α} (h : maps_to f s s) : ∀ n, maps_to (f^[n]) s s | 0 := λ _, id | (n+1) := (maps_to.iterate n).comp h theorem maps_to.iterate_restrict {f : α → α} {s : set α} (h : maps_to f s s) (n : ℕ) : (h.restrict f s s^[n]) = (h.iterate n).restrict _ _ _ := begin funext x, rw [subtype.ext_iff, maps_to.coe_restrict_apply], induction n with n ihn generalizing x, { refl }, { simp [nat.iterate, ihn] } end theorem maps_to.mono (hs : s₂ ⊆ s₁) (ht : t₁ ⊆ t₂) (hf : maps_to f s₁ t₁) : maps_to f s₂ t₂ := λ x hx, ht (hf $ hs hx) theorem maps_to.union_union (h₁ : maps_to f s₁ t₁) (h₂ : maps_to f s₂ t₂) : maps_to f (s₁ ∪ s₂) (t₁ ∪ t₂) := λ x hx, hx.elim (λ hx, or.inl $ h₁ hx) (λ hx, or.inr $ h₂ hx) theorem maps_to.union (h₁ : maps_to f s₁ t) (h₂ : maps_to f s₂ t) : maps_to f (s₁ ∪ s₂) t := union_self t ▸ h₁.union_union h₂ @[simp] theorem maps_to_union : maps_to f (s₁ ∪ s₂) t ↔ maps_to f s₁ t ∧ maps_to f s₂ t := ⟨λ h, ⟨h.mono (subset_union_left s₁ s₂) (subset.refl t), h.mono (subset_union_right s₁ s₂) (subset.refl t)⟩, λ h, h.1.union h.2⟩ theorem maps_to.inter (h₁ : maps_to f s t₁) (h₂ : maps_to f s t₂) : maps_to f s (t₁ ∩ t₂) := λ x hx, ⟨h₁ hx, h₂ hx⟩ theorem maps_to.inter_inter (h₁ : maps_to f s₁ t₁) (h₂ : maps_to f s₂ t₂) : maps_to f (s₁ ∩ s₂) (t₁ ∩ t₂) := λ x hx, ⟨h₁ hx.1, h₂ hx.2⟩ @[simp] theorem maps_to_inter : maps_to f s (t₁ ∩ t₂) ↔ maps_to f s t₁ ∧ maps_to f s t₂ := ⟨λ h, ⟨h.mono (subset.refl s) (inter_subset_left t₁ t₂), h.mono (subset.refl s) (inter_subset_right t₁ t₂)⟩, λ h, h.1.inter h.2⟩ theorem maps_to_univ (f : α → β) (s : set α) : maps_to f s univ := λ x h, trivial theorem maps_to_image (f : α → β) (s : set α) : maps_to f s (f '' s) := by rw maps_to' theorem maps_to_preimage (f : α → β) (t : set β) : maps_to f (f ⁻¹' t) t := subset.refl _ theorem maps_to_range (f : α → β) (s : set α) : maps_to f s (range f) := (maps_to_image f s).mono (subset.refl s) (image_subset_range _ _) @[simp] lemma maps_image_to (f : α → β) (g : γ → α) (s : set γ) (t : set β) : maps_to f (g '' s) t ↔ maps_to (f ∘ g) s t := ⟨λ h c hc, h ⟨c, hc, rfl⟩, λ h d ⟨c, hc⟩, hc.2 ▸ h hc.1⟩ @[simp] lemma maps_univ_to (f : α → β) (s : set β) : maps_to f univ s ↔ ∀ a, f a ∈ s := ⟨λ h a, h (mem_univ _), λ h x _, h x⟩ @[simp] lemma maps_range_to (f : α → β) (g : γ → α) (s : set β) : maps_to f (range g) s ↔ maps_to (f ∘ g) univ s := by rw [←image_univ, maps_image_to] theorem surjective_maps_to_image_restrict (f : α → β) (s : set α) : surjective ((maps_to_image f s).restrict f s (f '' s)) := λ ⟨y, x, hs, hxy⟩, ⟨⟨x, hs⟩, subtype.ext hxy⟩ theorem maps_to.mem_iff (h : maps_to f s t) (hc : maps_to f sᶜ tᶜ) {x} : f x ∈ t ↔ x ∈ s := ⟨λ ht, by_contra $ λ hs, hc hs ht, λ hx, h hx⟩ /-! ### Injectivity on a set -/ /-- `f` is injective on `a` if the restriction of `f` to `a` is injective. -/ @[reducible] def inj_on (f : α → β) (s : set α) : Prop := ∀ ⦃x₁ : α⦄, x₁ ∈ s → ∀ ⦃x₂ : α⦄, x₂ ∈ s → f x₁ = f x₂ → x₁ = x₂ theorem inj_on_empty (f : α → β) : inj_on f ∅ := λ _ h₁, false.elim h₁ theorem inj_on.eq_iff {x y} (h : inj_on f s) (hx : x ∈ s) (hy : y ∈ s) : f x = f y ↔ x = y := ⟨h hx hy, λ h, h ▸ rfl⟩ theorem inj_on.congr (h₁ : inj_on f₁ s) (h : eq_on f₁ f₂ s) : inj_on f₂ s := λ x hx y hy, h hx ▸ h hy ▸ h₁ hx hy theorem eq_on.inj_on_iff (H : eq_on f₁ f₂ s) : inj_on f₁ s ↔ inj_on f₂ s := ⟨λ h, h.congr H, λ h, h.congr H.symm⟩ theorem inj_on.mono (h : s₁ ⊆ s₂) (ht : inj_on f s₂) : inj_on f s₁ := λ x hx y hy H, ht (h hx) (h hy) H theorem inj_on_insert {f : α → β} {s : set α} {a : α} (has : a ∉ s) : set.inj_on f (insert a s) ↔ set.inj_on f s ∧ f a ∉ f '' s := ⟨λ hf, ⟨hf.mono $ subset_insert a s, λ ⟨x, hxs, hx⟩, has $ mem_of_eq_of_mem (hf (or.inl rfl) (or.inr hxs) hx.symm) hxs⟩, λ ⟨h1, h2⟩ x hx y hy hfxy, or.cases_on hx (λ hxa : x = a, or.cases_on hy (λ hya : y = a, hxa.trans hya.symm) (λ hys : y ∈ s, h2.elim ⟨y, hys, hxa ▸ hfxy.symm⟩)) (λ hxs : x ∈ s, or.cases_on hy (λ hya : y = a, h2.elim ⟨x, hxs, hya ▸ hfxy⟩) (λ hys : y ∈ s, h1 hxs hys hfxy))⟩ lemma injective_iff_inj_on_univ : injective f ↔ inj_on f univ := ⟨λ h x hx y hy hxy, h hxy, λ h _ _ heq, h trivial trivial heq⟩ lemma inj_on_of_injective (h : injective f) (s : set α) : inj_on f s := λ x hx y hy hxy, h hxy alias inj_on_of_injective ← function.injective.inj_on theorem inj_on.comp (hg : inj_on g t) (hf: inj_on f s) (h : maps_to f s t) : inj_on (g ∘ f) s := λ x hx y hy heq, hf hx hy $ hg (h hx) (h hy) heq lemma inj_on_iff_injective : inj_on f s ↔ injective (restrict f s) := ⟨λ H a b h, subtype.eq $ H a.2 b.2 h, λ H a as b bs h, congr_arg subtype.val $ @H ⟨a, as⟩ ⟨b, bs⟩ h⟩ lemma inj_on_preimage {B : set (set β)} (hB : B ⊆ 𝒫 (range f)) : inj_on (preimage f) B := λ s hs t ht hst, (preimage_eq_preimage' (hB hs) (hB ht)).1 hst lemma inj_on.mem_of_mem_image {x} (hf : inj_on f s) (hs : s₁ ⊆ s) (h : x ∈ s) (h₁ : f x ∈ f '' s₁) : x ∈ s₁ := let ⟨x', h', eq⟩ := h₁ in hf (hs h') h eq ▸ h' lemma inj_on.mem_image_iff {x} (hf : inj_on f s) (hs : s₁ ⊆ s) (hx : x ∈ s) : f x ∈ f '' s₁ ↔ x ∈ s₁ := ⟨hf.mem_of_mem_image hs hx, mem_image_of_mem f⟩ lemma inj_on.preimage_image_inter (hf : inj_on f s) (hs : s₁ ⊆ s) : f ⁻¹' (f '' s₁) ∩ s = s₁ := ext $ λ x, ⟨λ ⟨h₁, h₂⟩, hf.mem_of_mem_image hs h₂ h₁, λ h, ⟨mem_image_of_mem _ h, hs h⟩⟩ /-! ### Surjectivity on a set -/ /-- `f` is surjective from `a` to `b` if `b` is contained in the image of `a`. -/ @[reducible] def surj_on (f : α → β) (s : set α) (t : set β) : Prop := t ⊆ f '' s theorem surj_on.subset_range (h : surj_on f s t) : t ⊆ range f := subset.trans h $ image_subset_range f s lemma surj_on_iff_exists_map_subtype : surj_on f s t ↔ ∃ (t' : set β) (g : s → t'), t ⊆ t' ∧ surjective g ∧ ∀ x : s, f x = g x := ⟨λ h, ⟨_, (maps_to_image f s).restrict f s _, h, surjective_maps_to_image_restrict _ _, λ _, rfl⟩, λ ⟨t', g, htt', hg, hfg⟩ y hy, let ⟨x, hx⟩ := hg ⟨y, htt' hy⟩ in ⟨x, x.2, by rw [hfg, hx, subtype.coe_mk]⟩⟩ theorem surj_on_empty (f : α → β) (s : set α) : surj_on f s ∅ := empty_subset _ theorem surj_on_image (f : α → β) (s : set α) : surj_on f s (f '' s) := subset.rfl theorem surj_on.comap_nonempty (h : surj_on f s t) (ht : t.nonempty) : s.nonempty := (ht.mono h).of_image theorem surj_on.congr (h : surj_on f₁ s t) (H : eq_on f₁ f₂ s) : surj_on f₂ s t := by rwa [surj_on, ← H.image_eq] theorem eq_on.surj_on_iff (h : eq_on f₁ f₂ s) : surj_on f₁ s t ↔ surj_on f₂ s t := ⟨λ H, H.congr h, λ H, H.congr h.symm⟩ theorem surj_on.mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) (hf : surj_on f s₁ t₂) : surj_on f s₂ t₁ := subset.trans ht $ subset.trans hf $ image_subset _ hs theorem surj_on.union (h₁ : surj_on f s t₁) (h₂ : surj_on f s t₂) : surj_on f s (t₁ ∪ t₂) := λ x hx, hx.elim (λ hx, h₁ hx) (λ hx, h₂ hx) theorem surj_on.union_union (h₁ : surj_on f s₁ t₁) (h₂ : surj_on f s₂ t₂) : surj_on f (s₁ ∪ s₂) (t₁ ∪ t₂) := (h₁.mono (subset_union_left _ _) (subset.refl _)).union (h₂.mono (subset_union_right _ _) (subset.refl _)) theorem surj_on.inter_inter (h₁ : surj_on f s₁ t₁) (h₂ : surj_on f s₂ t₂) (h : inj_on f (s₁ ∪ s₂)) : surj_on f (s₁ ∩ s₂) (t₁ ∩ t₂) := begin intros y hy, rcases h₁ hy.1 with ⟨x₁, hx₁, rfl⟩, rcases h₂ hy.2 with ⟨x₂, hx₂, heq⟩, have : x₁ = x₂, from h (or.inl hx₁) (or.inr hx₂) heq.symm, subst x₂, exact mem_image_of_mem f ⟨hx₁, hx₂⟩ end theorem surj_on.inter (h₁ : surj_on f s₁ t) (h₂ : surj_on f s₂ t) (h : inj_on f (s₁ ∪ s₂)) : surj_on f (s₁ ∩ s₂) t := inter_self t ▸ h₁.inter_inter h₂ h theorem surj_on.comp (hg : surj_on g t p) (hf : surj_on f s t) : surj_on (g ∘ f) s p := subset.trans hg $ subset.trans (image_subset g hf) $ (image_comp g f s) ▸ subset.refl _ lemma surjective_iff_surj_on_univ : surjective f ↔ surj_on f univ univ := by simp [surjective, surj_on, subset_def] lemma surj_on_iff_surjective : surj_on f s univ ↔ surjective (restrict f s) := ⟨λ H b, let ⟨a, as, e⟩ := @H b trivial in ⟨⟨a, as⟩, e⟩, λ H b _, let ⟨⟨a, as⟩, e⟩ := H b in ⟨a, as, e⟩⟩ lemma surj_on.image_eq_of_maps_to (h₁ : surj_on f s t) (h₂ : maps_to f s t) : f '' s = t := eq_of_subset_of_subset h₂.image_subset h₁ lemma surj_on.maps_to_compl (h : surj_on f s t) (h' : injective f) : maps_to f sᶜ tᶜ := λ x hs ht, let ⟨x', hx', heq⟩ := h ht in hs $ h' heq ▸ hx' lemma maps_to.surj_on_compl (h : maps_to f s t) (h' : surjective f) : surj_on f sᶜ tᶜ := h'.forall.2 $ λ x ht, mem_image_of_mem _ $ λ hs, ht (h hs) /-! ### Bijectivity -/ /-- `f` is bijective from `s` to `t` if `f` is injective on `s` and `f '' s = t`. -/ @[reducible] def bij_on (f : α → β) (s : set α) (t : set β) : Prop := maps_to f s t ∧ inj_on f s ∧ surj_on f s t lemma bij_on.maps_to (h : bij_on f s t) : maps_to f s t := h.left lemma bij_on.inj_on (h : bij_on f s t) : inj_on f s := h.right.left lemma bij_on.surj_on (h : bij_on f s t) : surj_on f s t := h.right.right lemma bij_on.mk (h₁ : maps_to f s t) (h₂ : inj_on f s) (h₃ : surj_on f s t) : bij_on f s t := ⟨h₁, h₂, h₃⟩ lemma bij_on_empty (f : α → β) : bij_on f ∅ ∅ := ⟨maps_to_empty f ∅, inj_on_empty f, surj_on_empty f ∅⟩ lemma bij_on.inter (h₁ : bij_on f s₁ t₁) (h₂ : bij_on f s₂ t₂) (h : inj_on f (s₁ ∪ s₂)) : bij_on f (s₁ ∩ s₂) (t₁ ∩ t₂) := ⟨h₁.maps_to.inter_inter h₂.maps_to, h₁.inj_on.mono $ inter_subset_left _ _, h₁.surj_on.inter_inter h₂.surj_on h⟩ lemma bij_on.union (h₁ : bij_on f s₁ t₁) (h₂ : bij_on f s₂ t₂) (h : inj_on f (s₁ ∪ s₂)) : bij_on f (s₁ ∪ s₂) (t₁ ∪ t₂) := ⟨h₁.maps_to.union_union h₂.maps_to, h, h₁.surj_on.union_union h₂.surj_on⟩ theorem bij_on.subset_range (h : bij_on f s t) : t ⊆ range f := h.surj_on.subset_range lemma inj_on.bij_on_image (h : inj_on f s) : bij_on f s (f '' s) := bij_on.mk (maps_to_image f s) h (subset.refl _) theorem bij_on.congr (h₁ : bij_on f₁ s t) (h : eq_on f₁ f₂ s) : bij_on f₂ s t := bij_on.mk (h₁.maps_to.congr h) (h₁.inj_on.congr h) (h₁.surj_on.congr h) theorem eq_on.bij_on_iff (H : eq_on f₁ f₂ s) : bij_on f₁ s t ↔ bij_on f₂ s t := ⟨λ h, h.congr H, λ h, h.congr H.symm⟩ lemma bij_on.image_eq (h : bij_on f s t) : f '' s = t := h.surj_on.image_eq_of_maps_to h.maps_to theorem bij_on.comp (hg : bij_on g t p) (hf : bij_on f s t) : bij_on (g ∘ f) s p := bij_on.mk (hg.maps_to.comp hf.maps_to) (hg.inj_on.comp hf.inj_on hf.maps_to) (hg.surj_on.comp hf.surj_on) theorem bij_on.bijective (h : bij_on f s t) : bijective (t.cod_restrict (s.restrict f) $ λ x, h.maps_to x.val_prop) := ⟨λ x y h', subtype.ext $ h.inj_on x.2 y.2 $ subtype.ext_iff.1 h', λ ⟨y, hy⟩, let ⟨x, hx, hxy⟩ := h.surj_on hy in ⟨⟨x, hx⟩, subtype.eq hxy⟩⟩ lemma bijective_iff_bij_on_univ : bijective f ↔ bij_on f univ univ := iff.intro (λ h, let ⟨inj, surj⟩ := h in ⟨maps_to_univ f _, inj.inj_on _, iff.mp surjective_iff_surj_on_univ surj⟩) (λ h, let ⟨map, inj, surj⟩ := h in ⟨iff.mpr injective_iff_inj_on_univ inj, iff.mpr surjective_iff_surj_on_univ surj⟩) lemma bij_on.compl (hst : bij_on f s t) (hf : bijective f) : bij_on f sᶜ tᶜ := ⟨hst.surj_on.maps_to_compl hf.1, hf.1.inj_on _, hst.maps_to.surj_on_compl hf.2⟩ /-! ### left inverse -/ /-- `g` is a left inverse to `f` on `a` means that `g (f x) = x` for all `x ∈ a`. -/ @[reducible] def left_inv_on (f' : β → α) (f : α → β) (s : set α) : Prop := ∀ ⦃x⦄, x ∈ s → f' (f x) = x lemma left_inv_on.eq_on (h : left_inv_on f' f s) : eq_on (f' ∘ f) id s := h lemma left_inv_on.eq (h : left_inv_on f' f s) {x} (hx : x ∈ s) : f' (f x) = x := h hx lemma left_inv_on.congr_left (h₁ : left_inv_on f₁' f s) {t : set β} (h₁' : maps_to f s t) (heq : eq_on f₁' f₂' t) : left_inv_on f₂' f s := λ x hx, heq (h₁' hx) ▸ h₁ hx theorem left_inv_on.congr_right (h₁ : left_inv_on f₁' f₁ s) (heq : eq_on f₁ f₂ s) : left_inv_on f₁' f₂ s := λ x hx, heq hx ▸ h₁ hx theorem left_inv_on.inj_on (h : left_inv_on f₁' f s) : inj_on f s := λ x₁ h₁ x₂ h₂ heq, calc x₁ = f₁' (f x₁) : eq.symm $ h h₁ ... = f₁' (f x₂) : congr_arg f₁' heq ... = x₂ : h h₂ theorem left_inv_on.surj_on (h : left_inv_on f' f s) (hf : maps_to f s t) : surj_on f' t s := λ x hx, ⟨f x, hf hx, h hx⟩ theorem left_inv_on.maps_to (h : left_inv_on f' f s) (hf : surj_on f s t) : maps_to f' t s := λ y hy, let ⟨x, hs, hx⟩ := hf hy in by rwa [← hx, h hs] theorem left_inv_on.comp (hf' : left_inv_on f' f s) (hg' : left_inv_on g' g t) (hf : maps_to f s t) : left_inv_on (f' ∘ g') (g ∘ f) s := λ x h, calc (f' ∘ g') ((g ∘ f) x) = f' (f x) : congr_arg f' (hg' (hf h)) ... = x : hf' h theorem left_inv_on.mono (hf : left_inv_on f' f s) (ht : s₁ ⊆ s) : left_inv_on f' f s₁ := λ x hx, hf (ht hx) theorem left_inv_on.image_inter' (hf : left_inv_on f' f s) : f '' (s₁ ∩ s) = f' ⁻¹' s₁ ∩ f '' s := begin apply subset.antisymm, { rintro _ ⟨x, ⟨h₁, h⟩, rfl⟩, exact ⟨by rwa [mem_preimage, hf h], mem_image_of_mem _ h⟩ }, { rintro _ ⟨h₁, ⟨x, h, rfl⟩⟩, exact mem_image_of_mem _ ⟨by rwa ← hf h, h⟩ } end theorem left_inv_on.image_inter (hf : left_inv_on f' f s) : f '' (s₁ ∩ s) = f' ⁻¹' (s₁ ∩ s) ∩ f '' s := begin rw hf.image_inter', refine subset.antisymm _ (inter_subset_inter_left _ (preimage_mono $ inter_subset_left _ _)), rintro _ ⟨h₁, x, hx, rfl⟩, exact ⟨⟨h₁, by rwa hf hx⟩, mem_image_of_mem _ hx⟩ end theorem left_inv_on.image_image (hf : left_inv_on f' f s) : f' '' (f '' s) = s := by rw [image_image, image_congr hf, image_id'] theorem left_inv_on.image_image' (hf : left_inv_on f' f s) (hs : s₁ ⊆ s) : f' '' (f '' s₁) = s₁ := (hf.mono hs).image_image /-! ### Right inverse -/ /-- `g` is a right inverse to `f` on `b` if `f (g x) = x` for all `x ∈ b`. -/ @[reducible] def right_inv_on (f' : β → α) (f : α → β) (t : set β) : Prop := left_inv_on f f' t lemma right_inv_on.eq_on (h : right_inv_on f' f t) : eq_on (f ∘ f') id t := h lemma right_inv_on.eq (h : right_inv_on f' f t) {y} (hy : y ∈ t) : f (f' y) = y := h hy lemma left_inv_on.right_inv_on_image (h : left_inv_on f' f s) : right_inv_on f' f (f '' s) := λ y ⟨x, hx, eq⟩, eq ▸ congr_arg f $ h.eq hx theorem right_inv_on.congr_left (h₁ : right_inv_on f₁' f t) (heq : eq_on f₁' f₂' t) : right_inv_on f₂' f t := h₁.congr_right heq theorem right_inv_on.congr_right (h₁ : right_inv_on f' f₁ t) (hg : maps_to f' t s) (heq : eq_on f₁ f₂ s) : right_inv_on f' f₂ t := left_inv_on.congr_left h₁ hg heq theorem right_inv_on.surj_on (hf : right_inv_on f' f t) (hf' : maps_to f' t s) : surj_on f s t := hf.surj_on hf' theorem right_inv_on.maps_to (h : right_inv_on f' f t) (hf : surj_on f' t s) : maps_to f s t := h.maps_to hf theorem right_inv_on.comp (hf : right_inv_on f' f t) (hg : right_inv_on g' g p) (g'pt : maps_to g' p t) : right_inv_on (f' ∘ g') (g ∘ f) p := hg.comp hf g'pt theorem right_inv_on.mono (hf : right_inv_on f' f t) (ht : t₁ ⊆ t) : right_inv_on f' f t₁ := hf.mono ht theorem inj_on.right_inv_on_of_left_inv_on (hf : inj_on f s) (hf' : left_inv_on f f' t) (h₁ : maps_to f s t) (h₂ : maps_to f' t s) : right_inv_on f f' s := λ x h, hf (h₂ $ h₁ h) h (hf' (h₁ h)) theorem eq_on_of_left_inv_on_of_right_inv_on (h₁ : left_inv_on f₁' f s) (h₂ : right_inv_on f₂' f t) (h : maps_to f₂' t s) : eq_on f₁' f₂' t := λ y hy, calc f₁' y = (f₁' ∘ f ∘ f₂') y : congr_arg f₁' (h₂ hy).symm ... = f₂' y : h₁ (h hy) theorem surj_on.left_inv_on_of_right_inv_on (hf : surj_on f s t) (hf' : right_inv_on f f' s) : left_inv_on f f' t := λ y hy, let ⟨x, hx, heq⟩ := hf hy in by rw [← heq, hf' hx] /-! ### Two-side inverses -/ /-- `g` is an inverse to `f` viewed as a map from `a` to `b` -/ @[reducible] def inv_on (g : β → α) (f : α → β) (s : set α) (t : set β) : Prop := left_inv_on g f s ∧ right_inv_on g f t lemma inv_on.symm (h : inv_on f' f s t) : inv_on f f' t s := ⟨h.right, h.left⟩ lemma inv_on.mono (h : inv_on f' f s t) (hs : s₁ ⊆ s) (ht : t₁ ⊆ t) : inv_on f' f s₁ t₁ := ⟨h.1.mono hs, h.2.mono ht⟩ /-- If functions `f'` and `f` are inverse on `s` and `t`, `f` maps `s` into `t`, and `f'` maps `t` into `s`, then `f` is a bijection between `s` and `t`. The `maps_to` arguments can be deduced from `surj_on` statements using `left_inv_on.maps_to` and `right_inv_on.maps_to`. -/ theorem inv_on.bij_on (h : inv_on f' f s t) (hf : maps_to f s t) (hf' : maps_to f' t s) : bij_on f s t := ⟨hf, h.left.inj_on, h.right.surj_on hf'⟩ /-! ### `inv_fun_on` is a left/right inverse -/ theorem inj_on.left_inv_on_inv_fun_on [nonempty α] (h : inj_on f s) : left_inv_on (inv_fun_on f s) f s := λ x hx, inv_fun_on_eq' h hx lemma inj_on.inv_fun_on_image [nonempty α] (h : inj_on f s₂) (ht : s₁ ⊆ s₂) : (inv_fun_on f s₂) '' (f '' s₁) = s₁ := h.left_inv_on_inv_fun_on.image_image' ht theorem surj_on.right_inv_on_inv_fun_on [nonempty α] (h : surj_on f s t) : right_inv_on (inv_fun_on f s) f t := λ y hy, inv_fun_on_eq $ mem_image_iff_bex.1 $ h hy theorem bij_on.inv_on_inv_fun_on [nonempty α] (h : bij_on f s t) : inv_on (inv_fun_on f s) f s t := ⟨h.inj_on.left_inv_on_inv_fun_on, h.surj_on.right_inv_on_inv_fun_on⟩ theorem surj_on.inv_on_inv_fun_on [nonempty α] (h : surj_on f s t) : inv_on (inv_fun_on f s) f (inv_fun_on f s '' t) t := begin refine ⟨_, h.right_inv_on_inv_fun_on⟩, rintros _ ⟨y, hy, rfl⟩, rw [h.right_inv_on_inv_fun_on hy] end theorem surj_on.maps_to_inv_fun_on [nonempty α] (h : surj_on f s t) : maps_to (inv_fun_on f s) t s := λ y hy, mem_preimage.2 $ inv_fun_on_mem $ mem_image_iff_bex.1 $ h hy theorem surj_on.bij_on_subset [nonempty α] (h : surj_on f s t) : bij_on f (inv_fun_on f s '' t) t := begin refine h.inv_on_inv_fun_on.bij_on _ (maps_to_image _ _), rintros _ ⟨y, hy, rfl⟩, rwa [h.right_inv_on_inv_fun_on hy] end theorem surj_on_iff_exists_bij_on_subset : surj_on f s t ↔ ∃ s' ⊆ s, bij_on f s' t := begin split, { rcases eq_empty_or_nonempty t with rfl|ht, { exact λ _, ⟨∅, empty_subset _, bij_on_empty f⟩ }, { assume h, haveI : nonempty α := ⟨classical.some (h.comap_nonempty ht)⟩, exact ⟨_, h.maps_to_inv_fun_on.image_subset, h.bij_on_subset⟩ }}, { rintros ⟨s', hs', hfs'⟩, exact hfs'.surj_on.mono hs' (subset.refl _) } end lemma preimage_inv_fun_of_mem [n : nonempty α] {f : α → β} (hf : injective f) {s : set α} (h : classical.choice n ∈ s) : inv_fun f ⁻¹' s = f '' s ∪ (range f)ᶜ := begin ext x, rcases em (x ∈ range f) with ⟨a, rfl⟩|hx, { simp [left_inverse_inv_fun hf _, hf.mem_set_image] }, { simp [mem_preimage, inv_fun_neg hx, h, hx] } end lemma preimage_inv_fun_of_not_mem [n : nonempty α] {f : α → β} (hf : injective f) {s : set α} (h : classical.choice n ∉ s) : inv_fun f ⁻¹' s = f '' s := begin ext x, rcases em (x ∈ range f) with ⟨a, rfl⟩|hx, { rw [mem_preimage, left_inverse_inv_fun hf, hf.mem_set_image] }, { have : x ∉ f '' s, from λ h', hx (image_subset_range _ _ h'), simp only [mem_preimage, inv_fun_neg hx, h, this] }, end end set /-! ### Monotone -/ namespace monotone variables [preorder α] [preorder β] {f : α → β} protected lemma restrict (h : monotone f) (s : set α) : monotone (s.restrict f) := λ x y hxy, h hxy protected lemma cod_restrict (h : monotone f) {s : set β} (hs : ∀ x, f x ∈ s) : monotone (s.cod_restrict f hs) := h protected lemma range_factorization (h : monotone f) : monotone (set.range_factorization f) := h end monotone /-! ### Piecewise defined function -/ namespace set variables {δ : α → Sort y} (s : set α) (f g : Πi, δ i) @[simp] lemma piecewise_empty [∀i : α, decidable (i ∈ (∅ : set α))] : piecewise ∅ f g = g := by { ext i, simp [piecewise] } @[simp] lemma piecewise_univ [∀i : α, decidable (i ∈ (set.univ : set α))] : piecewise set.univ f g = f := by { ext i, simp [piecewise] } @[simp] lemma piecewise_insert_self {j : α} [∀i, decidable (i ∈ insert j s)] : (insert j s).piecewise f g j = f j := by simp [piecewise] variable [∀j, decidable (j ∈ s)] instance compl.decidable_mem (j : α) : decidable (j ∈ sᶜ) := not.decidable lemma piecewise_insert [decidable_eq α] (j : α) [∀i, decidable (i ∈ insert j s)] : (insert j s).piecewise f g = function.update (s.piecewise f g) j (f j) := begin simp [piecewise], ext i, by_cases h : i = j, { rw h, simp }, { by_cases h' : i ∈ s; simp [h, h'] } end @[simp, priority 990] lemma piecewise_eq_of_mem {i : α} (hi : i ∈ s) : s.piecewise f g i = f i := if_pos hi @[simp, priority 990] lemma piecewise_eq_of_not_mem {i : α} (hi : i ∉ s) : s.piecewise f g i = g i := if_neg hi lemma piecewise_singleton (x : α) [Π y, decidable (y ∈ ({x} : set α))] [decidable_eq α] (f g : α → β) : piecewise {x} f g = function.update g x (f x) := by { ext y, by_cases hy : y = x, { subst y, simp }, { simp [hy] } } lemma piecewise_eq_on (f g : α → β) : eq_on (s.piecewise f g) f s := λ _, piecewise_eq_of_mem _ _ _ lemma piecewise_eq_on_compl (f g : α → β) : eq_on (s.piecewise f g) g sᶜ := λ _, piecewise_eq_of_not_mem _ _ _ lemma piecewise_le {δ : α → Type*} [Π i, preorder (δ i)] {s : set α} [Π j, decidable (j ∈ s)] {f₁ f₂ g : Π i, δ i} (h₁ : ∀ i ∈ s, f₁ i ≤ g i) (h₂ : ∀ i ∉ s, f₂ i ≤ g i) : s.piecewise f₁ f₂ ≤ g := λ i, if h : i ∈ s then by simp * else by simp * lemma le_piecewise {δ : α → Type*} [Π i, preorder (δ i)] {s : set α} [Π j, decidable (j ∈ s)] {f₁ f₂ g : Π i, δ i} (h₁ : ∀ i ∈ s, g i ≤ f₁ i) (h₂ : ∀ i ∉ s, g i ≤ f₂ i) : g ≤ s.piecewise f₁ f₂ := @piecewise_le α (λ i, order_dual (δ i)) _ s _ _ _ _ h₁ h₂ lemma piecewise_le_piecewise {δ : α → Type*} [Π i, preorder (δ i)] {s : set α} [Π j, decidable (j ∈ s)] {f₁ f₂ g₁ g₂ : Π i, δ i} (h₁ : ∀ i ∈ s, f₁ i ≤ g₁ i) (h₂ : ∀ i ∉ s, f₂ i ≤ g₂ i) : s.piecewise f₁ f₂ ≤ s.piecewise g₁ g₂ := by apply piecewise_le; intros; simp * @[simp, priority 990] lemma piecewise_insert_of_ne {i j : α} (h : i ≠ j) [∀i, decidable (i ∈ insert j s)] : (insert j s).piecewise f g i = s.piecewise f g i := by simp [piecewise, h] @[simp] lemma piecewise_compl [∀ i, decidable (i ∈ sᶜ)] : sᶜ.piecewise f g = s.piecewise g f := funext $ λ x, if hx : x ∈ s then by simp [hx] else by simp [hx] @[simp] lemma piecewise_range_comp {ι : Sort*} (f : ι → α) [Π j, decidable (j ∈ range f)] (g₁ g₂ : α → β) : (range f).piecewise g₁ g₂ ∘ f = g₁ ∘ f := comp_eq_of_eq_on_range $ piecewise_eq_on _ _ _ theorem maps_to.piecewise_ite {s s₁ s₂ : set α} {t t₁ t₂ : set β} {f₁ f₂ : α → β} [∀ i, decidable (i ∈ s)] (h₁ : maps_to f₁ (s₁ ∩ s) (t₁ ∩ t)) (h₂ : maps_to f₂ (s₂ ∩ sᶜ) (t₂ ∩ tᶜ)) : maps_to (s.piecewise f₁ f₂) (s.ite s₁ s₂) (t.ite t₁ t₂) := begin refine (h₁.congr _).union_union (h₂.congr _), exacts [(piecewise_eq_on s f₁ f₂).symm.mono (inter_subset_right _ _), (piecewise_eq_on_compl s f₁ f₂).symm.mono (inter_subset_right _ _)] end theorem eq_on_piecewise {f f' g : α → β} {t} : eq_on (s.piecewise f f') g t ↔ eq_on f g (t ∩ s) ∧ eq_on f' g (t ∩ sᶜ) := begin simp only [eq_on, ← forall_and_distrib], refine forall_congr (λ a, _), by_cases a ∈ s; simp * end theorem eq_on.piecewise_ite' {f f' g : α → β} {t t'} (h : eq_on f g (t ∩ s)) (h' : eq_on f' g (t' ∩ sᶜ)) : eq_on (s.piecewise f f') g (s.ite t t') := by simp [eq_on_piecewise, *] theorem eq_on.piecewise_ite {f f' g : α → β} {t t'} (h : eq_on f g t) (h' : eq_on f' g t') : eq_on (s.piecewise f f') g (s.ite t t') := (h.mono (inter_subset_left _ _)).piecewise_ite' s (h'.mono (inter_subset_left _ _)) lemma piecewise_preimage (f g : α → β) (t) : s.piecewise f g ⁻¹' t = s.ite (f ⁻¹' t) (g ⁻¹' t) := ext $ λ x, by by_cases x ∈ s; simp [*, set.ite] lemma apply_piecewise {δ' : α → Sort*} (h : Π i, δ i → δ' i) {x : α} : h x (s.piecewise f g x) = s.piecewise (λ x, h x (f x)) (λ x, h x (g x)) x := by by_cases hx : x ∈ s; simp [hx] lemma apply_piecewise₂ {δ' δ'' : α → Sort*} (f' g' : Π i, δ' i) (h : Π i, δ i → δ' i → δ'' i) {x : α} : h x (s.piecewise f g x) (s.piecewise f' g' x) = s.piecewise (λ x, h x (f x) (f' x)) (λ x, h x (g x) (g' x)) x := by by_cases hx : x ∈ s; simp [hx] lemma piecewise_op {δ' : α → Sort*} (h : Π i, δ i → δ' i) : s.piecewise (λ x, h x (f x)) (λ x, h x (g x)) = λ x, h x (s.piecewise f g x) := funext $ λ x, (apply_piecewise _ _ _ _).symm lemma piecewise_op₂ {δ' δ'' : α → Sort*} (f' g' : Π i, δ' i) (h : Π i, δ i → δ' i → δ'' i) : s.piecewise (λ x, h x (f x) (f' x)) (λ x, h x (g x) (g' x)) = λ x, h x (s.piecewise f g x) (s.piecewise f' g' x) := funext $ λ x, (apply_piecewise₂ _ _ _ _ _ _).symm @[simp] lemma piecewise_same : s.piecewise f f = f := by { ext x, by_cases hx : x ∈ s; simp [hx] } lemma range_piecewise (f g : α → β) : range (s.piecewise f g) = f '' s ∪ g '' sᶜ := begin ext y, split, { rintro ⟨x, rfl⟩, by_cases h : x ∈ s;[left, right]; use x; simp [h] }, { rintro (⟨x, hx, rfl⟩|⟨x, hx, rfl⟩); use x; simp * at * } end lemma piecewise_mem_pi {δ : α → Type*} {t : set α} {t' : Π i, set (δ i)} {f g} (hf : f ∈ pi t t') (hg : g ∈ pi t t') : s.piecewise f g ∈ pi t t' := by { intros i ht, by_cases hs : i ∈ s; simp [hf i ht, hg i ht, hs] } @[simp] lemma pi_piecewise {ι : Type*} {α : ι → Type*} (s s' : set ι) (t t' : Π i, set (α i)) [Π x, decidable (x ∈ s')] : pi s (s'.piecewise t t') = pi (s ∩ s') t ∩ pi (s \ s') t' := begin ext x, simp only [mem_pi, mem_inter_eq, ← forall_and_distrib], refine forall_congr (λ i, _), by_cases hi : i ∈ s'; simp * end lemma univ_pi_piecewise {ι : Type*} {α : ι → Type*} (s : set ι) (t : Π i, set (α i)) [Π x, decidable (x ∈ s)] : pi univ (s.piecewise t (λ _, univ)) = pi s t := by simp end set lemma strict_mono_incr_on.inj_on [linear_order α] [preorder β] {f : α → β} {s : set α} (H : strict_mono_incr_on f s) : s.inj_on f := λ x hx y hy hxy, show ordering.eq.compares x y, from (H.compares hx hy).1 hxy lemma strict_mono_decr_on.inj_on [linear_order α] [preorder β] {f : α → β} {s : set α} (H : strict_mono_decr_on f s) : s.inj_on f := @strict_mono_incr_on.inj_on α (order_dual β) _ _ f s H lemma strict_mono_incr_on.comp [preorder α] [preorder β] [preorder γ] {g : β → γ} {f : α → β} {s : set α} {t : set β} (hg : strict_mono_incr_on g t) (hf : strict_mono_incr_on f s) (hs : set.maps_to f s t) : strict_mono_incr_on (g ∘ f) s := λ x hx y hy hxy, hg (hs hx) (hs hy) $ hf hx hy hxy lemma strict_mono.comp_strict_mono_incr_on [preorder α] [preorder β] [preorder γ] {g : β → γ} {f : α → β} {s : set α} (hg : strict_mono g) (hf : strict_mono_incr_on f s) : strict_mono_incr_on (g ∘ f) s := λ x hx y hy hxy, hg $ hf hx hy hxy lemma strict_mono.cod_restrict [preorder α] [preorder β] {f : α → β} (hf : strict_mono f) {s : set β} (hs : ∀ x, f x ∈ s) : strict_mono (set.cod_restrict f s hs) := hf namespace function open set variables {fa : α → α} {fb : β → β} {f : α → β} {g : β → γ} {s t : set α} lemma injective.comp_inj_on (hg : injective g) (hf : s.inj_on f) : s.inj_on (g ∘ f) := (hg.inj_on univ).comp hf (maps_to_univ _ _) lemma surjective.surj_on (hf : surjective f) (s : set β) : surj_on f univ s := (surjective_iff_surj_on_univ.1 hf).mono (subset.refl _) (subset_univ _) lemma left_inverse.left_inv_on {g : β → α} (h : left_inverse f g) (s : set β) : left_inv_on f g s := λ x hx, h x lemma right_inverse.right_inv_on {g : β → α} (h : right_inverse f g) (s : set α) : right_inv_on f g s := λ x hx, h x lemma left_inverse.right_inv_on_range {g : β → α} (h : left_inverse f g) : right_inv_on f g (range g) := forall_range_iff.2 $ λ i, congr_arg g (h i) namespace semiconj lemma maps_to_image (h : semiconj f fa fb) (ha : maps_to fa s t) : maps_to fb (f '' s) (f '' t) := λ y ⟨x, hx, hy⟩, hy ▸ ⟨fa x, ha hx, h x⟩ lemma maps_to_range (h : semiconj f fa fb) : maps_to fb (range f) (range f) := λ y ⟨x, hy⟩, hy ▸ ⟨fa x, h x⟩ lemma surj_on_image (h : semiconj f fa fb) (ha : surj_on fa s t) : surj_on fb (f '' s) (f '' t) := begin rintros y ⟨x, hxt, rfl⟩, rcases ha hxt with ⟨x, hxs, rfl⟩, rw [h x], exact mem_image_of_mem _ (mem_image_of_mem _ hxs) end lemma surj_on_range (h : semiconj f fa fb) (ha : surjective fa) : surj_on fb (range f) (range f) := by { rw ← image_univ, exact h.surj_on_image (ha.surj_on univ) } lemma inj_on_image (h : semiconj f fa fb) (ha : inj_on fa s) (hf : inj_on f (fa '' s)) : inj_on fb (f '' s) := begin rintros _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ H, simp only [← h.eq] at H, exact congr_arg f (ha hx hy $ hf (mem_image_of_mem fa hx) (mem_image_of_mem fa hy) H) end lemma inj_on_range (h : semiconj f fa fb) (ha : injective fa) (hf : inj_on f (range fa)) : inj_on fb (range f) := by { rw ← image_univ at *, exact h.inj_on_image (ha.inj_on univ) hf } lemma bij_on_image (h : semiconj f fa fb) (ha : bij_on fa s t) (hf : inj_on f t) : bij_on fb (f '' s) (f '' t) := ⟨h.maps_to_image ha.maps_to, h.inj_on_image ha.inj_on (ha.image_eq.symm ▸ hf), h.surj_on_image ha.surj_on⟩ lemma bij_on_range (h : semiconj f fa fb) (ha : bijective fa) (hf : injective f) : bij_on fb (range f) (range f) := begin rw [← image_univ], exact h.bij_on_image (bijective_iff_bij_on_univ.1 ha) (hf.inj_on univ) end lemma maps_to_preimage (h : semiconj f fa fb) {s t : set β} (hb : maps_to fb s t) : maps_to fa (f ⁻¹' s) (f ⁻¹' t) := λ x hx, by simp only [mem_preimage, h x, hb hx] lemma inj_on_preimage (h : semiconj f fa fb) {s : set β} (hb : inj_on fb s) (hf : inj_on f (f ⁻¹' s)) : inj_on fa (f ⁻¹' s) := begin intros x hx y hy H, have := congr_arg f H, rw [h.eq, h.eq] at this, exact hf hx hy (hb hx hy this) end end semiconj lemma update_comp_eq_of_not_mem_range' {α β : Sort*} {γ : β → Sort*} [decidable_eq β] (g : Π b, γ b) {f : α → β} {i : β} (a : γ i) (h : i ∉ set.range f) : (λ j, (function.update g i a) (f j)) = (λ j, g (f j)) := update_comp_eq_of_forall_ne' _ _ $ λ x hx, h ⟨x, hx⟩ /-- Non-dependent version of `function.update_comp_eq_of_not_mem_range'` -/ lemma update_comp_eq_of_not_mem_range {α β γ : Sort*} [decidable_eq β] (g : β → γ) {f : α → β} {i : β} (a : γ) (h : i ∉ set.range f) : (function.update g i a) ∘ f = g ∘ f := update_comp_eq_of_not_mem_range' g a h end function
367ec53d122d268d02622dd67a708be8cd8ccf05
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/analysis/normed_space/quaternion_exponential.lean
a92e0d96e7dd70d55a33b3fdde477b34e6f22e78
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
5,520
lean
/- Copyright (c) 2023 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import analysis.quaternion import analysis.normed_space.exponential import analysis.special_functions.trigonometric.series /-! # Lemmas about `exp` on `quaternion`s > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file contains results about `exp` on `quaternion ℝ`. ## Main results * `quaternion.exp_eq`: the general expansion of the quaternion exponential in terms of `real.cos` and `real.sin`. * `quaternion.exp_of_re_eq_zero`: the special case when the quaternion has a zero real part. * `quaternion.norm_exp`: the norm of the quaternion exponential is the norm of the exponential of the real part. -/ open_locale quaternion nat namespace quaternion @[simp, norm_cast] lemma exp_coe (r : ℝ) : exp ℝ (r : ℍ[ℝ]) = ↑(exp ℝ r) := (map_exp ℝ (algebra_map ℝ ℍ[ℝ]) (continuous_algebra_map _ _) _).symm /-- Auxiliary result; if the power series corresponding to `real.cos` and `real.sin` evaluated at `‖q‖` tend to `c` and `s`, then the exponential series tends to `c + (s / ‖q‖)`. -/ lemma has_sum_exp_series_of_imaginary {q : quaternion ℝ} (hq : q.re = 0) {c s : ℝ} (hc : has_sum (λ n, (-1)^n * ‖q‖^(2 * n) / (2 * n)!) c) (hs : has_sum (λ n, (-1)^n * ‖q‖^(2 * n + 1) / (2 * n + 1)!) s) : has_sum (λ n, exp_series ℝ _ n (λ _, q)) (↑c + (s / ‖q‖) • q) := begin replace hc := has_sum_coe.mpr hc, replace hs := (hs.div_const ‖q‖).smul_const q, obtain rfl | hq0 := eq_or_ne q 0, { simp_rw [exp_series_apply_zero, norm_zero, div_zero, zero_smul, add_zero], simp_rw [norm_zero] at hc, convert hc, ext (_ | n) : 1, { rw [pow_zero, mul_zero, pow_zero, nat.factorial_zero, nat.cast_one, div_one, one_mul, pi.single_eq_same, coe_one], }, { rw [zero_pow (mul_pos two_pos (nat.succ_pos _)), mul_zero, zero_div, pi.single_eq_of_ne (n.succ_ne_zero), coe_zero], } }, simp_rw exp_series_apply_eq, have hq2 : q^2 = -norm_sq q := sq_eq_neg_norm_sq.mpr hq, have hqn := norm_ne_zero_iff.mpr hq0, refine has_sum.even_add_odd _ _, { convert hc using 1, ext n : 1, let k : ℝ := ↑(2 * n)!, calc k⁻¹ • q ^ (2 * n) = k⁻¹ • ((-norm_sq q) ^ n) : by rw [pow_mul, hq2] ... = k⁻¹ • ↑((-1) ^ n * ‖q‖ ^ (2 * n)) : _ ... = ↑((-1) ^ n * ‖q‖ ^ (2 * n) / k) : _, { congr' 1, rw [neg_pow, norm_sq_eq_norm_sq, pow_mul, sq], push_cast }, { rw [←coe_mul_eq_smul, div_eq_mul_inv], norm_cast, ring_nf } }, { convert hs using 1, ext n : 1, let k : ℝ := ↑(2 * n + 1)!, calc k⁻¹ • q ^ (2 * n + 1) = k⁻¹ • ((-norm_sq q) ^ n * q) : by rw [pow_succ', pow_mul, hq2] ... = k⁻¹ • ((-1) ^ n * ‖q‖ ^ (2 * n)) • q : _ ... = ((-1) ^ n * ‖q‖ ^ (2 * n + 1) / k / ‖q‖) • q : _, { congr' 1, rw [neg_pow, norm_sq_eq_norm_sq, pow_mul, sq, ←coe_mul_eq_smul], push_cast }, { rw smul_smul, congr' 1, simp_rw [pow_succ', mul_div_assoc, div_div_cancel_left' hqn], ring } }, end /-- The closed form for the quaternion exponential on imaginary quaternions. -/ lemma exp_of_re_eq_zero (q : quaternion ℝ) (hq : q.re = 0) : exp ℝ q = ↑(real.cos ‖q‖) + (real.sin ‖q‖ / ‖q‖) • q := begin rw [exp_eq_tsum], refine has_sum.tsum_eq _, simp_rw ← exp_series_apply_eq, exact has_sum_exp_series_of_imaginary hq (real.has_sum_cos _) (real.has_sum_sin _), end /-- The closed form for the quaternion exponential on arbitrary quaternions. -/ lemma exp_eq (q : quaternion ℝ) : exp ℝ q = exp ℝ q.re • (↑(real.cos ‖q.im‖) + (real.sin ‖q.im‖ / ‖q.im‖) • q.im) := begin rw [←exp_of_re_eq_zero q.im q.im_re, ←coe_mul_eq_smul, ←exp_coe, ←exp_add_of_commute, re_add_im], exact algebra.commutes q.re (_ : ℍ[ℝ]), end lemma re_exp (q : ℍ[ℝ]) : (exp ℝ q).re = exp ℝ q.re * (real.cos ‖q - q.re‖) := by simp [exp_eq] lemma im_exp (q : ℍ[ℝ]) : (exp ℝ q).im = (exp ℝ q.re * (real.sin ‖q.im‖ / ‖q.im‖)) • q.im := by simp [exp_eq, smul_smul] lemma norm_sq_exp (q : ℍ[ℝ]) : norm_sq (exp ℝ q) = (exp ℝ q.re)^2 := calc norm_sq (exp ℝ q) = norm_sq (exp ℝ q.re • (↑(real.cos ‖q.im‖) + (real.sin ‖q.im‖ / ‖q.im‖) • q.im)) : by rw exp_eq ... = (exp ℝ q.re)^2 * norm_sq ((↑(real.cos ‖q.im‖) + (real.sin ‖q.im‖ / ‖q.im‖) • q.im)) : by rw [norm_sq_smul] ... = (exp ℝ q.re)^2 * ((real.cos ‖q.im‖) ^ 2 + (real.sin ‖q.im‖)^2) : begin congr' 1, obtain hv | hv := eq_or_ne (‖q.im‖) 0, { simp [hv] }, rw [norm_sq_add, norm_sq_smul, star_smul, coe_mul_eq_smul, smul_re, smul_re, star_re, im_re, smul_zero, smul_zero, mul_zero, add_zero, div_pow, norm_sq_coe, norm_sq_eq_norm_sq, ←sq, div_mul_cancel _ (pow_ne_zero _ hv)], end ... = (exp ℝ q.re)^2 : by rw [real.cos_sq_add_sin_sq, mul_one] /-- Note that this implies that exponentials of pure imaginary quaternions are unit quaternions since in that case the RHS is `1` via `exp_zero` and `norm_one`. -/ @[simp] lemma norm_exp (q : ℍ[ℝ]) : ‖exp ℝ q‖ = ‖exp ℝ q.re‖ := by rw [norm_eq_sqrt_real_inner (exp ℝ q), inner_self, norm_sq_exp, real.sqrt_sq_eq_abs, real.norm_eq_abs] end quaternion
1e24e47ee0f7347e181d7c36ea683f3912b27d76
6f1049e897f569e5c47237de40321e62f0181948
/src/exercises/07bis_abstract_negations.lean
afb2e2742a27843446c7c89219e82bd603f91a6d
[ "Apache-2.0" ]
permissive
anrddh/tutorials
f654a0807b9523608544836d9a81939f8e1dceb8
3ba43804e7b632201c494cdaa8da5406f1a255f9
refs/heads/master
1,655,542,921,827
1,588,846,595,000
1,588,846,595,000
262,330,134
0
0
null
1,588,944,346,000
1,588,944,345,000
null
UTF-8
Lean
false
false
1,212
lean
import data.real.basic open_locale classical /- Theoretical negations. This file is for people interested in logic who want to fully understand negations. Here we don't use contrapose or push_neg. The goal is to prove lemmas that are used by those tactics. Of course we can use exfalso, by_contradiction et by_cases. If this doesn't sound like fun then skip ahead to the next file. -/ section negation_prop variables P Q : Prop -- 0055 example : (P → Q) ↔ (¬ Q → ¬ P) := begin sorry end -- 0056 lemma non_imp (P Q : Prop) : ¬ (P → Q) ↔ P ∧ ¬ Q := begin sorry end -- In the one, let's use the axiom -- propext {P Q : Prop} : (P ↔ Q) → P = Q -- 0057 example (P : Prop) : ¬ P ↔ P = false := begin sorry end end negation_prop section negation_quantifiers variables (X : Type) (P : X → Prop) -- 0058 example : ¬ (∀ x, P x) ↔ ∃ x, ¬ P x := begin sorry end -- 0059 example : ¬ (∃ x, P x) ↔ ∀ x, ¬ P x := begin sorry end -- 0060 example (P : ℝ → Prop) : ¬ (∃ ε > 0, P ε) ↔ ∀ ε > 0, ¬ P ε := begin sorry end -- 0061 example (P : ℝ → Prop) : ¬ (∀ x > 0, P x) ↔ ∃ x > 0, ¬ P x := begin sorry end end negation_quantifiers
c226c6707e80dc32a1588def1e32867a19c78018
ff5230333a701471f46c57e8c115a073ebaaa448
/tests/lean/inaccessible2.lean
1dcb8c4decd266bd104b30188bf65d2555dae1ba
[ "Apache-2.0" ]
permissive
stanford-cs242/lean
f81721d2b5d00bc175f2e58c57b710d465e6c858
7bd861261f4a37326dcf8d7a17f1f1f330e4548c
refs/heads/master
1,600,957,431,849
1,576,465,093,000
1,576,465,093,000
225,779,423
0
3
Apache-2.0
1,575,433,936,000
1,575,433,935,000
null
UTF-8
Lean
false
false
898
lean
inductive imf {A B : Sort*} (f : A → B) : B → Sort* | mk : ∀ (a : A), imf (f a) definition inv_1 {A B : Sort*} (f : A → B) : ∀ (b : B), imf f b → A | .(f .(a)) (imf.mk .(f) a) := a -- Error inaccessible annotation inside inaccessible annotation definition inv_2 {A B : Sort*} (f : A → B) : ∀ (b : B), imf f b → A | .(f a) (let x := (imf.mk .(f) a) in x) := a -- Error invalid occurrence of 'let' expression definition inv_3 {A B : Sort*} (f : A → B) : ∀ (b : B), imf f b → A | .(f a) ((λ (x : imf f b), x) (imf.mk .(f) a)) := a -- Error invalid occurrence of 'lambda' expression definition sym {A : Sort*} : ∀ a b : A, a = b → b = a | .(a) .(a) (eq.refl a) := rfl -- Error `a` in eq.refl must be marked as inaccessible since it is an inductive datatype parameter definition symm2 {A : Sort*} : ∀ a b : A, a = b → b = a | _ _ rfl := rfl -- correct version
f3a06be277cc3079de7052afa2d7ffbafada09eb
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/category_theory/limits/constructions/equalizers.lean
7cc0d326d6694a3bcf347f3626be0127888aec4c
[ "Apache-2.0" ]
permissive
jjgarzella/mathlib
96a345378c4e0bf26cf604aed84f90329e4896a2
395d8716c3ad03747059d482090e2bb97db612c8
refs/heads/master
1,686,480,124,379
1,625,163,323,000
1,625,163,323,000
281,190,421
2
0
Apache-2.0
1,595,268,170,000
1,595,268,169,000
null
UTF-8
Lean
false
false
2,706
lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import category_theory.limits.shapes.equalizers import category_theory.limits.shapes.binary_products import category_theory.limits.shapes.pullbacks /-! # Constructing equalizers from pullbacks and binary products. If a category has pullbacks and binary products, then it has equalizers. TODO: provide the dual result. -/ noncomputable theory universes v u open category_theory category_theory.category namespace category_theory.limits variables {C : Type u} [category.{v} C] [has_binary_products C] [has_pullbacks C] -- We hide the "implementation details" inside a namespace namespace has_equalizers_of_pullbacks_and_binary_products /-- Define the equalizing object -/ @[reducible] def construct_equalizer (F : walking_parallel_pair ⥤ C) : C := pullback (prod.lift (𝟙 _) (F.map walking_parallel_pair_hom.left)) (prod.lift (𝟙 _) (F.map walking_parallel_pair_hom.right)) /-- Define the equalizing morphism -/ abbreviation pullback_fst (F : walking_parallel_pair ⥤ C) : construct_equalizer F ⟶ F.obj walking_parallel_pair.zero := pullback.fst lemma pullback_fst_eq_pullback_snd (F : walking_parallel_pair ⥤ C) : pullback_fst F = pullback.snd := by convert pullback.condition =≫ limits.prod.fst; simp /-- Define the equalizing cone -/ @[reducible] def equalizer_cone (F : walking_parallel_pair ⥤ C) : cone F := cone.of_fork (fork.of_ι (pullback_fst F) (begin conv_rhs { rw pullback_fst_eq_pullback_snd, }, convert pullback.condition =≫ limits.prod.snd using 1; simp end)) /-- Show the equalizing cone is a limit -/ def equalizer_cone_is_limit (F : walking_parallel_pair ⥤ C) : is_limit (equalizer_cone F) := { lift := begin intro c, apply pullback.lift (c.π.app _) (c.π.app _), apply limit.hom_ext, rintro (_ | _); simp end, fac' := by rintros c (_ | _); simp, uniq' := begin intros c _ J, have J0 := J walking_parallel_pair.zero, simp at J0, apply pullback.hom_ext, { rwa limit.lift_π }, { erw [limit.lift_π, ← J0, pullback_fst_eq_pullback_snd] } end } end has_equalizers_of_pullbacks_and_binary_products open has_equalizers_of_pullbacks_and_binary_products /-- Any category with pullbacks and binary products, has equalizers. -/ -- This is not an instance, as it is not always how one wants to construct equalizers! lemma has_equalizers_of_pullbacks_and_binary_products : has_equalizers C := { has_limit := λ F, has_limit.mk { cone := equalizer_cone F, is_limit := equalizer_cone_is_limit F } } end category_theory.limits
a45bde0d07502a6a9b66ac5db144b8d925f68edc
75db7e3219bba2fbf41bf5b905f34fcb3c6ca3f2
/tests/lean/run/tactic21.lean
c4f94cd49e657c3333afd01e012296d55d919e95
[ "Apache-2.0" ]
permissive
jroesch/lean
30ef0860fa905d35b9ad6f76de1a4f65c9af6871
3de4ec1a6ce9a960feb2a48eeea8b53246fa34f2
refs/heads/master
1,586,090,835,348
1,455,142,203,000
1,455,142,277,000
51,536,958
1
0
null
1,455,215,811,000
1,455,215,811,000
null
UTF-8
Lean
false
false
468
lean
import logic open tactic theorem tst1 {A : Type} {a b c : A} {p : A → A → Prop} (H1 : p a b) (H2 : p b c) : ∃ x, p a x ∧ p x c := by apply exists.intro; apply and.intro; eassumption; eassumption theorem tst2 {A : Type} {a b c d : A} {p : A → A → Prop} (Ha : p a c) (H1 : p a b) (Hb : p b d) (H2 : p b c) : ∃ x, p a x ∧ p x c := by apply exists.intro; apply and.intro; eassumption; eassumption reveal tst2 (* print(get_env():find("tst2"):value()) *)
6a911102a0bdb7f6dce44e4045d39f5b11a12f9f
bf532e3e865883a676110e756f800e0ddeb465be
/algebra/group.lean
42b8dff7518445ad23d154375ae10063e0ce6001
[ "Apache-2.0" ]
permissive
aqjune/mathlib
da42a97d9e6670d2efaa7d2aa53ed3585dafc289
f7977ff5a6bcf7e5c54eec908364ceb40dafc795
refs/heads/master
1,631,213,225,595
1,521,089,840,000
1,521,089,840,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
17,484
lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura Various multiplicative and additive structures. -/ import tactic.interactive section pending_1857 /- Transport multiplicative to additive -/ section transport open tactic @[user_attribute] meta def to_additive_attr : user_attribute (name_map name) name := { name := `to_additive, descr := "Transport multiplicative to additive", cache_cfg := ⟨λ ns, ns.mfoldl (λ dict n, do val ← to_additive_attr.get_param n, pure $ dict.insert n val) mk_name_map, []⟩, parser := lean.parser.ident, after_set := some $ λ src _ _, do env ← get_env, dict ← to_additive_attr.get_cache, tgt ← to_additive_attr.get_param src, (get_decl tgt >> skip) <|> transport_with_dict dict src tgt } end transport /- map operations -/ attribute [to_additive has_add.add] has_mul.mul attribute [to_additive has_zero.zero] has_one.one attribute [to_additive has_neg.neg] has_inv.inv attribute [to_additive has_add] has_mul attribute [to_additive has_zero] has_one attribute [to_additive has_neg] has_inv /- map constructors -/ attribute [to_additive has_add.mk] has_mul.mk attribute [to_additive has_zero.mk] has_one.mk attribute [to_additive has_neg.mk] has_neg.mk /- map structures -/ attribute [to_additive add_semigroup] semigroup attribute [to_additive add_semigroup.mk] semigroup.mk attribute [to_additive add_semigroup.to_has_add] semigroup.to_has_mul attribute [to_additive add_semigroup.add_assoc] semigroup.mul_assoc attribute [to_additive add_comm_semigroup] comm_semigroup attribute [to_additive add_comm_semigroup.mk] comm_semigroup.mk attribute [to_additive add_comm_semigroup.to_add_semigroup] comm_semigroup.to_semigroup attribute [to_additive add_comm_semigroup.add_comm] comm_semigroup.mul_comm attribute [to_additive add_left_cancel_semigroup] left_cancel_semigroup attribute [to_additive add_left_cancel_semigroup.mk] left_cancel_semigroup.mk attribute [to_additive add_left_cancel_semigroup.to_add_semigroup] left_cancel_semigroup.to_semigroup attribute [to_additive add_left_cancel_semigroup.add_left_cancel] left_cancel_semigroup.mul_left_cancel attribute [to_additive add_right_cancel_semigroup] right_cancel_semigroup attribute [to_additive add_right_cancel_semigroup.mk] right_cancel_semigroup.mk attribute [to_additive add_right_cancel_semigroup.to_add_semigroup] right_cancel_semigroup.to_semigroup attribute [to_additive add_right_cancel_semigroup.add_right_cancel] right_cancel_semigroup.mul_right_cancel attribute [to_additive add_monoid] monoid attribute [to_additive add_monoid.mk] monoid.mk attribute [to_additive add_monoid.to_has_zero] monoid.to_has_one attribute [to_additive add_monoid.to_add_semigroup] monoid.to_semigroup attribute [to_additive add_monoid.zero_add] monoid.one_mul attribute [to_additive add_monoid.add_zero] monoid.mul_one attribute [to_additive add_comm_monoid] comm_monoid attribute [to_additive add_comm_monoid.mk] comm_monoid.mk attribute [to_additive add_comm_monoid.to_add_monoid] comm_monoid.to_monoid attribute [to_additive add_comm_monoid.to_add_comm_semigroup] comm_monoid.to_comm_semigroup attribute [to_additive add_group] group attribute [to_additive add_group.mk] group.mk attribute [to_additive add_group.to_has_neg] group.to_has_inv attribute [to_additive add_group.to_add_monoid] group.to_monoid attribute [to_additive add_group.add_left_neg] group.mul_left_inv attribute [to_additive add_group.add] group.mul attribute [to_additive add_group.add_assoc] group.mul_assoc attribute [to_additive add_comm_group] comm_group attribute [to_additive add_comm_group.mk] comm_group.mk attribute [to_additive add_comm_group.to_add_group] comm_group.to_group attribute [to_additive add_comm_group.to_add_comm_monoid] comm_group.to_comm_monoid /- map theorems -/ attribute [to_additive add_assoc] mul_assoc attribute [to_additive add_semigroup_to_is_associative] semigroup_to_is_associative attribute [to_additive add_comm] mul_comm attribute [to_additive add_comm_semigroup_to_is_commutative] comm_semigroup_to_is_commutative attribute [to_additive add_left_comm] mul_left_comm attribute [to_additive add_right_comm] mul_right_comm attribute [to_additive add_left_cancel] mul_left_cancel attribute [to_additive add_right_cancel] mul_right_cancel attribute [to_additive add_left_cancel_iff] mul_left_cancel_iff attribute [to_additive add_right_cancel_iff] mul_right_cancel_iff attribute [to_additive zero_add] one_mul attribute [to_additive add_zero] mul_one attribute [to_additive add_left_neg] mul_left_inv attribute [to_additive neg_add_self] inv_mul_self attribute [to_additive neg_add_cancel_left] inv_mul_cancel_left attribute [to_additive neg_add_cancel_right] inv_mul_cancel_right attribute [to_additive neg_eq_of_add_eq_zero] inv_eq_of_mul_eq_one attribute [to_additive neg_zero] one_inv attribute [to_additive neg_neg] inv_inv attribute [to_additive add_right_neg] mul_right_inv attribute [to_additive add_neg_self] mul_inv_self attribute [to_additive neg_inj] inv_inj attribute [to_additive add_group.add_left_cancel] group.mul_left_cancel attribute [to_additive add_group.add_right_cancel] group.mul_right_cancel attribute [to_additive add_group.to_left_cancel_add_semigroup] group.to_left_cancel_semigroup attribute [to_additive add_group.to_right_cancel_add_semigroup] group.to_right_cancel_semigroup attribute [to_additive add_neg_cancel_left] mul_inv_cancel_left attribute [to_additive add_neg_cancel_right] mul_inv_cancel_right attribute [to_additive neg_add_rev] mul_inv_rev attribute [to_additive eq_neg_of_eq_neg] eq_inv_of_eq_inv attribute [to_additive eq_neg_of_add_eq_zero] eq_inv_of_mul_eq_one attribute [to_additive eq_add_neg_of_add_eq] eq_mul_inv_of_mul_eq attribute [to_additive eq_neg_add_of_add_eq] eq_inv_mul_of_mul_eq attribute [to_additive neg_add_eq_of_eq_add] inv_mul_eq_of_eq_mul attribute [to_additive add_neg_eq_of_eq_add] mul_inv_eq_of_eq_mul attribute [to_additive eq_add_of_add_neg_eq] eq_mul_of_mul_inv_eq attribute [to_additive eq_add_of_neg_add_eq] eq_mul_of_inv_mul_eq attribute [to_additive add_eq_of_eq_neg_add] mul_eq_of_eq_inv_mul attribute [to_additive add_eq_of_eq_add_neg] mul_eq_of_eq_mul_inv attribute [to_additive neg_add] mul_inv end pending_1857 universe u variables {α : Type u} @[simp, to_additive add_left_inj] theorem mul_left_inj [left_cancel_semigroup α] (a : α) {b c : α} : a * b = a * c ↔ b = c := ⟨mul_left_cancel, congr_arg _⟩ @[simp, to_additive add_right_inj] theorem mul_right_inj [right_cancel_semigroup α] (a : α) {b c : α} : b * a = c * a ↔ b = c := ⟨mul_right_cancel, congr_arg _⟩ structure units (α : Type u) [monoid α] := (val : α) (inv : α) (val_inv : val * inv = 1) (inv_val : inv * val = 1) namespace units variables [monoid α] {a b c : units α} instance : has_coe (units α) α := ⟨val⟩ theorem ext : ∀ {a b : units α}, (a : α) = b → a = b | ⟨v, i₁, vi₁, iv₁⟩ ⟨v', i₂, vi₂, iv₂⟩ e := by change v = v' at e; subst v'; congr; simpa [iv₂, vi₁] using mul_assoc i₂ v i₁ protected def mul : units α → units α → units α | ⟨v₁, i₁, vi₁, iv₁⟩ ⟨v₂, i₂, vi₂, iv₂⟩ := ⟨v₁ * v₂, i₂ * i₁, have v₁ * (v₂ * i₂) * i₁ = 1, by rw [vi₂]; simp [vi₁], by simpa [mul_comm, mul_assoc], have i₂ * (i₁ * v₁) * v₂ = 1, by rw [iv₁]; simp [iv₂], by simpa [mul_comm, mul_assoc]⟩ protected def inv' : units α → units α | ⟨v, i, vi, iv⟩ := ⟨i, v, iv, vi⟩ instance : has_mul (units α) := ⟨units.mul⟩ instance : has_one (units α) := ⟨⟨1, 1, mul_one 1, one_mul 1⟩⟩ instance : has_inv (units α) := ⟨units.inv'⟩ variables (a b) @[simp] lemma mul_coe : (↑(a * b) : α) = a * b := by cases a; cases b; refl @[simp] lemma one_coe : ((1 : units α) : α) = 1 := rfl lemma val_coe : (↑a : α) = a.val := rfl lemma inv_coe : ((a⁻¹ : units α) : α) = a.inv := by cases a; refl @[simp] lemma inv_mul : (↑a⁻¹ * a : α) = 1 := by simp [val_coe, inv_coe, inv_val] @[simp] lemma mul_inv : (a * ↑a⁻¹ : α) = 1 := by simp [val_coe, inv_coe, val_inv] @[simp] lemma mul_inv_cancel_left (a : units α) (b : α) : (a:α) * (↑a⁻¹ * b) = b := by rw [← mul_assoc, mul_inv, one_mul] @[simp] lemma inv_mul_cancel_left (a : units α) (b : α) : (↑a⁻¹:α) * (a * b) = b := by rw [← mul_assoc, inv_mul, one_mul] @[simp] lemma mul_inv_cancel_right (a : α) (b : units α) : a * b * ↑b⁻¹ = a := by rw [mul_assoc, mul_inv, mul_one] @[simp] lemma inv_mul_cancel_right (a : α) (b : units α) : a * ↑b⁻¹ * b = a := by rw [mul_assoc, inv_mul, mul_one] instance : group (units α) := by refine {mul := (*), one := 1, inv := has_inv.inv, ..}; { intros, apply ext, simp [mul_assoc] } @[simp] theorem mul_left_inj (a : units α) {b c : α} : (a:α) * b = a * c ↔ b = c := ⟨λ h, by simpa using congr_arg ((*) ↑(a⁻¹ : units α)) h, congr_arg _⟩ @[simp] theorem mul_right_inj (a : units α) {b c : α} : b * a = c * a ↔ b = c := ⟨λ h, by simpa using congr_arg (* ↑(a⁻¹ : units α)) h, congr_arg _⟩ end units section monoid variables [monoid α] {a b c : α} /-- Partial division. It is defined when the second argument is invertible, and unlike the division operator in `division_ring` it is not totalized at zero. -/ def divp (a : α) (u) : α := a * (u⁻¹ : units α) infix ` /ₚ `:70 := divp @[simp] theorem divp_self (u : units α) : (u : α) /ₚ u = 1 := by simp [divp] @[simp] theorem divp_one (a : α) : a /ₚ 1 = a := by simp [divp] theorem divp_assoc (a b : α) (u : units α) : a * b /ₚ u = a * (b /ₚ u) := by simp [divp, mul_assoc] @[simp] theorem divp_mul_cancel (a : α) (u : units α) : a /ₚ u * u = a := by simp [divp, mul_assoc] @[simp] theorem mul_divp_cancel (a : α) (u : units α) : (a * u) /ₚ u = a := by simp [divp, mul_assoc] @[simp] theorem divp_right_inj (u : units α) {a b : α} : a /ₚ u = b /ₚ u ↔ a = b := units.mul_right_inj _ theorem divp_eq_one (a : α) (u : units α) : a /ₚ u = 1 ↔ a = u := (units.mul_right_inj u).symm.trans $ by simp @[simp] theorem one_divp (u : units α) : 1 /ₚ u = ↑u⁻¹ := by simp [divp] variable α class is_submonoid (S : set α) : Prop := (one_mem : (1:α) ∈ S) (mul_mem : ∀ {s t}, s ∈ S → t ∈ S → s*t ∈ S) end monoid section group variables [group α] {a b c : α} instance : has_lift α (units α) := ⟨λ a, ⟨a, a⁻¹, mul_inv_self _, inv_mul_self _⟩⟩ @[simp, to_additive neg_inj'] theorem inv_inj' : a⁻¹ = b⁻¹ ↔ a = b := ⟨λ h, by rw ← inv_inv a; simp [h], congr_arg _⟩ @[to_additive eq_of_neg_eq_neg] theorem eq_of_inv_eq_inv : a⁻¹ = b⁻¹ → a = b := inv_inj'.1 @[simp, to_additive add_self_iff_eq_zero] theorem mul_self_iff_eq_one : a * a = a ↔ a = 1 := by have := @mul_left_inj _ _ a a 1; rwa mul_one at this @[simp, to_additive neg_eq_zero] theorem inv_eq_one : a⁻¹ = 1 ↔ a = 1 := by rw [← @inv_inj' _ _ a 1, one_inv] @[simp, to_additive neg_ne_zero] theorem inv_ne_one : a⁻¹ ≠ 1 ↔ a ≠ 1 := not_congr inv_eq_one @[to_additive left_inverse_neg] theorem left_inverse_inv (α) [group α] : function.left_inverse (λ a : α, a⁻¹) (λ a, a⁻¹) := assume a, inv_inv a attribute [simp] mul_inv_cancel_left add_neg_cancel_left mul_inv_cancel_right add_neg_cancel_right @[to_additive eq_neg_iff_eq_neg] theorem eq_inv_iff_eq_inv : a = b⁻¹ ↔ b = a⁻¹ := ⟨eq_inv_of_eq_inv, eq_inv_of_eq_inv⟩ @[to_additive neg_eq_iff_neg_eq] theorem inv_eq_iff_inv_eq : a⁻¹ = b ↔ b⁻¹ = a := by rw [eq_comm, @eq_comm _ _ a, eq_inv_iff_eq_inv] @[to_additive add_eq_zero_iff_eq_neg] theorem mul_eq_one_iff_eq_inv : a * b = 1 ↔ a = b⁻¹ := by simpa [mul_left_inv, -mul_right_inj] using @mul_right_inj _ _ b a (b⁻¹) @[to_additive add_eq_zero_iff_neg_eq] theorem mul_eq_one_iff_inv_eq : a * b = 1 ↔ a⁻¹ = b := by rw [mul_eq_one_iff_eq_inv, eq_inv_iff_eq_inv, eq_comm] @[to_additive eq_neg_iff_add_eq_zero] theorem eq_inv_iff_mul_eq_one : a = b⁻¹ ↔ a * b = 1 := mul_eq_one_iff_eq_inv.symm @[to_additive neg_eq_iff_add_eq_zero] theorem inv_eq_iff_mul_eq_one : a⁻¹ = b ↔ a * b = 1 := mul_eq_one_iff_inv_eq.symm @[to_additive eq_add_neg_iff_add_eq] theorem eq_mul_inv_iff_mul_eq : a = b * c⁻¹ ↔ a * c = b := ⟨λ h, by simp [h], λ h, by simp [h.symm]⟩ @[to_additive eq_neg_add_iff_add_eq] theorem eq_inv_mul_iff_mul_eq : a = b⁻¹ * c ↔ b * a = c := ⟨λ h, by simp [h], λ h, by simp [h.symm]⟩ @[to_additive neg_add_eq_iff_eq_add] theorem inv_mul_eq_iff_eq_mul : a⁻¹ * b = c ↔ b = a * c := ⟨λ h, by simp [h.symm], λ h, by simp [h]⟩ @[to_additive add_neg_eq_iff_eq_add] theorem mul_inv_eq_iff_eq_mul : a * b⁻¹ = c ↔ a = c * b := ⟨λ h, by simp [h.symm], λ h, by simp [h]⟩ @[to_additive add_neg_eq_zero] theorem mul_inv_eq_one {a b : α} : a * b⁻¹ = 1 ↔ a = b := by rw [mul_eq_one_iff_eq_inv, inv_inv] @[to_additive neg_comm_of_comm] theorem inv_comm_of_comm {a b : α} (H : a * b = b * a) : a⁻¹ * b = b * a⁻¹ := begin have : a⁻¹ * (b * a) * a⁻¹ = a⁻¹ * (a * b) * a⁻¹ := congr_arg (λ x:α, a⁻¹ * x * a⁻¹) H.symm, rwa [mul_assoc, mul_assoc, mul_inv_self, mul_one, ← mul_assoc, inv_mul_self, one_mul] at this; exact h end end group section add_monoid variables [add_monoid α] {a b c : α} @[simp] lemma bit0_zero : bit0 0 = 0 := add_zero _ @[simp] lemma bit1_zero : bit1 0 = 1 := add_zero _ end add_monoid section add_group variables [add_group α] {a b c : α} local attribute [simp] sub_eq_add_neg def sub_sub_cancel := @sub_sub_self @[simp] lemma sub_left_inj : a - b = a - c ↔ b = c := (add_left_inj _).trans neg_inj' @[simp] lemma sub_right_inj : b - a = c - a ↔ b = c := add_right_inj _ lemma sub_add_sub_cancel (a b c : α) : (a - b) + (b - c) = a - c := by simp lemma sub_sub_sub_cancel_right (a b c : α) : (a - c) - (b - c) = a - b := by simp theorem sub_eq_zero : a - b = 0 ↔ a = b := ⟨eq_of_sub_eq_zero, λ h, by simp [h]⟩ theorem sub_ne_zero : a - b ≠ 0 ↔ a ≠ b := not_congr sub_eq_zero theorem eq_sub_iff_add_eq : a = b - c ↔ a + c = b := by split; intro h; simp [h, eq_add_neg_iff_add_eq] theorem sub_eq_iff_eq_add : a - b = c ↔ a = c + b := by split; intro h; simp [*, add_neg_eq_iff_eq_add] at * theorem eq_iff_eq_of_sub_eq_sub {a b c d : α} (H : a - b = c - d) : a = b ↔ c = d := by rw [← sub_eq_zero, H, sub_eq_zero] theorem left_inverse_sub_add_left (c : α) : function.left_inverse (λ x, x - c) (λ x, x + c) := assume x, add_sub_cancel x c theorem left_inverse_add_left_sub (c : α) : function.left_inverse (λ x, x + c) (λ x, x - c) := assume x, sub_add_cancel x c theorem left_inverse_add_right_neg_add (c : α) : function.left_inverse (λ x, c + x) (λ x, - c + x) := assume x, add_neg_cancel_left c x theorem left_inverse_neg_add_add_right (c : α) : function.left_inverse (λ x, - c + x) (λ x, c + x) := assume x, neg_add_cancel_left c x end add_group section add_comm_group variables [add_comm_group α] {a b c : α} lemma sub_eq_neg_add (a b : α) : a - b = -b + a := by simp theorem neg_add' (a b : α) : -(a + b) = -a - b := neg_add a b lemma eq_sub_iff_add_eq' : a = b - c ↔ c + a = b := by rw [eq_sub_iff_add_eq, add_comm] lemma sub_eq_iff_eq_add' : a - b = c ↔ a = b + c := by rw [sub_eq_iff_eq_add, add_comm] lemma add_sub_cancel' (a b : α) : a + b - a = b := by simp lemma add_sub_cancel'_right (a b : α) : a + (b - a) = b := by rw [← add_sub_assoc, add_sub_cancel'] lemma sub_right_comm (a b c : α) : a - b - c = a - c - b := by simp lemma sub_add_sub_cancel' (a b c : α) : (a - b) + (c - a) = c - b := by rw add_comm; apply sub_add_sub_cancel lemma sub_sub_sub_cancel_left (a b c : α) : (c - a) - (c - b) = b - a := by simp end add_comm_group variables {β : Type*} [group α] [group β] {a b : α} /-- Predicate for group homomorphism. -/ def is_group_hom (f : α → β) : Prop := ∀ a b : α, f (a * b) = f a * f b namespace is_group_hom variables {f : α → β} (H : is_group_hom f) include H theorem mul : ∀ a b : α, f (a * b) = f a * f b := H theorem one : f 1 = 1 := mul_self_iff_eq_one.1 $ by simp [(H 1 1).symm] theorem inv (a : α) : (f a)⁻¹ = f a⁻¹ := inv_eq_of_mul_eq_one $ by simp [(H a a⁻¹).symm, one H] end is_group_hom /-- Predicate for group anti-homomorphism, or a homomorphism into the opposite group. -/ def is_group_anti_hom (f : α → β) : Prop := ∀ a b : α, f (a * b) = f b * f a namespace is_group_anti_hom variables {f : α → β} (H : is_group_anti_hom f) include H theorem mul : ∀ a b : α, f (a * b) = f b * f a := H theorem one : f 1 = 1 := mul_self_iff_eq_one.1 $ by simp [(H 1 1).symm] theorem inv (a : α) : (f a)⁻¹ = f a⁻¹ := inv_eq_of_mul_eq_one $ by simp [(H a⁻¹ a).symm, one H] end is_group_anti_hom theorem inv_is_group_anti_hom : is_group_anti_hom (λ x : α, x⁻¹) := mul_inv_rev
16c63d3d859f8a870ba259e24433fb993a577846
4fa161becb8ce7378a709f5992a594764699e268
/archive/sensitivity.lean
3e5a93e36d9555e8abbae05ca42610fd64b0d778
[ "Apache-2.0" ]
permissive
laughinggas/mathlib
e4aa4565ae34e46e834434284cb26bd9d67bc373
86dcd5cda7a5017c8b3c8876c89a510a19d49aad
refs/heads/master
1,669,496,232,688
1,592,831,995,000
1,592,831,995,000
274,155,979
0
0
Apache-2.0
1,592,835,190,000
1,592,835,189,000
null
UTF-8
Lean
false
false
15,516
lean
/- Copyright (c) 2019 Reid Barton, Johan Commelin, Jesse Han, Chris Hughes, Robert Y. Lewis, and Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Johan Commelin, Jesse Han, Chris Hughes, Robert Y. Lewis, and Patrick Massot -/ import tactic.fin_cases import tactic.apply_fun import linear_algebra.finite_dimensional import linear_algebra.dual import analysis.normed_space.basic /-! # Huang's sensitivity theorem A formalization of Hao Huang's sensitivity theorem: in the hypercube of dimension n ≥ 1, if one colors more than half the vertices then at least one vertex has at least √n colored neighbors. A fun summer collaboration by Reid Barton, Johan Commelin, Jesse Han, Chris Hughes, Robert Y. Lewis, and Patrick Massot, based on Don Knuth's account of the story (https://www.cs.stanford.edu/~knuth/papers/huang.pdf), using the Lean theorem prover (https://leanprover.github.io/), by Leonardo de Moura at Microsoft Research, and his collaborators (https://leanprover.github.io/people/), and using Lean's user maintained mathematics library (https://github.com/leanprover-community/mathlib). The project was developed at https://github.com/leanprover-community/lean-sensitivity and is now archived at https://github.com/leanprover-community/mathlib/blob/master/archive/sensitivity.lean -/ /-! The next two lines assert we do not want to give a constructive proof, but rather use classical logic. -/ noncomputable theory open_locale classical /-! We also want to use the notation `∑` for sums. -/ open_locale big_operators notation `|`x`|` := abs x notation `√` := real.sqrt open function bool linear_map fintype finite_dimensional dual_pair /-! ### The hypercube Notations: - `ℕ` denotes natural numbers (including zero). - `fin n` = {0, ⋯ , n - 1}. - `bool` = {`tt`, `ff`}. -/ /-- The hypercube in dimension `n`. -/ @[derive [inhabited, fintype]] def Q (n : ℕ) := fin n → bool /-- The projection from `Q (n + 1)` to `Q n` forgetting the first value (ie. the image of zero). -/ def π {n : ℕ} : Q (n + 1) → Q n := λ p, p ∘ fin.succ namespace Q /-! `n` will always denote a natural number. -/ variable (n : ℕ) /-- `Q 0` has a unique element. -/ instance : unique (Q 0) := ⟨⟨λ _, tt⟩, by { intro, ext x, fin_cases x }⟩ /-- `Q n` has 2^n elements. -/ lemma card : card (Q n) = 2^n := by simp [Q] /-! Until the end of this namespace, `n` will be an implicit argument (still a natural number). -/ variable {n} lemma succ_n_eq (p q : Q (n+1)) : p = q ↔ (p 0 = q 0 ∧ π p = π q) := begin split, { rintro rfl, exact ⟨rfl, rfl⟩, }, { rintros ⟨h₀, h⟩, ext x, by_cases hx : x = 0, { rwa hx }, { rw ← fin.succ_pred x hx, convert congr_fun h (fin.pred x hx) } } end /-- The adjacency relation defining the graph structure on `Q n`: `p.adjacent q` if there is an edge from `p` to `q` in `Q n`. -/ def adjacent {n : ℕ} (p : Q n) : set (Q n) := λ q, ∃! i, p i ≠ q i /-- In `Q 0`, no two vertices are adjacent. -/ lemma not_adjacent_zero (p q : Q 0) : ¬ p.adjacent q := by rintros ⟨v, _⟩; apply fin_zero_elim v /-- If `p` and `q` in `Q (n+1)` have different values at zero then they are adjacent iff their projections to `Q n` are equal. -/ lemma adj_iff_proj_eq {p q : Q (n+1)} (h₀ : p 0 ≠ q 0) : p.adjacent q ↔ π p = π q := begin split, { rintros ⟨i, h_eq, h_uni⟩, ext x, by_contradiction hx, apply fin.succ_ne_zero x, rw [h_uni _ hx, h_uni _ h₀] }, { intro heq, use [0, h₀], intros y hy, contrapose! hy, rw ←fin.succ_pred _ hy, apply congr_fun heq } end /-- If `p` and `q` in `Q (n+1)` have the same value at zero then they are adjacent iff their projections to `Q n` are adjacent. -/ lemma adj_iff_proj_adj {p q : Q (n+1)} (h₀ : p 0 = q 0) : p.adjacent q ↔ (π p).adjacent (π q) := begin split, { rintros ⟨i, h_eq, h_uni⟩, have h_i : i ≠ 0, from λ h_i, absurd h₀ (by rwa h_i at h_eq), use [i.pred h_i, show p (fin.succ (fin.pred i _)) ≠ q (fin.succ (fin.pred i _)), by rwa fin.succ_pred], intros y hy, simp [eq.symm (h_uni _ hy)] }, { rintros ⟨i, h_eq, h_uni⟩, use [i.succ, h_eq], intros y hy, rw [←fin.pred_inj, fin.pred_succ], { apply h_uni, change p (fin.pred _ _).succ ≠ q (fin.pred _ _).succ, simp [hy] }, { contrapose! hy, rw [hy, h₀] }, { apply fin.succ_ne_zero } } end @[symm] lemma adjacent.symm {p q : Q n} : p.adjacent q ↔ q.adjacent p := by simp only [adjacent, ne_comm] end Q /-! ### The vector space -/ /-- The free vector space on vertices of a hypercube, defined inductively. -/ def V : ℕ → Type | 0 := ℝ | (n+1) := V n × V n namespace V variables (n : ℕ) /-! `V n` is a real vector space whose equality relation is computable. -/ instance : decidable_eq (V n) := by { induction n ; { dunfold V, resetI, apply_instance } } instance : add_comm_group (V n) := by { induction n ; { dunfold V, resetI, apply_instance } } instance : vector_space ℝ (V n) := by { induction n ; { dunfold V, resetI, apply_instance } } end V /-- The basis of `V` indexed by the hypercube, defined inductively. -/ noncomputable def e : Π {n}, Q n → V n | 0 := λ _, (1:ℝ) | (n+1) := λ x, cond (x 0) (e (π x), 0) (0, e (π x)) @[simp] lemma e_zero_apply (x : Q 0) : e x = (1 : ℝ) := rfl /-- The dual basis to `e`, defined inductively. -/ noncomputable def ε : Π {n : ℕ} (p : Q n), V n →ₗ[ℝ] ℝ | 0 _ := linear_map.id | (n+1) p := cond (p 0) ((ε $ π p).comp $ linear_map.fst _ _ _) ((ε $ π p).comp $ linear_map.snd _ _ _) variable {n : ℕ} lemma duality (p q : Q n) : ε p (e q) = if p = q then 1 else 0 := begin induction n with n IH, { rw (show p = q, from subsingleton.elim p q), dsimp [ε, e], simp }, { dsimp [ε, e], cases hp : p 0 ; cases hq : q 0, all_goals { repeat {rw cond_tt}, repeat {rw cond_ff}, simp only [linear_map.fst_apply, linear_map.snd_apply, linear_map.comp_apply, IH], try { congr' 1, rw Q.succ_n_eq, finish }, try { erw (ε _).map_zero, have : p ≠ q, { intro h, rw p.succ_n_eq q at h, finish }, simp [this] } } } end /-- Any vector in `V n` annihilated by all `ε p`'s is zero. -/ lemma epsilon_total {v : V n} (h : ∀ p : Q n, (ε p) v = 0) : v = 0 := begin induction n with n ih, { dsimp [ε] at h, exact h (λ _, tt) }, { cases v with v₁ v₂, ext ; change _ = (0 : V n) ; simp only [] ; apply ih ; intro p ; [ let q : Q (n+1) := λ i, if h : i = 0 then tt else p (i.pred h), let q : Q (n+1) := λ i, if h : i = 0 then ff else p (i.pred h)], all_goals { specialize h q, rw [ε, show q 0 = tt, from rfl, cond_tt] at h <|> rw [ε, show q 0 = ff, from rfl, cond_ff] at h, rwa show p = π q, by { ext, simp [q, fin.succ_ne_zero, π] } } } end /-- `e` and `ε` are dual families of vectors. It implies that `e` is indeed a basis and `ε` computes coefficients of decompositions of vectors on that basis. -/ def dual_pair_e_ε (n : ℕ) : dual_pair (@e n) (@ε n) := { eval := duality, total := @epsilon_total _ } /-! We will now derive the dimension of `V`, first as a cardinal in `dim_V` and, since this cardinal is finite, as a natural number in `findim_V` -/ lemma dim_V : vector_space.dim ℝ (V n) = 2^n := have vector_space.dim ℝ (V n) = (2^n : ℕ), by { rw [dim_eq_card_basis (dual_pair_e_ε _).is_basis, Q.card]; apply_instance }, by assumption_mod_cast instance : finite_dimensional ℝ (V n) := finite_dimensional.of_finite_basis (dual_pair_e_ε _).is_basis lemma findim_V : findim ℝ (V n) = 2^n := have _ := @dim_V n, by rw ←findim_eq_dim at this; assumption_mod_cast /-! ### The linear map -/ /-- The linear operator $f_n$ corresponding to Huang's matrix $A_n$, defined inductively as a ℝ-linear map from `V n` to `V n`. -/ noncomputable def f : Π n, V n →ₗ[ℝ] V n | 0 := 0 | (n+1) := linear_map.prod (linear_map.coprod (f n) linear_map.id) (linear_map.coprod linear_map.id (-f n)) /-! The preceding definition uses linear map constructions to automatically get that `f` is linear, but its values are somewhat buried as a side-effect. The next two lemmas unbury them. -/ @[simp] lemma f_zero : f 0 = 0 := rfl lemma f_succ_apply (v : V (n+1)) : f (n+1) v = (f n v.1 + v.2, v.1 - f n v.2) := begin cases v, rw f, simp only [linear_map.id_apply, linear_map.prod_apply, prod.mk.inj_iff, linear_map.neg_apply, sub_eq_add_neg, linear_map.coprod_apply], exact ⟨rfl, rfl⟩ end /-! In the next statement, the explicit conversion `(n : ℝ)` of `n` to a real number is necessary since otherwise `n • v` refers to the multiplication defined using only the addition of `V`. -/ lemma f_squared : ∀ v : V n, (f n) (f n v) = (n : ℝ) • v := begin induction n with n IH; intro, { simpa only [nat.cast_zero, zero_smul] }, { cases v, simp [f_succ_apply, IH, add_smul, add_assoc], abel } end /-! We now compute the matrix of `f` in the `e` basis (`p` is the line index, `q` the column index). -/ lemma f_matrix : ∀ p q : Q n, |ε q (f n (e p))| = if q.adjacent p then 1 else 0 := begin induction n with n IH, { intros p q, dsimp [f], simp [Q.not_adjacent_zero] }, { intros p q, have ite_nonneg : ite (π q = π p) (1 : ℝ) 0 ≥ 0, { split_ifs ; norm_num }, have f_map_zero := (show linear_map ℝ (V (n+0)) (V n), from f n).map_zero, dsimp [e, ε, f], cases hp : p 0 ; cases hq : q 0, all_goals { repeat {rw cond_tt}, repeat {rw cond_ff}, simp [f_map_zero, hp, hq, IH, duality, abs_of_nonneg ite_nonneg, Q.adj_iff_proj_eq, Q.adj_iff_proj_adj] } } end /-- The linear operator $g_m$ corresponding to Knuth's matrix $B_m$. -/ noncomputable def g (m : ℕ) : V m →ₗ[ℝ] V (m+1) := linear_map.prod (f m + √(m+1) • linear_map.id) linear_map.id /-! In the following lemmas, `m` will denote a natural number. -/ variables {m : ℕ} /-! Again we unpack what are the values of `g`. -/ lemma g_apply : ∀ v, g m v = (f m v + √(m+1) • v, v) := by delta g; simp lemma g_injective : injective (g m) := begin rw g, intros x₁ x₂ h, simp only [linear_map.prod_apply, linear_map.id_apply, prod.mk.inj_iff] at h, exact h.right end lemma f_image_g (w : V (m + 1)) (hv : ∃ v, g m v = w) : f (m + 1) w = √(m + 1) • w := begin rcases hv with ⟨v, rfl⟩, have : √(m+1) * √(m+1) = m+1 := real.mul_self_sqrt (by exact_mod_cast zero_le _), simp [this, f_succ_apply, g_apply, f_squared, smul_add, add_smul, smul_smul], abel end /-! ### The main proof In this section, in order to enforce that `n` is positive, we write it as `m + 1` for some natural number `m`. -/ /-! `dim X` will denote the dimension of a subspace `X` as a cardinal. -/ notation `dim` X:70 := vector_space.dim ℝ ↥X /-! `fdim X` will denote the (finite) dimension of a subspace `X` as a natural number. -/ notation `fdim` := findim ℝ /-! `Span S` will denote the ℝ-subspace spanned by `S`. -/ notation `Span` := submodule.span ℝ /-! `Card X` will denote the cardinal of a subset of a finite type, as a natural number. -/ notation `Card` X:70 := X.to_finset.card /-! In the following, `⊓` and `⊔` will denote intersection and sums of ℝ-subspaces, equipped with their subspace structures. The notations come from the general theory of lattices, with inf and sup (also known as meet and join). -/ /-- If a subset `H` of `Q (m+1)` has cardinal at least `2^m + 1` then the subspace of `V (m+1)` spanned by the corresponding basis vectors non-trivially intersects the range of `g m`. -/ lemma exists_eigenvalue (H : set (Q (m + 1))) (hH : Card H ≥ 2^m + 1) : ∃ y ∈ Span (e '' H) ⊓ (g m).range, y ≠ (0 : _) := begin let W := Span (e '' H), let img := (g m).range, suffices : 0 < dim (W ⊓ img), { simp only [exists_prop], exact_mod_cast exists_mem_ne_zero_of_dim_pos this }, have dim_le : dim (W ⊔ img) ≤ 2^(m + 1), { convert ← dim_submodule_le (W ⊔ img), apply dim_V }, have dim_add : dim (W ⊔ img) + dim (W ⊓ img) = dim W + 2^m, { convert ← dim_sup_add_dim_inf_eq W img, rw ← dim_eq_of_injective (g m) g_injective, apply dim_V }, have dimW : dim W = card H, { have li : linear_independent ℝ (set.restrict e H) := linear_independent.comp (dual_pair_e_ε _).is_basis.1 _ subtype.val_injective, have hdW := dim_span li, rw set.range_restrict at hdW, convert hdW, rw [cardinal.mk_image_eq ((dual_pair_e_ε _).is_basis.injective zero_ne_one), cardinal.fintype_card] }, rw ← findim_eq_dim ℝ at ⊢ dim_le dim_add dimW, rw [← findim_eq_dim ℝ, ← findim_eq_dim ℝ] at dim_add, norm_cast at ⊢ dim_le dim_add dimW, rw nat.pow_succ at dim_le, rw set.to_finset_card at hH, linarith end theorem huang_degree_theorem (H : set (Q (m + 1))) (hH : Card H ≥ 2^m + 1) : ∃ q, q ∈ H ∧ √(m + 1) ≤ Card (H ∩ q.adjacent) := begin rcases exists_eigenvalue H hH with ⟨y, ⟨⟨y_mem_H, y_mem_g⟩, y_ne⟩⟩, have coeffs_support : ((dual_pair_e_ε (m+1)).coeffs y).support ⊆ H.to_finset, { intros p p_in, rw finsupp.mem_support_iff at p_in, rw set.mem_to_finset, exact (dual_pair_e_ε _).mem_of_mem_span y_mem_H p p_in }, obtain ⟨q, H_max⟩ : ∃ q : Q (m+1), ∀ q' : Q (m+1), |(ε q' : _) y| ≤ |ε q y|, from fintype.exists_max _, have H_q_pos : 0 < |ε q y|, { contrapose! y_ne, exact epsilon_total (λ p, abs_nonpos_iff.mp (le_trans (H_max p) y_ne)) }, refine ⟨q, (dual_pair_e_ε _).mem_of_mem_span y_mem_H q (abs_pos_iff.mp H_q_pos), _⟩, let s := √(m+1), suffices : s * |ε q y| ≤ ↑(_) * |ε q y|, from (mul_le_mul_right H_q_pos).mp ‹_›, let coeffs := (dual_pair_e_ε (m+1)).coeffs, calc s * (abs (ε q y)) = abs (ε q (s • y)) : by rw [map_smul, smul_eq_mul, abs_mul, abs_of_nonneg (real.sqrt_nonneg _)] ... = abs (ε q (f (m+1) y)) : by rw [← f_image_g y (by simpa using y_mem_g)] ... = abs (ε q (f (m+1) (lc _ (coeffs y)))) : by rw (dual_pair_e_ε _).decomposition y ... = abs ((coeffs y).sum (λ (i : Q (m + 1)) (a : ℝ), a • ((ε q) ∘ (f (m + 1)) ∘ λ (i : Q (m + 1)), e i) i)): by { erw [(f $ m+1).map_finsupp_total, (ε q).map_finsupp_total, finsupp.total_apply] ; apply_instance } ... ≤ ∑ p in (coeffs y).support, |(coeffs y p) * (ε q $ f (m+1) $ e p)| : norm_sum_le _ $ λ p, coeffs y p * _ ... = ∑ p in (coeffs y).support, |coeffs y p| * ite (q.adjacent p) 1 0 : by simp only [abs_mul, f_matrix] ... = ∑ p in (coeffs y).support.filter (Q.adjacent q), |coeffs y p| : by simp [finset.sum_filter] ... ≤ ∑ p in (coeffs y).support.filter (Q.adjacent q), |coeffs y q| : finset.sum_le_sum (λ p _, H_max p) ... = (finset.card ((coeffs y).support.filter (Q.adjacent q)): ℝ) * |coeffs y q| : by rw [← smul_eq_mul, ← finset.sum_const'] ... = (finset.card ((coeffs y).support ∩ (Q.adjacent q).to_finset): ℝ) * |coeffs y q| : by {congr, ext, simp, refl} ... ≤ (finset.card ((H ∩ Q.adjacent q).to_finset )) * |ε q y| : (mul_le_mul_right H_q_pos).mpr (by { norm_cast, exact finset.card_le_of_subset (by rw set.to_finset_inter; convert finset.inter_subset_inter_right coeffs_support) }) end
bd4fc1808613c2a5eae2f208a6344c5f70d41927
947b78d97130d56365ae2ec264df196ce769371a
/stage0/src/Init/Data/Array/Basic.lean
ce205184f0d9f6fc1f9a75298b5357d7ac126aa6
[ "Apache-2.0" ]
permissive
shyamalschandra/lean4
27044812be8698f0c79147615b1d5090b9f4b037
6e7a883b21eaf62831e8111b251dc9b18f40e604
refs/heads/master
1,671,417,126,371
1,601,859,995,000
1,601,860,020,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
30,442
lean
/- Copyright (c) 2018 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ prelude import Init.Data.Nat.Basic import Init.Data.Fin.Basic import Init.Data.UInt import Init.Data.Repr import Init.Data.ToString import Init.Control.Id import Init.Util universes u v w /- The Compiler has special support for arrays. They are implemented using dynamic arrays: https://en.wikipedia.org/wiki/Dynamic_array -/ structure Array (α : Type u) := (sz : Nat) (data : Fin sz → α) attribute [extern "lean_array_mk"] Array.mk attribute [extern "lean_array_data"] Array.data attribute [extern "lean_array_sz"] Array.sz @[reducible, extern "lean_array_get_size"] def Array.size {α : Type u} (a : @& Array α) : Nat := a.sz namespace Array variables {α : Type u} /- The parameter `c` is the initial capacity -/ @[extern "lean_mk_empty_array_with_capacity"] def mkEmpty (c : @& Nat) : Array α := { sz := 0, data := fun ⟨x, h⟩ => absurd h (Nat.notLtZero x) } @[extern "lean_array_push"] def push (a : Array α) (v : α) : Array α := { sz := Nat.succ a.sz, data := fun ⟨j, h₁⟩ => if h₂ : j = a.sz then v else a.data ⟨j, Nat.ltOfLeOfNe (Nat.leOfLtSucc h₁) h₂⟩ } @[extern "lean_mk_array"] def mkArray {α : Type u} (n : Nat) (v : α) : Array α := { sz := n, data := fun _ => v} theorem szMkArrayEq {α : Type u} (n : Nat) (v : α) : (mkArray n v).sz = n := rfl def empty : Array α := mkEmpty 0 instance : HasEmptyc (Array α) := ⟨Array.empty⟩ instance : Inhabited (Array α) := ⟨Array.empty⟩ def isEmpty (a : Array α) : Bool := a.size = 0 def singleton (v : α) : Array α := mkArray 1 v @[extern "lean_array_fget"] def get (a : @& Array α) (i : @& Fin a.size) : α := a.data i /- Low-level version of `fget` which is as fast as a C array read. `Fin` values are represented as tag pointers in the Lean runtime. Thus, `fget` may be slightly slower than `uget`. -/ @[extern "lean_array_uget"] def uget (a : @& Array α) (i : USize) (h : i.toNat < a.size) : α := a.get ⟨i.toNat, h⟩ /- "Comfortable" version of `fget`. It performs a bound check at runtime. -/ @[extern "lean_array_get"] def get! [Inhabited α] (a : @& Array α) (i : @& Nat) : α := if h : i < a.size then a.get ⟨i, h⟩ else arbitrary α def back [Inhabited α] (a : Array α) : α := a.get! (a.size - 1) def get? (a : Array α) (i : Nat) : Option α := if h : i < a.size then some (a.get ⟨i, h⟩) else none def getD (a : Array α) (i : Nat) (v₀ : α) : α := if h : i < a.size then a.get ⟨i, h⟩ else v₀ def getOp [Inhabited α] (self : Array α) (idx : Nat) : α := self.get! idx -- auxiliary declaration used in the equation compiler when pattern matching array literals. abbrev getLit {α : Type u} {n : Nat} (a : Array α) (i : Nat) (h₁ : a.size = n) (h₂ : i < n) : α := a.get ⟨i, h₁.symm ▸ h₂⟩ @[extern "lean_array_fset"] def set (a : Array α) (i : @& Fin a.size) (v : α) : Array α := { sz := a.sz, data := fun j => if h : i = j then v else a.data j } theorem szFSetEq (a : Array α) (i : Fin a.size) (v : α) : (set a i v).size = a.size := rfl theorem szPushEq (a : Array α) (v : α) : (push a v).size = a.size + 1 := rfl /- Low-level version of `fset` which is as fast as a C array fset. `Fin` values are represented as tag pointers in the Lean runtime. Thus, `fset` may be slightly slower than `uset`. -/ @[extern "lean_array_uset"] def uset (a : Array α) (i : USize) (v : α) (h : i.toNat < a.size) : Array α := a.set ⟨i.toNat, h⟩ v /- "Comfortable" version of `fset`. It performs a bound check at runtime. -/ @[extern "lean_array_set"] def set! (a : Array α) (i : @& Nat) (v : α) : Array α := if h : i < a.size then a.set ⟨i, h⟩ v else panic! "index out of bounds" @[extern "lean_array_fswap"] def swap (a : Array α) (i j : @& Fin a.size) : Array α := let v₁ := a.get i; let v₂ := a.get j; let a := a.set i v₂; a.set j v₁ @[extern "lean_array_swap"] def swap! (a : Array α) (i j : @& Nat) : Array α := if h₁ : i < a.size then if h₂ : j < a.size then swap a ⟨i, h₁⟩ ⟨j, h₂⟩ else panic! "index out of bounds" else panic! "index out of bounds" @[inline] def swapAt {α : Type} (a : Array α) (i : Fin a.size) (v : α) : α × Array α := let e := a.get i; let a := a.set i v; (e, a) -- TODO: delete as soon as we can define local instances @[neverExtract] private def swapAtPanic! [Inhabited α] (i : Nat) : α × Array α := panic! ("index " ++ toString i ++ " out of bounds") @[inline] def swapAt! {α : Type} (a : Array α) (i : Nat) (v : α) : α × Array α := if h : i < a.size then swapAt a ⟨i, h⟩ v else @swapAtPanic! _ ⟨v⟩ i @[extern "lean_array_pop"] def pop (a : Array α) : Array α := { sz := Nat.pred a.size, data := fun ⟨j, h⟩ => a.get ⟨j, Nat.ltOfLtOfLe h (Nat.predLe _)⟩ } -- TODO(Leo): justify termination using wf-rec partial def shrink : Array α → Nat → Array α | a, n => if n ≥ a.size then a else shrink a.pop n section variables {m : Type v → Type w} [Monad m] variables {β : Type v} {σ : Type u} -- TODO(Leo): justify termination using wf-rec @[specialize] partial def iterateMAux (a : Array α) (f : ∀ (i : Fin a.size), α → β → m β) : Nat → β → m β | i, b => if h : i < a.size then let idx : Fin a.size := ⟨i, h⟩; f idx (a.get idx) b >>= iterateMAux (i+1) else pure b @[inline] def iterateM (a : Array α) (b : β) (f : ∀ (i : Fin a.size), α → β → m β) : m β := iterateMAux a f 0 b @[inline] def foldlM (f : β → α → m β) (init : β) (a : Array α) : m β := iterateM a init (fun _ b a => f a b) @[inline] def foldlFromM (f : β → α → m β) (init : β) (beginIdx : Nat) (a : Array α) : m β := iterateMAux a (fun _ b a => f a b) beginIdx init -- TODO(Leo): justify termination using wf-rec @[specialize] partial def iterateM₂Aux (a₁ : Array α) (a₂ : Array σ) (f : ∀ (i : Fin a₁.size), α → σ → β → m β) : Nat → β → m β | i, b => if h₁ : i < a₁.size then let idx₁ : Fin a₁.size := ⟨i, h₁⟩; if h₂ : i < a₂.size then let idx₂ : Fin a₂.size := ⟨i, h₂⟩; f idx₁ (a₁.get idx₁) (a₂.get idx₂) b >>= iterateM₂Aux (i+1) else pure b else pure b @[inline] def iterateM₂ (a₁ : Array α) (a₂ : Array σ) (b : β) (f : ∀ (i : Fin a₁.size), α → σ → β → m β) : m β := iterateM₂Aux a₁ a₂ f 0 b @[inline] def foldlM₂ (f : β → α → σ → m β) (b : β) (a₁ : Array α) (a₂ : Array σ): m β := iterateM₂ a₁ a₂ b (fun _ a₁ a₂ b => f b a₁ a₂) @[specialize] partial def findSomeMAux (a : Array α) (f : α → m (Option β)) : Nat → m (Option β) | i => if h : i < a.size then let idx : Fin a.size := ⟨i, h⟩; do r ← f (a.get idx); match r with | some v => pure r | none => findSomeMAux (i+1) else pure none @[inline] def findSomeM? (a : Array α) (f : α → m (Option β)) : m (Option β) := findSomeMAux a f 0 @[specialize] partial def findSomeRevMAux (a : Array α) (f : α → m (Option β)) : ∀ (idx : Nat), idx ≤ a.size → m (Option β) | i, h => if hLt : 0 < i then have i - 1 < i from Nat.subLt hLt (Nat.zeroLtSucc 0); have i - 1 < a.size from Nat.ltOfLtOfLe this h; let idx : Fin a.size := ⟨i - 1, this⟩; do r ← f (a.get idx); match r with | some v => pure r | none => have i - 1 ≤ a.size from Nat.leOfLt this; findSomeRevMAux (i-1) this else pure none @[inline] def findSomeRevM? (a : Array α) (f : α → m (Option β)) : m (Option β) := findSomeRevMAux a f a.size (Nat.leRefl _) end -- TODO(Leo): justify termination using wf-rec @[specialize] partial def findMAux {α : Type} {m : Type → Type} [Monad m] (a : Array α) (p : α → m Bool) : Nat → m (Option α) | i => if h : i < a.size then do let v := a.get ⟨i, h⟩; condM (p v) (pure (some v)) (findMAux (i+1)) else pure none @[inline] def findM? {α : Type} {m : Type → Type} [Monad m] (a : Array α) (p : α → m Bool) : m (Option α) := findMAux a p 0 @[inline] def find? {α : Type} (a : Array α) (p : α → Bool) : Option α := Id.run $ a.findM? p @[specialize] partial def findRevMAux {α : Type} {m : Type → Type} [Monad m] (a : Array α) (p : α → m Bool) : ∀ (idx : Nat), idx ≤ a.size → m (Option α) | i, h => if hLt : 0 < i then have i - 1 < i from Nat.subLt hLt (Nat.zeroLtSucc 0); have i - 1 < a.size from Nat.ltOfLtOfLe this h; let v := a.get ⟨i - 1, this⟩; do { condM (p v) (pure (some v)) $ have i - 1 ≤ a.size from Nat.leOfLt this; findRevMAux (i-1) this } else pure none @[inline] def findRevM? {α : Type} {m : Type → Type} [Monad m] (a : Array α) (p : α → m Bool) : m (Option α) := findRevMAux a p a.size (Nat.leRefl _) @[inline] def findRev? {α : Type} (a : Array α) (p : α → Bool) : Option α := Id.run $ a.findRevM? p section variables {β : Type w} {σ : Type u} @[inline] def iterate (a : Array α) (b : β) (f : ∀ (i : Fin a.size), α → β → β) : β := Id.run $ iterateMAux a f 0 b @[inline] def iterateFrom (a : Array α) (b : β) (i : Nat) (f : ∀ (i : Fin a.size), α → β → β) : β := Id.run $ iterateMAux a f i b @[inline] def foldl (f : β → α → β) (init : β) (a : Array α) : β := iterate a init (fun _ a b => f b a) @[inline] def foldlFrom (f : β → α → β) (init : β) (beginIdx : Nat) (a : Array α) : β := Id.run $ foldlFromM f init beginIdx a @[inline] def iterate₂ (a₁ : Array α) (a₂ : Array σ) (b : β) (f : ∀ (i : Fin a₁.size), α → σ → β → β) : β := Id.run $ iterateM₂Aux a₁ a₂ f 0 b @[inline] def foldl₂ (f : β → α → σ → β) (b : β) (a₁ : Array α) (a₂ : Array σ) : β := iterate₂ a₁ a₂ b (fun _ a₁ a₂ b => f b a₁ a₂) @[inline] def findSome? (a : Array α) (f : α → Option β) : Option β := Id.run $ findSomeMAux a f 0 @[inline] def findSome! [Inhabited β] (a : Array α) (f : α → Option β) : β := match findSome? a f with | some b => b | none => panic! "failed to find element" @[inline] def findSomeRev? (a : Array α) (f : α → Option β) : Option β := Id.run $ findSomeRevMAux a f a.size (Nat.leRefl _) @[inline] def findSomeRev! [Inhabited β] (a : Array α) (f : α → Option β) : β := match findSomeRev? a f with | some b => b | none => panic! "failed to find element" @[specialize] partial def findIdxMAux {m : Type → Type u} [Monad m] (a : Array α) (p : α → m Bool) : Nat → m (Option Nat) | i => if h : i < a.size then condM (p (a.get ⟨i, h⟩)) (pure (some i)) (findIdxMAux (i+1)) else pure none @[inline] def findIdxM? {m : Type → Type u} [Monad m] (a : Array α) (p : α → m Bool) : m (Option Nat) := findIdxMAux a p 0 @[specialize] partial def findIdxAux (a : Array α) (p : α → Bool) : Nat → Option Nat | i => if h : i < a.size then if p (a.get ⟨i, h⟩) then some i else findIdxAux (i+1) else none @[inline] def findIdx? (a : Array α) (p : α → Bool) : Option Nat := findIdxAux a p 0 @[inline] def findIdx! (a : Array α) (p : α → Bool) : Nat := match findIdxAux a p 0 with | some i => i | none => panic! "failed to find element" def getIdx? [HasBeq α] (a : Array α) (v : α) : Option Nat := a.findIdx? $ fun a => a == v end section variables {m : Type → Type w} [Monad m] @[specialize] partial def anyRangeMAux (a : Array α) (endIdx : Nat) (hlt : endIdx ≤ a.size) (p : α → m Bool) : Nat → m Bool | i => if h : i < endIdx then let idx : Fin a.size := ⟨i, Nat.ltOfLtOfLe h hlt⟩; do b ← p (a.get idx); match b with | true => pure true | false => anyRangeMAux (i+1) else pure false @[inline] def anyM (a : Array α) (p : α → m Bool) : m Bool := anyRangeMAux a a.size (Nat.leRefl _) p 0 @[inline] def allM (a : Array α) (p : α → m Bool) : m Bool := do b ← anyM a (fun v => do b ← p v; pure (!b)); pure (!b) @[inline] def anyRangeM (a : Array α) (beginIdx endIdx : Nat) (p : α → m Bool) : m Bool := if h : endIdx ≤ a.size then anyRangeMAux a endIdx h p beginIdx else anyRangeMAux a a.size (Nat.leRefl _) p beginIdx @[inline] def allRangeM (a : Array α) (beginIdx endIdx : Nat) (p : α → m Bool) : m Bool := do b ← anyRangeM a beginIdx endIdx (fun v => do b ← p v; pure b); pure (!b) end @[inline] def any (a : Array α) (p : α → Bool) : Bool := Id.run $ anyM a p @[inline] def anyRange (a : Array α) (beginIdx endIdx : Nat) (p : α → Bool) : Bool := Id.run $ anyRangeM a beginIdx endIdx p @[inline] def anyFrom (a : Array α) (beginIdx : Nat) (p : α → Bool) : Bool := Id.run $ anyRangeM a beginIdx a.size p @[inline] def all (a : Array α) (p : α → Bool) : Bool := !any a (fun v => !p v) @[inline] def allRange (a : Array α) (beginIdx endIdx : Nat) (p : α → Bool) : Bool := !anyRange a beginIdx endIdx (fun v => !p v) section variables {m : Type v → Type w} [Monad m] variable {β : Type v} @[specialize] private def iterateRevMAux (a : Array α) (f : ∀ (i : Fin a.size), α → β → m β) : ∀ (i : Nat), i ≤ a.size → β → m β | 0, h, b => pure b | j+1, h, b => do let i : Fin a.size := ⟨j, h⟩; b ← f i (a.get i) b; iterateRevMAux j (Nat.leOfLt h) b @[inline] def iterateRevM (a : Array α) (b : β) (f : ∀ (i : Fin a.size), α → β → m β) : m β := iterateRevMAux a f a.size (Nat.leRefl _) b @[inline] def foldrM (f : α → β → m β) (init : β) (a : Array α) : m β := iterateRevM a init (fun _ => f) @[specialize] private def foldrRangeMAux (a : Array α) (f : α → β → m β) (beginIdx : Nat) : ∀ (i : Nat), i ≤ a.size → β → m β | 0, h, b => pure b | j+1, h, b => do let i : Fin a.size := ⟨j, h⟩; b ← f (a.get i) b; if j == beginIdx then pure b else foldrRangeMAux j (Nat.leOfLt h) b @[inline] def foldrRangeM (beginIdx endIdx : Nat) (f : α → β → m β) (ini : β) (a : Array α) : m β := if h : endIdx ≤ a.size then foldrRangeMAux a f beginIdx endIdx h ini else foldrRangeMAux a f beginIdx a.size (Nat.leRefl _) ini @[specialize] partial def foldlStepMAux (step : Nat) (a : Array α) (f : β → α → m β) : Nat → β → m β | i, b => if h : i < a.size then do let curr := a.get ⟨i, h⟩; b ← f b curr; foldlStepMAux (i+step) b else pure b @[inline] def foldlStepM (f : β → α → m β) (init : β) (step : Nat) (a : Array α) : m β := foldlStepMAux step a f 0 init end @[inline] def iterateRev {β} (a : Array α) (b : β) (f : ∀ (i : Fin a.size), α → β → β) : β := Id.run $ iterateRevM a b f @[inline] def foldr {β} (f : α → β → β) (init : β) (a : Array α) : β := Id.run $ foldrM f init a @[inline] def foldrRange {β} (beginIdx endIdx : Nat) (f : α → β → β) (init : β) (a : Array α) : β := Id.run $ foldrRangeM beginIdx endIdx f init a @[inline] def foldlStep {β} (f : β → α → β) (init : β) (step : Nat) (a : Array α) : β := Id.run $ foldlStepM f init step a @[inline] def getEvenElems (a : Array α) : Array α := a.foldlStep (fun r a => Array.push r a) empty 2 def toList (a : Array α) : List α := a.foldr List.cons [] instance [HasRepr α] : HasRepr (Array α) := ⟨fun a => "#" ++ repr a.toList⟩ instance [HasToString α] : HasToString (Array α) := ⟨fun a => "#" ++ toString a.toList⟩ section variables {m : Type v → Type w} [Monad m] variable {β : Type v} @[specialize] unsafe partial def umapMAux (f : Nat → α → m β) : Nat → Array NonScalar → m (Array PNonScalar.{v}) | i, a => if h : i < a.size then let idx : Fin a.size := ⟨i, h⟩; let v : NonScalar := a.get idx; let a := a.set idx (arbitrary _); do newV ← f i (unsafeCast v); umapMAux (i+1) (a.set idx (unsafeCast newV)) else pure (unsafeCast a) @[inline] unsafe partial def umapM (f : α → m β) (as : Array α) : m (Array β) := @unsafeCast (m (Array PNonScalar.{v})) (m (Array β)) $ umapMAux (fun i a => f a) 0 (unsafeCast as) @[inline] unsafe partial def umapIdxM (f : Nat → α → m β) (as : Array α) : m (Array β) := @unsafeCast (m (Array PNonScalar.{v})) (m (Array β)) $ umapMAux f 0 (unsafeCast as) @[implementedBy Array.umapM] def mapM (f : α → m β) (as : Array α) : m (Array β) := as.foldlM (fun bs a => do b ← f a; pure (bs.push b)) (mkEmpty as.size) @[implementedBy Array.umapIdxM] def mapIdxM (f : Nat → α → m β) (as : Array α) : m (Array β) := as.iterateM (mkEmpty as.size) (fun i a bs => do b ← f i.val a; pure (bs.push b)) end section variables {m : Type u → Type v} [Monad m] @[inline] def modifyM [Inhabited α] (a : Array α) (i : Nat) (f : α → m α) : m (Array α) := if h : i < a.size then do let idx : Fin a.size := ⟨i, h⟩; let v := a.get idx; let a := a.set idx (arbitrary α); v ← f v; pure $ (a.set idx v) else pure a end section variable {β : Type v} @[inline] def modify [Inhabited α] (a : Array α) (i : Nat) (f : α → α) : Array α := Id.run $ a.modifyM i f @[inline] def modifyOp [Inhabited α] (self : Array α) (idx : Nat) (f : α → α) : Array α := self.modify idx f @[inline] def mapIdx (f : Nat → α → β) (a : Array α) : Array β := Id.run $ mapIdxM f a @[inline] def map (f : α → β) (as : Array α) : Array β := Id.run $ mapM f as end section variables {m : Type v → Type w} [Monad m] variable {β : Type v} @[specialize] partial def forMAux (f : α → m PUnit) (a : Array α) : Nat → m PUnit | i => if h : i < a.size then let idx : Fin a.size := ⟨i, h⟩; let v : α := a.get idx; do f v; forMAux (i+1) else pure ⟨⟩ @[inline] def forM (f : α → m PUnit) (a : Array α) : m PUnit := a.forMAux f 0 @[inline] def forFromM (f : α → m PUnit) (beginIdx : Nat) (a : Array α) : m PUnit := a.forMAux f beginIdx @[specialize] partial def forRevMAux (f : α → m PUnit) (a : Array α) : forall (i : Nat), i ≤ a.size → m PUnit | i, h => if hLt : 0 < i then have i - 1 < i from Nat.subLt hLt (Nat.zeroLtSucc 0); have i - 1 < a.size from Nat.ltOfLtOfLe this h; let v : α := a.get ⟨i-1, this⟩; have i - 1 ≤ a.size from Nat.leOfLt this; do f v; forRevMAux (i-1) this else pure ⟨⟩ @[inline] def forRevM (f : α → m PUnit) (a : Array α) : m PUnit := a.forRevMAux f a.size (Nat.leRefl _) end -- TODO(Leo): justify termination using wf-rec partial def extractAux (a : Array α) : Nat → ∀ (e : Nat), e ≤ a.size → Array α → Array α | i, e, hle, r => if hlt : i < e then let idx : Fin a.size := ⟨i, Nat.ltOfLtOfLe hlt hle⟩; extractAux (i+1) e hle (r.push (a.get idx)) else r def extract (a : Array α) (b e : Nat) : Array α := let r : Array α := mkEmpty (e - b); if h : e ≤ a.size then extractAux a b e h r else r protected def append (a : Array α) (b : Array α) : Array α := b.foldl (fun a v => a.push v) a instance : HasAppend (Array α) := ⟨Array.append⟩ -- TODO(Leo): justify termination using wf-rec @[specialize] partial def isEqvAux (a b : Array α) (hsz : a.size = b.size) (p : α → α → Bool) : Nat → Bool | i => if h : i < a.size then let aidx : Fin a.size := ⟨i, h⟩; let bidx : Fin b.size := ⟨i, hsz ▸ h⟩; match p (a.get aidx) (b.get bidx) with | true => isEqvAux (i+1) | false => false else true @[inline] def isEqv (a b : Array α) (p : α → α → Bool) : Bool := if h : a.size = b.size then isEqvAux a b h p 0 else false instance [HasBeq α] : HasBeq (Array α) := ⟨fun a b => isEqv a b HasBeq.beq⟩ -- TODO(Leo): justify termination using wf-rec, and use `swap` partial def reverseAux : Array α → Nat → Array α | a, i => let n := a.size; if i < n / 2 then reverseAux (a.swap! i (n - i - 1)) (i+1) else a def reverse (a : Array α) : Array α := reverseAux a 0 -- TODO(Leo): justify termination using wf-rec @[specialize] partial def filterAux (p : α → Bool) : Array α → Nat → Nat → Array α | a, i, j => if h₁ : i < a.size then if p (a.get ⟨i, h₁⟩) then if h₂ : j < i then filterAux (a.swap ⟨i, h₁⟩ ⟨j, Nat.ltTrans h₂ h₁⟩) (i+1) (j+1) else filterAux a (i+1) (j+1) else filterAux a (i+1) j else a.shrink j @[inline] def filter (p : α → Bool) (as : Array α) : Array α := filterAux p as 0 0 @[specialize] partial def filterMAux {m : Type → Type} [Monad m] {α : Type} (p : α → m Bool) : Array α → Nat → Nat → m (Array α) | a, i, j => if h₁ : i < a.size then condM (p (a.get ⟨i, h₁⟩)) (if h₂ : j < i then filterMAux (a.swap ⟨i, h₁⟩ ⟨j, Nat.ltTrans h₂ h₁⟩) (i+1) (j+1) else filterMAux a (i+1) (j+1)) (filterMAux a (i+1) j) else pure $ a.shrink j @[inline] def filterM {m : Type → Type} [Monad m] {α : Type} (p : α → m Bool) (as : Array α) : m (Array α) := filterMAux p as 0 0 @[inline] def filterFromM {m : Type → Type} [Monad m] {α : Type} (p : α → m Bool) (beginIdx : Nat) (as : Array α) : m (Array α) := filterMAux p as beginIdx beginIdx @[specialize] partial def filterMapMAux {m : Type u → Type v} [Monad m] {α β : Type u} (f : α → m (Option β)) (as : Array α) : Nat → Array β → m (Array β) | i, bs => if h : i < as.size then do let a := as.get ⟨i, h⟩; b? ← f a; match b? with | none => filterMapMAux (i+1) bs | some b => filterMapMAux (i+1) (bs.push b) else pure bs @[inline] def filterMapM {m : Type u → Type v} [Monad m] {α β : Type u} (f : α → m (Option β)) (as : Array α) : m (Array β) := filterMapMAux f as 0 Array.empty @[inline] def filterMap {α β : Type u} (f : α → Option β) (as : Array α) : Array β := Id.run $ filterMapM f as partial def indexOfAux {α} [HasBeq α] (a : Array α) (v : α) : Nat → Option (Fin a.size) | i => if h : i < a.size then let idx : Fin a.size := ⟨i, h⟩; if a.get idx == v then some idx else indexOfAux (i+1) else none def indexOf? {α} [HasBeq α] (a : Array α) (v : α) : Option (Fin a.size) := indexOfAux a v 0 partial def eraseIdxAux {α} : Nat → Array α → Array α | i, a => if h : i < a.size then let idx : Fin a.size := ⟨i, h⟩; let idx1 : Fin a.size := ⟨i - 1, Nat.ltOfLeOfLt (Nat.predLe i) h⟩; eraseIdxAux (i+1) (a.swap idx idx1) else a.pop def feraseIdx {α} (a : Array α) (i : Fin a.size) : Array α := eraseIdxAux (i.val + 1) a def eraseIdx {α} (a : Array α) (i : Nat) : Array α := if i < a.size then eraseIdxAux (i+1) a else a theorem szFSwapEq (a : Array α) (i j : Fin a.size) : (a.swap i j).size = a.size := rfl theorem szPopEq (a : Array α) : a.pop.size = a.size - 1 := rfl section /- Instance for justifying `partial` declaration. We should be able to delete it as soon as we restore support for well-founded recursion. -/ instance eraseIdxSzAuxInstance (a : Array α) : Inhabited { r : Array α // r.size = a.size - 1 } := ⟨⟨a.pop, szPopEq a⟩⟩ partial def eraseIdxSzAux {α} (a : Array α) : ∀ (i : Nat) (r : Array α), r.size = a.size → { r : Array α // r.size = a.size - 1 } | i, r, heq => if h : i < r.size then let idx : Fin r.size := ⟨i, h⟩; let idx1 : Fin r.size := ⟨i - 1, Nat.ltOfLeOfLt (Nat.predLe i) h⟩; eraseIdxSzAux (i+1) (r.swap idx idx1) ((szFSwapEq r idx idx1).trans heq) else ⟨r.pop, (szPopEq r).trans (heq ▸ rfl)⟩ end def eraseIdx' {α} (a : Array α) (i : Fin a.size) : { r : Array α // r.size = a.size - 1 } := eraseIdxSzAux a (i.val + 1) a rfl def contains [HasBeq α] (as : Array α) (a : α) : Bool := as.any $ fun b => a == b def elem [HasBeq α] (a : α) (as : Array α) : Bool := as.contains a def erase [HasBeq α] (as : Array α) (a : α) : Array α := match as.indexOf? a with | none => as | some i => as.feraseIdx i partial def insertAtAux {α} (i : Nat) : Array α → Nat → Array α | as, j => if i == j then as else let as := as.swap! (j-1) j; insertAtAux as (j-1) /-- Insert element `a` at position `i`. Pre: `i < as.size` -/ def insertAt {α} (as : Array α) (i : Nat) (a : α) : Array α := if i > as.size then panic! "invalid index" else let as := as.push a; as.insertAtAux i as.size theorem ext {α : Type u} (a b : Array α) : a.size = b.size → (∀ (i : Nat) (hi₁ : i < a.size) (hi₂ : i < b.size) , a.get ⟨i, hi₁⟩ = b.get ⟨i, hi₂⟩) → a = b := match a, b with | ⟨sz₁, f₁⟩, ⟨sz₂, f₂⟩ => show sz₁ = sz₂ → (∀ (i : Nat) (hi₁ : i < sz₁) (hi₂ : i < sz₂) , f₁ ⟨i, hi₁⟩ = f₂ ⟨i, hi₂⟩) → Array.mk sz₁ f₁ = Array.mk sz₂ f₂ from fun h₁ h₂ => match sz₁, sz₂, f₁, f₂, h₁, h₂ with | sz, _, f₁, f₂, rfl, h₂ => have f₁ = f₂ from funext $ fun ⟨i, hi₁⟩ => h₂ i hi₁ hi₁; congrArg _ this theorem extLit {α : Type u} {n : Nat} (a b : Array α) (hsz₁ : a.size = n) (hsz₂ : b.size = n) (h : ∀ (i : Nat) (hi : i < n), a.getLit i hsz₁ hi = b.getLit i hsz₂ hi) : a = b := Array.ext a b (hsz₁.trans hsz₂.symm) $ fun i hi₁ hi₂ => h i (hsz₁ ▸ hi₁) end Array export Array (mkArray) @[inlineIfReduce] def List.toArrayAux {α : Type u} : List α → Array α → Array α | [], r => r | a::as, r => List.toArrayAux as (r.push a) @[inlineIfReduce] def List.redLength {α : Type u} : List α → Nat | [] => 0 | _::as => as.redLength + 1 @[inline, matchPattern] def List.toArray {α : Type u} (as : List α) : Array α := as.toArrayAux (Array.mkEmpty as.redLength) namespace Array def toListLitAux {α : Type u} (a : Array α) (n : Nat) (hsz : a.size = n) : ∀ (i : Nat), i ≤ a.size → List α → List α | 0, hi, acc => acc | (i+1), hi, acc => toListLitAux i (Nat.leOfSuccLe hi) (a.getLit i hsz (Nat.ltOfLtOfEq (Nat.ltOfLtOfLe (Nat.ltSuccSelf i) hi) hsz) :: acc) def toArrayLit {α : Type u} (a : Array α) (n : Nat) (hsz : a.size = n) : Array α := List.toArray $ toListLitAux a n hsz n (hsz ▸ Nat.leRefl _) [] theorem toArrayLitEq {α : Type u} (a : Array α) (n : Nat) (hsz : a.size = n) : a = toArrayLit a n hsz := -- TODO: this is painful to prove without proper automation sorry /- First, we need to prove ∀ i j acc, i ≤ a.size → (toListLitAux a n hsz (i+1) hi acc).index j = if j < i then a.getLit j hsz _ else acc.index (j - i) by induction Base case is trivial (j : Nat) (acc : List α) (hi : 0 ≤ a.size) |- (toListLitAux a n hsz 0 hi acc).index j = if j < 0 then a.getLit j hsz _ else acc.index (j - 0) ... |- acc.index j = acc.index j Induction (j : Nat) (acc : List α) (hi : i+1 ≤ a.size) |- (toListLitAux a n hsz (i+1) hi acc).index j = if j < i + 1 then a.getLit j hsz _ else acc.index (j - (i + 1)) ... |- (toListLitAux a n hsz i hi' (a.getLit i hsz _ :: acc)).index j = if j < i + 1 then a.getLit j hsz _ else acc.index (j - (i + 1)) * by def ... |- if j < i then a.getLit j hsz _ else (a.getLit i hsz _ :: acc).index (j-i) * by induction hypothesis = if j < i + 1 then a.getLit j hsz _ else acc.index (j - (i + 1)) If j < i, then both are a.getLit j hsz _ If j = i, then lhs reduces else-branch to (a.getLit i hsz _) and rhs is then-brachn (a.getLit i hsz _) If j >= i + 1, we use - j - i >= 1 > 0 - (a::as).index k = as.index (k-1) If k > 0 - j - (i + 1) = (j - i) - 1 Then lhs = (a.getLit i hsz _ :: acc).index (j-i) = acc.index (j-i-1) = acc.index (j-(i+1)) = rhs With this proof, we have ∀ j, j < n → (toListLitAux a n hsz n _ []).index j = a.getLit j hsz _ We also need - (toListLitAux a n hsz n _ []).length = n - j < n -> (List.toArray as).getLit j _ _ = as.index j Then using Array.extLit, we have that a = List.toArray $ toListLitAux a n hsz n _ [] -/ @[specialize] def getMax? {α : Type u} (as : Array α) (lt : α → α → Bool) : Option α := if h : 0 < as.size then let a0 := as.get ⟨0, h⟩; some $ as.foldlFrom (fun best a => if lt best a then a else best) a0 1 else none @[specialize] partial def partitionAux {α : Type u} (p : α → Bool) (as : Array α) : Nat → Array α → Array α → Array α × Array α | i, bs, cs => if h : i < as.size then let a := as.get ⟨i, h⟩; match p a with | true => partitionAux (i+1) (bs.push a) cs | false => partitionAux (i+1) bs (cs.push a) else (bs, cs) @[inline] def partition {α : Type u} (p : α → Bool) (as : Array α) : Array α × Array α := partitionAux p as 0 #[] #[] partial def isPrefixOfAux {α : Type u} [HasBeq α] (as bs : Array α) (hle : as.size ≤ bs.size) : Nat → Bool | i => if h : i < as.size then let a := as.get ⟨i, h⟩; let b := bs.get ⟨i, Nat.ltOfLtOfLe h hle⟩; if a == b then isPrefixOfAux (i+1) else false else true /- Return true iff `as` is a prefix of `bs` -/ def isPrefixOf {α : Type u} [HasBeq α] (as bs : Array α) : Bool := if h : as.size ≤ bs.size then isPrefixOfAux as bs h 0 else false private def allDiffAuxAux {α} [HasBeq α] (as : Array α) (a : α) : forall (i : Nat), i < as.size → Bool | 0, h => true | i+1, h => have i < as.size from Nat.ltTrans (Nat.ltSuccSelf _) h; a != as.get ⟨i, this⟩ && allDiffAuxAux i this private partial def allDiffAux {α} [HasBeq α] (as : Array α) : Nat → Bool | i => if h : i < as.size then allDiffAuxAux as (as.get ⟨i, h⟩) i h && allDiffAux (i+1) else true def allDiff {α} [HasBeq α] (as : Array α) : Bool := allDiffAux as 0 @[specialize] partial def zipWithAux {α β γ} (f : α → β → γ) (as : Array α) (bs : Array β) : Nat → Array γ → Array γ | i, cs => if h : i < as.size then let a := as.get ⟨i, h⟩; if h : i < bs.size then let b := bs.get ⟨i, h⟩; zipWithAux (i+1) (cs.push $ f a b) else cs else cs @[inline] def zipWith {α β γ} (as : Array α) (bs : Array β) (f : α → β → γ) : Array γ := zipWithAux f as bs 0 #[] def zip {α β} (as : Array α) (bs : Array β) : Array (α × β) := zipWith as bs Prod.mk end Array
b22df718ee8b03ec165443787e8bee332db2b6f1
624f6f2ae8b3b1adc5f8f67a365c51d5126be45a
/tests/compiler/array_test2.lean
e5f767615eafcd505cb0c60c293b84c9313dbd4c
[ "Apache-2.0" ]
permissive
mhuisi/lean4
28d35a4febc2e251c7f05492e13f3b05d6f9b7af
dda44bc47f3e5d024508060dac2bcb59fd12e4c0
refs/heads/master
1,621,225,489,283
1,585,142,689,000
1,585,142,689,000
250,590,438
0
2
Apache-2.0
1,602,443,220,000
1,585,327,814,000
C
UTF-8
Lean
false
false
444
lean
def check (b : Bool) : IO Unit := unless b $ IO.println "failed" def main : IO Unit := let a1 := [2, 3, 5].toArray; let a2 := [4, 7, 9].toArray; let a3 := [4, 7, 8].toArray; do check (Array.isEqv a1 a2 (fun v w => v % 2 == w % 2)); check (!Array.isEqv a1 a3 (fun v w => v % 2 == w % 2)); check (a1 ++ a2 == [2, 3, 5, 4, 7, 9].toArray); check (a1.any (fun a => a > 4)); check (!a1.any (fun a => a >10)); check (a1.all (fun a => a < 10))
67f7f45d2837a2467cdf820ab82b5a1f380c2f06
690889011852559ee5ac4dfea77092de8c832e7e
/src/data/rat/cast.lean
1a85c6296667259d654cfa19379a13c168dbe75b
[ "Apache-2.0" ]
permissive
williamdemeo/mathlib
f6df180148f8acc91de9ba5e558976ab40a872c7
1fa03c29f9f273203bbffb79d10d31f696b3d317
refs/heads/master
1,584,785,260,929
1,572,195,914,000
1,572,195,913,000
138,435,193
0
0
Apache-2.0
1,529,789,739,000
1,529,789,739,000
null
UTF-8
Lean
false
false
11,729
lean
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import data.rat.order /-! # Casts for Rational Numbers ## Summary We define the canonical injection from ℚ into an arbitrary division ring and prove various casting lemmas showing the well-behavedness of this injection. ## Notations - `/.` is infix notation for `rat.mk`. ## Tags rat, rationals, field, ℚ, numerator, denominator, num, denom, cast, coercion, casting -/ namespace rat variable {α : Type*} open_locale rat section with_div_ring variable [division_ring α] /-- Construct the canonical injection from `ℚ` into an arbitrary division ring. If the field has positive characteristic `p`, we define `1 / p = 1 / 0 = 0` for consistency with our division by zero convention. -/ protected def cast : ℚ → α | ⟨n, d, h, c⟩ := n / d @[priority 10] instance cast_coe : has_coe ℚ α := ⟨rat.cast⟩ @[simp] theorem cast_of_int (n : ℤ) : (of_int n : α) = n := show (n / (1:ℕ) : α) = n, by rw [nat.cast_one, div_one] @[simp, squash_cast] theorem cast_coe_int (n : ℤ) : ((n : ℚ) : α) = n := by rw [coe_int_eq_of_int, cast_of_int] @[simp, squash_cast] theorem cast_coe_nat (n : ℕ) : ((n : ℚ) : α) = n := cast_coe_int n @[simp, squash_cast] theorem cast_zero : ((0 : ℚ) : α) = 0 := (cast_of_int _).trans int.cast_zero @[simp, squash_cast] theorem cast_one : ((1 : ℚ) : α) = 1 := (cast_of_int _).trans int.cast_one theorem mul_cast_comm (a : α) : ∀ (n : ℚ), (n.denom : α) ≠ 0 → a * n = n * a | ⟨n, d, h, c⟩ h₂ := show a * (n * d⁻¹) = n * d⁻¹ * a, by rw [← mul_assoc, int.mul_cast_comm, mul_assoc, mul_assoc, ← show (d:α)⁻¹ * a = a * d⁻¹, from division_ring.inv_comm_of_comm h₂ (int.mul_cast_comm a d).symm] @[move_cast] theorem cast_mk_of_ne_zero (a b : ℤ) (b0 : (b:α) ≠ 0) : (a /. b : α) = a / b := begin have b0' : b ≠ 0, { refine mt _ b0, simp {contextual := tt} }, cases e : a /. b with n d h c, have d0 : (d:α) ≠ 0, { intro d0, have dd := denom_dvd a b, cases (show (d:ℤ) ∣ b, by rwa e at dd) with k ke, have : (b:α) = (d:α) * (k:α), {rw [ke, int.cast_mul], refl}, rw [d0, zero_mul] at this, contradiction }, rw [num_denom'] at e, have := congr_arg (coe : ℤ → α) ((mk_eq b0' $ ne_of_gt $ int.coe_nat_pos.2 h).1 e), rw [int.cast_mul, int.cast_mul, int.cast_coe_nat] at this, symmetry, change (a * b⁻¹ : α) = n / d, rw [eq_div_iff_mul_eq _ _ d0, mul_assoc, nat.mul_cast_comm, ← mul_assoc, this, mul_assoc, mul_inv_cancel b0, mul_one] end @[move_cast] theorem cast_add_of_ne_zero : ∀ {m n : ℚ}, (m.denom : α) ≠ 0 → (n.denom : α) ≠ 0 → ((m + n : ℚ) : α) = m + n | ⟨n₁, d₁, h₁, c₁⟩ ⟨n₂, d₂, h₂, c₂⟩ := λ (d₁0 : (d₁:α) ≠ 0) (d₂0 : (d₂:α) ≠ 0), begin have d₁0' : (d₁:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d₁0; exact d₁0 rfl), have d₂0' : (d₂:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d₂0; exact d₂0 rfl), rw [num_denom', num_denom', add_def d₁0' d₂0'], suffices : (n₁ * (d₂ * (d₂⁻¹ * d₁⁻¹)) + n₂ * (d₁ * d₂⁻¹) * d₁⁻¹ : α) = n₁ * d₁⁻¹ + n₂ * d₂⁻¹, { rw [cast_mk_of_ne_zero, cast_mk_of_ne_zero, cast_mk_of_ne_zero], { simpa [division_def, left_distrib, right_distrib, mul_inv_eq, d₁0, d₂0, division_ring.mul_ne_zero d₁0 d₂0, mul_assoc] }, all_goals {simp [d₁0, d₂0, division_ring.mul_ne_zero d₁0 d₂0]} }, rw [← mul_assoc (d₂:α), mul_inv_cancel d₂0, one_mul, ← nat.mul_cast_comm], simp [d₁0, mul_assoc] end @[simp, move_cast] theorem cast_neg : ∀ n, ((-n : ℚ) : α) = -n | ⟨n, d, h, c⟩ := show (↑-n * d⁻¹ : α) = -(n * d⁻¹), by rw [int.cast_neg, neg_mul_eq_neg_mul] @[move_cast] theorem cast_sub_of_ne_zero {m n : ℚ} (m0 : (m.denom : α) ≠ 0) (n0 : (n.denom : α) ≠ 0) : ((m - n : ℚ) : α) = m - n := have ((-n).denom : α) ≠ 0, by cases n; exact n0, by simp [(cast_add_of_ne_zero m0 this)] @[move_cast] theorem cast_mul_of_ne_zero : ∀ {m n : ℚ}, (m.denom : α) ≠ 0 → (n.denom : α) ≠ 0 → ((m * n : ℚ) : α) = m * n | ⟨n₁, d₁, h₁, c₁⟩ ⟨n₂, d₂, h₂, c₂⟩ := λ (d₁0 : (d₁:α) ≠ 0) (d₂0 : (d₂:α) ≠ 0), begin have d₁0' : (d₁:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d₁0; exact d₁0 rfl), have d₂0' : (d₂:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d₂0; exact d₂0 rfl), rw [num_denom', num_denom', mul_def d₁0' d₂0'], suffices : (n₁ * ((n₂ * d₂⁻¹) * d₁⁻¹) : α) = n₁ * (d₁⁻¹ * (n₂ * d₂⁻¹)), { rw [cast_mk_of_ne_zero, cast_mk_of_ne_zero, cast_mk_of_ne_zero], { simpa [division_def, mul_inv_eq, d₁0, d₂0, division_ring.mul_ne_zero d₁0 d₂0, mul_assoc] }, all_goals {simp [d₁0, d₂0, division_ring.mul_ne_zero d₁0 d₂0]} }, rw [division_ring.inv_comm_of_comm d₁0 (nat.mul_cast_comm _ _).symm] end @[move_cast] theorem cast_inv_of_ne_zero : ∀ {n : ℚ}, (n.num : α) ≠ 0 → (n.denom : α) ≠ 0 → ((n⁻¹ : ℚ) : α) = n⁻¹ | ⟨n, d, h, c⟩ := λ (n0 : (n:α) ≠ 0) (d0 : (d:α) ≠ 0), begin have n0' : (n:ℤ) ≠ 0 := λ e, by rw e at n0; exact n0 rfl, have d0' : (d:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d0; exact d0 rfl), rw [num_denom', inv_def], rw [cast_mk_of_ne_zero, cast_mk_of_ne_zero, inv_div]; simp [n0, d0] end @[move_cast] theorem cast_div_of_ne_zero {m n : ℚ} (md : (m.denom : α) ≠ 0) (nn : (n.num : α) ≠ 0) (nd : (n.denom : α) ≠ 0) : ((m / n : ℚ) : α) = m / n := have (n⁻¹.denom : ℤ) ∣ n.num, by conv in n⁻¹.denom { rw [←(@num_denom n), inv_def] }; apply denom_dvd, have (n⁻¹.denom : α) = 0 → (n.num : α) = 0, from λ h, let ⟨k, e⟩ := this in by have := congr_arg (coe : ℤ → α) e; rwa [int.cast_mul, int.cast_coe_nat, h, zero_mul] at this, by rw [division_def, cast_mul_of_ne_zero md (mt this nn), cast_inv_of_ne_zero nn nd, division_def] @[simp, elim_cast] theorem cast_inj [char_zero α] : ∀ {m n : ℚ}, (m : α) = n ↔ m = n | ⟨n₁, d₁, h₁, c₁⟩ ⟨n₂, d₂, h₂, c₂⟩ := begin refine ⟨λ h, _, congr_arg _⟩, have d₁0 : d₁ ≠ 0 := ne_of_gt h₁, have d₂0 : d₂ ≠ 0 := ne_of_gt h₂, have d₁a : (d₁:α) ≠ 0 := nat.cast_ne_zero.2 d₁0, have d₂a : (d₂:α) ≠ 0 := nat.cast_ne_zero.2 d₂0, rw [num_denom', num_denom'] at h ⊢, rw [cast_mk_of_ne_zero, cast_mk_of_ne_zero] at h; simp [d₁0, d₂0] at h ⊢, rwa [eq_div_iff_mul_eq _ _ d₂a, division_def, mul_assoc, division_ring.inv_comm_of_comm d₁a (nat.mul_cast_comm _ _), ← mul_assoc, ← division_def, eq_comm, eq_div_iff_mul_eq _ _ d₁a, eq_comm, ← int.cast_coe_nat, ← int.cast_mul, ← int.cast_coe_nat, ← int.cast_mul, int.cast_inj, ← mk_eq (int.coe_nat_ne_zero.2 d₁0) (int.coe_nat_ne_zero.2 d₂0)] at h end theorem cast_injective [char_zero α] : function.injective (coe : ℚ → α) | m n := cast_inj.1 @[simp] theorem cast_eq_zero [char_zero α] {n : ℚ} : (n : α) = 0 ↔ n = 0 := by rw [← cast_zero, cast_inj] @[simp] theorem cast_ne_zero [char_zero α] {n : ℚ} : (n : α) ≠ 0 ↔ n ≠ 0 := not_congr cast_eq_zero theorem eq_cast_of_ne_zero (f : ℚ → α) (H1 : f 1 = 1) (Hadd : ∀ x y, f (x + y) = f x + f y) (Hmul : ∀ x y, f (x * y) = f x * f y) : ∀ n : ℚ, (n.denom : α) ≠ 0 → f n = n | ⟨n, d, h, c⟩ := λ (h₂ : ((d:ℤ):α) ≠ 0), show _ = (n / (d:ℤ) : α), begin rw [num_denom', mk_eq_div, eq_div_iff_mul_eq _ _ h₂], have : ∀ n : ℤ, f n = n, { apply int.eq_cast; simp [H1, Hadd] }, rw [← this, ← this, ← Hmul, div_mul_cancel], exact int.cast_ne_zero.2 (int.coe_nat_ne_zero.2 $ ne_of_gt h), end theorem eq_cast [char_zero α] (f : ℚ → α) (H1 : f 1 = 1) (Hadd : ∀ x y, f (x + y) = f x + f y) (Hmul : ∀ x y, f (x * y) = f x * f y) (n : ℚ) : f n = n := eq_cast_of_ne_zero _ H1 Hadd Hmul _ $ nat.cast_ne_zero.2 $ ne_of_gt n.pos end with_div_ring @[move_cast] theorem cast_mk [discrete_field α] [char_zero α] (a b : ℤ) : ((a /. b) : α) = a / b := if b0 : b = 0 then by simp [b0, div_zero] else cast_mk_of_ne_zero a b (int.cast_ne_zero.2 b0) @[simp, move_cast] theorem cast_add [division_ring α] [char_zero α] (m n) : ((m + n : ℚ) : α) = m + n := cast_add_of_ne_zero (nat.cast_ne_zero.2 $ ne_of_gt m.pos) (nat.cast_ne_zero.2 $ ne_of_gt n.pos) @[simp, move_cast] theorem cast_sub [division_ring α] [char_zero α] (m n) : ((m - n : ℚ) : α) = m - n := cast_sub_of_ne_zero (nat.cast_ne_zero.2 $ ne_of_gt m.pos) (nat.cast_ne_zero.2 $ ne_of_gt n.pos) @[simp, move_cast] theorem cast_mul [division_ring α] [char_zero α] (m n) : ((m * n : ℚ) : α) = m * n := cast_mul_of_ne_zero (nat.cast_ne_zero.2 $ ne_of_gt m.pos) (nat.cast_ne_zero.2 $ ne_of_gt n.pos) @[simp, move_cast] theorem cast_inv [discrete_field α] [char_zero α] (n) : ((n⁻¹ : ℚ) : α) = n⁻¹ := if n0 : n.num = 0 then by simp [show n = 0, by rw [←(@num_denom n), n0]; simp, inv_zero] else cast_inv_of_ne_zero (int.cast_ne_zero.2 n0) (nat.cast_ne_zero.2 $ ne_of_gt n.pos) @[simp, move_cast] theorem cast_div [discrete_field α] [char_zero α] (m n) : ((m / n : ℚ) : α) = m / n := by rw [division_def, cast_mul, cast_inv, division_def] @[simp, move_cast] theorem cast_pow [discrete_field α] [char_zero α] (q) (k : ℕ) : ((q ^ k : ℚ) : α) = q ^ k := by induction k; simp only [*, cast_one, cast_mul, pow_zero, pow_succ] @[simp, squash_cast, move_cast] theorem cast_bit0 [division_ring α] [char_zero α] (n : ℚ) : ((bit0 n : ℚ) : α) = bit0 n := cast_add _ _ @[simp, squash_cast, move_cast] theorem cast_bit1 [division_ring α] [char_zero α] (n : ℚ) : ((bit1 n : ℚ) : α) = bit1 n := by rw [bit1, cast_add, cast_one, cast_bit0]; refl @[simp] theorem cast_nonneg [linear_ordered_field α] : ∀ {n : ℚ}, 0 ≤ (n : α) ↔ 0 ≤ n | ⟨n, d, h, c⟩ := show 0 ≤ (n * d⁻¹ : α) ↔ 0 ≤ (⟨n, d, h, c⟩ : ℚ), by rw [num_denom', ← nonneg_iff_zero_le, mk_nonneg _ (int.coe_nat_pos.2 h), mul_nonneg_iff_right_nonneg_of_pos (@inv_pos α _ _ (nat.cast_pos.2 h)), int.cast_nonneg] @[simp, elim_cast] theorem cast_le [linear_ordered_field α] {m n : ℚ} : (m : α) ≤ n ↔ m ≤ n := by rw [← sub_nonneg, ← cast_sub, cast_nonneg, sub_nonneg] @[simp, elim_cast] theorem cast_lt [linear_ordered_field α] {m n : ℚ} : (m : α) < n ↔ m < n := by simpa [-cast_le] using not_congr (@cast_le α _ n m) @[simp] theorem cast_nonpos [linear_ordered_field α] {n : ℚ} : (n : α) ≤ 0 ↔ n ≤ 0 := by rw [← cast_zero, cast_le] @[simp] theorem cast_pos [linear_ordered_field α] {n : ℚ} : (0 : α) < n ↔ 0 < n := by rw [← cast_zero, cast_lt] @[simp] theorem cast_lt_zero [linear_ordered_field α] {n : ℚ} : (n : α) < 0 ↔ n < 0 := by rw [← cast_zero, cast_lt] @[simp, squash_cast] theorem cast_id : ∀ n : ℚ, ↑n = n | ⟨n, d, h, c⟩ := show (n / (d : ℤ) : ℚ) = _, by rw [num_denom', mk_eq_div] @[simp, move_cast] theorem cast_min [discrete_linear_ordered_field α] {a b : ℚ} : (↑(min a b) : α) = min a b := by by_cases a ≤ b; simp [h, min] @[simp, move_cast] theorem cast_max [discrete_linear_ordered_field α] {a b : ℚ} : (↑(max a b) : α) = max a b := by by_cases a ≤ b; simp [h, max] @[simp, move_cast] theorem cast_abs [discrete_linear_ordered_field α] {q : ℚ} : ((abs q : ℚ) : α) = abs q := by simp [abs] end rat
b44f84926d1f04a6ab17100de2d86426a8f5c720
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/run/lambda_simp.lean
280639ecf2421c38f0f31b72d687e431796f9c1b
[ "Apache-2.0" ]
permissive
leanprover-community/lean
12b87f69d92e614daea8bcc9d4de9a9ace089d0e
cce7990ea86a78bdb383e38ed7f9b5ba93c60ce0
refs/heads/master
1,687,508,156,644
1,684,951,104,000
1,684,951,104,000
169,960,991
457
107
Apache-2.0
1,686,744,372,000
1,549,790,268,000
C++
UTF-8
Lean
false
false
162
lean
#print [simp] default constant addz (a : nat) : 0 + a = a attribute [simp] addz open tactic def ex : (λ a b : nat, 0 + a) = (λ a b, a) := by simp #print ex
384dca18efcea38d5262312998f10c8c3b7be6b0
592ee40978ac7604005a4e0d35bbc4b467389241
/Library/generated/mathscheme-lean/Monoid.lean
9b44b32f26a06e06cbb82247607a43b12d7f06df
[]
no_license
ysharoda/Deriving-Definitions
3e149e6641fae440badd35ac110a0bd705a49ad2
dfecb27572022de3d4aa702cae8db19957523a59
refs/heads/master
1,679,127,857,700
1,615,939,007,000
1,615,939,007,000
229,785,731
4
0
null
null
null
null
UTF-8
Lean
false
false
6,685
lean
import init.data.nat.basic import init.data.fin.basic import data.vector import .Prelude open Staged open nat open fin open vector section Monoid structure Monoid (A : Type) : Type := (op : (A → (A → A))) (e : A) (lunit_e : (∀ {x : A} , (op e x) = x)) (runit_e : (∀ {x : A} , (op x e) = x)) (associative_op : (∀ {x y z : A} , (op (op x y) z) = (op x (op y z)))) open Monoid structure Sig (AS : Type) : Type := (opS : (AS → (AS → AS))) (eS : AS) structure Product (A : Type) : Type := (opP : ((Prod A A) → ((Prod A A) → (Prod A A)))) (eP : (Prod A A)) (lunit_eP : (∀ {xP : (Prod A A)} , (opP eP xP) = xP)) (runit_eP : (∀ {xP : (Prod A A)} , (opP xP eP) = xP)) (associative_opP : (∀ {xP yP zP : (Prod A A)} , (opP (opP xP yP) zP) = (opP xP (opP yP zP)))) structure Hom {A1 : Type} {A2 : Type} (Mo1 : (Monoid A1)) (Mo2 : (Monoid A2)) : Type := (hom : (A1 → A2)) (pres_op : (∀ {x1 x2 : A1} , (hom ((op Mo1) x1 x2)) = ((op Mo2) (hom x1) (hom x2)))) (pres_e : (hom (e Mo1)) = (e Mo2)) structure RelInterp {A1 : Type} {A2 : Type} (Mo1 : (Monoid A1)) (Mo2 : (Monoid A2)) : Type 1 := (interp : (A1 → (A2 → Type))) (interp_op : (∀ {x1 x2 : A1} {y1 y2 : A2} , ((interp x1 y1) → ((interp x2 y2) → (interp ((op Mo1) x1 x2) ((op Mo2) y1 y2)))))) (interp_e : (interp (e Mo1) (e Mo2))) inductive MonoidTerm : Type | opL : (MonoidTerm → (MonoidTerm → MonoidTerm)) | eL : MonoidTerm open MonoidTerm inductive ClMonoidTerm (A : Type) : Type | sing : (A → ClMonoidTerm) | opCl : (ClMonoidTerm → (ClMonoidTerm → ClMonoidTerm)) | eCl : ClMonoidTerm open ClMonoidTerm inductive OpMonoidTerm (n : ℕ) : Type | v : ((fin n) → OpMonoidTerm) | opOL : (OpMonoidTerm → (OpMonoidTerm → OpMonoidTerm)) | eOL : OpMonoidTerm open OpMonoidTerm inductive OpMonoidTerm2 (n : ℕ) (A : Type) : Type | v2 : ((fin n) → OpMonoidTerm2) | sing2 : (A → OpMonoidTerm2) | opOL2 : (OpMonoidTerm2 → (OpMonoidTerm2 → OpMonoidTerm2)) | eOL2 : OpMonoidTerm2 open OpMonoidTerm2 def simplifyCl {A : Type} : ((ClMonoidTerm A) → (ClMonoidTerm A)) | (opCl eCl x) := x | (opCl x eCl) := x | (opCl x1 x2) := (opCl (simplifyCl x1) (simplifyCl x2)) | eCl := eCl | (sing x1) := (sing x1) def simplifyOpB {n : ℕ} : ((OpMonoidTerm n) → (OpMonoidTerm n)) | (opOL eOL x) := x | (opOL x eOL) := x | (opOL x1 x2) := (opOL (simplifyOpB x1) (simplifyOpB x2)) | eOL := eOL | (v x1) := (v x1) def simplifyOp {n : ℕ} {A : Type} : ((OpMonoidTerm2 n A) → (OpMonoidTerm2 n A)) | (opOL2 eOL2 x) := x | (opOL2 x eOL2) := x | (opOL2 x1 x2) := (opOL2 (simplifyOp x1) (simplifyOp x2)) | eOL2 := eOL2 | (v2 x1) := (v2 x1) | (sing2 x1) := (sing2 x1) def evalB {A : Type} : ((Monoid A) → (MonoidTerm → A)) | Mo (opL x1 x2) := ((op Mo) (evalB Mo x1) (evalB Mo x2)) | Mo eL := (e Mo) def evalCl {A : Type} : ((Monoid A) → ((ClMonoidTerm A) → A)) | Mo (sing x1) := x1 | Mo (opCl x1 x2) := ((op Mo) (evalCl Mo x1) (evalCl Mo x2)) | Mo eCl := (e Mo) def evalOpB {A : Type} {n : ℕ} : ((Monoid A) → ((vector A n) → ((OpMonoidTerm n) → A))) | Mo vars (v x1) := (nth vars x1) | Mo vars (opOL x1 x2) := ((op Mo) (evalOpB Mo vars x1) (evalOpB Mo vars x2)) | Mo vars eOL := (e Mo) def evalOp {A : Type} {n : ℕ} : ((Monoid A) → ((vector A n) → ((OpMonoidTerm2 n A) → A))) | Mo vars (v2 x1) := (nth vars x1) | Mo vars (sing2 x1) := x1 | Mo vars (opOL2 x1 x2) := ((op Mo) (evalOp Mo vars x1) (evalOp Mo vars x2)) | Mo vars eOL2 := (e Mo) def inductionB {P : (MonoidTerm → Type)} : ((∀ (x1 x2 : MonoidTerm) , ((P x1) → ((P x2) → (P (opL x1 x2))))) → ((P eL) → (∀ (x : MonoidTerm) , (P x)))) | popl pel (opL x1 x2) := (popl _ _ (inductionB popl pel x1) (inductionB popl pel x2)) | popl pel eL := pel def inductionCl {A : Type} {P : ((ClMonoidTerm A) → Type)} : ((∀ (x1 : A) , (P (sing x1))) → ((∀ (x1 x2 : (ClMonoidTerm A)) , ((P x1) → ((P x2) → (P (opCl x1 x2))))) → ((P eCl) → (∀ (x : (ClMonoidTerm A)) , (P x))))) | psing popcl pecl (sing x1) := (psing x1) | psing popcl pecl (opCl x1 x2) := (popcl _ _ (inductionCl psing popcl pecl x1) (inductionCl psing popcl pecl x2)) | psing popcl pecl eCl := pecl def inductionOpB {n : ℕ} {P : ((OpMonoidTerm n) → Type)} : ((∀ (fin : (fin n)) , (P (v fin))) → ((∀ (x1 x2 : (OpMonoidTerm n)) , ((P x1) → ((P x2) → (P (opOL x1 x2))))) → ((P eOL) → (∀ (x : (OpMonoidTerm n)) , (P x))))) | pv popol peol (v x1) := (pv x1) | pv popol peol (opOL x1 x2) := (popol _ _ (inductionOpB pv popol peol x1) (inductionOpB pv popol peol x2)) | pv popol peol eOL := peol def inductionOp {n : ℕ} {A : Type} {P : ((OpMonoidTerm2 n A) → Type)} : ((∀ (fin : (fin n)) , (P (v2 fin))) → ((∀ (x1 : A) , (P (sing2 x1))) → ((∀ (x1 x2 : (OpMonoidTerm2 n A)) , ((P x1) → ((P x2) → (P (opOL2 x1 x2))))) → ((P eOL2) → (∀ (x : (OpMonoidTerm2 n A)) , (P x)))))) | pv2 psing2 popol2 peol2 (v2 x1) := (pv2 x1) | pv2 psing2 popol2 peol2 (sing2 x1) := (psing2 x1) | pv2 psing2 popol2 peol2 (opOL2 x1 x2) := (popol2 _ _ (inductionOp pv2 psing2 popol2 peol2 x1) (inductionOp pv2 psing2 popol2 peol2 x2)) | pv2 psing2 popol2 peol2 eOL2 := peol2 def stageB : (MonoidTerm → (Staged MonoidTerm)) | (opL x1 x2) := (stage2 opL (codeLift2 opL) (stageB x1) (stageB x2)) | eL := (Now eL) def stageCl {A : Type} : ((ClMonoidTerm A) → (Staged (ClMonoidTerm A))) | (sing x1) := (Now (sing x1)) | (opCl x1 x2) := (stage2 opCl (codeLift2 opCl) (stageCl x1) (stageCl x2)) | eCl := (Now eCl) def stageOpB {n : ℕ} : ((OpMonoidTerm n) → (Staged (OpMonoidTerm n))) | (v x1) := (const (code (v x1))) | (opOL x1 x2) := (stage2 opOL (codeLift2 opOL) (stageOpB x1) (stageOpB x2)) | eOL := (Now eOL) def stageOp {n : ℕ} {A : Type} : ((OpMonoidTerm2 n A) → (Staged (OpMonoidTerm2 n A))) | (sing2 x1) := (Now (sing2 x1)) | (v2 x1) := (const (code (v2 x1))) | (opOL2 x1 x2) := (stage2 opOL2 (codeLift2 opOL2) (stageOp x1) (stageOp x2)) | eOL2 := (Now eOL2) structure StagedRepr (A : Type) (Repr : (Type → Type)) : Type := (opT : ((Repr A) → ((Repr A) → (Repr A)))) (eT : (Repr A)) end Monoid
88bb33c04951a9ed1ba6aa460ece052b0613fa20
968e2f50b755d3048175f176376eff7139e9df70
/examples/prop_logic_theory/unnamed_1924.lean
e388584a231fc694da6284eb1fe723df321a3c28
[]
no_license
gihanmarasingha/mth1001_sphinx
190a003269ba5e54717b448302a27ca26e31d491
05126586cbf5786e521be1ea2ef5b4ba3c44e74a
refs/heads/master
1,672,913,933,677
1,604,516,583,000
1,604,516,583,000
309,245,750
1
0
null
null
null
null
UTF-8
Lean
false
false
320
lean
variables {p q r : Prop} namespace hidden -- BEGIN theorem or_assoc : (p ∨ q) ∨ r ↔ p ∨ (q ∨ r) := begin split, { intro h, cases h with h₁ h₂, { cases h₁ with m₁ m₂, { left, exact m₁, }, { right, left, exact m₂, }, }, { sorry, }, }, { sorry, }, end -- END end hidden
61acf29f7adcfffd7c845e898600e9dd931a77c7
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
/tests/lean/utf8.lean
89c5f39565e555b73b5f51758fe6c005d4a4c5c9
[ "Apache-2.0" ]
permissive
soonhokong/lean-osx
4a954262c780e404c1369d6c06516161d07fcb40
3670278342d2f4faa49d95b46d86642d7875b47c
refs/heads/master
1,611,410,334,552
1,474,425,686,000
1,474,425,686,000
12,043,103
5
1
null
null
null
null
UTF-8
Lean
false
false
259
lean
open list vm_eval length "α₁" vm_eval length "α₁ → β₁" vm_eval length "∀ α : nat → nat, α 0 ≥ 0" print "------------" vm_eval utf8_length "α₁" vm_eval utf8_length "α₁ → β₁" vm_eval utf8_length "∀ α : nat → nat, α 0 ≥ 0"
bcaa60dd4067c40ee8f2b51d7a97aa166f67a8cf
9dc8cecdf3c4634764a18254e94d43da07142918
/src/topology/uniform_space/uniform_convergence_topology.lean
92fdd99b70693c1f7ca6366d2a378854a1ed4312
[ "Apache-2.0" ]
permissive
jcommelin/mathlib
d8456447c36c176e14d96d9e76f39841f69d2d9b
ee8279351a2e434c2852345c51b728d22af5a156
refs/heads/master
1,664,782,136,488
1,663,638,983,000
1,663,638,983,000
132,563,656
0
0
Apache-2.0
1,663,599,929,000
1,525,760,539,000
Lean
UTF-8
Lean
false
false
39,683
lean
/- Copyright (c) 2022 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import topology.uniform_space.uniform_convergence import topology.uniform_space.pi import topology.uniform_space.equiv /-! # Topology and uniform structure of uniform convergence This files endows `α → β` with the topologies / uniform structures of - uniform convergence on `α` (in the `uniform_convergence` namespace) - uniform convergence on a specified family `𝔖` of sets of `α` (in the `uniform_convergence_on` namespace), also called `𝔖`-convergence Usual examples of the second construction include : - the topology of compact convergence, when `𝔖` is the set of compacts of `α` - the strong topology on the dual of a topological vector space (TVS) `E`, when `𝔖` is the set of Von Neuman bounded subsets of `E` - the weak-* topology on the dual of a TVS `E`, when `𝔖` is the set of singletons of `E`. This file contains a lot of technical facts, so it is heavily commented, proofs included! ## Main definitions * `uniform_convergence.gen`: basis sets for the uniformity of uniform convergence. These are sets of the form `S(V) := {(f, g) | ∀ x : α, (f x, g x) ∈ V}` for some `V : set (β × β)` * `uniform_convergence.uniform_space`: uniform structure of uniform convergence. This is the `uniform_space` on `α → β` whose uniformity is generated by the sets `S(V)` for `V ∈ 𝓤 β`. We will denote this uniform space as `𝒰(α, β, uβ)`, both in the comments and as a local notation in the Lean code, where `uβ` is the uniform space structure on `β`. * `uniform_convergence_on.uniform_space`: uniform structure of 𝔖-convergence, where `𝔖 : set (set α)`. This is the infimum, for `S ∈ 𝔖`, of the pullback of `𝒰 S β` by the map of restriction to `S`. We will denote it `𝒱(α, β, 𝔖, uβ)`, where `uβ` is the uniform space structure on `β`. ## Main statements ### Basic properties * `uniform_convergence.uniform_continuous_eval`: evaluation is uniformly continuous for `𝒰(α, uβ)`. * `uniform_convergence.t2_space`: the topology of uniform convergence on `α → β` is T₂ if `β` is T₂. * `uniform_convergence.tendsto_iff_tendsto_uniformly`: `𝒰(α, β, uβ)` is indeed the uniform structure of uniform convergence * `uniform_convergence_on.uniform_continuous_eval_of_mem`: evaluation at a point contained in a set of `𝔖` is uniformly continuous for `𝒱(α, β, 𝔖 uβ)` * `uniform_convergence.t2_space`: the topology of `𝔖`-convergence on `α → β` is T₂ if `β` is T₂ and `𝔖` covers `α` * `uniform_convergence_on.tendsto_iff_tendsto_uniformly_on`: `𝒱(α, β, 𝔖 uβ)` is indeed the uniform structure of `𝔖`-convergence ### Functoriality and compatibility with product of uniform spaces In order to avoid the need for filter bases as much as possible when using these definitions, we develop an extensive API for manipulating these structures abstractly. As usual in the topology section of mathlib, we first state results about the complete lattices of `uniform_space`s on fixed types, and then we use these to deduce categorical-like results about maps between two uniform spaces. We only describe these in the harder case of `𝔖`-convergence, as the names of the corresponding results for uniform convergence can easily be guessed. #### Order statements * `uniform_convergence_on.mono`: let `u₁`, `u₂` be two uniform structures on `γ` and `𝔖₁ 𝔖₂ : set (set α)`. If `u₁ ≤ u₂` and `𝔖₂ ⊆ 𝔖₁` then `𝒱(α, γ, 𝔖₁, u₁) ≤ 𝒱(α, γ, 𝔖₂, u₂)`. * `uniform_convergence_on.infi_eq`: if `u` is a family of uniform structures on `γ`, then `𝒱(α, γ, 𝔖, (⨅ i, u i)) = ⨅ i, 𝒱(α, γ, 𝔖, u i)`. * `uniform_convergence_on.comap_eq`: if `u` is a uniform structures on `β` and `f : γ → β`, then `𝒱(α, γ, 𝔖, comap f u) = comap (λ g, f ∘ g) 𝒱(α, γ, 𝔖, u₁)`. An interesting note about these statements is that they are proved without ever unfolding the basis definition of the uniform structure of uniform convergence! Instead, we build a (not very interesting) Galois connection `uniform_convergence.gc` and then rely on the Galois connection API to do most of the work. #### Morphism statements (unbundled) * `uniform_convergence_on.postcomp_uniform_continuous`: if `f : (γ, uγ) → (β, uβ)` is uniformly continuous, then `(λ g, f ∘ g) : (α → γ, 𝒱(α, γ, 𝔖, uγ)) → (α → β, 𝒱(α, β, 𝔖, uβ))` is uniformly continuous. * `uniform_convergence_on.postcomp_uniform_inducing`: if `f : (γ, uγ) → (β, uβ)` is a uniform inducing, then `(λ g, f ∘ g) : (α → γ, 𝒱(α, γ, 𝔖, uγ)) → (α → β, 𝒱(α, β, 𝔖, uβ))` is a uniform inducing. * `uniform_convergence_on.precomp_uniform_continuous`: let `f : γ → α`, `𝔖 : set (set α)`, `𝔗 : set (set γ)`, and assume that `∀ T ∈ 𝔗, f '' T ∈ 𝔖`. Then, the function `(λ g, g ∘ f) : (α → β, 𝒱(α, β, 𝔖, uβ)) → (γ → β, 𝒱(γ, β, 𝔗 uβ))` is uniformly continuous. #### Isomorphism statements (bundled) * `uniform_convergence_on.congr_right`: turn a uniform isomorphism `(γ, uγ) ≃ᵤ (β, uβ)` into a uniform isomorphism `(α → γ, 𝒱(α, γ, 𝔖, uγ)) ≃ᵤ (α → β, 𝒱(α, β, 𝔖, uβ))` by post-composing. * `uniform_convergence_on.congr_left`: turn a bijection `e : γ ≃ α` such that we have both `∀ T ∈ 𝔗, e '' T ∈ 𝔖` and `∀ S ∈ 𝔖, e ⁻¹' S ∈ 𝔗` into a uniform isomorphism `(γ → β, 𝒰(γ, β, uβ)) ≃ᵤ (α → β, 𝒰(α, β, uβ))` by pre-composing. * `uniform_convergence_on.uniform_equiv_Pi_comm`: the natural bijection between `α → Π i, δ i` and `Π i, α → δ i`, upgraded to a uniform isomorphism between `(α → (Π i, δ i), 𝒱(α, (Π i, δ i), 𝔖, (Π i, uδ i)))` and `((Π i, α → δ i), (Π i, 𝒱(α, δ i, 𝔖, uδ i)))`. #### Important use cases * If `(G, uG)` is a uniform group, then `(α → G, 𝒱(α, G, 𝔖, uG))` is a uniform group: since `(/) : G × G → G` is uniformly continuous, `uniform_convergence_on.postcomp_uniform_continuous` tells us that `((/) ∘ —) : (α → G × G) → (α → G)` is uniformly continuous. By precomposing with `uniform_convergence_on.uniform_equiv_prod_arrow`, this gives that `(/) : (α → G) × (α → G) → (α → G)` is also uniformly continuous * The transpose of a continuous linear map is continuous for the strong topologies: since continuous linear maps are uniformly continuous and map bounded sets to bounded sets, this is just a special case of `uniform_convergence_on.precomp_uniform_continuous`. ## Implementation details We do not declare these structures as instances, since they would conflict with `Pi.uniform_space`. ## TODO * Show that the uniform structure of `𝔖`-convergence is exactly the structure of `𝔖'`-convergence, where `𝔖'` is the ***noncovering*** bornology (i.e ***not*** what `bornology` currently refers to in mathlib) generated by `𝔖`. * Add a type synonym for `α → β` endowed with the structures of uniform convergence? ## References * [N. Bourbaki, *General Topology, Chapter X*][bourbaki1966] ## Tags uniform convergence -/ noncomputable theory open_locale topological_space classical uniformity filter local attribute [-instance] Pi.uniform_space local attribute [-instance] Pi.topological_space open set filter namespace uniform_convergence variables (α β : Type*) {γ ι : Type*} variables {F : ι → α → β} {f : α → β} {s s' : set α} {x : α} {p : filter ι} {g : ι → α} /-- Basis sets for the uniformity of uniform convergence: `gen α β V` is the set of pairs `(f, g)` of functions `α → β` such that `∀ x, (f x, g x) ∈ V`. -/ protected def gen (V : set (β × β)) : set ((α → β) × (α → β)) := {uv : (α → β) × (α → β) | ∀ x, (uv.1 x, uv.2 x) ∈ V} /-- If `𝓕` is a filter on `β × β`, then the set of all `uniform_convergence.gen α β V` for `V ∈ 𝓕` is too. This will only be applied to `𝓕 = 𝓤 β` when `β` is equipped with a `uniform_space` structure, but it is useful to define it for any filter in order to be able to state that it has a lower adjoint (see `uniform_convergence.gc`). -/ protected lemma is_basis_gen (𝓑 : filter $ β × β) : is_basis (λ V : set (β × β), V ∈ 𝓑) (uniform_convergence.gen α β) := ⟨⟨univ, univ_mem⟩, λ U V hU hV, ⟨U ∩ V, inter_mem hU hV, λ uv huv, ⟨λ x, (huv x).left, λ x, (huv x).right⟩⟩⟩ /-- For `𝓕 : filter (β × β)`, this is the set of all `uniform_convergence.gen α β V` for `V ∈ 𝓕` is as a bundled `filter_basis`. This will only be applied to `𝓕 = 𝓤 β` when `β` is equipped with a `uniform_space` structure, but it is useful to define it for any filter in order to be able to state that it has a lower adjoint (see `uniform_convergence.gc`). -/ protected def basis (𝓕 : filter $ β × β) : filter_basis ((α → β) × (α → β)) := (uniform_convergence.is_basis_gen α β 𝓕).filter_basis /-- For `𝓕 : filter (β × β)`, this is the filter generated by the filter basis `uniform_convergence.basis α β 𝓕`. For `𝓕 = 𝓤 β`, this will be the uniformity of uniform convergence on `α`. -/ protected def filter (𝓕 : filter $ β × β) : filter ((α → β) × (α → β)) := (uniform_convergence.basis α β 𝓕).filter local notation `Φ` := λ (α β : Type*) (uvx : ((α → β) × (α → β)) × α), (uvx.1.1 uvx.2, uvx.1.2 uvx.2) /- This is a lower adjoint to `uniform_convergence.filter` (see `uniform_convergence.gc`). The exact definition of the lower adjoint `l` is not interesting; we will only use that it exists (in `uniform_convergence.mono` and `uniform_convergence.infi_eq`) and that `l (filter.map (prod.map f f) 𝓕) = filter.map (prod.map ((∘) f) ((∘) f)) (l 𝓕)` for each `𝓕 : filter (γ × γ)` and `f : γ → α` (in `uniform_convergence.comap_eq`). -/ local notation `lower_adjoint` := λ 𝓐, map (Φ α β) (𝓐 ×ᶠ ⊤) /-- The function `uniform_convergence.filter α β : filter (β × β) → filter ((α → β) × (α → β))` has a lower adjoint `l` (in the sense of `galois_connection`). The exact definition of `l` is not interesting; we will only use that it exists (in `uniform_convergence.mono` and `uniform_convergence.infi_eq`) and that `l (filter.map (prod.map f f) 𝓕) = filter.map (prod.map ((∘) f) ((∘) f)) (l 𝓕)` for each `𝓕 : filter (γ × γ)` and `f : γ → α` (in `uniform_convergence.comap_eq`). -/ protected lemma gc : galois_connection lower_adjoint (λ 𝓕, uniform_convergence.filter α β 𝓕) := begin intros 𝓐 𝓕, symmetry, calc 𝓐 ≤ uniform_convergence.filter α β 𝓕 ↔ (uniform_convergence.basis α β 𝓕).sets ⊆ 𝓐.sets : by rw [uniform_convergence.filter, ← filter_basis.generate, sets_iff_generate] ... ↔ ∀ U ∈ 𝓕, uniform_convergence.gen α β U ∈ 𝓐 : image_subset_iff ... ↔ ∀ U ∈ 𝓕, {uv | ∀ x, (uv, x) ∈ {t : ((α → β) × (α → β)) × α | (t.1.1 t.2, t.1.2 t.2) ∈ U}} ∈ 𝓐 : iff.rfl ... ↔ ∀ U ∈ 𝓕, {uvx : ((α → β) × (α → β)) × α | (uvx.1.1 uvx.2, uvx.1.2 uvx.2) ∈ U} ∈ 𝓐 ×ᶠ (⊤ : filter α) : forall₂_congr (λ U hU, mem_prod_top.symm) ... ↔ lower_adjoint 𝓐 ≤ 𝓕 : iff.rfl, end variables [uniform_space β] /-- Core of the uniform structure of uniform convergence. -/ protected def uniform_core : uniform_space.core (α → β) := uniform_space.core.mk_of_basis (uniform_convergence.basis α β (𝓤 β)) (λ U ⟨V, hV, hVU⟩ f, hVU ▸ λ x, refl_mem_uniformity hV) (λ U ⟨V, hV, hVU⟩, hVU ▸ ⟨uniform_convergence.gen α β (prod.swap ⁻¹' V), ⟨prod.swap ⁻¹' V, tendsto_swap_uniformity hV, rfl⟩, λ uv huv x, huv x⟩) (λ U ⟨V, hV, hVU⟩, hVU ▸ let ⟨W, hW, hWV⟩ := comp_mem_uniformity_sets hV in ⟨uniform_convergence.gen α β W, ⟨W, hW, rfl⟩, λ uv ⟨w, huw, hwv⟩ x, hWV ⟨w x, by exact ⟨huw x, hwv x⟩⟩⟩) /-- Uniform structure of uniform convergence. We will denote it `𝒰(α, β, uβ)`. -/ protected def uniform_space : uniform_space (α → β) := uniform_space.of_core (uniform_convergence.uniform_core α β) local attribute [instance] uniform_convergence.uniform_space local notation `𝒰(`α`, `β`, `u`)` := @uniform_convergence.uniform_space α β u /-- By definition, the uniformity of `α → β` endowed with the structure of uniform convergence on `α` admits the family `{(f, g) | ∀ x, (f x, g x) ∈ V}` for `V ∈ 𝓤 β` as a filter basis. -/ protected lemma has_basis_uniformity : (𝓤 (α → β)).has_basis (λ V, V ∈ 𝓤 β) (uniform_convergence.gen α β) := (uniform_convergence.is_basis_gen α β (𝓤 β)).has_basis /-- Topology of uniform convergence. -/ protected def topological_space : topological_space (α → β) := (𝒰(α, β, infer_instance)).to_topological_space /-- If `α → β` is endowed with the topology of uniform convergence, `𝓝 f` admits the family `{g | ∀ x, (f x, g x) ∈ V}` for `V ∈ 𝓤 β` as a filter basis. -/ protected lemma has_basis_nhds : (𝓝 f).has_basis (λ V, V ∈ 𝓤 β) (λ V, {g | (f, g) ∈ uniform_convergence.gen α β V}) := nhds_basis_uniformity' (uniform_convergence.has_basis_uniformity α β) variables {α} /-- Evaluation at a fixed point is uniformly continuous for `𝒰(α, β, uβ)`. -/ lemma uniform_continuous_eval (x : α) : uniform_continuous (function.eval x : (α → β) → β) := begin change _ ≤ _, rw [map_le_iff_le_comap, (uniform_convergence.has_basis_uniformity α β).le_basis_iff ((𝓤 _).basis_sets.comap _)], exact λ U hU, ⟨U, hU, λ uv huv, huv x⟩ end variables {β} /-- If `u₁` and `u₂` are two uniform structures on `γ` and `u₁ ≤ u₂`, then `𝒰(α, γ, u₁) ≤ 𝒰(α, γ, u₂)`. -/ protected lemma mono : monotone (@uniform_convergence.uniform_space α γ) := λ u₁ u₂ hu, (uniform_convergence.gc α γ).monotone_u hu /-- If `u` is a family of uniform structures on `γ`, then `𝒰(α, γ, (⨅ i, u i)) = ⨅ i, 𝒰(α, γ, u i)`. -/ protected lemma infi_eq {u : ι → uniform_space γ} : (𝒰(α, γ, ⨅ i, u i)) = ⨅ i, 𝒰(α, γ, u i) := begin -- This follows directly from the fact that the upper adjoint in a Galois connection maps -- infimas to infimas. ext : 1, change uniform_convergence.filter α γ (@uniformity _ (⨅ i, u i)) = @uniformity _ (⨅ i, (𝒰(α, γ, u i))), rw [infi_uniformity', infi_uniformity'], exact (uniform_convergence.gc α γ).u_infi end /-- If `u₁` and `u₂` are two uniform structures on `γ`, then `𝒰(α, γ, u₁ ⊓ u₂) = 𝒰(α, γ, u₁) ⊓ 𝒰(α, γ, u₂)`. -/ protected lemma inf_eq {u₁ u₂ : uniform_space γ} : (𝒰(α, γ, u₁ ⊓ u₂)) = (𝒰(α, γ, u₁)) ⊓ (𝒰(α, γ, u₂)) := begin -- This follows directly from the fact that the upper adjoint in a Galois connection maps -- infimas to infimas. rw [inf_eq_infi, inf_eq_infi, uniform_convergence.infi_eq], refine infi_congr (λ i, _), cases i; refl end /-- If `u` is a uniform structures on `β` and `f : γ → β`, then `𝒰(α, γ, comap f u) = comap (λ g, f ∘ g) 𝒰(α, γ, u₁)`. -/ protected lemma comap_eq {f : γ → β} : (𝒰(α, γ, ‹uniform_space β›.comap f)) = (𝒰(α, β, _)).comap ((∘) f) := begin letI : uniform_space γ := ‹uniform_space β›.comap f, ext : 1, change (uniform_convergence.filter α γ ((𝓤 β).comap _)) = (uniform_convergence.filter α β ((𝓤 β))).comap _, -- We have the following four Galois connection which form a square diagram, and we want -- to show that the square of upper adjoints is commutative. The trick then is to use -- `galois_connection.u_comm_of_l_comm` to reduce it to commutativity of the lower adjoints, -- which is way easier to prove. have h₁ := filter.gc_map_comap (prod.map ((∘) f) ((∘) f)), have h₂ := filter.gc_map_comap (prod.map f f), have h₃ := uniform_convergence.gc α β, have h₄ := uniform_convergence.gc α γ, refine galois_connection.u_comm_of_l_comm h₁ h₂ h₃ h₄ (λ 𝓐, _), have : prod.map f f ∘ (Φ α γ) = (Φ α β) ∘ prod.map (prod.map ((∘) f) ((∘) f)) id, { ext; refl }, rw [map_comm this, ← prod_map_map_eq'], refl end /-- Post-composition by a uniformly continuous function is uniformly continuous for the uniform structures of uniform convergence. More precisely, if `f : (γ, uγ) → (β, uβ)` is uniformly continuous, then `(λ g, f ∘ g) : (α → γ, 𝒰(α, γ, uγ)) → (α → β, 𝒰(α, β, uβ))` is uniformly continuous. -/ protected lemma postcomp_uniform_continuous [uniform_space γ] {f : γ → β} (hf : uniform_continuous f): uniform_continuous ((∘) f : (α → γ) → α → β) := -- This is a direct consequence of `uniform_convergence.comap_eq` uniform_continuous_iff.mpr $ calc 𝒰(α, γ, _) ≤ 𝒰(α, γ, ‹uniform_space β›.comap f) : uniform_convergence.mono (uniform_continuous_iff.mp hf) ... = (𝒰(α, β, _)).comap ((∘) f) : uniform_convergence.comap_eq /-- Post-composition by a uniform inducing is a uniform inducing for the uniform structures of uniform convergence. More precisely, if `f : (γ, uγ) → (β, uβ)` is a uniform inducing, then `(λ g, f ∘ g) : (α → γ, 𝒰(α, γ, uγ)) → (α → β, 𝒰(α, β, uβ))` is a uniform inducing. -/ protected lemma postcomp_uniform_inducing [uniform_space γ] {f : γ → β} (hf : uniform_inducing f): uniform_inducing ((∘) f : (α → γ) → α → β) := -- This is a direct consequence of `uniform_convergence.comap_eq` begin split, replace hf : (𝓤 β).comap (prod.map f f) = _ := hf.comap_uniformity, change comap (prod.map ((∘) f) ((∘) f)) _ = _, rw [← uniformity_comap rfl] at ⊢ hf, congr, rw [← uniform_space_eq hf, uniform_convergence.comap_eq] end /-- Turn a uniform isomorphism `(γ, uγ) ≃ᵤ (β, uβ)` into a uniform isomorphism `(α → γ, 𝒰(α, γ, uγ)) ≃ᵤ (α → β, 𝒰(α, β, uβ))` by post-composing. -/ protected def congr_right [uniform_space γ] (e : γ ≃ᵤ β) : (α → γ) ≃ᵤ (α → β) := { uniform_continuous_to_fun := uniform_convergence.postcomp_uniform_continuous e.uniform_continuous, uniform_continuous_inv_fun := uniform_convergence.postcomp_uniform_continuous e.symm.uniform_continuous, .. equiv.Pi_congr_right (λ a, e.to_equiv) } /-- Pre-composition by a any function is uniformly continuous for the uniform structures of uniform convergence. More precisely, for any `f : γ → α`, the function `(λ g, g ∘ f) : (α → β, 𝒰(α, β, uβ)) → (γ → β, 𝒰(γ, β, uβ))` is uniformly continuous. -/ protected lemma precomp_uniform_continuous {f : γ → α} : uniform_continuous (λ g : α → β, g ∘ f) := begin -- Here we simply go back to filter bases. rw uniform_continuous_iff, change 𝓤 (α → β) ≤ (𝓤 (γ → β)).comap (prod.map (λ g : α → β, g ∘ f) (λ g : α → β, g ∘ f)), rw (uniform_convergence.has_basis_uniformity α β).le_basis_iff ((uniform_convergence.has_basis_uniformity γ β).comap _), exact λ U hU, ⟨U, hU, λ uv huv x, huv (f x)⟩ end /-- Turn a bijection `γ ≃ α` into a uniform isomorphism `(γ → β, 𝒰(γ, β, uβ)) ≃ᵤ (α → β, 𝒰(α, β, uβ))` by pre-composing. -/ protected def congr_left (e : γ ≃ α) : (γ → β) ≃ᵤ (α → β) := { uniform_continuous_to_fun := uniform_convergence.precomp_uniform_continuous, uniform_continuous_inv_fun := uniform_convergence.precomp_uniform_continuous, .. equiv.arrow_congr e (equiv.refl _) } /-- The topology of uniform convergence is T₂. -/ lemma t2_space [t2_space β] : t2_space (α → β) := { t2 := begin letI : uniform_space (α → β) := 𝒰(α, β, _), letI : topological_space (α → β) := uniform_convergence.topological_space α β, intros f g h, obtain ⟨x, hx⟩ := not_forall.mp (mt funext h), exact separated_by_continuous (uniform_continuous_eval β x).continuous hx end } /-- The uniform structure of uniform convergence is finer than that of pointwise convergence, aka the product uniform structure. -/ protected lemma le_Pi : 𝒰(α, β, _) ≤ Pi.uniform_space (λ _, β) := begin -- By definition of the product uniform structure, this is just `uniform_continuous_eval`. rw [le_iff_uniform_continuous_id, uniform_continuous_pi], intros x, exact uniform_continuous_eval β x end /-- The topology of uniform convergence indeed gives the same notion of convergence as `tendsto_uniformly`. -/ protected lemma tendsto_iff_tendsto_uniformly : tendsto F p (𝓝 f) ↔ tendsto_uniformly F f p := begin letI : uniform_space (α → β) := 𝒰(α, β, _), rw [(uniform_convergence.has_basis_nhds α β).tendsto_right_iff, tendsto_uniformly], exact iff.rfl, end /-- The natural bijection between `α → β × γ` and `(α → β) × (α → γ)`, upgraded to a uniform isomorphism between `(α → β × γ, 𝒰(α, β × γ, uβ × uγ))` and `((α → β) × (α → γ), 𝒰(α, β, uβ) × 𝒰(α, γ, uγ))`. -/ protected def uniform_equiv_prod_arrow [uniform_space γ] : (α → β × γ) ≃ᵤ ((α → β) × (α → γ)) := -- Denote `φ` this bijection. We want to show that -- `comap φ (𝒰(α, β, uβ) × 𝒰(α, γ, uγ)) = 𝒰(α, β × γ, uβ × uγ)`. -- But `uβ × uγ` is defined as `comap fst uβ ⊓ comap snd uγ`, so we just have to apply -- `uniform_convergence.inf_eq` and `uniform_convergence.comap_eq`, which leaves us to check -- that some square commutes. (equiv.arrow_prod_equiv_prod_arrow _ _ _).to_uniform_equiv_of_uniform_inducing begin split, change comap (prod.map (equiv.arrow_prod_equiv_prod_arrow _ _ _) (equiv.arrow_prod_equiv_prod_arrow _ _ _)) _ = _, rw ← uniformity_comap rfl, congr, rw [prod.uniform_space, prod.uniform_space, uniform_space.comap_inf, uniform_convergence.inf_eq], congr; rw [← uniform_space.comap_comap, uniform_convergence.comap_eq]; refl -- the relevant diagram commutes by definition end variables (α) (δ : ι → Type*) [Π i, uniform_space (δ i)] local attribute [-instance] uniform_convergence.uniform_space /-- The natural bijection between `α → Π i, δ i` and `Π i, α → δ i`, upgraded to a uniform isomorphism between `(α → (Π i, δ i), 𝒰(α, (Π i, δ i), (Π i, uδ i)))` and `((Π i, α → δ i), (Π i, 𝒰(α, δ i, uδ i)))`. -/ protected def uniform_equiv_Pi_comm : @uniform_equiv (α → Π i, δ i) (Π i, α → δ i) (𝒰(α, Π i, δ i, Pi.uniform_space δ)) (@Pi.uniform_space ι (λ i, α → δ i) (λ i, 𝒰(α, δ i, _))) := -- Denote `φ` this bijection. We want to show that -- `comap φ (Π i, 𝒰(α, δ i, uδ i)) = 𝒰(α, (Π i, δ i), (Π i, uδ i))`. -- But `Π i, uδ i` is defined as `⨅ i, comap (eval i) (uδ i)`, so we just have to apply -- `uniform_convergence.infi_eq` and `uniform_convergence.comap_eq`, which leaves us to check -- that some square commutes. @equiv.to_uniform_equiv_of_uniform_inducing _ _ (𝒰(α, Π i, δ i, Pi.uniform_space δ)) (@Pi.uniform_space ι (λ i, α → δ i) (λ i, 𝒰(α, δ i, _))) (equiv.Pi_comm _) begin split, change comap (prod.map function.swap function.swap) _ = _, rw ← uniformity_comap rfl, congr, rw [Pi.uniform_space, uniform_space.of_core_eq_to_core, Pi.uniform_space, uniform_space.of_core_eq_to_core, uniform_space.comap_infi, uniform_convergence.infi_eq], refine infi_congr (λ i, _), rw [← uniform_space.comap_comap, uniform_convergence.comap_eq] -- Like in the previous lemma, the diagram actually commutes by definition end end uniform_convergence namespace uniform_convergence_on variables (α β : Type*) {γ ι : Type*} [uniform_space β] (𝔖 : set (set α)) variables {F : ι → α → β} {f : α → β} {s s' : set α} {x : α} {p : filter ι} {g : ι → α} local notation `𝒰(`α`, `β`, `u`)` := @uniform_convergence.uniform_space α β u /-- Uniform structure of `𝔖`-convergence, i.e uniform convergence on the elements of `𝔖`. It is defined as the infimum, for `S ∈ 𝔖`, of the pullback of `𝒰 S β` by `S.restrict`, the map of restriction to `S`. We will denote it `𝒱(α, β, 𝔖, uβ)`, where `uβ` is the uniform structure on `β`. -/ protected def uniform_space : uniform_space (α → β) := ⨅ (s : set α) (hs : s ∈ 𝔖), uniform_space.comap s.restrict (𝒰(s, β, _)) local notation `𝒱(`α`, `β`, `𝔖`, `u`)` := @uniform_convergence_on.uniform_space α β u 𝔖 /-- Topology of `𝔖`-convergence, i.e uniform convergence on the elements of `𝔖`. -/ protected def topological_space : topological_space (α → β) := (𝒱(α, β, 𝔖, _)).to_topological_space /-- The topology of `𝔖`-convergence is the infimum, for `S ∈ 𝔖`, of topology induced by the map of restriction to `S`, where `↥S → β` is endowed with the topology of uniform convergence. -/ protected lemma topological_space_eq : uniform_convergence_on.topological_space α β 𝔖 = ⨅ (s : set α) (hs : s ∈ 𝔖), topological_space.induced s.restrict (uniform_convergence.topological_space s β) := begin simp only [uniform_convergence_on.topological_space, to_topological_space_infi, to_topological_space_infi, to_topological_space_comap], refl end /-- If `S ∈ 𝔖`, then the restriction to `S` is a uniformly continuous map from `𝒱(α, β, 𝔖, uβ)` to `𝒰(↥S, β, uβ)`. -/ protected lemma uniform_continuous_restrict (h : s ∈ 𝔖) : @uniform_continuous _ _ (𝒱(α, β, 𝔖, _)) (𝒰(s, β, _)) s.restrict := begin change _ ≤ _, rw [uniform_convergence_on.uniform_space, map_le_iff_le_comap, uniformity, infi_uniformity], refine infi_le_of_le s _, rw infi_uniformity, exact infi_le _ h, end variables {α} /-- Let `u₁`, `u₂` be two uniform structures on `γ` and `𝔖₁ 𝔖₂ : set (set α)`. If `u₁ ≤ u₂` and `𝔖₂ ⊆ 𝔖₁` then `𝒱(α, γ, 𝔖₁, u₁) ≤ 𝒱(α, γ, 𝔖₂, u₂)`. -/ protected lemma mono ⦃u₁ u₂ : uniform_space γ⦄ (hu : u₁ ≤ u₂) ⦃𝔖₁ 𝔖₂ : set (set α)⦄ (h𝔖 : 𝔖₂ ⊆ 𝔖₁) : 𝒱(α, γ, 𝔖₁, u₁) ≤ 𝒱(α, γ, 𝔖₂, u₂) := calc 𝒱(α, γ, 𝔖₁, u₁) ≤ 𝒱(α, γ, 𝔖₂, u₁) : infi_le_infi_of_subset h𝔖 ... ≤ 𝒱(α, γ, 𝔖₂, u₂) : infi₂_mono (λ i hi, uniform_space.comap_mono $ uniform_convergence.mono hu) /-- If `x : α` is in some `S ∈ 𝔖`, then evaluation at `x` is uniformly continuous for `𝒱(α, β, 𝔖, uβ)`. -/ lemma uniform_continuous_eval_of_mem {x : α} (hxs : x ∈ s) (hs : s ∈ 𝔖) : @uniform_continuous _ _ 𝒱(α, β, 𝔖, _) _ (function.eval x) := @uniform_continuous.comp (α → β) (s → β) β (𝒱(α, β, 𝔖, _)) (𝒰(s, β, _)) _ _ _ (uniform_convergence.uniform_continuous_eval β (⟨x, hxs⟩ : s)) (uniform_convergence_on.uniform_continuous_restrict α β 𝔖 hs) variables {β} {𝔖} /-- If `u` is a family of uniform structures on `γ`, then `𝒱(α, γ, 𝔖, (⨅ i, u i)) = ⨅ i, 𝒱(α, γ, 𝔖, u i)`. -/ protected lemma infi_eq {u : ι → uniform_space γ} : 𝒱(α, γ, 𝔖, ⨅ i, u i) = ⨅ i, 𝒱(α, γ, 𝔖, u i) := begin simp_rw [uniform_convergence_on.uniform_space, uniform_convergence.infi_eq, uniform_space.comap_infi], rw infi_comm, exact infi_congr (λ s, infi_comm) end /-- If `u₁` and `u₂` are two uniform structures on `γ`, then `𝒱(α, γ, 𝔖, u₁ ⊓ u₂) = 𝒱(α, γ, 𝔖, u₁) ⊓ 𝒱(α, γ, 𝔖, u₂)`. -/ protected lemma inf_eq {u₁ u₂ : uniform_space γ} : 𝒱(α, γ, 𝔖, u₁ ⊓ u₂) = 𝒱(α, γ, 𝔖, u₁) ⊓ 𝒱(α, γ, 𝔖, u₂) := begin rw [inf_eq_infi, inf_eq_infi, uniform_convergence_on.infi_eq], refine infi_congr (λ i, _), cases i; refl end /-- If `u` is a uniform structures on `β` and `f : γ → β`, then `𝒱(α, γ, 𝔖, comap f u) = comap (λ g, f ∘ g) 𝒱(α, γ, 𝔖, u₁)`. -/ protected lemma comap_eq {f : γ → β} : 𝒱(α, γ, 𝔖, ‹uniform_space β›.comap f) = 𝒱(α, β, 𝔖, _).comap ((∘) f) := begin -- We reduce this to `uniform_convergence.comap_eq` using the fact that `comap` distributes -- on `infi`. simp_rw [uniform_convergence_on.uniform_space, uniform_space.comap_infi, uniform_convergence.comap_eq, ← uniform_space.comap_comap], refl -- by definition, `∀ S ∈ 𝔖, (f ∘ —) ∘ S.restrict = S.restrict ∘ (f ∘ —)`. end /-- Post-composition by a uniformly continuous function is uniformly continuous for the uniform structures of `𝔖`-convergence. More precisely, if `f : (γ, uγ) → (β, uβ)` is uniformly continuous, then `(λ g, f ∘ g) : (α → γ, 𝒱(α, γ, 𝔖, uγ)) → (α → β, 𝒱(α, β, 𝔖, uβ))` is uniformly continuous. -/ protected lemma postcomp_uniform_continuous [uniform_space γ] {f : γ → β} (hf : uniform_continuous f): @uniform_continuous (α → γ) (α → β) 𝒱(α, γ, 𝔖, _) 𝒱(α, β, 𝔖, _) ((∘) f) := begin -- This is a direct consequence of `uniform_convergence.comap_eq` rw uniform_continuous_iff, calc 𝒱(α, γ, 𝔖, _) ≤ 𝒱(α, γ, 𝔖, ‹uniform_space β›.comap f) : uniform_convergence_on.mono (uniform_continuous_iff.mp hf) (subset_rfl) ... = 𝒱(α, β, 𝔖, _).comap ((∘) f) : uniform_convergence_on.comap_eq end /-- Post-composition by a uniform inducing is a uniform inducing for the uniform structures of `𝔖`-convergence. More precisely, if `f : (γ, uγ) → (β, uβ)` is a uniform inducing, then `(λ g, f ∘ g) : (α → γ, 𝒱(α, γ, 𝔖, uγ)) → (α → β, 𝒱(α, β, 𝔖, uβ))` is a uniform inducing. -/ protected lemma postcomp_uniform_inducing [uniform_space γ] {f : γ → β} (hf : uniform_inducing f): @uniform_inducing (α → γ) (α → β) 𝒱(α, γ, 𝔖, _) 𝒱(α, β, 𝔖, _) ((∘) f) := -- This is a direct consequence of `uniform_convergence.comap_eq` begin split, replace hf : (𝓤 β).comap (prod.map f f) = _ := hf.comap_uniformity, change comap (prod.map ((∘) f) ((∘) f)) _ = _, rw [← uniformity_comap rfl] at ⊢ hf, congr, rw [← uniform_space_eq hf, uniform_convergence_on.comap_eq] end /-- Turn a uniform isomorphism `(γ, uγ) ≃ᵤ (β, uβ)` into a uniform isomorphism `(α → γ, 𝒱(α, γ, 𝔖, uγ)) ≃ᵤ (α → β, 𝒱(α, β, 𝔖, uβ))` by post-composing. -/ protected def congr_right [uniform_space γ] (e : γ ≃ᵤ β) : @uniform_equiv (α → γ) (α → β) 𝒱(α, γ, 𝔖, _) 𝒱(α, β, 𝔖, _) := { uniform_continuous_to_fun := uniform_convergence_on.postcomp_uniform_continuous e.uniform_continuous, uniform_continuous_inv_fun := uniform_convergence_on.postcomp_uniform_continuous e.symm.uniform_continuous, .. equiv.Pi_congr_right (λ a, e.to_equiv) } /-- Let `f : γ → α`, `𝔖 : set (set α)`, `𝔗 : set (set γ)`, and assume that `∀ T ∈ 𝔗, f '' T ∈ 𝔖`. Then, the function `(λ g, g ∘ f) : (α → β, 𝒱(α, β, 𝔖, uβ)) → (γ → β, 𝒱(γ, β, 𝔗 uβ))` is uniformly continuous. Note that one can easily see that assuming `∀ T ∈ 𝔗, ∃ S ∈ 𝔖, f '' T ⊆ S` would work too, but we will get this for free when we prove that `𝒱(α, β, 𝔖, uβ) = 𝒱(α, β, 𝔖', uβ)` for `𝔖'` the ***noncovering*** bornology generated by `𝔖`. -/ protected lemma precomp_uniform_continuous {𝔗 : set (set γ)} {f : γ → α} (hf : 𝔗 ⊆ (image f) ⁻¹' 𝔖) : @uniform_continuous (α → β) (γ → β) 𝒱(α, β, 𝔖, _) 𝒱(γ, β, 𝔗, _) (λ g : α → β, g ∘ f) := begin -- Since `comap` distributes on `infi`, it suffices to prove that -- `⨅ s ∈ 𝔖, comap s.restrict 𝒰(↥s, β, uβ) ≤ ⨅ t ∈ 𝔗, comap (t.restrict ∘ (— ∘ f)) 𝒰(↥t, β, uβ)`. simp_rw [uniform_continuous_iff, uniform_convergence_on.uniform_space, uniform_space.comap_infi, ← uniform_space.comap_comap], -- For any `t ∈ 𝔗`, note `s := f '' t ∈ 𝔖`. -- We will show that `comap s.restrict 𝒰(↥s, β, uβ) ≤ comap (t.restrict ∘ (— ∘ f)) 𝒰(↥t, β, uβ)`. refine le_infi₂ (λ t ht, infi_le_of_le (f '' t) $ infi_le_of_le (hf ht) _), -- Let `f'` be the map from `t` to `f '' t` induced by `f`. let f' : t → f '' t := (maps_to_image f t).restrict f t (f '' t), -- By definition `t.restrict ∘ (— ∘ f) = (— ∘ f') ∘ (f '' t).restrict`. have : t.restrict ∘ (λ g : α → β, g ∘ f) = (λ g : (f '' t) → β, g ∘ f') ∘ (f '' t).restrict := rfl, -- Thus, we have to show `comap (f '' t).restrict 𝒰(↥(f '' t), β, uβ) ≤` -- `comap (f '' t).restrict (comap (— ∘ f') 𝒰(↥t, β, uβ))`. rw [this, @uniform_space.comap_comap (α → β) ((f '' t) → β)], -- But this is exactly monotonicity of `comap` applied to -- `uniform_convergence.precomp_continuous`. refine uniform_space.comap_mono _, rw ← uniform_continuous_iff, exact uniform_convergence.precomp_uniform_continuous end /-- Turn a bijection `e : γ ≃ α` such that we have both `∀ T ∈ 𝔗, e '' T ∈ 𝔖` and `∀ S ∈ 𝔖, e ⁻¹' S ∈ 𝔗` into a uniform isomorphism `(γ → β, 𝒰(γ, β, uβ)) ≃ᵤ (α → β, 𝒰(α, β, uβ))` by pre-composing. -/ protected def congr_left {𝔗 : set (set γ)} (e : γ ≃ α) (he : 𝔗 ⊆ (image e) ⁻¹' 𝔖) (he' : 𝔖 ⊆ (preimage e) ⁻¹' 𝔗) : @uniform_equiv (γ → β) (α → β) 𝒱(γ, β, 𝔗, _) 𝒱(α, β, 𝔖, _) := { uniform_continuous_to_fun := uniform_convergence_on.precomp_uniform_continuous begin intros s hs, change e.symm '' s ∈ 𝔗, rw ← preimage_equiv_eq_image_symm, exact he' hs end, uniform_continuous_inv_fun := uniform_convergence_on.precomp_uniform_continuous he, .. equiv.arrow_congr e (equiv.refl _) } /-- If `𝔖` covers `α`, then the topology of `𝔖`-convergence is T₂. -/ lemma t2_space_of_covering [t2_space β] (h : ⋃₀ 𝔖 = univ) : @t2_space _ (uniform_convergence_on.topological_space α β 𝔖) := { t2 := begin letI : uniform_space (α → β) := 𝒱(α, β, 𝔖, _), letI : topological_space (α → β) := uniform_convergence_on.topological_space α β 𝔖, intros f g hfg, obtain ⟨x, hx⟩ := not_forall.mp (mt funext hfg), obtain ⟨s, hs, hxs⟩ : ∃ s ∈ 𝔖, x ∈ s := mem_sUnion.mp (h.symm ▸ true.intro), exact separated_by_continuous (uniform_continuous_eval_of_mem β 𝔖 hxs hs).continuous hx end } /-- If `𝔖` covers `α`, then the uniform structure of `𝔖`-convergence is finer than that of pointwise convergence. -/ protected lemma le_Pi_of_covering (h : ⋃₀ 𝔖 = univ) : 𝒱(α, β, 𝔖, _) ≤ Pi.uniform_space (λ _, β) := begin rw [le_iff_uniform_continuous_id, uniform_continuous_pi], intros x, obtain ⟨s : set α, hs : s ∈ 𝔖, hxs : x ∈ s⟩ := sUnion_eq_univ_iff.mp h x, exact uniform_continuous_eval_of_mem β 𝔖 hxs hs end /-- Convergence in the topology of `𝔖`-convergence means uniform convergence on `S` (in the sense of `tendsto_uniformly_on`) for all `S ∈ 𝔖`. -/ protected lemma tendsto_iff_tendsto_uniformly_on : tendsto F p (@nhds _ (uniform_convergence_on.topological_space α β 𝔖) f) ↔ ∀ s ∈ 𝔖, tendsto_uniformly_on F f p s := begin letI : uniform_space (α → β) := 𝒱(α, β, 𝔖, _), rw [uniform_convergence_on.topological_space_eq, nhds_infi, tendsto_infi], refine forall_congr (λ s, _), rw [nhds_infi, tendsto_infi], refine forall_congr (λ hs, _), rw [nhds_induced, tendsto_comap_iff, tendsto_uniformly_on_iff_tendsto_uniformly_comp_coe, uniform_convergence.tendsto_iff_tendsto_uniformly], refl end /-- The natural bijection between `α → β × γ` and `(α → β) × (α → γ)`, upgraded to a uniform isomorphism between `(α → β × γ, 𝒱(α, β × γ, 𝔖, uβ × uγ))` and `((α → β) × (α → γ), 𝒱(α, β, 𝔖, uβ) × 𝒰(α, γ, 𝔖, uγ))`. -/ protected def uniform_equiv_prod_arrow [uniform_space γ] : @uniform_equiv (α → β × γ) ((α → β) × (α → γ)) 𝒱(α, β × γ, 𝔖, _) (@prod.uniform_space _ _ 𝒱(α, β, 𝔖, _) 𝒱(α, γ, 𝔖, _)) := -- Denote `φ` this bijection. We want to show that -- `comap φ (𝒱(α, β, 𝔖, uβ) × 𝒱(α, γ, 𝔖, uγ)) = 𝒱(α, β × γ, 𝔖, uβ × uγ)`. -- But `uβ × uγ` is defined as `comap fst uβ ⊓ comap snd uγ`, so we just have to apply -- `uniform_convergence_on.inf_eq` and `uniform_convergence_on.comap_eq`, which leaves us to check -- that some square commutes. -- We could also deduce this from `uniform_convergence.uniform_equiv_prod_arrow`, but it turns out -- to be more annoying. @equiv.to_uniform_equiv_of_uniform_inducing _ _ 𝒱(α, β × γ, 𝔖, _) (@prod.uniform_space _ _ 𝒱(α, β, 𝔖, _) 𝒱(α, γ, 𝔖, _)) (equiv.arrow_prod_equiv_prod_arrow _ _ _) begin split, change comap (prod.map (equiv.arrow_prod_equiv_prod_arrow _ _ _) (equiv.arrow_prod_equiv_prod_arrow _ _ _)) _ = _, rw ← uniformity_comap rfl, congr, rw [prod.uniform_space, prod.uniform_space, uniform_space.comap_inf, uniform_convergence_on.inf_eq], congr; rw [← uniform_space.comap_comap, uniform_convergence_on.comap_eq]; refl -- the relevant diagram commutes by definition end variables (𝔖) (δ : ι → Type*) [Π i, uniform_space (δ i)] /-- The natural bijection between `α → Π i, δ i` and `Π i, α → δ i`, upgraded to a uniform isomorphism between `(α → (Π i, δ i), 𝒱(α, (Π i, δ i), 𝔖, (Π i, uδ i)))` and `((Π i, α → δ i), (Π i, 𝒱(α, δ i, 𝔖, uδ i)))`. -/ protected def uniform_equiv_Pi_comm : @uniform_equiv (α → Π i, δ i) (Π i, α → δ i) 𝒱(α, Π i, δ i, 𝔖, Pi.uniform_space δ) (@Pi.uniform_space ι (λ i, α → δ i) (λ i, 𝒱(α, δ i, 𝔖, _))) := -- Denote `φ` this bijection. We want to show that -- `comap φ (Π i, 𝒱(α, δ i, 𝔖, uδ i)) = 𝒱(α, (Π i, δ i), 𝔖, (Π i, uδ i))`. -- But `Π i, uδ i` is defined as `⨅ i, comap (eval i) (uδ i)`, so we just have to apply -- `uniform_convergence_on.infi_eq` and `uniform_convergence_on.comap_eq`, which leaves us to check -- that some square commutes. -- We could also deduce this from `uniform_convergence.uniform_equiv_Pi_comm`, but it turns out -- to be more annoying. @equiv.to_uniform_equiv_of_uniform_inducing _ _ 𝒱(α, Π i, δ i, 𝔖, Pi.uniform_space δ) (@Pi.uniform_space ι (λ i, α → δ i) (λ i, 𝒱(α, δ i, 𝔖, _))) (equiv.Pi_comm _) begin split, change comap (prod.map function.swap function.swap) _ = _, rw ← uniformity_comap rfl, congr, rw [Pi.uniform_space, uniform_space.of_core_eq_to_core, Pi.uniform_space, uniform_space.of_core_eq_to_core, uniform_space.comap_infi, uniform_convergence_on.infi_eq], refine infi_congr (λ i, _), rw [← uniform_space.comap_comap, uniform_convergence_on.comap_eq] -- Like in the previous lemma, the diagram actually commutes by definition end end uniform_convergence_on
76cc783e6e60b3d43aa617c2e35ae28b5d87a760
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/run/fun.lean
45546a2bf9166c7cec53bac1a2b6e3bb4d4dbc2d
[ "Apache-2.0" ]
permissive
leanprover-community/lean
12b87f69d92e614daea8bcc9d4de9a9ace089d0e
cce7990ea86a78bdb383e38ed7f9b5ba93c60ce0
refs/heads/master
1,687,508,156,644
1,684,951,104,000
1,684,951,104,000
169,960,991
457
107
Apache-2.0
1,686,744,372,000
1,549,790,268,000
C++
UTF-8
Lean
false
false
320
lean
open function bool constant f : nat → bool constant g : nat → nat #check f ∘ g ∘ g #check (id : nat → nat) constant h : nat → bool → nat #check swap h #check swap h ff nat.zero #check (swap h ff nat.zero : nat) constant f1 : nat → nat → bool constant f2 : bool → nat #check (f1 on f2) ff tt
eacb8ad5a8b12258d6159783c00a24c4e9c3f114
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/measure_theory/measure/regular.lean
26bb77f77822e40a098cc3c7ca00120f6af07ac8
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
33,773
lean
/- Copyright (c) 2021 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris Van Doorn, Yury Kudryashov -/ import measure_theory.constructions.borel_space.basic /-! # Regular measures > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. A measure is `outer_regular` if the measure of any measurable set `A` is the infimum of `μ U` over all open sets `U` containing `A`. A measure is `regular` if it satisfies the following properties: * it is finite on compact sets; * it is outer regular; * it is inner regular for open sets with respect to compacts sets: the measure of any open set `U` is the supremum of `μ K` over all compact sets `K` contained in `U`. A measure is `weakly_regular` if it satisfies the following properties: * it is outer regular; * it is inner regular for open sets with respect to closed sets: the measure of any open set `U` is the supremum of `μ F` over all closed sets `F` contained in `U`. In a Hausdorff topological space, regularity implies weak regularity. These three conditions are registered as typeclasses for a measure `μ`, and this implication is recorded as an instance. In order to avoid code duplication, we also define a measure `μ` to be `inner_regular` for sets satisfying a predicate `q` with respect to sets satisfying a predicate `p` if for any set `U ∈ {U | q U}` and a number `r < μ U` there exists `F ⊆ U` such that `p F` and `r < μ F`. We prove that inner regularity for open sets with respect to compact sets or closed sets implies inner regularity for all measurable sets of finite measure (with respect to compact sets or closed sets respectively), and register some corollaries for (weakly) regular measures. Note that a similar statement for measurable sets of infinite mass can fail. For a counterexample, consider the group `ℝ × ℝ` where the first factor has the discrete topology and the second one the usual topology. It is a locally compact Hausdorff topological group, with Haar measure equal to Lebesgue measure on each vertical fiber. The set `ℝ × {0}` has infinite measure (by outer regularity), but any compact set it contains has zero measure (as it is finite). Several authors require as a definition of regularity that all measurable sets are inner regular. We have opted for the slightly weaker definition above as it holds for all Haar measures, it is enough for essentially all applications, and it is equivalent to the other definition when the measure is finite. The interest of the notion of weak regularity is that it is enough for many applications, and it is automatically satisfied by any finite measure on a metric space. ## Main definitions * `measure_theory.measure.outer_regular μ`: a typeclass registering that a measure `μ` on a topological space is outer regular. * `measure_theory.measure.regular μ`: a typeclass registering that a measure `μ` on a topological space is regular. * `measure_theory.measure.weakly_regular μ`: a typeclass registering that a measure `μ` on a topological space is weakly regular. * `measure_theory.measure.inner_regular μ p q`: a non-typeclass predicate saying that a measure `μ` is inner regular for sets satisfying `q` with respect to sets satisfying `p`. ## Main results ### Outer regular measures * `set.measure_eq_infi_is_open` asserts that, when `μ` is outer regular, the measure of a set is the infimum of the measure of open sets containing it. * `set.exists_is_open_lt_of_lt` asserts that, when `μ` is outer regular, for every set `s` and `r > μ s` there exists an open superset `U ⊇ s` of measure less than `r`. * push forward of an outer regular measure is outer regular, and scalar multiplication of a regular measure by a finite number is outer regular. ### Weakly regular measures * `is_open.measure_eq_supr_is_closed` asserts that the measure of an open set is the supremum of the measure of closed sets it contains. * `is_open.exists_lt_is_closed`: for an open set `U` and `r < μ U`, there exists a closed `F ⊆ U` of measure greater than `r`; * `measurable_set.measure_eq_supr_is_closed_of_ne_top` asserts that the measure of a measurable set of finite measure is the supremum of the measure of closed sets it contains. * `measurable_set.exists_lt_is_closed_of_ne_top` and `measurable_set.exists_is_closed_lt_add`: a measurable set of finite measure can be approximated by a closed subset (stated as `r < μ F` and `μ s < μ F + ε`, respectively). * `measure_theory.measure.weakly_regular.of_pseudo_emetric_space_of_is_finite_measure` is an instance registering that a finite measure on a metric space is weakly regular (in fact, a pseudo emetric space is enough); * `measure_theory.measure.weakly_regular.of_pseudo_emetric_second_countable_of_locally_finite` is an instance registering that a locally finite measure on a second countable metric space (or even a pseudo emetric space) is weakly regular. ### Regular measures * `is_open.measure_eq_supr_is_compact` asserts that the measure of an open set is the supremum of the measure of compact sets it contains. * `is_open.exists_lt_is_compact`: for an open set `U` and `r < μ U`, there exists a compact `K ⊆ U` of measure greater than `r`; * `measurable_set.measure_eq_supr_is_compact_of_ne_top` asserts that the measure of a measurable set of finite measure is the supremum of the measure of compact sets it contains. * `measurable_set.exists_lt_is_compact_of_ne_top` and `measurable_set.exists_is_compact_lt_add`: a measurable set of finite measure can be approximated by a compact subset (stated as `r < μ K` and `μ s < μ K + ε`, respectively). * `measure_theory.measure.regular.of_sigma_compact_space_of_is_locally_finite_measure` is an instance registering that a locally finite measure on a `σ`-compact metric space is regular (in fact, an emetric space is enough). ## Implementation notes The main nontrivial statement is `measure_theory.measure.inner_regular.weakly_regular_of_finite`, expressing that in a finite measure space, if every open set can be approximated from inside by closed sets, then the measure is in fact weakly regular. To prove that we show that any measurable set can be approximated from inside by closed sets and from outside by open sets. This statement is proved by measurable induction, starting from open sets and checking that it is stable by taking complements (this is the point of this condition, being symmetrical between inside and outside) and countable disjoint unions. Once this statement is proved, one deduces results for `σ`-finite measures from this statement, by restricting them to finite measure sets (and proving that this restriction is weakly regular, using again the same statement). ## References [Halmos, Measure Theory, §52][halmos1950measure]. Note that Halmos uses an unusual definition of Borel sets (for him, they are elements of the `σ`-algebra generated by compact sets!), so his proofs or statements do not apply directly. [Billingsley, Convergence of Probability Measures][billingsley1999] -/ open set filter open_locale ennreal topology nnreal big_operators namespace measure_theory namespace measure /-- We say that a measure `μ` is *inner regular* with respect to predicates `p q : set α → Prop`, if for every `U` such that `q U` and `r < μ U`, there exists a subset `K ⊆ U` satisfying `p K` of measure greater than `r`. This definition is used to prove some facts about regular and weakly regular measures without repeating the proofs. -/ def inner_regular {α} {m : measurable_space α} (μ : measure α) (p q : set α → Prop) := ∀ ⦃U⦄, q U → ∀ r < μ U, ∃ K ⊆ U, p K ∧ r < μ K namespace inner_regular variables {α : Type*} {m : measurable_space α} {μ : measure α} {p q : set α → Prop} {U : set α} {ε : ℝ≥0∞} lemma measure_eq_supr (H : inner_regular μ p q) (hU : q U) : μ U = ⨆ (K ⊆ U) (hK : p K), μ K := begin refine le_antisymm (le_of_forall_lt $ λ r hr, _) (supr₂_le $ λ K hK, supr_le $ λ _, μ.mono hK), simpa only [lt_supr_iff, exists_prop] using H hU r hr end lemma exists_subset_lt_add (H : inner_regular μ p q) (h0 : p ∅) (hU : q U) (hμU : μ U ≠ ∞) (hε : ε ≠ 0) : ∃ K ⊆ U, p K ∧ μ U < μ K + ε := begin cases eq_or_ne (μ U) 0 with h₀ h₀, { refine ⟨∅, empty_subset _, h0, _⟩, rwa [measure_empty, h₀, zero_add, pos_iff_ne_zero] }, { rcases H hU _ (ennreal.sub_lt_self hμU h₀ hε) with ⟨K, hKU, hKc, hrK⟩, exact ⟨K, hKU, hKc, ennreal.lt_add_of_sub_lt_right (or.inl hμU) hrK⟩ } end lemma map {α β} [measurable_space α] [measurable_space β] {μ : measure α} {pa qa : set α → Prop} (H : inner_regular μ pa qa) (f : α ≃ β) (hf : ae_measurable f μ) {pb qb : set β → Prop} (hAB : ∀ U, qb U → qa (f ⁻¹' U)) (hAB' : ∀ K, pa K → pb (f '' K)) (hB₁ : ∀ K, pb K → measurable_set K) (hB₂ : ∀ U, qb U → measurable_set U) : inner_regular (map f μ) pb qb := begin intros U hU r hr, rw [map_apply_of_ae_measurable hf (hB₂ _ hU)] at hr, rcases H (hAB U hU) r hr with ⟨K, hKU, hKc, hK⟩, refine ⟨f '' K, image_subset_iff.2 hKU, hAB' _ hKc, _⟩, rwa [map_apply_of_ae_measurable hf (hB₁ _ $ hAB' _ hKc), f.preimage_image] end lemma smul (H : inner_regular μ p q) (c : ℝ≥0∞) : inner_regular (c • μ) p q := begin intros U hU r hr, rw [smul_apply, H.measure_eq_supr hU, smul_eq_mul] at hr, simpa only [ennreal.mul_supr, lt_supr_iff, exists_prop] using hr end lemma trans {q' : set α → Prop} (H : inner_regular μ p q) (H' : inner_regular μ q q') : inner_regular μ p q' := begin intros U hU r hr, rcases H' hU r hr with ⟨F, hFU, hqF, hF⟩, rcases H hqF _ hF with ⟨K, hKF, hpK, hrK⟩, exact ⟨K, hKF.trans hFU, hpK, hrK⟩ end end inner_regular variables {α β : Type*} [measurable_space α] [topological_space α] {μ : measure α} /-- A measure `μ` is outer regular if `μ(A) = inf {μ(U) | A ⊆ U open}` for a measurable set `A`. This definition implies the same equality for any (not necessarily measurable) set, see `set.measure_eq_infi_is_open`. -/ @[protect_proj] class outer_regular (μ : measure α) : Prop := (outer_regular : ∀ ⦃A : set α⦄, measurable_set A → ∀ r > μ A, ∃ U ⊇ A, is_open U ∧ μ U < r) /-- A measure `μ` is regular if - it is finite on all compact sets; - it is outer regular: `μ(A) = inf {μ(U) | A ⊆ U open}` for `A` measurable; - it is inner regular for open sets, using compact sets: `μ(U) = sup {μ(K) | K ⊆ U compact}` for `U` open. -/ @[protect_proj] class regular (μ : measure α) extends is_finite_measure_on_compacts μ, outer_regular μ : Prop := (inner_regular : inner_regular μ is_compact is_open) /-- A measure `μ` is weakly regular if - it is outer regular: `μ(A) = inf {μ(U) | A ⊆ U open}` for `A` measurable; - it is inner regular for open sets, using closed sets: `μ(U) = sup {μ(F) | F ⊆ U compact}` for `U` open. -/ @[protect_proj] class weakly_regular (μ : measure α) extends outer_regular μ : Prop := (inner_regular : inner_regular μ is_closed is_open) /-- A regular measure is weakly regular. -/ @[priority 100] -- see Note [lower instance priority] instance regular.weakly_regular [t2_space α] [regular μ] : weakly_regular μ := { inner_regular := λ U hU r hr, let ⟨K, hKU, hcK, hK⟩ := regular.inner_regular hU r hr in ⟨K, hKU, hcK.is_closed, hK⟩ } namespace outer_regular instance zero : outer_regular (0 : measure α) := ⟨λ A hA r hr, ⟨univ, subset_univ A, is_open_univ, hr⟩⟩ /-- Given `r` larger than the measure of a set `A`, there exists an open superset of `A` with measure less than `r`. -/ lemma _root_.set.exists_is_open_lt_of_lt [outer_regular μ] (A : set α) (r : ℝ≥0∞) (hr : μ A < r) : ∃ U ⊇ A, is_open U ∧ μ U < r := begin rcases outer_regular.outer_regular (measurable_set_to_measurable μ A) r (by rwa measure_to_measurable) with ⟨U, hAU, hUo, hU⟩, exact ⟨U, (subset_to_measurable _ _).trans hAU, hUo, hU⟩ end /-- For an outer regular measure, the measure of a set is the infimum of the measures of open sets containing it. -/ lemma _root_.set.measure_eq_infi_is_open (A : set α) (μ : measure α) [outer_regular μ] : μ A = (⨅ (U : set α) (h : A ⊆ U) (h2 : is_open U), μ U) := begin refine le_antisymm (le_infi₂ $ λ s hs, le_infi $ λ h2s, μ.mono hs) _, refine le_of_forall_lt' (λ r hr, _), simpa only [infi_lt_iff, exists_prop] using A.exists_is_open_lt_of_lt r hr end lemma _root_.set.exists_is_open_lt_add [outer_regular μ] (A : set α) (hA : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ U ⊇ A, is_open U ∧ μ U < μ A + ε := A.exists_is_open_lt_of_lt _ (ennreal.lt_add_right hA hε) lemma _root_.set.exists_is_open_le_add (A : set α) (μ : measure α) [outer_regular μ] {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ U ⊇ A, is_open U ∧ μ U ≤ μ A + ε := begin rcases eq_or_ne (μ A) ∞ with H|H, { exact ⟨univ, subset_univ _, is_open_univ, by simp only [H, _root_.top_add, le_top]⟩ }, { rcases A.exists_is_open_lt_add H hε with ⟨U, AU, U_open, hU⟩, exact ⟨U, AU, U_open, hU.le⟩ } end lemma _root_.measurable_set.exists_is_open_diff_lt [outer_regular μ] {A : set α} (hA : measurable_set A) (hA' : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ U ⊇ A, is_open U ∧ μ U < ∞ ∧ μ (U \ A) < ε := begin rcases A.exists_is_open_lt_add hA' hε with ⟨U, hAU, hUo, hU⟩, use [U, hAU, hUo, hU.trans_le le_top], exact measure_diff_lt_of_lt_add hA hAU hA' hU, end protected lemma map [opens_measurable_space α] [measurable_space β] [topological_space β] [borel_space β] (f : α ≃ₜ β) (μ : measure α) [outer_regular μ] : (measure.map f μ).outer_regular := begin refine ⟨λ A hA r hr, _⟩, rw [map_apply f.measurable hA, ← f.image_symm] at hr, rcases set.exists_is_open_lt_of_lt _ r hr with ⟨U, hAU, hUo, hU⟩, have : is_open (f.symm ⁻¹' U), from hUo.preimage f.symm.continuous, refine ⟨f.symm ⁻¹' U, image_subset_iff.1 hAU, this, _⟩, rwa [map_apply f.measurable this.measurable_set, f.preimage_symm, f.preimage_image], end protected lemma smul (μ : measure α) [outer_regular μ] {x : ℝ≥0∞} (hx : x ≠ ∞) : (x • μ).outer_regular := begin rcases eq_or_ne x 0 with rfl|h0, { rw zero_smul, exact outer_regular.zero }, { refine ⟨λ A hA r hr, _⟩, rw [smul_apply, A.measure_eq_infi_is_open, smul_eq_mul] at hr, simpa only [ennreal.mul_infi_of_ne h0 hx, gt_iff_lt, infi_lt_iff, exists_prop] using hr } end end outer_regular /-- If a measure `μ` admits finite spanning open sets such that the restriction of `μ` to each set is outer regular, then the original measure is outer regular as well. -/ protected lemma finite_spanning_sets_in.outer_regular [opens_measurable_space α] {μ : measure α} (s : μ.finite_spanning_sets_in {U | is_open U ∧ outer_regular (μ.restrict U)}) : outer_regular μ := begin refine ⟨λ A hA r hr, _⟩, have hm : ∀ n, measurable_set (s.set n), from λ n, (s.set_mem n).1.measurable_set, haveI : ∀ n, outer_regular (μ.restrict (s.set n)) := λ n, (s.set_mem n).2, -- Note that `A = ⋃ n, A ∩ disjointed s n`. We replace `A` with this sequence. obtain ⟨A, hAm, hAs, hAd, rfl⟩ : ∃ A' : ℕ → set α, (∀ n, measurable_set (A' n)) ∧ (∀ n, A' n ⊆ s.set n) ∧ pairwise (disjoint on A') ∧ A = ⋃ n, A' n, { refine ⟨λ n, A ∩ disjointed s.set n, λ n, hA.inter (measurable_set.disjointed hm _), λ n, (inter_subset_right _ _).trans (disjointed_subset _ _), (disjoint_disjointed s.set).mono (λ k l hkl, hkl.mono inf_le_right inf_le_right), _⟩, rw [← inter_Union, Union_disjointed, s.spanning, inter_univ] }, rcases ennreal.exists_pos_sum_of_countable' (tsub_pos_iff_lt.2 hr).ne' ℕ with ⟨δ, δ0, hδε⟩, rw [lt_tsub_iff_right, add_comm] at hδε, have : ∀ n, ∃ U ⊇ A n, is_open U ∧ μ U < μ (A n) + δ n, { intro n, have H₁ : ∀ t, μ.restrict (s.set n) t = μ (t ∩ s.set n), from λ t, restrict_apply' (hm n), have Ht : μ.restrict (s.set n) (A n) ≠ ⊤, { rw H₁, exact ((measure_mono $ inter_subset_right _ _).trans_lt (s.finite n)).ne }, rcases (A n).exists_is_open_lt_add Ht (δ0 n).ne' with ⟨U, hAU, hUo, hU⟩, rw [H₁, H₁, inter_eq_self_of_subset_left (hAs _)] at hU, exact ⟨U ∩ s.set n, subset_inter hAU (hAs _), hUo.inter (s.set_mem n).1, hU⟩ }, choose U hAU hUo hU, refine ⟨⋃ n, U n, Union_mono hAU, is_open_Union hUo, _⟩, calc μ (⋃ n, U n) ≤ ∑' n, μ (U n) : measure_Union_le _ ... ≤ ∑' n, (μ (A n) + δ n) : ennreal.tsum_le_tsum (λ n, (hU n).le) ... = ∑' n, μ (A n) + ∑' n, δ n : ennreal.tsum_add ... = μ (⋃ n, A n) + ∑' n, δ n : congr_arg2 (+) (measure_Union hAd hAm).symm rfl ... < r : hδε end namespace inner_regular variables {p q : set α → Prop} {U s : set α} {ε r : ℝ≥0∞} /-- If a measure is inner regular (using closed or compact sets), then every measurable set of finite measure can by approximated by a (closed or compact) subset. -/ lemma measurable_set_of_open [outer_regular μ] (H : inner_regular μ p is_open) (h0 : p ∅) (hd : ∀ ⦃s U⦄, p s → is_open U → p (s \ U)) : inner_regular μ p (λ s, measurable_set s ∧ μ s ≠ ∞) := begin rintros s ⟨hs, hμs⟩ r hr, obtain ⟨ε, hε, hεs, rfl⟩ : ∃ ε ≠ 0, ε + ε ≤ μ s ∧ r = μ s - (ε + ε), { use (μ s - r) / 2, simp [*, hr.le, ennreal.add_halves, ennreal.sub_sub_cancel, le_add_right] }, rcases hs.exists_is_open_diff_lt hμs hε with ⟨U, hsU, hUo, hUt, hμU⟩, rcases (U \ s).exists_is_open_lt_of_lt _ hμU with ⟨U', hsU', hU'o, hμU'⟩, replace hsU' := diff_subset_comm.1 hsU', rcases H.exists_subset_lt_add h0 hUo hUt.ne hε with ⟨K, hKU, hKc, hKr⟩, refine ⟨K \ U', λ x hx, hsU' ⟨hKU hx.1, hx.2⟩, hd hKc hU'o, ennreal.sub_lt_of_lt_add hεs _⟩, calc μ s ≤ μ U : μ.mono hsU ... < μ K + ε : hKr ... ≤ μ (K \ U') + μ U' + ε : add_le_add_right (tsub_le_iff_right.1 le_measure_diff) _ ... ≤ μ (K \ U') + ε + ε : by { mono*, exacts [hμU'.le, le_rfl] } ... = μ (K \ U') + (ε + ε) : add_assoc _ _ _ end open finset /-- In a finite measure space, assume that any open set can be approximated from inside by closed sets. Then the measure is weakly regular. -/ lemma weakly_regular_of_finite [borel_space α] (μ : measure α) [is_finite_measure μ] (H : inner_regular μ is_closed is_open) : weakly_regular μ := begin have hfin : ∀ {s}, μ s ≠ ⊤ := measure_ne_top μ, suffices : ∀ s, measurable_set s → ∀ ε ≠ 0, ∃ (F ⊆ s) (U ⊇ s), is_closed F ∧ is_open U ∧ μ s ≤ μ F + ε ∧ μ U ≤ μ s + ε, { refine { outer_regular := λ s hs r hr, _, inner_regular := H }, rcases exists_between hr with ⟨r', hsr', hr'r⟩, rcases this s hs _ (tsub_pos_iff_lt.2 hsr').ne' with ⟨-, -, U, hsU, -, hUo, -, H⟩, refine ⟨U, hsU, hUo, _⟩, rw [add_tsub_cancel_of_le hsr'.le] at H, exact H.trans_lt hr'r }, refine measurable_set.induction_on_open _ _ _, /- The proof is by measurable induction: we should check that the property is true for the empty set, for open sets, and is stable by taking the complement and by taking countable disjoint unions. The point of the property we are proving is that it is stable by taking complements (exchanging the roles of closed and open sets and thanks to the finiteness of the measure). -/ -- check for open set { intros U hU ε hε, rcases H.exists_subset_lt_add is_closed_empty hU hfin hε with ⟨F, hsF, hFc, hF⟩, exact ⟨F, hsF, U, subset.rfl, hFc, hU, hF.le, le_self_add⟩ }, -- check for complements { rintros s hs H ε hε, rcases H ε hε with ⟨F, hFs, U, hsU, hFc, hUo, hF, hU⟩, refine ⟨Uᶜ, compl_subset_compl.2 hsU, Fᶜ, compl_subset_compl.2 hFs, hUo.is_closed_compl, hFc.is_open_compl, _⟩, simp only [measure_compl_le_add_iff, *, hUo.measurable_set, hFc.measurable_set, true_and] }, -- check for disjoint unions { intros s hsd hsm H ε ε0, have ε0' : ε / 2 ≠ 0, from (ennreal.half_pos ε0).ne', rcases ennreal.exists_pos_sum_of_countable' ε0' ℕ with ⟨δ, δ0, hδε⟩, choose F hFs U hsU hFc hUo hF hU using λ n, H n (δ n) (δ0 n).ne', -- the approximating closed set is constructed by considering finitely many sets `s i`, which -- cover all the measure up to `ε/2`, approximating each of these by a closed set `F i`, and -- taking the union of these (finitely many) `F i`. have : tendsto (λ t, ∑ k in t, μ (s k) + ε / 2) at_top (𝓝 $ μ (⋃ n, s n) + ε / 2), { rw measure_Union hsd hsm, exact tendsto.add ennreal.summable.has_sum tendsto_const_nhds }, rcases (this.eventually $ lt_mem_nhds $ ennreal.lt_add_right hfin ε0').exists with ⟨t, ht⟩, -- the approximating open set is constructed by taking for each `s n` an approximating open set -- `U n` with measure at most `μ (s n) + δ n` for a summable `δ`, and taking the union of these. refine ⟨⋃ k ∈ t, F k, Union_mono $ λ k, Union_subset $ λ _, hFs _, ⋃ n, U n, Union_mono hsU, is_closed_bUnion t.finite_to_set $ λ k _, hFc k, is_open_Union hUo, ht.le.trans _, _⟩, { calc ∑ k in t, μ (s k) + ε / 2 ≤ ∑ k in t, μ (F k) + ∑ k in t, δ k + ε / 2 : by { rw ← sum_add_distrib, exact add_le_add_right (sum_le_sum $ λ k hk, hF k) _ } ... ≤ ∑ k in t, μ (F k) + ε / 2 + ε / 2 : add_le_add_right (add_le_add_left ((ennreal.sum_le_tsum _).trans hδε.le) _) _ ... = μ (⋃ k ∈ t, F k) + ε : _, rw [measure_bUnion_finset, add_assoc, ennreal.add_halves], exacts [λ k _ n _ hkn, (hsd hkn).mono (hFs k) (hFs n), λ k hk, (hFc k).measurable_set] }, { calc μ (⋃ n, U n) ≤ ∑' n, μ (U n) : measure_Union_le _ ... ≤ ∑' n, (μ (s n) + δ n) : ennreal.tsum_le_tsum hU ... = μ (⋃ n, s n) + ∑' n, δ n : by rw [measure_Union hsd hsm, ennreal.tsum_add] ... ≤ μ (⋃ n, s n) + ε : add_le_add_left (hδε.le.trans ennreal.half_le_self) _ } } end /-- In a metric space (or even a pseudo emetric space), an open set can be approximated from inside by closed sets. -/ lemma of_pseudo_emetric_space {X : Type*} [pseudo_emetric_space X] [measurable_space X] (μ : measure X) : inner_regular μ is_closed is_open := begin intros U hU r hr, rcases hU.exists_Union_is_closed with ⟨F, F_closed, -, rfl, F_mono⟩, rw measure_Union_eq_supr F_mono.directed_le at hr, rcases lt_supr_iff.1 hr with ⟨n, hn⟩, exact ⟨F n, subset_Union _ _, F_closed n, hn⟩ end /-- In a `σ`-compact space, any closed set can be approximated by a compact subset. -/ lemma is_compact_is_closed {X : Type*} [topological_space X] [sigma_compact_space X] [measurable_space X] (μ : measure X) : inner_regular μ is_compact is_closed := begin intros F hF r hr, set B : ℕ → set X := compact_covering X, have hBc : ∀ n, is_compact (F ∩ B n), from λ n, (is_compact_compact_covering X n).inter_left hF, have hBU : (⋃ n, F ∩ B n) = F, by rw [← inter_Union, Union_compact_covering, set.inter_univ], have : μ F = ⨆ n, μ (F ∩ B n), { rw [← measure_Union_eq_supr, hBU], exact monotone.directed_le (λ m n h, inter_subset_inter_right _ (compact_covering_subset _ h)) }, rw this at hr, rcases lt_supr_iff.1 hr with ⟨n, hn⟩, exact ⟨_, inter_subset_left _ _, hBc n, hn⟩ end end inner_regular namespace regular instance zero : regular (0 : measure α) := ⟨λ U hU r hr, ⟨∅, empty_subset _, is_compact_empty, hr⟩⟩ /-- If `μ` is a regular measure, then any open set can be approximated by a compact subset. -/ lemma _root_.is_open.exists_lt_is_compact [regular μ] ⦃U : set α⦄ (hU : is_open U) {r : ℝ≥0∞} (hr : r < μ U) : ∃ K ⊆ U, is_compact K ∧ r < μ K := regular.inner_regular hU r hr /-- The measure of an open set is the supremum of the measures of compact sets it contains. -/ lemma _root_.is_open.measure_eq_supr_is_compact ⦃U : set α⦄ (hU : is_open U) (μ : measure α) [regular μ] : μ U = (⨆ (K : set α) (h : K ⊆ U) (h2 : is_compact K), μ K) := regular.inner_regular.measure_eq_supr hU lemma exists_compact_not_null [regular μ] : (∃ K, is_compact K ∧ μ K ≠ 0) ↔ μ ≠ 0 := by simp_rw [ne.def, ← measure_univ_eq_zero, is_open_univ.measure_eq_supr_is_compact, ennreal.supr_eq_zero, not_forall, exists_prop, subset_univ, true_and] /-- If `μ` is a regular measure, then any measurable set of finite measure can be approximated by a compact subset. See also `measurable_set.exists_is_compact_lt_add` and `measurable_set.exists_lt_is_compact_of_ne_top`. -/ lemma inner_regular_measurable [regular μ] : inner_regular μ is_compact (λ s, measurable_set s ∧ μ s ≠ ∞) := regular.inner_regular.measurable_set_of_open is_compact_empty (λ _ _, is_compact.diff) /-- If `μ` is a regular measure, then any measurable set of finite measure can be approximated by a compact subset. See also `measurable_set.exists_lt_is_compact_of_ne_top`. -/ lemma _root_.measurable_set.exists_is_compact_lt_add [regular μ] ⦃A : set α⦄ (hA : measurable_set A) (h'A : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ K ⊆ A, is_compact K ∧ μ A < μ K + ε := regular.inner_regular_measurable.exists_subset_lt_add is_compact_empty ⟨hA, h'A⟩ h'A hε /-- If `μ` is a regular measure, then any measurable set of finite measure can be approximated by a compact subset. See also `measurable_set.exists_is_compact_lt_add` and `measurable_set.exists_lt_is_compact_of_ne_top`. -/ lemma _root_.measurable_set.exists_is_compact_diff_lt [opens_measurable_space α] [t2_space α] [regular μ] ⦃A : set α⦄ (hA : measurable_set A) (h'A : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ K ⊆ A, is_compact K ∧ μ (A \ K) < ε := begin rcases hA.exists_is_compact_lt_add h'A hε with ⟨K, hKA, hKc, hK⟩, exact ⟨K, hKA, hKc, measure_diff_lt_of_lt_add hKc.measurable_set hKA (ne_top_of_le_ne_top h'A $ measure_mono hKA) hK⟩ end /-- If `μ` is a regular measure, then any measurable set of finite measure can be approximated by a compact subset. See also `measurable_set.exists_is_compact_lt_add`. -/ lemma _root_.measurable_set.exists_lt_is_compact_of_ne_top [regular μ] ⦃A : set α⦄ (hA : measurable_set A) (h'A : μ A ≠ ∞) {r : ℝ≥0∞} (hr : r < μ A) : ∃ K ⊆ A, is_compact K ∧ r < μ K := regular.inner_regular_measurable ⟨hA, h'A⟩ _ hr /-- Given a regular measure, any measurable set of finite mass can be approximated from inside by compact sets. -/ lemma _root_.measurable_set.measure_eq_supr_is_compact_of_ne_top [regular μ] ⦃A : set α⦄ (hA : measurable_set A) (h'A : μ A ≠ ∞) : μ A = (⨆ (K ⊆ A) (h : is_compact K), μ K) := regular.inner_regular_measurable.measure_eq_supr ⟨hA, h'A⟩ protected lemma map [opens_measurable_space α] [measurable_space β] [topological_space β] [t2_space β] [borel_space β] [regular μ] (f : α ≃ₜ β) : (measure.map f μ).regular := begin haveI := outer_regular.map f μ, haveI := is_finite_measure_on_compacts.map μ f, exact ⟨regular.inner_regular.map f.to_equiv f.measurable.ae_measurable (λ U hU, hU.preimage f.continuous) (λ K hK, hK.image f.continuous) (λ K hK, hK.measurable_set) (λ U hU, hU.measurable_set)⟩ end protected lemma smul [regular μ] {x : ℝ≥0∞} (hx : x ≠ ∞) : (x • μ).regular := begin haveI := outer_regular.smul μ hx, haveI := is_finite_measure_on_compacts.smul μ hx, exact ⟨regular.inner_regular.smul x⟩ end /-- A regular measure in a σ-compact space is σ-finite. -/ @[priority 100] -- see Note [lower instance priority] instance sigma_finite [sigma_compact_space α] [regular μ] : sigma_finite μ := ⟨⟨{ set := compact_covering α, set_mem := λ n, trivial, finite := λ n, (is_compact_compact_covering α n).measure_lt_top, spanning := Union_compact_covering α }⟩⟩ end regular namespace weakly_regular /-- If `μ` is a weakly regular measure, then any open set can be approximated by a closed subset. -/ lemma _root_.is_open.exists_lt_is_closed [weakly_regular μ] ⦃U : set α⦄ (hU : is_open U) {r : ℝ≥0∞} (hr : r < μ U) : ∃ F ⊆ U, is_closed F ∧ r < μ F := weakly_regular.inner_regular hU r hr /-- If `μ` is a weakly regular measure, then any open set can be approximated by a closed subset. -/ lemma _root_.is_open.measure_eq_supr_is_closed ⦃U : set α⦄ (hU : is_open U) (μ : measure α) [weakly_regular μ] : μ U = (⨆ (F ⊆ U) (h : is_closed F), μ F) := weakly_regular.inner_regular.measure_eq_supr hU lemma inner_regular_measurable [weakly_regular μ] : inner_regular μ is_closed (λ s, measurable_set s ∧ μ s ≠ ∞) := weakly_regular.inner_regular.measurable_set_of_open is_closed_empty (λ _ _ h₁ h₂, h₁.inter h₂.is_closed_compl) /-- If `s` is a measurable set, a weakly regular measure `μ` is finite on `s`, and `ε` is a positive number, then there exist a closed set `K ⊆ s` such that `μ s < μ K + ε`. -/ lemma _root_.measurable_set.exists_is_closed_lt_add [weakly_regular μ] {s : set α} (hs : measurable_set s) (hμs : μ s ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ K ⊆ s, is_closed K ∧ μ s < μ K + ε := inner_regular_measurable.exists_subset_lt_add is_closed_empty ⟨hs, hμs⟩ hμs hε lemma _root_.measurable_set.exists_is_closed_diff_lt [opens_measurable_space α] [weakly_regular μ] ⦃A : set α⦄ (hA : measurable_set A) (h'A : μ A ≠ ∞) {ε : ℝ≥0∞} (hε : ε ≠ 0) : ∃ F ⊆ A, is_closed F ∧ μ (A \ F) < ε := begin rcases hA.exists_is_closed_lt_add h'A hε with ⟨F, hFA, hFc, hF⟩, exact ⟨F, hFA, hFc, measure_diff_lt_of_lt_add hFc.measurable_set hFA (ne_top_of_le_ne_top h'A $ measure_mono hFA) hF⟩ end /-- Given a weakly regular measure, any measurable set of finite mass can be approximated from inside by closed sets. -/ lemma _root_.measurable_set.exists_lt_is_closed_of_ne_top [weakly_regular μ] ⦃A : set α⦄ (hA : measurable_set A) (h'A : μ A ≠ ∞) {r : ℝ≥0∞} (hr : r < μ A) : ∃ K ⊆ A, is_closed K ∧ r < μ K := inner_regular_measurable ⟨hA, h'A⟩ _ hr /-- Given a weakly regular measure, any measurable set of finite mass can be approximated from inside by closed sets. -/ lemma _root_.measurable_set.measure_eq_supr_is_closed_of_ne_top [weakly_regular μ] ⦃A : set α⦄ (hA : measurable_set A) (h'A : μ A ≠ ∞) : μ A = (⨆ (K ⊆ A) (h : is_closed K), μ K) := inner_regular_measurable.measure_eq_supr ⟨hA, h'A⟩ /-- The restriction of a weakly regular measure to a measurable set of finite measure is weakly regular. -/ lemma restrict_of_measurable_set [borel_space α] [weakly_regular μ] (A : set α) (hA : measurable_set A) (h'A : μ A ≠ ∞) : weakly_regular (μ.restrict A) := begin haveI : fact (μ A < ∞) := ⟨h'A.lt_top⟩, refine inner_regular.weakly_regular_of_finite _ (λ V V_open, _), simp only [restrict_apply' hA], intros r hr, have : μ (V ∩ A) ≠ ∞, from ne_top_of_le_ne_top h'A (measure_mono $ inter_subset_right _ _), rcases (V_open.measurable_set.inter hA).exists_lt_is_closed_of_ne_top this hr with ⟨F, hFVA, hFc, hF⟩, refine ⟨F, hFVA.trans (inter_subset_left _ _), hFc, _⟩, rwa inter_eq_self_of_subset_left (hFVA.trans $ inter_subset_right _ _) end /-- Any finite measure on a metric space (or even a pseudo emetric space) is weakly regular. -/ @[priority 100] -- see Note [lower instance priority] instance of_pseudo_emetric_space_of_is_finite_measure {X : Type*} [pseudo_emetric_space X] [measurable_space X] [borel_space X] (μ : measure X) [is_finite_measure μ] : weakly_regular μ := (inner_regular.of_pseudo_emetric_space μ).weakly_regular_of_finite μ /-- Any locally finite measure on a second countable metric space (or even a pseudo emetric space) is weakly regular. -/ @[priority 100] -- see Note [lower instance priority] instance of_pseudo_emetric_second_countable_of_locally_finite {X : Type*} [pseudo_emetric_space X] [topological_space.second_countable_topology X] [measurable_space X] [borel_space X] (μ : measure X) [is_locally_finite_measure μ] : weakly_regular μ := begin haveI : outer_regular μ, { refine (μ.finite_spanning_sets_in_open'.mono' $ λ U hU, _).outer_regular, haveI : fact (μ U < ∞), from ⟨hU.2⟩, exact ⟨hU.1, infer_instance⟩ }, exact ⟨inner_regular.of_pseudo_emetric_space μ⟩ end end weakly_regular local attribute [instance] emetric.second_countable_of_sigma_compact /-- Any locally finite measure on a `σ`-compact (e)metric space is regular. -/ @[priority 100] -- see Note [lower instance priority] instance regular.of_sigma_compact_space_of_is_locally_finite_measure {X : Type*} [emetric_space X] [sigma_compact_space X] [measurable_space X] [borel_space X] (μ : measure X) [is_locally_finite_measure μ] : regular μ := { lt_top_of_is_compact := λ K hK, hK.measure_lt_top, inner_regular := (inner_regular.is_compact_is_closed μ).trans (inner_regular.of_pseudo_emetric_space μ) } end measure end measure_theory
5c1c27eceee91f92cdb2b967e6c72d627aa2344a
7cef822f3b952965621309e88eadf618da0c8ae9
/src/data/mv_polynomial.lean
77638e18dfe4093c12da6a9d393d8fd8690b5e8e
[ "Apache-2.0" ]
permissive
rmitta/mathlib
8d90aee30b4db2b013e01f62c33f297d7e64a43d
883d974b608845bad30ae19e27e33c285200bf84
refs/heads/master
1,585,776,832,544
1,576,874,096,000
1,576,874,096,000
153,663,165
0
2
Apache-2.0
1,544,806,490,000
1,539,884,365,000
Lean
UTF-8
Lean
false
false
43,702
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, Johan Commelin, Mario Carneiro Multivariate Polynomial -/ import algebra.ring import data.finsupp data.polynomial data.equiv.algebra noncomputable theory local attribute [instance, priority 100] classical.prop_decidable open set function finsupp lattice universes u v w x variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x} /-- Multivariate polynomial, where `σ` is the index set of the variables and `α` is the coefficient ring -/ def mv_polynomial (σ : Type*) (α : Type*) [comm_semiring α] := (σ →₀ ℕ) →₀ α namespace mv_polynomial variables {σ : Type*} {a a' a₁ a₂ : α} {e : ℕ} {n m : σ} {s : σ →₀ ℕ} section comm_semiring variables [comm_semiring α] {p q : mv_polynomial σ α} instance decidable_eq_mv_polynomial [decidable_eq σ] [decidable_eq α] : decidable_eq (mv_polynomial σ α) := finsupp.decidable_eq instance : has_zero (mv_polynomial σ α) := finsupp.has_zero instance : has_one (mv_polynomial σ α) := finsupp.has_one instance : has_add (mv_polynomial σ α) := finsupp.has_add instance : has_mul (mv_polynomial σ α) := finsupp.has_mul instance : comm_semiring (mv_polynomial σ α) := finsupp.comm_semiring /-- `monomial s a` is the monomial `a * X^s` -/ def monomial (s : σ →₀ ℕ) (a : α) : mv_polynomial σ α := single s a /-- `C a` is the constant polynomial with value `a` -/ def C (a : α) : mv_polynomial σ α := monomial 0 a /-- `X n` is the polynomial with value X_n -/ def X (n : σ) : mv_polynomial σ α := monomial (single n 1) 1 @[simp] lemma C_0 : C 0 = (0 : mv_polynomial σ α) := by simp [C, monomial]; refl @[simp] lemma C_1 : C 1 = (1 : mv_polynomial σ α) := rfl lemma C_mul_monomial : C a * monomial s a' = monomial s (a * a') := by simp [C, monomial, single_mul_single] @[simp] lemma C_add : (C (a + a') : mv_polynomial σ α) = C a + C a' := single_add @[simp] lemma C_mul : (C (a * a') : mv_polynomial σ α) = C a * C a' := C_mul_monomial.symm @[simp] lemma C_pow (a : α) (n : ℕ) : (C (a^n) : mv_polynomial σ α) = (C a)^n := by induction n; simp [pow_succ, *] instance : is_semiring_hom (C : α → mv_polynomial σ α) := { map_zero := C_0, map_one := C_1, map_add := λ a a', C_add, map_mul := λ a a', C_mul } lemma C_eq_coe_nat (n : ℕ) : (C ↑n : mv_polynomial σ α) = n := by induction n; simp [nat.succ_eq_add_one, *] lemma X_pow_eq_single : X n ^ e = monomial (single n e) (1 : α) := begin induction e, { simp [X], refl }, { simp [pow_succ, e_ih], simp [X, monomial, single_mul_single, nat.succ_eq_add_one] } end lemma monomial_add_single : monomial (s + single n e) a = (monomial s a * X n ^ e) := by rw [X_pow_eq_single, monomial, monomial, monomial, single_mul_single]; simp lemma monomial_single_add : monomial (single n e + s) a = (X n ^ e * monomial s a) := by rw [X_pow_eq_single, monomial, monomial, monomial, single_mul_single]; simp lemma monomial_eq : monomial s a = C a * (s.prod $ λn e, X n ^ e : mv_polynomial σ α) := begin apply @finsupp.induction σ ℕ _ _ s, { simp [C, prod_zero_index]; exact (mul_one _).symm }, { assume n e s hns he ih, simp [prod_add_index, prod_single_index, pow_zero, pow_add, (mul_assoc _ _ _).symm, ih.symm, monomial_add_single] } end @[recursor 5] lemma induction_on {M : mv_polynomial σ α → Prop} (p : mv_polynomial σ α) (h_C : ∀a, M (C a)) (h_add : ∀p q, M p → M q → M (p + q)) (h_X : ∀p n, M p → M (p * X n)) : M p := have ∀s a, M (monomial s a), begin assume s a, apply @finsupp.induction σ ℕ _ _ s, { show M (monomial 0 a), from h_C a, }, { assume n e p hpn he ih, have : ∀e:ℕ, M (monomial p a * X n ^ e), { intro e, induction e, { simp [ih] }, { simp [ih, pow_succ', (mul_assoc _ _ _).symm, h_X, e_ih] } }, simp [monomial_add_single, this] } end, finsupp.induction p (by have : M (C 0) := h_C 0; rwa [C_0] at this) (assume s a p hsp ha hp, h_add _ _ (this s a) hp) lemma hom_eq_hom [semiring γ] (f g : mv_polynomial σ α → γ) (hf : is_semiring_hom f) (hg : is_semiring_hom g) (hC : ∀a:α, f (C a) = g (C a)) (hX : ∀n:σ, f (X n) = g (X n)) (p : mv_polynomial σ α) : f p = g p := mv_polynomial.induction_on p hC begin assume p q hp hq, rw [is_semiring_hom.map_add f, is_semiring_hom.map_add g, hp, hq] end begin assume p n hp, rw [is_semiring_hom.map_mul f, is_semiring_hom.map_mul g, hp, hX] end lemma is_id (f : mv_polynomial σ α → mv_polynomial σ α) (hf : is_semiring_hom f) (hC : ∀a:α, f (C a) = (C a)) (hX : ∀n:σ, f (X n) = (X n)) (p : mv_polynomial σ α) : f p = p := hom_eq_hom f id hf is_semiring_hom.id hC hX p section coeff section -- While setting up `coeff`, we make `mv_polynomial` reducible so we can treat it as a function. local attribute [reducible] mv_polynomial /-- The coefficient of the monomial `m` in the multi-variable polynomial `p`. -/ def coeff (m : σ →₀ ℕ) (p : mv_polynomial σ α) : α := p m end lemma ext (p q : mv_polynomial σ α) : (∀ m, coeff m p = coeff m q) → p = q := ext lemma ext_iff (p q : mv_polynomial σ α) : (∀ m, coeff m p = coeff m q) ↔ p = q := ⟨ext p q, λ h m, by rw h⟩ @[simp] lemma coeff_add (m : σ →₀ ℕ) (p q : mv_polynomial σ α) : coeff m (p + q) = coeff m p + coeff m q := add_apply @[simp] lemma coeff_zero (m : σ →₀ ℕ) : coeff m (0 : mv_polynomial σ α) = 0 := rfl @[simp] lemma coeff_zero_X (i : σ) : coeff 0 (X i : mv_polynomial σ α) = 0 := single_eq_of_ne (λ h, by cases single_eq_zero.1 h) instance coeff.is_add_monoid_hom (m : σ →₀ ℕ) : is_add_monoid_hom (coeff m : mv_polynomial σ α → α) := { map_add := coeff_add m, map_zero := coeff_zero m } lemma coeff_sum {X : Type*} (s : finset X) (f : X → mv_polynomial σ α) (m : σ →₀ ℕ) : coeff m (s.sum f) = s.sum (λ x, coeff m (f x)) := (finset.sum_hom _).symm lemma monic_monomial_eq (m) : monomial m (1:α) = (m.prod $ λn e, X n ^ e : mv_polynomial σ α) := by simp [monomial_eq] @[simp] lemma coeff_monomial (m n) (a) : coeff m (monomial n a : mv_polynomial σ α) = if n = m then a else 0 := by convert single_apply @[simp] lemma coeff_C (m) (a) : coeff m (C a : mv_polynomial σ α) = if 0 = m then a else 0 := by convert single_apply lemma coeff_X_pow (i : σ) (m) (k : ℕ) : coeff m (X i ^ k : mv_polynomial σ α) = if single i k = m then 1 else 0 := begin have := coeff_monomial m (finsupp.single i k) (1:α), rwa [@monomial_eq _ _ (1:α) (finsupp.single i k) _, C_1, one_mul, finsupp.prod_single_index] at this, exact pow_zero _ end lemma coeff_X' (i : σ) (m) : coeff m (X i : mv_polynomial σ α) = if single i 1 = m then 1 else 0 := by rw [← coeff_X_pow, pow_one] @[simp] lemma coeff_X (i : σ) : coeff (single i 1) (X i : mv_polynomial σ α) = 1 := by rw [coeff_X', if_pos rfl] @[simp] lemma coeff_C_mul (m) (a : α) (p : mv_polynomial σ α) : coeff m (C a * p) = a * coeff m p := begin rw [mul_def, C, monomial], simp only [sum_single_index, zero_mul, single_zero, zero_add, sum_zero], convert sum_apply, simp only [single_apply, finsupp.sum], rw finset.sum_eq_single m, { rw if_pos rfl, refl }, { intros m' hm' H, apply if_neg, exact H }, { intros hm, rw if_pos rfl, rw not_mem_support_iff at hm, simp [hm] } end lemma coeff_mul (p q : mv_polynomial σ α) (n : σ →₀ ℕ) : coeff n (p * q) = finset.sum (antidiagonal n).support (λ x, coeff x.1 p * coeff x.2 q) := begin rw mul_def, have := @finset.sum_sigma (σ →₀ ℕ) α _ _ p.support (λ _, q.support) (λ x, if (x.1 + x.2 = n) then coeff x.1 p * coeff x.2 q else 0), convert this.symm using 1; clear this, { rw [coeff], repeat {rw sum_apply, apply finset.sum_congr rfl, intros, dsimp only}, convert single_apply }, { have : (antidiagonal n).support.filter (λ x, x.1 ∈ p.support ∧ x.2 ∈ q.support) ⊆ (antidiagonal n).support := finset.filter_subset _, rw [← finset.sum_sdiff this, finset.sum_eq_zero, zero_add], swap, { intros x hx, rw [finset.mem_sdiff, not_iff_not_of_iff (finset.mem_filter), not_and, not_and, not_mem_support_iff] at hx, by_cases H : x.1 ∈ p.support, { rw [coeff, coeff, hx.2 hx.1 H, mul_zero] }, { rw not_mem_support_iff at H, rw [coeff, H, zero_mul] } }, symmetry, rw [← finset.sum_sdiff (finset.filter_subset _), finset.sum_eq_zero, zero_add], swap, { intros x hx, rw [finset.mem_sdiff, not_iff_not_of_iff (finset.mem_filter), not_and] at hx, rw if_neg, exact hx.2 hx.1 }, { apply finset.sum_bij, swap 5, { intros x hx, exact (x.1, x.2) }, { intros x hx, rw [finset.mem_filter, finset.mem_sigma] at hx, simpa [finset.mem_filter, mem_antidiagonal_support] using hx.symm }, { intros x hx, rw finset.mem_filter at hx, rw if_pos hx.2 }, { rintros ⟨i,j⟩ ⟨k,l⟩ hij hkl, simpa using and.intro }, { rintros ⟨i,j⟩ hij, refine ⟨⟨i,j⟩, _, _⟩, { apply_instance }, { rw [finset.mem_filter, mem_antidiagonal_support] at hij, simpa [finset.mem_filter, finset.mem_sigma] using hij.symm }, { refl } } }, all_goals { apply_instance } } end @[simp] lemma coeff_mul_X (m) (s : σ) (p : mv_polynomial σ α) : coeff (m + single s 1) (p * X s) = coeff m p := begin have : (m, single s 1) ∈ (m + single s 1).antidiagonal.support := mem_antidiagonal_support.2 rfl, rw [coeff_mul, ← finset.insert_erase this, finset.sum_insert (finset.not_mem_erase _ _), finset.sum_eq_zero, add_zero, coeff_X, mul_one], rintros ⟨i,j⟩ hij, rw [finset.mem_erase, mem_antidiagonal_support] at hij, by_cases H : single s 1 = j, { subst j, simpa using hij }, { rw [coeff_X', if_neg H, mul_zero] }, end lemma coeff_mul_X' (m) (s : σ) (p : mv_polynomial σ α) : coeff m (p * X s) = if s ∈ m.support then coeff (m - single s 1) p else 0 := begin split_ifs with h h, { conv_rhs {rw ← coeff_mul_X _ s}, congr' 1, ext t, by_cases hj : s = t, { subst t, simp only [nat_sub_apply, add_apply, single_eq_same], refine (nat.sub_add_cancel $ nat.pos_of_ne_zero _).symm, rwa mem_support_iff at h }, { simp [single_eq_of_ne hj] } }, { delta coeff, rw ← not_mem_support_iff, intro hm, apply h, have H := support_mul _ _ hm, simp only [finset.mem_bind] at H, rcases H with ⟨j, hj, i', hi', H⟩, delta X monomial at hi', rw mem_support_single at hi', cases hi', subst i', erw finset.mem_singleton at H, subst m, rw [mem_support_iff, add_apply, single_apply, if_pos rfl], intro H, rw [add_eq_zero_iff] at H, exact one_ne_zero H.2 } end end coeff section eval₂ variables [comm_semiring β] variables (f : α → β) (g : σ → β) /-- Evaluate a polynomial `p` given a valuation `g` of all the variables and a ring hom `f` from the scalar ring to the target -/ def eval₂ (p : mv_polynomial σ α) : β := p.sum (λs a, f a * s.prod (λn e, g n ^ e)) @[simp] lemma eval₂_zero : (0 : mv_polynomial σ α).eval₂ f g = 0 := finsupp.sum_zero_index section variables [is_semiring_hom f] @[simp] lemma eval₂_add : (p + q).eval₂ f g = p.eval₂ f g + q.eval₂ f g := finsupp.sum_add_index (by simp [is_semiring_hom.map_zero f]) (by simp [add_mul, is_semiring_hom.map_add f]) @[simp] lemma eval₂_monomial : (monomial s a).eval₂ f g = f a * s.prod (λn e, g n ^ e) := finsupp.sum_single_index (by simp [is_semiring_hom.map_zero f]) @[simp] lemma eval₂_C (a) : (C a).eval₂ f g = f a := by simp [eval₂_monomial, C, prod_zero_index] @[simp] lemma eval₂_one : (1 : mv_polynomial σ α).eval₂ f g = 1 := (eval₂_C _ _ _).trans (is_semiring_hom.map_one f) @[simp] lemma eval₂_X (n) : (X n).eval₂ f g = g n := by simp [eval₂_monomial, is_semiring_hom.map_one f, X, prod_single_index, pow_one] lemma eval₂_mul_monomial : ∀{s a}, (p * monomial s a).eval₂ f g = p.eval₂ f g * f a * s.prod (λn e, g n ^ e) := begin apply mv_polynomial.induction_on p, { assume a' s a, simp [C_mul_monomial, eval₂_monomial, is_semiring_hom.map_mul f] }, { assume p q ih_p ih_q, simp [add_mul, eval₂_add, ih_p, ih_q] }, { assume p n ih s a, from calc (p * X n * monomial s a).eval₂ f g = (p * monomial (single n 1 + s) a).eval₂ f g : by simp [monomial_single_add, -add_comm, pow_one, mul_assoc] ... = (p * monomial (single n 1) 1).eval₂ f g * f a * s.prod (λn e, g n ^ e) : by simp [ih, prod_single_index, prod_add_index, pow_one, pow_add, mul_assoc, mul_left_comm, is_semiring_hom.map_one f, -add_comm] } end @[simp] lemma eval₂_mul : ∀{p}, (p * q).eval₂ f g = p.eval₂ f g * q.eval₂ f g := begin apply mv_polynomial.induction_on q, { simp [C, eval₂_monomial, eval₂_mul_monomial, prod_zero_index] }, { simp [mul_add, eval₂_add] {contextual := tt} }, { simp [X, eval₂_monomial, eval₂_mul_monomial, (mul_assoc _ _ _).symm] { contextual := tt} } end @[simp] lemma eval₂_pow {p:mv_polynomial σ α} : ∀{n:ℕ}, (p ^ n).eval₂ f g = (p.eval₂ f g)^n | 0 := eval₂_one _ _ | (n + 1) := by rw [pow_add, pow_one, pow_add, pow_one, eval₂_mul, eval₂_pow] instance eval₂.is_semiring_hom : is_semiring_hom (eval₂ f g) := { map_zero := eval₂_zero _ _, map_one := eval₂_one _ _, map_add := λ p q, eval₂_add _ _, map_mul := λ p q, eval₂_mul _ _ } end lemma eval₂_comp_left {γ} [comm_semiring γ] (k : β → γ) [is_semiring_hom k] (f : α → β) [is_semiring_hom f] (g : σ → β) (p) : k (eval₂ f g p) = eval₂ (k ∘ f) (k ∘ g) p := by apply mv_polynomial.induction_on p; simp [ eval₂_add, is_semiring_hom.map_add k, eval₂_mul, is_semiring_hom.map_mul k] {contextual := tt} @[simp] lemma eval₂_eta (p : mv_polynomial σ α) : eval₂ C X p = p := by apply mv_polynomial.induction_on p; simp [eval₂_add, eval₂_mul] {contextual := tt} lemma eval₂_congr (g₁ g₂ : σ → β) (h : ∀ {i : σ} {c : σ →₀ ℕ}, i ∈ c.support → coeff c p ≠ 0 → g₁ i = g₂ i) : p.eval₂ f g₁ = p.eval₂ f g₂ := begin apply finset.sum_congr rfl, intros c hc, dsimp, congr' 1, apply finset.prod_congr rfl, intros i hi, dsimp, congr' 1, apply h hi, rwa finsupp.mem_support_iff at hc end variables [is_semiring_hom f] @[simp] lemma eval₂_prod (s : finset γ) (p : γ → mv_polynomial σ α) : eval₂ f g (s.prod p) = s.prod (λ x, eval₂ f g $ p x) := (finset.prod_hom _).symm @[simp] lemma eval₂_sum (s : finset γ) (p : γ → mv_polynomial σ α) : eval₂ f g (s.sum p) = s.sum (λ x, eval₂ f g $ p x) := (finset.sum_hom _).symm attribute [to_additive] eval₂_prod lemma eval₂_assoc (q : γ → mv_polynomial σ α) (p : mv_polynomial γ α) : eval₂ f (λ t, eval₂ f g (q t)) p = eval₂ f g (eval₂ C q p) := by { rw eval₂_comp_left (eval₂ f g), congr, funext, simp } end eval₂ section eval variables {f : σ → α} /-- Evaluate a polynomial `p` given a valuation `f` of all the variables -/ def eval (f : σ → α) : mv_polynomial σ α → α := eval₂ id f @[simp] lemma eval_zero : (0 : mv_polynomial σ α).eval f = 0 := eval₂_zero _ _ @[simp] lemma eval_add : (p + q).eval f = p.eval f + q.eval f := eval₂_add _ _ lemma eval_monomial : (monomial s a).eval f = a * s.prod (λn e, f n ^ e) := eval₂_monomial _ _ @[simp] lemma eval_C : ∀ a, (C a).eval f = a := eval₂_C _ _ @[simp] lemma eval_X : ∀ n, (X n).eval f = f n := eval₂_X _ _ @[simp] lemma eval_mul : (p * q).eval f = p.eval f * q.eval f := eval₂_mul _ _ instance eval.is_semiring_hom : is_semiring_hom (eval f) := eval₂.is_semiring_hom _ _ theorem eval_assoc {τ} (f : σ → mv_polynomial τ α) (g : τ → α) (p : mv_polynomial σ α) : p.eval (eval g ∘ f) = (eval₂ C f p).eval g := begin rw eval₂_comp_left (eval g), unfold eval, congr; funext a; simp end end eval section map variables [comm_semiring β] variables (f : α → β) /-- `map f p` maps a polynomial `p` across a ring hom `f` -/ def map : mv_polynomial σ α → mv_polynomial σ β := eval₂ (C ∘ f) X variables [is_semiring_hom f] @[simp] theorem map_monomial (s : σ →₀ ℕ) (a : α) : map f (monomial s a) = monomial s (f a) := (eval₂_monomial _ _).trans monomial_eq.symm @[simp] theorem map_C : ∀ (a : α), map f (C a : mv_polynomial σ α) = C (f a) := map_monomial _ _ @[simp] theorem map_X : ∀ (n : σ), map f (X n : mv_polynomial σ α) = X n := eval₂_X _ _ @[simp] theorem map_one : map f (1 : mv_polynomial σ α) = 1 := eval₂_one _ _ @[simp] theorem map_add (p q : mv_polynomial σ α) : map f (p + q) = map f p + map f q := eval₂_add _ _ @[simp] theorem map_mul (p q : mv_polynomial σ α) : map f (p * q) = map f p * map f q := eval₂_mul _ _ @[simp] lemma map_pow (p : mv_polynomial σ α) (n : ℕ) : map f (p^n) = (map f p)^n := eval₂_pow _ _ instance map.is_semiring_hom : is_semiring_hom (map f : mv_polynomial σ α → mv_polynomial σ β) := eval₂.is_semiring_hom _ _ theorem map_id : ∀ (p : mv_polynomial σ α), map id p = p := eval₂_eta theorem map_map [comm_semiring γ] (g : β → γ) [is_semiring_hom g] (p : mv_polynomial σ α) : map g (map f p) = map (g ∘ f) p := (eval₂_comp_left (map g) (C ∘ f) X p).trans $ by congr; funext a; simp theorem eval₂_eq_eval_map (g : σ → β) (p : mv_polynomial σ α) : p.eval₂ f g = (map f p).eval g := begin unfold map eval, rw eval₂_comp_left (eval₂ id g), congr; funext a; simp end lemma eval₂_comp_right {γ} [comm_semiring γ] (k : β → γ) [is_semiring_hom k] (f : α → β) [is_semiring_hom f] (g : σ → β) (p) : k (eval₂ f g p) = eval₂ k (k ∘ g) (map f p) := begin apply mv_polynomial.induction_on p, { intro r, rw [eval₂_C, map_C, eval₂_C] }, { intros p q hp hq, rw [eval₂_add, is_semiring_hom.map_add k, map_add, eval₂_add, hp, hq] }, { intros p s hp, rw [eval₂_mul, is_semiring_hom.map_mul k, map_mul, eval₂_mul, map_X, hp, eval₂_X, eval₂_X] } end lemma map_eval₂ (f : α → β) [is_semiring_hom f] (g : γ → mv_polynomial δ α) (p : mv_polynomial γ α) : map f (eval₂ C g p) = eval₂ C (map f ∘ g) (map f p) := begin apply mv_polynomial.induction_on p, { intro r, rw [eval₂_C, map_C, map_C, eval₂_C] }, { intros p q hp hq, rw [eval₂_add, map_add, hp, hq, map_add, eval₂_add] }, { intros p s hp, rw [eval₂_mul, map_mul, hp, map_mul, map_X, eval₂_mul, eval₂_X, eval₂_X] } end lemma coeff_map (p : mv_polynomial σ α) : ∀ (m : σ →₀ ℕ), coeff m (p.map f) = f (coeff m p) := begin apply mv_polynomial.induction_on p; clear p, { intros r m, rw [map_C], simp only [coeff_C], split_ifs, {refl}, rw is_semiring_hom.map_zero f }, { intros p q hp hq m, simp only [hp, hq, map_add, coeff_add], rw is_semiring_hom.map_add f }, { intros p i hp m, simp only [hp, map_mul, map_X], simp only [hp, mem_support_iff, coeff_mul_X'], split_ifs, {refl}, rw is_semiring_hom.map_zero f } end lemma map_injective (hf : function.injective f) : function.injective (map f : mv_polynomial σ α → mv_polynomial σ β) := λ p q h, ext _ _ $ λ m, hf $ begin rw ← ext_iff at h, specialize h m, rw [coeff_map, coeff_map] at h, exact h end end map section degrees section comm_semiring /-- The maximal degrees of each variable in a multi-variable polynomial, expressed as a multiset. (For example, `degrees (x^2 * y + y^3)` would be `{x, x, y, y, y}`.) -/ def degrees (p : mv_polynomial σ α) : multiset σ := p.support.sup (λs:σ →₀ ℕ, s.to_multiset) lemma degrees_monomial (s : σ →₀ ℕ) (a : α) : degrees (monomial s a) ≤ s.to_multiset := finset.sup_le $ assume t h, begin have := finsupp.support_single_subset h, rw [finset.singleton_eq_singleton, finset.mem_singleton] at this, rw this end lemma degrees_monomial_eq (s : σ →₀ ℕ) (a : α) (ha : a ≠ 0) : degrees (monomial s a) = s.to_multiset := le_antisymm (degrees_monomial s a) $ finset.le_sup $ by rw [monomial, finsupp.support_single_ne_zero ha, finset.singleton_eq_singleton, finset.mem_singleton] lemma degrees_C (a : α) : degrees (C a : mv_polynomial σ α) = 0 := multiset.le_zero.1 $ degrees_monomial _ _ lemma degrees_X (n : σ) : degrees (X n : mv_polynomial σ α) ≤ {n} := le_trans (degrees_monomial _ _) $ le_of_eq $ to_multiset_single _ _ lemma degrees_zero : degrees (0 : mv_polynomial σ α) = 0 := by { rw ← C_0, exact degrees_C 0 } lemma degrees_one : degrees (1 : mv_polynomial σ α) = 0 := degrees_C 1 lemma degrees_add (p q : mv_polynomial σ α) : (p + q).degrees ≤ p.degrees ⊔ q.degrees := begin refine finset.sup_le (assume b hb, _), have := finsupp.support_add hb, rw finset.mem_union at this, cases this, { exact le_sup_left_of_le (finset.le_sup this) }, { exact le_sup_right_of_le (finset.le_sup this) }, end lemma degrees_sum {ι : Type*} (s : finset ι) (f : ι → mv_polynomial σ α) : (s.sum f).degrees ≤ s.sup (λi, (f i).degrees) := begin refine s.induction _ _, { simp only [finset.sum_empty, finset.sup_empty, degrees_zero], exact le_refl _ }, { assume i s his ih, rw [finset.sup_insert, finset.sum_insert his], exact le_trans (degrees_add _ _) (sup_le_sup_left ih _) } end lemma degrees_mul (p q : mv_polynomial σ α) : (p * q).degrees ≤ p.degrees + q.degrees := begin refine finset.sup_le (assume b hb, _), have := support_mul p q hb, simp only [finset.mem_bind, finset.singleton_eq_singleton, finset.mem_singleton] at this, rcases this with ⟨a₁, h₁, a₂, h₂, rfl⟩, rw [finsupp.to_multiset_add], exact add_le_add (finset.le_sup h₁) (finset.le_sup h₂) end lemma degrees_prod {ι : Type*} (s : finset ι) (f : ι → mv_polynomial σ α) : (s.prod f).degrees ≤ s.sum (λi, (f i).degrees) := begin refine s.induction _ _, { simp only [finset.prod_empty, finset.sum_empty, degrees_one] }, { assume i s his ih, rw [finset.prod_insert his, finset.sum_insert his], exact le_trans (degrees_mul _ _) (add_le_add_left ih _) } end lemma degrees_pow (p : mv_polynomial σ α) : ∀(n : ℕ), (p^n).degrees ≤ add_monoid.smul n p.degrees | 0 := begin rw [pow_zero, degrees_one], exact multiset.zero_le _ end | (n + 1) := le_trans (degrees_mul _ _) (add_le_add_left (degrees_pow n) _) end comm_semiring end degrees section vars /-- `vars p` is the set of variables appearing in the polynomial `p` -/ def vars (p : mv_polynomial σ α) : finset σ := p.degrees.to_finset @[simp] lemma vars_0 : (0 : mv_polynomial σ α).vars = ∅ := by rw [vars, degrees_zero, multiset.to_finset_zero] @[simp] lemma vars_monomial (h : a ≠ 0) : (monomial s a).vars = s.support := by rw [vars, degrees_monomial_eq _ _ h, finsupp.to_finset_to_multiset] @[simp] lemma vars_C : (C a : mv_polynomial σ α).vars = ∅ := by rw [vars, degrees_C, multiset.to_finset_zero] @[simp] lemma vars_X (h : 0 ≠ (1 : α)) : (X n : mv_polynomial σ α).vars = {n} := by rw [X, vars_monomial h.symm, finsupp.support_single_ne_zero zero_ne_one.symm] end vars section degree_of /-- `degree_of n p` gives the highest power of X_n that appears in `p` -/ def degree_of (n : σ) (p : mv_polynomial σ α) : ℕ := p.degrees.count n end degree_of section total_degree /-- `total_degree p` gives the maximum |s| over the monomials X^s in `p` -/ def total_degree (p : mv_polynomial σ α) : ℕ := p.support.sup (λs, s.sum $ λn e, e) lemma total_degree_eq (p : mv_polynomial σ α) : p.total_degree = p.support.sup (λm, m.to_multiset.card) := begin rw [total_degree], congr, funext m, exact (finsupp.card_to_multiset _).symm end lemma total_degree_le_degrees_card (p : mv_polynomial σ α) : p.total_degree ≤ p.degrees.card := begin rw [total_degree_eq], exact finset.sup_le (assume s hs, multiset.card_le_of_le $ finset.le_sup hs) end lemma total_degree_C (a : α) : (C a : mv_polynomial σ α).total_degree = 0 := nat.eq_zero_of_le_zero $ finset.sup_le $ assume n hn, have _ := finsupp.support_single_subset hn, begin rw [finset.singleton_eq_singleton, finset.mem_singleton] at this, subst this, exact le_refl _ end lemma total_degree_zero : (0 : mv_polynomial σ α).total_degree = 0 := by rw [← C_0]; exact total_degree_C (0 : α) lemma total_degree_one : (1 : mv_polynomial σ α).total_degree = 0 := total_degree_C (1 : α) lemma total_degree_add (a b : mv_polynomial σ α) : (a + b).total_degree ≤ max a.total_degree b.total_degree := finset.sup_le $ assume n hn, have _ := finsupp.support_add hn, begin rw finset.mem_union at this, cases this, { exact le_max_left_of_le (finset.le_sup this) }, { exact le_max_right_of_le (finset.le_sup this) } end lemma total_degree_mul (a b : mv_polynomial σ α) : (a * b).total_degree ≤ a.total_degree + b.total_degree := finset.sup_le $ assume n hn, have _ := finsupp.support_mul a b hn, begin simp only [finset.mem_bind, finset.mem_singleton, finset.singleton_eq_singleton] at this, rcases this with ⟨a₁, h₁, a₂, h₂, rfl⟩, rw [finsupp.sum_add_index], { exact add_le_add (finset.le_sup h₁) (finset.le_sup h₂) }, { assume a, refl }, { assume a b₁ b₂, refl } end lemma total_degree_list_prod : ∀(s : list (mv_polynomial σ α)), s.prod.total_degree ≤ (s.map mv_polynomial.total_degree).sum | [] := by rw [@list.prod_nil (mv_polynomial σ α) _, total_degree_one]; refl | (p :: ps) := begin rw [@list.prod_cons (mv_polynomial σ α) _, list.map, list.sum_cons], exact le_trans (total_degree_mul _ _) (add_le_add_left (total_degree_list_prod ps) _) end lemma total_degree_multiset_prod (s : multiset (mv_polynomial σ α)) : s.prod.total_degree ≤ (s.map mv_polynomial.total_degree).sum := begin refine quotient.induction_on s (assume l, _), rw [multiset.quot_mk_to_coe, multiset.coe_prod, multiset.coe_map, multiset.coe_sum], exact total_degree_list_prod l end lemma total_degree_finset_prod {ι : Type*} (s : finset ι) (f : ι → mv_polynomial σ α) : (s.prod f).total_degree ≤ s.sum (λi, (f i).total_degree) := begin refine le_trans (total_degree_multiset_prod _) _, rw [multiset.map_map], refl end end total_degree end comm_semiring section comm_ring variable [comm_ring α] variables {p q : mv_polynomial σ α} instance : ring (mv_polynomial σ α) := finsupp.ring instance : comm_ring (mv_polynomial σ α) := finsupp.comm_ring instance : has_scalar α (mv_polynomial σ α) := finsupp.has_scalar instance : module α (mv_polynomial σ α) := finsupp.module _ α instance C.is_ring_hom : is_ring_hom (C : α → mv_polynomial σ α) := by apply is_ring_hom.of_semiring variables (σ a a') lemma C_sub : (C (a - a') : mv_polynomial σ α) = C a - C a' := is_ring_hom.map_sub _ @[simp] lemma C_neg : (C (-a) : mv_polynomial σ α) = -C a := is_ring_hom.map_neg _ @[simp] lemma coeff_sub (m : σ →₀ ℕ) (p q : mv_polynomial σ α) : coeff m (p - q) = coeff m p - coeff m q := finsupp.sub_apply instance coeff.is_add_group_hom (m : σ →₀ ℕ) : is_add_group_hom (coeff m : mv_polynomial σ α → α) := { map_add := coeff_add m } variables {σ} (p) theorem C_mul' : mv_polynomial.C a * p = a • p := begin apply finsupp.induction p, { exact (mul_zero $ mv_polynomial.C a).trans (@smul_zero α (mv_polynomial σ α) _ _ _ a).symm }, intros p b f haf hb0 ih, rw [mul_add, ih, @smul_add α (mv_polynomial σ α) _ _ _ a], congr' 1, rw [finsupp.mul_def, finsupp.smul_single, mv_polynomial.C, mv_polynomial.monomial], rw [finsupp.sum_single_index, finsupp.sum_single_index, zero_add, smul_eq_mul], { rw [mul_zero, finsupp.single_zero] }, { rw finsupp.sum_single_index, all_goals { rw [zero_mul, finsupp.single_zero] } } end lemma smul_eq_C_mul (p : mv_polynomial σ α) (a : α) : a • p = C a * p := begin rw [← finsupp.sum_single p, @finsupp.smul_sum (σ →₀ ℕ) α α, finsupp.mul_sum], refine finset.sum_congr rfl (assume n _, _), simp only [finsupp.smul_single], exact C_mul_monomial.symm end @[simp] lemma smul_eval (x) (p : mv_polynomial σ α) (s) : (s • p).eval x = s * p.eval x := by rw [smul_eq_C_mul, eval_mul, eval_C] section degrees lemma degrees_neg (p : mv_polynomial σ α) : (- p).degrees = p.degrees := by rw [degrees, finsupp.support_neg]; refl lemma degrees_sub (p q : mv_polynomial σ α) : (p - q).degrees ≤ p.degrees ⊔ q.degrees := le_trans (degrees_add p (-q)) $ by rw [degrees_neg] end degrees section eval₂ variables [comm_ring β] variables (f : α → β) [is_ring_hom f] (g : σ → β) instance eval₂.is_ring_hom : is_ring_hom (eval₂ f g) := by apply is_ring_hom.of_semiring lemma eval₂_sub : (p - q).eval₂ f g = p.eval₂ f g - q.eval₂ f g := is_ring_hom.map_sub _ @[simp] lemma eval₂_neg : (-p).eval₂ f g = -(p.eval₂ f g) := is_ring_hom.map_neg _ lemma hom_C (f : mv_polynomial σ ℤ → β) [is_ring_hom f] (n : ℤ) : f (C n) = (n : β) := congr_fun (int.eq_cast' (f ∘ C)) n /-- A ring homomorphism f : Z[X_1, X_2, ...] → R is determined by the evaluations f(X_1), f(X_2), ... -/ @[simp] lemma eval₂_hom_X {α : Type u} (c : ℤ → β) [is_ring_hom c] (f : mv_polynomial α ℤ → β) [is_ring_hom f] (x : mv_polynomial α ℤ) : eval₂ c (f ∘ X) x = f x := mv_polynomial.induction_on x (λ n, by { rw [hom_C f, eval₂_C, int.eq_cast' c], refl }) (λ p q hp hq, by { rw [eval₂_add, hp, hq], exact (is_ring_hom.map_add f).symm }) (λ p n hp, by { rw [eval₂_mul, eval₂_X, hp], exact (is_ring_hom.map_mul f).symm }) /-- Ring homomorphisms out of integer polynomials on a type `σ` are the same as functions out of the type `σ`, -/ def hom_equiv : (mv_polynomial σ ℤ →+* β) ≃ (σ → β) := { to_fun := λ f, ⇑f ∘ X, inv_fun := λ f, ring_hom.of (eval₂ (λ n : ℤ, (n : β)) f), left_inv := λ f, ring_hom.ext $ eval₂_hom_X _ _, right_inv := λ f, funext $ λ x, by simp only [ring_hom.coe_of, function.comp_app, eval₂_X] } end eval₂ section eval variables (f : σ → α) instance eval.is_ring_hom : is_ring_hom (eval f) := eval₂.is_ring_hom _ _ lemma eval_sub : (p - q).eval f = p.eval f - q.eval f := is_ring_hom.map_sub _ @[simp] lemma eval_neg : (-p).eval f = -(p.eval f) := is_ring_hom.map_neg _ end eval section map variables [comm_ring β] variables (f : α → β) [is_ring_hom f] instance map.is_ring_hom : is_ring_hom (map f : mv_polynomial σ α → mv_polynomial σ β) := eval₂.is_ring_hom _ _ lemma map_sub : (p - q).map f = p.map f - q.map f := is_ring_hom.map_sub _ @[simp] lemma map_neg : (-p).map f = -(p.map f) := is_ring_hom.map_neg _ end map end comm_ring section rename variables {α} [comm_semiring α] /-- Rename all the variables in a multivariable polynomial. -/ def rename (f : β → γ) : mv_polynomial β α → mv_polynomial γ α := eval₂ C (X ∘ f) instance rename.is_semiring_hom (f : β → γ) : is_semiring_hom (rename f : mv_polynomial β α → mv_polynomial γ α) := by unfold rename; apply_instance @[simp] lemma rename_C (f : β → γ) (a : α) : rename f (C a) = C a := eval₂_C _ _ _ @[simp] lemma rename_X (f : β → γ) (b : β) : rename f (X b : mv_polynomial β α) = X (f b) := eval₂_X _ _ _ @[simp] lemma rename_zero (f : β → γ) : rename f (0 : mv_polynomial β α) = 0 := eval₂_zero _ _ @[simp] lemma rename_one (f : β → γ) : rename f (1 : mv_polynomial β α) = 1 := eval₂_one _ _ @[simp] lemma rename_add (f : β → γ) (p q : mv_polynomial β α) : rename f (p + q) = rename f p + rename f q := eval₂_add _ _ @[simp] lemma rename_sub {α} [comm_ring α] (f : β → γ) (p q : mv_polynomial β α) : rename f (p - q) = rename f p - rename f q := eval₂_sub _ _ _ @[simp] lemma rename_mul (f : β → γ) (p q : mv_polynomial β α) : rename f (p * q) = rename f p * rename f q := eval₂_mul _ _ @[simp] lemma rename_pow (f : β → γ) (p : mv_polynomial β α) (n : ℕ) : rename f (p^n) = (rename f p)^n := eval₂_pow _ _ lemma map_rename [comm_semiring β] (f : α → β) [is_semiring_hom f] (g : γ → δ) (p : mv_polynomial γ α) : map f (rename g p) = rename g (map f p) := mv_polynomial.induction_on p (λ a, by simp) (λ p q hp hq, by simp [hp, hq]) (λ p n hp, by simp [hp]) @[simp] lemma rename_rename (f : β → γ) (g : γ → δ) (p : mv_polynomial β α) : rename g (rename f p) = rename (g ∘ f) p := show rename g (eval₂ C (X ∘ f) p) = _, by simp only [eval₂_comp_left (rename g) C (X ∘ f) p, (∘), rename_C, rename_X]; refl @[simp] lemma rename_id (p : mv_polynomial β α) : rename id p = p := eval₂_eta p lemma rename_monomial (f : β → γ) (p : β →₀ ℕ) (a : α) : rename f (monomial p a) = monomial (p.map_domain f) a := begin rw [rename, eval₂_monomial, monomial_eq, finsupp.prod_map_domain_index], { exact assume n, pow_zero _ }, { exact assume n i₁ i₂, pow_add _ _ _ } end lemma rename_eq (f : β → γ) (p : mv_polynomial β α) : rename f p = finsupp.map_domain (finsupp.map_domain f) p := begin simp only [rename, eval₂, finsupp.map_domain], congr, ext s a : 2, rw [← monomial, monomial_eq, finsupp.prod_sum_index], congr, ext n i : 2, rw [finsupp.prod_single_index], exact pow_zero _, exact assume a, pow_zero _, exact assume a b c, pow_add _ _ _ end lemma injective_rename (f : β → γ) (hf : function.injective f) : function.injective (rename f : mv_polynomial β α → mv_polynomial γ α) := have (rename f : mv_polynomial β α → mv_polynomial γ α) = finsupp.map_domain (finsupp.map_domain f) := funext (rename_eq f), begin rw this, exact finsupp.injective_map_domain (finsupp.injective_map_domain hf) end lemma total_degree_rename_le (f : β → γ) (p : mv_polynomial β α) : (p.rename f).total_degree ≤ p.total_degree := finset.sup_le $ assume b, begin assume h, rw rename_eq at h, have h' := finsupp.map_domain_support h, rw finset.mem_image at h', rcases h' with ⟨s, hs, rfl⟩, rw finsupp.sum_map_domain_index, exact le_trans (le_refl _) (finset.le_sup hs), exact assume _, rfl, exact assume _ _ _, rfl end section variables [comm_semiring β] (f : α → β) [is_semiring_hom f] variables (k : γ → δ) (g : δ → β) (p : mv_polynomial γ α) lemma eval₂_rename : (p.rename k).eval₂ f g = p.eval₂ f (g ∘ k) := by apply mv_polynomial.induction_on p; { intros, simp [*] } lemma rename_eval₂ (g : δ → mv_polynomial γ α) : (p.eval₂ C (g ∘ k)).rename k = (p.rename k).eval₂ C (rename k ∘ g) := by apply mv_polynomial.induction_on p; { intros, simp [*] } lemma rename_prodmk_eval₂ (d : δ) (g : γ → mv_polynomial γ α) : (p.eval₂ C g).rename (prod.mk d) = p.eval₂ C (λ x, (g x).rename (prod.mk d)) := by apply mv_polynomial.induction_on p; { intros, simp [*] } lemma eval₂_rename_prodmk (g : δ × γ → β) (d : δ) : (rename (prod.mk d) p).eval₂ f g = eval₂ f (λ i, g (d, i)) p := by apply mv_polynomial.induction_on p; { intros, simp [*] } lemma eval_rename_prodmk (g : δ × γ → α) (d : δ) : (rename (prod.mk d) p).eval g = eval (λ i, g (d, i)) p := eval₂_rename_prodmk id _ _ _ end end rename lemma eval₂_cast_comp {β : Type u} {γ : Type v} (f : γ → β) {α : Type w} [comm_ring α] (c : ℤ → α) [is_ring_hom c] (g : β → α) (x : mv_polynomial γ ℤ) : eval₂ c (g ∘ f) x = eval₂ c g (rename f x) := mv_polynomial.induction_on x (λ n, by simp only [eval₂_C, rename_C]) (λ p q hp hq, by simp only [hp, hq, rename, eval₂_add]) (λ p n hp, by simp only [hp, rename, eval₂_X, eval₂_mul]) instance rename.is_ring_hom {α} [comm_ring α] (f : β → γ) : is_ring_hom (rename f : mv_polynomial β α → mv_polynomial γ α) := @is_ring_hom.of_semiring (mv_polynomial β α) (mv_polynomial γ α) _ _ (rename f) (rename.is_semiring_hom f) section equiv variables (α) [comm_semiring α] /-- The ring isomorphism between multivariable polynomials in no variables and the ground ring. -/ def pempty_ring_equiv : mv_polynomial pempty α ≃+* α := { to_fun := mv_polynomial.eval₂ id $ pempty.elim, inv_fun := C, left_inv := is_id _ (by apply_instance) (assume a, by rw [eval₂_C]; refl) (assume a, a.elim), right_inv := λ r, eval₂_C _ _ _, map_mul' := λ _ _, eval₂_mul _ _, map_add' := λ _ _, eval₂_add _ _ } /-- The ring isomorphism between multivariable polynomials in a single variable and polynomials over the ground ring. -/ def punit_ring_equiv : mv_polynomial punit α ≃+* polynomial α := { to_fun := eval₂ polynomial.C (λu:punit, polynomial.X), inv_fun := polynomial.eval₂ mv_polynomial.C (X punit.star), left_inv := begin refine is_id _ _ _ _, apply is_semiring_hom.comp (eval₂ polynomial.C (λu:punit, polynomial.X)) _; apply_instance, { assume a, rw [eval₂_C, polynomial.eval₂_C] }, { rintros ⟨⟩, rw [eval₂_X, polynomial.eval₂_X] } end, right_inv := assume p, polynomial.induction_on p (assume a, by rw [polynomial.eval₂_C, mv_polynomial.eval₂_C]) (assume p q hp hq, by rw [polynomial.eval₂_add, mv_polynomial.eval₂_add, hp, hq]) (assume p n hp, by rw [polynomial.eval₂_mul, polynomial.eval₂_pow, polynomial.eval₂_X, polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X]), map_mul' := λ _ _, eval₂_mul _ _, map_add' := λ _ _, eval₂_add _ _ } /-- The ring isomorphism between multivariable polynomials induced by an equivalence of the variables. -/ def ring_equiv_of_equiv (e : β ≃ γ) : mv_polynomial β α ≃+* mv_polynomial γ α := { to_fun := rename e, inv_fun := rename e.symm, left_inv := λ p, by simp only [rename_rename, (∘), e.symm_apply_apply]; exact rename_id p, right_inv := λ p, by simp only [rename_rename, (∘), e.apply_symm_apply]; exact rename_id p, map_mul' := rename_mul e, map_add' := rename_add e } /-- The ring isomorphism between multivariable polynomials induced by a ring isomorphism of the ground ring. -/ def ring_equiv_congr [comm_semiring γ] (e : α ≃+* γ) : mv_polynomial β α ≃+* mv_polynomial β γ := { to_fun := map e, inv_fun := map e.symm, left_inv := assume p, have (e.symm ∘ e) = id, { ext a, exact e.symm_apply_apply a }, by simp only [map_map, this, map_id], right_inv := assume p, have (e ∘ e.symm) = id, { ext a, exact e.apply_symm_apply a }, by simp only [map_map, this, map_id], map_mul' := map_mul _, map_add' := map_add _ } section variables (β γ δ) /-- The function from multivariable polynomials in a sum of two types, to multivariable polynomials in one of the types, with coefficents in multivariable polynomials in the other type. See `sum_ring_equiv` for the ring isomorphism. -/ def sum_to_iter : mv_polynomial (β ⊕ γ) α → mv_polynomial β (mv_polynomial γ α) := eval₂ (C ∘ C) (λbc, sum.rec_on bc X (C ∘ X)) instance is_semiring_hom_C_C : is_semiring_hom (C ∘ C : α → mv_polynomial β (mv_polynomial γ α)) := @is_semiring_hom.comp _ _ _ _ C mv_polynomial.is_semiring_hom _ _ C mv_polynomial.is_semiring_hom instance is_semiring_hom_sum_to_iter : is_semiring_hom (sum_to_iter α β γ) := eval₂.is_semiring_hom _ _ lemma sum_to_iter_C (a : α) : sum_to_iter α β γ (C a) = C (C a) := eval₂_C _ _ a lemma sum_to_iter_Xl (b : β) : sum_to_iter α β γ (X (sum.inl b)) = X b := eval₂_X _ _ (sum.inl b) lemma sum_to_iter_Xr (c : γ) : sum_to_iter α β γ (X (sum.inr c)) = C (X c) := eval₂_X _ _ (sum.inr c) /-- The function from multivariable polynomials in one type, with coefficents in multivariable polynomials in another type, to multivariable polynomials in the sum of the two types. See `sum_ring_equiv` for the ring isomorphism. -/ def iter_to_sum : mv_polynomial β (mv_polynomial γ α) → mv_polynomial (β ⊕ γ) α := eval₂ (eval₂ C (X ∘ sum.inr)) (X ∘ sum.inl) instance is_semiring_hom_iter_to_sum : is_semiring_hom (iter_to_sum α β γ) := eval₂.is_semiring_hom _ _ lemma iter_to_sum_C_C (a : α) : iter_to_sum α β γ (C (C a)) = C a := eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) lemma iter_to_sum_X (b : β) : iter_to_sum α β γ (X b) = X (sum.inl b) := eval₂_X _ _ _ lemma iter_to_sum_C_X (c : γ) : iter_to_sum α β γ (C (X c)) = X (sum.inr c) := eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) /-- A helper function for `sum_ring_equiv`. -/ def mv_polynomial_equiv_mv_polynomial [comm_semiring δ] (f : mv_polynomial β α → mv_polynomial γ δ) (hf : is_semiring_hom f) (g : mv_polynomial γ δ → mv_polynomial β α) (hg : is_semiring_hom g) (hfgC : ∀a, f (g (C a)) = C a) (hfgX : ∀n, f (g (X n)) = X n) (hgfC : ∀a, g (f (C a)) = C a) (hgfX : ∀n, g (f (X n)) = X n) : mv_polynomial β α ≃+* mv_polynomial γ δ := { to_fun := f, inv_fun := g, left_inv := is_id _ (is_semiring_hom.comp _ _) hgfC hgfX, right_inv := is_id _ (is_semiring_hom.comp _ _) hfgC hfgX, map_mul' := hf.map_mul, map_add' := hf.map_add } /-- The ring isomorphism between multivariable polynomials in a sum of two types, and multivariable polynomials in one of the types, with coefficents in multivariable polynomials in the other type. -/ def sum_ring_equiv : mv_polynomial (β ⊕ γ) α ≃+* mv_polynomial β (mv_polynomial γ α) := begin apply @mv_polynomial_equiv_mv_polynomial α (β ⊕ γ) _ _ _ _ (sum_to_iter α β γ) _ (iter_to_sum α β γ) _, { assume p, apply hom_eq_hom _ _ _ _ _ _ p, apply_instance, { apply @is_semiring_hom.comp _ _ _ _ _ _ _ _ _ _, apply_instance, apply @is_semiring_hom.comp _ _ _ _ _ _ _ _ _ _, apply_instance, { apply @mv_polynomial.is_semiring_hom }, { apply mv_polynomial.is_semiring_hom_iter_to_sum α β γ }, { apply mv_polynomial.is_semiring_hom_sum_to_iter α β γ } }, { apply mv_polynomial.is_semiring_hom }, { assume a, rw [iter_to_sum_C_C α β γ, sum_to_iter_C α β γ] }, { assume c, rw [iter_to_sum_C_X α β γ, sum_to_iter_Xr α β γ] } }, { assume b, rw [iter_to_sum_X α β γ, sum_to_iter_Xl α β γ] }, { assume a, rw [sum_to_iter_C α β γ, iter_to_sum_C_C α β γ] }, { assume n, cases n with b c, { rw [sum_to_iter_Xl, iter_to_sum_X] }, { rw [sum_to_iter_Xr, iter_to_sum_C_X] } }, { apply mv_polynomial.is_semiring_hom_sum_to_iter α β γ }, { apply mv_polynomial.is_semiring_hom_iter_to_sum α β γ } end /-- The ring isomorphism between multivariable polynomials in `option β` and polynomials with coefficients in `mv_polynomial β α`. -/ def option_equiv_left : mv_polynomial (option β) α ≃+* polynomial (mv_polynomial β α) := (ring_equiv_of_equiv α $ (equiv.option_equiv_sum_punit β).trans (equiv.sum_comm _ _)).trans $ (sum_ring_equiv α _ _).trans $ punit_ring_equiv _ /-- The ring isomorphism between multivariable polynomials in `option β` and multivariable polynomials with coefficients in polynomials. -/ def option_equiv_right : mv_polynomial (option β) α ≃+* mv_polynomial β (polynomial α) := (ring_equiv_of_equiv α $ equiv.option_equiv_sum_punit.{0} β).trans $ (sum_ring_equiv α β unit).trans $ ring_equiv_congr (mv_polynomial unit α) (punit_ring_equiv α) end end equiv end mv_polynomial
2cfac3cd08cdacb5b326244458f4e074c593619c
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/measure_theory/group/measurable_equiv.lean
baa7f9a11cbb4cf27d635c892f90d137365a33d4
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
8,017
lean
/- Copyright (c) 2021 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import measure_theory.group.arithmetic /-! # (Scalar) multiplication and (vector) addition as measurable equivalences > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. In this file we define the following measurable equivalences: * `measurable_equiv.smul`: if a group `G` acts on `α` by measurable maps, then each element `c : G` defines a measurable automorphism of `α`; * `measurable_equiv.vadd`: additive version of `measurable_equiv.smul`; * `measurable_equiv.smul₀`: if a group with zero `G` acts on `α` by measurable maps, then each nonzero element `c : G` defines a measurable automorphism of `α`; * `measurable_equiv.mul_left`: if `G` is a group with measurable multiplication, then left multiplication by `g : G` is a measurable automorphism of `G`; * `measurable_equiv.add_left`: additive version of `measurable_equiv.mul_left`; * `measurable_equiv.mul_right`: if `G` is a group with measurable multiplication, then right multiplication by `g : G` is a measurable automorphism of `G`; * `measurable_equiv.add_right`: additive version of `measurable_equiv.mul_right`; * `measurable_equiv.mul_left₀`, `measurable_equiv.mul_right₀`: versions of `measurable_equiv.mul_left` and `measurable_equiv.mul_right` for groups with zero; * `measurable_equiv.inv`: `has_inv.inv` as a measurable automorphism of a group (or a group with zero); * `measurable_equiv.neg`: negation as a measurable automorphism of an additive group. We also deduce that the corresponding maps are measurable embeddings. ## Tags measurable, equivalence, group action -/ namespace measurable_equiv variables {G G₀ α : Type*} [measurable_space G] [measurable_space G₀] [measurable_space α] [group G] [group_with_zero G₀] [mul_action G α] [mul_action G₀ α] [has_measurable_smul G α] [has_measurable_smul G₀ α] /-- If a group `G` acts on `α` by measurable maps, then each element `c : G` defines a measurable automorphism of `α`. -/ @[to_additive "If an additive group `G` acts on `α` by measurable maps, then each element `c : G` defines a measurable automorphism of `α`.", simps to_equiv apply { fully_applied := ff }] def smul (c : G) : α ≃ᵐ α := { to_equiv := mul_action.to_perm c, measurable_to_fun := measurable_const_smul c, measurable_inv_fun := measurable_const_smul c⁻¹ } @[to_additive] lemma _root_.measurable_embedding_const_smul (c : G) : measurable_embedding ((•) c : α → α) := (smul c).measurable_embedding @[simp, to_additive] lemma symm_smul (c : G) : (smul c : α ≃ᵐ α).symm = smul c⁻¹ := ext rfl /-- If a group with zero `G₀` acts on `α` by measurable maps, then each nonzero element `c : G₀` defines a measurable automorphism of `α` -/ def smul₀ (c : G₀) (hc : c ≠ 0) : α ≃ᵐ α := measurable_equiv.smul (units.mk0 c hc) @[simp] lemma coe_smul₀ {c : G₀} (hc : c ≠ 0) : ⇑(smul₀ c hc : α ≃ᵐ α) = (•) c := rfl @[simp] lemma symm_smul₀ {c : G₀} (hc : c ≠ 0) : (smul₀ c hc : α ≃ᵐ α).symm = smul₀ c⁻¹ (inv_ne_zero hc) := ext rfl lemma _root_.measurable_embedding_const_smul₀ {c : G₀} (hc : c ≠ 0) : measurable_embedding ((•) c : α → α) := (smul₀ c hc).measurable_embedding section mul variables [has_measurable_mul G] [has_measurable_mul G₀] /-- If `G` is a group with measurable multiplication, then left multiplication by `g : G` is a measurable automorphism of `G`. -/ @[to_additive "If `G` is an additive group with measurable addition, then addition of `g : G` on the left is a measurable automorphism of `G`."] def mul_left (g : G) : G ≃ᵐ G := smul g @[simp, to_additive] lemma coe_mul_left (g : G) : ⇑(mul_left g) = (*) g := rfl @[simp, to_additive] lemma symm_mul_left (g : G) : (mul_left g).symm = mul_left g⁻¹ := ext rfl @[simp, to_additive] lemma to_equiv_mul_left (g : G) : (mul_left g).to_equiv = equiv.mul_left g := rfl @[to_additive] lemma _root_.measurable_embedding_mul_left (g : G) : measurable_embedding ((*) g) := (mul_left g).measurable_embedding /-- If `G` is a group with measurable multiplication, then right multiplication by `g : G` is a measurable automorphism of `G`. -/ @[to_additive "If `G` is an additive group with measurable addition, then addition of `g : G` on the right is a measurable automorphism of `G`."] def mul_right (g : G) : G ≃ᵐ G := { to_equiv := equiv.mul_right g, measurable_to_fun := measurable_mul_const g, measurable_inv_fun := measurable_mul_const g⁻¹ } @[to_additive] lemma _root_.measurable_embedding_mul_right (g : G) : measurable_embedding (λ x, x * g) := (mul_right g).measurable_embedding @[simp, to_additive] lemma coe_mul_right (g : G) : ⇑(mul_right g) = (λ x, x * g) := rfl @[simp, to_additive] lemma symm_mul_right (g : G) : (mul_right g).symm = mul_right g⁻¹ := ext rfl @[simp, to_additive] lemma to_equiv_mul_right (g : G) : (mul_right g).to_equiv = equiv.mul_right g := rfl /-- If `G₀` is a group with zero with measurable multiplication, then left multiplication by a nonzero element `g : G₀` is a measurable automorphism of `G₀`. -/ def mul_left₀ (g : G₀) (hg : g ≠ 0) : G₀ ≃ᵐ G₀ := smul₀ g hg lemma _root_.measurable_embedding_mul_left₀ {g : G₀} (hg : g ≠ 0) : measurable_embedding ((*) g) := (mul_left₀ g hg).measurable_embedding @[simp] lemma coe_mul_left₀ {g : G₀} (hg : g ≠ 0) : ⇑(mul_left₀ g hg) = (*) g := rfl @[simp] lemma symm_mul_left₀ {g : G₀} (hg : g ≠ 0) : (mul_left₀ g hg).symm = mul_left₀ g⁻¹ (inv_ne_zero hg) := ext rfl @[simp] lemma to_equiv_mul_left₀ {g : G₀} (hg : g ≠ 0) : (mul_left₀ g hg).to_equiv = equiv.mul_left₀ g hg := rfl /-- If `G₀` is a group with zero with measurable multiplication, then right multiplication by a nonzero element `g : G₀` is a measurable automorphism of `G₀`. -/ def mul_right₀ (g : G₀) (hg : g ≠ 0) : G₀ ≃ᵐ G₀ := { to_equiv := equiv.mul_right₀ g hg, measurable_to_fun := measurable_mul_const g, measurable_inv_fun := measurable_mul_const g⁻¹ } lemma _root_.measurable_embedding_mul_right₀ {g : G₀} (hg : g ≠ 0) : measurable_embedding (λ x, x * g) := (mul_right₀ g hg).measurable_embedding @[simp] lemma coe_mul_right₀ {g : G₀} (hg : g ≠ 0) : ⇑(mul_right₀ g hg) = λ x, x * g := rfl @[simp] lemma symm_mul_right₀ {g : G₀} (hg : g ≠ 0) : (mul_right₀ g hg).symm = mul_right₀ g⁻¹ (inv_ne_zero hg) := ext rfl @[simp] lemma to_equiv_mul_right₀ {g : G₀} (hg : g ≠ 0) : (mul_right₀ g hg).to_equiv = equiv.mul_right₀ g hg := rfl end mul /-- Inversion as a measurable automorphism of a group or group with zero. -/ @[to_additive "Negation as a measurable automorphism of an additive group.", simps to_equiv apply { fully_applied := ff }] def inv (G) [measurable_space G] [has_involutive_inv G] [has_measurable_inv G] : G ≃ᵐ G := { to_equiv := equiv.inv G, measurable_to_fun := measurable_inv, measurable_inv_fun := measurable_inv } @[simp, to_additive] lemma symm_inv {G} [measurable_space G] [has_involutive_inv G] [has_measurable_inv G] : (inv G).symm = inv G := rfl /-- `equiv.div_right` as a `measurable_equiv`. -/ @[to_additive /-" `equiv.sub_right` as a `measurable_equiv` "-/] def div_right [has_measurable_mul G] (g : G) : G ≃ᵐ G := { to_equiv := equiv.div_right g, measurable_to_fun := measurable_div_const' g, measurable_inv_fun := measurable_mul_const g } /-- `equiv.div_left` as a `measurable_equiv` -/ @[to_additive /-" `equiv.sub_left` as a `measurable_equiv` "-/] def div_left [has_measurable_mul G] [has_measurable_inv G] (g : G) : G ≃ᵐ G := { to_equiv := equiv.div_left g, measurable_to_fun := measurable_id.const_div g, measurable_inv_fun := measurable_inv.mul_const g } end measurable_equiv
b99e448abfdff7f1a10efc55dbb984fc069cb693
367134ba5a65885e863bdc4507601606690974c1
/src/data/mv_polynomial/basic.lean
3f251b061a786b6808ffecd756f2a9877960c19a
[ "Apache-2.0" ]
permissive
kodyvajjha/mathlib
9bead00e90f68269a313f45f5561766cfd8d5cad
b98af5dd79e13a38d84438b850a2e8858ec21284
refs/heads/master
1,624,350,366,310
1,615,563,062,000
1,615,563,062,000
162,666,963
0
0
Apache-2.0
1,545,367,651,000
1,545,367,651,000
null
UTF-8
Lean
false
false
37,702
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, Johan Commelin, Mario Carneiro -/ import data.polynomial.eval /-! # Multivariate polynomials This file defines polynomial rings over a base ring (or even semiring), with variables from a general type `σ` (which could be infinite). ## Important definitions Let `R` be a commutative ring (or a semiring) and let `σ` be an arbitrary type. This file creates the type `mv_polynomial σ R`, which mathematicians might denote $R[X_i : i \in σ]$. It is the type of multivariate (a.k.a. multivariable) polynomials, with variables corresponding to the terms in `σ`, and coefficients in `R`. ### Notation In the definitions below, we use the following notation: + `σ : Type*` (indexing the variables) + `R : Type*` `[comm_semiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `mv_polynomial σ R` which mathematicians might call `X^s` + `a : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : mv_polynomial σ R` ### Definitions * `mv_polynomial σ R` : the type of polynomials with variables of type `σ` and coefficients in the commutative semiring `R` * `monomial s a` : the monomial which mathematically would be denoted `a * X^s` * `C a` : the constant polynomial with value `a` * `X i` : the degree one monomial corresponding to i; mathematically this might be denoted `Xᵢ`. * `coeff s p` : the coefficient of `s` in `p`. * `eval₂ (f : R → S₁) (g : σ → S₁) p` : given a semiring homomorphism from `R` to another semiring `S₁`, and a map `σ → S₁`, evaluates `p` at this valuation, returning a term of type `S₁`. Note that `eval₂` can be made using `eval` and `map` (see below), and it has been suggested that sticking to `eval` and `map` might make the code less brittle. * `eval (g : σ → R) p` : given a map `σ → R`, evaluates `p` at this valuation, returning a term of type `R` * `map (f : R → S₁) p` : returns the multivariate polynomial obtained from `p` by the change of coefficient semiring corresponding to `f` ## Implementation notes Recall that if `Y` has a zero, then `X →₀ Y` is the type of functions from `X` to `Y` with finite support, i.e. such that only finitely many elements of `X` get sent to non-zero terms in `Y`. The definition of `mv_polynomial σ R` is `(σ →₀ ℕ) →₀ R` ; here `σ →₀ ℕ` denotes the space of all monomials in the variables, and the function to `R` sends a monomial to its coefficient in the polynomial being represented. ## Tags polynomial, multivariate polynomial, multivariable polynomial -/ noncomputable theory open_locale classical big_operators open set function finsupp add_monoid_algebra open_locale big_operators universes u v w x variables {R : Type u} {S₁ : Type v} {S₂ : Type w} {S₃ : Type x} /-- Multivariate polynomial, where `σ` is the index set of the variables and `R` is the coefficient ring -/ def mv_polynomial (σ : Type*) (R : Type*) [comm_semiring R] := add_monoid_algebra R (σ →₀ ℕ) namespace mv_polynomial variables {σ : Type*} {a a' a₁ a₂ : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ} section comm_semiring section instances instance decidable_eq_mv_polynomial [comm_semiring R] [decidable_eq σ] [decidable_eq R] : decidable_eq (mv_polynomial σ R) := finsupp.decidable_eq instance [comm_semiring R] : comm_semiring (mv_polynomial σ R) := add_monoid_algebra.comm_semiring instance [comm_semiring R] : inhabited (mv_polynomial σ R) := ⟨0⟩ instance [semiring R] [comm_semiring S₁] [semimodule R S₁] : semimodule R (mv_polynomial σ S₁) := add_monoid_algebra.semimodule instance [semiring R] [semiring S₁] [comm_semiring S₂] [has_scalar R S₁] [semimodule R S₂] [semimodule S₁ S₂] [is_scalar_tower R S₁ S₂] : is_scalar_tower R S₁ (mv_polynomial σ S₂) := add_monoid_algebra.is_scalar_tower instance [semiring R] [semiring S₁][comm_semiring S₂] [semimodule R S₂] [semimodule S₁ S₂] [smul_comm_class R S₁ S₂] : smul_comm_class R S₁ (mv_polynomial σ S₂) := add_monoid_algebra.smul_comm_class instance [comm_semiring R] [comm_semiring S₁] [algebra R S₁] : algebra R (mv_polynomial σ S₁) := add_monoid_algebra.algebra end instances variables [comm_semiring R] [comm_semiring S₁] {p q : mv_polynomial σ R} /-- `monomial s a` is the monomial with coefficient `a` and exponents given by `s` -/ def monomial (s : σ →₀ ℕ) (a : R) : mv_polynomial σ R := single s a lemma single_eq_monomial (s : σ →₀ ℕ) (a : R) : single s a = monomial s a := rfl lemma mul_def : (p * q) = p.sum (λ m a, q.sum $ λ n b, monomial (m + n) (a * b)) := rfl /-- `C a` is the constant polynomial with value `a` -/ def C : R →+* mv_polynomial σ R := { to_fun := monomial 0, map_zero' := by simp [monomial], map_one' := rfl, map_add' := λ a a', single_add, map_mul' := λ a a', by simp [monomial, single_mul_single] } variables (R σ) theorem algebra_map_eq : algebra_map R (mv_polynomial σ R) = C := rfl variables {R σ} /-- `X n` is the degree `1` monomial $X_n$. -/ def X (n : σ) : mv_polynomial σ R := monomial (single n 1) 1 lemma C_apply : (C a : mv_polynomial σ R) = monomial 0 a := rfl @[simp] lemma C_0 : C 0 = (0 : mv_polynomial σ R) := by simp [C_apply, monomial] @[simp] lemma C_1 : C 1 = (1 : mv_polynomial σ R) := rfl lemma C_mul_monomial : C a * monomial s a' = monomial s (a * a') := by simp [C_apply, monomial, single_mul_single] @[simp] lemma C_add : (C (a + a') : mv_polynomial σ R) = C a + C a' := single_add @[simp] lemma C_mul : (C (a * a') : mv_polynomial σ R) = C a * C a' := C_mul_monomial.symm @[simp] lemma C_pow (a : R) (n : ℕ) : (C (a^n) : mv_polynomial σ R) = (C a)^n := by induction n; simp [pow_succ, *] lemma C_injective (σ : Type*) (R : Type*) [comm_semiring R] : function.injective (C : R → mv_polynomial σ R) := finsupp.single_injective _ lemma C_surjective {R : Type*} [comm_semiring R] (σ : Type*) (hσ : ¬ nonempty σ) : function.surjective (C : R → mv_polynomial σ R) := begin refine λ p, ⟨p.to_fun 0, finsupp.ext (λ a, _)⟩, simpa [(finsupp.ext (λ x, absurd (nonempty.intro x) hσ) : a = 0), C_apply, monomial], end lemma C_surjective_fin_0 {R : Type*} [comm_ring R] : function.surjective (mv_polynomial.C : R → mv_polynomial (fin 0) R) := C_surjective (fin 0) (λ h, let ⟨n⟩ := h in fin_zero_elim n) @[simp] lemma C_inj {σ : Type*} (R : Type*) [comm_semiring R] (r s : R) : (C r : mv_polynomial σ R) = C s ↔ r = s := (C_injective σ R).eq_iff instance infinite_of_infinite (σ : Type*) (R : Type*) [comm_semiring R] [infinite R] : infinite (mv_polynomial σ R) := infinite.of_injective C (C_injective _ _) instance infinite_of_nonempty (σ : Type*) (R : Type*) [nonempty σ] [comm_semiring R] [nontrivial R] : infinite (mv_polynomial σ R) := infinite.of_injective (λ i : ℕ, monomial (single (classical.arbitrary σ) i) 1) begin intros m n h, have := (single_eq_single_iff _ _ _ _).mp h, simp only [and_true, eq_self_iff_true, or_false, one_ne_zero, and_self, single_eq_single_iff, eq_self_iff_true, true_and] at this, rcases this with (rfl|⟨rfl, rfl⟩); refl end lemma C_eq_coe_nat (n : ℕ) : (C ↑n : mv_polynomial σ R) = n := by induction n; simp [nat.succ_eq_add_one, *] theorem C_mul' : mv_polynomial.C a * p = a • p := begin apply finsupp.induction p, { exact (mul_zero $ mv_polynomial.C a).trans (@smul_zero R (mv_polynomial σ R) _ _ _ a).symm }, intros p b f haf hb0 ih, rw [mul_add, ih, @smul_add R (mv_polynomial σ R) _ _ _ a], congr' 1, rw [add_monoid_algebra.mul_def, finsupp.smul_single], simp only [mv_polynomial.C], dsimp [mv_polynomial.monomial], rw [finsupp.sum_single_index, finsupp.sum_single_index, zero_add], { rw [mul_zero, finsupp.single_zero] }, { rw finsupp.sum_single_index, all_goals { rw [zero_mul, finsupp.single_zero] }, } end lemma smul_eq_C_mul (p : mv_polynomial σ R) (a : R) : a • p = C a * p := C_mul'.symm lemma X_pow_eq_single : X n ^ e = monomial (single n e) (1 : R) := begin induction e, { simp [X], refl }, { simp [pow_succ, e_ih], simp [X, monomial, single_mul_single, nat.succ_eq_add_one, add_comm] } end lemma monomial_add_single : monomial (s + single n e) a = (monomial s a * X n ^ e) := by rw [X_pow_eq_single, monomial, monomial, monomial, single_mul_single]; simp lemma monomial_single_add : monomial (single n e + s) a = (X n ^ e * monomial s a) := by rw [X_pow_eq_single, monomial, monomial, monomial, single_mul_single]; simp lemma single_eq_C_mul_X {s : σ} {a : R} {n : ℕ} : monomial (single s n) a = C a * (X s)^n := by { rw [← zero_add (single s n), monomial_add_single, C], refl } @[simp] lemma monomial_add {s : σ →₀ ℕ} {a b : R} : monomial s a + monomial s b = monomial s (a + b) := by simp [monomial] @[simp] lemma monomial_mul {s s' : σ →₀ ℕ} {a b : R} : monomial s a * monomial s' b = monomial (s + s') (a * b) := by rw [monomial, monomial, monomial, add_monoid_algebra.single_mul_single] @[simp] lemma monomial_zero {s : σ →₀ ℕ}: monomial s (0 : R) = 0 := by rw [monomial, single_zero]; refl @[simp] lemma sum_monomial {A : Type*} [add_comm_monoid A] {u : σ →₀ ℕ} {r : R} {b : (σ →₀ ℕ) → R → A} (w : b u 0 = 0) : sum (monomial u r) b = b u r := sum_single_index w @[simp] lemma sum_C {A : Type*} [add_comm_monoid A] {b : (σ →₀ ℕ) → R → A} (w : b 0 0 = 0) : sum (C a) b = b 0 a := by simp [C_apply, w] lemma monomial_eq : monomial s a = C a * (s.prod $ λn e, X n ^ e : mv_polynomial σ R) := begin apply @finsupp.induction σ ℕ _ _ s, { simp only [C_apply, prod_zero_index]; exact (mul_one _).symm }, { assume n e s hns he ih, rw [monomial_single_add, ih, prod_add_index, prod_single_index, mul_left_comm], { simp only [pow_zero], }, { intro a, simp only [pow_zero], }, { intros, rw pow_add, }, } end @[recursor 5] lemma induction_on {M : mv_polynomial σ R → Prop} (p : mv_polynomial σ R) (h_C : ∀a, M (C a)) (h_add : ∀p q, M p → M q → M (p + q)) (h_X : ∀p n, M p → M (p * X n)) : M p := have ∀s a, M (monomial s a), begin assume s a, apply @finsupp.induction σ ℕ _ _ s, { show M (monomial 0 a), from h_C a, }, { assume n e p hpn he ih, have : ∀e:ℕ, M (monomial p a * X n ^ e), { intro e, induction e, { simp [ih] }, { simp [ih, pow_succ', (mul_assoc _ _ _).symm, h_X, e_ih] } }, simp [add_comm, monomial_add_single, this] } end, finsupp.induction p (by have : M (C 0) := h_C 0; rwa [C_0] at this) (assume s a p hsp ha hp, h_add _ _ (this s a) hp) attribute [elab_as_eliminator] theorem induction_on' {P : mv_polynomial σ R → Prop} (p : mv_polynomial σ R) (h1 : ∀ (u : σ →₀ ℕ) (a : R), P (monomial u a)) (h2 : ∀ (p q : mv_polynomial σ R), P p → P q → P (p + q)) : P p := finsupp.induction p (suffices P (monomial 0 0), by rwa monomial_zero at this, show P (monomial 0 0), from h1 0 0) (λ a b f ha hb hPf, h2 _ _ (h1 _ _) hPf) @[ext] lemma ring_hom_ext {A : Type*} [semiring A] {f g : mv_polynomial σ R →+* A} (hC : ∀ r, f (C r) = g (C r)) (hX : ∀ i, f (X i) = g (X i)) : f = g := by { ext, exacts [hC _, hX _] } lemma hom_eq_hom [semiring S₂] (f g : mv_polynomial σ R →+* S₂) (hC : ∀a:R, f (C a) = g (C a)) (hX : ∀n:σ, f (X n) = g (X n)) (p : mv_polynomial σ R) : f p = g p := ring_hom.congr_fun (ring_hom_ext hC hX) p lemma is_id (f : mv_polynomial σ R →+* mv_polynomial σ R) (hC : ∀a:R, f (C a) = (C a)) (hX : ∀n:σ, f (X n) = (X n)) (p : mv_polynomial σ R) : f p = p := hom_eq_hom f (ring_hom.id _) hC hX p @[ext] lemma alg_hom_ext {A : Type*} [comm_semiring A] [algebra R A] {f g : mv_polynomial σ R →ₐ[R] A} (hf : ∀ i : σ, f (X i) = g (X i)) : f = g := by { ext, exact hf _ } @[simp] lemma alg_hom_C (f : mv_polynomial σ R →ₐ[R] mv_polynomial σ R) (r : R) : f (C r) = C r := f.commutes r section support /-- The finite set of all `m : σ →₀ ℕ` such that `X^m` has a non-zero coefficient. -/ def support (p : mv_polynomial σ R) : finset (σ →₀ ℕ) := p.support lemma support_monomial : (monomial s a).support = if a = 0 then ∅ else {s} := rfl lemma support_monomial_subset : (monomial s a).support ⊆ {s} := support_single_subset lemma support_add : (p + q).support ⊆ p.support ∪ q.support := by convert @finsupp.support_add _ _ _ p q lemma support_X [nontrivial R] : (X n : mv_polynomial σ R).support = {single n 1} := by rw [X, support_monomial, if_neg]; exact one_ne_zero end support section coeff /-- The coefficient of the monomial `m` in the multi-variable polynomial `p`. -/ def coeff (m : σ →₀ ℕ) (p : mv_polynomial σ R) : R := @coe_fn _ (monoid_algebra.has_coe_to_fun _ _) p m @[simp] lemma mem_support_iff {p : mv_polynomial σ R} {m : σ →₀ ℕ} : m ∈ p.support ↔ p.coeff m ≠ 0 := by simp [support, coeff] lemma not_mem_support_iff {p : mv_polynomial σ R} {m : σ →₀ ℕ} : m ∉ p.support ↔ p.coeff m = 0 := by simp lemma sum_def {A} [add_comm_monoid A] {p : mv_polynomial σ R} {b : (σ →₀ ℕ) → R → A} : p.sum b = ∑ m in p.support, b m (p.coeff m) := by simp [support, finsupp.sum, coeff] lemma support_mul (p q : mv_polynomial σ R) : (p * q).support ⊆ p.support.bUnion (λ a, q.support.bUnion $ λ b, {a + b}) := by convert add_monoid_algebra.support_mul p q; ext; convert iff.rfl @[ext] lemma ext (p q : mv_polynomial σ R) : (∀ m, coeff m p = coeff m q) → p = q := ext lemma ext_iff (p q : mv_polynomial σ R) : p = q ↔ (∀ m, coeff m p = coeff m q) := ⟨ λ h m, by rw h, ext p q⟩ @[simp] lemma coeff_add (m : σ →₀ ℕ) (p q : mv_polynomial σ R) : coeff m (p + q) = coeff m p + coeff m q := add_apply p q m @[simp] lemma coeff_zero (m : σ →₀ ℕ) : coeff m (0 : mv_polynomial σ R) = 0 := rfl @[simp] lemma coeff_zero_X (i : σ) : coeff 0 (X i : mv_polynomial σ R) = 0 := single_eq_of_ne (λ h, by cases single_eq_zero.1 h) instance coeff.is_add_monoid_hom (m : σ →₀ ℕ) : is_add_monoid_hom (coeff m : mv_polynomial σ R → R) := { map_add := coeff_add m, map_zero := coeff_zero m } lemma coeff_sum {X : Type*} (s : finset X) (f : X → mv_polynomial σ R) (m : σ →₀ ℕ) : coeff m (∑ x in s, f x) = ∑ x in s, coeff m (f x) := (s.sum_hom _).symm lemma monic_monomial_eq (m) : monomial m (1:R) = (m.prod $ λn e, X n ^ e : mv_polynomial σ R) := by simp [monomial_eq] @[simp] lemma coeff_monomial (m n) (a) : coeff m (monomial n a : mv_polynomial σ R) = if n = m then a else 0 := by convert single_apply @[simp] lemma coeff_C (m) (a) : coeff m (C a : mv_polynomial σ R) = if 0 = m then a else 0 := by convert single_apply lemma coeff_X_pow (i : σ) (m) (k : ℕ) : coeff m (X i ^ k : mv_polynomial σ R) = if single i k = m then 1 else 0 := begin have := coeff_monomial m (finsupp.single i k) (1:R), rwa [@monomial_eq _ _ (1:R) (finsupp.single i k) _, C_1, one_mul, finsupp.prod_single_index] at this, exact pow_zero _ end lemma coeff_X' (i : σ) (m) : coeff m (X i : mv_polynomial σ R) = if single i 1 = m then 1 else 0 := by rw [← coeff_X_pow, pow_one] @[simp] lemma coeff_X (i : σ) : coeff (single i 1) (X i : mv_polynomial σ R) = 1 := by rw [coeff_X', if_pos rfl] @[simp] lemma coeff_C_mul (m) (a : R) (p : mv_polynomial σ R) : coeff m (C a * p) = a * coeff m p := begin rw [mul_def, sum_C], { simp [sum_def, coeff_sum] {contextual := tt} }, simp end lemma coeff_mul (p q : mv_polynomial σ R) (n : σ →₀ ℕ) : coeff n (p * q) = ∑ x in (antidiagonal n).support, coeff x.1 p * coeff x.2 q := begin rw mul_def, -- We need to manipulate both sides into a shape to which we can apply `finset.sum_bij_ne_zero`, -- so we need to turn both sides into a sum over a product. have := @finset.sum_product (σ →₀ ℕ) R _ _ p.support q.support (λ x, if (x.1 + x.2 = n) then coeff x.1 p * coeff x.2 q else 0), convert this.symm using 1; clear this, { rw [coeff], iterate 2 { rw sum_apply, apply finset.sum_congr rfl, intros, dsimp only }, convert single_apply }, symmetry, -- We are now ready to show that both sums are equal using `finset.sum_bij_ne_zero`. apply finset.sum_bij_ne_zero (λ (x : (σ →₀ ℕ) × (σ →₀ ℕ)) _ _, (x.1, x.2)), { intros x hx hx', simp only [mem_antidiagonal_support, eq_self_iff_true, if_false, forall_true_iff], contrapose! hx', rw [if_neg hx'] }, { rintros ⟨i, j⟩ ⟨k, l⟩ hij hij' hkl hkl', simpa only [and_imp, prod.mk.inj_iff, heq_iff_eq] using and.intro }, { rintros ⟨i, j⟩ hij hij', refine ⟨⟨i, j⟩, _, _⟩, { simp only [mem_support_iff, finset.mem_product], contrapose! hij', exact mul_eq_zero_of_ne_zero_imp_eq_zero hij' }, { rw [mem_antidiagonal_support] at hij, simp only [exists_prop, true_and, ne.def, if_pos hij, hij', not_false_iff] } }, { intros x hx hx', simp only [ne.def] at hx' ⊢, split_ifs with H, { refl }, { rw if_neg H at hx', contradiction } } end @[simp] lemma coeff_mul_X (m) (s : σ) (p : mv_polynomial σ R) : coeff (m + single s 1) (p * X s) = coeff m p := begin have : (m, single s 1) ∈ (m + single s 1).antidiagonal.support := mem_antidiagonal_support.2 rfl, rw [coeff_mul, ← finset.insert_erase this, finset.sum_insert (finset.not_mem_erase _ _), finset.sum_eq_zero, add_zero, coeff_X, mul_one], rintros ⟨i,j⟩ hij, rw [finset.mem_erase, mem_antidiagonal_support] at hij, by_cases H : single s 1 = j, { subst j, simpa using hij }, { rw [coeff_X', if_neg H, mul_zero] }, end lemma coeff_mul_X' (m) (s : σ) (p : mv_polynomial σ R) : coeff m (p * X s) = if s ∈ m.support then coeff (m - single s 1) p else 0 := begin nontriviality R, split_ifs with h h, { conv_rhs {rw ← coeff_mul_X _ s}, congr' with t, by_cases hj : s = t, { subst t, simp only [nat_sub_apply, add_apply, single_eq_same], refine (nat.sub_add_cancel $ nat.pos_of_ne_zero _).symm, rwa finsupp.mem_support_iff at h }, { simp [single_eq_of_ne hj] } }, { rw ← not_mem_support_iff, intro hm, apply h, have H := support_mul _ _ hm, simp only [finset.mem_bUnion] at H, rcases H with ⟨j, hj, i', hi', H⟩, rw [support_X, finset.mem_singleton] at hi', subst i', rw finset.mem_singleton at H, subst m, rw [finsupp.mem_support_iff, add_apply, single_apply, if_pos rfl], intro H, rw [_root_.add_eq_zero_iff] at H, exact one_ne_zero H.2 } end lemma eq_zero_iff {p : mv_polynomial σ R} : p = 0 ↔ ∀ d, coeff d p = 0 := by { rw ext_iff, simp only [coeff_zero], } lemma ne_zero_iff {p : mv_polynomial σ R} : p ≠ 0 ↔ ∃ d, coeff d p ≠ 0 := by { rw [ne.def, eq_zero_iff], push_neg, } lemma exists_coeff_ne_zero {p : mv_polynomial σ R} (h : p ≠ 0) : ∃ d, coeff d p ≠ 0 := ne_zero_iff.mp h lemma C_dvd_iff_dvd_coeff (r : R) (φ : mv_polynomial σ R) : C r ∣ φ ↔ ∀ i, r ∣ φ.coeff i := begin split, { rintros ⟨φ, rfl⟩ c, rw coeff_C_mul, apply dvd_mul_right }, { intro h, choose c hc using h, classical, let c' : (σ →₀ ℕ) → R := λ i, if i ∈ φ.support then c i else 0, let ψ : mv_polynomial σ R := ∑ i in φ.support, monomial i (c' i), use ψ, apply mv_polynomial.ext, intro i, simp only [coeff_C_mul, coeff_sum, coeff_monomial, finset.sum_ite_eq', c'], split_ifs with hi hi, { rw hc }, { rw not_mem_support_iff at hi, rwa mul_zero } }, end end coeff section constant_coeff /-- `constant_coeff p` returns the constant term of the polynomial `p`, defined as `coeff 0 p`. This is a ring homomorphism. -/ def constant_coeff : mv_polynomial σ R →+* R := { to_fun := coeff 0, map_one' := by simp [coeff, add_monoid_algebra.one_def], map_mul' := by simp [coeff_mul, finsupp.support_single_ne_zero], map_zero' := coeff_zero _, map_add' := coeff_add _ } lemma constant_coeff_eq : (constant_coeff : mv_polynomial σ R → R) = coeff 0 := rfl @[simp] lemma constant_coeff_C (r : R) : constant_coeff (C r : mv_polynomial σ R) = r := by simp [constant_coeff_eq] @[simp] lemma constant_coeff_X (i : σ) : constant_coeff (X i : mv_polynomial σ R) = 0 := by simp [constant_coeff_eq] lemma constant_coeff_monomial (d : σ →₀ ℕ) (r : R) : constant_coeff (monomial d r) = if d = 0 then r else 0 := by rw [constant_coeff_eq, coeff_monomial] variables (σ R) @[simp] lemma constant_coeff_comp_C : constant_coeff.comp (C : R →+* mv_polynomial σ R) = ring_hom.id R := by { ext, apply constant_coeff_C } @[simp] lemma constant_coeff_comp_algebra_map : constant_coeff.comp (algebra_map R (mv_polynomial σ R)) = ring_hom.id R := constant_coeff_comp_C _ _ end constant_coeff section as_sum @[simp] lemma support_sum_monomial_coeff (p : mv_polynomial σ R) : ∑ v in p.support, monomial v (coeff v p) = p := finsupp.sum_single p lemma as_sum (p : mv_polynomial σ R) : p = ∑ v in p.support, monomial v (coeff v p) := (support_sum_monomial_coeff p).symm end as_sum section eval₂ variables (f : R →+* S₁) (g : σ → S₁) /-- Evaluate a polynomial `p` given a valuation `g` of all the variables and a ring hom `f` from the scalar ring to the target -/ def eval₂ (p : mv_polynomial σ R) : S₁ := p.sum (λs a, f a * s.prod (λn e, g n ^ e)) lemma eval₂_eq (g : R →+* S₁) (x : σ → S₁) (f : mv_polynomial σ R) : f.eval₂ g x = ∑ d in f.support, g (f.coeff d) * ∏ i in d.support, x i ^ d i := rfl lemma eval₂_eq' [fintype σ] (g : R →+* S₁) (x : σ → S₁) (f : mv_polynomial σ R) : f.eval₂ g x = ∑ d in f.support, g (f.coeff d) * ∏ i, x i ^ d i := by { simp only [eval₂_eq, ← finsupp.prod_pow], refl } @[simp] lemma eval₂_zero : (0 : mv_polynomial σ R).eval₂ f g = 0 := finsupp.sum_zero_index section @[simp] lemma eval₂_add : (p + q).eval₂ f g = p.eval₂ f g + q.eval₂ f g := finsupp.sum_add_index (by simp [is_semiring_hom.map_zero f]) (by simp [add_mul, is_semiring_hom.map_add f]) @[simp] lemma eval₂_monomial : (monomial s a).eval₂ f g = f a * s.prod (λn e, g n ^ e) := finsupp.sum_single_index (by simp [is_semiring_hom.map_zero f]) @[simp] lemma eval₂_C (a) : (C a).eval₂ f g = f a := by simp [eval₂_monomial, C, prod_zero_index] @[simp] lemma eval₂_one : (1 : mv_polynomial σ R).eval₂ f g = 1 := (eval₂_C _ _ _).trans (is_semiring_hom.map_one f) @[simp] lemma eval₂_X (n) : (X n).eval₂ f g = g n := by simp [eval₂_monomial, is_semiring_hom.map_one f, X, prod_single_index, pow_one] lemma eval₂_mul_monomial : ∀{s a}, (p * monomial s a).eval₂ f g = p.eval₂ f g * f a * s.prod (λn e, g n ^ e) := begin apply mv_polynomial.induction_on p, { assume a' s a, simp [C_mul_monomial, eval₂_monomial, is_semiring_hom.map_mul f] }, { assume p q ih_p ih_q, simp [add_mul, eval₂_add, ih_p, ih_q] }, { assume p n ih s a, from calc (p * X n * monomial s a).eval₂ f g = (p * monomial (single n 1 + s) a).eval₂ f g : by simp [monomial_single_add, -add_comm, pow_one, mul_assoc] ... = (p * monomial (single n 1) 1).eval₂ f g * f a * s.prod (λn e, g n ^ e) : by simp [ih, prod_single_index, prod_add_index, pow_one, pow_add, mul_assoc, mul_left_comm, is_semiring_hom.map_one f, -add_comm] } end @[simp] lemma eval₂_mul : ∀{p}, (p * q).eval₂ f g = p.eval₂ f g * q.eval₂ f g := begin apply mv_polynomial.induction_on q, { simp [C, eval₂_monomial, eval₂_mul_monomial, prod_zero_index] }, { simp [mul_add, eval₂_add] {contextual := tt} }, { simp [X, eval₂_monomial, eval₂_mul_monomial, (mul_assoc _ _ _).symm] { contextual := tt} } end @[simp] lemma eval₂_pow {p:mv_polynomial σ R} : ∀{n:ℕ}, (p ^ n).eval₂ f g = (p.eval₂ f g)^n | 0 := eval₂_one _ _ | (n + 1) := by rw [pow_add, pow_one, pow_add, pow_one, eval₂_mul, eval₂_pow] instance eval₂.is_semiring_hom : is_semiring_hom (eval₂ f g) := { map_zero := eval₂_zero _ _, map_one := eval₂_one _ _, map_add := λ p q, eval₂_add _ _, map_mul := λ p q, eval₂_mul _ _ } /-- `mv_polynomial.eval₂` as a `ring_hom`. -/ def eval₂_hom (f : R →+* S₁) (g : σ → S₁) : mv_polynomial σ R →+* S₁ := ring_hom.of (eval₂ f g) @[simp] lemma coe_eval₂_hom (f : R →+* S₁) (g : σ → S₁) : ⇑(eval₂_hom f g) = eval₂ f g := rfl lemma eval₂_hom_congr {f₁ f₂ : R →+* S₁} {g₁ g₂ : σ → S₁} {p₁ p₂ : mv_polynomial σ R} : f₁ = f₂ → g₁ = g₂ → p₁ = p₂ → eval₂_hom f₁ g₁ p₁ = eval₂_hom f₂ g₂ p₂ := by rintros rfl rfl rfl; refl end @[simp] lemma eval₂_hom_C (f : R →+* S₁) (g : σ → S₁) (r : R) : eval₂_hom f g (C r) = f r := eval₂_C f g r @[simp] lemma eval₂_hom_X' (f : R →+* S₁) (g : σ → S₁) (i : σ) : eval₂_hom f g (X i) = g i := eval₂_X f g i @[simp] lemma comp_eval₂_hom [comm_semiring S₂] (f : R →+* S₁) (g : σ → S₁) (φ : S₁ →+* S₂) : φ.comp (eval₂_hom f g) = (eval₂_hom (φ.comp f) (λ i, φ (g i))) := begin apply mv_polynomial.ring_hom_ext, { intro r, rw [ring_hom.comp_apply, eval₂_hom_C, eval₂_hom_C, ring_hom.comp_apply] }, { intro i, rw [ring_hom.comp_apply, eval₂_hom_X', eval₂_hom_X'] } end lemma map_eval₂_hom [comm_semiring S₂] (f : R →+* S₁) (g : σ → S₁) (φ : S₁ →+* S₂) (p : mv_polynomial σ R) : φ (eval₂_hom f g p) = (eval₂_hom (φ.comp f) (λ i, φ (g i)) p) := by { rw ← comp_eval₂_hom, refl } lemma eval₂_hom_monomial (f : R →+* S₁) (g : σ → S₁) (d : σ →₀ ℕ) (r : R) : eval₂_hom f g (monomial d r) = f r * d.prod (λ i k, g i ^ k) := by simp only [monomial_eq, ring_hom.map_mul, eval₂_hom_C, finsupp.prod, ring_hom.map_prod, ring_hom.map_pow, eval₂_hom_X'] section local attribute [instance, priority 10] is_semiring_hom.comp lemma eval₂_comp_left {S₂} [comm_semiring S₂] (k : S₁ →+* S₂) (f : R →+* S₁) (g : σ → S₁) (p) : k (eval₂ f g p) = eval₂ (k.comp f) (k ∘ g) p := by apply mv_polynomial.induction_on p; simp [ eval₂_add, k.map_add, eval₂_mul, k.map_mul] {contextual := tt} end @[simp] lemma eval₂_eta (p : mv_polynomial σ R) : eval₂ C X p = p := by apply mv_polynomial.induction_on p; simp [eval₂_add, eval₂_mul] {contextual := tt} lemma eval₂_congr (g₁ g₂ : σ → S₁) (h : ∀ {i : σ} {c : σ →₀ ℕ}, i ∈ c.support → coeff c p ≠ 0 → g₁ i = g₂ i) : p.eval₂ f g₁ = p.eval₂ f g₂ := begin apply finset.sum_congr rfl, intros c hc, dsimp, congr' 1, apply finset.prod_congr rfl, intros i hi, dsimp, congr' 1, apply h hi, rwa finsupp.mem_support_iff at hc end @[simp] lemma eval₂_prod (s : finset S₂) (p : S₂ → mv_polynomial σ R) : eval₂ f g (∏ x in s, p x) = ∏ x in s, eval₂ f g (p x) := (s.prod_hom _).symm @[simp] lemma eval₂_sum (s : finset S₂) (p : S₂ → mv_polynomial σ R) : eval₂ f g (∑ x in s, p x) = ∑ x in s, eval₂ f g (p x) := (s.sum_hom _).symm attribute [to_additive] eval₂_prod lemma eval₂_assoc (q : S₂ → mv_polynomial σ R) (p : mv_polynomial S₂ R) : eval₂ f (λ t, eval₂ f g (q t)) p = eval₂ f g (eval₂ C q p) := begin show _ = eval₂_hom f g (eval₂ C q p), rw eval₂_comp_left (eval₂_hom f g), congr' with a, simp, end end eval₂ section eval variables {f : σ → R} /-- Evaluate a polynomial `p` given a valuation `f` of all the variables -/ def eval (f : σ → R) : mv_polynomial σ R →+* R := eval₂_hom (ring_hom.id _) f lemma eval_eq (x : σ → R) (f : mv_polynomial σ R) : eval x f = ∑ d in f.support, f.coeff d * ∏ i in d.support, x i ^ d i := rfl lemma eval_eq' [fintype σ] (x : σ → R) (f : mv_polynomial σ R) : eval x f = ∑ d in f.support, f.coeff d * ∏ i, x i ^ d i := eval₂_eq' (ring_hom.id R) x f lemma eval_monomial : eval f (monomial s a) = a * s.prod (λn e, f n ^ e) := eval₂_monomial _ _ @[simp] lemma eval_C : ∀ a, eval f (C a) = a := eval₂_C _ _ @[simp] lemma eval_X : ∀ n, eval f (X n) = f n := eval₂_X _ _ @[simp] lemma smul_eval (x) (p : mv_polynomial σ R) (s) : eval x (s • p) = s * eval x p := by rw [smul_eq_C_mul, (eval x).map_mul, eval_C] lemma eval_sum {ι : Type*} (s : finset ι) (f : ι → mv_polynomial σ R) (g : σ → R) : eval g (∑ i in s, f i) = ∑ i in s, eval g (f i) := (eval g).map_sum _ _ @[to_additive] lemma eval_prod {ι : Type*} (s : finset ι) (f : ι → mv_polynomial σ R) (g : σ → R) : eval g (∏ i in s, f i) = ∏ i in s, eval g (f i) := (eval g).map_prod _ _ theorem eval_assoc {τ} (f : σ → mv_polynomial τ R) (g : τ → R) (p : mv_polynomial σ R) : eval (eval g ∘ f) p = eval g (eval₂ C f p) := begin rw eval₂_comp_left (eval g), unfold eval, simp only [coe_eval₂_hom], congr' with a, simp end end eval section map variables (f : R →+* S₁) /-- `map f p` maps a polynomial `p` across a ring hom `f` -/ def map : mv_polynomial σ R →+* mv_polynomial σ S₁ := eval₂_hom (C.comp f) X @[simp] theorem map_monomial (s : σ →₀ ℕ) (a : R) : map f (monomial s a) = monomial s (f a) := (eval₂_monomial _ _).trans monomial_eq.symm @[simp] theorem map_C : ∀ (a : R), map f (C a : mv_polynomial σ R) = C (f a) := map_monomial _ _ @[simp] theorem map_X : ∀ (n : σ), map f (X n : mv_polynomial σ R) = X n := eval₂_X _ _ theorem map_id : ∀ (p : mv_polynomial σ R), map (ring_hom.id R) p = p := eval₂_eta theorem map_map [comm_semiring S₂] (g : S₁ →+* S₂) (p : mv_polynomial σ R) : map g (map f p) = map (g.comp f) p := (eval₂_comp_left (map g) (C.comp f) X p).trans $ begin congr, { ext1 a, simp only [map_C, comp_app, ring_hom.coe_comp], }, { ext1 n, simp only [map_X, comp_app], } end theorem eval₂_eq_eval_map (g : σ → S₁) (p : mv_polynomial σ R) : p.eval₂ f g = eval g (map f p) := begin unfold map eval, simp only [coe_eval₂_hom], have h := eval₂_comp_left (eval₂_hom _ g), dsimp at h, rw h, congr, { ext1 a, simp only [coe_eval₂_hom, ring_hom.id_apply, comp_app, eval₂_C, ring_hom.coe_comp], }, { ext1 n, simp only [comp_app, eval₂_X], }, end lemma eval₂_comp_right {S₂} [comm_semiring S₂] (k : S₁ →+* S₂) (f : R →+* S₁) (g : σ → S₁) (p) : k (eval₂ f g p) = eval₂ k (k ∘ g) (map f p) := begin apply mv_polynomial.induction_on p, { intro r, rw [eval₂_C, map_C, eval₂_C] }, { intros p q hp hq, rw [eval₂_add, k.map_add, (map f).map_add, eval₂_add, hp, hq] }, { intros p s hp, rw [eval₂_mul, k.map_mul, (map f).map_mul, eval₂_mul, map_X, hp, eval₂_X, eval₂_X] } end lemma map_eval₂ (f : R →+* S₁) (g : S₂ → mv_polynomial S₃ R) (p : mv_polynomial S₂ R) : map f (eval₂ C g p) = eval₂ C (map f ∘ g) (map f p) := begin apply mv_polynomial.induction_on p, { intro r, rw [eval₂_C, map_C, map_C, eval₂_C] }, { intros p q hp hq, rw [eval₂_add, (map f).map_add, hp, hq, (map f).map_add, eval₂_add] }, { intros p s hp, rw [eval₂_mul, (map f).map_mul, hp, (map f).map_mul, map_X, eval₂_mul, eval₂_X, eval₂_X] } end lemma coeff_map (p : mv_polynomial σ R) : ∀ (m : σ →₀ ℕ), coeff m (map f p) = f (coeff m p) := begin apply mv_polynomial.induction_on p; clear p, { intros r m, rw [map_C], simp only [coeff_C], split_ifs, {refl}, rw f.map_zero }, { intros p q hp hq m, simp only [hp, hq, (map f).map_add, coeff_add], rw f.map_add }, { intros p i hp m, simp only [hp, (map f).map_mul, map_X], simp only [hp, mem_support_iff, coeff_mul_X'], split_ifs, {refl}, rw is_semiring_hom.map_zero f } end lemma map_injective (hf : function.injective f) : function.injective (map f : mv_polynomial σ R → mv_polynomial σ S₁) := begin intros p q h, simp only [ext_iff, coeff_map] at h ⊢, intro m, exact hf (h m), end @[simp] lemma eval_map (f : R →+* S₁) (g : σ → S₁) (p : mv_polynomial σ R) : eval g (map f p) = eval₂ f g p := by { apply mv_polynomial.induction_on p; { simp { contextual := tt } } } @[simp] lemma eval₂_map [comm_semiring S₂] (f : R →+* S₁) (g : σ → S₂) (φ : S₁ →+* S₂) (p : mv_polynomial σ R) : eval₂ φ g (map f p) = eval₂ (φ.comp f) g p := by { rw [← eval_map, ← eval_map, map_map], } @[simp] lemma eval₂_hom_map_hom [comm_semiring S₂] (f : R →+* S₁) (g : σ → S₂) (φ : S₁ →+* S₂) (p : mv_polynomial σ R) : eval₂_hom φ g (map f p) = eval₂_hom (φ.comp f) g p := eval₂_map f g φ p @[simp] lemma constant_coeff_map (f : R →+* S₁) (φ : mv_polynomial σ R) : constant_coeff (mv_polynomial.map f φ) = f (constant_coeff φ) := coeff_map f φ 0 lemma constant_coeff_comp_map (f : R →+* S₁) : (constant_coeff : mv_polynomial σ S₁ →+* S₁).comp (mv_polynomial.map f) = f.comp constant_coeff := by { ext; simp } lemma support_map_subset (p : mv_polynomial σ R) : (map f p).support ⊆ p.support := begin intro x, simp only [mem_support_iff], contrapose!, change p.coeff x = 0 → (map f p).coeff x = 0, rw coeff_map, intro hx, rw hx, exact ring_hom.map_zero f end lemma support_map_of_injective (p : mv_polynomial σ R) {f : R →+* S₁} (hf : injective f) : (map f p).support = p.support := begin apply finset.subset.antisymm, { exact mv_polynomial.support_map_subset _ _ }, intros x hx, rw mem_support_iff, contrapose! hx, simp only [not_not, mem_support_iff], change (map f p).coeff x = 0 at hx, rw [coeff_map, ← f.map_zero] at hx, exact hf hx end lemma C_dvd_iff_map_hom_eq_zero (q : R →+* S₁) (r : R) (hr : ∀ r' : R, q r' = 0 ↔ r ∣ r') (φ : mv_polynomial σ R) : C r ∣ φ ↔ map q φ = 0 := begin rw [C_dvd_iff_dvd_coeff, mv_polynomial.ext_iff], simp only [coeff_map, ring_hom.coe_of, coeff_zero, hr], end lemma map_map_range_eq_iff (f : R →+* S₁) (g : S₁ → R) (hg : g 0 = 0) (φ : mv_polynomial σ S₁) : map f (finsupp.map_range g hg φ) = φ ↔ ∀ d, f (g (coeff d φ)) = coeff d φ := begin rw mv_polynomial.ext_iff, apply forall_congr, intro m, rw [coeff_map], apply eq_iff_eq_cancel_right.mpr, refl end end map section aeval /-! ### The algebra of multivariate polynomials -/ variables (f : σ → S₁) variables [algebra R S₁] [comm_semiring S₂] /-- A map `σ → S₁` where `S₁` is an algebra over `R` generates an `R`-algebra homomorphism from multivariate polynomials over `σ` to `S₁`. -/ def aeval : mv_polynomial σ R →ₐ[R] S₁ := { commutes' := λ r, eval₂_C _ _ _ .. eval₂_hom (algebra_map R S₁) f } theorem aeval_def (p : mv_polynomial σ R) : aeval f p = eval₂ (algebra_map R S₁) f p := rfl lemma aeval_eq_eval₂_hom (p : mv_polynomial σ R) : aeval f p = eval₂_hom (algebra_map R S₁) f p := rfl @[simp] lemma aeval_X (s : σ) : aeval f (X s : mv_polynomial _ R) = f s := eval₂_X _ _ _ @[simp] lemma aeval_C (r : R) : aeval f (C r) = algebra_map R S₁ r := eval₂_C _ _ _ theorem aeval_unique (φ : mv_polynomial σ R →ₐ[R] S₁) : φ = aeval (φ ∘ X) := by { ext i, simp } lemma comp_aeval {B : Type*} [comm_semiring B] [algebra R B] (φ : S₁ →ₐ[R] B) : φ.comp (aeval f) = aeval (λ i, φ (f i)) := by { ext i, simp } @[simp] lemma map_aeval {B : Type*} [comm_semiring B] (g : σ → S₁) (φ : S₁ →+* B) (p : mv_polynomial σ R) : φ (aeval g p) = (eval₂_hom (φ.comp (algebra_map R S₁)) (λ i, φ (g i)) p) := by { rw ← comp_eval₂_hom, refl } @[simp] lemma eval₂_hom_zero (f : R →+* S₂) (p : mv_polynomial σ R) : eval₂_hom f (0 : σ → S₂) p = f (constant_coeff p) := begin suffices : eval₂_hom f (0 : σ → S₂) = f.comp constant_coeff, from ring_hom.congr_fun this p, ext; simp end @[simp] lemma eval₂_hom_zero' (f : R →+* S₂) (p : mv_polynomial σ R) : eval₂_hom f (λ _, 0 : σ → S₂) p = f (constant_coeff p) := eval₂_hom_zero f p @[simp] lemma aeval_zero (p : mv_polynomial σ R) : aeval (0 : σ → S₁) p = algebra_map _ _ (constant_coeff p) := eval₂_hom_zero (algebra_map R S₁) p @[simp] lemma aeval_zero' (p : mv_polynomial σ R) : aeval (λ _, 0 : σ → S₁) p = algebra_map _ _ (constant_coeff p) := aeval_zero p lemma aeval_monomial (g : σ → S₁) (d : σ →₀ ℕ) (r : R) : aeval g (monomial d r) = algebra_map _ _ r * d.prod (λ i k, g i ^ k) := eval₂_hom_monomial _ _ _ _ lemma eval₂_hom_eq_zero (f : R →+* S₂) (g : σ → S₂) (φ : mv_polynomial σ R) (h : ∀ d, φ.coeff d ≠ 0 → ∃ i ∈ d.support, g i = 0) : eval₂_hom f g φ = 0 := begin rw [φ.as_sum, ring_hom.map_sum, finset.sum_eq_zero], intros d hd, obtain ⟨i, hi, hgi⟩ : ∃ i ∈ d.support, g i = 0 := h d (finsupp.mem_support_iff.mp hd), rw [eval₂_hom_monomial, finsupp.prod, finset.prod_eq_zero hi, mul_zero], rw [hgi, zero_pow], rwa [pos_iff_ne_zero, ← finsupp.mem_support_iff] end lemma aeval_eq_zero [algebra R S₂] (f : σ → S₂) (φ : mv_polynomial σ R) (h : ∀ d, φ.coeff d ≠ 0 → ∃ i ∈ d.support, f i = 0) : aeval f φ = 0 := eval₂_hom_eq_zero _ _ _ h end aeval end comm_semiring end mv_polynomial
f9a9b1198c2fd8353309075ed0272d545e5cad0a
d6124c8dbe5661dcc5b8c9da0a56fbf1f0480ad6
/Papyrus/IR/InstructionRef.lean
1e376c20806ed7e33cebe0196274b8adfad86c13
[ "Apache-2.0" ]
permissive
xubaiw/lean4-papyrus
c3fbbf8ba162eb5f210155ae4e20feb2d32c8182
02e82973a5badda26fc0f9fd15b3d37e2eb309e0
refs/heads/master
1,691,425,756,824
1,632,122,825,000
1,632,123,075,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
947
lean
import Papyrus.Context import Papyrus.IR.ValueRef import Papyrus.IR.ValueKind import Papyrus.IR.InstructionKind namespace Papyrus /-- A reference to an external LLVM [Instruction](https://llvm.org/doxygen/classllvm_1_1Instruction.html). -/ structure InstructionRef extends UserRef where is_instruction : toValueRef.valueKind = ValueKind.instruction instance : Coe InstructionRef UserRef := ⟨(·.toUserRef)⟩ namespace InstructionRef /-- Cast a general `ValueRef` to a `InstructionRef` given proof it is one. -/ def cast (val : ValueRef) (h : val.valueKind = ValueKind.instruction) : InstructionRef := {toValueRef := val, is_instruction := h} /-- The LLVM opcode of this instruction. -/ def opcode (self : InstructionRef) : UInt32 := (· - ValueKind.instruction.toValueID) self.valueID /-- The kind of this instruction. -/ def instructionKind (self : InstructionRef) : InstructionKind := InstructionKind.ofOpcode! self.opcode
ff3d0daafa9ccb5214f7cf4eee8931b191684007
6dc0c8ce7a76229dd81e73ed4474f15f88a9e294
/tests/lean/run/binrel.lean
c2dda73c164f07499cc2c9f8fea660a4eff8f930
[ "Apache-2.0" ]
permissive
williamdemeo/lean4
72161c58fe65c3ad955d6a3050bb7d37c04c0d54
6d00fcf1d6d873e195f9220c668ef9c58e9c4a35
refs/heads/master
1,678,305,356,877
1,614,708,995,000
1,614,708,995,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
816
lean
def ex1 (x y : Nat) (i j : Int) := binrel! Less x i def ex2 (x y : Nat) (i j : Int) := binrel! Less i x def ex3 (x y : Nat) (i j : Int) := binrel! Less (i + 1) x def ex4 (x y : Nat) (i j : Int) := binrel! Less i (x + 1) def ex5 (x y : Nat) (i j : Int) := binrel! Less i (x + y) def ex6 (x y : Nat) (i j : Int) := binrel! Less (i + j) (x + 0) def ex7 (x y : Nat) (i j : Int) := binrel! Less (i + j) (x + i) def ex8 (x y : Nat) (i j : Int) := binrel! Less (i + 0) (x + i) def ex9 (n : UInt32) := binrel! Less n 0xd800 def ex10 (x : Lean.Syntax) : Bool := x.getArgs.all (binrel! BEq.beq ·.getKind `foo) def ex11 (xs : Array (Nat × Nat)) := let f a b := binrel! Less a.1 b.1 f xs[1] xs[2] def ex12 (i j : Int) := binrel! Eq (i, j) (0, 0) def ex13 (i j : Int) := (i, j) = (0, 0)
c297fb8235338f9f640a0f0ce43c892fd8e0129b
302c785c90d40ad3d6be43d33bc6a558354cc2cf
/src/combinatorics/simple_graph/basic.lean
19c0c47af4853a82821079b9aaaf0ceedbfcc0c2
[ "Apache-2.0" ]
permissive
ilitzroth/mathlib
ea647e67f1fdfd19a0f7bdc5504e8acec6180011
5254ef14e3465f6504306132fe3ba9cec9ffff16
refs/heads/master
1,680,086,661,182
1,617,715,647,000
1,617,715,647,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
19,512
lean
/- Copyright (c) 2020 Aaron Anderson, Jalex Stark, Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Jalex Stark, Kyle Miller, Alena Gusakov -/ import data.fintype.basic import data.sym2 import data.set.finite /-! # Simple graphs This module defines simple graphs on a vertex type `V` as an irreflexive symmetric relation. There is a basic API for locally finite graphs and for graphs with finitely many vertices. ## Main definitions * `simple_graph` is a structure for symmetric, irreflexive relations * `neighbor_set` is the `set` of vertices adjacent to a given vertex * `neighbor_finset` is the `finset` of vertices adjacent to a given vertex, if `neighbor_set` is finite * `incidence_set` is the `set` of edges containing a given vertex * `incidence_finset` is the `finset` of edges containing a given vertex, if `incidence_set` is finite ## Implementation notes * A locally finite graph is one with instances `∀ v, fintype (G.neighbor_set v)`. * Given instances `decidable_rel G.adj` and `fintype V`, then the graph is locally finite, too. ## Naming Conventions * If the vertex type of a graph is finite, we refer to its cardinality as `card_verts`. TODO: This is the simplest notion of an unoriented graph. This should eventually fit into a more complete combinatorics hierarchy which includes multigraphs and directed graphs. We begin with simple graphs in order to start learning what the combinatorics hierarchy should look like. TODO: Part of this would include defining, for example, subgraphs of a simple graph. -/ open finset universe u /-- A simple graph is an irreflexive symmetric relation `adj` on a vertex type `V`. The relation describes which pairs of vertices are adjacent. There is exactly one edge for every pair of adjacent edges; see `simple_graph.edge_set` for the corresponding edge set. -/ @[ext] structure simple_graph (V : Type u) := (adj : V → V → Prop) (sym : symmetric adj . obviously) (loopless : irreflexive adj . obviously) /-- Construct the simple graph induced by the given relation. It symmetrizes the relation and makes it irreflexive. -/ def simple_graph.from_rel {V : Type u} (r : V → V → Prop) : simple_graph V := { adj := λ a b, (a ≠ b) ∧ (r a b ∨ r b a), sym := λ a b ⟨hn, hr⟩, ⟨hn.symm, hr.symm⟩, loopless := λ a ⟨hn, _⟩, hn rfl } noncomputable instance {V : Type u} [fintype V] : fintype (simple_graph V) := by { classical, exact fintype.of_injective simple_graph.adj simple_graph.ext } @[simp] lemma simple_graph.from_rel_adj {V : Type u} (r : V → V → Prop) (v w : V) : (simple_graph.from_rel r).adj v w ↔ v ≠ w ∧ (r v w ∨ r w v) := iff.rfl /-- The complete graph on a type `V` is the simple graph with all pairs of distinct vertices adjacent. -/ def complete_graph (V : Type u) : simple_graph V := { adj := ne } instance (V : Type u) : inhabited (simple_graph V) := ⟨complete_graph V⟩ instance complete_graph_adj_decidable (V : Type u) [decidable_eq V] : decidable_rel (complete_graph V).adj := λ v w, not.decidable namespace simple_graph variables {V : Type u} (G : simple_graph V) /-- `G.neighbor_set v` is the set of vertices adjacent to `v` in `G`. -/ def neighbor_set (v : V) : set V := set_of (G.adj v) instance neighbor_set.mem_decidable (v : V) [decidable_rel G.adj] : decidable_pred (G.neighbor_set v) := by { unfold neighbor_set, apply_instance } lemma ne_of_adj {a b : V} (hab : G.adj a b) : a ≠ b := by { rintro rfl, exact G.loopless a hab } /-- The edges of G consist of the unordered pairs of vertices related by `G.adj`. -/ def edge_set : set (sym2 V) := sym2.from_rel G.sym /-- The `incidence_set` is the set of edges incident to a given vertex. -/ def incidence_set (v : V) : set (sym2 V) := {e ∈ G.edge_set | v ∈ e} lemma incidence_set_subset (v : V) : G.incidence_set v ⊆ G.edge_set := λ _ h, h.1 @[simp] lemma mem_edge_set {v w : V} : ⟦(v, w)⟧ ∈ G.edge_set ↔ G.adj v w := by refl /-- Two vertices are adjacent iff there is an edge between them. The condition `v ≠ w` ensures they are different endpoints of the edge, which is necessary since when `v = w` the existential `∃ (e ∈ G.edge_set), v ∈ e ∧ w ∈ e` is satisfied by every edge incident to `v`. -/ lemma adj_iff_exists_edge {v w : V} : G.adj v w ↔ v ≠ w ∧ ∃ (e ∈ G.edge_set), v ∈ e ∧ w ∈ e := begin refine ⟨λ _, ⟨G.ne_of_adj ‹_›, ⟦(v,w)⟧, _⟩, _⟩, { simpa }, { rintro ⟨hne, e, he, hv⟩, rw sym2.elems_iff_eq hne at hv, subst e, rwa mem_edge_set at he } end lemma edge_other_ne {e : sym2 V} (he : e ∈ G.edge_set) {v : V} (h : v ∈ e) : h.other ≠ v := begin erw [← sym2.mem_other_spec h, sym2.eq_swap] at he, exact G.ne_of_adj he, end instance edge_set_decidable_pred [decidable_rel G.adj] : decidable_pred G.edge_set := sym2.from_rel.decidable_pred _ instance edges_fintype [decidable_eq V] [fintype V] [decidable_rel G.adj] : fintype G.edge_set := subtype.fintype _ instance incidence_set_decidable_pred [decidable_eq V] [decidable_rel G.adj] (v : V) : decidable_pred (G.incidence_set v) := λ e, and.decidable /-- The `edge_set` of the graph as a `finset`. -/ def edge_finset [decidable_eq V] [fintype V] [decidable_rel G.adj] : finset (sym2 V) := set.to_finset G.edge_set @[simp] lemma mem_edge_finset [decidable_eq V] [fintype V] [decidable_rel G.adj] (e : sym2 V) : e ∈ G.edge_finset ↔ e ∈ G.edge_set := set.mem_to_finset @[simp] lemma edge_set_univ_card [decidable_eq V] [fintype V] [decidable_rel G.adj] : (univ : finset G.edge_set).card = G.edge_finset.card := fintype.card_of_subtype G.edge_finset (mem_edge_finset _) @[simp] lemma irrefl {v : V} : ¬G.adj v v := G.loopless v lemma edge_symm (u v : V) : G.adj u v ↔ G.adj v u := ⟨λ x, G.sym x, λ x, G.sym x⟩ @[symm] lemma edge_symm' {u v : V} (h : G.adj u v) : G.adj v u := G.sym h @[simp] lemma mem_neighbor_set (v w : V) : w ∈ G.neighbor_set v ↔ G.adj v w := iff.rfl @[simp] lemma mem_incidence_set (v w : V) : ⟦(v, w)⟧ ∈ G.incidence_set v ↔ G.adj v w := by simp [incidence_set] lemma mem_incidence_iff_neighbor {v w : V} : ⟦(v, w)⟧ ∈ G.incidence_set v ↔ w ∈ G.neighbor_set v := by simp only [mem_incidence_set, mem_neighbor_set] lemma adj_incidence_set_inter {v : V} {e : sym2 V} (he : e ∈ G.edge_set) (h : v ∈ e) : G.incidence_set v ∩ G.incidence_set h.other = {e} := begin ext e', simp only [incidence_set, set.mem_sep_eq, set.mem_inter_eq, set.mem_singleton_iff], split, { intro h', rw ←sym2.mem_other_spec h, exact (sym2.elems_iff_eq (edge_other_ne G he h).symm).mp ⟨h'.1.2, h'.2.2⟩, }, { rintro rfl, use [he, h, he], apply sym2.mem_other_mem, }, end /-- The set of common neighbors between two vertices `v` and `w` in a graph `G` is the intersection of the neighbor sets of `v` and `w`. -/ def common_neighbors (v w : V) : set V := G.neighbor_set v ∩ G.neighbor_set w lemma common_neighbors_eq (v w : V) : G.common_neighbors v w = G.neighbor_set v ∩ G.neighbor_set w := rfl lemma mem_common_neighbors {u v w : V} : u ∈ G.common_neighbors v w ↔ G.adj v u ∧ G.adj w u := by simp [common_neighbors] lemma common_neighbors_symm (v w : V) : G.common_neighbors v w = G.common_neighbors w v := by { rw [common_neighbors, set.inter_comm], refl } lemma not_mem_common_neighbors_left (v w : V) : v ∉ G.common_neighbors v w := λ h, ne_of_adj G h.1 rfl lemma not_mem_common_neighbors_right (v w : V) : w ∉ G.common_neighbors v w := λ h, ne_of_adj G h.2 rfl lemma common_neighbors_subset_neighbor_set (v w : V) : G.common_neighbors v w ⊆ G.neighbor_set v := by simp [common_neighbors] instance [decidable_rel G.adj] (v w : V) : decidable_pred (G.common_neighbors v w) := λ a, and.decidable section incidence variable [decidable_eq V] /-- Given an edge incident to a particular vertex, get the other vertex on the edge. -/ def other_vertex_of_incident {v : V} {e : sym2 V} (h : e ∈ G.incidence_set v) : V := h.2.other' lemma edge_mem_other_incident_set {v : V} {e : sym2 V} (h : e ∈ G.incidence_set v) : e ∈ G.incidence_set (G.other_vertex_of_incident h) := by { use h.1, simp [other_vertex_of_incident, sym2.mem_other_mem'] } lemma incidence_other_prop {v : V} {e : sym2 V} (h : e ∈ G.incidence_set v) : G.other_vertex_of_incident h ∈ G.neighbor_set v := by { cases h with he hv, rwa [←sym2.mem_other_spec' hv, mem_edge_set] at he } @[simp] lemma incidence_other_neighbor_edge {v w : V} (h : w ∈ G.neighbor_set v) : G.other_vertex_of_incident (G.mem_incidence_iff_neighbor.mpr h) = w := sym2.congr_right.mp (sym2.mem_other_spec' (G.mem_incidence_iff_neighbor.mpr h).right) /-- There is an equivalence between the set of edges incident to a given vertex and the set of vertices adjacent to the vertex. -/ @[simps] def incidence_set_equiv_neighbor_set (v : V) : G.incidence_set v ≃ G.neighbor_set v := { to_fun := λ e, ⟨G.other_vertex_of_incident e.2, G.incidence_other_prop e.2⟩, inv_fun := λ w, ⟨⟦(v, w.1)⟧, G.mem_incidence_iff_neighbor.mpr w.2⟩, left_inv := λ x, by simp [other_vertex_of_incident], right_inv := λ ⟨w, hw⟩, by simp } end incidence section finite_at /-! ## Finiteness at a vertex This section contains definitions and lemmas concerning vertices that have finitely many adjacent vertices. We denote this condition by `fintype (G.neighbor_set v)`. We define `G.neighbor_finset v` to be the `finset` version of `G.neighbor_set v`. Use `neighbor_finset_eq_filter` to rewrite this definition as a `filter`. -/ variables (v : V) [fintype (G.neighbor_set v)] /-- `G.neighbors v` is the `finset` version of `G.adj v` in case `G` is locally finite at `v`. -/ def neighbor_finset : finset V := (G.neighbor_set v).to_finset @[simp] lemma mem_neighbor_finset (w : V) : w ∈ G.neighbor_finset v ↔ G.adj v w := set.mem_to_finset /-- `G.degree v` is the number of vertices adjacent to `v`. -/ def degree : ℕ := (G.neighbor_finset v).card @[simp] lemma card_neighbor_set_eq_degree : fintype.card (G.neighbor_set v) = G.degree v := (set.to_finset_card _).symm lemma degree_pos_iff_exists_adj : 0 < G.degree v ↔ ∃ w, G.adj v w := by simp only [degree, card_pos, finset.nonempty, mem_neighbor_finset] instance incidence_set_fintype [decidable_eq V] : fintype (G.incidence_set v) := fintype.of_equiv (G.neighbor_set v) (G.incidence_set_equiv_neighbor_set v).symm /-- This is the `finset` version of `incidence_set`. -/ def incidence_finset [decidable_eq V] : finset (sym2 V) := (G.incidence_set v).to_finset @[simp] lemma card_incidence_set_eq_degree [decidable_eq V] : fintype.card (G.incidence_set v) = G.degree v := by { rw fintype.card_congr (G.incidence_set_equiv_neighbor_set v), simp } @[simp] lemma mem_incidence_finset [decidable_eq V] (e : sym2 V) : e ∈ G.incidence_finset v ↔ e ∈ G.incidence_set v := set.mem_to_finset end finite_at section locally_finite /-- A graph is locally finite if every vertex has a finite neighbor set. -/ @[reducible] def locally_finite := Π (v : V), fintype (G.neighbor_set v) variable [locally_finite G] /-- A locally finite simple graph is regular of degree `d` if every vertex has degree `d`. -/ def is_regular_of_degree (d : ℕ) : Prop := ∀ (v : V), G.degree v = d lemma is_regular_of_degree_eq {d : ℕ} (h : G.is_regular_of_degree d) (v : V) : G.degree v = d := h v end locally_finite section finite variables [fintype V] instance neighbor_set_fintype [decidable_rel G.adj] (v : V) : fintype (G.neighbor_set v) := @subtype.fintype _ _ (by { simp_rw mem_neighbor_set, apply_instance }) _ lemma neighbor_finset_eq_filter {v : V} [decidable_rel G.adj] : G.neighbor_finset v = finset.univ.filter (G.adj v) := by { ext, simp } @[simp] lemma complete_graph_degree [decidable_eq V] (v : V) : (complete_graph V).degree v = fintype.card V - 1 := begin convert univ.card.pred_eq_sub_one, erw [degree, neighbor_finset_eq_filter, filter_ne, card_erase_of_mem (mem_univ v)], end lemma complete_graph_is_regular [decidable_eq V] : (complete_graph V).is_regular_of_degree (fintype.card V - 1) := by { intro v, simp } /-- The minimum degree of all vertices (and `0` if there are no vertices). The key properties of this are given in `exists_minimal_degree_vertex`, `min_degree_le_degree` and `le_min_degree_of_forall_le_degree`. -/ def min_degree [decidable_rel G.adj] : ℕ := option.get_or_else (univ.image (λ v, G.degree v)).min 0 /-- There exists a vertex of minimal degree. Note the assumption of being nonempty is necessary, as the lemma implies there exists a vertex. -/ lemma exists_minimal_degree_vertex [decidable_rel G.adj] [nonempty V] : ∃ v, G.min_degree = G.degree v := begin obtain ⟨t, ht : _ = _⟩ := min_of_nonempty (univ_nonempty.image (λ v, G.degree v)), obtain ⟨v, _, rfl⟩ := mem_image.mp (mem_of_min ht), refine ⟨v, by simp [min_degree, ht]⟩, end /-- The minimum degree in the graph is at most the degree of any particular vertex. -/ lemma min_degree_le_degree [decidable_rel G.adj] (v : V) : G.min_degree ≤ G.degree v := begin obtain ⟨t, ht⟩ := finset.min_of_mem (mem_image_of_mem (λ v, G.degree v) (mem_univ v)), have := finset.min_le_of_mem (mem_image_of_mem _ (mem_univ v)) ht, rw option.mem_def at ht, rwa [min_degree, ht, option.get_or_else_some], end /-- In a nonempty graph, if `k` is at most the degree of every vertex, it is at most the minimum degree. Note the assumption that the graph is nonempty is necessary as long as `G.min_degree` is defined to be a natural. -/ lemma le_min_degree_of_forall_le_degree [decidable_rel G.adj] [nonempty V] (k : ℕ) (h : ∀ v, k ≤ G.degree v) : k ≤ G.min_degree := begin rcases G.exists_minimal_degree_vertex with ⟨v, hv⟩, rw hv, apply h end /-- The maximum degree of all vertices (and `0` if there are no vertices). The key properties of this are given in `exists_maximal_degree_vertex`, `degree_le_max_degree` and `max_degree_le_of_forall_degree_le`. -/ def max_degree [decidable_rel G.adj] : ℕ := option.get_or_else (univ.image (λ v, G.degree v)).max 0 /-- There exists a vertex of maximal degree. Note the assumption of being nonempty is necessary, as the lemma implies there exists a vertex. -/ lemma exists_maximal_degree_vertex [decidable_rel G.adj] [nonempty V] : ∃ v, G.max_degree = G.degree v := begin obtain ⟨t, ht⟩ := max_of_nonempty (univ_nonempty.image (λ v, G.degree v)), have ht₂ := mem_of_max ht, simp only [mem_image, mem_univ, exists_prop_of_true] at ht₂, rcases ht₂ with ⟨v, rfl⟩, rw option.mem_def at ht, refine ⟨v, _⟩, rw [max_degree, ht], refl end /-- The maximum degree in the graph is at least the degree of any particular vertex. -/ lemma degree_le_max_degree [decidable_rel G.adj] (v : V) : G.degree v ≤ G.max_degree := begin obtain ⟨t, ht : _ = _⟩ := finset.max_of_mem (mem_image_of_mem (λ v, G.degree v) (mem_univ v)), have := finset.le_max_of_mem (mem_image_of_mem _ (mem_univ v)) ht, rwa [max_degree, ht, option.get_or_else_some], end /-- In a graph, if `k` is at least the degree of every vertex, then it is at least the maximum degree. -/ lemma max_degree_le_of_forall_degree_le [decidable_rel G.adj] (k : ℕ) (h : ∀ v, G.degree v ≤ k) : G.max_degree ≤ k := begin by_cases hV : (univ : finset V).nonempty, { haveI : nonempty V := univ_nonempty_iff.mp hV, obtain ⟨v, hv⟩ := G.exists_maximal_degree_vertex, rw hv, apply h }, { rw not_nonempty_iff_eq_empty at hV, rw [max_degree, hV, image_empty], exact zero_le k }, end lemma degree_lt_card_verts [decidable_rel G.adj] (v : V) : G.degree v < fintype.card V := begin classical, apply finset.card_lt_card, rw finset.ssubset_iff, exact ⟨v, by simp, finset.subset_univ _⟩, end /-- The maximum degree of a nonempty graph is less than the number of vertices. Note that the assumption that `V` is nonempty is necessary, as otherwise this would assert the existence of a natural less than zero. -/ lemma max_degree_lt_card_verts [decidable_rel G.adj] [nonempty V] : G.max_degree < fintype.card V := begin cases G.exists_maximal_degree_vertex with v hv, rw hv, apply G.degree_lt_card_verts v, end lemma card_common_neighbors_le_degree_left [decidable_rel G.adj] (v w : V) : fintype.card (G.common_neighbors v w) ≤ G.degree v := begin rw [←card_neighbor_set_eq_degree], exact set.card_le_of_subset (set.inter_subset_left _ _), end lemma card_common_neighbors_le_degree_right [decidable_rel G.adj] (v w : V) : fintype.card (G.common_neighbors v w) ≤ G.degree w := begin convert G.card_common_neighbors_le_degree_left w v using 3, apply common_neighbors_symm, end lemma card_common_neighbors_lt_card_verts [decidable_rel G.adj] (v w : V) : fintype.card (G.common_neighbors v w) < fintype.card V := nat.lt_of_le_of_lt (G.card_common_neighbors_le_degree_left _ _) (G.degree_lt_card_verts v) /-- If the condition `G.adj v w` fails, then `card_common_neighbors_le_degree` is the best we can do in general. -/ lemma adj.card_common_neighbors_lt_degree {G : simple_graph V} [decidable_rel G.adj] {v w : V} (h : G.adj v w) : fintype.card (G.common_neighbors v w) < G.degree v := begin classical, erw [←set.to_finset_card], apply finset.card_lt_card, rw finset.ssubset_iff, use w, split, { rw set.mem_to_finset, apply not_mem_common_neighbors_right }, { rw finset.insert_subset, split, { simpa, }, { rw [neighbor_finset, ← set.subset_iff_to_finset_subset], apply common_neighbors_subset_neighbor_set } }, end end finite section complement /-! ## Complement of a simple graph This section contains definitions and lemmas concerning the complement of a simple graph. -/ /-- We define `compl G` to be the `simple_graph V` such that no two adjacent vertices in `G` are adjacent in the complement, and every nonadjacent pair of vertices is adjacent (still ensuring that vertices are not adjacent to themselves.) -/ def compl (G : simple_graph V) : simple_graph V := { adj := λ v w, v ≠ w ∧ ¬G.adj v w, sym := λ v w ⟨hne, _⟩, ⟨hne.symm, by rwa edge_symm⟩, loopless := λ v ⟨hne, _⟩, false.elim (hne rfl) } instance has_compl : has_compl (simple_graph V) := { compl := compl } @[simp] lemma compl_adj (G : simple_graph V) (v w : V) : Gᶜ.adj v w ↔ v ≠ w ∧ ¬G.adj v w := iff.rfl instance compl_adj_decidable (V : Type u) [decidable_eq V] (G : simple_graph V) [decidable_rel G.adj] : decidable_rel Gᶜ.adj := λ v w, and.decidable @[simp] lemma compl_compl (G : simple_graph V) : Gᶜᶜ = G := begin ext v w, split; simp only [compl_adj, not_and, not_not], { exact λ ⟨hne, h⟩, h hne }, { intro h, simpa [G.ne_of_adj h], }, end @[simp] lemma compl_involutive : function.involutive (@compl V) := compl_compl lemma compl_neighbor_set_disjoint (G : simple_graph V) (v : V) : disjoint (G.neighbor_set v) (Gᶜ.neighbor_set v) := begin rw set.disjoint_iff, rintro w ⟨h, h'⟩, rw [mem_neighbor_set, compl_adj] at h', exact h'.2 h, end lemma neighbor_set_union_compl_neighbor_set_eq (G : simple_graph V) (v : V) : G.neighbor_set v ∪ Gᶜ.neighbor_set v = {v}ᶜ := begin ext w, have h := @ne_of_adj _ G, simp_rw [set.mem_union, mem_neighbor_set, compl_adj, set.mem_compl_eq, set.mem_singleton_iff], tauto, end end complement end simple_graph
0eee2fb1153e51616867854bb7d448448c4cbc2d
510e96af568b060ed5858226ad954c258549f143
/data/rat.lean
943daee89c7b3870b322d0dbce4d68aacac270bc
[]
no_license
Shamrock-Frost/library_dev
cb6d1739237d81e17720118f72ba0a6db8a5906b
0245c71e4931d3aceeacf0aea776454f6ee03c9c
refs/heads/master
1,609,481,034,595
1,500,165,215,000
1,500,165,347,000
97,350,162
0
0
null
1,500,164,969,000
1,500,164,969,000
null
UTF-8
Lean
false
false
15,853
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 Introduces the rational numbers as discrete, linear ordered field. -/ import standard /- linorder -/ section linear_order_cases_on universes u v variables {α : Type u} [decidable_linear_order α] {β : Sort v} def linear_order_cases_on (a b : α) (h_eq : a = b → β) (h_lt : a < b → β) (h_gt : a > b → β) : β := if h₁ : a = b then h_eq h₁ else if h₂ : a < b then h_lt h₂ else h_gt ((lt_or_gt_of_ne h₁)^.resolve_left h₂) variables {a b : α} {h_eq : a = b → β} {h_lt : a < b → β} {h_gt : a > b → β} lemma linear_order_cases_on_eq (h : a = b) : linear_order_cases_on a b h_eq h_lt h_gt = h_eq h := dif_pos h lemma linear_order_cases_on_lt (h : a < b) : linear_order_cases_on a b h_eq h_lt h_gt = h_lt h := eq.trans (dif_neg $ ne_of_lt h) $ dif_pos h lemma linear_order_cases_on_gt (h : a > b) : linear_order_cases_on a b h_eq h_lt h_gt = h_gt h := eq.trans (dif_neg $ (ne_of_lt h)^.symm) (dif_neg $ not_lt_of_ge $ le_of_lt h) end linear_order_cases_on /- linorder ring -/ section ordered_ring universes u variables {α : Type u} [linear_ordered_ring α] {a b : α} lemma mul_nonneg_iff_right_nonneg_of_pos (h : 0 < a) : 0 ≤ b * a ↔ 0 ≤ b := ⟨suppose 0 ≤ b * a, nonneg_of_mul_nonneg_right this h, suppose 0 ≤ b, mul_nonneg this $ le_of_lt h⟩ end ordered_ring /- auxiliary -/ lemma not_antimono {a b : Prop} (nb : ¬ b) (h : (a → b)) : ¬ a := assume ha, nb (h ha) /- rational numbers -/ namespace rat protected def num_denum := ℤ × {d:ℤ // d > 0} protected def rel : rat.num_denum → rat.num_denum → Prop | ⟨n₁, ⟨d₁, _⟩⟩ ⟨n₂, ⟨d₂, _⟩⟩ := n₁ * d₂ = n₂ * d₁ private lemma rel_trans : Π{p q r}, rat.rel p q → rat.rel q r → rat.rel p r | ⟨n₁, ⟨d₁, _⟩⟩ ⟨n₂, ⟨d₂, _⟩⟩ ⟨n₃, ⟨d₃, _⟩⟩ := assume (h₁ : n₁ * d₂ = n₂ * d₁), assume (h₂ : n₂ * d₃ = n₃ * d₂), show n₁ * d₃ = n₃ * d₁, from eq_of_mul_eq_mul_right (ne_of_lt ‹d₂ > 0›)^.symm (by cc) instance setoid_rat.rel : setoid rat.num_denum := {r := rat.rel, iseqv := ⟨assume ⟨_, ⟨_, _⟩⟩, rfl, assume ⟨n₁, ⟨d₁, _⟩⟩ ⟨n₂, ⟨d₂, _⟩⟩ h, h^.symm, assume a b c, rel_trans⟩} @[simp] protected theorem rel_eq {n₁ d₁ n₂ d₂ : ℤ} { h₁ : d₁ > 0 } { h₂ : d₂ > 0 } : @setoid.r rat.num_denum _ (n₁, ⟨d₁, h₁⟩) (n₂, ⟨d₂, h₂⟩) = (n₁ * d₂ = n₂ * d₁) := rfl end rat def rat := quotient rat.setoid_rat.rel notation `ℚ` := rat namespace rat protected def zero : ℚ := ⟦⟨0, ⟨1, zero_lt_one⟩⟩⟧ instance : has_zero ℚ := ⟨rat.zero⟩ protected def one : ℚ := ⟦⟨1, ⟨1, zero_lt_one⟩⟩⟧ instance : has_one ℚ := ⟨rat.one⟩ private def add' : rat.num_denum → rat.num_denum → ℚ | ⟨n₁, ⟨d₁, h₁⟩⟩ ⟨n₂, ⟨d₂, h₂⟩⟩ := ⟦⟨n₁ * d₂ + n₂ * d₁, ⟨d₁ * d₂, mul_pos h₁ h₂⟩⟩⟧ protected def add : ℚ → ℚ → ℚ := quotient.lift₂ add' $ λ⟨n₁, ⟨d₁, h₁⟩⟩ ⟨n₂, ⟨d₂, h₂⟩⟩ ⟨n₃, ⟨d₃, h₃⟩⟩ ⟨n₄, ⟨d₄, h₄⟩⟩, assume (h₁ : n₁ * d₃ = n₃ * d₁) (h₂ : n₂ * d₄ = n₄ * d₂), quotient.sound $ calc (n₁ * d₂ + n₂ * d₁) * (d₃ * d₄) = (n₁ * d₃) * d₂ * d₄ + (n₂ * d₄) * (d₁ * d₃) : by simp [mul_add, add_mul] ... = (n₃ * d₁) * d₂ * d₄ + (n₄ * d₂) * (d₁ * d₃) : by rw [h₁, h₂] ... = (n₃ * d₄ + n₄ * d₃) * (d₁ * d₂) : by simp [mul_add, add_mul] instance : has_add ℚ := ⟨rat.add⟩ private def neg' : rat.num_denum → ℚ | ⟨n, d⟩ := ⟦⟨-n, d⟩⟧ protected def neg : ℚ → ℚ := quotient.lift neg' $ λ⟨n₁, ⟨d₁, h₁⟩⟩ ⟨n₂, ⟨d₂, h₂⟩⟩, assume (h : n₁ * d₂ = n₂ * d₁), quotient.sound $ show (-n₁) * d₂ = (-n₂) * d₁, by simp [h] instance : has_neg ℚ := ⟨rat.neg⟩ private def mul' : rat.num_denum → rat.num_denum → ℚ | ⟨n₁, ⟨d₁, h₁⟩⟩ ⟨n₂, ⟨d₂, h₂⟩⟩ := ⟦⟨n₁ * n₂, ⟨d₁ * d₂, mul_pos h₁ h₂⟩⟩⟧ protected def mul : ℚ → ℚ → ℚ := quotient.lift₂ mul' $ λ⟨n₁, ⟨d₁, h₁⟩⟩ ⟨n₂, ⟨d₂, h₂⟩⟩ ⟨n₃, ⟨d₃, h₃⟩⟩ ⟨n₄, ⟨d₄, h₄⟩⟩, assume (h₁ : n₁ * d₃ = n₃ * d₁) (h₂ : n₂ * d₄ = n₄ * d₂), quotient.sound $ calc (n₁ * n₂) * (d₃ * d₄) = (n₁ * d₃) * (n₂ * d₄) : by simp ... = (n₃ * d₁) * (n₄ * d₂) : by rw [h₁, h₂] ... = (n₃ * n₄) * (d₁ * d₂) : by simp instance : has_mul ℚ := ⟨rat.mul⟩ private def inv' : rat.num_denum → ℚ | ⟨n, ⟨d, h⟩⟩ := linear_order_cases_on n 0 (suppose n = 0, 0) (suppose n < 0, ⟦⟨-d, ⟨-n, neg_pos_of_neg this⟩⟩⟧) (suppose n > 0, ⟦⟨d, ⟨n, this⟩⟩⟧) private lemma inv'_zero : Π{d : {d:ℤ // d > 0}}, inv' ⟨0, d⟩ = 0 | ⟨d, p⟩ := linear_order_cases_on_eq rfl private lemma inv'_pos {n d : ℤ} {h : d > 0} (p : n > 0) : inv' ⟨n, ⟨d, h⟩⟩ = ⟦⟨d, ⟨n, p⟩⟩⟧ := linear_order_cases_on_gt p private lemma inv'_neg {n d : ℤ} {h : d > 0} (p : n < 0) : inv' ⟨n, ⟨d, h⟩⟩ = ⟦⟨- d, ⟨- n, neg_pos_of_neg p⟩⟩⟧ := linear_order_cases_on_lt p protected def inv : ℚ → ℚ := quotient.lift inv' $ λ⟨n₁, ⟨d₁, h₁⟩⟩ ⟨n₂, ⟨d₂, h₂⟩⟩, assume h_eq : n₁ * d₂ = n₂ * d₁, linear_order_cases_on n₁ 0 (suppose n₁ = 0, have n₂ * d₁ = 0, by simp [this] at h_eq; simp [h_eq], have n₂ = 0, from (eq_zero_or_eq_zero_of_mul_eq_zero this)^.resolve_right $ (ne_of_lt h₁)^.symm, by simp [this, ‹n₁ = 0›, inv'_zero]) (suppose n₁ < 0, have n₂ * d₁ < 0, from h_eq ▸ mul_neg_of_neg_of_pos this ‹0 < d₂›, have n₂ < 0, from neg_of_mul_neg_right this $ le_of_lt ‹d₁ > 0›, begin rw [inv'_neg this, inv'_neg ‹n₁ < 0›], apply quotient.sound, simp [h_eq] end) (suppose n₁ > 0, have n₂ * d₁ > 0, from h_eq ▸ mul_pos this ‹0 < d₂›, have n₂ > 0, from pos_of_mul_pos_right this $ le_of_lt ‹d₁ > 0›, begin rw [inv'_pos this, inv'_pos ‹n₁ > 0›], apply quotient.sound, simp [h_eq] end) instance : has_inv ℚ := ⟨rat.inv⟩ variables (a b c : ℚ) protected lemma add_zero : a + 0 = a := quotient.induction_on a $ λ⟨n, ⟨d, h⟩⟩, quotient.sound $ by simp [rat.rel] protected lemma zero_add : 0 + a = a := quotient.induction_on a $ λ⟨n, ⟨d, h⟩⟩, quotient.sound $ by simp [rat.rel] protected lemma add_comm : a + b = b + a := quotient.induction_on₂ a b $ λ⟨n₁, ⟨d₁, h₁⟩⟩ ⟨n₂, ⟨d₂, h₂⟩⟩, quotient.sound $ by simp [rat.rel] protected lemma add_assoc : a + b + c = a + (b + c) := quotient.induction_on₃ a b c $ λ⟨n₁, ⟨d₁, h₁⟩⟩ ⟨n₂, ⟨d₂, h₂⟩⟩ ⟨n₃, ⟨d₃, h₃⟩⟩, quotient.sound $ by simp [rat.rel, mul_add, add_mul] protected lemma add_left_neg : -a + a = 0 := quotient.induction_on a $ λ⟨n, ⟨d, h⟩⟩, quotient.sound $ by simp [rat.rel] protected lemma mul_one : a * 1 = a := quotient.induction_on a $ λ⟨n, ⟨d, h⟩⟩, quotient.sound $ by simp [rat.rel] protected lemma one_mul : 1 * a = a := quotient.induction_on a $ λ⟨n, ⟨d, h⟩⟩, quotient.sound $ by simp [rat.rel] protected lemma mul_comm : a * b = b * a := quotient.induction_on₂ a b $ λ⟨n₁, ⟨d₁, h₁⟩⟩ ⟨n₂, ⟨d₂, h₂⟩⟩, quotient.sound $ by simp [rat.rel] protected lemma mul_assoc : a * b * c = a * (b * c) := quotient.induction_on₃ a b c $ λ⟨n₁, ⟨d₁, h₁⟩⟩ ⟨n₂, ⟨d₂, h₂⟩⟩ ⟨n₃, ⟨d₃, h₃⟩⟩, quotient.sound $ by simp [rat.rel] protected lemma add_mul : (a + b) * c = a * c + b * c := quotient.induction_on₃ a b c $ λ⟨n₁, ⟨d₁, h₁⟩⟩ ⟨n₂, ⟨d₂, h₂⟩⟩ ⟨n₃, ⟨d₃, h₃⟩⟩, quotient.sound $ by simp [rat.rel, mul_add, add_mul] protected lemma mul_add : a * (b + c) = a * b + a * c := quotient.induction_on₃ a b c $ λ⟨n₁, ⟨d₁, h₁⟩⟩ ⟨n₂, ⟨d₂, h₂⟩⟩ ⟨n₃, ⟨d₃, h₃⟩⟩, quotient.sound $ by simp [rat.rel, mul_add, add_mul] private lemma rat_eq_zero : ∀{a : rat.num_denum}, ⟦a⟧ = (0:ℚ) → a.1 = 0 | ⟨n, ⟨d, h⟩⟩ eq_0 := have n * 1 = 0 * d, from quotient.exact eq_0, begin simp at this, assumption end private lemma eq_zero_of_rat_eq_zero : ∀{a : rat.num_denum}, a.1 = 0 → ⟦a⟧ = (0:ℚ) | ⟨n, ⟨d, h⟩⟩ (_ : n = 0) := begin simp [‹n = 0›], apply quotient.sound, simp [rat.rel] end private lemma rat_eq_zero_iff {a : rat.num_denum} : ⟦a⟧ = (0:ℚ) ↔ a.1 = 0 := ⟨rat_eq_zero, eq_zero_of_rat_eq_zero⟩ protected lemma zero_ne_one : 0 ≠ (1:ℚ) := assume h, zero_ne_one (rat_eq_zero h^.symm)^.symm protected lemma mul_inv_cancel : a ≠ 0 → a * a⁻¹ = 1 := quotient.induction_on a $ λ⟨n, ⟨d, h⟩⟩ neq0, let a : rat.num_denum := ⟨n, ⟨d, h⟩⟩ in linear_order_cases_on n 0 (suppose n = 0, by rw [this, @eq_zero_of_rat_eq_zero ⟨0, ⟨d, h⟩⟩ rfl] at neq0; contradiction) (suppose n < 0, have @has_inv.inv rat _ ⟦a⟧ = ⟦⟨-d, ⟨-n, neg_pos_of_neg this⟩⟩⟧, from @inv'_neg n d h _, begin simp [this], apply quotient.sound, simp [rat.rel] end) (suppose n > 0, have @has_inv.inv rat _ ⟦a⟧ = ⟦⟨d, ⟨n, this⟩⟩⟧, from @inv'_pos n d h _, begin simp [this], apply quotient.sound, simp [rat.rel] end) protected lemma inv_mul_cancel (h : a ≠ 0) : a⁻¹ * a = 1 := eq.trans (rat.mul_comm _ _) (rat.mul_inv_cancel _ h) instance decidable_eq_rat.rel : Π{a b : rat.num_denum}, decidable (rat.rel a b) | ⟨n₁, ⟨d₁, h₁⟩⟩ ⟨n₂, ⟨d₂, h₂⟩⟩ := show decidable (n₁ * d₂ = n₂ * d₁), by apply_instance instance decidable_eq_rat : decidable_eq ℚ := by dunfold rat; apply_instance instance field_rat : discrete_field ℚ := { zero := rat.zero, add := rat.add, neg := rat.neg, one := rat.one, mul := rat.mul, inv := rat.inv, zero_add := rat.zero_add, add_zero := rat.add_zero, add_comm := rat.add_comm, add_assoc := rat.add_assoc, add_left_neg := rat.add_left_neg, mul_one := rat.mul_one, one_mul := rat.one_mul, mul_comm := rat.mul_comm, mul_assoc := rat.mul_assoc, left_distrib := rat.mul_add, right_distrib := rat.add_mul, zero_ne_one := rat.zero_ne_one, mul_inv_cancel := rat.mul_inv_cancel, inv_mul_cancel := rat.inv_mul_cancel, has_decidable_eq := by apply_instance, inv_zero := quotient.sound rfl } private def nonneg' : rat.num_denum → Prop | ⟨n₁, ⟨d₁, h₁⟩⟩ := 0 ≤ n₁ protected def nonneg : ℚ → Prop := quotient.lift nonneg' $ λ⟨n₁, ⟨d₁, h₁⟩⟩ ⟨n₂, ⟨d₂, h₂⟩⟩ (h : n₁ * d₂ = n₂ * d₁), propext $ calc (0 ≤ n₁) ↔ (0 ≤ n₁ * d₂) : (mul_nonneg_iff_right_nonneg_of_pos h₂)^.symm ... ↔ (0 ≤ n₂ * d₁) : by rw h ... ↔ (0 ≤ n₂) : mul_nonneg_iff_right_nonneg_of_pos h₁ protected def nonneg_add : rat.nonneg a → rat.nonneg b → rat.nonneg (a + b) := quotient.induction_on₂ a b $ λ⟨n₁, ⟨d₁, h₁⟩⟩ ⟨n₂, ⟨d₂, h₂⟩⟩ _ _, add_nonneg (mul_nonneg ‹0 ≤ n₁› (le_of_lt ‹0 < d₂›)) (mul_nonneg ‹0 ≤ n₂› (le_of_lt ‹0 < d₁›)) protected def nonneg_mul : rat.nonneg a → rat.nonneg b → rat.nonneg (a * b) := quotient.induction_on₂ a b $ λ⟨n₁, ⟨d₁, h₁⟩⟩ ⟨n₂, ⟨d₂, h₂⟩⟩ _ _, mul_nonneg ‹0 ≤ n₁› ‹0 ≤ n₂› protected def nonneg_antisymm : rat.nonneg a → rat.nonneg (-a) → a = 0 := quotient.induction_on a $ λ⟨n₁, ⟨d₁, h₁⟩⟩ (h₂ : 0 ≤ n₁) (h₃ : 0 ≤ -n₁), quotient.sound $ le_antisymm (by simp; exact le_neg_of_le_neg h₃) (by simp; exact h₂) protected def nonneg_total : rat.nonneg a ∨ rat.nonneg (-a) := quotient.induction_on a $ λ⟨n₁, ⟨d₁, h₁⟩⟩, show 0 ≤ n₁ ∨ 0 ≤ -n₁, from or.imp_right neg_nonneg_of_nonpos (le_total 0 n₁) @[instance] def decidable_nonneg : decidable (rat.nonneg a) := quotient.rec_on_subsingleton a (λ⟨n, ⟨d, h⟩⟩, if h : 0 ≤ n then is_true h else is_false h) protected def le (a b : ℚ) := rat.nonneg (b - a) instance : has_le ℚ := ⟨rat.le⟩ protected lemma le_refl : a ≤ a := show rat.nonneg (a - a), begin rw [sub_self], exact le_refl (0 : int) end instance : linear_strong_order_pair ℚ := { le := rat.le, lt := λa b, a ≤ b ∧ a ≠ b, le_iff_lt_or_eq := assume a b, ⟨suppose a ≤ b, if h : a = b then or.inr h else or.inl ⟨this, h⟩, or.rec and.left (suppose a = b, show a ≤ b, from this ▸ rat.le_refl _)⟩, lt_irrefl := assume a ⟨_, h⟩, h rfl, le_refl := rat.le_refl, le_trans := assume a b c h_ab h_bc, have rat.nonneg (b - a + (c - b)), from rat.nonneg_add _ _ h_ab h_bc, show rat.nonneg (c - a), by simp at this; assumption, le_antisymm := assume a b h_ab h_ba, have a = - - b, from eq_neg_of_add_eq_zero $ rat.nonneg_antisymm _ h_ba (by simp; assumption), by rw neg_neg at this; assumption, le_total := assume a b, have rat.nonneg (b - a) ∨ rat.nonneg (- (b - a)), from rat.nonneg_total _, by rw neg_sub at this; assumption } protected def zero_le_of_nonneg : rat.nonneg a → 0 ≤ a := quotient.induction_on a $ assume ⟨n, ⟨d, h⟩⟩ _, show 0 ≤ n * 1 + (- 0) * d, by simp; assumption protected def nonneg_of_zero_le : 0 ≤ a → rat.nonneg a := quotient.induction_on a $ assume ⟨n, ⟨d, h⟩⟩, suppose 0 ≤ n * 1 + (- 0) * d, by simp at this; assumption instance : discrete_linear_ordered_field ℚ := { rat.field_rat with le := (≤), lt := (<), le_refl := le_refl, le_trans := assume a b c, le_trans, le_antisymm := assume a b, le_antisymm, le_total := le_total, le_iff_lt_or_eq := assume a b, le_iff_lt_or_eq, lt_irrefl := lt_irrefl, le_of_lt := assume a b, le_of_lt, lt_of_lt_of_le := assume a b c, lt_of_lt_of_le, lt_of_le_of_lt := assume a b c, lt_of_le_of_lt, zero_lt_one := ⟨rat.zero_le_of_nonneg _ (@zero_le_one int _), zero_ne_one⟩, add_le_add_left := assume a b (h_ab : rat.nonneg (b - a)) c, show rat.nonneg ((c + b) - (c + a)), by rw add_sub_add_left_eq_sub; assumption, add_lt_add_left := assume a b ⟨a_le_b, a_ne_b⟩ c, show rat.nonneg ((c + b) - (c + a)) ∧ c + a ≠ c + b, by rw [add_sub_add_left_eq_sub]; exact ⟨a_le_b, not_antimono a_ne_b add_left_cancel⟩, mul_nonneg := assume a b ha hb, rat.zero_le_of_nonneg _ $ rat.nonneg_mul _ _ (rat.nonneg_of_zero_le a ha) (rat.nonneg_of_zero_le b hb), mul_pos := assume a b ⟨nn_a, a_ne_zero⟩ ⟨nn_b, b_ne_zero⟩, ⟨rat.zero_le_of_nonneg _ $ rat.nonneg_mul _ _ (rat.nonneg_of_zero_le a nn_a) (rat.nonneg_of_zero_le b nn_b), (mul_ne_zero a_ne_zero^.symm b_ne_zero^.symm)^.symm⟩, decidable_eq := by apply_instance, decidable_le := assume a b, rat.decidable_nonneg (b - a), decidable_lt := assume a b, show decidable (rat.nonneg (b - a) ∧ a ≠ b), by apply_instance } end rat
2e3e930edc155223973dfa3c5e0cc7a5627e873f
5412d79aa1dc0b521605c38bef9f0d4557b5a29d
/src/Lean/Parser/Term.lean
2bfddb34ba12121a90b7d096e409b73e2d25e389
[ "Apache-2.0" ]
permissive
smunix/lean4
a450ec0927dc1c74816a1bf2818bf8600c9fc9bf
3407202436c141e3243eafbecb4b8720599b970a
refs/heads/master
1,676,334,875,188
1,610,128,510,000
1,610,128,521,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
14,987
lean
/- Copyright (c) 2019 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Sebastian Ullrich -/ import Lean.Parser.Attr import Lean.Parser.Level namespace Lean namespace Parser builtin_initialize registerBuiltinParserAttribute `builtinTacticParser `tactic LeadingIdentBehavior.both registerBuiltinDynamicParserAttribute `tacticParser `tactic @[inline] def tacticParser (rbp : Nat := 0) : Parser := categoryParser `tactic rbp namespace Tactic def tacticSeq1Indented : Parser := parser! many1Indent (group (ppLine >> tacticParser >> optional ";")) def tacticSeqBracketed : Parser := parser! "{" >> many (group (ppLine >> tacticParser >> optional ";")) >> ppDedent (ppLine >> "}") def tacticSeq := nodeWithAntiquot "tacticSeq" `Lean.Parser.Tactic.tacticSeq (tacticSeqBracketed <|> tacticSeq1Indented) /- Raw sequence for quotation and grouping -/ def seq1 := node `Lean.Parser.Tactic.seq1 $ sepBy1 tacticParser ";\n" (allowTrailingSep := true) end Tactic def darrow : Parser := " => " namespace Term /- Built-in parsers -/ @[builtinTermParser] def byTactic := parser!:leadPrec "by " >> Tactic.tacticSeq def optSemicolon (p : Parser) : Parser := ppDedent $ optional ";" >> ppLine >> p -- `checkPrec` necessary for the pretty printer @[builtinTermParser] def ident := checkPrec maxPrec >> Parser.ident @[builtinTermParser] def num : Parser := checkPrec maxPrec >> numLit @[builtinTermParser] def scientific : Parser := checkPrec maxPrec >> scientificLit @[builtinTermParser] def str : Parser := checkPrec maxPrec >> strLit @[builtinTermParser] def char : Parser := checkPrec maxPrec >> charLit @[builtinTermParser] def type := parser! "Type" >> optional (checkWsBefore "" >> checkPrec leadPrec >> checkColGt >> levelParser maxPrec) @[builtinTermParser] def sort := parser! "Sort" >> optional (checkWsBefore "" >> checkPrec leadPrec >> checkColGt >> levelParser maxPrec) @[builtinTermParser] def prop := parser! "Prop" @[builtinTermParser] def hole := parser! "_" @[builtinTermParser] def syntheticHole := parser! "?" >> (ident <|> hole) @[builtinTermParser] def «sorry» := parser! "sorry" @[builtinTermParser] def cdot := parser! symbol "·" <|> "." @[builtinTermParser] def emptyC := parser! "∅" <|> (symbol "{" >> "}") def typeAscription := parser! " : " >> termParser def tupleTail := parser! ", " >> sepBy1 termParser ", " def parenSpecial : Parser := optional (tupleTail <|> typeAscription) @[builtinTermParser] def paren := parser! "(" >> ppDedent (withoutPosition (withoutForbidden (optional (termParser >> parenSpecial)))) >> ")" @[builtinTermParser] def anonymousCtor := parser! "⟨" >> sepBy termParser ", " >> "⟩" def optIdent : Parser := optional (atomic (ident >> " : ")) def fromTerm := parser! " from " >> termParser def haveAssign := parser! " := " >> termParser def haveDecl := optIdent >> termParser >> (haveAssign <|> fromTerm <|> byTactic) @[builtinTermParser] def «have» := parser!:leadPrec withPosition ("have " >> haveDecl) >> optSemicolon termParser def sufficesDecl := optIdent >> termParser >> (fromTerm <|> byTactic) @[builtinTermParser] def «suffices» := parser!:leadPrec withPosition ("suffices " >> sufficesDecl) >> optSemicolon termParser @[builtinTermParser] def «show» := parser!:leadPrec "show " >> termParser >> (fromTerm <|> byTactic) def structInstArrayRef := parser! "[" >> termParser >>"]" def structInstLVal := parser! (ident <|> fieldIdx <|> structInstArrayRef) >> many (group ("." >> (ident <|> fieldIdx)) <|> structInstArrayRef) def structInstField := ppGroup $ parser! structInstLVal >> " := " >> termParser def optEllipsis := parser! optional ".." @[builtinTermParser] def structInst := parser! "{" >> ppHardSpace >> optional (atomic (termParser >> " with ")) >> manyIndent (group (structInstField >> optional ", ")) >> optEllipsis >> optional (" : " >> termParser) >> " }" def typeSpec := parser! " : " >> termParser def optType : Parser := optional typeSpec @[builtinTermParser] def explicit := parser! "@" >> termParser maxPrec @[builtinTermParser] def inaccessible := parser! ".(" >> termParser >> ")" def binderIdent : Parser := ident <|> hole def binderType (requireType := false) : Parser := if requireType then group (" : " >> termParser) else optional (" : " >> termParser) def binderTactic := parser! atomic (symbol " := " >> " by ") >> Tactic.tacticSeq def binderDefault := parser! " := " >> termParser def explicitBinder (requireType := false) := ppGroup $ parser! "(" >> many1 binderIdent >> binderType requireType >> optional (binderTactic <|> binderDefault) >> ")" def implicitBinder (requireType := false) := ppGroup $ parser! "{" >> many1 binderIdent >> binderType requireType >> "}" def instBinder := ppGroup $ parser! "[" >> optIdent >> termParser >> "]" def bracketedBinder (requireType := false) := explicitBinder requireType <|> implicitBinder requireType <|> instBinder /- It is feasible to support dependent arrows such as `{α} → α → α` without sacrificing the quality of the error messages for the longer case. `{α} → α → α` would be short for `{α : Type} → α → α` Here is the encoding: ``` def implicitShortBinder := node `Lean.Parser.Term.implicitBinder $ "{" >> many1 binderIdent >> pushNone >> "}" def depArrowShortPrefix := try (implicitShortBinder >> unicodeSymbol " → " " -> ") def depArrowLongPrefix := bracketedBinder true >> unicodeSymbol " → " " -> " def depArrowPrefix := depArrowShortPrefix <|> depArrowLongPrefix @[builtinTermParser] def depArrow := parser! depArrowPrefix >> termParser ``` Note that no changes in the elaborator are needed. We decided to not use it because terms such as `{α} → α → α` may look too cryptic. Note that we did not add a `explicitShortBinder` parser since `(α) → α → α` is really cryptic as a short for `(α : Type) → α → α`. -/ @[builtinTermParser] def depArrow := parser!:25 bracketedBinder true >> unicodeSymbol " → " " -> " >> termParser def simpleBinder := parser! many1 binderIdent >> optType @[builtinTermParser] def «forall» := parser!:leadPrec unicodeSymbol "∀ " "forall" >> many1 (ppSpace >> (simpleBinder <|> bracketedBinder)) >> ", " >> termParser def matchAlt (rhsParser : Parser := termParser) : Parser := nodeWithAntiquot "matchAlt" `Lean.Parser.Term.matchAlt $ "| " >> ppIndent (sepBy1 termParser ", " >> darrow >> rhsParser) /-- Useful for syntax quotations. Note that generic patterns such as `` `(matchAltExpr| | ... => $rhs) `` should also work with other `rhsParser`s (of arity 1). -/ def matchAltExpr := matchAlt def matchAlts (rhsParser : Parser := termParser) : Parser := parser! ppDedent $ withPosition $ many1Indent (ppLine >> matchAlt rhsParser) def matchDiscr := parser! optional (atomic (ident >> checkNoWsBefore "no space before ':'" >> ":")) >> termParser @[builtinTermParser] def «match» := parser!:leadPrec "match " >> sepBy1 matchDiscr ", " >> optType >> " with " >> matchAlts @[builtinTermParser] def «nomatch» := parser!:leadPrec "nomatch " >> termParser def funImplicitBinder := atomic (lookahead ("{" >> many1 binderIdent >> (symbol " : " <|> "}"))) >> implicitBinder def funSimpleBinder := atomic (lookahead (many1 binderIdent >> " : ")) >> simpleBinder def funBinder : Parser := funImplicitBinder <|> instBinder <|> funSimpleBinder <|> termParser maxPrec -- NOTE: we use `nodeWithAntiquot` to ensure that `fun $b => ...` remains a `term` antiquotation def basicFun : Parser := nodeWithAntiquot "basicFun" `Lean.Parser.Term.basicFun (many1 (ppSpace >> funBinder) >> darrow >> termParser) @[builtinTermParser] def «fun» := parser!:maxPrec unicodeSymbol "λ" "fun" >> (basicFun <|> matchAlts) def optExprPrecedence := optional (atomic ":" >> termParser maxPrec) @[builtinTermParser] def «parser!» := parser!:leadPrec "parser! " >> optExprPrecedence >> termParser @[builtinTermParser] def «tparser!» := parser!:leadPrec "tparser! " >> optExprPrecedence >> termParser @[builtinTermParser] def borrowed := parser! "@&" >> termParser leadPrec @[builtinTermParser] def quotedName := parser! nameLit @[builtinTermParser] def doubleQuotedName := parser! "`" >> checkNoWsBefore >> nameLit def simpleBinderWithoutType := nodeWithAntiquot "simpleBinder" `Lean.Parser.Term.simpleBinder (anonymous := true) (many1 binderIdent >> pushNone) /- Remark: we use `checkWsBefore` to ensure `let x[i] := e; b` is not parsed as `let x [i] := e; b` where `[i]` is an `instBinder`. -/ def letIdLhs : Parser := ident >> checkWsBefore "expected space before binders" >> many (ppSpace >> (simpleBinderWithoutType <|> bracketedBinder)) >> optType def letIdDecl := nodeWithAntiquot "letIdDecl" `Lean.Parser.Term.letIdDecl $ atomic (letIdLhs >> " := ") >> termParser def letPatDecl := nodeWithAntiquot "letPatDecl" `Lean.Parser.Term.letPatDecl $ atomic (termParser >> pushNone >> optType >> " := ") >> termParser def letEqnsDecl := nodeWithAntiquot "letEqnsDecl" `Lean.Parser.Term.letEqnsDecl $ letIdLhs >> matchAlts -- Remark: we use `nodeWithAntiquot` here to make sure anonymous antiquotations (e.g., `$x`) are not `letDecl` def letDecl := nodeWithAntiquot "letDecl" `Lean.Parser.Term.letDecl (notFollowedBy (nonReservedSymbol "rec") "rec" >> (letIdDecl <|> letPatDecl <|> letEqnsDecl)) @[builtinTermParser] def «let» := parser!:leadPrec withPosition ("let " >> letDecl) >> optSemicolon termParser @[builtinTermParser] def «let!» := parser!:leadPrec withPosition ("let! " >> letDecl) >> optSemicolon termParser @[builtinTermParser] def «let*» := parser!:leadPrec withPosition ("let* " >> letDecl) >> optSemicolon termParser def «scoped» := parser! "scoped " def «local» := parser! "local " def attrKind := parser! optional («scoped» <|> «local») def attrInstance := ppGroup $ parser! attrKind >> attrParser def attributes := parser! "@[" >> sepBy1 attrInstance ", " >> "]" def letRecDecl := parser! optional «attributes» >> letDecl def letRecDecls := sepBy1 letRecDecl ", " @[builtinTermParser] def «letrec» := parser!:leadPrec withPosition (group ("let " >> nonReservedSymbol "rec ") >> letRecDecls) >> optSemicolon termParser @[runBuiltinParserAttributeHooks] def whereDecls := parser! "where " >> many1Indent (group (letRecDecl >> optional ";")) @[runBuiltinParserAttributeHooks] def matchAltsWhereDecls := parser! matchAlts >> optional whereDecls @[builtinTermParser] def nativeRefl := parser! "nativeRefl! " >> termParser maxPrec @[builtinTermParser] def nativeDecide := parser! "nativeDecide!" @[builtinTermParser] def decide := parser! "decide!" @[builtinTermParser] def noindex := parser! "noindex!" >> termParser maxPrec @[builtinTermParser] def binrel := parser! "binrel! " >> ident >> ppSpace >> termParser maxPrec >> termParser maxPrec @[builtinTermParser] def typeOf := parser! "typeOf! " >> termParser maxPrec @[builtinTermParser] def ensureTypeOf := parser! "ensureTypeOf! " >> termParser maxPrec >> strLit >> termParser @[builtinTermParser] def ensureExpectedType := parser! "ensureExpectedType! " >> strLit >> termParser maxPrec def namedArgument := parser! atomic ("(" >> ident >> " := ") >> termParser >> ")" def ellipsis := parser! ".." @[builtinTermParser] def app := tparser!:(maxPrec-1) many1 $ checkWsBefore "expected space" >> checkColGt "expected to be indented" >> (namedArgument <|> ellipsis <|> termParser maxPrec) @[builtinTermParser] def proj := tparser! checkNoWsBefore >> "." >> (fieldIdx <|> ident) @[builtinTermParser] def arrayRef := tparser! checkNoWsBefore >> "[" >> termParser >>"]" @[builtinTermParser] def arrow := tparser! checkPrec 25 >> unicodeSymbol " → " " -> " >> termParser 25 def isIdent (stx : Syntax) : Bool := -- antiquotations should also be allowed where an identifier is expected stx.isAntiquot || stx.isIdent @[builtinTermParser] def explicitUniv : TrailingParser := tparser! checkStackTop isIdent "expected preceding identifier" >> checkNoWsBefore "no space before '.{'" >> ".{" >> sepBy1 levelParser ", " >> "}" @[builtinTermParser] def namedPattern : TrailingParser := tparser! checkStackTop isIdent "expected preceding identifier" >> checkNoWsBefore "no space before '@'" >> "@" >> termParser maxPrec @[builtinTermParser] def pipeProj := tparser!:minPrec " |>. " >> (fieldIdx <|> ident) @[builtinTermParser] def subst := tparser!:75 " ▸ " >> sepBy1 (termParser 75) " ▸ " -- NOTE: Doesn't call `categoryParser` directly in contrast to most other "static" quotations, so call `evalInsideQuot` explicitly @[builtinTermParser] def funBinder.quot : Parser := parser! "`(funBinder|" >> toggleInsideQuot (evalInsideQuot ``funBinder funBinder) >> ")" @[builtinTermParser] def bracketedBinder.quot : Parser := parser! "`(bracketedBinder|" >> toggleInsideQuot (evalInsideQuot ``bracketedBinder bracketedBinder) >> ")" @[builtinTermParser] def matchDiscr.quot : Parser := parser! "`(matchDiscr|" >> toggleInsideQuot (evalInsideQuot ``matchDiscr matchDiscr) >> ")" @[builtinTermParser] def attr.quot : Parser := parser! "`(attr|" >> toggleInsideQuot attrParser >> ")" @[builtinTermParser] def panic := parser!:leadPrec "panic! " >> termParser @[builtinTermParser] def unreachable := parser!:leadPrec "unreachable!" @[builtinTermParser] def dbgTrace := parser!:leadPrec withPosition ("dbgTrace! " >> ((interpolatedStr termParser) <|> termParser)) >> optSemicolon termParser @[builtinTermParser] def assert := parser!:leadPrec withPosition ("assert! " >> termParser) >> optSemicolon termParser def macroArg := termParser maxPrec def macroDollarArg := parser! "$" >> termParser 10 def macroLastArg := macroDollarArg <|> macroArg -- Macro for avoiding exponentially big terms when using `STWorld` @[builtinTermParser] def stateRefT := parser! "StateRefT" >> macroArg >> macroLastArg @[builtinTermParser] def dynamicQuot := parser! "`(" >> ident >> "|" >> toggleInsideQuot (parserOfStack 1) >> ")" end Term @[builtinTermParser default+1] def Tactic.quot : Parser := parser! "`(tactic|" >> toggleInsideQuot tacticParser >> ")" @[builtinTermParser] def Tactic.quotSeq : Parser := parser! "`(tactic|" >> toggleInsideQuot Tactic.seq1 >> ")" @[builtinTermParser] def Level.quot : Parser := parser! "`(level|" >> toggleInsideQuot levelParser >> ")" builtin_initialize registerParserAlias! "letDecl" Term.letDecl registerParserAlias! "haveDecl" Term.haveDecl registerParserAlias! "sufficesDecl" Term.sufficesDecl registerParserAlias! "letRecDecls" Term.letRecDecls registerParserAlias! "hole" Term.hole registerParserAlias! "syntheticHole" Term.syntheticHole registerParserAlias! "matchDiscr" Term.matchDiscr registerParserAlias! "bracketedBinder" Term.bracketedBinder registerParserAlias! "attrKind" Term.attrKind end Parser end Lean
f7d4ba18ca93d52a58bfbe3365abe0caed9882f3
b561a44b48979a98df50ade0789a21c79ee31288
/src/Lean/Parser/Basic.lean
7e6bba75b2059dfc98107eb49f01879a6e568ad9
[ "Apache-2.0" ]
permissive
3401ijk/lean4
97659c475ebd33a034fed515cb83a85f75ccfb06
a5b1b8de4f4b038ff752b9e607b721f15a9a4351
refs/heads/master
1,693,933,007,651
1,636,424,845,000
1,636,424,845,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
76,475
lean
/- Copyright (c) 2019 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Sebastian Ullrich -/ import Lean.Data.Trie import Lean.Data.Position import Lean.Syntax import Lean.ToExpr import Lean.Environment import Lean.Attributes import Lean.Message import Lean.Compiler.InitAttr import Lean.ResolveName /-! # Basic Lean parser infrastructure The Lean parser was developed with the following primary goals in mind: * flexibility: Lean's grammar is complex and includes indentation and other whitespace sensitivity. It should be possible to introduce such custom "tweaks" locally without having to adjust the fundamental parsing approach. * extensibility: Lean's grammar can be extended on the fly within a Lean file, and with Lean 4 we want to extend this to cover embedding domain-specific languages that may look nothing like Lean, down to using a separate set of tokens. * losslessness: The parser should produce a concrete syntax tree that preserves all whitespace and other "sub-token" information for the use in tooling. * performance: The overhead of the parser building blocks, and the overall parser performance on average-complexity input, should be comparable with that of the previous parser hand-written in C++. No fancy optimizations should be necessary for this. Given these constraints, we decided to implement a combinatoric, non-monadic, lexer-less, memoizing recursive-descent parser. Using combinators instead of some more formal and introspectible grammar representation ensures ultimate flexibility as well as efficient extensibility: there is (almost) no pre-processing necessary when extending the grammar with a new parser. However, because the all results the combinators produce are of the homogeneous `Syntax` type, the basic parser type is not actually a monad but a monomorphic linear function `ParserState → ParserState`, avoiding constructing and deconstructing countless monadic return values. Instead of explicitly returning syntax objects, parsers push (zero or more of) them onto a syntax stack inside the linear state. Chaining parsers via `>>` accumulates their output on the stack. Combinators such as `node` then pop off all syntax objects produced during their invocation and wrap them in a single `Syntax.node` object that is again pushed on this stack. Instead of calling `node` directly, we usually use the macro `leading_parser p`, which unfolds to `node k p` where the new syntax node kind `k` is the name of the declaration being defined. The lack of a dedicated lexer ensures we can modify and replace the lexical grammar at any point, and simplifies detecting and propagating whitespace. The parser still has a concept of "tokens", however, and caches the most recent one for performance: when `tokenFn` is called twice at the same position in the input, it will reuse the result of the first call. `tokenFn` recognizes some built-in variable-length tokens such as identifiers as well as any fixed token in the `ParserContext`'s `TokenTable` (a trie); however, the same cache field and strategy could be reused by custom token parsers. Tokens also play a central role in the `prattParser` combinator, which selects a *leading* parser followed by zero or more *trailing* parsers based on the current token (via `peekToken`); see the documentation of `prattParser` for more details. Tokens are specified via the `symbol` parser, or with `symbolNoWs` for tokens that should not be preceded by whitespace. The `Parser` type is extended with additional metadata over the mere parsing function to propagate token information: `collectTokens` collects all tokens within a parser for registering. `firstTokens` holds information about the "FIRST" token set used to speed up parser selection in `prattParser`. This approach of combining static and dynamic information in the parser type is inspired by the paper "Deterministic, Error-Correcting Combinator Parsers" by Swierstra and Duponcheel. If multiple parsers accept the same current token, `prattParser` tries all of them using the backtracking `longestMatchFn` combinator. This is the only case where standard parsers might execute arbitrary backtracking. At the moment there is no memoization shared by these parallel parsers apart from the first token, though we might change this in the future if the need arises. Finally, error reporting follows the standard combinatoric approach of collecting a single unexpected token/... and zero or more expected tokens (see `Error` below). Expected tokens are e.g. set by `symbol` and merged by `<|>`. Combinators running multiple parsers should check if an error message is set in the parser state (`hasError`) and act accordingly. Error recovery is left to the designer of the specific language; for example, Lean's top-level `parseCommand` loop skips tokens until the next command keyword on error. -/ namespace Lean namespace Parser def isLitKind (k : SyntaxNodeKind) : Bool := k == strLitKind || k == numLitKind || k == charLitKind || k == nameLitKind || k == scientificLitKind abbrev mkAtom (info : SourceInfo) (val : String) : Syntax := Syntax.atom info val abbrev mkIdent (info : SourceInfo) (rawVal : Substring) (val : Name) : Syntax := Syntax.ident info rawVal val [] /- Return character after position `pos` -/ def getNext (input : String) (pos : Nat) : Char := input.get (input.next pos) /- Maximal (and function application) precedence. In the standard lean language, no parser has precedence higher than `maxPrec`. Note that nothing prevents users from using a higher precedence, but we strongly discourage them from doing it. -/ def maxPrec : Nat := eval_prec max def argPrec : Nat := eval_prec arg def leadPrec : Nat := eval_prec lead def minPrec : Nat := eval_prec min abbrev Token := String structure TokenCacheEntry where startPos : String.Pos := 0 stopPos : String.Pos := 0 token : Syntax := Syntax.missing structure ParserCache where tokenCache : TokenCacheEntry def initCacheForInput (input : String) : ParserCache := { tokenCache := { startPos := input.bsize + 1 /- make sure it is not a valid position -/} } abbrev TokenTable := Trie Token abbrev SyntaxNodeKindSet := Std.PersistentHashMap SyntaxNodeKind Unit def SyntaxNodeKindSet.insert (s : SyntaxNodeKindSet) (k : SyntaxNodeKind) : SyntaxNodeKindSet := Std.PersistentHashMap.insert s k () /- Input string and related data. Recall that the `FileMap` is a helper structure for mapping `String.Pos` in the input string to line/column information. -/ structure InputContext where input : String fileName : String fileMap : FileMap deriving Inhabited /-- Input context derived from elaboration of previous commands. -/ structure ParserModuleContext where env : Environment options : Options -- for name lookup currNamespace : Name := Name.anonymous openDecls : List OpenDecl := [] structure ParserContext extends InputContext, ParserModuleContext where prec : Nat tokens : TokenTable quotDepth : Nat := 0 suppressInsideQuot : Bool := false savedPos? : Option String.Pos := none forbiddenTk? : Option Token := none def ParserContext.resolveName (ctx : ParserContext) (id : Name) : List (Name × List String) := ResolveName.resolveGlobalName ctx.env ctx.currNamespace ctx.openDecls id structure Error where unexpected : String := "" expected : List String := [] deriving Inhabited, BEq namespace Error private def expectedToString : List String → String | [] => "" | [e] => e | [e1, e2] => e1 ++ " or " ++ e2 | e::es => e ++ ", " ++ expectedToString es protected def toString (e : Error) : String := let unexpected := if e.unexpected == "" then [] else [e.unexpected] let expected := if e.expected == [] then [] else let expected := e.expected.toArray.qsort (fun e e' => e < e') let expected := expected.toList.eraseReps ["expected " ++ expectedToString expected] "; ".intercalate $ unexpected ++ expected instance : ToString Error := ⟨Error.toString⟩ def merge (e₁ e₂ : Error) : Error := match e₂ with | { unexpected := u, .. } => { unexpected := if u == "" then e₁.unexpected else u, expected := e₁.expected ++ e₂.expected } end Error structure ParserState where stxStack : Array Syntax := #[] /-- Set to the precedence of the preceding (not surrounding) parser by `runLongestMatchParser` for the use of `checkLhsPrec` in trailing parsers. Note that with chaining, the preceding parser can be another trailing parser: in `1 * 2 + 3`, the preceding parser is '*' when '+' is executed. -/ lhsPrec : Nat := 0 pos : String.Pos := 0 cache : ParserCache errorMsg : Option Error := none namespace ParserState @[inline] def hasError (s : ParserState) : Bool := s.errorMsg != none @[inline] def stackSize (s : ParserState) : Nat := s.stxStack.size def restore (s : ParserState) (iniStackSz : Nat) (iniPos : Nat) : ParserState := { s with stxStack := s.stxStack.shrink iniStackSz, errorMsg := none, pos := iniPos } def setPos (s : ParserState) (pos : Nat) : ParserState := { s with pos := pos } def setCache (s : ParserState) (cache : ParserCache) : ParserState := { s with cache := cache } def pushSyntax (s : ParserState) (n : Syntax) : ParserState := { s with stxStack := s.stxStack.push n } def popSyntax (s : ParserState) : ParserState := { s with stxStack := s.stxStack.pop } def shrinkStack (s : ParserState) (iniStackSz : Nat) : ParserState := { s with stxStack := s.stxStack.shrink iniStackSz } def next (s : ParserState) (input : String) (pos : Nat) : ParserState := { s with pos := input.next pos } def toErrorMsg (ctx : ParserContext) (s : ParserState) : String := match s.errorMsg with | none => "" | some msg => let pos := ctx.fileMap.toPosition s.pos mkErrorStringWithPos ctx.fileName pos (toString msg) def mkNode (s : ParserState) (k : SyntaxNodeKind) (iniStackSz : Nat) : ParserState := match s with | ⟨stack, lhsPrec, pos, cache, err⟩ => if err != none && stack.size == iniStackSz then -- If there is an error but there are no new nodes on the stack, use `missing` instead. -- Thus we ensure the property that an syntax tree contains (at least) one `missing` node -- if (and only if) there was a parse error. -- We should not create an actual node of kind `k` in this case because it would mean we -- choose an "arbitrary" node (in practice the last one) in an alternative of the form -- `node k1 p1 <|> ... <|> node kn pn` when all parsers fail. With the code below we -- instead return a less misleading single `missing` node without randomly selecting any `ki`. let stack := stack.push Syntax.missing ⟨stack, lhsPrec, pos, cache, err⟩ else let newNode := Syntax.node SourceInfo.none k (stack.extract iniStackSz stack.size) let stack := stack.shrink iniStackSz let stack := stack.push newNode ⟨stack, lhsPrec, pos, cache, err⟩ def mkTrailingNode (s : ParserState) (k : SyntaxNodeKind) (iniStackSz : Nat) : ParserState := match s with | ⟨stack, lhsPrec, pos, cache, err⟩ => let newNode := Syntax.node SourceInfo.none k (stack.extract (iniStackSz - 1) stack.size) let stack := stack.shrink (iniStackSz - 1) let stack := stack.push newNode ⟨stack, lhsPrec, pos, cache, err⟩ def setError (s : ParserState) (msg : String) : ParserState := match s with | ⟨stack, lhsPrec, pos, cache, _⟩ => ⟨stack, lhsPrec, pos, cache, some { expected := [ msg ] }⟩ def mkError (s : ParserState) (msg : String) : ParserState := match s with | ⟨stack, lhsPrec, pos, cache, _⟩ => ⟨stack.push Syntax.missing, lhsPrec, pos, cache, some { expected := [ msg ] }⟩ def mkUnexpectedError (s : ParserState) (msg : String) (expected : List String := []) : ParserState := match s with | ⟨stack, lhsPrec, pos, cache, _⟩ => ⟨stack.push Syntax.missing, lhsPrec, pos, cache, some { unexpected := msg, expected := expected }⟩ def mkEOIError (s : ParserState) (expected : List String := []) : ParserState := s.mkUnexpectedError "unexpected end of input" expected def mkErrorAt (s : ParserState) (msg : String) (pos : String.Pos) (initStackSz? : Option Nat := none) : ParserState := match s, initStackSz? with | ⟨stack, lhsPrec, _, cache, _⟩, none => ⟨stack.push Syntax.missing, lhsPrec, pos, cache, some { expected := [ msg ] }⟩ | ⟨stack, lhsPrec, _, cache, _⟩, some sz => ⟨stack.shrink sz |>.push Syntax.missing, lhsPrec, pos, cache, some { expected := [ msg ] }⟩ def mkErrorsAt (s : ParserState) (ex : List String) (pos : String.Pos) (initStackSz? : Option Nat := none) : ParserState := match s, initStackSz? with | ⟨stack, lhsPrec, _, cache, _⟩, none => ⟨stack.push Syntax.missing, lhsPrec, pos, cache, some { expected := ex }⟩ | ⟨stack, lhsPrec, _, cache, _⟩, some sz => ⟨stack.shrink sz |>.push Syntax.missing, lhsPrec, pos, cache, some { expected := ex }⟩ def mkUnexpectedErrorAt (s : ParserState) (msg : String) (pos : String.Pos) : ParserState := match s with | ⟨stack, lhsPrec, _, cache, _⟩ => ⟨stack.push Syntax.missing, lhsPrec, pos, cache, some { unexpected := msg }⟩ end ParserState def ParserFn := ParserContext → ParserState → ParserState instance : Inhabited ParserFn where default := fun ctx s => s inductive FirstTokens where | epsilon : FirstTokens | unknown : FirstTokens | tokens : List Token → FirstTokens | optTokens : List Token → FirstTokens deriving Inhabited namespace FirstTokens def seq : FirstTokens → FirstTokens → FirstTokens | epsilon, tks => tks | optTokens s₁, optTokens s₂ => optTokens (s₁ ++ s₂) | optTokens s₁, tokens s₂ => tokens (s₁ ++ s₂) | tks, _ => tks def toOptional : FirstTokens → FirstTokens | tokens tks => optTokens tks | tks => tks def merge : FirstTokens → FirstTokens → FirstTokens | epsilon, tks => toOptional tks | tks, epsilon => toOptional tks | tokens s₁, tokens s₂ => tokens (s₁ ++ s₂) | optTokens s₁, optTokens s₂ => optTokens (s₁ ++ s₂) | tokens s₁, optTokens s₂ => optTokens (s₁ ++ s₂) | optTokens s₁, tokens s₂ => optTokens (s₁ ++ s₂) | _, _ => unknown def toStr : FirstTokens → String | epsilon => "epsilon" | unknown => "unknown" | tokens tks => toString tks | optTokens tks => "?" ++ toString tks instance : ToString FirstTokens := ⟨toStr⟩ end FirstTokens structure ParserInfo where collectTokens : List Token → List Token := id collectKinds : SyntaxNodeKindSet → SyntaxNodeKindSet := id firstTokens : FirstTokens := FirstTokens.unknown deriving Inhabited structure Parser where info : ParserInfo := {} fn : ParserFn deriving Inhabited abbrev TrailingParser := Parser def dbgTraceStateFn (label : String) (p : ParserFn) : ParserFn := fun c s => let sz := s.stxStack.size let s' := p c s dbg_trace "{label} pos: {s'.pos} err: {s'.errorMsg} out: {s'.stxStack.extract sz s'.stxStack.size}" s' def dbgTraceState (label : String) (p : Parser) : Parser where fn := dbgTraceStateFn label p.fn info := p.info @[noinline] def epsilonInfo : ParserInfo := { firstTokens := FirstTokens.epsilon } @[inline] def checkStackTopFn (p : Syntax → Bool) (msg : String) : ParserFn := fun c s => if p s.stxStack.back then s else s.mkUnexpectedError msg @[inline] def checkStackTop (p : Syntax → Bool) (msg : String) : Parser := { info := epsilonInfo, fn := checkStackTopFn p msg } @[inline] def andthenFn (p q : ParserFn) : ParserFn := fun c s => let s := p c s if s.hasError then s else q c s @[noinline] def andthenInfo (p q : ParserInfo) : ParserInfo := { collectTokens := p.collectTokens ∘ q.collectTokens, collectKinds := p.collectKinds ∘ q.collectKinds, firstTokens := p.firstTokens.seq q.firstTokens } @[inline] def andthen (p q : Parser) : Parser := { info := andthenInfo p.info q.info, fn := andthenFn p.fn q.fn } instance : AndThen Parser where andThen a b := andthen a (b ()) @[inline] def nodeFn (n : SyntaxNodeKind) (p : ParserFn) : ParserFn := fun c s => let iniSz := s.stackSize let s := p c s s.mkNode n iniSz @[inline] def trailingNodeFn (n : SyntaxNodeKind) (p : ParserFn) : ParserFn := fun c s => let iniSz := s.stackSize let s := p c s s.mkTrailingNode n iniSz @[noinline] def nodeInfo (n : SyntaxNodeKind) (p : ParserInfo) : ParserInfo := { collectTokens := p.collectTokens, collectKinds := fun s => (p.collectKinds s).insert n, firstTokens := p.firstTokens } @[inline] def node (n : SyntaxNodeKind) (p : Parser) : Parser := { info := nodeInfo n p.info, fn := nodeFn n p.fn } def errorFn (msg : String) : ParserFn := fun _ s => s.mkUnexpectedError msg @[inline] def error (msg : String) : Parser := { info := epsilonInfo, fn := errorFn msg } def errorAtSavedPosFn (msg : String) (delta : Bool) : ParserFn := fun c s => match c.savedPos? with | none => s | some pos => let pos := if delta then c.input.next pos else pos match s with | ⟨stack, lhsPrec, _, cache, _⟩ => ⟨stack.push Syntax.missing, lhsPrec, pos, cache, some { unexpected := msg }⟩ /- Generate an error at the position saved with the `withPosition` combinator. If `delta == true`, then it reports at saved position+1. This useful to make sure a parser consumed at least one character. -/ @[inline] def errorAtSavedPos (msg : String) (delta : Bool) : Parser := { fn := errorAtSavedPosFn msg delta } /- Succeeds if `c.prec <= prec` -/ def checkPrecFn (prec : Nat) : ParserFn := fun c s => if c.prec <= prec then s else s.mkUnexpectedError "unexpected token at this precedence level; consider parenthesizing the term" @[inline] def checkPrec (prec : Nat) : Parser := { info := epsilonInfo, fn := checkPrecFn prec } /- Succeeds if `c.lhsPrec >= prec` -/ def checkLhsPrecFn (prec : Nat) : ParserFn := fun c s => if s.lhsPrec >= prec then s else s.mkUnexpectedError "unexpected token at this precedence level; consider parenthesizing the term" @[inline] def checkLhsPrec (prec : Nat) : Parser := { info := epsilonInfo, fn := checkLhsPrecFn prec } def setLhsPrecFn (prec : Nat) : ParserFn := fun c s => if s.hasError then s else { s with lhsPrec := prec } @[inline] def setLhsPrec (prec : Nat) : Parser := { info := epsilonInfo, fn := setLhsPrecFn prec } def checkInsideQuotFn : ParserFn := fun c s => if c.quotDepth > 0 && !c.suppressInsideQuot then s else s.mkUnexpectedError "unexpected syntax outside syntax quotation" @[inline] def checkInsideQuot : Parser := { info := epsilonInfo, fn := checkInsideQuotFn } def checkOutsideQuotFn : ParserFn := fun c s => if !c.quotDepth == 0 || c.suppressInsideQuot then s else s.mkUnexpectedError "unexpected syntax inside syntax quotation" @[inline] def checkOutsideQuot : Parser := { info := epsilonInfo, fn := checkOutsideQuotFn } def addQuotDepthFn (i : Int) (p : ParserFn) : ParserFn := fun c s => p { c with quotDepth := c.quotDepth + i |>.toNat } s @[inline] def incQuotDepth (p : Parser) : Parser := { info := p.info, fn := addQuotDepthFn 1 p.fn } @[inline] def decQuotDepth (p : Parser) : Parser := { info := p.info, fn := addQuotDepthFn (-1) p.fn } def suppressInsideQuotFn (p : ParserFn) : ParserFn := fun c s => p { c with suppressInsideQuot := true } s @[inline] def suppressInsideQuot (p : Parser) : Parser := { info := p.info, fn := suppressInsideQuotFn p.fn } @[inline] def leadingNode (n : SyntaxNodeKind) (prec : Nat) (p : Parser) : Parser := checkPrec prec >> node n p >> setLhsPrec prec @[inline] def trailingNodeAux (n : SyntaxNodeKind) (p : Parser) : TrailingParser := { info := nodeInfo n p.info, fn := trailingNodeFn n p.fn } @[inline] def trailingNode (n : SyntaxNodeKind) (prec lhsPrec : Nat) (p : Parser) : TrailingParser := checkPrec prec >> checkLhsPrec lhsPrec >> trailingNodeAux n p >> setLhsPrec prec def mergeOrElseErrors (s : ParserState) (error1 : Error) (iniPos : Nat) (mergeErrors : Bool) : ParserState := match s with | ⟨stack, lhsPrec, pos, cache, some error2⟩ => if pos == iniPos then ⟨stack, lhsPrec, pos, cache, some (if mergeErrors then error1.merge error2 else error2)⟩ else s | other => other def orelseFnCore (p q : ParserFn) (mergeErrors : Bool) : ParserFn := fun c s => let iniSz := s.stackSize let iniPos := s.pos let s := p c s match s.errorMsg with | some errorMsg => if s.pos == iniPos then mergeOrElseErrors (q c (s.restore iniSz iniPos)) errorMsg iniPos mergeErrors else s | none => s @[inline] def orelseFn (p q : ParserFn) : ParserFn := orelseFnCore p q true @[noinline] def orelseInfo (p q : ParserInfo) : ParserInfo := { collectTokens := p.collectTokens ∘ q.collectTokens, collectKinds := p.collectKinds ∘ q.collectKinds, firstTokens := p.firstTokens.merge q.firstTokens } /-- Run `p`, falling back to `q` if `p` failed without consuming any input. NOTE: In order for the pretty printer to retrace an `orelse`, `p` must be a call to `node` or some other parser producing a single node kind. Nested `orelse` calls are flattened for this, i.e. `(node k1 p1 <|> node k2 p2) <|> ...` is fine as well. -/ @[inline] def orelse (p q : Parser) : Parser := { info := orelseInfo p.info q.info, fn := orelseFn p.fn q.fn } instance : OrElse Parser where orElse a b := orelse a (b ()) @[noinline] def noFirstTokenInfo (info : ParserInfo) : ParserInfo := { collectTokens := info.collectTokens, collectKinds := info.collectKinds } def atomicFn (p : ParserFn) : ParserFn := fun c s => let iniPos := s.pos match p c s with | ⟨stack, lhsPrec, _, cache, some msg⟩ => ⟨stack, lhsPrec, iniPos, cache, some msg⟩ | other => other @[inline] def atomic (p : Parser) : Parser := { info := p.info, fn := atomicFn p.fn } def optionalFn (p : ParserFn) : ParserFn := fun c s => let iniSz := s.stackSize let iniPos := s.pos let s := p c s let s := if s.hasError && s.pos == iniPos then s.restore iniSz iniPos else s s.mkNode nullKind iniSz @[noinline] def optionaInfo (p : ParserInfo) : ParserInfo := { collectTokens := p.collectTokens, collectKinds := p.collectKinds, firstTokens := p.firstTokens.toOptional } @[inline] def optionalNoAntiquot (p : Parser) : Parser := { info := optionaInfo p.info, fn := optionalFn p.fn } def lookaheadFn (p : ParserFn) : ParserFn := fun c s => let iniSz := s.stackSize let iniPos := s.pos let s := p c s if s.hasError then s else s.restore iniSz iniPos @[inline] def lookahead (p : Parser) : Parser := { info := p.info, fn := lookaheadFn p.fn } def notFollowedByFn (p : ParserFn) (msg : String) : ParserFn := fun c s => let iniSz := s.stackSize let iniPos := s.pos let s := p c s if s.hasError then s.restore iniSz iniPos else let s := s.restore iniSz iniPos s.mkUnexpectedError s!"unexpected {msg}" @[inline] def notFollowedBy (p : Parser) (msg : String) : Parser := { fn := notFollowedByFn p.fn msg } partial def manyAux (p : ParserFn) : ParserFn := fun c s => do let iniSz := s.stackSize let iniPos := s.pos let mut s := p c s if s.hasError then return if iniPos == s.pos then s.restore iniSz iniPos else s if iniPos == s.pos then return s.mkUnexpectedError "invalid 'many' parser combinator application, parser did not consume anything" if s.stackSize > iniSz + 1 then s := s.mkNode nullKind iniSz manyAux p c s @[inline] def manyFn (p : ParserFn) : ParserFn := fun c s => let iniSz := s.stackSize let s := manyAux p c s s.mkNode nullKind iniSz @[inline] def manyNoAntiquot (p : Parser) : Parser := { info := noFirstTokenInfo p.info, fn := manyFn p.fn } @[inline] def many1Fn (p : ParserFn) : ParserFn := fun c s => let iniSz := s.stackSize let s := andthenFn p (manyAux p) c s s.mkNode nullKind iniSz @[inline] def many1NoAntiquot (p : Parser) : Parser := { info := p.info, fn := many1Fn p.fn } private partial def sepByFnAux (p : ParserFn) (sep : ParserFn) (allowTrailingSep : Bool) (iniSz : Nat) (pOpt : Bool) : ParserFn := let rec parse (pOpt : Bool) (c s) := do let sz := s.stackSize let pos := s.pos let mut s := p c s if s.hasError then if s.pos > pos then return s.mkNode nullKind iniSz else if pOpt then s := s.restore sz pos return s.mkNode nullKind iniSz else -- append `Syntax.missing` to make clear that List is incomplete s := s.pushSyntax Syntax.missing return s.mkNode nullKind iniSz if s.stackSize > sz + 1 then s := s.mkNode nullKind sz let sz := s.stackSize let pos := s.pos s := sep c s if s.hasError then s := s.restore sz pos return s.mkNode nullKind iniSz if s.stackSize > sz + 1 then s := s.mkNode nullKind sz parse allowTrailingSep c s parse pOpt def sepByFn (allowTrailingSep : Bool) (p : ParserFn) (sep : ParserFn) : ParserFn := fun c s => let iniSz := s.stackSize sepByFnAux p sep allowTrailingSep iniSz true c s def sepBy1Fn (allowTrailingSep : Bool) (p : ParserFn) (sep : ParserFn) : ParserFn := fun c s => let iniSz := s.stackSize sepByFnAux p sep allowTrailingSep iniSz false c s @[noinline] def sepByInfo (p sep : ParserInfo) : ParserInfo := { collectTokens := p.collectTokens ∘ sep.collectTokens, collectKinds := p.collectKinds ∘ sep.collectKinds } @[noinline] def sepBy1Info (p sep : ParserInfo) : ParserInfo := { collectTokens := p.collectTokens ∘ sep.collectTokens, collectKinds := p.collectKinds ∘ sep.collectKinds, firstTokens := p.firstTokens } @[inline] def sepByNoAntiquot (p sep : Parser) (allowTrailingSep : Bool := false) : Parser := { info := sepByInfo p.info sep.info, fn := sepByFn allowTrailingSep p.fn sep.fn } @[inline] def sepBy1NoAntiquot (p sep : Parser) (allowTrailingSep : Bool := false) : Parser := { info := sepBy1Info p.info sep.info, fn := sepBy1Fn allowTrailingSep p.fn sep.fn } /- Apply `f` to the syntax object produced by `p` -/ def withResultOfFn (p : ParserFn) (f : Syntax → Syntax) : ParserFn := fun c s => let s := p c s if s.hasError then s else let stx := s.stxStack.back s.popSyntax.pushSyntax (f stx) @[noinline] def withResultOfInfo (p : ParserInfo) : ParserInfo := { collectTokens := p.collectTokens, collectKinds := p.collectKinds } @[inline] def withResultOf (p : Parser) (f : Syntax → Syntax) : Parser := { info := withResultOfInfo p.info, fn := withResultOfFn p.fn f } @[inline] def many1Unbox (p : Parser) : Parser := withResultOf (many1NoAntiquot p) fun stx => if stx.getNumArgs == 1 then stx.getArg 0 else stx partial def satisfyFn (p : Char → Bool) (errorMsg : String := "unexpected character") : ParserFn := fun c s => let i := s.pos if c.input.atEnd i then s.mkEOIError else if p (c.input.get i) then s.next c.input i else s.mkUnexpectedError errorMsg partial def takeUntilFn (p : Char → Bool) : ParserFn := fun c s => let i := s.pos if c.input.atEnd i then s else if p (c.input.get i) then s else takeUntilFn p c (s.next c.input i) def takeWhileFn (p : Char → Bool) : ParserFn := takeUntilFn (fun c => !p c) @[inline] def takeWhile1Fn (p : Char → Bool) (errorMsg : String) : ParserFn := andthenFn (satisfyFn p errorMsg) (takeWhileFn p) partial def finishCommentBlock (nesting : Nat) : ParserFn := fun c s => let input := c.input let i := s.pos if input.atEnd i then eoi s else let curr := input.get i let i := input.next i if curr == '-' then if input.atEnd i then eoi s else let curr := input.get i if curr == '/' then -- "-/" end of comment if nesting == 1 then s.next input i else finishCommentBlock (nesting-1) c (s.next input i) else finishCommentBlock nesting c (s.next input i) else if curr == '/' then if input.atEnd i then eoi s else let curr := input.get i if curr == '-' then finishCommentBlock (nesting+1) c (s.next input i) else finishCommentBlock nesting c (s.setPos i) else finishCommentBlock nesting c (s.setPos i) where eoi s := s.mkUnexpectedError "unterminated comment" /- Consume whitespace and comments -/ partial def whitespace : ParserFn := fun c s => let input := c.input let i := s.pos if input.atEnd i then s else let curr := input.get i if curr == '\t' then s.mkUnexpectedError "tabs are not allowed; please configure your editor to expand them" else if curr.isWhitespace then whitespace c (s.next input i) else if curr == '-' then let i := input.next i let curr := input.get i if curr == '-' then andthenFn (takeUntilFn (fun c => c = '\n')) whitespace c (s.next input i) else s else if curr == '/' then let startPos := i let i := input.next i let curr := input.get i if curr == '-' then let i := input.next i let curr := input.get i if curr == '-' || curr == '!' then s -- "/--" and "/-!" doc comment are actual tokens else andthenFn (finishCommentBlock 1) whitespace c (s.next input i) else s else s def mkEmptySubstringAt (s : String) (p : Nat) : Substring := { str := s, startPos := p, stopPos := p } private def rawAux (startPos : Nat) (trailingWs : Bool) : ParserFn := fun c s => let input := c.input let stopPos := s.pos let leading := mkEmptySubstringAt input startPos let val := input.extract startPos stopPos if trailingWs then let s := whitespace c s let stopPos' := s.pos let trailing := { str := input, startPos := stopPos, stopPos := stopPos' : Substring } let atom := mkAtom (SourceInfo.original leading startPos trailing (startPos + val.bsize)) val s.pushSyntax atom else let trailing := mkEmptySubstringAt input stopPos let atom := mkAtom (SourceInfo.original leading startPos trailing (startPos + val.bsize)) val s.pushSyntax atom /-- Match an arbitrary Parser and return the consumed String in a `Syntax.atom`. -/ @[inline] def rawFn (p : ParserFn) (trailingWs := false) : ParserFn := fun c s => let startPos := s.pos let s := p c s if s.hasError then s else rawAux startPos trailingWs c s @[inline] def chFn (c : Char) (trailingWs := false) : ParserFn := rawFn (satisfyFn (fun d => c == d) ("'" ++ toString c ++ "'")) trailingWs def rawCh (c : Char) (trailingWs := false) : Parser := { fn := chFn c trailingWs } def hexDigitFn : ParserFn := fun c s => let input := c.input let i := s.pos if input.atEnd i then s.mkEOIError else let curr := input.get i let i := input.next i if curr.isDigit || ('a' <= curr && curr <= 'f') || ('A' <= curr && curr <= 'F') then s.setPos i else s.mkUnexpectedError "invalid hexadecimal numeral" def quotedCharCoreFn (isQuotable : Char → Bool) : ParserFn := fun c s => let input := c.input let i := s.pos if input.atEnd i then s.mkEOIError else let curr := input.get i if isQuotable curr then s.next input i else if curr == 'x' then andthenFn hexDigitFn hexDigitFn c (s.next input i) else if curr == 'u' then andthenFn hexDigitFn (andthenFn hexDigitFn (andthenFn hexDigitFn hexDigitFn)) c (s.next input i) else s.mkUnexpectedError "invalid escape sequence" def isQuotableCharDefault (c : Char) : Bool := c == '\\' || c == '\"' || c == '\'' || c == 'r' || c == 'n' || c == 't' def quotedCharFn : ParserFn := quotedCharCoreFn isQuotableCharDefault /-- Push `(Syntax.node tk <new-atom>)` into syntax stack -/ def mkNodeToken (n : SyntaxNodeKind) (startPos : Nat) : ParserFn := fun c s => let input := c.input let stopPos := s.pos let leading := mkEmptySubstringAt input startPos let val := input.extract startPos stopPos let s := whitespace c s let wsStopPos := s.pos let trailing := { str := input, startPos := stopPos, stopPos := wsStopPos : Substring } let info := SourceInfo.original leading startPos trailing stopPos s.pushSyntax (Syntax.mkLit n val info) def charLitFnAux (startPos : Nat) : ParserFn := fun c s => let input := c.input let i := s.pos if input.atEnd i then s.mkEOIError else let curr := input.get i let s := s.setPos (input.next i) let s := if curr == '\\' then quotedCharFn c s else s if s.hasError then s else let i := s.pos let curr := input.get i let s := s.setPos (input.next i) if curr == '\'' then mkNodeToken charLitKind startPos c s else s.mkUnexpectedError "missing end of character literal" partial def strLitFnAux (startPos : Nat) : ParserFn := fun c s => let input := c.input let i := s.pos if input.atEnd i then s.mkUnexpectedErrorAt "unterminated string literal" startPos else let curr := input.get i let s := s.setPos (input.next i) if curr == '\"' then mkNodeToken strLitKind startPos c s else if curr == '\\' then andthenFn quotedCharFn (strLitFnAux startPos) c s else strLitFnAux startPos c s def decimalNumberFn (startPos : Nat) (c : ParserContext) : ParserState → ParserState := fun s => let s := takeWhileFn (fun c => c.isDigit) c s let input := c.input let i := s.pos let curr := input.get i if curr == '.' || curr == 'e' || curr == 'E' then let s := parseOptDot s let s := parseOptExp s mkNodeToken scientificLitKind startPos c s else mkNodeToken numLitKind startPos c s where parseOptDot s := let input := c.input let i := s.pos let curr := input.get i if curr == '.' then let i := input.next i let curr := input.get i if curr.isDigit then takeWhileFn (fun c => c.isDigit) c (s.setPos i) else s.setPos i else s parseOptExp s := let input := c.input let i := s.pos let curr := input.get i if curr == 'e' || curr == 'E' then let i := input.next i let i := if input.get i == '-' then input.next i else i let curr := input.get i if curr.isDigit then takeWhileFn (fun c => c.isDigit) c (s.setPos i) else s.setPos i else s def binNumberFn (startPos : Nat) : ParserFn := fun c s => let s := takeWhile1Fn (fun c => c == '0' || c == '1') "binary number" c s mkNodeToken numLitKind startPos c s def octalNumberFn (startPos : Nat) : ParserFn := fun c s => let s := takeWhile1Fn (fun c => '0' ≤ c && c ≤ '7') "octal number" c s mkNodeToken numLitKind startPos c s def hexNumberFn (startPos : Nat) : ParserFn := fun c s => let s := takeWhile1Fn (fun c => ('0' ≤ c && c ≤ '9') || ('a' ≤ c && c ≤ 'f') || ('A' ≤ c && c ≤ 'F')) "hexadecimal number" c s mkNodeToken numLitKind startPos c s def numberFnAux : ParserFn := fun c s => let input := c.input let startPos := s.pos if input.atEnd startPos then s.mkEOIError else let curr := input.get startPos if curr == '0' then let i := input.next startPos let curr := input.get i if curr == 'b' || curr == 'B' then binNumberFn startPos c (s.next input i) else if curr == 'o' || curr == 'O' then octalNumberFn startPos c (s.next input i) else if curr == 'x' || curr == 'X' then hexNumberFn startPos c (s.next input i) else decimalNumberFn startPos c (s.setPos i) else if curr.isDigit then decimalNumberFn startPos c (s.next input startPos) else s.mkError "numeral" def isIdCont : String → ParserState → Bool := fun input s => let i := s.pos let curr := input.get i if curr == '.' then let i := input.next i if input.atEnd i then false else let curr := input.get i isIdFirst curr || isIdBeginEscape curr else false private def isToken (idStartPos idStopPos : Nat) (tk : Option Token) : Bool := match tk with | none => false | some tk => -- if a token is both a symbol and a valid identifier (i.e. a keyword), -- we want it to be recognized as a symbol tk.bsize ≥ idStopPos - idStartPos def mkTokenAndFixPos (startPos : Nat) (tk : Option Token) : ParserFn := fun c s => match tk with | none => s.mkErrorAt "token" startPos | some tk => if c.forbiddenTk? == some tk then s.mkErrorAt "forbidden token" startPos else let input := c.input let leading := mkEmptySubstringAt input startPos let stopPos := startPos + tk.bsize let s := s.setPos stopPos let s := whitespace c s let wsStopPos := s.pos let trailing := { str := input, startPos := stopPos, stopPos := wsStopPos : Substring } let atom := mkAtom (SourceInfo.original leading startPos trailing stopPos) tk s.pushSyntax atom def mkIdResult (startPos : Nat) (tk : Option Token) (val : Name) : ParserFn := fun c s => let stopPos := s.pos if isToken startPos stopPos tk then mkTokenAndFixPos startPos tk c s else let input := c.input let rawVal := { str := input, startPos := startPos, stopPos := stopPos : Substring } let s := whitespace c s let trailingStopPos := s.pos let leading := mkEmptySubstringAt input startPos let trailing := { str := input, startPos := stopPos, stopPos := trailingStopPos : Substring } let info := SourceInfo.original leading startPos trailing stopPos let atom := mkIdent info rawVal val s.pushSyntax atom partial def identFnAux (startPos : Nat) (tk : Option Token) (r : Name) : ParserFn := let rec parse (r : Name) (c s) := do let input := c.input let i := s.pos if input.atEnd i then return s.mkEOIError let curr := input.get i if isIdBeginEscape curr then let startPart := input.next i let s := takeUntilFn isIdEndEscape c (s.setPos startPart) if input.atEnd s.pos then return s.mkUnexpectedErrorAt "unterminated identifier escape" startPart let stopPart := s.pos let s := s.next c.input s.pos let r := Name.mkStr r (input.extract startPart stopPart) if isIdCont input s then let s := s.next input s.pos parse r c s else mkIdResult startPos tk r c s else if isIdFirst curr then let startPart := i let s := takeWhileFn isIdRest c (s.next input i) let stopPart := s.pos let r := Name.mkStr r (input.extract startPart stopPart) if isIdCont input s then let s := s.next input s.pos parse r c s else mkIdResult startPos tk r c s else mkTokenAndFixPos startPos tk c s parse r private def isIdFirstOrBeginEscape (c : Char) : Bool := isIdFirst c || isIdBeginEscape c private def nameLitAux (startPos : Nat) : ParserFn := fun c s => let input := c.input let s := identFnAux startPos none Name.anonymous c (s.next input startPos) if s.hasError then s else let stx := s.stxStack.back match stx with | Syntax.ident info rawStr _ _ => let s := s.popSyntax s.pushSyntax (Syntax.mkNameLit rawStr.toString info) | _ => s.mkError "invalid Name literal" private def tokenFnAux : ParserFn := fun c s => let input := c.input let i := s.pos let curr := input.get i if curr == '\"' then strLitFnAux i c (s.next input i) else if curr == '\'' then charLitFnAux i c (s.next input i) else if curr.isDigit then numberFnAux c s else if curr == '`' && isIdFirstOrBeginEscape (getNext input i) then nameLitAux i c s else let (_, tk) := c.tokens.matchPrefix input i identFnAux i tk Name.anonymous c s private def updateCache (startPos : Nat) (s : ParserState) : ParserState := -- do not cache token parsing errors, which are rare and usually fatal and thus not worth an extra field in `TokenCache` match s with | ⟨stack, lhsPrec, pos, cache, none⟩ => if stack.size == 0 then s else let tk := stack.back ⟨stack, lhsPrec, pos, { tokenCache := { startPos := startPos, stopPos := pos, token := tk } }, none⟩ | other => other def tokenFn (expected : List String := []) : ParserFn := fun c s => let input := c.input let i := s.pos if input.atEnd i then s.mkEOIError expected else let tkc := s.cache.tokenCache if tkc.startPos == i then let s := s.pushSyntax tkc.token s.setPos tkc.stopPos else let s := tokenFnAux c s updateCache i s def peekTokenAux (c : ParserContext) (s : ParserState) : ParserState × Except ParserState Syntax := let iniSz := s.stackSize let iniPos := s.pos let s := tokenFn [] c s if let some e := s.errorMsg then (s.restore iniSz iniPos, Except.error s) else let stx := s.stxStack.back (s.restore iniSz iniPos, Except.ok stx) def peekToken (c : ParserContext) (s : ParserState) : ParserState × Except ParserState Syntax := let tkc := s.cache.tokenCache if tkc.startPos == s.pos then (s, Except.ok tkc.token) else peekTokenAux c s /- Treat keywords as identifiers. -/ def rawIdentFn : ParserFn := fun c s => let input := c.input let i := s.pos if input.atEnd i then s.mkEOIError else identFnAux i none Name.anonymous c s @[inline] def satisfySymbolFn (p : String → Bool) (expected : List String) : ParserFn := fun c s => let initStackSz := s.stackSize let startPos := s.pos let s := tokenFn expected c s if s.hasError then s else match s.stxStack.back with | Syntax.atom _ sym => if p sym then s else s.mkErrorsAt expected startPos initStackSz | _ => s.mkErrorsAt expected startPos initStackSz def symbolFnAux (sym : String) (errorMsg : String) : ParserFn := satisfySymbolFn (fun s => s == sym) [errorMsg] def symbolInfo (sym : String) : ParserInfo := { collectTokens := fun tks => sym :: tks, firstTokens := FirstTokens.tokens [ sym ] } @[inline] def symbolFn (sym : String) : ParserFn := symbolFnAux sym ("'" ++ sym ++ "'") @[inline] def symbolNoAntiquot (sym : String) : Parser := let sym := sym.trim { info := symbolInfo sym, fn := symbolFn sym } def checkTailNoWs (prev : Syntax) : Bool := match prev.getTailInfo with | SourceInfo.original _ _ trailing _ => trailing.stopPos == trailing.startPos | _ => false /-- Check if the following token is the symbol _or_ identifier `sym`. Useful for parsing local tokens that have not been added to the token table (but may have been so by some unrelated code). For example, the universe `max` Function is parsed using this combinator so that it can still be used as an identifier outside of universe (but registering it as a token in a Term Syntax would not break the universe Parser). -/ def nonReservedSymbolFnAux (sym : String) (errorMsg : String) : ParserFn := fun c s => let initStackSz := s.stackSize let startPos := s.pos let s := tokenFn [errorMsg] c s if s.hasError then s else match s.stxStack.back with | Syntax.atom _ sym' => if sym == sym' then s else s.mkErrorAt errorMsg startPos initStackSz | Syntax.ident info rawVal _ _ => if sym == rawVal.toString then let s := s.popSyntax s.pushSyntax (Syntax.atom info sym) else s.mkErrorAt errorMsg startPos initStackSz | _ => s.mkErrorAt errorMsg startPos initStackSz @[inline] def nonReservedSymbolFn (sym : String) : ParserFn := nonReservedSymbolFnAux sym ("'" ++ sym ++ "'") def nonReservedSymbolInfo (sym : String) (includeIdent : Bool) : ParserInfo := { firstTokens := if includeIdent then FirstTokens.tokens [ sym, "ident" ] else FirstTokens.tokens [ sym ] } @[inline] def nonReservedSymbolNoAntiquot (sym : String) (includeIdent := false) : Parser := let sym := sym.trim { info := nonReservedSymbolInfo sym includeIdent, fn := nonReservedSymbolFn sym } partial def strAux (sym : String) (errorMsg : String) (j : Nat) :ParserFn := let rec parse (j c s) := if sym.atEnd j then s else let i := s.pos let input := c.input if input.atEnd i || sym.get j != input.get i then s.mkError errorMsg else parse (sym.next j) c (s.next input i) parse j def checkTailWs (prev : Syntax) : Bool := match prev.getTailInfo with | SourceInfo.original _ _ trailing _ => trailing.stopPos > trailing.startPos | _ => false def checkWsBeforeFn (errorMsg : String) : ParserFn := fun c s => let prev := s.stxStack.back if checkTailWs prev then s else s.mkError errorMsg def checkWsBefore (errorMsg : String := "space before") : Parser := { info := epsilonInfo, fn := checkWsBeforeFn errorMsg } def checkTailLinebreak (prev : Syntax) : Bool := match prev.getTailInfo with | SourceInfo.original _ _ trailing _ => trailing.contains '\n' | _ => false def checkLinebreakBeforeFn (errorMsg : String) : ParserFn := fun c s => let prev := s.stxStack.back if checkTailLinebreak prev then s else s.mkError errorMsg def checkLinebreakBefore (errorMsg : String := "line break") : Parser := { info := epsilonInfo fn := checkLinebreakBeforeFn errorMsg } private def pickNonNone (stack : Array Syntax) : Syntax := match stack.findRev? $ fun stx => !stx.isNone with | none => Syntax.missing | some stx => stx def checkNoWsBeforeFn (errorMsg : String) : ParserFn := fun c s => let prev := pickNonNone s.stxStack if checkTailNoWs prev then s else s.mkError errorMsg def checkNoWsBefore (errorMsg : String := "no space before") : Parser := { info := epsilonInfo, fn := checkNoWsBeforeFn errorMsg } def unicodeSymbolFnAux (sym asciiSym : String) (expected : List String) : ParserFn := satisfySymbolFn (fun s => s == sym || s == asciiSym) expected def unicodeSymbolInfo (sym asciiSym : String) : ParserInfo := { collectTokens := fun tks => sym :: asciiSym :: tks, firstTokens := FirstTokens.tokens [ sym, asciiSym ] } @[inline] def unicodeSymbolFn (sym asciiSym : String) : ParserFn := unicodeSymbolFnAux sym asciiSym ["'" ++ sym ++ "', '" ++ asciiSym ++ "'"] @[inline] def unicodeSymbolNoAntiquot (sym asciiSym : String) : Parser := let sym := sym.trim let asciiSym := asciiSym.trim { info := unicodeSymbolInfo sym asciiSym, fn := unicodeSymbolFn sym asciiSym } def mkAtomicInfo (k : String) : ParserInfo := { firstTokens := FirstTokens.tokens [ k ] } def numLitFn : ParserFn := fun c s => let initStackSz := s.stackSize let iniPos := s.pos let s := tokenFn ["numeral"] c s if !s.hasError && !(s.stxStack.back.isOfKind numLitKind) then s.mkErrorAt "numeral" iniPos initStackSz else s @[inline] def numLitNoAntiquot : Parser := { fn := numLitFn, info := mkAtomicInfo "numLit" } def scientificLitFn : ParserFn := fun c s => let initStackSz := s.stackSize let iniPos := s.pos let s := tokenFn ["scientific number"] c s if !s.hasError && !(s.stxStack.back.isOfKind scientificLitKind) then s.mkErrorAt "scientific number" iniPos initStackSz else s @[inline] def scientificLitNoAntiquot : Parser := { fn := scientificLitFn, info := mkAtomicInfo "scientificLit" } def strLitFn : ParserFn := fun c s => let initStackSz := s.stackSize let iniPos := s.pos let s := tokenFn ["string literal"] c s if !s.hasError && !(s.stxStack.back.isOfKind strLitKind) then s.mkErrorAt "string literal" iniPos initStackSz else s @[inline] def strLitNoAntiquot : Parser := { fn := strLitFn, info := mkAtomicInfo "strLit" } def charLitFn : ParserFn := fun c s => let initStackSz := s.stackSize let iniPos := s.pos let s := tokenFn ["char literal"] c s if !s.hasError && !(s.stxStack.back.isOfKind charLitKind) then s.mkErrorAt "character literal" iniPos initStackSz else s @[inline] def charLitNoAntiquot : Parser := { fn := charLitFn, info := mkAtomicInfo "charLit" } def nameLitFn : ParserFn := fun c s => let initStackSz := s.stackSize let iniPos := s.pos let s := tokenFn ["Name literal"] c s if !s.hasError && !(s.stxStack.back.isOfKind nameLitKind) then s.mkErrorAt "Name literal" iniPos initStackSz else s @[inline] def nameLitNoAntiquot : Parser := { fn := nameLitFn, info := mkAtomicInfo "nameLit" } def identFn : ParserFn := fun c s => let initStackSz := s.stackSize let iniPos := s.pos let s := tokenFn ["identifier"] c s if !s.hasError && !(s.stxStack.back.isIdent) then s.mkErrorAt "identifier" iniPos initStackSz else s @[inline] def identNoAntiquot : Parser := { fn := identFn, info := mkAtomicInfo "ident" } @[inline] def rawIdentNoAntiquot : Parser := { fn := rawIdentFn } def identEqFn (id : Name) : ParserFn := fun c s => let initStackSz := s.stackSize let iniPos := s.pos let s := tokenFn ["identifier"] c s if s.hasError then s else match s.stxStack.back with | Syntax.ident _ _ val _ => if val != id then s.mkErrorAt ("expected identifier '" ++ toString id ++ "'") iniPos initStackSz else s | _ => s.mkErrorAt "identifier" iniPos initStackSz @[inline] def identEq (id : Name) : Parser := { fn := identEqFn id, info := mkAtomicInfo "ident" } namespace ParserState def keepTop (s : Array Syntax) (startStackSize : Nat) : Array Syntax := let node := s.back s.shrink startStackSize |>.push node def keepNewError (s : ParserState) (oldStackSize : Nat) : ParserState := match s with | ⟨stack, lhsPrec, pos, cache, err⟩ => ⟨keepTop stack oldStackSize, lhsPrec, pos, cache, err⟩ def keepPrevError (s : ParserState) (oldStackSize : Nat) (oldStopPos : String.Pos) (oldError : Option Error) : ParserState := match s with | ⟨stack, lhsPrec, _, cache, _⟩ => ⟨stack.shrink oldStackSize, lhsPrec, oldStopPos, cache, oldError⟩ def mergeErrors (s : ParserState) (oldStackSize : Nat) (oldError : Error) : ParserState := match s with | ⟨stack, lhsPrec, pos, cache, some err⟩ => if oldError == err then s else ⟨stack.shrink oldStackSize, lhsPrec, pos, cache, some (oldError.merge err)⟩ | other => other def keepLatest (s : ParserState) (startStackSize : Nat) : ParserState := match s with | ⟨stack, lhsPrec, pos, cache, _⟩ => ⟨keepTop stack startStackSize, lhsPrec, pos, cache, none⟩ def replaceLongest (s : ParserState) (startStackSize : Nat) : ParserState := s.keepLatest startStackSize end ParserState def invalidLongestMatchParser (s : ParserState) : ParserState := s.mkError "longestMatch parsers must generate exactly one Syntax node" /-- Auxiliary function used to execute parsers provided to `longestMatchFn`. Push `left?` into the stack if it is not `none`, and execute `p`. Remark: `p` must produce exactly one syntax node. Remark: the `left?` is not none when we are processing trailing parsers. -/ def runLongestMatchParser (left? : Option Syntax) (startLhsPrec : Nat) (p : ParserFn) : ParserFn := fun c s => do /- We assume any registered parser `p` has one of two forms: * a direct call to `leadingParser` or `trailingParser` * a direct call to a (leading) token parser In the first case, we can extract the precedence of the parser by having `leadingParser/trailingParser` set `ParserState.lhsPrec` to it in the very end so that no nested parser can interfere. In the second case, the precedence is effectively `max` (there is a `checkPrec` merely for the convenience of the pretty printer) and there are no nested `leadingParser/trailingParser` calls, so the value of `lhsPrec` will not be changed by the parser (nor will it be read by any leading parser). Thus we initialize the field to `maxPrec` in the leading case. -/ let mut s := { s with lhsPrec := if left?.isSome then startLhsPrec else maxPrec } let startSize := s.stackSize if let some left := left? then s := s.pushSyntax left s := p c s -- stack contains `[..., result ]` if s.stackSize == startSize + 1 then s -- success or error with the expected number of nodes else if s.hasError then -- error with an unexpected number of nodes. s.shrinkStack startSize |>.pushSyntax Syntax.missing else -- parser succeded with incorrect number of nodes invalidLongestMatchParser s def longestMatchStep (left? : Option Syntax) (startSize startLhsPrec : Nat) (startPos : String.Pos) (prevPrio : Nat) (prio : Nat) (p : ParserFn) : ParserContext → ParserState → ParserState × Nat := fun c s => let prevErrorMsg := s.errorMsg let prevStopPos := s.pos let prevSize := s.stackSize let prevLhsPrec := s.lhsPrec let s := s.restore prevSize startPos let s := runLongestMatchParser left? startLhsPrec p c s match prevErrorMsg, s.errorMsg with | none, none => -- both succeeded if s.pos > prevStopPos || (s.pos == prevStopPos && prio > prevPrio) then (s.replaceLongest startSize, prio) else if s.pos < prevStopPos || (s.pos == prevStopPos && prio < prevPrio) then ({ s.restore prevSize prevStopPos with lhsPrec := prevLhsPrec }, prevPrio) -- keep prev -- it is not clear what the precedence of a choice node should be, so we conservatively take the minimum else ({s with lhsPrec := s.lhsPrec.min prevLhsPrec }, prio) | none, some _ => -- prev succeeded, current failed ({ s.restore prevSize prevStopPos with lhsPrec := prevLhsPrec }, prevPrio) | some oldError, some _ => -- both failed if s.pos > prevStopPos || (s.pos == prevStopPos && prio > prevPrio) then (s.keepNewError startSize, prio) else if s.pos < prevStopPos || (s.pos == prevStopPos && prio < prevPrio) then (s.keepPrevError prevSize prevStopPos prevErrorMsg, prevPrio) else (s.mergeErrors prevSize oldError, prio) | some _, none => -- prev failed, current succeeded let successNode := s.stxStack.back let s := s.shrinkStack startSize -- restore stack to initial size to make sure (failure) nodes are removed from the stack (s.pushSyntax successNode, prio) -- put successNode back on the stack def longestMatchMkResult (startSize : Nat) (s : ParserState) : ParserState := if !s.hasError && s.stackSize > startSize + 1 then s.mkNode choiceKind startSize else s def longestMatchFnAux (left? : Option Syntax) (startSize startLhsPrec : Nat) (startPos : String.Pos) (prevPrio : Nat) (ps : List (Parser × Nat)) : ParserFn := let rec parse (prevPrio : Nat) (ps : List (Parser × Nat)) := match ps with | [] => fun _ s => longestMatchMkResult startSize s | p::ps => fun c s => let (s, prevPrio) := longestMatchStep left? startSize startLhsPrec startPos prevPrio p.2 p.1.fn c s parse prevPrio ps c s parse prevPrio ps def longestMatchFn (left? : Option Syntax) : List (Parser × Nat) → ParserFn | [] => fun _ s => s.mkError "longestMatch: empty list" | [p] => fun c s => runLongestMatchParser left? s.lhsPrec p.1.fn c s | p::ps => fun c s => let startSize := s.stackSize let startLhsPrec := s.lhsPrec let startPos := s.pos let s := runLongestMatchParser left? s.lhsPrec p.1.fn c s longestMatchFnAux left? startSize startLhsPrec startPos p.2 ps c s def anyOfFn : List Parser → ParserFn | [], _, s => s.mkError "anyOf: empty list" | [p], c, s => p.fn c s | p::ps, c, s => orelseFn p.fn (anyOfFn ps) c s @[inline] def checkColGeFn (errorMsg : String) : ParserFn := fun c s => match c.savedPos? with | none => s | some savedPos => let savedPos := c.fileMap.toPosition savedPos let pos := c.fileMap.toPosition s.pos if pos.column ≥ savedPos.column then s else s.mkError errorMsg @[inline] def checkColGe (errorMsg : String := "checkColGe") : Parser := { fn := checkColGeFn errorMsg } @[inline] def checkColGtFn (errorMsg : String) : ParserFn := fun c s => match c.savedPos? with | none => s | some savedPos => let savedPos := c.fileMap.toPosition savedPos let pos := c.fileMap.toPosition s.pos if pos.column > savedPos.column then s else s.mkError errorMsg @[inline] def checkColGt (errorMsg : String := "checkColGt") : Parser := { fn := checkColGtFn errorMsg } @[inline] def checkLineEqFn (errorMsg : String) : ParserFn := fun c s => match c.savedPos? with | none => s | some savedPos => let savedPos := c.fileMap.toPosition savedPos let pos := c.fileMap.toPosition s.pos if pos.line == savedPos.line then s else s.mkError errorMsg @[inline] def checkLineEq (errorMsg : String := "checkLineEq") : Parser := { fn := checkLineEqFn errorMsg } @[inline] def withPosition (p : Parser) : Parser := { info := p.info, fn := fun c s => p.fn { c with savedPos? := s.pos } s } @[inline] def withoutPosition (p : Parser) : Parser := { info := p.info, fn := fun c s => let pos := c.fileMap.toPosition s.pos p.fn { c with savedPos? := none } s } @[inline] def withForbidden (tk : Token) (p : Parser) : Parser := { info := p.info, fn := fun c s => p.fn { c with forbiddenTk? := tk } s } @[inline] def withoutForbidden (p : Parser) : Parser := { info := p.info, fn := fun c s => p.fn { c with forbiddenTk? := none } s } def eoiFn : ParserFn := fun c s => let i := s.pos if c.input.atEnd i then s else s.mkError "expected end of file" @[inline] def eoi : Parser := { fn := eoiFn } open Std (RBMap RBMap.empty) /-- A multimap indexed by tokens. Used for indexing parsers by their leading token. -/ def TokenMap (α : Type) := RBMap Name (List α) Name.quickCmp namespace TokenMap def insert (map : TokenMap α) (k : Name) (v : α) : TokenMap α := match map.find? k with | none => Std.RBMap.insert map k [v] | some vs => Std.RBMap.insert map k (v::vs) instance : Inhabited (TokenMap α) := ⟨RBMap.empty⟩ instance : EmptyCollection (TokenMap α) := ⟨RBMap.empty⟩ end TokenMap structure PrattParsingTables where leadingTable : TokenMap (Parser × Nat) := {} leadingParsers : List (Parser × Nat) := [] -- for supporting parsers we cannot obtain first token trailingTable : TokenMap (Parser × Nat) := {} trailingParsers : List (Parser × Nat) := [] -- for supporting parsers such as function application instance : Inhabited PrattParsingTables := ⟨{}⟩ /- The type `leadingIdentBehavior` specifies how the parsing table lookup function behaves for identifiers. The function `prattParser` uses two tables `leadingTable` and `trailingTable`. They map tokens to parsers. - `LeadingIdentBehavior.default`: if the leading token is an identifier, then `prattParser` just executes the parsers associated with the auxiliary token "ident". - `LeadingIdentBehavior.symbol`: if the leading token is an identifier `<foo>`, and there are parsers `P` associated with the toek `<foo>`, then it executes `P`. Otherwise, it executes only the parsers associated with the auxiliary token "ident". - `LeadingIdentBehavior.both`: if the leading token an identifier `<foo>`, the it executes the parsers associated with token `<foo>` and parsers associated with the auxiliary token "ident". We use `LeadingIdentBehavior.symbol` and `LeadingIdentBehavior.both` and `nonReservedSymbol` parser to implement the `tactic` parsers. The idea is to avoid creating a reserved symbol for each builtin tactic (e.g., `apply`, `assumption`, etc.). That is, users may still use these symbols as identifiers (e.g., naming a function). -/ inductive LeadingIdentBehavior where | default | symbol | both deriving Inhabited, BEq, Repr /-- Each parser category is implemented using a Pratt's parser. The system comes equipped with the following categories: `level`, `term`, `tactic`, and `command`. Users and plugins may define extra categories. The method ``` categoryParser `term prec ``` executes the Pratt's parser for category `term` with precedence `prec`. That is, only parsers with precedence at least `prec` are considered. The method `termParser prec` is equivalent to the method above. -/ structure ParserCategory where tables : PrattParsingTables behavior : LeadingIdentBehavior deriving Inhabited abbrev ParserCategories := Std.PersistentHashMap Name ParserCategory def indexed {α : Type} (map : TokenMap α) (c : ParserContext) (s : ParserState) (behavior : LeadingIdentBehavior) : ParserState × List α := let (s, stx) := peekToken c s let find (n : Name) : ParserState × List α := match map.find? n with | some as => (s, as) | _ => (s, []) match stx with | Except.ok (Syntax.atom _ sym) => find (Name.mkSimple sym) | Except.ok (Syntax.ident _ _ val _) => match behavior with | LeadingIdentBehavior.default => find identKind | LeadingIdentBehavior.symbol => match map.find? val with | some as => (s, as) | none => find identKind | LeadingIdentBehavior.both => match map.find? val with | some as => match map.find? identKind with | some as' => (s, as ++ as') | _ => (s, as) | none => find identKind | Except.ok (Syntax.node _ k _) => find k | Except.ok _ => (s, []) | Except.error s' => (s', []) abbrev CategoryParserFn := Name → ParserFn builtin_initialize categoryParserFnRef : IO.Ref CategoryParserFn ← IO.mkRef fun _ => whitespace builtin_initialize categoryParserFnExtension : EnvExtension CategoryParserFn ← registerEnvExtension $ categoryParserFnRef.get def categoryParserFn (catName : Name) : ParserFn := fun ctx s => categoryParserFnExtension.getState ctx.env catName ctx s def categoryParser (catName : Name) (prec : Nat) : Parser := { fn := fun c s => categoryParserFn catName { c with prec := prec } s } -- Define `termParser` here because we need it for antiquotations @[inline] def termParser (prec : Nat := 0) : Parser := categoryParser `term prec /- ============== -/ /- Antiquotations -/ /- ============== -/ /-- Fail if previous token is immediately followed by ':'. -/ def checkNoImmediateColon : Parser := { fn := fun c s => let prev := s.stxStack.back if checkTailNoWs prev then let input := c.input let i := s.pos if input.atEnd i then s else let curr := input.get i if curr == ':' then s.mkUnexpectedError "unexpected ':'" else s else s } def setExpectedFn (expected : List String) (p : ParserFn) : ParserFn := fun c s => match p c s with | s'@{ errorMsg := some msg, .. } => { s' with errorMsg := some { msg with expected := [] } } | s' => s' def setExpected (expected : List String) (p : Parser) : Parser := { fn := setExpectedFn expected p.fn, info := p.info } def pushNone : Parser := { fn := fun c s => s.pushSyntax mkNullNode } -- We support two kinds of antiquotations: `$id` and `$(t)`, where `id` is a term identifier and `t` is a term. def antiquotNestedExpr : Parser := node `antiquotNestedExpr (symbolNoAntiquot "(" >> decQuotDepth termParser >> symbolNoAntiquot ")") def antiquotExpr : Parser := identNoAntiquot <|> antiquotNestedExpr @[inline] def tokenWithAntiquotFn (p : ParserFn) : ParserFn := fun c s => do let s := p c s if s.hasError || c.quotDepth == 0 then return s let iniSz := s.stackSize let iniPos := s.pos let s := (checkNoWsBefore >> symbolNoAntiquot "%" >> symbolNoAntiquot "$" >> checkNoWsBefore >> antiquotExpr).fn c s if s.hasError then return s.restore iniSz iniPos s.mkNode (`token_antiquot) (iniSz - 1) @[inline] def tokenWithAntiquot (p : Parser) : Parser where fn := tokenWithAntiquotFn p.fn info := p.info @[inline] def symbol (sym : String) : Parser := tokenWithAntiquot (symbolNoAntiquot sym) instance : Coe String Parser := ⟨fun s => symbol s ⟩ @[inline] def nonReservedSymbol (sym : String) (includeIdent := false) : Parser := tokenWithAntiquot (nonReservedSymbolNoAntiquot sym includeIdent) @[inline] def unicodeSymbol (sym asciiSym : String) : Parser := tokenWithAntiquot (unicodeSymbolNoAntiquot sym asciiSym) /-- Define parser for `$e` (if anonymous == true) and `$e:name`. Both forms can also be used with an appended `*` to turn them into an antiquotation "splice". If `kind` is given, it will additionally be checked when evaluating `match_syntax`. Antiquotations can be escaped as in `$$e`, which produces the syntax tree for `$e`. -/ def mkAntiquot (name : String) (kind : Option SyntaxNodeKind) (anonymous := true) : Parser := let kind := (kind.getD Name.anonymous) ++ `antiquot let nameP := node `antiquotName $ checkNoWsBefore ("no space before ':" ++ name ++ "'") >> symbol ":" >> nonReservedSymbol name -- if parsing the kind fails and `anonymous` is true, check that we're not ignoring a different -- antiquotation kind via `noImmediateColon` let nameP := if anonymous then nameP <|> checkNoImmediateColon >> pushNone else nameP -- antiquotations are not part of the "standard" syntax, so hide "expected '$'" on error leadingNode kind maxPrec $ atomic $ setExpected [] "$" >> manyNoAntiquot (checkNoWsBefore "" >> "$") >> checkNoWsBefore "no space before spliced term" >> antiquotExpr >> nameP def tryAnti (c : ParserContext) (s : ParserState) : Bool := do if c.quotDepth == 0 then return false let (s, stx) := peekToken c s match stx with | Except.ok stx@(Syntax.atom _ sym) => sym == "$" | _ => false @[inline] def withAntiquotFn (antiquotP p : ParserFn) : ParserFn := fun c s => if tryAnti c s then orelseFn antiquotP p c s else p c s /-- Optimized version of `mkAntiquot ... <|> p`. -/ @[inline] def withAntiquot (antiquotP p : Parser) : Parser := { fn := withAntiquotFn antiquotP.fn p.fn, info := orelseInfo antiquotP.info p.info } def withoutInfo (p : Parser) : Parser := { fn := p.fn } /-- Parse `$[p]suffix`, e.g. `$[p],*`. -/ def mkAntiquotSplice (kind : SyntaxNodeKind) (p suffix : Parser) : Parser := let kind := kind ++ `antiquot_scope leadingNode kind maxPrec $ atomic $ setExpected [] "$" >> manyNoAntiquot (checkNoWsBefore "" >> "$") >> checkNoWsBefore "no space before spliced term" >> symbol "[" >> node nullKind p >> symbol "]" >> suffix @[inline] def withAntiquotSuffixSpliceFn (kind : SyntaxNodeKind) (p suffix : ParserFn) : ParserFn := fun c s => do let s := p c s if s.hasError || c.quotDepth == 0 || !s.stxStack.back.isAntiquot then return s let iniSz := s.stackSize let iniPos := s.pos let s := suffix c s if s.hasError then return s.restore iniSz iniPos s.mkNode (kind ++ `antiquot_suffix_splice) (s.stxStack.size - 2) /-- Parse `suffix` after an antiquotation, e.g. `$x,*`, and put both into a new node. -/ @[inline] def withAntiquotSuffixSplice (kind : SyntaxNodeKind) (p suffix : Parser) : Parser := { info := andthenInfo p.info suffix.info, fn := withAntiquotSuffixSpliceFn kind p.fn suffix.fn } def withAntiquotSpliceAndSuffix (kind : SyntaxNodeKind) (p suffix : Parser) := -- prevent `p`'s info from being collected twice withAntiquot (mkAntiquotSplice kind (withoutInfo p) suffix) (withAntiquotSuffixSplice kind p suffix) def nodeWithAntiquot (name : String) (kind : SyntaxNodeKind) (p : Parser) (anonymous := false) : Parser := withAntiquot (mkAntiquot name kind anonymous) $ node kind p /- ===================== -/ /- End of Antiquotations -/ /- ===================== -/ def sepByElemParser (p : Parser) (sep : String) : Parser := withAntiquotSpliceAndSuffix `sepBy p (symbol (sep.trim ++ "*")) def sepBy (p : Parser) (sep : String) (psep : Parser := symbol sep) (allowTrailingSep : Bool := false) : Parser := sepByNoAntiquot (sepByElemParser p sep) psep allowTrailingSep def sepBy1 (p : Parser) (sep : String) (psep : Parser := symbol sep) (allowTrailingSep : Bool := false) : Parser := sepBy1NoAntiquot (sepByElemParser p sep) psep allowTrailingSep def categoryParserOfStackFn (offset : Nat) : ParserFn := fun ctx s => let stack := s.stxStack if stack.size < offset + 1 then s.mkUnexpectedError ("failed to determine parser category using syntax stack, stack is too small") else match stack.get! (stack.size - offset - 1) with | Syntax.ident _ _ catName _ => categoryParserFn catName ctx s | _ => s.mkUnexpectedError ("failed to determine parser category using syntax stack, the specified element on the stack is not an identifier") def categoryParserOfStack (offset : Nat) (prec : Nat := 0) : Parser := { fn := fun c s => categoryParserOfStackFn offset { c with prec := prec } s } unsafe def evalParserConstUnsafe (declName : Name) : ParserFn := fun ctx s => match ctx.env.evalConstCheck Parser ctx.options `Lean.Parser.Parser declName <|> ctx.env.evalConstCheck Parser ctx.options `Lean.Parser.TrailingParser declName with | Except.ok p => p.fn ctx s | Except.error e => s.mkUnexpectedError s!"error running parser {declName}: {e}" @[implementedBy evalParserConstUnsafe] constant evalParserConst (declName : Name) : ParserFn unsafe def parserOfStackFnUnsafe (offset : Nat) : ParserFn := fun ctx s => let stack := s.stxStack if stack.size < offset + 1 then s.mkUnexpectedError ("failed to determine parser using syntax stack, stack is too small") else match stack.get! (stack.size - offset - 1) with | Syntax.ident (val := parserName) .. => match ctx.resolveName parserName with | [(parserName, [])] => let iniSz := s.stackSize let s := evalParserConst parserName ctx s if !s.hasError && s.stackSize != iniSz + 1 then s.mkUnexpectedError "expected parser to return exactly one syntax object" else s | _::_::_ => s.mkUnexpectedError s!"ambiguous parser name {parserName}" | _ => s.mkUnexpectedError s!"unknown parser {parserName}" | _ => s.mkUnexpectedError ("failed to determine parser using syntax stack, the specified element on the stack is not an identifier") @[implementedBy parserOfStackFnUnsafe] constant parserOfStackFn (offset : Nat) : ParserFn def parserOfStack (offset : Nat) (prec : Nat := 0) : Parser := { fn := fun c s => parserOfStackFn offset { c with prec := prec } s } register_builtin_option internal.parseQuotWithCurrentStage : Bool := { defValue := false group := "internal" descr := "(Lean bootstrapping) use parsers from the current stage inside quotations" } /-- Run `declName` if possible and inside a quotation, or else `p`. The `ParserInfo` will always be taken from `p`. -/ def evalInsideQuot (declName : Name) (p : Parser) : Parser := { p with fn := fun c s => if c.quotDepth > 0 && !c.suppressInsideQuot && internal.parseQuotWithCurrentStage.get c.options && c.env.contains declName then evalParserConst declName c s else p.fn c s } private def mkResult (s : ParserState) (iniSz : Nat) : ParserState := if s.stackSize == iniSz + 1 then s else s.mkNode nullKind iniSz -- throw error instead? def leadingParserAux (kind : Name) (tables : PrattParsingTables) (behavior : LeadingIdentBehavior) : ParserFn := fun c s => do let iniSz := s.stackSize let (s, ps) := indexed tables.leadingTable c s behavior if s.hasError then return s let ps := tables.leadingParsers ++ ps if ps.isEmpty then return s.mkError (toString kind) let s := longestMatchFn none ps c s mkResult s iniSz @[inline] def leadingParser (kind : Name) (tables : PrattParsingTables) (behavior : LeadingIdentBehavior) (antiquotParser : ParserFn) : ParserFn := withAntiquotFn antiquotParser (leadingParserAux kind tables behavior) def trailingLoopStep (tables : PrattParsingTables) (left : Syntax) (ps : List (Parser × Nat)) : ParserFn := fun c s => longestMatchFn left (ps ++ tables.trailingParsers) c s partial def trailingLoop (tables : PrattParsingTables) (c : ParserContext) (s : ParserState) : ParserState := do let iniSz := s.stackSize let iniPos := s.pos let (s, ps) := indexed tables.trailingTable c s LeadingIdentBehavior.default if s.hasError then -- Discard token parse errors and break the trailing loop instead. -- The error will be flagged when the next leading position is parsed, unless the token -- is in fact valid there (e.g. EOI at command level, no-longer forbidden token) return s.restore iniSz iniPos if ps.isEmpty && tables.trailingParsers.isEmpty then return s -- no available trailing parser let left := s.stxStack.back let s := s.popSyntax let s := trailingLoopStep tables left ps c s if s.hasError then -- Discard non-consuming parse errors and break the trailing loop instead, restoring `left`. -- This is necessary for fallback parsers like `app` that pretend to be always applicable. return if s.pos == iniPos then s.restore (iniSz - 1) iniPos |>.pushSyntax left else s trailingLoop tables c s /-- Implements a variant of Pratt's algorithm. In Pratt's algorithms tokens have a right and left binding power. In our implementation, parsers have precedence instead. This method selects a parser (or more, via `longestMatchFn`) from `leadingTable` based on the current token. Note that the unindexed `leadingParsers` parsers are also tried. We have the unidexed `leadingParsers` because some parsers do not have a "first token". Example: ``` syntax term:51 "≤" ident "<" term "|" term : index ``` Example, in principle, the set of first tokens for this parser is any token that can start a term, but this set is always changing. Thus, this parsing rule is stored as an unindexed leading parser at `leadingParsers`. After processing the leading parser, we chain with parsers from `trailingTable`/`trailingParsers` that have precedence at least `c.prec` where `c` is the `ParsingContext`. Recall that `c.prec` is set by `categoryParser`. Note that in the original Pratt's algorith, precedences are only checked before calling trailing parsers. In our implementation, leading *and* trailing parsers check the precendece. We claim our algorithm is more flexible, modular and easier to understand. `antiquotParser` should be a `mkAntiquot` parser (or always fail) and is tried before all other parsers. It should not be added to the regular leading parsers because it would heavily overlap with antiquotation parsers nested inside them. -/ @[inline] def prattParser (kind : Name) (tables : PrattParsingTables) (behavior : LeadingIdentBehavior) (antiquotParser : ParserFn) : ParserFn := fun c s => let iniSz := s.stackSize let iniPos := s.pos let s := leadingParser kind tables behavior antiquotParser c s if s.hasError then s else trailingLoop tables c s def fieldIdxFn : ParserFn := fun c s => let initStackSz := s.stackSize let iniPos := s.pos let curr := c.input.get iniPos if curr.isDigit && curr != '0' then let s := takeWhileFn (fun c => c.isDigit) c s mkNodeToken fieldIdxKind iniPos c s else s.mkErrorAt "field index" iniPos initStackSz @[inline] def fieldIdx : Parser := withAntiquot (mkAntiquot "fieldIdx" `fieldIdx) { fn := fieldIdxFn, info := mkAtomicInfo "fieldIdx" } @[inline] def skip : Parser := { fn := fun c s => s, info := epsilonInfo } end Parser namespace Syntax section variable {β : Type} {m : Type → Type} [Monad m] @[inline] def foldArgsM (s : Syntax) (f : Syntax → β → m β) (b : β) : m β := s.getArgs.foldlM (flip f) b @[inline] def foldArgs (s : Syntax) (f : Syntax → β → β) (b : β) : β := Id.run (s.foldArgsM f b) @[inline] def forArgsM (s : Syntax) (f : Syntax → m Unit) : m Unit := s.foldArgsM (fun s _ => f s) () end end Syntax end Lean
8e881b9f782828c893bcfa492e1055e758cdbf95
80cc5bf14c8ea85ff340d1d747a127dcadeb966f
/src/number_theory/pell.lean
efe6f1d0fa7265bd66a5911a17b31180105dd063
[ "Apache-2.0" ]
permissive
lacker/mathlib
f2439c743c4f8eb413ec589430c82d0f73b2d539
ddf7563ac69d42cfa4a1bfe41db1fed521bd795f
refs/heads/master
1,671,948,326,773
1,601,479,268,000
1,601,479,268,000
298,686,743
0
0
Apache-2.0
1,601,070,794,000
1,601,070,794,000
null
UTF-8
Lean
false
false
37,103
lean
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import data.nat.modeq import data.zsqrtd.basic import tactic.omega namespace pell open nat section parameters {a : ℕ} (a1 : 1 < a) include a1 private def d := a*a - 1 @[simp] theorem d_pos : 0 < d := nat.sub_pos_of_lt (mul_lt_mul a1 (le_of_lt a1) dec_trivial dec_trivial : 1*1<a*a) /-- The Pell sequences, defined together in mutual recursion. -/ -- TODO(lint): Fix double namespace issue @[nolint dup_namespace] def pell : ℕ → ℕ × ℕ := λn, nat.rec_on n (1, 0) (λn xy, (xy.1*a + d*xy.2, xy.1 + xy.2*a)) /-- The Pell `x` sequence. -/ def xn (n : ℕ) : ℕ := (pell n).1 /-- The Pell `y` sequence. -/ def yn (n : ℕ) : ℕ := (pell n).2 @[simp] theorem pell_val (n : ℕ) : pell n = (xn n, yn n) := show pell n = ((pell n).1, (pell n).2), from match pell n with (a, b) := rfl end @[simp] theorem xn_zero : xn 0 = 1 := rfl @[simp] theorem yn_zero : yn 0 = 0 := rfl @[simp] theorem xn_succ (n : ℕ) : xn (n+1) = xn n * a + d * yn n := rfl @[simp] theorem yn_succ (n : ℕ) : yn (n+1) = xn n + yn n * a := rfl @[simp] theorem xn_one : xn 1 = a := by simp @[simp] theorem yn_one : yn 1 = 1 := by simp def xz (n : ℕ) : ℤ := xn n def yz (n : ℕ) : ℤ := yn n def az : ℤ := a theorem asq_pos : 0 < a*a := le_trans (le_of_lt a1) (by have := @nat.mul_le_mul_left 1 a a (le_of_lt a1); rwa mul_one at this) theorem dz_val : ↑d = az*az - 1 := have 1 ≤ a*a, from asq_pos, show ↑(a*a - 1) = _, by rw int.coe_nat_sub this; refl @[simp] theorem xz_succ (n : ℕ) : xz (n+1) = xz n * az + ↑d * yz n := rfl @[simp] theorem yz_succ (n : ℕ) : yz (n+1) = xz n + yz n * az := rfl /-- The Pell sequence can also be viewed as an element of `ℤ√d` -/ def pell_zd (n : ℕ) : ℤ√d := ⟨xn n, yn n⟩ @[simp] theorem pell_zd_re (n : ℕ) : (pell_zd n).re = xn n := rfl @[simp] theorem pell_zd_im (n : ℕ) : (pell_zd n).im = yn n := rfl /-- The property of being a solution to the Pell equation, expressed as a property of elements of `ℤ√d`. -/ def is_pell : ℤ√d → Prop | ⟨x, y⟩ := x*x - d*y*y = 1 theorem is_pell_nat {x y : ℕ} : is_pell ⟨x, y⟩ ↔ x*x - d*y*y = 1 := ⟨λh, int.coe_nat_inj (by rw int.coe_nat_sub (int.le_of_coe_nat_le_coe_nat $ int.le.intro_sub h); exact h), λh, show ((x*x : ℕ) - (d*y*y:ℕ) : ℤ) = 1, by rw [← int.coe_nat_sub $ le_of_lt $ nat.lt_of_sub_eq_succ h, h]; refl⟩ theorem is_pell_norm : Π {b : ℤ√d}, is_pell b ↔ b * b.conj = 1 | ⟨x, y⟩ := by simp [zsqrtd.ext, is_pell, mul_comm]; ring theorem is_pell_mul {b c : ℤ√d} (hb : is_pell b) (hc : is_pell c) : is_pell (b * c) := is_pell_norm.2 (by simp [mul_comm, mul_left_comm, zsqrtd.conj_mul, pell.is_pell_norm.1 hb, pell.is_pell_norm.1 hc]) theorem is_pell_conj : ∀ {b : ℤ√d}, is_pell b ↔ is_pell b.conj | ⟨x, y⟩ := by simp [is_pell, zsqrtd.conj] @[simp] theorem pell_zd_succ (n : ℕ) : pell_zd (n+1) = pell_zd n * ⟨a, 1⟩ := by simp [zsqrtd.ext] theorem is_pell_one : is_pell ⟨a, 1⟩ := show az*az-d*1*1=1, by simp [dz_val]; ring theorem is_pell_pell_zd : ∀ (n : ℕ), is_pell (pell_zd n) | 0 := rfl | (n+1) := let o := is_pell_one in by simp; exact pell.is_pell_mul (is_pell_pell_zd n) o @[simp] theorem pell_eqz (n : ℕ) : xz n * xz n - d * yz n * yz n = 1 := is_pell_pell_zd n @[simp] theorem pell_eq (n : ℕ) : xn n * xn n - d * yn n * yn n = 1 := let pn := pell_eqz n in have h : (↑(xn n * xn n) : ℤ) - ↑(d * yn n * yn n) = 1, by repeat {rw int.coe_nat_mul}; exact pn, have hl : d * yn n * yn n ≤ xn n * xn n, from int.le_of_coe_nat_le_coe_nat $ int.le.intro $ add_eq_of_eq_sub' $ eq.symm h, int.coe_nat_inj (by rw int.coe_nat_sub hl; exact h) instance dnsq : zsqrtd.nonsquare d := ⟨λn h, have n*n + 1 = a*a, by rw ← h; exact nat.succ_pred_eq_of_pos (asq_pos a1), have na : n < a, from nat.mul_self_lt_mul_self_iff.2 (by rw ← this; exact nat.lt_succ_self _), have (n+1)*(n+1) ≤ n*n + 1, by rw this; exact nat.mul_self_le_mul_self na, have n+n ≤ 0, from @nat.le_of_add_le_add_right (n*n + 1) _ _ (by ring at this ⊢; assumption), ne_of_gt d_pos $ by rw nat.eq_zero_of_le_zero (le_trans (nat.le_add_left _ _) this) at h; exact h⟩ theorem xn_ge_a_pow : ∀ (n : ℕ), a^n ≤ xn n | 0 := le_refl 1 | (n+1) := by simp [pow_succ']; exact le_trans (nat.mul_le_mul_right _ (xn_ge_a_pow n)) (nat.le_add_right _ _) theorem n_lt_a_pow : ∀ (n : ℕ), n < a^n | 0 := nat.le_refl 1 | (n+1) := begin have IH := n_lt_a_pow n, have : a^n + a^n ≤ a^n * a, { rw ← mul_two, exact nat.mul_le_mul_left _ a1 }, simp [pow_succ'], refine lt_of_lt_of_le _ this, exact add_lt_add_of_lt_of_le IH (lt_of_le_of_lt (nat.zero_le _) IH) end theorem n_lt_xn (n) : n < xn n := lt_of_lt_of_le (n_lt_a_pow n) (xn_ge_a_pow n) theorem x_pos (n) : 0 < xn n := lt_of_le_of_lt (nat.zero_le n) (n_lt_xn n) lemma eq_pell_lem : ∀n (b:ℤ√d), 1 ≤ b → is_pell b → b ≤ pell_zd n → ∃n, b = pell_zd n | 0 b := λh1 hp hl, ⟨0, @zsqrtd.le_antisymm _ dnsq _ _ hl h1⟩ | (n+1) b := λh1 hp h, have a1p : (0:ℤ√d) ≤ ⟨a, 1⟩, from trivial, have am1p : (0:ℤ√d) ≤ ⟨a, -1⟩, from show (_:nat) ≤ _, by simp; exact nat.pred_le _, have a1m : (⟨a, 1⟩ * ⟨a, -1⟩ : ℤ√d) = 1, from is_pell_norm.1 is_pell_one, if ha : (⟨↑a, 1⟩ : ℤ√d) ≤ b then let ⟨m, e⟩ := eq_pell_lem n (b * ⟨a, -1⟩) (by rw ← a1m; exact mul_le_mul_of_nonneg_right ha am1p) (is_pell_mul hp (is_pell_conj.1 is_pell_one)) (by have t := mul_le_mul_of_nonneg_right h am1p; rwa [pell_zd_succ, mul_assoc, a1m, mul_one] at t) in ⟨m+1, by rw [show b = b * ⟨a, -1⟩ * ⟨a, 1⟩, by rw [mul_assoc, eq.trans (mul_comm _ _) a1m]; simp, pell_zd_succ, e]⟩ else suffices ¬1 < b, from ⟨0, show b = 1, from (or.resolve_left (lt_or_eq_of_le h1) this).symm⟩, λh1l, by cases b with x y; exact have bm : (_*⟨_,_⟩ :ℤ√(d a1)) = 1, from pell.is_pell_norm.1 hp, have y0l : (0:ℤ√(d a1)) < ⟨x - x, y - -y⟩, from sub_lt_sub h1l $ λ(hn : (1:ℤ√(d a1)) ≤ ⟨x, -y⟩), by have t := mul_le_mul_of_nonneg_left hn (le_trans zero_le_one h1); rw [bm, mul_one] at t; exact h1l t, have yl2 : (⟨_, _⟩ : ℤ√_) < ⟨_, _⟩, from show (⟨x, y⟩ - ⟨x, -y⟩ : ℤ√(d a1)) < ⟨a, 1⟩ - ⟨a, -1⟩, from sub_lt_sub (by exact ha) $ λ(hn : (⟨x, -y⟩ : ℤ√(d a1)) ≤ ⟨a, -1⟩), by have t := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hn (le_trans zero_le_one h1)) a1p; rw [bm, one_mul, mul_assoc, eq.trans (mul_comm _ _) a1m, mul_one] at t; exact ha t, by simp at y0l; simp at yl2; exact match y, y0l, (yl2 : (⟨_, _⟩ : ℤ√_) < ⟨_, _⟩) with | 0, y0l, yl2 := y0l (le_refl 0) | (y+1 : ℕ), y0l, yl2 := yl2 (zsqrtd.le_of_le_le (le_refl 0) (let t := int.coe_nat_le_coe_nat_of_le (nat.succ_pos y) in add_le_add t t)) | -[1+y], y0l, yl2 := y0l trivial end theorem eq_pell_zd (b : ℤ√d) (b1 : 1 ≤ b) (hp : is_pell b) : ∃n, b = pell_zd n := let ⟨n, h⟩ := @zsqrtd.le_arch d b in eq_pell_lem n b b1 hp $ zsqrtd.le_trans h $ by rw zsqrtd.coe_nat_val; exact zsqrtd.le_of_le_le (int.coe_nat_le_coe_nat_of_le $ le_of_lt $ n_lt_xn _ _) (int.coe_zero_le _) theorem eq_pell {x y : ℕ} (hp : x*x - d*y*y = 1) : ∃n, x = xn n ∧ y = yn n := have (1:ℤ√d) ≤ ⟨x, y⟩, from match x, hp with | 0, (hp : 0 - _ = 1) := by rw nat.zero_sub at hp; contradiction | (x+1), hp := zsqrtd.le_of_le_le (int.coe_nat_le_coe_nat_of_le $ nat.succ_pos x) (int.coe_zero_le _) end, let ⟨m, e⟩ := eq_pell_zd ⟨x, y⟩ this (is_pell_nat.2 hp) in ⟨m, match x, y, e with ._, ._, rfl := ⟨rfl, rfl⟩ end⟩ theorem pell_zd_add (m) : ∀ n, pell_zd (m + n) = pell_zd m * pell_zd n | 0 := (mul_one _).symm | (n+1) := by rw[← add_assoc, pell_zd_succ, pell_zd_succ, pell_zd_add n, ← mul_assoc] theorem xn_add (m n) : xn (m + n) = xn m * xn n + d * yn m * yn n := by injection (pell_zd_add _ m n) with h _; repeat {rw ← int.coe_nat_add at h <|> rw ← int.coe_nat_mul at h}; exact int.coe_nat_inj h theorem yn_add (m n) : yn (m + n) = xn m * yn n + yn m * xn n := by injection (pell_zd_add _ m n) with _ h; repeat {rw ← int.coe_nat_add at h <|> rw ← int.coe_nat_mul at h}; exact int.coe_nat_inj h theorem pell_zd_sub {m n} (h : n ≤ m) : pell_zd (m - n) = pell_zd m * (pell_zd n).conj := let t := pell_zd_add n (m - n) in by rw [nat.add_sub_of_le h] at t; rw [t, mul_comm (pell_zd _ n) _, mul_assoc, (is_pell_norm _).1 (is_pell_pell_zd _ _), mul_one] theorem xz_sub {m n} (h : n ≤ m) : xz (m - n) = xz m * xz n - d * yz m * yz n := by injection (pell_zd_sub _ h) with h _; repeat {rw ← neg_mul_eq_mul_neg at h}; exact h theorem yz_sub {m n} (h : n ≤ m) : yz (m - n) = xz n * yz m - xz m * yz n := by injection (pell_zd_sub a1 h) with _ h; repeat {rw ← neg_mul_eq_mul_neg at h}; rw [add_comm, mul_comm] at h; exact h theorem xy_coprime (n) : (xn n).coprime (yn n) := nat.coprime_of_dvd' $ λk kx ky, let p := pell_eq n in by rw ← p; exact nat.dvd_sub (le_of_lt $ nat.lt_of_sub_eq_succ p) (dvd_mul_of_dvd_right kx _) (dvd_mul_of_dvd_right ky _) theorem y_increasing {m} : Π {n}, m < n → yn m < yn n | 0 h := absurd h $ nat.not_lt_zero _ | (n+1) h := have yn m ≤ yn n, from or.elim (lt_or_eq_of_le $ nat.le_of_succ_le_succ h) (λhl, le_of_lt $ y_increasing hl) (λe, by rw e), by simp; refine lt_of_le_of_lt _ (nat.lt_add_of_pos_left $ x_pos a1 n); rw ← mul_one (yn a1 m); exact mul_le_mul this (le_of_lt a1) (nat.zero_le _) (nat.zero_le _) theorem x_increasing {m} : Π {n}, m < n → xn m < xn n | 0 h := absurd h $ nat.not_lt_zero _ | (n+1) h := have xn m ≤ xn n, from or.elim (lt_or_eq_of_le $ nat.le_of_succ_le_succ h) (λhl, le_of_lt $ x_increasing hl) (λe, by rw e), by simp; refine lt_of_lt_of_le (lt_of_le_of_lt this _) (nat.le_add_right _ _); have t := nat.mul_lt_mul_of_pos_left a1 (x_pos a1 n); rwa mul_one at t theorem yn_ge_n : Π n, n ≤ yn n | 0 := nat.zero_le _ | (n+1) := show n < yn (n+1), from lt_of_le_of_lt (yn_ge_n n) (y_increasing $ nat.lt_succ_self n) theorem y_mul_dvd (n) : ∀k, yn n ∣ yn (n * k) | 0 := dvd_zero _ | (k+1) := by rw [nat.mul_succ, yn_add]; exact dvd_add (dvd_mul_left _ _) (dvd_mul_of_dvd_left (y_mul_dvd k) _) theorem y_dvd_iff (m n) : yn m ∣ yn n ↔ m ∣ n := ⟨λh, nat.dvd_of_mod_eq_zero $ (nat.eq_zero_or_pos _).resolve_right $ λhp, have co : nat.coprime (yn m) (xn (m * (n / m))), from nat.coprime.symm $ (xy_coprime _).coprime_dvd_right (y_mul_dvd m (n / m)), have m0 : 0 < m, from m.eq_zero_or_pos.resolve_left $ λe, by rw [e, nat.mod_zero] at hp; rw [e] at h; exact have 0 < yn a1 n, from y_increasing _ hp, ne_of_lt (y_increasing a1 hp) (eq_zero_of_zero_dvd h).symm, by rw [← nat.mod_add_div n m, yn_add] at h; exact not_le_of_gt (y_increasing _ $ nat.mod_lt n m0) (nat.le_of_dvd (y_increasing _ hp) $ co.dvd_of_dvd_mul_right $ (nat.dvd_add_iff_right $ dvd_mul_of_dvd_right (y_mul_dvd _ _ _) _).2 h), λ⟨k, e⟩, by rw e; apply y_mul_dvd⟩ theorem xy_modeq_yn (n) : ∀k, xn (n * k) ≡ (xn n)^k [MOD (yn n)^2] ∧ yn (n * k) ≡ k * (xn n)^(k-1) * yn n [MOD (yn n)^3] | 0 := by constructor; simp | (k+1) := let ⟨hx, hy⟩ := xy_modeq_yn k in have L : xn (n * k) * xn n + d * yn (n * k) * yn n ≡ xn n^k * xn n + 0 [MOD yn n^2], from modeq.modeq_add (modeq.modeq_mul_right _ hx) $ modeq.modeq_zero_iff.2 $ by rw pow_succ'; exact mul_dvd_mul_right (dvd_mul_of_dvd_right (modeq.modeq_zero_iff.1 $ (hy.modeq_of_dvd_of_modeq $ by simp [pow_succ']).trans $ modeq.modeq_zero_iff.2 $ by simp [-mul_comm, -mul_assoc]) _) _, have R : xn (n * k) * yn n + yn (n * k) * xn n ≡ xn n^k * yn n + k * xn n^k * yn n [MOD yn n^3], from modeq.modeq_add (by rw pow_succ'; exact modeq.modeq_mul_right' _ hx) $ have k * xn n^(k - 1) * yn n * xn n = k * xn n^k * yn n, by clear _let_match; cases k with k; simp [pow_succ', mul_comm, mul_left_comm], by rw ← this; exact modeq.modeq_mul_right _ hy, by rw [nat.add_sub_cancel, nat.mul_succ, xn_add, yn_add, pow_succ' (xn _ n), nat.succ_mul, add_comm (k * xn _ n^k) (xn _ n^k), right_distrib]; exact ⟨L, R⟩ theorem ysq_dvd_yy (n) : yn n * yn n ∣ yn (n * yn n) := modeq.modeq_zero_iff.1 $ ((xy_modeq_yn n (yn n)).right.modeq_of_dvd_of_modeq $ by simp [pow_succ]).trans (modeq.modeq_zero_iff.2 $ by simp [mul_dvd_mul_left, mul_assoc]) theorem dvd_of_ysq_dvd {n t} (h : yn n * yn n ∣ yn t) : yn n ∣ t := have nt : n ∣ t, from (y_dvd_iff n t).1 $ dvd_of_mul_left_dvd h, n.eq_zero_or_pos.elim (λn0, by rw n0; rw n0 at nt; exact nt) $ λ(n0l : 0 < n), let ⟨k, ke⟩ := nt in have yn n ∣ k * (xn n)^(k-1), from nat.dvd_of_mul_dvd_mul_right (y_increasing n0l) $ modeq.modeq_zero_iff.1 $ by have xm := (xy_modeq_yn a1 n k).right; rw ← ke at xm; exact (xm.modeq_of_dvd_of_modeq $ by simp [pow_succ]).symm.trans (modeq.modeq_zero_iff.2 h), by rw ke; exact dvd_mul_of_dvd_right (((xy_coprime _ _).pow_left _).symm.dvd_of_dvd_mul_right this) _ theorem pell_zd_succ_succ (n) : pell_zd (n + 2) + pell_zd n = (2 * a : ℕ) * pell_zd (n + 1) := have (1:ℤ√d) + ⟨a, 1⟩ * ⟨a, 1⟩ = ⟨a, 1⟩ * (2 * a), by { rw zsqrtd.coe_nat_val, change (⟨_,_⟩:ℤ√(d a1))=⟨_,_⟩, rw dz_val, change az a1 with a, rw zsqrtd.ext, dsimp, split; ring }, by simpa [mul_add, mul_comm, mul_left_comm, add_comm] using congr_arg (* pell_zd a1 n) this theorem xy_succ_succ (n) : xn (n + 2) + xn n = (2 * a) * xn (n + 1) ∧ yn (n + 2) + yn n = (2 * a) * yn (n + 1) := begin have := pell_zd_succ_succ a1 n, unfold pell_zd at this, rw [← int.cast_coe_nat, zsqrtd.smul_val] at this, injection this with h₁ h₂, split; apply int.coe_nat_inj; [simpa using h₁, simpa using h₂] end theorem xn_succ_succ (n) : xn (n + 2) + xn n = (2 * a) * xn (n + 1) := (xy_succ_succ n).1 theorem yn_succ_succ (n) : yn (n + 2) + yn n = (2 * a) * yn (n + 1) := (xy_succ_succ n).2 theorem xz_succ_succ (n) : xz (n + 2) = (2 * a : ℕ) * xz (n + 1) - xz n := eq_sub_of_add_eq $ by delta xz; rw [← int.coe_nat_add, ← int.coe_nat_mul, xn_succ_succ] theorem yz_succ_succ (n) : yz (n + 2) = (2 * a : ℕ) * yz (n + 1) - yz n := eq_sub_of_add_eq $ by delta yz; rw [← int.coe_nat_add, ← int.coe_nat_mul, yn_succ_succ] theorem yn_modeq_a_sub_one : ∀ n, yn n ≡ n [MOD a-1] | 0 := by simp | 1 := by simp | (n+2) := modeq.modeq_add_cancel_right (yn_modeq_a_sub_one n) $ have 2*(n+1) = n+2+n, by ring, by rw [yn_succ_succ, ← this]; refine modeq.modeq_mul (modeq.modeq_mul_left 2 (_ : a ≡ 1 [MOD a-1])) (yn_modeq_a_sub_one (n+1)); exact (modeq.modeq_of_dvd $ by rw [int.coe_nat_sub $ le_of_lt a1]; apply dvd_refl).symm theorem yn_modeq_two : ∀ n, yn n ≡ n [MOD 2] | 0 := by simp | 1 := by simp | (n+2) := modeq.modeq_add_cancel_right (yn_modeq_two n) $ have 2*(n+1) = n+2+n, by ring, by rw [yn_succ_succ, ← this]; refine modeq.modeq_mul _ (yn_modeq_two (n+1)); exact modeq.trans (modeq.modeq_zero_iff.2 $ by simp) (modeq.modeq_zero_iff.2 $ by simp).symm lemma x_sub_y_dvd_pow_lem (y2 y1 y0 yn1 yn0 xn1 xn0 ay a2 : ℤ) : (a2 * yn1 - yn0) * ay + y2 - (a2 * xn1 - xn0) = y2 - a2 * y1 + y0 + a2 * (yn1 * ay + y1 - xn1) - (yn0 * ay + y0 - xn0) := by ring theorem x_sub_y_dvd_pow (y : ℕ) : ∀ n, (2*a*y - y*y - 1 : ℤ) ∣ yz n * (a - y) + ↑(y^n) - xz n | 0 := by simp [xz, yz, int.coe_nat_zero, int.coe_nat_one] | 1 := by simp [xz, yz, int.coe_nat_zero, int.coe_nat_one] | (n+2) := have (2*a*y - y*y - 1 : ℤ) ∣ ↑(y^(n + 2)) - ↑(2 * a) * ↑(y^(n + 1)) + ↑(y^n), from ⟨-↑(y^n), by simp [pow_succ, mul_add, int.coe_nat_mul, show ((2:ℕ):ℤ) = 2, from rfl, mul_comm, mul_left_comm]; ring ⟩, by rw [xz_succ_succ, yz_succ_succ, x_sub_y_dvd_pow_lem a1 ↑(y^(n+2)) ↑(y^(n+1)) ↑(y^n)]; exact dvd_sub (dvd_add this $ dvd_mul_of_dvd_right (x_sub_y_dvd_pow (n+1)) _) (x_sub_y_dvd_pow n) theorem xn_modeq_x2n_add_lem (n j) : xn n ∣ d * yn n * (yn n * xn j) + xn j := have h1 : d * yn n * (yn n * xn j) + xn j = (d * yn n * yn n + 1) * xn j, by simp [add_mul, mul_assoc], have h2 : d * yn n * yn n + 1 = xn n * xn n, by apply int.coe_nat_inj; repeat {rw int.coe_nat_add <|> rw int.coe_nat_mul}; exact add_eq_of_eq_sub' (eq.symm $ pell_eqz _ _), by rw h2 at h1; rw [h1, mul_assoc]; exact dvd_mul_right _ _ theorem xn_modeq_x2n_add (n j) : xn (2 * n + j) + xn j ≡ 0 [MOD xn n] := by rw [two_mul, add_assoc, xn_add, add_assoc]; exact show _ ≡ 0+0 [MOD xn a1 n], from modeq.modeq_add (modeq.modeq_zero_iff.2 $ dvd_mul_right (xn a1 n) (xn a1 (n + j))) $ by rw [yn_add, left_distrib, add_assoc]; exact show _ ≡ 0+0 [MOD xn a1 n], from modeq.modeq_add (modeq.modeq_zero_iff.2 $ dvd_mul_of_dvd_right (dvd_mul_right _ _) _) $ modeq.modeq_zero_iff.2 $ xn_modeq_x2n_add_lem _ _ _ lemma xn_modeq_x2n_sub_lem {n j} (h : j ≤ n) : xn (2 * n - j) + xn j ≡ 0 [MOD xn n] := have h1 : xz n ∣ ↑d * yz n * yz (n - j) + xz j, by rw [yz_sub _ h, mul_sub_left_distrib, sub_add_eq_add_sub]; exact dvd_sub (by delta xz; delta yz; repeat {rw ← int.coe_nat_add <|> rw ← int.coe_nat_mul}; rw mul_comm (xn a1 j) (yn a1 n); exact int.coe_nat_dvd.2 (xn_modeq_x2n_add_lem _ _ _)) (dvd_mul_of_dvd_right (dvd_mul_right _ _) _), by rw [two_mul, nat.add_sub_assoc h, xn_add, add_assoc]; exact show _ ≡ 0+0 [MOD xn a1 n], from modeq.modeq_add (modeq.modeq_zero_iff.2 $ dvd_mul_right _ _) $ modeq.modeq_zero_iff.2 $ int.coe_nat_dvd.1 $ by simpa [xz, yz] using h1 theorem xn_modeq_x2n_sub {n j} (h : j ≤ 2 * n) : xn (2 * n - j) + xn j ≡ 0 [MOD xn n] := (le_total j n).elim xn_modeq_x2n_sub_lem (λjn, have 2 * n - j + j ≤ n + j, by rw [nat.sub_add_cancel h, two_mul]; exact nat.add_le_add_left jn _, let t := xn_modeq_x2n_sub_lem (nat.le_of_add_le_add_right this) in by rwa [nat.sub_sub_self h, add_comm] at t) theorem xn_modeq_x4n_add (n j) : xn (4 * n + j) ≡ xn j [MOD xn n] := modeq.modeq_add_cancel_right (modeq.refl $ xn (2 * n + j)) $ by refine @modeq.trans _ _ 0 _ _ (by rw add_comm; exact (xn_modeq_x2n_add _ _ _).symm); rw [show 4*n = 2*n + 2*n, from right_distrib 2 2 n, add_assoc]; apply xn_modeq_x2n_add theorem xn_modeq_x4n_sub {n j} (h : j ≤ 2 * n) : xn (4 * n - j) ≡ xn j [MOD xn n] := have h' : j ≤ 2*n, from le_trans h (by rw nat.succ_mul; apply nat.le_add_left), modeq.modeq_add_cancel_right (modeq.refl $ xn (2 * n - j)) $ by refine @modeq.trans _ _ 0 _ _ (by rw add_comm; exact (xn_modeq_x2n_sub _ h).symm); rw [show 4*n = 2*n + 2*n, from right_distrib 2 2 n, nat.add_sub_assoc h']; apply xn_modeq_x2n_add theorem eq_of_xn_modeq_lem1 {i n} : Π {j}, i < j → j < n → xn i % xn n < xn j % xn n | 0 ij _ := absurd ij (nat.not_lt_zero _) | (j+1) ij jn := suffices xn j % xn n < xn (j + 1) % xn n, from (lt_or_eq_of_le (nat.le_of_succ_le_succ ij)).elim (λh, lt_trans (eq_of_xn_modeq_lem1 h (le_of_lt jn)) this) (λh, by rw h; exact this), by rw [nat.mod_eq_of_lt (x_increasing _ (nat.lt_of_succ_lt jn)), nat.mod_eq_of_lt (x_increasing _ jn)]; exact x_increasing _ (nat.lt_succ_self _) theorem eq_of_xn_modeq_lem2 {n} (h : 2 * xn n = xn (n + 1)) : a = 2 ∧ n = 0 := by rw [xn_succ, mul_comm] at h; exact have n = 0, from n.eq_zero_or_pos.resolve_right $ λnp, ne_of_lt (lt_of_le_of_lt (nat.mul_le_mul_left _ a1) (nat.lt_add_of_pos_right $ mul_pos (d_pos a1) (y_increasing a1 np))) h, by cases this; simp at h; exact ⟨h.symm, rfl⟩ theorem eq_of_xn_modeq_lem3 {i n} (npos : 0 < n) : Π {j}, i < j → j ≤ 2 * n → j ≠ n → ¬(a = 2 ∧ n = 1 ∧ i = 0 ∧ j = 2) → xn i % xn n < xn j % xn n | 0 ij _ _ _ := absurd ij (nat.not_lt_zero _) | (j+1) ij j2n jnn ntriv := have lem2 : ∀k > n, k ≤ 2*n → (↑(xn k % xn n) : ℤ) = xn n - xn (2 * n - k), from λk kn k2n, let k2nl := lt_of_add_lt_add_right $ show 2*n-k+k < n+k, by {rw nat.sub_add_cancel, rw two_mul; exact (add_lt_add_left kn n), exact k2n } in have xle : xn (2 * n - k) ≤ xn n, from le_of_lt $ x_increasing k2nl, suffices xn k % xn n = xn n - xn (2 * n - k), by rw [this, int.coe_nat_sub xle], by { rw ← nat.mod_eq_of_lt (nat.sub_lt (x_pos a1 n) (x_pos a1 (2 * n - k))), apply modeq.modeq_add_cancel_right (modeq.refl (xn a1 (2 * n - k))), rw [nat.sub_add_cancel xle], have t := xn_modeq_x2n_sub_lem a1 (le_of_lt k2nl), rw nat.sub_sub_self k2n at t, exact t.trans (modeq.modeq_zero_iff.2 $ dvd_refl _).symm }, (lt_trichotomy j n).elim (λ (jn : j < n), eq_of_xn_modeq_lem1 ij (lt_of_le_of_ne jn jnn)) $ λo, o.elim (λ (jn : j = n), by { cases jn, apply int.lt_of_coe_nat_lt_coe_nat, rw [lem2 (n+1) (nat.lt_succ_self _) j2n, show 2 * n - (n + 1) = n - 1, by rw[two_mul, ← nat.sub_sub, nat.add_sub_cancel]], refine lt_sub_left_of_add_lt (int.coe_nat_lt_coe_nat_of_lt _), cases (lt_or_eq_of_le $ nat.le_of_succ_le_succ ij) with lin ein, { rw nat.mod_eq_of_lt (x_increasing _ lin), have ll : xn a1 (n-1) + xn a1 (n-1) ≤ xn a1 n, { rw [← two_mul, mul_comm, show xn a1 n = xn a1 (n-1+1), by rw [nat.sub_add_cancel npos], xn_succ], exact le_trans (nat.mul_le_mul_left _ a1) (nat.le_add_right _ _) }, have npm : (n-1).succ = n := nat.succ_pred_eq_of_pos npos, have il : i ≤ n - 1 := by apply nat.le_of_succ_le_succ; rw npm; exact lin, cases lt_or_eq_of_le il with ill ile, { exact lt_of_lt_of_le (nat.add_lt_add_left (x_increasing a1 ill) _) ll }, { rw ile, apply lt_of_le_of_ne ll, rw ← two_mul, exact λe, ntriv $ let ⟨a2, s1⟩ := @eq_of_xn_modeq_lem2 _ a1 (n-1) (by rw[nat.sub_add_cancel npos]; exact e) in have n1 : n = 1, from le_antisymm (nat.le_of_sub_eq_zero s1) npos, by rw [ile, a2, n1]; exact ⟨rfl, rfl, rfl, rfl⟩ } }, { rw [ein, nat.mod_self, add_zero], exact x_increasing _ (nat.pred_lt $ ne_of_gt npos) } }) (λ (jn : j > n), have lem1 : j ≠ n → xn j % xn n < xn (j + 1) % xn n → xn i % xn n < xn (j + 1) % xn n, from λjn s, (lt_or_eq_of_le (nat.le_of_succ_le_succ ij)).elim (λh, lt_trans (eq_of_xn_modeq_lem3 h (le_of_lt j2n) jn $ λ⟨a1, n1, i0, j2⟩, by rw [n1, j2] at j2n; exact absurd j2n dec_trivial) s) (λh, by rw h; exact s), lem1 (ne_of_gt jn) $ int.lt_of_coe_nat_lt_coe_nat $ by { rw [lem2 j jn (le_of_lt j2n), lem2 (j+1) (nat.le_succ_of_le jn) j2n], refine sub_lt_sub_left (int.coe_nat_lt_coe_nat_of_lt $ x_increasing _ _) _, rw [nat.sub_succ], exact nat.pred_lt (ne_of_gt $ nat.sub_pos_of_lt j2n) }) theorem eq_of_xn_modeq_le {i j n} (npos : 0 < n) (ij : i ≤ j) (j2n : j ≤ 2 * n) (h : xn i ≡ xn j [MOD xn n]) (ntriv : ¬(a = 2 ∧ n = 1 ∧ i = 0 ∧ j = 2)) : i = j := (lt_or_eq_of_le ij).resolve_left $ λij', if jn : j = n then by { refine ne_of_gt _ h, rw [jn, nat.mod_self], have x0 : 0 < xn a1 0 % xn a1 n := by rw [nat.mod_eq_of_lt (x_increasing a1 npos)]; exact dec_trivial, cases i with i, exact x0, rw jn at ij', exact lt_trans x0 (eq_of_xn_modeq_lem3 _ npos (nat.succ_pos _) (le_trans ij j2n) (ne_of_lt ij') $ λ⟨a1, n1, _, i2⟩, by rw [n1, i2] at ij'; exact absurd ij' dec_trivial) } else ne_of_lt (eq_of_xn_modeq_lem3 npos ij' j2n jn ntriv) h theorem eq_of_xn_modeq {i j n} (npos : 0 < n) (i2n : i ≤ 2 * n) (j2n : j ≤ 2 * n) (h : xn i ≡ xn j [MOD xn n]) (ntriv : a = 2 → n = 1 → (i = 0 → j ≠ 2) ∧ (i = 2 → j ≠ 0)) : i = j := (le_total i j).elim (λij, eq_of_xn_modeq_le npos ij j2n h $ λ⟨a2, n1, i0, j2⟩, (ntriv a2 n1).left i0 j2) (λij, (eq_of_xn_modeq_le npos ij i2n h.symm $ λ⟨a2, n1, j0, i2⟩, (ntriv a2 n1).right i2 j0).symm) theorem eq_of_xn_modeq' {i j n} (ipos : 0 < i) (hin : i ≤ n) (j4n : j ≤ 4 * n) (h : xn j ≡ xn i [MOD xn n]) : j = i ∨ j + i = 4 * n := have i2n : i ≤ 2*n, by apply le_trans hin; rw two_mul; apply nat.le_add_left, have npos : 0 < n, from lt_of_lt_of_le ipos hin, (le_or_gt j (2 * n)).imp (λj2n : j ≤ 2 * n, eq_of_xn_modeq npos j2n i2n h $ λa2 n1, ⟨λj0 i2, by rw [n1, i2] at hin; exact absurd hin dec_trivial, λj2 i0, ne_of_gt ipos i0⟩) (λj2n : 2 * n < j, suffices i = 4*n - j, by rw [this, nat.add_sub_of_le j4n], have j42n : 4*n - j ≤ 2*n, from @nat.le_of_add_le_add_right j _ _ $ by rw [nat.sub_add_cancel j4n, show 4*n = 2*n + 2*n, from right_distrib 2 2 n]; exact nat.add_le_add_left (le_of_lt j2n) _, eq_of_xn_modeq npos i2n j42n (h.symm.trans $ let t := xn_modeq_x4n_sub j42n in by rwa [nat.sub_sub_self j4n] at t) (λa2 n1, ⟨λi0, absurd i0 (ne_of_gt ipos), λi2, by rw[n1, i2] at hin; exact absurd hin dec_trivial⟩)) theorem modeq_of_xn_modeq {i j n} (ipos : 0 < i) (hin : i ≤ n) (h : xn j ≡ xn i [MOD xn n]) : j ≡ i [MOD 4 * n] ∨ j + i ≡ 0 [MOD 4 * n] := let j' := j % (4 * n) in have n4 : 0 < 4 * n, from mul_pos dec_trivial (lt_of_lt_of_le ipos hin), have jl : j' < 4 * n, from nat.mod_lt _ n4, have jj : j ≡ j' [MOD 4 * n], by delta modeq; rw nat.mod_eq_of_lt jl, have ∀j q, xn (j + 4 * n * q) ≡ xn j [MOD xn n], begin intros j q, induction q with q IH, { simp }, rw[nat.mul_succ, ← add_assoc, add_comm], exact modeq.trans (xn_modeq_x4n_add _ _ _) IH end, or.imp (λ(ji : j' = i), by rwa ← ji) (λ(ji : j' + i = 4 * n), (modeq.modeq_add jj (modeq.refl _)).trans $ by rw ji; exact modeq.modeq_zero_iff.2 (dvd_refl _)) (eq_of_xn_modeq' ipos hin (le_of_lt jl) $ (modeq.symm (by rw ← nat.mod_add_div j (4*n); exact this j' _)).trans h) end theorem xy_modeq_of_modeq {a b c} (a1 : 1 < a) (b1 : 1 < b) (h : a ≡ b [MOD c]) : ∀ n, xn a1 n ≡ xn b1 n [MOD c] ∧ yn a1 n ≡ yn b1 n [MOD c] | 0 := by constructor; refl | 1 := by simp; exact ⟨h, modeq.refl 1⟩ | (n+2) := ⟨ modeq.modeq_add_cancel_right (xy_modeq_of_modeq n).left $ by rw [xn_succ_succ a1, xn_succ_succ b1]; exact modeq.modeq_mul (modeq.modeq_mul_left _ h) (xy_modeq_of_modeq (n+1)).left, modeq.modeq_add_cancel_right (xy_modeq_of_modeq n).right $ by rw [yn_succ_succ a1, yn_succ_succ b1]; exact modeq.modeq_mul (modeq.modeq_mul_left _ h) (xy_modeq_of_modeq (n+1)).right⟩ theorem matiyasevic {a k x y} : (∃ a1 : 1 < a, xn a1 k = x ∧ yn a1 k = y) ↔ 1 < a ∧ k ≤ y ∧ (x = 1 ∧ y = 0 ∨ ∃ (u v s t b : ℕ), x * x - (a * a - 1) * y * y = 1 ∧ u * u - (a * a - 1) * v * v = 1 ∧ s * s - (b * b - 1) * t * t = 1 ∧ 1 < b ∧ b ≡ 1 [MOD 4 * y] ∧ b ≡ a [MOD u] ∧ 0 < v ∧ y * y ∣ v ∧ s ≡ x [MOD u] ∧ t ≡ k [MOD 4 * y]) := ⟨λ⟨a1, hx, hy⟩, by rw [← hx, ← hy]; refine ⟨a1, (nat.eq_zero_or_pos k).elim (λk0, by rw k0; exact ⟨le_refl _, or.inl ⟨rfl, rfl⟩⟩) (λkpos, _)⟩; exact let x := xn a1 k, y := yn a1 k, m := 2 * (k * y), u := xn a1 m, v := yn a1 m in have ky : k ≤ y, from yn_ge_n a1 k, have yv : y * y ∣ v, from dvd_trans (ysq_dvd_yy a1 k) $ (y_dvd_iff _ _ _).2 $ dvd_mul_left _ _, have uco : nat.coprime u (4 * y), from have 2 ∣ v, from modeq.modeq_zero_iff.1 $ (yn_modeq_two _ _).trans $ modeq.modeq_zero_iff.2 (dvd_mul_right _ _), have nat.coprime u 2, from (xy_coprime a1 m).coprime_dvd_right this, (this.mul_right this).mul_right $ (xy_coprime _ _).coprime_dvd_right (dvd_of_mul_left_dvd yv), let ⟨b, ba, bm1⟩ := modeq.chinese_remainder uco a 1 in have m1 : 1 < m, from have 0 < k * y, from mul_pos kpos (y_increasing a1 kpos), nat.mul_le_mul_left 2 this, have vp : 0 < v, from y_increasing a1 (lt_trans zero_lt_one m1), have b1 : 1 < b, from have xn a1 1 < u, from x_increasing a1 m1, have a < u, by simp at this; exact this, lt_of_lt_of_le a1 $ by delta modeq at ba; rw nat.mod_eq_of_lt this at ba; rw ← ba; apply nat.mod_le, let s := xn b1 k, t := yn b1 k in have sx : s ≡ x [MOD u], from (xy_modeq_of_modeq b1 a1 ba k).left, have tk : t ≡ k [MOD 4 * y], from have 4 * y ∣ b - 1, from int.coe_nat_dvd.1 $ by rw int.coe_nat_sub (le_of_lt b1); exact modeq.dvd_of_modeq bm1.symm, modeq.modeq_of_dvd_of_modeq this $ yn_modeq_a_sub_one _ _, ⟨ky, or.inr ⟨u, v, s, t, b, pell_eq _ _, pell_eq _ _, pell_eq _ _, b1, bm1, ba, vp, yv, sx, tk⟩⟩, λ⟨a1, ky, o⟩, ⟨a1, match o with | or.inl ⟨x1, y0⟩ := by rw y0 at ky; rw [nat.eq_zero_of_le_zero ky, x1, y0]; exact ⟨rfl, rfl⟩ | or.inr ⟨u, v, s, t, b, xy, uv, st, b1, rem⟩ := match x, y, eq_pell a1 xy, u, v, eq_pell a1 uv, s, t, eq_pell b1 st, rem, ky with | ._, ._, ⟨i, rfl, rfl⟩, ._, ._, ⟨n, rfl, rfl⟩, ._, ._, ⟨j, rfl, rfl⟩, ⟨(bm1 : b ≡ 1 [MOD 4 * yn a1 i]), (ba : b ≡ a [MOD xn a1 n]), (vp : 0 < yn a1 n), (yv : yn a1 i * yn a1 i ∣ yn a1 n), (sx : xn b1 j ≡ xn a1 i [MOD xn a1 n]), (tk : yn b1 j ≡ k [MOD 4 * yn a1 i])⟩, (ky : k ≤ yn a1 i) := (nat.eq_zero_or_pos i).elim (λi0, by simp [i0] at ky; rw [i0, ky]; exact ⟨rfl, rfl⟩) $ λipos, suffices i = k, by rw this; exact ⟨rfl, rfl⟩, by clear _x o rem xy uv st _match _match _fun_match; exact have iln : i ≤ n, from le_of_not_gt $ λhin, not_lt_of_ge (nat.le_of_dvd vp (dvd_of_mul_left_dvd yv)) (y_increasing a1 hin), have yd : 4 * yn a1 i ∣ 4 * n, from mul_dvd_mul_left _ $ dvd_of_ysq_dvd a1 yv, have jk : j ≡ k [MOD 4 * yn a1 i], from have 4 * yn a1 i ∣ b - 1, from int.coe_nat_dvd.1 $ by rw int.coe_nat_sub (le_of_lt b1); exact modeq.dvd_of_modeq bm1.symm, (modeq.modeq_of_dvd_of_modeq this (yn_modeq_a_sub_one b1 _)).symm.trans tk, have ki : k + i < 4 * yn a1 i, from lt_of_le_of_lt (add_le_add ky (yn_ge_n a1 i)) $ by rw ← two_mul; exact nat.mul_lt_mul_of_pos_right dec_trivial (y_increasing a1 ipos), have ji : j ≡ i [MOD 4 * n], from have xn a1 j ≡ xn a1 i [MOD xn a1 n], from (xy_modeq_of_modeq b1 a1 ba j).left.symm.trans sx, (modeq_of_xn_modeq a1 ipos iln this).resolve_right $ λ (ji : j + i ≡ 0 [MOD 4 * n]), not_le_of_gt ki $ nat.le_of_dvd (lt_of_lt_of_le ipos $ nat.le_add_left _ _) $ modeq.modeq_zero_iff.1 $ (modeq.modeq_add jk.symm (modeq.refl i)).trans $ modeq.modeq_of_dvd_of_modeq yd ji, by have : i % (4 * yn a1 i) = k % (4 * yn a1 i) := (modeq.modeq_of_dvd_of_modeq yd ji).symm.trans jk; rwa [nat.mod_eq_of_lt (lt_of_le_of_lt (nat.le_add_left _ _) ki), nat.mod_eq_of_lt (lt_of_le_of_lt (nat.le_add_right _ _) ki)] at this end end⟩⟩ lemma eq_pow_of_pell_lem {a y k} (a1 : 1 < a) (ypos : 0 < y) : 0 < k → y^k < a → (↑(y^k) : ℤ) < 2*a*y - y*y - 1 := have y < a → a + (y*y + 1) ≤ 2*a*y, begin intro ya, induction y with y IH, exact absurd ypos (lt_irrefl _), cases nat.eq_zero_or_pos y with y0 ypos, { rw y0, simpa [two_mul], }, { rw [nat.mul_succ, nat.mul_succ, nat.succ_mul y], have : y + nat.succ y ≤ 2 * a, { change y + y < 2 * a, rw ← two_mul, exact mul_lt_mul_of_pos_left (nat.lt_of_succ_lt ya) dec_trivial }, have := add_le_add (IH ypos (nat.lt_of_succ_lt ya)) this, convert this using 1, ring } end, λk0 yak, lt_of_lt_of_le (int.coe_nat_lt_coe_nat_of_lt yak) $ by rw sub_sub; apply le_sub_right_of_add_le; apply int.coe_nat_le_coe_nat_of_le; have y1 := nat.pow_le_pow_of_le_right ypos k0; simp at y1; exact this (lt_of_le_of_lt y1 yak) theorem eq_pow_of_pell {m n k} : (n^k = m ↔ k = 0 ∧ m = 1 ∨ 0 < k ∧ (n = 0 ∧ m = 0 ∨ 0 < n ∧ ∃ (w a t z : ℕ) (a1 : 1 < a), xn a1 k ≡ yn a1 k * (a - n) + m [MOD t] ∧ 2 * a * n = t + (n * n + 1) ∧ m < t ∧ n ≤ w ∧ k ≤ w ∧ a * a - ((w + 1) * (w + 1) - 1) * (w * z) * (w * z) = 1)) := ⟨λe, by rw ← e; refine (nat.eq_zero_or_pos k).elim (λk0, by rw k0; exact or.inl ⟨rfl, rfl⟩) (λkpos, or.inr ⟨kpos, _⟩); refine (nat.eq_zero_or_pos n).elim (λn0, by rw [n0, zero_pow kpos]; exact or.inl ⟨rfl, rfl⟩) (λnpos, or.inr ⟨npos, _⟩); exact let w := _root_.max n k in have nw : n ≤ w, from le_max_left _ _, have kw : k ≤ w, from le_max_right _ _, have wpos : 0 < w, from lt_of_lt_of_le npos nw, have w1 : 1 < w + 1, from nat.succ_lt_succ wpos, let a := xn w1 w in have a1 : 1 < a, from x_increasing w1 wpos, let x := xn a1 k, y := yn a1 k in let ⟨z, ze⟩ := show w ∣ yn w1 w, from modeq.modeq_zero_iff.1 $ modeq.trans (yn_modeq_a_sub_one w1 w) (modeq.modeq_zero_iff.2 $ dvd_refl _) in have nt : (↑(n^k) : ℤ) < 2 * a * n - n * n - 1, from eq_pow_of_pell_lem a1 npos kpos $ calc n^k ≤ n^w : nat.pow_le_pow_of_le_right npos kw ... < (w + 1)^w : nat.pow_lt_pow_of_lt_left (nat.lt_succ_of_le nw) wpos ... ≤ a : xn_ge_a_pow w1 w, let ⟨t, te⟩ := int.eq_coe_of_zero_le $ le_trans (int.coe_zero_le _) $ le_of_lt nt in have na : n ≤ a, from le_trans nw $ le_of_lt $ n_lt_xn w1 w, have tm : x ≡ y * (a - n) + n^k [MOD t], begin apply modeq.modeq_of_dvd, rw [int.coe_nat_add, int.coe_nat_mul, int.coe_nat_sub na, ← te], exact x_sub_y_dvd_pow a1 n k end, have ta : 2 * a * n = t + (n * n + 1), from int.coe_nat_inj $ by rw [int.coe_nat_add, ← te, sub_sub]; repeat {rw int.coe_nat_add <|> rw int.coe_nat_mul}; rw [int.coe_nat_one, sub_add_cancel]; refl, have mt : n^k < t, from int.lt_of_coe_nat_lt_coe_nat $ by rw ← te; exact nt, have zp : a * a - ((w + 1) * (w + 1) - 1) * (w * z) * (w * z) = 1, by rw ← ze; exact pell_eq w1 w, ⟨w, a, t, z, a1, tm, ta, mt, nw, kw, zp⟩, λo, match o with | or.inl ⟨k0, m1⟩ := by rw [k0, m1]; refl | or.inr ⟨kpos, or.inl ⟨n0, m0⟩⟩ := by rw [n0, m0, zero_pow kpos] | or.inr ⟨kpos, or.inr ⟨npos, w, a, t, z, (a1 : 1 < a), (tm : xn a1 k ≡ yn a1 k * (a - n) + m [MOD t]), (ta : 2 * a * n = t + (n * n + 1)), (mt : m < t), (nw : n ≤ w), (kw : k ≤ w), (zp : a * a - ((w + 1) * (w + 1) - 1) * (w * z) * (w * z) = 1)⟩⟩ := have wpos : 0 < w, from lt_of_lt_of_le npos nw, have w1 : 1 < w + 1, from nat.succ_lt_succ wpos, let ⟨j, xj, yj⟩ := eq_pell w1 zp in by clear _match o _let_match; exact have jpos : 0 < j, from (nat.eq_zero_or_pos j).resolve_left $ λj0, have a1 : a = 1, by rw j0 at xj; exact xj, have 2 * n = t + (n * n + 1), by rw a1 at ta; exact ta, have n1 : n = 1, from have n * n < n * 2, by rw [mul_comm n 2, this]; apply nat.le_add_left, have n ≤ 1, from nat.le_of_lt_succ $ lt_of_mul_lt_mul_left this (nat.zero_le _), le_antisymm this npos, by rw n1 at this; rw ← @nat.add_right_cancel 0 2 t this at mt; exact nat.not_lt_zero _ mt, have wj : w ≤ j, from nat.le_of_dvd jpos $ modeq.modeq_zero_iff.1 $ (yn_modeq_a_sub_one w1 j).symm.trans $ modeq.modeq_zero_iff.2 ⟨z, yj.symm⟩, have nt : (↑(n^k) : ℤ) < 2 * a * n - n * n - 1, from eq_pow_of_pell_lem a1 npos kpos $ calc n^k ≤ n^j : nat.pow_le_pow_of_le_right npos (le_trans kw wj) ... < (w + 1)^j : nat.pow_lt_pow_of_lt_left (nat.lt_succ_of_le nw) jpos ... ≤ xn w1 j : xn_ge_a_pow w1 j ... = a : xj.symm, have na : n ≤ a, by rw xj; exact le_trans (le_trans nw wj) (le_of_lt $ n_lt_xn _ _), have te : (t : ℤ) = 2 * ↑a * ↑n - ↑n * ↑n - 1, by rw sub_sub; apply eq_sub_of_add_eq; apply (int.coe_nat_eq_coe_nat_iff _ _).2; exact ta.symm, have xn a1 k ≡ yn a1 k * (a - n) + n^k [MOD t], by have := x_sub_y_dvd_pow a1 n k; rw [← te, ← int.coe_nat_sub na] at this; exact modeq.modeq_of_dvd this, have n^k % t = m % t, from modeq.modeq_add_cancel_left (modeq.refl _) (this.symm.trans tm), by rw ← te at nt; rwa [nat.mod_eq_of_lt (int.lt_of_coe_nat_lt_coe_nat nt), nat.mod_eq_of_lt mt] at this end⟩ end pell
4b6a93d8b774ad5f213d054e56e44d9494a6c26c
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/analysis/convex/strict_convex_space.lean
189e75c6b3c988dd9ffe054d351d4f3d87729172
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
14,294
lean
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Yury Kudryashov -/ import analysis.convex.normed import analysis.convex.strict import analysis.normed.order.basic import analysis.normed_space.add_torsor import analysis.normed_space.pointwise import analysis.normed_space.affine_isometry /-! # Strictly convex spaces > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file defines strictly convex spaces. A normed space is strictly convex if all closed balls are strictly convex. This does **not** mean that the norm is strictly convex (in fact, it never is). ## Main definitions `strict_convex_space`: a typeclass saying that a given normed space over a normed linear ordered field (e.g., `ℝ` or `ℚ`) is strictly convex. The definition requires strict convexity of a closed ball of positive radius with center at the origin; strict convexity of any other closed ball follows from this assumption. ## Main results In a strictly convex space, we prove - `strict_convex_closed_ball`: a closed ball is strictly convex. - `combo_mem_ball_of_ne`, `open_segment_subset_ball_of_ne`, `norm_combo_lt_of_ne`: a nontrivial convex combination of two points in a closed ball belong to the corresponding open ball; - `norm_add_lt_of_not_same_ray`, `same_ray_iff_norm_add`, `dist_add_dist_eq_iff`: the triangle inequality `dist x y + dist y z ≤ dist x z` is a strict inequality unless `y` belongs to the segment `[x -[ℝ] z]`. - `isometry.affine_isometry_of_strict_convex_space`: an isometry of `normed_add_torsor`s for real normed spaces, strictly convex in the case of the codomain, is an affine isometry. We also provide several lemmas that can be used as alternative constructors for `strict_convex ℝ E`: - `strict_convex_space.of_strict_convex_closed_unit_ball`: if `closed_ball (0 : E) 1` is strictly convex, then `E` is a strictly convex space; - `strict_convex_space.of_norm_add`: if `‖x + y‖ = ‖x‖ + ‖y‖` implies `same_ray ℝ x y` for all nonzero `x y : E`, then `E` is a strictly convex space. ## Implementation notes While the definition is formulated for any normed linear ordered field, most of the lemmas are formulated only for the case `𝕜 = ℝ`. ## Tags convex, strictly convex -/ open set metric open_locale convex pointwise /-- A *strictly convex space* is a normed space where the closed balls are strictly convex. We only require balls of positive radius with center at the origin to be strictly convex in the definition, then prove that any closed ball is strictly convex in `strict_convex_closed_ball` below. See also `strict_convex_space.of_strict_convex_closed_unit_ball`. -/ class strict_convex_space (𝕜 E : Type*) [normed_linear_ordered_field 𝕜] [normed_add_comm_group E] [normed_space 𝕜 E] : Prop := (strict_convex_closed_ball : ∀ r : ℝ, 0 < r → strict_convex 𝕜 (closed_ball (0 : E) r)) variables (𝕜 : Type*) {E : Type*} [normed_linear_ordered_field 𝕜] [normed_add_comm_group E] [normed_space 𝕜 E] /-- A closed ball in a strictly convex space is strictly convex. -/ lemma strict_convex_closed_ball [strict_convex_space 𝕜 E] (x : E) (r : ℝ) : strict_convex 𝕜 (closed_ball x r) := begin cases le_or_lt r 0 with hr hr, { exact (subsingleton_closed_ball x hr).strict_convex }, rw ← vadd_closed_ball_zero, exact (strict_convex_space.strict_convex_closed_ball r hr).vadd _, end variables [normed_space ℝ E] /-- A real normed vector space is strictly convex provided that the unit ball is strictly convex. -/ lemma strict_convex_space.of_strict_convex_closed_unit_ball [linear_map.compatible_smul E E 𝕜 ℝ] (h : strict_convex 𝕜 (closed_ball (0 : E) 1)) : strict_convex_space 𝕜 E := ⟨λ r hr, by simpa only [smul_closed_unit_ball_of_nonneg hr.le] using h.smul r⟩ /-- Strict convexity is equivalent to `‖a • x + b • y‖ < 1` for all `x` and `y` of norm at most `1` and all strictly positive `a` and `b` such that `a + b = 1`. This lemma shows that it suffices to check this for points of norm one and some `a`, `b` such that `a + b = 1`. -/ lemma strict_convex_space.of_norm_combo_lt_one (h : ∀ x y : E, ‖x‖ = 1 → ‖y‖ = 1 → x ≠ y → ∃ a b : ℝ, a + b = 1 ∧ ‖a • x + b • y‖ < 1) : strict_convex_space ℝ E := begin refine strict_convex_space.of_strict_convex_closed_unit_ball ℝ ((convex_closed_ball _ _).strict_convex' $ λ x hx y hy hne, _), rw [interior_closed_ball (0 : E) one_ne_zero, closed_ball_diff_ball, mem_sphere_zero_iff_norm] at hx hy, rcases h x y hx hy hne with ⟨a, b, hab, hlt⟩, use b, rwa [affine_map.line_map_apply_module, interior_closed_ball (0 : E) one_ne_zero, mem_ball_zero_iff, sub_eq_iff_eq_add.2 hab.symm] end lemma strict_convex_space.of_norm_combo_ne_one (h : ∀ x y : E, ‖x‖ = 1 → ‖y‖ = 1 → x ≠ y → ∃ a b : ℝ, 0 ≤ a ∧ 0 ≤ b ∧ a + b = 1 ∧ ‖a • x + b • y‖ ≠ 1) : strict_convex_space ℝ E := begin refine strict_convex_space.of_strict_convex_closed_unit_ball ℝ ((convex_closed_ball _ _).strict_convex _), simp only [interior_closed_ball _ one_ne_zero, closed_ball_diff_ball, set.pairwise, frontier_closed_ball _ one_ne_zero, mem_sphere_zero_iff_norm], intros x hx y hy hne, rcases h x y hx hy hne with ⟨a, b, ha, hb, hab, hne'⟩, exact ⟨_, ⟨a, b, ha, hb, hab, rfl⟩, mt mem_sphere_zero_iff_norm.1 hne'⟩ end lemma strict_convex_space.of_norm_add_ne_two (h : ∀ ⦃x y : E⦄, ‖x‖ = 1 → ‖y‖ = 1 → x ≠ y → ‖x + y‖ ≠ 2) : strict_convex_space ℝ E := begin refine strict_convex_space.of_norm_combo_ne_one (λ x y hx hy hne, ⟨1/2, 1/2, one_half_pos.le, one_half_pos.le, add_halves _, _⟩), rw [← smul_add, norm_smul, real.norm_of_nonneg one_half_pos.le, one_div, ← div_eq_inv_mul, ne.def, div_eq_one_iff_eq (two_ne_zero' ℝ)], exact h hx hy hne, end lemma strict_convex_space.of_pairwise_sphere_norm_ne_two (h : (sphere (0 : E) 1).pairwise $ λ x y, ‖x + y‖ ≠ 2) : strict_convex_space ℝ E := strict_convex_space.of_norm_add_ne_two $ λ x y hx hy, h (mem_sphere_zero_iff_norm.2 hx) (mem_sphere_zero_iff_norm.2 hy) /-- If `‖x + y‖ = ‖x‖ + ‖y‖` implies that `x y : E` are in the same ray, then `E` is a strictly convex space. See also a more -/ lemma strict_convex_space.of_norm_add (h : ∀ x y : E, ‖x‖ = 1 → ‖y‖ = 1 → ‖x + y‖ = 2 → same_ray ℝ x y) : strict_convex_space ℝ E := begin refine strict_convex_space.of_pairwise_sphere_norm_ne_two (λ x hx y hy, mt $ λ h₂, _), rw mem_sphere_zero_iff_norm at hx hy, exact (same_ray_iff_of_norm_eq (hx.trans hy.symm)).1 (h x y hx hy h₂) end variables [strict_convex_space ℝ E] {x y z : E} {a b r : ℝ} /-- If `x ≠ y` belong to the same closed ball, then a convex combination of `x` and `y` with positive coefficients belongs to the corresponding open ball. -/ lemma combo_mem_ball_of_ne (hx : x ∈ closed_ball z r) (hy : y ∈ closed_ball z r) (hne : x ≠ y) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) : a • x + b • y ∈ ball z r := begin rcases eq_or_ne r 0 with rfl|hr, { rw [closed_ball_zero, mem_singleton_iff] at hx hy, exact (hne (hx.trans hy.symm)).elim }, { simp only [← interior_closed_ball _ hr] at hx hy ⊢, exact strict_convex_closed_ball ℝ z r hx hy hne ha hb hab } end /-- If `x ≠ y` belong to the same closed ball, then the open segment with endpoints `x` and `y` is included in the corresponding open ball. -/ lemma open_segment_subset_ball_of_ne (hx : x ∈ closed_ball z r) (hy : y ∈ closed_ball z r) (hne : x ≠ y) : open_segment ℝ x y ⊆ ball z r := (open_segment_subset_iff _).2 $ λ a b, combo_mem_ball_of_ne hx hy hne /-- If `x` and `y` are two distinct vectors of norm at most `r`, then a convex combination of `x` and `y` with positive coefficients has norm strictly less than `r`. -/ lemma norm_combo_lt_of_ne (hx : ‖x‖ ≤ r) (hy : ‖y‖ ≤ r) (hne : x ≠ y) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) : ‖a • x + b • y‖ < r := begin simp only [← mem_ball_zero_iff, ← mem_closed_ball_zero_iff] at hx hy ⊢, exact combo_mem_ball_of_ne hx hy hne ha hb hab end /-- In a strictly convex space, if `x` and `y` are not in the same ray, then `‖x + y‖ < ‖x‖ + ‖y‖`. -/ lemma norm_add_lt_of_not_same_ray (h : ¬same_ray ℝ x y) : ‖x + y‖ < ‖x‖ + ‖y‖ := begin simp only [same_ray_iff_inv_norm_smul_eq, not_or_distrib, ← ne.def] at h, rcases h with ⟨hx, hy, hne⟩, rw ← norm_pos_iff at hx hy, have hxy : 0 < ‖x‖ + ‖y‖ := add_pos hx hy, have := combo_mem_ball_of_ne (inv_norm_smul_mem_closed_unit_ball x) (inv_norm_smul_mem_closed_unit_ball y) hne (div_pos hx hxy) (div_pos hy hxy) (by rw [← add_div, div_self hxy.ne']), rwa [mem_ball_zero_iff, div_eq_inv_mul, div_eq_inv_mul, mul_smul, mul_smul, smul_inv_smul₀ hx.ne', smul_inv_smul₀ hy.ne', ← smul_add, norm_smul, real.norm_of_nonneg (inv_pos.2 hxy).le, ← div_eq_inv_mul, div_lt_one hxy] at this end lemma lt_norm_sub_of_not_same_ray (h : ¬same_ray ℝ x y) : ‖x‖ - ‖y‖ < ‖x - y‖ := begin nth_rewrite 0 ←sub_add_cancel x y at ⊢ h, exact sub_lt_iff_lt_add.2 (norm_add_lt_of_not_same_ray $ λ H', h $ H'.add_left same_ray.rfl), end lemma abs_lt_norm_sub_of_not_same_ray (h : ¬same_ray ℝ x y) : |‖x‖ - ‖y‖| < ‖x - y‖ := begin refine abs_sub_lt_iff.2 ⟨lt_norm_sub_of_not_same_ray h, _⟩, rw norm_sub_rev, exact lt_norm_sub_of_not_same_ray (mt same_ray.symm h), end /-- In a strictly convex space, two vectors `x`, `y` are in the same ray if and only if the triangle inequality for `x` and `y` becomes an equality. -/ lemma same_ray_iff_norm_add : same_ray ℝ x y ↔ ‖x + y‖ = ‖x‖ + ‖y‖ := ⟨same_ray.norm_add, λ h, not_not.1 $ λ h', (norm_add_lt_of_not_same_ray h').ne h⟩ /-- If `x` and `y` are two vectors in a strictly convex space have the same norm and the norm of their sum is equal to the sum of their norms, then they are equal. -/ lemma eq_of_norm_eq_of_norm_add_eq (h₁ : ‖x‖ = ‖y‖) (h₂ : ‖x + y‖ = ‖x‖ + ‖y‖) : x = y := (same_ray_iff_norm_add.mpr h₂).eq_of_norm_eq h₁ /-- In a strictly convex space, two vectors `x`, `y` are not in the same ray if and only if the triangle inequality for `x` and `y` is strict. -/ lemma not_same_ray_iff_norm_add_lt : ¬ same_ray ℝ x y ↔ ‖x + y‖ < ‖x‖ + ‖y‖ := same_ray_iff_norm_add.not.trans (norm_add_le _ _).lt_iff_ne.symm lemma same_ray_iff_norm_sub : same_ray ℝ x y ↔ ‖x - y‖ = |‖x‖ - ‖y‖| := ⟨same_ray.norm_sub, λ h, not_not.1 $ λ h', (abs_lt_norm_sub_of_not_same_ray h').ne' h⟩ lemma not_same_ray_iff_abs_lt_norm_sub : ¬ same_ray ℝ x y ↔ |‖x‖ - ‖y‖| < ‖x - y‖ := same_ray_iff_norm_sub.not.trans $ ne_comm.trans (abs_norm_sub_norm_le _ _).lt_iff_ne.symm /-- In a strictly convex space, the triangle inequality turns into an equality if and only if the middle point belongs to the segment joining two other points. -/ lemma dist_add_dist_eq_iff : dist x y + dist y z = dist x z ↔ y ∈ [x -[ℝ] z] := by simp only [mem_segment_iff_same_ray, same_ray_iff_norm_add, dist_eq_norm', sub_add_sub_cancel', eq_comm] lemma norm_midpoint_lt_iff (h : ‖x‖ = ‖y‖) : ‖(1/2 : ℝ) • (x + y)‖ < ‖x‖ ↔ x ≠ y := by rw [norm_smul, real.norm_of_nonneg (one_div_nonneg.2 zero_le_two), ←inv_eq_one_div, ←div_eq_inv_mul, div_lt_iff (zero_lt_two' ℝ), mul_two, ←not_same_ray_iff_of_norm_eq h, not_same_ray_iff_norm_add_lt, h] variables {F : Type*} [normed_add_comm_group F] [normed_space ℝ F] variables {PF : Type*} {PE : Type*} [metric_space PF] [metric_space PE] variables [normed_add_torsor F PF] [normed_add_torsor E PE] include E lemma eq_line_map_of_dist_eq_mul_of_dist_eq_mul {x y z : PE} (hxy : dist x y = r * dist x z) (hyz : dist y z = (1 - r) * dist x z) : y = affine_map.line_map x z r := begin have : y -ᵥ x ∈ [(0 : E) -[ℝ] z -ᵥ x], { rw [← dist_add_dist_eq_iff, dist_zero_left, dist_vsub_cancel_right, ← dist_eq_norm_vsub', ← dist_eq_norm_vsub', hxy, hyz, ← add_mul, add_sub_cancel'_right, one_mul] }, rcases eq_or_ne x z with rfl|hne, { obtain rfl : y = x, by simpa, simp }, { rw [← dist_ne_zero] at hne, rcases this with ⟨a, b, ha, hb, hab, H⟩, rw [smul_zero, zero_add] at H, have H' := congr_arg norm H, rw [norm_smul, real.norm_of_nonneg hb, ← dist_eq_norm_vsub', ← dist_eq_norm_vsub', hxy, mul_left_inj' hne] at H', rw [affine_map.line_map_apply, ← H', H, vsub_vadd] }, end lemma eq_midpoint_of_dist_eq_half {x y z : PE} (hx : dist x y = dist x z / 2) (hy : dist y z = dist x z / 2) : y = midpoint ℝ x z := begin apply eq_line_map_of_dist_eq_mul_of_dist_eq_mul, { rwa [inv_of_eq_inv, ← div_eq_inv_mul] }, { rwa [inv_of_eq_inv, ← one_div, sub_half, one_div, ← div_eq_inv_mul] } end namespace isometry include F /-- An isometry of `normed_add_torsor`s for real normed spaces, strictly convex in the case of the codomain, is an affine isometry. Unlike Mazur-Ulam, this does not require the isometry to be surjective. -/ noncomputable def affine_isometry_of_strict_convex_space {f : PF → PE} (hi : isometry f) : PF →ᵃⁱ[ℝ] PE := { norm_map := λ x, by simp [affine_map.of_map_midpoint, ←dist_eq_norm_vsub E, hi.dist_eq], ..affine_map.of_map_midpoint f (λ x y, begin apply eq_midpoint_of_dist_eq_half, { rw [hi.dist_eq, hi.dist_eq, dist_left_midpoint, real.norm_of_nonneg zero_le_two, div_eq_inv_mul] }, { rw [hi.dist_eq, hi.dist_eq, dist_midpoint_right, real.norm_of_nonneg zero_le_two, div_eq_inv_mul] }, end) hi.continuous } @[simp] lemma coe_affine_isometry_of_strict_convex_space {f : PF → PE} (hi : isometry f) : ⇑(hi.affine_isometry_of_strict_convex_space) = f := rfl @[simp] lemma affine_isometry_of_strict_convex_space_apply {f : PF → PE} (hi : isometry f) (p : PF) : hi.affine_isometry_of_strict_convex_space p = f p := rfl end isometry
8e02533229d62729e916bf5d2dadf87eff97a17c
4fa161becb8ce7378a709f5992a594764699e268
/src/linear_algebra/finite_dimensional.lean
813563bbf55757a4dfebca17c4edd903b2bce167
[ "Apache-2.0" ]
permissive
laughinggas/mathlib
e4aa4565ae34e46e834434284cb26bd9d67bc373
86dcd5cda7a5017c8b3c8876c89a510a19d49aad
refs/heads/master
1,669,496,232,688
1,592,831,995,000
1,592,831,995,000
274,155,979
0
0
Apache-2.0
1,592,835,190,000
1,592,835,189,000
null
UTF-8
Lean
false
false
25,690
lean
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import linear_algebra.dimension import ring_theory.principal_ideal_domain /-! # Finite dimensional vector spaces Definition and basic properties of finite dimensional vector spaces, of their dimensions, and of linear maps on such spaces. ## Main definitions Assume `V` is a vector space over a field `K`. There are (at least) three equivalent definitions of finite-dimensionality of `V`: - it admits a finite basis. - it is finitely generated. - it is noetherian, i.e., every subspace is finitely generated. We introduce a typeclass `finite_dimensional K V` capturing this property. For ease of transfer of proof, it is defined using the third point of view, i.e., as `is_noetherian`. However, we prove that all these points of view are equivalent, with the following lemmas (in the namespace `finite_dimensional`): - `exists_is_basis_finite` states that a finite-dimensional vector space has a finite basis - `of_finite_basis` states that the existence of a finite basis implies finite-dimensionality - `iff_fg` states that the space is finite-dimensional if and only if it is finitely generated Also defined is `findim`, the dimension of a finite dimensional space, returning a `nat`, as opposed to `dim`, which returns a `cardinal`. When the space has infinite dimension, its `findim` is by convention set to `0`. Preservation of finite-dimensionality and formulas for the dimension are given for - submodules - quotients (for the dimension of a quotient, see `findim_quotient_add_findim`) - linear equivs, in `linear_equiv.finite_dimensional` and `linear_equiv.findim_eq` - image under a linear map (the rank-nullity formula is in `findim_range_add_findim_ker`) Basic properties of linear maps of a finite-dimensional vector space are given. Notably, the equivalence of injectivity and surjectivity is proved in `linear_map.injective_iff_surjective`, and the equivalence between left-inverse and right-inverse in `mul_eq_one_comm` and `comp_eq_id_comm`. ## Implementation notes Most results are deduced from the corresponding results for the general dimension (as a cardinal), in `dimension.lean`. Not all results have been ported yet. One of the characterizations of finite-dimensionality is in terms of finite generation. This property is currently defined only for submodules, so we express it through the fact that the maximal submodule (which, as a set, coincides with the whole space) is finitely generated. This is not very convenient to use, although there are some helper functions. However, this becomes very convenient when speaking of submodules which are finite-dimensional, as this notion coincides with the fact that the submodule is finitely generated (as a submodule of the whole space). This equivalence is proved in `submodule.fg_iff_finite_dimensional`. -/ universes u v v' w open_locale classical open vector_space cardinal submodule module function variables {K : Type u} {V : Type v} [field K] [add_comm_group V] [vector_space K V] {V₂ : Type v'} [add_comm_group V₂] [vector_space K V₂] /-- `finite_dimensional` vector spaces are defined to be noetherian modules. Use `finite_dimensional.iff_fg` or `finite_dimensional.of_finite_basis` to prove finite dimension from a conventional definition. -/ @[reducible] def finite_dimensional (K V : Type*) [field K] [add_comm_group V] [vector_space K V] := is_noetherian K V namespace finite_dimensional open is_noetherian /-- A vector space is finite-dimensional if and only if its dimension (as a cardinal) is strictly less than the first infinite cardinal `omega`. -/ lemma finite_dimensional_iff_dim_lt_omega : finite_dimensional K V ↔ dim K V < omega.{v} := begin cases exists_is_basis K V with b hb, have := is_basis.mk_eq_dim hb, simp only [lift_id] at this, rw [← this, lt_omega_iff_fintype, ← @set.set_of_mem_eq _ b, ← subtype.val_range], split, { intro, resetI, convert finite_of_linear_independent hb.1, simp }, { assume hbfinite, refine @is_noetherian_of_linear_equiv K (⊤ : submodule K V) V _ _ _ _ _ (linear_equiv.of_top _ rfl) (id _), refine is_noetherian_of_fg_of_noetherian _ ⟨set.finite.to_finset hbfinite, _⟩, rw [set.finite.coe_to_finset, ← hb.2], refl } end /-- The dimension of a finite-dimensional vector space, as a cardinal, is strictly less than the first infinite cardinal `omega`. -/ lemma dim_lt_omega (K V : Type*) [field K] [add_comm_group V] [vector_space K V] : ∀ [finite_dimensional K V], dim K V < omega.{v} := finite_dimensional_iff_dim_lt_omega.1 /-- In a finite dimensional space, there exists a finite basis. A basis is in general given as a function from an arbitrary type to the vector space. Here, we think of a basis as a set (instead of a function), and use as parametrizing type this set (and as a function the function `subtype.val`). -/ variables (K V) lemma exists_is_basis_finite [finite_dimensional K V] : ∃ s : set V, (is_basis K (subtype.val : s → V)) ∧ s.finite := begin cases exists_is_basis K V with s hs, exact ⟨s, hs, finite_of_linear_independent hs.1⟩ end /-- In a finite dimensional space, there exists a finite basis. Provides the basis as a finset. This is in contrast to `exists_is_basis_finite`, which provides a set and a `set.finite`. -/ lemma exists_is_basis_finset [finite_dimensional K V] : ∃ b : finset V, is_basis K (subtype.val : (↑b : set V) → V) := begin obtain ⟨s, s_basis, s_finite⟩ := exists_is_basis_finite K V, refine ⟨s_finite.to_finset, _⟩, rw set.finite.coe_to_finset, exact s_basis, end variables {K V} /-- A vector space is finite-dimensional if and only if it is finitely generated. As the finitely-generated property is a property of submodules, we formulate this in terms of the maximal submodule, equal to the whole space as a set by definition.-/ lemma iff_fg : finite_dimensional K V ↔ (⊤ : submodule K V).fg := begin split, { introI h, rcases exists_is_basis_finite K V with ⟨s, s_basis, s_finite⟩, exact ⟨s_finite.to_finset, by { convert s_basis.2, simp }⟩ }, { rintros ⟨s, hs⟩, rw [finite_dimensional_iff_dim_lt_omega, ← dim_top, ← hs], exact lt_of_le_of_lt (dim_span_le _) (lt_omega_iff_finite.2 (set.finite_mem_finset s)) } end /-- If a vector space has a finite basis, then it is finite-dimensional. -/ lemma of_finite_basis {ι : Type w} [fintype ι] {b : ι → V} (h : is_basis K b) : finite_dimensional K V := iff_fg.2 $ ⟨finset.univ.image b, by {convert h.2, simp} ⟩ /-- If a vector space has a finite basis, then it is finite-dimensional, finset style. -/ lemma of_finset_basis {b : finset V} (h : is_basis K (subtype.val : (↑b : set V) -> V)) : finite_dimensional K V := iff_fg.2 $ ⟨b, by {convert h.2, simp} ⟩ /-- A subspace of a finite-dimensional space is also finite-dimensional. -/ instance finite_dimensional_submodule [finite_dimensional K V] (S : submodule K V) : finite_dimensional K S := finite_dimensional_iff_dim_lt_omega.2 (lt_of_le_of_lt (dim_submodule_le _) (dim_lt_omega K V)) /-- A quotient of a finite-dimensional space is also finite-dimensional. -/ instance finite_dimensional_quotient [finite_dimensional K V] (S : submodule K V) : finite_dimensional K (quotient S) := finite_dimensional_iff_dim_lt_omega.2 (lt_of_le_of_lt (dim_quotient_le _) (dim_lt_omega K V)) /-- The dimension of a finite-dimensional vector space as a natural number. Defined by convention to be `0` if the space is infinite-dimensional. -/ noncomputable def findim (K V : Type*) [field K] [add_comm_group V] [vector_space K V] : ℕ := if h : dim K V < omega.{v} then classical.some (lt_omega.1 h) else 0 /-- In a finite-dimensional space, its dimension (seen as a cardinal) coincides with its `findim`. -/ lemma findim_eq_dim (K : Type u) (V : Type v) [field K] [add_comm_group V] [vector_space K V] [finite_dimensional K V] : (findim K V : cardinal.{v}) = dim K V := begin have : findim K V = classical.some (lt_omega.1 (dim_lt_omega K V)) := dif_pos (dim_lt_omega K V), rw this, exact (classical.some_spec (lt_omega.1 (dim_lt_omega K V))).symm end /-- If a vector space has a finite basis, then its dimension (seen as a cardinal) is equal to the cardinality of the basis. -/ lemma dim_eq_card_basis {ι : Type w} [fintype ι] {b : ι → V} (h : is_basis K b) : dim K V = fintype.card ι := by rw [←h.mk_range_eq_dim, cardinal.fintype_card, set.card_range_of_injective (h.injective zero_ne_one)] /-- If a vector space has a finite basis, then its dimension is equal to the cardinality of the basis. -/ lemma findim_eq_card_basis {ι : Type w} [fintype ι] {b : ι → V} (h : is_basis K b) : findim K V = fintype.card ι := begin haveI : finite_dimensional K V := of_finite_basis h, have := dim_eq_card_basis h, rw ← findim_eq_dim at this, exact_mod_cast this end /-- If a vector space is finite-dimensional, then the cardinality of any basis is equal to its `findim`. -/ lemma findim_eq_card_basis' [finite_dimensional K V] {ι : Type w} {b : ι → V} (h : is_basis K b) : (findim K V : cardinal.{w}) = cardinal.mk ι := begin rcases exists_is_basis_finite K V with ⟨s, s_basis, s_finite⟩, letI: fintype s := s_finite.fintype, have A : cardinal.mk s = fintype.card s := fintype_card _, have B : findim K V = fintype.card s := findim_eq_card_basis s_basis, have C : cardinal.lift.{w v} (cardinal.mk ι) = cardinal.lift.{v w} (cardinal.mk s) := mk_eq_mk_of_basis h s_basis, rw [A, ← B, lift_nat_cast] at C, have : cardinal.lift.{w v} (cardinal.mk ι) = cardinal.lift.{w v} (findim K V), by { simp, exact C }, exact (lift_inj.mp this).symm end /-- If a vector space has a finite basis, then its dimension is equal to the cardinality of the basis. This lemma uses a `finset` instead of indexed types. -/ lemma findim_eq_card_finset_basis {b : finset V} (h : is_basis K (subtype.val : (↑b : set V) -> V)) : findim K V = finset.card b := by { rw [findim_eq_card_basis h, fintype.subtype_card], intros x, refl } -- Note here we've restricted the universe levels of `ι` and `V` to be the same, for convenience. lemma cardinal_mk_le_findim_of_linear_independent [finite_dimensional K V] {ι : Type v} {b : ι → V} (h : linear_independent K b) : cardinal.mk ι ≤ findim K V := begin convert cardinal_le_dim_of_linear_independent h, rw ←findim_eq_dim K V end -- Note here we've restricted the universe levels of `ι` and `V` to be the same, for convenience. lemma fintype_card_le_findim_of_linear_independent [finite_dimensional K V] {ι : Type v} [fintype ι] {b : ι → V} (h : linear_independent K b) : fintype.card ι ≤ findim K V := by simpa [fintype_card] using cardinal_mk_le_findim_of_linear_independent h lemma finset_card_le_findim_of_linear_independent [finite_dimensional K V] {b : finset V} (h : linear_independent K (λ x, x : (↑b : set V) → V)) : b.card ≤ findim K V := begin rw ←fintype.card_coe, exact fintype_card_le_findim_of_linear_independent h, end section open_locale big_operators open finset /-- If a finset has cardinality larger than the dimension of the space, then there is a nontrivial linear relation amongst its elements. -/ lemma exists_nontrivial_relation_of_dim_lt_card [finite_dimensional K V] {t : finset V} (h : findim K V < t.card) : ∃ f : V → K, ∑ e in t, f e • e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := begin have := mt finset_card_le_findim_of_linear_independent (by { simpa using h }), rw linear_dependent_iff at this, obtain ⟨s, g, sum, z, zm, nonzero⟩ := this, -- Now we have to extend `g` to all of `t`, then to all of `V`. let f : V → K := λ x, if h : x ∈ t then if (⟨x, h⟩ : (↑t : set V)) ∈ s then g ⟨x, h⟩ else 0 else 0, -- and finally clean up the mess caused by the extension. refine ⟨f, _, _⟩, { dsimp [f], rw ← sum, fapply sum_bij_ne_zero (λ v hvt _, (⟨v, hvt⟩ : {v // v ∈ t})), { intros v hvt H, dsimp, rw [dif_pos hvt] at H, contrapose! H, rw [if_neg H, zero_smul], }, { intros _ _ _ _ _ _, exact subtype.mk.inj, }, { intros b hbs hb, use b, simpa only [hbs, exists_prop, dif_pos, mk_coe, and_true, if_true, finset.coe_mem, eq_self_iff_true, exists_prop_of_true, ne.def] using hb, }, { intros a h₁, dsimp, rw [dif_pos h₁], intro h₂, rw [if_pos], contrapose! h₂, rw [if_neg h₂, zero_smul], }, }, { refine ⟨z, z.2, _⟩, dsimp only [f], erw [dif_pos z.2, if_pos]; rwa [subtype.coe_eta] }, end /-- If a finset has cardinality larger than `findim + 1`, then there is a nontrivial linear relation amongst its elements, such that the coefficients of the relation sum to zero. -/ lemma exists_nontrivial_relation_sum_zero_of_dim_succ_lt_card [finite_dimensional K V] {t : finset V} (h : findim K V + 1 < t.card) : ∃ f : V → K, ∑ e in t, f e • e = 0 ∧ ∑ e in t, f e = 0 ∧ ∃ x ∈ t, f x ≠ 0 := begin -- Pick an element x₀ ∈ t, have card_pos : 0 < t.card := lt_trans (nat.succ_pos _) h, obtain ⟨x₀, m⟩ := (finset.card_pos.1 card_pos).bex, -- and apply the previous lemma to the {xᵢ - x₀} let shift : V ↪ V := ⟨λ x, x - x₀, add_left_injective (-x₀)⟩, let t' := (t.erase x₀).map shift, have h' : findim K V < t'.card, { simp only [t', card_map, finset.card_erase_of_mem m], exact nat.lt_pred_iff.mpr h, }, -- to obtain a function `g`. obtain ⟨g, gsum, x₁, x₁_mem, nz⟩ := exists_nontrivial_relation_of_dim_lt_card h', -- Then obtain `f` by translating back by `x₀`, -- and setting the value of `f` at `x₀` to ensure `∑ e in t, f e = 0`. let f : V → K := λ z, if z = x₀ then - ∑ z in (t.erase x₀), g (z - x₀) else g (z - x₀), refine ⟨f, _ ,_ ,_⟩, -- After this, it's a matter of verifiying the properties, -- based on the corresponding properties for `g`. { show ∑ (e : V) in t, f e • e = 0, -- We prove this by splitting off the `x₀` term of the sum, -- which is itself a sum over `t.erase x₀`, -- combining the two sums, and -- observing that after reindexing we have exactly -- ∑ (x : V) in t', g x • x = 0. simp only [f], conv_lhs { apply_congr, skip, rw [ite_smul], }, rw [finset.sum_ite], conv { congr, congr, apply_congr, simp [filter_eq', m], }, conv { congr, congr, skip, apply_congr, simp [filter_ne'], }, rw [sum_singleton, neg_smul, add_comm, ←sub_eq_add_neg, sum_smul, ←sum_sub_distrib], simp only [←smul_sub], -- At the end we have to reindex the sum, so we use `change` to -- express the summand using `shift`. change (∑ (x : V) in t.erase x₀, (λ e, g e • e) (shift x)) = 0, rw ←sum_map _ shift, exact gsum, }, { show ∑ (e : V) in t, f e = 0, -- Again we split off the `x₀` term, -- observing that it exactly cancels the other terms. rw [← insert_erase m, sum_insert (not_mem_erase x₀ t)], dsimp [f], rw [if_pos rfl], conv_lhs { congr, skip, apply_congr, skip, rw if_neg (show x ≠ x₀, from (mem_erase.mp H).1), }, exact neg_add_self _, }, { show ∃ (x : V) (H : x ∈ t), f x ≠ 0, -- We can use x₁ + x₀. refine ⟨x₁ + x₀, _, _⟩, { rw finset.mem_map at x₁_mem, rcases x₁_mem with ⟨x₁, x₁_mem, rfl⟩, rw mem_erase at x₁_mem, simp only [x₁_mem, sub_add_cancel, function.embedding.coe_fn_mk], }, { dsimp only [f], rwa [if_neg, add_sub_cancel], rw [add_left_eq_self], rintro rfl, simpa only [sub_eq_zero, exists_prop, finset.mem_map, embedding.coe_fn_mk, eq_self_iff_true, mem_erase, not_true, exists_eq_right, ne.def, false_and] using x₁_mem, } }, end section variables {L : Type*} [discrete_linear_ordered_field L] variables {W : Type v} [add_comm_group W] [vector_space L W] /-- A slight strengthening of `exists_nontrivial_relation_sum_zero_of_dim_succ_lt_card` available when working over an ordered field: we can ensure a positive coefficient, not just a nonzero coefficient. -/ lemma exists_relation_sum_zero_pos_coefficient_of_dim_succ_lt_card [finite_dimensional L W] {t : finset W} (h : findim L W + 1 < t.card) : ∃ f : W → L, ∑ e in t, f e • e = 0 ∧ ∑ e in t, f e = 0 ∧ ∃ x ∈ t, 0 < f x := begin obtain ⟨f, sum, total, nonzero⟩ := exists_nontrivial_relation_sum_zero_of_dim_succ_lt_card h, exact ⟨f, sum, total, exists_pos_of_sum_zero_of_exists_nonzero f total nonzero⟩, end end end /-- If a submodule has maximal dimension in a finite dimensional space, then it is equal to the whole space. -/ lemma eq_top_of_findim_eq [finite_dimensional K V] {S : submodule K V} (h : findim K S = findim K V) : S = ⊤ := begin cases exists_is_basis K S with bS hbS, have : linear_independent K (subtype.val : (subtype.val '' bS : set V) → V), from @linear_independent.image_subtype _ _ _ _ _ _ _ _ _ (submodule.subtype S) hbS.1 (by simp), cases exists_subset_is_basis this with b hb, letI : fintype b := classical.choice (finite_of_linear_independent hb.2.1), letI : fintype (subtype.val '' bS) := classical.choice (finite_of_linear_independent this), letI : fintype bS := classical.choice (finite_of_linear_independent hbS.1), have : subtype.val '' bS = b, from set.eq_of_subset_of_card_le hb.1 (by rw [set.card_image_of_injective _ subtype.val_injective, ← findim_eq_card_basis hbS, ← findim_eq_card_basis hb.2, h]; apply_instance), erw [← hb.2.2, subtype.val_range, ← this, set.set_of_mem_eq, ← subtype_eq_val, span_image], have := hbS.2, erw [subtype.val_range, set.set_of_mem_eq] at this, rw [this, map_top (submodule.subtype S), range_subtype], end variable (K) /-- A field is one-dimensional as a vector space over itself. -/ @[simp] lemma findim_of_field : findim K K = 1 := begin have := dim_of_field K, rw [← findim_eq_dim] at this, exact_mod_cast this end /-- The vector space of functions on a fintype has finite dimension. -/ instance finite_dimensional_fintype_fun {ι : Type*} [fintype ι] : finite_dimensional K (ι → K) := by { rw [finite_dimensional_iff_dim_lt_omega, dim_fun'], exact nat_lt_omega _ } /-- The vector space of functions on a fintype ι has findim equal to the cardinality of ι. -/ @[simp] lemma findim_fintype_fun_eq_card {ι : Type v} [fintype ι] : findim K (ι → K) = fintype.card ι := begin have : vector_space.dim K (ι → K) = fintype.card ι := dim_fun', rwa [← findim_eq_dim, nat_cast_inj] at this, end /-- The vector space of functions on `fin n` has findim equal to `n`. -/ @[simp] lemma findim_fin_fun {n : ℕ} : findim K (fin n → K) = n := by simp /-- The submodule generated by a finite set is finite-dimensional. -/ theorem span_of_finite {A : set V} (hA : set.finite A) : finite_dimensional K (submodule.span K A) := is_noetherian_span_of_finite K hA /-- The submodule generated by a single element is finite-dimensional. -/ instance (x : V) : finite_dimensional K (submodule.span K ({x} : set V)) := by {apply span_of_finite, simp} end finite_dimensional namespace submodule open finite_dimensional /-- A submodule is finitely generated if and only if it is finite-dimensional -/ theorem fg_iff_finite_dimensional (s : submodule K V) : s.fg ↔ finite_dimensional K s := ⟨λh, is_noetherian_of_fg_of_noetherian s h, λh, by { rw ← map_subtype_top s, exact fg_map (iff_fg.1 h) }⟩ /-- In a finite-dimensional vector space, the dimensions of a submodule and of the corresponding quotient add up to the dimension of the space. -/ theorem findim_quotient_add_findim [finite_dimensional K V] (s : submodule K V) : findim K s.quotient + findim K s = findim K V := begin have := dim_quotient_add_dim s, rw [← findim_eq_dim, ← findim_eq_dim, ← findim_eq_dim] at this, exact_mod_cast this end /-- The dimension of a submodule is bounded by the dimension of the ambient space. -/ lemma findim_le [finite_dimensional K V] (s : submodule K V) : findim K s ≤ findim K V := by { rw ← s.findim_quotient_add_findim, exact nat.le_add_left _ _ } /-- The dimension of a quotient is bounded by the dimension of the ambient space. -/ lemma findim_quotient_le [finite_dimensional K V] (s : submodule K V) : findim K s.quotient ≤ findim K V := by { rw ← s.findim_quotient_add_findim, exact nat.le_add_right _ _ } end submodule namespace linear_equiv open finite_dimensional /-- Finite dimensionality is preserved under linear equivalence. -/ protected theorem finite_dimensional (f : V ≃ₗ[K] V₂) [finite_dimensional K V] : finite_dimensional K V₂ := is_noetherian_of_linear_equiv f /-- The dimension of a finite dimensional space is preserved under linear equivalence. -/ theorem findim_eq (f : V ≃ₗ[K] V₂) [finite_dimensional K V] : findim K V = findim K V₂ := begin haveI : finite_dimensional K V₂ := f.finite_dimensional, rcases exists_is_basis_finite K V with ⟨s, s_basis, s_finite⟩, letI : fintype s := s_finite.fintype, have A : findim K V = fintype.card s := findim_eq_card_basis s_basis, have : is_basis K (λx:s, f (subtype.val x)) := f.is_basis s_basis, have B : findim K V₂ = fintype.card s := findim_eq_card_basis this, rw [A, B] end end linear_equiv namespace linear_map open finite_dimensional /-- On a finite-dimensional space, an injective linear map is surjective. -/ lemma surjective_of_injective [finite_dimensional K V] {f : V →ₗ[K] V} (hinj : injective f) : surjective f := begin have h := dim_eq_of_injective _ hinj, rw [← findim_eq_dim, ← findim_eq_dim, nat_cast_inj] at h, exact range_eq_top.1 (eq_top_of_findim_eq h.symm) end /-- On a finite-dimensional space, a linear map is injective if and only if it is surjective. -/ lemma injective_iff_surjective [finite_dimensional K V] {f : V →ₗ[K] V} : injective f ↔ surjective f := ⟨surjective_of_injective, λ hsurj, let ⟨g, hg⟩ := f.exists_right_inverse_of_surjective (range_eq_top.2 hsurj) in have function.right_inverse g f, from linear_map.ext_iff.1 hg, (left_inverse_of_surjective_of_right_inverse (surjective_of_injective this.injective) this).injective⟩ lemma ker_eq_bot_iff_range_eq_top [finite_dimensional K V] {f : V →ₗ[K] V} : f.ker = ⊥ ↔ f.range = ⊤ := by rw [range_eq_top, ker_eq_bot, injective_iff_surjective] /-- In a finite-dimensional space, if linear maps are inverse to each other on one side then they are also inverse to each other on the other side. -/ lemma mul_eq_one_of_mul_eq_one [finite_dimensional K V] {f g : V →ₗ[K] V} (hfg : f * g = 1) : g * f = 1 := have ginj : injective g, from has_left_inverse.injective ⟨f, (λ x, show (f * g) x = (1 : V →ₗ[K] V) x, by rw hfg; refl)⟩, let ⟨i, hi⟩ := g.exists_right_inverse_of_surjective (range_eq_top.2 (injective_iff_surjective.1 ginj)) in have f * (g * i) = f * 1, from congr_arg _ hi, by rw [← mul_assoc, hfg, one_mul, mul_one] at this; rwa ← this /-- In a finite-dimensional space, linear maps are inverse to each other on one side if and only if they are inverse to each other on the other side. -/ lemma mul_eq_one_comm [finite_dimensional K V] {f g : V →ₗ[K] V} : f * g = 1 ↔ g * f = 1 := ⟨mul_eq_one_of_mul_eq_one, mul_eq_one_of_mul_eq_one⟩ /-- In a finite-dimensional space, linear maps are inverse to each other on one side if and only if they are inverse to each other on the other side. -/ lemma comp_eq_id_comm [finite_dimensional K V] {f g : V →ₗ[K] V} : f.comp g = id ↔ g.comp f = id := mul_eq_one_comm /-- The image under an onto linear map of a finite-dimensional space is also finite-dimensional. -/ lemma finite_dimensional_of_surjective [h : finite_dimensional K V] (f : V →ₗ[K] V₂) (hf : f.range = ⊤) : finite_dimensional K V₂ := is_noetherian_of_surjective V f hf /-- The range of a linear map defined on a finite-dimensional space is also finite-dimensional. -/ instance finite_dimensional_range [h : finite_dimensional K V] (f : V →ₗ[K] V₂) : finite_dimensional K f.range := f.quot_ker_equiv_range.finite_dimensional /-- rank-nullity theorem : the dimensions of the kernel and the range of a linear map add up to the dimension of the source space. -/ theorem findim_range_add_findim_ker [finite_dimensional K V] (f : V →ₗ[K] V₂) : findim K f.range + findim K f.ker = findim K V := by { rw [← f.quot_ker_equiv_range.findim_eq], exact submodule.findim_quotient_add_findim _ } end linear_map section zero_dim open vector_space finite_dimensional lemma finite_dimensional_of_dim_eq_zero (h : vector_space.dim K V = 0) : finite_dimensional K V := by rw [finite_dimensional_iff_dim_lt_omega, h]; exact cardinal.omega_pos lemma findim_eq_zero_of_dim_eq_zero [finite_dimensional K V] (h : vector_space.dim K V = 0) : findim K V = 0 := begin convert findim_eq_dim K V, rw h, norm_cast end variables (K V) lemma finite_dimensional_bot : finite_dimensional K (⊥ : submodule K V) := finite_dimensional_of_dim_eq_zero $ by simp lemma findim_bot : findim K (⊥ : submodule K V) = 0 := begin haveI := finite_dimensional_bot K V, convert findim_eq_dim K (⊥ : submodule K V), rw dim_bot, norm_cast end variables {K V} lemma bot_eq_top_of_dim_eq_zero (h : vector_space.dim K V = 0) : (⊥ : submodule K V) = ⊤ := begin haveI := finite_dimensional_of_dim_eq_zero h, apply eq_top_of_findim_eq, rw [findim_bot, findim_eq_zero_of_dim_eq_zero h] end end zero_dim
abe15ef5e88b306edc3af13e132f0530999b2145
432d948a4d3d242fdfb44b81c9e1b1baacd58617
/src/group_theory/coset.lean
ec164bb12d610b1db5c6183e6e53f5947b0858c9
[ "Apache-2.0" ]
permissive
JLimperg/aesop3
306cc6570c556568897ed2e508c8869667252e8a
a4a116f650cc7403428e72bd2e2c4cda300fe03f
refs/heads/master
1,682,884,916,368
1,620,320,033,000
1,620,320,033,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
14,991
lean
/- Copyright (c) 2018 Mitchell Rowett. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mitchell Rowett, Scott Morrison -/ import group_theory.subgroup /-! # Cosets This file develops the basic theory of left and right cosets. ## Main definitions * `left_coset a s`: the left coset `a * s` for an element `a : α` and a subset `s ⊆ α`, for an `add_group` this is `left_add_coset a s`. * `right_coset s a`: the right coset `s * a` for an element `a : α` and a subset `s ⊆ α`, for an `add_group` this is `right_add_coset s a`. * `quotient_group.quotient s`: the quotient type representing the left cosets with respect to a subgroup `s`, for an `add_group` this is `quotient_add_group.quotient s`. * `quotient_group.mk`: the canonical map from `α` to `α/s` for a subgroup `s` of `α`, for an `add_group` this is `quotient_add_group.mk`. * `subgroup.left_coset_equiv_subgroup`: the natural bijection between a left coset and the subgroup, for an `add_group` this is `add_subgroup.left_coset_equiv_add_subgroup`. ## Notation * `a *l s`: for `left_coset a s`. * `a +l s`: for `left_add_coset a s`. * `s *r a`: for `right_coset s a`. * `s +r a`: for `right_add_coset s a`. ## TODO Add `to_additive` to `preimage_mk_equiv_subgroup_times_set`. -/ open set function variable {α : Type*} /-- The left coset `a * s` for an element `a : α` and a subset `s : set α` -/ @[to_additive left_add_coset "The left coset `a+s` for an element `a : α` and a subset `s : set α`"] def left_coset [has_mul α] (a : α) (s : set α) : set α := (λ x, a * x) '' s /-- The right coset `s * a` for an element `a : α` and a subset `s : set α` -/ @[to_additive right_add_coset "The right coset `s+a` for an element `a : α` and a subset `s : set α`"] def right_coset [has_mul α] (s : set α) (a : α) : set α := (λ x, x * a) '' s localized "infix ` *l `:70 := left_coset" in coset localized "infix ` +l `:70 := left_add_coset" in coset localized "infix ` *r `:70 := right_coset" in coset localized "infix ` +r `:70 := right_add_coset" in coset section coset_mul variable [has_mul α] @[to_additive mem_left_add_coset] lemma mem_left_coset {s : set α} {x : α} (a : α) (hxS : x ∈ s) : a * x ∈ a *l s := mem_image_of_mem (λ b : α, a * b) hxS @[to_additive mem_right_add_coset] lemma mem_right_coset {s : set α} {x : α} (a : α) (hxS : x ∈ s) : x * a ∈ s *r a := mem_image_of_mem (λ b : α, b * a) hxS /-- Equality of two left cosets `a * s` and `b * s`. -/ @[to_additive left_add_coset_equivalence "Equality of two left cosets `a + s` and `b + s`."] def left_coset_equivalence (s : set α) (a b : α) := a *l s = b *l s @[to_additive left_add_coset_equivalence_rel] lemma left_coset_equivalence_rel (s : set α) : equivalence (left_coset_equivalence s) := mk_equivalence (left_coset_equivalence s) (λ a, rfl) (λ a b, eq.symm) (λ a b c, eq.trans) /-- Equality of two right cosets `s * a` and `s * b`. -/ @[to_additive right_add_coset_equivalence "Equality of two right cosets `s + a` and `s + b`."] def right_coset_equivalence (s : set α) (a b : α) := s *r a = s *r b @[to_additive right_add_coset_equivalence_rel] lemma right_coset_equivalence_rel (s : set α) : equivalence (right_coset_equivalence s) := mk_equivalence (right_coset_equivalence s) (λ a, rfl) (λ a b, eq.symm) (λ a b c, eq.trans) end coset_mul section coset_semigroup variable [semigroup α] @[simp] lemma left_coset_assoc (s : set α) (a b : α) : a *l (b *l s) = (a * b) *l s := by simp [left_coset, right_coset, (image_comp _ _ _).symm, function.comp, mul_assoc] attribute [to_additive left_add_coset_assoc] left_coset_assoc @[simp] lemma right_coset_assoc (s : set α) (a b : α) : s *r a *r b = s *r (a * b) := by simp [left_coset, right_coset, (image_comp _ _ _).symm, function.comp, mul_assoc] attribute [to_additive right_add_coset_assoc] right_coset_assoc @[to_additive left_add_coset_right_add_coset] lemma left_coset_right_coset (s : set α) (a b : α) : a *l s *r b = a *l (s *r b) := by simp [left_coset, right_coset, (image_comp _ _ _).symm, function.comp, mul_assoc] end coset_semigroup section coset_monoid variables [monoid α] (s : set α) @[simp] lemma one_left_coset : 1 *l s = s := set.ext $ by simp [left_coset] attribute [to_additive zero_left_add_coset] one_left_coset @[simp] lemma right_coset_one : s *r 1 = s := set.ext $ by simp [right_coset] attribute [to_additive right_add_coset_zero] right_coset_one end coset_monoid section coset_submonoid open submonoid variables [monoid α] (s : submonoid α) @[to_additive mem_own_left_add_coset] lemma mem_own_left_coset (a : α) : a ∈ a *l s := suffices a * 1 ∈ a *l s, by simpa, mem_left_coset a (one_mem s) @[to_additive mem_own_right_add_coset] lemma mem_own_right_coset (a : α) : a ∈ (s : set α) *r a := suffices 1 * a ∈ (s : set α) *r a, by simpa, mem_right_coset a (one_mem s) @[to_additive mem_left_add_coset_left_add_coset] lemma mem_left_coset_left_coset {a : α} (ha : a *l s = s) : a ∈ s := by rw [←set_like.mem_coe, ←ha]; exact mem_own_left_coset s a @[to_additive mem_right_add_coset_right_add_coset] lemma mem_right_coset_right_coset {a : α} (ha : (s : set α) *r a = s) : a ∈ s := by rw [←set_like.mem_coe, ←ha]; exact mem_own_right_coset s a end coset_submonoid section coset_group variables [group α] {s : set α} {x : α} @[to_additive mem_left_add_coset_iff] lemma mem_left_coset_iff (a : α) : x ∈ a *l s ↔ a⁻¹ * x ∈ s := iff.intro (assume ⟨b, hb, eq⟩, by simp [eq.symm, hb]) (assume h, ⟨a⁻¹ * x, h, by simp⟩) @[to_additive mem_right_add_coset_iff] lemma mem_right_coset_iff (a : α) : x ∈ s *r a ↔ x * a⁻¹ ∈ s := iff.intro (assume ⟨b, hb, eq⟩, by simp [eq.symm, hb]) (assume h, ⟨x * a⁻¹, h, by simp⟩) end coset_group section coset_subgroup open subgroup variables [group α] (s : subgroup α) @[to_additive left_add_coset_mem_left_add_coset] lemma left_coset_mem_left_coset {a : α} (ha : a ∈ s) : a *l s = s := set.ext $ by simp [mem_left_coset_iff, mul_mem_cancel_left s (s.inv_mem ha)] @[to_additive right_add_coset_mem_right_add_coset] lemma right_coset_mem_right_coset {a : α} (ha : a ∈ s) : (s : set α) *r a = s := set.ext $ assume b, by simp [mem_right_coset_iff, mul_mem_cancel_right s (s.inv_mem ha)] @[to_additive eq_add_cosets_of_normal] theorem eq_cosets_of_normal (N : s.normal) (g : α) : g *l s = s *r g := set.ext $ assume a, by simp [mem_left_coset_iff, mem_right_coset_iff]; rw [N.mem_comm_iff] @[to_additive normal_of_eq_add_cosets] theorem normal_of_eq_cosets (h : ∀ g : α, g *l s = s *r g) : s.normal := ⟨assume a ha g, show g * a * g⁻¹ ∈ (s : set α), by rw [← mem_right_coset_iff, ← h]; exact mem_left_coset g ha⟩ @[to_additive normal_iff_eq_add_cosets] theorem normal_iff_eq_cosets : s.normal ↔ ∀ g : α, g *l s = s *r g := ⟨@eq_cosets_of_normal _ _ s, normal_of_eq_cosets s⟩ end coset_subgroup run_cmd to_additive.map_namespace `quotient_group `quotient_add_group namespace quotient_group /-- The equivalence relation corresponding to the partition of a group by left cosets of a subgroup.-/ @[to_additive "The equivalence relation corresponding to the partition of a group by left cosets of a subgroup."] def left_rel [group α] (s : subgroup α) : setoid α := ⟨λ x y, x⁻¹ * y ∈ s, assume x, by simp [s.one_mem], assume x y hxy, have (x⁻¹ * y)⁻¹ ∈ s, from s.inv_mem hxy, by simpa using this, assume x y z hxy hyz, have x⁻¹ * y * (y⁻¹ * z) ∈ s, from s.mul_mem hxy hyz, by simpa [mul_assoc] using this⟩ @[to_additive] instance left_rel_decidable [group α] (s : subgroup α) [d : decidable_pred (λ a, a ∈ s)] : decidable_rel (left_rel s).r := λ _ _, d _ /-- `quotient s` is the quotient type representing the left cosets of `s`. If `s` is a normal subgroup, `quotient s` is a group -/ def quotient [group α] (s : subgroup α) : Type* := quotient (left_rel s) /-- The equivalence relation corresponding to the partition of a group by right cosets of a subgroup. -/ @[to_additive "The equivalence relation corresponding to the partition of a group by right cosets of a subgroup."] def right_rel [group α] (s : subgroup α) : setoid α := ⟨λ x y, y * x⁻¹ ∈ s, assume x, by simp [s.one_mem], assume x y hxy, have (y * x⁻¹)⁻¹ ∈ s, from s.inv_mem hxy, by simpa using this, assume x y z hxy hyz, have (z * y⁻¹) * (y * x⁻¹) ∈ s, from s.mul_mem hyz hxy, by simpa [mul_assoc] using this⟩ @[to_additive] instance right_rel_decidable [group α] (s : subgroup α) [d : decidable_pred (λ a, a ∈ s)] : decidable_rel (left_rel s).r := λ _ _, d _ end quotient_group namespace quotient_add_group /-- `quotient s` is the quotient type representing the left cosets of `s`. If `s` is a normal subgroup, `quotient s` is a group -/ def quotient [add_group α] (s : add_subgroup α) : Type* := quotient (left_rel s) end quotient_add_group attribute [to_additive quotient_add_group.quotient] quotient_group.quotient namespace quotient_group variables [group α] {s : subgroup α} @[to_additive] instance fintype [fintype α] (s : subgroup α) [decidable_rel (left_rel s).r] : fintype (quotient_group.quotient s) := quotient.fintype (left_rel s) /-- The canonical map from a group `α` to the quotient `α/s`. -/ @[to_additive "The canonical map from an `add_group` `α` to the quotient `α/s`."] abbreviation mk (a : α) : quotient s := quotient.mk' a @[elab_as_eliminator, to_additive] lemma induction_on {C : quotient s → Prop} (x : quotient s) (H : ∀ z, C (quotient_group.mk z)) : C x := quotient.induction_on' x H @[to_additive] instance : has_coe_t α (quotient s) := ⟨mk⟩ -- note [use has_coe_t] @[elab_as_eliminator, to_additive] lemma induction_on' {C : quotient s → Prop} (x : quotient s) (H : ∀ z : α, C z) : C x := quotient.induction_on' x H @[to_additive] instance (s : subgroup α) : inhabited (quotient s) := ⟨((1 : α) : quotient s)⟩ @[to_additive quotient_add_group.eq] protected lemma eq {a b : α} : (a : quotient s) = b ↔ a⁻¹ * b ∈ s := quotient.eq' @[to_additive] lemma eq_class_eq_left_coset (s : subgroup α) (g : α) : {x : α | (x : quotient s) = g} = left_coset g s := set.ext $ λ z, by { rw [mem_left_coset_iff, set.mem_set_of_eq, eq_comm, quotient_group.eq], simp } @[to_additive] lemma preimage_image_coe (N : subgroup α) (s : set α) : coe ⁻¹' ((coe : α → quotient N) '' s) = ⋃ x : N, (λ y : α, y * x) '' s := begin ext x, simp only [quotient_group.eq, set_like.exists, exists_prop, set.mem_preimage, set.mem_Union, set.mem_image, subgroup.coe_mk, ← eq_inv_mul_iff_mul_eq], exact ⟨λ ⟨y, hs, hN⟩, ⟨_, hN, y, hs, rfl⟩, λ ⟨z, hN, y, hs, hyz⟩, ⟨y, hs, hyz ▸ hN⟩⟩ end end quotient_group namespace subgroup open quotient_group variables [group α] {s : subgroup α} /-- The natural bijection between a left coset `g * s` and `s`. -/ @[to_additive "The natural bijection between the cosets `g + s` and `s`."] def left_coset_equiv_subgroup (g : α) : left_coset g s ≃ s := ⟨λ x, ⟨g⁻¹ * x.1, (mem_left_coset_iff _).1 x.2⟩, λ x, ⟨g * x.1, x.1, x.2, rfl⟩, λ ⟨x, hx⟩, subtype.eq $ by simp, λ ⟨g, hg⟩, subtype.eq $ by simp⟩ /-- The natural bijection between a right coset `s * g` and `s`. -/ @[to_additive "The natural bijection between the cosets `s + g` and `s`."] def right_coset_equiv_subgroup (g : α) : right_coset ↑s g ≃ s := ⟨λ x, ⟨x.1 * g⁻¹, (mem_right_coset_iff _).1 x.2⟩, λ x, ⟨x.1 * g, x.1, x.2, rfl⟩, λ ⟨x, hx⟩, subtype.eq $ by simp, λ ⟨g, hg⟩, subtype.eq $ by simp⟩ /-- A (non-canonical) bijection between a group `α` and the product `(α/s) × s` -/ @[to_additive "A (non-canonical) bijection between an add_group `α` and the product `(α/s) × s`"] noncomputable def group_equiv_quotient_times_subgroup : α ≃ quotient s × s := calc α ≃ Σ L : quotient s, {x : α // (x : quotient s) = L} : (equiv.sigma_preimage_equiv quotient_group.mk).symm ... ≃ Σ L : quotient s, left_coset (quotient.out' L) s : equiv.sigma_congr_right (λ L, begin rw ← eq_class_eq_left_coset, show _root_.subtype (λ x : α, quotient.mk' x = L) ≃ _root_.subtype (λ x : α, quotient.mk' x = quotient.mk' _), simp [-quotient.eq'], end) ... ≃ Σ L : quotient s, s : equiv.sigma_congr_right (λ L, left_coset_equiv_subgroup _) ... ≃ quotient s × s : equiv.sigma_equiv_prod _ _ lemma card_eq_card_quotient_mul_card_subgroup [fintype α] (s : subgroup α) [fintype s] [decidable_pred (λ a, a ∈ s)] : fintype.card α = fintype.card (quotient s) * fintype.card s := by rw ← fintype.card_prod; exact fintype.card_congr (subgroup.group_equiv_quotient_times_subgroup) lemma card_subgroup_dvd_card [fintype α] (s : subgroup α) [fintype s] : fintype.card s ∣ fintype.card α := by haveI := classical.prop_decidable; simp [card_eq_card_quotient_mul_card_subgroup s] lemma card_quotient_dvd_card [fintype α] (s : subgroup α) [decidable_pred (λ a, a ∈ s)] [fintype s] : fintype.card (quotient s) ∣ fintype.card α := by simp [card_eq_card_quotient_mul_card_subgroup s] end subgroup namespace quotient_group variables [group α] -- FIXME -- why is there no `to_additive`? /-- If `s` is a subgroup of the group `α`, and `t` is a subset of `α/s`, then there is a (typically non-canonical) bijection between the preimage of `t` in `α` and the product `s × t`. -/ noncomputable def preimage_mk_equiv_subgroup_times_set (s : subgroup α) (t : set (quotient s)) : quotient_group.mk ⁻¹' t ≃ s × t := have h : ∀ {x : quotient s} {a : α}, x ∈ t → a ∈ s → (quotient.mk' (quotient.out' x * a) : quotient s) = quotient.mk' (quotient.out' x) := λ x a hx ha, quotient.sound' (show (quotient.out' x * a)⁻¹ * quotient.out' x ∈ s, from (s.inv_mem_iff).1 $ by rwa [mul_inv_rev, inv_inv, ← mul_assoc, inv_mul_self, one_mul]), { to_fun := λ ⟨a, ha⟩, ⟨⟨(quotient.out' (quotient.mk' a))⁻¹ * a, @quotient.exact' _ (left_rel s) _ _ $ (quotient.out_eq' _)⟩, ⟨quotient.mk' a, ha⟩⟩, inv_fun := λ ⟨⟨a, ha⟩, ⟨x, hx⟩⟩, ⟨quotient.out' x * a, show quotient.mk' _ ∈ t, by simp [h hx ha, hx]⟩, left_inv := λ ⟨a, ha⟩, subtype.eq $ show _ * _ = a, by simp, right_inv := λ ⟨⟨a, ha⟩, ⟨x, hx⟩⟩, show (_, _) = _, by simp [h hx ha] } end quotient_group /-- We use the class `has_coe_t` instead of `has_coe` if the first argument is a variable, or if the second argument is a variable not occurring in the first. Using `has_coe` would cause looping of type-class inference. See <https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/remove.20all.20instances.20with.20variable.20domain> -/ library_note "use has_coe_t"
5dd9f92dc01edbe1456295c7255a0a15c97b70fd
88892181780ff536a81e794003fe058062f06758
/src/100_theorems/t071.lean
05ef325f77027d4f87a658c68d839357efe562bc
[]
no_license
AtnNn/lean-sandbox
fe2c44280444e8bb8146ab8ac391c82b480c0a2e
8c68afbdc09213173aef1be195da7a9a86060a97
refs/heads/master
1,623,004,395,876
1,579,969,507,000
1,579,969,507,000
146,666,368
0
0
null
null
null
null
UTF-8
Lean
false
false
238
lean
import group_theory.order_of_element -- Order of a Subgroup theorem t071 {α : Type*} [group α] [fintype α] [decidable_eq α] (s : set α) [is_subgroup s] [fintype s] : fintype.card s ∣ fintype.card α := card_subgroup_dvd_card s
3e9de6ab0842612bd332e2e4a5eb0efa81ee7187
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/run/atomic2.lean
dd0a96c4b0a67e7d30a58068c1547fa64f949b96
[ "Apache-2.0" ]
permissive
leanprover-community/lean
12b87f69d92e614daea8bcc9d4de9a9ace089d0e
cce7990ea86a78bdb383e38ed7f9b5ba93c60ce0
refs/heads/master
1,687,508,156,644
1,684,951,104,000
1,684,951,104,000
169,960,991
457
107
Apache-2.0
1,686,744,372,000
1,549,790,268,000
C++
UTF-8
Lean
false
false
85
lean
notation `foo` := Type.{1} constant f : Type* → Type* #check foo → f foo → foo
fe405c4c2f88bb3dd8a42da17263f7d56673538b
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/linear_algebra/special_linear_group.lean
b7680634376169645772f911dc281f6dd076f1fa
[ "Apache-2.0" ]
permissive
jjgarzella/mathlib
96a345378c4e0bf26cf604aed84f90329e4896a2
395d8716c3ad03747059d482090e2bb97db612c8
refs/heads/master
1,686,480,124,379
1,625,163,323,000
1,625,163,323,000
281,190,421
2
0
Apache-2.0
1,595,268,170,000
1,595,268,169,000
null
UTF-8
Lean
false
false
5,732
lean
/- Copyright (c) 2020 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen The Special Linear group $SL(n, R)$ -/ import linear_algebra.matrix.nonsingular_inverse import linear_algebra.matrix.to_lin /-! # The Special Linear group $SL(n, R)$ This file defines the elements of the Special Linear group `special_linear_group n R`, also written `SL(n, R)` or `SLₙ(R)`, consisting of all `n` by `n` `R`-matrices with determinant `1`. In addition, we define the group structure on `special_linear_group n R` and the embedding into the general linear group `general_linear_group R (n → R)` (i.e. `GL(n, R)` or `GLₙ(R)`). ## Main definitions * `matrix.special_linear_group` is the type of matrices with determinant 1 * `matrix.special_linear_group.group` gives the group structure (under multiplication) * `matrix.special_linear_group.embedding_GL` is the embedding `SLₙ(R) → GLₙ(R)` ## Implementation notes The inverse operation in the `special_linear_group` is defined to be the adjugate matrix, so that `special_linear_group n R` has a group structure for all `comm_ring R`. We define the elements of `special_linear_group` to be matrices, since we need to compute their determinant. This is in contrast with `general_linear_group R M`, which consists of invertible `R`-linear maps on `M`. ## References * https://en.wikipedia.org/wiki/Special_linear_group ## Tags matrix group, group, matrix inverse -/ namespace matrix universes u v open_locale matrix open linear_map section variables (n : Type u) [decidable_eq n] [fintype n] (R : Type v) [comm_ring R] /-- `special_linear_group n R` is the group of `n` by `n` `R`-matrices with determinant equal to 1. -/ def special_linear_group := { A : matrix n n R // A.det = 1 } end namespace special_linear_group variables {n : Type u} [decidable_eq n] [fintype n] {R : Type v} [comm_ring R] instance coe_matrix : has_coe (special_linear_group n R) (matrix n n R) := ⟨λ A, A.val⟩ instance coe_fun : has_coe_to_fun (special_linear_group n R) := { F := λ _, n → n → R, coe := λ A, A.val } /-- `to_lin' A` is matrix multiplication of vectors by `A`, as a linear map. After the group structure on `special_linear_group n R` is defined, we show in `to_linear_equiv` that this gives a linear equivalence. -/ def to_lin' (A : special_linear_group n R) := matrix.to_lin' A lemma ext_iff (A B : special_linear_group n R) : A = B ↔ (∀ i j, A i j = B i j) := iff.trans subtype.ext_iff_val ⟨(λ h i j, congr_fun (congr_fun h i) j), matrix.ext⟩ @[ext] lemma ext (A B : special_linear_group n R) : (∀ i j, A i j = B i j) → A = B := (special_linear_group.ext_iff A B).mpr instance has_inv : has_inv (special_linear_group n R) := ⟨λ A, ⟨adjugate A, det_adjugate_eq_one A.2⟩⟩ instance has_mul : has_mul (special_linear_group n R) := ⟨λ A B, ⟨A.1 ⬝ B.1, by erw [det_mul, A.2, B.2, one_mul]⟩⟩ instance has_one : has_one (special_linear_group n R) := ⟨⟨1, det_one⟩⟩ instance : inhabited (special_linear_group n R) := ⟨1⟩ section coe_lemmas variables (A B : special_linear_group n R) @[simp] lemma inv_val : ↑(A⁻¹) = adjugate A := rfl @[simp] lemma inv_apply : ⇑(A⁻¹) = adjugate A := rfl @[simp] lemma mul_val : ↑(A * B) = A ⬝ B := rfl @[simp] lemma mul_apply : ⇑(A * B) = (A ⬝ B) := rfl @[simp] lemma one_val : ↑(1 : special_linear_group n R) = (1 : matrix n n R) := rfl @[simp] lemma one_apply : ⇑(1 : special_linear_group n R) = (1 : matrix n n R) := rfl @[simp] lemma det_coe_matrix : det A = 1 := A.2 lemma det_coe_fun : det ⇑A = 1 := A.2 @[simp] lemma to_lin'_mul : to_lin' (A * B) = (to_lin' A).comp (to_lin' B) := matrix.to_lin'_mul A B @[simp] lemma to_lin'_one : to_lin' (1 : special_linear_group n R) = linear_map.id := matrix.to_lin'_one end coe_lemmas instance group : group (special_linear_group n R) := { mul_assoc := λ A B C, by { ext, simp [matrix.mul_assoc] }, one_mul := λ A, by { ext, simp }, mul_one := λ A, by { ext, simp }, mul_left_inv := λ A, by { ext, simp [adjugate_mul] }, ..special_linear_group.has_mul, ..special_linear_group.has_one, ..special_linear_group.has_inv } /-- `to_linear_equiv A` is matrix multiplication of vectors by `A`, as a linear equivalence. -/ def to_linear_equiv (A : special_linear_group n R) : (n → R) ≃ₗ[R] (n → R) := { inv_fun := A⁻¹.to_lin', left_inv := λ x, calc A⁻¹.to_lin'.comp A.to_lin' x = (A⁻¹ * A).to_lin' x : by rw [←to_lin'_mul] ... = x : by rw [mul_left_inv, to_lin'_one, id_apply], right_inv := λ x, calc A.to_lin'.comp A⁻¹.to_lin' x = (A * A⁻¹).to_lin' x : by rw [←to_lin'_mul] ... = x : by rw [mul_right_inv, to_lin'_one, id_apply], ..matrix.to_lin' A } /-- `to_GL` is the map from the special linear group to the general linear group -/ def to_GL (A : special_linear_group n R) : general_linear_group R (n → R) := general_linear_group.of_linear_equiv (to_linear_equiv A) lemma coe_to_GL (A : special_linear_group n R) : (@coe (units _) _ _ (to_GL A)) = A.to_lin' := rfl @[simp] lemma to_GL_one : to_GL (1 : special_linear_group n R) = 1 := by { ext v i, rw [coe_to_GL, to_lin'_one], refl } @[simp] lemma to_GL_mul (A B : special_linear_group n R) : to_GL (A * B) = to_GL A * to_GL B := by { ext v i, rw [coe_to_GL, to_lin'_mul], refl } /-- `special_linear_group.embedding_GL` is the embedding from `special_linear_group n R` to `general_linear_group n R`. -/ def embedding_GL : (special_linear_group n R) →* (general_linear_group R (n → R)) := ⟨λ A, to_GL A, by simp, by simp⟩ end special_linear_group end matrix
15c45333c967b80e44cd3777f99c78ca240b3001
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
/src/data/W/basic.lean
0497c344008020ee71a4a964e3c66e3b70b38fb5
[ "Apache-2.0" ]
permissive
AntoineChambert-Loir/mathlib
64aabb896129885f12296a799818061bc90da1ff
07be904260ab6e36a5769680b6012f03a4727134
refs/heads/master
1,693,187,631,771
1,636,719,886,000
1,636,719,886,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
6,808
lean
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import data.equiv.list /-! # W types Given `α : Type` and `β : α → Type`, the W type determined by this data, `W_type β`, is the inductively defined type of trees where the nodes are labeled by elements of `α` and the children of a node labeled `a` are indexed by elements of `β a`. This file is currently a stub, awaiting a full development of the theory. Currently, the main result is that if `α` is an encodable fintype and `β a` is encodable for every `a : α`, then `W_type β` is encodable. This can be used to show the encodability of other inductive types, such as those that are commonly used to formalize syntax, e.g. terms and expressions in a given language. The strategy is illustrated in the example found in the file `prop_encodable` in the `archive/examples` folder of mathlib. ## Implementation details While the name `W_type` is somewhat verbose, it is preferable to putting a single character identifier `W` in the root namespace. -/ /-- Given `β : α → Type*`, `W_type β` is the type of finitely branching trees where nodes are labeled by elements of `α` and the children of a node labeled `a` are indexed by elements of `β a`. -/ inductive W_type {α : Type*} (β : α → Type*) | mk (a : α) (f : β a → W_type) : W_type instance : inhabited (W_type (λ (_ : unit), empty)) := ⟨W_type.mk unit.star empty.elim⟩ namespace W_type variables {α : Type*} {β : α → Type*} /-- The canonical map to the corresponding sigma type, returning the label of a node as an element `a` of `α`, and the children of the node as a function `β a → W_type β`. -/ def to_sigma : W_type β → Σ a : α, β a → W_type β | ⟨a, f⟩ := ⟨a, f⟩ /-- The canonical map from the sigma type into a `W_type`. Given a node `a : α`, and its children as a function `β a → W_type β`, return the corresponding tree. -/ def of_sigma : (Σ a : α, β a → W_type β) → W_type β | ⟨a, f⟩ := W_type.mk a f @[simp] lemma of_sigma_to_sigma : Π (w : W_type β), of_sigma (to_sigma w) = w | ⟨a, f⟩ := rfl @[simp] lemma to_sigma_of_sigma : Π (s : Σ a : α, β a → W_type β), to_sigma (of_sigma s) = s | ⟨a, f⟩ := rfl variable (β) /-- The canonical bijection with the sigma type, showing that `W_type` is a fixed point of the polynomial `Σ a : α, β a → W_type β`. -/ @[simps] def equiv_sigma : W_type β ≃ Σ a : α, β a → W_type β := { to_fun := to_sigma, inv_fun := of_sigma, left_inv := of_sigma_to_sigma, right_inv := to_sigma_of_sigma } variable {β} /-- The canonical map from `W_type β` into any type `γ` given a map `(Σ a : α, β a → γ) → γ`. -/ def elim (γ : Type*) (fγ : (Σ a : α, β a → γ) → γ) : W_type β → γ | ⟨a, f⟩ := fγ ⟨a, λ b, elim (f b)⟩ lemma elim_injective (γ : Type*) (fγ : (Σ a : α, β a → γ) → γ) (fγ_injective : function.injective fγ) : function.injective (elim γ fγ) | ⟨a₁, f₁⟩ ⟨a₂, f₂⟩ h := begin obtain ⟨rfl, h⟩ := sigma.mk.inj (fγ_injective h), congr' with x, exact elim_injective (congr_fun (eq_of_heq h) x : _), end instance [hα : is_empty α] : is_empty (W_type β) := ⟨λ w, W_type.rec_on w (is_empty.elim hα)⟩ lemma infinite_of_nonempty_of_is_empty (a b : α) [ha : nonempty (β a)] [he : is_empty (β b)] : infinite (W_type β) := ⟨begin introsI hf, have hba : b ≠ a, from λ h, ha.elim (is_empty.elim' (show is_empty (β a), from h ▸ he)), refine not_injective_infinite_fintype (λ n : ℕ, show W_type β, from nat.rec_on n ⟨b, is_empty.elim' he⟩ (λ n ih, ⟨a, λ _, ih⟩)) _, intros n m h, induction n with n ih generalizing m h, { cases m with m; simp * at * }, { cases m with m, { simp * at * }, { refine congr_arg nat.succ (ih _), simp [function.funext_iff, *] at * } } end⟩ variables [Π a : α, fintype (β a)] /-- The depth of a finitely branching tree. -/ def depth : W_type β → ℕ | ⟨a, f⟩ := finset.sup finset.univ (λ n, depth (f n)) + 1 lemma depth_pos (t : W_type β) : 0 < t.depth := by { cases t, apply nat.succ_pos } lemma depth_lt_depth_mk (a : α) (f : β a → W_type β) (i : β a) : depth (f i) < depth ⟨a, f⟩ := nat.lt_succ_of_le (finset.le_sup (finset.mem_univ i)) end W_type /- Show that W types are encodable when `α` is an encodable fintype and for every `a : α`, `β a` is encodable. We define an auxiliary type `W_type' β n` of trees of depth at most `n`, and then we show by induction on `n` that these are all encodable. These auxiliary constructions are not interesting in and of themselves, so we mark them as `private`. -/ namespace encodable @[reducible] private def W_type' {α : Type*} (β : α → Type*) [Π a : α, fintype (β a)] [Π a : α, encodable (β a)] (n : ℕ) := { t : W_type β // t.depth ≤ n} variables {α : Type*} {β : α → Type*} [Π a : α, fintype (β a)] [Π a : α, encodable (β a)] private def encodable_zero : encodable (W_type' β 0) := let f : W_type' β 0 → empty := λ ⟨x, h⟩, false.elim $ not_lt_of_ge h (W_type.depth_pos _), finv : empty → W_type' β 0 := by { intro x, cases x} in have ∀ x, finv (f x) = x, from λ ⟨x, h⟩, false.elim $ not_lt_of_ge h (W_type.depth_pos _), encodable.of_left_inverse f finv this private def f (n : ℕ) : W_type' β (n + 1) → Σ a : α, β a → W_type' β n | ⟨t, h⟩ := begin cases t with a f, have h₀ : ∀ i : β a, W_type.depth (f i) ≤ n, from λ i, nat.le_of_lt_succ (lt_of_lt_of_le (W_type.depth_lt_depth_mk a f i) h), exact ⟨a, λ i : β a, ⟨f i, h₀ i⟩⟩ end private def finv (n : ℕ) : (Σ a : α, β a → W_type' β n) → W_type' β (n + 1) | ⟨a, f⟩ := let f' := λ i : β a, (f i).val in have W_type.depth ⟨a, f'⟩ ≤ n + 1, from add_le_add_right (finset.sup_le (λ b h, (f b).2)) 1, ⟨⟨a, f'⟩, this⟩ variables [encodable α] private def encodable_succ (n : nat) (h : encodable (W_type' β n)) : encodable (W_type' β (n + 1)) := encodable.of_left_inverse (f n) (finv n) (by { rintro ⟨⟨_, _⟩, _⟩, refl }) /-- `W_type` is encodable when `α` is an encodable fintype and for every `a : α`, `β a` is encodable. -/ instance : encodable (W_type β) := begin haveI h' : Π n, encodable (W_type' β n) := λ n, nat.rec_on n encodable_zero encodable_succ, let f : W_type β → Σ n, W_type' β n := λ t, ⟨t.depth, ⟨t, le_refl _⟩⟩, let finv : (Σ n, W_type' β n) → W_type β := λ p, p.2.1, have : ∀ t, finv (f t) = t, from λ t, rfl, exact encodable.of_left_inverse f finv this end end encodable
b9d21d4d02d4e1fbea88a1aa2fc9e7051fc4a3d5
a4673261e60b025e2c8c825dfa4ab9108246c32e
/tests/lean/run/catchThe.lean
0c90f08c61f6ed81bc68e02d432d6d2c55081eb5
[ "Apache-2.0" ]
permissive
jcommelin/lean4
c02dec0cc32c4bccab009285475f265f17d73228
2909313475588cc20ac0436e55548a4502050d0a
refs/heads/master
1,674,129,550,893
1,606,415,348,000
1,606,415,348,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
818
lean
import Lean.Meta open Lean open Lean.Meta universes u v w abbrev M := ExceptT String $ MetaM def testM {α} [BEq α] [ToString α] (x : M α) (expected : α) : MetaM Unit := do let r ← x; match r with | Except.ok a => unless a == expected do throwError m!"unexpected result {a}" | Except.error e => throwError m!"FAILED: {e}" @[noinline] def act1 : M Nat := throwThe Exception $ Exception.error Syntax.missing "Error at act1" def g1 : M Nat := tryCatchThe Exception (tryCatch act1 (fun ex => pure 100)) (fun ex => pure 200) #eval testM g1 200 @[noinline] def act2 : M Nat := throw "hello world" def g2 : M Nat := tryCatchThe Exception (tryCatch act2 (fun ex => pure 100)) (fun ex => pure 200) #eval testM g2 100 def h1 : CoreM Nat := pure 10 #eval h1 def h2 : MetaM Nat := pure 20 #eval h2
d677a0f8b3909c7d601207b7f7b551d9409ccde3
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/control/traversable/instances.lean
18bd514d9a37c0fa9f7ab1c1b6adbb315d4c4e0c
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
5,580
lean
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon -/ import control.applicative import data.list.forall2 import data.set.functor /-! # Traversable instances > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file provides instances of `traversable` for types from the core library: `option`, `list` and `sum`. -/ universes u v section option open functor variables {F G : Type u → Type u} variables [applicative F] [applicative G] variables [is_lawful_applicative F] [is_lawful_applicative G] lemma option.id_traverse {α} (x : option α) : option.traverse id.mk x = x := by cases x; refl @[nolint unused_arguments] lemma option.comp_traverse {α β γ} (f : β → F γ) (g : α → G β) (x : option α) : option.traverse (comp.mk ∘ (<$>) f ∘ g) x = comp.mk (option.traverse f <$> option.traverse g x) := by cases x; simp! with functor_norm; refl lemma option.traverse_eq_map_id {α β} (f : α → β) (x : option α) : traverse (id.mk ∘ f) x = id.mk (f <$> x) := by cases x; refl variable (η : applicative_transformation F G) lemma option.naturality {α β} (f : α → F β) (x : option α) : η (option.traverse f x) = option.traverse (@η _ ∘ f) x := by cases x with x; simp! [*] with functor_norm end option instance : is_lawful_traversable option := { id_traverse := @option.id_traverse, comp_traverse := @option.comp_traverse, traverse_eq_map_id := @option.traverse_eq_map_id, naturality := @option.naturality, .. option.is_lawful_monad } namespace list variables {F G : Type u → Type u} variables [applicative F] [applicative G] section variables [is_lawful_applicative F] [is_lawful_applicative G] open applicative functor list protected lemma id_traverse {α} (xs : list α) : list.traverse id.mk xs = xs := by induction xs; simp! * with functor_norm; refl @[nolint unused_arguments] protected lemma comp_traverse {α β γ} (f : β → F γ) (g : α → G β) (x : list α) : list.traverse (comp.mk ∘ (<$>) f ∘ g) x = comp.mk (list.traverse f <$> list.traverse g x) := by induction x; simp! * with functor_norm; refl protected lemma traverse_eq_map_id {α β} (f : α → β) (x : list α) : list.traverse (id.mk ∘ f) x = id.mk (f <$> x) := by induction x; simp! * with functor_norm; refl variable (η : applicative_transformation F G) protected lemma naturality {α β} (f : α → F β) (x : list α) : η (list.traverse f x) = list.traverse (@η _ ∘ f) x := by induction x; simp! * with functor_norm open nat instance : is_lawful_traversable.{u} list := { id_traverse := @list.id_traverse, comp_traverse := @list.comp_traverse, traverse_eq_map_id := @list.traverse_eq_map_id, naturality := @list.naturality, .. list.is_lawful_monad } end section traverse variables {α' β' : Type u} (f : α' → F β') @[simp] lemma traverse_nil : traverse f ([] : list α') = (pure [] : F (list β')) := rfl @[simp] lemma traverse_cons (a : α') (l : list α') : traverse f (a :: l) = (::) <$> f a <*> traverse f l := rfl variables [is_lawful_applicative F] @[simp] lemma traverse_append : ∀ (as bs : list α'), traverse f (as ++ bs) = (++) <$> traverse f as <*> traverse f bs | [] bs := have has_append.append ([] : list β') = id, by funext; refl, by simp [this] with functor_norm | (a :: as) bs := by simp [traverse_append as bs] with functor_norm; congr lemma mem_traverse {f : α' → set β'} : ∀(l : list α') (n : list β'), n ∈ traverse f l ↔ forall₂ (λb a, b ∈ f a) n l | [] [] := by simp | (a::as) [] := by simp | [] (b::bs) := by simp | (a::as) (b::bs) := by simp [mem_traverse as bs] end traverse end list namespace sum section traverse variables {σ : Type u} variables {F G : Type u → Type u} variables [applicative F] [applicative G] open applicative functor open list (cons) protected lemma traverse_map {α β γ : Type u} (g : α → β) (f : β → G γ) (x : σ ⊕ α) : sum.traverse f (g <$> x) = sum.traverse (f ∘ g) x := by cases x; simp [sum.traverse, id_map] with functor_norm; refl variables [is_lawful_applicative F] [is_lawful_applicative G] protected lemma id_traverse {σ α} (x : σ ⊕ α) : sum.traverse id.mk x = x := by cases x; refl @[nolint unused_arguments] protected lemma comp_traverse {α β γ} (f : β → F γ) (g : α → G β) (x : σ ⊕ α) : sum.traverse (comp.mk ∘ (<$>) f ∘ g) x = comp.mk (sum.traverse f <$> sum.traverse g x) := by cases x; simp! [sum.traverse,map_id] with functor_norm; refl protected lemma traverse_eq_map_id {α β} (f : α → β) (x : σ ⊕ α) : sum.traverse (id.mk ∘ f) x = id.mk (f <$> x) := by induction x; simp! * with functor_norm; refl protected lemma map_traverse {α β γ} (g : α → G β) (f : β → γ) (x : σ ⊕ α) : (<$>) f <$> sum.traverse g x = sum.traverse ((<$>) f ∘ g) x := by cases x; simp [sum.traverse, id_map] with functor_norm; congr; refl variable (η : applicative_transformation F G) protected lemma naturality {α β} (f : α → F β) (x : σ ⊕ α) : η (sum.traverse f x) = sum.traverse (@η _ ∘ f) x := by cases x; simp! [sum.traverse] with functor_norm end traverse instance {σ : Type u} : is_lawful_traversable.{u} (sum σ) := { id_traverse := @sum.id_traverse σ, comp_traverse := @sum.comp_traverse σ, traverse_eq_map_id := @sum.traverse_eq_map_id σ, naturality := @sum.naturality σ, .. sum.is_lawful_monad } end sum
6dec562a00b2ab9bf34ec8da454894deafebb524
37583bc2df4ea4f4e29b43ee1302f004c24cfa59
/tut2.lean
67c277d946cf7b226cae7de420d5d8ddd924910d
[ "MIT" ]
permissive
Vtec234/tpil-solutions
9cd8576953eb7ea34e5959878bf00f73b035ba4e
70c1b5c5e33a9c26296edb17cf828327d7f69842
refs/heads/master
1,585,389,330,863
1,540,413,754,000
1,540,413,754,000
148,069,811
1
0
null
null
null
null
UTF-8
Lean
false
false
1,621
lean
section ex1 -- merged do_twice and Do_Twice into one function using dependent type def do_twice: Π {α: Type}, ((α → α) → α → α) := λ α f x, f (f x) -- this is the same, just different notation def do_twice' {α: Type} (f: α → α): α → α := λ x, f (f x) def double: ℕ → ℕ := λ x, x+x #reduce do_twice do_twice' double 2 end ex1 section ex2 def curry {α β γ: Type} (f: α × β → γ): α → β → γ := λ a b, f (a, b) def uncurry {α β γ: Type} (f: α → β → γ): α × β → γ := λ pr, f pr.fst pr.snd def mult_two: ℕ → ℕ → ℕ := λ x y, x*y def mult_pair: (ℕ × ℕ) → ℕ := λ pr, pr.fst*pr.snd #reduce curry mult_pair 2 4 #reduce uncurry mult_two (3, 5) end ex2 namespace ex3 constant vec: Type → ℕ → Type constant vec_add {α: Type} {m: ℕ}: vec α m → vec α m → vec α m constant vec_reverse {α: Type} {m: ℕ}: vec α m → vec α m constant v: vec ℕ 3 #check vec_add v v #check vec_reverse v end ex3 namespace ex4 constant vec: Type → ℕ → Type constant matrix : Type → ℕ → ℕ → Type constant madd: Π {α: Type} {m n: ℕ}, matrix α m n → matrix α m n → matrix α m n constant mmul: Π {α: Type} {m n k: ℕ}, matrix α m n → matrix α n k → matrix α m k -- assume column vector and matrix on left, so m rows in answer constant mvmul: Π {α: Type} {m n: ℕ}, matrix α m n → vec α n → vec α m constant M: matrix ℕ 3 4 constant M': matrix ℕ 4 5 constant v: vec ℕ 4 #check madd M M #check mmul M M' #check mvmul M v end ex4
fb7e51c18f54c6ba734611875cdd921c0b2b60c5
63abd62053d479eae5abf4951554e1064a4c45b4
/src/order/lattice.lean
58b8376125ac6a71d1a1bca029a7cb64e5c82927
[ "Apache-2.0" ]
permissive
Lix0120/mathlib
0020745240315ed0e517cbf32e738d8f9811dd80
e14c37827456fc6707f31b4d1d16f1f3a3205e91
refs/heads/master
1,673,102,855,024
1,604,151,044,000
1,604,151,044,000
308,930,245
0
0
Apache-2.0
1,604,164,710,000
1,604,163,547,000
null
UTF-8
Lean
false
false
18,061
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 Defines the inf/sup (semi)-lattice with optionally top/bot type class hierarchy. -/ import order.rel_classes set_option old_structure_cmd true universes u v w variables {α : Type u} {β : Type v} -- TODO: move this eventually, if we decide to use them attribute [ematch] le_trans lt_of_le_of_lt lt_of_lt_of_le lt_trans section -- TODO: this seems crazy, but it also seems to work reasonably well @[ematch] theorem le_antisymm' [partial_order α] : ∀ {a b : α}, (: a ≤ b :) → b ≤ a → a = b := @le_antisymm _ _ end /- TODO: automatic construction of dual definitions / theorems -/ reserve infixl ` ⊓ `:70 reserve infixl ` ⊔ `:65 /-- Typeclass for the `⊔` (`\lub`) notation -/ class has_sup (α : Type u) := (sup : α → α → α) /-- Typeclass for the `⊓` (`\glb`) notation -/ class has_inf (α : Type u) := (inf : α → α → α) infix ⊔ := has_sup.sup infix ⊓ := has_inf.inf /-- A `semilattice_sup` is a join-semilattice, that is, a partial order with a join (a.k.a. lub / least upper bound, sup / supremum) operation `⊔` which is the least element larger than both factors. -/ class semilattice_sup (α : Type u) extends has_sup α, partial_order α := (le_sup_left : ∀ a b : α, a ≤ a ⊔ b) (le_sup_right : ∀ a b : α, b ≤ a ⊔ b) (sup_le : ∀ a b c : α, a ≤ c → b ≤ c → a ⊔ b ≤ c) instance (α : Type*) [has_inf α] : has_sup (order_dual α) := ⟨((⊓) : α → α → α)⟩ instance (α : Type*) [has_sup α] : has_inf (order_dual α) := ⟨((⊔) : α → α → α)⟩ section semilattice_sup variables [semilattice_sup α] {a b c d : α} @[simp] theorem le_sup_left : a ≤ a ⊔ b := semilattice_sup.le_sup_left a b @[ematch] theorem le_sup_left' : a ≤ (: a ⊔ b :) := le_sup_left @[simp] theorem le_sup_right : b ≤ a ⊔ b := semilattice_sup.le_sup_right a b @[ematch] theorem le_sup_right' : b ≤ (: a ⊔ b :) := le_sup_right theorem le_sup_left_of_le (h : c ≤ a) : c ≤ a ⊔ b := le_trans h le_sup_left theorem le_sup_right_of_le (h : c ≤ b) : c ≤ a ⊔ b := le_trans h le_sup_right theorem sup_le : a ≤ c → b ≤ c → a ⊔ b ≤ c := semilattice_sup.sup_le a b c @[simp] theorem sup_le_iff : a ⊔ b ≤ c ↔ a ≤ c ∧ b ≤ c := ⟨assume h : a ⊔ b ≤ c, ⟨le_trans le_sup_left h, le_trans le_sup_right h⟩, assume ⟨h₁, h₂⟩, sup_le h₁ h₂⟩ @[simp] theorem sup_eq_left : a ⊔ b = a ↔ b ≤ a := le_antisymm_iff.trans $ by simp [le_refl] theorem sup_of_le_left (h : b ≤ a) : a ⊔ b = a := sup_eq_left.2 h @[simp] theorem left_eq_sup : a = a ⊔ b ↔ b ≤ a := eq_comm.trans sup_eq_left @[simp] theorem sup_eq_right : a ⊔ b = b ↔ a ≤ b := le_antisymm_iff.trans $ by simp [le_refl] theorem sup_of_le_right (h : a ≤ b) : a ⊔ b = b := sup_eq_right.2 h @[simp] theorem right_eq_sup : b = a ⊔ b ↔ a ≤ b := eq_comm.trans sup_eq_right theorem sup_le_sup (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊔ c ≤ b ⊔ d := sup_le (le_sup_left_of_le h₁) (le_sup_right_of_le h₂) theorem sup_le_sup_left (h₁ : a ≤ b) (c) : c ⊔ a ≤ c ⊔ b := sup_le_sup (le_refl _) h₁ theorem sup_le_sup_right (h₁ : a ≤ b) (c) : a ⊔ c ≤ b ⊔ c := sup_le_sup h₁ (le_refl _) theorem le_of_sup_eq (h : a ⊔ b = b) : a ≤ b := by { rw ← h, simp } lemma sup_ind [is_total α (≤)] (a b : α) {p : α → Prop} (ha : p a) (hb : p b) : p (a ⊔ b) := (is_total.total a b).elim (λ h : a ≤ b, by rwa sup_eq_right.2 h) (λ h, by rwa sup_eq_left.2 h) @[simp] lemma sup_lt_iff [is_total α (≤)] {a b c : α} : b ⊔ c < a ↔ b < a ∧ c < a := ⟨λ h, ⟨le_sup_left.trans_lt h, le_sup_right.trans_lt h⟩, λ h, sup_ind b c h.1 h.2⟩ @[simp] lemma le_sup_iff [is_total α (≤)] {a b c : α} : a ≤ b ⊔ c ↔ a ≤ b ∨ a ≤ c := by rw [← not_iff_not]; simp only [not_or_distrib, @sup_lt_iff α, @not_le (as_linear_order α)] @[simp] lemma lt_sup_iff [is_total α (≤)] {a b c : α} : a < b ⊔ c ↔ a < b ∨ a < c := by { rw ← not_iff_not, simp only [not_or_distrib, @not_lt (as_linear_order α), sup_le_iff] } @[simp] theorem sup_idem : a ⊔ a = a := by apply le_antisymm; simp instance sup_is_idempotent : is_idempotent α (⊔) := ⟨@sup_idem _ _⟩ theorem sup_comm : a ⊔ b = b ⊔ a := by apply le_antisymm; simp instance sup_is_commutative : is_commutative α (⊔) := ⟨@sup_comm _ _⟩ theorem sup_assoc : a ⊔ b ⊔ c = a ⊔ (b ⊔ c) := le_antisymm (sup_le (sup_le le_sup_left (le_sup_right_of_le le_sup_left)) (le_sup_right_of_le le_sup_right)) (sup_le (le_sup_left_of_le le_sup_left) (sup_le (le_sup_left_of_le le_sup_right) le_sup_right)) instance sup_is_associative : is_associative α (⊔) := ⟨@sup_assoc _ _⟩ @[simp] lemma sup_left_idem : a ⊔ (a ⊔ b) = a ⊔ b := by rw [← sup_assoc, sup_idem] @[simp] lemma sup_right_idem : (a ⊔ b) ⊔ b = a ⊔ b := by rw [sup_assoc, sup_idem] lemma sup_left_comm (a b c : α) : a ⊔ (b ⊔ c) = b ⊔ (a ⊔ c) := by rw [← sup_assoc, ← sup_assoc, @sup_comm α _ a] lemma forall_le_or_exists_lt_sup (a : α) : (∀b, b ≤ a) ∨ (∃b, a < b) := suffices (∃b, ¬b ≤ a) → (∃b, a < b), by rwa [or_iff_not_imp_left, not_forall], assume ⟨b, hb⟩, ⟨a ⊔ b, lt_of_le_of_ne le_sup_left $ mt left_eq_sup.1 hb⟩ /-- If `f` is a monotonically increasing sequence, `g` is a monotonically decreasing sequence, and `f n ≤ g n` for all `n`, then for all `m`, `n` we have `f m ≤ g n`. -/ theorem forall_le_of_monotone_of_mono_decr {β : Type*} [preorder β] {f g : α → β} (hf : monotone f) (hg : ∀ ⦃m n⦄, m ≤ n → g n ≤ g m) (h : ∀ n, f n ≤ g n) (m n : α) : f m ≤ g n := calc f m ≤ f (m ⊔ n) : hf le_sup_left ... ≤ g (m ⊔ n) : h _ ... ≤ g n : hg le_sup_right theorem semilattice_sup.ext_sup {α} {A B : semilattice_sup α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) (x y : α) : (by haveI := A; exact (x ⊔ y)) = x ⊔ y := eq_of_forall_ge_iff $ λ c, by simp only [sup_le_iff]; rw [← H, @sup_le_iff α A, H, H] theorem semilattice_sup.ext {α} {A B : semilattice_sup α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B := begin have := partial_order.ext H, have ss := funext (λ x, funext $ semilattice_sup.ext_sup H x), casesI A, casesI B, injection this; congr' end end semilattice_sup /-- A `semilattice_inf` is a meet-semilattice, that is, a partial order with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation `⊓` which is the greatest element smaller than both factors. -/ class semilattice_inf (α : Type u) extends has_inf α, partial_order α := (inf_le_left : ∀ a b : α, a ⊓ b ≤ a) (inf_le_right : ∀ a b : α, a ⊓ b ≤ b) (le_inf : ∀ a b c : α, a ≤ b → a ≤ c → a ≤ b ⊓ c) instance (α) [semilattice_inf α] : semilattice_sup (order_dual α) := { le_sup_left := semilattice_inf.inf_le_left, le_sup_right := semilattice_inf.inf_le_right, sup_le := assume a b c hca hcb, @semilattice_inf.le_inf α _ _ _ _ hca hcb, .. order_dual.partial_order α, .. order_dual.has_sup α } instance (α) [semilattice_sup α] : semilattice_inf (order_dual α) := { inf_le_left := @le_sup_left α _, inf_le_right := @le_sup_right α _, le_inf := assume a b c hca hcb, @sup_le α _ _ _ _ hca hcb, .. order_dual.partial_order α, .. order_dual.has_inf α } section semilattice_inf variables [semilattice_inf α] {a b c d : α} @[simp] theorem inf_le_left : a ⊓ b ≤ a := semilattice_inf.inf_le_left a b @[ematch] theorem inf_le_left' : (: a ⊓ b :) ≤ a := semilattice_inf.inf_le_left a b @[simp] theorem inf_le_right : a ⊓ b ≤ b := semilattice_inf.inf_le_right a b @[ematch] theorem inf_le_right' : (: a ⊓ b :) ≤ b := semilattice_inf.inf_le_right a b theorem le_inf : a ≤ b → a ≤ c → a ≤ b ⊓ c := semilattice_inf.le_inf a b c theorem inf_le_left_of_le (h : a ≤ c) : a ⊓ b ≤ c := le_trans inf_le_left h theorem inf_le_right_of_le (h : b ≤ c) : a ⊓ b ≤ c := le_trans inf_le_right h @[simp] theorem le_inf_iff : a ≤ b ⊓ c ↔ a ≤ b ∧ a ≤ c := @sup_le_iff (order_dual α) _ _ _ _ @[simp] theorem inf_eq_left : a ⊓ b = a ↔ a ≤ b := le_antisymm_iff.trans $ by simp [le_refl] theorem inf_of_le_left (h : a ≤ b) : a ⊓ b = a := inf_eq_left.2 h @[simp] theorem left_eq_inf : a = a ⊓ b ↔ a ≤ b := eq_comm.trans inf_eq_left @[simp] theorem inf_eq_right : a ⊓ b = b ↔ b ≤ a := le_antisymm_iff.trans $ by simp [le_refl] theorem inf_of_le_right (h : b ≤ a) : a ⊓ b = b := inf_eq_right.2 h @[simp] theorem right_eq_inf : b = a ⊓ b ↔ b ≤ a := eq_comm.trans inf_eq_right theorem inf_le_inf (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊓ c ≤ b ⊓ d := le_inf (inf_le_left_of_le h₁) (inf_le_right_of_le h₂) lemma inf_le_inf_right (a : α) {b c : α} (h : b ≤ c) : b ⊓ a ≤ c ⊓ a := inf_le_inf h (le_refl _) lemma inf_le_inf_left (a : α) {b c : α} (h : b ≤ c) : a ⊓ b ≤ a ⊓ c := inf_le_inf (le_refl _) h theorem le_of_inf_eq (h : a ⊓ b = a) : a ≤ b := by { rw ← h, simp } lemma inf_ind [is_total α (≤)] (a b : α) {p : α → Prop} (ha : p a) (hb : p b) : p (a ⊓ b) := @sup_ind (order_dual α) _ _ _ _ _ ha hb @[simp] lemma lt_inf_iff [is_total α (≤)] {a b c : α} : a < b ⊓ c ↔ a < b ∧ a < c := @sup_lt_iff (order_dual α) _ _ _ _ _ @[simp] lemma inf_le_iff [is_total α (≤)] {a b c : α} : b ⊓ c ≤ a ↔ b ≤ a ∨ c ≤ a := @le_sup_iff (order_dual α) _ _ _ _ _ @[simp] theorem inf_idem : a ⊓ a = a := @sup_idem (order_dual α) _ _ instance inf_is_idempotent : is_idempotent α (⊓) := ⟨@inf_idem _ _⟩ theorem inf_comm : a ⊓ b = b ⊓ a := @sup_comm (order_dual α) _ _ _ instance inf_is_commutative : is_commutative α (⊓) := ⟨@inf_comm _ _⟩ theorem inf_assoc : a ⊓ b ⊓ c = a ⊓ (b ⊓ c) := @sup_assoc (order_dual α) _ a b c instance inf_is_associative : is_associative α (⊓) := ⟨@inf_assoc _ _⟩ @[simp] lemma inf_left_idem : a ⊓ (a ⊓ b) = a ⊓ b := @sup_left_idem (order_dual α) _ a b @[simp] lemma inf_right_idem : (a ⊓ b) ⊓ b = a ⊓ b := @sup_right_idem (order_dual α) _ a b lemma inf_left_comm (a b c : α) : a ⊓ (b ⊓ c) = b ⊓ (a ⊓ c) := @sup_left_comm (order_dual α) _ a b c lemma forall_le_or_exists_lt_inf (a : α) : (∀b, a ≤ b) ∨ (∃b, b < a) := @forall_le_or_exists_lt_sup (order_dual α) _ a theorem semilattice_inf.ext_inf {α} {A B : semilattice_inf α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) (x y : α) : (by haveI := A; exact (x ⊓ y)) = x ⊓ y := eq_of_forall_le_iff $ λ c, by simp only [le_inf_iff]; rw [← H, @le_inf_iff α A, H, H] theorem semilattice_inf.ext {α} {A B : semilattice_inf α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B := begin have := partial_order.ext H, have ss := funext (λ x, funext $ semilattice_inf.ext_inf H x), casesI A, casesI B, injection this; congr' end end semilattice_inf /-! ### Lattices -/ /-- A lattice is a join-semilattice which is also a meet-semilattice. -/ class lattice (α : Type u) extends semilattice_sup α, semilattice_inf α instance (α) [lattice α] : lattice (order_dual α) := { .. order_dual.semilattice_sup α, .. order_dual.semilattice_inf α } section lattice variables [lattice α] {a b c d : α} /- Distributivity laws -/ /- TODO: better names? -/ theorem sup_inf_le : a ⊔ (b ⊓ c) ≤ (a ⊔ b) ⊓ (a ⊔ c) := le_inf (sup_le_sup_left inf_le_left _) (sup_le_sup_left inf_le_right _) theorem le_inf_sup : (a ⊓ b) ⊔ (a ⊓ c) ≤ a ⊓ (b ⊔ c) := sup_le (inf_le_inf_left _ le_sup_left) (inf_le_inf_left _ le_sup_right) theorem inf_sup_self : a ⊓ (a ⊔ b) = a := by simp theorem sup_inf_self : a ⊔ (a ⊓ b) = a := by simp theorem lattice.ext {α} {A B : lattice α} (H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B := begin have SS : @lattice.to_semilattice_sup α A = @lattice.to_semilattice_sup α B := semilattice_sup.ext H, have II := semilattice_inf.ext H, casesI A, casesI B, injection SS; injection II; congr' end end lattice /-- A distributive lattice is a lattice that satisfies any of four equivalent distribution properties (of sup over inf or inf over sup, on the left or right). A classic example of a distributive lattice is the lattice of subsets of a set, and in fact this example is generic in the sense that every distributive lattice is realizable as a sublattice of a powerset lattice. -/ class distrib_lattice α extends lattice α := (le_sup_inf : ∀x y z : α, (x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ (y ⊓ z)) section distrib_lattice variables [distrib_lattice α] {x y z : α} theorem le_sup_inf : ∀{x y z : α}, (x ⊔ y) ⊓ (x ⊔ z) ≤ x ⊔ (y ⊓ z) := distrib_lattice.le_sup_inf theorem sup_inf_left : x ⊔ (y ⊓ z) = (x ⊔ y) ⊓ (x ⊔ z) := le_antisymm sup_inf_le le_sup_inf theorem sup_inf_right : (y ⊓ z) ⊔ x = (y ⊔ x) ⊓ (z ⊔ x) := by simp only [sup_inf_left, λy:α, @sup_comm α _ y x, eq_self_iff_true] theorem inf_sup_left : x ⊓ (y ⊔ z) = (x ⊓ y) ⊔ (x ⊓ z) := calc x ⊓ (y ⊔ z) = (x ⊓ (x ⊔ z)) ⊓ (y ⊔ z) : by rw [inf_sup_self] ... = x ⊓ ((x ⊓ y) ⊔ z) : by simp only [inf_assoc, sup_inf_right, eq_self_iff_true] ... = (x ⊔ (x ⊓ y)) ⊓ ((x ⊓ y) ⊔ z) : by rw [sup_inf_self] ... = ((x ⊓ y) ⊔ x) ⊓ ((x ⊓ y) ⊔ z) : by rw [sup_comm] ... = (x ⊓ y) ⊔ (x ⊓ z) : by rw [sup_inf_left] instance (α : Type*) [distrib_lattice α] : distrib_lattice (order_dual α) := { le_sup_inf := assume x y z, le_of_eq inf_sup_left.symm, .. order_dual.lattice α } theorem inf_sup_right : (y ⊔ z) ⊓ x = (y ⊓ x) ⊔ (z ⊓ x) := by simp only [inf_sup_left, λy:α, @inf_comm α _ y x, eq_self_iff_true] lemma le_of_inf_le_sup_le (h₁ : x ⊓ z ≤ y ⊓ z) (h₂ : x ⊔ z ≤ y ⊔ z) : x ≤ y := calc x ≤ (y ⊓ z) ⊔ x : le_sup_right ... = (y ⊔ x) ⊓ (x ⊔ z) : by rw [sup_inf_right, @sup_comm _ _ x] ... ≤ (y ⊔ x) ⊓ (y ⊔ z) : inf_le_inf_left _ h₂ ... = y ⊔ (x ⊓ z) : sup_inf_left.symm ... ≤ y ⊔ (y ⊓ z) : sup_le_sup_left h₁ _ ... ≤ _ : sup_le (le_refl y) inf_le_left lemma eq_of_inf_eq_sup_eq {α : Type u} [distrib_lattice α] {a b c : α} (h₁ : b ⊓ a = c ⊓ a) (h₂ : b ⊔ a = c ⊔ a) : b = c := le_antisymm (le_of_inf_le_sup_le (le_of_eq h₁) (le_of_eq h₂)) (le_of_inf_le_sup_le (le_of_eq h₁.symm) (le_of_eq h₂.symm)) end distrib_lattice /-! ### Lattices derived from linear orders -/ @[priority 100] -- see Note [lower instance priority] instance lattice_of_linear_order {α : Type u} [o : linear_order α] : lattice α := { sup := max, le_sup_left := le_max_left, le_sup_right := le_max_right, sup_le := assume a b c, max_le, inf := min, inf_le_left := min_le_left, inf_le_right := min_le_right, le_inf := assume a b c, le_min, ..o } theorem sup_eq_max [linear_order α] {x y : α} : x ⊔ y = max x y := rfl theorem inf_eq_min [linear_order α] {x y : α} : x ⊓ y = min x y := rfl @[priority 100] -- see Note [lower instance priority] instance distrib_lattice_of_linear_order {α : Type u} [o : linear_order α] : distrib_lattice α := { le_sup_inf := assume a b c, match le_total b c with | or.inl h := inf_le_left_of_le $ sup_le_sup_left (le_inf (le_refl b) h) _ | or.inr h := inf_le_right_of_le $ sup_le_sup_left (le_inf h (le_refl c)) _ end, ..lattice_of_linear_order } instance nat.distrib_lattice : distrib_lattice ℕ := by apply_instance namespace monotone lemma le_map_sup [semilattice_sup α] [semilattice_sup β] {f : α → β} (h : monotone f) (x y : α) : f x ⊔ f y ≤ f (x ⊔ y) := sup_le (h le_sup_left) (h le_sup_right) lemma map_sup [semilattice_sup α] [is_total α (≤)] [semilattice_sup β] {f : α → β} (hf : monotone f) (x y : α) : f (x ⊔ y) = f x ⊔ f y := (is_total.total x y).elim (λ h : x ≤ y, by simp only [h, hf h, sup_of_le_right]) (λ h, by simp only [h, hf h, sup_of_le_left]) lemma map_inf_le [semilattice_inf α] [semilattice_inf β] {f : α → β} (h : monotone f) (x y : α) : f (x ⊓ y) ≤ f x ⊓ f y := le_inf (h inf_le_left) (h inf_le_right) lemma map_inf [semilattice_inf α] [is_total α (≤)] [semilattice_inf β] {f : α → β} (hf : monotone f) (x y : α) : f (x ⊓ y) = f x ⊓ f y := @monotone.map_sup (order_dual α) _ _ _ _ _ hf.order_dual x y end monotone namespace prod variables (α β) instance [has_sup α] [has_sup β] : has_sup (α × β) := ⟨λp q, ⟨p.1 ⊔ q.1, p.2 ⊔ q.2⟩⟩ instance [has_inf α] [has_inf β] : has_inf (α × β) := ⟨λp q, ⟨p.1 ⊓ q.1, p.2 ⊓ q.2⟩⟩ instance [semilattice_sup α] [semilattice_sup β] : semilattice_sup (α × β) := { sup_le := assume a b c h₁ h₂, ⟨sup_le h₁.1 h₂.1, sup_le h₁.2 h₂.2⟩, le_sup_left := assume a b, ⟨le_sup_left, le_sup_left⟩, le_sup_right := assume a b, ⟨le_sup_right, le_sup_right⟩, .. prod.partial_order α β, .. prod.has_sup α β } instance [semilattice_inf α] [semilattice_inf β] : semilattice_inf (α × β) := { le_inf := assume a b c h₁ h₂, ⟨le_inf h₁.1 h₂.1, le_inf h₁.2 h₂.2⟩, inf_le_left := assume a b, ⟨inf_le_left, inf_le_left⟩, inf_le_right := assume a b, ⟨inf_le_right, inf_le_right⟩, .. prod.partial_order α β, .. prod.has_inf α β } instance [lattice α] [lattice β] : lattice (α × β) := { .. prod.semilattice_inf α β, .. prod.semilattice_sup α β } instance [distrib_lattice α] [distrib_lattice β] : distrib_lattice (α × β) := { le_sup_inf := assume a b c, ⟨le_sup_inf, le_sup_inf⟩, .. prod.lattice α β } end prod
f1459d6576515e475f256bfcd9882386f9b7e223
8b9f17008684d796c8022dab552e42f0cb6fb347
/library/algebra/binary.lean
078e25cb0a234327c1d14628dfb413a6f4c80537
[ "Apache-2.0" ]
permissive
chubbymaggie/lean
0d06ae25f9dd396306fb02190e89422ea94afd7b
d2c7b5c31928c98f545b16420d37842c43b4ae9a
refs/heads/master
1,611,313,622,901
1,430,266,839,000
1,430,267,083,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
3,139
lean
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Module: algebra.binary Authors: Leonardo de Moura, Jeremy Avigad General properties of binary operations. -/ import algebra.function open eq.ops function namespace binary section variable {A : Type} variables (op₁ : A → A → A) (inv : A → A) (one : A) local notation a * b := op₁ a b local notation a ⁻¹ := inv a local notation 1 := one definition commutative [reducible] := ∀a b, a * b = b * a definition associative [reducible] := ∀a b c, (a * b) * c = a * (b * c) definition left_identity [reducible] := ∀a, 1 * a = a definition right_identity [reducible] := ∀a, a * 1 = a definition left_inverse [reducible] := ∀a, a⁻¹ * a = 1 definition right_inverse [reducible] := ∀a, a * a⁻¹ = 1 definition left_cancelative [reducible] := ∀a b c, a * b = a * c → b = c definition right_cancelative [reducible] := ∀a b c, a * b = c * b → a = c definition inv_op_cancel_left [reducible] := ∀a b, a⁻¹ * (a * b) = b definition op_inv_cancel_left [reducible] := ∀a b, a * (a⁻¹ * b) = b definition inv_op_cancel_right [reducible] := ∀a b, a * b⁻¹ * b = a definition op_inv_cancel_right [reducible] := ∀a b, a * b * b⁻¹ = a variable (op₂ : A → A → A) local notation a + b := op₂ a b definition left_distributive [reducible] := ∀a b c, a * (b + c) = a * b + a * c definition right_distributive [reducible] := ∀a b c, (a + b) * c = a * c + b * c definition right_commutative [reducible] {B : Type} (f : B → A → B) := ∀ b a₁ a₂, f (f b a₁) a₂ = f (f b a₂) a₁ definition left_commutative [reducible] {B : Type} (f : A → B → B) := ∀ a₁ a₂ b, f a₁ (f a₂ b) = f a₂ (f a₁ b) end section variable {A : Type} variable {f : A → A → A} variable H_comm : commutative f variable H_assoc : associative f local infixl `*` := f theorem left_comm : left_commutative f := take a b c, calc a*(b*c) = (a*b)*c : H_assoc ... = (b*a)*c : H_comm ... = b*(a*c) : H_assoc theorem right_comm : right_commutative f := take a b c, calc (a*b)*c = a*(b*c) : H_assoc ... = a*(c*b) : H_comm ... = (a*c)*b : H_assoc end section variable {A : Type} variable {f : A → A → A} variable H_assoc : associative f local infixl `*` := f theorem assoc4helper (a b c d) : (a*b)*(c*d) = a*((b*c)*d) := calc (a*b)*(c*d) = a*(b*(c*d)) : H_assoc ... = a*((b*c)*d) : H_assoc end definition right_commutative_compose_right [reducible] {A B : Type} (f : A → A → A) (g : B → A) (rcomm : right_commutative f) : right_commutative (compose_right f g) := λ a b₁ b₂, !rcomm definition left_commutative_compose_left [reducible] {A B : Type} (f : A → A → A) (g : B → A) (lcomm : left_commutative f) : left_commutative (compose_left f g) := λ a b₁ b₂, !lcomm end binary
a110994b3daac1408fb619bdc532749b968c001f
86f6f4f8d827a196a32bfc646234b73328aeb306
/examples/basics/unnamed_1327.lean
76f322f327bb21d3e0e62a5085fbf8b3d94d9133
[]
no_license
jamescheuk91/mathematics_in_lean
09f1f87d2b0dce53464ff0cbe592c568ff59cf5e
4452499264e2975bca2f42565c0925506ba5dda3
refs/heads/master
1,679,716,410,967
1,613,957,947,000
1,613,957,947,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
182
lean
import import analysis.special_functions.exp_log import tactic open real variables a b c : ℝ -- BEGIN example (h : a ≤ b) : c - exp b ≤ c - exp a := begin sorry end -- END
2e1a25812b9dd0f834a18b0f24491d789a26a979
57c233acf9386e610d99ed20ef139c5f97504ba3
/src/set_theory/fincard.lean
0af54dd8ea871596429b06323241005932d866ac
[ "Apache-2.0" ]
permissive
robertylewis/mathlib
3d16e3e6daf5ddde182473e03a1b601d2810952c
1d13f5b932f5e40a8308e3840f96fc882fae01f0
refs/heads/master
1,651,379,945,369
1,644,276,960,000
1,644,276,960,000
98,875,504
0
0
Apache-2.0
1,644,253,514,000
1,501,495,700,000
Lean
UTF-8
Lean
false
false
1,321
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 set_theory.cardinal /-! # Finite Cardinality Functions ## Main Definitions * `nat.card α` is the cardinality of `α` as a natural number. If `α` is infinite, `nat.card α = 0`. * `enat.card α` is the cardinality of `α` as an extended natural number. If `α` is infinite, `enat.card α = ⊤`. -/ open cardinal noncomputable theory variable {α : Type*} namespace nat /-- `nat.card α` is the cardinality of `α` as a natural number. If `α` is infinite, `nat.card α = 0`. -/ protected def card (α : Type*) : ℕ := (mk α).to_nat @[simp] lemma card_eq_fintype_card [fintype α] : nat.card α = fintype.card α := mk_to_nat_eq_card @[simp] lemma card_eq_zero_of_infinite [infinite α] : nat.card α = 0 := mk_to_nat_of_infinite end nat namespace enat /-- `enat.card α` is the cardinality of `α` as an extended natural number. If `α` is infinite, `enat.card α = ⊤`. -/ def card (α : Type*) : enat := (mk α).to_enat @[simp] lemma card_eq_coe_fintype_card [fintype α] : card α = fintype.card α := mk_to_enat_eq_coe_card @[simp] lemma card_eq_top_of_infinite [infinite α] : card α = ⊤ := mk_to_enat_of_infinite end enat
eb90325970a51922f2ed49b4ec6c9d00dc741385
3dc4623269159d02a444fe898d33e8c7e7e9461b
/.github/workflows/geo/src/group_objet/testt.lean
5a6f84cc3910308e9069022e4c3a720adcec3317
[]
no_license
Or7ando/lean
cc003e6c41048eae7c34aa6bada51c9e9add9e66
d41169cf4e416a0d42092fb6bdc14131cee9dd15
refs/heads/master
1,650,600,589,722
1,587,262,906,000
1,587,262,906,000
255,387,160
0
0
null
null
null
null
UTF-8
Lean
false
false
240
lean
variable (X : Type) def f : ℕ → ℕ := λ x, x + 1 include X def g : ℕ → ℕ := λ x, x + 1 omit X def h : ℕ → ℕ := λ x, x + 1 #check f -- f : ℕ → ℕ #check g -- g : Type → ℕ → ℕ #check h -- h : ℕ → ℕ
5630f5c555fe241460c05e220e2f142c73df46ee
e00ea76a720126cf9f6d732ad6216b5b824d20a7
/src/topology/bases.lean
5235b37b64e2f9e29bf02819749e91bf481d66f0
[ "Apache-2.0" ]
permissive
vaibhavkarve/mathlib
a574aaf68c0a431a47fa82ce0637f0f769826bfe
17f8340912468f49bdc30acdb9a9fa02eeb0473a
refs/heads/master
1,621,263,802,637
1,585,399,588,000
1,585,399,588,000
250,833,447
0
0
Apache-2.0
1,585,410,341,000
1,585,410,341,000
null
UTF-8
Lean
false
false
18,416
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 Bases of topologies. Countability axioms. -/ import topology.constructions data.set.countable open set filter classical open_locale topological_space namespace filter universes u v variables {α : Type u} {β : Type v} /-- A filter has a countable basis iff it is generated by a countable collection of subsets of α. (A filter is a generated by a collection of sets iff it is the infimum of the principal filters.) Note: we do not require the collection to be closed under finite intersections. -/ def has_countable_basis (f : filter α) : Prop := ∃ s : set (set α), countable s ∧ f = ⨅ t ∈ s, principal t lemma has_countable_basis_of_seq (f : filter α) (x : ℕ → set α) (h : f = ⨅ i, principal (x i)) : f.has_countable_basis := ⟨range x, countable_range _, by rwa infi_range⟩ lemma seq_of_has_countable_basis (f : filter α) (cblb : f.has_countable_basis) : ∃ x : ℕ → set α, f = ⨅ i, principal (x i) := begin rcases cblb with ⟨B, Bcbl, gen⟩, subst gen, cases B.eq_empty_or_nonempty with hB Bnonempty, { use λ n, set.univ, simp [principal_univ, *] }, rw countable_iff_exists_surjective_to_subtype Bnonempty at Bcbl, rcases Bcbl with ⟨g, gsurj⟩, rw infi_subtype', use (λ n, g n), apply le_antisymm; rw le_infi_iff, { intro i, apply infi_le_of_le (g i) _, apply le_refl _ }, { intros a, rcases gsurj a with i, apply infi_le_of_le i _, subst h, apply le_refl _ } end /-- Different characterization of countable basis. A filter has a countable basis iff it is generated by a sequence of sets. -/ lemma has_countable_basis_iff_seq (f : filter α) : f.has_countable_basis ↔ ∃ x : ℕ → set α, f = ⨅ i, principal (x i) := ⟨seq_of_has_countable_basis _, λ ⟨x, xgen⟩, has_countable_basis_of_seq _ x xgen⟩ lemma mono_seq_of_has_countable_basis (f : filter α) (cblb : f.has_countable_basis) : ∃ x : ℕ → set α, (∀ i j, i ≤ j → x j ⊆ x i) ∧ f = ⨅ i, principal (x i) := begin rcases (seq_of_has_countable_basis f cblb) with ⟨x', hx'⟩, let x := λ n, ⋂ m ≤ n, x' m, use x, split, { intros i j hij a, simp [x], intros h i' hi'i, apply h, transitivity; assumption }, subst hx', apply le_antisymm; rw le_infi_iff; intro i, { rw le_principal_iff, apply Inter_mem_sets (finite_le_nat _), intros j hji, rw ← le_principal_iff, apply infi_le_of_le j _, apply le_refl _ }, { apply infi_le_of_le i _, rw principal_mono, intro a, simp [x], intro h, apply h, refl }, end /-- Different characterization of countable basis. A filter has a countable basis iff it is generated by a monotonically decreasing sequence of sets. -/ lemma has_countable_basis_iff_mono_seq (f : filter α) : f.has_countable_basis ↔ ∃ x : ℕ → set α, (∀ i j, i ≤ j → x j ⊆ x i) ∧ f = ⨅ i, principal (x i) := ⟨mono_seq_of_has_countable_basis _, λ ⟨x, _, xgen⟩, has_countable_basis_of_seq _ x xgen⟩ /-- Different characterization of countable basis. A filter has a countable basis iff there exists a monotonically decreasing sequence of sets `x i` such that `s ∈ f ↔ ∃ i, x i ⊆ s`. -/ lemma has_countable_basis_iff_mono_seq' (f : filter α) : f.has_countable_basis ↔ ∃ x : ℕ → set α, (∀ i j, i ≤ j → x j ⊆ x i) ∧ (∀ {s}, s ∈ f ↔ ∃ i, x i ⊆ s) := begin refine (has_countable_basis_iff_mono_seq f).trans (exists_congr $ λ x, and_congr_right _), intro hmono, have : directed (≥) (λ i, principal (x i)), from directed_of_mono _ (λ i j hij, principal_mono.2 (hmono _ _ hij)), simp only [filter.ext_iff, mem_infi this ⟨0⟩, mem_Union, mem_principal_sets] end lemma has_countable_basis.comap {l : filter β} (h : has_countable_basis l) (f : α → β) : has_countable_basis (l.comap f) := begin rcases h with ⟨S, h₁, h₂⟩, refine ⟨preimage f '' S, countable_image _ h₁, _⟩, calc comap f l = ⨅ s ∈ S, principal (f ⁻¹' s) : by simp [h₂] ... = ⨅ s ∈ S, ⨅ (t : set α) (H : f ⁻¹' s = t), principal t : by simp ... = ⨅ (t : set α) (s ∈ S) (h₂ : f ⁻¹' s = t), principal t : by { rw [infi_comm], congr' 1, ext t, rw [infi_comm] } ... = _ : by simp [-infi_infi_eq_right, infi_and] end -- TODO : prove this for a encodable type lemma has_countable_basis_at_top_finset_nat : has_countable_basis (@at_top (finset ℕ) _) := begin refine has_countable_basis_of_seq _ (λN, Ici (finset.range N)) (eq_infi_of_mem_sets_iff_exists_mem _), assume s, rw mem_at_top_sets, refine ⟨_, λ ⟨N, hN⟩, ⟨finset.range N, hN⟩⟩, rintros ⟨t, ht⟩, rcases mem_at_top_sets.1 (tendsto_finset_range (mem_at_top t)) with ⟨N, hN⟩, simp only [preimage, mem_set_of_eq] at hN, exact ⟨N, mem_principal_sets.2 $ λ t' ht', ht t' $ le_trans (hN _ $ le_refl N) ht'⟩ end lemma has_countable_basis.tendsto_iff_seq_tendsto {f : α → β} {k : filter α} {l : filter β} (hcb : k.has_countable_basis) : tendsto f k l ↔ (∀ x : ℕ → α, tendsto x at_top k → tendsto (f ∘ x) at_top l) := suffices (∀ x : ℕ → α, tendsto x at_top k → tendsto (f ∘ x) at_top l) → tendsto f k l, from ⟨by intros; apply tendsto.comp; assumption, by assumption⟩, begin rw filter.has_countable_basis_iff_mono_seq at hcb, rcases hcb with ⟨g, gmon, gbasis⟩, have gbasis : ∀ A, A ∈ k ↔ ∃ i, g i ⊆ A, { intro A, subst gbasis, rw mem_infi, { simp only [set.mem_Union, iff_self, filter.mem_principal_sets] }, { exact directed_of_mono _ (λ i j h, principal_mono.mpr $ gmon _ _ h) }, { apply_instance } }, classical, contrapose, simp only [not_forall, not_imp, not_exists, subset_def, @tendsto_def _ _ f, gbasis], rintro ⟨B, hBl, hfBk⟩, choose x h using hfBk, use x, split, { simp only [tendsto_at_top', gbasis], rintros A ⟨i, hgiA⟩, use i, refine (λ j hj, hgiA $ gmon _ _ hj _), simp only [h] }, { simp only [tendsto_at_top', (∘), not_forall, not_exists], use [B, hBl], intro i, use [i, (le_refl _)], apply (h i).right }, end lemma has_countable_basis.tendsto_of_seq_tendsto {f : α → β} {k : filter α} {l : filter β} (hcb : k.has_countable_basis) : (∀ x : ℕ → α, tendsto x at_top k → tendsto (f ∘ x) at_top l) → tendsto f k l := hcb.tendsto_iff_seq_tendsto.2 end filter namespace topological_space /- countability axioms For our applications we are interested that there exists a countable basis, but we do not need the concrete basis itself. This allows us to declare these type classes as `Prop` to use them as mixins. -/ universe u variables {α : Type u} [t : topological_space α] include t /-- A topological basis is one that satisfies the necessary conditions so that it suffices to take unions of the basis sets to get a topology (without taking finite intersections as well). -/ def is_topological_basis (s : set (set α)) : Prop := (∀t₁∈s, ∀t₂∈s, ∀ x ∈ t₁ ∩ t₂, ∃ t₃∈s, x ∈ t₃ ∧ t₃ ⊆ t₁ ∩ t₂) ∧ (⋃₀ s) = univ ∧ t = generate_from s lemma is_topological_basis_of_subbasis {s : set (set α)} (hs : t = generate_from s) : is_topological_basis ((λf, ⋂₀ f) '' {f:set (set α) | finite f ∧ f ⊆ s ∧ (⋂₀ f).nonempty}) := let b' := (λf, ⋂₀ f) '' {f:set (set α) | finite f ∧ f ⊆ s ∧ (⋂₀ f).nonempty} in ⟨assume s₁ ⟨t₁, ⟨hft₁, ht₁b, ht₁⟩, eq₁⟩ s₂ ⟨t₂, ⟨hft₂, ht₂b, ht₂⟩, eq₂⟩, have ie : ⋂₀(t₁ ∪ t₂) = ⋂₀ t₁ ∩ ⋂₀ t₂, from Inf_union, eq₁ ▸ eq₂ ▸ assume x h, ⟨_, ⟨t₁ ∪ t₂, ⟨finite_union hft₁ hft₂, union_subset ht₁b ht₂b, ie.symm ▸ ⟨_, h⟩⟩, ie⟩, h, subset.refl _⟩, eq_univ_iff_forall.2 $ assume a, ⟨univ, ⟨∅, ⟨finite_empty, empty_subset _, by rw sInter_empty; exact ⟨a, mem_univ a⟩⟩, sInter_empty⟩, mem_univ _⟩, have generate_from s = generate_from b', from le_antisymm (le_generate_from $ assume u ⟨t, ⟨hft, htb, ne⟩, eq⟩, eq ▸ @is_open_sInter _ (generate_from s) _ hft (assume s hs, generate_open.basic _ $ htb hs)) (le_generate_from $ assume s hs, s.eq_empty_or_nonempty.elim (assume : s = ∅, by rw [this]; apply @is_open_empty _ _) (assume : s.nonempty, generate_open.basic _ ⟨{s}, ⟨finite_singleton s, singleton_subset_iff.2 hs, by rwa sInter_singleton⟩, sInter_singleton s⟩)), this ▸ hs⟩ lemma is_topological_basis_of_open_of_nhds {s : set (set α)} (h_open : ∀ u ∈ s, _root_.is_open u) (h_nhds : ∀(a:α) (u : set α), a ∈ u → _root_.is_open u → ∃v ∈ s, a ∈ v ∧ v ⊆ u) : is_topological_basis s := ⟨assume t₁ ht₁ t₂ ht₂ x ⟨xt₁, xt₂⟩, h_nhds x (t₁ ∩ t₂) ⟨xt₁, xt₂⟩ (is_open_inter _ _ _ (h_open _ ht₁) (h_open _ ht₂)), eq_univ_iff_forall.2 $ assume a, let ⟨u, h₁, h₂, _⟩ := h_nhds a univ trivial (is_open_univ _) in ⟨u, h₁, h₂⟩, le_antisymm (le_generate_from h_open) (assume u hu, (@is_open_iff_nhds α (generate_from _) _).mpr $ assume a hau, let ⟨v, hvs, hav, hvu⟩ := h_nhds a u hau hu in by rw nhds_generate_from; exact infi_le_of_le v (infi_le_of_le ⟨hav, hvs⟩ $ le_principal_iff.2 hvu))⟩ lemma mem_nhds_of_is_topological_basis {a : α} {s : set α} {b : set (set α)} (hb : is_topological_basis b) : s ∈ 𝓝 a ↔ ∃t∈b, a ∈ t ∧ t ⊆ s := begin change s ∈ (𝓝 a).sets ↔ ∃t∈b, a ∈ t ∧ t ⊆ s, rw [hb.2.2, nhds_generate_from, binfi_sets_eq], { simp only [mem_bUnion_iff, exists_prop, mem_set_of_eq, and_assoc, and.left_comm], refl }, { exact assume s ⟨hs₁, hs₂⟩ t ⟨ht₁, ht₂⟩, have a ∈ s ∩ t, from ⟨hs₁, ht₁⟩, let ⟨u, hu₁, hu₂, hu₃⟩ := hb.1 _ hs₂ _ ht₂ _ this in ⟨u, ⟨hu₂, hu₁⟩, le_principal_iff.2 (subset.trans hu₃ (inter_subset_left _ _)), le_principal_iff.2 (subset.trans hu₃ (inter_subset_right _ _))⟩ }, { rcases eq_univ_iff_forall.1 hb.2.1 a with ⟨i, h1, h2⟩, exact ⟨i, h2, h1⟩ } end lemma is_open_of_is_topological_basis {s : set α} {b : set (set α)} (hb : is_topological_basis b) (hs : s ∈ b) : _root_.is_open s := is_open_iff_mem_nhds.2 $ λ a as, (mem_nhds_of_is_topological_basis hb).2 ⟨s, hs, as, subset.refl _⟩ lemma mem_basis_subset_of_mem_open {b : set (set α)} (hb : is_topological_basis b) {a:α} {u : set α} (au : a ∈ u) (ou : _root_.is_open u) : ∃v ∈ b, a ∈ v ∧ v ⊆ u := (mem_nhds_of_is_topological_basis hb).1 $ mem_nhds_sets ou au lemma sUnion_basis_of_is_open {B : set (set α)} (hB : is_topological_basis B) {u : set α} (ou : _root_.is_open u) : ∃ S ⊆ B, u = ⋃₀ S := ⟨{s ∈ B | s ⊆ u}, λ s h, h.1, set.ext $ λ a, ⟨λ ha, let ⟨b, hb, ab, bu⟩ := mem_basis_subset_of_mem_open hB ha ou in ⟨b, ⟨hb, bu⟩, ab⟩, λ ⟨b, ⟨hb, bu⟩, ab⟩, bu ab⟩⟩ lemma Union_basis_of_is_open {B : set (set α)} (hB : is_topological_basis B) {u : set α} (ou : _root_.is_open u) : ∃ (β : Type u) (f : β → set α), u = (⋃ i, f i) ∧ ∀ i, f i ∈ B := let ⟨S, sb, su⟩ := sUnion_basis_of_is_open hB ou in ⟨S, subtype.val, su.trans set.sUnion_eq_Union, λ ⟨b, h⟩, sb h⟩ variables (α) /-- A separable space is one with a countable dense subset. -/ class separable_space : Prop := (exists_countable_closure_eq_univ : ∃s:set α, countable s ∧ closure s = univ) /-- A first-countable space is one in which every point has a countable neighborhood basis. -/ class first_countable_topology : Prop := (nhds_generated_countable : ∀a:α, (𝓝 a).has_countable_basis) /-- A second-countable space is one with a countable basis. -/ class second_countable_topology : Prop := (is_open_generated_countable : ∃b:set (set α), countable b ∧ t = topological_space.generate_from b) @[priority 100] -- see Note [lower instance priority] instance second_countable_topology.to_first_countable_topology [second_countable_topology α] : first_countable_topology α := let ⟨b, hb, eq⟩ := second_countable_topology.is_open_generated_countable α in ⟨assume a, ⟨{s | a ∈ s ∧ s ∈ b}, countable_subset (assume x ⟨_, hx⟩, hx) hb, by rw [eq, nhds_generate_from]⟩⟩ lemma second_countable_topology_induced (β) [t : topological_space β] [second_countable_topology β] (f : α → β) : @second_countable_topology α (t.induced f) := begin rcases second_countable_topology.is_open_generated_countable β with ⟨b, hb, eq⟩, refine { is_open_generated_countable := ⟨preimage f '' b, countable_image _ hb, _⟩ }, rw [eq, induced_generate_from_eq] end instance subtype.second_countable_topology (s : set α) [second_countable_topology α] : second_countable_topology s := second_countable_topology_induced s α coe lemma is_open_generated_countable_inter [second_countable_topology α] : ∃b:set (set α), countable b ∧ ∅ ∉ b ∧ is_topological_basis b := let ⟨b, hb₁, hb₂⟩ := second_countable_topology.is_open_generated_countable α in let b' := (λs, ⋂₀ s) '' {s:set (set α) | finite s ∧ s ⊆ b ∧ (⋂₀ s).nonempty} in ⟨b', countable_image _ $ countable_subset (by simp only [(and_assoc _ _).symm]; exact inter_subset_left _ _) (countable_set_of_finite_subset hb₁), assume ⟨s, ⟨_, _, hn⟩, hp⟩, absurd hn (not_nonempty_iff_eq_empty.2 hp), is_topological_basis_of_subbasis hb₂⟩ /- TODO: more fine grained instances for first_countable_topology, separable_space, t2_space, ... -/ instance {β : Type*} [topological_space β] [second_countable_topology α] [second_countable_topology β] : second_countable_topology (α × β) := ⟨let ⟨a, ha₁, ha₂, ha₃, ha₄, ha₅⟩ := is_open_generated_countable_inter α in let ⟨b, hb₁, hb₂, hb₃, hb₄, hb₅⟩ := is_open_generated_countable_inter β in ⟨{g | ∃u∈a, ∃v∈b, g = set.prod u v}, have {g | ∃u∈a, ∃v∈b, g = set.prod u v} = (⋃u∈a, ⋃v∈b, {set.prod u v}), by apply set.ext; simp, by rw [this]; exact (countable_bUnion ha₁ $ assume u hu, countable_bUnion hb₁ $ by simp), by rw [ha₅, hb₅, prod_generate_from_generate_from_eq ha₄ hb₄]⟩⟩ instance second_countable_topology_fintype {ι : Type*} {π : ι → Type*} [fintype ι] [t : ∀a, topological_space (π a)] [sc : ∀a, second_countable_topology (π a)] : second_countable_topology (∀a, π a) := have ∀i, ∃b : set (set (π i)), countable b ∧ ∅ ∉ b ∧ is_topological_basis b, from assume a, @is_open_generated_countable_inter (π a) _ (sc a), let ⟨g, hg⟩ := classical.axiom_of_choice this in have t = (λa, generate_from (g a)), from funext $ assume a, (hg a).2.2.2.2, begin constructor, refine ⟨pi univ '' pi univ g, countable_image _ _, _⟩, { suffices : countable {f : Πa, set (π a) | ∀a, f a ∈ g a}, { simpa [pi] }, exact countable_pi (assume i, (hg i).1), }, rw [this, pi_generate_from_eq_fintype], { congr' 1, ext f, simp [pi, eq_comm] }, exact assume a, (hg a).2.2.2.1 end @[priority 100] -- see Note [lower instance priority] instance second_countable_topology.to_separable_space [second_countable_topology α] : separable_space α := let ⟨b, hb₁, hb₂, hb₃, hb₄, eq⟩ := is_open_generated_countable_inter α in have nhds_eq : ∀a, 𝓝 a = (⨅ s : {s : set α // a ∈ s ∧ s ∈ b}, principal s.val), by intro a; rw [eq, nhds_generate_from, infi_subtype]; refl, have ∀s∈b, set.nonempty s, from assume s hs, ne_empty_iff_nonempty.1 $ λ eq, absurd hs (eq.symm ▸ hb₂), have ∃f:∀s∈b, α, ∀s h, f s h ∈ s, by simpa only [skolem, set.nonempty] using this, let ⟨f, hf⟩ := this in ⟨⟨(⋃s∈b, ⋃h:s∈b, {f s h}), countable_bUnion hb₁ (λ _ _, countable_Union_Prop $ λ _, countable_singleton _), set.ext $ assume a, have a ∈ (⋃₀ b), by rw [hb₄]; exact trivial, let ⟨t, ht₁, ht₂⟩ := this in have w : {s : set α // a ∈ s ∧ s ∈ b}, from ⟨t, ht₂, ht₁⟩, suffices (⨅ (x : {s // a ∈ s ∧ s ∈ b}), principal (x.val ∩ ⋃s (h₁ h₂ : s ∈ b), {f s h₂})) ≠ ⊥, by simpa only [closure_eq_nhds, nhds_eq, infi_inf w, inf_principal, mem_set_of_eq, mem_univ, iff_true], infi_ne_bot_of_directed ⟨a⟩ (assume ⟨s₁, has₁, hs₁⟩ ⟨s₂, has₂, hs₂⟩, have a ∈ s₁ ∩ s₂, from ⟨has₁, has₂⟩, let ⟨s₃, hs₃, has₃, hs⟩ := hb₃ _ hs₁ _ hs₂ _ this in ⟨⟨s₃, has₃, hs₃⟩, begin simp only [le_principal_iff, mem_principal_sets, (≥)], simp only [subset_inter_iff] at hs, split; apply inter_subset_inter_left; simp only [hs] end⟩) (assume ⟨s, has, hs⟩, have (s ∩ (⋃ (s : set α) (H h : s ∈ b), {f s h})).nonempty, from ⟨_, hf _ hs, mem_bUnion hs $ mem_Union.mpr ⟨hs, mem_singleton _⟩⟩, principal_ne_bot_iff.2 this) ⟩⟩ variables {α} lemma is_open_Union_countable [second_countable_topology α] {ι} (s : ι → set α) (H : ∀ i, _root_.is_open (s i)) : ∃ T : set ι, countable T ∧ (⋃ i ∈ T, s i) = ⋃ i, s i := let ⟨B, cB, _, bB⟩ := is_open_generated_countable_inter α in begin let B' := {b ∈ B | ∃ i, b ⊆ s i}, choose f hf using λ b:B', b.2.2, haveI : encodable B' := (countable_subset (sep_subset _ _) cB).to_encodable, refine ⟨_, countable_range f, subset.antisymm (bUnion_subset_Union _ _) (sUnion_subset _)⟩, rintro _ ⟨i, rfl⟩ x xs, rcases mem_basis_subset_of_mem_open bB xs (H _) with ⟨b, hb, xb, bs⟩, exact ⟨_, ⟨_, rfl⟩, _, ⟨⟨⟨_, hb, _, bs⟩, rfl⟩, rfl⟩, hf _ (by exact xb)⟩ end lemma is_open_sUnion_countable [second_countable_topology α] (S : set (set α)) (H : ∀ s ∈ S, _root_.is_open s) : ∃ T : set (set α), countable T ∧ T ⊆ S ∧ ⋃₀ T = ⋃₀ S := let ⟨T, cT, hT⟩ := is_open_Union_countable (λ s:S, s.1) (λ s, H s.1 s.2) in ⟨subtype.val '' T, countable_image _ cT, image_subset_iff.2 $ λ ⟨x, xs⟩ xt, xs, by rwa [sUnion_image, sUnion_eq_Union]⟩ end topological_space
ed90e6a2f9a847a399e21d7d3bc0cd42e9910583
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/algebra/lie/classical.lean
b6b6e38cfb15d363d29a223d5dfdd1d0fcb4e81a
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
13,415
lean
/- Copyright (c) 2020 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import algebra.invertible import data.matrix.basis import data.matrix.dmatrix import algebra.lie.abelian import linear_algebra.matrix.trace import algebra.lie.skew_adjoint import linear_algebra.symplectic_group /-! # Classical Lie algebras > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file is the place to find definitions and basic properties of the classical Lie algebras: * Aₗ = sl(l+1) * Bₗ ≃ so(l+1, l) ≃ so(2l+1) * Cₗ = sp(l) * Dₗ ≃ so(l, l) ≃ so(2l) ## Main definitions * `lie_algebra.special_linear.sl` * `lie_algebra.symplectic.sp` * `lie_algebra.orthogonal.so` * `lie_algebra.orthogonal.so'` * `lie_algebra.orthogonal.so_indefinite_equiv` * `lie_algebra.orthogonal.type_D` * `lie_algebra.orthogonal.type_B` * `lie_algebra.orthogonal.type_D_equiv_so'` * `lie_algebra.orthogonal.type_B_equiv_so'` ## Implementation notes ### Matrices or endomorphisms Given a finite type and a commutative ring, the corresponding square matrices are equivalent to the endomorphisms of the corresponding finite-rank free module as Lie algebras, see `lie_equiv_matrix'`. We can thus define the classical Lie algebras as Lie subalgebras either of matrices or of endomorphisms. We have opted for the former. At the time of writing (August 2020) it is unclear which approach should be preferred so the choice should be assumed to be somewhat arbitrary. ### Diagonal quadratic form or diagonal Cartan subalgebra For the algebras of type `B` and `D`, there are two natural definitions. For example since the the `2l × 2l` matrix: $$ J = \left[\begin{array}{cc} 0_l & 1_l\\ 1_l & 0_l \end{array}\right] $$ defines a symmetric bilinear form equivalent to that defined by the identity matrix `I`, we can define the algebras of type `D` to be the Lie subalgebra of skew-adjoint matrices either for `J` or for `I`. Both definitions have their advantages (in particular the `J`-skew-adjoint matrices define a Lie algebra for which the diagonal matrices form a Cartan subalgebra) and so we provide both. We thus also provide equivalences `type_D_equiv_so'`, `so_indefinite_equiv` which show the two definitions are equivalent. Similarly for the algebras of type `B`. ## Tags classical lie algebra, special linear, symplectic, orthogonal -/ universes u₁ u₂ namespace lie_algebra open matrix open_locale matrix variables (n p q l : Type*) (R : Type u₂) variables [decidable_eq n] [decidable_eq p] [decidable_eq q] [decidable_eq l] variables [comm_ring R] @[simp] lemma matrix_trace_commutator_zero [fintype n] (X Y : matrix n n R) : matrix.trace ⁅X, Y⁆ = 0 := calc _ = matrix.trace (X ⬝ Y) - matrix.trace (Y ⬝ X) : trace_sub _ _ ... = matrix.trace (X ⬝ Y) - matrix.trace (X ⬝ Y) : congr_arg (λ x, _ - x) (matrix.trace_mul_comm Y X) ... = 0 : sub_self _ namespace special_linear /-- The special linear Lie algebra: square matrices of trace zero. -/ def sl [fintype n] : lie_subalgebra R (matrix n n R) := { lie_mem' := λ X Y _ _, linear_map.mem_ker.2 $ matrix_trace_commutator_zero _ _ _ _, ..linear_map.ker (matrix.trace_linear_map n R R) } lemma sl_bracket [fintype n] (A B : sl n R) : ⁅A, B⁆.val = A.val ⬝ B.val - B.val ⬝ A.val := rfl section elementary_basis variables {n} [fintype n] (i j : n) /-- When j ≠ i, the elementary matrices are elements of sl n R, in fact they are part of a natural basis of sl n R. -/ def Eb (h : j ≠ i) : sl n R := ⟨matrix.std_basis_matrix i j (1 : R), show matrix.std_basis_matrix i j (1 : R) ∈ linear_map.ker (matrix.trace_linear_map n R R), from matrix.std_basis_matrix.trace_zero i j (1 : R) h⟩ @[simp] lemma Eb_val (h : j ≠ i) : (Eb R i j h).val = matrix.std_basis_matrix i j 1 := rfl end elementary_basis lemma sl_non_abelian [fintype n] [nontrivial R] (h : 1 < fintype.card n) : ¬is_lie_abelian ↥(sl n R) := begin rcases fintype.exists_pair_of_one_lt_card h with ⟨j, i, hij⟩, let A := Eb R i j hij, let B := Eb R j i hij.symm, intros c, have c' : A.val ⬝ B.val = B.val ⬝ A.val, by { rw [← sub_eq_zero, ← sl_bracket, c.trivial], refl }, simpa [std_basis_matrix, matrix.mul_apply, hij] using congr_fun (congr_fun c' i) i, end end special_linear namespace symplectic /-- The symplectic Lie algebra: skew-adjoint matrices with respect to the canonical skew-symmetric bilinear form. -/ def sp [fintype l] : lie_subalgebra R (matrix (l ⊕ l) (l ⊕ l) R) := skew_adjoint_matrices_lie_subalgebra (matrix.J l R) end symplectic namespace orthogonal /-- The definite orthogonal Lie subalgebra: skew-adjoint matrices with respect to the symmetric bilinear form defined by the identity matrix. -/ def so [fintype n] : lie_subalgebra R (matrix n n R) := skew_adjoint_matrices_lie_subalgebra (1 : matrix n n R) @[simp] lemma mem_so [fintype n] (A : matrix n n R) : A ∈ so n R ↔ Aᵀ = -A := begin erw mem_skew_adjoint_matrices_submodule, simp only [matrix.is_skew_adjoint, matrix.is_adjoint_pair, matrix.mul_one, matrix.one_mul], end /-- The indefinite diagonal matrix with `p` 1s and `q` -1s. -/ def indefinite_diagonal : matrix (p ⊕ q) (p ⊕ q) R := matrix.diagonal $ sum.elim (λ _, 1) (λ _, -1) /-- The indefinite orthogonal Lie subalgebra: skew-adjoint matrices with respect to the symmetric bilinear form defined by the indefinite diagonal matrix. -/ def so' [fintype p] [fintype q] : lie_subalgebra R (matrix (p ⊕ q) (p ⊕ q) R) := skew_adjoint_matrices_lie_subalgebra $ indefinite_diagonal p q R /-- A matrix for transforming the indefinite diagonal bilinear form into the definite one, provided the parameter `i` is a square root of -1. -/ def Pso (i : R) : matrix (p ⊕ q) (p ⊕ q) R := matrix.diagonal $ sum.elim (λ _, 1) (λ _, i) variables [fintype p] [fintype q] lemma Pso_inv {i : R} (hi : i*i = -1) : (Pso p q R i) * (Pso p q R (-i)) = 1 := begin ext x y, rcases x; rcases y, { -- x y : p by_cases h : x = y; simp [Pso, indefinite_diagonal, h], }, { -- x : p, y : q simp [Pso, indefinite_diagonal], }, { -- x : q, y : p simp [Pso, indefinite_diagonal], }, { -- x y : q by_cases h : x = y; simp [Pso, indefinite_diagonal, h, hi], }, end /-- There is a constructive inverse of `Pso p q R i`. -/ def invertible_Pso {i : R} (hi : i*i = -1) : invertible (Pso p q R i) := invertible_of_right_inverse _ _ (Pso_inv p q R hi) lemma indefinite_diagonal_transform {i : R} (hi : i*i = -1) : (Pso p q R i)ᵀ ⬝ (indefinite_diagonal p q R) ⬝ (Pso p q R i) = 1 := begin ext x y, rcases x; rcases y, { -- x y : p by_cases h : x = y; simp [Pso, indefinite_diagonal, h], }, { -- x : p, y : q simp [Pso, indefinite_diagonal], }, { -- x : q, y : p simp [Pso, indefinite_diagonal], }, { -- x y : q by_cases h : x = y; simp [Pso, indefinite_diagonal, h, hi], }, end /-- An equivalence between the indefinite and definite orthogonal Lie algebras, over a ring containing a square root of -1. -/ def so_indefinite_equiv {i : R} (hi : i*i = -1) : so' p q R ≃ₗ⁅R⁆ so (p ⊕ q) R := begin apply (skew_adjoint_matrices_lie_subalgebra_equiv (indefinite_diagonal p q R) (Pso p q R i) (invertible_Pso p q R hi)).trans, apply lie_equiv.of_eq, ext A, rw indefinite_diagonal_transform p q R hi, refl, end lemma so_indefinite_equiv_apply {i : R} (hi : i*i = -1) (A : so' p q R) : (so_indefinite_equiv p q R hi A : matrix (p ⊕ q) (p ⊕ q) R) = (Pso p q R i)⁻¹ ⬝ (A : matrix (p ⊕ q) (p ⊕ q) R) ⬝ (Pso p q R i) := by erw [lie_equiv.trans_apply, lie_equiv.of_eq_apply, skew_adjoint_matrices_lie_subalgebra_equiv_apply] /-- A matrix defining a canonical even-rank symmetric bilinear form. It looks like this as a `2l x 2l` matrix of `l x l` blocks: [ 0 1 ] [ 1 0 ] -/ def JD : matrix (l ⊕ l) (l ⊕ l) R := matrix.from_blocks 0 1 1 0 /-- The classical Lie algebra of type D as a Lie subalgebra of matrices associated to the matrix `JD`. -/ def type_D [fintype l] := skew_adjoint_matrices_lie_subalgebra (JD l R) /-- A matrix transforming the bilinear form defined by the matrix `JD` into a split-signature diagonal matrix. It looks like this as a `2l x 2l` matrix of `l x l` blocks: [ 1 -1 ] [ 1 1 ] -/ def PD : matrix (l ⊕ l) (l ⊕ l) R := matrix.from_blocks 1 (-1) 1 1 /-- The split-signature diagonal matrix. -/ def S := indefinite_diagonal l l R lemma S_as_blocks : S l R = matrix.from_blocks 1 0 0 (-1) := begin rw [← matrix.diagonal_one, matrix.diagonal_neg, matrix.from_blocks_diagonal], refl, end lemma JD_transform [fintype l] : (PD l R)ᵀ ⬝ (JD l R) ⬝ (PD l R) = (2 : R) • (S l R) := begin have h : (PD l R)ᵀ ⬝ (JD l R) = matrix.from_blocks 1 1 1 (-1) := by { simp [PD, JD, matrix.from_blocks_transpose, matrix.from_blocks_multiply], }, erw [h, S_as_blocks, matrix.from_blocks_multiply, matrix.from_blocks_smul], congr; simp [two_smul], end lemma PD_inv [fintype l] [invertible (2 : R)] : (PD l R) * (⅟(2 : R) • (PD l R)ᵀ) = 1 := begin have h : ⅟(2 : R) • (1 : matrix l l R) + ⅟(2 : R) • 1 = 1 := by rw [← smul_add, ← (two_smul R _), smul_smul, inv_of_mul_self, one_smul], erw [matrix.from_blocks_transpose, matrix.from_blocks_smul, matrix.mul_eq_mul, matrix.from_blocks_multiply], simp [h], end instance invertible_PD [fintype l] [invertible (2 : R)] : invertible (PD l R) := invertible_of_right_inverse _ _ (PD_inv l R) /-- An equivalence between two possible definitions of the classical Lie algebra of type D. -/ def type_D_equiv_so' [fintype l] [invertible (2 : R)] : type_D l R ≃ₗ⁅R⁆ so' l l R := begin apply (skew_adjoint_matrices_lie_subalgebra_equiv (JD l R) (PD l R) (by apply_instance)).trans, apply lie_equiv.of_eq, ext A, rw [JD_transform, ← coe_unit_of_invertible (2 : R), ←units.smul_def, lie_subalgebra.mem_coe, mem_skew_adjoint_matrices_lie_subalgebra_unit_smul], refl, end /-- A matrix defining a canonical odd-rank symmetric bilinear form. It looks like this as a `(2l+1) x (2l+1)` matrix of blocks: [ 2 0 0 ] [ 0 0 1 ] [ 0 1 0 ] where sizes of the blocks are: [`1 x 1` `1 x l` `1 x l`] [`l x 1` `l x l` `l x l`] [`l x 1` `l x l` `l x l`] -/ def JB := matrix.from_blocks ((2 : R) • 1 : matrix unit unit R) 0 0 (JD l R) /-- The classical Lie algebra of type B as a Lie subalgebra of matrices associated to the matrix `JB`. -/ def type_B [fintype l] := skew_adjoint_matrices_lie_subalgebra(JB l R) /-- A matrix transforming the bilinear form defined by the matrix `JB` into an almost-split-signature diagonal matrix. It looks like this as a `(2l+1) x (2l+1)` matrix of blocks: [ 1 0 0 ] [ 0 1 -1 ] [ 0 1 1 ] where sizes of the blocks are: [`1 x 1` `1 x l` `1 x l`] [`l x 1` `l x l` `l x l`] [`l x 1` `l x l` `l x l`] -/ def PB := matrix.from_blocks (1 : matrix unit unit R) 0 0 (PD l R) variable [fintype l] lemma PB_inv [invertible (2 : R)] : PB l R * matrix.from_blocks 1 0 0 (⅟(PD l R)) = 1 := begin rw [PB, matrix.mul_eq_mul, matrix.from_blocks_multiply, matrix.mul_inv_of_self], simp only [matrix.mul_zero, matrix.mul_one, matrix.zero_mul, zero_add, add_zero, matrix.from_blocks_one] end instance invertible_PB [invertible (2 : R)] : invertible (PB l R) := invertible_of_right_inverse _ _ (PB_inv l R) lemma JB_transform : (PB l R)ᵀ ⬝ (JB l R) ⬝ (PB l R) = (2 : R) • matrix.from_blocks 1 0 0 (S l R) := by simp [PB, JB, JD_transform, matrix.from_blocks_transpose, matrix.from_blocks_multiply, matrix.from_blocks_smul] lemma indefinite_diagonal_assoc : indefinite_diagonal (unit ⊕ l) l R = matrix.reindex_lie_equiv (equiv.sum_assoc unit l l).symm (matrix.from_blocks 1 0 0 (indefinite_diagonal l l R)) := begin ext i j, rcases i with ⟨⟨i₁ | i₂⟩ | i₃⟩; rcases j with ⟨⟨j₁ | j₂⟩ | j₃⟩; simp only [indefinite_diagonal, matrix.diagonal_apply, equiv.sum_assoc_apply_inl_inl, matrix.reindex_lie_equiv_apply, matrix.submatrix_apply, equiv.symm_symm, matrix.reindex_apply, sum.elim_inl, if_true, eq_self_iff_true, matrix.one_apply_eq, matrix.from_blocks_apply₁₁, dmatrix.zero_apply, equiv.sum_assoc_apply_inl_inr, if_false, matrix.from_blocks_apply₁₂, matrix.from_blocks_apply₂₁, matrix.from_blocks_apply₂₂, equiv.sum_assoc_apply_inr, sum.elim_inr]; congr, end /-- An equivalence between two possible definitions of the classical Lie algebra of type B. -/ def type_B_equiv_so' [invertible (2 : R)] : type_B l R ≃ₗ⁅R⁆ so' (unit ⊕ l) l R := begin apply (skew_adjoint_matrices_lie_subalgebra_equiv (JB l R) (PB l R) (by apply_instance)).trans, symmetry, apply (skew_adjoint_matrices_lie_subalgebra_equiv_transpose (indefinite_diagonal (unit ⊕ l) l R) (matrix.reindex_alg_equiv _ (equiv.sum_assoc punit l l)) (matrix.transpose_reindex _ _)).trans, apply lie_equiv.of_eq, ext A, rw [JB_transform, ← coe_unit_of_invertible (2 : R), ←units.smul_def, lie_subalgebra.mem_coe, lie_subalgebra.mem_coe, mem_skew_adjoint_matrices_lie_subalgebra_unit_smul], simpa [indefinite_diagonal_assoc], end end orthogonal end lie_algebra
d9b0eb972d7391cb699fd2f9aa24838fb1f8c1f2
30b012bb72d640ec30c8fdd4c45fdfa67beb012c
/tactic/default.lean
33eb816f2d47ca7340ce1516ebd4a25dae03167a
[ "Apache-2.0" ]
permissive
kckennylau/mathlib
21fb810b701b10d6606d9002a4004f7672262e83
47b3477e20ffb5a06588dd3abb01fe0fe3205646
refs/heads/master
1,634,976,409,281
1,542,042,832,000
1,542,319,733,000
109,560,458
0
0
Apache-2.0
1,542,369,208,000
1,509,867,494,000
Lean
UTF-8
Lean
false
false
108
lean
import tactic.interactive tactic.alias tactic.finish tactic.mk_iff_of_inductive_prop tactic.wlog
c1f89801e447ef0247d9457d2ea237ddad08d221
57c233acf9386e610d99ed20ef139c5f97504ba3
/src/analysis/calculus/formal_multilinear_series.lean
b0ec2beab6805c24d200bc2d826f320d2b701428
[ "Apache-2.0" ]
permissive
robertylewis/mathlib
3d16e3e6daf5ddde182473e03a1b601d2810952c
1d13f5b932f5e40a8308e3840f96fc882fae01f0
refs/heads/master
1,651,379,945,369
1,644,276,960,000
1,644,276,960,000
98,875,504
0
0
Apache-2.0
1,644,253,514,000
1,501,495,700,000
Lean
UTF-8
Lean
false
false
4,978
lean
/- Copyright (c) 2019 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 analysis.normed_space.multilinear /-! # Formal multilinear series In this file we define `formal_multilinear_series 𝕜 E F` to be a family of `n`-multilinear maps for all `n`, designed to model the sequence of derivatives of a function. In other files we use this notion to define `C^n` functions (called `times_cont_diff` in `mathlib`) and analytic functions. ## Notations We use the notation `E [×n]→L[𝕜] F` for the space of continuous multilinear maps on `E^n` with values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives. ## Tags multilinear, formal series -/ noncomputable theory open set fin open_locale topological_space variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜] {E : Type*} [normed_group E] [normed_space 𝕜 E] {F : Type*} [normed_group F] [normed_space 𝕜 F] {G : Type*} [normed_group G] [normed_space 𝕜 G] /-- A formal multilinear series over a field `𝕜`, from `E` to `F`, is given by a family of multilinear maps from `E^n` to `F` for all `n`. -/ @[derive add_comm_group] def formal_multilinear_series (𝕜 : Type*) [nondiscrete_normed_field 𝕜] (E : Type*) [normed_group E] [normed_space 𝕜 E] (F : Type*) [normed_group F] [normed_space 𝕜 F] := Π (n : ℕ), (E [×n]→L[𝕜] F) instance : inhabited (formal_multilinear_series 𝕜 E F) := ⟨0⟩ section module /- `derive` is not able to find the module structure, probably because Lean is confused by the dependent types. We register it explicitly. -/ local attribute [reducible] formal_multilinear_series instance : module 𝕜 (formal_multilinear_series 𝕜 E F) := begin letI : ∀ n, module 𝕜 (continuous_multilinear_map 𝕜 (λ (i : fin n), E) F) := λ n, by apply_instance, apply_instance end end module namespace formal_multilinear_series variables (p : formal_multilinear_series 𝕜 E F) /-- Forgetting the zeroth term in a formal multilinear series, and interpreting the following terms as multilinear maps into `E →L[𝕜] F`. If `p` corresponds to the Taylor series of a function, then `p.shift` is the Taylor series of the derivative of the function. -/ def shift : formal_multilinear_series 𝕜 E (E →L[𝕜] F) := λn, (p n.succ).curry_right /-- Adding a zeroth term to a formal multilinear series taking values in `E →L[𝕜] F`. This corresponds to starting from a Taylor series for the derivative of a function, and building a Taylor series for the function itself. -/ def unshift (q : formal_multilinear_series 𝕜 E (E →L[𝕜] F)) (z : F) : formal_multilinear_series 𝕜 E F | 0 := (continuous_multilinear_curry_fin0 𝕜 E F).symm z | (n + 1) := continuous_multilinear_curry_right_equiv' 𝕜 n E F (q n) /-- Killing the zeroth coefficient in a formal multilinear series -/ def remove_zero (p : formal_multilinear_series 𝕜 E F) : formal_multilinear_series 𝕜 E F | 0 := 0 | (n + 1) := p (n + 1) @[simp] lemma remove_zero_coeff_zero : p.remove_zero 0 = 0 := rfl @[simp] lemma remove_zero_coeff_succ (n : ℕ) : p.remove_zero (n+1) = p (n+1) := rfl lemma remove_zero_of_pos {n : ℕ} (h : 0 < n) : p.remove_zero n = p n := by { rw ← nat.succ_pred_eq_of_pos h, refl } /-- Convenience congruence lemma stating in a dependent setting that, if the arguments to a formal multilinear series are equal, then the values are also equal. -/ lemma congr (p : formal_multilinear_series 𝕜 E F) {m n : ℕ} {v : fin m → E} {w : fin n → E} (h1 : m = n) (h2 : ∀ (i : ℕ) (him : i < m) (hin : i < n), v ⟨i, him⟩ = w ⟨i, hin⟩) : p m v = p n w := by { cases h1, congr' with ⟨i, hi⟩, exact h2 i hi hi } /-- Composing each term `pₙ` in a formal multilinear series with `(u, ..., u)` where `u` is a fixed continuous linear map, gives a new formal multilinear series `p.comp_continuous_linear_map u`. -/ def comp_continuous_linear_map (p : formal_multilinear_series 𝕜 F G) (u : E →L[𝕜] F) : formal_multilinear_series 𝕜 E G := λ n, (p n).comp_continuous_linear_map (λ (i : fin n), u) @[simp] lemma comp_continuous_linear_map_apply (p : formal_multilinear_series 𝕜 F G) (u : E →L[𝕜] F) (n : ℕ) (v : fin n → E) : (p.comp_continuous_linear_map u) n v = p n (u ∘ v) := rfl variables (𝕜) {𝕜' : Type*} [nondiscrete_normed_field 𝕜'] [normed_algebra 𝕜 𝕜'] variables [normed_space 𝕜' E] [is_scalar_tower 𝕜 𝕜' E] variables [normed_space 𝕜' F] [is_scalar_tower 𝕜 𝕜' F] /-- Reinterpret a formal `𝕜'`-multilinear series as a formal `𝕜`-multilinear series, where `𝕜'` is a normed algebra over `𝕜`. -/ @[simp] protected def restrict_scalars (p : formal_multilinear_series 𝕜' E F) : formal_multilinear_series 𝕜 E F := λ n, (p n).restrict_scalars 𝕜 end formal_multilinear_series
4a46a4403ad3f7a9e35ef34557728b5fd26c7689
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/revert_frozen_dep.lean
28fe85e04c3f22df6914bb1f87380859ecccf56a
[ "Apache-2.0" ]
permissive
leanprover-community/lean
12b87f69d92e614daea8bcc9d4de9a9ace089d0e
cce7990ea86a78bdb383e38ed7f9b5ba93c60ce0
refs/heads/master
1,687,508,156,644
1,684,951,104,000
1,684,951,104,000
169,960,991
457
107
Apache-2.0
1,686,744,372,000
1,549,790,268,000
C++
UTF-8
Lean
false
false
145
lean
lemma ex {α : id Type} [has_add α] : true := begin dsimp at α -- should fail because the frozen instance `[has_add α]` depends on `α` end
fc10d4390c6c78fddaf3fbcb220d88d6576fdf6e
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/category_theory/sites/grothendieck_auto.lean
903b3a1addaca88a930acaf0fa46fd48368e0985
[]
no_license
AurelienSaue/Mathlib4_auto
f538cfd0980f65a6361eadea39e6fc639e9dae14
590df64109b08190abe22358fabc3eae000943f2
refs/heads/master
1,683,906,849,776
1,622,564,669,000
1,622,564,669,000
371,723,747
0
0
null
null
null
null
UTF-8
Lean
false
false
13,260
lean
/- Copyright (c) 2020 Bhavik Mehta, E. W. Ayers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta, E. W. Ayers -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.category_theory.sites.sieves import Mathlib.category_theory.limits.shapes.pullbacks import Mathlib.order.copy import Mathlib.PostPort universes v u l namespace Mathlib /-! # Grothendieck topologies Definition and lemmas about Grothendieck topologies. A Grothendieck topology for a category `C` is a set of sieves on each object `X` satisfying certain closure conditions. Alternate versions of the axioms (in arrow form) are also described. Two explicit examples of Grothendieck topologies are given: * The dense topology * The atomic topology as well as the complete lattice structure on Grothendieck topologies (which gives two additional explicit topologies: the discrete and trivial topologies.) A pretopology, or a basis for a topology is defined in `pretopology.lean`. The topology associated to a topological space is defined in `spaces.lean`. ## Tags Grothendieck topology, coverage, pretopology, site ## References * [https://ncatlab.org/nlab/show/Grothendieck+topology][nlab] * [S. MacLane, I. Moerdijk, *Sheaves in Geometry and Logic*][MM91] ## Implementation notes We use the definition of [nlab] and [MM91](Chapter III, Section 2), where Grothendieck topologies are saturated collections of morphisms, rather than the notions of the Stacks project (00VG) and the Elephant, in which topologies are allowed to be unsaturated, and are then completed. TODO (BM): Add the definition from Stacks, as a pretopology, and complete to a topology. This is so that we can produce a bijective correspondence between Grothendieck topologies on a small category and Lawvere-Tierney topologies on its presheaf topos, as well as the equivalence between Grothendieck topoi and left exact reflective subcategories of presheaf toposes. -/ namespace category_theory /-- The definition of a Grothendieck topology: a set of sieves `J X` on each object `X` satisfying three axioms: 1. For every object `X`, the maximal sieve is in `J X`. 2. If `S ∈ J X` then its pullback along any `h : Y ⟶ X` is in `J Y`. 3. If `S ∈ J X` and `R` is a sieve on `X`, then provided that the pullback of `R` along any arrow `f : Y ⟶ X` in `S` is in `J Y`, we have that `R` itself is in `J X`. A sieve `S` on `X` is referred to as `J`-covering, (or just covering), if `S ∈ J X`. See https://stacks.math.columbia.edu/tag/00Z4, or [nlab], or [MM92] Chapter III, Section 2, Definition 1. -/ structure grothendieck_topology (C : Type u) [category C] where sieves : (X : C) → set (sieve X) top_mem' : ∀ (X : C), ⊤ ∈ sieves X pullback_stable' : ∀ {X Y : C} {S : sieve X} (f : Y ⟶ X), S ∈ sieves X → sieve.pullback f S ∈ sieves Y transitive' : ∀ {X : C} {S : sieve X}, S ∈ sieves X → ∀ (R : sieve X), (∀ {Y : C} {f : Y ⟶ X}, coe_fn S Y f → sieve.pullback f R ∈ sieves Y) → R ∈ sieves X namespace grothendieck_topology protected instance has_coe_to_fun (C : Type u) [category C] : has_coe_to_fun (grothendieck_topology C) := has_coe_to_fun.mk (fun (J : grothendieck_topology C) => (X : C) → set (sieve X)) fun (J : grothendieck_topology C) => sieves J /-- An extensionality lemma in terms of the coercion to a pi-type. We prove this explicitly rather than deriving it so that it is in terms of the coercion rather than the projection `.sieves`. -/ theorem ext {C : Type u} [category C] {J₁ : grothendieck_topology C} {J₂ : grothendieck_topology C} (h : ⇑J₁ = ⇑J₂) : J₁ = J₂ := sorry @[simp] theorem mem_sieves_iff_coe {C : Type u} [category C] {X : C} {S : sieve X} (J : grothendieck_topology C) : S ∈ sieves J X ↔ S ∈ coe_fn J X := iff.rfl -- Also known as the maximality axiom. -- Also known as the stability axiom. @[simp] theorem top_mem {C : Type u} [category C] (J : grothendieck_topology C) (X : C) : ⊤ ∈ coe_fn J X := top_mem' J X @[simp] theorem pullback_stable {C : Type u} [category C] {X : C} {Y : C} {S : sieve X} (J : grothendieck_topology C) (f : Y ⟶ X) (hS : S ∈ coe_fn J X) : sieve.pullback f S ∈ coe_fn J Y := pullback_stable' J f hS theorem transitive {C : Type u} [category C] {X : C} {S : sieve X} (J : grothendieck_topology C) (hS : S ∈ coe_fn J X) (R : sieve X) (h : ∀ {Y : C} {f : Y ⟶ X}, coe_fn S Y f → sieve.pullback f R ∈ coe_fn J Y) : R ∈ coe_fn J X := transitive' J hS R h theorem covering_of_eq_top {C : Type u} [category C] {X : C} {S : sieve X} (J : grothendieck_topology C) : S = ⊤ → S ∈ coe_fn J X := fun (h : S = ⊤) => Eq.symm h ▸ top_mem J X /-- If `S` is a subset of `R`, and `S` is covering, then `R` is covering as well. See https://stacks.math.columbia.edu/tag/00Z5 (2), or discussion after [MM92] Chapter III, Section 2, Definition 1. -/ theorem superset_covering {C : Type u} [category C] {X : C} {S : sieve X} {R : sieve X} (J : grothendieck_topology C) (Hss : S ≤ R) (sjx : S ∈ coe_fn J X) : R ∈ coe_fn J X := sorry /-- The intersection of two covering sieves is covering. See https://stacks.math.columbia.edu/tag/00Z5 (1), or [MM92] Chapter III, Section 2, Definition 1 (iv). -/ theorem intersection_covering {C : Type u} [category C] {X : C} {S : sieve X} {R : sieve X} (J : grothendieck_topology C) (rj : R ∈ coe_fn J X) (sj : S ∈ coe_fn J X) : R ⊓ S ∈ coe_fn J X := sorry @[simp] theorem intersection_covering_iff {C : Type u} [category C] {X : C} {S : sieve X} {R : sieve X} (J : grothendieck_topology C) : R ⊓ S ∈ coe_fn J X ↔ R ∈ coe_fn J X ∧ S ∈ coe_fn J X := sorry theorem bind_covering {C : Type u} [category C] {X : C} (J : grothendieck_topology C) {S : sieve X} {R : {Y : C} → {f : Y ⟶ X} → coe_fn S Y f → sieve Y} (hS : S ∈ coe_fn J X) (hR : ∀ {Y : C} {f : Y ⟶ X} (H : coe_fn S Y f), R H ∈ coe_fn J Y) : sieve.bind (⇑S) R ∈ coe_fn J X := transitive J hS (sieve.bind (⇑S) R) fun (Y : C) (f : Y ⟶ X) (hf : coe_fn S Y f) => superset_covering J (sieve.le_pullback_bind (⇑S) R f hf) (hR hf) /-- The sieve `S` on `X` `J`-covers an arrow `f` to `X` if `S.pullback f ∈ J Y`. This definition is an alternate way of presenting a Grothendieck topology. -/ def covers {C : Type u} [category C] {X : C} {Y : C} (J : grothendieck_topology C) (S : sieve X) (f : Y ⟶ X) := sieve.pullback f S ∈ coe_fn J Y theorem covers_iff {C : Type u} [category C] {X : C} {Y : C} (J : grothendieck_topology C) (S : sieve X) (f : Y ⟶ X) : covers J S f ↔ sieve.pullback f S ∈ coe_fn J Y := iff.rfl theorem covering_iff_covers_id {C : Type u} [category C] {X : C} (J : grothendieck_topology C) (S : sieve X) : S ∈ coe_fn J X ↔ covers J S 𝟙 := sorry /-- The maximality axiom in 'arrow' form: Any arrow `f` in `S` is covered by `S`. -/ theorem arrow_max {C : Type u} [category C] {X : C} {Y : C} (J : grothendieck_topology C) (f : Y ⟶ X) (S : sieve X) (hf : coe_fn S Y f) : covers J S f := eq.mpr (id (Eq._oldrec (Eq.refl (covers J S f)) (covers.equations._eqn_1 J S f))) (eq.mpr (id (Eq._oldrec (Eq.refl (sieve.pullback f S ∈ coe_fn J Y)) (iff.mp (sieve.pullback_eq_top_iff_mem f) hf))) (top_mem J Y)) /-- The stability axiom in 'arrow' form: If `S` covers `f` then `S` covers `g ≫ f` for any `g`. -/ theorem arrow_stable {C : Type u} [category C] {X : C} {Y : C} (J : grothendieck_topology C) (f : Y ⟶ X) (S : sieve X) (h : covers J S f) {Z : C} (g : Z ⟶ Y) : covers J S (g ≫ f) := sorry /-- The transitivity axiom in 'arrow' form: If `S` covers `f` and every arrow in `S` is covered by `R`, then `R` covers `f`. -/ theorem arrow_trans {C : Type u} [category C] {X : C} {Y : C} (J : grothendieck_topology C) (f : Y ⟶ X) (S : sieve X) (R : sieve X) (h : covers J S f) : (∀ {Z : C} (g : Z ⟶ X), coe_fn S Z g → covers J R g) → covers J R f := sorry theorem arrow_intersect {C : Type u} [category C] {X : C} {Y : C} (J : grothendieck_topology C) (f : Y ⟶ X) (S : sieve X) (R : sieve X) (hS : covers J S f) (hR : covers J R f) : covers J (S ⊓ R) f := sorry /-- The trivial Grothendieck topology, in which only the maximal sieve is covering. This topology is also known as the indiscrete, coarse, or chaotic topology. See [MM92] Chapter III, Section 2, example (a), or https://en.wikipedia.org/wiki/Grothendieck_topology#The_discrete_and_indiscrete_topologies -/ def trivial (C : Type u) [category C] : grothendieck_topology C := mk (fun (X : C) => singleton ⊤) sorry sorry sorry /-- The discrete Grothendieck topology, in which every sieve is covering. See https://en.wikipedia.org/wiki/Grothendieck_topology#The_discrete_and_indiscrete_topologies. -/ def discrete (C : Type u) [category C] : grothendieck_topology C := mk (fun (X : C) => set.univ) sorry sorry sorry theorem trivial_covering {C : Type u} [category C] {X : C} {S : sieve X} : S ∈ coe_fn (trivial C) X ↔ S = ⊤ := set.mem_singleton_iff /-- See https://stacks.math.columbia.edu/tag/00Z6 -/ protected instance partial_order {C : Type u} [category C] : partial_order (grothendieck_topology C) := partial_order.mk (fun (J₁ J₂ : grothendieck_topology C) => ⇑J₁ ≤ ⇑J₂) (preorder.lt._default fun (J₁ J₂ : grothendieck_topology C) => ⇑J₁ ≤ ⇑J₂) sorry sorry sorry /-- See https://stacks.math.columbia.edu/tag/00Z7 -/ protected instance has_Inf {C : Type u} [category C] : has_Inf (grothendieck_topology C) := has_Inf.mk fun (T : set (grothendieck_topology C)) => mk (Inf (sieves '' T)) sorry sorry sorry /-- See https://stacks.math.columbia.edu/tag/00Z7 -/ theorem is_glb_Inf {C : Type u} [category C] (s : set (grothendieck_topology C)) : is_glb s (Inf s) := is_glb.of_image (fun (x y : grothendieck_topology C) => iff.refl (sieves x ≤ sieves y)) (is_glb_Inf (sieves '' s)) /-- Construct a complete lattice from the `Inf`, but make the trivial and discrete topologies definitionally equal to the bottom and top respectively. -/ protected instance complete_lattice {C : Type u} [category C] : complete_lattice (grothendieck_topology C) := complete_lattice.copy (complete_lattice_of_Inf (grothendieck_topology C) is_glb_Inf) complete_lattice.le sorry (discrete C) sorry (trivial C) sorry complete_lattice.sup sorry complete_lattice.inf sorry complete_lattice.Sup sorry Inf sorry protected instance inhabited {C : Type u} [category C] : Inhabited (grothendieck_topology C) := { default := ⊤ } @[simp] theorem trivial_eq_bot {C : Type u} [category C] : trivial C = ⊥ := rfl @[simp] theorem discrete_eq_top {C : Type u} [category C] : discrete C = ⊤ := rfl @[simp] theorem bot_covering {C : Type u} [category C] {X : C} {S : sieve X} : S ∈ coe_fn ⊥ X ↔ S = ⊤ := trivial_covering @[simp] theorem top_covering {C : Type u} [category C] {X : C} {S : sieve X} : S ∈ coe_fn ⊤ X := True.intro theorem bot_covers {C : Type u} [category C] {X : C} {Y : C} (S : sieve X) (f : Y ⟶ X) : covers ⊥ S f ↔ coe_fn S Y f := sorry @[simp] theorem top_covers {C : Type u} [category C] {X : C} {Y : C} (S : sieve X) (f : Y ⟶ X) : covers ⊤ S f := eq.mpr (id (Eq.trans (propext (covers_iff ⊤ S f)) (propext (iff_true_intro top_covering)))) trivial /-- The dense Grothendieck topology. See https://ncatlab.org/nlab/show/dense+topology, or [MM92] Chapter III, Section 2, example (e). -/ def dense {C : Type u} [category C] : grothendieck_topology C := mk (fun (X : C) (S : sieve X) => ∀ {Y : C} (f : Y ⟶ X), ∃ (Z : C), ∃ (g : Z ⟶ Y), coe_fn S Z (g ≫ f)) sorry sorry sorry theorem dense_covering {C : Type u} [category C] {X : C} {S : sieve X} : S ∈ coe_fn dense X ↔ ∀ {Y : C} (f : Y ⟶ X), ∃ (Z : C), ∃ (g : Z ⟶ Y), coe_fn S Z (g ≫ f) := iff.rfl /-- A category satisfies the right Ore condition if any span can be completed to a commutative square. NB. Any category with pullbacks obviously satisfies the right Ore condition, see `right_ore_of_pullbacks`. -/ def right_ore_condition (C : Type u) [category C] := ∀ {X Y Z : C} (yx : Y ⟶ X) (zx : Z ⟶ X), ∃ (W : C), ∃ (wy : W ⟶ Y), ∃ (wz : W ⟶ Z), wy ≫ yx = wz ≫ zx theorem right_ore_of_pullbacks {C : Type u} [category C] [limits.has_pullbacks C] : right_ore_condition C := fun (X Y Z : C) (yx : Y ⟶ X) (zx : Z ⟶ X) => Exists.intro (limits.pullback yx zx) (Exists.intro limits.pullback.fst (Exists.intro limits.pullback.snd limits.pullback.condition)) /-- The atomic Grothendieck topology: a sieve is covering iff it is nonempty. For the pullback stability condition, we need the right Ore condition to hold. See https://ncatlab.org/nlab/show/atomic+site, or [MM92] Chapter III, Section 2, example (f). -/ def atomic {C : Type u} [category C] (hro : right_ore_condition C) : grothendieck_topology C := mk (fun (X : C) (S : sieve X) => ∃ (Y : C), ∃ (f : Y ⟶ X), coe_fn S Y f) sorry sorry sorry end Mathlib
bc670f9be478cbf0de69497c85e27aa7925cde2c
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/category_theory/abelian/diagram_lemmas/four_auto.lean
a3bbe6eafa56e786f20ead35581ec2510482cb8a
[]
no_license
AurelienSaue/Mathlib4_auto
f538cfd0980f65a6361eadea39e6fc639e9dae14
590df64109b08190abe22358fabc3eae000943f2
refs/heads/master
1,683,906,849,776
1,622,564,669,000
1,622,564,669,000
371,723,747
0
0
null
null
null
null
UTF-8
Lean
false
false
1,790
lean
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.category_theory.abelian.pseudoelements import Mathlib.PostPort universes v u namespace Mathlib /-! # The four lemma Consider the following commutative diagram with exact rows in an abelian category: A ---f--> B ---g--> C ---h--> D | | | | α β γ δ | | | | v v v v A' --f'-> B' --g'-> C' --h'-> D' We prove the "mono" version of the four lemma: if α is an epimorphism and β and δ are monomorphisms, then γ is a monomorphism. ## Future work The "epi" four lemma and the five lemma, which is then an easy corollary. ## Tags four lemma, diagram lemma, diagram chase -/ namespace category_theory.abelian /-- The four lemma, mono version. For names of objects and morphisms, consider the following diagram: ``` A ---f--> B ---g--> C ---h--> D | | | | α β γ δ | | | | v v v v A' --f'-> B' --g'-> C' --h'-> D' ``` -/ theorem mono_of_epi_of_mono_of_mono {V : Type u} [category V] [abelian V] {A : V} {B : V} {C : V} {D : V} {A' : V} {B' : V} {C' : V} {D' : V} {f : A ⟶ B} {g : B ⟶ C} {h : C ⟶ D} {f' : A' ⟶ B'} {g' : B' ⟶ C'} {h' : C' ⟶ D'} {α : A ⟶ A'} {β : B ⟶ B'} {γ : C ⟶ C'} {δ : D ⟶ D'} [exact f g] [exact g h] [exact f' g'] (comm₁ : α ≫ f' = f ≫ β) (comm₂ : β ≫ g' = g ≫ γ) (comm₃ : γ ≫ h' = h ≫ δ) (hα : epi α) (hβ : mono β) (hδ : mono δ) : mono γ := sorry end Mathlib
8fefc09566cf4fa445ecd8d2b270b5116d4ba2af
02005f45e00c7ecf2c8ca5db60251bd1e9c860b5
/src/linear_algebra/basic.lean
3916681bb45c5543db8d7e6ec4ec4e1aa957f311
[ "Apache-2.0" ]
permissive
anthony2698/mathlib
03cd69fe5c280b0916f6df2d07c614c8e1efe890
407615e05814e98b24b2ff322b14e8e3eb5e5d67
refs/heads/master
1,678,792,774,873
1,614,371,563,000
1,614,371,563,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
96,682
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, Kevin Buzzard, Yury Kudryashov -/ import algebra.big_operators.pi import algebra.module.pi import algebra.module.prod import algebra.module.submodule import algebra.group.prod import data.finsupp.basic import data.dfinsupp import algebra.pointwise import order.compactly_generated /-! # Linear algebra This file defines the basics of linear algebra. It sets up the "categorical/lattice structure" of modules over a ring, submodules, and linear maps. If `p` and `q` are submodules of a module, `p ≤ q` means that `p ⊆ q`. Many of the relevant definitions, including `module`, `submodule`, and `linear_map`, are found in `src/algebra/module`. ## Main definitions * Many constructors for linear maps * `submodule.span s` is defined to be the smallest submodule containing the set `s`. * If `p` is a submodule of `M`, `submodule.quotient p` is the quotient of `M` with respect to `p`: that is, elements of `M` are identified if their difference is in `p`. This is itself a module. * The kernel `ker` and range `range` of a linear map are submodules of the domain and codomain respectively. * The general linear group is defined to be the group of invertible linear maps from `M` to itself. ## Main statements * The first and second isomorphism laws for modules are proved as `quot_ker_equiv_range` and `quotient_inf_equiv_sup_quotient`. ## Notations * We continue to use the notation `M →ₗ[R] M₂` for the type of linear maps from `M` to `M₂` over the ring `R`. * We introduce the notations `M ≃ₗ M₂` and `M ≃ₗ[R] M₂` for `linear_equiv M M₂`. In the first, the ring `R` is implicit. * We introduce the notation `R ∙ v` for the span of a singleton, `submodule.span R {v}`. This is `\.`, not the same as the scalar multiplication `•`/`\bub`. ## Implementation notes We note that, when constructing linear maps, it is convenient to use operations defined on bundled maps (`linear_map.prod`, `linear_map.coprod`, arithmetic operations like `+`) instead of defining a function and proving it is linear. ## Tags linear algebra, vector space, module -/ open function open_locale big_operators universes u v w x y z u' v' w' y' variables {R : Type u} {K : Type u'} {M : Type v} {V : Type v'} {M₂ : Type w} {V₂ : Type w'} variables {M₃ : Type y} {V₃ : Type y'} {M₄ : Type z} {ι : Type x} namespace finsupp lemma smul_sum {α : Type u} {β : Type v} {R : Type w} {M : Type y} [has_zero β] [semiring R] [add_comm_monoid M] [semimodule R M] {v : α →₀ β} {c : R} {h : α → β → M} : c • (v.sum h) = v.sum (λa b, c • h a b) := finset.smul_sum end finsupp section open_locale classical /-- decomposing `x : ι → R` as a sum along the canonical basis -/ lemma pi_eq_sum_univ {ι : Type u} [fintype ι] {R : Type v} [semiring R] (x : ι → R) : x = ∑ i, x i • (λj, if i = j then 1 else 0) := by { ext, simp } end /-! ### Properties of linear maps -/ namespace linear_map section add_comm_monoid variables [semiring R] variables [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃] [add_comm_monoid M₄] variables [semimodule R M] [semimodule R M₂] [semimodule R M₃] [semimodule R M₄] variables (f g : M →ₗ[R] M₂) include R @[simp] theorem comp_id : f.comp id = f := linear_map.ext $ λ x, rfl @[simp] theorem id_comp : id.comp f = f := linear_map.ext $ λ x, rfl theorem comp_assoc (g : M₂ →ₗ[R] M₃) (h : M₃ →ₗ[R] M₄) : (h.comp g).comp f = h.comp (g.comp f) := rfl /-- The restriction of a linear map `f : M → M₂` to a submodule `p ⊆ M` gives a linear map `p → M₂`. -/ def dom_restrict (f : M →ₗ[R] M₂) (p : submodule R M) : p →ₗ[R] M₂ := f.comp p.subtype @[simp] lemma dom_restrict_apply (f : M →ₗ[R] M₂) (p : submodule R M) (x : p) : f.dom_restrict p x = f x := rfl /-- A linear map `f : M₂ → M` whose values lie in a submodule `p ⊆ M` can be restricted to a linear map M₂ → p. -/ def cod_restrict (p : submodule R M) (f : M₂ →ₗ[R] M) (h : ∀c, f c ∈ p) : M₂ →ₗ[R] p := by refine {to_fun := λc, ⟨f c, h c⟩, ..}; intros; apply set_coe.ext; simp @[simp] theorem cod_restrict_apply (p : submodule R M) (f : M₂ →ₗ[R] M) {h} (x : M₂) : (cod_restrict p f h x : M) = f x := rfl @[simp] lemma comp_cod_restrict (p : submodule R M₂) (h : ∀b, f b ∈ p) (g : M₃ →ₗ[R] M) : (cod_restrict p f h).comp g = cod_restrict p (f.comp g) (assume b, h _) := ext $ assume b, rfl @[simp] lemma subtype_comp_cod_restrict (p : submodule R M₂) (h : ∀b, f b ∈ p) : p.subtype.comp (cod_restrict p f h) = f := ext $ assume b, rfl /-- Restrict domain and codomain of an endomorphism. -/ def restrict (f : M →ₗ[R] M) {p : submodule R M} (hf : ∀ x ∈ p, f x ∈ p) : p →ₗ[R] p := (f.dom_restrict p).cod_restrict p $ submodule.forall.2 hf lemma restrict_apply {f : M →ₗ[R] M} {p : submodule R M} (hf : ∀ x ∈ p, f x ∈ p) (x : p) : f.restrict hf x = ⟨f x, hf x.1 x.2⟩ := rfl lemma subtype_comp_restrict {f : M →ₗ[R] M} {p : submodule R M} (hf : ∀ x ∈ p, f x ∈ p) : p.subtype.comp (f.restrict hf) = f.dom_restrict p := rfl lemma restrict_eq_cod_restrict_dom_restrict {f : M →ₗ[R] M} {p : submodule R M} (hf : ∀ x ∈ p, f x ∈ p) : f.restrict hf = (f.dom_restrict p).cod_restrict p (λ x, hf x.1 x.2) := rfl lemma restrict_eq_dom_restrict_cod_restrict {f : M →ₗ[R] M} {p : submodule R M} (hf : ∀ x, f x ∈ p) : f.restrict (λ x _, hf x) = (f.cod_restrict p hf).dom_restrict p := rfl /-- The constant 0 map is linear. -/ instance : has_zero (M →ₗ[R] M₂) := ⟨⟨λ _, 0, by simp, by simp⟩⟩ instance : inhabited (M →ₗ[R] M₂) := ⟨0⟩ @[simp] lemma zero_apply (x : M) : (0 : M →ₗ[R] M₂) x = 0 := rfl @[simp] lemma default_def : default (M →ₗ[R] M₂) = 0 := rfl instance unique_of_left [subsingleton M] : unique (M →ₗ[R] M₂) := { uniq := λ f, ext $ λ x, by rw [subsingleton.elim x 0, map_zero, map_zero], .. linear_map.inhabited } instance unique_of_right [subsingleton M₂] : unique (M →ₗ[R] M₂) := coe_injective.unique /-- The sum of two linear maps is linear. -/ instance : has_add (M →ₗ[R] M₂) := ⟨λ f g, ⟨λ b, f b + g b, by simp [add_comm, add_left_comm], by simp [smul_add]⟩⟩ @[simp] lemma add_apply (x : M) : (f + g) x = f x + g x := rfl /-- The type of linear maps is an additive monoid. -/ instance : add_comm_monoid (M →ₗ[R] M₂) := by refine {zero := 0, add := (+), ..}; intros; ext; simp [add_comm, add_left_comm] instance linear_map_apply_is_add_monoid_hom (a : M) : is_add_monoid_hom (λ f : M →ₗ[R] M₂, f a) := { map_add := λ f g, linear_map.add_apply f g a, map_zero := rfl } lemma add_comp (g : M₂ →ₗ[R] M₃) (h : M₂ →ₗ[R] M₃) : (h + g).comp f = h.comp f + g.comp f := rfl lemma comp_add (g : M →ₗ[R] M₂) (h : M₂ →ₗ[R] M₃) : h.comp (f + g) = h.comp f + h.comp g := by { ext, simp } lemma sum_apply (t : finset ι) (f : ι → M →ₗ[R] M₂) (b : M) : (∑ d in t, f d) b = ∑ d in t, f d b := (t.sum_hom (λ g : M →ₗ[R] M₂, g b)).symm section smul_right variables {S : Type*} [semiring S] [semimodule R S] [semimodule S M] [is_scalar_tower R S M] /-- When `f` is an `R`-linear map taking values in `S`, then `λb, f b • x` is an `R`-linear map. -/ def smul_right (f : M₂ →ₗ[R] S) (x : M) : M₂ →ₗ[R] M := { to_fun := λb, f b • x, map_add' := λ x y, by rw [f.map_add, add_smul], map_smul' := λ b y, by rw [f.map_smul, smul_assoc] } @[simp] theorem smul_right_apply (f : M₂ →ₗ[R] S) (x : M) (c : M₂) : smul_right f x c = f c • x := rfl end smul_right instance : has_one (M →ₗ[R] M) := ⟨linear_map.id⟩ instance : has_mul (M →ₗ[R] M) := ⟨linear_map.comp⟩ lemma mul_eq_comp (f g : M →ₗ[R] M) : f * g = f.comp g := rfl @[simp] lemma one_app (x : M) : (1 : M →ₗ[R] M) x = x := rfl @[simp] lemma mul_app (A B : M →ₗ[R] M) (x : M) : (A * B) x = A (B x) := rfl @[simp] theorem comp_zero : f.comp (0 : M₃ →ₗ[R] M) = 0 := ext $ assume c, by rw [comp_apply, zero_apply, zero_apply, f.map_zero] @[simp] theorem zero_comp : (0 : M₂ →ₗ[R] M₃).comp f = 0 := rfl @[simp, norm_cast] lemma coe_fn_sum {ι : Type*} (t : finset ι) (f : ι → M →ₗ[R] M₂) : ⇑(∑ i in t, f i) = ∑ i in t, (f i : M → M₂) := add_monoid_hom.map_sum ⟨@to_fun R M M₂ _ _ _ _ _, rfl, λ x y, rfl⟩ _ _ instance : monoid (M →ₗ[R] M) := by refine {mul := (*), one := 1, ..}; { intros, apply linear_map.ext, simp {proj := ff} } section open_locale classical /-- A linear map `f` applied to `x : ι → R` can be computed using the image under `f` of elements of the canonical basis. -/ lemma pi_apply_eq_sum_univ [fintype ι] (f : (ι → R) →ₗ[R] M) (x : ι → R) : f x = ∑ i, x i • (f (λj, if i = j then 1 else 0)) := begin conv_lhs { rw [pi_eq_sum_univ x, f.map_sum] }, apply finset.sum_congr rfl (λl hl, _), rw f.map_smul end end end add_comm_monoid section add_comm_group variables [semiring R] [add_comm_monoid M] [add_comm_group M₂] [add_comm_group M₃] [add_comm_group M₄] [semimodule R M] [semimodule R M₂] [semimodule R M₃] [semimodule R M₄] (f g : M →ₗ[R] M₂) /-- The negation of a linear map is linear. -/ instance : has_neg (M →ₗ[R] M₂) := ⟨λ f, ⟨λ b, - f b, by simp [add_comm], by simp⟩⟩ @[simp] lemma neg_apply (x : M) : (- f) x = - f x := rfl @[simp] lemma comp_neg (g : M₂ →ₗ[R] M₃) : g.comp (- f) = - g.comp f := by { ext, simp } /-- The negation of a linear map is linear. -/ instance : has_sub (M →ₗ[R] M₂) := ⟨λ f g, ⟨λ b, f b - g b, by { simp only [map_add, sub_eq_add_neg, neg_add], cc }, by { intros, simp only [map_smul, smul_sub] }⟩⟩ @[simp] lemma sub_apply (x : M) : (f - g) x = f x - g x := rfl lemma sub_comp (g : M₂ →ₗ[R] M₃) (h : M₂ →ₗ[R] M₃) : (g - h).comp f = g.comp f - h.comp f := rfl lemma comp_sub (g : M →ₗ[R] M₂) (h : M₂ →ₗ[R] M₃) : h.comp (g - f) = h.comp g - h.comp f := by { ext, simp } /-- The type of linear maps is an additive group. -/ instance : add_comm_group (M →ₗ[R] M₂) := by refine {zero := 0, add := (+), neg := has_neg.neg, sub := has_sub.sub, sub_eq_add_neg := _, ..}; intros; ext; simp [add_comm, add_left_comm, sub_eq_add_neg] instance linear_map_apply_is_add_group_hom (a : M) : is_add_group_hom (λ f : M →ₗ[R] M₂, f a) := { map_add := λ f g, linear_map.add_apply f g a } end add_comm_group section has_scalar variables {S : Type*} [semiring R] [monoid S] [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃] [semimodule R M] [semimodule R M₂] [semimodule R M₃] [distrib_mul_action S M₂] [smul_comm_class R S M₂] (f : M →ₗ[R] M₂) instance : has_scalar S (M →ₗ[R] M₂) := ⟨λ a f, ⟨λ b, a • f b, λ x y, by rw [f.map_add, smul_add], λ c x, by simp only [f.map_smul, smul_comm c]⟩⟩ @[simp] lemma smul_apply (a : S) (x : M) : (a • f) x = a • f x := rfl instance {T : Type*} [monoid T] [distrib_mul_action T M₂] [smul_comm_class R T M₂] [smul_comm_class S T M₂] : smul_comm_class S T (M →ₗ[R] M₂) := ⟨λ a b f, ext $ λ x, smul_comm _ _ _⟩ instance : distrib_mul_action S (M →ₗ[R] M₂) := { one_smul := λ f, ext $ λ _, one_smul _ _, mul_smul := λ c c' f, ext $ λ _, mul_smul _ _ _, smul_add := λ c f g, ext $ λ x, smul_add _ _ _, smul_zero := λ c, ext $ λ x, smul_zero _ } theorem smul_comp (a : S) (g : M₃ →ₗ[R] M₂) (f : M →ₗ[R] M₃) : (a • g).comp f = a • (g.comp f) := rfl end has_scalar section semimodule variables {S : Type*} [semiring R] [semiring S] [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃] [semimodule R M] [semimodule R M₂] [semimodule R M₃] [semimodule S M₂] [semimodule S M₃] [smul_comm_class R S M₂] [smul_comm_class R S M₃] (f : M →ₗ[R] M₂) instance : semimodule S (M →ₗ[R] M₂) := { add_smul := λ a b f, ext $ λ x, add_smul _ _ _, zero_smul := λ f, ext $ λ x, zero_smul _ _ } variable (S) /-- Applying a linear map at `v : M`, seen as `S`-linear map from `M →ₗ[R] M₂` to `M₂`. See `linear_map.applyₗ` for a version where `S = R`. -/ @[simps] def applyₗ' : M →+ (M →ₗ[R] M₂) →ₗ[S] M₂ := { to_fun := λ v, { to_fun := λ f, f v, map_add' := λ f g, f.add_apply g v, map_smul' := λ x f, f.smul_apply x v }, map_zero' := linear_map.ext $ λ f, f.map_zero, map_add' := λ x y, linear_map.ext $ λ f, f.map_add _ _ } section variables (R M) /-- The equivalence between R-linear maps from `R` to `M`, and points of `M` itself. This says that the forgetful functor from `R`-modules to types is representable, by `R`. This as an `S`-linear equivalence, under the assumption that `S` acts on `M` commuting with `R`. When `R` is commutative, we can take this to be the usual action with `S = R`. Otherwise, `S = ℤ` shows that the equivalence is additive. See note [bundled maps over different rings]. -/ @[simps] def ring_lmap_equiv_self [semimodule S M] [smul_comm_class R S M] : (R →ₗ[R] M) ≃ₗ[S] M := { to_fun := λ f, f 1, inv_fun := smul_right (1 : R →ₗ[R] R), left_inv := λ f, by { ext, simp }, right_inv := λ x, by simp, .. applyₗ' S (1 : R) } end end semimodule section comm_semiring variables [comm_semiring R] [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃] variables [semimodule R M] [semimodule R M₂] [semimodule R M₃] variables (f g : M →ₗ[R] M₂) include R theorem comp_smul (g : M₂ →ₗ[R] M₃) (a : R) : g.comp (a • f) = a • (g.comp f) := ext $ assume b, by rw [comp_apply, smul_apply, g.map_smul]; refl /-- Composition by `f : M₂ → M₃` is a linear map from the space of linear maps `M → M₂` to the space of linear maps `M₂ → M₃`. -/ def comp_right (f : M₂ →ₗ[R] M₃) : (M →ₗ[R] M₂) →ₗ[R] (M →ₗ[R] M₃) := ⟨f.comp, λ _ _, linear_map.ext $ λ _, f.2 _ _, λ _ _, linear_map.ext $ λ _, f.3 _ _⟩ /-- Applying a linear map at `v : M`, seen as a linear map from `M →ₗ[R] M₂` to `M₂`. See also `linear_map.applyₗ'` for a version that works with two different semirings. This is the `linear_map` version of `add_monoid_hom.eval`. -/ @[simps] def applyₗ : M →ₗ[R] (M →ₗ[R] M₂) →ₗ[R] M₂ := { to_fun := λ v, { to_fun := λ f, f v, ..applyₗ' R v }, map_smul' := λ x y, linear_map.ext $ λ f, f.map_smul _ _, ..applyₗ' R } /-- Alternative version of `dom_restrict` as a linear map. -/ def dom_restrict' (p : submodule R M) : (M →ₗ[R] M₂) →ₗ[R] (p →ₗ[R] M₂) := { to_fun := λ φ, φ.dom_restrict p, map_add' := by simp [linear_map.ext_iff], map_smul' := by simp [linear_map.ext_iff] } @[simp] lemma dom_restrict'_apply (f : M →ₗ[R] M₂) (p : submodule R M) (x : p) : dom_restrict' p f x = f x := rfl end comm_semiring section semiring variables [semiring R] [add_comm_monoid M] [semimodule R M] instance endomorphism_semiring : semiring (M →ₗ[R] M) := by refine {mul := (*), one := 1, ..linear_map.add_comm_monoid, ..}; { intros, apply linear_map.ext, simp {proj := ff} } lemma mul_apply (f g : M →ₗ[R] M) (x : M) : (f * g) x = f (g x) := rfl end semiring section ring variables [ring R] [add_comm_group M] [semimodule R M] instance endomorphism_ring : ring (M →ₗ[R] M) := { ..linear_map.endomorphism_semiring, ..linear_map.add_comm_group } end ring section comm_ring variables [comm_ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃] variables [semimodule R M] [semimodule R M₂] [semimodule R M₃] /-- The family of linear maps `M₂ → M` parameterised by `f ∈ M₂ → R`, `x ∈ M`, is linear in `f`, `x`. -/ def smul_rightₗ : (M₂ →ₗ[R] R) →ₗ[R] M →ₗ[R] M₂ →ₗ[R] M := { to_fun := λ f, { to_fun := linear_map.smul_right f, map_add' := λ m m', by { ext, apply smul_add, }, map_smul' := λ c m, by { ext, apply smul_comm, } }, map_add' := λ f f', by { ext, apply add_smul, }, map_smul' := λ c f, by { ext, apply mul_smul, } } @[simp] lemma smul_rightₗ_apply (f : M₂ →ₗ[R] R) (x : M) (c : M₂) : (smul_rightₗ : (M₂ →ₗ R) →ₗ M →ₗ M₂ →ₗ M) f x c = (f c) • x := rfl end comm_ring end linear_map /-! ### Properties of submodules -/ namespace submodule section add_comm_monoid variables [semiring R] [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃] variables [semimodule R M] [semimodule R M₂] [semimodule R M₃] variables (p p' : submodule R M) (q q' : submodule R M₂) variables {r : R} {x y : M} open set instance : partial_order (submodule R M) := { le := λ p p', ∀ ⦃x⦄, x ∈ p → x ∈ p', ..partial_order.lift (coe : submodule R M → set M) coe_injective } variables {p p'} lemma le_def : p ≤ p' ↔ (p : set M) ⊆ p' := iff.rfl lemma le_def' : p ≤ p' ↔ ∀ x ∈ p, x ∈ p' := iff.rfl lemma lt_def : p < p' ↔ (p : set M) ⊂ p' := iff.rfl lemma not_le_iff_exists : ¬ (p ≤ p') ↔ ∃ x ∈ p, x ∉ p' := not_subset lemma exists_of_lt {p p' : submodule R M} : p < p' → ∃ x ∈ p', x ∉ p := exists_of_ssubset lemma lt_iff_le_and_exists : p < p' ↔ p ≤ p' ∧ ∃ x ∈ p', x ∉ p := by rw [lt_iff_le_not_le, not_le_iff_exists] /-- If two submodules `p` and `p'` satisfy `p ⊆ p'`, then `of_le p p'` is the linear map version of this inclusion. -/ def of_le (h : p ≤ p') : p →ₗ[R] p' := p.subtype.cod_restrict p' $ λ ⟨x, hx⟩, h hx @[simp] theorem coe_of_le (h : p ≤ p') (x : p) : (of_le h x : M) = x := rfl theorem of_le_apply (h : p ≤ p') (x : p) : of_le h x = ⟨x, h x.2⟩ := rfl variables (p p') lemma subtype_comp_of_le (p q : submodule R M) (h : p ≤ q) : q.subtype.comp (of_le h) = p.subtype := by { ext ⟨b, hb⟩, refl } /-- The set `{0}` is the bottom element of the lattice of submodules. -/ instance : has_bot (submodule R M) := ⟨{ carrier := {0}, smul_mem' := by simp { contextual := tt }, .. (⊥ : add_submonoid M)}⟩ instance inhabited' : inhabited (submodule R M) := ⟨⊥⟩ @[simp] lemma bot_coe : ((⊥ : submodule R M) : set M) = {0} := rfl section variables (R) @[simp] lemma mem_bot : x ∈ (⊥ : submodule R M) ↔ x = 0 := mem_singleton_iff end instance unique_bot : unique (⊥ : submodule R M) := ⟨infer_instance, λ x, subtype.ext $ (mem_bot R).1 x.mem⟩ lemma nonzero_mem_of_bot_lt {I : submodule R M} (bot_lt : ⊥ < I) : ∃ a : I, a ≠ 0 := begin have h := (submodule.lt_iff_le_and_exists.1 bot_lt).2, tidy, end instance : order_bot (submodule R M) := { bot := ⊥, bot_le := λ p x, by simp {contextual := tt}, ..submodule.partial_order } protected lemma eq_bot_iff (p : submodule R M) : p = ⊥ ↔ ∀ x ∈ p, x = (0 : M) := ⟨ λ h, h.symm ▸ λ x hx, (mem_bot R).mp hx, λ h, eq_bot_iff.mpr (λ x hx, (mem_bot R).mpr (h x hx)) ⟩ protected lemma ne_bot_iff (p : submodule R M) : p ≠ ⊥ ↔ ∃ x ∈ p, x ≠ (0 : M) := by { haveI := classical.prop_decidable, simp_rw [ne.def, p.eq_bot_iff, not_forall] } /-- The universal set is the top element of the lattice of submodules. -/ instance : has_top (submodule R M) := ⟨{ carrier := univ, smul_mem' := λ _ _ _, trivial, .. (⊤ : add_submonoid M)}⟩ @[simp] lemma top_coe : ((⊤ : submodule R M) : set M) = univ := rfl @[simp] lemma mem_top : x ∈ (⊤ : submodule R M) := trivial instance : order_top (submodule R M) := { top := ⊤, le_top := λ p x _, trivial, ..submodule.partial_order } instance : has_Inf (submodule R M) := ⟨λ S, { carrier := ⋂ s ∈ S, (s : set M), zero_mem' := by simp, add_mem' := by simp [add_mem] {contextual := tt}, smul_mem' := by simp [smul_mem] {contextual := tt} }⟩ private lemma Inf_le' {S : set (submodule R M)} {p} : p ∈ S → Inf S ≤ p := bInter_subset_of_mem private lemma le_Inf' {S : set (submodule R M)} {p} : (∀p' ∈ S, p ≤ p') → p ≤ Inf S := subset_bInter instance : has_inf (submodule R M) := ⟨λ p p', { carrier := p ∩ p', zero_mem' := by simp, add_mem' := by simp [add_mem] {contextual := tt}, smul_mem' := by simp [smul_mem] {contextual := tt} }⟩ instance : complete_lattice (submodule R M) := { sup := λ a b, Inf {x | a ≤ x ∧ b ≤ x}, le_sup_left := λ a b, le_Inf' $ λ x ⟨ha, hb⟩, ha, le_sup_right := λ a b, le_Inf' $ λ x ⟨ha, hb⟩, hb, sup_le := λ a b c h₁ h₂, Inf_le' ⟨h₁, h₂⟩, inf := (⊓), le_inf := λ a b c, subset_inter, inf_le_left := λ a b, inter_subset_left _ _, inf_le_right := λ a b, inter_subset_right _ _, Sup := λtt, Inf {t | ∀t'∈tt, t' ≤ t}, le_Sup := λ s p hs, le_Inf' $ λ p' hp', hp' _ hs, Sup_le := λ s p hs, Inf_le' hs, Inf := Inf, le_Inf := λ s a, le_Inf', Inf_le := λ s a, Inf_le', ..submodule.order_top, ..submodule.order_bot } instance add_comm_monoid_submodule : add_comm_monoid (submodule R M) := { add := (⊔), add_assoc := λ _ _ _, sup_assoc, zero := ⊥, zero_add := λ _, bot_sup_eq, add_zero := λ _, sup_bot_eq, add_comm := λ _ _, sup_comm } @[simp] lemma add_eq_sup (p q : submodule R M) : p + q = p ⊔ q := rfl @[simp] lemma zero_eq_bot : (0 : submodule R M) = ⊥ := rfl lemma eq_top_iff' {p : submodule R M} : p = ⊤ ↔ ∀ x, x ∈ p := eq_top_iff.trans ⟨λ h x, @h x trivial, λ h x _, h x⟩ variables (R) @[simp] lemma bot_to_add_submonoid : (⊥ : submodule R M).to_add_submonoid = ⊥ := rfl @[simp] lemma top_to_add_submonoid : (⊤ : submodule R M).to_add_submonoid = ⊤ := rfl lemma subsingleton_iff : subsingleton M ↔ subsingleton (submodule R M) := add_submonoid.subsingleton_iff.trans $ begin rw [←subsingleton_iff_bot_eq_top, ←subsingleton_iff_bot_eq_top], convert to_add_submonoid_eq; refl end lemma nontrivial_iff : nontrivial M ↔ nontrivial (submodule R M) := not_iff_not.mp ( (not_nontrivial_iff_subsingleton.trans $ subsingleton_iff R).trans not_nontrivial_iff_subsingleton.symm) variables {R} instance [subsingleton M] : unique (submodule R M) := ⟨⟨⊥⟩, λ a, @subsingleton.elim _ ((subsingleton_iff R).mp ‹_›) a _⟩ instance unique' [subsingleton R] : unique (submodule R M) := by haveI := semimodule.subsingleton R M; apply_instance instance [nontrivial M] : nontrivial (submodule R M) := (nontrivial_iff R).mp ‹_› @[simp] theorem inf_coe : (p ⊓ p' : set M) = p ∩ p' := rfl @[simp] theorem mem_inf {p p' : submodule R M} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := iff.rfl @[simp] theorem Inf_coe (P : set (submodule R M)) : (↑(Inf P) : set M) = ⋂ p ∈ P, ↑p := rfl @[simp] theorem infi_coe {ι} (p : ι → submodule R M) : (↑⨅ i, p i : set M) = ⋂ i, ↑(p i) := by rw [infi, Inf_coe]; ext a; simp; exact ⟨λ h i, h _ i rfl, λ h i x e, e ▸ h _⟩ @[simp] lemma mem_Inf {S : set (submodule R M)} {x : M} : x ∈ Inf S ↔ ∀ p ∈ S, x ∈ p := set.mem_bInter_iff @[simp] theorem mem_infi {ι} (p : ι → submodule R M) : x ∈ (⨅ i, p i) ↔ ∀ i, x ∈ p i := by rw [← mem_coe, infi_coe, mem_Inter]; refl theorem disjoint_def {p p' : submodule R M} : disjoint p p' ↔ ∀ x ∈ p, x ∈ p' → x = (0:M) := show (∀ x, x ∈ p ∧ x ∈ p' → x ∈ ({0} : set M)) ↔ _, by simp theorem disjoint_def' {p p' : submodule R M} : disjoint p p' ↔ ∀ (x ∈ p) (y ∈ p'), x = y → x = (0:M) := disjoint_def.trans ⟨λ h x hx y hy hxy, h x hx $ hxy.symm ▸ hy, λ h x hx hx', h _ hx x hx' rfl⟩ theorem mem_right_iff_eq_zero_of_disjoint {p p' : submodule R M} (h : disjoint p p') {x : p} : (x:M) ∈ p' ↔ x = 0 := ⟨λ hx, coe_eq_zero.1 $ disjoint_def.1 h x x.2 hx, λ h, h.symm ▸ p'.zero_mem⟩ theorem mem_left_iff_eq_zero_of_disjoint {p p' : submodule R M} (h : disjoint p p') {x : p'} : (x:M) ∈ p ↔ x = 0 := ⟨λ hx, coe_eq_zero.1 $ disjoint_def.1 h x hx x.2, λ h, h.symm ▸ p.zero_mem⟩ /-- The pushforward of a submodule `p ⊆ M` by `f : M → M₂` -/ def map (f : M →ₗ[R] M₂) (p : submodule R M) : submodule R M₂ := { carrier := f '' p, smul_mem' := by rintro a _ ⟨b, hb, rfl⟩; exact ⟨_, p.smul_mem _ hb, f.map_smul _ _⟩, .. p.to_add_submonoid.map f.to_add_monoid_hom } @[simp] lemma map_coe (f : M →ₗ[R] M₂) (p : submodule R M) : (map f p : set M₂) = f '' p := rfl @[simp] lemma mem_map {f : M →ₗ[R] M₂} {p : submodule R M} {x : M₂} : x ∈ map f p ↔ ∃ y, y ∈ p ∧ f y = x := iff.rfl theorem mem_map_of_mem {f : M →ₗ[R] M₂} {p : submodule R M} {r} (h : r ∈ p) : f r ∈ map f p := set.mem_image_of_mem _ h @[simp] lemma map_id : map linear_map.id p = p := submodule.ext $ λ a, by simp lemma map_comp (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) (p : submodule R M) : map (g.comp f) p = map g (map f p) := submodule.coe_injective $ by simp [map_coe]; rw ← image_comp lemma map_mono {f : M →ₗ[R] M₂} {p p' : submodule R M} : p ≤ p' → map f p ≤ map f p' := image_subset _ @[simp] lemma map_zero : map (0 : M →ₗ[R] M₂) p = ⊥ := have ∃ (x : M), x ∈ p := ⟨0, p.zero_mem⟩, ext $ by simp [this, eq_comm] /-- The pullback of a submodule `p ⊆ M₂` along `f : M → M₂` -/ def comap (f : M →ₗ[R] M₂) (p : submodule R M₂) : submodule R M := { carrier := f ⁻¹' p, smul_mem' := λ a x h, by simp [p.smul_mem _ h], .. p.to_add_submonoid.comap f.to_add_monoid_hom } @[simp] lemma comap_coe (f : M →ₗ[R] M₂) (p : submodule R M₂) : (comap f p : set M) = f ⁻¹' p := rfl @[simp] lemma mem_comap {f : M →ₗ[R] M₂} {p : submodule R M₂} : x ∈ comap f p ↔ f x ∈ p := iff.rfl lemma comap_id : comap linear_map.id p = p := submodule.coe_injective rfl lemma comap_comp (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) (p : submodule R M₃) : comap (g.comp f) p = comap f (comap g p) := rfl lemma comap_mono {f : M →ₗ[R] M₂} {q q' : submodule R M₂} : q ≤ q' → comap f q ≤ comap f q' := preimage_mono lemma map_le_iff_le_comap {f : M →ₗ[R] M₂} {p : submodule R M} {q : submodule R M₂} : map f p ≤ q ↔ p ≤ comap f q := image_subset_iff lemma gc_map_comap (f : M →ₗ[R] M₂) : galois_connection (map f) (comap f) | p q := map_le_iff_le_comap @[simp] lemma map_bot (f : M →ₗ[R] M₂) : map f ⊥ = ⊥ := (gc_map_comap f).l_bot @[simp] lemma map_sup (f : M →ₗ[R] M₂) : map f (p ⊔ p') = map f p ⊔ map f p' := (gc_map_comap f).l_sup @[simp] lemma map_supr {ι : Sort*} (f : M →ₗ[R] M₂) (p : ι → submodule R M) : map f (⨆i, p i) = (⨆i, map f (p i)) := (gc_map_comap f).l_supr @[simp] lemma comap_top (f : M →ₗ[R] M₂) : comap f ⊤ = ⊤ := rfl @[simp] lemma comap_inf (f : M →ₗ[R] M₂) : comap f (q ⊓ q') = comap f q ⊓ comap f q' := rfl @[simp] lemma comap_infi {ι : Sort*} (f : M →ₗ[R] M₂) (p : ι → submodule R M₂) : comap f (⨅i, p i) = (⨅i, comap f (p i)) := (gc_map_comap f).u_infi @[simp] lemma comap_zero : comap (0 : M →ₗ[R] M₂) q = ⊤ := ext $ by simp lemma map_comap_le (f : M →ₗ[R] M₂) (q : submodule R M₂) : map f (comap f q) ≤ q := (gc_map_comap f).l_u_le _ lemma le_comap_map (f : M →ₗ[R] M₂) (p : submodule R M) : p ≤ comap f (map f p) := (gc_map_comap f).le_u_l _ --TODO(Mario): is there a way to prove this from order properties? lemma map_inf_eq_map_inf_comap {f : M →ₗ[R] M₂} {p : submodule R M} {p' : submodule R M₂} : map f p ⊓ p' = map f (p ⊓ comap f p') := le_antisymm (by rintro _ ⟨⟨x, h₁, rfl⟩, h₂⟩; exact ⟨_, ⟨h₁, h₂⟩, rfl⟩) (le_inf (map_mono inf_le_left) (map_le_iff_le_comap.2 inf_le_right)) lemma map_comap_subtype : map p.subtype (comap p.subtype p') = p ⊓ p' := ext $ λ x, ⟨by rintro ⟨⟨_, h₁⟩, h₂, rfl⟩; exact ⟨h₁, h₂⟩, λ ⟨h₁, h₂⟩, ⟨⟨_, h₁⟩, h₂, rfl⟩⟩ lemma eq_zero_of_bot_submodule : ∀(b : (⊥ : submodule R M)), b = 0 | ⟨b', hb⟩ := subtype.eq $ show b' = 0, from (mem_bot R).1 hb section variables (R) /-- The span of a set `s ⊆ M` is the smallest submodule of M that contains `s`. -/ def span (s : set M) : submodule R M := Inf {p | s ⊆ p} end variables {s t : set M} lemma mem_span : x ∈ span R s ↔ ∀ p : submodule R M, s ⊆ p → x ∈ p := mem_bInter_iff lemma subset_span : s ⊆ span R s := λ x h, mem_span.2 $ λ p hp, hp h lemma span_le {p} : span R s ≤ p ↔ s ⊆ p := ⟨subset.trans subset_span, λ ss x h, mem_span.1 h _ ss⟩ lemma span_mono (h : s ⊆ t) : span R s ≤ span R t := span_le.2 $ subset.trans h subset_span lemma span_eq_of_le (h₁ : s ⊆ p) (h₂ : p ≤ span R s) : span R s = p := le_antisymm (span_le.2 h₁) h₂ @[simp] lemma span_eq : span R (p : set M) = p := span_eq_of_le _ (subset.refl _) subset_span lemma map_span (f : M →ₗ[R] M₂) (s : set M) : (span R s).map f = span R (f '' s) := eq.symm $ span_eq_of_le _ (set.image_subset f subset_span) $ map_le_iff_le_comap.2 $ span_le.2 $ λ x hx, subset_span ⟨x, hx, rfl⟩ /- See also `span_preimage_eq` below. -/ lemma span_preimage_le (f : M →ₗ[R] M₂) (s : set M₂) : span R (f ⁻¹' s) ≤ (span R s).comap f := by { rw [span_le, comap_coe], exact preimage_mono (subset_span), } /-- An induction principle for span membership. If `p` holds for 0 and all elements of `s`, and is preserved under addition and scalar multiplication, then `p` holds for all elements of the span of `s`. -/ @[elab_as_eliminator] lemma span_induction {p : M → Prop} (h : x ∈ span R s) (Hs : ∀ x ∈ s, p x) (H0 : p 0) (H1 : ∀ x y, p x → p y → p (x + y)) (H2 : ∀ (a:R) x, p x → p (a • x)) : p x := (@span_le _ _ _ _ _ _ ⟨p, H0, H1, H2⟩).2 Hs h section variables (R M) /-- `span` forms a Galois insertion with the coercion from submodule to set. -/ protected def gi : galois_insertion (@span R M _ _ _) coe := { choice := λ s _, span R s, gc := λ s t, span_le, le_l_u := λ s, subset_span, choice_eq := λ s h, rfl } end @[simp] lemma span_empty : span R (∅ : set M) = ⊥ := (submodule.gi R M).gc.l_bot @[simp] lemma span_univ : span R (univ : set M) = ⊤ := eq_top_iff.2 $ le_def.2 $ subset_span lemma span_union (s t : set M) : span R (s ∪ t) = span R s ⊔ span R t := (submodule.gi R M).gc.l_sup lemma span_Union {ι} (s : ι → set M) : span R (⋃ i, s i) = ⨆ i, span R (s i) := (submodule.gi R M).gc.l_supr lemma span_eq_supr_of_singleton_spans (s : set M) : span R s = ⨆ x ∈ s, span R {x} := by simp only [←span_Union, set.bUnion_of_singleton s] @[simp] theorem coe_supr_of_directed {ι} [hι : nonempty ι] (S : ι → submodule R M) (H : directed (≤) S) : ((supr S : submodule R M) : set M) = ⋃ i, S i := begin refine subset.antisymm _ (Union_subset $ le_supr S), suffices : (span R (⋃ i, (S i : set M)) : set M) ⊆ ⋃ (i : ι), ↑(S i), by simpa only [span_Union, span_eq] using this, refine (λ x hx, span_induction hx (λ _, id) _ _ _); simp only [mem_Union, exists_imp_distrib], { exact hι.elim (λ i, ⟨i, (S i).zero_mem⟩) }, { intros x y i hi j hj, rcases H i j with ⟨k, ik, jk⟩, exact ⟨k, add_mem _ (ik hi) (jk hj)⟩ }, { exact λ a x i hi, ⟨i, smul_mem _ a hi⟩ }, end lemma mem_sup_left {S T : submodule R M} : ∀ {x : M}, x ∈ S → x ∈ S ⊔ T := show S ≤ S ⊔ T, from le_sup_left lemma mem_sup_right {S T : submodule R M} : ∀ {x : M}, x ∈ T → x ∈ S ⊔ T := show T ≤ S ⊔ T, from le_sup_right lemma mem_supr_of_mem {ι : Sort*} {b : M} {p : ι → submodule R M} (i : ι) (h : b ∈ p i) : b ∈ (⨆i, p i) := have p i ≤ (⨆i, p i) := le_supr p i, @this b h lemma mem_Sup_of_mem {S : set (submodule R M)} {s : submodule R M} (hs : s ∈ S) : ∀ {x : M}, x ∈ s → x ∈ Sup S := show s ≤ Sup S, from le_Sup hs @[simp] theorem mem_supr_of_directed {ι} [nonempty ι] (S : ι → submodule R M) (H : directed (≤) S) {x} : x ∈ supr S ↔ ∃ i, x ∈ S i := by { rw [← mem_coe, coe_supr_of_directed S H, mem_Union], refl } theorem mem_Sup_of_directed {s : set (submodule R M)} {z} (hs : s.nonempty) (hdir : directed_on (≤) s) : z ∈ Sup s ↔ ∃ y ∈ s, z ∈ y := begin haveI : nonempty s := hs.to_subtype, simp only [Sup_eq_supr', mem_supr_of_directed _ hdir.directed_coe, set_coe.exists, subtype.coe_mk] end section variables {p p'} lemma mem_sup : x ∈ p ⊔ p' ↔ ∃ (y ∈ p) (z ∈ p'), y + z = x := ⟨λ h, begin rw [← span_eq p, ← span_eq p', ← span_union] at h, apply span_induction h, { rintro y (h | h), { exact ⟨y, h, 0, by simp, by simp⟩ }, { exact ⟨0, by simp, y, h, by simp⟩ } }, { exact ⟨0, by simp, 0, by simp⟩ }, { rintro _ _ ⟨y₁, hy₁, z₁, hz₁, rfl⟩ ⟨y₂, hy₂, z₂, hz₂, rfl⟩, exact ⟨_, add_mem _ hy₁ hy₂, _, add_mem _ hz₁ hz₂, by simp [add_assoc]; cc⟩ }, { rintro a _ ⟨y, hy, z, hz, rfl⟩, exact ⟨_, smul_mem _ a hy, _, smul_mem _ a hz, by simp [smul_add]⟩ } end, by rintro ⟨y, hy, z, hz, rfl⟩; exact add_mem _ ((le_sup_left : p ≤ p ⊔ p') hy) ((le_sup_right : p' ≤ p ⊔ p') hz)⟩ lemma mem_sup' : x ∈ p ⊔ p' ↔ ∃ (y : p) (z : p'), (y:M) + z = x := mem_sup.trans $ by simp only [submodule.exists, coe_mk] end notation R`∙`:1000 x := span R (@singleton _ _ set.has_singleton x) lemma mem_span_singleton_self (x : M) : x ∈ R ∙ x := subset_span rfl lemma nontrivial_span_singleton {x : M} (h : x ≠ 0) : nontrivial (R ∙ x) := ⟨begin use [0, x, submodule.mem_span_singleton_self x], intros H, rw [eq_comm, submodule.mk_eq_zero] at H, exact h H end⟩ lemma mem_span_singleton {y : M} : x ∈ (R ∙ y) ↔ ∃ a:R, a • y = x := ⟨λ h, begin apply span_induction h, { rintro y (rfl|⟨⟨⟩⟩), exact ⟨1, by simp⟩ }, { exact ⟨0, by simp⟩ }, { rintro _ _ ⟨a, rfl⟩ ⟨b, rfl⟩, exact ⟨a + b, by simp [add_smul]⟩ }, { rintro a _ ⟨b, rfl⟩, exact ⟨a * b, by simp [smul_smul]⟩ } end, by rintro ⟨a, y, rfl⟩; exact smul_mem _ _ (subset_span $ by simp)⟩ lemma le_span_singleton_iff {s : submodule R M} {v₀ : M} : s ≤ (R ∙ v₀) ↔ ∀ v ∈ s, ∃ r : R, r • v₀ = v := by simp_rw [le_def', mem_span_singleton] @[simp] lemma span_zero_singleton : (R ∙ (0:M)) = ⊥ := by { ext, simp [mem_span_singleton, eq_comm] } lemma span_singleton_eq_range (y : M) : ↑(R ∙ y) = range ((• y) : R → M) := set.ext $ λ x, mem_span_singleton lemma span_singleton_smul_le (r : R) (x : M) : (R ∙ (r • x)) ≤ R ∙ x := begin rw [span_le, set.singleton_subset_iff, mem_coe], exact smul_mem _ _ (mem_span_singleton_self _) end lemma span_singleton_smul_eq {K E : Type*} [division_ring K] [add_comm_group E] [module K E] {r : K} (x : E) (hr : r ≠ 0) : (K ∙ (r • x)) = K ∙ x := begin refine le_antisymm (span_singleton_smul_le r x) _, convert span_singleton_smul_le r⁻¹ (r • x), exact (inv_smul_smul' hr _).symm end lemma disjoint_span_singleton {K E : Type*} [division_ring K] [add_comm_group E] [module K E] {s : submodule K E} {x : E} : disjoint s (K ∙ x) ↔ (x ∈ s → x = 0) := begin refine disjoint_def.trans ⟨λ H hx, H x hx $ subset_span $ mem_singleton x, _⟩, assume H y hy hyx, obtain ⟨c, hc⟩ := mem_span_singleton.1 hyx, subst y, classical, by_cases hc : c = 0, by simp only [hc, zero_smul], rw [s.smul_mem_iff hc] at hy, rw [H hy, smul_zero] end lemma disjoint_span_singleton' {K E : Type*} [division_ring K] [add_comm_group E] [module K E] {p : submodule K E} {x : E} (x0 : x ≠ 0) : disjoint p (K ∙ x) ↔ x ∉ p := disjoint_span_singleton.trans ⟨λ h₁ h₂, x0 (h₁ h₂), λ h₁ h₂, (h₁ h₂).elim⟩ lemma mem_span_insert {y} : x ∈ span R (insert y s) ↔ ∃ (a:R) (z ∈ span R s), x = a • y + z := begin simp only [← union_singleton, span_union, mem_sup, mem_span_singleton, exists_prop, exists_exists_eq_and], rw [exists_comm], simp only [eq_comm, add_comm, exists_and_distrib_left] end lemma span_insert_eq_span (h : x ∈ span R s) : span R (insert x s) = span R s := span_eq_of_le _ (set.insert_subset.mpr ⟨h, subset_span⟩) (span_mono $ subset_insert _ _) lemma span_span : span R (span R s : set M) = span R s := span_eq _ lemma span_eq_bot : span R (s : set M) = ⊥ ↔ ∀ x ∈ s, (x:M) = 0 := eq_bot_iff.trans ⟨ λ H x h, (mem_bot R).1 $ H $ subset_span h, λ H, span_le.2 (λ x h, (mem_bot R).2 $ H x h)⟩ @[simp] lemma span_singleton_eq_bot : (R ∙ x) = ⊥ ↔ x = 0 := span_eq_bot.trans $ by simp @[simp] lemma span_zero : span R (0 : set M) = ⊥ := by rw [←singleton_zero, span_singleton_eq_bot] @[simp] lemma span_image (f : M →ₗ[R] M₂) : span R (f '' s) = map f (span R s) := span_eq_of_le _ (image_subset _ subset_span) $ map_le_iff_le_comap.2 $ span_le.2 $ image_subset_iff.1 subset_span lemma supr_eq_span {ι : Sort w} (p : ι → submodule R M) : (⨆ (i : ι), p i) = submodule.span R (⋃ (i : ι), ↑(p i)) := le_antisymm (supr_le $ assume i, subset.trans (assume m hm, set.mem_Union.mpr ⟨i, hm⟩) subset_span) (span_le.mpr $ Union_subset_iff.mpr $ assume i m hm, mem_supr_of_mem i hm) lemma span_singleton_le_iff_mem (m : M) (p : submodule R M) : (R ∙ m) ≤ p ↔ m ∈ p := by rw [span_le, singleton_subset_iff, mem_coe] lemma singleton_span_is_compact_element (x : M) : complete_lattice.is_compact_element (span R {x} : submodule R M) := begin rw complete_lattice.is_compact_element_iff_le_of_directed_Sup_le, intros d hemp hdir hsup, have : x ∈ Sup d, from (le_def.mp hsup) (mem_span_singleton_self x), obtain ⟨y, ⟨hyd, hxy⟩⟩ := (mem_Sup_of_directed hemp hdir).mp this, exact ⟨y, ⟨hyd, by simpa only [span_le, singleton_subset_iff]⟩⟩, end instance : is_compactly_generated (submodule R M) := ⟨λ s, ⟨(λ x, span R {x}) '' s, ⟨λ t ht, begin rcases (set.mem_image _ _ _).1 ht with ⟨x, hx, rfl⟩, apply singleton_span_is_compact_element, end, by rw [Sup_eq_supr, supr_image, ←span_eq_supr_of_singleton_spans, span_eq]⟩⟩⟩ lemma lt_add_iff_not_mem {I : submodule R M} {a : M} : I < I + (R ∙ a) ↔ a ∉ I := begin split, { intro h, by_contra akey, have h1 : I + (R ∙ a) ≤ I, { simp only [add_eq_sup, sup_le_iff], split, { exact le_refl I, }, { exact (span_singleton_le_iff_mem a I).mpr akey, } }, have h2 := gt_of_ge_of_gt h1 h, exact lt_irrefl I h2, }, { intro h, apply lt_iff_le_and_exists.mpr, split, simp only [add_eq_sup, le_sup_left], use a, split, swap, { assumption, }, { have : (R ∙ a) ≤ I + (R ∙ a) := le_sup_right, exact this (mem_span_singleton_self a), } }, end lemma mem_supr {ι : Sort w} (p : ι → submodule R M) {m : M} : (m ∈ ⨆ i, p i) ↔ (∀ N, (∀ i, p i ≤ N) → m ∈ N) := begin rw [← span_singleton_le_iff_mem, le_supr_iff], simp only [span_singleton_le_iff_mem], end section open_locale classical /-- For every element in the span of a set, there exists a finite subset of the set such that the element is contained in the span of the subset. -/ lemma mem_span_finite_of_mem_span {S : set M} {x : M} (hx : x ∈ span R S) : ∃ T : finset M, ↑T ⊆ S ∧ x ∈ span R (T : set M) := begin refine span_induction hx (λ x hx, _) _ _ _, { refine ⟨{x}, _, _⟩, { rwa [finset.coe_singleton, set.singleton_subset_iff] }, { rw finset.coe_singleton, exact submodule.mem_span_singleton_self x } }, { use ∅, simp }, { rintros x y ⟨X, hX, hxX⟩ ⟨Y, hY, hyY⟩, refine ⟨X ∪ Y, _, _⟩, { rw finset.coe_union, exact set.union_subset hX hY }, rw [finset.coe_union, span_union, mem_sup], exact ⟨x, hxX, y, hyY, rfl⟩, }, { rintros a x ⟨T, hT, h2⟩, exact ⟨T, hT, smul_mem _ _ h2⟩ } end end /-- The product of two submodules is a submodule. -/ def prod : submodule R (M × M₂) := { carrier := set.prod p q, smul_mem' := by rintro a ⟨x, y⟩ ⟨hx, hy⟩; exact ⟨smul_mem _ a hx, smul_mem _ a hy⟩, .. p.to_add_submonoid.prod q.to_add_submonoid } @[simp] lemma prod_coe : (prod p q : set (M × M₂)) = set.prod p q := rfl @[simp] lemma mem_prod {p : submodule R M} {q : submodule R M₂} {x : M × M₂} : x ∈ prod p q ↔ x.1 ∈ p ∧ x.2 ∈ q := set.mem_prod lemma span_prod_le (s : set M) (t : set M₂) : span R (set.prod s t) ≤ prod (span R s) (span R t) := span_le.2 $ set.prod_mono subset_span subset_span @[simp] lemma prod_top : (prod ⊤ ⊤ : submodule R (M × M₂)) = ⊤ := by ext; simp @[simp] lemma prod_bot : (prod ⊥ ⊥ : submodule R (M × M₂)) = ⊥ := by ext ⟨x, y⟩; simp [prod.zero_eq_mk] lemma prod_mono {p p' : submodule R M} {q q' : submodule R M₂} : p ≤ p' → q ≤ q' → prod p q ≤ prod p' q' := prod_mono @[simp] lemma prod_inf_prod : prod p q ⊓ prod p' q' = prod (p ⊓ p') (q ⊓ q') := coe_injective set.prod_inter_prod @[simp] lemma prod_sup_prod : prod p q ⊔ prod p' q' = prod (p ⊔ p') (q ⊔ q') := begin refine le_antisymm (sup_le (prod_mono le_sup_left le_sup_left) (prod_mono le_sup_right le_sup_right)) _, simp [le_def'], intros xx yy hxx hyy, rcases mem_sup.1 hxx with ⟨x, hx, x', hx', rfl⟩, rcases mem_sup.1 hyy with ⟨y, hy, y', hy', rfl⟩, refine mem_sup.2 ⟨(x, y), ⟨hx, hy⟩, (x', y'), ⟨hx', hy'⟩, rfl⟩ end end add_comm_monoid variables [ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃] variables [semimodule R M] [semimodule R M₂] [semimodule R M₃] variables (p p' : submodule R M) (q q' : submodule R M₂) variables {r : R} {x y : M} open set @[simp] lemma neg_coe : -(p : set M) = p := set.ext $ λ x, p.neg_mem_iff @[simp] protected lemma map_neg (f : M →ₗ[R] M₂) : map (-f) p = map f p := ext $ λ y, ⟨λ ⟨x, hx, hy⟩, hy ▸ ⟨-x, neg_mem _ hx, f.map_neg x⟩, λ ⟨x, hx, hy⟩, hy ▸ ⟨-x, neg_mem _ hx, ((-f).map_neg _).trans (neg_neg (f x))⟩⟩ @[simp] lemma span_neg (s : set M) : span R (-s) = span R s := calc span R (-s) = span R ((-linear_map.id : M →ₗ[R] M) '' s) : by simp ... = map (-linear_map.id) (span R s) : (map_span _ _).symm ... = span R s : by simp lemma mem_span_insert' {y} {s : set M} : x ∈ span R (insert y s) ↔ ∃(a:R), x + a • y ∈ span R s := begin rw mem_span_insert, split, { rintro ⟨a, z, hz, rfl⟩, exact ⟨-a, by simp [hz, add_assoc]⟩ }, { rintro ⟨a, h⟩, exact ⟨-a, _, h, by simp [add_comm, add_left_comm]⟩ } end -- TODO(Mario): Factor through add_subgroup /-- The equivalence relation associated to a submodule `p`, defined by `x ≈ y` iff `y - x ∈ p`. -/ def quotient_rel : setoid M := ⟨λ x y, x - y ∈ p, λ x, by simp, λ x y h, by simpa using neg_mem _ h, λ x y z h₁ h₂, by simpa [sub_eq_add_neg, add_left_comm, add_assoc] using add_mem _ h₁ h₂⟩ /-- The quotient of a module `M` by a submodule `p ⊆ M`. -/ def quotient : Type* := quotient (quotient_rel p) namespace quotient /-- Map associating to an element of `M` the corresponding element of `M/p`, when `p` is a submodule of `M`. -/ def mk {p : submodule R M} : M → quotient p := quotient.mk' @[simp] theorem mk_eq_mk {p : submodule R M} (x : M) : (quotient.mk x : quotient p) = mk x := rfl @[simp] theorem mk'_eq_mk {p : submodule R M} (x : M) : (quotient.mk' x : quotient p) = mk x := rfl @[simp] theorem quot_mk_eq_mk {p : submodule R M} (x : M) : (quot.mk _ x : quotient p) = mk x := rfl protected theorem eq {x y : M} : (mk x : quotient p) = mk y ↔ x - y ∈ p := quotient.eq' instance : has_zero (quotient p) := ⟨mk 0⟩ instance : inhabited (quotient p) := ⟨0⟩ @[simp] theorem mk_zero : mk 0 = (0 : quotient p) := rfl @[simp] theorem mk_eq_zero : (mk x : quotient p) = 0 ↔ x ∈ p := by simpa using (quotient.eq p : mk x = 0 ↔ _) instance : has_add (quotient p) := ⟨λ a b, quotient.lift_on₂' a b (λ a b, mk (a + b)) $ λ a₁ a₂ b₁ b₂ h₁ h₂, (quotient.eq p).2 $ by simpa [sub_eq_add_neg, add_left_comm, add_comm] using add_mem p h₁ h₂⟩ @[simp] theorem mk_add : (mk (x + y) : quotient p) = mk x + mk y := rfl instance : has_neg (quotient p) := ⟨λ a, quotient.lift_on' a (λ a, mk (-a)) $ λ a b h, (quotient.eq p).2 $ by simpa using neg_mem p h⟩ @[simp] theorem mk_neg : (mk (-x) : quotient p) = -mk x := rfl instance : has_sub (quotient p) := ⟨λ a b, quotient.lift_on₂' a b (λ a b, mk (a - b)) $ λ a₁ a₂ b₁ b₂ h₁ h₂, (quotient.eq p).2 $ by simpa [sub_eq_add_neg, add_left_comm, add_comm] using add_mem p h₁ (neg_mem p h₂)⟩ @[simp] theorem mk_sub : (mk (x - y) : quotient p) = mk x - mk y := rfl instance : add_comm_group (quotient p) := by refine {zero := 0, add := (+), neg := has_neg.neg, sub := has_sub.sub, sub_eq_add_neg := _, ..}; repeat {rintro ⟨⟩}; simp [-mk_zero, ← mk_zero p, -mk_add, ← mk_add p, -mk_neg, ← mk_neg p, -mk_sub, ← mk_sub p, sub_eq_add_neg]; cc instance : has_scalar R (quotient p) := ⟨λ a x, quotient.lift_on' x (λ x, mk (a • x)) $ λ x y h, (quotient.eq p).2 $ by simpa [smul_sub] using smul_mem p a h⟩ @[simp] theorem mk_smul : (mk (r • x) : quotient p) = r • mk x := rfl instance : semimodule R (quotient p) := semimodule.of_core $ by refine {smul := (•), ..}; repeat {rintro ⟨⟩ <|> intro}; simp [smul_add, add_smul, smul_smul, -mk_add, (mk_add p).symm, -mk_smul, (mk_smul p).symm] lemma mk_surjective : function.surjective (@mk _ _ _ _ _ p) := by { rintros ⟨x⟩, exact ⟨x, rfl⟩ } lemma nontrivial_of_lt_top (h : p < ⊤) : nontrivial (p.quotient) := begin obtain ⟨x, _, not_mem_s⟩ := exists_of_lt h, refine ⟨⟨mk x, 0, _⟩⟩, simpa using not_mem_s end end quotient lemma quot_hom_ext ⦃f g : quotient p →ₗ[R] M₂⦄ (h : ∀ x, f (quotient.mk x) = g (quotient.mk x)) : f = g := linear_map.ext $ λ x, quotient.induction_on' x h end submodule namespace submodule variables [field K] variables [add_comm_group V] [vector_space K V] variables [add_comm_group V₂] [vector_space K V₂] lemma comap_smul (f : V →ₗ[K] V₂) (p : submodule K V₂) (a : K) (h : a ≠ 0) : p.comap (a • f) = p.comap f := by ext b; simp only [submodule.mem_comap, p.smul_mem_iff h, linear_map.smul_apply] lemma map_smul (f : V →ₗ[K] V₂) (p : submodule K V) (a : K) (h : a ≠ 0) : p.map (a • f) = p.map f := le_antisymm begin rw [map_le_iff_le_comap, comap_smul f _ a h, ← map_le_iff_le_comap], exact le_refl _ end begin rw [map_le_iff_le_comap, ← comap_smul f _ a h, ← map_le_iff_le_comap], exact le_refl _ end lemma comap_smul' (f : V →ₗ[K] V₂) (p : submodule K V₂) (a : K) : p.comap (a • f) = (⨅ h : a ≠ 0, p.comap f) := by classical; by_cases a = 0; simp [h, comap_smul] lemma map_smul' (f : V →ₗ[K] V₂) (p : submodule K V) (a : K) : p.map (a • f) = (⨆ h : a ≠ 0, p.map f) := by classical; by_cases a = 0; simp [h, map_smul] end submodule /-! ### Properties of linear maps -/ namespace linear_map section add_comm_monoid variables [semiring R] [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃] variables [semimodule R M] [semimodule R M₂] [semimodule R M₃] include R open submodule /-- If two linear maps are equal on a set `s`, then they are equal on `submodule.span s`. See also `linear_map.eq_on_span'` for a version using `set.eq_on`. -/ lemma eq_on_span {s : set M} {f g : M →ₗ[R] M₂} (H : set.eq_on f g s) ⦃x⦄ (h : x ∈ span R s) : f x = g x := by apply span_induction h H; simp {contextual := tt} /-- If two linear maps are equal on a set `s`, then they are equal on `submodule.span s`. This version uses `set.eq_on`, and the hidden argument will expand to `h : x ∈ (span R s : set M)`. See `linear_map.eq_on_span` for a version that takes `h : x ∈ span R s` as an argument. -/ lemma eq_on_span' {s : set M} {f g : M →ₗ[R] M₂} (H : set.eq_on f g s) : set.eq_on f g (span R s : set M) := eq_on_span H /-- If `s` generates the whole semimodule and linear maps `f`, `g` are equal on `s`, then they are equal. -/ lemma ext_on {s : set M} {f g : M →ₗ[R] M₂} (hv : span R s = ⊤) (h : set.eq_on f g s) : f = g := linear_map.ext (λ x, eq_on_span h (eq_top_iff'.1 hv _)) /-- If the range of `v : ι → M` generates the whole semimodule and linear maps `f`, `g` are equal at each `v i`, then they are equal. -/ lemma ext_on_range {v : ι → M} {f g : M →ₗ[R] M₂} (hv : span R (set.range v) = ⊤) (h : ∀i, f (v i) = g (v i)) : f = g := ext_on hv (set.forall_range_iff.2 h) section finsupp variables {γ : Type*} [has_zero γ] @[simp] lemma map_finsupp_sum (f : M →ₗ[R] M₂) {t : ι →₀ γ} {g : ι → γ → M} : f (t.sum g) = t.sum (λ i d, f (g i d)) := f.map_sum lemma coe_finsupp_sum (t : ι →₀ γ) (g : ι → γ → M →ₗ[R] M₂) : ⇑(t.sum g) = t.sum (λ i d, g i d) := coe_fn_sum _ _ @[simp] lemma finsupp_sum_apply (t : ι →₀ γ) (g : ι → γ → M →ₗ[R] M₂) (b : M) : (t.sum g) b = t.sum (λ i d, g i d b) := sum_apply _ _ _ end finsupp section dfinsupp variables {γ : ι → Type*} [decidable_eq ι] [Π i, has_zero (γ i)] [Π i (x : γ i), decidable (x ≠ 0)] @[simp] lemma map_dfinsupp_sum (f : M →ₗ[R] M₂) {t : Π₀ i, γ i} {g : Π i, γ i → M} : f (t.sum g) = t.sum (λ i d, f (g i d)) := f.map_sum lemma coe_dfinsupp_sum (t : Π₀ i, γ i) (g : Π i, γ i → M →ₗ[R] M₂) : ⇑(t.sum g) = t.sum (λ i d, g i d) := coe_fn_sum _ _ @[simp] lemma dfinsupp_sum_apply (t : Π₀ i, γ i) (g : Π i, γ i → M →ₗ[R] M₂) (b : M) : (t.sum g) b = t.sum (λ i d, g i d b) := sum_apply _ _ _ end dfinsupp theorem map_cod_restrict (p : submodule R M) (f : M₂ →ₗ[R] M) (h p') : submodule.map (cod_restrict p f h) p' = comap p.subtype (p'.map f) := submodule.ext $ λ ⟨x, hx⟩, by simp [subtype.ext_iff_val] theorem comap_cod_restrict (p : submodule R M) (f : M₂ →ₗ[R] M) (hf p') : submodule.comap (cod_restrict p f hf) p' = submodule.comap f (map p.subtype p') := submodule.ext $ λ x, ⟨λ h, ⟨⟨_, hf x⟩, h, rfl⟩, by rintro ⟨⟨_, _⟩, h, ⟨⟩⟩; exact h⟩ /-- The range of a linear map `f : M → M₂` is a submodule of `M₂`. -/ def range (f : M →ₗ[R] M₂) : submodule R M₂ := map f ⊤ theorem range_coe (f : M →ₗ[R] M₂) : (range f : set M₂) = set.range f := set.image_univ @[simp] theorem mem_range {f : M →ₗ[R] M₂} : ∀ {x}, x ∈ range f ↔ ∃ y, f y = x := set.ext_iff.1 (range_coe f) theorem mem_range_self (f : M →ₗ[R] M₂) (x : M) : f x ∈ f.range := mem_range.2 ⟨x, rfl⟩ @[simp] theorem range_id : range (linear_map.id : M →ₗ[R] M) = ⊤ := map_id _ theorem range_comp (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) : range (g.comp f) = map g (range f) := map_comp _ _ _ theorem range_comp_le_range (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) : range (g.comp f) ≤ range g := by rw range_comp; exact map_mono le_top theorem range_eq_top {f : M →ₗ[R] M₂} : range f = ⊤ ↔ surjective f := by rw [submodule.ext'_iff, range_coe, top_coe, set.range_iff_surjective] lemma range_le_iff_comap {f : M →ₗ[R] M₂} {p : submodule R M₂} : range f ≤ p ↔ comap f p = ⊤ := by rw [range, map_le_iff_le_comap, eq_top_iff] lemma map_le_range {f : M →ₗ[R] M₂} {p : submodule R M} : map f p ≤ range f := map_mono le_top /-- Restrict the codomain of a linear map `f` to `f.range`. This is the bundled version of `set.range_factorization`. -/ @[reducible] def range_restrict (f : M →ₗ[R] M₂) : M →ₗ[R] f.range := f.cod_restrict f.range f.mem_range_self section variables (R) (M) /-- Given an element `x` of a module `M` over `R`, the natural map from `R` to scalar multiples of `x`.-/ def to_span_singleton (x : M) : R →ₗ[R] M := linear_map.id.smul_right x /-- The range of `to_span_singleton x` is the span of `x`.-/ lemma span_singleton_eq_range (x : M) : (R ∙ x) = (to_span_singleton R M x).range := submodule.ext $ λ y, by {refine iff.trans _ mem_range.symm, exact mem_span_singleton } lemma to_span_singleton_one (x : M) : to_span_singleton R M x 1 = x := one_smul _ _ end /-- The kernel of a linear map `f : M → M₂` is defined to be `comap f ⊥`. This is equivalent to the set of `x : M` such that `f x = 0`. The kernel is a submodule of `M`. -/ def ker (f : M →ₗ[R] M₂) : submodule R M := comap f ⊥ @[simp] theorem mem_ker {f : M →ₗ[R] M₂} {y} : y ∈ ker f ↔ f y = 0 := mem_bot R @[simp] theorem ker_id : ker (linear_map.id : M →ₗ[R] M) = ⊥ := rfl @[simp] theorem map_coe_ker (f : M →ₗ[R] M₂) (x : ker f) : f x = 0 := mem_ker.1 x.2 lemma comp_ker_subtype (f : M →ₗ[R] M₂) : f.comp f.ker.subtype = 0 := linear_map.ext $ λ x, suffices f x = 0, by simp [this], mem_ker.1 x.2 theorem ker_comp (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) : ker (g.comp f) = comap f (ker g) := rfl theorem ker_le_ker_comp (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) : ker f ≤ ker (g.comp f) := by rw ker_comp; exact comap_mono bot_le theorem disjoint_ker {f : M →ₗ[R] M₂} {p : submodule R M} : disjoint p (ker f) ↔ ∀ x ∈ p, f x = 0 → x = 0 := by simp [disjoint_def] theorem ker_eq_bot' {f : M →ₗ[R] M₂} : ker f = ⊥ ↔ (∀ m, f m = 0 → m = 0) := by simpa [disjoint] using @disjoint_ker _ _ _ _ _ _ _ _ f ⊤ theorem ker_eq_bot_of_inverse {f : M →ₗ[R] M₂} {g : M₂ →ₗ[R] M} (h : g.comp f = id) : ker f = ⊥ := ker_eq_bot'.2 $ λ m hm, by rw [← id_apply m, ← h, comp_apply, hm, g.map_zero] lemma le_ker_iff_map {f : M →ₗ[R] M₂} {p : submodule R M} : p ≤ ker f ↔ map f p = ⊥ := by rw [ker, eq_bot_iff, map_le_iff_le_comap] lemma ker_cod_restrict (p : submodule R M) (f : M₂ →ₗ[R] M) (hf) : ker (cod_restrict p f hf) = ker f := by rw [ker, comap_cod_restrict, map_bot]; refl lemma range_cod_restrict (p : submodule R M) (f : M₂ →ₗ[R] M) (hf) : range (cod_restrict p f hf) = comap p.subtype f.range := map_cod_restrict _ _ _ _ lemma ker_restrict {p : submodule R M} {f : M →ₗ[R] M} (hf : ∀ x : M, x ∈ p → f x ∈ p) : ker (f.restrict hf) = (f.dom_restrict p).ker := by rw [restrict_eq_cod_restrict_dom_restrict, ker_cod_restrict] lemma map_comap_eq (f : M →ₗ[R] M₂) (q : submodule R M₂) : map f (comap f q) = range f ⊓ q := le_antisymm (le_inf (map_mono le_top) (map_comap_le _ _)) $ by rintro _ ⟨⟨x, _, rfl⟩, hx⟩; exact ⟨x, hx, rfl⟩ lemma map_comap_eq_self {f : M →ₗ[R] M₂} {q : submodule R M₂} (h : q ≤ range f) : map f (comap f q) = q := by rwa [map_comap_eq, inf_eq_right] @[simp] theorem ker_zero : ker (0 : M →ₗ[R] M₂) = ⊤ := eq_top_iff'.2 $ λ x, by simp @[simp] theorem range_zero : range (0 : M →ₗ[R] M₂) = ⊥ := submodule.map_zero _ theorem ker_eq_top {f : M →ₗ[R] M₂} : ker f = ⊤ ↔ f = 0 := ⟨λ h, ext $ λ x, mem_ker.1 $ h.symm ▸ trivial, λ h, h.symm ▸ ker_zero⟩ lemma range_le_bot_iff (f : M →ₗ[R] M₂) : range f ≤ ⊥ ↔ f = 0 := by rw [range_le_iff_comap]; exact ker_eq_top theorem range_eq_bot {f : M →ₗ[R] M₂} : range f = ⊥ ↔ f = 0 := by rw [← range_le_bot_iff, le_bot_iff] lemma range_le_ker_iff {f : M →ₗ[R] M₂} {g : M₂ →ₗ[R] M₃} : range f ≤ ker g ↔ g.comp f = 0 := ⟨λ h, ker_eq_top.1 $ eq_top_iff'.2 $ λ x, h $ mem_map_of_mem trivial, λ h x hx, mem_ker.2 $ exists.elim hx $ λ y ⟨_, hy⟩, by rw [←hy, ←comp_apply, h, zero_apply]⟩ theorem comap_le_comap_iff {f : M →ₗ[R] M₂} (hf : range f = ⊤) {p p'} : comap f p ≤ comap f p' ↔ p ≤ p' := ⟨λ H x hx, by rcases range_eq_top.1 hf x with ⟨y, hy, rfl⟩; exact H hx, comap_mono⟩ theorem comap_injective {f : M →ₗ[R] M₂} (hf : range f = ⊤) : injective (comap f) := λ p p' h, le_antisymm ((comap_le_comap_iff hf).1 (le_of_eq h)) ((comap_le_comap_iff hf).1 (ge_of_eq h)) theorem ker_eq_bot_of_injective {f : M →ₗ[R] M₂} (hf : injective f) : ker f = ⊥ := begin have : disjoint ⊤ f.ker, by { rw [disjoint_ker, ← map_zero f], exact λ x hx H, hf H }, simpa [disjoint] end end add_comm_monoid section add_comm_group variables [semiring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃] variables [semimodule R M] [semimodule R M₂] [semimodule R M₃] include R open submodule lemma comap_map_eq (f : M →ₗ[R] M₂) (p : submodule R M) : comap f (map f p) = p ⊔ ker f := begin refine le_antisymm _ (sup_le (le_comap_map _ _) (comap_mono bot_le)), rintro x ⟨y, hy, e⟩, exact mem_sup.2 ⟨y, hy, x - y, by simpa using sub_eq_zero.2 e.symm, by simp⟩ end lemma comap_map_eq_self {f : M →ₗ[R] M₂} {p : submodule R M} (h : ker f ≤ p) : comap f (map f p) = p := by rw [comap_map_eq, sup_of_le_left h] theorem map_le_map_iff (f : M →ₗ[R] M₂) {p p'} : map f p ≤ map f p' ↔ p ≤ p' ⊔ ker f := by rw [map_le_iff_le_comap, comap_map_eq] theorem map_le_map_iff' {f : M →ₗ[R] M₂} (hf : ker f = ⊥) {p p'} : map f p ≤ map f p' ↔ p ≤ p' := by rw [map_le_map_iff, hf, sup_bot_eq] theorem map_injective {f : M →ₗ[R] M₂} (hf : ker f = ⊥) : injective (map f) := λ p p' h, le_antisymm ((map_le_map_iff' hf).1 (le_of_eq h)) ((map_le_map_iff' hf).1 (ge_of_eq h)) theorem map_eq_top_iff {f : M →ₗ[R] M₂} (hf : range f = ⊤) {p : submodule R M} : p.map f = ⊤ ↔ p ⊔ f.ker = ⊤ := by simp_rw [← top_le_iff, ← hf, range, map_le_map_iff] end add_comm_group section ring variables [ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃] variables [semimodule R M] [semimodule R M₂] [semimodule R M₃] variables {f : M →ₗ[R] M₂} include R open submodule theorem sub_mem_ker_iff {x y} : x - y ∈ f.ker ↔ f x = f y := by rw [mem_ker, map_sub, sub_eq_zero] theorem disjoint_ker' {p : submodule R M} : disjoint p (ker f) ↔ ∀ x y ∈ p, f x = f y → x = y := disjoint_ker.trans ⟨λ H x y hx hy h, eq_of_sub_eq_zero $ H _ (sub_mem _ hx hy) (by simp [h]), λ H x h₁ h₂, H x 0 h₁ (zero_mem _) (by simpa using h₂)⟩ theorem inj_of_disjoint_ker {p : submodule R M} {s : set M} (h : s ⊆ p) (hd : disjoint p (ker f)) : ∀ x y ∈ s, f x = f y → x = y := λ x y hx hy, disjoint_ker'.1 hd _ _ (h hx) (h hy) theorem ker_eq_bot : ker f = ⊥ ↔ injective f := by simpa [disjoint] using @disjoint_ker' _ _ _ _ _ _ _ _ f ⊤ lemma ker_le_iff {p : submodule R M} : ker f ≤ p ↔ ∃ (y ∈ range f), f ⁻¹' {y} ⊆ p := begin split, { intros h, use 0, rw [← mem_coe, f.range_coe], exact ⟨⟨0, map_zero f⟩, h⟩, }, { rintros ⟨y, h₁, h₂⟩, rw le_def, intros z hz, simp only [mem_ker, mem_coe] at hz, rw [← mem_coe, f.range_coe, set.mem_range] at h₁, obtain ⟨x, hx⟩ := h₁, have hx' : x ∈ p, { exact h₂ hx, }, have hxz : z + x ∈ p, { apply h₂, simp [hx, hz], }, suffices : z + x - x ∈ p, { simpa only [this, add_sub_cancel], }, exact p.sub_mem hxz hx', }, end end ring section field variables [field K] variables [add_comm_group V] [vector_space K V] variables [add_comm_group V₂] [vector_space K V₂] lemma ker_smul (f : V →ₗ[K] V₂) (a : K) (h : a ≠ 0) : ker (a • f) = ker f := submodule.comap_smul f _ a h lemma ker_smul' (f : V →ₗ[K] V₂) (a : K) : ker (a • f) = ⨅(h : a ≠ 0), ker f := submodule.comap_smul' f _ a lemma range_smul (f : V →ₗ[K] V₂) (a : K) (h : a ≠ 0) : range (a • f) = range f := submodule.map_smul f _ a h lemma range_smul' (f : V →ₗ[K] V₂) (a : K) : range (a • f) = ⨆(h : a ≠ 0), range f := submodule.map_smul' f _ a end field end linear_map namespace is_linear_map lemma is_linear_map_add [semiring R] [add_comm_monoid M] [semimodule R M] : is_linear_map R (λ (x : M × M), x.1 + x.2) := begin apply is_linear_map.mk, { intros x y, simp, cc }, { intros x y, simp [smul_add] } end lemma is_linear_map_sub {R M : Type*} [semiring R] [add_comm_group M] [semimodule R M]: is_linear_map R (λ (x : M × M), x.1 - x.2) := begin apply is_linear_map.mk, { intros x y, simp [add_comm, add_left_comm, sub_eq_add_neg] }, { intros x y, simp [smul_sub] } end end is_linear_map namespace submodule section add_comm_monoid variables {T : semiring R} [add_comm_monoid M] [add_comm_monoid M₂] variables [semimodule R M] [semimodule R M₂] variables (p p' : submodule R M) (q : submodule R M₂) include T open linear_map @[simp] theorem map_top (f : M →ₗ[R] M₂) : map f ⊤ = range f := rfl @[simp] theorem comap_bot (f : M →ₗ[R] M₂) : comap f ⊥ = ker f := rfl @[simp] theorem ker_subtype : p.subtype.ker = ⊥ := ker_eq_bot_of_injective $ λ x y, subtype.ext_val @[simp] theorem range_subtype : p.subtype.range = p := by simpa using map_comap_subtype p ⊤ lemma map_subtype_le (p' : submodule R p) : map p.subtype p' ≤ p := by simpa using (map_mono le_top : map p.subtype p' ≤ p.subtype.range) /-- Under the canonical linear map from a submodule `p` to the ambient space `M`, the image of the maximal submodule of `p` is just `p `. -/ @[simp] lemma map_subtype_top : map p.subtype (⊤ : submodule R p) = p := by simp @[simp] lemma comap_subtype_eq_top {p p' : submodule R M} : comap p.subtype p' = ⊤ ↔ p ≤ p' := eq_top_iff.trans $ map_le_iff_le_comap.symm.trans $ by rw [map_subtype_top] @[simp] lemma comap_subtype_self : comap p.subtype p = ⊤ := comap_subtype_eq_top.2 (le_refl _) @[simp] theorem ker_of_le (p p' : submodule R M) (h : p ≤ p') : (of_le h).ker = ⊥ := by rw [of_le, ker_cod_restrict, ker_subtype] lemma range_of_le (p q : submodule R M) (h : p ≤ q) : (of_le h).range = comap q.subtype p := by rw [← map_top, of_le, linear_map.map_cod_restrict, map_top, range_subtype] end add_comm_monoid section ring variables {T : ring R} [add_comm_group M] [add_comm_group M₂] [semimodule R M] [semimodule R M₂] variables (p p' : submodule R M) (q : submodule R M₂) include T open linear_map lemma disjoint_iff_comap_eq_bot {p q : submodule R M} : disjoint p q ↔ comap p.subtype q = ⊥ := by rw [eq_bot_iff, ← map_le_map_iff' p.ker_subtype, map_bot, map_comap_subtype, disjoint] /-- If `N ⊆ M` then submodules of `N` are the same as submodules of `M` contained in `N` -/ def map_subtype.rel_iso : submodule R p ≃o {p' : submodule R M // p' ≤ p} := { to_fun := λ p', ⟨map p.subtype p', map_subtype_le p _⟩, inv_fun := λ q, comap p.subtype q, left_inv := λ p', comap_map_eq_self $ by simp, right_inv := λ ⟨q, hq⟩, subtype.ext_val $ by simp [map_comap_subtype p, inf_of_le_right hq], map_rel_iff' := λ p₁ p₂, map_le_map_iff' (ker_subtype p) } /-- If `p ⊆ M` is a submodule, the ordering of submodules of `p` is embedded in the ordering of submodules of `M`. -/ def map_subtype.order_embedding : submodule R p ↪o submodule R M := (rel_iso.to_rel_embedding $ map_subtype.rel_iso p).trans (subtype.rel_embedding _ _) @[simp] lemma map_subtype_embedding_eq (p' : submodule R p) : map_subtype.order_embedding p p' = map p.subtype p' := rfl /-- The map from a module `M` to the quotient of `M` by a submodule `p` as a linear map. -/ def mkq : M →ₗ[R] p.quotient := ⟨quotient.mk, by simp, by simp⟩ @[simp] theorem mkq_apply (x : M) : p.mkq x = quotient.mk x := rfl /-- The map from the quotient of `M` by a submodule `p` to `M₂` induced by a linear map `f : M → M₂` vanishing on `p`, as a linear map. -/ def liftq (f : M →ₗ[R] M₂) (h : p ≤ f.ker) : p.quotient →ₗ[R] M₂ := ⟨λ x, _root_.quotient.lift_on' x f $ λ a b (ab : a - b ∈ p), eq_of_sub_eq_zero $ by simpa using h ab, by rintro ⟨x⟩ ⟨y⟩; exact f.map_add x y, by rintro a ⟨x⟩; exact f.map_smul a x⟩ @[simp] theorem liftq_apply (f : M →ₗ[R] M₂) {h} (x : M) : p.liftq f h (quotient.mk x) = f x := rfl @[simp] theorem liftq_mkq (f : M →ₗ[R] M₂) (h) : (p.liftq f h).comp p.mkq = f := by ext; refl @[simp] theorem range_mkq : p.mkq.range = ⊤ := eq_top_iff'.2 $ by rintro ⟨x⟩; exact ⟨x, trivial, rfl⟩ @[simp] theorem ker_mkq : p.mkq.ker = p := by ext; simp lemma le_comap_mkq (p' : submodule R p.quotient) : p ≤ comap p.mkq p' := by simpa using (comap_mono bot_le : p.mkq.ker ≤ comap p.mkq p') @[simp] theorem mkq_map_self : map p.mkq p = ⊥ := by rw [eq_bot_iff, map_le_iff_le_comap, comap_bot, ker_mkq]; exact le_refl _ @[simp] theorem comap_map_mkq : comap p.mkq (map p.mkq p') = p ⊔ p' := by simp [comap_map_eq, sup_comm] @[simp] theorem map_mkq_eq_top : map p.mkq p' = ⊤ ↔ p ⊔ p' = ⊤ := by simp only [map_eq_top_iff p.range_mkq, sup_comm, ker_mkq] /-- The map from the quotient of `M` by submodule `p` to the quotient of `M₂` by submodule `q` along `f : M → M₂` is linear. -/ def mapq (f : M →ₗ[R] M₂) (h : p ≤ comap f q) : p.quotient →ₗ[R] q.quotient := p.liftq (q.mkq.comp f) $ by simpa [ker_comp] using h @[simp] theorem mapq_apply (f : M →ₗ[R] M₂) {h} (x : M) : mapq p q f h (quotient.mk x) = quotient.mk (f x) := rfl theorem mapq_mkq (f : M →ₗ[R] M₂) {h} : (mapq p q f h).comp p.mkq = q.mkq.comp f := by ext x; refl theorem comap_liftq (f : M →ₗ[R] M₂) (h) : q.comap (p.liftq f h) = (q.comap f).map (mkq p) := le_antisymm (by rintro ⟨x⟩ hx; exact ⟨_, hx, rfl⟩) (by rw [map_le_iff_le_comap, ← comap_comp, liftq_mkq]; exact le_refl _) theorem map_liftq (f : M →ₗ[R] M₂) (h) (q : submodule R (quotient p)) : q.map (p.liftq f h) = (q.comap p.mkq).map f := le_antisymm (by rintro _ ⟨⟨x⟩, hxq, rfl⟩; exact ⟨x, hxq, rfl⟩) (by rintro _ ⟨x, hxq, rfl⟩; exact ⟨quotient.mk x, hxq, rfl⟩) theorem ker_liftq (f : M →ₗ[R] M₂) (h) : ker (p.liftq f h) = (ker f).map (mkq p) := comap_liftq _ _ _ _ theorem range_liftq (f : M →ₗ[R] M₂) (h) : range (p.liftq f h) = range f := map_liftq _ _ _ _ theorem ker_liftq_eq_bot (f : M →ₗ[R] M₂) (h) (h' : ker f ≤ p) : ker (p.liftq f h) = ⊥ := by rw [ker_liftq, le_antisymm h h', mkq_map_self] /-- The correspondence theorem for modules: there is an order isomorphism between submodules of the quotient of `M` by `p`, and submodules of `M` larger than `p`. -/ def comap_mkq.rel_iso : submodule R p.quotient ≃o {p' : submodule R M // p ≤ p'} := { to_fun := λ p', ⟨comap p.mkq p', le_comap_mkq p _⟩, inv_fun := λ q, map p.mkq q, left_inv := λ p', map_comap_eq_self $ by simp, right_inv := λ ⟨q, hq⟩, subtype.ext_val $ by simpa [comap_map_mkq p], map_rel_iff' := λ p₁ p₂, comap_le_comap_iff $ range_mkq _ } /-- The ordering on submodules of the quotient of `M` by `p` embeds into the ordering on submodules of `M`. -/ def comap_mkq.order_embedding : submodule R p.quotient ↪o submodule R M := (rel_iso.to_rel_embedding $ comap_mkq.rel_iso p).trans (subtype.rel_embedding _ _) @[simp] lemma comap_mkq_embedding_eq (p' : submodule R p.quotient) : comap_mkq.order_embedding p p' = comap p.mkq p' := rfl lemma span_preimage_eq {f : M →ₗ[R] M₂} {s : set M₂} (h₀ : s.nonempty) (h₁ : s ⊆ range f) : span R (f ⁻¹' s) = (span R s).comap f := begin suffices : (span R s).comap f ≤ span R (f ⁻¹' s), { exact le_antisymm (span_preimage_le f s) this, }, have hk : ker f ≤ span R (f ⁻¹' s), { let y := classical.some h₀, have hy : y ∈ s, { exact classical.some_spec h₀, }, rw ker_le_iff, use [y, h₁ hy], rw ← set.singleton_subset_iff at hy, exact set.subset.trans subset_span (span_mono (set.preimage_mono hy)), }, rw ← left_eq_sup at hk, rw f.range_coe at h₁, rw [hk, ← map_le_map_iff, map_span, map_comap_eq, set.image_preimage_eq_of_subset h₁], exact inf_le_right, end end ring end submodule namespace linear_map variables [ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃] variables [module R M] [module R M₂] [module R M₃] lemma range_mkq_comp (f : M →ₗ[R] M₂) : f.range.mkq.comp f = 0 := linear_map.ext $ λ x, by simp lemma ker_le_range_iff {f : M →ₗ[R] M₂} {g : M₂ →ₗ[R] M₃} : g.ker ≤ f.range ↔ f.range.mkq.comp g.ker.subtype = 0 := by rw [←range_le_ker_iff, submodule.ker_mkq, submodule.range_subtype] /-- A monomorphism is injective. -/ lemma ker_eq_bot_of_cancel {f : M →ₗ[R] M₂} (h : ∀ (u v : f.ker →ₗ[R] M), f.comp u = f.comp v → u = v) : f.ker = ⊥ := begin have h₁ : f.comp (0 : f.ker →ₗ[R] M) = 0 := comp_zero _, rw [←submodule.range_subtype f.ker, ←h 0 f.ker.subtype (eq.trans h₁ (comp_ker_subtype f).symm)], exact range_zero end /-- An epimorphism is surjective. -/ lemma range_eq_top_of_cancel {f : M →ₗ[R] M₂} (h : ∀ (u v : M₂ →ₗ[R] f.range.quotient), u.comp f = v.comp f → u = v) : f.range = ⊤ := begin have h₁ : (0 : M₂ →ₗ[R] f.range.quotient).comp f = 0 := zero_comp _, rw [←submodule.ker_mkq f.range, ←h 0 f.range.mkq (eq.trans h₁ (range_mkq_comp _).symm)], exact ker_zero end end linear_map @[simp] lemma linear_map.range_range_restrict [semiring R] [add_comm_monoid M] [add_comm_monoid M₂] [semimodule R M] [semimodule R M₂] (f : M →ₗ[R] M₂) : f.range_restrict.range = ⊤ := by simp [f.range_cod_restrict _] /-! ### Linear equivalences -/ namespace linear_equiv section add_comm_monoid variables [semiring R] [add_comm_monoid M] [add_comm_monoid M₂] [add_comm_monoid M₃] [add_comm_monoid M₄] section variables {semimodule_M : semimodule R M} {semimodule_M₂ : semimodule R M₂} variables (e e' : M ≃ₗ[R] M₂) lemma map_eq_comap {p : submodule R M} : (p.map e : submodule R M₂) = p.comap e.symm := submodule.coe_injective $ by simp [e.image_eq_preimage] /-- A linear equivalence of two modules restricts to a linear equivalence from any submodule of the domain onto the image of the submodule. -/ def of_submodule (p : submodule R M) : p ≃ₗ[R] ↥(p.map ↑e : submodule R M₂) := { inv_fun := λ y, ⟨e.symm y, by { rcases y with ⟨y', hy⟩, rw submodule.mem_map at hy, rcases hy with ⟨x, hx, hxy⟩, subst hxy, simp only [symm_apply_apply, submodule.coe_mk, coe_coe, hx], }⟩, left_inv := λ x, by simp, right_inv := λ y, by { apply set_coe.ext, simp, }, ..((e : M →ₗ[R] M₂).dom_restrict p).cod_restrict (p.map ↑e) (λ x, ⟨x, by simp⟩) } @[simp] lemma of_submodule_apply (p : submodule R M) (x : p) : ↑(e.of_submodule p x) = e x := rfl @[simp] lemma of_submodule_symm_apply (p : submodule R M) (x : (p.map ↑e : submodule R M₂)) : ↑((e.of_submodule p).symm x) = e.symm x := rfl end section uncurry variables (V V₂ R) /-- Linear equivalence between a curried and uncurried function. Differs from `tensor_product.curry`. -/ protected def uncurry : (V → V₂ → R) ≃ₗ[R] (V × V₂ → R) := { map_add' := λ _ _, by { ext ⟨⟩, refl }, map_smul' := λ _ _, by { ext ⟨⟩, refl }, .. equiv.arrow_arrow_equiv_prod_arrow _ _ _} @[simp] lemma coe_uncurry : ⇑(linear_equiv.uncurry R V V₂) = uncurry := rfl @[simp] lemma coe_uncurry_symm : ⇑(linear_equiv.uncurry R V V₂).symm = curry := rfl end uncurry section variables {semimodule_M : semimodule R M} {semimodule_M₂ : semimodule R M₂} variables (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M) (e : M ≃ₗ[R] M₂) variables (p q : submodule R M) /-- Linear equivalence between two equal submodules. -/ def of_eq (h : p = q) : p ≃ₗ[R] q := { map_smul' := λ _ _, rfl, map_add' := λ _ _, rfl, .. equiv.set.of_eq (congr_arg _ h) } variables {p q} @[simp] lemma coe_of_eq_apply (h : p = q) (x : p) : (of_eq p q h x : M) = x := rfl @[simp] lemma of_eq_symm (h : p = q) : (of_eq p q h).symm = of_eq q p h.symm := rfl /-- A linear equivalence which maps a submodule of one module onto another, restricts to a linear equivalence of the two submodules. -/ def of_submodules (p : submodule R M) (q : submodule R M₂) (h : p.map ↑e = q) : p ≃ₗ[R] q := (e.of_submodule p).trans (linear_equiv.of_eq _ _ h) @[simp] lemma of_submodules_apply {p : submodule R M} {q : submodule R M₂} (h : p.map ↑e = q) (x : p) : ↑(e.of_submodules p q h x) = e x := rfl @[simp] lemma of_submodules_symm_apply {p : submodule R M} {q : submodule R M₂} (h : p.map ↑e = q) (x : q) : ↑((e.of_submodules p q h).symm x) = e.symm x := rfl variable (p) /-- The top submodule of `M` is linearly equivalent to `M`. -/ def of_top (h : p = ⊤) : p ≃ₗ[R] M := { inv_fun := λ x, ⟨x, h.symm ▸ trivial⟩, left_inv := λ ⟨x, h⟩, rfl, right_inv := λ x, rfl, .. p.subtype } @[simp] theorem of_top_apply {h} (x : p) : of_top p h x = x := rfl @[simp] theorem coe_of_top_symm_apply {h} (x : M) : ((of_top p h).symm x : M) = x := rfl theorem of_top_symm_apply {h} (x : M) : (of_top p h).symm x = ⟨x, h.symm ▸ trivial⟩ := rfl /-- If a linear map has an inverse, it is a linear equivalence. -/ def of_linear (h₁ : f.comp g = linear_map.id) (h₂ : g.comp f = linear_map.id) : M ≃ₗ[R] M₂ := { inv_fun := g, left_inv := linear_map.ext_iff.1 h₂, right_inv := linear_map.ext_iff.1 h₁, ..f } @[simp] theorem of_linear_apply {h₁ h₂} (x : M) : of_linear f g h₁ h₂ x = f x := rfl @[simp] theorem of_linear_symm_apply {h₁ h₂} (x : M₂) : (of_linear f g h₁ h₂).symm x = g x := rfl @[simp] protected theorem range : (e : M →ₗ[R] M₂).range = ⊤ := linear_map.range_eq_top.2 e.to_equiv.surjective lemma eq_bot_of_equiv [semimodule R M₂] (e : p ≃ₗ[R] (⊥ : submodule R M₂)) : p = ⊥ := begin refine bot_unique (submodule.le_def'.2 $ assume b hb, (submodule.mem_bot R).2 _), rw [← p.mk_eq_zero hb, ← e.map_eq_zero_iff], apply submodule.eq_zero_of_bot_submodule end @[simp] protected theorem ker : (e : M →ₗ[R] M₂).ker = ⊥ := linear_map.ker_eq_bot_of_injective e.to_equiv.injective variables {f g} /-- An linear map `f : M →ₗ[R] M₂` with a left-inverse `g : M₂ →ₗ[R] M` defines a linear equivalence between `M` and `f.range`. This is a computable alternative to `linear_equiv.of_injective`, and a bidirectional version of `linear_map.range_restrict`. -/ def of_left_inverse {g : M₂ → M} (h : function.left_inverse g f) : M ≃ₗ[R] f.range := { to_fun := f.range_restrict, inv_fun := g ∘ f.range.subtype, left_inv := h, right_inv := λ x, subtype.ext $ let ⟨x', hx'⟩ := linear_map.mem_range.mp x.prop in show f (g x) = x, by rw [←hx', h x'], .. f.range_restrict } @[simp] lemma of_left_inverse_apply (h : function.left_inverse g f) (x : M) : ↑(of_left_inverse h x) = f x := rfl @[simp] lemma of_left_inverse_symm_apply (h : function.left_inverse g f) (x : f.range) : (of_left_inverse h).symm x = g x := rfl end end add_comm_monoid section add_comm_group variables [semiring R] variables [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃] [add_comm_group M₄] variables {semimodule_M : semimodule R M} {semimodule_M₂ : semimodule R M₂} variables {semimodule_M₃ : semimodule R M₃} {semimodule_M₄ : semimodule R M₄} variables (e e₁ : M ≃ₗ[R] M₂) (e₂ : M₃ ≃ₗ[R] M₄) @[simp] theorem map_neg (a : M) : e (-a) = -e a := e.to_linear_map.map_neg a @[simp] theorem map_sub (a b : M) : e (a - b) = e a - e b := e.to_linear_map.map_sub a b end add_comm_group section neg variables (R) [semiring R] [add_comm_group M] [semimodule R M] /-- `x ↦ -x` as a `linear_equiv` -/ def neg : M ≃ₗ[R] M := { .. equiv.neg M, .. (-linear_map.id : M →ₗ[R] M) } variable {R} @[simp] lemma coe_neg : ⇑(neg R : M ≃ₗ[R] M) = -id := rfl lemma neg_apply (x : M) : neg R x = -x := by simp @[simp] lemma symm_neg : (neg R : M ≃ₗ[R] M).symm = neg R := rfl end neg section ring variables [ring R] [add_comm_group M] [add_comm_group M₂] variables {semimodule_M : semimodule R M} {semimodule_M₂ : semimodule R M₂} variables (f : M →ₗ[R] M₂) (e : M ≃ₗ[R] M₂) /-- An `injective` linear map `f : M →ₗ[R] M₂` defines a linear equivalence between `M` and `f.range`. See also `linear_map.of_left_inverse`. -/ noncomputable def of_injective (h : f.ker = ⊥) : M ≃ₗ[R] f.range := of_left_inverse $ classical.some_spec (linear_map.ker_eq_bot.1 h).has_left_inverse @[simp] theorem of_injective_apply {h : f.ker = ⊥} (x : M) : ↑(of_injective f h x) = f x := rfl /-- A bijective linear map is a linear equivalence. Here, bijectivity is described by saying that the kernel of `f` is `{0}` and the range is the universal set. -/ noncomputable def of_bijective (hf₁ : f.ker = ⊥) (hf₂ : f.range = ⊤) : M ≃ₗ[R] M₂ := (of_injective f hf₁).trans (of_top _ hf₂) @[simp] theorem of_bijective_apply {hf₁ hf₂} (x : M) : of_bijective f hf₁ hf₂ x = f x := rfl end ring section comm_ring variables [comm_ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃] variables [semimodule R M] [semimodule R M₂] [semimodule R M₃] open linear_map /-- Multiplying by a unit `a` of the ring `R` is a linear equivalence. -/ def smul_of_unit (a : units R) : M ≃ₗ[R] M := of_linear ((a:R) • 1 : M →ₗ M) (((a⁻¹ : units R) : R) • 1 : M →ₗ M) (by rw [smul_comp, comp_smul, smul_smul, units.mul_inv, one_smul]; refl) (by rw [smul_comp, comp_smul, smul_smul, units.inv_mul, one_smul]; refl) /-- A linear isomorphism between the domains and codomains of two spaces of linear maps gives a linear isomorphism between the two function spaces. -/ def arrow_congr {R M₁ M₂ M₂₁ M₂₂ : Sort*} [comm_ring R] [add_comm_group M₁] [add_comm_group M₂] [add_comm_group M₂₁] [add_comm_group M₂₂] [module R M₁] [module R M₂] [module R M₂₁] [module R M₂₂] (e₁ : M₁ ≃ₗ[R] M₂) (e₂ : M₂₁ ≃ₗ[R] M₂₂) : (M₁ →ₗ[R] M₂₁) ≃ₗ[R] (M₂ →ₗ[R] M₂₂) := { to_fun := λ f, (e₂ : M₂₁ →ₗ[R] M₂₂).comp $ f.comp e₁.symm, inv_fun := λ f, (e₂.symm : M₂₂ →ₗ[R] M₂₁).comp $ f.comp e₁, left_inv := λ f, by { ext x, simp }, right_inv := λ f, by { ext x, simp }, map_add' := λ f g, by { ext x, simp }, map_smul' := λ c f, by { ext x, simp } } @[simp] lemma arrow_congr_apply {R M₁ M₂ M₂₁ M₂₂ : Sort*} [comm_ring R] [add_comm_group M₁] [add_comm_group M₂] [add_comm_group M₂₁] [add_comm_group M₂₂] [module R M₁] [module R M₂] [module R M₂₁] [module R M₂₂] (e₁ : M₁ ≃ₗ[R] M₂) (e₂ : M₂₁ ≃ₗ[R] M₂₂) (f : M₁ →ₗ[R] M₂₁) (x : M₂) : arrow_congr e₁ e₂ f x = e₂ (f (e₁.symm x)) := rfl @[simp] lemma arrow_congr_symm_apply {R M₁ M₂ M₂₁ M₂₂ : Sort*} [comm_ring R] [add_comm_group M₁] [add_comm_group M₂] [add_comm_group M₂₁] [add_comm_group M₂₂] [module R M₁] [module R M₂] [module R M₂₁] [module R M₂₂] (e₁ : M₁ ≃ₗ[R] M₂) (e₂ : M₂₁ ≃ₗ[R] M₂₂) (f : M₂ →ₗ[R] M₂₂) (x : M₁) : (arrow_congr e₁ e₂).symm f x = e₂.symm (f (e₁ x)) := rfl lemma arrow_congr_comp {N N₂ N₃ : Sort*} [add_comm_group N] [add_comm_group N₂] [add_comm_group N₃] [module R N] [module R N₂] [module R N₃] (e₁ : M ≃ₗ[R] N) (e₂ : M₂ ≃ₗ[R] N₂) (e₃ : M₃ ≃ₗ[R] N₃) (f : M →ₗ[R] M₂) (g : M₂ →ₗ[R] M₃) : arrow_congr e₁ e₃ (g.comp f) = (arrow_congr e₂ e₃ g).comp (arrow_congr e₁ e₂ f) := by { ext, simp only [symm_apply_apply, arrow_congr_apply, linear_map.comp_apply], } lemma arrow_congr_trans {M₁ M₂ M₃ N₁ N₂ N₃ : Sort*} [add_comm_group M₁] [module R M₁] [add_comm_group M₂] [module R M₂] [add_comm_group M₃] [module R M₃] [add_comm_group N₁] [module R N₁] [add_comm_group N₂] [module R N₂] [add_comm_group N₃] [module R N₃] (e₁ : M₁ ≃ₗ[R] M₂) (e₂ : N₁ ≃ₗ[R] N₂) (e₃ : M₂ ≃ₗ[R] M₃) (e₄ : N₂ ≃ₗ[R] N₃) : (arrow_congr e₁ e₂).trans (arrow_congr e₃ e₄) = arrow_congr (e₁.trans e₃) (e₂.trans e₄) := rfl /-- If `M₂` and `M₃` are linearly isomorphic then the two spaces of linear maps from `M` into `M₂` and `M` into `M₃` are linearly isomorphic. -/ def congr_right (f : M₂ ≃ₗ[R] M₃) : (M →ₗ[R] M₂) ≃ₗ (M →ₗ M₃) := arrow_congr (linear_equiv.refl R M) f /-- If `M` and `M₂` are linearly isomorphic then the two spaces of linear maps from `M` and `M₂` to themselves are linearly isomorphic. -/ def conj (e : M ≃ₗ[R] M₂) : (module.End R M) ≃ₗ[R] (module.End R M₂) := arrow_congr e e lemma conj_apply (e : M ≃ₗ[R] M₂) (f : module.End R M) : e.conj f = ((↑e : M →ₗ[R] M₂).comp f).comp e.symm := rfl lemma symm_conj_apply (e : M ≃ₗ[R] M₂) (f : module.End R M₂) : e.symm.conj f = ((↑e.symm : M₂ →ₗ[R] M).comp f).comp e := rfl lemma conj_comp (e : M ≃ₗ[R] M₂) (f g : module.End R M) : e.conj (g.comp f) = (e.conj g).comp (e.conj f) := arrow_congr_comp e e e f g lemma conj_trans (e₁ : M ≃ₗ[R] M₂) (e₂ : M₂ ≃ₗ[R] M₃) : e₁.conj.trans e₂.conj = (e₁.trans e₂).conj := by { ext f x, refl, } @[simp] lemma conj_id (e : M ≃ₗ[R] M₂) : e.conj linear_map.id = linear_map.id := by { ext, simp [conj_apply], } end comm_ring section field variables [field K] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃] variables [module K M] [module K M₂] [module K M₃] variables (K) (M) open linear_map /-- Multiplying by a nonzero element `a` of the field `K` is a linear equivalence. -/ def smul_of_ne_zero (a : K) (ha : a ≠ 0) : M ≃ₗ[K] M := smul_of_unit $ units.mk0 a ha section noncomputable theory open_locale classical lemma ker_to_span_singleton {x : M} (h : x ≠ 0) : (to_span_singleton K M x).ker = ⊥ := begin ext c, split, { intros hc, rw submodule.mem_bot, rw mem_ker at hc, by_contra hc', have : x = 0, calc x = c⁻¹ • (c • x) : by rw [← mul_smul, inv_mul_cancel hc', one_smul] ... = c⁻¹ • ((to_span_singleton K M x) c) : rfl ... = 0 : by rw [hc, smul_zero], tauto }, { rw [mem_ker, submodule.mem_bot], intros h, rw h, simp } end /-- Given a nonzero element `x` of a vector space `M` over a field `K`, the natural map from `K` to the span of `x`, with invertibility check to consider it as an isomorphism.-/ def to_span_nonzero_singleton (x : M) (h : x ≠ 0) : K ≃ₗ[K] (K ∙ x) := linear_equiv.trans (linear_equiv.of_injective (to_span_singleton K M x) (ker_to_span_singleton K M h)) (of_eq (to_span_singleton K M x).range (K ∙ x) (span_singleton_eq_range K M x).symm) lemma to_span_nonzero_singleton_one (x : M) (h : x ≠ 0) : to_span_nonzero_singleton K M x h 1 = (⟨x, submodule.mem_span_singleton_self x⟩ : K ∙ x) := begin apply submodule.coe_eq_coe.mp, have : ↑(to_span_nonzero_singleton K M x h 1) = to_span_singleton K M x 1 := rfl, rw [this, to_span_singleton_one, submodule.coe_mk], end /-- Given a nonzero element `x` of a vector space `M` over a field `K`, the natural map from the span of `x` to `K`.-/ abbreviation coord (x : M) (h : x ≠ 0) : (K ∙ x) ≃ₗ[K] K := (to_span_nonzero_singleton K M x h).symm lemma coord_self (x : M) (h : x ≠ 0) : (coord K M x h) (⟨x, submodule.mem_span_singleton_self x⟩ : K ∙ x) = 1 := by rw [← to_span_nonzero_singleton_one K M x h, symm_apply_apply] end end field end linear_equiv namespace submodule section semimodule variables [semiring R] [add_comm_monoid M] [semimodule R M] /-- If `s ≤ t`, then we can view `s` as a submodule of `t` by taking the comap of `t.subtype`. -/ def comap_subtype_equiv_of_le {p q : submodule R M} (hpq : p ≤ q) : comap q.subtype p ≃ₗ[R] p := { to_fun := λ x, ⟨x, x.2⟩, inv_fun := λ x, ⟨⟨x, hpq x.2⟩, x.2⟩, left_inv := λ x, by simp only [coe_mk, submodule.eta, coe_coe], right_inv := λ x, by simp only [subtype.coe_mk, submodule.eta, coe_coe], map_add' := λ x y, rfl, map_smul' := λ c x, rfl } end semimodule variables [ring R] [add_comm_group M] [module R M] variables (p : submodule R M) open linear_map /-- If `p = ⊥`, then `M / p ≃ₗ[R] M`. -/ def quot_equiv_of_eq_bot (hp : p = ⊥) : p.quotient ≃ₗ[R] M := linear_equiv.of_linear (p.liftq id $ hp.symm ▸ bot_le) p.mkq (liftq_mkq _ _ _) $ p.quot_hom_ext $ λ x, rfl @[simp] lemma quot_equiv_of_eq_bot_apply_mk (hp : p = ⊥) (x : M) : p.quot_equiv_of_eq_bot hp (quotient.mk x) = x := rfl @[simp] lemma quot_equiv_of_eq_bot_symm_apply (hp : p = ⊥) (x : M) : (p.quot_equiv_of_eq_bot hp).symm x = quotient.mk x := rfl @[simp] lemma coe_quot_equiv_of_eq_bot_symm (hp : p = ⊥) : ((p.quot_equiv_of_eq_bot hp).symm : M →ₗ[R] p.quotient) = p.mkq := rfl variables (q : submodule R M) /-- Quotienting by equal submodules gives linearly equivalent quotients. -/ def quot_equiv_of_eq (h : p = q) : p.quotient ≃ₗ[R] q.quotient := { map_add' := by { rintros ⟨x⟩ ⟨y⟩, refl }, map_smul' := by { rintros x ⟨y⟩, refl }, ..@quotient.congr _ _ (quotient_rel p) (quotient_rel q) (equiv.refl _) $ λ a b, by { subst h, refl } } end submodule namespace submodule variables [comm_ring R] [add_comm_group M] [add_comm_group M₂] [module R M] [module R M₂] variables (p : submodule R M) (q : submodule R M₂) @[simp] lemma mem_map_equiv {e : M ≃ₗ[R] M₂} {x : M₂} : x ∈ p.map (e : M →ₗ[R] M₂) ↔ e.symm x ∈ p := begin rw submodule.mem_map, split, { rintros ⟨y, hy, hx⟩, simp [←hx, hy], }, { intros hx, refine ⟨e.symm x, hx, by simp⟩, }, end lemma comap_le_comap_smul (f : M →ₗ[R] M₂) (c : R) : comap f q ≤ comap (c • f) q := begin rw le_def', intros m h, change c • (f m) ∈ q, change f m ∈ q at h, apply q.smul_mem _ h, end lemma inf_comap_le_comap_add (f₁ f₂ : M →ₗ[R] M₂) : comap f₁ q ⊓ comap f₂ q ≤ comap (f₁ + f₂) q := begin rw le_def', intros m h, change f₁ m + f₂ m ∈ q, change f₁ m ∈ q ∧ f₂ m ∈ q at h, apply q.add_mem h.1 h.2, end /-- Given modules `M`, `M₂` over a commutative ring, together with submodules `p ⊆ M`, `q ⊆ M₂`, the set of maps $\{f ∈ Hom(M, M₂) | f(p) ⊆ q \}$ is a submodule of `Hom(M, M₂)`. -/ def compatible_maps : submodule R (M →ₗ[R] M₂) := { carrier := {f | p ≤ comap f q}, zero_mem' := by { change p ≤ comap 0 q, rw comap_zero, refine le_top, }, add_mem' := λ f₁ f₂ h₁ h₂, by { apply le_trans _ (inf_comap_le_comap_add q f₁ f₂), rw le_inf_iff, exact ⟨h₁, h₂⟩, }, smul_mem' := λ c f h, le_trans h (comap_le_comap_smul q f c), } /-- Given modules `M`, `M₂` over a commutative ring, together with submodules `p ⊆ M`, `q ⊆ M₂`, the natural map $\{f ∈ Hom(M, M₂) | f(p) ⊆ q \} \to Hom(M/p, M₂/q)$ is linear. -/ def mapq_linear : compatible_maps p q →ₗ[R] p.quotient →ₗ[R] q.quotient := { to_fun := λ f, mapq _ _ f.val f.property, map_add' := λ x y, by { ext m', apply quotient.induction_on' m', intros m, refl, }, map_smul' := λ c f, by { ext m', apply quotient.induction_on' m', intros m, refl, } } end submodule namespace equiv variables [semiring R] [add_comm_monoid M] [semimodule R M] [add_comm_monoid M₂] [semimodule R M₂] /-- An equivalence whose underlying function is linear is a linear equivalence. -/ def to_linear_equiv (e : M ≃ M₂) (h : is_linear_map R (e : M → M₂)) : M ≃ₗ[R] M₂ := { .. e, .. h.mk' e} end equiv namespace add_equiv variables [semiring R] [add_comm_monoid M] [semimodule R M] [add_comm_monoid M₂] [semimodule R M₂] /-- An additive equivalence whose underlying function preserves `smul` is a linear equivalence. -/ def to_linear_equiv (e : M ≃+ M₂) (h : ∀ (c : R) x, e (c • x) = c • e x) : M ≃ₗ[R] M₂ := { map_smul' := h, .. e, } @[simp] lemma coe_to_linear_equiv (e : M ≃+ M₂) (h : ∀ (c : R) x, e (c • x) = c • e x) : ⇑(e.to_linear_equiv h) = e := rfl @[simp] lemma coe_to_linear_equiv_symm (e : M ≃+ M₂) (h : ∀ (c : R) x, e (c • x) = c • e x) : ⇑(e.to_linear_equiv h).symm = e.symm := rfl end add_equiv namespace linear_map open submodule section isomorphism_laws variables [ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃] variables [module R M] [module R M₂] [module R M₃] variables (f : M →ₗ[R] M₂) /-- The first isomorphism law for modules. The quotient of `M` by the kernel of `f` is linearly equivalent to the range of `f`. -/ noncomputable def quot_ker_equiv_range : f.ker.quotient ≃ₗ[R] f.range := (linear_equiv.of_injective (f.ker.liftq f $ le_refl _) $ submodule.ker_liftq_eq_bot _ _ _ (le_refl f.ker)).trans (linear_equiv.of_eq _ _ $ submodule.range_liftq _ _ _) /-- The first isomorphism theorem for surjective linear maps. -/ noncomputable def quot_ker_equiv_of_surjective (f : M →ₗ[R] M₂) (hf : function.surjective f) : f.ker.quotient ≃ₗ[R] M₂ := f.quot_ker_equiv_range.trans (linear_equiv.of_top f.range (linear_map.range_eq_top.2 hf)) @[simp] lemma quot_ker_equiv_range_apply_mk (x : M) : (f.quot_ker_equiv_range (submodule.quotient.mk x) : M₂) = f x := rfl @[simp] lemma quot_ker_equiv_range_symm_apply_image (x : M) (h : f x ∈ f.range) : f.quot_ker_equiv_range.symm ⟨f x, h⟩ = f.ker.mkq x := f.quot_ker_equiv_range.symm_apply_apply (f.ker.mkq x) /-- Canonical linear map from the quotient `p/(p ∩ p')` to `(p+p')/p'`, mapping `x + (p ∩ p')` to `x + p'`, where `p` and `p'` are submodules of an ambient module. -/ def quotient_inf_to_sup_quotient (p p' : submodule R M) : (comap p.subtype (p ⊓ p')).quotient →ₗ[R] (comap (p ⊔ p').subtype p').quotient := (comap p.subtype (p ⊓ p')).liftq ((comap (p ⊔ p').subtype p').mkq.comp (of_le le_sup_left)) begin rw [ker_comp, of_le, comap_cod_restrict, ker_mkq, map_comap_subtype], exact comap_mono (inf_le_inf_right _ le_sup_left) end /-- Second Isomorphism Law : the canonical map from `p/(p ∩ p')` to `(p+p')/p'` as a linear isomorphism. -/ noncomputable def quotient_inf_equiv_sup_quotient (p p' : submodule R M) : (comap p.subtype (p ⊓ p')).quotient ≃ₗ[R] (comap (p ⊔ p').subtype p').quotient := linear_equiv.of_bijective (quotient_inf_to_sup_quotient p p') begin rw [quotient_inf_to_sup_quotient, ker_liftq_eq_bot], rw [ker_comp, ker_mkq], exact λ ⟨x, hx1⟩ hx2, ⟨hx1, hx2⟩ end begin rw [quotient_inf_to_sup_quotient, range_liftq, eq_top_iff'], rintros ⟨x, hx⟩, rcases mem_sup.1 hx with ⟨y, hy, z, hz, rfl⟩, use [⟨y, hy⟩, trivial], apply (submodule.quotient.eq _).2, change y - (y + z) ∈ p', rwa [sub_add_eq_sub_sub, sub_self, zero_sub, neg_mem_iff] end @[simp] lemma coe_quotient_inf_to_sup_quotient (p p' : submodule R M) : ⇑(quotient_inf_to_sup_quotient p p') = quotient_inf_equiv_sup_quotient p p' := rfl @[simp] lemma quotient_inf_equiv_sup_quotient_apply_mk (p p' : submodule R M) (x : p) : quotient_inf_equiv_sup_quotient p p' (submodule.quotient.mk x) = submodule.quotient.mk (of_le (le_sup_left : p ≤ p ⊔ p') x) := rfl lemma quotient_inf_equiv_sup_quotient_symm_apply_left (p p' : submodule R M) (x : p ⊔ p') (hx : (x:M) ∈ p) : (quotient_inf_equiv_sup_quotient p p').symm (submodule.quotient.mk x) = submodule.quotient.mk ⟨x, hx⟩ := (linear_equiv.symm_apply_eq _).2 $ by simp [of_le_apply] @[simp] lemma quotient_inf_equiv_sup_quotient_symm_apply_eq_zero_iff {p p' : submodule R M} {x : p ⊔ p'} : (quotient_inf_equiv_sup_quotient p p').symm (submodule.quotient.mk x) = 0 ↔ (x:M) ∈ p' := (linear_equiv.symm_apply_eq _).trans $ by simp [of_le_apply] lemma quotient_inf_equiv_sup_quotient_symm_apply_right (p p' : submodule R M) {x : p ⊔ p'} (hx : (x:M) ∈ p') : (quotient_inf_equiv_sup_quotient p p').symm (submodule.quotient.mk x) = 0 := quotient_inf_equiv_sup_quotient_symm_apply_eq_zero_iff.2 hx end isomorphism_laws section fun_left variables (R M) [semiring R] [add_comm_monoid M] [semimodule R M] variables {m n p : Type*} /-- Given an `R`-module `M` and a function `m → n` between arbitrary types, construct a linear map `(n → M) →ₗ[R] (m → M)` -/ def fun_left (f : m → n) : (n → M) →ₗ[R] (m → M) := mk (∘f) (λ _ _, rfl) (λ _ _, rfl) @[simp] theorem fun_left_apply (f : m → n) (g : n → M) (i : m) : fun_left R M f g i = g (f i) := rfl @[simp] theorem fun_left_id (g : n → M) : fun_left R M _root_.id g = g := rfl theorem fun_left_comp (f₁ : n → p) (f₂ : m → n) : fun_left R M (f₁ ∘ f₂) = (fun_left R M f₂).comp (fun_left R M f₁) := rfl /-- Given an `R`-module `M` and an equivalence `m ≃ n` between arbitrary types, construct a linear equivalence `(n → M) ≃ₗ[R] (m → M)` -/ def fun_congr_left (e : m ≃ n) : (n → M) ≃ₗ[R] (m → M) := linear_equiv.of_linear (fun_left R M e) (fun_left R M e.symm) (ext $ λ x, funext $ λ i, by rw [id_apply, ← fun_left_comp, equiv.symm_comp_self, fun_left_id]) (ext $ λ x, funext $ λ i, by rw [id_apply, ← fun_left_comp, equiv.self_comp_symm, fun_left_id]) @[simp] theorem fun_congr_left_apply (e : m ≃ n) (x : n → M) : fun_congr_left R M e x = fun_left R M e x := rfl @[simp] theorem fun_congr_left_id : fun_congr_left R M (equiv.refl n) = linear_equiv.refl R (n → M) := rfl @[simp] theorem fun_congr_left_comp (e₁ : m ≃ n) (e₂ : n ≃ p) : fun_congr_left R M (equiv.trans e₁ e₂) = linear_equiv.trans (fun_congr_left R M e₂) (fun_congr_left R M e₁) := rfl @[simp] lemma fun_congr_left_symm (e : m ≃ n) : (fun_congr_left R M e).symm = fun_congr_left R M e.symm := rfl end fun_left universe i variables [semiring R] [add_comm_monoid M] [semimodule R M] variables (R M) instance automorphism_group : group (M ≃ₗ[R] M) := { mul := λ f g, g.trans f, one := linear_equiv.refl R M, inv := λ f, f.symm, mul_assoc := λ f g h, by {ext, refl}, mul_one := λ f, by {ext, refl}, one_mul := λ f, by {ext, refl}, mul_left_inv := λ f, by {ext, exact f.left_inv x} } instance automorphism_group.to_linear_map_is_monoid_hom : is_monoid_hom (linear_equiv.to_linear_map : (M ≃ₗ[R] M) → (M →ₗ[R] M)) := { map_one := rfl, map_mul := λ f g, rfl } /-- The group of invertible linear maps from `M` to itself -/ @[reducible] def general_linear_group := units (M →ₗ[R] M) namespace general_linear_group variables {R M} instance : has_coe_to_fun (general_linear_group R M) := by apply_instance /-- An invertible linear map `f` determines an equivalence from `M` to itself. -/ def to_linear_equiv (f : general_linear_group R M) : (M ≃ₗ[R] M) := { inv_fun := f.inv.to_fun, left_inv := λ m, show (f.inv * f.val) m = m, by erw f.inv_val; simp, right_inv := λ m, show (f.val * f.inv) m = m, by erw f.val_inv; simp, ..f.val } /-- An equivalence from `M` to itself determines an invertible linear map. -/ def of_linear_equiv (f : (M ≃ₗ[R] M)) : general_linear_group R M := { val := f, inv := f.symm, val_inv := linear_map.ext $ λ _, f.apply_symm_apply _, inv_val := linear_map.ext $ λ _, f.symm_apply_apply _ } variables (R M) /-- The general linear group on `R` and `M` is multiplicatively equivalent to the type of linear equivalences between `M` and itself. -/ def general_linear_equiv : general_linear_group R M ≃* (M ≃ₗ[R] M) := { to_fun := to_linear_equiv, inv_fun := of_linear_equiv, left_inv := λ f, by { ext, refl }, right_inv := λ f, by { ext, refl }, map_mul' := λ x y, by {ext, refl} } @[simp] lemma general_linear_equiv_to_linear_map (f : general_linear_group R M) : (general_linear_equiv R M f : M →ₗ[R] M) = f := by {ext, refl} end general_linear_group end linear_map namespace submodule variables [ring R] [add_comm_group M] [module R M] instance : is_modular_lattice (submodule R M) := ⟨λ x y z xz a ha, begin rw [mem_inf, mem_sup] at ha, rcases ha with ⟨⟨b, hb, c, hc, rfl⟩, haz⟩, rw mem_sup, refine ⟨b, hb, c, mem_inf.2 ⟨hc, _⟩, rfl⟩, rw [← add_sub_cancel c b, add_comm], apply z.sub_mem haz (xz hb), end⟩ end submodule
cf92efe8ea1624ae45b7d8c08eec2c9f0422bb3b
80cc5bf14c8ea85ff340d1d747a127dcadeb966f
/src/topology/sheaves/sheaf_condition/pairwise_intersections.lean
a4c461c710a2fc8c9eb52a2ed1a64584ce86d2cd
[ "Apache-2.0" ]
permissive
lacker/mathlib
f2439c743c4f8eb413ec589430c82d0f73b2d539
ddf7563ac69d42cfa4a1bfe41db1fed521bd795f
refs/heads/master
1,671,948,326,773
1,601,479,268,000
1,601,479,268,000
298,686,743
0
0
Apache-2.0
1,601,070,794,000
1,601,070,794,000
null
UTF-8
Lean
false
false
11,915
lean
import topology.sheaves.sheaf import category_theory.limits.preserves.basic import category_theory.category.pairwise /-! # Equivalent formulations of the sheaf condition We give an equivalent formulation of the sheaf condition. Given any indexed type `ι`, we define `overlap ι`, a category with objects corresponding to * individual open sets, `single i`, and * intersections of pairs of open sets, `pair i j`, with morphisms from `pair i j` to both `single i` and `single j`. Any open cover `U : ι → opens X` provides a functor `diagram U : overlap ι ⥤ (opens X)ᵒᵖ`. There is a canonical cone over this functor, `cone U`, whose cone point is `supr U`, and in fact this is a limit cone. A presheaf `F : presheaf C X` is a sheaf precisely if it preserves this limit. We express this in two equivalent ways, as * `is_limit (F.map_cone (cone U))`, or * `preserves_limit (diagram U) F` -/ noncomputable theory universes v u open topological_space open Top open category_theory open category_theory.limits namespace Top.presheaf variables {X : Top.{v}} variables {C : Type u} [category.{v} C] /-- An alternative formulation of the sheaf condition (which we prove equivalent to the usual one below as `sheaf_condition_equiv_sheaf_condition_pairwise_intersections`). A presheaf is a sheaf if `F` sends the cone `pairwise.cone U` to a limit cone. (Recall `pairwise.cone U`, has cone point `supr U`, mapping down to the `U i` and the `U i ⊓ U j`.) -/ @[derive subsingleton, nolint has_inhabited_instance] def sheaf_condition_pairwise_intersections (F : presheaf C X) : Type (max u (v+1)) := Π ⦃ι : Type v⦄ (U : ι → opens X), is_limit (F.map_cone (pairwise.cone U)) /-- An alternative formulation of the sheaf condition (which we prove equivalent to the usual one below as `sheaf_condition_equiv_sheaf_condition_preserves_limit_pairwise_intersections`). A presheaf is a sheaf if `F` preserves the limit of `pairwise.diagram U`. (Recall `pairwise.diagram U` is the diagram consisting of the pairwise intersections `U i ⊓ U j` mapping into the open sets `U i`. This diagram has limit `supr U`.) -/ @[derive subsingleton, nolint has_inhabited_instance] def sheaf_condition_preserves_limit_pairwise_intersections (F : presheaf C X) : Type (max u (v+1)) := Π ⦃ι : Type v⦄ (U : ι → opens X), preserves_limit (pairwise.diagram U) F /-! The remainder of this file shows that these conditions are equivalent to the usual sheaf condition. -/ variables [has_products C] namespace sheaf_condition_pairwise_intersections open category_theory.pairwise category_theory.pairwise.hom open sheaf_condition_equalizer_products /-- Implementation of `sheaf_condition_pairwise_intersections.cone_equiv`. -/ @[simps] def cone_equiv_functor_obj (F : presheaf C X) ⦃ι : Type v⦄ (U : ι → opens ↥X) (c : limits.cone (diagram U ⋙ F)) : limits.cone (sheaf_condition_equalizer_products.diagram F U) := { X := c.X, π := { app := λ Z, walking_parallel_pair.cases_on Z (pi.lift (λ (i : ι), c.π.app (single i))) (pi.lift (λ (b : ι × ι), c.π.app (pair b.1 b.2))), naturality' := λ Y Z f, begin cases Y; cases Z; cases f, { ext i, dsimp, simp only [limit.lift_π, category.id_comp, fan.mk_π_app, category_theory.functor.map_id, category.assoc], dsimp, simp only [limit.lift_π, category.id_comp, fan.mk_π_app], }, { ext ⟨i, j⟩, dsimp [sheaf_condition_equalizer_products.left_res], simp only [limit.lift_π, limit.lift_π_assoc, category.id_comp, fan.mk_π_app, category.assoc], have h := c.π.naturality (hom.left i j), dsimp at h, simpa using h, }, { ext ⟨i, j⟩, dsimp [sheaf_condition_equalizer_products.right_res], simp only [limit.lift_π, limit.lift_π_assoc, category.id_comp, fan.mk_π_app, category.assoc], have h := c.π.naturality (hom.right i j), dsimp at h, simpa using h, }, { ext i, dsimp, simp only [limit.lift_π, category.id_comp, fan.mk_π_app, category_theory.functor.map_id, category.assoc], dsimp, simp only [limit.lift_π, category.id_comp, fan.mk_π_app], }, end, }, } section local attribute [tidy] tactic.case_bash /-- Implementation of `sheaf_condition_pairwise_intersections.cone_equiv`. -/ @[simps] def cone_equiv_functor (F : presheaf C X) ⦃ι : Type v⦄ (U : ι → opens ↥X) : limits.cone (diagram U ⋙ F) ⥤ limits.cone (sheaf_condition_equalizer_products.diagram F U) := { obj := λ c, cone_equiv_functor_obj F U c, map := λ c c' f, { hom := f.hom, }, }. end /-- Implementation of `sheaf_condition_pairwise_intersections.cone_equiv`. -/ @[simps] def cone_equiv_inverse_obj (F : presheaf C X) ⦃ι : Type v⦄ (U : ι → opens ↥X) (c : limits.cone (sheaf_condition_equalizer_products.diagram F U)) : limits.cone (diagram U ⋙ F) := { X := c.X, π := { app := begin rintro (⟨i⟩|⟨i,j⟩), { exact c.π.app (walking_parallel_pair.zero) ≫ pi.π _ i, }, { exact c.π.app (walking_parallel_pair.one) ≫ pi.π _ (i, j), } end, naturality' := begin rintro (⟨i⟩|⟨⟩) (⟨⟩|⟨j,j⟩) ⟨⟩, { dsimp, erw [F.map_id], simp, }, { dsimp, simp only [category.id_comp, category.assoc], have h := c.π.naturality (walking_parallel_pair_hom.left), dsimp [sheaf_condition_equalizer_products.left_res] at h, simp only [category.id_comp] at h, have h' := h =≫ pi.π _ (i, j), rw h', simp, refl, }, { dsimp, simp only [category.id_comp, category.assoc], have h := c.π.naturality (walking_parallel_pair_hom.right), dsimp [sheaf_condition_equalizer_products.right_res] at h, simp only [category.id_comp] at h, have h' := h =≫ pi.π _ (j, i), rw h', simp, refl, }, { dsimp, erw [F.map_id], simp, }, end, }, } /-- Implementation of `sheaf_condition_pairwise_intersections.cone_equiv`. -/ @[simps] def cone_equiv_inverse (F : presheaf C X) ⦃ι : Type v⦄ (U : ι → opens ↥X) : limits.cone (sheaf_condition_equalizer_products.diagram F U) ⥤ limits.cone (diagram U ⋙ F) := { obj := λ c, cone_equiv_inverse_obj F U c, map := λ c c' f, { hom := f.hom, w' := begin rintro (⟨i⟩|⟨i,j⟩), { dsimp, rw [←(f.w walking_parallel_pair.zero), category.assoc], }, { dsimp, rw [←(f.w walking_parallel_pair.one), category.assoc], }, end }, }. section local attribute [tidy] tactic.case_bash /-- Implementation of `sheaf_condition_pairwise_intersections.cone_equiv`. -/ @[simps] def cone_equiv_unit_iso_app (F : presheaf C X) ⦃ι : Type v⦄ (U : ι → opens ↥X) (c : cone (diagram U ⋙ F)) : (𝟭 (cone (diagram U ⋙ F))).obj c ≅ (cone_equiv_functor F U ⋙ cone_equiv_inverse F U).obj c := { hom := { hom := 𝟙 _ }, inv := { hom := 𝟙 _ }} end /-- Implementation of `sheaf_condition_pairwise_intersections.cone_equiv`. -/ @[simps {rhs_md := semireducible}] def cone_equiv_unit_iso (F : presheaf C X) ⦃ι : Type v⦄ (U : ι → opens X) : 𝟭 (limits.cone (diagram U ⋙ F)) ≅ cone_equiv_functor F U ⋙ cone_equiv_inverse F U := nat_iso.of_components (cone_equiv_unit_iso_app F U) (by tidy) /-- Implementation of `sheaf_condition_pairwise_intersections.cone_equiv`. -/ @[simps {rhs_md := semireducible}] def cone_equiv_counit_iso (F : presheaf C X) ⦃ι : Type v⦄ (U : ι → opens X) : cone_equiv_inverse F U ⋙ cone_equiv_functor F U ≅ 𝟭 (limits.cone (sheaf_condition_equalizer_products.diagram F U)) := nat_iso.of_components (λ c, { hom := { hom := 𝟙 _, w' := begin rintro ⟨_|_⟩, { ext, dsimp, simp, }, { ext ⟨i,j⟩, dsimp, simp, }, end }, inv := { hom := 𝟙 _, w' := begin rintro ⟨_|_⟩, { ext, dsimp, simp, }, { ext ⟨i,j⟩, dsimp, simp, }, end, }}) (by tidy) /-- Cones over `diagram U ⋙ F` are the same as a cones over the usual sheaf condition equalizer diagram. -/ @[simps] def cone_equiv (F : presheaf C X) ⦃ι : Type v⦄ (U : ι → opens X) : limits.cone (diagram U ⋙ F) ≌ limits.cone (sheaf_condition_equalizer_products.diagram F U) := { functor := cone_equiv_functor F U, inverse := cone_equiv_inverse F U, unit_iso := cone_equiv_unit_iso F U, counit_iso := cone_equiv_counit_iso F U, } local attribute [reducible] sheaf_condition_equalizer_products.res sheaf_condition_equalizer_products.left_res /-- If `sheaf_condition_equalizer_products.fork` is an equalizer, then `F.map_cone (cone U)` is a limit cone. -/ def is_limit_map_cone_of_is_limit_sheaf_condition_fork (F : presheaf C X) ⦃ι : Type v⦄ (U : ι → opens X) (P : is_limit (sheaf_condition_equalizer_products.fork F U)) : is_limit (F.map_cone (cone U)) := is_limit.of_iso_limit ((is_limit.of_cone_equiv (cone_equiv F U).symm).symm P) { hom := { hom := 𝟙 _, w' := begin rintro ⟨⟩, { dsimp, simp, refl, }, { dsimp, simp only [limit.lift_π, limit.lift_π_assoc, category.id_comp, fan.mk_π_app, category.assoc], rw ←F.map_comp, refl, } end }, inv := { hom := 𝟙 _, w' := begin rintro ⟨⟩, { dsimp, simp, refl, }, { dsimp, simp only [limit.lift_π, limit.lift_π_assoc, category.id_comp, fan.mk_π_app, category.assoc], rw ←F.map_comp, refl, } end }, } /-- If `F.map_cone (cone U)` is a limit cone, then `sheaf_condition_equalizer_products.fork` is an equalizer. -/ def is_limit_sheaf_condition_fork_of_is_limit_map_cone (F : presheaf C X) ⦃ι : Type v⦄ (U : ι → opens X) (Q : is_limit (F.map_cone (cone U))) : is_limit (sheaf_condition_equalizer_products.fork F U) := is_limit.of_iso_limit ((is_limit.of_cone_equiv (cone_equiv F U)).symm Q) { hom := { hom := 𝟙 _, w' := begin rintro ⟨⟩, { dsimp, simp, refl, }, { dsimp, ext ⟨i, j⟩, simp only [limit.lift_π, limit.lift_π_assoc, category.id_comp, fan.mk_π_app, category.assoc], rw ←F.map_comp, refl, } end }, inv := { hom := 𝟙 _, w' := begin rintro ⟨⟩, { dsimp, simp, refl, }, { dsimp, ext ⟨i, j⟩, simp only [limit.lift_π, limit.lift_π_assoc, category.id_comp, fan.mk_π_app, category.assoc], rw ←F.map_comp, refl, } end }, } end sheaf_condition_pairwise_intersections open sheaf_condition_pairwise_intersections /-- The sheaf condition in terms of an equalizer diagram is equivalent to the reformulation in terms of a limit diagram over `U i` and `U i ⊓ U j`. -/ def sheaf_condition_equiv_sheaf_condition_pairwise_intersections (F : presheaf C X) : F.sheaf_condition ≃ F.sheaf_condition_pairwise_intersections := equiv.Pi_congr_right (λ i, equiv.Pi_congr_right (λ U, equiv_of_subsingleton_of_subsingleton (is_limit_map_cone_of_is_limit_sheaf_condition_fork F U) (is_limit_sheaf_condition_fork_of_is_limit_map_cone F U))) /-- The sheaf condition in terms of an equalizer diagram is equivalent to the reformulation in terms of the presheaf preserving the limit of the diagram consisting of the `U i` and `U i ⊓ U j`. -/ def sheaf_condition_equiv_sheaf_condition_preserves_limit_pairwise_intersections (F : presheaf C X) : F.sheaf_condition ≃ F.sheaf_condition_preserves_limit_pairwise_intersections := equiv.trans (sheaf_condition_equiv_sheaf_condition_pairwise_intersections F) (equiv.Pi_congr_right (λ i, equiv.Pi_congr_right (λ U, equiv_of_subsingleton_of_subsingleton (λ P, preserves_limit_of_preserves_limit_cone (pairwise.cone_is_limit U) P) (by { introI, exact preserves_limit.preserves (pairwise.cone_is_limit U) })))) end Top.presheaf
d0ff8501f89faf7d58e2ef0db0ecc59bd722eee7
d436468d80b739ba7e06843c4d0d2070e43448e5
/test/omega.lean
d320448c0dc48d508fc68b46430e6a9cbf3dc80b
[ "Apache-2.0" ]
permissive
roro47/mathlib
761fdc002aef92f77818f3fef06bf6ec6fc1a28e
80aa7d52537571a2ca62a3fdf71c9533a09422cf
refs/heads/master
1,599,656,410,625
1,573,649,488,000
1,573,649,488,000
221,452,951
0
0
Apache-2.0
1,573,647,693,000
1,573,647,692,000
null
UTF-8
Lean
false
false
2,819
lean
/- Test cases for omega. Most of the examples are from John Harrison's Handbook of Practical Logic and Automated Reasoning. -/ import tactic.omega example (n : ℤ) : n - 1 ≠ n := by omega example (x : int) : (x = 5 ∨ x = 7) → 2 < x := by omega example (x : int) : x ≤ -x → x ≤ 0 := by omega example : ∀ x y : int, (x ≤ 5 ∧ y ≤ 3) → x + y ≤ 8 := by omega example : ∀ (x y z : int), x < y → y < z → x < z := by omega example (x y z : int) : x - y ≤ x - z → z ≤ y:= by omega example (x : int) (h1 : x = -5 ∨ x = 7) (h2 : x = 0) : false := by omega example : ∀ x : int, 31 * x > 0 → x > 0 := by omega example (x y : int) : (-x - y < x - y) → (x - y < x + y) → (x > 0 ∧ y > 0) := by omega example : ∀ (x : int), (x ≥ -1 ∧ x ≤ 1) → (x = -1 ∨ x = 0 ∨ x = 1) := by omega example : ∀ (x : int), 5 * x = 5 → x = 1 := by omega example (x y : int) : ∀ z w v : int, x = y → y = z → x = z := by omega example : ∀ x : int, x < 349 ∨ x > 123 := by omega example : ∀ x y : int, x ≤ 3 * y → 3 * x ≤ 9 * y := by omega example (x : int) (h1 : x < 43 ∧ x > 513) : false := by omega example (x y z w : int) : x ≤ y → y ≤ z → z ≤ w → x ≤ w:= by omega example (x y z : int) : ∀ w v : int, 100 = x → x = y → y = z → z = w → w = v → v = 100 := by omega example (x : nat) : 31 * x > 0 → x > 0 := by omega example (x y : nat) : (x ≤ 5 ∧ y ≤ 3) → x + y ≤ 8 := by omega example : ∀ (x y z y : nat), ¬(2 * x + 1 = 2 * y) := by omega example : ∀ (x y : nat), x > 0 → x + y > 0 := by omega example : ∀ (x : nat), x < 349 ∨ x > 123 := by omega example : ∀ (x y : nat), (x = 2 ∨ x = 10) → (x = 3 * y) → false := by omega example (x y : nat) : x ≤ 3 * y → 3 * x ≤ 9 * y := by omega example (x y z : nat) : (x ≤ y) → (z > y) → (x - z = 0) := by omega example (x y z : nat) : x - 5 > 122 → y ≤ 127 → y < x := by omega example : ∀ (x y : nat), x ≤ y ↔ x - y = 0 := by omega example (k : nat) (h : 1 * 1 + 1 * 1 + 1 = 1 * 1 * k) : k = 3 := by omega example (a b : ℕ) (h : a < b + 1) (ha : a.prime) : a ≤ b := by omega example (a b c : ℕ) (h : a < b + 1) (ha : c.prime) : a ≤ b := by omega example (a b : ℕ) (h : a < b + 1) (p : fin a) : a ≤ b := by omega example : 3 < 4 := by omega /- Use `omega manual` to disable automatic reverts, and `omega int` or `omega nat` to specify the domain. -/ example (i : int) (n : nat) (h1 : n = 0) (h2 : i < i) : false := by omega int example (i : int) (n : nat) (h1 : i = 0) (h2 : n < n) : false := by omega nat example (x y z w : int) (h1 : 3 * y ≥ x) (h2 : z > 19 * w) : 3 * x ≤ 9 * y := by {revert h1 x y, omega manual} example (n : nat) (h1 : n < 34) (i : int) (h2 : i * 9 = -72) : i = -8 := by {revert h2 i, omega manual int}
cb6e9f70bad25bf1a6ad6bc03f9497e33bdefbce
26bff4ed296b8373c92b6b025f5d60cdf02104b9
/tests/lean/run/tactic_op_overload_bug.lean
2a2e1530721460283aade9566cc16107cc76506f
[ "Apache-2.0" ]
permissive
guiquanz/lean
b8a878ea24f237b84b0e6f6be2f300e8bf028229
242f8ba0486860e53e257c443e965a82ee342db3
refs/heads/master
1,526,680,092,098
1,427,492,833,000
1,427,493,281,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
526
lean
import data.num data.bool open bool well_founded namespace pos_num definition lt_pred (a b : pos_num) : Prop := lt a b = tt definition not_lt_one1 (a : pos_num) : ¬ lt_pred a one := begin esimp {lt_pred}, intro H, apply (absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff a) H) end open tactic well_founded print raw intro -- intro is overloaded definition not_lt_one2 (a : pos_num) : ¬ lt_pred a one := begin esimp {lt_pred}, intro H, apply (absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff a) H) end end pos_num
9a6e13ac5e5cfcfc990833b516f5ed7b2f17eb81
d642a6b1261b2cbe691e53561ac777b924751b63
/src/algebra/commute.lean
569d98ff90c375c8bcab06e3f8f2f2aee36d92fd
[ "Apache-2.0" ]
permissive
cipher1024/mathlib
fee56b9954e969721715e45fea8bcb95f9dc03fe
d077887141000fefa5a264e30fa57520e9f03522
refs/heads/master
1,651,806,490,504
1,573,508,694,000
1,573,508,694,000
107,216,176
0
0
Apache-2.0
1,647,363,136,000
1,508,213,014,000
Lean
UTF-8
Lean
false
false
13,175
lean
/- Copyright (c) 2019 Neil Strickland. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Neil Strickland, Yury Kudryashov -/ import algebra.semiconj group_theory.submonoid group_theory.subgroup ring_theory.subring /-! # Commuting pairs of elements in monoids ## Main definitions * `commute a b` : `a * b = b * a` * `centralizer a` : `{ x | commute a x }` * `set.centralizer s` : elements that commute with all `a ∈ s` We prove that `centralizer` and `set_centralilzer` are submonoid/subgroups/subrings depending on the available structures, and provide operations on `commute _ _`. E.g., if `a`, `b`, and c are elements of a semiring, and that `hb : commute a b` and `hc : commute a c`. Then `hb.pow_left 5` proves `commute (a ^ 5) b` and `(hb.pow_right 2).add_right (hb.mul_right hc)` proves `commute a (b ^ 2 + b * c)`. Lean does not immediately recognise these terms as equations, so for rewriting we need syntax like `rw [(hb.pow_left 5).eq]` rather than just `rw [hb.pow_left 5]`. ## Implementation details Most of the proofs come from the properties of `semiconj_by`. -/ /-- Two elements commute, if `a * b = b * a`. -/ def commute {S : Type*} [has_mul S] (a b : S) : Prop := semiconj_by a b b open_locale smul namespace commute section has_mul variables {S : Type*} [has_mul S] /-- Equality behind `commute a b`; useful for rewriting. -/ protected theorem eq {a b : S} (h : commute a b) : a * b = b * a := h /-- Any element commutes with itself. -/ @[refl, simp] protected theorem refl (a : S) : commute a a := eq.refl (a * a) /-- If `a` commutes with `b`, then `b` commutes with `a`. -/ @[symm] protected theorem symm {a b : S} (h : commute a b) : commute b a := eq.symm h protected theorem symm_iff {a b : S} : commute a b ↔ commute b a := ⟨commute.symm, commute.symm⟩ end has_mul section semigroup variables {S : Type*} [semigroup S] {a b c : S} /-- If `a` commutes with both `b` and `c`, then it commutes with their product. -/ @[simp] theorem mul_right (hab : commute a b) (hac : commute a c) : commute a (b * c) := hab.mul_right hac /-- If both `a` and `b` commute with `c`, then their product commutes with `c`. -/ @[simp] theorem mul_left (hac : commute a c) (hbc : commute b c) : commute (a * b) c := hac.mul_left hbc end semigroup protected theorem all {S : Type*} [comm_semigroup S] (a b : S) : commute a b := mul_comm a b section monoid variables {M : Type*} [monoid M] @[simp] theorem one_right (a : M) : commute a 1 := semiconj_by.one_right a @[simp] theorem one_left (a : M) : commute 1 a := semiconj_by.one_left a @[simp] theorem units_inv_right {a : M} {u : units M} : commute a u → commute a ↑u⁻¹ := semiconj_by.units_inv_right @[simp] theorem units_inv_right_iff {a : M} {u : units M} : commute a ↑u⁻¹ ↔ commute a u := semiconj_by.units_inv_right_iff @[simp] theorem units_inv_left {u : units M} {a : M} : commute ↑u a → commute ↑u⁻¹ a := semiconj_by.units_inv_symm_left @[simp] theorem units_inv_left_iff {u : units M} {a : M}: commute ↑u⁻¹ a ↔ commute ↑u a := semiconj_by.units_inv_symm_left_iff @[simp] protected theorem map {N : Type*} [monoid N] (f : M →* N) {a b : M} : commute a b → commute (f a) (f b) := semiconj_by.map f variables {a b : M} (hab : commute a b) (m n : ℕ) @[simp] theorem pow_right : commute a (b ^ n) := hab.pow_right n @[simp] theorem pow_left : commute (a ^ n) b := (hab.symm.pow_right n).symm @[simp] theorem pow_pow : commute (a ^ m) (b ^ n) := (hab.pow_left m).pow_right n variable (a) @[simp] theorem self_pow : commute a (a ^ n) := (commute.refl a).pow_right n @[simp] theorem pow_self : commute (a ^ n) a := (commute.refl a).pow_left n @[simp] theorem pow_pow_self : commute (a ^ n) (a ^ m) := (commute.refl a).pow_pow n m variables {u₁ u₂ : units M} theorem units_coe : commute u₁ u₂ → commute (u₁ : M) u₂ := semiconj_by.units_coe theorem units_of_coe : commute (u₁ : M) u₂ → commute u₁ u₂ := semiconj_by.units_of_coe @[simp] theorem units_coe_iff : commute (u₁ : M) u₂ ↔ commute u₁ u₂ := semiconj_by.units_coe_iff end monoid section group variables {G : Type*} [group G] {a b : G} @[simp] theorem inv_right : commute a b → commute a b⁻¹ := semiconj_by.inv_right @[simp] theorem inv_right_iff : commute a b⁻¹ ↔ commute a b := semiconj_by.inv_right_iff @[simp] theorem inv_left : commute a b → commute a⁻¹ b := semiconj_by.inv_symm_left @[simp] theorem inv_left_iff : commute a⁻¹ b ↔ commute a b := semiconj_by.inv_symm_left_iff theorem inv_inv : commute a b → commute a⁻¹ b⁻¹ := semiconj_by.inv_inv_symm @[simp] theorem inv_inv_iff : commute a⁻¹ b⁻¹ ↔ commute a b := semiconj_by.inv_inv_symm_iff section variables (hab : commute a b) (m n : ℤ) include hab @[simp] theorem gpow_right : commute a (b ^ m) := hab.gpow_right m @[simp] theorem gpow_left : commute (a ^ m) b := (hab.symm.gpow_right m).symm @[simp] theorem gpow_gpow : commute (a ^ m) (b ^ n) := (hab.gpow_right n).gpow_left m end variables (a) (m n : ℤ) @[simp] theorem self_gpow : commute a (a ^ n) := (commute.refl a).gpow_right n @[simp] theorem gpow_self : commute (a ^ n) a := (commute.refl a).gpow_left n @[simp] theorem gpow_gpow_self : commute (a ^ m) (a ^ n) := (commute.refl a).gpow_gpow m n end group section semiring variables {A : Type*} @[simp] theorem zero_right [mul_zero_class A] (a : A) : commute a 0 := semiconj_by.zero_right a @[simp] theorem zero_left [mul_zero_class A] (a : A) : commute 0 a := semiconj_by.zero_left a a @[simp] theorem add_right [distrib A] {a b c : A} : commute a b → commute a c → commute a (b + c) := semiconj_by.add_right @[simp] theorem add_left [distrib A] {a b c : A} : commute a c → commute b c → commute (a + b) c := semiconj_by.add_left variables [semiring A] {a b : A} (hab : commute a b) (m n : ℕ) @[simp] theorem smul_right : commute a (n •ℕ b) := hab.smul_right n @[simp] theorem smul_left : commute (n •ℕ a) b := hab.smul_left n @[simp] theorem smul_smul : commute (m •ℕ a) (n •ℕ b) := hab.smul_smul m n variable (a) @[simp] theorem self_smul : commute a (n •ℕ a) := (commute.refl a).smul_right n @[simp] theorem smul_self : commute (n •ℕ a) a := (commute.refl a).smul_left n @[simp] theorem self_smul_smul : commute (m •ℕ a) (n •ℕ a) := (commute.refl a).smul_smul m n @[simp] theorem cast_nat_right : commute a (n : A) := semiconj_by.cast_nat_right a n @[simp] theorem cast_nat_left : commute (n : A) a := semiconj_by.cast_nat_left n a end semiring section ring variables {R : Type*} [ring R] {a b c : R} @[simp] theorem neg_right : commute a b → commute a (- b) := semiconj_by.neg_right @[simp] theorem neg_right_iff : commute a (-b) ↔ commute a b := semiconj_by.neg_right_iff @[simp] theorem neg_left : commute a b → commute (- a) b := semiconj_by.neg_left @[simp] theorem neg_left_iff : commute (-a) b ↔ commute a b := semiconj_by.neg_left_iff @[simp] theorem neg_one_right (a : R) : commute a (-1) := semiconj_by.neg_one_right a @[simp] theorem neg_one_left (a : R): commute (-1) a := semiconj_by.neg_one_left a @[simp] theorem sub_right : commute a b → commute a c → commute a (b - c) := semiconj_by.sub_right @[simp] theorem sub_left : commute a c → commute b c → commute (a - b) c := semiconj_by.sub_left variables (hab : commute a b) (m n : ℤ) @[simp] theorem gsmul_right : commute a (m •ℤ b) := hab.gsmul_right m @[simp] theorem gsmul_left : commute (m •ℤ a) b := hab.gsmul_left m @[simp] theorem gsmul_gsmul : commute (m •ℤ a) (n •ℤ b) := hab.gsmul_gsmul m n @[simp] theorem self_gsmul : commute a (n •ℤ a) := (commute.refl a).gsmul_right n @[simp] theorem gsmul_self : commute (n •ℤ a) a := (commute.refl a).gsmul_left n @[simp] theorem self_gsmul_gsmul : commute (m •ℤ a) (n •ℤ a) := (commute.refl a).gsmul_gsmul m n variable (a) @[simp] theorem cast_int_right : commute a (n : R) := by rw [← gsmul_one n]; exact (commute.one_right a).gsmul_right n @[simp] theorem cast_int_left : commute (n : R) a := (commute.cast_int_right a n).symm end ring end commute -- Definitions and trivial theorems about them section centralizer variables {S : Type*} [has_mul S] /-- Centralizer of an element `a : S` is the set of elements that commute with `a`. -/ def centralizer (a : S) : set S := { x | commute a x } @[simp] theorem mem_centralizer {a b : S} : b ∈ centralizer a ↔ commute a b := iff.rfl /-- Centralizer of a set `T` is the set of elements that commute with all `a ∈ T`. -/ protected def set.centralizer (s : set S) : set S := { x | ∀ a ∈ s, commute a x } @[simp] protected theorem set.mem_centralizer (s : set S) {x : S} : x ∈ s.centralizer ↔ ∀ a ∈ s, commute a x := iff.rfl protected theorem set.mem_centralizer_iff_subset (s : set S) {x : S} : x ∈ s.centralizer ↔ s ⊆ centralizer x := by simp only [set.mem_centralizer, mem_centralizer, set.subset_def, commute.symm_iff] protected theorem set.centralizer_eq (s : set S) : s.centralizer = ⋂ a ∈ s, centralizer a := set.ext $ assume x, by simp only [s.mem_centralizer, set.mem_bInter_iff, mem_centralizer] protected theorem set.centralizer_decreasing {s t : set S} (h : s ⊆ t) : t.centralizer ⊆ s.centralizer := s.centralizer_eq.symm ▸ t.centralizer_eq.symm ▸ set.bInter_subset_bInter_left h end centralizer section monoid variables {M : Type*} [monoid M] (a : M) (s : set M) instance centralizer.is_submonoid : is_submonoid (centralizer a) := { one_mem := commute.one_right a, mul_mem := λ _ _, commute.mul_right } instance set.centralizer.is_submonoid : is_submonoid s.centralizer := by rw s.centralizer_eq; apply_instance @[simp] theorem monoid.centralizer_closure : (monoid.closure s).centralizer = s.centralizer := set.subset.antisymm (set.centralizer_decreasing monoid.subset_closure) (λ x, by simp only [set.mem_centralizer_iff_subset]; exact monoid.closure_subset) -- Not sure if this should be an instance lemma centralizer.inter_units_is_subgroup : is_subgroup { x : units M | commute a x } := { one_mem := commute.one_right a, mul_mem := λ _ _, commute.mul_right, inv_mem := λ _, commute.units_inv_right } theorem commute.list_prod_right {a : M} {l : list M} (h : ∀ x ∈ l, commute a x) : commute a l.prod := is_submonoid.list_prod_mem (λ x hx, mem_centralizer.2 (h x hx)) theorem commute.list_prod_left {l : list M} {a : M} (h : ∀ x ∈ l, commute x a) : commute l.prod a := (commute.list_prod_right (λ x hx, (h x hx).symm)).symm end monoid section group variables {G : Type*} [group G] (a : G) (s : set G) instance centralizer.is_subgroup : is_subgroup (centralizer a) := { inv_mem := λ _, commute.inv_right } instance set.centralizer.is_subgroup : is_subgroup s.centralizer := by rw s.centralizer_eq; apply_instance @[simp] lemma group.centralizer_closure : (group.closure s).centralizer = s.centralizer := set.subset.antisymm (set.centralizer_decreasing group.subset_closure) (λ x, by simp only [set.mem_centralizer_iff_subset]; exact group.closure_subset) end group /- There is no `is_subsemiring` in mathlib, so we only prove `is_add_submonoid` here. -/ section semiring variables {A : Type*} [semiring A] (a : A) (s : set A) instance centralizer.is_add_submonoid : is_add_submonoid (centralizer a) := { zero_mem := commute.zero_right a, add_mem := λ _ _, commute.add_right } instance set.centralizer.is_add_submonoid : is_add_submonoid s.centralizer := by rw s.centralizer_eq; apply_instance @[simp] lemma add_monoid.centralizer_closure : (add_monoid.closure s).centralizer = s.centralizer := set.subset.antisymm (set.centralizer_decreasing add_monoid.subset_closure) (λ x, by simp only [set.mem_centralizer_iff_subset]; exact add_monoid.closure_subset) end semiring section ring variables {R : Type*} [ring R] (a : R) (s : set R) instance centralizer.is_subring : is_subring (centralizer a) := { neg_mem := λ _, commute.neg_right } instance set.centralizer.is_subring : is_subring s.centralizer := by rw s.centralizer_eq; apply_instance @[simp] lemma ring.centralizer_closure : (ring.closure s).centralizer = s.centralizer := set.subset.antisymm (set.centralizer_decreasing ring.subset_closure) (λ x, by simp only [set.mem_centralizer_iff_subset]; exact ring.closure_subset) end ring namespace commute protected theorem mul_pow {M : Type*} [monoid M] {a b : M} (hab : commute a b) : ∀ (n : ℕ), (a * b) ^ n = a ^ n * b ^ n | 0 := by simp only [pow_zero, mul_one] | (n + 1) := by simp only [pow_succ, mul_pow n]; assoc_rw [(hab.symm.pow_right n).eq]; rw [mul_assoc] protected theorem mul_gpow {G : Type*} [group G] {a b : G} (hab : commute a b) : ∀ (n : ℤ), (a * b) ^ n = a ^ n * b ^ n | (n : ℕ) := hab.mul_pow n | -[1+n] := by { simp only [gpow_neg_succ, hab.mul_pow, mul_inv_rev], exact (hab.pow_pow n.succ n.succ).inv_inv.symm.eq } end commute theorem neg_pow {R : Type*} [ring R] (a : R) (n : ℕ) : (- a) ^ n = (-1) ^ n * a ^ n := (neg_one_mul a) ▸ (commute.neg_one_left a).mul_pow n
5e85b56db360ebd94e8895196c6980369348f5da
02005f45e00c7ecf2c8ca5db60251bd1e9c860b5
/src/linear_algebra/tensor_algebra.lean
e23e5b44b6897c9585c57ae2bb0702b6ef79c395
[ "Apache-2.0" ]
permissive
anthony2698/mathlib
03cd69fe5c280b0916f6df2d07c614c8e1efe890
407615e05814e98b24b2ff322b14e8e3eb5e5d67
refs/heads/master
1,678,792,774,873
1,614,371,563,000
1,614,371,563,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
6,040
lean
/- Copyright (c) 2020 Adam Topaz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Adam Topaz. -/ import algebra.free_algebra import algebra.ring_quot import algebra.triv_sq_zero_ext /-! # Tensor Algebras Given a commutative semiring `R`, and an `R`-module `M`, we construct the tensor algebra of `M`. This is the free `R`-algebra generated (`R`-linearly) by the module `M`. ## Notation 1. `tensor_algebra R M` is the tensor algebra itself. It is endowed with an R-algebra structure. 2. `tensor_algebra.ι R` is the canonical R-linear map `M → tensor_algebra R M`. 3. Given a linear map `f : M → A` to an R-algebra `A`, `lift R f` is the lift of `f` to an `R`-algebra morphism `tensor_algebra R M → A`. ## Theorems 1. `ι_comp_lift` states that the composition `(lift R f) ∘ (ι R)` is identical to `f`. 2. `lift_unique` states that whenever an R-algebra morphism `g : tensor_algebra R M → A` is given whose composition with `ι R` is `f`, then one has `g = lift R f`. 3. `hom_ext` is a variant of `lift_unique` in the form of an extensionality theorem. 4. `lift_comp_ι` is a combination of `ι_comp_lift` and `lift_unique`. It states that the lift of the composition of an algebra morphism with `ι` is the algebra morphism itself. ## Implementation details As noted above, the tensor algebra of `M` is constructed as the free `R`-algebra generated by `M`, modulo the additional relations making the inclusion of `M` into an `R`-linear map. -/ variables (R : Type*) [comm_semiring R] variables (M : Type*) [add_comm_monoid M] [semimodule R M] namespace tensor_algebra /-- An inductively defined relation on `pre R M` used to force the initial algebra structure on the associated quotient. -/ inductive rel : free_algebra R M → free_algebra R M → Prop -- force `ι` to be linear | add {a b : M} : rel (free_algebra.ι R (a+b)) (free_algebra.ι R a + free_algebra.ι R b) | smul {r : R} {a : M} : rel (free_algebra.ι R (r • a)) (algebra_map R (free_algebra R M) r * free_algebra.ι R a) end tensor_algebra /-- The tensor algebra of the module `M` over the commutative semiring `R`. -/ @[derive [inhabited, semiring, algebra R]] def tensor_algebra := ring_quot (tensor_algebra.rel R M) namespace tensor_algebra instance {S : Type*} [comm_ring S] [semimodule S M] : ring (tensor_algebra S M) := ring_quot.ring (rel S M) variables {M} /-- The canonical linear map `M →ₗ[R] tensor_algebra R M`. -/ def ι : M →ₗ[R] (tensor_algebra R M) := { to_fun := λ m, (ring_quot.mk_alg_hom R _ (free_algebra.ι R m)), map_add' := λ x y, by { rw [←alg_hom.map_add], exact ring_quot.mk_alg_hom_rel R rel.add, }, map_smul' := λ r x, by { rw [←alg_hom.map_smul], exact ring_quot.mk_alg_hom_rel R rel.smul, } } lemma ring_quot_mk_alg_hom_free_algebra_ι_eq_ι (m : M) : ring_quot.mk_alg_hom R (rel R M) (free_algebra.ι R m) = ι R m := rfl /-- Given a linear map `f : M → A` where `A` is an `R`-algebra, `lift R f` is the unique lift of `f` to a morphism of `R`-algebras `tensor_algebra R M → A`. -/ @[simps symm_apply] def lift {A : Type*} [semiring A] [algebra R A] : (M →ₗ[R] A) ≃ (tensor_algebra R M →ₐ[R] A) := { to_fun := ring_quot.lift_alg_hom R ∘ λ f, ⟨free_algebra.lift R ⇑f, λ x y (h : rel R M x y), by induction h; simp [algebra.smul_def]⟩, inv_fun := λ F, F.to_linear_map.comp (ι R), left_inv := λ f, by { ext, simp [ι], }, right_inv := λ F, by { ext, simp [ι], } } variables {R} @[simp] theorem ι_comp_lift {A : Type*} [semiring A] [algebra R A] (f : M →ₗ[R] A) : (lift R f).to_linear_map.comp (ι R) = f := (lift R).symm_apply_apply f @[simp] theorem lift_ι_apply {A : Type*} [semiring A] [algebra R A] (f : M →ₗ[R] A) (x) : lift R f (ι R x) = f x := by { dsimp [lift, ι], refl, } @[simp] theorem lift_unique {A : Type*} [semiring A] [algebra R A] (f : M →ₗ[R] A) (g : tensor_algebra R M →ₐ[R] A) : g.to_linear_map.comp (ι R) = f ↔ g = lift R f := (lift R).symm_apply_eq -- Marking `tensor_algebra` irreducible makes `ring` instances inaccessible on quotients. -- https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/algebra.2Esemiring_to_ring.20breaks.20semimodule.20typeclass.20lookup/near/212580241 -- For now, we avoid this by not marking it irreducible. attribute [irreducible] ι lift @[simp] theorem lift_comp_ι {A : Type*} [semiring A] [algebra R A] (g : tensor_algebra R M →ₐ[R] A) : lift R (g.to_linear_map.comp (ι R)) = g := by { rw ←lift_symm_apply, exact (lift R).apply_symm_apply g } /-- See note [partially-applied ext lemmas]. -/ @[ext] theorem hom_ext {A : Type*} [semiring A] [algebra R A] {f g : tensor_algebra R M →ₐ[R] A} (w : f.to_linear_map.comp (ι R) = g.to_linear_map.comp (ι R)) : f = g := begin rw [←lift_symm_apply, ←lift_symm_apply] at w, exact (lift R).symm.injective w, end /-- The left-inverse of `algebra_map`. -/ def algebra_map_inv : tensor_algebra R M →ₐ[R] R := lift R (0 : M →ₗ[R] R) lemma algebra_map_left_inverse : function.left_inverse algebra_map_inv (algebra_map R $ tensor_algebra R M) := λ x, by simp [algebra_map_inv] /-- The left-inverse of `ι`. As an implementation detail, we implement this using `triv_sq_zero_ext` which has a suitable algebra structure. -/ def ι_inv : tensor_algebra R M →ₗ[R] M := (triv_sq_zero_ext.snd_hom R M).comp (lift R (triv_sq_zero_ext.inr_hom R M)).to_linear_map lemma ι_left_inverse : function.left_inverse ι_inv (ι R : M → tensor_algebra R M) := λ x, by simp [ι_inv] end tensor_algebra namespace free_algebra variables {R M} /-- The canonical image of the `free_algebra` in the `tensor_algebra`, which maps `free_algebra.ι R x` to `tensor_algebra.ι R x`. -/ def to_tensor : free_algebra R M →ₐ[R] tensor_algebra R M := free_algebra.lift R (tensor_algebra.ι R) @[simp] lemma to_tensor_ι (m : M) : (free_algebra.ι R m).to_tensor = tensor_algebra.ι R m := by simp [to_tensor] end free_algebra
a8d68b69047fed025587fb0b17330423b9c1e89b
9be442d9ec2fcf442516ed6e9e1660aa9071b7bd
/tests/lean/run/macroParams.lean
a93296807bfd605d3d5c31d4cfdb98af80dadcca
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach" ]
permissive
EdAyers/lean4
57ac632d6b0789cb91fab2170e8c9e40441221bd
37ba0df5841bde51dbc2329da81ac23d4f6a4de4
refs/heads/master
1,676,463,245,298
1,660,619,433,000
1,660,619,433,000
183,433,437
1
0
Apache-2.0
1,657,612,672,000
1,556,196,574,000
Lean
UTF-8
Lean
false
false
147
lean
macro x:ident noWs "(" ys:term,* ")" : term => `($x $ys*) #check id(1) macro "foo" &"only" : tactic => `(trivial) example : True := by foo only
84f18b43b8ee765bd1912d12ccefd3ff851425b2
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/order/ideal_auto.lean
9540c2688cc6cc73af4bd3653f51f90b4429a28d
[]
no_license
AurelienSaue/Mathlib4_auto
f538cfd0980f65a6361eadea39e6fc639e9dae14
590df64109b08190abe22358fabc3eae000943f2
refs/heads/master
1,683,906,849,776
1,622,564,669,000
1,622,564,669,000
371,723,747
0
0
null
null
null
null
UTF-8
Lean
false
false
7,827
lean
/- Copyright (c) 2020 David Wärn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Wärn -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.order.basic import Mathlib.data.equiv.encodable.basic import Mathlib.PostPort universes u_2 l u_1 namespace Mathlib /-! # Order ideals, cofinal sets, and the Rasiowa–Sikorski lemma ## Main definitions Throughout this file, `P` is at least a preorder, but some sections require more structure, such as a bottom element, a top element, or a join-semilattice structure. - `ideal P`: the type of upward directed, downward closed subsets of `P`. Dual to the notion of a filter on a preorder. - `cofinal P`: the type of subsets of `P` containing arbitrarily large elements. Dual to the notion of 'dense set' used in forcing. - `ideal_of_cofinals p 𝒟`, where `p : P`, and `𝒟` is a countable family of cofinal subsets of P: an ideal in `P` which contains `p` and intersects every set in `𝒟`. ## References - https://en.wikipedia.org/wiki/Ideal_(order_theory) - https://en.wikipedia.org/wiki/Cofinal_(mathematics) - https://en.wikipedia.org/wiki/Rasiowa–Sikorski_lemma Note that for the Rasiowa–Sikorski lemma, Wikipedia uses the opposite ordering on `P`, in line with most presentations of forcing. ## Tags ideal, cofinal, dense, countable, generic -/ namespace order /-- An ideal on a preorder `P` is a subset of `P` that is - nonempty - upward directed - downward closed. -/ structure ideal (P : Type u_2) [preorder P] where carrier : set P nonempty : set.nonempty carrier directed : directed_on LessEq carrier mem_of_le : ∀ {x y : P}, x ≤ y → y ∈ carrier → x ∈ carrier namespace ideal /-- The smallest ideal containing a given element. -/ def principal {P : Type u_1} [preorder P] (p : P) : ideal P := mk (set_of fun (x : P) => x ≤ p) sorry sorry sorry protected instance inhabited {P : Type u_1} [preorder P] [Inhabited P] : Inhabited (ideal P) := { default := principal Inhabited.default } /-- An ideal of `P` can be viewed as a subset of `P`. -/ protected instance set.has_coe {P : Type u_1} [preorder P] : has_coe (ideal P) (set P) := has_coe.mk carrier /-- For the notation `x ∈ I`. -/ protected instance has_mem {P : Type u_1} [preorder P] : has_mem P (ideal P) := has_mem.mk fun (x : P) (I : ideal P) => x ∈ ↑I /-- Two ideals are equal when their underlying sets are equal. -/ theorem ext {P : Type u_1} [preorder P] (I : ideal P) (J : ideal P) : ↑I = ↑J → I = J := sorry /-- The partial ordering by subset inclusion, inherited from `set P`. -/ protected instance partial_order {P : Type u_1} [preorder P] : partial_order (ideal P) := partial_order.lift coe ext theorem mem_of_mem_of_le {P : Type u_1} [preorder P] {x : P} {I : ideal P} {J : ideal P} : x ∈ I → I ≤ J → x ∈ J := set.mem_of_mem_of_subset @[simp] theorem principal_le_iff {P : Type u_1} [preorder P] {x : P} {I : ideal P} : principal x ≤ I ↔ x ∈ I := { mp := fun (h : ∀ {y : P}, y ≤ x → y ∈ I) => h (le_refl x), mpr := fun (h_mem : x ∈ I) (y : P) (h_le : y ≤ x) => mem_of_le I h_le h_mem } /-- A specific witness of `I.nonempty` when `P` has a bottom element. -/ @[simp] theorem bot_mem {P : Type u_1} [order_bot P] {I : ideal P} : ⊥ ∈ I := mem_of_le I bot_le (set.nonempty.some_mem (nonempty I)) /-- There is a bottom ideal when `P` has a bottom element. -/ protected instance order_bot {P : Type u_1} [order_bot P] : order_bot (ideal P) := order_bot.mk (principal ⊥) partial_order.le partial_order.lt sorry sorry sorry sorry /-- There is a top ideal when `P` has a top element. -/ protected instance order_top {P : Type u_1} [order_top P] : order_top (ideal P) := order_top.mk (principal ⊤) partial_order.le partial_order.lt sorry sorry sorry sorry /-- A specific witness of `I.directed` when `P` has joins. -/ theorem sup_mem {P : Type u_1} [semilattice_sup P] {I : ideal P} (x : P) (y : P) (H : x ∈ I) : y ∈ I → x ⊔ y ∈ I := sorry @[simp] theorem sup_mem_iff {P : Type u_1} [semilattice_sup P] {x : P} {y : P} {I : ideal P} : x ⊔ y ∈ I ↔ x ∈ I ∧ y ∈ I := { mp := fun (h : x ⊔ y ∈ I) => { left := mem_of_le I le_sup_left h, right := mem_of_le I le_sup_right h }, mpr := fun (h : x ∈ I ∧ y ∈ I) => sup_mem x y (and.left h) (and.right h) } end ideal /-- For a preorder `P`, `cofinal P` is the type of subsets of `P` containing arbitrarily large elements. They are the dense sets in the topology whose open sets are terminal segments. -/ structure cofinal (P : Type u_2) [preorder P] where carrier : set P mem_gt : ∀ (x : P), ∃ (y : P), ∃ (H : y ∈ carrier), x ≤ y namespace cofinal protected instance inhabited {P : Type u_1} [preorder P] : Inhabited (cofinal P) := { default := mk set.univ sorry } protected instance has_mem {P : Type u_1} [preorder P] : has_mem P (cofinal P) := has_mem.mk fun (x : P) (D : cofinal P) => x ∈ carrier D /-- A (noncomputable) element of a cofinal set lying above a given element. -/ def above {P : Type u_1} [preorder P] (D : cofinal P) (x : P) : P := classical.some (mem_gt D x) theorem above_mem {P : Type u_1} [preorder P] (D : cofinal P) (x : P) : above D x ∈ D := exists.elim (classical.some_spec (mem_gt D x)) fun (a : classical.some (mem_gt D x) ∈ carrier D) (_x : x ≤ classical.some (mem_gt D x)) => a theorem le_above {P : Type u_1} [preorder P] (D : cofinal P) (x : P) : x ≤ above D x := exists.elim (classical.some_spec (mem_gt D x)) fun (_x : classical.some (mem_gt D x) ∈ carrier D) (b : x ≤ classical.some (mem_gt D x)) => b end cofinal /-- Given a starting point, and a countable family of cofinal sets, this is an increasing sequence that intersects each cofinal set. -/ def sequence_of_cofinals {P : Type u_1} [preorder P] (p : P) {ι : Type u_2} [encodable ι] (𝒟 : ι → cofinal P) : ℕ → P := sorry theorem sequence_of_cofinals.monotone {P : Type u_1} [preorder P] (p : P) {ι : Type u_2} [encodable ι] (𝒟 : ι → cofinal P) : monotone (sequence_of_cofinals p 𝒟) := sorry theorem sequence_of_cofinals.encode_mem {P : Type u_1} [preorder P] (p : P) {ι : Type u_2} [encodable ι] (𝒟 : ι → cofinal P) (i : ι) : sequence_of_cofinals p 𝒟 (encodable.encode i + 1) ∈ 𝒟 i := sorry /-- Given an element `p : P` and a family `𝒟` of cofinal subsets of a preorder `P`, indexed by a countable type, `ideal_of_cofinals p 𝒟` is an ideal in `P` which - contains `p`, according to `mem_ideal_of_cofinals p 𝒟`, and - intersects every set in `𝒟`, according to `cofinal_meets_ideal_of_cofinals p 𝒟`. This proves the Rasiowa–Sikorski lemma. -/ def ideal_of_cofinals {P : Type u_1} [preorder P] (p : P) {ι : Type u_2} [encodable ι] (𝒟 : ι → cofinal P) : ideal P := ideal.mk (set_of fun (x : P) => ∃ (n : ℕ), x ≤ sequence_of_cofinals p 𝒟 n) sorry sorry sorry theorem mem_ideal_of_cofinals {P : Type u_1} [preorder P] (p : P) {ι : Type u_2} [encodable ι] (𝒟 : ι → cofinal P) : p ∈ ideal_of_cofinals p 𝒟 := Exists.intro 0 (le_refl p) /-- `ideal_of_cofinals p 𝒟` is `𝒟`-generic. -/ theorem cofinal_meets_ideal_of_cofinals {P : Type u_1} [preorder P] (p : P) {ι : Type u_2} [encodable ι] (𝒟 : ι → cofinal P) (i : ι) : ∃ (x : P), x ∈ 𝒟 i ∧ x ∈ ideal_of_cofinals p 𝒟 := Exists.intro (sequence_of_cofinals p 𝒟 (encodable.encode i + 1)) { left := sequence_of_cofinals.encode_mem p 𝒟 i, right := Exists.intro (encodable.encode i + 1) (le_refl (sequence_of_cofinals p 𝒟 (encodable.encode i + 1))) } end Mathlib
6acab4e9919da8a72f97ce99af40124e0a8e7071
9dc8cecdf3c4634764a18254e94d43da07142918
/src/category_theory/sites/sheafification.lean
3fa8f802d41f3f3c2dd73203d5afca1c2f043dc2
[ "Apache-2.0" ]
permissive
jcommelin/mathlib
d8456447c36c176e14d96d9e76f39841f69d2d9b
ee8279351a2e434c2852345c51b728d22af5a156
refs/heads/master
1,664,782,136,488
1,663,638,983,000
1,663,638,983,000
132,563,656
0
0
Apache-2.0
1,663,599,929,000
1,525,760,539,000
Lean
UTF-8
Lean
false
false
24,082
lean
/- Copyright (c) 2021 Adam Topaz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz -/ import category_theory.sites.plus import category_theory.limits.concrete_category /-! # Sheafification We construct the sheafification of a presheaf over a site `C` with values in `D` whenever `D` is a concrete category for which the forgetful functor preserves the appropriate (co)limits and reflects isomorphisms. We generally follow the approach of https://stacks.math.columbia.edu/tag/00W1 -/ namespace category_theory open category_theory.limits opposite universes w v u variables {C : Type u} [category.{v} C] {J : grothendieck_topology C} variables {D : Type w} [category.{max v u} D] section variables [concrete_category.{max v u} D] local attribute [instance] concrete_category.has_coe_to_sort concrete_category.has_coe_to_fun /-- A concrete version of the multiequalizer, to be used below. -/ @[nolint has_nonempty_instance] def meq {X : C} (P : Cᵒᵖ ⥤ D) (S : J.cover X) := { x : Π (I : S.arrow), P.obj (op I.Y) // ∀ (I : S.relation), P.map I.g₁.op (x I.fst) = P.map I.g₂.op (x I.snd) } end namespace meq variables [concrete_category.{max v u} D] local attribute [instance] concrete_category.has_coe_to_sort concrete_category.has_coe_to_fun instance {X} (P : Cᵒᵖ ⥤ D) (S : J.cover X) : has_coe_to_fun (meq P S) (λ x, Π (I : S.arrow), P.obj (op I.Y)) := ⟨λ x, x.1⟩ @[ext] lemma ext {X} {P : Cᵒᵖ ⥤ D} {S : J.cover X} (x y : meq P S) (h : ∀ I : S.arrow, x I = y I) : x = y := subtype.ext $ funext $ h lemma condition {X} {P : Cᵒᵖ ⥤ D} {S : J.cover X} (x : meq P S) (I : S.relation) : P.map I.g₁.op (x ((S.index P).fst_to I)) = P.map I.g₂.op (x ((S.index P).snd_to I)) := x.2 _ /-- Refine a term of `meq P T` with respect to a refinement `S ⟶ T` of covers. -/ def refine {X : C} {P : Cᵒᵖ ⥤ D} {S T : J.cover X} (x : meq P T) (e : S ⟶ T) : meq P S := ⟨λ I, x ⟨I.Y, I.f, (le_of_hom e) _ I.hf⟩, λ I, x.condition ⟨I.Y₁, I.Y₂, I.Z, I.g₁, I.g₂, I.f₁, I.f₂, (le_of_hom e) _ I.h₁, (le_of_hom e) _ I.h₂, I.w⟩⟩ @[simp] lemma refine_apply {X : C} {P : Cᵒᵖ ⥤ D} {S T : J.cover X} (x : meq P T) (e : S ⟶ T) (I : S.arrow) : x.refine e I = x ⟨I.Y, I.f, (le_of_hom e) _ I.hf⟩ := rfl /-- Pull back a term of `meq P S` with respect to a morphism `f : Y ⟶ X` in `C`. -/ def pullback {Y X : C} {P : Cᵒᵖ ⥤ D} {S : J.cover X} (x : meq P S) (f : Y ⟶ X) : meq P ((J.pullback f).obj S) := ⟨λ I, x ⟨_,I.f ≫ f, I.hf⟩, λ I, x.condition ⟨I.Y₁, I.Y₂, I.Z, I.g₁, I.g₂, I.f₁ ≫ f, I.f₂ ≫ f, I.h₁, I.h₂, by simp [reassoc_of I.w]⟩ ⟩ @[simp] lemma pullback_apply {Y X : C} {P : Cᵒᵖ ⥤ D} {S : J.cover X} (x : meq P S) (f : Y ⟶ X) (I : ((J.pullback f).obj S).arrow) : x.pullback f I = x ⟨_, I.f ≫ f, I.hf⟩ := rfl @[simp] lemma pullback_refine {Y X : C} {P : Cᵒᵖ ⥤ D} {S T : J.cover X} (h : S ⟶ T) (f : Y ⟶ X) (x : meq P T) : (x.pullback f).refine ((J.pullback f).map h) = (refine x h).pullback _ := rfl /-- Make a term of `meq P S`. -/ def mk {X : C} {P : Cᵒᵖ ⥤ D} (S : J.cover X) (x : P.obj (op X)) : meq P S := ⟨λ I, P.map I.f.op x, λ I, by { dsimp, simp only [← comp_apply, ← P.map_comp, ← op_comp, I.w] }⟩ lemma mk_apply {X : C} {P : Cᵒᵖ ⥤ D} (S : J.cover X) (x : P.obj (op X)) (I : S.arrow) : mk S x I = P.map I.f.op x := rfl variable [preserves_limits (forget D)] /-- The equivalence between the type associated to `multiequalizer (S.index P)` and `meq P S`. -/ noncomputable def equiv {X : C} (P : Cᵒᵖ ⥤ D) (S : J.cover X) [has_multiequalizer (S.index P)] : (multiequalizer (S.index P) : D) ≃ meq P S := limits.concrete.multiequalizer_equiv _ @[simp] lemma equiv_apply {X : C} {P : Cᵒᵖ ⥤ D} {S : J.cover X} [has_multiequalizer (S.index P)] (x : multiequalizer (S.index P)) (I : S.arrow) : equiv P S x I = multiequalizer.ι (S.index P) I x := rfl @[simp] lemma equiv_symm_eq_apply {X : C} {P : Cᵒᵖ ⥤ D} {S : J.cover X} [has_multiequalizer (S.index P)] (x : meq P S) (I : S.arrow) : multiequalizer.ι (S.index P) I ((meq.equiv P S).symm x) = x I := begin let z := (meq.equiv P S).symm x, rw ← equiv_apply, simp, end end meq namespace grothendieck_topology namespace plus variables [concrete_category.{max v u} D] local attribute [instance] concrete_category.has_coe_to_sort concrete_category.has_coe_to_fun variable [preserves_limits (forget D)] variables [∀ (X : C), has_colimits_of_shape (J.cover X)ᵒᵖ D] variables [∀ (P : Cᵒᵖ ⥤ D) (X : C) (S : J.cover X), has_multiequalizer (S.index P)] noncomputable theory /-- Make a term of `(J.plus_obj P).obj (op X)` from `x : meq P S`. -/ def mk {X : C} {P : Cᵒᵖ ⥤ D} {S : J.cover X} (x : meq P S) : (J.plus_obj P).obj (op X) := colimit.ι (J.diagram P X) (op S) ((meq.equiv P S).symm x) lemma res_mk_eq_mk_pullback {Y X : C} {P : Cᵒᵖ ⥤ D} {S : J.cover X} (x : meq P S) (f : Y ⟶ X) : (J.plus_obj P).map f.op (mk x) = mk (x.pullback f) := begin dsimp [mk, plus_obj], simp only [← comp_apply, colimit.ι_pre, ι_colim_map_assoc], simp_rw [comp_apply], congr' 1, apply_fun meq.equiv P _, erw equiv.apply_symm_apply, ext i, simp only [diagram_pullback_app, meq.pullback_apply, meq.equiv_apply, ← comp_apply], erw [multiequalizer.lift_ι, meq.equiv_symm_eq_apply], cases i, refl, end lemma to_plus_mk {X : C} {P : Cᵒᵖ ⥤ D} (S : J.cover X) (x : P.obj (op X)) : (J.to_plus P).app _ x = mk (meq.mk S x) := begin dsimp [mk, to_plus], let e : S ⟶ ⊤ := hom_of_le (order_top.le_top _), rw ← colimit.w _ e.op, delta cover.to_multiequalizer, simp only [comp_apply], congr' 1, dsimp [diagram], apply concrete.multiequalizer_ext, intros i, simpa only [← comp_apply, category.assoc, multiequalizer.lift_ι, category.comp_id, meq.equiv_symm_eq_apply], end lemma to_plus_apply {X : C} {P : Cᵒᵖ ⥤ D} (S : J.cover X) (x : meq P S) (I : S.arrow) : (J.to_plus P).app _ (x I) = (J.plus_obj P).map I.f.op (mk x) := begin dsimp only [to_plus, plus_obj], delta cover.to_multiequalizer, dsimp [mk], simp only [← comp_apply, colimit.ι_pre, ι_colim_map_assoc], simp only [comp_apply], dsimp only [functor.op], let e : (J.pullback I.f).obj (unop (op S)) ⟶ ⊤ := hom_of_le (order_top.le_top _), rw ← colimit.w _ e.op, simp only [comp_apply], congr' 1, apply concrete.multiequalizer_ext, intros i, dsimp [diagram], simp only [← comp_apply, category.assoc, multiequalizer.lift_ι, category.comp_id, meq.equiv_symm_eq_apply], let RR : S.relation := ⟨_, _, _, i.f, 𝟙 _, I.f, i.f ≫ I.f, I.hf, sieve.downward_closed _ I.hf _, by simp⟩, cases I, erw x.condition RR, simpa [RR], end lemma to_plus_eq_mk {X : C} {P : Cᵒᵖ ⥤ D} (x : P.obj (op X)) : (J.to_plus P).app _ x = mk (meq.mk ⊤ x) := begin dsimp [mk, to_plus], delta cover.to_multiequalizer, simp only [comp_apply], congr' 1, apply_fun (meq.equiv P ⊤), ext i, simpa, end variables [∀ (X : C), preserves_colimits_of_shape (J.cover X)ᵒᵖ (forget D)] lemma exists_rep {X : C} {P : Cᵒᵖ ⥤ D} (x : (J.plus_obj P).obj (op X)) : ∃ (S : J.cover X) (y : meq P S), x = mk y := begin obtain ⟨S,y,h⟩ := concrete.colimit_exists_rep (J.diagram P X) x, use [S.unop, meq.equiv _ _ y], rw ← h, dsimp [mk], simp, end lemma eq_mk_iff_exists {X : C} {P : Cᵒᵖ ⥤ D} {S T : J.cover X} (x : meq P S) (y : meq P T) : mk x = mk y ↔ (∃ (W : J.cover X) (h1 : W ⟶ S) (h2 : W ⟶ T), x.refine h1 = y.refine h2) := begin split, { intros h, obtain ⟨W, h1, h2, hh⟩ := concrete.colimit_exists_of_rep_eq _ _ _ h, use [W.unop, h1.unop, h2.unop], ext I, apply_fun (multiequalizer.ι (W.unop.index P) I) at hh, convert hh, all_goals { dsimp [diagram], simp only [← comp_apply, multiequalizer.lift_ι, category.comp_id, meq.equiv_symm_eq_apply], cases I, refl } }, { rintros ⟨S,h1,h2,e⟩, apply concrete.colimit_rep_eq_of_exists, use [(op S), h1.op, h2.op], apply concrete.multiequalizer_ext, intros i, apply_fun (λ ee, ee i) at e, convert e, all_goals { dsimp [diagram], simp only [← comp_apply, multiequalizer.lift_ι, meq.equiv_symm_eq_apply], cases i, refl } }, end /-- `P⁺` is always separated. -/ theorem sep {X : C} (P : Cᵒᵖ ⥤ D) (S : J.cover X) (x y : (J.plus_obj P).obj (op X)) (h : ∀ (I : S.arrow), (J.plus_obj P).map I.f.op x = (J.plus_obj P).map I.f.op y) : x = y := begin -- First, we choose representatives for x and y. obtain ⟨Sx,x,rfl⟩ := exists_rep x, obtain ⟨Sy,y,rfl⟩ := exists_rep y, simp only [res_mk_eq_mk_pullback] at h, -- Next, using our assumption, -- choose covers over which the pullbacks of these representatives become equal. choose W h1 h2 hh using λ (I : S.arrow), (eq_mk_iff_exists _ _).mp (h I), -- To prove equality, it suffices to prove that there exists a cover over which -- the representatives become equal. rw eq_mk_iff_exists, -- Construct the cover over which the representatives become equal by combining the various -- covers chosen above. let B : J.cover X := S.bind W, use B, -- Prove that this cover refines the two covers over which our representatives are defined -- and use these proofs. let ex : B ⟶ Sx := hom_of_le begin rintros Y f ⟨Z,e1,e2,he2,he1,hee⟩, rw ← hee, apply le_of_hom (h1 ⟨_, _, he2⟩), exact he1, end, let ey : B ⟶ Sy := hom_of_le begin rintros Y f ⟨Z,e1,e2,he2,he1,hee⟩, rw ← hee, apply le_of_hom (h2 ⟨_, _, he2⟩), exact he1, end, use [ex, ey], -- Now prove that indeed the representatives become equal over `B`. -- This will follow by using the fact that our representatives become -- equal over the chosen covers. ext1 I, let IS : S.arrow := I.from_middle, specialize hh IS, let IW : (W IS).arrow := I.to_middle, apply_fun (λ e, e IW) at hh, convert hh, { let Rx : Sx.relation := ⟨I.Y, I.Y, I.Y, 𝟙 _, 𝟙 _, I.f, I.to_middle_hom ≫ I.from_middle_hom, _, _, by simp [I.middle_spec]⟩, have := x.condition Rx, simpa using this }, { let Ry : Sy.relation := ⟨I.Y, I.Y, I.Y, 𝟙 _, 𝟙 _, I.f, I.to_middle_hom ≫ I.from_middle_hom, _, _, by simp [I.middle_spec]⟩, have := y.condition Ry, simpa using this }, end lemma inj_of_sep (P : Cᵒᵖ ⥤ D) (hsep : ∀ (X : C) (S : J.cover X) (x y : P.obj (op X)), (∀ I : S.arrow, P.map I.f.op x = P.map I.f.op y) → x = y) (X : C) : function.injective ((J.to_plus P).app (op X)) := begin intros x y h, simp only [to_plus_eq_mk] at h, rw eq_mk_iff_exists at h, obtain ⟨W, h1, h2, hh⟩ := h, apply hsep X W, intros I, apply_fun (λ e, e I) at hh, exact hh end /-- An auxiliary definition to be used in the proof of `exists_of_sep` below. Given a compatible family of local sections for `P⁺`, and representatives of said sections, construct a compatible family of local sections of `P` over the combination of the covers associated to the representatives. The separatedness condition is used to prove compatibility among these local sections of `P`. -/ def meq_of_sep (P : Cᵒᵖ ⥤ D) (hsep : ∀ (X : C) (S : J.cover X) (x y : P.obj (op X)), (∀ I : S.arrow, P.map I.f.op x = P.map I.f.op y) → x = y) (X : C) (S : J.cover X) (s : meq (J.plus_obj P) S) (T : Π (I : S.arrow), J.cover I.Y) (t : Π (I : S.arrow), meq P (T I)) (ht : ∀ (I : S.arrow), s I = mk (t I)) : meq P (S.bind T) := { val := λ I, t I.from_middle I.to_middle, property := begin intros II, apply inj_of_sep P hsep, rw [← comp_apply, ← comp_apply, (J.to_plus P).naturality, (J.to_plus P).naturality, comp_apply, comp_apply], erw [to_plus_apply (T II.fst.from_middle) (t II.fst.from_middle) II.fst.to_middle, to_plus_apply (T II.snd.from_middle) (t II.snd.from_middle) II.snd.to_middle, ← ht, ← ht, ← comp_apply, ← comp_apply, ← (J.plus_obj P).map_comp, ← (J.plus_obj P).map_comp], rw [← op_comp, ← op_comp], let IR : S.relation := ⟨_, _, _, II.g₁ ≫ II.fst.to_middle_hom, II.g₂ ≫ II.snd.to_middle_hom, II.fst.from_middle_hom, II.snd.from_middle_hom, II.fst.from_middle_condition, II.snd.from_middle_condition, _⟩, swap, { simp only [category.assoc, II.fst.middle_spec, II.snd.middle_spec], apply II.w }, exact s.condition IR, end } theorem exists_of_sep (P : Cᵒᵖ ⥤ D) (hsep : ∀ (X : C) (S : J.cover X) (x y : P.obj (op X)), (∀ I : S.arrow, P.map I.f.op x = P.map I.f.op y) → x = y) (X : C) (S : J.cover X) (s : meq (J.plus_obj P) S) : ∃ t : (J.plus_obj P).obj (op X), meq.mk S t = s := begin have inj : ∀ (X : C), function.injective ((J.to_plus P).app (op X)) := inj_of_sep _ hsep, -- Choose representatives for the given local sections. choose T t ht using λ I, exists_rep (s I), -- Construct a large cover over which we will define a representative that will -- provide the gluing of the given local sections. let B : J.cover X := S.bind T, choose Z e1 e2 he2 he1 hee using λ I : B.arrow, I.hf, -- Construct a compatible system of local sections over this large cover, using the chosen -- representatives of our local sections. -- The compatilibity here follows from the separatedness assumption. let w : meq P B := meq_of_sep P hsep X S s T t ht, -- The associated gluing will be the candidate section. use mk w, ext I, erw [ht, res_mk_eq_mk_pullback], -- Use the separatedness of `P⁺` to prove that this is indeed a gluing of our -- original local sections. apply sep P (T I), intros II, simp only [res_mk_eq_mk_pullback, eq_mk_iff_exists], -- It suffices to prove equality for representatives over a -- convenient sufficiently large cover... use (J.pullback II.f).obj (T I), let e0 : (J.pullback II.f).obj (T I) ⟶ (J.pullback II.f).obj ((J.pullback I.f).obj B) := hom_of_le begin intros Y f hf, apply sieve.le_pullback_bind _ _ _ I.hf, { cases I, exact hf }, end, use [e0, 𝟙 _], ext IV, dsimp only [meq.refine_apply, meq.pullback_apply, w], let IA : B.arrow := ⟨_, (IV.f ≫ II.f) ≫ I.f, _⟩, swap, { refine ⟨I.Y, _, _, I.hf, _, rfl⟩, apply sieve.downward_closed, convert II.hf, cases I, refl }, let IB : S.arrow := IA.from_middle, let IC : (T IB).arrow := IA.to_middle, let ID : (T I).arrow := ⟨IV.Y, IV.f ≫ II.f, sieve.downward_closed (T I) II.hf IV.f⟩, change t IB IC = t I ID, apply inj IV.Y, erw [to_plus_apply (T I) (t I) ID, to_plus_apply (T IB) (t IB) IC, ← ht, ← ht], -- Conclude by constructing the relation showing equality... let IR : S.relation := ⟨_, _, IV.Y, IC.f, ID.f, IB.f, I.f, _, I.hf, IA.middle_spec⟩, convert s.condition IR, cases I, refl, end variable [reflects_isomorphisms (forget D)] /-- If `P` is separated, then `P⁺` is a sheaf. -/ theorem is_sheaf_of_sep (P : Cᵒᵖ ⥤ D) (hsep : ∀ (X : C) (S : J.cover X) (x y : P.obj (op X)), (∀ I : S.arrow, P.map I.f.op x = P.map I.f.op y) → x = y) : presheaf.is_sheaf J (J.plus_obj P) := begin rw presheaf.is_sheaf_iff_multiequalizer, intros X S, apply is_iso_of_reflects_iso _ (forget D), rw is_iso_iff_bijective, split, { intros x y h, apply sep P S _ _, intros I, apply_fun (meq.equiv _ _) at h, apply_fun (λ e, e I) at h, convert h, { erw [meq.equiv_apply, ← comp_apply, multiequalizer.lift_ι] }, { erw [meq.equiv_apply, ← comp_apply, multiequalizer.lift_ι] } }, { rintros (x : (multiequalizer (S.index _) : D)), obtain ⟨t,ht⟩ := exists_of_sep P hsep X S (meq.equiv _ _ x), use t, apply_fun meq.equiv _ _, swap, { apply_instance }, rw ← ht, ext i, dsimp, rw [← comp_apply, multiequalizer.lift_ι], refl } end variable (J) /-- `P⁺⁺` is always a sheaf. -/ theorem is_sheaf_plus_plus (P : Cᵒᵖ ⥤ D) : presheaf.is_sheaf J (J.plus_obj (J.plus_obj P)) := begin apply is_sheaf_of_sep, intros X S x y, apply sep, end end plus variables (J) variables [∀ (P : Cᵒᵖ ⥤ D) (X : C) (S : J.cover X), has_multiequalizer (S.index P)] [∀ (X : C), has_colimits_of_shape (J.cover X)ᵒᵖ D] /-- The sheafification of a presheaf `P`. *NOTE:* Additional hypotheses are needed to obtain a proof that this is a sheaf! -/ def sheafify (P : Cᵒᵖ ⥤ D) : Cᵒᵖ ⥤ D := J.plus_obj (J.plus_obj P) /-- The canonical map from `P` to its sheafification. -/ def to_sheafify (P : Cᵒᵖ ⥤ D) : P ⟶ J.sheafify P := J.to_plus P ≫ J.plus_map (J.to_plus P) /-- The canonical map on sheafifications induced by a morphism. -/ def sheafify_map {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) : J.sheafify P ⟶ J.sheafify Q := J.plus_map $ J.plus_map η @[simp] lemma sheafify_map_id (P : Cᵒᵖ ⥤ D) : J.sheafify_map (𝟙 P) = 𝟙 (J.sheafify P) := by { dsimp [sheafify_map, sheafify], simp } @[simp] lemma sheafify_map_comp {P Q R : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (γ : Q ⟶ R) : J.sheafify_map (η ≫ γ) = J.sheafify_map η ≫ J.sheafify_map γ := by { dsimp [sheafify_map, sheafify], simp } @[simp, reassoc] lemma to_sheafify_naturality {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) : η ≫ J.to_sheafify _ = J.to_sheafify _ ≫ J.sheafify_map η := by { dsimp [sheafify_map, sheafify, to_sheafify], simp } variable (D) /-- The sheafification of a presheaf `P`, as a functor. *NOTE:* Additional hypotheses are needed to obtain a proof that this is a sheaf! -/ def sheafification : (Cᵒᵖ ⥤ D) ⥤ Cᵒᵖ ⥤ D := (J.plus_functor D ⋙ J.plus_functor D) @[simp] lemma sheafification_obj (P : Cᵒᵖ ⥤ D) : (J.sheafification D).obj P = J.sheafify P := rfl @[simp] lemma sheafification_map {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) : (J.sheafification D).map η = J.sheafify_map η := rfl /-- The canonical map from `P` to its sheafification, as a natural transformation. *Note:* We only show this is a sheaf under additional hypotheses on `D`. -/ def to_sheafification : 𝟭 _ ⟶ sheafification J D := J.to_plus_nat_trans D ≫ whisker_right (J.to_plus_nat_trans D) (J.plus_functor D) @[simp] lemma to_sheafification_app (P : Cᵒᵖ ⥤ D) : (J.to_sheafification D).app P = J.to_sheafify P := rfl variable {D} lemma is_iso_to_sheafify {P : Cᵒᵖ ⥤ D} (hP : presheaf.is_sheaf J P) : is_iso (J.to_sheafify P) := begin dsimp [to_sheafify], haveI : is_iso (J.to_plus P) := by { apply is_iso_to_plus_of_is_sheaf J P hP }, haveI : is_iso ((J.plus_functor D).map (J.to_plus P)) := by { apply functor.map_is_iso }, exact @is_iso.comp_is_iso _ _ _ _ _ (J.to_plus P) ((J.plus_functor D).map (J.to_plus P)) _ _, end /-- If `P` is a sheaf, then `P` is isomorphic to `J.sheafify P`. -/ def iso_sheafify {P : Cᵒᵖ ⥤ D} (hP : presheaf.is_sheaf J P) : P ≅ J.sheafify P := by letI := is_iso_to_sheafify J hP; exactI as_iso (J.to_sheafify P) @[simp] lemma iso_sheafify_hom {P : Cᵒᵖ ⥤ D} (hP : presheaf.is_sheaf J P) : (J.iso_sheafify hP).hom = J.to_sheafify P := rfl /-- Given a sheaf `Q` and a morphism `P ⟶ Q`, construct a morphism from `J.sheafifcation P` to `Q`. -/ def sheafify_lift {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (hQ : presheaf.is_sheaf J Q) : J.sheafify P ⟶ Q := J.plus_lift (J.plus_lift η hQ) hQ @[simp, reassoc] lemma to_sheafify_sheafify_lift {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (hQ : presheaf.is_sheaf J Q) : J.to_sheafify P ≫ sheafify_lift J η hQ = η := by { dsimp only [sheafify_lift, to_sheafify], simp } lemma sheafify_lift_unique {P Q : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (hQ : presheaf.is_sheaf J Q) (γ : J.sheafify P ⟶ Q) : J.to_sheafify P ≫ γ = η → γ = sheafify_lift J η hQ := begin intros h, apply plus_lift_unique, apply plus_lift_unique, rw [← category.assoc, ← plus_map_to_plus], exact h, end @[simp] lemma iso_sheafify_inv {P : Cᵒᵖ ⥤ D} (hP : presheaf.is_sheaf J P) : (J.iso_sheafify hP).inv = J.sheafify_lift (𝟙 _) hP := begin apply J.sheafify_lift_unique, simp [iso.comp_inv_eq], end lemma sheafify_hom_ext {P Q : Cᵒᵖ ⥤ D} (η γ : J.sheafify P ⟶ Q) (hQ : presheaf.is_sheaf J Q) (h : J.to_sheafify P ≫ η = J.to_sheafify P ≫ γ) : η = γ := begin apply J.plus_hom_ext _ _ hQ, apply J.plus_hom_ext _ _ hQ, rw [← category.assoc, ← category.assoc, ← plus_map_to_plus], exact h, end @[simp, reassoc] lemma sheafify_map_sheafify_lift {P Q R : Cᵒᵖ ⥤ D} (η : P ⟶ Q) (γ : Q ⟶ R) (hR : presheaf.is_sheaf J R) : J.sheafify_map η ≫ J.sheafify_lift γ hR = J.sheafify_lift (η ≫ γ) hR := begin apply J.sheafify_lift_unique, rw [← category.assoc, ← J.to_sheafify_naturality, category.assoc, to_sheafify_sheafify_lift], end end grothendieck_topology variables (J) variables [concrete_category.{max v u} D] [preserves_limits (forget D)] [∀ (P : Cᵒᵖ ⥤ D) (X : C) (S : J.cover X), has_multiequalizer (S.index P)] [∀ (X : C), has_colimits_of_shape (J.cover X)ᵒᵖ D] [∀ (X : C), preserves_colimits_of_shape (J.cover X)ᵒᵖ (forget D)] [reflects_isomorphisms (forget D)] lemma grothendieck_topology.sheafify_is_sheaf (P : Cᵒᵖ ⥤ D) : presheaf.is_sheaf J (J.sheafify P) := grothendieck_topology.plus.is_sheaf_plus_plus _ _ variables (D) /-- The sheafification functor, as a functor taking values in `Sheaf`. -/ @[simps] def presheaf_to_Sheaf : (Cᵒᵖ ⥤ D) ⥤ Sheaf J D := { obj := λ P, ⟨J.sheafify P, J.sheafify_is_sheaf P⟩, map := λ P Q η, ⟨J.sheafify_map η⟩, map_id' := λ P, Sheaf.hom.ext _ _ $ J.sheafify_map_id _, map_comp' := λ P Q R f g, Sheaf.hom.ext _ _ $ J.sheafify_map_comp _ _ } instance presheaf_to_Sheaf_preserves_zero_morphisms [preadditive D] : (presheaf_to_Sheaf J D).preserves_zero_morphisms := { map_zero' := λ F G, by { ext, erw [colimit.ι_map, comp_zero, J.plus_map_zero, J.diagram_nat_trans_zero, zero_comp] } } /-- The sheafification functor is left adjoint to the forgetful functor. -/ @[simps unit_app counit_app_val] def sheafification_adjunction : presheaf_to_Sheaf J D ⊣ Sheaf_to_presheaf J D := adjunction.mk_of_hom_equiv { hom_equiv := λ P Q, { to_fun := λ e, J.to_sheafify P ≫ e.val, inv_fun := λ e, ⟨J.sheafify_lift e Q.2⟩, left_inv := λ e, Sheaf.hom.ext _ _ $ (J.sheafify_lift_unique _ _ _ rfl).symm, right_inv := λ e, J.to_sheafify_sheafify_lift _ _ }, hom_equiv_naturality_left_symm' := begin intros P Q R η γ, ext1, dsimp, symmetry, apply J.sheafify_map_sheafify_lift, end, hom_equiv_naturality_right' := λ P Q R η γ, by { dsimp, rw category.assoc } } instance Sheaf_to_presheaf_is_right_adjoint : is_right_adjoint (Sheaf_to_presheaf J D) := ⟨_, sheafification_adjunction J D⟩ instance presheaf_mono_of_mono {F G : Sheaf J D} (f : F ⟶ G) [mono f] : mono f.1 := (Sheaf_to_presheaf J D).map_mono _ lemma Sheaf.hom.mono_iff_presheaf_mono {F G : Sheaf J D} (f : F ⟶ G) : mono f ↔ mono f.1 := ⟨λ m, by { resetI, apply_instance }, λ m, by { resetI, exact Sheaf.hom.mono_of_presheaf_mono J D f }⟩ variables {J D} /-- A sheaf `P` is isomorphic to its own sheafification. -/ @[simps] def sheafification_iso (P : Sheaf J D) : P ≅ (presheaf_to_Sheaf J D).obj P.val := { hom := ⟨(J.iso_sheafify P.2).hom⟩, inv := ⟨(J.iso_sheafify P.2).inv⟩, hom_inv_id' := by { ext1, apply (J.iso_sheafify P.2).hom_inv_id }, inv_hom_id' := by { ext1, apply (J.iso_sheafify P.2).inv_hom_id } } instance is_iso_sheafification_adjunction_counit (P : Sheaf J D) : is_iso ((sheafification_adjunction J D).counit.app P) := is_iso_of_fully_faithful (Sheaf_to_presheaf J D) _ instance sheafification_reflective : is_iso (sheafification_adjunction J D).counit := nat_iso.is_iso_of_is_iso_app _ end category_theory
7a9405c7040d4c9553fbbabdbdeb57de542864cb
d31b9f832ff922a603f76cf32e0f3aa822640508
/src/hott/init/function.lean
74b0184c33fe477a207f92a1535baa13cb13bcd3
[ "Apache-2.0" ]
permissive
javra/hott3
6e7a9e72a991a2fae32e5764982e521dca617b16
cd51f2ab2aa48c1246a188f9b525b30f76c3d651
refs/heads/master
1,585,819,679,148
1,531,232,382,000
1,536,682,965,000
154,294,022
0
0
Apache-2.0
1,540,284,376,000
1,540,284,375,000
null
UTF-8
Lean
false
false
751
lean
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura General operations on functions. -/ import .meta.support universes u v w hott_theory namespace function @[hott] def compose_right {A B} (f : B → B → B) (g : A → B) : B → A → B := λ b a, f b (g a) @[hott] def compose_left {A B} (f : B → B → B) (g : A → B) : A → B → B := λ a b, f (g a) b @[hott] def dcompose {A} {B : A → Type _} {C : Π {x : A}, B x → Type _} (f : Π {x : A} (y : B x), C y) (g : Πx, B x) : Πx, C (g x) := λx, f (g x) infixr ` ∘' `:60 := dcompose end function namespace hott export function attribute [reducible] id end hott
a904366e37eb378edfff47413e25f1ac8405bc79
aa44b2a5876642f9460205af61a5449b74465655
/src/factor_matrix.lean
93016a8c74093552973c31f0bd80bd6bde30343a
[]
no_license
robertylewis/mathematica_examples
d129d67de147dc2792dcf0b6b70fac9b2eaf8274
e317381c49db032accef2a92e7650d029952ad76
refs/heads/master
1,632,630,516,240
1,631,905,726,000
1,631,905,726,000
80,952,455
2
0
null
null
null
null
UTF-8
Lean
false
false
2,414
lean
/- Copyright (c) 2017 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Robert Y. Lewis -/ import mathematica import data.list.basic open expr tactic /-! In this demo we use a brief computable representation of matrices to verify instances of LU decomposition done by Mathematica. With some extra glue, this could operate on mathlib's matrix representation. The LU algorithm is only specified up to permutation, which we do not address here, so this is only correct for simple cases. -/ def {u} dot_lists {α : Type u} [has_zero α] [has_mul α] [has_add α] : list α → list α → α | [a] [b] := a*b | (h1::t1) (h2::t2) := h1*h2 + dot_lists t1 t2 | _ _ := 0 def {u} mul_lists {α : Type u} [has_zero α] [has_mul α] [has_add α] [inhabited α] (m1 m2 : list (list α)) : list (list α) := list.map (λ i, (list.map (λ j, dot_lists (list.inth m1 i) (list.inth (list.transpose m2) j)) (list.range (list.inth m1 0).length))) (list.range m1.length) infix `**`:50 := mul_lists local attribute [instance] def inhabited_of_has_zero {α} [has_zero α] : inhabited α := ⟨0⟩ @[reducible] def {u} is_lower_triangular {α : Type u} [has_lt α] [has_zero α] (m : list (list α)) : Prop := ∀ i < m^.length, ∀ j < (list.inth m i)^.length, i < j → list.inth (list.inth m i) j = 0 @[reducible] def {u} is_upper_triangular {α : Type u} [has_lt α] [has_zero α] (m : list (list α)) : Prop := ∀ i < m^.length, ∀ j < (list.inth m i)^.length, i > j → list.inth (list.inth m i) j = 0 meta def lu_tac : tactic unit := do t ← target, (lam _ _ _ bd) ← return $ app_arg t, (lam _ _ _ ande) ← return $ app_arg bd, `(%%_ ∧ %%_ ∧ %%_ = %%e) ← return $ ande, tp ← infer_type e, m ← mathematica.run_command_on_using (λ e, e ++ " // LeanForm // Activate // LUDecomp") e "matrix_factor.m", m2 ← to_expr ```((%%m : list %%tp)), lhs ← to_expr ```(list.inth %%m2 0), rhs ← to_expr ```(list.inth %%m2 1), existsi lhs, existsi rhs, `[refine ⟨dec_trivial, dec_trivial, _⟩], reflexivity example : ∃ l u, is_lower_triangular l ∧ is_upper_triangular u ∧ l ** u = [[(1 : ℤ), 2], [3, 4]] := by lu_tac example : ∃ l u, is_lower_triangular l ∧ is_upper_triangular u ∧ l ** u = [[1, 2, 3], [1, 4, 9], [1, 8, 27]] := by lu_tac
a88cc7f4bf46729d6082f15461a4c33e346cf0e7
9be442d9ec2fcf442516ed6e9e1660aa9071b7bd
/tests/lean/linterMissingDocs.lean
42b1f2720c64847f4ed4fe7cf12bc5ba0ec328a9
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach" ]
permissive
EdAyers/lean4
57ac632d6b0789cb91fab2170e8c9e40441221bd
37ba0df5841bde51dbc2329da81ac23d4f6a4de4
refs/heads/master
1,676,463,245,298
1,660,619,433,000
1,660,619,433,000
183,433,437
1
0
Apache-2.0
1,657,612,672,000
1,556,196,574,000
Lean
UTF-8
Lean
false
false
2,221
lean
import Lean set_option linter.all true /-- A doc string -/ def hasDoc (x : Nat) := x def noDoc (x : Nat) := x private def auxDef (x : Nat) := x namespace Foo protected def noDoc2 (x : Nat) := x end Foo open Foo in def openIn (x : Nat) := x open Foo in /-- A doc string -/ def openIn2 (x : Nat) := x set_option pp.all true in def setOptionIn1 (x : Nat) := x set_option pp.all true in /-- A doc string -/ def setOptionIn2 (x : Nat) := x set_option linter.all false in def nolintAll (x : Nat) := x set_option linter.all true in set_option linter.missingDocs false in def nolintDoc (x : Nat) := x set_option linter.all false in set_option linter.missingDocs true in def lintDoc (x : Nat) := x inductive Ind where | ind1 | ind2 : Ind → Ind | /-- A doc string -/ doc : Ind with @[computedField] field : Ind → Nat | _ => 1 structure Foo where mk1 : Nat /-- test -/ (mk2 mk3 : Nat) {mk4 mk5 : Nat} [mk6 mk7 : Nat] class Bar (α : Prop) := mk :: (foo bar := 1) class Bar2 (α : Prop) where bar := 2 class Bar3 (α : Prop) extends Bar α where bar := 3 (foo baz := 3) theorem aThm : True := trivial example : True := trivial instance : Bar True := {} initialize init : Unit ← return initialize return declare_syntax_cat myCat syntax "my_syn" : myCat syntax (name := namedSyn) "my_named_syn" myCat : command infixl:20 "<my_infix>" => Nat.add infixr:20 (name := namedInfix) "<my_named_infix>" => Nat.add notation:20 "my_notation" x y => Nat.add x y notation:20 (name := namedNota) "my_named_notation" x y => Nat.add x y macro_rules | `(my_named_syn my_syn) => `(def hygienic := 1) elab_rules : command | `(my_named_syn my_syn) => return my_named_syn my_syn elab "my_elab" : term => return Lean.mkConst ``false macro "my_macro" : term => `(my_elab) class abbrev BarAbbrev (α : Prop) := Bar α register_option myOption : Bool := { defValue := my_macro, descr := "hi mom" } elab (name := myCmd) (docComment)? "my_command" ident : command => pure () my_command x open Lean.Linter.MissingDocs in @[missingDocsHandler myCmd] def handleMyCmd : SimpleHandler := fun | `(my_command $x:ident) => lintNamed x "my_command" | _ => pure () /-- doc -/ my_command y my_command z
44c2a1d33f5de9d7edb9403613840eccbb09ca16
4950bf76e5ae40ba9f8491647d0b6f228ddce173
/src/analysis/mean_inequalities.lean
0bd41725f00d44207a5f469077ad1efc105d4f38
[ "Apache-2.0" ]
permissive
ntzwq/mathlib
ca50b21079b0a7c6781c34b62199a396dd00cee2
36eec1a98f22df82eaccd354a758ef8576af2a7f
refs/heads/master
1,675,193,391,478
1,607,822,996,000
1,607,822,996,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
35,312
lean
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne -/ import analysis.convex.specific_functions import analysis.special_functions.pow import data.real.conjugate_exponents import tactic.nth_rewrite import measure_theory.integration /-! # Mean value inequalities In this file we prove several inequalities, including AM-GM inequality, Young's inequality, Hölder inequality, and Minkowski inequality. ## Main theorems ### AM-GM inequality: The inequality says that the geometric mean of a tuple of non-negative numbers is less than or equal to their arithmetic mean. We prove the weighted version of this inequality: if $w$ and $z$ are two non-negative vectors and $\sum_{i\in s} w_i=1$, then $$ \prod_{i\in s} z_i^{w_i} ≤ \sum_{i\in s} w_iz_i. $$ The classical version is a special case of this inequality for $w_i=\frac{1}{n}$. We prove a few versions of this inequality. Each of the following lemmas comes in two versions: a version for real-valued non-negative functions is in the `real` namespace, and a version for `nnreal`-valued functions is in the `nnreal` namespace. - `geom_mean_le_arith_mean_weighted` : weighted version for functions on `finset`s; - `geom_mean_le_arith_mean2_weighted` : weighted version for two numbers; - `geom_mean_le_arith_mean3_weighted` : weighted version for three numbers; - `geom_mean_le_arith_mean4_weighted` : weighted version for four numbers. ### Generalized mean inequality The inequality says that for two non-negative vectors $w$ and $z$ with $\sum_{i\in s} w_i=1$ and $p ≤ q$ we have $$ \sqrt[p]{\sum_{i\in s} w_i z_i^p} ≤ \sqrt[q]{\sum_{i\in s} w_i z_i^q}. $$ Currently we only prove this inequality for $p=1$. As in the rest of `mathlib`, we provide different theorems for natural exponents (`pow_arith_mean_le_arith_mean_pow`), integer exponents (`fpow_arith_mean_le_arith_mean_fpow`), and real exponents (`rpow_arith_mean_le_arith_mean_rpow` and `arith_mean_le_rpow_mean`). In the first two cases we prove $$ \left(\sum_{i\in s} w_i z_i\right)^n ≤ \sum_{i\in s} w_i z_i^n $$ in order to avoid using real exponents. For real exponents we prove both this and standard versions. ### Young's inequality Young's inequality says that for non-negative numbers `a`, `b`, `p`, `q` such that $\frac{1}{p}+\frac{1}{q}=1$ we have $$ ab ≤ \frac{a^p}{p} + \frac{b^q}{q}. $$ This inequality is a special case of the AM-GM inequality. It can be used to prove Hölder's inequality (see below) but we use a different proof. ### Hölder's inequality The inequality says that for two conjugate exponents `p` and `q` (i.e., for two positive numbers such that $\frac{1}{p}+\frac{1}{q}=1$) and any two non-negative vectors their inner product is less than or equal to the product of the $L_p$ norm of the first vector and the $L_q$ norm of the second vector: $$ \sum_{i\in s} a_ib_i ≤ \sqrt[p]{\sum_{i\in s} a_i^p}\sqrt[q]{\sum_{i\in s} b_i^q}. $$ We give versions of this result in `real`, `nnreal` and `ennreal`. There are at least two short proofs of this inequality. In one proof we prenormalize both vectors, then apply Young's inequality to each $a_ib_i$. We use a different proof deducing this inequality from the generalized mean inequality for well-chosen vectors and weights. Hölder's inequality for the Lebesgue integral of ennreal and nnreal functions: we prove `∫ (f * g) ∂μ ≤ (∫ f^p ∂μ) ^ (1/p) * (∫ g^q ∂μ) ^ (1/q)` for `p`, `q` conjugate real exponents and `α→(e)nnreal` functions in two cases, * `ennreal.lintegral_mul_le_Lp_mul_Lq` : ennreal functions, * `nnreal.lintegral_mul_le_Lp_mul_Lq` : nnreal functions. ### Minkowski's inequality The inequality says that for `p ≥ 1` the function $$ \|a\|_p=\sqrt[p]{\sum_{i\in s} a_i^p} $$ satisfies the triangle inequality $\|a+b\|_p\le \|a\|_p+\|b\|_p$. We give versions of this result in `real`, `nnreal` and `ennreal`. We deduce this inequality from Hölder's inequality. Namely, Hölder inequality implies that $\|a\|_p$ is the maximum of the inner product $\sum_{i\in s}a_ib_i$ over `b` such that $\|b\|_q\le 1$. Now Minkowski's inequality follows from the fact that the maximum value of the sum of two functions is less than or equal to the sum of the maximum values of the summands. ## TODO - each inequality `A ≤ B` should come with a theorem `A = B ↔ _`; one of the ways to prove them is to define `strict_convex_on` functions. - generalized mean inequality with any `p ≤ q`, including negative numbers; - prove that the power mean tends to the geometric mean as the exponent tends to zero. - prove integral versions of these inequalities. -/ universes u v open finset open_locale classical nnreal big_operators noncomputable theory variables {ι : Type u} (s : finset ι) namespace real /-- AM-GM inequality: the geometric mean is less than or equal to the arithmetic mean, weighted version for real-valued nonnegative functions. -/ theorem geom_mean_le_arith_mean_weighted (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : ∑ i in s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) : (∏ i in s, (z i) ^ (w i)) ≤ ∑ i in s, w i * z i := begin -- If some number `z i` equals zero and has non-zero weight, then LHS is 0 and RHS is nonnegative. by_cases A : ∃ i ∈ s, z i = 0 ∧ w i ≠ 0, { rcases A with ⟨i, his, hzi, hwi⟩, rw [prod_eq_zero his], { exact sum_nonneg (λ j hj, mul_nonneg (hw j hj) (hz j hj)) }, { rw hzi, exact zero_rpow hwi } }, -- If all numbers `z i` with non-zero weight are positive, then we apply Jensen's inequality -- for `exp` and numbers `log (z i)` with weights `w i`. { simp only [not_exists, not_and, ne.def, not_not] at A, have := convex_on_exp.map_sum_le hw hw' (λ i _, set.mem_univ $ log (z i)), simp only [exp_sum, (∘), smul_eq_mul, mul_comm (w _) (log _)] at this, convert this using 1; [apply prod_congr rfl, apply sum_congr rfl]; intros i hi, { cases eq_or_lt_of_le (hz i hi) with hz hz, { simp [A i hi hz.symm] }, { exact rpow_def_of_pos hz _ } }, { cases eq_or_lt_of_le (hz i hi) with hz hz, { simp [A i hi hz.symm] }, { rw [exp_log hz] } } } end theorem pow_arith_mean_le_arith_mean_pow (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : ∑ i in s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) (n : ℕ) : (∑ i in s, w i * z i) ^ n ≤ ∑ i in s, (w i * z i ^ n) := (convex_on_pow n).map_sum_le hw hw' hz theorem pow_arith_mean_le_arith_mean_pow_of_even (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : ∑ i in s, w i = 1) {n : ℕ} (hn : even n) : (∑ i in s, w i * z i) ^ n ≤ ∑ i in s, (w i * z i ^ n) := (convex_on_pow_of_even hn).map_sum_le hw hw' (λ _ _, trivial) theorem fpow_arith_mean_le_arith_mean_fpow (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : ∑ i in s, w i = 1) (hz : ∀ i ∈ s, 0 < z i) (m : ℤ) : (∑ i in s, w i * z i) ^ m ≤ ∑ i in s, (w i * z i ^ m) := (convex_on_fpow m).map_sum_le hw hw' hz theorem rpow_arith_mean_le_arith_mean_rpow (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : ∑ i in s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) {p : ℝ} (hp : 1 ≤ p) : (∑ i in s, w i * z i) ^ p ≤ ∑ i in s, (w i * z i ^ p) := (convex_on_rpow hp).map_sum_le hw hw' hz theorem arith_mean_le_rpow_mean (w z : ι → ℝ) (hw : ∀ i ∈ s, 0 ≤ w i) (hw' : ∑ i in s, w i = 1) (hz : ∀ i ∈ s, 0 ≤ z i) {p : ℝ} (hp : 1 ≤ p) : ∑ i in s, w i * z i ≤ (∑ i in s, (w i * z i ^ p)) ^ (1 / p) := begin have : 0 < p := lt_of_lt_of_le zero_lt_one hp, rw [← rpow_le_rpow_iff _ _ this, ← rpow_mul, one_div_mul_cancel (ne_of_gt this), rpow_one], exact rpow_arith_mean_le_arith_mean_rpow s w z hw hw' hz hp, all_goals { apply_rules [sum_nonneg, rpow_nonneg_of_nonneg], intros i hi, apply_rules [mul_nonneg, rpow_nonneg_of_nonneg, hw i hi, hz i hi] }, end end real namespace nnreal /-- The geometric mean is less than or equal to the arithmetic mean, weighted version for `nnreal`-valued functions. -/ theorem geom_mean_le_arith_mean_weighted (w z : ι → ℝ≥0) (hw' : ∑ i in s, w i = 1) : (∏ i in s, (z i) ^ (w i:ℝ)) ≤ ∑ i in s, w i * z i := by exact_mod_cast real.geom_mean_le_arith_mean_weighted _ _ _ (λ i _, (w i).coe_nonneg) (by assumption_mod_cast) (λ i _, (z i).coe_nonneg) /-- The geometric mean is less than or equal to the arithmetic mean, weighted version for two `nnreal` numbers. -/ theorem geom_mean_le_arith_mean2_weighted (w₁ w₂ p₁ p₂ : ℝ≥0) : w₁ + w₂ = 1 → p₁ ^ (w₁:ℝ) * p₂ ^ (w₂:ℝ) ≤ w₁ * p₁ + w₂ * p₂ := by simpa only [fin.prod_univ_succ, fin.sum_univ_succ, fin.prod_univ_zero, fin.sum_univ_zero, fin.cons_succ, fin.cons_zero, add_zero, mul_one] using geom_mean_le_arith_mean_weighted (univ : finset (fin 2)) (fin.cons w₁ $ fin.cons w₂ fin_zero_elim) (fin.cons p₁ $ fin.cons p₂ $ fin_zero_elim) theorem geom_mean_le_arith_mean3_weighted (w₁ w₂ w₃ p₁ p₂ p₃ : ℝ≥0) : w₁ + w₂ + w₃ = 1 → p₁ ^ (w₁:ℝ) * p₂ ^ (w₂:ℝ) * p₃ ^ (w₃:ℝ) ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ := by simpa only [fin.prod_univ_succ, fin.sum_univ_succ, fin.prod_univ_zero, fin.sum_univ_zero, fin.cons_succ, fin.cons_zero, add_zero, mul_one, ← add_assoc, mul_assoc] using geom_mean_le_arith_mean_weighted (univ : finset (fin 3)) (fin.cons w₁ $ fin.cons w₂ $ fin.cons w₃ fin_zero_elim) (fin.cons p₁ $ fin.cons p₂ $ fin.cons p₃ fin_zero_elim) theorem geom_mean_le_arith_mean4_weighted (w₁ w₂ w₃ w₄ p₁ p₂ p₃ p₄ : ℝ≥0) : w₁ + w₂ + w₃ + w₄ = 1 → p₁ ^ (w₁:ℝ) * p₂ ^ (w₂:ℝ) * p₃ ^ (w₃:ℝ)* p₄ ^ (w₄:ℝ) ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ + w₄ * p₄ := by simpa only [fin.prod_univ_succ, fin.sum_univ_succ, fin.prod_univ_zero, fin.sum_univ_zero, fin.cons_succ, fin.cons_zero, add_zero, mul_one, ← add_assoc, mul_assoc] using geom_mean_le_arith_mean_weighted (univ : finset (fin 4)) (fin.cons w₁ $ fin.cons w₂ $ fin.cons w₃ $ fin.cons w₄ fin_zero_elim) (fin.cons p₁ $ fin.cons p₂ $ fin.cons p₃ $ fin.cons p₄ fin_zero_elim) /-- Weighted generalized mean inequality, version sums over finite sets, with `ℝ≥0`-valued functions and natural exponent. -/ theorem pow_arith_mean_le_arith_mean_pow (w z : ι → ℝ≥0) (hw' : ∑ i in s, w i = 1) (n : ℕ) : (∑ i in s, w i * z i) ^ n ≤ ∑ i in s, (w i * z i ^ n) := by exact_mod_cast real.pow_arith_mean_le_arith_mean_pow s _ _ (λ i _, (w i).coe_nonneg) (by exact_mod_cast hw') (λ i _, (z i).coe_nonneg) n /-- Weighted generalized mean inequality, version for sums over finite sets, with `ℝ≥0`-valued functions and real exponents. -/ theorem rpow_arith_mean_le_arith_mean_rpow (w z : ι → ℝ≥0) (hw' : ∑ i in s, w i = 1) {p : ℝ} (hp : 1 ≤ p) : (∑ i in s, w i * z i) ^ p ≤ ∑ i in s, (w i * z i ^ p) := by exact_mod_cast real.rpow_arith_mean_le_arith_mean_rpow s _ _ (λ i _, (w i).coe_nonneg) (by exact_mod_cast hw') (λ i _, (z i).coe_nonneg) hp /-- Weighted generalized mean inequality, version for two elements of `ℝ≥0` and real exponents. -/ theorem rpow_arith_mean_le_arith_mean2_rpow (w₁ w₂ z₁ z₂ : ℝ≥0) (hw' : w₁ + w₂ = 1) {p : ℝ} (hp : 1 ≤ p) : (w₁ * z₁ + w₂ * z₂) ^ p ≤ w₁ * z₁ ^ p + w₂ * z₂ ^ p := begin have h := rpow_arith_mean_le_arith_mean_rpow (univ : finset (fin 2)) (fin.cons w₁ $ fin.cons w₂ fin_zero_elim) (fin.cons z₁ $ fin.cons z₂ $ fin_zero_elim) _ hp, { simpa [fin.sum_univ_succ, fin.sum_univ_zero, fin.cons_succ, fin.cons_zero] using h, }, { simp [hw', fin.sum_univ_succ, fin.sum_univ_zero, fin.cons_succ, fin.cons_zero], }, end /-- Weighted generalized mean inequality, version for sums over finite sets, with `ℝ≥0`-valued functions and real exponents. -/ theorem arith_mean_le_rpow_mean (w z : ι → ℝ≥0) (hw' : ∑ i in s, w i = 1) {p : ℝ} (hp : 1 ≤ p) : ∑ i in s, w i * z i ≤ (∑ i in s, (w i * z i ^ p)) ^ (1 / p) := by exact_mod_cast real.arith_mean_le_rpow_mean s _ _ (λ i _, (w i).coe_nonneg) (by exact_mod_cast hw') (λ i _, (z i).coe_nonneg) hp end nnreal namespace real theorem geom_mean_le_arith_mean2_weighted {w₁ w₂ p₁ p₂ : ℝ} (hw₁ : 0 ≤ w₁) (hw₂ : 0 ≤ w₂) (hp₁ : 0 ≤ p₁) (hp₂ : 0 ≤ p₂) (hw : w₁ + w₂ = 1) : p₁ ^ w₁ * p₂ ^ w₂ ≤ w₁ * p₁ + w₂ * p₂ := nnreal.geom_mean_le_arith_mean2_weighted ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ ⟨p₁, hp₁⟩ ⟨p₂, hp₂⟩ $ nnreal.coe_eq.1 $ by assumption theorem geom_mean_le_arith_mean3_weighted {w₁ w₂ w₃ p₁ p₂ p₃ : ℝ} (hw₁ : 0 ≤ w₁) (hw₂ : 0 ≤ w₂) (hw₃ : 0 ≤ w₃) (hp₁ : 0 ≤ p₁) (hp₂ : 0 ≤ p₂) (hp₃ : 0 ≤ p₃) (hw : w₁ + w₂ + w₃ = 1) : p₁ ^ w₁ * p₂ ^ w₂ * p₃ ^ w₃ ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ := nnreal.geom_mean_le_arith_mean3_weighted ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ ⟨w₃, hw₃⟩ ⟨p₁, hp₁⟩ ⟨p₂, hp₂⟩ ⟨p₃, hp₃⟩ $ nnreal.coe_eq.1 $ by assumption theorem geom_mean_le_arith_mean4_weighted {w₁ w₂ w₃ w₄ p₁ p₂ p₃ p₄ : ℝ} (hw₁ : 0 ≤ w₁) (hw₂ : 0 ≤ w₂) (hw₃ : 0 ≤ w₃) (hw₄ : 0 ≤ w₄) (hp₁ : 0 ≤ p₁) (hp₂ : 0 ≤ p₂) (hp₃ : 0 ≤ p₃) (hp₄ : 0 ≤ p₄) (hw : w₁ + w₂ + w₃ + w₄ = 1) : p₁ ^ w₁ * p₂ ^ w₂ * p₃ ^ w₃ * p₄ ^ w₄ ≤ w₁ * p₁ + w₂ * p₂ + w₃ * p₃ + w₄ * p₄ := nnreal.geom_mean_le_arith_mean4_weighted ⟨w₁, hw₁⟩ ⟨w₂, hw₂⟩ ⟨w₃, hw₃⟩ ⟨w₄, hw₄⟩ ⟨p₁, hp₁⟩ ⟨p₂, hp₂⟩ ⟨p₃, hp₃⟩ ⟨p₄, hp₄⟩ $ nnreal.coe_eq.1 $ by assumption /-- Young's inequality, a version for nonnegative real numbers. -/ theorem young_inequality_of_nonneg {a b p q : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) (hpq : p.is_conjugate_exponent q) : a * b ≤ a^p / p + b^q / q := by simpa [← rpow_mul, ha, hb, hpq.ne_zero, hpq.symm.ne_zero, div_eq_inv_mul] using geom_mean_le_arith_mean2_weighted hpq.one_div_nonneg hpq.symm.one_div_nonneg (rpow_nonneg_of_nonneg ha p) (rpow_nonneg_of_nonneg hb q) hpq.inv_add_inv_conj /-- Young's inequality, a version for arbitrary real numbers. -/ theorem young_inequality (a b : ℝ) {p q : ℝ} (hpq : p.is_conjugate_exponent q) : a * b ≤ (abs a)^p / p + (abs b)^q / q := calc a * b ≤ abs (a * b) : le_abs_self (a * b) ... = abs a * abs b : abs_mul a b ... ≤ (abs a)^p / p + (abs b)^q / q : real.young_inequality_of_nonneg (abs_nonneg a) (abs_nonneg b) hpq end real namespace nnreal /-- Young's inequality, `ℝ≥0` version. We use `{p q : ℝ≥0}` in order to avoid constructing witnesses of `0 ≤ p` and `0 ≤ q` for the denominators. -/ theorem young_inequality (a b : ℝ≥0) {p q : ℝ≥0} (hp : 1 < p) (hpq : 1 / p + 1 / q = 1) : a * b ≤ a^(p:ℝ) / p + b^(q:ℝ) / q := real.young_inequality_of_nonneg a.coe_nonneg b.coe_nonneg ⟨hp, nnreal.coe_eq.2 hpq⟩ /-- Young's inequality, `ℝ≥0` version with real conjugate exponents. -/ theorem young_inequality_real (a b : ℝ≥0) {p q : ℝ} (hpq : p.is_conjugate_exponent q) : a * b ≤ a ^ p / nnreal.of_real p + b ^ q / nnreal.of_real q := begin nth_rewrite 0 ←coe_of_real p hpq.nonneg, nth_rewrite 0 ←coe_of_real q hpq.symm.nonneg, exact young_inequality a b hpq.one_lt_nnreal hpq.inv_add_inv_conj_nnreal, end /-- Hölder inequality: the scalar product of two functions is bounded by the product of their `L^p` and `L^q` norms when `p` and `q` are conjugate exponents. Version for sums over finite sets, with `ℝ≥0`-valued functions. -/ theorem inner_le_Lp_mul_Lq (f g : ι → ℝ≥0) {p q : ℝ} (hpq : p.is_conjugate_exponent q) : ∑ i in s, f i * g i ≤ (∑ i in s, (f i) ^ p) ^ (1 / p) * (∑ i in s, (g i) ^ q) ^ (1 / q) := begin -- Let `G=∥g∥_q` be the `L_q`-norm of `g`. set G := (∑ i in s, (g i) ^ q) ^ (1 / q), have hGq : G ^ q = ∑ i in s, (g i) ^ q, { rw [← rpow_mul, one_div_mul_cancel hpq.symm.ne_zero, rpow_one], }, -- First consider the trivial case `∥g∥_q=0` by_cases hG : G = 0, { rw [hG, sum_eq_zero, mul_zero], intros i hi, simp only [rpow_eq_zero_iff, sum_eq_zero_iff] at hG, simp [(hG.1 i hi).1] }, { -- Move power from right to left rw [← div_le_iff hG, sum_div], -- Now the inequality follows from the weighted generalized mean inequality -- with weights `w_i` and numbers `z_i` given by the following formulas. set w : ι → ℝ≥0 := λ i, (g i) ^ q / G ^ q, set z : ι → ℝ≥0 := λ i, f i * (G / g i) ^ (q / p), -- Show that the sum of weights equals one have A : ∑ i in s, w i = 1, { rw [← sum_div, hGq, div_self], simpa [rpow_eq_zero_iff, hpq.symm.ne_zero] using hG }, -- LHS of the goal equals LHS of the weighted generalized mean inequality calc (∑ i in s, f i * g i / G) = (∑ i in s, w i * z i) : begin refine sum_congr rfl (λ i hi, _), have : q - q / p = 1, by field_simp [hpq.ne_zero, hpq.symm.mul_eq_add], dsimp only [w, z], rw [← div_rpow, mul_left_comm, mul_div_assoc, ← @inv_div _ _ _ G, inv_rpow, ← div_eq_mul_inv, ← rpow_sub']; simp [this] end -- Apply the generalized mean inequality ... ≤ (∑ i in s, w i * (z i) ^ p) ^ (1 / p) : nnreal.arith_mean_le_rpow_mean s w z A (le_of_lt hpq.one_lt) -- Simplify the right hand side. Terms with `g i ≠ 0` are equal to `(f i) ^ p`, -- the others are zeros. ... ≤ (∑ i in s, (f i) ^ p) ^ (1 / p) : begin refine rpow_le_rpow (sum_le_sum (λ i hi, _)) hpq.one_div_nonneg, dsimp only [w, z], rw [mul_rpow, mul_left_comm, ← rpow_mul _ _ p, div_mul_cancel _ hpq.ne_zero, div_rpow, div_mul_div, mul_comm (G ^ q), mul_div_mul_right], { nth_rewrite 1 [← mul_one ((f i) ^ p)], exact canonically_ordered_semiring.mul_le_mul (le_refl _) (div_self_le _) }, { simpa [hpq.symm.ne_zero] using hG } end } end /-- The `L_p` seminorm of a vector `f` is the greatest value of the inner product `∑ i in s, f i * g i` over functions `g` of `L_q` seminorm less than or equal to one. -/ theorem is_greatest_Lp (f : ι → ℝ≥0) {p q : ℝ} (hpq : p.is_conjugate_exponent q) : is_greatest ((λ g : ι → ℝ≥0, ∑ i in s, f i * g i) '' {g | ∑ i in s, (g i)^q ≤ 1}) ((∑ i in s, (f i)^p) ^ (1 / p)) := begin split, { use λ i, ((f i) ^ p / f i / (∑ i in s, (f i) ^ p) ^ (1 / q)), by_cases hf : ∑ i in s, (f i)^p = 0, { simp [hf, hpq.ne_zero, hpq.symm.ne_zero] }, { have A : p + q - q ≠ 0, by simp [hpq.ne_zero], have B : ∀ y : ℝ≥0, y * y^p / y = y^p, { refine λ y, mul_div_cancel_left_of_imp (λ h, _), simpa [h, hpq.ne_zero] }, simp only [set.mem_set_of_eq, div_rpow, ← sum_div, ← rpow_mul, div_mul_cancel _ hpq.symm.ne_zero, rpow_one, div_le_iff hf, one_mul, hpq.mul_eq_add, ← rpow_sub' _ A, _root_.add_sub_cancel, le_refl, true_and, ← mul_div_assoc, B], rw [div_eq_iff, ← rpow_add hf, hpq.inv_add_inv_conj, rpow_one], simpa [hpq.symm.ne_zero] using hf } }, { rintros _ ⟨g, hg, rfl⟩, apply le_trans (inner_le_Lp_mul_Lq s f g hpq), simpa only [mul_one] using canonically_ordered_semiring.mul_le_mul (le_refl _) (nnreal.rpow_le_one hg (le_of_lt hpq.symm.one_div_pos)) } end /-- Minkowski inequality: the `L_p` seminorm of the sum of two vectors is less than or equal to the sum of the `L_p`-seminorms of the summands. A version for `nnreal`-valued functions. -/ theorem Lp_add_le (f g : ι → ℝ≥0) {p : ℝ} (hp : 1 ≤ p) : (∑ i in s, (f i + g i) ^ p) ^ (1 / p) ≤ (∑ i in s, (f i) ^ p) ^ (1 / p) + (∑ i in s, (g i) ^ p) ^ (1 / p) := begin -- The result is trivial when `p = 1`, so we can assume `1 < p`. rcases eq_or_lt_of_le hp with rfl|hp, { simp [finset.sum_add_distrib] }, have hpq := real.is_conjugate_exponent_conjugate_exponent hp, have := is_greatest_Lp s (f + g) hpq, simp only [pi.add_apply, add_mul, sum_add_distrib] at this, rcases this.1 with ⟨φ, hφ, H⟩, rw ← H, exact add_le_add ((is_greatest_Lp s f hpq).2 ⟨φ, hφ, rfl⟩) ((is_greatest_Lp s g hpq).2 ⟨φ, hφ, rfl⟩) end end nnreal namespace real variables (f g : ι → ℝ) {p q : ℝ} /-- Hölder inequality: the scalar product of two functions is bounded by the product of their `L^p` and `L^q` norms when `p` and `q` are conjugate exponents. Version for sums over finite sets, with real-valued functions. -/ theorem inner_le_Lp_mul_Lq (hpq : is_conjugate_exponent p q) : ∑ i in s, f i * g i ≤ (∑ i in s, (abs $ f i)^p) ^ (1 / p) * (∑ i in s, (abs $ g i)^q) ^ (1 / q) := begin have := nnreal.coe_le_coe.2 (nnreal.inner_le_Lp_mul_Lq s (λ i, ⟨_, abs_nonneg (f i)⟩) (λ i, ⟨_, abs_nonneg (g i)⟩) hpq), push_cast at this, refine le_trans (sum_le_sum $ λ i hi, _) this, simp only [← abs_mul, le_abs_self] end /-- Minkowski inequality: the `L_p` seminorm of the sum of two vectors is less than or equal to the sum of the `L_p`-seminorms of the summands. A version for `real`-valued functions. -/ theorem Lp_add_le (hp : 1 ≤ p) : (∑ i in s, (abs $ f i + g i) ^ p) ^ (1 / p) ≤ (∑ i in s, (abs $ f i) ^ p) ^ (1 / p) + (∑ i in s, (abs $ g i) ^ p) ^ (1 / p) := begin have := nnreal.coe_le_coe.2 (nnreal.Lp_add_le s (λ i, ⟨_, abs_nonneg (f i)⟩) (λ i, ⟨_, abs_nonneg (g i)⟩) hp), push_cast at this, refine le_trans (rpow_le_rpow _ (sum_le_sum $ λ i hi, _) _) this; simp [sum_nonneg, rpow_nonneg_of_nonneg, abs_nonneg, le_trans zero_le_one hp, abs_add, rpow_le_rpow] end variables {f g} /-- Hölder inequality: the scalar product of two functions is bounded by the product of their `L^p` and `L^q` norms when `p` and `q` are conjugate exponents. Version for sums over finite sets, with real-valued nonnegative functions. -/ theorem inner_le_Lp_mul_Lq_of_nonneg (hpq : is_conjugate_exponent p q) (hf : ∀ i ∈ s, 0 ≤ f i) (hg : ∀ i ∈ s, 0 ≤ g i) : ∑ i in s, f i * g i ≤ (∑ i in s, (f i)^p) ^ (1 / p) * (∑ i in s, (g i)^q) ^ (1 / q) := by convert inner_le_Lp_mul_Lq s f g hpq using 3; apply sum_congr rfl; intros i hi; simp only [abs_of_nonneg, hf i hi, hg i hi] /-- Minkowski inequality: the `L_p` seminorm of the sum of two vectors is less than or equal to the sum of the `L_p`-seminorms of the summands. A version for `real`-valued nonnegative functions. -/ theorem Lp_add_le_of_nonneg (hp : 1 ≤ p) (hf : ∀ i ∈ s, 0 ≤ f i) (hg : ∀ i ∈ s, 0 ≤ g i) : (∑ i in s, (f i + g i) ^ p) ^ (1 / p) ≤ (∑ i in s, (f i) ^ p) ^ (1 / p) + (∑ i in s, (g i) ^ p) ^ (1 / p) := by convert Lp_add_le s f g hp using 2 ; [skip, congr' 1, congr' 1]; apply sum_congr rfl; intros i hi; simp only [abs_of_nonneg, hf i hi, hg i hi, add_nonneg] end real namespace ennreal /-- Young's inequality, `ennreal` version with real conjugate exponents. -/ theorem young_inequality (a b : ennreal) {p q : ℝ} (hpq : p.is_conjugate_exponent q) : a * b ≤ a ^ p / ennreal.of_real p + b ^ q / ennreal.of_real q := begin by_cases h : a = ⊤ ∨ b = ⊤, { refine le_trans le_top (le_of_eq _), repeat {rw ennreal.div_def}, cases h; rw h; simp [h, hpq.pos, hpq.symm.pos], }, push_neg at h, -- if a ≠ ⊤ and b ≠ ⊤, use the nnreal version: nnreal.young_inequality_real rw [←coe_to_nnreal h.left, ←coe_to_nnreal h.right, ←coe_mul, coe_rpow_of_nonneg _ hpq.nonneg, coe_rpow_of_nonneg _ hpq.symm.nonneg, ennreal.of_real, ennreal.of_real, ←@coe_div (nnreal.of_real p) _ (by simp [hpq.pos]), ←@coe_div (nnreal.of_real q) _ (by simp [hpq.symm.pos]), ←coe_add, coe_le_coe], exact nnreal.young_inequality_real a.to_nnreal b.to_nnreal hpq, end variables (f g : ι → ennreal) {p q : ℝ} /-- Hölder inequality: the scalar product of two functions is bounded by the product of their `L^p` and `L^q` norms when `p` and `q` are conjugate exponents. Version for sums over finite sets, with `ennreal`-valued functions. -/ theorem inner_le_Lp_mul_Lq (hpq : p.is_conjugate_exponent q) : (∑ i in s, f i * g i) ≤ (∑ i in s, (f i)^p) ^ (1/p) * (∑ i in s, (g i)^q) ^ (1/q) := begin by_cases H : (∑ i in s, (f i)^p) ^ (1/p) = 0 ∨ (∑ i in s, (g i)^q) ^ (1/q) = 0, { replace H : (∀ i ∈ s, f i = 0) ∨ (∀ i ∈ s, g i = 0), by simpa [ennreal.rpow_eq_zero_iff, hpq.pos, hpq.symm.pos, asymm hpq.pos, asymm hpq.symm.pos, sum_eq_zero_iff_of_nonneg] using H, have : ∀ i ∈ s, f i * g i = 0 := λ i hi, by cases H; simp [H i hi], have : (∑ i in s, f i * g i) = (∑ i in s, 0) := sum_congr rfl this, simp [this] }, push_neg at H, by_cases H' : (∑ i in s, (f i)^p) ^ (1/p) = ⊤ ∨ (∑ i in s, (g i)^q) ^ (1/q) = ⊤, { cases H'; simp [H', -one_div, H] }, replace H' : (∀ i ∈ s, f i ≠ ⊤) ∧ (∀ i ∈ s, g i ≠ ⊤), by simpa [ennreal.rpow_eq_top_iff, asymm hpq.pos, asymm hpq.symm.pos, hpq.pos, hpq.symm.pos, ennreal.sum_eq_top_iff, not_or_distrib] using H', have := ennreal.coe_le_coe.2 (@nnreal.inner_le_Lp_mul_Lq _ s (λ i, ennreal.to_nnreal (f i)) (λ i, ennreal.to_nnreal (g i)) _ _ hpq), simp [← ennreal.coe_rpow_of_nonneg, le_of_lt (hpq.pos), le_of_lt (hpq.one_div_pos), le_of_lt (hpq.symm.pos), le_of_lt (hpq.symm.one_div_pos)] at this, convert this using 1; [skip, congr' 2]; [skip, skip, simp, skip, simp]; { apply finset.sum_congr rfl (λ i hi, _), simp [H'.1 i hi, H'.2 i hi, -with_zero.coe_mul, with_top.coe_mul.symm] }, end /-- Minkowski inequality: the `L_p` seminorm of the sum of two vectors is less than or equal to the sum of the `L_p`-seminorms of the summands. A version for `ennreal` valued nonnegative functions. -/ theorem Lp_add_le (hp : 1 ≤ p) : (∑ i in s, (f i + g i) ^ p)^(1/p) ≤ (∑ i in s, (f i)^p) ^ (1/p) + (∑ i in s, (g i)^p) ^ (1/p) := begin by_cases H' : (∑ i in s, (f i)^p) ^ (1/p) = ⊤ ∨ (∑ i in s, (g i)^p) ^ (1/p) = ⊤, { cases H'; simp [H', -one_div] }, have pos : 0 < p := lt_of_lt_of_le zero_lt_one hp, replace H' : (∀ i ∈ s, f i ≠ ⊤) ∧ (∀ i ∈ s, g i ≠ ⊤), by simpa [ennreal.rpow_eq_top_iff, asymm pos, pos, ennreal.sum_eq_top_iff, not_or_distrib] using H', have := ennreal.coe_le_coe.2 (@nnreal.Lp_add_le _ s (λ i, ennreal.to_nnreal (f i)) (λ i, ennreal.to_nnreal (g i)) _ hp), push_cast [← ennreal.coe_rpow_of_nonneg, le_of_lt (pos), le_of_lt (one_div_pos.2 pos)] at this, convert this using 2; [skip, congr' 1, congr' 1]; { apply finset.sum_congr rfl (λ i hi, _), simp [H'.1 i hi, H'.2 i hi] } end end ennreal section lintegral /-! ### Hölder's inequality for the Lebesgue integral of ennreal and nnreal functions We prove `∫ (f * g) ∂μ ≤ (∫ f^p ∂μ) ^ (1/p) * (∫ g^q ∂μ) ^ (1/q)` for `p`, `q` conjugate real exponents and `α→(e)nnreal` functions in several cases, the first two being useful only to prove the more general results: * `ennreal.lintegral_mul_le_one_of_lintegral_rpow_eq_one` : ennreal functions for which the integrals on the right are equal to 1, * `ennreal.lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top` : ennreal functions for which the integrals on the right are neither ⊤ nor 0, * `ennreal.lintegral_mul_le_Lp_mul_Lq` : ennreal functions, * `nnreal.lintegral_mul_le_Lp_mul_Lq` : nnreal functions. -/ open measure_theory variables {α : Type*} [measurable_space α] {μ : measure α} namespace ennreal lemma lintegral_mul_le_one_of_lintegral_rpow_eq_one {p q : ℝ} (hpq : p.is_conjugate_exponent q) {f g : α → ennreal} (hf : measurable f) (hg : measurable g) (hf_norm : ∫⁻ a, (f a)^p ∂μ = 1) (hg_norm : ∫⁻ a, (g a)^q ∂μ = 1) : ∫⁻ a, (f * g) a ∂μ ≤ 1 := begin calc ∫⁻ (a : α), ((f * g) a) ∂μ ≤ ∫⁻ (a : α), ((f a)^p / ennreal.of_real p + (g a)^q / ennreal.of_real q) ∂μ : lintegral_mono (λ a, young_inequality (f a) (g a) hpq) ... = 1 : begin simp_rw [div_def], rw lintegral_add, { rw [lintegral_mul_const _ hf.ennreal_rpow_const, lintegral_mul_const _ hg.ennreal_rpow_const, hf_norm, hg_norm, ←ennreal.div_def, ←ennreal.div_def, hpq.inv_add_inv_conj_ennreal], }, { exact hf.ennreal_rpow_const.ennreal_mul measurable_const, }, { exact hg.ennreal_rpow_const.ennreal_mul measurable_const, }, end end /-- Function multiplied by the inverse of its p-seminorm `(∫⁻ f^p ∂μ) ^ 1/p`-/ def fun_mul_inv_snorm (f : α → ennreal) (p : ℝ) (μ : measure α) : α → ennreal := λ a, (f a) * ((∫⁻ c, (f c) ^ p ∂μ) ^ (1 / p))⁻¹ lemma fun_eq_fun_mul_inv_snorm_mul_snorm {p : ℝ} (f : α → ennreal) (hf_nonzero : ∫⁻ a, (f a) ^ p ∂μ ≠ 0) (hf_top : ∫⁻ a, (f a) ^ p ∂μ ≠ ⊤) {a : α} : f a = (fun_mul_inv_snorm f p μ a) * (∫⁻ c, (f c)^p ∂μ)^(1/p) := by simp [fun_mul_inv_snorm, mul_assoc, inv_mul_cancel, hf_nonzero, hf_top] lemma fun_mul_inv_snorm_rpow {p : ℝ} (hp0 : 0 < p) {f : α → ennreal} {a : α} : (fun_mul_inv_snorm f p μ a) ^ p = (f a)^p * (∫⁻ c, (f c) ^ p ∂μ)⁻¹ := begin rw [fun_mul_inv_snorm, mul_rpow_of_nonneg _ _ (le_of_lt hp0)], suffices h_inv_rpow : ((∫⁻ (c : α), f c ^ p ∂μ) ^ (1 / p))⁻¹ ^ p = (∫⁻ (c : α), f c ^ p ∂μ)⁻¹, by rw h_inv_rpow, rw [inv_rpow_of_pos hp0, ←rpow_mul, div_eq_mul_inv, one_mul, _root_.inv_mul_cancel (ne_of_lt hp0).symm, rpow_one], end lemma lintegral_rpow_fun_mul_inv_snorm_eq_one {p : ℝ} (hp0_lt : 0 < p) {f : α → ennreal} (hf : measurable f) (hf_nonzero : ∫⁻ a, (f a)^p ∂μ ≠ 0) (hf_top : ∫⁻ a, (f a)^p ∂μ ≠ ⊤) : ∫⁻ c, (fun_mul_inv_snorm f p μ c)^p ∂μ = 1 := begin simp_rw fun_mul_inv_snorm_rpow hp0_lt, rw [lintegral_mul_const _ hf.ennreal_rpow_const, mul_inv_cancel hf_nonzero hf_top], end /-- Hölder's inequality in case of finite non-zero integrals -/ lemma lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top {p q : ℝ} (hpq : p.is_conjugate_exponent q) {f g : α → ennreal} (hf : measurable f) (hg : measurable g) (hf_nontop : ∫⁻ a, (f a)^p ∂μ ≠ ⊤) (hg_nontop : ∫⁻ a, (g a)^q ∂μ ≠ ⊤) (hf_nonzero : ∫⁻ a, (f a)^p ∂μ ≠ 0) (hg_nonzero : ∫⁻ a, (g a)^q ∂μ ≠ 0) : ∫⁻ a, (f * g) a ∂μ ≤ (∫⁻ a, (f a)^p ∂μ)^(1/p) * (∫⁻ a, (g a)^q ∂μ)^(1/q) := begin let npf := (∫⁻ (c : α), (f c) ^ p ∂μ) ^ (1/p), let nqg := (∫⁻ (c : α), (g c) ^ q ∂μ) ^ (1/q), calc ∫⁻ (a : α), (f * g) a ∂μ = ∫⁻ (a : α), ((fun_mul_inv_snorm f p μ * fun_mul_inv_snorm g q μ) a) * (npf * nqg) ∂μ : begin refine lintegral_congr (λ a, _), rw [pi.mul_apply, fun_eq_fun_mul_inv_snorm_mul_snorm f hf_nonzero hf_nontop, fun_eq_fun_mul_inv_snorm_mul_snorm g hg_nonzero hg_nontop, pi.mul_apply], ring, end ... ≤ npf * nqg : begin rw lintegral_mul_const' (npf * nqg) _ (by simp [hf_nontop, hg_nontop, hf_nonzero, hg_nonzero]), nth_rewrite 1 ←one_mul (npf * nqg), refine mul_le_mul _ (le_refl (npf * nqg)), have hf1 := lintegral_rpow_fun_mul_inv_snorm_eq_one hpq.pos hf hf_nonzero hf_nontop, have hg1 := lintegral_rpow_fun_mul_inv_snorm_eq_one hpq.symm.pos hg hg_nonzero hg_nontop, exact lintegral_mul_le_one_of_lintegral_rpow_eq_one hpq (hf.ennreal_mul measurable_const) (hg.ennreal_mul measurable_const) hf1 hg1, end end lemma ae_eq_zero_of_lintegral_rpow_eq_zero {p : ℝ} (hp0_lt : 0 < p) {f : α → ennreal} (hf : measurable f) (hf_zero : ∫⁻ a, (f a)^p ∂μ = 0) : f =ᵐ[μ] 0 := begin rw lintegral_eq_zero_iff hf.ennreal_rpow_const at hf_zero, refine filter.eventually.mp hf_zero (filter.eventually_of_forall (λ x, _)), dsimp only, rw [pi.zero_apply, rpow_eq_zero_iff], intro hx, cases hx, { exact hx.left, }, { exfalso, linarith, }, end lemma lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero {p : ℝ} (hp0_lt : 0 < p) {f g : α → ennreal} (hf : measurable f) (hf_zero : ∫⁻ a, (f a)^p ∂μ = 0) : ∫⁻ a, (f * g) a ∂μ = 0 := begin rw ←@lintegral_zero_fun α _ μ, refine lintegral_congr_ae _, suffices h_mul_zero : f * g =ᵐ[μ] 0 * g , by rwa zero_mul at h_mul_zero, have hf_eq_zero : f =ᵐ[μ] 0, from ae_eq_zero_of_lintegral_rpow_eq_zero hp0_lt hf hf_zero, exact filter.eventually_eq.mul hf_eq_zero (ae_eq_refl g), end lemma lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top {p q : ℝ} (hp0_lt : 0 < p) (hq0 : 0 ≤ q) {f g : α → ennreal} (hf_top : ∫⁻ a, (f a)^p ∂μ = ⊤) (hg_nonzero : ∫⁻ a, (g a)^q ∂μ ≠ 0) : ∫⁻ a, (f * g) a ∂μ ≤ (∫⁻ a, (f a)^p ∂μ) ^ (1/p) * (∫⁻ a, (g a)^q ∂μ) ^ (1/q) := begin refine le_trans le_top (le_of_eq _), have hp0_inv_lt : 0 < 1/p, by simp [hp0_lt], rw [hf_top, ennreal.top_rpow_of_pos hp0_inv_lt], simp [hq0, hg_nonzero], end /-- Hölder's inequality for functions `α → ennreal`. The integral of the product of two functions is bounded by the product of their `ℒp` and `ℒq` seminorms when `p` and `q` are conjugate exponents. -/ theorem lintegral_mul_le_Lp_mul_Lq (μ : measure α) {p q : ℝ} (hpq : p.is_conjugate_exponent q) {f g : α → ennreal} (hf : measurable f) (hg : measurable g) : ∫⁻ a, (f * g) a ∂μ ≤ (∫⁻ a, (f a)^p ∂μ) ^ (1/p) * (∫⁻ a, (g a)^q ∂μ) ^ (1/q) := begin by_cases hf_zero : ∫⁻ a, (f a) ^ p ∂μ = 0, { refine le_trans (le_of_eq _) (zero_le _), exact lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero hpq.pos hf hf_zero, }, by_cases hg_zero : ∫⁻ a, (g a) ^ q ∂μ = 0, { refine le_trans (le_of_eq _) (zero_le _), rw mul_comm, exact lintegral_mul_eq_zero_of_lintegral_rpow_eq_zero hpq.symm.pos hg hg_zero, }, by_cases hf_top : ∫⁻ a, (f a) ^ p ∂μ = ⊤, { exact lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top hpq.pos hpq.symm.nonneg hf_top hg_zero, }, by_cases hg_top : ∫⁻ a, (g a) ^ q ∂μ = ⊤, { rw [mul_comm, mul_comm ((∫⁻ (a : α), (f a) ^ p ∂μ) ^ (1 / p))], exact lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_eq_top hpq.symm.pos hpq.nonneg hg_top hf_zero, }, -- non-⊤ non-zero case exact ennreal.lintegral_mul_le_Lp_mul_Lq_of_ne_zero_of_ne_top hpq hf hg hf_top hg_top hf_zero hg_zero, end end ennreal /-- Hölder's inequality for functions `α → nnreal`. The integral of the product of two functions is bounded by the product of their `ℒp` and `ℒq` seminorms when `p` and `q` are conjugate exponents. -/ theorem nnreal.lintegral_mul_le_Lp_mul_Lq {p q : ℝ} (hpq : p.is_conjugate_exponent q) {f g : α → nnreal} (hf : measurable f) (hg : measurable g) : ∫⁻ a, (f * g) a ∂μ ≤ (∫⁻ a, (f a)^p ∂μ)^(1/p) * (∫⁻ a, (g a)^q ∂μ)^(1/q) := begin simp_rw [pi.mul_apply, ennreal.coe_mul], exact ennreal.lintegral_mul_le_Lp_mul_Lq μ hpq hf.ennreal_coe hg.ennreal_coe, end end lintegral
4f5184b0f76ac9d0cc7962ebb8df530ff19be40d
b7f22e51856f4989b970961f794f1c435f9b8f78
/tests/lean/run/record6.lean
902cbab9853d2c1f7705b66cdf717ccca9ebe375
[ "Apache-2.0" ]
permissive
soonhokong/lean
cb8aa01055ffe2af0fb99a16b4cda8463b882cd1
38607e3eb57f57f77c0ac114ad169e9e4262e24f
refs/heads/master
1,611,187,284,081
1,450,766,737,000
1,476,122,547,000
11,513,992
2
0
null
1,401,763,102,000
1,374,182,235,000
C++
UTF-8
Lean
false
false
308
lean
import logic data.unit structure point (A : Type) (B : Type) := mk :: (x : A) (y : B) structure point2 (A : Type) (B : Type) extends point A B := make structure point3 extends point num num, private point2 num num renaming x→y y→z check point3.mk theorem tst : point3.mk 1 2 3 = point.mk 1 2 := rfl
aa00278891921ea0438b4c3b6b9bd80eccba1823
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/algebra/parity.lean
d51bf886d687d5b6dc219c45577f11e113a0eedd
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
12,439
lean
/- Copyright (c) 2022 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import algebra.group_power.lemmas /-! # Squares, even and odd elements > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file proves some general facts about squares, even and odd elements of semirings. In the implementation, we define `is_square` and we let `even` be the notion transported by `to_additive`. The definition are therefore as follows: ```lean is_square a ↔ ∃ r, a = r * r even a ↔ ∃ r, a = r + r ``` Odd elements are not unified with a multiplicative notion. ## Future work * TODO: Try to generalize further the typeclass assumptions on `is_square/even`. For instance, in some cases, there are `semiring` assumptions that I (DT) am not convinced are necessary. * TODO: Consider moving the definition and lemmas about `odd` to a separate file. * TODO: The "old" definition of `even a` asked for the existence of an element `c` such that `a = 2 * c`. For this reason, several fixes introduce an extra `two_mul` or `← two_mul`. It might be the case that by making a careful choice of `simp` lemma, this can be avoided. -/ open mul_opposite variables {F α β R : Type*} section has_mul variables [has_mul α] /-- An element `a` of a type `α` with multiplication satisfies `is_square a` if `a = r * r`, for some `r : α`. -/ @[to_additive "An element `a` of a type `α` with addition satisfies `even a` if `a = r + r`, for some `r : α`."] def is_square (a : α) : Prop := ∃ r, a = r * r @[simp, to_additive] lemma is_square_mul_self (m : α) : is_square (m * m) := ⟨m, rfl⟩ @[to_additive] lemma is_square_op_iff (a : α) : is_square (op a) ↔ is_square a := ⟨λ ⟨c, hc⟩, ⟨unop c, by rw [← unop_mul, ← hc, unop_op]⟩, λ ⟨c, hc⟩, by simp [hc]⟩ end has_mul @[simp, to_additive] lemma is_square_one [mul_one_class α] : is_square (1 : α) := ⟨1, (mul_one _).symm⟩ @[to_additive] lemma is_square.map [mul_one_class α] [mul_one_class β] [monoid_hom_class F α β] {m : α} (f : F) : is_square m → is_square (f m) := by { rintro ⟨m, rfl⟩, exact ⟨f m, by simp⟩ } section monoid variables [monoid α] {n : ℕ} {a : α} @[to_additive even_iff_exists_two_nsmul] lemma is_square_iff_exists_sq (m : α) : is_square m ↔ ∃ c, m = c ^ 2 := by simp [is_square, pow_two] alias is_square_iff_exists_sq ↔ is_square.exists_sq is_square_of_exists_sq attribute [to_additive even.exists_two_nsmul "Alias of the forwards direction of `even_iff_exists_two_nsmul`."] is_square.exists_sq attribute [to_additive even_of_exists_two_nsmul "Alias of the backwards direction of `even_iff_exists_two_nsmul`."] is_square_of_exists_sq @[to_additive even.nsmul] lemma is_square.pow (n : ℕ) : is_square a → is_square (a ^ n) := by { rintro ⟨a, rfl⟩, exact ⟨a ^ n, (commute.refl _).mul_pow _⟩ } @[simp, to_additive even.nsmul'] lemma even.is_square_pow : even n → ∀ a : α, is_square (a ^ n) := by { rintro ⟨n, rfl⟩ a, exact ⟨a ^ n, pow_add _ _ _⟩ } @[simp, to_additive even_two_nsmul] lemma is_square_sq (a : α) : is_square (a ^ 2) := ⟨a, pow_two _⟩ variables [has_distrib_neg α] lemma even.neg_pow : even n → ∀ a : α, (-a) ^ n = a ^ n := by { rintro ⟨c, rfl⟩ a, simp_rw [←two_mul, pow_mul, neg_sq] } lemma even.neg_one_pow (h : even n) : (-1 : α) ^ n = 1 := by rw [h.neg_pow, one_pow] end monoid @[to_additive] lemma is_square.mul [comm_semigroup α] {a b : α} : is_square a → is_square b → is_square (a * b) := by { rintro ⟨a, rfl⟩ ⟨b, rfl⟩, exact ⟨a * b, mul_mul_mul_comm _ _ _ _⟩ } variables (α) @[simp] lemma is_square_zero [mul_zero_class α] : is_square (0 : α) := ⟨0, (mul_zero _).symm⟩ variables {α} section division_monoid variables [division_monoid α] {a : α} @[simp, to_additive] lemma is_square_inv : is_square a⁻¹ ↔ is_square a := begin refine ⟨λ h, _, λ h, _⟩, { rw [← is_square_op_iff, ← inv_inv a], exact h.map (mul_equiv.inv' α) }, { exact ((is_square_op_iff a).mpr h).map (mul_equiv.inv' α).symm } end alias is_square_inv ↔ _ is_square.inv attribute [to_additive] is_square.inv @[to_additive even.zsmul] lemma is_square.zpow (n : ℤ) : is_square a → is_square (a ^ n) := by { rintro ⟨a, rfl⟩, exact ⟨a ^ n, (commute.refl _).mul_zpow _⟩ } variables [has_distrib_neg α] {n : ℤ} lemma even.neg_zpow : even n → ∀ a : α, (-a) ^ n = a ^ n := by { rintro ⟨c, rfl⟩ a, exact zpow_bit0_neg _ _ } lemma even.neg_one_zpow (h : even n) : (-1 : α) ^ n = 1 := by rw [h.neg_zpow, one_zpow] end division_monoid lemma even_abs [subtraction_monoid α] [linear_order α] {a : α} : even (|a|) ↔ even a := by cases abs_choice a; simp only [h, even_neg] @[to_additive] lemma is_square.div [division_comm_monoid α] {a b : α} (ha : is_square a) (hb : is_square b) : is_square (a / b) := by { rw div_eq_mul_inv, exact ha.mul hb.inv } @[simp, to_additive even.zsmul'] lemma even.is_square_zpow [group α] {n : ℤ} : even n → ∀ a : α, is_square (a ^ n) := by { rintro ⟨n, rfl⟩ a, exact ⟨a ^ n, zpow_add _ _ _⟩ } -- `odd.tsub` requires `canonically_linear_ordered_semiring`, which we don't have lemma even.tsub [canonically_linear_ordered_add_monoid α] [has_sub α] [has_ordered_sub α] [contravariant_class α α (+) (≤)] {m n : α} (hm : even m) (hn : even n) : even (m - n) := begin obtain ⟨a, rfl⟩ := hm, obtain ⟨b, rfl⟩ := hn, refine ⟨a - b, _⟩, obtain h | h := le_total a b, { rw [tsub_eq_zero_of_le h, tsub_eq_zero_of_le (add_le_add h h), add_zero] }, { exact (tsub_add_tsub_comm h h).symm } end lemma even_iff_exists_bit0 [has_add α] {a : α} : even a ↔ ∃ b, a = bit0 b := iff.rfl alias even_iff_exists_bit0 ↔ even.exists_bit0 _ section semiring variables [semiring α] [semiring β] {m n : α} lemma even_iff_exists_two_mul (m : α) : even m ↔ ∃ c, m = 2 * c := by simp [even_iff_exists_two_nsmul] lemma even_iff_two_dvd {a : α} : even a ↔ 2 ∣ a := by simp [even, has_dvd.dvd, two_mul] alias even_iff_two_dvd ↔ even.two_dvd _ theorem even.trans_dvd (hm : even m) (hn : m ∣ n) : even n := even_iff_two_dvd.2 $ hm.two_dvd.trans hn theorem has_dvd.dvd.even (hn : m ∣ n) (hm : even m) : even n := hm.trans_dvd hn @[simp] lemma range_two_mul (α : Type*) [semiring α] : set.range (λ x : α, 2 * x) = {a | even a} := by { ext x, simp [eq_comm, two_mul, even] } @[simp] lemma even_bit0 (a : α) : even (bit0 a) := ⟨a, rfl⟩ @[simp] lemma even_two : even (2 : α) := ⟨1, rfl⟩ @[simp] lemma even.mul_left (hm : even m) (n) : even (n * m) := hm.map (add_monoid_hom.mul_left n) @[simp] lemma even.mul_right (hm : even m) (n) : even (m * n) := hm.map (add_monoid_hom.mul_right n) lemma even_two_mul (m : α) : even (2 * m) := ⟨m, two_mul _⟩ lemma even.pow_of_ne_zero (hm : even m) : ∀ {a : ℕ}, a ≠ 0 → even (m ^ a) | 0 a0 := (a0 rfl).elim | (a + 1) _ := by { rw pow_succ, exact hm.mul_right _ } section with_odd /-- An element `a` of a semiring is odd if there exists `k` such `a = 2*k + 1`. -/ def odd (a : α) : Prop := ∃ k, a = 2*k + 1 lemma odd_iff_exists_bit1 {a : α} : odd a ↔ ∃ b, a = bit1 b := exists_congr $ λ b, by { rw two_mul, refl } alias odd_iff_exists_bit1 ↔ odd.exists_bit1 _ @[simp] lemma odd_bit1 (a : α) : odd (bit1 a) := odd_iff_exists_bit1.2 ⟨a, rfl⟩ @[simp] lemma range_two_mul_add_one (α : Type*) [semiring α] : set.range (λ x : α, 2 * x + 1) = {a | odd a} := by { ext x, simp [odd, eq_comm] } lemma even.add_odd : even m → odd n → odd (m + n) := by { rintro ⟨m, rfl⟩ ⟨n, rfl⟩, exact ⟨m + n, by rw [mul_add, ← two_mul, add_assoc]⟩ } lemma odd.add_even (hm : odd m) (hn : even n) : odd (m + n) := by { rw add_comm, exact hn.add_odd hm } lemma odd.add_odd : odd m → odd n → even (m + n) := begin rintro ⟨m, rfl⟩ ⟨n, rfl⟩, refine ⟨n + m + 1, _⟩, rw [two_mul, two_mul], ac_refl end @[simp] lemma odd_one : odd (1 : α) := ⟨0, (zero_add _).symm.trans (congr_arg (+ (1 : α)) (mul_zero _).symm)⟩ @[simp] lemma odd_two_mul_add_one (m : α) : odd (2 * m + 1) := ⟨m, rfl⟩ lemma odd.map [ring_hom_class F α β] (f : F) : odd m → odd (f m) := by { rintro ⟨m, rfl⟩, exact ⟨f m, by simp [two_mul]⟩ } @[simp] lemma odd.mul : odd m → odd n → odd (m * n) := begin rintro ⟨m, rfl⟩ ⟨n, rfl⟩, refine ⟨2 * m * n + n + m, _⟩, rw [mul_add, add_mul, mul_one, ← add_assoc, one_mul, mul_assoc, ← mul_add, ← mul_add, ← mul_assoc, ← nat.cast_two, ← nat.cast_comm], end lemma odd.pow (hm : odd m) : ∀ {a : ℕ}, odd (m ^ a) | 0 := by { rw pow_zero, exact odd_one } | (a + 1) := by { rw pow_succ, exact hm.mul odd.pow } end with_odd end semiring section monoid variables [monoid α] [has_distrib_neg α] {a : α} {n : ℕ} lemma odd.neg_pow : odd n → ∀ a : α, (-a) ^ n = - a ^ n := by { rintro ⟨c, rfl⟩ a, simp_rw [pow_add, pow_mul, neg_sq, pow_one, mul_neg] } lemma odd.neg_one_pow (h : odd n) : (-1 : α) ^ n = -1 := by rw [h.neg_pow, one_pow] end monoid section canonically_ordered_comm_semiring variables [canonically_ordered_comm_semiring α] -- this holds more generally in a `canonically_ordered_add_monoid` if we refactor `odd` to use -- either `2 • t` or `t + t` instead of `2 * t`. lemma odd.pos [nontrivial α] {n : α} (hn : odd n) : 0 < n := begin obtain ⟨k, rfl⟩ := hn, rw [pos_iff_ne_zero, ne.def, add_eq_zero_iff, not_and'], exact λ h, (one_ne_zero h).elim end end canonically_ordered_comm_semiring section ring variables [ring α] {a b : α} {n : ℕ} @[simp] lemma even_neg_two : even (- 2 : α) := by simp only [even_neg, even_two] lemma odd.neg (hp : odd a) : odd (-a) := begin obtain ⟨k, hk⟩ := hp, use -(k + 1), rw [mul_neg, mul_add, neg_add, add_assoc, two_mul (1 : α), neg_add, neg_add_cancel_right, ←neg_add, hk], end @[simp] lemma odd_neg : odd (-a) ↔ odd a := ⟨λ h, neg_neg a ▸ h.neg, odd.neg⟩ @[simp] lemma odd_neg_one : odd (- 1 : α) := by simp lemma odd.sub_even (ha : odd a) (hb : even b) : odd (a - b) := by { rw sub_eq_add_neg, exact ha.add_even hb.neg } lemma even.sub_odd (ha : even a) (hb : odd b) : odd (a - b) := by { rw sub_eq_add_neg, exact ha.add_odd hb.neg } lemma odd.sub_odd (ha : odd a) (hb : odd b) : even (a - b) := by { rw sub_eq_add_neg, exact ha.add_odd hb.neg } lemma odd_abs [linear_order α] : odd (abs a) ↔ odd a := by cases abs_choice a with h h; simp only [h, odd_neg] end ring section powers variables [linear_ordered_ring R] {a : R} {n : ℕ} lemma even.pow_nonneg (hn : even n) (a : R) : 0 ≤ a ^ n := by cases hn with k hk; simpa only [hk, two_mul] using pow_bit0_nonneg a k lemma even.pow_pos (hn : even n) (ha : a ≠ 0) : 0 < a ^ n := by cases hn with k hk; simpa only [hk, two_mul] using pow_bit0_pos ha k lemma odd.pow_nonpos (hn : odd n) (ha : a ≤ 0) : a ^ n ≤ 0:= by cases hn with k hk; simpa only [hk, two_mul] using pow_bit1_nonpos_iff.mpr ha lemma odd.pow_neg (hn : odd n) (ha : a < 0) : a ^ n < 0:= by cases hn with k hk; simpa only [hk, two_mul] using pow_bit1_neg_iff.mpr ha lemma odd.pow_nonneg_iff (hn : odd n) : 0 ≤ a ^ n ↔ 0 ≤ a := ⟨λ h, le_of_not_lt (λ ha, h.not_lt $ hn.pow_neg ha), λ ha, pow_nonneg ha n⟩ lemma odd.pow_nonpos_iff (hn : odd n) : a ^ n ≤ 0 ↔ a ≤ 0 := ⟨λ h, le_of_not_lt (λ ha, h.not_lt $ pow_pos ha _), hn.pow_nonpos⟩ lemma odd.pow_pos_iff (hn : odd n) : 0 < a ^ n ↔ 0 < a := ⟨λ h, lt_of_not_le (λ ha, h.not_le $ hn.pow_nonpos ha), λ ha, pow_pos ha n⟩ lemma odd.pow_neg_iff (hn : odd n) : a ^ n < 0 ↔ a < 0 := ⟨λ h, lt_of_not_le (λ ha, h.not_le $ pow_nonneg ha _), hn.pow_neg⟩ lemma even.pow_pos_iff (hn : even n) (h₀ : 0 < n) : 0 < a ^ n ↔ a ≠ 0 := ⟨λ h ha, by { rw [ha, zero_pow h₀] at h, exact lt_irrefl 0 h }, hn.pow_pos⟩ lemma even.pow_abs {p : ℕ} (hp : even p) (a : R) : |a| ^ p = a ^ p := begin rw [←abs_pow, abs_eq_self], exact hp.pow_nonneg _ end @[simp] lemma pow_bit0_abs (a : R) (p : ℕ) : |a| ^ bit0 p = a ^ bit0 p := (even_bit0 _).pow_abs _ lemma odd.strict_mono_pow (hn : odd n) : strict_mono (λ a : R, a ^ n) := by cases hn with k hk; simpa only [hk, two_mul] using strict_mono_pow_bit1 _ end powers